akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    A.sort(reverse=True)
    count = -1 * A[0]
    rest = N

    for n in [0,0,1,1,2,2]:
        count += A[n]
        rest -= 1
        if rest == 0:
            print(count)
            return
    k = 2
    n = 3
    while True:
        for _ in range(3):
            for _ in range(k):
                count += A[n]
                rest -= 1
                if rest == 0:
                    print(count)
                    return
            n += 1
        k ** 2

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

int main() {
  int N, K, sum;
  cin >> N >> K;

  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x < K - x) {
      sum += x * 2;
    }
    else {
      sum += (K - x) * 2;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
using System;
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    int k = int.Parse(input[3]);
    if( a >= k )
    {
      Console.WriteLine(k);
    }else if( a+b >= k )
    {
      Console.WriteLine(a);
    }else
    {
      Console.WriteLine(a*2+b-k);
    }
  }
}

Measured memory_bytes: 17900
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <vector>

int main() {
    std :: ios_base :: sync_with_stdio(false);

    int t = 1;
    //std :: cin >> t;

    while(t--) {
        uint64_t n, m;
        std :: cin >> n >> m;

        uint64_t x, y;
        uint64_t ans = 0;

        for(int i = 0 ; i < n ; i++) {
            std :: cin >> x >> y;

            if(x * x + y * y <= m * m) ans++;
        }

        std :: cout << ans << '\n';
    }
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>

int main(void){
   
   char b;
   
   scanf("%c",&b);
   
   if(b == 'A'){
      printf("T\n");
   }
   else if(b == 'T'){
      printf("A\n");
   }
   else if(b == 'C'){
      printf("G\n");
   }
   else {
      printf("C\n");
   }
   
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, k, a;
  in(n);
  vector<ll> c(n);
  rep(i, n)
    in(c[i]);
  sort(all(c));
  a = c[0];
  rep(i, n){
    a = __gcd(a, c[i]);
  }
  out(a);
  memi;
}

Measured memory_bytes: 1024
// a,bを決めてcをにぶたんする cを最長とする
// sort.Searchのせいで4時間くらいバグらせた （対処法不明
package main
import (
	"fmt"
	"sort"
)
func main(){
	var N int
	fmt.Scan(&N)
	L := make([]int, N)
	for i:=0; i<N; i++{
		fmt.Scan(&L[i])
	}
	sort.Ints(L)
	ans := 0
	for a:=0; a<N-2; a++{
		for b:=a+1; b<N-1; b++{
			// cを最長とおいたのでb以上（for的にL[b]>=L[a]なので）

			// なぜかうまくいかない 多分以下のせい どこが悪いのか不明 ジャッジかパッケージがバグってるとしか思えない_
			// c := sort.Search(N, func(j int)bool{
			// 	if L[a]+L[b] < L[j]{
			// 		return true
			// 	}
			// 	return false
			// })
			// searchIntsってのがあったので使ってみる
			c := sort.SearchInts(L, L[a]+L[b])
			if c > b{
				ans += (c-1-b)
			}
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 2044
n = int(input())
t, a = map(int, input().split())
i = 0
nums = [0, 10**6]

for h in list(map(int, input().split())):
    i += 1
    if abs(a - (t-h*0.006)) < abs(a - (t - nums[1]*0.006)):
        nums = [i, h]

print(nums[0])

Measured memory_bytes: 3060
#include<stdio.h>
 int main(void)
 {
     int N,A[101];
     int i,j,tmp;

     scanf("%d",&N);

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

     for(i=0;i<N;i++){
       for(j=i+1;j<N;j++){
         if(A[i]>A[j]){
           tmp=A[i];
           A[i]=A[j];
           A[j]=tmp;
         }
       }
     }

     printf("%d\n",A[N-1]-A[0]);

     return 0;
 }


Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

//平均値に書き換える！

 int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    double ave = 0;
    FOR(i, 0, N){
        cin >> A[i];
        ave += A[i];
    }
    ave /= N;
    ll cost = 0;
    FOR(i, 0, N){
        cost += pow(abs(int(round(ave))-A[i]),2);
    }
    cout << cost << endl;
 }

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }

ll cnt(ll h, ll w) {}

ll factorial[200001];
ll finverse[100001];

int main() {
  //
  factorial[0] = 1;
  finverse[0] = 1;
  factorial[1] = 1;
  finverse[1] = 1;
  REP(i, 2, 200001) { factorial[i] = i * factorial[i - 1] % MOD; }
  REP(i, 2, 100001) { finverse[i] = finverse[i - 1] * modinv(i, MOD) % MOD; }

  ll h, w, a, b;
  cin >> h >> w >> a >> b;
  ll ans = 0;
  REP(j, b, w) {
    // cout << h - a - 1 + j << "C" << j << endl;
    ll comb1 = factorial[(h - a - 1) + j] * finverse[j] % MOD *
               finverse[(h - a - 1)] % MOD;
    // cout << a - 1 + w - j - 1 << "C" << b - 1 << endl;
    ll comb2 = factorial[(a - 1) + (w - j - 1)] * finverse[a - 1] % MOD *
               finverse[w - j - 1] % MOD;
    ans = (ans + comb1 * comb2 % MOD) % MOD;
    // cout << comb1 << "," << comb2 << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	int num,a;
	cin>>num;
	vector<int> v(101,0);
	for (int i = 0; i < num; i++) {
		cin >> a;
		v[a]++;
	}
	num = 0;
	for (int j = 1; j <= 100; j++) {
		if (v[j] >0)
			num++;
	}
	cout<<num;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 20:57:27 2019

@author: Yamazaki Kenichi
"""

N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = 0
for i in range(N):
    ans += V[i] - C[i] if V[i] > C[i] else 0
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  ll n;
  cin >> n;
  ll arr[n];
  for(ll i=0;i<n;i++)
    cin >> arr[i];
  sort(arr,arr+n,greater<ll>());
  ll i=0;
  ll a1=-1,a2=-1;
  while(i<n){
    if(arr[i]==arr[i+1]){
      if(a1==-1){
        a1=arr[i];
        i+=2;
      }
      else if(a1!=-1){
        a2=arr[i];
        i+=2;
        break;
      }
    }
    else{
      i++;
    }
  }
  if(a1!=-1 && a2!=-1){
    ll ans = a1*a2;
    cout << ans << endl;
  }
  else{
    cout << "0" << endl;
  }
  return 0;
}


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

int prime(long long x) {
  for (long long i = 2; i * i <= x; ++i)
    if (x % i == 0)
      return 0;
  return 1;
}

int main() {
  long long a, b;
  scanf("%lld %lld", &a, &b);
  a = __gcd(a, b);
  int ans = 0;
  for (long long i = 1; i * i <= a; ++i) {
    if (a % i == 0) {
      ans += prime(i);
      if (i != a / i)
        ans += prime(a / i);
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main()
{
	int n;
	int a[1000];
	int cnt=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==1 && i%2==1)
		{
			cnt++;
		}
	}
	printf("%d\n",cnt);
		
	return 0;
}

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

#define ll       long long
#define ull      unsigned ll
#define pii      pair<int, int>
#define pll      pair<ll, ll>
#define mp       make_pair
#define ff       first
#define ss       second
#define sz(x)    (int) x.size()
#define all(v)   v.begin(), v.end()

template <typename T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <typename T> inline void smax(T &a, T b) {a = a > b ? a : b;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}

template <typename T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l); }

const int mod = (int) 1e9 + 7;

inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll) a * b % mod;}

const int inf = (int) 2e9 + 5;
const ll  Inf = (ll) 2e18 + 5;
const int N   = (int) 2e5 + 5;



int solve() {
    string s; cin >> s; if(s == "ABC") printf("ARC\n"); else printf("ABC\n");
    return 0;
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int test = 1, tc = 0;
    //Int(test);
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
    return 0;
}


Measured memory_bytes: 3576
import java.util.*;

public class Main{
    static final int INF = (int)1e9;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        Work[] x = new Work[n];
        for(int i=0; i<n; i++){
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            x[i] = new Work(a,b);
        }
        
        Arrays.sort(x);
        
        boolean ans = true;
        long time = 0;
        for(Work w : x){
            time += w.a;
            if(time > w.b){
                ans = false;
                break;
            }
        }
        
        System.out.println(ans? "Yes" : "No");
    }
}

class Work implements Comparable<Work>{
    int a;
    int b;
    public Work(int a, int b){
        this.a = a;
        this.b = b;
    }
    
    @Override
    public int compareTo(Work o) {
        return this.b - o.b;
    }
}

Measured memory_bytes: 70004
import java.util.*;
import java.math.*;

class Main{       
   public static void main(String[] args){

      Scanner sc = new Scanner(System.in);  
      
      String s = sc.next();
      
      for(int i = 0;i < s.length();i+=2){
          System.out.print(s.charAt(i));
      }
      
      System.out.println();
      
   }
}
        

Measured memory_bytes: 29216
/*SorooshH*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> tpi;
typedef pair<pii,pii> qpi;
const int MAX = 1e6;
const int MV = 1e5;
const int INF = 2e9;
const int MOD = 1e9 + 7;
int MA = -INF , MI = INF , ANS;

int r , c , d , q;
int arr[400][400];
pii coo[MAX+10];
ll dp[400][400];
int s , f;
pii s1 , f1;

int32_t main()
{
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> r >> c >> d;

    for(int i=1 ; i<=r ; i++)
    {
        for(int j=1 ; j<=c ; j++)
            cin >> arr[i][j] , coo[ arr[i][j] ] = {i,j};
    }

    for(int i=r*c ; i>=1 ; i--)
    {
        if( i+d <= r*c )
            dp[ coo[i].F ][ coo[i].S ] = dp[ coo[i+d].F ][ coo[i+d].S ] + abs( coo[i].F - coo[i+d].F ) + abs( coo[i].S - coo[i+d].S );
    }

    cin >> q;

    while(q--)
    {
        cin >> s >> f;
        cout << dp[ coo[s].F ][ coo[s].S ] - dp[ coo[f].F ][ coo[f].S ] << "\n";
    }

    return 0;
}


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

const long MOD=998244353;
const long INF=100000000000000000;
int main(){
    long N;
    cin>>N;
    vector<long> A(N);
    for(int i=0;i<N;i++) cin>>A.at(i);
    
    sort(A.rbegin(),A.rend());
    
    long prevalue=-1,first=0,second=0;
    for(int i=0;i<N;i++){
        if(prevalue==A.at(i)){
            prevalue=A.at(i);
            if(first<1){
                first=A.at(i);
                prevalue=-1;
            }
            else if(second<1){
                second=A.at(i);
                prevalue=-1;
            }
        }else{
            prevalue=A.at(i);
        }
    }
    
    cout<<first*second<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#define LIM 8

using namespace std;

int n,m,p;
int board[LIM][LIM][LIM];
int height[LIM][LIM];

int dr[] = {0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0};
int dc[] = {1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1,0};
int dh[] = {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,1};

bool check_seq() {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			for (int k = 0; k < height[i][j]; ++k) {
				int color = board[i][j][k];
				for (int d = 0; d < sizeof(dr)/sizeof(int); ++d) {
					int len = 1;
					bool seq = true;
					int pr = i;
					int pc = j;
					int ph = k;
					while (seq) {
						int nr = pr + dr[d];
						int nc = pc + dc[d];
						int nh = ph + dh[d];
						int nmin = min(min(nr,nc),nh);
						int nmax = max(max(nr,nc),nh);
						if (nmin >= 0 && nmax < n) {
							if (board[nr][nc][nh] != color) {
								seq = false;
							}
							else {
								++len;
								pr = nr;
								pc = nc;
								ph = nh;
								if (len == m) {
									return true;
								}
							}
						}
						else {
							seq = false;
						}

					}
				}
			}
		}
	}
	return false;
}

int main(void) {
	while (cin >> n >> m >> p, n) {
		int res = 0;
		for (int i = 0; i < LIM; ++i) {
			for (int j = 0; j < LIM; ++j) {
				height[i][j] = 0;
				for (int k = 0; k < LIM; ++k) {
					board[i][j][k] = -1;
				}
			}
		}
		for (int i = 0; i < p; ++i) {
			int row,col;
			cin >> row >> col;
			board[row-1][col-1][height[row-1][col-1]] = i%2;
			++height[row-1][col-1];
			if (i+2 >= 2*m && res == 0) {
				if (check_seq()) {
					res = i+1;
				}
			}
		}

		if (res == 0) {
			cout << "Draw" << endl;
		}
		else {
			if (res%2 == 1) {
				cout << "Black ";
			}
			else {
				cout << "White ";
			}
			cout << res << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3016
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

void solve()
{
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		uf.merge(a,b);
	}
	ll ans=0;
	rep(i,n){
		ans=max(ans,uf.size(i));
	}
	cout<<ans<<endl;

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 6344
import sys
sys.setrecursionlimit(10**6)

def rec(i):
    if dp[i] < INF:
        return dp[i]
    if i == 0:
        return 0
    dp[i] = min(dp[i], rec(i-1) + abs(h[i] - h[i - 1]))
    if i > 1:
        dp[i] = min(dp[i], rec(i-2) + abs(h[i] - h[i - 2]))
    return dp[i]


INF = float('inf')
dp = [INF] * (10 ** 5 + 10)
h = [0] * (10 ** 4 + 10)

N = int(input())
h = list(map(int, input().split())) + h

print(rec(N-1))


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

int main() {

        string S, T;
        cin >> S >> T;

        int n = T.size();
        char T1 = T.at(n-1);
        //N = T.size();
        //T = T.at(N);

        S += T1;

//      cout << S << endl;      

        if (T == S) {
                cout << "Yes" << endl;
        }

        else {
                cout << "No" << endl;
        }

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

struct unionfind {
	vector<int> par, siz;
	unionfind(int N) : par(N), siz(N,1) {
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int root(int x) {
		while(par[x] != x) x = par[x] = par[par[x]];
		return x;
	}
	void unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int size(int x) {
		return siz[root(x)];
	}
};

int main(){
	int n, m; cin >> n >> m;
	unionfind uf(n);
	int a, b;
	REP(i,m){
		cin >> a >> b;
		a--; b--;
		uf.unite(a,b);
	}
	int ans=1;
	REP(i,n){
		ans=max(ans,uf.size(i));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4836
import sys
from collections import deque
readline = sys.stdin.readline

N = int(readline())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    s,t = map(lambda x:int(x)-1, readline().split())
    edges[s].append(t)
    edges[t].append(s)

def bfs(edges, s)->list:
    V = len(edges)
    dist = [float('inf')]*V
    visited = [False]*V
    dist[s] = 0
    visited[s] = True
    q = deque([s])
    while q:
        cur = q.popleft()
        for nex in edges[cur]:
            if visited[nex]:
                continue
            q.append(nex)
            visited[nex] = True
            dist[nex] = dist[cur] + 1
    return dist

dist1 = bfs(edges, 0)
dist2 = bfs(edges, N-1)
score1 = 0
for d1,d2 in zip(dist1, dist2):
    if d1 <= d2:
        score1 += 1
# print(score1)
print("Fennec" if score1 > N/2 else "Snuke")


Measured memory_bytes: 30088
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		for (int i = (s.length() - 1) / 2; i > 0; i--) {
			if (s.substring(0, i).equals(s.substring(i, i * 2))) {
				System.out.println(i * 2);
				return;
			}
		}
	}
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = a * b;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC80(void);
void ABC81(void);
void ABC82(void);
void ABC83(void);
void ABC84(void);
void ABC85(void);
void ABC86(void);
void ABC87(void);
void ABC88(void);
void ABC89(void);

int main(void){
    ABC85();
}

void ABC85(){
    int n,i,ans,r;
    cin>>n;
    vector<int> vec(n);
    for(i=0;i<n;i++){
        cin>>vec[i];
    }
    sort(vec.begin(),vec.end());
    r=vec[0];
    ans=1;
    for(i=1;i<n;i++){
        if(vec[i]!=r){
            ans++;
            r=vec[i];
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int x[100010], y[100010], c[100010], d[200010];
vector<PII> g[200010];
bool used[200010];

void dfs(int num) {
  used[num] = true;
  for(auto i: g[num]) {
    if(used[i.first]) continue;
    d[i.first] = i.second - d[num];
    dfs(i.first);
  }
}

int mi1, mi2;
int R, C;
void dfs2(int num) {
  used[num] = true;
  for(auto i: g[num]) {
    if(used[i.first]) continue;
    if(i.first < R) chmin(mi1, d[i.first]);
    else chmin(mi2, d[i.first]);
    dfs2(i.first);
  }
}

signed main(void)
{
  cin >> R >> C;
  int n;
  cin >> n;
  REP(i, n) {
    cin >> y[i] >> x[i] >> c[i];
    x[i]--, y[i]--;
    g[x[i]+R].PB({y[i], c[i]});
    g[y[i]].PB({x[i]+R, c[i]});
  }

  REP(i, R+C) {
    if(!used[i]) {
      dfs(i);
    }
  }

  bool flag = true;
  REP(i, n) {
    if(d[x[i]+R] + d[y[i]] != c[i]) {
      flag = false;
      break;
    }
  }
  if(!flag) {
    cout << "No" << endl;
    return 0;
  }

  // REP(i, R+C) cout << d[i] << " "; cout << endl;

  // cout << INF + INF << endl;

  memset(used, false, sizeof(used));
  REP(i, R+C) {
    if(!used[i]) {
      mi1 = INF, mi2 = INF;
      if(i < R) mi1 = d[i];
      else mi2 = d[i];
      d[i] = 0;
      dfs2(i);
      // cout << i << " " << mi1 << " " << mi2 << endl;
      if(mi1 + mi2 < 0) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 17408
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        ll n = N / i;
        ans += i * n * (n+1) / 2; 
    }
    cout << ans << endl;  
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define pb push_back
#define N 1000500
typedef long long int ll;
using namespace std;
int main(void){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	fast;
	int i;
	string s;
	cin>>s;
	int n=s.length();
	ll dp[n+1][2];
	memset(dp,0,sizeof dp);
	//dp[1][0]=s[0]-'0';
	//dp[1][1]=10-(s[0]-'0');
	dp[0][1]=1;
	for(i=0;i<n;i++){
		int k=s[i]-'0';
		dp[i+1][0]=min(dp[i][0]+k,dp[i][1]+10-k);
		dp[i+1][1]=min(dp[i][0]+k+1,dp[i][1]+10-k-1);
	}
	cout<<dp[n][0]<<endl;
}

Measured memory_bytes: 19832
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

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


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}
// 立っている ビットの数
int bitcount(unsigned int uc);
int bitcount(unsigned int uc)
{
	int bit;

	for (bit = 0; 0 != uc; uc = (unsigned int)(uc >> 1))
		if (0 != (uc & 1))++bit;

	return bit;
}//bitco

#define _rnd(a,b)    ((a+b-1)/b) //　A/Bの余りを繰り上げる

#pragma endregion

// ABC081 B- Shift only
int main(void) {
	int n, a[201];
	int i, cnt = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 2) {
			printf("%d\n", cnt); return 0;
		}
		a[i] /= 2;
	}
	cnt++;
	while (1) {
		for (i = 0; i < n; i++) {
			if (a[i] % 2) { printf("%d\n", cnt); return 0; }
			a[i] /= 2;
		}
	cnt++;
    }

	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 1732
N, M = map(int, input().split())
g = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

ans = 0
def walk(cur, visited):
    global ans
    tmp = visited + [cur]
    if len(tmp) == N:
        ans += 1
    for nex in g[cur]:
        if nex not in tmp:
            walk(nex, tmp)
walk(1, [])
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
  double w,h,x,y; auto dmy=scanf("%lf %lf %lf %lf", &w, &h, &x, &y);
  printf("%lf", w*h/2.0);
  double sigma = 1e-9;
  if(abs(w-2*x) < sigma && abs(h-2*y) < sigma){
    printf(" 1");
  }else{
    printf(" 0");
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi h(n);
    rep(i, n) cin >> h[i];
    for (int i = n-1; i >= 0; --i) {
        h[i] = h[i] - h[i-1];
    }
    int ans = 0;
    rep(i, n) {
        if (h[i] > 0) ans += h[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;

ll n,m,ar[N],sum,t,pw[N];


int main()
{
	fast;
	cin>>n>>m;
	fs(ar,n);
	ll a=0,b=0;
	fo(i,1,n)
		if(ar[i]%2==1)
			a++;
		else
			b++;
	pw[0]=1;
	fo(i,1,50)
		pw[i]=pw[i-1]*2;
	sum=pw[b];
	if(a==0 && m==1)
		return cout<<0,0;
	sum=sum* max(pw[a]/2,1ll);
	cout<<sum;
}



Measured memory_bytes: 3612
/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl;
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl;
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl;
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl;
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl;
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 200010;

ll ar[maxn];

void MAIN() {

    ll n;
    cin >> n;
    ll mn = maxn, cnt = 0;
    fori (i, n) {
        ll x; cin >> x;
        smin(mn, x);
        if (mn >= x) {
            ++cnt;
        }
    }
    cout << cnt << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(

    )";
    MAIN();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18 + 18
ll n;
ll zero = 0, pos = 0, neg = 0;
vector<ll> a;
ll solve_pos(ll rnk) {
	vector<ll> vp (a.begin() + n - pos, a.end());
	vector<ll> vn (a.begin(), a.begin() + neg);
	reverse(vn.begin(), vn.end());
	ll big = INF;
	ll small = 1;
	while (small <= big) {
		ll mid = small + (big - small) / 2;
		ll cnt = 0;
		for (int i = pos - 1, j = 0; i >= 0; i--) {
			for (; j < i && vp[i] * vp[j] <= mid; j++) {}
			cnt += min(i, j);
		}
		for (int i = neg - 1, j = 0; i >= 0; i--) {
			for (; j < i && vn[i] * vn[j] <= mid; j++) {}
			cnt += min(i, j);
		}
		if (cnt < rnk)
			small = mid + 1;
		else big = mid - 1;
	}
	return small;
}
ll solve_neg(ll rnk) {
	vector<ll> vp (a.begin() + n - pos, a.end());
	reverse(vp.begin(), vp.end());
	vector<ll> vn (a.begin(), a.begin() + neg);
	reverse(vn.begin(), vn.end());
	ll big = -1;
	ll small = -INF;
	while (small <= big) {
		ll mid = small + (big - small) / 2;
		ll cnt = 0;
		for (int i = 0, j = 0; i < neg; i++) {
			for (; j < pos && vn[i] * vp[j] <= mid; j++) {}
			cnt += j;
		}
		if (cnt < rnk)
			small = mid + 1;
		else big = mid - 1;
	}
	return small;
}
int main() {
	ll k;
	cin >> n >> k;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (!a[i]) zero++;
		else if (a[i] > 0) pos++;
		else neg++;
	}
	sort(a.begin(), a.end());
	ll cnt_neg = pos * neg;
	ll cnt_zero = (zero - 1) * zero / 2 + zero * (n - zero);
	ll cnt_pos = (pos - 1) * pos / 2 + (neg - 1) * neg / 2;
	ll ans;
	if (k <= cnt_neg)
		ans = solve_neg(k);
	else if (k <= cnt_neg + cnt_zero)
		ans = 0;
	else
		ans = solve_pos(k - cnt_neg - cnt_zero);
	cout << ans << "\n";
	return 0;
}

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

int main() {
  int N, a = 1, b = 0, c;
  cin >> N;
  vector<int> vec(N + 1);
  for (int i = 1; i <= N; i++)
    cin >> vec.at(i);
  while (true){
    if (vec.at(a) == 0){
      cout << -1 << endl;
      break;
    }
    if (vec.at(a) == 2){
      b++;
      cout << b << endl;
      break;
    }
    b++;
    c = a;
    a = vec.at(a);
    vec.at(c) = 0;
  }
}

Measured memory_bytes: 3768
#include <iostream>
#include <cstdint>
#include <algorithm>

using i64 = std::int64_t;

int main() {
	i64 a, b, k;
	std::cin >> a >> b >> k;

	std::cout << std::max<i64>(a - k, 0) << " " << std::max<i64>((k > a ? b - (k - a) : b), 0) << std::endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 10000


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

  for(i=0;i<n;i++){
    //偶数か
    if(num[i]==2) {
      cnt++;
      continue;
    }
    if(num[i]%2 == 0) continue;
    for(j=3;j*j<=num[i];j+=2){
      if(num[i]%j == 0) break;
    }
    if(j*j>num[i]) cnt++;
  }
  
  printf("%d\n",cnt);

  return 0;
}



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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;


int main() {
  string s; cin >> s;
  set<char> az {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  set<char> st;
  rep(i, s.size()) {
    st.insert(s[i]);
  }
  
  char ans;
  for (auto x: az) {
    auto itr = st.find(x);
    if (itr == st.end()) {
      dump(x);
      return 0;
    }
  }

  dump("None");  
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;


int main(int argc, char *argv[])
{
	ll K, X, Y;
	vector<pair<ll, ll>> p;

	cin >> K >> X >> Y;

	bool xflag = false;
	bool yflag = false;
	bool xyswap = false;

	if (X < 0) {
		X = -X;
		xflag = true;
	}
	if (Y < 0) {
		Y = -Y;
		yflag = true;
	}
	if(X < Y) {
		swap(X, Y);
		xyswap = true;
	}

	if ((X + Y) % 2 == 1 && K % 2 == 0) {
		cout << -1 << endl;
		return 0;
	}

	if (X + Y == K) {
		cout << 1 << endl;
		if (xyswap) {
			swap(X, Y);
		}
		if (xflag) {
			X = -X;
		}
		if (yflag) {
			Y = -Y;
		}
		printf("%lld %lld\n", X, Y);
		return 0;
	}

	int n = (X + Y + K - 1) / K;
	if (n <= 1) {
		n = 2;
	}
	if ((X + Y) % 2 != n * K % 2) {
		n++;
	}

	if (n == 3 && X < K) {
		ll c = (K - X + Y) / 2;
		p.push_back(make_pair(X, -K + X));
		p.push_back(make_pair(X + (K + X - Y) / 2, -K + X + c));
		p.push_back(make_pair(X, Y));
	} else {
		ll over = ((n * K) - X - Y) / 2;
		for (int i = 0; i < n; i++) {
			ll dist = (i + 1) * K;
			if (dist <= Y + over) {
				p.push_back(make_pair(0, dist));
			} else if (dist <= Y + over + X) {
				p.push_back(make_pair(dist - Y - over, Y + over));
			} else {
				p.push_back(make_pair(X, Y + (n - (i + 1)) * K));
			}
		}
	}

	if(xyswap) {
		for (int i = 0; i < p.size(); i++) {
			ll t = p[i].first;
			p[i].first = p[i].second;
			p[i].second = t;
		}
	}

	if (xflag) {
		for (int i = 0; i < p.size(); i++) {
			p[i].first = -p[i].first;
		}
	}
	if (yflag) {
		for (int i = 0; i < p.size(); i++) {
			p[i].second = -p[i].second;
		}
	}

	cout << p.size() << endl;
	for (int i = 0; i < p.size(); i++) {
		printf("%lld %lld\n", p[i].first, p[i].second);
	}

	return 0;
}


Measured memory_bytes: 6384
class Priority_queue
  def initialize(bool = true)
    if bool
      @ope = proc{|a, b|(a and b)? a > b : false}
    else
      @ope = proc{|a, b|(a and b)? a < b : false}
    end
    @heap = []
  end

  def <<(other)
    @heap.push(other)
    up
  end

  def gets
    result = @heap.shift
    @heap.unshift(@heap.pop)
    down
    return result
  end
  
  def up(key = @heap.size - 1)
    if @ope.call(@heap[key / 2], @heap[key])
      @heap[key / 2], @heap[key] = @heap[key], @heap[key / 2]
      down(key / 2)
      up(key / 2)
    end
  end

  def down(key = 0)
    if @ope.call(@heap[key], @heap[key * 2]) and @ope.call(@heap[key * 2 + 1], @heap[key * 2])
      @heap[key], @heap[key * 2] = @heap[key * 2], @heap[key]
      down(key * 2)
    elsif @ope.call(@heap[key], @heap[key * 2 + 1])
      @heap[key], @heap[key * 2 + 1] = @heap[key * 2 + 1], @heap[key]
      down(key * 2 + 1)
    end
  end
  def inspect
    @heap
  end
  
end
class Edge
  include Comparable
  attr_reader :cost
  def initialize(a, b, cost)
    @a, @b = a, b
    @cost = cost
  end
  def self.set(n)
    @@array = Array.new(n, false)
  end
  def self.reach(n)
    @@array[n] = true
  end
  def <=>(other)
    @cost <=> other.cost
  end
  def reach?
    @@array[@a] and @@array[@b]
  end
  def to
    return @b
  end
  def inspect
    "|#{@a}<#{@cost}>#{@b}|"
  end
end

def main
  n = gets.to_i
  Edge::set(n)
  matrix = []
  n.times do
    matrix << gets.split(" ").map(&:to_i)
  end
  counter = 0
  position = 0
  queue = Priority_queue.new
  cost = 0
  while counter < n
    Edge::reach(position)
    matrix[position].each_with_index{|item, idx|
      queue << Edge.new(position, idx, item) if item != -1
    }
    minimum = queue.gets
    while minimum and minimum.reach?
      minimum = queue.gets
    end
    cost += minimum.cost if minimum
    position = minimum.to if minimum
    counter += 1
  end
  puts cost
end

main

Measured memory_bytes: 6216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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 GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) { return (a * b) / GCD(a, b);}

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

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

int ans[1000][1000];

int n, m, a, b;

int cmp(pair<int, int> A, pair<int, int> B){
	return A.second > B.second;
}

void test(int _a, int _b){ // add of per row, add of per column
	vector<pair<int, int>> A;
	for(int i = 0; i < m; i++){
		A.push_back({i, (i < _b) * abs(n - b * 2) + min(b, n - b)});
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			ans[i][j] = 0;
		}
	}
	for(int i = 0; i < n; i++){
		int le = (i < _a) * abs(m - a * 2) + min(a, m - a);
		sort(A.begin(), A.end(), cmp);
		for(int j = 0; j < le; j++){
			ans[i][A[j].first] = 1;
			A[j].second--; 
		}
	}
	bool OK = 1;
	for(int i = 0; i < m; i++){
		if(A[i].second != 0){
			OK = 0;
		}
	}
	if(!OK){
		return;
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cout << ans[i][j];
		}
		cout << endl;
	}
	exit(0);
}

int main(){
	cin >> n >> m >> a >> b;
	int x1 = a, x2 = m - a;
	int y1 = b, y2 = n - b;
	if(x2 < x1) swap(x1, x2);
	if(y2 < y1) swap(y1, y2);
	unordered_map<int, int> M;
	for(int i = 0; i <= n; i++){
		M[x1 * n + (x2 - x1) * i] = i;
	}
	for(int i = 0; i <= m; i++){
		if(M.find(y1 * m + (y2 - y1) * i) != M.end()){
			test(M[y1 * m + (y2 - y1) * i], i);
		}
	}
	cout << -1;
}

Measured memory_bytes: 5248
open Batteries

module IntSet = Set.Make (struct
  let compare = Pervasives.compare

  type t = int
end)

let read_two () = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a, b))

let read_three () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c -> (a, b, c))

let read_four () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c d -> (a, b, c, d))

let read_list () =
  read_line () |> String.split_on_char ' '
  |> List.map (fun s -> int_of_string s)

let rec read_list_nl n =
  if n = 0 then [] else (read_line () |> int_of_string) :: read_list_nl (n - 1)

(* a**x *)
let pow a x =
  let rec aux acc = function 0 -> acc | n -> aux (acc * a) (n - 1) in
  aux 1 x

let rec pow2 n = if n mod 2 = 0 then 1 + pow2 (n / 2) else 0

let rec f d a n = if n > d then 0 else 1 + f d a (n + a)

let rec total acc = function [] -> acc | x :: rest -> total (acc + x) rest

let () =
  let n = read_int () in
  let d, x = read_two () in
  let a = read_list_nl n in
  let c = List.map (fun x -> f d x 1) a in
  let ans = total 0 c + x in
  print_int ans;
  print_newline ()


Measured memory_bytes: 1024
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n;
int d[] = {3, 5, 7};
int main(){
    cin >> n;
    int ans = 0;
    for(int i = 3;i <= 10;i++){
        if(d_cnt(n) < i)continue;
        for(int j = 0;j < pow(3, i);j++){
            bool flg[3] = {};
            LL num = 0;
            LL mem = j;
            REP(k, i){
                num *= 10;
                num += d[mem%3];
                flg[mem%3] = true;
                mem /= 3;
            }
            if(!(flg[0] && flg[1] && flg[2]))continue;
            if(num <= n)ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <algorithm>
#include <deque>
#include <vector>
using namespace std;

int road[1000001][3];
int main() {
	int N,M,K;
	vector<pair<int,int> >nGo[3001];
	deque<int> dis;
	int dist[3001];
	int signer[3001]={};
	for(int i=1;i<=3000;i++)
		dist[i]=(1 << 30 );
	cin >> N >> M >> K;
	int a,b,c;
	for(int i=0;i<M;i++){
		cin >> a >> b >> c;
		nGo[a].push_back(pair<int,int>(b,c));
		nGo[b].push_back(pair<int,int>(a,c));
		road[i][0]=a;
		road[i][1]=b;
		road[i][2]=c;
	}
	for(int i=0;i<K;i++){
		cin >> a;
	//	dis.insert(multimap<int,int>::value_type(0,a));
		dis.push_back(a);
		dist[a]=0;
	}
	while(!dis.empty()){
		int miner=0;
		for(int i=0;i<dis.size();i++)
		miner=(dist[dis[miner]]<dist[dis[i]]) ? miner:i;
		int r=dis[miner];
		dis[miner]=dis[0];
		dis[0]=r;
		int now=dis[0];
		for(int i=0;i<nGo[now].size();i++){
			if(dist[nGo[now][i].first]>dist[now]+nGo[now][i].second){
				if(signer[nGo[now][i].first]==0){
				dis.push_back(nGo[now][i].first);
				signer[nGo[now][i].first]=1;
				}
				dist[nGo[now][i].first]=dist[now]+nGo[now][i].second;
			}
		}
		dis.pop_front();
	}
	int maxer=0;
	for(int i=0;i<M;i++)
	maxer=max(maxer,(dist[road[i][0]]+dist[road[i][1]]+road[i][2]+1)/2);
	for(int i=1;i<=N;i++)
	maxer=max(maxer,dist[i]);
	cout << maxer <<  endl;
	return 0;
}

Measured memory_bytes: 5368