akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>

const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int N;
    cin>>N;
    vector<int> L(N);
    for(int i=0;i<N;i++){
        cin>>L.at(i);
    }
    sort(L.begin(),L.end());
    int ans=0;
    for(int i=0;i<N-2;i++){
        for(int j=i+1;j<N-1;j++){
            ans+=lower_bound(L.begin()+j+1,L.end(),L[i]+L[j])-L.begin()-j-1;
        }
    }
    cout<<ans<<endl;
}

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

using LL = long long;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

	const int M = 62;
	const LL MOD = 1e9 + 7;

	int n; cin >> n;
	vector<int> f(M);
	for (int i = 0; i < n; ++i) {
		LL x; cin >> x;
		for (int j = 0; j < M; ++j) {
			if (x & (1ll << j)) {
				f[j]++;
			}
		}
	}
	LL ans = 0;
	for (int j = 0; j < M; ++j) {
		LL val = (1ll << j) % MOD;
		val = (val * f[j]) % MOD;
		val = (val * (n - f[j])) % MOD;
		ans = (ans + val) % MOD;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import math
x = int(input())
prime = []
sarch = [i for i in range(2, 10 ** 6 + 1)]
while True:
    if (sarch[0] > math.sqrt(x)):
        prime.extend(sarch)
        for i in prime:
            if i >= x:
                print(i)
                exit()
    else:
        head = sarch[0]
        prime.append(head)
        sarch.pop(0)
        sarch = [num for num in sarch if num % head != 0]

Measured memory_bytes: 51096
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

to = 0
rem = 0
for i in range(N+1):
	if rem > 0:
		a = max(0, A[i]-rem)
		to += A[i] - a
		A[i] = a
	if i == N:
		break
	
	if A[i] < B[i]:
		rem = B[i] - A[i]
		to += A[i]
	else:
		rem = 0
		to += B[i]

print(to)



Measured memory_bytes: 18476
import java.util.*;
import java.util.stream.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long x = in.nextLong();
		long ans = Math.abs(x - in.nextLong());
		for (int i = 1; i < n; i++) {
			ans = gcd(ans, Math.abs(x - in.nextLong()));
		}
		System.out.println(ans);
	}

	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}

Measured memory_bytes: 48224
// 

#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long    // %d=>%lld, 1<<n  => 1LL<<n
#define pb push_back

using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
    return firstEl.second > secondEl.second;
}

const ll MOD = 1000000007;
const int INF = 1000000007;
// const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
// const ll LLINF = 1LL << 50;
const double PI = acos(-1);
const double EPS = 0.000000001;


const int MAX_n = 100000;
int n,a[MAX_n];

int cnt[3];


signed main(){

    cin >> 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]%4 == 0){
                cnt[2]++;
            }else{
                cnt[1]++;
            }
        }else{
            cnt[0]++;
        }
    }
    if(cnt[1] == 0){
        if(cnt[0]<=cnt[2]+1){
            cout<< "Yes\n";
        }else{
            cout<< "No\n";
        }
    }else{
        if(cnt[0]<=cnt[2]){
            cout<< "Yes\n";
        }else{
            cout<< "No\n";
        }
    }


    return 0;
}

Measured memory_bytes: 1024
n=int(input())
a=list(map(int, input().split()))
a.append(0)
a=[0]+a
ans=0

for i in range(n+1):
    ans+=abs(a[i+1]-a[i])

for i in range(1,n+1):
    x=abs(a[i+1]-a[i-1])
    y=abs(a[i+1]-a[i])+abs(a[i]-a[i-1])
    print(ans+x-y)
            

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

public class Main {
    
    static int n;
    static int m;
    
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        n=Integer.parseInt(st.nextToken());
        m=Integer.parseInt(st.nextToken());
        boolean[][] n_map=new boolean[n][n];
        boolean[][] m_map=new boolean[m][m];
        String str;
        for(int i=0;i<n;i++){
            str=br.readLine();
            for(int j=0;j<n;j++){
                n_map[i][j]=(str.charAt(j)=='#');
            }
        }
        for(int i=0;i<m;i++){
            str=br.readLine();
            for(int j=0;j<m;j++){
                m_map[i][j]=(str.charAt(j)=='#');
            }
        }
        
        for(int i=0;i<=n-m;i++){
            for(int j=0;j<=n-m;j++){
                if(check(n_map,m_map,i,j)){
                    System.out.println("Yes");
                    System.exit(0);
                }
            }
        }System.out.println("No");
        
    }
    
    static boolean check(boolean[][] a,boolean[][] b,int start1,int start2){
        
        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                if(a[i+start1][j+start2]!=b[i][j]){ return false; }
            }
        }
        return true;
    }
}


Measured memory_bytes: 22992
n = int(input())
arr = list(map(int, input().split()))
L, R = {0}, {0}
for i in range(len(arr)//2):
    tmp = {arr[i]}
    for a in L:
        tmp.add(a + arr[i])
    L |= tmp
for i in range(len(arr)//2, len(arr)):
    tmp = {arr[i]}
    for a in R:
        tmp.add(a + arr[i])
    R |= tmp
input()
for m in map(int, input().split()):
    tag = False
    for a in L:
        if m - a in R:
            tag = True
            break
    print(['no', 'yes'][tag])


Measured memory_bytes: 5668
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int sum = 0;
    int max = -1;
    int max_index = -1;
    int[] array = new int[n];

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
      if(array[i]>max){
        max = array[i];
        max_index = i;
      }
    }
    array[max_index] /= 2;
    for(int i=0; i<n; i++){
      sum += array[i];
    }

    System.out.println(sum);
  }

}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n, k; cin>>n>>k;
    vector<int> g[201];
    int m=0;
    for(int i=0; (1<<i)<=n; i++){
        for(int j=1; j<=n; j++){
            if(j==(1<<i)) continue;
            if(j&(1<<i)){
                g[1<<i].push_back(j);m++;
            }
        }
    }
    cout<<m<<endl;
    for(int i=0; (1<<i)<=n; i++){
        for(auto x:g[1<<i]){
            cout<<(1<<i)<<" "<<x<<endl;
        }
    }
    for(int i=0; i<k; i++){
        bool ok=0;
        int ans=0;
        for(int j=0; (1<<j)<=n; j++){
            cout<<(1<<j)<<endl;
            string s; cin>>s;
            if(s=="Yes"){
                ok=1;
                break;
            }else if(s=="Near"){
                ans^=(1<<j);
            }
        }
        if(ok) continue;
        cout<<ans<<endl;
        string s0; cin>>s0;
    }
    return 0;
}


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

int main() {
	int n; cin >> n;
	vector<pair<int, int>>AB(n);
	for (auto&& x : AB) {
		int a, b; cin >> a >> b;
		x.first = a, x.second = b;
	}

	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		if ((AB[i].first + ans) % AB[i].second != 0) {
			long long tmp = (AB[i].first + ans) / AB[i].second + 1;
			ans += (AB[i].second * tmp) - (AB[i].first + ans);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;
int n;
int a[100010];
int b[100010];
int c[100010];
int d[100010];


signed main(){

    cin >> n;
    
    rep(i,n) cin >> a[i];
    sort(a,a+n);

    deque<int> dq;

    dq.push_front(a[0]);
    int cnt = 1;
    int s = 1;
    int l = n-1;
    int c = 1;
    while(cnt != n){
        if(c == 1){
            dq.push_back(a[l]);
            l--;
            cnt++;
        }else{
            dq.push_front(a[l]);
            l--;
            cnt++;
        }

        if(cnt == n)break;

        if(c == 1){
            dq.push_back(a[s]);
            s++;
            cnt++;
        }else{
            dq.push_front(a[s]);
            s++;
            cnt++;
        }
        c *= -1;
    }
    int ans1 = 0;
    for(auto itr = dq.begin(); itr != dq.end()-1; ++itr) {
        ans1 += abs(*itr - *(itr+1));
    }


    deque<int> dq1;
    dq1.push_front(a[n-1]);
    cnt = 1;
    s = 0;
    l = n-2;
    c = 1;
    while(cnt != n){

        if(c == 1){
            dq1.push_back(a[s]);
            s++;
            cnt++;
        }else{
            dq1.push_front(a[s]);
            s++;
            cnt++;
        }

        if(cnt == n)break;

        if(c == 1){
            dq1.push_back(a[l]);
            l--;
            cnt++;
        }else{
            dq1.push_front(a[l]);
            l--;
            cnt++;
        }

        c *= -1;
    }
    int ans2 = 0;
    for(auto itr = dq1.begin(); itr != dq1.end()-1; ++itr) {
        ans2 += abs(*itr - *(itr+1));
    }

    cout << max(ans1,ans2) << endl;

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 2688
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;

typedef long long ll;

int x[51],y[51];
int main(){

   int n,K;
   cin >> n >> K;
   vector< pair<int,int> > l;
   for(int i = 0; i < n;i++){
      int xx,yy;
      cin >> xx >> yy;
      x[i] = xx;
      y[i] = yy;
      l.push_back(pair<int,int>(xx,yy));
   }

   ll ans =(1LL << 62);
   for(int i = 0; i < n;i++){
      for(int j = 0; j < n;j++){
         //if(i >= j)break;
         for(int k=0;k<n;k++){
            for(int t=0;t<n;t++){
              // if(k>=t)break;
               int num = 0;
               for(int p=0;p<n;p++){
                  if(l[p].first >= x[i] && l[p].first <= x[j] && l[p].second >= y[k] && l[p].second <= y[t])num++;
               }
               //cout << num << endl;
               if(K > num)continue;
               ans = min(ans , (ll)(x[j] - x[i])*(y[t] - y[k]));
            }
         }
      }
   }

   cout << ans << endl;

}

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

int main() {
	int h, a;

	cin >> h >> a;
	int cnt = 0;
	while(true) {
		if(h <= 0) {
			cout <<  cnt;
			break;
		} else {
			h -= a;
			cnt++;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        String[] s = new String[n];
        HashSet<String> hs = new HashSet<String>();
        boolean doit = true;
        for(int i = 0; i<n; i++){
            s[i] = in.next();
            if(hs.add(s[i])==false){
                doit = false;
                out.println("No");
                break;
            }
        }
        if(doit){
            String prev = s[0];
            boolean check = true;
            for(int i = 1; i<n; i++){
                if(s[i].charAt(0)!=prev.charAt(prev.length()-1)){
                    check = false;
                    out.println("No");
                    break;
                }
                prev = s[i];
            }
            if(check) out.println("Yes");
        }
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

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

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



Measured memory_bytes: 32944
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    N = int(input())
    D = [int(c) for c in input().split()]
    num = 0
    for i in range(len(D)):
        for j in range(i + 1, len(D)):
            num += D[i] * D[j]
    print(num)
    
            
        


if __name__ == '__main__':
    main()

Measured memory_bytes: 21660
H, W = map(int, input().split())
S = []
for h in range(H):
  S.append(list(input()))
  
dx = [-1,  0,  1, -1, 1, -1, 0, 1]
dy = [-1, -1, -1,  0, 0,  1, 1, 1]

for h in range(H):
  for w in range(W):
    if S[h][w] == ".":
      bomb = 0
      for nx, ny in zip(dx, dy):
        if h+nx<0 or w+ny<0 or h+nx>=H or w+ny>=W:
          pass
        else:
          if S[h+nx][w+ny] == '#':
            bomb+=1
      S[h][w] = str(bomb)
    else:
      pass

for s in S:
  print(''.join(s))

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    string s,t;
    cin >> s;
    t = s;
    reverse(t.begin(),t.end());

    string ans;

    int s_i = 0,t_i = 0;
    int cnt = 0;

    while(s_i < s.length() && t_i < s.length()){
        if(s[s_i] == t[t_i]){
            ans.push_back(s[s_i]);
            s_i++;
            t_i++;
        }else if(s[s_i] != 'x' && t[t_i] != 'x' && s[s_i] != t[t_i]){
            //回文にできない
            cout << "-1" << endl;
            return 0;
        }else{
            cnt++;
            if(s[s_i] == 'x'){
                ans.push_back('x');
                s_i++;
            }else if(t[t_i] == 'x'){
                ans.push_back('x');
                t_i++;
            }
        }
    }

    if(s_i != s.length()){
        for(int i = s_i;i < s.length();i++){
            ans.push_back(s[i]);
        }
    }else if(t_i != t.length()){
        for(int i = t_i;i < t.length();i++){
            ans.push_back(t[i]);
        }
    }
    cout << ans.length() - s.length() << endl;

    return 0;
}

Measured memory_bytes: 784
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a,b,c,d,n;
int main()
{
	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&n);
	a=8ll*a;b=4ll*b;c=2ll*c;
	if(a<=d||b<=d||c<=d)
	{
		a=min(a,min(b,c))/2ll;
		printf("%lld\n",a*n);
		return 0;
	}
	if(n%2==0)
	{
		printf("%lld\n",d*n/2ll);
		return 0;
	}
	else
	{
		ll ans=d*(n/2ll);
		//printf("%lld %lld %lld %lld\n",ans,a,b,c);
		ans+=min(a,min(b,c))/2;
		printf("%lld\n",ans);
	}
	return 0;
 } 

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string S;
  cin >> S;
  
  int lg = S.size();
  
  if(S.at(lg-1) == 's'){
    cout << S << "es" << endl;
  }
  
  else{
    cout << S << "s" << endl;  
  }
  
}

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

int main()
{
    int a,b,c,k;
    
    cin >> a >> b >> c;
    cin >> k;
    max({a,b,c});
    
    
    
    int sum = a+b+c;
    
    cout << sum + max({a,b,c})* ((1 << k) - 1);
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){int n,i;
cin>>n;
int a[n+1],b[n+1],c[n+1];
int dp[n+1][4];
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++){cin>>a[i]>>b[i]>>c[i];}
dp[1][1]=a[1],dp[1][2]=b[1],dp[1][3]=c[1];
for(i=2;i<=n;i++){
    dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i];
    dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i];
    dp[i][3]=max(dp[i-1][2],dp[i-1][1])+c[i];
}
cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
    return 0;}

Measured memory_bytes: 2944
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        boolean out = false;
        if(a == b && b != c) out = true;
        if(b == c && a != c) out = true;
        if(c == a && a != b) out = true;
        System.out.println(out ? "Yes" : "No");
    }
}

Measured memory_bytes: 21972
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

bool is_syo(int *a, int N){
  for(int i = 0; i < N - 1; i++){
    if(a[i] >= a[i + 1]){
      return false;
    }
  }

  return true;
}

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

  for(int i = 0; i < N; i++){
    for(int j = i + 1; j < N; j++){
      int b[N];
      for(int k = 0; k < N; k++) b[k] = p[k];
      int tmp = b[i];
      b[i] = b[j];
      b[j] = tmp;
      if(is_syo(b, N)){
        //cout << i << j << endl;
        cout << "YES" << endl;
        return 0;
      }
    }
  }

  if(is_syo(p, N)){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<LL> x, y;
  Solver(LL n) : n(n), x(n), y(n){};

  void solve() {
    set<pair<LL, LL>> S;
    for (int i = 0; i < n; ++i) {
      cin >> x[i] >> y[i];
      S.emplace(x[i], y[i]);
    }
    DBG(x, y)
    int ans = n;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (i == j) continue;
        LL p = x[i] - x[j];
        LL q = y[i] - y[j];
        int tmp = 0;
        for (int k = 0; k < n; ++k) {
          if (S.find({x[k] + p, y[k] + q}) != S.end()) tmp++;
        }
        ans = min(ans, n - tmp);
      }
    }
    cout << ans << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//vector<ll> cue: キューの宣言
//n重ループ：初期化の位置に注意
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

ll a(ll n, ll x) {
	ll r = pow(10, x);
	n = (n % r);
	n /= pow(10, x - 1);
	return n;
}

int main() {
	ll N; cin >> N;
	string s[N]; rep(i, N)cin >> s[i];

	ll a = 0, b = 0, ab = 0;
	rep(i, N) {
		if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') ab++;
		else if (s[i][s[i].size() - 1] == 'A')a++;
		else if (s[i][0] == 'B')b++;
	}

	ll ans = 0;
	rep(i, N) {
		for (int j = 0; j <= s[i].size() - 2; j++) {
			if (s[i][j] == 'A' && s[i][j+1] == 'B')ans++;
		}
	}

	if (ab == 0) cout << ans + min(a, b) << endl;
	else if (a + b > 0) cout << ans + ab + min(a, b) << endl;
	else cout << ans + ab - 1 << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int a,b,c,x,y;
  ll ans=INF;
  cin >> a >> b >> c >> x >> y;
  c*=2;
  rep(i,100001){
    ll tmp=c*i+max(x-i,0)*a+max(y-i,0)*b;
    chmin(ans,tmp);
  }
  cout << ans << endl;

  return 0;
}


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

int n, A[2000], q;

int solve(int i, int sum) {
    if (sum == 0) return 1;
    if (sum < 0) return 0;
    if (i >= n) return 0;
#ifdef DEBUG
    cout << "i:" << i << " sum:" << sum << endl;
#endif
    int res = solve(i + 1, sum) || solve(i + 1, sum - A[i]);
    return res;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        int m;
        cin >> m;
#ifdef DEBUG
        cout << m << endl;
#endif
        if (solve(0, m)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3088
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int a = scan.nextInt();
	    int b = scan.nextInt();
	    scan.close();
	    int cnt=0;
	    for(int i=a;i<=b;i++) {
	    	String s = String.valueOf(i) ;
	    	for(int j=0;j<s.length()/2;j++) {
	    		int x = Character.getNumericValue(s.charAt(j));
	    		int y = Character.getNumericValue(s.charAt(s.length()-1-j));
	    		if(x!=y)break;
	    		else if(j==s.length()/2-1)cnt++;

	    	}
	    }
	    System.out.println(cnt);
	}

}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n, k);
  in(string, s);
  int ans = 0;
  rep(i, n - 1) if (s[i] == s[i + 1]) ++ans;
  out(min(ans + k * 2, n - 1));
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
int main(void)
{
        int a[3][3],b[20],m,n,i,j=0,k=0,l=0,p=0;
        char s[1000];

        for(i=0; i<3; i++){
                for(j=0; j<3; j++)
                scanf("%d",&a[i][j]);
        }
        scanf("%d",&n);

        for(i=0; i<n; i++)      scanf("%d",&b[i]);
                
        for(i=0; i<3; i++){ p=0; //ヨコline check
                for(j=0; j<3; j++){ 
                        for(k=0; k<n; k++)
                                if(a[i][j]==b[k]) p++;
                        if(p==3){ printf("Yes\n"); return 0;}
                }
        }
        p=0;
        for(i=0; i<3; i++){ p=0; //タテline check
                for(j=0; j<3; j++){ 
                        for(k=0; k<n; k++)
                                if(a[j][i]==b[k]) p++;
                        if(p==3){ printf("Yes\n"); return 0;}
                }
        }

                while(a[1][1]==b[i]){ i++;
                        if(i==111){ printf("No\n"); return 0;}
                }
p=0;
        for(i=0; i<3; i++){
                for(k=0; k<n; k++)
                if(a[i][i]==b[k]) p++;
                if(p==3){ printf("Yes\n"); return 0;}
        }
        p=0;
        for(i=0; i<3; i++){ 
                for(k=0; k<n; k++)
                if(a[2-i][i]==b[k])p++;
                if(p==3){ printf("Yes\n");return 0;}
        }

          printf("No\n");
          return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n, m; cin >> n >> m;
	vector<pair<pair<int, int>, int>> py(m);
	rep(i, m) {
		int x, y; cin >> x >> y;
		py[i] = mp(mp(x, y), i);
	}
	SORT(py);
	vector<PII> print(m);
	int cnt = 1;
	rep(i, m) {
		int p1 = py[i].first.first;
		if (i != 0) {
			if (py[i - 1].first.first == py[i].first.first)cnt++;
			else cnt = 1;
		}
		int p2 = cnt;
		print[py[i].second] = mp(p1, p2);
	}

	rep(i, m) {
		int p1 = print[i].first;
		int p2 = print[i].second;
		printf("%06d%06d\n", p1, p2);
	}
}

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

using namespace std;

int main() {
    
    int n,k;
    cin >> n >> k;
    int ans = 0;
    while(n--) {
        int x;
        cin >> x;
        ans += x >= k;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h> 


int main(){ 
    int h, w; 
    int i, j; 
    while(1){ 
        scanf("%d %d ", &h, &w); 
        if(h==0&&w==0)break; 
        for(i=0;i<h;i++){ 
            for(j=0;j<w;j++){ 
                if(i==0||i==h-1||j==0||j==w-1){ 
                    printf("#"); 
                }else{ 
                    printf("."); 
                } 
            } 
            printf("\n"); 
        } 
        printf("\n"); 
    } 


    return 0; 
}


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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif

int main()
{
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    string a , b;
    cin >> a >> b;
    b.pop_back();
    if(a == b)cout << "Yes\n";
    else cout << "No\n";
    #ifdef VAMP
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>

using namespace std;

int main() {
    string str;
    cin >> str;

    int i;
    for(i=0; i<str.length(); i++) {
        if(i%2==0) {
            cout << str[i];
        }
    }
    cout << endl;

    return 0;

}

Measured memory_bytes: 576
#include <iostream>
#include <math.h>

using namespace std;

#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main() {
    int N,A,B;
    cin>>N >> A >> B;
    int max=MIN(A,B);
    int min = 0;
    if(N<A+B){
        min = A+B-N;
    }

    cout << max << " " << min << endl;
}

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

#define double long double
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

int norm(int a) {
  return ((a % MOD) + MOD) % MOD;
}

int mul(int a, int b) {
  return int(a * 1LL * b % MOD);
}

int binPow(int a, int k) {
  int ans = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
  }
  return ans;
}

// If I need to find (x / a) % MOD, I need to use this function:
//    (x / a) % MOD = (x * inv(a)) % MOD
int inv(int a) {
  int b = binPow(a, MOD - 2);
  assert(mul(a, b) == 1);
  return b;
}

// Init variables here
const int N = 1e6 + 7;

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);

}

char s[12];

void solve() {
  int n;
  scanf("%d", &n);
  map<long long, int> mp;
  long long hash;
  FOR(i, 0, n) {
    scanf("%s", s);
    sort(s, s + 10);
    hash = 0;
    FOR(j, 0, 10) {
      hash = hash * 27 + s[j] - 'a' + 1;
    }
    mp[hash]++;
  }
  long long ans = 0, cur;
  for (auto p : mp) {
    cur = p.Y;
    ans += cur * (cur - 1) / 2;
  }
  printf("%lld\n", ans);
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  //ios_base::sync_with_stdio(false); cin.tie();
  //auto beginProgram = chrono::steady_clock::now();
  //int t; scanf("%d", &t); while (t--) 
  {
    input();
    solve();
  }
  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int main() {
  string s;
  cin>>s;
  string t="keyence";
  
   for(int i=0;i<s.size();i++){
      for(int j=i;j<s.size();j++){
        string h;
        for(int k=0;k<s.size();k++){
          if(k>i&&k<j){continue;}
          else{h+=s[k];}
        }
        if(h==t){cout<<"YES"<<endl;return 0;}
   }
   }
   cout<<"NO"<<endl;
  return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;cin>>s;
    bool key[26] = {false};
    bool key_none=true;
    for(int i=0;i<s.length();i++){
        key[s[i]-'a']=true;
    }
    for(int i=0;i<26;i++){
        if(key[i]==false){
            char ans='a'+i;
            cout<<ans<<endl;
            key_none=false;
            break;
        }
    }
    if(key_none) cout<<"None"<<endl;
}

Measured memory_bytes: 512
#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 int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // 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 {
    mint res(*this);
    return res/=a;
  }
};
mint f(int n){
    if (n==0)return 1;
    mint x=f(n/2);
    x*=x;
    if (n%2==1) x*=2;
    return x;
}
mint combination(int a,int n){
    mint x=1, y=1;
    for (int i=0;i<a;i++){
        x*=n-i;
        y*=a-i;
    }
    return x/y;
}
int main(void) {


    int n,a,b;
    cin >> n >> a >> b;
    mint ans;
    ans=f(n)-1;
    mint x,y;
    x=combination(a,n);
    y=combination(b,n);
    ans = ans-(x+y);
    cout << ans.x << endl;


}



Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>	
#include<unordered_map>
#include<unordered_set>
using namespace std;


typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdoutn

int main()
{
	IO;
	int n{},d{},ans{};
	cin>>n>>d;
	while(n--)
	{
		double x{},y{};
		cin>>x>>y;
		if(sqrt((x*x)+(y*y))<=d)ans++;
	}
	cout<<ans<<'\n';
	//system("pause");
	return 0;
}

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


int main(){
  
  int n,m;
  cin>>n>>m;
  vector<int> arr(n);
  for(int i=0;i<n;i++){
   cin>>arr[i]; 
  }
  vector<vector<int> > g(n);
  for(int i=0;i<m;i++){
   int x,y;
    cin>>x>>y;
    x -= 1;
    y -= 1;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int ans =0;
  for(int i=0;i<n;i++){
    int maxa = -1;
   for(int j=0;j<g[i].size();j++){
    maxa = max(maxa,arr[g[i][j]]); 
   }
    if(maxa < arr[i])
      ans += 1;
  }
  cout<<ans<<endl;
  
  
  
  
  
 return 0; 
  
}


Measured memory_bytes: 8776
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<cmath>
#include<vector>
#include<algorithm>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
const int maxn = 1e5+5;
int w[maxn], v[maxn], dp[maxn];

int main(){
	int h, n; cin >> h >> n;
	for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];
	memset(dp, 0x3f, sizeof dp);
	dp[0] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= 2 * h; j++){
			if(j < w[i]) dp[j] = min(dp[j], dp[0] + v[i]);
			else dp[j] = min(dp[j], dp[j - w[i]] + v[i]);
		}
	}
	int mi = inf;
	for(int i = h; i <= 2*h; i++) mi = min(mi, dp[i]);
	cout << mi << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    bool ret = true;
    for(int i = N - 1;i >= 1;i--) {
        if(vec.at(i - 1) > vec.at(i)) {
            vec.at(i - 1)--;
        }
    }
    for(int i = 0;i < N - 1;i++) {
        if(vec.at(i) > vec.at(i + 1)) {
            ret = false;
        }
    }
    if(ret == true) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640
def prime_f(n,p=2):
    if n==1:
        return []
    while True:
        if n<p**2:
            return [n]
        if n%p==0:
            l=prime_f(n//p,p)
            l.append(p)
            return l
        p+=1


def histo_list(lis):
    if lis==[]:
        return []
    new=[[lis[0],1]]
    d=lis[0]
    for c in range(1,len(lis)):
        if lis[c]!=d:
            new.append([lis[c],1])
            d=lis[c]
        else:
            new[-1][1]+=1
    return new


n=int(input())
a=prime_f(n)
a=a[::-1]
b=histo_list(a)
c=[b[x][1] for x in range(len(b))]
s=0
for x in c:
    s+=((8*x+1)**0.5-1)//2
print(int(s))

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

#define pb push_back
#define fo(i,s,t) for(int i = s; i <= t; ++ i)
const int maxn = 100050;

int n, lv1[maxn], lv2[maxn], spot;
vector<int> nex[maxn];
int now, col[maxn];

void bfs(int s,int *d)
{
	queue<int> q; q.push(s);
	fo(i,1,n) d[i] = -1; d[s] = 0;
	while(!q.empty())
	{
		int h = q.front(); q.pop();
		for(auto p:nex[h]) if(d[p]==-1&&p!=spot) 
		{
			d[p] = d[h]+1;
			q.push(p);
		}
	}
}

int main()
{
	scanf("%d",&n);
	fo(i,2,n) {int x, y; scanf("%d%d",&x,&y); nex[x].pb(y); nex[y].pb(x);}
	bfs(1,lv1); bfs(n,lv2);
	int w1, w2; w1 = w2 = 0;
	fo(i,1,n) if(lv1[i] <= lv2[i]) ++ w1; else ++ w2;
	if(w1 > w2) printf("Fennec\n");
	else printf("Snuke\n");
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<string> name(N);
  map<string,int> mp;
  cin >> name[0];
  mp[name[0]]++;
  int a,b;
  for (int i=1; i<N; i++) {
    cin >> name[i];
    mp[name[i]]++;
    a = name[i-1].size();
    b = name[i].size();
    if (name[i-1][a-1] != name[i][0]) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (auto i=mp.begin(); i!=mp.end(); i++) {
    if (i -> second == 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
N=int(input())
A=[int(input())for i in range(N)]
T=A.copy()
A.sort()
max1=A[-1]
mcount=A.count(max1)
max2=A[-2]
for i in range(N):
    if T[i]==max1 and mcount==1:
        print(max2)
    else:
        print(max1)

Measured memory_bytes: 14152
H, W  = map(int, input().split())
m = []
for i in range(H):
    t = list(map(int, input().split()))
    m.append(t)
s = 0
u = 0
ans =0
l = []
for i in range(H):
    if u%2==0:
        for j in range(W):
            if i==H-1 and j ==W-1:break
            if m[i][j]%2 ==1:
                s+=1
            if s%2==1 and j !=W-1:
                ans+=1
                l.append([i+1,j+1,i+1,j+2])
            elif s%2==1:
                ans+=1
                l.append([i+1,j+1,i+2,j+1])
    else:
        for j in reversed(range(W)):
            if i==H-1 and j ==0:break
            if m[i][j]%2 ==1:
                s+=1
            if s%2==1 and j !=0:
                ans+=1
                l.append([i+1,j+1,i+1,j])
            elif s%2==1:
                ans+=1
                l.append([i+1,j+1,i+2,j+1])
    u+=1
print(ans)
for p,q,w,e in l:
    print(p,q,w,e)


Measured memory_bytes: 30268
package main

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

func main() {
	sc = initScanner(os.Stdin)
	n := scanInt(sc)
	fmt.Println(resolve(n))
}

func resolve(n int) int {
	for n > 0 {
		n -= 1000
	}

	if n < 0 {
		return -n
	} else {
		return n
	}
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
const int M=200001;
int n,q,a,b;
int head[M],nxt[M<<1],to[M<<1],tot;
void add(int a,int b){
	nxt[++tot]=head[a];
	to[tot]=b;
	head[a]=tot;
}
int cnt[M],Ans[M],t;
void dfs(int x,int la){
	t+=cnt[x];
	Ans[x]=t;
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==la)continue;
		dfs(y,x);
	}
	t-=cnt[x];
}
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<n;i++){
		scanf("%d%d",&a,&b);
		add(a,b),add(b,a);
	}
	while(q--){
		scanf("%d%d",&a,&b);
		cnt[a]+=b;
	}
	dfs(1,0);
	for(int i=1;i<n;i++)printf("%d ",Ans[i]);
	printf("%d\n",Ans[n]);
}

Measured memory_bytes: 17024
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = int(input())
n, q  = map(int, input().split())
s  = input()
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

nac = []
c = 0
for i, s_ in enumerate(s):
    if s[i] == 'C':
        if s[i-1] == 'A':
            c += 1

    nac.append(c)

#print(nac)

for _ in range(q):
    l, r = map(int, input().split())
    print(nac[r-1] - nac[l-1])


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

int main() {
    int a[3];
    rep(i, 3) cin >> a[i];

    int ans = 0;
    while (!(a[0] == a[1] && a[1] == a[2])) {
        int maxv = *max_element(a, a + 3);
        int cnt = count(a, a + 3, maxv);
        if (cnt == 1) {
            rep(i, 3) if (a[i] != maxv) a[i]++;
        } else if (cnt == 2) {
            rep(i, 3) if (a[i] != maxv) a[i] += 2;
        }
        ans++;
    }

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


Measured memory_bytes: 256
N, K = map(int, input().split())
S = list(input())
T = []
pre = S[0]
cnt = 0
ans = -1
for i in range(N):
  if S[i] == pre:
    cnt += 1
    pass
  else:
    T += [pre]
    ans += cnt
    cnt = 0
    pre = S[i]

ans += cnt
T += [pre]
ans += min(K*2, len(T)-1)
print(ans)

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-13
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    long double a, b, c;
    cin >> a >> b >> c;
    ll d = c-a-b;
    (d>0 && 4*a*b < d*d) ? Yes() : No();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    ll a[n], b[n];
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    sort(a, a + n);
    sort(b, b + n);
    if(n % 2 == 1) cout << b[n / 2] - a[n / 2] + 1 << endl;
    else
        cout << b[(n - 1) / 2] + b[n / 2] - a[(n - 1) / 2] - a[n / 2] + 1<< endl;
    return 0;
}

Measured memory_bytes: 6748