akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 4e5 + 17;

int nn;

struct segtree
{
	vector< pair<int, int> > T;
	segtree() { }

	segtree(int n)
	{
		nn = n;
		T.resize(4 * n);

		forn (i, 4 * n)
			T[i] = make_pair((int) inf, (int) inf);
	}

	void upd(int i, int x, int v = 1, int l = 0, int r = nn - 1)
	{
		if (l == r)
			T[v] = make_pair(x, i);
		else
		{
			int m = (l + r) / 2;
			i <= m ? upd(i, x, 2 * v, l, m) : upd(i, x, 2 * v + 1, m + 1, r);
			T[v] = min(T[2 * v], T[2 * v + 1]);
		}
	}

	pair<int, int> get(int lq, int rq, int v = 1, int l = 0, int r = nn - 1)
	{
		if (l > rq || r < lq)
			return make_pair(inf, inf);

		if (lq <= l && r <= rq)
			return T[v];
		
		int m = (l + r) / 2;
		return min(get(lq, rq, 2 * v, l, m), get(lq, rq, 2 * v + 1, m + 1, r));
	}
};

struct range
{
	int l, r, p;
	range() { }
	range(int l, int r, int p) : l(l), r(r), p(p) { }
};

struct cmp
{
	const bool operator()(range a, range b) { return a.p > b.p || (a.p == b.p && a.l < b.l); }
};

int n;
int p[maxn];
segtree ev, od;

bool read()
{
	if (scanf("%d", &n) != 1)
		return false;

	forn (i, n)
		scanf("%d", p + i);

	return true;
}

void solve()
{
	ev = od = segtree(n);

	forn (i, n)
		if (i & 1)
		{
			od.upd(i, p[i]);
			ev.upd(i, inf);
		}
		else
		{
			ev.upd(i, p[i]);
			od.upd(i, inf);
		}

	vector<int> ans;
	priority_queue<range, vector<range>, cmp> q;
	q.push(range(0, n - 1, ev.get(0, n - 1).first));

	while (!q.empty())
	{
		auto cur = q.top();
		q.pop();
		int lq = cur.l, rq = cur.r;
		pair<int, int> ft, sc;

		if (lq & 1 ^ 1)
		{
			ft = ev.get(lq, rq);
			sc = od.get(ft.second, rq);
		}
		else
		{
			ft = od.get(lq, rq);
			sc = ev.get(ft.second, rq);
		}

		ans.push_back(ft.first);
		ans.push_back(sc.first);

		if (lq < ft.second - 1)
		{
			int p = ((lq & 1 ^ 1) ? ev.get(lq, ft.second - 1) : od.get(lq, ft.second - 1)).first;
			q.push(range(lq, ft.second - 1, p));
		}

		if (ft.second + 1 < sc.second - 1)
		{
			int p = ((ft.second & 1) ? ev.get(ft.second + 1, sc.second - 1) : od.get(ft.second + 1, sc.second - 1)).first;
			q.push(range(ft.second + 1, sc.second - 1, p));
		}

		if (sc.second + 1 < rq)
		{
			int p = ((sc.second & 1) ? ev.get(sc.second + 1, rq) : od.get(sc.second + 1, rq)).first;
			q.push(range(sc.second + 1, rq, p));
		}
	}

	for (auto i : ans)
		printf("%d ", i);

	printf("\n");
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	read();
	solve();

	return 0;
}


Measured memory_bytes: 16268
line = input().split(" ")
h = int(line[0])
w = int(line[1])
arr =[]
for i in range(h):
    arr.append(input())

for i in range(w+2):
    print("#", end="")
print()

for i in arr:
    print("#"+i+"#")

for i in range(w+2):
    print("#", end="")
print()


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  int N, Y;
  scanf("%d %d", &N, &Y)+1;

  Y /= 1000;

  if (Y < N || N * 10 < Y) {
    printf("-1 -1 -1\n");
    return 0;
  }

  for (int y10 = 0; y10 <= N; y10++) {
    for (int y5 = 0; y5 <= N - y10; y5++) {
      int y1 = N - y10 - y5;
      if (y10 * 10 + y5 * 5 + y1 == Y) {
        printf("%d %d %d\n", y10, y5, y1);
        return 0;
      }
    }
  }

  printf("-1 -1 -1\n");
  return 0;
}


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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	set<char> arr[2] = {{'R', 'U', 'D'}, {'L', 'U', 'D'}};
	string s;
	cin >> s;
	for(int i=0; i<s.size(); i++) {
		if(!arr[i&1].count(s[i])) {
			return !(cout << "No");
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    long long n, a, b;
    cin >> n >> a >> b;
    long long sets = n/(a+b);
    long long amaris = n%(a+b)>a?a:n%(a+b);
    long long sum = a*sets + amaris;
    cout << sum << endl;
    return 0;
}

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

int H,W;
    
int bfs(vector<string> S,int sx,int sy){
    

    int F[H][W];
    for(int i = 0 ; i < H;i++){
        for(int j = 0; j < W;j++){
            F[i][j]=0;
            if(S[i][j]=='.'){
                F[i][j]=-100;
            }
        }
    }
    //cout << S[0][0]<<endl;
    bool flag= false;
    for(int i = 0 ; i < H;i++){
        for(int j = 0; j < W;j++){
            if(S[i][j]=='.'){
                //sx = i,sy = j;
                flag = true;
                //cout << i << j <<endl;
                break;
            }
        }
        if(flag)break;
    }
    
    queue<pair<int,int>> que;
    //cout <<"#"<< sx << sy<<endl;
    que.push(make_pair(sx,sy));
    F[sx][sy]=0;
    //cout <<F[0][0]<<endl;
    int x,y,gx,gy;
    vector<int> vec1 = {1,0,-1,0};
    vector<int> vec2 = {0,1,0,-1};
    
    //int cont = 0;
    //cout << "a"<<endl;
    bool flag2;
    while(que.size() > 0){
        //cout << "a"<<endl;
        
        
    //          cout <<"############"<<endl;
    // for(int i = 0 ; i < H;i++){
    //     for(int j = 0; j < W;j++){
            
    //         cout << F[i][j];

    //     }
    //     cout <<endl;
    // }
    // cout <<"############"<<endl;
        
        
        
        
        
        
        x = que.front().first;
        y = que.front().second;
        que.pop();
        int res = 0;
        res = max(res,F[x][y]);
        //cout << "XX"<<res <<endl;
        for(int i = 0; i < 4;i++){
            //cout <<"-------#"<<  x+vec1[i]  <<" "<<y+vec2[i]  <<endl;
            if(0 <= x+vec1[i] && x+vec1[i] < H  
            && 0 <= y+vec2[i] && y+vec2[i] < W ){
                //cout <<"##"<<S[x+vec1[i]][y+vec2[i]]<<"#"<<F[x+vec1[i]][y+vec2[i]]<<endl;
                if(S[x+vec1[i]][y+vec2[i]]=='.'&&F[x+vec1[i]][y+vec2[i]]==-100){
                    gx = x+vec1[i];
                    gy = y+vec2[i];
                    F[x+vec1[i]][y+vec2[i]] = res+1;
                    que.push(make_pair(x+vec1[i],y+vec2[i]));
                    
                }
            }
            
        }
        
    //  cout <<"############"<<endl;
        flag2 = true;
        for(int i = 0 ; i < H;i++){
            for(int j = 0; j < W;j++){
                
                if(F[i][j]==-100)flag2 = false;
    
            }
            
        }
        if(flag2)break;
    // cout <<"############"<<endl;
        

    }
    
    //  cout <<"############"<<endl;
    // for(int i = 0 ; i < H;i++){
    //     for(int j = 0; j < W;j++){
            
    //         cout << F[i][j];

    //     }
    //     cout <<endl;
    // }
    // cout <<"############"<<endl;

    // cout << cont <<endl;    
    //cout <<"ans:"<<F[x][y]<<endl;
    return F[gx][gy];
    
}    

int main(){
    

    cin >> H >> W;

    vector<string> S(H);
    
    for(int i = 0; i < H;i++){
        cin >> S[i];
    }
    
    int res = 0;
    for (int x = 0; x < H; ++x) {
        for (int y = 0; y < W; ++y) {
            if (S[x][y] == '#') continue;
            res = max(res, bfs(S, x, y));
        }
    }
    
    cout << res << endl;
}


Measured memory_bytes: 256
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)

type queue struct {
  Processes []*process
}

func (qu *queue) enqueue(p *process) {
  qu.Processes = append(qu.Processes, p)
}

func (qu *queue) dequeue() *process {
  data := qu.Processes[0]
  qu.Processes = qu.Processes[1:]
  return data
}

type process struct {
  Name string
  Time int
}

func newProcess(name string, time int) *process {
  return &process{
    Name: name,
    Time: time,
  }
}

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Scan()
  t := strings.Fields(sc.Text())
  n, _ := strconv.Atoi(t[0])
  q, _ := strconv.Atoi(t[1])

  var qu queue
  for i := 0; i < n; i++ {
    sc.Scan()
    t = strings.Fields(sc.Text())
    time, _ := strconv.Atoi(t[1])
    qu.enqueue(newProcess(t[0], time))
  }

  currentTime := 0
  for len(qu.Processes) > 0 {
    data := qu.dequeue()
    if data.Time - q <= 0 {
      fmt.Printf("%s %d\n", data.Name, data.Time + currentTime)
      currentTime += data.Time
    } else {
      data.Time -= q
      qu.enqueue(data)
      currentTime += q
    }
  }
}


Measured memory_bytes: 7272
#include<cstdio>
#include<algorithm>
#include<queue>

#define INF 1<<29

using namespace std;

int main(){
	while(1){
		int n,m;
		scanf("%d%d",&m,&n);
		if(m==0 && n==0){
			break;
		}
		int cost[101][101];
		int time[101][101];
		
		for(int i=0;i<101;i++)
		for(int j=0;j<101;j++)
		cost[i][j]=time[i][j]=INF;
		
		for(int i=0;i<m;i++){
			int a,b,c,d;
			scanf("%d%d%d%d",&a,&b,&c,&d);
			cost[a][b]=cost[b][a]=c;
			time[a][b]=time[b][a]=d;
		}
		
		for(int k=1;k<=n;k++){
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
					time[i][j]=min(time[i][j],time[i][k]+time[k][j]);
				}
			}
		}
		
		scanf("%d",&m);
		for(int i=0;i<m;i++){
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			if(c==0){
				printf("%d\n",cost[a][b]);
			}else{
				printf("%d\n",time[a][b]);
			}
		}
	}
}

Measured memory_bytes: 848
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long n = sc.nextLong();
		int MOD = 1000000007;
		
		// 計算
		long result = 1;
		for(int i = 0; i < n; i++){
		    result *= 10;
		    result %= MOD;
		}
		long a = 1;
		for(int i = 0; i < n; i++){
		    a *= 9;
		    a %= MOD;
		}
		long b = 1;
		for(int i = 0; i < n; i++){
		    b *= 8;
		    b %= MOD;
		}
		result -= a;
		result += MOD;
		result %= MOD;
		result -= a;
		result += MOD;
		result %= MOD;
		result += b;
		result %= MOD;
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}

}


Measured memory_bytes: 25804
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>
#include<set>
#include<array>
#include<cassert>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;

const int MAX=101;
const int INF=1<<25;
int n,m,c,s,g;

//??????????????????0???????????????????????¨
vector<vector<vector<int>>> G(21,vector<vector<int>>(MAX,vector<int>(MAX,INF)));
//????????¨
int p[50];
int q[21][50];
int r[21][51];

int cal(int dist,int cam){
	int money=0;
	if(dist==INF) return INF;
	rep(i,50){
		if(q[cam][i] >= dist){
			if(i==0) money+=r[cam][i]*dist;
			else money+=(dist-q[cam][i-1])*r[cam][i]; //?¶?????????´???
			break;
		}	
		if(q[cam][i] <= dist){
			if(i==0)money+=q[cam][i]*r[cam][i]; //?¶??????????????????´???
			else money+=(q[cam][i]-q[cam][i-1])*r[cam][i];
		}
	}
	return money;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		cin >> n >> m >> c >> s >> g;
		if(n==0&&m==0&&c==0&&s==0&&g==0) break;
		s--;g--;
		G.clear();
		G.resize(21);
		rep(i,21){ G[i].resize(MAX); rep(j,MAX) G[i][j].resize(MAX,INF);}
		fill_n((int *)q,sizeof(q)/sizeof(int),INF);
		fill_n((int *)r,sizeof(r)/sizeof(int),INF);
		fill_n((int *)p,sizeof(p)/sizeof(int),INF);

		for(int i=1;i<=m;i++){
			int x,y,d,c;
			cin >> x >> y >> d >> c;
			x--;y--;
			G[c][x][y]=min(G[c][x][y],d);	
			G[c][y][x]=min(G[c][y][x],d);	
		}
		
		for(int i=1;i<=c;i++){
			cin >> p[i];
		}
		
		rep(i,c){
			rep(j,p[i+1]-1) cin >> q[i+1][j];
			rep(j,p[i+1]) cin >> r[i+1][j];
		}
		//?????????????????????????¨????
		for(int l = 1;l<=c;++l)
			for(int k = 0; k < n; ++k)
				for(int i = 0; i < n; ++i)
					for(int j = 0; j < n; ++j){
						G[l][i][j] = min(G[l][i][j], G[l][i][k] + G[l][k][j]);
						G[0][i][j] = min(cal(G[l][i][j],l),G[0][i][j]);
					}
		
		/*
		for(int i=0;i<=c;i++) rep(j,n) rep(k,n){
			G[0][j][k] = min(G[c][j][k],G[0][j][k]);	
		}*/
		
		//??????????¨????
		for(int k = 0; k < n; ++k)
			    for(int i = 0; i < n; ++i)
					      for(int j = 0; j < n; ++j) G[0][i][j] = min(G[0][i][j], G[0][i][k] + G[0][k][j]);
	
		if(G[0][s][g]==INF) cout << -1 << endl;
		else cout << G[0][s][g] << endl;
	}	
	
	return 0;
}

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

typedef long long ll;
ll MOD = 1000000007;

int main()
{
    int n, x, now = 0, c = 0; 
    cin >> n >> x;
    vector <int> l(n,0);
    for (int i = 0; i < n; i++) cin >> l[i];

    for (int i = 0; i < n; i++) {
        //cout << now << endl;
        if (now <= x) c++;
        now += l[i];
    }
    if (now <= x) c++;
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;


int main(){
  string s;
  cin >> s;
  if(s == "A") printf("T\n");
  else if(s == "C") printf("G\n");
  else if(s == "G") printf("C\n");
  else if(s == "T") printf("A\n");
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,pair<int,int> > p[30000];
int main(){
	int a,b;
	int sz=0;
	for(int i=1;i<=150;i++){
		for(int j=i+1;j<=150;j++){
			p[sz++]=make_pair(i*i+j*j,make_pair(i,j));
		}
	}
	std::sort(p,p+sz);
	while(scanf("%d%d",&a,&b),a){
		pair<int,pair<int,int> >q=make_pair(a*a+b*b,make_pair(a,b));
		pair<int,pair<int,int> >r=*upper_bound(p,p+sz,q);
		printf("%d %d\n",r.second.first,r.second.second);
	}
}

Measured memory_bytes: 1380
package main

import (
	"fmt"
)

func main() {
	var N, X, M int
	fmt.Scanf("%d%d%d", &N, &X, &M)

	if N <= M || M == 1 {
		sum := 0
		Ai := X
		for i := 0; i < N; i++ {
			sum += Ai
			Ai = (Ai * Ai) % M
			if Ai == 0 {
				break
			}
		}
		fmt.Println(sum)
		return
	}

	i2sum := make([]int, M)
	Ai2i := make([]int, M)
	for i := 0; i < M; i++ {
		Ai2i[i] = -1
	}
	var k, l int
	var sum_k, sum_kl, sum_lN int
	Ai := X
	for i := 0; i < M; i++ {
		i2sum[i] = Ai
		if i > 0 {
			i2sum[i] += i2sum[i-1]
		}
		if Ai2i[Ai] != -1 {
			k, l = Ai2i[Ai], i
			sum_k, sum_kl, sum_lN = 0, i2sum[l-1], 0
			if (N-k)%(l-k)+k-1 > 0 {
				sum_lN = i2sum[(N-k)%(l-k)+k-1]
			}
			if k > 0 {
				sum_k = i2sum[k-1]
				sum_kl -= i2sum[k-1]
				sum_lN -= i2sum[k-1]
			}
			fmt.Println(sum_k + (sum_kl * ((N - k) / (l - k))) + sum_lN)
			return
		}
		Ai2i[Ai] = i
		Ai = (Ai * Ai) % M
	}
}


Measured memory_bytes: 3048
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    auto calc = [&](int mask) {
        long long sum = 0;
        for (int j = 0; j < n; j++) if ((a[j] & mask) == a[j]) sum += b[j];
        return sum;
    };
    long long ans = calc(k);
    for (int i = 0; i < 31; i++) if (k >> i & 1) {
        int mask = (k ^ (1 << i)) | ((1 << i) - 1);
        ans = max(ans, calc(mask));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <stack>      //std::stack
#include <string>
#include <stdlib.h>
using namespace std;

int main(void)
{
    string stack[200];
    std::stack<int> myStack;
    int i = 0;                          //genzaichi

    while(cin >> stack[i])
    {
        int data01, data02;
        if(stack[i] == "+")             //addition
        {
            data01 = myStack.top();
            myStack.pop();
            data02 = myStack.top();
            myStack.pop();
            myStack.push(data01+data02);
        }
        else if(stack[i] == "-")         //subtraction
        {
            data01 = myStack.top();
            myStack.pop();
            data02 = myStack.top();
            myStack.pop();
            myStack.push(data02-data01);
        }
        else if(stack[i] == "*")       //multiplication
        {
            data01 = myStack.top();
            myStack.pop();
            data02 = myStack.top();
            myStack.pop();
            myStack.push(data01*data02);
        }
        else
        {
            myStack.push(atoi(stack[i].c_str()));
        }
    }

    cout << myStack.top() << endl;      //Calculation result
    return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <string>
using namespace std;

#define int long long
#define rep(n, i) for (int i = 0; i < n; i++)
#define rep2(n, m, i) for (int i = m; i < n; i++)
#define rep_r(n, i) for (int i = n - 1; i >= 0; i--)

const int MOD = 1e9 + 7;
const int MAX_LEN = 1e5 + 1;

int dp[MAX_LEN][4];

signed main() {
    string s;
    cin >> s;
    const string ABC = "ABC";
    int len_s = s.size();
    dp[len_s][3] = 1;
    rep(3, i) {
        dp[len_s][i] = 0;
    }

    rep_r(len_s, i) {
        int m = (s[i] == '?') ? 3 : 1;
        dp[i][3] = m * dp[i + 1][3];
        dp[i][3] %= MOD;
        rep_r(3, j) {
            int m1 = m;
            int m2 = (s[i] == '?' || s[i] == ABC[j]) ? 1 : 0;
            dp[i][j] = m1 * dp[i + 1][j] + m2 * dp[i + 1][j + 1];
            dp[i][j] %= MOD;
        }
    }
    cout << dp[0][0] << endl;
}

Measured memory_bytes: 3584
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var (
		a int
		b string
	)
	fmt.Scan(&a, &b)
	b = strings.Replace(b, ".", "", -1)
	ib, _ := strconv.Atoi(b)
	fmt.Println(a * ib / 100)
}


Measured memory_bytes: 1820
#include <iostream>
#include <limits>

static const uint32_t MAX_VALUE = 100100;
static const uint32_t MAX_N = 110;
static const uint64_t I = 1LL << 60;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  uint32_t N;
  uint64_t W;

  uint32_t v[MAX_N];
  uint64_t w[MAX_N];

  uint64_t dp[MAX_N][MAX_VALUE];

  std::cin >> N >> W;
  for (uint32_t i = 0; i < N; i++) {
    std::cin >> w[i] >> v[i];
  }

  for (uint32_t i = 0; i < MAX_N; i++) {
    for (uint32_t j = 0; j < MAX_VALUE; j++) dp[i][j] = I;
  }

  dp[0][0] = 0;

  for (uint32_t i = 0; i < N; i++) {
    for (uint32_t j = 0; j < MAX_VALUE - 1; j++) {
      if (j >= v[i]) {
        dp[i + 1][j] = std::min(dp[i][j - v[i]] + w[i], dp[i + 1][j]);
      }
      dp[i + 1][j] = std::min(dp[i][j], dp[i + 1][j]);
    }
  }

  uint64_t value = 0;
  for (uint32_t i = 0; i < MAX_VALUE; i++) {
    if (dp[N][i] > 0 && dp[N][i] <= W) {
      value = i;
    }
  }

  std::cout << value << std::endl;

  return 0;
}


Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << max(a - b * 2, 0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

typedef struct{
    int num;
    int sum;
} teams;

void q_sort(teams data[], int begin, int end);

int main(int argc, const char * argv[])
{
    int num = 0;
    while (1) {
        scanf("%d", &num);
        if (num == 0) {
            break;
        }
        teams data[1000000];
        int m[4], s[4];
        for (int i = 0; i < num; i++) {
            data[i].sum = 0;
            scanf("%d %d %d %d %d %d %d %d %d", &data[i].num, &m[0], &s[0], &m[1], &s[1], &m[2], &s[2], &m[3], &s[3]);
            for (int k = 0; k < 4; k++) {
                data[i].sum += m[k] * 60 + s[k];
            }
        }
        q_sort(data, 0, num - 1);
        for (int i = 0; i < 2; i++) {
            printf("%d\n", data[i].num);
        }
        printf("%d\n", data[num - 2].num);
    }
    return 0;
}

void q_sort(teams data[], int begin, int end){
    int i = begin;
    int k = end;
    teams pivot = data[(begin + end) / 2];
    teams temp;
    while (1) {
        while (data[i].sum < pivot.sum) {
            i++;
        }
        while (pivot.sum < data[k].sum) {
            k--;
        }
        if (i >= k) {
            break;
        }
        temp = data[i];
        data[i] = data[k];
        data[k] = temp;
        i++;
        k--;
    }
    if (begin < i - 1) {
        q_sort(data, begin, i - 1);
    }
    if (k + 1 < end) {
        q_sort(data, k + 1, end);
    }
}

Measured memory_bytes: 1232
#include <cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n;
	double a[100];
	scanf("%d",&n);
	rep(i,n) scanf("%lf",a+i);

	double ans=0;
	rep(i,n) ans+=1/a[i];
	printf("%f\n",1/ans);

	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int q =sc.nextInt();
		long[] a=new long[n+1];
		long[] sum=new long[n+1];
		long[] sum2=new long[n+1];
		for(int i=1; i<=n; i++){
			a[i]=sc.nextLong();
			sum[i]=sum[i-1]+a[i];
			if(i%2==0){
				sum2[i]=a[i]+sum2[i-1];
			}else{
				sum2[i]=sum2[i-1];
			}
		}
		int right=0;
		int left=0;
		for(int i=0; i<q; i++){
			right=-1;
			left=(n-1)/2;
			long x=sc.nextLong();
			if(Math.abs(x-a[n-2*left])<=Math.abs(x-a[n-left])){
				System.out.println(sum[n]-sum[n/2]);
				continue;
        	}
			while(left-right>1){
				int mid=(right+left)/2;
				if(Math.abs(x-a[n-mid])<Math.abs(x-a[n-mid*2])){
					left=mid;
				}else{
					right=mid;
				}
			}
			long two=0;
			if(n%2==0){
				two=sum2[n-2*left];
			}else{
				two=sum[n-2*left]-sum2[n-2*left];
			}
			System.out.println(sum[n]-sum[n-left]+two);
		}
	}
}


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

typedef long long ll;
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define endl '\n'
const int N = 5e5 + 10;
using namespace std;

int main() {
    IO;
    int n;
    cin >> n;
    map<int, int> cnt;
    for (int i = 1; i <= 100; ++i) {
        for (int j = 1; j <= 100; ++j) {
            for (int k = 1; k <= 100; ++k) {
                int ans = i * i + j * j + k * k + i * j + j * k + k * i;
                cnt[ans]++;
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << cnt[i] << endl;
    }


}

Measured memory_bytes: 5452
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int n = Integer.parseInt(sc.next());
int[] t=new int[n+1];
for (int i = 1; i <= n; i++) {t[i]=Integer.parseInt(sc.next());}
int m = Integer.parseInt(sc.next());
int[] p=new int[m+1];
int[] x=new int[m+1];
for (int i = 1; i <= m; i++) {p[i]=Integer.parseInt(sc.next());x[i]=Integer.parseInt(sc.next());}
int ans=0;
for(int i:t){
    ans+=i;
}
for (int i =1; i <= m; i++) {out.println(ans-t[p[i]]+x[i]);}
}}

Measured memory_bytes: 21716
import sys 
a = list(map(int,input().split()))

N = a[0]
M = a[1]

b = ['0']*N

for i in range(0,M):
    x = list(map(str,input().split()))
    if b[int(x[0])-1] != '0' and b[int(x[0])-1] != x[1]: #既に与えられたところに違う値
        print('-1')
        sys.exit()
    elif N >= 2 and x[0] == '1' and x[1] == '0': #the first digit is  "0"
        print('-1')
        sys.exit()
    else:
        b[int(x[0])-1] = x[1]

if N != 1 and b[0] == '0':
    b[0] = '1'

ans = ''.join(b)
print(ans)


Measured memory_bytes: 3064
h, w = map(int, input().split())
S = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j] == '#':
            continue
        cnt = 0
        for dx in [-1, 0, 1]:
            for dy in [-1, 0, 1]:
                if not 0 <= i+dy <h  or not 0 <= j+dx < w:
                    continue
                if S[i+dy][j+dx] == '#':
                    cnt += 1
        S[i][j] = str(cnt)
for s in S:
    print("".join(s))


Measured memory_bytes: 3188
/*input
1000000
*/
/*
***IT'S OUR LONG WAY TO THE OIILLLL***
 
 
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░███░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░█▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▀██████████████████████████████████████████████████
░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █████
░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░
*/
//010000000010
#include<bits/stdc++.h>
#define ll          long long
#define pb          emplace_back
#define endl        '\n'
#define pi         pair<ll int,ll int>
#define vi          vector<int>
#define vll          vector<ll int>
#define vpi          vector<pair<int,int>>
#define vpll          vector<pair<ll int,ll int>>
#define all(a)      (a).begin(),(a).end()
#define allr(a)      (a).rbegin(),(a).rend()
#define sz(x)       (ll int)x.size()
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define tr(x,t)      for(t=x.begin();t!=x.end();t++)
#define mp          make_pair
#define inf 1000000000
#define hell 1000000000
#define fi first
#define se second
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    ll t=1;
    //cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;
        ll ans=0;
        for (int i = 1; i < n+1; ++i)
        {
            /* code */
            if(i%3!=0&&i%5!=0)
                ans+=i;
        }
        cout << ans;    
    }

    return 0;
}   

Measured memory_bytes: 3640
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;



int main(void)
{
    int h,n;
    cin >>h >>n;


    vector<int> a;
    vector<int> b;
    for(int i = 0; i < n; i++){
        int ta,tb;
        cin >>ta >>tb;
        a.push_back(ta);
        b.push_back(tb);
    }
    int init = 999999999;
    vector<int> dp(h+10000, init);

    dp[0] = 0;

    for(int i = 0; i < h+10000; i++){
        if(dp[i] == init){
            continue;
        }
        for(int j = 0; j < n; j++){
            if(i+a[j] < h+10000){
                dp[i+a[j]] = min(dp[i+a[j]], dp[i] + b[j]);
            }
        }
    }

    int ans = init;
    for(int i = h; i < h+10000; i++){
        ans = min(ans, dp[i]);
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String a = in.next(), b = in.next(), c = in.next();
        if (a.charAt(a.length()-1) == b.charAt(0) && b.charAt(b.length()-1) == c.charAt(0)){
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }
    
}

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

int n,a[100];

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	cout<<a[n-1]-a[0]<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
n = int(input())

arr = map(int,raw_input().split())

arrb = []

for i in range(n):
	arrb.append(arr[i]-i)

med = np.median(arrb)

ans = 0
for i in range(n):
	ans += abs(arrb[i]-med)

print int(ans)

Measured memory_bytes: 31100
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

ll mod = 1000000007;
int main() {
  int n, m;
  scan(n, m);
  vi s(n), t(m);
  scan(s);
  scan(t);

  vvll dp(n+1, vll(m+1, 0));
  rep (i, n+1) {
    dp[i][0] = 1;
  }
  rep (j, m+1) {
    dp[0][j] = 1;
  }
  rep (i, n) {
    rep (j, m) {
      dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] + mod - dp[i][j]) % mod;
      if (s[i] == t[j]) {
        dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod;
      }
    }
  }
  print(dp[n][m]);

  return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  multiset<int> p;
  for(int i = 0; i < n; i++){
    int x; cin >> x;
    p.insert(x);
  }
  int k = *(--p.end()); p.erase(--p.end());
  int dist = 1<<30, best = -1;
  for(auto it : p){
  	int v0 = it, v1 = k - it;
    if(max(v0,v1) < dist){
      dist = max(v0, v1);
      best = it;
    }
  }
  cout << k << " " << best << endl;
  return 0;
}

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

typedef long long ll;

int N, K;

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

   ll a = 0;
   for (int x = 1; x <=N; x++) {
      if (x % K == 0) {
         a++;
      }
   }

   ll b = 0;
   for (int x = 1; x <=N; x++) {
      if (x % K == K/2) {
         b++;
      }
   }

   ll ans = a * a * a;
   if (K % 2 == 0) {
      ans += b * b * b;
   }

   cout << ans << endl;

   return 0;
}

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

int main(){
	
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i,n){
		cin >> p[i];
		p[i]--;
	}
	
	vector<int> idx(n);
	rep(i,n) idx[p[i]] = i;
	
	set<int> setidx;
	vector<ll> c(n);
	
	for(int i = n-1; i >= 0; i--){
		// calc c
		int idxi = idx[i];
		setidx.insert(idxi);
		
		vector<int> leftidx(2,-1);
		vector<int> rightidx(2,n);
		{
			// calc left
			auto itr = setidx.find(idxi);
			rep(j,2){
				if(itr-- == setidx.begin()) break;
				leftidx[j] = *itr;
			}
		}
		
		{
			// calc right
			auto itr = setidx.find(idxi);
			rep(j,2){
				if(++itr == setidx.end()) break;
				rightidx[j] = *itr;
			}
		}
		
		vector<int> ls(2);
		vector<int> rs(2);
		ls[0] = idxi - leftidx[0];
		ls[1] = leftidx[0] - leftidx[1];
		rs[0] = rightidx[0] - idxi;
		rs[1] = rightidx[1] - rightidx[0];
		
		c[idxi] = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
		
	}
	
	ll res = 0;
	rep(i,n) res += (p[i]+1) * c[i];
	cout << res << endl;
	
	return 0;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    cout << (int)pow(input(), 3) << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll D;
    cin>>D;
    if(D == 25)cout<<"Christmas";
    if(D == 24)cout<<"Christmas Eve";
    if(D == 23)cout<<"Christmas Eve Eve";
    if(D == 22)cout<<"Christmas Eve Eve Eve";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int h,w;
int n;
int a;
int grid[105][105];

int main()
{
    scanf("%d%d%d",&h,&w,&n);
    queue<int> q;
    for (int i=1;i<=n;i++) {
        scanf("%d",&a);
        for (int j=0;j<a;j++) q.push(i);
    }
    for (int i=1;i<=h;i++) {
        if (i%2==1) {
            for (int j=1;j<=w;j++) {
                grid[i][j]=q.front();q.pop();
            }
        } else {
            for (int j=w;j>=1;j--) {
                grid[i][j]=q.front();q.pop();
            }
        }
    }
    for (int i=1;i<=h;i++) {
        for (int j=1;j<=w;j++) {
            printf("%d ",grid[i][j]);
        }
        printf("\n");
    }
}

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

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int w = s.nextInt();
		
		long[] values = new long[n];
		int[] weights = new int[n];
		
		for(int i = 0; i < n; i++) {
			weights[i] = s.nextInt();
			values[i] = s.nextLong();
		}
		
		long[][] knapsack = new long[n + 1][w + 1];

		for(int r = 1; r < knapsack.length; r++) {
			for(int c = 1; c < knapsack[0].length; c++) {
				long ifChosen = c < weights[r - 1] ? 0 : values[r - 1] + knapsack[r-1][c - weights[r - 1]];
				knapsack[r][c] = Math.max(knapsack[r - 1][c], ifChosen);
//				System.out.prlongln(" hello " );
			}
		}
		System.out.println(knapsack[knapsack.length - 1][knapsack[0].length - 1]);
	}
}


Measured memory_bytes: 126544
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = tmp = 0

s=input()
n=len(s)
for i in range(0,n):
    # print(list(itertools.combinations(range(1, n), i)))
    for c in itertools.combinations(range(1,n),i):
        tmp=0
        for ci in c:
            ans+=int(s[tmp:ci])
            # print(int(s[tmp:ci]),0,tmp)
            tmp=ci
        ans+=int(s[tmp:n])
        # print(int(s[tmp:n]),1)
print(ans)


Measured memory_bytes: 64620
#include <cstdio>

int main (void)
{
    int n, tmp;
    scanf("%d", &n);
    scanf("%d", &tmp);
  	int min=tmp;
  	for(int i=1; i<n ; i++){
    	scanf("%d", &tmp);
      	if(min-tmp > 1 ){
        	printf("No\n");
          return 0;
        }else if(tmp > min){
        	min = tmp;
        }
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 15 22:45:08 2019

@author: mac
"""
grades = []
count = 0

while(count == 0):
    scores = list(map(int, input().split(" ")))
    if scores[0] == -1 and scores[1] == -1 and scores[2] == -1:
        count += 1
    grades.append(scores)

for i in range(len(grades) - 1):
    if grades[i][0] == -1 or grades[i][1] == -1:
        print('F')
    elif grades[i][0] + grades[i][1] >= 80:
        print('A')
    elif grades[i][0] + grades[i][1] >= 65:
        print('B')
    elif grades[i][0] + grades[i][1] >= 50:
        print('C')
    elif grades[i][0] + grades[i][1] >= 30:
        if grades[i][2] >= 50:
            print('C')
        else:
            print('D')
    else:
        print('F')


Measured memory_bytes: 5624
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    long a, b, k;
    scan(a, b, k);
    long t = min(a, k);
    a -= t;
    b -= min(b, k - t);
    writefln("%d %d", a, b);
}














void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
# 参考: https://atcoder.jp/contests/abc076/submissions/5314710
S = gets.chomp
T = gets.chomp

if S.length < T.length
  puts 'UNRESTORABLE'
  exit
end

(S.length - T.length).downto(0) do |i|
  i.upto(i+T.length-1) do |j|
    break if S[j] != T[j-i] && S[j] != '?'
    if j == i+T.length-1
      0.upto(S.length-1) do |k|
        if S[k] == '?' && (k < i || k > j)
          S[k] = 'a'
        elsif k >= i && k <= j
          S[k] = T[k-i]
        end
      end
      puts S
      exit
    end
  end
end
puts 'UNRESTORABLE'

Measured memory_bytes: 1788
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int a = stoi(s.substr(0,2));
  int b = stoi(s.substr(2,2));
  bool yymm = false;
  bool mmyy = false;
  if(1 <= b && b <= 12) yymm = true;
  if(1 <= a && a <= 12) mmyy = true;

  if(yymm && mmyy)   cout << "AMBIGUOUS" << endl;
  if(!yymm && !mmyy) cout << "NA"        << endl;
  if(yymm && !mmyy)  cout << "YYMM"      << endl;
  if(!yymm && mmyy)  cout << "MMYY"      << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
i = input()

int_i = int(i)

for k in range(int_i):
    arr_train = input()
    len_train = len(arr_train)
    last_train = []
    for j in range(1, len_train):
        bef_train = arr_train[:j:]
        af_train = arr_train[j::]
        last_train.append(bef_train+af_train)
        last_train.append(bef_train[::-1]+af_train)
        last_train.append(bef_train+af_train[::-1])
        last_train.append(bef_train[::-1]+af_train[::-1])
        last_train.append(af_train+bef_train)
        last_train.append(af_train[::-1]+bef_train)
        last_train.append(af_train+bef_train[::-1])
        last_train.append(af_train[::-1]+bef_train[::-1])
    uniq_train = list(set(last_train))
    print(len(uniq_train))


Measured memory_bytes: 5640
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
const ll mod = 998244353;
#define int ll
int n, m, a[100002];

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    for(int i=1; i<=n; i++) cin>>a[n-i+1];
    int l=2, r=2;
    //if(a[1]==1) r=2;
    //if(a[1]>2) return cout<<-1, 0;
    for(int i=1; i<=n; i++){
       // if(a[i]>r) return cout<<-1, 0;
        int xd=a[i];
        l=l-(l%xd)+xd*(l%xd!=0);
        r=r-(r%xd)+xd-1;
        if(l>r) return cout<<-1, 0;
    }
    cout<<l<<" "<<r;
}


Measured memory_bytes: 1024
#include<cstdio>
const int M=1e5+10;
long long f[M];
int n,m,w,c;
long long ma(long long a,long long b){return a>b?a:b;}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&w,&c);
		for(int j=m;j>=w;j--)
			f[j]=ma(f[j],f[j-w]+c);
	}
	printf("%lld",f[m]);
	return 0;
}


Measured memory_bytes: 896