akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int N, K, X[50], Y[50];

int count(int x1, int x2, int y1, int y2) {
    int ret = 0;
    REP(i, N) if (x1 <= X[i] && X[i] <= x2 && y1 <= Y[i] && Y[i] <= y2)
        ret++;
    return ret;
}

int main() {
    int SX[50], SY[50];
    cin >> N >> K;
    REP(i, N) cin >> X[i] >> Y[i];
    REP(i, N) {
        SX[i] = X[i];
        SY[i] = Y[i];
    }
    sort(SX, SX + N); sort(SY, SY + N);

    ll ans = 4000000000000000000;
    REP(x1, N) FOR(x2, x1 + K - 1, N) REP(y1, N) FOR(y2, y1 + K - 1, N) if (count(SX[x1], SX[x2], SY[y1], SY[y2]) >= K) {
        ans = min(ans, ll(SX[x2] - SX[x1]) * (SY[y2] - SY[y1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<float,int> P;
int main(void)
{
	P a[8],b[8],c[8],d[18];
	int i,j,jj,jjj;
	for(i=0;i<8;i++){
		scanf("%d %f",&a[i].second,&a[i].first);
	}
//for(i=0;i<8;i++)	printf(" %d %f\n",a[i].first,a[i].second);
	sort(a,a+8);	
	for(i=0;i<8;i++){
		scanf("%d %f",&b[i].second,&b[i].first);
	}
	sort(b,b+8);
	for(i=0;i<8;i++){
		scanf("%d %f",&c[i].second,&c[i].first);
	}
	sort(c,c+8);
	
	for(i=0;i<6;i++){
		d[i].first=a[i+2].first;	
		d[i].second=a[i+2].second;	
		//printf("j=%d %f\n",d[i].second,d[i].first);
	}
	for(i=0;i<6;i++){
		d[i+6].first=b[i+2].first;
		d[i+6].second=b[i+2].second;		
		//printf("jj=%d %f\n",d[i+6].second,d[i+6].first);
	}
	for(i=0;i<6;i++){
		d[i+12]=c[i+2];
		//printf("jjj=%d %f\n",d[i+12].second,d[i+12].first);
	}
	//printf("%d %f\n",d[i].second,d[i].first);
	sort(d,d+18);
	//
	
	printf("%d %.2f\n",a[0].second,a[0].first);
	printf("%d %.2f\n",a[1].second,a[1].first);
	printf("%d %.2f\n",b[0].second,b[0].first);
	printf("%d %.2f\n",b[1].second,b[1].first);
	printf("%d %.2f\n",c[0].second,c[0].first);
	printf("%d %.2f\n",c[1].second,c[1].first);
	printf("%d %.2f\n",d[0].second,d[0].first);
	printf("%d %.2f\n",d[1].second,d[1].first);
	return 0;
}

Measured memory_bytes: 1076
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

ll mod=998244353;
long long modpow(long long x,long long n,long long mod)
{
  if(n==0)return 1;
  long long res=modpow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>cnt(n);
  ll res=1;
  rep(i,n){

    ll a;cin>>a;
    if(i==0&&a!=0){
      cout<<0<<endl;
      return 0;
    }
    cnt[a]++;
  }
  if(cnt[0]>1){
    cout<<0<<endl;
    return 0;
  }
  rep(i,n-1){
    if(cnt[i]==0&&cnt[i+1]>0){
      cout<<0<<endl;
      return 0;
    }
    if(cnt[i+1]&&cnt[i]>0)res*=modpow(cnt[i],cnt[i+1],mod);
    res%=mod;
    //cout<<res<<endl;
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 1152
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{

    class Program
    {

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int[] p = new int[n];
            int max = -1;
            int maxind = 1;

            for(int i = 0; i < n; i++)
            {
                p[i] = int.Parse(Console.ReadLine());
                if(max < p[i])
                {
                    max = p[i];
                    maxind = i;
                }
            }

            int sum = 0;
            
            for(int i = 0; i < n; i++)
            {
                if(i == maxind)
                {
                    sum += p[i] / 2;
                }
                else
                {
                    sum += p[i];
                }

            }

            Console.WriteLine(sum);

        }
    }
}


Measured memory_bytes: 13140
#!/usr/bin/env python
# coding: utf-8

import sys

def P(k):
    return (k*(k-1))//2

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.child = [1 for _ in range(n)] # 自分も含めた子の数
        self.ans = (n*(n-1))//2

    def root(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry

    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return

        cx = self.child[rx]
        cy = self.child[ry]
        self.ans -= (P(cx+cy)-P(cx)-P(cy))
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.child[ry] += cx
            self.child[rx] = 0
        else:
            self.par[ry] = rx
            self.child[rx] += cy
            self.child[ry] = 0
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1


def main():
    N, M = list(map(int, sys.stdin.readline().split()))
    edges = []
    for _ in range(M):
        a, b = list(map(int, sys.stdin.readline().split()))
        edges.append((a-1, b-1))

    u = UnionFind(N)
    lans = []
    for e in edges[::-1]:
        lans.append(str(u.ans))
        u.unite(e[0], e[1])
        # print(e, u.ans, u.par, u.child)
    print("\n".join(lans[::-1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 32824
// 基本のinclude
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define invrep(i,n) for(int i = (int)(n); i > 0; i++)
using ll = long long;

int main() {
    int n, m;
    cin >> n >> m;
    ll h[n];
    rep(i, n) cin >> h[i];
    int a[m], b[m];
    rep(i, m) cin >> a[i] >> b[i];

    int good[n];
    rep(i, n) good[i] = 1;

    rep(i, m) {
        if (h[a[i]-1] - h[b[i]-1] <= 0) good[a[i]-1] = 0;
        if (h[b[i]-1] - h[a[i]-1] <= 0) good[b[i]-1] = 0;
    }

    int ans = 0;
    rep(i, n) ans += good[i];

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

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define repo(i,o,n) for(int i=o;i<(int)(n);i++)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,k,a,b;
vector<pair<int,int>> v;

main() {
    cin >> n >> k;
    rep(i,n) cin >> a >> b,v.pb(make_pair(a,b));
    sort(all(v));
    rep(i,n) {
        if (v[i].se < k) k-=v[i].se;
        else {cout << v[i].fi << endl;return 0;}
    }
}



Measured memory_bytes: 2420
#include<stdio.h>
 
int main(void){
 
int n,k,i,j; 
int key;
int a[1100];
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(j=1;j<=n;j++){
key = a[j];
i = j-1;
while(i>0 && a[i]>key){
a[i+1]=a[i];
i = i-1;
}
a[i+1] = key;
for(k=1;k<=n;k++){
if(k==n){
printf("%d\n",a[k]);
}
else{
printf("%d ",a[k]);
}
}
}
return 0;
}

Measured memory_bytes: 2720
#include<bits/stdc++.h>
using namespace std;
long long h,n;
int main(){
	cin>>h;
	n=1;
	long long res=0LL;
	while(h){
		res+=n;
		n*=2;
		h/=2;
	}
	cout<<res<<endl;
	return 0;
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {

            Solve();

            //Console.WriteLine(ans);
            Console.ReadKey();
        }

        static void Solve()
        {
            var N = GetInt();
            var a = GetIntArray().OrderByDescending(o => o).ToArray() ;
            var A = 0;
            var B = 0;
            for(int i = 0; i < N; i++)
            {
                if (i % 2 == 0)
                {
                    A += a[i];
                }
                else
                {
                    B += a[i];
                }
            }
            var ans = A - B;

            Console.WriteLine(ans); 
        }




        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

Measured memory_bytes: 13396
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    string ans;
    for (int i = 0; i < 9; i++) {
        char a;
        cin >> a;
        if (i == 0 || i == 4 || i == 8)ans += a;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
INF = float('inf')
TOWN_NUM = 10

while True:
    way_num = int(input())
    if way_num == 0:
        break

    table = [[INF for i in range(TOWN_NUM)] for j in range(TOWN_NUM)]

    for _ in range(way_num):
        a,b,c = [int(i) for i in input().split()]
        table[a][b] = c
        table[b][a] = c

    for k in range(TOWN_NUM):
        for i in range(TOWN_NUM):
            for j in range(TOWN_NUM):
                if table[i][j] > table[i][k] + table[k][j]:
                    table[i][j] = table[i][k] + table[k][j]

    answer = INF
    answer_id = 0
    for i in range(TOWN_NUM):
        tmp = 0
        flag = False
        for j in range(TOWN_NUM):
            if table[i][j] < INF and i != j:
                tmp = tmp + table[i][j]
                flag = True
        if tmp < answer and flag:
            answer = tmp
            answer_id = i

    print(answer_id, answer)


Measured memory_bytes: 5620
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 998244353;

int countWhite(int** sum, int x, int y, int a, int b) {
	int rtv = sum[b - 1][a - 1];

	if (x != 0) rtv -= sum[b - 1][x - 1];
	if (y != 0) rtv -= sum[y - 1][a - 1];
	if (x != 0 && y != 0) rtv += sum[y - 1][x - 1];

	return rtv;
}

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

	int h, w, k;
	cin >> h >> w >> k;
	string* s = new string[h];
	rep(i, h) cin >> s[i];

	int** sum = new int*[h];
	rep(i, h) {
		sum[i] = new int[w];

		rep(j, w) {
			sum[i][j] = (s[i][j] == '1' ? 1 : 0);

			if (i != 0) sum[i][j] += sum[i - 1][j];
			if (j != 0) sum[i][j] += sum[i][j - 1];
			if (i != 0 && j != 0) sum[i][j] -= sum[i - 1][j - 1];
		}
	}

	int ans = MOD;
	rep(bitFlag, 1 << (h - 1)) {
		vector<int> t;
		t.push_back(0);
		rep(i, h - 1) {
			if (bitFlag & (1 << i)) t.push_back(i + 1);
		}
		t.push_back(h);

		int casei = t.size() - 2;

		int pre = 0;
		int ok = 0;
		bool flag = true;
		REP(i, 1, w + 1) {
			bool check = true;
			REP(j, 1, t.size()) {
				if (countWhite(sum, pre, t[j - 1], i, t[j]) > k) {
					check = false;
					break;
				}
			}

			if (check) {
				ok = i;
			}
			else {
				if (ok == pre) {
					flag = false;
					break;
				}

				pre = ok;
				++casei;
				--i;
			}
		}

		if (flag) ans = min(ans, casei);
	}

	cout << ans << "\n";

	return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    priority_queue<int,std::vector<int>,std::greater<int>> que;
    cin >> a >> b >> c;
    que.push(a);
    que.push(b);
    que.push(c);
    cout << que.top() << " ";
    que.pop();
    que.pop();
    cout << que.top() << endl;
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    std::ios::sync_with_stdio(false);
    long long int n,k,a,b,c,d=1e15;
    cin>>n>>k;
    int x[n];
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
    }
    for(int i=0;i+k-1<n;i++)
    {
        a=i;
        b=i+k-1;
        c=min(abs(x[a])+abs(x[a]-x[b]), abs(x[b])+abs(x[a]-x[b]));
        d=min(c,d);
    }
    cout<<d<<endl;
}


Measured memory_bytes: 640
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 99999999
#define N 300003
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int n;
int main(){
fcin;
	string s;
	cin>>s;
	int l = s.find('7');
	if(l!=-1) cout<<"Yes\n";
	else cout<<"No\n";
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    map<string , int> mp;

    mp["SUN"]=7;
    mp["MON"]=6;
    mp["TUE"]=5;
    mp["WED"]=4;
    mp["THU"]=3;
    mp["FRI"]=2;
    mp["SAT"]=1;
    cout<<mp[s]<<endl;
    return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), (c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	int H; cin >> H;
	int W; cin >> W;
	cout << (N - H + 1)*(N - W + 1) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Scanner;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while (true) {
			int n = Integer.parseInt(scan.nextLine());
			if (n == 0) {
				break;
			}
			String sTmp = scan.nextLine();
			int sum = 0;
			int[] s = new int[n];
 			for (int i = 0; i < n; i++) {
				s[i] = Integer.parseInt(sTmp.split(" ")[i]);
				sum += s[i];
			}
			double ave = (double)sum / (double)n;
			double dv = 0;
			for (int i = 0; i < n; i++) {
				dv += (ave - (double)s[i]) * (ave - (double)s[i]);
			}
			double res = Math.sqrt(dv / n);
			System.out.println(res);
		}
	}

}


Measured memory_bytes: 64944
#include <bits/stdc++.h>
#define pb push_back
#define sp " "
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define tra(a,b) for (auto a:b) 
#define fo(a,b,c) for (int a=b;a<=c;a++) 
#define ms(a,b) memset(a,b,sizeof(a)) 
#define all(a) a.begin(),a.end()
#define rev(a) reverse(a.begin(),a.end())
#define bit(i,j) (i&(1<<j))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef pair<int,ii> iii;

const int N=2e5+5,mod=998244353;
int n,m;	
int main()
{
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	cin>>n>>m;
	n=n*(n-1); m=m*(m-1);
	cout<<n/2+m/2;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n;
  cin >> n;
  int k = n / 1000;
  int ans = 1000 * (k + 1) - n;
  if(n % 1000 == 0){
    ans = 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 2e5+7, MOD = 1e9+7;
//need define int long long
int mod(int n) {
    n %= MOD;
    if (n < 0) return n + MOD;
    else return n;
}   
int fp(int a, int p) {
    int ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = mod(ans * c);
        c = mod(c * c);
    }   
    return ans;
}   
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }

struct M {
ll x;
M (int x_) {
    x = mod(x_);
}   
M () {
    x = 0;
}
M operator + (M y) {
    int ans = x + y.x;
    if (ans >= MOD)
        ans -= MOD;
    return M(ans);
}
M operator - (M y) {
    int ans = x - y.x;
    if (ans < 0)
        ans += MOD;
    return M(ans);            
}   
M operator * (M y) {
    return M(x * y.x % MOD);   
}   
M operator / (M y) {
    return M(x * fp(y.x, MOD - 2) % MOD);
}   
M operator + (int y) {
    return (*this) + M(y);
}
M operator - (int y) {
    return (*this) - M(y);
}   
M operator * (int y) {
    return (*this) * M(y);
}   
M operator / (int y) {
    return (*this) / M(y);
}   
M operator ^ (int p) {
    return M(fp(x, p));
}   
void operator += (M y) {
    *this = *this + y;
}   
void operator -= (M y) {
    *this = *this - y;
}   
void operator *= (M y) {
    *this = *this * y;
}
void operator /= (M y) {
    *this = *this / y;
}   
void operator += (int y) {
    *this = *this + y;
}   
void operator -= (int y) {
    *this = *this - y;
}   
void operator *= (int y) {
    *this = *this * y;
}
void operator /= (int y) {
    *this = *this / y;
}   
void operator ^= (int p) {
    *this = *this ^ p;
}
};  

M f[N], inv[N];
void prec() {
    f[0] = M(1);
    for (int i = 1; i < N; ++i)
        f[i] = f[i - 1] * M(i);
    inv[N - 1] = f[N - 1] ^ (MOD - 2);
    for (int i = N - 2; i >= 0; --i)
        inv[i] = inv[i + 1] * M(i + 1);
}
M C(int n, int k) {
    if (n < k)
        return M(0);
    else
        return f[n] * inv[k] * inv[n - k];
}   


signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20); 
    #endif

    prec();

    int h, w, a, b;
    cin >> h >> w >> a >> b;

    M ans = C(w + h - 2, w - 1);

    int x = h - a;
    for (int y = 0; y < b; ++y) {
        int x1 = h - 1 - x;
        int y1 = w - 1 - y;
        ans -= C((x - 1) + y, x - 1) * C(x1 + y1, x1);
    }   

    cout << ans.x << endl;
}


Measured memory_bytes: 6708
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n,x;
	int a[105],d[105];
	cin>>n>>x;
	cin>>a[0];
	for(int i=1;i<n;i++){
		cin>>a[i];
	}
	d[0]=0;
	for(int i=1;i<=n;i++){
		d[i]=a[i-1]+d[i-1];
	}
	int cnt=0;
	for(int i=0;i<=n;i++){
		if(d[i]<=x){
			cnt++;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    p = list(map(int, input().split()))
    ans = 0
    for i in range(n-2):
        if p[i+1] != min(p[i:i+3]) and p[i+1] != max(p[i:i+3]):
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

int N,A,B,H[101010];

bool check(ll x){
    ll c=0;
    for(int i=0;i<N;i++){
        ll h=1LL*H[i]-1LL*x*B;
        if(h<=0) continue;
        c+=h/A;
        if(h%A) c++;
    }
    return c<=x;
}

int main() {
    cin>>N>>A>>B;
    A-=B;
    for(int i=0;i<N;i++) cin>>H[i];
    
    int ng=0,ok=1010101010;
    while(ng+1!=ok){
        int x=(ng+ok)/2;
        if(check(x)) ok=x;
        else ng=x;
    }
    cout<<ok<<endl;
}

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

int main(){
int b,c;
int d;
int w,n;
int a[30];
for(int i=0;i<30;i++){
a[i]=i+1;
}
cin>>w;
cin>>n;
for(int i=0;i<n;i++){
scanf("%d,%d",&b,&c);
d=a[b-1];
a[b-1]=a[c-1];
a[c-1]=d;
}
for(int i=0;i<w;i++){
cout<<a[i]<<endl;
}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
long long dp[200004];
int c[200004];
int main(){
	int n;
	const int mod=1e9+7;
	scanf("%d",&n);
	for(int i=0;i<n;++i)
		scanf("%d",&c[i]);
	dp[c[n-1]]=1;
	for(int i=n-1;i>=0;--i){
		if(i && c[i-1]==c[i])
			continue;
		dp[c[i-1]]=(dp[c[i-1]]+dp[c[i]])%mod;
	}
	printf("%lld\n",dp[c[0]]);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
constexpr int INF = 1 << 30;
constexpr int MOD = 1e9 + 7;

int n, a[100010], cnt[100010];

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> n;
  for(int i = 0; i < n; ++i) cin >> a[i];

  for(int i = 1; i < n; ++i) 
    if(a[i-1] >= a[i]) cnt[i] = cnt[i-1] + 1;

  int ans = 0;
  for(int i = 0; i < n; ++i) ans = max(ans, cnt[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数
char s[100001];
int a[100001];

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

ll ans = 0;
void dfs(int i, int c) {

}

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

	scanf("%s", s);
	REP(i, n) {
		if (s[i] == 'A') {
			if (s[i + 1] == 'C')a[i+1]++;
		}
		a[i + 2] = a[i+1];
	}

	REP(i, q) {
		int l, r;
		scanf("%d%d", &l, &r);
		PRINTD(a[r - 1] - a[l - 1]);
	}
}

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

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

  map<ll, ll> m;
  rep(i,0,N-1) {
    ll A, B;
    cin >> A >> B;
    m[B] += A;
  }

  ll num = 0; string ans = "Yes";
  for (pair<int,int> p : m) {
    num += p.second;
    if (p.first < num) ans = "No";
  }

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


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


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

	ll N,sum=0,sunuke=0,ans=INF;
	cin >> N;
	vector<ll> a(N);
	FOR(i,0,N){
		cin >> a[i];
		sum += a[i];
	}
	FOR(i,0,N-1){
		sunuke += a[i];
		ans = min(ans,abs(sum-sunuke*2));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
n = gets.to_i
a = Array.new(n)
(0..(n-1)).each do |i|
  a[i] = gets.to_i
end

b = a

if n == 2
  a = a.sort
  p a[1]-a[0]
elsif n == 3
  a = a.sort
  p [(a[2]*2-a[0]-a[1]), (a[2]+a[1]-a[0]*2)].max
else

  if a.length.odd?
    a = a.sort!.each_slice(a.length / 2 + 1).to_a
  else
    a = a.sort!.each_slice(a.length / 2).to_a
  end

  a1 = a[0]
  a2 = a[1].sort! {|x,y| y<=>x}

  sum = 0
  l = a1.length
  if n.odd?
    (0..l-1).each do |i|
      if i == 0
        sum += (a2[0] + a2[1] - a1[0]*2)
      elsif i == (l-1) || i == (l-2)
        sum += (a2[i-1] - a1[i])
      else
        sum += (a2[i+1] + a2[i-1] - a1[i]*2)
      end
    end
  else
    (0..l-1).each do |i|
      if i == 0
        sum += (a2[0] + a2[1] - a1[0]*2)
      elsif i == (l-1)
        sum += (a2[i-1] - a1[i])
      else
        sum += (a2[i+1] + a2[i-1] - a1[i]*2)
      end
    end
  end



  if n.odd?
    a = b.sort! {|x,y| y<=>x}
    a = a.each_slice(a.length / 2 + 1).to_a
    a1 = a[0]
    a2 = a[1].sort! {|x,y| y<=>x}
    sum1 = 0
    (0..l-1).each do |i|
      if i == 0
        sum1 += (a2[0] + a2[1] - a1[0]*2)
      elsif i == (l-1) || i == (l-2)
        sum1 += (a2[i-1] - a1[i])
      else
        sum1 += (a2[i+1] + a2[i-1] - a1[i]*2)
      end
    end
    sum1 = sum1 * (-1)
    sum = [sum, sum1].max

  end

    p sum

end


Measured memory_bytes: 4880
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const int MAXS = 114514;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n;
    cin>>n;
    int f = 0,t=0,o=0;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        if(k%4==0)f++;
        else if(k%2==0)t++;
        else o++;
    }
    if(t==0){
        if(f>=o-1)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else{
        if(f>=o)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=1<<30;
int  ans;
int  dp[10005];
int  v[10005],w[10005];
int main(){
	int h,n;
	cin>>h>>n;
	for(int i=1;i<=n;i++){
		cin>>v[i]>>w[i];
	}
	for(int i=0;i<=h;i++) dp[i]=inf;
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=h;j++){
			if(j>=v[i]) dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
			else dp[j]= min(dp[j],w[i]);
		}
	}
//	for(int i=0;i<=h;i++)
	cout<<dp[h]<<endl;
	return 0;
}

Measured memory_bytes: 384
N = int(input())
L = []
for i in range(N - 1):
	a = list(str(i + 1))
	b = list(str(N - i - 1))
	asum = sum(list(map(int, a)))
	bsum = sum(list(map(int, b)))
	
	L.append(asum + bsum)
print(min(L))

Measured memory_bytes: 3972
#include<iostream>
using namespace std;
int bubbleSort(int a[],int n)
{
    int flag=1,i,temp,c=0;
    while(flag)
    {
        flag=0;
        for(i=n-1;i>=1;i--)
        {
            if(a[i]<a[i-1])
            {
                temp=a[i];
                a[i]=a[i-1];
                a[i-1]=temp;
                c++;
                flag=1;
            }
        }
    }
    return c;
}
int main()
{
    int N,A[101];
    cin>>N;
    for(int i=0;i<N;i++)
    {
        cin>>A[i];
    }
    int num=bubbleSort(A,N);
    for(int i=0;i<N;i++)
    {
        if(i>0)
            cout<<" ";
        cout<<A[i];
    }
    cout<<endl<<num<<endl;

    return 0;
}



Measured memory_bytes: 3112
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[0]
y=[0]
for i in range(n):
    x.append(x[i]+a[i])
for i in range(m):
    y.append(y[i]+b[i])
count=0
j=m
for i in range(n+1):
    if x[i]>k:
        break
    while y[j]>k-x[i]:
        j-=1
    count=max(count,i+j)
print(count)


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

using namespace std;

#define ff first
#define ss second
#define mp make_pair
#define sz size()
#define pb push_back
using ll = long long;
using pii = pair<int, int>;

const int N = 2e5 + 5;
ll A[N];

int main() {


  ll k, n;
  cin >> k >> n;
  ll x = 0LL;

  for(int i = 0; i < n; i++){
    cin >> A[i];
    if(i)x = max(x, A[i] - A[i - 1]);
  }
  x = max(x,  A[0] - A[n - 1] + k);
  cout << k - x << endl;


  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	cin >> N;
	ll ans = 1;
	for (int i = 1; i <= N; i++) {
		ans = ans * i % mod;
	}
	cout << ans << endl;
}

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

int main() {
    int a, b;
    int cnt;
    while (cin >> a >> b) {
        cnt=0;
        a+=b;
        while (a>0) {
            a/=10;
            cnt++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 3100
import kotlin.math.abs
import kotlin.math.min

fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    val n = readLine()?.toInt() ?: return
    val a = longList()
    val aa = 0.until(n).map {
        a[it] - (it + 1)
    }.sorted()
    if (n % 2 == 1) {
        val b = aa[n / 2]
        var sum1 = 0L
        0.until(n).forEach {
            sum1 += abs(a[it] - (it + 1 + b))
        }
        println(sum1.toString())
    } else {
        val b = aa[n / 2]
        val c = aa[n / 2 - 1]
        var sum1 = 0L
        var sum2 = 0L
        0.until(n).forEach {
            sum1 += abs(a[it] - (it + 1 + b))
            sum2 += abs(a[it] - (it + 1 + c))
        }
        println(min(sum1, sum2).toString())
    }
}

Measured memory_bytes: 77424
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    // Here your code !
    int n;
    int s[1000];
    double m, a;
    cin >> n;
    do {
        for(int i=0;i<n;i++) {
            cin >> s[i];
        }
        m = 0;
        for(int i=0;i<n;i++) {
            m = m + s[i];
        }
        m = m / n;
        a = 0;
        for(int i=0;i<n;i++) {
            a = a + pow(s[i] - m, 2);
        }
        a = sqrt(a / n);
        cout << fixed
             << setprecision(5)
             << a << endl;
        cin >> n;
    } while(n != 0);
    
}

Measured memory_bytes: 3236
//NAME-ADITYYA OJHA
                                               /*
                                                      GURU(MENTOR)-AARADHYA
                                               */
/*
 *     Heart beats fast
 *         Colors and promises
 *             How to be brave
 *                 How can I love when I am afraid to fall...
                                             (courtesy-amnesiac_dusk)
 */

#include <bits/stdc++.h>
#define ll long long int
#define forin for(int i=0;i<n;i++)
#define pb push_back
#define vx vector<ll> x
#define vy  vector<ll> y
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  f   first
#define  s   second
#define mod 1000000007
using namespace std;

/*
check for corner cases(for n==1)
 check for int overflow
 run on some sample cases before submitting
*/

/*FERMAT THEOREM

       pow(x,m-1)%m=1 (x and m are co-prime)
*/
/*MODULAR INVERSE

        pow(x,-1)=pow(x,m-2) (x and m are co-prime)
*/

/*
ll  mode(ll x,ll n,ll mod)
{
    if(n==0)return 1%mod;

    ll u=mode(x,n/2,mod);
    u=(u*u)%mod;
    if(n & 1)u=(u*x)%mod;
}
*/
ll k=1;
ll divSum(ll n)
{
    ll sum = 0;
    for (ll i = 1; i <= n; ++i) {
           ll z=n/i;
           sum+=(z)*(z+1)/2 * i;



    }
    return sum;
}

int main()
{
   ll n;
   cin>>n;
   ll ans=divSum(n);
   cout<<ans<<endl;
}


Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <regex>
#include <vector>
#include <map>

using namespace std;

string str;
int array_size[58] = {};
map<int, int> values[58];
regex re_left(R"((.)\[([^=]+)\](.*))");
regex re_right(R"(=(.+))");

int valueOf(string s) {
    smatch m;
    if (regex_match(s, m, re_left)) {
        int array_name = (int)(m[1].str()[0]-'A');
        int index = valueOf(m[2].str());
        if (array_size[array_name] <= index) return -1;
        else {
            auto it = values[array_name].find(index);
            if (it != values[array_name].end()) return it->second;
            else return -1;
        }
    } else {
        return stoi(s);
    }
}

int main() {
    cin>>str;
    while (str[0] != '.') {
        vector<string> program;
        for (int i = 0; i < 58; i++) {
            array_size[i] = 0;
            values[i].clear();
        }
        while (str[0] != '.') {
            program.push_back(str);
            cin>>str;
        }

        smatch match;
        for (int l = 0; l < program.size(); l++) {
            if (regex_match(program[l], match, re_left)) {
                int array_name = (int)(match[1].str()[0]-'A');
                int index = valueOf(match[2].str());
                string right = match[3].str();
                if (right.empty()) array_size[array_name] = index;
                else {
                    if (array_size[array_name] <= index) {
                        cout<<l+1<<endl;
                        break;
                    } else if (regex_match(right, match, re_right)) {
                        int value = valueOf(match[1]);
                        if (value == -1) {
                            cout<<l+1<<endl;
                            break;
                        } else values[array_name][index] = value;
                    }
                }
            }
            if (l == program.size()-1) cout<<"0"<<endl;
        }
        cin>>str;
    }
}

Measured memory_bytes: 3372
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		Deque<String> deque = new ArrayDeque<>();
		deque.addFirst(str);
		int Q = Integer.parseInt(sc.next());
		String[][] s = new String[Q][3];
		for(int i = 0; i < Q; i++) {
			s[i][0] = sc.next();
			if(s[i][0].equals("1")) {
				s[i][1] = "0";
				s[i][2] = "0";
			} else {
				s[i][1] = sc.next();
				s[i][2] = sc.next();
			}
		}
		
		boolean order = true;
		
		for(int i = 0; i < Q; i++) {
			if(s[i][0].equals("1")) {
				order = !order;
			} else {
				boolean temp = order;
				if(s[i][1].equals("1")) {
					temp = !order;
				}
				if(temp) {
					deque.addLast(s[i][2]);
				} else {
					deque.addFirst(s[i][2]);
				}
			}
		}
		StringBuilder S = new StringBuilder("");
		int N = deque.size();
		for(int i = 0; i < N; i++) {
			S.append(deque.pollFirst());
		}
		if(order) {
			System.out.println(S);
		} else {
			System.out.println(S.reverse());
		}
	}
}


Measured memory_bytes: 124404
#include<bits/stdc++.h>
using namespace std;
using lint = long long;

signed main(){
  lint N; cin >> N;
  vector<lint> num(N);
  for(lint i = 1; i < N; i++){
    lint x; cin >> x;
    num[x - 1]++;
  }
  for(lint i = 0; i < N; i++) cout << num[i] << endl;
}

Measured memory_bytes: 4844
#include <iostream>

using namespace std;

int main() {
    int N, Z, W;
    cin >> N >> Z >> W;

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

    if (N == 1) {
        cout << abs(a[N-1]-W) << endl;
    }else{
        cout << max(abs(a[N-1]-W), abs(a[N-1]-a[N-2])) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
int main(){
	int N; 
	int K; 
	cin >> N >> K; 
	int dp[100010] = {}; // 0 は後手，1は先手
	int A[110] = {}; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
	}
	for(int i = 1; i <= K; i++){
		int s = upper_bound(A, A+N, i) - A; 
		for(int j = 0; j < s; j++){
			if(dp[i - A[j]] == 0){
				dp[i] = 1;
			}
		}
	}
	if(dp[K] == 0){cout << "Second" << endl;}
	else{cout << "First" << endl;}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


int main() {
    int n;
    cin >> n;
    int x[n][2];
    rep(i,n){
        cin >> x[i][0] >> x[i][1];
    }

    if(n==1){
        cout << '1' << endl;
        return 0;
    }

    vector<P> v;

    rep(i,n){
        rep(j,n){
            if(i!=j){
                v.push_back(P(x[i][0]-x[j][0],x[i][1]-x[j][1]));
            }
        }
    }
    sort(v.begin(),v.end());

    int count = 0;
    rep(i,v.size()){
        P p = v[i];
        int tmp = upper_bound(v.begin(),v.end(), p) - lower_bound(v.begin(),v.end(), p);
        count = max(count,tmp);
    }

    /*
    int count = 0;
    int a,b;
    a = v[0].first;
    b = v[0].second;
    int tmp = 1;
    srep(i,1,v.size()){
        if(v[i].first==a&&v[i].second==b){
            tmp++;
        }else{
            count = max(count,tmp);
            a = v[i].first;
            b = v[i].second;
            tmp = 1;
        }
    }
    count = max(count,tmp);
     */

    int ans = n-count;

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


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;
using namespace std;

int main() {
 
   int N,M;
   cin >> N >> M;
   int *p = new int[M]();
   int *s = new int[M]();

   int toi;
   string ttt;
   for(int i=0;i<M;i++){
      cin >> toi >> ttt;
      p[i]=toi-1;
      if(ttt=="WA")s[i]=0;
      if(ttt=="AC")s[i]=1;
      //cout << p[i] << " " << s[i]<< " " << ttt << endl;
   }

   int *ac = new int[N]();
   int *wa = new int[N]();
   for(int i=0;i<M;i++){
      if(ac[p[i]]==0 && s[i]==0){
         wa[p[i]]+=1;
      }else if(ac[p[i]]==0 && s[i]==1){
         ac[p[i]]=1;
      }
   }
   int sei=0;
   int pen=0;
   for(int i=0;i<N;i++){
      //cout << i<< " " <<ac[i] << " " << wa[i] << endl;
      sei += (ac[i]==1?1:0);
      pen += (ac[i]>0?wa[i]:0);
   }
   cout << sei <<" " << pen << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,K,p,q,count=0;cin>>N>>K;
  vector<long> a(100000);
  for(int i=0;i<N;i++){
    cin>>p>>q;
    a.at(p-1)+=q;
  }
  for(int i=0;i<100000;i++){
    count+=a.at(i);
    if(count>=K){
      cout<<i+1<<endl;
      break;
    }
  }
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC052_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] abcd = Console.ReadLine().Split(' ');
            int a = int.Parse(abcd[0]);
            int b = int.Parse(abcd[1]);
            int c = int.Parse(abcd[2]);
            int d = int.Parse(abcd[3]);

            Console.WriteLine(Math.Max(a * b, c * d));
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll mod=(int)1e9+7;

int main()
{
	ios;
	int x,y;
	cin>>x>>y;
//	if(2*x==y || 4*x==y) cout<<"Yes\n";
//	else if((4*x-y)>0 && (4*x-y)%2==0) cout<<"Yes\n";
	if(y%2==0 && y>=2*x && y<=4*x) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3600
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    char list[] = new char[200];
    char sub[] = new char[200];
    String L;
    int N,i,j,h;

    while(true){

      L = scanner.next();

      if(L.equals("-")){
        break;
      }

      for(i=0;i<L.length();i++){
        list[i] = L.charAt(i);
      }

      N = scanner.nextInt();

      for(i=0;i<N;i++){
        h = scanner.nextInt();

        for(j=0;j<L.length();j++){
          sub[j] = list[j];
        }

        for(j=h;j<L.length();j++){
          list[j-h] = sub[j];
        }

        for(j=0;j<h;j++){
          list[j+L.length()-h] = sub[j];
        }

      }

      for(i=0;i<L.length();i++){
        System.out.print(list[i]);
      }

      System.out.print("\n");
    }
  }
}



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

int get_largest_rec(const int w, int dp[]){
	stack<P> rs;
	int maxa = 0;
	dp[w] = 0;

	rep(i, w+1){
		P rect = make_pair(i, dp[i]);
		if(rs.empty()) rs.push(rect);
		else {
			if(rs.top().second < rect.second) rs.push(rect);
			else if(rs.top().second > rect.second) {
				int t = i;
				while(rs.size() && rs.top().second >= rect.second){
					P pre = rs.top(); rs.pop();
					int area = pre.second*(i - pre.first);
					maxa = max(maxa, area);
					t = pre.first;
				}
				rect.first = t;
				rs.push(rect);
			}
		}
	}
	return maxa;
}

int main(){
	int h, w; cin >> h >> w;
	bool t[h][w];
	rep(i, h)rep(j, w) {
		bool b; cin >> b;
		t[i][j] = b;
	}

	int dp[h+1][w+1];
	rep(j, w)rep(i, h){
		if(t[i][j]) dp[i][j] = 0;
		else dp[i][j] = (i > 0) ? dp[i-1][j] + 1 : 1;
	}

	int ans = 0;
	rep(i, h) ans = max(ans, get_largest_rec(w, dp[i]));

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



Measured memory_bytes: 12688
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    rep (i, n) cin >> l[i];

    sort(rrng(l));

    ll ans = 0;
    rep (i, k) ans += l[i];

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


Measured memory_bytes: 256