akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.Arrays;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		Deque<Integer> stack = new ArrayDeque<Integer>();
		String[] str = (br.readLine()).split(" ");
		int count = 0;
		for (int i = 0 ; i<n ; i++ ) {
			stack.addFirst(Integer.parseInt(str[i]));
		}
		int q = Integer.parseInt(br.readLine());
		String[] line4 = (br.readLine()).split(" ");
		int[] num = new int[q];
		for (int i = 0; i<q ; i++ ) {
			num[i] = Integer.parseInt(line4[i]);
		}
		for ( int i = 0; i<q ; i++ ) {
			int a = num[i];
			if (stack.remove(a)) {
				count++;
				try{
				while(stack.remove(a));
				}catch (NullPointerException e){
					break;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 28320
#include <bits/stdc++.h>
using namespace std ;

#define int long long

int32_t main(){
	int x , n;
	cin >> x >> n;
	map<int,int> mp ;
	for(int i = 0 ; i < n ; i++) {
		int f ; cin >> f ;
		mp[f]++ ;
	}
	int ans ;
	for(int i = 0 ; i < 105 ; i++){
		if(!mp.count(x-i)){
			ans = x - i ;
			break ;
		} 
		if(!mp.count(x+i)){
			ans = x + i ;
			break ;
		}
	}
	cout << ans ;
	return 0 ;
}



Measured memory_bytes: 3616
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;
 
inline void up(int &x,const int &y){if(x<y)x=y;}
inline void down(int &x,const int &y){if(x>y)x=y;}
const int maxn = 410000;
 
int n;
int li[maxn],ri[maxn];
struct node{int x,i,p;}a[maxn<<1]; int m;
inline bool cmp(const node x,const node y){return x.x==y.x?x.i<y.i:x.x<y.x;}
inline bool cmpp(const node x,const node y){return x.x==y.x?x.p<y.p:x.x<y.x;}
 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x,y; scanf("%d%d",&x,&y); if(x>y) swap(x,y);
		li[i]=x,ri[i]=y;
		a[++m]=(node){x,i,0};
		a[++m]=(node){y,i,1};
	}sort(a+1,a+m+1,cmp);
	
	ll ans=LLONG_MAX;
	if(a[1].i!=a[m].i)
	{
		sort(a+1,a+m+1,cmpp);
		int l=2;for(;l<m&&a[l].p!=1;l++); l=a[l].x;
		down(l,li[a[m].i]);
		int mn=inf;
		for(int i=m-1;i>=2;i--)
		{
			down(mn,a[i].x-l); if(a[i].p==0) break;
			down(l,li[a[i].i]);
		}
		ans=(ll)(a[m].x-a[1].x)*(ll)mn;
	}
	int u1=0,d2=inf;
	for(int i=1;i<=n;i++)
	{
		up(u1,li[i]);
		down(d2,ri[i]);
	}
	ans=min(ans,(ll)(u1-a[1].x)*(ll)(a[m].x-d2));
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 10496
#include<iostream>
using namespace std;

#define rep(i,b) for(int i=0;i<=b;i++)
int main(){int n,r;while(cin>>n){r=0;rep(a,9)rep(b,9)rep(c,9)rep(d,9)if(a+b+c+d==n)r++;cout<<r<<endl;}}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n, m; cin >> n >> m;
	vector<bool> isacs(n + 1);
	vector<int> was(n + 1);
	int acs = 0;

	FOR_LT(i, 0, m) {
		int p; cin >> p;
		string s; cin >> s;
		bool isac = (s == "AC");
		if (isacs[p]) continue;

		if (isac) {
			acs++;
			isacs[p] = true;
		}
		else {
			was[p]++;
		}
	}

	int wass = 0;
	FOR_LE(i, 1, n) {
		if (isacs[i]) {
			wass += was[i];
		}
	}

	cout << acs << " " << wass << endl;

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>

int main(void){
  char a[8];
  int b[8];
  int i,j,k;
  int n;
  int max,min;
  int tmp;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    max = 0;
    min = 0;
    for(j=0;j<8;j++){
      scanf(" %c ",&a[j]);
      b[j] = a[j] - '0';
    }


    for(j=0;j<7;j++){
      for(k=j+1;k<8;k++){
	if(b[j] > b[k]){
	  tmp = b[j];
	  b[j] = b[k];
	  b[k] = tmp;
	}
      }
    }


    for(j=0;j<8;j++){
      max += b[j] * pow(10,j);
      min += b[j] * pow(10,7-j);
    }

    printf("%d\n",max-min);
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

int H, W;
char a[100][100];

int main() {
    cin >> H >> W;
    rep(i, H)rep(j, W) cin >> a[i][j];

    // 外枠
    rep(i, W + 2) cout << '#';
    cout << endl;

    rep(i, H) {
        cout << '#';
        rep(j, W) {
            cout << a[i][j];
        }

        cout << '#' << endl;
    }

    rep(i, W + 2) cout << '#';
    cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }
        int m = sc.nextInt();
        String[] t = new String[m];
        for (int i = 0; i < m; i++) {
            t[i] = sc.next();
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            int count = 0;
            for (int j = 0; j < n; j++) {
                if (s[i].equals(s[j])) {
                    count++;
                }
            }
            for (int j = 0; j < m; j++) {
                if (s[i].equals(t[j])) {
                    count--;
                }
            }
            if (max < count) {
                max = count;
            }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define lli long long int
using namespace std;


int main()
{
	int n, total = 0;
	vector<int> v;
	
	cin >> n;
	int a[n+5], b[n+5] = {0};
	
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	for(int i = n; i >= 1; i--){
		total = 0;
		
		for(int j = 2*i; j <= n; j += i){
			total += b[j];
		}
		
		if(total%2 != a[i]){
			b[i] = 1;
			v.push_back(i);
		}
	}
	
	int l = v.size();
	
	cout << l << "\n";
	for(int i = 0; i < l; i++){
		cout << v[i];
		if(i != l-1) cout << " ";
		else cout << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 3064
import math
import numpy

a,b,h,m = (float(x) for x in input().split())
hkaku = 360 * h / 12 + 30 * m / 60
mkaku = 360 * m / 60
kakudo = abs(hkaku-mkaku) * math.pi * 2 / 360
x = a*a + b*b - 2*a*b*math.cos(kakudo)
x = x**0.5
print(x)

Measured memory_bytes: 27144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int N, A, B, C;

bool check(string s) {
    if (s == "AB" && A == 0 && B == 0) {
        return true;
    } else if (s == "AC" && A == 0 && C == 0) {
        return true;
    } else if (s == "BC" && C == 0 && B == 0) {
        return true;
    }
    return false;
}

int main() {
    cin >> N >> A >> B >> C;
    vector<string> S(N);
    rep(i, N) cin >> S[i];
    vector<char> ans;
    rep(i, N) {
        string s = S[i];
        if (check(s)) {
            puts("No");
            return 0;
        };
        if (s == "AB") {
            if (A == 0) {
                ans.push_back('A');
                A++; B--;
            } else if (B == 0 || i == N-1) {
                ans.push_back('B');
                B++; A--;
            } else if (i < N-1) {
                if (S[i+1] == "AB" || S[i+1] == "AC") {
                    ans.push_back('A');
                    A++; B--;
                } else if (S[i+1] == "BC") {
                    ans.push_back('B');
                    B++; A--;
                }
            }
        }
        if (s == "BC") {
            if (C == 0) {
                ans.push_back('C');
                C++; B--;
            } else if (B == 0 || i == N-1) {
                ans.push_back('B');
                B++; C--;
            } else if (i < N-1) {
                if (S[i+1] == "BC" || S[i+1] == "AC") {
                    ans.push_back('C');
                    C++; B--;
                } else if (S[i+1] == "AB") {
                    ans.push_back('B');
                    B++; C--;
                }
            }
        }        
        if (s == "AC") {
            if (A == 0) {
                ans.push_back('A');
                A++; C--;
            } else if (C == 0 || i == N-1) {
                ans.push_back('C');
                C++; A--;
            } else if (i < N-1) {
                if (S[i+1] == "AB" || S[i+1] == "AC") {
                    ans.push_back('A');
                    A++; C--;
                } else if (S[i+1] == "BC") {
                    ans.push_back('C');
                    C++; A--;
                }
            }
        }
    }
    puts("Yes");
    for (char c : ans) {
        cout << c << '\n';
    }    
    return 0;
}

Measured memory_bytes: 6720
#include <iostream>
#include <fstream>
#include <climits>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <deque>
#include <map>
using namespace std;

typedef long long ll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define forn(i,n) for(int i=0; i<int(n); i++)
#define for1(i,n) for(int i=1; i<=int(n); i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

void no(int ex = -1) {
	cout << ex << endl;
	//cout << "NO" << endl;
	//exit(0);
}
void bl(bool win) {
	if (win) cout << "YES"; else cout << "NO";
	cout << endl;
}

const int N = 1020;
const ll INF = LLONG_MAX;
const int mod = 998244353;

/*vector<bool> pr;
void prime() {
	int EDGE = 1000;
	pr.assign(EDGE, true);
	pr[0] = false; pr[1] = false;
	for (int i = 2; i < EDGE; i++) {
		if (pr[i])
			if (1LL * i * i < EDGE)
				for (int j = i * i; j < EDGE; j += i)
					pr[j] = false;
	}
}*/
//prime


ll T;

int main() {
	IOS;
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ll n, m, cnt = 0;
	cin >> n;
	vector<ll> pw(N);
	forn(i, N) {
		pw[i] = pow(i, 5);
	}
	for (int i = -N+1; i < N; i++) {
		for (int j = -N+1; j < N; j++) {
			ll q, w;
			if (i < 0) { q = -pw[-i]; }
			else q = pw[i];
			if (j < 0) { w = -pw[-j]; }
			else w = pw[j];
			if (q - w == n) { cout << i << " " << j; return 0; }
		}
	}
}

Measured memory_bytes: 3564
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision
#include <regex>



typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll W = 1000000007;


using namespace std;
void omajinai() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
    //freopen("txt.csv","r",stdin);
}


class Main{
public:
    Main(){
        
    }
    
    
    void run(){
        int N,M; cin>>N>>M;
        vector<vector<int> > m(N,vector<int>(N,0));
        REP(i,M){
            int a,b; cin>>a>>b;
            m[a-1][b-1]++; m[b-1][a-1]++;
        }
        REP(i,N) cout<<accumulate(m[i].begin(), m[i].end(),0)<<endl;
    }
};

int main(){
    omajinai();
    Main().run();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define beg begin()
#define en end()
#define sz size()
#define mem(a,b) memset(a,b,sizeof a)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	ios::sync_with_stdio(false);
	int n,k;cin>>n>>k;
	int a=n/k;
	int b=a+(n%k);
	if(a-b==0) cout<< "0";
	else cout<<"1";
	cout<<endl;
	//~ cout<<abs(b-a);cout<<endl;
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  double ans, tmp;
  if (n%2 == 0) {
    tmp = (double)n;
    ans += n/(n*2.0);
  } else {
    tmp = (double)n;
    ans = (tmp+1.0)/(2.0*tmp);
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 256
def act(st):
    st.sort(key = lambda x:x[0])
    OP = [st[0]]

    for i in range(1,len(st)):
        if OP[len(OP)-1][1] < st[i][0]:
            OP.append(st[i])
        elif OP[len(OP)-1][1] <= st[i][1]:
            pass
        else:
            OP.pop()
            OP.append(st[i])
    return len(OP)

def main():
    n = int(input())
    st = [tuple(map(int,input().split())) for _ in range(n)]

    ans = act(st)
    print(ans)

if __name__ == "__main__":
    main()



Measured memory_bytes: 20424
N = int(input())
not_prime = 0
 
for loop in range(N):
    num = int(input())
 
    if num%2 == 0:
        if num != 2:
            not_prime += 1
    else:
        for i in range(3,num,2):
            if i*i > num:
                break
            if num%i == 0:
                not_prime += 1
                break
 
print("%d"%(N-not_prime))


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;

const int N=200005;
const int mod=1000000007;
typedef long long ll;


char s[N];

int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    ll tmp=0,ans=0;
    for(int i=len; i>0; i--)
    {
        if(s[i-1]=='B' && s[i]=='C')
        {
            tmp++;
            i--;
        }
        else if(s[i]=='A') ans+=tmp;
        else tmp=0;
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007

signed main()
{
	init();
	solve();
}

ll N, x, a[100100];

void init()
{
	cin >> N >> x;
	rep(i, N) cin >> a[i];
}

void solve()
{
	ll res = 0;
	if (a[0] > x) {
		res = a[0] - x;
		a[0] = x;
	}
	reps(i, 1, N) {
		if (a[i-1]+a[i] > x) {
			res += a[i-1] + a[i] - x;
			a[i] = x - a[i-1];
		}
	}
	cout << res << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll>   pairl;
typedef vector<ll>     vl;
typedef vector<ll>     vll;
typedef vector<vector<ll> > vvl;
const   int            infi = numeric_limits<int>::max();
const   ll             infl = numeric_limits<ll>::max();
const   double         eps = 0;
const   int            ms  = 0;



int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    

    int N;
    int M;
    cin >> N >> M;
    vi A(M), B(M);
    vvi C; 
    rep(i, M){

        int a_ , b_;
        cin >> a_ >> b_;
        A[i] = a_;
        B[i] = b_;
        vi c;
        rep(j, b_){
            int c_;
            cin >> c_;
            c.pb(c_); 
        }
        C.pb(c);
    }
    
    vi mem((1<<12), infi);///

   rep(i, M){
        int nk = 0;
        rep(j, B[i]){
            nk+=1<<(C[i][j]-1);
        }
        
        
        mem[nk] = min(mem[nk], A[i]);

        
        rep(k, 1<<N){
            //cout << k << "aa" << mem[k] << endl;
            if(i > 0 && mem[k] != infi){
                //cout <<  "aa" << mem[k] << endl;
                mem[k|nk] = min(mem[k]+A[i], mem[k|nk]);
            }
        }

    }
    
    if(mem[(1<<N)-1]!= infi){
        cout << mem[(1<<N)-1] << "\n";
    }else{
        cout << -1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void print_num(int A[], int N){
    for(int i=0; i<N; i++){
        if(i != N-1){
            cout << A[i] << " ";
        }else{
            cout << A[i] << endl;
        }
    }
}

void insertionSort(int A[], int N){
    for(int i=0; i<N; i++){
        int v = A[i];
        int j = i-1;
        while(j >= -1 && A[j] > v){
            A[j+1] = A[j];
            j--;
            A[j+1] = v;
        }
        print_num(A, N);
    }

}

int main(){
    int n;
    cin >> n;
    int vec[n];
    for(int i=0; i<n; i++) cin >> vec[i];

    insertionSort(vec, n);


    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
using namespace std;
#define MAX_N 100

int graph[MAX_N+1][MAX_N+1];

int main() {
  int n;
  int u,k,v;
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> u >> k;
    for(int j=0;j<k;j++) {
      cin >> v;
      if(graph[u][v] == 0)
        graph[u][v] = 1;
    }
  }

  for(int i=1;i<=n;i++) {
    for(int j=1;j<=n;j++) {
      cout << graph[i][j] << (j==n ? "\n" : " ");
    }
  }
}

Measured memory_bytes: 1200
/*
	"We know what we are, but know not what we may be."
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

/*
	"You never know how strong you are until being strong is the only choice you have."
*/

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
	
/*
	"With self-discipline most anything is possible."
*/
	
	long long n, k; cin >> n >> k;

	vector<long long> a(n);
	long long gcd = 0;
	for(auto &x : a){
		cin >> x;
		gcd = __gcd(x, gcd);
	}
	
	if(k % gcd == 0 && k <= *max_element(a.begin(), a.end())) cout << "POSSIBLE";
	else cout << "IMPOSSIBLE";	
	return 0;
}

/*
	"Reach for it. Push yourself as far as you can."
*/

Measured memory_bytes: 1024
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

struct uf {
  VI dat;
  uf(int n): dat(n) {
    REP(i,0,n) {
      dat[i] = i;
    }
  }
  int find(int x) {
    if(dat[x] == x) {
      return x;
    }
    return dat[x] = find(dat[x]);
  }
  void unite(int x, int y) {
    dat[find(x)] = find(y);
  }
};

int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int l = s.size();
  VI xs(l+2);
  xs[0] = xs[l+1] = 0;
  transform(s.begin(), s.end(), xs.begin()+1, [](char c){return c-'a';});
  transform(xs.begin(), xs.end()-1, xs.begin()+1, xs.begin(), [](int x, int y){return (y+26-x)%26;});
  xs.pop_back();
  uf u(l+1);
  int N;
  cin >> N;
  REP(i,0,N) {
    int l, r;
    cin >> l >> r;
    u.unite(l-1, r);
  }
  for(int i=0, j=l; i < j; i++, j--) {
    u.unite(i, j);
  }
  VI sum(l+1, 0);
  REP(i,0,l+1) {
    sum[u.find(i)] += xs[i];
    sum[u.find(i)] %= 26;
  }
  bool ans = all_of(sum.begin(), sum.end(), [](int x){return x == 0;});
  cout << (ans ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 1744
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    map<int,int> mp;
    for(int i = 0; i < n; i++){
        mp[a[i]]++;
    }

    for(auto &i : mp){
        if(i.second > 1){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;

int main()
{
	vector<pair<string,int>> CAL;

	CAL.push_back(make_pair("SUN",7));
	CAL.push_back(make_pair("MON",6));
	CAL.push_back(make_pair("TUE",5));
	CAL.push_back(make_pair("WED",4));
	CAL.push_back(make_pair("THU",3));
	CAL.push_back(make_pair("FRI",2));
	CAL.push_back(make_pair("SAT",1));

	string s;
	cin >> s;
	vector<pair<string,int>>::iterator it;
	
	for(it=CAL.begin();it!=CAL.end();it++){
		if((*it).first==s){
			cout << (*it).second << endl;
			break;
		}
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int l, r, d;
    cin >> l >> r >> d;


    int ans = 0;
    for (int i = 0; i <= 100; ++i) {
        if (l <= i * d && i * d <= r)
            ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;

//자동 정렬은 ctrl k f
//주석은 ctrl k c
//주석 해제는 ctrl k u
// int gcd(int a, int b){
// 	while(b!=0){
// 		int r= a%b;
// 		a=b;
// 		b=r;
// 	}
// 	return a;
// }
// int lcm(int a, int b){
// 	return a*b/gcd(a,b);
// }
long long int arr[200001];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string a, b;
	cin >> a >> b;
	//cabacc
	//abc
	int sum = INF;
	//int min_sum = 0;
	

	for (int j = 0; j < a.length()-b.length()+1; j++) {
		int cnt = 0;
		for (int i = 0; i < b.length(); i++) {
			if (b[i] != a[j+i]) {
				cnt++;
			}
		}
		sum = min(cnt, sum);
	}

	cout << sum;
	/*int n;
	cin >> n;
	long long int total = 0;
	for (int i = 0; i < n-1; i++) {
		cin >> arr[i];
		total += arr[i] % 1000000007;
		total %=1000000007;
	}
	long long int sum = 0;
	long long int m_sum = 0;
	for (int i = 0; i < n; i++) {
		m_sum += arr[i];
		m_sum = m_sum  % 1000000007;
		sum = sum + arr[i] * (total - m_sum);
		sum = sum % 1000000007;

	}
	cout << sum % 1000000007;*/
	return 0;
}



Measured memory_bytes: 3576
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N, W = ds_in()

values = np.zeros(W + 1, dtype=int)  # 重さi以下の最大価値
for _ in range(N):
    pre = values.copy()
    wv = ds_in()  # [weight, value]
    values[wv[0]:] = np.maximum(values[:-wv[0]] + wv[1], values[wv[0]:])

print(values[-1])


Measured memory_bytes: 21044
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
  
  int h,n;
  cin >> h >> n;

  int sum = 0;

  for(int i = 0;i<n;i++){
    int a;
    cin >> a;
    sum+=a;
  }

  if(sum>=h)cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}
    
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,m,i;
  cin>>n>>m;
  
  for(i=m/n;i>0;i--){
	if(m%i==0){
		cout<<i<<endl;
     	return 0;
    }
  }
}

Measured memory_bytes: 256
N = int(input())
lr = []

for i in range(N):
    x, l = map(int, input().split())
    lr.append((x-l,x+l))

res = 0
max_r = float("-inf")

sorted_lr = sorted(lr, key=lambda x:x[1])
for lr in sorted_lr:
    if max_r <= lr[0]:
        res += 1
        max_r = lr[1]

print(res)

Measured memory_bytes: 87724
def main():
    n, k = [int(x) for x in input().split()]
    scores = [int(x) for x in input().split()]

    for index, new in enumerate(scores[k:]):
        if scores[index] < new:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 31428
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class ModComb{
public:
    static const ll MOD=1e9+7;
    static const int MAXN=2e5+10;
    ll factor[MAXN];
    ModComb(){
        factor[0]=1;
        for(ll i=1;i<MAXN;i++)factor[i]=i*factor[i-1]%MOD;
    }
    ll egcd(ll a,ll b,ll &x,ll &y){
        if(a==0){
            x=0;
            y=1;
            return b;
        }
        ll x1,y1;
        ll d=egcd(b%a,a,x1,y1);
        x=y1-(b/a)*x1;
        y=x1;
        return d;
    }
    ll modInv(ll k){
        ll g,x,y;
        g=egcd(k,MOD,x,y);
        if(g!=1)return -1;
        return (x%MOD+MOD)%MOD;
    }
    ll comb(ll n,ll m){
        if(n<m)swap(n,m);
        ll rt=factor[n]*modInv(factor[m])%MOD;
        rt=rt*modInv(factor[n-m])%MOD;
        return rt;
    }
};
class Solver{
public:
    static const ll MOD=1e9+7;
    static const int MAXN=2e5+10;
    ll N,M,K;
    ModComb *comb;
    Solver(){
        comb=new ModComb();
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin>>N>>M>>K;
        ll ans=0;
        ll cnt=comb->comb(N*M-2,K-2);
        for(ll d=1;d<=N-1;d++){
            ll tmp=d*M*M%MOD*(N-d)%MOD;
            ans=(ans+tmp*cnt%MOD)%MOD;
        }
        for(ll d=1;d<=M-1;d++){
            ll tmp=d*N*N%MOD*(M-d)%MOD;
            ans=(ans+tmp*cnt%MOD)%MOD;
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 1792
#define IN_MAX 50000

char table[IN_MAX+1];

void createtable1(){ //0->prime 1->not prime
  int i=2,j;
  table[1]=1;
  for(;i<=IN_MAX;i++)
    if(!table[i])
      for(j=i*2;j<=IN_MAX;j+=i)
        table[j]=1;
}

void put(int n){
  int i=2,s=0;
  for(;i<=n/2;i++){
    if(table[i])continue;
    if(!table[n-i]){
      s++;
    }
  }
  printf("%d\n",s);
}

int main(){
  int n;
  createtable1();
  while(1){
    scanf("%d",&n);
    if(!n)return 0;
    put(n);
  }
  return 0;
}

Measured memory_bytes: 452
package main

import (
	"fmt"
	"math"
)

func prime_factors(n int) []int {
	factors := make([]int, 0)
	i := 2
	for i*i <= n {
		r := n % i
		if r != 0 {
			i += 1
		} else if r == 0 {
			n /= i
			factors = append(factors, i)
		}
	}
	if n > 1 {
		factors = append(factors, n)
	}
	return factors
}

func main() {
	// Code for C - Factors of Factorial
	var N int
	fmt.Scan(&N)

	ans := make(map[int]int, 1000)
	for {
		if N == 1 {
			break
		} else {
			a := make([]int, 0)
			a = prime_factors(N)
			for i := 0; i < len(a); i++ {
				ans[a[i]]++
			}
			N--
		}
	}

	var sum int = 1
	for _, v := range ans {
		sum *= (v + 1)
		sum %= (int(math.Pow10(9)) + 7)
	}

	fmt.Println(sum)
}


Measured memory_bytes: 1932
#############################################################
class UnionFind():
    def __init__(self, n):
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        #要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        #要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        # 要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]

    def same(self, x, y):
        # 要素x, yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)

    def members(self, x):
        # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        # すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        # グループの数を返す
        return len(self.roots())

    def all_group_members(self):
        # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
################################################################################
def examD():
    N, M = LI()
    P = LI()
    uf = UnionFind(N)
    for i in range(M):
        x, y = LI()
        if not uf.same(x - 1, y - 1):
            uf.union(x - 1, y - 1)
    ans = 0
    for i in range(N):
        if uf.same(P[i]-1,i):
            ans +=1
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()


Measured memory_bytes: 14388
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define mp(x, y) make_pair(x, y)
#define pb(x) emplace_back(x)
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> pii;

const int mod = 1e9 + 7;
ll qp(ll base, ll b)
{
    ll res = 1;
    while (b) {
        if (b & 1)
            res = res * base % mod;
        base = base * base % mod;
        b >>= 1;
    }
    return res;
}
ll dp[200010], fac[200010], inv[200010];
ll C(int m, int n)
{
    return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main()
{
    fac[0] = inv[0] = 1;
    for (int i = 1; i <= 200000; i++)
        fac[i] = fac[i - 1] * i % mod;
    inv[200000] = qp(fac[200000], mod - 2);
    for (int i = 200000 - 1; i >= 1; i--)
        inv[i] = inv[i + 1] * (i + 1) % mod;
    int n, k;
    cin >> n >> k;
    k = min(n - 1, k);
    for (int i = 1; i <= n; i++)
        dp[i] = C(i - 1, n - 1);
    ll ans = 1;
    for (int i = 1; i <= k; i++)
        ans = (ans + C(i, n) * dp[n - i] % mod) % mod;
    cout << ans;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <numeric>

#define repAll(n) (n).begin(), (n).end()
#define repConAll(n) (n).cbegin(), (n).cend()

using namespace std;

namespace {

}

int main()
{
	int A = 0, B = 0, C = 0;

	cin >> A >> B;

	for (int i = 1; i <= 3; ++i){
		if ((A * B * i) % 2 == 1){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 888
#include<iostream>
using namespace std;

int main() {
    int N;
    long tmp;
    cin>>N;
    int ans = 0;
    for(int i=0;i<N;++i){
        cin>>tmp;
        if (tmp%2==1) {
            ans = 1;
        }
    }
    if(ans==1){
        cout<<"first"<<endl;
    }
    else{
        cout<<"second"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    char turn = 'a';
    char ans;
    while(true){
        if(turn == 'a'){
            if(a.size() == 0){
                ans = 'A';
                break;
            } else {
                turn = a[0];
                a = a.substr(1);
            }
        } else if(turn == 'b'){
            if(b.size() == 0){
                ans = 'B';
                break;
            } else {
                turn = b[0];
                b = b.substr(1);
            }
        } else {
            if(c.size() == 0){
                ans = 'C';
                break;
            } else {
                turn = c[0];
                c = c.substr(1);
            }
        } 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x)  upper_bound(all(a), x) - lower_bound(all(a), x)
#define MCOUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0)
#define scan(x) scanf("%lld",&x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 2222222222222222222;
const ll mod = 1000000007;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok, flag;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


int main(void) {
  ll a, b;
  cin >> a >> b;
  if (a + b == 15) {
	cout << "+" << endl;
  }
  else if (a*b == 15) {
	cout << "*" << endl;
  }
  else {
	cout << "x" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
     
    bool flag = 1;
    int m = 0;
    int cnt = 0;
    while(flag) {
        flag = 0;
        for(int i = N-1; i > m; i--) {
            if(A[i] < A[i-1]) {
                swap(A[i], A[i-1]);
                flag = 1;
                cnt++;
            } 
        }
        m++;
    }

    for(int i = 0; i < N; i++) {
        if(i != N-1) cout << A[i] << ' ';
        else cout << A[i] << endl;
    }
    
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
vector<string> mv;
int n;string ret;
void dfs(int p,int line){
    if(p==n){
        mv.push_back(ret);
        return ;
    }
    for(int i=0;i<line;i++){
        ret.push_back('a'+i);
        if(i==line-1)
        dfs(p+1,line+1);
        else dfs(p+1,line);
        ret.pop_back();
    }
}
int main(){
    cin>>n;
    dfs(0,1);
    for(auto it:mv)cout<<it<<endl;
	return 0;
}

Measured memory_bytes: 9588
n,k,s = map(int,input().split())

if s < 10**9:
    if k == n:
        for i in range(n-1):
            print(s, end = ' ')
        print(s)
    else:
        for i in range(k):
            print(s, end = ' ')
        for i in range(n-k-1):
            print(s+1, end = ' ')
        print(s+1)
else:
    if k == 0:
        for i in range(n-1):
            print(1, end = ' ')
        print(1)
    elif k == n:
        for i in range(n-1):
            print(s, end = ' ')
        print(s)
    else:
        for i in range(k-1):
            print(s, end = ' ')
        print(s-n+k, end = ' ')
        for i in range(n-k-1):
            print(1, end = ' ')
        print(1)


Measured memory_bytes: 4224
def main():
    h,w = map(int,input().split(" "))
    s = [list(input()) for i in range(h)]
    
    dp = [[0]*w for i in range(h)]
    dp[0][0] = 1 if s[0][0]=="#" else 0

    for i in range(1,h):
        sgmdown = 1 if s[i][0]=="#" and s[i-1][0]=="." else 0
        dp[i][0] = dp[i-1][0] + sgmdown
    
    for j in range(1,w):
        sgmright = 1 if s[0][j]=="#" and s[0][j-1]=="." else 0
        dp[0][j] = dp[0][j-1] + sgmright

    for i in range(1,h):
        for j in range(1,w):
            sgmdown = 1 if s[i][j]=="#" and s[i-1][j]=="." else 0
            sgmright = 1 if s[i][j]=="#" and s[i][j-1]=="." else 0
            dp[i][j] = min(dp[i-1][j]+sgmdown, dp[i][j-1]+sgmright)

    print(dp[h-1][w-1])
main()

Measured memory_bytes: 3188
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main(){
  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<long long> p(a),q(b),r(c);
  vector <long long> ans;
  for(int i=0;i<a;i++){
    cin >> p.at(i);
  }
  for(int i=0;i<b;i++){
    cin >> q.at(i);
  }
  for(int i=0;i<c;i++){
    cin >> r.at(i);
    ans.push_back(r.at(i));
  }
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  sort(q.begin(), q.end());
  reverse(q.begin(), q.end());
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());
  for(int i=0;i<x;i++){
    ans.push_back(p[i]);
  }
  for(int i=0;i<y;i++){
    ans.push_back(q[i]);
  }
  long long sum=0;
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  for(int i=0;i<x+y;i++){
    sum += ans.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 8816
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define IFOR(k,a,b) for(int k=(a); k>=(b); --k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define IREP(k,a) for(int k=a-1; k>=(0);--k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define x first
#define y second
#define INF 1000000001
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define PI 3.1415926535897932384626
#define ERR -987654321
#define read1(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define readl1(a) scanf("%lld",&a)
#define readl2(a,b) scanf("%lld%lld",&a,&b)
#define readl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int l,r;
    cin>>l;
    int p[21];
    p[0] = 1;
    FOR(i,1,20) p[i] = p[i-1]*2; 
    REP(i,21) {
        if(p[i] > l) break;
        else r = i;
    }
    int n = 1;
    vector<pair<int,pii> > v;
    IREP(i,r) {
        v.PB(MP(p[i],MP(n,n+1)));
        v.PB(MP(0,MP(n,n+1)));
        n++;
    }

    int q = l - p[r], s = p[r];
    IREP(i,21) {
        if(p[i] <= q && q != 0) {
            v.PB(MP(s,MP(1,n-i)));
            q -= p[i];
            s += p[i];
        }
    }

    cout<<n<<" "<<v.size()<<endl;
    for(auto i:v) {
        cout<<i.y.x<<" "<<i.y.y<<" "<<i.x<<endl; 
    }

	return 0;
}






Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main() {
    int i, j;
    int n, m;

    int* mat;
    int* vec;
    int* result;

    scanf("%d %d", &n, &m);

    mat = malloc(sizeof(int) * n * m);
    vec = malloc(sizeof(int) * m);
    result = malloc(sizeof(int) * n);

    for (i = 0; i < n; i++) {
        result[i] = 0;
        for (j = 0; j < m; j++) {
            scanf("%d", &mat[i * m + j]);
        }
    }
    for (i = 0; i < m; i++) {
        scanf("%d", &vec[i]);
    }

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            result[i] += mat[i * m + j] * vec[j];
        }
    }

    for (i = 0; i < n; i++) {
        printf("%d\n", result[i]);
    }

    free(mat);
    free(vec);
    free(result);

    return 0;
}



Measured memory_bytes: 2104
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> t;
    for (int i = 1; i <= 100; ++i) {
        if (a%i == 0 && b%i == 0) {
            t.push_back(i);
        }
    }
    std::cout << t[t.size() - k];
    return 0;
}

Measured memory_bytes: 256
import scala.io.{StdIn => in}

object Main extends App {

  val prime = Array.ofDim[Boolean](200001)
  for(i <- 2 to 200000) prime(i) = true

  for(i <- 2L to 200000L if prime(i.toInt)){
    for(j <- (i * i) to 200000L by i) {
      prime(j.toInt) = false 
    }
  }
  val x = in.readLine.toInt
  val ans = (x to 200000).filter(prime(_)).head
  println(ans)
}

Measured memory_bytes: 37276
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N = int(input())

if N % 2:
    s = N
    print(cmb(N - 1, 2) - N // 2 + N - 1)
else:
    s = 1 + N
    print(cmb(N, 2) - N // 2)

for i in range(1, N):
    for j in range(i + 1, N + 1):
        if i + j != s:
            print(i, j)

Measured memory_bytes: 4100
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)

using namespace std;

int r,g,b,n,ans;

int main(){
	scanf("%d%d%d%d",&r,&g,&b,&n);
	rep (i,0,n)
		rep (j,0,n-i){
			int k=n-i-j;
			ans+=(i%r==0&&j%g==0&&k%b==0);
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val ps = Seq.fill(n)(sc.nextInt)

  val psx = 0 +: ps :+ 0
  val psx2 = psx.tail
  val psx3 = psx2.tail

  val res =
    psx3.foldLeft((0L, psx.head, psx2.head)){ case ((cnt, first, second), e) =>
      val b1 = first != 0 && e != 0
      val b2 = Seq(first, second, e).sorted.tail.head == second
      ( cnt + (if(b1 && b2) 1 else 0) ,second, e )
  }._1

  println(res)
}


Measured memory_bytes: 27332
#include <bits/stdc++.h>
//#include <vector>
using namespace std;
//using ll = long long;
#define rep(i,n) for (int i=0; i<(n); ++i)

int main() {
  int n, m;
  cin >> n >> m;
  
  int a[n][m];
  rep(i, n)
    rep(j, m) cin >> a[i][j];

  int b[m];
  rep(i, m) cin >> b[i];

  rep(i, n) {
    int c=0;
    rep(j, m) {
      c += a[i][j] * b[j];
    }
    cout << c << endl;
  }
  return 0;
}



Measured memory_bytes: 3140
#include <iostream>
using namespace std;
inline int gcd(int x,int y)
{
	if(x>y) swap(x,y);
	while(x) y%=x,swap(x,y);
	return y;
}
int main(int argc, char** argv) {
	int n;
	cin >> n;
	cout << 360/gcd(n,360);
	return 0;
}

Measured memory_bytes: 3212
import sys
input = sys.stdin.readline

def main():
    x = int(input())
    for i in range(-1000, 1000):
        for j in range(-1000, 1000):
            if x == i**5 - j**5:
                print(i, j)
                break
        else:
            continue
        break

if __name__ == '__main__':
    main()

Measured memory_bytes: 9096
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    k=parseInt(readline())
    ans=0
    for i in 1:k
        for j in 1:k
            for l in 1:k
                ans+=gcd(i,j,l)
            end
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 158956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

bool isReversible(int n){
    string s;
    s = to_string(n);
    bool flg = true;
    for(int i=0; i<s.size(); i++) if(s[i] != s[s.size()-1-i]) flg = false;

    return flg;
}

int main(){
    int a,b; cin >> a >> b;
    int ans = 0;

    for(int i=a; i<=b; i++) if(isReversible(i)) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<string>
using namespace std;

int main(){
    int n;
    cin>>n;
    int key;
    string cmd;

    list<int> L;
    for(int i=0;i<n;++i){
        cin>>cmd;
        if(cmd=="insert"){
            cin>>key;
            L.push_front(key);
        }
        else if(cmd=="delete"){
            cin>>key;
            for(list<int>::iterator it=L.begin();it!=L.end();++it){
                if(*it==key){
                    L.erase(it);
                    break;
                }
            }
        }
        else if(cmd=="deleteFirst"){
            L.pop_front();
        }
        else if(cmd=="deleteLast"){
            L.pop_back();
        }
    }

    int i=0;
    for(list<int>::iterator it=L.begin();it!=L.end();++it){
        if(i++){cout<<" ";}
        cout<<*it;
    }
    cout<<"\n";
}

Measured memory_bytes: 34272