akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair< int, int > Pi;
typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const double DINF = 5e14, eps = 1e-10;
const long long MOD = 1e9 + 7, INF = 5e18;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

struct BIT{
	private:
	int n;
	vector<ll>v;
	public:
	BIT(int N){
		v.resize(N);
		n=N;
	}
	void add(int it,int val){
		while(it<=n)v[it]+=val,it+=it&(-it);
	}
	ll sum(int it){
		ll ret=0;
		while(it>0)ret+=v[it],it-=it&(-it);
		return ret;
	}
};

int n,m,l,r;
vector<int>st[300010];
BIT b(300010);

void input(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>l>>r;
		st[r-l+1].eb(l);
	}
	return;
}

void solve(){
	ll ans=n;
	for(int i=1;i<=m;i++){
		int plus=0;
		for(int j=i;j<=m;j+=i)plus+=b.sum(j);
		for(int j=0;j<st[i].size();j++){
			b.add(st[i][j],1);
			b.add(st[i][j]+i,-1);
		}
		cout<<ans+plus<<endl;
		ans-=st[i].size();
	}
	return;
}

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


Measured memory_bytes: 13440
a = []
for w in range(2, 201):
    for h in range(1, w):
        a.append([h**2+w**2, h, w])
a.sort()

while 1:
    h,w = map(int,input().split())
    if h == 0: break
    # print(a.index([h**2+w**2,h,w]))
    ans = a[a.index([h**2+w**2,h,w])+1]
    print(ans[1], ans[2])



Measured memory_bytes: 8108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        int[][] matrix = new int[n][n];
        for(int i = 0; i < n; i++){
        	Arrays.fill(matrix[i], Integer.MAX_VALUE);
        }
        //Vertex[] v = new Vertex[n];
        for(int i = 0; i < n; i++){
        	String tmpStr = br.readLine();
        	
        	String[] tmp = tmpStr.split(" ");
        	for(int j = 0;j < Integer.parseInt(tmp[1]); j++){
        		matrix[i][Integer.parseInt(tmp[ 2*(j + 1)])] = Integer.parseInt(tmp[2*(j + 1) + 1]);
        	}

        }
        /*
        for(int i = 0; i < n; i++){
        	for(int j = 0; j < n; j++){
        		System.out.print(matrix[i][j]+ " ");
        	}
        	System.out.println();
        }
        */
        int[] dist = singleSourceShortestDense(matrix, 0);
        
        for(int i = 0; i < n ; i++){
        	System.out.println(i + " " + dist[i]);
        }
	}

	static int[] singleSourceShortestDense(int[][] matrix, int s){
		int n = matrix[0].length;
		int[] dist = new int[n];
		Arrays.fill(dist, Integer.MAX_VALUE);
		boolean[] visited = new boolean[n];
		Arrays.fill(visited, false);

		dist[s] = 0;
		
		while(true){
		
			int u = -1;
			int sd = Integer.MAX_VALUE;
			
			for(int i = 0; i < n ; i++){
				if(!visited[i] && dist[i] < sd){
					sd = dist[i];
					u = i;
				}
			}
			
			if(u == -1){
				break;
			}
			
			visited[u] = true;
			for(int v = 0; v < n ; v++){
				int w = matrix[u][v];
				if(v == u) continue;
				
				long newLen = dist[u];
				newLen += w;
				if(newLen < dist[v]){
					dist[v] = (int)newLen;
				}
			}

		}
		
		return dist;
	}

}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;

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

  if (t == "P" || t == "D") {
    cout << t;
    return 0;
  } else if (t == "?") {
    cout << "D";
    return 0;
  }

  for(int i = 0; i < t.length(); i++) {
    if (t.at(i) == '?') {
      t.at(i) = 'D';
    }
  }
  cout << t;
}


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

typedef long long ll;

const ll MAX = 1000000000;

int main()
{
	int n, k;
	ll a;
	scanf("%d%d", &n, &k);
	mcf_graph<int, ll> graph(n*2+2);
	int s = n*2, t = n*2+1;
	for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
		scanf("%lld", &a);
		graph.add_edge(i, n+j, 1, MAX-a);
	}
	graph.add_edge(s, t, n*k, MAX);
	for (int i = 0; i < n; ++i) {
		graph.add_edge(s, i, k, 0);
		graph.add_edge(n+i, t, k, 0);
	}
	auto ans = graph.flow(s, t, n*k);
	printf("%lld\n", MAX*n*k-ans.second);
	char grid[n][n+5];
	memset(grid, '.', sizeof grid);
	auto edges = graph.edges();
	for (auto e : edges) {
		if (e.from != s && e.to != t && e.flow) {
			grid[e.from][e.to-n] = 'X';
		}
	}
	for (int i = 0; i < n; ++i) {
		grid[i][n] = '\0';
		printf("%s\n", grid[i]);
	}
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define SIZE 305
using namespace std;

char mp[SIZE][SIZE];
int ans[SIZE][SIZE];
int main()
{
	int n,m,K;
	scanf("%d %d %d",&n,&m,&K);
	for(int i=0;i<n;i++) scanf("%s",&mp[i]);
	int bef=0;
	int sz=0;
	for(int i=0;i<n;i++)
	{
		bool up=false;
		vector <int> vx;
		for(int j=0;j<m;j++)
		{
			if(mp[i][j]=='#')
			{
				up=true;
				vx.push_back(j);
			}
		}
		if(up)
		{
			int from=0;
			int last=i;
			if(sz+vx.size()==K) last=n-1;
			for(int j=0;j<vx.size();j++)
			{
				int to=vx[j];
				if(j==vx.size()-1) to=m-1;
				for(int x=bef;x<=last;x++)
				{
					for(int y=from;y<=to;y++) ans[x][y]=sz;
				}
				from=to+1;
				sz++;
			}
			bef=i+1;
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++) printf("%d ",ans[i][j]+1);
		puts("");
	}
	return 0;
}

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


using namespace std;

typedef long long ll;

int main() {
	string s;
	cin >> s;
	int n = s.length();
	int cnt = 0;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] != s[i + 1]) {
			cnt++;
		}
	}
	cout << cnt << endl;
}


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

int mod;

__int128 mul(__int128 x, __int128 y) {
    return (__int128) (x % mod) * (y % mod) % mod;
}

__int128 pw(__int128 a, __int128 b) {
    assert(b >= 0);
    a %= mod;
    __int128 r = 1;
    for( ; b ; b >>= 1, a = mul(a, a)) {
        if(b & 1) {
            r = mul(r, a);
        }
    }
    return r;
}

struct Mat {
    __int128 a[3][3];
    Mat() {
        memset(a, 0, sizeof a);
    }
    __int128 *operator [](int x) {
        return a[x];
    }
    Mat operator * (Mat b) {
        Mat c;
        for(int i = 0 ; i < 3 ; ++ i) {
            for(int j = 0 ; j < 3 ; ++ j) {
                for(int k = 0 ; k < 3 ; ++ k) {
                    c[i][j] = (c[i][j] + mul(a[i][k], b[k][j])) % mod;
                }
            }
        }
        return c;
    }
    void output() {
        for(int i = 0 ; i < 3 ; ++ i) {
            for(int j = 0 ; j < 3 ; ++ j) {
                printf("%lld ", (ll) a[i][j]);
            }
            puts("");
        }
        puts("");
    }
};
Mat pw(Mat a, __int128 b) {
    Mat r;
    for(int i = 0 ; i < 3 ; ++ i) {
        r[i][i] = 1;
    }
    for( ; b ; b >>= 1, a = a * a) {
        if(b & 1) {
            r = r * a;
        }
    }
    return r;
}

__int128 getinv(__int128 n) {
    return pw(n, mod - 2);
}

__int128 ans;
__int128 L, A, B;
__int128 log10(__int128 x) {
    // printf("log(%lld) = %lld\n", (ll) x, (ll) (log(x) / log(10)));
    // cout << log(x) << endl;
    // cout << log(10) << endl;
    // return log(x) / log(10) + 1;
    __int128 res = 0;
    if(x == 0) return 1;
    while(x) {
        x /= 10;
        ++ res;
    }
    return res;
}

int main() {
    ll _L, _A, _B;
    cin >> _L >> _A >> _B >> mod;
    L = _L - 1, A = _A, B = _B;
    ans = 0;

    // +B ~ +LB
    for(__int128 i = 0 ; i <= L ; ) {

        // printf("begin\n");

        __int128 len = log10(A + (__int128) i * B);
        __int128 j = i, l = i, r = L;
        while(l <= r) {
            __int128 mid = (l + r) >> 1;
            __int128 nl = log10(A + mid * B);
            if(nl <= len) { // 实际上只有==
                j = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }

        // printf("%lld, %lld\n", (ll) i, (ll) j);

        // [i, j] 中转移都是 * 10^len
        __int128 l10 = pw(10, len);
        Mat base, coef;
        // (A+iB)(A+(i+1)B)(A+(i+2)B)...(A+jB)
        
        base[0][0] = (A + mul(i, B)) % mod, base[0][1] = 0, base[0][2] = 1;

        coef[0][0] = 1, coef[0][1] = 1, coef[0][2] = 0;
        coef[1][0] = 0, coef[1][1] = l10, coef[1][2] = 0;
        coef[2][0] = B, coef[2][1] = 0, coef[2][2] = 1;

        // printf("pw = %lld\n", (ll) (j - i + 1));
        // printf("%lld\n", (ll) len);
        // printf("%lld\n", (ll) (len * (j - i + 1)));
        base = base * pw(coef, j - i + 1);

        // printf("res = %lld\n", (ll) base[0][1]);
        ans = (mul(ans, pw(10, len * (j - i + 1))) + base[0][1]) % mod;

        i = j + 1;
        // printf("end\n");
    }
    printf("%lld\n", (ans % mod + mod) % mod);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int main() {
    int d,n;
    cin >> d >> n;
    vector<int> ans(99);
    if(d==0){
        if(n == 100) cout << 101 << endl;
        else cout << n << endl;
    }
    else if(d == 1 ){
        if(n != 100){
            rep(i,99) ans.at(i) = 100 * (i+1);
            cout << ans.at(n-1) << endl;
        }
        else cout << 10100;
    }
    else{
        if(n != 100){
            rep(i,99) ans.at(i) = 10000*(i+1);
            cout << ans.at(n-1) << endl;
        }
        else cout << 1010000;
    }

}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	long long a,v,b,w,t;
	cin >> a >> v >> b >> w >> t;
	long long dis=abs(a-b);
	long long vel=v-w;
	bool flg;
	if(dis==0)
		flg=true;
	else if(vel<=0)
		flg=false;
	else if(vel*t>=dis)
		flg=true;
	else 
		flg=false;
	
	cout << (flg ? "YES":"NO") << endl;
		




}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
//#define max(a,b) ((a>b)?a:b)
//#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
// #define assmin(a,b) if(b<=a) { a=b; }
// #define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.00000000001)
#define side 1e9
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[200005];
void power()
{
    powe[0]=1;
    REP(i,1,200005)
    {
        powe[i]=mymod(2*powe[i-1],num);
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
}
struct node
{
	vll adj;
    ll height;
};

ll find(ll n, ll wt, ll nm)
{
    ll st = 1;
    ll en = nm;
    ll mid = (st) + (en - st)/2;
    while(st<=en)
    {
        if(wt+3*(nm+mid)>=n && wt+2*(nm+mid)<=n)
        {
            return mid;
        }
        else if(wt+3*(nm+mid)<n)
        {
            st = mid+1;
        }
        else
        {
            en = mid-1;
        }
        mid = (st) + (en - st)/2;
    }
    if(wt+3*(nm+mid)>=n && wt+2*(nm+mid)<=n)
    {
            return mid;
     }
    return 0;
}
bool my(pair<ll, char> p1, pair<ll, char> p2)
{
    return p1.first > p2.first;
}
ll f(ll a)
{
    return (a*a*a*a*a);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x;
    cin>>x;
    REP(i,-119,120)
    {
        REP(j,-119,120)
        {
            if(f(i) - f(j) == x)
            {
                cout<<i<<" "<<j<<"\n";
                exit(0);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3640
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N, M;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
	}

	int[] genSeed() {
		int odds = 0;
		int evens = 1;
		int count = 0;
		boolean isOddTurn = true;
		while (count < M) {
			if (isOddTurn) {
				odds += 2;
				isOddTurn= false;
			} else {
				evens += 2;
				isOddTurn = true;
			}
			count++;
		}
		int[] results = new int[2];
		results[0] = odds;
		results[1] = evens;
		return results;
	}

	void calc() {
		int[] seeds = genSeed();
		Deque<Integer> odds = new ArrayDeque<>();
		for (int i = 1; i <= seeds[0]; ++i) {
			odds.addLast(i);
		}
		Deque<Integer> evens = new ArrayDeque<>();
		for (int i = seeds[0] + 1; i <= seeds[0] + seeds[1]; ++i) {
			evens.addLast(i);
		}
		while (!odds.isEmpty()) {
			System.out.println(odds.pollFirst() + " " + odds.pollLast());
		}
		while (evens.size() >= 2) {
			System.out.println(evens.pollFirst() + " " + evens.pollLast());
		}
	}

	void showResult() {
	}

}

Measured memory_bytes: 56140
"use strict"
function Main(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  var A=input[0], B=input[1];
  if(A>0){
    console.log(xor(XORsum(A-1),XORsum(B)));
    return;
  }else{
    console.log(XORsum(B));
  }
}

function zeroFill(str){
  return ("00000000000000000000000000000000000000000000000000"+str).slice(-50)
}

function XORsum(x){//0から数値xまでのxorの総和を数値で返す。
  var result=0;
  result+=((x%4===1||x%4===2)?1:0);
  for(let i=1;i<49;i++){
    result+=((x%Math.pow(2,i+1)>=Math.pow(2,i)&&x%2===0)?Math.pow(2,i):0);
  }
  return result;
}

function xor(a,b){
  var A=zeroFill(a.toString(2)).split("").map(x=>x-0);
  var B=zeroFill(b.toString(2)).split("").map(x=>x-0);
  var C=A.map((x,i)=>(x+B[i])%2);
  return parseInt(C.join(""),2);
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));


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

int d[200];

int main(){
	int n;
	while(scanf("%d",&n),n){
		for(int i=0;i<200;i++) d[i]=0;
		for(int i=0;i<n;i++){ int a; scanf("%d",&a); d[a-1]=1; }
		int t,b=0,T[2]={0,0};
		while(1){
			t=-1; b=(b+1)&1;
			for(int i=0;i<2*n;i++){
				if(d[i]==b&&i>t){ d[i]=2; b=(b+1)&1; t=i; T[b]++;}
				if(T[0]==n||T[1]==n) break;
			}
			if(T[0]==n||T[1]==n) break;
		}
		int res=0;
		for(int i=0;i<2*n;i++) if(d[i]==0) res++;
		printf("%d\n",res);
		res=0;
		for(int i=0;i<2*n;i++) if(d[i]==1) res++;
		printf("%d\n",res);
	}
}

Measured memory_bytes: 1188
#include<stdio.h>
int main() {
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a==b&&a!=c)
	printf("Yes\n");
	else if(a==c&&a!=b)
	printf("Yes\n");
	else if(b==c&&b!=a)
	printf("Yes\n");
	else 
	printf("No\n");
	return 0;
}

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

int main() {
    int N, T;
    cin >> N >> T;
    int t[N];
    ll ans = T;
    for (int i = 0; i < N; i++) scanf(" %d", &t[i]);
    for (int i = 1; i < N; i++) {
        if (t[i]-t[i-1] >= T) ans += T;
        else ans += t[i] - t[i-1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int sign(double x){
  if (x > EPS){
    return 1;
  } else if (x < - EPS){
    return -1;
  } else {
    return 0;
  }
}
struct point{
  double x, y;
  point(){
  }
  point(double x, double y): x(x), y(y){
  }
  point operator +(point P){
    return point(x + P.x, y + P.y);
  }
  point operator -(point P){
    return point(x - P.x, y - P.y);
  }
  point operator *(double k){
    return point(x * k, y * k);
  }
  point operator /(double k){
    return point(x / k, y / k);
  }
};
double abs(point P){
  return sqrt(pow(P.x, 2) + pow(P.y, 2));
}
double dot(point P, point Q){
  return P.x * Q.x + P.y * Q.y;
}
double cross(point P, point Q){
  return P.x * Q.y - P.y * Q.x;
}
struct line{
  point A, B;
  line(){
  }
  line(point A, point B): A(A), B(B){
  }
};
point vec(line L){
  return L.B - L.A;
}
bool is_parallel(line L1, line L2){
  return sign(cross(vec(L1), vec(L2))) == 0;
}
point line_intersection(line L1, line L2){
  return L1.A + vec(L1) * cross(L2.A - L1.A, vec(L2)) / cross(vec(L1), vec(L2));
}
bool on_segment(point P, line L){
  return sign(dot(P - L.A, vec(L))) == 1 && sign(dot(P - L.B, vec(L))) == -1;
}
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int xa, ya, xb, yb;
    cin >> xa >> ya >> xb >> yb;
    line L1 = line(point(xa, ya), point(xb, yb));
    int n;
    cin >> n;
    vector<line> L2(n);
    vector<int> o(n), l(n);
    for (int j = 0; j < n; j++){
      int xs, ys, xt, yt;
      cin >> xs >> ys >> xt >> yt >> o[j] >> l[j];
      L2[j] = line(point(xs, ys), point(xt, yt));
    }
    vector<pair<double, int>> I;
    for (int j = 0; j < n; j++){
      if (!is_parallel(L1, L2[j])){
        point P = line_intersection(L1, L2[j]);
        if (on_segment(P, L1) && on_segment(P, L2[j])){
          double t = abs(P - L1.A) / abs(vec(L1));
          I.push_back(make_pair(t, (o[j] + l[j]) % 2));
        }
      }
    }
    sort(I.begin(), I.end());
    int sz = I.size();
    int ans = 0;
    for (int j = 0; j < sz - 1; j++){
      if (I[j].second != I[j + 1].second){
        ans++;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3028
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	long long N, X;
	cin >> N >> X;
	vector<long long> x(N);

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

	reverse(x.begin(), x.end());

	long long ans = INFINITY;

	vector<long long> sum(N + 1);

	for (int i = 0; i < N; i++) {
		sum[i + 1] = sum[i] + x[i];
	}

	for (long long k = 1; k < N + 1; k++) {
		long long cost = k * X + N * X;
		
		for (long long i = 0; i*k < N; i++) {
			long long t = i + 1;
			long long l = k * i;
			long long r = min(l + k, N);
			if (t == 1) {
				cost += (sum[r] - sum[l]) * 5;
			}
			else {
				cost += (sum[r] - sum[l])*(2 * t + 1);
			}
			if (cost > ans) break;
		}
		ans = min(ans, cost);

	}

	cout << ans << endl;

}



Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
using ll = long long;
 
 
 
int main() {
    int n;
    scanf("%d", &n);
    // dp[heads]
    // if we had i tosses, then tails=i-heads
    vector<double> dp(n + 1);
    // dp[i] - p-bility that there are i heads so far
    dp[0] = 1;
    for(int coin = 0; coin < n; ++coin) {
        double p_heads;
        scanf("%lf", &p_heads);
        for(int i = coin + 1; i >= 0; --i) {
            dp[i] = (i == 0 ? 0 : dp[i-1] * p_heads) + dp[i] * (1 - p_heads);
        }
    }
    double answer = 0;
    for(int heads = 0; heads <= n; ++heads) {
        int tails = n - heads;
        if(heads > tails) {
            answer += dp[heads];
        }
    }
    printf("%.10lf\n", answer);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;



int main()
{	
	int n,h,w,t[10][10],dis[10],ans=0,k;

	cin>>h>>w;
	for(int i=0;i<10;i++)
	{
		dis[i]=1000000000;
		for(int j=0;j<10;j++)
		{
			cin>>t[i][j];
		}
	}
	int a[10]={0,1,2,3,4,5,6,7,8,9};
	do
	{
		int sum=0;
		if(a[0]==1)continue;
		for(int i=1;i<10;i++)
		{
			sum+=t[a[i-1]][a[i]];
			if(a[i]==1)break;
		}
		dis[a[0]]=min(dis[a[0]],sum);
	}
	while(next_permutation(a,a+10));

	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>k;
			if(k!=-1&&k!=1)ans+=dis[k];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
//Inbornhandsome
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define endl '\n'
#define int long long

const int N = 1e5 + 7;

int stones[N], cost[N], n, k;

int find_cost(int stone)
{
    if(stone > n)   return 1e9;
    if(stone == n)  return 0;

    int &ans = cost[stone];

    if(ans != -1) return ans;

    ans = 1e10;

    for(int i = 1; i <= k and stone + i <= n; ++ i)
    {
        ans = min(ans, abs(stones[stone] - stones[stone + i]) + find_cost(stone + i));
    }
    
    
    return ans;
}

int32_t main()
{
    IOS; //FIO;

    cin >> n >> k;

    memset(cost,-1,sizeof(cost));

    for(int i = 1; i <= n; ++ i)
        cin  >> stones[i];

    cout << find_cost(1);

    return 0;
}

Measured memory_bytes: 6528
program postdocs
  implicit none
  character(200000) :: t
  integer :: n, i
  read(*,*) t
  n = len_trim(t)
  do i = 1, n
    if (t(i:i) == '?') t(i:i) = 'D'
  end do
  write(*,'(a)') trim(t)
end program postdocs

Measured memory_bytes: 3268
my ($tap, $mitap) = glob<>;
my $count = 0;

for(my $i =1; $i <= 20; $i++){
	if($mitap <= (($tap-1) * $i + 1)){
    	$count = $i;
    	last;
    }
}
if($mitap == 1){
	print 0;
} else {
	print $count;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(ll i=0; i < n; i++)
#define reps(i, n) for(ll i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;
int n;

int main() {
  int n;cin >> n;
  int ans =0;
  int x;cin >> x;
  ans = x;
  rep(i,n-2){
    int y;cin >> y;
    ans += min(x,y);
    x = y;
  }
  cout << ans+x;
}

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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
typedef long long ll;


int main() {
	int n, a = 0, b = 0, c = 0;
	cin >> n;
	REP(i, n) {
		int d;
		cin >> d;
		if (d % 4 == 0)a++;
		else if (d % 2 == 0)b++;
		else c++;
	}
	if (a >= c)cout << "Yes" << endl;
	else if (b == 0 && a + 1 == c)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	long long A;
	string B;
	cin >> A >> B;

	long long b = 0;
	for( int i = 0; i < B.size(); i++ ) {
		if( isdigit( B[i] ) ) {
			int n = B[i] - '0';
			b = b * 10 + n;
		}
	}
 
	long long ans = A * b / 100;
 
	cout << ans << endl;
}

Measured memory_bytes: 3572
#include <cassert>

#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 <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#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 <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int n,q;
    cin>>n>>q;
    vector<stack<int>> st(n);
    rep(i,0,q){
        int cmd;cin>>cmd;
        if(cmd==0){
            int t,x;cin>>t>>x;
            st[t].push(x);
        }else  if(cmd==1){
            int t;cin>>t;
            if(!st[t].empty())cout<<st[t].top()<<endl;
        }else {
            int t;cin>>t;
            if(!st[t].empty())st[t].pop();
        }
    }
    

}



/*

*/


Measured memory_bytes: 4312
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")

#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int n;
int main()
{
	cin>>n;
	cout<<n*(n+1)/2<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;


int main()
{
	int n;
	long long int a[100002], s = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i % 2 == 0)
			s += a[i];
		else
			s -= a[i];
	}
	cout << s;
	s = s / 2;
	for (int i = 0; i < n-1; i++) {
		s = a[i] - s;
		cout << " " << 2 * s;
	}
	cout << endl;
}

Measured memory_bytes: 2048
from collections import deque
from copy import deepcopy, copy
dy = [-1, 0, 0, 1]
dx = [0, -1, 1, 0]
N = 3
def g(i, j, a):
    t = a // (10 ** j) % 10
    return a - t * (10 ** j) + t * (10 ** i)
def MAIN():
    m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0}, 0:{3, 1}}
    MAP = "".join(input().replace(" ", "") for _ in range(N))
    start = 8 - MAP.find("0")
    MAP = int(MAP)
    goal = ('1', '2', '3', '4', '5', '6', '7', '8', '0')
    goal = 123456780
    dp = deque([(0, start, MAP)])
    LOG = {MAP}
    while dp:
        cnt, yx, M = dp.popleft()
        if M == goal:
            print(cnt)
            break
        cnt += 1
        for nyx in m[yx]:
            CM = g(yx, nyx, M)
            if not CM in LOG:
                dp.append((cnt, nyx, CM))
                LOG.add(CM)
MAIN()



Measured memory_bytes: 25996
n, m = map(int, input().split())
s_li_ = []
c_li_ = []

for _ in range(m):
  s, c = map(int, input().split())
  s_li_.append(s)
  c_li_.append(c)

def func(n, m, s_li, c_li):
  if m==0:
    if n==1:
      return 0
    else:
      return 10**(n-1)
  
  if n==1:
    if (s_li[0]==1) & (c_li[0]==0):
      return 0
  
  for i in range(10**(n-1), 10**n):
    cnt = 0
    for s, c in zip(s_li, c_li):
      if str(i)[s-1] == str(c):
        cnt+=1
    if cnt==m:
      return i
    
  return -1

print(func(n, m, s_li_, c_li_))


Measured memory_bytes: 9132
class _in{struct my_iterator{int it;const bool rev;explicit constexpr my_iterator(int it_, bool rev=false):it(it_),rev(rev){}constexpr int operator*(){return it;}constexpr bool operator!=(my_iterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const my_iterator i,n;public:explicit constexpr _in(int n):i(0),n(n){}explicit constexpr _in(int i,int n):i(i,n<i),n(n){}constexpr const my_iterator& begin(){return i;}constexpr const my_iterator& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    string s; cin >> s;
    for(int i : _in(s.size())) {
        cout << s[i];
        if(i == 3) cout << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    int ans = 0; REP(i,n) ans+=i+1;
    out(ans);

    return 0;
}

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

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, k;
    cin >> n >> k;
    for (int x = (1 << k) - 1; x < 1 << n;)
    {
        cout << x << ':';
        for (int i = 0; i < n; i++)
        {
            if (x >> i & 1)
            {
                cout << ' ' << i;
            }
        }
        cout << '\n';
        int t = x | (x - 1);
        x = (t + 1) | (((~t & -~t) - 1) >> (__builtin_ctz(x) + 1));
    }
}

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



Measured memory_bytes: 3092
// test.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <bits/stdc++.h>
#define read(x) int x; cin>>x
#define pi pair<int, int>
#define pl pair<ll, ll>
#define newa(x, type, n) type* x = new type[n] 

typedef long long ll;

using namespace std;

int test()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	read(n);
	read(m);
	newa(l, int, m);
	newa(r, int, m);
	for (int i = 0; i < m; i++)
		cin >> l[i] >> r[i];
	int lmax = l[0];
	int rmin = r[0];
	for (int i = 1; i < m; i++)
		lmax = max(lmax, l[i]), rmin = min(rmin, r[i]);
	int ans = rmin - lmax + 1;
	if (ans < 0)
		ans = 0;
	cout << ans;
	return 0;
}

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

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
mcnt = 0
s = 10**9
for i in range(n):
  if a[i] < 0:
    mcnt += 1
    a[i] = -1 * a[i]
  s = min(s, abs(a[i]))
if mcnt % 2 == 0:
  print(sum(a))
else:
  print(sum(a) - (s*2))

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

using ll = long long;

const ll inf = ll(1e18);

int n;
ll s, m = inf;

int main(){
    scanf("%d", &n);
    for(ll x, y; n--; ){
        scanf("%lld%lld", &x, &y);
        if(x > y) m = min(m, y);
        s += x;
    }
    printf("%lld\n", max(0LL, s - m));
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main()
{
	int b = 0;
	int w = 0;
	int aa[3] = { 0, 0, 0 };
	int a[3] = { 0, 0, 0 };
	for (int i = 0; i < 10; i++)
	{
		cin >> b;
		if (b > a[2])
		{
			a[2] = b;
		}
		if (a[2] > a[1])
		{
			w = a[1];
			a[1] = a[2];
			a[2] = w;
		}
		if (a[1] > a[0])
		{
			w = a[0];
			a[0] = a[1];
			a[1] = w;
		}
	}
	for (int i = 0; i < 10; i++)
	{
		cin >> b;
		if (b > aa[2])
		{
			aa[2] = b;
		}
		if (aa[2] > aa[1])
		{
			w = aa[1];
			aa[1] = aa[2];
			aa[2] = w;
		}
		if (aa[1] > aa[0])
		{
			w = aa[0];
			aa[0] = aa[1];
			aa[1] = w;
		}
	}
	cout << a[0] + a[1] + a[2] << " " << aa[0] + aa[1] + aa[2] << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <random>

using ll = long long int;
using P = std::pair<ll, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int l[30];
ll c[30],s[400][30],ans[150000];
std::vector<int> v[150000];

int main(void){
	int d,i,j,n=26,k,m=125000;
	ll ansm = -INFLL;
	for(k=0; k<m; ++k){
		for(j=0; j<n; ++j){
			v[k].push_back(j);
		}
		std::random_device seed_gen;
		std::mt19937 engine(seed_gen());
		std::shuffle(v[k].begin(), v[k].end(), engine);
	}
	std::cin >> d;
	for(i=0; i<26; ++i){
		std::cin >> c[i];
	}
	for(i=0; i<d; ++i){
		for(j=0; j<n; ++j){
			std::cin >> s[i][j];
		}
	}
	for(k=0; k<m; ++k){
		for(j=0; j<n; ++j){
			l[j] = -1;
		}
		for(i=0; i<d; ++i){
			ans[k] += s[i][v[k][i%26]];
			l[v[k][i%26]] = i;
			for(j=0; j<n; ++j){
				ans[k] -= c[j]*(i-l[j]);
			}
		}
		ansm = std::max(ansm,ans[k]);
		// std::cout << ans[k] << std::endl;
	}
	for(k=0; k<m; ++k){
		if(ans[k] == ansm){
			for(i=0; i<d; ++i){
				std::cout << v[k][i%26]+1 << std::endl;
			}
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 25764
#include <iostream>
#include <string>
#include <cmath>
#include <typeinfo>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  for(int i=0; i<m; i++) {
    cin >> s[i] >> c[i];
  }
  if (n == 1) {
    for(int i=0; i<10; i++) {
      string str = to_string(i);
      int check = 1;
      for(int j=0; j<m; j++) {
        if (str[s[j]-1] != c[j]) {
          check = 0;
        }
      }
      if (check == 1) {
        cout << i << endl;
        return 0;
      }
    }
  } else {
    for(int i=pow(10, n-1); i<pow(10, n); i++) {
      string str = to_string(i);
      int check = 1;
      for(int j=0; j<m; j++) {
        if (str[s[j]-1] != c[j]) {
          check = 0;
        }
      }
      if (check == 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long R){
    if(R < 1200){
        cout << "ABC" << "\n";
    } else if (R < 2800) {
        cout << "ARC" << "\n";
    } else {
        cout << "AGC" << "\n";
    }
}

int main(){

    long long R;
    scanf("%lld",&R);
    solve(R);
    return 0;
}



Measured memory_bytes: 256
h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1

m = [[-1] * w for _ in range(h)]
for hh in range(h):
    c = input()
    for ww, cc in enumerate(c):
        if cc == '.':
            m[hh][ww] = h*w

from collections import deque
q = deque()

q.append((0, x1, y1))
while q:
    s, x, y = q.popleft()
    s1 = s + 1

    for i in range(1, k+1):
        xx, yy = x + i, y
        if xx >= h or m[xx][yy] <= s:
            break
        if m[xx][yy] == s1:
            continue
        if xx == x2 and yy == y2:
            print(s1)
            exit(0)
        m[xx][yy] = s1
        q.append((s1, xx, yy))

    for i in range(1, k+1):
        xx, yy = x - i, y
        if xx < 0 or m[xx][yy] <= s:
            break
        if m[xx][yy] == s1:
            continue
        if xx == x2 and yy == y2:
            print(s1)
            exit(0)
        m[xx][yy] = s1
        q.append((s1, xx, yy))

    for i in range(1, k+1):
        xx, yy = x, y + i
        if yy >= w or m[xx][yy] <= s:
            break
        if m[xx][yy] == s1:
            continue
        if xx == x2 and yy == y2:
            print(s1)
            exit(0)
        m[xx][yy] = s1
        q.append((s1, xx, yy))

    for i in range(1, k+1):
        xx, yy = x, y - i
        if yy < 0 or m[xx][yy] <= s:
            break
        if m[xx][yy] == s1:
            continue
        if xx == x2 and yy == y2:
            print(s1)
            exit(0)
        m[xx][yy] = s1
        q.append((s1, xx, yy))

print(-1)


Measured memory_bytes: 49596
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
const int maxn = 1e5;
const int inf = 1<< 30;
typedef long long LL;
int n;
char a[3*maxn+5];
int pos[3*maxn+5],vis[3*maxn+5];
int main(){
	scanf("%d",&n);
	scanf("%s",a);
	int ind = 0;
	for(int i = 0;i<n;i++){
		pos[i] = ind;
		if(a[i] == 'W')
			ind++;
	}
	ind = 0;
	for(int i = n-1;i>=0;i--){
		vis[i] = ind;
		if (a[i] == 'E')
			ind++;
	}
	int ans = inf;
	for(int i = 0;i<n;i++){
		if(ans > pos[i]+vis[i]) 
			ans = pos[i] + vis[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  string s;
  cin >> s;
  deque<char> deq;
  int ssize = s.size();
  for(int i = 0; i < ssize; i++){
    if(s.at(i) == 'B'){
      if(deq.size() > 0) deq.pop_back();
    }
    else deq.push_back(s.at(i));
  }
  while(deq.size()){
    cout << deq.front();
    deq.pop_front();
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        if(A < 1 || A > 9 || B < 1 || B > 9) {
            System.out.println(-1);
            return;
        }

        System.out.println(A * B);
    }
}

Measured memory_bytes: 23636
h,w=map(int,input().split())
a=[]
for i in range(h):
  tmp=input()
  if len(tmp)!=tmp.count('.'):
    a.append(tmp)
  else:
    h-=1

b=[]
for i in range(w):
  cnt=0
  for j in range(h):
    if a[j][i]=='.':
      cnt+=1
  if cnt==h:
    b.append(0)
  else:
    b.append(1)

for i in range(h):
  for j in range(w):
    if b[j]:
      print(a[i][j], end='')
  print()
      

Measured memory_bytes: 4468
#include <stdio.h>
int main(void){
  int A, B, C, D, e = 0;
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  scanf("%d", &D);

  while(A > 0 && C > 0){
    C -= B;
    if(C <= 0) e += 1; 
    A -= D;
  }
  if(e > 0) printf("Yes\n");
  else printf("No\n");
} 


Measured memory_bytes: 1620
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> T MV(T v) { return v; }
template<typename T, typename ... U> auto MV(T v, int a, U ... b) { return vector<decltype(MV(v, b ...))>(a, MV(v, b ...)); }

#define bit(b, i) (((b) >> (i)) & 1)
#define PC __builtin_popcountll
#define BL(a) (a ? 64 - __builtin_clzll(a) : 0)

int main() {
	const int B = 9;
	const int M = 100'000;
	
	IN(int, n);
	vector<int> v(n + 1), w(n + 1);
	inc1(i, n) { cin >> v[i] >> w[i]; }
	
	auto dp = MV(0, (1 << B) + 1, M + 1);
	inc(i, 1 << (B - 1)) {
		int p = (1 << (B - 1)) + i;
		if(p > n) { break; }
		
		vector<int> a;
		until(p == 0) {
			a.PB(p);
			p /= 2;
		}
		
		assert(SI(a) == B);
		inc(b, 1 << B) {
			int vs = 0, ws = 0;
			inc(j, B) { if(bit(b, j) == 1) { vs += v[a[j]]; ws += w[a[j]]; } }
			if(ws <= M) { setmax(dp[i][ws], vs); }
		}
		inc1(j, M) { setmax(dp[i][j], dp[i][j - 1]); }
	}
	
	IN(int, q);
	inc(qq, q) {
		IN(int, p, L);
		vector<int> a;
		until(p == 0 || BL(p) == B) {
			a.PB(p);
			p /= 2;
		}
		if(p == 0) { p = 1 << B; }
		p -= 1 << (B - 1);
		
		int ans = 0;
		inc(b, 1 << SI(a)) {
			int vs = 0, ws = 0;
			inc(j, B) { if(bit(b, j) == 1) { vs += v[a[j]]; ws += w[a[j]]; } }
			
			if(ws <= L) { setmax(ans, vs + dp[p][L - ws]); }
		}
		OUT(ans);
	}
}


Measured memory_bytes: 206784