akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#define H 12
#define W 12

using namespace std;

bool island[H][W];
bool arrived[H][W];

bool is_not_arrived(int x, int y) {
	if(x<0 || W<=x || y<0 || H<=y) return false;

	if(island[y][x] && !arrived[y][x]) {
		arrived[y][x] = true;
		is_not_arrived(x+1,y);
		is_not_arrived(x-1,y);
		is_not_arrived(x,y+1);
		is_not_arrived(x,y-1);
		return true;
	}

	return false;
}

int main() {
	while(true) {
		for(int i = 0; i < H; i++) {
			string s;
			cin >> s;
			for(int j = 0; j < H; j++) {
				island[i][j] = (s[j]=='1');
				arrived[i][j] = false;
			}
		}

		if(cin.eof()) break;

		int ans = 0;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if(is_not_arrived(j,i)) {
					ans++;
				}
			}
		}

		cout << ans << endl;
	}
}



Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long n,ans,s;
int main()
{
    scanf("%lld",&n);
    for(int i=sqrt(n);i>0;i--)
        if(n%i==0)
		{
            ans=n/i;
            break;
        }
    while(ans>0)
        s++,ans/=10;
    printf("%lld\n",s); 
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N = II()
res = 0
for i in range(1, N+1):
    n = N//i
    res += i*n*(n+1)//2

print(res)


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

int n, m;
long long a[100000];

int main()
{
    cin >> n >> m;

    int ans = 1;
    for(int a = 1; a * a <= m; a++){

        if(m % a != 0) continue;

        int b = m / a;

        if((long)a * n <= m) ans = max(ans, a);
        if((long)b * n <= m) ans = max(ans, b);
    }

    cout << ans << endl;
}

Measured memory_bytes: 888
#/*
	AUTHOR:shivam51
	IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  const ll mod=1e9+7;
  const ll MAX=2e5+1;
  //
  //
	void solve(){
		ll n,k;
		cin>>n>>k;
		int arr[n+1];
		rep(i,0,n)
			cin>>arr[i];
		arr[n]=k;
		sort(arr,arr+n+1);
		ll ans=(arr[1]-arr[0]);
		// cout<<ans;
		rep(i,2,n+1)
			ans=__gcd(ans,(ll)(arr[i]-arr[i-1]));
		cout<<ans;
	}
  int main(){ 
	hs;
	ll t;
	// cin>>t;
	t=1;
	while(t--)
	    solve();
	return 0; 
} 

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 3e6 + 5;

char s[MAXN];

int cntw[MAXN], cnte[MAXN];

void solve(){
	int n;
	scanf("%d%s", &n, &s[1]);
	REPN(i, 1, n){
		cntw[i] = cntw[i - 1] + (s[i] == 'W' ? 1 : 0);
		cnte[i] = cnte[i - 1] + (s[i] == 'E' ? 1 : 0);
	}
	int ans = n;
	REPN(i, 1, n){
		int cur = cntw[i - 1] + (cnte[n] - cnte[i]);
		ans = min(ans, cur);
	}
	printf("%d\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 7552
#include <iostream>
#include <algorithm>

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  int values[3];
  REP(i, 3) cin >> values[i];
  sort(values, values + 3);
  cout << values[0] + values[1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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; }

int main(){
	ll a,b,c,d;cin>>a>>b>>c>>d;
	cout << max(a*c,max(a*d,max(b*c,b*d))) << endl;
	return 0;
}

Measured memory_bytes: 3632
k=' key = '
input()
A=[0]+input().split()
H=len(A)
for i in range(1,H):
 print(f'node {i}: key = {A[i]}, {"parent"+k+A[i//2]+", "if i>1 else""}{"left"+k+A[2*i]+", "if 2*i<H else""}{"right"+k+A[2*i+1]+", "if 2*i+1<H else""}')


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

int main() {
    int N, K;
    cin >> N >> K;
    int num = 1;
    rep(i, N) {
        int num1 = num * 2;
        int num2 = num + K;
        num = min(num1, num2);
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#ifndef LOCAL
struct ostdmy{template<class T>ostdmy&operator<<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
bool solve(){
    int n;
    cin>>n;
    vi b(n);
    cin>>b;
    vi ans(n,-1);
    vector<bool> c(n,false);
    REP(i,n){
        int cnt=0;
        bool flag=false;
        cerr<<c<<endl;
        REPR(j,n){
            if(c[j]){
                cnt++;
                continue;
            }
            if(i-cnt+1==b[j]){
                flag=true;
                ans[i]=b[j];
                cerr<<':'<<b[j]<<endl;
                c[j]=true;
                break;
            }
        }
        if(!flag)return false;
    }
    cout<<ans<<endl;
    return true;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    if(!solve())cout<<-1<<endl;

    return 0;
}


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

int main(){
   int N,M;
   cin >> N;
   vector<int>T(N+1),d_T(N+1);
   for(int i=0;i<N;i++){
       cin >> T[i];
       d_T[i] = T[i];
   }
   cin >> M;
   vector<int>P(M+1),X(M+1);
   for(int i=0;i<M;i++){
       cin >> P[i] >> X[i];
   }
   for(int j=0;j<M;j++){
        int ans=0;
        d_T[P[j]-1] = X[j];
        for(int i=0;i<N;i++) ans += d_T[i];
        cout << ans << endl;
        for(int i=0;i<N;i++) d_T[i] = T[i];
   }

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#define _GLIBCXX_DEBUG//.at(i)を[i]と書いても許される
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
int  n ,m;

int main(){
	cin>>n>>m;
	int a = max(n,m);
	int b = min(n,m);//差が2以上なら無理なので0
	long long p = pow(10,9)+7;
	if(a-b>=2){
		cout<<0<<endl;
	}
	else{
		//まず、bを並べて、その間とかにaを並べていく
		long long A=1 ;
		long long B =1; 
		for(int i = 1; i<=b;i++){
			B *=i;
			B %=p;
		}
		if(a==b){
			B*=2;
			B %=p;
		}
		A *= B;
		for(int i = 1; i<=a ; i++){
			A *=i;
			A %=p;
		}
		cout<<A<<endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
long long n,m,k;
long long a=-1,b; 
int main() {
    cin>>n>>m>>k;
    if(n%k)a=n/k+1;
      else a=n/k;
    b=m/k;
	cout<<(b-a)+1<<endl;
    return 0;
}

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

int get_int() {
    int n = 0;
    int c = getchar_unlocked();
    if(c == 45) {
        c = getchar_unlocked();
        while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
        return -n;
    } else if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
int get_str(char *str) {
    int c;
    while((c = getchar_unlocked()) > 32) *str++ = (char)c;
    *str = 0;
    return c;
}
void put_int(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    if(n < 0) n = -n, putchar_unlocked('-');
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
void put_str(char *str) { while(*str) putchar_unlocked(*str++); }

typedef struct Node {
    int key;
    struct Node *left, *right;
} Node;
typedef struct BST {
    Node *root;
    size_t size;
} BST;
void bst_init(BST *BST) {
    BST->root = NULL;
    BST->size = 0;
}
void bst_insert(BST *BST, int key) {
    Node *new_node = malloc(sizeof(Node));
    new_node->key = key;
    new_node->left = NULL;
    new_node->right = NULL;
    Node *tmp;
    Node *root = BST->root;
    while(root != NULL) {
        tmp = root;
        if(key < root->key) root = root->left;
        else root = root->right;
    }
    if(BST->size == 0) BST->root = new_node;
    else if(key < tmp->key) tmp->left = new_node;
    else tmp->right = new_node;
    BST->size++;
}
int bst_find(Node *root, int key) {
    if(root == NULL) return 0;
    else if(root->key == key) return 1;
    else if(root->key > key) return bst_find(root->left, key);
    else return bst_find(root->right, key);
}
void bst_inorder(Node *root) {
    if(root == NULL) return;
    bst_inorder(root->left);
    putchar_unlocked(' '), put_int(root->key);
    bst_inorder(root->right);
}
void bst_preorder(Node *root) {
    if(root == NULL) return;
    putchar_unlocked(' '), put_int(root->key);
    bst_preorder(root->left);
    bst_preorder(root->right);
}
int main(int argc, char **argv) {
    BST BST;
    bst_init(&BST);
    int m = get_int();
    int key;
    char c[8];
    for(int i = 0; i < m; ++i) {
        get_str(c);
        switch(*c) {
        case 'i':
            key = get_int();
            bst_insert(&BST, key);
            break;
        case 'f':
            key = get_int();
            put_str(bst_find(BST.root, key) ? "yes\n" : "no\n");
            break;
        default:
            bst_inorder(BST.root);
            putchar_unlocked('\n');
            bst_preorder(BST.root);
            putchar_unlocked('\n');
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 14060
N,M = map(int,input().split())
a = [-1]*N
ans = 0
for i in range(M):
    s,c = map(int,input().split())
    if a[s-1] == -1:
        a[s-1] = c
    elif a[s-1] != c:
        ans = -1
        break
if a[0] == 0 and N>1:
    ans = -1
if ans != -1:
    if a[0] == -1 and N>1:
        a[0] = 1
    if a[0] == -1 and N == 1:
        a[0] = 0
    for i in range(N):
        if a[i] == -1:
            a[i] = 0
        a[i] = str(a[i])
    ans = "".join(a)
print(ans)


Measured memory_bytes: 9204
#include <stdio.h>
#include <string.h>

int main(){
	char op;
	int a,b;

	scanf("%d %d", &a,&b);

	if (a==b) {
		puts("Draw");
	}else if (a==1){
		puts("Alice");
	}else if (b==1){
		puts("Bob");
	}else if (a < b){
		puts("Bob");
	}else{
		puts("Alice");
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,f[N],si[N];
int getf(int x){return f[x]==x?x:f[x]=getf(f[x]);}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) f[i]=i,si[i]=1;
    for(int i=1;i<=m;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        u=getf(u);v=getf(v);
        if(u==v) continue;
        f[v]=u;
        si[u]+=si[v];
    }
    int ans=0;
    for(int i=1;i<=n;i++) ans=max(ans,si[i]);
    printf("%d\n",ans);
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int64_t  N;
  cin >> N;
  double a=sqrt(N);
  double x=floor(a);
  int64_t b;
  int ans=10000000;
  for(int i=1;i<x+1;i++){
    if(N%i==0){
      b=N/i;
      int j=1;
      long long c=pow(10,j);
      while(b/c>0){
        b=b/c;
        j++;
      }
      ans=min(j,ans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
 #define all(v) (v).begin(),(v).end()
 using ll = long long;
using Graph = vector<vector<int>>;
const int MAX = 510000;
const int MOD = 1000000007;
 
 
 
int main(){
ll n;
  cin>>n;
  vector<ll>op(3);
  rep(i,3) op.at(i)=0;
  ll ans=1;
  rep(i,n){
  ll p;
    cin>>p;
  ll t=0;
    ll k=0;
    if(op.at(0)==p) {
      t=t+1;
    }
    if(op.at(1)==p){
    t=t+1;;
      k=1;
    }
    if(op.at(2)==p){
    t=t+1;
      k=2;
    }
    ans=ans*t%MOD;
    op.at(k)=op.at(k)+1;
  }
cout<<ans<<endl;
  
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail)
{
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}

int dfs(VEC<VEC<int>> &g, int pos, VEC<bool> &used, int usedNum)
{
  int n = g.size();
  if (n == usedNum)
  {
    DUMP("inback");
    return 1;
  }
  else
  {
    int ans = 0;
    REP(i, 0, n)
    {

      if (g[pos][i] == 1 && !used[i])
      {
        DUMP(g, i, used, usedNum, ans);
        used[i] = 1;
        ++usedNum;
        ans += dfs(g, i, used, usedNum);
        --usedNum;
        used[i] = 0;
      }
    }
    return ans;
  }
}
int main()
{
  int n, m;
  cin >> n >> m;
  VEC<VEC<int>> g(n, VEC<int>(n, 0));
  REP(i, 0, m)
  {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a][b] = 1;
    g[b][a] = 1;
  }
  VEC<bool> used(n, 0);
  used[0] = 1;
  int ans = dfs(g, 0, used, 1);
  cout << ans << endl;

  return 0;
}


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

int main(void){
	int K,T;
	cin>>K>>T;
	vector<int> a(T);
	int dame=0;
	for(int i=0; i<T; ++i){
		cin>>a[i];
	}
	sort(a.begin(),a.end(),greater<int>());
	while(true){
		if(a[0]==0){
			break;
		}
		a[0]--;
		if(T<2){
			dame+=a[0];
			break;
		}
		if(a[1]==0){
			dame+=a[0];
			break;
		} else {
			a[1]--;
		}
		sort(a.begin(),a.end(),greater<int>());
	}
	cout<<dame<<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;
typedef long long int ll;

int main() {
  ll n, k; string t;
  int jp[3] = {0};
  char jan[3] = {'r', 's', 'p'};
  ll ans = 0;
  cin >> n >> k >> jp[0] >> jp[1] >> jp[2] >> t;
  for (int i = 0; i < n; i++) {
    rep(j, 3)
      if (jan[j] == t[i]) {
        if (i >= k && t[i] == t[i-k]) {
          t[i] = 'x';
          continue;
        }
        // cout<< i << " " << jp[(j+2)%3] << endl;
        ans += jp[(j+2)%3];
      }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, A;
  cin >> N;
  vector<int> As(N);
  
  for (int i = 0; i < N; i++) {
    cin >> As.at(i);
  }

  vector<int> tempAs = As;
  sort(tempAs.begin(), tempAs.end());
  
  if (tempAs.at(N-1) == tempAs.at(N-2)) {
    for (int i = 0; i < N; i++) {
      cout << tempAs.at(N-1) << endl;
    }
  }
  else {
    int place = 0;
    for (int j = 0; j < N; j++) {
      if (As.at(j) < tempAs.at(N-1))
        place++;
      if (As.at(j) == tempAs.at(N-1))
        break;      
    }    
    for (int i = 0; i < place; i++) {
      cout << tempAs.at(N-1) << endl;
    }
    cout << tempAs.at(N-2) << endl;
    for (int i = place + 1; i < N; i++) {
      cout << tempAs.at(N-1) << endl;
    }    
  }

}

Measured memory_bytes: 3200
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    printf("%.10f", w * h/2.0);
    if(2.0*x == w && 2.0*y == h){
        cout << " 1" << endl;
    }else{
        cout << " 0" << endl;
    }
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//end



int main(){
   int n; scanf("%d",&n);
   ll res=0; vector<ll> a(n),b(n);
   rep(i,0,n)scanf("%lld%lld",&a[i],&b[i]);
   rrep(i,n-1,-1){
      a[i]+=res;
      ll add=(a[i]+b[i]-1)/b[i]*b[i]-a[i];
      res+=add; 
   } printf("%lld\n",res);
   return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
  int i, j;
  int n;
  int a[1001];
  int current;

  scanf("%d", &n);

  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);

  for (i = 0; i < n; i++)
    if ( i < n - 1) {
      printf("%d ", a[i]);
    } else {
      printf("%d\n", a[i]);
    }

  for (i = 1; i < n; i++) {
    current = a[i];
    j = i - 1;
    while (j >= 0 && a[j] > current) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = current;

    for (j = 0; j < n; j++) {
      if (j < n - 1) {
        printf("%d ", a[j]);
      } else {
        printf("%d\n", a[j]);
      }
    }

  }

  return 0;
}



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

int main()
{
    int n,i,j;
    cin >> n;
    double a[n],dp[n+1][n+1],x1[n],y1[n];
    for(i=0;i<n;i++)
    cin >> a[i];
    dp[0][0]=1;
    for(i=0;i<n;i++)
    {
        if(i==0)
        {
            x1[i]=a[i];
            y1[i]=1-a[i];
        }
        else
        {
            x1[i]=a[i]*x1[i-1];
            y1[i]=y1[i-1]*(1-a[i]);
        }
    }
    for(i=1;i<=n;i++)
    {
        dp[i][0]=y1[i-1];
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(j>i)
            dp[i][j]=0;
            else
            dp[i][j]=a[i-1]*dp[i-1][j-1]+(1-a[i-1])*dp[i-1][j];
        }
    }
    
    int k=(n/2)+1;
    double s=0;
    for(i=k;i<=n;i++)
    s+=dp[n][i];
    cout << fixed << setprecision(15) << s <<endl; 
    return 0;
}


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

typedef long long lli;
typedef vector<int> Vi;
typedef vector<lli> Vl;
typedef pair<int, int> Pii;
typedef pair<lli, lli> Pll;


//===


int main()
{
	string S;
	cin >> S;
	
	int left, right;
	string tmp;
	tmp.push_back(S[0]);
	tmp.push_back(S[1]);
	left = atoi(tmp.c_str());
	tmp.clear();
	tmp.push_back(S[2]);
	tmp.push_back(S[3]);
	right = atoi(tmp.c_str());
	if (left > 0 && left <= 12 && right > 0 && right <= 12) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (left > 0 && left <= 12) {
		cout << "MMYY" << endl;
	}
	else if (right > 0 && right <= 12) {
		cout << "YYMM" << endl;
	}
	else {
		cout << "NA" << endl;
	}
}

Measured memory_bytes: 256
' Imports System.Collections.Generic
' Imports System.Linq
' Imports System.Text
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim a = Console.ReadLine()
        Dim s = Console.ReadLine()
        Console.WriteLine(If(3200 <= a, s, "red"))
        Return
    End Sub
End Class

Measured memory_bytes: 28096
import sys
import collections
input = sys.stdin.readline

n = int(input())
v = list(map(int, input().split()))

v_even = v[::2]
v_odd = v[1::2]

c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)

most_even = c_even.most_common(2)
most_odd = c_odd.most_common(2)

if most_even[0][0] != most_odd[0][0]:
    print(n - most_even[0][1] - most_odd[0][1])
elif len(most_even) == len(most_odd) == 1:
    print(int(n/2))
else:
    if most_even[0][1] > most_odd[0][1]:
        print(n - most_even[0][1] - most_odd[1][1])
    elif most_even[0][1] < most_odd[0][1]:
        print(n - most_odd[0][1] - most_even[1][1])
    else:
        print(n - most_even[0][1] - max(most_even[1][1], most_odd[1][1]))

Measured memory_bytes: 19104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		Arrays.sort(s);
		Arrays.sort(t);
		int l = Math.min(s.length, t.length);
		boolean check = false;
		int c = 0;
		for(int i = 0; i < l; i++) {
			if(s[i] < t[t.length-1-i]) {
				check = true;
				break;
			}else if(s[i] == t[t.length-1-i]){
				c++;
			}
		}
		if(c == l && s.length < t.length) {
			check = true;
		}

		if(check) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


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

#define REP(i,n) for(int i=0;i<(n);i++)

using namespace std;

int game(int num, int pebbles){
    int cand[num];
    REP(i,num) cand[i] = 0;

    int cnt = 0, p = pebbles, ans;
    while(true){
        int turn = cnt % num;
        cnt++;
        if(p == 0){
            if(cand[turn] == 0) continue;
            p += cand[turn];
            cand[turn] = 0;
        }else{
            p--;
            cand[turn]++;
            if(cand[turn] == pebbles){
                ans = turn;
                break;
            }
        }
    }
    return ans;
}

int main(){
    int n, p;
    while(cin >> n >> p){
        if(n == 0 && p == 0) break;
        int ans = game(n, p);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include <iomanip>
#include <cstdio>
using namespace std;
int main(void){
  int a,b;
  cin>>a>>b;
  cout<<(int)a/b<<" "<<a%b<<" ";
  cout << fixed << setprecision(5) << (double)a/b << endl; // C++
  return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i=0; i<(int)(n); ++i)
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

string r(string s){
  string r1 = s.substr(0, 1);
  string r2 = s.substr(1, s.size()-1);
  return r2+r1;
}

int main() {
  string S, T;
  cin >> S >> T;
  if(S==T){
    cout << "Yes" << endl;
    return 0;
  }
  string ans = "No";
  REP(i, S.size()){
    S = r(S);
    if(S == T) {
      ans = "Yes";
      break;
    }
  }
  cout << ans << 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();
        int[] T = new int[n + 1];

        for(int i = 1; i <= n; i ++){
            T[i] = sc.nextInt();
        }

        for(int i = 1; i <= n ; i ++){
            System.out.print("node " + i + ": key = " + T[i] + ", ");
            if(i/2 > 0){
                System.out.print("parent key = " + T[i/2] + ", ");
            }

            if(2*i <= n){
                System.out.print("left key = " + T[2*i] + ", ");
            }

            if((2*i + 1) <= n){
                System.out.print("right key = " + T[2*i + 1] + ", ");
            }
            System.out.println();
        }

    }


}


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

#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define itr vi:iterator
#define vpll vector < pair<long long,long long> >
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define pdd pair<double, double>

#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)

using namespace std;

int main(){

    // ios::sync_with_stdio(0);
    // cin.tie(0); cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif

    vi v(3);
    rep(i, 3) cin >> v[i];
    sort(all(v));
    int res = v[0]+v[1];
    cout << res;



    //cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
        Reader in = new Reader();
        int n = in.nextInt();
        int m = in.nextInt();
        int sum = 0;
        for (int i=0;i<m;i++)
            sum += in.nextInt();
        System.out.println(Math.max(-1, n - sum));
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}


Measured memory_bytes: 32448
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main ()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(c<=a+b){
      cout<<c+b<<endl;
  }
  if(c>a+b){
      cout<<a+b+b+1<<endl;
  }

  
}


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

int main(){
    int minNum=1000;
    string S;
    cin >> S;
    int tmp;

    for(int i=0; S[i+2]!='\0'; i++){
	tmp =atoi(S.substr(i, 3).c_str());
	tmp = abs(tmp -753);
	minNum = min(tmp, minNum);
    }
    
    cout << minNum << endl;    
}


Measured memory_bytes: 256
n, k = map(int, input().split())
x = list(map(int, input().split()))

x_neg = []
x_pos = []
for xx in x:
    if xx < 0:
        x_neg.append(-xx)
    else:
        x_pos.append(xx)
x_neg = x_neg[::-1]

ans = float('inf')
if k <= len(x_neg):
    ans = min(ans, x_neg[k-1])
if k <= len(x_pos):
    ans = min(ans, x_pos[k-1])

for i in range(1, k):
    j = k - i
    if i <= len(x_pos) and 1 <= j <= len(x_neg):
        d1 = x_pos[i - 1]
        d2 = x_neg[j - 1]
        d = min(d1, d2) * 2 + max(d1, d2)
        ans = min(ans, d)
print(ans)


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

int main()
{
 long int n;
  cin>>n;
  long int sum=0;
  for(int i=1;i<=n;i++)
  {
    if(i%3==0&&i%5==0)
    {
      continue;
    }
    else if(i%3==0)
    {
      continue;
    }
    else if(i%5==0)
    {
      continue;
    }
    else
    {
      sum+=i;
    }
  }
  cout<<sum;
 
  return 0;
}

Measured memory_bytes: 3596
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N,M;
    R(N,M);
    W(N*(N-1)/2+M*(M-1)/2);
    return 0;
}


Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
ll dp[2][4];
int now = 0;
int t[3];
ll p2[32];
bool use[100010];
void Sequence() {

	string o,e;
	cin >> o >> e;
	int si = o.size() + e.size();
	string s(si,' ');
	int i = 0;
	int j = 0;
	for (size_t k = 0; k < si; k++)
	{
		if (k % 2 == 0) s[k] = o[i++];
		else s[k] = e[j++];
	}
	cout << s << endl;
}
int main() {
	Sequence();
	return 0;
}



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

#define fast ios_base::sync_with_stdio; cin.tie(0); cout.tie(0)
#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
//#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))
const long double pi=3.14159265359;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{fast;
 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 #endif
 int t=1,n;
 //cin>>t;
 while(t--)
 {ll b=0;
  string s;
  ll a;
  cin>>a;
  cin>>s;
  rep(i,0,s.length()){
    if(s[i]=='.'){
        continue;
    }
    int x=s[i]-48;
    b=b*10+x;
  }
  ll x=a*b;
  cout<<x/100;
 }
 return 0;
}


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

int main(){
    string a,b;
    cin >> a >> b;
    char ans;
    if (a < b){
        ans = '<';
    }else if (a > b){
        ans = '>';
    }else{
        ans = '=';
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long x;
  unsigned long long a = 100;
  cin >> x;
  for (unsigned long long i = 0; i < x; i++) {
    a += a/100;
    if (a >= x) {
      cout << i+1 << endl;
      break;
    }
  }
}

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) { cin >> a[i]; }
    vector<ll> b(n);
    rep(i, n) { b[a[i] - 1] = i + 1; }
    rep(i, n) {
        if (i != n - 1)
            cout << b[i] << " ";
        else
            cout << b[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4840
@A=glob<>;
@l=<>;
printf sort{$a-$b}map{
	@v=//;
	$x=-30;
	for(0..@l){
		if($t=$'>>2*$_&3){
			$v[$t]+=$l[$_];
			$x+=10
		}
	}
	for(1..3){
		$x+=abs$A[$_]-($v[$_]||1e9)
	}
	$x
}1..1<<2*@l


Measured memory_bytes: 9472
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<list>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<limits>
#include<unordered_map>
#include<cctype>
#include<complex>
#pragma warning(disable:4996)
using namespace std;

#define debug(i) cout<<"<debug> "<<#i<<" "<<i<<" <\\debug>"<<endl
#define mfor(i,a,b) for(int i=(a);i<=(b);i++)
#define mrep(i,a,b) for(int i=(a);i>=(b);i--)
#define lll __int128
#define Re register
#define mem(a,b) memset(a,(b),sizeof(a))
#define Design ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
typedef pair<int, int> intpair;
typedef pair<long long int, long long int> llpair;
typedef long long int ll;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;

//#pragma comment(linker, "/STACK:1024000000,1024000000") 

const int maxn = 1e6 + 10;
int a[maxn];

int gcd(int a, int b)
{
	if (!b) return a;
	return gcd(b, a % b);
}

map<int, bool>ext;

bool getdivor(int x)
{
	for (int i = 2; i * i <= x; i++)
	{
		if (x % i) continue;
		if (ext[i]) return false;
		ext[i] = true;
		while (x % i == 0)
		{
			x /= i;
		}
	}
	if (x != 1)
	{
		if (ext[x]) return false;
		ext[x] = 1;
		return true;
	}
	return true;
}

int main()
{
	Design;
	int n;
	cin >> n;
	mfor(i, 1, n) cin >> a[i];
	int t = a[1];
	bool f = true;
	mfor(i, 2, n)
	{
		int g = gcd(t, a[i]);
		if (g != 1)
		{
			f = false;
		}
		t = g;
	}
	mfor(i, 1, n)
	{
		if (!getdivor(a[i]))
		{
			f = false;
			break;
		}
	}
	if (t != 1) cout << "not coprime";
	else if (f) cout << "pairwise coprime";
	else cout << "setwise coprime";
}

Measured memory_bytes: 7012
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> position(n + 1);
	FOR(i, 0, n) {
		scanf("%d", &a[i]);
		position[a[i]] = i;
	}
	set<int> border;
	long long sumx = 0;
	FOR(i, 1, n + 1) {
		int nowpos = position[i];

		auto pos = border.upper_bound(nowpos);

		int ub, lb;
		if (border.size() == 0) {
			ub = n, lb = -1;
		}

		else if (pos == border.end()) {
			ub = n;
			lb = *border.rbegin();
		}
		else {
			ub = *pos;
			if (pos == border.begin())
				lb = -1;
			else
				lb = *(--pos);
		}

		long long left = nowpos - lb - 1;
		long long right = ub - nowpos - 1;
		if (left < right)
			swap(left, right);

		long long toadd = (long long)i*(right + 1)*(left + 1);
		sumx += toadd;
		border.insert(nowpos);
	}
	cout << sumx << endl;


	return 0;
}

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

int main()
{
  int x[5];
  
  cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
  
  for(int i=0; i<5; i++)
    if(x[i] == 0)
    {
      cout << i+1 << endl;
      break;
    }
  
 return 0; 
}


Measured memory_bytes: 3632
#include <stdio.h>
int main() {
	char s[9];
	int i;
	int max = 0;
	int count = 0;
	scanf("%s",&s);
	for (i = 0; i <= 9; i++) {
		if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') {
			count++;
			if (count > max) {
				max = count;
			}
		}
		else {
			count = 0;
		}
	}
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,c;
    cin>>n>>m>>c;
    int a[n][m];
    int b[m];
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    int count=0;
    for(int i=0;i<n;i++){
        int x=0;
        for(int j=0;j<m;j++){
            x+=(a[i][j]*b[j]);
        }
        x+=c;
        if(x>0){
            count++;
        }
    }
    cout<<count<<endl;

    
    return 0;
    
}



Measured memory_bytes: 256
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1000000007
#define mxval 1e9 + 7
#define grt [](auto x,auto y){return x>y;}
#define pii pair<int,int>
/*********VARIABLE****************/
using namespace std;
int i,j,n,m,k,l,q,t,a,b,sum[3],tot[3],cnt[3];
/*********FUNCTIONS**************/
int powom(int a,int b) {
    int result = 1;
    while (b > 0) {
        if (b & 1)
            result = result * a;
        a = a * a;
        b >>= 1;
    }
    return result;
}
/***********MAIN**************/
vector<int> gh[200001],wght(200001);
vector<bool> visit(200001);
void dfs(int src,int val){
    wght[src]+=val;
    visit[src]=1;
    for(auto x : gh[src]){
        if(!visit[x]){
            dfs(x,wght[src]);
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>q;
    fri(0,n-2){
        cin>>a>>b;
        gh[a].pb(b);
        gh[b].pb(a);
    }
    while(q--){
        int p,x;
        cin>>p>>x;
        wght[p]+=x;
    }
    dfs(1,0);
    fri(1,n){
        cout<<wght[i]<<" ";
    }
    return 0;
}
//.........

Measured memory_bytes: 24320
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
	
}

int main()
{
	int N,K,R,S,P,ans=0;
	string T;
	cin>>N>>K>>R>>S>>P;
	cin>>T;
	for(int i=0;i<T.length();i++)
	{
		if(i<K||T[i]!=T[i-K])ans+=(T[i]=='r'?P:(T[i]=='s'?R:S));
		else T[i]='f';
	}
	cout<<ans;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const long long N=2e5+520;
long long ans,n,f[N],t,lt,c[N],tot,cnt,sum[N];
struct node
{
	long long a,b;
}gjj[N];
inline bool cmp(node x,node y)
{
	return y.a*(x.b+1)<x.a*(y.b+1);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>n>>t;
	lt=35;
	for(long long i=1;i<=n;i++)
	{
		long long x,y;
		cin>>x>>y;
		if(x==0)
		c[++tot]=y+1;
		else
		{
			gjj[++cnt].a=x;
			gjj[cnt].b=y;
		}
	}
	sort(gjj+1,gjj+cnt+1,cmp);
	sort(c+1,c+tot+1);
	for(long long i=1;i<=tot;i++)
	sum[i]=sum[i-1]+c[i];
	//for(long long i=1;i<=cnt;i++)
	//cout<<gjj[i].a<<' '<<gjj[i].b<<endl;
	for(int i=0;i<=lt;i++)
	f[i]=t+1;
	f[0]=0;
	//cout<<lt<<endl;
	for(long long i=1;i<=cnt;i++)
	for(long long j=lt;j>=1;j--)
	f[j]=min(f[j],(f[j-1]+1)*(gjj[i].a+1)+gjj[i].b);
	//for(long long i=0;i<=min(cnt,lt);i++)
	//cout<<f[cnt][i]<<endl;
	for(long long i=0;i<=lt;i++)
	if(f[i]<=t)
	{
		if(tot)
	    ans=max(i+(upper_bound(sum+1,sum+tot+1,t-f[i])-(sum+1)),ans);
	    else
	    ans=max(i,ans);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6684