akhauriyash/Code-Regression huggingface dataset:
#pragma GCC diagnostic ignored "-Wunused-result"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 502;
//const ll INF = (ll)1e18 + 41;
const int INF = (int)1e9 + 41;
const ll MD = (ll)1e9 + 7;
bool D = false;

int sum[N][N], a[N][N];
int max_depth[N][N];
short int r[N][N][N];
short int l[N][N][N];

void solve() {
    int n, m;
    cin >> n;
    m = n;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            a[i][j] = 0;
            max_depth[i][j] = i;
            sum[i][j] = 0;
            short int *r2 = r[i][j];
            short int *l2 = l[i][j];
            auto val_l = (short int)N;
            auto val_r = (short int)-1;
            for (int h = 0; h <= n; h++) {
                l2[h] = val_l;
                r2[h] = val_r;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < m; j++) {
            if (s[j] == '#') a[i][j] = 0;
            else a[i][j] = s[j] - '0';
        }
    }
    ll ans = 0;

    for (int i = n - 1; i >= 0; i--) {
        for (int j = m - 1; j >= 0; j--) {
            if (a[i][j] == 0) {
                max_depth[i][j] = -1;
                continue;
            }

            short int *left = r[i + 1][j];
            short int *_left = l[i + 1][j];
            short int *rait = l[i][j + 1];
            short int *_rait = r[i][j + 1];
            short int *meL = l[i][j];
            short int *meR = r[i][j];

            meL[i] = (short int)j;
            meR[i] = max(meL[i], _rait[i]);
            for (int h = i + 1; h < n; h++) {
                meL[h] = min(_left[h], rait[h]);
                meR[h] = max(left[h], _rait[h]);
            }
            max_depth[i][j] = max(i, max(max_depth[i + 1][j], max_depth[i][j + 1]));

            int cur_sum = sum[i][j + 1] + sum[i + 1][j];
            int h = i;
            //cout << i << " " << j << endl;
            if (i == 1 && j == 0) {
                j = i * j;
            }
            while (h < n) {
                while (h < n && left[h] < rait[h]) h++;
                if (h >= n) continue;

                cur_sum -= sum[h][rait[h]];
                h = max_depth[h][rait[h]] + 2;
            }

            sum[i][j] = cur_sum + a[i][j];
            ans += a[i][j] * cur_sum;
        }
    }

    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tst = 1;
    //scanf("%d", &tst);
    //cin >> tst;
#ifdef MADE_BY_SERT
    //freopen("a.in", "r", stdin);
    D = true;
    tst = 4;
    while (tst--) {
        solve();
    }
#else
    while (tst--) solve();
#endif
}


Measured memory_bytes: 497408
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", function (chunk) {
    var input = chunk.trim().split("\n");
    var order = 1;
    while (true) {
        var n = input.shift();
        if (n == 0)
            break;
        var coordinate = [];
        while (n--)
            coordinate.push(input.shift().split(" ").map(Number));
        coordinate.push(coordinate[0]);
        var area = 0;
        for (var i = 0; i < coordinate.length - 1; i++) {
            area += (coordinate[i][0] * coordinate[i + 1][1]) - (coordinate[i][1] * coordinate[i + 1][0]);
        }
        console.log(order + " " + Math.abs(area / 2).toFixed(1));
        input.shift();
        order++;
    }
});

Measured memory_bytes: 17016
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace __gnu_pbds;
using namespace std;
//typedef
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
//constants
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
// gcd of a and b
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
// distance between (a,b) and (c,d)
long double dis(long long a,long long b,long long c,long long d){return sqrt( ((a)-(c))*((a)-(c))+((b)-(d))*((b)-(d)) );}
// simple prime check
bool isprime(long long a){
if(a==2)return 1;
if(!(a&1))return 0;
for(ll i=3;i*i<=a;i+=2){
	if(a%i==0)return 0;
}
return 1;
}
// fast expo
long long mpow(long long base,long long exponent,long long modulus){
if(modulus==1)return 0;
long long result = 1;
base=base%modulus;
while(exponent){
		if(exponent%2 == 1)
			result=(result*base)%modulus;
		exponent=exponent>>1;
		base=(base*base)%modulus;
	}
return result;
}
// modular inverse
ll minv(ll a,ll mod){
	ll _gcd=gcd(a,mod);
	assert(_gcd==1);
	return mpow(a,mod-2,mod);
}

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*
ll dx[]={1,0,-1,0,1,1,-1,-1};
ll dy[]={0,-1,0,1,1,-1,-1,1};
*/

/*
void sieve(int N){
	for(int i=0;i<=N;i++){
		spf[i]=i;
	}
	for(int i=2;i*i<=N;i++){
		if(spf[i]==i){
			for(int j=i*i;j<=N;j+=i){
				spf[j]=min(spf[j],i);
			}
		}
	}
	return;
}
*/

/*
void nCr(ll n,ll k){
	ll i,j;
	for(i=0;i<=n;i++){
		for(j=0;j<=min(i,k);j++){

			if(j==0 or j==i)C[i][j]=1LL;
			else  C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}
	}
	return;
}
*/
/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll n,x;
ll l[1005],d[1005];
int main(){FAST;
	cin>>n>>x;
for(ll i=1;i<=n;i++){
	cin>>l[i];
}
for(ll i=2;i<=n+1;i++){
	d[i]=d[i-1]+l[i-1];
}
ll ans = 0;
for(ll i=1;i<=n+1;i++)if(d[i]<=x)ans++;
	cout<<ans;
return 0;
}

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

int main(void){
  string s;
  cin >> s;
  int mxs = 0;
  for(int i=0;i<s.length();i++){
    int cnt = 0;
    for(int j=i;j<s.length();j++){
      if(s[j] != 'A' && s[j] != 'T' && s[j] != 'G' && s[j] != 'C'){
        break;
      }else{
        cnt++;
      }
    }
    mxs = max(mxs,cnt);
  }

  cout << mxs << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os
from math import sin, cos
import math

alphabet = 'abcdefghijklmnopqrstuvwxyz'


def rotate_char(c, num):
    if c == ' ' or c == '.' or c == '\n':
        return c

    n = ord(c) + num
    if n > 122:
        n -= 26
    return chr(n)

def rotate_string(s, num):
    ret = []
    for c in s:
        new_c = rotate_char(c, num)
        ret.append(new_c)
    return ''.join(ret)

for s in sys.stdin:
    for i in range(26):
        rotated = rotate_string(s, i)
        if 'the' in rotated or 'this' in rotated or 'that' in rotated:
            print(rotated, end='')
            break

Measured memory_bytes: 7548
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,l;
  cin>>n>>l;
  if(l>0) cout<<(n-1)*(2*l+n)/2<<endl;
  else if(l+n-1<0) cout<<(n-1)*(2*l+n-2)/2<<endl;
  else cout<<n*(2*l+n-1)/2<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

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


        String temp = sc.nextLine();
        String[] tempArr = temp.split("");
        int cnt1 = 0,cnt2 = 0;
        for(String str : tempArr) {
            if (str.equals("0")) {
                cnt1++;
            }else {
                cnt2++;
            }
        }

        System.out.println(Math.min(cnt1,cnt2) * 2);


    }

}


Measured memory_bytes: 32852
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> G(N, vector<int>());
    rep(i, N) {
        string s;
        cin >> s;
        rep(j, s.size()) {
            if (s[j] - '0' == 1) {
                G[i].push_back(j);
            }
        }
    }

    int ans = -1;

    rep(k, N) {
        vector<int> label(N, -1);
        label[k] = 1;
        queue<int> que;
        que.push(k); // 0 を橙色頂点にする
        set<int> se;
        se.insert(1);

        // BFS 開始 (キューが空になるまで探索を行う)
        while (!que.empty()) {
            int v = que.front(); // キューから先頭頂点を取り出す
            que.pop();

            // v から辿れる頂点をすべて調べる
            for (int nv : G[v]) {
                if (label[nv] != -1)
                    continue; // すでに発見済みの頂点は探索しない

                // 新たな白色頂点 nv について距離情報を更新してキューに追加する
                label[nv] = label[v] + 1;
                se.insert(label[nv]);
                que.push(nv);
            }
        }

        bool judge = 1;
        rep(i, N) {
            rep(j, G[i].size()) {
                if (abs(label[i] - label[G[i][j]]) != 1) {
                    judge = 0;
                    break;
                }
            }
            if (!judge)
                break;
        }

        if (judge)
            ans = max(ans, (int)se.size());
    }

    cout << ans << endl;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define plskz ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;

int main() {
    plskz

    int k;
    string s;
    cin >> k >> s;

    if(s.size() <= k)
        cout << s;
    else
        cout << s.substr(0, k) << "...";
}   

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    double n;
    cin >> n;
    cout << (ceil(n/2)) / n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxc 123456

int gcd(ll a,ll b)
{
    if(a==b){
        return a;
    }
    ll c;
	if(a<b)
	{	a=a+b;
		b=a-b;
		a=a-b;
	}
	c=a%b;
	while(a%b!=0)
	{	a=b;
		b=c;
		c=a%b;
	}
	return b;
}
int main ()
{
    ll n,m;
    ll a[maxc];
    cin>>n>>m;
    a[0]=m;
    if(n==1){
        ll g;
        cin>>g;
        printf("%lld\n",abs(g-m));
        return 0;
    }
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int b[maxc];
    for(int i=0;i<=n;i++){
        b[i]=abs(a[i+1]-a[i]);
    }
    /*for(int i=0;i<n;i++)
        printf("%d ",b[i]);
    cout<<endl;*/
    ll add=gcd(b[0],b[1]);
        /*cout<<add<<endl;*/
    for(int i=2;i<n;i++){
        add=gcd(add,b[i]);
         /*cout<<add<<endl;*/
        if(add==1)
            break;
    }
    printf("%lld\n",add);
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

signed main() {
	string S = nextString();

	rep(i, S.size()) {
		if (i > 0 && S[i] == S[i-1]) {
			cout << i << ' ' << (i + 1) << endl;
			return 0;
		} else if (i > 1 && S[i] == S[i - 2]) {
			cout << (i - 1) << ' ' << (i + 1) << endl;
			return 0;
		}
	}

	cout << "-1 -1" << endl;

    return 0;
}


Measured memory_bytes: 512
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>

const long long INF = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong N;
    cin >> N;
    llong ans=INF;
    vector<llong> W(N, 0);
    llong S1, S2;
    for(int i=0; i<W.size(); i++){
        cin >> W[i];
    }
    
    for(int T=0; T<N-1; T++){
        S1 = 0;
        S2 = 0;
        for(int i=0; i<W.size(); i++){
            if(T>=i){
                S1 = S1 + W[i];
            }else{
                S2 = S2 + W[i];
            }
        }
        ans = min(ans, abs(S1-S2));
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;


typedef struct rec {

  int id;
  int time;

} record;

record rank[1000001];

int comp(const void* a,const void* b) {

  record t1=*(record*) a;
  record t2=*(record*) b;

  return t1.time-t2.time;

}

int main() {

  int n;
  int c1,m1,s1,m2,s2,m3,s3,m4,s4;


  while(cin >> n,n) {

    for(int i=0;i<n;i++) {

      record tmp;

      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;

      rank[i].id=c1;

      rank[i].time=(60*m1+s1)+(60*m2+s2)+(60*m3+s3)+(60*m4+s4);

    }

    //for(int i=0;i<n;i++) cout << rank[i].id << " " << rank[i].time << endl;

    qsort(rank,n,sizeof(rank[0]),comp);

    //for(int i=0;i<n;i++) cout << rank[i].id << " " << rank[i].time << endl;

    cout << rank[0].id << endl;

    cout << rank[1].id << endl;

    cout << rank[n-2].id << endl;

  }

  return 0;

}

Measured memory_bytes: 1020
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int dx[2][6]={{-1,-1,0,0,1,1},{-1,-1,0,0,1,1}};
int dy[2][6]={{-1,0,-1,1,-1,0},{1,0,-1,1,1,0}};
int bfs[110][110];
int m[110][110];
int main(){
	int a,b;
	while(scanf("%d%d",&b,&a),a){
		int c;scanf("%d",&c);
		queue<pair<int,int> >Q;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)bfs[i][j]=-1;
		for(int i=0;i<c;i++){
			int p,q;scanf("%d%d",&q,&p);
			p--;q--;
			bfs[p][q]=0;
			Q.push(make_pair(p,q));
		}
		while(Q.size()){
			int row=Q.front().first;
			int col=Q.front().second;
			Q.pop();
			int t=row%2;
			for(int i=0;i<6;i++){
				if(0<=row+dx[t][i]&&row+dx[t][i]<a&&0<=col+dy[t][i]&&col+dy[t][i]<b&&!~bfs[row+dx[t][i]][col+dy[t][i]]){
					bfs[row+dx[t][i]][col+dy[t][i]]=bfs[row][col]+1;
					Q.push(make_pair(row+dx[t][i],col+dy[t][i]));
				}
			}
		}
		int ret=0;
		int d;scanf("%d",&d);
		for(int i=0;i<d;i++){
			int p,q;scanf("%d%d",&q,&p);p--;q--;
			for(int j=0;j<a;j++)for(int k=0;k<b;k++)m[j][k]=-1;
			m[p][q]=0;
			Q.push(make_pair(p,q));
			while(Q.size()){
				int row=Q.front().first;
				int col=Q.front().second;
				Q.pop();
				int t=row%2;
				for(int j=0;j<6;j++){
					if(0<=row+dx[t][j]&&row+dx[t][j]<a&&0<=col+dy[t][j]&&col+dy[t][j]<b&&!~m[row+dx[t][j]][col+dy[t][j]]){
						m[row+dx[t][j]][col+dy[t][j]]=m[row][col]+1;
						Q.push(make_pair(row+dx[t][j],col+dy[t][j]));
					}
				}
			}
			int val=0;
			for(int j=0;j<a;j++)for(int k=0;k<b;k++)if(bfs[j][k]>m[j][k])val++;
			ret=max(val,ret);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1080
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int main(){
  ll n;
  cin>>n;
  ll d[n];
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  sort(d,d+n);
  ll a=d[n/2];
  ll b=d[n/2-1];
  ll ans=a-b;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 1024
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int n;
	string s;
	cin >> n >> s;
	int w = 0, r = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'W')
			w++;
		else
			r++;
	}
	int mn = 201234567;
	int w1 = 0, r1 = 0;
	for (int i = 0; i <= n; i++) {
		int w2 = w - w1, r2 = r - r1;
		mn = min(mn, max(w1, r2));
		if (i == n)
			continue;
		if (s[i] == 'W')
			w1++;
		else
			r1++;
	}
	cout << mn << endl;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 1e9;
const int MOD = 1000000007;

struct Sieve {
        int n;
        vector<int> f,primes;
        
        Sieve(int n=1):n(n),f(n+1){
                f[0] = f[1] = -1;
                for(long long i=2;i<=n;++i){
                        if(f[i]) continue;
                        primes.push_back(i);
                        f[i] = i;
                        for(long long j = i*i;j <= n;j += i) {
                                if(!f[j]) f[j] = i;
                        }
                }
        }
        
        bool isPrime(int x){return f[x] == x;}
        
        vector<int> factorList(int x){
                vector<int> res;
                while(x != 1){
                        res.push_back(f[x]);
                        x /= f[x];
                }
                return res;
        }
        
        vector<pair<int,int>> factor(int x){
                vector<int> fl = factorList(x);
                if(fl.size() == 0) return {};
                vector<pair<int,int>> res(1,pair<int,int>(fl[0],0));
                for(int p:fl){
                        if(res.back().first == p){
                                res.back().second ++;
                        }else{
                                res.emplace_back(p,1);
                        }
                }
                return res;
        }
        
};

int main(){
        Sieve sieve(55560);
        int n ;
        cin >> n;
        int i = 0;
        vector<int> ans;
        while(ans.size() < n){
                if(sieve.isPrime(5*i+1)){
                        ans.push_back(5*i+1);
                }
                i++;
        }
        rep(j,n){
                cout << ans[j] << " "  ;
        }
        cout << endl;
}

Measured memory_bytes: 512
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_A

fn main() {
    // snip
    struct SegmentTree<T: Clone + Copy>{
        n: usize,
        f: fn(T, T) -> T,
        e: T,
        x: Vec<T>
    }

    impl<T: Clone + Copy> SegmentTree<T> {
        fn new(n: usize, f: fn(T, T) -> T, e: T) -> SegmentTree<T> {
            let m = 1 << format!("{:b}", n).len();
            SegmentTree { n: m, f: f, e: e, x: vec![e; 2 * m - 1] }
        }
        fn update(&mut self, i: usize, y: T) {
            let mut j = i + self.n - 1;
            self.x[j] = y;
            while j > 0 {
                j = (j - 1) / 2;
                self.x[j] = (self.f)(self.x[2 * j + 1], self.x[2 * j + 2]);
            }
        }
        fn find(&self, s: usize, t: usize) -> T { self.q(0, 0, self.n, s, t) }
        fn q(&self, i: usize, l: usize, r: usize, s: usize, t: usize) -> T {
            if l >= t || r <= s { self.e }
            else if s <= l && r <= t { self.x[i] }
            else {
                (self.f)(
                    self.q(2 * i + 1, l, (l + r) / 2, s, t),
                    self.q(2 * i + 2, (l + r) / 2, r, s, t)
                )
            }
        }
    }
    // snip

    let (n, q): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let (com, x, y): (Vec<usize>, Vec<usize>, Vec<usize>) = {
        let (mut com, mut x, mut y) = (vec![], vec![], vec![]);
        for _ in 0..q {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            com.push(iter.next().unwrap().parse().unwrap());
            x.push(iter.next().unwrap().parse().unwrap());
            y.push(iter.next().unwrap().parse().unwrap());
        }
        (com, x, y)
    };
    const INF: usize = (2 << 30) - 1;
    let mut segt = SegmentTree::new(n, std::cmp::min, INF);

    for i in 0..q {
        if com[i] == 0 { segt.update(x[i], y[i]); }
        else {
            let ans = segt.find(x[i], y[i] + 1);
            println!("{}", ans);
        }
    }
}


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

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

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

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

const double pi = 3.141592653589793;
// -------------------------------------------------------
int N;
int C[1000], S[1000], F[1000];

int main() {
  cin >> N;
  repe(i, 1, N - 1) { cin >> C[i] >> S[i] >> F[i]; }

  repe(i, 1, N - 1) {
    int t = 0;
    repe(j, i, N - 1) {
      if (t < S[j]) {
        t = S[j];
        t += C[j];
      } else {
        int modf = t % F[j];
        t += (F[j] - modf) % F[j];
        t += C[j];
      }
    }
    cout << t << endl;
  }
  cout << 0 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int a[6];
int num(int b){
    int counter=0;
    for(int i=0;i<6;i++){
        if(i==b) continue;
        else if(a[i]==a[b])counter++;
    }
    return counter;
}
int main(void){
    for(int i=0;i<6;i++) scanf("%d",&a[i]);
    for(int j=0;j<6;j++) if(num(j)==2){
                             printf("NO");
                             return 0;
                         }
    printf("YES");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
    int r,g,b;
    cin>>r>>g>>b;
    int k=r*100+g*10+b;
    if(k%4==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<unordered_map>
#include<string>
#include<algorithm>
#include<set>
#define _ cin.tie(0);ios_base::sync_with_stdio(false);
using namespace std;
const int N = 200 + 5;
const int M = 8 + 5;
const int INF = 0x3f3f3f3f;

unordered_map<int, int> mp;
int main(){ _
    int n, x;
    cin >> n;
    while(n --){
        cin >> x;
        ++ mp[x];
    }
    int cnt = 0;
    for(auto &i: mp){
        cnt += i.second%2;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
int n,m,k;

int main() {
    cin >> n >> m >> k;
    for (int i=0;i<=n;++i) for (int j=0;j<=m;++j) {
        int s=i*m+j*n-2*i*j;
        if (s==k) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifndef U_L_LONG
typedef unsigned long long ULLONG;
#endif
#ifndef L_LONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}


static void ABC105D_CandyDistribution();

#if 1
int main()
{
	ABC105D_CandyDistribution();
	fflush(stdout);
	return 0;
}
#endif


static void ABC105D_CandyDistribution()
{
	int N, M;
	get2int(N, M);

	std::map<LLONG, LLONG> modPair;
	modPair[0]++;

	LLONG sum = 0;
	for (int i = 0; i < N; i++) {
		LLONG snack;
		get1int<LLONG>(snack);
		sum = snack + sum;

		LLONG sup = sum % (LLONG)M;
		modPair[sup]++;
	}
	
	LLONG groups = 0;

	for (auto mIt = modPair.begin(); mIt != modPair.end(); mIt++) {
		groups += (mIt->second) * (mIt->second - 1) / 2;
	}
	printf("%lld\n", groups);
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    int n, m; cin>>n>>m;
    int l=1,r=n; 
    int ans=n;
    rep(i, m){
        int p, q; cin>>p>>q;
        if(l<p) l=p;
        if(q<r) r=q;
        if(l>r) {
            ans = 0;
            break;
        }
        ans = min(ans, r-l+1);
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
A = list(map(int,input().split()))
flag = 0
#mi = min(A)
Q = np.array(A)
an = 1
def toku(Q):
    mi = min(Q)
    R1 = Q % mi
    if any(R1) == 0:
        flag = 1
        an = mi
        return flag, an, R1
    else:
        flag = 0
        an = 1
        ind = np.argmin(Q)
        R1[ind] = mi
        R = R1[R1!=0]
        return flag, an, R

while flag == 0:
    flag,an,PP = toku(Q)
    Q = PP

print(an)

Measured memory_bytes: 23136
n = int(input())
s = input()
s2 = input()
i = 0
flag = -1
ans = 1
mod = 1000000007
while i<n:
  if s[i] == s2[i]:
    if flag == -1:
      ans *= 3
      flag = 0
    elif flag == 0:
      ans *= 2
      flag=0
    else:
      flag=0
    i+=1
  else:
    if flag == -1:
      ans *= 6
      flag = 1
    elif flag == 0:
      ans *= 2
      flag = 1
    else:
      ans *= 3
      flag = 1
    i += 2
  ans %= mod
print(ans)

Measured memory_bytes: 3064
def getInv(N):#Qはmod
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv

Q = 10**9+7
modinv = getInv(4*10**5)
N, M, K = map( int, input().split())
T = N*M
comb = 1
for i in range(K-2):
    comb *= T-2-i
    comb %= Q
    comb *= modinv[K-2-i]
    comb %= Q
ans = 0
for i in range(1, M):
    ans += N**2*(M-i)*i
    ans %= Q
for i in range(1, N):
    ans += M**2*(N-i)*i
    ans %= Q
ans %= Q
print( ans*comb%Q)


Measured memory_bytes: 42224
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.nextInt();
            int n = in.nextInt();

            if (k % 2 == 0) {
                out.print(k / 2);
                for (int i = 0; i < n - 1; i++) {
                    out.print(" " + k);
                }
                out.println();
                return;
            }

            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                list.add((k + 1) / 2);
            }
            for (int i = 0; i < n / 2; i++) {
                if (list.get(list.size() - 1) == 1) {
                    list.remove(list.size() - 1);
                } else {
                    list.set(list.size() - 1, list.get(list.size() - 1) - 1);
                    while (list.size() < n) list.add(k);
                }
            }
            for (int i = 0; i < list.size(); i++) {
                if (i > 0) out.print(" ");
                out.print(list.get(i));
            }
            out.println();
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll MOD = 1e9 + 7;
    //N文字目までで、AGC,GAC,ACGを含まない末尾3文字の通り数(0:A,1:G,2:C,3:T)
    vector<vector<vector<vector<ll>>>> dp(N + 1, vector<vector<vector<ll>>>(4, vector<vector<ll>>(4, vector<ll>(4))));
    ll answer = 0;
    map<int, char> charMap;
    charMap[0] = 'A';
    charMap[1] = 'G';
    charMap[2] = 'C';
    charMap[3] = 'T';
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int k = 0; k < 4; k++)
            {
                for (int l = 0; l < 4; l++)
                {
                    if ((charMap[j] == 'A' && charMap[k] == 'G' && charMap[l] == 'C') 
                    || (charMap[j] == 'G' && charMap[k] == 'A' && charMap[l] == 'C') 
                    || (charMap[j] == 'A' && charMap[k] == 'C' && charMap[l] == 'G'))
                    {
                        continue;
                    }
                    if (i <= 2)
                    {
                        dp.at(i + 1).at(j).at(k).at(l) = 1;
                    }
                    else
                    {
                        for (int m = 0; m < 4; m++)
                        {
                            if((charMap[m] == 'A' && charMap[k] == 'G' && charMap[l] == 'C')
                            ||(charMap[m] == 'A' && charMap[j] == 'G' && charMap[l] == 'C'))
                            {
                                continue;
                            }
                            dp.at(i + 1).at(j).at(k).at(l) += dp.at(i).at(m).at(j).at(k);
                            dp.at(i + 1).at(j).at(k).at(l) %= MOD;
                        }
                    }
                    if (i == N - 1)
                    {
                        answer = (answer + dp.at(N).at(j).at(k).at(l)) % MOD;
                    }
                }
            }
        }
    }
    cout << answer << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

constexpr ll INF=1e18;
ll dp[125252];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, m;
  string s;
  cin>>n>>m>>s;
  REP(i, n+1){
    dp[i]=INF;
  }
  dp[n]=0;
  vi ans;
  int cur=n;
  while(cur>0){
    bool ok=false;
    FOR(i, cur-m, cur){
      if(i<=0){
        dp[0]=dp[cur]+1;
        ans.push_back(cur);
        cur=0;
        ok=true;
        break;
      }
      if(s[i]=='0'){
        dp[i]=dp[cur]+1;
        ans.push_back(cur-i);
        cur=i;
        ok=true;
        break;
      }
    }
    if(!ok){
      break;
    }
  }
  if(dp[0]!=INF){
    int l=ans.size();
    FORR(i, 0, l){
      cout<<ans[i]<<" \n"[i==0];
    }
  }
  else{
    cout<<-1<<'\n';
  }
  return 0;
}


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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

ll gcd(ll x, ll y)
{
  if (x % y == 0)
  {
    return y;
  }
  return gcd(y, x % y);
}

int main()
{
  char A[2][3];
  rep(i,0,3)cin >> A[0][i];
  rep(i,0,3)cin >> A[1][i];

  bool ans = true;
  rep(i, 0, 3){
    if (A[0][i] != A[1][2-i])
    {
      ans = false;
    }
  }
  if (ans)
  {
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int H, W;
	scanf("%d %d", &H, &W);
	bool dptable[H][W][25600];
	int A[H][W], B[H][W];
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) scanf("%d", &A[i][j]);
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) scanf("%d", &B[i][j]);
	}
	for (int i = 0; i < 25600; ++i) {
		if (i == 12800 + (A[0][0] - B[0][0]) || i == 12800 + (B[0][0] - A[0][0])) dptable[0][0][i] = true;
		else dptable[0][0][i] = false;
	}
	for (int i = 1; i < W; ++i) {
		for (int j = 0; j < 25600; ++j) {
			dptable[0][i][j] = false;
			if (j + (A[0][i] - B[0][i]) >= 0 && j + (A[0][i] - B[0][i]) < 25600) dptable[0][i][j] |= dptable[0][i - 1][j + (A[0][i] - B[0][i])];
			if (j + (B[0][i] - A[0][i]) >= 0 && j + (B[0][i] - A[0][i]) < 25600) dptable[0][i][j] |= dptable[0][i - 1][j + (B[0][i] - A[0][i])];
		}
	}
	for (int i = 1; i < H; ++i) {
		for (int j = 0; j < 25600; ++j) {
			dptable[i][0][j] = false;
			if (j + (A[i][0] - B[i][0]) >= 0 && j + (A[i][0] - B[i][0]) < 25600) dptable[i][0][j] |= dptable[i - 1][0][j + (A[i][0] - B[i][0])];
			if (j + (B[i][0] - A[i][0]) >= 0 && j + (B[i][0] - A[i][0]) < 25600) dptable[i][0][j] |= dptable[i - 1][0][j + (B[i][0] - A[i][0])];
		}
	}
	for (int i = 1; i < H; ++i) {
		for (int j = 1; j < W; ++j) {
			for (int k = 0; k < 25600; ++k) {
				dptable[i][j][k] = false;
				if (k + (A[i][j] - B[i][j]) >= 0 && k + (A[i][j] - B[i][j]) < 25600) {
					dptable[i][j][k] |= dptable[i][j - 1][k + (A[i][j] - B[i][j])];
					dptable[i][j][k] |= dptable[i - 1][j][k + (A[i][j] - B[i][j])];
				}
				if (k - (A[i][j] - B[i][j]) >= 0 && k - (A[i][j] - B[i][j]) < 25600) {
					dptable[i][j][k] |= dptable[i][j - 1][k - (A[i][j] - B[i][j])];
					dptable[i][j][k] |= dptable[i - 1][j][k - (A[i][j] - B[i][j])];
				}
			}
		}
	}
	for (int i = 0; i < 12800; ++i) {
		if (dptable[H - 1][W - 1][12800 + i] || dptable[H - 1][W - 1][12800 - i]) {
			printf("%d", i);
			return 0;
		}
	}
}


Measured memory_bytes: 160256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(v) (v).begin(),(v).end()
#define endl '\n'

using namespace std;

const int N = 100005;
const int LG = 19;
const int MOD = 1e9 + 7;
const int INF = 2000000000;
const ll INFLL = 1LL * INF * INF;

int dp[N][2];
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    dp[0][0] = (s[0] != '0');
    dp[0][1] = (s[0] != '1');
    for (int i = 1; i < s.size(); i++) {
        dp[i][0] = dp[i - 1][1] + (s[i] != '0');
        dp[i][1] = dp[i - 1][0] + (s[i] != '1');
    }
    cout << min(dp[s.size()-1][0], dp[s.size()-1][1]) << endl;
    return 0;
}


Measured memory_bytes: 1232
#2020-03-21
lst = input()
count = int(input())
for i in range(count):
    t = input().split()
    a = int(t[1])
    b = int(t[2])
    if t[0] == 'print':
        print(lst[a:b+1])

    elif t[0] == 'replace':
        lst = lst[0 : a] + t[3] + lst[b + 1 :]

    elif t[0] == "reverse":
        lst = lst[0:a] + lst[a:b+1][::-1] + lst[b+1:]


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  // 入力
  ll D;
  cin >> D;
  vll C(26);
  rep(i, 26) cin >> C[i];
  vvll S(D, vll(26));
  rep(i, D) rep(j, 26) cin >> S[i][j];

  vll T(D);  // その日に行うコンテスト
  rep(i, D) {
    T[i] = i % 26 + 1;
  }

  auto calc = [&]() -> ll {
    vll la(26, 0);
    ll res = 0;
    rep(i, D + 1) {
      if (i == 0) continue;
      ll t = T[i - 1];
      res += S[i - 1][t];
      la[t] = i;
      rep(j, 26) {
        res -= C[j] * (i - la[j]);
      }
    }
    return res;
  };

  rep(i, 10) {
    ll original = calc();
    ll index = rand() % D;
    ll before_contest = T[index];
    ll after_contest = (rand() % 26) + 1;
    T[index] = after_contest;
    ll after = calc();
    if (original < after) {
      continue;
    } else {
      T[index] = before_contest;
    }
  }

  rep(i, D) {
    COUT(T[i]);
  }

  return 0;
}

Measured memory_bytes: 3772
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 998244353;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};
//uniform_int_distribution(0,1)(rng)
string toString(long long x)
{
stringstream ss;
ss << x;
string str = ss.str();
return str;
}
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int main()
{
    IO;
    string s;
    cin >> s;
    int f1 = 0,f2 = 0;
    for(int i = 0;i < s.length();i++)
    {
        f1 += ((i % 2) ? s[i] == '0' : s[i] == '1');
        f2 += ((i % 2) ? s[i] == '1' : s[i] == '0');
    }
    cout << min(f1,f2);
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int[] A;
        int i, j;

        A = new int[10000];

        i=0;
        while(true){
            if(i == 10000){break;}
            A[i] = sc.nextInt();
            if(A[i] == 0){break;}
            i++;
        }

        for(j=1;j<=i;j++){
            System.out.println("Case " + j + ": " + A[j-1]);
        }
    }
}



Measured memory_bytes: 42924
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

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

func main() {
	sc.Split(bufio.ScanWords)
	
	n := scanInt()

	ans := 0
	d := 1
	for i := 1; i < n+1; i*=10 {
		if d%2 == 0 {
			d++
			continue
		}
		
		if n/i/10 == 0 {
			ans += n-i+1
		} else {
			ans += i*10-i
		}
		d++
	}
	
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}
  
int main() {
  int k, n;
  cin >> k >> n;
  vector<int> p(n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int q;
    cin >> q;
    sum += q;
  }
  if (sum > k) {
    cout << -1 <<endl;
  }
  else {
    cout << k - sum <<endl;
  }
} 


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

vector<int> tsort(vector<vector<int>> G){

  int n = G.size();
  vector<int> sorted,indeg(n,0); //入次数
  for(int u = 0; u < n; u++){
    for(int v : G[u]){
      indeg[v]++;
    }
  }

  //priority_queue<int,vector<int>,greater<int>> q; //最小値
  queue<int> q;
  for(int u = 0; u < n; u++){
    if(indeg[u] == 0) q.push(u);
  }
  while(!q.empty()){
    int u = q.front(); q.pop();
    for(int v : G[u]){
      indeg[v]--;
      if(indeg[v] == 0) q.push(v);
    }
    sorted.push_back(u);
  }
  return sorted;
}

signed main(){

  int n,m; cin >> n >> m;
  vector<vector<int>> G(n);
  for(int i = 0; i < n-1+m; i++){
    int a,b; cin >> a >> b;
    a--,b--;
    G[a].push_back(b);
  }

  auto v = tsort(G);
  vector<int> dp(n,0),ans(n,0);
  // function< void(int,int,int) > dfs =
  // [&](int u,int pre,int d){
  //   if(dp[u] < d){
  //     dp[u] = d;
  //     ans[u] = pre+1 - (pre == -1);
  //   }
  //   for(int v : G[u]){
  //     if(v == pre) continue;
  //     dfs(v,u,d+1);
  //   }
  //
  // };
  // dfs(v[0],-1,0);

  for(int i = 0; i < n; i++){
    for(int u : G[v[i]]){
      if(dp[u] < dp[v[i]]+1){
        dp[u] = dp[v[i]]+1;
        ans[u] = v[i]+1;
      }
    }
  }

  for(int i = 0; i < n; i++){
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 13180
import numpy as np
a, b = map(int, input().split())

num = [i+1 for i in range(999)]

tower = np.cumsum(num)

for j in range(len(tower) - 1):
    if tower[j] - a == tower[j+1] - b:
        print(tower[j] - a)
        break
    else:
        continue

Measured memory_bytes: 21288
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int N, D;
  cin >> N >> D;
  if (N%((2*D)+1)) {
    cout << N/(2*D+1)+1 << endl;

  } else {
    cout << N/(2*D+1) << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

string s;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	sort(s.begin(), s.end());
	cout << ((s == "abc") ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long double PI = 3.14159265358979323846;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    bool turn = true;
    while (a > 0 && c > 0) {
        if (turn) {
            c -= b;
        } else {
            a -= d;
        }
        turn = !turn;
    }
    if (a <= 0) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }

    return 0;
}


Measured memory_bytes: 3560