akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <map>
#include <cstdlib>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-9
#define N 2005
int read()
{
	int x = 0; char ch = getchar();
	for(;ch<'0'||ch>'9';ch = getchar());
	for(;ch>='0'&&ch<='9';ch = getchar()) x = (x<<3)+(x<<1)+(ch^48);
	return x;
}

int now,d[N][N];
int ver[N<<1],ne[N<<1],head[N],tot;
void add(int x,int y)
{
	ver[++tot] = y; ne[tot] = head[x]; head[x] = tot;
	ver[++tot] = x; ne[tot] = head[y]; head[y] = tot;
}

void dfs(int u,int pre,int dis)
{
	for(int i=head[u],v;i;i=ne[i])
	if((v = ver[i]) != pre)
	{
		d[now][v] = d[v][now] = dis;
		dfs(v,u,dis+1);
	}
}
int n,k,sum,ans;
int main()
{
	n = read(); k = read(); ans = inf;
	for(int i=1;i<n;i++) add(read(),read());
	for(int i=1;i<=n;i++)
	{
		now = i;
		dfs(i,0,1);
	}
	if(k&1)
	{
		k/=2; int u,v;
		for(int i=1;i<=tot;i+=2)
		{
			u = ver[i]; v = ver[i+1];
			sum = 0;
			for(int j=1;j<=n;j++)
				if(d[j][u] > k && d[j][v] > k)
					sum++;
			ans = min(ans,sum);
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			sum = 0;
			for(int j=1;j<=n;j++)
				if(j != i && (d[i][j]<<1) > k)
					sum++;
			ans = min(ans,sum);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef vector<ll> V;
typedef pair<ll,ll> P;
typedef map<ll,ll> M;

#define REP(i, n) for(ll (i) = 0; (i) < (n); ++(i))
#define FOR(i, j, n) for(ll (i) = (j); (i) < (n); ++(i))
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; --(i))

signed main(){
    int n,r,t;
    cin >> n >> r >> t;
    V a(n);
    for(auto& xx : a)
        cin >> xx;
    V v(r, 0);
    V minu(r, 0);
    V lazy(r, 0);
    V posvec(n, 0);
    REP(j,t){
        lazy = V(r, 0);
        REP(i,n){
            auto& pos = posvec[i];
            pos += a[i];
            pos %= r;
            if(j)
                lazy[pos]++;
            minu[pos] = min(minu[pos], --v[pos]);
        }
        REP(i,r)v[i] += lazy[i];
    }
    ll ans = 0;
    for(auto& xx : minu)ans -= xx;
    cout << ans << endl;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
int main (){
int n;
cin>>n;
int x,y=0,m=0;
int i;
for(i=0;i<n;i++){
cin>>x;
y+=x;
m=max(x,m);
}
y-=m/2;
cout<<y;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
#define  MAXN 10000000

char a[MAXN];
int  b[MAXN] = { 0 };

int main(void)
{

	int n;
	while (scanf("%d", &n) != EOF)
	{
		int i = 0, j = 0;
		scanf("%s", a);
		int num = 0;
		int min = 100000000;
		for (int m = 0; m < n; m++)
		{
			if (a[m] == 'E')
			{
				b[m] = 1;
			}
		}
		for (int m = 0; m < n - 1; m++)
		{
			b[m + 1] += b[m];
		}

		for (int m = 0; m < n; m++)
		{
			if (a[m] == 'E')
				num = (m - b[m] + (b[n - 1] - b[m]) + 1);
			else
				num = (m - b[m] + (b[n - 1] - b[m]));
			if (min > num)
				min = num;
		}
		printf("%d\n", min);
		memset(b, 0, sizeof(b));
	}

	return 0;
}

Measured memory_bytes: 41088
while True:
    a, b = map(int, input().split())
    if a == b and a == 0:
        break
 
    for i in range(a):
        for j in range(b):
            if (i+j)%2==0:
                print("#", end = "")
            else:
                print(".", end = "")
        print()
    print()


Measured memory_bytes: 7004
#include <iostream>
#include <algorithm>

using namespace std;
int m[1000001]{0};

bool isjump(int num){
    if(m[num] == 0){
        m[num]++;
        return true;
    }
    else
        return false;

}

int main()
{
    int n;
    cin >> n;
    int ans = 1;

    while(isjump(n)){
        if(n % 2 == 0)
            n /= 2;
        else
            n = 3*n+1;

        ans++;
    }

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


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

map<long long int,long long int>m;
map<long long int,long long int>::iterator it,it1;
main()
{
    long long int n,i,j,k,cnt=0,ans=1;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=n-1;i>0;i--)
    {
        if(a[i]==a[i-1])
        {
            cnt++;
            ans*=a[i];
            i--;
        }
        if(cnt==2)
        {
            break;
        }
    }
    if(cnt==2)
    {
        cout<<ans<<endl;
    }
    else{
        cout<<0<<endl;
    }
}


Measured memory_bytes: 4000
n=int(input())
a=list(map(int,input().split()))
import math
s=[0]*(n+1)#累積和法
a.insert(0,0)
for i in range(1,n+1):
    s[i]=s[i-1]+a[i]
from collections import Counter
data=Counter(s)
def combination_cout(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
ans=[]
for i in data.values():
    if 2<=i:
        ans.append(i)
total=0
for i in ans:
    total+=combination_cout(i,2)
print(total)
        

Measured memory_bytes: 41816
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
 
typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 18;
int n, a[1 << N];

struct Pair {
	int a = 0, b = 0;
	void add(int x) {
		if (x > a) {
			b = a;
			a = x;
		}	else if (x > b) {
			b = x;
		}
	}
	void add(const Pair & p) {
		add(p.a);
		add(p.b);
	}
	int get() {
		return a + b;
	}
};

Pair dp[1 << N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 0; i < (1 << n); i++) {
		cin >> a[i];
		dp[i].add(a[i]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < (1 << n); j++) {
			if (j >> i & 1) {
				continue;
			}
			dp[j | (1 << i)].add(dp[j]);
		}
	}
	int cur = 0;
	for (int i = 1; i < (1 << n); i++) {
		cur = max(cur, dp[i].get());
		cout << cur << '\n';
	}
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

int main(){
	int N,K;cin>>N>>K;
  vi h(N);
  rep(i,N)cin>>h[i];
  sort(all(h));
  //DEBUG(h);

  auto itr1 = h.begin();
  auto itr2 = next(itr1, K-1);

  int ans = LIMIT;

  while(itr2!=h.end()){
    //DEBUG(*itr1, *itr2);
    ans = min(ans, *itr2 - *itr1);

    itr1++;
    itr2++;
  }

  cout<<ans<<endl;
}

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

const ll INF = 1LL << 61;

int main(){
	int n;
  	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];

	ll ans = INF;
	for(int a0 : {1,-1,a[0]} ) if(a0 != 0) {
		ll tmp = abs(a0 - a[0]), sum = a0;
		for(int i = 1; i < n; i++){
			sum += a[i];
			if(sum - a[i] > 0){
				if(sum >= 0){
					tmp += sum + 1;
					sum = -1;
				}
			}
			else if(sum - a[i] < 0){
				if(sum <= 0){
					tmp += 1 - sum;
					sum = 1;
				}
			}
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}


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

using namespace std;
 
typedef long long int ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector <string> vs;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pi;

//#define int ll
#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238
#define MOD 1000000007
#define loop(n) for(int i = 0; i < n; i++)
#define rloop(n) for(int i = n-1; i >= 0; i--)

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

int steps_needed(int len, vi &a) {
    int steps=0;
    int n = a.size();
    for(int i=0; i<n; i++) {
      steps += (a[i]+len-1)/len - 1;
    }
    return steps;
}
int32_t main() {
    io();
    int t=1;
    //cin>>t;
    while(t--) {
        int n, k;
        cin>>n>>k;
        vi a(n);
        int maxl = -1;
        loop(n) {
          cin>>a[i];
          if(maxl<a[i])
            maxl = a[i];
        }
        // left will be 0 and right will be maxl
        //binary search on longest length left..start it with maxl/2..and count the steps..
        //if steps>k, then increase the length, if steps<k then decrease length
        int l=1, r=maxl;
        int mid;
        if(k==0) {
          cout<<maxl<<"\n";
          return 0;
        }

        while(l<r) {
          mid = l + (r-l)/2;
          int steps = steps_needed(mid,a);
          if(steps>k)
            l = mid+1;
          else if(steps<=k)
            r = mid;
        }
        cout<<l<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3924
N = int(input())
h = list(map(int,input().split()))

DP = [10**10]*N

DP[0] = 0
DP[1] = min(DP[1],DP[0]+abs(h[1]-h[0]))

for i in range(2,N):
    DP[i] = min(DP[i],DP[i-2]+abs(h[i]-h[i-2]))
    DP[i] = min(DP[i],DP[i-1]+abs(h[i]-h[i-1]))
    
print(DP[-1])

Measured memory_bytes: 20548
import java.io.IOException;
import java.util.Arrays;

public class Main {
	/**
	* @param args
	*/

	static class SH {
		public	int	n;
		public	int	d;
		public	int	b;
		public SH(int n, int d, int b) {
			this.n = n;
			this.d = d;
			this.b = b;
		}
	}

	public	static	SH[]		t = null;
	public	static	double[][]	d = null;
	public	static	int[][][]	p = null;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int		n   = parseNum();
		int[]	tmp = new int[2];
		double	min = Double.MAX_VALUE;
		String	out = "";

		t = new SH[n];
		d = new double[n][1<<n];
		p = new int[n][1<<n][2];

		for (int i = 0; i < n; i++) {
			t[i] = new SH(parseNum(), parseNum(), parseNum());
			Arrays.fill(d[i], Double.MAX_VALUE);
		}

		solve(0, 0, 0, 1);

		for (int i = 0; i < n; i++) {
			if (d[i][1<<i] < min) {
				min    = d[i][1<<i];
				tmp[0] = 1<<i;
				tmp[1] = i;
			}
		}

		while (tmp[0] != -1) {
			if (out.isEmpty()) {
				out += ""+t[tmp[1]].n;
			} else {
				out += " "+t[tmp[1]].n;
			}
			tmp = p[tmp[1]][tmp[0]];
		}

		System.out.println(out);
	}

	private	static double solve(int state, int j, int w, int dp) {
		double min = Double.MAX_VALUE;

		if (state == (1<<t.length)-1) {
			p[j][state] = new int[]{-1, -1};
			return 0.0;
		}

		if (d[j][state] != Double.MAX_VALUE) {
			return d[j][state];
		}

		for (int i = 0; i < t.length; i++) {
			double tmp = (dp == 1)?0.0:Math.abs(t[j].d-t[i].d)/(2000.0/(70+w));
			if ((state&(1<<i))!=0) continue;

			tmp += solve(state+(1<<i), i, w+20*t[i].b, dp+1);
			if(tmp < min){
				if (dp > 1) {
					p[j][state] = new int[]{state+(1<<i), i};
				}
				min = tmp;
			}
		}

		if (dp > 1) d[j][state] = min;
		return min;
	}
	private static int parseNum() {
		try {
			int	buf = 0;
			int	num = 0;
			int	mns = 0;
			int	skp = 1;

			// -,0〜9以外は読み飛ばす
			while (true) {
				buf = System.in.read();
				if (buf == '-') {
					mns = 1;
					skp = 0;
				} else if (buf >= '0' && buf <= '9') {
					num = num * 10 + (buf - '0');
					skp = 0;
				} else if (skp == 0) {
					return (mns == 0)?num:num*(-1);
				}
			}
		} catch (IOException e) {}
		return -1;
	}
}

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

int main(){
    string tap;
    cin >> tap;
    int n = tap.size();
    bool ok = true;
    for(int i = 0; i < n; i+=2){
        if(tap[i] == 'L'){
            ok = false;
            break;
        }
    }

    for(int i = 1; i < n; i+=2){
        if(tap[i] == 'R'){
            ok = false;
            break;
        }
    }
    
    if(ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n,k=map(int,input().split())
if k>(n-1)*(n-2)//2:
  print(-1)
else:
  Chk=[[False]*n for _ in range(n)]
  E=[]
  for i in range(2,n+1):
    E.append([1,i])
    Chk[0][i-1]=True
    Chk[i-1][0]=True
  res=(n-1)*(n-2)//2-k
  
  while res>0:
    for i in range(2,n+1):
      for j in range(i+1,n+1):
        if Chk[i-1][j-1]==False:
          s,g=i,j
          Chk[i-1][j-1]=True
          Chk[j-1][i-1]=True
          break
      else:
        continue
      break
    E.append([s,g])
    res-=1
  print(len(E))
  for s,g in E:
    print(s,g)


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

using namespace std;
using ll = long long;

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

struct Sieve {
  vector<ll> p;

  Sieve(ll n) : p(n + 1, 1) {
    p[1] = 0;
    for (ll i = 2; i <= n; ++i) {
      if (p[i] != 1) continue;
      p[i] = i;
      for (ll j = i * i; j <= n; j += i) {
        if (p[j] == 1) p[j] = i;
      }
    }
  }

  vector<ll> factorList(ll x) {
    vector<ll> f;
    while (p[x] != 0) {
      f.push_back(p[x]);
      x /= p[x];
    }
    return f;
  }

  map<ll, ll> factor(ll x) {
    auto l = factorList(x);
    map<ll, ll> mp;
    for (auto v : l) {
      ++mp[v];
    }

    return mp;
  }

  bool isPrime(ll x) { return p[x] == x; }
};

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

  // int ans = 0;
  // for (int i = 2; (ll)i * i <= n; ++i) {
  //   if (n % i != 0) continue;
  //
  //   int p = i;
  //   while (n % p == 0) {
  //     n /= p;
  //     p *= i;
  //     ++ans;
  //   }
  //
  //   while (n % i == 0) n /= i;
  // }
  //
  // if (n != 1) ++ans;
  // cout << ans << endl;

  auto s = Sieve(sqrt(n) + 1);

  ll ans = 0;
  for (int i = 2; (ll)i * i <= n; ++i) {
    if (!s.isPrime(i)) continue;
    int d = i;
    while (n % d == 0) {
      n /= d;
      d *= i;
      ++ans;
    }

    while (n % i == 0) n /= i;
  }

  if (n != 1) ++ans;
  cout << ans << endl;

  return 0;
}


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

using namespace std;

// 入力
int N, M, Q;
vector<long long> a, b, c, d;

long long dfs(vector<long long> & A) {
	if (A.size() == N) {
		long long sum = 0;
		for (int i = 0; i < Q; i++) {
			if (A[b[i]] - A[a[i]] == c[i]) {
				sum += d[i];
			}
		}
		return sum;
	}

	long long res = 0;
	int prev_last = (A.empty() ? 0 : A.back());
	for (int i = prev_last; i < M; i++) {
		A.push_back(i);
		res = max(res, dfs(A)); // 再帰呼び出ししながらスコア最大値を更新
		A.pop_back();
	}
	return res;
}

int main(void) {
	cin >> N >> M >> Q;
	a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
	for (int q = 0; q < Q; q++) {
		cin >> a[q] >> b[q] >> c[q] >> d[q];
		--a[q]; --b[q]; // 0-indexに変換
	}

	vector<long long> A;
	cout << dfs(A) << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 100000007
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0)
#define ll long long
typedef vector<ll> vl;
typedef map<ll,ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
ll i,j;
int main()
{IOS;
int t;
t=1;
while(t--)
{ string s,t;
cin>>s>>t;
ll c=0;
for(i=0;i<s.size();i++)
{
    if(s[i]!=t[i])c++;
}
cout<<c<<endl;
}
return 0;}



Measured memory_bytes: 3796
#include <iostream>
#include <math.h>

using namespace std;

bool p[1000000];

void primes() {
    for (int i = 0; i < 1000000; i++) {
        p[i] = true;
    }

    p[0] = p[1] = false;

    for (int i = 2; i < sqrt(999999); i++) {
        if (p[i]) {
            for (int j = i * 2; j < 1000000; j += i) {
                p[j] = false;
            }
        }
    }
}

int main() {
    primes();

    int n;
    while (cin >> n) {
        int ans = 0;
        for (int i = 2; i <= n; i++) {
            if (p[i]) {
                ans += 1;
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  int k,s;
  cin>>k>>s;
  int ans=0;
  rep(i,k+1){
    rep(j,k+1){
      int z=s-i-j;
      if(0<=z&&z<=k) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); \
                cin.tie(0); \
                cout.tie(0)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(_v)             _v.begin(), _v.end()
#define sz(_v)              (int) _v.size()
#define first(_obj)         (*_obj.begin())
#define last(_obj)          (*prev(_obj.end()))
#define FIND(_obj, _val)    (_obj.find(_val) != _obj.end())
#define RESET(_a, _v)       fill_n(_a,sizeof(_a)/sizeof(_a[0]),_v)
#define REP(_i, _n)         for (int _i = 0; _i < (int) _n; _i++)
#define FOR(_i, _a, _b)     for (int _i = (int) _a; _i <= (int) _b; _i++)
#define FORD(_i, _a, _b)    for (int _i = (int) _a; _i >= (int) _b; _i--)
#define FORIT(_it, _obj)    for (auto _it = _obj.begin(); _it != _obj.end(); _it++)

// DEBUG UTIL
template<typename TF>
void debug(ostream &out, TF const &f) {
    out << f << std::endl;
}
 
template<typename TF, typename ... TR>
void debug(ostream &out, TF const &f, TR const& ... rest) {
    out << f << " ";
    debug( out, rest... );
}
 
#define DEBUG(...) debug(cerr, "[", #__VA_ARGS__, "]:", __VA_ARGS__)

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<double,double>;
using vi = vector<int>;
using vii = vector<pii>;
using vll = vector<ll>;
using vs = vector<string>;

const int DR[] = {-1, 0, 1, 0, -1, 1, 1, -1}; // ccw
const int DC[] = {0, -1, 0, 1, -1, -1, 1, 1};
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = 1073741823;
const ll INFLL = 4e18;
const int MAX = 100;
const int VMAX = 1e3;

int N, W, SUM, w[MAX+5], v[MAX+5], dp[MAX+5][MAX*VMAX+5];

void read() {
    cin >> N >> W;
    FOR(i, 1, N) {
        cin >> w[i] >> v[i];
        SUM += v[i];
    }
}

void solve() {
    FOR(j, 1, SUM) dp[0][j] = INF;

    FOR(i, 1, N) {
        REP(j, v[i]) dp[i][j] = dp[i - 1][j];
        FOR(j, v[i], SUM) dp[i][j] = min(dp[i - 1][j], w[i] + dp[i - 1][j - v[i]]);
    }

    FORD(j, SUM, 1)
        if (dp[N][j] <= W) {
            cout << j << "\n";
            return;
        }

    cout << "0\n";
}

int main() {
    FAST_IO;
    int TC = 1;
    FOR(tc, 1, TC) {
        read();
        solve();
    }
}

Measured memory_bytes: 41216
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll cnt[100003];

int main()
{
    ll n,sum=0,i,q,a,b;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>a;cnt[a]++;sum+=a;
    }
    cin>>q;
    while(q--)
    {
        cin>>a>>b;
        sum-=(a*cnt[a]);
        sum+=(b*cnt[a]);

        cnt[b]+=cnt[a];cnt[a]=0;
        cout<<sum<<endl;
    }


    return 0;
}



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

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int>S(N);
    vector<int>T(N);
    vector<int>X(N);
    for (int i = 0; i < N; ++i) {
      cin >> S[i] >> T[i] >> X[i];
    }
    vector<int>D(Q);
    for (int i = 0; i < Q; ++i) {
      cin >> D[i];
    }
    
    // S-X, T-X, XをXの降順にソートする
    vector<tuple<int, int, int>> xst(N);
    for (int i = 0; i < N; ++i) {
        xst[i] = make_tuple(X[i], S[i] - X[i], T[i] - X[i]);
    }
    sort(xst.begin(), xst.end(), greater<tuple<int, int, int>>());
    for (int i = 0; i < N; ++i) {
        X[i] = get<0>(xst[i]);
        S[i] = get<1>(xst[i]);
        T[i] = get<2>(xst[i]);
    }


    // 時刻[S_i, T_i)に出発するとiにぶち当たる
    // 複数の工事があるならiの大きい工事が優先される
    // 時刻t以降次に更新されるまでの進む距離(t, x)をpairで持つ
    vector<pair<int, int>> dist;
    dist.reserve(2*N);
    dist.push_back(make_pair(0, -1));

    vector<pair<int, int>> timeline;
    timeline.reserve(2*N);
    for (int i = 0; i < N; ++i) {
        timeline.push_back(make_pair(S[i], i));
        timeline.push_back(make_pair(T[i], -1)); // 同時刻ならこっちが先
    }
    sort(timeline.begin(), timeline.end());

    // 工事中のものを入れるヒープ
    priority_queue<int, vector<int>> que;

    for (int i = 0; i < timeline.size(); ++i) {
        int t = timeline[i].first;
        int k = timeline[i].second;

        if(k == -1 && ! que.empty() && T[que.top()] <= t){
            int flag = 0;
            while (T[que.top()] <= t){
                que.pop();
                if(que.empty()){
                    flag = 1;
                    dist.push_back(make_pair(t, -1));
                    break;
                }
            }
            if(flag == 0){
                dist.push_back(make_pair(t, X[que.top()]));
            }
        } else if(k != -1){
            if(que.empty()){
                que.push(k);
                dist.push_back(make_pair(t, X[k]));
            } else{
                if(que.top() < k){
                    dist.push_back(make_pair(t, X[k]));
                }
                que.push(k);
            }
        }
    }

    vector<ll> ans(Q);
    // tが同じものがいっぱいあるなら最後のものを取る
    for (int i = 0; i < Q; ++i) {
        auto iter = lower_bound(dist.begin(), dist.end(), make_pair(D[i]+1, -1));
        iter--;
        auto p = *iter;
        ans[i] = p.second;
    }

    for (int i = 0; i < Q; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 14976
passes = [[[-1.0, -1.0]], [[-1.0, -1.0]]]
n = gets.to_i
f1, a1, t1, x1, y1 = gets.chomp.split.map(&:to_i)
(n - 1).times{
    f2, a2, t2, x2, y2 = gets.chomp.split.map(&:to_i)
    passes[t2] << [Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2), (f2 - f1) / 60.0] if a2 != a1 && t2 == t1
    f1, a1, t1, x1, y1 = f2, a2, t2, x2, y2
}
0.upto(1){|i|
    passes[i].sort_by!{|a, b| [-a, b]}
    puts "#{passes[i][0][0]} #{passes[i][0][1]}"
}


Measured memory_bytes: 8932
#include<iostream>   //AA06( 10/ 05/ 20)
#include<string>

using namespace std;

int main()
{
    int i, x = 0;

    string S, T;

    cin >> S >> T;

    for(i = 0; i < S.length(); ++i) {

        if(S[i] != T[i])
            x++;
    }


    x > 0? cout << "No" << endl: cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3596
n = input()
a=int(n)%10
if a == 2 or a == 4 or a == 5 or a == 7 or a == 9:
    print("hon")
elif a == 0 or a == 1 or a == 6 or a == 8:
    print("pon")
else:
    print("bon")
    

Measured memory_bytes: 9168
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vint;
typedef vector<uint> vuint;
typedef vector<ull> vull;
typedef vector<ll> vll;

#define init(type,var) type var;cin>>var;
#define vinit(type,var,n) vector<type> var((uint)n);loop(i,0,n)cin>>var[i];
#define linit(type,var,n) list<type> var;loop(i,0,n){type _v;cin>>_v;var.push_back(_v);}
#define range(container) container.begin(),container.end()
#define loop(i,first,end) for(ull i=(first);i<(end);i++)
#define outl(out) cout<<(out)<<endl;

const ull INF = (ull)(-1LL);

typedef ull dint;

typedef vector<dint> vdint;

int main(void){
	init(dint, n);

	dint rn = sqrt(n) + 1;
	dint sum = n + 1;
	loop(i, 1, rn){
		if (n % i == 0){
			dint s = i + (n / i);
			if (s < sum)sum = s;
		}
	}

	outl(sum - 2);

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int b = sc.nextInt();
			if (n == 0 && b == 0)
				break;
			int[] box = new int[n];
			int[] tmp = new int[n];

			for (int i = 0; i < n; i++) {
				box[i] = (n - i);
				// System.out.println(box[i]);
			}
			for (int i = 0; i < b; i++) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				System.arraycopy(box, 0, tmp, 0, x - 1);
				System.arraycopy(box, x - 1, box, 0, y);
				System.arraycopy(tmp, 0, box, y, x - 1);

			}
			System.out.println(box[0]);
		}
	}
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, M; cin >> N >> M;
  vector<ll> H(N); REP(i, N) cin >> H[i];
  vector<long long> A(M), B(M); REP(i, M) cin >> A[i] >> B[i];

  vector<vector<ll>> a(N + 1);

  REP(i, M) {
    if(vector_finder(a[A[i]], B[i]) == 0) {
      a[A[i]].push_back(B[i]);
      a[B[i]].push_back(A[i]);
    }
  }

  vector<ll> ans(N);
  REP(i, N + 1) {
    REP(k, a[i].size()) {
      if(i + 1 > a[i][k]) continue;
      // cout << i << " test " << H[i - 1] << " " << H[a[i][k] - 1] << endl;
      if(H[i - 1] > H[a[i][k] - 1]) {
        // cout << "hi " << H[i - 1] << endl;
        ans[i - 1]++;
        // cout << ans[i - 1] << endl;
      } else if(H[i - 1] < H[a[i][k] - 1]) {
        ans[a[i][k] - 1]++;
      }
    }
  }
/*
  REP(i, N) {
    cout << "toosu " << ans[i] << " " << a[i + 1].size() << endl;
  } */

  ll cnt = 0;
  REP(i, N) {
    if(ans[i] == a[i + 1].size()) cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 12240
using System;

 class Program
 {
     static void Main(string[] args)
     {
         double data0, data1, data2;
         double[] result = new double[3];
         String nyuryoku;
         nyuryoku = Console.ReadLine();
         string[] data = nyuryoku.Split(' ');
         data0 = Double.Parse(data[0]);
         data1 = Double.Parse(data[1]);
         //data2 = Double.Parse(data[2]);
         double result1,result2,result3;
         result2 = data0 % data1;
         result1 = (data0 - result2) / data1;
         result3 = data0 / data1;
         Console.WriteLine(String.Format("{0} {1} {2:F5}",result1,result2,result3));
         

      }
 }



Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std;
char s[15];
int main() {
	scanf("%s", s);
	int n = (int) strlen(s);
	long long ans = 0;
	for (int i = 0; i < (1 << (n - 1)); ++ i) {
		vector<long long> all;
		all.push_back(0);
		for (int j = 0; j < n; ++ j) {
			(all.back() *= 10) += s[j] - '0';
			if (i >> j & 1) all.push_back(0);
		}
		long long res = 0;
		for (long long x : all) res += x;
		ans += res;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    if(S[0] == S[1] && S[1] != S[2] && S[2] == S[3])
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <type_traits>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define all(n) std::begin(n), std::end(n)
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void calc() {

	Int A, P; std::cin >> A >> P;
	std::cout << (A * 3 + P) / 2;

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ss              second
#define ar              array
#define int             long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("ip1.txt", "r", stdin);
  freopen("op1.txt", "w", stdout);
#endif
}

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
  return (a.second < b.second);
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int prime(int n) {
  int flag = 1;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {flag = 0; break;}
  }
  return flag;
}
int power(int x, int y)
{
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
  else
    return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
  return (a * b) / gcd(a, b);
}

int32_t main()
{
  k_007();
  int a;
  cin >> a;
  cout << a + (a * a) + (a * a * a) << endl;
}


Measured memory_bytes: 3676
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
  N,A,B = i_map()
  h = [i_input() for i in range(N)]

  def check(mid,A,B):
    cnt = 0

    for i in h:
      i -= B*mid
      if i <= 0:
        continue
      cnt += math.ceil(i/(A-B))
    if cnt <= mid:
      return True
    else:
      return False

  start = 1
  end = max(h)

  while end - start > 1:
    middle = (end + start)//2
    if check(middle,A,B):
      end = middle
    else:
      start = middle

  print(end)



if __name__=="__main__":
    main()

Measured memory_bytes: 76472
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include <ios>
#include <iomanip>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef tuple<ll,ll,ll> Tl;



int atcoder(){
    //入力
    ll w,h,n;
    cin >> w >> h >> n;
    ll x[110],y[110],a[110];
    ll ans[4]={0,w,0,h};
    REP(i,0,n){
        cin >> x[i] >> y[i] >> a[i];
        if(a[i]==1) chmax(ans[0],x[i]);
        if(a[i]==2) chmin(ans[1],x[i]);
        if(a[i]==3) chmax(ans[2],y[i]);
        if(a[i]==4) chmin(ans[3],y[i]);
    }
    
    if(ans[0]<ans[1] && ans[2]<ans[3]) cout << (ans[1]-ans[0])*(ans[3]-ans[2]) << ENT;
    else cout << 0 << ENT;
    
    return 0;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define Pi 3.1415926535
#define MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int solve(){
    int n,x,y; cin >> n >> x >> y;
    --x, --y;
    vector<vint> d(n,vint(n,0));
    vint ans(n,0);
    
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            d.at(i).at(j) = min(j-i, abs(x-i)+abs(y-j)+1);
        }
    }
    

    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            ans.at(d.at(i).at(j))++;
        }
    }

    repp(i,n-1) cout << ans.at(i) << endl;

    return 0;
}

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


Measured memory_bytes: 16000
#include <iostream>
#include <map>
#include <cstdlib>
#include <string>
#include <queue>
using namespace std;
const int N = 3;
const int N2 = 9;
const int x[4] = {0, 0, 1, -1};
const int y[4] = {-1, 1, 0, 0};
const char ch[4] = {'l', 'r', 'd', 'u'};

class node{
public:
	int f[N2];
	int space;
	string str;
	bool operator< (const node& n) const
	{
		for (int i = 0; i < N2; ++i)
		{
			if (f[i] == n.f[i])
				continue;
			return f[i] < n.f[i];
		}
		return false;
	} 
};

bool Is_Return(const node& n)
{
	for (int i = 0; i < N2; ++i)
	{
		if (n.f[i] != i + 1)
			return false;
	}
	return true;
}

string bfs(node& n)
{
	queue<node> Q;
	map<node, bool> ans;
	Q.push(n);
	ans[n] = true;
	while (!Q.empty())
	{
		node u = Q.front();
		Q.pop();
		if (Is_Return(u))
			return u.str;
		int tx = u.space / N;
		int ty = u.space % N;
		for (int i = 0; i < 4; ++i)
		{
			int sx = tx + x[i];
			int sy = ty + y[i];
			if (sx < 0 || sy < 0 || sx >= N || sy >= N)
				continue;
			node v = u;
			swap(v.f[v.space], v.f[sx * N + sy]);
			v.space = sx * N + sy;
			if (!ans[v])
			{
				ans[v] = true;
				v.str += ch[i];
				Q.push(v);
			}
		}
	}
	return "unsolvable";
}

int main()
{
	node n;
	for (int i = 0; i < N2; ++i)
	{
		cin >> n.f[i];
		if (n.f[i] == 0)
		{
			n.space = i;
			n.f[i] = N2;
		}
	}
	string s = bfs(n);
	cout << s.length() << endl;
	return 0;
}


Measured memory_bytes: 30536
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define prique priority_queue
int h,w,ans=0;
int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
bool b[1100][1100];
char c[1100][1100];
vector<vector<int>>d(1100,vector<int>(1100,INF));
queue<P>que;
signed main(){
    cin>>h>>w;
    rep(i,h){
        rep(j,w){
            cin>>c[i][j];
            if(c[i][j]=='#'){
                b[i][j]=true;
                d[i][j]=0;
                que.push(make_pair(i,j));
            }
        }
    }
    while(!que.empty()){
        P f=que.front();
        que.pop();
        int x=f.first,y=f.second;
        b[x][y]=true;
        rep(i,4){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx>=0&&nx<h&&ny>=0&&ny<w&&b[nx][ny]==false){
                que.push(make_pair(nx,ny));
                b[nx][ny]=true;
                d[nx][ny]=d[x][y]+1;
            }
        }
    }
    rep(i,h){
        rep(j,w){
            ans=max(ans,d[i][j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 28212
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

// 素因数分解。計算量はO(√n)
map<ll, ll> primefactor(ll n) {  // (nのi番目の素因数, その素因数の個数)のmapを返す(n = 720 = (2^4)*(3^2)*(5^1)なら{(2, 4), (3, 2), (5, 1)}のように)
    map<ll, ll> res;
    for(ll i = 2; i*i <= n; i++) {
        while(n%i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) {
        res[n] = 1;
    }
    return res;
}

ll gcd(ll x, ll y) {
    if(y == 0) {
        return x;
    }
    return gcd(y, x%y);
}
 
int main() {
    ll a, b;
    cin >> a >> b;

    ll g = gcd(a, b);

    if(g == 1) {
        out(1);
        re0;
    }

    map<ll, ll> mp = primefactor(g);
    
    out(mp.size() + 1);
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

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

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int main()
{
    int X,A;
    cin >> X >> A;
    if(X<A){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }
}

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

seikai = [False] * (n + 1)
wa_list = [0] * (n + 1)
ac = 0
wa = 0
for i in range(m):
    p, s = input().split()

    if not seikai[int(p)]:
        if s == "WA":
            wa_list[int(p)] += 1
        else:
            ac += 1
            wa += wa_list[int(p)]
            seikai[int(p)] = True
print(ac, wa)

Measured memory_bytes: 4596
n=gets.to_i
a=gets.chomp.split(" ").map(&:to_i) 
b=gets.chomp.split(" ").map(&:to_i) 
c=gets.chomp.split(" ").map(&:to_i) 
re=0
b.each {|i| re+=i}
mae=-10
a.each do |i|
  re+=c[i-2] if i==mae+1
  mae=i
end
puts re
  

Measured memory_bytes: 3836
def levenshtein_distance(a, b):
    m = len(a)
    n = len(b)
    ld = [[m + n for j in range(n + 1)] for i in range(m + 1)]
    for i in range(m + 1):
        ld[i][0] = i
    for j in range(n + 1):
        ld[0][j] = j
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            ld[i][j] = min(ld[i-1][j]+1,
                           ld[i][j-1]+1,
                           ld[i-1][j-1]+(a[i-1] != b[j-1]))
    return ld[m][n]


a = input()
b = input()
print(levenshtein_distance(a, b))



Measured memory_bytes: 46240
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,d,x;
    cin >> n >> d >> x;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    int64_t res = 0;
    rep(i,n){
        rep(j,d){
            if(d < 1+j*a.at(i)) break;
            res++;
        }
    }
    cout << res+x << endl;
}


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

int main(void){

    int K, S;

    scanf("%d%d", &K, &S);

    int ans = 0;

    for(int i = 0; i <= K; i++){
        if(i > S){
            break;
        }
        for(int j = 0; j <= K; j++){
            if(i + j > S){
                break;
            }
            if(S - i - j >= 0 && S - i - j <= K){
                ans++;
            }
        }
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
	int n; cin>>n;
	int cnt=0;
	rep(i,n){
		int x; cin>>x;
		while(x%2==0){
			x/=2; cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int64_t a,b,c;
    cin >> a >> b >> c;
    if(a > c)
      cout << a - c << ' ' << b << endl;
    else if(b > (c-a))
      cout << 0 << ' ' << b - (c -a) << endl;
    else
      cout << 0 << ' ' << 0 << endl;

    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<pair<ll, ll> > a(n);
    for(int i=0;i<n;i++){
        cin >> a[i].first;
        a[i].second = -i;
    }
    sort(be(a));
    vector<vector<ll> > dp(n+1,vector<ll> (n+1,0));
    for (int i=0;i<n;i++)for (int j=0;j<n;j++){
        ll id = -a[i].second;
        dp[i+1][j] = max(dp[i][j]+a[i].first*(i-id+j), dp[i][j+1] + a[i].first*(id-j));
    }
    cout << dp[n][0] << endl;
    return 0;
}


Measured memory_bytes: 34576
import string

def f(s, t):
    ret = 0
    for c in string.ascii_lowercase:
        found_s = False
        found_t = False
        for i in range(len(s)):
            if s[i] == c:
                found_s = True
                break
        for i in range(len(t)):
            if t[i] == c:
                found_t = True
                break
        if found_s and found_t:
            ret += 1
    return ret
    
if __name__ == '__main__':
    n = int(input())
    s = input()

    ans = 0
    for i in range(n + 1):
        #i文字目が壁になる
        #0文字目の手前まで:空文字列
        #n+1文字目の手前まで:全文字列
        tmp = f(s[:i], s[i:]) 
        ans = max(ans, tmp)
    print(ans)

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
#define de_x(x) cout<<"debug_val: "<<x<<endl;
#define de_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
std::mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x ; }
const ll MOD=1e9 +7;
ll ksm(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int _;
/***********************/
//const long mod =1e9+7;
void run(){
}
long power(long a,long b){
	return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}
long Con(int n,int k){
	long x =1,y =1;
	for(int i=1;i<=k;i++){
		 x = x*(n-i+1) %MOD;
		 y = y*i %MOD;
	}
	return  x * ksm(y ,MOD-2)%MOD;
}
int main(){
//	for(scanf("%d",&_); _;_--) run();	
	long n,a,b;
	cin>> n >> a>> b ;
	long ans = ksm(2,n);
	ans -= Con(n,a);
	ans -= Con(n,b);
	ans--;
	cout<<(ans%MOD +MOD)%MOD<<endl;
	return 0;
}

Measured memory_bytes: 256