akhauriyash/Code-Regression huggingface dataset:
class Vector2:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Vector2(self.x + other.x, self.y + other.y)

    def __hash__(self):
        return self.x * 10 + self.y

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y


def create_water_range():
    l = []

    for item in [-1, 0, 1]:
        for item2 in [-1, 0, 1]:
            l.append(Vector2(item, item2))

    return l


def create_jump_range():
    l = []

    for item in [-2, 2]:
        for item2 in [-1, 0, 1]:
            l.append(Vector2(item, item2))
            l.append(Vector2(item2, item))

    return l


WATER_RANGE = create_water_range()
JUMP_RANGE = create_jump_range()


def is_live(water_count, point, LIMIT, WATER_POINT_LIST):
    if LIMIT <= water_count:
        return True

    center = WATER_POINT_LIST[water_count]

    water_point_set = set(center + water for water in WATER_RANGE)

    for jump in JUMP_RANGE:
        new_point = point + jump

        if 0 <= new_point.x <= 9 and 0 <= new_point.y <= 9:
            if new_point in water_point_set:
                result = is_live(water_count + 1, new_point, LIMIT, WATER_POINT_LIST)

                if result:
                    return result

    return False


while True:
    x, y = [int(item) for item in input().split(" ")]

    if x == 0 and y == 0:
        break

    my_point = Vector2(x, y)

    water_count = int(input())
    point_list = [int(item) for item in input().split(" ")]

    water_point_list = []

    for x, y in zip(point_list[::2], point_list[1::2]):
        water_point_list.append(Vector2(x, y))

    result = is_live(0, my_point, water_count, water_point_list)

    if result:
        print("OK")
    else:
        print("NA")



Measured memory_bytes: 5648
import sys
import bisect
sys.setrecursionlimit(10**9)
INF = 2**30
N = int(input())
A = list(map(int, input().split()))
E = []
for i in range(N):
    E.append([])
for i in range(N-1):
    u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    E[u].append(v)
    E[v].append(u)

ans = [0] * N
dp = [INF] * N

def dfs(now, par, len):
    ok = bisect.bisect_left(dp, A[now])
    memo = dp[ok]
    dp[ok] = A[now]

    ok1 = bisect.bisect_left(dp, INF)
    ans[now] = ok1

    for to in E[now]:
        if to == par:
            continue
        dfs(to, now, len+1)
    dp[ok] = memo

dfs(0, -1, 0)

for i in range(N):
    print(ans[i])


Measured memory_bytes: 230860
#include "stdio.h"

int main(){
  int x,c=0;
  scanf("%d",&x);
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j==x)c=1;
    }
  }
  if(c==1)printf("Yes");
  if(c==0)printf("No");
  return 0;
}

Measured memory_bytes: 128
s = input()
k = int(input())
 
limit = min(100, k)
 
ans = 1
for i in range(limit):
    if s[i] != '1': # K番目までで1が登場すれば1、そうでなければその次のもの
        ans = s[i]
        break
 
print(ans)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


ll dp[60][205000];
int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    vector<ll> s(m + 1);
    rep(i, n) cin >> a[i];
    rep(i, m) {
        cin >> b[i];
        s[i + 1] = s[i] + b[i];
    }
    ll ans = upper_bound(all(s), k) - s.begin() - 1;
    ll sum = 0;
    rep(i, n){
        sum += a[i];
        if(k - sum < 0) break;
        chmax(ans, (ll)(i + 1 + upper_bound(all(s), k - sum) - s.begin() - 1));
    }
    print(ans);


}



Measured memory_bytes: 7896
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int  main()
{
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll>red;
    vector<ll>gre;
    vector<ll>ans;
    while(a--)
    {
       ll k; cin>>k;
       red.push_back(k);
    }
    sort(red.rbegin(),red.rend());
    while(b--)
    {
        ll q; cin>>q;
        gre.push_back(q);
    }
    sort(gre.rbegin(),gre.rend());
    while(c--)
    {
        ll w; cin>>w;
        ans.push_back(w);
    }
    //cout<<red[0]<<endl;
    ll s=0;
     for(ll i=0;i<x;i++) ans.push_back(red[i]);
     for(ll i=0;i<y;i++) ans.push_back(gre[i]);
      sort(ans.rbegin(),ans.rend());
     for(ll i=0;i<x+y;i++)
        s+=ans[i];

     cout<<s<<"\n";

return 0;
}


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

int N, A, B;
int P[100], cnt[3] = {};

int main(){
  cin >> N;
  cin >> A >> B;
  for(int i = 0; i < N; i++){
    cin >> P[i];
    if(P[i] <= A){
      cnt[0]++;
    }else if(P[i] <= B){
      cnt[1]++;
    }else{
      cnt[2]++;
    }
  }
  cout << min(cnt[0], min(cnt[1], cnt[2])) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MOD 1000000007

typedef long long ll;

ll fct[1333333] = { 1, 1 }, inv[1333333] = { 1, 1 }, fiv[1333333] = { 1, 1 };

ll combination(ll n, ll r)
{
	return fct[n] * fiv[r] % MOD * fiv[n - r] % MOD;
}

int main(void)
{
	ll X, Y, i;

	scanf("%lld %lld" ,&X, &Y);

	if ((X + Y) % 3)
	{
		puts("0");
		return 0;
	}

	ll x = (2 * Y - X) / 3, y = (2 * X - Y) / 3;

	if (x < 0 || y < 0)
	{
		puts("0");
		return 0;
	}

	for (i = 2; i <= x + y; i++)
	{
		fct[i] = fct[i - 1] * i % MOD;
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		fiv[i] = fiv[i - 1] * inv[i] % MOD;
	}

    printf("%lld" ,combination(x + y, x));
    return 0;
}

Measured memory_bytes: 15744
using System;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = new long[5000];
            var totals = new long[5000];
            while(true)
            {
                var n = long.Parse(Console.ReadLine());
                if (n == 0) break;
                long last = 0;
                long max = long.MinValue;
                for(int i = 0; i < n; i++)
                {
                    nums[i] = long.Parse(Console.ReadLine());
                    max = Math.Max(max, nums[i]);
                    totals[i] = last = nums[i] + last;
                }

                for(int i = 0; i < n - 1; i++)
                    for(int j = i + 1; j < n; j++)
                    {
                        max = Math.Max(totals[j] - totals[i] + nums[i], max);
                    }
                Console.WriteLine(max);
            }
        }
    }
}

Measured memory_bytes: 5780
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
map<string, ll> mp;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }

  ll ans = 0;
  for(auto x: mp) {
    ll xx = x.second - 1;
    ans += ((xx * xx + xx) / 2);
  }

  cout << ans << endl;
}


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

 
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
 int n;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++){
     cin>>a[i];
 }int sum =0 ;
 for(int i=1;i<n;i++){
    if(a[i] < a[i-1] ){
        int d = a[i-1]-a[i];
        sum += d;
        a[i] += d;
    }
 }
 cout<<sum;
}

Measured memory_bytes: 5216
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] h = new long[n];
        for (int i= 0; i<n;i++) {
            h[i] = sc.nextLong();
        }
        Arrays.sort(h);
        long ans = 0;
        for (int i=0;i<n-k;i++) {
            ans+=h[i];
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 83564
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD=1e9+7;
//Variables End


void solve(){
	int a,b,k;cin>>k>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			cout<<"OK";
			return;
		}
	}
	cout<<"NG";
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    for(int i=1;i<=ti;i++)
    {
		solve();        
    }
    return 0;
        
}


Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
			int A = vs[0];
			int B = vs[1];

			if (A >= 13) {
				Console.WriteLine(B);
			} else if (12 >= A && A >= 6) {
				Console.WriteLine(B / 2);
			} else {
				Console.WriteLine(0);
			}
		}
	}
}


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

long long N;
vector<long long> tree[100005];

long long grundy(long long pa, long long cur){
	long long ret = 0;
	for(long long i = 0; i < tree[cur].size(); i++){
		if(tree[cur][i] != pa){
			ret = ret ^ grundy(cur, tree[cur][i]);
		}
	}
	if(cur == 0){
		//cout << "cur = " << cur << " ret = " << 0 << endl;
		return ret;
	}
	if(tree[cur].size() == 1){
		//cout << "cur = " << cur << " ret = " << 1 << endl;
		return 1;
	}
	return ret + 1;
}



int main(){
	cin >> N;
	for(long long i = 0; i < N - 1; i++){
		long long x, y;
		cin >> x >> y;
		x--;y--;
		tree[x].push_back(y);
		tree[y].push_back(x);
	}

	if(grundy(-1, 0) == 0){
		cout << "Bob" << endl;
	}else{
		cout << "Alice" << endl;
	}
}


Measured memory_bytes: 11904
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        int[] i = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        if(i[2]-i[1] == i[1] - i[0])Console.WriteLine("YES");
        else Console.WriteLine("NO");
        }
}


Measured memory_bytes: 13268
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    int N;
    int[] A;

    AtCoder(FastScanner sc) {
        N = sc.nextInt();
        A = IntStream.range(0, N).map(i -> sc.nextInt()).sorted().toArray();
    }

    void solve(PrintWriter out) {
        out.println(A[N - 1] - A[0]);
    }

}

class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 29140
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int n;
int A[40001],B[40001];

int check(int k,set<P> S){
  int win=0;
  for(int i=n-k-1;i<n;i++){
    set<P>::iterator it=S.upper_bound(P(B[i],-1));
    if(it==S.end())it--;
    if(it->second<k)continue;
    win++;
    S.erase(it);
  }
  return win>k/2;
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++) cin>>A[i];
    for(int i=0;i<n;i++) cin>>B[i];
    sort(A,A+n,greater<int>());
    sort(B,B+n,greater<int>());
    int ans=0,idx=0,win=0;
    for(int i=0;i<n;i++){
      if(B[idx]>=A[i])idx++;
      else if(B[idx]<A[i])win++;
      ans=i+1;
      if((i+1)/2<win)break;
    }
    if(ans<n)cout<<ans<<endl;
    else cout<<"NA"<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 3392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll power(ll a, ll b) {
	return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1;
}
int main() {
	ll n, k;
	cin >> n >> k;
	ll dp[k + 1], ans = 0;
	for (ll i = k; i >= 1; i--) {
		dp[i] = power(k / i, n);
		for (ll j = 2 * i; j <= k; j += i)dp[i] -= dp[j];
		ans = (ans + i * dp[i] % mod) % mod;
	}
	cout << (ans + mod) % mod;
	return 0;
}

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

int func(int x) {
    int cnt = 0;
    while (x%2==0) {
        cnt++;
        x/=2;
    }
    return cnt;
}

int main() {
    int N; cin >> N;
    int ans = 0;
    rep(i, N){
        int x;
        cin >> x;
        ans += func(x);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *	
from heapq import *
from math import *
from itertools import permutations 
 
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
 
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:	
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
def li():
	return [int(x) for x in input().split()]
def fli():
	return [float(x) for x in input().split()]	
def gi():	
	return [x for x in input().split()]
def fi():
	return int(input())
def si():
	return list(input().rstrip())	
def mi():
	return 	map(int,input().split())	
def gh():
	sys.stdout.flush()
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)
def bo(i):
	return ord(i)-ord('a')
		


tt=1



while tt>0:
	tt-=1
	n=fi()
	a=fli()
	dp=[[0 for i in range(n+1)] for j in range(n+1)]
	for i in range(n):
		if i==0:
			dp[i][0]=1-a[i]
			dp[i][1]=a[i]
		else:
			for j in range(0,n+1):
				dp[i][j]=dp[i-1][j]*(1-a[i])+(dp[i-1][j-1]*a[i] if j>0 else 0)
	ans=0			
	for i in range(n+1):
		if i>n-i:
			ans+=dp[n-1][i]
	print(ans)					


Measured memory_bytes: 229136
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int main() {
    int ans = 0;
    string w, t;
    cin >> w;
    while(true) {
        cin >> t;
        if(t == "END_OF_TEXT") break;
        for(int i = 0; i < t.size(); ++i) {
            if('A' <= t[i] && t[i] <= 'Z') {
                t[i] = (char)(t[i] - 'A' + 'a');
            }
        }
        if(t == w) ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=3e5 + 5;
const int M=1e5 + 5;


int main()
{
	ios_base::sync_with_stdio(false);
	int i,n,a,b,ans[N];
	vector < pair < int , int > > v;
	cin>>n>>a>>b;
	if(b>n || a>n){
		cout<<-1<<endl;
		return 0;
	}
	int prt=n/b;
	if(n%b !=0) prt++;
	if(a<prt || a>n-b+1){
		cout<<-1<<endl;
		return 0;	
	}

	for(i=0;i<n;i+=b){
		if(i+b-1<=n-1){
			v.pb(mkp(i,i+b-1));
		}
		else{
			v.pb(mkp(i,n-1));
		}
	}
	for(i=0;i<v.size();i++){
		int foo=v[i].se+1;
		for(int j=v[i].fi;j<=v[i].se;j++){
			ans[j]=foo;
			foo--;
		}
	}
	int rem=a-prt;
	for(i=1;i<v.size();i++){
		int l=v[i].fi;
		int r=v[i].se;
		r=min(r,l+rem);
		reverse(ans+l,ans+r+1);
		rem-=r-l;
	}
	for(i=0;i<n;i++) cout<<ans[i]<<" ";
	cout<<endl;	

		
	
		
	return 0;
}

Measured memory_bytes: 6892
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <fstream>

using namespace std;

int main(void)
{
	vector <int> a;
	int temp;
	int H, W;
	int n;
	int grid[100][100];

	cin >> H >> W;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		a.push_back(temp);
	}

	int index = 0;
	for (int i = 0; i < H; i++)
	{
		if (i % 2 == 0)
		{
			for (int j = 0; j < W; j++)
			{
				grid[i][j] = index + 1;
				a[index]--;
				if (a[index] == 0)
				{
					index++;
				}
			}
		}
		else
		{
			for (int j = W - 1; j >= 0; j--)
			{
				grid[i][j] = index + 1;
				a[index]--;
				if (a[index] == 0)
				{
					index++;
				}
			}
		}
	}

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n, m;
   cin>>n>>m;
   int arr[n+1];
   memset(arr, -1, sizeof(arr));
   int flag = 0;
   for(int i = 0; i<m ; i++){
       int index , val;
       cin>>index>>val;
       if(arr[index] != -1 && arr[index] != val){
           flag = 1;
       }
       else{
           arr[index] = val;
       }
   }
   if(flag)cout<<-1<<endl;
   else{
       string s = "";
       if(n == 1){
           if(arr[1] == -1){
               cout<<0<<endl;
           }
           else cout<<arr[1]<<endl;
       }
       else{
           if(arr[1] == -1){
               s += '1';
           }
           else s+= '0'  + arr[1];
       
       for(int i = 2; i<=n; i++){
           if(arr[i] == -1){
               s += '0';
           }
           else{
               s += '0' + arr[i];
           }
       }
       if(arr[1] == 0)cout<<-1<<endl;
       else
       cout<<s<<endl;
           
       }
   }
  
}

Measured memory_bytes: 256
//p1t3
//P1T2
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4;
int raw[maxn];
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	char pre = s[0];
	int ans = 1;
	for(int i = 1;i < s.size();i++){
		if(s[i] != pre){
			ans++;
			pre = s[i];
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include<vector>
#include<iostream>
#include<string>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<cmath>
#include<algorithm>
#include<numeric>
#define LONG long long int
using namespace std;

int main() {
	int n;
	int k;
	string s;

	cin >> n;
	cin >> k;
	cin >> s;
	for (int i = 0; i < n; i++)
	{
		if (i == k-1)
		{
			s[i] = tolower(s[i]);
		}
		
		cout << s[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cmath>
#include <algorithm>
using namespace std;
typedef complex<double> C;
#define EPS (1e-6)

int n;
C c[301];

void solve() {
  for(int i=0;i<n;i++)
  cin>>c[i].real()>>c[i].imag();
  
  int res = 1;
  for (int i = 0; i < n; i += 1) {
    for (int j = i+1; j < n; j += 1) {
      C v = c[j] - c[i];
      double absv = abs(v);
      if (absv > 2.0 + EPS) continue;
      // _
      C m = c[i] + (v / 2.0);
      // ~ÜÅÌ£
      double dist = sqrt(1.0 - absv * absv / 4.0);
      // PÊ@üxNg
      C unv  = (v * C(0, 1)) / absv;
      // S
      C nv = unv * dist;
      for (int k = 0; k < 2; k += 1) {          
        int cnt = 0;
        nv *= -1;
        C tc = m + nv;
        for (int l = 0; l < n; l += 1) {
          if (abs(tc - c[l]) < 1.0 + EPS) cnt++;
        }
        res = max(res, cnt);
      }
    }
  }
  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>n, n) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 984
/* Coached by rainboy */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 100000

int compare_c(const void *a, const void *b) {
	char ca = *(char *) a;
	char cb = *(char *) b;

	return ca - cb;
}

int compare_s(const void *a, const void *b) {
	char *s = *(char **) a;
	char *t = *(char **) b;

	return strcmp(s, t);
}

int main() {
	static char *ss[N], s[16];
	int n, i, k;
	long long ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", s);
		qsort(s, 10, sizeof *s, compare_c);
		ss[i] = strdup(s);
	}
	qsort(ss, n, sizeof *ss, compare_s);
	ans = 0;
	k = 1;
	for (i = 1; i <= n; i++)
		if (i < n && strcmp(ss[i - 1], ss[i]) == 0)
			k++;
		else {
			ans += (long long) k * (k - 1) / 2;
			k = 1;
		}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4860
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main() {
  ll n,k;
  cin>>n>>k;
  vector<ll> p(n);

  ll pl=0;
  ll mi=0;
  ll zr=0;
  rep(i,n){
    cin>>p[i];
    if(p[i]>0) pl++;
    if(p[i]==0) zr++;
    if(p[i]<0) mi++;
  }

  if(pl*mi<k && k<=pl*mi+pl*zr+mi*zr+zr*(zr-1)/2) {
    cout << 0 << endl;
    return 0;
  }

  sort(all(p));

//————————————————二分探索——————————————————————————
//小さい方からk番目の数x ＝ x以下の数がk個以上あるような最小の数

if(k<=pl*mi){
  ll mid;

  ll ng = -1000000000000000001;
  ll ok = 0;
  while (abs(ok - ng) > 1) {
    mid = (ng + ok) / 2;

    ll cnt=0;
    rep(i,mi){
      auto x = lb(all(p),(mid+p[i]+1)/p[i]);
      int z=x-p.begin();
      if(0<=z && z<n){
        cnt+=n-z;
      }
    }
    (cnt>=k? ok : ng) = mid;
  }

  cout << ok << endl;
  return 0;
}


//————————————————二分探索——————————————————————————
//小さい方からk番目の数x ＝ x以下の数がk個以上あるような最小の数

if(k>pl*mi+pl*zr+mi*zr+zr*(zr-1)/2){
  ll mid;

  ll ng = 0;
  ll ok = 1000000000000000000;
  vector<ll> q(mi);
  vector<ll> r(pl);
  rep(i,mi){
    q[i]=p[i];
  }
  rep(i,pl){
    r[i]=p[mi+zr+i];
  }

  while (abs(ok - ng) > 1) {
    mid = (ng + ok) / 2;
    
    ll cnt=0;
    rep(i,mi){
      auto x = lb(all(q),mid/q[i]);
      int z=x-q.begin();
      if(0<=z && z<mi) cnt+=mi-z;
      if(q[i]*q[i]<=mid) cnt--;
    }
    
    rep(i,pl){
      auto x = ub(all(r),mid/r[i]);
      int z=x-r.begin();
      if(0<=z && z<pl) cnt+=z;
      else cnt+=pl;
      if(r[i]*r[i]<=mid) cnt--;
    }

    if(cnt/2+pl*mi+pl*zr+mi*zr+zr*(zr-1)/2>=k) ok = mid;
    else ng=mid;
  }

  cout << ok << endl;
  return 0;
}




}


Measured memory_bytes: 3200
s = input()

if s[0] != "A":
    print("WA")
    exit()
count = 0
for i in range(2, len(s)-1):
    if s[i] == "C":
        count += 1
if count != 1:
    print("WA")
    exit()
if ord("z") < ord(s[1]) or ord(s[1]) < ord("a"):
    print("WA")
    exit()
if ord("z") < ord(s[-1]) or ord(s[-1]) < ord("a"):
    print("WA")
    exit()
print("AC")

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main() {
	int k;
	cin >> k;
	string s;
	cin >> s;
	
	if (s.size() <= k) cout << s << '\n';
	else {
		cout << s.substr(0, k) + "...";
		if (s.size() > 2 * k) cout << s.substr(2 * k + 1);
		cout << '\n';
	}
	
	return 0;
} 

Measured memory_bytes: 3632
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>

using namespace std;

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

const double eps = 1e-6;
const ll MOD = 1000000007;
const ll INF = 1e15;

int main() {
	ll N;
	cin >> N;
	vector<ll> A(1LL << N);
	for (int i = 0;i < A.size();i++) {
		cin >> A[i];
	}
	vector<P> dp(1LL << N, P(-1, -1));
	dp[0] = P(0, -1);
	ll beforea = 0;
	ll beforeb = 1;
	for (ll now = 1;now < 1LL << N;now++) {
		vector<P> cand;
		cand.push_back(P(A[now], now));
		for (ll k = 0;k < N;k++) {
			ll see = 1LL << k;
			if ((now & see) != 0) {
				ll from = now ^ see;
				if (dp[from].first != -1)
					cand.push_back(P(A[dp[from].first], dp[from].first));
				if (dp[from].second != -1)
					cand.push_back(P(A[dp[from].second], dp[from].second));
			}
		}
		sort(cand.begin(), cand.end());
		cand.erase(unique(cand.begin(), cand.end()), cand.end());
		ll i1 = cand[(ll)cand.size() - 1].second;
		ll i2 = cand[(ll)cand.size() - 2].second;
		ll nowans = A[i2] + A[i1];
		dp[now] = P(i1, i2);
		if (nowans < A[beforea] + A[beforeb]) {
			i1 = beforea;
			i2 = beforeb;
		}
		else {
			beforea = i1;
			beforeb = i2;
		}
		cout << A[i2] + A[i1] << endl;
	}
	return 0;
}


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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto X = RD;
	auto L = RDR.ARR;

	long ans = 1, a;
	foreach (i; 0..N)
	{
		a += L[i];
		if (a <= X)
		{
			++ans;
		}
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

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

using namespace std;

int main() {
	int n, m;
	scanf("%d %d", &n, &m);

	map<int, int> cnt;
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		cnt[x]++;
	}

	for(int i = 0; i < m; i++) {
		int b, c;
		scanf("%d %d", &b, &c);
		while(cnt.begin()->first < c and b > 0) {
			int tmp = min(cnt.begin()->second, b);
			cnt[c] += tmp;
			cnt.begin()->second -= tmp;
			b -= tmp;
			if(!cnt.begin()->second) {
				cnt.erase(cnt.begin());
			}
		}
	}
	long long ans = 0;
	for(auto p : cnt) ans += 1LL * p.first * p.second;

	printf("%lld\n", ans);
}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        int ans=(N-1)/2;
        Console.WriteLine(ans);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long a[1001][4];
int main() {
    int n,m,i,j,k;
    scanf("%d%d",&n,&m);
    for (i = 0;i < n;i ++) {
        for (j = 0;j < 3;j ++)
            cin>>a[i][j];
    }
    long long ans = -1;
    for (i = 0;i < 8;i ++) {
        long long f[100010];
        for (j = 0;j < n;j ++) {
            long long sum = 0;
            for (k = 0;k < 3;k ++) {
                if(i >> k & 1)sum += a[j][k];
                else sum -= a[j][k];
            }
            f[j] = sum;
        }
        sort(f,f + n);
        long long s = 0;
        for (j = 1;j <= m;j ++)s += f[n - j];
        ans = max(s,ans);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
use num_bigint::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: isize = std::isize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn solve(
    n: isize,
    a: &BigInt,
    b: &BigInt,
    c: &BigInt,
    d: &BigInt,
    cache: &mut HashMap<isize, BigInt>,
) -> BigInt {
    if let Some(x) = cache.get(&n) {
        x.clone()
    } else {
        // eprintln!("{}", n);
        let k = 4;
        let m0 = max(0, n - k);
        let m1 = n + k;
        let mut x = n * d;
        for m in m0..=m1 {
            if m % 2 == 0 && m / 2 < n {
                x = min(x, (n - m).abs() * d + a + solve(m / 2, a, b, c, d, cache));
            }
            if m % 3 == 0 && m / 3 < n {
                x = min(x, (n - m).abs() * d + b + solve(m / 3, a, b, c, d, cache));
            }
            if m % 5 == 0 && m / 5 < n {
                x = min(x, (n - m).abs() * d + c + solve(m / 5, a, b, c, d, cache));
            }
        }
        cache.insert(n, x);
        cache[&n].clone()
    }
}

fn main() {
    input! {
        t: usize,
        nabcd: [(isize, isize, isize, isize, isize); t],
    }
    for &(n, a, b, c, d) in &nabcd {
        let mut cache = HashMap::new();
        cache.insert(0, 0.to_bigint().unwrap());
        let result = solve(
            n,
            &a.to_bigint().unwrap(),
            &b.to_bigint().unwrap(),
            &c.to_bigint().unwrap(),
            &d.to_bigint().unwrap(),
            &mut cache,
        );
        // eprintln!("{:?}", cache);
        println!("{}", result);
    }
}


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

int dp[101][4][2];

int main() {
    string S;
    cin >> S;
    int K;
    cin >> K;

    int n = (int)S.size();

    dp[0][0][0] = 1;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 2; k++) {
                int digit = S[i] - '0';
                for (int d = 0; d <= 9; d++) {
                    int ni = i + 1, nj = j, nk = k;
                    if (d != 0) nj++;
                    if (nj > K) continue;
                    if (k == 0) {
                        if (d > digit) continue;
                        if (d < digit) nk = 1;
                    }
                    dp[ni][nj][nk] += dp[i][j][k];
                }
            }
        }
    }

    int res = dp[n][K][0] + dp[n][K][1];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
    int N, Q;
    scanf("%d%d", &N, &Q);
    char S[N+1];
    scanf("%s", S);
    int t[N+1];
    t[1]=0;
    for(int i=0; i<N; i++){
        if(S[i]=='A' && S[i+1]=='C'){
            t[i+1]=t[i]+1;
        }else{
            t[i+1]=t[i];
        }
    }
    int l[Q], r[Q];
    for(int i=0; i < Q; i++){
        scanf("%d%d", &l[i], &r[i]);
    }
    for(int i=0; i< Q; i++){
        printf("%d\n", t[r[i]-1]-t[l[i]-1]);
    }
    return 0;
}

Measured memory_bytes: 2048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class A
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int[] A = GetInts(3);
		WriteLine(A.Sum() >= 22 ? "bust" : "win");
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n,k,c=0,d=0;
  string s;
  char h;
  cin>>n>>k>>s;k*=2;
  for(int i=0;i<n;i++){
    if(i==0)h=s[i];
    else{
      if(h==s[i])c++;
      else{h=s[i];
        if(d<k){
          d++;c++;
        }
      }
    }
  }
  cout<<c;
}

Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		B_Reversi solver = new B_Reversi();
		solver.solve(1, in, out);
		out.close();
	}

	static class B_Reversi {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			final int MOD = (int) (1e9 + 7);
			int n = in.nextInt();
			int[] a = new int[n];
			int max = 0;
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
				max = Math.max(max, a[i]);
			}
			int[] prev = new int[max + 1];
			int[] d = new int[n + 1];
			d[0] = 1;
			for (int i = 1; i <= n; i++) {
				int x = a[i - 1];
				d[i] = d[i - 1];
				if (prev[x] > 0 && prev[x] + 1 != i) {
					d[i] += d[prev[x]];
					if (d[i] >= MOD) {
						d[i] -= MOD;
					}
				}
				prev[x] = i;
			}
			out.println(d[n]);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

	}
}



Measured memory_bytes: 46748
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.replace(/\n$/,"")).split("\n");
while(true){
   var nt=(Arr.shift()).split(" ");
   var str=nt[0];
   var type=nt[1];
   if(type=="X")break;
   str=str.replace(/^./,function(s){
      return s.toLowerCase();
   });
   str=str.replace(/[A-Z]/g,function(s){
      return "_"+s;
   });
   var arr=str.split("_");
   for(var i=1;i<arr.length;i++){
      arr[i]=arr[i].replace(/./,function(s){
         return s.toUpperCase();
      });
   }
   if(type=="U"){
      arr[0]=arr[0].replace(/^./,function(s){
         return s.toUpperCase();
      });
      console.log(arr.join(""));
   }
   if(type=="L")console.log(arr.join(""));
   if(type=="D")console.log(arr.join("_").toLowerCase());
}

Measured memory_bytes: 8684
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define rev(s) (string((s).rbegin(), (s).rend()))
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

int main() {
    int n;cin>>n;
    vector<int> b(n-1);
    rep(i,n-1) cin>>b[i];
    b.push_back(b[n-2]);
    vector<int> a(n);

    rep(i,n) {
        if (i==0) {
            a[i]=b[i];
        }
        else {
            a[i]=min(b[i-1],b[i]);
        }
    }
    ll ans = 0;
    rep(i,n) {
        ans+=a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] min = new int[n+1];
      	min[0] = Integer.MAX_VALUE;
        for (int i =0;i<n; i++) {
            p[i] = sc.nextInt();
            if (i > 0) min[i] = Math.min(min[i-1], p[i-1]);
        }

        int ans = 1;
        for (int i = 1;i < n; i ++) {
            if (min[i] > p[i]) ans++;
        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 90952
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100;
int a[N],n,m,q,ans,x[N],y[N],z[N],d[N];
void getmax()
{
	int sum=0;
	for(int i=0;i<q;i++)
		if(a[y[i]]-a[x[i]]==z[i])
			sum+=d[i];
	ans=max(ans,sum);
}
void dfs(int now)
{
	if(now==n+1)
	{
		getmax();
		return;
	}
	for(int i=a[now-1];i<=m;i++)
	{
		a[now]=i;
		dfs(now+1);
	}
}
int main()
{
	a[0]=1;
	cin>>n>>m>>q;
	for(int i=0;i<q;i++)
	{
		cin>>x[i]>>y[i]>>z[i]>>d[i];
	}
	dfs(1);
	cout<<ans<<"\n";
}

Measured memory_bytes: 3592
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <map>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  
  if(k % 2 == 1) cout << b - a << endl;
  else			 cout << a - b << endl;


return 0;
}

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

long long mod(long long a, long long m) {
	a %= m;
	return a >= 0 ? a : a+m;
}

int main() {
	long long n, m;
	cin >> n >> m;
	vector<long long> s(n+1, 0);
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
		s[i] = mod(s[i] + s[i-1], m);
	}
	map<long long, long long> mp;
	long long ans = 0;
	for (int i = 0; i <= n; i++) {
		ans += mp[s[i]];
		mp[s[i]]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7528
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int N,A,B,C;
vl l(8);

int dfs(int k,int a,int b,int c){
  if(k == N){
    if(a*b*c == 0) return 1e8;
    else return abs(A-a)+abs(B-b)+abs(C-c) - 30;
  }
  int r0 = dfs(k+1,a,b,c);
  int r1 = dfs(k+1,a+l[k],b,c) + 10;
  int r2 = dfs(k+1,a,b+l[k],c) + 10;
  int r3 = dfs(k+1,a,b,c+l[k]) + 10;
  return min(min(r0,r1),min(r2,r3));
}

int main(){
  cin >> N >> A >> B >> C;
  rep(i,N) cin >> l.at(i);
  cout << dfs(0,0,0,0) << endl;
}

Measured memory_bytes: 256
import sys

h = int(sys.stdin.readline().rstrip())

def main():
    x = h
    cnt = 0
    while x > 1:
        x //= 2
        cnt += 1
    res = 0
    for i in range(cnt+1):
        res += 2 ** i
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define int long long
#define ll long long
#define moder 1000000007
#define INF LLONG_MAX/3
#define P std::pair<int,int>
using namespace std;

int n;
bool f[110][5][2];
int p[110][11];
int c[110];
signed main(){
	cin>>n;
	rep(i,n){
		rep(j,5){
			rep(k,2)cin>>f[i][j][k];
		}
	}
	rep(i,n){
		rep(j,11)cin>>p[i][j];
	}
	int ans=-INF;
	for(int i=0;i<(1<<5);i++){
		for(int j=0;j<(1<<5);j++){
			if(!i&&!j)continue;
			rep(k,n)c[k]=0;
			rep(k,5){
				if((i>>k)&1){
					rep(l,n){
						if(f[l][k][0])c[l]++;
					}
				}
			}
			rep(k,5){
				if((j>>k)&1){
					rep(l,n){
						if(f[l][k][1])c[l]++;
					}
				}
			}
			int cnt=0;
			rep(k,n){
				cnt+=p[k][c[k]];
			}
			ans=max(ans,cnt);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    int a, b;
    cin >> a >> b;
    int c = min(a, b);
    int d = max(a, b);

    REP0 (i, d)
    {
        cout << c;
    }
    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256