akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=b-1;i>=a;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll X;
  cin >> X;
  ll A=130,B=129;
  Rep(i,-130,131){
    Rep(j,-130,131){
      if(i*i*i*i*i-j*j*j*j*j==X){
        cout  <<i <<" " << j <<  endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3640
n=[i for i in range(100272)]
n[:2]=[0,0]
for i in range(2, 100272//2):
    if n[i]==i:n[i*2::i]=[0 for e in range(len(n[i*2::i]))]
while True:
    M,P=[int(i) for i in input().split()]
    if M==-1 and P==-1:break
    p=list(filter(lambda x:x!=0,n[M+1:]))[:25]
    l=[]
    for i in range(len(p)):
        for j in range(i+1):
            l.append(p[i]+p[j])
    print(sorted(l)[P-1])


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 100'000
#define MAX_M 100'000

i64 N, M;
priority_queue<i64> pq;

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

  i64 p;
  REP(i, N) {
    cin >> p;
    pq.push(p);
  }

  REP(i, M) {
    p = pq.top(); pq.pop();
    pq.push(p / 2);
  }

  i64 s = 0;
  REP(i, N) {
    p = pq.top(); pq.pop();
    s += p;
  }

  cout << s << endl;

  return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>
#define FOR(x,n) for(int i=(x);i<(n);i++)
int main(void){
    int mon,att=0;
    scanf("%i %i",&mon,&att);
    int c=0;
    while(1){
        mon-=att;
        c++;
        if(mon<=0) break;
    }
    printf("%i\n",c);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <cmath>
#include <random>
#include <bitset>
#include <complex>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define mmin(a, b) a = min(a, (b))
#define mmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define pb(a) push_back(a)
#define ALL(a) a.begin(),a.end()
#define sqr(x) (x) * (x)
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#define f(cnt) (((cnt) + 1) * (cnt) / 2)
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = 2 * acos(0.0);

template<typename T>
struct edge {
    int from, to;
    T w;
    edge(int from, int to, T w): from(from), to(to), w(w) { }
    edge() { }
};

template<class T, class C>
void show(C a) {
//    FIXME: it doesn't work
    for (T x : a)
        cout << x << " ";
    cout << endl;
}

ll calc(ll n) {
    return n * n * n;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n, k;
    cin >> n >> k;
    vl a(k);
    for (ll i = 0; i < k; ++i) {
        ll cur = n / k;
        cur += n % k >= i;
        a[i] = cur;
    }
    a[0] -= 1;
    ll ans = calc(a[0]);
    if (!(k & 1)) ans += calc(a[k >> 1]);
    cout << ans;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
# S昇順かつP降順
n = int(input())
lis = []
for i in range(1, n+1):
    a, b = input().split()
    lis.append((i, a, int(b)))

lis.sort(key=lambda x: x[2], reverse=True)
lis.sort(key=lambda x: x[1])
for i in range(n):
    print(lis[i][0])


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
class JNum{
	static constexpr uint64_t mod = 1000000007;
	uint64_t num;
public:
	JNum(uint64_t x):num(x%mod){}
	JNum operator+(const JNum& j)const{
		return (num + j.num)%mod;
	}
	JNum operator*(const JNum& j)const{
		return (num * j.num)%mod;
	}
	void operator+=(const JNum& j){
		num += j.num;
		num %= mod;
	}
	void operator*=(const JNum& j){
		num *= j.num;
		num %=mod;
	}
	uint64_t out()const{return num;}
};
using namespace std;
template<typename T>
void get(T& t){cin >> t;}
int main(void){
	string s;
	get(s);
	if(s.find("YAKI")==0)cout << "Yes" << endl;
	else cout << "No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.util.Comparator.*;
class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();        
        String[] s = new String[n];
        for(int i = 0; i < n ; i++)
            s[i] = (stdIn.next() + "_" + (1100 - stdIn.nextInt()) + "_" + (i +1));
        Arrays.sort(s);
        for(String i: s)
            System.out.println(i.split("_")[2]);
   }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
using namespace std;
#define INF (1<<25)
#define P(a,b) make_pair(a,b)

int id = 0;
string s;

int exp();
int term();
int fact();

int exp(){
	int ans = term();
	while(true){
		char c = s[id++];
		if(c == '+'){
			ans += term();
		}else if(c=='-'){
			ans -= term();
		}else{
			return ans;
		}
	}
}
int term(){
	int ans = fact();
	while(true){
		char c = s[id++];
		if(c == '*'){
			ans *= fact();
		}else if(c=='/'){
			ans /= fact();
		}else{
			id--;
			return ans;
		}
	}
	
}
int fact(){
	char c = s[id++];
	if(c=='(') return exp();
	if(c=='-') return -exp();
	if(c=='+') return  exp();
	int x = c - '0';
	while(true){
		c = s[id++];
		if('0' <= c && c <= '9'){
			x = x*10 + c - '0';
		}else{
			id--;
			return x;
		}
	}
}
int main(){
	int n;
	cin >> n;
	while(n--){
		cin >> s;
		id = 0;
		cout << exp() << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  char c1,c2,c3,c4;
  cin >> c1 >> c2 >> c3 >> c4;
  if (c1 == '+'){
    N++;
  } else {
    N--;
  }
  if (c2 == '+'){
    N++;
  } else {
    N--;
  }
  if (c3 == '+'){
    N++;
  } else {
    N--;
  }
  if (c4 == '+'){
    N++;
  } else {
    N--;
  }
  cout << N;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> a(n + 1, 0);
	vector<bool> pushed(n + 1, false);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	int now = 1;
	int ans = 0;

	while (now != 2) {
		if (pushed[now]) {
			ans = -1;
			break;
		}

		pushed[now] = true;
		now = a[now];
		ans++;
	}

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


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long n, k, new_n;
    cin >> n >> k;
    n = n % k;

    new_n = abs(n - k);
    if (new_n >= n)
        cout << n << endl;
    else
        cout << new_n << endl;
        
    return 0;
}


Measured memory_bytes: 256
n,m,l=map(int,input().split())
a=[]
b=[]

for i in range(n):
    a.append(list(map(int,input().split())))

for i in range(m):
    b.append(list(map(int,input().split())))

c=[]
for i in range(n):
    ci=[]
    for j in range(l):
        cij=0
        for k in range(m):
            cij+=a[i][k]*b[k][j]
        ci.append(cij)
    c.append(ci)

for i in range(len(c)):
    for j in range(len(c[i])):
        print(c[i][j],end="")

        if(j<len(c[i])-1):
            print(" ",end="")
    print()



Measured memory_bytes: 7148
#include <stdio.h>
int makerand(int a, int b, int c, int x);
int main(void) {
    int num,a,b,c,rand,i,reel[100],sp;
    while (1) {
        scanf("%d %d %d %d %d",&num,&a,&b,&c,&rand);
        if (num==0&&a==0&&b==0&&c==0&&rand==0) break;
        for (i=0; i<num; i++) scanf("%d",&reel[i]);
        sp=0;
        for (i=0; i<num; i++) {
            if (reel[i]>=c) break;
        }
        if (i!=num) {
            printf("-1\n");
            continue;
        }
        if (rand==reel[0]) {
            sp++;
            if (sp==num) {
            	printf("0\n");
            	continue;
            }
            
        }
        for (i=1; i<=10000; i++) {
            if (sp>=num-1&&reel[sp]==makerand(a,b,c,rand)) break;
        	rand=makerand(a,b,c,rand);
            if (rand==reel[sp]) sp++;
        }
        if (i==10001) {
            printf("-1\n");
        } else {
            printf("%d\n",i);
        }
    }
    return 0;
}

int makerand(int a, int b, int c, int x) {
    return (a*x+b)%c;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> l(n);
  for(int i=0; i<n; i++){
    cin >> l[i];
  }
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());
  int ans = 0;
  for(int i=0; i<k; i++){
    ans += l[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int a[MAXN];
int G[105][105];

int main()
{
    int h,w;
    while(scanf("%d%d",&h,&w)!=EOF)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
            scanf("%d",&a[i]);
        int cnt=1;
        for(int i=1;i<=h;++i)
        {
            if(i&1)
            {
                for(int j=1;j<=w;++j)
                {
                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }else
            {
                for(int j=w;j>=1;--j)
                {
                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }
        }
        for(int i=1;i<=h;++i)
        {
            for(int j=1;j<=w;++j)
            {
                if(j!=w) printf("%d ",G[i][j]);
                else printf("%d\n",G[i][j]);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;
		int numC = 0;
		int numD = 0;

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();
			numC = scanner.nextInt();
			numD = scanner.nextInt();

			boolean canTalk = false;

			canTalk = ((Math.abs(numA - numB) <= numD && Math.abs(numB - numC) <= numD)
					|| Math.abs(numA - numC) <= numD);

			System.out.println(canTalk ? "Yes" : "No");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numX = 0;

		try {
			scanner = new Scanner(System.in);
			numX = scanner.nextInt();

			int max = 0;
			for (int i = 1; i <= numX; i++) {
				for (int j = 2; j < 10; j++) {
					if (Math.pow(i, j) <= numX) {
						max = Math.max(max, (int) Math.pow(i, j));
					} else {
						break;
					}
				}
			}

			System.out.println(max);
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private static class StrComparator implements Comparable<String> {

		@Override
		public int compareTo(String o) {
			// TODO 自動生成されたメソッド・スタブ
			return 0;
		}

	}

	private void solveC() {
		Scanner scanner = null;
		String s = "";
		int numK = 0;

		try {
			scanner = new Scanner(System.in);
			s = scanner.next();
			numK = scanner.nextInt();
			Set<String> wk = new HashSet<String>();

			String wkS = "";
			for (int i = 0; i < s.length(); i++) {
				int max = i + numK < s.length() ? i + numK : s.length();
				for (int j = i; j <= max; j++) {
					wkS = s.substring(i, j);
					if (wkS != null && !wkS.equals("")) {
						wk.add(wkS);
					}
				}
			}

			List<String> wkList = new ArrayList<String>();
			for (String string : wk) {
				wkList.add(string);
			}

			Collections.sort(wkList);

			System.out.println(wkList.get(numK - 1));

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 24908
#include<iostream>
#include<queue>
using namespace std;
priority_queue <int, vector<int >, greater<int > > q;
int main(){
    int t=3;
    while(t--){
        int i;
        cin>>i;
        q.push(i);
    }
    int ans=0;
    ans+=q.top();
    q.pop();
    ans+=q.top();
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<unsigned ll>
#define mp make_pair
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const unsigned ll l=1000000007;
const int MAX_=2000;
int T;

void print(string res, int i)
{
  printf("Case #%d: %s\n",T-i,res.c_str());
  // cout << res;
}
void print(ll res, int i)
{
  printf("Case #%d: %lld\n",T-i,res);
  // cout << res;
}

// ll ans(vll &a, int i)
// {
//   if(i == 0)
//     return 1;

//   int cnta=0,cntb=0;

//   for(auto x: a)
//   {
//     if(x & (1<<i) == 0)
//     {
//       cnta++;
//     }
//     else
//       cntb++;
//   }

//   if(cnta == a.size())
//   {
//     return ans(a,i-1);
//   }

//   if(cntb == a.size())
//   {
//     return 1<<i + ans(a,i-1);
//   }

//   ll toret1, toret2;

// }

void solve(int t)
{
  unsigned ll h,w;
  cin >> h >> w;
  if(h > w)
    swap(h,w);
  if(h == 1)
  {
    cout << 1 << endl;
    return;
  }
  h++;
  w++;
  unsigned ll ans= (h/2)*(w/2) + ((h-1)/2)*((w-1)/2);
  cout << ans << endl;

  // ll a,b,c;
  // cin >> a >> b >> c;
  // cout << sqrt(a) << " " << sqrt(b) << " " << sqrt(c) << endl;
  // if(sqrt(a) + sqrt(b) < sqrt(c))
  // {
  //   cout << "YES" << endl;
  // }
  // else
  //   cout << "NO" << endl;
}

int main()
{
  IOS
  int t,testCases;
  testCases=1;
  #ifdef DEBUG
    freopen("input.txt","r",stdin);
    cin >> testCases;
    cout << "Running " << testCases << " testcases" << endl;
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
  #endif

  while(testCases--)
  {
    t=1;
    // cin >> t; //comment this in case of singular test case
    T = t;
    while(t--)
    {
      // cout << "HERE" << endl;
      solve(t);
    }
  }
  return 0;

}




Measured memory_bytes: 256
"use strict"

function func(n){
  for(let i=2; i<n; i++){
    if(n%i === 0){
      return false;
    }
  }
  return true;
}


function Main(input) {
  let X = Number(input.trim());
 
  let ret = 0;
  for(let i=X; ;i++){
    if(func(i)){
      ret = i;
      break;
    }
  }
  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
#include <iostream>

using namespace std;

int main(){
  int N,M;
  int sum = 0;
  int T[110];
  int P[110];
  int X[110];

  cin >> N;
  for(int i=0;i < N;i++){
    cin >> T[i];
    sum += T[i];
  }
  cin >> M;
  for(int i=0;i<M;i++){
    cin >> P[i] >> X[i];
  }
  for(int i=0;i<M;i++){
    cout << sum - T[P[i] - 1] + X[i] << endl;
  }

  return 0;
}

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

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

    for(int i = 1; i <= n; i++){
        if(i % 3 == 0){
            cout << " " << i;
        }
        else if(i % 10 == 3 || (i / 10) % 10 == 3 || (i / 100) % 10 == 3 || i / 1000 == 3){
            cout << " " << i;
        }

        if(i == n){
            cout << endl;
        }
    }

}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>

// UnionFind 木 ; 頂点 = 0, 1, 2, ...,  n-1
class UnionFindTree{
private:
    using Vint = std::vector<int>;
    const int n; // 集合の大きさ
    Vint Parent; // 親のインデックスを指し示す
    Vint SetSize; // 各集合の大きさ(要素数)を保持する関数
public:
    // コンストラクタ
    UnionFindTree(int nn): n(nn){
        SetSize.resize(n, 1);
        Parent.resize(n);
        // 初めは, 全ての頂点は根である
        for(int i = 0; i < n; ++i) Parent[i] = i;
    }
    // デコンストラクタ
    ~UnionFindTree(void){}
    // 頂点 x の属する集合の根を返す関数
    int rootOf(int x){
        // x が 根であるなら終了
        if(Parent[x] == x) return x;
        // そうでないなら, 親を属する集合の根に付け替える
        return Parent[x] = rootOf(Parent[x]);
    }
    // 頂点 x, y を併合する
    void unite(int x, int y){
        int root_x = rootOf(x);
        int root_y = rootOf(y);
        // 異なる集合に属する場合
        if(root_x == root_y) return;
        if(SetSize[root_x] < SetSize[root_y]) std::swap(root_x, root_y);
        Parent[root_y] = root_x;
        SetSize[root_x] += SetSize[root_y];
    }
    // 頂点 x, y が 同じ集合に属しているかを判定する
    bool sameSet(int x, int y){
        return rootOf(x) == rootOf(y);
    }
    // 頂点 x の属する集合の要素数
    int sizeOf(int x){
        return SetSize[rootOf(x)];
    }
};


int main(void){
    int n, q; scanf("%d%d", &n, &q);
    UnionFindTree UFT(n);
    for(int _ = 0; _ < q; ++_){
        int p, q, r; scanf("%d%d%d", &p, &q, &r);
        if(p == 0) UFT.unite(q, r);
        else puts( UFT.sameSet(q, r) ? "1" : "0");
    }
    return 0;
}


Measured memory_bytes: 3240
a, b, c, k = map(int, input().split())
sum = 0

while k > 0:
    if a <= k:
        sum += a
        k -= a
        if k <= 0:
            break
    else:
        sum += k
        break

    if b <= k:
        k -= b
        if k <= 0:
            break
    else:
        break

    if  c <= k:
        sum -= c
        k -= c
        if k <= 0:
            break
    else:
        sum -= k
        break
    

print(sum)

Measured memory_bytes: 9108
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n;

int main(){
    cin >> n;
    LL ans = HINF<LL>();
    for(LL i = 1;i <= sqrt(n + 1);i++){
        if(n % i == 0){
            ans = min(ans, i + n/i - 2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    int area1, area2;
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    area1 = A*B;
    area2 = C*D;
    if(area1 > area2) {
        cout << area1 << endl;
    } else {
        cout << area2 << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        k: usize,
    }

    let mut ans = std::iter::repeat(49+k/50).take(50).collect_vec();
    for i in 0..k%50 {
        for j in 0..50 {
            if i == j {
                ans[j] += 50;
            } else {
                ans[j] -= 1;
            }
        }
    }
    println!("50");
    for v in ans {
        print!("{} ", v);
    }

}


Measured memory_bytes: 2180
#include <cstdint>
#include <iostream>
#include <memory>
#include <vector>
#include <unordered_map>

using namespace std;

struct Node {
  Node(int64_t u) : v(u) {}
  int64_t v;
  shared_ptr<Node> next = nullptr;
};

vector<int64_t> MakeVec(unordered_map<int64_t, shared_ptr<Node>>& nodes, int64_t st) {
  shared_ptr<Node> st_adr = nodes[st];
  vector<int64_t> vec;
  vec.push_back(st_adr->v);
  shared_ptr<Node> cur = st_adr->next;
  while (cur != nullptr && cur != st_adr) {
    vec.push_back(cur->v);
    cur = cur->next;
  }
  return vec;
}

int main() {
  int64_t N, X, M;
  cin >> N >> X >> M;

  unordered_map<int64_t, shared_ptr<Node>> nodes;
  
  shared_ptr<Node> pre = make_shared<Node>(X);
  nodes[X] = pre;
  vector<int64_t> loop;
  int64_t sum = X;
  int64_t n = 1;
  for (; n < N; ++n) {
    int64_t cur = (pre->v * pre->v) % M;
    if (nodes.count(cur)) {
      loop = MakeVec(nodes, cur);
      break;
    }
    shared_ptr<Node> cur_node = make_shared<Node>(cur);
    pre->next = cur_node;
    pre = cur_node;
    nodes[cur] = cur_node;
    sum += cur;
  }
  if (n == N) {
    cout << sum << endl;
  } else {
    int64_t loop_sum = loop[0];
    vector<int64_t> sums(loop.size()+1, 0);
    sums[1] = loop[0];
    for (size_t i = 1, size = loop.size(); i < size; ++i) {
      sums[i+1] = sums[i] + loop[i];
      loop_sum += loop[i];
    }
    int64_t rest = N - n;
    cout << sum + loop_sum * (rest / loop.size()) + sums[rest % loop.size()] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 9296
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
 
	ll n, a[100005];

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	if (a[n-1] != 2) {
		cout << -1 << endl;
		return 0;
	}

	ll mn = 2, mx = 3;

	for (int i = n-2; i >= 0; i--) {
		ll d = mn / a[i];

		if (a[i] * d < mn)
			d++;
		if (a[i] * d > mx) {
			cout << -1 << endl;
			return 0;
		}
		mn = a[i] * d;

		d = mx / a[i];
		mx = a[i] * (d + 1) - 1;
	}

	cout << mn << " " << mx << endl;
 
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

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

const int INF = 1e9 + 7, N = 1e5 + 7, M = 1e9 + 7;

vi G[N];
int dp[N][2];

void dfs(int u, int p = -1) {
	dp[u][0] = dp[u][1] = 1;
	for(int v:G[u]) if(v != p){
		dfs(v, u);
		dp[u][0] = (ll) dp[u][0] * (dp[v][0] + dp[v][1]) % M;
		dp[u][1] = (ll) dp[u][1] * dp[v][0] % M;
	}
}

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		G[u].PB(v);
		G[v].PB(u);		
	}
	dfs(1);
	cout << (dp[1][0] + dp[1][1]) % M << endl;


}



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

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

    int c[n-1], s[n-1], f[n-1];
    for (int i = 0; i < n-1; i++) {
        cin >> c[i] >> s[i] >> f[i];
    }

    for (int i = 0; i < n; i++) {
        int time = 0;
        for (int j = i; j < n-1; j++) {
            if (time <= s[j]) {
                time = s[j] + c[j];
            } else if ((time-s[j]) % f[j] == 0) {
                time += c[j];
            } else {
                time += f[j] - ((time-s[j]) % f[j]) + c[j];
            }
        }

        cout << time << endl;
    }

    return 0;
}

Measured memory_bytes: 256
// C - Attention
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; string S; cin>>N>>S;
	vi W(N+1);
	rp(i, 0, N) W[i+1] = W[i] + (S[i]=='W');
	int mini = INT_MAX;
	rp(leader, 1, N+1)
		mini = min(mini, W[leader-1] + (N-leader)-(W[N]-W[leader]));
	cout<< mini <<endl;
}

Measured memory_bytes: 1796
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true){

			int a = sc.nextInt();
			String option = sc.next();
			int b = sc.nextInt();

			if(option.equals("?"))break;

			int ans = 0;

			switch(option){
			case "+":
				ans = a+b;
				break;
			case "-":
				ans = a-b;
				break;
			case "*":
				ans = a*b;
				break;
			case "/":
				ans = a/b;
				break;
			}

			System.out.println(ans);
		}
	}
}



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

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

  vector<int> A(N);
  rep(i, N) cin >> A[i];

  sort(A.begin(), A.end());

  int prev = 0;
  vector<int> kinds;
  for (int i = 1; i < N; i++)
    if (A[i - 1] != A[i]) {
      kinds.push_back(i - prev);
      prev = i;
    }
  kinds.push_back(N - prev);

  sort(kinds.begin(), kinds.end());

  int diff = kinds.size() - K;
  int ans = 0;
  rep(i, diff) ans += kinds[i];

  cout << ans << endl;
}

Measured memory_bytes: 2168
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    long long L, R;
    cin >> L >> R;

    R = min(R, L + 2019 * 2);

    long long ans = INF;
    for (long long i = L; i <= R - 1; i++) {
        for (long long j = i + 1; j <= R; j++) {
            ans = min(ans, (i * j) % 2019);
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    int n;cin >> n;
    vector<int> a(n);
    int k = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
        k ^= a.at(i);
    }
    for (int i = 0; i < n - 1; i++)
    {
        cout << (int)(k ^ a[i]) << " ";
    }
    cout << (int)(k ^ a[n-1]) << endl;
    
    return 0;
}

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

int main(){
  int N;cin>>N;
  vector<int> L(N);
  for(int i=0;i<N;i++) cin>>L.at(i);
  sort(L.begin(),L.end());
  long count=0;
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
        if(L.at(i)+L.at(j)<=L.at(k)) break;
        else count++;
      }
    }
  }
  cout<<count<<endl;
}
      

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> PP;
PP A[1001];
void Max(int &a,int b){a=max(a,b);}

int main(){
  int n;
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>A[i].f.s>>A[i].f.f>>A[i].s;
    sort(A,A+n);
    
    int dp[2][367][367]={};
    for(int i=0;i<n;i++){
      int l=A[i].f.s,r=A[i].f.f+1,c=A[i].s,b=i%2;
      for(int j=0;j<=366;j++)
	for(int k=0;k<=366;k++){
	  Max(dp[!b][j][k],dp[b][j][k]);
	  if(j<=l)Max(dp[!b][r][k],dp[b][j][k]+c);
	  if(k<=l)Max(dp[!b][j][r],dp[b][j][k]+c);
	}

    }
    int ans=0;  
    for(int i=0;i<=366;i++)
      for(int j=0;j<=366;j++)Max(ans,dp[n%2][i][j]);
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 4136
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 10;
int num[maxn];
int main(void) {
    std::ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, k, x;
    while(cin >> n >> k) {
        memset(num, 0, sizeof(num));
        int kind = 0;
        for(int i = 0; i < n; ++i) {
            cin >> x;
            if(!num[x]) ++kind;
            num[x]++;
        }
        if(kind <= k) {
            cout << 0 << endl;
            continue;
        }
        sort(num, num + maxn, greater<int>());
        vector<int> vt;
        for(int i = 0; ; ++i) {
            if(!num[i]) break;
            vt.push_back(num[i]);
        }
        reverse(vt.begin(), vt.end());
        int cnt = 0;
        for(int i = 0; i < kind - k; ++i) cnt += vt[i];
        cout << cnt << endl;
    }
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  ll N,K;
  cin >> N >> K;
  vector<ll> P(N);
  vector<ll> Sum(N);
  rep(i,N){
    ll p;
    cin >> p;
    P.at(i) = p + 1;
    if(i == 0){
      Sum.at(0) = P.at(0);
    }
    else{
      Sum.at(i) = Sum.at(i-1) + P.at(i);
    }
  }
  ll M = Sum.at(K-1) - 0;
  rep(i,N-K){
    M = max(M,Sum.at(K+i)-Sum.at(i));
  }
  cout << fixed << setprecision(8);
  if(M % 2 != 0){
  cout << M/2 + 0.5 << endl;
  }
  else{
    cout << M/2 << endl;
  }
  return 0;
}

Measured memory_bytes: 6396
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var l = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var lg = l.Where(x => x % 2 == 0).ToArray();
        var lk = l.Where(x => x % 2 == 1).ToArray();
        int i = 0;
        long res = 0;
        while (i < lg.Length)
        {
            var wari = lg[i];
            while(wari % 2 == 0)
            {
                wari /= 2;
                res++;
            }
            i++;
        }
        Console.WriteLine(res);
    }
}


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

using namespace std;

using int64 = long long;

int main() {
  int N;
  cin >> N;
  for(int i = 111; i <= 999; i += 111) {
    if(N <= i) {
      cout << i << endl;
      exit(0);
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	int n;
  cin>>n;
  vector<vector<vector<int> > > builds(4, vector<vector<int> > (3, vector<int>(10)));
  int b,f,r,v;
  rep(i,n){
    cin>>b>>f>>r>>v;
    builds.at(b-1).at(f-1).at(r-1) += v;
  }
  rep(i,4){
    rep(j,3){
      rep(k,10){
        printf(" %d", builds.at(i).at(j).at(k));
      }
      printf("\n");
    }
    if (i==3){break;}
    printf("####################\n");
  }
}


Measured memory_bytes: 3256
object Main {

  def gcd(a: Long, b: Long): Long = if(b!=0) gcd(b,a%b) else a

  def lcm(a: Long, b: Long): Long = a * b / gcd(a,b)

  def loop(s: String){
    if (s != null) {
      val Array(a,b,_*) = s.split(" ").map(_.toLong)
      println(gcd(a,b)+" "+lcm(a,b))
      loop(scala.io.StdIn.readLine)
    }
  }


  def main(args: Array[String]): Unit = {
    var line = ""
    while({line = scala.io.StdIn.readLine; line != null }) {
      val Array(a,b,_*) = line.split(" ").map(_.toLong)
      println(gcd(a,b)+" "+lcm(a,b))
    }

    //loop(scala.io.StdIn.readLine)
  }
}

Measured memory_bytes: 40716
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <deque>

using namespace std;

int main(int argc, char const *argv[])
{
	 string s; cin >> s;
	 if (s[0] != 'A')
	 {
	 	cout << "WA" << endl;
	 	return 0;
	 }
	 int cnt = 0;
	 string ans = "AC";
	 for (int i = 1; i < s.length(); i++)
	 {
	 	if (isupper(s[i]))
	 	{
	 		if (i == 1 || i == s.length() - 1 || s[i] != 'C') ans = "WA";
	 		cnt++;
	 	}
	 }
	 if (cnt != 1) ans = "WA";
	 cout << ans << endl; 
}

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

int main()
{
    long long int n, i, count = 0, maxx = 0;

    cin >> n;

    vector<long long int> a(n);

    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    for (i = 0; i < n; i++)
    {
        maxx = max(maxx, a[i]);

        count += maxx - a[i];
    }

    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 4740
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  int N; cin >> N;

  int x = -1;
  FOR(i,1,N+1) {
    if ((int)(i*1.08) == N) {
      x = i;
      break;
    }
  }

  string ans = x<0 ? ":(" : to_string(x);

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
/*
ID: yzshang1
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
int n;
int c[10][10];
void cut(int x, int &first, int &last) {
	last = x % 10;
	while (x > 10) x /= 10;
	if (x == 10) x = 1;
	first = x;
	//cerr << "first " << first << " last " << last << endl; 
}
int main() {
	cin >> n;
	repn(i, n) {
		int f, l;
		cut(i, f, l);
		c[f][l]++;
	}
	int ans = 0;
	rep(i, 10) rep(j, 10) ans += c[i][j] * c[j][i];
	cout << ans << endl;
	return 0; 
}
 

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  int H,W; cin >> H >> W;
  int N; cin >> N;
  v<int> a(N);
  rep(i,N){
    cin >> a[i];
  }
  vv<int> field(H,v<int>(W));
  int x=0,y=0;
  rep(i,N){
    rep(j,a[i]){
      if(y==W){
        x++;
        y=0;
      }
      field[x][y]=i+1;
      y++;
      //cout <<x << endl;
    }

  }

  for(int i=0;i<H;i+=2){
    reverse(field[i].begin(),field[i].end());
  }

  rep(i,H){
    rep(j,W-1) cout << field[i][j] << " ";
    cout << field[i][W-1];
    cout << endl;
  }
  return 0;
}


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

int main(void)
{
    int h, w;
    char sky[128][128];
    int cloud[128][128] = {0};
    int i, j;

    scanf("%d %d", &h, &w);
    for (i = 0; i < h; i++) scanf("%s", sky[i]);

    memset(cloud, -1, 128 * 128 * sizeof(int));
    for (i = 0; i < h; i++){
        for (j = 0; j < w; ){
            for (; j < w && sky[i][j] == '.'; j++);
            if (j < w) cloud[i][j] = 0;
            else break;
            for (j++; j < w && sky[i][j] == '.'; j++) cloud[i][j] = cloud[i][j - 1] + 1;
        }
    }

    for (i = 0; i < h; i++){
        for (j = 0; j < w; j++) printf("%d%c", cloud[i][j], "\n "[j < w - 1]);
    }

    return 0;
}

Measured memory_bytes: 688
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

inline bool IN(int x, int y, int w, int h)
{
    return 0 <= x && x < w && 0 <= y && y < h;
}

string strstep(string l){
	string r="";
	rp(i,l){
		if(l[i]=='z'){
			r+='a';
		}else if(l[i]>='A' && l[i]<='y'){
			r+=(l[i]+1);
		}else{
			r+=l[i];
		}
	}
	return r;
}
bool findth(string& string){
	bool flag=false;
	size_t found;
	found=string.find("the");
	if(found!=string::npos){
		flag=true;
	}
	found=string.find("this");
	if(found!=string::npos){
		flag=true;
	}
	found=string.find("that");
	if(found!=string::npos){
		flag=true;
	}
	return flag;
}
int main()
{
	string s;
	while(getline(cin, s)){
		rep(i,26){
			if(findth(s)){
				cout << s << endl;
				break;
			}else{
				s=strstep(s);
			}
		}
	}

}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}



int n;
vector<int> v;
int ans=0;

void f(int c){
  int res=0;
  bool flag[200000]={};


  for(int kc=c;kc<n-1;kc+=c){
    int a=n-1-kc;
    int b=a-c;
    if(a<=b||b<=0) break;
    if(a==kc||flag[a]||flag[kc]) break;
    res+=v[a]+v[kc];
    flag[a]=true;
    flag[kc]=true;
    ans=max(ans,res);
  }
}




main(){
  cin>>n;
  v.resize(n);
  
  rep(i,n){
    cin>>v[i];
  }

  for(int i=1;i<n-1;i++){
    f(i);
  }

  cout<<ans<<endl;
}


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

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

long long MOD = 1000000000 + 7;


int solve(int n){

  int ret = 0;

  for(int x = 1; x*x < n; x++){
    for(int y = 1; x*x + y*y + x*y < n; y++){
      for(int z = 1; x*x+y*y+z*z+x*y+y*z+z*x <= n; z++){
        if(x*x+y*y+z*z+x*y+y*z+z*x == n){
          ret++;
        }
      }
    }
  }
  return ret;
}
int main(){
  cout << setprecision(10);

  int N; cin >> N;
  for(int n = 1; n <= N; n++){
    cout<<solve(n)<<endl;
  }

}


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

typedef long long int ll;

int main()
{
    string o, e;
    cin >> o >> e;
    ll olen = o.length(), elen = e.length();
    bool f = true;
    ll cnt = 0;
    for(ll i = 0;i < olen + elen;i++){
        if(cnt == olen + elen){
            break;
        }
        if(f){
            cout << o[i];
            f = false;
            i--;
        }
        else{
            cout << e[i];
            f = true;
        }
        cnt++;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd; 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define pb(v) push_back(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b)
{
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s)
{
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v)
{
	forl(i,v.size())
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
void pa(ll *v,ll size)
{
	forl(i,size)
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
// ll nck(ll N,ll K,ll mod)
// {
// 	if(N<K)
// 	{
// 		return 0;
// 	}
// 	return (((facs[N]*facsinv[N-K])%mod)*facsinv[K])%mod;
// }
ll power(ll x,ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		{
			res=(res*x)%p;
		}
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x,ll mod)
{
	if(x>=mod)
	{
		x%=mod;
	}
}
ll sumofgp(ll a,ll n,ll m)
{
	// n = number of terms - 1
	if(n<0)
	{
		return 0;
	}
	if(n==0)
	{
		return 1;
	}
	if(n==1)
	{
		return (1+a)%m;
	}
	ll ans;
	if(n%2)
	{
        ans=(1+a)*sumofgp((a*a)%m,(n-1)/2,m);
	}
    else
    {
        ans=1+((a*(1+a))%m)*sumofgp((a*a)%m,n/2-1,m);
    }
    return ans%m;
}
ll power_of_2_not_less(ll n)
{
	if(!n)
	{
		return 1;
	}
	n--;
	n |= n>>1;
	n |= n>>2;
	n |= n>>4;
	n |= n>>8;
	n |= n>>16;
	n |= n>>32;
	n++;
	return n;
}
// void checktime()
// {
// 	struct timespec ts;
// 	printf("Running Program\n");
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double st=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	// Call Funcn Here
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double en=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	printf("Program ended\nTime = %Lf\n",en-st);
// }

int main(void)
{
	fastio
	ll a, b, c, k;
	cin>>a>>b>>c>>k;
	ll ans = 0;
	ans += min(a,k);
	k -= min(a,k);
	if(k<=0) {
		cout<<ans<<"\n";
		return 0;
	}
	k -= min(b,k);
	if(k<=0) {
		cout<<ans<<"\n";
		return 0;
	}
	ans -= k;
	cout<<ans<<"\n";
	return 0;
}

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

int main()
{
	string sr[200];
	int n,m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> sr[i];
	sort(sr, sr + n);
	for (int i = 0; i < n; i++)
		cout << sr[i];
	cout << endl;
	return 0;
}


Measured memory_bytes: 256