akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

vector<bool> Eratosthenes(int n) {
    vector<bool> prime(n, true);
    prime[0] = prime[1] = false;
    for (int i = 2; i * i <= n; i++) {
        if (!prime[i]) continue;
        for (int j = 2; i * j <= n; j++) {
            prime[i * j] = false;
        }
    }
    return prime;
}

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

    auto primes = Eratosthenes(55556);
    vector<int> ans;
    REP(i, 2, primes.size()) {
        if (primes[i] && i % 5 == 1) {
            ans.push_back(i);
        }
        if (ans.size() == N) break;
    }

    for (auto a : ans) cout << a << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C (GCC 5.4.1)
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS

int min3(int a, int b, int c){
	int ary[3] = {a, b, c};
	int min = 0x7F;
	for (int i = 0; i < 3; ++i)	min = (min < ary[i] ? min : ary[i]);
	return min;
}

int main(int argc, char const *argv[])
{
	int n,a,b;
	int p[103];
	int ia = 0,ib = 0,ic = 0;

	scanf("%d %d%d",&n,&a,&b);
	for (int i = 0; i < n; ++i){
		scanf("%d", &p[i]);
		if(p[i] <= a)	++ia;
		else if((a + 1) <= p[i] && p[i] <= b)	++ib;
		else ++ic;
	}
	printf("%d\n", min3(ia, ib, ic));
	return 0;
}


Measured memory_bytes: 128
#A
n=int(input())
h_list=list(map(int,input().split()))
h1=abs(h_list[0]-h_list[1])
cst_list=[0,h1]

for i in range(2,n):
    x1=cst_list[i-1]+abs(h_list[i]-h_list[i-1])
    x2=cst_list[i-2]+abs(h_list[i]-h_list[i-2])
    cst_list.append(min(x1,x2))
print(cst_list[-1])    

Measured memory_bytes: 20504
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int s[100][100];

int main(){
  int n,m;
  ll ans=0;
  cin >> n >> m;
  int k[m];
  rep(i,m){
    cin >> k[i];
    rep(j,k[i]){
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  int p[m];
  rep(i,m)cin >> p[i];
  for (int bit = 0; bit < (1<<n); ++bit){
    int on[n]={};
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                on[i]++;
            }
        }
    bool ok=true;
    rep(i,m){
      int cnt=0;
      rep(l,k[i]){
        if(on[s[i][l]]>0)cnt++;
      }
      if(cnt%2!=p[i])ok=false;
    }
    if(ok){
      ans++;
    }
  }
  cout << ans << endl;
return 0;}

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

int main() {
long long n;
cin >> n;
long long a[n];
long long ans = 0;
for(int i=0;i<n;i++){
    cin >> a[i];
}
long long sum[n+1];
sum[0]=0;
map<long long,long long> p;
p[0]=1;
for(long long i=0;i<n;i++){
    sum[i+1]=sum[i]+a[i];
}
for(long long i=0;i<n;i++){
  p[sum[i+1]]++;
}
for(auto i:p){
    ans+=(i.second*(i.second-1))/2;
}
cout << ans << endl;
}


Measured memory_bytes: 15872
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String s = sc.next();
    String b = sc.next();
    System.out.print("A");
    System.out.print(s.charAt(0));
    System.out.println("C");
  }
}


Measured memory_bytes: 21844
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){

string S;
cin>>S;
string ans="";
rep(i,1<<3){
    int sum=S[0]-'0';
    rep3(j,3){
        if((i>>(j-1))&1){
            sum+=S[j]-'0';
        }
        else{
            sum-=S[j]-'0';
        }
    }
    if(sum==7){
        ans+=string(1,S[0]);
        rep3(j,3){
            if((i>>(j-1))&1){
                ans+=string(1,'+');
                ans+=string(1,S[j]);
            }
            else{
                ans+=string(1,'-');
                ans+=string(1,S[j]);
            }
        }
        ans+="=7";
        break;
    }
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,t,i,res=0;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> t;
    while(t%2==0){
      t/=2;
      res++;
    }
  }
  cout << res << endl;
  return 0;
}

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

int main(){
    int N,M,y,max;
    string s[100],t[100];


    cin>>N;

    for(int i=1;i<=N;i++){
        cin>>s[i];
    }
    cin>>M;

    for(int i=1;i<=M;i++){
        cin>>t[i];
    }

    max=0;
    for(int i=1;i<=N;i++){
        y=0;
        for(int j=i;j<=N;j++){
            if(s[i]==s[j]) y=y+1;
        }
        for(int k=1;k<=M;k++){
            if(s[i]==t[k]) y=y-1;
        }
        if(max<y) max=y;
    }

    if(max<0) max=0;

    cout<<max<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,k;cin >> a >> b >> k;
	int cnt=0;
	for(int i=100;i>0;--i){
		if(a%i==0 && b%i==0) cnt++;
		if(cnt==k){
			cout << i << endl;
			break;
		}
	}
}


Measured memory_bytes: 256
MOD = 998244353
n, m, k = map(int, input().split())
c = 1
cnt = 0
for x in range(k + 1):
    cnt += c * m * pow(m - 1, n - 1 - x, MOD) 
    cnt %= MOD
    c *= (n - x - 1) * pow(x + 1, MOD - 2, MOD)
    c %= MOD
print(cnt)

Measured memory_bytes: 9168
N = int(input())
for ai in range(N//4,3500):
    for bi in range(N//4,3500):
        try:
            ci = N*ai*bi/(4*ai*bi-N*ai-N*bi)
        except:
            continue
        if ci == int(ci) and ci > 0:
            print(ai,bi,int(ci))
            exit()


Measured memory_bytes: 73464
#include <iostream>
using namespace std;
int main()
{
    char c[100005];
    while(cin >> c)
    {
        for(int i=0; c[i]!='\0'; i+=2)
        {
                cout << c[i];
                if(c[i+1]=='\0')
                    i--;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>

using namespace std;


int main() {

	int n;
	int truth = 0;
	int result;
	vector<int> s;
	int t;

	cin >> n;

	while (cin >> t) {
		s.push_back(t);
		truth += t;
	}

	if (truth % 10 == 0) {
		sort(s.begin(), s.end());
		for (int t : s) {
			if (t % 10 != 0) {
				result = truth - t;
				if (result < 0) {
					cout << '0' << endl;
				} else {
					cout << result << endl;
				}
				return 0;
			}
		}
		cout << '0' << endl;
	} else {
		cout << truth << endl;
	}


	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;

	string s, t; cin >> s >> t;
	FOR_LT(i, 0, s.size()) {
		cout << (char)s[i] << (char)t[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

s = input()
if len(s) == 2 and s[0]==s[1]: print(1,2); exit()
for n,(i,j,k) in enumerate(zip(s,s[1:],s[2:])):
    if i==j or j==k or k==i:
        print(n+1,n+3)
        break
else: print(-1,-1)

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

int main() {
	int a, b;
	int count = 0;
	cin >> a >> b;
	while (a <= b){
		stringstream c;
		c << a;
		string ans =  c.str();
		string alt = ans;
		reverse(alt.begin(), alt.end());
		if (alt == ans)
			count++;
		a++;
	}
	cout << count<<"\n";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main()
{
    double x1,x2,y1,y2,d,x,y;
    x=y=x1=x2=y1=y2=d=0;
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    x=x1-x2;
    y=(y1-y2);
    d=sqrt((x*x)+(y*y));
    printf("%.8lf",d);
    x1=x2=y1=y2=d=0;
    return 0;
}



Measured memory_bytes: 2104
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>



using namespace std;




int main() {

	string s;
	cin>>s;
	int ans=s.size();
	int a=0,b=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='S')a++;
		else {
			if(a){
				a--;ans-=2;
			}
		}
	}
	cout<<ans<<endl;

    return 0;
}

	
	


	

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
int a[1000000];
int cnt = 0;
void insertionsort(int A[],int n ,int g)
{
	for (int i = g; i < n; ++i)
	{
		int v = A[i];
		int j = i-g;
		while(j>=0 && A[j]>v)
		{
			A[j+g] = A[j];
			j = j-g;
			cnt++;
		}
		A[j+g] = v;
	}
}


int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d",&a[i]);
	}

	vector<int> G;
	int h = 1;
	for (int i = 0; i < n; ++i)
	{
		if(h>n) break;
		G.push_back(h);
		h = 3*h+1;
	}
	int m = G.size();
	for (int i = m-1; i >= 0; --i)
	{
		insertionsort(a, n, G[i]);
	}

	printf("%d\n", m);
	for (int i = m-1; i > 0; --i)
	{
		printf("%d ", G[i]);
	}
	printf("%d\n", G[0]);

	printf("%d\n", cnt);
	for (int i = 0; i < n; ++i)
	{
		printf("%d\n", a[i]);
	}
	return 0;
}

Measured memory_bytes: 7116
a = gets
b = a.split

w,h,x,y,r = b.map(&:to_i)

unless ( -100 <= x || x <= 100 ) || ( -100 <= y || y <= 100 )
  return
end

unless (0 < w || w <= 100 ) || (0 < h || h <= 100 ) || (0 < r || r <= 100 )
  return
end


if  ( (x < r) || (y < r) ) || ( ((w - x) < r) || ((h - y) < r) )
  puts "No"
else
  puts "Yes"
end



Measured memory_bytes: 8888
#include<stdio.h>
#define N 200000

int main()
{
  char s[N],t[N];

  scanf("%s",s);
  scanf("%s",t);

  int count=0;
  for(int i=0;i<N;i++){
    if(s[i] != t[i]) count++;

    if(s[i] == 0) break;
  }

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

  return 0;
}


Measured memory_bytes: 2080
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define p 1000000007
#define pb push_back
int dp[1001][1001];

int ways(int i,int j,int n,int m,vector<vector<char>> &v)
{
    if(v[i][j]=='#')
   {
            return dp[i][j]=0; 
            // vahan se koi path available nhi hai...
   }
   else
   {
    if( (i==n && j==m-1) || (i==n-1 && j==m))
    {
        return dp[i][j]=1;
    }
    else
    {
        if(dp[i][j]!=-1)
        {
            return dp[i][j];
        }
        
        
        else
        {
            return dp[i][j]=((j+1<=m?ways(i,j+1,n,m,v):0)%p+(i+1<=n?ways(i+1,j,n,m,v):0)%p)%p;
        }
    }
   }
}

int solve(int n,int m,vector<vector<char>> &v)
{
    memset(dp,-1,sizeof(dp));
    return ways(1,1,n,m,v);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n,m;
    cin>>n>>m;
    // 2-d array ko vector ke ander vector ke form mei reprsent kr sakte hain...
    vector<vector<char>> v(n+1,vector<char>(m+1));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>v[i].at(j);
        }
    }
    cout<<solve(n,m,v);
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    long long int n;
    cin >> n;
    int flag = 1;
    for(int i = 2; i < sqrt(n)+1; i++) {
        if(n % i == 0) {
            flag = 0;
            //cout << n % i << endl;
            break;
        }
    }

    int x = 0;
    if(flag == 1) {
        cout <<  n - 1 << endl;
    }
    else if(n == 1) {
        cout << 0 << endl;
    }
    else {
        for(int i = 2; i < sqrt(n)+1; i++) {
            if(n % i == 0) {
                x = max(i, x);
            }
        }
        cout << x + n/x - 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=510;
typedef pair<int,int> pii;
#define mp make_pair
#define fi first
#define se second

int n,mod,f[N][N],tp=0,g[N],new_f[N];
pii st[N];

int cal(int x,int y,int c) {
	int z=0;
	while(z<(n<<1)&&z*z+x*x<=y*y+c) ++z;
	return z;
}

int main() {
	cin>>n>>mod;
	for(int i=0;i<n;i++) st[++tp]=mp(cal(i,n,-1),-i),g[i]=cal(i,n<<1,0);
	for(int i=n;i<(n<<1);i++) st[++tp]=mp(cal(i,n<<1,0),1);
	sort(st+1,st+tp+1);
	int ans=0;
	for(int k=0;k<=n;k++) {
		memset(f,0,sizeof(f)),f[0][0]=1;
		int cnta=0,cntc=0;
		for(int i=1;i<=tp;i++) {
			if(st[i].se>0) {
				for(int j=0;j<=cnta;j++) f[i][j]=1ll*f[i-1][j]*(st[i].fi-cntc-j)%mod;
				++cntc;
			}
			else {
				memset(new_f,0,sizeof(new_f));
				for(int j=0;j<=cnta;j++) {
					new_f[j+1]=(new_f[j+1]+1ll*f[i-1][j]*(st[i].fi-cntc-j))%mod;
					new_f[j]=(new_f[j]+1ll*f[i-1][j]*(g[-st[i].se]-(n+k+cnta-j)))%mod;
				}
				memcpy(f[i],new_f,sizeof(new_f));
				++cnta;
			}
		}
		ans=(ans+((k&1)?-1:1)*f[tp][k])%mod;
	}
	cout<<(ans%mod+mod)%mod;
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h> 
using namespace std;
long long n,h[101],cnt,b[101];
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0'&&s[i+1]=='0'){
		s[i+1]='1';
		cnt++;}
		else if(s[i]=='1'&&s[i+1]=='1'){
		s[i+1]='0';
		cnt++;}}
		cout<<cnt;}


Measured memory_bytes: 512
N=int(input())
W=[input() for _ in range(N)]
his=set()
ok=True
lc=W[0][0]
for w in W:
	if w in his or lc != w[0]:
		ok=False
		break
	his.add(w)
	lc=w[len(w)-1]
print("Yes" if ok else "No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	string in; cin >> in;
	in = "0" + in;
	
	vi dp(2, inf);
	dp[0] = 0;
	for(char c : in){
		vi next(2, inf);
		rep(i, 2) if(dp[i] < inf) rep(d, 10) rep(j, 2){
			
			int r = i * 10 + d - (c - '0') - j;
			if(r < 0) continue;
			next[j] = min(next[j], dp[i] + r + d);
		}
		dp = next;
	}
	cout << dp[0] << endl;
	
	return 0;
}

Measured memory_bytes: 2332
using System;
using System.Linq;

namespace MinPro2019_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var KAB = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var K = KAB[0];
            var A = KAB[1];
            var B = KAB[2];

            if (B - A <= 2)
            {
                Console.WriteLine(K + 1);
                return;
            }

            long b = 1;
            if (b < A)
            {
                K -= A - b;
                b += A - b;
            }

            while (K >= 2)
            {
                b += (B - A);
                K -= 2;
            }

            if (K == 1) b++;
            Console.WriteLine(b);
        }
    }
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    int arr[n];
    //int mark[n];
    map<pair<int,int> ,bool > check;
    for(int i=1;i<=n;++i){
        cin>>arr[i];
        //mark[arr[i]]=i;
    }
    int ans=0;
    for(int i=1;i<=n;++i){
        if(i==arr[arr[i]]){
            if(!check[{i,arr[i]}] || !check[{arr[i],i}]){
                check[{i,arr[i]}]=1;
                check[{arr[i],i}]=1;
                ans++;
            }
        }
    }
    cout<<ans;
    cout<<endl;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int n,q;
    string s;
    cin >> n >> q;
    cin >> s;
    vector<pair<int, int>> question(q);
    rep(i, q){
        int r, l;
        cin >> l >> r;
        question[i] = make_pair(l, r);
    }
    int ac_cnt[100001] = {0};
    int cnt = 0;
    for (int i=0; i<n; i++){
        ac_cnt[i] = cnt;
        if (s[i] == 'A' && s[i+1] == 'C'){
            cnt++;
        }
    }

    rep(i,q){
        int l = question[i].first;
        int r = question[i].second;
        int ans = ac_cnt[r-1] - ac_cnt[l-1];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n, m; cin >> n >> m;
	vector<vector<int>> tb(n, vector<int>(m));

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> tb[i][j];
		}
	}

	set<int> s;
	for (int i = 0; i < 10000; i++) {
		s.insert(i*i);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			int val = 0;
			for (int k = 0; k < m; k++) {
				int diff = abs(tb[i][k] - tb[j][k]);
				val += diff * diff;
			}

			if (s.count(val))ans++;
		}
	}

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

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		boolean[][] cards = new boolean[4][13];

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		br.readLine();
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			String suit = arr[0];
			int num = Integer.parseInt(arr[1]);

			cards[getIndex(suit)][num - 1] = true;
		}

		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 13; j++) {
				if (!cards[i][j])
					System.out.println(getSuit(i) + " " + (j + 1));
			}
		}
	}

	private static int getIndex(String suit) {
		if ("S".equals(suit))
			return 0;
		else if ("H".equals(suit))
			return 1;
		else if ("C".equals(suit))
			return 2;
		else if ("D".equals(suit))
			return 3;

		throw new RuntimeException();
	}

	private static String getSuit(int index) {
		final String[] suits = { "S", "H", "C", "D" };
		return suits[index];
	}
}

Measured memory_bytes: 17072
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
    cin>>a>>b>>c;
    if((a==b&&a!=c)||(b==c&&b!=a)||(a==c&&a!=b))
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    const S = arg[1].split("");
    let alreadyHappy = 0;
    let last;
    
    for(let i in S) {
        if(last === "L" && S[i] === "L") {
            alreadyHappy++;
        }
        
        if(last === "R" && S[i] === "R") {
            alreadyHappy++;
        }
        
        last = S[i];
    }

    console.log(Math.min(N - 1, alreadyHappy + (2 * K)));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 13132
#include<iostream>
#include<cstdio>
#include<math.h>

using namespace std;

int a[1005];

int main()
{
    int n,T,i,j,A,H,k;
    double sum,mins = 1000000.0;

    scanf("%d %d %d",&n,&T,&A);

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

        sum = fabs(A-((double)T-(double)a[i]*0.006));
       // printf("%f %f\n",sum,mins);
        if(sum < mins){
            k = i+1;
            mins = sum;
        }
        //printf("%d\n",k);
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

	int N,X;
	
	scanf("%d %d",&N,&X);
	
	int m[100];
	
	int i;
	int min,volume,num;
	
	min=X;
	volume=X;
	
	for(i=0;i<N;i++)
	{
		scanf("%d",&m[i]);
		volume -= m[i];
		if(min>m[i]){
			min = m[i];
		}
	}
	
	num = volume / min;
	num += N;

	printf("%d",num);

}


Measured memory_bytes: 128
n = int(input())
p = list(map(int,input().split()))
import collections
import itertools
c = collections.Counter(p)
c_keys = list(c.keys())
com_list = list(itertools.combinations(c_keys, 3))

ans = 0
for i in range(len(com_list)):
    p_sort = sorted(com_list[i])
    if p_sort[0] + p_sort[1] > p_sort[2]:
        ans += c[p_sort[0]] * c[p_sort[1]] * c[p_sort[2]]

print(ans)

Measured memory_bytes: 20728
import java.util.*;
import java.math.*;
import java.text.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			double x = in.nextDouble();
			double h = in.nextDouble();
			if(x==0 && h==0) break;
			double s = (x*x) + Math.sqrt((x*x/4)+(h*h))*x*2;
			DecimalFormat fm = new DecimalFormat("#.000000");
			System.out.println(fm.format(s));
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
    //ios_base::sync_with_stdio(false);
    ll t;

        ll n, m, a, b;
        cin>>n;
        n %= 1000;
        if(n == 0) {
            puts("0");
            return 0;
        }
        cout<<1000ll - n<<"\n";

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll h,w;
    cin >> h >> w;
    if(h%3==0||w%3==0){
        cout << 0 << endl;
        return 0;
    }
    ll res = 1LL<<60;
    for(ll i=1;i<h-1;i++){
        ll tmp=res;
        ll maxx = max(i, (h-i)/2+(h-i)%2); 
        ll minx = min(i, (h-i)/2); 
        res = min(res, abs(maxx*w-minx*w));
    }
    DEBUG{cout << res << endl;}
    for(ll i=1;i<w-1;i++){
        ll maxx = max(i, (w-i)/2+(w-i)%2); 
        ll minx = min(i, (w-i)/2); 
        res = min(res, abs(maxx*h-minx*h));
    }
    DEBUG{cout << res << endl;}
    for(ll i=1;i<h;i++){
        ll maxx = max(i*w, (h-i)*(w/2+w%2)); 
        ll minx = min(i*w, (h-i)*(w/2)); 
        res = min(res, abs(maxx-minx));
    }
    DEBUG{cout << res << endl;}
    for(ll i=1;i<w;i++){
        ll maxx = max(i*h, (w-i)*(h/2+h%2)); 
        ll minx = min(i*h, (w-i)*(h/2)); 
        res = min(res, abs(maxx-minx));
    }
    // for(ll i=1;i<w;i++){
    //     res = min(res, abs(i*h-(h-i)*(h/2)));
    // }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
N, T = map(int, input().split())
AB= []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort(key=lambda x: x[1], reverse=True)
AB.sort()
# print(AB)
A = [x[0] for x in AB]
B = [x[1] for x in AB]

dp = [[0] * (T + 3) for _ in range(N + 3)]
dp[0][0] = 0
for i in range(N):
    for j in range(T):
        if A[i] <= j:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - A[i]] + B[i])
        else:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

# print(dp)
ans = 0
for i in range(N):
    # print(dp[i][T - 1])
    ans = max(ans, dp[i][T - 1] + B[i])
print(ans)

Measured memory_bytes: 117080
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

n = k()
for i in range(1,10):
    for j in range(1,10):
        if n == i*j:
            print("Yes")
            sys.exit()
print("No")


Measured memory_bytes: 10040
#include <bits/stdc++.h>
#include<string>
#define mod 1000000007
using ll = long long;
using namespace std; 

int main(){
    string n; cin >> n;
    for (auto a : n){
        if (a=='7') {
            cout << "Yes" << "\n";
            return 0;
        }
    }
    cout << "No" << "\n";
}



Measured memory_bytes: 3596
#include<stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	long int ar[n];
	for(int i=0;i<n;i++){
		scanf("%ld",&ar[i]);
	}
	long int sl=0,c=0;
	for(int i=0;i<=n-2;i++){
		if(ar[i]>ar[i+1]){
			c=ar[i]-ar[i+1];
			ar[i+1]=ar[i+1]+c;
			sl+=c;
		}
	}
	printf("%ld",sl);
}

Measured memory_bytes: 3240
M = 998244353
n,m,K = map(int,input().split())
ans = 0
c = 1
for k in range(K+1):
    ans += c * m * pow(m-1,n-k-1,M)
    c *= (n-k-1) * pow(k+1,M-2,M)
    ans %= M
    c %= M
print(ans)


Measured memory_bytes: 9028
#include <cstdio>
#include <exception>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <map>

using namespace std;

const int CAP = 2e5;
const int N = 1e6;
const int T = 1e7;
const long long INF = 1LL << 60;

struct line {
	long long a;
	long long b;
	long long eval(long long x) {
		return a * x + b;
	}
	long long below(const line& other, long long x) {
		return (a - other.a) * x + (b - other.b) <= 0;
	}
};

bool vis[T];
line c[T];

void modify(int i, int l, int r, line a) {
	if (!vis[i]) {
		vis[i] = 1;
		c[i] = a;
		return;
	}
	if (c[i].below(a, l) && c[i].below(a, r)) {
		return;
	}
	if (a.below(c[i], l) && a.below(c[i], r)) {
		swap(a, c[i]);
		return;
	}
	if (a.below(c[i], l)) {
		swap(a, c[i]);
	}
	int mid = (l + r) / 2;
	if (c[i].below(a, mid)) {
		//intersect [mid:r]
		modify(2 * i + 1, mid, r, a);
	} else {
		//intersect [l:mid - 1]
		swap(c[i], a);
		modify(2 * i, l, mid - 1, a);
	}
}

long long value(int i, int l, int r, int x) {
	if (!vis[i]) {
		return INF;
	}
	if (l == r) {
		return c[i].eval(x);
	}
	long long ans = c[i].eval(x);
	int mid = (l + r) >> 1;
	if (x >= mid) {
		return min(ans, value(2 * i + 1, mid, r, x));

	} else {
		return min(ans, value(2 * i, l, mid - 1, x));
	}
}

long long dp;

int main() {
	::ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	long long c;
	cin >> n >> c;
	for (int i = 0; i < n; ++i) {
		static long long h;
		cin >> h;
		if (i != 0) {
			dp = value(1, 1, N, h) + c + h * h;
		}
		line cur = { -2 * h, dp + h * h };
		modify(1, 1, N, cur);
		//cout << dp << " ";
	}
	cout << dp << "\n";
	return 0;
}

Measured memory_bytes: 58368
#!/usr/bin/env python

#from collections import deque
#import itertools as it
#import sys
#import math

def func():
    N = int(input())

    A = list(map(int, input().split()))
    P = [[(A[0], 0), (0, 0)] for i in range(2 ** N)]

    for i in range(1, 2 ** N):
        if (A[i], i) > P[i][0]:
            P[i][1] = P[i][0]
            P[i][0] = (A[i], i)
        elif (A[i], i) > P[i][1]:
            P[i][1] = (A[i], i)
        for j in range(N):
            if (i & (1 << j)) == 0:
                index = i + (1 << j)
                for k in range(2):
                    if P[i][k] > P[index][0]:
                        P[index][1] = P[index][0]
                        P[index][0] = P[i][k]
                    elif P[i][k] > P[index][1] and P[i][k] != P[index][0]:
                        P[index][1] = P[i][k]
    ans = 0
    for i in range(1, 2 ** N):
        ans = max(ans, P[i][0][0] + P[i][1][0])
        print(ans)
    #print(P)

func()

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

vector<int> A;

bool solve(int m, int i)
{
	if (m == 0)
	{
		return true;
	}
	if (i == A.size() || m < 0)
	{
		return false;
	}
	return solve(m, i + 1) + solve(m - A[i], i + 1);
}

int main() 
{
	int n, q, m;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		A.push_back(tmp);
	}

	sort(A.begin(), A.end());
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		cin >> m;
		if (solve(m, 0))
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}
}


Measured memory_bytes: 3168
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=4010;
int v[N];
char s[5],w[N];
inline bool ask(int x,int y) {
    printf("? %d %d\n",x,y);
    fflush(stdout);
    scanf("%s",s);
    return s[0]=='Y';
}
int main() {
    int n,m,tp=0;
    cin>>n>>m;
    if(n<=m) return puts("Impossible"),0;
    for(int i=0;i<n+m;i++) {
	if(!tp) v[++tp]=i;
	else if(ask(v[tp],i)) v[++tp]=i;
	else --tp;
    }
    for(int i=0;i<n+m;i++) w[i]=ask(v[tp],i)+'0';
    printf("! %s",w);
    return 0;
}

Measured memory_bytes: 724
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int n;

vector<vector<int> >v;
vector<int >deg;

int dp[maxn];
int ans;

void dfs(int x,int prev)
{
	for(int i=0;i<v[x].size();i++)
	{
		int son=v[x][i];
		if(son!=prev)
		{
			dfs(son,x);
		}
	}
	int sum=0;int add=0;
	for(int i=0;i<v[x].size();i++)
	{
		int son=v[x][i];
		if(son!=prev)
		{
			if(dp[son]==0)add++;
			sum+=dp[son];
		}
	}
	//dp[x]有可能为0 
	dp[x]=sum+max(add-1,0); //add-1可能<0 
}

int main()
{
	ios::sync_with_stdio(0);
	
	cin>>n;v.resize(n+1);deg.resize(n+1);
	for(int i=1;i<n;i++)
	{
		int a,b;cin>>a>>b;
		v[a].push_back(b);v[b].push_back(a);
		deg[a]++;deg[b]++;
	}
	
	int ma=0,root=-1;
	for(int i=0;i<n;i++)
	{
		if(deg[i]>ma)
		{
			ma=deg[i];
			root=i;
		}
	}
	if(ma<=2)
	{
		cout<<"1\n";return 0;
	}
	
	dfs(root,-1);
	cout<<dp[root];
	return 0;
}

Measured memory_bytes: 9984
#include<stdio.h>
int main(void){
int a,b,x;
char op;

while(1){
    scanf("%d %c %d",&a,&op,&b);
if(op == '+'){
	x=a+b;
	printf("%d\n",x);
}
if(op == '-'){
	x=a-b;
	printf("%d\n",x);
}
if(op == '*'){
	x=a*b;
	printf("%d\n",x);
}
if(op == '/'){
	x=(double)a/(double)b;
	printf("%d\n",x);
}
if(op == '?'){
    break;
}

}


return(0);
}


Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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


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

    ll N;
    cin >> N;
    string ans;

    ll i = 2;
    ll j = -2;

    for(int k = 0; k <= 500; k++){
        if(N % i == 0){
            ans.push_back('0');
        }else{
            ans.push_back('1');
            N -= (-j/2);
        }
        i *= 2;
        j *= -2;
        if(N == 0){
            break;
        }
    }

    reverse(ans.begin(), ans.end());

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;

const int mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }

  vector<int> dp(1 << n);
  dp[0] = 1;
  for (int mask = 0; mask < (1<<n) - 1; ++mask) {
    int i = __builtin_popcount(mask);
    for (int j = 0; j < n; ++j) {
      int u = (1 << j);
      if (a[i][j] && !(mask & u)) {
        int m2 = (mask | u);
        dp[m2] += dp[mask];
        if (dp[m2] >= mod) {
          dp[m2] -= mod;
        }
      }
    }
  }
  cout << dp[(1 << n) - 1] << '\n';

  return 0;
}


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

int main() {
    int n;
    cin>>n;
    vector<int> f(n,0);
    vector<vector<int> > p = vector<vector<int> >(n, vector<int>(11, 0));
    int tf;
    for(int i=0; i<n; i++) {
        for(int j=0; j<10; j++) {
            cin>>tf;
            f[i] |= tf<<j;
        }
    }
    for(int i=0; i<n; i++) {
        for(int j=0; j<11; j++) {
            cin>>p[i][j];
        }
    }
    long long maxs = -(1<<30);
    int te;
    for(int mf=1; mf<1024; mf++) {
        int sum=0;
        for(int i=0; i<n; i++) {
            te = mf&f[i];
            int count=0;
            for(int j=0; j<10; j++) {
                count += te%2;
                te /= 2;
            }
            sum += p[i][count];
        }
        maxs = max((long long)sum, maxs);
    }
    cout << maxs << endl;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int[] X = nextIntArray(sc, M);

		sc.close();

		if (N >= M) {
			out.println(0);
			return;
		}

		Arrays.sort(X);

		int[] r = new int[M - 1];
		for (int i = 0; i < M - 1; i++) {
			r[i] = Math.abs(X[i + 1] - X[i]);
		}

		Arrays.sort(r);

		// 距離の長いN-1個の区間は通らないようにする
		long fuyou = 0;
		for (int i = 0; i < N - 1; i++) {
			fuyou += r[(M - 1) - 1 - i];
		}

		out.println(Math.abs(X[M - 1] - X[0]) - fuyou);

	}

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

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 49208
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func vi(n int, args ...int) []int {
	res := make([]int, n)
	if len(args) == 0 {
		return res
	}
	v := args[0]
	if v == 0 {
		return res
	}
	for i := 0; i < n; i++ {
		res[i] = v
	}
	return res
}

func vvi(n int, args ...int) [][]int {
	res := make([][]int, n)
	m := n
	if len(args) > 0 {
		m = args[0]
	}
	v := 0
	if len(args) > 1 {
		v = args[1]
	}
	for i := 0; i < n; i++ {
		res[i] = vi(m, v)
	}
	return res
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
type edge struct {
	to   int
	cost int64
}

func main() {
	defer stdout.Flush()
	n := readInt()
	c := make([][]edge, n+1)
	for i := 0; i < n-1; i++ {
		a := readInt()
		b := readInt()
		cost := readInt64()
		e1 := edge{b, cost}
		e2 := edge{a, cost}
		c[a] = append(c[a], e1)
		c[b] = append(c[b], e2)
	}

	Q := readInt()
	K := readInt()

	d := make([]int64, n+1)
	for i := 0; i < n+1; i++ {
		d[i] = math.MaxInt64
	}
	q := make([]int, 0)
	pop := func() (int, bool) {
		if len(q) == 0 {
			return -1, false
		}
		r := q[0]
		q = q[1:]
		return r, true
	}
	push := func(a int) {
		q = append(q, a)
	}

	push(K)
	d[K] = 0
	for from, ok := pop(); ok; from, ok = pop() {
		for _, e := range c[from] {
			nc := d[from] + e.cost
			if nc < d[e.to] {
				d[e.to] = nc
				push(e.to)
			}
		}
	}

	for i := 0; i < Q; i++ {
		x := readInt()
		y := readInt()
		println(d[x] + d[y])
	}
}


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

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i = 0; i < N; i++)cin >> H.at(i);
    bool pro = true;
    
    //左から右に向かって広義単調増加 <-> 右から左に向かって広義単調減少
    // i マス目を 1 低くできるので、減少列を考えるほうが楽
    //右（N）から左（0）に向かって、次のマスを１低くすることで左から右へ広義単調減少列になるかどうか考える
    
    for(int i = N - 1; i > 0; i--){
        if(H.at(i - 1) <= H.at(i))continue;//広義単調減少列である場合は考えない
        else{
            //左の方が大きい場合、左の高さを -1 する
            //-1 したとき、i, i - 1 番目が広義単調減少列 -> i 番目の高さと i - 1 番目の高さが等しい 
            if(H.at(i - 1) - 1 == H.at(i)){
                H.at(i - 1) = H.at(i - 1) - 1;
                continue;
            }
            
            //そうならない場合は不可能なので、break して終了
            else{
                pro = false;
                break;
            }
        }
    }
    
    if(pro)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

/*
問題文通りに右から左に向かって１減らすかを考えると、
    N
    2 2 2 2 2 ... 2 2 1
    
    N
    2 2 2 3 2 ... 2 2 1
みたいなテストケースの判定がめんどくさい(N - 1番目を -1 したとき遡らなくてはいけないため)
*/

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <map>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  std::map<string, int> S;
  rep(i, N)
  {
    string tmp;
    cin >> tmp;
    S[tmp]++;
  }

  cout << "AC x " << S["AC"] << endl;
  cout << "WA x " << S["WA"] << endl;
  cout << "TLE x " << S["TLE"] << endl;
  cout << "RE x " << S["RE"] << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int main(void)
{
    string S;
    cin >> S;

    string str = S;
    reverse(str.begin(), str.end());
    if (str != S) {
        cout << "No" << endl;
        return 0;
    }

    int half = S.size() / 2;
    string left = S.substr(0, half);
    string l = left;
    reverse(l.begin(), l.end());
    if (l != left) {
        cout << "No" << endl;
        return 0;
    }

    string right = S.substr(half + 1, half);
    string r = right;
    reverse(r.begin(), r.end());
    if (r != right) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
        #include <vector>
        #include <algorithm>
         
        using namespace std;
         
        int main() {
          long long n;
          cin >> n;
         
          vector<long long> a(n);
          for(long long i;i<n;i++){
            cin >> a[i];
          }
          
          std::sort(a.begin(),a.end());
          while(true){
            if(a.size()==1){
              break;
            }
          	if (a[1]%a[0]==0){
              a[1]=0;
              a.erase(a.begin()+1);
            } else {
              a[1] = a[1] - a[0];
              if(a[1]<a[0]){
                std::sort(a.begin(),a.end());
              }
            }
          }
          
          cout << a[0] << endl;
          return 0;
        }

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>
#include<iomanip>

using namespace std;

typedef long long ll;

int main()
{
  int n, x = 0, y = 0, ans = 10000000;
  cin >> n;
  vector<int> v(n), c(n);

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

  for (int i = 0; i < n; i++)
  {
    if(v[i] > c[i]){
      x += v[i];
      y += c[i];
    }
  }
  
  cout << x - y << endl;
  return 0;
  
}


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

def calc(list):
    """
    return (min,max,sum)

    >>> calc([10, 1, 5, 4, 17])
    (1, 17, 37)
    >>> calc([-2, -1, 0])
    (-2, 0, -3)
    >>> calc([-1000000,1000000,0])
    (-1000000, 1000000, 0)
    """

    return (min(list),max(list),sum(list))


if __name__ == '__main__':
    n = int(raw_input())
    list = map(int,raw_input().split())
    print " ".join(map(str,calc(list)))

Measured memory_bytes: 7168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ull n,a;
    cin >> n;
    vector<ull> a_1,cmp;
    ull ans[2]={0,0};
    for(int i=0;i<n;i++){
        cin >> a;
        a_1.push_back(a);
    }
    sort(a_1.begin(),a_1.end());
    for(int i=0;i<n-1;i++){
        if(a_1[i]==a_1[i+1]){
            if(a_1[i]>=ans[1]){
                ans[0]=ans[1];
                ans[1]=a_1[i];
                i++;
            }
        }
    }
    ull x=ans[0]*ans[1];
    cout << x << endl;

    return 0;
}

Measured memory_bytes: 1400
use std::io::*;
//use std::str::*;

fn main() {
	let s = get_in();
	let vec = s.split_whitespace().map(|n| n.parse::<isize>().unwrap()).collect::<Vec<isize>>();
	let (a, v) = (vec[0], vec[1]);
	
	let s = get_in();
	let vec = s.split_whitespace().map(|n| n.parse::<isize>().unwrap()).collect::<Vec<isize>>();
	let (b, w) = (vec[0], vec[1]);
	
	let t = get_in().replace("\n", "").parse::<isize>().unwrap();
	
	if a < b {
		if t*v + a >= t*w + b {
			println!("YES");
		} else {
			println!("NO");
		}
	} else {
		if -t*v + a <= -t*w + b {
			println!("YES");
		} else {
			println!("NO");
		}
	}
	
	
}

fn get_in() -> String {
	let mut buf = String::new();
	stdin().read_line(&mut buf).ok();
	
	buf
}


Measured memory_bytes: 2104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

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

		while (true) {
			int n = Integer.parseInt(br.readLine());

			if (n == 0)
				break;

			if (n == 1 || n == 2) {
				System.out.println(0);
				continue;
			}

			int ans = 0;
			for (int i = n / 2 + 1; i >= 1; i--) {
				int sum = 0;
				for (int j = i; j >= 1; j--) {
					sum += j;
					if (sum == n) {
						ans++;
					}
					if (sum >= n)
						break;
				}
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 24452
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	a := ReadInts(N)
	s := make([]int, N+1)
	for i := 0; i < N; i++ {
		s[i+1] = s[i] + a[i]
	}
	ans := 1 << 62
	for i := 1; i < N; i++ {
		xy := 2*s[i] - s[N]
		if xy < 0 {
			xy *= -1
		}
		if ans > xy {
			ans = xy
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 6592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
int main() {
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	string ans;
	if(A+B==C+D)ans="Balanced";
	else if (A+B>C+D)ans="Left";
	else if (A+B<C+D)ans="Right";
	cout<<ans<<endl;
}

Measured memory_bytes: 256