akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define MOD 1e9+7
using namespace std;
#define  pp push_back
#define  po pop_back
#define  mp make_pair
#define clr(a) memset(a,0,sizeof(a))
#define neg(a) memset(a,-1,sizeof(a))
#define fas(a) memset(a,false,sizeof(a))
#define debug(x) cout<<#x<<": "<<x<<endl
#define debug1(x) cout<<#x<<": "<<x<<" "
#define rev(x) reverse(x.begin(), x.end())
#define int long long 
#define F first
#define S second
//int a[2000];
void printvector(std::vector<int> v){  for (int i = 0; i < v.size(); ++i){cout<<v[i]<<" ";}cout<<""<<endl;}
void printarray(int a[],int n){for (int i = 0; i < n; ++i){cout<<a[i]<<" ";}cout<<""<<endl;}
 
int L,n; 
int get(int x[],int y[])
{

   // printarray(x,n);
   // printarray(y,n);
   int px[n],py[n];
   for (int i = 0; i < n; ++i)
   {
       px[i]=2*x[i];
       if(i!=0)px[i]+=px[i-1];
   }
   for(int i=n-1;i>=0;i--)
   {
      py[i]=2*y[i];
      if(i!=n-1)py[i]+=py[i+1];
   }
   int fans=0;
   for(int i=0;i<n;i++)
   {
      int ans=0;
      int left=0,right=0;
      if(i+1>n-(i+1))
      {
        left=n-(i+1)+1;
        right=n-(i+1);
        
      }
      else
      {
          left=i+1;
          right=i+1;
      }
      ans+=px[i]-x[i];
      if(i-left>=0)ans-=px[i-left];
      if(right>0)
      {
         ans+=py[i+1];
         if(i+1+right<n)ans-=py[i+1+right];
      }

      fans=max(fans,ans);
   }
 
    //debug(fans);  
 
   return fans;


}
 

void  solve()
{
  cin>>L>>n;
  int x[n],y[n];
  for(int i=0;i<n;i++)cin>>x[i];
  for(int i=0;i<n;i++)y[i]=L-x[i];
 
  int ans1=get(x,y);
  for(int i=0;i<n;i++)swap(x[i],y[i]);
  for(int i=0;i<n/2;i++)
  { 
     swap(x[i],x[n-i-1]);
     swap(y[i],y[n-i-1]);
  }
  int ans2=get(x,y);

  cout<<max(ans1,ans2)<<endl; 


}




 int32_t main() 
{

  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
    
   solve();

return 0;

}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

template<typename T>
class BIT {
private:
  vector<T> bit;
  int n;
public:
  BIT(int _n) : n(_n) {
    bit = vector<T>(n+1, 0);
  }
  void add(int v, T a){ //0-indexed
    for(int x=v+1; x<=n; x += x&(-x)) bit[x] += a;
  }
  T sum(int v){ //0-indexed
    T ret=0;
    for(int x=v+1; x>0; x -= x&(-x)) ret += bit[x];
    return ret;
  }
  int lower_bound(T w){ //w以上となる最小のsumの位置(0-indexed)
    if(w<=0) return 0;
    int x=0, d=0;
    while(n > (1<<d)) d++;
    for(int k=(1<<(d-1)); k>0; k/=2){
      if(x+k<=n && bit[x+k]<w){
        w -= bit[x+k];
        x += k;
      }
    }
    return x;
  }
};

int main(){
  int n,m,q;
  cin>>n>>m>>q;

  vector<vector<int>> toDel(n);
  vector<vector<pair<int,int>>> query(n); // [l] -> <r, idx>

  BIT<int> bit(n);
  rep(i,m){
    int l,r;
    cin>>l>>r;
    l--;r--;
    bit.add(r, 1);
    toDel[l].pb(r);
  }

  rep(i,q){
    int l,r;
    cin>>l>>r;
    l--;r--;
    query[l].pb({r,i});
  }

  vector<int> ans(q);

  rep(i,n){
    for(auto &p : query[i]){
      ans[p.second] = bit.sum(p.first);
    }
    for(auto &r : toDel[i]){
      bit.add(r, -1);
    }
  }

  for(auto &a : ans) cout << a << "\n";

  return 0;
}


Measured memory_bytes: 3584
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = 1<<30;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> c(H);
    rep(i, H) cin >> c[i];
    // count '#'
    int cnt=0;
    rep(i, H) rep(j, W) if(c[i][j] == '#') cnt++;

    deque<vector<int>> q;
    q.push_back({0,0,1}); // x, y, dist
    c[0][0] = '#';
    int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
    int leng = INF;
    while (!q.empty()){
        vector<int> tmp = q.front(); q.pop_front();
        int x = tmp[0], y = tmp[1], dist = tmp[2];
        rep(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx == W-1 && ny == H-1){
                if(leng > dist + 1) leng = dist + 1;
            }else if(0 <= nx && nx < W && 0 <= ny && ny < H && c[ny][nx] == '.'){
                q.push_back({nx, ny, dist+1});
                c[ny][nx] = '#';
            }
        }
    }
    if(leng == INF) cout << -1 << endl;
    else cout << H*W-leng-cnt << endl;
    return 0;
}


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    if(a[0]+a[1]+a[2]>=22) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n,i,j,k;
  int m,f,r;

  scanf("%d",&m);
  scanf("%d",&f);
  scanf("%d",&r);
  while (!((m==-1) && (f==-1) && (r==-1))){
    if ((m==-1) || (f==-1)){
      printf("%c\n",'F');
    }else if (m+f>=80){
      printf("%c\n",'A');
    }else if(m+f>=65){
      printf("%c\n",'B');
    }else if(m+f>=50){
      printf("%c\n",'C');
    }else if(m+f>=30){
      if (r>=50){
        printf("%c\n",'C');
      }else{
        printf("%c\n",'D');
      }
    }else{
      printf("%c\n",'F');
    }
    scanf("%d",&m);
    scanf("%d",&f);
    scanf("%d",&r);
  }


  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jun 20 21:02:38 JST 2020
 **/

signed main() {
    Int x;
    std::cin >> x;
    Int g = std::gcd(x, 360);
    std::cout << 360 / g << std::endl;
}


Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(void){
   int x, i = 1; 
   while(1){
       cin >> x;
       
       if ( x == 0 ) break;
        cout << "Case " << i << ": " << x << endl; 
        i++; 
   }
}
//ITP1_3_B



Measured memory_bytes: 3088
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int m = sc.nextInt();

		pr.println(24 - m + 24);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int a[100];
long dp[2503][53];
int main(){
long n,x;
cin>>n>>x;
for(long i=1;i<=n;i++)cin>>a[i];
dp[0][0]=1;dp[a[1]][1]=1;
for(long i=2;i<=n;i++){
    for(long j=2500;j>=a[i];j--){
        for(long u=1;u<=i;u++){
            dp[j][u]+=dp[j-a[i]][u-1];
        }
    }
}
long long ans=0;
for(long i=1;i<=n;i++){
    for(long j=1;j<=2500;j++){long r=j/i;
        if(j%i==0&&r==x){ans=ans+dp[j][i];}
    }
}
cout<<ans<<endl;}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#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 rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra
    map< ll, ll > prime_factor(ll n) {
        map< ll, ll > ret;
        for(ll i = 2; i * i <= n; i++) {
            while(n % i == 0) {
                ret[i]++;
                n /= i;
            }
        }
        if(n != 1) ret[n] = 1;
        return ret;
    }

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        map<ll,ll> m;
        m=prime_factor(n);
        ll res=0;
        for(auto p:m){
            ll x=p.second;
            ll i=1;
            while(x>=i){
                x-=i;
                i++;
                res++;
            }
        }
        cout<<res<<endl;
    }

Measured memory_bytes: 3656
n,m = map(int,input().split())
s_c_list = []
for i in range(m):
  s_c_list.append(list(map(int,input().split())))
check = False
if n == 1:
  for i in range(10):
    con = 0
    list_i = list(str(i))
    ch_list = [0 for i in range(m)]
    for j in range(m):
      if int(list_i[s_c_list[j][0] - 1]) == s_c_list[j][1]:
        ch_list[j] = 1
    if sum(ch_list) == m:
      print(i)
      check = True
      break
else:
    
  for i in range(10**(n-1),10**n):
    con = 0
    list_i = list(str(i))
    ch_list = [0 for i in range(m)]
    for j in range(m):
      if int(list_i[s_c_list[j][0] - 1]) == s_c_list[j][1]:
        ch_list[j] = 1
    if sum(ch_list) == m:
      print(i)
      check = True
      break
if check == False:
  print(-1)
    




Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef vector<int> ivec;
typedef vector<string> svec;

const int MOD=1000000007;

int a[100010];
int main(){
	int n,m,q;
	int ans=0;
	int a[100],b[100],c[100],d[100];
	cin>>n>>m>>q;
	for(int i=0;i<q;i++)
	{
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--,b[i]--;
	}
	
	int comb=(1<<n)-1;
	while(comb<(1<<(m+n-1)))
	{
		vector<int> v;
		int sa=0;
		for(int j=0;j<m+n-1;j++)
		{
			if(comb & (1 << j))
			{
				v.push_back(j-sa);
				sa++;
			}
		}
		//cout<<comb<<endl;
		//if(v.size()==n)
		//{
			int sum=0;
			for(int k=0;k<q;k++)
			{
				if(v[b[k]]-v[a[k]]==c[k])sum+=d[k];
			}
			ans=max(ans,sum);
		//}
		int x=comb & -comb,y=comb+x;
		comb=((comb & ~y)/x>>1)|y;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3592
import sys


def input(): return sys.stdin.readline().strip()


def main():
    def get_binary(num, digit): return bin(num)[2:].zfill(digit)

    def count_blacks(mat, bin_str_h, bin_str_w):
        count = 0
        for h_i, row in enumerate(mat):
            if (bin_str_h[h_i] == "0"):
                continue
            for w_i, cell in enumerate(row):
                if (bin_str_w[w_i] == "1" and cell == "#"):
                    count += 1

        return count

    H, W, K = map(int, input().split())
    mat = [list(input()) for _ in range(H)]
    ans_count = 0

    for h in range(2**H):
        for w in range(2**W):
            h_bin = get_binary(h, H)
            w_bin = get_binary(w, W)
            if (count_blacks(mat, h_bin, w_bin) == K):
                ans_count += 1

    print(ans_count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9232
from itertools import permutations
from math import factorial

def dist(x1, y1, x2, y2):
    return ((x2-x1)**2 + (y2-y1)**2)**(1/2)


N = int(input())
xy = []
for _ in range(N):
    x, y = map(int, input().split())
    xy.append((x, y))
adj = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
    for j in range(N):
        adj[i][j] = dist(xy[i][0], xy[i][1], xy[j][0], xy[j][1])

ans = 0
for v_list in permutations(list(range(N))):
    for i in range(N-1):
        ans += adj[v_list[i]][v_list[i+1]]

print(ans / factorial(N))


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

using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  int sum = 0;
  for(int i=0; i<n; ++i){
    int xi;
    cin >> xi;
    sum += min(xi*2, abs(xi-k)*2);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import sys

def minimumCostSort(A):
    B = sorted(A)
    V = [False] * len(A)
    T = [0] * 10001
    ans = 0
    s = min(A)

    for i in range(len(A)):
        T[B[i]] = i

    for i in range(len(A)):
        if V[i]:
            continue
        S = an = 0
        j = i
        m = 10000
        while True:
            V[j] = True
            an += 1
            v = A[j]
            m = min(m, v)
            S += v
            j = T[v]
            if V[j]:
                break
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s)
    return ans

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    A = map(int, lines[1].split())
    print minimumCostSort(A)

Measured memory_bytes: 6580
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(n, a);
    }
    static void getAns(int n, int[] a)
    {
        var min = int.MaxValue;
        var ans = -1;
        for (int i = 0; i < n; i++)
            if (a[i] < min) { ans = i; min = a[i]; }
        Console.WriteLine(ans + 1);
    }
}



Measured memory_bytes: 16692
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

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

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (n - i - j >= 0 && y - i * 10000 - j * 5000 == (n - i - j) * 1000) {
        printf("%d %d %d\n", i, j, n - i - j);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
ll mod=1e9 +7;
int main(){
	
	int n,x;
	cin >> n;
	int a[n];
	bool answer=true;
	FOR(i,n) a[i]=0;
	FOR(i,n){
		cin >> x;
		if(x < n) a[x]++;
	}
	for(int i=n-1;i >0;i-=2){
		if(a[i]!=2){ 
			answer=false;
			break;
		}
	}
	if(n%2==1 && a[0]!=1) answer=false;
	ll q=1;
	int i=0;
	if(!answer) cout << 0;
	while(i<n/2){
		q*=2;
		q%=mod;
		i++;
	}
	if(answer) cout << q;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
        int b = sc.nextInt();
		
      	if(a <= b){
          System.out.println(a);
        }else{
          System.out.println(a-1);
        }
 
      	
 
    }
}

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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}


int main() {
    int s, w;
    cin >> s >> w;
    if (s <= w) {
        cout << "unsafe" << endl;
    }else {
        cout << "safe" << endl;
    }
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

typedef long long ll;
using namespace std;

int main() {
  int n,ans = 1000;
  cin >> n;

  int a[n];
  rep(i,0,n){
    cin >> a[i];
  }

  rep(i,0,n){
    int count = 0;
    for(;a[i]%2 == 0;){
      a[i] /= 2;
      count++;
    }
    ans = min(ans,count);
  }
  pout(ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b, c;
    int flag = 0;
    scanf("%d", &a);
    for(c = 1; c <= 9; c++){
        for(b = 1; b <= 9; b++){
            if(a == b * c){
                flag = 1;
                // printf("あった");
            }
            // printf("%2d ", b * c);
        }
        // printf("\n", c);
    }    
    if(flag == 1){
        printf("Yes");
    }else{
        printf("No");
    }
    
    
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
  string keys[] = {
    "",
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz",
  };
  int n;
  string s;
  int kind;
  int cur;

  cin >> n;
  for( int lp=0;lp<n;lp++ ){
    cin >> s;

    //    cout << "s=" << s << endl;
    cur=-1;
    for( unsigned int i=0;i<s.length();i++ ){
      //      cout<<"s[i]="<<s[i]<<" cur="<<cur<<" kind="<<kind<<endl;

      if( s[i]=='0' ){
	if( cur>=0 ){
	  cout << keys[ kind][cur%keys[kind].length() ] ;
	  cur=-1;
	}
      }else{
	if( cur<0 ){
	  kind = s[i] - '0';
	  cur=0;
	}else
	  cur++;
      }
    }
    cout << endl;

    //    break;
  }

  return 0;
}

Measured memory_bytes: 0
from collections import deque,Counter

N = int(input())
lisB = list(map(int,input().split()))

ans = deque()
while len(lisB) > 0:
    for i in range(len(lisB)-1,-1,-1):
        if lisB[i]-1 == i:
            ans.appendleft(lisB.pop(i))
            break
    else:
        print(-1)
        exit()

print(*ans)


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cstring>
#include <vector>




int main()
{
	long long h, w, n;

	std::cin >> h >> w >> n;

	std::vector<long long> v(n);

	for (size_t i = 0; i < v.size(); i++) {
		std::cin >> v[i];
	}

	long long pos = 0;
	std::vector<std::vector<long long> > maze(h, std::vector<long long>(w, 0));
	for (size_t i = 0; i < h; i++) {
		if (i % 2 == 0) {
			for (size_t j = 0; j < w; j++) {
				maze[i][j] = pos + 1;
				v[pos]--;
				if (v[pos] == 0) {
					pos++;
				}
			}
		} else {
			for (int j = w - 1; j >= 0; j--) {
				maze[i][j] = pos + 1;
				v[pos]--;
				if (v[pos] == 0) {
					pos++;
				}
			}
		}
	}

	for (size_t i = 0; i < h; i++) {
		for (size_t j = 0; j < w; j++) {
			std::cout << maze[i][j];
			if (j != w - 1) {
				std::cout << " ";
			}
		}
		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
const int MAX_C = 2010;
long long Com[MAX_C][MAX_C] = {0};

int main(){
  int N; cin >> N; int a[N]; int cnt = 1;
  rep(i, N){
    cin >> a[i];
    if(a[i]==cnt) cnt++; 
  }
  if(cnt==1) cout << -1 << endl;
  else cout << N-cnt+1 << endl;
}

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

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

  bool fourtype = false;
  char color;

  for (int i = 0; i < N; i++){
    cin >> color;
    if (color == 'Y'){
      fourtype = true;
    }
  }

  if (fourtype){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}


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

int n, a[2], p, L;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> L;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i & 1];
		if(a[1] + a[0] >= L) p = i - 1;
	}
	if(!p) return cout << "Impossible", 0;
	cout << "Possible\n";		
	for(int i = 1; i < p; ++i) cout << i << '\n';
	for(int i = n - 1; i > p; --i) cout << i << '\n'; 
	cout << p;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>
#define N 10

int cmpr_int(const void *a, const void *b)
{
  const int *x = a;
  const int *y = b;
  return *y - *x;
}

int main()
{
  static int x[N];
  int i;
  for (i = 0; i < N; i++) {
    scanf("%d", &x[i]);
  }
  qsort(x, N, sizeof(x[0]), cmpr_int);
  for (i = 0; i < 3; i++) {
    printf("%d\n", x[i]);
  }
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	int res = (int)1 << 60;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i + K - 1 < N; i++) {
		int R = A[i];
		int L = A[i + K - 1];
		int ans;
		if (R*L > 0) {
			ans = max(abs(R), abs(L));
		}
		else {
			ans = abs(R) + abs(L) + min(abs(R), abs(L));
		}
		res = min(res, ans);
	}
	cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



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

	int n, x;
	cin >> n >> x;
	vi a(n);
	rep(i, n)cin >> a[i];

	ll ans = 0;
	if (a[0] > x) {
		ans += a[0] - x;
		a[0] = x;
	}
	repr(i, 1, n) {
		if (a[i] + a[i - 1] > x) {
			ans += a[i] + a[i - 1] - x;
			a[i] = x-a[i-1];
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define repr(i, n) for(int i=(n-1); 1<=i; i--)
#define repr2(i, from, to) for(int i=(from-1); (int)(to)<=i; i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct gNode { int from, to, cost; };
struct tNode { int value; int parent; vector<int> child; };


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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

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

	int ans = 0;
	rep(i, n){
		ans += b[i];
		if(i != n-1 && a[i]+1 == a[i+1]) ans+=c[a[i]-1];
	}

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

Measured memory_bytes: 256
n = gets.to_i
ss = []
n.times do
  ss << gets.chomp.chars.sort.join
end

s_h = Hash.new(0)

ss.each do |s|
  s_h[s] += 1
end

def combi(n,k)
  return 0 if n < 2
  k=n-k if 2*k > n
  return 1 if k == 0
  ((n-k+1)..n).reduce(&:*)/((1..k).reduce(&:*))
end

# puts s_h

ans = 0
s_h.each do |k, v|
  ans += combi(v, 2)
end

puts ans

# ans = 0
# (0..n-2).each do |i|
#   ((i+1)..(n-1)).each do |j|
#     if ss[i] == ss[j]
#       ans += 1
#     end
#   end
# end

# puts ans



Measured memory_bytes: 31996
use std::cmp;

fn main() {
    let line: Vec<u32> = read_vec();
    let a: u32 = line[0];
    let b: u32 = line[1];
    let c: u32 = line[2];
    let x: u32 = line[3];
    let y: u32 = line[4];

    let mut x1: u32 = x;
    let mut y1: u32 = y;
    let mut z1: u32 = 0;

    if a + b > 2 * c {
        let m = cmp::min(x1, y1);
        z1 += 2 * m;
        x1 -= m;
        y1 -= m;
    }

    if a > 2 * c {
        z1 += 2 * x1;
        x1 = 0;
    }

    if b > 2 * c {
        z1 += 2 * y1;
        y1 = 0;
    }

    println!("{}", x1 * a + y1 * b + z1 * c);

}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
//be name khoda
#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;

using namespace std;

const ll INF = 1e18;
const ll maxn = 2e5+100;
const ll K = 310;
const ll mod = 1e9+7;

ll n , m , k, d;
ll dp[maxn][K], f[maxn][K];
string s;

ll ds(ll x)
{
    ll ans = 0;
    while(x)
    {
        ans += x%10;
        x /= 10;
    }
    return ans;
}

int main()
{
    cin>> s >> d; n = s.size();

    if(n <= 8)
    {
        ll x = 0, pw = 1;
        for(ll i = n-1; i >= 0; i--)
        {
            ll y = s[i]; y -= 48;
            x += pw * y;
            pw *= 10;
        }

        ll ans = 0;
        for(ll i = 1; i <= x; i++)
            if(ds(i) % d == 0)
                ans++;
        cout<< ans;
        return 0;
    }

    if(d == 1)
    {
        ll pw = 1, ans = 0;
        for(ll i = n-1; i >= 0; i--)
        {
            ll y = s[i]; y -= 48;
            ans = (ans + (pw*y) % mod) % mod;
            pw = (pw*10) % mod;
        }
        cout<< ans;
        return 0;
    }

	if(n == 1)
	{
		ll ans = 0;
		ll y = s[0]; y -= 48;
		for(ll i = 1; i <= y; i++)
			if(i % d == 0)
				ans++;
		cout<< ans;
		return 0;
	}
    for(ll i = n-1; i >= 0; i--)
        for(ll j = 0; j < d; j++)
        {
            if(i == n-1){
                for(ll ii = 0; ii < 10; ii++){
                    if((ii % d) == j)
                        f[i][j]++;
				}
			    continue;
            }
            for(ll ii = 0; ii < 10; ii++){
                ll x = (j-ii+10*d)%d;
                f[i][j] = (f[i][j] + f[i+1][x]) % mod;
            }
        }

    for(ll i = n-1; i >= 0; i--)
    {
        ll y = s[i]; y -= 48;
        for(ll j = 0; j < d; j++)
        {
            if(i == n-1){
                for(ll ii = 0; ii <= y; ii++)
                    if((ii % d) == j)
                        dp[i][j]++;
                continue;
            }

            for(ll ii = 0; ii < y; ii++){
                ll x = (j-ii+10*d)%d;
                dp[i][j] = (dp[i][j] + f[i+1][x]) % mod;
            }
            ll x = (j-y+10*d)%d;
            dp[i][j] = (dp[i][j] + dp[i+1][x]) % mod;
        }
    }

	dp[0][0] %= mod;
	if(dp[0][0] < 0)
		dp[0][0] += mod;

	if(dp[0][0] == 0)
		cout<< mod-1;
	else
		cout<< dp[0][0] - 1;
}







Measured memory_bytes: 51456
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	nextReader = NewScanner()
	_ = nextInt()
	line2 := nextInt()

	// desc sort
	sort.Sort(sort.Reverse(sort.IntSlice(line2)))

	var alice_point int
	var bob_point int

	for i := 0; i < len(line2); i++ {
		if i%2 == 0 {
			alice_point += line2[i]
		} else {
			bob_point += line2[i]
		}
	}

	fmt.Println(alice_point - bob_point)
}

// ------ Mathライブラリ ---------------------------------//
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func maxIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ------ Mathライブラリ ---------------------------------//

// ----- 標準入力用の関数 ----------------------------------//
var nextReader func() []string

func NewScanner() func() []string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	return func() []string {
		r.Scan()
		return strings.Fields(r.Text())
	}
}

func nextString() []string {
	return nextReader()
}

func nextInt() []int {
	var intArray []int
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.Atoi(v)
		intArray = append(intArray, i)
	}
	return intArray
}

func nextFloat64() []float64 {
	var floatArray []float64
	strArray := nextReader()
	for _, v := range strArray {
		f, _ := strconv.ParseFloat(v, 64)
		floatArray = append(floatArray, f)
	}
	return floatArray
}

// ------ 標準入力用の関数 ---------------------------------//

// ------ あまり使わない -----------------------------------//
func nextInt64() []int64 {
	var int64Array []int64
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.ParseInt(v, 10, 64)
		int64Array = append(int64Array, i)
	}
	return int64Array
}

// ------ あまり使わない -----------------------------------//


Measured memory_bytes: 640
import java.util.*;
 public class Main {
 
   public static void main(String[] args) { 
       Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       int[] arr = new int[n]; 
       for(int i = 0; i < n; i++) {
          arr[i] = sc.nextInt();
       }

       long cnt = 0;
       for(int i = 0; i < n - 1; i++) {
          cnt += arr[i] / 2;
          arr[i] = arr[i] % 2;
          int min = Math.min(arr[i], arr[i+1]);
          cnt += min;
          arr[i+1] -= min;
       }
       cnt += arr[n-1] / 2;
       System.out.println(cnt);
   }
 } 

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

int linesearch(int a[], int n,int key)
{
	for (int i = 0; i < n; i++) {
		if (a[i] == key) return 1;
	}
	return false;
}

int main()
{
	int n, q,t,sum=0;
	int s[10100];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> s[i];
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> t;
		sum += linesearch(s, n, t);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3128
import sys

def main() -> None:
    n, c, k = map(int, input().split())
    t = [int(sys.stdin.readline()) for _ in range(n)]
    ans = wait_start = wait_people = 0

    for ti in sorted(t):
        if ti - wait_start > k or wait_people == c:
            wait_people = 0
        wait_people += 1

        if wait_people == 1:
            wait_start = ti
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll k,i;
    cin >> k;
    ll num = 7 % k;
    ll N = 1e6 + 100;
    for(i = 1 ; i < N ; i++)
    {
        if(num == 0)
        {
            cout << i << "\n";
            return 0;
        }
        num = ((num * 10) % k + 7) % k;
    }
    cout << "-1\n";
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
ll ma(ll a, ll b){
	if(a>b)return a;
	else return b;
}
int main(){
	int n,k;
	cin>>n>>k;
	vector<ll> a(n+2),psum(n+2),ksum(n+2);
	for(int i=1;i<=n;i++){
		cin>>a[i];
		psum[i] = psum[i-1] + ma(a[i],0);
	}
	for(int i=1;i<=k;i++){
		ksum[1]+=a[i];
	}
	for(int i=k+1;i<=n;i++){
		ksum[i-k+1] = ksum[i-k] + a[i] - a[i-k];
	}
	ll ans=-1;
	for(int i=1;i<=n-k+1;i++){
		ll tmp=0;
		tmp += ma(ksum[i],0);
		tmp += psum[i-1];
		tmp += psum[n] - psum[i+k-1];
		if(ans<tmp)ans=tmp;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {  
	public static void main(String[] args) { //Not Quite
		//Sub-array sum equals K strikes back again (This time, linear complexity is needed)
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		Map<Long,Long> sums = new HashMap<Long,Long>();
		long ans = 0;
		long sum = 0;
		sums.put((long)0, (long)1);
		for (int i = 0; i < N; i++) {
			long x = I.nextLong();
			sum+=x;
			long check = sum; //sum-0
			if (sums.containsKey(check)) ans+=sums.get(check); 
			sums.put(sum, sums.getOrDefault(sum, (long)0)+1);
			//Number of negative prefix sums means that many 0 
			//sum sub-arrays (x+(-x) = 0)
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 63056
#include <cstdio>

int main(){
    int H, W;
    while(true){
        scanf("%d %d", &H, &W);
        if (H==0 && W==0){
            break;
        }
        for(int i = 0; i<H; i++){
            for(int j=0; j<W; j++){
                if(i == 0 || j == 0 || i == H-1 || j == W-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2692
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
 long long A;
 long long b1, b2;
 char ch;
  cin >> A >> b1 >> ch >> b2;
  long long b = b1 * 100 + b2;
  cout << (A * b) / 100 << endl;
  
  return 0;
}

Measured memory_bytes: 3604
import itertools

n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]
r = [[] for i in range(n + 1)]
ans = 0
for i in range(m):
    r[l[i][0]].append(l[i][1])
    r[l[i][1]].append(l[i][0])
p = "2345678"[:n-1]
p = list(itertools.permutations(p))
for i in range(len(p)):
    check = True
    t = "1" + "".join(p[i])
    for j in range(len(t)-1):
        if not int(t[j + 1]) in r[int(t[j])]:
            check = False
    if check:
        ans += 1
print(ans)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { printf("ERROR%d!\n",num); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    deque<char> deq;
    string S;
    cin >> S;
    rep(i,S.size()) deq.push_back(S[i]);
    int Q;
    cin >> Q;
    int flag = 0;
    rep(i,Q){
      int T;
      cin >> T;
      if(T==1) flag= (flag==0)? 1:0;
      else{
        int F; char C;
        cin >> F >> C;
        if(flag==0){
          if(F==1) deq.push_front(C);
          else deq.push_back(C);
        }else{
          if(F==1) deq.push_back(C);
          else deq.push_front(C);
        }
      }
    }

    if(flag==0){
      for(auto v : deq) cout << v; cout << endl;
    }else{
      for(auto v=deq.end()-1; v>=deq.begin(); v--){
        cout << *v;
      }
      cout << endl;
    }
}

Measured memory_bytes: 976
#include<iostream>
#include<vector>
#include<string>

using namespace std;

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

	vector<char> ans;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0')ans.push_back('0');
		else if (s[i] == '1')ans.push_back('1');
		else if (ans.size() > 0) ans.pop_back();
	}
	for (int i = 0; i < ans.size(); i++)cout << ans[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;

ll N;

int main() {
    int i, k, Ans = 0;
    scanf("%lld", &N);

    ll base = 1;
    for(i = 0; i <= 16; i++) {
        for(k = 0; k <= 9; k++) if((base - 1) + (base * k) <= N) {
            Ans = max(Ans, i * 9 + k);
        }
        base *= 10;
    }

    printf("%d", Ans);
    return 0;
}

Measured memory_bytes: 128
N,W=map(int,input().split())
oj=[]
for i in range(N):
  oj.append(list(map(int,input().split())))
M=100*1001
dp=[10**10]*M
dp[0]=0
for i in range(N):
  for j in range(M,-1,-1):
    if j+oj[i][1]<M:
      k=j+oj[i][1]
      dp[k]=min(dp[k],dp[j]+oj[i][0])
v=0
for i in range(M):
  if dp[i]<=W:v=i
print(v)


Measured memory_bytes: 41564
num = int(input())
k = int(1)

for i in range(1,num+1):
    if i%3 == 0:
        print(" %d"%i, end="")

    else:
        k = i
        while (k):
            if k%10 == 3:
                print(" %d"%i, end="")
                break
            k //=10
print()


Measured memory_bytes: 5868
import numpy as np

def is_ok(mid, k):
    s = np.maximum(a - mid // f, 0).sum()
    if s <= k:
        return True
    else:
        return False

n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
f = np.array(list(map(int, input().split())))
a = np.sort(a)
f = np.sort(f)[::-1]

l, r = -1, np.max(a * f) # l:ng, r:ok
while l + 1 < r:
    mid = (l + r) // 2
    if is_ok(mid, k):
        r = mid
    else:
        l = mid
print(r)

Measured memory_bytes: 37176
import copy

n = int(input())
num = list(map(int, input().split()))

tmp = copy.deepcopy(num)
q = int(input())
for _ in range(q):
    b, m, e = map(int, input().split())
    for i in range(e - b):
        pos = b + (i + e - m) % (e - b)
        tmp[pos] = num[i + b]
    num = copy.deepcopy(tmp)

print(' '.join(str(n) for n in num))


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

using namespace std;

#define pb push_back
const int maxi=1e6+7;
int a[maxi];
int n;
string s;
int cnt1[maxi],cnt[maxi];
int ma1,mb1,ma2,mb2;
map<int,int> mp,mp1;
vector<pair<int,int>> ans;
int main()
{
    cin>>s;

    int n=s.size();

    if (s[n-1]=='1' || s[0]=='0') return !printf("-1\n");

   for (int i=0;i<n-1;i++)
   if (s[i]!=s[n-i-2]) return !printf("-1\n");


    int root=1;

    for (int i=2;i<=n/2;i++)
        if (s[i-1]=='1')
        {
            for (int j=root;j<i;j++)
            ans.pb({j,i});
            root=i;
        }

    for (int i=root;i<n;i++)
    ans.pb({i,n});

    for (auto i:ans)
        printf("%d %d\n",i.first,i.second);
    return 0;
}


Measured memory_bytes: 4596
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<cmath>
#include<map>
using namespace std;
using ll = long long;
const int INF = 1e9;
#define rep(i,n)for(int i=0;i<n;++i)
#define p pair<int,int>
int main() {
	int N;
	cin >> N;
	int a[100];
	int amin = 100;
	int amax = -100;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		amin = min(amin, a[i]);
		amax = max(amax, a[i]);
	}
	int ans = INF;
	for (int i = amin; i <= amax; ++i) {
		int sum = 0;
		for (int j = 0; j < N; ++j) {
			sum += (i - a[j])*(i - a[j]);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("board.in");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

str t;
ll a, mod = 1e9+7, o=0;
vec<vec<ll>> dp;

int main() {
    fast;
    cin>>t;
    a = t.size();
    dp = vec<vec<ll>>(a, vec<ll>(13));
    if(t[0]=='?') for(int q=0; q<10; q++) dp[0][q] = 1;
    else dp[0][t[0]-'0'] = 1;
    for(int q=1; q<a; q++){
        for(int pr = 0; pr<13; pr++){
            if(t[q]!='?'){
                dp[q][(pr*10+(t[q]-'0'))%13] += dp[q-1][pr];
                dp[q][(pr*10+(t[q]-'0'))%13]%=mod;
            }
            else{
                for(int e=0; e<10; e++){
                    dp[q][(pr*10+e)%13] += dp[q-1][pr];
                    dp[q][(pr*10+e)%13]%=mod;
                }
            }
        }
    }
    cout<<dp[a-1][5];
}

Measured memory_bytes: 13648
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}

int main(){
	int a,b;scanf("%d%d",&a,&b);
	if(a*b%2)printf("Odd\n");else printf("Even\n");
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x = i;
        if (x % 3 == 0){
            cout << " " << i;
        }
        else{
            while (x){
                if (x % 10 == 3){
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
long long X=0,x=0,ans=1000000000000000000LL;
cin>>n;
vector<long long> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
X+=a[i];
}
for(int i=0;i<n;i++){
x+=a[i];
if(i+1<n)ans=min(ans,abs(X-2*x));
}
cout<<ans<<endl;
}

Measured memory_bytes: 1792