akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b; cin>>a>>b;
	int ans=0;
	if(a<b){
		ans+=b;
		b--;
	}
	else{
		ans+=a;
		a--;
	}
	if(a<b){
		ans+=b;
		b--;
	}
	else{
		ans+=a;
		a--;
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 3636
S = str(input())
for i in range(len(S)):
    if i % 2 == 1:
        if S[i] == "L" or S[i] == "U" or S[i] == "D":
            pass
        else:
            print("No")
            exit()
    else:
        if S[i] == "R" or S[i] == "U" or S[i] == "D":
            pass
        else:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define in(x) cin >> x
#define out(x) cout << x << endl

#define PI acos(-1)
#define pp push_back

#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl

#define vec2(type) vector<vector<type>>
#define vec3(type) vector<vector<vector<type>>>

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

#define Tcmp(X, Y) (abs(aryvec[i]->x) == X && abs(aryvec[i]->y) == Y)

template<typename T> void input(T *data, int n){
	For(i, n){
		cin >> data[i];
	}
}

template<typename T> void sort(vector<T> &ary){
	sort(ary.begin(), ary.end());
}

template<typename T> void rsort(vector<T> &ary){
	sort(ary.rbegin(), ary.rend());
}

void rstring(string &str){
	string temp = str;

	For(i, (int)str.size()){
		str[i] = temp[(str.size() - 1) - i];
	}
}

struct Vec{
	int x, y;
	Vec():
	x(0), y(0){}
};

int main(){

		int a, b;
		in(a), in(b);

		int sum = 0;

		For(i, 2){
			if(a >= b){
				sum += a--;
			}
			else{
				sum += b--;
			}
		}

		out(sum);

	return 0;


}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
from collections import deque


def solve(N: int, D: int, A: int, X: "List[int]", H: "List[int]"):
    M = sorted([(X[i], H[i]) for i in range(N)])
    DD = 2*D
    result = 0
    revert = deque()
    currentDamage = 0
    for m in M:
        while len(revert) > 0 and revert[0][0] < m[0]:
            currentDamage -= revert[0][1]
            revert.popleft()
        nextDamage = max(0, m[1] - currentDamage)
        needAttack = math.ceil(nextDamage/A)
        currentDamage += needAttack * A
        result += needAttack
        if needAttack > 0:
            revert.append((m[0]+2*D, needAttack*A))
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    H = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        H[i] = int(next(tokens))
    solve(N, D, A, X, H)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47848
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, a, b; cin >> x >> a >> b;
  if( a-b>=0) {
    cout << "delicious" << endl;
  }
  else if (a-b<0){
    if (b-a<=x) {
      cout << "safe" << endl;
    }
    else if (b-a>x) {
      cout << "dangerous" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
"""
双対セグ木
アクセスは0-indexed, 内部のツリーは 1-indexed
関数は閉区間
作用素は右から作用とする

引数：
    N: 処理する区間の長さ
    compose: 作用素を合成させる関数 (max, min, __add__,ラムダ式,関数定義など)
    UNIT: 恒等作用素
    funcval(x,f) = f(x)
"""

class segment_tree_dual:
    def __init__(self, N, compose, funcval, UNIT=None):
        self.compose = compose
        self.UNIT = UNIT
        self.funcval = funcval

        self.height = (N-1).bit_length() #木の高さ
        self.N0 = 1<<self.height #木の横幅 >= N
        self.laz = [self.UNIT]*(2*self.N0) #作用素の木
        self.val = None #値の配列

    #初期値の配列を作る
    def build(self,initial):
        self.val = initial[:]

    #laz[k] を子に伝える、
    def propagate(self,k):
        if self.laz[k] == self.UNIT: return;
        if self.N0 <= k:
            self.val[k-self.N0] = self.funcval(self.val[k-self.N0], self.laz[k])
            self.laz[k] = self.UNIT
        else:
            self.laz[(k<<1)  ] = self.compose(self.laz[(k<<1)  ],self.laz[k]);
            self.laz[(k<<1)+1] = self.compose(self.laz[(k<<1)+1],self.laz[k]);
            self.laz[k] = self.UNIT;
    
    # laz[k]およびその上に位置する作用素をすべて伝播
    def thrust(self,k):
        for i in range(self.height,-1,-1): self.propagate(k>>i)
    
    def thrust_for_update(self,k):
        while k&1 == 0: k//=2
        for i in range(self.height-1,-1,-1): self.propagate(k>>i)

    # 区間[L,R]に関数 f を作用
    def update(self, L,R,f):
        """まず伝播させる（オペレータが可換なら必要ない）"""
        L += self.N0; R += self.N0+1
        self.thrust_for_update(L)
        self.thrust_for_update(R-1)
        
        #[L,R)に対応する区間たちに関数 f を合成
        while L < R:
            if R & 1:
                R -= 1
                self.laz[R] = self.compose(self.laz[R],f)
            if L & 1:
                self.laz[L] = self.compose(self.laz[L],f)
                L += 1
            L >>= 1; R >>= 1
    
    # values[k] を取得。
    def point_get(self, k):
        res = self.val[k]
        k += self.N0
        while k:
            res = self.funcval(res, self.laz[k])
            k //= 2
        return res
    
    # values[k] = x 代入する
    def point_set(self, k): 
        self.thrust(k)
        self.val[k] = x



###########################################################################
#日経2020予選D
#https://atcoder.jp/contests/nikkei2019-2-qual/submissions/8384133 (伝播あり)
#https://atcoder.jp/contests/nikkei2019-2-qual/submissions/8384138 (伝播なし)
###########################################################################

# coding: utf-8
# Your code here!
 
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n,m = [int(i) for i in readline().split()]
lrc = [tuple(int(i) for i in readline().split()) for _ in range(m)]
lrc.sort()

compose = lambda f,g: min(f,g)
funcval = lambda x,f: min(x,f)
UNIT = INF = 10**18

seg = segment_tree_dual(n, compose, funcval, UNIT)
seg.build([0]+[INF]*(n-1))

for l,r,c in lrc:
    l -= 1
    r -= 1
    v = seg.point_get(l)
    seg.update(l+1,r,v+c)

ans = seg.point_get(n-1)

if ans != INF:
    print(ans)
else:
    print(-1)





Measured memory_bytes: 84956
import os,sys
from io import BytesIO, IOBase

def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())

mod=1000000007

import math  

for i in range(1):
    n,m=mi()
    print(math.ceil(n/m))

Measured memory_bytes: 38384
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();

        int N = sc.nextInt();
        int D = sc.nextInt();
        int X[][] = new int[N][D];
        for (int i=0;i<N;i++) {
            X[i] = sc.nextIntArray(D);
        }

        int ans = 0;

        for (int i=0;i<N;i++) {
            for (int j=i+1;j<N;j++) {
                if (check(X[i], X[j], D) == true) {
                    ans++;
                }
            }
        }

        out.println(ans);
        out.flush();
    }

    public static boolean check(int a[], int b[], int D) {
        int sq = 0;
        for (int i=0;i<D;i++) {
            sq += (a[i] - b[i]) * (a[i] - b[i]);
        }

        for (int i=0;i<=sq;i++) {
            if (sq == i * i) {
                return true;
            }
        }

        return false;
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

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

        int[] nextIntArray(int N) {
            int a[] = new int[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextInt();
            }

            return a;
        }

        long[] nextLongArray(int N) {
            long a[] = new long[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextLong();
            }

            return a;
        }

        double[] nextDoubleArray(int N) {
            double a[] = new double[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextDouble();
            }

            return a;
        }

        String[] nextTokenArray(int N) {
            String a[] = new String[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextToken();
            }

            return a;
        }
    }
}

Measured memory_bytes: 21332
def count_char(array)
  answers = {
            "a" => 0,
            "b" => 0,
            "c" => 0,
            "d" => 0,
            "e" => 0,
            "f" => 0,
            "g" => 0,
            "h" => 0,
            "i" => 0,
            "j" => 0,
            "k" => 0,
            "l" => 0,
            "m" => 0,
            "n" => 0,
            "o" => 0,
            "p" => 0,
            "q" => 0,
            "r" => 0,
            "s" => 0,
            "t" => 0,
            "u" => 0,
            "v" => 0,
            "w" => 0,
            "x" => 0,
            "y" => 0,
            "z" => 0
            }
  length = array.length
    for i in 0..(length-1)
      if answers[array[i].downcase] == nil
        next
      else
        answers[array[i].downcase] += 1
     end
   end
     return answers
end

sum_hash = {}

while str_array = gets
  # str_array = input_values.chars.map(&:to_s)
answer = count_char(str_array)
sum_hash.merge!(answer){|key, v0, v1|v0 + v1}

end
 sum_hash.each {|key, value|
   print(key + " : ", value.to_s + "\n")
 }

Measured memory_bytes: 8752
#include<bits/stdc++.h>
using namespace std ;
#define rep(i,n) for(int i=0;i<n;i++)
#define maxn 100005
#define int long long
int dp[maxn];
int arr[maxn];
int n,k ;
void top(int m){
    dp[0] = 0 ;
    for(int i=1;i<n;i++){
        dp[i] = dp[i-1]+abs(arr[i]-arr[i-1]);
        for(int j=i-2; ((i-j)<=k) && j>=0 ;j-- ){
            dp[i] = min(dp[i],abs(arr[i]-arr[j])+dp[j]);
        //    cout << i << " " << j << " "  << dp[i] << endl ;
        }
    }
//    for(int i=0;i<n;i++)
//        cout << dp[i] << " " << arr[i] << endl ;
}
void solve(){
    cin >> n >> k;
    rep(i,n){
        //scanf("%ld",&arr[i]);
        cin >> arr[i] ;
    }
    top(n-1);
    printf("%lld",dp[n-1]);
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1 ;
    while(t--){solve();}
    return 0 ;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
const int N=401,M=100001;
int n,m,ans,x[M],y[M];
vector<int> s[N],p;
bool b[N],alive[N];
int main(){
	cin>>n>>m;
	ref(i,1,m)cin>>x[i]>>y[i];
	ref(i,1,n){
		alive[i]=1;
		ref(j,1,n)b[j]=0;b[i]=1;
		def(j,m,1){
			if(b[x[j]]&b[y[j]]){alive[i]=0;break;}
			if(b[x[j]]^b[y[j]]){
				b[x[j]]=b[y[j]]=1;
				s[i].push_back(j);
			}
		}
	}
	ref(i,1,n)if(alive[i])ref(j,i+1,n)if(alive[j]){
		p.clear();
		for(int c1=s[i].size()-1,c2=s[j].size()-1;;){
			if(c1<0&&c2<0)break;
			if(c2<0||c1>=0&&s[i][c1]<s[j][c2])
				p.push_back(s[i][c1--]);
			else p.push_back(s[j][c2--]);
		}
		ref(I,1,n)b[I]=0;b[i]=b[j]=1;
		bool fg=1;
		for(int c=p.size()-1,la=0;c>=0;c--)if(p[c]!=la){
			la=p[c];
			if(b[x[la]]&b[y[la]]){fg=0;break;}
			if(b[x[la]]^b[y[la]])b[x[la]]=b[y[la]]=1;
		}
		ans+=fg;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define int unsigned long long
#define ld long double
#define inf 0x7f7f7f7f7f7f7f7f 
#define maxn 1000010
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define mod 998244353
#define db(x) cout << x << endl; 
#define eps 0.0001
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
	int a,b,n;
	cin >> a >> b >> n;
	int x=min(b-1,n);
	cout << a*x/b-a*(x/b);
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;
const int MAX = 510000;
const int MOD = 1000000007;
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


/*
* 素因数分解
* @param [in] n   自然数
* @param [in] out 素因数分解した数が入る
*/
template<typename T>
void PrimeFactors(T n, std::map<T,T> &out)
{
	while (n % 2 == 0)
	{
		++out[2];
		n = n / 2;
	}

	for (T i = 3; i <= sqrt(n); i = i + 2)
	{
		while (n%i == 0)
		{
			++out[i];
			n = n / i;
		}
	}

	if (n > 2)
		++out[n];
}



int main(void){ 
    ll n;ll K;cin>>n>>K;
    char k[n+1];
    k[0]='0';
    k[n+1]='0';
    rep(i,n){
        cin>>k[i+1];
    }
    ll count=0;
    for(int i=0;i<=n;i++){
        if(k[i]==k[i+1]&&k[i]=='R'){count++;}
    }
    for(int i=1;i<=n+1;i++){
        if(k[i]==k[i-1]&&k[i]=='L'){count++;}
    }
    cout<<min(n-1,count+2*K)<<endl;
    
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int x, y, z;
	cin >> x >> y >> z;
	swap(x, y);
	swap(x, z);
	cout << x << " " << y << " " << z;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int N = sc.nextInt();
	  String s = sc.next();
	  char[] S = s.toCharArray();
	  //合体後の文字列
	  StringBuilder sb = new StringBuilder();
	  sb.append(S[0]);
	  
	  for(int i=1; i<N; i++) {
		  if(S[i] != S[i-1]) {
			  sb.append(S[i]);
		  }
	  }
	  int ans = sb.length();
	  out.println(ans);
  }
}

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }

int main(){
	int k , x ; 
	cin >> k >> x ; 
	int l = max((int)-1e6,(x-k+1)) , r = min((x+k-1),(int)1e6) ; 
	for( ; l <= r ; l++ )cout << l << " " ; 
		cout << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 1e6+6;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,m; 
    cin>>n>>m;
    n = n*(n-1)/2;
    m = m*(m-1)/2;
    cout<<n+m<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import itertools
lst = list(map(str,input().split()))
lst1 = list(itertools.permutations(lst))

ans_array = []
for i in range(len(lst1)):
    num1 = int(lst1[i][0]+lst1[i][1]) + int(lst1[i][2])
    num2 = int(lst1[i][0]) + int(lst1[i][1]+lst1[i][2])
    ans_array.append(num1)
    ans_array.append(num2)
print(max(ans_array))

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


int main(){
    int N;
    cin >> N;
    float ans = 0;
    rep(i,N){
        float x;
        string s;
        cin >> x >> s;
        (s == "JPY") ? (ans += x) : (ans += (x * 380000));
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
void init_ios() {ios_base::sync_with_stdio(false); cin.tie(nullptr);}

int N, K;
vector<int> G[2000];

int main() {
	scanf("%d%d", &N, &K);
	for (int i = 0, A,B; i < N-1; ++i) {
		scanf("%d%d", &A, &B);
		--A, --B;
		G[A].push_back(B);
		G[B].push_back(A);
	}

	int res = 1<<30;

	if (K%2) {
		vector<vector<bool>> chosen(N, vector<bool>(N, 0));
		for (int i = 0; i < N; ++i) {
			for (auto& j : G[i]) if (!chosen[i][j]) {
				chosen[i][j] = chosen[j][i] = 1;
				vector<int> checked(N, 0);
				checked[i] = checked[j] = 1;
				queue<pair<int, int>> q;
				q.emplace(i, 0), q.emplace(j, 0);
				while (q.size()) {
					auto p = q.front(); q.pop();
					if (p.second < (K-1)/2) for (auto& d : G[p.first]) if (!checked[d]) {
						checked[d] = 1;
						q.emplace(d, p.second+1);
					}
				}
				res = min(res, N-accumulate(checked.begin(), checked.end(), 0));
			}
		}
	} else {
		for (int i = 0; i < N; ++i) {
			vector<int> checked(N, 0);
			checked[i] = 1;
			queue<pair<int, int>> q;
			q.emplace(i, 0);
			while (q.size()) {
				auto p = q.front(); q.pop();
				if (p.second < K/2) for (auto& d : G[p.first]) if (!checked[d]) {
					checked[d] = 1;
					q.emplace(d, p.second+1);
				}
			}
			res = min(res, N-accumulate(checked.begin(), checked.end(), 0));
		}
	}

	printf("%d\n", res);

	return 0;
}


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

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  rep(i, 3) {
    rep(j, 3) cin >> a.at(i).at(j);
  }
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i, n) cin >> b.at(i);
  vector<vector<bool>> appear(3, vector<bool>(3));
  rep(i, 3) {
    rep(j, 3) appear.at(i).at(j) = false;
  }
  rep(i, 3) {
    rep(j, 3) {
      rep(k, n) {
        if(a.at(i).at(j) == b.at(k)) appear.at(i).at(j) = true;
      }
    }
  }
  string ans = "No";
  if (appear.at(0).at(0) == true && appear.at(0).at(1) == true && appear.at(0).at(2) == true) ans = "Yes";
  if (appear.at(0).at(0) == true && appear.at(1).at(0) == true && appear.at(2).at(0) == true) ans = "Yes";
  if (appear.at(1).at(0) == true && appear.at(1).at(1) == true && appear.at(1).at(2) == true) ans = "Yes";
  if (appear.at(0).at(1) == true && appear.at(1).at(1) == true && appear.at(2).at(1) == true) ans = "Yes";
  if (appear.at(2).at(0) == true && appear.at(2).at(1) == true && appear.at(2).at(2) == true) ans = "Yes";
  if (appear.at(0).at(2) == true && appear.at(1).at(2) == true && appear.at(2).at(2) == true) ans = "Yes";
  if (appear.at(0).at(0) == true && appear.at(1).at(1) == true && appear.at(2).at(2) == true) ans = "Yes";
  if (appear.at(0).at(2) == true && appear.at(1).at(1) == true && appear.at(2).at(0) == true) ans = "Yes"; 
  cout << ans << endl;
} 

Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, K):
    div0 = N // K
    divh = (N + (K // 2)) // K if K % 2 == 0 else 0
    import math
    print(div0 ** 3 + divh ** 3)


if __name__ == '__main__':
    # S = input()
    # N = int(input())
    N, K = map(int, input().split())
    # A = [int(i) for i in input().split()]
    # B = [int(i) for i in input().split()]
    # AB = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, K)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


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

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const ll INF = 100000000000000;

const int dx[4] = {0,  0, 1, -1};
const int dy[4] = {1, -1, 0,  0};

const int N = 100001;
ll n,A,B,a[N];
ll solve(ll pos){
//	debug(pos);
//	debug(curX);
//	system("pause");
	if (pos == n - 1){
		return 0;
	}

	if (pos < n){
		ll ans = INF;
		if (pos + 1 < n){
			ans = min(ans,solve(pos + 1)  + (a[pos + 1] - a[pos]) * A);
			ans = min(ans,solve(pos + 1) + B);
			return ans;
		}
		
	}

}
int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> A >> B;
	forn(i,n) cin >> a[i];
	cout << solve(0) << endl;
  	return 0;
}


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


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

  vector<int> h( n ) ;
  rep( i, n ) cin >> h[i];

  
  int h_before = -999;
  rep( i, n ) {
    if ( h_before <= h[i]-1 ) {
      h_before = h[i]-1;
    }
    else if ( h_before <= h[i] ) {
      h_before = h[i];
    }
    else {
      puts( "No" ) ;
      return 0 ;
    }
  }
  puts("Yes");
  return 0 ;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

const int N = 8;
int k;
map<Edge,int> mp;
bool isinput[8];

void changeBoard(int board[N][N], int i, int j, int d)
{
    int k;
    mp[MP(i,j)] += d;

    for (k = 0; k < N; k++) { 
        board[i][k] += d;             /* 横方向 */
        board[k][j] += d;             /* 縦方向 */
    }
    if (i > j) {
        for (k = 0; k < N-(i-j); k++) {
            board[k+(i-j)][k] += d;   /* 右下がり斜め方向 (i > jのとき） */
        }
    } else {
        for (k = 0; k < N-(j-i); k++) {
            board[k][k+(j-i)] += d;   /* 右下がり斜め方向 (i <= jのとき） */
        }
    }
    if (i+j < N) {
        for (k = 0; k <= i+j; k++) {
            board[i+j-k][k] += d;     /* 左下がり斜め方向（i +j < Nのとき） */
        }
    } else {
        for (k = i+j-N+1; k < N; k++) {
            board[i+j-k][k] += d;     /* 左下がり斜め方向（i+j >= Nのとき） */
        }
    }
}

void setQueen(int queen[N], int board[N][N], int i)
{
    int j;
    
    if (i == N) {                              /* 解が見つかった */
        FOR(i,0,N-1){
          FOR(j,0,N-1){
            if(queen[i]==j) cout << "Q";
            else cout << ".";
          }
          cout << "\n";
        }
        return;
    }

    if (isinput[i]) {
      setQueen(queen, board, i+1);
    }
    
    for (j = 0; j < N; j++) {
        if (board[i][j] == 0) {                /* (i,j) の位置に置けるならば */
            queen[i] = j;                      /* (i,j) の位置にクイーンを置く */
            changeBoard(board, i, j, +1);      /* (i,j) から縦横斜めの方向のboard値を+1する */
            setQueen(queen, board, i+1);       /* i+1 行目のクイーンの位置を決める */
            changeBoard(board, i, j, -1);      /* (i,j) から縦横斜めの方向のboard値を元に戻す */
        }
    }
}

int main() {
  cin >> k;
  int queen[N];
  int board[N][N];
  memset(board, 0, sizeof(board));
  FOR(i,0,k-1){
    int x,y; cin >> x >> y;
    isinput[x] = true;
    queen[x] = y;
    changeBoard(board, x, y, +1);
  }
  setQueen(queen, board, 0);

}




Measured memory_bytes: 3108
#include<stdio.h>
int n, a, C[30], r;
int main(){
    int i, t, c;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&a);
        r ^= a;
        t = (a&-a);
        c=0;
        while(t){
            t>>=1;
            c++;
        }
        C[c]++;
    }
    c = 0;
    for(i=30;i>=0;i--){
        if((r>>i)&1){
            c++;
            if(!C[i+1]){
                printf("-1\n");
                return 0;
            }
            r ^= (1<<(i+1))-1;
        }
    }
    printf("%d\n",c);
}

Measured memory_bytes: 128
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String l,s="";
		while ((l=br.readLine())!=null) s+=l.toLowerCase();
		s=s.replace(" ","");
		char[] a={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
		int r;
        for(char c:a){
        	r=0;
        	for(int i=0;i<s.length();i++){
            	if(s.charAt(i)==c) r+=1; 
        	}
        	System.out.println(c+" : "+r);
        }
	}
}

Measured memory_bytes: 24432
#include<stdio.h>
int d[101010];
int p[101010];
int rui[101010];
int main()
{
	for (int i = 2; i <= 100000; i++)for (int j = i + i; j <= 100000; j += i)d[j] = 1;
	for (int i = 3; i <= 100000; i++)if (d[i] == 0 && d[(i + 1) / 2] == 0)p[i] = 1;
	for (int i = 1; i <= 100000; i++)rui[i] = rui[i - 1] + p[i];
	int query;
	scanf("%d", &query);
	for (int i = 0; i < query; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		printf("%d\n", rui[b] - rui[a - 1]);
	}
}

Measured memory_bytes: 1664
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
#define ll long long 
// #define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=2*1e5+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]%2==0)
		{
			if(a[i]%3!=0&&a[i]%5!=0)
			{
				cout<<"DENIED\n";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
} 
// I never lose. I either win or I learn

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e:t) fill_v(e, v);
}

typedef pair<int, int> P;

class CKDMC {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, Q;
        string S;
        cin >> N >> S >> Q;

        vector<int> K(Q);
        REP(i, Q) cin >> K[i];

        for (int k : K) {
            int d = 0;
            int m = 0;
            int dm = 0;
            int res = 0;
            REP(i, S.size()) {
                if (S[i] == 'D') {
                    d++;
                }
                if (S[i] == 'M') {
                    m++;
                    dm += d;
                }
                if (S[i] == 'C') {
                    res += dm;
                }
                int a = i - k + 1;
                if (a < 0) continue;
                if (S[a] == 'D') {
                    dm -= m;
                    d--;
                }
                if (S[a] == 'M') {
                    m--;
                }
            }
            cout << res << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CKDMC solver;
    solver.solve(in, out);
    return 0;
}


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

int A, B;

int main() {
    cin >> A >> B;
    int res = A + B;

    if (res >= 10) {
        cout << "error" << endl;
    } else {
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,total=0;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n-1;i++)
		for(int j=i+1;j<=n;j++)
			total+=a[i]*a[j];
	cout<<total<<endl;
	return 0;
}


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

struct edge{
    int to, cap, rev;
};

#define MAX_V 202
vector<edge> G[MAX_V];
bool used[MAX_V];

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

// v...target vertex, t...end vertex, f...maximum flow 
int dfs(int v, int t, int f){
    if(v == t)  return f;

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

    return 0;
}

const int INF = 1<<29;

// maxflow from s to t
int max_flow(int s, int t){
    int flow = 0;
    while(1){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f == 0)  return flow;
        flow += f;
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> ri(n), rj(n), bi(n), bj(n);
    int SOURCE = 0, SINK = 201;
    for(int i = 0; i < n; i++)  cin >> ri[i] >> rj[i], add_edge(SOURCE, i+1, 1);
    for(int i = 0; i < n; i++)  cin >> bi[i] >> bj[i], add_edge(101+i, SINK,1);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(ri[i] < bi[j] && rj[i] < bj[j])  add_edge(i+1, 101+j, 1);
        }
    }
    cout << max_flow(SOURCE, SINK) << endl;
    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		StringBuffer str = new StringBuffer(line);
		StringBuffer ans = new StringBuffer();

		int N = Integer.parseInt(br.readLine());

		for(int i = 0; i < N; i++) {
			String[] set = br.readLine().split(" ");
			int a = Integer.parseInt(set[1]);
			int b = Integer.parseInt(set[2]) + 1;

			switch(set[0]) {
			case "print":
				ans.append(str.substring(a, b)).append("\n");
				break;
			case "reverse":
				StringBuilder str1 = new StringBuilder(str.substring(a, b));
				str.replace(a, b, str1.reverse().toString());
				break;
			case "replace":
				str.replace(a, b, set[3]);
				break;
			}
		}
		System.out.print(ans);
	}
}

Measured memory_bytes: 24840
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;ll mod=1e9+7;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){ll ans=1,l=2;rep(i,0,min(n-r,r)){ans*=(n-i);ans%=mod;while(ans%l==0&&l<=min(r,n-r)){ans/=l;l++;}}return ans;}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}//素数の時true
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll a,b,c;
 cin>>a>>b>>c;
 if((a-b)*(b-c)*(c-a)==0&&a+b+c!=3*a)py;
 else pn;
return 0;}


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

vector<vector<int>> g;
int n,u,v;

void bfs(int start,vector<int> &dist){
  queue<int> que;
  que.push(start);

  while(!que.empty()){
    int c = que.front();
    que.pop();

    for(int next:g[c]){
      if(dist[next]==-1){
        dist[next] = dist[c] + 1;
        que.push(next);
      }
    }
  }
}

int main(){
  cin >> n >> u >> v;
  u--;
  v--;
  g.assign(n,vector<int>());

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

  if(g[u].size()==1 && g[u][0]==v){
    cout << 0 << endl;
    return 0;
  }

  vector<int> distt(n,-1),dista(n,-1);
  distt[u]=0,dista[v]=0;
  bfs(u,distt);
  bfs(v,dista);

  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    if(distt[i]<dista[i]) ans = max(ans,dista[i]-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6656
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-9;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int t[210000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a-1;i++){
		int s;scanf("%d",&s);s--;
		t[s]++;
	}
	for(int i=0;i<a;i++)printf("%d\n",t[i]);
}

Measured memory_bytes: 2492
public class Main {

  private static void solve() {
    char[] s = ns();
    int n = s.length;
    int m = 2019;
    long[][] dp = new long[2][m];
    long ret = 0;
    for (int i = 0; i < n; i++) {
      int d = s[i] - '0';
      int from = i % 2;
      int to = from ^ 1;
      for (int j = 0; j < m; j++) {
        dp[to][(j * 10 + d) % m] = dp[from][j];
      }
      dp[to][d]++;
      ret += dp[to][0];
    }

    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 38700
import sys
N = int(input())

A = [None] * N
B = [None] * N

for i in range(1, N+1):
    a, b = map(int, sys.stdin.readline().split())
    A[N-i] = a
    B[N-i] = b

cnt = 0
for i in range(N):
    A_add = A[i] + cnt
    r =  A_add % B[i]
    if r == 0:
        pass
    else:
        cnt += B[i] - r
print(cnt)


Measured memory_bytes: 10932
from collections import defaultdict
import itertools
n, c = map(int, input().split())
D = [list(map(int, input().split()))for _ in range(c)]


# 色は0始まりで管理する

# 入力の色を受け取って、それぞれの色毎にいくつあるか
diago0 = defaultdict(int)
diago1 = defaultdict(int)
diago2 = defaultdict(int)

for i in range(n):
    for j, color in enumerate(map(int, input().split())):
        color -= 1
        if (i+j) % 3 == 0:
            diago0[color] += 1
        elif (i+j) % 3 == 1:
            diago1[color] += 1
        else:
            diago2[color] += 1


# 0列目をcにするときのcにするときの最小コスト
cost0 = [0]*c
cost1 = [0]*c
cost2 = [0]*c

for i in range(c):
    for k, v in diago0.items():
        cost0[i] += D[k][i]*v
for i in range(c):
    for k, v in diago1.items():
        cost1[i] += D[k][i]*v
for i in range(c):
    for k, v in diago2.items():
        cost2[i] += D[k][i]*v

INF = 10**18
ans = INF
for trio in itertools.combinations(range(c), 3):
    for a, b, c in itertools.permutations(trio, 3):
        cost = cost0[a]+cost1[b]+cost2[c]
        if cost < ans:
            ans = cost
print(ans)


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int N,W;
vector<int> v,w;
vector<vector<int>> dp; //?????¢???
int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

int rec(int i,int j){
	int retval;
	if(dp[i][j] != -1) return dp[i][j];
	if(i==N){
		retval=0;
	}
	else if(j < w[i]){
		retval=rec(i+1,j);
	}
	else{
		retval=max(v[i]+rec(i+1,j-w[i]),rec(i+1,j));
	}
	
	return dp[i][j]=retval;
}

signed main(){
	// your code goes here
	N=read(),W=read();
	v.resize(N);
	w.resize(N);
	dp.resize(N+1);
	REP(i,N+1) dp[i].resize(W+1,-1);
	REP(i,N){
		v[i]=read();
		w[i]=read();
	}
	
	cout << rec(0,W) << endl;
}

Measured memory_bytes: 10736
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

int main(){
	FIO
	
	int A, B, M;cin >> A >> B >> M;
	vector<int> a(A), b(B);
	int min_ref = INT_MAX, min_mic = INT_MAX;
	for(int i = 0; i < A;i++){cin >> a[i];min_ref = min(min_ref, a[i]);}
	for(int i = 0; i < B;i++){cin >> b[i];min_mic = min(min_mic, b[i]);}
	int min_cost = min_ref + min_mic;
	for(int i = 0; i < M; i++){
		int x, y, c;cin >> x >> y >> c;
		x--;y--;
		int now = a[x] + b[y] - c;
		if(now < min_cost)
			min_cost = now;
		
	}
	cout << min_cost;
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args) {
	      Scanner sc = new Scanner(System.in);
	      int h = sc.nextInt();
	      int w = sc.nextInt();
	      
	      char[][] grid = new char[h][w];
	      for(int i = 0; i < h; i++)
	        grid[i] = sc.next().toCharArray();
	      
	      int[][] cnt = new int[h][w];
	      if(grid[0][0] == '#')
	        cnt[0][0] = 1;

	      for(int i = 1; i < w; i++) {
	          if(grid[0][i] == '.')
	            cnt[0][i] = cnt[0][i-1];
	          else {
	            if(grid[0][i-1] == '#')
	              cnt[0][i] = cnt[0][i-1];
	            else
	              cnt[0][i] = cnt[0][i-1] + 1;
	          }
	        }
	      for(int i = 1; i < h; i++) {
	          cnt[i][0] = cnt[i-1][0];
	          if (grid[i-1][0] == '.' && grid[i][0] == '#')
	          	cnt[i][0]++;
	        }

	      for(int i = 1; i < h; i++) {
	          for(int j = 1; j < w; j++) {
	            if(grid[i][j] == '.') {
	              cnt[i][j] = Math.min(cnt[i-1][j], cnt[i][j-1]);
	            } else {
	              int up = cnt[i-1][j];
	              if(grid[i-1][j] == '.')
	                up++;
	              int left = cnt[i][j-1];
	              if(grid[i][j-1] == '.')
	                left++;
	              cnt[i][j] = Math.min(up, left);
	            }
	          }
	        }
	      System.out.println(cnt[h-1][w-1]);
	}
}

Measured memory_bytes: 23764