akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define INFTY 1000000000

int l[500000]={};
int r[500000]={};
int a;
int hairetu[1000000];
void merge(int,int,int);
void mergesort(int,int);

int main(){
  int b,i,left,right;
  a=0;
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&hairetu[i]);
  }
  left=0;
  right=b;
  mergesort(left,right);
  for(i=0;i<b;i++){
    if(i!=b-1)printf("%d ",hairetu[i]);
    else printf("%d\n",hairetu[i]);
  }
  printf("%d\n",a);
  return 0;
}
void merge(int left,int mid,int right){
  int i,j,k,n1,n2;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    l[i]=hairetu[left+i];
  }
  for(i=0;i<n2;i++){
    r[i]=hairetu[mid+i];
  }
  l[n1]=INFTY;
  r[n2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    a++;
    if(l[i]<=r[j]){
      hairetu[k]=l[i];
      i++;
    }
    else{
      hairetu[k]=r[j];
      j++;
    }
  }
}
void mergesort(int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(left,mid);
    mergesort(mid,right);
    merge(left,mid,right);
  }
}

Measured memory_bytes: 5764
#include <atcoder/all>
using namespace std;
using namespace atcoder;
int main()
{
    int n, q;
    cin >> n >> q;
    dsu uf(n);
    for(int i = 0; i < q; i++)
    {
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0)
        {
            uf.merge(u, v);
        }
        else
        {
            if(uf.same(u, v)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 3912
#!/usr/bin/env python3
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
#import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
#from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())

n,k = MI()
if n%k == 0:
    print(0)
else:
    n = n%k
    while abs(n-k) < n:
        n = abs(n-k)
    print(n)


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

int main()
{
    int H, N;
    cin >> H >> N;

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

    int sum = accumulate(A.begin(), A.end(), 0);
    if (sum >= H) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640
// IN the name of GOD

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M = 1e9 + 7;

void solve () {
    int z1, z2;
    cin >> z1 >> z2;
    int x, y;
    bool ok = 0;
    if (z2 < 2*z1 || z2 > 4*z1) {
        cout << "No";
        return;
    }
    if ((z2 - 2*z1)%2) {
        cout << "No";
        return;
    }
    cout << "Yes";
}

int main () {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
        // scanf("%d", &tt);
    while (tt--)
        solve();
 
}


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

#define f first
#define s second
#define ins insert
#define pb push_back
#define endl '\n'
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
#define sz(c) (int) (c).size()
#define trav(x,c) for(auto &(x) : (c))
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define _for(i,a,n) for(int (i) = (a) ; (i) < (n); ++(i))
#define _rfor(i,a,n) for(int (i) = (n)-1 ; (i) >= (a); --(i))
#define db(x) cout << (#x) << ": " << (x) << endl;
#define _db(c) trav(x,c) cout << (x) << " "; cout << endl;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(0);
#define tc int t; cin >> (t); while ((t)--)

int main() {
	godspeed;
	
	int count = 0;
	string s; cin >> s;
	string t; cin >> t;

	for (int i = 0 ; i < sz(s) ; ++i) 
		if(s[i] != t[i]) count++;

	cout << count;
}

Measured memory_bytes: 3824
#include<stdio.h>

int tf[20][20];

int judge(int x,int y,int w,int h){
  int cnt=1;
  int i,j;
  tf[x][y]=1;
  if(x-1>=0){
    if(tf[x-1][y]==0){
      cnt+=judge(x-1,y,w,h);
    }
  }
  if(y-1>=0){
    if(tf[x][y-1]==0){
      cnt+=judge(x,y-1,w,h);
    }
  }
  if(x+1<=h-1){
    if(tf[x+1][y]==0){
      cnt+=judge(x+1,y,w,h);
    }
  }
  if(y+1<=w-1){
    if(tf[x][y+1]==0){
      cnt+=judge(x,y+1,w,h);
    }
  }
  return cnt;
}

void doit(int w,int h){
  char maze[h][w+1];
  int x,y;
  int i,j;
  for(i=0;i<h;i++){
    scanf("%s",maze[i]);
    for(j=0;j<w;j++){
      if(maze[i][j]=='#'){
	tf[i][j]=1;
      }
      else{
	tf[i][j]=0;
	if(maze[i][j]=='@'){
	  x=i;
	  y=j;
	}
      }
    }
  }
  printf("%d\n",judge(x,y,w,h));
}

int main(){
  int w,h;
  scanf("%d %d",&w,&h);
  while(w!=0){
    doit(w,h);
    scanf("%d %d",&w,&h);
  }
  return 0;
}

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

int main() {
    /*変数定義，入力*/
    int N;
    cin >> N;
    vector<int> d(N);  rep(i, N) cin >> d[i];
    int sum = 0;

    /*演算*/
    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            sum += d.at(i)*d.at(j);
        }
    }
    /*出力*/
    cout << sum << endl;

    /*終了*/
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    xn = []
    yn = []
    hn = []
    for i in range(N):
        xi, yi, hi = map(int, input().split())
        xn.append(xi)
        yn.append(yi)
        hn.append(hi)
    for Cx in range(101):
        for Cy in range(101):
            last = None
            flg = True
            for i in range(N):
                if 0 == hn[i]:
                    continue
                H = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]
                if H < 1:
                    flg = False
                    break
                if last:
                    if H != last:
                        flg = False
                        break
                last = H
            if not flg:
                continue
            for i in range(N):
                if 0 == hn[i]:
                    h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                    if h < H:
                        flg = False
                        break
            if not flg:
                continue
            print(Cx, Cy, H)
            return


main()


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int H, W;
string grid[55];

inline bool check(int h, int w){
  int cnt = 0;
  if(h + 1 == H || grid[h + 1][w] == '.') cnt++;
  if(h - 1 < 0 || grid[h - 1][w] == '.') cnt++;
  if(w + 1 == W || grid[h][w + 1] == '.') cnt++;
  if(w - 1 < 0 || grid[h][w - 1] == '.') cnt++;

  if(cnt == 4) return false;
  return true;
}


int main(){
  FAST_IO

  cin >> H >> W;

  for(int rep = 0; rep < H; ++rep) cin >> grid[rep];

  for(int h = 0; h < H; ++h){
    for(int w = 0; w < W; ++w){
      if(grid[h][w] == '.') continue;

      if(!check(h, w)){
        cout << "No\n";
        return 0;
      }

    }
  }

  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define INT_INF (2 * 1e9)
#define LL_INF  (2LL * 1e18)
#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#endif
 
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9 + 7;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }

void solve()
{
	int n;
	cin >> n;

	vector<int> arr(n);

	for(auto& el: arr)
		cin >> el;

	int ans = arr[0];

	for(auto el: arr)
		ans = __gcd(ans, el);

	cout << ans << endl;
}

int main(int argc, char** argv)
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#define int long long
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 5;
int n;
int head[MAXN] , to[MAXN << 1] , nxt[MAXN << 1] , cnt , ans , du[MAXN << 1];
LL f[MAXN] , a[MAXN];
void add(int u , int v) {nxt[++cnt] = head[u];head[u] = cnt;to[cnt] = v;}
void dfs(int x , int fa) {
	LL _sum = 0 , mx = 0;
	for (int i = head[x]; i; i = nxt[i]) {
		if(to[i] == fa) continue;
		dfs(to[i] , x);
		if(ans) return;
		mx = max(mx , f[to[i]]);
		_sum += f[to[i]];
	}
	if(!_sum) {
		f[x] = a[x];
		return;
	}
	f[x] = 2ll * a[x] - _sum;
	if(f[x] < 0 || f[x] > a[x] || mx - f[x] > _sum - mx) {
		printf("NO");
		exit(0);
	}
}
signed main() {
	scanf("%lld" , &n);
	for (int i = 1; i <= n; ++i) scanf("%lld" , &a[i]);
	if (n == 2) return puts(a[1] == a[2] ? "YES" : "NO"), 0;
	int root = 0;
	for (int i = 1; i < n; ++i) {
		int u , v;
		scanf("%lld %lld" , &u , &v);
		du[u] ++;du[v] ++;
		add(u , v);add(v , u);
		if(du[u] > 1) root = u;
		if(du[v] > 1) root = v;
	}
	dfs(root , 0);
	if(f[root]) printf("NO");
	else printf("YES");
	return 0;
}

Measured memory_bytes: 15784
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    char c;
    cin >> c;
    if(c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

struct UF {
  vector<int> par;
  vector<int> sizes;
  UF(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (sizes[x] < sizes[y]) {
      swap(x, y);
    }
    par[y] = x;
    sizes[x] += sizes[y];
    sizes[y] = 0;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
}; // UF

int V, E;
vvi edge;
ll cost;

void kruskal() {
  cost = 0;
  UF uf(V);
  rep (i, E) {
    auto e = edge[i];
    if (uf.same(e[1], e[2])) {
      continue;
    }
    uf.unite(e[1], e[2]);
    cost += e[0];
    if (uf.size(e[1]) == V) {
      break;
    }
  }
  return;
}

int main() {
  scanf("%d %d", &V, &E);
  edge.assign(E, vi(3));
  rep (i, E) {
    int s, t, w;
    scanf("%d %d %d", &s, &t, &w);
    edge[i][0] = w;
    edge[i][1] = s;
    edge[i][2] = t;
  }
  sort(all(edge));
  kruskal();
  printf("%lld\n", cost);

  return 0;
}

Measured memory_bytes: 8516
#include<bits/stdc++.h>
using namespace std;
bitset<2002010> f;//f[i]=1表示i可以取到
int n,x,s;
int main()
{
	cin>>n;
	f[0]=1;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		s+=x;
		f=(f|(f<<x));
	}
	for(int i=(s+1)/2;i<=s;i++)
	if(f[i])
	{
		cout<<i;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  v(string) s(3);
  rep(i,3){
    cin >> s[i];
  }
  int ans = 0;
  rep(i,N) {
    map<int,int> mp;
    mp[s[0][i]-'a']++;
    mp[s[1][i]-'a']++;
    mp[s[2][i]-'a']++;
    ans += sz(mp)-1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,q,k,S[100000],T[50000],left,right,mid,count=0;
  scanf("%d",&n);
  for(k=0;k<n;k++){
    scanf("%d",&S[k]);
  }
  scanf("%d",&q);
  for(k=0;k<q;k++){
    scanf("%d",&T[k]);
  }
  
  for(k=0;k<q;k++)
    {
      left = 0;
      right = n;
      while(left<right)
	{
	  mid=(left+right)/2;
	  if(S[mid]==T[k]){count++;break;}
	  else if(T[k]<S[mid]){right = mid;}
	  else {left = mid+1;}
	}
    }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2300
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>
#include<random>
using namespace std ;

#define MAXN 200007

int n , lim ;
pair < int , int > a[ MAXN ] ;

int srt[ MAXN ] ;

bool p[ MAXN ] ;

bool cmp1 ( int p1 , int p2 ) {
    if ( a[ p1 ].first != a[ p2 ].first ) { return a[ p1 ].first < a[ p2 ].first ; }
    return a[ p1 ].second > a[ p2 ].second ;
}

bool cmp2 ( int p1 , int p2 ) {
    if ( a[ p1 ].second != a[ p2 ].second ) { return a[ p1 ].second > a[ p2 ].second ; }
    return a[ p1 ].first < a[ p2 ].first ;
}

void input ( ) {
    scanf ( "%d%d" , &n , &lim ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        scanf ( "%d%d" , &a[ i ].first , &a[ i ].second ) ;
        srt[ i ] = i ;         
    }
}

void solve ( ) {
    sort ( srt + 1 , srt + n + 1 , cmp1 ) ;
    int id = 1 ;
    int sm = 0 ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        if ( a[ srt[ i ] ].first >= id ) {
            ++ id ; ++ sm ;
            p[ srt[ i ] ] = true ;
        }
    }
    sort ( srt + 1 , srt + n + 1 , cmp2 ) ;
    int en = lim ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        if ( en < id ) { break ; }
        if ( a[ srt[ i ] ].second <= en && p[ srt[ i ] ] == false ) {
            -- en ; ++ sm ;
        }
    }
    printf ( "%d\n" , n - sm ) ;
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 2816
s = input()

def first_A(s):
  for i in range(len(s)):
    if s[i] == "A":
      return i
    
def last_Z(s):
  for i in range(len(s)):
    if s[-(i+1)] == "Z":
      return -(i+1)+len(s)
    
print(last_Z(s) - first_A(s) + 1)

Measured memory_bytes: 9280
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int mp[12][12];
int imos[10][12][12];

int get(int t, int x1, int y1, int x2, int y2){
    return imos[t][y2][x2] - imos[t][y2][x1 - 1] - imos[t][y1 - 1][x2] + imos[t][y1 - 1][x1 - 1];
}

int getMin(int x1, int y1, int x2, int y2){
    for(int i = 0; ;i++){
        if(get(i, x1, y1, x2, y2))return i;
    }
}
int getMax(int x1, int y1, int x2, int y2){
    for(int i = 9; ;i--){
        if(get(i, x1, y1, x2, y2))return i;
    }
}

int getMinEdge(int x1, int y1, int x2, int y2){
    int mn = getMin(x1, y1, x2, y1);
    mn = min(mn, getMin(x1, y2, x2, y2));
    mn = min(mn, getMin(x1, y1, x1, y2));
    mn = min(mn, getMin(x2, y1, x2, y2));
    return mn;
}

int main(){

    for(int d, w; cin >> d >> w, d; ){
        int ans = 0;
        for(int y = 1; y <= d; y++){
            for(int x = 1; x <= w; x++){
                cin >> mp[y][x];
            }
        }
        for(int i = 0; i < 10; i++){
            for(int y = 0; y < 12; y++){
                for(int x = 0; x < 12; x++){
                    imos[i][y][x] = 0;
                }
            }
            for(int y = 1; y <= d; y++){
                for(int x = 1; x <= w; x++){
                    imos[i][y][x] = imos[i][y][x - 1];
                    if(mp[y][x] == i)imos[i][y][x]++;
                }
            }
            for(int x = 1; x <= w; x++){
                for(int y = 1; y <= d; y++){
                    imos[i][y][x] += imos[i][y - 1][x];
                }
            }
        }
        for(int y1 = 1; y1 <= d; y1++){
            for(int x1 = 1; x1 <= w; x1++){
                for(int y2 = y1 + 2; y2 <= d; y2++){
                    for(int x2 = x1 + 2; x2 <= w; x2++){
                        int flg = 1;
                        int tmp = 0;
                        int edge = getMinEdge(x1, y1, x2, y2);
                        for(int i = 0; i < 10; i++){
                            int cnt = get(i, x1+1, y1+1, x2-1,y2-1);
                            if(edge <= i && cnt)flg = 0;      
                            tmp += (edge - i) * cnt;
                        }
                        if(flg){
                            ans = max(ans, tmp);
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define REP(i, N) for (int i = 0; i < N; i++)

bool visited[100][100];

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

    vector<pair<int, int>> ans;
    if (n % 2 == 1)
    {
        for (int i = 1; i < n; i++)
        {
            ans.push_back(make_pair(n, i));
        }
        n--;
    }

    vector<pair<int, int>> v;
    for (int i = 1; i <= n / 2; i++)
    {
        v.push_back(make_pair(i, n - i + 1));
    }

    for (auto p : v)
    {
        for (int i = 1; i <= n; i++)
        {
            if (i != p.second && i != p.first && !visited[p.first][i])
            {
                ans.push_back(make_pair(p.first, i));
                visited[p.first][i] = true;
                visited[i][p.first] = true;
            }
            if (i != p.first && i != p.second && !visited[p.second][i])
            {
                ans.push_back(make_pair(p.second, i));
                visited[p.second][i] = true;
                visited[i][p.second] = true;
            }
        }
    }

    int m = ans.size();
    cout << m << endl;
    for (auto p : ans)
    {
        cout << p.first << " " << p.second << endl;
    }

    return 0;
}

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

using namespace std;

const int   N   = 1e5 + 1;

string s;

int main()  {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> s;
	
	int n = s.size();   s = "0" + s;
	
	for(int i = 0 ; i <= n / 2 ; ++i)
		if (s[i] != s[n - i])
			return 0 * puts("-1");
	
	vector<int> v;
	
	for(int i = 1 ; i <= n ; ++i)
		if (s[i] == '1')    v.push_back(i);
	
	v.push_back(n);
	
	if (v[0] != 1)  return 0 * puts("-1");
	
	int cur = n, curRoot = n - 1;
	
	for(int i = 1 ; i < v.size() ; ++i) {
		cout << cur << " " << curRoot << "\n";
		if (v[i] == v[i - 1] + 1)   {
			cur = curRoot--;
			continue;
		}
		int num = v[i] - v[i - 1] - 1;
		cur = curRoot;
		while(num--)    cout << --cur << " " << curRoot << "\n";
		swap(--cur,curRoot);
	}
}

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

using namespace std;
#define ll long long int
const int mod = 1e9+7;
int main()
{
    ll n,k;
    cin >> n >> k;

    ll tot = 0;
    for(ll i=k;i<=n+1;i++){
        ll mn = i*(i-1)/2;
        ll mx = (n-i+1+n)*i/2;
        tot += (mx-mn+1);
        tot %= mod;
    }
    cout<<tot<<endl;
}


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

if n < 10:
    print(n)
elif n < 100:
    print(9)
elif n < 1000:
    print(9 + (n-100+1))
elif n < 10000:
    print(9 + 900)
elif n < 100000:
    print(9 + 900 + (n-10000+1))
else:
    print(9 + 900 + 90000)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] d = new int[n];


		for(int i = 0;i < n; i++) {
			d[i] = sc.nextInt();
		}
		int ans =0;
		for(int i = 0; i < n; i++) {
			for(int j = i + 1; j < n; j ++){
				ans += d[i] * d[j];
			}
		}

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 21844
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}
 
fn main() {
  let n: u32 = read();

  if n < 1200 {
    println!("ABC");
  } else {
    println!("ARC");
  }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
typedef pair<int,int> P;
typedef pair<int,P> PP;
char m[1111][1111];
int ans[1111][1111];
signed main(){
  int h,w;
  cin>>h>>w;
  int INF=11111111;
  fill_n(*ans,1111*1111,INF);
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
	 cin>>m[i][j];
    
  for(int i=0;i<h;i++){
    int cnt=-1;
    for(int j=0;j<w;j++){
	 if(cnt==-1&&m[i][j]=='#'){
	   cnt=0;
	 }
	 if(cnt==-1)continue;
	 if(m[i][j]=='#')cnt=0;
	 ans[i][j]=min(ans[i][j],cnt);
	 cnt++;
    }
    cnt=-1;
    for(int j=w-1;j>=0;j--){
	 if(cnt==-1&&m[i][j]=='#'){
	   cnt=0;
	 }
	 if(cnt==-1)continue;
	 if(m[i][j]=='#')cnt=0;
	 ans[i][j]=min(ans[i][j],cnt);
	 cnt++;
    }
  }
  /*
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
	 cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }
  
  */
  for(int i=0;i<w;i++){
    int cnt=-1;
    for(int j=0;j<h;j++){
	 if(cnt==-1&&ans[j][i]!=INF){
	   cnt=ans[j][i];
	 }
	 if(cnt==-1)continue;
	 ans[j][i]=cnt=min(cnt,ans[j][i]);
	 cnt++;
    }
    cnt=-1;
    for(int j=h-1;j>=0;j--){
	 if(cnt==-1&&ans[j][i]!=INF){
	   cnt=ans[j][i];
	 }
	 if(cnt==-1)continue;
	 ans[j][i]=cnt=min(cnt,ans[j][i]);
	 cnt++;
    }
  }
  /*
  cout<<"b"<<endl;  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
	 cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }

  */
  int a=0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
	 a=max(a,ans[i][j]);

  cout<<a<<endl;
  return 0;
}


Measured memory_bytes: 11008
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
#include<algorithm>
#include<string>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define LL  long long int 
#define Pi 3.14159265358979;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a, b;
	int i = 0, j = 0,k = 0;//ループ用配列
	int ans = -1001001001;

	cin >> a >> b;
	if ((a + b) > ans)ans = a + b;
	else;
	if ((a - b) > ans)ans = a - b;
	else;
	if ((a * b) > ans)ans = a * b;
	else;

	cout << ans << "\n";
}


Measured memory_bytes: 3620
import itertools
import numpy as np


n,m = map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
ls = list(itertools.permutations(range(1,n+1)))

count=0
for route in ls:
    if route[0]!=1:
        break

    flag = True
    for i in range(n-1):
        if ( ([route[i],route[i+1]] in ab) or ([route[i+1],route[i]] in ab) )  == False:
            flag = False
            continue
    if flag == False:
        continue
    count +=1

print(count)


Measured memory_bytes: 31924
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    class Edge
    {
        public int dest;
        public Edge(int dest)
        {
            this.dest = dest;
        }
    }

    static void Main(string[] args)
    {
        // 行数を取得
        int n = int.Parse(Console.ReadLine().Split()[0]);
        
        // EdgeのListを持つVertexのListを作成
        var adjList = new List<List<Edge>>();

        // パース
        for (int i = 0; i < n; i++)
        {
            var line = Console.ReadLine().Split().Select(str => int.Parse(str)).ToArray();
            int k = line[1];
            adjList.Add(new List<Edge>());
            for (int j = 2; j < k + 2; j++)
            {
                adjList[i].Add(new Edge(line[j] - 1));
            }
        }

        for (int i = 0; i < adjList.Count; i++)
        {
            string line = "";
            for (int j = 0; j < adjList.Count; j++)
            {
                if (j > 0)
                {
                    line += " ";
                }
                bool isExist = false;
                for (int l = 0; l < adjList[i].Count; l++)
                {
                    if (j == adjList[i][l].dest)
                    {
                        isExist = true;
                        break;;
                    }
                }
                line += isExist ? "1" : "0";
            }
            System.Console.WriteLine(line);
        }
    }
}



Measured memory_bytes: 9768
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define VL vector < ll >
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
#define cu cout<<
#define en endl
#define sp " "
#include<cstdio>
#include<cstring>
void bug()
{
    cout << "here\n";
}
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
#define N 10000009
bool prime[N];
vector<ll> prm;
void seive ()
{
    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {

        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
bool isprime(ll n)
{
    if(n<2) return 0;
    if(n==2) return 1;
    else
    {
        for(int i=2; i*i<=n; i++)
            if(n%i==0) return 0;
    }
    return 1;

}

ll countSum(ll x)
{
    ll res = 0;
    while (x != 0)
    {
        res += (x % 10);
        x /= 10;
    }
    return res;
}
const int nx = 2e6+5;
int us[nx];
int a[nx],w[nx];
int main()
{
    fast;

    int n,m;
    cin>>n>>m;
   int ac=0,wa=0;
    for(int i=0; i<m; i++)
    {
        int p;
        string s;
        cin>>p>>s;

        if(s=="AC")
        {
            if(a[p]==0)ac++;
            a[p]=1;
        }
        else if(s=="WA")
        {
            if(a[p]==0)w[p]++;
        }
    }

    for(int i=1; i<=n; i++)if(a[i]==1)wa+=w[i];

    cout<<ac<<" "<<wa;

}









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

int main(){
  int64_t n;
  cin >> n;
  if(n%11==0){
    cout << n/11*2 << endl;
  }else{
    int64_t ans=n/11*2;
    n-=ans/2*11;
    if(n<=6)
      ans++;
    else
      ans+=2;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  int d, t, s;
  cin >> d >> t >> s;
  if (t * s >= d) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

const ll MODULO = 1000000007L;
ll mod_minus(ll x, ll modval) {
    if (x >= 0) {
        return x % modval;
    } else {
        ll mm = ((-x) % modval);
        if (mm == 0) {
            return 0;
        } else {
            return modval - mm;
        }
    }
}
ll mod(ll x) {
    return mod_minus(x, MODULO);
}

ll mod_pow(ll x, ll n, ll modval) {
    if (n == 0) {
        return 1;
    }
    ll res = mod_pow(x * x % modval, n / 2, modval);
    if (n & 1) {
        res = res * x % modval;
    }
    return res;
}
// ll pow(ll x, ll n) {
//     return mod_pow(x, n, MODULO);
// }

// void recursive(ll k, ll r, vector<vector<ll>>& dp) {
//     dp[k][r] = dp[k - 1][r - 3];
// }
int main() {
    ll S;
    cin >> S;

    ll total = 0;
    // k桁でトップをtに固定したとき合計r以下になる個数
    //vector<vector<vector<ll>>> dp(700, vector<vector<ll>>(2001, vector<ll>(2001, 0)));

    if (S <= 2) {
        print(0);
        return 0;
    }
    total = 1;

    // k桁で合計r以下になる個数
    vector<vector<ll>> dp(700, vector<ll>(2001, 0));
    for (ll r = 3; r <= 2000; r++) {
        dp[1][r] = r - 2;
    }

    ll max_k = S / 3;
    for (ll k = 2; k <= max_k; k++) {
        for (ll r = 3; r <= 2000; r++) {
            dp[k][r] = mod(dp[k][r - 1] + dp[k - 1][r - 3]);
        }
        total = mod(total + mod(dp[k][S] - dp[k][S - 1]));
    }
    print(total);
}


Measured memory_bytes: 14200
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;

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

	int N = scan.nextInt();
	int K = scan.nextInt();

	Integer[] l_ = new Integer[N];
	for(int i = 0; i < N; i++){
	    l_[i] = scan.nextInt();
	}

	Arrays.sort(l_, Comparator.reverseOrder());

	int len = 0;
	for(int i = 0; i < K; i++){
	    len += l_[i];
	}

	System.out.println(len);
    }
}

	


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

int main(){
    int n;
    cin >>n;
    int h[n];
    rep(i,n){
        cin >>h[i];
    }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout << dp[n-1] <<endl;
    return 0;
}

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



const int INF = 10010010;

int main() {
    int h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--;
    cw--;
    dh--;
    dw--;
    
    vector<vector<char>> s(h,vector<char>(w));
    rep(i,h) {
        rep(j,w) {
            cin >> s[i][j];
        }
    }
    
    
    vector<vector<int>> d(h,vector<int>(w,INF));
    int wh[4] = {1,0,-1,0}, ww[4] = {0,1,0,-1};
    int lh[20] =
            {-2,-2,-2,-2,-2,
            -1,-1,-1,-1,
            0,0,
            1,1,1,1,
            2,2,2,2,2
            };
    int lw[20] =
            {-2,-1,0,1,2,
            -2,-1,1,2,
            -2,2,
            -2,-1,1,2,
            -2,-1,0,1,2
            };
    
    deque<P> que;
    que.push_front(P(ch,cw));
    //que.push_back(P(ch,cw));
    d[ch][cw] = 0;
    
    while(que.size()) {
        P p = que.front();
        que.pop_front();
        if(p.first == dh && p.second == dw)
            break;
        
        for(int i = 0; i < 4; i++) {
            int nh = p.first + wh[i], nw = p.second + ww[i];
            
            if(0 <= nh && nh < h && 0 <= nw && nw < w &&
               s[nh][nw] != '#' && d[nh][nw] > d[p.first][p.second]) {
                que.push_front(P(nh,nw));
                d[nh][nw] = d[p.first][p.second];
            }
        }
        
        for(int i = 0; i < 20; i++) {
            int nh = p.first + lh[i], nw = p.second + lw[i];
            
            if(0 <= nh && nh < h && 0 <= nw && nw < w &&
               s[nh][nw] != '#' && d[nh][nw] > d[p.first][p.second] + 1) {
                que.push_back(P(nh,nw));
                d[nh][nw] = d[p.first][p.second] + 1;
            }
        }
    }
    
    if(d[dh][dw] == INF)
        cout << -1 << endl;
    else
        cout << d[dh][dw] << endl;
    
    
    
    return 0;
}




Measured memory_bytes: 8636
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        for(int i = 0; i < a; i++){
            list.add(sc.nextInt());
        }
        ArrayList<Integer> list1 = new ArrayList<>(list);
        Collections.sort(list1);
        int center1 = list1.size() / 2 - 1;
        int center2 = center1 + 1;
        int ans = list1.get(center2) - list1.get(center1);
        
        System.out.println(ans);
    }
}

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

ll solve(int n) {
  int res = 0;
  for(int i=1;i<n;i++) {
    int a = (n-1)/i;
    //cout << i << " x " << a << endl;
    res += a;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  cout << solve(n);
}

Measured memory_bytes: 3652
//
// Created by misclicked on 3/7/20.
//

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

#define ONLINE_JUDGE
#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#else
    ios_base::sync_with_stdio(false);
    cin.tie();
#endif
    string s;
    cin >> s;
    if (s == "BBB" || s == "AAA")cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)


ll modpow(ll x, ll n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        ll h = modpow(x, n / 2);
        return h * h % MOD;
    } else {
        return x * modpow(x, n - 1) % MOD;
    }
}

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

int main() {
    int D, G; cin >> D >> G;
    vector<int> p(D), c(D);
    rep(i,D)  cin >> p[i] >> c[i];

    int ans = INF;
    rep(mask, 1<<D) {
      int score = 0, solved = 0, rest_max = -1;
      rep(i,D)  {
        if (mask >> i & 1){
          score += 100 * (i+1) * p[i] + c[i];
          solved += p[i];
        }else{
          rest_max = i;
        }
      }
      if (score < G){
        int plus = 100 * (rest_max + 1);
        int need = (G - score + plus - 1) / plus;
        if (need >= p[rest_max]){
          continue;
        }
        solved += need;
      }
      ans = min(ans, solved);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> W >> H >> N;
	vector<int>y(N);
	vector<int>x(N);
	for (int i = 0; i < N; i++) {
		cin >> y[i] >> x[i];
	}
	for (int i = 1; i < N; i++) {
		if (y[i] >= y[i - 1] && x[i] >= x[i - 1]) {
			K += max(y[i] - y[i - 1], x[i] - x[i - 1]);
		}
		else if (y[i] <= y[i - 1] && x[i] <= x[i - 1]) {
			K += max(y[i - 1] - y[i], x[i - 1] - x[i]);
		}
		else {
			K += abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
		}
	}
	cout << K << endl;
	return 0;
}


Measured memory_bytes: 3224
from collections import deque, defaultdict

N, M = map(int, input().split())
ab = []
for _ in range(N + M - 1):
    ab.append(tuple(map(int, input().split())))

in_cnt = defaultdict(int)
rev = defaultdict(list)
outs = defaultdict(list)
for a, b in ab:
    in_cnt[b - 1] += 1
    rev[b - 1].append(a - 1)
    outs[a - 1].append(b - 1)

res = []
queue = deque([i for i in range(N) if in_cnt[i] == 0])
while len(queue) != 0:
    v = queue.popleft()
    res.append(v)
    for v2 in outs[v]:
        in_cnt[v2] -= 1
        if in_cnt[v2] == 0:
            queue.append(v2)

order = [i for i, v in sorted(enumerate(res), key=lambda x: x[1])]

ans = [0] * N
ans[res[0]] = 0
for v in res[:0:-1]:
    ans[v] = max([(order[v2], v2) for v2 in rev[v]])[1] + 1

for a in ans:
    print(a)


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

using namespace std;

const int N = 234567;
int n, a[N];

long long sol() {

  if (a[0] != 0) return -1;

  long long res = 0;
  
  deque<int> ch;
  int delta = 0;


  for (int i = n - 1; i >= 1; --i) {

    if (ch.size() > 0 && ch[ch.size() - 1] > a[i] + delta) return -1;
    if (ch.size() == 0 || ch[ch.size() - 1] != a[i] + delta) ch.push_back(a[i] + delta);

    delta++;

//    cout << i << ": ";
//    for (int j = 0; j < ch.size(); ++j) cout << ch[j] << " ";
//    cout << endl;

    while (ch.size() > 0 && ch.front() - delta <= 0) {
      if (ch.front() == delta) ++res;
      ch.pop_front();
    }
    res += ch.size();


    if (ch.size() == 0) {  
      delta = 0;
    }
    
  }

  if (ch.size() != 0) return -1;

  return res;

}

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


  cout << sol() << endl;

  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <set>
using namespace std;
const int MAXN = 100005;
const int inf = 0x3f3f3f3f;
typedef long long LL;
int a[MAXN];
struct node{
    int from,to;
}edge[MAXN*2];
int head[MAXN];
int vis[MAXN];
int bin[MAXN];
int cnt;
void add(int u, int v)
{
    edge[cnt].to=v;
    edge[cnt].from=head[u];
    head[u]=cnt++;
}
int findx(int x)
{
    if(bin[x]==x)
        return x;
    return bin[x]=findx(bin[x]);
}
void merge(int u, int v)
{
    int fx=findx(u);
    int fy=findx(v);
    if(bin[fy]!=fx)
        bin[fy]=fx;
}
void dfs(int u)
{
    vis[u]=1;
    for(int i=head[u];~i;i=edge[i].from)
    {
        int v=edge[i].to;
        if(!vis[v])
        {
            bin[v]=cnt;
            dfs(v);
        }
    }
}
int main()
{
    int n, m;
    cnt=0;
    memset(head, -1, sizeof(head));
    memset(vis,0,sizeof(vis));
    scanf("%d %d", &n, &m);
    for(int i=1;i<=n;++i)
    {
        scanf("%d", &a[i]);
        bin[i]=i;
    }
    for(int i=0;i<m;++i)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        add(x,y);
        add(y,x);
    }
    int ans=0;
    cnt=1;
    for(int i=1;i<=n;++i)
    {
        if(!vis[i])
        {
            bin[i]=cnt;
            dfs(i);
            cnt++;
        }
        if(bin[a[i]]==bin[i])
            ans++;
    }
    printf("%d\n", ans);
    return 0;
}
 
 

Measured memory_bytes: 9948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    string k;
    ll d;
    cin >> k >> d;
    ll n = k.size();

    ll dp[n+1][2][d]; memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;

    zep(i, 0, n){
        ll x = k[i]-'0';

        zep(y, 0, d){
            dp[i+1][0][(y+x)%d] += dp[i][0][y];
            dp[i+1][0][(y+x)%d] %= MOD;

            rep(j, 0, x-1){
                dp[i+1][1][(y+j)%d] += dp[i][0][y];
                dp[i+1][1][(y+j)%d] %= MOD;
            }

            rep(j, 0, 9){
                dp[i+1][1][(y+j)%d] += dp[i][1][y];
                dp[i+1][1][(y+j)%d] %= MOD;
            }
        }
    }
    print((dp[n][0][0]+dp[n][1][0]+MOD-1)%MOD)
    
    return 0;
}

Measured memory_bytes: 15872
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
int main(){
  while(1){
    ll i,b[4010],a[4010],n,e[4010],p,q,k=0;
    scanf("%lld\n",&n);
    if(n==0){
      return 0;
    }
    for(i=0;i<=4000;i++){
      a[i]=0,b[i]=0;
    }
    for(i=0;i<n;i++){
      scanf("%lld %lld %lld\n",&e[i],&p,&q);
      a[e[i]]+=p*q;
    }
    for(i=0;i<n;i++){
      if(b[e[i]]==0 && a[e[i]]>=1000000){
        b[e[i]]=1;
        printf("%lld\n",e[i]);
        k++;
      }
    }
    if(k==0){
      printf("NA\n");
    }
  }
  return 0;
}


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

using namespace std;

int gcd(int a, int b){
	return b == 0 ? a : gcd(b, a % b);
}

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

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

	vector<int> prefix_gcd(n + 1);
	vector<int> suffix_gcd(n + 1);

	prefix_gcd[1] = a[1];
	for(int i = 2; i <= n; ++i){
		prefix_gcd[i] = gcd(a[i], prefix_gcd[i - 1]);
	}

	suffix_gcd[1] = a[n];
	for(int i = 2; i <= n; ++i){
		suffix_gcd[i] = gcd(a[n - i + 1], suffix_gcd[i - 1]);
	}

	int res = max(prefix_gcd[n - 1], suffix_gcd[n - 1]);
	for(int i = 2; i <= n - 1; ++i){
		res = max(res, gcd(prefix_gcd[i - 1], suffix_gcd[n - i]));
	}

	cout << res;
    return 0;
}


Measured memory_bytes: 1408
from collections import*
N,*AB=map(int,open(0).read().split())
E=[[]for _ in range(N+1)]
for a,b in zip(*[iter(AB)]*2):
	E[a]+=[b]
	E[b]+=[a]
def g(s):
	Q=deque([s]);d=[0]*(N+1)
	while Q:
		v=Q.popleft()
		for u in E[v]:
			if d[u]==0:
				Q+=[u]
				d[u]=d[v]+1
	return d[1:]
print("SFneunknee c"[0<sum(1 if f<=s else-1 for f,s in zip(g(1),g(N)))::2])

Measured memory_bytes: 31732
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(ll i=0;i<n;i++)
#define repp(i,a,b) for(ll i=a;i<=b;i++)
#define reff(i,a,b) for(ll i=a;i>=b;i--)
#define ll long long int
#define pll pair<ll,ll>
#define fill(a,x) memset(a,x,sizeof(a))
#define mb make_pair
#define pb push_back
#define F first
#define S second
#define M 1000000007
#define sc(x) scanf("%d",&x)
#define scc(x1,x2) scanf("%d%d",&x1,&x2)
#define sccc(x1,x2,x3) scanf("%d%d%d",&x1,&x2,&x3)
#define pr(x) printf("%lld ",x)
#define dbg(a)          std::cerr<<#a<<"="<<(a)<<"\n"
#define dbg1(a,b)       std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define dbg2(a,b,c)     std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define dbg3(a,b,c,d)   std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define all(v) v.begin(),v.end()
#define PI 3.14159265
#define co cout<<"fuck"<<endl
const int INF = 2034567891;
const ll INF64 = 4234567890123456789ll;
long long nc3(long long v){return (v * (v - 1ll) * (v - 2ll)) / 6ll;}
long long nc2(long long v){return (v * (v - 1ll)) / 2ll;}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
const int N = 10+2e5;
bool isprime(ll n) {
    if (n < 2) return 0;
    if (n == 2) return 1;
    if (n % 2 == 0) return 0;
    for (ll i = 3; i*i <= n; i++) if (n%i == 0) return 0;
    return 1;
}
double dist(pll p1, pll p2)
 {
    return (p1. F - p2.F)*(p1.F - p2.F) +
          (p1.S - p2.S)*(p1.S - p2.S);
 }
ll power(ll x,ll y)
{
    ll ans=1;
    while(y>0){
        if(y&1)
            ans=(ans*x)%M;
        x=(x*x)%M;
        y/=2;
    } 
    return ans;
}
int main()
{
     fast;
     ll x;
     cin>>x;
     if(x==101)
     {
       cout<<1;
       return 0;
	 }
     double po=1.01;
     double t = 100.0;
     repp(i,2,4000)
     {
        double f = po*t;
        ll an = f;
        t = an;
        //dbg(po);
        if(f>=x)
        { 
           cout<<i-1;
           break;
		}
	 }
}   

Measured memory_bytes: 3648