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

using namespace std;

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

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	
	auto calc = [&](ll x){
		ll sum = 0;
		rep(i, n){
			//ai - k*n + x - k <= n - 1
			ll k = (a[i] + x + 1) / (n + 1);
			sum += k;
		}
		return sum;
	};
	
	ll lo = -1, hi = accumulate(all(a), n - 1ll) / n, mid;
	while(lo + 1 < hi){
		mid = (lo + hi) / 2;
		if(calc(n * mid) <= n * mid) hi = mid;
		else lo = mid;
	}
	/*
	ll ans = n * lo;
	while(calc(ans) != ans) ans++;
	while(ans >= n && calc(ans - n) == ans - n) ans -= n;
	
	for(ll i = ans - 10; i <= ans + 10; i++) dbg(i, calc(i));
	cout << ans << endl;
	*/
	for(ll a = max(0ll, n * lo - 1000); a <= n * lo + 1000; a++){
		if(calc(a) == a){
			cout << a << endl;
			return 0;
		}
	}
	assert(0);
	
	return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long int N;
    cin>>N;
    vector<int> ans;
    long long int total = 0, div3 = 0, div5 = 0, div15 = 0;
    long long int n3 = (int)N/3, n5 = (int)N/5, n15 = (int)N/15;
    total = ((1+N)*N)/2;
    if(N >= 3)
        div3 = ((3 + n3*3)*n3)/2;
    if(N >= 5)
        div5 = ((5 + n5*5)*n5)/2;
    if(N >= 15)
        div15 = ((15 + n15*15)*n15)/2;

    // cout<<total<<" "<<div3<<" "<<div5<<" "<<div15<<endl;
    cout<<total-div3-div5+div15<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,i,ans=0;
  cin>>n>>m;
  vector<int> x(m),d(m-1);
  for(i=0;i<m;i++) cin>>x.at(i);
  sort(x.begin(),x.end());
  for(i=0;i<m-1;i++) d.at(i)=x.at(i+1)-x.at(i);
  sort(d.begin(),d.end());
  for(i=0;i<m-n;i++) ans+=d.at(i);
  cout<<ans<<endl;
}

Measured memory_bytes: 3976
s = input()
dic = {"A", "T", "C", "G"}

k = [1 if s[i] in dic else 0 for i in range(len(s))]

result = []
for i in range(len(k)):
    cnt = 0
    if k[i] == 1:
        cnt = 1
        j = i-1
        while j >= 0:
            if k[j] == 1:
                cnt += 1
                j -= 1
            else:
                break
    result.append(cnt)

print(max(result))




Measured memory_bytes: 9056
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i;
    cin>>a>>b;
    string s[100];

    for(i=0; i<a; i++)
    {
        cin>>s[i];
    }
    sort(s,s+a);

    for(i=0; i<a; i++)
    {
        cout<<s[i];
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N ;
  int A,B,C,D ;
  A = N / 1000;
  B = (N  % 1000)/100;
  C = (N  % 100)/10;
  D = (N % 10);

  if ((A==B && B==C) || ( B==C && C==D) ) {
  cout << "Yes" << endl;
  }

  else {
  cout << "No" << endl;
  }
  }


Measured memory_bytes: 256
S = input()

op_cnt = len(S) - 1#数字の間の数

ans = 0

for i in range(2 ** op_cnt):
  sign = [""] * op_cnt
  for j in range(op_cnt):
    if ((i>>j)&1):
      sign[j] = "+"
       
  formula = ""      
  for k in range(op_cnt):
    formula += S[k] + sign[k]
  formula += S[op_cnt]
  ans += eval(formula)
print(ans)

	

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b ;
  if ((a*b)%2 == 0){
  	cout << "Even" << endl; 	 
  }
  else{
  	cout << "Odd" << endl; 	 
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
s = str(input())
r = 0
g = 0
for i in range(n):
  if s[i] == "R":
    r += 1
  elif s[i] == "G":
    g += 1
c = r*g*(n-r-g)
for j in range(1,n-1):
  for i in range(1,min(n-j-1,j)+1):
    if (s[j-i] != s[j]) and (s[j] != s[j+i]) and (s[j+i] != s[j-i]):
      c -= 1
print(c)

Measured memory_bytes: 9216
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

bool isPalindrome(string s) {
    int n = cast(int)s.length;
    for (int i = 0; i < n/2; i++) {
        if (s[i] != s[$-i-1]) return false;
    }
    return true;
}

bool calc(string s) {
    int n = cast(int)s.length;
    if (!isPalindrome(s)) return false;
    if (!isPalindrome(s[0..(n-1)/2])) return false;
    if (!isPalindrome(s[(n+3)/2-1..$])) return false;
    return true;
}

void main() {
    string s; scan(s);
    writeln(calc(s) ? "Yes" : "No");
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define F 110000
using namespace std;
 
vector<int> v[F];
int a,b,x,y,r,i;
 
int D(int t){
    int e=0;
    while(e*e<=r*r-t*t)e++;
    return e-1;
}
 
int main(){
     
    while(cin>>a>>b>>r&&a+b){
    for(int i=0;i<F;i++){
        v[i].clear();
    }
    r*=4;
    for(i=0;i<a;i++){
        cin>>x>>y;
        v[x].push_back(y);
    }
    for(i=0;i<a;i++){
        sort(v[i].begin(),v[i].end());
    }
    int n=0;
    while(b--){
        cin>>x>>y;
        for(i=max(0,x-r);i<=min(F-100,x+r);i++){
            n+=lower_bound(v[i].begin(),v[i].end(),y+D(x-i)+1)-lower_bound(v[i].begin(),v[i].end(),y-D(x-i));
        }
    }
    cout<<n<<endl;
    }
    return 0;
}

Measured memory_bytes: 6920
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

int main(int argc, char* argv[]) {

	int N,M,X,Y;
	int ans = 0;

	cin >> N >> M >> X >> Y;

	vector<int> x(N,0);
	vector<int> y(M,0);

	for(int i=0 ; i<N ; i++){
		cin >> x[i];
	}

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

	sort(x.rbegin(),x.rend());
	sort(y.begin(),y.end());

	ans = X;
	while(ans < Y){
		if(x[0] < ans && y[0] >= ans){
			break;
		}
		ans++;
	}

	if(ans < Y && ans > X && ans <=Y){
		cout << "No War" << endl;
	}else{
		cout << "War" << endl;
	}

	return 0;

}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    double l;
    cin>>l;
    double x=l/3;
    cout<<setprecision(30)<<x*x*x;




}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<ll> a(n),b(n),c(n);
    REP(i,n)cin >> a[i];
    REP(i,n)cin >> b[i];
    REP(i,n)cin >> c[i];

    sort(All(a));
    sort(All(b));
    sort(All(c));

    vector<ll> cou(n);

    for(ll i=0;i<n;i++){
        cou[i] = lower_bound(a.begin(),a.end(),b[i])-a.begin();
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        ans+=cou[i]*(n-(upper_bound(c.begin(),c.end(),b[i])-c.begin()));
    }

    cout << ans << endl;
}


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

#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back
#define t top()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define ll long long
#define oo 1e17
#define int long long

const int N = 55;
int n , k , res , mod = 1e9 + 7;
int a[N][N];

struct Matrix
{
    int x[N][N];
    Matrix(){};
    Matrix(int a[N][N])
    {
        FOR(i , 1 , n)
            FOR(j , 1 , n)
                x[i][j] = a[i][j];
    }
    Matrix operator * (Matrix const &b)
    {
        Matrix c;
        FOR(i , 1 , n)
            FOR(j , 1 , n)
            {
                c.x[i][j] = 0;
                FOR(k , 1 , n)
                    c.x[i][j] = (c.x[i][j] + x[i][k] * b.x[k][j]) % mod;
            }
        return c;
    }
    friend Matrix operator ^ (Matrix const &a , int const &b)
    {
        if(b == 1)
            return a;
        Matrix c = a ^ (b / 2);
        if(b & 1)
            return c * c * a;
        return c * c;
    }
};

main()
{
    //freopen("R.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    FOR(i , 1 , n)
        FOR(j , 1 , n)
            cin >> a[i][j];
    Matrix I = Matrix(a);
    Matrix A = I ^ k;
    FOR(i , 1 , n)
        FOR(j , 1 , n)
            res = (res + A.x[i][j]) % mod;
    cout << res;
}


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

int main(){
	int N,P;
	string S;
	cin >> N >> P >> S;
	vector<int> T;
	for(int i=0;i<N;i++)T.push_back(S[i]-'0');
	
	if(10%P==0){
		long long ans=0;
		for(int i=0;i<N;i++)if(T[i]%P==0)ans+=i+1;
		cout << ans << endl;
		return 0;
	}
	
	vector<int> mod10p(N+1);
	mod10p[0]=1;
	for(int i=0;i<N;i++)mod10p[i+1]=(mod10p[i]*10)%P;
	
	for(int i=0;i<N;i++)T[N-i-1]=(T[N-i-1]*mod10p[i])%P;
	vector<int> sum(N+1,0);
	for(int i=0;i<N;i++)sum[i+1]=(sum[i]+T[i])%P;
	map<int,long long> m;
	for(int i=1;i<=N;i++){
		if(m.find(sum[i])==m.end())m.insert(make_pair(sum[i],1));
		else m[sum[i]]++;
	}
	long long ans=0;
	for(auto p:m){
		int k=p.first;
		long long c=p.second;
		ans+=c*(c-1)/2;
		if(k==0)ans+=c;
		//cout << k << " " << c << endl;
	}
	cout << ans << endl;
	
	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;
ll a[MAX_N];

vector<pair<ll, int>> a_sort;

int ans;

int main(void) {
  // Here your code !
  scanf("%d", &n);

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

  for (int i = 0; i < n; ++i) {
    a_sort.push_back(make_pair(a[i], i % 2));
  }

  sort(a_sort.begin(), a_sort.end());
  
  int odd2even = 0;
  int even2odd = 0;

  for (int i = 0; i < n; ++i) {
    int cur_parity = i % 2;

    if (cur_parity == 0 && a_sort[i].second == 1) {
      even2odd += 1;
    } else if (cur_parity == 1 && a_sort[i].second == 0) {
      odd2even += 1;
    }
  }

  ans = odd2even;

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

  return 0;
}


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

#define SZ(a) (int)(a).size()
typedef long long ll;

int main() {
	cin.sync_with_stdio(false);
	string s;
	cin >> s;
	int n = SZ(s);
	int ans = n;
	for (char c = 'a'; c <= 'z'; c++) {
		int mx = 0;
		int m = 0;
		for (int i = 0; i <= n; i++) {
			if (i == n || s[i] == c) {
				mx = max(mx, m);
				m = 0;
			}
			else {
				m++;
			}
		}
		ans = min(ans, mx);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 0


[W,H,x,y] = inpl()
ans1 = W*H/2.0
ans2 = 1 if abs(2*x-W)<eps and abs(2*y-H) <eps else 0

print(*[ans1,ans2])

Measured memory_bytes: 12520
#include <iostream>
using namespace std;
int main()
{
	int a;
	int n;
	cin>>n>>a;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	for(int i=0;i<n-1;i++){
		int tmp=i;
		for(int j=i+1;j<n;j++){
			if(arr[j]>arr[tmp]){
				tmp=j;
			}
		}	
		int m;
		m=arr[i];
		arr[i]=arr[tmp];
		arr[tmp]=m;
	}
	int q=0;
	for(int i=0;i<a;i++){		
		q+=arr[i];
	}	
	cout<<q;
	return 0;
}

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

using namespace std;

string s;
int n,ans;
int main() {
    ios::sync_with_stdio(false);
    cin >> s;
    n = s.size();
    ans = n;
    for (int i = 0; i < n-1; i++)
        if (s[i] != s[i+1])
            ans = min(ans, max(i+1, n-(i+1)));

    cout << ans <<'\n';


    return 0;


}


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

// cin >> a >> b;
// coud << "" << << endl;

string alphabet[] = {"", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"};

void standard_string(string now, int N, int lim, vector<string> &vec)
{
    if (N == 1) {
        for (int i = 1; i <= lim; ++i) {
            string s = now + alphabet[i];
            vec.push_back(s);
        }
        return;
    }

    // N >= 2
    for (int i = 1; i <= lim; ++i) {
        string s = now + alphabet[i];
        if (i < lim) {
            standard_string(s, N - 1, lim, vec);
        } else {
            standard_string(s, N - 1, lim + 1, vec);
        }
    }
}


void Main() {
    int N;
    cin >> N;


    vector<string> res;
    standard_string("", N, 1, res);


    for (int i = 0; i < res.size(); ++i) {
        cout << res[i] << endl;
    }

}



int main() {
    Main();
    return 0;
}



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

int main(){
  long long n;
  cin >> n;
  char a[50]; a[1]='a';
  int b[50];
  rep(i,25){
    a[i+2] = a[i+1] + 1;
    b[i]=0;
  }
  
  for(int i=0; n>0; i++){
    b[i] = n % 26;
    if(b[i] == 0){b[i] = 26;}
    n = (n-1) / 26;
  }
  
  for(int i=20; i>=0; i--){
    if(b[i] != 0){
      cout << a[b[i]];
    }
  }
  
  return 0;
}


Measured memory_bytes: 3644
N = int(input())
A = list(map(int, input().split()))
sumlow = 0
sumhigh = 0
i = 0
j = N-1
while i<=j:
    if sumlow <= sumhigh:
        sumlow += A[i]
        i += 1
    else:
        sumhigh += A[j]
        j -= 1
print(abs(sumlow-sumhigh))


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

struct SCC {
    int n;
    vector<vector<int>>& G;
    vector<vector<int>> G_rev;
    vector<int> comp, order;
    vector<bool> visited;

    SCC(vector<vector<int>>& G) : G(G), n(G.size()) {
        comp.resize(n, -1);
        visited.resize(n);
        G_rev.resize(n);
        for (int u = 0; u < n; u++) {
            for (int v : G[u]) {
                G_rev[v].push_back(u);
            }
        }

        for (int v = 0; v < n; v++) dfs(v);
        reverse(order.begin(), order.end());
        int c = 0;
        for (int v : order) if (comp[v] == -1) rdfs(v, c++);
    }

    int operator[](int k) {
        return comp[k];
    }

    void dfs(int u) {
        if (visited[u]) return;
        visited[u] = true;
        for (int v : G[u]) dfs(v);
        order.push_back(u);
    }

    void rdfs(int u, int c) {
        if (comp[u] != -1) return;
        comp[u] = c;
        for (int v : G_rev[u]) rdfs(v, c);
    }
};

struct UnionFind {
    vector<int> par, rank, size;

    UnionFind(int n) {
        par.resize(n);
        for (int i = 0; i < n; i++) par[i] = i;
        rank.resize(n);
        size.resize(n, 1);
    }

    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

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

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int get_size(int x) {
        return size[find(x)];
    }
};

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

    int V, E;
    cin >> V >> E;
    vector<vector<int>> G(V);
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
    }
    SCC scc(G);
    UnionFind uf(2 * V);
    for (int i = 0; i < V; i++) uf.unite(i, V + scc[i]);
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int u, v;
        cin >> u >> v;
        cout << (uf.same(u, v) ? 1 : 0) << '\n';
    }
}


Measured memory_bytes: 4700
#include<stdio.h>
int main(void)
{
	int N,M,ans,i;
	ans=0;
	scanf("%d %d",&N,&M);
	for(i=1;i<N;i++){
		ans+=i;
	}
	for(i=1;i<M;i++){
		ans+=i;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1728
#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!{
        N: usize,
        V: [(usize, usize, usize); N],
    }
    for (t, x, y) in V {
        if x + y > t || t % 2 != (x + y) % 2 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

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

int main() {
	
	ios_base::sync_with_stdio(false);
	
	char ch;

	int cnt = 0;
	for(int i = 0; i < 6; ++i)
	{
		cin >> ch;

		if(ch == '1') ++cnt;
	}

	cout << cnt;

	return 0;
}

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

def main():
    S = input()
    
    lenS = len(S)
    N = 13
    DP = [0] * N
    DP[0] = 1
    
    mod = 10 ** 9 + 7
    mul = 1
    for i in reversed(range(lenS)):
        nextDP = [0] *13
        c = S[i]
        if c == '?':
            for k in range(10):
                for j in range(N):
                    nextDP[(k * mul + j) %N] += DP[j]
                    nextDP[(k * mul + j) %N] %= mod

        else:
            k = int(S[i])
            for j in range(N):
                nextDP[(k * mul + j) %N] += DP[j]
                nextDP[(k * mul + j) %N] %= mod

        mul *= 10
        mul %= N
        DP = nextDP

    return DP[5]

if __name__ == '__main__':
    print(main())



Measured memory_bytes: 43500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.Petrozavodsk
{
    class TwoInteger
    {
        public static void Main()
        {
            var xy = ReadLine().Trim().Split(' ').Select(_ => int.Parse(_));
            if (xy.First() % xy.Last() == 0)
            {
                WriteLine(-1);
            }
            else
            {
                WriteLine(xy.First());
            }
        }
    }
}


Measured memory_bytes: 11348
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
    long long n, k;
    cin >> n >> k;
    long long a[2020];
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) {
                ans += k * (k + 1) / 2;
            }
            else if (a[i] < a[j]) {
                ans += k * (k - 1) / 2;
            }
            ans %= 1000000007;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long s = 0;
        long[] a = new long[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextLong();
            s += a[i];
        }
        int q = sc.nextInt();
        long[] b = new long[q];
        long[] c = new long[q];
        for (int i = 0; i < c.length; i++) {
            b[i] = sc.nextLong();
            c[i] = sc.nextLong();
        }

        Map<Long, Long> map = new HashMap<>();
        for (int i = 0; i < a.length; i++) {
            long v = 1;
            if (map.containsKey(a[i])) {
                v += map.get(a[i]);
            }
            map.put(a[i], v);
        }

        for (int i = 0; i < q; i++) {
            if (map.containsKey(b[i])) {
                s += (c[i] - b[i]) * map.get(b[i]);
                long v = 0;
                if (map.containsKey(c[i])) {
                    v += map.get(c[i]);
                }
                map.put(c[i], map.get(b[i]) + v);
                map.remove(b[i]);
            }
            System.out.println(s);
        }

        sc.close();
    }
}

Measured memory_bytes: 68620
K, N = map(int, input().split())
A = list(map(int, input().split()))

A = sorted(A)
max_l = 0

for i in range(1, N):
  if i < N-1:
    l = A[i+1] - A[i]
  else:
    l = K - A[N-1] + A[0]
  max_l = l if max_l<l else max_l
  
print(K - max_l)

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> c(n);
	vector<int> s(n);
	vector<int> f(n);
	rep(i,n-1) cin >> c.at(i) >> s.at(i) >> f.at(i);
	vector<int> ans(n);
	rep(i,n-1){
		int m=0;
		for(int j=i;j<n-1;++j){
			if(m<=s.at(j)) m=s.at(j)+c.at(j);
			else{
				if((m-s.at(j))%f.at(j)==0) m+=c.at(j);
				else m+=f.at(j)-(m-s.at(j))%f.at(j)+c.at(j);
			}
		}
		ans.at(i)=m;
	}
	rep(i,n) cout << ans.at(i) << endl;
}

Measured memory_bytes: 256
genl :: Int -> [Int] -> [(Int,Int)]
genl _ [] = []
genl n (x:xs) = (n,x):(genl (n+1) xs)

bsort :: [(Int,Int)] -> [(Int,Int)]
bsort [] = []
bsort [x] = [x]
bsort (x:y:l) = if (snd x) > (snd y) then y:(bsort (x:l)) else x:(bsort (y:l))

bsorts :: Int -> [(Int,Int)] -> [(Int,Int)]
bsorts 0 l = l
bsorts n l = bsorts (n-1) (bsort l)

main :: IO ()
main = do
   n <- read <$> getLine
   l' <- map read.words <$> getLine
   let ave = sum l'
       l = bsorts n $ genl 0 (map (\x -> (abs $ x*n - ave)) l')
   putStrLn $ show $ fst $ head l

Measured memory_bytes: 1020
n = gets.to_i

dp = Array.new(10){Array.new(10, 0)}
1.upto(n) do |x|
  dp[x.to_s[0].to_i][x.to_s[-1].to_i] += 1
end

ans = 0

1.upto(9) do |i|
  1.upto(9) do |j|
    ans += dp[i][j] * dp[j][i]
  end
end

puts ans


Measured memory_bytes: 14344
/**
 *    author:  tourist
 *    created: 08.10.2017 15:50:42       
**/
#include <bits/stdc++.h>

using namespace std;

string solve(int a, int b, int c) {
  bool flag = false;
  if (a == 0) {
    flag = true;
    a = b;
    b = c;
    c = 0;
  }
  string res = "";
  if (a == 0) {
    res = string(b, 'b');
  } else {
    if (b == 0 && c == 0) {
      res = string(a, 'a');
    } else {
      vector<string> put(a, "a");
      for (int i = 0; i < c; i++) {
        put[i % a] += 'c';
      }
      int ptr = c % a;
      for (int i = 0; i < b; i++) {
        put[ptr] += 'b';
        ptr++;
        if (ptr == a) {
          ptr = c % a;
        }
      }
      map<string, int> mp;
      for (auto &s : put) {
        mp[s]++;
      }
      vector< pair<string, int> > v;
      for (auto &p : mp) {
        v.push_back(p);
      }
      assert(v.size() <= 3);
      while (v.size() < 3) {
        v.emplace_back("", 0);
      }
      string aux = solve(v[0].second, v[1].second, v[2].second);
      res = "";
      for (int i = 0; i < (int) aux.size(); i++) {
        res += v[aux[i] - 'a'].first;
      }
    }
  }
  if (flag) {
    for (char &c : res) {
      c++;
    }
  }
  return res;
}

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  cout << solve(a, b, c) << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools
from functools import cmp_to_key
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = map(int, readline().split())
A = map(int, readline().split())
A = sorted(A)

ret = 1
for num in A:
    ret *= num
    if(ret > 1000000000000000000):
        print(-1)
        exit(0)
print(ret)
exit(0)


Measured memory_bytes: 20984
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>

using namespace std;

vector<int> colors;
vector<vector<bool>> has_edge;
int diff;
vector<int> diffs;
int N,M;

bool dfs(int v, int c) {
    colors[v] = c;
    diff += c;
    for (int w = 0; w < N; w++) {
        if (!has_edge[v][w]) continue;
        if (colors[w] == c) return false;
        if (colors[w] == 0 && !dfs(w, -c)) return false;
    }
    return true;
}

vector<int> total_diffs(vector<int> diffs) {
    if (diffs.size() == 0) return {0};
    int last = diffs.back();
    diffs.pop_back();
    auto total_diffs_smaller = total_diffs(diffs);

    vector<int> total_diffs;
    for (auto total_diff : total_diffs_smaller) {
        total_diffs.emplace_back(total_diff + last);
        total_diffs.emplace_back(total_diff - last);
    }
    sort(total_diffs.begin(), total_diffs.end());
    total_diffs.erase(unique(total_diffs.begin(), total_diffs.end()), total_diffs.end());
    return total_diffs;
}

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

    has_edge.resize(N);
    for (int i = 0; i < N; i++) {
        has_edge[i].resize(N, true);
    }
    colors.resize(N, 0);

    for (int v = 0; v < N; v++) {
        has_edge[v][v] = false;
    }
    for (int i = 0; i < M; i++) {
        int A,B;
        cin >> A >> B;
        A--;
        B--;
        has_edge[A][B] = false;
        has_edge[B][A] = false;
    }

    for (int v = 0; v < N; v++) {
        if (colors[v] == 0) {
            diff = 0;
            if (!dfs(v, 1)) {
                cout << -1;
                return 0;
            }
            diffs.emplace_back(diff);
        }
    }
    int abs_total_diff_min = INT_MAX;
    for (auto total_diff : total_diffs(diffs)) {
        int t = abs(total_diff);
        if (abs_total_diff_min > t) abs_total_diff_min = t;
    }

    int bigger = (N + abs_total_diff_min) / 2;
    int smaller = (N - abs_total_diff_min) / 2;

    cout << (bigger * (bigger - 1) + smaller * (smaller - 1)) / 2;
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

main(){

int i,a,b;

for(i==1;;i++){

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

if(a==0&&b==0) break;

if(a<b) printf("%d %d\n",a,b);

else printf("%d %d\n",b,a);

}

return 0;

}


Measured memory_bytes: 2044
N=gets.to_i
as=gets.split.map(&:to_i)
cnt_m=0
cnt=0
as.each do |e|
  cnt+=1 if e<0
end
as=as.map{|e|e.abs}.sort
puts cnt.even? ? as.inject(:+) : as.inject(:+)-as[0]*2


Measured memory_bytes: 11000
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main()
{
    int a, b;
    cin >> a >> b;

    cout << a*b << " " << a*2+b*2 << endl;
}

int main()
{
    std::cout << std::fixed << std::setprecision(15);
    Main();
}


Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define pb push_back
using ll = long long;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(void){
    int N,temp;
    vector<int> e;
    cin >> N;
    for(int i=0;i<=N;i++){
        e.pb(0);
    }
    for(int i=1;i<N;i++){
        cin >> temp;
        e[temp]++;
    }
    for(int i=1;i<=N;i++){
        cout << e[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
	int n;
	cin >> n;
	map<int, int> cnt;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		cnt[a]++;
	}
	int ans = 0;
	for (auto x : cnt) {
		int diff = x.second - x.first;
		ans += (diff < 0) ? x.second : diff;
	}
	cout << ans << endl;
}

Measured memory_bytes: 8104
#include<iostream>
using namespace std;
int m, n;
int a[1000];
bool check(int v) {
	int cnt = 0, s = 1000000000;
	for (int i = 0; i < n; i++) {
		if (a[i] > v)return false;
	}
	for (int i = 0; i < n; i++) {
		if (s + a[i] > v) {
			cnt++;
			s = a[i];
		}
		else {
			s += a[i];
		}
	}
	if (cnt > m)return false;
	return true;
}
int main() {
	while (true) {
		cin >> m >> n;
		if (m == 0 && n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int L = 0, R = 100000000, M;
		for (int i = 0; i < 50; i++) {
			M = (L + R) / 2;
			bool r1 = check(M - 1);
			bool r2 = check(M);
			if (r1 == true)R = M;
			if (r2 == false) { L = M; }
		}
		cout << M << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Map<Integer, Integer> m = new HashMap<>();
        for (int i = 0; i < 4; i++) {
            int n = sc.nextInt();
            if (m.containsKey(n)) {
                m.put(n, m.get(n) + 1);
            } else {
                m.put(n, 1);
            }
        }
        int c = 0;
        for (Map.Entry<Integer, Integer> e : m.entrySet()) {
            if (e.getValue() == 4) {
                c = 2;
            }
            if (e.getValue() == 2) {
                c++;
            }
        }
        System.out.println(c == 2 ? "yes" : "no");
    }
}


Measured memory_bytes: 26348
#include<stdio.h>
int main(void){
	int x[3000],y[3000];
	int i,h;
	i=0;
	h=0;
	while(1){
		scanf("%d %d",&x[i],&y[i]);
		if((x[i]==0)&&(y[i]==0)){break;}
		i++;
	}
	
	for(h=0;h<i;h++){
		if(x[h]<y[h]){
			printf("%d %d\n",x[h],y[h]);
		}
			else if(x[h]>y[h]){
				printf("%d %d\n",y[h],x[h]);
			}
			else{
				printf("%d %d\n",x[h],y[h]);
			}
		}
	return 0;
}


Measured memory_bytes: 2028
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

const long long p = 1e9 + 7;
long long n, a, b;

long long ci_fang(long long x, long long y) {
	long long res = 1;
	while (y) {
		if (y & 1) res = res * x % p;
		x = x * x % p;
		y >>= 1;
	}
	return res;
}

long long C(long long a, long long b) { //求C（总，...）
	long long res = 1;
	for (long long i = 1, j = a; i <= b; ++i, --j) {
		res = res * j % p;
		res = res * ci_fang(i, p - 2) % p;
	}
	return res;
}

//算组合数时，数据非常大，所以要用到lucas定理来计算组合数的大小
//具体原理需详细学习...
long long lucas(long long a, long long b) {
	if (a < p && b < p) return C(a, b);
	return C(a % p, b % p) * lucas(a / p, b / p) % p;
}
int main()
{ 
	cin >> n >> a >> b;
	// +p 同余定理用于减法的时候尽量在减完之后再加上模数，防止出现负数
	cout << (ci_fang(2, n) - 1 - (lucas(n, a) % p + lucas(n, b) % p) % p + p) % p << endl;
}

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

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

		while((str=br.readLine()) != null){
			double minv = Double.parseDouble(str);
			double t = minv/9.8;
			double y = 4.9 * Math.pow(t, 2);
			double n = (y+5)/5;
			System.out.println((int)Math.ceil(n));
		}
	}
}

Measured memory_bytes: 17060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n;cin >> n;
    int f = 0;
    int a[n];
    rep(i,n)cin >> a[i];
    vector<int> mae,usi;
    rep(i,n){
        if(f == 0)usi.push_back(a[i]);
        else mae.push_back(a[i]);
        f ^= 1;



    }
    vector<int> ans;
    for(int i = mae.size()-1;i >= 0;i--)ans.push_back(mae[i]);
    for(int i = 0;i < usi.size();i++)ans.push_back(usi[i]);
    if(f)reverse(ans.begin(),ans.end());
    for(auto p:ans)cout << p << " ";
    

    return 0;

}

Measured memory_bytes: 7016
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		String winner = "";
		if(a == 1) {
			if(b == 1) {
				winner = "Draw";
			} else {
				winner = "Alice";
			}
		} else if(b == 1) {
			winner = "Bob";
		} else {
			if(a == b) {
				winner = "Draw";
			} else if(a > b){
				winner = "Alice";
			} else {
				winner = "Bob";
			}
		}
		System.out.println(winner);
	}
}

Measured memory_bytes: 21716
#include"bits/stdc++.h"
using namespace std;

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    for (int64_t i = 0; i < N; i++) {
        cin >> A[i];
    }

    int64_t right = accumulate(A.begin(), A.end(), (int64_t)0);
    int64_t ans = LLONG_MAX;
    int64_t left = 0;
    for (int64_t i = 0; i < N - 1; i++) {
        //i個目の区間の後ろで切る
        left += A[i];
        right -= A[i];
        ans = min(ans, abs(right - left));
    }

    cout << ans << endl;
}

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

v= list(map(int, input().split())) 
c= list(map(int, input().split()))
r=[]

for i in range(n):
  r.append(v[i]-c[i]) 

r.append(0)
r.sort(reverse=True)

ret= sum([j for j in r if j>=0])
print(ret)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int dp[10010];
int main()
{
    int n;
    int l[100];
    int x;
    cin>>n>>x;
    REP(i,n)cin>>l[i];
    int cnt=1;
    int now=0;
    REP(i,n)
    {
        now+=l[i];
        if(now<=x)cnt++;
    }
    cout<<cnt<<endl;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int n=s.size();
	int cnt1=0,cnt2=0;
	rep(i,n){
		if(s.at(i)=='0') cnt1++;
		else cnt2++;
	}
	cout << min(cnt1,cnt2)*2 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H1,H2, M1, M2, K, ans;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  int okiterutime;
  okiterutime = (H2 - H1) * 60 + (M2 - M1);//単位は分
  ans = okiterutime - K;
  cout << ans << endl;
  
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define maxn 270010
int n,m,a[maxn],b[maxn][2];
int main()
{
    scanf("%d",&n); m=(1<<n);
    for(int i=0;i<m;++i) scanf("%d",&a[i]);
    for(int s=0;s<m;++s)
        for(int i=s;;i=(i-1)&s)
        {
            b[s][1]=max(b[s][1],a[i]);
            if(b[s][1]>b[s][0]) swap(b[s][1],b[s][0]);
            if(!i) break;
        }
    for(int i=1;i<m;++i)
    {
        a[i]=b[i][0]+b[i][1];
        if(i) a[i]=max(a[i],a[i-1]);
        printf("%d\n",a[i]);
    }

    return 0;
}


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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

map<long, long> dp;

long f(long x)
{
	if(x == 1) return 1;
	else if(dp[x]) return dp[x];
	else
	{
		return dp[x] = 2*f(x/2)+1;
	}
}

int main()
{
	// freopen("input.in", "r", stdin);
	long h; scanf("%lld", &h);
	printf("%lld\n", f(h));
}

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

int main()
{
    ll H, W, K; cin >> H >> W >> K;
    vector<vector<char>> c(H, vector<char>(W, 0));
    rep(i, H) {
        rep(j, W) {
            char tmp; cin >> tmp;
            c[i][j] = tmp;
        }
    }

    ll ans = 0;
    rep(i, (1<< H)) {
        rep(j, (1<<W)) {
            //cout << "i = " << i << ",j = " << j << endl;
            ll tmp = 0;
            rep(k, H) {
                rep(l, W) {
                    //cout << "k= " << k << ",(1<<k) = " << (1<<k) << ",l= " << l << ",(1<<l) = " << (1<<l) << endl;
                    if ((i & (1<<k)) || (j & (1<<l))) { // 選択された行列は読み飛ばす
                        continue;
                    }
                    else {
                        if (c[k][l] == '#') {
                            tmp++;
                        }
                    }
                }
            }
            if (tmp == K) ans++;
        }
    }
    cout << ans << endl;

}


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

using namespace std;

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

typedef complex<double> P;
struct Line : public vector<P>
{
  Line(P a=P(), P b=P()) {
    push_back(a); push_back(b);
  }
};
typedef Line Segment;

#define EPS (1e-7)

bool operator < (P const& a, P const& b) {
  return (a.real() != a.real()) ? a.real() < b.real() : a.imag() < b.imag();
}

double dot(P const& a, P const& b) {
  return real(conj(a)*b);
}

double cross(P const& a, P const& b) {
  return imag(conj(a)*b);
}

P projection_point(P const& a, P const& b, P const& c) {
  double k = dot(b-a, c-a) / norm(b-a);
  return a+k*(b-a);
}

P reflection_point(P const& a, P const& b, P const& c) {
  return c + 2.*(projection_point(a, b, c) - c);
}

bool is_parallel(Segment const& s, Segment const& t) {
  return abs(cross(s[1]-s[0], t[1]-t[0])) < EPS;
}

bool is_orthogonal(Segment const& s, Segment const& t) {
  return abs(dot(s[1]-s[0], t[1]-t[0])) < EPS;
}

int ccw(P a, P b, P c) {
  b -= a, c -= a;
  if(cross(b, c) > 0) return +1; // counter clockwise
  if(cross(b, c) < 0) return -1;  // clockwise
  if(dot(b, c) < 0) return +2;    // c-a-b
  if(norm(b) < norm(c)) return -2;  // a-b-c
  return 0; // on segment
}

bool is_intersect_ss(Segment s, Segment t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0
         && ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}

int main () {
  
  int q; cin >> q;
  for(;q--;) {
    Segment s, t;
    cin >> s[0].real() >> s[0].imag();
    cin >> s[1].real() >> s[1].imag();
    cin >> t[0].real() >> t[0].imag();
    cin >> t[1].real() >> t[1].imag();
    
    cout << is_intersect_ss(s, t) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1252
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    String S=gs();
        int a=0;
        for(int i=1; i<=S.length();i++) {
        	String S2=S.substring(0,S.length()-i);
        	if (S2.length()%2==0) {
        		if(S2.substring(0, S2.length()/2).equals(S2.substring(S2.length()/2, S2.length()))) {
        			a=S2.length();
        			break;
        		}
        	}
        }

	   
	    System.out.print(a);

//        if (t.equals("Sunny")) {
//        	System.out.print("Cloudy");
//        }else if(t.equals("Cloudy")){
//        	System.out.print("Rainy");
//        } else {
//        	System.out.print("Sunny");
//        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35448
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  int D, ans = 0, check = 0, count = 0 ;
  int C[27] ;
  cin >> D ;
  int S[27][D+1], choice[D+1] = {}, history[27] = {} ;
  for(int i=1;i<27;i++) cin >> C[i] ;
  for(int i=1;i<(D+1);i++){
    for(int j=1;j<27;j++){
      cin >> S[j][i] ;
    }
  }
  for(int date=1;date<(D+1);date++){
    cin >> choice[date] ;
    history[choice[date]] = date ;
    ans += S[choice[date]][date] ;
    for(int i=1;i<27;i++){
      ans -= C[i] * ( date - history[i]) ;
    }
    cout << ans << endl ;
  }
  return 0 ;
}  

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

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

  string card_T, card_H;
  int point_T = 0, point_H = 0;
  for (int i = 0; i < n; i++) {
    cin >> card_T >> card_H;
    if (card_T > card_H) point_T += 3;
    else if (card_T < card_H) point_H += 3;
    else point_T++, point_H++;
  }

  cout << point_T << " " << point_H << endl;

  return 0;
}


Measured memory_bytes: 3144
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  int a,b;
  cin >> a >> b;
  string A,B;
  A = "";
  B = "";
  for(int i=0; i<b; i++){
    A += a+'0';
  }
  for(int i=0; i<a; i++){
    B += b+'0';
  }
  if(A < B){
    cout << A << endl;
  }else{
    cout << B << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 1 << 22
int map[1000][1000];
int n, minval = 999999;

int prim()
{
    int sum = 0;
    int d[1000], fathernode[1000], color[1000];;
    for(int i = 0; i < n; i ++)
        d[i] = fathernode[i] = MAX;
    d[0] = 0;
    while(true)
    {
        int ch = -1, min = MAX;
        for(int i = 0; i < n; i ++)
        {
            if(min > d[i] && color[i] == 0) //选取未被染色的点
            {
                ch = i;
                min = d[i];
            }
        }
        if(ch == -1) //选完了，跳出
            break;
        color[ch] = 1;//选取这个点后染色
        for(int j = 0; j < n; j ++)//选取V-T中与T距离最近的节点
        {
            if(d[j] > map[ch][j] && color[j] == 0)
            {
                d[j] = map[ch][j];
                fathernode[j] = ch;//j节点的父节点是ch
            }
        }
    }
    //选取完毕，开始加起来
    for(int k = 0; k < n; k ++)//只加被染色（即被选中的）节点
    {
        if(fathernode[k] != MAX)//只加上有父节点的点
            sum += map[k][fathernode[k]];
    }
    return sum;
}

int main(void)
{
    scanf("%d", &n);
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < n; j ++)
        {
            int t;
            scanf("%d", &t);
            map[i][j] = (t == -1 ? MAX : t);
        }
    printf("%d\n", prim() );
    return 0;
}


Measured memory_bytes: 3108
def main(input_str):
    input_list = list(input_str)
    count = 0
    if input_list[0] == "0":
        ans = []
        for i, _ in enumerate(input_list):
            if i % 2 == 0:
                ans.append("0")
            else:
                ans.append("1")
        for i, _ in enumerate(input_list):
            if input_list[i] != ans[i]:
                count += 1

    else:
        ans = []
        for i, _ in enumerate(input_list):
            if i % 2 == 0:
                ans.append("1")
            else:
                ans.append("0")
        for i, _ in enumerate(input_list):
            if input_list[i] != ans[i]:
                count += 1

    return count


if __name__ == "__main__":
    input_str = input()
    print(main(input_str))


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

char c;
string s="ATCG";

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

  cin>>c;
  rep(i,4){
    if(s[i]==c){
      cout<<s[i^1]<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	s := read()
	result := true
	for i := 1; i < len(s); i++ {
		if strings.Count(s, s[i-1:i]) != 2 {
			result = false
			break
		}
	}
	if result {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func read() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640