akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
const int MAX = 1000000;
void divide_x(int x, int y);
void divide_y(int x, int y);

int main(){
    int A, B, K;

    // input 
    cin >> A >> B >> K;

    if(K % 2 == 0){  // Kが偶数の時K/2回ずつ交換を行う
        for(int i = 0; i < K / 2; i++){
            A /= 2;
            B += A;
            B /= 2;
            A += B;
        }
    }
    else{  // Kが偶数の時K/2回ずつ交換を行い，1回交換を行う
        for(int i = 0; i < K / 2; i++){
            A /= 2;
            B += A;
            B /= 2;
            A += B;
    }
        A /= 2;
        B += A;
    }

    // output 
    cout << A << ' ' << B << endl;
	return 0;
}

// xを2で割った商にし，その商をyに足す
void divide_x(int x, int y){ 
    x /= 2;
    y += x;
    cout << x << ' ' << y << endl;
}

// xをyで割った商にし，その商をxに足す
void divide_y(int x, int y){
    y /= 2;
    x += y; 
    cout << x << ' ' << y << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
// template<class T> T gabs(const T& x) { return max(x, -x); }
// #define abs gabs

int main() {
    i64 n, m;
    cin >> n >> m;
    if (n >= m / 2) {
        cout << m / 2 << endl;
    } else {
        i64 x = m - 2 * n;
        cout << n + x / 4 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

N,C=map(int,input().split())
imos=[0 for i in range(0,10**5+2)]
bangumi={i:[] for i in range(1,C+1)}
for i in range(0,N):
    s,t,c=map(int,input().split())
    imos[s]+=1
    imos[t+1]+=-1
    bangumi[c].append((s,t))

ans=list(accumulate(imos))
for i in range(1,C+1):
    bangumi[i].sort()

for i in range(1,C+1):
    if len(bangumi[i])>1:
        for j in range(0,len(bangumi[i])-1):
            s,t=bangumi[i][j]
            u,v=bangumi[i][j+1]
            if t==u:
                ans[t]-=1

print(max(ans))

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll K, A, B;
    cin >> K >> A >> B;
    
    ll ans = 0;
    if(A+1 <= K) {
        if(A+2 < B) {
            if((K-A-1)%2 == 0) ans = B + (B-A) * ((K-A-1) / 2);
            else ans = B + (B-A) * ((K-A-1) / 2) + 1;
        }
        else ans = K + 1;
    }
    else ans = K + 1;

    PR(ans);
    
    return 0;
}

/*

[1] x -> x+1
[2] x -> x-A
[3] x -> x+B

*/

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

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

    string S_copy = S;

    size_t c;
    while ((c = S_copy.find_first_of("A")) != string::npos) {
        S_copy.erase(c, 1);
    }

    if (S_copy != "KIHBR") {
        cout << "NO" << endl;
        return 0;
    }

    vector<ll> A_cnt(6, 0);
    ll idx = 0;
    rep(i, S.length()) {
        if (S[i] == 'A') {
            A_cnt[idx]++;
        } else {
            idx++;
        }
    }

    vector<ll> A_ans = {1, 0, 0, 1, 1, 1};

    rep(i, 6) {
        if (A_cnt[i] > A_ans[i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 3544
// https://atcoder.jp/contests/abc150/tasks/abc150_c

#include <iostream>
#include <iomanip>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cmath>

using namespace std;

int factorial(int n)
{
    if(n == 1)
    {
        return 1;
    }
    return n * factorial(n - 1);
}

int main(int argc, const char* argv[])
{
    int n;
    cin >> n;

    vector<int> p(n), q(n);

    for(int i = 0; i < n; ++i)
    {
        cin >> p[i];
    }

    for(int i = 0; i < n; ++i)
    {
        cin >> q[i];
    }

    int count = factorial(n);
    vector<vector<int>> pattern(count, vector<int>(n));

    // パターンを昇順列挙
    vector<int> master(n);
    for(int i = 0; i < n; ++i)
    {
        master[i] = i + 1;
    }
    {
        int i = 0;
        do {
            pattern[i] = master;
            i++;
        }while(next_permutation(master.begin(), master.end()));
    }

    // 何番目と一致するかを判定
    int pi = lower_bound(pattern.begin(), pattern.end(), p) - pattern.begin();
    int qi = lower_bound(pattern.begin(), pattern.end(), q) - pattern.begin();

    cout << abs(pi - qi) << endl;

    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll cc = b / c - (a - 1) / c, dd = b / d - (a - 1) / d;
	ll x = c / __gcd(c, d) * d, cd = b / x - (a - 1) / x;
	cout << (b - a + 1) - cc - dd + cd << endl;
}


Measured memory_bytes: 256
H,W = [ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(10) ]

from copy import deepcopy

for _ in range(19):
  li2 = deepcopy(li)
  for i in range(10):
    for j in range(10):
      for k in range(10):
        li2[i][j] = min( li2[i][j] , li[i][k]+li[k][j] )
  li = li2

gr = []
for i in range(H):
  gr.extend([ int(it) for it in input().split() ])
  
import collections  as cols
ccc = cols.Counter(gr)
cost = 0
for k,v in ccc.items():
  if (k!=-1):
    cost += v*li[k][1]
print ( cost ) 

Measured memory_bytes: 45092
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;


class Solution{

public:
    long long ways(const vector<int>& nums, int A){

        int n = nums.size();
        vector<vector<vector<long long>>> dp(n, vector<vector<long long>>(n + 1, vector<long long>(n * A + 1, -1)));

        long long res = 0;
        for(int i = 1; i <= n; i ++)
            res += solve(nums, 0, i, i * A, dp);
        return res;
    }

private:
    long long solve(const vector<int>& nums, int index, int left, int N,
                    vector<vector<vector<long long>>>& dp){

        if(index == nums.size())
            return N == 0 && left == 0 ? 1 : 0;
        if(dp[index][left][N] != -1) return dp[index][left][N];

        long long res = solve(nums, index + 1, left, N, dp);
        if(nums[index] <= N && left) res += solve(nums, index + 1, left - 1, N - nums[index], dp);
        return dp[index][left][N] = res;
    }
};

int main() {

//    vector<int> nums1 = {7, 9, 8, 9};
//    cout << Solution().ways(nums1, 8) << endl;
//    // 5
//
//    vector<int> nums2 = {6, 6, 9};
//    cout << Solution().ways(nums2, 8) << endl;
//    // 0
//
//    vector<int> nums3 = {3, 6, 2, 8, 7, 6, 5, 9};
//    cout << Solution().ways(nums3, 5) << endl;
//    // 19
//
//    vector<int> nums4(33, 3);
//    cout << Solution().ways(nums4, 3) << endl;
//    // 8589934591

    int N, A;
    scanf("%d%d", &N, &A);

    vector<int> nums(N);
    for(int i = 0; i < N; i ++) scanf("%d", &nums[i]);
    printf("%lld\n", Solution().ways(nums, A));

    return 0;
}


Measured memory_bytes: 53872
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int n, m;
  cin >> n >> m;

  ll total = (n + m) * (n + m - 1) / 2;

  ll ans = total - n * m;

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt=0,a;
  cin>>n;
  int c[8]={};
  for(int i=0;i<n;i++){
    cin>>a;
    if(a<3200)
      c[a/400]=1;
    else
      cnt++;
  }
  int b=0;
  for(int i=0;i<8;i++){
    b+=c[i];
  }
  cout<<(b==0?1:b)<<" "<<b+cnt;
}

Measured memory_bytes: 256
using System;

public class ITP1_8_B
{
  static void Main()
  {
    while (true)
    {
      char[] input = Console.ReadLine().ToCharArray();
      if (input[0] == '0') break;
      int sum = 0;
      for (int i = 0; i < input.Length; i++)
      {
        sum += (int)Char.GetNumericValue(input[i]);
      }
      Console.WriteLine(sum);
    }
  }
}

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=((ll)n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=((ll)a);i<((ll)n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vl a(n); cin>>a;
    map<ll,ll> mp,mp2;
    for(ll i=0;i<n;i+=2)mp[a[i]]++;
    for(ll i=1;i<n;i+=2)mp2[a[i]]++;
    ll mv=0,mv2=0,mc=0,mc2=0;
    for(auto&p:mp){
        ll v,c;tie(v,c)=p;
        if(chmax(mc,c))mv=v;
    }
    for(auto&p:mp2){
        ll v,c;tie(v,c)=p;
        if(chmax(mc2,c))mv2=v;
    }

    ll ans=LINF;
    if(mv!=mv2){
        chmin(ans, n-mc-mc2);
    }else{
        ll tmp=0;
        
        tmp=mc;
        mc=0;
        for(auto&p:mp){
            ll v,c;tie(v,c)=p;
            if(v!=mv)chmax(mc,c);
        }
        chmin(ans, n-mc-mc2);
        mc=tmp;
        tmp=mc2;
        mc2=0;
        for(auto&p:mp2){
            ll v,c;tie(v,c)=p;
            if(v!=mv2)chmax(mc2,c);
        }
        chmin(ans, n-mc-mc2);
        mc2=tmp;
    }
    puta(ans);
    return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    int n;
    cin >> n;
    vector<double> x;
    for(int i=0; i<n; i++){
        double tmp_x;
        cin >> tmp_x;
        x.push_back(tmp_x);
    }
    // 平均
    double mean = 0;
    for(int i=0; i<n; i++){
        mean += x[i];
    }
    mean /= double(n);

    int fl = floor(mean);
    int ce = ceil(mean);

    int ans_fl = 0;
    int ans_ce = 0;
    for(int i=0; i<n; i++){
        ans_fl += (x[i] - fl) * (x[i] - fl);
        ans_ce += (x[i] - ce) * (x[i] - ce);
    }

    cout << min(ans_ce, ans_fl);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	int m;
	int[] a;
	int oddcount, evencount;
	
	int calc(int oc, int ec, int s) {
		if (oc == 0 && ec == 0) {
			if (s % 10 == 0) return 1;
			else return 0;
		} else {
			int ans = 0;
			if (oc > 0) {
				for (int i = 0; i < m; i++) {
					ans += calc(oc-1, ec, s+a[i]);
				}
			} else {
				for (int i = 0; i < m; i++) {
					if (2*a[i] < 10) {
						ans += calc(oc, ec-1, s+2*a[i]);
					} else {
						ans += calc(oc, ec-1, s+1+2*a[i]-10);
					}
				}
			}

			return ans;
		}
	}
	
	void run() {
		int n = sc.nextInt(); 
		String ID = sc.next(); 
		char[] id = ID.toCharArray();
		m = sc.nextInt();
		a = new int[m];
		for (int i = 0; i < m; i++)
			a[i] = sc.nextInt();
		
		oddcount = evencount = 0;
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			if (id[n-i] == '*') {
				if (i % 2 == 0) evencount++;
				else oddcount++;
			} else {
				int t = Integer.parseInt(""+id[n-i]);
				if (i % 2 == 0) {
					if (2*t < 10) sum += 2*t;
					else sum += 1+2*t-10;
				} else {
					sum += t;
				}
			}
		}
		
		out.println(calc(oddcount, evencount, sum));
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

bool IsTriangle(int a, int b, int c)
{
	return (a != b) && (a != c) && (b != c) && ((a + b) > c) && ((b + c) > a) && ((c + a) > b);
}

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

	vector<int> L(N);
	rep(i, N) cin >> L[i];

	if (N <= 2)
	{
		cout << 0 << endl;
		return 0;
	}

	int ans = 0;
	int i = 0, j = 1, k = 2;
	for (;;)
	{
		if (IsTriangle(L[i], L[j], L[k])) ans++;

		k++;
		if (k == N)
		{
			j++;
			if (j == (k - 1))
			{
				i++;
				if (i == (j - 1))
				{
					break;
				}
				else
				{
					j = i + 1;
					k = j + 1;
				}
			}
			else
			{
				k = j + 1;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3636
n,k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7
# s=正の数、t=負の数
s,t = [], []
for a in A:
  if a<0:
    t.append(a)
  else:
    s.append(a)

S = len(s)
T = len(t)
ok = False
if (S>0):
  if n==k:
    # すべての負の数をペアにできる
    ok = T%2==0
  else:
    # 負の数は考慮しない
    ok = True
else:
  # kが偶数個
  ok = (k%2==0)

ans = 1
if not ok:
  A.sort(key=lambda x: abs(x))
  for i in range(k):
    ans *= A[i]
    ans %= MOD
else:
  s.sort()
  t.sort(reverse=True)
  if k%2==1:
    ans *= s.pop()
    ans %= MOD

  p = []
  while len(s) >= 2:
    x = s.pop()
    x *= s.pop()
    p.append(x)

  while len(t) >= 2:
    x = t.pop()
    x *= t.pop()
    p.append(x)

  p.sort(reverse=True)
  for i in range(k//2):
    ans *= p[i]
    ans %= MOD

print(ans % MOD)

Measured memory_bytes: 114508
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def combinations_count(n, r):
        if n > 1:
            return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        else:
            return 0

    n = ni()
    a = na()

    a.sort()

    max_ai = max(a)
    idx = bisect.bisect_left(a, max_ai // 2)

    r = -1

    r = a[max(0, idx - 1)]
    if a[idx] != max_ai:
        r = a[idx] if abs(a[idx] - max_ai / 2) < abs(r - max_ai / 2) else r

    print(max_ai, r)


if __name__ == '__main__':
    main()


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

using ll = long long int;
constexpr int IINF = INT_MAX;

string s;
vector<vector<int> > dp;

bool solve(){
    int n;
    cin >> s;
    s.insert(s.begin(),'0');
    n = s.size();
    dp.resize(n+1,vector<int>(2,IINF/2));
    dp[0][0] = 0;
    for(int i=0;i<n;i++){
        int D = s[i]-'0';
        dp[i+1][0] = min(dp[i][0]+D, dp[i][1]+(10-D));
        dp[i+1][1] = min(dp[i][0]+D+1, dp[i][1]+(9-D));
    }
    cout << dp[n][0] << endl;
    return true;
}

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

Measured memory_bytes: 55940
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    for(int i=0;i<=s.size();i++){
        if(s[i]=='C'){
            for(int j=i+1;j<=s.size();j++){
                if(s[j]=='F'){
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/


#include <stdio.h>

using namespace std;

int main(){
    int N;
    scanf("%d", &N);
    int A[N-1], B[N];
    for(int i = 0; i<N-1; i++){
        scanf("%d", &A[i]);
        B[i]= 0;
    }
    B[N-1]= 0;
    for(int i = 0; i<N-1; i++){
        B[A[i]-1]+=1;
    }
    for(int i=0; i<N; i++){
        printf("%d\n", B[i]);
    }
    return 0;
}

Measured memory_bytes: 3292
//1d reversi new method
#include <bits/stdc++.h>
using namespace std;
long long n,m,k,tmp,sum=0;
string s;
char r1,r2,op;
int main(){
	ios::sync_with_stdio(0);
	getline(cin,s);
	//scanf("\n");
	long long cntb=0,cntw=0;
	op=s[0];
	for (int i=1;i<s.length();i++){
		if (s[i]!=op) sum++;
		op=s[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3684
o=998244353
f=[1]
for i in range(1,2500100):f.append(f[-1]*i%o)
def c(n,k):return f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o)
n,m=map(int,input().split())
w=3*m
u=n-1
a=c(w+u,u)-n*c(n+m-2,u)
if u>m:
 for i in range(m+1,min(w,n)+1):
  if w-i+1&1:a-=c(n,i)*c((w-i)//2+u,u)
print(a%o)

Measured memory_bytes: 107272
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define INF 100000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;


int main() {
    
    int n,x,a,b,j;
    string ans;
    x = 0;
    j = 0;
    
    cin >> n;
    rep(i,n){
        cin >> a >> b;
        if(a==b){
            x++;
        }else{
            x = 0;
        }
        if(x>=3){
            j=1;
        }
    }
    if(j==1){
        ans = "Yes";
    }else{
        ans = "No";
    }

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

Measured memory_bytes: 3624
def main():
    buf = input()
    k = int(buf)

    n = 50
    a = []
    for i in range(n):
        a.append(n-i-1)
    p = k // 50
    for i in range(n):
        a[i] += p
    k %= 50
    i = 0
    while k > 0:
        a[i] += 1
        k -= 1
        i += 1
    print(n)
    print(' '.join([str(x) for x in a]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
def winpoints(teams)   #   -> [[team1,point1],[team2,point2], ...]
  tp = teams.map{|team,win,lose,draw| [team, 3*win+1*draw]}
  return tp.sort{|a,b| b[1]<=>a[1]}
end

def main
  if true then
    fh=STDIN
  else
    fh=open("in1_0124.txt")
  end

  first=true
  while true do
    n = fh.gets.chomp.to_i
    break if n==0
    teams = []
    0.upto(n-1){|i|
      teams.push(fh.gets.chomp.split.map{|x| (x=~ /^\d+$/) ? x.to_i : x})
    }
    if first then
      first=false
    else
      puts
    end
    winpoints(teams).each{|team,points|
      printf("%s,%d\n", team, points)
    }
  end

end

if $0 == __FILE__ then
  main
end

Measured memory_bytes: 8784
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int mod =1000000007;
const double PI = acos(-1);
ll lcm(ll x, ll y) { return x / __gcd(x, y) * y; }
int main(){
   int n;cin>>n;
   ll a[n];
   rep(i,n)cin>>a[i];
   ll l =a[0];
   rep(i,n){
       l= lcm(l,a[i]);
   }
   cout<<l<<endl;
}


Measured memory_bytes: 3652
import Control.Monad
import Data.List

main = do
    n <- readLn
    s <- replicateM n getLine
    m <- readLn
    t <- replicateM m getLine
    putStrLn . show $ resolve s t

resolve:: [String] -> [String] -> Int
resolve s t = max 0 (maximum (piyo s t))

hoge:: Int -> [String] -> String -> Int
hoge n [] a = n
hoge n (t:ts) a
    | t == a = hoge (n + 1) ts a
    | otherwise = hoge n ts a

fuga:: [String] -> [String] -> [Int]
fuga s t = map (hoge 0 s) t

piyo s t = map (\x -> (fst x) - (snd x)) $ zip (fuga s s) (fuga t s)


Measured memory_bytes: 636
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;

signed main()
{
	ios::sync_with_stdio(false);
	int n,a,b;
	cin>>n>>a>>b;
	cout<<n/(a+b)*a+min(a,n%(a+b))<<endl;
	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define v vector
#define vi vector<int>
#define vi2 vector<vi>
#define vl vector<long long>
#define vl2 vector<vl>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

/*int main(){
    unsigned long long n, ans = 1, sum;
    bool zero=false;
    cin >> n;
    long long a[n];
    rep(i,n) {
        cin >> a[i];
        if(a[i] == 0) {
            zero=true;
            break;
        }
    }
    if(zero) {
        cout << 0 << endl;
        return 0;
    }
    rep(i,n) {
        sum = to_string(ans).length();
        if(to_string(a[i]).length()+sum - 2>18){
            cout << -1 << endl;
            return 0;
        }else if(ans*a[i]>1000000000000000000){
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
}*/

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

Measured memory_bytes: 3728
from math import sqrt

N,M = map(int,input().split())

divisor = set([])
for i in range(1,int(sqrt(M))+1):
	if M % i == 0:
		if i <= int(M / N):
			divisor.add(i)
		if (M // i) <= int(M / N):
			divisor.add(M // i)

print(max(divisor))


Measured memory_bytes: 3068
#include <iostream>

using namespace std;

bool IsPalindrome(int n) {
    int N = n;
    int a[10];
    int i = 0;
    while(n > 0) {
        a[i++] = n % 10;
        n /= 10;
    }
    if (a[0] == a[4] && a[1] == a[3]) {
        //cout << N << endl;
        return true;
    } else {
        return false;
    }
}

int main() {
    int a, b;
    cin >> a >> b;
    int count = 0;
    for (int i = a; i <= b; i++) {
        if (IsPalindrome(i)) {
            count++;
        }
    }
    cout << count << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc093/tasks/abc093_b

int main() {
    int a, b, k; cin >> a >> b >> k;
    set<int> ans;

    for (int i = a; i < a+k; i++) {
        if (i > b) break;
        ans.insert(i);
    }
    for (int i = b; i > b-k; i--) {
        if (i < a) break;
        ans.insert(i);
    }

    for (int t : ans) {
        cout << t << "\n";
    }



    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
typedef long long int ll;

using namespace std;

int main(int argc, char const *argv[]) {
    ll MOD = 1000000007LL;
    int H, W;
    cin >> H >> W;
    vector<string> grid(H);
    vector<vector<ll>> values(H, vector<ll>(W));
    for (int i = 0; i < H; i++) {
        cin >> grid[i];
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '#') {
                values[i][j] = 0LL;
                continue;
            }
            if (i == 0 && j == 0) {
                values[i][j] = 1LL;
            } else if (i == 0) {
                values[i][j] = values[i][j - 1];
            } else if (j == 0) {
                values[i][j] = values[i - 1][j];
            } else {
                values[i][j] = values[i - 1][j] + values[i][j - 1];
                values[i][j] = values[i][j] % MOD;
            }
            // cout << i << j << values[i][j] << endl;
        }
    }
    cout << values[H - 1][W - 1] << endl;
    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N;
    double T, A;
    double  H;
    vector<pair<double, int>> data;
    
    cin >> N;
    cin >> T >> A;
    
    for(int i = 1; i <= N; i++){
        cin >> H;
        data.push_back(make_pair(abs(A - (T - H * 0.006)),i));
    }
    
    sort(data.begin(), data.end());
    
    cout << data.at(0).second << endl;
    
}


Measured memory_bytes: 256
// pythonだとTLEになったのでgoでやる
// 初めてのsortのbinary search
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"reflect"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	a, b, q := nextInt(), nextInt(), nextInt()
	var INF int
	INF = 1
	for i := 0; i < 18; i++ {
		INF *= 10
	}
	s, t := make([]int, a+2), make([]int, b+2)
	s[0], s[a+1] = -INF, INF
	t[0], t[b+1] = -INF, INF
	for i := 1; i < a+1; i++ {
		s[i] = nextInt()
	}
	for i := 1; i < b+1; i++ {
		t[i] = nextInt()
	}
	for i := 0; i < q; i++ {
		target := nextInt()
		// Searchにわたすの、スライスの長さだけでいいの？スライス自身は必要じゃないの？
		y := float64(sort.Search(len(s), func(j int) bool { return s[j] > target }))
		if y == float64(a+1) {
			y -= 1
		} else if y == 1 {
			y += 1
		}
		x := y - 1
		w := float64(sort.Search(len(t), func(j int) bool { return t[j] > target }))
		if w == float64(b+1) {
			w -= 1
		} else if w == 1 {
			w += 1
		}
		z := w - 1
		result1 := math.Abs(float64(target-s[int(x)])) + math.Abs(float64(s[int(x)]-t[int(w)]))
		result2 := math.Abs(float64(target-s[int(x)])) + math.Abs(float64(s[int(x)]-t[int(z)]))
		result3 := math.Abs(float64(target-s[int(y)])) + math.Abs(float64(s[int(y)]-t[int(w)]))
		result4 := math.Abs(float64(target-s[int(y)])) + math.Abs(float64(s[int(y)]-t[int(z)]))
		result5 := math.Abs(float64(target-t[int(z)])) + math.Abs(float64(t[int(z)]-s[int(x)]))
		result6 := math.Abs(float64(target-t[int(z)])) + math.Abs(float64(t[int(z)]-s[int(y)]))
		result7 := math.Abs(float64(target-t[int(w)])) + math.Abs(float64(t[int(w)]-s[int(x)]))
		result8 := math.Abs(float64(target-t[int(w)])) + math.Abs(float64(t[int(w)]-s[int(y)]))
		var results = []float64{result1, result2, result3, result4, result5, result6, result7, result8}
		sort.Float64s(results)
		result0 := int(results[0])
		fmt.Fprintln(out, result0)
		
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define eps 1e-8
ll n,k,a[200005],q,ans;
int main()
{  cin>>n;
   for(int i=1;i<=n;i++)cin>>a[i];
   int sum=a[1];
   for(int i=2;i<=n;i++)
   {  sum=sum^a[i];
   }
   for(int i=1;i<=n;i++)
   printf("%d ",sum^a[i]);


}

Measured memory_bytes: 5252
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

typedef pair<int, int> P;
int N;
vector<int> A;
const int MONOID = 0;
ll f(ll x, ll y) {
  return x + y;
}

void add(ll x, ll y) {
  ll i = x + N - 1;
  A.at(i) += y;
  while (i > 0) {
    i = (i-1)/2;
    A.at(i) = f(A.at(i*2+1), A.at(i*2+2));
  }
}

ll findRec(ll x, ll y, ll n, ll l, ll r) {
  if (r <= x || y <= l) return MONOID;
  if (x <= l && r <= y) return A.at(n);
  return f(
    findRec(x, y, n*2+1, l, (l+r)/2),
    findRec(x, y, n*2+2, (l+r)/2, r)
  );
}

ll find(ll x, ll y) {
  return findRec(x, y+1, 0, 0, N);
}

int main() {
  int n,q; cin >> n >> q;
  N = 1;
  while (N < n) N *= 2;
  vector<int> C(n);
  A.assign(3*n, 0);
  loop(i,0,n) cin >> C[i];

  vector<int> points[n+1];
  vector<int> prev(n+1, -1);
  loop(i,0,n) {
    int c = C[i];
    if (prev[c] != -1) {
      points[prev[c]].emplace_back(i);
    }
    prev[c] = i;
  }

  vector<P> qs[n+1];
  loop(i,0,q) {
    int l,r;cin >> l >> r;
    l--;r--;
    qs[l].emplace_back(r, i);
  }

  vector<int> ans(q, 0);
  for (int x=n-1; x>=0; x--) {
    for (auto &&y: points[x]) {
      add(y, 1);
    }
    for (auto q: qs[x]) {
      ans[q.second] = q.first-x+1-find(0, q.first);
    }
  }
  loop(i,0,q) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 63844
let get_2_ints () = Scanf.scanf "%d %d " (fun u v -> u,v)

let () =
  let (s,c) = get_2_ints ()
  in
  (
    let c_left = c-s*2 in
    if c_left >= 0 then (
      s + c_left / 4
    )else(
      let s_true = c / 2
      in s_true
    )
  )
  |> string_of_int |> print_endline

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct q{
	int s,c;
};
q a[6];
int main(){
	int len,n,i,j,k,x,y,z;
	cin>>len>>n;
	for(i=1;i<=n;i++){
		cin>>a[i].s>>a[i].c;
	}
	switch(len){
		case 1:
			x=-1;
			for(i=1;i<=n;i++){
				if(a[i].c!=x&&x!=-1){
					cout<<"-1";
					return 0;
				}else{
					x=a[i].c;
				}
			}
			cout<<max(0,x);
			break;
		case 2:
			x=y=-1;
			for(i=1;i<=n;i++){
				if(((a[i].c!=x&&x!=-1)||a[i].c==0)&&a[i].s==1){
					cout<<"-1";
					return 0;
				}else{
					if(a[i].s==1) x=a[i].c;
				}
				if(a[i].c!=y&&y!=-1&&a[i].s==2){
					cout<<"-1";
					return 0;
				}else{
					if(a[i].s==2) y=a[i].c;
				}
			}
			cout<<max(1,x)<<max(0,y);
			break;
		case 3:
			x=y=z=-1;
			for(i=1;i<=n;i++){
				if(((a[i].c!=x&&x!=-1)||a[i].c==0)&&a[i].s==1){
					cout<<"-1";
					return 0;
				}else{
					if(a[i].s==1) x=a[i].c;
				}
				if(a[i].c!=y&&y!=-1&&a[i].s==2){
					cout<<"-1";
					return 0;
				}else{
					if(a[i].s==2) y=a[i].c;
				}
				if(a[i].c!=z&&z!=-1&&a[i].s==3){
					cout<<"-1";
					return 0;
				}else{
					if(a[i].s==3) z=a[i].c;
				}
			}
			cout<<max(1,x)<<max(0,y)<<max(0,z);
			break;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 15;
int arr[MAX][MAX];
int main()
{
	boost;
	int n, m, x, i, j;
	cin >> n >> m >> x;
	fo(i, 0, n) {
		foe(j, 0, m)
		cin >> arr[i][j];
	}
	int ans = inf;
	for(i = 0; i < (1 << n); i++) {
		int cnt[MAX];
		memset(cnt, 0, sizeof cnt);
		int cost = 0;
		for(int j = 0; j < n; j++) {
			if(i & (1 << j)) {
				cost += arr[j][0];
				for(int k = 1; k <= m; k++)
				cnt[k] += arr[j][k];
			}
		}
		bool ok = 1;
		for(int j = 1; j <= m; j++) {
			if(cnt[j] < x) {
				ok = 0;
				break;
			}
		}
		if(ok) ans = min(ans, cost);
	}
	cout << (ans == inf ? -1 : ans);
}


Measured memory_bytes: 3652
import sys
input = sys.stdin.readline
n,m = input().split()
n = int(n)
m = int(m)
list = [[0,0]] * n
for i in range(n):
    a,b = input().split()
    list[i] = [int(a),int(b)]
list.sort()
k = 0
ans = 0
while m > 0:
    if m > list[k][1]:
        m -= list[k][1]
        ans += (list[k][0] * list[k][1])
    else:
        ans += (list[k][0] * m)
        m = 0
    k += 1
print(ans)

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

ll n,a,b;

int main()
{
    scanf("%lld%lld%lld",&a,&b,&n);
    n=min(n,b-1);
    printf("%lld",a*n/b-n/b*a);
    return 0;
}

Measured memory_bytes: 3788
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            String s = in.next();
            String s2 = in.next();
            String s3 = in.next();
            StringBuilder sb = new StringBuilder();
            sb.append(s.charAt(0));
            sb.append(s2.charAt(0));
            sb.append(s3.charAt(0));
            System.out.println(sb.toString().toUpperCase());
        }
    }
}


Measured memory_bytes: 21332
#include <cstdio>
int main() {
	int E,Y;
	scanf("%d %d",&E,&Y);
	if(E==0) {
		if(Y<=1911) printf("M%d\n",Y-1868+1);
		else if(Y<=1925) printf("T%d\n",Y-1912+1);
		else if(Y<=1988) printf("S%d\n",Y-1926+1);
		else printf("H%d\n",Y-1989+1);
	}else if(E==1) {
		printf("%d\n",1868+(Y-1));
	}else if(E==2) {
		printf("%d\n",1912+(Y-1));	
	}else if(E==3) {
		printf("%d\n",1926+(Y-1));	
	}else {
		printf("%d\n",1989+(Y-1));	
	}
}


Measured memory_bytes: 2760
def isprime(n):
    judgement = True
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            judgement = False
            break
    return judgement


x = int(input())

while True:
    if isprime(x):
        answer = x
        print(answer)
        exit()
    else:
        x += 1


Measured memory_bytes: 2940
#include"bits/stdc++.h"
using namespace std;
int main()
{
    int a, b;
    cin >> a;
    cin >> b;

    int sum = a + b;
    if (sum == 3) {
        cout << 3 << endl;
    }
    else if (sum == 4) {
        cout << 2 << endl;
    }
    else {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
program main
  implicit none
  integer(8) i,L,R,dist,ans,j
  ans = 2020
  read(*, *) L, R
  dist = min(2019,R-L)
  do i = L,L+dist-1
    do j = i+1,L+dist
      ans = min(ans,mod(i*j,2019))
    end do
  end do

  write(*,*) ans
end program main


Measured memory_bytes: 256
num_list = [int(i) for i in input().split()]
max_num = max(num_list)
res = 0
for i,n in enumerate(num_list):
  while max_num >= num_list[i]+2:
    num_list[i] +=2
    res +=1
min_num = min(num_list)
mins = len([x for x in num_list if x==min_num])
if mins==3:
  print(res)
elif mins==2:
  print(res+1)
else:
  print(res+2)

Measured memory_bytes: 3064
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, m, t; rd(n, m, t);
  auto r=readln.split.to!(int[]);
  foreach(ref e; r) e--;
  auto d=new long[][](n, n);
  const long inf=1_000_000_000_000_000_000;
  foreach(i; 0..n) fill(d[i], inf);
  foreach(i; 0..n) d[i][i]=0;
  foreach(_; 0..m){
    int a, b; long c; rd(a, b, c);
    a--; b--;
    d[a][b]=d[b][a]=c;
  }

  foreach(k; 0..n){
    foreach(i; 0..n){
      foreach(j; 0..n){
        d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
      }
    }
  }

  auto dp=new long[][](t, (1<<t));
  foreach(i; 0..t) fill(dp[i], inf);
  foreach(i; 0..t) dp[i][0]=0;
  foreach(i; 0..t) dp[i][1<<i]=0;
  foreach(i; 0..(1<<t)){
    foreach(tg; 0..t)if(!(i&(1<<tg))){
      foreach(j; 0..t)if(i&(1<<j)){
        dp[tg][i|(1<<tg)]=min(dp[tg][i|(1<<tg)], 
                              dp[j][i]+d[r[j]][r[tg]]);
      }
    }
  }
  
  long mi=inf;
  foreach(i; 0..t) mi=min(mi, dp[i][(1<<t)-1]);
  writeln(mi);

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {
	private static long M = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		long[] xs = new long[n];
		long[] ys = new long[m];

		for (int i = 0; i < n; i++) {
			xs[i] = sc.nextInt();
		}

		for (int i = 0; i < m; i++) {
			ys[i] = sc.nextInt();
		}

		long xa = 0;
		for (int i = 0; i < n; i++) {
			xa += i * xs[i] - (n - i - 1) * xs[i];
			xa %= M;
		}

		long ya = 0;
		for (int i = 0; i < m; i++) {
			ya += i * ys[i] - (m - i - 1) * ys[i];
			ya %= M;
		}

		System.out.println((xa * ya) % M);
	}
}


Measured memory_bytes: 94104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char a[10],b[10],c[10];

        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        int i,j;
        gets(a);
        gets(b);
        int len=strlen(b);
        for (i=0,j=len-1;i<len,j>=0 ;i++,j--)
        {
            c[i]=b[j];
        }
        if(strcmp(a,c)==0)
            printf("YES\n");
        else
            printf("NO\n");
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
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;
}

int main(void)
{
    ll a, b, k;
    cin >> a >> b >> k;

    ll tk = a - k;
    ll ak = a + b - k;

    if(tk < 0){
        if(ak < 0){
            ak = 0;
        }
        cout << 0 << " " << ak << endl;
    }
    else{
        cout << tk << " " << b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<unordered_map>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF=2e15;
typedef pair<ll,ll> P;

ll N;
ll match[1010][1010];
vector<ll> edges[1001001];
bool visited[1001001];
bool tmp[1001001];
vector<ll> sorted;
ll longest[1001001];
bool f=false;
void Visit(ll n,ll cost){
    // longest[n]=max(longest[n],cost);
    if(tmp[n]){
        cout<<"-1";
        f=true;
        return;
    }else if(!visited[n]){
        tmp[n]=true;
        for(auto o:edges[n]){
            Visit(o,cost+1);
            if(f)return;
        }
        tmp[n]=false;
        visited[n]=true;
        sorted.push_back(n);
    }
}
ll Calc(ll n){
    if(longest[n]!=0){
        return longest[n];
    }
    for(auto o:edges[n]){
        longest[n]=max(longest[n],Calc(o)+1);
    }
    return longest[n];
}
int main(){
    cin>>N;
    for(ll i=0;i<N;i++){
        ll prev;
        for(ll j=0;j<N-1;j++){
            ll opo;
            cin>>opo;
            opo--;
            ll now=min(i,opo)*N+max(i,opo);
            if(j!=0){
                edges[prev].push_back(now);
            }
            prev=now;
        }
    }
    for(ll i=0;i<N;i++){
        for(ll j=i+1;j<N;j++){
            ll now=i*N+j;
            if(!visited[now] && !tmp[now]){
                Visit(now,0);
            }
            if(f)return 0;
        }
    }
    ll ans=0;
    for(ll i=sorted.size()-1;i>=0;i--){
        ll v=sorted[i];
        if(longest[v]==0)
            ans=max(ans,Calc(v));
    }
    cout<<ans+1;
    return 0;
}

Measured memory_bytes: 54768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	multiset<int, greater<int>> st;
	rep(i, (1 << n)) {
		int a;
		cin >> a;
		st.insert(a);
	}
	st.insert(-inf);
	vector<int> vec;
	int ma = *st.begin();
	vec.pb(ma);
	st.erase(st.find(ma));
	rep(_, n) {
		vector<int> nxt = vec;
		for (auto i : vec) {
			int val = *st.upper_bound(i);
			if (val == -inf) {
				cout << "No\n";
				return 0;
			}
			nxt.pb(val);
			st.erase(st.find(val));
		}
		vec = nxt;
	}
	cout << "Yes\n";
}

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

int main(int argc, char *argv[]){
	char s[27];
	int i,j,n;
	int found=0;

	scanf("%s",s);

	n=strlen(s);
	//printf("%d\n",n);

	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(s[i]==s[j]){
				found=1;
			}
		}
	if(found==1){
		break;
	}
	}

	if(found==1){
		printf("no\n");
	}else{
		printf("yes\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<queue>
#include<vector>
using namespace std;

int main(){
	int d;
	while(cin>>d&&d){
		int *MAX_p,*MAX_d,zero_d=0,zero_p=0;
		{//init
			MAX_p=&zero_p;MAX_d=&zero_d;
		}
		for(int p,d1,d2;d--;){
			cin>>p>>d1>>d2;
			if(*MAX_d<d1+d2){
				*MAX_d=d1+d2;
				*MAX_p=p;
			}
		}
		cout<<*MAX_p<<" "<<*MAX_d<<endl;
	}
}

Measured memory_bytes: 868