akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

const int inf = (int)1e9;

int main()
{
	int n, m, k;
	int ans = 0;
	vector<int> dist;
	vector<vector<pair<int, int> > > graph;
	vector<pair<pair<int, int>, int> > edge;
	
	scanf("%d%d%d", &n, &m, &k);
	dist.resize(n, inf);
	graph.resize(n);
	edge.reserve(m);
	for(int i = 0; i < m; ++i) {
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		a -= 1, b -= 1;
		edge.push_back(make_pair(make_pair(a, b), l));
		graph[a].push_back(make_pair(b, l));
		graph[b].push_back(make_pair(a, l));
	}
	
	for(int i = 0; i < k; ++i) {
		
		int s;
		scanf("%d", &s);
		s -= 1;
		
		priority_queue<pair<int, int> > q;
		
		q.push(make_pair(0, s));
		
		while(!q.empty()) {
			
			int v = q.top().second;
			int c = -q.top().first;
			q.pop();
			
			if(dist[v] < c)
				continue;
			dist[v] = c;
			
			for(int i = 0; i < graph[v].size(); ++i) {
				int w = graph[v][i].first;
				int d = graph[v][i].second + c;
				q.push(make_pair(-d, w));
			}
		}
	}
	
	//for(int i = 0; i < n; ++i)
	//	printf("[debug] %d -> %d\n", i, dist[i]);
	
	for(int i = 0; i < m; ++i) {
		
		int a = edge[i].first.first;
		int b = edge[i].first.second;
		int l = edge[i].second;
		int cost;
		
		if(dist[a] > dist[b])
			swap(a, b);
		
		if(dist[a] + l == dist[b])
			cost = dist[b];
		else
			cost = (l - (dist[b] - dist[a]) + 1) / 2 + dist[b];
		ans = max(ans, cost);
		//printf("[debug] (%d, %d) -> (%d, %d) -> %d -> %d\n", a, dist[a], b, dist[b], l, cost);
	}
	
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 7016
#include <stdio.h>

int main(void)
{
  char string[20];
  scanf("%s", string);

  for (int i = 0; i < 19; i++)
  {
    if (i == 5 || i == 13)
    {
      printf(" ");
      continue;
    }
    printf("%c", string[i]);
  }
  puts("");
  return 0;
}


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

def dfs(s, mx):
    if len(s) == n:
        print(s)
        return
    else:
        for i in range(ord("a"), ord(mx)+2):
            t = s
            t += chr(i)
            dfs(t, max(chr(i), mx))

dfs("a", chr(ord("a")))

Measured memory_bytes: 4404
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        if(a>b){
            int t=a;
            a=b;
            b=t;
        }if(b>c){
            int t=b;
            b=c;
            c=t;
        }if(a>b){
            int t=a;
            a=b;
            b=t;
        }
            System.out.println(a+" "+b+" "+c);
    }
}



Measured memory_bytes: 26304
from math import ceil
n = int(input())

total = 0
for i in range(ceil(n ** 0.5) + 1):
  if n % (i + 1) == 0:
    a = n // (i + 1) - 1
    if a >= 2 and n // a == n % a:
      total += a

print(total)

Measured memory_bytes: 3188
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
        int n; 
        cin >> n; 
        while(n){
                int m,g,d;
                cin >> m >> g >> d; 
                int kuji[d][n+1];
                memset(kuji,0,sizeof(kuji));
                for(int i = 0; i < d; i++){
                        int tmp;
                        cin >> tmp;
                        for(int j = n-1; j > 0; j--){
                                kuji[i][j] = tmp%10;
                                tmp /= 10;
                        }  
                }  
                int num[d+1][n+2];
                memset(num,0,sizeof(num));
                for(int i = 0; i < n; i++){
                        num[0][i+1] = i+1;
                }  
                for(int i = 0; i < d; i++){
                        memcpy(num[i+1], num[i], sizeof(num[i]));
                        for(int j = 1; j < n; j++){
                                if(kuji[i][j]) swap(num[i+1][j],num[i+1][j+1]);
                        }  
                }  
                if(num[d][g] == m) cout << 0 << endl;
                else{
                        bool f = true;
                        int s[2] = {num[d][g], m};
                        sort(s, s+2);
                        for(int i = 0; i < d; i++){
                                for(int j = 1; f && j < n; j++){
                                        int t[2] = {num[i][j], num[i][j+1]};
                                        sort(t, t+2);
                                        if(memcmp(s,t,sizeof(s)) == 0){
                                                if(kuji[i][j-1] + kuji[i][j] + kuji[i][j+1] == 0){
                                                        cout << i+1 << " " << j << endl;
                                                        f = false;
                                                }  
                                        }  
                                }  
                        }  
                        if(f) cout << 1 << endl;
                }  
                cin >> n; 
        }  
}

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

int main() {
  int n;
  cin >> n;
  int count = 100000;
  for (int i = 0; i < n; i++) {
    int s = 0;
    int a;
    cin >> a;
    if (a % 2 == 1){
      count = 0;
      break;
    }
    else {
      while (a % 2 == 0) {
        s++;
        a /= 2;
      }
      if (s < count) {
        count = s;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
x = int(input())
dp = [False] * (x + 106)
money_li = [100, 101, 102, 103, 104, 105]
dp[0] = True
for i in range(x + 1):
    if dp[i]:
        for money in money_li:
            dp[i + money] = True

print(1) if dp[x] else print(0)


Measured memory_bytes: 3828
#include<iostream>
#include<cmath>
using namespace std;
int n, I[1 << 10], R[1 << 10], V[1 << 10];
int main() {
	while (true) {
		cin >> n; if (n == 0)break;
		for (int i = 1; i <= n; i++) { cin >> I[i]; }
		long double minx = 100.0; int T = 0;
		for (int S = 0; S < 16; S++) {
			for (int A = 0; A < 16; A++) {
				for (int C = 0; C < 16; C++) {
					R[0] = S; long double sum = 0.0;
					for (int i = 1; i <= n; i++) R[i] = (A*R[i - 1] + C) % 256;
					for (int i = 0; i < 256; i++) V[i] = 0;
					for (int i = 1; i <= n; i++) V[(I[i] + R[i]) % 256]++;
					for (int i = 0; i < 256;i++){
						if (V[i] >= 1) {
							long double F = 1.0*V[i] / n;
							sum -= F*log(F);
						}
					}
					if (sum < minx) {
						minx = sum; T = S * 256 + A * 16 + C;
					}
				}
			}
		}
		cout << T / 256 << ' ' << (T / 16) % 16 << ' ' << T % 16 << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
  int r, g, b;
  scanf("%d %d %d", &r, &g, &b);

  if ((100 * r + 10 * g + b) % 4 == 0)
    printf("YES");
  else
    printf("NO");
}

Measured memory_bytes: 256
from fractions import gcd

A, B, K = list(map(int, input().split(" ")))

d = gcd(A, B)

def divisor(n):
    #for i in range(1,int(n**0.5)+1):
    ass = [i for i in range(1, n+1) if n % i == 0]
    return ass

ass = divisor(d)
#print(ass)
out = ass[-K]
print(out)

Measured memory_bytes: 5076
# F - Strivore
import sys
MOD = 10**9+7
K = int(input())
S = input()
l = len(S)
ans = 0
 
tmp = pow(26,K,MOD)
ans = tmp
waru = pow(26,-1,MOD)
 
for i in range(1,K+1):
    tmp = (tmp*25*waru)%MOD
    tmp = (tmp*(l-1+i)*pow(i,-1,MOD))%MOD
    ans = (ans+tmp)%MOD
 
print(ans)

Measured memory_bytes: 10808
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

const long long int MAX_N = 200000;

int main(int argc, char const *argv[]) {
  long long int N, K;
  long long int A[MAX_N];
  long long int cnt[MAX_N] = {0};
  cin >> N >> K;
  for (long long int i = 0; i < N; i++) cin >> A[i];

  for (long long int i = 0; i < N; i++) cnt[A[i]]++;
  sort(cnt, cnt + MAX_N, greater<long long int>());
  long long int ans = 0;

  for (long long int i = K; i < N; i++) ans += cnt[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<utility>
#include<tuple>
#include<set>
#include<list>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

const long long MAXN = 1e6;
const long long MOD = 1e9+7;
const long long INF = __LONG_LONG_MAX__ / 2;

using namespace std;

int l[MAXN];

signed main(){
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
      cin >> l[i];
    }
    sort(l, l+N);
    int sum = 0;
    for (int i = 0; i < K; i++)
    {
      sum+=l[N-1 -i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define foru(a,b,c) for(int a=b;a<=c;++a)
#define int long long

using namespace std;

int n;
int a[100001];
int dp[100001][2];

main()
{
    cin >> n;
    foru(i,1,n) cin >> a[i];
    int mi=1000000000,kq=0,re=0;
    foru(i,1,n)
    {
        kq+=abs(a[i]);
        if(a[i]<0) re++;
        if(abs(a[i])<mi)
        {
            mi=abs(a[i]);
        }
    }
    if(re%2) kq-=2*mi;
    cout << kq;
}

Measured memory_bytes: 1024
'use strict'

function main(input) {
  input = input.split('\n')[0].split(' ');
  const a = Number(input[0]);
  const b = Number(input[1]);

  const ans = (a * b) - (a + b - 1);
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

ll a[5];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	ll mi = 1e18, cur = -1;
	rep(i,5){
		cin >> a[i];
		if(a[i] <= mi){
			mi = a[i];
			cur = i;
		}
	}
	ll ans = n / mi + 5;
	if(n%mi == 0) --ans;
	cout << ans << endl;
	return 0;
}

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

//https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }


  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};


int main() {
    ll N,Q;
    string S;
    cin >> N >> S >> Q;
    SegmentTree<ll> seg(N,[](ll a,ll b){return a|b;},0);
    for(int i=0;i<N;i++){
        int t = S[i] -'a';
        seg.update(i,1<<t);
    }

    for(int q=0;q<Q;q++){
        int a;
        cin >> a;
        if(a==1){
            int b;
            char c;
            cin >> b >> c;
            --b;
            seg.update(b,1<<(c-'a'));
        }else{
            
            int b,c;
            cin >> b >>c;
            --b;--c;
            cout << __builtin_popcount(seg.query(b,c+1)) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 9092
import math
import numpy as np

def distance(y, z, d):
    y = np.array(y)
    z = np.array(z)
    delta2 = (y-z)**2
    return math.sqrt(sum(delta2))

n, d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))

cnt = 0
for i in range(n):
    for j in range(i+1, n):
        if distance(x[i], x[j], d).is_integer():
            cnt += 1
print(cnt)

Measured memory_bytes: 12504
// abc137_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int K, X;
    cin >> K >> X;

    const int sup = 1000000;
    const int inf = -1000000;

    int r = min(sup, X + K - 1);
    int l = max(inf, X - K + 1);


    REPN(i, l, r){
        cout << i << " ";
    }
    cout << r << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int puzzle[3][3];
int tmp[3][3];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 void empty(int *x,int *y) {
    int i,j;
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++) {
            if(!puzzle[i][j]) {
                *x = j;
                *y = i;
                return;
            }
        }
    }
}

 
void swap(int *a,int *b) {
    int tmp;
 
    tmp = *a;
    *a = *b;
    *b = tmp;
}
 
  
int cal() {
    int i,a,sum=0;
 
    for(i=0; i<9; i++) {
        a = puzzle[i/3][i%3];
        if(a) {
            a--;
            sum += abs(i/3 - a/3) + abs(i%3 - a%3);
        }
    }
    return sum;
}
 
 

int dfs(int x,int y,int p,int dep,const int lim) {
    int i,h,nx,ny,res;
 
    h = cal();
    if(h==0) return dep;
    if(dep+h>lim) return -1;
 
    for(i=0; i<4; i++) {
        nx = x+dx[i];
        ny = y+dy[i];
 
        if(~p && i==(p+2)%4) continue;
        if(!(0<=nx && nx<3 && 0<=ny && ny<3)) continue;
 
        swap(&puzzle[y][x],&puzzle[ny][nx]);
        res = dfs(nx,ny,i,dep+1,lim);
        if(~res) return res;
 
        swap(&puzzle[y][x],&puzzle[ny][nx]);
    }
 
    return -1;
}

int main() {
    int i,j,ans,x,y,l;
 
    //puzzle input
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++) scanf("%d",&puzzle[i][j]);
    }
 
 
    empty(&x,&y);
    for(l=0; l<100; l++) {
        //copy
        for(i=0; i<3; i++) {
            for(j=0; j<3; j++) tmp[i][j] = puzzle[i][j];
        }
 
        //dfs
        ans = dfs(x,y,-1,0,l);
        if(ans!=-1) {
            printf("%d\n",ans);
            break;
        }
 
        //copy
        for(i=0 ; i<3 ; i++) {
            for(j=0 ; j<3 ; j++) puzzle[i][j] = tmp[i][j];
        }
 
        //error
        ans = -1;
        if(l==99) printf("%d\n",ans);
    }
 
    //ans output
    //printf("%d\n",ans);
 
    return 0;
}
 

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

int N, M;
vector<int> v[100010];
int depth[100010];
int ans[100010] = {};

//void dfs(int);
void bfs();

int main() {
    
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
        //双方向にvectorでグラフを表現
    }
    //depth[1] = 1;
    //dfs(1);
    bfs();


    /*
    REP(i, 2, N + 1) {
        //cout << depth[i] << endl;
        if (depth[i] == INF) {
            cout << "No" << endl;
            return 0;
        }
    }
    */

    cout << "Yes" << endl;
    REP(i, 2, N + 1) {
        cout << ans[i] << endl;
    }
}

void bfs() {
    queue<int> q;
    //全てをINFで初期化
    rep(i, 100010) depth[i] = INF;
    q.push(1);
    depth[1] = 0;

    //キューが空になるまでループ
    while (q.size()) {
        //キューの先頭を取り出す
        int a = q.front(); q.pop();
        //移動先をループ
        rep(i, (int)v[a].size()) {
            //移動した後の部屋をbとする
            int b = v[a][i];
            if (depth[b] > depth[a] + 1) {
                q.push(b);
                depth[b] = depth[a] + 1;
                ans[b] = a;
            }
        }
    }
}

/*
void dfs(int a) {
    //aは前回のインデックス
    //dは前回の深さ
    //まずv[a]のやつを全部出してdfsする
    //もしdepthが一緒かこっちのほうがおおきかったらあきらめる
    rep(i, (int)v[a].size()) {
        //v[a][i]は向こう側のインデックス
        int b = v[a][i];
        if (b == a) continue;
        //cout << "a:" << a << " b:" <<  b << " ";
        if (depth[b] > depth[a] + 1) {
            depth[b] = depth[a] + 1;
            //cout << "depth[" << b << "]:" << depth[b] << endl;
            ans[b] = a;
            dfs(b);
        }
    }
}
*/

Measured memory_bytes: 10808
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(;;){
			int s1=sc.nextInt();
			int s2=sc.nextInt();
			int s3=sc.nextInt();
			double minR=sqrt(s1*s1+s2*s2);
			minR=min(minR, sqrt(s2*s2+s3*s3));
			minR=min(minR, sqrt(s3*s3+s1*s1));
			if(s1==0&&s2==0&&s3==0)
				break;
//			println(minR+"");
			int n=sc.nextInt();
			for(int i=0; i<n; i++){
				int r=sc.nextInt();
				if(2*r>minR)
					println("OK");
				else
					println("NA");
			}
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
package main

import (
	"fmt"
)

func main() {
	var a,b int
	fmt.Scan(&a,&b)
	x := a * b
	
	if a < b {
		tmp := a
		a = b
		b = tmp
	}
	
	r := a % b
	for r != 0 {
		a = b
		b = r
		r = a % b
	}
	
	fmt.Println(x / b)
}

Measured memory_bytes: 512
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 1e5;
int dp[N + 5];
vector<int> vec[N + 5];

int calc(int x) {
	if(dp[x] != -1) return dp[x];
	dp[x] = 0;
	for(int i = 0;i < vec[x].size();i++) {
		int nx = vec[x][i];
		dp[x] = max(dp[x], calc(nx) + 1);
	}
	return dp[x];
}

void hora(int tc) {
	int n,m;
	cin>>n>>m;
	memset(dp,-1,sizeof dp);
	for(int i = 0;i < m;i++) {
		int x,y;
		cin>>x>>y;
		vec[x].PB(y);
	}
	int res = -1;
	for(int i = 1;i <= n;i++)  {
		res = max(res, calc(i));
	}
	cout<<res<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}



Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((c-a<=d&&-d<=c-a)||((c-b<=d&&-d<=c-b)&&(a-b<=d&&-d<=a-b))){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1e18+7;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    ll p = 0;
    ll m = 0;
    pair<ll,ll> ans = {0,0};
    rep(i,0,n){
        p += a[i];
        m += a[i];
        if(i%2==0){
            if(p<=0){
                ans.first += 1-p;
                p = 1;
            }
            if(m>=0){
                ans.second += m+1;
                m = -1;
            }
        }
        else{
            if(p>=0){
                ans.first += p+1;
                p = -1;
            }
            if(m<=0){
                ans.second += 1-m;
                m = 1;
            }
        }
    }
    cout << min(ans.first,ans.second) << endl;
}

Measured memory_bytes: 1024
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int R, G, B, N; cin >> R >> G >> B >> N;
    int ans = 0;
    for(int i=0; R*i<=N; i++) {
        for(int j=0; R*i + G*j<=N; j++) {
            int rem = N - R*i - G*j;
            if(rem < 0) continue;
            if(rem % B != 0) continue;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  double t,a;
  cin>>n>>t>>a;
  vector<int> h(n);
  for(int i=0;i<n;i++) cin>>h[i];

  int ans=1;
  double min=1<<20;
  for(int i=0;i<n;i++){
    double tmp = t - (double)h[i]*0.006;
    double abs = tmp>a ? tmp-a:a-tmp;
    if(abs < min){
      min = abs;
      ans = i+1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N,M;
  cin >> N >> M;
  vector<string> A(N);
  REP(i, N) cin >> A[i];
  vector<string> B(M);
  REP(i, M) cin >> B[i];
  
  int flag2 = 0;
  REP(i,N-M+1){
    REP(j,N-M+1){
      int flag=0;
      REP(k,M){
        REP(l,M){
          if(B.at(k).at(l)!=A.at(i+k).at(j+l)){
            flag=1;
          }
        }
      }
      if(flag==0){
        flag2 = 1;
        break;
      }
    }
    if(flag2==1){
      break;
    }
  }
  if(flag2==1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def reflection(line, point):
    x0, y0, x1, y1 = line
    p, q = point
    x1 -= x0; y1 -= y0
    p -= x0; q -= y0
    cv = p*x1 + q*y1
    sv = p*y1 - q*x1
    cv2 = cv**2 - sv**2
    sv2 = 2*cv*sv
    dd = (p**2 + q**2)*(x1**2 + y1**2)
    if dd == 0:
        return x0 + p, y0 + q
    return x0 + (cv2 * p - sv2 * q) / dd, y0 + (sv2 * p + cv2 * q) / dd

def solve():
    x0, y0, x1, y1 = map(int, input().split())
    q = int(input())
    for i in range(q):
        x, y = map(int, input().split())
        print("%.16f %.16f" % reflection((x0, y0, x1, y1), (x, y)))
solve()


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

using namespace std;

using ll=int_fast64_t;

using ld=long double;

using pll=pair<ll,ll>;

using pld=pair<ld,ld>;

const ll INF=1LL<<60;

void solve();

int main(){

cin.tie(0);ios::sync_with_stdio(false);
cout<<fixed<<setprecision(10);solve();

}

#define foreach(i,a) for(auto &i:a)
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)

template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  vector<ll> A(n),B(n);
  rep(i,n) cin>>A[i];
  rep(i,n) cin>>B[i];

  ll ans=0;
  rep(d,30){
    ll T=1<<d;
    vector<ll> C(n),D(n);
    rep(i,n) C[i]=A[i]%(2*T);
    rep(i,n) D[i]=B[i]%(2*T);
    sort(D.begin(),D.end());
    ll cnt=0;
    foreach(c,C){
      cnt+=D.end()-lower_bound(D.begin(),D.end(),T-c);
      cnt-=D.end()-lower_bound(D.begin(),D.end(),2*T-c);
      cnt+=D.end()-lower_bound(D.begin(),D.end(),3*T-c);
      cnt-=D.end()-lower_bound(D.begin(),D.end(),4*T-c);
    }
    if(cnt&1) ans+=T;
  }
  cout<<ans<<"\n"; 
}

Measured memory_bytes: 6616
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias BC = Tuple!(long, "b", long, "c");

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    auto AS = readln.split.to!(long[]);
    sort!"a > b"(AS);

    BC[] BCS;
    BCS.length = M;
    foreach (ref bc; BCS) {
        auto l = readln.split.to!(long[]);
        bc = BC(l[0], l[1]);
    }
    sort!"a.c > b.c"(BCS);

    long r;
    int i, j;
    foreach (_; 0..N) {
        if (j < M && BCS[j].b <= 0) ++j;
        if (j == M || AS[i] > BCS[j].c) {
            r += AS[i++];
        } else {
            r += BCS[j].c;
            BCS[j].b -= 1;
        }
    }
    writeln(r);
}

Measured memory_bytes: 5248
import java.util.Arrays;
import java.util.Scanner;

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int ans = 0;

		int [] list = new int [] {A,B,C};
		Arrays.sort(list);

		ans = (10*list[2] + list[1]) + list[0];

		System.out.println( ans );
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int main() {
    int i, j, n, x, lo, hi;
    scanf("%d%d", &n, &x);
    if(x==1 || x==2*n-1) {
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    if(n==2) {
        printf("1\n2\n3\n");
        return 0;
    }
    vi a(2*n);
    if(x+2<=2*n-1) {
        a[n-2]=x+1;
        a[n-1]=x-1;
        a[n]=x;
        a[n+1]=x+2;
        lo=x-1;
        hi=x+2;
    }
    else {
        a[n-2]=x-2;
        a[n-1]=x+1;
        a[n]=x;
        a[n+1]=x-1;
        lo=x-2;
        hi=x+1;
    }
    i=j=1;
    while(i<=2*n-1) {
        if(i==n-2) i=n+2;
        if(j==lo) j=hi+1;
        a[i++]=j++;
    }
    for(i=1; i<=2*n-1; i++)
        printf("%d\n", a[i]);
    return 0;
}

Measured memory_bytes: 2304
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=2000005;
const int mod=1e9+7;
int pow_mod(int a,int b)
{
	int ret=1;
	for(;b;b>>=1,a=1LL*a*a%mod)if(b&1)ret=1LL*ret*a%mod;
	return ret;
}
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int pre[MAXN],inv[MAXN];
int C(int n,int m){return 1LL*pre[n]*inv[m]%mod*inv[n-m]%mod;}
int f(int u,int v,int x,int y){int u1=abs(x-u),u2=abs(v-y);return C(u1+u2,u1);}
int p1,p2,p3,p4,p5,p6;
int q1,q2,q3,q4,q5,q6;
int cal1(int x,int y)
{
	int ret=0;
	ad(ret,f(x,y,p1-1,q1-1));dl(ret,f(x,y,p1-1,q2));
	dl(ret,f(x,y,p2,q1-1));ad(ret,f(x,y,p2,q2));
	return ret;
}
int cal2(int x,int y)
{
	int ret=0;
	ad(ret,f(x,y,p6+1,q6+1));dl(ret,f(x,y,p5,q6+1));
	dl(ret,f(x,y,p6+1,q5));ad(ret,f(x,y,p5,q5));
	return ret;
}
int main()
{
	pre[0]=1;for(int i=1;i<MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
	inv[MAXN-1]=pow_mod(pre[MAXN-1],mod-2);
	for(int i=MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
	p1=read();p2=read();p3=read();p4=read();p5=read();p6=read();
	q1=read();q2=read();q3=read();q4=read();q5=read();q6=read();
	int ans=0;
	for(int i=p3;i<=p4;i++)
	{
		int s1=cal1(i,q3-1),s2=cal2(i,q3);
		dl(ans,1LL*s1*s2%mod*(i+q3)%mod);
		s1=cal1(i,q4),s2=cal2(i,q4+1);
		ad(ans,1LL*s1*s2%mod*(i+q4+1)%mod);
	}
	for(int i=q3;i<=q4;i++)
	{
		int s1=cal1(p3-1,i),s2=cal2(p3,i);
		dl(ans,1LL*s1*s2%mod*(i+p3)%mod);
		s1=cal1(p4,i),s2=cal2(p4+1,i);
		ad(ans,1LL*s1*s2%mod*(i+p4+1)%mod);
	}
	pr2(ans);
	return 0;
}


Measured memory_bytes: 15744
n=int(input())
x=[]
for _ in range(n):
    a,b=map(int,input().split())
    x.append([a+b,a,b])
x.sort(reverse=True)
ans=0
for i in range(n):
    if i%2==0: ans+=x[i][1]
    else: ans-=x[i][2]
print(ans)

Measured memory_bytes: 23260
//#include<stdio.h>
//#include<stdlib.h>
#include<bits/stdc++.h>
//#define Min(a,b,c) min((a),min((b),(c)))
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-11
#define MEM(x) memset(x,0,sizeof(x))
#define N 200005
#define pi 3.14159265359
using namespace std;
typedef long long LL;
int main(){
	int mod = 1e9+7;
	LL fra[100005];
	fra[0]=1;
	for(int i=1;i<1e5+5;i++)
	fra[i]=fra[i-1]*i%mod;
	int n,m;
	scanf("%d %d",&n,&m);
	if(n==m){
		printf("%lld\n",2*fra[n]%mod*fra[m]%mod);
	}
	else if(n==m+1){
		printf("%lld\n",fra[n]%mod*fra[m]%mod);
	}
	else if(n==m-1){
		printf("%lld\n",fra[n]%mod*fra[m]%mod);
	}
	else
	printf("0");
}

Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, A[111111], B[111111], c = 0;

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> A[i];
  
  for (int i = 0; i < N; i ++)
    std::cin >> B[i];

  std::vector<std::pair<int, int>> a;

  long long x = 0;

  for (int i = 0; i < N; i ++)
    if (A[i] >= B[i]) {
      a.emplace_back(A[i] - B[i], i);
    }
    else {
      x += B[i] - A[i];

      c ++;
    }

  std::sort(ALL(a), std::greater<std::pair<int, int>>());

  for (const auto& pair : a) {
    if (x <= 0)
      break;

    x -= pair.first;

    c ++;
  }

  std::cout << (x > 0 ? -1 : c) << std::endl;

  return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    double d;
    cin >> d;
    vector<double> x(n), y(n);
    int ret = 0;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        if (x[i] * x[i] + y[i] * y[i] <= d * d + 1e-8)
            ret++;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll N,W;
    cin>>N>>W;
    ll w[N],v[N];
    for(ll i=0;i<N;++i){cin>>w[i]>>v[i];}
    ll dp[N+1][W+1];
    for(ll i=0;i<N+1;++i){dp[i][0]=0;}
    for(ll i=0;i<W+1;++i){dp[0][i]=0;}
    for(ll j=1;j<W+1;++j)
    {
        for(ll i=1;i<N+1;++i)
        {
            if(j<w[i-1]){dp[i][j]=dp[i-1][j];}
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
            }
        }
    }
    cout<<dp[N][W];
}


Measured memory_bytes: 82316
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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





void printVector(VI &a){
    int n = SZ(a);
    REP(i, n){
        if(i) cout << " ";
        cout << a[i];
    }
    cout << "\n";
}

int selectionSort(VI &a){
    int n = SZ(a), ret = 0, minidx;
    REP(i, n){
        minidx = i;
        FOR(j, i, n){
            if(a[j] < a[minidx])
                minidx = j;
        }
        if(i != minidx){
            ++ret; swap(a[i], a[minidx]);
        }
    }
    return ret;
}

int main(){
    int n; cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];
    int cnt = selectionSort(a);
    printVector(a);
    cout << cnt << "\n";
    return 0;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;



signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  int mul4=0,mul2=0;
  rep(i,n){
    cin>>a[i];
    a[i]%=4;
    if(a[i]==0)mul4++;
    if(a[i]==2)mul2++;
  }
  mul2/=2;
  mul4+=mul2;
  cout<<(mul4>=n/2?"Yes":"No")<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
    #include <cstdio>
    using namespace std;
     
    int main() {
    	int a, b; cin >> a >> b;
    	if (a <= 0 && b >= 0) printf("Zero\n");
    	else if (a > 0) printf("Positive\n");
    	else{
    		if ((b - a) & 1) printf("Positive\n");
    		else printf("Negative\n");
    	}
    	return 0;
    }

Measured memory_bytes: 256
def main():
	H,W = list(map(int, input().split()))
	grid = []

	for _ in range(H):
		grid.append(list(input()))

	shift = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]

	for i in range(H):
		for j in range(W):
			if(grid[i][j] == "#"):
				continue
			
			count = 0
			for k in shift:
				ii = i + k[0]
				jj = j + k[1]

				if(-1 < ii < H and -1 < jj < W and grid[ii][jj] == "#"):
					count += 1
			
			grid[i][j] = count

	for row in grid:
		print("".join(map(str, row)))


if __name__ == "__main__":
	main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define INF 0x3f3f3f3f
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mod 1000000007
using namespace std;


int main()
{
  ll n;
  cin >> n;
  double arr[n+1];
  fr(i,0,n)cin >> arr[i+1];
  double dp[n+1][n+1];
  fr(i,0,n+1)
  {
      fr(j,0,n+1)
      {
          if(i==0&&j==0)
          {
              dp[i][j]=1;
          }
          else if(j>i)
          {
              dp[i][j]=0;
          }
          else if(j==0)
          {
              dp[i][j]=(dp[i-1][0]*(1-arr[i]));
          }
          else 
          {
              dp[i][j]=(1-arr[i])*dp[i-1][j]+arr[i]*dp[i-1][j-1];
          }
      }
  }
  double sum=0;
  fr(i,n/2+1,n+1)
  sum+=dp[n][i];
  cout << setprecision(10)<<fixed << sum << endl;
  
  return 0;
}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

long long func(long long b, long long n){
  if(n<b){
    return n;
  }
  long long res;
  res = func(b,n/b)+n%b;
  return res;
}

int main(){
  long long n,s;
  cin>>n>>s;
  long long b;
  for(long long i=2;i*i<=n;i++){
    if(func(i,n)==s){
      cout<<i<<endl;
      return 0;
    }
  }
  if(n-s<0){
    cout<<-1<<endl;
    return 0;
  }
  if(n-s==0){
    cout<<n+1<<endl;
    return 0;
  }
  long long temp;
  vector<long long> div;//(n-sの約数)+1を入れる。これらはbの候補。
  for(long long i=1;i*i<=n-s;i++){
    if((n-s)%i==0){
      if(i+1>sqrt(n)){
        div.push_back(i+1);
      }
      temp = (n-s)/i+1;
      if(temp>sqrt(n)){
        div.push_back(temp);
      }
    }
  }
  sort(div.begin(),div.end());
  REP(i,(int)div.size()){
    if(s==(n/div[i]+n%div[i])){
      cout<<div[i]<<endl;
      return 0;
    }
  }
  
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  int key;
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);

  for(i =1; i<=n;i++){
  key = A[i];
  j = i-1;
  

 while (j >=0&& A[j]>key)
    {
	  A[j+1] = A[j];
	  j--;
	  A[j+1] = key;
    }
 trace(A,n);
  }
  

  return 0;
}

Measured memory_bytes: 608
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;

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

    for(size_t i = 0; i < s.length() - 1; i++){
        if(s[i] == s[i+1]){
            cout << (i + 1) << " " << (i + 2) << endl;
            return 0;
        }
    }

    for(size_t i = 0; i < s.length() - 2; i++){
        if(s[i] == s[i+1] || s[i] == s[i+2] || s[i+1] == s[i+2]){
            cout << (i + 1) << " " << (i + 3) << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	string s[101];
	int h,n;
	cin>>h>>n;
	for(int i=0;i<h;i++) cin>>s[i];
	for(int i=0;i<h;i++){
		cout<<s[i]<<endl;
		cout<<s[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4352
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		int M = in.nextInt();
		int[][] edge = new int[N+1][N+1];
		for(int i = 0; i < M; i++){
			int a = in.nextInt();
			int b = in.nextInt();
			edge[a][b]++;
			edge[b][a]++;
		}
		
		for(int i = 1; i <= N; i++){
			int sum = 0;
			for(int j = 1; j <= N; j++) sum += edge[i][j];
			System.out.println(sum);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m, a, b;
  
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++)
    cin >> s.at(i);
  
  cin >> m;
  vector<string> t(m);
  for (int i = 0; i < m; i++)
    cin >> t.at(i);
  
  a = 0;
  for (int i = 0; i < n; i++){
    b = 0;
    for (int j = 0; j < n; j++) {
      if(s.at(i) == s.at(j))
        b++;
    }
    
    for (int j = 0; j < m; j++) {
      if(s.at(i) == t.at(j))
        b--;
    }
    if (b > a)
      a = b;
  }
  cout << a << endl;
}

Measured memory_bytes: 256