akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
	string s, t;
	cin >> s >> t;
	int a, b; cin >> a >> b;
	string u; cin >> u;
	if (u == s) cout << a - 1 << ' '<< b << endl;
	if (u == t) cout << a <<' ' <<  b - 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> data(N, -1);
    rep(i, M){
        int si, ci;
        cin >> si >> ci;
        if(data[si - 1] == -1){
            data[si - 1] = ci;
        } else {
            if(data[si - 1] != ci){
                cout << "-1" << endl;
                return 0;
            }
        }
    }
    rep(i, N){
        if(i == 0 && N != 1){
            if(data[i] == 0){
                cout << "-1" << endl;
                return 0;
            }
            if(data[i] == -1){
                data[i] = 1;
            }
        } else {
            if(data[i] == -1){
                data[i] = 0;
            }
        }
    }
    for(int x: data){
        cout << x;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<iomanip>
using namespace std;



int main() {
	int x,y;
	cin >> x >> y;
	if (x == 2 || y == 2){
		cout << "No" << endl;
	}
	else{
		if(x==4 || x==6 || x==9 || x==11){
			if(y==4 || y==6 || y==9 || y==11){
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
		}else{
			if (y==4 || y==6 || y==9 || y==11){
				cout << "No" << endl;
			}else{
				cout << "Yes" << endl;
			}
		}

	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string s;

int main(void){
    
    cin >> s;
    
    s[3] = '8';
    cout << s << endl;
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true)
    {
        int n, r;
        cin >> n >> r;
        if (n == 0 && r == 0)
        {
            break;
        }
        vector<int> hanahuda;
        for (int i = n; i >= 1; i--)
        {
            hanahuda.push_back(i);
        }
        for (int i = 0; i < r; i++)
        {
            vector<int> tmp1, tmp2, tmp3;
            int p, c;
            cin >> p >> c;
            for (int j = 0; j < p - 1; j++)
            {
                tmp2.push_back(hanahuda[j]);
            }
            for (int j = p - 1; j < p + c - 1; j++)
            {
                tmp1.push_back(hanahuda[j]);
            }
            for (int j = p + c - 1; j < n; j++)
            {
                tmp3.push_back(hanahuda[j]);
            }
            hanahuda.clear();
            for (int i = 0; i < (int)tmp1.size(); i++)
            {
                hanahuda.push_back(tmp1[i]);
            }
            for (int i = 0; i < (int)tmp2.size(); i++)
            {
                hanahuda.push_back(tmp2[i]);
            }
            for (int i = 0; i < (int)tmp3.size(); i++)
            {
                hanahuda.push_back(tmp3[i]);
            }
        }
        cout << hanahuda[0] << endl;
    }
}


Measured memory_bytes: 3012
#include <iostream>
#include <algorithm>
int main(){

int n = 0,a[100];
int count = 0,answer = 0;

std::cin>>n;
for(int i = 0; i<n;i++){
std::cin>>a[i];
}
for(int i = 0;i < n;i++){
if(a[i] == 1){
count++;
}
answer=std::max(answer,count);
if(a[i] == 0){
count = 0;
}
}
std::cout << answer+1 << std::endl;
}


Measured memory_bytes: 3076
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int N, K, D;
	cin >> N >> K;
	vi b(10);
	REP(i, K) {
		cin >> D;
		b[D]++;
	}

	int tmp = N, ans;
	while (true) {
		ans = tmp;
		while (tmp > 0) {
			int p = tmp % 10;
			if (b[p]) {
				break;
			}
			tmp /= 10;
		}
		if (tmp == 0) {
			break;
		}
		tmp = ans + 1;
	}

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

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    vector<bool> win(k+1, 0);
    for(int i = 1; i <= k; i++){
        for(int j = 0; j < n; j++){
            if(a[j] > i)    break;
            win[i] = win[i] | !win[i-a[j]];
        }
    }
    cout << (win[k] ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 256
n,k,q,*a=map(int,open(0).read().split())
ans=10**18
for y in set(a):
  c=[]
  tmp=[]
  for aa in a:
    if aa>=y:
      tmp.append(aa)
    else:
      if len(tmp)>=k:
        c+=sorted(tmp)[:len(tmp)-k+1]
      tmp=[]
  if len(tmp)>=k:
    c+=sorted(tmp)[:len(tmp)-k+1]
  if len(c)>=q:
    c.sort()
    x=c[q-1]
    ans=min(ans,x-y)
print(ans)

Measured memory_bytes: 3316
import java.util.Scanner;


public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		for(;;)
		{
			int w = scanner.nextInt();
			int h = scanner.nextInt();
			
			if(w==0 && h==0)
			{
				break;
			}
			
			for(int i=0; i<w; i++)
			{
				for(int j=0; j<h; j++)
				{
					if((j==0||j==h-1) || (i==0||i==w-1))
					{
						System.out.print("#");
					}
					else
					{
						System.out.print(".");
					}
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 33928
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int w, h;
  cin >> w >> h;
  VL p(w);
  VL q(h);
  typedef pair<ll, int> PLI;
  vector<PLI> que(w + h);
  REP(i, 0, w) {
    cin >> p[i];
    que[i] = PLI(p[i], i);
  }
  REP(i, 0, h) {
    cin >> q[i];
    que[w + i] = PLI(q[i], w + i);
  }
  sort(que.begin(), que.end());
  ll sum = 0;
  int cw = 0;
  int ch = 0;
  REP(i, 0, que.size()) {
    PLI cur = que[i];
    if (cur.second >= w) {
      sum += cur.first * (w + 1 - cw);
      ch++;
    } else {
      sum += cur.first * (h + 1 - ch);
      cw++;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;
template <class T, class U>
void chmin(T& t, const U& u) {
  if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
  if (t < u) t = u;
}

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

Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define P pair<ll,ll>
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	ll n; cin >> n;
	if(n%2){
		cout << 0 << endl;
	}else{
		n/=10;
		ll ans = 0;
		while(n){
			ans += n; 
			n/=5;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >>s;
  
  vector<int> a(1000000);
  a.at(0)=s;
  bool c=0;
  for(int i=0;i<1000000;i++){
    if(a.at(i)%2==0){
      a.at(i+1)=a.at(i)/2;
    }
    else if(a.at(i)%2==1){
      a.at(i+1)=3*a.at(i)+1;
    }
    for(int j=i;j>-1;j--){
      if(a.at(i+1)==a.at(j)){
        c=1;
        break;
      }
    }
    if(c){
      cout <<i+2<<endl;
      break;
    }
  }
}
  

Measured memory_bytes: 4096
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T> 
void print(vector<T> &x) {
    int n = x.size();
    REP(i,n) {
        if (i != n-1) cout << x[i] << " ";
        else cout << x[i] << endl;
    }
}

int main(int argc, char const *argv[]) {
    int n,m;
    cin >> n >> m;
    vector<int> a(n+1,0);
    REP(i,m) {
        int x;
        cin >> x;
        a[x] = 1;
        if (x != 0 && a[x-1] == 1) {
            cout << 0 << endl;
            return 0;
        }
    }
    vector<ll> dp(n+1);

    dp[0] = 1;
    dp[1] = 1;
    if (a[1] == 1) dp[1] = 0;

    for (int i = 2; i <= n; ++i) {
        if (a[i] != 1) dp[i] = (dp[i-1]+dp[i-2])%MOD;
    }
    cout << dp[n] << endl;


    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
void trace(int a[],int n)
{
    for(int i=0;i<n;i++)
    {
        if (i > 0)
            cout << " ";
        cout << a[i];
    }
    cout<<endl;
}
void insertionSort(int a[],int n)
{
    int i,j,sum;
    for(i=1;i<n;i++)
    {
        sum=a[i];
        j=i-1;
        while(j>=0&&a[j]>sum)
        {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=sum;
        trace(a,n);
    }
}
int main()
{
    int n,i;
    cin>>n;
    int a[100];
    for(i=0;i<n;i++)
        cin>>a[i];
    trace(a,n);
    insertionSort(a,n);
    return 0;
}


Measured memory_bytes: 3084
using System;

class ITP1_5_A
{
    public static void Main()
    {
        int[] H = new int[10000];
        int[] W = new int[10000];
        int count = 0;

        for (; ; count++)
        {
            string[] Input = Console.ReadLine().Split(' ');
            if (Input[0] == "0" && Input[1] == "0")
                break;
            H[count] = int.Parse(Input[0]);
            W[count] = int.Parse(Input[1]);
        }

        for (int k = 0; k < count; k++)
        {
            for (int i = 0; i < H[k]; i++)
            {
                for (int j = 0; j < W[k]; j++)
                {
                    Console.Write("#");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 8908
import sys
sys.setrecursionlimit(10**6)

N = input()
W = [[] for _ in range(N)]
E = [[] for _ in range(N)]
for i in range(N-1):
  u, v, w = map(int, raw_input().split())
  E[u-1] += [v-1]
  W[u-1] += [w]
  E[v-1] += [u-1]
  W[v-1] += [w]

ans = [0]*N
def f(v, p, c):
  ans[v] = c
  for e, w, in zip(E[v], W[v]):
    if e!=p:
      f(e, v, c if w%2==0 else 1-c)
f(0, -1, 0)

for a in ans:
  print a


Measured memory_bytes: 90792
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
    long long int N;
    cin >> N;

    int max;
    int keta = 0;
    bool flag = false;


    max = N;
    while(N != 0) {
        int y = N % 10;
        N /= 10;
        keta++;
        if (N == 0) break;
        if (y != 9) flag = true;
        max = N;
    }

    // cout << keta << ":" << max << endl;

    long long int ans = 0;
    if (keta != 1) {
        if (flag) {
            for (int i = 0; i < keta - 1; i++) {
                ans += 9;
            }
            ans += max - 1;
        } else {
            for (int i = 0; i < keta - 1; i++) {
                ans += 9;
            }
            ans += max;
        }
    } else {
        ans = max;
    }
     cout << ans << endl;   
}

Measured memory_bytes: 256
# coding:utf-8

import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    A = LI()

    B = [0]
    for a in A:
        B.append(B[-1] + a)
    C = Counter(B)

    res = 0
    for c in C.values():
        res += c * (c - 1) // 2

    return res


print(main())


Measured memory_bytes: 41720
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

template <class T>
class WeightedUnionFind {
  int n;
  vector<int> par,sz;
  vector<T> w;
  // weight[i] : iがpar[i]よりどれだけ重いか
public:
  WeightedUnionFind(){}
  WeightedUnionFind(int _n) : n(_n) {
    par.resize(n, -1);
    sz.resize(n, 1);
    w.resize(n, 0);
  }
  int find(int i){
    if(par[i] < 0){
      return i;
    } else {
      int p = find(par[i]);
      w[i] += w[par[i]];
      par[i] = p;
      return p;
    }
  }
  T weight(int x){
    find(x);
    return w[x];
  }
  bool same(int x, int y){
    return find(x) == find(y);
  }
  // weight[i] +w の位置に j を配置
  void unite(int i, int j, T nw){
    nw += weight(i) - weight(j);
    int x = find(i), y = find(j);
    if(x == y) return;
    if(sz[x] < sz[y]){
      swap(x, y);
      nw = -nw;
    }
    sz[x] += sz[y];
    par[y] = x;
    w[y] = nw;
  }
  // x からみた y の相対位置
  T diff(int x, int y){
    return weight(y) - weight(x);
  }
};

int main(){
  int n,m;
  while(cin>>n>>m, n|m){
    WeightedUnionFind<long> uf(n);
    rep(i,m){
      char s[5];
      int a,b;
      cin>>s>>a>>b;
      a--;b--;
      if(s[0]=='?'){
        if(uf.same(a,b)) cout << uf.diff(a,b) << endl;
        else cout << "UNKNOWN" << endl;
      } else {
        long c;
        cin>>c;
        uf.unite(a, b, c);
      }
    }
  }

  return 0;
}



Measured memory_bytes: 4336
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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 const INF = 1001001001;


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

ll N,D,A;
cin >> N >> D >> A;

set<ll> v;
map<ll, ll> hp;
map<ll, ll> add;
D *= 2;
rep(i,N) {
    ll x,h;
    cin >> x >> h;
    v.insert(x);
    v.insert(x + D);
    hp[x] = h;
}

ll ans = 0;
ll cur = 0; // imos

for(auto x : v) {
    ll cnt = (max((ll)0, hp[x] - cur) + A - 1) / A;
    ans += cnt;
    cur += A * cnt;
    add[x + D] = A * cnt;
    cur -= add[x];
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 81536
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
 
 
int main(){
	int n;
	string s;
	int i,j;
	int temp;
	int dx[4] = {-1,0,0,1};
	int dy[4] = {0,-1,1,0};
	char ac[2] = {'A','C'};
	
 
	cin >> s;
	
	
	REP(i,s.size()){
		if(s[i]==ac[0]){
			if(s[i+1]==ac[1]){
				printf("Yes\n");
				return 0;
			}	
		}
	}
	
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
# i回操作をする = K個のボールがi箇所に分かれている
# 赤　赤　赤　赤　赤
# 赤のボールの隙間は、赤の個数 + 1 (両端含む) = 6
# この隙間の数に対して i 箇所を選ぶ
# 青のボール3個を2箇所に入れる場合、たとえば
# 赤　赤　青青　赤　赤　青　赤
# あるいは
# 青青　赤　赤　赤　赤　赤　青
# 6箇所から2箇所選ぶため、6C2
# (赤の数+1) C i　・・・★
# さらにこの2箇所に対して、最低1個を入れる組み合わせを求める
# これは
# 青　青　青
# のうちの1箇所に敷居を入れる方法なので
# 青 | 青　青
# 青　青 | 青
# の2通り
# (青の数-1) C (i-1) # ただしi>1
# これを★と掛け合わせる

from functools import reduce
def nCr(n,r,DIV):
  if r<n-r:
    r=n-r
  if r==0:
    return 1
  f=lambda x,y:x*y%DIV
  X=reduce(f,range(n-r+1,n+1))
  Y=reduce(f,range(1,r+1))
  return X*pow(Y,DIV-2,DIV)%DIV

N,K=map(int,input().split())
B = K
R = N-K

DIV = 10**9 + 7
for i in range(1,K+1):
  # (赤の数+1) C i　・・・★
  print((nCr(R+1,i,DIV) * nCr(B-1,i-1,DIV))%DIV)


Measured memory_bytes: 3940
#include<iostream>
#include<cmath>
using namespace std;
bool isPrime(int n)
{
	if (n < 2)
		return false;
	if (n == 2)
		return true;
	if (n % 2 == 0)
		return false;
	for (int i = 3; i <= sqrt(n); i += 2)
		if (n%i == 0)
			return false;
	return true;
}
int main()
{
	while (true)
	{
		int a, d, n;
		cin >> a >> d >> n;
		if (!a && !d && !n)
			break;
		int i = a;
		int cnt = 0;
		int ans = -1;
		while (true)
		{
			if (isPrime(i))
				cnt++;
			if (cnt == n)
			{
				ans = i;
				break;
			}
			i += d;
		}
		cout << ans << endl;
	}
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, k, ans;
int a[N];

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n, greater<int>());
    for (int i = 0; i < k; ++i) {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;


static class P
{
    static void Main()
    {
        var nh = Console.ReadLine().Split().Select(int.Parse).ToArray();
        //先に全部投げることを考える?
        List<Tuple<int, int>> list = new List<Tuple<int, int>>();
        for (int i = 0; i < nh[0]; i++)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            list.Add(new Tuple<int, int>(ab[0], 0));
            list.Add(new Tuple<int, int>(ab[1], 1));
        }
        var h = nh[1];
        int count = 0;
        foreach (var item in list.OrderByDescending(x => x.Item1))
        {
            if (item.Item2 == 0)
            {
                var c = (h + item.Item1 - 1) / item.Item1;
                count += c;
                h -= c * item.Item1;
            }
            else
            {
                count++;
                h -= item.Item1;
            }
            if (h <= 0) break;
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 31036
n, m = map(int,input().split())

min = -1
max = 1000000
for i in range(m):
    l, r = map(int,input().split())
    if min < l: min = l
    if r < max: max = r
    if max < min:
        print(0)
        break
else:
    print(max - min + 1)

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

using namespace std;

unsigned long long gcd(unsigned long long a, unsigned long long b) {
    unsigned long long c;
    if(a<b) {
        c = a;a = b; b = c;
    }

    while(b>0uLL) {
        c = b; b = a%b; a = c;
    }
    return a;
}

int main(int argc, char const *argv[])
{
    int n; cin >> n;
    vector<unsigned long long> a(n,0uLL);
    vector<unsigned long long> l(n+1,0uLL);
    vector<unsigned long long> r(n+1,0uLL);
    for(int i=0;i<n;++i) {
        cin >> a[i];
    }

    l[0] = 0uLL; r[n-1] = 0uLL;
    for(int i=1;i<n;++i) {
        l[i] = gcd(l[i-1], a[i-1]);
        r[n-i-1] = gcd(r[n-i], a[n-i]);
    }
    
    unsigned long long m = 0uLL;
    for(int i=0;i<n;++i) {
        m = max(m, gcd(l[i], r[i]));
    }
    cout << m << endl;
    
    
    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

class Main {
    // dp
    public static long knapsack1(int[] w, long[] v, int C) {
        int n = w.length;
        long[][] dp = new long[n][C+1];

        for (int c = 1; c <= C; c++) {
            dp[0][c] = (c >= w[0]) ? v[0] : 0;
        }

        for (int i = 1; i < n; i++) {
            for (int c = 1; c <= C; c++) {
                dp[i][c] = dp[i-1][c];
                if (c >= w[i]) {
                    dp[i][c] = Math.max(dp[i][c], v[i] + dp[i-1][c-w[i]]);
                }
            }
        }

        return dp[n-1][C];
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int C = in.nextInt();

        int[] w = new int[N];
        long[] v = new long[N];
        for (int i = 0; i < N; i++) {
            w[i] = in.nextInt();
            v[i]  = in.nextLong();
        }
        in.close();

        // call function hear
        long ret = knapsack1(w, v, C);
        System.out.println(ret);
    }
}

Measured memory_bytes: 127444
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int n;
	cin >> n;

	for (int k = 4; k < 100; k += 4) {
		if (k == n) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	for (int k = 7; k < 100; k += 7) {
		if (k == n) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	for (int i = 7; i < 100; i += 7) {
		for (int k = 4; k < 100; k += 4) {
			if (i + k == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
	return 0;


}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b;
  char op;
  while(1){
    scanf("%d %c %d",&a,&op,&b);
    if(op=='+'){
      printf("%d\n",a+b);
    }
    else if(op=='-'){
      printf("%d\n",a-b);
    }
    else if(op=='*'){
      printf("%d\n",a*b);
    }
    else if(op=='/'){
      printf("%d\n",a/b);
    }
    else if(op=='?'){
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 2724
N,Q = map(int, input().split())
S = input()
acCount = [0]*len(S)

count = 0
for i in range(len(S)-1):
  if S[i]=='A' and S[i+1]=='C':
    count += 1
  acCount[i+1] = count

  
for i in range(Q):
  L,R = map(int, input().split())
  print(acCount[R-1]-acCount[L-1])

Measured memory_bytes: 6060
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Measured memory_bytes: 6428
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <functional>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
const int MOD = 1000000007;
const int INF = 100100100;
const double EPS = 0.000000001;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool pairCompare(const P& pair1, const P& pair2) {
    return pair1.second > pair2.second;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, b[100001];
  vector<pair<ll,ll> > vec;
  cin >> n >> m;
  REP(i, n){
    int a, b_;
    cin >> a >> b_;
    vec.push_back(pair<ll,ll>(i, a));
    b[i] = b_;
  }
  sort(ALL(vec), pairCompare);
  ll ans = 0;
  while(m > 0){
    if(b[vec.back().first] <= m) {
      ans += vec.back().second * b[vec.back().first];
      m -= b[vec.back().first];
      vec.pop_back();
    }
    else {
      ans += vec.back().second * m;
      m = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


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

const int N = 2e5 + 10;
typedef long long ll;

ll sum[N], dp[N], a[N];
int n, m, i, j, k;

int main(){
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", a + i);
    if (i & 1) {
      sum[i] = sum[i - 2] + a[i];
    }
  }
  dp[1] = 0;
  for (int i = 2; i <= n; i++) {
    if (i & 1) {
      dp[i] = std::max(dp[i - 2] + a[i], dp[i - 1]);
    } else {
      dp[i] = std::max(sum[i - 1], dp[i - 2] + a[i]);
    }
  }
  printf("%lld\n", dp[n]);
  return 0;  
}

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

int main(){
    int a,b,c,d,count=0;
    cin >> a >> b >> c >> d;
    for(int i=0;i<=100;i++){
        if(a<=i&&i<b&&c<=i&&i<d)count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
typedef long long ll;
typedef long double ld;
//typedef ll long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef pair<ll,pair<ll,ll> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000 + 7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)2e18
# define LN 20  
# define EPS 1e-9
typedef pair<ll,pair<ll,ll> > pii;
# define INF1 1e9
# define maxn 200005
# define offset 100005
# define ovf (1LL<<32)-1
const ld eps = 1e-10L;
# define int long long
/*void LPS()
{
	len = s.length();
    lps[0] = 0;
    for(ll i=1;i<len;i++){
 
        ll j = lps[i-1];
        while(j > 0 && s[j] != s[i])    j = lps[j-1];
        if(s[i] == s[j])    j++;
        lps[i] = j;
    }
}*/

/*************************************************
struct Coupon {
	ll l;
	ll r;
	ll id;
 
	Coupon(ll l, ll r, ll id): l(l), r(r), id(id) {} // Initialization
 
	bool operator<(const Coupon& c) const{ // Sorting
		return l < c.l;    
	}
};
 
**************************************************/
int32_t main()
{
	string s;
	cin >> s;
	string prev = "";

	string curr = "";
	int ans = 0;
	for(int i=0;i<s.length();i++)
	{
		curr += s[i];
		if(curr != prev)
		{
			ans ++;
			prev = curr;
			curr = "";
		}
	}

	cout << ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N;
    cin>>N;
    if(N==1){
        cout<<"Hello World"<<endl;
    }else{
        int A,B;
        cin>>A>>B;
        cout<<A+B<<endl;
    }
}


Measured memory_bytes: 3608
def combinations(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(2, r + 1):
        res //= i
    return res

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse = True)

mx = sum(v[:A])
ans1 = mx/A
a = v[A]
cnt = v.count(a)

ans2 = 0
for i in range(A, B + 1):
    if A*sum(v[:i]) < i*mx:
        break
    ans2 += combinations(cnt, v[:i].count(a))

print(ans1)
print(ans2)


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

int main() {
  int a, b;
  cin >> a >> b;
  cout << (b % a == 0 ? a + b : b -a) << endl;
}

Measured memory_bytes: 256
s=input()
t=input()
l=len(t)
a=[]
for i in range(l-1,len(s)):
    x=s[len(s)-1-i:len(s)-1-i+l]
    cnt=0
    for j in range(l):
        if x[j]=="?" or x[j]==t[j]:
            cnt+=1
        else:
            break
    if cnt==l:
        u=s[:len(s)-1-i].replace("?","a")
        v=s[len(s)-1-i+l:].replace("?","a")
        key=u+t+v
        a.append(key)
if len(a)==0:
    print("UNRESTORABLE")
    exit()
a=sorted(a)
print(a[0])


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

#define INF 1000050000

int main()
{
	int n, k;
	int h[100005];
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}
	int dp[100005];
	for(int i = 1; i < n; i++) {
		dp[i] = INF;
	}
	dp[0] = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 1; j <= k; j++) {
			if(i + j >= n) continue;
			dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
		}
	}
	printf("%d\n", dp[n-1]);
}

Measured memory_bytes: 1024
#include <iostream>

int main()
{
    long long L, R;
    std::cin >> L >> R;
    if(R - L >= 2019){
        std::cout << 0 << std::endl;
        return 0;
    }

    int min = 2018;
    for(long long i=L; i<=R-1; i++){
        for(long long j=i+1; j<=R; j++){
            int x = i % 2019;
            int y = j % 2019;
            int r = (x * y) % 2019;
            if(r < min) min = r;
        }
    }
    std::cout << min << std::endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int A, B, C;
  cin >> A >> B >> C;

  bool found = false;
  for (int i = 1; i < 100; ++i) {
    if ((B * i + C) % A == 0)
      found = true;
  }

  if (found)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  vector<int>a(3);cin>>a[0]>>a[1]>>a[2];
  sort(a.begin(),a.end());
  cout<<a[0]+a[1]<<endl;
return 0;
}

Measured memory_bytes: 256
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int K = 1000, K2 = K * 2, K4 = K2 * 2;

int bb[K4][K4];

int main() {
	int n, k; cin >> n >> k;
	int k2 = k * 2;
	int k4 = k2 * 2;
	while (n--) {
		int i, j; cin >> i >> j, i %= k2, j %= k2;
		string s; cin >> s;
		if (s == "W")
			i += (i >= k ? -k : k);
		bb[i][j]++;
		bb[k2 + i][j]++;
		bb[i][k2 + j]++;
		bb[k2 + i][k2 + j]++;
	}
	for (int i = 0; i < k4; i++)
		for (int j = 1; j < k4; j++)
			bb[i][j] += bb[i][j - 1];
	for (int i = 1; i < k4; i++)
		for (int j = 0; j < k4; j++)
			bb[i][j] += bb[i - 1][j];
	int ans = 0;
	for (int i_ = 0; i_ < k2; i_++)
		for (int j_ = 0; j_ < k2; j_++) {
			int i, j, cnt = 0;
			i = i_, j = j_;
			cnt += bb[i + k][j + k] - bb[i][j + k] - bb[i + k][j] + bb[i][j];
			i = i_ + k, j = j_ + k;
			cnt += bb[i + k][j + k] - bb[i][j + k] - bb[i + k][j] + bb[i][j];
			ans = max(ans, cnt);
		}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 66100
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func ch(a byte, R, S, P int) (byte, int) {
	var ret byte
	var pt int
	switch a {
	case 'r':
		ret = 'p'
		pt = P
	case 's':
		ret = 'r'
		pt = R
	case 'p':
		ret = 's'
		pt = S
	}
	return ret, pt
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N, K := getInt(), getInt()
	R, S, P := getInt(), getInt(), getInt()
	T := getString()

	a := make([]byte, N)

	ans := 0
	for i := 0; i < N; i++ {
		x, pt := ch(T[i], R, S, P)
		if i-K >= 0 && a[i-K] == x {
			x = 'x'
			pt = 0
		}
		a[i] = x
		ans += pt
	}
	out(ans)
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int x,max=0,kazu[101]={0};
	while(scanf("%d",&x)!=EOF)
	{
		kazu[x]++;
		if(max<kazu[x])
			max=kazu[x];
	}
	for(x=0; x<101; x++)
	{
		if(max==kazu[x])
			printf("%d\n",x);
	}
	return 0;
}

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

#define Online 1
// #define multitest 1
#define Debug 1
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve()
{
	string s;
	cin >> s;
	ll cnt = 0;
	int n = s.size(), x = 0;
	for (int i = 0; i < n; ++i)
	{
		if (s[i] == 'A')
		{
			if (i + 2 < n)
			{
				x++;
				if (s[i + 1] == 'B' && s[i + 2] == 'C')
				{
					cnt += x;
					s[i] = 'B';
					s[i + 1] = 'C';
					s[i + 2] = 'A';
					// cout << s << ' ' << i << '\n';
					i = i + 1;
					x--;
				}
			}
		}
		else
			x = 0;
	}
	cout << cnt;
}

int main()
{
	ControlIO();
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	TimerStart();
	while (t--)
		solve();
	TimerStop();
	return 0;
}

void ControlIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef Online
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
	TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}

Measured memory_bytes: 720
N, M = map(int, input().split())
a = [int(input()) for j in range(M)]

#dp[i]:i段目までの上がり方

div = 1000000007

dp = [0] * (N+1)
dp[0] = 1
if not 1 in a:
    dp[1] = 1
else:
    del a[0]

def stairs():
    for i in range(N-1):
        if dp[i+1] == 0 and dp[i] == 0:
            break
        if a:
            if i+2 == a[0]:
                del a[0]
                continue
        dp[i+2] = (dp[i+1] + dp[i]) % div
    print(dp[N])

stairs()

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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
ll ret = 0;

ll A, B, K;

void input() {
  IN(A);
  IN(B);
  IN(K);
}

void solve() {
  ll k = 0;
  for(ll i=100; i>0; i--){
    ll test = i;
    if((A%test == 0) && (B%test == 0)){
      k++;
    }
    if(k == K){
      ret = test;
      break;
    }
  }
}

int main(void){
  input();
  solve();
  PRINT(ret);
}


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

string S;

int main(){
	cin >> S;
	set<char> tmp;
	for(long long i = 0; i < S.size(); i++) {
		tmp.insert(S[i]);
	}
	if(tmp.size() == 2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 3616
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
)

var N, A, B, C int
var ls []int

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d %d %d", &N, &A, &B, &C)

	ls = make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &ls[i])
	}

	ans := math.MaxInt64
	for _, t := range dfs(0) {
		if t.fst == 0 || t.snd == 0 || t.trd == 0 {
			continue
		}
		mp := dist(t) + t.cost
		if mp < ans {
			ans = mp
		}
		//ans = min(ans, mp)
	}
	fmt.Println(ans)
}

func min(ns ...int) int {
	ret := math.MaxInt64
	for _, n := range ns {
		if n < ret {
			ret = n
		}
	}
	return ret
}

type triple struct {
	fst, snd, trd, cost int
}

func dist(t triple) int {
	as := make([]int, 3)
	as[0] = t.fst
	as[1] = t.snd
	as[2] = t.trd
	sort.Sort(sort.IntSlice(as))
	return abs(as[0]-C) + abs(as[1]-B) + abs(as[2]-A)
}

func abs(n int) int {
	if n >= 0 {
		return n
	}
	return -n
}

func dfs(index int) []triple {
	ret := make([]triple, 0)
	if index == N {
		ret = append(ret, triple{0, 0, 0, 0})
		return ret
	}
	for _, a := range dfs(index + 1) {
		t1 := triple{a.fst, a.snd, a.trd, a.cost}
		if t1.fst != 0 {
			t1.cost += 10
		}
		t1.fst += ls[index]
		ret = append(ret, t1)

		t2 := triple{a.fst, a.snd, a.trd, a.cost}
		if t2.snd != 0 {
			t2.cost += 10
		}
		t2.snd += ls[index]
		ret = append(ret, t2)

		t3 := triple{a.fst, a.snd, a.trd, a.cost}
		if t3.trd != 0 {
			t3.cost += 10
		}
		t3.trd += ls[index]
		ret = append(ret, t3)

		t4 := triple{a.fst, a.snd, a.trd, a.cost}
		ret = append(ret, t4)
	}
	return ret
}


Measured memory_bytes: 12160
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define INF 999999

int x,y,t,n,m,route[2][20][20];
int i,j,k,l;

int main(){
	while(scanf("%d",&m)*m){
		n=0;
		for(i=0;i<11;i++){
			for(j=0;j<11;j++){
				if(i!=j)route[0][i][j]=INF;
			}
		}

		for(i=0;i<m;i++){
			scanf("%d %d %d",&x,&y,&t);
			if(x+1>n)n=x+1;
			if(y+1>n)n=y+1;
			route[0][x][y]=t;
			route[0][y][x]=t;
		}

		for(l=1;pow(2.0,l-1)<n-1;l++){
			for(i=0;i<n;i++){
				for(j=0;j<n;j++){
					route[l%2][i][j]=route[(l+1)%2][i][j];
					for(k=0;k<n;k++){
						if(route[l%2][i][j]>route[(l+1)%2][i][k]+route[(l+1)%2][k][j]){
							route[l%2][i][j]=route[(l+1)%2][i][k]+route[(l+1)%2][k][j];
						}
					}
				}
			}
		}

		l=(l-1)%2;

		x=INF;
		for(i=0;i<n;i++){
			k=0;
			for(j=0;j<n;j++)k+=route[l][i][j];
			if(k<x){
				x=k;
				y=i;
			}
		}

		printf("%d %d\n",y,x);

	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;

int main(){
    int n,mi=INF,p,ans=0;
    cin>>n;
    rep(i,n){
        cin>>p;
        if(p<mi)ans++,mi=p;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define c2(n,m) cin>>n>>m
#define c3(n,m,k) cin>>n>>m>>k
#define c4(n,m,k,l) cin>>n>>m>>k>>l
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  bool a=false,b=false,c=false,d=false,e=1,n=1;
  string s,ans="Yes";
  c(s);
  rep(i,0,s.size()){
    if(s[i]=='N') a=true;
    if(s[i]=='S') b=true;
    if(s[i]=='E') c=true;
    if(s[i]=='W') d=true;
  }
  if(a==false && b==true) ans="No";
  if(a==true && b==false) ans="No";
  if(c==false && d==true) ans="No";
  if(c==true && d==false) ans="No";
  co(ans);
  
  return 0;
}


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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

int main(){
	int n,x0; scanf("%d%d",&n,&x0);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	sort(a.begin(),a.end());

	vector dp(n+1,vector<mint>(1e5+1));
	rep(x,1e5+1) dp[0][x]=x;
	rep(i,n){
		rep(x,1e5+1){
			dp[i+1][x]=i*dp[i][x]+dp[i][x%a[i]];
		}
	}
	cout<<dp[n][x0]<<'\n';

	return 0;
}


Measured memory_bytes: 82468
int1 = lambda x: int(x) - 1

N, K = map(int, input().split())
P = tuple(map(int1, input().split()))
C = tuple(map(int, input().split()))

visited = set()
cycles = []
for i in range(N):
    if i not in visited:
        cur = P[i]
        cycle = [i]
        while cur != i:
            visited.add(cur)
            cycle.append(cur)
            cur = P[cur]
        cycles.append(cycle)

ans = -float('inf')
for cycle in cycles:
    l = len(cycle)
    score = [0]
    for x in cycle * 2:
        score.append(score[-1] + C[x])

    # i回進めるときのスコア最大値
    lst = [0] * (min(K, l) + 1)
    lst[0] = -float('inf')
    for i in range(1, min(K, l) + 1):
        tmp = -float('inf')
        for j in range(l):
            tmp = max(tmp, score[j + i] - score[j])
        lst[i] = tmp

    lap = K // l
    if lap == 0:
        ans = max(ans,
                  max(lst))
    else:
        around_score = lst[l]
        ans = max(ans,
                  max(lst),
                  around_score * (lap - 1) + max(lst),
                  around_score * lap + max(lst[:K % l + 1]))
print(ans)


Measured memory_bytes: 69696
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D, a, c;
  int i=0;
  cin >> A >> B >> C >> D;
  
  a=A;
  c=C;
  
  while (A>0 && C>0)
  {
      A=A-D;
      C=C-B;
      i++;
  }
  
  /*cout << A << endl;
  cout << B << endl;
  cout << i << endl;*/
  
  if (B*i >= c)
  {
      cout << "Yes";
  }

  else {
      cout << "No";
  }
}

Measured memory_bytes: 3632
package main

import (
  "fmt"
  "os"
  "strconv"
)

func main() {
  var s string
  fmt.Scan(&s)
  if y, _ := strconv.Atoi(s[:4]); y > 2019 {
    fmt.Println("TBD")
    os.Exit(0)
  }
  if m, _ := strconv.Atoi(s[5:7]); m > 4 {
    fmt.Println("TBD")
    os.Exit(0)
  }
  fmt.Println("Heisei")

}

Measured memory_bytes: 512
N = int(input())
L = list(map(int, input().split()))
L.sort()
answer = 0
for i in range(N-1, 1, -1): # iは辺の最大値
    s = 0 # aは1番短い辺
    l = i-1
    while l > s:
        if L[s] + L[l] > L[i]:
            answer += l - s
            l -= 1
        else:
            s += 1
print(answer)


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int main(){
  int a,b,c,d,e,x;
  cin >> a >> b >> c >> d >> e;
  x = min((a-1)%10,(b-1)%10);
  x = min(x,(c-1)%10);
  x = min(x,(d-1)%10);
  x = min(x,(e-1)%10);
  x++;
  //cout << x;
  cout << ((a-1)/10+1)*10+((b-1)/10+1)*10+((c-1)/10+1)*10+((d-1)/10+1)*10+((e-1)/10+1)*10-10+x;
}


Measured memory_bytes: 256