akhauriyash/Code-Regression huggingface dataset:
require 'pp'

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 入力値を文字列で返却する
def gets_s()
  gets.chomp
end

N = gets_i
name_hash = Hash.new(0)

N.times do
  s = gets_s[0]
  march = %w(M A R C H)
  if march.include?(s)
    name_hash[s] += 1
  end
end

if name_hash.keys.size < 3
  puts 0
else
  total = 0
  name_hash.keys.combination(3).each do |a, b, c|
    total += name_hash[a] * name_hash[b] * name_hash[c]
  end
  puts total
end


Measured memory_bytes: 2300
#include <iostream>
#include <math.h>//

using namespace std;

int main(){
    int N, D, ans;
    cin >> N >> D;
    
    ans = 0;
    for(int i = 0;i < N ; i++){
        double x, y;
        cin >> x >> y;
        x = pow(x,2);
        y = pow(y,2);
        if((double)sqrt(x+y) <= D){
            ans++;
        }
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 3836
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
	int n;
	cin >> n;
	int ans = 0;
	int *a = new int[n];
	bool *flag = new bool[n];
	for (int i = 0; i < n; i++){
		flag[i] = false;
		cin >> a[i];
	}

	for (int i = 0; i < n; ++i){
		if ((i+1 == a[a[i]-1])&&((flag[i]==false)&&(flag[a[i]-1]==false))){
			ans++;
			flag[i] = true;
			flag[a[i]-1] = true;
	
		}
	
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	map <string, ll> m;
	string s,t;
	cin>>s>>t;
	ll a, b;
	cin>>a>> b;
	m[s]=a; m[t] = b;
	string u;
	cin>>u;
	m[u]--;
	cout<<m[s]<<" "<<m[t]<<"\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 3600
/**
 *    Author:   Jay Sabale
 *	       
**/

#include<bits/stdc++.h>

using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
typedef vector <lli> vl;
typedef vector <string> vs;
typedef vector < pair <long, long> > vll;

// Debugging :
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(lli i=0; i<n; i++)
#define rep(i,k,n) for (lli i = k; i < n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

// Printing Data :
#define pvec(v) forz(i,v.si) cout<<v[i]<<" "; cout<<endl;
#define parr(arr, n) forz(i,n) cout<<arr[i]<<" "; cout<<endl;
#define p1(i) cout<<i<<endl;
#define p2(i, j) cout<<i<<" "<<j<<endl;
#define p3(i, j, k) cout<<i<<" "<<j<<" "<<k<<endl;
#define p4(i, j, k, l) cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;

typedef pair <lli,lli> pll;

// CODE BEGINS :

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

int main()
{
    kira; 

    lli k; cin>>k;

    lli sum=0 ;

    for(lli i=1; i<=k; i++)
    {
        for(lli j=1; j<=k; j++)
        {
            for(lli l=1; l<=k; l++)
            {
                sum = sum + gcd(gcd(i, j), l);
            }
        }
    }

    cout<<sum<<endl;

    return 0;
}




















































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


main()
{
    int n,k; cin>>n>>k;
    vector<int> h(n);
    for(int &x:h) cin>>x;
    sort(rbegin(h),rend(h));
    long long ans{};
    for(int i=k; i<n; ++i) ans+=h[i];
    cout << ans << "\n";
}

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

using namespace std;

typedef long long ll;
#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const ll LINF = 1e18 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

ll check(ll b, ll n) {
  if (n < b) {
    return n;
  } else {
    return check(b, floor(n / b)) + n % b;
  }
}

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

  LCIN(N, S);

  if (N == S) {
    cout << N + 1 << endl;
    return 0;
  }

  // b ≦ √n
  FOR(bi, 2, sqrt(N) + 1ll) {
    if (check(bi, N) == S) {
      cout << bi << endl;
      return 0;
    }
  }

  ll ans = LINF;
  // b > √n
  FOR(pi, 1, sqrt(N - S) + 1ll) {
    if (abs(N - S) % pi != 0) {
      continue;
    }
    ll b = (N - S) / pi + 1;
    if (b <= sqrt(N)) {
      continue;
    }
    if (check(b, N) == S) {
      ans = min(ans, b);
    }
  }
  if (ans < LINF) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  
  return 0;
}



Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	private int N;
	private int Q;
	private List<int>[] adj;
	private long[] cnt;
	private long[] ans;

	public void Solve()
	{
		N = GetInt();
		Q = GetInt();
		adj = Enumerable.Range(0, N).Select(_ => new List<int>()).ToArray();
		for(int i = 0; i < N - 1; i++)
		{
			int a = GetInt() - 1;
			int b = GetInt() - 1;
			adj[a].Add(b);
			adj[b].Add(a);
		}
		cnt = new long[N];
		for(int i = 0; i < Q; i++)
		{
			int p = GetInt() - 1;
			long x = GetLong();
			cnt[p] += x;
		}

		ans = Enumerable.Repeat(-1L, N).ToArray();
		dfs(0, 0);
		Console.WriteLine(string.Join(" ", ans.Select(x => x.ToString()).ToArray()));
	}

	private void dfs(int v, long cost)
	{
		cost += cnt[v];
		ans[v] = cost;

		foreach(int u in adj[v])
		{
			if(ans[u] == -1)
				dfs(u, cost);
		}
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
}


Measured memory_bytes: 80636
#include<stdio.h>
int main()
{
	int h,n,a[100000],i,x;
	scanf("%d %d",&h,&n);
	x=0;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		x+=a[i];
	}
	if(h-x<=0) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	vector<ll> t(n+1);
	for(int i=1;i<=n;++i) {
		cin>>t[i];
		t[i]%=m;
	
	}
	
	/*int res=0;
	for(int i=0;i<n;++i) {
		int sum=0;
		for(int j=i;j<n;++j) {
			sum+=t[j];
			if(sum%m==j-i+1) res++;
		}
	}
	
	cerr<<res<<"\n";*/
	
	for(int i=1;i<=n;++i) {
		t[i]-=1;
		t[i]+=t[i-1];
		t[i]%=m;
		if(t[i]<0) t[i]+=m;
	}
	/*for(auto i:t) cerr<<i<<" ";
	cerr<<"!\n";*/
	map<ll,int> cnt;
	cnt[0]++;
	ll ans=0;
	for(int i=1;i<=n;++i) {
		if(i>=m) cnt[t[i-m]]--; 
		ans+=cnt[t[i]];
		cnt[t[i]]++;
	}
	
	
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 14336
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int k[20001],bit[20001];

int dp[1<<22];
set<int> cnt[1<<22];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&k[i]);
		for(int j=0;j<k[i];j++){
			int a=0;
			scanf("%d",&a);
			a--;
			bit[i]+=(1<<a);
		}
		dp[bit[i]]=bit[i];
		if(cnt[bit[i]].size()<3)cnt[bit[i]].insert(i);
	}
	int res=0;
	for(int i=(1<<22)-1;i>=0;i--){
		for(int j=0;j<22;j++){
			if(!((i>>j) & 1)){
				dp[i]|=dp[i+(1<<j)];
				set<int>::iterator it=cnt[i+(1<<j)].begin();
				while(cnt[i].size()<3 && it!=cnt[i+(1<<j)].end()){
					cnt[i].insert(*it);
					it++;
				}
			}
		}
		if(cnt[i].size()==3){
			int v=__builtin_popcount(i)*__builtin_popcount(dp[i]);
			res=max(res,v);
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 805976
a,b = gets.chomp.split(" ").map(&:to_s)

a_string =''
b_string =''

b.to_i.times do
  a_string= a_string + a
end

a.to_i.times do
  b_string= b_string + b
end

if a.to_i > b.to_i
  puts b_string
else
  puts a_string
end

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

public class Main {

    public static void main(String[] args) throws IOException {
        // TODO 自動生成されたメソッド・スタ
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        int[] a = new int[6];

        for (int i = 0; i < s.length; i++) {
            a[i] = Integer.parseInt(s[i]);
        }
        Dices dices = new Dices(a);

        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
            String[] TopFront = br.readLine().split(" ");
            int top = Integer.parseInt(TopFront[0]);
            int front = Integer.parseInt(TopFront[1]);
            dices.setTop(top);
            dices.setFront(front);
            System.out.println(dices.RIGHT);
        }
    }
}

class Dices {
    int TOP, BOTTOM, LEFT, RIGHT, FRONT, BACK;

    Dices(int[] a) {
        this.TOP = a[0];
        this.FRONT = a[1];
        this.RIGHT = a[2];
        this.LEFT = a[3];
        this.BACK = a[4];
        this.BOTTOM = a[5];
    }

    void setTop(int top) {
        if (this.FRONT == top)
            this.turnN();
        else if (this.RIGHT == top)
            this.turnW();
        else if (this.LEFT == top)
            this.turnE();
        else if (this.BACK == top)
            this.turnS();
        else if (this.BOTTOM == top) {
            this.turnN();
            this.turnN();
        }
    }

    void setFront(int front) {
        if (this.RIGHT == front)
            this.turnL();
        else if (this.LEFT == front)
            this.turnR();
        else if (this.BACK == front) {
            this.turnR();
            this.turnR();
        }
    }

    void turnS() {
        int tmp = this.TOP;
        this.TOP = this.BACK;
        this.BACK = this.BOTTOM;
        this.BOTTOM = this.FRONT;
        this.FRONT = tmp;
    }

    void turnN() {
        int tmp = this.TOP;
        this.TOP = this.FRONT;
        this.FRONT = this.BOTTOM;
        this.BOTTOM = this.BACK;
        this.BACK = tmp;
    }

    void turnW() {
        int tmp = this.TOP;
        this.TOP = this.RIGHT;
        this.RIGHT = this.BOTTOM;
        this.BOTTOM = this.LEFT;
        this.LEFT = tmp;
    }

    void turnE() {
        int tmp = this.TOP;
        this.TOP = this.LEFT;
        this.LEFT = this.BOTTOM;
        this.BOTTOM = this.RIGHT;
        this.RIGHT = tmp;
    }

    void turnL() {
        int tmp = this.FRONT;
        this.FRONT = this.RIGHT;
        this.RIGHT = this.BACK;
        this.BACK = this.LEFT;
        this.LEFT = tmp;
    }

    void turnR() {
        int tmp = this.FRONT;
        this.FRONT = this.LEFT;
        this.LEFT = this.BACK;
        this.BACK = this.RIGHT;
        this.RIGHT = tmp;
    }

}



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

int main() {
  int a, b, c, d;
  cin >> a  >> b >> c >> d;
  int l = a + b;
  int r = c + d;
  if (l < r) {
    cout << "Right";
  }else if(l > r){
    cout << "Left";
  }else{
  	cout << "Balanced";
  }
}

Measured memory_bytes: 3648
N=int(input())
import sys
sys.setrecursionlimit(10**6)
#頂点の色
colors=[0]*(N)
L=[[] for _ in range(N)]
for i in range(N-1):
  #u,vを長さwでつなぐ
  u,v,w=map(int, input().split())
  L[u-1].append((v-1,w,i))
  L[v-1].append((u-1,w,i))
  
def dfs(start_node, pre_node,is_even, ):
  for next_node,l,i in L[start_node]:
    if next_node==pre_node:
      continue
    if is_even:
      if l%2==0:
        colors[next_node]=0
        is_even_next=True
      else:
        colors[next_node]=1
        is_even_next=False
    else:
      if l%2==0:
        colors[next_node]=1
        is_even_next=False
      else:
        colors[next_node]=0
        is_even_next=True
    dfs(next_node, start_node, is_even_next)
    
dfs(0,-1,True)
for color in colors:
  print(color)

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

int main()
{
	int a;
	cin >> a;
	if (a > 200)
	{
		cout << 0;
	}
	else if (a >= 195)
	{
		cout << 5;
	}
	else if (a >= 189)
	{
		cout << 4;
	}
	else if (a >= 165)
	{
		cout << 3;
	}
	else if (a >= 135)
	{
		cout << 2;
	}
	else if(a >= 105)
	{
		cout << 1;
	}
	else
	{
		cout << 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int m,f,r;
	scanf("%d%d%d",&m,&f,&r);
	while(!(m==-1&&f==-1&&r==-1)){
		m = (m < 0)?-100:m;
		f = (f < 0)?-100:f;
		r = (r < 0)?-100:r;
		if(m+f >= 80){
			printf("A\n");
		}else if(m+f >= 65){
			printf("B\n");
		}else if(m+f >= 50){
			printf("C\n");
		}else if(m+f >= 30){
			if(r >= 50){
				printf("C\n");
			}else{
				printf("D\n");
			}
		}else{
			printf("F\n");
		}
		scanf("%d%d%d",&m,&f,&r);
	}
}



Measured memory_bytes: 2072
import bisect
from sys import stdin

def IL(): return list(map(int, stdin.readline().split()))
def SIL(): return sorted(list(map(int, stdin.readline().split())))

def main():
	n = int(input())
	A = SIL()
	B = IL()
	C = SIL()
	
	ans = 0
	for b in B:
	    smaller = bisect.bisect_left(A, b)
	    bigger = bisect.bisect_right(C, b)
	    ans += smaller*(n - bigger)

	print(ans)
	
	
if __name__ == "__main__": main()

Measured memory_bytes: 22720
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  
    int N, K;
    string S;
    cin >> N >> K >> S;
  
    if(S[K-1]=='A'){
       S[K-1]='a';
    }
     
    if(S[K-1]=='B'){
       S[K-1]='b';
    }
    
    if(S[K-1]=='C'){
       S[K-1]='c';
    }
    
    cout << S << endl;
}


Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().rstrip())
li = [0] + list(map(int,stdin.readline().rstrip().split()))
lin = [0]*(n+1)
point = 0
lis = []

for i in range(n,0,-1):
    su = sum(lin[i::i])%2
    if li[i] != su:
        lin[i] = 1
        point += 1
        lis.append(i)
    
print(point)
lis.sort()

for i in lis:
    print(i)

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

using ll = long long;
using namespace std;
constexpr ll inf = 1e9;
constexpr ll mod = 1e9+7;

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

    int H, W;
    cin>>H>>W;
    int dp[10][10];
    for (int i = 0; i <= 9; i++)
        for (int j = 0; j <= 9; j++) cin>>dp[i][j];
    
    for (int j = 0; j <= 9; j++) {
        for (int i = 0; i <= 9; i++) {
            for (int k = 0; k <= 9; k++) {
                if (dp[i][k] > dp[i][j] + dp[j][k]) dp[i][k] = dp[i][j] + dp[j][k];
            }
        }
    }

    int ans = 0;
    for (int h = 0; h < H; h++)
        for (int w = 0; w < W; w++) {
            int A;
            cin>>A;
            if (A != -1) ans += dp[A][1];
        }

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

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  string a,b,c;
  cin>>n>>a>>b>>c;
  int ans = 0;
  REP(i,n){
    if(a[i]==b[i] && b[i]==c[i]){
      //
    }else if(a[i]==b[i] || b[i]==c[i] || c[i]==a[i]){
      ans++;
    }else{
      ans += 2;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll X;
    cin >> X;
    ll money=100;
    ll day=0;
    while(money<X){
        double a;
      	a=(double)money*1.01;
        money=floor(a);
        day++;
    }
    cout << day;
    return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  int k;
  string s;
  cin>>k>>s;
  if(s.length()>k){
    for(int i=0;i<k;i++){
      cout<<s[i];
    }
    cout<<"..."<<endl;
  }else{
    cout<<s<<endl;
  }
  return 0;
}


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

int main(){
    int H, W, N, sr, sc;
    string S, T;
    cin >> H >> W >> N >> sr >> sc >> S >> T;
    
    int r, c;
    // 上に落とす
    r = sr, c = sc;
    for(int i=0; i<N; i++){
        if(S[i]=='U') r--;
        if(r==0){
            cout << "NO" << endl;
            return 0;
        }
        if(T[i]=='D' && r<H) r++;
    }

    // 下に落とす
    r = sr, c = sc;
    for(int i=0; i<N; i++){
        if(S[i]=='D') r++;
        if(r==H+1){
            cout << "NO" << endl;
            return 0;
        }
        if(T[i]=='U' && r>1) r--;
    }

    // 右に落とす
    r = sr, c = sc;
    for(int i=0; i<N; i++){
        if(S[i]=='R') c++;
        if(c==W+1){
            cout << "NO" << endl;
            return 0;
        }
        if(T[i]=='L' && c>1) c--;
    }

    // 左に落とす
    r = sr, c = sc;
    for(int i=0; i<N; i++){
        if(S[i]=='L') c--;
        if(c==0){
            cout << "NO" << endl;
            return 0;
        }
        if(T[i]=='R' && c<H) c++;
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 776
import java.util.*;
 
public class Main {
 
		public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
        int X = sc.nextInt();
          for (int i = X-(K-1); i <= X+(K-1); i++) {
            if(i>1000000) break;
            if(i<-1000000) continue;
           System.out.print(i + " "); 
          }
	}
}

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

const int maxn = 1e6 + 5, maxq = 10005;


int main()
{
	ll x, y, X, Y, equal = 0;
	cin >> X >> Y >> x >> y;
	cout << X * Y / 2 << (X*Y % 2 ? ".5 " : " ") << ((2 * x == X) && (2 * y == Y));


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int inf = 1e9 + 5;
const int nax = 1e6 + 5;

int ans;
vi w[nax];
int par[nax];

int k;

int dfs(int a) {
	int h = 0;
	for(int b : w[a]) {
		maxi(h, 1 + dfs(b));
	}
	if(h == k - 1 && par[a] != 1) {
		++ans;
		return -1;
	}
	return h;
}

int main() {
	int n;
	scanf("%d%d", &n, &k);
	RI(i, n) scanf("%d", &par[i]);
	if(par[1] != 1) ++ans;
	par[1] = 1;
	
	FOR(i, 2, n) w[par[i]].pb(i);
	
	dfs(1);
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 31872
/**
  @file d.cpp
  @title D - ModSum
  @url https://atcoder.jp/contests/abc139/tasks/abc139_d
**/

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

int main() {
  LL N;
  cin >> N;

  cout << (N - 1) * N / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int k = sc.nextInt();
    int r = sc.nextInt();
    int s = sc.nextInt();
    int p = sc.nextInt();
    long sum = 0;
    String way = "";
    String t = sc.next();
    int i=0;

    for (; i < k; i++) {
      char c = t.charAt(i);
      switch (c) {
      case 'r':
        sum += p;
        way += 'p';
        break;

      case 's':
        sum += r;
        way += 'r';
        break;

      case 'p':
        sum += s;
        way += 's';
        break;
      }
    }

    for (; i + k < n; i++) {
      char c = t.charAt(i);
      switch (c) {
      case 'r':
        if (way.charAt(i - k) == 'p') {
          way += getWay(t, i + k, 'p');
        } else {
          sum += p;
          way += 'p';
        }
        break;

      case 's':
        if (way.charAt(i - k) == 'r') {
          way += getWay(t, i + k, 'r');
        } else {
          sum += r;
          way += 'r';
        }
        break;

      case 'p':
        if (way.charAt(i - k) == 's') {
          way += getWay(t, i + k, 's');
        } else {
          sum += s;
          way += 's';
        }
        break;
      }
    }

    for (; i < n; i++) {
      char c = t.charAt(i);
      switch (c) {
      case 'r':
        if (way.charAt(i - k) != 'p') {
          sum += p;
        }
        break;

      case 's':
        if (way.charAt(i - k) != 'r') {
          sum += r;
        }
        break;

      case 'p':
        if (way.charAt(i - k) != 's') {
          sum += s;
        }
        break;
      }
    }

    System.out.println(sum);

  }

  public static char getWay(String t, int index, char ban) {
    char c = t.charAt(index);
    char ret = 0;
    switch (c) {
    case 'r':
      if (ban == 'r') {
        ret = 's';
      } else {
        ret = 'r';
      }
      break;
    case 's':
      if (ban == 's') {
        ret = 'p';
      } else {
        ret = 's';
      }
      break;
    case 'p':
      if (ban == 'p') {
        ret = 'r';
      } else {
        ret = 'p';
      }
      break;
    }

    return ret;
  }

}

Measured memory_bytes: 63652
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;

template<class T>
using vec2d = std::vector<std::vector<T>>;


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


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


const int MOD = (int)1e9 + 7;

void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  vec2d<int> g(n);
  FOR(i, n-1) {
    auto a = next<int>(in) - 1;
    auto b = next<int>(in) - 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vec<int> dpWhite(n, 0), dpBlack(n, 0);

  function<void(int, int)> dfs = [&] (int v, int p) {
    int64_t wh = 1, bl = 1;
    for (auto to : g[v]) {
      if (to == p) continue;
      dfs(to, v);
      bl *= dpWhite[to];
      bl %= MOD;
      wh *= (dpBlack[to] + dpWhite[to]) % MOD;
      wh %= MOD;
    }
    dpWhite[v] = (int)wh;
    dpBlack[v] = (int)bl;
  };
  dfs(0, -1);
  out << (dpWhite[0] + dpBlack[0]) % MOD << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int S, W;
    cin >> S >> W;
    if(S <= W) {
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
l,l_1,l_2 = [],[],[]
if len(A) % 2 == 0:  
  for i in range(len(A)):
    if i <= len(A)/2 - 2:
      l.append(-2)
    elif i == len(A)/2 -1:
      l.append(-1)
    elif i == len(A)/2:
      l.append(1)
    else:
      l.append(2)
  ans_d = [A[i]*l[i] for i in range(len(A))]
  print(sum(ans_d))
if len(A) % 2 == 1:
  for i in range(len(A)):
    if i <= int(len(A)/2) -2:
      l_1.append(2)
      l_2.append(-2)
    elif int(len(A)/2) -1 <= i <= int(len(A)/2):
      l_1.append(1)
      l_2.append(-1)
    else:
      l_1.append(-2)
      l_2.append(2)
  l_1.sort()
  l_2.sort()
  ans_d1 = [A[i]*l_1[i] for i in range(len(A))]
  ans_d2 = [A[i]*l_2[i] for i in range(len(A))]
  print(max(sum(ans_d1),sum(ans_d2)))

Measured memory_bytes: 17004
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  for(; b >= a; a++){
    if(to_string(a)[0] == to_string(a)[4] && to_string(a)[1] == to_string(a)[3]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;

int main(){
	IOS;
	int n;
	cin >> n;
	vector<int> num(n+1);
	for(int i=1;i<=n;i++) cin >> num[i];
	vector<int> cnt(n+1,0),ans;
	for(int i=n;i>0;i--){
		if(num[i]==0){
			if(cnt[i]%2==1){
				ans.push_back(i);
				for(int j=1;j*j<=i;j++){
					if(i%j==0){
						cnt[j]++;
						if(j*j!=i) cnt[i/j]++;
					}
				}
			}
		}
		else{
			if(cnt[i]%2==0){
				ans.push_back(i);
				for(int j=1;j*j<=i;j++){
					if(i%j==0){
						cnt[j]++;
						if(j*j!=i) cnt[i/j]++;
					}
				}
			}
		}
	}
	cout << ans.size() << '\n';
	for(int f:ans) cout << f << ' ';
	cout << '\n';
	return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b=0,c=0;
  cin >> a;
  vector<int> rank(a),pts(a);
  for (int i=0;i<a;i++){
    cin >> rank[i] >> pts[i];
    if (rank[i]>b){
      b=rank[i];
      c=pts[i];
    }
  }
  for(;c>0;c--){
      b++;
  }
  cout << b << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;

int main(){
	int n;
	int a[100];
	cin >> n;
	rep(i,n)
		cin >> a[i];
	sort(a,a+n,greater<int>());
	int alice=0,bob=0;
	rep(i,n){
		if (i%2) alice+=a[i];
		else bob+=a[i];
	}
	cout << bob-alice << endl;
}

Measured memory_bytes: 256
struct Read<R: std::io::BufRead> {
    stdin: R,
    v: Vec<String>,
    i: usize,
}
impl<R:std::io::BufRead> Read<R> {
    pub fn new(stdin: R) -> Self {
        Read{
            stdin: stdin,
            v: Vec::new(),
            i: 0,
        }
    }
    pub fn read_line(&mut self) {
        self.i = 0; self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        let mut ws = buf.split_whitespace();
        loop {
            let x = ws.next();
            if x.is_none() {break;}
            let x = x.unwrap().to_owned();
            self.v.push(x);
        }
    }
    pub fn read_t<T: std::str::FromStr>(&mut self) -> T {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.parse().unwrap_or_else(|_| panic!())
    }
    
    #[allow(dead_code)]
    pub fn read_i32(&mut self) -> i32 {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_usize(&mut self) -> usize {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_u64(&mut self) -> u64 {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_string(&mut self) -> String {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.to_owned()
    }
}
fn main() {
    use std::io;
    let stdin = io::stdin();
    let stdin = io::BufReader::new(stdin.lock());
    let read = Read::new(stdin);
    solve(read);
}

fn solve<R: std::io::BufRead>(mut r: Read<R>) {
    let n = r.read_usize();
    let k = r.read_i32();
    let mut x:Vec<i32> = Vec::new();
    for i in 0..n {
        x.push(r.read_i32());
    }

    let mut ans:i32 = 0;
    for i in 0..n {
        ans += if (0 - x[i]).abs() < (k - x[i]).abs() {
            (0 - x[i]).abs() * 2
        } else {
            (k - x[i]).abs() * 2
        }
    }
    println!("{}",ans);

}


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;

int main(void)
{
	int n;
	int x[100] = {}, y[100] = {};

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> y[i];
	}
	double a1 = 0, a2 = 0, a3 = 0, ae = 0;
	for (int i = 0; i < n; i++)
	{
		a1 += fabs(x[i] - y[i]);
		a2 += fabs(x[i] - y[i]) * fabs(x[i] - y[i]);
		a3 += fabs(x[i] - y[i]) * fabs(x[i] - y[i]) * fabs(x[i] - y[i]);
		ae = max(ae, fabs(x[i] - y[i]));
	}
	printf("%.5f\n", a1);
	printf("%.5f\n", sqrt(a2));
	printf("%.5f\n", pow(a3, 1.0 / 3.0));
	printf("%.5f\n", ae);
	return 0;
}


Measured memory_bytes: 3340
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
ans = 0 if a[0] < x else a[0] - x
a[0] = min(a[0], x)
for i in range(n-1):
    if a[i+1] + a[i] > x:
        ans += a[i+1] + a[i] - x
        a[i+1] -= a[i+1] + a[i] - x
print(ans)


Measured memory_bytes: 63984
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

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; }

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b/a,c) << endl;

}



Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

/** ワーシャル・フロイド法による全点対最短路探索

    経路を逐次最小化していく。

    知らないパスにはコスト大きめを設定しておくこと。
    O(|V|^3)

    @param[in] V  頂点数
    @param[in, out] distance[i][j]: 頂点i -> jのコスト
*/
template<typename T, typename M>
void warshall_floyd(T V, M& distance)
{
    for (T k = 0; k < V; ++k) {
        for (T i = 0; i < V; ++i) {
            for (T j = 0; j < V; ++j) {
                distance[i][j] = std::min(distance[i][j],
                                          distance[i][k] + distance[k][j]);
            }
        }
    }
}

int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    boost::multi_array<int, 2> mat(boost::extents[N][N]);
    std::fill(mat.data(), mat.data() + mat.num_elements(), 10000);

    struct Path {
        int a;
        int b;
        int c;
    };

    std::vector<Path> pathes;

    for (decltype(M) i = 0; i < M; ++i) {
        int a, b, c;
        std::cin >> a >> b >> c;
        a--;
        b--;
        mat[a][b] = mat[b][a] = c;

        pathes.push_back({a, b, c});
    }
    for (int i = 0; i < N; ++i) {
        mat[i][i] = 0;
    }

    warshall_floyd(N, mat);

    int count = 0;
    for (auto& path: pathes) {
        bool isRequired =false;
        for (int f = 0; f < N; ++f) {
            for (int t = 0; t < N; ++t) {
                auto d = mat[f][t];
                auto dd = mat[f][path.a] + path.c + mat[path.b][t];
                if (d == dd) {
                    isRequired = true;
                }
            }
        }
        if (!isRequired) {
            count++;
        }
    }


    std::cout << count << std::endl;

    return 0;
}


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

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >

const int N=1;

int main()
{
 ll a,b,k;
 cin>>a>>b>>k;
 ll tmp=min(a,k);
 k-=tmp;
 a-=tmp;
 if(k!=0){
    b=max(b-k,0LL);
 }
 cout<<a<<" "<<b;
 }


Measured memory_bytes: 3632
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 9)
    
    from collections import deque

    N = int(input())

    #隣接リストの作成
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        G[u].append(v)
        G[v].append(u)

    #直径を求める
    dist = [-1] * N
    dist[0] = 0
    que = deque()
    que.append(0) #スタート地点を入れる
    while len(que) != 0:
        tmp = que.popleft()
        for i in G[tmp]:
            if dist[i] == -1:
                dist[i] = dist[tmp] + 1
                que.append(i)
    
    tmp = 0
    start = -1
    for index, x in enumerate(dist):
        if tmp < x:
            start = index
            tmp = x
    
    dist = [-1] * N
    dist[start] = 0
    que = deque()
    que.append(start) #スタート地点を入れる
    while len(que) != 0:
        tmp = que.popleft()
        for i in G[tmp]:
            if dist[i] == -1:
                dist[i] = dist[tmp] + 1
                que.append(i)

    tmp = 0
    gpal = -1
    for index, x in enumerate(dist):
        if tmp < x:
            goal = index
            tmp = x

    dist1 = [-1] * N
    dist1[goal] = 0
    que = deque()
    que.append(goal) #スタート地点を入れる
    while len(que) != 0:
        tmp = que.popleft()
        for i in G[tmp]:
            if dist1[i] == -1:
                dist1[i] = dist1[tmp] + 1
                que.append(i)

    # print (dist)
    # print (dist1)
    for i in range(N):
        print (2 * (N - 1) - max(dist[i], dist1[i]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 30748
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

ll ans = 1;
vector<ll> v[2];
int cnt0;

ll getnxt(int &p, int &q) {
    ll v1 = p<v[0].size()? v[0][p]: -1;
    ll v2 = q<v[1].size()? v[1][q]: -1;
    if (v1<v2) {
        q++; return v2;
    } else {
        p++; return v1;
    }
}

ll power(int x, int n) {
    ll res = 1, now = x;
    for (;n;n>>=1,now=now*now%mod) if (n&1) res=res*now%mod;
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    int n, k; cin >> n >> k;
    for (int i=0;i<n;i++) {
        ll x; cin >> x;
        if (x>0) v[0].pb(x); else
        if (x<0) v[1].pb(-x); else cnt0++;
    }

    if (v[0].size()+v[1].size()<k) {
        cout << 0 << endl;
        return 0;
    }

    sort(v[0].begin(), v[0].end(), greater<ll>());
    sort(v[1].begin(), v[1].end(), greater<ll>());

    if (k==n-cnt0) {
        for (auto x: v[0]) ans = ans*x%mod;
        for (auto x: v[1]) ans = ans*(mod-x)%mod;
        if (cnt0&&v[1].size()%2) {
            cout << 0 << endl;
        } else {
            cout << ans << endl;
        }
        return 0;
    }

    if (k%2==1&&v[0].size()==0) {
        if (cnt0) {
            cout << 0 << endl;
            return 0;
        }
        reverse(v[1].begin(), v[1].end());
        for (int i=0;i<k;i++) ans = ans*(mod-v[1][i])%mod;
        cout << ans << endl;
        return 0;
    }

    if (v[1].size()==0) {
        for (int i=0;i<k;i++) ans = ans*v[0][i]%mod;
        cout << ans << endl;
        return 0;
    }

    if (v[0].size()==0) {
        for (int i=0;i<k;i++) ans = ans*(mod-v[1][i])%mod;
        cout << ans << endl;
        return 0;
    }

    int p = 0, q = 0;
    for (int i=0;i<k;i++) ans = ans*getnxt(p, q)%mod;

    if (q%2==1) {
        if (p<v[0].size()&&q<v[1].size()&&p>0&&q>0) {
            ll v1 = v[0][p]*v[0][p-1];
            ll v2 = v[1][q]*v[1][q-1];
            if (v1>=v2) {
                ans *= v[0][p]*power(v[1][q-1], mod-2)%mod;
                ans %= mod;
            } else {
                ans *= power(v[0][p-1], mod-2)*v[1][q]%mod;
                ans %= mod;
            }
        } else if (p==v[0].size()) {
            ans *= power(v[0][p-1], mod-2)*v[1][q]%mod;
            ans %= mod;
        } else {
            ans *= v[0][p]*power(v[1][q-1], mod-2)%mod;
            ans %= mod;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 5588
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>
#include <functional>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

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

vector<int> table[5000];

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;
    for (int i = 0; i < N-1; i++) {
        table[i].push_back(i+1);
        table[i+1].push_back(i);
    }
    table[X].push_back(Y);
    table[Y].push_back(X);

    vector<int> ans(N, 0);

    for (int start= 0; start < N; start++) {
        vector<int> dis(N, INF);
        dis[start] = 0;
        queue<int> que;
        que.push(start);
        while (!que.empty()) {
            int v = que.front(); que.pop();
            for (int next : table[v]) {
                if (dis[next] > dis[v] + 1) {
                    dis[next] = dis[v] + 1;
                    que.push(next);
                }
            }
        }
        for (int i = 0; i < N; i++) {
            ans[dis[i]]++;
        }
    }

    for (int k = 1; k <= N-1; k++) {
        cout << ans[k] / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#ifndef ONLINE_JUDGE
#define OJ \
    freopen("input.txt", "r", stdin); \
    //freopen("output.txt", "w", stdout);
#else
#define OJ ;
#endif
#define fo(int, i, l, r) for ( int i = l ; i < r ; ++ i)
#define srtV(a) sort(a.begin(),a.end())
int sz=0;
void dfs(int s,vector <int> adj[],vector<int> &is_visited)
{
    if(is_visited[s]) return;

    is_visited[s]=true;
    sz++;
    //cout<<"visited"<<s<<" while sz="<<sz<<"\n";
    for (auto u:adj[s])
    {
        //cout<<"going to u= "<<u<<"\n";
        dfs(u,adj,is_visited);
    }
    return;
}


void solve()
{
    int n,m;
    cin>>n>>m;
    vector <int> adj[n],is_visited(n,0);
    set <pair<int,int>> edges;
    int ans=1;

    for(int i=0;i<m;++i)
    {
        int u,v;
        
        int x,y;

        cin>>x>>y;
        u=min(x,y);
        v=max(x,y);
        u--;
        v--;
        if(edges.find({u,v})!=edges.end()){
            
        }
        else
        {
        //cout<< "added "<<u<<" "<<v<<endl;
        adj[u].push_back(v);
        adj[v].push_back(u);
        edges.insert({u,v});
        
        }
        //cout<<i<<endl;

    }
    //cout<<"done\n";
    for(int i=0;i<n;++i)
    {
        if(is_visited[i])
            continue;
        //cout<<"reset\n";
        sz=0;
        dfs(i,adj,is_visited);
        ans=max(ans,sz);
    }

    cout<<ans<<"\n";

    





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

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

int main(){
  string S;
  cin >>  S;
  char c = S.at(S.size()-1);
  if(c=='s'){
    S+="es";
  }else{
    S+='s';
  }
  printl(S);
}


Measured memory_bytes: 3624