akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
struct Cake{
    long long x, y, z;
    Cake(){x=y=z=0;}
    Cake(long long x_, long long y_, long long z_): x(x_), y(y_), z(z_){}
    long long calc(bool xp, bool yp, bool zp) const{
        long long res = 0;
        if(xp) res += x;
        else res -= x;
        if(yp) res += y;
        else res -= y;
        if(zp) res += z;
        else res -= z;
        return res;
    }
    Cake operator +(const Cake &r){
        return Cake(x + r.x, y + r.y, z + r.z);
    }
};
int main(){
    int N; cin>>N;
    int M; cin>>M;
    vector<Cake> A(N, Cake());
    for(int i=0; i<N; i++){
        ll x, y, z; cin>>x>>y>>z;
        A[i] = Cake(x, y, z);
    }
    ll res = 0;
    for(int x=0; x<2; x++){
        for(int y=0; y<2; y++){
            for(int z=0; z<2; z++){
                if(x and y and z) sort(A.begin(), A.end(), [&](const Cake a, const Cake b){return a.calc(1, 1, 1)> b.calc(1, 1, 1);});
                else if(x and y) sort(A.begin(), A.end(), [&](const Cake a, const Cake b){return a.calc(1, 1, 0)> b.calc(1, 1, 0);});
                else if(y and z) sort(A.begin(), A.end(), [&](const Cake a, const Cake b){return a.calc(0, 1, 1)> b.calc(0, 1, 1);});
                else if(z and x) sort(A.begin(), A.end(), [&](const Cake a, const Cake b){return a.calc(1, 0, 1)> b.calc(1, 0, 1);});
                else if(x) sort(A.begin(), A.end(), [&](const Cake a, const Cake b){return a.calc(1, 0, 0)> b.calc(1, 0, 0);});
                else if(y) sort(A.begin(), A.end(), [&](const Cake a, const Cake b){return a.calc(0, 1, 0)> b.calc(0, 1, 0);});
                else if(z) sort(A.begin(), A.end(), [&](const Cake a, const Cake b){return a.calc(0, 0, 1)> b.calc(0, 0, 1);});
                else sort(A.begin(), A.end(), [&](const Cake a, const Cake b){return a.calc(0, 0, 0)> b.calc(0, 0, 0);});
                Cake score(0, 0, 0);
                for(int i=0; i<M; i++){
                    score = score + A[i];
                }
                res = max(res, abs(score.x)+abs(score.y)+abs(score.z));
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input().strip())
L = [int(x) for x in input().strip().split(" ")]

# L = sorted(L, reverse=True)
Len = len(L)
cnt = 0
for i in range(Len):
    for j in range(i, Len):
        if L[i] == L[j]:
            continue
        for k in range(j, Len):
            if L[i] == L[k] or L[j] == L[k]:
                continue
            longer = max(L[i], L[j], L[k])
            other = L[i] + L[j] + L[k] - longer
            if longer < other:
                cnt += 1
print(cnt)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,s,n) for(ll i=(s);i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1000000000000000;

vector<vector<pair<ll,ll>>> yen(100010);
vector<vector<pair<ll,ll>>> snuuk(100010);
vll dyen(100010,INF);
vll dsnuuk(100010,INF);

void dijkstrayen(ll s){
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> q;
    dyen[s]=0;
    q.push(mp(0,s));
    while(!q.empty()){
        auto p=q.top();q.pop();
        ll v=p.second;
        if(dyen[v]<p.first)continue;
        for(auto e:yen[v]){
            if(dyen[e.first]>dyen[v]+e.second){
                dyen[e.first]=dyen[v]+e.second;
                q.push(mp(dyen[e.first],e.first));
            }
        }
    }
}
void dijkstrasnuuk(ll t){
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> q;
    dsnuuk[t]=0;
    q.push(mp(0,t));
    while(!q.empty()){
        auto p=q.top();q.pop();
        ll v=p.second;
        if(dsnuuk[v]<p.first)continue;
        for(auto e:snuuk[v]){
            if(dsnuuk[e.first]>dsnuuk[v]+e.second){
                dsnuuk[e.first]=dsnuuk[v]+e.second;
                q.push(mp(dsnuuk[e.first],e.first));
            }
        }
    }
}

int main(){
    ll n,m,s,t;cin>>n>>m>>s>>t;
    rep(i,m){
        ll u,v,a,b;cin>>u>>v>>a>>b;
        yen[u].push_back(mp(v,a));
        yen[v].push_back(mp(u,a));
        snuuk[u].push_back(mp(v,b));
        snuuk[v].push_back(mp(u,b));
    }
    dijkstrayen(s);
    dijkstrasnuuk(t);
    vll d(n+1);
    d[0]=INF+1;
    rep2(i,1,n+1)d[i]=dyen[i]+dsnuuk[i];
    vll sum(n);
    ll mi=d[n];
    for(ll i=n-1;i>=0;i--){
        sum[i]=INF-mi;
        mi=min(mi,d[i]);
    }
    rep(i,n)cout<<sum[i]<<endl;
}

Measured memory_bytes: 19908
n = int(input())
s = list(input())
ans = 0
r = [0 for i in range(n)]
g = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
    if s[i] == "R":
        r[i] += 1
    elif s[i] == "G":
        g[i] += 1
    else:
        b[i] += 1
    if i > 0:
        r[i] += r[i-1]
        g[i] += g[i-1]
        b[i] += b[i-1]
ju = [0,0,0]
ju2 = ["R","G","B"]
for i in range(n-2):
    for j in range(3):
        if s[i] == ju2[j]:
            ju[j] += 1
    for j in range(i+1,n-1):
        #print(ans)
        for k in range(3):
            if s[j] == ju2[k]:
                ju[k] += 1
                key = k
        if ju[key] == 1:
            if ju[0] == 0:
                ans += r[n-1] - r[j]
                if j + (j-i) < n:
                    if r[j+(j-i)] > r[j+(j-i)-1]:
                        ans -= 1
            
            elif ju[1] == 0:
                ans += g[n-1] - g[j]
                if j + (j-i) < n:
                    if g[j+(j-i)] > g[j+(j-i)-1]:
                        ans -= 1
            else:
                ans += b[n-1] - b[j]
                if j + (j-i) < n:
                    if b[j+(j-i)] > b[j+(j-i)-1]:
                        ans -= 1
        ju[key] -= 1
    ju = [0,0,0]
print(ans)
            


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

int main(){
    string S;
    cin >> S;
    ll N = S.size();
    ll X = 0;
    ll cnt = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'B') {
            X += i;
            cnt++;
        }
    }
    cout << N*(N-1)/2 - (N-cnt)*(N-cnt-1)/2 - X << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

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

   int count = 0;
   for(int i=1; i<N+1; i=i+2){
      int n = 1;
      for(int j=1; j<N/2+1; ++j){
	 if(i%j==0) ++n;
      }
      if(n==8) ++count;
   }
   std::cout << count << std::endl;

   return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int X = Integer.parseInt(sc.next());
            int N = Integer.parseInt(sc.next());
            boolean[] p = new boolean[102];

            for (int i = 0; i < N; i++) {
                 p[Integer.parseInt(sc.next())] = true;
            }
            for (int i = 0; i <= 50; i++) {
                if (X - i >= 0 && !p[X - i]) {
                    System.out.println(X - i);
                    return;
                }
                if (X + i <= 101 && !p[X + i]) {
                    System.out.println(X + i);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 35636
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
using info = pair<ll,P>;

vector<pair<int,P>> g[50];
int main() {
  int n,m,s;
  cin >> n >> m >> s;
  rep(i,m){
    int u,v,a,b;
    cin >> u >> v >> a >> b;
    --u; --v;
    g[u].emplace_back(v,P(a,b));
    g[v].emplace_back(u,P(a,b));
  }
  vector<int> c(n), d(n);
  rep(i,n) cin >> c[i] >> d[i];

  vector<vector<ll>> dp(n,vector<ll>(2505, 1e18L));
  priority_queue<info,vector<info>,greater<info>> q;
  auto push = [&](int v, int s, ll t){
    if(s<0) return;
    if(dp[v][s]<=t) return;
    dp[v][s] = t;
    q.emplace(t,P(v,s));
  };
  push(0,min(s,2500),0);
  while(!q.empty()){
    info info = q.top(); q.pop();
    int u = info.second.first;
    int s = info.second.second;
    ll t = info.first;

    if(dp[u][s]!=t) continue;
    push(u,min(s+c[u],2500),t+d[u]);
    for(pair<int,P> e:g[u]){
      int v = e.first;
      P p = e.second;
      push(v,s-p.first,t+p.second);
    }
  }
  
  rep(i,n-1){
    ll ans = 1e18L;
    for(ll t:dp[i+1]) ans = min(ans,t);
    cout << ans << endl;
  }
}


Measured memory_bytes: 6236
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int D;
int X[200010],Y[200010];

signed main(){
	cin>>N>>D;
	REP(i,N){
		cin>>X[i]>>Y[i];
	}
	int ans=0;
	REP(i,N){
		if(X[i]*X[i]+Y[i]*Y[i]<=D*D){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6764
#include <bits/stdc++.h>
        using namespace std;
         
        int main() {
          int a,b,c;
          cin >> a >> b >> c;//.at(0) >> s.at(1) >> s.at(2) >> s.at(3);
          //sort(s.begin(),s.end());
          
          if(a>c&&c>b) cout << "Yes" << endl;
          else if(a<c&&c<b)cout << "Yes" << endl;
          else cout << "No" << endl;
          return 0;
        }

Measured memory_bytes: 256
N=int(input())
w=[input() for i in range(N)]
rule = 'Yes'
same = False
for x in range(1, N):
    rule='Yes'
    same = False
    if w[x-1][len(w[x-1])-1] != w[x][0]:
       rule = 'No'
       break
    for y in range(x):
        if w[y]==w[x]:
            rule='No'
            same = True
            break
    if same:
        break
print(rule)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
signed main(){
    int n;
    cin>>n;
    map<int,int> ma;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        if(ma.find(t)==ma.end()){
            ma.insert(P(t,1));
        }else{
            ma[t]++;
        }
    }
    int a=0,b=0;
    for(auto i:ma){
        if(i.se>=4){
            a=i.fi;
            b=i.fi;    
        }
        else if(i.se>=2){
            b=a;
            a=i.fi;
        }
    }
    cout<<a*b<<endl;
    return 0;
}

Measured memory_bytes: 6528
function Main(input) {
  input = input.split("\n");
  var H = parseInt(input[0]);
  var W = parseInt(input[1]);
  var N = parseInt(input[2]);
  var ans = Math.ceil(N/Math.max(H,W));

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21956
#include<cstdio>
#include<algorithm>

//#define	mp		make_pair
#define	num		first
#define	suit	second

using namespace std;

typedef	pair<int,char>	pic;

int base[4][14],ratio[9];

int isStraight(pic hand[5]){
	sort(hand,hand+5);
	if(hand[0].num==1 && hand[1].num==10 && hand[2].num==11 && hand[3].num==12 && hand[4].num==13)
		return 1;
	for(int i=1;i<5;i++)	if(hand[0].num+i!=hand[i].num)	return -1;
	return hand[4].num;
}

bool isFlush(const pic hand[5]){
	for(int i=1;i<5;i++)	if(hand[0].suit!=hand[i].suit)	return false;
	return true;
}

bool isFourCard(const pic hand[5]){
	int buc[14]={};
	for(int i=0;i<5;i++)	buc[hand[i].num]++;
	for(int i=1;i<=13;i++)	if(buc[i]==4)	return true;
	return false;
}

bool isFullHouse(const pic hand[5]){
	int buc[14]={};
	for(int i=0;i<5;i++)	buc[hand[i].num]++;
	bool _2=false,_3=false;
	for(int i=1;i<=13;i++){
		if(buc[i]==2)	_2=true;
		if(buc[i]==3)	_3=true;
	}
	return _2&&_3;
}

bool isThreeCard(const pic hand[5]){
	int buc[14]={};
	for(int i=0;i<5;i++)	buc[hand[i].num]++;
	for(int i=1;i<=13;i++)	if(buc[i]==3)	return true;
	return false;
}

bool isTwoPair(const pic hand[5]){
	int buc[14]={};
	for(int i=0;i<5;i++)	buc[hand[i].num]++;
	int _2=0;
	for(int i=1;i<=13;i++)	if(buc[i]==2)	_2++;
	return _2==2;
}

bool isOnePair(const pic hand[5]){
	int buc[14]={};
	for(int i=0;i<5;i++)	buc[hand[i].num]++;
	for(int i=1;i<=13;i++)	if(buc[i]==2)	return true;
	return false;
}

int calcHand(pic hand[5]){
	int st=isStraight(hand);
	bool fl=isFlush(hand);
	if(st==1 && fl)			return ratio[8];
	if(st!=-1 && fl)		return ratio[7];
	if(isFourCard(hand))	return ratio[6];
	if(isFullHouse(hand))	return ratio[5];
	if(fl)					return ratio[4];
	if(st!=-1)				return ratio[3];
	if(isThreeCard(hand))	return ratio[2];
	if(isTwoPair(hand))		return ratio[1];
	if(isOnePair(hand))		return ratio[0];
	return 0;
}

int calcBase(const pic hand[5]){
	static int suit2id[128];
	suit2id['S']=0;
	suit2id['C']=1;
	suit2id['H']=2;
	suit2id['D']=3;
	int point=0;
	for(int i=0;i<5;i++)	point+=base[suit2id[hand[i].suit]][hand[i].num];
	return point;
}

int main(){
	for(int n,t=0;~scanf("%d",&n);t++){
		if(t>0)	puts("");
		for(int i=0;i<4;i++)for(int j=1;j<=13;j++)	scanf("%d",base[i]+j);
		for(int i=0;i<9;i++)	scanf("%d ",ratio+i);
		while(n--){
			pic hand[5];
			for(int i=0;i<5;i++){
				char t;
				scanf("%c%c ",&t,&hand[i].suit);
				if     (t=='A')	hand[i].num=1;
				else if(t=='T')	hand[i].num=10;
				else if(t=='J')	hand[i].num=11;
				else if(t=='Q')	hand[i].num=12;
				else if(t=='K')	hand[i].num=13;
				else			hand[i].num=t-'0';
			}
			printf("%d\n",calcHand(hand)*calcBase(hand));
		}
	}
	return 0;
}

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

int main() {
        int h, w, n; cin >> h >> w >> n;
        if(h > w) swap(h, w);

        for(int i = 1; i <= h; i++) {
            if(i * w >= n) {
                cout << i << endl;
                return 0;
            }
        }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;

    double ans = 0;

    for (int i = 0; i < N; i++){
        double x;
        cin >> x;

        string u;
        cin >> u;

        if (u == "JPY"){
            ans += x;
        }
        else {
            ans += x * 380000.0;
        }
    }

    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 

bool check(int n,int i)
{
  while( n || i )
  {
    if((n&1) < (i&1)) return false;
    n >>= 1;
    i >>= 1;
  }
  return true;
}

int main()
{
  __;
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> v;
  for(int i=0;i<n;i++)
  {
    if(check(n-1,i)) 
    {
      v.pu(i);
      continue;
    }
  }

  set<char> se;
  bool zero = false;
  for(int i=0;i<s.size();i++) 
  {
    if(s[i] == '1') zero = true;
    s[i]--;
    se.insert(s[i]);
  }

  int x = 0;
  if(se.size() == 3)
  {
    for(int i=0;i<v.size();i++)
    {
      if(s[v[i]] == '1') x ^= 1;
      // t(s[v[i]],v[i],x);
    }
  }
  else if(se.size() == 2)
  {
    for(int i=0;i<v.size();i++)
    {
      if(s[v[i]] != '0') x ^= s[v[i]]-'0';
    }
    if(!zero) 
    {
      cout << 1 << endl;
      return 0;
    }
  }
  else 
  {
    if(s.size() == 1) cout << (char)(s[0]+1) << endl;
    else cout << 0 << endl;
    return 0;
  }

  cout << x << endl;
  return 0;
}


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

namespace MyProgram{
    public class Program
    {	
        public static void Main(string[] args)
    	{
            int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();    
            int W = input[0];
            int H = input[1];
            int N = input[2];
            int maxX = W;
            int minX = 0;
            int maxY = H;
            int minY = 0;

            int x,y,a;            
            for(int i = 0 ; i < N ; i++)
            {
                input = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
                x = input[0];
                y = input[1];
                a = input[2];
                if(a == 1)
                {
                    minX = Math.Max(minX,x);
                }
                else if(a == 2)
                {
                    maxX = Math.Min(maxX,x);
                }
                else if(a == 3)
                {
                    minY = Math.Max(minY,y);
                }
                else if(a == 4)
                {
                    maxY = Math.Min(maxY,y);
                }
            }
            int ansX = Math.Max(0,(maxX-minX));
            int ansY = Math.Max(0,(maxY-minY));
            
            int ans = ansX * ansY;
            Console.WriteLine(ans);
    	}
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define CALC {if(sign==0) term=term*x; else term=term/x;}

int num;
char str[101];

int smartCalc(){
  int sum=0, term=1, sign=0, x=0;
  while(1){
    switch(str[num]){
    case '*':
      CALC;
      sign=0;
      x=0;
      break;
    case '/':
      CALC;
      sign=1;
      x=0;
      break;
    case '+':
      CALC;
      sum += term;
      term=1;
      sign = 0;
      x =0;
      break;
    case '-':
      CALC;
      sum += term;
      term = -1;
      sign = 0;
      x=0;
      break;
    case '(':
      num += 1;
      x = smartCalc();
      break;
    case ')':
    case '=':
      CALC;
      sum += term;
      return sum;
      break;
    default:
      x = x*10 + str[num] - '0';
    }
    num += 1;
  }
}
int main(){
  int n, i;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%s", str);
    num=0;
    printf("%d\n", smartCalc());
  }
  return 0;
}

Measured memory_bytes: 596
import sys

def solve():
      input = sys.stdin.readline
      S = input().strip("\n")
      T = input().strip("\n")
      a = 0
      for i in range(len(S)):
            if S[i] != T[i]: a += 1
      print(a)

      return 0

if __name__ == "__main__":
      solve()

Measured memory_bytes: 9352
s = input()
a = [int(c) for c in s]
b = a[:]
ans1 = 0
ans0 = 0

#最初が1
if a[0] == 0:
    a[0] = 1
    ans1 += 1
for i in range(1,len(s)):
    if a[i] == a[i-1]:
        a[i] = (a[i-1]+1)%2
        ans1 += 1
#最初が0
if b[0] == 1:
    b[0] = 0
    ans0 += 1
for i in range(1,len(s)):
    if b[i] == b[i-1]:
        b[i] = (b[i-1]+1)%2
        ans0 += 1
print(min(ans1,ans0))

Measured memory_bytes: 4860
from bisect import bisect_left
n=int(input())
a=list(map(int,input().split()))
num1=[0]*n
num2=[0]*n
for i in range(n):
    num1[i]=i+1+a[i]
    num2[i]=i+1-a[i]
num2_sort=sorted(list(set(num2)))
num2_set=set(num2)
num2_cnt=[0]*len(num2_sort)
for i in range(n):
    b=bisect_left(num2_sort,num2[i])
    num2_cnt[b]+=1
ans=0
for i in range(n):
    if num1[i] in num2_set:
        c=bisect_left(num2_sort,num1[i])
        ans+=num2_cnt[c]
    d=bisect_left(num2_sort,num2[i])
    num2_cnt[d]-=1
print(ans)


Measured memory_bytes: 133988
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int par[N], rnk[N], sz[N];
int findroot(int node) {
  if (par[node] == node)
    return node;
  else {
    par[node] = findroot(par[node]);
    return par[node];
  }
}
void dounion(int x, int y) {
  if (rnk[x] > rnk[y]) {
    par[y] = x;
    sz[x] += sz[y];
  }
  else if (rnk[x] < rnk[y]) {
    par[x] = y;
    sz[y] += sz[x];
  }
  else {
    par[x] = y;
    sz[y] += sz[x];
    rnk[y]++;
  }
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    sz[i] = 1;
    par[i] = i;
  }
  pair<int, int> edg[m];
  for (int i = 0; i < m; i++) {
    cin >> edg[i].first >> edg[i].second;
    edg[i].first--;
    edg[i].second--;
  }
  long long ans[m], cnt = (n - 1LL) * n / 2;
  for (int i = m - 1; i >= 0; i--) {
    ans[i] = cnt;
    int x = findroot(edg[i].first);
    int y = findroot(edg[i].second);
    if (x != y) {
      cnt -= 1LL * sz[x] * sz[y];
      dounion(x, y);
    }
  }
  for (int i = 0; i < m; i++)
    cout << ans[i] << '\n';
  return 0;
}


Measured memory_bytes: 6328
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
//#define MOD 1000000007
using namespace std;
typedef long long ll;

const int MOD = 998244353;
const ll MAX = 1000010;

ll add(ll x, ll y){
  x += y;
  if (x >= MOD) return x - MOD;
  return x;
}
ll sub(ll x, ll y){
  x -= y;
  if (x < 0) return x + MOD;
  return x;
}
ll mult(ll x, ll y){
  return (x * y) % MOD;
}
ll powm(ll x, ll p){
  if (p == 0) return 1;
  if (p & 1) return mult(x, powm(x, p - 1));
  return powm(mult(x, x), p / 2);
}
ll modinv(ll a) {
  return powm(a, MOD-2);
}

ll w[MAX]; // index:i のiを除く約数xについて Sum of w[x] が 1/i な w[i]
void winit(){
  reps(i,1,MAX){
    w[i]=modinv(i);
  }
  reps(i,1,MAX){
    for(int j=2*i; j<MAX; j+=i){
      w[j] += MOD-w[i];
      w[j] %= MOD;
    }
  }
}

void Main(){

  int N;
  cin>>N;

  winit();

  ll a[MAX]={};

  rep(i,N){
    ll aa; cin>>aa;
    ++a[aa];
  }

  ll ans=0;
  reps(i,1,MAX){
    ll sum1=0; ll sum2=0;
    for(ll j=i; j<MAX; j+=i){
      sum1+=j*a[j];
      sum1%=MOD;
      sum2+=a[j]*((j*j)%MOD)%MOD;
      //sum2+=(a[j]*j%MOD)*j%MOD;
      sum2%=MOD;
    }
    sum1*=sum1;
    sum1%=MOD;

    ll here=(w[i]*(sum1-sum2+MOD))%MOD;
    ans+=here;
    ans%=MOD;
  }

  ans*=modinv(2);
  ans%=MOD;

  cout<< ans <<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 15872
function main(data){
    input = data.split("\n");
    len = input[0]
    str = input[1];
    temp = input[1].split("");
    n = "";
    m = "";
    for(i = len; i >= 0; i -= 1){
        if(temp[i] === ")"){
            for(j = i - 1; j >= 0; j -= 1){
                if(temp[j] === "("){
                    temp.splice(i,1);
                    temp.splice(j,1);
                    break;
                }
            }
        }
    }
    for(i = 0,len = temp.length; i < len; i+=1){
        if(temp[i] === ")"){
            n += "("
        }else{
            m += ")";
        }
    }
    console.log(n + str + m)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7496
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	bb := make(books, n)
	for i := 0; i < n; i++ {
		bb[i].city = getNextString(scanner)
		bb[i].point = getNextInt(scanner)
		bb[i].i = i
	}
	sort.Sort(bb)
	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, bb[i].i+1)
	}
}

type book struct {
	city     string
	point, i int
}
type books []book

func (a books) Len() int      { return len(a) }
func (a books) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a books) Less(i, j int) bool {
	c := strings.Compare(a[i].city, a[j].city)
	if c == 0 {
		return a[i].point > a[j].point
	}
	return c == -1
}


Measured memory_bytes: 640
#include <iostream>
#include <limits.h>

using namespace std;

int dp[100][100];
int p[101];
int n;

void solve() {
	for (int m = n; m > 0; m--) {
		for (int t = 0, i = 0, j = n - m + 1; t < n && j < n; t++) {
			dp[i][j] = INT_MAX;
			for (int k = i; k < j; k++) {
				int temp = dp[i][k] + dp[k + 1][j] + p[i] * p[k + 1] * p[j + 1];
				if (temp < dp[i][j]) {
					dp[i][j] = temp;
				}
			}
			i++;
			j++;
		}
	}
}

int main() {
	int a, b;
	cin >> n >> a;

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

	solve();
	cout << dp[0][n - 1] << endl;

	return 0;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    string s;
    cin >> s;
    int cntRed  = 0;
    int cntBlue = 0;
    for (auto c : s) {
        if (c == '1')
            cntBlue++;
        else
            cntRed++;
    }

    cout << min(cntBlue, cntRed) * 2 << endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<pll> vll; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL);
    ll n,m,k,i,j,l;
    cin>>n>>m>>k;
    vector<ll>row(n+1,0);
    vector<ll>column(m+1,0);
    vector<pii>q;
    for(i=0;i<k;i++){
        cin>>j>>l;
        q.push_back({j,l});
        row[j]++;column[l]++;
    }
    long long ans=0,rowMaxx=0,columnMaxx=0,rowMaxxCount=0,columnMaxxCount=0;
    set<ll>r,c;
    for(i=1;i<=n;i++){
        rowMaxx=max(rowMaxx,row[i]);
    }
    for(i=1;i<=n;i++){
        if(row[i]==rowMaxx)
        {rowMaxxCount++;
        r.insert(i);}
    }
    for(i=1;i<=m;i++)columnMaxx=max(columnMaxx,column[i]);
    for(i=1;i<=m;i++){
        if(column[i]==columnMaxx){
            columnMaxxCount++;
        c.insert(i);}
    }
    ll count=0;
    for(i=0;i<q.size();i++){
        if(r.find(q[i].first)!=r.end()&&c.find(q[i].second)!=c.end())count++;
    }
    // cout<<count<<endl;
    if(count<rowMaxxCount*columnMaxxCount)cout<<rowMaxx+columnMaxx<<endl;
    else cout<<rowMaxx+columnMaxx-1<<endl;
    return 0;
}


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

int main(){
  char a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a==b&&a==c) cout << "Yes" << endl;
  else if(b==c&&b==d) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
//#include "convinienceBox.h"
using namespace std;

int main(){
    string S,T;
    cin>>S>>T;
    int cnt = 0;
    for(int i=0; i<S.length(); i++){
        if(S[i]!=T[i]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

int main() {
  int N,A,B,C;
  int X[3][3],Y[3][3];
  Y[0][0]=0;
    Y[0][1]=0;
    Y[0][2]=0;
    Y[1][0]=0;
    Y[1][1]=0;
    Y[1][2]=0;
    Y[2][0]=0;
    Y[2][1]=0;
    Y[2][2]=0;
  cin>>X[0][0]>>X[0][1]>>X[0][2]>>X[1][0]>>X[1][1]>>X[1][2]>>X[2][0]>>X[2][1]>>X[2][2];
  cin >>N;
  for(int i=0;i<N;i++){
    cin>>B;
    for(int j=0;j<3;j++){
      for(int u=0;u<3;u++){
        if(X[j][u]==B){
          Y[j][u]=1;
        }
      }
    }
  }
  if((Y[0][0]==1&&Y[0][1]==1&&Y[0][2]==1)||(Y[1][0]==1&&Y[1][1]==1&&Y[1][2]==1)||(Y[2][0]==1&&Y[2][1]==1&&Y[2][2]==1)||(Y[0][0]==1&&Y[1][1]==1&&Y[2][2]==1)||(Y[2][0]==1&&Y[1][1]==1&&Y[0][2]==1)||(Y[2][0]==1&&Y[1][0]==1&&Y[0][0]==1)||(Y[2][1]==1&&Y[1][1]==1&&Y[0][1]==1)||(Y[0][2]==1&&Y[1][2]==1&&Y[2][2]==1)){
  cout <<"Yes"<< endl;
}
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);

  if((a|b|c)&1) puts("0");
  else if(a==b && b==c) puts("-1");
  else {
    int k = 0;
    do {
      int newa = (b+c)/2;
      int newb = (a+c)/2;
      int newc = (a+b)/2;
      a = newa; b = newb; c = newc;
      k++;
    } while(!((a|b|c)&1));
    printf("%d\n", k);
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

void No(){
    cout<<"No"<<endl;
}
int main(){
    int n;
    cin>>n;
    if(n<=2){
        No();
        return 0;
    }
    if(n==3){
        cout<<"Yes"<<endl;
        for(int i=0;i<5;i++){
            cout<<i+1<<" "<<i+2<<endl;
        }
        return 0;
    }
    int m=1;
    while(m*2<=n) m*=2;

    if(m==n){
        No();
        return 0;
    }
    vector<pair<int,int>> res;
    auto line=[n,&res](vector<int> vec){
        for(int i=0;i+1<vec.size();i++){
            res.push_back({vec[i],vec[i+1]});
        }
        for(int i=0;i+1<vec.size();i++){
            res.push_back({n+vec[i],n+vec[i+1]});
        }
    };
    for(int i=m;i+1<=n;i+=2){
        line({i,i+1});
        res.push_back({i,1});
        res.push_back({1,i+1+n});
    }
    if(n%2==0){
        int x=n^1^m;
        res.push_back({n,m});
        res.push_back({x,n+n});
        vector<int> vec(m-1);
        vec[0]=1;
        vec[1]=x;
        int id=2;
        for(int i=2;i<m;i++){
            if(i!=x) vec[id++]=i;
        }
        line(vec);
        res.push_back({vec.back(),n+1});
    }
    else{
        vector<int> vec(m-1);
        iota(vec.begin(),vec.end(),1);
        line(vec);
        res.push_back({m-1,n+1});
    }
    assert(res.size()==2*n-1);
    cout<<"Yes"<<endl;
    for(auto p:res){
        cout<<p.first<<" "<<p.second<<endl;
    }

    return 0;
}


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

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    string s;
    cin >> s;
    bool c = true;
    if (s[0] != '2') c = false;
    if (s[1] != '0') c = false;
    if (s[2] != '1') c = false;
    if (s[3] != '9') c = false;
    if (s[4] != '/') c = false;
    if (s[5] != '0') c = false;
    if (!isdigit(s[6]) || s[6]-'0' > 4 || s[6] == '0') c = false;
    if (s[7] != '/') c= false;
    if (stoi(s.substr(8,9)) >= 31) c = false;
    if (c) cout << "Heisei" << endl;
    else cout << "TBD" << endl;
    cin >> s;
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b){
    return (a/gcd(a,b)*b);
}


int main() {
    int A,B,C,K,ans;
    cin >> A>>B>>C>>K;
    
    if(A >= K)
        ans = K;
    else if(A+B >= K)
        ans = A;
    else
        ans = A - (K - A - B);

    

    //string ans = ( flag ? "Yes" : "No" );
    //printf("%.8lf", ans);
    cout << ans;
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <queue>
#include <functional>
#include <iso646.h>
#include <bitset>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main()
{
	string x;
	cin >> x;
	if (x == "ABC")
	{
		cout << "ARC" << endl;
	}
	else
	{
		cout << "ABC" << endl;
	}

	return 0;
}


Measured memory_bytes: 3040
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する

bool check(string s) {
    if (s.back() == '1') return false;
    if (s[0] == '0') return false;
    for (int i = 0; i < s.size() - 1; ++i) {
        int j = s.size() - 2 - i;
        if (s[i] != s[j]) return false;
    }

    return true;
}

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


    string s;

    cin >> s;

    if (!check(s)) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> v; //e in vのときe頂点のつりーわんが作ればいい
    for (int i = 1; i * 2 < s.size(); ++i) {
        if (s[i] == '1') v.push_back(i + 1);
    }
    if (v.size() == 0) {
        //やべーやつ作ればいい
        for(int i = 2; i <= s.size(); ++i){
            cout << 1 << " " << i << endl;
        }
        return 0;
    }

    vector<int> dv;
    dv.push_back(v[0]);
    for (int i = 1; i < v.size(); ++i) {
        dv.push_back(v[i] - v[i - 1]);
    }

    int rest = s.size() - 1;
    using P = pair<int, int>;
    vector<P> ans;
    for (int i = 1; i <= v.size(); ++i) {
        ans.emplace_back(i, i + 1);
        rest--;
    }

    int tapi = v.size() + 2;
    for (int i = 1; i <= dv.size(); ++i) {
        for (int j = 0; j < dv[i-1] - 1; ++j) {
            ans.emplace_back(i, tapi++);
            rest--;
        }
    }

    while(rest > 0){
        rest--;
        ans.emplace_back(v.size() + 1, tapi++);
    }

    for(auto e: ans){
        cout << e.first << " " << e.second << endl;
    }


    return 0;
}


Measured memory_bytes: 2868
---- Quote(Alteration) ----
Queue = {}

function Queue.new()
    local obj = { buff = {}, top_index = 0}
    return setmetatable(obj,{__index = Queue})
end

function Queue:enqueue(x)
    table.insert(self.buff, x)
end

function Queue:dequeue()
    self.top_index = self.top_index + 1
    local value = self.buff[self.top_index]
    self.buff[self.top_index] = nil
    return value
end
--[[
function Queue:top()
    if #self.buff > 0 then
        return self.buff[self.top_index]
    end
end
--
function Queue:isEmpty()
    return #self.buff == 0
end
--]]
---- from http://www.nct9.ne.jp/m_hiroi/light/lua.html ----


--[[
ルンルン数の特徴:十以上の位がそれまでに出て来たルンルン数を流用している。
それゆえ、流用される側の数字の一の位に-1, 0, 1を加えた数と
流用される側の数字を10倍した数を足し、ルンルン数を生成する。
ただし、流用される側の数字の一の位の数字が0,9のときは生成しない場合を作っておく。
]]
local k = io.read("*n")
local lunluns = Queue.new()
for i = 1, 9 do
    lunluns:enqueue(i)
    if i == k then
        print(tostring(i)); os.exit()
    end
end

for i = 1, k do
    local x = 0LL + lunluns:dequeue()
    if x % 10 ~= 0 then
        lunluns:enqueue(10 * x + (x % 10) - 1)
        if #lunluns.buff == k then
            print(tostring(10 * x + (x % 10) - 1):sub(1, -3)); break
        end
    end
    lunluns:enqueue(10 * x + (x % 10))
    if #lunluns.buff == k then
        print(tostring(10 * x + (x % 10)):sub(1, -3)); break
    end
    if x % 10 ~= 9 then
        lunluns:enqueue(10 * x + (x % 10) + 1)
        if #lunluns.buff == k then
            print(tostring(10 * x + (x % 10) + 1):sub(1, -3)); break
        end
    end
end

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

using namespace std;

const double eps = 1e-10;
const double PI = acos(-1.0);
const int N = 2e5 + 10;

typedef long long LL;

int n;
LL k;
double ssin[N], ccos[N];

int dcmp(double x){
	if(fabs(x)<eps)	return 0;
	return x < 0 ? -1 : 1;
}

inline double sqr(double x){
	return x * x;
}

bool chk(double dx, double dy, int p, double s){
    double xc = ccos[p] - 1.0;
    double yc = ssin[p];

    double g = dx * yc - dy * xc;
    g = fabs(g) * 0.5;

	return dcmp(g - s) <= 0;
}

LL cal(int i, int l, int r, double s){
    if(l > r)	return 0;
    int len = r - l + 1;
    LL ret = 0, ret1 = 0;

    double dx = ccos[i] - 1.0;
    double dy = ssin[i];

    if(len & 1){
		ret1 = chk(dx, dy, l + r >> 1, s);
    }

    r = l + len / 2 - 1;
    int ll = l;

    int mid, key = l - 1;
    while(l <= r){
		mid = l + r >> 1;
        if(chk(dx, dy, mid, s)){
            key = max(key, mid);
            l = mid + 1;
        } else {
			r = mid - 1;
        }
    }

    ret = key - ll + 1;

	return ret * 2 + ret1;
}

bool ok(double s){
	LL sum = 0;
    for(int i=1; i<n; i++){
        sum = sum + cal(i, i+1, n-1, s);
        sum = sum + cal(i, 1, i-1, s);
    }
    sum = sum * n / 6;
    return sum >= k;
}

int main(){
	while(~scanf("%d %lld", &n, &k)){
		for(int i=0; i<n; i++){
            ssin[i] = sin(2.0*PI * i / n);
            ccos[i] = cos(2.0*PI * i / n);
		}

        double low=0.0, top=PI, ans=top, mid;
        while(top - low > eps){
			mid = (low + top) * 0.5;
            if(ok(mid)){
				ans = min(ans, mid);
				top = mid - eps;
            } else {
				low = mid + eps;
            }
        }
        printf("%.12f\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long

using namespace std;

int main()
{
	int a,b;
	cin >> a >> b;
	if (a > 9 || b > 9 )
	{
		cout << -1 << endl;
	}
	else	
	{
		cout << a*b << endl;
	}
	return 0;
}



Measured memory_bytes: 256
n, k, q = map(int, input().split())
points=[k]*(n+1)
cnt=[0]*(n+1)
for i in range(q):
  cnt[int(input())]+=1
for j in range(1,n+1):
  if k-(q-cnt[j])>0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 5448
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
const int oo = 1e9+7;
const int mod = 1e9+7;

vector<vector<int>> dp;
vector<vector<int>> can;
int n;

int add(int& a, int b) {
    return (a + b) % mod;
}

int solve(int ind, int mask) {
    
    if(ind == n && mask == (1 << n)-1) {
        return 1;
    } else if(dp[ind][mask] != -1) {
        return dp[ind][mask];
    }
    
    int ans = 0;
    
    for(int i = 0; i < n; ++i) {
        if(can[ind][i] && !(mask & (1 << i))) {
            ans = add(ans, solve(ind+1, mask | (1 << i)));
        }
    }
    
    dp[ind][mask] = ans;
    return ans;
}

int main() {
    
    scanf("%d",&n);
    
    can.resize(n);
    for(int i = 0; i < n; ++i) {
        can[i].resize(n);
        for(int j = 0; j < n; ++j) {
            scanf("%d",&can[i][j]);
        }
    }
    
    dp.assign(n, vector<int>((1<<n), -1));
    
    int ans = solve(0, 0);

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




Measured memory_bytes: 180608
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

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


int main() {
    
    ll x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int n;

int main() {

	cin >> n;

	int sum = 0;
	for (int i = 1; i <= n; ++i)
		sum += i;

	cout << sum << endl;

	return 0;
}

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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;
typedef vector<int> vi;
const int maxn = 100 + 10;

int main() {
    int n, k;
    cin >> n >> k;
    vll nums(n);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }
    sort(nums.begin(), nums.end());
    ll ans = INT_MAX;
    for (int i = 0; i <= n - k; ++i) {
        ans = min(ans, nums[i + k - 1] - nums[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, N, A[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	int l[2], r[2], m;
	long long ans, min, max, sum[200001];
	for (i = 1, sum[0] = 0; i <= N; i++) sum[i] = sum[i-1] + A[i];
	for (i = 2, ans = sum[N]; i <= N - 2; i++) {
		l[0] = 1;
		r[0] = i - 1;
		while (l[0] < r[0]) {
			m = (l[0] + r[0] + 1) / 2;
			if (sum[m] < sum[i] - sum[m]) l[0] = m;
			else r[0] = m - 1;
		}
		if (l[0] < i - 1 && sum[l[0]+1] < sum[i] - sum[l[0]]) l[0]++;

		l[1] = i + 1;
		r[1] = N - 1;
		while (l[1] < r[1]) {
			m = (l[1] + r[1] + 1) / 2;
			if (sum[m] - sum[i] < sum[N] - sum[m]) l[1] = m;
			else r[1] = m - 1;
		}
		if (l[1] < N - 1 && sum[l[1]+1] - sum[i] < sum[N] - sum[l[1]]) l[1]++;
		
		min = (sum[l[0]] < sum[i] - sum[l[0]])? sum[l[0]]: sum[i] - sum[l[0]];
		max = sum[i] - min;
		if (sum[l[1]] - sum[i] < min) min = sum[l[1]] - sum[i];
		if (sum[N] - sum[l[1]] < min) min = sum[N] - sum[l[1]];
		if (sum[l[1]] - sum[i] > max) max = sum[l[1]] - sum[i];
		if (sum[N] - sum[l[1]] > max) max = sum[N] - sum[l[1]];
		if (max - min < ans) ans = max - min;
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 4080