akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,K,q;
ll dp[5005][5005];
ll tp[5005];

ll get(int f,int t){
	if(f>=0){
		return (tp[t]-tp[f]+MOD)%MOD;
	}else{
		return (tp[K*2]-tp[K*2+f]+tp[t]+MOD)%MOD;
	}
}

int main(void){
	scanf("%d%d%d%d",&n,&m,&K,&q);
	dp[0][0]=1;
	for(int i=0;i<=m;i++){
		memset(tp,0,sizeof(tp));
		for(int j=0;j<2*K;j++){
			for(int k=0;k<n/(2*K);k++){
				tp[j+1]+=dp[i][k*(2*K)+j];
				tp[j+1]%=MOD;
			}
		}
		for(int j=0;j<2*K;j++){
			tp[j+1]+=tp[j];
			tp[j+1]%=MOD;
		}
		for(int j=0;j<2*K;j++){
			for(int k=0;k<n/(2*K);k++){
				//printf("%d %d %d %lld\n",i,j,k,get(j,j+K));
				dp[i+1][k*(2*K)+j]=get(j-K+1,j+1);
				//printf("%d %d %d %d %lld\n",i+1,k*(2*K)+j,j-K+1,j+1,dp[i+1][k*(2*K)+j]);
			}
		}
	}
	for(int i=0;i<q;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		int dif=(c-a+n)%n;
		printf("%lld\n",dp[b][dif]);
	}
	return 0;
}


Measured memory_bytes: 198808
#include <iostream>

int main(){
	int a, b, c, d;
	std::cin >> a >> b >> c >> d;

	int turn = 0;
	while(!(a <= 0 || c <= 0)){
		if(turn % 2 == 0){
			c -= b;
		}
		else{
			a -= d;
		}

		++turn;
	}

	if(turn % 2 == 0){
		std::cout << "No" << std::endl;
	}
	else{
		std::cout << "Yes" << std::endl;
	}
	
	return 0;
}


Measured memory_bytes: 3640
a, b = map(int, input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return set(a)
f1 = prime_factorize(a)
f2 = prime_factorize(b)

print(len(f1.intersection(f1, f2)) + 1)

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
using namespace std;
int seg[32];
void init(){
  for(int i=0;i<32;i++){
    seg[i]=0;
  }
}
void update(int x,int a){
  x+=15; int r=a-seg[x]; seg[x]=a;
  while(x>0){
    x=(x-1)/2;
    seg[x]+=r;
  }
}
int query(int a,int b,int k,int l,int r){
  if(a>r || l>b) return 0;
  if(a<=l && r<=b) return seg[k];
  int le=query(a,b,k*2+1,l,(1+r-1)/2);
  int ri=query(a,b,k*2+2,(l+r)/2,r);
  return le+ri;
}
int main(){
  for(int i=0;i<10;i++){
    int ro; scanf("%d",&ro);
    update(i,ro);
  }
  printf("%d\n",query(0,15,0,0,15));
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) for(int i=0;i<n;i++)
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vlai=valarray<int>;

#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
class Eratosthenes{
  public:
    int n, sqlim;
    vector<bool> prime;
    Eratosthenes(int N):n(N+1){
        sqlim=(int)ceil(sqrt(n));
        prime=vector<bool>(n,1); prime[0]=prime[1]=0;
        calc(); }

    void calc(){for(int i=2;i<=sqlim;i++) if(prime[i]) for(int j=i*i;j<=n;j+=i) prime[j]=0;}
    vi primeArray(int s=0, int l=10000){vi ret; for(int i=s;ret.size()!=l;i++) if(prime[i]) ret.push_back(i); return ret;}
};

int main(void){
    int n,p,l=100;
    Eratosthenes e(110000);
    while(cin>>n>>p,n!=-1){
        auto v=e.primeArray(n+1,l);
        vi res;
        rep(i,l)range(j,i,l)res.push_back(v[i]+v[j]);
        sort(all(res));
        cout<<res[p-1]<<endl;
    }
}

Measured memory_bytes: 3180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main(void)
{
	int x;
  	string str;
  	cin >> x;
  	cin >> str;
  	if(str.length()<=x){
        cout <<str <<endl;
    }else{
        string ry="";
        for(int a=0;a<x;a++){
            ry+=str[a];
        }
        cout << ry << "..."<<endl;
    }
    
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    ll na=0,nb=0;
    rep(i,0,n){
        ll a,b;cin>>a>>b;
        if(i==0){
            na=a;
            nb=b;
            continue;
        }
        ll c=na/a,d=nb/b;
        if(na%a!=0)c++;
        if(nb%b!=0)d++;
        c=max(c,d);
        na=a*c;nb=b*c;
    }
    cout<<na+nb<<endl;
    
}


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

int main()
{
    string a,b,c;
    cin >> a >> b >> c;
    cout << (a[a.length()-1]==b[0] && b[b.length()-1]==c[0] ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;

int main() {
  string s;
  cin >> s;
  string res = "";
  for (auto c : s) {
    if (c == '0') res += '0';
    else if (c == '1') res += '1';
    else {
      if (!res.empty()) res.pop_back();
    }
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 3632
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    println((n-2)*180)
end
main()

Measured memory_bytes: 109308
INF = 99999999
def to2d(n, ln)
  ar = Array.new(ln)
  for i in 0..(ln-1)
    ar[i] = n / (2**(ln-1-i))
    n -= ar[i]*(2**(ln-1-i))
  end
  return ar.reverse
end

h, w, k = gets.split.map(&:to_i)
c = h.times.map{gets.chomp.split("").map(&:to_i)}

cs = Array.new(h).map{Array.new(w+1,0)}
for i in 0..(h-1)
  for j in 0..(w-1)
    cs[i][j+1] = cs[i][j] + c[i][j]
  end
end

ans = INF
for div in 0..(2**(h-1)-1)
  sep = to2d(div, h-1)
  cnt = 0
  sep.each{|sp| cnt += sp}
  st = 1
  en = 1
  while en <= w
    sum = 0
    for rw in 0..(h-1)
      sum += cs[rw][en] - cs[rw][st-1]
      if sep[rw] == 1 || rw == h-1
        if sum > k
          if st < en
            cnt += 1
            st = en
            break
          else
            cnt = INF
            break
          end
        elsif rw == h-1
          en += 1
        end
        sum = 0
      end
    end
    break if cnt >= INF
  end
  ans = [ans,cnt].min
end
puts ans

Measured memory_bytes: 2300
from collections import deque
H,W,K=map(int,input().split())
A=[list(input())for _ in [0]*H]
for i,a in enumerate(A):
	if"S"in a:y,x=i,a.index("S")
d=1e9
Q=deque([(1,y,x)])
while Q:
	c,i,j=Q.popleft();d=min(d,i,j,H-i-1,W-j-1)
	if c>K:continue
	for h,w in((i+1,j),(i,j+1),(i-1,j),(i,j-1)):
		if 0<=h<H and 0<=w<W and A[h][w]==".":A[h][w]="";Q+=[(c+1,h,w)]
print(1--d//K)

Measured memory_bytes: 75356
#=
C:
- Julia version: 
- Author: abap
- Date: 2019-11-16
=#
N = parse(readline())
xy = []
for i in 1:N
    push!(xy,parse.(split(readline())))
end

get_length(a, b) = sqrt((a[1] - b[1])^2 + (a[2] - b[2])^2)

len = []
if N!=2
for i in 1:N
    for j in i+1:N
        push!(len,get_length(xy[i],xy[j]))
    end
end
println(sum(len)/(N/2))
else
    println(get_length(xy[1],xy[2]))
end

#=o = factorial(N-1)
oo = o*(N-1)

sums = sum(len.*oo)

println(sums/factorial(N))
=#


Measured memory_bytes: 123784
from math import sqrt

def fact(n):
    insu = []
    for i in range(2,int(sqrt(n))+1):
        if n % i == 0:
            while n % i == 0:
                n //= i
                insu.append(i)
        if n == 1:
            break
    if n > 1:
        insu.append(n)
    return insu

def main():
    N,P = map(int,input().split())
    insu = fact(P)
    insu_set,insu_list,pt = set(),[],0
    for i in range(len(insu)):
        if insu[i] not in insu_set:
            insu_set.add(insu[i])
            insu_list.append([insu[i],1])
            pt += 1
        else:
            insu_list[pt-1][1] += 1
    for i in range(len(insu_list)):
        insu_list[i][1] //= N

    ans = 1
    for a,b in insu_list:
        ans *= a**b
    print(ans)

if __name__ =="__main__":
    main()


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

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

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

    size_t N, K;
    cin >> N >> K;

    vector<int64_t> h(N);
    for (auto &hi: h) cin >> hi;

    vector<int64_t> dp(N + K + 1, LINF);
    dp[0] = 0;
    for (size_t i = 0; i < N; ++i) {
        for (size_t j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }

    cout << dp[N - 1] << "\n";

    return 0;
}


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

int main(){
	string s;
	cin >> s;
	int counter = 0;
	REP(i,3){
		if(s[i] == 'o')counter++;
	}
	cout << 700 + 100 * counter << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
s = []
c = []

for i in range(M):
    a, b = map(int, input().split())
    s.append(a)
    c.append(b)

ans = [None]*N

for i in range(M):

    if s[i] == 1 and c[i] == 0 and N != 1:
        print(-1)
        exit()
    if ans[s[i]-1] == None:
        ans[s[i]-1] = c[i]
    elif ans[s[i]-1] == c[i]:
        continue
    else:
        print(-1)
        exit()

if N == 1:
    if ans[0] == None:
        ans[0] = 0
else:
    if ans[0] == None:
        ans[0] = 1
    for i in range(1, N):
        if ans[i] == None:
            ans[i] = 0

print(*ans, sep="")


Measured memory_bytes: 3064
def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    s = input().rstrip()

    ans = 1000
    for i in range(len(s) - 2):
        num = int(s[i:i+3])
        if ans > abs(753 - num):
            ans = abs(753 - num)

    print(ans)



if __name__ == "__main__":
    resolve()


Measured memory_bytes: 80048
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);

#define l_ength size

ll MOD;

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[6060][13000];

int main(void){
	int n,i,j;
	ll ans = 0ll;
	std::cin >> n >> MOD;
	n *= 3;
	dp[0][6500] = 1ll;
	for(i=0; i<n; ++i){
		for(j=500; j<=12500; ++j){
			add_mod(dp[i+1][j-1],dp[i][j]);
			add_mod(dp[i+2][j+1],dp[i][j]*(i+1)%MOD);
			add_mod(dp[i+3][j],dp[i][j]*(i+1)*(i+2)%MOD);
		}
	}
	for(j=500; j<=6500; ++j){
		add_mod(ans,dp[n][j]);
	}
	std::cout << ans << std::endl;
	return 0;
}


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

int main(){

  int A,B;
  string ans = "No";
  cin >>A>>B;

  for(int i = 1;i<=3;i++){
    if((A*B*i)%2 != 0){
      ans = "Yes";
    }

  }

  cout <<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,pn,n,j;
  char dig[9];
  scanf("%d",&pn);
  for(i=0;i<pn;i++){
    printf("Case %d:\n",i+1);
    scanf("%d",&n);
    for(j=0;j<10;j++){
      sprintf(dig,"%08d",n*n);
      dig[6]='\0';
      n=atoi(dig+2);
      printf("%d\n",n);
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;

using namespace std;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int n, a;
	vi c(3, 0);
	cin >> n;
	REP(i, n) {
		cin >> a;
		c[a % 3]++;
	}

	if (c[1] + c[2] == 0) {
		cout << 1 << endl;
	}
	else {
		int m = min(c[1], c[2]);
		c[1] -= m;
		c[2] -= m;
		int ans = c[0] + 2*m;
		ans += max(min(3, c[1]), min(3, c[2]));
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 99999999999999
#define MAX_V 100010
#define MAX_E 2019

    /*Solve*/

int main(){
    ll k,a,b;
    cin >> k >> a >> b;
    ll ans;
    ll c=(k-a+1)/2;
    if(1<b-a){
        ans=c*(b-a)+k-2*c+1;
    }else ans=k+1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;

int main(void)
{
	int N, M; cin >> N >> M;
	vector<int> route(N, 0);
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		route[a - 1]++;
		route[b - 1]++;
	}

	rep(i, 0, N)cout << route[i] << endl;

	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
min = 100000
for a in 1..(n/2)
  b = n - a
  sum = 0
  a.to_s.chars{|c|
    sum +=c.to_i
  }
  b.to_s.chars{|c|
    sum +=c.to_i
  }
  min = [min, sum].min
end
puts min

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

void countingsort(unsigned short *,unsigned short *,int n);

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;
  
  scanf("%d", &n);
  
  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  countingsort(A,B,n);
  for(i=1;i<=n;i++){
    if(i==n){printf("%d\n",B[i]);}
    else{printf("%d ",B[i]);}
  }
  



return 0;
}

void countingsort(unsigned short *A,unsigned short *B,int n){
  int i,j=1,C[2000000];
  for(i=0;i<=VMAX;i++){
    C[i]=0;
  }
  
  
  for(j=1;j<=n;j++){
    C[A[j]]++;
  }
  
  
  for(i=1;i<=VMAX;i++){
    C[i]=C[i]+C[i-1];
  }
  
  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
}



Measured memory_bytes: 9712
<?php
fscanf(STDIN, '%d %d %d', $num, $min, $max);
$res = 0;
for ($i = 0; $i < $num; $i++) {
	fscanf(STDIN, '%d', $t);
	if ($t < $min || $t >= $max) {
		$res++;
	}
}
echo $res.PHP_EOL;

Measured memory_bytes: 3452
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;
 
int main()
{
    int N; cin >> N;
    int x1 = 0, y1 = 0, t1 = 0;
    for (int i = 0; i < N; i++)
    {
        int x2,y2,t2; cin >> t2 >> x2 >> y2;
        int dist = abs(x2-x1)+abs(y2-y1);
        if(dist <= t2-t1 and dist%2 == (t2-t1)%2){
            x1 = x2; y1 = y2; t1 = t2;
        }
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
class AGC034_B {
    static void Main(string[] args) {
        string S = Console.ReadLine();
        long ans = 0;
        int BC = 0;
        for (int i = S.Length - 1; i >= 0; i--) {
#if LOCAL_ENVIRONMENT
        Console.Error.WriteLine($"i:{i}");
#endif
            if (i >= 1 && S[i] == 'C' && S[i - 1] == 'B') { i--; BC++; }
            else if (S[i] == 'A') {
                ans += BC;
            } else BC = 0;
#if LOCAL_ENVIRONMENT
        Console.Error.WriteLine($" i:{i}, ans:{ans}, BC:{BC}");
#endif
        }
        Console.WriteLine(ans);
    } //Main
}


Measured memory_bytes: 13664
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int P[40010],A[40010],B[40010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi();
	for(int i=1;i<=n;++i)A[i]=i*20000,B[i]=(n-i+1)*20000;
	for(int i=1;i<=n;++i)P[i]=gi(),A[P[i]]-=n-i;
	for(int i=1;i<=n;++i)printf("%d ",A[i]);puts("");
	for(int i=1;i<=n;++i)printf("%d ",B[i]);puts("");
	return 0;
}


Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = ReadLongs();
            var N = inputs[0];
            var Q = inputs[1];

            var tree = Enumerable.Repeat(0, (int)N)
                .Select(x => new List<long>())
                .ToArray();
            for (var i = 0; i < N - 1; i++)
            {
                inputs = ReadLongs();
                var a = inputs[0];
                var b = inputs[1];
                tree[a - 1].Add(b - 1);
                tree[b - 1].Add(a - 1);
            }

            var counter = new long[N];
            for (var i = 0; i < Q; i++)
            {
                inputs = ReadLongs();
                var p = inputs[0];
                var x = inputs[1];
                counter[p - 1] += x;
            }

            var isRooted = new bool[N];
            var queue = new Queue<int>();
            queue.Enqueue(0);
            isRooted[0] = true;
            while (queue.Count > 0)
            {
                var root = queue.Dequeue();
                foreach (var node in tree[root])
                {
                    if (isRooted[node]) continue;
                    counter[node] += counter[root];
                    queue.Enqueue((int)node);
                    isRooted[node] = true;
                }
            }

            return string.Join(" ", counter);
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 53884
n = int(input())
a = list(map(int,input().split()))
odd = True
ans = 0
def half(x):
    return x/2
while odd:
  if all(i%2 == 0 for i in a):
    ans+=1
    a = list(map(half,a))
  else:
    odd = False
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){

  int a[4],b[4],n,m;

  while(cin >> a[0]){
    n = 0;
    m = 0;
    cin >> a[1] >> a[2] >> a[3];
    for(int i=0;i<4;i++){
      cin >> b[i];
      if(a[i] == b[i]) n++;
      for(int j=0;j<4;j++){
	if(b[i] == a[j]) m++;
      }
    }
    
    cout << n << " " << (m-n) << endl;
  }
  return (0);
}

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

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

int findGCD(int a, int b, int c)
{
    return gcd(a, gcd(b, c));
}

int main(){

 int k;
 cin>>k;
 int sum = 0;

 for(int a = 1; a <= k ; a++)
 {
 for(int b = 1; b <= k ; b++)
 {
 for(int c = 1; c <= k ; c++)
 { 
     sum += findGCD(a,b,c);

 }
 }
 
 }
 
 cout<<sum;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i = n; i < (int) N; i++)
#define p(s)		cout<<(s)<<endl
using namespace std;

int main() {
	string s;
	cin>>s;
	int numg=count(s.begin(),s.end(),'g');
	p(numg-((int)s.size()+1)/2);
	return 0;
}


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

using namespace std;

int main()
{
  long long a, b;
  
  scanf("%lld %lld", &a, &b);
  
  long long g = __gcd(a, b);
  
  int ans = 1;
  for (long long i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      ans++;
      while (g % i == 0) g /= i;
    }
  }
  
  if (g != 1) ans++;
  
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,s[10005],ans,p[10005],x[10005];
vector<int>g[10005];
priority_queue<P,vector<P>,greater<P> >q;
int main(void){
	scanf("%lld",&n);
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		g[--a].PB(--b);
		g[b].PB(a);
		s[a]++;
		s[b]++;
	}
	for(int i=0;i<n;i++)scanf("%lld",x+i);
	sort(x,x+n);
	int k=0;
	for(int i=0;i<n;i++)q.push(P(s[i],i)),p[i]=-1;
	while(!q.empty()){
		ll a=q.top().F,b=q.top().S;
		q.pop();
		if(s[b]!=a||p[b]!=-1)continue;
		ans+=s[b]*x[k];
		p[b]=k++;
		for(int i=0;i<g[b].size();i++){
			int u=g[b][i];
			s[u]--;
			q.push(P(s[u],u));
		}
	}
	printf("%lld\n",ans);
	for(int i=0;i<n;i++){
		printf("%d",x[p[i]]);
		if(i==n-1)printf("\n");
		else printf(" ");
	}
}

Measured memory_bytes: 1660
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
int main(){
int a[4]={6000,4000,3000,2000};
rep(i,4){
int in1,in2;
cin>>in1>>in2;
cout<<a[in1-1]*in2<<endl;
}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,r;
    cin>>s;
    int moves=0;
    int i=1;
    int f=0;
    while(s.size()>2&&i<s.size())
    {
         f=0;
        if((i+1)<s.size())
        {
            if(s[i-1]!=s[i+1])
            {
                f=1;
                s.erase(i,1);
                moves++;
            }
    
        }
        if(!f)
            i++;
        else
            i=max(1,i-1);

    }
    if(moves%2)
        printf("First");
    else
        printf("Second");
    return 0;
}


Measured memory_bytes: 512
N , M = map(int,input().split())
o = []
n = []
for i in range(M):
    a,b=map(int,input().split())
    if b == N:
        n.append(a)
    elif a == 1:
        o.append(b)

if set(n) & set(o):
    print ('POSSIBLE')
else:
    print ('IMPOSSIBLE')

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

int main(){
  int a,b,res;
  cin >> a >> b;
  for(int i=a;i<b+1;i++){
    int s=i%10;
    int t=(i/10000)%10;
    int u=(i/10)%10;
    int v=(i/1000)%10;
    if(s==t&&u==v){
      res++;
    }
  }
  cout << res << endl;
  return 0;
}


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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N, K;
    cin >> N >> K;
    
    if((N+1)/2 >= K)
        cout << "YES\n";
    else
        cout << "NO\n";

    return 0;
}

Measured memory_bytes: 256
from math import gcd
from collections import defaultdict

upper = 10**6
N = int(input())
A = list(map(int, input().split()))
num = defaultdict(int)

g = 0
for a in A:
    g = gcd(g, a)
    num[a] += 1

isStopped = False
for i in range(2, upper+1):
    x = 0
    for j in range(i, upper+1, i):
        x += num[j]
    if x >= 2:
        isStopped = True
        break

if not isStopped:
    print("pairwise coprime")
elif g == 1:
    print("setwise coprime")
else:
    print("not coprime")



Measured memory_bytes: 264948
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		while(true)
		{
			int w = sc.nextInt();
			if(w == 0)break;
			int h = sc.nextInt();
			int x = 1;
			int y = 1;
			int facing = 0; //UP RIGHT DOWN LEFT!
			
			while(true)
			{
				String com = sc.next();
				facing = facing%4;
				if(facing < 0)facing += 4;
			
				if(com.equals("STOP"))
				{
					System.out.println(x + " " + y);
					break;
				}
				else if(com.equals("RIGHT"))
				{
					facing += 1;
				}
				else if(com.equals("LEFT"))
				{
					facing -= 1;
				}
				if(com.equals("FORWARD"))
				{
					int arg = sc.nextInt();
					if(facing == 0)y+=arg;
					if(facing == 1)x+=arg;
					if(facing == 2)y-=arg;
					if(facing == 3)x-=arg;
				}
				else if(com.equals("BACKWARD"))
				{
					int arg = sc.nextInt();
					if(facing == 0)y-=arg;
					if(facing == 1)x-=arg;
					if(facing == 2)y+=arg;
					if(facing == 3)x+=arg;
				}
				
				if(x > w) x = w;
				if(y > h) y = h;
				if(x < 1) x = 1;
				if(y < 1) y = 1;
			}
		}
				

	}

}



Measured memory_bytes: 36468
#include <iostream>
#include <string> 
#include <vector>
#include <queue>
#define MAX 100000
using namespace std;

int main(void){
  vector<int> v[MAX];
  bool visited[MAX];
  int N,M;
  cin >> N >> M;
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    v[a-1].push_back(b-1);
    v[b-1].push_back(a-1);
  }
  for(int i=0;i<N;i++){
    visited[i] = false;
  }
  int num=0;
  for(int i=0;i<N;i++){
    if(!visited[i]){
      queue<int> q;
      q.push(i);
      visited[i] = true;
      while(q.size() > 0){
        int node = q.front();
        visited[node] = true;
        q.pop();
        for(int j=0;j<v[node].size();j++){
          if(!visited[v[node][j]]){
            q.push(v[node][j]);
          }
        }
      }
      num++;
    }
  }
  cout << num - 1 << endl;
  return 0;
}

Measured memory_bytes: 8988
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a;
    cin>>a;
    int b,c;
    b=a/100;
    c=a%100;
    if(0<b && b<13){
        if(0<c && c<13){
            cout<<"AMBIGUOUS"<<endl;
            return 0;
        }
        else{
            cout<<"MMYY"<<endl;
            return 0;
        }
    }
    else{
        if(0<c && c<13){
            cout<<"YYMM"<<endl;
            return 0;
        }
        else{
            cout<<"NA"<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h1,s1,h2,s2;

    cin >> h1 >> s1 >> h2 >> s2;
    while(h1 > 0 && h2>0){
        h2-=s1;
        if(h2<=0){
            cout << "Yes"; return 0;
        }
        h1-=s2;
        if(h1<=0){
            cout << "No"; return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3592
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 1e5+5;

int a[N][3], dp[N][3];

signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    	cin >> a[i][0] >> a[i][1] >> a[i][2];
    for (int i = 1; i <= n; i++) {
    	for (int j = 0; j < 3; j++) {
    		dp[i][j] = 0;
    		for (int k = 0; k < 3; k++) {
    			if (k == j) continue;
    				dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
    		}
    	}
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]});
    return 0;
}

Measured memory_bytes: 4992
//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];

ll dp[N];

void solve(){
    ll n, W, x, y;
    cin >> n >> W;
    for(int i = 0; i < n; ++i){
        cin >> x >> y;
        for(int j = W; j >= x; --j){
            dp[j] = max(dp[j], dp[j - x] + y);
        }
    }
    cout << dp[W];
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro

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

const int mod = 1e9 + 7;
const int MN = 100010;

int exp(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) {
    return exp(x, mod - 2);
}
int fact[MN], invf[MN];
int comb(int n, int k) {
    return 1LL * fact[n] * invf[k] % mod * invf[n - k] % mod;
}

int N;
int A[MN], psum[MN];

int main() {
    fact[0] = 1;
    for(int i = 1; i < MN; i++) {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    for(int i = 0; i < MN; i++) {
        invf[i] = inv(fact[i]);
    }

    scanf("%d", &N);

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

    for(int i = 1; i <= N; i++) {
        psum[i] = 1LL * fact[i] * fact[N - i - 1] % mod * comb(N, i + 1) % mod;
        psum[i] += psum[i - 1];
        psum[i] %= mod;
    }

    int ans = 0;
    for(int i = 0; i < N; i++) {
        ans += 1LL * A[i] * (psum[i] + psum[N - 1 - i]) % mod;
        ans %= mod;
        ans += 1LL * A[i] * fact[N] % mod;
        ans %= mod;
    }
    printf("%d", ans);
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
	int a;
	while(cin>>a,a){
		vector<vector<int> >s;
		for(int b=0;b<a;b++){
			vector<int>c(3);
			cin>>c[0]>>c[1]>>c[2]; 
			s.push_back(c);
		}
		for(int d=0;d<s.size();d++){
		int n=0;
		for(int e=0;e<s.size();e++){ 
			if(s[d][1]>=s[e][1]&&s[d][1]<s[e][2])n+=s[e][0];
			}
			if(n>150){cout<<"NG"<<endl;break;}
			if(s.size()-1==d){cout<<"OK"<<endl;}
		}
	}
}

Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{
        int S;
        int h, m, s;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        S = Integer.parseInt(br.readLine());

        h = S / (60 * 60);
        S = S % (60 * 60);
        m = S / 60;
        s = S % 60;
        System.out.println(h + ":" + m + ":" + s);

    }

}

Measured memory_bytes: 24220
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        int[] a = new int[N];
        for(int i = 0; i<N; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(a);
        int ans = 0;
        for(int i = 0; i<K; i++) {
            ans += a[a.length - 1 - i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22736
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int H, A;
  cin >> H >> A;
  if (H % A != 0)
  {
    H = H / A + 1;
  }
  else
  {
    H /= A;
  }
  cout << H << endl;
}

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

using namespace std;

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

	int a[n+1], b[n+1], c[n];

	for(int i=1;i<=n;i++)
		cin >> a[i];
	for(int i=1;i<=n;i++)
		cin >> b[i];
	for(int i=1;i<n;i++)
		cin >> c[i];

	int ans = 0;
	ans = b[a[1]];
	for(int i=2;i<n+1;i++)
	{
		int dish = a[i];
		int prev_dish = a[i-1];
		ans += b[dish];
		// cout << "dish: " << dish << " " << "prev_dish: " << prev_dish << "\n";
		// see(prev_dish);
		// cout << "\n\n\n";
		if(dish-prev_dish == 1)
		{
			ans += c[prev_dish];
		}
	}

	cout << ans << "\n";
}

Measured memory_bytes: 256
#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 all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }
 
 
const long long MAXN = 1e9 + 9;
const long long SIZE = 3e5 + 5;
const long long MOD = 1e9 + 7;


int x;


int main() { speedhack()

	cin >> x;

	if (x >= 30)
		cout << "Yes";
	else 
		cout << "No";
		
	return 0;
}


Measured memory_bytes: 3700
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define N 301
int n,m;
int a[N][N];
int num[N];
bool v[N];
int ans;
int main(){
	scanf("%d%d",&n,&m);
	int s;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j)
			scanf("%d",&a[i][j]);
		int b=a[i][1];
		if(++num[b]>ans){
			ans=num[b];
			s=b;
		}
	}
	for(int i=1;i<m;++i){
		memset(num,0,sizeof num);
		v[s]=1;
		int tans=0;
		for(int j=1;j<=n;++j){
			for(int k=1;k<=m;++k){
				int b=a[j][k];
				if(!v[b]){
					if(++num[b]>tans){
						tans=num[b];
						s=b;
					}
					break;
				}
			}
		}
		ans=min(ans,tans);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 512
def main():
    N, M = map(int, input().split())
    inf = int(1e10)
    dp = [inf] * (1 << N) #1をNだけシフトする 2**B
    #鍵をビットで表す　dp[i]は鍵の状態iにできる最小費用を
    dp[0] = 0
    bits = set()
    bits.add(0)
    for i in range(M):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))
        # cを状態keyに変換
        key = 0
        for t in c:
            key += 1 << (t - 1)
        # bits内のbitとkeyのORを更新
        # 更新したbitはbitsに追加
        add_bits = set()
        for bit in bits:
            tmp = bit | key
            if dp[bit] + a < dp[tmp]:
                dp[tmp] = dp[bit] + a
                add_bits.add(tmp)
        bits |= add_bits
    
    if dp[(1 << N) - 1] == inf:
        print(-1)
    else:
        print(dp[(1 << N) - 1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 3836
import sys
input = sys.stdin.readline
N=int(input())
H=list(map(int,input().split()))
counts=[]
count=0
for i in range(N-1):
  if H[i] >= H[i+1]:
    count+=1
    if i==N-2:
      counts.append(count)
  elif H[i] < H[i+1]:
    counts.append(count)
    count=0
counts.sort()
if N==1:
  print(0)
else:
  print(counts[-1])

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

using namespace std;

int solve(const int stones_height[], int memo[], const int &n){
    int ans;
    if(memo[n] != -1) ans = memo[n];
    else if(n == 1) return 0;
    else{
        ans = abs(stones_height[n] - stones_height[n - 1]) + solve(stones_height, memo, n - 1);
        if(n - 2 >= 1){
            ans = min(ans, abs(stones_height[n] - stones_height[n - 2]) + solve(stones_height, memo, n - 2));
        }
    }
    return memo[n] = ans;
}

int main(){
    int n;
    while(scanf("%d", &n) != EOF){
        int stones_height[n + 1], memo[n + 1];
        for(int i = 0; i < n; i++){
            scanf("%d", &stones_height[i + 1]);
            memo[i + 1] = -1;
        }
        printf("%d\n", solve(stones_height, memo, n));
    }
    return 0;
}

Measured memory_bytes: 12328
"use strict";
function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");

  let X = inputs[0];
  switch (X) {
    case "3":
    case "5":
    case "7":
      console.log("YES");
      break;
    default:
      console.log("NO");
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
n = int(input())
w = [input().rstrip() for i in range(n)]
use = [w[0]]
for i in range(1,n):
  if w[i][0] == w[i-1][-1] and w[i] not in use:
    use.append(w[i])
  else:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<cmath>
#define INF 9999999
using namespace std;
int a,b,c;
int main(){
	while(cin>>a>>b){
		while(b!=0){
			c=a%b;
			a=b;
			b=c;
		}
		cout<<a<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXN 60
#define MAXS 3600
int n;
char* strings[MAXN];
int min(const int a, const int b) {
    return a < b ? a : b;
}

void read_str(int idx) {
    char buf[MAXN];
    fgets(buf, MAXN, stdin);
    int len = strlen(buf);
    if(buf[len - 1] == '\n') buf[--len] = '\0';
    strings[idx] = strdup(buf);
}
int solve(char* res) {
    int t = 0;
    int cnt[26];
    for(int i = 0; i < 26; i++) cnt[i] = 1e9;
    for(int i = 0; i < n; i++) {
        int currcnt[26] = {0};
        int len = strlen(strings[i]);
        for(int j = 0; j < len; j++) 
            currcnt[strings[i][j] - 'a']++;
        for(int j = 0; j < 26; j++) cnt[j] = min(cnt[j], currcnt[j]);
    }
    for(int i = 0; i < 26; i++)
        for(int j = 0; j < cnt[i]; j++)
            res[t++] = i + 'a';
    res[t] = '\0';
    return t;
}
int main(void) {
    scanf("%d\n", &n);
    char res[MAXS];
    for(int i = 0; i < n; i++) read_str(i);
    solve(res);
    puts(res);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int ans = 0;
	if (n <= k) {
		ans = n * x;
	}
	else
	{
		ans = k * x;
		ans += (n - k)*y;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  vector<vector<int>> G(200000);
  int N, M;
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  vector<int> dist(200000, -1);
  vector<int> ans(200000);
  queue<int> q;

  dist.at(0) = 0;
  dist.at(1) = 0;
  q.push(1);

  while(!q.empty()){
    int v = q.front();
    q.pop();
    for(auto nv : G.at(v)){
      if(dist.at(nv) != -1) continue;
      dist.at(nv) = dist.at(v) + 1;
      q.push(nv);
      ans.at(nv) = v;
    }
  }

  cout << "Yes" << endl;
  for(int i = 2; i <= N; i++){
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 13688
#include <bits/stdc++.h>
//debug
#define vecprint(v) cout << "  vector: ";rep(i,v.size())cout << v[i] << " ";cout << endl;
#define setprint(s) cout << "  set: ";for(auto i=s.begin();i!=s.end();i++)cout << *i << " ";cout << endl;
#define mappairprint(s) cout << "  map: ";for(auto i=s.begin();i!=s.end();i++)cout << i->first << " " << i->second << endl;cout << endl;
//reader
#define r1(a) cin>>(a)
#define r2(a,b) cin>>(a)>>(b)
#define r3(a,b,c) cin>>(a)>>(b)>>(c)
//writer
#define w1(a) cout<<(a)<<" "
#define w2(a,b) cout<<(a)<<" "<<(b)<<" "
#define w3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "
#define wl1(a) cout<<(a)<<endl
#define wl2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wl3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
//variable definition
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
//roop
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define all(c) c.begin(),c.end()
//term
#define elif else if
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
using namespace std;
using ll = long long;
//const
constexpr double PI = 3.141592653589793238462643383279;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};



int main() {
  //input
  int n;
  cin >> n;
  
  int a[n] = {0};
  for(int i=1; i<n; i++) {
    int tmp;
    cin >> tmp;
    a[tmp-1]++;
  }
  
  rep(i,n) {
    cout << a[i] << endl;
  }
}

Measured memory_bytes: 4364
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
using namespace std;

int n, m;
bool f1[200001], tn[200001];
int main() {
    cin >> n >> m;
    for(int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        if(u == 1) f1[v] = 1;
        if(v == n) tn[u] = 1;
    }
    for(int i = 1; i <= n; i++)
        if(f1[i] && tn[i]) return puts("POSSIBLE") && 0;
    if(f1[n] || tn[1]) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
int main(){
FASTIO  
ll n,k;
cin>>n>>k;
ll ans=0;
for(ll i=k;i<=n+1;i++){
  ll a=((i)*(i-1))/2;
  ll b=((n*(n+1))/2)-(((n-i)*(n-i+1))/2);
  ans=((ans%mod)+(b-a+1)%mod)%mod;
}
cout<<ans;
return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
#define MOD 1000000007

ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main(){
    ll n;cin>>n;
    vector<ll> a(n);
    vector<ll> rain(n);
    For(i,n){
        cin>>a.at(i);
        rain.at(i)=0;
    }
    For(i,n){
        if(i%2==0){
            rain.at(0)+=a.at(i);
        }
        else{
            rain.at(0)-=a.at(i);
        }
    }
    cout<<rain.at(0)<<" ";
    For1(i,n){
        rain.at(i)=2*a.at(i-1)-rain.at(i-1);
        cout<<rain.at(i)<<" ";
    }
}

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

struct Student {
  int no, point;
  string city;

  // 演算子オーバーロードで比較関数を定義
  bool operator<(const Student& another) const {
    if (city != another.city)
      return city < another.city; // 高い順に並べたいので演算子を逆に
    if (point != another.point)
      return point > another.point; // 同様に比較演算子を反転
    return no < another.no;
  }
};

int main() {
  int n;
  cin >> n;
  vector<Student> vec(n);
  for (int i = 0; i < n; i++){
    vec[i].no = i+1;
    cin >> vec[i].city >> vec[i].point;
  }

  sort(vec.begin(), vec.end()); // operator< を使ってソートされる

  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i].no << endl;
  }
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val Sd = next()
    val T = next()
    fun match(s: String, t: String): Boolean {
        for (n in 0 until T.length)
            if (s[n] != '?' && s[n] != t[n]) return false
        return true
    }
    var ans = mutableListOf<String>()
    for (n in 0 until Sd.length - T.length + 1)
        if (match(Sd.substring(n until n + T.length), T)) {
            val S = Sd.map { it }.toCharArray()
            for (m in 0 until T.length) S[n + m] = T[m]
            for (m in 0 until Sd.length) if (S[m] == '?') S[m] = 'a'
            ans.add(S.joinToString(""))
        }
    if (ans.size == 0) return println("UNRESTORABLE")
    println(ans.sorted().first())
}


fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { Integer.parseInt(it) + d }
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map { it.toDouble() }


Measured memory_bytes: 36568
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

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

    int res = 0;
    int l = 0;
    int r = n-1;
    while(l<r){
        if(c[l]=='R') {
            l++;
        }
        else if(c[r]=='W'){
            r--;
        }
        else{
            res++;
            l++,r--;
        }
    }

    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3688
fun main(args: Array<String>) {
    val n = readInputLine().toInt()

    var ans = readInputLine().toLong()
    
    for (i in 2..n) {
        val t = readInputLine().toLong()
        val gcd = if (ans > t) gcd(ans, t) else gcd(t, ans)
        ans = ans / gcd * t
    }

    println(ans)
}
 
fun readInputLine(): String {
    return readLine()!!
}

fun gcd(a: Long, b: Long): Long {
    // a >= b とする
    if (b == 0L) {
        return a
    }
    return gcd(b, a % b)
}


Measured memory_bytes: 31840
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.ST                 as ST
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Foldable                  ( toList )
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Sequence                 as SQ
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n readString
toPair [x, y] = (x, y)

main = do
  [h, w] <- readInt
  print $ solve h w

solve h w | min h w == 1 = 1
          | otherwise    = ceiling (fromIntegral (h * w) / 2)


Measured memory_bytes: 380