akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15

//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造

//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  UnionFind(int N) : UF(N) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    UF.at(rx) = ry; // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false; // 1や0,-1は素数ではない
  }
  if (x == 2) {
    return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false; // 割れたら素数じゃない
    }
  }
  return true;
}

//ライブラリ終わり

int main() {
  int N, K, L;
  cin >> N >> K >> L;
  UnionFind C(N), T(N);
  for (int i = 0; i < K; i++) {
    int X, Y;
    cin >> X >> Y;
    C.unite(X - 1, Y - 1);
  }
  for (int i = 0; i < L; i++) {
    int X, Y;
    cin >> X >> Y;
    T.unite(X - 1, Y - 1);
  }
  map<pair<int, int>, int> memo;  
  vector<pair<int, int>> M(N);
  for (int i = 0; i < N; i++) {
    M.at(i) = make_pair(C.root(i), T.root(i));
    memo[M.at(i)]++;
  }
  for (int i = 0; i < N - 1; i++) {
    cout << memo[M.at(i)] << " ";
  }
  cout << memo[M.at(N - 1)] << endl;
}

Measured memory_bytes: 17612
n,k,q=map(int, input().split())

A = []
for i in range(q):
    A.append(int(input()))

score = [k]*n
score = list(map(lambda x:x-q,score) )
for i in A:
     
    score[i-1]+=1

for i in score:
    if i <= 0:
        print('No') 
    else:
        print('Yes')

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

typedef pair<long long, long long> pll;
const long long INF = 1LL<<60;
int N;
vector<long long> A;

void chmax(pll &a, pll b) {
  if (a.first < b.first) a.second = max(a.first, b.second), a.first = b.first;
  else a.second = max(a.second, b.first);
}

int main() {
  cin >> N;
  A.resize(1<<N);
  vector<pll> dp(1<<N);
  for (int bit = 0; bit < (1<<N); ++bit) {
	cin >> A[bit];
	dp[bit] = {A[bit], -INF};
  }
  for (int i = 0; i < N; ++i) {
	for (int bit = 0; bit < (1<<N); ++bit) {
	  if (bit & (1<<i)) {
		chmax(dp[bit], dp[bit^(1<<i)]);
	  }
	}
  }
  long long res = -INF;
  for (int bit = 0; bit < (1<<N); ++bit) {
	long long tmp = dp[bit].first + dp[bit].second;
	res = max(res, tmp);
	if (bit) cout << res << endl;
  }
}		   


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

int main(){
    int ans=-(1e9+1),rt;
    int MIN,MAX=0,minv;
    int n;
    cin >> n;
    int data[n];
    cin >> rt;
    MIN=rt;
    for (int i = 1; i < n; i++){
        MIN=min(MIN,rt);
        cin >> rt;
        ans=max(rt-MIN,ans);
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    return 0;
}



Measured memory_bytes: 3120
def g;$z=gets.split.map &:to_i;end
def f x,y
a=g<<1;b,c,d=y<2?[a.map{1}]*3:f(x,y-1)
[a,(0..x-1).map{|i|a[i]>1?d[i]:a[i]>0?0:c[i]+(b[i-1]<1?c[i-1]:0)+(b[i+1]<1?c[i+1]:0)}<<0,c]end
p f(*$z)[1].inject(:+)while g[0]>0

Measured memory_bytes: 6116
#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;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n;
    cin >> n;
    map<string,int>k;
    rep(i,n){
        string s;
        cin >> s;
        k[s]++;
    }
    cout << k.size() << endl;
    return 0;
}

Measured memory_bytes: 19224
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
long long A,B,K;
cin >> A >> B >> K;
 
if(A>=K){
    cout<<A-K<<' '<<B<<endl;
    
}
else if((A+B)>=K){
cout<<0<<' '<<(A+B)-K<<endl;
}
else{
    cout<<0<<' '<<0<<endl;
}
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
	int x1,x2,x3,x4,y1,y2,y3,y4,henx,heny;

	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	
	henx = x2 - x1;
	heny = y2 - y1;
	y3 = y2 + henx;
	x3 = x2 - heny;
	y4 = y3 - heny;
	x4 = x3 - henx;

	printf("%d %d %d %d\n",x3,y3,x4,y4);
 
	return 0;
}

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

const int maxn = 2e5 + 5;
int h[maxn];
ll dp[maxn];
int n;
ll c;

#define until first
#define opt second
ll cost(int i, int j) { return dp[j] + ll(h[i] - h[j])*(h[i] - h[j]) + c; }
void solve() {
  dp[n] = 0;
  vector<pair<int,int>> v;
  v.emplace_back(n - 1, n);
  int ipos = 0;
  for (int i = n - 1; i >= 1; i--) {
    while (ipos + 1 < v.size() && i <= v[ipos + 1].until) {
      ipos++;
    }
    dp[i] = cost(i, v[ipos].opt);
    while (v.back().until < i && cost(v.back().until, i) <= cost(v.back().until, v.back().opt)) {
      v.pop_back();
    }
    int l = 1, r = min(i - 1, v.back().until);
    while (l <= r) {
      int mid = (l + r)/2;
      if (cost(mid, i) <= cost(mid, v.back().opt)) l = mid + 1;
      else r = mid - 1;
    }
    if (l - 1 >= 1) {
      v.emplace_back(l - 1, i);
    }
  }
}

int main() {
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  solve();
  cout << dp[1] << '\n';
  return 0;
}


Measured memory_bytes: 4724
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const int MAXS = 114514;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    string s;
    cin>>s;
    int a=s[0]-'0';
    int b=s[1]-'0';
    int c=s[2]-'0';
    int d=s[3]-'0'; 
    if(a+b+c+d==7)cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    else if(a-b+c+d==7)cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    else if(a+b-c+d==7)cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    else if(a+b+c-d==7)cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    else if(a-b-c+d==7)cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    else if(a-b+c-d==7)cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    else if(a+b-c-d==7)cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
    else if(a-b-c-d==7)cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
long long pre[100005]={1},a[100005],ans=0;
int n,k;
bool cmp(long long a,long long b)
{
	return a<b;
}
/*快速幂板子*/
long long qmul(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1)res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
/*组合数板子*/
long long C(long long a,long long b)
{
	if(a<=0||b<=0||a<b)return 0;
	long long k1=pre[a]%mod;
	long long k2=qmul(pre[b]%mod,mod-2)%mod;
	long long k3=qmul(pre[a-b]%mod,mod-2)%mod;
	return ((k1*k2)%mod*k3)%mod;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	sort(a,a+n,cmp);
	pre[0]=1;
	for(int i=1;i<=n;i++)pre[i]=pre[i-1]*i%mod;
	for(int i=0;i<n;i++)
	{
		if(n-i-1>=k-1)ans+=(mod-C(n-i-1,k-1))*a[i]%mod;
		if(i>=k-1)ans+=C(i,k-1)%mod*a[i]%mod;
		ans%=mod;
	}
	while(ans<0)ans+=mod;
	printf("%lld\n",ans%mod);
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define REP(n) for(int i = 0; i < n; i++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
template<class X=int>inline X min(X a,X b,X c){return min(min(a,b),c);}
template<class X=int>inline X min(X a,X b,X c,X d){return min(min(a,b,c),d);}
template<class X=int> inline X max(X a,X b,X c){return max(max(a,b),c);}
template<class X=int> inline X max(X a,X b,X c,X d){return max(max(a,b,c),d);}
template<class X=int> inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int> inline X len(X s,X e){return (e-s+1);}
const int MOD = 1e9 + 7;
const ll INF =  1e18;
const bool TESTCASES = 0;
const bool CODEJAM = 0;

void solve() {
	int n, W;
	cin >> n >> W;
	vector<int> w(n), v(n);
	REP(n) cin >> w[i] >> v[i];
	int MAXV = accumulate(all(v), 0);
	vector<vector<long long>> dp(n + 1, vector<ll> (MAXV + 1, INF));
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= MAXV; j++) {
			if(j == 0)
				dp[i][j] = 0;
			else if(i == 0)
				dp[i][j] = INF;
			else if(v[i - 1] <= j)
				dp[i][j] = min(w[i - 1] + dp[i - 1][j - v[i - 1]], dp[i - 1][j]);
			else
				dp[i][j] = dp[i - 1][j];
		}
	}
	for(int i = MAXV; i >= 0; i--) if(dp[n][i] <= W) {
		cout << i << "\n";
		return;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int T = 1;
	if(TESTCASES) cin >> T;
	for(int t = 1; t <= T; t++) {
		if(CODEJAM) cout << "Case #" << t << ": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 83172
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	int n;
	cin >> n;
	cout << n*n*n <<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {   
	static long MOD=(long) (1e9+7);
	public static void main(String[] args) throws IOException 
	{ 
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();

		int[] arr = new int[n];
		for(int i =0; i< n; i++)
			arr[i] = in.nextInt();

		long[][] dp = new long[n][n];

		for(int i =n-1; i>= 0; i--){
           for(int j = i; j<n; j++) {
           	 if(i==j)
           	 	dp[i][j] = arr[i];
           	 else 
           	 	dp[i][j] = Math.max(arr[i]-dp[i+1][j],
           	 		        arr[j]-dp[i][j-1]);
           }
		}

		System.out.println(dp[0][n-1]);
      
	}
}

Measured memory_bytes: 129280
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul  unsigned long long int
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod
//ll divide(ll a, ll b)  //euler's theorem(a/b)%mod
//{
//   return a*power(b,mod-2)%mod;  //only when mod is prime
//}
ll inf=1e18+5;
ll power(ll x, ll y)
{
    ll res = 1;
   while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
int main()
{
    speed;
    int n,w;
    cin>>n>>w;
    vector<int> weight(n),value(n);
    ll sum_value=0;
    for(int i=0;i<n;i++){
    	cin>>weight[i]>>value[i];
    	sum_value+=value[i];
	}
	vector<ll> dp(sum_value+1,inf);  //minimum weight when we have i value
	dp[0]=0;
	for(int item=0;item<n; item++)
	{
		for(ll j=sum_value; j>=value[item];j--)
		{
			dp[j]= min(dp[j], weight[item] + dp[j-value[item]]);
		}
	}
	ll ans=0;
	for(ll i=0;i<=sum_value;i++)
	{
		if(dp[i]<=w)
		ans=max(ans,i);
	}
	cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
#define int long long
using namespace std;
int n,ans;
vector <int> d;
int divide(int x,int kind)
{
	int cnt=0;
	for (int i=1;i*i<=x;i++)
	{
		if (x%i==0)
		{
			if (i!=1) cnt++;
			if (kind==1 && i!=1) d.push_back(i);
			if (x/i!=i)
			{
				if (x/i!=1) cnt++;
				if (kind==1 && x/i!=1) d.push_back(x/i);
			}
		}
	}
	return cnt;
}
signed main()
{
	scanf("%lld",&n);
	ans=divide(n-1,0);
	divide(n,1);
	for (int i=0;i<(int)d.size();i++)
	{
		int x=n;
		while (x%d[i]==0) x/=d[i];
		if (x%d[i]==1) ans++;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define M1 1000000007
#define M2 998244353
#define ll long long int
#define N (int)1e5+3
#define test(t) while(t--)
#define PI acos(-1.0)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repp(i,b,a) for(ll i=b-1;i>=a;i--)
#define clr(ar, val) memset(ar, val, sizeof(ar))
#define F first
#define S second
#define PB push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define V(a) vector<a>
#define M(a,b) map<a,b>
#define endl '\n'
#define all(x) begin(x),end(x)
#define allr(x) rbegin(x),rend(x)
#define pr(a) cout<<a<<endl;
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = { 0, -1, 0, 1 };
const int dy[4] = { -1, 0, 1, 0 };
using namespace std;

ll CalculateMex(set<ll> Set){
    ll Mex = 0;
    while(Set.find(Mex)!=Set.end()){
        Mex++;
    }
    return Mex;
}

ll floor_div(ll a, ll b) {
	return a / b - (((a ^ b) < 0) and a % b);
}
ll ceil_div(ll a, ll b){
    return a / b + (((a ^ b) >= 0) and a % b);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);   
	    freopen("output.txt","w",stdout);
	#endif 
}

void solve()
{
    ll n,k;
    cin>>n>>k;
    ll ans = n%k;
    if (ans*2 < k){
        cout << ans << endl;
    }
    else{
        cout << k - ans << endl;
    }
    
}

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    test(t){
        solve();
    }
    return 0;
}

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    int n;
    string s;
    cin >> n >> s;

    int ans = 0;

    int r = 0;
    while ((r = s.find("ABC", r)) != string::npos)
    {
        ans++;
        r++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,h,m,s;
	scanf("%d",&s);
	a=s%3600; h=(s-a)/3600; s=s-h*3600;
	a=s%60; m=(s-a)/60; s=s-m*60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

int main(){
    int A[3];
    for(int i = 0; i < 3; ++i) cin >> A[i];
    sort(A, A + 3);
    int64_t ans = 0;
    while(A[1] < A[2]){
        ++ans;
        ++A[0], ++A[1];
    }
    int d = A[2] - A[0];
    if(d % 2 == 0){
        cout << ans + d / 2 << endl;
    } else {
        cout << ans + d / 2 + 2 << endl;
    }
}

Measured memory_bytes: 256
s = input()

A_id = -1
Z_id = -1

#一番左のAと一番右のZを抽出する
for i in range(len(s)):
    if s[i]=='A':
        A_id = i
        break

for i in reversed(range(len(s))):
    if s[i]=='Z':
        Z_id = i
        break

print(Z_id - A_id + 1)

Measured memory_bytes: 40048
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int R,C,N;
struct node {
    int to,next;
    int64 val;
}E[MAXN * 10];
int head[MAXN],sumE;
int64 val[MAXN],xmin,ymin;
bool vis[MAXN];
bool used[MAXN];
void add(int u,int v,int64 c) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    E[sumE].val = c;
    head[u] = sumE;
}
bool dfs(int u) {
    vis[u] = 1;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(!vis[v]) {
	    val[v] = E[i].val - val[u];
	    if(!dfs(v)) return false;
	}
	else {
	    if(val[u] + val[v] != E[i].val) return false;
	}
    }
    return true;
}
void find_min(int u) {
    used[u] = 1;
    if(u <= R) xmin = min(xmin,val[u]);
    if(u > R) ymin = min(ymin,val[u]);
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(!used[v]) find_min(v);
    }
}
void Solve() {
    read(R);read(C);read(N);
    int a,b;int64 c;
    for(int i = 1 ; i <= N ; ++i) {
	read(a);read(b);read(c);
	add(a,b + R,c);add(b + R,a,c);
    }
    for(int i = 1 ; i <= R + C ; ++i) {
	if(!vis[i]) {
	    if(!dfs(i)) {puts("No");return;}
	    xmin = 1e18,ymin = 1e18;
	    find_min(i);
	    if(xmin + ymin < 0) {puts("No");return;}
	}
    }
    puts("Yes");
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 9472
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int A[3];
    cin >> A[0] >> A[1] >> A[2];
    sort(A, A+3);
    int num = 0;
    bool rem0 = A[0]%2;
    bool rem1 = A[1]%2;
    bool rem2 = A[2]%2;

    if(rem0 != rem1){
        num++;
        if(rem2){
            if(rem0)
                A[0]++,A[2]++;
            else
                A[1]++,A[2]++;
        }else{
            if(rem0)
                A[1]++,A[2]++;
            else
                A[0]++,A[2]++;
        }
    }else{
        if(rem0 != rem2){
            num++;
            A[0]++;
            A[1]++;
        }
    }

    num += (A[2] - A[0]) / 2;
    num += (A[2] - A[1]) / 2;
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 256
import {stdin} from 'process';
let input = "";
stdin.on('data', x => {input += x});
stdin.on('end', () => {
    let [d, n] = input.split(' ')
        .map(x=>x.trim()).map(x=>parseInt(x));
    if (n === 100) {
        console.log(101 * Math.pow(100, d));
    }
    else {
        console.log(n * Math.pow(100, d));
    }
});

Measured memory_bytes: 11596
n,m=map(int,input().split())
p=[input().split() for _ in range(m)]#よみこみ
q=[0 for _ in range(n)]#間違え数積算
r=[0 for _ in range(n)]#正解出た時点
for a in p:
  e=int(a[0])-1#問題名
  if a[1]=="WA":
    q[e]+=1#間違ってたら一プラス
  else:
    if r[e]==0:
      r[e]=q[e]+1#会ってたら現状の間違え数＋１を追加
c=0
d=0
for b in r:
  if b>0:#あってたら1以上
    c+=1
    d+=b-1
print(c,d)

Measured memory_bytes: 33888
N=int(input())
a = [int(x) for x in input().split()]
a.sort()
a.reverse()
j=0
k=0
for i in range(N):
    if i%2==0:
        j=j+a[i]
    else:
        k=k+a[i]
l=j-k
print(l)

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

void out(){cout << "\n";}
template<class T,class... Args>
void out(const T &x,const Args &... args){
	cout << x << " ";
	out(args...);
}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll k;
	string s;
	vs ans;
	cin >> s >> k;
	ll n=SIZE(s);
	for(ll i=1;i<=min(n,k);i++){
		rep(j,n-i+1){
			string t="";
			rep(k,i) t+=s[j+k];
			ans.pb(t);
		}
	}
	sort(all(ans));
	Eunique(ans);
	cout << ans[k-1] << endl;
	return 0;
}

Measured memory_bytes: 1660
n = int(input())
now=0
t=[0 for i in range(n+1)]  #配列の大きさを指定
x=[0 for i in range(n+1)]
y=[0 for i in range(n+1)]

for i in range(n):
     t[i+1],x[i+1],y[i+1] = map(int,input().split())

for i in range(1,n+1):
    time = int(t[i])-int(t[i-1])
    next2 = int(x[i])+int(y[i])
    if time >= next2-now and (time-(next2-now))%2 == 0:
       now = int(x[i])+int(y[i])
    else:
        print('No')
        exit()
    
print('Yes')

Measured memory_bytes: 11816
#include <stdio.h>
#include <iostream>
#include <string>
#include <set>

int main(void) {
  int i, j, k, n;
  scanf("%d", &n);
  std::set<std::string> se;
  std::string s;
  for(i = 0; i < n; ++i) {
    std::cin >> s;
    if(s[0] == 'i') {
      std::cin >> s;
      se.insert(s);
    } else {
      std::cin >> s;
      if(se.find(s) != se.end()) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}


Measured memory_bytes: 32668
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define OUT(s) cout << s << "\n";
using namespace std;


string S;
// https://atcoder.jp/contests/abc166
void Main()
{
    if (S == "ABC"){
        OUT("ARC");
    } else {
        OUT("ABC");
    }

}

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

Measured memory_bytes: 3640
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define umap unordered_map

const ll MOD = 1e9 + 7;

void madd(ll& a, ll b){
	a += b;
	if (a >= MOD) a -= MOD;
}

void msub(ll& a, ll b){
	a -= b;
	if (a < 0) a += MOD;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	string K; cin >> K;
	int D; cin >> D;
	vi lim = vi();
	for(const auto& c : K){
		lim.pb((int)(c - '0'));
	}
	int n = isize(lim);
	ll dp[n+1][2][D];
	rep(i,n+1)rep(j, 2)rep(k, D) dp[i][j][k] = 0;
	dp[0][1][0] = 1;

	for(int i = 0; i < n; i++){
		for(int tight = 0; tight <= 1; tight++){
			for(int ds = 0; ds < D; ds++){
				int md = tight ? lim[i] : 9;
				for(int d = 0; d <= md; d++){
					int nt = (tight and lim[i] == d) ? 1 : 0;
					int nds = (d + ds) % D;
					madd(dp[i+1][nt][nds], dp[i][tight][ds]);
				}
			}
		}
	}
	ll ans = 0;
	madd(ans, dp[n][0][0]);
	madd(ans, dp[n][1][0]);
	msub(ans, 1);
	cout << ans;	
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  vi cnt(9);
  rep(i, n) {
    int a; std::cin >> a;
    a /= 400;
    chmin(a, 8);
    cnt[a]++;
  }
  int ans = 0;
  rep(i, 8) ans += (cnt[i] > 0);
  std::cout << (ans == 0 && cnt[8] > 0 ? 1 : ans) << " ";
  if (cnt[8] > 0) ans += cnt[8];
  std::cout << ans << "\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

		String S = scanner.next();
		String T = scanner.next();
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		String U = scanner.next();

		if(U.equals(S)){
			a -=1;
		}else{
			b -=1;
		}

		System.out.println(a +" " + b);
	}

}


Measured memory_bytes: 23252
#include <iostream>

using namespace std;

struct set_type{
	int parent;
	int dif_with_parent;
};

set_type find(set_type subsets[], int i){
	if(subsets[i].parent != i){
		set_type parent_set = find(subsets, subsets[i].parent);
		subsets[i].dif_with_parent += parent_set.dif_with_parent;
		subsets[i].parent = parent_set.parent;
	}
	return subsets[i];
}

void unite(set_type subsets[], int x, int y, int dif){
	set_type xroot = find(subsets, x);
	set_type yroot = find(subsets, y);
	int root_dif = subsets[y].dif_with_parent - subsets[x].dif_with_parent + dif; // difference between yroot - xroot
	if(root_dif > 0){
		// yroot will be parent of xroot
		subsets[subsets[x].parent].dif_with_parent = root_dif;
		subsets[subsets[x].parent].parent = subsets[y].parent;
	}else{
		// xroot will be parent of yroot
		subsets[subsets[y].parent].dif_with_parent = -root_dif; 
		subsets[subsets[y].parent].parent = subsets[x].parent;
	}
}

int main(){
	int n, q;
	cin >> n >> q;
	set_type subsets[n];
	for(auto i = 0; i < n; ++i) subsets[i] = {i, 0};
	for(auto i = 0; i < q; ++i){
		int cmd_type;
		cin >> cmd_type;
		if(cmd_type == 0){
			int x, y, dif;
			cin >> x >> y >> dif;
			unite(subsets, x, y, dif);
		}else if(cmd_type == 1){
			int x, y;
			cin >> x >> y;
			find(subsets, x);
			find(subsets, y);
			if(subsets[x].parent != subsets[y].parent){
				cout << "?" << endl;
			}else{
				cout << subsets[x].dif_with_parent - subsets[y].dif_with_parent << endl;
			}
		}
	}
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N, M; cin >> N >> M;
  cout << N-M-1 << endl;

  return 0;
}

Measured memory_bytes: 3152
#!/usr/bin/env python3

def main():
    na = list(map(int, input().split()))
    A, B = na[0], na[1]

    mp = []
    for i in range(41):
        lst = []
        for j in range(41):
            lst.append(0)
        for j in range(41):
            lst.append(1)
        mp.append(lst)

    a = b = 1

    if a < A:
        for n in range(3, 39 + 3, 3):
            for i in range(n):
                if a < A:
                    mp[n - i][41 + i + 1] = 0
                    a += 1
                else:
                    break
            if A <= a:
                break
    if a < A:
        for n in range(36, 0, -3):
            for i in range(n):
                if a < A:
                    mp[39 - i][41 + 39 - n + i + 1] = 0
                    a += 1
                else:
                    break
            if A <= a:
                break
    if b < B:
        for n in range(3, 39 + 3, 3):
            for i in range(n):
                if b < B:
                    mp[n - i][i + 1] = 1
                    b += 1
                else:
                    break
            if B <= b:
                break
    if b < B:
        for n in range(36, 0, -3):
            for i in range(n):
                if b < B:
                    mp[39 - i][39 - n + i + 1] = 1
                    b += 1
                else:
                    break
            if B <= b:
                break


    print('41 82')
    for lst in mp:
        s = ''
        for v in lst:
            s += '#' if v == 1 else '.'
        print(s)

if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;


int main()
{
    int n ;
    cin>>n;
    string s;
    cin>>s;
int open =0,close =0;

for(int index=0;index<n;index++)
{
    if(s[index]=='(')
        open++;
    else
    {
        if(open)open--;
        else
            close++;
    }
}
while(close--)
    cout<<'(';
cout<<s;
while(open--)
    cout<<')';
cout<<endl;
 return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int A, B, C, D;

    cin >> A >> B >> C >> D;

    while (true) {
        C = C - B;
        if (C <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        A = A - D;
        if (A <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }
ll mod = 1e9+7;
signed main() {
    ll n,k,q,a; cin>>n>>k>>q;
    vl b(n,k);
    rep(i,q){
        cin>>a;
        b[a-1]++;
    }
    rep(i,n){
        if(b[i]-q>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
// int LCSubStr(string X, string Y, int m, int n) 
// {
//     int LCSuff[m+1][n+1]; 
//     int result = 0;
//     for (int i=0; i<=m; i++) 
//     { 
//         for (int j=0; j<=n; j++) 
//         { 
//             if (i == 0 || j == 0) 
//                 LCSuff[i][j] = 0; 
  
//             else if (X[i-1] == Y[j-1]) 
//             { 
//                 LCSuff[i][j] = LCSuff[i-1][j-1] + 1; 
//                 result = max(result, LCSuff[i][j]); 
//             } 
//             else LCSuff[i][j] = 0; 
//         } 
//     } 
//     return result; 
// } 
int main()
{
	SPEED
	string s, t;
	cin >> s >> t;

	int m = s.size();
	int n = t.size();

	int ans = INT_MAX;

	if(m<n)
	{
		for (int i = 0; i < n-m+1; ++i)
		{
			int curr = m;
			for (int j = 0; j < m; ++j)
			{
				if(s[j]==t[i+j])
				{
					curr--;
				}
			}
			ans = min(ans, curr);
		}
	}
	else if(m>n)
	{
		for (int i = 0; i < m-n+1; ++i)
		{
			int curr = n;
			for (int j = 0; j < n; ++j)
			{
				if(t[j]==s[j+i])
				{
					curr--;
				}
			}

			ans = min(ans, curr);
		}
	}
	else
	{
		int curr = n;
		for (int i = 0; i < n; ++i)
		{
			if(s[i]==t[i])
			{
				curr--;
			}
		}
		ans = min(ans, curr);
	}


	cout << ans;
	return 0;
}

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


int main(void){
    int n;
    std::cin >> n;

    std::vector<int> h(n);
    for(int i = 0; i < n; i++){
        std::cin >> h.at(i);
    }

    int cnt = 0;

    for(int i = 0; i < n; i++){
        if(i == h.at(i) - 1){
            continue;
        }
        else{
            cnt++;
        }
    }
    
    if(cnt == 0 || cnt == 2){
        puts("YES");
    }
    else{
        puts("NO");
    }
    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  int n, k; cin >> n >> k;
  vi a(n);
  int ma = 0;
  REP(i, n) {
    cin >> a[i];
    chmax(ma, a[i]);
  }

  int g = a[0];
  FOR(i, 1, n) {
    g = __gcd(g, a[i]);
  }

  if(k % g == 0 && k <= ma) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }


}
























Measured memory_bytes: 640
def sol():
    dp=[0]*(w+1)
    for i in l:
        for j in range(w-i[1],0,-1):
            if(dp[j]!=0):
                    dp[j+i[1]]=max(dp[j+i[1]],dp[j]+i[0])
        dp[i[1]]=max(dp[i[1]],i[0])
    print "Case %d:"%cnt
    print max(dp)
    print dp.index(max(dp))
cnt=0
while 1:
    w=int(raw_input())
    cnt+=1
    if w==0:
        break
    n=int(raw_input())
    l=[]
    for i in range(n):
        l.append(map(int,raw_input().split(',')))
    sol()

Measured memory_bytes: 6364
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
   int a,b;
   cin>>a>>b;
   int ans=0;
   int n=1;
   if(b==1){
      cout<<0<<endl;
      return 0;
   }
   while(n<b){
      n+=(a-1);
      ans++;
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
n = gets.to_i
li = []
lil = []
n.times do
  li << gets.chomp.split
end

lil = li.map{|a| a.join(' ')}

li = li.sort { |a,b| (a[0] <=> b[0]).nonzero? || (b[1].to_i <=> a[1].to_i)}
li = li.map{|a| a.join(' ')}

li.each do |v|
  ans = lil.index(v)
  puts ans+1
end


Measured memory_bytes: 1788
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){
  int N, A;
  cin >> N;
  int ans = 0;
  vector<int> vec(N);

  for (int i = 0; i < N; i++){
    cin >> A;
    vec.at(i) = A;
  }

  int status = -1; // -1が同じか切断直後、0が減少、1が増加
  for (int i = 0; i < N-1; i++) {
    if(status == -1){
      if(vec.at(i) < vec.at(i+1)) status = 1;
      if(vec.at(i) > vec.at(i+1)) status = 0;
    }else{
      if(vec.at(i) < vec.at(i+1) && status == 0){ // 減少ステータスのときに増加したらステータスを-1にする
        ans++;
        status = -1;
      }
      if(vec.at(i) > vec.at(i+1) && status == 1){ // 増加ステータスのときに増加したらステータスを-1にする
        ans++;
        status = -1;
      }
    }
  }
  cout << ans+1 << endl;

  return 0;
}

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

using namespace std;

//#define DEBUG

#ifdef DEBUG
#define dump(i) cout << "[*] " #i " : " << i << endl;
#define debug(i) i
#else
#define dump(i)
#define debug(i)
#endif

int main() {
        int n, d, x;
        cin >> n >> d >> x;
        vector<int> a(n);
        dump(n);
        dump(d);
        dump(x);
        for (int i = 0; i < n; ++i) {
                cin >> a[i];
                dump(a[i]);
        }
        int ans = 0;
        for (int i = 0; i < n;++i) {
                int choco = 1;
                int j = a[i] + 1, day = 1;
                while (true) {
                        if (j > d) break;
                        ++choco;
                        ++day;
                        j = day * a[i] + 1;
                }
                ans += choco;

                dump(ans);
                dump(choco);
        }
        cout << ans + x << endl;
        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14
const int MAX_E = 2020;
const int MAX_V = 1010;

struct edge{int from, to, cost;};
edge es[MAX_E];
int d[MAX_V];
int V, E;

bool bellman_ford(int s){
    for(int i = 0; i < V; i++)
        d[i] = INF;
    d[s] = 0;
    int cnt = 0;
    while(true){            
        bool update = false;
        cnt++;              
        for(int i = 0; i < E; i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(cnt == V - 1)
                    return true;
                update = true;
            }
        }
        if(!update)break;
    }
    return false;
}

signed main(){
    cin >> V >> E;
    int r;
    cin >> r;
    int s, t, c;
    rep(i, E){
        cin >> s >> t >> c;
        es[i].from = s;
        es[i].to = t;
        es[i].cost = c;
    }
    if(bellman_ford(r))
        cout << "NEGATIVE CYCLE" << endl;
    else{
        rep(i, V){
            if(d[i] == INF)cout << "INF" << endl;
            else
                cout << d[i] << endl;
        }
    }
}

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

#define ll long long int

const ll INF = 1e18 + 5;

int main() {
    ll n, w, weight, value;
    cin>>n>>w;
    vector<ll> dp(n * 1000 + 1, INF);
    dp[0] = 0;
    while(n--) {
        cin>>weight>>value;
        for(int v = dp.size() - 1 - value; v >= 0; v--)
            dp[v + value] = min(dp[v] + weight, dp[v + value]);
    }
    ll ans = 0;
    for(int i=dp.size() - 1; i>=0 && ans == 0; i--)
        if(dp[i] <= w) ans = i;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

ll n,q;
ll uf[10010],ufrank[10010];

void init(ll n){
	for(ll i=0;i<n;i++){
		uf[i]=i;
		ufrank[i]=0;
	}
}

ll find(ll x){
	if(uf[x]==x){
		return x;
	}
	else{
		return uf[x]=find(uf[x]);
	}
}

void unite(ll x,ll y){
	x=find(x);
	y=find(y);
	if(x==y) return;

	if(ufrank[x]<ufrank[y]) uf[x]=y;
	else{
		uf[y]=x;
		if(ufrank[x]==ufrank[y]) ufrank[x]++;
	}
}

bool same(ll x,ll y){
	return find(x)==find(y);
}

int main(){
	cin>>n>>q;
	ll com,x,y;
	bool ans;
	init(n);
	for(ll i=0;i<q;i++){
		cin>>com>>x>>y;
		if(com==0){
			unite(x,y);
		}
		else{
			ans=same(x,y);
			if(ans) cout<<1<<endl;
			else cout<<0<<endl;
		}
	}
	return 0;
}






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

const int maxn = 1e5;
vector<bool> prime;
vector<int> sumlike2017;

int main() {
  int q;
  cin >> q;
  vector<int> l(q), r(q);
  for (int i = 0; i < q; i++) {
    cin >> l[i] >> r[i];
  }

  prime.resize(maxn + 1, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= maxn + 1; i++) {
    if (!prime[i]) continue;
    for (int j = 2 * i; j < maxn + 1; j += i) {
      prime[j] = false;
    }
  }
  sumlike2017.resize(maxn + 1, 0);
  for (int i = 0; i < maxn; i++) {
    sumlike2017[i + 1] = sumlike2017[i] + (prime[i] && prime[(i + 1) / 2]);
  }

  for (int i = 0; i < q; i++) {
    cout << sumlike2017[r[i] + 1] - sumlike2017[l[i]] << endl;
  }
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n, 0);
  for (int i=1; i<n; i++) {
    cin >> a.at(i);
    b.at(a.at(i)-1)++;
  }
  
  for (int i=0; i<n; i++)
    cout << b.at(i) << endl;
}

Measured memory_bytes: 4840
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

void solve(){
    string s; cin>>s;
    int a = 0, b = 0;
    f(i,s.length()) if(s[i] == '0') a++;
    b = s.length() - a;
    int ans = 2*min(a,b);
    cout<<ans<<endl;
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

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

int main() {
	long long H, W;
	cin >> H >> W;
	if (H == 1 || W == 1) {
		cout << 1 << endl;
		return 0;
	}
	if (H % 2 == 1 && W % 2 == 1) {
		cout << (H * W+1) / 2 << endl;
	}
	else {
		cout <<  H * W /2 << endl;
	}
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        new Main().main();
    }
    
    void main() {
        Scanner sc = new Scanner(System.in);
        
        int[][] a = new int[100][100];
        int i = 0;
        while(sc.hasNext()) {
            String s = sc.nextLine();
            String[] temp = s.split(",");
//            System.out.println(temp.length);
            for(int j=0;j<temp.length;j++) {
//            	System.out.print(temp[j] + " ");
                a[i][j] = Integer.parseInt(temp[j]);
//                System.out.println(a[i][j]);
            }
//            System.out.println();
            i++;
        }
       // System.out.println(i);
        int e = (i/2) + 1;
        int[][] dp = new int[e][e];
        int ind = 0;
        for(int k=0;k<e;k++) {
            for(int j=0;j<e;j++) {
                int min = Math.min(k+j+1, (2*e) - (k+j+1));
                if(k+j < e) {
                    dp[k][j] = a[k+j][min-1-k];
                    ind = min-1-k;
                }else {
                    dp[k][j] = a[k+j][ind];
                }
            }
        }
        
        // for(int k=0;k<e;k++) {
        // 	for(int j=0;j<e;j++) {
        // 		System.out.print(dp[k][j]);
        // 	}
        // 	System.out.println();
        // }
        
        for(int j=1;j<e;j++) {
            dp[0][j] += dp[0][j-1];
        }
        for(int k=1;k<e;k++) {
            dp[k][0] += dp[k-1][0];
        }
        for(int k=1;k<e;k++) {
            for(int j=1;j<e;j++) {
                dp[k][j] += Math.max(dp[k-1][j], dp[k][j-1]);
            }
        }
        System.out.println(dp[e-1][e-1]);
    }

}


Measured memory_bytes: 27860