akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int mod=1e9+7,M=5e3+7;
LL read(){
	LL ans=0,f=1,c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
	return ans*f;
}
LL qmod(LL a,LL b){
	LL ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod; b>>=1;
	}
	return ans;
}
LL n,m,dp[M][M];
char s[M];
int main(){
	n=read();
	scanf("%s",s+1);
	m=strlen(s+1);
	dp[0][0]=1;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=i;j++){
			dp[i+1][j+1]=(dp[i+1][j+1]+2*dp[i][j]%mod)%mod;
			dp[i+1][max(j-1,0)]=(dp[i+1][max(j-1,0)]+dp[i][j])%mod;
		}	
	}
	LL ans=dp[n][m]*qmod(qmod(2,m),mod-2)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 194176
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    x = NI()
    print(1-x)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68832
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal a = sc.nextBigDecimal();
		BigDecimal b = sc.nextBigDecimal();
		BigDecimal c = a.multiply(b);
		System.out.println(c.setScale(0, BigDecimal.ROUND_DOWN));
	}

}


Measured memory_bytes: 37552
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long FINV(int n){
    if (n < 0) return 0;
    return finv[n];
}

int main() {
    // 前処理
    COMinit();

    ll n, k;
    cin >> n >> k;
    ll a[n];
    rep(i,n)cin >> a[i];
    sort(a,a+n);
    ll ans = 0;
    
    rep(i,n){
        ans += a[i] * COM(i, k-1) % MOD;
        ans %= MOD;
    }
    rep(i,n){
        ans += (MOD - a[i]) * COM(n-1-i, k-1) % MOD;
        ans %= MOD;
    }

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


Measured memory_bytes: 12928
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int ans = 100000;
		for(int i = 1; i <= n; i++) {
			int tmp1 = 0;
			int tmp2 = 0;
			for(int j = 0; j < n; j++) {
				if(j <= i) {
					tmp1 += a[j];
				}else {
					tmp2+= a[j];
				}
			}
			int tmp3 = Math.abs(tmp1-tmp2);
			ans = Math.min(ans, tmp3);
		}
		System.out.println(ans);
		sc.close();
	}
	
    
}


Measured memory_bytes: 21716
#include<iostream>
#include <vector>
using namespace std;
   
int Merge(int A[],int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int i,j,k;
  int L[n1+1],R[n2+1];
     
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1]=1000000000;
  R[n2]=1000000000;
     
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }else{
      A[k]=R[j];
      j++;
    }
  }
  return right-left;
}
   
int Merge_Sort(int A[],int left,int right){
  int mid,res=0;
  if(left+1<right){
    mid=(left+right)/2;
   
    res+=Merge_Sort(A,left,mid);
    res+=Merge_Sort(A,mid,right);
    res+=Merge(A,left,mid,right);
       
  }
  return res;
}

int Partition(vector<int> &vec, int left, int right) {
    int split = vec[right];
    int i = left - 1;
    for (int j = left; j < right; ++j) {
        if (vec[j] <= split) {
            ++i;
            std::swap(vec[i], vec[j]);
        }
    }
    std::swap(vec[i + 1], vec[right]);
 
    return i + 1;
}
 
void QuickSort(vector<int> &vec, int left, int right) {
    if ((left < right) && (left >= 0)) {
        int q = Partition(vec, left, right);
        QuickSort(vec, left, q - 1);
        QuickSort(vec, q + 1, right);
    }
}

int main(){
  int i,x,n,S[500000]; 
  cin>>n;
  for(i=0;i<n;i++)cin>>S[i];

  vector<int> vec(S,S + n);
  QuickSort(vec, 0, vec.size() - 1);
   
  x=Merge_Sort(S,0,n);
     
  for(i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<vec[i];
  }
  cout<<endl;
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 8532
fib = [1,1,2,3,5,8,13,21,34]
mod = 1000000007
H,W,K = list(map(int,input().split()))

dp = [[0]*(W+2) for i in range(H+1)]
dp[0][1] = 1

for i in range(1,H+1):
  for j in range(1,W+1):
    if j == 1:
      dp[i][j] = ( dp[i-1][j]*fib[W-1] + dp[i-1][j+1]*fib[W-2] ) %mod
    elif j == W+1:
      dp[i][j-1] = ( dp[i-1][j]*fib[j-2]*fib[W-j] + dp[i-1][j]*fib[j-1]*fib[W-j] ) %mod
    else:
      dp[i][j] = ( dp[i-1][j-1]*fib[j-2]*fib[W-j] + dp[i-1][j]*fib[j-1]*fib[W-j] + dp[i-1][j+1]*fib[j-1]*fib[W-j-1] ) %mod

print(dp[-1][K])

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

using namespace std;

    template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
    if ((first == last) || (first == k) || (last == k))
        return false;
    Iterator itr1 = first;
    Iterator itr2 = last;
    ++itr1;
    if (last == itr1)
        return false;
    itr1 = last;
    --itr1;
    itr1 = k;
    --itr2;
    while (first != itr1)
    {
        if (*--itr1 < *itr2)
        {
            Iterator j = k;
            while (!(*itr1 < *j)) ++j;
            std::iter_swap(itr1,j);
            ++itr1;
            ++j;
            itr2 = k;
            std::rotate(itr1,j,last);
            while (last != j)
            {
                ++j;
                ++itr2;
            }
            std::rotate(k,itr2,last);
            return true;
        }
    }
    std::rotate(first,k,last);
    return false;
}

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

    vector<vector<double> > v;
    for(int i=0; i< n; i++){
        vector<double> vv(3);
        for(int j=0; j< 3; j++) cin >> vv[j];
        v.push_back(vv);
    }

    vector<int> num(n);
    for(int i=0; i< n; i++) num[i] = i;

    double ret = 0;

    if(m < 2){printf("%.20f\n", ret); return 0;}

    do{
        vector<int> c;
        for(int i=0; i< m; i++) c.push_back(num[i]);
        double sum = 0;
        do{
            sum += pow(v[c[0]][0]-v[c[1]][0], 2) + pow(v[c[0]][1]-v[c[1]][1], 2) + pow(v[c[0]][2]-v[c[1]][2], 2);
        }while(next_combination(c.begin(), c.begin()+2, c.end()));
        ret = max(ret, sum);
    }while(next_combination(num.begin(), num.begin()+m, num.end()));
    printf("%.20f\n", ret);
}

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

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

/* define const */
const long long INF = (1LL << 60);
/* end defineing */

int main()
{
    long long x, y, z, k;
    long long a[1000];
    long long b[1000];
    long long c[1000];
    long long tmp[3000];
    cin >> x >> y >> z >> k;
    for (int i = 0; i < x; i++)
        cin >> a[i];
    for (int i = 0; i < y; i++)
        cin >> b[i];
    for (int i = 0; i < z; i++)
        cin >> c[i];
    for (int i = 0; i < 3000; i++)
        tmp[i] = 99999999999;
    sort(a, a + x, greater<long long>());
    sort(b, b + y, greater<long long>());
    sort(c, c + z, greater<long long>());

    int cnt = 0;
    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            for (int m = 0; m < z; m++)
            {
                if (cnt < k)
                {
                    tmp[cnt++] = a[i] + b[j] + c[m];
                    sort(tmp, tmp + k);
                }
                else
                {
                    if (tmp[0] < a[i] + b[j] + c[m])
                    {
                        tmp[0] = a[i] + b[j] + c[m];
                        sort(tmp, tmp + k);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }
    sort(tmp, tmp + k, greater<long long>());
    for (int i = 0; i < k; i++)
        cout << tmp[i] << endl;
}


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

int main() {
    string s, t;  cin >> s >> t;
    int ans = 100000;
    for (int i = 0; i < s.size() - t.size() + 1; ++i) {
        int cnt = 0;
        for (int j = 0; j < t.size(); ++j) {
            if (s[i + j] != t[j]) ++cnt;
        }
        ans = min(ans, cnt);
        // DUMP(cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define size(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

int x[103];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x[i];
    }
    int ans = 1e9;
    for (int i = 1; i <= 100; i++) {
        int res = 0;
        for (int j = 1; j <= n; j++) {
            res += (x[j] - i) * (x[j] - i);
        }
        ans = min(ans, res);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ins insert
#define sz(x) (long long)x.size()
typedef long long ll;
typedef long double ld;
const int N = 100005;
const ld pi = 3.141592653;
const ll MOD = 1000000007;

using namespace std;

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

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int T = 1;
        //cin>>T;
        while(T--)
        {
                ll n, i, ans=0;
                cin>>n;
                vector<ll> a(n);
                deque<ll> dq;
                for(i=0; i<n; i++) cin>>a[i];
                sort(a.begin(), a.end()); 
                dq.pb(a.back()); a.pop_back();
                //cout<<ans<<" ";
                while(sz(a)!=0)
                {
                        ans=ans + dq.back();
                        dq.pop_back(); dq.push_front(a.back()); dq.push_front(a.back());
                        //cout<<ans<<" ";
                        a.pop_back();
                }
                cout<<ans;
        }
        return 0;
}

Measured memory_bytes: 6332
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

map<char, int> D;
bool isvalid(int x){
    string s = to_string(x);
    int n = s.size();
    for (int i = 0; i < n; i++) {
        if (D[s[i]] != 0) {
            return false;
        }
    }

    return true;
}

void solve(){
    int N, K;
    cin >> N >> K;

    for (int i = 0; i < K; i++) {
        char d;
        cin >> d;
        D[d]++;
    }

    int i = N;
    while (1){
        if (isvalid(i)) {
            cout << i << endl;
            return;
        }
        i++;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
R = []

for _ in range(3):
    L = []
    for i in range(8):
        p, t = input().split()
        p = int(p)
        t = float(t)
        L.append((p,t))
    
    L.sort(key=lambda x: x[1])
    for i in [0, 1]:
        print(*L[i])
    R.extend(L[2:])

R.sort(key=lambda x: x[1])
for i in [0, 1]:
    print(*R[i])



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

int main() {
  string O, E;
  cin >> O >> E;
  string S;
  S = O + E;
  
  if ( O.size() == E.size() ) {
    for (int i = 0; i < O.size() ; i++) {
      S.at(2*i) = O.at(i);
      S.at(2*i+1) = E.at(i);
    }
  }
  else {
    for (int i = 0; i < O.size() ; i++) {
      S.at(2*i) = O.at(i);
    }
    for (int i = 0; i < E.size() ; i++) {
      S.at(2*i+1) = E.at(i);
    }
  }
    
  cout << S << endl;
  
  
}


Measured memory_bytes: 256
#include <stdio.h>

void printChessboard(int h, int w) {
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ((i + j) % 2 == 0) ? printf("#") : printf(".");
        }
        printf("\n");
    }
    printf("\n");
}

int main() {
    int h, w;
    while (1) {
        scanf("%d %d", &h, &w);
        if(h == 0 && w == 0) break;

        printChessboard(h, w);
    }
    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int n,a[505],k,q[505],m[505]; 
V<int> t;
bool check(int p){
	FOR(i,1,n)m[i]=a[i]%p;
	sort(m+1,m+n+1); 
	for(int i=n;i>=1;i--)q[i]=q[i+1]+p-m[i];
	int sum=0;
	FOR(i,0,n){
		sum+=m[i];
		if(sum==q[i+1])break;
	}
	return (sum<=k);
} 
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	cin>>n>>k;
	int sum=0,st;
	FOR(i,1,n)cin>>a[i],sum+=a[i];
	st=sqrt(sum);
	FOR(i,1,st){
		if(sum%i==0){
			t.PB(i);
			if(i*i!=sum)t.PB(sum/i);
		}
	}
	sort(ALL(t),greater<int>());
	for(int i=0;i<t.size();i++){
		if(check(t[i])){
			cout<<t[i];break;
		}
	}
	RE 0;
}




Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)

{
    long long int x, a, ans = 0, r;
    cin>>x;
    if(x >= 500){
        if(x%500 == 0){
            a = x/500;
            ans = a*1000;
        }
        else{
            a = x/500;
            ans = a*1000;
            r = x%500;
            if(r > 5){
                a = r/5;
                ans += (a*5);
            }
        }
    }
    else{
        a = x/5;
        ans += (a*5);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  map<char, int> m;
  for (int i = 0; i < S.size(); i++) {
    m[S[i]]++;
  }
  ll max_v = max({m['a'], m['b'], m['c']});
  ll min_v = min({m['a'], m['b'], m['c']});
  if (max_v - min_v > 1) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  return 0;
}

Measured memory_bytes: 3728
#include<stdio.h>
int main()
{
    int x,y;
    scanf("%d %d",&x,&y);
    if((x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12)&&(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12)){
        printf("Yes\n");
    }
    else if((x==4 || x==6 || x==9 || x==11)&&(y==4 || y==6 || y==9 || y==11)){
        printf("Yes\n");
    }
    else if(x==2 && y==2){
        printf("Yes\n");
    }
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
n,y = (int(i) for i in input().split())
ans = 0
for i in range(n+1):
  for j in range(n+1):
    sen = n-i-j
    if sen >= 0:
     if i*10000+j*5000+sen*1000 ==y:
      ans = 1
      judge = [i,j,sen]
if ans >0 :
  print(*judge)
else:
  print("-1 -1 -1")

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

typedef long long ll;

const int MOD = 1000000007;
ll fact[2010];
 
// a^b % MOD を計算して返す
ll power(ll a, ll b) {
  if (b == 0) {
    return 1;
  } else {
    ll ans = power(a, b / 2); ans = ans * ans; ans = ans % MOD;
    if (b % 2 == 1) ans = ans * a;
    ans = ans % MOD;
    return ans;
  }
}
 
 // nCr % MOD を計算して返す
ll choose(ll n, ll r) {
  ll ans = fact[n];
  ans = fact[n] * power(fact[r], MOD-2); ans = ans % MOD;
  ans = ans * power((fact[n-r] + MOD) % MOD, MOD-2); ans = ans % MOD;
  return ans;
}

int main() {
  ll n, k;
  cin >> n >> k;
  fact[0] = 1;
  for (int i = 0; i < 2005; ++i) {
    fact[i+1] = fact[i]*(i+1)%MOD;
  }
  for (int i = 1; i <= k; ++i) {
    if (i > n-k+1) { cout << 0 << endl; continue; }
    ll ans = choose(n-k+1, i) * choose(k-1, i-1) % MOD;
    cout << ans << endl;
  }
}



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

int main(void){
    char taps[100];
    int i = 0,a,sum = 0;
    
    scanf("%s",taps);
    
    //何文字目までループを回せばいいかaに代入させる
    a = strlen(taps);
    
    //偶数番目にlが出た回数と奇数番目にrが出た時にカウントして合計が０なら踏みやすいタップ
    //taps[0]が1番目に来る
    
    for(i=0;i<=a;i+=2){
        if(taps[i] == 'L'){
            sum ++;
        }    
    }
        
    //taps[１]が2番目に来る
    for(i=1;i<=a;i+=2){
        if(taps[i] == 'R'){
            sum ++;
        }
        
    }
        
    if (sum == 0){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
typedef long long lint;
const int INF = 2e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> T print(T &x) {
    cout << x << '\n';
    return 0;
}
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;
}
int modulo(int a, int b, int n) {
    long long x = 1, y = a;
    while(b > 0) {
        if(b % 2 == 1) {
            x = (x * y) % n; // multiplying with base
        }
        y = (y * y) % n; // squaring the base
        b /= 2;
    }
    return x % n;
}
/* templates */ /* templates */ /* templates */ /* templates */ /* templates */

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

    int N = in(), W = in();
    int w[N + 1], v[N + 1];
    rep(i, 1, N + 1) { cin >> w[i] >> v[i]; }

    lint dp[N + 10][W + 10];
    rep(i, W + 10) { dp[0][i] = 0; }
    rep(i, 1, N + 1) {
        rep(j, 0, W + 1) {
            if(j - w[i] >= 0) {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    print(dp[N][W]);
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

int main(){
  int k,n,o = 0,ans = INF;
  cin >> n >> k;
  int h[n];
  REP(i,n) {
    cin >> h[i];
  }
  sort(h, h+n);
  for (int i = 0;i <= n-k;i++) {
    o = h[i+k-1] - h[i];
    if (o < ans) {
      ans = o;
    }
  }
  cout << ans;
} 

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

template <class _T> inline bool chmax (_T& a,_T b){if(a<b){a=b;return true;}return false;}
template <class _T> inline bool chmin (_T& a,_T b){if(a>b){a=b;return true;}return false;}

const long long INF = 1LL << 60;

bool dp[110][10100] = {false};

int GCD(int a,int b){
	if(b==0) return a;
	return GCD(b,a%b);
}
int main(void){
	int n;cin >> n;
	int ans;
	rep(i,n){
		int a;
		cin >> a;
		if(i == 0) ans = a;
		ans = GCD(a,ans);
	}
	cout << ans << endl;
	return 0; 
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    internal static class CR
    {
        public static string GetText() { return Console.ReadLine(); }
        public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long GetLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
    }

    public class Program
    {
        public static long N { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            N = CR.GetLong();

            var sum = 0L;
            for (long i = 0; i <= N; i++)
            {
                if (i % 3 != 0 && i % 5 != 0)
                {
                    sum += i;
                }
            }

            return sum;
        }
    }
}


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

int main() {
   int n,sum=0,ans=100000; cin>>n;
   vector<int> w(n);
   rep (i,n) {
     cin >> w[i]; sum+=w[i];
   }
   rep(i,n){
     int count=0;
     rep(j,i) count+=w[j];
     int rest=sum-count;
     ans=min(ans,abs(count-rest));
   }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double EPS=1e-10;
double add(double a,double b) {
	if(abs(a+b)<EPS*(abs(a)+abs(b))) return 0;
	return a+b;
}
typedef pair<int,int> PI;
typedef pair<double,PI> E;
struct P {
	double x,y;
	P() {}
	P(double x,double y):x(x),y(y) {}
	P operator+(P p) const{
		return P(add(x,p.x),add(y,p.y));	
	}
	P operator-(const P p) const {
		return P(add(x,-p.x),add(y,-p.y));
	}
	P operator*(double d) const{
		return P(x*d,y*d);	
	}
	double dot(const P p) const{
		return add(x*p.x,y*p.y);
	}
	double det(const P p) const{
		return add(x*p.y,-y*p.x);	
	}
};
bool cmp_x(const P& p,const P& q) {
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}
vector<P> convex_hull(P* ps,int n) {
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> qs(n*2);
	for(int i=0;i<n;i++) {
		while(k>1 && (qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--) {
		while(k>t && (qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}
double dist(P p,P q) {
	return sqrt((p-q).dot(p-q));	
}
int par[100];
int Rank[100];
void init(int n) {
	for(int i=0;i<n;i++) {
		par[i]=i;
		Rank[i]=0;
	}
}
int find(int x) {
	if(par[x]==x) {
		return x;
	}else {
		return par[x]=find(par[x]);	
	}
}
void unite(int x,int y) {
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(Rank[x]<Rank[y]) {
		par[x]=y;	
	}else {
		par[y]=x;
		if(Rank[x]==Rank[y]) Rank[x]++;
	}
}
bool same(int x,int y) {
	return find(x)==find(y);	
}
map<PI,int> idx;
int main() {
	int V,R;
	scanf("%d %d",&V,&R);
	P ps[100],tmp_ps[100];
	for(int i=0;i<V;i++) {
		int x,y;
		scanf("%d %d",&x,&y);
		tmp_ps[i]=ps[i]=P(x,y);
		idx[PI(x,y)]=i;
	}
	vector<P> conv=convex_hull(tmp_ps,V);
	conv.push_back(conv[0]);
	init(V);
	double ans=0;
	for(int i=1;i<conv.size();i++) {
		ans+=dist(conv[i-1],conv[i]);
		unite(idx[PI(conv[i-1].x,conv[i-1].y)],idx[PI(conv[i].x,conv[i].y)]);
	}
	E road[1000];
	for(int i=0;i<R;i++) {
		int s,t;
		scanf("%d %d",&s,&t);s--;t--;
		road[i]=E(dist(ps[s],ps[t]),PI(s,t));
	}
	sort(road,road+R);
	for(int i=0;i<R;i++) {
		double d=road[i].first;
		int s=road[i].second.first;
		int t=road[i].second.second;
		if(same(s,t)) continue;
		unite(s,t);
		ans+=d;
	}
	printf("%.15lf\n",ans);
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    vi sieve(1000010);
    sort(a.begin(), a.end());
    set<ll> skip;
    rep(i,n-1){
        if(a.at(i)==a.at(i+1)) skip.insert(a.at(i));
    }
    ll res = 0;
    rep(i,n){
        if(sieve.at(a.at(i))==1) continue;
        if(skip.count(a.at(i))==0){
            res++;
        };
        ll tmp = a.at(i);
        while(tmp<1000010){
            sieve.at(tmp) = 1;
            tmp+=a.at(i);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 13276
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

int main(){
  ll a,b,c,swap;
  cin >> a >> b >> c;
  swap = a;
  a = b;
  b = swap;
  swap = a;
  a = c;
  c = swap;
  cout << a << ' ' << b << ' ' << c << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    x, k, d = ril()
    a = 2 * d
    b = - x + k * d
    f = lambda i : a * i - b
    if b <= 0:
        ans = -b
    elif a * k < b:
        ans = -f(k)

    elif b % a == 0:
        ans = 0
    else:
        x1 = b // a
        x2 = x1 + 1
        ans = min(-f(x1), f(x2))
    print(ans)

if __name__ == '__main__':
    main()


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

using namespace std;

int main() {

	int A, B, C, K;
	cin >> A >> B >> C >> K;

	vector<int> X;
	if (K > A) {
		K -= A;
		if (K > B) {
			K -= B;
			if (K > C) {
				cout << A - C << endl;
			}
			else {
				cout << A - K << endl;
			}
		}
		else {
			cout << A << endl;
		}
	}
	else {
		cout << K << endl;
	}

	return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    int n; cin >> n;
    ll x = 0, y = 0;
    rep(i, n) {
        ll a, b; cin >> a >> b;
        if (a >= x && b >= y) {
            x = a; y = b;
        } else {
            ll beki = 1;
            if (a < x) {
                beki = max(beki, ceil(x, a));
            }
            if (b < y) {
                beki = max(beki, ceil(y, b));
            }
            //cout << beki << " " << a << " " << b << endl;
            x = beki * a; y = beki * b;
        }
        //cout << x << " " << y << endl;
    }
    cout << x + y << endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n, d[1005], ans;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> d[i];
        for (int j = 1; j < i; j++) ans += d[i] * d[j];
    }
    cout << ans << endl;
    return 0;
}

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

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

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

int f(int x) {
	int res = 0;
	while (x % 2 == 0) {
		x /= 2;
		res++;
	}
	return res;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for (int n = 0; n < N; ++n) {
		int m;
		cin >> m;
		A[n] = m/2;
	}
	int t = f(A[0]);
	for (int n = 0; n < N; ++n) {
		if (t != f(A[n])) {
			cout << 0 << endl;
			return 0;
		}
		A[n] >> t;
	}
	M >> t;
	long long l = 1;
	for (int n = 0; n < N; ++n) {
		l = lcm(l, (long long)A[n]);
		if (l > M) {
			cout << 0 << endl;
			return 0;
		}
	}
	
	cout << ( 1 + M / l)/2 <<endl;
	return 0;
}

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

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

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char *argv[])
{
	int a,b;
	cin >> a >> b;
	cout << (a+b)/2 + (a+b)%2 << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int N, M, V, P;
  cin >> N >> M >> V >> P;
  vi32 A(N);
  cin >> A;
  sort(A.rbegin(), A.rend());
  int ok = -1, ng = N;
  while (ng - ok > 1) {
    int md = (ok + ng) / 2;
    auto a = A;
    i64 rest = (i64) M * V;
    a[md] += M, rest -= M;
    if (a[md] < a[P - 1]) {
      ng = md;
      continue;
    }
    rep(i, P - 1) {
      if (i == md) continue;
      if (rest > 0) {
        a[i] += M, rest -= M;
      }
    }
    repi(i, P - 1, N) {
      if (i == md) continue;
      if (rest > 0) {
        i64 add = max(0, a[md] - a[i]);
        add = min(rest, add);
        add = min(add, (i64) M);
        a[i] += add, rest -= add;
      }
    }
    (rest == 0 ? ok : ng) = md;
  }
  cout << ng << endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] strlist = str.split(" ");
		int h = Integer.parseInt(strlist[0]);
		String[] list = new String[h];

		for(int i=0; i<h; i++){
			list[i] = input.readLine();
			System.out.println(list[i]);
			System.out.println(list[i]);
		}

	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
bool a[300001],b[300001];
int n,p,q,m;
bool check()
{
	for(int i=2;i<n;i++)
	if(a[i] && b[i]) return 1;
	return 0;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&p,&q);
		if(p==1)
			a[q]=1;
		if(q==n)
			b[p]=1;
	}
	puts(check()?"POSSIBLE":"IMPOSSIBLE");
	return 0;
 } 

Measured memory_bytes: 640
import sys
from io import StringIO
import unittest

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def resolve():
    n,m,k=map(int, sys.stdin.readline().strip().split())
    #list(map(int,input().strip().split()))

    uf = UnionFind(n)

    res=[[] for i in range(n)]
    frd=[0 for i in range(n)]
    blk=[0 for i in range(n)]

    for i in range(m):
        #a,b=list(map(int,input().strip().split()))
        a,b=map(int, sys.stdin.readline().strip().split())
        a-=1
        b-=1
        uf.Unite(a,b)
        frd[a]+=1
        frd[b]+=1
    
    for i in range(k):
        #a,b=list(map(int,input().strip().split()))
        a,b=map(int, sys.stdin.readline().strip().split())
        a-=1
        b-=1
        if uf.isSameGroup(a,b):
            blk[a]+=1
            blk[b]+=1
    
    rescnt=[]

    for i in range(n):
        ri=uf.Count(i)-1-blk[i]-frd[i]
        rescnt.append(str(ri))
        ##rescnt.append(str(n-uf.size(i)-len(blk[i])))
    
    print(" ".join(rescnt))

resolve()

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

//int Flag=0;

void find_island(int *cp){
//	int length=cp-c1;

	*cp=0;
	
	if(*(cp+1)==1) find_island(cp+1);
	if(*(cp+52)==1)find_island(cp+52);
	if(*(cp+53)==1)find_island(cp+53);
	if(*(cp-1)==1)find_island(cp-1);
	if(*(cp-51)==1)find_island(cp-51);
	if(*(cp-52)==1)find_island(cp-52);
	if(*(cp-53)==1)find_island(cp-53);
	if(*(cp+51)==1)find_island(cp+51);	
}


int main()
{
	int w,h;

	cin>>w>>h;
	while( w!=0 || h!=0 ){
		int c[52][52]={},island=0;
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin>>c[i][j];
			}
		}

		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(c[i][j]==1){
					island++;
					find_island(&c[i][j]);
				}
			}
		}
		cout<<island<<endl;
		cin>>w>>h;
	}
}

Measured memory_bytes: 1212
package main

import "fmt"

func main() {
    var N, M, countN, countM, ans int
    fmt.Scan(&N, &M)
    
    countN = N * (N-1) / 2
    countM = M * (M-1) / 2
    
    ans = countN + countM
    
    fmt.Println(ans)
    
}

Measured memory_bytes: 512
#include <iostream>
#include <set>
using namespace std;
main() {
  int s; cin>>s;
  set<int> found; found.insert(s);
  int i=2, n=s, fn;
  while(true) {
    if (n%2==0) fn=n/2;
    else        fn=3*n+1;
    if (found.find(fn) != found.end()) {
      cout<<i<<endl; exit(0); }
    found.insert(fn);
    n=fn;
    ++i;
  }
}

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

int main(void)
{
	int a,b,x;
	
	scanf("%d%d%d",&x,&a,&b);
	
	if(a >= b){
		printf("delicious\n");
	}else if( (b-a) <= x){
		printf("safe\n");
	}else{
		printf("dangerous\n");
	}
	
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
int main() {
    int n;
    cin>>n;
    printf("ABC%d\n",n);
	return 0;
}

Measured memory_bytes: 768
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
dp = [0] * (N+1)
mod = 10**9 + 7

for i in range(M):
    dp[a[i]] = -1

if N == 1:
    print(1)
elif N == 2:
    if dp[1] == -1:
        print(1)
    else:
        print(2)
else:
    dp[0] = 1
    if dp[1] != -1 and dp[2] != -1:
        dp[1] = 1
        dp[2] = dp[0] + dp[1]
    elif dp[1] == -1 and dp[2] != -1:
        dp[2] = 1
    elif dp[1] != -1 and dp[2] == -1:
        dp[1] = 1
    else:
        print(0)
        exit()
    
    
    for i in range(3, N+1):
        if dp[i] == -1:
            continue
        elif dp[i-1] == -1 and dp[i-2] != -1:
            dp[i] = dp[i-2]
        elif dp[i-1] != -1 and dp[i-2] == -1:
            dp[i] = dp[i-1]
        elif dp[i-1] != -1 and dp[i-2] != -1:
            dp[i] = dp[i-1] + dp[i-2]
        else:
            print(0)
            exit()
    
    print(dp[N] % mod)

Measured memory_bytes: 460020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> p(n+1);
    rep(i,1,n+1) cin >> p[i];
    int cnt=0;
    rep(i,1,n+1) {
        if (i==p[i]) {
            swap(p[i],p[i+1]);
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define mii map<int,int>
#define MOD 1000000007
#define fr(i,k,n) for(int i=k;i<n;i++)
#define fl(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
typedef long long ll;
int prime[100001]={};
void sieve()
{
	prime[0]=1;
	prime[1]=1;
	for(int i=0;i*i<100001;i++)
	{
		if(prime[i]==0)
		{
			for(int j=i*i;j<100001;j+=i)
			{
				prime[j]=1;
			}
		}
	}
}
ll binpow(ll a,ll b,ll m)
{
	ll res=1;
	while(b>0)
	{

	if(b&1)
	{
		res=res*a%m;
	}
	a=a*a%m;
	b>>=1;
   }
   return res;
}
void solve()
{
	string s;
	cin>>s;
	if(s=="ABC")
	cout<<"ARC"<<endl;
	else
	cout<<"ABC"<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
//cin>>t;
while(t--)
{
solve();
}

return 0;
}




Measured memory_bytes: 3656
# coding: utf-8

# In[1]:

import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


# In[2]:

#import copy
#import numpy as np
try:
    from fractions import gcd
except:
    from math import gcd


# In[ ]:

# 左からn個の最大公約数を求める O(n)
# 右からn個の最大公約数を求める O(n)
# n個目を抜いた最大公約数は n-1個目までの公約数とn+1個目からの公約数との公約数


# In[3]:

lg = [1]*(N)
rg = [1]*(N)
ans = 0


# In[4]:

#print(lg)
#print(rg)
#print(A)


# In[ ]:

lg[0] = A[1]
rg[0] = A[N-2]
lg[1] = A[0]
rg[1] = A[N-1]
#print(lg, rg)
for i in range(1, N-1):
    #print(i)
    lg[i+1] = gcd(lg[i], A[i])
    #print(lg[i], A[i])
    rg[i+1] = gcd(rg[i], A[N-1-i])
    #print(rg[N-1-i], A[N-1-i])
#print(lg, rg)

#ans = [0]*N
ans = [gcd(lg[i], rg[N-1-i]) for i in range(N)]
#for i in range(N):
    #print(i, lg[i], rg[N-i-1])
    #ans = gcd(lg[i], rg[N-i-1])
print(max(ans))


# In[6]:

#print(ans)



Measured memory_bytes: 14076
n = int(input())
xl =  [list(map(int,input().split())) for _ in range(n)]

#始まりと終わりの時間の多次元リストに組み替える
st = [(xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]) for i in range(n)]
#終わりの時間でソート！
st.sort(key=lambda x:x[1])

ans = 0
#最後に選んだ時間の仕事の終了時間
last = - 10**10

for i in range(n):
    if last <= st[i][0]:
        ans += 1
        last = st[i][1]

print(ans)


Measured memory_bytes: 42792
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
vector<pair<ll, ll> > v;
const ll m = 1000000007;

ll pow_mod(ll a, ll n, ll m) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % m;
    a = a * a % m;
    n = n >> 1;
  }
  return res;
}
  
int prime_factorize(ll n) {

  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll ex = 0;
    while (n % i == 0) { ++ex; n /= i; }
    v.push_back( P(i, ex) );
  }
  if (n != 1) v.push_back( P(n, 1) );
  
  return 0;
}

int main() {

  // -------------------------
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N, M;
  cin >> N >> M;

  ll ans = 1;

  prime_factorize(M);
  
  for(int i = 0; i < v.size(); i++) {

    ll n = v[i].second + N - 1;
    ll r = N - 1;

    ll result = 1;
    for (ll i = 0; i < r ; i++) {
      result = (result * (n-i)) % m;
    }
    for (int i = r; i >= 1 ; i--) {
      ll num = pow_mod(i, m-2, m);
      result = (result * num) % m;
    }
    ans *= result;
    ans = ans % m;
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;

int main() {
	int dice[6], x;
	string s;
	for (int i = 0; i < 6; i++) {
		cin >> dice[i];
	}
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		x = dice[0];
		if (s[i] == 'N') {
			dice[0] = dice[1];
			dice[1] = dice[5];
			dice[5] = dice[4];
			dice[4] = x;
		}
		if (s[i] == 'S') {
			dice[0] = dice[4];
			dice[4] = dice[5];
			dice[5] = dice[1];
			dice[1] = x;
		}
		if (s[i] == 'W') {
			dice[0] = dice[2];
			dice[2] = dice[5];
			dice[5] = dice[3];
			dice[3] = x;
		}
		if (s[i] == 'E') {
			dice[0] = dice[3];
			dice[3] = dice[5];
			dice[5] = dice[2];
			dice[2] = x;
		}
	}
	cout << dice[0] << endl;

	return 0;
}

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

public class Main {

public static void main(String [] args){

        int N,M;
        long x,y,z;
        Scanner input = new Scanner(System.in);

        N = input.nextInt();
        M = input.nextInt();
        long[] para01 = new long[N];
        long[] para02 = new long[N];
        long[] para03 = new long[N];
        long[] para04 = new long[N];
        long[] para05 = new long[N];
        long[] para06 = new long[N];
        long[] para07 = new long[N];
        long[] para08 = new long[N];
        long[] ans = new long[8];
        for (int i=0; i<N; i++) {
                x = input.nextLong();
                y = input.nextLong();
                z = input.nextLong();
                para01[i] = x+y+z;
                para02[i] = x+y-z;
                para03[i] = x-y+z;
                para04[i] = -x+y+z;
                para05[i] = x-y-z;
                para06[i] = -x-y+z;
                para07[i] = -x+y-z;
                para08[i] = -x-y-z;
        }

        Arrays.sort(para01);
        Arrays.sort(para02);
        Arrays.sort(para03);
        Arrays.sort(para04);
        Arrays.sort(para05);
        Arrays.sort(para06);
        Arrays.sort(para07);
        Arrays.sort(para08);

        for (int i=0; i< M; i++ ) {
                ans[0] +=para01[N-1-i];
                ans[1] +=para02[N-1-i];
                ans[2] +=para03[N-1-i];
                ans[3] +=para04[N-1-i];
                ans[4] +=para05[N-1-i];
                ans[5] +=para06[N-1-i];
                ans[6] +=para07[N-1-i];
                ans[7] +=para08[N-1-i];
        }

        Arrays.sort(ans);
        System.out.println(ans[7]);
}
}


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

//input
int N, M;
vector<vector<int>> G;

int dp[100010];
int rec(int v){
    if (dp[v] != -1) return dp[v];

    int res = 0;
    for (auto nv : G[v]) {
        res = max(res, rec(nv) + 1);
    }
    
    return dp[v] = res;
}

int main(){
    cin >> N >> M;
    
    G.assign(N, vector<int>());
    for (int i = 0; i < M; ++i){
        int x, y; cin >> x >> y;
        --x; --y;
        G[x].push_back(y);
    }

    for (int v = 0; v < N; ++v) dp[v] = -1;

    int res = 0;
    for (int v = 0; v < N; ++v) res = max(res, rec(v));

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 8192