akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define vc vector<int>
#define um unordered_map<int,int>
#define ll long long 
#define rep(i,a,b) for(__typeof(a) i=a; i<b; i++)
#define si(a) a.size()
#define all(a) a.begin(),a.end()
#define ss(a) a.second
#define ff(a) a.first
#define M 1000000
#define pb push_back
#define repit(i,a) for(auto i=a.begin(); i!=a.end(); i++)
#define take(arr,n) for(int i=0;i<n;i++)cin>>arr[i]
#define out(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<' '
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define reprev(i,b,a) for(__typeof(b) i=b; i>=a; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define doublearray vector<vector<int>>
#define mod 998244353 
using namespace std;
ll max(ll a, ll b){ return a>b?a:b; }
ll min(ll a, ll b){ return a<b?a:b; }
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}
int binaryS(ll x, ll sb[], int m){
    int l = 0, r=m;
    int mid = (l+r)/2;
    while(l<r){
        mid = (l+r)/2;
        if(sb[mid]<x) l= mid+1;
        else if(sb[mid]>x) r = mid-1;
        else return mid;
    }
    return l;
}
int main(){
    fastio;
    ll n; cin>>n;
    string f = "";
    while(n){
        if(n%26==0){
            f+='z';
            n/=26; n--;
        }
        else{
            f+='a'+(n%26-1);
            n/=26;
        }
    }
    reverse(all(f));
    cout<<f<<endl;
    return 0;
}





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


int main(){
    long long H;
    int N;
    cin >> H >> N;
    vector<long long> A(N);

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

    for(int i=0; i<N; ++i){
        H -= A[i];
        if(H <= 0){
            cout << "Yes" << endl;
            return 0;
        }
    }

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

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    vi n(3);
    ll countf=0,counts=0;
    rep(i,3){
        cin >> n[i];
        if(n[i] == 5)countf++;
        else if(n[i] == 7)counts++;
    }
    if(countf == 2 && counts == 1)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int S,a,b;
  cin>>S;
   b=S%100;
  
  a=S/100;
 
  
  if(a>0&&a<=12){
    if(b>0&&b<=12){
      cout<<"AMBIGUOUS"<<endl;
    }
    else{
      cout<<"MMYY"<<endl;
    }
  }
  
  else if(b>0&&b<=12){
    cout<<"YYMM"<<endl;
  }
  else{
    cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 256
from collections import Counter
n, m = map(int, input().split())
X = list(map(int, input().split()))
Odd = [0]*m
C = [0]*m
L = [0]*m
D = Counter(X)
for i, c in D.items():
  C[i%m] += c
  Odd[i%m] += c%2
  L[i%m] += c//2
ans = 0
ans += C[0]//2
for i in range(1, (m+1)//2):
  if C[i] <= C[m-i]:
    ans += C[i]
    if C[i] <= Odd[m-i]:
      ans += L[m-i]
    else:
      ans += L[m-i] + (-(C[i]-Odd[m-i])//2)
  else:
    ans += C[m-i]
    if C[m-i] <= Odd[i]:
      ans += L[i]
    else:
      ans += L[i] + (-(C[m-i]-Odd[i])//2)
if m%2 == 0:
  ans += C[m//2]//2
print(ans)

Measured memory_bytes: 21984
#include<stdio.h>
int main(void){
    int a[10000], min, max, n, i;
    long long sum = 0;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
        sum += a[i];
    }
    max=min=a[0];
    for(i=1; i<n; i++){
        if(a[i]>max)max=a[i];
        if(a[i]<min)min=a[i];
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}
    


Measured memory_bytes: 2140
//srinivas
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(x=in;x<n;x+=r)
#define ifr(x,n) for(x=0;x<n;x++)
#define dfr(x,n) for(x=n-1;x>=0;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // freopen("input.txt","r",stdin);
    ll n,w,i,j;
    cin>>n>>w;
    ll a[n],b[n];
    ifr(i,n)cin>>a[i]>>b[i];
    ll dp[n][w+1];
    ifr(i,n)
    	ifr(j,w+1)
    		dp[i][j]=0;
    fr(i,a[0],w+1,1)
    	dp[0][i]=b[0];
    fr(i,1,n,1){
    	ifr(j,w+1){
    		if(j<a[i])
    				dp[i][j]=dp[i-1][j];
    		else{
				if(j-a[i]>=0)
					dp[i][j]=max(dp[i-1][j-a[i]]+b[i],dp[i-1][j]);
				else
					dp[i][j]=dp[i-1][j];
    		}
    	}
    }
    // ifr(i,n){
    // 	ifr(j,w+1){
    // 		cout<<dp[i][j]<<" ";
    // 	}
    // 	cout<<endl;
    // }
    cout<<dp[n-1][w]<<endl;
    return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
vector<ll> v;
ll cal(ll x, ll y){
    if(y%2){
        v.push_back(x);
    }
    if(y<=1)
        return 0;
    if(x>=5){
        return y/2*2+cal(x+x-9, y/2);
    }
    return y/2+cal(x+x, y/2);
}
int main(){
    ll n;
    while(cin>>n){
        v.clear();
        ll ans=0;
        ll tmp, tmp1, x, y;
        for(int i=0; i<n; ++i){
            scanf("%lld%lld",&x,&y);
            tmp=cal(x, y);
            ans+=tmp;
//            cout<<tmp<<" "<<ans<<endl;
        }
        while(v.size()>1){
            tmp=v.back();
            v.pop_back();
            tmp1=v.back();
            v.pop_back();
            ++ans;
            if(tmp+tmp1>=10){
                v.push_back(1);
                v.push_back(tmp+tmp1-10);
            }
            else{
                v.push_back(tmp+tmp1);
            }
        }
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 34660
S = input()
if len(S) > 9:
    print('NO')
    exit()

if S.replace('A', '') != 'KIHBR':
    print('NO')
    exit()

for i in range(1, len(S)):
    if S[i] == 'A' and S[i-1] not in ('H', 'B', 'R'):
        print('NO')
        exit()

print('YES')


Measured memory_bytes: 9112
import math
from collections import deque
def main():
    n = int(input())
    a = [int(t)for t in input().split()]

    vote = {}
    for a_ in a:
        if a_ in vote.keys():
            vote[a_] += 1
        else:
            vote[a_] = 1

    combi = {}

    result = 0
    for a_,num in vote.items():
        # combi[a_] = num*(num-1)//2
        result += num*(num-1)//2

    for a_ in a:
        res = result-(vote[a_]-1)
        print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 26780
#include <iostream>
using namespace std;
int main(){
  long long int N;
  cin >> N;
  int ans = 100;
  for(long long int i = 1LL; i*i <= N; ++i){
    if(N%i == 0){
      long long t = max(i, N/i);
      int k = 0;
      while(t > 0){
	t /= 10;
	++k;
      }
      ans = min(ans, k);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int a,b;
	while(cin>>a>>b){
		cout<<(a-1)*(b-1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>

#define rep(j, n) for (int i = j; i < n; i++)
#define repd(j, n) for (int i = j; i > n; i--)
#define maxx 100010

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

int main() {
	int a, b, ans = 0;
	cin >> a >> b;
	int kind[30];
	rep(0, b) {
		kind[i] = 0;
	}
	rep(0, a) {
		int c;
		cin >> c;
		rep(0, c) {
			int d;
			cin >> d;
			kind[d-1]++;
		}
	}
	rep(0, b) {
		if (kind[i] == a) {
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val player = readLine()?.orEmpty()
    val firstLine = readLine()?.split(" ").orEmpty()
    val colorList = listOf("gray","brown","green","marine","blue","yellow","orange","red")
    var rateList = mutableListOf<String>()
    var master = 0

    firstLine.forEach{
        val color = it.toInt() / 400
        if(color < 8){
            rateList.add(colorList[color])
        }else{
            master += 1
        }
    }
    var min = 0
    var max = 0
    
    if(rateList.size != 0){
        min = rateList.distinct().size    
        max = min + master
    }else{
        min = 1
        max = master
    }
     
    
    println("$min $max")
}

Measured memory_bytes: 37928
n = int(input())
p = list(input().split())
a = 0
for i in range(1,n-1):
    if int(p[i-1]) < int(p[i]) < int(p[i+1]) or int(p[i+1]) < int(p[i]) < int(p[i-1]):
        a += 1

print(a)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int A, B;
	cin >> A >> B;
	if (B % A == 0)cout << A + B << endl;
	else cout << B - A << endl;
}

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

int main(){
    int K, S, ans = 0;
    cin >> K >> S;
    rep(i, K + 1)
        rep(j, K + 1)
            if(0 <= S - i - j && S - i - j <= K) ans++;
    cout << ans << endl;
}

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

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

	for(int i=a; i <= b; i++) {
		if( (i/10000)==(i%10) && (i/1000%10)==(i/10%10) ) ans++;
	}
	cout << ans <<endl;

}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int solve_testcase() {
    int N; scanf("%d", &N);
    if(N == 0) return 1;

    vector<string> vs(N);
    for(int i=0; i<N; i++) cin >> vs[i];

    int line = 0;
    auto parse = [&](auto &&self) -> ll {
        if(vs[line].back() == '*' or vs[line].back() == '+') {
            int depth = vs[line].size(); char op = vs[line++].back();
            ll res = (op == '*' ? 1 : 0);
            while(line < N and vs[line].size() == depth + 1) {
                ll num = self(self);
                if(op == '*') res *= num;
                if(op == '+') res += num;
            }
            return res;            
        }
        else {
            return vs[line++].back() - '0';
        }
    };
    ll ans = parse(parse);
    printf("%lld\n", ans);
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

int main()
{
	LL A, B;
	cin >> A >> B;

	if (A == B) {
		cout << A << endl;
		return 0;
	}

	LL ans = 0;

	if (A % 2) {
		ans ^= A;
		A++;
	}

	if (B % 2 == 0) {
		ans ^= B;
		B--;
	}

	if (A >= B) {
		cout << ans << endl;
		return 0;
	}

	LL d = (B - A + 1) / 2;
	if (d % 2) {
		ans ^= 1;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int n,num[100005],i,j,ai=0,aj=0;
    cin>>n;
    for(i=1;i<=n;i++){scanf("%d",&num[i]);ai=max(ai,num[i]);}
    for(i=1;i<=n;i++){
        if(fabs((double)aj-(double)ai/2)>fabs((double)num[i]-(double)ai/2))
            aj=num[i];
    }
   cout<<ai<<' '<<aj<<endl;

    return 0;

}

Measured memory_bytes: 640
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) ]))
def invr():
    return(map(int,input().split()))
  
i = inlt()
D = i[0]
T = i[1]
S = i[2]
 
if D/T > S:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 61568
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int n; cin >> n;
  cout << n * (n + 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0 ;i < n;i++){
        cin >> a[i];
    }
    for(int i = 0;i < n - 1;i++){
        cout << a.back() << " ";
        a.pop_back();
    }
      cout << a.back() << endl;
    return 0;
}



Measured memory_bytes: 3076
def main():
    import bisect
    n = int(input())
    l = sorted(list(map(int,input().split())))
    ans = 0
    for i in range(1,n-1):
        ll = l[0:i]
        lr = l[i+1:]
        c = l[i]
        for j in range(len(lr)):
            b = bisect.bisect_left(ll,lr[j]-c+1)
            ans += len(ll)-b
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <functional>
using namespace std;

#define N_MAX 15
#define S_MAX 10

int X, Y, n, M[S_MAX][S_MAX];
vector< pair<int, int> > k;
int ans;

struct Rect {
  int x, y, w, h;
};
Rect R[N_MAX];

bool isHit(int u) {
  for(int i = 0; i < n; ++i) {
    if(i == u) continue;
    if(R[u].x >= R[i].x + R[i].w) continue;
    if(R[u].y >= R[i].y + R[i].h) continue;
    if(R[i].x >= R[u].x + R[u].w) continue;
    if(R[i].y >= R[u].y + R[u].h) continue;
    return true;
  }
  return false;
}

void draw() {
  for(int i = 0; i < n; ++i) {
    for(int dx = 0; dx < R[i].w; ++dx) {
      for(int dy = 0; dy < R[i].h; ++dy) {
	M[R[i].y+dy][R[i].x+dx] = i+1;
      }
    }
  }
}

void rec(int p) {
  if(p == n) {
    draw();
    ans++;
    return;
  }

  int x = R[k[p].second].x;
  int y = R[k[p].second].y;

  for(int h = 1; h <= k[p].first; ++h) {
    if(k[p].first % h != 0) continue;
    int w = k[p].first / h;
    R[k[p].second].h = h;
    R[k[p].second].w = w;
    for(int ny = y-h+1; ny <= y; ++ny) {
      for(int nx = x-w+1; nx <= x; ++nx) {
	if(nx < 0 || nx + w > X) continue;
	if(ny < 0 || ny + h > Y) continue;
	R[k[p].second].x = nx;
	R[k[p].second].y = ny;
	if(!isHit(k[p].second)) rec(p+1);
	if(ans >= 2) return;
      }
    }
  }
  R[k[p].second].x = x;
  R[k[p].second].y = y;
  R[k[p].second].w = 1;
  R[k[p].second].h = 1;
}


void solve() {
  ans = 0;
  sort(k.begin(), k.end(), greater< pair<int, int> >());
  rec(0);
  if(ans == 1) {
    for(int i = 0; i < Y; ++i) {
      for(int j = 0; j < X; ++j) {
	if(j != 0) cout << " ";
	cout << M[i][j];
      }
      cout << endl;
    }
  } else {
    cout << "NA" << endl;
  }
}

main() {
  while((cin >> X >> Y >> n) && (X || Y || n)) {
    k.clear();
    for(int i = 0; i < n; ++i) {
      int b, s;
      cin >> b >> s;
      b--;
      k.push_back(pair<int, int>(s, b));
    }
    for(int i = 0; i < Y; ++i) {
      for(int j = 0; j < X; ++j) {
	cin >> M[i][j];
	if(M[i][j] != 0) {
	  int u = M[i][j] - 1;
	  R[u].x = j;
	  R[u].y = i;
	  R[u].w = 1;
	  R[u].h = 1;
	}
      }
    }
    solve();
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int a, b, c, d=0, k, i;
	cin >> a >> b >> k;
	c =gcd(a, b);
	i = c + 1;
	while (k > d) {
		i--;
		if (c % i == 0) {
			d++;
		}
	}
	cout << i << endl;
}



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

int main() {
	long long N;
	cin >> N;
	if (N % 2 == 1) cout << 0 << endl;
	else {
		long long COUNT = 0, X = 1;
		N /= 2;
		while (N != 0) {
			COUNT += N / 5;
			N /= 5;
			X++;
		}
		cout << COUNT << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
#include<numeric>
using namespace std;
typedef long long ll;
//ll mod = 1e9+7;
ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> ab(m);
    rep(i, m) {
        int tmp_a, tmp_b;
        cin >> tmp_a >> tmp_b;
        --tmp_a, --tmp_b;
        ++ab[tmp_a], ++ab[tmp_b];
    }
    rep(i, m) {
        if ( ab[i] & 1 ) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        var S = cin.Next;
        for (int i = S.Length - 2; i >= 0; i-=2)
        {
            bool flag = true;
            for (int j = 0; j < i / 2; j++)
            {
                if (S[j] != S[j + i / 2]) flag = false;

            }
            if (flag)
            {
                WriteLine(i);
                return;
            }

        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 11216
n,m=map(int,input().split())
l=set()
r=set()
for i in range(m):
        l_,r_=map(int,input().split())
        l.add(l_)
        r.add(r_)
l=max(l)
r=min(r)
print(max(0,r-l+1))

Measured memory_bytes: 18784
#include<iostream>
#include<vector>
//#include<ctime>
using namespace std;
int main(){
	int n;
	cin >> n;
	//clock_t t1, t2;
	//t1 = clock();
	for(int i = 1; i <= n; i++){
		int num[10];
		for(int j = 0; j < 10; j++) cin >> num[j];
		bool flag = false;
		for(int j = 0; j < (1 << 10); j++){
			vector<int> va, vb;
			for(int k = 0; k < 10; k++){
				if(j & (1 << k)) va.push_back(num[k]);
				else vb.push_back(num[k]);
			}
			bool flag_ = true;
			for(int k = 1; k < va.size(); k++){
				if(va[k] < va[k - 1]) flag_ = false;
			}
			for(int k = 1; k < vb.size(); k++){
				if(vb[k] < vb[k - 1]) flag_ = false;
			}
			if(flag_) flag = true;
		}
		if(flag) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	//t2 = clock();
	//cout << t2 - t1 << endl;
	return 0;
}


Measured memory_bytes: 3080
/*
 * Problem Description: Shell Sort
 * Category:
 * Author: Khan
 * Date: 11th October, 2017
 */

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

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

void shellSort(int A[], int n)
{
    for (int h = 1; ; )
    {
        if(h > n)
            break;
        G.push_back(h);
        h = 3 * h + 1;
    }
    for(int i = G.size() - 1; i >= 0; --i)
    {
        insertionSort(A, n, G[i]);
    }
}

int main(int argc, char const *argv[])
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &A[i]);
    }
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for (int i = G.size() - 1; i >= 0; --i)
    {
        printf("%d", G[i]);
        if(i)
            printf("\n");
    }
    cout << endl;
    printf("%lld\n", cnt);
    for (int i = 0; i < n; ++i)
    {
        printf("%d\n", A[i]);
    }
    return 0;
}

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

int b() {
    string s, t;
    cin >> s >> t;

    int n = t.size();
    int ans = n;
    for(int i = n - 1; i < s.size(); i++) {
        int cnt = 0;
        for(int j = 0; j < t.size(); j++) {
            if(s[i - j] == t[(n - 1) - j]) cnt++;
        }
        ans = min(ans, n - cnt);
    }
    cout << ans << endl;
    return 0;
}

int main() {
    b();
    return 0;
}



Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

//Collatz's Problem
public class Main{

	static int[] dp;

	static int f(int n){
		if(dp[n]!=-1)return dp[n];
		if(n%2==0)return dp[n] = f(n/2)+1;
		else return dp[n] = f(n*3+1)+1;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		dp = new int[1000001];
		Arrays.fill(dp, -1);
		dp[1] = 0;
		while(true){
			int x = sc.nextInt();
			if(x==0)break;
			System.out.println(f(x));
		}
	}
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll x(n), y(n);
    rep(i, n){
        cin >> x[i] >> y[i];
    }
    map<pair<ll, ll>, ll> mp;
    rep(i, n-1){
        repr(j, i+1, n){
            ll dx = x[i] - x[j];
            ll dy = y[i] - y[j];
            if(dx < 0 || (dx == 0 && dy < 0)){
                dx *= -1;
                dy *= -1;
            }
            if(mp.count(make_pair(dx, dy))){
                mp[make_pair(dx, dy)]++;
            }else{
                mp.emplace(make_pair(dx, dy), 1LL);
            }
        }
    }
    ll ans = 0;
    for(auto i = mp.begin(); i != mp.end(); ++i){
        ans = max(ans, i->second);
        //dump2(i->first.first, i->first.second);
        //dump(i->second);
    }
    cout << n-ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-6
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
const int MAXN=2e5+5;
int a[MAXN];
ll tot=0;
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		tot+=a[i];
	}
	ll ans=0x3f3f3f3f3f3f3f3f;
	ll now=0,els;
	for(int i=1;i<n;i++)
	{
		now+=a[i];
		els=tot-now;
		ans=min(ans,abs(els-now));
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
N, K = map(int, input().split())
S = str(input())
S_after = ""
for i in range(N):
    if i == K-1:
        if S[K-1] == "A":
            S_after += 'a'
        if S[K-1] == 'B':
            S_after += 'b'
        if S[K-1] == 'C':
            S_after += 'c'
    else:
        S_after += S[i]
print(S_after)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
   string s;
   cin >> s;
   if(s=="Sunny")
   cout << "Cloudy" << endl;
   else if(s=="Cloudy")
   cout << "Rainy" << endl;
   else
   cout << "Sunny" << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#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 yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll popcount(ll x){
  ll cnt=0;
  ll res=0;
  while((1<<cnt)<=x){
    if((1<<cnt)&x)
      res++;
    cnt++;
  }

  return res;
}

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

  ll n;
  cin>>n;
  string x;
  cin>>x;

  ll t=0;
  REP(i,n){
    if(x[i]=='1')
      t++;
  }

  vll p(2);
  p[0]=t+1;
  p[1]=t-1;
  vll X(2,0);
  vvll base(2,vll(n+1,1));
  REP(j,2){
    if(p[j]<=0)
      continue;
    REP(i,n){
      if(x[n-1-i]=='1'){
        X[j]=(X[j]+base[j][i])%p[j];
      }

      base[j][i+1]=base[j][i]*2%p[j];
    }
  }


  REP(i,n){
    ll now;
    ll k;
    if(x[i]=='1'){
      k=1;
      if(p[1]==0){
        cout<<0<<endl;
        continue;
      }

      now=(X[k]-base[k][n-1-i]+p[k])%p[k];
    }
    else{
      k=0;
      now=(X[k]+base[k][n-1-i])%p[k];
    }

    ll ans=1;
    while(now!=0){
      now=now%popcount(now);
      ans++;
    }
    cout<<ans<<endl;

  }

}



Measured memory_bytes: 8364
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = int(input())
	if(n%500 <= a):
		print('Yes')
	else:
		print('No')

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


Measured memory_bytes: 63340
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  int sum1 = 0;
  int sum2 = 0;
  rep(i,N) {
    sum1 += A[i];
    sum2 += A[i] * A[i];
  }
  int ans = INF;
  srep(y,-100,101) {
    int c = N * y * y - 2 * sum1 * y + sum2;
    if(ans > c) {
      ans = c;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int H, W, i, j;

  while(1){

  scanf("%d %d", &H, &W);
  if(H==0 && W==0) break;

  for(i=0;i<H;i++) {
    for(j=0;j<W;j++) {
      if(i%2!=0) {
        if(j%2!=0) printf("#");
        else printf(".");
      } else {
        if (j%2!=0) printf(".");
        else printf("#");
      }
    }
    printf("\n");
  }
  printf("\n");
}

  return 0;
}



Measured memory_bytes: 2024
s = list(input())

t = list(input())
f = 0 
if len(t) == len(s) + 1:
    f = 0
else:
    f = 1

for i in range(len(s)):
    if s[i] != t[i]:
        f = 1

if f == 0:
    print("Yes")
else:
    print("No")





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

const int XD = 3003;

int dp[ XD ][ XD ];
char znak[ XD ][ XD ]; // (a-z) -> i-1,j-1;  # - i-1,j;  $ - i,j-1;

string rev( string s )
{
    string r;
    for( int i = s.size() - 1; i >= 0; i-- )
        r += s[ i ];
    return r;
}
string lcs( string s, string t )
{
    for( int i = 1; i < s.size(); i++ )
    {
        for( int j = 1; j < t.size(); j++ )
        {
            if( s[ i ] == t[ j ] )
            {
                dp[ i ][ j ] = dp[ i - 1 ][ j - 1 ] + 1;
                znak[ i ][ j ] = s[ i ];
            }
            else
            {
                dp[ i ][ j ] = max( dp[ i - 1 ][ j ], dp[ i ][ j - 1 ] );
                ( dp[ i ][ j ] == dp[ i ][ j - 1 ] )? znak[ i ][ j ] = '$':znak[ i ][ j ] = '#';
            }
        }
    }
    string r;
    int i = s.size() - 1, j = t.size() - 1;
    while( i > 0 && j > 0 )
    {
        if( znak[ i ][ j ] == '#' ) i--;
        else if( znak[ i ][ j ] == '$' ) j--;
        else if( znak[ i ][ j ] != 0 ) { r += znak[ i ][ j ]; i--; j--; }
    }
    return rev( r );
}
int main()
{
    ios_base::sync_with_stdio( false );
    string s, t; cin >> s >> t;
    s = "#" + s; t = "$" + t;
    cout << lcs( s, t );
    return 0;
}


Measured memory_bytes: 44288
mod = 10**9 + 7
K = 60

L, R = map(int, input().split())
Rb, Lb = [0], [0]
for i in range(K):
    Rb.append((R>>i)%2)
    Lb.append((L>>i)%2)
    if Rb[-1]:
        Rm = i+1
    if Lb[-1]:
        Lm = i+1
dp =[[1, 1, 1, 1] for _ in range(K+1)]
r = 0
for i in range(1, K+1):
    dp[i][0] = dp[i-1][0] * 3 % mod
    if Rb[i]:
        dp[i][1] = dp[i-1][1] * 2 + dp[i-1][0] % mod
    else:
        dp[i][1] = dp[i-1][1]

    if Lb[i]:
        dp[i][2] = dp[i-1][2]
    else:
        dp[i][2] = dp[i-1][2] * 2 + dp[i-1][0] % mod

    if Rb[i] and Lb[i]:
        dp[i][3] = dp[i-1][3]
    elif Rb[i]:
        dp[i][3] = dp[i-1][1] + dp[i-1][2] + dp[i-1][3] % mod
    elif Lb[i]:
        dp[i][3] = 0
    else:
        dp[i][3] = dp[i-1][3]

    if Rm > i and Lm < i:
        r += dp[i-1][0]
    elif Rm > i and Lm == i:
        # このとき確実にLb[i] == 1
        r += dp[i-1][2]
    elif Rm == i and Lm < i:
        r += dp[i-1][1]
    elif Rm == i and Lm == i:
        r += dp[i-1][3]
    else:
        r += 0
    r = r % mod
print(r)


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

namespace io {
char buf[1<<21], *p1 = buf, *p2 = buf;
inline char gc() {
    if(p1 != p2) return *p1++;
    p1 = buf;
    p2 = p1 + fread(buf, 1, 1 << 21, stdin);
    return p1 == p2 ? EOF : *p1++;
}
#define G gc

#ifndef ONLINE_JUDGE
#undef G
#define G getchar
#endif

template<class I>
inline void read(I &x) {
    x = 0; I f = 1; char c = G();
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = G(); }
    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = G(); }
    x *= f;
}
template<class I>
inline void write(I x) {
    if(x == 0) {putchar('0'); return;}
    I tmp = x > 0 ? x : -x;
    if(x < 0) putchar('-');
    int cnt = 0;
    while(tmp > 0) {
        buf[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while(cnt > 0) putchar(buf[--cnt]);
}

#define in(x) read(x)
#define outn(x) write(x), putchar('\n')
#define out(x) write(x), putchar(' ')

} using namespace io;

#define ull unsigned long long
#define ll long long
const int N = 100010;

struct Node {
	int a, b;
} a[N];
bool cmp(Node a, Node b) {return a.a < b.a;}
bool operator < (Node a, Node b) {return a.b < b.b;}
priority_queue<Node>q;

int main() { 
	int n, m; read(n); read(m);
	for(int i = 1; i <= n; ++i) read(a[i].a), read(a[i].b);
	sort(a+1,a+n+1,cmp);
	int cur = 1, ans = 0;
	for(int i = 1; i <= m; ++i) {
		while(cur <= n && a[cur].a <= i) q.push(a[cur]), ++cur;
		if(!q.empty()) {
			int v = q.top().b; q.pop();
			ans += v;
		}
	}
	outn(ans);
}

Measured memory_bytes: 2168
N, W = map(int, input().split())
X = [0] + [-1] * 110000
ma = 0
for i in range(N):
    w, v = map(int, input().split())
    
    for j in range(len(X))[::-1]:
        if X[j] >= 0:
            if X[j] + w <= W:
                if X[j+v] < 0:
                    X[j+v] = X[j]+w
                    ma = max(ma, j+v)
                else:
                    X[j+v] = min(X[j+v], X[j]+w)

print(ma)

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

using namespace std;

int main(){
    long long n, m, ans = 0;
    cin >> n >> m;
    for (long long i = 1; i*i <= m; i++){
        if (m % i == 0){
            if (i*n <= m) ans = max(ans, i);
            if (m/i*n <= m) ans = max(ans, m/i);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
if n >= m:
    print(0)
    exit(0)
x = list(map(int, input().split()))
x.sort()
distance = [x[i + 1] - x[i] for i in range(m - 1)] 
distance.sort()
print(sum(distance[:m - n]))

Measured memory_bytes: 13968
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>
#include <unordered_set>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct Dice{
	char face[6];
	void Turn(int a,int b,int c,int d){
		int x=face[a];
		face[a]=face[b];
		face[b]=face[c];
		face[c]=face[d];
		face[d]=x;
	}
	void TurnX(){Turn(1,5,4,2);}
	void TurnY(){Turn(0,2,3,5);}
	void TurnZ(){Turn(0,4,3,1);}
};
ostream& operator<<(ostream& os,const Dice& d)
{
	const char* f=d.face;
	printf("(%c,%c,%c,%c,%c,%c)",f[0],f[1],f[2],f[3],f[4],f[5]);
	return os;
}

// upper case <-> lower case
char flip(char c)
{
	return c^1<<5;
}
bool match(char a,char b)
{
	return flip(a)==b;
}

void update(Dice& d,int i)
{
	if(i%2==0) d.TurnX();
	if(i%2==1) d.TurnY();
	if(i%6==5) d.TurnZ();
}

string rotatemin(const string& s)
{
	string t=s;
	rep(i,s.size())
		t=min(t,s.substr(i)+s.substr(0,i));
	return t;
}

string solve(Dice ds[])
{
	vector<unordered_set<string>> upper(256),lower(256);
	int ps[8]; iota(ps,ps+8,0);
	do{
		int bit=0;
		rep(i,4) bit|=1<<ps[i];
		char* fs[4]; rep(i,4) fs[i]=ds[ps[i]].face;
		for(int i=0;i<24;update(ds[ps[0]],i),i++){
			for(int j=0;j<24;update(ds[ps[1]],j),j++){
				if(!match(fs[0][0],fs[1][3]))
					continue;
				for(int k=0;k<24;update(ds[ps[2]],k),k++){
					if(!match(fs[1][1],fs[2][4]))
						continue;
					for(int l=0;l<24;update(ds[ps[3]],l),l++){
						if(!match(fs[2][3],fs[3][0]) || !match(fs[3][4],fs[0][1]))
							continue;
						upper[bit].insert(rotatemin({fs[0][2],fs[1][2],fs[2][2],fs[3][2]}));
						lower[bit].insert(rotatemin({fs[0][5],fs[1][5],fs[2][5],fs[3][5]}));
					}
				}
			}
		}
	}while(reverse(ps+4,ps+8),next_permutation(ps,ps+8));
	
	rep(i,256) for(string s:upper[i]){
		for(char& c:s) c=flip(c);
		if(lower[255^i].count(rotatemin(s)))
			return "YES";
	}
	return "NO";
}

int main()
{
	for(Dice ds[8];;){
		rep(i,8){
			char* f=ds[i].face;
			cin>>f[2]>>f[0]>>f[1]>>f[4]>>f[3]>>f[5];
		}
		if(ds[0].face[2]=='0') break;
		
		cout<<solve(ds)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 4704
//#include "pch.h" 
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod 1e9 + 7
#define inf 1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
using namespace std;
int a[114514], b[114514];
signed main() {
	int n, q;
	string s;
	cin >> n >> q >> s;
	int m = s.size();
	a[0] = 0;
	b[0] = 0;
	for(int i=0;i<n;i+=2) {
		if (s[i] == 'A'&&s[i + 1] == 'C'&&i+1<n) {
			a[i+1] = 1;
		}
		else a[i+1] = 0;
	}
	for (int i = 1; i < n; i+=2) {
		if (s[i] == 'A'&&s[i + 1] == 'C'&&i + 1 < n) {
			b[i + 1] = 1;
		}
		else {
			b[i + 1] = 0;
		}
	}
	rep(i, n) {
		a[i + 1] += a[i];
		b[i + 1] += b[i];
	}
	rep(i, q) {
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		cout << a[r] - a[l] + b[r] - b[l] << endl;
	}
}

Measured memory_bytes: 2688
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
 
if (A[0][0] in b) and (A[0][1] in b) and (A[0][2] in b) or \
    (A[1][0] in b) and (A[1][1] in b) and (A[1][2] in b) or \
    (A[2][0] in b) and (A[2][1] in b) and (A[2][2] in b) or \
    (A[0][0] in b) and (A[0][1] in b) and (A[0][2] in b) or \
    (A[0][0] in b) and (A[1][0] in b) and (A[2][0] in b) or \
    (A[0][1] in b) and (A[1][1] in b) and (A[2][1] in b) or \
    (A[0][2] in b) and (A[1][2] in b) and (A[2][2] in b) or \
    (A[0][0] in b) and (A[1][1] in b) and (A[2][2] in b) or \
    (A[0][2] in b) and (A[1][1] in b) and (A[2][0] in b):
    print('Yes')
else:
    print('No')

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

char getGrade(int m,int f, int r){
    int sum =m + f;
    char grade;
    if(m==-1||f==-1){
        grade='F';
    }else if(80<=sum){
        grade='A';
    }else if(65<=sum&&sum<80){
        grade='B';
    }else if(50<=sum&&sum<65){
        grade='C';
    }else if(30<=sum&&sum<50){
        if(50<=r)grade='C';
        else grade='D';
    }else if(sum<30){
        grade='F';
    }
    
    return grade;
}

int main(){
    int m,f,r;
    while(1){
        cin>>m>>f>>r;
        if(m==-1&&f==-1&&r==-1)break;
        cout<<getGrade(m,f,r)<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
int gcd(int a, int b){
   if (a%b == 0){
       return(b);
   }else{
       return(gcd(b, a%b));
   }
}
int main() {

int a;cin>>a;
  int b[a];
  rep(i,a){cin>>b[i];}
  
  int ans=b[0];
  rep(j,a){ans=gcd(b[j],ans);}
  
  cout<<ans<<endl;
  

}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>

#define div1 1000000007

using namespace std;

int main(void)
{
    int a, b, i;

    cin >> a >> b;

    if(a < b){
        for(i=1; i<=b; i++){
            cout << a;
        }
    }
    else{
        for(i=1; i<=a; i++){
            cout << b;
        }
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
s = list(input())

even_s_list = ['R', 'U', 'D']
odd_s_list = ['L', 'U', 'D']
result = 'Yes'
for i, c in enumerate(s):
    if (i % 2 == 0) and not (c in even_s_list):
        result = 'No'
        break
    if (i % 2 == 1) and not (c in odd_s_list):
        result = 'No'
        break

print(result)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    vector<long long> p(N);
    for (int i = 0; i < N; ++i){
        cin >> p[i], ++p[i];
    }

    vector<long long> s(N+1, 0);
    for (int i = 0; i < N; ++i) s[i+1] = s[i] + p[i];

    // K 差を見ていく
    long long res = 0;
    for (int i = 0; i+K <= N; ++i) res = max(res, s[i+K] - s[i]);
    cout << fixed << setprecision(10) << (double)(res)/2 << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>

int main(void)
{
        int n,k,ans;
        scanf("%d %d",&n,&k);

        if(n % 2 == 0 && n / 2  >= k) {
                printf("YES\n");
        } else if(n % 2 == 1 && n / 2 + 1 >= k) {
                printf("YES\n");
        } else {
                printf("NO\n");
        }

        return 0;
}


Measured memory_bytes: 128