akhauriyash/Code-Regression huggingface dataset:
// Problem : A - Plural Form
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define int long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define mod 998244353
#define bug cout<<"HY"<<endl
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define numize(A) A.numize(unique(A.begin(), A.end()) - A.begin())
typedef pair<int,int> P;
int power(int a,int b)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return (power((a*a)%mod,b/2))%mod;
    return (a*(power((a*a)%mod,b/2))%mod)%mod;
}
int modInv(int n)
{
    return power(n, MOD-2);
}
int nCr(int n, int r, int p=MOD)
{
   if (r==0)
      return 1;
    int Fact[n+1];
    Fact[0] = 1;
    for (int i=1 ; i<=n; i++)
    {
        Fact[i] = (Fact[i-1]*i)%p;
    }
    return (((Fact[n]* modInv(Fact[r])) % MOD) *(modInv(Fact[n-r]) % MOD)) % MOD;
}
double PI=3.14159265359;
void solve()
{
	string s;
	cin>>s;
	if(s.back()=='s')
	{
		s+='e';
		s+='s';
	}
	else
	{
		s+='s';
	}
	cout<<s<<endl;
	return;
}
int32_t main()
{
    boost;
    int  t=1;
    // cin>>t;
    while(t--)
    {
    	solve();
    }
}


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

int main() {
  int count1=0;
  int count2=0;
  int count3=0;
  int count4=0;
  for(int i=0;i<3;i++){
    int a,b;
    cin >>a>>b;
    if(a==1)
      count1++;
    if(a==2)
      count2++;
    if(a==3)
      count3++;
    if(a==4)
      count4++;
    if(b==1)
      count1++;
    if(b==2)
      count2++;
    if(b==3)
      count3++;
    if(b==4)
      count4++;
  }
  if((count1*count2*count3*count4)%3==0)
    cout<<"NO"<<endl;
  else
    cout<<"YES"<<endl;
}
    

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
nums = list(map(int, input().split()))

counter = defaultdict(list)
for i in range(len(nums)):
  counter[nums[i]].append(i)

total = 0
for _,v in counter.items():
  v = len(v)
  total += (v * (v-1)) // 2

for k in range(len(nums)):
  t = len(counter[nums[k]])
  print(total - t*(t-1)//2 + (t-1)*(t-2)//2)

Measured memory_bytes: 98636
import sys

INF = float('inf')

input = sys.stdin.readline


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


N, K = LIST()
h = LIST()

# DP配列を初期化
dp = [INF] * N

# 初期条件を入力
dp[0] = 0

# テーブルを更新 もらうDP
for i in range(1, N):
    x = max(0, i - K)
    dp[i] = min([dp_ + abs(h[i] - h_) for dp_, h_ in zip(dp[x:i], h[x:i])])

print(dp[N - 1])

Measured memory_bytes: 14012
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vi;

signed main()
{
    int n, k;
    cin >> n >> k;
    vi arr(n);
    int lo = 1, hi = 1;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
        hi = max(arr[i], hi);
    }
    while (lo < hi)
    {
        int mid = (lo + hi) >> 1;
        int cnt = 0;
        for (auto it:arr)
        {
            cnt += ((it + mid - 1) / mid) - 1;
        }
        if (cnt <= k)
        {
            hi = mid;
        }
        else
        {
            lo = mid + 1;
        }
    }
    cout << hi << endl;
}

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

int main () {
  int  a, b, c;
  cin >> a >> b >> c;
  
  if ( a+b == c || a+c == b || b+c == a ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define ll long long
using namespace std;
int main() {
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	cout << n / 2 + n % 2 << endl;
	return 0;
}


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

// THINK: INT vs LONG LONG?

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

	string s;
	cin >> s;
	cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << '\n';

	return 0;
}

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

using namespace std;

int main()
{
    long long k , a , b ;
    cin>>k>>a>>b ;
    long long now = 1ll ;
    if(a+1 < b)
    {
        now += min(k , a-1ll) ;
        k -= min(k , a-1ll) ;
        if(k <= 1)
            return cout<<now+k<<"\n" , 0 ;
        k -= 2 ;
        now = b ;
        if(k & 1)
        {
            --k ;
            return cout<<now - (k / 2ll * a) + (k / 2ll * b) + 1ll<<"\n" , 0 ;
        }
        else
            return cout<<now - (k / 2ll * a) + (k / 2ll * b)<<"\n" , 0 ;
    }
    else
        return cout<<now+k<<"\n" , 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
int main() {
string s1,s2,s3,s;
cin>>s1>>s2>>s3;
if( isupper(s2[0])&&s2.length()>=1&&s2.length()<=100 ){
        s=toupper(s1[0]);
        cout<<s;
        cout<<s2[0];
        s=toupper(s3[0]);
        cout<<s;

}
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,d;
	cin>>n>>d;
	ll ans=0;
	rep(i,n){
		ll x,y;
		cin>>x>>y;
		if(x*x+y*y<=d*d) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
const int inf=1e8;
using namespace std;
int main(){
  int a,b,c,d,e;
  while(cin>>a>>b>>c>>d>>e,a+b+c+d+e){
    c--;d--;e--;
    vector<vector<int> >cost(a,vector<int>(a));
    rep(i,a)rep(j,a){
      if(i==j)cost[i][j]=0;
      else cost[i][j]=inf;
    }
    rep(i,b){
      int f,g,h;
      cin>>f>>g>>h;
      f--;g--;
      cost[f][g]=h;
    }
    rep(k,a)rep(i,a)rep(j,a)
      cost[i][j]=min(cost[i][k]+cost[k][j],cost[i][j]);
    int mi=inf;
    rep(i,a)mi=min(mi,cost[c][i]+cost[i][d]+cost[i][e]);
    cout<<mi<<endl;
  }
}

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

int main()
{
    string as,bs;
    int a,b;
    cin >> a >> b;
    char a_ = '0' + a;
    char b_ = '0' + b;
    for( int i = 0; i < b; i++ )
    {
        as.push_back(a_);
    }

    for( int i = 0; i < a; i++ )
    {
        bs.push_back(b_);
    }

    if( as <= bs )
    {
        cout << as << endl;
    }
    else if( as > bs )
    {
        cout << bs << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cctype>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long Int;
typedef string::const_iterator Itr;

int P, Q, R;

int expression(Itr &itr);
int term(Itr &itr);
int factor(Itr &itr);
int letter(Itr &itr);

int _not(int n)
{
	if (n == 0)return 2;
	else if (n == 1)return 1;
	else return 0;
}

int _star(int x, int y)
{
	if (x == 0 || y == 0)return 0;
	else if (x == 1 || y == 1)return 1;
	else return 2;
}

int _plus(int x, int y)
{
	if (x == 0 && y == 0)return 0;
	else if (x == 2 || y == 2)return 2;
	else return 1;
}

int expression(Itr &itr) 
{
	int ret = term(itr);

	while (true)
	{
		if (*itr == '*')
		{
			itr++;
			ret = _star(ret, term(itr));

		}
		else if (*itr == '+')
		{
			itr++;
			ret = _plus(ret, term(itr));
		}
		else
		{
			break;
		}
	}
	return ret;
}

int term(Itr &itr)
{
	int ret;

	if (*itr == '-')
	{
		itr++;
		ret = _not(term(itr));
	}
	else
	{
		ret = factor(itr);
	}

	return ret;
}

int factor(Itr &itr)
{
	int ret;

	if (*itr == '(')
	{
		itr++;
		ret = expression(itr);
		itr++;
	}
	else
	{
		ret = letter(itr);
	}

	return ret;
}

int letter(Itr &itr)
{
	int ret = 0;

	if (*itr == 'P')
	{
		ret = P;
	}
	else if (*itr == 'Q')
	{
		ret = Q;
	}
	else if (*itr == 'R')
	{
		ret = R;
	}
	else if(isdigit(*itr))
	{
		ret = *itr - '0';
	}
	itr++;
	return ret;
}

int main()
{
	while (true)
	{
		string str;
		getline(cin, str);
		if (str[0] == '.')break;
		str.append("_");
		int count = 0;
		REP(i, 3)REP(j, 3)REP(k, 3)
		{
			P = i;
			Q = j;
			R = k;
			Itr begin = str.begin();
			int ans = expression(begin);
			if (ans == 2)
			{
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}


Measured memory_bytes: 3012
program remainder_minimization_2019
    implicit none
    integer(8):: l,r,c,i,j
    integer(8),parameter:: max_loop=2019
    c=2019
    read*,l,r
    do i=l, min(r,l+max_loop)-1
        do j=i+1,min(r,l+max_loop)
            c = min(c,mod(i*j,2019))
        end do
    end do
    print*, c
        
end program remainder_minimization_2019

Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int n;
  cin >> n;
  string input;
  cin >> input;
  
  vector<int> value(n+1);
  value[0] = 0;

  for(int i = 0; i < n; i++){
    
    if(input[i] == 'I'){
      value[i+1] = value[i] + 1;
    } else {
      value[i+1] = value[i] - 1;
    }
  }
  
  sort(value.begin(), value.end(), greater<int>());
  cout << value[0] << endl;
  return 0;
}

Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

# sys.setrecursionlimit(2147483647)
# INF = float("inf")
#
# N = int(sys.stdin.readline())
# S = [sys.stdin.readline().rstrip() for _ in range(N)]
# M = int(sys.stdin.readline())
# T = [sys.stdin.readline().rstrip() for _ in range(M)]
#
# ans = 0
# for s in set(S):
#     a = S.count(s)
#     b = T.count(s)
#     ans = max(ans, a - b, 0)
#
# print(ans)

A, B = list(map(int, sys.stdin.readline().split()))

ans = 0
for i in range(A, B+1):
    ans += str(i) == ''.join(list(reversed(str(i))))
print(ans)


Measured memory_bytes: 13676
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, K, ans = 0, all = 0;
    cin >> N >> K;
    vector<int> V(N), L(N), R(N);
    for (int i = 0; i < N; i++) {
        cin >> V.at(i);
        all += V.at(i);
    }
    for (int i = 0; i < N - 1; i++) {
        L.at(i + 1) = L.at(i) + V.at(i);
    }
    for (int i = 0; i < N - 1; i++) {
        R.at(i + 1) = R.at(i) + V.at(N - i - 1);
    }

    for (int i = 1; i <= K; i++) {
        vector<int> A(i);
        if (i == N) {
            int sum = all;
            A = V;
            sort(ALL(A));
            for (int j = 0; j < K - N; j++){
                if (A.at(j) < 0) {
                    sum -= A.at(j);
                }
                else {
                    cout << max(ans, sum) << endl;
                    return 0;
                }
                if (j == K - N - 1){
                    cout << max(ans, sum) << endl;
                    return 0;
                }
            }
            cout << max(ans, sum) << endl;
            return 0;
        }
        for (int j = 0; j < i + 1; j++) {
            int sum = 0;
            sum += L.at(j) + R.at(i - j);
            for (int k = 0; k < j; k++) {
                A.at(k) = V.at(k);
            }
            for (int k = j; k < i; k++) {
                A.at(k) = V.at(N + j - k - 1);
            }
            sort(ALL(A));
            if (i == K) {
                ans = max(ans, sum);
            }

            for (int k = 0; k < K - i; k++) {
                if (A.at(k) < 0) {
                    sum -= A.at(k);
                }
                else {
                    ans = max(ans, sum);
                    break;
                }
                if (k == K - i - 1 || k == i - 1){
                    ans = max(ans, sum);
                    break;
                }
            }

        }
    }
    cout << ans << endl;

}


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

using namespace std;
 
int main()
{
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	
	vector<long long> ans;
	ans.push_back(a*x + b*y);
	ans.push_back(2*c*(x < y ? y : x));
	ans.push_back((2*c*(x < y ? x : y)) + (x < y ? (y - x)*b : (x - y)*a));
	
	cout << *min_element(ans.begin(), ans.end()) << endl;
	
	return 0;
}

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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;
typedef pair < ll , ll > pll;

const double PI = acos(-1);
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
	

ll addMod(ll a, ll b){
	if(a + b >= MOD) return a + b - MOD;
	return a + b;
}

ll mulMod(ll a, ll b){
	return (a*b)%MOD;
}

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp,tmp);
	if(b%2 == 1) tmp = mulMod(tmp,a);
	return tmp;
}

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

//////////////////////////////////////////////

const int N = 400;

int n,m;
ll dp[N + 5][N + 5];
ll tot[N + 5][N + 5];
int A[N + 5], B[N + 5];

ll solve(int idx, int rem){
	if(idx == n+1){
		if(rem == 0) return 1;
		return 0;
	}
	ll& ret = dp[idx][rem];
	if(ret != -1) return ret;
	ret = 0;
	FOR(i,rem+1){
		ret = addMod(ret, mulMod(solve(idx+1,rem-i), addMod(tot[i][B[idx]], MOD - tot[i][A[idx]-1])));
	}
	return ret;
	
}
int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	FOR(i,N+2){
		FOR(j,N+2){
			tot[i][j] = (i == 0) ? 1 : mulMod(tot[i-1][j], (ll)j);
		}
	}
	FOR(i,N+2){
		tot[i][0] = 0;
		REP(j,1,N){
			tot[i][j] = addMod(tot[i][j], tot[i][j-1]);
		}
	}
	cin >> n >> m;
	REP(i,1,n) cin >> A[i];
	REP(i,1,n) cin >> B[i];
	memset(dp,-1,sizeof dp);
	cout << solve(1,m) << endl;
	return 0;
}

Measured memory_bytes: 2816
S = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(S[K-1])


Measured memory_bytes: 2940
l = input()
n = len(l)

dp = [[0,0] for i in range(n+1)]
mod = 10**9 + 7
dp[0][0] = 1

for i in range(n):

    if l[i] == '0':
        dp[i+1][0] = dp[i][0] % mod
        dp[i+1][1] = dp[i][1]*3 % mod
    else:
        dp[i+1][0] = dp[i][0]*2 % mod
        dp[i+1][1] = dp[i][0] + dp[i][1]*3 % mod

print(sum(dp[-1]) % mod)

Measured memory_bytes: 19628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, x, y, ans[2005];
int main(){
	scanf("%d%d%d", &n, &x, &y);
	x--; y--;
	rep(i,n) rep(j,i) ans[min(i-j,abs(i-y)+abs(j-x)+1)]++;
	rep(i,n-1) printf("%d\n", ans[i+1]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem( f, x ) memset( f, x, sizeof(f) )
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
#define pk push_back
typedef long long ll;
using namespace std;
const int M = 215;
const int N = 55;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 2505;
ll m, n, s;
int head[N], cnt;
ll dis[N][MAXN];
ll c[N], d[N];

struct eg{
    int to, pre;
    ll a, b;
    eg( ):to(0), pre(0), a(0), b(0){ }
    eg( int tt, int pp, int aa, int bb ){
        to = tt, pre = pp, a = aa, b = bb;
    }
}e[M];

struct node{
    int x, c, d;
    node():x(0), c(0), d(0){ }
    node( int xx, int cc, int dd ):x(xx), c(cc), d(dd){}
    friend bool operator<( node p1, node p2 ){
        if( p1.d == p2.d )
            return p1.c < p2.c;
        return p1.d > p2.d;
    }
};

void add( int x, int y, int a, int b ){
    e[++cnt] = eg( y, head[x], a, b );
    head[x] = cnt;
}

void Bfs( ){
    dis[1][s] = 0;
    priority_queue<node> pq;
    node cur, nxt;
    cur = node( 1, s, 0 );
    pq.push( cur );
    while( !pq.empty() ){
        cur = pq.top();
        pq.pop();
        int x = cur.x;
        int w = cur.c;
        //cout << "cur_x: " << x << endl;
        for( int i = head[x]; i; i = e[i].pre ){
            int to = e[i].to;
            ll a = e[i].a, b = e[i].b;
            if( w >= a && dis[to][w-a] > dis[x][w]+b ){
                dis[to][w-a] = dis[x][w]+b;
                pq.push( node(to, w-a, dis[to][w-a]) );
            }
        }
        ll mi = min( ll(2500), w+c[x] );
        if( dis[x][mi] > dis[x][w]+d[x] ){
            dis[x][mi] = dis[x][w]+d[x];
            pq.push( node( x,mi,dis[x][mi] ));
        }

    }
}

void init( ){
    for( int i = 0; i <= n; i++ ){
        head[i] = 0;
        for( int j = 0; j < MAXN; j++ )
            dis[i][j] = INF;
    }
    s = min( s, ll(2500) );
    cnt = 0;
}

int main( ){
    while( scanf( "%lld %lld %lld", &n, &m, &s ) != EOF ){
        init( );
        int x, y;
        ll a, b;
        for( int i = 0; i < m; i++ ){
            scanf( "%d %d %lld %lld", &x, &y, &a, &b );
            add( x, y, a, b );
            add( y, x, a, b );
        }
        for( int i = 1; i <= n; i++ )
            scanf( "%lld %lld", c+i, d+i );
        Bfs( );
        for( int i = 2; i <= n; i++ ){
            ll ans = INF;
            for( int j = 0; j < MAXN; j++ )
                ans = min( ans, dis[i][j] );
            printf( "%lld\n", ans );
        }
    }
    return 0;
}


Measured memory_bytes: 10504
#include <iostream>

int main(int argc, const char * argv[]) {
    
    int n ;
    
    int taro = 0, hana = 0 ;
    
    std::string taroStr, hanaStr ;
    
    std::cin >> n ;
    
    for (int i=0; i<n; i++) {
        
        std::cin >> taroStr >> hanaStr ;
        int tarop=0, hanap=0 ;
        
        for (int i=0; i<std::min(taroStr.length(), hanaStr.length()); i++) {
            for (char alf='z'; alf>='a'; alf--) {
                
                if ( alf == taroStr[i] && alf == hanaStr[i] ) {
                    tarop += 1 ;
                    hanap += 1 ;
                } else if ( alf == taroStr[i] ) {
                    tarop += 1 ;
                    break ;
                } else if ( alf == hanaStr[i] ) {
                    hanap += 1 ;
                    break ;
                }
            }
            
            if (tarop != hanap){
               break ;
            }
            
        }
        
        if ( tarop == hanap ) {
            tarop += ( taroStr.length() > hanaStr.length() ) ;
            hanap += ( taroStr.length() < hanaStr.length() ) ;
        }
        
        taro += (tarop > hanap) * 3 ;
        hana += (tarop < hanap) * 3 ;
        hana += (tarop == hanap) ;
        taro += (tarop == hanap) ;
        
    }
    
    printf("%d %d\n", taro, hana) ;
    
    return 0 ;
}



Measured memory_bytes: 3260
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()){
			int d=sc.nextInt();
			int n=600/d;
			int total=0;
			for(int i=1; i<n; i++){
				total+=d*f(i*d);
			}
			System.out.println(total);

		}

		
	}

	public static double f(int x){//x???d,2d,3d...

		return x*x;
	}

}

Measured memory_bytes: 26044
// D - Median of Medians

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int N;
int a[100000];
int b[100000];
int c[100001];
int d[100002];
int d_sorted[100002];

// Binary Indexed Tree （indexは1始まり）
// T は +-*/ と 0 を持つ
template<class T> class BIT {
private:
	int N; // 要素数
	vector<T> nodes;

public:
	BIT(int N) {
		this->N = N;
		nodes.assign(N+1, 0);
	}

	// index k の値にxを加える
	void add(int k, T x) {
		for (int i=k; i<=N; i += (i & -i)) {
			nodes[i] += x;
		}
	}

	// 半開区間 [0, k) の合計を返す
	T sum(int k) {
		T result = 0;
		for (int i=k-1; i>0; i -= (i & -i)) {
			result += nodes[i];
		}

		return result;
	}

	// 半開区間 [s, t) の合計を返す
	T sum(int s, int t) {
		return sum(t) - sum(s);
	}
};

// 反転数の数を求める
ll count_num_of_inv() {
	BIT<ll> bit(N+1);
	unordered_map<int, int> d_to_i;

	reverse(d+1, d+N+2);

	for (int i=1; i<=N+1; i++) {
		d_sorted[i] = d[i];
	}

	sort(d_sorted+1, d_sorted+N+2);

	for (int i=1; i<=N+1; i++) {
		if (d_to_i[d_sorted[i]] == 0) d_to_i[d_sorted[i]] = i;
	}

	ll result = 0;

	for (int i=1; i<=N+1; i++) {
		result += bit.sum(d_to_i[d[i]]+1, N+2);
		bit.add(d_to_i[d[i]], 1);
	}

	return result;
}

bool is_ok(int k) {
	for (int i=0; i<N; i++) {
		if (a[i] <= k) {
			b[i] = 1;
		} else {
			b[i] = 0;
		}
	}

	c[0] = 0;
	for (int i=0; i<N; i++) {
		c[i+1] = c[i] + b[i];
	}

	for (int i=0; i<=N; i++) {
		d[i+1] = 2 * c[i] - i;
	}

	return count_num_of_inv() > (ll)N * (N+1) / 4;
}

ll find_min_ok(ll lower, ll upper) {
	ll ok = upper - 1;
	ll ng = lower - 1;

	while(ok - ng > 1) {
		ll trying = (ng + ok) / 2;

		if (is_ok(trying)) {
			ok = trying;
		} else {
			ng = trying;
		}
	}

	return ok;
}

int main() {
	cin >> N;

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

	int ans = find_min_ok(0, INF);

	cout << ans << endl;

	return 0;
}

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

int main(){
    double f;
    string a, b;
    cin >> a >> b;
    f = sqrt(stod(a+b));
    if(f == (int)f){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char[] c = sc.next().toCharArray();
		
		int res = 0;
		
		for(int i = 1; i < c.length; i++) {
			if(c[i] == c[i-1]) {
				c[i] = c[i-1] == '0' ? '1' : '0';
				res++;
			}
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 26980
package main

import "fmt"

func main() {
	var A, B, C, D int
	fmt.Scan(&A, &B, &C, &D)
	countOfdeathA := 0
	if A%D == 0 {
		countOfdeathA = A / D
	} else {
		countOfdeathA = A/D + 1
	}
	if C-B*countOfdeathA > 0 {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}


Measured memory_bytes: 1752
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
//最大公約数
template<typename T>
constexpr T gcd(T a, T b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

//最小公倍数
template<typename T>
constexpr T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}
int main() {
	string s;
	cin >> s;
	int c = 0;
	for (int i = 0; i < 4; ++i) {
		if (s[i] == '+')++c;
		else --c;
	}
	PRI(c);
	return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
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;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int N;
  cin >> N;
  
  int odcnt = 0;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin >> A;
    if (A % 2 != 0) odcnt++;
  }
  
  string ans = "NO";
  if (odcnt % 2 == 0) ans = "YES";
  
  cout << ans<< endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

int main()
{
	ll N; cin >> N;
	ll s[100];
	ll sum = 0;
	ll min = 1 << 21;
	rep(i, 0, N) {
		ll t;
		cin >> t;
		sum += t;
		if (min > t && t % 10 != 0) {
			min = t;
		}
	}
	if (sum % 10 == 0) {
		if (min == 1 << 21 || min % 10 == 0) {
			sum = 0;
		}
		else {
			sum = sum - min;
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  [a,b,c] <- map read . words <$> getLine
  putStrLn $ solve a b c

solve :: Int -> Int -> Int -> String
solve a b c =
  show c ++ " " ++ show a ++ " " ++ show b

test :: IO ()
test = do
  print $ solve 1 2 3 == "3 1 2"
  print $ solve 100 100 100 == "100 100 100"
  print $ solve 41 59 31 == "31 41 59"
  putStrLn "test finished"

Measured memory_bytes: 508
let rec solve acc = function
  | 0 -> acc
  | n -> solve (Char.chr (Char.code 'a' + n mod 26) :: acc) (n / 26)

let () = Scanf.scanf "%d" @@ fun n ->
  let pow = Array.make 12 0 in
  pow.(0) <- 1;
  for i = 0 to 10 do
    pow.(i + 1) <- 26 * pow.(i)
  done;
  let rec aux d n (p :: ps) =
    if n < p
    then (d, n)
    else aux (d + 1) (n - p) ps in
  let rec solve acc n = function
    | 0 -> acc
    | d -> solve (Char.chr (Char.code 'a' + n mod 26) :: acc) (n / 26) (d - 1) in
  let (d, n) = aux 0 n @@ Array.to_list pow in
  List.iter print_char @@ solve ['\n'] n d



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

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;
typedef pair<ll,ll> pll;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

void init(){
    cin.tie(0);
    ios::sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}


int main(){
    init();
    string arr[3];
    int p[3] = {0};
    cin >> arr[0] >> arr[1] >> arr[2];
    int role = 0;
    while(true){
        if(p[role] == arr[role].size())
            return cout << (role == 0 ? 'A' : (role == 1 ? 'B' : 'C')), 0;
        char c = arr[role][p[role]++];
        role = (c == 'a' ? 0 : (c == 'b' ? 1 : 2));
        
    }
}

Measured memory_bytes: 256
//file_name:ABC69_A.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n,m;
    scanf("%d%d",&n,&m);


    ll ans = (n-1)*(m-1);

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



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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50

int main()
{
    int n;
    cin >> n;
    map<int, int> mp;
    while(n--)
    {
        int a;
        cin >> a;
        mp[a%4]++;
    }
    if(mp[2] % 2 == 0)
    {
        if(mp[1] + mp[3] - mp[0] <= 1)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        if(mp[1] + mp[3] + 1 - mp[0] <= 1)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <bitset>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REP1(i, n) for(int i = 1; i <= (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define ZERO(a) memset(a, 0, sizeof(a))

#define RAD(d) (PI * (d) / 180)
#define DEG(r) (180.0 * (r) / PI)

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

template<class T> void dump(const vector<T> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

template<class T> void dump(int w, int h, const vector<T> &v)
{
	REP(j, h){
		REP(i, w-1){ cout << v[j * w + i] << " "; }
		cout << v[j * w + w-1] << endl;
	}
}

template<class T> T accumulate(const vector<T> &v)
{
	T sum = 0;
	REP(i, SZ(v)){ sum += v[i]; }
	return sum;
}

template<class T> struct Matrix
{
	T w, h;
	vector<T> A;
	Matrix(T w_, T h_) : w(w_), h(h_), A(w * h) {}
	T get(T x, T y) const { return A[y * w + x]; }
};

template<class T> void input(Matrix<T> &m)
{
	REP(j, m.h){
		REP(i, m.w){
			cin >> m.A[j * m.w + i];
		}
	}
}

template<class T> Matrix<T> prod(const Matrix<T> &a, const Matrix<T> &b)
{
	Matrix<T> m(b.w, a.h);

	REP(j, m.h){
		REP(i, m.w){
			ll c = 0;
			REP(k, a.w){
				c += a.A[j * a.w + k] * b.A[k * b.w + i];
			}
			m.A[j * m.w + i] = c;
		}
	}

	return m;
}

void dump(const Matrix<ll> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%lld ", m.A[j * m.w + i]); }
		printf("%lld\n", m.A[j * m.w + m.w-1]);
	}
}

void dump(const Matrix<double> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%f ", m.A[j * m.w + i]); }
		printf("%f\n", m.A[j * m.w + m.w-1]);
	}
}

string &to_upper(string &s)
{
	REP(i, s.length()){
		if('a' <= s[i] && s[i] <= 'z'){
			s[i] -= 32;
		}
	}

	return s;
}

string &to_lower(string &s)
{
	REP(i, s.length()){
		if('A' <= s[i] && s[i] <= 'Z'){
			s[i] += 32;
		}
	}

	return s;
}

int main()
{
	int N;
	string S;
	cin >> N >> S;

	int cnt = 0;
	int idx = 0;
	for(;;){
		idx = S.find("ABC", idx);
		if(idx == (int)string::npos)
			break;

		cnt++;
		idx += 3;
	}

	cout << cnt << endl;

	return 0;
}


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

int main() {
  int n,ans=0,t=10000000;
  cin >> n;
  vector<int> a(n),b(n);
  for (int i=0;i<n;i++){
      cin >> a.at(i);
      b.at(i)=a.at(i);
  }
  for (int j=0;j<4;j++){
      for (int i=0;i<n;i++){
          a.at(i)=b.at(i);
      }
      ans=0;
  ans=ans+j;
  a.at(0)=a.at(0)-j;
  for (int i=0;i<n-1;i++){
      if (a.at(i)>0) {
          ans=ans+a.at(i)*2;
          a.at(i+1)-=a.at(i);
      }
  }
  if (a.at(n-1)>0) ans=ans+a.at(n-1);
  t=min(t,ans);
  }
  cout << t << endl;
}


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

const int N = 1e5, mod = 1e9 + 7;

int n, dp[N][2];
vector <int> adj[N];

signed main() {
	cin >> n;
	for (int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	function <int(int, int)> add = [&](int a, int b) {
		return (a % mod + b % mod) % mod;
	};
	function <int(int, int)> mul = [&](int a, int b) {
		return (a % mod * b % mod) % mod;
	};
	function <void(int, int)> dfs = [&](int v, int p) {
		dp[v][0] = dp[v][1] = 1;
		for (auto u : adj[v]) {
			if (u == p) continue;
			dfs(u, v);
			dp[v][1] = mul(dp[v][1], dp[u][0]);
			dp[v][0] = mul(dp[v][0], add(dp[u][1], dp[u][0]));
		}
	};
	dfs(1, 0);
	cout << add(dp[1][0], dp[1][1]);
}

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

using namespace std;
const int N = 2e5+5;
bool np[N];
vector<int> p;

void sieve(){
    for(int i=2;i<N;++i){
        if(np[i]) continue;
        p.push_back(i);
        for(int j=i*2;j<N;j+=i) np[j]=1;
    }
}



int main() {
    // freopen("in.txt", "rt", stdin);
    // freopen("out.txt", "w", stdout);
    sieve();
    int x;
    cin>>x;
    cout<<(*lower_bound(p.begin(),p.end(),x));
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(&A[0], &A[N]);
    lli minCost = 99999999999999999;
    for(int i = A[0]; i < A[N - 1]; i++) {
        lli cost = 0;
        for(int j = 0; j < N; j++) {
            cost += (lli) pow(A[j] - i, 2);
        }
        if(cost < minCost) minCost = cost;
    }
    if(minCost == 99999999999999999) {
        minCost = 0;
    }
    cout << minCost;
    return 0;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 1e5, mod = 1e9 + 7, dsz = 4;
int n, m, d[nsz + 5], cur[nsz + 5], del[nsz + 5], dp[nsz + 5], pre[nsz + 5];

struct matrix {
	int n, m, d[dsz + 5][dsz + 5];
	
	matrix(int n = 0, int m = 0, bool e = 0) {
		this->n = n, this->m = m;
		loop (i, n) {
			loop (j, m) {
				d[i][j] = (i == j) & e;
			}
		}
	}
	
	matrix(vector< vector<int> > a) {
		n = a.size(), m = a[0].size();
		loop (i, n) {
			loop (j, m) {
				d[i][j] = a[i][j];
			}
		}
	}
	
	int* operator [] (int id) {
		return d[id];
	}
};
matrix a = matrix({
	{0, 1, 1, 0},
	{0, 1, 1, 0},
	{0, 1, 2, 2},
	{0, 1, 1, 1},
}),
b = matrix({
	{0, 0, 0, 0},
	{0, 1, 1, 0},
	{0, 0, 1, 2},
	{0, 0, 0, 1}
}),
res = matrix({
	{1},
	{0},
	{1},
	{1},
});

matrix inline operator * (matrix a, matrix b) {
	matrix res(a.n, b.m);
	loop (i, a.n) {
		loop (j, b.m) {
			loop (k, a.m) {
				res[i][j] = (res[i][j] + (num) a[i][k] * b[k][j] % mod) % mod;
			}
		}
	}
	return res;
}

matrix inline qpow(matrix a, int p) {
	matrix res(a.n, a.m, 1);
	for (; p; p >>= 1) {
		if (p & 1) {
			res = res * a;
		}
		a = a * a;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(0);
	cin >> n >> m;
	cont (i, m) {
		cin >> d[i];
	}
	cont (i, m) {
		res = qpow(a, d[i] - d[i - 1] - 1) * res;
		res = b * res;
	}
	res = qpow(a, n - d[m]) * res;
	cout << res[0][0] << ln;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int[] a = new int[4];
			int[] b = new int[4];
			int hitcount = 0,browcount = 0;
			for(int i = 0; i < 4;i++ ){
				a[i] = sc.nextInt();
			}
			for(int i = 0; i < 4;i++ ){
				b[i] = sc.nextInt();
			}
			for(int i = 0; i < 4;i++ ){
				for(int j  = 0; j < 4 ; j++){
					if(a[i] == b[j]){
						if(i == j){
							hitcount++;
						}else if(i != j){
							browcount++;
						}
					}
				}
			}
			System.out.printf("%d %d\n",hitcount,browcount);
		}
	}
}

Measured memory_bytes: 18156
#include<iostream>

using namespace std;

int main(){
    int N;
    int A[305][305];
    long ans=0;
    bool b=1;
    bool c;
    cin>>N;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>A[i][j];
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j)continue;
            for(int k=0;k<N;k++){
                if(k==i||k==j)continue;
                if(A[i][j]>A[i][k]+A[k][j]){
                    b=0;
                    break;
                }
            }
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j)continue;
            c=1;
            for(int k=0;k<N;k++){
                if(k==i||k==j)continue;
                if(A[i][j]==A[i][k]+A[k][j]){
                    c=0;
                }
            }
            if(c)ans+=A[i][j];
        }
    }
    if(b==0)cout<<-1<<endl;
    else cout<<ans/2<<endl;
    return 0;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;
    Graph<int> G(N);
    for (int i = 1; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> color(N, -1), cnt(2);
    queue<int> que;
    color[0] = 0;
    cnt[0]++;
    que.push(0);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (auto nv : G[v]) {
            if (~color[nv])
                continue;
            cnt[color[nv] = !color[v]]++;
            que.push(nv);
        }
    }

    bool rev = cnt[0] < cnt[1];
    if (cnt[0] < cnt[1])
        swap(cnt[0], cnt[1]);
    int modcnt[3] = {N / 3, (N + 2) / 3, (N + 1) / 3};

    vector<int> ans(N);
    if (cnt[1] >= modcnt[2]) {
        for (int i = 0; i < N; ++i) {
            if (color[i] ^ rev) {
                if (modcnt[2])
                    ans[i] = (--modcnt[2]) * 3 + 2;
                else
                    ans[i] = (--modcnt[0]) * 3 + 3;
            } else {
                if (modcnt[1])
                    ans[i] = (--modcnt[1]) * 3 + 1;
                else
                    ans[i] = (--modcnt[0]) * 3 + 3;
            }
        }
    } else {
        for (int i = 0; i < N; ++i) {
            if (color[i] ^ rev)
                ans[i] = (--modcnt[0]) * 3 + 3;
            else {
                if (modcnt[1])
                    ans[i] = (--modcnt[1]) * 3 + 1;
                else if (modcnt[2])
                    ans[i] = (--modcnt[2]) * 3 + 2;
                else
                    ans[i] = (--modcnt[0]) * 3 + 3;
            }
        }
    }

    for (auto i : ans)
        cout << i << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 15344
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define MAXN 1007

struct Node{
    int numBoll=1;
    bool flag=0;
};
int main(void)
{
    vector<Node> vi;
    int N,M;
    cin >> N >> M;
    for(int i=0; i<N; i++){
     Node node;
        if(i==0){
            node.flag = 1;
        }else{
            node.flag = 0;
        }
        vi.push_back(node);
    }
    for(int i=0; i<M; i++){
        int x,y;
        cin >> x >> y;
        if(vi[x-1].flag){
            vi[y-1].flag = 1;
        }
        vi[x-1].numBoll--;
        vi[y-1].numBoll++;
        if(vi[x-1].numBoll == 0){
            vi[x-1].flag = 0;
        }

    }
    int ans=0;
    for(int i=0; i<vi.size(); i++){
        if(vi[i].flag)
            ans++;
    }
    cout <<ans;
    return 0;

}


Measured memory_bytes: 1400
#include <stdio.h>
#include <algorithm>
using namespace std;


int main()
{
	int a[10],i;
	for(i = 0; i < 10; i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+10);
	printf("%d\n%d\n%d\n",a[9],a[8],a[7]);
	return 0;
}

Measured memory_bytes: 1048
#import<iostream>
#import<atcoder/all>
using namespace std;long N,Q,i,a;int main(){cin>>N>>Q;atcoder::fenwick_tree<long>b(N);for(;i<N;i++)cin>>a,b.add(i,a);while(Q--){cin>>i>>a>>N;if(i)cout<<b.sum(a,N)<<endl;else b.add(a,N);}}

Measured memory_bytes: 8208
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
bool isPalin(string s)
{
     string p=s;
    reverse(p.begin(),p.end());
    if(p==s)
    return true;
    else 
    return false;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    int n=s.size();
    string f=s.substr(0,(n-1)/2);
    string d=s.substr((n+3)/2-1,(n-1)/2);
    if(isPalin(s) &&  isPalin(f) && isPalin(d))
    cout<<"Yes\n";
    else
    cout<<"No\n";
}

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

int main(){
    int x,y;cin>>x>>y;
    for(int i=0;i<=x;i++){
        if(i*2+(x-i)*4==y){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3636
nm = [int(i) for i in input().split()]
dic = {}

co = 0
pe = 0

for i in range(0,nm[1]):
  tmp = [j for j in input().split()]
  val = dic.setdefault(tmp[0],['NEW', 0])
  
  if (val[0] == 'NEW') or (val[0] == 'WA'):	#新規追加
    if tmp[1] == 'WA':
      dic[tmp[0]][1] += 1
      dic[tmp[0]][0] = 'WA'
    elif tmp[1] == 'AC':
      co += 1
      pe += dic[tmp[0]][1]
      dic[tmp[0]][0] = 'AC'

print(co, pe)


Measured memory_bytes: 25280
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  n = int(input())
  s = input()
  slen = len(s)
  new = ""
  for i in range(slen): # A ~ Z : 65 ~ 90
    if 65 <= ord(s[i]) + n <= 90:
      new += chr(ord(s[i])+n)
    else:
      new += chr(ord(s[i]) + n - 26)
  print(*new,sep="")
if __name__ == '__main__':
  main()

Measured memory_bytes: 4724
#include <iostream>

using namespace std;

int a, b, c;

int main(void)
{
	cin >> a >> b >> c;
	
	int ans = 0;
	int na, nb, nc, m;
	while(1){
		if(a == 0 && b == 0 && c == 0){
			ans = -1;
			break;
		}
		if(a % 2 || b % 2 || c % 2) break;
		ans++;
		m = min(a, min(b, c));
		a -= m, b -= m, c -= m;
		na = (b+c)/2, nb = (c+a)/2, nc = (a+b)/2;
		a = na, b = nb, c = nc;
	}	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vs = vector<string>;
template <typename T>
using ost = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
#define forn(i,n) for(int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second

int main() {
    ios::sync_with_stdio(false);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll d = a - b;
    cout << (k%2==0? d:-d) << '\n';
}


Measured memory_bytes: 256