akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

struct StNumCnt
{
  StNumCnt() : m_nNum(0), m_nCnt(0) { }

  int m_nNum;
  int m_nCnt;
};

class CGreater_nCnt
{
  public:
    bool operator()(const StNumCnt& lhs, const StNumCnt& rhs)
    {
      return lhs.m_nCnt > rhs.m_nCnt;
    }
};

void fnInput(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

int fnMinChangeCnt(const vector<int>& cnrvnNum)
{
  map<int, int> mpNumCntEvn, mpNumCntOdd;

  for (int i = 0; i < cnrvnNum.size(); ++i)
    if ( i % 2 == 0 )
      mpNumCntEvn[ cnrvnNum[i] ]++;
    else
      mpNumCntOdd[ cnrvnNum[i] ]++;

  vector<StNumCnt> voNumCntEvn( mpNumCntEvn.size() ),
                   voNumCntOdd( mpNumCntOdd.size() );

  int n = 0;
  for (pair<int, int> PNumCnt : mpNumCntEvn)
  {
    voNumCntEvn[n].m_nNum   = PNumCnt.first;
    voNumCntEvn[n++].m_nCnt = PNumCnt.second;
  }

  n = 0;
  for (pair<int, int> PNumCnt : mpNumCntOdd)
  {
    voNumCntOdd[n].m_nNum   = PNumCnt.first;
    voNumCntOdd[n++].m_nCnt = PNumCnt.second;
  }

  sort(begin(voNumCntEvn), end(voNumCntEvn), CGreater_nCnt() );
  sort(begin(voNumCntOdd), end(voNumCntOdd), CGreater_nCnt() );

  int nMinChangeCnt = INT_MAX;

  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j)
      if (voNumCntEvn[i].m_nNum != voNumCntOdd[j].m_nNum)
        nMinChangeCnt = 
          min( nMinChangeCnt, 
               (int)cnrvnNum.size() - voNumCntEvn[i].m_nCnt - voNumCntOdd[j].m_nCnt );

  return nMinChangeCnt;
}
  
int main()
{
  vector<int> vnNum;
  
  fnInput(vnNum);
  cout << fnMinChangeCnt(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 8916
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
ll gcd(ll a,ll b){
	if(a==0){
		return b;
	}
	return gcd(b%a,a);
}
ll count(ll a,ll b,ll c){
	ll d=(b/c);
	ll e=((a-1)/c);
	return d-e;
}
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	// cout<<gcd(3,2)<<endl;
	// cout<<(c*d)/(gcd(c,d))<<endl;
	// cout<<count(a,b,c)<<" "<<count(a,b,d)<<" "<<count(a,b,(c*d)/(gcd(c,d)))<<endl;
	cout<<b-a+1-count(a,b,c)-count(a,b,d)+count(a,b,(c*d)/(gcd(c,d)))<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int n;
int a[15];

int main()
{
	cin >> n;
	int m = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0)m++;
	}

	

	int e = 1;
	ll ans = 1;
	for (int i = 0; i < n; i++) {
		ans *= 3;
		if (a[i] % 2 == 0)e *= 2;
		else e *= 1;
	}
	cout << ans - e << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a, b;
	scanf("%d %d",&a,&b); 
	if(a < b){
		printf("a < b\n");
	} else if(a > b){
		printf("a > b\n");
	} else {
		printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 2040
n, m, c = map(int, input().split())
b = tuple(map(int, input().split()))
a = [tuple(map(int, input().split())) for i in range(n)]

ans = 0


for i in range(n):

    f = c

    for j in range(m):
        f += a[i][j] * b[j]


    if f > 0:
        ans += 1


print(ans)


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

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  int happy = 0;
  rep(i, n - 1) {
    if (s[i] == s[i + 1]) happy++;
  }
  int ans = min(happy + k * 2, n - 1);

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


Measured memory_bytes: 512
#!/usr/bin/env python3
from itertools import product

# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N = int(input())
    grid = [[None for _ in range(N)] for i in range(N)]
    for i in range(N):
        a = int(input())
        for _ in range(a):
            x, y = list(map(int, input().split()))
            grid[i][x-1] = y
    res = 0
    for p in product([0, 1], repeat=N):
        flag = True
        p = list(p)
        for i in range(N):
            if p[i] == 0:
                continue
            for j in range(N):
                if grid[i][j] is None:
                    continue
                if grid[i][j] == p[j]:
                    continue
                flag = False
                break
            if flag:
                continue
            break
        if flag:
            res = max(res, sum(p))
    print(res)
    pass

if __name__ == '__main__':
    main()


Measured memory_bytes: 48236
def modpow(a, n, mod):
    res = 1
    while n:
        if n % 2:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


MOD = 1000000007

n = int(input())
ans = (modpow(10, n, MOD) - 2 * modpow(9, n, MOD) + modpow(8, n, MOD)) % MOD
print(ans)


Measured memory_bytes: 61304
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  bool check = 1;
  for (int i = 0; i < 3; i++){
   if(S[i] == S[i+1]) check = 0; 
  }
  
  if(check == 0) cout << "Bad" << endl;
  else cout << "Good" << endl;
}


Measured memory_bytes: 256
import fractions
A,B=map(int,input().split())

gcd=fractions.gcd(A,B)
count=1

for i in range(2,int(pow(gcd,1/2))+1):
    if gcd==1:
        break
    else:
        if gcd%i==0:
            count+=1
            while gcd%i==0:
                gcd//=i
if gcd!=1:
    count+=1
print(count)
    

Measured memory_bytes: 5176
import sys
n = int(input())
pret = 0
prex = 0
prey = 0
for i in range(n):
    t,x,y = map(int,input().split())
    tmp = t - pret - abs(x - prex) - abs(y - prey)
    #print(t, x, y, tmp)
    if tmp >= 0 and tmp % 2 == 0:
        pret = t
        prex = x
        prey = y
    else:
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int N;cin >> N;
    const int MAXN = 200000;
    int A[MAXN];
    ll tmp[MAXN];
    rep(i,N)cin >> A[i];
    tmp[N-1] = 0;
    for(int i=N-2;i>=0;i--){
        ll tm = A[i+1] + tmp[i+1];
        tm %= MOD;
        tmp[i] = tm;
    }
    ll ans = 0;
    rep(i,N){
        ll tm = tmp[i]* A[i];
        tm %= MOD;
        ans += tm;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 5988
from numpy import *
N,K = map(int,input().split())
A = array(sorted(list(map(int,input().split()))))
nega = A[A<0]
zera = A[A==0]
posa = A[0<A]

def cnt(x):
  y = 0
  if x>=0:
    y+=N*len(zera)
  y+=searchsorted(A,x//posa,side="right").sum()
  y+=N*len(nega)-searchsorted(A,-(-x//nega)).sum() 
  y-=len(A[A*A<=x])
  return y//2

r = 10**18
l = -r-1

while r-l>1:
  c=(r+l)//2
  if K<=cnt(c):
    r=c
  else:
    l=c

print(r)

Measured memory_bytes: 47648
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
int n;
double dp[301][301][301];
double solve(int a,int b,int c){
    if(dp[a][b][c]>=0)return dp[a][b][c];
    if(!(a|b|c))return 0.0;
    double maki=0.0;
    if(a)maki+=solve(a-1,b,c)*a;
    if(b)maki+=solve(a+1,b-1,c)*b;
    if(c)maki+=solve(a,b+1,c-1)*c;
    maki+=n;
    maki/=(a+b+c);
    return dp[a][b][c]=maki;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    memset(dp,-1,sizeof(dp));
    int a,b[4];
    memset(b,0,sizeof(b));
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        b[a]++;
    }
    doublecout(solve(b[1],b[2],b[3]));
    return 0;
}


Measured memory_bytes: 213376
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ans = []
for x in range(X):
    for y in range(Y):
        for z in range(Z):
            if (x + 1) * (y + 1) * (z + 1) <= K:
                ans.append(A[x] + B[y] + C[z])
            else:
                break

ans.sort(reverse=True)
print(*ans[:K], sep='\n')


Measured memory_bytes: 48864
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
using ll = long long;

vector<vector<int>> btab,wtab;
pair<int,int> calkim2(int x1,int y1,int x2,int y2) {
    int imb=0,imw=0;
    pair<int,int> ans;
    imb = btab[y2][x2]-btab[y1-1][x2]-btab[y2][x1-1]+btab[y1-1][x1-1];
    imw = wtab[y2][x2]-wtab[y1-1][x2]-wtab[y2][x1-1]+wtab[y1-1][x1-1];
    return make_pair(imb,imw);
}
int main() {
    int n,k;cin>>n>>k;
    btab.assign(2*k+1,vector<int>(2*k+1,0));
    wtab.assign(2*k+1,vector<int>(2*k+1,0));
    int bn=0,wn=0;
    for (int i=0;i<n;i++) {
        int x,y;
        char col;
        cin >> x >> y >> col;
        if (col=='B') {
            btab[y%(2*k)+1][x%(2*k)+1]+=1;
            bn+=1;
        }
        else {
            wtab[y%(2*k)+1][x%(2*k)+1]+=1;
            wn+=1;
        }      
    }
    for (int i=1;i<(2*k)+1;i++) {
        for (int j=1;j<(2*k)+1;j++) {        
            btab[i][j]+=btab[i][j-1];
            wtab[i][j]+=wtab[i][j-1];
        }
    }
    for (int j=1;j<(2*k)+1;j++) {
        for (int i=1;i<(2*k)+1;i++) {
            btab[i][j]+=btab[i-1][j];
            wtab[i][j]+=wtab[i-1][j];
        }
    }
    vector<vector<int>> xytabb,xytabw;
    int totalmax=0;
    bool end=false,testend=false;
    for (int i=0;i<k;i++) {
        if (testend) break;
        for (int j=0;j<k;j++) {
            vector<int> xls = {1,i+1,k+i+1};
            vector<int> xle = {i,k+i,2*k};
            vector<int> yls = {1,j+1,k+j+1};
            vector<int> yle = {j,k+j,2*k};
            vector<int> boxb(9,0),boxw(9,0);

            for (int yk=0;yk<3;yk++) {
                for (int l=0;l<3;l++) {
                    int id = yk*3+l;
                    if (id%2==1 and xls[l]<=xle[l] and yls[yk]<=yle[yk]) {
                        pair<int,int> temp;
                        temp = calkim2(xls[l],yls[yk],xle[l],yle[yk]);
                        boxb[id]=temp.first;
                        boxw[id]=temp.second;
                    }
                }                
            }
            int sumwo = boxw[1]+boxw[3]+boxw[5]+boxw[7];
            int sumwe = wn-sumwo;
            int sumbo = boxb[1]+boxb[3]+boxb[5]+boxb[7];
            int sumbe = bn-sumbo;
            totalmax = max(totalmax,sumwe+sumbo);
            totalmax = max(totalmax,sumwo+sumbe);
            if (totalmax==wn+bn) {
                testend=true;
                break;
            }
        }
    }
    cout << totalmax<<endl;
    return 0;
}

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

typedef long long ll;


int n, m;
int a[10000], b[10000], c[10000];
int dist[100][100];
int const INF = 1000000000;

int main(){
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if (i == j) dist[i][j] = 0;
            else dist[i][j] = INF;
        }
    }
    for (int i = 0; i < m; i++){
        dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
        dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
    }

    for (int k = 0; k < n; k++){
        for (int i = 0; i < n; i++){
            for (int j = 0;j < n; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int res = m;
    for (int i = 0; i < m; i++){
        bool check = false;
        for (int j = 0; j < n; j++){
            for (int k = 0; k < n; k++){
                if (dist[j][k] == dist[j][a[i]] + c[i] + dist[b[i]][k]){
                    check = true;
                }
            }
        }
        if (check) res--;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int n, m, K;
    scanf("%d%d%d", &n, &m, &K);
    lint a[n], b[m], asum[n+1], bsum[m+1];
    asum[0] = bsum[0] = 0;
    rep(i, n) scanf("%lld", &a[i]), asum[i+1] = asum[i] + a[i];
    rep(i, m) scanf("%lld", &b[i]), bsum[i+1] = bsum[i] + b[i];

    int ans = 0;
    rep(i, n+1){
        if(asum[i] > K) break;
        int tmp = upper_bound(bsum, bsum+m+1, K-asum[i]) - bsum;
        chmax(ans, i + tmp - 1);
    }
    printf("%d\n", ans);
}

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

ll a, b, c;
int main() {
    cin >> a >> b >> c;
    if(a == b && b == c) puts("Yes");
    else puts("No");
    
    return 0;
}

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

using namespace std;

const int maxn = 1e5 + 10;
int a[maxn], dp[maxn], n;

int main()
{
    ios::sync_with_stdio(false);
    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> a[i];
    dp[1] = abs(a[1] - a[0]);
    for (int i = 2; i < n; i++)
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));

    cout << dp[n - 1];

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

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

  uint64_t res = 1;
  rep(i, N) {
    res *= (i + 1);
    res %= (uint64_t)1e9 + 7;
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

int main() {
  int N; cin >> N;
  vector<ll> a(N); 
  REP(i, N) {
    cin >> a[i];
    if(a[i]%2 == 1){
      cout << "first" << endl;
      return 0;
    }
  }

  cout << "second" << endl;

}


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

int main() {
  int n, k, x, y, ans = 0;
  cin >> n>> k >> x >> y;
  for (int i=1; i <= n; i++) { 
    if(i <= k) { 
      ans += x;
    } else {
      ans += y;
      }
    }
  cout << ans << endl;
  return 0;
  }


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n, m;
string s, t;

map<pair<int, int>, char> mm;

ll gcd(ll a, ll b) {
	while (b) {
		ll q = a % b;
		a = b;
		b = q;
	}
	return a;
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> m;
	cin >> s >> t;
	for (int i = 0; i < s.size(); ++i) {
		int g = gcd(i, n);
		pair<int, int> tmp = {i / g, n / g};
		mm[tmp] = s[i];
	}
	for (int i = 0; i < t.size(); ++i) {
		int g = gcd(i, m);
		pair<int, int> tmp = {i / g, m / g};
		if (mm.count(tmp) && mm[tmp] != t[i]) {
			cout << -1 << "\n";
			return 0;
		}
	}
	cout << ll(n) * ll(m) / gcd(n, m) << "\n";
	return 0;
}




Measured memory_bytes: 6144
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main(){

	int s;
	int bk[1000001];
	int turn  = 1;
	
	cin >> s;

	for (;;){
		if (bk[s] == 1)break;
			bk[s] = 1;
		s = (s % 2 == 0) ? s / 2 : 3 * s + 1;
		turn++;
	}

	cout << turn << endl;

}

Measured memory_bytes: 2304
<?php
fscanf(STDIN,'%d%d%d%d',$X1,$Y1,$X2,$Y2);
$D1=$X2-$X1;
$D2=$Y2-$Y1;
$X3=$X2-$D2;
$Y3=$Y2+$D1;
$X4=$X1-$D2;
$Y4=$Y1+$D1;

echo $X3," ",$Y3," ",$X4," ",$Y4;

 ?>


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

int main()
{
ll n ;
cin >> n ;
ll sum=0;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
  sum+=a[i];
}

if(sum%((1+n)*n/2)!=0){cout << "NO" << endl;return 0;}
sum/=(1+n)*n/2;
rep(i,n-1){
  if((a[i]+sum-a[i+1])%n!=0){cout << "NO" << endl;return 0;}
  if(a[i+1]-a[i]>sum){cout << "NO" << endl;return 0;}
}
if((a[n-1]+sum-a[0])%n!=0){cout << "NO" << endl;return 0;}
if(a[n-1]-a[0]>sum){cout << "NO" << endl;return 0;}
cout << "YES" << endl;
return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#define M 100000

int S[M];

int partition(int,int);

int main(){

  int i,n,m;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&S[i]);
    }
  m = partition(0,n-1);
  
  for(i=0;i<n;i++)
    {
      if(i) printf(" ");
      if(i==m)printf("[");
      printf("%d",S[i]);
      if(i==m)printf("]");
    }
  printf("\n");
  return 0;
}
int partition(int p,int r)
{
  int x,i,j,tmp=0;

  x = S[r];
  i = p-1;
  for(j=p;j<r;j++)
    {
      if(S[j]<=x)
	{
	  i = i+1;
	  tmp=S[i];
	  S[i]=S[j];
	  S[j]=tmp;
	}
    }
  tmp=S[i+1];S[i+1]=S[r];S[r]=tmp;
  return i+1;
}

      

Measured memory_bytes: 992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_143
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            string s = Read();
            List<int> cs = new List<int>();
            cs.Add(s[0]);
            for(int i = 1; i < n; i++)
            {
                if (cs[cs.Count - 1] == s[i]) continue;
                cs.Add(s[i]);
            }
            WriteLine(cs.Count);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

using namespace std;

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int main(void){
	int n;
	long long a[30]={1,2,4};
	loop(i,3,30)
		a[i] = a[i-1] + a[i-2] + a[i-3];
	while(cin>>n,n)
		cout<<1+a[n-1]/3650<<endl;
		
	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<math.h>

using namespace std;

void write(int , int);
int main()
{
  int H, W;
  cin >> H >> W;
  while(H!=0 || W!=0){
    write(H, W);
    cin >> H >> W;
  }
  return 0;
}

void write(int H, int W){
  for(int y=0; y<H; y++){
    for(int x=0; x<W; x++){
      if((x+y)%2==0)cout << '#';
      else cout << '.';
    }
    cout << endl;
  }
  cout << endl;
}



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

using namespace std;

int main() {
    int n;
    cin >> n;
    int temp = n;
    int sum = 0;

    while(n / 10 != 0){
        sum += n % 10;
        n /= 10;
//        cout << n << endl;
    }
    sum += n % 10;
//    cout << sum << endl;
    
    if(temp % sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

const int MAX_N=1e5,MAX_M=1e5;
int N,M,A[MAX_M],B[MAX_M];

int deg[MAX_N];
int main(){
	cin>>N>>M;
	REP(i,M){
		cin>>A[i]>>B[i];
		deg[A[i]]++;
		deg[B[i]]++;
	}
	bool flg=true;
	REP(i,N){
		if (deg[i]%2!=0){
			flg=false;
		}
	}
	if (flg){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define maxn 105
struct Node{
	double key;int x,y;
	bool operator < (const Node &b)const{
		return key<b.key;
	}
}a[maxn];
int sx,sy;double ans;
double cal(int x,int y){
	sx+=x,sy+=y;
	return atan2(y,x);
}
int main(){
	int n;scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d%d",&a[i].x,&a[i].y),a[i].key=cal(a[i].x,a[i].y);
	sort(a,a+n);
	for(int i=0;i<n;i++){
		int x=0,y=0;
		for(int j=i;;j++){
			j%=n;x+=a[j].x,y+=a[j].y;
			ans=max(sqrt(1ll*x*x+1ll*y*y),ans);
			if(x==sx&&y==sy)break;
		}
	}
	printf("%.20lf",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int x = sc.nextInt();
    int n = sc.nextInt();
    boolean[] isExist = new boolean[100];
    if (n == 0) {
      sc.nextLine();
      sc.nextLine();
    }
    for (int i = 0; i < n; i++) {
      isExist[sc.nextInt() - 1] = true;
    }

    if (!isExist[x - 1]) {
      System.out.println(x);
      return;
    }

    for (int i = 1; i <= 100; i++) {
      if ((x - 1) - i < 0 || !isExist[(x - 1) - i]) {
        System.out.println(x - i);
        return;
      }

      if ((x - 1) + i >= 100 || !isExist[(x - 1) + i]) {
        System.out.println(x + i);
        return;
      }
    }
  }
}


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

// returns the index of the element in list which should be in sorted_index
int getIndex(vector< int > list,
	     vector< int > sorted_list,
	     int sorted_index) {
  for (int i = 0; i < list.size(); i++)
    if (list[i] == sorted_list[sorted_index])
      return i;
}

pair< vector< int >, int > getCycleCost(vector< int > list,
					vector< int > sorted_list,
					int sorted_index) {
  int cost = 0;
  while (getIndex(list, sorted_list, sorted_index) != sorted_index) {
    int first_swap = getIndex(list, sorted_list, sorted_index);
    int second_swap = getIndex(list, sorted_list, first_swap);
    int holder = list[first_swap];
    list[first_swap] = list[second_swap];
    list[second_swap] = holder;
    cost += list[first_swap] + list[second_swap];
  }
  return pair< vector< int >, int > (list, cost);
}

pair< vector< int >, int > getCycleCostWithGlobalMinSwap(vector< int > list,
							 vector< int > sorted_list,
							 int sorted_index) {
  int holder = list[0];
  int swap_index = getIndex(list, sorted_list, sorted_index);
  list[0] = list[swap_index];
  list[swap_index] = holder;
  int cost = list[0] + list[swap_index];
  pair< vector< int >, int > cycle_sol = getCycleCost(list, sorted_list, 0);
  cycle_sol.second += cost;
  return cycle_sol;
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector< int > list (n, 0);
  for (int i = 0; i < n; i++)
    cin >> list[i];
  // sort the list
  vector< int > sorted_list (list);
  sort(sorted_list.begin(), sorted_list.end());
  int sort_index = 0;
  int totalcost = 0;
  while (sort_index < n) {
    if (getIndex(list, sorted_list, sort_index) == sort_index)
      sort_index++;
    // if the lowest value after sort_index isn't in the right spot
    else {
      pair< vector< int >, int > holder = getCycleCost(list, sorted_list, sort_index);
      // if the globally lowest value is not in the correct spot
      if (!sort_index) {
	list = holder.first;
	totalcost += holder.second;
      } else {
	pair< vector< int >, int > gholder = getCycleCostWithGlobalMinSwap(list, sorted_list, sort_index);
	if (gholder.second < holder.second) {
	  list = gholder.first;
	  totalcost += gholder.second;
	} else {
	  list = holder.first;
	  totalcost += holder.second;
	}
      }
    }
  }
  cout << totalcost << endl;
  return 0;
}



Measured memory_bytes: 3204
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    int x[m]; for (int i = 0; i < m; i++) cin >> x[i];
    if (n >= m) { cout << 0 << endl; return 0; }
    sort(x, x+m);
    for (int i = 0; i < m-1; i++) x[i] = x[i+1] - x[i];
    sort(x, x+m-1);
    long long ans = 0;
    for (int i = 0; i < m-n; i++) ans += x[i];
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105;

int n;
int x[MAXN];
int mn, mx;
long long ans = -1;

int main() { 

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }

  mn = x[0], mx = x[0];
  for (int i = 0; i < n; i++) {
    mn = min(mn, x[i]);
    mx = max(mx, x[i]);
  }

  for (int i = mn; i <= mx; i++) {
    long long cur = 0;
    for (int j = 0; j < n; j++) {
      cur += (x[j] - i) * (x[j] - i);
    }
    if (ans == -1 || cur < ans) {
      ans = cur;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
long long  i,b,c;
int main()
{
    while (~scanf ("%lld",&c))
    {
    for (i=1; i<=c; i++)
    {
        if(i*i>c)
        {
            break;
        }
        b=i;
    }
    
    printf ("%lld\n",b*b);
    return 0;
    }
}

Measured memory_bytes: 128
use std::collections::HashSet;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        ds: [usize; n]
    }
    let mut s = HashSet::new();
    for d in ds {
        s.insert(d);
    }
    println!("{}", s.len());
}


Measured memory_bytes: 4352
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    private static int[] points;
    private static int paramN = 0;
    private static NeighborList[] neighbors;

    private static class NeighborList {
        ArrayList<Integer> nl;
        public NeighborList() {
            nl = new ArrayList<Integer>();
        }
    }

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String[] mainParams = scanner.nextLine().split(" ");
        paramN = Integer.parseInt(mainParams[0]);
        int paramQ = Integer.parseInt(mainParams[1]);
        points = new int[paramN];
        neighbors = new NeighborList[paramN + 1];

        for (int i = 0; i < paramN + 1; i++) {
            neighbors[i] = new NeighborList();
        }

        for (int i = 0; i < paramN - 1; i++) {
            String[] data = scanner.nextLine().split(" ");
            neighbors[Integer.parseInt(data[0])].nl.add(Integer.parseInt(data[1]));
            neighbors[Integer.parseInt(data[1])].nl.add(Integer.parseInt(data[0]));
        }

        for (int i = 0; i < paramQ; i++) {
            String[] data = scanner.nextLine().split(" ");
            points[Integer.parseInt(data[0]) - 1] += Integer.parseInt(data[1]);
        }

        scanner.close();

        addCountToPoint(1, 0);

        String[] outs = new String[points.length];
        for (int i = 0; i < points.length; i++) {
            outs[i] = String.valueOf(points[i]);
        }

        print(String.join(" ", outs));
    }

    private static void addCountToPoint(int pointId, int p) {
        ArrayList<Integer> nei = neighbors[pointId].nl;
        for (int i = 0; i < nei.size(); i++) {
            int neId = nei.get(i);
            if (neId == p) continue;
            points[neId - 1] += points[pointId - 1];
            addCountToPoint(neId, pointId);
        }
    }

    private static void print(String text) {
        System.out.println(text);
    }
}

Measured memory_bytes: 379496
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b < c + d) {
        cout << "Right\n";
    } else if (a + b == c + d) {
        cout << "Balanced\n";
    } else {
        cout << "Left\n";
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {    
    int n, m; cin >> n >> m;
    vector<vector<int>> G(n, vector<int>());
    rep(i, m){
        int a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> seen(n, -1);
    seen[0] = 0;
    queue<int> que;
    que.push(0);

    while(!que.empty()){
        int pos = que.front(); que.pop();
        for(int e: G[pos]){
            if(seen[e] != -1) continue;
            seen[e] = pos;
            que.push(e);
        }
    }
    cout << "Yes" << ln;
    for(int i=1; i<n; i++){
        cout << seen[i] + 1 << ln;
    }

}

Measured memory_bytes: 10236
#include <iostream>
#include <cmath>

using namespace std;

int Func(long long a) {
	int i = 0;
	while (a > 0) {
		a /= 10;
		i++;
	}
	return i;
}

int main(void) {
	long long n;
	cin >> n;
	int ans = Func(n), i = 2;
	for (; i <= sqrt(n); i++) {
		if (n % i == 0)
			ans = Func(n / i);
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

#define x1 biri
#define y1 ganja

const int N = 2010;

int n, m, q;
char g[N][N];
int deg[N][N];
int dp[N][N];
int ed[N][N];
int rowUp[N][N];
int rowDown[N][N];
int colLeft[N][N];
int colRight[N][N];

int sum (int a[N][N], int x1, int y1, int x2, int y2) {
	return a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1];
}

int main () {
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 1; i <= n; ++i) {
  	scanf("%s", g[i] + 1);
  }
  for (int i = 1; i <= n; ++i) {
  	for (int j = 1; j <= m; ++j) {
  		if (g[i][j] == '0') continue;
  		if (g[i - 1][j] == '1') ++deg[i][j];
  		if (g[i + 1][j] == '1') ++deg[i][j];
  		if (g[i][j - 1] == '1') ++deg[i][j];
  		if (g[i][j + 1] == '1') ++deg[i][j];
  		// cout << deg[i][j] << " ";
  	} 
  	// cout << endl;
  }
  for (int i = 1; i <= n; ++i) {
  	for (int j = 1; j <= m; ++j) {
  		dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + (g[i][j] - '0');
  	}
  }
  for (int i = 1; i <= n; ++i) {
  	for (int j = 1; j <= m; ++j) {
  		ed[i][j] = ed[i - 1][j] + ed[i][j - 1] - ed[i - 1][j - 1] + deg[i][j];
  	}
  }
  for (int i = 1; i <= n; ++i) {
  	for (int j = 1; j <= m; ++j) {
  		rowUp[i][j] = rowUp[i][j - 1];
  		if (g[i][j] == '1' and g[i - 1][j] == '1') {
  			++rowUp[i][j];
  		}
  	}
  }
  for (int i = 1; i <= n; ++i) {
  	for (int j = 1; j <= m; ++j) {
  		rowDown[i][j] = rowDown[i][j - 1];
  		if (g[i][j] == '1' and g[i + 1][j] == '1') {
  			++rowDown[i][j];
  		}
  	}
  }
  for (int j = 1; j <= m; ++j) {
  	for (int i = 1; i <= n; ++i) {
  		colLeft[i][j] = colLeft[i - 1][j];
  		if (g[i][j] == '1' and g[i][j - 1] == '1') {
  			++colLeft[i][j];
  		}
  	}
  }
  for (int j = 1; j <= m; ++j) {
  	for (int i = 1; i <= n; ++i) {
  		colRight[i][j] = colRight[i - 1][j];
  		if (g[i][j] == '1' and g[i][j + 1] == '1') {
  			++colRight[i][j];
  		}
  	}
  }
  while (q--) {
  	int x1, y1, x2, y2;
  	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
  	int v = sum(dp, x1, y1, x2, y2);
  	int e = sum(ed, x1, y1, x2, y2);
  	int sub = (rowUp[x1][y2] - rowUp[x1][y1 - 1]) + (rowDown[x2][y2] - rowDown[x2][y1 - 1]) + (colLeft[x2][y1] - colLeft[x1 - 1][y1]) + (colRight[x2][y2] - colRight[x1 - 1][y2]);
  	// cout << v << " " << e << " " << sub << endl;
  	e -= sub, e >>= 1;
  	printf("%d\n", v - e);
  }
  return 0;
}



Measured memory_bytes: 115968
c = [input() for i in range(2)]

c0=[]
for i in range(3):
  c0.append(c[0][i])
c1=[]
for i in range(3):
  c1.append(c[1][i])
  
if c0[0]==c1[2] and c0[1]==c1[1] and c0[2]==c1[0]:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3060
fun main(args: Array<String>) {
  val (N) = readLine()!!.split(" ").map { it.toLong() }
  val sqrtN = Math.sqrt(N.toDouble()).toLong() + 1
  var a = 1L
  for (i in 2..sqrtN) {
    if (N % i == 0L) a = i
  }
  val b = N / a
  println(a + b - 2)
}



Measured memory_bytes: 37908
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=2e5+5;
struct node
{
    int k,l,r;
    node(int k=0,int l=0,int r=0):k(k),l(l),r(r){}
};
struct haha
{
    int id,v,k;
    haha(int id=0,int v=0,int k=0):id(id),v(v),k(k){}
    bool operator<(const haha&o)const
    {
        if(v==o.v) return k<o.k;
        return v<o.v;
    }
};
vector<node>vl,vr;
int n,t[N<<2],lz[N<<2],ss[N];
ll ans=0;
ll s[2][N];
void update(int l,int r,int k)
{
    //cout<<"LE "<<l<<' '<<r<<' '<<t[k]<<endl;
    assert(t[k]>=0);
    if(l!=r)
    {
        t[k<<1]-=lz[k],t[k<<1|1]-=lz[k];
        lz[k<<1]+=lz[k],lz[k<<1|1]+=lz[k];
    }
    lz[k]=0;
}
int query(int l,int r,int k)
{
    if(lz[k]) update(l,r,k);
    if(t[k]!=0) return 0;
    if(l==r) return l;
    int m=l+r>>1;
    if(t[k<<1|1]==0) return query(m+1,r,k<<1|1);
    return query(l,m,k<<1);
}
void fix(int l,int r,int k,int x)
{
    if(lz[k]) update(l,r,k);
    if(r<x) return;
    if(l>=x)
    {
        //cout<<"F: "<<l<<' '<<r<<endl;
        lz[k]++;t[k]--;
        update(l,r,k);
        return;
    }
    int m=l+r>>1;
    fix(l,m,k<<1,x);fix(m+1,r,k<<1|1,x);
    t[k]=min(t[k<<1],t[k<<1|1]);
}
void build(int l,int r,int k)
{
    lz[k]=0;t[k]=l;
    if(l==r) return;
    int m=l+r>>1;
    build(l,m,k<<1);build(m+1,r,k<<1|1);
    t[k]=l;
}
void solve(vector<node>v,int p)
{
    build(1,n,1);
    priority_queue<haha>q;
    ll sum=0;
    for(int i=0;i<v.size();i++) sum+=v[i].r,q.push(haha(i,v[i].l-v[i].r,v[i].k));
    s[p][0]=sum;
    for(int i=1;i<=n;i++)
    {
        int pos=query(1,n,1);
        //cout<<pos<<' '<<t[1]<<endl;
        while(!q.empty())
        {
            int id=q.top().id;q.pop();
            if(v[id].k==0) continue;
            if(v[id].k>pos)
            {
                //cout<<v[id].l<<' '<<v[id].r<<' '<<v[id].k<<endl;
                sum=sum-v[id].r+v[id].l;
                fix(1,n,1,v[id].k);
                break;
            }
        }
        s[p][i]=max(sum,s[p][i-1]);
    }
}
fstream in,out;
void getts()
{
    int t=50;
    in.open("1.txt");
    in<<t<<endl;
    while(t--)
    {
        int n=5;
        in<<n<<endl;
        for(int i=1;i<=n;i++)
        {
            int k=rand()%n+1,l=rand()%100+1,r=rand()%100+1;
            in<<k<<' '<<l<<' '<<r<<endl;
        }
    }
    in.close();
}
bool de=false;
int main()
{
    srand(time(0));
    //getts();freopen("1.txt","r",stdin);out.open("out.txt");de=true;
    int t;scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        vl.clear();vr.clear();ans=0;
        for(int i=1;i<=n;i++)
        {
            int k,l,r;
            scanf("%d%d%d",&k,&l,&r);
            if(l==r) ans+=l;
            else if(l>r) vl.push_back({k,l,r});
            else vr.push_back({n-k,r,l});
        }
        for(int i=0;i<=n;i++) s[0][i]=s[1][i]=0;
        solve(vl,0);
        solve(vr,1);
        ll res=0;
        for(int i=0;i<=n;i++)
            res=max(res,s[0][i]+s[1][n-i]);
        if(!de) printf("%lld\n",ans+res);
        if(de) out<<ans+res<<endl;
    }
}


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

const int N = 100005;

int n, m, x[N], diff[N], swp[N], a[N], ret[N];
ll k, ans;

void swap_swap(int *a, int *b) {
    for (int i = 0; i < n-1; i++) ret[i] = a[b[i]];
    for (int i = 0; i < n-1; i++) a[i] = ret[i];
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n-1; i++) {
        diff[i] = x[i+1] - x[i];
        swp[i] = i;
    }

    cin >> m >> k;
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        swap(swp[a[i]-2], swp[a[i]-1]);
    }

    while (k > 0) {
        if (k & 1) swap_swap(diff, swp);
        swap_swap(swp, swp);
        k >>= 1;
    }

    ans = x[0];
    cout << ans << "\n";
    for (int i = 0; i < n-1; i++) {
        ans += diff[i];
        cout << ans << "\n";
    }

    return 0;
}

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

int main() {
  int h,n;
  cin >> h >> n;
  vector<int>a(n);
  vector<int>b(n);
  vector<int>dp(h+1,1e9);
  rep(i,n) cin >> a[i] >> b[i];
  
  dp[0]=0;
  rep(i,n){
    rep(j,h+1){
      int t=min(h,(int)j+a[i]);
      dp[t]=min(dp[t],dp[j]+b[i]);
    }
  }
  cout << dp[h] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string X;
  cin >> X;
  int N = X.size();
  stack<char> st;
  for (int i = 0; i < N; i++){
    if (X[i] == 'S'){
      st.push(X[i]);
    } else {
      if (!st.empty() && st.top() == 'S'){
        st.pop();
      } else {
        st.push(X[i]);
      }
    }
  }
  cout << st.size() << endl;
}

Measured memory_bytes: 644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int a = in.nextInt();
            int b = in.nextInt();
            int h = in.nextInt();
            System.out.println((a + b) * h / 2);
        }
    }
}


Measured memory_bytes: 27072
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = getInt(sc);
		int b = getInt(sc);

		if (a + b < 10) {
			System.out.println(a + b);
		} else {
			System.out.println("error");
		}

	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}

class Status {
	long x;
	long tmpCoins;

	public Status(long x, long tmpCoins) {
		this.x = x;
		this.tmpCoins = tmpCoins;
	}
}


Measured memory_bytes: 23636
n=int(input())
h=list(map(int,input().split()))
d=[0]*n
d[1]=abs(h[1]-h[0])
for i in range(2,n):
    d[i]=min(d[i-1]+abs(h[i]-h[i-1]),d[i-2]+abs(h[i]-h[i-2]))
print(d[n-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
const ll mod = 1e9 + 7;
int n;
ll a[N], b[N];
map<pair<ll, ll>, ll> mp;
ll ans = 1, cnt1, cnt2, cnt;
ll ksm(ll p, ll q) {
	ll ret = 1;
	while (q) {
		if (q & 1) ret = (ret * p) % mod;
		p = (p * p) % mod;
		q = q >> 1;
	}
	return ret;
}
ll f(ll x) {
	return ksm(2, x);
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		if (a[i] == 0 || b[i] == 0) {
			if (a[i] == 0 && b[i] == 0) {
				cnt++;
			} else if (a[i] == 0) {
				cnt1++;
			} else if (b[i] == 0) {
				cnt2++;
			}
			continue;
		}
		ll gcd = __gcd(a[i], b[i]);
		a[i] /= gcd;
		b[i] /= gcd;
		if (a[i] < 0) a[i] = -a[i], b[i] = -b[i];
//		cout << a[i] << " " << b[i] << endl;
		mp[make_pair(a[i], b[i])]++;
	}
	for (map<pair<ll, ll>, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		if (it->second == 0) continue;
		ll u = it->first.first;
		ll v = it->first.second;
//		cout << u << " " << v << endl;
		ll now = f(mp[make_pair(u, v)]);
//		cout << f(mp[make_pair(u, v)]) << endl;
//		mp[make_pair(u, v)] = 0;
		v = -v;
		if (v < 0) v = -v, u = -u;
		if (mp.count(make_pair(v, u))) {
			now = (now + f(mp[make_pair(v, u)]) - 1) % mod;
			mp[make_pair(v, u)] = 0;
		}
		now = now % mod;
//		cout << now << endl;
		ans = (ans * now) % mod;
	}
	ans = (ans * ((f(max(cnt1, cnt2)) + f(min(cnt1, cnt2)) - 1) % mod)) % mod;
	ans += cnt;
	cout << (ans - 1 + mod) % mod;
	return 0;
}

Measured memory_bytes: 19068
#include<stdio.h>
int main()
{
	int x,y,z,c;
	while(scanf("%d%d",&x,&y),x)
	{
		for(c=(x<y?0:1);z=x%y;++c)x=y,y=z;
		printf("%d %d\n",y,c);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) cout << "YES\n";
	else cout << "NO\n";
}

Measured memory_bytes: 256