akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n; cin >> n;
    vector<int> a(n), b(n);
    rep(i, n)
    {
        cin >> a[i];
        b[i] = a[i] - i + 1;
    }
    sort(ALL(b));
    //PrintVector(b);
    int k;
    if (b.size() & 1) k = b[b.size()/2];
    else k = (b[b.size()/2] + b[b.size()/2 - 1]) / 2;
    //COUT(k);
    ll ans = 0;
    rep(i, n)
    {
        ans += abs(b[i] - k);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, v) for (auto &&i : v)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
vector<vector<lli>> v;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    lli N;
    cin >> N;
    v.resize(N, vector<lli>(3));
    REP(i, N)
    {
        cin >> v[i][1] >> v[i][2];
        v[i][0] = v[i][1] + v[i][2];
    }
    sort(ALL(v));
    reverse(ALL(v));
    lli ans = 0;
    REP(i, N)
    {
      //  cout << v[i][1] << endl;
        ans += i % 2 == 0 ? v[i][1] : -v[i][2];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 5760
S = str(input())

if S == "AccccCcccc":
    print('AC')
    
elif S[0] == "A":
    S1 = "a"+S[1:]
    if S[2] == "C":
        S2 = S1[:2]+"c"+S1[3:]
        if S2.islower():
            print("AC")
        else:
            print("WA")

    elif S[-2] == "C":
        S2 = S1[:-2]+"c"+S1[-1]
        if S2.islower():
            print("AC")
        else:
            print("WA")
    else:
        print("WA")

else:
    print("WA")


Measured memory_bytes: 9064
#include<cstdio>

int main() {
    char ch;
    int cnt[26] = {};

    while (scanf("%c", &ch) != EOF) {
        if (ch > 'Z') ch -= ('a' - 'A');
        cnt[ch - 'A']++;            
    }
    for (int i = 0; i < 26; i++) printf("%c : %d\n", 'a' + i, cnt[i]);

    return 0;
}

Measured memory_bytes: 968
a = input()
b = a[2:-1]
if a.startswith("A"):
    if b.count("C") == 1:
        c = list(a)
        c.remove("A")
        c.remove("C")
        for i in c:
            if i.isupper():
                print("WA")
                exit()
        print("AC")
        exit()
print("WA")


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
	
int main(){
  int n,k;
  scanf("%d %d",&n,&k);
  int dp[n]{0};
  int a[n];
  for(int i = 0; i< n; ++i){
    scanf("%d",&a[i]);
  }

  dp[1] = abs(a[1]-a[0]);

  for (int i =2; i <n;++i){
    int m = 1e9;
    for(int j = 1; j<= min(i,k);++j){
      m = min(m,abs(a[i]-a[i-j])+dp[i-j]);
    }
    dp[i] = m;
  }
  printf("%d",dp[n-1]);
}


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

int h[100005], gd[100005];

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &h[i]);
        gd[i] = 1;
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        if (h[a] > h[b]) gd[b] = 0;
        else if (h[a] == h[b]) gd[a] = 0, gd[b] = 0;
        else gd[a] = 0;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        if (gd[i]) ans++;
    printf("%d\n", ans);
}

Measured memory_bytes: 2500
import sys
readline = sys.stdin.buffer.readline

A, B, M = map(int, readline().split()) 
aa = list(map(int, readline().split()))
bb = list(map(int, readline().split()))

res = min(aa) + min(bb)

for i in range(M):
    x, y, c = map(int, readline().split())
    x -= 1
    y -= 1
    res = min(res, aa[x] + bb[y] - c)

print(res)

Measured memory_bytes: 63072
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n, c;
	cin >> n >> c;
	vector<vector<int>> d(c, vector<int>(c));
	vector<vector<int>> C(n, vector<int>(n));
	rep(i, c) {
		rep(j, c) {
			cin >> d[i][j];
		}
	}
	rep(i, n) {
		rep(j, n) {
			cin >> C[i][j];
			C[i][j]--;
		}
	}
		int ans = 1000000000;
		vector<int> a1(c), a2(c), a0(c);
		rep(i, c) {
			rep(j, n) {
				rep(k, n) {
					if ((j + k) % 3 == 0) a0[i] += d[C[j][k]][i];
					else if ((j + k) % 3 == 1) a1[i] += d[C[j][k]][i];
					else a2[i] += d[C[j][k]][i];
				}
			}
		}
		for (int i = 0; i < c - 2; i++) {
			for (int j = i + 1; j < c - 1; j++) {
				for (int k = j + 1; k < c; k++) {
					ans = min(ans, a0[i] + a1[j] + a2[k]);
					ans = min(ans, a0[i] + a2[j] + a1[k]);
					ans = min(ans, a1[i] + a0[j] + a2[k]);
					ans = min(ans, a1[i] + a2[j] + a0[k]);
					ans = min(ans, a2[i] + a1[j] + a0[k]);
					ans = min(ans, a2[i] + a0[j] + a1[k]);
				}
			}
		}
		cout << ans << endl;
}

Measured memory_bytes: 1280
n,a,b = map(int, input().split())
count = 0
if a != 0:
    roop = int(n / (a + b))
    remainder = n % (a + b)
    if roop > 0:
        count += roop * a
    
    if remainder > 0:
        if remainder <= a:
            count += remainder
        else:
            count += a
print(count)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, m) = [int(e) for e in lines[0].split(" ")]

    return (n, m)


def solve(n, m):

    result = 'No'
    if n == m:
        result = 'Yes'
    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<string>
#include<vector>
using namespace std;
int min_cost=10000;
int main(){
    int N,T;
    cin>>N>>T;
    vector<int>c(N);
    vector<int>t(N);
    for(int i=0;i<N;i++){
        cin>>c[i]>>t[i];
    }
    int MAX=1<<30;//2の30乗
    int ans=MAX;
    for(int i=0;i<N;i++){
        if(t[i]<=T){
            ans=min(ans,c[i]);
        }
    }
    if(ans<MAX){
        cout<<ans<<endl;
        return 0;
    }else{
        cout<<"TLE"<<endl;
        return 0;
    }
}


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

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  int a = 0;
  int ba = 0;
  int b = 0;
  int sol = 0;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int i = 1; s[i]; ++i) {
      sol += s[i - 1] == 'A' && s[i] == 'B';
    }
    if (s[0] == 'B' && s.back() == 'A') {
      ba++;
    } else if (s[0] == 'B') {
      b++;
    } else if (s.back() == 'A') {
      a++;
    }
  }
  if (ba) {
    sol += ba - 1;
    if (a) sol++, a--;
    if (b) sol++, b--;
  }
  sol += min(a, b);
  cout << sol << '\n';
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
    int n;
    long long a[100010];

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
    }

    int zero = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            zero++;
            break;
        }
    }

    if (zero > 0) {
        printf("0\n");
        return 0;
    }

    long long p=1;
    for (int i = 0; i < n; i++) {
        if (a[i] <= 1000000000000000000/p) {
            p = p * a[i];
        } else {
            printf("-1\n");
            return 0;
        }
    }

    printf("%lld\n", p);
    return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = min(b - 1, n);
  ll ans = (a * x / b) - a * (x / b);
  
  cout << ans << '\n';
}

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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

class union_find{
public:
    explicit union_find(int _n):n(_n){
        par.resize(static_cast<unsigned long>(_n));
        rank.resize(static_cast<unsigned long>(_n));
        sizes.resize(static_cast<unsigned long>(_n));
        for(int i=0;i<_n;i++){
            par[i]=i;
            rank[i]=0;
            sizes[i]=1;
        }
    }
    
    //親ノードを見つけます
    int find(int a){
        if(par[a]==a)return a;
        return par[a]=find(par[a]);
    }
    
    //aとbが同じグループかの判定
    bool same(int a,int b){
        return find(a)==find(b);
    }
    
    //aとbを同じグループにします
    void unite(int a,int b){
        link(find(a),find(b));
    }
    
    //aが属するグループの要素数を求めます
    int size(int a){
        return sizes[find(a)];
    }
    
    //全体がどのグループに属しているかがわかります
    void view(){
        for(int i=0;i<n;i++){
            cout<<" par"<<"["<<i<<"]="<<par[i]<<((i==n-1)?"\n":",");
        }
        for(int i=0;i<n;i++){
            cout<<"size"<<"["<<i<<"]="<<sizes[i]<<((i==n-1)?"\n":",");
        }
        cout<<endl;
    }

private:
    void link(int a,int b){
        if(same(a,b))return;
        if(rank[a]>rank[b]){
            par[b]=a;
            sizes[a]+=sizes[b];
            sizes[b]=0;
        }else{
            par[a]=b;
            if(rank[a]==rank[b])rank[b]++;
            sizes[b]+=sizes[a];
            sizes[a]=0;
        }
    }
    int n;
    vector<int> par;
    vector<int> rank;
    vector<int> sizes;
};

int n, k, l;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  if (stream2 == NULL) return 0;
#endif
  cin >> n >> k >> l;
  union_find uf1(n);
  for (int i = 0; i < k; i++) {
    int a, b; cin >> a >> b;
    uf1.unite(a - 1, b - 1);
  }
  union_find uf2(n);
  for (int i = 0; i < l; i++) {
    int a, b; cin >> a >> b;
    uf2.unite(a - 1, b - 1);
  }
  vector<pair<int,int> > v;
  for (int i = 0; i < n; i++) {
    v.push_back(make_pair(uf1.find(i), uf2.find(i)));
  }
  // uf1.view();
  // uf2.view();
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    int a = uf1.find(i);
    int b = uf2.find(i);
    cout << upper_bound(v.begin(), v.end(), make_pair(a, b)) - lower_bound(v.begin(), v.end(), make_pair(a, b));
    if (i != n - 1) cout << " ";
  }
  cout << endl;
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  fclose(stream2);
#endif
  return 0;
}

Measured memory_bytes: 7028
using System;
using System.Text;

public class Test
{
	static public void Main( )
	{
		StringBuilder output = new StringBuilder();
		output.Capacity = 608;
		while( true ) { 
			string[] data = Console.ReadLine().Split( ' ' );
			var H = Int64.Parse( data[0] );
			var W = Int64.Parse( data[1] );
			if( 0 == H && 0 == W ) break;
			
			
			for( var i=0; i<H; i++ ) {
				for( var j=0; j<W; j++ ) {
					output.Append( "#");
				}
				output.Append( "\n");
			}
			output.Append( "\n");
		}
		Console.Write( output );
	}
}

Measured memory_bytes: 5624
//atcoder ABC 137 D题

#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;

int n, m;
int a[100005];
pair <int, int> job[100005];
priority_queue <int> que;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1, x, val; i <= n; ++i) {
		scanf("%d%d", &x, &val);
		job[i].fi = m - x + 1;
		job[i].se = val;
	}

	long long ans = 0;
	sort (job + 1, job + n + 1);
	for (int i = m, j = n; i; --i) {
		for (; j; --j) {
			if (job[j].fi < i) break;
			que.push(job[j].se);
		}
		if (!que.empty()) {
			ans += que.top();
			que.pop();
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1660
N, MA, MB = gets.split.map(&:to_i)
drags = N.times.map { gets.split.map(&:to_i) }

dp = Hash.new { |h, k| h[k] = Hash.new(Float::INFINITY) }

drags.each do |a, b, c|
  a_keys = dp.keys.sort
  b_keys = Hash.new
  
  a_keys.each { |sa| b_keys[sa] = dp[sa].keys }

  a_keys.reverse_each do |sa|
    na = sa + a

    b_keys[sa].sort.reverse_each do |sb|
      nb = sb + b

      cost = dp[sa][sb] + c

      if dp[na][nb] > cost
        dp[na][nb] = cost
      end
    end
  end

  if dp[a][b] > c
    dp[a][b] = c
  end
end

ans = Float::INFINITY

dp.each do |na, listB|
  listB.each do |nb, cost|
    if na * MB == nb * MA && ans > cost
      ans = cost
    end
  end
end

if ans == Float::INFINITY
  puts -1
else
  puts ans
end



Measured memory_bytes: 6264
import java.util.Scanner;

class Main {
	Scanner sc=new Scanner(System.in);

	public void run() {
		int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
		ln((a<b && b<c)?"Yes":"No");
	}

	public static void main(String[] args) {
		new Main().run();
	}
	
	public static void pr(Object o) {
		System.out.print(o);
	}
	
	public static void ln(Object o) {
		System.out.println(o);
	}
	
	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
import math

def main(N, d):
  if d == 1:
    return N
  elif d == 2:
    return 9
  elif d == 3:
    return 9 + (N - 99)
  elif d == 4:
    return 909
  elif d == 5:
    return 909 + (N - 9999)
  else:
    return 90909
 

N = int(input())
d = int(math.log10(N)) + 1

print(main(N, d))

Measured memory_bytes: 3188
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<10)
#define LLINF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    if (105 <= n && n <= 134)cout << '1';
    else if (135 <= n && n <= 164)cout << '2';
    else if (165 <= n && n <= 188)cout << '3';
    else if (189 <= n && n <= 194)cout << '4';
    else if (195 <= n)cout << '5';
    else cout << '0';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <unordered_map>

const int MOD = pow(10,9)+7;
typedef long long ll;

using namespace std;
int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}



ll solve(vector<ll> csum, ll N, ll sig){
    
    ll cumOper = 0;
    
    ll sign = sig;
    ll count = 0;
    
    
    ll signi;
    
    for(auto i = 0; i < N; i++){
        
        
        if( (csum[i]+cumOper) == 0){
            count++;
            cumOper -= sign;
        }
        
        signi = (csum[i]+cumOper)/abs(csum[i]+cumOper);
        
        if (signi!= sign) {
            sign = signi;
            continue;
        }
        
        ///  csum[i]+cumOperを (-sign)にする。
        
        
        /// sign = 1のとき、csum[i]+cumOper > 0なので、 -1になるまで減らす。
        /// sign = -1のとき、csum[i]+cumOper < 0なので、+1になるまで増やす
        
        if (sign == 1){
            count +=(csum[i] + cumOper + 1);
            cumOper += (-1) * (csum[i] + cumOper + 1);
        }else{
            count +=  (-(csum[i] + cumOper) + 1);
            cumOper += (1) * (-(csum[i] + cumOper) + 1);
        }
        
        sign = -sign;
    }
    
    return count;
}




int main() {

    ll N = lin(); ll K = lin();
  
    typedef pair<ll,ll>  P;
    
    vector<P> inp;
    P temp;
    for(auto i = 0; i< N; i++){
        cin >> temp.first >> temp.second;
        inp.push_back(temp);
    }
    
    sort(inp.begin(),inp.end(),[](P val1, P val2){return val1.first < val2.first;});
    
    ll  cur = 0;
    while(K>0){
        K -=inp[cur].second;
        cur++;
    }
    
    cout << inp[--cur].first << endl;
    
    
    return 0;
    
    
}






Measured memory_bytes: 2420
main(H,W,i,j){for(;scanf("%d %d",&H,&W),H;puts(""))for(i=0;i<H;i++)for(j=0;j<W;j++)printf("%s%s",i>0&&i<H-1&&j>0&&j<W-1?".":"#",j==W-1?"\n":"");}

Measured memory_bytes: 1748
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	int n;
	cin >> n;

	int ans = inf;

	Rep(i, 1, n){
		int a = i;
		int b = n - a;
		int tmp = 0;
		// 桁を足す
		while (a > 0) {
			tmp += a % 10;
			a /= 10;
		}
		while (b > 0) {
			tmp += b % 10;
			b /= 10;
		}
		ans = min(tmp, ans);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll F[2100010];

ll Mul(ll a, ll b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
ll square(ll x) {
	return (x * x) % mod;
}

ll power(ll x, ll y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

ll Div(ll a, ll b) {
	return Mul(a, power(b, mod - 2));
}
ll P(ll n, ll r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

ll C(ll n, ll r) {
	if (n < r || n < 0 || r < 0) return 0;
	ll ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}

int main()
{
	ll X, Y;
	cin >> X >> Y;
	if ((X + Y) % 3 != 0 || abs(X - Y) > (X + Y) / 3) {
		cout << 0 << endl;
	}
	else {
		if (abs(X - Y) > (X + Y) / 3) {
			cout << 0 << endl;
			return 0;
		}
		fact();
		int n = (X + Y) / 3;
		int r = (n - abs(X - Y)) / 2;
		cout << C(n, r) << endl;
	}
}

Measured memory_bytes: 16640
// #define USE_CPP11
// #define USE_PRINTF

#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <complex>
#include <memory>
#include <sstream>

#ifdef USE_CPP11
#include <unordered_map>
#include <unordered_set>
#include <functional>
#endif

#define PRINT(obj) cout << obj << endl
#define REP(i, n) for(int (i) = 0; (i) < (n); i++)
#define SPACE " "

typedef long long ll;

const int INF = 1e9 + 10;

using namespace std;

namespace Scanner {
#ifdef USE_PRINTF
  int    nextInt()    { int    d; scanf("%d" , &d); return d; }
  float  nextFloat()  { float  f; scanf("%f" , &f); return f; }
  double nextDouble() { double f; scanf("%lf", &f); return f; }  
  string nextString() { string s; scanf("%s" , &s); return s; }
  ll     nextll()     { ll     l; scanf("%ll", &l); return l; }
#else
  int    nextInt()    { int    d; cin >> d; return d; }
  float  nextFloat()  { float  f; cin >> f; return f; }
  double nextDouble() { double f; cin >> f; return f; }  
  string nextString() { string s; cin >> s; return s; }
  ll     nextll()     { ll     l; cin >> l; return l; }
#endif

  string getLine() { 
    string input;
    getline(cin, input);
    return input;
  }
};

namespace myLibrary {
  vector<string> split(const string& str, char delim) {
    vector<string> ret;
    size_t current = 0, found;
    while ((found = str.find_first_of(delim, current)) != string::npos) {
      ret.push_back(string(str, current, found - current));
      current = found + 1;
    }
    ret.push_back(string(str, current, str.size() - current));
    return ret;
  }
  
#ifdef USE_CPP11
  ///
  /// higher-order functional
  /// This is something like map in haskell, python, etc.
  /// Sample usage:
  ///   vector<int> a = {1, 2, 3, 4, 5};
  ///   vector<int> b = myLibrary::_Map<int, int>(a, [](int n){
  ///     return n * n;
  ///   });
  /// Result:
  ///   b = 1, 4, 9, 16, 25
  ///
  template<typename T_IN, typename T_OUT, class Functor>
  vector<T_OUT> _Map(vector<T_IN> src, Functor func) {
    vector<T_OUT> ret;
    for (int i = 0; i < src.size(); i++) {
      ret.push_back(func(src[i]));
    }
    return ret;
  }
#endif

};

struct Point {
public:
  int y, x;
  Point(int y, int x): y(y), x(x) { }
  Point() { }
};

/// BEGIN //////////////////////////////////////////////////////////

int main() {
  while (true) {
    int e = Scanner::nextInt();
    if (e == 0) {
      break;
    }

    int ans = 1000000;
    for (int z = 0; z <= 100; z++) {
      for (int y = 0; y <= 1000; y++) {
        int t = z * z * z + y * y;
        int x = e - t;
        if (x >= 0) {
          ans = min(ans, (x + y + z));
        }
      }
    }

    PRINT(ans);
  }
  return 0;
}

/// END   //////////////////////////////////////////////////////////

Measured memory_bytes: 1164
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
#include <deque>
#include <math.h>
#include <tgmath.h>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << "\n";}
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ull a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

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

ll aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

//fast power
ll calc(ll a, ll b) {
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        ll d = calc(a, b / 2);
        return (d * d) % MOD;
    }
    else return (a * calc(a, b - 1)) % MOD;
}

//fast combination
ll comb(ll n, ll a) {
    ll b = 1, c = 1;
    for (ll i = 1; i <= a; ++i) {
        b = b * i % MOD;
        c = c * (n - i + 1) % MOD;
    }

    return c * calc(b, MOD - 2) % MOD;
}

ll comb2(ll a) {
    ll b = a / 2;
    if (a % 2) {
        b = (a - 1) / 2;
        return (b * a);
    }
    return (b * (a - 1));
}

int kyotsu(string ss, int st, int ed, string ss2) {
    int ans = 0;
    for ( int i = st; i < ed; ++i ) {
        if (i - st >= ss2.size()) return ans;
        if (ss[i] == ss2[i - st] || ss[i] == '?') {
            ans++;
        } else {
            return -1;
        }
    }
    return ans;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    vector<ll> hh(n);
    vector<ll> dp(n, 100000000000);
    rep (i, 0, n) cin >> hh[i];
    dp[0]=0;
    rep (i, 0, n) {
        rep (j, 1, k+1) {
            chmin(dp[i+j], dp[i] + aabs(hh[i]-hh[i+j]));
        }
    } 
    cout << dp[n-1] << endl;

    return 0;
}


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



int main(){
  int a[10000]={};
  int b[10000]={};
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    b[i]=a[i];
  }
  int mi=1e9;
  for(int i=0;i<=a[1];i++){
    int count=0;
    a[1]-=i;
    count+=i;
    for(int t=1;t<n;t++){
      a[t+1]-=a[t];
      count+=a[t]*2;
      if(a[t+1]<0){a[t+1]=0;}
    }
    count+=a[n];
    //cout<<count<<endl;
    mi=min(mi,count);
    for(int t=0;t<=n;t++){
      a[t]=b[t];
    }
  }
  cout<<mi<<endl;
  
  return 0;
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
vector<pii> q;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        int a,b; cin >> a >> b;
        q.emplace_back(a,b);
    }
}

bool isdisjoint(pii a, pii b){
    return ((a.second<=b.first) or (b.second<=a.first));
}

int solve(){
    sort(q.begin(),q.end());
    int ans=0;
    pii cur = q[0];
    for (int i = 0; i < M; i++)
    {
        if(isdisjoint(cur,q[i])){
            DBG(cur)
            DBG(q[i])
            ans++;
            cur = q[i];
        }
        else{
            cur.first = max(cur.first,q[i].first);
            cur.second = min(cur.second,q[i].second);
        }
    }
    cout << ans+1 << endl;
    
    return 0;
}   

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


Measured memory_bytes: 1400
#include <stdio.h>

int main(void) {
	int x,y,tmp;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0)break;
		else if(x<y)printf("%d %d\n",x,y);
		else printf("%d %d\n",y,x);
	}
	return 0;
}



Measured memory_bytes: 2020
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << '\n';
  exit(0);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  string s;
  cin >> s;
  string ss;
  rep(i, 5){
    ss += "hi";
    if(s == ss) Pr(1);
  }
  Pr(0);
}


Measured memory_bytes: 256
from collections import defaultdict
from math import log
N=int(input())
A=list(map(int,input().split()))
dict=defaultdict(int)
for a in A:
    dict[a]+=1
A.sort(reverse=True)
ans=0
for a in A:
    if dict[a]==0:
        continue
    c=int(log(a,2))
    b=~a & ((1<<(c+1)) -1)
    b+=1
    dict[a]-=1
    if dict[b]:
        ans+=1
        dict[b]-=1
    else:
        dict[a]+=1
print(ans)


Measured memory_bytes: 112468
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(I,N) for (int I=0; I<N; I++)
#define fornd(I,N) for (int I=N-1; I>=0; I--)
#define forab(I,A,B) for (int I=A; I<=B; I++)
#define forabd(I,A,B) for (int I=B; I>=A; I--)
#define FOREACH(I,A) for (__typeof__(A)::iterator I=A.begin(); I<A.end(); I++)
#define pb push_back
#define mp make_pair

typedef long long int ll;

const ll mod = 1000000007;

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

  double p = 0;
  if (N >= K) {
    p = (double)(N - K + 1) / N;
  }

  int lim = min(N, K - 1);
  forab(i, 1, lim) {
    double temp = 1.0 / N;
    int ct = i;
    while (ct < K) {
      ct *= 2;
      temp /= 2;
    }
    p += temp;
  }

  cout << fixed << setprecision(12) << p << endl;

  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const ll MOD = 998244353;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  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 b) const {
    mint res(1), a(*this);
    while (b) {
      if (b & 1) res *= a;
      a *= a;
      b >>= 1;
    }
    return res;
  }
  // 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;}


const int MAX_N = 3005;
mint dp[MAX_N][MAX_N];

int main2() {

  REP(i, MAX_N) REP(j, MAX_N) dp[i][j] = 0;

  int A = nextLong();
  int B = nextLong();
  int C = nextLong();
  int D = nextLong();


  dp[C][D] = 1;
  for (int a = C; a >= A; a--) {
    for (int b = D; b >= B; b--) {
      if (dp[a][b].x == 0) continue;
      dp[a-1][b] += mint(b) * dp[a][b];
      dp[a][b-1] += mint(a) * dp[a][b];
      dp[a-1][b-1] -= mint(b-1) * mint(a-1) * dp[a][b];
    }
  }

  ll ans = dp[A][B].x;
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 74200
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,x = inpl()
a = inpl()
ans = 0
for i in range(n-1):
    tmp = a[i+1] + a[i]
    if tmp > x:
        if a[i+1] >= tmp - x:
            a[i+1] -= tmp - x
            ans += tmp - x
        else:
            ans += a[i+1]
            a[i+1] = 0
            ans += a[i] - x
            a[i] = x
print(ans)

Measured memory_bytes: 15668
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long x, a, b;
  cin >> x >> a >> b;
  long foo = b - a;
  if (foo <= 0) puts("delicious");
  else if (foo <= x) puts("safe");
  else puts("dangerous");
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    int h,w;
    cin >> h >> w;

    char C[h][w];
    rep(i,h){
        rep(j,w){
            cin >> C[i][j];
        }
    }

    for(int i=0;i<2*h;i++){
        rep(j,w){
            cout << C[i/2][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define min(a,b) ((a)<(b) ? (a):(b))
#define max(a,b) ((a)>(b) ? (a):(b))

int gcd(int a, int b){
    while( b ){
        int m = a % b;
        a = b;
        b = m;
    }
    return a;
}

int lcm(int a, int  b){
    return (a*b)/gcd(a,b);
}

int isPrim(int a){
    if(a==1){
        return 0;
    }
    for(int i=2;i<=(a+1)/2;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}

long long mod_pow(long long x, long long n, long long mod){
    //xのn乗を計算するのにn乗を2進表記にして計算
    //x^22 = x^16 + x^4 + x^2
    long long ret=1;
    while(n>0){
        if(n%2==1){
            ret=(ret*x)%mod;//答えに付加
        }
        x=(x*x)%mod;//2乗
        n=n/2;
    }
    return ret;
}

struct VV{
    int x;
    int y;
    int z;
};

class LessInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        if(riLeft.x == riRight.x){
            return riLeft.y > riRight.y;
        }
        return riLeft.x > riRight.x;
        
    }
};

class indInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        return riLeft.x < riRight.x;
        
    }
};

struct XX{
    int zenbu=0;
    int kidoku=0;
};

class xxIntu {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        //第1条件
        if(riLeft.z != riRight.z){
            return riLeft.z < riRight.z;//<:昇順(小さい順)、>:降順(大きい順)
        }
        //第2条件
        return riLeft.x < riRight.x;
    }
};
bool operator< (const VV &riLeft, const VV &riRight){
    return riLeft.z < riRight.z;
};
/*bool operator> (const XX &riLeft, const XX &riRight){
    return riLeft.a > riRight.a;
};*/



int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //getline(cin, target);
    //cin >> x >> y;
    //ここから
    
    int N,K,X,Y;
    cin >> N>>K>>X>>Y;
    int ans=0;
    if(N<=K){
        ans=N*X;
    }else{
        ans=K*X;
        ans=ans+(N-K)*Y;
    }
    cout << ans << endl;
    
    //ここまで
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int a =N/1000;
        int b =N%1000/100;
        int c =N%100/10;
        int d =N%10;
        
        if(a==b && b==c && c==d){
            System.out.println("Yes");
        }else if(a==b && b==c){
            System.out.println("Yes");
        }else if(b==c && c==d){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21712
#!python3

from time import perf_counter
tick = perf_counter() + 1.92

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect

def resolve():
    G = 26
    it = map(int, sys.stdin.read().split())
    D = next(it)
    C = [next(it) for i in range(G)]
    S = [[next(it) for i in range(G)] for i in range(D)]
    L = [[-1] for i in range(G)]
    T = [0] * D

    def update(di, qi):

        score = 0
        t0 = T[di]
        score += S[di][qi]-S[di][t0]

        a1 = li = L[t0][:]
        ii = li.index(di)
        la = D if len(li)-1 == ii else li[ii+1]
        score -= C[t0] * (di-li[ii-1])*(la-di)
        li.pop(ii)

        a2 = li = L[qi][:]
        ii = bisect(li, di)
        li.insert(ii, di)
        la = D if len(li)-1 == ii else li[ii+1]
        score += C[qi] * (di-li[ii-1])*(la-di)

        return score, (a1, a2)

    U = 10
    def calc(i, j):
        score = S[i][j]
        for k in range(G):
            u = k - L[k][-1]
            score -= C[k] * (u + u + U) * U // 2
        score += C[k] * U * (i-L[j][-1])
        return score

    for di in range(D):
        if di + U >= D:
            U = D - di
        i, score = 0, calc(di, 0)
        for qi in range(1, G):
            x = calc(di, qi)
            if x > score:
                i, score = qi, x
        T[di] = i
        L[i].append(di)

    while perf_counter() < tick:
        di, qi = randrange(0, D), randrange(0, G)
        diff, swap = update(di, qi)
        if diff > 0:
            score += diff
            q0, T[di] = T[di], qi
            L[q0], L[qi] = swap

    print(*(i+1 for i in T), sep="\n")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 90284
#include<iostream>
using namespace std;
int main()
{
    int N,T,i,j,a=2000,b=2000;
    int c[200];
    int t[200];
    cin>>N>>T;
    for(i=0;i<N;i++)
    {
        cin>>c[i]>>t[i];
    }
    for(i=0;i<N;i++)
    {
        if(t[i]<=T)
        {
            if(c[i]<=a)
            {
                a=c[i];
                b=t[i];
            }
        }
    }
    if(a==2000 && b==2000)
    {
        cout<<"TLE"<<endl;
    }
    else
    {
        cout<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ky112233
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CRally solver = new CRally();
        solver.solve(1, in, out);
        out.close();
    }

    static class CRally {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] x = new int[n];
            for (int i = 0; i < n; i++) x[i] = in.nextInt();
            int sum = Arrays.stream(x).sum();
            int avg1 = sum / n;
            int avg2 = sum / n + 1;
            int num1 = Arrays.stream(x).map(i -> (i - avg1) * (i - avg1)).sum();
            int num2 = Arrays.stream(x).map(i -> (i - avg2) * (i - avg2)).sum();
            out.println(Math.min(num1, num2));
        }

    }
}



Measured memory_bytes: 26964
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
using namespace std;

int N, C, s[100000], t[100000], c[100000], record[200020];

int main(void) {
    cin >> N >> C;
    for (int i = 0; i < N; i++) cin >> s[i] >> t[i] >> c[i];
    for (int i = 0; i <= C; i++) {
        int tmp[200020] = {};
        for (int j = 0; j < N; j++) {
            if (c[j] == i) {
                tmp[s[j] * 2 - 1]++;
                tmp[t[j] * 2]--;
            }
        }
        for (int j = 1; j < 200002; j++)tmp[j] += tmp[j - 1];
        for (int j = 1; j < 200002; j++)if (tmp[j] > 0) record[j]++;
    }
    int max = -1;
    for (int j = 1; j < 200002; j++)if (max < record[j])max = record[j];
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 2944
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>

#define rep(i,n) for(int i = 0;i < (n);i++)
#define repp(i,j, n) for(int i = (j);i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define INF 1e9

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi s(n);
  int sum = 0;
  rep(i, n){
    cin >> s[i];
    sum += s[i];
  }
  sort(all(s));
  rep(i, n){
    if(sum%10 != 0){
      cout << sum << endl;
      return 0;
    }else{
      if(s[i]%10 != 0) sum -= s[i];
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 384
import Data.Int

main = getContents >>= print . solve 0 . map (read:: String->Int64) . tail . words

solve cnt (d:[]) = cnt
solve cnt (d:x:y:z)
  | x^2 + y^2 <= d^2 = solve (cnt + 1) (d:z)
  | otherwise = solve cnt (d:z)

Measured memory_bytes: 6788
import sys
import math
input = sys.stdin.readline
def prime_factor(n):
    factors = []
    while n%2==0:
        factors.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            factors.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        factors.append(n)
    return set(factors)


n=int(input())
L=list(map(int,input().split()))
val = L[0]
for i in range(1,n):
    val=math.gcd(val,L[i])
if val!=1:
    print('not coprime')
    sys.exit()
d={}
for i in range(n):
    factors = prime_factor(L[i])
    for j in factors:
        if j not in d.keys():
            d[j]=1
        else:
            print('setwise coprime')
            sys.exit()
print('pairwise coprime')



Measured memory_bytes: 174700
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; }
    public static void Main()
    {
        int[] s = new int[5];
        for (int i = 0; i < 5; i++) s[i] = NextInt();
        int ind = 0;
        int min = 10;
        for (int i = 0; i < 5; i++)
        {
            if (s[i] % 10 == 0) continue;
            if (s[i] % 10 < min) { min = s[i] % 10; ind = i; }
        }
        int ans = 0;
        for (int i = 0; i < 5; i++)
        {
            if (i == ind) ans += s[i];
            else
            {
                if (s[i] % 10 == 0) ans += s[i];
                else ans += (s[i] / 10 + 1) * 10;
            }
        }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13268