akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

struct Card{int num; char suit;};

void bubbleSort(Card c[], int N);
void selectionSort(Card c[], int N);
void swap(Card& x, Card& y);
void showArray(Card c[], int N);
bool Stable(Card x[], Card y[], int N);

int main()
{
	int N;
	Card c1[36], c2[36];
	cin >> N;
	for(int i = 0; i < N; i++)
	{
		cin >> c1[i].suit >> c1[i].num;
		c2[i] = c1[i];
	}

	bubbleSort(c1, N);
	cout << "Stable" << endl;
	selectionSort(c2, N);
	if(Stable(c1, c2, N))
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;
	return 0;
}

void bubbleSort(Card c[], int N)
{
	for(int i = 0; i < N; i++)
		for(int j = N-1; j>i; j--)
			if(c[j].num < c[j-1].num)
				swap(c[j], c[j-1]);
	showArray(c, N);
}

void selectionSort(Card c[], int N)
{
	int min;
	for(int i = 0; i<N; i++)
	{
		min = i;
		for(int j = i; j < N; j++)
			if(c[j].num<c[min].num)
				min = j;
		swap(c[i], c[min]);
	}
	showArray(c, N);
}

void swap(Card& x, Card& y)
{
	Card temp = x;
	x = y;
	y = temp;
}

void showArray(Card c[], int N)
{
	cout<<c[0].suit << c[0].num;
	for(int i = 1; i < N; i++)
		cout<<' '<< c[i].suit << c[i].num;
	cout<<endl;
}

bool Stable(Card x[], Card y[], int N)
{
	for(int i = 0; i < N; i++)
		if(x[i].suit != y[i].suit)
			return false;
	return true;
}

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

int main()
{
    int n, a[200000], ans = 0;
    cin >> n;
    for (int in = 0; in < n; in++)
    {
        cin >> a[in];
    }

    int des = 1;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == des)
        {
            des++;
            ans++;
        }
    }

    if (des == 1) cout << -1 << endl;
    else cout << n - ans << endl;
}

Measured memory_bytes: 4380
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
	const char H[4] = "HIT";
	const char R[8] = "HOMERUN";
	const char O[4] = "OUT";
	int score = 0;
	int runner = 0;
	int out = 0;
	int event = 0;
	int n;
	scanf("%d",&n);
	while(event < n){
		char s[10];
		scanf("%s",s);
		if(strcmp(s,H) == 0)
		{
			runner++;
			if(runner == 4)
			{
				score++;
				runner--;
			}
		}
		else if(strcmp(s,R) == 0)
		{
			score = score + runner + 1;
			runner = 0;
		}
		else if(strcmp(s,O) == 0) out++;
		if(out == 3){
			runner = 0;
			out = 0;
			printf("%d\n",score);
			score = 0;
			event++;
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;

const ll N = 1e5 + 10;

map<pi, ll> mp;
ll pri[N], vis[N], tot = 0;
ll n, a[N];

void get_prime(ll t) {
  for (ll i = 2; i <= t; i++) {
    if (!vis[i]) {
      pri[++tot] = i;
    }
    for (ll j = 1; j <= tot && i * pri[j] <= t; j++) {
      vis[i * pri[j]] = 1;
      if (i % pri[j] == 0) {
        break;
      }
    } 
  }
}

void solve(ll vl) {
  // cout<<vl<<"+++"<<endl;
  ll pre = 1, suf = 1;
  for (int i = 1; i <= tot && pri[i] * pri[i] * pri[i] <= vl; i++) {
    int cnt = 0;
    while (vl % pri[i] == 0) {
      vl /= pri[i];
      cnt++;
    }
    cnt %= 3;
    if (cnt == 1) {
      pre *= pri[i];
    } else if (cnt == 2) {
      suf *= pri[i];
    }
  }
  ll now = sqrt(vl);
  if (now * now == vl) {
    suf *= now;
  } else {
    pre *= vl;
  }
  mp[pi(pre, suf)]++;
}

int main() {
  get_prime(3000);
  scanf("%d", &n);
  int ans = 0;
  for (ll i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    solve(a[i]);
  }
  for (auto cur : mp) {
    ll w1 = cur.first.first, w2 = cur.first.second;
    if (w1 > w2 && mp[pi(w2, w1)]) continue;
    if (w1 == w2) {
      ans++;
    } else {
      ans += max(mp[pi(w1, w2)], mp[pi(w2, w1)]);
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

using namespace std;

vector<int> a = {1, 3, 5, 7, 8, 10, 12};
vector<int> b = {4, 6, 9, 11};
vector<int> c = {2};

int main(){
  int x, y;
  cin >> x >> y;
  if(a == b) {
    cout << "Yes" << endl;
  } else if((find(a.begin(), a.end(), x) != a.end()) &&
            (find(a.begin(), a.end(), y) != a.end())){
    cout << "Yes" << endl;
  } else if((find(b.begin(), b.end(), x) != b.end()) &&
            (find(b.begin(), b.end(), y) != b.end())){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
const ll BIGMOD = 1e9 + 7;
using namespace std;

int main() {
  string str;
  cin >> str;
  if (str[3] == str[2] && str[4] == str[5])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

W,n = inpl()
wv = [inpl() for _ in range(n)]
dp = [INF] * (W+1)
dp[0] = 0
for i in range(n):
    w,v = wv[i]
    for j in range(W+1):
        if j < w:
            dp[j] = min(dp[j], v)
            continue
        dp[j] = min(dp[j], dp[j-w] + v)
print(dp[W])

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

using ll = long long;

int const nmax = (1 << 18);
int const threshold = (1 << 9);
int const lim = 100000;
int dp[1 + threshold][1 + lim];
int v[1 + nmax], weight[1 + nmax];

int query(int node, int val) {
  if(node <= threshold)
    return dp[node][val];
  else {
    if(weight[node] <= val)
      return std::max(query(node / 2, val), query(node / 2, val - weight[node]) + v[node]);
    else
      return query(node / 2, val);
  }
}

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

  int n;
  std::cin >> n;
  for(int i = 1;i <= n; i++)
    std::cin >> v[i] >> weight[i];
  for(int i = 1;i <= std::min(n, threshold); i++) {
    for(int j = 0; j <= lim; j++)
      dp[i][j] = dp[i / 2][j];
    for(int j = weight[i]; j <= lim; j++)
      dp[i][j] = std::max(dp[i][j], dp[i / 2][j - weight[i]] + v[i]);
  }
  int q;
  std::cin >> q;
  for(int i = 1;i <= q; i++) {
    int node, val;
    std::cin >> node >> val;
    std::cout << query(node, val) << '\n';
  }
}


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

int main() {
  long X;

  cin >> X;
  int count=0;
  long a=100;
 while(a<X){
  a= 1.01*a;
   count=count+1;
 }
  cout << count <<endl;
 return 0;
}


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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 10016

int c[N], d[N], x[N], q[N];
vi adj[N];

int main()
{
    canhazfast();

    int n, k = 0, ans = 0;

    cin >> n;
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
        ++d[a];
        ++d[b];
    }
    for (int i = 0; i < n; ++i) cin >> c[i];
    sort(c, c+n);
    for (int i = 1; i <= n; ++i) {
        if (d[i] == 1) q[k++] = i;
    }
    for (int i = 0; i < n; ++i) {
        int u = q[i];
        x[u] = c[i];
        if (i+1 < n) ans += c[i];
        for (int v : adj[u]) {
            if (--d[v] == 1) q[k++] = v;
        }
    }
    cout << ans << '\n';
    for (int i = 1; i <= n; ++i) cout << x[i] << ' ';
    cout << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int N = 101;
const int CRL = -1;
int adj[N][N] = {0};
int d[N]={0};
int kai[N];

int main()
{
    int n;
    memset(d, CRL, sizeof(d));
    d[1]=0;
    queue <int> q;
    q.push(1);
    cin >> n;
    for(int i=1;i<=n;i++){
    	int k;
    	int l;
    	cin >> l >> k;
    	kai[i]=l;
    	for(int j=1;j<k+1;j++){
    		int m;
    		cin >> m;
    		adj[i][j] = m;
    	}
    }
    while(q.size()){
    	int k = q.front();
    	q.pop();
    	for(int i=1;i<kai[i]+1;i++){
    		if(d[adj[k][i]]==CRL){
    			d[adj[k][i]] = d[k]+1;
    			q.push(adj[k][i]);
    		}
    	}
    }
    for(int i=2;i<N;i++)
    	if(d[i]==0)d[i]=-1;
    for(int i=1;i<=n;i++){
    	cout << i << " " << d[i] << endl;
    }
    return 0;
}

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

int main() {
  int a,b,c,d,e,k;
  string ans = "Yay!";

  cin >> a >> b >> c >> d >> e >> k;

  if (b - a > k) {
    ans = ":(";
  }
  else if (c - a > k) {
    ans = ":(";
  }
  else if (d - a > k) {
    ans = ":(";
  }
  else if (e - a > k) {
    ans = ":(";
  }
  else if (c - b > k) {
    ans = ":(";
  }
  else if (d - b > k) {
    ans = ":(";
  }
  else if (e - b > k) {
    ans = ":(";
  }
  else if (d - c > k) {
    ans = ":(";
  }
  else if (e - c > k) {
    ans = ":(";
  }
  else if (e - d > k) {
    ans = ":(";
  }
  cout << ans << endl;
}

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

int main() {
  int a, b, c; cin >> a >> b >> c;
  int sum, div;
  sum = a + b + c;
  div = sum / 3;
  if (div == a && div == b && div == c) {
    cout << "No" << endl;
  } else if (a == b || b == c || c == a){
    cout << "Yes" << endl;
  } else cout << "No" << endl;
  return 0;
}

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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MAXN 10005
#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;


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

	int R;
	double C;

	cin >> R;

	C = 2*pi*R;

	printf("%.20f\n", C);
	return 0;		
}



Measured memory_bytes: 3744
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline


def DFS(add,next,cnt):
    x,y=add
    for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
        X,Y=x+i,y+j
        if 0<=X<h and 0<=Y<w:
            if S[X][Y]==next and color[X][Y]=="white":
                color[X][Y]=str(cnt)
                DFS([X,Y],"." if next=="#" else "#",cnt)


h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]
cnt=0

color=[["white" for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j]=="#" and color[i][j]=="white":
            cnt +=1
            DFS([i,j],".",cnt)

dictionary={str(i+1):[0,0] for i in range(cnt)}
for i in range(h):
    for j in range(w):
        if color[i][j]!="white":
            if S[i][j]==".":dictionary[color[i][j]][0] +=1
            else:dictionary[color[i][j]][1] +=1

ans=0
for v,m in dictionary.values():
    ans +=v*m
print(ans)

Measured memory_bytes: 360708
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
static const int INF = 1ll<<60;
typedef pair<int,int> pii;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};


int N,M;
int feld[11][11];
int cnt;
pii last;
int ans;

void dfs(int x,int y,int sum){
    for(int i=0;i<4;++i){
        int nx=x;
        int ny=y;
        while(1){
            nx+=dx[i];
            ny+=dy[i];
            if(nx<0||nx>=N||ny<0||ny>=M)break;
            if(feld[ny][nx]==1){
                feld[ny][nx]=-1;
                dfs(nx,ny,sum+1);
                feld[ny][nx]=1;
                break;
            }
            else if(feld[ny][nx]==2){
                if(sum==cnt){
                    ans++;
                    return ;
                }
            }
        }
    }
    return ;
}


signed main(){
    while(1){
        cin>>N>>M;
        if(N==0&&M==0)break;
        memset(feld,-1,sizeof(feld));
        for(int i=0;i<M;++i){
            for(int j=0;j<N;++j){
                cin>>feld[i][j];
                if(feld[i][j]==2){
                    last.FI=i;
                    last.SE=j;
                }
                else if(feld[i][j]==1)cnt++;
            }
        }
        dfs(last.SE,last.FI,0);
        cout<<ans<<endl;
        ans=0;
        cnt=0;
    }
}

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

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

const ll MAX_N=131072;
int bit[MAX_N*2-1];
ll n;
int main(){
  ll N;cin>>N;
  ll A[N];
  ll x=0;
  rep(i,N){
    cin>>A[i];
    if (i%2==0) x+=A[i];
    else x-=A[i];
  }
  cout<<x;
  rep(i,N-1){
    cout<<" "<<2*A[i]-x;
    x=2*A[i]-x;
  }
  cout<<endl;
}


Measured memory_bytes: 2048
def resolve():
    n = int(input())
    v = map(int,input().split())
    c = map(int,input().split())
    s = [x-y for x,y in zip(v,c) if (x-y)>0]
    ans = 0
    if s:
        ans = sum(s)
    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	int b;
	cin>>a;
	for(int i=0;i<a.size();i++)
	{
		b+=a[i]-'0';
	}
	if(b%9==0)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
 } 

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


int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i,N) cin >> H.at(i);
    int ans = 0;
    int cnt = 0;
    rep(i,N-1) {
        if (H.at(i) >= H.at(i+1)) cnt++;
        if (H.at(i) < H.at(i+1) || i == N - 2) {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    cout << ans << endl;
}


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

int main(){
	int h,w;cin>>h>>w;
	int n;cin>>n;
	vector<int> a(n);
	vector<vector<int>> c(h,vector<int>(w));
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	int x = 0;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(a[x] == 0){
				x++;
			}
			c[i][j] = x + 1;
			a[x]--;
		}
	}
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(i % 2 != 0){
				cout << c[i][w - 1 - j] << " ";
			}
			else{
				cout << c[i][j] << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int m=1e5+10;
int n;
int arr[m];
int rra[m];
int dp[m];
int a[m];
int b[m];
int c[m];
int pd[m];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	arr[0]=a[0];
	rra[0]=b[0];
	dp[0]=c[0];
	pd[0]=max(dp[0], max(arr[0], rra[0]));
	for(int i=1;i<n;i++){
		arr[i]=max(rra[i-1], dp[i-1])+a[i];
		rra[i]=max(arr[i-1], dp[i-1])+b[i];
		dp[i]=max(arr[i-1], rra[i-1])+c[i];
		pd[i]=max(dp[i], max(arr[i], rra[i]));
	}
	cout << pd[n-1] << endl;
}

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

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX / 2 + 2], R[MAX / 2 + 2];

llong merge(int A[], int n, int left, int mid, int right)
{
    int i, j, k;
    llong cnt = 0;
    int n1 = mid - left;  //  Lの要素数
    int n2 = right - mid;  // Rの要素数
    for (i = 0; i < n1; i++) {
        L[i] = A[left + i];  // Aの左側をLに
    }
    for (i = 0; i < n2; i++) {
        R[i] = A[mid + i];  // Aの右側をRに
    }
    L[n1] = R[n2] = SENTINEL;  // LとRの最後の要素は十分大きく設定する
    i = j = 0;
    for (k = left; k < right; k++) {
        if (L[i] <= R[j]) {  // LがR以下ならAにLの添字をインクリメントして入れる
            A[k] = L[i++];
        } else {
            // そうでないならAにRの添字をインクリメントして入れる
            // このときLの要素数-今までAに入れたL要素数だけcntに加算する
            // これはRはLよりも添字が大きく，Rの要素がAに入る時まだAに入ってないBの数だけ反転数が増えるということだから
            A[k] = R[j++];
            cnt += n1 - i;  // = mid + j - k - 1
        }
    }
    return cnt;
}

llong mergeSort(int A[], int n, int left, int right)
{
    int mid;
    llong v1, v2, v3;
    if (left + 1 < right) {
        mid = (left + right) / 2;
        v1 = mergeSort(A, n, left, mid);
        v2 = mergeSort(A, n, mid, right);
        v3 = merge(A, n, left, mid, right);
        return v1 + v2 + v3;
    } else {
        return 0;
    }
}

int main()
{
    int A[MAX], n, i;

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

    llong ans = mergeSort(A, n, 0, n);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4644
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}

ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
//////////////////////////////////////
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int g=gcd(a,b);
    if(c%g==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    return 0;
}

Measured memory_bytes: 3572
#pragma GCC optimize "O3"

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e4 + 10, INF = INT_MAX / 4;

class BipartiteMatching { // O( ( V + E ) * sqrt( V ) )
 public: 
  vector< int > G[ N ]; // N = total number of nodes = n + m
  int n, m, match[ N ], dist[ N ];
  // n: number of nodes on left side, nodes are numbered 1 to n
  // m: number of nodes on right side, nodes are numbered n+1 to n+m
  // G = NIL[0] ??? G1[G[1---n]] ??? G2[G[n+1---n+m]]
  bool BFS() {
    queue< int > Q;
    for (int i = 1; i <= n; i++ ) {
      if ( match[ i ] == 0 ) {
        dist[ i ] = 0;
        Q.push( i );
      }
      else dist[ i ] = INF;
    }
    dist[ 0 ] = INF;
    while ( !Q.empty() ) {
      int u = Q.front(); Q.pop();
      if ( u != 0 )
        for(int v : G[u])
          if ( dist[ match[ v ] ] == INF ) {
            dist[ match[ v ] ] = dist[ u ] + 1;
            Q.push( match[ v ] );
          }
    }
    return ( dist[ 0 ] != INF );
  }
  bool DFS( int u ) {
    if ( u != 0 ) {
      for(int v : G[u])
        if ( dist[ match[ v ] ] == dist[ u ] + 1 and DFS( match[ v ] ) ) {
          match[ v ] = u;
          match[ u ] = v;
          return true;
        }
      dist[ u ] = INF;
      return false;
    }
    return true;
  }
  int Solve() {
    int matching = 0;
    fill_n(match, n+m+1, 0);
    while ( BFS() )
      for (int i = 1; i <= n; i++ )
        if ( match[ i ] == 0 and DFS( i ) ) matching++;
    return matching;
  }
  void AddEdge( int u, int v ) { G[ u ].push_back( n + v ); }
} ob;

int main() {
  int E; scanf("%d %d %d", &ob.n, &ob.m, &E);
  for(int i = 0; i < E; ++i) {
    int x, y; scanf("%d %d", &x, &y);
    ob.AddEdge(x+1, y+1);
  }
  printf("%d\n", ob.Solve());
}

Measured memory_bytes: 3536
using System;
using System.Collections.Generic;
using System.Linq;

namespace ForATCODER
{
    public class Program
    {
        public static void Main(string[] args)
        {
            long res = 0;
            //     long[] kn = s2iarray(Console.ReadLine().Split(' '));
            //   long[] an = s2iarray(Console.ReadLine().Split(' '));
           int r =  s2i(Console.ReadLine());
            Console.WriteLine(r * 2* Math.PI);


        }
      
      
        static int s2i(String s)
        {
            return Convert.ToInt32(s);
        }
        static void RESULT(double res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(long res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(ulong res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(int res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(String res)
        {
            Console.WriteLine(res);
        }
        static String[] ReadLineAll(int count)
        {
            String[] res = new String[count];
            for (int i = 0; i < count; i++)
            {
                res[i] = Console.ReadLine();
            }
            return res;
        }

        static int[] s2iarray(String[] src)
        {
            int len = src.Length;
            int[] res = new int[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt32(src[i]);
            }
            return res;
        }
        static long[] s2larray(String[] src)
        {
            int len = src.Length;
            long[] res = new long[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt64(src[i]);
            }
            return res;
        }
    }
}


Measured memory_bytes: 27632
#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;

const string M_INF="-";

int n,m,cost[]={0,2,5,5,4,5,6,3,7,6};
string dp[10010];

void chmax(string &s, string t){
  if(s==M_INF)s=t;
  else if(s.size()<t.size())s=t;
  else if(s.size()==t.size())if(s<t)s=t;
}

int main(){
  cin>>n>>m;
  vector<int>a(m);
  rep(i,m)cin>>a[i];
  
  rep(i,10010)dp[i]=M_INF;
  dp[0]="";
  for(int i=0; i<=n; ++i){
    if(dp[i]==M_INF)continue;
    rep(j,m){
      chmax(dp[i+cost[a[j]]],dp[i]+char(a[j]+'0'));
    }
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 54796
// https://atcoder.jp/contests/abc129/tasks/abc129_c

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1000000007)
#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))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

int ret[100002];
set<int> st;
int rec(int n) {
    ll ans = 0;
    if (ret[n] != -1) {
        return ret[n];
    }
    if (n == 0) {
        return 1;
    }
    if (n - 1 >= 0 && st.count(n - 1) == 0) {
        ans += rec(n - 1);
    }
    if (n - 2 >= 0 && st.count(n - 2) == 0) {
        ans += rec(n - 2);
    }
    return ret[n] = (ans % MOD);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m, t;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        cin >> t;
        st.insert(t);
    }
    fill((int *)ret, (int *)(ret + lengthof(ret)), -1);
    cout << rec(n) << endl;
    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=100009;
int m,n,v,p;
int a[N],pf[N];
bool f(int i){
	int rem=m*v-(n-i)*m;
	rem-=(p-1)*m;
	if(rem<=0)return a[i]+m>=a[p-1];
	int avg=ceil(((pf[i-1]-pf[p-2])+rem)/(long double)(i-p+1));
	// cout << rem << " " << pf[i-1] << " " << pf[p-2] << endl;
	// cout << a[i]+m <<  "          "<< (avg) << " " << i << endl;
	return ((a[i]+m)>=avg and a[i]+m>=a[p-1]);
}
int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	cin >> n >> m >> v >> p;
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a,a+n);
	reverse(a,a+n);
	pf[0]=a[0];
	for(int i=1;i<n;++i)pf[i]=pf[i-1]+a[i];
	int ans=p,val=a[0];
	for(int i=p;i<n;i++){
		if(a[i]==a[i-1])ans++;
		else if(f(i))ans++;
		else break;
	}
	cout << ans;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    FOR(i,1,s.size()){
        int len = s.size()-i;
        if (len&1) continue;
        string t = s.substr(0,len);
        if (t.substr(0,len/2)==t.substr(len/2,len/2)){
            cout<<len<<endl;
            break;
        }
    }
    return 0;
}


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

using namespace std;

int main(){
	int n;
	cin>>n;
	int cant[4];
	
	for(int i=0; i<4; i++)cant[i]=0;
	for(int i=0; i<n; i++){
		int p;
		cin>>p;
		cant[p%4]++;
	}
	//for(int i=0; i<4; i++)cout<<cant[i]<<" ";
	if(cant[0]>=cant[1]+cant[3] || (cant[0]+1==cant[1]+cant[3] && cant[2]==0)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


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

int main() {
  int N;
  cin >> N;
  string S;
  bool diverse;
  for (int i=0; i<N; i++) {
    cin >> S;
    if (S == "Y") {
      cout << "Four" << endl;
      diverse = true;
      break;
    }
    else {
      diverse = false;
    }
  }
  if (!diverse) {
    cout << "Three" << endl;
  }
}

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

int main(){
    
    int n,k,t;
    cin>>n>>k>>t;
    int cnt=0;
    while(k<n){
        cnt+=t;
        n=n-k;
    }
    if(n>0) cnt+=t;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3620
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

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

    ll a;
    ll ans = 1;
    ll MAX = 1e18;
    bool flag = 0;
    bool zero = 0;

    rep(i, n) {
        cin >> a;
        if (a==0) zero = 1;
        // else if (ans > MAX/a) flag = 1;
        if (ans!=0 && a > MAX/ans) flag = 1;
        // if (ans != 0) if (a > MAX/ans) flag = 1;
        ans *= a;
        // cout << ans << endl;
    }

    if (zero) cout << 0 << endl;
    else if (flag) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<deque>
using namespace std;
const long mod=1e9+7;
string s;
long calc(deque<long>&Q)
{
	long A=-1,B=0;
	while(!Q.empty()&&Q.front()!=-3)
	{
		long now;
		if(Q.front()==-2)
		{
			Q.pop_front();
			long T=calc(Q);
			Q.pop_front();
			now=T*T%mod;
		}
		else
		{
			now=Q.front();
			Q.pop_front();
		}
		if(A==-1)A=now;
		else
		{
			B+=now;
			if(B>=32)B=32;
		}
	}
	return A>>B;
}
main()
{
	while(getline(cin,s),s!="#")
	{
		deque<long>P;
		for(int i=0;i<s.size();)
		{
			if(s[i]=='S')
			{
				i++;
				P.push_back(-2);
				while(s[i]!='<')i++;
				i++;
			}
			else if(s[i]=='>')
			{
				i++;
				P.push_back(-1);
			}
			else if(s[i]==' ')i++;
			else
			{
				long t=0;
				while('0'<=s[i]&&s[i]<='9')
				{
					t=t*10+s[i]-'0';
					i++;
				}
				P.push_back(t);
			}
		}
		deque<long>Q;
		bool num=false;
		for(int i=P.size()-1;i>=0;)
		{
			if(P[i]>=0)
			{
				num=true;
				Q.push_front(P[i]);
				i--;
			}
			else if(P[i]==-2)
			{
				Q.push_front(-2);
				i--;
			}
			else
			{
				if(num)
				{
					if(i>=1&&P[i-1]==-1)
					{
						i-=2;
						num=false;
					}
					else
					{
						cout<<"ERROR"<<endl;
						return 1;
					}
				}
				else
				{
					Q.push_front(-3);
					i--;
					num=false;
				}
			}
		}
		cout<<calc(Q)<<endl;
	}
}



Measured memory_bytes: 6108
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(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));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

ll dp[301][301][301];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,K;
	cin>>n>>K;
	vl v(n+1);
	rep(i,n)cin>>v[i+1];
	rep(i,301)rep(j,301)rep(k,301)dp[i][j][k]=(i==0?0:LINF);
	rep(i,300)rep(j,300)rep(k,i+1){
		//naosu
		chmin(dp[i+1][j+1][k],dp[i][j][k]);
		//naosanai
		chmin(dp[i+1][j][i+1],dp[i][j][k]+max(0ll,v[i+1]-v[k]));
	}
	ll ans=LINF;
	rep(i,301)chmin(ans,dp[n][K][i]);
	cout<<ans<<endl;

}


Measured memory_bytes: 213376
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

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

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

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

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

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

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	X:=readInt()
	A:=readInt()
	if X < A {
		println(0)
	} else {
		println(10)
	}
}

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


Measured memory_bytes: 640
from itertools import product
N, M = map(int, input().split())
S = []
for m in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])
P = list(map(int, input().split()))

ans = 0
for c in product([0, 1], repeat=N):
    ok = True
    for m in range(M):
        sm = 0
        for s in S[m]:
            sm += c[s - 1]
        if sm % 2 != P[m]:
            ok = False
            break
    if ok:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int k;
int a,b;

void solve(){
    cin >> k;
    cin >> a >> b;
    Rep(i,a,b+1){
        if(i%k==0){
            cout << "OK" << endl;
            return;
        }
    }
    cout << "NG" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

const int INF = 1001001001;

int wa(int x) {
  string s = to_string(x);
  int n = sz(s);

  int sum = 0;
  for (int i = 0; i < n; ++i) sum += stoi(s.substr(i, 1));

  return sum;
}

void Main() {
  Cin(int, n);

  int ans = INF;
  for (int a = 1; a <= n - 1; ++a) {
    int b = n - a;
    ans = min(ans, wa(a) + wa(b));
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n l ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let rec loop i =
        if i = n - 1 then (-1) else
            if a.(i) + a.(i + 1) >= l then i else loop (i + 1)
    in
    let k = loop 0 in
    if k < 0 then print_endline "Impossible" else (
        print_endline "Possible";
        for j = 0 to k - 1 do
            Printf.printf "%d\n" (j + 1)
        done;
        for j = n - 2 downto k + 1 do
            Printf.printf "%d\n" (j + 1)
        done;
        Printf.printf "%d\n" (k + 1)
    )
)

Measured memory_bytes: 6016
open Batteries
open BatPrintf

let scan fmt f =
  Scanf.sscanf (read_line ()) fmt f

let scan_list cnv =
  read_line ()
  |> String.split_on_char ' '
  |> List.map cnv

let scan_listn n cnv =
  (0 --^ n) /@ (fun _ -> (cnv % read_line) ())

let rec zip xs ys =
  match xs, ys with
  | [], _ -> []
  | _, [] -> []
  | x::xs, y::ys ->
    (x, y) :: zip xs ys

let n = scan "%d" identity
let s = scan_listn n identity

module SMap = Map.Make (struct
    type t = string
    let compare = String.IString.compare
  end)

let () =
  let map = fold (fun m k -> SMap.modify_def 0 k succ m) SMap.empty s in
  let m = SMap.fold (fun _ v m -> if v > m then v else m) map 0 in
  SMap.filter (fun _ n -> n = m) map
  |> SMap.keys
  |> List.of_enum
  |> List.sort String.compare
  |> String.concat "\n"
  |> printf "%s\n"


Measured memory_bytes: 36032
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <string>

using namespace std;
 
int main()
{
    int n;
    cin >> n;
    int r[n+1] = {};
    int p;
    int k = 0;
    for (int i = 0;i<n;i++){
        cin >> p;
        r[p+1]=r[p]+1;
        if(k < r[p+1]){
            k = r[p+1];
        }
    }
    cout << n-k;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int mat[2][n];
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin>>mat[i][j];
        }
    }
    
    int dp[2][n];
    dp[0][0]=mat[0][0];
    for(int i=1;i<n;i++){
        dp[0][i]= mat[0][i]+dp[0][i-1];
    }
    dp[1][0]= mat[1][0]+mat[0][0];
    
    
    for(int j=1;j<n;j++){
            dp[1][j] = mat[1][j] + max(dp[1][j-1],dp[0][j]);
        }
    cout<<dp[1][n-1];
    
    return 0;
    
}

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

const int maxn = 100010;
int n, x, ans, tot, a[maxn], b[maxn], c[maxn], d[maxn], fa[maxn];
map<int, int> mp;
bool chk[maxn];

int find(int x) {
    return x == fa[x] ? x : fa[x] = find(fa[x]);
}

int main() {
    scanf("%d", &n), n++;
    for (int i = 1; i < n; i++) {
        scanf("%d", &a[i]), c[i] = a[i], x ^= a[i];
    }
    a[n] = c[n] = x, sort(c + 1, c + n + 1), x = 0;
    for (int i = 1; i < n; i++) {
        scanf("%d", &b[i]), d[i] = b[i];
        fa[i] = i, x ^= b[i];
    }
    b[n] = d[n] = x, sort(d + 1, d + n + 1), fa[n] = n;
    int tot = 0;
    for (int i = 1; i <= n; i++) {
        if (c[i] ^ d[i]) printf("-1\n"), exit(0);
        if (!mp.count(c[i])) mp[c[i]] = ++tot;
    }
    for (int i = 1; i <= n; i++) {
        a[i] = mp[a[i]], b[i] = mp[b[i]];
        if (a[i] == b[i]) continue;
        if (i < n) ans++;
        int u = find(a[i]), v = find(b[i]);
        fa[u] = v, chk[u] = chk[v] = 1;
    }
    if (!ans) printf("0\n"), exit(0);
    chk[a[n]] = chk[b[n]] = 1;
    for (int i = 1; i <= tot; i++) {
        ans += (chk[i] && find(i) == i);
    }
    printf("%d\n", ans - 1);
    return 0;
}

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

const int MOD = (int)1e9+7;

int main(){
	int H,W;
	cin >> H >> W;
	vector<vector<int>> c(10,vector<int>(10));
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cin >> c.at(i).at(j);
		}
	}
	vector<vector<int>> A(H,vector<int>(W));
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> A.at(i).at(j);
		}
	}

	vector<int> mi(10);
	priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>> pq;
	for(int i=0;i<10;i++){
		if(i==1)	continue;
		vector<int> dis(10,1e9);
		dis.at(i)=0;
		for(int j=0;j<10;j++){
			pq.push(make_tuple(c.at(i).at(j),i,j));
		}
		while(!pq.empty()){
			int cost,start,end;
			tie(cost,start,end)=pq.top();
			pq.pop();
			if(dis.at(end)<=dis.at(start)+cost)	continue;
			dis.at(end)=min(dis.at(end),dis.at(start)+cost);
			for(int j=0;j<10;j++){
				if(dis.at(j)<=dis.at(end)+c.at(end).at(j))	continue;
				pq.push(make_tuple(c.at(end).at(j),end,j));
			}
		}
		mi.at(i)=dis.at(1);
	}
	
	int ans=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(A.at(i).at(j)==1 || A.at(i).at(j)==-1)	continue;
			ans+=mi.at(A.at(i).at(j));
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 384
import itertools
n, m, q = [int(i) for i in input().split(" ")]
A = []
for i in range(q):
    A.append([int(i) for i in input().split(" ")])
given = [i for i in range(1, m + 1)]
ans = itertools.combinations_with_replacement(given, n)
answer = 0
for solve in ans:
    now = 0
    for i in range(q):
        if (solve[A[i][1] - 1] - solve[A[i][0] - 1]) == A[i][2]:
            now += A[i][3]
    if (now > answer):
        answer = 0 + now
print(answer)


Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, s, e) for (int i = s; i < e; i++)
#define endl '\n'
int main()
{
    int N;
    cin >> N;
    set<int> D;
    rep(i, 0, N)
    {
        int tmp;
        cin >> tmp;
        D.insert(tmp);
    }
    cout << D.size() << endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std ;
#define For(i,a,b) for(int i = (a) , _b = (b) ; i <= _b ; i++ )
#define Ford(i,a,b) for(int i = (a) , _b = (b) ; i >= _b ; i-- )
typedef long long ll ;
typedef pair<int,int> II ;
const int N = 1e6 + 5 ;
const ll base = 1e9 + 7 ;
const ll inf = 1e18 + 7 ;
int n ;
ll a[N] , r[N] , l[N] ;
priority_queue<ll , vector<ll> , greater<ll> > q ;
priority_queue<ll> q1 ;
int main() {
    //freopen(task".inp" , "r" , stdin ) ; freopen(task".out" , "w" , stdout ) ;
    ios_base::sync_with_stdio(false) ; cin.tie(NULL) ;
    cin >> n;
    For(i , 1 , 3*n) cin >> a[i] ;
    /// tinh l[i] ;
    ll to =  0;
    For(i , 1 , n) {
        q.push(a[i]) ;
        to += a[i];
    }
    l[n] = to;
    For(i , n+1 , 3*n) {
        if(q.top() < a[i]) {
            to -= q.top() ;
            q.pop() ;
            q.push(a[i])  ;
            to = to + a[i] ;
        }
        l[i] = to;
    }

    to = 0;
    For(i , n*2+1 , n*3) {
        q1.push(a[i]);
        to+=a[i];
    }
    r[n*2+1] = to;
    Ford(i , n*2 , 1) {
        if(q1.top() > a[i]) {
            to -= q1.top() ;
            q1.pop() ;
            q1.push(a[i]) ;
            to = to + a[i] ;
        }
        r[i] = to;
    }
    ll ans = -inf;
    For(i , n , n*2) ans = max(ans , l[i] - r[i+1]);
    cout << ans ;
    return 0 ;
}


Measured memory_bytes: 13428
#include<iostream>
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>
#include<math.h>
#include"boost/algorithm/string.hpp"
#include<array>

using namespace std;



int main(){
	/*Q4*/
	unsigned long long n, ret = 0;
	cin >> n;
	unsigned long long i = n - 1;
	unsigned long long sq_n = sqrt(n);
	
	for (unsigned long long j = 1;j <= sq_n; j++){
		unsigned long long k = i / j;
		if (k == 0){
			break;
		}
		if (n / k == n % k){
			ret += k;
		}
	}

	cout << ret << endl;
	return 0;
	/*Q3*/
	//std::array<string, 1000> str;


	/*Q2*/

/*	int r, g, b;//ハコの中の個数
	int n;
	int ret = 0;
	cin >> r >> g >> b >> n;
	int i_st = n / r, j_st = n / g, k_st = n / b;
	int i, j, k;
	int x, y, z;

	for (i = i_st; -1 < i; --i){
		x = r * i;
		for (j = j_st; -1 < j; --j){
			y = g * j;
		
			if (
				((n-x-y) > -1)
				&& ((n-x-y) % b == 0)
				){
				++ret;
			}
		}
	}

	cout << ret << endl;

	return 0;


	/*Q1*/
	/*
	int a, b;
	cin >> a >> b;

	cout << (int)(a - b + 1) << endl;
	
	return 0;
	*/
}

Measured memory_bytes: 256
// AOJ 2310 Rose Garden Witch
// 2018.3.14 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct { double a; int f; } T;
T tbl[100000]; int sz;
char map[605][605];
int f[16] = {0,-1,0,0,0,0,0,1,1,0,0,0,0,0,-1,0};

int cmp(T *a, T *b) {
	if (fabs(a->a - b->a) < 1e-7) return a->f - b->f;
	if (a->a <= b->a) return -1; return 1;
}

int main()
{
	int H, W, r, c, t, i, ans;
	char buf[20];

	fgets(buf, 10, stdin), sscanf(buf, "%d%d", &H, &W);
	for (r = 1; r <= H; r++) {
		fgets(map[r]+1, 603, stdin);
		for (c = 1; c <= W; c++) map[r][c] &= 1; map[r][c] = 0;
	}

	sz = 0;	for (r = 0; r <= H; r++) for (c = 0; c <= W; c++) {
		int x = ((map[r][c]<<3) | (map[r][c+1]<<2) | (map[r+1][c]<<1) | map[r+1][c+1]) & 0xf;
		if (f[x]) tbl[sz].a = atan2(H-r, c), tbl[sz++].f = f[x];
	}

	qsort(tbl, sz, sizeof(T), cmp);
	ans = 0; for (t = 1, i = 0; i < sz; i++) if ((t += tbl[i].f) > ans) ans = t;
	if (ans < 2) ans = 2;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 4572
import java.util.Scanner;

public class Main{
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			long K = scan.nextLong();
			long A = scan.nextLong();
			long B = scan.nextLong();

			if(B-A>2) {
				if(1+K<A+2) {
					System.out.println(1+K);
				}else {

					K=K-(A-1);

					long s = K/2;
					long r = K%2;

					long goukei =1+(A-1)+s*(B-A)+r;


					System.out.println(goukei);

				}

			}else{
				System.out.println(1+K);
			}

		}


	}



}


Measured memory_bytes: 35660
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b, c, d, f;
  double e;
  cin >> a >> b >> c >> d >> e >> f;
  set<double> w, s;
  for (int i = 0; 100 * a * i <= f; i++)
  {
    for (int j = 0; 100 * a * i + 100 * b * j <= f; j++)
    {
      if (i == 0 && j == 0)
        continue;
      w.insert(100 * a * i + 100 * b * j);
    }
  }
  for (int i = 0; c * i <= f; i++)
  {
    for (int j = 0; c * i + d * j <= f; j++)
      s.insert(c * i + d * j);
  }
  int aw = 100 * a, as = 0;
  double Max = 0;
  double D = e / (100 + e);
  for (auto itr = w.begin(); itr != w.end(); itr++)
  {
    for (auto jtr = s.begin(); jtr != s.end(); jtr++)
    {
      if (*itr + *jtr > f)
        break;
      double dens = *jtr / (*itr + *jtr);
      if (dens > Max && dens <= D)
      {
        Max = dens;
        aw = *itr;
        as = *jtr;
      }
    }
  }
  cout << aw + as << " " << as << endl;
  return 0;
}


Measured memory_bytes: 384