akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>

int main(){
	std::string s;
	std::cin >> s;
	
	int num = 0;
	int abs = 1000;
	for(int i = 0; i < s.size() - 2; ++i){
		std::string tmp = s.substr(i, 3);
		num = std::atoi(tmp.c_str());
		if(std::abs(753 - num) < abs){
			abs = std::abs(753 - num);
		}
	}
	
	std::cout << abs << std::endl;
	
	return 0;
}

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    W,H,N = MI()
    bottom = 0
    top = H
    left = 0
    right = W
    for i in range(N):
        a,b,c = MI()
        if c==1:
            left = max(left,a)
        if c==2:
            right = min(right,a)
        if c==3:
            bottom = max(bottom, b)
        if c==4:
            top = min(top, b)
    if left <= right and bottom <= top:
        print((right-left)*(top-bottom))
    else:
        print(0)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#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 (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
typedef pair<int,int>P;
vector<P>v;
int main(){
	cin>>N;
	if(N%2==1){
		REP(i,N){
			v.push_back(P(i+1,N-1-i));
		}
	}else{
		REP(i,N){
			v.push_back(P(i+1,N-i));
		}
	}
	int ans=0;
	vector<P>w;
	REP(i,N){
		for(int j=i+1;j<N;j++){
			int x=i+1;
			int y=j+1;
			bool check=false;
			REP(k,v.size()){
				if(x==v[k].first&&y==v[k].second){
					check=true;
				}
			}
			if(check==false){
				ans++;
				w.push_back(P(x,y));
			}
		}
	}
	cout<<ans<<endl;
	REP(i,ans){
		cout<<w[i].first<<" "<<w[i].second<<endl;
	}
}

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

long long h,exponent;

long long twopower(long long n){
	long long a = 1;
	for(long long i = 1;i<=n;i++){
		a = a * 2;
	}
	return a;
}

int main(){
	cin>>h;
	for(long long i = 1;i <= h;i++){
		if(h >= twopower(i)){
			exponent++;
		}else{
			break;
		}
	}
	cout<<twopower(exponent + 1) - 1<<endl;
}

Measured memory_bytes: 256
n=int(input())
a=map(int,input().split())
ans1,ans2=0,0
m1,m2=0,0
k=1
for i in a:
  m1+=i
  m2+=i
  if k:
    k=0
    if m1>=0:
      ans1+=m1+1
      m1=-1
    if m2<=0:
      ans2+=1-m2
      m2=1
  else:
    k=1
    if m1<=0:
      ans1+=1-m1
      m1=1
    if m2>=0:
      ans2+=m2+1
      m2=-1
print(min(ans1,ans2))

Measured memory_bytes: 11516
#include <iostream>
#include <string>
using namespace std;
bool c,f;
string s;
int i;
int main(){
  cin>>s;
  for(i=0;i<s.size()&&!c;i++)if(s[i]=='C')c=true;
  for(;i<s.size();i++)if(s[i]=='F')f=true;
  cout<<(f?"Yes":"No");
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n = int(input())
a = [int(i) for i in readline().split()]


m = sum(a)//n

ans = 100000000
for i in {-1,0,1}:
    res = sum((x-m-i)**2 for x in a)
    ans = min(ans,res)

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
#include <time.h>
#define l(x) x<<1
#define r(x) ((x<<1) | 1)
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int inf = 2*(1e9) + 10;
const long long MOD = 1000000009;
const int NMAX = 1000005;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};


LL a,b,c;
LL k;
int main(){
    cin>>a>>b>>c>>k;
    if(k%2){
        cout<<b-a<<"\n";
    } else {
        cout<<a-b<<"\n";
    }

    return 0;
}


Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(x):
    print(int(not x))


if __name__ == '__main__':
    # S = input()
    x = int(input())
    # N, M = map(int, input().split())
    # Ai = [int(i) for i in input().split()]
    # Bi = [int(i) for i in input().split()]
    # ABi = [[int(i) for i in input().split()] for _ in range(N)]
    solve(x)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


Measured memory_bytes: 9172
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

struct edge {
    int to, parity;
};

vector<edge> G[100100];
int N;
int color[100100];
int cnt = 0;

int rev(int c) {
    if(c == 0) return 1;
    if(c == 1) return 0;
}

void dfs(int v, int c) {
    color[v] = c;
    for(int i = 0; i < G[v].size(); i++) {
        if(color[G[v][i].to] == 0 || color[G[v][i].to] == 1) continue;

        if(G[v][i].parity == 0) {
            color[G[v][i].to] = c;
            cnt ++;
            dfs(G[v][i].to, c);
        }
        else {
            color[G[v][i].to] = rev(c);
            cnt ++;
            dfs(G[v][i].to, rev(c));
        }
    }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  rep(i, N - 1) {
      int u, v, w; cin >> u >> v >> w;
      u --; v --;
      w %= 2;
      edge es;
      es.to = v; es.parity = w;
      G[u].push_back(es);
      es.to = u;
      G[v].push_back(es);
  }
  rep(i, N) color[i] = -1;

  dfs(0, 0);
  rep(i, N) {
      cout << color[i] << "\n";
  }
  return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[3][3],flag=0;
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      {
      	cin>>a[i][j];
	  }
	 int n;
	 cin>>n;
	 int b[n];
	 for(int i=0;i<n;i++)cin>>b[i];
	 for(int k=0;k<n;k++)
	 {
	 	for(int i=0;i<3;i++)
	 	 {
	 	 	for(int j=0;j<3;j++)
	 	 	{
	 	 		if(b[k]==a[i][j])
	 	 		a[i][j]=0;
	 	 		
			  }
		  }
		  if(k>=2)
		  {
		  	if(a[0][0]==0&&a[1][1]==0&&a[2][2]==0||a[0][2]==0&&a[1][1]==0&&a[2][0]==0||a[0][0]==0&&a[0][1]==0&&a[0][2]==0)
		  	{
		  		flag=1;
		  		break;
			  }
			  if(a[0][2]==0&&a[1][2]==0&&a[2][2]==0||a[2][2]==0&&a[2][1]==0&&a[2][0]==0||a[2][0]==0&&a[1][0]==0&&a[0][0]==0)
		  	{
		  		flag=1;
		  		break;
			  }
			  if(a[1][0]==0&&a[1][1]==0&&a[1][2]==0||a[0][1]==0&&a[1][1]==0&&a[2][1]==0)
		  	{
		  		flag=1;
		  		break;
			  }
		  }
		  
	 }
	 if(flag)
	 cout<<"Yes"<<endl;
	 else
	 cout<<"No"<<endl;
	 return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int N,ans=0;
	scanf("%d",&N);
	int num[N+1];
	
	for(int i=1;i<=N;i++)num[i]=0;
	
	for(int i=0;i<N;i++){
		long long tmp;
		scanf("%lld",&tmp);
		
		if(tmp>N){
			ans++;
			continue;
		}
		
		num[tmp]++;
	}
	
	for(int i=1;i<=N;i++){
		if(num[i]>=i)ans+=num[i]-i;
		else ans+=num[i];
	}
	
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

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

    if (s.at(2) == s.at(3) && s.at(4) == s.at(5))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
s=input()
S="a"+s[::]+"a"
s=s.replace("x","")
if s[:len(s)//2]!=s[:-(len(s)//2)-1:-1]:
    print(-1)
    quit()
r=0
l=len(S)-1
ans=0
while r<l:
    R,L=0,0
    while S[r+R]=="x":
        R+=1
    while S[l-L]=="x":
        L+=1
    ans+=abs(R-L)
    r+=R+1
    l-=L+1
print(ans)

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


int main()
{
    int a; cin >> a;
    cout << a + a*a + a*a*a << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 3636
#include <iostream>

using namespace std;
#define MAX 500000
#define SEN 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt = 0;
void merges(int A[],int leftt,int midd,int rightt)
{
    int n1 = midd - leftt;
    int n2 = rightt - midd;
    int i,j,k;
    for( i = 0;i < n1;i++)L[i] = A[leftt+i];
    for(i = 0;i < n2;i++)R[i] = A[midd+i];
    L[n1] = SEN;
    R[n2] = SEN;
    i = 0,j = 0;
    for(k = leftt;k < rightt;k++)
    {
        if(L[i]<=R[j]){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        }
        cnt++;
    }
}
void mergeSort(int A[],int leftt,int rightt){
if(leftt < rightt -1){
    int midd = (leftt + rightt)/2;
    mergeSort(A,leftt,midd);
    mergeSort(A,midd,rightt);
    merges(A,leftt,midd,rightt);
}
}
int main()
{
    int n,A[500000];
    cin >> n;
    for(int i = 0;i < n;i++)
    {
        cin >> A[i];
    }
    mergeSort(A,0,n);
    for(int i = 0;i < n;i++)
    {
        if(i) cout <<" ";
        cout << A[i] ;
    }
    cout <<endl<< cnt<<endl ;
}



Measured memory_bytes: 7000
from collections import Counter
s = str(input())
l = [chr(i) for i in range(97, 97+26)]

ans = 100
for i in l:
  tmp = s
  cnt = 0
  if i in s:
    while len(Counter(tmp)) > 1:
      c = ''
      for j in range(len(tmp)-1):
        if (tmp[j]==i) or (tmp[j+1]==i):
          c += i
        else:
          c += tmp[j]
      cnt += 1
      tmp = c
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 9316
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int D;
	ll G;
	cin >> D >> G;
	int p[D];
	ll c[D];
	REP(i,D){
		cin >> p[i] >> c[i];
	}

	bool comp[D];
	ll ret=1LL<<60;
	for (ll mask = 0; mask < (1LL<<(D)); ++mask) {
//		println("---------------------");
		ll cnt = 0;
		ll sum = 0;
//		printf("mask : ");
		REP(i,D){
			comp[i] = (mask & (1LL << i))!=0;
//			printf("%d",comp[i]);
			if(comp[i]){
				cnt += p[i];
				sum += p[i]*(i+1)*100+c[i];
			}
		}
//		printf("\ninit cnt = %d, sum = %d \n",cnt,sum);
		for (int i = D-1; i >= 0; --i) {
			if(sum >= G) break;
			if(comp[i]) continue;
			ll NeededCntToGetG = CEIL(G-sum, (i+1)*100);
//			printf("needed : %d -> ",NeededCntToGetG);
			if(NeededCntToGetG >= p[i]){
				cnt += p[i]-1;
				sum += (p[i]-1)*(i+1)*100;
//				printf("+ %d * %d = %d < %d\n",(p[i]-1),(i+1)*100,sum,G);
			}else{
				cnt += NeededCntToGetG;
				sum += NeededCntToGetG * (i+1)*100;
//				printf("+ %d * %d = %d >= %d\n",NeededCntToGetG,(i+1)*100,sum,G);
				break;
			}
		}
		if(sum >= G){
//			printf("========== ret = %d\n",cnt);
			ret = min(ret,cnt);
		}
	}
//	println("=====");
	println(ret);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
  ll H, N, tmp;
  ll sum = 0;
  cin >> H >> N;
  for (ll i=0; i<N; i++){
    cin >> tmp;
    sum += tmp;
  }
  cout << (H <= sum ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const __int128 maxn = 1e18;
void scan(__int128 &x)
{
    x = 0;
    int f = 1;
    char ch;
    if((ch = getchar()) == '-') f = -f;
    else x = x*10 + ch-'0';
    while((ch = getchar()) >= '0' && ch <= '9')
        x = x*10 + ch-'0';
    x *= f;
}
void _print(__int128 x)
{
    if(x > 9) _print(x/10);
    putchar(x%10 + '0');
}
void print(__int128 x) {
    if(x < 0)
    {
        x = -x;
        putchar('-');
    }
    _print(x);
}
__int128 Abs(__int128 x) {
    return x > 0 ? x : -x;
}
int main() {
    long long a,b,c,k,ans;
cin >> a >> b >> c >> k;
    if (k&1) ans = b-a;
    else ans = a-b;
    if (abs(ans) > maxn) printf("Unfair");
    else printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 384
<?php

$s = trim(fgets(STDIN));

if(substr_count($s, 'R') == 2){
    if($s[0] == 'R' && $s[2] == 'R'){
        echo 1;
        exit;
    }else{
        echo 2;
        exit;
    }
}

echo substr_count($s, 'R');


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

using namespace std;


int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s = ' ' + s;
    int ans = 0;
    for (int i = 1; i < n; i++) {
        if (i < n && s[i] == s[i + 1]) {
            ans++;
        }
        else {
            if (!k) continue;
            k--;
            ans++;
            for (int j = i + 1; j <= n && s[j] != s[i]; j++)
                s[j] = s[i];
        }
    }
   // cout << s << "\n";
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int parent(int);
int left(int);
int right(int);

int main(){

  int n, id;
  int k[250];
  int pk, lk, rk;
 
  scanf("%d", &n);
  
  for( id=1; id<=n; id++ ) {
    scanf("%d", &k[id]);
  }

  for( id=1; id<=n; id++ ) {
    printf("node %d: key = %d, ",id, k[id]);
    if( id>1 ) {
      pk = parent(id);
      printf("parent key = %d, ",k[pk]);
    }
    lk = left(id);
    rk = right(id);
    if( lk<=n ) {
      printf("left key = %d, ",k[lk]);
    }
    if( rk<=n ) {
      printf("right key = %d, ",k[rk]);
    }
    printf("\n");
  }
  return 0;
}

int parent(int i) {
  return i/2;
}

int left(int i) {
  return 2*i;
}

int right (int i) {
  return 2*i+1;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
char s[105];

int main()
{
	int n;
	cin>>n;
	cin.ignore();
	cin.getline(s,105);
	int len = strlen(s);
	if(n>=len){
		for(int i = 0;i<len;++i)
		    cout<<s[i];
	}
	else{
		for(int i = 0;i<n;++i)
		    cout<<s[i];
		cout<<"..."<<endl;
	}
	return 0;
}

Measured memory_bytes: 3544
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n;
ll a[100010],ans[100010];
int main(){
	scanf("%lld",&n);
	rep(i,0,n)scanf("%d",a+i);
	ll s=0;
	rep(i,0,n)s+=a[i];
	ll temp=0;
	rep(i,0,n/2)temp+=a[2*i];
	ll idx=n-1;
	rep(_,0,n){
		ans[idx]=s-2*temp;
		temp+=a[idx]-a[(idx+1)%n];
		idx=(idx+2)%n;
	}
	rep(i,0,n)printf("%lld ",ans[i]);
}

Measured memory_bytes: 2816
W, H, N = map(int,input().split())
dx, dy = 0, 0

for i in range(N):
  x, y, a = map(int,input().split())
  if(a == 1):
    dx = max(dx, x)
  elif(a == 2):
    W = min(W, x)
  elif(a == 3):
    dy = max(dy, y)
  else:
    H = min(H, y)
if(W <= dx or H <= dy):
  print(0)
else:
  print((dx-W) * (dy-H))


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

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

struct Edge{
  int u,v,cost;
  Edge(int a=0,int b=0,int c=0){ u=a;v=b;cost=c; }
  bool operator<(const Edge& a)const{ return cost < a.cost; }
};

struct UnionFind{
  int par[128];
  int rank[128];
  int s;

  UnionFind(int n){ init(n); }
  void init(int n){
    s = n;
    for(int i=0;i<n;i++){
      par[i] = i;
      rank[i] = 0;
    }
  }
  int find(int x){ return (x==par[x]?x:par[x] = find(par[x])); }
  int same(int x,int y){ return find(x)==find(y); }
  int size(){ return s; }
  void unite(int x, int y){
    x = find(x); y = find(y);
    if(x==y) return;
    s--;
    if(rank[x] < rank[y]){
      par[x] = y;
    }else{
      par[y] = x;
      if(rank[x] == rank[y]) rank[x]++;
    }
  }
};

int N,M;
Edge es[5000];

int main(){
  while(scanf("%d%d",&N,&M) && N||M){
    rep(i,M){
      int a,b,w;
      scanf("%d%d%d",&a,&b,&w); a--; b--;
      es[i] = Edge(a,b,w);
    }
    
    sort(es, es + M);
    int res = INF;
    rep(i,M){
      UnionFind uf(N);
      for(int j=i;j<M;j++){
	Edge e = es[j];
	if(!uf.same(e.u, e.v))  uf.unite(e.u, e.v);
	if(uf.size() == 1) res = min(res, es[j].cost-es[i].cost);
      }
    }

    printf("%d\n", res==INF?-1:res);
  }
  return 0;
}

Measured memory_bytes: 1248
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    vector<int> a(n+2);
    rep(i, n) cin >> a[i+1];
    n += 2;

    auto dp = initVec2<int>(n + 1, 5, INF);
    dp[0][0] = 0;
    rep(i, n){
        rep(j, 5){
            for(int k = j; k < 5; k++){
                if(k == 0 || k == 4){
                    dp[i+1][k] = min(dp[i+1][k], dp[i][j] + a[i]);
                    continue;
                }
                if(k == 2){
                    dp[i+1][k] = min(dp[i+1][k], dp[i][j] + (a[i] + 1) % 2);
                    continue;
                }
                if(a[i] != 0){
                    dp[i+1][k] = min(dp[i+1][k], dp[i][j] + a[i] % 2);
                }else{
                    dp[i+1][k] = min(dp[i+1][k], dp[i][j] + 2);
                }
            }
        }
    }

    cout << dp[n][4] << endl;

    return 0;
}


Measured memory_bytes: 15872
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;

const int MAX_N = 1505;
const int MAX_M = 1505;

int h[MAX_N];
int w[MAX_M];

void solve(int n, int m) {
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
        h[i] += h[i - 1];
    }
    for (int i = 1; i <= m; i++) {
        cin >> w[i];
        w[i] += w[i - 1];
    }
    map<int, ll> cnt;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            cnt[h[j] - h[i - 1]]++;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = i; j <= m; j++) {
            ans += cnt[w[j] - w[i - 1]];
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    while (true) {
        cin >> N >> M;
        if (N == 0 && M == 0) break;
        solve(N, M);
    }
    return 0;
}


Measured memory_bytes: 26888
#include <stdio.h>

int main(){
  int x,y;
  int temp;
  scanf("%d %d",&x,&y);
  if(y>x){
    temp = x;
    x = y;
    y = temp;
  }
  while(x%y!=0){
    x = x%y;
    temp = x;
    x = y;
    y = temp;
  }
  printf("%d\n",y);
  return 0;
}


Measured memory_bytes: 2144
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var a = ReadLine();
            var list = new List<long>();

            for (int i = 0; i < n; i++)
            {
                if (a[i] == list.Count + 1)
                {
                    list.Add(a[i]);
                }
            }

            if (Resolve(list) == false)
            {
                Console.WriteLine("-1");
            }
            else
            {
                Console.WriteLine(n - list.Count);
            }
        }

        static bool Resolve(List<long> list)
        {
            if (list.Count == 0)
            {
                return false;
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i] != i + 1)
                {
                    return false;
                }
            }

            return true;
        }

        static List<long> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => long.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 38224
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<int> p(n),a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> p[i];
    a[p[i]-1]=(n+5)*p[i];
    b[p[i]-1]=(n+5)*(n+1-p[i])+i;
  }
  for(int i=0;i<n;i++){
    cout << a[i] << " ";
  }
  cout << endl;
  for(int i=0;i<n;i++){
    cout << b[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long long int gcd(long long int a, long long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long long int lcm(long long int a, long long int b){
  return a * b / gcd(a, b);
}

// 10min
int main(void){
  int k, x;
  int min, max;
  
  scanf("%d%d", &k, &x);

  min = x - k + 1;
  if(min < -1000000){
    min = -1000000;
  }

  max = x + k - 1;
  if(max > 1000000){
    max = 1000000;
  }

  for(int i = min; i <= max; i++){
    printf("%d ", i);
  }

  printf("\n");
  return 0;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a != 1 && b != 1) {
		if (a < b) {
			cout << "Bob" << endl;
		}
		else if(a>b) {
			cout << "Alice" << endl;
		}
		else {
			cout << "Draw" << endl;
		}
	}
	else {
		if (a < b) {
			cout << "Alice" << endl;
		}
		else if(a>b){
			cout << "Bob" << endl;
		}
		else {
			cout<<"Draw"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long a,b,c,d;
   cin>>a>>b>>c>>d;
   /*if(a>0 && b>0 && c>0 && d>0)
    cout<<b*d<<endl;
   else if(a<0 && b<0 && c<0 && d<0)
   cout<<b*d<<endl;
   else if (a>0 && b>0 && c<0 && d<0)
    cout<<a*c<<endl;
    */
    long long sum1=a*c;
   long long sum2=a*d;
   long long sum3=b*c;
   long long sum4=b*d;
   long long maxi=max(max(sum1,sum2),max(sum3,sum4));
   cout<<maxi<<endl;
}


Measured memory_bytes: 3636
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> k >> n;
  rep(i, n) cin >> a[i];
  ans = a[n - 1] - a[0];
  rrep(i, 1, n) { ans = min(ans, a[n - 1] - a[i] + k - a[n - 1] + a[i - 1]); }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	x := iSScan(n)
	y := make([]int, n)
	copy(y, x)
	sort.Ints(y)
	p, q := y[n/2-1], y[n/2]
	for _, v := range x {
		if v <= p {
			fmt.Println(q)
		} else {
			fmt.Println(p)
		}
	}
}


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

int main()
{
	string s;
	cin>>s;
	int a=(s[0]%48);
	int Y=(a*10)+(s[1]%48);
	int M=((s[2]%48)*10)+(s[3]%48);
	
	 if(((Y>=1)&&(Y<=12))&&((M>=1)&&(M<=12)))
    {
        cout<<"AMBIGUOUS";
    }
    else
    {
        if((Y>=1)&&(Y<=12))

        {
            cout<<"MMYY";
        }
        else if((M>=1)&&(M<=12))

        {
            cout<<"YYMM";
        }
        else
        {
            cout<<"NA";
        }
    }
}

Measured memory_bytes: 3600
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N, D, A = map(int, input().split())
a = []
b = []
res = 0
for _ in range(N):
  x, h = map(int, input().split())
  a.append([x, h])
  b.append(x)
a.sort(key = lambda x: x[0])
b.sort()
imos = [0] * (N + 2)
for i in range(N):
  a[i][1] += imos[i]
  imos[i + 1] += imos[i]
  if a[i][1] <= 0: continue
  l = a[i][0]
  r = a[i][0] + 2 * D
  t = bl(b, r)
  if t < N:
    if b[t] > r: t -= 1
  x = -(-a[i][1] // A)
  imos[i + 1] -= A * x
  imos[t + 1] += A * x
  a[i][1] = 0
  res += x
  #print(i, t)
  #print(a, imos)
#print(imos)
#print(a)
print(res)

"""
AtCoderレートで全ての優劣が決定される異世界ベラルーシ。
ここでは他世界からの転生者は「旅行者 - tourist -」と呼ばれる。

不幸な交通事故から、社長 高橋直小はベラルーシに異世界転生してしまった。
"""

Measured memory_bytes: 94448
import sys

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

coord = [a, b, c, d, e]
flag = False
for i in range(len(coord)):
    for j in range(len(coord)):
        dis = abs(coord[i] - coord[j])
        if dis > k :
            flag = True
if flag == True :
    print(":(")
else :
    print("Yay!")

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		final Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		
		long[] pos = new long[n + 1];
		for(int i = 0; i < n; i++){
			pos[i + 1] = sc.nextLong();
		}
		pos[0] = -1;
		
		int any_order = n;
		long answer = 1;
		
		for(int i = 1; i <= n; i++){
			final long prev_diff = pos[i] - pos[i - 1];
			
			if(prev_diff <= 1){
				answer *= i - (n - any_order);
				answer %= 1000000007;
				any_order -= 1;
					
				pos[i] = pos[i - 1];
			}else{
				pos[i] = pos[i - 1] + 2;
			}
		}
		
		//System.out.println(any_order + " " + Arrays.toString(pos));
		
		
		for(int i = 1; i <= any_order; i++){
			answer *= i;
			answer %= 1000000007;
		}
		
		System.out.println(answer);
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
		
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 37460
from collections import Counter

def factoring(N, factor_prev):
    '''
    input:
    N, factor_prev: 素因数分解すべきN, Nまでに存在する素数のリスト
    output
    N_dict, factor_list: Nの素因数分解の辞書: 例えば12の場合{2: 2, 3: 1}, Nが素数の場合はfactor_prevにNを追加して返す。Nが素数でない場合は引数を返す。
    '''
    
    factor_list = factor_prev
    N_dict = {}
    
    while True:
        if N == 1:
            return N_dict, factor_list
        
        for factor in factor_prev:
            if N % factor == 0:
                N = N // factor
                
                # 集計部分
                if factor in N_dict:
                    N_dict[factor] += 1
                    break
                    
                else:
                    N_dict[factor] = 1
                    break
                    
            #素数の場合
            if factor == factor_prev[-1] and N % factor != 0:
                factor_list.append(N)
                N_dict[N] = 1
                return N_dict, factor_list
              
def factorial_factoring(N):
    # 例外処理
    if N == 1:
        return {2: 0}
    
    else:
        factorial_factoring_dict = {}
        
        for i in range(2, N+1):
            if i == 2:
                N_dict = {2: 1}
                factor_prev = [2]
                factorial_factoring_dict = Counter(factorial_factoring_dict) + Counter(N_dict)
            else:
                N_dict, factor_prev = factoring(i, factor_prev)
                factorial_factoring_dict = Counter(factorial_factoring_dict) + Counter(N_dict)
    
    return(factorial_factoring_dict)
  
divisor = 1
mod = 1000000007
N = int(input())
for _, v in factorial_factoring(N).items():
    divisor = divisor * (v + 1)
print(divisor % mod)

Measured memory_bytes: 3316
#include<iostream>
using namespace std;
int main(){
  unsigned int H, W;
  while(cin>>H>>W && H !=0 && W!=0) {
    for(int i=0; i<H; i++) {
      for(int j =0; j<W; j++) cout << '#';
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3084
N = int(input())
b = list(map(int,input().split()))
B = len(b)
ans = []
can_t = 0
for i in range(B):
	if can_t == 0:
		judge = 0
		j = 0
		while judge == 0:
			if len(b)- 1 - j < 0:
				can_t = 1
				judge = 1
			elif b[len(b)-j-1] == len(b)-j:
				judge = 1
				ans.append(len(b)-j)
				del b[len(b)-1-j]
			else:
				j += 1

				
if len(ans) == N:
	for i in range(N):
		print(ans[N-1-i])
else:
	print(-1)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		
		int res = 0;
		for (int i=0; i<=A; i++) {
			for (int j=0; j<=B; j++) {
				for (int k=0; k<=C; k++) {
					int t = 500*i + 100*j + 50*k;
					if (t==X) res ++;
				}
			}			
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 22608
#include<bits/stdc++.h>
#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
using namespace std;
#define ll long long
#define fr(n) for(ll i = 0; i < n; i++)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    string s1,s2;
    cin >> s1 >> s2;
    int l1 = s1.length();
    int l2 = s2.length();
    int c[l1+1][l2+1];
    string lcs = "";
    for(int i = 0; i <= l1; i++) c[i][0] = 0;
    for(int i = 0; i <= l2; i++) c[0][i] = 0;
    for(int i = 1; i <= l1; i++){
        for(int j = 1; j <= l2; j++){
            if(s1[i-1] == s2[j-1]){
                c[i][j] = c[i-1][j-1] + 1;
            }else{
                c[i][j] = max( c[i-1][j] , c[i][j-1] );
            }
        }
    }
    
    int i = l1; int j = l2;
    while(i >= 1 && j >= 1){
        // trace(i,j);
        if( c[i][j] > c[i-1][j] && c[i][j] > c[i][j-1]){
            lcs += s1[i-1];
            i--;j--;
        }else if( c[i-1][j] > c[i][j-1] ){
            i--;
        }else{
            j--;
        }
        
        trace(i,j);
    }
    //cout << lcs << endl;
    for(int i = lcs.length()-1; i >= 0; i-- ) cout << lcs[i];


    
    
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    string s;
    int r;
    for (getline(cin, s); s != "0"; getline(cin, s)) {
        r = 0;
        for (auto c: s) {
            r += c - '0';
        }
        cout<<r<<endl;;
    }
}



Measured memory_bytes: 3196
import math as ma
n=int(input())
m=0
for i in range (n):
    a = int(input())
    if a==2:
        m+=1
    if a>2:
        for j in range(2,int(ma.sqrt(a))+2):
            if a%j==0:
                break
            if j ==int(ma.sqrt(a))+1:
                m+=1
print(m)


Measured memory_bytes: 5676
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

int main(){
    int n , m;
    cin >> n >> m;
    vector<int> a(n);
    REP(i, 0, n){
        cin >> a.at(i);
    }
    int s = accumulate(a.begin(), a.end(), 0);
    sort(a.begin(), a.end());
    float tmp = (float(s)/(4*m));
    if(a[n-m] < tmp){p("No");}
    else{p("Yes");}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(void)
{
	while(1)
	{
	int a,b;
	scanf("%d",&b);
	if(b==0){break;}
	for(int i=0;i<9;i++){
		scanf("%d",&a);
		b-=a;
	}
	printf("%d\n",b);
	}
	return 0; 
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vector<string> va;

void input() {
  ;
  ;
  cin>>N;
  va.resize(N);
  rep(i,0,N-1){
    cin>>va[i];
  }
}
void solve() {
  set<string> st;
  for(auto x : va){
    st.insert(x);
  }
  cout<<st.size()<<endl;
  ;

  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 25016
inf = 10**9+7

n = int(input())
dp = [inf for i in range(n+1)]
dp[0] = 0
tmp = 1
use = [1]
while tmp*6 <= n:
    tmp *= 6
    use.append(tmp)
tmp = 1
while tmp*9 <= n:
    tmp *= 9
    use.append(tmp)
use.sort()

for i in range(n):
    for num in use:
        if i+1-num >= 0:
            dp[i+1] = min(dp[i+1], dp[i+1-num]+1)
        else:
            break
print(dp[n])

Measured memory_bytes: 45040
n,m = gets.split(" ").map(&:to_i)
dp = Array.new(m){Array.new(n+1,0)}
coins = gets.split(" ").map(&:to_i)
#coins ??????
coins.each_with_index do |coin,index|
  #???????????????????????????
  (n+1).times do |value|
    #?????¨??????coin??????????????????????????????????¶???????????????????
    case
    when index >= 1 && value-coin > 0
      #???????????£?????????????????¨???
      dp[index][value] = [dp[index-1][value], dp[index][value-coin]+1].min
    when value-coin == 0
      #coin????????????????????????0??????1?????\??????
      dp[index][value] = 1
    when index == 0 && value-coin > 0
      #?????????????????????????????¨???
      dp[index][value] = dp[index][value-coin]+1
    when index >= 1 && !(value-coin > 0)
      #???????????£?????????????????¨???
      dp[index][value] = dp[index-1][value]
    end
  end
end
puts dp[m-1][n]

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

template <typename T>
struct BinaryIndexedTree{
// アーベル群に対応するデータ構造
// 1要素更新:O(logN), 区間クエリ:O(logN)
  vector<T> BIT;

  BinaryIndexedTree(int N): BIT(N+1){}

  void add(int idx, T diff){
    for(int i=idx; i<BIT.size(); i+= i&-i){
      BIT.at(i)+= diff;
    }
  }

  T cumulative(int right){// [1, right)
    T ans= 0;
    for(int i=right-1; i>0; i-= i&-i){
      ans+= BIT.at(i);
    }
    return ans;
  }

  T range(int left, int right){// [left, right)
    return cumulative(right)- cumulative(left);
  }

  void set_val(int idx, int val){
    int a_i= range(idx, idx+ 1);
    add(idx, val- a_i);
  }
};

int main(){ // 各アルファベットcについてa_c(i)= (S(i)==c) ? 1 : 0 なる数列を考える。
            // 「S[l,r]にcが登場する <=> a_c[l,r]の区間和が正」に着目して、a_cに対応するBITを保持するアプローチ
  const int Nab= 26;
  int N;
  string str;
  cin >> N >> str;

  vector<BinaryIndexedTree<int>> data(Nab, BinaryIndexedTree<int>(N));
  for(int i=0; i<N; i++){
    data.at(str.at(i)-'a').set_val(i+1, 1); // 1-indexed
  }

  int Q;
  cin >> Q;

  int query,buf1,buf2;
  char bufc;
  for(int i=0; i<Q; i++){
    cin >> query;
    if(query==1){
      cin >> buf1 >> bufc;
      for(int j=0; j<Nab; j++){
        data.at(j).set_val(buf1, 0);
      }
      data.at(bufc-'a').set_val(buf1, 1);
    }
    else{
      cin >> buf1 >> buf2;
      int ans= 0;
      for(int j=0; j<Nab; j++){
        if(data.at(j).range(buf1, buf2+1) > 0){ ans++; }
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 53636
import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static int gcd(int a, int b) {
        if(a < b) return gcd(b,a);
        if(b == 0) return a;
        return gcd(b,a%b);
    }

    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer k = Integer.parseInt(scanner.next());

        int ans = 0;
        for(int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 36160
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

ll N, M;
string s;

int main(void) {
  cin >> N >> M;
  cin >> s;
  ll i;
  
  for(i=0; i<=(N-1)/2; i++) {
    swap(s[i], s[N-i]);
  }
  
  ll pos=0;
  vector<ll> res;
  while(pos<N) {
    ll f=1;
    for(i=min(M, N-pos); i>=1; i--) {
      if(s[pos+i]=='0') {
        pos+=i;
        res.pb(i);
        f=0;
        break;
      }
    }
    
    if(f) {
      pt(-1);
      return 0;
    }
    
  }
  
  for(i=0; i<res.size(); i++) {
    pt(res[(ll)res.size()-i-1]);
  }

}


Measured memory_bytes: 1528
#include<iostream>
#include<algorithm>
using namespace std;
int a,b;
int main(){
	cin>>a>>b;
	if(a<=0 && b>=0)cout<<"Zero"<<endl;
	else if(a<0 && (min(-1,b)-a)%2==0)cout<<"Negative"<<endl;
	else{cout<<"Positive"<<endl;}
}

Measured memory_bytes: 256
# coding=utf-8
# Date: 2020-01-08
# Author: lee215

get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]


H, N = gets()
A = gets()
if sum(A) >= H:
    print 'Yes'
else:
    print 'No'


Measured memory_bytes: 11292
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)

int main(){
	string str;
	cin >> str;
	for(int i = 0; i < str.size(); i++){
		if('A' <= str[i] && str[i] <= 'C')str[i] = str[i]+('X'-'A');
		else str[i] = str[i] - 3;
	}
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define stdi(in) freopen(in, "r", stdin)
#define stdo(out) freopen(out, "w", stdout)
#define stdio(in, out) stdi(in); stdo(out)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define MAX 1000007
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
//typedef int ittt;
//#define int ll


using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ordered_set tree<int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

const ll inf = 1e18;

ll hit[MAX][3];
ll dp[MAX][3];
int n;

ll solve(int i, int ch){
	//cerr<<"solve\n";
	if(i>n){
		return 0;
	}

	if(ch!=-1 && dp[i][ch]!=-1) return dp[i][ch];
	ll ans = 0;

	if(ch==-1){
		ans = max(hit[i][1]+solve(i+1, 1), hit[i][2]+solve(i+1, 2));
		ans = max(hit[i][0]+solve(i+1, 0), ans);
	}

	if(ch==0){
		ans = max(hit[i][1]+solve(i+1, 1), hit[i][2]+solve(i+1, 2));
	}

	if(ch==1){
		ans = max(hit[i][0]+solve(i+1, 0), hit[i][2]+solve(i+1, 2));
	}

	if(ch==2){
		ans = max(hit[i][1]+solve(i+1, 1), hit[i][0]+solve(i+1, 0));
	}

	return dp[i][ch] = ans;

}

int main(){
    /*#ifndef ONLINE_JUDGE
        stdio("in", "out");
    #endif*/
    fast;
    cin>>n;

    dp[0][0] = dp[0][1] = dp[0][2] = -1;

    for(int i=1;i<=n;i++){
    	cin>>hit[i][0]>>hit[i][1]>>hit[i][2];
    	dp[i][0] = dp[i][1] = dp[i][2] = -1;
    }

    ll ans = solve(0, -1);
    cout<<ans<<'\n';
    
    return 0;
}

Measured memory_bytes: 14720
N, L, T = map(int, input().split())
X = [0] * N
W = [0] * N
for i in range(N):
    X[i], W[i] = map(int, input().split())

res = [0] * N
c = 0
for i in range(N):
    if W[i] == 1:
        res[i] = (X[i] + T) % L
        c += (X[i] + T) // L
    else:
        res[i] = (X[i] - T) % L
        c += (X[i] - T) // L
res = sorted(res)
c = c % N
res = res[c:] + res[:c]
print(*[ans for ans in res], sep='\n')

Measured memory_bytes: 15052