akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

int N, M;
int res[3];
bool setflag[3];

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

  if(M==0){
    if(N > 1)    cout << pow(10,N-1) << endl;
    else cout << 0 << endl;
    return 0;
  }

  res[3-N] = 1;
  
  for(int i=0;i<M;++i){
    int s,c;
    cin >> s >> c;
    int idx = s+2-N;
    if(setflag[idx] && res[idx] != c){
      cout << -1 << endl;
      return 0;
    }
    res[idx] = c;
    setflag[idx] = true;
  }
  if(res[3-N]==0 && N != 1){
    cout << -1 << endl;
    return 0;
  }
  
  cout << res[0] * 100 + res[1] * 10 + res[2] << endl;
  return 0;
}

Measured memory_bytes: 256
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e12;
const ll inf=1e18;
const ll ms=10000000;
fast;
ll n,m,ans;
string s;
void solve()
{
    cin>>n>>s;
    for(auto &it:s)
    {
        it=(char)((it+n-65)%26+65);
    }
    cout<<s<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int a[6] = { 500,100,50,10,5,1 };
	int b;
	while (cin >> b) {
		if (b == 0)break;
		int c = 0;
		b = 1000 - b;
		for (int i = 0; i < 6; ++i) {
			if (b / a[i]>=1) {
				c = c + b / a[i];
				b = b%a[i];
			}
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 2912
n, m = gets.split(" ").map(&:to_i)

@ind_arr = Array.new(n+1){|i| i}
@f_arr = Array.new(n+1, 1)

def find(x)
  return x if x == @ind_arr[x]
  # 途中のindexも更新しておく
  @ind_arr[x] = find(@ind_arr[x])
  return @ind_arr[x]
end

def union(x, y)
  x = find(x)
  y = find(y)
  return if x == y
  @ind_arr[x] = y
  @f_arr[y] += @f_arr[x]
end

m.times do
  a, b = gets.split(" ").map(&:to_i)
  union(a, b)
end

puts @f_arr.max


Measured memory_bytes: 17448
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a<c&&b<c)cout<<a+b<<endl;
  else if(a<b&&c<b)cout<<a+c<<endl;
  else if(b<a&&c<a)cout<<b+c<<endl;
  else if(a==b&&b==c)cout<<a+b<<endl;
  else if(a==b&&c<a)cout<<a+c<<endl;
  else if(a==c&&b<a)cout<<a+b<<endl;
  else if(b==c&&a<b)cout<<a+b<<endl;
  return 0;
}


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

const int DIM = 1e5 + 5;

int arr[DIM];

int main( void ) {
    
    int n;
    cin >> n;
    
    for( int i = 1; i <= n; i ++ )
        cin >> arr[i];
    
    sort( arr + 1, arr + n + 1, greater<int>() );
    
    int p = 0;
    while( p < n - 1 && arr[p + 2] > p + 1 )
        p ++;
    
    int l1 = 0;
    while( p + l1 + 1 < arr[p + 1] )
        l1 ++;
    
    int l2 = 0;
    while( arr[p + l2 + 2] > p )
        l2 ++;
    
    cout << ( ( l1 % 2 + l2 % 2 ) != 0 ? "First\n" : "Second\n" );
    
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

inline ll distance(pair<ll, ll> a, pair<ll, ll> b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}


//void search(ll y, ll x, ll n, vector<ll> aa) {
//
//	if (x < 0 || y < 0 || x >= W || y >= H)return;
//
//	if (aa[y * H + x] <= (n + 1))return;
//
//	aa[y * H + x] = n + 1;
//
//	search(y + 1, x, n + 1, aa);
//	search(y - 1, x, n + 1, aa);
//	search(y, x + 1, n + 1, aa);
//	search(y, x - 1, n + 1, aa);
//	return;
//}



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

	char A[1000][1000];
	ll H, W;

	cin >> H >> W;


	vector<pair<ll, ll> > dis;
	vector<ll> aa(H * W, 4000);
	queue<pair<ll, ll> > q1;
	queue<pair<ll, ll> > q2;
	ll count = 0;

	rep(y, H) {
		rep(x, W) {
			cin >> A[y][x];
			if (A[y][x] == '#') {
				dis.push_back(make_pair(y, x));
				q1.push(make_pair(y, x));
			}
		}
	}

	pair<ll, ll> a;
	bool flg = true;
	while (flg) {
		flg = false;

		while (!q1.empty()) {
			a = q1.front();
			q1.pop();

			if (a.first + 1 < H) {
				if (A[a.first + 1][a.second] != '#') {
					A[a.first + 1][a.second] = '#';
					q2.push(make_pair(a.first + 1, a.second));
				}

			}

			if (a.first - 1 >= 0) {
				if (A[a.first - 1][a.second] != '#') {
					A[a.first - 1][a.second] = '#';
					q2.push(make_pair(a.first - 1, a.second));
				}
			}

			if (a.second + 1 < W) {
				if (A[a.first][a.second + 1] != '#') {
					A[a.first][a.second + 1] = '#';
					q2.push(make_pair(a.first, a.second + 1));
				}
			}

			if (a.second - 1 >= 0) {
				if (A[a.first][a.second - 1] != '#') {
					A[a.first][a.second - 1] = '#';
					q2.push(make_pair(a.first, a.second - 1));
				}
			}


		}
		if (!q2.empty()) {
			q1.swap(q2);
			flg = true;
		}
		count++;
	}


	cout << count-1 << endl;





	return 0;
}


Measured memory_bytes: 41060
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=5+3*1e+4;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=7+1e+9;

int main() {
	int n, a[128];
	cin >> n;
	REP(i,n)
		cin >> a[i];
	int ans = INF;
	FOR(i,-200, 201){
		int sum = 0;
		REP(j,n){
			sum += (a[j] - i) * (a[j] - i);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
    return 0;
}


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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    string s,t;
    cin>>s>>t;
    int n=s.size();
    int ans=0;
    rep(i,n){
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3892
n,m=map(int,input().split())
p=[]
pp=[]
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    p.append(i)
    pp.append(m//i)
pp.reverse()
p+=pp
l,r=-1,len(p)
while r-l!=1:
  t=(l+r)//2
  if p[t]>=n:
    r=t
  else:
    l=t
print(m//p[r])

Measured memory_bytes: 64056
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

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

  cout << static_cast<int>(pow(x, 3)) << endl;

  return 0;
}



Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
using ll=long long;
int n,c=1,k=1000,x,m=1000,ans;
int main(){
  cin>>x>>n;
  vector<int> p(n);
  rep(i,n)cin>>p[i];
  for(int i=-110;i<110;++i){
    bool f=true;
    k=abs(x-i);
    // cout<<k<<endl;
    rep(j,n)if(i==p[j]){f=false;break;};
    if(f){
      if(m>k)m=k,ans=i;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3592
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ar := make([]int, n)
	for i := range ar {
		fmt.Scan(&ar[i])
	}
	sum := 0
	for i := 0; i < n-2; i++ {
		if ar[i] < ar[i+1] && ar[i+1] < ar[i+2] {
			sum++
		}
		if ar[i] > ar[i+1] && ar[i+1] > ar[i+2] {
			sum++
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool> vecbool;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<string> vecstr;
typedef vector<vecint> vec2int;
typedef vector<vecbool> vec2bool;
int dx[4]{-1, +1, 0, 0};
int dy[4]{0, 0, -1, +1};
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
vecint a;
vec2int dp;
int n, k;
bool rec(int p, int q) {
  // if (p <= 0) return false;
  if (dp[p][q] != -1) return dp[p][q] == 1 ? true : false;
  int r = (q != 1);
  REP(i, n) {
    if (p >= a[i]) {
      if (!rec(p - a[i], r)) {
        dp[p][q] = 1;
        return true;
      }
    }
  }
  dp[p][q] = 0;
  return false;
}
int main() {
  init();
  cin >> n >> k;
  a.resize(n);
  for (auto& e : a) cin >> e;
  dp = vector<vector<int> >(k + 1, vecint(2, -1));
  REP(i, a[0]) dp[i][0] = dp[i][1] = 0;
  for (const auto& e : a) dp[e][0] = dp[e][1] = 1;
  // // REP(i, k + 1) { cout << i << " " << dp[i][0] << " " << dp[i][1] << endl;
  // }
  cout << (rec(k, 0) ? "First" : "Second") << endl;
  // REP(i, k + 1) { cout << "i: " << dp[i][0] << " " << dp[i][1] << endl; }
}



Measured memory_bytes: 13568
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define REP(i, n) for(int i = 0; i < n; i++)
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void){
  int n, k, s;
  cin>>n>>k;
  vector<int> a;
  long long dp[100100];
  REP(i, n){
    cin>>s;
    a.push_back(s);
  }
  REP(i, 100100){
    dp[i]=INF;
  }
  dp[0] = 0;
  REP(i, n){
    for(int j = 1; j <= k; ++j){
      chmin(dp[i+j], dp[i]+abs(a[i]-a[i+j]));
    }
  }
  cout<<dp[n-1]<<endl;  
  return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, m;
    cin >> n >> m;
    if(n == m) Yes();
    else No();
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 1145141919;
    for (int a = 1; a < n; a++) {
        int b = n - a;
        int sum = 0;
        int ta = a, tb = b;
        while (ta > 0) {
            sum += ta % 10;
            ta /= 10;
        }
        while (tb > 0) {
            sum += tb % 10;
            tb /= 10;
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

MOD = 10 ** 9 + 7

def make_table(size=10**6, p=MOD):
    fac = [None] * (size + 1)
    fac[0] = 1
    for i in range(size):
        fac[i+1] = fac[i] * (i + 1) % p
    ifac = [None] * (size + 1)
    ifac[size] = pow(fac[size], p-2, p)
    for i in range(size, 0, -1):
        ifac[i-1] = ifac[i] * i % p
    return fac, ifac

fac, ifac = make_table(5*10**5)

def comb(n, r, mod=MOD):
    if r > n or r < 0:
        return 0
    return fac[n] * ifac[r] % mod * ifac[n-r] % mod

def nHr(n, r):
    return comb(n-1+r, r)

n, k = map(int, sys.stdin.readline().split())
if k >= n:
        k = n - 1

def main():
    res = nHr(n, n)
    for i in range(k+1, n):
        res -= comb(n, i) * nHr(n-i, i) % MOD
        res %= MOD
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 42612
s=input()
K=int(input())
a=list("abcdefghijklmnopqrstuvwxyz")
l=[]
S=set()
n=len(s)

for c in a:
	j=-1
	for i in range(s.count(c)):
		j+=s[j+1:].find(c)+1
		k=j+1
		while k<=n and k-j<=5:
			S.add(s[j:k])
			k+=1
	if len(S)>=5:
		break

A=sorted(S)
print(A[K-1])

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

int x= sc.nextInt();
if(x==1){
	System.out.println(1);
}else{
	int ans=1;

	int pre=1;
	for(int i=2; i<=x; i++){
				pre=i;
				while(pre<=x){
						pre=pre*i;
						if(pre<=x && ans<pre){
							ans = pre;
						}
				}
		}
		System.out.println(ans);
	}

	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  long long x,y,z;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y<a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[111];
int l[111];
int j[1];

long long x,y,z,mod=1000000007;
//string r;
char r[1];

P u[1];
queue<int> q;
stack<P> s;

//vector<int> v;

bool as(P a,P b)
{
  return a.x<b.x;
}

struct S
{
  int x,r;
  long long f;
};

vector<S> v[111];

void ad(int n,int m,long long x)
{
  v[n].push_back({m,(int)v[m].size(),x});
  v[m].push_back({n,(int)v[n].size()-1,0});
}

void bfs()
{
  memset(o,0,sizeof(o));
  o[0]=1;
  q.push(0);
  for(;q.size();q.pop())
  for(int h=0;h<v[q.front()].size();h++)
  if(v[q.front()][h].f&&!o[v[q.front()][h].x])
  {
    o[v[q.front()][h].x]=o[q.front()]+1;
    q.push(v[q.front()][h].x);
  }
}

long long f(int n,int m,long long x)
{
  //printf("%d %lld\n",n,x);
  if(n==m) return x;
  
  for(;l[n]<v[n].size();l[n]++)
  if(v[n][l[n]].f&&o[n]+1==o[v[n][l[n]].x])
  {
    long long p=f(v[n][l[n]].x,m,min(x,v[n][l[n]].f));
    v[n][l[n]].f-=p;
    v[v[n][l[n]].x][v[n][l[n]].r].f+=p;
    if(p) return p;
  }
  return 0;
}

int main()
{
  scanf("%d",&a);
  for(int t=1;t<=a;t++)
  {
    scanf("%d",&n);
    if(n<0) ad(0,t,-n);
    else y+=n,ad(t,a+1,n);
    for(int h=t*2;h<=a;h+=t)
      ad(t,h,mod*mod);
  }
  for(;;)
  {
    bfs();
    if(!o[a+1]) break;
    memset(l,0,sizeof(l));
    x=f(0,a+1,mod*mod);
    if(!x) break;
    else z+=x;
  }
  printf("%lld",y-z);
}
//2




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

int main() {
  int a,b;
  int ans=0;
  cin >> a >> b;

  vector<int> v(5,0);
  for(int i=0;i<b-a+1;i++){
    v[0] = (a+i)%10;
    v[1] = (a+i-v[0])%100;
    v[2] = (a+i-v[0]-v[1])%1000;
    v[3] = (a+i-v[0]-v[1]-v[2])%10000;
    v[4] = a+i-v[0]-v[1]-v[2]-v[3];

    if(v[0]*10000 == v[4]){
      if(v[1]*100 == v[3]){
        ++ans;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
int main(){
  ll x;
  cin >> x;
  double t1 = 100;
  ll cou = 0;
  while(t1 < x){
    t1 *= 1.01;
    t2 = (ll)t1;
    t1 = t2;
    cou++;
  }
  cout << cou << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> s(n);
    int sum = 0;
    rep(i, 0, n){
        cin >> s[i];
        sum += s[i];
    }
    sort(all(s));
    bool f = false;
    if(sum % 10 == 0) f = true;
    rep(i, 0, n){
        if(f && s[i] % 10 != 0){
            sum -= s[i];
            f = false;
        }
    }
    if(f == false) cout << sum << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

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

int main() {


	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<ll> cnt(26, 0);
	for (int i = 0; i < s.length(); i++) {
		cnt[s[i] - 'a']++;
	}
	ll ans = 1;
	for (int i = 0; i < 26; i++)
	{
		ans *= (cnt[i] + 1);
		ans %= MOD;
	}
	cout << ans - 1 << endl;

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

const int MAXN = 200005;
const int MAXM = 300005;
const int INF = (1 << 30) - 1;

struct Edge
{
	int to;
	int cap;
	int nxt;
}edge[MAXM << 1];

int n,id = 1,ans,ca,cb,S,T;
int a[MAXN];
int b[MAXN];
int first[MAXN];
int dis[MAXN];
int cur[MAXN];
int bela[MAXN];
int belb[MAXN];
int vala[MAXN];
int valb[MAXN];

bool vis[MAXN];

queue<int> Q;
map<int,int> e[MAXN];

void addE(int u,int v,int c)
{
	edge[++id] = (Edge){v,c,first[u]};
	first[u] = id;
	edge[++id] = (Edge){u,0,first[v]};
	first[v] = id;
}

bool bfs()
{
	memset(dis,-1,sizeof(dis));
	dis[S] = 0;
	Q.push(S);
	while (!Q.empty())
	{
		int u = Q.front();
		Q.pop();
		for (int i = first[u];i;i = edge[i].nxt)
			if (edge[i].cap > 0 && dis[edge[i].to] == -1)
			{
				dis[edge[i].to] = dis[u] + 1;
				Q.push(edge[i].to);
			}
	}
	return ~dis[T];
}

int dfs(int u,int f)
{
	if (u == T)
		return f;
	int res = 0;
	for (int &i = cur[u];i;i = edge[i].nxt)
		if (edge[i].cap > 0 && dis[edge[i].to] == dis[u] + 1)
		{
			int ret = dfs(edge[i].to,min(edge[i].cap,f));
			edge[i].cap -= ret;
			edge[i ^ 1].cap += ret;
			f -= ret;
			res += ret;
			if (!f)
				break;
		}
	return res;
}

int Dinic()
{
	int res = 0;
	while (bfs())
	{
		memcpy(cur,first,sizeof(cur));
		while (int tot = dfs(S,INF))
		{
			res += tot;
			memcpy(cur,first,sizeof(cur));
		}
	}
	return res;
}

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n;i++)
	{
		scanf("%d",&a[i]);
		a[i]++;
	}
	for (int i = 1;i <= n;i++)
	{
		scanf("%d",&b[i]);
		b[i]++;
	}
	for (int i = 1;i <= n;i++)
	{
		if (vis[i])
			continue;
		ca++;
		int cur = i;
		while (!vis[cur])
		{
			vis[cur] = 1;
			bela[cur] = ca;
			cur = a[cur];
		}
	}
	memset(vis,0,sizeof(vis));
	for (int i = 1;i <= n;i++)
	{
		if (vis[i])
			continue;
		cb++;
		int cur = i;
		while (!vis[cur])
		{
			vis[cur] = 1;
			belb[cur] = cb;
			cur = b[cur];
		}
	}
	ans = n;
	S = 0,T = ca + cb + 1;
	for (int i = 1;i <= n;i++)
	{
		if (a[i] == i && b[i] == i)
			ans--;
		else if (a[i] == i)
			addE(S,belb[i] + ca,1);
		else if (b[i] == i)
			addE(bela[i],T,1);
		else
		{
			addE(bela[i],belb[i] + ca,1);
			if (a[i] == b[i])
				addE(belb[i] + ca,bela[i],1);
		}
	}
	printf("%d\n",ans - Dinic());
	return 0;
}

Measured memory_bytes: 22784
m,i,j,k,c[],p;main(n){for(;scanf("%d%d",&n,&m),n;printf("%d\n",j>m?k:j)){for(k=3;k--;)for(scanf("%d",&i);i--;c[j]=k)scanf("%d",&j);for(j=i=0;i++<n;p=c[i]*2+p&3)j+=pow(3,n-i)*abs(p-c[i]);j=fmin(j,pow(3,n)+~j);}}

Measured memory_bytes: 0
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    string a,b,c;
    cin >> n >> a >> b >> c;
    ll ans=0;
    rep(i,n){
        if(a[i]==b[i]&&b[i]==c[i]){
            ans+=0;
        }
        else if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i]){
            ans++;
        }
        else{
            ans+=2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3504
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

class RunRun {
public:
	RunRun(long long K);
	~RunRun();
	long long main_calc();
private:
	long long make_Run(long long i);
	void recursive(long long k, long long num, long long bef);
private:
	const long long K;
	vector<long long> val;
};

RunRun::RunRun(long long K) : K(K){
	val.clear();
}

RunRun::~RunRun() {
}


void RunRun::recursive(long long k, long long num, long long bef) {
	long long dnum = num;
	if (k == 0) {
		val.push_back(num);
		return;
	}
	else {
		if (0 < bef) {
			dnum = num;
			dnum += (bef - 1) * (long long)pow(10, k - 1);
			recursive(k - 1, dnum, bef - 1);
		}
		dnum = num;
		dnum += bef * (long long)pow(10, k - 1);
		recursive(k - 1, dnum, bef);
		if (bef < 9) {
			dnum = num;
			dnum += (bef + 1) * (long long)pow(10, k - 1);
			recursive(k - 1, dnum, bef + 1);
		}
	}
}

long long RunRun::make_Run(long long i) {

	for (long j = 1; j <= 9; j++) {
		recursive(i - 1, j * (long long)pow(10, i - 1), j);
	}

	return val.size();
}

long long RunRun::main_calc() {

	long long sum = 0;
	long long i = 0;

	while (sum < K) {
		i++;
		sum = make_Run(i);
	}

	return val[K - 1];
}

int main(){

	long long K;
	cin >> K;

	RunRun r(K);

	cout << r.main_calc() << endl;

	return 0;
}



Measured memory_bytes: 2420
N, K = map(int, input().split())
ans = []
if ((N - 1) * (N - 2)) / 2 < K:
    print('-1')
else:
    M = (N - 1) * (N - 2) // 2
    for i in range(N - 1):
        ans.append([1, i + 2])
    j, k = 2, 3
    while (M > K):
        ans.append([j, k])
        M -= 1
        k += 1
        if k > N:
            j += 1
            k = j + 1
    print(len(ans))
    for out in ans:
        print(*out)

Measured memory_bytes: 4120
from collections import deque

aa = input()
bb = input()
cc = input()
a, b, c = deque(aa), deque(bb), deque(cc)
now = 'a'
while (1):
    if now == 'a':
        if len(a) == 0:
            print('A')
            exit()
        now = a.popleft()
    elif now == 'b':
        if len(b) == 0:
            print('B')
            exit()
        now = b.popleft()
    else:
        if len(c) == 0:
            print('C')
            exit()
        now = c.popleft()


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++)cin>>a[i];
  int b=0;
  for(int i=0;i<N;i++)b+=a[i]%2;
  if(b==0)cout<<"second"<<endl;
  else cout<<"first"<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
const int N=1e7+1;
long long a[N];
int main(){
    long long i,j,n,l=0;
    scanf("%lld",&n);
    for(i=1;i<=n;i++){
        for(j=i;j<=n;j+=i){
            a[j]++;
        }
    }
    for(i=1;i<=n;i++){
        l+=i*a[i];
    }
    printf("%lld\n",l);
    return 0;
}

Measured memory_bytes: 81864
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i,n) for(int i=n-1;i>=0;i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
 

signed main(){
   
   int n;
   string s;
   cin>>s;
   int ans=0,ans2=0;
   rep(i,s.size()){
   		if(i%2==0 && s[i]=='0')ans++;
   		if(i%2==1 && s[i]=='1')ans++;
   		if(i%2==1 && s[i]=='0')ans2++;
   		if(i%2==0 && s[i]=='1')ans2++;
   }
   cout<<min(ans,ans2)<<endl;
   
   
}


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

int main() {
  int P,Q,R,A,B,C,a,b;
  cin>>P>>Q>>R;
  A=P+Q;
  B=Q+R;
  C=R+P;
  a=min(A,B);
  b=min(a,C);
  cout<<b<<endl;
}


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

int main() {
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    ll count = 1;
    for(ll i=0; i<n; i++){
        if(count > n) break;
        ans++;
        count *= k;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	int a, b,c=0;

	cin >> a >> b;
	c += a - 1;
	if (b >= a)c++;
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long ans=0;
	bool a=true;
  	string s;
	cin >> s;
	if(s[0]=='W'){
		a=true;
	}else if(s[0]=='B'){
		a=false;
	}
	for(int i=1;i<s.size();i++){
		if(a==true&&s[i]=='B'){
			ans++;
			a=false;
		}
		if(a==false&&s[i]=='W'){
			ans++;
			a=true;
		}
	}
  	cout << ans << endl;
  	return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <unordered_map>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;

int mod_pow(int a, int b) {
    if (!b) return 1;
    if (b % 2) return a * mod_pow(a, b - 1) % MOD;
    int q = mod_pow(a, b / 2);
    return q * q % MOD;
}

vector<vector<int>> g;
int ans;
int n, k;
void dfs(int v, int p = -1, int minus = 0) {
    ans = ans * max(0LL, k - minus) % MOD;
    int now = (p != -1) + 1;
    for (int u : g[v]) {
        if (u != p) {
            dfs(u, v, now);
            now++;
        }
    }
}

void solve() {
    cin >> n >> k;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int from, to;
        cin >> from >> to;
        from--; to--;
        g[from].push_back(to);
        g[to].push_back(from);
    }

    ans = 1;
    dfs(0);
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //int t;
    //cin >> t;
    int t = 1;
    while (t--) solve();
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

// template from zscoder

int s[3];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a[3][3];

    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            cin >> a[i][j];
            if(i==j)s[0] += a[i][j];
        }
    }
    s[1] = a[0][1]+a[1][2]+a[2][0];
    s[2] = a[0][2]+a[1][0]+a[2][1];
    if(s[0]==s[1]&&s[1]==s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;

const int mod = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n;
    cin >> n;
    vi x(n);
    vi y(n);

    rep(i, n){
        cin >> x[i] >> y[i];
    }

    double sum = 0;
    rep(i, n){
        rep(j, n){
            if(i != j){
                sum += sqrt((x[j]-x[i]) * (x[j]-x[i]) + (y[j]-y[i]) * (y[j]-y[i]));
            }
        }
    }


    cout << fixed << setprecision(8) << sum / (double)n << endl;
    return 0;
}



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

using namespace std;
using ll = long long int;

int main(void) {

    ll n, m, x;
    cin >> n >> m >> x;
    vector<ll> c(n);
    vector<vector<ll>> a(n, vector<ll>(m));
    for(ll i=0; i<n; i++) {
        cin >> c[i];
        for(ll j=0; j<m; j++)
            cin >> a[i][j];
    }

    ll res = 1e9;
    for(ll i=0; i<1ll<<n; i++) {
        ll r = 0;
        vector<ll> aa(m);
        for(ll j=0; j<n; j++) {
            if(~(i>>j)&1) continue;
            r += c[j];
            for(ll k=0; k<m; k++)
                aa[k] += a[j][k];
        }
        if(all_of(aa.begin(), aa.end(), [&](ll t){ return t  >= x; }))
            res = min(r, res);
    }

    cout << (res == 1e9 ? -1 : res) << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
using namespace std;
#define ll long long int
ll has[1000005]={};
ll track1[1000005]={};
int main(){
   ll n;
   cin>>n;
   ll a[n];
   ll i;
   for(i=0;i<n;i++){
       cin>>a[i];
       track1[a[i]]++;
   }
   if(track1[1]!=0){
       if(track1[1]==1){
           cout<<"1";
       }
       else{
           cout<<"0";
       }
       return 0;
   }
   sort(a,a+n);
   ll count=0;
   for(i=0;i<n;i++){
       if(has[a[i]]==0){
           if(track1[a[i]]==1){
               count++;
           }
           ll j = a[i];
           has[j]=1;
           while(1){
               j=j+a[i];
               if(j>1000005){
                   break;
               }
               has[j]=1;
           }
       }
   }
   cout<<count;
}


Measured memory_bytes: 20812
import math
N,D=tuple(map(int,input().split(' ')))

x=[]

for i in range(N):
    x.append(list(map(int,input().split(' '))))

def K(a1,a2):
    return math.sqrt(sum(map(lambda x:pow(x[0]-x[1],2),zip(a1,a2))))

A=0

for i in range(N):
    for j in range(i+1,N):
        temp=K(x[i],x[j])
        if temp==math.floor(temp):
            A+=1

print(A)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define N 100005
#define LL long long
using namespace std;
vector<int> G[N];
int n,a[N],d[N],rt;
void GG(){ printf("NO"); exit(0);}
void dfs(int t,int fa)
{
	int i; LL Max=0,x,sum=0;
	if(d[t]==1) return ;
	for(i=0;i<G[t].size();i++)
		if(G[t][i]!=fa) dfs(G[t][i],t);
	for(i=0;i<G[t].size();i++)
		if(G[t][i]!=fa)
			sum+=a[G[t][i]],Max=max(Max,1LL*a[G[t][i]]);
	x=sum-a[t];
	if(x<0||2*x>sum) GG();
	if(Max*2>sum&&x>sum-Max) GG();
	a[t]=sum-2*x;
}
int main()
{
	int i,x,y;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	for(i=1;i<n;i++){
		scanf("%d %d",&x,&y);
		G[x].push_back(y),d[x]++;
		G[y].push_back(x),d[y]++;
	  }
	for(i=1;i<=n;i++)
		if(d[i]!=1) rt=i;
	if(rt==0){
		if(a[1]!=a[2]) GG();
		else printf("YES");
		return 0;
	  }
	dfs(rt,0);
	if(a[rt]!=0) GG();
	printf("YES");
	return 0;
}


Measured memory_bytes: 13568
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7);
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt();
		long sum = 0;
		int[] w = new int[n];
		for(int i=0;i<n;++i) {
			w[i] = sc.nextInt();
			sum+=w[i];
		}
		long pre = 0,ans = Integer.MAX_VALUE;
		for(int i=0;i<n;++i) {
			sum-=w[i];
			pre+=w[i];
			ans = Math.min(ans,Math.abs(pre-sum));
		}
		out.print(ans);
		out.close();
	}
	
	
}

Measured memory_bytes: 21204
#include <stdio.h>
   
int main(void){
   
  int a[4][13] = {0};
  int n,rank;
  char c;
  register int i,s;
   
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%s %d",&c,&rank);
    switch(c){
      case 'S':
        a[0][rank - 1] = 1;
        break;
      case 'H':
        a[1][rank - 1] = 1;
        break;
      case 'C':
        a[2][rank - 1] = 1;
        break;
      case 'D':
        a[3][rank - 1] = 1;
    }
 
  }
  for(i = 0;i < 4;i++){
    for(s = 0;s < 13;s++){
      if(a[i][s] == 0){
        switch(i){
          case 0:
            printf("S %d\n",s + 1);
            break;
          case 1:
            printf("H %d\n",s + 1);
            break;
          case 2:
            printf("C %d\n",s + 1);
            break;
          case 3:
            printf("D %d\n",s + 1);
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 596
// ABC109
// B - Shiritori

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100;

int N;
string w[MAX_N];

bool solve() {
    unordered_set<string> s;
    s.insert(w[0]);
    for (int i = 1; i < N; i++) {
        if (w[i - 1].back() != w[i][0]) {
            return false;
        }
        if (s.count(w[i]) > 0) {
            return false;
        }
        s.insert(w[i]);
    }
    return true;
}

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

    cout << (solve() ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n, m, c;
    cin >> n >> m >> c;
    int cnt = 0;
    int b[m];
    REP(i, m)
    {
        cin >> b[i];
    }
    REP(i, n)
    {
        int ans = c;
        REP(j, m)
        {
            int t;
            cin >> t;
            ans += b[j] * t;
        }
        if (ans > 0)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}


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



}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main() {
    string s="abcdefghijklmnopqrstuvwxyz";
    string s1="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    char a,b;
    cin>>a;
    for(int i=0;i<s.size();i++)
    {
    	if(a==s[i])
    	{
    		b='a';
    		break;
		}
		if (a==s1[i])
		{
			b='A';
			break;
		}
		
	}
	cout<<b;
	return 0;
}

Measured memory_bytes: 3040
#include <stdio.h>

int N,a[100000][2];

main(){
    int i,j;
    scanf("%d",&N);
    for(i=0;i<N;i++)
        scanf("%d",&a[i][0]);

    i=j=0;
    while(1){
        if(a[i][1]++){
            puts("-1");
            break;
        }
        if(a[1][1]){
            printf("%d\n",j);
            break;
        }
        i=a[i][0]-1;
        j++;
    }
    return 0;
}

Measured memory_bytes: 896
N = int(input())
L = list(map(int,input().split()))
LS = sorted(L)

ansL = []

if N <= 2:
    print(0)
else:
    for i in range(N-2):
        for j in range(i+1,N-1):
            for k in range(1+j,N):
                if LS[i] + LS[j] > LS[k] and not LS[i] == LS[j] and not LS[j] == LS[k] and not LS[k] == LS[i]:
                    yo,u,so = sorted([LS[i],LS[j],LS[k]])
                    ansL.append((yo,u,so))
    print(len(ansL))


Measured memory_bytes: 94212
import  math
n, d = map(int,input().split())
x = []
total=0
num = 0
for i in range(n):
    x.append(list(map(int,input().split())))

for a in range(n):
    for b in range(a+1,n):
        for c in range(d):
            total+= (x[a][c]-x[b][c])**2
        result=math.sqrt(total)
        if(result.is_integer()):
            num+=1

        total=0
print(num)

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-8;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    rep(i, n - k) {
        if (a[i] < a[i + k])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define int long long
#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++)
using namespace std;

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int h, a;
    cin >> h >> a;
    if (h % a == 0) cout << h/a << endl;
    else cout << h/a +1 << endl;
    return 0;
}

Measured memory_bytes: 256
use std::collections::*;
use std::io::*;
use std::*;
macro_rules! get {
    ($($t:tt),*; $n:expr) => {
        {
            let stdin = std::io::stdin();
            let ret = std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
                let line = line.unwrap();
                let mut it = line.split_whitespace();
                _get!(it; $($t),*)
            }).collect::<Vec<_>>();
            ret
        }
    };
    ($($t:tt),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut it = line.split_whitespace();
            _get!(it; $($t),*)
        }
    };
}
macro_rules! _get {
    // iterator(splitted input-string) => iterator(output-type)
    ($it:ident; [char]) => {
        _get!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; usize1) => {
        $it.next().unwrap().parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap().parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:ty),+) => {
        ($(_get!($it; $t)),*)
    };
}

fn main() {
    let (l, r, d) = get!(i32, i32, i32);
    let mut ans = 0;
    for i in l..=r {
        if i % d == 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2112
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int q = Integer.parseInt(scan.next());

        UnionFind uf = new UnionFind(n);
        for (int i = 0; i < q; i++) {
            int com = Integer.parseInt(scan.next());
            int x = Integer.parseInt(scan.next());
            int y = Integer.parseInt(scan.next());
            if (com == 0) {
                uf.unite(x, y);
            } else {
                if (uf.same(x, y)) {
                    System.out.println("1");
                } else {
                    System.out.println("0");
                }
            }
        }
        scan.close();
    }

    static class UnionFind {
        /** ルートノード */
        private int[] roots;

        /**
         * コンストラクタ.
         *
         * @param n ノード数
         */
        public UnionFind(int n) {
            roots = new int[n];
            for (int i = 0; i < n; i++) {
                roots[i] = i;
            }
        }

        /**
         * 各々のノードが属するグループを結合する.
         *
         * @param x
         * @param y
         */
        public void unite(int x, int y) {
            roots[getRoot(y)] = getRoot(x);
        }

        /**
         * 各々のノードが属するグループが同じかどうかを判定する.
         *
         * @param x
         * @param y
         * @return 同じグループに属するならtrue
         */
        public boolean same(int x, int y) {
            return getRoot(x) == getRoot(y);
        }

        /**
         * ルートノードを返す.<br>
         * 再帰によって経路圧縮を行っている.
         *
         * @param x
         * @return ルートノード
         */
        private int getRoot(int x) {
            int parent = roots[x];
            if (x != parent) {
                roots[x] = getRoot(parent);
            }
            return roots[x];
        }
    }

}



Measured memory_bytes: 71784
#include <cstdio>
#include <algorithm>
 
int left, right, ans;
int cnt[2019], min[2];
 
int main() {
    scanf("%d%d", &left, &right);
    right = std::min(right, left + 2019);
    ans = 2019;
    for (int i = left; i <= right ; ++i) {
        for (int j = i + 1; j <= right; ++j) {
            ans = std::min(ans, (i % 2019) * (j % 2019) % 2019);
        }
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
// Problem : A - Not
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*

WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!

Falling down is an accident, Staying down is a choice.

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

int main()
{
    io;
    ll in;
    cin>>in;
    if(in==0)
    {
    	cout<<1;
    }
    else
    {
    	cout<<0;
    }
    return 0;
}



Measured memory_bytes: 3600