akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (ll i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << (x) << endl
#define debug2(x, y) cerr << #x << ": " << (x) << " " << #y << ": " << y << endl;
#define int long long
using namespace std;
using II = pair<int, int>;
using VII = vector<II>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;

class Graph {
  vector<bool> used;
  int t; // ゴール
  // f: 流量
  int dfs(int v, int f) {
    if (v == t) return f;
    used[v] = true;
    for (edge& e: G[v]) {
      if (used[e.to] || e.cap <= 0) continue;
      int res = dfs(e.to, min(f, e.cap));
      if (res <= 0) continue;
      e.cap -= res;
      G[e.to][e.rev].cap += res;
      return res;
    }
    return 0;
  }
public:
  int V;
  // G[e.to][e.rev]で逆辺にアクセスできるように
  // 逆辺には"辺に流した流量"を入れる(はじめは全て0)
  struct edge { int to, cap, rev; };
  vector<vector<edge>> G;
  Graph(int V) : V(V), G(V), used(V) {}
  void add_edge(int from, int to, int cap) {
    G[from].push_back({to, cap, (int)G[to].size()});
    G[to].push_back({from, 0, (int)G[from].size() - 1});
  }
  int max_flow(int s, int t) {
    this->t = t;
    int ret = 0;
    while (1) {
      fill(ALL(used), false);
      int f = dfs(s, 1e18);
      if (f == 0) return ret;
      ret += f;
    }
  }
};
signed main() {
  int V, E; cin >> V >> E;
  Graph g(V);
  while (E--) {
    int u, v, c; cin >> u >> v >> c;
    g.add_edge(u, v, c);
  }
  cout << g.max_flow(0, V - 1) << endl;
}



Measured memory_bytes: 3328
# -*- coding utf-8 -*-

a,b = map(int,input().split())

if a==1 and b==1:
    print("Draw")
elif a==1:
    print("Alice")
elif b==1:
    print("Bob")
elif a>b:
    print("Alice")
elif b>a:
    print("Bob")
elif a==b:
    print("Draw")



Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		sc.close();
		String[] split = line.split(" ");
		int x = Integer.parseInt(split[0]);
		int y = Integer.parseInt(split[1]);
		int area = x * y;
		int circumference = x * 2 + y * 2;
		System.out.println(area + " " + circumference);
	}
}

Measured memory_bytes: 26056
listA=[]

while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        

money = min(listA[1]) + min(listA[2]) 
wari = 100000000

for k in range(listA[0][2]):
    a = listA[k+3][0]
    b = listA[k+3][1]
    if wari > listA[1][a-1] + listA[2][b-1] - listA[k+3][2]:
        wari = listA[1][a-1] + listA[2][b-1] - listA[k+3][2]

if money <= wari:
    print(money)
        
else:
    print(wari)

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

int main()
{
	int top, stop, sstop, obj;
	top = stop = sstop = 0;
	for (int i = 0; i < 10; i++){
		cin >> obj;
		if (obj > top){
			sstop = stop;
			stop = top;
			top = obj;
		}else if (obj > stop){
			sstop = stop;
			stop = obj;
		}else if (obj > sstop){
			sstop = obj;
		}
	}
	cout << top << "\n" << stop << "\n" << sstop << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
    #define REP(i, n) for(int i = 0;i < n;i++)
    #define REPR(i, n) for(int i = n;i >= 0;i--)
    #define FOR(i, m, n) for(int i = m;i < n;i++)
    #define FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)
    #define INF 999999999
    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;

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

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

       int cnt=0;

        vector<int> b(m,0);
        for(int i=0; i<m; i++)
        {
            cin>>b[i];
        }
        vector<vector<int>> a(n,vector<int>(m,0));
        for(int i=0; i<n; i++)
       {
           for(int j=0; j<m; j++)
           {
               cin>>a[i][j];
           }
       }

       for(int i=0; i<n; i++)
       {   int ans=0;
           for(int j=0; j<m; j++)
           {
               ans+=a[i][j]*b[j];
           }
           ans+=c;
           if(ans>0) {++cnt;}
       }
       cout<<cnt<<endl;
    }

Measured memory_bytes: 256
N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]

li = [0]*N
if N > 1:
    li[0] = 1
te = [[] * 1 for i in range(N)]

check = 0

if check == 0:
    for j in range(M):
        a = sc[j][0] - 1
        b = sc[j][1]
        te[a].append(b)

    for i in range(M):
        if sc[i][0] == 1 and sc[i][1] == 0 and N > 1:
            ans = -1
            check = 1
            break

    for k in range(N):
        if len(set(te[k])) >= 2:
            ans = -1
            check = 1
            break
        else:
            if len(set(te[k])) == 1:
                li[k] = te[k][0]

if check == 0:
    ans = ""
    for s in li:
        ans += str(s)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c,d;
    char q,w,e,r;
    cin >> q >> w >> e>>r;
    a = q-'0';
    b = w-'0';
    c = e-'0';
    d = r-'0';
    if(a + b + c + d == 7){
        cout << a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7\n";
        exit(0);
    }
    if(a + b + c - d == 7){
        cout << a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7\n";
        exit(0);
    }
    if(a + b - c + d == 7){
        cout << a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7\n";
        exit(0);
    }
    if(a + b - c - d == 7){
        cout << a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7\n";
        exit(0);
    }
    if(a - b + c + d == 7){
        cout << a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7\n";
        exit(0);
    }
    if(a - b + c - d == 7){
        cout << a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7\n";
        exit(0);
    }
    if(a - b - c + d == 7){
        cout << a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7\n";
        exit(0);
    }
    if(a - b - c - d == 7){
        cout << a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7\n";
        exit(0);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    string s;
    cin >> n >> s;
    int cnt[26] = {};
    rep(i, n)
    {
        cnt[s[i] - 'a']++;
    }
    int ans = 1;
    rep(i, 26) ans = (ans * (cnt[i] + 1)) % mod;
    ans = (ans - 1) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 512
N = (gets).to_i
Vs = (gets).split(" ").map { |i| i.to_i }
costs = (gets).split(" ").map.with_index { |i,idx|
    t = Vs[idx] - i.to_i
    if t > 0 then
        t
    else
        0
    end
  }

total = 0
costs.each { |c| total = total + c }

puts total

Measured memory_bytes: 1788
#include <cstdio>
#include <algorithm>
using namespace std;

long long n, k, a[100005];
int main() {
	int i;
	scanf("%d", &n);
	for(i=1; i<=n; i++) scanf("%d", &a[i]);
	sort(a+1, a+n+1);
	for(i=1; i<n-1; i++) {
		a[i] += a[i-1];
		if(a[i]*2 < a[i+1]) k = i;
	}
	printf("%d", n-k);
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
namespace whatever{
	int readu(){
		char ch=getchar();
		while(!isdigit(ch))
			ch=getchar();
		int value=ch-'0';
		ch=getchar();
		while(isdigit(ch)){
			value=value*10+ch-'0';
			ch=getchar();
		}
		return value;
	}
	void writeull(long long n){
		if(n<10)
			putchar(n+'0');
		else{
			writeull(n/10);
			putchar(n%10+'0');
		}
	}
	void run(){
		cerr<<"time(0): "<<time(0)<<endl;
		int n=readu();
		static int a[100000];
		for(int i=0; i<n; ++i)
			a[i]=readu();
		sort(a, a+n);
		long long result=(accumulate(a+n-n/2, a+n, 0ll)-accumulate(a, a+n/2, 0ll))*2;
		if(n%2==0)
			result-=a[n/2]-a[n/2-1];
		else
			result+=max(a[n/2]-a[n/2-1], a[n/2+1]-a[n/2])-(a[n/2+1]-a[n/2-1]);
		writeull(result);
		putchar('\n');
	}
}
int main(){
	whatever::run();
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main()
{
    string s,t;
    cin >> s >> t;
    int cnt=0;
    REP(i,s.size()){
        if(s[i]!=t[i]){
            cnt ++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3924
#include<iostream>
using namespace std;
int main(){
    int n,tmp,max=0,min=1001;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>tmp;
        if(tmp>max)max=tmp;
        if(tmp<min)min=tmp;
    }
    cout<<max-min<<endl;
    return 0;
}

Measured memory_bytes: 256
s=input()
if s[0]=="A" and s[2:-1].count("C")==1:
  c=s[2:-1].index("C")
  if s[1:c+2].islower() and s[c+3:].islower():
    print("AC")
  else:
    print("WA")
else:
  print("WA")

Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var r = cin.nextInt();
            var g = cin.nextInt();

            Console.WriteLine(g*2-r);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

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

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

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

        public string[] ArrayString(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = next();
            }
            return Array;
        }

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

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

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

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

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

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


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

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


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

int main ()
{
	typedef int l;
	int a,b,c,d;  cin>>a>>b>>c>>d;
	
	l s1=a+c;
	l s2=a+d;
	l s3=b+c;
	l s4=b+d;
	
	cout<<min(s1,min(s2,min(s3,s4)));
	
	


}


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

int main() {
  int n;
  string str;
  cin >> n >> str;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    vector <int> vec1(26, 0);
    vector <int> vec2(26, 0);
    for (int j = 0; j <= i; j++) {
      int x = str.at(j) - 'a';
      vec1.at(x) = 1;
    }
    for (int k = i+1; k < n; k++) {
      int y = str.at(k) - 'a';
      vec2.at(y) = 1;
    }
    int tmp = 0;
    for (int z = 0; z < 26; z++) {
      if (vec1.at(z)+vec2.at(z) >= 2) {
        tmp++;
      }
    }
    if (tmp > ans) {
      ans = tmp;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
class Program
 {
        static void Main(string[] args)
        {
    　	string N = Console.ReadLine(); //標準入力
         int count= 0;
        	for(int i=0;i<N.Length;i++){
              string s2 = N.Substring(i, 1);
              int a = int.Parse(s2);
              count = (count + a)%9;
            }
          if(count ==0){
            
          Console.WriteLine("{0}", "Yes");//改行付き出力
          }else{
          Console.WriteLine("{0}", "No");//改行付き出力
          }
        //Console.WriteLine("{0}", count);//改行付き出力
        
        }
 }

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int h,w;
char a[1252][1252];
int dist[1252][1252];

int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
bool check(int i, int j){
    if(a[i][j]=='#')return false;
    REP(d,4){
        int ni = i+dx[d], nj = j+dy[d];
        if(ni<0 || nj<0 || ni>=h || nj>=w)continue;
        if(a[ni][nj]=='#')return true;
    }
    return false;
}

int main(){
    scanf("%d%d",&h,&w);
    REP(i,h)scanf("%s",a[i]);
    int ans = 0;
    queue<pii> Q;
    const int INF = 1<<30;
    REP(i,h)REP(j,w)dist[i][j] = INF;
    REP(i,h)REP(j,w)if(check(i,j)){
        dist[i][j] = 1;
        Q.push(pii(i,j));
    }
    while(Q.size()){
        int i = Q.front().first;
        int j = Q.front().second; Q.pop();
        a[i][j] = '#';
        CHMAX(ans, dist[i][j]);
        REP(d,4){
            int ni = i+dx[d], nj = j+dy[d];
            if(ni<0 || nj<0 || ni>=h || nj>=w)continue;
            if(a[ni][nj]=='#')continue;
            int nd = dist[i][j] + 1;
            if(nd < dist[ni][nj]){
                dist[ni][nj] = nd;
                Q.push(pii(ni,nj));
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 11776
# ABC084b
import sys
import re
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

a, b = map(int, input().split())
s = input()[:-1]

print('Yes' if re.fullmatch(
    '[0-9]{' + str(a) + '}-[0-9]{' + str(b) + '}', s) != None else 'No')

Measured memory_bytes: 3188
N = int(input())
C = list(map(int, input().split()))
A = []
B = []
while C != [0] * N:
    a = max(C)
    A.append(a)
    for i in range(len(C)):
        if C[i] == a:
            C[i] = 0
            break
    a = max(C)
    B.append(a)
    for i in range(len(C)):
        if C[i] == a:
            C[i] = 0
            break
print(sum(A)-sum(B))

Measured memory_bytes: 39152
#include<iostream>
#include<vector>
#include<utility>

using namespace std;

vector<pair<double,double> > rec(vector<int> v){
  if(v.size()==1)return {make_pair(0.,0.)};
  vector<pair<double,double> > ret;
  for(int i=0;i<1<<v.size();i++){
    vector<int> nw[2];
    int ws[2]={};
    for(int j=0;j<v.size();j++){
      nw[i>>j&1].push_back(v[j]);
      ws[i>>j&1]+=v[j];
    }
    if(ws[0]==0||ws[1]==0)continue;
    auto l=rec(nw[0]);
    auto r=rec(nw[1]);
    double x=ws[1]*1./(ws[0]+ws[1]);
    for(auto e:l){
      for(auto f:r){
	ret.emplace_back(max(e.first+x,f.first-(1-x)),max(1-x+f.second,e.second-x));
      }
    }
  }
  return ret;
}

int main(){
  int T;
  cin>>T;
  while(T--){
    double r;
    int s;
    cin>>r>>s;
    vector<int> w(s);
    for(int i=0;i<s;i++){
      cin>>w[i];
    }
    auto res=rec(w);
    double a=-1;
    for(auto e:res){
      double l=e.first+e.second;
      if(l<r){
	a=max(a,l);
      }
    }
    cout.precision(9);
    cout<<fixed<<a<<endl;
  }
}

Measured memory_bytes: 2220
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int a[maxn], b[maxn], k, n, m, sum, p;
double c, r;
string s, t;


int main(){
    ios_base::sync_with_stdio(0);
    cin>>n>>m;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
    }
    while(m--){
        cin>>k>>p;
        if(a[k] > a[p])b[p] = 1;
        else if(a[k] < a[p])
                b[k] = 1;
        else {
            b[k] = 1;
            b[p] = 1;
        }

    }
    for(int i = 1; i <= n; i++){
        if(b[i] == 0)sum++;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, ans = 0, tmp;
	cin >> nn;
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> tmp;
		while(tmp % 2 == 0)
		{
			ans++;
			tmp /= 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
//In the name of God

#include <bits/stdc++.h>
using namespace std;

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

const int N = 2e5+10 , mod = 1e9+7;

#define int ll

int fen[N] , h[N] , b[N];

inline int get(int x){
   int ret = 0;
   for( ; x ; x -= x & -x)
      ret = max(ret , fen[x]);
   return ret;
}

inline void add(int x , int val){
   for( ; x < N ; x += x & -x)
      fen[x] = max(fen[x] , val);
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   cout << fixed << setprecision(9);
   int n;
   cin >> n;
   for(int i = 0 ; i < n ; i++)
      cin >> h[i];
   for(int j = 0 ; j < n ; j++)
      cin >> b[j];
   for(int i = 0 ; i < n ; i++){
      int ret = get(h[i]) + b[i];
      add(h[i] , ret);
   }
   cout << get(N - 1);
   return 0;
}


Measured memory_bytes: 4992
#include <iostream>

using namespace std;

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

    int i, p[N], count=0;
    for(i=0; i<N; i++) {
        cin >> p[i];
        if(p[i]==i+1) {
            continue;
        } else {
            count += 1;
        }
    }

    if(count<=2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class B
{
	public static void Main()	
	{
		int H = GetInt();
		int W = GetInt();
		string[] C = new string[H];
		for(int i = 0; i < H; i++)
			C[i] = GetString();

		for(int i = 0; i < H; i++)
		{
			Console.WriteLine(C[i]);
			Console.WriteLine(C[i]);
		}
	}
}


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

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

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N;
	cin >> N;
	if (N % 10 == 9 || N / 10 == 9) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
// AOJ 1319 Driving an Icosahedral Rover
// 2018.2.8 bal4u

#include <stdio.h>
#include <string.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	if (c == '-') {
		c = getchar_unlocked();
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
		return -n;
	}
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define INF  120
#define BASE 100
#define MAX  100
#define LIM	 200
#define QMAX 910000

typedef struct { unsigned char x, y, k; } Q;
Q q[QMAX+2]; int top, end;

int mv[60][3] = {
{ 5, 13, 15},{14, 16,  3},{17,  4, 12},
{20,  8,  1},{ 6,  2, 18},{ 0, 19,  7},
{ 4, 22, 11},{23,  9,  5},{10,  3, 21},
{12,  7, 24},{ 8, 25, 13},{26, 14,  6},
{ 9, 28,  2},{29,  0, 10},{ 1, 11, 27},
{32, 34,  0},{35,  1, 30},{ 2, 31, 33},
{34, 37,  4},{38,  5, 35},{ 3, 33, 36},
{37, 40,  8},{41,  6, 38},{ 7, 36, 39},
{40, 43,  9},{44, 10, 41},{11, 39, 42},
{43, 32, 14},{30, 12, 44},{13, 42, 31},
{28, 46, 16},{47, 17, 29},{15, 27, 45},
{50, 20, 17},{18, 15, 48},{16, 49, 19},
{53, 23, 20},{21, 18, 51},{19, 52, 22},
{56, 26, 23},{24, 21, 54},{22, 55, 25},
{59, 29, 26},{27, 24, 57},{25, 58, 28},
{58, 50, 32},{48, 30, 59},{31, 57, 49},
{46, 53, 34},{51, 35, 47},{33, 45, 52},
{49, 56, 37},{54, 38, 50},{36, 48, 55},
{52, 59, 40},{57, 41, 53},{39, 51, 58},
{55, 47, 43},{45, 44, 56},{42, 54, 46}};

char d[201][201][60];
int dx[2][3] = {{-1,1,0},{-1,1, 0}};
int dy[2][3] = {{ 0,0,1},{ 0,0,-1}};
int dk[2][3] = {{ 1,0,2},{ 0,1, 2}};

int main()
{
	int x, y, k, i, f, nx, ny, nk, ans;

	memset(d, INF, sizeof(d));
	d[BASE][BASE][0] = 0;
	q[0].x = BASE, q[0].y = BASE, q[0].k = 0, top = 0, end = 1;
	while (top != end) {
		x = q[top].x, y = q[top].y, k = q[top++].k;
		if (d[x][y][k] >= MAX) break;

		f = (x+y) & 1;
		for (i = 0; i < 3; i++) {
			nx = x + dx[f][i], ny = y + dy[f][i], nk = mv[k][dk[f][i]];

			if (nx >= 0 && nx <= LIM && ny >= 0 && ny <= LIM && d[x][y][k]+1 < d[nx][ny][nk]) {
				d[nx][ny][nk] = d[x][y][k]+1;
				q[end].x = nx, q[end].y = ny, q[end++].k = nk;
			}
		}
	}

	while (1) {
		x = in(), y = in(), k = in();
		if ((x|y|k) == 0) break;
		x += BASE, y += BASE, k *= 3;
		ans = INF;
		for (i = 0; i < 3; i++) if (ans > d[x][y][k+i]) ans = d[x][y][k+i];
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 6676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vec<ll> A(N+1);
    for(int i=2;i<=N;i++){
        cin >> A[i];
        A[i] += A[i-1];
    }
    vvec<ll> B(M+1,vec<ll>(N+1,0));
    for(int i=1;i<=N;i++) for(int j=1;j<=M;j++) cin >> B[j][i];
    vvec<ll> S(N+2,vec<ll>(N+2,0));
    
    auto imos = [&](vec<ll>& b){
        set<int> s;
        s.insert(0);
        s.insert(N+1);
        vec<int> id(N);
        iota(id.begin(),id.end(),1);
        sort(id.begin(),id.end(),[&](int i,int j){return b[i]>b[j];});
        for(auto i:id){
            set<int>::iterator itl = s.upper_bound(i);
            int r = *itl;
            itl--;
            int l = *itl;
            r--; l++;
            S[l][i] += b[i];
            S[l][r+1] -= b[i];
            S[i+1][i] -= b[i];
            S[i+1][r+1] += b[i];
            s.insert(i);     
        }
    };
    
    for(int j=1;j<=M;j++) imos(B[j]);

    for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) S[i][j] += S[i-1][j];
    for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) S[i][j] += S[i][j-1];

    ll ans = 0;
    for(int i=1;i<=N;i++) for(int j=i;j<=N;j++) ans = max(ans,S[i][j]-A[j]+A[i]);
    cout << ans << endl;
}

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

int main()
{
    int N;
    cin>>N;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;

    int r = 0;
    int g = 0;
    int b = 0;
    long long ans = 1;
    for (int a: A)
    {
        if (a!=r && a!=g && a!=b) {ans *= 0;}
        if (a!=r && a!=g && a==b) {ans *= 1; b++;}
        if (a!=r && a==g && a!=b) {ans *= 1; g++;}
        if (a!=r && a==g && a==b) {ans *= 2; b++;}
        if (a==r && a!=g && a!=b) {ans *= 1; r++;}
        if (a==r && a!=g && a==b) {ans *= 2; b++;}
        if (a==r && a==g && a!=b) {ans *= 2; g++;}
        if (a==r && a==g && a==b) {ans *= 3; b++;}
        ans %= 1000000007LL;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 888
#include<stdio.h>
int main(void)
{
	int t,n,s,f,i,sum;
	while(1){
		sum=0;
		scanf("%d",&t);
		if(t==0)break;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d %d",&s,&f);
			sum=sum+(f-s);
		}
		if(sum>=t){
			printf("OK\n");
		}
		else{
			printf("%d\n",t-sum);
		}
	
	}
	return 0;
}

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

int main(){
    string s;
    cin>>s;
    int a=count(s.begin(),s.end(),'a');
    int b=count(s.begin(),s.end(),'b');
    int c=count(s.begin(),s.end(),'c');
    cout<<(max({a,b,c})-min({a,b,c})<=1 ?  "YES" : "NO")<<endl;
    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;

void solve(){
	int n;
	cin >> n;
	int p[n];
	cin >> p[0];
	int mn = p[0];
	int ans = 1;
	for(int i = 1; i < n; ++i){
		cin >> p[i];
		mn = min(mn, p[i]);
		if(mn == p[i])ans++;
	}
	cout << ans << endl;
}

int32_t main(){
	IO;
	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


Measured memory_bytes: 1792
n, l = map(int, input().split())
sum = 0
ans = float("inf")

for i in range(n):
    sum += l + (i + 1) - 1

for i in range(n):
    temp = sum
    temp -= l + (i + 1) - 1

    if abs(sum - temp) < abs(sum - ans):
        ans = temp

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int maxn=50005;
int h,w,k,dp[1005][1005],sx,sy,ant;
char s[1005][1005];
queue<pii> qu;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int fun(int i,int j)
{
    int ant=(i+k-2)/k;
    ant=min(ant,(j+k-2)/k);
    ant=min(ant,(h-i+k-1)/k);
    ant=min(ant,(w-j+k-1)/k);
    return ant;
}
int main()
{
    ant=0x3f3f3f3f;
    memset(dp,0x3f3f3f3f,sizeof dp);
    scanf("%d %d %d",&h,&w,&k);
    for(int i=1;i<=h;i++)
        scanf("%s",s[i]+1);
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(s[i][j]=='S')
            {
                sx=i;
                sy=j;
                break;
            }
        }
    }
    dp[sx][sy]=0;
    qu.push(pii(sx,sy));
    while(!qu.empty())
    {
        int x=qu.front().first;
        int y=qu.front().second;
        qu.pop();
        if(dp[x][y]==k)
            continue;
        for(int i=0;i<4;i++)
        {
            int nx=x+dx[i];
            int ny=y+dy[i];
            if(nx<1||nx>h||ny<1||ny>w||dp[x][y]+1>=dp[nx][ny]||s[nx][ny]=='#')
                continue;
            dp[nx][ny]=dp[x][y]+1;
            qu.push(pii(nx,ny));
        }
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(dp[i][j]<0x3f3f3f3f)
            {
                ant=min(ant,fun(i,j)+1);
            }
        }
    }
    printf("%d\n",ant);
    return 0;
}


Measured memory_bytes: 4992
nums = [int(x) for x in input().split()]

sign = [0] * 4
for x in range(4):
    if nums[x] < 0:
        sign[x] = 1

result = min(nums[0:2]) * min(nums[2:])

if sum(sign) == 1 or sum(sign) == 0:
    result = max(nums[0:2]) * max(nums[2:])

if sum(sign) == 2:
    if (sign[0] == 1 and sign[1]) or (sign[2] == 1 and sign[3] == 1):
        if sign[0] == 1:
             result = max(nums[0:2]) * min(nums[2:])
        elif sign[2] == 1:
             result = min(nums[0:2]) * max(nums[2:])
    else:
        cur1 = nums[0] * nums[2]
        cur2 = nums[1] * nums[3]
        if abs(cur1) > abs(cur2):
            result = cur1
        else:
            result = cur2
print(result)


Measured memory_bytes: 9212
import java.util.Scanner;
public class Main{
public static void main(String[] args){
	Scanner sc =new Scanner(System.in);
	int w = sc.nextInt();
	int n =sc.nextInt();
	int[] values =new int[w];
	for(int i=0;i<values.length;i++){
	values[i]=i+1;
	}
	for(int i=0;i<n;i++){
	String str =sc.next();
	String[] ab=str.split(",");
	int a =Integer.parseInt(ab[0])-1;
	int b =Integer.parseInt(ab[1])-1;
	int temp;
	temp=values[a];
	values[a]=values[b];
	values[b]=temp;
	}
	for(int i=0;i<w;i++){
	System.out.printf("%d\n",values[i]);
	}
}
}

Measured memory_bytes: 17228
num_of_person, num_of_foods = map(int, input().split())

if num_of_person == 0:
    print("0")

common_favorit_food_set = set()
for i in range(num_of_person):
    research = list(map(int, input().split()))
    num_of_favorit = research[0]
    favorit_set = set(research[1:])
    if i == 0:
        common_favorit_food_set = favorit_set
    else:
        common_favorit_food_set &= favorit_set


print("{}".format(len(common_favorit_food_set)))


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

void swap(int &x, int &y) {
  int tmp;
  tmp = x;
  x = y;
  y = tmp;
}

int selectionSort(int *a, int n) {
  int minj, res = 0;
  for (int i=0; i<n; i++) {
    minj = i;
    for (int j=i; j<n; j++) {
      if (a[j] < a[minj]) {
        minj = j;
      }
    }
    if (i != minj) {
      swap(a[i], a[minj]);
      res++;
    }
  }
  return res;
}

int main() {
  int N, A[100], cnt;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  cnt = selectionSort(A, N);

  for (int i=0; i<N; i++) {
    cout << A[i];
    if (i < N - 1) cout << " ";
  }
  cout << endl << cnt << endl;

  return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll k[200005],l[200005],r[200005];
bool c1(ll i,ll j){
	return k[i]<k[j];
}
void solve(){
	ll n,res=0;
	cin>>n;
	vector<ll> g1,g2;
	for(ll i=1;i<=n;i++){
		cin>>k[i]>>l[i]>>r[i];
		if(l[i]>r[i])
		g1.push_back(i);
		else
		g2.push_back(i);
	}
	sort(g1.begin(),g1.end(),c1);
	ll cur=1;
	multiset<ll> m;
	for(ll i=0;i<sz(g1);i++){
		ll j=i;
		while(j<sz(g1)&&k[g1[i]]==k[g1[j]])
		j++;
		while(i<j){
			if(cur>k[g1[i]]){
				if((*m.begin())<l[g1[i]]-r[g1[i]]){
					res+=l[g1[i]]-(*m.begin());
					m.erase(m.begin());
					m.insert(l[g1[i]]-r[g1[i]]);
				}
				else
				res+=r[g1[i]];
			}
			else{
				m.insert(l[g1[i]]-r[g1[i]]);
				res+=l[g1[i]];
				cur++;
			}
			i++;
		}
		i--;
	}
	sort(g2.begin(),g2.end(),c1);
	ll temp=cur;
	cur=n;
	m.clear();
	for(ll i=sz(g2)-1;i>=0;i--){
		ll j=i;
		while(j>=0&&k[g2[i]]==k[g2[j]]){
			k[g2[j]]++;
			j--;
		}
		if(k[g2[i]]==n+1){
			while(i>j){
				res+=l[g2[i]];
				i--;
			}
			i++;
			continue;
		}
		while(i>j){
			if(cur<k[g2[i]]||cur<temp){
                  if((*m.begin())<r[g2[i]]-l[g2[i]]){
					res+=r[g2[i]]-(*m.begin());
					m.erase(m.begin());
					m.insert(r[g2[i]]-l[g2[i]]);
				  }
				  else
				  res+=l[g2[i]];
			}
			else{
				m.insert(r[g2[i]]-l[g2[i]]);
				res+=r[g2[i]];
				cur--;
			}
			i--;
		}
		i++;
	}
	cout<<res<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    cin>>qc;
    for(ll i=1;i<=qc;i++)
	solve();
}


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

int main () {
	int n, m;
	cin >> n >> m;
	int a[n], b[n], c[m], d[m];
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
	for (int j = 0; j < m; j++) cin >> c[j] >> d[j];

	int min[n], ans[n], dis;/* ans[n]は各学生が移動するチェックポイン
    トの番号を格納する*/
  //min[n]に最小のdisを格納する
	for (int i = 0; i < n; i++) { //人の位置
		min[i] = 1000000000; //初期化(最小値なので0ではなく10^9)
		for (int j = 0; j < m; j++) { //チェックポイントの位置
			dis = abs(a[i] - c[j]) + abs(b[i] - d[j]); //マンハッタン距離
			if (dis < min[i]) {
				min[i] = dis;
				ans[i] = j + 1; //jが0から始まっているので+1
			}
		}
	}
	for (int i = 0; i < n; i++) cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    
           Scanner sc = new Scanner(System.in);
           int a,b,sum;
           a = sc.nextInt();
           b = sc.nextInt();
     
           int tmp = a % b;
           
          if(tmp == 0) {
             System.out.print(0); 
          } else {
             System.out.print(1);
          }
     
   }
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<set>
#include<map>
#include<queue>
#include<vector>
#define ll long long int
#define INF 0x7fffffff
#define me(a,b) memset(a,b,sizeof(a))
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int x=100*(a-b)+1900*b;
    for(int i=1;i<=b;i++)
        x*=2;
    cout<<x<<endl;
}


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

using ll=long long; 

void solve(){
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	vector<int>a(n),b(m);
	for(int i=0; i<n; i++)cin>>a[i];
	for(int i=0; i<m; i++)cin>>b[i];
	a.push_back(x);
	b.push_back(y);
	for(int i=0; i<a.size(); i++){
		for(int j=0; j<b.size(); j++){
			if(b[j]<=a[i]){
				cout<<"War"<<endl;
				return;
			}
		}
	}
	cout<<"No War"<<endl;
}

signed main(){
	//while(1)
	solve();
}

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

using namespace std;

template<typename T>
class FenwickTree {
    int n;
    vector<T> data;
public:
    FenwickTree(int n):n(n), data(n, 0){}
    T sum(int i, int j){
        if(i)return sum(0, j) - sum(0, i - 1);
        T res = 0;
        for(; j>=0; j=(j&(j+1))-1)res += data[j];
        return res;
    }
    void add(int k, T v){
        for(; k<n; k|=k+1)data[k] += v;
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    FenwickTree<int> ftree(n);
    while(q--){
        int com, x, y;
        cin >> com >> x >> y;
        if(com)cout << ftree.sum(x - 1, y - 1) << '\n'; else ftree.add(x - 1, y);
    }
    return 0;
}

Measured memory_bytes: 1536
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define left asdgashgrketwjklrej
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-9
#define M_PI 3.141592653589793
#define bsize 1024

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 200031;

int n,M,V,P;
int ar[N];
vector<pair<int,int> > order;

long long pref_sum[N*4];

int ans;

void build(){
	for (int i=1;i<=n;i++){
		pref_sum[i]=pref_sum[i-1]+ar[i];
	}
}

bool valid(int ps){
	if (ps<=P) // already good
		return true;
	long long ohead=ar[P]-ar[ps];
	if (ohead>M)
		return false; // can't make it
	long long S=pref_sum[ps-1]-pref_sum[P-1];
	long long cnt=(ps-1)-(P-1);
	long long baseline=1ll*cnt*ar[ps];
	long long toremove=S-baseline;
	long long can_remove=(n-V)*1ll*M;
	return (can_remove>=toremove);
}

int main(){
//    freopen("apache.in","r",stdin);
//    freopen("apache.out","w",stdout);
 //   freopen("input.txt", "r", stdin);
 //   freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
 //   cin.tie(0);

    cin>>n>>M>>V>>P;

    for (int i=1;i<=n;i++){
    	cin>>ar[i];
    	order.push_back(make_pair(ar[i],i));
    }

    sort(order.begin(),order.end());
    reverse(order.begin(),order.end());

    for (int i=0;i<order.size();i++){
    	ar[i+1]=order[i].first;
    }

    build();

    for (int i=1;i<=n;i++){
    	if (valid(i))
    		++ans;
    }

    cout<<ans<<endl;


    //    cin.get(); cin.get();
    return 0;
}


Measured memory_bytes: 2420
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<int> mat[300005];

class ELISDL {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll n, a, b; cin >> n >> a >> b;
      if (a+b > n+1) {
        cout << -1 << endl;
        return;
      }
      if (a*b < n) {
        cout << -1 << endl;
        return;
      }
      int now = 0;
      rep(i, a) {
        mat[i].clear();
      }

      for(int i=n; i>=1; i--) {
        if (mat[now].size() == b || now+i == a-1) {
          now++;
        }
        mat[now].push_back(i);
      }
      rep(i, a) {
        reverse(all(mat[i]));
      }

      set<int, greater<>> st;
      rep(i, a) {
        st.insert(i);
      }

      while(true) {
        bool flag = false;
        vector<int> remove;
        for(auto& i: st) {
          if (!mat[i].empty()) {
            cout << mat[i].back() << ' ';
            mat[i].pop_back();
            flag = true;
          } else {
            remove.push_back(i);
          }
        }
        for(auto e: remove) {
          st.erase(e);
        }
        if (!flag) {
          break;
        }
      }
      cout << endl;
    }
};

signed main() {
  ELISDL solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_DIGIT 100

ll N, K;
vector<ll> A;

// i ビット目の j の数
vector< vector<ll> > cnt;

ll dp[MAX_DIGIT][2];

// n の最上位ビットを求める
static inline ll get_bit(ll n) {
    ll ret = 0;
    for(ll i = 0; i < 63; ++i) {
        if( (n >> i) & 1) { ret = i; }
    }
    return ret;
}

// i ビット目を見ていて、ここまでのパターンが K と同じなら tight = 1
ll dfs(ll i, ll tight) {
    if(i < 0) { return 0; }

    ll& ret = dp[i][tight];
    if(~ret) { return ret; }
    ret = 0;

    // 0 にした場合
    ll cand0 = (1LL << i) * cnt[i][1];
    // 1 にした場合
    ll cand1 = (1LL << i) * cnt[i][0];

    // tight が 0 ならどちらでも取れる
    if(tight == 0) {
        ret = max(cand0, cand1) + dfs(i-1, 0);
    }
    else {
        if((K >> i) & 1) {
            // K の該当ビットが 1 なら両方とれる
            ret = cand0 + dfs(i-1, 0);
            ret = max(ret, cand1 + dfs(i-1, 1));
        }
        else {
            ret = cand0 + dfs(i-1, 1);
        }
    }
    return ret;
}

signed main()
{
    ll max_bit = 0;   // A の最大ビット数
    cin >> N >> K;
    A.resize(N);
    REP(i, N) {
        cin >> A[i];
        max_bit = max(max_bit, get_bit(A[i]));
    }
    max_bit = max(max_bit, get_bit(K));

    // cnt の作成
    cnt.assign(max_bit + 2, vector<ll>(2, 0));
    REP(i, N) {
        for(ll digit = 0; digit <= max_bit; ++digit) {
            ll d_bit = (A[i] >> digit) & 1;
            cnt[digit][d_bit]++;
        }
    }

    MINUS(dp);
    ll ans = dfs(max_bit + 1, 1);
    assert(ans >= 0);
    printf("%lld\n", ans);

    return 0;
}


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

int selectionSort(int a[], int n) {
  int cnt = 0;
  for (int i = 0; i < n-1; i ++) {
    int minj = i;
    for (int j = i+1; j < n; j ++) {
      if (a[j] < a[minj]) {
        minj = j;
      }
    }
    swap(a[i], a[minj]);
    if (i != minj) cnt ++;
  }
  return cnt;
}

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

  int cnt = selectionSort(a, n);

  for (int i = 0; i < n; i ++) {
    if (i) cout << " ";
    cout << a[i];
  }
  cout << endl;
  cout << cnt << endl;
}



Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;
string s2;

int main() {
	while (cin >> s&&s != ".") {
		cin >> s2;
		string t = "";
		string buf = "", buf2 = "";
		vector<string> vs[2];
		bool f = 0;
		rep(i, s.size()) {
			if (s[i] == '\"') {
				if (f) {
					vs[0].push_back(t);
					t.clear();
				}
				f = !f;
			}
			if (f)t += s[i];
			else buf += s[i];
		}
		t = "";
		f = 0;
		rep(i, s2.size()) {
			if (s2[i] == '\"') {
				if (f) {
					vs[1].push_back(t);
					t.clear();
				}
				f = !f;
			}
			if (f)t += s2[i];
			else buf2 += s2[i];
		}
		bool ok = buf == buf2;
		ll cnt = 0;
		if (vs[0].size() == vs[1].size()) {
			rep(i, vs[0].size()) {
				if (vs[0][i] != vs[1][i])cnt++;
			}
		}
		else cnt = INF;
		if (s == s2)cout << "IDENTICAL" << endl;
		else if (ok&&cnt <= 1)cout << "CLOSE" << endl;
		else cout << "DIFFERENT" << endl;
	}
}


Measured memory_bytes: 3096
#include <iostream>
# define ll long long
#include<set>

using namespace std;

int main()
{
   ll n;
   set<ll>s;
   cin>>n;
   for(ll i=0;i<n;i++)
   {
       ll t;
       cin>>t;
       s.insert(t);
   }
   if(s.size()==n)
   cout<<"YES"<<endl;
   else
   cout<<"NO"<<endl;
   
   return 0;
}

Measured memory_bytes: 9600
#include <iostream>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(b-a > k || c-a >k || d-a >k || e-a>k){
    cout << ":(" << endl;
    return 0;
  }
  if(c-b > k || d-b >k || e-b >k){
    cout << ":(" << endl;
    return 0;
  }
  if(d-c > k || e-c >k || d-c >k){
    cout << ":(" << endl;
    return 0;
  }
  cout << "Yay!" << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int ,input().split()))
MOD = 10**9+7

sum = 0
for i in range (N):
    sum += A[i]

ans = 0
for i in range(N):
    sum -= A[i]
    ans += (A[i] * sum) % MOD

ans = ans % MOD
print(ans)

Measured memory_bytes: 31612
import java.util.*;

public class Main {

	private static List<Integer> getStrings(Scanner sc, int num) {
		List<Integer> stringList = new ArrayList<>();
		while(num>0) {
			int nextInt = sc.nextInt();
			stringList.add(nextInt);
			num--;
		}
		return stringList;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> array = getStrings(sc, n);
		array.sort(Integer::compareTo);
		int[] result = new int[1000001];
		int max = array.get(array.size()-1);
		int count = 0;
		for (int i = 0; i < array.size(); i++) {
			int m = array.get(i);
			if (result[m] == 0) {
				for (int j = m; j <= 1000000; j+=m) {
					result[j]++;
				}
			} else {
				result[m]++;
			}
		}
		for (int i = 0; i < array.size(); i++) {
			if (result[array.get(i)] == 1) {
				count++;
			}
		}
		System.out.println(count);
		return;
	}

}


Measured memory_bytes: 65136
def insertionSort(a, n, g, cnt)
  g.upto(n-1) do |i|
    v = a[i]
    j = i - g
    while j >= 0 && a[j] > v do
      a[j+g] = a[j]
      j = j - g
      cnt += 1
    end
    a[j+g] = v
  end
  return cnt
end

def shellSort(a, n)
  cnt = 0
  m = 0
  g = [1]
  while g[m] * 3 + 1 < n do
    g[m+1] = g[m] * 3 + 1
    m += 1
  end
  gStr = ''
  (m).downto(0) do |i|
    gStr << g[i].to_s
    gStr << ' '
    cnt = insertionSort(a, n, g[i], cnt)
  end
  puts m + 1
  puts gStr
  puts cnt
  n.times do |i|
    puts a[i]
  end
end

n = gets.to_i
a = []
n.times do
  a.push(gets.to_i)
end
shellSort(a, n)

Measured memory_bytes: 16692
s = input()
t = input()
slist = [ord(i) for i in s]
tlist = [ord(i) for i in t]
slist.sort()
tlist.sort(reverse=True)

lim=0
if len(s)>len(t):lim = len(t)
else:lim = len(s) 

for i in range(lim):
  if slist[i]<tlist[i]:
    print("Yes")
    exit()
  elif slist[i]>tlist[i]:
    print("No")
    exit()
if len(t)>len(s):
  print("Yes")
  exit()
print("No")

Measured memory_bytes: 3064
s = []
a = [0, 0, 0]
b = [0, 0, 0]
for i in range(3):
    s.append(list(map(int, input().split())))

b[0] = s[0][0]
b[1] = s[0][1]
b[2] = s[0][2]

a[1] = s[1][0] - b[0]
a[2] = s[2][0] - b[0]

for i in range(1, 3):
    for j in range(1, 3):
        if s[i][j] != a[i] + b[j]:
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 3064