akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on

ll nCr(int N) {
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = i + 1; j <= N; j++) {
      if (i == j) continue;
      ans++;
    }
  }
  return ans;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;

  ll ans = nCr(N) + nCr(M);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// Problem : D - Robot Arms
// Contest : AtCoder Regular Contest 103
// URL : https://atcoder.jp/contests/arc103/tasks/arc103_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct node
{
 int x,y;
}p[1005];
const char s[]="LRDU";
char res[55];
vector<int> d;
int main()
{
 int n,op;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  cin>>p[i].x>>p[i].y;
  if(i==1)op=(p[i].x+p[i].y)&1;
  else if(op!=((p[i].x+p[i].y)&1))
  {
   cout<<-1<<endl;
   return 0;
  }
 }
 cout<<32-op<<endl;
 cout<<1<<' ';
 d.push_back(0),d.push_back(1);
 for(int i=op;i<=30;i++)
 {
  d.push_back(1<<i);
  cout<<(1<<i)<<' ';
 }
 cout<<endl;
 for(int i=1;i<=n;i++)
 {
  long long x=0,y=0,tx=p[i].x,ty=p[i].y;
  for(int j=32-op;j;j--)
  {
   if(abs(tx-x)>abs(ty-y))
   {
    if(tx-x>0)res[j]='R',x=x+d[j];
    else res[j]='L',x=x-d[j];
   }
   else
   {
    if(ty-y>0)res[j]='U',y=y+d[j];
    else res[j]='D',y=y-d[j];
   }
  }
  cout<<(res+1)<<endl; 
 }
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
	string s; cin>>s;
	int ans=INF;
	FOR(i,0,s.size()-2){
		int n=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0')*1;
		if(abs(n-753)<abs(ans-753)) ans=n;
	}
	co(abs(ans-753));
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

  int n; cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; i++) {
    string s; cin >> s;
    mp[s]++;
  }
  vector<pair<int, string>> v;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    v.push_back(make_pair(it->second, it->first));
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  int cnt = v[0].first;
  vector<string> ans;
  for (int i = 0; i < v.size(); i++) {
    if (v[i].first == cnt) {
      ans.push_back(v[i].second);
    }
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}

Measured memory_bytes: 31596
import math
K = int(input())
N = list()
ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        N.append(math.gcd(a, b))

for n in N:
    for c in range(1, K+1):
        ans += math.gcd(n, c)

print(ans)

Measured memory_bytes: 9428
#include <iostream>

using namespace std;
int main()
{
  string a[8];
  for(;cin>>a[0];)
    {
      for(int i=1;i<8;i++)
	cin>>a[i];
      char n='X';
      for(int i=0;i<8;i++)
	for(int j=0;j<8;j++)
	  if(a[i][j]=='1')
	    {
	      if(i<7&&j<7&&a[i][j+1]=='1' &&a[i+1][j]=='1' &&a[i+1][j+1]=='1')
		n='A';
	      else if(i<5&&a[i+1][j]=='1' &&a[i+2][j]=='1' &&a[i+3][j]=='1')
		n='B';
	      else if(j<5&&a[i][j+1]=='1' &&a[i][j+2]=='1' &&a[i][j+3]=='1')
		n='C';
	      else if(j>0&&i<6&&a[i+1][j]=='1' &&a[i+1][j-1]=='1' &&a[i+2][j-1]=='1')
		n='D';
	      else if(i<7&&j<6&&a[i][j+1]=='1' &&a[i+1][j+1]=='1' &&a[i+1][j+2]=='1')
		n='E';
	      else if(i<6&&j<7&&a[i+1][j]=='1' &&a[i+1][j+1]=='1' &&a[i+2][j+1]=='1')
		n='F';
	      if(n!='X')
		break;
	    }
      if(n=='X')
	n='G';
      cout<<n<<endl;

    }
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9 + 7;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
const int mod = 1e9 + 7;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main() {
    int n;
    while (cin >> n && n > 0) {
        int sum = 0;
        for (int d = n; d < 600; d += n) {
            sum += n * d * d;
        }
        cout << sum << endl;
    }
}



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

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			char[] ring = input.readLine().toCharArray();
			char[] pattern = input.readLine().toCharArray();
			boolean flag = false;

			int tmp;
			for (int i = 0; i < ring.length; i++) {
				tmp = i;
				for (int j = 0; j < pattern.length; tmp++, j++) {
					if (tmp == ring.length) {
						tmp = 0;
					}

					if (ring[tmp] != pattern[j]) {
						break;
					} else if (j == pattern.length-1) {
						flag = true;
					}
				}
				if (flag) {
					break;
				}
			}
			System.out.println(flag ? "Yes" : "No");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}

Measured memory_bytes: 17052
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yn(int o){
    if (o == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int main() {
    int a, b, c; cin >> a >> b >> c;
    int m = max({a,b,c});
    cout << a + b + c - m << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pii pair <int,int>
ll mod=1000000007;
ll dp[2001];
ll solve(int n)
{
	if(dp[n]!=-1)
		return dp[n];
	else
	{
		ll ans=0;
		for(int i=3;i<=n;i++)
		{
			ans=(ans+solve(n-i))%mod;
		}
		dp[n]=ans;
	}
	return dp[n];
}

int main()
{
	fast;
	int n;cin>>n;
	memset(dp,-1,sizeof(dp));
	dp[0]=1;
	dp[1]=0;
	dp[2]=0;
	dp[3]=1;
	dp[4]=1;
	dp[5]=1;
	dp[6]=2;
	cout<<solve(n);


}

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

using namespace std;

#define fast_io ios::sync_with_stdio(false); cin.tie(NULL);

int main()
{
	fast_io;
	
	int n;
	cin >> n;
	int array[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> array[i];
	}

	int answer = 0;
	for (int i = 0; i < n; ++i)
	{
		while (array[i] % 2 == 0)
		{
			array[i] /= 2;
			answer++;
		}
	}
		
	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  string t="No";
  if(s.at(0)==s.at(1) && s.at(2)==s.at(3) && s.at(0)!=s.at(2)){
    t="Yes";
  }
  if(s.at(0)==s.at(2) && s.at(1)==s.at(3) && s.at(1)!=s.at(2)){
    t="Yes";
  }
   if(s.at(0)==s.at(3) && s.at(2)==s.at(1) && s.at(0)!=s.at(2)){
    t="Yes";
  }
  cout << t;
}
    


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		
		int n = sc.nextInt();
		int i = sc.nextInt();
		
		System.out.println(n-i+1);

	}
}

Measured memory_bytes: 26908
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath>

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
typedef long long ll;
using namespace std;

map<ll, ll> cnt_min;

ll res(ll N) {
    if(N == 1) return 1;

    // 値が会ったら
    if(cnt_min.count(N)) {
        return cnt_min[N];
    }else {
        return cnt_min[N] = 2 * res(N/2) + 1;
    }
}

void solve(long long H){
    cout << res(H) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long H;
    scanf("%lld",&H);
    solve(H);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int V[3000][3000];
ll dp[3001][3001][4];

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


	int R, C, K;
	cin >> R >> C >> K;

	rep(i, K) {
		int r, c, v;
		cin >> r >> c >> v;
		V[c - 1][r - 1] = v;
	}

	rep(i, C) rep(j, R) {
		for(int k = 2; k >= 0; k--) {
			chmax(dp[i][j][k + 1], dp[i][j][k] + V[i][j]);
		}
		rep(k, 3) {
			chmax(dp[i + 1][j][k], dp[i][j][k]);
			chmax(dp[i][j + 1][0], dp[i][j][k]);
		}
		chmax(dp[i + 1][j][3], dp[i][j][3]);
		chmax(dp[i][j + 1][0], dp[i][j][3]);
	}

	ll kotae = 0;
	rep(j, R + 1) rep(k, 4) {
		chmax(kotae, dp[C][j][k]);
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 320108
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

#define WHITE 0
#define BRACK 1
#define GRAY 2
#define N 101

int color[N];
int d[N];
int f[N];
int e[N];
int time;
int A[N][N];
int v[N];
int B[N][N];
int n;
int Q[N];
int head, tail;

void enqueue(int x){
  Q[tail]=x;
  if(tail+1==N) tail=0;
  else tail=tail+1;
}

int dequeue(){
  int x;
  x=Q[head];
  if(head+1==N) head=0;
  else head=head+1;
  return x;
}

void BFS(int s){
  int i,u=v[s],v,j,k;

  for(i=1;i<=n;i++){
    color[u]=WHITE;
    d[u]=INT_MAX;
    color[s]=GRAY;
  }
  d[s]=0;
  
  for(i=0;i<N;i++)Q[i]=0;
  head=1;
  tail=1;
  enqueue(s);
  
  for(j=1;Q[j]!=0;j++){
    u=dequeue();
    for(i=1;i<=e[u];i++){
      v=B[u][i];
      if(color[v]==WHITE){
	color[v]=GRAY;
	d[v]=d[u]+1;
	enqueue(v);
      }
    }
    color[u]=BRACK;
  }

  for(k=1;k<=n;k++) printf("%d %d\n",k,d[k]);

}

main(){
  int i,j,v1;
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      A[i][j]=WHITE;
    }
  }

  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%d%d",&v[i],&e[i]);
    for(j=1;j<=e[i];j++){
      scanf("%d",&v1);
      B[i][j]=v1;
      A[i][v1]= BRACK;
    }
  }

  for(i=0;i<N;i++)d[i]=-1;

  BFS(1);

  return 0;
}

Measured memory_bytes: 672
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<n;i++)

int main(){
  int n;
  cin >> n;
  int cnt[100000];
  rep(i,100){
    rep(j,100){
      rep(k,100){
        cnt[i*i+j*j+k*k+i*j+j*k+k*i]++;
      }
    }
  }
  for(int i=1;i<=n;i++){
    cout << cnt[i] << endl;
  }
  return 0;
}


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

int n,m,G;

vector<int> t[30];
int u[30];
map<int,int> dp;

int solve(int S){
  if(S==G)return 0;
  if(dp[S]>0)return dp[S];

  int k;
  for(k=0;k<n;k++)if((S>>k&1)==0) break; 

  int res=30;
  for(int i=0;i<(int)t[k].size();i++){
    int w=t[k][i];
    res=min(res, solve(S|u[w])+1 );
  }
  return dp[S]=res;
}


int main(){
  int a,b;
  while(cin>>n>>m){
    if(n==0&&m==0)break;

    dp.clear();
    for(int i=0;i<n;i++)t[i].clear();

    for(int i=0;i<m;i++){
      cin>>a>>b;
      t[a].push_back(b);
      t[b].push_back(a);
    }

    for(int i=0;i<n;i++){
      u[i]=1<<i;
      t[i].push_back(i);
      for(int j=0;j<(int)t[i].size();j++)u[i]|=1<<t[i][j];
    }

    G=(1<<n)-1;			      
    cout<<solve(0)<<endl;
  }
  return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	int n;
	cin >> n;
	int mi = INF,cnt = 0;
	rep(i,n){
		int p;
		cin >> p;
		if(p < mi){
			cnt++;
			mi = p;
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        char c = s.next().charAt(0);
        if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') System.out.println("vowel");
        else System.out.println("consonant");
    }

}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25392
#include <stdio.h>

const int N=1e5+5;

int n,m,ans;

struct Node {
	bool status;
	int tot;
} a[N];

int main() {
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++)
		a[i].status=false,a[i].tot=1;
	a[1].status=true;
	for(int i=1; i<=m; i++) {
		int x,y;
		scanf("%d%d",&x,&y);
		if(a[x].status)
			a[y].status=true;
		if(a[x].tot==1)
			a[x].status=false;
		a[x].tot--;
		a[y].tot++;
	}
	for(int i=1; i<=n; i++)
		if(a[i].status)
			ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class A {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int N, M;
        Input(out N, out M);
        int count = 0;
        Print(N * (N - 1) / 2 + M * (M - 1) / 2);
        Out.Flush();
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void Inputs<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 13140
import java.util.*;
 
public class Main {
    public static void main (String[] args) {
        //Scanner in = new Scanner(System.in);
        Scanner scanner = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        String NString = scanner.nextLine();
        String[] arr = NString.split(" ");
        int  a = Integer.valueOf(arr[0]);
        int  b = Integer.valueOf(arr[1]);
        int  c = Integer.valueOf(arr[2]);

        sb.append((a + b + c) < 22 ? "win" : "bust");
        System.out.println(sb);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    string s; cin >>s;
    int n = s.length();

    int ans = 0;
    for (int i = 1; i < n/2; i++) {
        string s1 = "";
        string s2 = "";
        for (int j = 0; j < i; j++) {
            s1 += s[j];
            s2 += s[i+j]; 
        }
        if (s1 == s2) {
            //cout << s1 << " " << s2 << endl;
            ans = max(ans, i*2);
        }
    }
    cout << ans << endl;
    return 0;
}




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

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

    reverse(N.begin(), N.end());
    int n = (int)N.size();

    vector<vector<int>> T(n, vector<int>(2));
    T[0][0] = N[0]-'0';
    T[0][1] = 10-(N[0]-'0');
    for (int i=1; i<n; i++)
    {
        T[i][0] = min(T[i-1][0]+N[i]-'0', T[i-1][1]+N[i]-'0'+1);
        T[i][1] = min(T[i-1][0]+10-(N[i]-'0'), T[i-1][1]+9-(N[i]-'0'));
    }
    cout<<min(T[n-1][0], T[n-1][1]+1)<<endl;
}


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

#define M_PI       3.14159265358979323846

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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;


//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 SQ(a) ((a)*(a))
#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 SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


struct Edge {
    int to, from;
    ll cost;
    Edge(int from, int to, ll cost): from(from), to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

int main() {
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    string s, t; cin >> s >> t;

    ll n = s.size(), m = t.size();

    vector<vector<ll>> v(26);
    
    REP(i, n){
        v[s[i]-'a'].push_back(i);
    }
    REP(i, n){
        v[s[i]-'a'].push_back(i+n);
    }

    ll ans = 0;
    ll idx=0;
    REP(i, m){
        int c = t[i]-'a';
        if(v[c].size()==0){
            cout << -1 << endl;
            return 0;
        }
        
        idx = *lower_bound(all(v[c]), idx)+1;
        if(idx >= n){
            idx -= n;
            ans += n;
        }
    }
    cout << idx + ans << endl;
    return 0;

}

Measured memory_bytes: 2800
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
ll test[12345678], res[12345678];
signed main() {
	ll n, x = 0, cnt = 0, ans = 0;
	cin >> n;
	for (int h = 0; h <= n; h++) {
		cin >> test[h];

		if (h == 0) { res[h] = 1; }
		else { res[h] = min((ll)1000000000000000001, res[h - 1] * 2 - test[h]); }

		if (h != n && res[h] <= 0) { x++; }
		if (h == n && res[h] < 0) { x++; }
		if (h == 0 && test[h] != 0) { x++; }
	}
	if (n == 0) {
		if (test[0] == 1) { cout << 1 << endl; }
		else { cout << -1 << endl; }
		return 0;
	}
	if (x != 0) { cout << -1 << endl; return 0; }

	cnt = test[n]; ans += cnt;

	for (int h = n - 1; h >= 0; h--) {
		if (cnt > res[h]) { cnt = res[h]; }
		cnt += test[h]; ans += cnt;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5188
import os
from io import BytesIO

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

n, k = map(int, input().split())
a = sorted(int(i) for i in input().split())

dp = [False] * (k + 1)

for i in xrange(k + 1):
    for ai in a:
        if ai > i:
            break
        if not dp[i - ai]:
            dp[i] = True
            break

os.write(1, 'First' if dp[k] else 'Second')

Measured memory_bytes: 33516
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=200005;
int f[N],from[N],d[N],q[N],n,a,b,rt,rt2;
char s[N];
vi e[N];
ll ans;

void diameter(){
	int r=0,u;
	fill(d,d+n+1,-1);
	d[1]=0,q[r++]=1;
	for(int l=0;l<r;l++){
		u=q[l];
		REP(k,SZ(e[u])){
			if(d[e[u][k]]==-1){
				d[e[u][k]]=d[u]+1;
				q[r++]=e[u][k];
			}
		}
	}
	fill(d,d+n+1,-1),r=0;
	d[u]=0,q[r++]=u;
	for(int l=0;l<r;l++){
		u=q[l];
		REP(k,SZ(e[u])){
			if(d[e[u][k]]==-1){
				d[e[u][k]]=d[u]+1;
				from[e[u][k]]=u;
				q[r++]=e[u][k];
			}
		}
	}
	vi pt;
	for(;u;u=from[u]){
		pt.pb(u);
//		cout<<"@"<<u<<endl;
	}
	if(SZ(pt)&1){
		rt=pt[SZ(pt)/2];
	}
	else{
		rt=pt[SZ(pt)/2-1];
		rt2=pt[SZ(pt)/2];
	}
}

void dfs(int u,int fa){
	d[u]=0,f[u]=N;
	REP(k,SZ(e[u])){
		int v=e[u][k];
		if(v==fa) continue;
		dfs(v,u);
		d[u]=max(d[u],d[v]+1);
		ans+=max(0,d[v]+2-f[v]);
//		cout<<"#"<<v<<" "<<max(0,d[v]+2-f[v])<<endl;
		f[u]=min(f[u],max(f[v],d[v]+1));
	} 
	if(s[u]=='1'){
		f[u]=0;
	}
//	cout<<"!"<<u<<" "<<fa<<"  "<<d[u]<<" "<<f[u]<<endl;
}

int main(){
	read(n);
	rep(i,1,n-1){
		read(a),read(b);
		e[a].pb(b),e[b].pb(a);
	}
	scanf("%s",s+1);
	diameter();
	if(!rt2){
		dfs(rt,0);
		ans+=max(0,d[rt]-f[rt]);
	}
	else{
		dfs(rt,rt2);
		ans+=max(0,d[rt]-f[rt]+1);
		dfs(rt2,rt);
		ans+=max(0,d[rt2]-f[rt2]+1);
	}
	cout<<ans+1<<endl;
	return 0;
}

Measured memory_bytes: 22504
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,k]=i2()
x=[]
y=[]
zz=[]
for i in range(n):
 z=i2()
 x.append([z[0],i])
 y.append([z[1],i])
 zz.append(z)
x.sort()
y.sort()
xx=[i[1] for i in x]
yy=[i[1] for i in y]
a=float("inf")
for i in range(n):
 for j in range(i,n):
  for kk in range(n):
   for l in range(kk,n):
     if len(set(xx[i:j+1])&set(yy[kk:l+1]))==k:
         a=min(a,(zz[xx[j]][0]-zz[xx[i]][0])*(zz[yy[l]][1]-zz[yy[kk]][1]))
print(a)

Measured memory_bytes: 48732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        long N = cin.nextLong();
        long ans=0;
        if(N%2==0)ans=N;
       else ans=2*N;
      Console.WriteLine(ans);
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
input = input()

arr = input.split(" ")
N = int(arr[0])
K = int(arr[1])

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

R = Base_10_to_n(N, K)

print(len(str(R)))

Measured memory_bytes: 3064
using System;


namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string ABC = Console.ReadLine();
            string[] WHxyr = (ABC.Split(' '));
            int W = int.Parse(WHxyr[0]);
            int H = int.Parse(WHxyr[1]);
            int x = int.Parse(WHxyr[2]);
            int y = int.Parse(WHxyr[3]);
            int r = int.Parse(WHxyr[4]);
            int t, f;

            t = x + r;
            f = y + r;
            if (0 < x && 0 < y)
            {
                if (t <= W && f <= H)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

int main() {
	
	int n,i,k;
	cin>>n;
	int arr[n][3],dp[n][3];
	for(i=0;i<n;i++)
    	cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	
	
	for(i=0;i<n;i++)
	{
	    if(i==0)
	    {
	        dp[i][0]=arr[i][0];
	        dp[i][1]=arr[i][1];
	        dp[i][2]=arr[i][2];
	    }
	    else
	    {
	        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i][0];
	        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
	        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+arr[i][2];
	    }
	    
	}
	cout<<max(dp[n-1][0],max(dp[n-1][2],dp[n-1][1]))<<endl;
	
	return 0;
}

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

using namespace std;

int main() {
	int n, m, c, r = 0, b[22];
	cin >> n >> m >> c;
	for (int i = 0; i < m; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++) {
		int d = c;
		for (int j = 0; j < m; j++) {
			int a;
			cin >> a;
			d += a * b[j];
		}
		if (d > 0) r++;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  rep(i,20){
    ll a;cin>>a;
    if(a==0) return 0;
    vector<ll> v(a);
    rep(j,a) cin>>v[j];
    sort(ALL(v));
    cout<<(Svec(v)-v[a-1]-v[0])/(a-2)<<endl;
  }
}


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

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char ch;


		try {

			String inputed = br.readLine();

			for(int i = 0; i < inputed.length(); i++){
				ch = inputed.charAt(i);

				if(ch >= 'a' && ch <= 'z'){
					System.out.print((char)(ch-32));
				}else if(ch >= 'A' && ch <= 'Z'){
					System.out.print((char)(ch+32));
				}else{
					System.out.print((char)ch);
				}
			}
			System.out.printf("\n");

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


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

int main() {
    string S, T;
    int count = 0;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++){
        if (S[i] != T[i]){
            count++;
        }
    }
    cout << S.size() - count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n; cin >> n;
    vector<int>x(n),y(n),h(n);
    rep(i,n){
        cin >> x[i] >> y[i] >> h[i];
    }
    vector<piii>candidate;
    rep(cx,101)rep(cy,101){
        bool exist = false;
        bool valid = true;
        int th = -INF;
        rep(i,n){
            if(th == -INF and h[i] > 0){
                th = h[i] + abs(cx -x[i]) + abs(cy - y[i]);
                exist = true;
            } else if(exist and h[i] > 0){
                if(th != h[i] + abs(cx-x[i]) + abs(cy -y[i]))
                    valid = false;
            }
        }
        if(valid and th >= 1 and exist){
            candidate.push_back(piii(cx,pii(cy,th)));
        }
    }
    for(auto && itr :candidate ) {
        int cx = itr.first;
        int cy = itr.second.first;
        int th = itr.second.second;
        bool valid = true;
        rep(i,n){
            valid = (h[i] == max(0LL,th - abs(x[i] - cx) - abs(y[i] - cy)));
            if(!valid)break;
        }
        if(valid)return cout << cx << " " << cy << " " << th << endl,0;
    }
}





Measured memory_bytes: 704
#include <cstdio>       //SPFA
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int MaxN = 1000000;
typedef long long LL;
int n, m, all;
int pre[MaxN + 5], last[MaxN + 5], other[MaxN + 5], cost[MaxN + 5];
LL	dis[MaxN + 5], seq[MaxN + 5];
bool Inque[MaxN + 5];

void Build(int x, int y, int w)
{
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
	cost[all] = w;
}

void Bfs(int s)
{
	int head = 1, tail = 1, now, ed, dr;
	seq[tail] = s;
	for(int i = 1; i <= n; i++)
	{
		if(i == s) dis[i] = 0;
		else dis[i] = 1ll << 60;
	}
	Inque[s] = 1;
	while(head <= tail)
	{
		now = seq[head];
		ed = last[now];
		while(ed != -1)
		{
			dr = other[ed];
			if(dis[now] + cost[ed] < dis[dr])
			{
				dis[dr] = dis[now] + cost[ed];
				if(!Inque[dr])
				{
					Inque[dr] = 1;
					seq[++tail] = dr;
				}
			}
			ed = pre[ed];
		}
		Inque[now] = 0;
		head++;
	}
}

int main()
{
	all = -1;
	memset(last, -1, sizeof(last));
	scanf("%d", &n);
	for(int i = 1; i <= n-1; i++)
	{
		int a, b, w;
		scanf("%d%d%d", &a, &b, &w);
		Build(a, b, w); Build(b, a, w);
	}
	memset(seq, 0, sizeof(seq));
	memset(Inque, 0, sizeof(Inque));
	int q,k;
	scanf("%d%d",&q,&k);
	Bfs(k);
	for (int i = 1; i <= q; i++)
	{
		int h,j;
		scanf("%d %d",&h,&j);
		printf("%lld\n",dis[h]+dis[j]);
	}
}

Measured memory_bytes: 24192
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

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;
}
using Graph = vector<vector<int> >;//隣接リスト
 
vector<bool> seen;
void dfs(Graph &G, int v) {
    seen[v] = true;
    for (auto next_v: G[v]) {
        if (seen[next_v]) continue;
        dfs(G, next_v);
    }
}

int main() {
    ll N, M;
    cin >> N >> M;

    vl H(N+1);
    rep(i, 1, N+1) {
        cin >> H[i];
    }

    Graph G(N+1);

    for (int i = 0; i < M; ++i) {
        ll a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    ll ans = 0;
    rep(i, 1, N+1) {
        bool flag = true;
        rep(j, 0, G[i].size()) {
            if (H[i] > H[G[i][j]]) {
            } else {
                flag = false;
                break;
            }
        }
        if (flag) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9064
while true
        n = STDIN.gets.chomp.to_i
        break if n == 0
        s = STDIN.gets.split(' ').collect {|v| v.to_f}
        m = s.inject(:+) / n
        alpha = 0.0
        s.each {|v|
                alpha += (v - m) ** 2
        }
        puts Math.sqrt(alpha / n)
end

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

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

using ll = long long int;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VB = vector<bool>;
using VVB = vector<VB>;




int main(){
  string s;
  bool p, q, ans;
  cin >> s;
  p = (s.length() % 2 == 0);
  q = (s.front() == s.back());
  ans = (p == q);
  if(ans) puts("First");
  else puts("Second");
  return 0;
}

Measured memory_bytes: 512
#!/mnt/c/Users/moiki/bash/env/bin/python
# FROM : https://atcoder.jp/contests/abc111/submissions/4032175

N = int(input())
targets = [ list(map(int, input().split())) for _ in range(N)]

mod_1st = sum(targets[0]) % 2 
if not all( sum(t) %2 == mod_1st for t in targets[1:]):
    print(-1)
    exit(0)

# if mod == 1, m = 31, di = 2^(i-1), 
# if mod == 0, m = 32, di = 2^(i-1), d32 = 1

# num of arms

mod = mod_1st
print(33 - mod)  # 33 or 32 
D = [2**i for i in range(31, -1, -1)] # 32
if mod == 0:
    D.append(1)
print(' '.join(map(str, D)))
# ----
for (x,y) in targets:
    temp = []
    for d in D:
        if x >= y and x+y >= 0:
            temp.append("R")
            x -= d
        elif x < y and x + y >= 0:
            temp.append("U")
            y -= d
        elif x >= y and x + y  <0 :
            temp.append("D")
            y += d
        else:
            temp.append("L")
            x += d
    print(''.join(temp))
            
    



Measured memory_bytes: 43248
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
//#include <ostream>


using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  ll X;
  cin >> X;
  ll ans = 0;
  for(int i = 0;i <= X/500;i++){
    ans = max(ans,1000*i+((X-500*i)/5)*5);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
  
     string n;

     cin >> n;

  //   cout << n << endl;
     
    int ans = 0;
    for(int i = 0;i<n.size();i++){
      int a = n[i]-'0';
      ans = ans + a;

    }
  
 // cout << ans << endl;
  int num = atoi(n.c_str());
  
  if(num%ans==0){
     cout << "Yes" << endl;
  }else{
     cout << "No" << endl;
  }

  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   int n;
   cin >> n;
   vector<bool> isprime(2*n,true);
   for(int i = 2;i*i<2*n;i++)
   {
      for(int j = i*2;j<2*n;j+=i)
      {
         isprime[j]=false;
      }
   }

   for(int i=n;;i++)
   {
      if(isprime[i]==true)
      {
         cout<<i<<endl;
         return 0;
      }
   }
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
ans = []
for i in range(n, 0, -1):
    temp = sum(b[i - 1:n:i]) % 2
    if temp != a[i - 1]:
        b[i - 1] = 1
    if b[i - 1] == 1:
        ans.append(str(i))
print(len(ans))
if len(ans) > 0:
    print(" ".join(ans))

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

#define LL long long
#define lowbit(x) (x&-x)
#define PLL pair<LL,LL>
#define PII pair<int,int>

#define MAXN 100000
int N,M;
struct node{
    int u,v,id,dir;
}Edge[MAXN+5];
vector<node> G[MAXN+5];
vector<PII> ans;

int out[MAXN+5];
int dep[MAXN+5];
int faID[MAXN+5];
bool dfs(int u,int fa,int d){
    out[u]=0;
    dep[u]=d;
    for(int i=0;i<int(G[u].size());i++){
        int v=G[u][i].v,k=G[u][i].id;
        if(v!=fa&&dep[v]<dep[u]){
            Edge[k].dir=Edge[k].u==u;
            faID[v]=k;
            if(out[v]==-1){
                if(!dfs(v,u,d+1))
                    out[u]++,ans.push_back(make_pair(u,v));
                else
                    out[v]++,ans.push_back(make_pair(v,u));
            }
            else
                out[u]++,ans.push_back(make_pair(u,v));
        }
    }
    if(out[u]%2){
        int f=faID[u];
        Edge[f].dir=!Edge[f].dir;
        return 1;
    }
    return 0;
}

int main(){
    scanf("%d%d",&N,&M);
    int cnt=0;
    for(int i=1;i<=M;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back((node){u,v,i,0});
        G[v].push_back((node){v,u,i,0});
        Edge[i]=(node){u,v,i,0};
    }
    memset(out,-1,sizeof out);
    dfs(1,-1,1);
    if(out[1]%2)
        return puts("-1"),0;
        /*
    for(int i=1;i<=M;i++){
        if(Edge[i].dir==1)
            print<int>(Edge[i].u,' '),print<int>(Edge[i].v,'\n');
        else
            print<int>(Edge[i].v,' '),print<int>(Edge[i].u,'\n');
    }
    */
    for(int i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
}


Measured memory_bytes: 23028