akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define dd double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	ll n, k;
	cin >> n >> k;
	cout << min(n % k, abs(n % k - k));
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    long x, y;
    readlnTo(x, y);
    writeln(abs(x-y) > 1 ? "Alice": "Brown");
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	rep(i,n) cin>>a[i];
	vector<bool> dp(k+1,false);
	FOR(i,1,k+1){
		rep(j,n){
			if(i-a[j]>=0){
				if(!dp[i-a[j]]){
					dp[i]=true;
				}
			}else break;
		}
	}
	if(dp[k]) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}

Measured memory_bytes: 256
//InTheNameOfGod
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn =1;
long double n,m,d,re;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n>>m>>d;
    cout<<fixed<<setprecision(9);
    if(n<d)cout<<0;
    else if(d==0)
    {
        cout<<n/(n*n)*(m-1);
    }
    else
    {
        re=2.0*(n-d)/(n*n)*(m-1);
        cout<<re;
    }
    return 0;
}


Measured memory_bytes: 256
using System;

namespace relay_d
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] x = new int[3];
			for (int i = 0; i < 3; i++) x[i] = int.Parse(Console.ReadLine());
			int sum = x[2] * 3;
			Console.WriteLine(x[0] + " " + x[1] + " " + (sum - x[0] - x[1]));
			Console.WriteLine((sum - (x[0] + x[0] + x[1] - x[2])) + " " + x[2] + " " + (x[0] + x[0] + x[1] - x[2] - x[2]));
			Console.WriteLine((x[0] + x[1] - x[2]) + " " + (sum - x[1] - x[2]) + " " + (sum - x[0] - x[2]));
		}
	}
}

Measured memory_bytes: 13268
#include<stdio.h>
int main () {
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H)
printf("Yes\n");
else
printf("No\n");
return 0;
}



Measured memory_bytes: 2092
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
#include <ctime>
#include <numeric>
using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1,1,1,-1,-1},dy[]={1,0,-1,0,1,-1,1,-1};

main(){
  ll n,m;
  while(cin>>n>>m,n|m){
    ll in[m];
    rep(i,m)cin>>in[i];
    ll sum=0;
    ll num=n;
    
    rep(i,(1<<m)){
      ll lcm=1;
      int bi=0;
      rep(j,m){
        if((1<<j)&i){
          ++bi;
          lcm=lcm*in[j]/__gcd(lcm,in[j]);
        }
      }

      ll lnum=n/lcm;      
      if(bi&1){
        sum+=n*(n+1)/2-lnum*(lnum+1)/2*lcm;
        num+=lnum;
      }else{
        sum-=n*(n+1)/2-lnum*(lnum+1)/2*lcm;
        num-=lnum;
      }
    }
    //cout<<num<<' '<<sum<<endl;
    num=n-num;
    if(num==0)cout<<0<<endl;
    else printf("%.9f\n",sum*1.0/num);
  }
}

Measured memory_bytes: 0
#include <stdio.h>

void    lucky(int a)
{
    int handred;
    int ten;
    int one;

    handred = a / 100;
    ten = a % 100 / 10;
    one = a % 10;

    if (100 <= a && a <= 999)
    {
        if (handred == 7 || ten == 7 || one == 7)
            printf("%s\n", "Yes");
        else
            printf("%s\n", "No");
    }
}

int     main(void)
{
    int i;

    scanf("%d", &i);
    lucky(i);
    return (0);
}


Measured memory_bytes: 1648
r,c,k=map(int,input().split())
items=[list(map(int,input().split())) for _ in range(k)]
dp=[[[0 for _ in range(c+1)] for _ in range(r+1)] for _ in range(5)]
for x,y,z in items:
    dp[4][x][y]=z
for i in range(1,r+1):
    for j in range(1,c+1):
        v=dp[4][i][j]
        dp[0][i][j]=max(dp[0][i][j-1],dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
        dp[1][i][j]=max(dp[1][i][j-1],dp[0][i][j-1]+v,max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])+v)
        dp[2][i][j]=max(dp[2][i][j-1],dp[1][i][j-1]+v)
        dp[3][i][j]=max(dp[3][i][j-1],dp[2][i][j-1]+v)
print(max(dp[i][r][c] for i in range(4)))

Measured memory_bytes: 495368
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AizuOnline
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var n = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
            var H = n[0]; var W = n[1];

            var hw = new int[H, W];
            foreach (var h in Enumerable.Range(0, H))
            {
                var m = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
                for (int w = 0; w < m.Length; w++)
                {
                    hw[h, w] = m[w];
                }
            }

            var dp = new int[H, W];
            var max = int.MinValue;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (hw[i, j] == 1)
                    {
                        dp[i, j] = 0;
                    }
                    else
                    {
                        if (i == 0 || j == 0)
                        {
                            dp[i, j] = 1;
                        }
                        else
                        {
                            dp[i, j] = Math.Min(dp[i, j - 1],
                                Math.Min(dp[i - 1, j - 1], dp[i - 1, j])) + 1;
                        }
                    }
                    max = Math.Max(dp[i, j], max);
                }
            }

            //var max = int.MinValue;
            //for (int i = 0; i < H; i++)
            //{
            //    for (int j = 0; j < W; j++)
            //    {
            //        max = Math.Max(dp[i, j], max);
            //    }
            //}

            Console.WriteLine(max * max);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 31332
N=int(input())
A=[list(map(int,input().split())) for _ in range(N)]
A.sort(key=lambda x:x[1])
ans=0
for i in range(N):
  if ans+A[i][0]>A[i][1]:
    print('No')
    exit()
  ans+=A[i][0]
print('Yes')

Measured memory_bytes: 46912
void main() {
	auto N = ri;
	auto b = readAs!(int[]);
	ulong[] ans;
	while(b != []) {
		bool flag = false;
		foreach_reverse(i; 0..b.length) {
			if(b[i] == i+1) {
				ans ~= i+1;
				b = b[0..i] ~ b[i+1..$];
				flag = true;
				break;
			}
		}
		if(!flag) {
			writeln(-1);
			return;
		}
	}
	ans.retro.each!writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


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

int cnt;

void insertionSort(int A[], int n, int g) {
  for(int i = g; i <= n-1; ++i) {
    int v = A[i];
    int j = i - g;
    while(j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[], int n) {
  cnt = 0;
  int g[] = {797161, 265720, 88573, 29524, 9841, 3280, 1093, 364, 121, 40, 13, 4, 1};
  //int g[] = {531441, 177147, 59049, 19683, 6561, 2187, 729, 243, 81, 27, 9, 3, 1};
  int M = sizeof(g)/sizeof(int);
  vector<int> G;
  for(int i = M-1; i >= 0; --i) G.push_back(g[i]);
  int m = 0;
  while(m < M && G[m] <= n) ++m;
  G.resize(m);
  reverse(G.begin(), G.end());


  printf("%d\n", m);
  for(int i = 0; i < m; ++i) {
    if(i) printf(" ");
    printf("%d", G[i]);
  }
  printf("\n");

  for(int i = 0; i <= m-1; ++i) {
    insertionSort(A, n, G[i]);
  }
  printf("%d\n", cnt);
  for(int i = 0; i < n; ++i) {
    printf("%d\n", A[i]);
  }
}

int n;
int A[1000000];

int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; ++i) cin >> A[i];
  shellSort(A, n);
  return 0;
}

Measured memory_bytes: 5156
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------
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 N, X;
vector<int> x;

int main() {
  cin >> N >> X;
  rep(i, 0, N) {
    int xx;
    cin >> xx;
    x.push_back(xx);
  }
  x.push_back(X);
  sort(x.begin(), x.end());
  rep(i, 1, N + 1) { x[i] -= x[0]; }
  int g = gcd(x[1], x[2]);
  rep(i, 3, N + 1) { g = gcd(g, x[i]); }
  cout << g << endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string S,T,U;
    int A,B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if(S == U){
        cout << A-1 << " "<< B<< endl;
    }else if(T == U){
        cout <<A << " "<< B-1 << endl;
    }else{
        cout << A << " "<< B << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
  int i = 0, cnt = 0;
  char s[6];

  scanf("%s", s);
  for (i = 0; i < 6; i++) {
    if (s[i] == '1') cnt++;
  }
  printf("%d\n", cnt);

  return 0;
}

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

int main() {
  string S, Ans="None";
  cin >> S;
  vector<int> T(26);
  rep(i, S.size()){
    T.at(S.at(i)-'a')++;
  }
  rep(i,26){
    if(T.at(i)==0){
      Ans=char(i+'a');
      break;
    }
  }
  cout << Ans << endl;
}

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

bool is_prime(int x){
    double root_x = sqrt(x);
    int root_x_int = root_x + 1;

    for(int i=2;i<=root_x_int;i++){
        if(x%i==0){
            return false;
        }
    }

    return true;
}

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

    for(int i=x;;i++){

        if(i==2 || is_prime(i)){
            cout << i << endl;
            break;
        }
    }
} 




Measured memory_bytes: 256
n = int(input())
s = list(input())
import collections as coll
t = coll.Counter(s)
b1,w1=t["#"],t["."]

b = 0
w = 0
p = 0
q = w1
for i in range(n):
    if s[i] == "#":
        b += 1
    elif s[i] == ".":
        w += 1
    
    p = b + w1 - w
    if p < q:
        q = p

print(q)

Measured memory_bytes: 4900
import java.util.*;

public class Main {
	static long[] dist;
	static long INF = 100000000000000000L;
	static ArrayList<ArrayList<Edge>> adj;
	
	static class Edge {
		int to;
		long w;
		Edge(int _to, long _w) {
			this.to = _to;
			this.w = _w;
		}
		
		@Override
		public String toString() {
			return "(to=" + to + ", w=" + w + ")";
		}
		
	}
	
	static class NextNode {
		int id;
		long cost;
		NextNode(int _id, long _cost) {
			id = _id; cost = _cost;
		}
	}
	
	static void initG(int V) { // V: the number of vertexes
		for(int i=0; i<V; i++) {
			adj.add(new ArrayList<Edge>());
		}
	}

	static void dijkstra(int s) {
		Arrays.fill(dist, INF);
		dist[s] = 0;
		PriorityQueue<NextNode> pq = new PriorityQueue<NextNode>(new Comparator<NextNode>() {
			public int compare(NextNode n1, NextNode n2) {
				if(n1.cost > n2.cost) return 1;
				else if(n1.cost==n2.cost) return 0;
				else return -1;
			}
		});
		pq.add(new NextNode(s, 0));
		while(!pq.isEmpty()) {
			NextNode cn = pq.poll();
			if(cn.cost > dist[cn.id]) continue;
			for(Edge e : adj.get(cn.id)) {
				if(cn.cost + e.w < dist[e.to]) {
					dist[e.to] = cn.cost + e.w;
					pq.add(new NextNode(e.to, dist[e.to]));
				}
			}
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int V = sc.nextInt();
		int E = sc.nextInt();
		int r = sc.nextInt();
		dist = new long[V];
		adj = new ArrayList<ArrayList<Edge>>(V);
		initG(V);
		for(int i=0; i<E; i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			int d = sc.nextInt();
			adj.get(s).add(new Edge(t, d));
		}
		sc.close();
		dijkstra(r);
		for(int i=0; i<V; i++) {
			if(dist[i] == INF) {
				System.out.println("INF");
			} else {
				System.out.println(dist[i]);
			}
		}
	}
	
}



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

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define array(N, t) (t*)calloc(N, sizeof(t))
#define ll long long
#define INF ((1LL << 62) - (1LL << 31))
#define max(p, q)((p) > (q) ? (p) : (q))
#define min(p, q)((p) < (q) ? (p) : (q))
#define swap(type, a, b) { type temp = a; a = b; b = temp; }


int N;
int ans = 0;

int baisu_cnt(int x) {
  int cnt = 0;
  for (int i = 1; i <= x; i += 1) {
    if (x % i == 0) {
      cnt += 1;
    }
  }
  return cnt;
}

void solve1() {
  int cnt_C = N - 1;

  for (int i = cnt_C; i > 0; i -= 1) {
    int mult_A_B = N - i;
    int cnt_baisu = baisu_cnt(mult_A_B);
    ans += cnt_baisu;
  }
}

int baisu[1000005] = {0};

void solve2() {
  for (int i = 1; i < N; i += 1) {
    for (int j = 1; j <= i; j += 1) {
      if (i % j == 0) {
        baisu[j] += 1;
      }
    }
  }
  for (int i = 1; i < N; i += 1) {
    ans += baisu[i];
  }
}

void solve3() {
  for (int A = 1; A < N; A += 1) {
    ans += (N - 1) / A;
  }
}

int main() {
  scanf("%d", &N);
  // solve1();
  // solve2();
  solve3();
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1720
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using ll = long long;
using namespace std;

int main(){
    int x1,y1,x2,y2,x3,y3,x4,y4;
    cin >> x1 >> y1 >> x2 >> y2;
    x3 = x2 - (y2-y1);
    y3 = y2 + (x2-x1);
    x4 = x1 - (y2-y1);
    y4 = y1 + (x2-x1);
    cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,count_p=0,count_q=0;
    cin>>N;
    vector<int> P(N);
    vector<int> Q(N);
    for(int i=0;i<N;i++){
        cin>>P[i];
    }
    for(int i=0;i<N;i++){
        cin>>Q[i];
    }
    while(next_permutation(P.begin(),P.begin()+N)){
        count_p++;
    }
    while(next_permutation(Q.begin(),Q.begin()+N)){
        count_q++;
    }
    cout<<abs(count_p-count_q)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long k=1e9+7;
inline long long ksm(long long a,long long b){
	register long long s=1;
	while(b){
		if(b&1)s=s*a%k;
		a=a*a%k;
		b>>=1;
	}
	return s%k;
}
inline long long cc(long long n,long long g){
	long long s=1,i;
	for(i=n;i>n-g;--i)s=(s*i)%k;
	for(i=1;i<=g;++i)s=(s*ksm(i,k-2))%k;
	return s;
}
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	cout<<(ksm(2,n)-1-cc(n,a)-cc(n,b)+10*k)%k;
}

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

int main()
{
  int n;
  vector<int64_t> m(3);
  cin >> n >> m[0] >> m[1] >> m[2];
  vector<pair<int, int>> vp;
  for (int i = 0; i < n; i++)
  {
    char a, b;
    cin >> a >> b;
    vp.emplace_back((int)(a - 'A'), (int)(b - 'A'));
  }
  vp.emplace_back(0, 1);
  vector<int> ans;
  auto add = [&](int a, int b) {
    m[a]++, m[b]--;
    ans.push_back(a);
  };
  for (int i = 0; i < n; i++)
  {
    int a, b, na, nb;
    tie(a, b) = vp[i];
    if (!m[a] && !m[b])
    {
      cout << "No" << endl;
      return 0;
    }
    else if (!m[a])
    {
      add(a, b);
    }
    else if (!m[b])
    {
      add(b, a);
    }
    else
    {
      tie(na, nb) = vp[i + 1];
      if (a == na || a == nb)
      {
        add(a, b);
      }
      else
      {
        add(b, a);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < n; i++)
  {
    cout << (char)(ans[i] + 'A') << endl;
  }
}

Measured memory_bytes: 4824
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;

#define endl '\n'
#define int ll

signed main() {
    fast;

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

    int ans = 0;

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

    cout<<ans;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    from fractions import gcd
    a,b =readInts()
    g = gcd(a,b)
    print(a // g * b)
if __name__ == '__main__':
  main()


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

int main(){
	int n;
	cin>>n;
	int k = n%10;
	if (k == 2 || k == 4 || k == 5 || k == 7 || k == 9){
		cout<<"hon";
	}
	else if (k == 0 || k == 1 || k == 6 || k == 8){
		cout<<"pon";
	}
	else{
		cout<<"bon";
	}
}

Measured memory_bytes: 3616
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int z = sc.nextInt();
		int w = sc.nextInt();
		int[] aa = new int[n + 1];
		aa[0] = w;
		for (int i = 1; i <= n; i++)
			aa[i] = sc.nextInt();
		int[] dp = new int[n];
		int[] dq = new int[n];
		for (int i = n - 1; i >= 0; i--) {
			dp[i] = dq[i] = Math.abs(aa[i] - aa[n]);
			for (int j = i + 1; j < n; j++) {
				dp[i] = Math.max(dp[i], dq[j]);
				dq[i] = Math.min(dq[i], dp[j]);
			}
		}
		println(dp[0]);
	}
}


Measured memory_bytes: 40080
#include <iostream>

using namespace std;

long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  int K;
  cin >> K;
  long long ans = 0;
  for (int a = 1; a <= K; a++)
    for (int b = 1; b <= K; b++)
      for (int c = 1; c <= K; c++)
        ans += gcd(gcd(a, b), c);
  cout << ans << endl;
  return 0;
}

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

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

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;
  VI a(n);
  REP(i, n) cin >> a[i];

  VI b(n); b[0] = a[0];
  FOR(i, 1, n) b[i] = b[i-1] + a[i];
  // cout << b << endl;

  int ret = INF;
  FOR(i, 2, n-1) {
    // cout << "i:" << i << endl;
    // [0,i)[i,n) で分割
    int lb = 0, ub = i-1;
    while(ub-lb > 1) {
      int mid = (ub+lb)/2;
      // [0,mid][mid+1,i)
      int x = b[mid], y = b[i-1] - b[mid];
      if(x > y) ub = mid;
      else lb = mid;
    }
    // lbかlb+1
    int v1, v2;
    int tmp1 = abs(2*b[lb]-b[i-1]), tmp2 = abs(2*b[lb+1]-b[i-1]);
    if(tmp1 < tmp2) v1 = b[lb], v2 = b[i-1] - b[lb];
    else v1 = b[lb+1], v2 = b[i-1] - b[lb+1];
    // cout << lb << " " << v1 << " " << v2 << endl;

    lb = i, ub = n-1;
    while(ub-lb > 1) {
      int mid = (ub+lb)/2;
      // [i,mid][mid+1,n)
      int x = b[mid] - b[i-1], y = b[n-1] - b[mid];
      if(x > y) ub = mid;
      else lb = mid;
    }
    int v3, v4;
    tmp1 = abs(b[lb]-b[i-1]-(b[n-1]-b[lb]));
    tmp2 = abs(b[lb+1]-b[i-1]-(b[n-1]-b[lb+1]));
    // cout << lb << " " << tmp1 << " " << tmp2 << endl;
    if(tmp1 < tmp2) v3 = b[lb]-b[i-1], v4 = b[n-1] - b[lb];
    else v3 = b[lb+1]-b[i-1], v4 = b[n-1] - b[lb+1];
    // cout << v3 << " " << v4 << endl;

    chmin(ret, max({v1, v2, v3, v4}) - min({v1, v2, v3, v4}));
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 3456
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int time, team, pro, rec;
	while (cin >> time >> team >> pro >> rec, time) {
		vvi pena(team, vi(pro, 0));
		vector<pair<pii, int>> ac(team, pair<pii, int>({0,0},0));
		REP(i, team)
			ac[i].second = (i + 1);
		REP(i,rec) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			b--;
			c--;
			if (d == 0) {
				ac[b].first.first = ac[b].first.first + 1;
				ac[b].first.second= ac[b].first.second - a - pena[b][c];
			}
			else {
				pena[b][c] += 20;
			}
		}
		RSORT(ac);
		REP(i, team) {
			if (i != 0)
				if (ac[i - 1].first.first == ac[i].first.first&&
					ac[i - 1].first.second == ac[i].first.second)
					cout << "=";
				else
					cout << ",";
			cout << ac[i].second;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3156
module Sort_Module
    implicit none
    public
    contains
    recursive subroutine mergesort(a, p, r, b)
        integer(8) a(:), b(:)
        integer(8) p, r
        integer(8) q
        if (p < r) then
            q = (p+r)/2
            call mergesort(a, p, q, b)
            call mergesort(a, q+1, r, b)
            call merge(a, p, q, r, b)
        end if
    end subroutine mergesort
    subroutine merge(a, p, q, r, b)
        integer(8) a(:), b(:)
        integer(8) p, r, q, i, j, k
        integer(8) t
        k = p;   i = p;   j = q+1
        do
            if (.not. (k <= r)) exit
            if (j > r) then
                t = a(i);   i = i+1
            else if (i > q) then
                t = a(j);   j = j+1
            else if (a(i) <= a(j)) then
                t = a(i);   i = i+1
            else
                t = a(j);   j = j+1
            end if
            b(k) = t;   k = k+1
        end do
        do i = p, r
            a(i) = b(i)  
        end do
    end subroutine merge
    subroutine sort(a)
      integer(8) a(:),b(ubound(a,1)-size(a)+1:ubound(a,1)),n,k
      n = ubound(a,1)
      k = ubound(a,1)-size(a)+1
      call mergesort(a,k,n,b)
    end subroutine sort
    function POSL(a,v) result(r)!find first i:a(i)>=v
        implicit none
        integer(8) :: a(:),l,r,idx,v
        r = ubound(a,1) + 1
        l = ubound(a,1)-size(a)
        do while(r-l>1)
            idx = l + (r-l)/2
            if(a(idx) >= v)then
                r = idx
            else
                l = idx
            endif
        enddo
    end function
    function POSU(a,v) result(r)!find first i:a(i)>v
        implicit none
        integer(8) :: a(:),l,r,idx,v
        r = ubound(a,1) + 1
        l = ubound(a,1)-size(a)
        do while(r-l>1)
            idx = l + (r-l)/2
            if(a(idx) > v)then
                r = idx
            else
                l = idx
            endif
        enddo
    end function
    function NUM(a,v) result(n)
        implicit none
        integer(8) :: a(:),v,n
        n = POSU(a,v) - POSL(a,v)
    end function
end module Sort_Module
  

program atcoder
    use Sort_Module
    implicit none
    integer(8) :: ans,a,b,c(1:4),i
    c=0
    do i=1,3
        read*,a,b
        c(a)=c(a)+1
        c(b)=c(b)+1
    enddo
    call sort(c)
    if( all((/1,1,2,2/)==c) )then
        write(*,'(a)')"YES"
    else 
        write(*,'(a)')"NO"
    endif
    stop 
contains
end program atcoder

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int n, m;
vi adj[105];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			if (n & 1) {
				if (i == n)
					adj[i].pb(j), m++;
				else if (i + j != n)
					adj[i].pb(j), m++;
			} else {
				if (i + j != n + 1)
					adj[i].pb(j), m++;
			}

	cout << m << endl;
	for (int i = 1; i <= n; i++)
		for (int j : adj[i])
			cout << i << " " << j << endl;
	
	return 0;
}

Measured memory_bytes: 256
# using DP
# time complexity: O(n * (2^16) * c)
# 1 <= n <= 30, 1 <= c <= 30
# worst case: 30 * (2^16) * 30 = 58982400

bc = [bin(i).count('1') for i in range(65536)] # bitcount

def solve():
    from sys import stdin
    f_i = stdin
    
    while True:
        n, c = map(int, f_i.readline().split())
        if n == 0:
            break
        
        A = [int(f_i.readline().replace(' ', ''), 2) for i in range(n)]
        B = [int(f_i.readline().replace(' ', ''), 2) for i in range(c)]
        
        dp1 = {A[0]: 0} # {state: score}
        dp2 = {}
        
        for a in A[1:] + [0]:
            for st1, sc1 in dp1.items():
                for b in B:
                    cb = st1 & b
                    sc2 = sc1 + bc[cb]
                    st2 = (st1 - cb) | a
                    try:
                        if dp2[st2] < sc2:
                            dp2[st2] = sc2
                    except KeyError:
                        dp2[st2] = sc2
            dp1, dp2 = dp2, {}
        
        print(max(dp1.values()))

solve()


Measured memory_bytes: 15456
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  if(a/1000==a%1000/100 && a%1000/100==a%100/10) cout << "Yes" << endl;
  else if(a%1000/100==a%100/10 && a%100/10==a%10) cout << "Yes" << endl;
  else cout << "No" << endl;
  }

Measured memory_bytes: 3628
a, b = map(int, input().split())
lst = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]

if lst.index(a) > lst.index(b):
  print('Alice')
elif a == b:
  print('Draw')
else:
  print('Bob')

Measured memory_bytes: 9084
#include<bits/stdc++.h>
using namespace std;
#define test(t) int t;cin>>t;while(t--)
#define lli long long int
#define pb push_back
#define MAX 10000007
#define mod 1000000007
//a.push_back(i+'0');convert i to char;
//cout << fixed << setprecision(2) << pi ;
const lli infl=0x3f3f3f3f3f3f3f3fLL;
int prime(lli n)
{int f=1;
    for(lli i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {f=0;break;}
    }if(f==0) return 0;
    return 1;

}
int power(int a,int b)
{
   int result=1;
    while(b>0)
    {   if(b%2)
        result=(a*result)%mod;
        a=(a*a)%mod;
        b=b/2;
    }
    return result%mod;
}
int main()
{  ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
    //test(t)
    {
       lli ans=infl,c,d,x,y,z,n,q,m,r,f=0,i=0,j=0,odd=0,even=0;
      lli sum=0,sum1=0,sum2=0,res=0,cur,l,k,area,maxm=-infl,minm=infl,low,high=0,r1,r2,c1,c2;
       string s1,s2,s3,str,s;
       vector<int>v,u;
       cin>>n;
       lli a[n][3];
       int dp[n][3];ans=0;
       for(i=0;i<n;i++)
        cin>>a[i][0]>>a[i][1]>>a[i][2];
       dp[0][0]=a[0][0];dp[0][1]=a[0][1];dp[0][2]=a[0][2];
      i=0; ans=max(dp[i][0],max(dp[i][2],dp[i][1]));
       for(i=1;i<n;i++)
       {
           dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
           dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
           dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
           ans=max(dp[i][0],max(dp[i][2],dp[i][1]));
       }cout<<ans;
       cout<<endl;
    }
}


Measured memory_bytes: 7096
def calculate(arr1,arr2):

    result = 0
    for i in range(len(arr2)):

        if (arr1[i] + arr1[i+1]) >= arr2[i]:
            result += arr2[i]
        else:
            result += arr1[i] + arr1[i+1]

        res1 = arr2[i] - arr1[i]

        if arr2[i] >= arr1[i]:
            arr1[i] = 0
        else:
            arr1[i] = arr1[i] - arr2[i]

        if res1 > 0:
            if arr1[i+1] >= res1:
                arr1[i+1] = arr1[i+1] - res1
            else:
                arr1[i+1] = 0


    return result


N = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

result = calculate(arr1, arr2)

print(result)






Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int count(vector<int> v,int a)
{
	set<int> s;
	for(int k=a+1;k<v.size();k++)
	{
		s.insert(v[k]);
		if(s.size()==10)
		{
			return 10;
		}
	}
	return s.size();
}
int count2(vector<int> v,int a)
{
	int ans=0;
	bool use[10]={false};
	for(int l=a+1;l<v.size();l++)
	{
		if(use[v[l]])
		{
			continue;
		}
		ans+=count(v,l);
		use[v[l]]=true;
	}
	return ans;
}
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<n;i++)
	{
		v.push_back(s[i]-'0');
	}
	int ans=0;
	bool used[10]={false};
	for(int j=0;j<n;j++)
	{
		if(used[v[j]])
		{
			continue;
		}
		ans+=count2(v,j);
		used[v[j]]=true;
	}
	cout<<ans;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int ans = 0;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(all(p));
    p[n-1] /= 2;
    rep(i,n) ans += p[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
//#include <tuple>
#include <set>
#include <string.h>
#include <functional>

#define X first
#define Y second
#define MP make_pair
//#define MT make_tuple
#define REP(i, a, n) for(int (i) = (a); (i) < (n); ++(i))
#define FOR(i, n) REP(i, 0, n)
typedef long long ll;
using namespace std;
const int MAX = 500;

template<class T, class U>
void convert(T &t, U &u)
{
	stringstream ss;
	ss << t;
	ss >> u;
}

int main()
{
	string n;
	while (cin >> n){
		bool used[10] = {};
		int pidx = -1, eidx = -1;
		FOR(i, n.size()){
			if (n[i] == '+') pidx = i;
			if (n[i] == '=') eidx = i;
			if (n[i] >= '0' && n[i] <= '9') used[n[i] - '0'] = true;
		}

		//各数列にパース.
		string a = n.substr(0, pidx);
		string b = n.substr(pidx + 1, eidx - (pidx + 1));
		string c = n.substr(eidx + 1, n.size() - (eidx + 1));

		int ans = -1;
		FOR(i, 10){
			//if (used[i]) continue;

			string aa = a, bb = b, cc = c;

			//Xを置き換える.
			FOR(j, aa.size()) if (aa[j] == 'X') aa[j] = i + '0';
			FOR(j, bb.size()) if (bb[j] == 'X') bb[j] = i + '0';
			FOR(j, cc.size()) if (cc[j] == 'X') cc[j] = i + '0';

			//2桁以上の数列で先頭に0がある場合は飛ばす.
			if (aa.size() >= 2 && aa[0] == '0') continue;
			if (bb.size() >= 2 && bb[0] == '0') continue;
			if (cc.size() >= 2 && cc[0] == '0') continue;

			//処理しやすいように数列の長さを合わせる.
			int ma = MAX - aa.size();
			int mb = MAX - bb.size();
			int mc = MAX - cc.size();
			FOR(j, ma) aa.insert(0, "0");
			FOR(j, mb) bb.insert(0, "0");
			FOR(j, mc) cc.insert(0, "0");

			//筆算.
			int up = 0;
			string res(MAX, ' ');
			FOR(j, MAX){
				int s = aa[(MAX - 1) - j] - '0';
				int t = bb[(MAX - 1) - j] - '0';

				res[(MAX - 1) - j] = ((s + t + up) % 10) + '0';
				up = (s + t + up) / 10;
			}

			//計算結果と結果の数列を比較して一緒なら終了.
			if (res == cc){
				ans = i;
				break;
			}
		}

		if (ans == -1) cout << "NA" << endl;
		else cout << ans << endl;

		if (cin.eof()) break;
 	}

	return 0;
}

Measured memory_bytes: 1228
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int h2 = sc.nextInt();
        int w2 = sc.nextInt();
        System.out.println((h - h2) * (w - w2));
    }
}

Measured memory_bytes: 23764
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

const int N = 26, D = 365;

using namespace std;
int main() {
    int d;
    cin >> d;
    vector<int> c(N), hi(D);
    vector<vector<int>> s(D, vector<int>(N));
    for (int i = 0; i < N; ++i)
        cin >> c[i];
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < N; ++j)
            cin >> s[i][j];
        hi[i] = max_element(s[i].begin(), s[i].end()) - s[i].begin();
    }
    vector<vector<int>> nxt(D, vector<int>(N, D));
    for (int i = d - 1; i > 0; --i) {
        for (int j = 0; j < N; ++j)
            if (j == hi[i])
                nxt[i - 1][j] = i;
            else
                nxt[i - 1][j] = nxt[i][j];
    }
    vector<int> ans;
    vector<int> last(N, 0);
    for (int i = 1; i <= d; ++i) {
        int maxt = 0;
        double maxg = INT_MIN;
        for (int j = 0; j < N; ++j) {
            double gain = s[i - 1][j];
            for (int k = 0; k < N; ++k)
                if (k != j) {
                    int tot = nxt[i - 1][k] - last[k];
                    int now = i - 1 - last[k];
                    double loss = c[k] * (tot - now);
                    gain -= loss;
                }
            if (gain > maxg) {
                maxg = gain;
                maxt = j;
            }
        }
        last[maxt] = i;
        ans.emplace_back(maxt + 1);
    }
    for (int i : ans)
        cout << i << endl;
}


Measured memory_bytes: 3744
#include <stdio.h>
#define MAX 500001
#define INFTY 1000000000
int A[MAX],L[MAX],R[MAX],c=0;

void Merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
L[i]=A[left+i];
}

for(i=0;i<n2;i++){
R[i]=A[mid+i];
  }

  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;

  for(k=left;k<right;k++){
    c++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else {
      A[k]=R[j];
      j=j+1;
    }
  }
}

void MergeSort(int A[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    MergeSort(A,left,mid);
    MergeSort(A,mid,right);
    Merge(A,left,mid,right);
  }
}

int main(){
  int i,n;

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


  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1){
printf(" ");
}
  }
printf("\n");
  printf("%d\n",c);
  
  return 0;
}


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n; cin>>n;
	map<ll,ll> mp;
	vl vec(n);
	rep(i,0,n){
		ll a; cin>>a;
		--a;
		mp[a]=i;
		vec[i]=a;
	}
	sort(all(vec));
	vl ans(n);
	rep(i,0,n){
		ans[i]=mp[vec[i]]+1;
	}
	rep(i,0,n) cout<<ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 8576
n,a,b,c = map(int,input().split())

orgPetternList =[]
def petternMake(cnt,s):
  if cnt == n+1:
    orgPetternList.append(s)
    return
  for i in range(4):
    petternMake(cnt+1,s+str(i))
  

banboo = [int(input()) for i in range(n)]

#全部一度全パターンで足しきる場合の回す元リスト作成
petternMake(1,'')

min = 999999999
#全パターンループして、最低MP算出
for ptn in orgPetternList:

  if ptn.find('1') == -1 or ptn.find('2') == -1  or ptn.find('3') == -1 :
    continue
    
  ptnList = list(ptn)
  sumMp = nowa = nowb = nowc = acnt = bcnt = ccnt= 0
  for cnt in range(len(ptnList)):
    
    if ptnList[cnt] == '1':
      nowa += banboo[cnt]
      acnt+=1
      if acnt>1:
        sumMp +=10
    elif ptnList[cnt]=='2':
      nowb += banboo[cnt]
      bcnt+=1
      if bcnt>1:
        sumMp +=10
    elif ptnList[cnt]=='3':
      nowc += banboo[cnt]
      ccnt+=1
      if ccnt>1:
        sumMp +=10
      
  sumMp = sumMp + abs(a-nowa) + abs(b-nowb) +abs(c-nowc)

  if sumMp < min:
    min = sumMp

print(min)

Measured memory_bytes: 56156
import java.util.Scanner;

class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        String S = sc.next();
        if(N%2!=0){
            System.out.print("No");
        }else{
            if(S.substring(0,N/2).equals(S.substring(N/2))){
                System.out.print("Yes");
            }else{
                System.out.print("No");
            }
        }
        System.out.flush();
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long dp[2005];
long long f(int sum){
	if(sum<0) return 0;
	long long&ret = dp[sum];
	if(~ret) return ret;
	ret = 0;
	for(int i=3; i<=sum; i++) ret+=f(sum-i);
	return ret%=mod;
}
int main(){
	memset(dp,-1,sizeof(dp));
	int s;
	cin>>s;
	dp[0] = 1;
	cout<<f(s);
}

Measured memory_bytes: 3640
def resolve():
    N = int(input())
    T, A = list(map(int,input().split()))
    H = list(map(int,input().split()))
    ans = 0
    for i in range(1, N):
        if abs(A-(T-H[i]*0.006)) < abs(A-(T-H[ans]*0.006)):
            ans = i
    print(ans + 1)

if '__main__' == __name__:
    resolve()

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::map<std::pair<int, int>, int> map;
	for (int i = 0; i < n; i++) {
		char s[30];
		scanf("%s", s);
		char *poss = strchr(s, '.');
		if (poss) {
			bool nonzero = false;
			for (char *pos = poss + 1; *pos; pos++) if (*pos != '0') nonzero = true;
			if (!nonzero) poss = NULL;
		}
		if (!poss) { // integer
			int all = std::stoi(std::string(s));
			int r2 = 0;
			while (all % 2 == 0) r2++, all /= 2;
			int r5 = 0;
			while (all % 5 == 0) r5++, all /= 5;
			map[{r2, r5}]++;
			continue;
		}
		int pos = poss - s;
		int64_t all = 0;
		int cnt = 0;
		for (int i = 0; i < pos; i++) {
			all = all * 10 + s[i] - '0';
		}
		for (int i = pos + 1; s[i]; i++) {
			all = all * 10 + s[i] - '0';
			cnt++;
		}
		int r2 = 0;
		while (all % 2 == 0) r2++, all /= 2;
		int r5 = 0;
		while (all % 5 == 0) r5++, all /= 5;
		r2 -= cnt;
		r5 -= cnt;
		map[{r2, r5}]++;
	}
	int64_t res = 0;
	for (auto &i : map) {
		for (auto &j : map) {
			if (i.first < j.first) continue;
			if (i.first == j.first && i.first.first >= 0 && i.first.second >= 0) res += (int64_t) i.second * (i.second - 1) / 2;
			else if (i.first.first + j.first.first >= 0 && i.first.second + j.first.second >= 0) res += (int64_t) i.second * j.second;
		}
	}
	printf("%" PRId64 "\n", res);
	
	return 0;
}


Measured memory_bytes: 3792
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();

		String ans;
		int sub = Math.abs(a - b);

		if (sub % 2 != 0)
			ans = "IMPOSSIBLE";
		else
			ans = Integer.toString(sub / 2 + Math.min(a, b));

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 22864
#include <bits/stdc++.h>
#include <regex>
//#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define FOR(i, s, e) for (ll i = ll(s); i < ll(e); ++i)
#define REP(i, e) FOR(i, 0, e)
//#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
#define AST(exp, msg) if(!(exp)){EPR((msg))} assert((exp));
#define TAST(exp, msg) if(!(exp)){EPR((msg))} while(!(exp)){}
#define EPR(msg) cerr << (msg) << endl;
using namespace std;
using ll = long long; using ull = unsigned long long;
//using vi = vector<int>; using vvi = vector<vi>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>;
using vs = vector<string>;
//using pii = pair<int, int>; 
using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  ll X; cin>>X;

  ll ans = (X/500)*1000 + ((X%500)/5)*5;

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
pbls = list(map(int, input().split()))
ans = 1e18
for i in range(pow(2, n)):
    bls = pbls[::]
    if (bin(i).count("1") != k):
        continue
    temp = 0
    l = []
    for b in range(n):
        if (i & (1 << b)):
            l.append(b)
    for c in l:
        if (c == 0):
            continue
        else:
            m = max(bls[:c])
            if (m < bls[c]):
                pass
            else:
                temp += m + 1 - bls[c]
                bls[c] = m + 1
    ans = min(ans,temp)
print(ans)



Measured memory_bytes: 3064
fn main() {
    let stdin = std::io::stdin();
    let mut buf = String::new();

    stdin.read_line(&mut buf).unwrap();
    let mut flg = false;
    for i in buf.chars() {
        if flg {
            println!("A{}C", i);
            break;
        }
        if i == ' ' {
            flg = true;
        }
    }
}


Measured memory_bytes: 4352