akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        TreeMap<Long,Long> map = new TreeMap<>(Comparator.reverseOrder());

        lines = in.readLine().split(" ");
        Long b = 0L;
        for (int i = 0; i < n; i++) {
          b = Long.parseLong(lines[i]);
          if(map.containsKey(b)) map.put(b, map.get(b) + 1);
          else  map.put(b, 1L);
        }

        Long c = 0L;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          b = Long.parseLong(lines[0]);
          c = Long.parseLong(lines[1]);
          if(map.containsKey(c)) map.put(c, map.get(c) + b);
          else map.put(c, b);
        }

        Long N = new Long(n);
        Long ans = 0L;
        Long k, v;
        Iterator<Long> ite = map.keySet().iterator();
        for(Long cnt = 0L; cnt < N; cnt += v) {
          k = ite.next();
          v = map.get(k);
          if(cnt + v < N) ans += k * v;
          else ans += k * (n - cnt);
        }

        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 79412
var s:string;
    z,x:int64;
    i,n:longint;

begin
  readln(s);
  n:=length(s);
  val(s,z);
  for i:=1 to n do
  inc(x,ord(s[i])-48);
  if z mod x=0 then writeln('Yes') else writeln('No');
end.

Measured memory_bytes: 128
class User:
    def __init__(self, name, card):
        self.card = card
        self.name = name

    def draw(self):
        val = self.card[0]
        del self.card[0]
        return val

A = User("A", list(raw_input().strip()))
B = User("B", list(raw_input().strip()))
C = User("C", list(raw_input().strip()))

user = A
while(True):

    if len(user.card) == 0:
        break

    nextId = user.draw()

    if nextId == 'a':
        user = A
    elif nextId == 'b':
        user = B
    else:
        user = C

print user.name


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,m,q;
  cin >> n >> m >> q;
  int a[q],b[q],c[q],d[q];
  
  rep(i,q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }
  ll ans=0;
  exrep(i1,1,m){
    exrep(i2,i1,m){
      exrep(i3,i2,m){
        exrep(i4,i3,m){
          exrep(i5,i4,m){
            exrep(i6,i5,m){
              exrep(i7,i6,m){
                exrep(i8,i7,m){
                  exrep(i9,i8,m){
                    exrep(i10,i9,m){
                      int A[10];
                      A[0]=i1,A[1]=i2,A[2]=i3,A[3]=i4,A[4]=i5,A[5]=i6,A[6]=i7,A[7]=i8,A[8]=i9,A[9]=i10;
                      ll sum=0;
                      rep(i,q){
                        if(A[b[i]]-A[a[i]]==c[i])sum+=d[i];
                      }
                      ans=max(ans,sum);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
                             
    
  return 0;     
}


Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var dic = new Dictionary<string, int>();
        for (int i = 0; i < N; i++)
        {
            var S = ReadLine();
            if (dic.ContainsKey(S))
            {
                dic[S]++;
            }
            else
            {
                dic[S] = 1;
            }
        }
        var list = new List<string>();
        var max = dic.Values.Max();
        foreach (var i in dic)
        {
            if (i.Value == max)
            {
                list.Add(i.Key);
            }
        }
        list.Sort();
        foreach (var i in list)
        {
            WriteLine(i);
        }
    }
}


Measured memory_bytes: 52124
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
const int mod=1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main(){
    int m1,m2,d1,d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;

    if(m2 -m1 == 1){
        puts("1");
    }else{
        puts("0");
    }

    //cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a,s,y,t;
  while(1){
    scanf("%d %d",&a,&s);
    if(a == 0 && s == 0)
      break;
    for(y=0;y<a;y++){
      for(t=0;t<s;t++){
        printf("#");
      }
      printf("\n");
        }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 2608
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int euler(int num){

	 int ret = num;

	 for(int i = 2; i*i <= num;  i++){
			if(num%i == 0) {
				  ret  = ret/i*(i-1);
				  while(num%i == 0)num /= i;
			}
	  }
	  if(num != 1) ret = ret/num*(num-1);
	  return ret;
}

int main(){

	int N;
	scanf("%d",&N);

	printf("%d\n",euler(N));

	return 0;
}

Measured memory_bytes: 3164
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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



  cin >> n;
  FOR(i, 1, n + 1) {
    s = to_string(i);
    if (s.size() % 2) ans++;
  }
  cout << ans << endl;





  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
 ll n,s;
 cin>>n>>s;
 if(s==n){cout<<n+1<<endl;return 0;}
 ll border=sqrt(n);
 for(int i=2;i<=sqrt(n)+100000;i++){
     ll res=0,rec=n;
     while(rec!=0){
          res+=rec%i;
          rec/=i;
     }
     if(res==s){cout<<i<<endl;return 0;}
 }
 vector<ll> tmp;
 for(ll i=2;i<=sqrt(n-s)+10000;i++){
     if((n-s)%(i-1)!=0)continue;
    tmp.push_back(i);
    tmp.push_back((n-s)/(i-1)+1);
     
 }
 sort(all(tmp));
 for(int i=0;i<tmp.size();i++){
     ll res=0,tm=tmp[i],rec=n;
    // cout<<tm<<endl;
     while(rec!=0){
          res+=rec%tm;
          rec/=tm;
     }
     if(res==s){cout<<tm<<endl;return 0;}
 }
 cout<<-1<<endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int gcd(int a, int b){
  int c;
  while( a != 0 ){
    c = a;
    a = b%a;
    b = c;
  }
  return b;
}

int main(void) {
  int w, h, c;
  cin >> w >> h >> c;
  int a = gcd(w, h);
  cout << (w/a * h/a)*c << endl;

  return 0;
}

// EOF

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

int main(){
    int N, K;
    cin >> N >> K;
    int ans = 0;
    while(N != 0){
        N /= K;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

struct Card {
  char suit;
  int value;
};

/* Bubble sort */
void bubble(struct Card A[], int n) {
  for (int i=0; i<n-1; i++) {
    for (int j=n-1; j>i; j--) {
      if (A[j-1].value > A[j].value) {
        swap(A[j-1], A[j]);
      }
    }
  }
}

/* Selection sort */
void selection(struct Card A[], int n) {
  for (int i=0; i<n; i++) {
    int minj = i;
    for (int j=i; j<n; j++) {
      if (A[j].value < A[minj].value){
        minj = j;
      }
    }
    if (i < minj){
      swap(A[i], A[minj]);
    }
  }
}

/* Output sort result */
void print(struct Card A[], int n) {
  for (int i=0; i<n; i++) {
    if (i>0) {
      cout << " ";
    }
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int n) {
  for (int i=0; i<n; i++) {
    if (C1[i].suit != C2[i].suit) {
      return false;
    }
  }
  return true;
}

int main() {
  int N;
  char suit;

  cin >> N;
  Card C1[N], C2[N];
  for (int i=0; i<N; i++) {
    cin >> C1[i].suit >> C1[i].value;
    C2[i] = C1[i];
  }

  bubble(C1, N);
  selection(C2, N);

  print(C1, N);
  cout << "Stable" <<endl;
  print(C2, N);
  if (isStable(C1, C2, N)) {
    cout << "Stable" <<endl;
  } else {
    cout << "Not stable" <<endl;
  }

  return 0;
}



Measured memory_bytes: 3104
from collections import Counter
def factorization(n) -> list:
	ret = []
	i = 2
	while i * i <= n:
		while n % i == 0:
			n //= i
			ret.append(i)
		i += 1
	if n != 1:
		ret.append(n)
	return ret

n=int(input())
if n==1:
	print(0)
	exit()
c=Counter(factorization(n))
ans=0
for x in c.values():
	r=0
	while r*(r+1)//2<=x:
		r+=1
	ans+=r-1
print(ans)

Measured memory_bytes: 9468
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int x;
  cin >> x;

  int ans = 1;
  for(int i = 2; i*i <= x; i++){
    int n = i;
    for(int j = 2; n*i <= x; j++){
      n *= i;
    }
    if(n != i) chmax(ans, n);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	int k, n, p[200000];
	
	cin >> n >> k;
	for(int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int s = 0;
	for(int i = 0; i < k; i++) {
		s += (p[i] + 1);
	}
	int t = s;
	for(int i = 1; i <= n - k; i++) {
		t = t - (p[i-1] + 1) + (p[i+k-1] + 1);
		if (s < t) s = t;
	}
	cout << setprecision(60) << (double)s / 2 << endl;
}

Measured memory_bytes: 1024
N,A,B=map(int,input().split())
res=0
N1=N//(A+B)
N2=N%(A+B)
if A==0:
    res=0
elif B==0:
    res=N
else:
    res1=(N1)*A
    if A<=N2:
        res2=A
    else:
        res2=N2
    res=res1+res2
print(res)

Measured memory_bytes: 3064
#[macro_use]extern crate text_io;
use proconio::input;

fn main() {
    input!(x:i64);
    let mut n = 100i64;
    let mut cnt = 0;
    while n < x {
        n += n / 100;
        cnt += 1;
    }
    println!("{}",cnt);
}

Measured memory_bytes: 2136
import std.stdio;
import std.algorithm;
void main()
{
	int a,b,c,k;
	readf("%d %d %d\n%d",&a,&b,&c,&k);
	int sum=a+b+c-max(a,max(b,c)),x=max(a,max(b,c));
	for (;k--;x*=2) {}
	write(sum+x);
}

Measured memory_bytes: 256
def main():
    N=int(input())
    A=list(map(int,input().split()))
    if 0 in A:
        print(0)
        return
    
    prod=1
    for a in A:
        prod *=a
        if prod > 1000000000000000000:
            print(-1)
            return
    
    print(prod)
main()

Measured memory_bytes: 21640
#include<bits/stdc++.h>
#define REP(i,m,n) for(int i=m;i<n;i++)
#define ll long long
#define RE return
using namespace std;
int n;
ll a[100001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	ll sum=1;
	REP(i,0,n){
		cin>>a[i];
		
	}
	sort(a,a+n);
	REP(i,0,n){
		ll last=sum;
		sum*=a[i];
		if(a[i]!=0ll&&sum<last||sum>(ll)(1e18)){
			cout<<-1;
			RE 0;
		}
	}
	
	if(sum>(ll)(1e18))
	cout<<-1;
	else
	cout<<sum;
	RE 0;
}

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


bool used[256];
int cnt;

void solve(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
		used[s[i]-'a'] = true;
		cnt++;
	}
    if(cnt < 26){
		for(int i = 0; i < 26; i++){
			if(!used[i]){
				cout << s + (char)('a' + i) << endl;
				return;
			}
		}
	}
    string t = s;
	if(next_permutation(s.begin(), s.end())){
		for(int i = 0; i < s.size(); i++){
			cout << s[i];
			if(s[i] != t[i]) break;
		}
		cout << endl;
	}else{
		cout << -1 << endl;
	}
   
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
const int MAXN = 100000 + 10;

int n;
int data[MAXN];
 
int main(){
	scanf("%d", &n);
	
	for(register int i=1; i<=n; i++){
		scanf("%d", &data[i]);
		
		if(data[i] % 2 == 1){
			printf("first");
			return 0;
		}
	}	
	
	printf("second");
	
	

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;
typedef long long ll;

int main() {
   int N;
   cin >> N;
   int l, r;
   vector<int> L, R;
   for (int i = 0; i < N; i++) {
      cin >> l >> r;
      L.push_back(l);
      R.push_back(r);
   }
   L.push_back(0);
   R.push_back(0);
   sort(L.begin(), L.end());
   sort(R.begin(), R.end());
   ll ans = 0;
   for (int i = 0; i <= N; i++) {
      ans += max(0, 2 * (L[N - i] - R[i]));
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
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; }
const ll INF=1LL<<60;

string n;
ll sum;

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main(){
    cin>>n;
    for(auto& x : n){
        sum+=ctoi(x);
    }
    if(sum%9==0) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
    return 0;
}


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

int main()
{ string s,t;
   cin>>s>>t;
   int s1,t1;
   cin>>s1>>t1;
   string u;
   cin>>u;
   if(u==s)s1--;
   else t1--;
   cout << s1<<" "<<t1<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    s = input()
    if str.isupper(s):
        print("A")
    else:
        print("a")


if __name__ == '__main__':
    main()


Measured memory_bytes: 10696
from collections import deque
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
que = deque(a)
right = que.pop()
left = que.popleft()
sums = right - left
while(bool(que)):
  a = que.pop()
  if not bool(que):
    sums += max(abs(right-a),abs(left-a))
    break
  b = que.popleft()
  sums += right + a - left -b
  right = a
  left = b

print(sums)

Measured memory_bytes: 8120
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = a+b;

        if (c>=24)
            System.out.println(c-24);
        else
            System.out.println(c);
    }
}


Measured memory_bytes: 35772
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    map<string,int>m={{"SUN",7},{"MON",6},{"TUE",5},{"WED",4},{"THU",3},{"FRI",2},{"SAT",1}};
    string s;
    cin>>s;
    cout<<m[s]<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  ll X,Y,Z;
  cin>>X>>Y>>Z;
  cout<<(X-Z)/(Y+Z)<<endl;
}


Measured memory_bytes: 256
import math

def a():
    s = input()
    if s == 'RRR':
        print(3)
    elif 'RR' in s:
        print(2)
    elif 'R' in s:
        print(1)
    else:
        print(0)


def b():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    count = 0
    for i, li in enumerate(l):
        for j, lj in enumerate(l[i + 1:],i + 1):
            for lk in l[j + 1:]:
                if lk < li + lj and li != lj and lj != lk:
                    # print(li,lj,lk)
                    count += 1
    print(count)




def c():
    x,k,d = map(int,input().split())
    min = 0
    x = abs(x)
    # k_max = x // d
    # x -= k_max * d
    # k回移動しても0を超えない
    if x >= k * d:
        min = x - k * d
    else:
        # 0を超える直前まで移動（その分kを減算）
        k -= (x // d)
        x -= (x // d) * d
        min = abs(x - (k % 2) * d)
    print(min)



def d():
    pass


# a()
# b()
c()
# d()

Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> t(n), x(n), y(n);
	for(int i = 0; i < n; ++i){
		cin >> t[i] >> x[i] >> y[i];
	}
	int last_t = 0, last_x = 0, last_y = 0;
	bool answer = true;
	for(int i = 0; i < n; ++i){
		const int dt = t[i] - last_t;
		const int dy = abs(y[i] - last_y);
		const int dx = abs(x[i] - last_x);
		if(dx + dy > dt){
			answer = false;
		}else if((dx + dy) % 2 != dt % 2){
			answer = false;
		}
		last_t = t[i];
		last_x = x[i];
		last_y = y[i];
	}
	cout << (answer ? "Yes" : "No") << endl;
	return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  string s[2] = {"Even" , "Odd"};
  cout << s[(a*b)%2] << endl;
  return 0;
}


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

int main(void){
    ll n; cin >> n;
    vector<ll>prime;
    for(int i=2;i<=n;i++){
        bool flag = false;
        for(int j=0;j<prime.size();j++){
            if(i%prime[j]==0){
                flag = true;
            }
        }
        if(flag == false) prime.push_back(i);
    }

    // for(int i=0;i<prime.size();i++){
    //     cout << prime[i] << ' ';
    // }cout << endl;

    vector<ll>cnt(prime.size()+1,0);
    for(int i=2;i<=n;i++){
        for(int j=0;j<prime.size();j++){
            ll tmp = i;
            while(tmp%prime[j]==0){
                cnt[j]++;
                tmp /= prime[j];
                // cout << tmp << ' ';
            }
        }
    }

    // for(int i=0;i<cnt.size();i++){
    //     cout << cnt[i] << ' ';
    // }cout << endl;

    ll ans = 1;
    for(int i=0;i<cnt.size();i++){
        ans = (ans*(cnt[i]+1))%(1000000007);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
T, A = [int(i) for i in input().split()]
H = list(map(int, input().split()))
compare = []

for i in range(N):
    kion = T - H[i]*0.006
    compare.append(abs(kion - A))
    Min = min(compare)
    #print('kion{}'.format(kion))
    #print('差：{}'.format(abs(kion - A)))
print(compare.index(Min)+1)
#print(T,A)
#print(H)
#print('compare:{}'.format(compare))

Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        k: usize
    }
    let d = 1000000007;
    let mut st = vec![1; n + 1];
    for i in 1..n + 1 {
        st[i] = st[i - 1] * i % d;
    }
    let sti: Vec<usize> = st.iter().cloned().map(|x| inv_m(x, d)).collect();
    let mut ans = 1;
    for i in 1..min(n, k + 1) {
        ans = (ans + st[n] * sti[i] % d * sti[n - i] % d * st[n - 1] % d * sti[i] % d * sti[n - i - 1] % d) % d;
    }
    println!("{}", ans);
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}

fn inv_m(n: usize, d: usize) -> usize {
    pow_m(n, d - 2, d)
}


Measured memory_bytes: 8444
#include<stdio.h>
int main(){
	int n,i;
	while(scanf("%d",&n)!=EOF){
		bool flag1=false,flag2=false;
		int sum=1,a[n];
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(i=0;i<n-1;i++){
			if(a[i]<a[i+1])
				flag1=true;
			if(a[i]>a[i+1])
				flag2=true;
			if(flag1&&flag2){
				flag1=false;flag2=false;
				sum++;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int h[n];
    rep(i,n)cin >> h[i];
    
    int ans = 0;
    rep(i,n){
        bool can = true;
        rep(j,i){
            if(h[i]<h[j])can = false;
        }
        if(can)ans++;
    }
    
    cout << ans;
    
	return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>
#include <stdlib.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=a;i<n;i++)
int comp(const void* a,const void* b){
	return *(int*)b-*(int*)a;
}
void fill(int a[],int b,int c){
	for(int i=0;i<b;i++) a[i]=c;
	return;
}
int ary[4][100];
int item[4][101];
int s[4];
int main(void)
{
	int n,a,b,ans=0;
	int i,j,k,l;
	ll W,m;
	scanf("%d %lld",&n,&W);
	FOR(i,0,n){
		scanf("%d %d",&a,&b);
		if(!i) m=a;
		ary[a-m][s[a-m]++]=b;
	}
	FOR(i,0,4){
		qsort(ary[i],s[i],sizeof(int),comp);
		FOR(j,0,s[i]) item[i][j+1]=item[i][j]+ary[i][j];
	}
	FOR(i,0,s[0]+1){
		FOR(j,0,s[1]+1){
			FOR(k,0,s[2]+1){
				FOR(l,0,s[3]+1){
					if(m*i+(m+1)*j+(m+2)*k+(m+3)*l<=W){
						ans=MAX(ans,item[0][i]+item[1][j]+item[2][k]+item[3][l]);
					}
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}
    

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int main(){
	int N,M;
	cin >> N >> M;
	int road[N] = {0};

	FOR(i,0,M){
		int ai,bi;
		cin >> ai >> bi;
		road[ai-1]++;
		road[bi-1]++;
	}
	FOR(i,0,N) cout << road[i] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int D = 0, N = 0;
    long long ans = 0;
    long long tmp = 0;
    cin >> N;

    for (int i = 0; i < N;i++){
        cin >> tmp;
        while(tmp%2==0){
            ans++;
            tmp = tmp / 2;
        }
        tmp = 2;
    }

    cout << ans << endl;

}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(50 + 5);
const int MAX_X = (int)(50 + 5);

int n, a;
int x[MAX_N];

ll dp[MAX_N][MAX_N][MAX_N * MAX_X];

ll ans = 0;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &a);

  for (int i = 1; i <= n; ++i) {
    scanf("%d", &(x[i]));
  }

  dp[0][0][0] = 1LL;

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      for (int k = 0; k < n * MAX_X; ++k) {
        if (k - x[i] < 0) {
          dp[i][j][k] = dp[i - 1][j][k];
        }
        else {
          if (j > 0) dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
        }
      }
    }
  }

  for (int j = 1; j <= n; ++j) {
    ans += dp[n][j][j * a];
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 65792
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int a,b,d,x;
	char dum[100];
	cin>>a>>b;
	d=sprintf(dum,"%d",b);
	x=a*pow(10,d)+b;
	for(int i=0;i<=1000;i++)
	{
		if(i*i==x)
		{
			puts("Yes");return 0;
		}
	}
	puts("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int R,C;
typedef pair<int, int> P;

char c[1000][1000];

int tek[1000][1000];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int kai=0;
queue<P> a;

void iro(){
    while(true){
        P p=a.front();
        kai=tek[p.first][p.second];
        a.pop();
        for(int i=0;i<4;i++){
            int ny=p.first+dy[i];
            int nx=p.second+dx[i];
            if(0<=nx&&nx<C&&0<=ny&&ny<R&&c[ny][nx]=='.'){
                c[ny][nx]='#';
                tek[ny][nx]=tek[p.first][p.second]+1;
                a.push({ny,nx});
            }
        }
        if(a.size()==0) break;
    }
}

int main(){
    cin>>R>>C;
    
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++){
            cin>>c[i][j];
            
        }
    }
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++){
            if(c[i][j]=='#'){
                a.push({i,j});
                tek[i][j]=0;
            }
        }
    }
    iro();
    cout<<kai<<endl;
    
    
}

Measured memory_bytes: 13328
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007

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

  int N; cin>>N;
  vector<vector<int>> A(2, vector<int>(N));
  rep(i,2) rep(j,N) cin>>A[i][j];

  // 累積和による解法
  vector<int> S1(N+1), S2(N+1);
  rep(i, N) {
    S1[i+1] = S1[i] + A[0][i];
    S2[i+1] = S2[i] + A[1][i];
  }

  int res = 0;
  reps(i,1,N+1) {
    int sum = S1[i] + (S2[N]-S2[i-1]);
    res = max(res, sum);
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
/*ॐ नमो भगवते वासुदेवाय नमः*/
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).rend()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a, n) sort(a, a + n)
#define sortvec(V) sort(all(V))

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

typedef unordered_map<int, int, custom_hash> u_map;
typedef unordered_set<int, int, custom_hash> u_set;
typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef priority_queue<int> p_queue;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

int binpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int inverse(int x){
    return binpow(x, MOD - 2, MOD);
}

void solve()
{
    int n;
    cin >> n;
    if(n == 0)  cout << 1 << endl;
    else cout << 0 << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n,k,q; cin >> n >> k >> q;
  vl point(n,0);
  
  rep(i,q){
    ll x; cin >> x;
    point.at(x-1)++;
  }
  
  rep(i,n){
    if(point.at(i) > q-k) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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

template<class T> struct BinaryIndexTree{
    int n;
    vector<T> bit;
    vector<T> org;

    BinaryIndexTree(int si): bit(si+1), org(si+1) { n = si+1; };

    void add(int idx, T v){
        org[++idx] += v;
        for(int i = idx;i <= n;i+=i&-i) bit[i] += v;
    }

    void update(int idx, T v){
        T vv = v - org[++idx];
        org[idx] = v;
        for(int i = idx;i <= n;i+=i&-i) bit[i] += vv;
    }

    T sum(int a){
        T ret = 0;
        for(int i = a;i > 0;i-=i&-i) ret += bit[i];
        return ret;
    }

    T sum(int l, int r) { return sum(r)-sum(l); };
};

#define int long long

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

    BinaryIndexTree<int> bit(n);
    vector<int> memo(n);

    for(int i = 0;i < m;i++){
        int c, x, y;
        cin >> c >> x >> y;
        if(c == 0){
            memo[x-1] += y;
            bit.update(x-1, memo[x-1]);
        }else{
            cout << bit.sum(x-1, y) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 5176
import sys

n, a, b, c, d = map(int, input().split())
s = input()

lst = [0] * (n+1)
for i in range(1, n+1):
    if s[i-1] == '#':
        lst[i] = 1

if c < d:
    stone = 0
    for i in range(b+1, d+1):
        if lst[i] == 1:
            stone += 1
            if stone == 2:
                print('No')
                sys.exit()
        else:
            stone = 0
    stone = 0
    for i in range(a+1, c+1):
        if lst[i] == 1:
            stone += 1
            if stone == 2:
                print('No')
                sys.exit()
        else:
            stone = 0
    print('Yes')
else:
    brank = 0
    three = 0
    for i in range(b-1, c+1):
        if lst[i] == 0:
            brank += 1
            if brank == 3:
                if i-1 <= d:
                    three = 1
                    break
                else:
                    print('No')
                    sys.exit()
        else:
            brank = 0
    if three == 0:
        print('No')
        sys.exit()
    stone = 0
    for i in range(b+1, d+1):
        if lst[i] == 1:
            stone += 1
            if stone == 2:
                print('No')
                sys.exit()
        else:
            stone = 0
    stone = 0
    for i in range(a+1, c+1):
        if lst[i] == 1:
            stone += 1
            if stone == 2:
                print('No')
                sys.exit()
        else:
            stone = 0
    print('Yes')

Measured memory_bytes: 5044
# C
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[0::2]).most_common()
b=Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0]!=b[0][0]:
    print(n-(a[0][1]+b[0][1]))
else:
    print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int N;
string S;
map< pair<string, string>, int> pat_l;   // first: 文字列パターン second: それが出てくる回数
map< pair<string, string>, int> pat_r;

void make_pat(map< pair<string, string>, int>& pat, string s) {
    ll fact = 1;
    REP(i, N) { fact *= 2; }
    REP(i, fact) {
        string first_s = "", second_s = "";
        REP(j, N) {
            if((i >> j) & 1) { first_s += s[j]; }
            else { second_s += s[j]; }
        }
        pat[make_pair(first_s, second_s)]++;
    }
}

signed main()
{
    cin >> N >> S;

    // pat の作成
    string s_l = S.substr(0, N);
    string s_r = S.substr(N, N);
    reverse(s_r.begin(), s_r.end());

    make_pat(pat_l, s_l);
    make_pat(pat_r, s_r);

    ll ans = 0;
    for(auto& pat : pat_l) {
        pair<string, string> p = pat.first;
        swap(p.first, p.second);
        if(pat_r.count(p) != 0) {
            ans += pat.second * pat_r[p];
        }
    }
    printf("%lld\n", ans);

    return 0;
}


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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

class mint {
public:
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    ll get() const { return x; }
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); return (t & 1) ? a*a*(*this) : a*a; }
    operator ll () const { return x; }
    operator string () const { return to_string(x); }
    friend istream& operator>>(istream& is, mint& a) { is>>a.x; return is; }

    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};

class Combination {
public:
    vector<mint> fc, fci;
    int n;
    Combination(int n): n(n) {
        fc.resize(n+1, mint(1));
        fci.resize(n+1, mint(1));
        for (int i=2; i<=n; ++i) {
            fc[i] = fc[i-1] * mint(i);
            fci[i] = fci[i-1] / mint(i);
        }
    }
    mint operator()(ll n, ll k) {
        if (k == 0 || n == k) return 1;
        return fc[n] * fci[k] * fci[n-k];
    }
};

Combination C(200000);
vector<int> to[200000];
mint dp[200000], ans[200000];
ll num[200000];

int N;

void dfs1(int u, int prev) {
    mint pp = 1;
    ll sum = 0;
    for (int v: to[u]) {
        if (v == prev) continue;
        dfs1(v, u);
        pp *= dp[v];
        pp *= C.fci[num[v]];
        sum += num[v];
    }
    dp[u] = pp * C.fc[sum];
    num[u] = sum + 1;
}

void dfs2(int u, int prev) {
    if (u == 0) {
        ans[u] = dp[u];
    } else {
        mint pcomb = ans[prev] / dp[u] * C.fc[num[u]] * C.fci[N-1] * C.fc[N - num[u] - 1];
        ans[u] = dp[u] * pcomb * C.fci[N - num[u]] * C.fci[num[u] - 1] * C.fc[N - 1];
    }
    for (int v: to[u]) {
        if (v == prev) continue;
        dfs2(v, u);
    }
}

int main() {
    cin >> N;
    for (int i=0; i<N-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    dfs1(0, -1);
    dfs2(0, -1);
    for (int i=0; i<N; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 21748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
	clock_t st = clock();
	ll k;
	cin >> k;
	ll n = 7, ans = 1;
	while (n % k) {
		n = (n * 10 + 7) % k;
		ans++;

		if ((double)(clock() - st) / CLOCKS_PER_SEC >= 1.9) {
			co(-1);
			return 0;
		}
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main() {

	int n;
	cin >> n;

	unsigned long sum = 0;
	for (int i=1; i<=n; i++) {

		if ((i % 3 != 0) && (i % 5 != 0)) {
			sum += i;
		}
	}

	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3632
N, x = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
A.insert(0,0)
for i in range(len(A)-1):
  s = A[i] + A[i+1]
  if s > x:
    diff = min(s - x, A[i+1])
    A[i+1] -= diff
    ans += diff
  
print(ans)


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

int main(){
  int a, b, c;
  std::cin >> a >> b >> c;
  if(a == b){
    std::cout << c << std::endl;
  }else if(b == c){
    std::cout << a << std::endl;    
  }else if(a == c){
    std::cout << b << std::endl;
  }
  return 0;
}


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  
  bool finished = false;
  int count = 0;
  int ans;
  
  for(int i = A; i >= 1; i--){
    if( A % i == 0 && B % i == 0 ) {
      ans = i;
      count++;
      finished = true;
    }
     if( K == count )break;
   }
  cout << ans << endl;
}


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

#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007

int main(){
  fast;
    ll n;
    cin>>n;
    ll arr[n],sum=0;
    for(int i=0;i<n;i++)
        cin>>arr[i],sum+=arr[i];
    ll val[n];
    for(int i=0;i<n;i++)
        val[i]=(sum-arr[i])%mod,sum-=arr[i];
    ll ans=0;
    for(int i=0;i<n;i++)
        ans=(ans+(val[i]*arr[i])%mod)%mod;
    cout<<ans;
  return 0;
}


Measured memory_bytes: 6740
#include<bits/stdc++.h>
using namespace std;
int n,d,A[11][11],ans;
bool Check(int x,int y){
	int a=0;
	for(int j=1;j<=d;j++)a+=(A[x][j]-A[y][j])*(A[x][j]-A[y][j]);
	int b=sqrt(a);
	if(a==b*b)return 1;
	return 0;
}
int main(){
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;i++)for(int j=1;j<=d;j++)scanf("%d",&A[i][j]);
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)if(Check(i,j))ans++;
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cctype>
int main(void){
    char ch;
    
    while(1){
        scanf("%c", &ch);
     
        if(islower(ch)) printf("%c", toupper(ch));
        else if(isupper(ch)) printf("%c", tolower(ch));
        else printf("%c", ch);
        if(ch == '\n') break;
    }
    
    return 0;
}


Measured memory_bytes: 2624
(N,M,K),A,B = $<.map{|ln| ln.split.map(&:to_i) }

n,k,a = 0,K,[]
while 0<A.size && A[0]<=k
	a << A[0]
	k -= A.shift
	n += 1
end
while 0<B.size && B[0]<=k
	k -= B.shift
	n += 1
end
nmax = n
while 0<a.size && 0<B.size
	while 0<a.size && k<B[0]
		k += a.pop
		n -= 1
	end
	while 0<B.size && B[0]<=k
		k -= B.shift
		n += 1
	end
	nmax = n if nmax<n
end
p nmax


Measured memory_bytes: 41744
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define deb(x) cout << #x << "=" << x << endl
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
int M=1e9+7,N=205001;

int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M



void solve() {
	int n;
	cin>>n;
	int ac=0,wa=0,tle=0,re=0;
	string s;
	while(n--){
		cin>>s;
		if(s=="AC") ac++;
		else if(s=="WA") wa++;
		else if(s=="TLE") tle++;
		else re++;
	}
	cout<<"AC x "<<ac<<"\nWA x "<<wa<<"\nTLE x "<<tle<<"\nRE x "<<re;
	
}


signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}





Measured memory_bytes: 3648
from collections import Counter
import math
import statistics
import itertools
a,b=map(int,input().split())
# b=input()
# c=[]
# for i in a:
#     c.append(int(i))
# A,B,C= map(int,input().split())
# f = list(map(int,input().split()))
g = [list(map(lambda x: '{}'.format(x), list(input()))) for _ in range(a)]
# h = []
# for i in range(a):
#     h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen

for i in range(a):
    for k in range(b):
        count=0
        if g[i][k]==".":
            if k-1>=0:
                if g[i][k-1]=="#":
                    count+=1
            if i-1>=0:
                if g[i-1][k]=="#":
                    count+=1
            if i-1>=0 and k-1>=0:
                if g[i-1][k-1]=="#":
                    count+=1
            if k+1<=b-1:
                if g[i][k+1]=="#":
                    count+=1
            if i+1<=a-1:
                if g[i+1][k]=="#":
                    count+=1
            if i+1<=a-1 and k+1<=b-1:
                if g[i+1][k+1]=="#":
                    count+=1
            if i-1>=0 and k+1<=b-1:
                if g[i-1][k+1]=="#":
                    count+=1
            if i+1<=a-1 and k-1>=0:
                if g[i+1][k-1]=="#":
                    count+=1
            g[i][k]=str(count)


for i in g:
    print("".join(i))

Measured memory_bytes: 10900