akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  int n;
  cin >> n;
  string s,f="Yes";
  cin >> s;
  if(n%2==1)f="No";
  else{
    rep(i,n/2){
      if(s[i]!=s[i+n/2])f="No";
    }
  }
  cout << f;
}




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

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    if((100*r + 10*g + b) % 4 == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h1,m1,h2,m2,k;cin>>h1>>m1>>h2>>m2>>k;
    cout<<(h2-h1)*60+(m2-m1)-k;

    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define int long long int
#define rep(a,b,c) for(int a=b;a<c;++a)
using namespace std;
const int Mod = 1000000007;
int n,m,a;
signed main(){
    cin >> n >> m;
    int sum = 0,sumy = 0;
    rep(i,0,n){
        cin >> a;
        sum += a*(i+i-n+1);
        sum%=Mod;
    }
    rep(i,0,m){
        cin >> a;
        sumy += a*(i+i-m+1);
        sumy%=Mod;
    }
    cout << (sum*sumy)%Mod << endl;
    return 0;
}


Measured memory_bytes: 256
x1,y1,x2,y2 = map(int,input().split())
vec = (y1-y2,x2-x1)
x3,y3 = x2+vec[0],y2+vec[1]
vec1 = (y2-y3,x3-x2)
x4,y4 = x3+vec1[0],y3+vec1[1]
print(x3,y3,x4,y4)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846



int main(){
	vector< pair<ll,ll> > v;
	ll n,k,i,j,a,b;
	cin>>n>>k;
	loop(i,0,n){
		cin>>a>>b;
		v.push_back(make_pair(a,b));
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	ll sum=0;
	i=0;
	while((sum+v.back().second)<k){
		sum+=v.back().second;
		v.pop_back();
		i++;
	}
	cout<<v.back().first<<endl;
}

Measured memory_bytes: 2420
class Edge():
    def __init__(self, src, to, weight):
        self.src = src
        self.to = to
        self.weight = weight

    def __lt__(self, other):
        return self.weight < other.weight

class Edges():
    def __init__(self):
        self.E = []
    
    def append(self, src, to, weight=0):
        self.E.append(Edge(src, to, weight))

    def getInOrderByASC(self):
        return sorted(self.E)

class UnionFind():
    def __init__(self, N):
        self.N = N
        self.parents = [-1]*N

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
        
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


class MinimumSpanningTree():
    def __init__(self, V, edges):
        self.V = V
        self.E = edges

    # O(E*log(V))
    def kruskal(self):
        U = UnionFind(self.V)
        total = 0
        for e in self.E.getInOrderByASC():
            if not U.same(e.src, e.to):
                total += e.weight
                U.unite(e.src, e.to)
        return total


V,E = map(int, raw_input().split())
edges = Edges()
for i in range(E):
    s,t,w = map(int, raw_input().split())
    edges.append(s,t,w)

mst = MinimumSpanningTree(V, edges)
print mst.kruskal()



Measured memory_bytes: 51580
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int m = sc.nextInt();
    int x;
    int y;
    int z;
    int as[] = new int[a];
    int bs[] = new int[b];
    int ms[] = new int[m];
    int ans ;
    int amin = 100000;
    int bmin = 100000;
    
    for(int i = 0; i < a;i++) {
      as[i] = sc.nextInt();
      if(as[i] < amin) amin = as[i];
    }
    for(int i = 0; i < b;i++) {
      bs[i] = sc.nextInt();
      if(bs[i] < bmin) bmin = bs[i];
    }
    
    ans = amin + bmin;
    
   	for(int i = 0; i < m;i++){
      x = as[sc.nextInt()-1];
      y = bs[sc.nextInt()-1];
      z = x + y -sc.nextInt();
      
  	  if(z < ans) ans = z;
      	
    }
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 61396
s=input()
if s=='SUN':
  print(7)

if s=='MON':
  print(6)

if s=='TUE':
  print(5)

if s=='WED':
  print(4)

if s=='THU':
  print(3)

if s=='FRI':
  print(2)

if s=='SAT':
  print(1)

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int>a(n);
  int left=0, right=0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    right = max(right, a[i]);
  }
  int mid;
  while(right-left>1){
    mid = (right+left)/2;
    long cut=0;
    for(int i=0; i<n; i++){
      cut += (a[i]%mid==0 ? a[i]/mid-1 : a[i]/mid);
    }
    if(cut<=k)right = mid;
    else left = mid;
  }
  cout << right;
  return 0;
}
    


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

using namespace std;

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();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;


struct  dice {
	public :
	int u,f,r;
	int up(){return u;}
	int down(){return 7-u;}
	int right(){return r;}
	int left(){return 7-r;}
	int front(){return f;}
	int back(){return 7-f;}
	void tofront(){ swap(f,u);u=7-u;};
	void toback(){ tofront(),tofront(),tofront();};
	void toright(){ swap(r,u);u=7-u;}
	void toleft(){ toright(),toright(),toright();};
};

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

stack<dice> table [210][210];

int main(void){
	int n;
	while(cin >> n,n){
		rep(i,210)rep(j,210) while(!table[i][j].empty())table[i][j].pop();
		rep(i,n){
			int u,f;
			cin >> u >> f;
			int x=100,y=100;
			dice cur; cur.u=1; cur.f=3; cur.r=5;
			rep(loop,4){
				if(u==cur.up())
					break;
				cur.tofront();
			}
			rep(loop,4){
				if(u==cur.up())
					break;
				cur.toright();
			}
			rep(loop,4){
				if(f==cur.front())
					break;
				cur.tofront();
				cur.toright();
				cur.toback();
			}

			table[x][y].push(cur);
			while(1){
				int d=-1;
				int cmax=-1;
				int c=table[x][y].size();
				if(cur.front()>=4&&cur.front()>cmax&&(c-(int)table[x+dx[0]][y+dy[0]].size())>=2){
					cmax=cur.front();
					d=0;
				}
				if(cur.back()>=4&&cur.back()>cmax&&(c-(int)table[x+dx[1]][y+dy[1]].size())>=2){
					cmax=cur.back();
					d=1;
				}
				if(cur.right()>=4&&cur.right()>cmax&&(c-(int)table[x+dx[2]][y+dy[2]].size())>=2){
					cmax=cur.right();
					d=2;
				}
				if(cur.left()>=4&&cur.left()>cmax&&(c-(int)table[x+dx[3]][y+dy[3]].size())>=2){
					cmax=cur.left();
					d=3;
				}
				if(d==-1)
					break;
				else{
					table[x][y].pop();
					switch(d){
						case 0:
							cur.tofront();
							break;
						case 1:
							cur.toback();
							break;
						case 2:
							cur.toright();
							break;
						case 3:
							cur.toleft();
							break;
					}
					x+=dx[d]; y+=dy[d];
					table[x][y].push(cur);
				}
			}
		}

		int res[6]={0};
		rep(i,210)rep(j,210){
			if(abs(i-100)+abs(j-100) > 100)
				continue;
			if(table[i][j].size())
				res[table[i][j].top().up()-1]++;
		}
		rep(i,6)
			cout << (i?" ":"") << res[i];
		cout << endl;
	}
	return 0; 
}

Measured memory_bytes: 30132
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  ll n;
  cin>>n;
  ll re=0;
  int d=0;
  for(int m=n;m;m/=10) ++d;
  rep(i,100){
    if(!n) break;
    ll tmp=n%10;
    rep(j,i+1){
      re+=(tmp<<max(0,d-i-1))<<max(0,i-j-1);
      tmp*=10;
    }
    n/=10;
    //cout<<re<<endl;
  }
  cout<<re<<endl;
  return 0;
}


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

dp = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
    s = str(i)
    dp[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += dp[i][j] * dp[j][i]
print(ans)

Measured memory_bytes: 40428
#include <stdio.h>

int main(void) {

	int i;
	int a, b;

	scanf("%d %d", &a, &b);

	if (a > b)			printf("a > b\n");
	else if (a < b)		printf("a < b\n");
	else if (a == b)	printf("a == b\n");

	return 0;
}

Measured memory_bytes: 2676
#include<stdio.h>
//#define ll long long
int main(){
	int n,d[50];
	int sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&d[i]);
	}
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			sum+=(d[i]*d[j]);
		}
	}
	printf("%d",sum);
	return 0;
}

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

using namespace std;

int N, ans = 0;

void print_array(vector<vector<int> > v){
  for(int i = 0;i < N;i++){
    cout << v.at(i).at(0) << " " << v.at(i).at(1) << endl;
  }
}

int main(int argc, char *argv[])
{
  bool flag = false;
  cin >> N;
  vector<vector<int> > D(N, vector<int>(N));
  for(int i = 0; i < N; i++){
    cin >> D.at(i).at(0) >> D.at(i).at(1);
  }
  //print_array(D);
  for(int i = 0;i < N;i++){
    //cout << D.at(i).at(0) << " " << D.at(i).at(1) << endl;
    //cout << ans << endl;
    if(D.at(i).at(0) == D.at(i).at(1)){
      ans+=1;
    }
    else{
      ans = 0;
    }
    if(ans == 3){
      flag  = true;
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3580
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{

    struct Node
    {
        public int depth;
        public List<int> son;
        public int p;
        public string type;
    }


    class Program
    {

        static int v;

        static void Depth(int k, Node[] a)
        {
            if(a[k].p == -1)
            {
                return;
            }
            else
            {
                k = a[k].p;
                v++;
                Depth(k, a);
                return;
            }
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            Node[] a = new Node[n];

            //sonのインタスンスを作る
            for(int i = 0; i < n; i++)
            {
                a[i].son = new List<int>();
                a[i].p = -1;
            }

            for(int i= 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int id = int.Parse(input[0]);
                int k = int.Parse(input[1]);
                

                //親子関係、pとson
                for(int j = 2; j < k + 2; j++)
                {
                    int s = int.Parse(input[j]);
                    a[s].p = id;                                     
                    a[id].son.Add(s);                   
                }    
            }
        
            //nodeの種類を割り当てる
            for (int i = 0; i < n; i++)
            {
                if (a[i].p == -1)
                {
                    a[i].type = "root";
                }
                else if (a[i].son.Count == 0)
                {
                    a[i].type = "leaf";
                }
                else
                {
                    a[i].type = "internal node";
                }
            }


            for(int i = 0; i < n; i++)
            {
                v = 0;
                Depth(i, a);
                a[i].depth = v;
            }

            for(int i = 0; i < n; i++)
            {
                Console.WriteLine($"node {i}: parent = {a[i].p}, depth = {a[i].depth}, {a[i].type}, [" + String.Join(", ", a[i].son) + "]");

            }

        }
    }
}



Measured memory_bytes: 38048
#include <iostream>

int GCD(int a, int b)
{
    if (a < b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }
    int r = 1;

    while (r != 0)
    {
        r = a % b;
        a = b;
        b = r;
    }

    return a;
}

int main()
{
    int a, b;
    std::cin >> a >> b;

    std::cout << GCD(a, b) << std::endl;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ka = a;
  rep(i, 0, 101) {
    if(ka % b == c) {
      cout << "YES" << endl;
      return 0;
    }
    ka += a;
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

Alice, Bob = 0, 0

for i in range(N):
  if i % 2 == 0:
    Alice += a.pop(a.index(max(a)))
  else:
    Bob += a.pop(a.index(max(a)))
    
ans = abs(Alice - Bob)

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	ll a, b;
	cin >> a >> b;
	ll gcd;
	for (int i = min(a, b); i >= 1; i--) {
		if (a%i == 0 && b%i == 0) {
			gcd = i;
			break;
		}
	}
	a /= gcd;
	b /= gcd;
	cout << gcd*a*b << endl;
}

Measured memory_bytes: 256
#include<stdlib.h>

int main(void){
	int count, count1, num, num1 = 0, num2 = 0, num3 = 0, i;
	int hill[10] = { '0' }, ans[3] = { '0' };

	for (count = 0; count < 10; count++){
		scanf("%d", &hill[count]);
	}

	for (count = 0; count < 10; count++){
		if (num1 < hill[count]){
			num1 = hill[count];
			num = count;
		}
	}
	hill[num] = 0;

	for (count = 0; count < 10; count++){
		if (num2 < hill[count]){
			num2 = hill[count];
			num = count;
		}
	}
	hill[num] = 0;

	for (count = 0; count < 10; count++){
		if (num3 < hill[count]){
			num3 = hill[count];
			num = count;
		}
	}

	printf("%d\n%d\n%d\n", num1, num2, num3);

	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
    public static void abc173_a() {
        try (Scanner sc = new Scanner(System.in)) {
            int a = Integer.parseInt(sc.next());
            int change = a % 1000;
            if (change == 0)
                System.out.println(0);
            else
                System.out.println(1000 - change);
        }
    }


    public static void main(String[] args) {
        abc173_a();
    }
}

Measured memory_bytes: 35728
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <iomanip>
#include <numeric>
#include <bitset>

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

using namespace std;

typedef long long ll;

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
  return x/gcd(x, y)*y;
}

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

  ll a, b; cin >> a >> b;
  cout << lcm(a, b) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n); i++)
#define sz(x) int(x.size())
using namespace std;


int main(){
    int n, k, q;
    int point[100005];


    cin >> n >> k >> q;

    rep(i, n+1)point[i] = 0;

    rep(i, q){
        int temp;
        cin >> temp;
        point[temp+1]++;
    }

    for(int i = 1; i < n+1; i++){
        cout << (k-(q-point[i+1])>0 ? "Yes" : "No") << endl;
    }

    return 0;
}


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

int main(){
    int n, res = 0;
    cin>>n;
    while(n != 0){
        int r = n % 10;
        if( r == 7){
            res = 1;
            break;
        }
        n = n / 10;
    }
    if(res)
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 3572
# coding:utf-8
# Doubly Linked List

from collections import deque

def main():

    n = int(input())
    dll = deque()

    for _ in range(n):
        operation = input().split(' ')
        if operation[0] in ["insert", "delete"]:
            key = operation[1]
            if operation[0] == "insert":
                dll.appendleft(key)
            else:
                try:
                    dll.remove(key)
                except:
                    pass

        else:
            if operation[0][6] == 'F':
                dll.popleft()

            else:
                dll.pop()

    print(' '.join(dll))

if __name__ == "__main__":
    main()

Measured memory_bytes: 71952
/*------U Have To DO It------*/
/* BY-> RicoProg */
/*        ___ 
           __|__|
          |  |___       */
#include <bits/stdc++.h>
using namespace std;
 
 
//---------------------------------------------------MACROS----------------------------------------------------------
#define ll long long
#define ld long double
#define beg(i ,n) for(ll i=0;i<n;i++)
#define beg1(i ,n) for(ll i=1;i<n;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back 
#define mp make_pair
#define nl "\n" 
#define vec(v , n) vector<ll> v(n)
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define pll pair<ll , ll>
#define mii map<int , int>
#define mll map<ll , ll>
#define msi map<string , int>
#define mci map<char , int>
#define f1 first
#define f2 second
 
//---------------------------------------------------GLOBAL----------------------------------------------------------
const ll MOD = 1e9 + 7 ;
const ll MAX = 1e5 + 7 ;
//---------------------------------------------------FUNCTIONS-------------------------------------------------------

ld p[301][301][301] , dp[301][301][301] ;
ll n ;

void solve(){
	cin >> n ;
	ll one , two , three , a ;
	one = two = three = 0 ;
	beg(i , n) cin >> a , one+=(a == 1) , two+=(a == 2) , three+=(a == 3) ;
	p[one][two][three] = 1 ;
	for(int c = three ; c>=0 ; c--){
		for(int b = two+three ; b>=0 ; b--){
			for(int a=n ; a>=0 ; a--){
				if(a==0 && b==0 && c==0){
					continue ;
				}
				if(a+b+c > n){
					continue ;
				}
				ld evs = (ld)n/(a+b+c) ;
				dp[a][b][c] += p[a][b][c] * evs ;
				if(a!=0){
					p[a-1][b][c] += p[a][b][c] * ((double)a/(double)(a+b+c)) ;
					dp[a-1][b][c] += dp[a][b][c] * ((double)a/(double)(a+b+c)) ;
				}
				if(b!=0){
					p[a+1][b-1][c] += p[a][b][c] *((double)b/(double)(a+b+c)) ;
					dp[a+1][b-1][c] += dp[a][b][c] * ((double)b/(double)(a+b+c)) ;
				}
				if(c!=0){
					p[a][b+1][c-1] += p[a][b][c] *((double)c/(double)(a+b+c)) ;
					dp[a][b+1][c-1] += dp[a][b][c] * ((double)c/(double)(a+b+c)) ;
				}
			}
		}
	}
	cout << setprecision(20) << dp[0][0][0] ;
}
//---------------------------------------------------DRIVER----------------------------------------------------------
int main()
{
    fast ;
    int t=1 ;
    //cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}	

Measured memory_bytes: 852224
#include <iostream>
#include <stdio.h>

using namespace std;

int graph[100][100];
int near[100];
bool is_not_use[100];
int n,m;
int l;

void ini(){
    l=0;
    for(int i=0; i<100; i++){
        for(int j=0; j<100; j++){
            graph[i][j]=2147483647;
        }
    }
    for(int i=0; i<100; i++){
        near[i]=2147483647;
        is_not_use[i]=true;
    }
}

void prim(){
    int v=0;
    int min_cost=2147483647-1;
    for(int i=0; i<n; i++){
        if(min_cost>near[i]&&is_not_use[i]){
            min_cost=near[i];
            v=i;
        }
    }
    is_not_use[v]=false;
    l+=min_cost;
    for(int i=0; i<n; i++){
        if(near[i]>graph[v][i]){
            near[i]=graph[v][i];
        }
    }
    bool flag=false;
    for(int i=0; i<n; i++){
        if(is_not_use[i])flag=true;
    }
    if(flag)prim();
}



int main(void)
{
    while(1){
        ini();
        cin>>n;
        if(n==0)break;
        cin>>m;
        for(int i=0; i<m; i++){
            int a,b,c;
            scanf("%d,%d,%d",&a,&b,&c);
            graph[a][b]=c;
            graph[b][a]=c;
        }
        is_not_use[0]=false;
        for(int i=0; i<n; i++){
            near[i]=graph[0][i];
        }
        prim();
        cout<<l/100-n+1<<endl;
        
        
        
    }
}

Measured memory_bytes: 1284
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}





int main(){
  int x;
  cin >> x;
  ll ans = 0;
  ans += x/500 * 1000;
  x -= x/500 * 500;
  ans += x/5 * 5;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct Sieve{
	int n;
	vector<int> f, primes;
	Sieve(int n):n(n), f(n+1){
		f[0] = f[1] = -1;
		for(long long i = 2; i <= n; i++){
			if(f[i]) continue;
			primes.push_back(i);
			f[i] = i;
			for(long long j = i*i; j <= n; j += i){
				if(!f[j]) f[j] = i;
			}
		}
	}
	bool isPrime(int x){return f[x] == x;}
	vector<int> factorList(int x){
		vector<int> res;
		while(x != 1){
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}
	vector<pair<int, int>> factor(int x){
		vector<int> fl = factorList(x);
		if(fl.size() == 0) return {};
		vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0));
		for(int p : fl){
			if(res.back().first == p){
				res.back().second++;
			}
			else{
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};

const ll mod = 1000000007;

ll mod_pow(ll x, ll n, ll mod){
	ll res = 1;
	while(n > 0){
		if(n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	Sieve sie(1e6);
	vector<ll> a(n);
	map<int, int> mp;
	rep(i,n){
		cin >> a[i];
		vector<P> fl = sie.factor(a[i]);
		for(auto p : fl){
			chmax(mp[p.first], p.second);
		}
	}
	ll lcm = 1;
	for(auto p : mp){
		rep(j,p.second){
			lcm = (lcm * p.first) % mod;
		}
	}
	ll ans = 0;
	rep(i,n){
		ll b = (lcm * mod_pow(a[i], mod-2, mod)) % mod;
		ans = (ans + b) % mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4988
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    long long N,K,S;
    cin >> N >> K >> S;
    long long a;
    if ( S == (long long)1e+9 ) { a = 1; }
    else { a = S+1; }
    for ( int i = 0; i < N; i++ ) {
        if ( i < K ) { cout << S; }
        else { cout << a; }
        if ( i != N-1 ) { cout << " "; }
    }
    return 0;
}

Measured memory_bytes: 1280
fn factorize(mut n: u64) -> Vec<u64> {
    let mut f = vec![1];
    for k in 2.. {
        if k * k > n {
            break;
        }
        if n % k == 0 {
            let mut c = 0;
            while n % k == 0 {
                n /= k;
                c += 1;
            }
            let mut next = f.clone();
            let mut mul = 1;
            for _ in 0..c {
                mul *= k;
                for &f in f.iter() {
                    next.push(f * mul);
                }
            }
            f = next;
        }
    }
    if n > 1 {
        let mut next = f.clone();
        for f in f {
            next.push(f * n);
        }
        f = next;
    }
    f
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: u64 = s.trim().parse().unwrap();
    let mut ok = vec![];
    for f in factorize(n) {
        if f <= 1 {
            continue;
        }
        let mut n = n;
        while n % f == 0 {
            n /= f;
        }
        if n % f == 1 {
            ok.push(f);
        }
    }
    for f in factorize(n - 1) {
        if f <= 1 {
            continue;
        }
        let mut n = n;
        while n % f == 0 {
            n /= f;
        }
        if n % f == 1 {
            ok.push(f);
        }
    }
    ok.sort();
    ok.dedup();
    println!("{}", ok.len());
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  string s, t = "", u = "maerd", v = "remaerd", w = "esare", x = "resare";
  int a = 0;
  cin >> s;
  rrep(i, s.size()) t += s[i];
  while(a < (int)s.size()){
    string y = "", z = "", r = "";
    rep(i, 7){
      if(a+i >= (int)s.size()) break;
      r += t[a+i];
      if(i < 5) y += t[a+i];
      if(i < 6) z += t[a+i];
    }
    if(y == u || y == w) a += 5;
    else if(z == x) a += 6;
    else if(r == v) a += 7;
    else break;
  }
  if(a < (int)s.size()) cout << "NO" << "\n";
  else cout << "YES" << "\n";
  return 0;
}

Measured memory_bytes: 512
b_list = [input() for i in range(int(input()))]
r_list = [input() for i in range(int(input()))]

ans = 0 
for i in list(set(b_list)):
  if ans <= b_list.count(i) - r_list.count(i):
    ans = b_list.count(i) - r_list.count(i)
    
print(int(ans))

Measured memory_bytes: 3064
function main(input) {
  var a = input[0]-0;
  var b = input[1]-0;
  var ans = 1;
  for(var i=0;i<a;i++){
    ans = Math.min(ans+b,ans*2);
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	long long a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	long long mul=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			mul=mul+(a[i]*a[j]);
		}
	}
	cout<<mul<<endl;
}

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

int main(){
	int R, G, B, N;
	cin >> R >> G >> B >> N;
	
	int sum = 0;
	for(int i = 0; i*R <= N; i++)
		for(int j = 0; i*R+j*G <= N; j++){
			int v = i*R+j*G;
			if((N-v)%B == 0)
				sum++;		
		}

	cout << sum << endl;
}

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

int n;
int a[100011],b[100011];
int h[100011];
int ll[100011],rr[100011];

long long MOD=1000000007;
long long ans;

int main()
{
    int i,j;
    bool gg=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
    }
    a[0]=b[n+1]=0;
    
    memset(h,0,sizeof(h));
    for(i=1;i<=n;i++)
    {
        if(a[i]!=a[i-1])
        {
            h[i]=a[i];
        }
    }
    for(i=n;i>=1;i--)
    {
        if(b[i]!=b[i+1])
        {
            if(h[i]==0 || h[i]==b[i])
            {
                h[i]=b[i];
            }
            else
            {
                gg=1;
            }
        }
        else
        {
            if(h[i]!=0 && h[i]>b[i])
            {
                gg=1;
            }
        }
    }
    
    if(gg==1)
    {
        cout<<0<<endl;
    }
    else
    {
        ans=1;
        ll[0]=rr[n+1]=0;
        for(i=1;i<=n;i++)
        {
            if(h[i]!=0)
            {
                ll[i]=h[i];
            }
            else
            {
                ll[i]=ll[i-1];
            }
        }
        
        for(i=n;i>=1;i--)
        {
            if(h[i]!=0)
            {
                rr[i]=h[i];
            }
            else
            {
                rr[i]=rr[i+1];
            }
        }
        
        for(i=1;i<=n;i++)
        {
            if(h[i]==0)
            {
                ans=ans*(long long)min(ll[i],rr[i])%MOD;
            }
        }
        
        cout<<ans<<endl;
    }
    
    
    
    return 0;
} 



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

using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (int)n; i++)

const int inf = 1000000000;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  set<int> st;
  st.insert(a);
  st.insert(b);
  st.insert(c);
  if (st.size() == 2) std::cout << "Yes" << endl;
  else std::cout << "No" << endl;
}


Measured memory_bytes: 3544
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n';
 
int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	sort(a.begin(), a.end());
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			cout << "NO"; return 0;
		}
	}
	cout << "YES";
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  for(;;){
    int r,a;
    cin >> r >> a;
    if(r == 0 && a == 0) break;
    char sr[5],sa[5];
    sprintf(sr,"%04d",r);
    sprintf(sa,"%04d",a);
    int hit = 0,blow = 0;
    for(int i=0; i<4; i++){
      for(int j=0; j<4; j++){
        if(sr[i] == sa[j]){
          if(i==j) hit++;
          else blow++;
          continue;
        }
      }
    }
    cout << hit << " " << blow << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);    
    int N, T; cin >> N >> T;
    int t[N];
    for (int i = 0; i < N; ++i){cin >> t[i];}
    long long dp[N] = {};
    dp[0] = T;
    for (int i = 0; i < N; ++i) {(t[i + 1] - t[i] >= T) ? dp[i + 1] = dp[i] + T : dp[i + 1] = dp[i] + t[i + 1] - t[i];}
    cout << dp[N - 1] << '\n';
    return 0;
}

Measured memory_bytes: 2560
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String X = sc.next();
  String Y = sc.next();
  int a = Integer.parseInt(X,16);
  int b = Integer.parseInt(Y,16);
  if(a > b)System.out.println(">");
  else if(a == b)System.out.println("=");
  else System.out.println("<");
}
}
                     

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

typedef bool B;
typedef long double D;
typedef complex<D> P;
typedef vector<P> VP;
typedef struct {P s,t;} L;
typedef vector<L> VL;
typedef struct {P c;D r;} C;
typedef vector <C> VC;

const D eps=1.0e-10;
const D pi=acos(-1.0);
template<class T> bool operator==(T a, T b){return abs(a-b)< eps;}
template<class T> bool operator< (T a, T b){return a < b-eps;}
template<class T> bool operator<=(T a, T b){return a < b+eps;}
template<class T> int sig(T r) {return (r==0||r==-0) ? 0 : r > 0 ? 1 : -1;}
#define X real()
#define Y imag()

D ip(P a, P b) {return a.X * b.X + a.Y * b.Y;}
D ep(P a, P b) {return a.X * b.Y - a.Y * b.X;}
D sq(D a) {return sqrt(max(a, (D)0));}
P vec(L l){return l.t-l.s;}
inline P input(){D x,y;cin >> x >> y; return P(x,y);}
// ???????????¬????????¨???

// ???????????? verify AOJ CGL_1_C
enum CCW{
	LEFT = 1,
	RIGHT = 2,
	BACK = 4,
	FRONT = 8,
	MID = 16,
	ON=FRONT|BACK|MID
};

inline int ccw(P base, P a, P b) {              //???a??¨???b???????????????????????????
	a -= base; b -= base;
	if (ep(a, b) > 0)
		return LEFT;    // counter clockwise
	if (ep(a, b) < 0)
		return RIGHT;   // clockwise
	if (ip(a, b) < 0)
		return BACK;    // b--base--a on line
	if (norm(a) < norm(b))
		return FRONT;   // base--a--b on line
	// otherwise
	return MID;      // base--b--a on line  a??¨b????????????????????????
}



// ??????????????????
inline B cmp_x(const P &a,const P &b){
	return (abs(a.X-b.X)<eps ) ?  a.Y<b.Y : a.X<b.X;
}  // base x
inline B cmp_y(const P &a,const P &b){
	return (abs(a.Y-b.Y)<eps ) ?  a.X<b.X : a.Y<b.Y;
}  // base y
inline B cmp_a(const P &a,const P &b){
	return (abs(arg(a)-arg(b))<eps ) ?  norm(a) < norm(b) : arg(a)<arg(b);
} // base arg

// ????§???¢

// convex_hull
// Verify AOJ 0063

VP convex_hull(VP pol){
	int n=pol.size(),k=0;
	sort(pol.begin(),pol.end(),cmp_y);
	VP res(2*n);

	//??\??????while?????????????????????
	//????????????????????????????????????????????´??????<=0
	//???????????????????????????????????????????????´??????<0

	// down
	rep(i,n){
		while( k>1 && ep(res[k-1]-res[k-2],pol[i]-res[k-1])<0) k--;
		res[k++]=pol[i];
	}
	// up
	for(int i=n-2,t=k;i>=0;i--){
		while( k>t && ep(res[k-1]-res[k-2],pol[i]-res[k-1])<0) k--;
		res[k++]=pol[i];
	}
	res.resize(k-1);
	return res;
}

int main(void){
	int n;
	cin >> n;
	VP pol;
	rep(i,n) pol.push_back(input());
	VP res=convex_hull(pol);
	int m=res.size();

	cout << m << endl;
	rep(i,m){
		int x=res[i].X,y=res[i].Y;
		cout << x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 14380
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n,ans=-INF,maxi,sol;
string s;
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='W')
		sol--;
		else
		sol++;
		if(sol>ans){
			ans=sol;
			maxi=i;
		}
	}
	ans=0;
	for(int i=0;i<maxi;i++){
		if(s[i]=='W')
		ans++;
	}
	for(int i=maxi+1;i<s.size();i++){
		if(s[i]=='E')
		ans++;
	}
	cout<<ans;
	//system("pause");
	return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, c;
  cin >> n >> c;
  vl x(n), y(n), u(n), s(n + 1, 0), t(n + 1, 0);
  rep(i, n) {
    cin >> x[i] >> u[i];
    y[i] = c - x[i];
  }
  vl v = u;
  reverse(all(y));
  reverse(all(v));
  rep(i, n) {
    s[i + 1] = s[i] + u[i];
    t[i + 1] = t[i] + v[i];
  }
  rep(i, n) {
    s[i + 1] -= x[i];
    t[i + 1] -= y[i];
  }
  ll ans = 0;
  rep(_, 2) {
    set<ll, greater<ll>> st;
    for(int i = n; i >= 1; i--) {
      st.insert(t[n - i]);
      ans = max(ans, s[i]);
      ll now = s[i] + *st.begin();
      ans = max(ans, now - x[i - 1]);
    }
    swap(s, t);
    swap(x, y);
  }
  cout << ans << endl;
}

Measured memory_bytes: 12768
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N=1e6+5;
struct node{
    int u,v,nxt;
}edge[N];
int head[N],mcnt;
void add_edge(int u,int v){
    mcnt++;
    edge[mcnt].u=u;
    edge[mcnt].v=v;
    edge[mcnt].nxt=head[u];
    head[u]=mcnt;
}
int n;
int sz[N];
bool dfs(int u,int fa){
    sz[u]=1;
    int cnt=0;
    for(int i=head[u];i;i=edge[i].nxt){
        int v=edge[i].v;
        if(v==fa)
            continue;
        if(dfs(v,u))
            return true;
        if(sz[v]){
            cnt++;
            sz[u]=0;
            if(cnt==2)
                return true;
        }
    }
    return false;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        add_edge(u,v);
        add_edge(v,u);
    }
    puts(dfs(1,0)||sz[1]?"First":"Second");
}


Measured memory_bytes: 8704
N=int(input())
l,r=0,N
print(0)
s=input()
ls=s
if s!='Vacant':
    for i in range(19):
        x=l+(r-l)//2
        print(x)
        s=input()
        if s=='Vacant':
            break
        elif (x-l)%2==0 and s==ls or (x-l)%2==1 and s!=ls:
            l=x
            ls=s
        else:
            r=x


Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


i64 n, a[303030];
i64 d[101];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 61; j++){
			if((a[i] >> j) & 1) d[j]++;
		}
	}
	
	i64 ans = 0;
	for(int i = 0; i < 61; i++){
		ans += ((d[i] * (n-d[i]) % INF) * ((1LL << i) % INF)) % INF;
		ans %= INF;
	}
	cout << ans << endl;
	
	return 0;
}

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

int main(){
  int x, y, ans;
  cin >> x >> y;
  if(x >= 0 && y >= 0){
    if(y == 0) cout << x + 1 << endl;
    else if(x > y) cout << x - y + 2 << endl;
    else cout << y - x << endl;
  }
  if(x >= 0 && y < 0){
    if(x >= -y) cout << x + y + 1 << endl;
    else cout << -y - x + 1 << endl;
  }
  if(x < 0 && y >= 0){
    if(y == 0) cout << -x << endl;
    else if(-x >= y) cout << -x - y + 1 << endl;
    else cout << y + x + 1 << endl;
  }
  if(x < 0 && y < 0){
    if(-x >= -y) cout << y - x << endl;
    else cout << 2 + x - y << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>

using namespace std;

int main() {
	double a, b, c, d, e, f;
	while (cin >> a >> b >> c >> d >> e >> f) {
		auto x = (e*c - b*f) / (a*e - b*d);
		auto y = (a*f - c*d) / (a*e - b*d);
		if (x == -0.) {
			x = 0.;
		}
		if (y == -0.) {
			y = 0.;
		}
		printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 1228
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int a, b, c, d, e, f;
  scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
  int anssw = 0, anss = 0;
  double conct = 0;
  for (int i=0; i<=f; i+=100*a) {
    for (int j=0; j<=f-i; j+=100*b) {
      for (int k=0; k<=f-i-j; k+=c) {
        if ((i+j)/100 * e < k)
          break;
        for (int l=0; l<=f-i-j-k; l+=d) {
          if ((i+j)/100 * e < k + l)
            break;
          double tmp = 100.00*(k+l)/(i+j+k+l);
          if (conct < tmp) {
            conct = tmp;
            anssw = i+j+k+l;
            anss = k+l;
          }
        }
      }
    }
  }
  if (anssw == 0)
    anssw = 100*a;
  printf("%d %d\n", anssw, anss);
  return 0;
}


Measured memory_bytes: 128
def find(x):
    if par[x] == x:
        return x
    else:
        return find(par[x])

def unite(x, y):
    x = find(x)
    y = find(y)

    if x != y:
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1

def same(x, y):
    return find(x) == find(y)

#初期化
n, m = map(int, input().split())
par = [0]*n
for i in range(n):
    par[i] = i #まず全ての値を根に置く
rank = [1]*n #深さ
size = [1]*n #根iにおけるグループサイズ

edge = [tuple(map(int, input().split())) for i in range(m)]
edge = edge[::-1]
for i in range(m):
    edge[i] = (edge[i][0]-1, edge[i][1]-1)

res = []
for i in range(m):
    fi = find(edge[i][0])
    se = find(edge[i][1])
    if fi == se:
        res.append(0)
    else:
        res.append(size[fi]*size[se])
        unite(fi, se)
ass = 0
for i in range(m):
    ass += res[m-1-i]
    print(ass)



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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 1152
N = int(input())
S = input()

from itertools import product

p = product([str(i) for i in range(10)], repeat=3)

ans = 0
for i,j,k in p:
  x = S.find(i)
  if x<0:
    continue
  y = S[x+1:].find(j)
  if y<0:
    continue
  z = S[x+y+2:].find(k)
  if z<0:
    continue
  #print(i,j,k, S, S[x+1:],S[x+y+2:])
  ans += 1
print(ans)
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
int copy(int const x){
	return x;
}

int main(){
	int n;cin>>n;
	vector<vector<int>> a(n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n - 1; j++) {
			int x;cin>>x;x--;a[i].pb(x);
		}
		a[i].pb(-1);
	}
	vector<int> now(n);
	vector<int> cnt(n,0);
	vector<bool> used(n,false);
	queue<int> q;
	for(int i = 0; i < n; i++) {
		now[i] = a[i][0]; 
		q.push(i);
	}
	int i = 0;
	int ans = 0;
	while(i <= n * (n - 1) / 2){
		i++;
		bool flag = true;
		int q_size = q.size();
		int j = 0;
		while(j < q_size) {
			int top = q.front();
			q.pop();
			if (now[top] != -1 && now[now[top]] == top && used[now[top]] == false && used[top] == false){//やりたい同士のとき
				int tmp = copy(now[top]);
				cnt[top]++;
				cnt[tmp]++;
				now[top] = a[top][cnt[top]];
				now[tmp] = a[tmp][cnt[tmp]];
				used[top] = true;
				used[tmp] =true;
				q.push(top);
				q.push(tmp);
				// for(int i = 0; i < n; i++) {
				// 	cout << now[top] << endl;
				// }
			}
			j++;
		}
		for(int i = 0; i < n; i++) {
				used[i] = false;
				}
			for(int i = 0; i < n; i++) {
				if (now[i] != -1){
					flag = false;
				}
			}
			ans++;
			if (flag){
				cout << ans << endl;
				return 0;
			}
		
	}
	
	for(int i = 0; i < n; i++) {
		if (now[i] != -1){
			cout << -1 << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 4352