akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int a = 0;
		int b = 0;
		for (int i = n - 1; i >= 0; i -= 2) {
			a += arr[i];
			if (i > 0) {
				b += arr[i - 1];
			}
		}
		System.out.println(a - b);
	}
}


Measured memory_bytes: 21844
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		int H = scanner.nextInt();
		int W = scanner.nextInt();
		int h = scanner.nextInt();
		int w = scanner.nextInt();
		
		System.out.println((H-h) * (W-w) );
		scanner.close();
	}

}


Measured memory_bytes: 27092
#include <bits/stdc++.h>
#include<set>
#include <algorithm>
#define ll long long 
#include <string.h>
using namespace std;

int main()
{
	ll int k,a,b;
	cin>>k>>a>>b;
	ll int i;
	for(i=a;i<=b;i++)
	{
		if ((i%k==0))
		{
		cout<<"OK"<<endl;
		return 0;
	}
	}
	cout<<"NG"<<endl;
	
	
} 




Measured memory_bytes: 3584
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x = N * 800;
		int y = (N / 15) * 200;
		int s = x - y;
		System.out.print(s);
	}
}

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

int main() {
  int n,k; cin>>n>>k;
  int an[n]; rep(i,n) cin >> an[i];
  rep(i, n-k) {
    if (an[i] < an[i+k]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}


Measured memory_bytes: 4360
from copy import deepcopy

N = int(input())
T = list(map(int, input().split()))
M = int(input())
P, X = [], []
for _ in range(M):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)

for i in range(M):
    ans = deepcopy(T)
    ans[P[i] - 1] = X[i]
    print(sum(ans))


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define pii pair<ll,ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(ll i=a;i<=(ll)b;++i)
#define per(i,a,b) for(ll i=a;i>=(ll)b;--i)
#define ll long long
#define lowbit(x) ((x)&(-x))

char s[14][1010];
int belong[12],cnt[12];
int main()
{
    IOS
    int n,m,mx;cin>>n>>m>>mx;
    rep(i,1,n) rep(j,1,m) cin>>s[i][j];
    int mask=(1<<n)-1;
    int ans=1e9;
    rep(i,0,mask)
    {
        int bg=1,tem=0;
        rep(j,0,n-1)
        {
            if((1<<j)&i) belong[j+1]=bg++;
            else belong[j+1]=bg;
        }
        memset(cnt,0,sizeof(cnt));

        rep(j,1,m)
        {
            rep(k,1,n) if(s[k][j]=='1') cnt[belong[k]]++;
            bool ok=false,flag=false;
            rep(k,1,bg) if(cnt[k]>mx) ok=true;
            if(ok)
            {
                tem++;
                rep(k,1,n) if(s[k][j]=='1') cnt[belong[k]]--;
                rep(k,1,bg) if(cnt[k]>mx) flag=true;
            }
            else continue;

            if(flag)
            {
                tem=1e9;
                break;
            }
            else
            {
                memset(cnt,0,sizeof(cnt));
                rep(k,1,n) if(s[k][j]=='1') cnt[belong[k]]++;
            }
        }
       // cout<<tem<<endl;
        ans=min(ans,tem+__builtin_popcount(i));
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int a1 = sc.nextInt();
	int a2 = sc.nextInt();
	int a3 = sc.nextInt();
	int b1 = (int)(Math.abs(a1-a2));
	int b2 = (int)(Math.abs(a3-a2));
	int b3 = (int)(Math.abs(a1-a3));
	int max = Math.max(b1,Math.max(b2,b3));
	System.out.println(b1+b2+b3-max);

    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
void display()
{
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    puts(abs(a-c) <= d || abs(a-b) <= d && abs(b-c) <=d ? "Yes": "No");
}
int main(void)
{
    display();
}

Measured memory_bytes: 3600
/*
      author : nishi5451
      created: 11.08.2020 23:06:34
*/

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


int main(){
    int n;
    cin >> n;
    if(n%2) cout << n/2+1 << endl;
    else cout << n/2 << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  ll A,B;
  cin >> N >> A >> B;
  ll x[N];
  for(int i=0;i<N;i++) cin >> x[i];

  ll ans = 0LL;
  for(int i=0;i<N-1;i++){
    ll dist = x[i+1] - x[i];
    ans += min(dist*A , B);
  }

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

Measured memory_bytes: 1024
#include <stdio.h>
 
struct DICE {
int d1,d2,d3,d4,d5,d6;
};
 
void MoveDice(struct DICE *p,char c);
 
int main(){
struct DICE p;char compass;struct DICE *pp;
scanf("%d %d %d %d %d %d\n",&p.d1,&p.d2,&p.d3,&p.d4,&p.d5,&p.d6);
scanf("%c", &compass);
while(compass!='\n'){
MoveDice(&p,compass);
scanf("%c", &compass);
}
printf("%d\n",p.d1);
return 0;
}
 
void MoveDice(struct DICE *p,char c){
int tmp;
tmp=p->d1;
switch(c){
case 'W':
p->d1=p->d3;p->d3=p->d6;p->d6=p->d4;p->d4=tmp;
break;
case 'E':
p->d1=p->d4;p->d4=p->d6;p->d6=p->d3;p->d3=tmp;
break;
case 'N':
p->d1=p->d2;p->d2=p->d6;p->d6=p->d5;p->d5=tmp;
break;
case 'S':
p->d1=p->d5;p->d5=p->d6;p->d6=p->d2;p->d2=tmp;
break;
}
}


Measured memory_bytes: 2132
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
n = str(n)
res = 0
for elem in n:
    res += int(elem)
if res % 9 == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9352
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	bool f = 0;
	for (int i = 1; i < b; i++)if ((i*a) % b == c)f = 1;
	if (f)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define ff              first
#define ss              second
#define SZ(x)           ((int)(x).size())
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main() {
    cpp();
    ll k;
    cin>>k;
    string s;
    cin>>s;
    if(s.size()<=k){
        cout<<s<<endl;
    }
    else{
        string temp = string(s.begin(), s.begin()+k);
        temp+="...";
        cout<<temp<<endl;
    }
    return 0;
}

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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

ll dis[10000000];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);



	ll k,n;
	cin>>k>>n;

	ll tmp;
	for(int i=0; i<n; i++){
		cin>>tmp;
		dis[i] =tmp;
	}
	dis[n]=k+dis[0];

	ll ans=0;
	ll max =0;
	for(int i=0; i<n; i++){
		ans +=dis[i+1] -dis[i];

		if(dis[i+1] -dis[i] >max){
			max =dis[i+1] -dis[i];
		}
	}
	cout<<ans-max<<endl;


}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int h,w;
int s[20][20];

int main(){
  while(1){
    cin>>h>>w;
    if(h==0)break;
    rep(i,h)rep(j,w){
      cin>>s[i][j];
    }
    int res=0;
    rep(a,h)rep(b,w)rep(c,h)rep(d,w){
      if(c-a<2||d-b<2)continue;
      int sh=100;
      int nh=0;
      int mn=100;
      repl(i,a,c+1)repl(j,b,d+1){
        if(i==a||i==c||j==b||j==d)minch(sh,s[i][j]);
        else maxch(nh,s[i][j]);
      }
      if(sh<=nh)continue;
      int sum=0;
      repl(i,a,c+1)repl(j,b,d+1){
        if(i==a||i==c||j==b||j==d)continue;
        sum+=(sh-s[i][j]);
      }
      maxch(res,sum);
    }
    cout<<res<<endl;
  }
  return 0;
}



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

/*
// ordered_set 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
 
using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ld, ld>                                    pll;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define Sort(x)                                         sort(all(x))
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

//const ll md = 1e9 + 7;//998244353;
const int xn = 1e5 + 10;
const int xm = -20 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int Md = 998244353;
const int TM = 3;
const int Base = 257;

string s, ans;

int main(){
    InTheNameOfGod;
    
    cin >> s;
    for (char c : s){
    	if (c == '?') ans += 'D';
    	else ans += c;
	}
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N ;
  	cin >> N;
  
  	int an = N / 2;
  
  	if ( N % 2 == 1){
    	cout << an + 1 << endl;
    }else{
    	cout << an << endl;
    }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }
template<typename V> void printVec(V v) {ll i=0;for(auto x : v){std::cout << " [" << i++ << "] " << x;} print();}
template<typename V> void printVP(V v) {ll i=0;for(auto x : v){std::cout << " [" << i++ << "] " << x.second;} print();}
int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N, K;
  std::cin >> N >> K;
  std::string S;
  std::cin >> S;
  N = S.size();

  std::vector< std::pair<ll, ll> > vp;
  char state = S[0];
  ll NN = 0LL;
  ll cnt = 0LL;
  for (ll i = 0; i < N; i++) {
    //print(S[i], state, cnt);
    if (state == S[i]) {
      cnt++;
      continue;
    }
    if (state != S[i]) {
      if (state == '0') {
	vp.push_back(std::make_pair(0, cnt));
	NN++;
      } else {
	vp.push_back(std::make_pair(1, cnt));
      }
      state = state == '0' ? '1' : '0';
      cnt = 1;
    }
  }
  if (state == '0') {
    vp.push_back(std::make_pair(0, cnt));
    vp.push_back(std::make_pair(1, 0));
    NN++;
  } else {
    vp.push_back(std::make_pair(1, cnt));
    vp.push_back(std::make_pair(0, 0));
  }

  //printVP(vp);

  if (K >= NN) {
    ll ans = N;
    print(ans);
    return 0;
  }

  ll ans = 0LL;

  // oxoxox...o
  // oxoxox...x
  if (vp[0].first == 1) {
    ll num = vp[0].second;
    for (ll i = 0; i < K; i++) {
      num += vp[2 * i + 1].second + vp[2 * i + 2].second;
    }
    ans = std::max(ans, num);

    for (ll i = K; i < NN; i++) {
      num += vp[2 * i + 1].second + vp[2 * i + 2].second;
      num -= vp[2 * (i-K)].second + vp[2 * (i-K) + 1].second;
      //print(2 * i + 1, 2 * i + 2, 2 * (i-K), 2 * (i-K) + 1);
      //print("num", num);
      ans = std::max(ans, num);
    }
    //print("ans", ans);
  }

  // xoxoxox...o 先頭のxをoにする
  if (vp[0].first == 0) {
    ll num = 0LL;
    for (ll i = 0; i < K; i++) {
      num += vp[2 * i].second + vp[2 * i + 1].second;
    }
    //print("num2", num);
    ans = std::max(ans, num);
  }

  if (vp[1].first == 1) {
    ll num = vp[1].second;
    for (ll i = 0; i < K; i++) {
      num += vp[2 * i + 2].second + vp[2 * i + 3].second;
    }
    //print("num3", num);
    ans = std::max(ans, num);

    for (ll i = K; i < NN-1; i++) {
      num += vp[2 * i + 2].second + vp[2 * i + 3].second;
      num -= vp[2 * (i-K)+1].second + vp[2 * (i-K) + 2].second;
      //print(2 * i + 1, 2 * i + 2, 2 * (i-K), 2 * (i-K) + 1);
      //print("num3", num);
      ans = std::max(ans, num);
    }
    //print("ans", ans);
  }

  print(ans);
  return 0;
}


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

using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		int p;
		vector<int> j(n - 1);
		long long sum = 0;
		for (int i = 0; i < n; ++i) cin >> p, sum += p;
		for (int i = 0; i < n - 1; ++i) cin >> j[i];
		sort(j.begin(), j.end(), greater<int>());
		long long ans = sum * n;
		for (int i = 0; i < n - 1; ++i) {
			sum += j[i];
			ans = max(ans, sum * (n - i - 1));
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3264
def nextLunlun(l):
  l[-1]+=1
  for i in range(len(l)-1):
    if abs(l[-i-1]-l[-i-2])>=2 or l[-i-1]==10:
      l[-i-2]+=1
      l[-i-1]=0

  if l[0]>=10:
    l.insert(0,1)
    l[1]=0
    
  for i in range(len(l)-1):
    if abs(l[i]-l[i+1])>=2:
      l[i+1]=max(0,l[i]-1)
  
  return l

l=[0]
n=int(input())

for i in range(n):
  nextLunlun(l)
for num in l:
  print(num,end='')
print()

Measured memory_bytes: 9224
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long x, k, d;
    cin >> x >> k >> d;
    if (x == 0)
    {
        if (k % 2) {
            cout << x + d;
        }
        else
            cout << x;
        return 0;
    }
    if (x > 0)
    {
        long long dif = x;
        long long req = dif / d;
        if (req >= k) {
            cout << x - k*d;
        }
        else
        {
            x -= req * d;
            k -= req;
            if (1) {
                if (k % 2 == 0) {
                    cout << x;
                }
                else
                    cout << abs(x - d);
                return 0;
            }
        }
    }
    else
    {
        long long req = (abs(x)) / d;
        if (req >= k) {
            cout << abs(x + k * d);
        }
        else {
            x += req * d;
            k -= req;
            if (k % 2 == 0) {
                cout << abs(x);
            }
            else
                cout << x + d;
            return 0;
        }
    }
}


Measured memory_bytes: 3540
// A - Pair
// https://abc108.contest.atcoder.jp/tasks/abc108_a

import scala.io.StdIn.readLine

object Main extends App {

  val k = readLine.toInt

  val halfFloor = k / 2
  val (odd, even) = if (k % 2 == 0) (halfFloor, halfFloor) else (halfFloor + 1, halfFloor)

  val c = odd * even

  println(c)

}

Measured memory_bytes: 25296
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int, input().split())
    A = list(map(lambda x:int(x) - 1, input().split()))

    nexts = []
    nexts.append(A)
    for _ in range(61):
        next = nexts[-1]
        nnext = [None] * n
        for i in range(n):
            nnext[i] = next[next[i]]
        nexts.append(nnext)

    now = 0
    for d in range(61):
        if (k >> d) & 1:
            now = nexts[d][now]

    print(now + 1)
resolve()

Measured memory_bytes: 180196
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  map<string,int> m;
  rep(i,n){
    string s;
    cin >> s;
    m[s]++;
  }
  cout<<"AC x "<<m["AC"]<<endl;
  cout<<"WA x "<<m["WA"]<<endl;
  cout<<"TLE x "<<m["TLE"]<<endl;
  cout<<"RE x "<<m["RE"]<<endl;
  return 0;
}

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

int main(){
  int r, g, b;
  cin >> r >> g >> b;
  if((r*100+g*10+b)%4==0){
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
typedef long long ll;
/**
 * Uncomment the #define below if problem contains multiple test cases
 */
// #define MULTIPLE_TESTS 1
template <typename T>
inline void readArray(vector<T>& arr, int n) {
  arr.resize(n);
  for (auto& element : arr) {
    cin >> element;
  }
}

void solve() {
  int n;
  cin >> n;
  vector<ll> arr;
  readArray(arr, n);

  sort(arr.begin(), arr.end());
  reverse(arr.begin(), arr.end());
  ll ans = arr[0];
  int k = 1;
  int cnt = 2;
  while (cnt < n) {
    ans += arr[k];
    ++cnt;
    if (cnt % 2 == 0) {
      ++k;
    }
  }
  cout << ans << endl;
}

int main() {
  FAST_IO;
  int t = 1;
#ifdef MULTIPLE_TESTS
  cin >> t;
#endif

  while (t--) {
    solve();
  }

  return 0;
}

Measured memory_bytes: 4780
#include<iostream>
using namespace std; 
int main() {
{ int x,y; while(1)
{cin>>x>>y; 
if(x==0 && y==0)break; 
if(x>=y)cout<<y<<" "<<x<<endl;
else cout<<x<<" "<<y<<endl; } 
return 0; } 
		
	
}


Measured memory_bytes: 3068
def main():
    n = int(input())
    As = [int(input()) for _ in range(n)]

    x = [0]*n
    i = 0
    ans = 0
    while x[i] == 0:
        ans += 1
        x[i] = 1
        i = As[i] - 1
        if i == 1:
            print(ans)
            exit()
    print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 50008
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll X;
    cin >> X;
    string out = "NO";
    if(X==3||X==5||X==7) out = "YES";
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(),M = in();
    cout << N*(N-1)/2 + M*(M-1)/2 << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v) for (auto &&V : v)
#define all(x) (x).begin(), (x).end()
constexpr int INF = 1 << 30;
constexpr long long INFL = 1LL << 62;
constexpr int MOD = 1e9 + 7;
constexpr double EPS = 1e-9;
using lint = long long;

using namespace std;

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

  int x, a;
  cin >> x >> a;
  cout << (x >= a) * 10 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

#include<string>
#include <algorithm> 
using namespace std;

int main()
{
    int n,k;
    string s;
    cin >> n >> s >> k;

    string s_k = s.substr(k-1,1);
    string res = "";
    for(int i = 0 ; i < n ; i++){
        if(s_k==s.substr(i,1)) res += s_k;
        else res += "*";
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int a, b, c;
  	string ans;
  	
  	cin >> a >> b >> c;
  	if(a != b && b != c && c != a) ans = "No";
  	else if(a == b && b == c && c == a) ans = "No";
  	else ans = "Yes";
  
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
while (true) {
   var n = arr.shift() - 0;
   if (n == 0) break;
   var nww = [];
   for (var i = 0; i < n; i++) nww[i] = arr.shift().split(" ");
   nww = nww.map(v => [v[0], v[1] - 0, v[2] - 0]);
   nww.sort((a,b)=>{
      return b[1]-a[1];
   });
   var max = 0;
   var ans = "";
   var bomb = function (strA, strB, sum, g) {
      if (strB.length == 0) {
         if (max < g ) {
            ans = strA;
            max = g ;
         }
         return;
      }
      for(var i=0;i<strB.length;i++){
         var v=strB[i];
         if (sum <= nww[v][2]) {
            var a = strA+v;
            var b = strB.replace(v,"");
            bomb(a, b, sum + nww[v-0][1], g + nww[v-0][1] * (strA.length + 1));
         }
      }
   };
   var str = "";
   for (var i = 0; i < n; i++) str+=i;
   bomb("", str, 0, 0);
   console.log(ans.split("").map(v => nww[v-0][0]).reverse().join("\n"));
}


Measured memory_bytes: 19308
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c, t;
	cin >> a >> b >>c;
	if(a>b){
		t = a;
		a = b;
		b = t;
	}
	if(a>c){
		t = a;
		a = c;
		c = t;
	}
	if(b>c){
		t = b;
		b = c;
		c = t;
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}



Measured memory_bytes: 3112
N = int(input())
B = list(map(int,input().split()))
A = [0]*N
A[0] = A[1] = B[0]
for i in range(1,N-1):
    if B[i] < B[i-1]:
        A[i] = B[i]
        A[i+1] = B[i]
    else:
        A[i+1] = B[i]
#print(A)
print(sum(A))

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

#define ALL(a)  (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define REP(i,n) for(int i=0;i<(int)n;++i)

#define CLEAR(a) memset((a), 0, sizeof(a))

inline int toInt(string s) { int x; istringstream iss(s); iss >> x; return x; }
template<class T> inline string toString(T x) { ostringstream oss; oss <<x ; return oss.str(); }
template<class T> inline T sqr(T x) { return x * x; }

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

const double EPS = 1e-10;
const double PI  = acos(-1.0);

const long long INF = (1LL << 60LL);

typedef ll Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void shortestPath(const Graph &g, int s,
    vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}

int main(int argc, char *argv[]) {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--; t--;

  Graph g_y(n), g_s(n);
  REP(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--; v--;
    g_y[u].push_back(Edge(u, v, Weight(a)));
    g_y[v].push_back(Edge(v, u, Weight(a)));
    g_s[u].push_back(Edge(u, v, Weight(b)));
    g_s[v].push_back(Edge(v, u, Weight(b)));
  }


  Array from(n), to(n);
  vector<int> from_prev(n), to_prev(n);

  shortestPath(g_y, s, from, from_prev);
  shortestPath(g_s, t, to, to_prev);

  Array minimum(n);
  REP(i, n) {
    if (i == 0) {
      minimum[n - i - 1] = from[n - i - 1] + to[n - i - 1];
    }
    else {
      minimum[n - i - 1] = min(from[n - i - 1] + to[n - i - 1], minimum[n - i]);
    }
  }

  REP(i, n) {
    cout << 1000000000000000LL - minimum[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 20292
import sys

n = int(sys.stdin.readline().rstrip())
*a, = map(int, sys.stdin.readline().split())
*b, = map(int, sys.stdin.readline().split())

def main():
    tot = 0
    for i in range(n):
        tot += min(b[i], a[i])
        b[i] = max(0, b[i] - a[i])
        tot += min(b[i], a[i+1])
        a[i+1] = max(0, a[i+1] - b[i])
    print(tot)
        
if __name__ ==  '__main__':
    main()

Measured memory_bytes: 19376
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

	public static void solve() {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		final int MAX = 100000;

		//入力
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] nums = new long[MAX];
		Arrays.fill(nums, 0);
		for(int i = 0; i < n; i++){
			int a = sc.nextInt();
			long b = sc.nextLong();
			a--;
			nums[a] += b;
		}
		sc.close();

		//処理
		int ans = -1;
		for(int i = 0; i < MAX; i++){
			if(k <= nums[i]){
				ans = i + 1;
				break;
			}else{
				k -= nums[i];
			}
		}

		//出力	
		out.println(ans);
		out.flush();
	}

	static class Pair{
		int a,b;
		public Pair(int a, int b){
			this.a = a;
			this.b = b;
		}
	}
}

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

int main()
{
  int H, W;

  while(true){

    cin >> H >> W;
    if(!H && !W) break;

    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }

  return 0;

}

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

using namespace std;

template <class T> inline bool chmin(T &a, T b) { /* {{{ */
  if (a > b) {
    a = b;
    return true;
  }
  return false;
} /* }}} */

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (auto &h : H) {
    cin >> h;
  }
  vector<int> dp(N + 5, 1e9);
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    chmin(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]));
    chmin(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]));
  }
  cout << dp[N - 1] << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int n,s=0,h,w,a,b;
	cin>>n>>h>>w;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		int t1=a/h,t2=b/w;
		s+=min(t1,t2);
		//cout<<i<<" "<<t1<<" "<<t2<<endl;
	}
		
	cout<<s<<endl; 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001



int main() {
    int N; cin >> N;
    vector<PLL> V(N);

    for(int i=0; i<N; i++){
        ll a, b; cin >> a >> b;
        V[i] = {b, a};
    }
    
    sort(V.begin(), V.end());
    
    ll cur = 0;
    for(int i=0; i<N; i++){
        cur += V[i].sc;
        if(cur>V[i].fs){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
    
}



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

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

const int MAXN = 16;

int n;
ll adj[MAXN+10][MAXN+10];

ll dp[(1<<MAXN)+10], score[(1<<MAXN)+10];

ll solve(int bitmask)
{
    if(bitmask==(1<<n)-1) return 0;

    ll &ret=dp[bitmask];
    if(ret!=-1) return ret;

    int i, j, k;
    int now;
    for(i=0; i<n; i++) if((bitmask & (1<<i))==0) { now=i; break; }
    int bitmask2=bitmask|(1<<now);
    int t=(1<<n)-1-bitmask2;

    for(i=t; true; i=(i-1)&t)
    {
        ret=max(ret, solve(bitmask2+i)+score[i|(1<<now)]);
        if(i==0) break;
    }


    return ret;
}

int main()
{
    int i, j, k;

    memset(dp, -1, sizeof(dp));

    scanf("%d", &n);
    for(i=0; i<n; i++) for(j=0; j<n; j++) scanf("%lld", &adj[i][j]);

    for(i=0; i<(1<<n); i++)
    {
        vector<ll> V;
        for(j=0; j<n; j++) if(i&(1<<j)) V.push_back(j);
        for(j=0; j<V.size(); j++) for(k=j+1; k<V.size(); k++) score[i]+=adj[V[j]][V[k]];
    }

    printf("%lld", solve(0));
    return 0;
}


Measured memory_bytes: 1280
import sys
S = sys.stdin.readlines()
cnt = [0] * 101
for s in S:
    n = int(s)
    cnt[n] += 1
m = max(cnt)
n = cnt.count(m)
p = 0
for i in range(n):
    p = cnt.index(m)
    print(p)
    cnt[p] = 0 

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

using namespace std;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

class Pos
{
public:
	int x, y;
};

void solve()
{
	int d;
	cin >> d;
	bool first = true;
	while(d--)
	{
		if(!first)
		{
			cout << endl;
		}
		first = false;
		int n;
		cin >> n;
		if(n == 1)
		{
			cout << "#" << endl;
			continue;
		}
		else if(n == 2)
		{
			cout << "##" << endl;
			cout << "# " << endl;
			continue;
		}
		vector< vector<char> > field(n, vector<char>(n, ' '));
		for(int i = 0; i < n; ++i)
		{
			field[i][0] = '#';
			field[i][n - 1] = '#';
			field[0][i] = '#';
		}
		int direction = 0;
		Pos current;
		current.x = n - 1;
		current.y = n - 1;
		while(true)
		{
			Pos next;
			next.x = current.x + dx[direction];
			next.y = current.y + dy[direction];
			int count = 0;
			while(field[next.y + dy[direction]][next.x + dx[direction]] != '#')
			{
				field[next.y][next.x] = '#';
				current = next;
				next.x = current.x + dx[direction];
				next.y = current.y + dy[direction];
				++count;
			}
			direction = (direction + 1) % 4;
			if(count < 2)
			{
				break;
			}
		}
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cout << field[i][j];
			}
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>

using namespace std;
typedef long long ll;
#define MOD 1000000007

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

    ll ans;
    if(N == 1) {
        ans = 0;
    } else {
        ans = (N - 1) * N / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
s=int(input())
mod=10**9+7
ans=0
fac=[1]
for i in range(s*3):
	fac.append(fac[-1]*(i+1)%mod)
def c(x,y):
	r=fac[y]*fac[x-y]%mod
	return fac[x]*pow(r,mod-2,mod)%mod
for i in range(1,s//3+1):
	n=s-3*i
	ans+=c(n+i-1,i-1)
	ans%=mod
print(ans)

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

#define MAX 2000000000

int n, A[200000];
long long cnt = 0;

void merge(int left, int mid, int right) {
	int n1 = mid - left, n2 = right - mid;
	int L[n1 + 1], R[n1 + 1];
	for (int i = 0; i < n1; i++)
		L[i] = A[left + i];
	for (int i = 0; i < n2; i++)
		R[i] = A[mid + i];
	L[n1] = MAX;
	R[n2] = MAX;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		} else {
			A[k] = R[j];
			j++;
			cnt += n1 - i;
		}
	}
}

void mergesort(int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergesort(left, mid);
		mergesort(mid, right);
		merge(left, mid, right);
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];
	mergesort(0, n);
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 4640
Ans = "A"
while True:
    try:
        Pos = list(map(str,input().split(",")))
        if Pos == ['']:
            print(Ans)
            break
        if Ans in Pos:
            Ans = Pos[((Pos.index(Ans)) + 1) % 2]
    except:
        print(Ans)
        break 
        

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

typedef long long int ll;
using namespace std;
int main(){
	int N,X,k;
	int count=1;
	int sum=0;
	vector<int> L;
	cin >> N>>X;
	if(X==0){
		cout<<1<<endl;
		return 0;
	}
	for(int i=0;i<N;i++){
		cin>>k;
		if(X>=sum+k){
			sum+=k;
			count++;
		}else{
			cout<<count<<endl;
			return 0;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=1e17+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<int>&ar,int in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<int>&ar,int in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int a,b,c,x,q,w,e,ans=0;cin>>a>>b>>c>>x;
	for(q=0;q<=a;q++){
		for(w=0;w<=b;w++){
			for(e=0;e<=c;e++){
				if(q*500+w*100+e*50==x){ans++;}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
m,d = map(int,input().split())

ans = 0

for i in range(d+1):
    d1 = i%10
    d10 = (i//10)%10
    #print(d1,d10)
    if d1 < 2 or d10 < 2:
        continue
    if d1 * d10 <= m:
        ans += 1

print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
using namespace std;
 
 
 
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
   
 
    long int n;
    cin>>n;
    long int i,j,k,x,cnt=0;
    long int h[100005]={0};
   
         for(i=1;i<=100;++i)
          {
              for(j=1;j<=100;++j)
               {
                   for(k=1;k<=100;++k)
                    {
                        cnt=i*i+j*j+k*k+i*j+i*k+j*k;
                        h[cnt]++;
                           
                    }
               }
               
          }
          
        for(i=1;i<=n;++i)
          {
              cout<<h[i]<<endl;
          }
         
     
    
    
   
     return 0;
}

Measured memory_bytes: 4364
W = []
for w in range(10):
    w = int(input())
    W.append(w)
K = []
for k in range(10):
    k = int(input())
    K.append(k)
W.sort()
K.sort()
a1 = W[7] + W[8] + W[9]
a2 = K[7] + K[8] + K[9]
print(a1,a2)

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

int main() {
  int n, d, x;
  cin >> n;
  cin >> d >> x;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int ans = x;
  for (int i = 0; i < n; i++) {
    int j = 0;
    while (true) {
      if (j*a[i] + 1 > d) {
        break;
      }
      ans++;
      j++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int N,K;
  scanf("%d%d",&N,&K);

  if((N-1)*(N-2)/2 < K){
    printf("-1\n");
    return 0;
  }

  int cnt = N-1 + (N-1)*(N-2)/2-K;
  printf("%d\n",cnt);
  for (int i = 1; i < N; i++) {
    printf("%d %d\n",i,N);
  }

  cnt -= N-1;
  int x = 1,y = 2;
  for (int i = 0; i < cnt; i++) {
    printf("%d %d\n",x,y);
    y++;
    if(y == N){
      x++;
      y = x+1;
    }
  }

  return 0;
}

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

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] v = new int[N+1];
		int[] w = new int[N+1];
		for(int i = 1; i <= N; i++){
			v[i] = sc.nextInt();
			w[i] = sc.nextInt();
		}
		
		int[] dp = new int[W+1];
		
		for(int i = 1; i <= N; i++){
			for(int j = 0; j <= W; j++){
				if(j + w[i] <= W)
					dp[j + w[i]] = Math.max(dp[j + w[i]], dp[j] + v[i]);
			}
		}
		
		System.out.println(dp[W]);
		
	}//end main
}//end Main

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}



Measured memory_bytes: 24864
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <fstream>

using namespace std;

ifstream fin("data.txt");

vector<string> v;
string x;
int n, l;

int main() {

  cin >> n >> l;
  cin.ignore();
  for (int i = 0; i < n; i++) {
    getline(cin, x);
    v.push_back(x);
  }

  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    cout << v[i];
  }

  return 0;
}


Measured memory_bytes: 3644
#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 main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	double ans = 0;
	double t;
	string s;
	rep(i, n) {
		cin >> t >> s;
		if(s == "JPY") ans += t;
		else ans += t * 380000;
	}

	cout << std::setprecision(10) << ans << "\n";

	return 0; 
}


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

int H, W;
char S[26][26][6];
char ABC[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
bool flag = false;
int main(void) {
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { scanf("%s", &S[i][j]); } }

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (strcmp("snuke", S[i][j]) == 0) {
				printf("%c%d", ABC[j], i + 1);
				flag = true;
				break;
			}
		}
		if (flag == true) { break; }
	}
	return 0;
}

Measured memory_bytes: 128
use proconio::{input, fastout};
use std::collections::{BinaryHeap, HashMap};
use std::cmp::Reverse;

#[fastout]
fn main() {
  input! {
    n: usize,
    k: usize,
    mut vals: [(usize, usize);n]
  }
  
  let mut map: HashMap<usize, Vec<usize>> = HashMap::new();  
  for (i, v) in vals {
    let entry = map.entry(i).or_insert(vec![]);
    entry.push(v);
  }
  let kinds = map.len();
  
  let mut stack: Vec<(usize, usize)> = vec![];

  for (_, smap) in map.iter_mut() {
    smap.sort();
    smap.reverse();
    stack.push((*smap.first().unwrap(), 1));
    for i in 1..smap.len() {
      stack.push((smap[i], 0));
    }
  }
  stack.sort_by(|a, b| a.0.cmp(&b.0));
  stack.reverse();

  let mut max = 0;
  let mut total = 0;
  let mut count = 0;
  let mut zeros = BinaryHeap::new();
  for i in 0..k {
    let (val, first) = stack[i];
    total += val;
    count += first;
    if first == 0 {
      zeros.push(Reverse(val));
    }
  }
  max = total + (count * count);
  let mut index = k;
  while count < kinds && count < k {
    let (val, first) = stack[index];
    if first == 1 {
      let minus = zeros.pop().unwrap();
      total = total - minus.0 + val;
      count += 1;
      max = std::cmp::max(max, total + (count * count));
    }
    index += 1;
  }
  
  println!("{}", max);
}

Measured memory_bytes: 13296
k,n =map(int,input().split())
a = list(map(int,input().split()))
a.append(k+a[0])
#print(a)
l = 0
for i in range (n):
    l = max(l,a[i+1]-a[i])
ans = k-l
print(ans)



'''
ans_a = 0
for i in range(len(a)-1):
    ans_a +=(a[i+1]-a[i])
for i in range(n):
    if a[i]>k/2:
        a[i] = k-a[i]

a.sort(reverse=True)
kai = a[0]+a[1]
#print(kai,ans_a)
print(min(kai,ans_a))
'''

Measured memory_bytes: 26420
n = gets.to_i
arr = []
n.times{
    a, b = gets.chomp.split.map(&:to_i)
    arr[a + b] = 0 if arr[a + b].nil?
    arr[a + b] += 1
}
digit = 0
while true
    if arr[digit].nil?
        arr[digit] = 0
    else
        k, r = arr[digit].divmod 2
        arr[digit] = r
        add = 1
        while k > 0
            k, r = k.divmod 2
            arr[digit + add] = 0 if arr[digit + add].nil?
            arr[digit + add] += r
            add += 1
        end
    end
    digit += 1
    break if digit == arr.length
end
arr.each_with_index{|x, i| puts "#{i} 0" if x == 1}



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

int main(){
  int n,m; cin >>n >>m;
  int s[6],c[6];
  rep(i,m) cin >>s[i] >>c[i];
  rep(i,1000){
    string str = to_string(i);
    if(str.size()==n){
      int cnt = 0;
      rep(j,m){
        if(str[s[j]-1]!=c[j]+'0') break;
        else cnt++;
      }
      if(cnt==m) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0; 
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	char n1,n2,n3;
	cin>>n1>>n2>>n3;
	if(n1=='7')cout<<"Yes"<<endl;
	else if(n2=='7')cout<<"Yes"<<endl;
	else if(n3=='7')cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N; string S;
    cin >> N >> S;

    stack<char> st;
    rep(i, 0, S.size()) {
        char next = S[i];
        if (st.empty()) st.push(next);
        else if (next == ')' and st.top() == '(') st.pop();
        else st.push(next);
    }

    while(!st.empty()) {
        char top = st.top();
        st.pop();

        if (top == ')') S.insert(S.begin(), '(');
        else S.push_back(')');
    }

    cout << S << endl;
}

Measured memory_bytes: 256