akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
 
#define N 10000
#define Q 500
 
int main(void){
 
  int i,j,n,q,count=0,key,flag=0;
  int s[N],t[Q];
  
  scanf("%d",&n);
  if(n>N) exit(1);
  for(i=0;i<n;i++) scanf("%d",&s[i]);
   
  scanf("%d",&q);
  if(q>Q) exit(2);
  for(i=0;i<q;i++) scanf("%d",&t[i]);
 
  for(i=0;i<q;i++){
    flag=0;
    key=t[i];
      j=0;
    s[n]=key;
 
    while(1){
      if(s[j]==key){
    flag++;
    break;
      }
      j++;
      if(j==n) break;
 
    }
    if(flag==1) count ++;
  }
  
  printf("%d\n",count);
 
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int H,A;
  cin>>H>>A;
  cout<<H/A + (int)(H%A>0)<<endl;
  
  return;
}


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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


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

using namespace std;

int n, la;

int main() {
	scanf("%d", &n);
	while (n--) {
		int tmp;
		scanf("%d", &tmp);
		if (tmp < la) {
			puts("No");
			return 0;
		}
		if (tmp - 1 >= la)
			tmp--;
		la = tmp;
	}
	puts("Yes");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define endl '\n' 
typedef long long int lli ; 
using namespace std; 

int main(int argc, char const *argv[])
{	

	int n  = 0, m  = 0; 
	cin >> n >> m; 
	vector<pair<int, int>> a(m); 
	for(int i = 0; i<m; ++i){
		int u , v; 
		cin >> u >> v; 
		a[i] = make_pair(v,u); 
	} 
	sort(a.begin() , a.end()) ; 
	int c = 1;
	int end = a[0].first; 
	for(int i = 1; i < m; ++i){
		if(a[i].second >= end){
			c++; 
			end = a[i].first; 
		}
	} 
	cout << c; 

	
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
a = [int(i) for i in input().split()]

li_int = [int(i) for i in range(1, 10001)]

li_use = set(li_int) - set(a)
li_use = list(li_use)

ans = 0

for j in range(len(a)-1):
    if a[j] == a[j+1]:
        a[j+1] = li_use[j]
        ans += 1
        li_use.remove(li_use[j])
else:
    print(ans)


Measured memory_bytes: 4556
n, m = [int(i) for i in input().split()]
f = True
d = {}
for _ in range(m):
  s, c = [int(i) for i in input().split()]
  if s in d.keys() and d[s] != c:
    f = False
  d[s] = c
  
ans = ''


if n != 1:
  if 1 in d.keys():
    if d[1] == 0:
      f = False
    else:
      ans = str(d[1])
  else:
    ans = '1'
  for i in range(n-1):
    if i+2 in d:
      ans += str(d[i+2])
    else:
      ans += '0'
else:
  if 1 in d.keys():
    ans = str(d[1])
  else:
    ans = '0'
    
if f:
  print(ans)
else:
  print(-1)




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

int main()
{
    int $=1;
    //cin>>$;
    while($--)
    {
        string s;
        cin>>s;
        ll a=0;
        for(auto x:s) a+=x-'0';
        if(a%9==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


/*
8888888888888888888888888888
    Md. Masud Mazumder
    University of Chittagong
    Department of CSE
8888888888888888888888888888
*/


Measured memory_bytes: 3716
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
    string a, b, c;
    int n;
    int ans = 0;

    cin >> n;

    cin >> a >> b >> c;

    for (int i = 0; i < (int)a.size(); i++) {
        if (a[i] == b[i]) {
            if (a[i] != c[i]) ans++;
        }
        else if (a[i] == c[i]) {
            if (a[i] != b[i]) ans++;
        }
        else if (b[i] == c[i]) {
            if (b[i] != a[i]) ans++;
        }
        else if (a[i] != b[i] && a[i] != c[i] && b[i] != c[i]) {
            ans += 2;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
n,m = map(int,input().split())
A = [[int(j) for j in input().split()] for i in range(n)]
b = [int(input()) for j in range(m)]

for i in range(n):
    c = 0
    for j in range(m):
        c += A[i][j]*b[j]
    print(c) 


Measured memory_bytes: 6012
/*
 * src.cpp
 *
 *  Created on: 2016/08/11
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

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

const int MAX_LEN=1e5;

int p;
char ex[MAX_LEN+32];

int power(int x,int n){
	int res=1;
	while (n){
		if (n&1){
			res=res*x%p;
		}
		n>>=1;
		x=x*x%p;
	}
	return res;
}

int pos;
bool valid;

int term();
int factor();

int exression(){
	int value=term();
	while (ex[pos]=='+' || ex[pos]=='-'){
		if (ex[pos]=='+'){
			pos++;
			value=(value+term())%p;
		}else{
			pos++;
			int m=p-term();
			value=(value+m)%p;
		}
	}
	return value;
}

int term(){
	int value=factor();
	while (ex[pos]=='*' || ex[pos]=='/'){
		if (ex[pos]=='*'){
			pos++;
			value=value*factor()%p;
		}else{
			pos++;
			int f=factor();
			if (f==0) valid=true;
			int d=power(f,p-2);
			value=value*d%p;
		}
	}
	return value;
}

int factor(){
	int value=0;
	if (ex[pos]=='('){
		pos++;
		value=exression();
		pos++;
	}else if (isdigit(ex[pos])){
		while (isdigit(ex[pos])){
			value=value*10+ex[pos]-'0';
			pos++;
		}
	}
	return value;
}

int main(){
	do{
		scanf("%d:",&p);
		if (p){
			fgets(ex,MAX_LEN+32,stdin);
			int len=strlen(ex);
			int l=0;
			REP(i,len-1){
				if (ex[i]!=' '){
					ex[l]=ex[i];
					l++;
				}
			}
			ex[l++]=0;
			pos=0;
			valid=false;
			int e=exression();
			if (valid){
				printf("NG\n");
			}else{
				printf("%s = %d (mod %d)\n",ex,e,p);
			}
		}
	}while (p);
	return 0;
}

Measured memory_bytes: 1280
s=input()
c=0
while len(s)>1:
  if s[0]==s[len(s)-1]:
    s=s[1:len(s)-1]
  elif s[0]=='x':
    c+=1
    s=s[1:]
  elif s[len(s)-1]=='x':
    c+=1
    s=s[:len(s)-1]
  else:
    print(-1)
    exit()
print(c)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const ll mod = 1000000000+7;

ll mod_pow(ll a, ll n, ll p){
    if(n == 0)  return 1;
    if(n%2 == 1)    return (a*mod_pow(a, n-1, p)) % p;
    ll t = mod_pow(a, n/2, p);
    return (t*t) % p;
}

ll inv_pow(ll a, ll p){
    return mod_pow(a, p-2, p);
}

ll nCr(ll n, ll r){
    ll ret = 1;
    for(ll i = n; i >= n-r+1; i--)  (ret *= i) %= mod;
    for(int i = 1; i <= r; i++)   (ret *= inv_pow(i, mod)) %= mod;
    return ret;
}

int main(){
    ll n,a,b;   cin >> n >> a >> b;
    ll ans = 0;
    ans = mod_pow(2, n, mod) - 1;
    (ans = ans + mod - nCr(n, a)) %= mod;
    (ans = ans + mod - nCr(n, b)) %= mod;
    cout << ans << endl;
}


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

int main() {
    int i, j, k;
    int n, x;
    while (true) {
        cin >> n >> x;
        if (n == 0 && x == 0) {
            break;
        }

        int count = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) {
                        count++;
                    }
                }
            }
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define fi first
#define se second

const int maxn=55,mod=1e9+7;
int n,k;
struct matrix
{
    int m[maxn][maxn];
};
matrix a;

matrix operator *(matrix A,matrix B)
{
    matrix C;
    forinc(i,0,n-1) forinc(j,0,n-1) C.m[i][j]=0;
    forinc(t,0,n-1){
        forinc(i,0,n-1)
        forinc(j,0,n-1)
        {
            C.m[i][j]=(A.m[i][t]*B.m[t][j]+C.m[i][j])%mod;
        }
    }
    return C;
}
matrix pw(matrix a,int k)
{
   matrix b=a;
   for(;k;k>>=1,a=a*a) if(k&1) b=b*a;
   return b;;
}

main()
{
    cin>>n>>k;
    forinc(i,0,n-1) forinc(j,0,n-1)
    {
        int u;
        cin>>u;
        a.m[i][j]=u;
    }
    matrix kq=pw(a,k-1);
    int ret=0;
    forinc(i,0,n-1) forinc(j,0,n-1) ret=(ret+kq.m[i][j])%mod;
    cout<<ret;
}


Measured memory_bytes: 512
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    s = input()
    ans = 0
    ls = [0] * s.count('W')
    idx = 0
    for i in range(len(s)):
        if s[i] == 'W':
            ls[idx] = i
            idx += 1
    cnt = 0
    for i in ls:
        ans += (i - cnt)
        cnt += 1
    print(ans)

if __name__=="__main__":
    solve()


Measured memory_bytes: 11240
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    string s;
    cin >> s;
    string ns = "";

    vector<string> ans;
    rep(i, s.size()){
        if(s[i] == 'A') {
            ns += 'A';
        } else if(s[i] == 'B' && s[min(i+1, (int)s.size()-1)] == 'C'){
            i++;
            ns += 'S';
        } else if(ns!=""){
            ans.push_back(ns);
            ns = "";
        }
    }
    if (ns!="") ans.push_back(ns);

    ll score = 0;
    rep(i, ans.size()){
        string ts = ans[i];
        reverse(ts.begin(), ts.end());

        int snum = 0;
        rep(j, ts.size()){
            if (ts[j]=='S'){
                snum++;
            } else {
                score += snum;
            }         
        }
    }

    //show(ans);

    cout << score << endl;
}



Measured memory_bytes: 3196
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
k = [0]*n
for i in a:
  k[i-1]+=1
g = 0
for i in range(n):
  g+=((k[i]*(k[i]-1))//2)
for i in a:
  print(g+1-k[i-1])
  

Measured memory_bytes: 26780
#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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

struct fenwick_tree {
  typedef int T;
  T n;
  vector<T> bit;

  // 各要素の初期値は 0
  fenwick_tree(T num) : bit(num+1, 0) { n = num; }

  // a_i += w
  void add(T i, T w) {
    for (T x = i; x <= n; x += x & -x) {
      bit[x] += w;
    }
  }
  // [1, i] の和を計算.
  T sum(T i) {
    T ret = 0;
    for (T x = i; x > 0; x -= x & -x) {
      ret += bit[x];
    }
    return ret;
  }
  // [left+1, right] の和を計算.
  T sum(T left, T right) {
    return sum(right) - sum(left);
  }
};

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
  ll N,k;
  cin >> N >> k;
  mint K=k;

  vector<int> A(N);
  vector<int> B(2*N);
  REP(i, N) cin >> A[i];
  fenwick_tree f_tree(2010);
  fenwick_tree f_tree2(2010);
  REP(i,2*N){
    B[i]=A[i%N];
  }

  mint ans = 0;
  for (int j = 0; j < N; j++) {
    ans += j - f_tree.sum(A[j]);
    f_tree.add(A[j], 1);
  }
  mint ans2 = 0;
  for (int j = 0; j < 2*N; j++) {
    ans2 += j - f_tree2.sum(B[j]);
    f_tree2.add(B[j], 1);
  }
  mint x = ans*K+(ans2-ans*2)*K*(K-1)/2;
  cout << x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<string.h>
#include <math.h>

using namespace std;
//recursive implementation
int lcs(string x, string y, int lx, int ly){
	//base case
	if(lx==0 || ly==0)
		return 0;
	else if(x[lx-1]==y[ly-1])
		return lcs(x, y, lx-1, ly-1)+1;
	else
		return max(lcs(x,y,lx, ly-1), lcs(x,y,lx-1, ly));
}

//dp implementation
void lcs_dp(string x, string y, int lx, int ly){
	
	int dp[lx+1][ly+1];
	
	for(int i=0;i<=lx;i++){
		for(int j=0;j<=ly;j++){
			if(i==0||j==0)dp[i][j]=0;
			else if(x[i-1]==y[j-1])
				dp[i][j] = dp[i-1][j-1]+1;
			else
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	
	int res_length = dp[lx][ly];
	//the length od the sequence is in res_length
	char res[res_length+1];
	res[res_length]='\0';
	//intiialise index to length-1
	int index=res_length-1;
	//now print the lcs itself
	int xi=lx, yi=ly;
	while(index>=0){
		if(x[xi-1]==y[yi-1])
		{
			res[index] = x[xi-1];
			xi--;
			yi--;
			index--;	
		}
		else{
			if(dp[xi-1][yi]>dp[xi][yi-1]){
				xi--;
			}
			else{
				yi--;
			}
		}
	
	}
	cout<<res<<endl;
}
	
int main(){
	string x; string y;
	cin>>x;
	cin>>y;
	int lx, ly;
	lx = x.length();
	ly = y.length();
	
	lcs_dp(x,y,lx,ly);
	return 0;

}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vec vector
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << a << endl
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()


int main() {
  string S,T;
  cin >> S >> T;
  int ans = 1e9,N = S.size(),tsize = T.size();
  rep(i,N) {
    if (i+tsize>N)
      continue;
    int cnt = 0;
    rep(j,tsize) {
      if (S[i+j] != T[j])
        cnt++;
    }
    ans = min(ans,cnt);
  }
  print(ans);
  return 0;
}

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

int main(){
  int N,A,B,sum=0,tmp,j;
  cin >> N >> A >> B;
  for(int i=1;i<N+1;i++){
    j=i;
    while(j>0){
      tmp += j%10;
      j = j/10;
    }
    if(tmp>=A && tmp <=B){
      sum += i;
    }
    tmp=0;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lim 10000007
#define mod 1000000007
#define mp make_pair
#define sd(n) scanf("%lld",&n)
#define pb push_back
#define FIO() freopen("in.txt","r",stdin)
#define F first
#define S second
#define db double
#define INF 1e12
#define pd(n) printf("%lld\n",n)
#define pdd(n) printf("%.20lf\n",n)
#define pii pair<ll,ll>

int main()
{
    //FIO();
    ll x,y;
    cin>>x>>y;
   vector<ll>v;
   ll ans=INF;
   ll q;
   if(x==0)
   {
    if(y>0)
        cout<<y<<endl;
    else cout<<abs(y)+1<<endl;
    return 0;
   }
   if(y==0)
   {
    if(x<0)
        cout<<abs(x)<<endl;
    else cout<<1+abs(x)<<endl;
    return 0;
   }
   if(x>0)
   {if(abs(y)>=abs(x))
   {
     q=abs(y)-abs(x);
    if(y<0)
        q++;
    ans=min(ans,q);
   }
   else
   {
        q=1+abs(x)-abs(y);
        if(y>0)
            q++;
        ans=min(ans,q);
   }
}
else
{
    if(abs(x)>=abs(y))
    {
        q=abs(x)-abs(y);
        if(y>0)
            q++;
        ans=min(ans,q);
    }
    else
    {
        q=abs(y)-abs(x)+1;
        if(y<0)
            q++;
        ans=min(ans,q);
    }

}

cout<<ans<<endl;

  

    

    
}

Measured memory_bytes: 256
#B問題
N, L =map(int,input().split())
apple =  [i+1 for i in range(N)]
apple_taste = [L+i-1 for i in apple]
delete = min(apple_taste)
if delete < 0:
    abs_apple_taste = [abs(L+i-1) for i in apple]
    delete = -min(abs_apple_taste)
apple_taste.remove(delete)
print(sum(apple_taste))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,ll>;
const int MAX = 100005;
vector<P> to[MAX];
vector<ll> Node(MAX);
void rec(int cur, int prev, ll d) {
    Node[cur] = d;
    for(P v : to[cur]) {
        if(v.first == prev) continue;
        rec(v.first, cur, d+v.second);
    }
}
int main() {
    int n; cin >> n;
    rep(i, n-1) {
        int a, b; ll c; cin >> a >> b >> c;
        a--; b--;
        to[a].push_back(P{b, c});
        to[b].push_back(P{a, c});
    }
    int q, k; cin >> q >> k;
    k--;
    rec(k,-1,0);
    rep(i, q) {
        int x, y; cin >> x >> y; x--; y--;
        //x to k
        ll x_k = abs(Node[x]-Node[k]);
        ll y_k = abs(Node[y]-Node[k]);
        cout << x_k + y_k << endl;
    }
}


Measured memory_bytes: 14336
#include<algorithm>
#include<complex>
#include<cstdio>
#include<iostream>
#include<queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
template<class T> T at(vector<T> v, int i) {return v[i % v.size()];}

#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};
typedef vector<P> Pol;

const D EPS = 1e-8;
const D PI = acos(-1);

int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return norm(a - b) < EPS;}

// 比較関数
namespace std {
  bool operator<(P a, P b) {return sig(a.X, b.X) ? a.X < b.X : a.Y < b.Y;}
}

D sr(D a) {return sqrt(max(a, (D)0));}

// 内積
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// 外積
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.b - a.a;}

// 線分abに対する点cの位置
enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
int ccw(P a, P b, P c) {
  if (a == c || b == c) return ON;
  int s = sig(det(b - a, c - a));
  if (s) return s > 0 ? LEFT : RIGHT;
  return (a < b) == (b < c) ? FRONT : (c < a) == (a < b) ? BACK : ON;
}

// 有向角度
D arg(P base, P a, P b) {
  D ang = arg((b - base) / (a - base));
  return ang > 0 ? ang : ang + 2 * PI;
}

// 射影
P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.a + proj(vec(l), p - l.a);}

// 交点
P pLL(L a, L b) {return a.a + vec(a) * (det(vec(b), b.a - a.a) / det(vec(b), vec(a)));}

// 距離
D dLP(L l, P p) {return abs(det(vec(l), p - l.a)) / abs(vec(l));}

// 円
struct C{P c; D r;};

// 交差判定
bool iCL(C c, L l) {return sig(c.r, dLP(l, c.c)) >= 0;}

// 交点
pair<P, P> pCL(C c, L l) {
  P x = perp(l, c.c);
  P y = vec(l) / abs(vec(l)) * sr(c.r * c.r - norm(x - c.c));
  return make_pair(x - y, x + y);
}

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) break;
    Pol p(n), q(m);
    rep (i, n) cin >> p[i].X >> p[i].Y;
    rep (i, m) cin >> q[i].X >> q[i].Y;
    P c;
    cin >> c.X >> c.Y;
    D res = 2 * PI;
      rep (i, n) {
	if (near(c, p[i])) continue;
	C a = (C){c, abs(c - p[i])};
	rep (j, m) {
	  L s = (L){q[j], at(q, j + 1)};
	  if (!iCL(a, s)) continue;
	  pair<P, P> pp = pCL(a, s);
	  if (ccw(s.a, s.b, pp.first) == ON) {
	    res = min(res, arg(c, pp.first, p[i]));
	  }
	  if (ccw(s.a, s.b, pp.second) == ON) {
	    res = min(res, arg(c, pp.second, p[i]));
	  }
	}
      }
      swap(n, m);
      swap(p, q);
      rep (i, n) {
	if (near(c, p[i])) continue;
	C a = (C){c, abs(c - p[i])};
	rep (j, m) {
	  L s = (L){q[j], at(q, j + 1)};
	  if (!iCL(a, s)) continue;
	  pair<P, P> pp = pCL(a, s);
	  if (ccw(s.a, s.b, pp.first) == ON) {
	    res = min(res, arg(c, p[i], pp.first));
	  }
	  if (ccw(s.a, s.b, pp.second) == ON) {
	    res = min(res, arg(c, p[i], pp.second));
	  }
	}
      }
    printf("%.12Lf\n", res * 180 / PI);
  }
  return 0;
}

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

using namespace std;

int main()
{
    int n;
    
    while (cin >> n, n) {
        vector<vector<int> > a(2, vector<int>(n));
        int cnt = 0;
        int f, t;

        f = 0;
        t = 1;
        for (int i = 0; i < n; i++)
            cin >> a[0][i];

        while (a[t] != a[f]) {
            for (int i = 0; i < n; i++) {
                int tmp = 0;
                for (int j = 0; j < n; j++)
                    if (a[f][i] == a[f][j])
                        tmp++;
                a[t][i] = tmp;
            }

            cnt++;
            f = 1 - f;
            t = 1 - t;
        }

        cout << cnt - 1 << endl;
        for (int i = 0; i < n - 1; i++)
            cout << a[t][i] << " ";
        cout << a[t][n - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll ;
 
#define pb     push_back
#define mp     make_pair
#define all(v) v.begin() , v.end()
#define allr(v) v.rbegin(), v.rend()
const ll INF =  0x3f3f3f3f;
const int MOD = 1e9+7;
const int MAX = 1e5+5;
 
int n, d;
vector<int> a;
map<int, int> cnt;
 
int main(int argc, char const *argv[])
{
  ios_base::sync_with_stdio(false);

  scanf("%d" , &n);
  for(int i = 0 ; i < n ; i++){
  	scanf("%d" , &d);
  	cnt[d]++;
  	a.pb(d);
  }
 
  sort(allr(a));
  int prev = -1;
 
  ll side1, side2;
  side1 = -1;
  side2 = -1;
 
  for(int i = 0 ; i < (int)a.size() ; i++){
  	int s = a[i];
  	if(s == prev)
  		continue;
  	else
  		prev = s;
  	if(cnt[s] > 3){
  		if(side1 == -1){
	  		side1 = side2 = s;
	  		break;  			
  		}
  		else if(side2 == -1){
  			side2 = s;
  			break;
  		}
  	}
  	else if(cnt[s] > 1){
  		if(side1 == -1)
  			side1 = s;
  		else{
  			side2 = s;
  			break;
  		}
  	}
  }
 
  if(side1 == -1 || side2 == -1)
  	printf("0");
  else
  	printf("%lld" , side1*side2);
 
 
 
  return 0;
}  

Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (1e2) + 5;
bool M[N][N];
int n;

int main() {
	scanf("%d", &n);
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			if (i + j == n + (1 - n % 2)) {
				M[i][j] = 1;
			} else {
				cnt++;
			}
		}
	}
	printf("%d\n", cnt);
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			if (M[i][j] == 0) {
				printf("%d %d\n", i, j);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!(n: usize, a: [u32; n]);
    let mut l = a.iter().min().unwrap() - 1;
    let mut r = a.iter().max().unwrap() + 1;

    while 1 < r - l {
        let c = (l + r) / 2;
        let mut b = vec![n as i32; n + 1];
        (0..n).for_each(|i| b[i + 1] = b[i] + if a[i] <= c { 1 } else { -1 });

        let sz = 2 * n + 1;
        let mut seg = vec![0; 2 * sz];
        let mut cnt = 0;
        for x in b {
            let x = x as usize;

            let mut l = sz;
            let mut r = sz + x;
            while l < r {
                if l % 2 == 1 {
                    cnt += seg[l];
                    l += 1;
                }
                if r % 2 == 1 {
                    r -= 1;
                    cnt += seg[r];
                }
                l /= 2;
                r /= 2;
            }

            let mut i = x + sz;
            seg[i] += 1;
            while 0 < i {
                i /= 2;
                seg[i] = seg[2 * i] + seg[2 * i + 1];
            }
        }

        if (n * (n + 1)) / 4 < cnt {
            r = c;
        } else {
            l = c;
        }
    }
    println!("{}", r);
}

/*
 * 答えが X 以下であることの条件は、
 * 中央値が X 以下である区間が n(n+1)/4 個より多くあることです。
 *
 * 中央値が X 以下である区間を数えるために、X 以下 を 1、大きいものを -1 とします。
 * すると、中央値が X 以下である条件は、総和が 0 以上なことです。
 * そこで、この配列の累積和を取って、距離 1 以上の弱増加ペアを数え上げればよいです。
 *
 * うーん、セグツリーを書くしかなさそうですね。
 */


Measured memory_bytes: 6852
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            Array.Sort(input);
            if (input[0] != 1) { Console.WriteLine("NO"); return; }
            if (input[1] != 4) { Console.WriteLine("NO"); return; }
            if (input[2] != 7) { Console.WriteLine("NO"); return; }
            if (input[3] != 9) { Console.WriteLine("NO"); return; }

            Console.WriteLine("YES");
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int n;
	cin >> n;
	v1 c(0);
	map<string, pair<int, int>> q;//はじめがばしょ、次がカウント
	vector<string> sal(0);
	int j = 0;
	rep(i, n){
		string s;
		cin >> s;
		if(q.find(s) == q.end()){
			q[s] = make_pair(j, 1);
			c.push_back(1);
			sal.push_back(s);
			j++;
		}else{
			q[s].second ++;
			c.at(q[s].first)++;
		}
	}
	int f = sal.size();
	int g = c.size();
	if(f != g) cout << "error" << endl;
	set<string> answer;
	int max = 0;
	rep(i, f){
		if(c.at(i) > max){
			answer.erase(answer.begin(), answer.end());
			answer.insert(sal.at(i));
			max = c.at(i);
		}else if(c.at(i) == max){
			answer.insert(sal.at(i));
		}
	}
	int h = answer.size();
	auto itr = answer.begin();
	rep(i, h){
		cout << *itr << endl;
		itr++;
	}
}


Measured memory_bytes: 41328
#include <stdio.h>
#include <stdlib.h>
long xxx[10][1001][101];

long pattern(int n,int s,int from){
	long i,x=0;
	if(xxx[n][s][from]>=0)x=xxx[n][s][from];
	else{
		for(i=(s-100*(n-1)>from?s-100*(n-1):from); i<100 && i<=s ;i++){x+=pattern(n-1,s-i,i+1);}
		xxx[n][s][from]=x;
	}
	return x;
}

int main(void){
	int n,s,i,j,k;
	for(j=0;j<1001;j++){
		for(k=0;k<101;k++){
			xxx[1][j][k]=( (j<=100 && k<=j)?1:0 );
			xxx[2][j][k]=( (2*k<=j && j<=200) ? ((100-k+1)-abs((100-k)-(j-k*2)))/2 : 0 );
		}
	}
	for(i=3;i<10;i++){for(j=0;j<1001;j++){for(k=0;k<101;k++){xxx[i][j][k]=-1;}}}
    while(scanf("%d %d",&n,&s)*(n+s)){
	printf("%ld\n",pattern(n,s,0));}
    return 0;
}

Measured memory_bytes: 7712
#include<stdio.h>
int main(){
  char s[5];
  scanf("%s",s);
  int count=0;
  for(int i=0;i<4;i++){
    for(int j=i+1;j<4;j++){
      if(s[i]==s[j])
        count++;
    }
  }
  if(count!=2)
    printf("No");
  else
    printf("Yes");
}


Measured memory_bytes: 1728
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

int main() {
    i64 n;
    cin >> n;
    vector<i64> a(3 * n);
    for (int i = 0; i < 3 * n; ++i) {
        cin >> a[i];
    }

    vector<i64> sum_l(3 * n + 1), sum_r(3 * n + 1);
    priority_queue<i64, vector<i64>, greater<i64>> pq_l;
    priority_queue<i64> pq_r;
    for (int i = 0; i < 2 * n; ++i) {
        sum_l[i + 1] = sum_l[i] + a[i];
        pq_l.push(a[i]);
        if (pq_l.size() > n) {
            sum_l[i + 1] -= pq_l.top();
            pq_l.pop();
        }
    }
    for (int i = 3 * n - 1; i >= n; --i) {
        sum_r[i] = sum_r[i + 1] + a[i];
        pq_r.push(a[i]);
        if (pq_r.size() > n) {
            sum_r[i] -= pq_r.top();
            pq_r.pop();
        }
    }
    // for (i64 x : sum_l) cerr << x << ' ';cerr << endl;
    // for (i64 x : sum_r) cerr << x << ' ';cerr << endl;
    i64 ans = -(1ll << 60);
    for (int i = n; i <= 2 * n; ++i) {
        ans = max(ans, sum_l[i] - sum_r[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9588
import java.util.Scanner;

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

    long K = scanner.nextLong();
    int N = 50;
    long[] k = new long[N];

    long l = K / N;
    int r = (int) (K % N);
    for (int i = 0; i < r; i++) k[i] = l + 1;
    for (int i = r; i < N; i++) k[i] = l;

    System.out.println(N);
    for (int i = 0; i < N; i++) {
      long a = N * (k[i] + 1) - 1;
      for (int j = 0; j < N; j++) if(i != j) a -= k[j];
      System.out.printf("%d ", a);
    }
    System.out.println();
  }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        if (s[i] != s[n - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    // cout << 1 << endl;
    for (int i = 0; i < (n - 1) / 2; i++) {
        if (s[i] != s[(n - 1) / 2 - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    // cout << 1 << endl;
    for (int i = (n + 3) / 2; i < n; i++) {
        if (s[i] != s[n - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
#define Mod 1000000007
#define N 17
int a[N],f[N][1<<N],pw[1<<N],ni[1<<N],n,m,i,mask,j;
inline int qmi(int di,int zhi)
{
	int ret=1,x=di;
	while (zhi){
		if (zhi&1) ret=1LL*ret*x%Mod;x=1LL*x*x%Mod;zhi>>=1;
	}return ret;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++) scanf("%d",&a[i]);a[0]=1;
	f[0][0]=(n&1)?(-1):1;
	pw[0]=1;
	for (mask=1;mask<=(1<<n);mask++) pw[mask]=1LL*pw[mask-1]*mask%Mod;
	ni[(1<<n)]=qmi(pw[(1<<n)],Mod-2);
	for (mask=(1<<n);mask>=1;mask--) ni[mask-1]=1LL*ni[mask]*mask%Mod;
	for (mask=1;mask<(1<<n);mask++) f[0][mask]=-f[0][mask-(mask&(-mask))];
	for (i=1;i<=m;i++){
		for (mask=0;mask<(1<<n);mask++) if (mask-a[i]+2>=0) f[i-1][mask]=1LL*f[i-1][mask]*pw[mask-a[i-1]+1]%Mod*ni[mask-a[i]+2]%Mod;
		else f[i-1][mask]=0;
		for (mask=0;mask<(1<<n);mask++){
			if (mask-a[i]+2>0) f[i][mask]=(1LL*f[i-1][mask]*(mask-a[i]+2)+f[i][mask])%Mod;
			for (j=0;j<n;j++) if (!(mask&(1<<j))) f[i][mask|(1<<j)]=(1LL*f[i-1][mask]*(1<<j)+f[i][mask|(1<<j)])%Mod;
		}
	}int ans=1LL*f[m][(1<<n)-1]*pw[(1<<n)-a[m]]%Mod*qmi(2,n)%Mod;
	printf("%d\n",(ans+Mod)%Mod);
	return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	char a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	if(a==f && b==e && c==d){
		cout<<"YES"<<endl;	
	}else{
		cout<<"NO"<<endl;
	}
	




}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  cout << "ABC" << n << endl;
  return 0;
}


Measured memory_bytes: 256
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,min:Integer;
  l:array of Integer;
  s,s123,s1,s2,s3:string;
  al:string = 'abcdefghijklmnopqrstuvwxyz';
  tf,tfl,tfr:Boolean;
begin
  try
    { TODO -oUser -cConsole メイン : ここにコードを記述してください }
    Readln(s1);
    Readln(s2);
    count:=0;
    max  :=0;
    min  :=100;

    for i:=1 to length(s1) do begin
      s:=s1[length(s1)];
      Delete(s1, length(s1), 1);
      s1:=s+s1;
      if s1=s2 then begin
        Writeln('Yes');
        Readln;
        Exit;
      end;
    end;

    Writeln('No');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


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

int main()
{
    int h, w;
    cin >> h >> w;
    char s[h + 1][w + 1];
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> s[i][j];
            if (s[i][j] == '.')
                s[i][j] = '0';
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] == '#')
            {
                for (int k = i - 1; k <= i + 1; k++)
                {
                    for (int l = j - 1; l <= j + 1; l++)
                    {
                        if (k >= 0 && k < h && l >= 0 && l < w && s[k][l] != '#')
                            s[k][l] += 1;
                    }
                }
            }
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cout << s[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3568
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    a = ILI()
    return (N, a)


def solve(N, a):
    a_lef = a[0: N]
    a_rig = [-i for i in a[2 * N: 3 * N]]
    heapq.heapify(a_lef)
    heapq.heapify(a_rig)
    sum_lef = sum(a_lef)
    sum_rig = sum(a_rig)
    l_sum_lef = [sum_lef]
    l_sum_rig = [sum_rig]
    
    for i in range(1, N + 1):
        heapq.heappush(a_lef, a[N - 1 + i])
        lef_pop = heapq.heappop(a_lef)
        sum_lef += a[N - 1 + i] - lef_pop
        l_sum_lef.append(sum_lef)
        
        heapq.heappush(a_rig, -a[2 * N - i])
        rig_pop = heapq.heappop(a_rig)
        sum_rig += -a[2 * N - i] - rig_pop
        l_sum_rig.append(sum_rig)

    ans = -INF

    for i in range(N + 1):
        num_dif = l_sum_lef[i] + l_sum_rig[N - i]
        ans = max(ans, num_dif)

    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


Measured memory_bytes: 40268
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,k = map(int,input().split())
a = [int(i) for i in input().split()]

def divisorize(fct):
    b, e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]
 
 
def factorize(n):
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
 
 
def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

c = []
fct = factorize(sum(a))
for div in divisorize(fct):
    c.append(num(div))

c.sort(reverse=True)
ans = 1
from heapq import heapify,heappush,heappop

for num in c:
  chk = 0; cnt = 0
  sp = 0
  pl = []; mi = []
  heapify(pl); heapify(mi)
  for j in a:
    m = min(j%num,num-j%num)
    chk += m
    if m == j%num:
      cnt += m
      heappush(pl,-m)
    else:
      cnt -= m
      heappush(mi,-m)
  
  if cnt != 0:
    for i in range(abs(cnt)//num):
      if cnt > 0 and pl!=[]:
        p = heappop(pl)
        chk += (num+2*p)
      elif cnt < 0 and mi!=[]:
        q = heappop(mi)
        chk += (num+2*q)
        
  if chk <= 2*k:
    ans = num
    break
    
print(ans)

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

ll n,w,W,V,val,sum,weight,maxi;
ll wt[101],v[101],dp[101][100001];
#define inf ll(1e13)
main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>W;
	
	for(int i=1;i<=n;i++)
	{
		cin>>wt[i]>>v[i];
		maxi+=v[i];
	}
	
	for(ll i=1;i<=n;i++)
	{
		sum+=v[i];
		weight+=wt[i];
		for(ll j=maxi;j>=1;j--)
		{
			if(j>sum)
				dp[i][j]=inf;
			else if(i==1)
				dp[i][j]=wt[1];
			else if(j<=sum)
			{
				dp[i][j]=min(wt[i]+dp[i-1][j-v[i]],dp[i-1][j]);
			}
		}
	}
	
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=maxi;j++)
		{
			if(dp[i][j]<=W)
			{
				ans=max(ans,j);
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 78336
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b)
		cout << "Draw" << endl;
	else if (a == 1)
		cout << "Alice" << endl;
	else if (b == 1)
		cout << "Bob" << endl;
	else if (a > b)
		cout << "Alice" << endl;
	else
		cout << "Bob" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
    long long A,B,C,K;
    cin >> A >> B >> C >> K;

    if(K <= A) {
        cout << K << endl;
        return 0;
    }
    if(K <= (A+B)) {
        cout << A << endl;
        return 0;
    }

    long long tmp = 0;
    tmp = K - (A + B);
    cout << A - tmp << endl;
}

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

struct UnionFind{
    vector<int> par;
    int cnt;
    UnionFind(int n) : par(n, -1), cnt(n) {}
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x != y){
            if(par[y] < par[x]) swap(x, y);
            par[x] += par[y]; par[y] = x; cnt--;
        }
    }
    int find(int x){
        return par[x] < 0 ? x : par[x] = find(par[x]);
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return -par[find(x)];
    }
    int size(){
        return cnt;
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    UnionFind uf(n);
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    vector<ll> v;
    ll t = uf.size();
    ll sum = t * (t - 1) / 2;
    for(int i = m - 1; i >= 0; i--){
        v.push_back(sum);
        if(uf.same(a[i], b[i])) continue;
        ll a1 = uf.size(a[i]), b1 = uf.size(b[i]);
        sum -= a1 * b1;
        uf.unite(a[i], b[i]);
    }
    reverse(v.begin(), v.end());
    for(int i = 0; i < m; i++){
        cout << v[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3444
#include <iostream>     
#include <vector>       
#include <algorithm>    
using namespace std;    
#define rep(i,n) for(int i=0;i<(n);i++)                       
 
int main() {            
  int n; 
  cin >> n;             
  string s;             
  cin >> s; 
  int count = 0;        
  rep(i,n-2){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C' )++count;
  }
  cout << count << endl;
}                                                                                                    
 
 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), std::greater<char>());
    cout << (s < t ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   string s,t;
   cin>>s>>t;
   int n=s.size();
   int m=t.size();
   int dp[n+1][m+1];
   memset(dp,0,sizeof(dp));
   for(int i=0;i<=n;i++){
       for(int j=0;j<=m;j++){
           if(i==0 || j==0)
           dp[i][j]=0;
           else  if(s[i-1]==t[j-1])
           dp[i][j]=dp[i-1][j-1]+1;
           else
           dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
           
       }
   }
 //  cout<<dp[n][m];
  int index=dp[n][m];
  char c[index+1];
  c[index]='\0';
  int i=n,j=m;
  while(i> 0 && j>0){
      if(s[i-1]==t[j-1]){
          c[index-1]=s[i-1];
          i--;
          j--;
          index--;
      }
      else if(dp[i-1][j]>dp[i][j-1])
      i--;
      else
      j--;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 35456
s=input()
nn=s.split()
n=int(nn[0])
m=int(nn[1])
s=input()
aa=s.split()
a=[]
tot=0
for i in range(0,len(aa)):
	a.append(int(aa[i]))
	tot+=a[i]
num=0
for i in a:
	if i>=tot/(4*m) :
		num+=1
if num>=m :
	print('Yes')
else:
	print('No')


Measured memory_bytes: 3064
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int,input().split())
uf = UnionFind(n)
for _ in range(m):
  a,b = map(int,input().split())
  uf.union(a-1,b-1)
print(uf.group_count()-1)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, m; cin>>n>>m;
    vector<pi> P(n);
    rep(i, n) cin>>P[i].se>>P[i].fi;
	sort(all(P), [](pi &p1, pi &p2){return p1.se < p2.se;});

	ll ans = 0;
	int idx = 0;
	priority_queue<pi> q;
    for(int i=1; i<=m; i++){
		while(P[idx].se<=i && idx<P.size()){
			q.push(P[idx++]);
		}
		int cost, score;
		if (q.empty()) continue;
		tie(score, cost) = q.top(); q.pop();
		ans += score;
    }
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, a, n) for ( i = a; i < (n); i++)
#define fill(a,v)                    memset(a, v, sizeof(a))
#define sz(a)                       ((int)(a.size()))
#define x first
#define y second
#define mp make_pair
#define pb push_back
using namespace std;
vector <ll> edges[100005]; 
ll dp[100005]={};
ll visited[100005]={};

ll dfs(ll i){
	visited[i]=1;
	
	 ll j;
	rep(j,0,sz(edges[i])){
		if(!visited[edges[i][j]])
			dfs(edges[i][j]);
		dp[i]= max(dp[i],1+dp[edges[i][j]]);
	}
	
	

}
int main(){
	fast;
	ll i,j,W,k,tc,q,m,n,flag;	
	cin>>n>>m;

	rep(i,0,m){
		cin >> j >> k;
		edges[j].pb(k);
	}
	rep(i,1,n+1){
		if(!visited[i])
			dfs(i);
	}
	// dfs(1);
	ll maxx=0;
	rep(i,1,n+1){
		maxx=max(maxx,dp[i]);
		// cout<<dp[i]<<" ";
	}
	cout<<maxx;


}


Measured memory_bytes: 9344
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	string S=in<string>();
	int N=S.size();
	vector<vector<int>> dp(N+1,vector<int>(13,0));
	dp[0][0]=1;

	REP(i,N){
		if(S[i]=='?'){
			REP(j,13){
				REP(k,10){
					dp[i+1][(j*10+k)%13] += dp[i][j];
					dp[i+1][(j*10+k)%13] %= atcoder_mod;
				}
			}
		}
		else{
			REP(j,13){
				dp[i+1][(j*10+(S[i]-'0'))%13] += dp[i][j];
				dp[i+1][(j*10+(S[i]-'0'))%13] %= atcoder_mod;
			}
		}
	}
	out(dp[N][5]);

	return 0;
}


Measured memory_bytes: 8912