akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<map>
#include<string>
#include<iostream>
#include<set>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
//#define scanf scanf_s
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<30);
const llint mod=1000000007;

/*printf("? %c %c\n",x,y);
		fflush(stdout);
		char ret;scanf(" %c", &ret);
		*/
int main(void){
	int i,j,k,N=200,a;
	vector<pair<int,int>> kotae;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		for(j=i+1;j<N;j++){
			printf("? ");
			for(k=0;k<N;k++){
				if(k==i||k==j){a=1;} else{a=0;}
				printf("%d",a);
			}
			printf("\n");
			fflush(stdout);
			scanf("%d",&a);
			if(a!=0){kotae.pub(mp(i,j));}
		}
	}
	printf("!");
	for(i=0;i<kotae.size();i++){
		printf(" (%d,%d)",kotae[i].first,kotae[i].second);
		
	}
	printf("\n");
	fflush(stdout);
	return 0;
}


Measured memory_bytes: 852
num_route = 0
num_node = 0

def func(unvisited_paths, visited_node, current_node):
    global num_route
    if len(visited_node) == num_node:
            num_route += 1
            return
    for next_path in [path for path in unvisited_paths if (path[0] == current_node) and (path[1] not in visited_node)]:
        next_visited_node = visited_node + [next_path[1]]
        next_unvisited_paths = unvisited_paths[:]
        next_unvisited_paths.pop(next_unvisited_paths.index([current_node, next_path[1]]))
        next_unvisited_paths.pop(next_unvisited_paths.index([next_path[1], current_node]))
        next_current_node = next_path[1]
        
        func(next_unvisited_paths, next_visited_node, next_current_node)
    
    return

def main():
    global num_node
    num_node, num_path = map(int, input().split())
    unvisited_paths = [list(map(int, input().split())) for i in range(num_path)]
    for path in unvisited_paths[:]:
        unvisited_paths.append([path[1], path[0]])
    current_node, visited_node = 1, [1]
    func(unvisited_paths, visited_node, current_node)
    print(num_route)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
def div2 h,w
 
  return [h*w/2, h*w/2] if h % 2 == 0 or w % 2 == 0
  h,w = [h, w].sort
  return [w/2*h, (w+1)/2*h]
end
  
def f h,w
  
  return 0 if h % 3 == 0 or w % 3 == 0
  
  res0 = res1 = h*w
  
  0.upto h%3 do |i|
    
    s = w*(h/3 + i)
    ss =div2(h-h/3-i, w).push(s)
    res0 = [res0, ss.max - ss.min].min
  end
  
  0.upto w%3 do |i|
    
    s = h*(w/3 + i)
    ss =div2(w-w/3-i, h).push(s)
    res1 = [res1, ss.max - ss.min].min 
  end
  
  [res0, res1].min
end  

H, W = gets.split.map(&:to_i).sort
puts [f(H,W), f(W,H)].min



Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
	ll i,j,k,l,m,n,r;

	cin >> n >> m;

	l = 0;

	for(i=0;i<m;i++)
	{
		cin >> k;

		l += k;
	}

	if(l > n)
		cout << -1 << '\n';
	else
		cout << (n-l) << '\n';
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>

using namespace std;

int main()
{
  int n,m;
  cin >> n >> m;
  vector<int> c(m,0);
  for(int i=0;i<n;i++)
  {
    int k;
    cin >> k;
    for(int j=0;j<k;j++)
    {
      int a;
      cin >> a;
      c[a-1]++;
    }
  }
  int ans=0;
  for(int i=0;i<m;i++)
    if(c[i]==n)ans++;
  cout << ans << endl;
}


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

int main(){
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	rep(i, N - 2) {
		if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C')ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def abc157c_guess_the_number():
    n, m = map(int, input().split())
    ans = ''
    if n == 1:
        ans = '0'
    if n == 2:
        ans = '10'
    if n == 3:
        ans = '100'
    changed = [False] * n
    for i in range(m):
        s, c = map(int, input().split())
        if ans[s - 1] != str(c):
            if changed[s-1]:
                print('-1')
                return
            ans_lst = list(ans)
            ans_lst[s - 1] = str(c)
            ans = ''.join(ans_lst)
            changed[s - 1] = True
    if n >= 2 and ans[0] == '0':
        print('-1')
        return

    print(int(ans))
abc157c_guess_the_number()

Measured memory_bytes: 9172
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	string S=in<string>(),T=in<string>();
	string A;

	bool no_fit = true;
	for(int i=0,ei=S.size()-T.size()+1;i<ei;i++){
		string P(S,i,T.size());
		bool part_fit = true;
		for(int j=0,ej=P.size();j<ej;j++){
			if(P[j]=='?') continue;
			if(P[j]!=T[j]){
				part_fit = false;
				break;
			}
		}
		if(part_fit){
			string B(S);
			for(int j=0;j<S.size();j++){
				if(j<i || j>=i+T.size()){
					if(B[j]=='?') B[j] = 'a';
				}
				else{
					B[j] = T[j-i];
				}
			}
			if(A.empty() || B<A){
				A = B;
				no_fit = false;
			}
		}
	}
	
	cout << (no_fit ? "UNRESTORABLE" : A) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> v;
    ll res = 0;
    ll ans = 0;
    rep(i,n){
        ll a; cin >> a;
        res += a;
        res %= m;
        v.push_back(res);
    }
    sort(v.begin(),v.end());
    ll a[n];
    rep(i,n) a[i] = 1;
    ll k = 0;
    rep(i,v.size()){
        if(v[i]==0) ans++;
        if(v[i]==v[i+1]) a[k]++;
        else k++;
    }
    rep(i,k) ans += a[i]*(a[i]-1)/2;
    cout << ans << endl;
}



Measured memory_bytes: 2036
import java.io.*;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
while((str=br.readLine())!=null){
double n=Double.parseDouble(str);
int f=(int)(Math.pow(n,2)/98)+2;
System.out.println(f);
}
}
}

Measured memory_bytes: 16892
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

ll table_5[120][5],index_10,leftTable[120],rightTable[120],m_data[10] = {0,1,2,3,4,5,6,7,8,9};
ll* table_10;

void calc10(){

	int select_num = 5,num,loc_left[5],loc_right[5],left_index,right_index,index,calc[5],value;

	index_10 = 0;

	for(int i = 0; i < 1024;i++){
		num = 0;
		for(int k = 0; k < 10; k++){
			if(i & (1 << k))num++;
		}
		if(num != select_num)continue;

		left_index = right_index = 0;

		//??°???????????????????????????
		for(int k = 0; k < 10; k++){
			if(i & (1 << k)){
				loc_left[left_index++] = k;
			}else{
				loc_right[right_index++] = k;
			}
		}

		left_index = right_index = 0;

		calc[0] = m_data[loc_left[0]],calc[1] = m_data[loc_left[1]],calc[2] = m_data[loc_left[2]],calc[3] = m_data[loc_left[3]],calc[4] = m_data[loc_left[4]];
		//?????????????¨????
		for(index = 0;index < 120; index++){
			value = 0;
			for(int p = 0; p < 5;p++){
				value = 10*value + calc[table_5[index][p]];
			}
			leftTable[left_index++] = value;
		}

		calc[0] = m_data[loc_right[0]],calc[1] = m_data[loc_right[1]],calc[2] = m_data[loc_right[2]],calc[3] = m_data[loc_right[3]],calc[4] = m_data[loc_right[4]];
		//?????????????¨????
		for(index = 0;index < 120; index++){
			value = 0;
			for(int p = 0; p < 5;p++){
				value = 10*value + calc[table_5[index][p]];
			}
			rightTable[right_index++] = value;
		}

		for(int k = 0; k < 120; k++){
			for(int p = 0; p < 120; p++){
				table_10[index_10++] = 100000*leftTable[k] + rightTable[p];
				//printf("%lld\n",table_10[index_10-1]);
			}
		}
	}
}


int main(){

	table_10 = new ll[3628800];

	int index_5 = 0;

	for(int a = 0; a < 5; a++){
		for(int b = 0; b < 5; b++){
			for(int c = 0; c < 5; c++){
				for(int d = 0; d < 5; d++){
					for(int e = 0; e < 5; e++){
						if(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e){
							table_5[index_5][0] = a,table_5[index_5][1] = b,table_5[index_5][2] = c,table_5[index_5][3] = d,table_5[index_5][4] = e;
							index_5++;
						}
					}
				}
			}
		}
	}

	calc10();

	ll tmp,base_num = 0,length,maximum = -1,ans;

	char buf[11];

	scanf("%s",buf);

	for(length = 0;buf[length] != '\0';length++);

	for(int i = 0; i < length; i++){
		base_num = 10*base_num + buf[i] - '0';
	}

	ll S = pow(10,length),S2 = pow(10,length-1);

	for(int i = 0; i < 3628800; i++){
		tmp = min(abs(table_10[i]%S-base_num),S-abs(table_10[i]%S-base_num));
		if(tmp > maximum){
			maximum = tmp;
			ans = table_10[i]%S;
		}else if(tmp == maximum){
			if(ans > table_10[i]%S){
				ans = table_10[i]%S;
			}
		}
	}

	if(ans/S2 == 0)printf("0");
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 31276
import copy

def partition(p, r):
    i = p
    for j in range(p, r):
        if A[r][1] >= A[j][1]:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[r], A[i] = A[i], A[r]
    return i

def quick_sort(p, r):
    if p < r:
        q = partition(p, r)
        quick_sort(p, q-1)
        quick_sort(q+1, r)

def is_stable():
    for i in range(N-1):
        if A[i][1] == A[i+1][1]:
            small_idx, large_idx = 0, 0
            cnt = 0
            for j in range(N):
                if A[i] == orig_list[j]:
                    small_idx = j
                    cnt += 1
                elif A[i+1] == orig_list[j]:
                    large_idx = j
                    cnt += 1
                if cnt == 2:
                    break
            if small_idx > large_idx:
                return False
    return True


N = int(input())
A = []
for _ in range(N):
    suit, num = input().split()
    num = int(num)
    A.append([suit, num])
orig_list = copy.copy(A)

quick_sort(0, N-1)

is_stable = is_stable()
if is_stable:
    print("Stable")
else:
    print("Not stable")

for card in A:
    print("%s %d" % (card[0], card[1]))


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void die() {
  cout << "Impossible\n";
  exit(0);
}

void solve() {
  int r, c;
  cin >> r >> c;
  vector<pii> v;
  for(int i = 0; i < r; i++) {
    string s;
    cin >> s;
    int lhs = c;
    int rhs = -1;
    int seen = 0;
    for(int j = 0; j < c; j++) {
      if(s[j] == '#') {
        lhs = min(lhs, j);
        rhs = max(rhs, j);
        seen++;
      }
    }
    if(seen != rhs - lhs + 1) {
      die();
    }
    v.push_back({lhs, rhs});
  }
  if(v[0].first != 0) die();
  if(v[r-1].second != c-1) die();
  for(int i = 1; i < v.size(); i++) {
    if(v[i-1].second != v[i].first) die();
  }
  cout << "Possible\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int main(){

	char number[36];
	char ans[1000],pre_switch[36],current_switch[36],current_bulb[1000];

	bool** check = new bool*[1000];
	for(int i = 0; i < 1000; i++){
		check[i] = new bool[36];
	}

	for(int i = 0; i <= 9; i++)number[i] = i + '0';
	for(int i = 0; i <= 25; i++)number[10+i] = i + 'A';

	int N,M,Q,count,tmp;
	while(true){
		scanf("%d %d %d",&N,&M,&Q);
		if(N == 0 && M == 0 && Q == 0)break;

		if(Q == 0 && N == 1){
			for(int i = 0; i < M; i++)printf("0");
			printf("\n");
			continue;
		}

		for(int i = 0; i < M; i++){
			ans[i] = '?';
			for(int k = 0; k < N; k++){
				check[i][k] = true;
			}
		}

		for(int i = 0; i < N; i++)pre_switch[i] = '0';

		for(int i = 0; i < Q; i++){
			scanf("%s %s",current_switch,current_bulb);

			for(int k = 0; k < N; k++){
				if(current_switch[k] == '1'){
					if(pre_switch[k] == '0'){
						current_switch[k] = '1';
					}else{
						current_switch[k] = '0';
					}
				}else{
					current_switch[k] = pre_switch[k];
				}
				pre_switch[k] = current_switch[k];
			}

			for(int a = 0; a < M; a++){
				for(int b = 0; b < N; b++){
					if(current_bulb[a] != current_switch[b]){
						check[a][b] = false;
					}
				}
			}
		}

		for(int i = 0; i < M; i++){
			count = 0;
			for(int k = 0; k < N; k++){
				if(check[i][k]){
					tmp = k;
					count++;
				}
			}
			if(count == 1)ans[i] = number[tmp];
		}

		for(int i = 0; i < M; i++)printf("%c",ans[i]);
		printf("\n");

	}

	return 0;
}

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

int main() {
  int N;
  cin >> N; 
  
  for(int i = 0; i < N; i++ ){
    string S;
    cin >> S;
    
    if(i == N-1 && S != "Y"){
      cout << "Three" << endl;
      break;
    }
    else if(S != "Y"){
      continue;
    }
    else{
      cout << "Four" << endl;
    break;
    }
  }
}
   


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define v long long
bool check = true;
v bins (v b[], v time, v n) {
    v l = 0, r = n, m;
    while (r > l + 1) {
        m = (l + r) / 2;
        if (b[m] < time) {
            l = m;
        }
        else if (b[m] > time) {
            r = m;
        }
        else {
            return m;
        }
    }
    m = (l + r) / 2;
    if (b[m] > time) {
        check = false;
        return 0;
    }
    return m;
}
int main () {
    v m, n, k;
    scanf ("%lld %lld %lld", &m, &n, &k);
    v a[m], b[n];
    for (v i = 0; i < m; i++) {
        scanf ("%lld", &a[i]);
        if (i > 0) {
            a[i] += a[i - 1];
        }
    }
    for (v i = 0; i < n; i++) {
        scanf ("%lld", &b[i]);
        if (i > 0) {
            b[i] += b[i - 1];
        }
    }
    v max_books = 0;
    for (v x = 0; x <= m; x++) {
        v time_for_first;
        if (x == 0) {
            time_for_first = 0;
        }
        else if (a[x - 1] > k) {
            break;
        }
        else {
            time_for_first = a[x - 1];
        }
        v remaining_time = k - time_for_first;
        v y = bins (b, remaining_time, n);
        if (check) {
            y++;
        }
        else {
            check = true;
        }
        if (x + y > max_books) {
            max_books = x + y;
        }
    }
    printf ("%lld\n", max_books);
    return 0;
}

Measured memory_bytes: 6864
#include<iostream>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<string.h>

using namespace std;

struct st{
    int p[8];
    int t;
};

bool used[8][8][8][8][8][8][8];

inline bool judge(int ar[8]){

    for(int i=0;i<8;i++){
	if (ar[i] != i) return false;
    }
    return true;
}

inline int findzero(int *ar){
    for(int i=0;i<8;i++){
	if(ar[i] == 0) return i;
    }
    return 0;
}

int main(){

    int d[] = {-4,-1,1,4};
    vector< vector<int> > d1;
    for(int i=0;i<8;i++){
	d1.push_back(vector<int>());
	for(int j=0;j<4;j++){
	    if(i+d[j]>-1&&i+d[j]<8){
		if(i == 3 && j==2) continue;
		else if(i == 4 && j == 1) continue;
		d1[i].push_back(i+d[j]);
	    }
	}
    }
		
    queue<struct st > next;
    int zero,nextzero;
    bool endflag=false,flag;
    struct st ar;
    while(true){
	memset(used,0,sizeof(used));
	flag = false;
	if((cin >> ar.p[0])==0) break;
	for(int i=1;i<8;i++){
	    cin >> ar.p[i];
	}
       while(!next.empty()){
	   next.pop();
       }
	ar.t=0;
	next.push(ar);
       if(ar.p[0] == 0 && ar.p[1] == 1 && ar.p[2] == 2&&ar.p[3]==3&&ar.p[4] == 4&&ar.p[5]==5) {
	    flag = true; 
	    cout << '0' << endl;
	    continue;
	}
	while(!next.empty()){
	    ar = next.front();
	    used[ar.p[0]][ar.p[1]][ar.p[2]][ar.p[3]][ar.p[4]][ar.p[5]][ar.p[6]] = true;
	    zero = findzero(ar.p);
	    next.pop();
	    ar.t++;
	    for(int i=0;i<d1[zero].size();i++){
		   nextzero = d1[zero][i];
		   swap(ar.p[nextzero],ar.p[zero]);
		   if( ar.p[0] == 0 && ar.p[1] == 1 && ar.p[2] == 2&&ar.p[3]==3&&ar.p[4] == 4&&ar.p[5]==5&&ar.p[6]==6 ) {
		       flag = true;
		       cout << ar.t << endl;
		       while(!next.empty()){
			   next.pop();
		       }
		   }
		    if(!used[ar.p[0]][ar.p[1]][ar.p[2]][ar.p[3]][ar.p[4]][ar.p[5]][ar.p[6]]){
			next.push(ar);
		    }
		   swap(ar.p[nextzero],ar.p[zero]);
	    }
	    if(flag) break;
	}

	ar.t = 0;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m,k;
const int FMAX = 600002;
ll fact[FMAX];
ll ifact[FMAX];

ll modpow(ll a,ll b,ll c){
  ll r = 1;
  while(b){
    if(b&1)r=r*a%c;
    a=a*a%c;
    b>>=1;
  }
  return r;
}
ll modinv(ll a,ll c){
  return modpow(a,c-2,c);
}

int main(){
  scanf("%d%d%d",&n,&m,&k);
  // fact init
  fact[0] = 1;
  FOR(i,1,FMAX)fact[i]=fact[i-1]*i%MOD;
  ifact[FMAX-1]=modinv(fact[FMAX-1],MOD);
  FORR(i,0,FMAX-1)ifact[i]=ifact[i+1]*(i+1)%MOD;
  // a == n-1 && b <= m && c <= k
  ll ans = 0;
  int a = n-1;
  ll bipow = 1;
  ll subsum = 0;
  ll tris = modpow(3,m+k,MOD);
  ll invtri = modinv(3,MOD);
  ll factabc = (a==0?1:fact[a-1]);
  int befbeg,befend;
  FOR(s,0,m+k+1){
    // c = s-b
    // 0<=c<=k
    // 0<=b<=m

    // s-b>=0 -> b<=s
    // s-b<=k -> b>=s-k
    int abc = a+s;
    if(abc!=0){
      factabc = factabc*abc%MOD;
    }
    ll unit = factabc*ifact[a]%MOD*ifact[s]%MOD*tris%MOD;
    tris = tris*invtri%MOD;

    int beg = max(s-k,0);
    int end = min(s,m);
    if(s>0){
      bipow += bipow;
      subsum *= 2;
      if(befbeg+1==beg){
        subsum += fact[s-1]*ifact[befbeg]%MOD*ifact[s-1-befbeg]%MOD;
      }
      if(befend==end){
        subsum += fact[s-1]*ifact[befend]%MOD*ifact[s-1-befend]%MOD;
      }
      if(bipow>=MOD)bipow-=MOD;
      subsum %= MOD;
    }
    befbeg = beg;
    befend = end;
    ans += unit*(bipow+MOD-subsum)%MOD;
    if(ans>=MOD)ans-=MOD;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 9600
import java.util.*;
 
public class Main {
  public static long MOD = (long)Math.pow(10, 9) + 7;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    long[] count = new long[1000001];
    for(int i = 0; i < n; i++) {
      long t = sc.nextLong();
      a[i] = t;
      for(long j = 2; (j * j) <= t; j++) {
        long k = 0;
        while((t % j) == 0) {
          k++;
          t /= j;         
        }
        count[(int)j] = Math.max(count[(int)j], k);
      }
      if(t > 1) count[(int)t] = Math.max(count[(int)t], 1);
    }
 
    long ans = 0; 
 
    long lcm = 1;

    for(int i = 1; i < 1000001; i++) {
      long c = (long)Math.pow(i, count[i]);
      lcm = (lcm * c) % MOD;
    }
 
    for(int i = 0; i < n; i++) {
      long b = lcm;
      b = (b * func(a[i], MOD - 2)) % MOD;
      ans = (ans + b) % MOD;
    }
 
    System.out.println(ans);
  }

  public static long func(long a, long x) {
    if(x == 0) return 1;
    if((x % 2) == 0) {
      long t = func(a, x / 2);
      return (t * t) % MOD;
    } else {
      return (a * func(a, x - 1)) % MOD;
    }
  }
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
typedef pair< int, int > pii;

class Decoration {
private:
	int n;
	vector< pii > deco, job;
	
	int toLeft(int k) { return (k << 1) + 1; }
	int toRight(int k) { return (k << 1) + 2; }
	int center(int l, int r) { return (l + r) >> 1; }
	
	pii mixDeco(pii fp, pii sp) {
		if (fp.first == 0) return sp;
		if (sp.first == 0) return fp;
		if (fp.first < 0 || sp.first < 0) return pii(-1,-1);
		if (fp.second + 1 == sp.first) return pii(fp.first, sp.second);
		return pii(-1, -1);
	}
	
	void lazyEval(int k, int l, int r) {
		deco[k] = mixDeco(deco[k], job[k]);
		if (k < n-1) {
			job[toLeft(k)] = mixDeco(job[toLeft(k)], job[k]);
			job[toRight(k)] = mixDeco(job[toRight(k)], job[k]);
		}
		job[k] = pii(0,0);
	}
	
	void addDeco(int a, int b, int x, int k, int l, int r) {
		lazyEval(k, l, r);
		if (r <= a || b <= l) return;
		if (a <= l && r <= b) {
			job[k] = pii(x, x);
			lazyEval(k, l, r);
			return;
		}
		addDeco(a, b, x, toLeft(k), l, center(l, r));
		addDeco(a, b, x, toRight(k), center(l, r), r);
	}
	
	pii getDeco(int a, int k, int l, int r) {
		lazyEval(k, l, r);
		if (l == a && r == a+1) return deco[k];
		int c = center(l, r);
		if (a < c) return getDeco(a, toLeft(k), l, c);
		else return getDeco(a, toRight(k), c, r);
	}
	
public:
	Decoration(int __n) {
		for (n=1; n<__n; n<<=1);
		deco.assign(2*n, pii(0,0));
		job.assign(2*n, pii(0,0));
	}
	
	void addDeco(int a, int b, int x) { addDeco(a, b, x, 0, 0, n); }
	pii getDeco(int a) { return getDeco(a, 0, 0, n); }
};

int main() {
	int N, K;
	cin >> N >> K;
	
	Decoration deco(N);
	
	int T;
	cin >> T;
	for_(i,0,T) {
		int l, r, x;
		cin >> l >> r >> x;
		deco.addDeco(l-1, r, x);
	}
	
	int ans = 0;
	for_(i,0,N) {
		pii p = deco.getDeco(i);
		if (p.first == 1 && p.second == K) ++ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11012
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace Contest
{
    class Program
    {
        public void Solve()
        {
            var sc = new Scanner();
            int N = sc.NextInt();
            int Q = sc.NextInt();
            string S = sc.Next();

            var sum = new int[N + 1];
            for (int i = 1; i < N; i++)
            {
                sum[i + 1] = sum[i];
                if (S[i] == 'C' && S[i - 1] == 'A')
                {

                    sum[i + 1]++;
                }

            }

            var sb = new StringBuilder();

            for (int i = 0; i < Q; i++)
            {
                var l = sc.NextInt() - 1;
                if (l > 0 && S[l] == 'C' && S[l - 1] == 'A') l++;
                int r = sc.NextInt();
                sb.AppendLine((sum[r] - sum[l]).ToString());
            }
            Console.Write(sb.ToString());
        }


        static void Main(string[] args) => new Program().Solve();
    }

    class Scanner
    {
        private char _separator = ' ';
        private StreamReader _stream = new StreamReader(Console.OpenStandardInput());
        private int _pos = 0;
        private string[] _line = new string[0];
        public string Next()
        {
            if (_pos >= _line.Length)
            {
                _line = _stream.ReadLine().Split(_separator);
                _pos = 0;
            }
            return _line[_pos++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public string[] Array()
        {
            if (_pos >= _line.Length)
                _line = _stream.ReadLine().Split(_separator);
            _pos = _line.Length;
            return _line;
        }
        public int[] IntArray()
        {
            var arr = Array();
            var res = new int[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = int.Parse(arr[i]);
            }
            return res;
        }
        public long[] LongArray()
        {
            var arr = Array();
            var res = new long[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = long.Parse(arr[i]);
            }
            return res;
        }
        public double[] DoubleArray()
        {
            var arr = Array();
            var res = new double[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = double.Parse(arr[i]);
            }
            return res;
        }
    }
}


Measured memory_bytes: 19144
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, p[100010], ans;

signed main() {
	cin >> n;
	rep(i, n) cin >> p[i];
	int i = 0;
	while (i < n) {
		if (p[i] == i + 1) {
			ans++;
			i += 2;
		}
		else i++;
	}
	cout << ans << endl;
	ggr
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	int i;
	char O[50],E[50],pass[100];
	scanf("%s",&O);
	scanf("%s",&E);
	for(i=0;;i++){
		if(O[i]!='\0'){
			pass[2*i]=O[i];
		}else{
			pass[2*i]='\0';
			break;
		}
		if(E[i]!='\0'){
			pass[2*i+1]=E[i];
		}else{
			pass[2*i+1]='\0';
			break;
		}
	}
	printf("%s\n",pass);
	return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        long g = sc.nextLong();
        List<List<Long>> list = new ArrayList<>();
        for (int i = 1; i <= d; i++) {
            int p = sc.nextInt();
            int c = sc.nextInt();
            List<Long> l = new ArrayList<>();
            for (int j = 0; j < p - 1; j++) {
                l.add(100l * i);
            }
            l.add(100l * i + c);
            list.add(l);
        }
        sc.close();

//        System.out.println(list);

        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < pow(2, d); i++) {
            String str = toBinaryString(i, d);
//            System.out.println(str);
            int num = 0;
            long sum = 0;
            for (int j = 0; j < str.length(); j++) {
                if (str.charAt(j) == '1') {
                    num += list.get(j).size();
                    sum += sum(list.get(j));
                }
            }

//            System.out.println("sum=" + sum + ", num=" + num);
            if (sum >= g && num <= ans) {
                ans = num;
            }

            int lastZeroIndex = str.lastIndexOf('0');
            if (lastZeroIndex >= 0) {
                for (int j = 0; j < list.get(lastZeroIndex).size(); j++) {
                    sum += list.get(lastZeroIndex).get(0);
                    num++;
                    if (sum >= g && num <= ans) {
                        ans = num;
                    }
                }
            }
        }
        System.out.println(ans);
    }

    static long sum(List<Long> list) {
        long ret = 0;
        for (Long l : list) {
            ret += l;
        }
        return ret;
    }

    // baseのn乗を計算を返す
    static int pow(int base, int n) {
        int ret = 1;
        for (int i = 0; i < n; i++) {
            ret *= base;
        }
        return ret;
    }

    // intをlength桁のbit文字列に変換
    static String toBinaryString(int input, int length) {
        return toBinaryString(input).substring(29 - length);
    }

    // intを29桁のbit文字列に変換
    static String toBinaryString(int input) {
        String ret = "";
        int max = 0x10000000;
        for (int i = 0; i < 29; i++) {
            int tmp = input / max;
            ret += tmp;
            input %= max;
            max /= 2;
        }
        return ret;
    }

}


Measured memory_bytes: 29396
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int n;
	cin >> n;
	int t = lcm(n, 360);
	cout << t / n << endl;
	return 0;
}

Measured memory_bytes: 3572
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

int main(){
	while(1){
		int n, m, k;
		int t[2][101][101];
		
		scanf(" %d %d", &n, &m);
		if(n==0) break;
		memset(t, -1, sizeof(t));
		
		for(int i=0; i<n; ++i){
			int a, b, time, cost;
			scanf(" %d %d %d %d", &a, &b, &cost, &time);
			t[0][a][b]=t[0][b][a]=cost;
			t[1][a][b]=t[1][b][a]=time;
		}
		
		scanf(" %d", &k);
		for(int i=0; i<k; ++i){
			int p, q, r;
			scanf(" %d %d %d", &p, &q, &r);
			long a[101]; //各駅までの最小値
			
			for(int j=0; j<=100; ++j) a[j]=50000000;
			
			//bfs
			queue<int> que;
			a[p]=0;
			que.push(p);
			while( !que.empty() ){
				int v=que.front();
				que.pop();
				for(int j=1; j<=m; ++j){
					if(t[r][v][j]>=0 && a[j]>t[r][v][j]+a[v]){
						a[j]=t[r][v][j]+a[v];	
						que.push(j);
					}
				}	
			}
			
			printf("%ld\n",a[q]);
		}
	}
}

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

int compare(const void * a, const void * b) {
  return *(int *)a - *(int *)b;
}

int main(void) {
  int n, a_sum=0, b_sum=0;
  scanf("%d", &n);
  int card[n];

  for (int i=0 ; i < n; i++) {
    scanf("%d", &card[i]);
  }
  qsort(card, n, sizeof(card[0]),compare);

  // ソートされてる時に最適な戦略
  for (int j=n-1; j > -1; j = j - 2) {
    if (j == 0) {
      a_sum += card[j];
    } else {
      a_sum += card[j];
      b_sum += card[j-1];
    }
  }
  printf("%d",a_sum - b_sum);
}

Measured memory_bytes: 1688
#include <iostream>

int main()
{
    while (true)
    {
        int h, w;
        std::cin >> h >> w;
        
        if (h == 0 && w == 0)
            break;
        
        for (int hh = 0; hh < h; ++hh)
        {
            for (int ww = 0; ww < w; ++ww)
                std::cout << ((hh + ww) % 2 == 0 ? '#' : '.');
            
            std::cout << std::endl;
        }
        
        std::cout << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
using lint = long int;
#define MOD 1000000007

int N;
lint A[200010];
lint sumA = 0;  //Aの和
lint res = 0;

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

    for(int i = 0; i < N; i++) sumA += A[i];
    sumA %= MOD;  //剰余

    for(int i = 0; i < N-1; i++){  //A[i]との積...A[i+1]~A[N-1]
        sumA -= A[i];
        if(sumA <= 0) sumA += MOD;  //sumAが0以下なら+MODでsumA<=MOD
        res += A[i] * sumA;  //long int範囲を超越しない演算
        res %= MOD;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>i) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL((a))), (a).end());} while(0)
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  VI A(M);
  REP(i, M) cin >> A.at(i);
  SORTG(A);

  VI dp(N+1, -INF);
  VI num = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  dp.at(0) = 0;

  REP2(i, 1, N+1)
  {
    REPx(x, A)
    {
      int tmp;
      if (i - num.at(x) < 0) continue;
      else tmp = dp.at(i-num.at(x)) + 1;
      dp.at(i) = max(tmp, dp.at(i));
    }
  }
  string ans = "";
  const int digit = dp.at(N);
  REP(i, digit)
  {
    REPx(x, A)
    {
      int idx = N - num.at(x);
      if (idx < 0) continue;
      if (dp.at(idx) == dp.at(N) - 1)
      {
        ans += to_string(x);
        N -= num.at(x);
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
   int R;
   cin >> R;
   if( R < 1200 ) cout << "ABC" << endl;
   else if( R > 1199 && R < 2800 ) cout << "ARC" << endl;
   else cout << "AGC" << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    int a,b,i;
    while(cin>>a>>b)
    {
        string s[1001];
        for(i=0;i<a;i++)
        {
            cin>>s[i];
        }
        sort(s+0,s+a);
        for(int j=0;j<a;j++)
            cout<<s[j];
    }
    return 0;
}


Measured memory_bytes: 3616
import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Control.Monad.Primitive
import Control.Applicative
import Control.Arrow
import Data.List
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import qualified Data.Sequence as Sq
import Data.Tuple
import Data.Function
import Text.Printf
import Debug.Trace
import Numeric


main :: IO ()
main = do
  [n,tmax] <- map read . words <$> getLine :: IO [Int]
  dat <- filter (\[c,t] -> t<=tmax) . map (map read . words) . lines <$> getContents :: IO [[Int]]

  if null dat then
    putStrLn "TLE"
    else
    print $ minimum $ map (\[c,_] -> c) dat
    


Measured memory_bytes: 1020
#include<stdio.h>
using namespace std;

int main(){
    int m,n;
    scanf("%d%d",&n,&m);
    int mat[100][100] = {};
    int vec[100] = {};
    int ans_vec[100] = {};
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d",&mat[i][j]);
        }
    }
    for(int j=0;j<m;j++){
        scanf("%d",&vec[j]);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            ans_vec[i]+=mat[i][j]*vec[j];
        }
    }
    for(int i=0;i<n;i++){
        printf("%d\n",ans_vec[i]);
    }
}


Measured memory_bytes: 2804
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		boolean allow = true;
		for(int i=0;i<n;i++) {
			int a = sc.nextInt();
			if(a%2==0 && a%3!=0 && a%5!=0)
				allow = false;
		}
		
		System.out.println(allow ? "APPROVED" : "DENIED");
	}
}


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

int main () {
  long long mod = 1000000007;
  long long X,Y;
  cin >> X >> Y;
  if ((X+Y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  if (X > (X+Y)*2/3 || Y > (X+Y)*2/3) {
    cout << 0 << endl;
    return 0;
  }
  long long N = (X+Y)/3;
  X -= N;
  Y = N - X;
  
  long long NN = 1;
  long long XX = 1;
  long long YY = 1;
  for (int i=1; i<=N; i++) {
    NN *= i;
    NN %= mod;
  }
  for (int i=1; i<=X; i++) {
    XX *= i;
    XX %= mod;
  }
  for (int i=1; i<=Y; i++) {
    YY *= i;
    YY %= mod;
  }
  long long XC,YC,XXX,YYY;
  XXX = XX;
  YYY = YY;
  for (int i=0; i<9; i++) {
    XC = XXX;
    YC = YYY;
    for (int j=0; j<9; j++) {
      XXX *= XC;
      XXX %= mod;
      YYY *= YC;
      YYY %= mod;
    }
  }
  for (int i=0; i<5; i++) {
    XXX *= XX;
    XXX %= mod;
    YYY *= YY;
    YYY %= mod;
  }

  long long ans = NN * XXX % mod;
  ans *= YYY;
  ans %= mod;
  
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int main()
{
    int i;
    int n,h,lh=0,flg=0;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++)
    {
        scanf("%d",&h);
        if(h > lh)
        {
            lh = h - 1;
        }
        else if(h < lh)
        {
            flg = 1;
        }
    }
    
    if(flg == 0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<pair<int, int>> v(2*n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &a[i], &b[i]);
        v[2*i] = {a[i], 2*i}, v[2*i+1] = {b[i], 2*i+1};
    }
    sort(v.begin(), v.end());
    vector<int> cnt(n);
    ll ans = 0; int p = 0;
    for (int i = 0; i < n; ++i) {
        cnt[v[i].second/2]++;
        p += v[i].second % 2;
        ans += v[i].first;
    }
    for (int i = 0; i < n; ++i) {
        if(cnt[i] > 1){
            cout << ans << "\n";
            return 0;
        }
    }
    if(p == n || p == 0){
        cout << ans << "\n";
        return -0;
    }
    if(v[n].second/2 == v[n-1].second/2){
        cout << ans +
            min(v[n+1].first - v[n-1].first,
                v[n].first - v[n-2].first) << "\n";
    }else {
        cout << ans + v[n].first - v[n-1].first << "\n";
    }
    return 0;
}


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		if(A + B + 1 >= C) {
			System.out.println(B + C);
		}else {
			long ans = A + 2 * B + 1;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll inf = 1LL << 60;

int main(){ 
  int N; ll M; cin >> N >> M;
  vector<ll> A(N);
  vector<ll> B(N+1);
  for(int i = 0; i < N; i++){ cin >> A[i];}
  
  sort(A.begin(),A.end());
  B[N] = 0;
  B[N-1] = A[N-1];
  
  for(int i = N-2; i >= 0; i--){ 
    B[i] = B[i+1]+A[i];
  }
 
  
  //ソート
  
  ll l = 0; ll r = inf;//ここ戻せ
  
  while( r - l > 1 ){ 
    
    ll d = l+(r-l)/2;
    
    ll cnt = 0;
    
    for(int i = 0; i < N; i++){ 
      
      // d-A[i]以上となるような人数を求める
      
      auto itr = lower_bound(A.begin(),A.end(),d-A[i])-A.begin();
      
      cnt += N-itr;
     
      
      
    }
    
   if(cnt >= M){ //　もっと下限を上げていい
      l = d;
    }
    else{
      r = d;
    }
  }
  // 最大の下限r発見
  
  r = l;
  
  ll ans = 0;
  ll how = 0;
  
 
  for(int i = 0; i < N; i++){
    //値がr-A[i]以上となるような要素の和をansにたす
    
    ll x = r-A[i];
    
    auto itr = lower_bound(A.begin(),A.end(),x)-A.begin();
    
    // A[itr],,A[N-1]までの和
    
    if( itr == N ){ continue;}
    
    how += N-itr;
    
    ans += B[itr]+A[i]*(N-itr);
      
  }
  
  //how-r個分はもっとも小さい要素を覗く
  
  
  if( how > M){ ans -= r*(how-M);}

  cout << ans << endl;
  
  return 0;
}
  

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll s[100];
int main(){
    int n;
    cin>>n;
    s[0]=2;s[1]=1;
    for(int i=2;i<=86;i++)
        s[i]=s[i-1]+s[i-2];
    cout<<s[n]<<endl;
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
    int n;
    string s; cin>>s;
    n=s.size();
    int ans=0;
    for(int i=0; i<n/2; i++){
        if(s[i]!=s[n-1-i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
	string s; cin >> s;

	if ((s[0] == s[1]) && (s[1] == s[2]))
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}

	return 0;
}


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

int calcMax(int v[], int n, int m){
    int ans = 0;
    for(int i=0;i<n;i++){
        int cnt = 1;
        for(int j=i;j<i+m;j++){
            if(j >= n) break;
            cnt *= v[j];
        }
        ans = max(ans,cnt);
    }
    return ans;
}

int main(){
    int n,m;
    while(cin >> n >> m && (n|m)){
        int v[100], ans[2];
        for(int i=0;i<n;i++) cin >> v[i];
        ans[0] = calcMax(v, n, m);
        ans[1] = 0;

        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                swap(v[i],v[j]);
                ans[1] = max(ans[1],calcMax(v,n,m));
                swap(v[i],v[j]);
            }
        }

        if(ans[1] - ans[0] < 0) cout << "NO GAME" << endl;
        else cout << ans[1] - ans[0] << endl;
    }
}

Measured memory_bytes: 864
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt() ;
		int[][] a = new int[2][n];
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < n; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int max = 0;
		int sum = 0;
		for(int i = 0; i <  n; i++) {
			for(int j = 0; j <= i; j++) {
				sum += a[0][j];
			}
			for(int k = n - 1; k >= i; k--) {
				sum += a[1][k];
			}
			if(sum>max) {
				max = sum;
			}
			sum = 0;
		}
		System.out.println(max);

	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
const ll MX = 1e12; 
const ll N =105;
const ll M =100005;
ll dp[N][100005],c[N],w[N];


int32_t main(){
    IOS;
    ll i,j,k,n,m,p,W;
    cin >> n >> W;
    fori2(n){
        cin >> w[i] >> c[i];
    }
    for(i = 0 ; i <= n ; i++){
        for(j = 1 ; j < M ; j++){
            dp[i][j] = MX;
        }
    }
    for(i =  1 ; i <= n ; i++){
        for(j = 1 ; j < M ; j++){
            dp[i][j] = min(dp[i-1][j],dp[i][j]);
            if(j >= c[i]){
                dp[i][j] = min(dp[i][j],dp[i-1][j-c[i]] + w[i]);
            }
        }
    }
    for(j = M - 1 ; j >= 0 ; j--){
        if(dp[n][j] <= W){
            cout << j <<"\n";
            return 0;
        }
    }
} 

Measured memory_bytes: 80128
import java.util.Scanner;

class Main {
	 public static void main(String[] args){
	        Scanner scan = new Scanner(System.in);
	        
	        int val[] = {1, 5, 4, 3, 2,6};
	    	
	    	int n;
	    	String dir;
	    	
	    	while (true) {
		    	Dice dice = new Dice(val);
	    		
	    		n = scan.nextInt();
	    		if (n == 0) break;
	    		
	    		for (int i = 0; i < n; i++) {
	    			dir = scan.next();
	    			if (dir.equals("north")) dice.noth();
	    			else if (dir.equals("east")) dice.east();
	    			else if (dir.equals("west")) dice.west();
	    			else if (dir.equals("south")) dice.south();
	    		}
	    	System.out.println(dice.getDice(0));
	    	}
	    }
}

class Dice {
    private int[] dice = new int[6];

    Dice() {
    	
    };

    Dice(int[] val) {
    	for (int i = 0; i < this.dice.length; i++) {
			this.dice[i] = val[i];
		}
    }

    void setDice(int i, int val) {
    	this.dice[i] = val;
    }

    int getDice(int i) {
    	return this.dice[i];
    }

    int[] getDice() {
    	return this.dice;
    }

	int[] noth() {
		swap(0, 1, 5, 4);
		return this.dice;
	}

	int[] east() {
		swap(0, 3, 5, 2);
		return this.dice;
	}

	int[] west() {
		swap(0, 2, 5, 3);
		return this.dice;
	}

	int[] south() {
		swap(0, 4, 5, 1);
		return this.dice;
	}

	int[] right() {
		swap(1, 2, 4, 3);
		return this.dice;
	}

	int[] left() {
		swap(1, 3, 4, 2);
		return this.dice;
	}

	void swap(int n1, int n2, int n3, int n4) {
		int swap = this.dice[n1];
		this.dice[n1] = this.dice[n2];
		this.dice[n2] = this.dice[n3];
		this.dice[n3] = this.dice[n4];
		this.dice[n4] = swap;
	}

	void dicePrint() {
		int i;
		for (i = 0; i < this.dice.length - 1; i++) {
			System.out.print(this.dice[i] + ", ");
		}
	}
}

Measured memory_bytes: 28752