akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from operator import itemgetter

# Union-Find木
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        # 1-indexedのままでOK、その場合は[0]は未使用
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

N = int(input())
X = [[0] * 2 for i in range(N)]
Y = [[0] * 2 for i in range(N)]
for i in range(N):
    x, y = map(int, input().split())
    X[i][0] = x
    X[i][1] = i
    Y[i][0] = y
    Y[i][1] = i
# 元indexを保持して座標位置順にソート
X.sort()
Y.sort()

edges = []
for i in range(1, N):
    # 座標上で隣り合う頂点同士で辺集合を作る
    edges.append((X[i-1][1], X[i][1], X[i][0] - X[i-1][0]))
    edges.append((Y[i-1][1], Y[i][1], Y[i][0] - Y[i-1][0]))
# コスト順にソート
edges.sort(key=itemgetter(2))

uf = UnionFind(N)
ans = 0
# Union-Findで閉路を作らない確認をして最小全域木を作る
for x, y, w in edges:
    if not uf.same(x, y):
        uf.union(x, y)
        ans += w
print(ans)


Measured memory_bytes: 129184
w, h, n = map(int, input().split())
xl, xr, yl, yh= 0, w, 0, h

for _ in range(n):
  a, b, c = map(int, input().split())
  if c == 1:
    xl = max(xl, a)
  elif c == 2:
    xr = min(xr, a)
  elif c == 3:
    yl = max(yl, b)
  else:
    yh = min(yh, b)
if yh - yl >= 0 and xr - xl >= 0:
  print((yh - yl) * (xr - xl))
else :
  print(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
double arr[5000], dp[5000][5000], brr[5000], crr[5000];

double coin(int a, int b){
	if(a == 0){
		if(b == 0) return 1;
		if(b > 0) return 0;
	}else if(b == 0) dp[a][b] = brr[a];
	else if(a == b)dp[a][b] = crr[a];
	else if(dp[a][b] > -1) return dp[a][b];
	else{
		dp[a][b] = (arr[a] * coin(a - 1, b - 1)) + ((1 - arr[a]) * coin(a - 1, b));
	} 
	//cout << a << " " << b << " " << dp[a][b] << endl;
	return dp[a][b];
}
int main (){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> arr[i];
	}
	
	brr[1] = 1 - arr[1];
	crr[1] = arr[1];
	for(int i = 2; i <= n; i++){
		brr[i] = brr[i - 1] * (1 - arr[i]);
	}
	
	for(int i = 2; i <= n; i++){
		crr[i] = crr[i - 1] * arr[i];
	}
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			dp[i][j] = -1;
		}
	}
	double ans = 0;
	int m = ceil(n / 2.0);
	for(int i = n; i >= m; i--){
		ans += coin(n,i);
	}
	
	cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 118656
from collections import Counter
def capital(c):
  return c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def solve(s):
  if s[0] != 'A':
    return False

  if capital(s[1]) or capital(s[-1]):
    return False

  st = Counter(s[2:-1])
  if st['C'] != 1:
    return False
  for c in s[2:-1]:
    if c == 'C': continue
    if capital(c): return False
  return True

s=raw_input()
if solve(s):
  print 'AC'
else:
  print 'WA'


Measured memory_bytes: 2812
#include<bits/stdc++.h>
     
    using namespace std;
     
    int main(){
    	int n, m, r;
    	scanf("%d%d%d", &n, &m, &r);
    	int sum = 0;
    	for(int i = 0, x; i < n; i++){
    		scanf("%d", &x);
    		sum += (m - 1) / x + 1;
    	}
    	printf("%d\n", sum + r);
    }

Measured memory_bytes: 256
n = int(input())
ne = 0
no = 0
a = list(map(int, input().split()))
for ai in a:
    if ai % 2 == 0:
        ne += 1
    else:
        no += 1

# print(n, a, ne, no)

# 奇数はくっつけると偶数になる
odd_rem = no % 2
ne += no // 2

# 偶数はくっつけると偶数になって1つ減るので，1つだけにできる
# ne = 1

# if odd_rem == 1:

# 奇数
if odd_rem == 1:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 62448
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>

using namespace std;

int main() {
  long long int a,b,x;
  cin >> a >> b >> x;
  long long int tmp = b / x - a / x;
  if(a % x == 0)tmp++;
  cout << tmp << endl;
}


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

int main() {
  ll ans=0;
  int n,x,a,b=0;
  cin >> n >> x;
  REP(i,n) {
    cin >> a;
    int over = max(0, a+b-x);
    ans += over;
    b = a-over;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
static const double EPS = 1e-10;
static const double INF = 1e10;

class Point{
    public:
        double x, y;
 
        Point(double x = 0, double y = 0): x(x), y(y) {}
 
        Point operator + (Point p){ return Point(x + p.x, y + p.y);}
        Point operator - (Point p){ return Point(x - p.x, y - p.y);}
        Point operator * (double a){ return Point(a * x, a * y);}
        Point operator / (double a){ return Point(x / a, y / a);}
 
        double abs(){ return sqrt(norm());}
        double norm(){ return x * x + y * y;}
 
        bool operator < (const Point &p) const{
            return x != p.x ? x < p.x : y < p.y;
        }
 
        bool operator == (const Point &p) const{
            return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
        }
};

double getDistance(Point a, Point b){
    return (a - b).abs();
}

int main(){
	int N;
	scanf("%d", &N);
	vector<Point> p(N);
	for(int i = 0; i < N; i++) scanf("%lf %lf", &p[i].x, &p[i].y);
	sort(p.begin(), p.end());
	vector<vector<double> > memo(N, vector<double>(N, INF));
	double res = INF;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(j <= i) continue;
			if(i == 0 && j == 1) memo[i][j] = getDistance(p[i], p[j]);
			else if(j - i > 1) memo[i][j] = memo[i][j - 1] + getDistance(p[j - 1], p[j]);
			else{
				for(int k = 0; k < N; k++){
					if(k >= i) continue;
					memo[i][j] = min(memo[i][j], memo[k][i] + getDistance(p[k], p[j]));
				}
			}
			if(j == N - 1) res = min(res, memo[i][j] + getDistance(p[i], p[j]));
		}
	}
	printf("%.10lf\n", res);
	return 0;
}



Measured memory_bytes: 10436
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    vector<ll> b(n);
    vector<ll> a(n);
    rep(i,n) cin>>a[i]>>b[i];
    for(ll i=n-1;i>=0;i--){
      // cout<<a[i]+sum<<" "<<b[i]<<" "<<(b[i])-(a[i]+sum)%b[i]<<endl;
      if(a[i]!=0&&b[i]!=1&&(a[i]+sum)%b[i]!=0)sum+=abs((b[i])-(a[i]+sum)%b[i]);
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4756
//AcFreak

#include<bits/stdc++.h>
#define lint long long int 
#define mp make_pair
#define pb push_back
#define f first
#define INF (lint )(1e9)
#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s second
#define endl '\n'
#define pii pair<int,int >
using namespace std;
//Use Below with unordered maps  :{ 
struct pair_hash {
    template <class T1, class T2>
    std::size_t operator () (const std::pair<T1,T2> &p) const {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);
        
        return h1 ^ h2;  
    }
};


int dp[123456];
 vector<vector<int > >g(123456);

int solve(int index)
{
    int ans=0;
    
    if(g[index].size() == 0)
    return 1;
    
    
    if(dp[index] > 0)
    return dp[index];
    
    
    for(int t=0;t<g[index].size();t++)
    {
        ans = max(ans,1+solve(g[index][t]));
    }
    return dp[index] = ans;
}

int main()
{__
    
    int n,m;
    cin>>n>>m;
    
   
    
    int i,j;
    
    for(i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        
        x--;y--;
        g[x].push_back(y);
    }
    
    for(j=0;j<123456;j++)
    dp[j]=-1;
    
    for(i=0;i<n;i++)
    {
        dp[i] = solve(i);
    }
    
    int ans=0;
    
    for(i=0;i<n;i++)
    {
        ans = max(ans,dp[i]);
    }
    
    cout<<ans-1<<endl;
    
    
    
    
    return 0;
}

Measured memory_bytes: 8832
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    h1,m1,h2,m2,k = map(int,input().split())
    cnt1 = h1*60 + m1
    cnt2 = h2*60 + m2
    print(max((cnt2-cnt1) - k,0))

Measured memory_bytes: 9612
#include <stdio.h>
 
int main( void )
{
    int h,w,i,j;
    
	while(1){
    	scanf("%d %d", &h, &w);
		
		if((h == 0) && (w == 0)) break;
		
		for(i = 0; i < h; i++){
			for(j = 0; j < w; j++){
				(((i % 2 == 0) && (j % 2 == 0)) ||
				 ((i % 2 == 1) && (j % 2 == 1))) ? printf("#") : printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
    
    return 0;
}

Measured memory_bytes: 572
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] city = new int[N];
        for (int i = 0; i < M; ++i) {
            int A = sc.nextInt();
            ++city[A - 1];
            int B = sc.nextInt();
            ++city[B - 1];
        }
        sc.close();
        for (int i = 0; i < N; ++i) {
            System.out.println(city[i]);
        }
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL =LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

bool is_prime(int N){
    
    if (N == 1) return false;
    
    int sqn = sqrt(N);
    
    for(auto i = 2; i<=sqn; i++){
        if (N % i == 0) return false;
    }
    return true;
}


int main() {
    int q;cin>>q;
    vector<int> goododd;
    for(auto i = 1; i<100005;i+=2){
        
        if(is_prime((i+1)/2) && is_prime(i)) goododd.push_back(i);
        
    }
    
    rep(i,q){
        int l,r;cin>>l>>r;
        
        cout<< (upper_bound(all(goododd),r)-goododd.begin()) - (lower_bound(all(goododd),l)-goododd.begin()) <<endl;
        
    }
    
    
    return 0;
}










Measured memory_bytes: 640
using System;
using static System.Console;
using static System.Int32;
using static System.Math;
using System.Linq;
using System.Collections.Generic;

class Solution
{
    static void Main()
    {
    lb:
        var sp = ReadLine().Split();
        var h = Parse(sp[0]);
        var k = Parse(sp[1]);
        var dic = new Dictionary<int, int>();
        for(int i = 0; i < k; ++i)
        {
            sp = ReadLine().Split();
            var damage = Parse(sp[0]);
            var mp = Parse(sp[1]);
            bool add = true;
            var removes = new List<int>();
            foreach(var pair in dic)
            {
                if (damage <= pair.Value && pair.Key <= mp)
                {
                    add = false;
                    break;
                }
                if (pair.Value <= damage && mp <= pair.Key)
                {
                    removes.Add(pair.Key);
                }
            }
            foreach (var key in removes) dic.Remove(key);
            if (add) dic[mp] = damage;
        }
        var magic = new SortedList<int, int>(dic.Count);
        foreach (var pair in dic) magic.Add(pair.Key, pair.Value);
        var result = new Dictionary<int, int>();
        for (int i = 1; i <= h; ++i)
        {
            int min = MaxValue;
            foreach (var pair in magic)
            {
                var hp = i - pair.Value;
                min = Min(min, (0 < hp ? result[hp] : 0) + pair.Key);
                if (hp <= 0) break;
            }
            result[i] = min;
        }
        WriteLine(result[h]);
    }
}


Measured memory_bytes: 14048
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n;
    cin>>n;
    ll a[n];
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        sum^=a[i];
    }
    rep(i,n){
        cout<<(sum^a[i])<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 5088
import sys
def I(): return int(sys.stdin.readline().rstrip())

def f(x,y,z):
    return x*x+y*y+z*z+x*y+y*z+z*x

def Main():
    n = I()
    c = [0]*n
    fa = True
    for i in range(1,n+1):
        if n<f(i,1,1):  break
        for j in range(1,n+1):
            if n<f(i,j,1):  break
            for k in range(1,n+1):
                tmp = f(i,j,k)
                if n<tmp:   break
                c[tmp-1] += 1

    for rep in c:
        print(rep)
    return

if __name__=='__main__':
    Main()

Measured memory_bytes: 9192
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	char s[14];
	int i;
	for (int i = 0; i<14; i++){
		s[i] = 0;
	}
	scanf("%s",s);
	for (int i = 12; i > 3; i--) {
		s[i + 1] = s[i];
	}
	s[4] = ' ';
	printf("%s\n",s);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-9;
const int inf=2e9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	sort(all(in),[](int a,int b){
		return a>b;
	});
	int t=0;
	while(t+1<n){
		if(in[t+1]<=t+1)break;
		t++;
	}
	int a=in[t]-t,b=1,c=t;
	while(t+1<n){
		if(in[t+1]<=c)break;
		b++;
		t++;
	}
	if(a%2&&b%2)cout<<"Second"<<endl;
	else cout<<"First"<<endl;
}












Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
int main() {
	cin >> n;
	vector<int>v(n);
	vector<int>l(n/2);
	vector<int>r(n/2);
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}
	sort(v.begin(), v.end());

	for(int i = 0; i < n/2; i++){
		l[i] = v[i];
		r[i] = v[n-i-1];
	}

	sort(l.begin(), l.end());
	sort(r.begin(), r.end());

	int cnt = l.back();
	int limit = r.front();
	int ans = 0;
	while(1){
		while(cnt <= limit){
			cnt++;
			ans++;
		}
		if(cnt > limit){
			break;
		}
	}
	cout << ans-1;


  return 0;
}


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

string a, b;
int pd[MAXN][MAXN];
int d[MAXN][MAXN];
bool visitado[MAXN][MAXN];
int n, m;


int solve(int i, int j){
	if(i == n || j == m) return 0;
	
	if(visitado[i][j]) return pd[i][j];
	
	if(a[i] == b[j]){
		d[i][j] = 1;
		visitado[i][j]  = 1;
		return pd[i][j] = 1+solve(i+1,j+1);
	}
	
	int res = solve(i+1,j);
	d[i][j] = 2;
	int ax =solve(i,j+1); 
	if(ax > res){
		d[i][j] = 3;
		res = ax;
	}
	visitado[i][j] = 1;
	return pd[i][j] = res;
}

void printa(int i, int j){
	if(i == n || j == m) return;
	
	if(d[i][j] == 1){
		cout << a[i];
		printa(i+1,j+1);
	}else if (d[i][j] == 2){
		printa(i+1,j);
	}else{
		printa(i,j+1);
	}
	
	
}

int main (){
	cin >> a >> b;
	n = (int)a.size();
	m = (int)b.size();
	solve(0,0);
	printa(0,0);
	
}


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

const long long MOD = 1000000007;
typedef long long LL;
LL mof = MOD;
inline LL pow_mod(LL a,LL k,LL mo)
{
    LL ans=1;
    while(k)
    {
        if(k%2) ans=ans*a%mo;
        a=a*a%mo;
        k>>=1;
    }
    return ans%mo;
}
const int maxn = 2e5+7;
LL jc[maxn+7];
inline LL inv(LL x)
{
    return pow_mod(x,mof-2,mof);
}
LL Inv[maxn+7];
LL C(LL N,LL k)
{
    if(k>N||k<0)return 0;
    if(k==0||k==N)return 1;
    LL ans=1;
    ans=ans*jc[N]*Inv[k]%mof*Inv[N-k]%mof;
    return ans;
}
void init()
{
    jc[1]=jc[0]=1;
    for(LL i=2; i<=maxn; ++i) jc[i]=jc[i-1]*i%mof;
    for(int i=0; i<=maxn; ++i) Inv[i]=inv(jc[i]);
}
void solve(long long n, long long a, long long b){
    LL ans = pow_mod(2,n,MOD);
    LL c1 = 1;
    for(LL i=1;i<=a;++i)
    {
        c1 = c1 * (n-i+1) % MOD;
    }
    c1 *= Inv[a];
    c1 %= MOD;

    LL c2 = 1;
    for(LL i=1;i<=b;++i)
    {
        c2 = c2 * (n-i+1) % MOD;
    }
    c2 = c2 * Inv[b] % MOD;
    cout<< ((ans-c1-c2-1)%MOD+MOD)%MOD<<endl;
}

int main(){
    init();
    long long n;
    scanf("%lld",&n);
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(n, a, b);
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>

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

    std::vector<int> p(n);
    for (int i = 0; i < n; i += 1) {
        std::cin >> p[i];
    }

    int answer = 0;
    for (int i = 1; i < n - 1; i += 1) {
        if (p[i - 1] < p[i] && p[i] <= p[i + 1]) {
            answer += 1;
        } else if (p[i - 1] >= p[i] && p[i] > p[i + 1]) {
            answer += 1;
        }
    }

    std::cout << answer << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>  
using namespace std; 
int main(){  
	int n,a=0,b=0,c=0,d=0;
	cin>>n;
	int i,j;
	string st;
	for(i=0;i<n;i++){
		cin>>st;
		if(st[0]=='A')a++;
		if(st[0]=='W')b++;
		if(st[0]=='T')c++;
		if(st[0]=='R')d++;
	} 
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<b<<endl;
	cout<<"TLE x "<<c<<endl;
	cout<<"RE x "<<d<<endl;
    return 0;  
} 

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
int main(void)
{
    int r,g;
    cin >> r >> g;
    pr(2*g-r);
}

Measured memory_bytes: 256
#include<cmath>
#include<iostream>
#include<queue>

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

using namespace std;

typedef long double D;
typedef vector<D> V;
typedef vector<V> M;

V gauss_jordan(M m, V v) {
  for (int r = m.size(); r--; ) {
    int p = r;
    rep (i, r) if (abs(m[i][r]) > abs(m[p][r])) p = i;
    swap(m[r], m[p]);
    swap(v[r], v[p]);
    if (abs(m[r][r]) < 1e-8) throw 0;
    v[r] /= m[r][r];
    rep (i, r) m[r][i] /= m[r][r];
    rep (i, m.size()) if(i != r) {
      v[i] -= m[i][r] * v[r];
      rep (k, r) m[i][k] -= m[i][r] * m[r][k];
    }
  }
  return v;
}

int main() {
  while (true) {
    int d;
    cin >> d;
    if (d == 0) break;
    D v[10];
    rep (i, d + 3) cin >> v[i];
    rep (i, d + 2) {
      M m;
      rep (j, d + 2) if (i != j) {
	V a;
	D l = 1;
	rep (k, d + 1) {
	  a.push_back(l);
	  l *= j;
	}
	m.push_back(a);
      }
      V a;
      rep (j, d + 2) if (i != j) {
	a.push_back(v[j]);
      }
      a = gauss_jordan(m, a);
      D r = 0;
      D l = 1;
      rep (j, d + 1) {
	r += l * a[j];
	l *= d + 2;
      }
      if (abs(r - v[d + 2]) < 0.5) {
	cout << i << endl;
	goto next;
      }
    }
    cout << d + 2 << endl;
  next:;
  }
  return 0;
}

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

using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);

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

    sort(p.begin(),p.end());

    int sum = 0;

    for(int i=0; i<k; i++){
        sum+=p[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 3624
N,K = map(int, input().split())
A = [int(a)-1 for a in input().split()]

used = [-1]*N
cnt = 0
town = 0
used[0] = 0
while True:
    town = A[town]
    cnt += 1
    if used[town] >= 0:
        cnt = cnt-used[town]
        break
    used[town] = cnt

if K > used[town]:
    K -= used[town]
    K %= cnt
    K += used[town]
ans = used.index(K)+1
print(ans)

Measured memory_bytes: 32268
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int d[N];
    for (int i = 0; i < N; i++)
    {
        cin >> d[i];
    }
    int ans = 0;
    for (int i = 0; i < N - 1; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 1e9+7;
long double PI = acosl(-1);
const ll infl = 1e18+100;
const int inf = 2e9+100;
const int nmax = 2e5+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

vector<int>g[nmax];
int rong[nmax];
vector<int>r2nod[nmax];
int intime[nmax], outtime[nmax], par[nmax];
int shomoy;

void dfs(int u, int p=0){
    intime[u] = ++shomoy;
    par[u] = p;
    for(int v : g[u]) if(v!=p){
        dfs(v, u);
    }
    outtime[u] = shomoy;
}

ll bit[nmax];

void upd(int idx, ll val, int limit){
    while(idx<=limit){
        bit[idx]+=val, idx += idx&-idx;
    }
}

ll kuery(int idx){
    ll ret = 0;
    while(idx) ret+= bit[idx], idx-= idx&-idx;
    return ret;
}

bool cmp(int a, int b){
    return intime[a] > intime[b];
}

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

    int n;
    cin>>n;
    for(int i=1; i<=n; i++) cin>>rong[i];
    for(int i=1; i<n; i++){
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i=1; i<=n; i++) r2nod[ rong[i] ].push_back(i);
    dfs(1);
    vector<ll>uttor;
    for(int i=1; i<=n; i++){
        ll ans = 0;
        vector<pii>tmp;
        sort(r2nod[i].begin(), r2nod[i].end(), cmp);
        for(int u : r2nod[i]){

            ll sam = 0;
            for(int v : g[u]) if(v!=par[u]){
                int L1 = intime[v], R1 = outtime[v];
                ll z1 = kuery(R1) - kuery(L1-1);
                z1 = R1-L1+1 - z1;
                ans += sam * z1;
                sam+=z1;
            }

            int L = intime[u], R = outtime[u];
            ll z = kuery(R) - kuery(L-1);
            z = R-L+1 - z;
            int baki = n - kuery(n) - z + 1;
            ans+= 1LL*baki*z;
            upd(L, z, n);
            tmp.push_back({L,z});
        }
        uttor.push_back(ans);
        for(pii z : tmp){
            upd(z.first, -z.second, n);
        }
    }

    for(auto z : uttor)
        cout<<z<<"\n";
}


Measured memory_bytes: 38800
#ifdef _MSC_VER
#  define _CRT_SECURE_NO_WARNINGS
#  define _USE_MATH_DEFINES
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double;
using u32 = unsigned int; using u64 = unsigned long long int; using str = string;
template <typename T> using vec = vector<T>; void in() { }
template <typename T, typename...TS> void in(T &&x, TS &&...xs) { cin >> x; in(move(xs)...); }
template <typename T> void out(T &&x) { cout << x << "\n"; }
template <typename T, typename...TS> void out(T &&x, TS &&...xs) { cout << x << " "; out(move(xs)...); }
#define indef(t, ...) t __VA_ARGS__; in(__VA_ARGS__)
#define get(t) []{ t x; cin >> x; return x; }()
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define even(x) ((abs(x) & 1) == 0)
#define odd(x) ((abs(x) & 1) == 1)
#define bit(x, i) (((x) >> i) & 1)
#define append emplace_back
#define bisect_left lower_bound
#define bisect_right upper_bound
#define bound(a, x, b) (a <= x && x <= b)
const i64 MOD = 1000000007ll;
const f64 EPS = 1e-10;

void solve() {
    indef(i64, n);
    vec<i64> v;
    times(n, i) {
        indef(i64, a);
        v.append(a);
    }

    i64 ans = 0, off = 0;
    bool valid = false;
    while (!valid) {
        valid = true;
        i64 cnt = 0;
        times(n, i) {
            v[i] += off;
            if (v[i] > n-1) {
                valid = false;
                i64 t = v[i] / n;
                cnt += t;
                v[i] -= n*t;
                v[i] -= t;
            }
        }
        off = cnt;
        ans += cnt;
    }
    out(ans);
}

i32 main()
{
    ios::sync_with_stdio(false);

#ifdef _MSC_VER
    /**
    ifstream fin("input.txt"); cin.rdbuf(fin.rdbuf()); assert(fin);
    ofstream fout("output.txt"); cout.rdbuf(fout.rdbuf()); assert(fout);
    /**/
#endif

    //cout << fixed << setprecision(9);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
using namespace std;
#pragma warning(disable : 4996)

int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int r;
	cin >> r;
	cout << r * r;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli a;
    cin>>a;
    cout<<(a+a*a+a*a*a);
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b<c+d){cout<<"Right"<<endl;return 0;}
  if(a+b==c+d){cout<<"Balanced"<<endl;return 0;}
  if(a+b>c+d){cout<<"Left"<<endl;return 0;}

  return 0;
}


Measured memory_bytes: 256
taro, hanako = 0, 0
n = int(input())
for _ in range(n):
    a, b = input().split()
    if a > b:
        taro += 3
    elif a < b:
        hanako += 3
    else:
        taro += 1
        hanako += 1
print(taro, hanako)

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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

int N, S;

int a[100005];

int main(){
	cin.tie(0);
	
	cin>>N>>S;
	
	rep(i, N)cin>>a[i];
	
	int v = 0, t = 0, l = N+1;
	rep(s, N) {
		if(s>0)v -= a[s-1];
		while(v<S && t<N)v += a[t++];
		if(S<=v && l>t-s)l = t-s;
	}
	
	cout<<(l>N?0:l)<<endl;
	
	return 0;
}



Measured memory_bytes: 3504
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, K;
  cin >> N >> K;
  if (N % K == 0) {
    cout << 0 << "\n";
  }
  else {
    cout << 1 << "\n";
  }
}


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

int main()
{
    long long dp[105];
    int N;
    cin >> N;
    dp[0] = 2, dp[1] = 1;
    for(int i = 2; i <= N; i++) {
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    cout << dp[N] << endl;

    return (0);
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  vi vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  std::cin >> k;
  std::cout << vec[k-1] << "\n";
}


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

int main(int argc, const char * argv[]) {
    int N,K;
    cin>>N>>K;
    if(N>=K && K>=1 && N<=50){
        char s[N];
    for(int i=0;i<N;i++){
        cin>>s[i];
    }
    
    if(s[K-1]=='A'){
        s[K-1] = 'a';
    }else if(s[K-1]=='B'){
        s[K-1] = 'b';
    }else if(s[K-1]=='C'){
        s[K-1] = 'c';
    }
        for(int i=0;i<N;i++){
        cout<<s[i];
        }
        cout<<endl;
    }else{
        return 0;
    }
    
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    string s, t;
    cin >> s >> t;
    int flag = 1;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) flag = 0;
    }
    if (flag) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 3652
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

n = int(input())
A = list(map(int, input().split()))
k = lcm_list(A)
r = 0
ln = list(range(n))
for i in ln:
    r += k//A[i]
print(r%(10**9+7))


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

int n, odd;
int a[100005];

int main() {
    scanf("%d", &n);
    odd = 0;
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if(a[i] & 1) odd++;
    }
    if(odd % 2 == 0) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN      
const ll mod=1e9+7;
const int N=1e5+4;

int main()                  
{
	int n,mx=0; ll ans=0;
  
  	scn(n);
  
  	rep(i,0,n)
    {
      int val; scn(val); mx=max(mx,val);
      
      ans+=(mx-val);
    }
  
  	cout<<ans;
  
    return 0;
}


Measured memory_bytes: 3688
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
vector<ll> divisor(ll n) {
	vector<ll> res;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) res.push_back(n / i);
		}
	}
	return res;
}
ll test[12345678], ok[12345678];
signed main() {
	ll n = 0, m, q, k, a = 0, b = 0, c = 0, d = 0, cnt = 0, sum = 0;
	cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> test[h]; ok[test[h]]++;
	}
	for (int h = 0; h < n; h++) {
		ll z = 0;
		vector<ll> v = divisor(test[h]);
		for (int i = 0; i < v.size(); i++) {
			if (ok[v[i]] >= 2) { 
				z++;
			}
			if (ok[v[i]] == 1 && v[i] != test[h]) {
				z++;
			}
		}
		if (z == 0) { cnt++; }
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 12812
package main

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

func main() {
	sc := NewScanner(os.Stdin)
	a, _ := sc.NextInt()
	b, _ := sc.NextInt()
	c, _ := sc.NextInt()
	d, _ := sc.NextInt()
	ans := solve(a, b, c, d)
	fmt.Println(ans)
}

const mod = 998244353

func solve(a, b, c, d int) (ans int) {
	dp := make([][]int, c+1)
	for i := range dp {
		dp[i] = make([]int, d+1)
	}
	dp[a][b] = 1
	for i := a; i <= c; i++ {
		for j := b; j <= d; j++ {
			if i == a && j == b {
				continue
			}
			tmp := j * dp[i-1][j] % mod
			tmp = (tmp + i*dp[i][j-1]%mod) % mod
			tmp = (tmp - (i-1)*(j-1)*dp[i-1][j-1]%mod + mod) % mod
			if tmp < 0 {
				panic("")
			}
			dp[i][j] = tmp
		}
	}
	return dp[c][d]
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}


Measured memory_bytes: 76856
#include <stdio.h>
#define swap(type, x, y) do{ type t = x; x = y; y = t; }while(0)
#define min(a, b) ((a)>(b) ? (b) : (a))

void quick(long a[], long b[], int left, int right){
  int pl = left, pr = right;
  long x = a[(left + right) / 2];
  do{
    while(a[pl] < x)  pl++;
    while(a[pr] > x)  pr--;
    if(pl <= pr){
      swap(long, a[pl], a[pr]);
      swap(long, b[pl], b[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(a, b, pl, right);
  if(pr > left)  quick(a, b, left, pr);
}

int main(){
  int n, m;  scanf("%d %d", &n, &m);
  long a[100005], b[100005];
  for(int i=0; i<n; i++)  scanf("%ld %ld", a+i, b+i);
  quick(a, b, 0, n-1);

  long ans = 0;
  int flag = 0;
  int juice = 0;
  while(juice < m){
    ans = ans + a[flag] * min(b[flag], m-juice);
    juice += b[flag];
    flag++;
  }
  printf("%ld\n", ans);
  return 0;
}
  


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int a,b;
    cin>>a>>b;
    cout<<a/(b*2+1)+(a%(b*2+1)!=0?1:0)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 1e5 + 7;

int ps[N];
int ps2[N];

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
		
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	for (int i = 0; i < n; i++) {
		ps[i + 1] = ps[i] + a[i];
	}
	for (int i = 0; i < n; i++) {
		ps2[i + 1] = ps2[i] + max((int)0, a[i]);
	}
	int v = ps2[n];
	int ans = 0;
	for (int i = 0; i + k <= n; i++) {
		int cv = v - (ps2[i + k] - ps2[i]);
		ans = max(ans, cv);
		// cerr << cv << ' ' << ps[i + k] - ps[i] << endl;
		ans = max(ans, cv + (ps[i + k] - ps[i]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
n = int(input())
a = list(map(str,input().split()))
b = a[::-1]
b = b[::2]
if n%2 == 0:
  c = a[::2]
else:
  c = a[1::2]
d = b+c
if n >= 2:
  print(' '.join(d))
else:
  print(a[0])

Measured memory_bytes: 27204
from math import*
n,P = map(int, input().split())
if n==1:
    print(P)
else:
    lim = int(sqrt(P))
    ans = 1
    for i in range(2,lim+1):
        cnt = 0
        while P%i==0:
            P = P//i
            cnt += 1
        while cnt>=n:
            ans *= i
            cnt -= n
    print(ans)


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

using namespace std;

int main()
{
    int k;
    cin>>k;
    if (k % 7 == 0) k /= 7;
    if (k % 2 == 0 || k % 5 == 0) {
        cout << -1 << '\n';
        return 0;
    }
    if (k == 1) {
        cout << 1 << '\n';
        return 0;
    }
    int a = 1, b = 1;
    while (b > 0) {
        b = 10 * b + 1;
        b %= k;
        a++;
    }
    cout << a << '\n';
    return 0;
}

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

class Main {

	public static void main(String[] args) {


        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String inputData;
            StringBuilder sb = new StringBuilder();
            while(true){
	            inputData = reader.readLine();
	            if("0 0".equals(inputData)){
	            	break;
	            }else{
					String[] strNumber = inputData.split(" ");
					int a = Integer.parseInt(strNumber[0]);
					int b = Integer.parseInt(strNumber[1]);
					if(a > b){
						sb.append(b + " " + a);
					}else{
						sb.append(a + " " + b);
					}
					sb.append(System.getProperty("line.separator"));
	            }
            }
            System.out.print(sb.toString());

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

}

Measured memory_bytes: 26832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=1; i<n; i++)
using namespace std;
using vi = vector<int>;
//ABC148_D
int main(){
    int n, count=0;
    cin >> n;
    vi ai(n);
    rep(i,n){
        cin >> ai.at(i); 
    }
    int j=0;
    rep(i,n){
        if (ai.at(i) == 0){
            continue;
        }
        else if (ai.at(i) != i+j+1){
            ai.at(i) = 0;
            j -= 1;
            count += 1;
        }

    }
    sort(ai.begin(), ai.end());
    if (ai.at(n-1) == 0)cout << -1 << '\n';
    else cout << count << '\n';
    return 0;
    

}

Measured memory_bytes: 4052
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007
#define ll long long
typedef int data_t;

int main(){
    char s[206];
    scanf("%s",s);
    int len=strlen(s);
    int i;
    for(i=2;i<=len-2;i+=2) {
        //s[0] to s[len-i-1]
        int k=(len-i)/2-1;
        //0-k same as k+1-2k+!
        int u;
        for(u=0;u<=k;u++){
            if(s[u]!=s[u+k+1]) break;
        }
        if(u>k){
            printf("%d\n",len-i);
            return 0;
        }
    }
    printf("%d\n",0);
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>

using namespace std;

int main()
{
  int num;
  double weight, height;
  while(scanf("%d,%lf,%lf", &num, &weight, &height) != EOF)
  {
    if(weight / (height * height) >= 25.0)
    {
      printf("%d\n", num);
    }
  }
  return 0;
}

Measured memory_bytes: 1056
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

void func(int n){
	int table[n];

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

	int ans = 2000000;

	for(int i = 0; i < n-1; i++){
		for(int k = i+1; k < n; k++){
			ans = min(ans,abs(table[i]-table[k]));
		}
	}

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

}


int main(){

	int n;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		func(n);
	}

	return 0;
}

Measured memory_bytes: 2720
#include<stdio.h>
int main(void){
int a,b,c,d;
d=0;
scanf("%d %d %d",&a,&b,&c);
for(a;a<=b;a++){
if(c%a==0){
d=d+1;
}
}
printf("%d\n",d);
return 0;
}

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

using namespace std;

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

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

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

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

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

  int N;
  string S;
  cin >> N >> S;

  set<string> st1;
  set<string> st2;
  set<string> st3;

  for(int i = 0; i < N; i++){
    
    for(auto itr = st2.begin(); itr != st2.end(); itr++){
      string ss = *itr;
      st3.insert( ss + to_string(S[i]));
    }

    for(auto itr = st1.begin(); itr != st1.end(); itr++){
      string ss = *itr;
      st2.insert( ss + to_string(S[i]));
    }
    st1.insert(to_string(S[i]));
  
  }

  cout << st3.size() << endl;

  return 0;
}


Measured memory_bytes: 384
N = int(input())
H = list(map(int, input().split()))

yesFlag = True

for i in range(len(H) - 1):
    if (H[i + 1] - H[i] > 0):
        H[i + 1] -= 1
    elif (H[i + 1] - H[i] < 0):
        yesFlag = False
    
if (yesFlag):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14252
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define sl(c) (('a')<=(c)&&(c)<=('z'))
#define ll(c) (('A')<=(c)&&(c)<=('Z'))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define PI 3.141592653589793
#define cout (cout<<fixed<<setprecision(15))
#define makeupper(t) (transform(all(t),t.begin(),::toupper))
#define makelower(t) (transform(all(t),t.begin(),::tolower))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define NEXT_LINE string junk; getline(cin, junk);
#define output(v) do{rep(i,v.size())cout<<(i?" ":"")<<v[i];cout<<"\n";}while(0)
#define output2(v) rep(i,v.size()){rep(j,v[i].size()){cout<<(j?" ":"")<<v[i][j];}cout<<"\n";}
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
int main(){
    lint n,m,p;
    cin>>n>>m>>p;
    vec a(m),b(m),c(m);
    rep(i,m)cin>>a[i]>>b[i]>>c[i];
    rep(i,m)c[i]-=p;
    rep(i,m)a[i]--;
    rep(i,m)b[i]--;
    vector<lint> diff(n,1e16);
    diff[0]=0;
    rep(k,n-1)rep(i,m){
        diff[b[i]]=min(diff[b[i]],diff[a[i]]-c[i]);
    }
    lint ans=-diff[n-1];
    rep(k,n)rep(i,m){
        diff[b[i]]=min(diff[b[i]],diff[a[i]]-c[i]);
    }
    if(ans!=-diff[n-1])cout<<-1;
    else cout<<max(0LL,ans);
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#define maxn 1000005
#define mod 998244353
using namespace std;
int n,m,fact[maxn],inv[maxn];
int C(int n,int m) { return 1ll*fact[n]*inv[m]%mod*inv[n-m]%mod; }
int powmod(int a,int n)
{
	int res=1;
	while(n)
	{
		if(n&1) res=1ll*res*a%mod;
		a=1ll*a*a%mod;
		n>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%d",&n,&m);
	if(n<m) swap(n,m);
	fact[0]=1;
	for(int i=1;i<=n+m;i++) fact[i]=1ll*fact[i-1]*i%mod;
	inv[0]=inv[1]=1;
	for(int i=2;i<=n+m;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1;i<=n+m;i++) inv[i]=1ll*inv[i-1]*inv[i]%mod;
	int tmp=499122177ll*powmod(C(n+m,n),mod-2)%mod,res=0;
	for(int i=1;i<=m;i++) res=(res+1ll*C(i*2,i)*C(n+m-i*2,m-i)%mod)%mod;
	int ans=(n+1ll*res*tmp%mod)%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,a;
  cin >> n;
  set<int> s;
  bool t=true;
  for(int64_t i=0;i<n;i++){
    cin >> a;
    s.insert(a);
  }
  if(s.size()==n)cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 12972