akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//



int main(void) {

    ld r; cin >> r;
    ld ans = r * 6.28318530717958623200;
    out(ans);
    


    


    return 0;
}











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

main()
{
        int n; cin>>n;
        string s; cin>>s;
        long ans=0;
        vector<set<int>> v(3);
        for(int i=0;i<n;i++)
        {
                if(s[i]=='R')v[0].insert(i);
                if(s[i]=='G')v[1].insert(i);
                if(s[i]=='B')v[2].insert(i);
        }

        ans=v[0].size()*v[1].size()*v[2].size();

        for(int i=0;i<n;i++)
        {
                for(int t=0;t<3;t++)
                {
                        if(!v[t].count(i))continue;

                        for(int d=1;d<=i;d++)
                        {
                                if(t==0)
                                {
                                        if(v[1].count(i-d))
                                        {
                                                if(v[2].count(i+d))ans--;
                                        }else if(v[1].count(i+d))
                                        {
                                                if(v[2].count(i-d))ans--;
                                        }
                                }
                                if(t==1)
                                {
                                        if(v[0].count(i-d))
                                        {
                                                if(v[2].count(i+d))ans--;
                                        }else if(v[0].count(i+d))
                                        {
                                                if(v[2].count(i-d))ans--;
                                        }
                                }
                                if(t==2)
                                {
                                        if(v[1].count(i-d))
                                        {
                                                if(v[0].count(i+d))ans--;
                                        }else if(v[1].count(i+d))
                                        {
                                                if(v[0].count(i-d))ans--;
                                        }
                                }
                        }
                }
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 3776
#include <queue>
#include <iostream>
#include <string>

using namespace std;

int main(){
	int quantum, now=0, n, index; //index????????\??????????????????????????°
	int time[100000];
	string name[100000];
	queue<int> Q;

	cin >> n >> quantum;

	for(int i=0; i<n; i++){
		Q.push(i);
		cin >> name[i] >> time[i];
	}

	while(!Q.empty()){
		index = Q.front();
		if(time[index] > quantum){
			now += quantum;
			time[index] -= quantum;
			Q.pop();
			Q.push(index);
		}else{
			now += time[index];
			time[index] = now;
			cout << name[index] << " " << time[index] << endl;
			Q.pop();
		}
	}

	/*
	for(int i=0; i<n; i++){
		cout << name[i] << " " << time[i] << endl;
	}
	*/

	return 0;
}

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

const int mxN = 1e5+7;

int main() {
	string s, t;
	cin >> s >> t;
	int a = s.length(), b = t.length();
	vector<vector<int>> dp(a + 1, vector<int>(b + 1, 0));
	
	for(int i = 1; i <= a; i++) {
		for(int j = 1; j <= b; j++) {
			if(s[i-1] == t[j-1]) {
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	
	int len = dp[a][b];
	string ans(len, ' ');
	int i = a, j = b;
	while(i > 0 && j > 0) {
		if(s[i-1] == t[j-1]) {
			ans[len - 1] = s[i-1];
			i--; j--; len--;
		}
		else if(dp[i-1][j] > dp[i][j-1]) {
			i--;
		}
		else {
			j--;
		}
	}
	cout << ans << "\n";
}


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

int main(){
    int x,y,num[2][3000],tmp,count=0;
    while(true){
        cin>>x>>y;
        if(x==0&&y==0)break;
        else{
            if(x>y){
                num[0][count]=y;
                num[1][count]=x;
            }
            else{
                num[0][count]=x;
                num[1][count]=y;
            }
        }
        count++;
    }

    for(int i=0;i<count;i++){
        cout<<num[0][i]<<" "<<num[1][i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3092
n = int(input())

a = list(map(int,input().strip().split()))

b = [0 for i in range(n+1)]
for i in range(len(a)):
	b[i+2] += 1
	b[a[i]] += 1
b[1] += 1
for i in range(1,n+1):
	print(b[i]-1)

Measured memory_bytes: 32316
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    # See:
    # https://www.youtube.com/watch?v=ENSOy8u9K9I&feature=youtu.be
    path = list()
    order = [-1 for _ in range(n + 1)]
    place = 1

    while order[place] == -1:
        order[place] = len(path)
        path.append(place)
        place = a[place - 1]

    cycle = len(path) - order[place]
    before_cycle_count = order[place]

    if (k < before_cycle_count):
        print(path[k])
    else:
        k -= before_cycle_count
        k %= cycle
        print(path[before_cycle_count + k])


if __name__ == '__main__':
    main()


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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if (((x - r) >= 0 && (x + r) <= W ) && ((y - r) >= 0 && (y + r) <= H)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3112
#include<stdio.h>
#define M 10000
#define N -1

struct Node{int p,l,r;};
struct Node T[M];
int n;

void preParse(int u){
if(u==N)return;
printf(" %d",u);
preParse(T[u].l);
preParse(T[u].r);
}

void inParse(int u){
	if(u==N)return;
	inParse(T[u].l);
	printf(" %d",u);
	inParse(T[u].r);
}

void postParse(int u){
	if(u==N)return;
	postParse(T[u].l);
	postParse(T[u].r);
	printf(" %d",u);
}
int main(){
	int i,v,l,r,root;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	T[i].p=N;
	}
	
	for(i=0;i<n;i++){
		scanf("%d %d %d",&v,&l,&r);
		T[v].l=l;
		T[v].r=r;
		if(l!=N)T[l].p=v;
		if(r!=N)T[r].p=v;
	}
	for(i=0;i<n;i++)if(T[i].p==N) root = i;
	
	printf("Preorder\n");
	preParse(root);
	printf("\n");
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	printf("Postorder\n");
	postParse(root);
	printf("\n");
	
	return 0;
}
	


Measured memory_bytes: 2080
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
long long int lis[500004];
long long int query[500004];
long long int ans[500004];
long long int BIT[500004];
long long int last[500004];
int main(){
    long long int N,Q;
    cin>>N>>Q;
    for(int i=1;i<=N;i++){
        int a;
        cin>>a;
        lis[i]=a;
        //syutu[a].push_back(i);
    }
    for(int i=0;i<Q;i++){
        long long int a,b;
        cin>>a>>b;
        query[i]=b*500001*500001+a*500001+i;
    }





    sort(query,query+Q);
    query[Q]=500001ll*500012ll*500001ll;
    long long int owariQ=0;
    for(int i=1;i<=N;i++){
        int hiku;
        hiku=last[lis[i]];
        last[lis[i]]=i;
        long long int kari=i;
        while(kari<=500004){
            BIT[kari]+=1;
            kari += kari & -kari;
        }

        kari=hiku;
        if(kari!=0){
            while(kari<=500004){
                BIT[kari]-=1;
                kari += kari & -kari;
            }
        }
        //printf("hoge");
        //printf("[%lld]\n",query[owariQ]/500001/500001);
        while(query[owariQ]/500001/500001==i){

            //cout<<"hoge";

            long long int r=query[owariQ]/500001/500001;
            long long int l=(query[owariQ]/500001)%500001;
            long long int papapa=0;
            while(r>0){
                papapa+=BIT[r];
                r -= r & -r;
            }
            l--;
            while(l>0){
                papapa-=BIT[l];
                l -= l & -l;
            }
            //cout<<papapa<<endl;
            ans[query[owariQ]%500001]=papapa;
            owariQ++;
        }



    }
    /*
    vector<long long int>kazukukan;
    for(int i=1;i<=500000;i++){
        long long int bef;
        for(int j=0;j<syutu[i].size();j++){
            if(j=0){
                bef=syutu[i][j];
            }
            else{
                kazukukan.push_back(i*500001+syutu[i][j]);
                bef=syutu[i][j];
            }
        }
    }
    */
    for(int i=0;i<Q;i++)cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 23336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

int N, K;

void solve()
{
	ll ans = 0;
	const ll L = N/K;
	ans = L*L*L;
	if((K%2)==0 && N>=K/2){ 
		ll t = (N-K/2)/K+1;
		ans += t*t*t;
	}

	cout << ans << endl;
}

int main()
{
	cin >> N >> K;
	solve();
}

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

int main() {
    int n;
    scanf("%d",&n);
    long long res = 0;
    for(int i=1;i<=n;i++) {
        if(i%3==0 || i%5==0) continue;
        res += i;
    }
    printf("%lld\n", res);
}


Measured memory_bytes: 3824
n,c=map(int,input().split())
xv=[list(map(int,input().split())) for i in range(n)]
fa=[0]*(n+1)
ga=[0]*(n+1)
fb=[0]*(n+1)
gb=[0]*(n+1)
ans1=0
ans2=0
fa[1]=xv[0][1]-xv[0][0]
ga[1]=max(fa[1],fa[0])
fb[1]=xv[-1][1]-(c-xv[-1][0])
gb[1]=max(fb[0],fb[1])
for i in range(1,n):
  fa[i+1]=fa[i]+xv[i][1]-(xv[i][0]-xv[i-1][0])
  ga[i+1]=max(ga[i],fa[i+1])
  fb[i+1]=fb[i]+xv[-i-1][1]-(xv[-i][0]-xv[-i-1][0])
  gb[i+1]=max(gb[i],fb[i+1])
ans1=ga[n]
ans2=gb[n]
for i in range(0,n):
  ans1=max(ans1,ga[i]+fb[n-i]-(c-xv[-n+i][0]))
  ans2=max(ans2,gb[i]+fa[n-i]-xv[n-i-1][0])
print(max(ans1,ans2))

Measured memory_bytes: 39436
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

struct mint {
  LL x; 
  mint(LL x=0):x((x%mod+mod)%mod){}
  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;
  }
};

string K;
int D;

LL ans = 0;

void solve(){
	int N = (int)K.size();
	//上からi桁目まで見るとき、(0<=i<=N-1)
	//と決めたとき各桁の和をDで割ったあまりがjになる数
	//がいくつあるかをdp[i][j][t]とおく
	//だたしそこまでの桁がKと一致していればt=1
	//していなければt=0
	//といった風に分ける
	const int MATCH = 1;
	const int NOT_MATCH = 0;
	vector<vector<vector<mint>>> dp(N,vector<vector<mint>>(D,vector<mint>(2,0)));

	for(int i=0;i<K[0]-'0';i++){
		dp[0][i%D][NOT_MATCH] += mint(1);
	}
	dp[0][(K[0]-'0')%D][MATCH] += mint(1);

	//配るDP
	for(int i=0;i<=N-2;i++){
		int next_digit = K[i+1]-'0';//今見てる桁よりひとつ進んだとこの数
		//NOT_MATCHから配る
		for(int j=0;j<D;j++){
			for(int d=0;d<10;d++){
				dp[i+1][(j+d)%D][NOT_MATCH] += dp[i][j][NOT_MATCH];
			}
		}
		//MATCHから配る
		for(int d=0;d<next_digit;d++){
			for(int j=0;j<D;j++){
				dp[i+1][(j+d)%D][NOT_MATCH] += dp[i][j][MATCH];
			}
		}
		for(int j=0;j<D;j++){
			dp[i+1][(j+next_digit)%D][MATCH] += dp[i][j][MATCH];
		}
	}

	// cout << "NOT_MATCH" << endl;
	// for(int i=0;i<N;i++){
	// 	for(int j=0;j<D;j++){
	// 		cout << dp[i][j][NOT_MATCH].x << " ";
	// 	}
	// 	cout << endl;
	// }
	// cout << endl;
	// cout << "MATCH" << endl;
	// for(int i=0;i<N;i++){
	// 	for(int j=0;j<D;j++){
	// 		cout << dp[i][j][MATCH].x << " ";
	// 	}
	// 	cout << endl;
	// }
	// cout << endl;

	ans = (dp[N-1][0][MATCH] + dp[N-1][0][NOT_MATCH] - mint(1)).x;
}
 
int main(){
    cin >> K;
    cin >> D;
 
    solve();

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

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	if(a%3==0||b%3==0||(a+b)%3==0)cout<<"Possible"s;
	else cout<<"Impossible"s;
	cout<<"\n"s;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <stdlib.h>
using namespace  std;

int main() {
    int a[100];
    int i = 0;
    string str,str1;
    getline(cin, str1);
    int l = str1.length();
    int j = 0;
    while (1) {
        str = "e";
        while (1) {
            if (j >= str1.length())break;
            if (str1[j] == ' ') {
                j++;
                break;
            }
            if (str == "e")str[0] = str1[j];
            else str += str1[j];
            j++;
        }
        if (str == "e")break;
        if (str == "+") {
            a[i - 2] += a[i - 1];
            i --;
        }
        else if (str == "-") {
            a[i - 2] -= a[i - 1];
            i --;
        }
        else if (str == "*") {
            a[i - 2] *= a[i - 1];
            i --;
        }
        else {
            char* c;
            c = new char[str.length()+1];
            for (int k = 0; k < str.length(); k++) {
                c[k] = str[k];
            }
            c[str.length()] = NULL;
            a[i] = atoi(c);
            i++;
            delete[] c;
        }
        if (j >= str1.length())break;
    }
    cout << a[0] << endl;
    return 0;
}


Measured memory_bytes: 3228
x = int(input())

if x == 1:
    print(1)
else:
    answer = 0
    for i in range(2, x):
        if x < i ** 2:
            break
        
        j = 2
        while True:
            if i ** j > x:
                break
            if i ** j > answer:
                answer = i ** j
            j += 1
    print(answer)

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

int main() {
  
  int N;
  cin >> N;
  
  string S;
  cin >> S;
  
  int ans = 0;
  
  for (int i = 1; i <= N - 1; i++) {
    
    vector<int> vec(N - i + 1);
    
    for (int j = 0; j < N - i; j++) {
      if (S[j] == S[i + j]) vec[j + 1] = vec[j] + 1;
    }
    
    priority_queue<int> pq;
    
    for (int j = 0; j < N - i + 1; j++) {
      pq.push(vec[j]);
    }
    
    if (ans < min(i, pq.top())) ans = min(i, pq.top());
    
  }
  
  cout << ans << endl;
  
}

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

class ufds {

public:
	// this function initializes the UFDS
	ufds(int n) {
		par.resize(n);
		sz.resize(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}

	//  this function returns the representative of the group that item x is in
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			// path compression: link x -> representative of the group directly
			// recursively follow the arrows up to the representative
			par[x] = find(par[x]);
			return par[x];
		}
	}

	// this function combines the groups items x and y are in
	void merge(int x, int y) {
		// find the representatives of the two groups
		x = find(x);
		y = find(y);
		if (x == y) {
			return;
		}
		par[x] = y; // x -> y
		sz[y] += sz[x]; // number of items in group y has increased by the number of items in group x
		return;
	}

	// this function returns the size of the group item x is in
	int get_size(int x) {
		return sz[find(x)];
	}

	// this function returns true if items x and y are in the same set
	bool same_set(int x, int y) {
		return find(x) == find(y);
	}

private:
	vector<int> par;
	// par[i] is the 'parent' of item i
	// i -> par[i]
	vector<int> sz;
	// sz[i] stores the number of items in group i
};

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

	int n, m;
	cin >> n >> m;
	ufds data = ufds(2*n);

	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		data.merge(i, n+p-1);
	}
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		data.merge(x-1, y-1);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += data.same_set(i, n + i);
	}
	cout << ans;
}

Measured memory_bytes: 4784
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int cnt=0;
  while(cin>>str){
    int cc=0;
    for(int i=0;i<str.size();i++){
      string str2="";
      while(str[i+cc]>='0'&&str[i+cc]<='9'){
	cc++;
	//	cout<<"!"<<endl;
      }
      //cout<<str2<<endl;
      str2=str.substr(i,cc);
      for(int k=str2.size()-1;k>=0;k--){
	int hiseki=1;
	for(int j=0;j<str2.size()-k-1;j++)
	  hiseki*=10;
	cnt+=(str2[k]-'0')*hiseki;
      }
      i+=cc;
      cc=0;
    }
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3144
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
	int n;
	ll x;
	cin >> n >> x;
	ll a[n + 5];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	ll ans = 0;
	ll def = 0;
	for (int i = 1; i < n; i++){
		if(a[i - 1] + a[i] > x){
			def += a[i - 1] + a[i] - x;
			ans += def;
			if(a[i] -def >= 0) {
				a[i] -= def;
			} else {
				def -= a[i];
				a[i] = 0;
				a[i - 1] -= def;
			}
			def = 0;
		}
	}
	
	cout << ans << endl;

	
	
	
	
	return 0;
}

Measured memory_bytes: 1152
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

z = sorted(p)[-X:] + sorted(q)[-Y:] + r
print(sum(sorted(z)[-(X+Y):]))


Measured memory_bytes: 113900
a, b = map(str, input().split())
#print(a)
#print(b)

a2 = round(int(a),len(a))
b2 = b.replace('.','')
b3 = round(int(b2),len(b2))
#print(a2)
#print(b2)
c = a2 * b3
c2 = str(c)
#print(c2)
if len(c2)<3:
    print(0)
else:
    print(c2[0:-2])


Measured memory_bytes: 9208
def main():
    H, W = map(int, input().split())
    G = [input() for _ in range(H)]

    cond_r = [True] * H
    cond_c = [True] * W
    for r in range(H):
        if all(x == '.' for x in G[r]):
            cond_r[r] = False
    for c in range(W):
        if all(x == '.' for r in range(H) for x in G[r][c]):
            cond_c[c] = False
    for r, row in enumerate(G):
        if not cond_r[r]: continue
        for c, cell in enumerate(row):
            if not cond_c[c]: continue
            print(cell, end='')
        print()


if __name__ == '__main__':
    main()


Measured memory_bytes: 4468
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	S = input()
	S = S[:-1]

	tmp = len(S)
	tmp = tmp // 2

	ans = 0
	for i in range(tmp):
		#print("{} {}".format(S[i], S[-1 * (i+1)]))
		if S[i] == S[-1 * (i+1)]:
			pass
		else:
			ans += 1

	print(ans)


if __name__ == "__main__":
	main()


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define M 10007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N, dp[1024][8];
char charge[1024];

int check(int n, int p){
  //  printf("%c %d\n", charge[n], p);
  switch(charge[n]){
  case 'J':
    if((p>>2)%2) return 1;
    break;
  case 'O':
    if((p>>1)%2) return 1;
    break;
  case 'I':
    if(p%2) return 1;
    break;
  default:
    break;
  }
  return 0;
}

int key(int prev, int now){
  for(int i = 2; i >= 0; i--){
    if((prev>>i)%2 == 1 && (now>>i)%2 == 1) return 1;
  }
  return 0;
}

int dfs(int n, int prev){
  /*  if(n == N-1){
    int res = 0;
    REP(i, 1, 8){
      if(check(n, i) && key(prev, i)) res++;
    }
    return res;
    }*/
  if(n == N) return 1;
  if(dp[n][prev] >= 0) return dp[n][prev];
  int res = 0;
  REP(i, 1, 8){
    if(check(n, i) && key(prev, i)) res += dfs(n+1, i);
    res %= M;
  }
  return dp[n][prev] = res;
}

int main(){
  scanf("%d%s", &N, charge);
  memset(dp, -1, sizeof(dp));
  int res = 0;
  REP(i, 4, 8){
    if(check(0, i)){
      //      printf("%d\n", i);
      res += dfs(1, i);
      res %= M;
    }
  }

  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 1304
#include<stdio.h>
#include<string.h>
int main(){
  int a=0,b=0,n,i,j,sa,sb,flag;
  char as[101],bs[101];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",as,bs);
    sa=strlen(as);
    sb=strlen(bs);
    if(sa<sb)flag=sb;
    else flag=sa;
    for(j=0;j<flag;j++){
      if(as[j]>bs[j]){
	a+=3;
	break;
      }
      else if(as[j]<bs[j]){
	b+=3;
	break;
      }
      else if(as[j]==bs[j] && j==flag-1){
	a++;
	b++;
	break;
      }
    }
  }
  printf("%d %d\n",a,b);
  return(0);
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N; cin >> N; string S[N];
  rep(i, N){
    cin >> S[i];
    sort(S[i].begin(), S[i].end());
  }
  sort(S, S+N);
  int cnt = 1;
  vector<int> tmp;
  rep(i, N-1){
    if(S[i] == S[i+1])  cnt++; 
    else {tmp.push_back(cnt); cnt = 1;}
  }
  tmp.push_back(cnt);
  ll ans = 0;
  rep(i, tmp.size()){
    ans += (ll) tmp[i]*(tmp[i]-1)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define vs vector<string>
#define ss second
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define tr1(x)                cout<<#x<<": "<<x<<endl
#define tr2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define tr4(x, y, z, d)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#d<<": "<<d<<endl
#define tr3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define db1(x) cerr << #x << ": " << x <<'\n'
#define db2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define db3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<int, int> &a,const pair<int, int> &b)
{
    return (a.ss<b.ss);
}
int min(int a, int b){
    if(a<b){
        return a;
    }
    else{
        return b;
    }
}
int max(int a, int b){
    if(a>b){
        return a;
    }
    else{
        return b;
    }
}
int max(int a, int b, int c){
    return(max( max(a,b), c ));
}
int min(int a, int b, int c){
    return (min ( min(a,b) , c));
}
int poww(int a, int b)
{
    int res = 1;
    for(int i = 1; i<=b; ++i)
        res *= a;
 
    return res;
}
int findlcm(int arr[], int n)
{
    // Initialize result
    int ans = arr[0];
 
    // ans contains LCM of arr[0], ..arr[i]
    // after i'th iteration,
    for (int i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (__gcd(arr[i], ans)));
 
    return ans;
}
bool prime[100001];
void SieveOfEratosthenes(int n)
{
    memset(prime, true, sizeof(prime));
 
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
  }
}
bool double_is_int(double trouble) {
   double absolute = abs( trouble );
   return absolute == floor(absolute);
}
//Define mx for maximum range and MOD for large numbers
#define mx 500005
#define mod 1000000007
 
// Declare all the variables and global functions here -
int t;
int32_t main(){
    IOS;
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n){
        cin >> a[i];

    }
    int cnt = 0;
    rep(i, 1, n-1){
        if(a[i]!=min(a[i], a[i-1], a[i+1]) && a[i]!=max(a[i], a[i-1], a[i+1])){
            cnt++;
        }
    }

    cout << cnt << endl;
}  

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

using namespace std;

int main() {
  string str[4] {"maerd","remaerd","esare","resare"};
  
  string S;
  cin>>S;
  
  reverse(S.begin(), S.end());
  
  bool a = true;
  for (int i=0;i<S.size();) {
    bool b=false;
    for (int j=0;j<4;j++) {
      string d = str[j];
      if (S.substr(i,d.size())==d) {
        b=true;
        i+=d.size();
      }
    }
    if (!b) {
      a = false;
      break;
    }
  }
  
  if (a) {
    cout<<"YES"<<endl;
  }
  else {
    cout<<"NO"<<endl;
  }
  
}



Measured memory_bytes: 512
module agc61
 implicit none
contains
 subroutine agc61a(a,x,y)
  integer(8),intent(in)::x,y
  integer(8),intent(inout)::a(:)
  a(x)=y
 end subroutine agc61a
 function agc61b(a,x,y)result(ans)
  integer(8),intent(in)::a(:),x,y
  integer(8)::ans
  ans=maxval(a(x:y))
 end function agc61b
 function agc61c(a,x,y,N)result(ans)
  integer(8),intent(in)::a(:),x,y,N
  integer(8)::ans,ia,c
  c=0
  do ia=x,N
   if(a(ia)>=y)then
    c=ia
    exit
   end if
  end do
  if(c==0)then
   ans=N+1
  else
   ans=c
  end if
 end function agc61c
end module agc61

program abc61
 use agc61
 implicit none
 integer(8)::N,Q,p,x,y,ia,ib
 integer(8),allocatable::a(:)
 read(*,*)N,Q
 allocate(a(N))
 read(*,*)(a(ia),ia=1,N)
 do ib=1,Q
  read(*,*)p,x,y
  if(p==1)then
   call agc61a(a,x,y)
  else if(p==2)then
   print'(i0)',agc61b(a,x,y)
  else
   print'(i0)',agc61c(a,x,y,N)
  end if
 end do
 deallocate(a)
end program abc61

Measured memory_bytes: 4572
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<numeric>
#include<map>
#include<limits>
using namespace std;

#define R(i,s,n) for(int i=s;i<n;i++)
#define D(i,n,s) for(int i=n-1;i>=s;i--)
typedef pair<int,int> P;
typedef unsigned long long ull;
typedef long long ll;

const int MAX_N = 17;

vector< vector<string> > str;
int n,num,opr;  //、計算値格納用
P ope;

void solve();

int main() {

  while(cin>>n && n) {
    str.resize(n);
    string tmp = "";
    ope = P(0,0);
    R(i,0,n) {
      cin>>tmp;
      str[i].resize(tmp.size());
      R(j,0,tmp.size()) str[i][j] = tmp[j];
      if(tmp.size() > ope.second && (tmp[tmp.size()-1] == '+' || tmp[tmp.size()-1] == '*')) ope = P(i,tmp.size());
    }
    /*
    str.erase(str.begin()+1,str.begin()+2);
    R(i,0,str.size()) {
      R(j,0,str[i].size()) cout<<str[i][j];
      cout<<endl;
    }
*/
    solve();
  }
  return 0;
}

void solve() {
  while(str.size()>1) {
    //cout<<str.size()<<endl;
    num = atoi(str[ope.first+1][str[ope.first+1].size()-1].c_str());
  //  cout << ope.first << " " << str[ope.first+1].size() << endl;
    opr = str.size();
    R(i,ope.first+2,str.size()) {
      if(str[i].size() <= str[ope.first].size()) { opr = i; break; }
      if(str[ope.first][str[ope.first].size()-1][0] == '+') num += atoi(str[i][str[i].size()-1].c_str());
      else num *= atoi(str[i][str[i].size()-1].c_str());
    }

    str[ope.first][str[ope.first].size()-1] = to_string(num);
    str.erase(str.begin()+ope.first+1,str.begin()+opr);

    ope = P(0,0);
    R(i,0,str.size()) {
      if(str[i].size() > ope.second && (str[i][str[i].size()-1][0] == '+' || str[i][str[i].size()-1][0] == '*')) ope = P(i,str[i].size());
    }
  }

  cout<<str[0][0]<<endl;
  /*
  R(i,0,n) {
    R(j,0,str[i].size()) cout<<str[i][j];
    cout<<endl;
  }
  cout<<"ope = "<<ope.first<<endl;
  */
}



Measured memory_bytes: 3244
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define MOD 1000000007

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

    int n,wt;
    cin>>n>>wt;

    ll w[n+1],v[n+1];
    ll dp[n+1][wt+1];

    for(int i= 1; i<=n; i++){
        cin>>w[i]>>v[i];
    }

    for(int i = 0; i<=n; i++){
        for(int j = 0; j<=wt; j++){
            dp[i][j] = 0;
        }
    }
    for(int i = 1; i<=n; i++){
        for(int j = 1; j<=wt; j++){
            if(j>=w[i]){
                dp[i][j] = max(dp[i-1][j],v[i]+dp[i-1][j - w[i]]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout<<dp[n][wt];
}

Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
int N,K,x,ans=0;
int main(){
  cin >> N >> K;
  for(int i=0;i<N;i++){
    cin >> x;
    ans+=min(x,K-x)*2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque

N,M=list(map(int,input().split()))
G = [[] for i in range(N)]
for i in range(M):
    A,B=list(map(int,input().split()))
    G[A-1].append(B-1)
    G[B-1].append(A-1)

done = [0]*N #その人を見たかどうか(通過したかどうか)
out = 0 #最大値を更新していく
for i in range(0,N): #スタート地点の候補
    if done[i]==1:
        continue
    s = i
    dist = 0
    que = deque([s])
    dist += 1
    done[s] = 1
    while que:
        v = que.popleft()
        for w in G[v]:
            if done[w]==1:
                continue
            dist += 1
            done[w] = 1
            que.append(w)
    out = max(dist,out)
print(out)

Measured memory_bytes: 111936
#二分ヒープ
class BinaryHeap
  def initialize
    @heap = Array.new
    @size = 0
  end
  def push(x)
    @size += 1
    upfrom(@size - 1, x)
  end
  def shift
    wk = @heap[0]
    @size -= 1
    downfrom(0, @heap[@size])
    wk
  end
  def change(o, n)
    i = @heap.find_index{|h| h == o}
    return if i.nil?
    if i == 0 || (o <= n) then
      downfrom(i, n)
    else
      upfrom(i, n)
    end
  end
  def delete(x)
    i = @heap.find_index{|h| h == x}
    return if i.nil?
    @size -= 1
    downfrom(i, @heap[@size])
  end
  def first
    @size == 0 ? nil : @heap[0]
  end
  def second
    if @size < 2 then
      nil
    elsif @size == 2 then
      @heap[1]
    else
      @heap[1] <= @heap[2] ? @heap[1] : @heap[2]
    end
  end
  def empty?
    @size == 0
  end

  private

  def upfrom(i, x)
    me = i
    while 0 < me do
      parent = (me - 1) >> 1
      break if @heap[parent] <= x
        @heap[me] = @heap[parent]
        me = parent
    end
    @heap[me] = x
  end
  def downfrom(i, x)
    me = i
    while me < @size do
      child = (me << 1) + 1
      break if child >= @size
      if (child + 1) < @size && (@heap[child + 1] <= @heap[child]) then
        child += 1
      end
      break if x <= @heap[child]
      @heap[me] = @heap[child]
      me = child
    end
    @heap[me] = x
  end
end

N = gets.to_i
S = gets.chomp.split(" ").map(&:to_i)

S.sort!.reverse!
max_size = 2 ** N
C = Hash.new{|h, k| h[k] = BinaryHeap.new}
C[S[0]].push(0)
CI = BinaryHeap.new
CI.push(0)
P = Array.new(2 ** (N + 1) - 1)
P[0] = S[0]
ans = true
(1...S.size).each{|i|
  s = S[i]
  j = CI.first
  j = CI.second if P[j] == s
  (ans = false; break) if j.nil?
  k = P[j]
  jj = C[k].shift
  wk = 2 * j + 2
  if wk < max_size then
    C[k].push(wk - 1)
    CI.change(j, C[k].first)
    P[wk - 1] = k
    C[s].push(wk)
    CI.push(wk) if C[s].second.nil?
    P[wk] = s
  else
    (C.delete(k); CI.delete(j)) if C[k].empty?
  end
}

puts ans ? 'Yes' : 'No'


Measured memory_bytes: 46612
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
S1 = [0] * (N + 1)
S2 = [0] * (N + 1)
for i in range(N):
        S1[i + 1] = S1[i] + A1[i]
for i in range(N):
        S2[i + 1] = S2[i] + A2[i]
ans = 0 
for i in range(1, N + 1): 
        ans = max(ans, S1[i] - S1[0] + S2[N] - S2[i - 1]) 
print(ans)

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

int main() {
	int n,a[100],cnt;
	while (cin >> n, n) {
		cnt = 0;
		for (int i = 0; i < n; i++) cin >> a[i];
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (a[i] > a[j]) cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans
    
    ### intチェック
    def is_integer(self, n):
        try:
            float(n)
        except ValueError:
            return False
        else:
            return float(n).is_integer()

    ### 幾何学問題用
    def dist(self, A, B):
        d = 0
        for i in range(len(A)):
            d += (A[i]-B[i])**2            
        d = d**(1/2)
        return d

    ### 絶対値
    def abs(self, n):
        if n >= 0:
            return n
        else:
            return -n

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

while True:
    N = int(input())
    if N==0:
        break
    A = [int(x) for x in input().split()]

    ave = sum(A)/N

    count = 0

    for i in A:
        if i <= ave:
            count += 1
    
    print(count)



Measured memory_bytes: 6736
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

struct KMP {
  vector<ll> pattern;
  int plen;
  vector<int> table;

  KMP(const vector<ll>& s)
      : pattern(s), plen((int)pattern.size()), table(plen + 1) {
    table[0] = -1;
    int j = -1;
    for (int i = 0; i < plen; ++i) {
      while (j >= 0 && pattern[i] != pattern[j]) {
        j = table[j];
      }
      table[i + 1] = ++j;
    }
  }

  void search(const vector<ll>& text, vector<int>& res) {
    int head = 0, j = 0, tlen = (int)text.size();
    while (head + j < tlen) {
      if (pattern[j] == text[head + j]) {
        if (++j == plen) {
          res.push_back(head);
          head = head + j - table[j];
          j = table[j];
        }
      } else {
        head = head + j - table[j];
        if (j)
          j = table[j];
      }
    }
  }
};

signed main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) {
    cin >> a[i];
  }
  vector<ll> b(N);
  rep(i, N) {
    cin >> b[i];
  }

  vector<ll> aa(N), bb(N);
  rep(i, N) {
    int j = (i + 1) % N;
    aa[i] = (a[i] ^ a[j]);
    bb[i] = (b[i] ^ b[j]);
  }

  vector<ll> aa2(2 * N);
  rep(i, N) {
    aa2[i] = aa[i];
    aa2[i + N] = aa[i];
  }

  KMP kmp(bb);  // 検索文字列
  vector<int> ans;
  kmp.search(aa2, ans);
  rep(i, len(ans)) {
    if (ans[i] >= N)
      break;
    int k = ans[i];
    ll x = (a[k] ^ b[0]);
    cout << k << ' ' << x << "\n";
  }
}

Measured memory_bytes: 16116
import sys
from collections import defaultdict
inputs = sys.stdin.readlines()

n = int(inputs[0])
S = inputs[1:]

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i].rstrip())))
    d[s] += 1

ans = 0
for v in d.values():
    ans += v*(v+1)//2
print(ans)

Measured memory_bytes: 26080
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll n, m;
vector<ll> G[N], R[N];
ll id[N], ans[N], root;
ll M[N];
vector<ll> T;
void DFS(ll v) {
	M[v] = 1;
	for (auto u : G[v]) 
		if (!M[u])
			DFS(u);
	T.pb(v);
}
int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n - 1 + m; i ++) {
		ll v, u;
		cin >> v >> u;
		G[v].pb(u);
		R[u].pb(v);
	}
	for (int i = 1; i <= n; i ++) {
		if (R[i].size()) continue;
		DFS(i);
	}
	reverse(all(T));
	root = T[0];
	for (int i = 0; i < n; i ++) {
		id[T[i]] = i;
	}
	for (int i = 1; i <= n; i ++) {
		ll pos = -1, v = 0;
		for (auto u : R[i]) {
			if (id[u] > pos) {
				pos = id[u];
				v = u;
			}
		}
		ans[i] = v;
	}
	for (int i = 1; i <= n; i ++) {
		cout << ans[i] <<  '\n';
	}
}

Measured memory_bytes: 25976
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF (9223372036854775807LL)
#define EPS (1e-10)
#define endl ('\n')
//#define MOD 1000000007LL
#define MOD 998244353LL
//#define MOD 18446744069414584321ULL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

int main(){
    vec a(5);
    rep(i,5)cin>>a[i];
    cout<<min_element(all(a))-a.begin()+1<<endl;
}

Measured memory_bytes: 3608
# coding: utf-8
# Your code here!
c=[]
for i in range(3):
    c.append(list(map(int,input().split())))
D1=[]
stp = 0
for i in range(3):
    for j in range(3):
        for k in range(j+1,3):
            D1.append(c[i][j]-c[i][k])

for i in range(6):
    if D1[i] != D1[i+3]:
        stp += 1

D2=[]
for i in range(3):
    for j in range(3):
        for k in range(j+1,3):
            D2.append(c[j][i]-c[k][i])

for i in range(6):
    if D2[i] != D2[i+3]:
        stp += 1
if stp == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Integer> sg = new ArrayList<Integer>();
		
		int[] heights = null;
		String str = "";
		try {
			str = in.readLine();
			heights = new int[str.length() + 1];
			heights[0] = 0;
			
			int height = 0;
			for (int i = 1; i < (str.length() + 1); i++) {
				char c = str.charAt(i - 1);
				
				switch (c) {
				case '\\' :
					height--;
					break;
				case '/' :
					height++;
					break;
				}
				heights[i] = height;
			}

			int num = 0;
			
			int limit = str.length() + 1;
			for (int i = 0; i < limit; i++) {
				int th = heights[i];
				int tmin = th;
				
				for (int j = (i + 1); j < limit; j++) {
					if (th < heights[j]) break;
					
					if (th == heights[j]) {
						if (tmin == th) {
							break;
						} else {
							sg.add(i);
							sg.add(j);
							
							num++;
							i = (j - 1);
							break;
						}
					}
					
					if (tmin > heights[j]) tmin = heights[j];
				}
			}
			
			double[] areas = new double[num];
			for (int i = 0; i < areas.length; i++) {
				int start = sg.get(i * 2);
				int end = sg.get(i * 2 + 1);
				
				height = 0;
				double area = 0.0;
				for (int j = start; j < end; j++) {
					char c = str.charAt(j);
					
					area = area + height;
					switch (c) {
					case '\\' :
						height++;
						area = area + 0.5;
						break;
					case '/' :
						height--;
						area = area - 0.5;
						break;
						}
				}
				
				areas[i] = area;
			}
			
			int sum = 0;
			for (int i = 0; i < areas.length; i++) {
				sum = sum + (int)areas[i];
			}
			System.out.println(sum);
			
			System.out.print(num);
			for (int i = 0; i < num; i++) {
				System.out.print(" " + (int)areas[i]);
			}
			System.out.println();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 27028
#include <bits/stdc++.h>
using namespace std;
 
 // a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
int K;
cin >> K;
int sum = 0;

for(int a = 1; a <= K; a++){
for(int b = 1; b <= K; b++){
for(int c = 1; c <= K; c++){
int M = GCD(a, b);
    int N = GCD(M, c);
    sum += N;

}
    
}

}
cout << sum << endl;
}



Measured memory_bytes: 3636