akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

//BFS解答
int main(){
    int n, m; cin >> n >> m;

    vector<vector<bool>> g(n, vector<bool> (n,false));
    vector<P> edge(m);

    //隣接グラフの作成。
    rep(i,m){
        cin >> edge[i].first >> edge[i].second;
        edge[i].first--; edge[i].second--;

        g[edge[i].first][edge[i].second] = true;
    }

    int ans = 0;

    rep(k,m){
        g[edge[k].first][edge[k].second] = false;

        vector<int> dist(n,1002003004);
        queue<int> q;

        auto push = [&] (int v, int d){
            if(dist[v] != 1002003004) return;
            dist[v] = d;
            q.push(v);
        };

        push(0,0);
        while(!q.empty()){
            int v = q.front(); q.pop();
            int d = dist[v];

            rep(j,n){
                if(g[v][j]) push(j,d);
                if(g[j][v]) push(j,d);
            }

        }

        rep(j,n){
            if(dist[j] != 0){
                ans++;
                break;
            }
        }


        g[edge[k].first][edge[k].second] = true;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

const int MOD = 1e9 + 7;

long long mod_pow(long long a, long long b, long long p = MOD) { // = (a^b) % p //((a^-1) % p) = (a^(p-2)) % p;
	long long res = 1;
	a %= p;

	while (b > 0) {
		if ((b & 1) == 1) res = ((res % p) * (a % p)) % p;
		a = ((a % p) * (a % p)) % p;
		b >>= 1;
	}
	return res;
}

long long  C(long long  n, long long  r) {
	//n!/r!(n-r)!
	cerr << n << " " << r << endl;
	r = max(r, n - r);
	long long  num = 1, den = 1;
	for (int i = r + 1; i <= n; i++) num = (num % MOD * i % MOD) % MOD;
	for (int j = 1; j <= n - r; j++) den = (den % MOD * j % MOD) % MOD;

	return (num % MOD * mod_pow(den, MOD - 2)) % MOD;
}

int main() {

	long long  n, a, b; cin >> n >> a >> b;
	long long  res = ((C(n, a) + C(n, b)) % MOD + 1) % MOD;

	cout << (mod_pow(2, n) - res + MOD) % MOD;

	return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

intt x, k, d;

int main() {

	FAST;

	cin >> x >> k >> d;
	// most importantly
	x = abs(x);
	intt steps = x / d;
	if (k <= steps) {
		cout << x - k * d << '\n';
	}
	else {
		intt kk = k - steps;
		if (kk % 2 == 0) cout << x - steps * d << '\n';
		else cout << d - (x - steps * d) << '\n';
	}
	return 0;
}

Measured memory_bytes: 3636
import math
a,b,h,m=list(map(int, input().split()))


th_a = 360/12 * h + 360/12*m/60
th_b = 360*m/60

ab_th = abs(th_a - th_b)
if ab_th > 180:
    ab_th = 360 - ab_th

print(math.sqrt(a*a + b*b -2*a*b*math.cos(math.radians(ab_th))))

Measured memory_bytes: 9516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    string x;
    while(1){
        int sum=0;
        cin>>x;
        if(x=="0") break;
        for(int i=0;i<x.size();i++) sum+=x[i]-'0';
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 3220
N,X=map(int,input().split())
A=list(map(int,input().split()))
B=[]
for i in range(N):
    B.append(abs(A[i]-X))


a=B[0]

for j in range(1,N):
    b=B[j]
    if b<a:
        a,b=b,a
    while b!=0:
        a,b=b,a%b
print(a)

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	
	int n;cin >> n;
	REP(i,100){
		REP(j,100){
			if(i*4+j*7==n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	
	return 0;
}


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

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
  
int main(){
  int N, P; string S;
  cin >> N >> P >> S;
  if(N==1){
    if(ctoi(S[0])%P==0){
      cout << 1 << endl;
      return 0;
    }
    else cout << 0 << endl;
    return 0;
  }
  int64_t ans=0;
  if(P==2 || P==5){
    for(int i=0;i<N;i++){
      if(ctoi(S[i])%P==0){
        ans+=i+1;
      }
    }
    cout << ans << endl;
    return 0;
  }
  int now=1;
  vector<int> A(N);
  A[0]=1;
  for(int i=1;i<N;i++){
    now*=10;
    now%=P;
    A[i]=now;
  }
  now=0;
  vector<int64_t> Q(P);
  Q[0]=1;
  for(int i=N-1;i>=0;i--){
    now+=ctoi(S[i])*A[N-1-i];
    now%=P;
    Q[now]++;
  }
  for(int i=0;i<P;i++){
    ans+=(Q[i]*(Q[i]-1))/2;
  }
  cout << ans << endl;
  return 0;
}
      

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

int main() {
    int N, M, ans=0, bridge=0;
    cin >> N >> M;
    vector<pair<int, int>> a(M);

    for(int i=0; i<M; i++)
	cin >> a[i].second >> a[i].first;

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

    for(int i=0; i<M; i++){
	int left=a[i].second, right=a[i].first;
	if(left<=bridge){
	}
	else{
	    bridge = right-1;
	    ans++;

	}
    }




    cout << ans << endl;
} 




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

int main(){

    ll n, W, val=0; cin >> n >> W;
    vector< ll > w(n+1), v(n+1);
    for(int i=1; i<=n; i++)
        cin >> w[i] >> v[i], val += v[i];

    vector< vector<ll> > dp;
    dp.assign(n+1, vector<ll>(val+1,1e12));

    for(int i=0; i<=n; i++) dp[i][0] = 0;
    for(int i=1; i<=n; i++)
    for(int j=1; j<=val; j++){
        dp[i][j] = dp[i-1][j];
        if(j>=v[i])
            dp[i][j] = min(dp[i][j], w[i]+dp[i-1][j-v[i]]);
    }ll ans = 0;
    for(int i=1; i<=val; i++)
        if(dp[n][i] <= W)
            ans = i;
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 83052
import sys
from collections import defaultdict
from heapq import heappush, heappop
def input(): return sys.stdin.readline().strip()


def main():
    """
    ６のべき乗しか引き出せない部分問題を考える。
    このとき最適な支払方法は、当然大きい金額を序盤に一気に下ろすこと。
    なのでN円をi円と(N - i)円に分けて片方を6のべき、もう片方を９のべきで支払って
    その合計を見ればよい。

    それぞれの支払い方はすなわち６進数（９進数）展開することに他ならないので
    １円から支払う方法を考えた方が早い。
    """
    N = int(input())
    ans = N
    for i in range(N + 1):
        cnt = 0
        t = i
        while t > 0:
            cnt += t % 6
            t //= 6
        t = N - i
        while t > 0:
            cnt += t % 9
            t //= 9
        ans = min(ans, cnt)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73404
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[10];
bool work1()
{
	if(a[3]>1) return false;
	if(a[3]==1&&a[4]>2) return false;
	if(a[3]==0&&a[4]==0) return false;
	return true;
}
bool work2()
{
	if(a[1]>1) return false;
	if(a[1]==1&&a[2]>2) return false;
	if(a[1]==0&&a[2]==0) return false;
	return true;
}
int main ()
{
	for(int i=1;i<=4;i++)
		scanf("%1d",&a[i]);
	int f1=work1();
	int f2=work2();
	if(f1==1&&f2==0) cout<<"YYMM"<<endl;
	else if(f1==0&&f2==1) cout<<"MMYY"<<endl;
	else if(f1==1&&f2==1) cout<<"AMBIGUOUS"<<endl;
	else cout<<"NA"<<endl; 
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (w, h, x, y) = readLine()!!.split(" ").map{ it.toDouble()}
    val a = if( w / x == 2.0 && h / y == 2.0 ) 1 else 0
    println( (w * h / 2.0).toString() + " "  + a )
}


Measured memory_bytes: 36012
use proconio::input;

fn main() -> Result<(), ()> {
    input! {
        n: usize,
        mut a: [usize; n]
    }
    a.sort();
    let mut d = vec![true; *a.last().unwrap() + 1];
    let mut r = 0;
    for (i, &x) in a.iter().enumerate() {
        if d[x] {
            if i > 0 && a[i - 1] == x {
                d[x] = false;
                r -= 1;
            } else {
                for f in d.iter_mut().skip(2 * x).step_by(x) {
                    *f = false;
                }
                r += 1;
            }
        }
    }
    println!("{}", r);

    Ok(())
}


Measured memory_bytes: 5904
#include <bits/stdc++.h>
#define mod  1000000007
using namespace std;

int pathCount(vector < vector < char > > &grid) {
  int rows = grid.size();
  int cols = grid[0].size();

  vector < vector < int > >dp(rows, vector < int >(cols, 0));

  for (int i = 1; i < rows; i++){
    if (grid[i][0] == '#') {
      break;
    }
    dp[i][0] = 1;
  }

  for (int j = 1; j < cols; j++) {
    if (grid[0][j] == '#') {
      break;
    }
    dp[0][j] = 1;
  }

  for (int i = 1; i < rows; i++) {
    for (int j = 1; j < cols; j++) {
      if(grid[i][j] == '#') {
        continue;
      }

      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
    }
  }

  return dp[rows - 1][cols - 1];

}

int main() {
  int rows;
  cin>>rows;
  int cols;
  cin>>cols;
  vector < vector < char > > grid(rows, vector < char >(cols, '.'));
  for (int i = 0; i < rows; i++) {
    for (int j = 0; j < cols; j++) {
      cin>>grid[i][j];
    }
  }

  cout<<pathCount(grid)<<endl;

  return 0;
}


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

int main() {
  int x,y;
  cin>>x>>y;
  int ans=0;
  if (x>y) {
    ans=min(abs(x+y)+1,abs(x-y)+2);
  }
  if (x<y) {
    ans=min(abs(x+y)+1,abs(x-y));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  P p[N];
  rep(i,N){
    int a;
    cin >> a;
    p[i] = P(a, i+1);
  }
  sort(p, p+N);
  reverse(p, p+N);
  multiset<int> vec;
  vec.insert(0);
  vec.insert(0);
  vec.insert(N+1);
  vec.insert(N+1);
  int ans = 0;
  for(int i=0;i<N;i++){
    int id = p[i].second;
    auto itr = vec.lower_bound(id);
    int R1 = *itr++;
    int R2 = *itr--;
    itr--;
    int L2 = *itr--;
    int L1 = *itr;
    ans += p[i].first * (id-L2) * (R2-R1);
    ans += p[i].first * (L2-L1) * (R1-id);
    vec.insert(id);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6528
#include "bits/stdc++.h"
#define MAXN 200009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
void fail(){
	puts("-1");
	exit(0);
}
int arr[MAXN];
int main(){
    //~ freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
		scanf("%d",arr+i);
	for(int i=1;i<=n;i++)
		if(arr[i]>i-1)
			fail();
	ll ans=0;	
	for(int i=2;i<=n;i++){
		if(arr[i-1]<arr[i]){
			if(arr[i]-arr[i-1]>1)
				fail();
			ans++;	
		}
		else
			ans+=arr[i];
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
/*
               ██████  ██████
               ██   ██ ██   ██
 Author ->     ██████  ██   ██
               ██      ██   ██
               ██      ██████
 
        nik is love.
        nik is motivation.
        Ek modulus aapki jindagi barbaad kar sakti hai
        Watch for integer overflows.
        A dream doesn't become reality through magic; it takes sweat, determination and hard work" — Colin Powell
 */
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional>
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define eps                   0.000000001
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair<ll,ll>
#define endl                 '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> special_map;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
const ll inf=1000000007;
vector<ll> vis(200010,0),par(200010,0),dis(200010,inf),di(200010,0),fin(200010,0);
vector<ll> adj[200010];
int myrandom (int i) { return std::rand()%i;}
const int MAX=1e9;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    //clock_t launch=clock();
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n+1;i++)
    {
        ll mini=(i*(i-1))/2;
        ll maxi=(n*(n+1))/2-((n-i)*(n-i+1))/2;
        ll tot=maxi-mini+1;
        ans=(ans+tot)%inf;
    }
    cout<<ans<<endl;
    //clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


Measured memory_bytes: 15900
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


void solve() {
    ll i,j,k,l,r,x,y; string s;
    ll n;
    bool exit = false;
    cin>>n;
    vector<ll> v1,v2;
    FOR(i,n/2){
        ll input;
        cin>>input;
        v1.push_back(input);
        cin>>input;
        v2.push_back(input);
    }
    if(n%2==1){
        ll input;
        cin>>input;
        v1.push_back(input);
    }
    //FORR(i,v2) cout<<i<<endl;
    map<ll,ll> countMap1,countMap2;//first:element second:count
    for (auto & elem : v1){
        auto result = countMap1.insert(pair<ll,ll>(elem,1));
        if(result.second == false)
            result.first -> second++;
    }
    for (auto & elem : v2){
        auto result = countMap2.insert(pair<ll,ll>(elem,1));
        if(result.second == false)
            result.first -> second++;
    }
    pair<ll,ll> maxFreq1(-1,0);
    pair<ll,ll> maxFreq2(-1,0);
    for(auto & elem: countMap1){
        //std::cout << elem.first << " :: " << elem.second << std::endl;
        if(elem.second>maxFreq1.second){
            maxFreq1=elem;
        }
    }

    for(auto & elem: countMap2){
        //std::cout << elem.first << " :: " << elem.second << std::endl;
        if(elem.second>maxFreq2.second){
            maxFreq2=elem;
        }
    }
    if(maxFreq1.first != maxFreq2.first){
        cout<<n-maxFreq1.second-maxFreq2.second<<endl;
        return;
    }else{
        pair<ll,ll> temp1,temp2;
        temp1 = maxFreq1;
        temp2 = maxFreq2;
        maxFreq1.first=-1;
        maxFreq1.second=0;
        maxFreq2.first=-1;
        maxFreq2.second=0;
        for(auto & elem: countMap1){
        //std::cout << elem.first << " :: " << elem.second << std::endl;
            if(elem.second>maxFreq1.second && elem.first!=temp1.first){
                maxFreq1=elem;
            }
        }

        for(auto & elem: countMap2){
        //std::cout << elem.first << " :: " << elem.second << std::endl;
            if(elem.second>maxFreq2.second && elem.first!=temp2.first){
                maxFreq2=elem;
            }
        }
        cout<<n-max(temp1.second+maxFreq2.second, temp2.second+maxFreq1.second)<<endl;
    }
    /*cin>>N;
    vector<ll> V;
    FOR(x,N+1) {
            FOR(y,N+1) {
                    ll ret=1;
                    FOR(i,x) ret*=2;
                    FOR(i,y) ret*=5;
                    V.push_back(ret);
            }
    }
    sort(ALL(V));
    FORR(v,V) cout<<v<<endl;*/
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}



Measured memory_bytes: 7284
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int D;
int c[26];
int s[365][26];
int selected[365];
int scores[26];

int calculateScore(int t){
    int retVal = 0;
    int last = -1;
    for(int i=0;i<D;i++){
        if(selected[i] == t){
            last = i;
            retVal += s[i][t];
        }else{
            retVal -= c[t] * (i-last);
        }
    }
    return retVal;
}


int main() {
    clock_t start = clock();
    cin >> D;
    for(int i=0;i<26;i++){
        cin >> c[i];
    }
    for(int i=0;i<D;i++)for(int j=0;j<26;j++){
        cin >> s[i][j];
    }

    
    for(int i=0;i<D;i++){
        int maxNum =-(1e7);
        int maxArg = 0;
        for(int j=0;j<26;j++){
            if(s[i][j] -c[j]*(D/26) > maxNum){
                maxNum = s[i][j] -c[j]*(D/26);
                maxArg = j;
            }
        }
        selected[i] = maxArg;
    }
    for(int i=0;i<26;i++){
        scores[i] = calculateScore(i);
    }
    int itr = 1;
    while(clock()-start<(CLOCKS_PER_SEC*2- 100000)){
        // cerr <<"itr =" << itr <<"\n";
        itr++;
        int q = rand()%26;
        int t = rand()%D;
        int oldq = selected[t];
        int oldscore = scores[oldq] + scores[q];
        selected[t] = q;
        int newScore = calculateScore(oldq) + calculateScore(q);
        // cerr <<"oldScore=" << oldscore <<"newScore=" << newScore << "\n";
        if(newScore <oldscore){
            selected[t] = oldq;
        }
    }
    for(int i=0;i<D;i++){
        cout << selected[i]+1 <<"\n";
    }
    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int MAXN = 1e6 + 6;
constexpr int INF = 1e9 + 7;
int n;
int dp[MAXN];

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

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

    dp[0] = 0;
    for (int i = 0; i <= n; ++i) {
        for (int j = 1; i + j <= n; j *= 6) {
            dp[i + j] = min(dp[i + j], 1 + dp[i]);
        }

        for (int j = 1; i + j <= n; j *= 9) {
            dp[i + j] = min(dp[i + j], 1 + dp[i]);
        }
    }

    printf("%d\n", dp[n]);
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

// アカウント間違えて提出しました　ごめんなさい

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> v(4);
    for(int i = 0; i < 4; i++) {
        cin >> v[i];
    }
    int ans = INF;
    for(int i = 0; i < 4; i++) {
        for(int j = i + 1; j < 4; j++) {
            vector<bool> used(4, 0);
            used[i] = used[j] = 1;
            int sum1 = v[i] + v[j];
            int sum2 = accumulate(ALL(v), 0) - sum1;
            chmin(ans, abs(sum1 - sum2));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3212
mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line().split_whitespace().map(|s| s.to_string()).collect()
    }

    pub struct Reader {
        buf: VecDeque<String>
    }

    impl Reader {
        pub fn new() -> Reader {
            Reader {buf: VecDeque::new()}
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T where T: FromStr, T::Err: Debug {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }

        pub fn nextN<T>(&mut self, n: usize) -> Vec<T> where T: FromStr, T::Err: Debug {
            let mut vec: Vec<T> = Vec::with_capacity(n);
            for i in 0..n {
                vec.push(self.next());
            }
            vec
        }
    }
}

mod data {
    pub struct UnionFind {
        root : Vec<usize>
    }

    impl UnionFind {
        pub fn new(size : usize) -> UnionFind {
            UnionFind {root : (0..size).collect()}
        }

        pub fn find(&mut self, x : usize) -> usize {
            let xroot = self.root[x];
            if x != xroot {
                self.root[x] = self.find(xroot);
            }
            self.root[x]
        }

        pub fn unite(&mut self, x : usize, y : usize) {
            let xroot = self.find(x);
            self.root[xroot] = self.find(y);
        }

        pub fn same(&mut self, x : usize, y : usize) -> bool {
            self.find(x) == self.find(y)
        }
    }
}

fn with_large_stack(func : fn() -> ()) {
    use std::thread::Builder;
    let builder = Builder::new();
    let th = builder.stack_size(10000000);

    th.spawn(move || {
        func();
    }).unwrap().join();
}

fn main() {
    with_large_stack(_main);
}

fn _main() {
    let mut reader = reader::Reader::new();

    let a: i32 = reader.next();
    let b: i32 = reader.next();
    if a + b >= 10 {
        println!("error");
    } else {
        println!("{}", a + b);
    }
}

Measured memory_bytes: 8572
#include <stdio.h>
#define MAX 100000
 
int A[MAX], n;
 
int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j] <= x) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}
 
int main(void) {
  int i, q;
 
  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  q = partition(0,n-1);
 
  for(i=0; i<n; i++) {
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");
 
  return 0;
}

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

int las[2][20];
int a[200005];
int n;
long long ans;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        int b = 0;
        for(int j = 0; j < 20; j++){
            if(a[i] >> j & 1){
                las[1][j] = las[0][j];
                las[0][j] = i;
            }
            b = max(b, las[1][j]);
        }
        ans += i-b;
    }
    cout << ans << '\n';
}

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

#define ll long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)

using namespace std;

int main()
{
  int N; cin>>N;
  vector<ll> a(N);
  rep(i,N) cin>>a[i];
  vector<ll> b(N),c(N);
  rep(i,N) b[i] = a[i]+i;
  rep(i,N) c[i] = i-a[i];
  map<ll,int> Map;
  ll ans=0;
  RFOR(i,N-1,1){
    Map[c[i]]++;
    ans+=Map[b[i-1]];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 30680
N = int(input())
a = list(map(int,input().split()))

tmp = [0]*(N)
tmp_N = N

for i in range(N-1,-1,-1):
    tmp_c = 0
    for j in range(i,N,i+1):
        tmp_c += tmp[j]
    if tmp_c%2 == a[i]:
        tmp[i] = 0
    else:
        tmp[i] += 1

ans_c = 0
ans_b = []
for i in range(N):
    if tmp[i] != 0:
        ans_c += 1
        ans_b.append(i+1)
        
print(ans_c)
print(*ans_b)
        

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

using namespace std;

int main() {
    while(true) {
        int H, W, N;
        cin >> H >> W >> N;
        if(!H && !W && !N) break;

        vector<vector<int> > v(H, vector<int>(W));
        vector<vector<int> > cnt(H+1, vector<int>(W+1, 0));
        for(int i = 0; i < H; ++i) {
            for(int j = 0; j < W; ++j) {
                cin >> v[i][j];
            }
        }
        cnt[0][0] = N-1;
        for(int i = 0; i < H; ++i) {
            for(int j = 0; j < W; ++j) {
                cnt[i+1][j] += cnt[i][j]/2;
                cnt[i][j+1] += cnt[i][j]/2;
                if(cnt[i][j] & 1) {
                    if(v[i][j] == 0) cnt[i+1][j]++;
                    else cnt[i][j+1]++;

                    v[i][j] ^= 1;
                }
            }
        }
        int i = 0, j = 0;
        while(i < H && j < W) {
            if(v[i][j] == 0) ++i;
            else ++j;
        }
        cout << (i+1) << ' ' << (j+1) << endl;
    }
    return 0;
}

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

using namespace std;

#define sz(a) int(a.size())

vector <int> sw [15];
int main() {
	int n, m;
	cin >> n >> m;

	vector <int> p (m);
	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		sw[i].resize(k);
		for (int &t : sw[i]) {
			cin >> t;
			t--;
		}
	}

	for (int &t : p) cin >> t;

	int ans = 0;
	for (int i = 0; i < (1<<n); i++) {
		vector <int> c (n);
		for (int j = 0; j < n; j++) c[j] = (i&(1<<j)) > 0;

		bool sc = 1;
		for (int j= 0; j < m; j++) {
			int cur = 0;
			for (auto t : sw[j]) cur ^= c[t];
			if (cur != p[j]) {
				sc = 0;
				break;
			}
		}

		if (sc) ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	double t,v,y,n;
	int p;
	while(scanf("%lf",&v) != EOF){
		t=v/9.8;
		y=4.9*t*t;
		p=1;
		n=0;
		while(y > n){
			p++;
			n=5*p-5;
		}
		printf("%d\n",p);
	}
return 0;
}

Measured memory_bytes: 628
n = int(input())
s1 = input()
s2 = input()
ans = 0
mod = 10**9+7

if s1[0] != s2[0]:
    ans = 6
    i = 2
    b = 1
else:
    ans = 3
    i = 1
    b = 0

while i < n:
    if s1[i] != s2[i]:
        i += 2
        if b:
            ans = ans*3%mod
        else:
            ans = ans*2%mod
            b = 1
    else:
        i += 1
        if b:
            b = 0
        else:
            ans = ans*2%mod
print(ans)


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  ll n,k; cin >> n >> k;
  vl h(n);
  rep(i,n)cin>>h[i];
  sort(all(h));
  ll res = L_INF;
  for(int i=0;i+k-1<n;i++){
      res = min(res,h[i+k-1]-h[i]);
  }
    out(res);
}


Measured memory_bytes: 1024
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]

n,h=MI()
a=[]
b=[]
for i in range(n):
    x,y=MI()
    a.append(x)
    b.append(y)
a.sort()
b.sort()
A=a[-1]
for i in range(n):
    if b[i]>=A:
        c=[A]+b[i:]
        break
c=c[::-1]
ans=0
for i in range(len(c)-1):
    ans+=1
    h-=c[i]
    if h<=0:
        break
if h>0:
    ans+=(h+A-1)//A
print(ans)


Measured memory_bytes: 65368
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define mod 1000000007
using namespace std;

int dp[101][100002];
int n;
vector<int> a;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	int k;
	cin>>n>>k;
	a.resize(n);

	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	dp[0][0] = 1;
	for(int i=1;i<=n;++i){
		vector<int> ps(k+1);
		ps[0] = 1;
		for(int j=1;j<=k;++j)
			ps[j] = (dp[i-1][j]+ps[j-1])%mod;
		for(int j=0;j<=k;++j){
			dp[i][j] = ps[j];
			if(j-a[i-1]>0){
				dp[i][j] = (mod-ps[j-a[i-1]-1]+dp[i][j])%mod;
			}
		}
	}
	// for(int i=0;i<=n;++i){
	// 	for(int j=0;j<=k;++j){
	// 		cout<<dp[i][j]<<" \n"[j==k];
	// 	}
	// }
	cout<<dp[n][k];
	// cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	return 0;
}

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

using namespace std;

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

using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int r, d, xx;
    cin >> r >> d >> xx;

    for(int i = 0; i <10; ++i){
        int tmp = r*xx-d;
        ppp(tmp);
        xx = tmp;
    }






    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
v = []
for _ in range(h):
    v.append([0] * w)
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            v[i][j] = '#'
        else:
            c = 0
            if i > 0: c += s[i - 1][j] == '#'
            if j > 0: c += s[i][j - 1] == '#'
            if i < h - 1: c += s[i + 1][j] == '#'
            if j < w - 1: c += s[i][j + 1] == '#'
            if i > 0 and j > 0: c += s[i - 1][j - 1] == '#'
            if i > 0 and j < w - 1: c += s[i - 1][j + 1] == '#'
            if i < h - 1 and j > 0: c += s[i + 1][j - 1] == '#'
            if i < h - 1 and j < w - 1: c += s[i + 1][j + 1] == '#'
            v[i][j] = str(c)
    print(''.join(v[i]))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()

int main() {
  ll a,b,x;
  cin>>a>>b>>x;
  if(a%x==0) cout<<(b/x)-(a/x)+1<<endl;
  else cout<<(b/x)-(a/x)<<endl;
return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;

unsigned n;
vector<vector<unsigned>> e;

unsigned ans = 0;
unsigned solve2(unsigned p, unsigned pre) {
	unsigned first = 0, second = 0;
	for (auto next : e[p]) {
		if (next == pre) continue;
		unsigned d = solve2(next, p);
		second = max(second, min(first, d));
		first = max(first, d);
	}
	ans = max(ans, first + second + 1);
	return first + 1;
}

void solve() {
	cin >> n;
	e.resize(n);
	rep(i, n - 1) {
		unsigned a, b; cin >> a >> b;
		a--; b--;
		e[b].push_back(a);
		e[a].push_back(b);
	}
	ans = max(ans, solve2(0, (unsigned)-1));

	if (ans % 3 == 2) cout << "Second" << endl;
	else cout << "First" << endl;
}

int main() {

	solve();

	return 0;
}



Measured memory_bytes: 23168
#include <bits/stdc++.h>
// e.g. sort(all(a), [](int a1, int a2) { return a1 < a2; });
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

int main() {
  ll x;
  cin >> x;
  // 500円玉
  ll ans = 0;
  ans += x/500 * 1000;
  x = x%500;

  ans += x/5 * 5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import math
n,d=map(int,input().split())
za=[list(map(int,input().split())) for i in range(n)]
ans=0
lon=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(d):
            lon+=(za[i][k]-za[j][k])**2
        else:
            lon=math.sqrt(lon)
            if lon==int(lon):
                ans+=1
            lon=0
print(ans)

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

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif

    string s1, s2;
    cin >> s1 >> s2;
    int cnt = 0 ;
    for(int i=0; i<3; i++)
        cnt += s1[i] == s2[i];
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

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

using namespace std;

int main(){
	int n,T,e; scanf("%d%d%d",&n,&T,&e);
	rep(i,n){
		int x; scanf("%d",&x);
		for(int k=1;k<10000;k++) if(T-e<=k*x && k*x<=T+e){ printf("%d\n",i+1); return 0; }
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define all( X ) ( X ).begin(), ( X ).end()

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	bool is_visited = false;
} node;
typedef struct {
	int to;
	int cost;
	P <int, int> change;
} edge;

int main(){
	ll money = 1000, stock = 0;
	int N; cin >> N;
	vector <int> vec( N );
	rep( i, 0, N ) cin >> vec[ i ];
	rep( i, 0, N - 1 ){
		if (vec[ i ] < vec[ i + 1 ]){
			stock += money / vec[ i ];
			money %= vec[ i ];
			money += stock * vec[ i + 1 ];
			stock = 0;
		}
	}
	cout << money << endl;

}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 3648
import Control.Monad (forM)

shuffle :: Int -> String -> String
shuffle n cards = shuffle' n (length cards) (cards++cards)
  where
      shuffle' :: Int -> Int -> String -> String
      shuffle' 0 0 _      = []
      shuffle' 0 m (x:xs) = x:(shuffle' 0 (m-1) xs)
      shuffle' n m (x:xs) = shuffle' (n - 1) m xs

main :: IO ()
main = do
    cards <- getLine
    if cards == "-" then return ()
    else do
        m <- getLine >>= return . (\n -> read n :: Int)
        n <- (forM [1..m] $ \_ -> getLine) >>= return . map (\n -> read n :: Int)
        putStrLn $ shuffles n cards
        main
  where
      shuffles :: [Int] -> String -> String
      shuffles []     cards = cards
      shuffles (x:xs) cards = shuffles xs $ shuffle x cards


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

int main() {
    int N;
    cin >> N;
    vector<int> A;
    map<int, int> number;
    int temp;
    for (int i = 0; i < N; ++i) {
        cin >> temp;
        A.push_back(temp);
        number[temp] += 1;
    }
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    int ans = 0;
    for (int i = 0; i < A.size(); ++i) {
        if(number[A[i]] % 2 == 1) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5368
#include <cmath>
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
using namespace std;

int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if (x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


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

#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define print_upto(a,n)        for(int i=0;i<n;i++)    cout<<a[i]<<" "; cout<<endl
#define take(x,n)           for(int i=0;i<n;i++)  cin>>x[i];

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"

#define ll long long
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"

#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod 1000000007

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll, ll> pll;
typedef map< ll, ll> mll;

ll fast_mod_exp(ll a, ll b, ll m) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % m;

		a = (a * a) % m;
		b = b >> 1;
	}

	return res;
}

int main() {

	// Use ctrl+shift+b ( second option )
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
#endif

	ll n;
	cin >> n;

	ll m = 1000000007;

	ll v1 = fast_mod_exp(10, n, m);
	ll v2 = fast_mod_exp(9, n, m);
	ll v3 = fast_mod_exp(8, n, m);

	ll ans = (v1 + v3 - v2 + m) % m;
	ans = (ans - v2 + m) % m;

	if (n == 1)
		cout << "0" << nl;
	else if (n == 2)
		cout << "2" << nl;
	else
		cout << ans << nl;

	return 0;
}


Measured memory_bytes: 3640
S=input()
Q=int(input())
lst=[]
for _ in range(Q):
    lst.append(input().split())

import collections

str=list(S)
d=collections.deque(str)

right=True
for operation in lst:
    if operation[0]=='1':
       right=not right

    else:
        if right==True and operation[1]=='1' or right==False and operation[1]=='2':
            d.appendleft(operation[2])
        else:
            d.append(operation[2])
str=list(d)
if right==True:
    print(''.join(str))
else:
    print(''.join(str[::-1]))

Measured memory_bytes: 117720
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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 argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<double> a(n);
  rep(i,n) cin >> a[i];
  double ans=0;
  rep(i,n){
    double tmp=1/a[i];
    ans+=tmp;
  }
  cout << 1/ans << endl;

  return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main()
{
    int h, w, m;
    cin >> h >> w >> m;
    vector<int> vh(h);
    vector<int> vw(w);
    vector<pair<int, int>> vpii;
    REP(i, m)
    {
        int y, x;
        cin >> y >> x;
        y--;
        x--;
        vh[y]++;
        vw[x]++;
        vpii.push_back({ y, x });
    }

    int hmax = -1;
    set<int> sh;
    REP(i, h)
    {
        if (hmax < vh[i]) {
            sh.clear();
            sh.insert(i);
            hmax = vh[i];
        } else if (hmax == vh[i]) {
            sh.insert(i);
        }
    }
    int wmax = -1;
    set<int> sw;
    REP(i, w)
    {
        if (wmax < vw[i]) {
            sw.clear();
            sw.insert(i);
            wmax = vw[i];
        } else if (wmax == vw[i]) {
            sw.insert(i);
        }
    }
    int ans = hmax + wmax;
    int ccnt = 0;
    REP(i, m)
    {
        if (sh.find(vpii[i].first) != sh.end() && sw.find(vpii[i].second) != sw.end()) {
            ccnt++;
        }
    }
    if ((ll)sh.size() * (ll)sw.size() == ccnt)
        ans--;
    cout << ans << endl;
}


Measured memory_bytes: 36168
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <iomanip>

using namespace std;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
#define INF 1 << 30;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<ll, ll> pll;

vector<pair<ll, ll>> pF;


int main(){
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> bs(M);
    rep(i, M){
        cin >> bs[i];
    }
    int ans = 0;

    rep(i, N){
        int tmp = 0;
        rep(i, M){
            int a;
            cin >> a;
            tmp += a * bs[i];
        }
        tmp += C;
        if(tmp > 0){
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int sum = 0;
    for(int i = 0;i < m; i++){
        sum += a[i];
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3600
from collections import defaultdict
d=set()
a=defaultdict(list)
n = int(input())
for i in range(n):
    h,m=list(map(int,input().split()))
    a[m].append(h)
    d.add(m)
t=0
r=0

for i in sorted(d):
    for j in a[i]:
        t+=j
    if t>i:
        r=1
        break
if r==1:
    print('No')
else:
    print('Yes')

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); 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)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K; cin>>N>>K;
    vi a(N);
    rep(i,N) cin>>a[i];
    rep(i,N) a[i]--;
    int cur=0;
    while(K){
        vi next(N);
        if (K&1) cur=a[cur];
        rep(i,N) next[i]=a[a[i]];
        a.swap(next);
        K>>=1;
    }
    cout<<cur+1<<"\n";
    return 0;
}


Measured memory_bytes: 4784
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;


int main(){

  int a[100];
  while(1){
    fill(a,a+100,0);
    //rep(i,100) printf("%d\n",a[i]);
    int n,p;
    scanf("%d%d",&n,&p);
    if(n==0) break;
    int wan=p;
    int now=0;
    int mama=false;
    while(1){
      rep(i,n){
        if(a[i]==p){ printf("%d\n",i); mama=true;}
      }
      if(mama) break;
      if(wan!=0){
        a[now]++;
        wan--;
      }
      else{
        wan=a[now];
        a[now]=0;
      }
      if(now==n-1) now=0;
      else now++;
    }
  }

  return 0;

}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
  string T;
  T="Yes";
    int len = S.size();
    for(int i = 0; i < (len-1)/2; i++){
        if(S.at(i) != S.at(((len-2)/2)-i) || S.at(i) != S.at(len-1-i)) {
          T="No";
          cout << "No" << endl;
          break;
        }
    }
      if(T=="Yes"){
       cout << "Yes" << endl;
}
         }


Measured memory_bytes: 256