akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=1e9+7;
#define N 505
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,cnt[N],ans,fac[N],inv[N];
int dp[N][N][N]; // 区间长度到i，区间个数j，区间长度和 k。 
inline int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i){
		fac[i]=1LL*fac[i-1]*i%mod;
	}
	inv[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i){
		inv[i]=1LL*inv[i+1]*(i+1)%mod;
	}
}
inline int C(int n,int m){
	return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;++i){
		++cnt[read()];
	}
	init(m);
	dp[m+1][0][0]=1;
	for(int i=m;i>=1;--i){
		for(int j=0;j<=m;++j){
			for(int k=0;k<=m;++k){
				if(!dp[i+1][j][k])continue;
				for(int p=0;p<=m/i;++p){
					if(j+p>m||k+p*i>m)continue;
					dp[i][j+p][k+p*i]=(dp[i][j+p][k+p*i]+1LL*dp[i+1][j][k]*inv[p])%mod;
				}
			}
		}
		for(int j=0;j<=m;++j){
			for(int k=j*(i-1);k<=m;++k){
				dp[i][j][k]=1LL*dp[i][j][k]*qpow(k-j*(i-1),cnt[i])%mod;
			}
		}
	}
	for(int j=0;j<=m;++j){
		for(int k=0;k<=m;++k){
			ans=(ans+1LL*fac[j]*dp[1][j][k]%mod*C(m-k+1,j)*((m-k)&1?-1:1))%mod;
		}
	}
	printf("%d\n",(ans+mod)%mod);
	return 0;
}



Measured memory_bytes: 14032
#include <iostream>

using namespace std;
long long n, d, sol;

int main()
{
    cin >> n;/// d <= n/d | *d ==> d*d<=n
    for(long long i = 1; i*i <= n; i++){
        if(n%i==0){
            d=i;
        }
    }
    sol = d+n/d-2;
    cout << sol;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <array>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

constexpr int MAX_SIZE = 210;
constexpr int INF = (1 << 29);
constexpr array<int, 4> dx{1, -1, 0, 0};
constexpr array<int, 4> dy{0, 0, 1, -1};

int w, h;
long long field[MAX_SIZE][MAX_SIZE];

inline void replace(const vector<int> &coords, vector<int> &target) {
	for(auto &e : target) {
		e = lower_bound(coords.begin(), coords.end(), e) - coords.begin();
		e *= 2;
	}
}

int compress(vector<int> &a, vector<int> &b) {
	vector<int> coords(a);
	coords.reserve(a.size() + b.size() + 2);
	coords.emplace_back(-INF);
	coords.emplace_back(INF);
	coords.insert(coords.end(), b.begin(), b.end());

	sort(coords.begin(), coords.end());
	coords.erase(unique(coords.begin(), coords.end()), coords.end());

	replace(coords, a);
	replace(coords, b);

	return coords.size() * 2;
}

inline bool out(int x, int y) {
	return x < 0 || y < 0 || x >= w || y >= h;
}

void dfs(int x, int y, long long value) {
	field[y][x] = -1;
	for(int i = 0; i < 4; ++i) {
		const int nx = x + dx[i];
		const int ny = y + dy[i];

		if(out(nx, ny) || field[ny][nx] != value) continue;
		dfs(nx, ny, value);
	}
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	for(int n; cin >> n && n;) {
		vector<int> l(n), t(n), r(n), b(n);
		for(int i = 0; i < n; ++i) {
			cin >> l[i] >> t[i] >> r[i] >> b[i];
		}

		w = compress(l, r);
		h = compress(t, b);

		for(int i = 0; i < n; ++i) {
			--t[i];
			++l[i];
		}

		memset(field, 0, sizeof(field));
		for(int i = 0; i < n; ++i) {
			long long bit = (1ll << i);
			field[t[i]][l[i]] += bit;
			field[t[i]][r[i] + 1] -= bit;
			field[b[i] - 1][l[i]] -= bit;
			field[b[i] - 1][r[i] + 1] += bit;
		}

		for(auto &line : field) {
			partial_sum(begin(line), end(line), begin(line));
		}

		for(int y = h - 1; y > 0; --y) {
			for(int x = 0; x < w; ++x) {
				field[y - 1][x] += field[y][x];
			}
		}

		int ans = 0;
		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w; ++j) {
				if(field[i][j] != -1) {
					dfs(j, i, field[i][j]);
					++ans;
				}
			}
		}
		cout << ans << endl;
	}
	return EXIT_SUCCESS;
}

Measured memory_bytes: 3044
h,w,k=map(int, input().split())
board = [list(input()) for _ in range(h)]
ans=0
for paint_h in range(2**h):
  for paint_w in range(2**w):
    cnt=0
    for i in range(h):
      for j in range(w):
        if (paint_h>>i)&1==0 and (paint_w>>j)&1==0:
          if board[i][j]=='#':
            cnt+=1
    if cnt==k:
      ans += 1
print(ans)


Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, K;
int t[112345], d[112345];
bool selected[112345];

vector<pii> c[112345]; // 各種類ごと
vector<pii> prid; // 代表

int main() {
	cin >> N >> K;
	REP(i, N) scanf("%d %d", t + i, d + i), t[i]--;
	
	REP(i, N) c[t[i]].push_back(pii(d[i], i));
	
	REP(i, 112345) if (!c[i].empty()) {
		prid.push_back(*max_element(ALL(c[i])));
	}
	sort(ALL(prid), greater<pii>());
	
	vector<pii> dat;
	REP(i, N) dat.push_back(pii(d[i], i));
	sort(ALL(dat), greater<pii>());
	
	ll ans = 0, ssum = 0, csum = 0; // s:確定, c:未確定
	int r = K - 1;
	set<int> ss;
	
	REP(i, K) {
		int curidx = dat[i].se;
		csum += d[curidx];
		ss.insert(curidx);
	}
	
	REP(i, K) { // i+1種類選ぶ
		if (i >= prid.size()) break;
		
		int curidx = prid[i].se;
		
		selected[curidx] = true;
		ssum += d[curidx];
		
		if (ss.find(curidx) != ss.end()) {
			csum -= d[curidx];
		}
		else {
			while (r > 0 && selected[dat[r].se]) r--;
			csum -= d[dat[r].se];
			ss.erase(dat[r].se);
			r--;
		}
		
		chmax(ans, (ll)(i + 1) * (i + 1) + ssum + csum);
	}
	
	cout << ans << endl;
	
	return 0;
}

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

int main(){
	ll a[200010];
  ll ans[200010]={0};
  ll n;
  cin>>n;
  for(ll i=2;i<=n;i++){
  	cin>>a[i];
    ans[a[i]]++;
  }
  
  for(ll i=1;i<=n;i++){
  	cout<<ans[i]<<"\n";
  }
}

Measured memory_bytes: 6748
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll dp[100][4][4][4];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    rep(i,0,4){
        rep(j,0,4){
            rep(k,0,4){
                dp[2][i][j][k]=1;
            }
        }
    }
    dp[2][0][2][1]=0;
    dp[2][0][1][2]=0;
    dp[2][2][0][1]=0;
    rep(i,1,N-1){
        rep(j,0,4){
            rep(k,0,4){
                rep(u,0,4){
                    if((j==0||k==0)&&u==2){
                        dp[i+1][k][u][0]+=dp[i][j][k][u];
                        dp[i+1][k][u][0]%=MOD;
                        dp[i+1][k][u][2]+=dp[i][j][k][u];
                        dp[i+1][k][u][2]%=MOD;
                        dp[i+1][k][u][3]+=dp[i][j][k][u];
                        dp[i+1][k][u][3]%=MOD;
                    }
                    else if(k==0&&u==1){
                        dp[i+1][k][u][0]+=dp[i][j][k][u];
                        dp[i+1][k][u][0]%=MOD;
                        dp[i+1][k][u][1]+=dp[i][j][k][u];
                        dp[i+1][k][u][1]%=MOD;
                        dp[i+1][k][u][3]+=dp[i][j][k][u];
                        dp[i+1][k][u][3]%=MOD;
                    }
                    else if(k==2&&(j==0||u==0)){
                        dp[i+1][k][u][0]+=dp[i][j][k][u];
                        dp[i+1][k][u][0]%=MOD;
                        dp[i+1][k][u][2]+=dp[i][j][k][u];
                        dp[i+1][k][u][2]%=MOD;
                        dp[i+1][k][u][3]+=dp[i][j][k][u];
                        dp[i+1][k][u][3]%=MOD;
                    }
                    else{
                        dp[i+1][k][u][0]+=dp[i][j][k][u];
                        dp[i+1][k][u][0]%=MOD;
                        dp[i+1][k][u][1]+=dp[i][j][k][u];
                        dp[i+1][k][u][1]%=MOD;
                        dp[i+1][k][u][2]+=dp[i][j][k][u];
                        dp[i+1][k][u][2]%=MOD;
                        dp[i+1][k][u][3]+=dp[i][j][k][u];
                        dp[i+1][k][u][3]%=MOD;
                    }
                }
            }
        }
    }
    ll ans=0;
    rep(i,0,4){
        rep(j,0,4){
            rep(k,0,4){
                ans+=dp[N-1][i][j][k];
                ans%=MOD;
            }
        }
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 256
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

X,Y,Z = imn()

print(Z,X,Y,sep=' ')

Measured memory_bytes: 5292
S = input()
(A,B,C,D) = map(int,(S[0],S[1],S[2],S[3]))

if A+B+C+D==7:
  print ("{}+{}+{}+{}=7".format(A,B,C,D))
elif A+B+C-D==7:
  print ("{}+{}+{}-{}=7".format(A,B,C,D))
elif A+B-C+D==7:
  print ("{}+{}-{}+{}=7".format(A,B,C,D))
elif A+B-C-D==7:
  print ("{}+{}-{}-{}=7".format(A,B,C,D))
elif A-B+C+D==7:
  print ("{}-{}+{}+{}=7".format(A,B,C,D))
elif A-B+C-D==7:
  print ("{}-{}+{}-{}=7".format(A,B,C,D))
elif A-B-C+D==7:
  print ("{}-{}-{}+{}=7".format(A,B,C,D))
elif A-B-C-D==7:
  print ("{}-{}-{}-{}=7".format(A,B,C,D))


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

using namespace std;

int main()
{
  ll k, a, b;
  ll kk;
  cin >> k >> a >> b;
  kk = k;
  if (b <= a)
  {
    cout << k + 1 << endl;
    return 0;
  }

  if (k < a + 1)
  {
    cout << k + 1 << endl;
    return 0;
  }

  ll result = 1;
  k = k - (a + 1);
  result += b - a;
  result += (b - a) * (k / 2);
  result += a + (k % 2 - 1);

  cout << max(result, kk + 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;



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

	ll N,ans=0,a=0,b=0,ba=0;
	cin >> N;
	string s;
	FOR(i,0,N){
		cin >> s;
		FOR(j,0,s.size()-1){
			if(s[j]=='A'&&s[j+1]=='B')ans++;
		}
		if(s[0]=='B')b++;
		if(s[s.size()-1]=='A')a++;
		if(s[0]=='B'&&s[s.size()-1]=='A')ba++;
	}
	a -= ba;
	b -= ba;
	bool aa = false;
	if(a){
		a--;
		aa = true;
	}
	while(1){
		if(aa){
			if(ba){
				ba--;
				ans++;
			}else if(b){
				b--;
				ans++;
				aa = false;
			}else{
				break;
			}
		}else if(a){
			a--;
			if(ba){
				ba--;
				ans++;
				aa = true;
			}else if(b){
				b--;
				ans++;
				aa = false;
			}else{
				break;
			}
		}else if(ba){
			ba--;
			if(ba){
				ans++;
				ba--;
				aa = true;
			}else if(b){
				b--;
				ans++;
				aa = false;
			}else{
				break;
			}
		}else{
			break;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
const int M=100010;
using ll=long long;

int main(){
	string s;
	int ans=0;
	cin>>s;
	rep(i,s.size()-1){
		if(s[i]!=s[i+1])ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#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 int MAX_N = 100005;
int dp[MAX_N],h[MAX_N];

void init()
{
	rep(i,MAX_N)
	{
		dp[i] = 1e9+5;
	}
}

int main()
{
	init();
	int N,K;
	cin >> N >> K;
	rep(i,N)
	{
		cin >> h[i];
	}
	dp[0] = 0;
	rep(i,N)
	{
		for (int j = 1; j <= K; ++j)
		{
			if (i - j >= 0)
			{
				dp[i] = min(dp[i],dp[i-j] + abs(h[i]-h[i-j]));
			}
		}
	}
	/*
	rep(i,N)
	{
		cout << dp[i] << " ";
	}
	*/
	cout << dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int Q,H,S;long long N;
  long double D;
  cin>>Q>>H>>S>>D>>N;
  vector<long double>K(4);
  K[0]=Q*4;
  K[1]=H*2;
  K[2]=S;K[3]=D/2;
  long double J=D/2;
  sort(K.begin(),K.end());
  if(K[0]==J){
    if(N%2==0){
      cout<<(long long)D*N/2<<endl;
    }
    else{
      cout<<(long long)(D*(N-1)/2+K[1])<<endl;
    }
  }
  else{
    cout<<(long long)K[0]*N<<endl;
  }
}


Measured memory_bytes: 3692
n,m=map(int,input().split())
H=list(map(int,input().split()))
X=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    X[a-1].append(b-1)
    X[b-1].append(a-1)
ans=0
for i in range(n):
    flag=True
    if len(X[i])==0:
        ans+=1
    else:
        for x in X[i]:
            if H[i]<=H[x]:
                flag=False
        if flag:
            ans+=1
print(ans)

Measured memory_bytes: 29356
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<map>
#include<vector>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=200010,MOD=998244353;
struct coor{
	int x,y;
	bool friend operator<(const coor&A,const coor&B)
	{return A.x<B.x;}
}C[maxn];
int N,X[maxn],Y[maxn],pow2[maxn];
map<int,int>mx,my;
struct BIT{
	int b[maxn];
	inline int lowbit(int x)
	{return x&(-x);}
	void upd(int x,int d){
		for(;x<maxn;x+=lowbit(x))
			(b[x]+=d)%=MOD;
	}
	int query(int x){
		int ret=0;
		for(;x;x-=lowbit(x))
			(ret+=b[x])%=MOD;
		return ret;
	}
}bit;
int main(){
	//freopen("in","r",stdin);
	N=read();
	for(int i=1;i<=N;i++)
		X[i]=C[i].x=read(),Y[i]=C[i].y=read();
	sort(X+1,X+1+N);
	sort(Y+1,Y+1+N);
	sort(C+1,C+1+N);
	pow2[0]=1;
	for(int i=1;i<=N;i++)
		mx[X[i]]=i,my[Y[i]]=i,pow2[i]=pow2[i-1]*2%MOD;
	for(int i=1;i<=N;i++)
		C[i].x=mx[C[i].x],C[i].y=my[C[i].y];
	long long ans=0;
	for(int i=1;i<=N;i++){
		int U=C[i].y-1,D=N-C[i].y,L=i-1,R=N-i;
		int UL=bit.query(C[i].y-1),UR=U-UL,DL=i-UL-1,DR=D-DL;
		ans+=pow2[N];
		ans-=1LL*pow2[U]+pow2[D]+pow2[L]+pow2[R]-pow2[UL]-pow2[UR]-pow2[DL]-pow2[DR];
		ans--;
		ans%=MOD;
		bit.upd(C[i].y,1);
	}
	(ans+=MOD)%=MOD;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 23680
#include "bits/stdc++.h"
using namespace std;
#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 ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;   
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;
// cout << << endl;
// cin >> ;

int main(){
    ll a,b,d=0,n,m,ans=0;
    string s,s2;
    cin >> a >> b >> n;
    VI c(100);
    for(int i=1; i<=100;i++){
        if(a%i==0&&b%i==0){
            c[ans]=i;
            ans++;
        }
    }
    cout << c[ans-n] <<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int n = in.nextInt();
            int sum = 0;
            for (int i = 0; i < n; i++) {
                sum += in.nextInt();
            }
            if (sum >= h)
                out.println("Yes");
            else
                out.println("No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 32428
import sys


def is_palindrome(s):
    l1 = list(s)
    l2 = list(s)
    l2.reverse()
    if l1 == l2:
        return True
    else:
        return False


n = 0
for line in sys.stdin:
    s = line.rstrip()
    if is_palindrome(s):
        n += 1
print n

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

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

    int a, odd = 0;
    for (int i = 0; i < n; i++) cin >> a, odd += a % 2;

    cout << (odd ? (long long)pow(2, n - 1) : p ? 0 : (long long)pow(2, n)) << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input().strip())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
total = 0
for a in A:
    total += a
for i in range(N, 0, -1):
    ii = i - 1
    if A[i] > B[ii]:
        A[i] -= B[ii]
        B[ii] = 0
    if B[ii] >= A[i]:
        B[ii] -= A[i]
        A[i] = 0
    if A[ii] > B[ii]:
        A[ii] -= B[ii]
        B[ii] = 0
    if B[ii] >= A[ii]:
        B[ii] -= A[ii]
        A[ii] = 0
newTotal = 0
for a in A:
    newTotal += a
print(total - newTotal)

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_H 410
#define MAX_W MAX_H

class UnionFind {
    public:
        UnionFind(){}
        UnionFind(int size) { Init(size); }
        // size: Union-Find で扱いたい要素の数
        void Init(int size) { m_Data.assign(size, -1); }

        // x と y の属する集合を併合
        // 既に一緒な集合内にいるなら false を
        // 新たに併合されたなら true を返す
        bool Unite(int x, int y) {
            x = Find(x), y = Find(y);
            if(x == y) { return (false); }
            if(m_Data[x] > m_Data[y]) { swap(x, y); }
            m_Data[x] += m_Data[y];
            m_Data[y] = x;
            return (true);
        }

        // 要素 k が属する集合の根を返す
        int Find(int k) {
            if(m_Data[k] < 0) { return (k); }
            return (m_Data[k] = Find(m_Data[k]));
        }

        // 要素 k と同じ集合の要素数を返す
        int Size(int k) { return (-m_Data[Find(k)]); }

    private:
        vector<int> m_Data;
};

int H, W;
vector<string> S;
vector< vector<bool> > isUsed;
UnionFind uf;
ll black[MAX_H * MAX_W] = {};    // グループ i の黒の数
ll white[MAX_H * MAX_W] = {};

static inline int get_id(int i, int j) { return i * W + j; }

// 黒→白→黒とたどりいけるところまで行く
// 辿れた全てを Union-Find で同じグループにする
void dfs(int i, int j, char prev, int root) {
    if(isUsed[i][j] || prev == S[i][j]) { return; }
    isUsed[i][j] = true;
    uf.Unite(get_id(i, j), root);

    if(i > 0) { dfs(i-1, j, S[i][j], root); }
    if(i < H-1) { dfs(i+1, j, S[i][j], root); }
    if(j > 0) { dfs(i, j-1, S[i][j], root); }
    if(j < W-1) { dfs(i, j+1, S[i][j], root); }
}

signed main()
{
    cin >> H >> W;
    S.assign(H, "");
    REP(i, H) { cin >> S[i]; }

    isUsed.assign(H, vector<bool>(W, false));
    uf.Init(H * W);

    REP(i, H) {
        REP(j, W) {
            // 探索し、そのノードのグループを決定
            if(isUsed[i][j]) { continue; }
            dfs(i, j, '?', get_id(i, j));
        }
    }

    // 同じグループの白の数と黒の数を数える
    REP(i, H) {
        REP(j, W) {
            if(S[i][j] == '#') { black[uf.Find(get_id(i, j))]++; }
            else { white[uf.Find(get_id(i, j))]++; }
        }
    }

    ll ans = 0;
    REP(i, H) {
        REP(j, W) {
            ans += black[get_id(i, j)] * white[get_id(i, j)];
        }
    }
    printf("%lld\n", ans);

    return 0;
}


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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    vector<i64> a;
    i64 sum = 0;
    for(i64 i=0;i<n;++i){
        i64 tmp;
        cin >> tmp;
        a.push_back(tmp);
        if(i%2)sum -= tmp;
        else sum += tmp;
    }
    vector<i64> ans({sum});
    for(int i=0;i<n-1;++i){
        ans.push_back(2*a[i] - ans[i]);
    }
    for(int i=0;i<n;++i){
        if(i)cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

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

int main(){
 
  string s;
  cin >> s;
  string S;
  
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '0') {
      S.push_back('0');
    } else if (s.at(i) == '1') {
      S.push_back('1');
    } else if (s.at(i) == 'B' && S.size() != 0) {
      string S2;
      for (int j = 0; j < S.size() - 1; j++) {
        S2.push_back(S.at(j));
      }
      S = S2;
    }
  }
  cout << S << endl;


  
  return 0;
}
    


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] a = new int[n];
    int b = 0;
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      if(a[i] == 1) b = i;
    }
    int t = 0;
    int c_0 = b;
    int c_1 = b;
    for(int i = 0; i < n; i++) {
      if(c_0 <= 0) break;
      c_0 -= (k - 1);
      t++;
      if(c_0 <= 0) break;
    }
    for(int i = 0; i < n; i++) {
      if(c_1 >= n - 1) break;
      c_1 += (k - 1);
      t++;
      if(c_1 >= n - 1) break;
    }
    int ans = (n - 1)/(k - 1) + 1;
    if((n - 1) % (k - 1) == 0) ans = ans - 1;
    System.out.println(ans);
  }
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;



template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int main() {
    int N, K; cin >> N >> K;
    string S;
    cin >> S;
    vector<int> list;
    if(S[0] == '0') list.emplace_back(0);
    char pre = S[0];
    int count = 0;
    rp(i, 0, N) {
        if(pre != S[i]) {
            list.emplace_back(count);
            count = 0;
        }
        count++;
        pre = S[i];
    }
    list.emplace_back(count);
    if(S[N-1] == '0') list.emplace_back(0);
    // rp(i, 0, int(list.size())) {
    //     cout << list.at(i) << endl;
    // }
    int ans = 0;
    int l = list.size();
    if(2 * K >= l-1) {
        ans = N;
    } else {
        int now = 0;
        rp(i, 0, 2 * K + 1) {
            now += list.at(i);
        }
        ans = now;
        int s = 0;
        while(1) {
            now += list.at(2*K+s+1) + list.at(2*K+s+2);
            now -= list.at(s+1) + list.at(s);
            chmax(ans, now); 
            if(s + 2 * K + 2 >= l - 1) break;
            s+=2;
        }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 4076
s = list(input())
t = list(input())
ans = 0
if s == t:
    ans += 1
for i in range(len(s)):
    s.insert(0, s[-1])
    s.pop()
    if s == t:
        ans += 1
        break
if ans == 0:
    print("No")
else:
    print("Yes")

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

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

  ll N; cin >> N;
  ll D; cin >> D;
  D = D * D;

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ll X; cin >> X;
    ll Y; cin >> Y;
    if (X * X + Y * Y <= D) ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN = 10000 + 5;
const int MAXQ = 500 + 5;
int main(int argc, char const *argv[])
{
	int n,q;
	int S[MAXN];
	int T[MAXQ];
	int ans=0;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		scanf("%d",&S[i]);
	}
	cin>>q;
	for (int i = 0; i < q; ++i)
	{
		scanf("%d",&T[i]);
		S[n] = T[i];
		int j = 0;
		while(S[j]!=T[i])
		{
			j++;
		}
		if(j != n) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define EPS (1e-10)
#define equal(x,y)  (fabs(x-y)<EPS)
enum Status{
	COUNTER_CLOCKWISE=1,CLOCKWISE=-1,ONLINE_BACK=2,ONLINE_FRONT=-2,ON_SEGMENT=0
};
struct Point{
	double x,y;
	Point(double _x=0,double _y=0): x(_x),y(_y){ }
	Point operator+(const Point & p){
		return Point(x+p.x,y+p.y);
	}
	Point operator-(const Point & p){
		return Point(x-p.x,y-p.y);
	}
	Point operator*(double k){
		return Point(k*x,k*y);
	}
};
typedef Point Vector;
struct Segment{
	Point p1,p2;
	Segment(){	}
	Segment(Point _p1,Point _p2):p1(_p1),p2(_p2){}
};
typedef Segment Line;
double dot(const Vector &v1,const Vector & v2 ){	//内积 
	return v1.x*v2.x+v1.y*v2.y;
}
double cross(const Vector &v1,const Vector & v2){	//外积 
	return v1.x*v2.y-v1.y*v2.x;
}
double norm(const Vector & v){						//范数 
	return dot(v,v);
}
double abs(const Vector & v){						//模长 
	return sqrt(norm(v));
}
Point project(Segment s,Point p){					//点在直线上的投影坐标 
	Vector base=s.p2-s.p1,v=p-s.p1;
	double len = dot(base,v)*(1.0/norm(base));
	return s.p1+base*len;
}
Point reflect(Segment s,Point p){					//点关于直线的轴对称点 
	Point proj=project(s,p);
	return proj*2.0-p;
}
int ccw( Point p1, Point p2,  Point p3){			//判断三点的相对位置 
	Vector v1=p2-p1,v2=p3-p1;
	if(cross(v1,v2)<-EPS) return CLOCKWISE;
	if(cross(v1,v2)>EPS) return COUNTER_CLOCKWISE;
	if(dot(v1,v2)<-EPS) return ONLINE_BACK;
	if(norm(v1)<norm(v2)) return ONLINE_FRONT;
	return ON_SEGMENT;
}
bool intersect(Point p1,Point p2,Point p3,Point p4){//线段相交 
	return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
				ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}
bool intersect(Segment s1,Segment s2){
	return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}
double distanceLP(Line l,Point p){					//点到直线的距离 
	Vector v1=l.p2-l.p1,v2=p-l.p1;
	return fabs(cross(v1,v2))/abs(v1);
}
double distanceSP(Segment s,Point p){				//点到线段的距离
	if(dot(p-s.p2,s.p1-s.p2)>EPS&& dot(p-s.p1,s.p2-s.p1)>EPS) 
		return distanceLP(s,p);	
	double len1=abs(s.p1-p),len2=abs(s.p2-p);
	return min(len1,len2);
}
double distanceSS(Segment s1,Segment s2){			//两线段间距离
	if(intersect(s1,s2)) return 0.0;
	double len[]={distanceSP(s1,s2.p1),distanceSP(s1,s2.p2),
					distanceSP(s2,s1.p1),distanceSP(s2,s1.p2)};
	double minlen=len[0];
	for(int i=1;i<4;i++)
		if(minlen>len[i]) minlen=len[i];
	return minlen;
}
int main(){
	double x[4],y[4];
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>x[0]>>y[0]>>x[1]>>y[1];
		cin>>x[2]>>y[2]>>x[3]>>y[3];
		printf("%.10f\n", distanceSS(Segment(Point(x[0],y[0]),Point(x[1],y[1])),Segment(Point(x[2],y[2]),Point (x[3],y[3])) ) );
	}
	return 0;
}


Measured memory_bytes: 3296
a, b, m = map(int, input().split())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))

wk = -1
for i in range(m):
    x, y, c = map(int, input().split())
    if wk == -1:
        wk = li_a[x - 1] + li_b[y - 1] - c
    else:
        wk = min(wk,li_a[x - 1] + li_b[y - 1] - c)
answer = min(wk,min(li_a) + min(li_b))
print(answer)


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,x;cin >> n >> x;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	sort(a.begin(),a.end());
	int ans=0;
	rep(i,n){
		if(i==n-1){
			if(a.at(i)==x) ans++;
			break;
		}
		if(a.at(i)<=x){
			ans++;
			x-=a.at(i);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
#include <cstring>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

#define int long long

std::string str;
int n, k;

const int ms = 303;
const int MOD = 998244353;

std::vector<int> groups;
int memo[ms][ms][ms][2];

int dp(int on, int ones, int cost, int t) {
	if(cost < 0) return 0;
	if(n == on) {
		return ones == 0 ? 1 : 0;
	}
	int &ans = memo[on][ones][cost][t];
	if(ans != -1) return ans;
	ans = 0;
	if(t == 0) {
		// can use some from future here
		ans = dp(on, ones, cost, 1);
		// or use some from here to back
		for(int i = 1; i <= groups[on] && i <= ones; i++) {
			ans = (ans + dp(on+1, ones - i, cost, 0)) % MOD;
		}
	} else {
		ans = (dp(on, ones+1, cost-1, 1) + dp(on+1, ones, cost, 0)) % MOD;
	}
	//std::cout << "on (" << on << ", " << ones << ", " << cost << ", " << t << ") got " << ans << '\n';
	return ans;
}

main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	std::cin >> str >> k;
	while((int) str.size() > 0 && str[0] == '1') {
		str = str.substr(1, (int) str.size() - 1);
	}
	//std::cout << "string reduced to " << str << " of size " << str.size() << '\n';
	n = (int) str.size();
	k = std::min(k, ms-1);
	for(int l = 0, r = 0; l < n; l = r) {
		assert(str[l] == '0');
		l++;
		r++;
		if(r == n || str[r] == '0') {
			groups.push_back(0);
			continue;
		}
		while(r < n && str[l] == str[r]) r++;
		assert(l < r);
		groups.push_back(r - l);
	}
	n = (int) groups.size();
	memset(memo, -1, sizeof memo);
	int ans = 0;
	for(int i = 0; i <= k; i++) {
		ans = (ans + dp(0, i, k-i, 0)) % MOD;
	}
	std::cout << ans << '\n';
}

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

using namespace std;

const int maxn = 2e5 + 7;

struct Que{
	int l,r;
	bool operator < (const Que& a)const{
		return (l == a.l) ? (r < a.r) : (l < a.l);
	}
}q[maxn];
int Min[maxn << 2];
int tag[maxn << 2];
int a[maxn];
int sum;
int n,Q;
int Read(char c = 0,int re = 0){
	while(!isdigit(c = getchar()));
	re = c - '0';
	while(isdigit(c = getchar()))
		re = ((re << 2) + re << 1) + c - '0';
	return re;
}
#define MID() int mid = l + r >> 1
void Pushdown(int u){
	int add = tag[u];tag[u] = 0;
	Min[u << 1] += add;
	Min[u << 1 | 1] += add;
	tag[u << 1] += add;
	tag[u << 1 | 1] += add;
}
void Update(int u,int l,int r,int L,int R,int v){
	if(l >= L && r <= R){
		Min[u] += v;
		tag[u] += v;
		return;
	}
	MID();
	if(tag[u])Pushdown(u);
	if(L <= mid)Update(u << 1,l,mid,L,R,v);
	if(R >  mid)Update(u << 1 | 1,mid + 1,r,L,R,v);
	Min[u] = min(Min[u << 1],Min[u << 1 | 1]);
}
void Modify(int u,int l,int r,int x,int v){
	if(l == r)return Min[u] = min(Min[u],v),void();
	MID();
	if(x <= mid)Modify(u << 1,l,mid,x,v);
	else Modify(u << 1 | 1,mid + 1,r,x,v);
	Min[u] = min(Min[u << 1],Min[u << 1 | 1]);
}
int Query(int u,int l,int r,int L,int R){
	if(l >= L && r <= R)return Min[u];
	if(tag[u])Pushdown(u);
	MID();
	int re = 0x3f3f3f3f;
	if(L <= mid)re = min(re,Query(u << 1,l,mid,L,R));
	if(R >  mid)re = min(re,Query(u << 1 | 1,mid + 1,r,L,R));
	return re;
}
int main(){
	n = Read();
	memset(Min,0x3f,sizeof Min);
	Modify(1,0,n,0,0);
	for(int i = 1; i <= n; ++i)
		a[i] = Read(),sum += (a[i] == 0);
	Q = Read();
	for(int i = 1; i <= Q; ++i)
		q[i].l = Read(),q[i].r = Read();
	sort(q + 1,q + Q + 1);
	int cur = 1;
	for(int i = 1; i <= n; ++i){
		while(q[cur].l == i){
			int tmp = Query(1,0,n,0,q[cur].r - 1);
			Modify(1,0,n,q[cur].r,tmp);
			cur++;
		}
		Update(1,0,n,0,i - 1,(a[i] == 1) ? 1 : -1);
	}
	printf("%d\n",Query(1,0,n,0,n) + sum);
	return 0;
}


Measured memory_bytes: 8832
/*
 It's better to sleep happy and tired rather than disappointed and frustrated
 There's only 1 thing that's impossible and that is defeating a man who doesn't give up
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

const int inf=0x3f3f3f3f;
int n, k;
ll ans, arr[2*mx5];
string str;
 
int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		cin >> n >> k;
		for(int i = 1; i <= n ; i++) {
			arr[i] = arr[i-1]+i;
			// cout << arr[i] << " ";
		}
		for(int i = k; i <= n+1; i++) {
			// cout << ans << " ";
			ans = (ans%mod + (((arr[n]-arr[n-i+1]+(n-i+1))%mod - (arr[i-1])%mod)%mod + mod)%mod +1)%mod;
		}
		cout << ans;
	}
	return 0;
}


Measured memory_bytes: 5160
#include<stdio.h>
#include<iostream>
#include<cstdlib>
using namespace std;

int N;
int main (){
    cin >> N;
    string s = "";
    if( N == 0 ) {
        cout << 0 << endl;
        return 0;
    }
    while( N != 0){
        if( abs(N) % 2 ){
            N--;
            s = "1" + s;
        } else {
            s = "0" + s;
        }
        N /= -2;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
intt gcd(intt a, intt b) {return b ? gcd(b, a % b) : a;}
intt lcm(intt a, intt b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = ((res%mod) * (a%mod))%mod;
      a = ((a%mod) * (a%mod))%mod;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("inn.txt","r",stdin);
  freopen("o.txt","w",stdout);
  #endif
}
///////////U L R D
int dx[4]={0,-1,1,0};
int dy[4]={1,0,0,-1};

template <typename T1, typename T2>
struct less_second {
    typedef pair<T1, T2> type;
    bool operator ()(type const& a, type const& b) const {
        return a.second > b.second;
    }
};


intt solve(vector<vector<intt>> v,intt wt)
{
  intt n=v.size();
  vector<intt> dp(wt+1,-1);
  
  for(int i=0;i<n;i++)
  {
      for(int j=wt;j>=v[i][0];j--)
      {
        dp[j]=max(dp[j],v[i][1]+dp[j-v[i][0]]);
      }
  }
  return dp[wt]+1;
}

int main()
{
  go();
  fast_io
  intt n,wt;cin>>n>>wt;
  vector<vector<intt>> v(n,vector<intt>(2));
  
  for0(i,n)
  {
    for0(j,2)
    {
      cin>>v[i][j];
    }
  }
  cout << solve(v,wt) <<"\n";

}

























Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n,k;
    int tmp;
    vector <int> l;
    cin >> n >> k;
    FOR(i,0,n){
        cin >> tmp;
        l.push_back(tmp);
    }
    sort(l.begin(),l.end());
    int sum=0;
    FOR(i,0,k){
        sum+= l[n-1-i];
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  int a, b, c;cin>>a>>b>>c;
  if(a>b)swap(a, b);
  if(a>c)swap(a, c);
  if(b>c)swap(b, c);
  cout<<(a+b==c?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = sc.nextInt();
    int answer = 0;

    for(int i = 0; i<N; i++){
      //以下をN回繰り返す
      int a =sc.nextInt();
      while(a%2 == 0){
        //「aが偶数」が真である間
        a /= 2;
        //aにa/2を代入して
        answer++;
        //answerを1増やす
      }
    }
    System.out.println(answer);
  }
}


Measured memory_bytes: 33960
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    vector<int> cnt(3, 0), upper(3);
    vector<string> s(3);
    for (int i = 0; i < 3; i++){
        cin >> s[i];
        upper[i] = s[i].size();
    }
    int cur = 0;
    while (true) {
        if (cnt[cur] == upper[cur]) { printf("%c\n",'A' + cur); return 0; }
        cur = s[cur][cnt[cur]++] - 'a';
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define ll          long long
#define pii         pair<ll, ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll, ll>
#define mii         map<pii, ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define lb          lower_bound
#define ub          upper_bound

#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)
 
#define track(x)                 cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
 
#define ed(i)       i.end()
#define mem(a)	    memset(a, 0, sizeof(a))

#define MOD         1000000007
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a + b + p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int b) {a = max(a, b); }
void self_min(int &a, int b) {a = min(a, b); }
void self_add(int &a, int b, int p = MOD) { a += b; if(a >= p) a -= p;}
void self_sub(int &a, int b, int p = MOD) { a -= b; if(a < 0) a += p;}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
const int INF = 1e9 + 5;
#define N	    	400001

void solve(){
    ll n, m;
    cin>>n>>m;
    vector<pair<ll, ll> > v;
    rep(i, 0, n) {
        int a, b;
        cin>>a>>b;
        v.pb(mp(a, b));
    }
    sort(all(v));
    ll amount = 0;
    rep(i, 0, n) {
        ll curr = min((ll)v[i].y, (ll)m);
        amount += v[i].x * curr;
        m = m - curr;
    }
    cout<<amount<<endl;
}
int main() {
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 2420
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#define maxn 1010
#define INF 0x3f3f3f3f
#define LL long long
#define ULL unsigned long long
#define E 1e-8
#define mod 1000000007
#define P pair<int,int>
using namespace std;
//n个  长度是L
int main()
{
    int n,l;
    while(cin>>n>>l)
    {
        string s[105];
        int a[105];
        for(int i = 0 ; i < n ; i++ )
        {
            cin>>s[i];
            a[i] = (int)s[i][0];
            //cout<<a[i]<<endl;
        }
        sort(s+0,s+n);
        for(int j = 0 ; j < n ; j++ )
        cout<<s[j];
        }
}

Measured memory_bytes: 256
import copy
while 1:
    t,n=map(int,input().split())
    if t==n==0:break
    field=[[0 for i in range(2*t+1)] for j in range(2*t+1)]
    stone=[]
    for i in range(n):stone.append(list(map(int,input().split())))
    x,y=map(int,input().split())
    for xi,yi in stone:
        if 0<=t+xi-x<=2*t and 0<=t+yi-y<=2*t:field[t+xi-x][t+yi-y]=-1
    field[t][t]=1
    for k in range(t):
        field_c=copy.deepcopy(field)
        for i in range(2*t+1):
            for j in range(2*t+1):
                if field[i][j]>0:
                    field_c[i+1][j+1]=-1 if field_c[i+1][j+1]==-1 else 1
                    field_c[i+1][j]=-1 if field_c[i+1][j]==-1 else 1
                    field_c[i][j+1]=-1 if field_c[i][j+1]==-1 else 1
                    field_c[i-1][j-1]=-1 if field_c[i-1][j-1]==-1 else 1
                    field_c[i-1][j]=-1 if field_c[i-1][j]==-1 else 1
                    field_c[i][j-1]=-1 if field_c[i][j-1]==-1 else 1
        field=field_c
    ct=[flatten for inner in field for flatten in inner]
    print(ct.count(1))


Measured memory_bytes: 6524
#include<cstdio>
using namespace std;

int n,d,x,a,ans;

int main()
{
	scanf("%d%d%d",&n,&d,&x);
	ans=x;
	for(register int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		ans+=(d-1)/a+1;
	}
	printf("%d",ans);
	return 0;
}

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

using namespace std;

int lg, lgmax;
string s;

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> s;
  if (s[0] == 'R')
    lg = 1;
  for (int i = 1; i < (int)s.size(); ++i) if (s[i] == 'R') {
    if (s[i - 1] == 'R')
      ++lg;
    else {
      lgmax = max (lgmax, lg);
      lg = 1;
    }
  }
  lgmax = max (lgmax, lg);
  cout << lgmax;
}


Measured memory_bytes: 3648
import Data.List ( sortBy )
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInt :: IO Int
readInt = fst . fromJust . C.readInt <$> C.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  _ <- getLine
  as <- readInts 
  print . point . alisAndBob . sort' $ as

sort' 
  :: Ord a => [a] -> [a]
sort' = sortBy (flip compare)

alisAndBob 
  :: Ord a => [a] -> ([a],[a])
alisAndBob ns = helper ns ([],[])
  where
    helper :: Ord a => [a] -> ([a],[a]) -> ([a],[a])
    helper [] ab = ab
    helper [a] ab@(as,bs) = (a:as, bs)
    helper (a:b:cs) ab@(as,bs) = helper cs (a:as, b:bs)

point
  :: ([Int],[Int]) -> Int
point (as,bs) = sum as - sum bs

Measured memory_bytes: 508
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {

	ll K, S,an=0;
	cin >> K >> S;

	for (ll x = 0; x <= K; x++) {
		for (ll y = 0; y <= K;y++) {
			if (S - x - y >= 0 && K >= S - x - y) {
				an++;
			}
		}
	}
	cout << an << endl;
}


Measured memory_bytes: 256