akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n) 
{ v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i]; }
template<class T, class U> void read_n(vector<pair<T, U>>& v, size_t n)
{ v = vector<pair<T, U>>(n); 
  for (lli i=0; i<n; ++i) cin >> v[i].first >> v[i].second; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const lli SIZE = 100000;
lli k, n;
vector<lli> m, s;
int main() {
  cin >> n >> k;
  vector<bool> b(n, false);
  vector<vector<lli>> a;
  init_n(a, n+1);
  for (lli i=0; i<n; ++i) {
    lli t, d;
    cin >> t >> d;
    a[t].push_back(d);
  }
  for (lli i=0; i<n+1; ++i) {
    if (!a[i].empty()) {
      sort(begin(a[i]), end(a[i]));
      m.push_back(a[i].back());
      a[i].pop_back();
      for (lli j=0; j<a[i].size(); ++j) s.push_back(a[i][j]);
    }
  }
  sort(begin(m), end(m), greater<lli>());
  sort(begin(s), end(s), greater<lli>());
  m[0]++;
  for (lli i=1; i<m.size(); ++i) { m[i] += m[i-1] + 2*(i+1) - 1;}
  for (lli i=1; i<s.size(); ++i) s[i] += s[i-1];
  m.insert(begin(m), 0);
  s.insert(begin(s), 0);
  lli ans = 0;
  for (lli i=0; i<=k; ++i) {
    lli j = k-i;
    if (i>=m.size()) break;
    if (j>=s.size()) continue;
    ans = max(ans, m[i]+s[j]);
  }
  cout << ans << endl;
  return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<string> blue(N);
    for (int i = 0; i < N; i++) {
        cin >> blue.at(i);
    }
    int M;
    cin >> M;
    vector<string> red(M);
    for (int i = 0; i < M; i++) {
        cin >> red.at(i);
    }
    int max = 0;
    for (int i = 0; i < N; i++) {
        int count = 0;
        for (int j = 0; j < N; j++) {
            if (blue.at(i) == blue.at(j)) {
                count++;
            }
        }
        for (int j = 0; j < M; j++) {
            if (blue.at(i) == red.at(j)) {
                count--;
            }
        }
        if (max < count) {
            max = count;
        }
    }
    cout << max;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

struct mint
{
	ll x;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a)
	{
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a)
	{
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a)
	{
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const
	{
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const
	{
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const
	{
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const
	{
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const
	{
		return pow(mod - 2);
	}
	mint& operator/=(const mint a)
	{
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const
	{
		mint res(*this);
		return res /= a;
	}
};
ostream& operator<<(ostream& os, const mint& a)
{
	os << a.x;
	return os;
}

int main()
{
	ll n, k;
	cin >> n >> k;

	mint minv;
	for (ll i = 0; i <= k; i++) minv += i;
	mint maxv;
	for (ll i = n + 1; n + 1 - k < i; i--) maxv += i;
	mint ans = maxv - minv + 1;

	for (ll i = k + 1; i <= n + 1; i++) {
		minv += i;
		maxv += n + 2 - i;
		ans += maxv - minv + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;

class Cube{
public:
  int f[6]; //??????????????°???
  Cube(){} //?????????????????????
  void roll_z(){ roll(1, 2, 4, 3);} //????????????????????§??????????????????????????°???????????¨????????????
  void roll_y(){ roll(0, 2, 5, 3);}
  void roll_x(){ roll(0, 1, 5, 4);}
  void roll(int i, int j, int k, int l){
    int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
  }
};

bool eq( Cube c1, Cube c2){
  for ( int i = 0; i < 6; i++)
    if ( c1.f[i] != c2.f[i] ) return false;
  return true;
}

bool equal( Cube c1, Cube c2){
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 4; j++) {
        if (eq(c1, c2)) return true;
        c1.roll_z();
      }
      if (i % 2 == 0) c1.roll_y();
      else c1.roll_x();
    }
    return false;
  }

int n; Cube C[100];

bool check(){
  for (int i = 0; i < n-1; i++){
    for (int j = i+1; j < n; j++){ if ( (equal(C[i], C[j])) ) return false;}
  }
  return true;
}

    //???????????????????????????????????¢??°????????£??????????????????????????????

//???????????´??°?????\?????????????????????????????????

int main(){
  cin >> n;

  for (int i = 0; i < n; i++)
    for (int j = 0; j < 6; j++) cin >> C[i].f[j];

    if (check()) cout << "Yes" << endl;
    else cout << "No" << endl;

return 0;
}

Measured memory_bytes: 3096
import java.io.*;
import java.util.*;


public class Main {
    static long mod = 1000000000+7;
    static long n,a,b,k;
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ");
        n = sc.nextInt();
        int k = sc.nextInt();
        char[] s = sc.next().toCharArray();
        s[k-1] =(char)( s[k-1]-('A'-'a'));
        System.out.println(new String(s));
    }
}



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

const int N = 75, K = 75;
const long long mod = 1000000007ll;

int n, m, stk[N], suf[K], pos[N], tmp[N], top = 0;
char str[K];
long long c[N * 5][N * 5], ans = 0ll;

long long solve () {
	queue<int> que;
	for (int i = 0; i < m; i++) suf[i] = 1;
	for (int i = 0, j = top - 1; i < m && j >= 0; i++) {
		if (str[i] == 'r') que.push(i);
		if (stk[j] && str[i] == 'b' && !que.empty()) {
			suf[que.front()] = suf[i] = 0;
			que.pop();
			pos[j--] = i;
		}
		while (j >= 0 && !stk[j] && !que.empty()) {
			suf[que.front()] = 0, que.pop();
			pos[j--] = i;
		}
		if (i == m - 1 && j >= 0) return 0ll;
	}

	suf[m] = 0;
	for (int i = m - 1; i >= 0; i--) suf[i] += suf[i + 1];
	for (int i = 0, j = 0; i < top; i++) {
		if (stk[i]) {
			j += stk[i] - 1;
			if (suf[pos[i]] < j) return 0ll;
		}
	}

	long long res = 1ll;
	for (int i = 0; i <= n; i++) tmp[i] = 0;
	for (int i = 0; i < top; i++) tmp[stk[i]]++;
	for (int i = 0, j = 0; i <= n; i++) {
		j += tmp[i];
		res = res * c[j][tmp[i]] % mod;
	}

	int num1 = 0, num2 = 0;
	for (int i = 0; i < top; i++) {
		if (stk[i]) num1 += 2 * stk[i] - 1, num2 += 2;
		else num1++;
	}
	if (top) num1 += top - 1, num2 += 2;
	else num1++;
	res = res * c[n + num2 - 1][num1 + num2 - 1] % mod;
	return res;
}

void dfs (int mn, int total) {
	if (mn == n + 1) ans = (ans + solve()) % mod;
	if (mn <= n) dfs(mn + 1, total);
	int t = mn ? mn << 1 : 2;
	if (total + t <= n + 1) {
		stk[top++] = mn;
		dfs(mn, total + t);
		top--;
	}
}

int main () {
	scanf("%d%d%s", &n, &m, str);
  	for (int i = 0; i <= n * 5; i++) {
    	for (int j = 0; j <= n * 5; j++) c[i][j] = 0ll;
    }
  	for (int i = 0; i <= n * 5; i++) c[i][0] = c[i][i] = 1ll;
	for (int i = 1; i <= n * 5; i++) {
		for (int j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
	}
	dfs(0, 0);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;

/**
 * Created by Seiya on 2016/10/16.
 */
public class Main {
     static final long MOD = 1000000007;

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

        int N; // 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107
        int[] sosu = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009};
        int[] kosu = new int[200];


        for (int i = 0; i < 200; i++) {
            kosu[i] = 0;
        }

        int i;

        N = scanner.nextInt();

        for (int j = 2; j <= N; j++) {
            i = 0;
            int temp = j;
            while (true) {
                if (temp == 1) break;
                while (true) {
                    if (temp % sosu[i] != 0) break;
                    temp /= sosu[i];
                    kosu[i]++;
                }
                i++;
            }

        }
        long ans = 1;
        for (int j = 0; j < 200; j++) {
            ans = ans * (kosu[j] + 1) % MOD;
        }

        System.out.println(ans);


    }





}




Measured memory_bytes: 9800
import java.util.Scanner;
class Main{
    public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
int menseki=x*y;
int syunaga=x+x+y+y;
System.out.println(menseki+" "+syunaga);
    }
}

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

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

	int n, ww;
	cin >> n >> ww;
	vector<int> w(n + 1), v(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	vector<vector<long long>> dp(n + 1, vector<long long>(ww + 1));
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= ww; j++) {
			if(j < w[i]) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
		}
	}
	cout << dp[n][ww] << endl;
	return 0;	
}

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

int main(){
    ll N;
    cin >> N;
    map<ll, ll> cnt;
    ll sp = 0;
    rep(i, 0, N){
        ll a;
        cin >> a;
        a /= 400;
        if(a >= 8){
            sp++;
        }else{
            cnt[a]++;
        }
    }
    if(cnt.size() == 0) cout << "1 " << sp << endl;
    else cout << cnt.size() << " " << cnt.size() + sp << endl;
    return 0;
}

Measured memory_bytes: 256
// cand <genesis?>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const ll base = 7;
const ll N = 1e5 + 9;
const ll inf = 1000100009;
typedef pair<ll,ll> LL;

ll a,b,n,i,j;
ll cal(ll x){
    ll res = 1,i;
    for (i=1;i<=5;i++) res *= x;
    return res;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("test.INP", "r", stdin);
    //cout<<cal(104) - cal(103)<<"\n";
    cin>>n;
    for (i=1;i<=n/i;i++){
        if (n%i == 0){
            for (j=1;j<=1000;j++){
                if (cal(j) - cal(j - i) == n){
                    cout<<j<<" "<<j - i; return 0;
                }
            }
        }
    }
    for (i=0;i<=1000;i++){
        for (j=0;j<=1000;j++){
            if (cal(i) + cal(j) == n){
                cout<<i<<" "<<-1*j; return 0;
            }
        }
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;


int main(void) {
	ll r;
	cin >> r;
	cout << (3 * r*r) << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n;

int main() {
	cin >> n;
	
	cout << 3 * n * n << endl;
	
	return 0;
}


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

int main() {
   int a,b;
   cin >>a>>b;
   if(a==b){
      cout<<2*a<<endl;
      return 0;
   }else{
      cout<< max(a+b-1,max(2*a-1,2*b-1)) <<endl;
   return 0;
   }
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()

    return n**2


print(main())




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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Range Set Counter
//-------------------------------------------------
template<typename T>
class RangeSet
{
private:
    ::std::vector<int> v;
    ::std::unordered_map<T, int> Map;
    ::std::vector<::std::vector<int> > data;
    int kind;
public:
    RangeSet(const ::std::vector<T> &v_):v(v_.size()){
        int sz = v_.size(); kind = 0;
        for(int i=0;i<sz;i++){
            T t = v_[i];
            if (Map.count(t)){
                data[Map[t]].push_back(i);
            }else{
                Map[t] = kind++;
                data.push_back(::std::vector<int>());
                data.back().push_back(i);
            }
            v[i] = Map[t];
        }
    }
    //query for all elements
    int query(T x){
        if (!Map.count(x)) return 0;
        return data[Map[x]].size();
    }
    //query for [a, b]
    int query(int a, int b, T x){
        if (a>b) return 0;
        if (!Map.count(x)) return 0;
        int xi = Map[x];
        auto right = ::std::upper_bound(data[xi].begin(),data[xi].end(),b);
        auto left  = ::std::lower_bound(data[xi].begin(),data[xi].end(),a);
        return right-left;
    }
    //search x for [k, tail]
    int find(int k, T x){
        if (!Map.count(x)) return -1;
        int xi = Map[x];
        auto itr = ::std::lower_bound(data[xi].begin(),data[xi].end(),k);
        if (itr!=data[xi].end()){
            return *itr;
        }else{
            return -1;
        }
    }
};

const int MOD = 2019;

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int n = s.size();
    vi dp(n+1), d10; d10.pb(1);
    rep(i,n) dp[i+1]=(dp[i]*10+(s[i]-'0'))%MOD;
    do{
        d10.pb(d10.back()*10%MOD);
    }while(d10.back()!=1);
    int C = d10.size()-1;
    rep(i,n+1) dp[i]=dp[i]*d10[C-i%C]%MOD;

    RangeSet<int> rs(dp);
    ll ans=0;
    rep(i,n){
        ans+=rs.query(i+1,n,dp[i]);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 6428
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    
	int a[3];
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	int N;
	scanf("%d", &N);
	long int maxi;
	long int total=0;
	if(a[0]>=a[1]) {
		if (a[0]>=a[2]) {
		    maxi=a[0];
			for (int i=1;i<=N;i++) {
                int temp = maxi*2;
	            maxi=temp;
	        }
	        total = maxi+ a[1] + a[2];  
		}
		else {
			maxi=a[2];
			for (int i=1;i<=N;i++) {
                int temp = maxi*2;
	            maxi=temp;
	        }
	        total = maxi+ a[0] + a[1];  
		    	
		}
	}
	else {
	         maxi=a[1];
	     for (int i=1;i<=N;i++) {
                int temp = maxi*2;
	            maxi=temp;
	        }
	        total = maxi+ a[0] + a[2];  	 	 
    }
	
	printf("%ld", total);
	return(0);
}

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

int main(){
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for(int i  = 0; i < N; i++)
        cin >> S.at(i);
    sort(S.begin(), S.end());
    for(int i  = 0; i < N; i++)
        cout << S.at(i);
    cout << endl;
}

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

Measured memory_bytes: 1152
import java.util.Scanner;
 
class Main {
	int n;
	int k;
	int[] h;
	long[] dp;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		k = sc.nextInt();
		h = new int[n];
		dp = new long[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
			dp[i] = Long.MAX_VALUE;
		}
		dp[0] = 0;
	}
	void solve(){
		for(int i=1;i<n;i++){
			for(int j=1;j<=k&&(i-j)>=0;j++){
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			}
		}
		System.out.println(dp[n-1]);
	}
}

Measured memory_bytes: 57428
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef pair<int,int> P;
const int MX=100000;
int d[MX*2+1],inf=1e9;
int a[100000],c[100000];
int main(){
	int N,x;
	cin>>N>>x;
	rep(i,N) cin>>a[i]>>c[i];
	priority_queue<P,vector<P>,greater<P> > que;
	rep(i,MX*2+1) d[i]=inf;
	que.push(P(0,0));
	d[0]=0;
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v=p.sc;
		if(d[v]!=p.fs) continue;
		rep(i,N){
			int nv=v+a[i];
			if(nv<=MX*2&&d[nv]>d[v]+c[i]){
				d[nv]=d[v]+c[i];
				que.push(P(d[nv],nv));
			}
			nv=v-a[i];
			if(0<nv&&d[nv]>d[v]+c[i]){
				d[nv]=d[v]+c[i];
				que.push(P(d[nv],nv));
			}
		}
	}
	if(d[x]==inf) puts("-1");
	else cout<<d[x]<<endl;
}


Measured memory_bytes: 3884
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

menus = [a, b, c, d, e]
ceils = [math.ceil(a/10)*10, math.ceil(b/10)*10, math.ceil(c/10)*10, math.ceil(d/10)*10, math.ceil(e/10)*10]

minIndex = 0
minTime = 10
for i in range(5):
    tmp = menus[i]%10
    if(tmp!=0):
        if(minTime>tmp):
            minTime = tmp
            minIndex = i
ans = 0
for i in range(5):
    if(i==minIndex):
        ans += menus[i]
    else:
        ans += ceils[i]

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
#include <iostream>
using namespace std;

/* 入力 */

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

  int sum=0;

  for(int i=0;i<n;i++){
    for(int j=0;j<n&&j!=i;j++){
      sum+=d[i]*d[j];
    }
  }

  cout<<sum<<endl;

}


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

using namespace std;

const int N = 200000, M = 200000;

int aa[N], bb[M];

int main() {
	int n, m, k; cin >> n >> m >> k;
	for (int i = 0; i < n; i++)
		cin >> aa[i];
	for (int j = 0; j < m; j++)
		cin >> bb[j];
	long long a = 0, b = 0;
	for (int j = 0; j < m; j++)
		b += bb[j];
	int ans = 0;
	for (int i = 0, j = m - 1; i <= n; i++) {
		while (j >= 0 && a + b > k)
			b -= bb[j--];
		if (a + b <= k)
			ans = max(ans, i + j + 1);
		if (i < n)
			a += aa[i];
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 5192
#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <time.h>
#define ll long long
#define N 100003
#define M 103
#define db double
#define P putchar
#define G getchar
#define inf 998244353
using namespace std;
char ch;
void read(int &n)
{
	n=0;
	ch=G();
	while((ch<'0' || ch>'9') && ch!='-')ch=G();
	ll w=1;
	if(ch=='-')w=-1,ch=G();
	while('0'<=ch && ch<='9')n=(n<<3)+(n<<1)+ch-'0',ch=G();
	n*=w;
}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
ll abs(ll x){return x<0?-x:x;}
ll sqr(ll x){return x*x;}
void write(ll x){if(x>9) write(x/10);P(x%10+'0');}

int a[N],b[N],c[N],d[N],n,ans,f[N],g[N],s,x,y;
bool bz[N];

int get(int x)
{
	return f[x]=(x==f[x]?x:get(f[x]));
}

int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	
	read(n);s=0;
	for(int i=1;i<=n;i++)
		read(a[i]),s^=a[i];
	a[n+1]=s;s=0;
	for(int i=1;i<=n;i++)
		read(b[i]),s^=b[i];
	b[++n]=s;
	
	for(int i=1;i<=n;i++)
		c[i]=a[i],d[i]=b[i],f[i]=i;
	
	sort(c+1,c+1+n);
	sort(d+1,d+1+n);
	
	for(int i=1;i<=n;i++)
		if(c[i]!=d[i])
		{
			P('-');P('1');
			return 0;
		}
	
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=b[i] || i==n)
		{
			if(i!=n)ans++;
			x=lower_bound(c+1,c+1+n,a[i])-c;
			y=lower_bound(c+1,c+1+n,b[i])-c;
			bz[x]=bz[y]=1;
			f[get(x)]=get(y);
		}
	}
	if(ans==0)
	{
		P('0');
		return 0;
	}
	
	for(int i=1;i<=n;i++)
		if(bz[i] && f[i]==i)ans++;
	
	write(ans-1);
	
	return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=(n)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1e9+7
#define max3(a,b,c) max(a,max(b,c)) 
#define mix3(a,b,c) mix(a,mix(b,c))

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main(){
   
    int n;cin>>n;
    vvi abc(3,vi(n));rep(i,n)cin>>abc[0][i]>>abc[1][i]>>abc[2][i];

    vvi dp(n,vi(3,0));

    rep(i,3){
        dp[0][i]=abc[i][0];
    }

    rep(i,n-1){
        rep(j,3){
            dp[i+1][j] = max(dp[i][(j+1)%3]+abc[j][i+1],dp[i][(j+2)%3]+abc[j][i+1]);
        }
    }

    cout << max3(dp[n-1][0],dp[n-1][1],dp[n-1][2]) << endl;
    
    return 0;
}

Measured memory_bytes: 6904
require 'prime'

MAX = 10 ** 6
n = gets.to_i
a_n = gets.split.map(&:to_i)

# 全GCDが1でない場合どちらでもない
all_gcd = a_n[0]
1.upto(n-1) do |i|
    all_gcd = all_gcd.gcd(a_n[i])
end
if all_gcd > 1
    puts "not coprime"
    exit 0
end

## ============
## 以下は全GCDは常に1前提
## ============

memo = Array.new(10 ** 6 + 1, 0)
primes = Array.new(10 ** 6 + 1, 0)
Prime.each(MAX) do |i|
    primes[i] = 1
end

a_n.sort!
a_n.each do |a|
    # 素数はすでに計算済みなので素因数分解を省略
    if primes[a] == 1
        if memo[a] == 1
            puts "setwise coprime"
            exit 0
        end

        memo[a] = 1
    else
        Prime.prime_division(a).each do |x, cnt|
            if memo[x] == 1
                puts "setwise coprime"
                exit 0
            end
            memo[x] = 1
        end
    end
end

puts "pairwise coprime"


Measured memory_bytes: 99572
package main

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

func main() {

	nextReader = newScanner()

	n, k := nextInt(), nextInt()

	t := n % k
	min := t

	for i := 0; i < 100000000; i++ {
		t = abs(t - k)

		if t < min {
			min = t
			if min == 0 {
				break
			}
		}

	}

	fmt.Println(min)

}

/* --------------------------------------------------------------------------
 *  std.io
 * ------------------------------------------------------------------------- */
var nextReader func() string

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func mins(t ...int) int {
	if len(t) == 0 {
		return 0
	}

	min := t[0]
	for i := 1; i < len(t); i++ {
		if min > t[i] {
			min = t[i]
		}
	}
	return min
}

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return 0 - a
	}
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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 (b<a) { a=b; return 1; } return 0; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int a,b;
  cin >> a >> b;
  if(a==b)cout << a*2 << endl;
  else if(a>b)cout << a*2-1 << endl;
  else cout << b*2-1 << endl;
}



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

int main() {
    int n, maxv = -1;
    cin >> n;
    string s;
    cin >> s;
    

    for (int i = 1; i < n; i++)
    {
        int cnt = 0;
        string empty = "";
        //前の文字列
        string tmpf = s.substr(0, i);
        //後ろの文字列
        string tmpb = s.substr(i, n - 1);
        for (int j = 0; j < tmpf.size(); j++)
        {
            for (int k = 0; k < tmpb.size(); k++)
            {
                if (tmpf[j] == tmpb[k])
                {
                    //前と後ろで同じ文字を見つけたら、emptyに追加する
                    empty += tmpf[j];
                }
            }
        }
        //empty内の文字の重複を消す
        sort(empty.begin(), empty.end());
        empty.erase(unique(empty.begin(), empty.end()), empty.end());
        cnt = empty.size();
        
        maxv = max(maxv, cnt);
    }
    cout << maxv << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+100;
ll a[maxn];
ll dp[maxn];
const int mod=998244353;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
    int n=s.length();
    int k=n;
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]) continue;
        k=min(k,max(i+1,n-i-1));
    }
    cout<<k<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#define INF 222200
#define MAXN 100
#define NIL -1
#define WHITE 0
#define BLACK 1
#define GRAY 2

void SSSP(void);

int G[MAXN][MAXN];//weight を記録した隣接行列
int n = 0;


int main(){

  int i = 0, j = 0;
  int u = 0, k = 0, v = 0;
  
  scanf("%d",&n);

  for(i = 0; i < n; i++){

    for(j = 0; j < n; j++){

      G[i][j] = INF;
      
    }
    
  }

  for(i = 0; i < n; i++){
    
    scanf("%d%d",&u,&k);
    
    for(j = 0; j < k; j++){
      
      scanf("%d",&v);
      scanf("%d",&G[i][v]);
      
    }
    
  }

  SSSP();
  
  return 0;
  
}

void SSSP(void){
  
  int d[MAXN];//V-TとTをつなぐ辺の中で重み最小の辺の重み
  int color[MAXN];
  int i = 0;
  int u = 0, v = 0;
  int mini = 0;

  for(i = 0; i < n; i++){
    d[i] = INF;
    color[i] = WHITE;
  }
  
  d[0] = 0;
  color[0] = GRAY;

  while(1){
    
    mini = INF;
    u = -1;
    for(i = 0; i < n; i++){
      
      if(color[i] != BLACK && d[i] < mini){
	mini = d[i];
	u = i;
      }
      
    }

    if(u == -1)break;

    color[u] = BLACK;

    for(v = 0; v < n; v++){
      
      if(color[v] != BLACK && G[u][v] != INF){
	
	if(G[u][v] + d[u] < d[v]){
	  
	  d[v] = G[u][v] + d[u];
	  color[v] = GRAY;
	  //sum += d[v];
	  //printf("%d\n",&d[v]);
	  
	}
	
      }
      
    }
 
  }
  
  for(i = 0; i < n; i++){
    printf("%d ",i);
    if(d[i] == INF)printf("-1\n");
    else printf("%d\n",d[i]);
  }
  
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	int h,w,k;
	cin>>h>>w>>k;
	char a[h][w];
	ll ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a[i][j];
			if(a[i][j]=='#'){ans+=1;}
		}
	}
	int res=0;
	int n=pow(2,h);
	int m=pow(2,w);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			set<int>col;
			set<int>row;
			for(int k=0;k<h;k++){
				if(i&(1<<k)){
					row.insert(k);
				}
			}
			for(int k=0;k<w;k++){
				if(j&(1<<k)){
					col.insert(k);
				}
			}
			//ps(row);e;
			//ps(col);e;
			int c=0;
			for(int p=0;p<h;p++){
				for(int q=0;q<w;q++){
					if(a[p][q]=='#' and (row.count(p) or col.count(q))){
						c+=1;
					}
				}
			}
			//cout<<c<<endl;
			if((ans-c)==k){res++;}
		}
	}
	cout<<res;
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}


Measured memory_bytes: 4040
#include <iostream>
#include <vector>
#include <set>
using namespace std;
using ll = long long;

template<class T>
class RangeMin {
	private:
		vector<T> seg;
		int n;

	public:	
		RangeMin(const vector<T>& v) : n(v.size()), seg(2*v.size()) {
			for (int i = 0; i < n; ++i) seg[i+n] = v[i];
			for (int i = n-1; i > 0; --i) seg[i] = min(seg[2*i], seg[2*i+1]);
		}
		T get(int a, int b) const {
			T res = seg[a + n]; // Change to INF to allow a > b
			for (a += n, b += n+1; a < b; a=(a+1)/2, b /= 2) {
				if (a & 1) res = min(res, seg[a]);
				if (b & 1) res = min(res, seg[b-1]);
			}
			return res;
		}
		void set(int i, T v) {
			seg[i + n] = v;
			for (i += n; i > 1; i /= 2) seg[i/2] = min(seg[i], seg[i^1]);
		}
};

bool comp(const vector<int>& a, const vector<int>& b) {
	if (a.size() != b.size()) return a.size() > b.size();
	for (int i = 0; i < a.size(); ++i) {
		if (a[i] != b[i]) return a[i] < b[i];
	}
	return false;
}

vector<int> tryAll(vector<int> act, int b, const vector<int>& ban) {
	vector<int> res = {};
	for (auto x : act) {
		if (b == x) continue;

		vector<int> off = {x};
		vector<int> rem;
		for (auto v : act) {
			if (v != x) rem.push_back(v);
		}

		vector<int> app = tryAll(rem, ban[x], ban);
		for (auto v : app) off.push_back(v);
		if (! comp(res, off)) res = off;
	}
	return res;
}

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

	int n;
	cin >> n;

	vector<pair<int, int>> ins(n);
	for (int i = 0; i < n; ++i) ins[i] = {0, i};

	vector<int> ban(n);
	for (int& p : ban) {
		cin >> p;
		--p;
		--ins[p].first;
	}
	RangeMin<pair<int, int>> rm(ins);

	if (n == 2) {
		cout << -1 << '\n';
	} else {
		// Lexicographically smallest such arrangement
		// If some card is banned by all other remaining cards, it must be next
		// Otherwise, all three-card setups are possible

		set<int> act;
		for (int i = 0; i < n; ++i) act.insert(i);

		vector<int> res(n-3);
		for (int i = 0; i < n-3; ++i) {
			int j = rm.get(0, n-1).second;
			if (-ins[j].first < n-1-i) {
				auto it = act.begin();
				if (i > 0 && ban[res[i-1]] == *it) ++it;
				j = *it;
				act.erase(it);
			} else {
				act.erase(act.find(j));
			}
			++ins[ban[j]].first;
			if (act.find(ban[j]) != act.end()) {
				rm.set(ins[ban[j]].second, ins[ban[j]]);
			}
			rm.set(j, {n, -1});
			res[i] = j;
		}

		// Handle last three
		vector<int> rem;
		for (auto v : act) rem.push_back(v);
		int b = (n == 3 ? -1 : ban[res[n-4]]);

		vector<int> lst = tryAll(rem, b, ban);

		for (auto i : res) cout << i+1 << ' ';
		for (auto i : lst) cout << i+1 << ' ';
		cout << '\n';
	}
}


Measured memory_bytes: 8704
//Let's play :)
#include<bits/stdc++.h>
using namespace std;

#define tarzan ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long 

int rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
int cc[] = {1, 1, 0, -1, -1, -1, 0, 1};

const int mod = 1e9 + 7;
const int N = 300050;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    tarzan;
    int test = 1;
    //cin >> test;
    while(test--) {
        int n, m;
        cin >> n >> m;
        int ans = (n) * (n - 1) / 2;
        ans += (m) * (m - 1) / 2;
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
-- templete

f a m = f' a 1
  where
    f' 1 t = t
    f' x t = f' ((a*x) `mod` m) (t+1)

main = do
    ds <- getInts
    unless (all (==0) ds) $ do
        print $ foldl1 lcm $ map (apply2 f) $ splitRec 2 ds
        main


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

int color[100001];
vector <pair<int,int>> adj[100001];

void coloring(int now,int d,int c)
{
    for(auto it : adj[now])
    {
        int next = it.first;
        int dd = d + it.second;
        dd%=2;

        if(dd==0)
        {
            if(color[next]==-1)
            {
                color[next] = c;
                coloring(next,dd,c);
            }
        }
        else
        {
            if(color[next]==-1)
            {
                color[next] = 1-c;
                coloring(next,dd,c);
            }
        }
    }
}

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

    int n,u,v,w;

    cin >> n;

    for(int i=0;i<n-1;i++)
    {
        cin >> u >> v >> w;
        w%=2;
        adj[u].push_back(make_pair(v,w));
        adj[v].push_back(make_pair(u,w));
    }

    memset(color,-1,sizeof(color));
    color[1] = 0;
    coloring(1,0,0);

    for(int i=1;i<=n;i++)
    {
        cout << color[i] << '\n';
    }

    return 0;
}

Measured memory_bytes: 8448
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18



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

	int anst = 0;
	int ansh = 0;

	for (int i = 0; i < n; i++) {
		string t, h; cin >> t >> h;

		if (t > h) {
			anst += 3;
		}
		else if (h > t) {
			ansh += 3;
		}
		else {
			ansh++; anst++;
		}
	}

	cout << anst << " " << ansh << endl;

	return 0;
}


Measured memory_bytes: 3172
#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) cin >> a[i];
  int colors[8] = {0};
  int target = 0;
  int index = -1;
  for (int i = 0; i < N; i++) {
    if (a[i] < 400) {
      index = 0;
    } else if (a[i] < 800) {
      index = 1;
    } else if (a[i] < 1200) {
      index = 2;
    } else if (a[i] < 1600) {
      index = 3;
    } else if (a[i] < 2000) {
      index = 4;
    } else if (a[i] < 2400) {
      index = 5;
    } else if (a[i] < 2800) {
      index = 6;
    } else if (a[i] < 3200) {
      index = 7;
    } else {
      target++;
      index = -1;
    }
    if (index >= 0) colors[index]++;
  }
  int ans = 0;
  for (int i = 0; i < 8; i++) {
    if (colors[i] > 0) ans++;
  }
  // 解答
  cout << (ans == 0 ? 1 : ans) << " " << ans + target << endl;
  return 0;
}


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

long long md(pair<long long,long long> x,pair<long long,long long> y){
    return max(x.first,y.first)-min(x.first,y.first)+max(x.second,y.second)-min(x.second,y.second);
}

int GCD(int x,int y){
    int temp;
    if(x<y){
        temp=x,x=y,y=temp;
    }
    if(y<1){
        return -1;
    }
    if(x%y==0){
        return y;
    }
    return GCD(x,x%y);
}

int main(){
    string S;
    cin >> S;
    long long K;
    cin >> K;
    int N=S.size();
    if(N<K){
        for(int i=0;i<N;i++){
            if(S[i]=='1')
            continue;
            else{
                cout << S[i] << endl;
                return 0;
            }
        }
        cout << 1 << endl;
        return 0;
    }
    else{
        for(int i=0;i<K;i++){
            if(S[i]=='1')
            continue;
            else{
                cout << S[i] << endl;
                return 0;
            }
        }
        cout << 1 << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int e[100004];
int main() {
	for (int i = 2; i <= 317; i++) {
		if (e[i] == 0) {
			for (int j = i; j * i <= 100003; j++) {
				e[i * j] = 1;
			}
		}
	}
	scanf("%d", e);
	for (int i = e[0]; true; i++) {
		if (e[i] == 0) {
			printf("%d\n", i);
			return 0;
		}
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;

long long mod=1000000007;

long long fact[1000013];

long long fp(long long x,long long y){
	long long don=1;
	while(y>0){
		if(y%2==1){
			don*=x;
		}
		don%=mod;
		y/=2;
		x*=x;
		x%=mod;
	}
	don%=mod;
	return don;
}

long long mut(long long u){
	if(u>0){
		return u;
	}
	else{
		return -u;
	}
}

int main(){
	//fri("a.gir");
	//fro("a.cik");
	long long n,m;
	cin>>n>>m;
	if((n+m)%3!=0){
		cout<<0;
		return 0;
	}
	if( mut(n-m)>min(n,m) ){
		cout<<0;
		return 0;
	}
	fact[1]=1;
	for(int i=2;i<=1000000;i++){
		fact[i]=i*fact[i-1];
		fact[i]%=mod;
	}
	long long hs=(m+n)/3;
	long long fark=mut(n-m);
	long long b=(hs-fark)/2;
	long long a=hs-b;
	if(a==0 || b==0){
		cout<<1;
		return 0;
	}
	long long bas=fact[hs]*fp(fact[a],mod-2);
	bas%=mod;
	bas*=fp(fact[b],mod-2);
	bas%=mod;
	cout<<bas<<endl;

	
 
	return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
vector<int> g[4];
int main()
{
    for(int i = 1; i<= 3;i++)
    {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int cnt = 0;
    for(int i = 1; i<= 4; i++)
    {
        if(g[i].size() == 1)
            cnt++;
    }
    if(cnt==2)
    {
        cout<<"YES";
    }
    else
        cout<<"NO";

}


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

int main(){
    int n;
    cin >> n;
    if(n%2){
        cout << setprecision(10) <<  (n/2+1) / (double)n << endl;
    }
    else cout << 0.5 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int d[100100][50],n;
int min(int a,int b){
    if(a>b)return b;
    return a;
}
int dp(int l,int r){
    if(d[l][r]!=0)return d[l][r];
    if(l==0&&r!=0)return r;
    int temp=100;
    if(r>45)return 100;
    d[l][r]=100;
    for(int i=0;i<10;i++)temp=min(temp,dp((l*10+i)%n,r+i));
    return d[l][r]=temp;
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)for(int j=0;j<50;j++)d[i][j]=0;
    printf("%d\n",dp(0,0));
}

Measured memory_bytes: 223104
def DP_C() :
    N = int(input())
    a = []
    b = []
    c = []
    for i in range(N) :
        ai, bi, ci = map(int, input().split())
        a.append(ai)
        b.append(bi)
        c.append(ci)

    dp = [[0]*3 for _ in range(N)]
    dp[0][0] += a[0]
    dp[0][1] += b[0]
    dp[0][2] += c[0]

    for i in range(1,N) :
        dp[i][0] = max(dp[i][0], dp[i-1][1] + a[i])
        dp[i][0] = max(dp[i][0], dp[i-1][2] + a[i])
        dp[i][1] = max(dp[i][1], dp[i-1][0] + b[i])
        dp[i][1] = max(dp[i][1], dp[i-1][2] + b[i])
        dp[i][2] = max(dp[i][2], dp[i-1][0] + c[i])
        dp[i][2] = max(dp[i][2], dp[i-1][1] + c[i])

    return max(dp[N-1])

print(DP_C())


Measured memory_bytes: 80088
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{it.toDouble()}
    var sum = a.sum() / n
    var ans = 0
    var k = 1000000.0
    for(i in 0 until n){
        if(Math.abs(a[i] - sum) < k){
            k = Math.abs(a[i] - sum)
            ans = i
        }
    }
    println(ans)
}


Measured memory_bytes: 36076
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val a = sc.next()
    val b = sc.next()
    var j = 0
    for (i in 0..2) {
        if (a[i] == b[i]) j += 1
    }
    print(j)
}

Measured memory_bytes: 31268