akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoderD
{
    static void Main()
    {
        long mod = 1000000007;
        int n;
        int a;
        int b;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            a = int.Parse(words[1]);
            b = int.Parse(words[2]);
        }

        long total = 1;
        for (int i = 0; i < n; i++)
        {
            if (n - i > 30)
            {
                total *= (1024 * 1024 * 1024);
                i += 29;
            }
            else
            {
                total *= 2;
            }
            total = total % mod;
        }
        total -= 1;

        // Console.WriteLine(total);

        long ca = Combination(n, a);
        long cb = Combination(n, b);

        long answer = total - ca - cb;
        if (answer < mod)
        {
            answer += mod;
        }
        if (answer < mod)
        {
            answer += mod;
        }

        Console.WriteLine(answer % mod);
    }

    // Comnibation（mod版）
    private static long Combination(int n, int k)
    {
        long mod = 1000000007;
        long answer = 1;
        for (int i = n; i > n - k; i--)
        {
            answer = mul(answer, i);
        }
        for (int i = 1; i <= k; i++)
        {
            answer = div(answer, i);
        }
        return answer;
    }

    // 掛け算（mod版）
    private static long mul(long a, long b)
    {
        long mod = 1000000007;
        return ((a % mod) * (b % mod)) % mod;
    }

    // 割り算（mod版）
    private static long div(long a, long b)
    {
        long mod = 1000000007;
        return mul(a, pow(b, mod - 2));
    }

    // べき乗（mod版）
    private static long pow(long a, long b)
    {
        long mod = 1000000007;
        if (b == 0)
        {
            return 1;
        }
        else if (b == 1)
        {
            return a % mod;
        }
        else if (b % 2 == 0)
        {
            long d = pow(a, b / 2);
            return d * d % mod;
        }
        else
        {
            return a * pow(a, b - 1) % mod;
        }
    }
}

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

int p[10000];

int main()
{
    int x,n;
    cin>>x>>n;
    for(int i=0;i<n;++i){
        int c;
        cin>>c;
        p[c]++;
    }
    int r=10000, ans=10000;
    for(int i=200;i>=0;--i){
        if(p[i])continue;
        if(r >= abs(x-i)){
            r=abs(x-i);
            ans=i;
        }
    }
    cout<<ans<<endl;
}

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] p = new int[n];
		
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		
		Arrays.sort(p);
		int count = 0;
		for(int i = 0; i < k; i++) {
			count += p[i];
		}
		
		System.out.println(count);
	}

}


Measured memory_bytes: 38608
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>
#include <complex>
#include <stdio.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e18;
const LL MAXN = 100001;

LL n;
LL x;
VLL a;

VLL t;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(2 * v, tl, tm);
		build(2 * v + 1, tm + 1, tr);
		t[v] = min(t[v * 2], t[v * 2 + 1]);
	}
}

LL min(int v, int tl, int tr, int l, int r)
{
	if (l > r || tl > tr)
		return INF;

	if (l == tl && r == tr)
		return t[v];
	int tm = (tl + tr) / 2;
	return min(min(v * 2, tl, tm, l, min(r, tm)), min(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r));
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	cin >> n >> x;
	a.assign(n, 0);
	t.assign(8 * n, 0);
	FOR(i, 0, n)
		cin >> a[i];
	FOR(i, 0, n)
		a.push_back(a[i]);

	build(1, 0, 2 * n - 1);
	LL ans = INF, curr;
	FOR(k, 0, n)
	{
		curr = k*x;
		FOR(i, 0, n)
			curr += min(1, 0, 2 * n - 1, i + n - k, i + n);
		ans = min(ans, curr);
	}

	cout << ans;
	//cin >> n;
	return 0;
}

Measured memory_bytes: 480
import sys
input = sys.stdin.readline

def main():
    N = input()
    A = [int(a) for a in input().split()]
    dic = {}

    for a in A:
        dic[a] = dic.get(a,0)+1

    if len(dic)>3:
        print("No")
    else:
        key = [k for k in dic]
        key.sort(key=lambda x:dic[x])
        if len(dic)==1:
            if key[0] == 0:
                print("Yes")
            else:
                print("No")
        elif len(dic)==2:
            if key[0] == 0 and key[1]^key[1]==0 and dic[key[1]]==dic[key[0]]*2:
                print("Yes")
            else:
                print("No")
        else:
            if key[0]^key[1] != key[2]:
                print("No")
            else:
                if dic[key[0]]==dic[key[1]]==dic[key[2]]:
                    print("Yes")
                else:
                    print("No")


if __name__ == '__main__':
    main()


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

int main() {
    
    vector<long long> v(4, 0);
    cin >> v[0] >> v[1] >> v[2] >> v[3];
    
    long long sum = 0;
    
    if (v[3] > 0 && v[0] >= v[3]) {
        sum += v[3];
        cout << sum;
        return 0;
    } else {
        sum += v[0];
        v[3] -= v[0];
    }
    
    if (v[3] > 0 && v[1] >= v[3]) {
        cout << sum;
        return 0;
    } else {
        v[3] -= v[1];
    }
    
    if (v[3] > 0 && v[2] >= v[3]) {
        sum -= v[3];
        cout << sum; return 0;
    } else {
        sum -= v[2];
        v[3] -= v[2];
    }
    
    cout << sum << endl;
    
    
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<(n-1);i++){
    if(s.at(i)!=s.at(i+1)){
      ans++;
    }
  }
  ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;a++)
#define rl(a,b,c) for(int a=b;a>=c;a--)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n;
pair<int,int> lo[55];
int v[55];
vector<int> tmp;
vector<int> final;
map<mp,int> MM;
int res;
void compute(int p,int q){
	int _ans=0;
	rb(i,1,n) {
//		cout<<lo[i].FIR-p<<" "<<lo[i].SEC-q<<" "<<MM[II(lo[i].FIR-p,lo[i].SEC-q)]<<endl;
	if(MM[II(lo[i].FIR-p,lo[i].SEC-q)]==0){
		_ans++;
	} 
	}
	res=min(_ans,res);
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	res=n;	
	rb(i,1,n){
		cin>>lo[i].FIR>>lo[i].SEC;
		MM[lo[i]]=true;
	}
	rb(i,1,n){
		rb(j,1,n){
			if(i==j) continue;
			int _p=lo[i].FIR-lo[j].FIR,_q=lo[i].SEC-lo[j].SEC;
			compute(_p,_q);
//			cout<<
		}
	}cout<<res;
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>
using namespace std;
using ll = long long;

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


Measured memory_bytes: 3192
#include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <climits>
    #include <cfloat>
    #include <map>
    #include <utility>
    #include <set>
    #include <iostream>
    #include <memory>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <functional>
    #include <sstream>
    #include <complex>
    #include <stack>
    #include <queue>
    #include <iomanip>
    using namespace std;
    #define pb push_back
    #define pf push_fron
    #define INF 1e9
    #define PI acos(-1)
    typedef long long ll;
     
     
    int main() {
    	
    	int a, b, x;
    	cin >> a >> b >> x;
    	int cat = a + b;
    	cout<<((cat>=x&&a<=x)?"YES":"NO")<<endl;
     
    	return 0;
    }

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int X;
  cin>>X;
  int ans=1;
  for(int b=1;b<=X;b++){
    for(int p=2;p<=X;p++){
      int s=pow(b,p);
      if(s<=X){chmax(ans,s);}
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4140
N,Q = map(int,input().split())
S = input()
query = [[int(e)-1 for e in input().split()] for _ in range(Q)]
acc = [0]*(N+1)
for i in range(1,N):
    acc[i+1] = acc[i]
    if S[i-1] == "A" and S[i] == "C":
        acc[i+1] += 1
for l,r in query:
    ans = acc[r+1] - acc[l]
    if S[l-1] == "A" and S[l] == "C":
        ans -= 1
    print(ans)

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


bool is_prime(int x) {
  for (int i = 3; i * i < x; i += 2) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int x;
  cin >> x;
  if (x == 2) {
    cout << 2 << endl;
  }
  else {
    if (x % 2 == 0) {
      x += 1;
    }
    while (!is_prime(x)) {
      x += 2;
    }
    cout << x << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bitcnt(n) __builtin_popcountll(n)
#define tr(container , s ) for(auto x : container ){cout << x << s;} cout<<endl;
#define one(x) cerr<<#x<<" : "<<x<<endl;
#define two(x,y) cerr<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<endl;
#define three(x,y,z) cerr<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<" , "<<#z<<" : "<<z<<endl;
#define PI acos(-1)
const int M = 1000000007;
const int N=3e5+5;

signed main()
{
    string t , c;
    cin >> c >> t;
    cout<<t<<c << endl;
}



Measured memory_bytes: 256
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let mut a:usize = read!();
    let mut k:usize = read!();
    k -= 1;
    let mut s:String = read!();
    let mut v:Vec<char> = s.chars().collect();
    if v[k] == 'A' {
        v[k] = 'a';
    }
    else if v[k] == 'B' {
        v[k] = 'b';
    }
    else if v[k] == 'C' {
        v[k] = 'c';
    }
    let ss: String = v.into_iter().collect();
    println!("{}",ss);
}


Measured memory_bytes: 2136
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll K;
string S;
ll _25[2123456], _26[2123456], fact[2123456];

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

int main() {

	cin >> K;
	cin >> S;
	ll s = S.size();

	_25[0] = _26[0] = fact[0] = 1;
	rep(i, 2123450) {
		_25[i + 1] = _25[i] * 25 % 1000000007;
		_26[i + 1] = _26[i] * 26 % 1000000007;
		fact[i + 1] = fact[i] * (i + 1) % 1000000007;
	}

	ll ans = 0;
	for (int i = 0; i <= K; ++i) {
		ll sub = (_25[K - i] * _26[i]) % 1000000007;
		sub *= fact[s - 1 + K - i];
		sub %= 1000000007;
		sub *= modinv(fact[s - 1], 1000000007);
		sub %= 1000000007;
		sub *= modinv(fact[K - i], 1000000007);
		sub %= 1000000007;
		ans += sub;
		ans %= 1000000007;
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while(b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

ll modpow(ll x, ll n) {
        ll ans = 1;
        while(n) {
                if(n & 1) ans = (ans * x) % MOD;
                x = (x * x) % MOD;
                n>>=1;
        }
        return ans;
}


vector<pair<ll, ll>> prime_factorize(ll n) {
	vector<pair<ll, ll>> res;
	for (ll i=2; i*i <=n; i++) {
		if (n%i != 0) continue;
		ll ex = 0;
		while (n%i==0) {
			ex++; n /= i;
		}
		res.push_back({i, ex});
	}
	if (n != 1) res.push_back({n, 1});
	return res;
}

int main(int, char**) {
	int n; cin >> n;
	vector<ll> A;
	vector<ll> N(1100000, 0);
	ll lc = 1;
	for (int i=0; i<n; i++) {
		ll a; cin >> a;
		A.push_back(a);
		auto pf = prime_factorize(a);
		for (auto p : pf) N[p.first] = max(N[p.first], p.second);
	}
	ll lcm = 1;
	for (int i=2; i<1100000; i++) {
		lcm = (lcm * modpow(i, N[i]))%MOD;
	}
	ll ret = 0;
	for (int i=0; i<n; i++) {
		ll add = lcm * modinv(A[i], MOD) % MOD;
		ret = (ret + add) % MOD;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 9088
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
	long int n,a[100000],ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
	}
	for(int i=0;i<n;i++){
		if(a[a[i]]==i){
			ans++;
		}
	}
	cout<<ans/2<<std::endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()



int main()
{
	string s; cin >> s;
	int res = 1000;
	int right = s.size() - 3;
	rep(i, 0, right)
	{
		string t = s.substr(i, 3);
		res = min(res, abs(753 - stoi(t)));
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
ll dp[10010];

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

    int H,N; cin >> H >> N;
    vector<pair<int,int>> AB(N);
    REP(i,N){
        int Amax = 0;
        cin >> AB[i].first >> AB[i].second;
        if(AB[i].first > Amax) Amax = AB[i].first;
    }

    REP(i,10010) dp[i] = INF;
    dp[0] = 0;
    
    for(int i=0; i<N; ++i){
        for(int j=0; j<=H; ++j){
            chmin(dp[min(j + AB[i].first, H)], dp[j] + AB[i].second);
        }
    }

    cout << dp[H] << endl;

    return 0;

}

Measured memory_bytes: 384
use proconio::input;

fn main() {
    input! {
        n: usize,
        x: String
    };
    let s = x.as_bytes();
    let mut cnt = 0;
    for &c in s {
        if c == b'1' { cnt += 1 }
    }
    let mut dp = vec![0; n+1];
    for i in 1..=n as i32 {
        let d = i.count_ones() as i32;
        dp[i as usize] = dp[(i%d) as usize] + 1;
    }
    let mut res = vec![0; n];
    for &d in [-1, 1].iter() {
        let m = cnt + d;
        if m <= 0 || (n as i32) < m { continue }
        let mut p2 = vec![1; n];
        let mut sum = 0;
        for i in (0..n-1).rev() {
            p2[i] = 2*p2[i+1] % m;
        }
        for i in 0..n {
            if s[i] == b'1' { sum = (sum + p2[i]) % m; }
        }
        for i in 0..n {
            if d == -1 {
                if s[i] == b'0' { continue }
                res[i] = dp[((sum+m-p2[i])%m) as usize] + 1;
            } else {
                if s[i] == b'1' { continue }
                res[i] = dp[((sum+p2[i])%m) as usize] + 1;
            }
        }
    }
    for &d in &res {
        println!("{}", d);
    }
}


Measured memory_bytes: 4756
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

void solve(){
  ll n; cin >> n;
  cout << (n-1)*n/2 << '\n';
}

int main(){
  solve();
  return 0;
}

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

using namespace std;

int N, K;

int main() {
    scanf("%d", &K);
    if (K == 1) {
        printf("1\n1\n");
        return 0;
    }
    N = (K + 3) / 4 * 2;
    printf("%d\n", N);
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            int a = (i + j) % N + 1;
            if (i & 1) a += N;
            if (a > K) a -= N;
            printf("%d ", a);
        }
        printf("\n");
    }
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

// printDPTable; 2次元DPテーブルを出力するテスト用関数
void printDPTable(const vector<vector<long long>> &dp){
    long long wide = 2;
    for(long long i=0; i<dp.size(); i++){
        for(long long j=0; j<dp[i].size(); j++){
            cout << setw(wide) << dp[i][j] << (j != dp[i].size()-1 ? " " : "\n");
        }
    }
    cout << "\n";
}

int main(){
    Init();

    // 初期入力
    ll h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    // 上下に可能な限り長く取る
    vvi ans(h, vi(w, 0));
    ll strNo = 1;
    for(ll i=0; i<h; i++){
        for(ll j=0; j<w; j++){
            // イチゴじゃないなら無視
            if(s[i][j] != '#') continue;

            // イチゴなら上下に可能な限り長くとる
            ans[i][j] = strNo;
            for(ll ti = i-1; ti>=0; ti--){
                if(s[ti][j] == '#' || ans[ti][j] != 0) break;
                ans[ti][j] = strNo;
            }
            for(ll ti = i+1; ti<h; ti++){
                if(s[ti][j] == '#' || ans[ti][j] != 0) break;
                ans[ti][j] = strNo;
            }
            strNo++;
        }
    }
    
    // 左から見て右に伸ばす
    for(ll j=0; j<w-1; j++){
        if(ans[0][j+1] == 0){
            for(ll i=0; i<h; i++) ans[i][j+1] = ans[i][j];
        }
    }

    // 右から見て左から伸ばす
    for(ll j=w-1; j>0; j--){
        if(ans[0][j-1] == 0){
            for(ll i=0; i<h; i++) ans[i][j-1] = ans[i][j];
        }
    }

    printDPTable(ans);
}

Measured memory_bytes: 3996
import heapq

N, M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(N)]

D = {}
for i in range(N) :
    k,v = L[i]
    if k not in D :
        D[k] = [v]
    else :
        D[k].append(v)

class Heapq :
    def __init__(self, arr, desc=False) :
        if desc :
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)
    
    def pop(self) :
        return heapq.heappop(self.hq) * self.sign
    
    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)
 
    def top(self):
        return self.hq[0] * self.sign
 
    def size(self):
        return len(self.hq)

q = Heapq([], True)
ans = 0
for k in range(1, M+1) :
    if k in D :
        for v in D[k] :
            q.push(v)
    if q.size() :
        ans += q.pop()
print(ans)


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

using namespace std;

int M, N, K, c[1009], l[1009];
char a[19][19], aux[20][19][19], ans[1009][1009];

bool cmp (int i, int j, int x, int y)
{
    if (i == x) return (j < y);
    return (i < x);
}

bool FOUND = 0;
void back (int h, int v, char ch, int xh, int yh, int xv, int yv)
{
    if (FOUND) return ;
/*    if (h + v == 1)
    {
        for (int i=1; i<=N; i++, printf ("\n"))
            for (int j=1; j<=N; j++)
                if (a[i][j] != 0) printf ("%c", a[i][j]);
                else printf (".");
        printf ("\n");
    }*/
    int lim = (3 * K / N);
    if (h == 0 && v == 0)
    {
//        printf ("%d %d\n", K, (3 * K) / N);
        //for (int i=1; i<=N; i++)
          //  printf ("%d %d\n", l[i], c[i]);
        for (int i=1; i<=N; i++)
            for (int j=1; j<=N; j++)
                aux[N][i][j] = a[i][j];
        FOUND = 1;
        return ;
    }
    if (h > 0 && (h + v) % 2 == 0)
    {
        for (int i=1; i<=N; i++)
            for (int j=1; j<N; j++)
                if (cmp (xh, yh, i, j) && a[i][j] == 0 && a[i][j + 1] == 0 && c[j] < lim && c[j + 1] < lim && l[i] < lim)
                {
                    l[i] ++, c[j] ++, c[j + 1] ++;
                    a[i][j] = a[i][j + 1] = ch;
                    back (h - 1, v, ch + 1, i, j, xv, yv);
                    a[i][j] = a[i][j + 1] = 0;
                    l[i] --, c[j] --, c[j + 1] --;
                }
    }
    else
    {
        for (int i=1; i<N; i++)
            for (int j=1; j<=N; j++)
                if (cmp (xv, yv, i, j) && a[i][j] == 0 && a[i + 1][j] == 0 && c[j] < lim && l[i + 1] < lim && l[i] < lim)
                {
                    l[i] ++, c[j] ++, l[i + 1] ++;
                    a[i][j] = a[i + 1][j] = ch;
                    back (h, v - 1, ch + 1, xh, yh, i, j);
                    a[i][j] = a[i + 1][j] = 0;
                    l[i] --, c[j] --, l[i + 1] --;
                }
    }
}

void place (int i, int j, int n, int offset)
{
    for (int dx=1; dx<=n; dx++)
        for (int dy=1; dy<=n; dy++)
            ans[i + dx - 1][j + dy - 1] = aux[n][dx][dy] + offset;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &M);
if (M <= 2)
{
    printf ("-1\n");
    return 0;
}
for (N = 3; N<=7; N++)
{
    FOUND = 0;
    for (K=1; K<=(N * N) / 2; K++)
        if ((3 * K) % N == 0 && (K == N || N == 3))
            back (K, K, 'a', 0, 0, 0, 0);
    if (!FOUND)
        printf ("fail %d\n", N);
}
if (M <= 7)
    place (1, 1, M, 0);
else
{
    N = M % 4 + 4;
    place (1, 1, N, 0);
    for (int i=N + 1; i<=M; i+=4)
        place (i, i, 4, 0);
}
for (int i=1; i<=M; i++, printf ("\n"))
    for (int j=1; j<=M; j++)
    {
        if (ans[i][j] == 0) ans[i][j] = '.';
        printf ("%c", ans[i][j]);
    }
return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>
int main(){
  int b[3];
  scanf("%d %d %d", &b[0], &b[1], &b[2]);
  if ( b[0] && b[1] || b[2] ){//どれか１だったら
    printf("Open\n");
  }else{
    printf("Close\n");
  }
  return(0);
} 



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

using namespace std;

#define ll long long
#define sz size()
#define int ll

void solve() {
    ll k;
    cin >> k;
    ll r = 0;
    ll curr = 0;
    while(r < k){
        curr++;
        r *= 26;
        r += 26;
    }

    string s = "";
    for(int i = 1; i <= curr; i++){
         s += 'a';
    }

    ll l = (r - 26) / 26 + 1;
    ll dif = k - l;
    int pos = s.sz - 1;
    string abc = "abcdefghijklmnopqrstuvwxyz";
    //cout << dif << "\n";
    while(dif > 0){
        ll val = 1;
        ll diff = dif;
        ll cnt = 0;
        pos = s.sz - 1;
        while(diff >= 26){
            diff /= 26;
            cnt++;
            val *= 26;
            pos--;
        }
        s[pos] = abc[diff];
        dif %= val;
        //cout << dif << " " << pos << "\n";
    }
    cout << s;
}

signed main() {
    solve();
}




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

check=0
if n<4:
    check=1
    print('No')
elif n%4==0 or n%7==0:
    check=1
    print('Yes')
else:
    while n>7:
        n-=7
        if n%4==0:
            check=1
            print('Yes')
            break

if check==0:
    print('No')


Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
from math import pow


def solve(X: int):
    def func(A):
        return pow(X+A**5, 1/5)

    for A in range(-200, 200):
        for B in range(-200, 200):
            if X == A**5-B**5:
                print(A, B)
                return


# Generated by 1.1.6 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()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  string s;
  cin >> s;
  string ans;
  REP(i, s.size()){
    if(s[i]=='0'){
      ans.push_back('0');
    }
    else if(s[i] == '1'){
      ans.push_back('1');
    }
    else{
      if(ans.size()){
        ans.pop_back();
      }
    }
  }

  cout <<  ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    vector<int> p(n), q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> comp(n);
    vector<int> v(n);
    rep(i,n) v[i] = i+1;
    int num = 0;
    int a,b;
    do {
        int k = 0;
        for (int x : v) {
            comp[k++] = x;
        }
        int ok = true;
        rep(i,n) {
            if (p[i] != comp[i]) {
                ok = false;
                break;
            }
        }
        if (ok) a = num;
        num++;
    } while (next_permutation(v.begin(), v.end()));
    num = 0;
    do {
        int k = 0;
        for (int x : v) {
            comp[k++] = x;
        }
        int ok = true;
        rep(i,n) {
            if (q[i] != comp[i]) {
                ok = false;
                break;
            }
        }
        if (ok) b = num;
        num++;
    } while (next_permutation(v.begin(), v.end()));
    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

/** Problem2582 : Step Aerobics **/
int main()
{
	int N;
	while (cin>>N, N) {
		const int l=1, r=2, n=0;
		string s;
		int old = n;
		
		int ans=0;
		rep(i, N) {
			cin>>s;
			int ne;
			if (old != n) {
				if (s[0]=='l') ne=l;
				else		   ne=r;
				if (old != ne)
					ans++;
				old = n;
			} else {
				if (s[0]=='l') old=l;
				else		   old=r;
			}
		}
		cout << ans << endl;
	}
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N[4];
signed main() {
    rep(i, 4) { cin >> N[i]; }
    sort(N, N + 4);
    if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9) { cout << "YES" << endl; }
    else { cout << "NO" << endl; }

}

Measured memory_bytes: 3612
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
long long int i,j,k;
long long int n,m,p,x=0;
long long int a[2002],b[2002],c[2002];
long long int dp[1002];
int kousin=0;
 
 
int main(){
	//nは頂点の数、mは辺の数
	cin>>n>>m;
	for(i=0;i<n;i++){
		dp[i]=INF;
	}
	dp[0]=0;
	for(i=0;i<m;i++){
		cin>>a[i]>>b[i];
		a[i]-=1;
		b[i]-=1;
		cin>>p;
		c[i]=-p;
	}
	while(true){
		bool update = false;
		for(i=0;i<m;i++){
			if(dp[a[i]]!=INF && dp[b[i]]>dp[a[i]]+c[i]){
				dp[b[i]] = dp[a[i]]+c[i];
				update = true;
				
			}
		}
		x+=1;
		if(!update)break;
		if(x==1)kousin = dp[n-1];
		if(x==2 && kousin != dp[n-1]){
			x=-1;
			break;
		}else if(x==2){
			x=0;
			break;
		}
	}
	/*if(x[0][0]<0){
		cout<<"inf"<<endl;
	}else{
		cout<<-x[0][n-1]<<endl;
	}*/
	if(x==-1){
		cout<<"inf"<<endl;
	}else{
		cout<<-dp[n-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))  // xが範囲内か
#define sort_u(x) sort((x).begin(),(x).end())
#define sort_d(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()  // 配列のサイズ
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;  // 確認したいとき
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))  // 切り上げたいとき
#define newline puts("")
#define v(T) vector<T>  // Tはどんな型でもいい
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;  // ******
typedef vector<vi> vvi;
typedef vector<ll> vl;  // ******
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}  // vi a(n); cin>>a;
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}  // cout<<a;  aの中身全部出す
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame1 { puts("-1"); return 0;}
#define dame0 { puts("0"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//mins(ans,now);  ansに最小値が入る
//if(max(ans,now)) ansが小さければ更新して実行。cnt++とか。
//ll sum = suma(a);

int main() {
    int n; cin >> n;
    vl l(n); cin>>l;
    if(n < 3) dame0;
    int ans=0;
    rep(i,n) srep(j,i+1,n) srep(k,j+1,n){
        if(l[i]==l[j] || l[i]==l[k] || l[k]==l[j]) continue;
        if(l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[k] + l[j] > l[i]) ans++;
    }
    cout << ans << endl;
}

/*
g++ a.cpp
./a.out

oj d
oj t

debug:ctrl+shift+B+./problem.exe
problem.in+f5

*/


Measured memory_bytes: 3604
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
long long rec(long long a, long long b) {
	if (b == 0) return -a;
	return 2 * (a - a % b) + rec(b, a % b);
}
long long n, a, b;
int main() {
	cin >> n >> a;
	b = n - a;
	if (a < b) swap(a, b);
	cout << rec(a, b) + n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i];
  int L;
  cin>>L;
  vector<vector<int>> dp(17, vector<int>(n));

  int p = 0;
  rep(i,n){
    while(p+1<n && vec[p+1]-vec[i]<=L) p++;
    dp[0][i] = p;
  }
  repl(i,1,17){
    rep(j,n) dp[i][j] = dp[i-1][dp[i-1][j]];
  }

  int q;
  cin>>q;
  rep(_,q){
    int a,b;
    cin>>a>>b;
    a--;b--;
    if(a>b) swap(a,b);
    // a -> b

    int l=0, r=n;
    while(r-l>1){
      int m = (r+l)/2;
      auto ok = [&](){
        int pos = a;
        int x = m;
        int c = 0;
        while(x>0){
          if(x&1) pos = dp[c][pos];
          c++;
          x /= 2;
        }
        return pos>=b;
      };
      if(ok()) r = m;
      else l = m;
    }
    cout << r << endl;
  }
  return 0;
}


Measured memory_bytes: 7928
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char b;
    scanf("%c",&b);
    if(b=='A')
        printf("T");
    if(b=='T')
        printf("A");
    if(b=='C')
        printf("G");
    if(b=='G')
        printf("C");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (long long i = (a); i <= (b); i++)
#define FORD(i,a,b) for (long long i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(long long)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end());
#define BUG(x) cout << #x << " = " << x << endl
#define BUGP(x) cout << #x << " = " << x._1 << ", " << x._2 << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto _i:x) cout << _i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 1e-8
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

int n, c, cost[33][33], val, cnt[3][33], change[3][33];

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> c;
  FOR (i, 1, c) FOR (j, 1, c) cin >> cost[i][j];
  FOR (i, 1, n) FOR (j, 1, n) cin >> val, cnt[(i + j) % 3][val]++;
  REP (i, 3) FOR (j, 1, c) {
    int tmp = 0;
    FOR (k, 1, c) tmp += cnt[i][k] * cost[k][j];
    change[i][j] = tmp;
  }
  int ans = mod;
  FOR (i, 1, c) FOR (j, 1, c) FOR (k, 1, c) if (i - j && i - k && k - j) {
    ans = min(ans, change[0][i] + change[1][j] + change[2][k]);
  }
  cout << ans;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

int main() {
	for (;;) {
		int N; cin >> N;
		if (N == 0) break;
		vector<int> x(N), y(N);
		for (int i = 1; i < N; i++) {
			int n, d; cin >> n >> d;
			x[i] = x[n] + dx[d];
			y[i] = y[n] + dy[d];
		}
		int xmin = INT_MAX, xmax = INT_MIN, ymin = INT_MAX, ymax = INT_MIN;
		for (int i = 0; i < N; i++) {
			xmin = min(xmin, x[i]);
			xmax = max(xmax, x[i]);
			ymin = min(ymin, y[i]);
			ymax = max(ymax, y[i]);
		}
		cout << xmax - xmin + 1 << ' ' << ymax - ymin + 1 << endl;
	}
}

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

int a,b,c;

void changeNum(int& a,int& b){
    int temp = a;
    a=b;
    b=temp;
}

main(){
    cin>>a>>b>>c;
    
    if(a>b){
        changeNum(a,b);
    }
    if(b>c){
        changeNum(b,c);
    }
    if(a>b){
        changeNum(a,b);
    }
    
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}




Measured memory_bytes: 3088
def c_BigArray(N, K, I):
    from collections import defaultdict
    from operator import itemgetter
    d = defaultdict(int)
    for a, b in I:
        d[a] += b
    d = sorted(d.items(), key=itemgetter(0))
    
    tmp = 0
    for k, v in d:
        tmp += v
        if tmp >= K:
            return k
    return None

N,K = [int(i) for i in input().split()]
I = [[int(i) for i in input().split()] for j in range(N)]
print(c_BigArray(N, K, I))

Measured memory_bytes: 31584
n = int(input())
a = list(map(int, input().split()))
dp = [[0] * 2 for i in range(n + 1)]
dp[0][0] = 0
dp[0][1] = -float('inf')
for i in range(n):
    dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i])
    dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i])

print(dp[n][0])


Measured memory_bytes: 25616
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#define ll long long
using namespace std;

int main(void){
    int a;
    cin >> a;
    if (a >= 1200){
        cout << "ARC";
    } else {
        cout << "ABC";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val (r, c) = readLine()!!.split(' ').map(String::toInt)
    val map = Array(r + 2) { CharArray(c + 2) { '#' } }
    (1..r).forEach {
        map[it] = readLine()!!
                .toMutableList()
                .apply { this.add(0, '#') }
                .apply { this.add(this.size, '#') }
                .toCharArray()
    }
    val branch = Array((r + 1) * (c + 1)) { mutableListOf<Int>() }
    for (i in 1..r) {
        for (j in 1..c) {
            val cur = j + (c * (i - 1))
            if (map[i][j] == '.' && map[i][j + 1] == '.') {
                branch[cur].add(cur + 1)
                branch[cur + 1].add(cur)
            }
            if (map[i][j] == '.' && map[i + 1][j] == '.') {
                branch[cur].add(cur + c)
                branch[cur + c].add(cur)
            }
        }
    }

    val minCost = Array((r + 1) * (c + 1)) { Int.MAX_VALUE }
    minCost[1] = 1

    val queue = ArrayDeque<Int>().apply { addFirst(1) }
    while (queue.isNotEmpty()) {
        val cur = queue.pollLast()!!
        for (to in branch[cur]) {
            if (minCost[to] > minCost[cur] + 1) {
                minCost[to] = minCost[cur] + 1
                queue.addFirst(to)
            }
        }
    }
    if (minCost[r * c] == Int.MAX_VALUE) {
        println(-1)
    } else {
        val pCount = map.map { it.count { it == '.' } }.sum()
        println(pCount - minCost[r * c])
    }
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

ll dp[100][10];
ll dsum[100][10];
ll K;

set<ll> S;

void dfs(int keta, ll v, int last) {
  if( keta <= 0 ) {
    S.insert(v);
    return;
  }
  REP(i,0,10) {
    if( abs(last-i) <= 1 ) {
      dfs(keta-1,v * 10LL + i, i);
    }
  }
}

int main() {

  REP(i,0,12) {
    REP(j,1,10) {
      dfs(i,j,j);
    }
  }
  vector<ll> vec;
  for(ll s : S) {
    vec.pb(s);
  }
  sort(ALL(vec));
  //rep(i,(int)vec.size()){
  //cout << i << "-th: " << vec[i] << endl;
  //}
  cin >> K;
  cout << vec[K-1] << endl;
  return 0;
  REP(i,0,10) dp[1][i] = 1LL;
  REP(i,2,30) {
    REP(j,0,10) {
      REP(k,-1,2) {
	if( j+k < 0 ) continue;
	dp[i][j] += dp[i-1][j+k];
      }
    }
  }
  REP(i,1,30) {
    dsum[i][1] = dsum[i-1][9];
    REP(j,1,10) {
      dsum[i][j] += ( dsum[i][j-1] + dp[i][j] );
    }
  }
  cout << dsum[1][9] << "!"<< endl;
  cout << dsum[2][1] << "!"<< endl;

  int keta = -1;
  ll sum = 0;

  REP(i,1,30) {
    REP(j,1,10) sum += dp[i][j];
    keta = i;
    if( sum >= K ) break;
  }
  cout << "keta = " << keta << endl;

  REP(i,1,3) {
    rep(j,10) cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
    puts("");
  }
  
  ll x = K;
  for(int i=keta;i>=1;--i) {
    int v = -1;
    int sp = ( ( i == keta ) ? 1 : 0 );
    REP(j,sp,10) {
      if( x <= dsum[i][j] ) {
	v = j;
	break;
      }
    }
    assert( v != -1 );
    cout << "keta = " << i << ", v = " << v << " x = " << x << " dsum[" << i << "][" << v << "] = " << dsum[i][v] << endl;
    cout << v;
    if( v - 1 >= 1 ) {
      x -= dsum[i][v-1];
    } else {
      x -= dsum[i-1][9];
    }
 
    cout <<"  next x = " << x << endl;
    assert( x >= 0 );
  }
  puts("");
  
  return 0;
}


Measured memory_bytes: 98028
A, B, C = map(int, input().split())
if (A + B + C) % 2 == max(A, B, C) % 2:
  print((3 * max(A, B, C) - (A + B + C)) // 2)
else:
  print((3 * max(A, B, C) - (A + B + C) + 3) // 2)

Measured memory_bytes: 3060
s=input()
n=len(s)
mod=10**9+7
dp=[[0]*4 for _ in range(n+1)]
dp[n][3]=1
for i in reversed(range(n)):
    for j in reversed(range(4)):
        if j==3:
            if s[i]=="?":
                m=3
            else:
                m=1
            dp[i][j]+=m*dp[i+1][j]
        else:
            if s[i]=="?":
                m1=3
            else:
                m1=1
            if j==0:
                if s[i]=="A" or s[i]=="?":
                    m2=1
                else:
                    m2=0
            elif j==1:
                if s[i]=="B" or s[i]=="?":
                    m2=1
                else:
                    m2=0
            else:
                if s[i]=="C" or s[i]=="?":
                    m2=1
                else:
                    m2=0
            dp[i][j]+=m1*dp[i+1][j]+m2*dp[i+1][j+1]
        dp[i][j]%=mod
print(dp[0][0]%mod)
#print(dp)

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

ll input[105];
vector <pair <ll,ll> > temp;

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

	ll i,j,k,l,m,n,t;

	ll x;

	cin >> x >> n;

	for(i=0;i<n;i++)
	{
		cin >> k;
		input[k] = -1;
	}

	// sort(input.begin(),input.end());

	k = 0;
	for(i=0;i<105;i++)
	{
		if(input[i] != -1)
		{
			temp.push_back(pair <ll,ll> (abs(x-i),i));
		}
	}

	sort(temp.begin(),temp.end());

	cout << temp[0].second << '\n';
}

Measured memory_bytes: 3636