akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod=998244353;

#define pb push_back
#define mp make_pair


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

    ll t,n,x,y;
    cin>>n>>x>>y;
    ll k=n-y+x+1,a[10000];
    for(ll i=1;i<n;i++){
        a[i]=max(0LL,k-1);
        k--;
    }
    for(ll i=x+1;i<y;i++){
        for(ll j=1;j<x;j++){
            ll s=min(i-j,x-j+1+y-i);
            a[s]++;
        }
        for(ll j=y+1;j<=n;j++){
            ll s=min(j-i,i-x+1+j-y);
            a[s]++;
        }
    }
    for(ll i=x;i<=y;i++){
        for(ll j=i+1;j<=y;j++){
            if(i==x && j==y)
                continue;
            ll s=min(j-i,i-x+y-j+1);
            a[s]++;
        }
    }
    for(ll i=1;i<n;i++)
        cout<<a[i]<<"\n";

    return 0;
}




Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    string s; cin >> s ;
    vector<int> v(2,0);
    rep(i,s.size()){
        v[s[i]-'0']++;
    }
    cout << min(v[0],v[1])*2 << endl;


    return 0;
}

Measured memory_bytes: 512
h,w=map(int,input().split())
mod=10**9+7
T=[]
for i in range(h):
  T.append(input())
DP=[[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if i==0:
      if j==0:
        DP[i][j]=1
      elif T[i][j]=="#":
        DP[i][j]=0
      else:
        DP[i][j]=DP[i][j-1]
    else:
      if j==0:
        if T[i][j]=="#":
          DP[i][j]=0
        else:
          DP[i][j]=DP[i-1][j]
      else:
        if T[i][j]=="#":
          DP[i][j]=0
        else:
          DP[i][j]=(DP[i-1][j]+DP[i][j-1])%mod
print(DP[h-1][w-1])


Measured memory_bytes: 51824
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int e[200000][3];
long d[100001];
int search(int x, int l, int r){
	while(l<=r){
		int m=(l+r)/2;
		if(e[m][0]>=x) r=m-1; else l=m+1;
	}
	return l;
}

int main(void){
	int n, i;
	scanf("%d", &n);
	for(i=0; i<n-1; i++){
		int A, B, C;
		scanf("%d%d%d", &A, &B, &C);
		e[i*2][0]=A; e[i*2][1]=B; e[i*2][2]=C;
		e[i*2+1][0]=B; e[i*2+1][1]=A; e[i*2+1][2]=C;
	}
	qsort(e, (n-1)*2, sizeof(int)*3, comp);

	int s[100000], S=0;
	d[1]=0;
	s[S++]=1;
	while(S>0){
		int p=s[--S];
		i=search(p, 0, (n-1)*2-1);
		for(; e[i][0]==p; i++){
			if(d[e[i][1]]==0){
				d[e[i][1]] = d[p] + e[i][2];
				s[S++]=e[i][1];
			}
		}
	}
	d[1]=0;
	for(i=1; i<=n; i++){
		printf("%d\n", d[i]&1);
	}
}



Measured memory_bytes: 4860
#pragma region

#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int N;
  cin >> N;

  vector<vector<ll>> table(9, vector<ll>(9, 0));

  rep(i, 1, 10) rep(j, 1, 10) {
    if (i * 10 + j <= N) table[i - 1][j - 1]++;
    rep(k, 1, 5) {
      int t = i * pow(10, k + 1) + j;
      rep(l, pow(10, k)) {
        if (t + l * 10 <= N) table[i - 1][j - 1]++;
      }
    }
  }

  ll ans = 0;
  rep(i, 9) rep(j, 9) {
    ans += table[i][j] * table[j][i];
  }
  rep(i, 1, 10) {
    if (i <= N) ans++;
    ans += table[i - 1][i - 1] * 2;
  }

  out(ans);
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

//#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
//#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
//#include <atomic>
#include <chrono>
//#include <condition_variable>
#include <forward_list>
//#include <future>
#include <initializer_list>
//#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
//#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main ()
{
	//FILE* fp_in = freopen ( "2011-input.txt" , "r" , stdin );
	//FILE* fp_out = freopen ( "result.txt" , "w" , stdout );
	int N;
	while( cin >> N , N )
	{
		bool f = 1;
		vector<vector<int>>data ( 31 );
		for( int i = 0; i < N; i++ )
		{
			int a;
			cin >> a;
			for( int j = 0; j < a; j++ )
			{
				int b;
				cin >> b;
				data[b].push_back ( i );
			}
		}
		long long int dp[31][51] = {};
		for( int i = 0; i < N; i++ )
		{
			dp[0][i] = 1ll << i;
		}
		for( int i = 1; i < 31; i++ )
		{
			long long int sum = 0;
			for( auto x : data[i] )
			{
				sum |= dp[i - 1][x];
			}
			for( auto x : data[i] )
			{
				dp[i][x] = sum;
			}
			for( int j = 0; j < N; j++ )
			{
				if( !dp[i][j] )
				{
					dp[i][j] = dp[i - 1][j];
				}
			}
			if( sum == ( 1ll << N ) - 1 )
			{
				cout << i << endl;
				f = 0;
				break;
			}
		}
		if( f )
		{
			cout << -1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
 
int main() {
  int H,N; cin >>H>>N;
  vector<int> A(N);
  int sum=0;
  rep(i,N){
    cin>>A.at(i);
    sum=sum+A.at(i);
  }
  if(sum>=H){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

int main() {
	string str1, str2;
	cin >> str1 >> str2;
	bool same = true;
	const int n = str1.size();
	
	for(int i = 0; i < n; ++i) {
		if(str1[i] != str2[i]) {
			same = false;
			break;
		}
	}
	
	if(same) {
		cout << "Yes";
	} else {
		cout << "No";
	}
}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
   int n,m,sum=0,a,b[110],t=0;
   cin>>n>>m;
   for(int i=1;i<=n;i++)  cin>>b[i], sum+=b[i];
   a=sum/(4*m);
   for(int i=1;i<=n;i++) 
   {
      if(b[i]*4*m>=sum) t++; 
   } 
   if(t>=m)cout<<"Yes";
      	else cout<<"No";


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Blue ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,n) for(int i=a;i<n;++i)
typedef vector<int> vi;
typedef long long ll;
const int mod=1e9+7;
 
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

void solve(){
	int n;
	cin>>n;
	vi a(n);
	bool ok=1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(!(a[i]&1)){
			if(!(a[i]%3==0 || a[i]%5==0))ok=0;
		}
	}
	cout<<(ok?"APPROVED":"DENIED");
 
}
 
 
int main(){
	Blue;
	int test=1;
	//cin>>test;
	while(test--)
		solve();
	return 0;
}

Measured memory_bytes: 3568
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_1-A: Insertion Sort

#include <iostream>

static void print_ints(const int as[], const unsigned int n)
{
  const char* sep = "";
  for (unsigned int i = 0; i < n; ++i) {
    std::cout << sep << as[i];
    sep = " ";
  }
  std::cout << std::endl;
}

static void insert(int as[], const unsigned int i)
{
  // as[0..i-1] is sorted
  const auto asi = as[i];
  auto j = i;
  while (j >= 1 && asi < as[j-1]) {
    as[j] = as[j-1];
    --j;
  }
  as[j] = asi;
}

static void insertion_sort(int as[], const unsigned int n)
{
  for (auto i = 1u; i < n; ++i) {
    print_ints(as, n);
    insert(as, i);
  }
}

int main()
{
  unsigned int n;
  std::cin >> n;
  int as[n];
  for (auto i = 0u; i < n; ++i) {
    std::cin >> as[i];
  }

  insertion_sort(as, n);
  print_ints(as, n);
}

// eof

Measured memory_bytes: 3084
fun main (args: Array<String>) {
	readLine()
	val list = readLine()!!.split(" ").map(String::toInt)
	
	var num : Int
	var calc : Int
	
	var scoreA : Int = 0
	var scoreB : Int = 0
	
	var sort : MutableList<Int> = mutableListOf()
	
	for (i in 0..list.size - 1) {
		num = list[i]
		sort.add(num)
		
	}
	
	for (i in 0..list.size - 1) {
		
		for (j in 0..i) {
			
			if (sort[j] < sort[i]) {
				calc = sort[j]
				sort[j] = sort[i]
				sort[i] = calc
				
			}
			
		}
		
	}
	
	for (i in 0..list.size - 1) {
		num = sort[i]
		
		if (i == 0 || i % 2 == 0) {
			scoreA += num
		} else {
			scoreB += num
		}
		
	}
	
	println("${scoreA - scoreB}")
	
}

Measured memory_bytes: 37864
f = open(0)
N, M, L = map(int, f.readline().split())
A = [list(map(int, f.readline().split())) for i in range(N)]
B = [list(map(int, f.readline().split())) for i in range(M)]
C = [[0]*L for i in range(N)]
for i in range(N):
    for j in range(L):
        C[i][j] = str(sum(A[i][k]*B[k][j] for k in range(M)))
for line in C:
    print(*line)


Measured memory_bytes: 7280
#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;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}
vector<vector<lli>> a;
vector<lli> dp;
vector<lli> godp;
vector<bool> vis;
lli n;
void filldp(){
	dp[0]=0;

	for(lli mask=1;mask<(1<<n);mask++){
		lli tmp=0;
		for(lli i=0;(1<<i)<=mask;i++){
			if((mask&(1<<i))==0)continue;
			
			for(lli j=0;(1<<j)<=mask;j++){
				if((mask&(1<<j))==0)continue;
				tmp+=a[i][j];
			}
		}
		dp[mask]=tmp/2;
	}
}
lli go(lli x){
	if(num1bit(x)==1)return godp[x]=0;
	if(vis[x])return godp[x];
	vis[x]=1;
	lli ret=dp[x];
	for(int ss=(x-1)&x;ss>0;ss=(ss-1)&x){
		ret= max ( ret,dp[ss]+go(x-ss));
	}
	return godp[x]=ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	a.assign(n,vector<lli>(n,0));
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>a[i][j];
	dp.assign((1<<n),-1e18);
	godp.assign((1<<n),-1e18);
	vis.assign((1<<n),0);
	filldp();
	cout<<go((1<<n)-1)<<endl;
	// if(n==4){
	// 	printvec(dp);
	// 	cout<<endl;
	// 	printvec(godp);
	// }
}


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

using namespace std;

int main(){
	string s;
	string s1;
	cin>>s>>s1;
	for(int i=0;i<s.length();i++){
		if(s[i] != s1[i]){
			cout<<"No"<<endl;
			return 0; 
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 3624
s = input()
pre = int(s[:2])
suf = int(s[2:])
if 0 < pre <= 12 and 0 < suf <= 12:
  print('AMBIGUOUS')
elif 0 < suf <= 12:
  print('YYMM')
elif 0 < pre <= 12:
  print('MMYY')
else:
  print('NA')

Measured memory_bytes: 3060
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

#define P 1000000007

char s[2][500][501];
int main(void){
	int h=nextint();
	int w=nextint();
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(i==0){
				s[0][i][j]='.';
				s[1][i][j]='#';
			}else if(i==h-1){
				s[0][i][j]='#';
				s[1][i][j]='.';
			}else if(j%2==0){
				s[0][i][j]='.';
				s[1][i][j]='#';
			}else{
				s[0][i][j]='#';
				s[1][i][j]='.';
			}
			char c=getchar();
			if(c=='#'){
				s[0][i][j]='#';
				s[1][i][j]='#';
			}
		}
		getchar();
	}
	for(int i=0; i<h; i++){
		puts(s[0][i]);
	}
	putchar(10);
	for(int i=0; i<h; i++){
		puts(s[1][i]);
	}
}


Measured memory_bytes: 1152
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
import queue

N, M = map(int, input().split())
if M == 0:
    print(-1)
    exit()
adj = [[] for _ in range(N)]
for i in range(M):
    u, v = map(int, input().split())    
    u -= 1
    v -= 1
    adj[u].append(v)
S, T = map(int, input().split())
S -= 1
T -= 1

dist = [[INF,INF,INF] for _ in range(N+1)]
 
q = queue.Queue()
q.put((S, 0))
dist[S][0] = 0
while not q.empty():
    u, l = q.get()
    for v in adj[u]:
        nl = (l + 1) % 3
        if dist[v][nl] != INF:
            continue
        dist[v][nl] = dist[u][l] + 1
        q.put((v, nl))
d = dist[T][0]
answer = -1 if d == INF else d // 3
print(answer)




Measured memory_bytes: 42760
#include<set>
#include<queue>
#include<cstdio>

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

using namespace std;

struct board{
	int a[4][8];
	bool operator<(const board &B)const{
		rep(i,4) rep(j,8) if(a[i][j]!=B.a[i][j]) return a[i][j]<B.a[i][j];
		return false;
	}
};

bool isgoal(const board &B){
	rep(i,4) rep(j,7) if(B.a[i][j]!=(i+1)*10+(j+1)) return false;
	return true;
}

int main(){
	int T; scanf("%d",&T);
	while(T--){
		board B0;
		rep(i,4){
			B0.a[i][0]=(i+1)*10+1;
			rep(j,7){
				int a; scanf("%d",&a);
				B0.a[i][j+1]=(a%10==1?-1:a);
			}
		}

		set<board> Vis; // すでに訪れた盤面
		Vis.insert(B0);

		int ans=-1;
		queue< pair<int,board> > Q;
		Q.push(make_pair(0,B0));
		while(!Q.empty()){
			int t=Q.front().first;
			board B=Q.front().second; Q.pop();

			if(isgoal(B)){ ans=t; break; }

			static int x[48],y[48];
			rep(i,4) rep(j,8) if(B.a[i][j]!=-1) {
				x[B.a[i][j]]=j;
				y[B.a[i][j]]=i;
			}
			rep(i,4) rep(j,8) if(B.a[i][j]==-1) {
				int left=B.a[i][j-1];
				if(left%10<7 && left!=-1){
					int tmp=B.a[y[left+1]][x[left+1]];
					B.a[i][j]=left+1;
					B.a[y[left+1]][x[left+1]]=-1;

					if(Vis.count(B)==0){
						Vis.insert(B);
						Q.push(make_pair(t+1,B));
					}

					B.a[i][j]=-1;
					B.a[y[left+1]][x[left+1]]=tmp;
				}
			}
		}

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

	return 0;
}

Measured memory_bytes: 11000
n, m = map(int, input().split())
*p, = range(n)
def root(s):
    if s == p[s]:
        return p[s]
    p[s] = s = root(p[s])
    return s
def unite(a, b):
    aa = root(a);bb = root(b)
    if aa < bb:
        p[bb] = aa
    else:
        p[aa] = bb
        
for i in range(m):
    s, t = map(int, input().split())
    unite(s, t)
N = int(input())
*_, = map(root, range(n))

ans = []
for i in range(N):
    s, t = map(int, input().split())
    ans.append('yes' if p[s] == p[t] else 'no')
print('\n'.join(ans))


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

ll dp[52][52][2500];

int main()
{
    cout << fixed << setprecision(15);
    ll N, A;
    cin >> N >> A;

    vector<ll> X(N);

    REP(i, N){
        cin >> X[i];
    }

    Fill(dp, 0);

    dp[0][0][0] = 1;

    for(ll i=0; i<=N; i++){
        for(ll j=0; j<=N; j++){
            for(ll k=0; k<=2500; k++){
                if(i==0 && j==0 && k == 0){
                    dp[i][j][k] = 1;
                }
                else if(i>=1 && k<X[i-1]){
                    dp[i][j][k] = dp[i-1][j][k];
                }
                else if(i>=1 && j>=1 && k>=X[i-1]){
                    dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-X[i-1]];
                }
                else{
                    dp[i][j][k] = 0;
                }
            }
        }
    }

    ll ans = 0;
    for(ll k=1; k<=N; k++){
        ans += dp[N][k][k*A];
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 56396
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define per(i,b,a) for(int i=b; i>=a; i--)
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pi ;
typedef vector<pair<int,int> > vpi ;
typedef vector<int> vi ;
typedef long long ll ;
const int mod = 998244353 ;
const int inf = 1e9 + 5;
ll powmod(ll a, ll b) { ll ret = 1 ; while(b) { if(b&1) ret = (ret*a)%mod ;  a = (a*a)%mod ; b >>= 1 ; }  return ret ; }
const int maxn = 1e5 + 5 ;
int n,wt ;
int w[maxn], v[maxn] ;
ll dp[102][maxn] ;
int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cin >> n >> wt ;
    rep(i,0,n-1)
    cin >> w[i] >> v[i] ;
    rep(i,0,n-1)
     rep(j,0,wt) dp[i][j] = -63 ;
    dp[0][w[0]] = v[0] ;
    dp[0][0] = 0 ;
    rep(i,1,n-1)
    {
        rep(j,0,wt)
        {
            if(j-w[i] >= 0)
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            else dp[i][j] = dp[i-1][j] ;
        }
    }
    ll res = -63 ;
    rep(j,0,wt)
     res = max(res, dp[n-1][j]) ;
     cout << res << "\n" ;
    return 0 ;
}


Measured memory_bytes: 80128
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;

long long combination(long long n, long long r){
    if(r==0){
        return 1;
    }else{
        return combination(n,r-1)*(n-r+1)/r;
    }
}


int main(){
    int N;
    cin >> N;
    long long A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    long long ans=0;
    long long l=0, r=0;
    
    int one[20]={};

    
    while(l<N && r<N){
        long long t=A[r];
        for(int i=0; i<20; i++){
            one[i]+=t%2;
            t/=2;
        }
        
        
        int ok=1;
        for(int i=0; i<20; i++){
            if(one[i]>1){
                ok=0;
            }
        }
        while(ok==0){
            long long tmp=A[l];
            for(int i=0; i<20; i++){
                one[i]-=tmp%2;
                tmp/=2;
            }
            l++;
            
            ok=1;
            for(int i=0; i<20; i++){
                if(one[i]>1){
                    ok=0;
                }
            }
        }
        
        
        ans+=r-l+1;
        r++;

    }

    cout<<ans<<endl;
    return 0;
}




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

int main() {
    string S; cin >> S;
    if(S == "SAT") {
        cout << 1 << endl;
    }
    if(S == "FRI") {
        cout << 2 << endl;
    }
     if(S == "THU") {
        cout << 3 << endl;
    }
     if(S == "WED") {
        cout << 4 << endl;
    }
     if(S == "TUE") {
        cout << 5 << endl;
    }
     if(S == "MON") {
        cout << 6 << endl;
    }
     if(S == "SUN") {
        cout << 7 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)

int main(){
  string a;cin>>a;
  if(a=="AAA"||a=="BBB")cout<<"No";
  else cout<<"Yes";
  }


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

int main(){
    ll N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    A--; B--; C--; D--;

    if(C < D){
        ll c = 0;
        rep(i, B, D){
            if(S[i] == '#') c++;
            else c = 0; 
            if(c > 1){
                cout << "No" << endl;
                return 0;
            }
        }
        c = 0;
        rep(i, A, C){
            if(S[i] == '#') c++;
            else c = 0; 
            if(c > 1){
                cout << "No" << endl;
                return 0;
            }
        }
    }else{
        ll c = 0, mx = 0;
        rep(i, B-1, D+2){
            if(S[i] == '.') c++;
            else c = 0;
            mx = max(mx, c);
        }
        if(mx < 3){
            cout << "No" << endl;
            return 0;
        }
        c = 0;
        rep(i, A, C){
            if(S[i] == '#') c++;
            else c = 0;
            if(c > 1){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
S = list(input())
A = [0] * (len(S)+1)
imos = [0] * (len(S))
for i in range(len(S)):
    if S[i] == '>':
        imos[i] = 1
    else:
        imos[i] = -10000000
imos += [0]
for i in range(len(S), 0, -1):
    imos[i-1] = max(0, imos[i-1] + imos[i])
A[0] = imos[0]
for i in range(len(S)):
    if S[i] == '<':
        A[i+1] = max(imos[i+1], A[i]+1)
    else:
        A[i+1] = max(0, min(A[i]-1, imos[i+1]))
print(sum(A))

Measured memory_bytes: 46544
#include <bits/stdc++.h>
using namespace std;
long long A, B, C;
int main() {
    cin >> A >> B >> C;
    long long ret = (1LL << 61);
    ret = min(ret, B * C * (A % 2));
    ret = min(ret, C * A * (B % 2));
    ret = min(ret, A * B * (C % 2));
    cout << ret << endl;
    return 0;
}

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

int64_t N,K;
vector<int64_t> A,F;

// costをx以下にすることができるか
bool isOK (int64_t x ){
    int64_t K0 = 0;
    for ( int i = 0; i < N; ++i){
        int64_t cost = A[i] * F[i];
        //cout << "cost " << cost << " x " << x << endl;
        if ( cost > x ){
            K0 = K0 + ( cost - x ) / F[i];
            if ( ( cost - x ) % F[i] ) ++K0;
        }
    }
    //cout << K0 << " " << K << endl;
    if ( K0 <= K ) return true;
    else return false;
}

int main() {
    cin >> N >> K;
    A.resize(N);
    F.resize(N);
    for ( int64_t i = 0; i < N; ++i){
        cin >> A[i];
    }
    for ( int64_t i = 0; i < N; ++i){
        cin >> F[i];
    }
    
    sort(A.begin(),A.end());
    sort(F.begin(),F.end(),greater<int64_t>());
    
    int64_t ok = 1e+12 + 1, ng = -1;
    int64_t mid;
    while ( ok - ng > 1 ){
        mid = ( ng + ok ) / 2;
        //cout << mid << endl;
        if ( isOK(mid) ){
            ok = mid;
        } else {
            ng = mid;
        }
    }
    
    cout << ok << endl;
    
    return 0;
}


Measured memory_bytes: 6400
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i = x;i<n;i++)
#define S(v) sort(v.begin(), v.end());
#define ff first
#define ss second



int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	ll n, d,ct = 0;
	cin>>n>>d;
	while(n--){
		ll x,y;
		cin>>x>>y;
		if(x*x + y*y <= d*d)ct++;
	}
	cout<<ct;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    map<int, int> ma, mb;

    int n;
    cin >> n;

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

    int m;
    cin >> m;

    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        ma[a]++;
    }

    for (const auto& p : ma) {
        if (mb[p.first] < p.second) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 19072
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x; cin >> n >> x;
  vector<int>a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int ans=0, m=0;
  for(int i=0; i<n; i++){
    if(m < x) {
      m += a[i];
      ans = i+1;
    }
  }
  if(m != x) ans--;
  cout << ans << endl;
}

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

using namespace std;

struct ToLower {
    char operator()(char c) {return tolower(c); }
};

int main() {
    string w, t;
    int ans = 0;
    cin >> w;
    transform(w.begin(), w.end(),  w.begin(), ToLower());
    getline(cin, t);
    while (t != "END_OF_TEXT") {
        istringstream iss(t);
        vector<string> tokens{istream_iterator<string>{iss},
                              istream_iterator<string>{}};
        for (auto word : tokens) {
            transform(word.begin(), word.end(), word.begin(), ToLower());
            if (word == w) ans++;
        }
        getline(cin, t);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3220
Scanf.scanf "%d" (fun n ->
    let nei = Array.make n [] in
    for i = 1 to n - 1 do
        Scanf.scanf " %d %d" (fun a b ->
            let a = a - 1 in
            let b = b - 1 in
            nei.(a) <- b :: nei.(a);
            nei.(b) <- a :: nei.(b))
    done;
    let visited = Array.make n false in
    let rec find_shortest_way cur hist =
        if cur = 0 then hist else
            let rec loop = function
                | [] -> []
                | hd :: tl ->
                        if visited.(hd) then loop tl else
                            let () = visited.(hd) <- true in
                            let hist = find_shortest_way hd (hd :: hist) in
                            if hist = [] then loop tl else hist
            in
            loop nei.(cur)
    in
    visited.(n - 1) <- true;
    let hist = find_shortest_way (n - 1) [ n - 1 ] in
    let path = Array.of_list hist in
    let vis2 = Array.make n 0 in
    vis2.(0) <- 1;
    vis2.(n - 1) <- 2;
    let fill hist code =
        let rec loop f next = function
            | [] -> if next = [] then f else loop f [] next
            | hd :: tl -> (
                    let rec loop2 next f = function
                        | [] -> loop f next tl
                        | h :: t ->
                                if vis2.(h) = 0 then (vis2.(h) <- code; loop2 (h :: next) (f + 1) t)
                                                else loop2 next f t
                    in
                    loop2 next f nei.(hd)
           )
        in
        loop 0 [] hist
    in
    let step2 fenhist sunhist =
        let fens = List.length fenhist in
        let suns = List.length sunhist in
        let fens = fens + fill fenhist 1 in
        let suns = suns + fill sunhist 2 in
        print_endline @@ if fens <= suns then "Snuke" else "Fennec"
    in
    let rec loop fen sun fenhist sunhist turn =
        if turn then (
            let fen = fen + 1 in
            if fen = sun then step2 fenhist sunhist else
                let () = vis2.(path.(fen)) <- 1 in
                loop fen sun (path.(fen) :: fenhist) sunhist (not turn)
        ) else (
            let sun = sun - 1 in
            if fen = sun then step2 fenhist sunhist else
                let () = vis2.(path.(sun)) <- 2 in
                loop fen sun fenhist (path.(sun) :: sunhist) (not turn)
        )
    in
    let sun = Array.length path - 1 in
    loop 0 sun [ 0 ] [ n - 1 ] true
)


Measured memory_bytes: 22656
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
    int to;
    T cost;
    Edge() {};
    Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
    int n;
    bool directed;
    vector<vector<Edge<T>>> edges;
public:

    Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)){};
    Graph() {};

    void add(int from,int to, T cost) {
        edges[from].emplace_back(to, cost);
        if(!directed){
            edges[to].emplace_back(from,cost);
        }
    }

    int size() {
        return n;
    }
};


int main() {

    int N;

    cin >> N;

    set<string> S;

    REP(i,N){
        string c;
        cin >> c;
        S.insert(c);
    }

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

    return 0;
}

Measured memory_bytes: 19176
N,M=map(int,input().split())
PY=[list(map(int,input().split()))+[i] for i in range(M)]
PY = sorted(PY, key=lambda x:(x[0], x[1]))
k=1
PY[0][1]=k
for i in range(1,M):
  if PY[i][0]!=PY[i-1][0]:
    k=1
  else:
    k+=1
  PY[i][1]=k
PY = sorted(PY, key=lambda x:x[2])
for p,y,_ in PY:
  print('{0:06}{1:06}'.format(p,y))

Measured memory_bytes: 32028
#include <cstdio>
int N;
int A[100][100];

int main() {
	scanf("%d", &N);
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) {
			scanf("%d", &A[i][j]);
		}
	}
	int out = -1;
	for (int t = N - 1; 0 <= t; t--) {
		int tmp = 0;
		for (int i = 0; i <= t; i++) {
			tmp += A[0][i];
		}
		for (int i = t; i <= N - 1; i++) {
			tmp += A[1][i];
		}
		if (tmp > out) {
			out = tmp;
		}
	}
	printf("%d\n", out);
	return 0;
}


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

int main () {
        int n, sum = 0, ans = 0;
        cin >> n;
        vector <int> a(n);
        for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i];
        int goal = round (1.0 * sum / n);
        for (int i = 0; i < n; ++i) ans = ans + (a[i]-goal)*(a[i]-goal);
        cout << ans << endl;
        return 0;
}

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

int main(int argc, char *argv[]) {
  long n, m;
  std::cin >> n >> m;
  std::vector<std::pair<long, int>> s(n);
  for (int i = 0; i < n; ++i)
    std::cin >> s.at(i).first >> s.at(i).second;

  std::stable_sort(s.begin(), s.end());

  long sum = 0;
  for (auto &v : s) {
    if (v.second >= m) {
      std::cout << sum + (v.first * m) << std::endl;
      return 0;
    }
    sum += v.first * v.second;
    m -= v.second;
  }

  return 1;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
struct edge{int to,silver,cost;};
#define PP pair<int,P>
int n,m,s,c[50],d[50],dist[50][2451];
vector<edge>v[50];
void dijkstra(){
    rep(i,50){
        rep(j,2451){
            dist[i][j]=INF;
        }
    }
    priority_queue<PP,vector<PP>,greater<PP>>q;
    q.push({0,{0,s}});
    dist[0][s]=0;
    while(!q.empty()){
        PP p=q.top();
        q.pop();
        if(dist[p.se.fi][p.se.se]!=p.fi)continue;
        for(int i=0;p.se.se+c[p.se.fi]*i<=2450;i++){
            for(edge e:v[p.se.fi]){
                if(p.se.se+c[p.se.fi]*i-e.silver<0)continue;
                if(dist[e.to][p.se.se+c[p.se.fi]*i-e.silver]>p.fi+d[p.se.fi]*i+e.cost){
                    dist[e.to][p.se.se+c[p.se.fi]*i-e.silver]=p.fi+d[p.se.fi]*i+e.cost;
                    q.push({dist[e.to][p.se.se+c[p.se.fi]*i-e.silver],{e.to,p.se.se+c[p.se.fi]*i-e.silver}});
                }
            }
        }
    }
}
signed main(){
    cin>>n>>m>>s;
    chmin(s,2450ll);
    rep(i,m){
        int u,w,a,b;
        cin>>u>>w>>a>>b;
        u--,w--;
        v[u].pb({w,a,b});
        v[w].pb({u,a,b});
    }
    rep(i,n)cin>>c[i]>>d[i];
    dijkstra();
    rep(i,n){
        if(i){
            int ans=INF;
            rep(j,2451)chmin(ans,dist[i][j]);
            cout<<ans<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 200868
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  int n,k; cin>>n>>k;
  string s; cin>>s;
  s[k-1]=s[k-1]-'A'+'a';
  cout<<s<<endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt, sum int
var Max, Min int = 0, 1e9

func main() {
	reader.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())
	ans = N * (N - 1) / 2
	fmt.Println(ans)
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

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

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define N 100003
#define what_is(x) cerr << #x << " is " << x << endl;

using namespace std;
string abcd;
int op[4];
int solve(int ind, int sum) {
	if (ind == 4) {
		if (sum == 7)
			return 1;
		else
			return 0;
	}

	op[ind] = 0;
	if(solve(ind+1, sum + abcd[ind] - '0'))
		return 1;

	op[ind] = 1;
	return solve(ind+1, sum - abcd[ind] + '0');

}

int main() {
	// for fast input output using cin cout
	std::ios_base::sync_with_stdio(false);

	// input
	cin >> abcd;

	solve(0, 0);

	string ans;
	// cout << op[0] << op[1] << op[2] << op[3] << endl;

	ans = "";
	for (int i = 0; i < 4; ++i)
	{
		if (i == 0 && !op[i]) {
			ans.push_back(abcd[i]);
			continue;
		}

		if (!op[i])
			ans += "+";
		else
			ans += "-";
		ans.push_back(abcd[i]);
	}
	ans += "=7";

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#define pb push_back

using namespace std;

const int N = 1e5 + 5;

struct node
{
	int val,id;
	int operator < (node b) const
	{
		return val < b.val;
	}
};

int n,m,p,y;
int ans[N][2];
vector <node> V[N];

int main()
{
	scanf("%d%d",&n,&m);
	for (int i = 1 ; i <= m ; i++) scanf("%d%d",&p,&y),V[p].pb((node){y,i});
	for (int i = 1 ; i <= n ; i++) if (V[i].size()) sort(V[i].begin(),V[i].end());
	for (int i = 1 ; i <= n ; i++) 
	{
		if (V[i].size())
		{
			int siz = V[i].size();
			for (int j = 0 ; j < siz ; j++) 
			{
				ans[V[i][j].id][0] = i,ans[V[i][j].id][1] = j + 1;
			}
		}
	}
	for (int i = 1 ; i <= m ; i++) printf("%06d%06d\n",ans[i][0],ans[i][1]);
	return 0;
}


Measured memory_bytes: 7808
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)

ng = -1
ok = 10**12+100
while ok - ng > 1:
    mid = (ok + ng) // 2
    if sum(max(0,a-mid//f) for a,f in zip(A,F)) <= K:
        ok = mid
    else:
        ng = mid
print(ok)


Measured memory_bytes: 119756
// ＡＢＣのＡ過去問を解くだけだよ

// フォント:Electroharmonix
// x:小文字(ｘ)    X:大文字(Ｘ)
// +:プラス(＋)    &:アンド(＆)

#include <bits/stdc++.h>

using namespace std;

void Main()
{
    int N, i;
    cin >> N >> i;
    cout << N - i + 1;
}

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

    //std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    return 0;
}

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

int main(){
    ll sum = 0;
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        if(i%3 != 0 && i%5 != 0){
            sum+=i;
        }
    }
    cout << sum;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
bool rec(int a,int b,int c,int d){
  if(a>=5&&b>=5)return false;
  if(a<5&&c<5&&!rec(c+a,d,a,b))return true;
  if(a<5&&d<5&&!rec(c,d+a,a,b))return true;
  if(b<5&&c<5&&!rec(c+b,d,a,b))return true;
  if(b<5&&d<5&&!rec(c,d+b,a,b))return true;
  return false;
}
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<(rec(a,b,c,d)?"ISONO":"NAKAJIMA")<<endl;
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n, p;
  cin >> n>> p;
  ll radicand = 1;
  ll ans = 1;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  while(pow(radicand,n) <= p){
    if (p%(ll)pow(radicand,n) == 0) ans = radicand;
    radicand++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
if N >= M:
  print(0)
  exit()

X = [int(x) for x in input().split()]

X = sorted(X)
L = [ X[i] - X[i-1] for i in range(1, M)]
L = sorted(L)
#print(X)
#print(L)

print(sum(L[:M-N]))

Measured memory_bytes: 13832
from collections import deque

def main():
    N = int(input())
    A = input().split()

    deq = deque()
    for i in range(N):
        if i % 2 == 0:
            deq.append(A[i])
        else:
            deq.appendleft(A[i])

    if N % 2 == 1:
        deq.reverse()
    print(" ".join(deq))


if __name__ == "__main__":
    main()

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n, m;
    cin >> n >> m;

    for (int i=0; i<m; i++) {
        int x;
        cin >> x;
        n -= x;
    }
    cout << max(-1, n) << "\n";
}


Measured memory_bytes: 3656
s = list(input())
t = list(input())

def num_replace(string, sub, shift):
    ans = 0
    for i in range(len(sub)):
        if string[i + shift] != sub[i]:
            ans += 1
    return ans
#print(num_replace(s, t, 0))

min_num = float("inf")
for shift in range(0, len(s) - len(t) + 1):
    min_num = min(min_num, num_replace(s, t, shift))
print(min_num)

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

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

  if(N[0]=='7' || N[1]=='7' || N[2]=='7')
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
typedef long long LL;
const int MAXN = 2e5 + 10;
const LL Mod = 1e9 + 7;
LL qpow(LL base, LL times)
{
	LL tmp = base % Mod;
	LL Ans = 1;
	while (times)
	{
		if (times & 1) Ans = Ans * tmp % Mod;
		times >>= 1;
		tmp = tmp * tmp % Mod;
	}
	return Ans % Mod;
}
LL nC[MAXN], n_1C[MAXN];
int main()
{
	LL n, k;
	std::cin >> n >> k;
	nC[0] = 1;
	for (LL i = 1; i <= n; i++)
	{
		LL cur = (nC[i - 1] * (n - i + 1)) % Mod;
		nC[i] = cur * qpow(i, Mod - 2) % Mod;
	}
	n_1C[0] = 1;
	for (LL i = 1; i < n; i++)
	{
		LL cur = (n_1C[i - 1] * (n - i)) % Mod;
		n_1C[i] = cur * qpow(i, Mod - 2) % Mod;
	}
	k = std::min(n, k);
	LL Ans = 0;
	for (int i = 0; i <= k; i++)
	{
		// std::cout<<"Ans is "<<Ans<<'\n';
		Ans = (Ans + ((nC[i] * n_1C[n - i - 1]) % Mod)) % Mod;
	}
	std::cout<<Ans<<'\n';
}

Measured memory_bytes: 3328
#include <cstdio>
#include <set>
#include <vector>

using namespace std;

int main(){
  int n;

  while(scanf("%d" ,&n) ,n){
    int MAX = (n-1) / 2;
    int cnt[MAX];
    fill(cnt,cnt+MAX,0);

    set<int> s;
    for(int i = 1 ; i < n ; i++){
      int num = i * i % n;
      if(!s.count(num)){
	s.insert(num);
      }
    }

    set<int>::iterator it;
    vector<int> v;
    for(it = s.begin() ; it != s.end() ; it++){
      v.push_back(*it);
    }

    int len = (int)v.size();
    for(int i = 0 ; i < len ; i++){
      for(int j = 0 ; j < len ; j++){
	if(i == j) continue;
	int diff = v[i] - v[j];

	if(diff < 0){
	  diff += n;
	}
	if(diff > MAX){
	  diff -= n;
	}

	cnt[diff-1]++;
      }
    }
    for(int i = 0 ; i < MAX ; i++){
      printf("%d\n" ,cnt[i]*2);
    }
  }

  return 0;
}

Measured memory_bytes: 1368
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest
{
	class Program
	{
		static void Main()
		{
            int N = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse);
            Console.WriteLine(a.Max() - a.Min());
#if DEBUG
			Console.ReadKey();
#endif
		}
	}
}

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



int main() {
    
    long N;
    cin>>N;
    vector<long>num(N);
    vector<long>copy;
    
    for(long i=0;i<N;i++)
    {cin>>num.at(i);}
    copy=num;
    sort(num.begin(),num.end());
    reverse(num.begin(),num.end());
    for(long i=0;i<N;i++)
    {if(copy.at(i)==num.at(0))
    {cout<<num.at(1)<<endl;}
    else{cout<<num.at(0)<<endl;}
        }
    
    
    
    
}


Measured memory_bytes: 4736
function Main(input){
	var a = input.split("\n");
  if(a[0] == 1){
  	return "Hello World";
  }
  if(a[0] == 2){
  	return (a[1]*1) + (a[2]*1);
  }
}

console.log(Main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 21064