akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define N 501
#define M 1000000007
using namespace std;
ll a[N][N], v[N],k=0,n;
bool f[N*N];
vector<pair<ll,ll>>temp;
void dfs(int i){
    for(ll j=1; j<=n; ++j)
        if(!a[i][j] && i!=j){
            if(v[j]==-1){ //cout<<i<<" "<<j<<" "<<k<<"\n";
                a[i][j]=a[j][i]=k+1;
                v[j]=v[i]+1;
                for(ll t=1; t<=n; ++t)
                    f[a[j][t]]=1;
                temp.push_back({i,j});
                dfs(j);
            }
            else if((v[j]+v[i])%2==1){//cout<<i<<" "<<j<<" "<<k<<".\n";
                a[i][j]=a[j][i]=k+1;
                for(ll t=1; t<=n; ++t)
                    f[a[j][t]]=1;
                temp.push_back({i,j});
            }
        }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,j,t;
    cin>>n;
    for(i=1; i<=n; ++i){
        for(j=1; j<=n; ++j){
            if(!a[i][j] && i!=j){
                temp.clear();
                for(t=1; t<=n; ++t)
                    v[t]=-1;
                for(t=1; t<=k; ++t)
                    f[t]=0;
                v[i]=0;
                a[i][j]=a[j][i]=k+1;
                //cout<<i<<" "<<j<<" "<<a[i][j]<<";\n";
                v[j]=1;
                dfs(j);
                ll gasit=k+1;
                for(t=1; t<=k && gasit==k+1; ++t)
                    if(!f[t])
                        gasit=t;
                if(gasit==k+1) ++k;
                for(auto it:temp)
                    a[it.f][it.s]=a[it.s][it.f]=gasit;
            }
        }
    }
    for(i=1; i<=n; ++i){
        for(j=i+1; j<=n; ++j)
            cout<<a[i][j]<<" ";
        cout<<"\n";
    }
    return 0;
}


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

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

	int x = 1;

	for(int i=0;i<n;i++) {
		if(x+k<x*2) {
			x += k;
		} else {
			x *= 2;
		}
	}

	cout << x << endl;
}

Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall

h,w=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]
a=[list(map(int,input().split())) for i in range(h)]

d=floyd_warshall(c)
ans=0
for i in range(h):
 for j in range(w):
  num=a[i][j]
  if num!=1 and num!=-1:
   ans+=d[num][1]
print(int(ans))

Measured memory_bytes: 14052
while 1:
	try:
		N,M = map(int,raw_input().split())
		dp = [[0]*(M+1) for i in range(3)]
		for _ in range(N):
			name = raw_input()
			C,V,D,L = map(int,raw_input().split())
			VDL = [V,D,L]
			if C > M:
				continue
			for i in range(3):
				dp[i][C] = max(dp[i][C],VDL[i])
				for j in range(M):
					if dp[i][j]:
						if j+C <= M:
							dp[i][j+C] = max(dp[i][j+C],dp[i][j]+VDL[i])
		print max(max(dp[0]),max(dp[1]),max(dp[2]))
	except:
		break

Measured memory_bytes: 4276
#include <iostream>
#include <cmath>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

int main() {
  string S;
  cin >> S;
  for (int i = 0; i < S.length(); i++) S[i] = 'x';
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 888
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N,M=mis()
    ac = set()
    pe = defaultdict(int)
    for _ in range(M):
        p, S = input().split()
        p = int(p)
        if S == 'AC':
            ac.add(p)
        elif p not in ac:
            pe[p] += 1
    print(len(ac), sum(pe[p] for p in ac))




main()


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

#define ll long long
int main()
{
    int A, B, C, X, cnt = 0;
    cin >> A >> B >> C >> X;
    for (int i = 0; i <= A; i++)
    {
        for (int j = 0; j <= B; j++)
        {
            for (int k = 0; k <= C; k++)
            {
                if (500 * i + 100 * j + 50 * k == X)
                    cnt++;
            }
        }
    }
    cout << cnt << endl;
}

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

#define int long long 

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 998244353;

int qpow(int a,int x) {
    int res=1;
    for(;x;x>>=1,a=1ll*a*a%mod) if(x&1) res=1ll*res*a%mod;
    return res;
}

int fac[maxn],ifac[maxn],n,a,b,k;

void gen() {
    fac[0]=ifac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
    ifac[n]=qpow(fac[n],mod-2);
    for(int i=n-1;i;i--) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}

int c(int a,int b) {return 1ll*fac[a]*ifac[b]%mod*ifac[a-b]%mod;}

signed main() {
    read(n),read(a),read(b),read(k);
    int ans=0;gen();
    for(int i=0;i<=n;i++) {
        int x=k-a*i;
        if(x%b!=0) continue;
        x/=b;if(x>n||x<0) continue;
        ans=(ans+1ll*c(n,i)*c(n,x)%mod)%mod;
    }
    write(ans);
    return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int main(){
  int a,b;

  cin>>a>>b;


  cout<<(a+b)%24;

  return 0;
}


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

using namespace std;
typedef vector<vector<int>> matrix;
typedef vector<int> vec;

matrix matprod( matrix &A, matrix &B, int mod = 1);
matrix matpow( matrix src, int p, int M );
int solve();

int main(void) {
	
	while(solve()){}

	return 0;
}

matrix matprod( matrix &A, matrix &B, int mod ) {

	matrix ret( B.size(), vec( A[0].size(), 0 ) );
	for( int i = 0; i < ret.size(); i++ ) {
		for( int j = 0; j < ret[i].size(); j++ ) {
			for( int k = 0; k < A[i].size(); k++ ) {
				ret[i][j] += A[i][k]*B[k][j];
				ret[i][j] %= mod;
			}
		}
	}

	return ret;

}
matrix matpow( matrix src, int p, int M) {

	//???????´????
	if( p == 0 ) {
		matrix ret(src);
		for( int i = 0; i < ret.size(); i++ ) {
			for( int j = 0; j < ret[i].size(); j++ ) {
				if( i == j ) {
					ret[i][j] = 1;
				} else {
					ret[i][j] = 0;
				}
			}
		}
		return ret;
	}
	if( p == 1 ) { return src; }

	if( p & 1 ) {

		matrix n;
		matrix m(matpow(src,(p-1)/2,M));

		n = matprod(m,m,M);
		return matprod(src,n,M);

	} else {

		matrix m(matpow(src,p/2,M));
		return matprod(m,m,M);

	}

}

int solve() {

	int N,M,A,B,C,T;

	cin >> N >> M >> A >> B >> C >> T;

	if( N == 0 ){ return 0; }

	matrix mat( N, vec(N, 0) );
	matrix ans( N, vec(N, 0) );
	matrix mat2(N, vec(N, 0) );

	vector<int> S(N,0);

	int t[3] = { A, B, C };

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

	for( int i = 0; i < N; i++ ) {
		for( int k = -1; k < 2; k++ ) {
			if( i + k < 0 || i + k >= N ) { continue; }
			mat[i][i+k] = t[k+1];
		}
	}
	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < N; j++ ) {
			mat2[i][j] = S[(i+j)%N];
		}
	}

	mat = matpow( mat, T, M );
	ans = matprod( mat, mat2, M );
	
	for( int i = 0; i < N; i++ ) {
		if( i > 0 ) { cout << " "; }
		cout << ans[i][0];
	}
	
	cout << endl;
	
	return 1;

}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    double H;
    int A;
    cin >> H >> A;
    cout << ceil (H / A) << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
def main3():
    d = deque()
    rd= deque()
    N = int(input().strip())
    for n in input().split():
        if len(rd)%2!=0:
            d.append(n)
            rd.appendleft(n)
        else:
            rd.append(n)
            d.appendleft(n)
    if N % 2 ==0:
        print(*rd)
    else:
        print(*d)

if __name__ == "__main__":
    main3()

Measured memory_bytes: 24516
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define per(i,n) for (int i = (n)-1; i >=0; --i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n,a,b;cin>>n>>a>>b;
    
    puts((b-a)%2==0 ? "Alice":"Borys");
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<P> vecp;
  vector<P> vecn;
  rep(i, n){
    string s;
    cin >> s;
    int ssz=s.size();
    int rnum=0, lnum=0;
    rep(j, ssz){
      if(s[j]=='('){
        lnum++;
      } else {
        if(lnum>0){
          lnum--;
        } else {
          rnum++;
        }
      }
    }
    int rnum2=0, lnum2=0;
    for(int j=ssz-1; j>=0; j--){
      if(s[j]==')'){
        rnum2++;
      } else {
        if(rnum2>0){
          rnum2--;
        } else {
          lnum2++;
        }
      }
    }
    if(lnum2-rnum>=0){
      vecp.push_back(P(rnum, lnum2));
    } else {
      vecn.push_back(P(-lnum2, rnum));
    }

  }
  ssort(vecp);ssort(vecn);
  int psz=vecp.size();
  int nsz=vecn.size();
  int lnow=0;
  rep(i, psz){
    int rnum3=vecp[i].first, lnum3=vecp[i].second;
    if(lnow<rnum3){
      cout <<"No" << endl;
      return 0;
    }
    lnow+=lnum3-rnum3;
  }
  rep(i, nsz){
    int rnum4=vecn[i].second, lnum4=-vecn[i].first;
    if(lnow<rnum4){
      cout <<"No" << endl;
      return 0;
    }
    lnow+=lnum4-rnum4;
  }
  if(lnow==0){
    cout <<"Yes" << endl;
  } else {
    cout <<"No" << endl;
  }
  return 0;
}


Measured memory_bytes: 11236
<?php
        $h;
        $m;
        $s;
        $x;
        $S=fgets(STDIN);
        $h= floor($S/3600);
        $x= floor($S%3600);
        $m=floor($x/60);
        $s= floor($x%60);
        print ($h.':'.$m.':'.$s);
        ?>

Measured memory_bytes: 15264
#include <stdio.h>
#include <stdlib.h>
int asc(const void *a, const void *b){
    return *(int*)a-*(int*)b;
}
int main(void){
    int n,i,ans=1;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    qsort(a,n,sizeof(int),asc);
    for(i=1;i<n;i++){
        if(a[i-1]!=a[i]) ans++;
    }
    printf("%d",ans);
}


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

#define mp make_pair
#define se second
#define fi first
#define pb push_back

using namespace std;

int d[5000][5000];

int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    s = '*' + s;
    t = '*' + t;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            if(s[i] == t[j])
                d[i][j] = d[i - 1][j - 1] + 1;
            else
                d[i][j] = max(d[i - 1][j], d[i][j - 1]);
    int x = n, y = m;
    string ans = "";
    while(x > 0 && 0 < y)
        if(s[x] == t[y]){
            ans += s[x];
            x--;
            y--;
        }else
            if(d[x][y - 1] > d[x - 1][y])
                y--;
            else
                x--;
    reverse(ans.begin(), ans.end());
    cout << ans;
}


Measured memory_bytes: 59264
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define    boost        ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define    nl           "\n"
#define    ll           long long
#define    pb           push_back
#define    mpr          make_pair
#define    fr(i,a,n)    for(ll i=a;i<n;++i)
#define    fr0(i,n)     for(ll i=0;i<n;++i)
#define    pii          pair<int, int>
#define    FO           find_by_order
#define    OK           order_of_key
#define    mem(a)       memset(a,0,sizeof(a))
#define    ff           first
#define    ss           second


typedef tree <
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update >
set_t;


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


template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
	double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
	time_taken *= 1e-9;
	cout << "\nExecuted in: " << fixed
	     << time_taken << setprecision(9);
	cout << " sec";
#endif
}

///----------------------------- | START | --------------------------------------///

/*
	LCS Problem
https://atcoder.jp/contests/dp/tasks/dp_f
*/

const int N = 3e3 + 5;

int dp[N][N];
char path[N][N];
void solve()
{
	string s, t;
	cin >> s >> t;
	int m = s.size(), n = t.size();

	fr(i, 1, m + 1) fr(j, 1, n + 1)
	{
		if (s[i - 1] == t[j - 1])
		{
			dp[i][j] = 1 + dp[i - 1][j - 1];
			path[i][j] = 'x';
		}

		else
		{
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			if (dp[i][j] == dp[i - 1][j])
				path[i][j] = 'd';
			else path[i][j] = 'l';
		}
	}
	string ans;
	int i = m, j = n;
	while (i != 0 && j != 0)
	{
		if (path[i][j] == 'x')
		{
			ans.pb(s[i - 1]);
			i--, j--;
		}
		else if (path[i][j] == 'd')	i--;
		else j--;
	}

	reverse(ans.begin(), ans.end());
	cout << ans << nl;
}




int32_t main()
{
	auto start = chrono::high_resolution_clock::now();
	boost;
	fio();
	int t;
	t = 1;
	//cin >> t;
	while (t--) solve();
	auto end = chrono::high_resolution_clock::now();
	TIME(start, end);
	return 0;
}




Measured memory_bytes: 47640
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {
 
    const lines = input.split('\n')
    const N = lines[0] - 0

    const f = n => n * (n + 1) / 2
    let s = 0
    s = f(N)
    s -= f(Math.floor(N / 3)) * 3
    s -= f(Math.floor(N / 5)) * 5
    s += f(Math.floor(N / 15)) * 15

    console.log(s)

})(input)


Measured memory_bytes: 29564
L = input()
l = len(L)
a = 1
for i in range(l):
    a = 3 * a
    a = a % 1000000007
b = 2
c = 0
j = l-2
while(j >= 0):
    d = 0
    if L[l-1-j] == "0":
        d = 2 * b % 1000000007
    else:
        b = (2 * b) % 1000000007
    c = (3 * c) % 1000000007
    c = (d + c) % 1000000007
    j -= 1
a = (a - c) % 1000000007
print(a)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+9;
struct num{
    int arr[3];
};
bool operator<(num a,num b){
    for(int i=0;i<3;i++){
        if(a.arr[i]!=b.arr[i])return a.arr[i]<b.arr[i];
    }
}
bool operator==(num a,num b){
    for(int i=0;i<3;i++){
        if(a.arr[i]!=b.arr[i])return 0;
    }
    return 1;
}
int main(){
    int a,b,c,d,e,f,g,h;
    ios::sync_with_stdio(0);
    num tmp;
    while(cin>>tmp.arr[0]>>tmp.arr[1]>>tmp.arr[2]){
        g=0;
        sort(tmp.arr,tmp.arr+3);
        a=tmp.arr[0],b=tmp.arr[1],c=tmp.arr[2];
        set<ll> se;
        while(a%2==0&&b%2==0&&c%2==0){
            g++;
            //cout<<a<<' '<<b<<' '<<c<<' '<<se.size()<<endl;
            se.insert(a*(ll)(1e9+1ll)+b);
            e=a/2;f=b/2;d=c/2;
            tmp.arr[0]=f+d;
            tmp.arr[1]=e+d;
            tmp.arr[2]=e+f;
            sort(tmp.arr,tmp.arr+3);
            a=tmp.arr[0],b=tmp.arr[1],c=tmp.arr[2];
            if(se.find(a*(ll)(1e9+1ll)+b)!=se.end()){
                g=-1;
                break;
            }
        }
        cout<<g<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
//BISMILLAHIR RAHMANIR RAHIM
//RABBI ZIDNI ILMA
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define endl "\n"
#define inf (1LL<<61)
#define pi acos(-1)
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(0);cout<< fixed<< setprecision(10);
#define DEBUG(x) cout<<"["<<#x<<": "<<x<<"]\n"
#define DEBUG2(x, y) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]\n"
#define DEBUG3(x, y, z) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]"<<"  ["<<#z<<": "<<z<<"]\n"
#define DEBUG4(x, y, z, k) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]"<<"  ["<<#z<<": "<<z<<"]"<<"  ["<<#k<<": "<<k<<"]\n"

int main()
{
    fastio

    ll n, x, t;
    cin>> n>> x>> t;
    cout<< (n+x-1) / x * t;
}



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

typedef struct
{
        int top;
        int south_side;
        int east_side;
        int west_side;
        int north_side;
        int bottom;
} Dice;

int main()
{
        Dice dice;
        char operation[100];
        int operation_size = 0, count = 0, tmp;

        scanf("%d %d %d %d %d %d", &dice.top, &dice.south_side,
                        &dice.east_side, &dice.west_side, &dice.north_side, &dice.bottom);

        scanf("%s", operation);

        operation_size = strlen( operation );
        while ( count < operation_size )
        {
                if ( operation[count] == 'S' )
                {
                        tmp = dice.south_side;
                        dice.south_side = dice.top;
                        dice.top = dice.north_side;
                        dice.north_side = dice.bottom;
                        dice.bottom = tmp;
                }
                else if ( operation[count] == 'W' )
                {
                        tmp = dice.west_side;
                        dice.west_side = dice.top;
                        dice.top = dice.east_side;
                        dice.east_side = dice.bottom;
                        dice.bottom = tmp;
                }
                else if ( operation[count] == 'N' )
                {
                        tmp = dice.north_side;
                        dice.north_side = dice.top;
                        dice.top = dice.south_side;
                        dice.south_side = dice.bottom;
                        dice.bottom = tmp;
                }
                else if ( operation[count] == 'E' )
                {
                        tmp = dice.east_side;
                        dice.east_side = dice.top;
                        dice.top = dice.west_side;
                        dice.west_side = dice.bottom;
                        dice.bottom = tmp;
                }
                count = count + 1;
        }

        printf("%d\n", dice.top);
        return 0;
}

Measured memory_bytes: 596
n,m=map(int,input().split())
stu=[]
for i in range(n):
    a,b=map(int,input().split())
    stu.append([a,b])
che=[]
for i in range(m):
    a,b=map(int,input().split())
    che.append([a,b])
check=che 
ans=[0]*n 
for i in range(n):
    a,b=stu[i][0],stu[i][1]
    mini=10**433
    ind=-1 
    for j in range(m): 
        c,d=check[j][0],check[j][1]
        if abs(a-c)+abs(d-b)<mini: 
            mini=abs(a-c)+abs(d-b)
            ind=j+1 
    ans[i]=ind 
print(*ans,sep='\n')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
vector<vector<int>> all[11];
int main()
{
	int n,m,q;
	cin>>n>>m>>q;
	vector<int> aa(q),bb(q),cc(q),dd(q);
	for(int i=0;i<q;i++)
	{
		cin>>aa[i]>>bb[i]>>cc[i]>>dd[i];
		aa[i]--;bb[i]--;
	}
	for(int i=1;i<=m;i++)
		all[1].push_back({i});
	for(int i=1;i<n;i++)
	{
		for(auto& v : all[i])
		{
			int tmp = v.back();
			for(int a=tmp;a<=m;a++)
			{
				vector<int> kk = v;
				kk.push_back(a);
				all[i+1].push_back(kk);
			}
		}
	}
	int ans = 0;
	for(auto i : all[n] )
	{
		vector<int> now = i;
		int sum = 0;
		for(int j=0;j<q;j++)
		{
			if(now[bb[j]]-now[aa[j]] == cc[j])
			{
				sum+=dd[j]; 
			}
		}
		ans = max(sum,ans);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 16192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P ,ll> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, k, d = 'A'-'a';
    string s;
    cin >> n >> k >> s;
    s[k-1] -= d;
    cout << s << endl;


    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>
//#include<bits/stdc++.h>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	long long N, K;
	cin >> N >> K;

	long long n = N % K;

	cout << min(n, abs(n - K)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int L;
  int R;
  cin >>L>>R;
  int s =L/2019;
  int t =R/2019;
  if (s!=t){
  cout <<0<<endl;  
  }
  else{
     L%=2019;
  R%=2019;
 vector<int>data(R-L);
    for (int i=L;i<R;i++){
      vector <int>data1(R-i);
    for (int j=i+1;j<R+1;j++){
    data1.at(j-i-1)=j*i%2019;
    }
      sort(data1.begin(),data1.end());
      data.at(i-L)=data1.at(0);
    }
    sort(data.begin(),data.end());
    cout <<data.at(0)<<endl;
  }
}

Measured memory_bytes: 256
def prime_fact(n: int)->list:
    '''n の素因数を返す
    '''
    if n < 2:
        return []

    d = 2
    res = []
    while n > 1 and d * d <= n:
        if n % d == 0:
            res.append(d)
        while n % d == 0:
            n //= d
        d += 1

    if n > 1:
        # n が素数
        res.append(n)

    return res


def gen_primes(n: int)->int:
    '''n まで(n 含む)の素数を返します。
    '''
    if n < 2:
        return []
    primes = [2]

    if n < 3:
        return primes
    primes.append(3)

    def is_prime(n: int)->bool:
        for p in primes:
            if n % p == 0:
                return False
        return True

    # 2,3 以降の素数は 6k+1 あるいは 6k-1
    # の形をしていることを利用して列挙する。
    for k in range((N+1)//6):
        k += 1

        if is_prime(6*k-1):
            primes.append(6*k-1)

        if is_prime(6*k+1):
            primes.append(6*k+1)

    return primes


def gcd(a: int, b: int)->int:
    if a < b:
        a, b = b, a
    return a if b == 0 else gcd(b, a % b)


def gcd_list(A: list)->int:
    if len(A) == 0:
        return 0
    if len(A) == 1:
        return A[0]

    g = abs(A[0])
    for a in A[1:]:
        g = gcd(g, abs(a))
    return g


def polynominal_divisors(N: int, A: list)->list:
    # primes = prime_fact(abs(A[-1]))
    A.reverse()
    # 候補となる素数は、N 以下の素数あるいは、aN の素因数

    def check(p: int)->bool:
        '''素数 p が任意の整数 x について f(x) を割り切れるかを
        check する。具体的には、

        - a0
        - a1 + ap + a{2p-1} + ...
        - a2 + a{p+1} + a{2p} + ...
        ...
        - a{p-1} + a{2p-2} + ...
        という項が p で割り切れるかを検査する。
        '''
        if A[0] % p != 0:
            return False

        for i in range(1, min(N, p)):
            # ai + a{i+p-1} + ... を求めて
            # p で割り切れるか検査する。
            # print('p={}'.format(p))
            b = 0
            while i <= N:
                # print('i={}'.format(i))
                b = (b + A[i]) % p
                i += p-1
            if b != 0:
                return False
        return True

    primes = set(gen_primes(N) + prime_fact(gcd_list(A)))
    res = [p for p in primes if check(p)]
    res.sort()

    return res


if __name__ == "__main__":
    N = int(input())
    A = [int(input()) for _ in range(N+1)]

    ans = polynominal_divisors(N, A)
    for a in ans:
        print(a)


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int n;
ll a[400];
pair<ll, ll> dp[400][400];

pair<ll, ll> f(int p, int q)
{
    if (p == q) return {0, a[p]};
    if (dp[p][q] != pair<ll, ll>{-1ll, -1ll}) return dp[p][q];
    pair<ll, ll> bst = {1e15, 1e15};
    for (int i = p; i < q; ++i)
    {
        ll tot = f(p, i).first + f(i + 1, q).first;
        ll cst = f(p, i).second + f(i + 1, q).second;
        bst = min(bst, {tot + cst, cst});
    }
    return dp[p][q] = bst;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];

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

    cout << f(0, n - 1).first;
}


Measured memory_bytes: 2816
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

vector<vector<ll>> memo;

ll get(int x, int y) {
	if (memo[x][y] != -1)
		return memo[x][y];

	if (x == 0) return 1;
	if (y < x) return 0;

	memo[x][y] = get(x, y - 1) + get(x - 1, y - 1);
	return memo[x][y];
}

ll mpow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; i < b; i++) {
		ans *= a;
		ans %= 1000000007;
	}
	return ans;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}
int vmax(vector<int> v) {
	int max = INT32_MIN;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	if (A == 0 || B == 0) return max(A, B);
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}

	return B;
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}

template<int index>
bool comp(tuple<ll, ll, ll, ll> a, tuple<ll, ll, ll, ll> b) {
	return get<index>(a) < get<index>(b);
}

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


int len(int x) {
	return (int)log10(x) + 1;
}

int same_vec(vector<int> a, vector<int> b) {
	int res = 1, num = a.size();
	for (int i = 0; i < num; i++) {
		if (a[i] != b[i]) {
			res = 0;
			break;
		}
 	}
	return res;
}


int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	string S;
	cin >> S;

	ll ans = 1, len = S.size();

	string prev = S.substr(0, 1);
	ll tmp_len;
	for (ll index = 1; index < len; index += tmp_len) {
		for (tmp_len = 1;; tmp_len++) {
			if (prev != S.substr(index, tmp_len)) {
				ans++;
				prev = S.substr(index, tmp_len);
				break;
			}
			else if (index + tmp_len >= len) {
				goto LoopEnd;
			}
 		}
	}

	LoopEnd:;
	cout << ans << endl;

ProgramEndPointLabel:;

	//Program End
	system("pause");

	return 0;
}
/*

*/




Measured memory_bytes: 780
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
ll dp[110][100100]={0};


int main() {
    int n,W;
    cin>>n>>W;
    vector<int> w(n),v(n);
    rep(i,n) cin>>w[i]>>v[i];
    
    rep(i,n){
        for(int j=0; j<=W; j++){
            if(j-w[i]>=0){
                chmax(dp[i+1][j], dp[i][j - w[i]] + v[i]);
            }
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    
    cout << dp[n][W] << endl;
    return 0;
}


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

int main() {
    double l;
    cin >> l;
    double a = l / 3.0;
    double v = a * a * a;
    cout << std::setprecision(10) << v << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

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

  int x, y;
  cin >> x >> y;

  int z = y - 2 * x;
  if (z < 0) {
    cout << "No\n";
    return 0;
  }
  if (z % 2 != 0) {
    cout << "No\n";
    return 0;
  }
  if (z / 2 > x) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";

  return 0;
}


Measured memory_bytes: 3644
from sys import stdin


def dfs(g, v, visited):
    visited[v] = True

    for v2 in range(len(visited)):
        if not g[v][v2]:
            continue
        if visited[v2]:
            continue
        dfs(g, v2, visited)


def main():
    n, m = map(int, stdin.readline().split())
    ab = [list(map(int, stdin.readline().split())) for _ in range(m)]
    g = [[False] * n for _ in range(n)]
    for a, b in ab:
        g[a - 1][b - 1] = True
        g[b - 1][a - 1] = True

    ans = 0

    for i in range(m):
        visited = [False for _ in range(n)]
        a, b = ab[i]
        g[a - 1][b - 1] = False
        g[b - 1][a - 1] = False

        dfs(g, 0, visited)

        check = False
        for v in visited:
            if not v:
                check = True
        if check:
            ans += 1

        g[a - 1][b - 1] = True
        g[b - 1][a - 1] = True

    print(ans)


if __name__ == "__main__":
    main()


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

int dp[100010][3];

signed main()
{
    int n; cin>>n;
    vi a(n);
    vi b(n);
    vi c(n);
    rep(i,n){
        cin>>a[i];
        cin>>b[i];
        cin>>c[i];
    }
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    reps(i,n-1){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}


Measured memory_bytes: 4992
#include <iostream>


bool judging(int x, int y, int z)  //widthes of three edges
{
    if (x * x + y * y == z * z) {
        return true;
    } else if (z * z + x * x == y * y) {
        return true;
    } else if (y * y + z * z == x * x) {
        return true;
    } else {
        return false;
    }
}


int main()
{
    int a, b, c, n;  //the number of lines
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> a >> b >> c;
        if (judging(a, b, c)) {
            std::cout << "YES" << std::endl;
        } else {
            std::cout << "NO" << std::endl;
        }
    }
}

Measured memory_bytes: 2924
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll sum = 0;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    vector<ll> v;
    for (ll i = 1; i <= sqrt(sum) + 1; i++) {
        if (sum % i == 0) {
            v.push_back(i);
            v.push_back(sum / i);
        }
    }
    sort(all(v));
    reverse(all(v));
    for (int i = 0; i < v.size(); i++) {
        ll g = v[i];
        vector<ll> vv;
        ll s = 0, ss = 0;
        for (int j = 0; j < n; j++) {
            vv.push_back(g * (a[j] / g + 1) - a[j]);
            s += a[j] - g * (a[j] / g);
            ss += g * (a[j] / g);
        }
        sort(all(vv));
        for (int j = 0; j < n; j++) {
            if (ss == sum) {
                break;
            }
            ss += g;
            s -= g - vv[j];
            s += vv[j];
        }
        if (s / 2 <= k) {
            cout << g << endl;
            return 0;
        }
    }
}


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

int main() {
	map<string, int> memo;
	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		memo[s] += 1;
	}

	int mx = 0;
	for (const auto& x: memo) {
		if (mx < x.second) {
			mx = x.second;
		}
	}

	for (auto it = memo.begin(); it != memo.end(); it++) {
		if (it->second == mx) {
			cout << it->first << "\n";
		}
	}
	return 0;
}

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

using namespace std;

int main() {
	long n;
	cin >> n;
	while (n != 0) {
		n *= 2;
		vector<long> r;
		int c = 0;
		long u = (long)pow(n, 0.5);
		for (int i = u; i >= 1; i--) {
			if (n % i == 0) {
				r.push_back(i);
				c++;
			}
		}

		for (int i = 0; i < c; i++) {
			long k = r[i];
			long beta = k;
			long alpha = n / k;
			if (beta % 2 == alpha % 2) continue;
			long a = (alpha - beta + 1) / 2;
			long b = (alpha + beta - 1) / 2;
			cout << a << " " << b - a + 1 << endl;
			break;
		}

		cin >> n;
	}
	return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){
    int A, B;
    cin >> A >> B;
    A--; B--;

    char C[100][100];
    rep(i,50) rep(j,100) C[i][j] = '.';
    rep(i,50) rep(j,100) C[i+50][j] = '#';

    int line = 0, row = 0;
    while(B > 0){
        if(row == 98){
            line += 2;
            row = 0;
        }

        C[line][row] = '#';
        row += 2;
        B--;
    }

    line = 99, row = 0;
    while(A > 0){
        if(row == 98){
            line -= 2;
            row = 0;
        }
        
        C[line][row] = '.';
        row += 2;
        A--;
    }

    cout << 100 << " " << 100 << endl;
    rep(i,100){
        rep(j,100) cout << C[i][j];
        cout << endl;
    }
}

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

int main(void){
    char a;
    cin >> a;
    if(a >= 'a' && a <= 'z') cout << 'a' << endl;
    else cout << 'A' << endl;
    return 0;
}

Measured memory_bytes: 3628
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
d, t = Counter(d), Counter(t)
for i in set(t):
    if d[i] < t[i]:
        print("NO")
        exit()
print("YES")

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

// DAME:
int main(){
    int n, m;
    cin >> n >> m;
    vector< tuple<int, int, int> > pyi(m);
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        pyi[i] = make_tuple(a, b, i);
    }
    sort(pyi.begin(), pyi.end());
    int num = 0;
    // TIPS: tupleに格納されている値はget<i>で指定する
    int x = get<0>(pyi[0]);
    // ans {index, p, num: count}
    vector< vector<int> > ans(m, vector<int>(3));
  
    for(int i=0; i<m; i++){
        int y = get<0>(pyi[i]);
        if(x!=y){
            num = 0;
            x = get<0>(pyi[i]);
        }
        num++;
        int z = get<2>(pyi[i]);
        ans[i][0] = z;
        ans[i][1] = x;
        ans[i][2] = num;
    }

    sort(ans.begin(), ans.end());
  
    for(int i=0; i<m; i++){
        cout << setfill('0') << right << setw(6) << ans[i][1];
        cout << setfill('0') << right << setw(6) << ans[i][2];
        cout << endl;
    }
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

#define MAX_V 100000

int V;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];

void add_edge(int from, int to) {
  G[from].push_back(to);
  rG[to].push_back(from);
}

void dfs(int v) {
  used[v] = true;
  for (int i = 0; i < (int)G[v].size(); i++) {
    if (!used[G[v][i]]) dfs(G[v][i]);
  }
  vs.push_back(v);
}

void rdfs(int v, int k) {
  used[v] = true;
  cmp[v] = k;
  for (int i = 0; i < (int)rG[v].size(); i++) {
    if (!used[rG[v][i]]) rdfs(rG[v][i], k);
  }
}

int scc() {
  memset(used, 0, sizeof(used));
  vs.clear();
  for (int v = 0; v < V; v++) {
    if (!used[v]) dfs(v);
  }
  memset(used, 0, sizeof(used));
  int k = 0;
  for (int i = vs.size() - 1; i >= 0; i--) {
    if (!used[vs[i]]) rdfs(vs[i], k++);
  }
  return k;
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int E; cin >> V >> E;
  REP(_, E) {
    int f, t; cin >> f >> t;
    add_edge(f, t);
  }
  scc();
  int Q; cin >> Q;
  REP(_, Q) {
    int x, y; cin >> x >> y;
    cout << (cmp[x] == cmp[y]) << endl;
  }
  return 0;
}

Measured memory_bytes: 9144
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

long long int absolute(long long int a) {
	if(a > 0) {
		return a;
	} else {
		return -a;
	}
}

int main(void) {
	int i;
	long long int X, K, D;
	char buf[256], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	X = atoll(ch);
	ch = strtok(NULL, " ");
	K = atoll(ch);
	ch = strtok(NULL, " ");
	D = atoll(ch);

	X = absolute(X);

	if(K < (X / D)) {
		printf("%lld\n", (X - (K * D)));
	} else if((K - (X / D)) % 2 == 0) {
		printf("%lld\n", (X % D));
	} else {
		printf("%lld\n", absolute(D - (X % D)));
	}

	return 0;
}


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

int main(){
    int n,m,x,y; cin>>n>>m>>x>>y;
    int a=-1e9,b=1e9;
    for(int i=0;i<n;i++){
        int l; cin>>l;
        a=max(a,l);
    }
    for(int i=0;i<m;i++){
        int r; cin>>r;
        b=min(b,r);
    }
    for(int i=x+1;i<=y;i++){
        if(a<i&&b>=i){
            cout << "No War" <<endl;
            return 0;
        }
    }
    cout<<"War"<<endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
op = [tuple(map(int, input().split())) for _ in range(m)]
op.sort(key = lambda x: x[1], reverse = True)
index = 0
for b, c in op:
    for i in range(index, min(index + b, n)):
        if c <= a[i]:
            print(sum(a))
            exit()
        else:
            a[i] = c
    index = i + 1
print(sum(a))

Measured memory_bytes: 22108
package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)

    var max = 0
    var count = 0
    for i := 0; i < n; i++ {
        var h int
        fmt.Scan(&h)


        if h < max {
            continue
        }
        max = h
        count++
    }

    fmt.Println(count)
}

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

def main():
  while True:
    n = input()
    if not n: break

    memo = []
    ans = []
    for i in xrange(n):
      s = raw_input()
      d = 0
      for c in s:
        if c == ".":
          d += 1
      memo.append(d)
      ans.append([" "] * d + [s[d:]])

    t = []
    for i in xrange(n - 1, -1, -1):
      d = memo[i]
      t = filter(lambda x: x < d, t)
      for tt in t:
        ans[i][tt] = "|"
      if d > 0:
        ans[i][d - 1] = "+"
        t.append(d - 1)

    for i in xrange(n):
      print "".join(ans[i])

  return 0

## -------------------------------------------
## TEMPLATE

from sys import stdin
from sys import setrecursionlimit
from copy import deepcopy
from math import sqrt
from itertools import permutations
from itertools import combinations

def getline():
  return stdin.readline()

def getLineAs(tp):
  return map(tp, getline().split())

def array(n, init = 0):
  return [deepcopy(init) for i in range(n)]

if __name__ == "__main__":
  setrecursionlimit(1024 * 1024)
  main()

Measured memory_bytes: 14964
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
int main()
{
	double m,n,i,j,t,k;
	cin>>n;
	m=n*n*n/27;
	printf("%.8lf",m);
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
struct UnionFind{
    vi data;
    UnionFind(int size):data(size,-1){}
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    REP(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        uf.unite(a,b);
    }
    int ans=0;
    REP(i,n){
        if(uf.root(i)==i){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N;
  cin >> N;
  vi A(N);
  vi v(1e5+1);
  ll sum=0;
  rep(i,N) {
    cin >> A[i];
    v[A[i]]++;
    sum+=A[i];
  }
  int Q;
  cin >> Q;
  vi B(Q),C(Q);
  rep(i,Q) cin >> B[i] >> C[i];
  
  rep(i,Q) {
    int x=v[B[i]];
    v[B[i]]=0;
    v[C[i]]+=x;
    sum+=x*(C[i]-B[i]);
    cout << sum << endl;
  }
}

Measured memory_bytes: 4776
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp(a,b) make_pair(a,b)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
struct edge { int to; int to2; int cost; };
int a[100006];

int divi(int a, int b) {
	if (a%b)return a / b;
	else return (a / b) - 1;
}

signed main() {
	int n; cin >> n;
	int ans = 0;
	rep(i, n)cin >> a[i];
	int mx = 1;
	rep(i, n) {
		ans += divi(a[i], mx);
		if (mx == 1)mx++;
		else {
			if (a[i] == mx)mx++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

string S;
int target = 7;

string func(int i, int x, string ops){
  if (i==S.size()) {
    if (x==target) return ops;
    else return "";
  }
  
  string opsP = func(i+1, x+(S[i]-'0'), ops+"+");
  if (opsP != "") return opsP;

  string opsM = func(i+1, x-(S[i]-'0'), ops+"-");
  if (opsM != "") return opsM;

  return "";
}

int main(){
  cin >> S;
  string ops = func(1,S[0]-'0',"");
  rep(i,3) cout << S[i] << ops[i];
  cout << S[3] << "=7"<< endl; 

  // cout << fixed << setprecision(6);
  return 0;
}



Measured memory_bytes: 256