akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int main(){
    int n;
    scanf("%d", &n);
    int p[n];
    rep(i, 0, n){
        scanf("%d", &p[i]);
    }
    int ans = 1, min = p[0];
    rep(i, 1, n){
        if(p[i] <= min){
            ans++;
            min = p[i];
        }
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)


int main(){
    ll N,A,B,rs=0,Nans,min,max;
    cin >> N >> A >> B;

    if(N == 1){
        if(A == B)
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }else if(A > B){
        cout << 0 << endl;
    }else{
        Nans = N - 2;
        max = B * (Nans+1) + A;
        min = A * (Nans+1) + B;
        rs = max - min + 1;
        cout << rs << endl;
    }

    return 0;

}

Measured memory_bytes: 3608
N=int(input())

A,B=map(int,input().split())
P=list(map(int,input().split()))
one=0
two=0
three=0

for i in range(N):
  if P[i]<=A:
    one+=1
  elif P[i]>B:
    three+=1
  else:
    two+=1

print(min(one,two,three))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && a != c)
        Yes();
    else if(a == c && a != b)
        Yes();
    else if(b == c && b != a)
        Yes();
    else No();
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

const long long MOD = 1e9 + 7;
const int maxN = 1e6 + 11;

int N;
long long f[maxN],t[maxN];
int A[maxN],C[maxN];

void find(int v,int n){
//    cout << "Find to v = " << v << endl;//
    if(v > n){
        //cout << " - ";
        //for(int i = 1; i <= n; ++i) cout << A[i] << " ";
        // /cout << endl;
        ++C[n];
        return ;
    }
    A[v] = 1;
    find(v + 1,n);
    for(int x = 2; x <= n - v; ++x){
        A[v] = x;
        for(int i = 1; i <= x; ++i){
            A[i + v] = 1;
        }
        find(x + v + 1,n);
    }
}

void build(int v = 1){
    if(v > N){
        for(int i = 1; i <= N; ++i) cout << A[i] << " ";
        cout << " ~> end with " << A[N] << endl; 
        return ;
    }
    for(int i = 1; i <= N; ++i){
        A[v] = i;
        if(i > 1){
            if(v == N){
                build(v + 1);
                continue;
            }
            for(int j = 1; j <= N; ++j){
                for(int k = v + 1; k <= v + i; ++k){
                    A[k] = j;
                }
                if(j > 1){
                    for(int k = v + 1; k <= N; ++k) A[k] = j;
                    build(N + 1);
                }else  build(v + i + 1);
            }
        }else build(v + 1);
    }
}
int main(){
    
    scanf("%d",&N);

    //build();
    
    if(N == 1){
        printf("1");
    }else if(N == 2) printf("4");
    else{
        // main
    
        f[0] = t[0] = 1;
        for(int i = 1; i <= N; ++i){
            if(i <= 2) f[i] = 1;
            else{
                f[i] = (f[i - 1] + t[i - 3]) % MOD;
            }
            t[i] = (t[i - 1] + f[i]) % MOD;
 //           find(1,i);
        }
        //
        long long res = 0;
        for(int i = 1; i < N; ++i){
            int xmin = N - i;
            if(i == N - 1) ++xmin;
            res = (res + (f[i - 1] * (N - xmin + 1)) % MOD) % MOD;
            //cout << "at pos = " << i << " ~> " << xmin << " & " << (f[i - 1] * (N - xmin + 1)) % MOD << endl;
        }
        res = (res + f[N - 1]) % MOD;

        //

        //cout << "Res = " << res << endl;

        long long cnt = 0;
        for(int i = 1; i < N; ++i){
            long long tmp = ((f[i - 1] * (N - 1)) % MOD * (N - 1)) % MOD;
            cnt = (cnt + tmp) % MOD;
        }
        cnt = (cnt + (f[N - 1] * (N - 1)) % MOD) % MOD;
        //cout << "cnt = " << cnt << endl;
        printf("%lli",(res + cnt) % MOD);
    }

    return 0;
}

Measured memory_bytes: 17536
from sys import stdin
N = int(stdin.readline().rstrip())
data = list(map(int, stdin.readline().rstrip().split()))

m = max(data)
l = [0] * (m + 1)
count = 0

for i in data:
    tmp = 1
    j = 1
    while tmp  <=  m:
        l[i * j] += 1
        j += 1
        tmp = i * j

for i in data:
    if l[i] == 1:
        count  += 1

print(count)

Measured memory_bytes: 32172
#include<stdio.h>

int main(void)
{

  int i,time[4],min,sec,sum;

  sum = 0 ;

  for(i=0;i<4;i++){
    scanf("%d",&time[i]);
    sum = sum + time[i] ;
  }
  
  min = sum / 60 ;
  sec = sum % 60 ;

  printf("%d\n",min);
  printf("%d\n",sec);

  return 0;
}

Measured memory_bytes: 596
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <math.h>
#include <algorithm>

using namespace std;

struct Point {
    double x;
    double y;
};

void koch(int n, Point p1, Point p2) {
    if (n == 0) {
	return;
    }

    Point s,u,t;
    double radian= M_PI*60.0 / 180;

    s.x = (2.0*p1.x + 1.0*p2.x) / 3.0;
    s.y = (2.0*p1.y + 1.0*p2.y) / 3.0;
    t.x = (1.0*p1.x + 2.0*p2.x) / 3.0;
    t.y = (1.0*p1.y + 2.0*p2.y) / 3.0;
    u.x = (t.x - s.x)*cos(radian) - (t.y - s.y)*sin(radian) + s.x;
    u.y = (t.x - s.x)*sin(radian) + (t.y - s.y)*cos(radian) + s.y;

    koch(n- 1, p1, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, p2);

}

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

    Point p1, p2;
    int n; scanf("%d", &n);
    p1.x = 0;
    p1.y = 0;
    p2.x = 100;
    p2.y = 0;

    printf("%.8f %.8f\n", p1.x, p1.y);
    koch(n, p1, p2);
    printf("%.8f %.8f\n", p2.x, p2.y);
    
    return 0;
}

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

string s, t;

int main() {
    cin >> s >> t;
    if (t.substr(0, s.size()) == s) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 3636
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int combi(int x)
{
  return x * (x - 1) / 2;
}
int main()
{
  int n, m;
  scanf("%d%d", &n, &m);
  printf("%d\n", combi(n) + combi(m));
}

Measured memory_bytes: 128
import qualified Data.ByteString.Char8 as BC
import Data.IORef
import Control.Monad(forM_, when)
import Data.Maybe(fromJust)

main :: IO()
main = BC.getContents >>= solve.map (fst.fromJust.BC.readInt).tail.BC.lines >>= print

solve :: [Int] -> IO Int
solve (x:y:xs) = do
                a <- newIORef (y - x)
                b <- newIORef (min x y)
                forM_ xs $ \z -> do
                    a' <- readIORef a
                    b' <- readIORef b
                    when (z - b' > a') $ writeIORef a (z - b')
                    when (z < b')      $ writeIORef b z
                readIORef a

Measured memory_bytes: 5840
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	multiset<string> S;
	int x,y,z; cin>>x>>y>>z;
	for(int i=0;i<x;i++) S.insert("a");
	for(int i=0;i<y;i++) S.insert("b");
	for(int i=0;i<z;i++) S.insert("c");
	while(S.size()>1)
	{
		string a=(*S.begin());
		string b = (*prev(S.end()));
		S.erase(S.begin());S.erase(prev(S.end()));
		S.insert(a+b);
	}
	cout<<(*S.begin())<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())]
int n,x,y;
vector<P>hoge[200005];
P mn=mp(INF,INF);
int par[200005],ran[200005],c[200005],a[200005];
vector<int>vi[200005];
void init(){ for(int i=0;i<200005;i++) par[i] = i; }
int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
void unite(int x,int y){
	x = find(x); y = find(y); if(x==y) return;
	if(ran[x] < ran[y]) par[x] = y;
	else{
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}
ll modpow(ll x,ll n)
{
	ll res=1;
	while(n>0)
	{
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[200005],R[200005];
void make(){
	F[0] = 1;
	for(int i=1;i<200005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<200005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
bool same(int x,int y){ return find(x)==find(y); }
set<P>S;
int main(){
	cin>>n>>x>>y;make();
	rep(i,n){
		scanf("%d%d",&c[i],&a[i]);
		hoge[c[i]].pb(mp(a[i],i));
	}
	init();
	repn(i,n){
		SORT(hoge[i]);
		for(int j=1;j<hoge[i].size();j++) {
			if(hoge[i][0].fi+hoge[i][j].fi<=x) unite(hoge[i][0].sc,hoge[i][j].sc);
		}
		if(hoge[i].size()) S.insert(mp(hoge[i][0].fi,i));
	}
	P mn = *S.begin();
	repn(i,n){
		rep(j,hoge[i].size()) if(i!=mn.sc&&hoge[i][j].fi+hoge[mn.sc][0].fi<=y) unite(hoge[i][j].sc,hoge[mn.sc][0].sc);
	}
	S.erase(S.begin());
	if(S.size()){
		mn = *S.begin();
		repn(i,n){
			rep(j,hoge[i].size()) if(i!=mn.sc&&hoge[i][j].fi+hoge[mn.sc][0].fi<=y) unite(hoge[i][j].sc,hoge[mn.sc][0].sc);
		}
	}
	rep(i,n){
		vi[find(i)].pb(i);
	}
	ll ret = 1;
	rep(i,n){
		if(find(i) != i) continue;
		map<int,int>M;
		rep(j,vi[i].size()){
			M[c[vi[i][j]]]++;
		}
		int x = vi[i].size();
		for(map<int,int>::iterator it=M.begin();it!=M.end();++it){
			ret = ret*C(x,it->sc)%mod;
			x-=it->sc;
		}
	}
	cout<<ret<<endl;
}

Measured memory_bytes: 34420
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
ll n, k;

int main(){
	IOS
	cin >> n >> k;
	ll ans=k;
	n--;
	while(n--){
		ans*=(k-1);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3632
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N = INT()
	S = input()

	former = S[:N]
	latter = S[N:][::-1]

	dic_f = defaultdict(int)
	dic_l = defaultdict(int)

	for x in product([0, 1], repeat=N):
		tmp_red = ""
		tmp_blue = ""
		for i in range(N):
			if x[i]:
				tmp_red += former[i]
			else:
				tmp_blue += former[i]
		dic_f["{},{}".format(tmp_red, tmp_blue)] += 1

	for x in product([0, 1], repeat=N):
		tmp_red = ""
		tmp_blue = ""
		for i in range(N):
			if x[i]:
				tmp_red += latter[i]
			else:
				tmp_blue += latter[i]
		dic_l["{},{}".format(tmp_red, tmp_blue)] += 1
	
	ans = 0
	for key in dic_f:
		red_f, blue_f = key.split(",")
		ans += dic_f[key]*dic_l[key]
	print(ans)

if __name__ == '__main__':
	main()


Measured memory_bytes: 91864
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();
        int z = scan.nextInt();
        System.out.println(z + " " + x + " " + y);
    }
}


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

typedef long long ll;
const int maxn = 2e5 + 10;

int main(){
//    freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin>>a>>b;
    int res = a+(a-1);
    res = max(res, max(b+(b-1), a+b));
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.math.*;
import java.util.*;

public class Main {
	public static int x,min=Integer.MAX_VALUE;
	public static void dfs(boolean buf[],int aim[],int arr[][],int k){
		for(int i=1;i<aim.length;i++){
			if(aim[i]<x)
				break;
			if(i==aim.length-1){
				min=Math.min(min, aim[0]);
				return;
			}
		}
		boolean flag=true;
		for(int i=0;i<buf.length;i++){
			if(!buf[i]){
				break;
			}
			if(i==buf.length){
				if(min==Integer.MAX_VALUE){
					min=-1;
				}
				return;
			}
		}
		for(int i=k;i<buf.length;i++){
			if(!buf[i]){
				buf[i]=true;
				for(int j=0;j<aim.length;j++){
					aim[j]+=arr[i][j];
				}
				dfs(buf,aim,arr,k+1);
				for(int j=0;j<aim.length;j++){
					aim[j]-=arr[i][j];
				}
				buf[i]=false;
			}
		}
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		x=sc.nextInt();
		int arr[][]=new int[n][m+1];
		for(int i=0;i<n;i++){
			for(int j=0;j<=m;j++){
				arr[i][j]=sc.nextInt();
			}
		}
		boolean buf[]=new boolean [n];
		int aim[]=new int[m+1];
		dfs(buf,aim,arr,0);
		System.out.println(min==2147483647?-1:min);
	}
}

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

int n;
int a[3][200];
int dp[3][200];

int main() {
    ios::sync_with_stdio(false);

    cin >> n;
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> a[i][j];
            dp[i][j] = a[i][j];
        }
    }

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

    cout << dp[2][n] << endl;




    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  int answer = 1;
  for (int i = 0; i < N; ++i) {
    int next0 = answer * 2;
    int next1 = answer + K;
    answer = min(next0, next1);
  }
  cout << answer << endl;
  return 0;
}

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

int main() {
  long long n,m,k,sum=0,a=0,b=0,c=0,d=0,ans=0;
  long long MOD = 1000000007;
  long long INF = 1LL << 60;
  cin >> a >> b >> c >> d;
  while(true){
    a -= d;
    c -= b;
    if(a <= 0 && c <= 0){
      ans = 0;
      break;
    } else if (a <= 0) {
      ans = 1;
      break;
    } else if (c <= 0){
      ans = 0;
      break;
    }
  }
  if (ans == 0){
  cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}


/*{
  }*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

//constexpr int mod = 1e9+7;
//constexpr int inf = 1<<30;

signed main(){
  int n, t;
  cin >> n >> t;

  vi a(n);
  rep(i, 0, n) cin >> a[i];

  int m = 0, ma = a[n-1];
  for(int i = n-2; i >= 0; i--){
    chmax(m, ma-a[i]);
    chmax(ma, a[i]);
  }

  map<int, int> cnt;
  int ans = 0;
  rep(i, 0, n){
    ans += cnt[a[i]-m];
    cnt[a[i]]++;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,t5=0,t7=0;
    cin>>a>>b>>c;
    if(a==5)t5++;if(a==7)t7++;
    if(b==5)t5++;if(b==7)t7++;
    if(c==5)t5++;if(c==7)t7++;
    if(t5==2&&t7==1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<char>> c(2*h,vector<char>(w));
  for(int i=0;i<2*h;i++){
    for(int j=0;j<w;j++){
      if(i%2==0){
        cin>>c.at(i).at(j);
      }
      else{
        c.at(i).at(j)=0;
      }
    }
  }
  vector<vector<char>> ans((2*h),vector<char>(w));
  for(int i=0;i<2*h;i++){
    for(int j=0;j<w;j++){
      if(i%2==0){
        ans.at(i).at(j)=c.at(i).at(j);
      }
      else{
        ans.at(i).at(j)=ans.at(i-1).at(j);
      }
    }
  }
  for(int i=0;i<2*h;i++){
    for(int j=0;j<w;j++){
      cout<<ans.at(i).at(j);
    }
    cout<<endl;
  }
  return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define mod 1000000007

#define MAX_V 30

struct edge{ int to,cap,rev; };
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int> que;
  level[s]=0;
  que.push(s);
  while(!que.empty()){
    int v=que.front(); que.pop();
    for(int i=0;i<(int)G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[e.to]<0){
        level[e.to]=level[v]+1;
        que.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  for(int &i=iter[v];i<(int)G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  while(1){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}

int N;
string S[10001];
vector<char> p,s;
int incnt[26],cnt[26];

int main(){
  cin>>N;
  rep(i,N){
    cin>>S[i];
    p.push_back(S[i][0]);
    s.push_back(S[i][S[i].size()-1]);
    incnt[S[i][S[i].size()-1]-'a']++;
    cnt[S[i][0]-'a']++;
  }
  rep(i,26){
    if(incnt[i]==0)continue;
    //dbg(incnt[i]);
    //dbg(cnt[i]);
    rep(j,27)G[j].clear();
    rep(j,N){
      if(s[j]=='a'+i){
        add_edge(p[j]-'a',26,1);
      }else{
        add_edge(p[j]-'a',s[j]-'a',1);
      }
    }
    //dbg(max_flow(i,26));
    if(cnt[i]<=max_flow(i,26)){
      cout<<(char)('a'+i)<<endl;
    }
  }
  return 0;
}



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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;


int main(){
  double x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2;
  double distance = sqrt(((x1-x2)*(x1-x2))  + ((y1-y2) * (y1-y2)));
  cout << fixed << setprecision(6) << distance << endl;
}



Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,p[N],a[N];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&p[i]),a[p[i]]=i;
	for (int i=1;i<=n;i++) printf("%d ",i*n);
	for (int i=1;i<=n;i++) printf("%d\n",(n-i+1)*n+a[i]);
	return 0;
}

Measured memory_bytes: 768
#include<stdio.h>

int bubbleSort(int a[], int n)
{
	int i, j, temp;
	int swap = 0;
	
	for(i = 0; i <= n; i++)
	{
		for(j = n - 1; j >= i + 1; j--)
		{
			if(a[j] < a[j - 1])
			{
				temp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = temp;
				swap++;
			}
		}
	}
	
	return swap;
}

int main(void)
{
	int n, i, swap;
	
	scanf("%d", &n);
	
	int a[n];
	
	for(i = 0; i < n; i++)
	{
		if(i != n - 1)
		{
			scanf("%d ", &a[i]);
		}
		else
		{
			scanf("%d", &a[i]);
		}
	}
	
	swap = bubbleSort(a, n);
	
	for(i = 0; i < n; i++)
	{
		if(i != n - 1)
		{
			printf("%d ", a[i]);
		}
		else
		{
			printf("%d\n", a[i]);
		}
	}
	
	printf("%d\n", swap);
	return 0;
}
	


Measured memory_bytes: 2100
def GetMaxes(d):
    m = []
    for k, v in d.items():
        m.append([k,v])
    m.sort(key=lambda x:-x[1])

    if len(m) == 1:
        m.append([0, 0])
    return m[:2]

def main():
    n = int(input())
    v = list(map(int, input().split()))

    dic0 = dict()
    dic1 = dict()
    d = [dic0, dic1]
    for i in range(n):
        dic = d[i%2]
        if v[i] not in dic:
            dic[v[i]] = 1
        else:
            dic[v[i]] += 1

    m0 = GetMaxes(d[0])
    m1 = GetMaxes(d[1])

    if m0[0][0] == m1[0][0]:
        take0 = m0[0][1] + m1[1][1]
        take1 = m1[0][1] + m0[1][1]
        if take0 > take1:
            print(n-take0)
        else:
            print(n-take1)
    else:
        print(n - m0[0][1] - m1[0][1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 18684
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	int a;
	string s;
	cin >> a >> s;
	cout << (a < 3200 ? "red" : s) << endl;
	return 0;
}


Measured memory_bytes: 256
import math
a, b, c, d = map(int, input().split())
ac = (a - 1) // c
bc = b // c
ad = (a - 1) // d
bd = b // d
lcm = c * d // math.gcd(c,d)
acd = (a - 1) // lcm
bcd = b // lcm
print((b-a+1)-((bc-ac)+(bd-ad)-(bcd-acd)))

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
string s, t;
cin >> s >> t;
t += s;
cout << t;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



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

int digitSum(int i){
	int sum=0;
	while(i>0){
		sum+=i%10;
		i/=10;
	}return sum;	
}
int main()
{
	int N,A,B;
	scanf("%d %d %d",&N,&A,&B);
	int sum=0;
	for(int i=1;i<=N;i++){
		if(digitSum(i)>=A&&digitSum(i)<=B){
			sum+=i;
		}
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
using namespace std;

int main(void) {
	string str;
	const char chg = 'A' - 'a';

	for (int i = 0; i < 3; ++i) {
		cin >> str;
		char c = str[0] + chg;
		cout << c;
	}
	cout << '\n';

	return 0;
}


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

int main(){
	char b[11];
	cin>>b;
	if(b[5]=='1'||b[6]>'4')cout<<"TBD";
	else cout<<"Heisei";
	return 0;
	}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  	static int mod = 1000000007;
  static int size = 200001;
	static long[] fac = new long[size];
	static long[] finv = new long[size];
	static long[] inv = new long[size];
	static int INF = Integer.MAX_VALUE;
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	int N = sc.nextInt();
  int[] A =new int[N];
  int[] JUN =new int[N];
  for(int i=0;i<N;i++){
    A[i] = sc.nextInt();
    JUN[A[i]-1]=i+1;
  }
  System.out.print(JUN[0]);
  for(int j=1;j<N;j++){
    System.out.print(" "+JUN[j]);
  }




} 

 //fac, inv, finvテーブルの初期化、これ使う場合はinitComb()で初期化必要
	public static  void initComb(){
		fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
		for (int i = 2; i < size; ++i) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}
 
	//nCk % mod
	public static long comb(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
		return fac[n] * finv[k] % mod * finv[n - k] % mod;
	}
 
	//n! % mod
	public static long fact(int n){
		return fac[n];
	}
 
	//(n!)^-1 with % mod
	public static long finv(int n){
		return finv[n];
	}
  
}

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

const int NG = 1 << 28;
//const vector<int> OK = {1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 4, 4, 4, 6, 6, 6, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3};
const int T[4][5] = {
	{6, 7, 8, 12, 9},
	{0, 1, 2, 14, 18},
	{0, 3, 6, 9, 15},
	{2, 5, 8, 11, 12}
};
const int U[4][5] = {
	{21, 22, 23, 17, 11},
	{27, 28, 29, 15, 20},
	{23, 26, 29, 20, 17},
	{21, 24, 27, 18, 14}
};

map<vector<int>, int> mp;

bool check(vector<int> &p)
{
	for (int i = 0; i < 9; i++) if (p[0] != p[i]) return false;
	for (int i = 9; i < 12; i++) if (p[9] != p[i]) return false;
	for (int i = 12; i < 15; i++) if (p[12] != p[i]) return false;
	for (int i = 15; i < 18; i++) if (p[15] != p[i]) return false;
	for (int i = 18; i < 21; i++) if (p[18] != p[i]) return false;
	for (int i = 21; i < 30; i++) if (p[21] != p[i]) return false;
	return true;
}

int search(vector<int> &p, int n)
{
	if (check(p)) return n;
	if (n >= 9) return NG;
	//if (mp.count(p)) return mp[p];
	
	//printf("%d\n", n);
	/*for (int i = 0; i < 30; i++){
		printf("%d ", p[i]);
	}
	puts("");*/
	
	int res = NG;
	
	vector<int> &q = p;
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 5; j++){
			swap(q[T[i][j]], q[U[i][j]]);
		}
		int t = search(q, n + 1);
		res = min(res, t);
		for (int j = 0; j < 5; j++){
			swap(q[T[i][j]], q[U[i][j]]);
		}
	}
	
	return /*mp[p] = */res;
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		mp.clear();
		vector<int> p(30);
		for (int j = 0; j < 30; j++){
			scanf("%d", &p[j]);
		}
		printf("%d\n", search(p, 0));
	}
	return 0;
}

Measured memory_bytes: 1188
# -*- coding: utf-8 -*-

import random
import sys
import os
import pprint


"""Matrix Chain Multiplication"""

#fd = os.open('ALDS1_10_B.txt', os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())

n = int(input())
col = [0] * (n + 1)
for i in range(n):
    row, column = map(int, input().split())
    col[i] = row
    col[i+1] = column

memo = [[0 for i in range(n+1)] for j in range(n+1)]
#pprint.pprint(memo)

for length in range(2, n+1):
    for start_index in range(1, n - length + 2):
        end_index = start_index + length - 1
        candidates = []
        for split_index in range(start_index, end_index):
            left = memo[start_index][split_index]
            right = memo[split_index + 1][end_index]
            plus = col[start_index - 1] * col[split_index] * col[end_index]
            candidates.append(left + plus + right)

        memo[start_index][end_index] = min(candidates)
        #print('memo', start_index, end_index, memo[start_index][end_index])

#pprint.pprint(memo)
print(memo[1][n])

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

class WarshallFloyd():
    def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときは'inf')

    def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

    def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行ける
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d

n,m,l = na()
g = WarshallFloyd(n)

for i in range(m):
    a,b,c = na()
    g.add(a-1,b-1,c)

gg = WarshallFloyd(n)
d = g.WarshallFloyd_search()

for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            gg.add(i,j,1)

q = ni()
dd = gg.WarshallFloyd_search()

for i in range(q):
    s,t = na()
    print(-1 if dd[s-1][t-1] == float('inf') else dd[s-1][t-1]-1)

Measured memory_bytes: 130940
def main():
    from builtins import int, map, list, print
    from fractions import gcd
    from functools import reduce
    import sys
    def lcm(x, y):
        return (x * y) // gcd(x, y)

    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_number = (lambda: int(input()))

    N = input_number()
    T = [input_number() for i in range(N)]
    ans = reduce(lcm, T, 1)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5204
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_V 100

bool g[MAX_V][MAX_V];
bool used[MAX_V];
int d[MAX_V];
int f[MAX_V];
int V;
int t;

void
dfs(int u)
{
	int v;

	used[u] = true;
	d[u] = ++t;
	for (v = 0; v < V; ++v)
	{
		if (g[u][v] && !used[v])
			dfs(v);
	}

	f[u] = ++t;
}

void
solve()
{
	int v;

	t = 0;
	for (v = 0; v < V; ++v)
		used[v] = false;

	for (v = 0; v < V; ++v)
	{
		if (!used[v])
			dfs(v);
	}

	for (v = 0; v < V; ++v)
		printf("%d %d %d\n", v + 1, d[v], f[v]);
}

int
main(int argc, char** argv)
{
	int u, v;
	int k;
	int i, j;

	scanf("%d", &V);
	for (i = 0; i < V; ++i)
	{
		scanf("%d", &u);
		for (v = 1; v <= V; ++v)
			g[u - 1][v - 1] = false;

		scanf("%d", &k);
		for (j = 0; j < k; ++j)
		{
			scanf("%d", &v);
			g[u - 1][v - 1] = true;
		}
	}

	solve();
	return 0;
}

Measured memory_bytes: 600
require 'pp'

n = gets.chomp!.to_i
s_n = Array.new(n)
t_n = Array.new(n)
n.times do |i|
    s, t = gets.split
    s_n[i] = s
    t_n[i] = t.to_i
end
x = gets.chomp!

ok = false
sum = 0
s_n.each_with_index do |s, i|
    if s_n[i] == x
        ok = true
        next
    end

    if ok
        sum += t_n[i]
    end
end

puts sum


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

int main(){

  int a, b;
  
  while( cin >> a){
    int count=0;
    cin >> b;
    double x = a + b;

    while(1){
      x = x / 10;
      count++;
      if(x < 1) break;
    }
    cout << count << endl;
  }
   
  
  return 0;
}

Measured memory_bytes: 1160
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll x, y, z, k;
	scanf("%ld %ld %ld %ld", &x, &y, &z, &k);
	V a(x), b(y), c(z);
	SCAN(a); SCAN(b); SCAN(c);

	V d;
	REP(i, 0, x) REP(j, 0, y) {
		d.push_back(a[i]+b[j]);
	}
	std::sort(ALL(d), std::greater<ll>());
	ll min = std::min(k, (ll)d.size());
	V e;
	REP(i, 0, min) REP(j, 0, z) {
		e.push_back(d[i]+c[j]);
	}
	std::sort(ALL(e), std::greater<ll>());
	REP(i, 0, k) printf("%ld\n", e[i]);
	return 0;
}



Measured memory_bytes: 43368
#入力高速化 + 再帰回数制限解除
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
#ダイクストラ
#単一始点最短経路(正の辺のみ)
#s=始点 n=頂点数 edgeは隣接リスト(edge=[[[1,2],[2,4]],[[2,1]],[]])
#0-indexed
from heapq import heappop,heappush
def dijkstra(s,n,edge):
  inf=10**16
  ans=[inf]*n
  ans[s]=0
  h=[[0,s]]
  while h:
    c,v=heappop(h)
    if ans[v]<c:continue
    for u,t in edge[v]:
      if c+t<ans[u]:
        ans[u]=c+t
        heappush(h,[c+t,u])
  return ans
#solve
n,m,s,t=map(int,input().split())
s-=1
t-=1
yen_edge=[[]for _ in range(n)]
snuuk_edge=[[]for _ in range(n)]
for _ in range(m):
  u,v,a,b=map(int,input().split())
  u-=1
  v-=1
  yen_edge[u].append([v,a])
  yen_edge[v].append([u,a])
  snuuk_edge[u].append([v,b])
  snuuk_edge[v].append([u,b])
yen=dijkstra(s,n,yen_edge)
snuuk=dijkstra(t,n,snuuk_edge)
ans=[10**15-(yen[i]+snuuk[i])for i in range(n)]
for i in range(n-2,-1,-1):ans[i]=max(ans[i],ans[i+1])
for i in ans:print(i)

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

int main(){
  int a,b;
  cin >> a >> b;  

  if (a < b)cout << "a < b" << "\n";
     
  if (a > b)cout << "a > b" << "\n";
 
  if (a == b)cout << "a == b" << "\n";

  return 0;
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line

int main()
{
	cout << setprecision(10);
	ll q, h, s, d ;
	cin >> q >> h >> s >> d >> n;

	//nリットルほしい
	//2L買うとき、どの選択肢が一番いいか。
	ll two = min({q*8,h*4,s*2,d});
	//1L余るか、それともちょうど全部買い切れるかのどっちか
	ll ans = 0 ;
	ans += two* (n / 2);
	n %= 2;
	if(n == 0 ){
	}
	else{
		ans += min({q*4,h*2,s});
	}
	cout << ans << endl;
	return 0 ;



}


Measured memory_bytes: 256
N = int(input())
S = input()
r = S[1:].count("E")
rs = [r]
for i in range(1, N):
  if S[i-1] == "W":
    r += 1
  if S[i] == "E":
    r -= 1
  rs.append(r)
r = min(rs)
print(r)


Measured memory_bytes: 15564
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int n; cin >> n;
    VI v(n); REP(i,n) cin >> v[i];
    VI c(n); REP(i,n) cin >> c[i];
    int ans = 0;
    REP(i,n){
        int vc = v[i]-c[i];
        if(vc>0) ans+=vc;
    }
    out(ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 1000000007
#define ll  long long
using namespace std;
ll dp(vector<vector<ll>>&val,int i,int j){
	int h=val.size(),w=val[0].size();
	if(j==w-1){
		if(val[i][j]==-1){
			if(val[i+1][j]!=-1){val[i][j]=val[i+1][j];}
			else{val[i][j]=dp(val,i+1,j);}
		}
	}else if(i==h-1){
		if(val[i][j]==-1){
			if(val[i][j+1]!=-1){val[i][j]=val[i][j+1];}
			else{val[i][j]=dp(val,i,j+1);}
		}
	}else{
		if(val[i][j]==-1){
			ll a,b;
			if(val[i][j+1]==-1){a=dp(val,i,j+1);}else{a=val[i][j+1];}
			if(val[i+1][j]==-1){b=dp(val,i+1,j);}else{b=val[i+1][j];}
			val[i][j]=(a%M+b%M)%M;
		}
	}return val[i][j]%M;
}
int main(){
int h,w;
cin>>h>>w;
vector<vector<char>> mat;vector<vector<ll>> val;
for(int i=0;i<h;i++){
	vector<char>x;vector<ll>y;
	for(int j=0;j<w;j++){
		char z;cin>>z;x.push_back(z);if(z=='#'){y.push_back(0);}else{y.push_back(-1);}
	}mat.push_back(x);val.push_back(y);
}
val[h-1][w-1]=1;
cout<<dp(val,0,0);
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string S=in<string>();
	int v = 0;
	REP(i,4){
		if(S[i]=='+') v++;
		else v--;
	}

 	cout << v << endl;
	return 0;
}


Measured memory_bytes: 256
var n,i,j,max: longint;
snt: array[1..1000000] of boolean;
begin

read(n);
max:=n*10;
for j:=1 to max do snt[j]:=true;
snt[1]:=false;
j:=2;
while j<=trunc(sqrt(max)) do
begin
while snt[j]=false do inc(j);
for i:=2 to max div j do snt[i*j]:=false;
inc(j);
end;
while snt[n]=false do inc(n);
write(n);

end.


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

typedef long long ll;
#define int ll
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define int ll

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;


void solve() {
	int x, k, d;
	cin >> x >> k >> d;
	x = abs(x);

	int cur = x%d;
	int left = x/d;
	if(left > k) cur = x - k*d;
	else if((k-left)%2 == 1) cur = abs(cur - d);
	cout << cur;
}

int32_t main() {_
	
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
		solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}

Measured memory_bytes: 3800
S = list(input())

b = 0
for i in range(0,int((len(S)-1)/2)):
    if S[i] == S[len(S)-i-1]:
        b += 1

if len(S) > 3:
    if len(S)%4 == 1:
        c = 0
        for i in range(0,int((len(S)-1)/4)):
            if S[i] == S[int((len(S)-1)/2)-i-1]:
                c += 1
        d = 0
        for i in range(0,int((len(S)-1)/4)):
            if S[int((len(S)+3)/2)+i-1] == S[len(S)-i-1]:
                d += 1
        if b == int((len(S)-1)/2) and c == int((len(S)-1)/4) and d == int((len(S)-1)/4):
            print('Yes')
        else:
            print('No')
    elif len(S)%4 == 3:
        c = 0
        for i in range(0,int((len(S)-3)/4)):
            if S[i] == S[int((len(S)-1)/2)-i-1]:
                c += 1
        d = 0
        for i in range(0,int((len(S)-3)/4)):
            if S[int((len(S)+3)/2)+i-1] == S[len(S)-i-1]:
                d += 1
        if b == int((len(S)-1)/2) and c == int((len(S)-3)/4) and d == int((len(S)-3)/4):
            print('Yes')
        else:
            print('No')
else:
    if S[0] == S[2]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3188
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;

//--------------------------- Solve ---------------------------//

using Graph = vector<vector<int>>;

int N, K;
Graph g;
mint ans = 1;

void rec(int v, int p, int depth, int sub) {
    int color = K - sub;
    if (depth == 0) sub = 0;
    else sub = 1;
    for (auto e : g[v]) {
        if (e == p) continue;
        sub++;
        rec(e, v, depth+1, sub);
    }
    ans *= color;
    //print("v:", v, "color[v]:", color[v]);
}

void solve() {
    cin >> N >> K;
    g.resize(N);
    for (int i = 0; i < N-1; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    rec(0, -1, 0, 0);

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 14460
N,Q=[int(i) for i in input().split()]
S=input()
lr=[]
for i in range(Q):
  lr.append([int(i) for i in input().split()])

acn=[0 for i in range(N)]
count=0
for i in range(1,N):
  if S[i-1]+S[i]=="AC":
    count+=1
  acn[i]=count
for i in range(Q):
  l=lr[i][0]
  r=lr[i][1]
  print(acn[r-1]-acn[l-1])

Measured memory_bytes: 24464