akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			int l = cin.Int();
			long[] a = cin.ArrayLong(n);

			int index = -1;
			for (int i = 0; i < n - 1; i++) {
				if (a[i] + a[i + 1] >= l) {
					index = i;
					break;
				}
			}

			if (index == -1) {
				Console.WriteLine("Impossible");
				return;
			}

			var sb = new StringBuilder();
			for (int i = 0; i < index; i++) {
				sb.AppendLine((i + 1).ToString());
			}

			for (int i = n - 2; i > index; i--) {
				sb.AppendLine((i + 1).ToString());
			}

			sb.AppendLine((index + 1).ToString());
			Console.WriteLine("Possible");
			Console.WriteLine(sb.ToString());
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 32988
#include<bits/stdc++.h>
#define N 200005
using namespace std;
const int p = 1000000007;
int jie[N],ni[N];
int c(int n,int m)
{
    return 1LL*jie[n]*ni[m]%p*ni[n-m]%p;
}
int main()
{
    jie[0]=ni[0]=ni[1]=1;
    for(int i=1;i<=200000;i++)jie[i]=1LL*jie[i-1]*i%p;
    for(int i=2;i<=200000;i++)ni[i]=1LL*ni[p%i]*(p-p/i)%p;
    for(int i=2;i<=200000;i++)ni[i]=1LL*ni[i-1]*ni[i]%p;
    int H,W,A,B;
    cin>>H>>W>>A>>B;
    int ans=0;
    for(int i=1;i<=H-A;i++)
    {
        ans+=1LL*c(i-1+B-1,i-1)*c(H-i+W-B-1,H-i)%p;
        ans%=p;
    }
    cout<<ans<<endl;
    return 0;
}


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

bool compare(pair<int, int> a, pair<int, int> b){
  if(a.first!=b.first) return a.first>b.first;
  else a.second>b.second;
}

int main() {
  int N, ans=0; cin >> N;
  vector<pair<int,int>> blue(N), red(N);
  for (int i=0; i<N; i++) {
    cin >> red[i].first >> red[i].second;
  }
  for (int i=0; i<N; i++) {
    cin >> blue[i].first >> blue[i].second;
  }
  sort(red.begin(), red.end(), compare);
  sort(blue.begin(), blue.end(), compare);
  for (int i=0; i<N; i++) {
    int maxy=200, idx;
    for (int j=0; j<N; j++) {
      if(blue[j].first>red[i].first&&blue[j].second>red[i].second&&blue[j].second<maxy){
        maxy=blue[j].second;
        idx=j;
      }        
    } 
    if(maxy!=200) {
      ans++;
      blue[idx].second=-1;
    }
  }
  cout << ans << "\n";
  return 0;
} 

Measured memory_bytes: 256
# http://abc051.contest.atcoder.jp/tasks/abc051_b
K,N=map(int,raw_input().split())
count=0
for i in range(K+1):
	for j in range(K+1):
		# print i,j,(N-(i+j))
		if 0<=(N-(i+j))<=K:
			count+=1
print count

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

int up(const void *a ,const void *b){
  return *(int *)a - *(int *)b;
}

int main(void){
  int n , k;
  scanf("%d %d",&n,&k);

  int p[n];
  for(int i = 0;i < n;i ++){
    scanf("%d",&p[i]);
  }

  qsort(p,n,sizeof(int),up);


  int ans = 0;
  for(int i = 0;i < k;i ++){
    ans += p[i];
  }

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

  return 0;

}

Measured memory_bytes: 1708
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n, k;
    cin >> n >> k;
    
    vector<int> h(n);

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

    sort(h.begin(), h.end());

    int s = 1000000000;
    for (int i=0; i<n-k+1; i++) {
        s = min(s, h[i+k-1]-h[i]);
    }

    cout << s << endl;
    return 0;
}

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

int main() {
  int N;
  scanf("%d", &N);
  int minus = (N-1)/2;
  long long a[N],ans[N];
  long long sumrain = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &a[i]);
    sumrain += a[i];
  }

  ans[0] = sumrain;
  for (int i = 1; i <= minus; ++i) {
    int ref = (i*2-1)%N;
    ans[0] -= 2*a[ref];
  }

  for (int i = 1; i <= N-1; ++i){
    ans[i] = a[i-1]*2 - ans[i-1];
  }

  for (int i = 0; i < N; ++i) cout << ans[i] << endl;


}



Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b,c,d,xko=0,yko=0;
	cin >> n >> a >> b >> c >> d;
	if(n%a!=0){
		xko=n/a+1;
	}else{
		xko=n/a;
	}
	if(n%c!=0){
		yko=n/c+1;
	}else{
		yko=n/c;
	}
	if(b*xko<d*yko){
		cout << b*xko << endl;
	}else{
		cout << d*yko << endl;
	}
} 
	


Measured memory_bytes: 3120
use proconio::input;

fn main() {
    input! {
        h: usize,
        a: usize,
    }

    solve(h, a);
}

fn solve(h: usize, a: usize) {
    match h % a {
        0 => println!("{}", h / a),
        _ => println!("{}", h / a + 1),
    }
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string c;
    cin >> c;
    if (c == "a" || c == "e" || c == "i" || c == "o" || c == "u" ){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define fi first
#define se second
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
 
template<class T> bool uin(T &a, T b) {return (a < b ? false : (a = b, true));}
template<class T> bool uax(T &a, T b) {return (a > b ? false : (a = b, true));}
 
//~ ifstream f(".in");
//~ ofstream g(".out");
 
const int NMAX = 16;
const ll INF = 1e18L;

int n;
int a[NMAX][NMAX];
ll score[(1 << NMAX)];
ll dp[(1 << NMAX)];
 
void getScoreOfAllGroups() {
  for (int mask = 0; mask < (1 << n); ++mask) {
    dp[mask] = -INF;
    for (int i = 0; i < n; ++i) {
      if ((mask & (1 << i)) == 0) {
        continue;
      }
      for (int j = i + 1; j < n; ++j) {
        if ((mask & (1 << j)) != 0) {
          score[mask] += a[i][j];
        }
      }
    }
  }
}
 
void solve(vector<int> &rabbits, int curr, int pos, int mask) {
  uax(dp[(mask ^ curr)], dp[mask] + score[curr]);
  assert((mask & curr) == 0);
  if (pos == (int)rabbits.size()) {
    return;
  }
  solve(rabbits, curr, pos + 1, mask);
  solve(rabbits, (curr ^ (1 << rabbits[pos])), pos + 1, mask);
}
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEFINE
  freopen(".in", "r", stdin);
#endif
 
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }
  
  getScoreOfAllGroups();
  dp[0] = 0;
  for (int mask = 0; mask < (1 << n); ++mask) {
    vector<int> rabbits;
    for (int i = 0; i < n; ++i) {
      if ((mask & (1 << i)) == 0) {
        rabbits.push_back(i);
      }
    }
    solve(rabbits, 0, 0, mask);
  }
  
  cout << dp[(1 << n) - 1] << '\n';
 
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

llong n, k;
llong res = 1;
vector<vector<int> > G;

void dfs(int v, int pre, int cand) {
  res = res * cand % MOD;
  cand = k - 1 - (pre != -1);
  rep(i, (int)G[v].size()) {
    if (G[v][i] != pre) {
      dfs(G[v][i], v, cand);
      --cand;
    }
  }
}

int main (int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  G.resize(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(0, -1, k);

  cout << res << endl;

  return 0;
}

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

int ans[105][105];

int main()
{
    int n, m, nn;
    scanf("%d%d%d", &n, &m, &nn);
    int tmpx = 1, tmpy = 1;
    for(int i = 1;i <= nn;i++)
    {
        int x;
        cin >> x;
        while(x--)
        {
            if(tmpx&1)
            {
                if(tmpy <= m)
                    ans[tmpx][tmpy] = i, tmpy++;
                else
                    tmpy--, tmpx++, x++;
            }
            else
            {
                if(tmpy >= 1)
                    ans[tmpx][tmpy] = i, tmpy--;
                else
                    tmpy++, tmpx++, x++;
            }
        }
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(j == 1)
                printf("%d", ans[i][j]);
            else
                printf(" %d", ans[i][j]);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<limits.h>
int main(void)
{
	int h,w,r[25][25],x,min=INT_MAX,i,j,k,l;
	scanf("%d %d", &h, &w);
	for(i=0; i<h; i++)
	{
		for(j=0; j<w; j++)
		scanf("%d", &r[i][j]);
	}
	for(i=0; i<h; i++)
	{
		for(j=0; j<w; j++)
		{
			x=0;
			for(k=0; k<h; k++)
			{
				for(l=0; l<w; l++)
				{
					if(abs(i-k)<abs(j-l))
					x+=abs(i-k)*r[k][l];
					else
					x+=abs(j-l)*r[k][l];
				}
			}
			if(min>x)
			min=x;
		}
	}
	printf("%d\n", min);
	
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  string s;
  cin>>s;
  long long int firstA=2000000;
  long long int endZ=0;
  for(long long int i=0; i<s.size();i++){
    if(s[i]=='A'){
      firstA=min(i,firstA);
    }
    if(s[i]=='Z'){
      endZ=max(endZ,i);
    }
  }
  cout<<endZ-firstA +1<<endl;
}

Measured memory_bytes: 640
import sys
stdin = sys.stdin 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

def Solve():
    N,K=na()
    S=input()
    l=[]
    N=len(S)
    #print(len(S))
    if(S[0]=="0"):
        #print("00")
        l.append(0)
    t=S[0]
    ct=1
    #print("aa")
    #print(S)
    #print(S[0],S[1],S[2])
    for b in S[1:]:
        #print(b)
        if(t!=b):
            l.append(ct)
            ct=1
            t=b
        else:
            ct+=1
    #print("bb")
    l.append(ct)
    len_l=len(l)
    if(len_l//2 <= K):
        return sum(l)
    ans = res = sum(l[:2*K+1])
    
    if(len_l%2==0):
        l.append(0)
        len_l+=1
    g = K * 2 + 1
    for i in range(K*2+1,len_l-1,2):
        ans -= l[i-g] + l[i-g+1]
        ans += l[i] + l[1+i]
        if(res<ans):
            res=ans
    #print(S)
    #print(l)
    #print(len_l)
    return res

print(Solve())

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

int main(){
  int n,m,a[11111];
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    int total = 0;
    for(int i=0;i<n;i++){
      cin >> a[i];
      total += a[i];
    }
    sort(a,a+n,greater<int>() );
    for(int i=m-1;i<n;i+=m) total -= a[i];
    cout << total << endl;
  }
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+2;
map<int,int>cnt;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
	int now=0;
	ll ans=0,p=1;
	cnt[0]=1;
	for(int i=s.size()-1;i>=0;i--){ 
		now=(now+(s[i]-'0')*p)%2019;
		ans+=cnt[now];
		cnt[now]++;
		p=p*10%2019;
	}
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3740
h = {}
min = 0
max = 1

STDIN.gets.to_i.times do
  q = STDIN.gets.split
  case q[0]
  when '0' then
    if q[1] == '0'
      h[min] = q[2]
      min -= 1
    else
      h[max] = q[2]
      max += 1
    end
  when '1' then
    idx = q[1].to_i + min + 1
    puts h[idx]
  when '2' then
    if q[1] == '0'
      h.delete(min + 1)
      min += 1
    else
      h.delete(max - 1)
      max -= 1
    end
  end
end



Measured memory_bytes: 46620
#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,k;
    cin >> n >> k;
    vector<int>x(n);
    rep(i,n){
        cin >> x[i];
    }
    ll ans = 0;
    rep(i,n){
        ans+=min(x[i],k-x[i]);
    }
    ans*=2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fr(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

const int mod=(int)1e9+7;
int n,c,s,t;
ll C[2002][2002];
int m,in[2002];
vector<vi> e;

bool v[2002];
void rec(int c){
	v[c]=1;
	rep(i,e[c].size())if(!v[e[c][i]])rec(e[c][i]);
}
bool hasloop(){
	rep(i,n)if(in[i]==0&&!v[i])rec(i);
	rep(i,n)if(!v[i])return 1;
	return 0;
}

int cld[2002];
int reccld(int c){
	if(cld[c]>=0)return cld[c];
	cld[c]=1;
	rep(i,e[c].size())cld[c]+=reccld(e[c][i]);
	return cld[c];
}
ll T[2002];
ll recT(int c){
	ll &res=T[c];
	if(res>=0)return res;
	res=1;
	int n=cld[c]-1;
	rep(i,e[c].size()){
		res=res*recT(e[c][i])%mod;
		res=res*C[n][cld[e[c][i]]]%mod;
		n-=cld[e[c][i]];
	}
	return res;
}
ll dp[2002][2002],sum[2002][2002];

int main(){
	rep(i,2002)rep(j,i+1)C[i][j]=i==0||i==j?1ll:(C[i-1][j-1]+C[i-1][j])%mod;
	
	cin>>n>>c>>s>>t;
	e.resize(++n);
	rep(i,c){
		int a,b; cin>>a>>b;
		e[b].pb(a);
		in[a]++;
	}
	if(hasloop()){
		cout<<0<<endl; return 0;
	}
	for(int i=1;i<n;i++)if(in[i]==0)e[0].pb(i);
	t=n-t;
	
	static int prev[2002];
	rep(i,n)prev[i]=-1;
	queue<int> q; q.push(0);
	while(!q.empty()){
		int c=q.front(); q.pop();
		if(c==s)break;
		rep(i,e[c].size())q.push(e[c][i]), prev[e[c][i]]=c;
	}
	vi path;
	for(int c=s;c>=0;c=prev[c])path.pb(c);
	reverse(all(path));
	m=path.size();
	path.pb(n+1); T[n+1]=1;
	
	rep(i,n)cld[i]=T[i]=-1;
	rep(i,n)if(cld[i]<0)reccld(i);
	rep(i,n)if(T[i]<0)recT(i);
	
	rep(i,m){
		ll mul=1; int x=cld[path[i]]-cld[path[i+1]]-1;
		rep(j,e[path[i]].size())if(e[path[i]][j]!=path[i+1]){
			mul=mul*T[e[path[i]][j]]%mod*C[x][cld[e[path[i]][j]]]%mod;
			x-=cld[e[path[i]][j]];
		}
		rep(j,n+1)if(j>=i&&n-cld[path[i+1]]-1-j>=0){
			ll tmp=i&&j?sum[i-1][j-1]:1;
			tmp=tmp*C[n-cld[path[i+1]]-1-j][cld[path[i]]-cld[path[i+1]]-1]%mod;
			tmp=tmp*mul%mod;
			dp[i][j]=tmp;
			sum[i][j]=((j?sum[i][j-1]:0)+dp[i][j])%mod;
		}
	}
	cout<<dp[m-1][t]<<endl;
	
	return 0;
}

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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
//#define int long long

signed main(){
    string s; cin >> s;
    cout << count(ALL(s),'1') << endl;
}

Measured memory_bytes: 256
import sys
sin={'a','b','c','d','e','f','g','h','i','j','k','l',
     'm','n','o','p','q','r','s','t','u','v','w','x',
     'y','z'}
s=list(input())
snum=len(list(set(s)))
if snum==26:
    print('None')
    sys.exit(0)

kotae=list(sin-set(s))
kotae.sort()
print(kotae[0])

Measured memory_bytes: 3956
#include <iostream>
#include <complex.h>
#include <math.h>
using namespace std;

const double eps = pow(10, -11);
double x[4], y[4];
int N;
typedef complex<double> xy_t;

double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag();}
int main() {
  cin >> N; //問題数
  for (int t=0; t<N; ++t) {
    for (int i=0; i<4; ++i)
	  cin >> x[i] >> y[i]; //x0,y0..x3,y3
	xy_t a[2] = {
	  xy_t(x[0], y[0]) - xy_t(x[1],y[1]),
	  xy_t(x[2], y[2]) - xy_t(x[3],y[3])
	  };
	  double s = cross_product(a[0] , a[1])/2;
	  bool p = abs(s) < eps;
	  cout << (p ? "YES" : "NO") << endl;
	  }
	 }

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

int main(){

	int n;
	cin >> n;

	vector<int> a(n+1),b(n);

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

	for(int j=0;j<n;j++){
		cin >> b[j];
	}

	long long ans = 0;

	for(int i=0;i<n;i++){
		if(b[i] < a[i]){
			ans+=b[i];
			a[i]-=b[i];
		}else{
			ans+=a[i];
			b[i]-=a[i];

			if(b[i]<a[i+1]){
				ans+=b[i];
				a[i+1]-=b[i];
			}else{
				ans+=a[i+1];
				a[i+1]=0;
			}
		}
	}

	cout << ans << "\n";


	return 0;
}

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

int main(){
    int S;
    cin >> S;
    int s = S%60;
    int M = (S-s)/60;
    int m = M%60;
    int H = (M-m)/60;
    int h = H;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


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

const int MAX_R = 10;
const int MAX_C = 10000;

int R, C;
bool osenbei[MAX_R][MAX_C];

void reverse_row(int row)
{
  for (int i = 0; i < C; i++)
    osenbei[row][i] = !osenbei[row][i];
}

void reverse_col(int col)
{
  for (int i = 0; i < R; i++)
    osenbei[i][col] = !osenbei[i][col];
}

int count_row(int row)
{
  int res = 0;

  for (int i = 0; i < C; i++)
    if (osenbei[row][i]) res++;

  return res;
}

int count_col(int col)
{
  int res = 0;

  for (int i = 0; i < R; i++)
    if (osenbei[i][col]) res++;

  return res;
}

int dfs(int row) {
  if (row == R) {
    int res = 0;

    for (int c = 0; c < C; c++) {
      int count = count_col(c);
      res += max(count, R - count);
    }

    return res;
  }
  else {
    int res = dfs(row + 1);

    reverse_row(row);
    res = max(res, dfs(row + 1));
    reverse_row(row);

    return res;
  }
}

int solve()
{
  return dfs(0);
}

int main()
{
  while (true) {
    scanf("%d %d", &R, &C);

    if (R == 0 && C == 0) break;

    for (int r = 0; r < R; r++) {
      for (int c = 0; c < C; c++) {
        int d;
        scanf("%d", &d);
        osenbei[r][c] = d == 0;
      }
    }
    printf("%d\n", solve());
  }

  return 0;
}


Measured memory_bytes: 3252
a, b = map(str, input().split())
if a == 'H' and b == 'H':
    print('H')

elif a == 'H' and b == 'D':
    print('D')

elif a == 'D' and b == 'H':
    print('D')

elif a == 'D' and b == 'D':
    print('H')
    

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

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF (1<<20)

int main() {
	int N, T;
	cin >> N >> T;
	vector<int> A(N), B;
	map<int, bool> m;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		m[A[i]]=true;
	}
	B = A;
	sort(B.rbegin(), B.rend());

	vector<int> d(N); int j=0;
	for (int i = 0; i < N-1; i++) {
		m[A[i]]=false;
		while(!m[B[j]]) j++;
		d[i] = B[j] - A[i];
		//cout << d[i] <<" "<< B[j] << endl;
	}
	sort(d.rbegin(), d.rend());

	int ans=0, mx=d[0];
	for (int i = 0; i < d.size(); i++) {
		if(mx!=d[i]) break;
		ans++;
	}
	
	cout << ans << endl;
}



Measured memory_bytes: 6144
N = int(input())
a = list(map(int,input().split()))
R = [0]*9
for r in a:
  rr = r//400
  if rr < 8:
    R[rr] = 1
  else:
    R[8] += 1
s2 = sum(R)
s1 = max(1,s2-R[8])
print(s1,s2)

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

using namespace std;
//#define LOCAL
#define maxn 123456

typedef long long ll;
ll c[123456];

ll solve(int n, int id){
    ll sum = 0;
    ll res = 0;
    for (int i = 0; i < n; ++i) {
        if(id % 2 == 0){
            if(sum + c[i] <= 0){
                res += abs(sum + c[i] - 1);
                sum = 1;
            }
            else sum += c[i];
        } else{
            if(sum + c[i] >= 0) {
                res += abs(sum + c[i] - (-1));
                sum = -1;
            }
            else sum += c[i];
        }
        id ++;
    }
    return res;
}
int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin>>c[i];
    }
    ll res = solve(n, 1);
    res = min(res, solve(n, 2));
    cout << res <<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define maxn 200005
using namespace std;
struct Node{
    int to,next,val;
}q[maxn<<1];
int head[maxn],cnt=0;
int dis[maxn];
void init(){
    memset(head,-1,sizeof(head));
    cnt=0;
}
void add_edge(int from,int to){
    q[cnt].to=to;
    q[cnt].next=head[from];
    q[cnt].val=0;
    head[from]=cnt++;
}
void dfs(int x,int fa){
    for(int i=head[x];i!=-1;i=q[i].next){
        int to=q[i].to;
        if(to==fa) continue;
        dis[to]+=dis[x];
        dfs(to,x);
    }
}
int main()
{
    int n,q;
    init();
    scanf("%d%d",&n,&q);
    for(int i=1;i<n;i++){
        int from,to;
        scanf("%d%d",&from,&to);
        add_edge(from,to);
        add_edge(to,from);
    }
    while(q--){
        int x,val;
        scanf("%d%d",&x,&val);
        dis[x]+=val;
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++){
        if(i==1) printf("%d",dis[i]);
        else printf(" %d",dis[i]);
    }
    return 0;
}

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

int main()
{
  int n;
  cin>>n;
  int * arr= new int [n];
  int *dp = new int[n];
  memset(dp,0,sizeof(dp));

  for(int i=0;i<n;i++)
  cin>>arr[i];
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
   for(int i=2;i<n;i++)
   {
       dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
   }
   cout<<endl;

cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 4320
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long int ll;
using namespace std;
const int mod=1e9+7;

int a,b,c;
string s;
int ans;
int sum[1010];
int main(){
    cin>>a>>b;
    REP(i,1,1001){
        sum[i] =sum[i-1]+i;
    }
    REP(i,1,1000){
        if(sum[i]-a<0) continue;
            if (sum[i] - a == sum[i + 1] - b) {
                ans = sum[i] - a;
                break;
            }
    }
    p(ans);
    return 0;
}


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

pair<int, int> b[100000];
vector<long> c[100000];
int main()
{
    int H, W, D; cin>>H>>W>>D;
    for(int i=0; i<H; ++i) for(int j=0; j<W; ++j) {
        int a; cin>>a;
        b[a]=make_pair(i+1, j+1);
    }
    for(int i=1; i<=D; ++i) {
        int x=0, y=0;
        if (i==D) c[i].push_back(0);
        for(int j=i; j<=H*W; j+=D) {
            int s, t; tie(s, t)=b[j];
            c[i].push_back(abs(x-s)+abs(y-t));
            x=s, y=t;
        }
        for(int j=1; j<c[i].size(); ++j) c[i][j]+=c[i][j-1];
    }
    int Q; cin>>Q;
    while (Q--) {
        int L, R; cin>>L>>R;
        int m=L%D?:D;
        cout<<c[m][R/D]-c[m][L/D]<<endl;
    }
}


Measured memory_bytes: 6272
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
s = list(input())
T = list(input())


for i in range(len(s)-len(T), -1, -1):
	for j in range(len(T)):
		if s[i+j] != T[j] and s[i+j] != "?":
			break
	else:
		s[i:i+len(T)] = T
		for i in range(len(s)):
			if s[i] == "?":
				s[i] = "a"
		print(*s, sep = "")
		break
else:
	print("UNRESTORABLE")






Measured memory_bytes: 5200
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <bool Directed, typename TEdge> struct graph {
    using EType = TEdge;
    vector<TEdge> edges;
    vector<vector<int>> adj;
    graph(int n) : adj(n + 1) {}
    graph(int n, int m) : graph(n) { edges.reserve(m); }
    TEdge& operator()(int i) { return edges[i]; }
    vector<int>& operator[](int u) { return adj[u]; }
    int size() { return adj.size() - 1; }
    void add_edge(const TEdge& e) {
        adj[e.u].push_back(edges.size());
        edges.push_back(e);
        if(not Directed) {
            adj[e.v].push_back(edges.size());
            edges.push_back(e.reverse());
        }
    }
};
struct edge {
    int u, v;
    edge reverse() const { return {v, u}; }
};
ostream& operator<<(ostream& os, const edge& e) {
    os << "(" << e.u << ", " << e.v << ")";
    return os;
}
template <typename graph> void dfs(graph& g,
const function<void(int)>& pre_node = [](int) {},
const function<void(typename graph::EType&)>& pre_edge = [](typename graph::EType&) {},
const function<void(typename graph::EType&)>& pos_edge = [](typename graph::EType&) {},
const function<void(int)>& pos_node = [](int) {},
int root = 0) {
    vector<bool> vis(g.size() + 1);
    function<void(int)> dfs = [&](int u) {
        vis[u] = true;
        pre_node(u);
        for(int i : g[u]) if(not vis[g(i).v]) {
            pre_edge(g(i)), dfs(g(i).v), pos_edge(g(i));
        }
        pos_node(u);
    };
    if(root) {
        dfs(root);
    } else {
        for(int u = 1; u <= g.size(); u++) if(not vis[u]) {
            dfs(u);
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k, l;
    cin >> n >> k >> l;
    graph<0, edge> g1(n), g2(n);
    for(int i = 0; i < k; i++) {
        int u, v;
        cin >> u >> v;
        g1.add_edge({u, v});
    }
    for(int i = 0; i < l; i++) {
        int u, v;
        cin >> u >> v;
        g2.add_edge({u, v});
    }
    vector<pair<int, int>> c(n + 1);
    for(int i = 1; i <= n; i++) {
        c[i] = {i, i};
    }
    dfs(g1, [](int) {}, [&](edge& e) {
        c[e.v].first = c[e.u].first;
    });
    dfs(g2, [](int) {}, [&](edge& e) {
        c[e.v].second = c[e.u].second;
    });
    map<pair<int, int>, int> counter;
    for(int i = 1; i <= n; i++) {
        counter[c[i]]++;
    }
    for(int i = 1; i <= n; i++) {
        if(i > 1) cout << " ";
        cout << counter[c[i]];
    }
    cout << endl;
    return 0;
}


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

int main () {
  char a;
  cin >> a;
  
  if (65 <= a && a <= 90) {
    cout << 'A';
  } else {
    cout << 'a';
  }
}

Measured memory_bytes: 3624
import java.util.*;

class Main {
  public static void main(String[] args) {
    Map<Integer, Integer> count = new HashMap<>();
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    long sum = 0;
    for(int i =0; i < n; i++) {
      a[i] = sc.nextInt();
      sum += a[i];
      count.put(a[i], count.getOrDefault(a[i], 0) + 1);
    }
    
    int q = sc.nextInt();
    
    for(int i =0; i < q; i++) {
      int b = sc.nextInt();
      int c = sc.nextInt();
      int temp = count.getOrDefault(b, 0);
      if(temp != 0) {
        sum += (c - b)*temp;
        count.remove(b);
        count.put(c, count.getOrDefault(c, 0) + temp);
      }
      System.out.println(sum);
    }
  }
}


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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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;
}

long long fac[MAX_N], finv[MAX_N], inv[MAX_N];
// テーブルを作る前処理 from: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_N; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// factorial
long long fact(int n) {
    if (n == 1) return fac[n] = 1;
    if (fac[n]) return fac[n];
    return fac[n] = (fact(n - 1) * n) % MOD;
}

long long modpow(long long m, long long p) {
    if (p == 0) return 1;
    if (p % 2)
        return m * modpow(m, p - 1) % MOD;
    else {
        long res = modpow(m, p / 2);
        return res * res % MOD;
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a, b;
    cin >> a >> b;

    auto f = [](ll a) {
        ll num;
        if (a % 2)
            num = ((a + 1) / 2) % 2;
        else
            num = a xor (a / 2) % 2;
        return num;
    };

    ll ans = f(a - 1) xor f(b);
    out(ans);
}


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

int main(){
  int n;
  cin >> n;
  bool ans = false;
  rep(i, 9){
    rep(j, 9){
      if(n==(i+1)*(j+1)) ans = true;
    }
  }
  
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    
  return 0;
}


Measured memory_bytes: 3624
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <complex>
#include <iomanip>
#include <queue>
//定数
#define MOD 1000000007
//マクロ
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

#define vsort(v) sort((v).begin(), (v).end());

typedef unsigned long long int ull;
typedef long long lint;

using namespace std;




int main(){
    string S;
    int count = 0;
    //入力
    cin >> S;
    rep(i, S.size()/2)  if(S[i] != S[S.size()-1-i]) count++;

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Pair{
		int L;
		int R;
		Pair(int L, int R){
			this.L=L;
			this.R=R;
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		ArrayList<Pair> lr = new ArrayList<>();
		for(int i=0; i<M; i++) {
			int L=sc.nextInt(); L--;
			int R=sc.nextInt(); R--;
			lr.add(new Pair(L, R));
		}

		int sum[] = new int[N+1];

		sum[0]=0;
		for(int i=0; i<M; i++) {
			Pair p = lr.get(i);
			sum[p.L] += -1;
			sum[p.R+1] += 1;
		}

		int cnt = 0;
		if(sum[N]==M) cnt++;
		for(int i=N-1; i>=0; i--) {
			sum[i] += sum[i+1];
			if(sum[i]==M) cnt++;
		}
		System.out.println(cnt);
		sc.close();
	}
}


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

int digitsum(int x){
    int sum=0;
    while(x>0){
        sum += x%10;
        x /=10;
    }
    return sum;
}

int main() {
    int N;
    cin >> N;
    int f = digitsum(N);
    if(N % f == 0) cout << "Yes" <<endl;
    else cout << "No" <<endl;
}

Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
C_h, C_w = map(int, input().split())
D_h, D_w = map(int, input().split())
X = [input() for _ in range(H)]

inf = 10 ** 9
dist = [[inf] * W for _ in range(H)]
dist[C_h - 1][C_w - 1] = 0
q = deque()
q.append((C_h - 1, C_w - 1))


while q:
    u, v = q.popleft()
    for i, j in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        if (0 <= u + i < H and 0 <= v + j < W
                and X[u + i][v + j] == "."
                and dist[u + i][v + j] > dist[u][v]):
            dist[u + i][v + j] = dist[u][v]
            q.appendleft((u + i, v + j))

    for i in range(-2, 3):
        for j in range(-2, 3):
            if (0 <= u + i < H and 0 <= v + j < W
                    and X[u + i][v + j] == "."
                    and dist[u + i][v + j] > dist[u][v] + 1):
                dist[u + i][v + j] = dist[u][v] + 1
                q.append((u + i, v + j))

if dist[D_h - 1][D_w - 1] < inf:
    print(dist[D_h - 1][D_w - 1])
else:
    print(-1)


Measured memory_bytes: 91820
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator sl
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v;
map<LL,LL>u;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    string a;
    cin>>a;
    z=0;
    for(i=0,j=a.SZ-1; j>i; i++,j--)
    {
        if(a[i]!=a[j])
        {
            z=1;
            break;
        }
    }
    if(z==0)
    {
        if(a.SZ%2==0)
        {
            for(i=0,j=a.SZ/2-1,k=1; j>i; i++,j--)
            {
                if(a[i]!=a[j])
                {
                    k=0;
                    break;
                }
            }
            if(k==1)
            {
                for(i=a.SZ/2,j=a.SZ-1,l=1; j>i; i++,j--)
                {
                    if(a[i]!=a[j])
                    {
                        l=0;
                        break;
                    }
                }
                if(l==0)
                {
                    cout<<"No"<<endl;
                }
                else
                {
                    cout<<"Yes"<<endl;
                }
            }
            else
            {
                cout<<"No"<<endl;
            }
        }
        else
        {
            for(i=0,j=a.SZ/2-1,k=1; j>i; i++,j--)
            {
                if(a[i]!=a[j])
                {
                    k=0;
                    break;
                }
            }
            if(k==1)
            {
                for(i=a.SZ/2+1,j=a.SZ-1,l=1; j>i; i++,j--)
                {
                    if(a[i]!=a[j])
                    {
                        l=0;
                        break;
                    }
                }
                if(l==0)
                {
                    cout<<"No"<<endl;
                }
                else
                {
                    cout<<"Yes"<<endl;
                }
            }
            else
            {
                cout<<"No"<<endl;
            }
        }
    }
    else
    {
        cout<<"No"<<endl;
    }
}


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

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

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

  while(true) {
    int N, M, P;
    cin >> N >> M >> P;
    if(N + M + P == 0) break;

    int sum = 0;
    int a;
    int X[1010];
    rep(i, N) {
      cin >> a;
      X[i] = a;
      sum += X[i];
    }
    if(X[M - 1] == 0) {
      cout << 0 << endl;

      continue;
    }
    sum = sum * 100;

    sum = sum - (sum * P / 100);

    sum = sum / X[M - 1];

    cout << sum << endl;
  }
}



Measured memory_bytes: 3004
from fractions import gcd
from math import ceil
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=len(bin(a[0]))-bin(a[0]).rfind("1")
for i in range(1,n):
  if c!=len(bin(a[i]))-bin(a[i]).rfind("1"):
    print(0)
    exit()
g=a[0]
for i in range(n-1):
   g=(g//gcd(g,a[i+1]))*(a[i+1]//gcd(g,a[i+1]))*gcd(g,a[i+1])
g//=2
print(ceil((m//g)/2))


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

using ll=long long;
ll n,k;
pair<ll,ll> a[100010]; 

int cmp(pair<ll,ll> q,pair<ll,ll> w)
{
	return q.first<w.first;
}

int main()
{
    ios::sync_with_stdio(false);
	cin>>n>>k;
	for (int i=1;i<=n;i++) cin>>a[i].first>>a[i].second;
	sort(a+1,a+n+1,cmp); 
	ll j=0;
	for (int i=1;i<=n;i++)
	{
		j+=a[i].second;
		if (j>=k) 
		{
			cout<<a[i].first;
			return 0;
		}
	}
}

Measured memory_bytes: 1792
import bisect
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1, len(A)):
  A[i] += A[i - 1]
for i in range(1, len(B)):
  B[i] += B[i - 1]
#print(A, B)
res = 0
for i in range(len(A)):
  temp = k - A[i]
  bcan = bisect.bisect_right(B, temp)
  if temp >= 0:
    res = max(res, (i + 1 + bcan))
bcan = bisect.bisect_right(B, k)
res = max(res, bcan)
print(res)

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

#define INF 100000000
#define MOD 100000007

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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;
}

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c; cin>>a>>b>>c;
    if(b+c>=a) cout<<b+c-a<<endl;
    else cout<<0<<endl;


    return  0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    string S;
    cin >> N >> S;
    ll ans = 0;
    rep(i, 1000) {
        string s = to_string(i);
        while (s.size() < 3) {
            s = '0' + s;
        }
        int idx = 0;
        rep(i, N) {
            if (idx <= 2 && s[idx] == S[i]) {
                idx ++;
            }
        }
        if (idx == 3) {
            ans ++;
        }
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 384
def gcd_core(a,b):
    if b == 0:
        return a
    else:
        return gcd_core(b,a%b)

def gcd(arr):
    g = gcd_core(arr[0],arr[1])
    for i in range(2,len(arr)):
        g = gcd_core(g,arr[i])
    return g

n = int(input())
s = input()
r = 0
for c in s:
    if c=="R":
        r +=1

if r > n//2:
    print("Yes")
else:
    print("No")

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

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

  vector<int> w(n);
  int wtmp = 0;
  for (int i = 0; i < n; i++) {
    if (s.at(i) == 'W') {
      wtmp++;
    }
    w.at(i) = wtmp;
  }
  w.insert(w.begin(), 0);

  vector<int> e(n);
  int etmp = n - wtmp;
  for (int i = 0; i < n; i++) {
    if (s.at(i) == 'E') {
      etmp--;
    }
    e.at(i) = etmp;
  }
  e.insert(e.begin(), n - wtmp);


  int ans = n, tmp = 0;
  for (int i = 0; i <= n; i++) {
    if (i == 0) {
      tmp = e.at(i);
    } else if (i == n) {
      tmp = w.at(i);
    } else {
      tmp = w.at(i) + e.at(i);
    }
    ans = min(tmp, ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 5232
#include <iostream>
#include <vector>
#include <string>

using namespace std;

vector<vector<int>> dp, p;
string s, t;

void get_string(int i, int j, string& res, int k){
	if (k < 0) return;
	// cout << p[i][j] << endl;
	if (p[i][j] == 0) {
		res[k] = s[i-1];
		get_string(i-1, j-1, res, k-1);
	}else if (p[i][j] == 1){
		get_string(i-1, j, res, k);
	} else if (p[i][j] == 2){
		get_string(i, j-1, res, k);
	}
}

int main(){
	cin >> s >> t;
	int n = s.size(), m = t.size();

	dp.assign(n+1, vector<int>(m+1, 0));
	p.assign(n+1, vector<int>(m+1, -1));

	for(int i = 1 ; i <= n ; i++){
		for(int j = 1; j <= m; j++){
			if (s[i-1] == t[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
				p[i][j] = 0;
			} else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
				p[i][j] = (dp[i-1][j] >= dp[i][j-1]) ? 1 : 2;
			}
		}
	}

	string res(dp[n][m], ' ');

	get_string(n, m, res, dp[n][m] - 1);

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 70912
import numpy as np

n, k, q = map(int, input().split())
a = []
for _ in range(q):
    a.append(int(input()))

nn = np.zeros(n)
kk = np.zeros(n) + k
qq = np.zeros(n) + q

for i in a:
    nn[i-1] += 1

_list = (kk-qq+nn).tolist()

for ans in _list:
    if ans > 0:
        print('Yes')
    else:
        print('No')

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

int main() {
    int T;
    while(cin >> T, T) {
        vector<int> t(T);
        int N = 0;
        for(int i=0; i<T; ++i) {
            cin >> t[i];
        }
        cin >> N;
        vector<vector<int>> dp(101, vector<int>(101, 1e9));
        dp[1][1] = 0;
        vector<int> M(101, 1e9);
        for(int i=0; i<N; ++i) {
            int d, m;
            cin >> d >> m;
            M[d] = min(m, M[d]);
        }
        for(int i=2; i<101; ++i) {
            for(int j=1; j<i; ++j) {
                if(M[i] >= t[(i-j) % T]) {
                    dp[i][j] = dp[i-1][j];
                }
            }
            for(int j=1; j<101; ++j) {
                dp[i][i] = min(dp[i][i], dp[i-1][j]+1);
            }
        }
        int res = 1e9;
        for(int i=1; i<101; ++i) {
            res = min(res, dp[100][i]);
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  // 文字列
  string str;
  cin >> str;
  
  if ( str.at(2) == str.at(3) && str.at(4) == str.at(5) ) {
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" << endl;
    }
  
}


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

using namespace std;

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

	int a, b;
	cin >> a >> b;

	const int pa = 8, pb = 10;

	for(int i = 0; i <= pb * 100; ++i){
		if((a + 1) * 100 > i * pa && i * pa >= a * 100){
			if((b + 1) * 100 > i * pb && i * pb >= b * 100){
				cout << i << "\n";
				return 0;
			}
		}
	}

	cout << "-1\n";	
}

Measured memory_bytes: 256
a1, a2, a3 = [int(x) for x in input().split()]
a1a2 = abs(a1 - a2)
a1a3 = abs(a1 - a3)
a2a3 = abs(a2 - a3)

print(sum(sorted([a1a2, a1a3, a2a3])[:2]))
  

Measured memory_bytes: 2940
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int d[] = new int[N];
		
		for(int i=0; i<N; i++) {
			d[i] = sc.nextInt();
		}
		//問題を難易度順に昇順で並び替える
		Arrays.sort(d);
		// N/2番目の要素から、N/2-1番目の要素を引いたものを出力
		System.out.println(d[N/2]-d[N/2-1]);
	}		
}
	// N/2番目に難しい問題がARC用の問題、N/2-1番目に難しい問題がABC用の問題
	// ARC用の問題の数とABC用の問題の数は同じになる
	// 以上の２つは同じ値である

Measured memory_bytes: 50408