akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (int)(ceil(double(n)/double(m)))
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main(){
	int n,a,b,c ;
	cin>>a>>b>>c ;
	cout<< b* ( c/a) ;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char c[100],b[100];
int main(){
    cin>>c>>b;
    for(int i=0;i<max(strlen(c),strlen(b));i++)
    {
        if(c[i]!='\0')cout<<c[i];
        if(b[i]!='\0')cout<<b[i];
    }
    cout<<endl;
    return 0;
}

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

int pow(int a,int p){
  a%=MOD;
  if(p==0)return 1;
  li s=pow(a,p/2);
  if(df) printf("pow(%d,%d)=%d\n",a,p/2,s);
  (s*=s)%=MOD;
  if(p%2==0)return s;
  return s*a%MOD;
}

int inv(int a){
  int p=pow(a,MOD-2);
  if(df) printf("inv(%d)=%d\n",a,p);
  return p;
}

int binom(int n,int r){
  li a=1,b=1;
  rep(i,r){
    (a*=n-i)%=MOD;
    (b*=i+1)%=MOD;
  }
  li ret=a*inv(b)%MOD;
  if(df)printf("binom(%d,%d)=%ld/%ld=%ld\n",n,r,a,b,ret);
  return ret;
}

int main(){
  int n,a,b; cin >>n >>a >>b;
  int s=pow(2,n);
  int d=(binom(n,a)+binom(n,b)+1)%MOD;
  (s+=MOD-d)%=MOD;
  cout << s << "\n";
}

Measured memory_bytes: 256
import sys
i = 0
H = []
W = []
while(1):
    tmp = [int(x) for x in input().split()]
    H.append(tmp[0])
    W.append(tmp[1])
    if(H[i]==0 and W[i]==0):
        break
    i+=1
for u in range(i):
    for s in range(H[u]):
        for t in range(W[u]):
            sys.stdout.write('#')
        print("")
    print("")




Measured memory_bytes: 6324
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n = int(input())
    d_list = list(map(int, input().split()))
    d_list.sort()
    print(d_list[(n//2)] - d_list[(n//2)-1])

if __name__ == "__main__":
    main()

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

//cmdで g++ test.cpp とするとコンパイルできる

int main() {
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  cout<<a.at(N/2)-a.at(N/2-1)<<endl;
}


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

int main()
{
  int N;
  cin >> N;
  N = N%28;

  for(int i=0;i<=7;i++)
  {
    if(N < 4*i)
    {
      cout << "No" << endl;
      return 0;
    }
    if((N-4*i)%7 == 0)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define itn int
#define gI gi
#define int long long 

using namespace std;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int k, len, ans, c[103][103], dp[10003][5][3];
char s[10003];
string ss;

int dfs(int x, int y, int z)
{
	if (y > k) return 0;
	if (x > len) return y == k;
	if (dp[x][y][z] != -1) return dp[x][y][z];
	int kk = (z == 1) ? (s[x] - '0') : 9, sum = 0;
	for (int i = 0; i <= kk; i+=1)
		sum += dfs(x + 1, y + (i != 0), z && (i == kk));
	 return dp[x][y][z] = sum;
}

signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	scanf("%s", s + 1);
	memset(dp, -1, sizeof(dp));
	k = gi();
	len = strlen(s + 1);
	printf("%lld\n", dfs(1, 0, 1));
	return 0;
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

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



int main() {
    ll N;
    cin >>N;
    vector<ll> P(N);
    vector<ll> Q(N);
    rep(i,N){
        cin >>P[i];
    }
    rep(i,N){
        cin >>Q[i];
    }
    ll A, B;
    vector<ll> a(N);
    rep(i,N){
        a[i] = i+1;
    }
    ll cnt =0;
    do {
        
        if(a == P){
            A = cnt;
        }
        if(a == Q){
            B = cnt;
        }
        cnt++;

    } while(next_permutation(all(a)));
        cout << abs(A-B) << endl;


    return 0;
    

}

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

int main()
{
  int n,k,m;
  queue<int> L;
  while(1){
    cin>>n>>k>>m;
    if(n==0 && k==0 && m==0)break;
    for(int i=1;i<n+1;i++)L.push(i);
    for(int i=0;i<m-1;i++){
      L.push(L.front());
      L.pop();
    }
    L.pop();
    while(L.size()!=1){
      for(int i=0;i<k-1;i++){
	L.push(L.front());
	L.pop();
      }
      L.pop();
    }
    cout<<L.front()<<endl;
    L.pop();
  }
  return 0;
}

Measured memory_bytes: 1268
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++) //0から
#define REP(i,n) for(int j=i;j<n;j++) //iから
#define in(a) cin>>a
#define out(a) cout<<a<<endl

long long int kaijo(long long int n){
    if(n == 0) return 1;
    return n * kaijo(n-1);
}


vector<bool> is_prime;
void Eratosthenes(long long int n){
    is_prime.resize(n+1,true);
    is_prime[0]=false;
    is_prime[1]=false;
    for(long long int i = 2; i <= n; i++){
        if(is_prime[i]){
            for(long long int j = i*i; j <= n; j++){
                is_prime[j] = false;
            }
        }
    }
}

//素数列挙
vector<long long int> Prime;
void Prime_Enumeration(long long int n){
    Eratosthenes(n);
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            Prime.push_back(i);
        }
    }
}

long long int gcd(long long int a, long long int b){
    if(a<b){
        swap(a,b);
    }
    long long int r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return r;
}

long long int lcm(long long int a, long long int b){
    long long int g = gcd(a,b);
    long long int l = (a * b) / g;

    return l;
}

//aが負の時でも余りを非負にしたいとき
long long  mod(long long a, long long m){
    return (a % m + m) % m;
}

//拡張ユークリッド ap + bq = gcd(a,b)
long long extGCD(long long a, long long b, long long &p, long long &q){
    if(b == 0){ p = 1; q = 0; return a;}
    long long d = extGCD(b, a % b, q, p);
    q -= a /b * p;
    
    return d;
}

//中国剰余定理
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2){
    long long p, q;
    long long d = extGCD(m1, m2, p, q);

    if((b2-b1) % d != 0) return make_pair(0, -1); //解なし

    long long m = m1 * (m2 / d);
    long long tmp = (b2 - b1) / d * p % (m2 / d);
    long long r =mod(b1 + m1 * tmp, m);

    return make_pair(r, m);
}

//mod.mでのa^{-1}
long long modinv(long long a, long long m){
    long long b = m, u = 1, v = 0;
    while(b){
        long long t = a /b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0)u += m;
    return u;

}
const long long MOD = 1000000007;

//key以上のうち最小の要素のindex
int binary_search(long long int *a, long long int n, long long int key){
    long long int right = n, left = -1;
    long long int md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}


int main(){
    long long int n,k;
    //cin>>n;
    vector<long long int> a(n);
    //rep(i,n) in(a[i]);


    string s;
    cin>>s;

    n = s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='1') s[i] = '9';
        else if(s[i] == '9') s[i] ='1';
    }

    cout<<s<<endl;


    

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string k; int d; cin >> k >> d;
  int lk = k.size();
  vector<vector<vector<int> > > f(2, vector<vector<int> > (lk + 1, vector<int> (d, 0) ) );
  f[1][lk][0] = 1;
  f[0][lk][0] = 1;
  const int mod = 1000000007;
  for(int i = lk - 1; i >= 0; i--){
    for(int rot = 0; rot < 2; rot++){
      for(int j = 0; j < d; j++){
        int lim = rot ? 9 : (k[i] - '0');
        for(int dig = 0; dig <= lim; dig++){
          f[rot][i][j] += f[rot || (dig < lim)][i + 1][(j + dig)%d];
          if(f[rot][i][j] >= mod) f[rot][i][j] -= mod;
        }
      }
    }
  }
  int ans = f[0][0][0] + mod - 1;
  if(ans >= mod) ans -= mod;
  cout << ans << endl;
  return 0;
}
          
  
  


Measured memory_bytes: 13184
#include <stdio.h>

int main(void){
	char str[20];
	int i = 0;
	int max = 0, count = 0;
	scanf("%s", str);
	while(str[i]){
		if(str[i] == 'A' || str[i] == 'T' || str[i] == 'G' || str[i] == 'C'){
			count++;
		}else{
			if(max < count)max = count;
			count = 0;
		}
		i++;
	}
	if(max < count)max = count;
	printf("%d\n", max);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  ll mx = A[0];
  ll ans = 0;
  for (int i = 1; i < n; i++){
    if(A[i] <= mx ) ans += mx - A[i];
    else mx = A[i];
  }
  cout << ans << endl;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
template< typename T > using Vec = vector< T >;
template< typename T > T modAdd(T a, T b, T mod) { return (a+b)%mod; }
template< typename T > T modMul(T a, T b, T mod) { return (a*b)%mod; }

Vec< Vec< int > > mul(int N, int M, Vec< Vec< int > >& A, Vec< Vec< int > >& B) {
	Vec< Vec< int > > R(N, Vec< int >(N, 0));
	for_(i,0,N) for_(j,0,N) for_(k,0,N) R[i][j] = modAdd(R[i][j], modMul(A[i][k], B[k][j], M), M);
	return R;
}

Vec< Vec< int > > modPowMat(int N, int M, Vec< Vec< int > > A, int k) {
	Vec< Vec< int > > R(N, Vec< int >(N, 0));
	for_(i,0,N) R[i][i] = 1;
	while (k) {
		if (k & 1) R = mul(N, M, R, A);
		A = mul(N, M, A, A);
		k >>= 1;
	}
	return R;
}

int main() {
	int N, M, A, B, C, T;
	while (cin >> N >> M >> A >> B >> C >> T, N != 0) {
		Vec< int > S(N);
		for_(i,0,N) cin >> S[i];
		
		Vec< Vec< int > > mat(N, Vec< int >(N, 0));
		for_(i,0,N) {
			if (i - 1 >= 0) mat[i][i-1] = A;
			mat[i][i] = B;
			if (i + 1 < N) mat[i][i+1] = C;
		}
		
		mat = modPowMat(N, M, mat, T);
		
		for_(i,0,N) {
			int Si = 0;
			for_(j,0,N) Si = modAdd(Si, modMul(mat[i][j], S[j], M), M);
			cout << Si << (i < N-1 ? " " : "\n");
		}
	}
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define debug 1

int main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n;
	cin>>n;
	int p[n];
	for(int i=0;i<n;i++)
		cin>>p[i];
	int ans=0;
	for(int i=1;i<n-1;i++)
		if((p[i-1]>p[i] && p[i]>p[i+1]) ||
		 (p[i-1]<p[i] && p[i]<p[i+1]))
		ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
cardlist = [[i for i in range(1,14)] for j in range(4)]
n = int(input())
for s in range(0, n):
    x,y = map(str,input().split())
    y = int(y)
    if x == "S":
        cardlist[0].remove(y)
    elif x == "H":
        cardlist[1].remove(y)
    elif x == "C":
        cardlist[2].remove(y)
    else:
        cardlist[3].remove(y)
for z in cardlist[0]:
    print("S", z)
for z in cardlist[1]:
    print("H", z)
for z in cardlist[2]:
    print("C", z)
for z in cardlist[3]:
    print("D", z)

Measured memory_bytes: 7700
gets
ps = [0] + gets.split.map(&:to_i)
xys = $stdin.read.split

rest = {}
idx = 1
while idx < ps.length
  rest[idx] = 1
  idx += 1
end

xys = xys.each_slice(2).map {|x,y| [[x,y],[y,x]]}.flatten(1).sort
h = {}
xys.each do |xs,ys|
  x = xs.to_i
  y = ys.to_i
  h[x] ||= []
  h[x] << y
end

as = []
used = {}
h.each do |k,v|
  next if used[k]
  b = v
  lused = {}
  lused[k] = 1
  until b.empty?
    b.each do |n|
      lused[n] = 1
    end
    b = b.map {|n| h[n] || []}.flatten.uniq.reject {|n| lused[n]}
  end
  lused.each_key do |i|
    rest.delete(i)
  end
  as << lused
  used.merge!(lused)
end

# p h
# p as
# p rest

ret = 0

rest.each_key do |i|
  ret += 1 if ps[i] == i
end

as.each do |h|
  h.each_key do |n|
    ret += 1 if h[ps[n]]
  end
end

p ret


Measured memory_bytes: 76492
// The moment you think of giving up you have already lost the battle
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }
    }
}
const int N=1e6+5;
int d[N],cnt[N];
int main()
{
    memset(d,0,sizeof(d));
    memset(cnt,0,sizeof(cnt));
    int i,j;
    int n;
    cin>>n;
    int res[n];
    for(i=0;i<n;i++)
    {
        cin>>res[i];
        cnt[res[i]]++;
    }
    for(i=1;i<N;i++)
    {
        for(j=i;j<N;j+=i)
        {
            d[j]+=cnt[i];
        }
    }
    int ans=0;
    for(i=0;i<n;i++)
    {
        if(d[res[i]]==1)
            ans++;

    }
    cout<<ans;


}


Measured memory_bytes: 12216
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		if (x < a) {
			System.out.println(0);
		} else {
			System.out.println(10);
		}
	}
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < n - 2; i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math

def read_input():
    n = int(input())
    return n


def submit():
    n = read_input()

    factor_cand = int(math.ceil(math.sqrt(n)))

    while n % factor_cand:
        factor_cand -= 1

        if factor_cand == 1:
            nl = len([c for c in str(n)])
            print(nl)
            return

    a = int(n / factor_cand)
    b = int(factor_cand)

    al = len([c for c in str(a)])
    bl = len([c for c in str(b)])

    print(max(al, bl))



if __name__ == '__main__':
    submit()


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

#define Inf ll(1e18)
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=55;
int n,ql,qr;
ll X,D;
ll m[maxn],dp[maxn*maxn*maxn],ndp[maxn*maxn*maxn],qval[maxn*maxn*maxn];
int qpos[maxn*maxn*maxn];
int c[maxn],par[maxn],ord[maxn],lim[maxn];
bool cmp(int a,int b){
	return m[a]*c[b]<m[b]*c[a];
}

int main(){
	scanf("%d%lld%lld",&n,&X,&D);
	REP(i,n){
		scanf("%d",&m[i]);
		if(i>1)scanf("%d",&par[i]);
		c[i]=1;
		ord[i]=i;
	}
	for(int i=n;i>1;i--){
		m[par[i]]+=m[i];
		c[par[i]]+=c[i]; 
	}
	sort(ord+1,ord+1+n,cmp);
	ll summ=0,sumc=0,ans=0;
	REP(i,n){
		if(summ>X)break;
		int s=0;
		REP(j,n)if(j!=i){
			if(ord[j]==1)lim[ord[j]]=n;
			else lim[ord[j]]=min(n,int(D));
			s+=lim[ord[j]]*c[ord[j]];
		}
		rep(k,s+1)dp[k]=Inf; 
		dp[0]=0;
		REP(j,n)if(j!=i){
			rep(k,c[ord[j]]){
				ql=1;qr=0;
				rep(kk,(s-k)/c[ord[j]]+1){
					int now=kk*c[ord[j]]+k;
					while(ql<=qr&&qpos[ql]<kk-lim[ord[j]])ql++;
					if(dp[now]!=Inf){
						while(qr>=ql&&dp[now]-kk*m[ord[j]]<qval[qr])qr--;
						qval[++qr]=dp[now]-kk*m[ord[j]];
						qpos[qr]=kk;
					}
					if(ql<=qr)ndp[now]=qval[ql]+kk*m[ord[j]];
					else ndp[now]=Inf;
				}
			}
			rep(k,s+1)dp[k]=ndp[k];
		}
		rep(k,s+1)if(dp[k]+summ<=X){
			ll cur=ord[i]==1?Inf:D;
			ans=max(ans,k+sumc+min(cur,(X-dp[k]-summ)/m[ord[i]])*c[ord[i]]);
		}
		if(max(D-n,0LL)>Inf/m[ord[i]])break;
		summ+=m[ord[i]]*max(D-n,0LL);
		sumc+=c[ord[i]]*max(D-n,0LL);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    // private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int x = in.nextInt();
        int y = in.nextInt();

        out.println(
                y % 2 == 0 && x * 2 <= y && y <= x * 4 ? "Yes" : "No"
        );
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 25424
// ABC161
// a.cs

using System;

class A
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int A = int.Parse(str[0]);
        int B = int.Parse(str[1]);
        int C = int.Parse(str[2]);

        int temp;

        temp = A;
        A = B;
        B = temp;

        temp = A;
        A = C;
        C = temp;

        Console.WriteLine("{0} {1} {2}", A, B, C); 
    }
}

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

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
	if ( ch == 'A') return 1;
	else if ( ch == 'C') return 2;
	else if ( ch == 'G') return 3;
	else if ( ch == 'T') return 4;
	else return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
	long long sum = 0, p = 1, i;
	for ( i = 0; i < strlen(str); i++ ){
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
	long long key, i, h;
	key = getKey(str);
	for (i = 0;; i++) {
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0) return 1;
		else if (strlen(H[h]) == 0) return 0;
	}
	return 0;
}

int insert(char str[]){
	long long key, i, h;
	key = getKey(str);
	for (i = 0;; i++) {
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0) return 1;
		else if (strlen(H[h]) == 0) {
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



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

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

ll f(ll x, ll c, ll d) {
    ll res = x;
    res -= x / c;
    res -= x / d;
    res += x / lcm(c, d);
    return res;
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = f(b, c, d) - f(a - 1, c, d);
    cout << ans << endl;
    return 0;
}

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


int n;

pair<long long, long long> caldiff(vector<long long> & elements,  vector<vector<pair<long long, long long>>> &dp, 
                    int i, int j, bool player)
{
    //cout << "#1:  i " << i <<" j " << j << " player: " << player<< endl;
    if (dp[i][j].first != 0 || dp[i][j].second != 0) {
     
     //cout << "#2: i " << i <<" j " << j << " " << dp[i][j].first << "  " << dp[i][j].second <<endl;
     
      return dp[i][j];
    }

    if (i == j)
    {
        if (player == 1)
          dp[i][j] = make_pair(elements[i], 0);
        else
        {
          dp[i][j] = make_pair(0, elements[i]);
        }
       // cout << "#3:  i " << i <<" j " << j << " " << dp[i][j].first << "  " << dp[i][j].second <<endl;
        return dp[i][j];
    }
    pair <long long, long long> x = caldiff(elements, dp, i+1, j, (player+1)%2);
    pair <long long, long long> y = caldiff(elements, dp, i, j-1, (player+1)%2);

    if (player){
      if (elements[i] + x.first > elements[j] + y.first) {
      dp[i][j].first = elements[i] + x.first;
      dp[i][j].second = x.second;
      }
      else
      {
         dp[i][j].first = elements[j] + y.first;
         dp[i][j].second = y.second;
      }
    }
    else
    {
       if (elements[i] + x.second > elements[j] + y.second) {
      dp[i][j].second = elements[i] + x.second;
      dp[i][j].first = x.first;
      }
      else
      {
         dp[i][j].second = elements[j] + y.second;
         dp[i][j].first = y.first;
      }
    }
    //cout<< "#4: dp[i][j] " << dp[i][j].first << " " << dp[i][j].second<<endl; 

    return dp[i][j];
}
int main()
{
    scanf("%d", &n);
    vector<long long> elements(n);
    for(auto &x: elements)
      scanf("%lld", &x);
    vector<vector<pair<long long, long long> >> arr(3000);
    for (auto &x: arr)
      x = vector<pair<long long, long long> >(3000, make_pair(0,0));
    caldiff(elements, arr, 0, n-1, 1);
    cout << arr[0][n-1].first - arr[0][n-1].second <<endl;

    return 0;
}

Measured memory_bytes: 141440
#include <iostream>

using namespace std;

int main(int argc, const char *argv[])
{
  int x;
  cin >> x;

  int cnt500 = x / 500;
  x = x % 500;
  int cnt5 = x / 5;

  cout << cnt500 * 1000 + cnt5 * 5 << "\n";
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    int N; cin >> N;
    set<string>S;
    ll ans = 1;

    for (int i = 0; i < N; i++){
      string a;  cin >> a;
      S.insert(a);
    }
    
    // if(N == 1) {
    //   cout << ans << endl;
    //   return 0;
    // }

    // sort(S.begin(), S.end());
    
    // for (int i = 0; i < N-1; i++)
    // {
    //   tmp = S[i];
    //   if(tmp.compare(S[i+1]) != 0){
    //     ans++;
    //   }
    // }

    cout << S.size() << endl;
    
    return 0;
    
}

Measured memory_bytes: 19112
from collections import deque

# 頂点数と辺数
N, M = map(int, input().split())
# 辺
AB = [map(int, input().split()) for _ in range(M)]

# 無向グラフの隣接リスト設定
link = [[] for _ in range(N + 1)]
for a, b in AB:
  link[a].append(b)
  link[b].append(a)

# BFSのデータフレーム
dist = [-1] * (N + 1)  # 看板未設定
que = deque([1])       # 頂点1を始点とした訪問キュー

# BFS 開始 (キューが空になるまで探索を行う)
while que:
    v = que.popleft() # キューから先頭頂点(現在地)v取得

    for i in link[v]:
      # 未設定頂点iに現在地への看板を設定し訪問キューに追加する
      if dist[i] == -1:
        dist[i] = v
        que.append(i)

# 結果出力（各頂点に設置する看板）
print('Yes')
print('\n'.join(str(v) for v in dist[2:]))

Measured memory_bytes: 106472
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))

int n;
int m;
int r;

i64 dist[210][210];

int q[10];

int main()
{
	for(int i =0;i < 210;i++) for(int j = 0;j < 210;j++)
		dist[i][j] = 1e18;
	cin >> n >> m >> r;
	for(int i = 0;i < r;i++)
		cin >> q[i];
	for(int i = 0;i < m;i++)
	{
		int a,b;
		i64 c;
		cin >> a >> b >> c;
		dist[a][b] = c;
		dist[b][a] = c;
	}

	for(int k = 1;k <= n;k++)
	{
		for(int i = 1;i <= n;i++)
		{
			for(int j = 1;j <= n;j++)
			{
				dist[i][j] = min(dist[i][j] , dist[i][k] + dist[k][j]);
			}
		}
	}

	i64 result = 1e18;

	sort(q , q + r);
	do
	{
		i64 sum = 0;
		for(int i = 1;i < r;i++)
		{
			sum += dist[q[i - 1]][q[i]];
		}
		result = min(result , sum);
	} while(next_permutation(q,q + r));


	cout << result << endl;
}




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

int main(){
    int n, x, count;
    
    while(1){
        cin >> n >> x;
        count = 0;
        
        if(n == 0 && x == 0) break;
        
        for(int i = n; i > 0; i--){
            for(int j = i - 1; j > 0; j--){
                for(int k = j - 1; k > 0; k--){
                    if((i + j + k) == x) count++;
                }
            }
        }
        
        cout << count << endl;
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    int si, sj, ei, ej;
    cin >> si >> sj >> ei >> ej;
    vector<vector<int>> grid(h + 2, vector<int>(w + 2, true));
    for(int i = 1; i <= h; i++) {
        string s;
        cin >> s;
        for(int j = 1; j <= w; j++) {
            grid[i][j] = s[j - 1] == '@';
        }
    }
    map< pair<int, int>, vector<vector<int>> > obs;
    for(int di : {-1, 1}) {
        obs[{di, 0}] = vector<vector<int>>(h + 2, vector<int>(w + 2));
        for(int i = (di < 0 ? 1 : h); (di < 0 ? i <= h : i >= 1); i -= di) {
            for(int j = 1; j <= w; j++) {
                obs[{di, 0}][i][j] = grid[i][j] ? 0 : obs[{di, 0}][i + di][j] + 1;
            }
        }
    }
    for(int dj : {-1, 1}) {
        obs[{0, dj}] = vector<vector<int>>(h + 2, vector<int>(w + 2));
        for(int i = 1; i <= h; i++) {
            for(int j = (dj < 0 ? 1 : w); (dj < 0 ? j <= w : j >= 1); j -= dj) {
                obs[{0, dj}][i][j] = grid[i][j] ? 0 : obs[{0, dj}][i][j + dj] + 1;
            }
        }
    }
    vector<set<int>> alive_hori(h + 2), alive_vert(w + 2);
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            alive_hori[i].insert(j);
            alive_vert[j].insert(i);
        }
    }
    set<tuple<int, int, int>> pq;
    auto visit = [&](int x, int y1, int y2, int d, vector<set<int>>& axis, vector<set<int>>& orth) {
        for(auto it = axis[x].lower_bound(y1); it != axis[x].end() and *it <= y2; ) {
            if(addressof(axis) == addressof(alive_hori)) {
                pq.insert({d, x, *it});
            } else {
                pq.insert({d, *it, x});
            }
            orth[*it].erase(x);
            it = axis[x].erase(it);
        }
    };
    visit(si, sj, sj, 0, alive_hori, alive_vert);
    while(not pq.empty()) {
        auto [d, i, j] = *pq.begin();
        pq.erase(pq.begin());
        if(i == ei and j == ej) {
            cout << d << endl;
            return 0;
        }
        if(d < lim<int>::max()) {
            for(auto di : {-1, 1}) {
                auto lim_i = obs[{di, 0}][i][j];
                int x = i, y = i + di * min(k, lim_i - 1);
                visit(j, min(x, y), max(x, y), d + 1, alive_vert, alive_hori);
            }
            for(auto dj : {1, -1}) {
                auto lim_j = obs[{0, dj}][i][j];
                int x = j, y = j + dj * min(k, lim_j - 1);
                visit(i, min(x, y), max(x, y), d + 1, alive_hori, alive_vert);
            }
        } else {
            break;
        }
    }
    cout << -1 << endl;
    return 0;
}


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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    int n;
    cin >> n;
    vector<ll> t(n);
    ll lcm = 1;
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        lcm = lcm / gcd(lcm, t[i]) * t[i];
    }
    cout << lcm << endl;
    return 0;
}

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

const int G = 3 , P = 998244353 , _ = 1 << 14 | 1; int N , M , dp[_] , fac[_] , ifac[_] , A[_] , B[_];
int poww(long long a , int b){int tms = 1; while(b){if(b & 1) tms = tms * a % P; a = a * a % P; b >>= 1;} return tms;}
int binom(int a , int b){return 1ll * fac[a] * ifac[b] % P * ifac[a - b] % P;}

int dir[_] , w[_] , need , invnd;
void init(int len){
	need = 1; while(need < len) need <<= 1;
	invnd = poww(need , P - 2);
	for(int i = 1 ; i < need ; ++i) dir[i] = (dir[i >> 1] >> 1) | (i & 1 ? need >> 1 : 0);
	for(int i = 1 ; i < need ; i <<= 1){
		w[i] = 1; int wn = poww(G , P / 2 / i);
		for(int j = 1 ; j < i ; ++j) w[i + j] = 1ll * w[i + j - 1] * wn % P;
	}
}

void DFT(int *arr , int tp){
	for(int i = 1 ; i < need ; ++i) if(i < dir[i]) swap(arr[i] , arr[dir[i]]);
	for(int i = 1 ; i < need ; i <<= 1)
		for(int j = 0 ; j < need ; j += i << 1)
			for(int k = 0 ; k < i ; ++k){
				int x = arr[j + k] , y = 1ll * arr[i + j + k] * w[i + k] % P;
				arr[j + k] = (x + y) % P; arr[i + j + k] = (x - y + P) % P;
			}
	if(tp == -1){
		reverse(arr + 1 , arr + need);
		for(int i = 0 ; i < need ; ++i)
			arr[i] = 1ll * arr[i] * invnd % P;
	}
}

int main(){
	cin >> N >> M; fac[0] = 1; for(int i = 1 ; i <= N + 2 ; ++i) fac[i] = 1ll * fac[i - 1] * i % P;
	ifac[N + 2] = poww(fac[N + 2] , P - 2); for(int i = N + 1 ; ~i ; --i) ifac[i] = ifac[i + 1] * (i + 1ll) % P;
	init(2 * N + 10); dp[0] = 1; for(int i = 3 ; i <= N + 2 ; ++i) B[i] = ifac[i];
	DFT(B , 1);
	for(int i = 1 ; i <= M ; ++i){
		memset(A , 0 , sizeof(A)); for(int j = 0 ; j <= N ; ++j) A[j] = 1ll * dp[j] * ifac[j] % P;
		DFT(A , 1); for(int j = 0 ; j < need ; ++j) A[j] = 1ll * A[j] * B[j] % P;
		DFT(A , -1); for(int j = 0 ; j <= N ; ++j) dp[j] = (dp[j] * (binom(j + 1 , 2) + 1ll) + 1ll * A[j + 2] * fac[j + 2]) % P;
	}
	int sum = 0; for(int i = 0 ; i <= N ; ++i) sum = (sum + 1ll * binom(N , i) * dp[i]) % P;
	cout << sum; return 0;
}


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


def main():
    N = input()
    if int(N[-1]) == 3:
        print("bon")
    elif int(N[-1]) in[2, 4, 5, 7, 9]:
        print("hon")
    elif int(N[-1]) in [0, 1, 6, 8]:
        print("pon")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9116
n,m,x,y=map(int, input().split())
x_list=list(map(int, input().split()))
y_list=list(map(int, input().split()))
if max(x_list)<min(y_list) and max(x_list)<y and x<min(y_list):
  print("No War")
else:
  print("War")

Measured memory_bytes: 9108
#include <algorithm>
#include <iostream>
#include <set>
#include <string>

using namespace std;

int32_t main() {
  uint32_t n;
  cin >> n;

  for (uint32_t _ = 0; _ < n; _++) {
    string str;
    cin >> str;

    set<string> trains;
    for (uint32_t i = 1; i < str.size(); i++) {
      string first = str.substr(0, i);
      string second = str.substr(i, str.size() - i);
      string rfirst = string(first);
      reverse(rfirst.begin(), rfirst.end());
      string rsecond = string(second);
      reverse(second.begin(), second.end());
      trains.insert(first + second);
      trains.insert(rfirst + second);
      trains.insert(first + rsecond);
      trains.insert(rfirst + rsecond);
      trains.insert(second + first);
      trains.insert(second + rfirst);
      trains.insert(rsecond + first);
      trains.insert(rsecond + rfirst);
    }
    cout << trains.size() << endl;
  }
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    string s; cin >> s;
    int N = s.size();
    bool odd = true, even = true;
    rep(i, N) {
        if(i&1) {
            if(s[i] == 'R') even = false;
        } else {
            if(s[i] == 'L') odd = false;
        }
    }
    cout << (odd && even ? "Yes" : "No") << '\n';
    return 0;
}

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

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

using namespace std;

pair<int,int> calc(const string &s, int i) {
  if (s[i] == '-') {
    auto p = calc(s, i+1);
    p.first = 2 - p.first;
    return p;
  } else if (s[i] == '(') {
    auto lhs = calc(s, i+1);
    auto rhs = calc(s, lhs.second + 1);
    if (s[lhs.second] == '*') {
      return make_pair(min(lhs.first, rhs.first), rhs.second+1);
    } else {
      return make_pair(max(lhs.first, rhs.first), rhs.second+1);
    }
  } else {
    return make_pair(s[i] - '0', i+1);
  }
}

int main() {
  while(1){
    string s;
    cin>>s;
    if (s == ".") break;
    int cnt = 0;
    REP(i,27) {
      int v[3];
      int p = i;
      REP(j,3) {
        v[j] = p % 3;
        p /= 3;
      }
      string cp = s;
      for (char &c : cp) {
        if ('P' <= c && c <= 'R') {
          c = v[c - 'P'] + '0';
        }
      }
      if (calc(cp, 0).first == 2) ++cnt;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin>>a;
  if(a[0]==a[1] && a[1]!=a[2] && a[2]==a[3])cout<<"Yes"<<endl;
  else if(a[0]==a[2] && a[2]!=a[1]&& a[1]==a[3])cout<<"Yes"<<endl;
  else if(a[0]==a[3] && a[3]!=a[1]&&a[1]==a[2])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
 

Measured memory_bytes: 3592
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
)

var sc = bufio.NewScanner(os.Stdin)


func next() int {
  sc.Scan()
  i, _ := strconv.Atoi(sc.Text())
  return i
}

func sort(array []int) []int {
  if len(array) < 2 {
    return array
  }

  pivot := array[0]
  left := []int{}
  right := []int{}
  for _, v := range array[1:] {
    if v > pivot {
      right = append(right, v)
    } else {
      left = append(left, v)
    }
  }

  left = sort(left)
  right = sort(right)

  sorted := append(left, pivot)
  sorted = append(sorted, right...)

  return sorted
}


func main() {
  sc.Split(bufio.ScanWords)
  n := next()
  k := next()
  arrP := make([]int, n, n)
  arrSum := make([]int, n-k+1, n-k+1)
  maxSum := arrSum[0]
  maxArrIndex := 0
  
  for i := 0; i < n; i++ {
    arrP[i] = next()
    if i < k {
      arrSum[0] += arrP[i]
    } else {
      arrSum[i-k+1] = arrSum[i-k] + arrP[i] - arrP[i-k]
      if arrSum[i-k+1] > maxSum {
        maxSum = arrSum[i-k+1]
        maxArrIndex = i-k+1
      }
    }
  }
  
  ex := 0.0
  for i := maxArrIndex; i < maxArrIndex+k; i++ {
    ex += float64(arrP[i]+1) / 2.0
  }
  
  fmt.Println(ex)
}

Measured memory_bytes: 4480
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
const int N=3005,P=1e9+7,inv2=500000004;
inline void Add(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))if(y&1)res=mul(res,x);
	return res;
}
struct node{int x,y;}p[N];
int f[N][N],g[2][N],ans[2][N][N],a[N];
int n,q,res;
//void solve1(int pos){
//	fd(t,q,1){
//		int x=p[t].x,y=p[t].y;
//		fp(i,1,n)g[0][i]=g[1][i]=0;
//		fp(i,1,n)g[0][i]=add(f[x][i],f[y][i]),g[1][i]=add(f[i][x],f[i][y]);
//		int c=f[x][y],d=f[y][x];
//		fp(i,1,n)f[x][i]=f[y][i]=g[0][i],f[i][x]=f[i][y]=g[1][i];
//		f[x][y]=f[y][x]=add(c,d);
//	}
//	fp(i,1,n)fp(j,1,n)ans[pos][i][j]=f[i][j];
//}
void solve(int pos){
	int tag=1;
	fd(t,q,1){
		tag=mul(tag,2);
		int x=p[t].x,y=p[t].y;
		fp(i,1,n)g[0][i]=g[1][i]=0;
		fp(i,1,n)g[0][i]=add(f[x][i],f[y][i]),g[1][i]=add(f[i][x],f[i][y]);
		int c=f[x][y],d=f[y][x];
		fp(i,1,n)f[x][i]=f[y][i]=mul(g[0][i],inv2),f[i][x]=f[i][y]=mul(g[1][i],inv2);
		f[x][y]=f[y][x]=mul(add(c,d),inv2),f[x][x]=f[y][y]=0;
	}
	fp(i,1,n)fp(j,1,n)ans[pos][i][j]=mul(f[i][j],tag);
}
void init(){
	fp(i,1,n)fp(j,1,n)f[i][j]=0;
	fp(i,1,n)fp(j,i+1,n)f[i][j]=1;
	solve(0);
	fp(i,1,n)fp(j,1,n)f[i][j]=0;
	fp(i,1,n)fp(j,1,i-1)f[i][j]=1;
	solve(1);
}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),q=read();
	fp(i,1,n)a[i]=read();
	fp(i,1,q)p[i].x=read(),p[i].y=read();
	init();
	fp(i,1,n)fp(j,i+1,n)Add(res,a[i]==a[j]?0:a[i]>a[j]?ans[0][i][j]:ans[1][i][j]);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 106752
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    sort(rall(a));
    ll ans = a[0];
    int now = 1;
    n -= 2;
    while(n > 0) {
        if(n >= 2) {
            n -= 2;
            ans += a[now]*2;
            now++;
        } else {
            ans += a[now];
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3992
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#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;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >


int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
void solve(){
    int x,y;
    cin>>x>>y;
    rep1(i,0,x){
        int ans=(i*2)+(x-i)*4;
        if(ans==y){
            cout<<"Yes"<<endl;
            return;
        }
    }
    cout<<"No"<<endl;
}

signed main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("data.in","r",stdin);
        freopen ("data.out","w",stdout);
    #endif*/
    int t;
    t=1;
    while(t--){
        solve();
    }

     return 0;

}
///Alhamdulillah




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

int main(){

    const long long int md = 1000000007;
    int N;
    cin >> N;
    vector<long long int> A(N);
    vector<long long int> A_cumu(N);
    rep (i, N){
        cin >> A[i];
        if (i == 0) A_cumu[0] = A[0];
        else A_cumu[i] = (A_cumu[i-1] + A[i])%md;
    }

    long long int ans = 0;
    for (int i = 1; i < N; i++){
        ans += (A[i]*A_cumu[i-1])%md;
        ans %= md;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6432
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    ll n, m; cin >> n >> m;
    vector <ll> adj[n+10];
    for (ll i=0; i<m; i++) {
        ll a, b; cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    ll ans[n+2] = {-1};
    bool vis[n+2] = {false};
    queue <ll> q; q.push(1); vis[1] = true;
    while (!q.empty()) {
        ll s = q.front(); q.pop();
        for (auto u: adj[s]) {
            if (vis[u]) continue;
            vis[u] = true;
            ans[u] = s;
            q.push(u);
        }
    }
    for (ll i=2; i<=n; i++) {
        if (ans[i]==-1) {
            nout("No"); return;
        }
    }
    
    nout("Yes");
    for (ll i=2; i<=n; i++) {
        nout(ans[i]);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

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

using namespace std;

int main()
{
    int n,i,k,x,cnt=0;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>x;
        if(x>=k)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
# coding:utf-8

import sys

input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


H, W, D = inpl()

num_coordinate = {}
for i in range(H):
    w = inpl()
    for j in range(W):
        num_coordinate[w[j]] = (i, j)

c_sum = {}
for d in range(1, D + 1):
    c_sum[d] = [0]

for d in range(1, D + 1):
    for n in range(d + D, H * W + 1, D):
        c_sum[d].append(c_sum[d][-1] + abs(num_coordinate[n][0] - num_coordinate[n - D][0])
                        + abs(num_coordinate[n][1] - num_coordinate[n - D][1]))

Q = int(input())
for _ in range(Q):
    l, r = inpl()
    index = (l - 1) % D + 1
    index_l, index_r = (l - 1) // D, (r - 1) // D

    print(c_sum[index][index_r] - c_sum[index][index_l])


Measured memory_bytes: 39132
package main

import "fmt"

var r, s, p int
var (
	handMap = map[rune]int{
		'r': 0,
		's': 1,
		'p': 2,
	}
)

func main() {
	var N, K int
	var S string
	fmt.Scan(&N, &K)
	fmt.Scan(&r, &s, &p)
	fmt.Scan(&S)
	T := []rune(S)

	count := 0

	for k := 0; k < K; k++ {
		// mod K = k
		var hands []int
		for i := k; i < N; i += K {
			hands = append(hands, handMap[T[i]])
		}
		ll := len(hands)
		dp := make([][]int, 3)
		dp[0] = make([]int, ll)
		dp[1] = make([]int, ll)
		dp[2] = make([]int, ll)

		dp[0][0] = score(0, hands[0])
		dp[1][0] = score(1, hands[0])
		dp[2][0] = score(2, hands[0])
		for i := 1; i < ll; i++ {
			op := hands[i]
			dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + score(0, op)
			dp[1][i] = max(dp[2][i-1], dp[0][i-1]) + score(1, op)
			dp[2][i] = max(dp[0][i-1], dp[1][i-1]) + score(2, op)
		}
		myScore := max3(dp[0][ll-1], dp[1][ll-1], dp[2][ll-1])
		count += myScore
	}
	fmt.Println(count)
}

// グー 0, ちょき 1, パー 2
func score(me, op int) int {
	// draw
	if me == op {
		return 0
	}
	// lose
	if (me+1)%3 != op%3 {
		return 0
	}
	if me == 0 {
		return r
	} else if me == 1 {
		return s
	}
	return p
}

func max3(a, b, c int) int {
	return max(a, max(b, c))
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 7536