akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
ll a[maxn],sum[maxn];
ll f[maxn];
int tmp;
int main(){
	int n=read(),m=read();
	a[++tmp]=n;
	REP(i,1,m){
		ll x=readll();
		while(tmp && a[tmp]>=x) --tmp;
		a[++tmp]=x;
	}
	sum[tmp]=1;
	DREP(i,tmp,2){
		sum[i-1]+=(a[i]/a[i-1])*sum[i];
		ll u=a[i]%a[i-1];
		while(u){
			int x=upper_bound(a+1,a+tmp+1,u)-a-1;
			if(x==0){
				f[u]+=sum[i];
				break;
			}
			sum[x]+=(u/a[x])*sum[i];
			u%=a[x];
		}
	}
	f[a[1]]=sum[1];
	DREP(i,a[1]-1,1) f[i]+=f[i+1];
	REP(i,1,n) printf("%lld\n",f[i]);
	return 0;
}

Measured memory_bytes: 4096
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <set>
using namespace std;


#define ll long long int


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, m;
    cin>>n>>m;
    int a;
    for(int i=0; i<m; i++){
        cin>>a;
        n -= a;
    }
    
    if(n<0) cout<<-1<<endl;
    else cout<<n<<endl;
    
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c){
        cout << 1 << endl;
    } else if(a == b || b == c || a == c){
        cout << 2 << endl;
    } else{
        cout << 3 << endl;
    }
    return 0;
}

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

int main() {
  int N,x,sum=0;
  cin >> N;
  int i=1;
  cin>>x;
    while(x%2==0){
      x/=2;
      sum++;
    }
  for(i;i<N;i++){
    cin>>x;
    int j=0;
    while(x%2==0&&j!=sum){
      x/=2;
      j++;
    }
    if(j<sum)sum=j;    
  }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readInteger()
    val aList = readIntegerList()
    val countMap = elementCountMap(aList)

    var tmp = 0
    for (c in countMap.values) {
        if (c > 1) {
            tmp += (c - 1)
        }
    }

    if (tmp % 2 == 0) {
        println(aList.size - tmp)
    } else {
        println(aList.size - tmp - 1)
    }
}

/**
 * O(n)
 */
fun <T>elementCountMap(list: List<T>): Map<T, Int> {
    val countMap = mutableMapOf<T, Int>()
    for (e in list) {
        countMap[e] = (countMap[e] ?: 0) + 1
    }
    return countMap
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


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

using namespace std;

const int MAXN = 3005;

int dp[MAXN][MAXN];

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	
	string s, t;
	cin >> s >> t;
		
	int len_s = (int) s.size();
	int len_t = (int) t.size();
	
	memset(dp, 0, sizeof dp);

	for (int i = 1; i <= len_s; i++) {
		for (int j = 1; j <= len_t; j++) {
			if (s[i - 1] == t[j - 1])
				dp[i][j] = 1 + dp[i - 1][j - 1];
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}

	int i = len_s, j = len_t;
	string ans = "";

	while(i > 0 && j > 0) {
		if (dp[i][j] == dp[i - 1][j])
			i--;
		else if (dp[i][j] == dp[i][j - 1])
			j--;
		else {
			ans += s[i - 1];
			i--, j--;
		}
	}
	
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 35584
def d_practical_skill_test(H, W, D, A, Q, I):
    # クエリが1-indexedなため、配列もそれに従う(0番は使わない)
    px = [0 for _ in range(H * W + 1)]
    py = [0 for _ in range(H * W + 1)]  # (px[Aij],py[Aij])にAijの値が入っている
    d = [0 for _ in range(H * W + 1)]  # 1~D→ゴールまでのコスト
    for i in range(H):
        for j in range(W):
            px[A[i][j]] = i
            py[A[i][j]] = j
    for i in range(D + 1, H * W + 1):
        d[i] = d[i - D] + abs(px[i] - px[i - D]) + abs(py[i] - py[i - D])
    ans = []
    for l, r in I:
        ans.append(str(d[r] - d[l]))
    return '\n'.join(ans)

H,W,D = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(H)]
Q = int(input())
I = [[int(i) for i in input().split()] for j in range(Q)]
print(d_practical_skill_test(H, W, D, A, Q, I))

Measured memory_bytes: 37120
#ifdef _MSC_VER
#  define _CRT_SECURE_NO_WARNINGS
#  define _USE_MATH_DEFINES
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
using u32 = unsigned int; using u64 = unsigned long long int;
template <class T> using vec = vector<T>;
void in(){}; template <class T, class...TS> void in(T &&x, TS &&...xs) { cin >> x; in(move(xs)...); };
template <class T> void out(T &&x) { cout << x << "\n"; }; template <class T, class...TS> void out(T &&x, TS &&...xs) { cout << x << " "; out(move(xs)...); }
#define indef(t, ...) t __VA_ARGS__; in(__VA_ARGS__)
#define get(t) []{ t _; cin >> _; return _; }()
#define times(n, i) for (i32 i =  0 ; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define even(x) ((abs(x) & 1) == 0)
#define odd(x) ((abs(x) & 1) == 1)
#define bit(x, i) (((x) >> i) & 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007ll;
const f64 EPS = 1e-10;

struct unionfind {
    vec<i32> data;
    unionfind(i32 size) : data(size, -1) { }
    void unite(i32 x, i32 y) {
        x = find(x); y = find(y); if (x == y) return;
        if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x;
    }
    i32 find(i32 x) { return data[x] < 0 ? x : data[x] = find(data[x]); }
    i32 size(i32 x) { return -data[find(x)]; }
    bool same(i32 x, i32 y) { return find(x) == find(y); }
};

i32 n;
vec<pair<i32, i32>> xs, ys;
vec<tuple<i32, i32, i32>> es;

i32 solve() {
    in(n);
    times(n, ni) {
        indef(i32, x, y);
        xs.append(make_pair(x, ni));
        ys.append(make_pair(y, ni));
    }
    sortall(xs);
    sortall(ys);
    times(n-1, ni) {
        es.append(make_tuple(xs[ni+1].first - xs[ni].first, xs[ni].second, xs[ni+1].second));
        es.append(make_tuple(ys[ni+1].first - ys[ni].first, ys[ni].second, ys[ni+1].second));
    }
    sortall(es);

    i32 ans = 0;
    unionfind uf(n);
    times(es.size(), ei) {
        i32 d, ni, nj;
        tie(d, ni, nj) = es[ei];
        if (uf.same(ni, nj)) continue;
        uf.unite(ni, nj);
        ans += d;
    }
    return ans;
}

i32 main()
{
    ios::sync_with_stdio(false);

#ifdef _MSC_VER
    /**
    ifstream fin("input.txt"); cin.rdbuf(fin.rdbuf()); assert(fin);
    ofstream fout("output.txt"); cout.rdbuf(fout.rdbuf()); assert(fout);
    /**/
#endif

    out(solve());

    return 0;
}

Measured memory_bytes: 7016
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];

    vll sum(n, 0);
    sum[0] = a[0];
    srep(i, 1, n) {
        sum[i] = sum[i-1] + a[i];
    }

    ll ans = LINF;
    rep(i, n-1) {
        ll diff = abs(sum[n-1] - sum[i] - sum[i]);
        ans = min(ans, diff);
    }


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

Measured memory_bytes: 2560
n=int(input())
d=dict()
for i in map(int,input().split()):
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
ans=0
for i in d.keys():
  if i<=d[i]:
    ans+=d[i]-i
  else:
    ans+=d[i]
print(ans)

Measured memory_bytes: 23284
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.StringTokenizer;

public class Main  implements Runnable {
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 64 * 1024 * 1024).start();
    }
    public void run() {
    	FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		String str = sc.next();
		char[] c = str.toCharArray();
		long ans = 0;
		int n = (int)Math.pow(2,(double)c.length-1);
		for (int i = 0; i < n; i++) {
			long tmp = (c[0] - '0');
			for (int j = 1; j < c.length; j++) {
				if((i>>(j-1)&1)==0)
				{
					tmp=tmp*(long)10;
					tmp += (c[j]-'0');
				}
				else {
					ans += tmp;
					tmp = (c[j]-'0');
				}
			}
			ans += tmp;
		}

		out.printf("%d", ans);
		out.flush();
	}

    
    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }
        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }
    }
}

Measured memory_bytes: 23380
package main

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

func main() {

	alpha_counter := make(map[rune]int)
	in_string := ""
	scanner := bufio.NewScanner(os.Stdin)

	for {
		if scanner.Scan() == false {
			break
		}
		in_string += scanner.Text()
	}

	for _, r := range in_string {

		if ('A' <= r) && (r <= 'Z') {
			r += 'a' - 'A'
		}

		if ('a' <= r) && (r <= 'z') {

			_, exist := alpha_counter[r]

			if exist {
				alpha_counter[r] += 1
			} else {
				alpha_counter[r] = 1
			}
		}
	}

	for i := 'a'; i <= 'z'; i++ {
		v, _ := alpha_counter[i]
		fmt.Printf("%c : %d\n", i, v)
	}
}



Measured memory_bytes: 1132
from collections import Counter
from functools import reduce
from operator import mul

mod = 10 ** 9 + 7


def my_mul(a, b):
    return a * b % mod


n = int(input())
s = input()

cnt = Counter(s)

print(reduce(my_mul, (v + 1 for v in cnt.values())) - 1)

# 同じ文字列でも、異なる位置から作られたものは区別するため、2
# N − 1 通りのすべての部分列が区別され
# ることになります。
# 条件より、同じ文字を 2 度使ってはいけないため、ある文字 c について colorful の条件を壊さないとり方
# は (c の出現回数 + 1) となります (どれか 1 つを取るケース及び文字 c を一切取らないケース)
# すべての文字 c についてのこのとり方の積を求め、空文字列の分の 1 を引いた数が答えとなります。


Measured memory_bytes: 3820
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 2e5+100;
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(k>=s.size())
    cout<<s;
    else {
    	for(int i=0;i<k;i++)
    	cout<<s[i];
    	cout<<"...";
	}
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

int main() {
	ll h, w; cin >> h >> w;
	if (w > h) {
		swap(h, w);
	}

	// h > w;
	if (!(h % 3) || !(w % 3)) {
		cout << 0 << endl;
		return 0;
	}

	ll ans = ((h > w) ? w : h);
	ll s = MAX_L;
	rep(i, 1, h) {
		ll a = i * w;
		ll b = w / 2 * (h - i);
		ll c = (w / 2 + ((w & 1) ? 1 : 0)) * (h - i);
		ll maxS = max(a, max(b, c));
		ll minS = min(a, min(b, c));
		s = min(s, maxS - minS);
	}

	rep(i, 1, w) {
		ll a = i * h;
		ll b = h / 2 * (w - i);
		ll c = (h / 2 + ((h & 1) ? 1 : 0)) * (w - i);
		ll maxS = max(a, max(b, c));
		ll minS = min(a, min(b, c));
		s = min(s, maxS - minS);
	}
	cout << min(ans, s) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
using namespace std;
int main() {
	long long int n, m, a[50] = {}, b[50] = {}, count[51] = {};
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		count[a[i]]++;
		count[b[i]]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << count[i] << endl;
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), a + n
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)

using namespace std;

typedef long long ll;

const double EPS = 1e-10;
const double PI = acos(-1.0);

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n;
	scanf("%d", &n);
	if(n % 2) {
		printf("%.9f\n", (n / 2 + 1) / (double)n);
	} else {
		printf("%.9f\n", (n / 2) / (double)n);
	}
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = Counter(a)
cnt_sorted = sorted(cnt.items(), key=lambda x: x[1])
num = len(cnt.keys()) - k
ans = 0
for i in range(num):
    ans += cnt_sorted[i][1]
print(ans)

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

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

string K;
int D;
int dp[11111][2][111];

int rec(int digit, int smaller, int modD) {
  if (digit >= K.size()) {
    return modD == 0;
  }

  if (dp[digit][smaller][modD] != -1) {
    return dp[digit][smaller][modD];
  }

  int lim = (smaller ? 9 : K[digit] - '0');
  int ret = 0;
  for (int num = 0; num <= lim; num++) {
    int t = rec(digit + 1, smaller || (num < lim), (modD + num) % D);
    Add(ret, t);
  }

  return dp[digit][smaller][modD] = ret;
}

signed main() {
  cin >> K >> D;

  rep (i, 11111) rep (j, 2) rep (k, 111) dp[i][j][k] = -1;

  int ans = rec(0, 0, 0);
  Add(ans, -1LL);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 20480
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int n, m, a[10], cnt[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int d[10002];
string ans[10002];

int dy(int n)
{
	if(n < 0) return -2;
	
	int& ret = d[n];
	string& s = ans[n];

	int here = 0;
	if(ret != -1) return ret;

	for(int i = 1; i <= m; i++)
	{
		int next = dy(n - cnt[a[i]]);

		if(next == -2) continue;
		if(ret < next)
		{
			here = i;
			ret = next;
		}
		else if(ret == next && a[i] > a[here])
		{
			here = i;
		}
	}

	ret = (ret == -1 ? -2 : ret + 1);
	if(ret != -2)
	{
		char ch = a[here] + '0';
		s = ans[n - cnt[a[here]]];
		s.push_back(ch);
	}

	return ret;
}

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= m; i++) cin >> a[i];
	for(int i = 0; i <= n; i++) 
	{
		d[i] = -1;
		ans[i] = "";
	}

	d[0] = 0;
	
	dy(n);
	reverse(ans[n].begin(), ans[n].end());
	cout << ans[n] << '\n';
}

Measured memory_bytes: 39168
n,l = map(int,input().split(" "))

aji = []
aji_abs = []
total = 0
for i in range(n):
  a = l + (i + 1) - 1
  aji.append(a)
  aji_abs.append(abs(a))
  total += a

print(total - aji[aji_abs.index(min(aji_abs))])

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

int N,M;
vint G[1111];

signed main(){
    cin>>N>>M;
    vint A(N);
    rep(i,N)cin>>A[i];
    rep(i,M){
        int a,b;
        scanf("%lld%lld",&a,&b);
        a--;b--;
        G[a].pb(b);
    }

    vint ord;
    vint deg(N);
    rep(i,N)for(auto u:G[i])deg[u]++;
    rep(i,N)if(deg[i]==0)ord.pb(i);
    rep(i,N){
        int v=ord[i];
        for(auto u:G[v]){
            if(--deg[u]==0)ord.pb(u);
        }
    }
    reverse(all(ord));

    vint q(N);
    for(auto v:ord){
        set<int>s;
        for(auto u:G[v])s.insert(q[u]);
        q[v]=0;
        while(s.find(q[v])!=s.end())q[v]++;
    }

    vint x(N);
    rep(i,N)x[q[i]]^=A[i];
    rep(i,N)if(x[i]){
        cout<<1<<endl;
        return 0;
    }
    cout<<2<<endl;
    return 0;
}


Measured memory_bytes: 3388
# -*- coding: utf-8 -*-
 
x = int(input())
#x = 8
 
y = input().split()
#y = ["3","1","4","1","5","9","2","6"]
 
for i in range(x):
    y[i] = int(y[i])
 
Max = max(y)
Min = min(y)
 
ans = Max - Min
 
print(ans)

Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        int[] p = new int[m];
        int[] x = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = sc.nextInt();
            x[i] = sc.nextInt();
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += t[i];
        }
        for (int i = 0; i < m; i++) {
            System.out.println(sum - t[p[i] - 1] + x[i]);
        }
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
string s;
ll n;
int a[11];
ll ans;


int ar[3] = {3,5,7};
void calc(ll num, int f1, int f2, int f3){
    int nn;
    string st;
    for(int i = 0; i < 3; i++){
        nn = num*10+ar[i];
        if(i == 0)  f1++;
        else if(i == 1) f2++;
        else   f3++;

        st = to_string(nn);
        if(st.length() > 9) return;

        if(f1 != 0 && f2 != 0 && f3 != 0){
            if(nn <= n){
                ++ans;
            //  cout << nn << endl;
                calc(nn,f1,f2,f3);
            }
        }
        else{
            calc(nn,f1,f2,f3);
        }
        if(i == 0)  f1--;
        else if(i == 1) f2--;
        else   f3--;
    }
    return;
}

int main(){
    cin >> n;
    int f1=0,f2=0,f3=0;
    calc(3,1,0,0);
    calc(5,0,1,0);
    calc(7,0,0,1);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, s, n, m) for(int i = s; i < (int)(n); i+=m)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

int main()
{
    string S;
    cin >> S;
    S += "R";
    ll N = S.length();
    ll rcnt = 1;
    ll lcnt = 0;
    ll pos = 0;
    vector<ll> ans(N-1, 0);
    rep(i, 1, N, 1) {
        if (S[i] == 'R') {
            if (S[i-1] == 'L') {
                rep(j, 0, rcnt, 1) {
                    if (j % 2 == 0) {
                        ans[pos]++;
                    } else {
                        ans[pos+1]++;
                    }
                }
                rep(j, 0, lcnt, 1) {
                    if (j % 2 == 0) {
                        ans[pos+1]++;
                    } else {
                        ans[pos]++;
                    }
                }

                rcnt=0;
                lcnt=0;
            }
            rcnt ++;
        } else {
            if (S[i-1] == 'R') pos = i-1;
            lcnt++;
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int fc(string s){
  int res = 0;
  rep(i, s.size()){
    res += s.at(i) - '0';
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  int ans = 1001001001;
  rep2(i, 1, n){
    int a = i;
    int b = n-a;
    int add = fc(to_string(a)) + fc(to_string(b));
    ans = min(ans, add);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

    int i=0;
    int e=s.size()-1;
    int m=0;
    while(i<e)
    {
        if(s[i]!=s[e]){ s[i]=s[e]; m++; }
        i++;
        e--;
    }

    cout << m << endl;

    return 0;

}


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

#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define STR(s) string s;cin>>s

int main(){
  STR(x);
  int ans = 0, cnts = 0;
  FOR(it, x){
    if(*it == 'S'){
      cnts++;
    }
    else {
      if (cnts == 0){
        ans++;
      }
      else {
        cnts--;
      }
    }
  }
  ans += cnts;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define Pi 3.1415926535
#define MOD 1000000007;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << endl;}
void no(){cout << "No" << endl;}

int solve(){
    int n; cin >> n;
    vint a(n); rep(i,n) cin >> a[i];
    cout << *max_element(all(a)) - *min_element(all(a)) << endl;

    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 256
fun main() {
    val d = readLine()!!.toInt()
    val c = readLine()!!.split(" ").map { it.toInt() }
    val list = (0 until d).map { readLine()!!.split(" ").map { it.toInt() } }

    val listT = (0 until d).map { readLine()!!.toInt() }

    val executeDate = IntArray(26) { 0 }
    fun last(date: Int): Int =
        (0 until 26).map {
            c[it] * (date - executeDate[it])
        }.sum()

    var last = 0
    (1..d).forEach {
        val exam = listT[it - 1] - 1
        val add = list[it - 1][exam]
        executeDate[exam] = it

        val remove = last(it)
        last += add - remove
        println(last)
    }
}

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

#define MAX 10

int N;
int L[MAX];

int main() {
	cin >> N;
	for( int i = 0; i < N; i++ ) {
		cin >> L[i];
	}

	int mai = max_element( L, L + N ) - L;
	int ma = L[mai];
	int sum = 0;
	for( int i = 0; i < N; i++ ) {
		if( i == mai ) {
			continue;
		}
		sum += L[i];
	}
	int ans = 0;
	if( ma < sum ) {
		ans = 1;
	}

	if( ans  ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<char,int> P;

static const double eps = 10e-9;

int getNum(int num){
	int a = num * num;
	int res=0;
	a/=100;
	for(int i=0;i<4;i++){
		res += (a % 10) * pow(10.0,i);
		a/=10;
	}

	return res;
}

int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			int num;
			scanf("%d",&num);
			printf("Case %d:\n",i+1);
			for(int j=0;j<10;j++){
				num = getNum(num);
				printf("%d\n",num);
			}
		}
	}
}

Measured memory_bytes: 3272
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	ll n, sum1=0,sum2=0,ave1=0,ave2=0;
	cin >> n;
	vector<ll>arr(n);
	rep(i, n)cin >> arr[i];
	sum1 = accumulate(all(arr), 0);
	ave1 = ceil((double)sum1 / n);
	ave2 = sum1 / n;
	sum1 = 0;
	rep(i, n) {
		sum1 += pow((arr[i] - ave1), 2LL);
		sum2 += pow((arr[i] - ave2), 2LL);
	}
	cout << min(sum1,sum2) << endl;
	return 0;
}



Measured memory_bytes: 3728
N,M=map(int,input().split())
a=set()
mod=1000000007
for _ in range(M):
    aa=int(input())
    a.add(aa)
dp=[0]*(N+2)
dp[0]=1
for i in range(0,N):
    if i in a:
        continue
    else:
        dp[i+1]+=dp[i]
        dp[i+2]+=dp[i]
print(dp[N]%mod)


Measured memory_bytes: 468984
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using ll = long long;
using namespace std;

int main() {
	int a, b, c; cin >> a >> b >> c;
	if (b >= a * c) {
		cout << c << endl;
	}
	else {
		cout << b / a << endl;
	}
	  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int f (a-b);
  int ans (c-f);
  if (ans < 0) {
  cout << 0;
  }
  else
  {
    cout << ans;
  }
  
  return 0;
  }


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

using namespace std;

int main()
{
	int a, b ;
    string op;

    while (op != "?"){

        cin >> a >> op >> b;

        if (op == "+") cout << a + b  << endl;
        if (op == "-") cout << a - b  << endl;
        if (op == "*") cout << a * b  << endl;
        if (op == "/") cout << a / b  << endl;
    }
   
    return 0;


}


Measured memory_bytes: 3132
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[7] = {0, 1, 1, 0, -1, -1, 0};
int dy[2][7] = {{1, 0, -1, -1, -1, 0, 0},
                {1, 1, 0, -1, 0, 1, 0}};
struct S{
  int x, y, s, t;
  S(int x, int y, int s, int t) : 
    x(x), y(y), s(s), t(t) {}
  bool operator < (const S& st) const {
    if(s != st.s) return s > st.s;
    if(t != st.t) return t > st.t;
    if(x != st.x) return x > st.x;
    return y > st.y;
  }
};

int main(){
  int sx, sy, gx, gy;
  while(cin>>sx>>sy>>gx>>gy){
    int n;
    bool furnit[201][201] = {};
    int fx[1000], fy[1000];
    cin>>n;
    REP(i, n){
      cin>>fx[i]>>fy[i];
    }
    int W, H;
    cin>>W>>H;
    REP(i, n){
      furnit[fy[i] + H][fx[i] + W] = true;
    }
    sx += W; sy += H; gx += W; gy += H;
    priority_queue<S> que;
    que.push(S(sx, sy, 0, 0));
    int ans = -1;
    bool used[201][201][6] = {};
    while(!que.empty()){
      S s = que.top(); que.pop();
      if(s.x == gx && s.y == gy) {
        ans = s.s;
        break;
      }
      if(used[s.y][s.x][s.t]) continue;
      used[s.y][s.x][s.t] = true;
      int dir = abs((s.x - W) * (s.y - H) * s.t) % 6;
      //printf("x = %d y = %d s = %d t = %d dir = %d\n", s.x - W, s.y - H, s.s, s.t, dir);
      for(int r = 0; r < 7; r++){
        S next(s.x + dx[r], s.y + dy[abs(s.x - W) % 2][r], (dir == r) ? s.s : (s.s + 1), (s.t + 1) % 6);
        //printf("next[%d]: x = %d y = %d s = %d t = %d ", r, next.x - W, next.y - H, next.s, next.t);
        if(valid(next.x, next.y, 2 * W + 1, 2 * H + 1) && !furnit[next.y][next.x] && !used[next.y][next.x][next.t]){
          //printf("OK");
          que.push(next);
        }
        //printf("\n");
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1948
import java.lang.Math

fun main(args: Array<String>) {
    // drkenさんの解説を見て書く
    // http://drken1215.hatenablog.com/entry/2020/01/19/025500
    val INF = 1 shl 29
    val N = readInputLine().toInt()
    val AArr = readInputLine().split(" ").map { it.toInt() }.toIntArray()
    val BArr = readInputLine().split(" ").map { it.toInt() }.toIntArray()

    // ビットが立っているカードを使用してソート済みの際に、ソート済み範囲最も右側の数値を指定した際の操作数
    val dp = Array(1 shl N) { IntArray(51) { INF } }
    dp[0][0] = 0
    for (bit in 0 until (1 shl N)) {
        // 使用したカードの総数
        var used = 0
        for (i in 0 until N) {
            if (bit and (1 shl i) != 0) {
                used++
            }
        }

        // 使用していないカードを、ソート済み範囲の外に配置した際の(元の位置, 移動後位置)のリスト
        // ソート済み範囲外はソートする必要はない
        val unusedPoints = mutableListOf<Pair<Int, Int>>()
        var iter = used
        for (i in 0 until N) {
            if (bit and (1 shl i) == 0) {
                unusedPoints.add(Pair(i, iter))
                iter++
            }
        }

        // bitで表される使用カード状態に、新たに1枚カードを加える際のDP配る操作
        for (s in 0..50) {
            if (dp[bit][s] >= INF) {
                // 最も右側のカード数値を表せる操作がないときは配らない
                continue
            }
            for (p in unusedPoints) {
                val next = if (Math.abs(p.first - used) % 2 == 0) AArr[p.first] else BArr[p.first]
                if (next >= s) {
                    // next < sの場合は広義単調増加を満たせないのでスキップ
                    dp[bit or (1 shl p.first)][next] =
                        Math.min(dp[bit or (1 shl p.first)][next],
                                 dp[bit][s] + Math.abs(p.second - used))
                }
            }
        }
    }

    val ans = dp[(1 shl N) - 1].min()!!
    println(if (ans < INF) ans else -1)
}

fun readInputLine(): String {
    return readLine()!!
}


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

using namespace std;

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;

	ll numways = k;

	for (int i = 1; i < n; i++) {
		numways *= k - 1;
	}

	cout << numways << endl;
	
    return 0;
}


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

#define REP(i, x) for (int i = 1; i <= (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  int A[20];
  int B[20];
  int C[20];

  long result = 0;
  
  cin >> N;
  REP(i, N) {cin >> A[i];}
  REP(i, N) {cin >> B[i];}
  REP(i, N-1) {cin >> C[i];}

  int last_a = -100;
  REP(i, N){
    result += B[A[i]];
    if(A[i] - last_a == 1){
      result += C[last_a];
    }
    last_a = A[i];
  }

  cout << result << endl;

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int t[n], x[n], y[n];
  for ( int i = 1; i <= n; i++){
    cin >> t[i] >> x[i] >> y[i];
  }
  t[0] = x[0] = y[0] = 0;
  int dt, dx, dy;
  bool flag = true;
  for ( int i = 1; i <= n; i++){
    dt = t[i] - t[i-1];
    dx = abs(x[i] - x[i-1]);
    dy = abs(y[i] - y[i-1]);
    if ( ( dt < dx + dy ) || (dt%2 != (dx+dy)%2) ){
      flag = false;
      break;
    }
  }

  if ( flag ){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int A, B; cin >> A >> B;
  string S; cin >> S;
  
  string SA = S.substr(0,A);
  char Sh = S.at(A);
  string SB = S.substr(A+1);
  
  if (count(all(SA),'-') || Sh != '-' || count(all(SB),'-')) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}



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

int main(){
    int d;
    cin >> d;
    vector<int> c(26);
    int s[d][26];
    const int n = 26;
    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];
        }
    }
    map<int,int> last;
    for(int now = 0; now < d; now++){
        int ct;
        int mx = -mod;
        for(int i = 0; i < n; i++){
            int can = 0;
            can += s[now][i];
            for(int j = 0; j < n; j++){
                if(i == j) continue;
                can -= c[j]*(now+1-last[j]);
            }
            if(mx < can){
                mx = can;
                ct = i;
            }
        }
        last[ct] = now+1;
        cout << ct+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b; cin >> a >>b;
	cout << 2 * b - a;
	


	cout << endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int a[11];
string s;

int main(){
	cin>>s;
  rep(i,4)a[i]=s[i]-'0';
  rep(S,1<<3){
    int c=a[0];
    rep(j,3){
      if((S>>j)&1)c+=a[j+1];
      else c-=a[j+1];
    }
    if(c==7){
      cout<<a[0];
      rep(j,3){
        if((S>>j)&1)cout<<"+"<<a[j+1];
        else cout<<"-"<<a[j+1];
      }
      cout<<"=7"<<endl;
      return 0;
    }
  }
	return 0;
}


Measured memory_bytes: 256
MAX = 1005
  
for cno in range(1, 100):
    lim = int(input())
    if lim == 0: break
    print("Case ", cno, ":", sep='')
    N = int(input())
    V = [[0 for j in range(MAX)] for i in range(2)]
    W = [[0 for j in range(MAX)] for i in range(2)]     
    k1, k2 = 0, 1
    for i in range(1, N+1):
        v, w = map(int, input().split(','))
        for j in range(1, w):
            V[k2][j] = V[k1][j]
            W[k2][j] = W[k1][j]
        for j in range(w, lim+1):
            d = j - w
            if V[k1][d] + v >= V[k1][j]:
                V[k2][j] = V[k1][d] + v
                W[k2][j] = W[k1][d] + w
            else:
                V[k2][j] = V[k1][j]
                W[k2][j] = W[k1][j]
        k1, k2 = k2, k1
    print(V[k1][lim], W[k1][lim], sep='\n')


Measured memory_bytes: 5728
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, u, v = map(int, readline().split())
m = map(int,read().split())
data = list(zip(m,m))

graph = [[] for _ in range(n+1)]
for a,b in data:
    graph[a].append(b)
    graph[b].append(a)

def dfs(v):
    dist = [None] * (n + 1)
    dist[v] = 0
    stack = [v]
    while stack:
        x = stack.pop()
        for y in graph[x]:
            if dist[y] is None:
                dist[y] = dist[x] + 1
                stack.append(y)
    return dist
res = 0
du, dv = dfs(u), dfs(v)
for i in range(1, n+1):
    dvi = dv[i]
    if du[i] <= dvi:
        if dvi > res:
            res = dvi
print(res - 1)

Measured memory_bytes: 36316
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////
double M_PIi = 3.141592653589793;

int main() {

	int N, M;
	cin >> N >> M;
	vector<vector<int>> gate(N, vector<int>());

	vector<int> Used(N, -1);

	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		gate[a].push_back(b);
		gate[b].push_back(a);
	}

	queue<int> Q;
	Q.push(0);

	while (!Q.empty()) {
		int q = Q.front();
		Q.pop();

		rep(i,gate[q].size()) {
			if (Used[gate[q][i]] == -1) {
				Used[gate[q][i]] = q;
				Q.push(gate[q][i]);
			}
		}	
	}

	cout << "Yes" << endl;
	rep(i, N-1) {
		cout << Used[i+1] + 1<< endl;
	}

	return 0;
}


Measured memory_bytes: 10284
# -*- coding: utf-8 -*-
import sys
from functools import reduce

MAX_INT = 2**62-1
sys.setrecursionlimit(10**7)

input = sys.stdin.readline

# @profile
MOD = 10**9 + 7


def mul_mod(*args, mod=MOD):
    return reduce(lambda a, b: a * b % mod, args)


def solve(g, f, fi, m):
    mul = mul_mod

    stack = [(0, 1)]
    pre_order = []
    n = len(g) - 1

    while stack:
        pre, cur = stack.pop()
        pre_order.append((pre, cur))

        for nxt in g[cur]:
            if nxt == pre:
                continue
            stack.append((cur, nxt))

    size = [1] * (n+1)
    dp = [1] * (n+1)

    for pre, cur in reversed(pre_order):
        dp[cur] = mul(dp[cur], f[size[cur]-1])
        dp[pre] = mul(dp[pre], dp[cur], fi[size[cur]])
        size[pre] += size[cur]

    ans = [1] * (n+1)
    ans[1] = dp[1]

    for pre, cur in pre_order[1:]:
        i = size[cur]
        temp = mul(ans[pre], f[n-i-1], fi[n-1], f[i], pow(dp[cur], m-2, m))
        ans[cur] = mul(f[n-1], temp, fi[n-i], dp[cur], fi[i-1])
    print(*ans[1:], sep='\n')


# @profile
def main():
    mul = mul_mod
    mod = MOD
    n = int(input())
    g = [[] for _ in range(n+1)]

    fact = [1] * (n+1)
    fact_inv = [0] * (n+1)

    for i in range(1, n+1):
        fact[i] = mul(fact[i-1], i)

    fact_inv[-1] = pow(fact[-1], mod-2, mod)

    for i in range(n)[::-1]:
        fact_inv[i] = mul(fact_inv[i+1], (i+1))

    for _ in range(n-1):
        a, b = map(int, input().split())
        g[a].append(b)
        g[b].append(a)

    solve(g, fact, fact_inv, mod)


if __name__ == "__main__":

    main()


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

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b){
        printf("a < b\n");
    }
    if(a>b){
        printf("a > b\n");
    }
    if(a==b){
        printf("a == b\n");
    }
    
    return 0;
}


Measured memory_bytes: 3128