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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
#define guard(x) if( not ( x ) ) continue;
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      Int a, b, c, d; scan(a, b, c, d);
      Int x = a + b, y = c + d;
      puts(x==y?"Balanced":x>y?"Left":"Right");
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




Measured memory_bytes: 256
import sys

def main():
    N = int(input())
    a = list(map(int, input().split()))
    colors = [0] * 9 # 8色 + 任意の1色
    for rate in a:
        colors[min(rate // 400, 8)] += 1

    used = 0
    for c in colors[0:8]:
        if c != 0:
            used += 1

    mn = max(used, 1)
    mx = used + colors[8]
    print(mn, mx)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
    int m, f, r;
    for(;;) {
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1) break;
        
        if(m == -1 || f == -1) {
            cout << "F" << endl;
            continue;
        }
        if(m+f < 30) {
            cout << "F" << endl;
            continue;
        }
        if(m+f < 50) {
            if(r >= 50) {
                cout << "C" << endl;
            } else {
                cout << "D" << endl;
            }
            continue;
        }
        if(m+f < 65) {
            cout << "C" << endl;
            continue;
        }
        if(m+f < 80) {
            cout << "B" << endl;
            continue;
        }
        cout << "A" << endl;
    }
    
    return 0;
}

    



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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, c;
    cin >> n >> m >> c;
    vector<ll> b(m);
    for (int i = 0; i < m; i++) cin >> b[i];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        vector<ll> a(m);
        for (int j = 0; j < m; j++) cin >> a[j];
        ll sum = c;
        for (int j = 0; j < m; j++) {
            sum += a[j] * b[j];
        }
        ans += (sum > 0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a=input()

b = int(a[:2])
c = int(a[2:])

if 0< b < 13:
    a_month_flag = 1
    a_year_flag = 1
elif b == 0:
    a_month_flag = 0
    a_year_flag = 0
else:
    a_month_flag = 0
    a_year_flag = 1

if 0< c < 13:
    b_month_flag = 1
    b_year_flag = 1
elif c == 0:
    b_month_flag = 0
    b_year_flag = 0
else:
    b_month_flag = 0
    b_year_flag = 1

if a_month_flag ==1 and b_month_flag==1:
    print("AMBIGUOUS")
elif a_month_flag == 1 and b_month_flag == 0:
    print("MMYY")
elif a_month_flag == 0 and b_month_flag ==1:
    print("YYMM")
else:
    print("NA")


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

using namespace std;

const int N = 400001;

int d[N],n;

struct BIT
{
    long long f[N];

    void update (int pos, long long x)
    {
        for (;pos <= n; pos+= pos&-pos)
            f[pos] = max(f[pos], x);
    }


    long long get (int pos)
    {
        if (!pos) return 0;
        long long res = -1;
        for (;pos;pos-=pos&-pos)
            res=max(res,f[pos]);
        return res;
    }

} bit;

int h[N], a[N], s[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i=1; i<=n; i++)
    {
        cin >> h[i];
    }
    for (int i=1;i<=n; i++)
        cin >> a[i];
    long long res = -1, cur;
    for (int i=1; i<=n; i++)
    {
        cur = bit.get(h[i] - 1);
        cur += a[i];
        res = max(res, cur);
        bit.update(h[i], cur);
    }
    cout << res;
    return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll a,b;
  cin >> a >> b;
  if(a>b) swap(a,b);

  REP(i,b) cout << a;
  cout << endl;
  
  //cout << fixed << setprecision(10);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> p(n), q(n), v(n);
    for(int i=0; i<n; i++) cin >> p[i];
    for(int i=0; i<n; i++) cin >> q[i];
    for(int i=0; i<n; i++) v[i] = i + 1;
    int a = -1, b = -1, k = 0;
    while(next_permutation(v.begin(), v.end())) {
        bool ok1 = true, ok2 = true;
        for(int i=0; i<n; i++) {
            if(p[i] != v[i]) ok1 = false;
            if(q[i] != v[i]) ok2 = false;
        }
        if(ok1) a = k;
        if(ok2) b = k;
        if(a != -1 && b != -1) break;
        k++;
    }
    cout << abs(a - b) << endl;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int d,i;
    cin>>d;
    cout<<"Christmas ";
    for (i=0;i<25-d;i++)
        cout<<"Eve ";
    cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 100005
#define TRACE(x) cout<<#x<<" = "<<x<<'\n'
#define TRACE2(x, y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<'\n'
#define TRACEA(arr, i) cout<<#arr<<"["<<i<<"]"<<" = "<<arr[i]<<'\n'
#define PRINT(arr, n) for (int iDx = 0; iDx < n; iDx++) printf("%d%c", arr[iDx], " \n"[iDx == n-1])
#define SZ(x) (int)(x).size()
using namespace std;
struct ii {
	int a, b;
	bool operator < (ii o) const { return tie(a, b) < tie(o.a, o.b); }
};
struct iii {
	int a, b, c;
	bool operator < (iii o) const { return tie(a, b, c) < tie(o.a, o.b, o.c); }
};
int TC, K, Q, x, y, z;

long long N, M;

int main() {
	#ifdef FAIRUZI10
	freopen("/home/fairuzi/Documents/CP/input.in", "r", stdin);
	#endif
	
	scanf("%lld%lld", &N, &M);
	long long ans = INF;
	for (long long i = 0; i <= N; i++) {
		long long a = M*i;
		long long b = M/2*(N-i);
		long long c = (M+1)/2*(N-i);
		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
		
		a = M*i;
		b = (N-i)/2*M;
		c = (N-i+1)/2*M;
		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}
	for (long long i = 0; i <= M; i++) {
		long long a = N*i;
		long long b = N/2*(M-i);
		long long c = (N+1)/2*(M-i);
		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
		
		a = N*i;
		b = (M-i)/2*N;
		c = (M-i+1)/2*N;
		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}
	printf("%lld\n", ans);
	
	return 0;
}



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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  auto start = clock();
  vector<vector<int>> v(n, vector<int> (n-1));
  rep(i, n) rep(j, n-1){
    cin >> v[i][j];
    v[i][j]--;
  }
  vector<int> index(n, 0);

  for (int i = 1; i <= ((n-1) * n) / 2; i++) {
    auto end = clock();
    if(static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000 > 1600){
      cout << (n * (n-1)) / 2 << endl;
      return 0;
    }
    vector<bool> battled(n, false);
    // cout << "===" << endl;
    // cout << i << endl;
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if(index[j] >= n-1) continue;
      int enemy = v[j][index[j]];
      if(index[j] >= n-1 || index[enemy] >= n-1) continue;
      if(v[enemy][index[enemy]] == j && !battled[j] && !battled[enemy]){
        flag = false;
        battled[j] = true;
        battled[enemy] = true;
        index[enemy]++;
        index[j]++;
      }
    }
    if(flag) break;

    flag = true;
    rep(j, n){
      if(index[j] < n-1) {
        flag = false;
        break;
      }
    }
    if(flag){
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

}


Measured memory_bytes: 4224
a,b,k=map(int,input().split())
count=int(0)
m=0
if a<b:
    m=a
else:
    m=b

for i in reversed(range(1,m+1)):
    if a%i==0 and b%i==0:
        count+=1
    
    if count==k:
        print(i)
        break

Measured memory_bytes: 3060
using System;

class CF2016QCB
{
	static public void Main(string[] args)
	{
		int K, T;
		string[] vals = Console.ReadLine().Split(' ');
		K = int.Parse(vals[0]);
		T = int.Parse(vals[1]);
		int[] a = new int[T];

		vals = Console.ReadLine().Split(' ');
		for(int i=0; i<T; i++)
		{
			a[i] = int.Parse(vals[i]);
		}

		int prev = -1;
		int max, maxi;
		int max2, max2i;
		int ans = 0;
		while(--K >= 0)
		{
			max = max2 = 0;
			maxi = max2i = -1;
			for(int i=0; i < T; i++)
			{
				if(max < a[i])
				{
					max2i = maxi;
					max = a[i];
					maxi = i;
				}
				else if(max2 < a[i])
				{
					max2 = a[i];
					max2i = i;
				}
			}
			if(maxi == prev)
			{
				if(max2i == -1)
				{
					ans++;
					a[maxi]--;
					prev = maxi;
					//Console.WriteLine(maxi+1);
				}
				else
				{
					a[max2i]--;
					prev = max2i;
					//Console.WriteLine(max2i+1);
				}
			}
			else
			{
				a[maxi]--;
				prev = maxi;
				//Console.WriteLine(maxi+1);
			}
		}
		Console.WriteLine(ans);
	}
}


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

#define MOD 1000000007LL
#define ll long long

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<ll> ans(N + 1, 0);
    for(ll x = 1; x * x <= N; x++){
        for(ll y = 1; x * x + y * y <= N; y++){
            for(ll z = 1; z * z <= N; z++){
                ll n = x * x + y * y + z * z + x * y + y * z + z * x;
                if(1 <= n && n <= N) ans[n]++;
                if(n > N) break;
            }
        }
    }
    for(int i = 1; i <= N; i++) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 3668
require 'prime'

N = gets.to_i

p = Prime.prime_division(N).map{ |x| x[0] }
c = Prime.prime_division(N).map{ |x| (0 .. x[1]).to_a }

start = c[0]

(1..c.size - 1).each{ |i|
	start = start.product c[i]
}

start = start.map{ |x| x.class == Array ? x.flatten : [x]  }

yaku = start.map{|x| x.map.with_index{ |y, i| p[i] ** y }.inject(:*) }.sort

root = N ** (1.0 / 2)

x = yaku.bsearch{|x| x >= root}
puts x-1 + N/x -1

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

using namespace std;

int main(){
    int L;
    while(cin >> L){
        vector<int> A(L);
        for(auto& t : A) cin >> t;
        vector<vector<long long>> dp(5, vector<long long>(L+1, 1LL << 60));
        dp[0][0] = 0;
        for(int i=0;i<L;i++){
            long long base = dp[0][i];
            dp[0][i+1] = dp[0][i] + A[i];
            base = min(base, dp[1][i]);
            dp[1][i+1] = base + (A[i] == 0 ? 2 : A[i]%2 == 1 ? 1 : 0);
            base = min(base, dp[2][i]);
            dp[2][i+1] = base + (A[i]%2 == 0 ? 1 : 0);
            base = min(base, dp[3][i]);
            dp[3][i+1] = base + (A[i] == 0 ? 2 : A[i]%2 == 1 ? 1 : 0);
            base = min(base, dp[4][i]);
            dp[4][i+1] = base + A[i];
        }
        long long res = dp[0][L];
        for(int i=1;i<5;i++) res = min(res, dp[i][L]);
        cout << res << endl;
    }
}

Measured memory_bytes: 10368
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			if (n == 0)
				break;
			map = new int[n][n];
			v = new boolean[n][n];
			m = 0;
			p = new int[2][n * n];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++) {
					map[i][j] = scanner.nextInt();
					if (map[i][j] < 0) {
						p[0][m] = i;
						p[1][m++] = j;
						v[i][j] = true;
					}

				}
			System.out
					.println(slove(p[0][0], p[1][0], 0, map[p[0][0]][p[1][0]]) ? "YES"
							: "NO");

		}
	}

	private boolean slove(int y, int x, int k, int sum) {
		if (sum > 0)
			return false;
		if (sum == 0) {
			if (++k == m)
				return true;
			return slove(p[0][k], p[1][k], k, map[p[0][k]][p[1][k]]);
		}
		for (int[] mo : move) {
			int ny = y + mo[0];
			int nx = x + mo[1];
			if (!isOK(ny, nx))
				continue;
			if (v[ny][nx])
				continue;
			v[ny][nx] = true;
			if (slove(ny, nx, k, sum + map[ny][nx]))
				return true;
			v[ny][nx] = false;
		}

		return false;
	}

	private boolean isOK(int ny, int nx) {
		return 0 <= ny && ny < n && 0 <= nx && nx < n;
	}

	int n, m;
	int[][] map;
	int[][] p;
	boolean[][] v;
	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
}

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


int n,A[2000];

// ??\?????????M???????????????????´????????????????????????°??¢??°
int solve(int i,int m){ // i????????\??????????´?????????£???m??????????????´???ture?????????
	if( m==0 ) return 1; // ???????????°???????????¨??§??¶???????¨?0?????????????????§m=0?????????ture?????????
	if( i>=n ) return 0;
	int res = solve(i+1,m) || solve(i+1,m-A[i]);
	return res;
}


int main(){
	int q,M;
	cin >> n;
	for(int i=0; i<n; i++) cin >> A[i];

	cin >> q;
	for(int i=0; i<q; i++){
		cin >> M;
		if( solve(0,M) ){
			cout << "yes\n";
		}else{
			cout << "no\n";
		}
	}

	return 0;
}

Measured memory_bytes: 3080
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int sum = 0;

        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            sum += (d - 1) / a + 1;
        }
        System.out.println(sum + x);
    }
}

Measured memory_bytes: 21716
n = int(input())
b = list(map(int,input().split()))

ans = []
while len(ans) < n:
  pop_i = -1
  for i in range(len(b)):
    if b[i] == i+1:
      pop_i = i
  if pop_i >= 0:
    b.pop(pop_i)
    ans.append(pop_i+1)
  else:
    print(-1)
    break
else:
  for i in range(n)[::-1]:
    print(ans[i])
               

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int L = N*1e3 + 10;
int w[N], v[N];
long long dp[N][L];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, W;
	cin >> n >> W;
	for (int i = 1; i<=n; i++)
		cin >> w[i] >> v[i];
	dp[0][0] = 0;
	for (int i = 1; i < L; i++)
		dp[0][i] = 1e10;
	int Max = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < L; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j - v[i] >= 0)
				dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
			if (Max < j&&dp[i][j] <= W)
				Max = j;
		}
	}
	cout << Max;
	return 0;
}

Measured memory_bytes: 88448
// macros
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define debug(a) cout << "L(" << __LINE__ << "):" << #a << ":" << a << endl;

// problems limits
#define MAX_N 1000

// Variables
string S;

// problems input
void input()
{
    cin >> S;
}

// problems main
void solve()
{
    int ans = 0, pcnt=0;
    ans = S.size() / 2;
    FOR(i,0,S.size()) {
        pcnt += S[i] == 'p';
    }
    cout << ans - pcnt << endl;

}

int main()
{
    ios::sync_with_stdio(false);

    input();

    solve();
}

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

int main(){
  string s;
  cin >> s;

  int ans = s.size();
  stack<int> spos;
  int i=0;
  int j=1;
  while(j < s.size()){
    if(s[i]=='S' && s[j]=='T'){
      ans -= 2;
      if(i==0 || spos.empty()){
        i = j+1;
        j = j+2;
      }
      else{
        i = spos.top();
        spos.pop();
        j = j+1;
      }
    }
    else if(s[i] == 'S' && s[j] == 'S'){
      spos.push(i);
      i = j;
      j = j+1;
    }
    else if(s[i] == 'T' && s[j] == 'S'){
      spos = stack<int>();
      i = j;
      j = j+1;
    }
    else if(s[i] == 'T' && s[j] == 'T'){
      spos = stack<int>();
      i = j+1;
      j = j+2;
    }
    //cout << i << " " << j << endl;
  }

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



Measured memory_bytes: 900
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define lld long double

#define data etokek

#define int lll

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

const int N = 1e6 + 32;
const int M = 1e9 + 7;
const int mod = 998244353;
const int rx[4] = {-1, -1, 1, 1};
const int ry[4] = {-1, 1, -1, 1};
const lld eps = 1e-11;
const double pi = acos(-1.0);
const int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};

lll bp(lll a, lll b) {
    if (!b) {
        return 1;
    }
    if (b % 2) {
        return (bp(a, b - 1) * a) % M;
    }
    lll ans = bp(a, b / 2);
    return (ans * ans) % M;
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("inverse.in", "r", stdin);
//    freopen("inverse.out", "w", stdout);
#endif
    lll n, k;
    cin >> n >> k;
    k = n + 1 - k;
    if (!k) {
        cout << 1;
        return 0;
    }
    lll res = ((n - k) * ((k * (k + 1) / 2) % M)) % M;
    ++k;
    res += (((k * ((k * k + 5) % M)) % M) * bp(6, M - 2)) % M;
    res %= M;
    cout << res;
    return 0;
}


Measured memory_bytes: 3648
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let mut edges = Vec::with_capacity(2 * n);
    for i in 0..n {
        let a: u64 = sc.read();
        let b: u64 = sc.read();
        edges.push((a, i, true));
        edges.push((b, i, false));
    }
    edges.sort_by_key(|e| e.0);

    let mut candidates = vec![];
    if let Some(ans) = calc(&edges) {
        candidates.push(ans);
    }

    edges.swap(n, n - 1);
    if let Some(ans) = calc(&edges) {
        candidates.push(ans);
    }
    edges.swap(n, n - 1);

    edges.swap(n - 2, n);
    if let Some(ans) = calc(&edges) {
        candidates.push(ans);
    }
    edges.swap(n - 2, n);

    edges.swap(n - 1, n + 1);
    if let Some(ans) = calc(&edges) {
        candidates.push(ans);
    }
    edges.swap(n - 1, n + 1);

    candidates.sort();
    println!("{}", candidates[0]);
}

fn calc(edges: &[(u64, usize, bool)]) -> Option<u64> {
    let n = edges.len() / 2;
    let mut a_count = 0;
    let mut count = vec![0; n];
    let mut sum = 0;
    for i in 0..n {
        let (cost, i, is_a) = edges[i];
        count[i] += 1;
        sum += cost;
        if is_a {
            a_count += 1;
        }
    }
    if count.iter().any(|&e| e >= 2) || a_count == n || a_count == 0 {
        Some(sum)
    } else {
        None
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8632
ABCD = input()
S = list(ABCD)
op_cnt = len(S) - 1

ans = None
for i in range(2**op_cnt):
    op = ["+"] * op_cnt
    for j in range(op_cnt):
        if i >> j & 1:
            op[op_cnt - j - 1] = "-"
    expr = S[0] + "".join(o+s for s,o in zip(S[1:], op))
    if eval(expr) == 7:
        ans = expr + "=7"
        break
print(ans)

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc129/tasks/abc129_d
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define rep(i, s, n) for (ll i = s; i < n; ++i)
#define repd(i, s, n) for (ll i = s; n < i; --i)
#define dump(x) cerr << #x << " = " << (x) << " | ";
#define _mp make_pair
#define _pb push_back
#define _f first
#define _s second
#define _lb lower_bound
#define _ub upper_bound
#define _sz(x) (int)x.size()
#define _count(arr, target) count(arr, arr + (sizeof(arr)), target)
const int INF = 2 * 1e9;
const int MOD = 1e9 + 7;

using namespace std;

int solve(int row, int col) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    int ans = -1;
    string g[row + 2][col + 2]{};
    int u[row + 2][col + 2];
    int d[row + 2][col + 2];
    int r[row + 2][col + 2];
    int l[row + 2][col + 2];

    // input
    rep(i, 0, col + 2) { g[0][i] = "#"; }

    rep(i, 1, row + 1) {
        cin >> s;
        rep(j, 0, col + 2) {
            if (j == 0 || j == col + 1) {
                g[i][j] = "#";
            } else {
                g[i][j] = s[j - 1];
            }
        }
    }

    rep(i, 0, col + 2) { g[row + 1][i] = "#"; }

    // init
    rep(i, 0, row + 2) {
        rep(j, 0, col + 2) {
            l[i][j] = 0;
            u[i][j] = 0;
            r[i][j] = 0;
            d[i][j] = 0;
        }
    }

    // ....o
    rep(i, 1, row + 1) {
        rep(j, 1, col + 1) {
            if (g[i][j] == "#") {
                l[i][j] = 0;
            } else if (l[i][j - 1] == 0) {
                l[i][j] = 1;
            } else {
                l[i][j] = l[i][j - 1] + 1;
            }
        }
    }

    // o
    // .
    // .
    // .
    rep(i, 1, row + 1) {
        rep(j, 1, col + 1) {
            if (g[i][j] == "#") {
                u[i][j] = 0;
            } else if (u[i - 1][j] == 0) {
                u[i][j] = 1;
            } else {
                u[i][j] = u[i - 1][j] + 1;
            }
        }
    }

    // o....
    rep(i, 1, row + 1) {
        repd(j, col, 0) {
            if (g[i][j] == "#") {
                r[i][j] = 0;
            } else if (r[i][j + 1] == 0) {
                r[i][j] = 1;
            } else {
                r[i][j] = r[i][j + 1] + 1;
            }
        }
    }
    // ..
    // ..
    // ..
    // o.
    repd(i, row, 0) {
        rep(j, 0, col + 1) {
            if (g[i][j] == "#") {
                d[i][j] = 0;
            } else if (d[i + 1][j] == 0) {
                d[i][j] = 1;
            } else {
                d[i][j] = d[i + 1][j] + 1;
            }
        }
    }
    rep(i, 0, row + 2) {
        rep(j, 0, col + 2) {
            ans = max(ans, l[i][j] + u[i][j] + r[i][j] + d[i][j]);
        }
    }
    return ans - 3;
}

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

    int row, col;
    cin >> row >> col;

    int ans = solve(row, col);
    cout << ans << endl;
}


Measured memory_bytes: 191472
import heapq

def main2(l, n):
    ans = 0
    lis = []
    heapq.heapify(lis)

    for i in range(1, n):
        for j in l[i]:
            heapq.heappush(lis, j)
        while len(lis) > i:
            ans += heapq.heappop(lis)

    return ans

def main():
    from sys import stdin

    t = int(stdin.readline().strip())

    answer = []
    for _ in range(t):

        n = int(stdin.readline().strip())
        ans = 0
        l = [[] for _ in range(n+1)]
        r = [[] for _ in range(n+1)]

        for _ in range(n):
            i, j, k = map(int, stdin.readline().strip().split())
            if j > k:
                ans += j
                l[i].append(j-k)
            elif j < k:
                if i == n:
                    ans += j
                else:
                    ans += k
                    r[n-i].append(k-j)
            else:
                ans += j

        ans -= main2(l, n) + main2(r, n)
        answer.append(ans)

    for i in answer:
        print(i)

main()

Measured memory_bytes: 47368
import scala.io.Source.stdin

case class Node(
  id: Int,
  children: List[Int],
  parent: Int = -1,
  depth: Int = 0
) {
  override def toString() = {
    val name = if (depth == 0) "root" else if (children.length > 0) "internal node" else "leaf"
    s"node $id: parent = $parent, depth = $depth, ${ name }, [${children.mkString(", ")}]"
  }
}

object Main {
  def main(argv: Array[String]) = {
    val head :: tail = stdin.getLines.toList
    val count = head.toInt
    val nodes = new Array[Node](count)

    tail foreach { line =>
      val id :: count :: children = line.split(" ").map(_.toInt).toList
      nodes(id) = Node(id, children)
    }

    nodes foreach { node =>
      node.children.foreach { id =>
        val child = nodes(id)
        nodes(id) = child.copy(parent = node.id)
      }
    }

    nodes.find(n => n.parent == -1) foreach { root =>
      recursive(0, root, nodes)
    }

    nodes foreach { node =>
      println(node)
    }
  }

  def recursive(currentDepth: Int, node: Node, nodes: Array[Node]): Unit = {
    node.children foreach { id =>
      nodes(id) = nodes(id).copy(depth = currentDepth + 1)
      recursive(currentDepth + 1, nodes(id), nodes)
    }
  }
}


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

using namespace std;

typedef long long ll;

const int MAX_N = 2e5 + 5;

void solve() {
  string s;
  cin >> s;
  if (s[s.size() - 1] == 's') {
    cout << s << "es";
  } else {
    cout << s << 's';
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int t = 1; //cin >> t;
  while (t --) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3644
import sys


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


INF = float('inf')

x = I()
if 400 <= x <= 599:
    ans = 8
elif 600 <= x <= 799:
    ans = 7
elif 800 <= x <= 999:
    ans = 6
elif 1000 <= x <= 1199:
    ans = 5
elif 1200 <= x <= 1399:
    ans = 4
elif 1400 <= x <= 1599:
    ans = 3
elif 1600 <= x <= 1799:
    ans = 2
else:
    ans = 1
print(ans)


Measured memory_bytes: 9224
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b;
  scanf("%d%d", &a, &b);
  puts(a == b ? "Yes" : "No");
}

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

typedef long long ll;
const ll MOD = 1000000007;
const int MAXN = 6010;

vector<int> G[MAXN];
int n, siz[MAXN];
ll f[MAXN][MAXN][2];
ll fac[MAXN];
ll tmp[MAXN][2];

void dfs(int x, int fa)
{
	f[x][1][0] = 1; siz[x] = 1;
	for(int i = 0; i < G[x].size(); ++i)
	{
		int y = G[x][i];
		if(y == fa) continue;
		dfs(y, x);
		for(int j = 1; j <= siz[x]; ++j)
		{
			tmp[j][0] = f[x][j][0];
			f[x][j][0] = 0;
			tmp[j][1] = f[x][j][1];
			f[x][j][1] = 0;
		}
		for(int j = 1; j <= siz[x]; ++j)
			for(int k = 1; k <= siz[y]; ++k)
			{
				(f[x][j + k][0] += tmp[j][0] * f[y][k][0] % MOD + tmp[j][1] * f[y][k][1] % MOD) %= MOD;
				(f[x][j + k][1] += tmp[j][0] * f[y][k][1] % MOD + tmp[j][1] * f[y][k][0] % MOD) %= MOD;
				(f[x][j][0] += tmp[j][0] * f[y][k][1] % MOD * fac[k - 1] % MOD + tmp[j][1] * f[y][k][0] % MOD * fac[k - 1] % MOD) %= MOD;
				(f[x][j][1] += tmp[j][0] * f[y][k][0] % MOD * fac[k - 1] % MOD + tmp[j][1] * f[y][k][1] % MOD * fac[k - 1] % MOD) %= MOD;
			}
		siz[x] += siz[y];
	}
}

int main()
{
	scanf("%d", &n);
	for(int i = 1, u, v; i < n; ++i)
	{
		scanf("%d %d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	fac[1] = 1;
	for(int i = 3; i < MAXN; i += 2) fac[i] = fac[i - 2] * i % MOD;
	dfs(1, 0); ll ans = 0;
	for(int i = 2; i <= n; i += 2)
	{
		ans = (ans + f[1][i][0] * fac[i - 1] % MOD) % MOD;
		ans = (ans - f[1][i][1] * fac[i - 1] % MOD) % MOD;
		ans = (ans + MOD) % MOD;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 471040
#include "bits/stdc++.h"
using namespace std;

int main() {
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if (x - r < 0 || y - r < 0 || x + r > w || y + r > h) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
}

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

using namespace std;

int main()
{
int sx,sy,tx,ty,i,x,y;
scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
x=tx-sx;
y=ty-sy;
for(i=0;i<x;++i){
    printf("R");
}
for(i=0;i<y;++i){
    printf("U");
}
for(i=0;i<x;++i){
    printf("L");
}
for(i=0;i<y;++i){
    printf("D");
}
printf("D");
for(i=0;i<x+1;++i){
    printf("R");
}
for(i=0;i<y+1;++i){
    printf("U");
}
printf("L");
printf("U");
for(i=0;i<x+1;++i){
    printf("L");
}
for(i=0;i<y+1;++i){
    printf("D");
}
printf("R");




    return 0;
}


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

int main(void)
{
    int n;
    cin >> n;
    bool flag = true;
    int a_cnt = 0;
    int b_cnt = 0;
    int ab_cnt = 0;
    for (int i = 0; i < n; i++)
    {
        std::string s;
        cin >> s;
        int l = s.length();
        if (s[0] == 'B')
            b_cnt++;
        if (s[l - 1] == 'A')
            a_cnt++;
        if ((s[0] == 'B') && (s[l - 1] != 'A'))
        {
            flag = false;
        }
        else if ((s[0] != 'B') && (s[l - 1] == 'A'))
        {
            flag = false;
        }
        for (int i = 0; i < l - 1; i++)
        {
            if ((s[i] == 'A') && (s[i + 1] == 'B'))
            {
                ab_cnt++;
            }
        }
    }
    // cout << "b_cnt: " << b_cnt << endl;
    // cout << "a_cnt: " << a_cnt << endl;
    // cout << "ab_cnt: " << ab_cnt << endl;
    // cout << "flag: " << flag << endl;

    int cnt;
    cnt = ab_cnt + min(a_cnt, b_cnt);
    if ((a_cnt == b_cnt) && (flag == true) && (cnt != 0) && (a_cnt != 0))
        cnt--;
    cout << cnt << endl;
}

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

int main(){
  string s;
  cin >> s;
  vector<int>ans(s.size(),0);
  int a=0,b=0;
  for(int i=0,l=s.size();i<l;i++){
    if(s.at(i)=='R'){
      if(i%2==0)
        a++;
      else
        b++;
    }else{
      if(i%2==0){
        ans.at(i)+=a;
        ans.at(i-1)+=b;
      }else{
        ans.at(i)+=b;
        ans.at(i-1)+=a;
      }
      a=0,b=0;
    }
  }
  for(int i=s.size()-1;i>=0;i--){
    if(s.at(i)=='L'){
      if(i%2==0)
        a++;
      else
        b++;
    }else{
      if(i%2==0){
        ans.at(i)+=a;
        ans.at(i+1)+=b;
      }else{
        ans.at(i)+=b;
        ans.at(i+1)+=a;
      }
      a=0,b=0;
    }
  }
  for(int i=0,l=s.size();i<l;i++){
    cout << ans.at(i);
    if(i==l-1)
      cout << '\n';
    else
      cout << ' ';
  }
  return 0;
}

Measured memory_bytes: 3860
#include<iostream>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<stdio.h>
using namespace std;

int main() {
    int a,bb=0,b,d;
    cin>>a>>b;
    d=b-a;
    for(int i=1;i<=d;i++)bb+=i;
    bb-=b;
    cout<<bb<<endl;
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
	string s;
	int a, b;
	while (cin >> s >> a >> b) {
		cout << s << " " << a + b << " " << a * 200 + b * 300 << endl;
	}
}

Measured memory_bytes: 3020
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n){
    int a[n],b[m],sum1=0,sum2=0,ans=1e9,p1,p2;
    r(i,n)cin>>a[i],sum1+=a[i];
    r(j,m)cin>>b[j],sum2+=b[j];
    r(i,n)r(j,m){
      int a1=sum1,a2=sum2;
      a1+=b[j]-a[i];
      a2+=a[i]-b[j];
      if(a1==a2&&abs(a1-a2)<ans){
	ans=abs(a1-a2);
	p1=a[i];
	p2=b[j];
      }
    }
    if(ans==1e9)cout<<(-1)<<endl;
    else cout<<p1<<' '<<p2<<endl;
  }
}

Measured memory_bytes: 3068
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<P> sushi;
	rep(i,n){
		int t;
		ll d;
		cin >> t >> d;
		sushi.emplace_back(d, t);
	}
	sort(sushi.rbegin(), sushi.rend());
	ll sum = 0, ans = 0, kind = 0;
	priority_queue<P> pq;
	vector<int> cnt(n+1, 0);
	rep(i,k){
		++kind;
		if(cnt[sushi[i].second]++ > 0){
			pq.push(P(-sushi[i].first, sushi[i].second));
			--kind;
		}
		sum += sushi[i].first;
	}
	ans = sum + kind * kind;
	for(int i = k; i < n; ++i){
		if(cnt[sushi[i].second] > 0) continue;
		if(pq.empty()) break;
		ll d = -pq.top().first;
		int t = pq.top().second;
		pq.pop();
		sum = sum - d + sushi[i].first;
		++cnt[sushi[i].second];
		--cnt[t];
		++kind;
		chmax(ans, sum + kind * kind);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6828
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
//////////////////////////////////


int main() {
    string s;
    cin >> s;
    int n = s.size();
    string tmp = "";
    string tmp2 = "";
    int cnt = 0;
    for(int i=0; i<n; i++) {
        tmp2 += s[i];
        if(tmp == tmp2) {
            continue;
        }else{
            tmp = tmp2;
            tmp2 = "";
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}




// EOF


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

P p[300000];
int main(){
	int n;cin>>n;
	rep(i,n){
		cin>>p[i].first>>p[i].second;
	}
	sort(p,p+n,[](P a,P b){return a.second<b.second;});
	ll sum=0;
	rep(i,n){
		sum+=p[i].first;
		if(sum>p[i].second){
			puts("No");return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 1792
import collections

k = int(input())
Q = collections.deque([int(i) for i in range(1, 10)])
for _ in range(k):
    x = Q.popleft()
    if x%10:
        Q.append(10*x + x%10 - 1)
    Q.append(10*x + x%10)
    if x%10 != 9:
        Q.append(10*x + x%10 + 1)
print(x)


Measured memory_bytes: 18868
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
r = 0
for i in range(n):
    a = list(map(int, input().split()))
    f = c
    for j in range(m):
        f = f + a[j] * b[j]
    if f > 0:
        r = r + 1
print(r)


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

int main() {
  int n;
  	cin>>n;
  vector<int>vec(n);
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  
  int sum=0;
  int resum=1;
  
  for(int j=1;j<n;j++){
    for(int k=0;k<j;k++){
      if(vec[k]<=vec[j]){
        sum+=1;
      }
    }
    if(sum==j){
      resum+=1;
      sum=0;
    }
    else{
      sum=0;
    }
    
  }
    cout<<resum<<endl;
      
  
}


Measured memory_bytes: 256
import java.util.*
 
fun main(args: Array<String>) {
  readLine()
  var arr = readLine()!!.split(" ")!!.map{ it -> it.toInt() }
  var counter = 0

  for ((index, value) in arr.withIndex()) {
    if (value != index + 1 ){
      counter++
    }
  }
  
  when (counter) {
    0,2 -> {
      println("YES")
    }
    else -> {
      println("NO")
    }
  }
}

Measured memory_bytes: 38052
#include <iostream>
using namespace std;
#define REP(i,a,b) for(int i = (int)(a); (i) < (b); i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int n;
	cin >> n;
	int a[n];
	rep(i,n) cin >> a[i];
	
	int k = 0;
	for (int j = n-1; j >= 0; j = j-2){
		cout << a[j] << " ";
		k = j;	
	}
	for (int l = k ? 0 : 1; l < n; l = l+2){
		cout << a[l] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>

void DiceRoll(int num[6], char cmd);
int DiceJudge(int Dice1[6], int Dice2[6]);

int main()
{
    int Dice[101][6];
    int i, j;
    int n, f_flag = 0;
    
    scanf("%d", &n);
    for(i=0; i<n; i++){
        for(j=0; j<6; j++){
            scanf("%d", &Dice[i][j]);
        }
    }
    for(i=0; i<n-1; i++){
        for(j=i+1; j<n; j++){
            if(DiceJudge(Dice[i], Dice[j]) == 1) f_flag = 1;
        }
    }
    
    if(f_flag == 0) printf("Yes\n");
    else printf("No\n");
    
    return 0;
}

void DiceRoll(int num[6], char cmd)
{
    int tmp = num[0];
    switch(cmd){
        case 'N':
            num[0] = num[1];
            num[1] = num[5];
            num[5] = num[4];
            num[4] = tmp;
            break;
        case 'S':
            num[0] = num[4];
            num[4] = num[5];
            num[5] = num[1];
            num[1] = tmp;
            break;
        case 'W':
            num[0] = num[2];
            num[2] = num[5];
            num[5] = num[3];
            num[3] = tmp;
            break;
        case 'E':
            num[0] = num[3];
            num[3] = num[5];
            num[5] = num[2];
            num[2] = tmp;
            break;
        default:
            break;
    }
}


int DiceJudge(int Dice1[6], int Dice2[6])
{
    int i, count=0;
    int judge = 0;
    for(i=1; i<6; i++){
        if(Dice1[0] == Dice2[i]){
            switch(i){
                case 1:
                    DiceRoll(Dice2, 'N');
                    break;
                case 2:
                    DiceRoll(Dice2, 'W');
                    break;
                case 3:
                    DiceRoll(Dice2, 'E');
                    break;
                case 4:
                    DiceRoll(Dice2, 'S');
                    break;
                case 5:
                    DiceRoll(Dice2, 'N');
                    DiceRoll(Dice2, 'N');
                    break;
                default:
                    break;
            }
        }
    }
    for(i=0; i<6; i++){
        if(i>1 && i<5){
            if(Dice1[1] == Dice2[i]){
                switch(i){
                    case 2:
                        DiceRoll(Dice2, 'N');
                        DiceRoll(Dice2, 'W');
                        DiceRoll(Dice2, 'S');
                        break;
                    case 3:
                        DiceRoll(Dice2, 'N');
                        DiceRoll(Dice2, 'E');
                        DiceRoll(Dice2, 'S');
                        break;
                    case 4:
                        DiceRoll(Dice2, 'N');
                        DiceRoll(Dice2, 'W');
                        DiceRoll(Dice2, 'W');
                        DiceRoll(Dice2, 'S');
                        break;
                    default:
                        break;
                }
            }
        }
    }
    for(i=0; i<6; i++){
        if(Dice1[i] == Dice2[i]) count++;
    }
    if(count == 6) judge = 1;
    
    return (judge);
}

Measured memory_bytes: 580
n = int(input())
str_n = str(n)
keta = len(str_n)
suji = [str(i) for i in range(10)]
#print(str_n,keta,suji)
ans = 0
for i in range(int(str_n[0]),10):
    tmp = ''
    for j in range(keta):
        tmp += suji[i]
    #print(tmp)
    if int(tmp)>=n:
        ans = int(tmp)
        break
print(ans)



Measured memory_bytes: 9124
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define A 0
#define G 1
#define C 2
#define T 3
#define int long long
bool ng(int a, int b, int c, int d) {
    int x[4] = {a, b, c, d};
    rep(i, 4) {
        if(i != 0) swap(x[i], x[i - 1]);
        rep(j, 2) {
            if(x[j] == A && x[j + 1] == G && x[j + 2] == C) return true;
        }
        if(i != 0) swap(x[i], x[i - 1]);
    }
    return false;
}
int dp[110][4][4][4];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, 4) rep(j, 4) rep(k, 4) {
        if(ng(i, j, k, -1)) continue;
        dp[3][i][j][k] = 1;
    }
    REP(i, 3, N - 1) {
        rep(a, 4) {
            rep(b, 4) {
                rep(c, 4) {
                    rep(d, 4) {
                        if(ng(a, b, c, d)) continue;
                        dp[i + 1][b][c][d] += dp[i][a][b][c];
                        dp[i + 1][b][c][d] %= mod;
                    }
                }
            }
        }
    }
    int ans = 0;
    rep(i, 4) rep(j, 4) rep(k, 4) ans = (ans + dp[N][i][j][k]) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	string S; cin >> S;
	string str;
	int num = S.size() - 7;
	if (S == "keyence") {
		cout << "YES" << endl;
		return 0;
	}
	rep(i, 8) {
		str = S.substr(0, i) + S.substr(i + num, 7 - i);
		if (str == "keyence") {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	cin >> S;
}

Measured memory_bytes: 256
import static java.util.Arrays.deepToString;

import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	final int INF = 100101001;
	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			int C = sc.nextInt();
			int R = sc.nextInt();
			if (R == 0) break;
			char[][] table = new char[R][C];
			for (int i = 0; i < R; i++) table[i] = sc.next().toCharArray();
			int[][] best = new int[R][C];
			for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) best[i][j] = INF;
			ArrayDeque<Integer> q = new ArrayDeque<Integer>();
			for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) {
				if (i == 0 || j == 0 || i == R - 1 || j == C - 1) {
					best[i][j] = 0;
					q.add(i);
					q.add(j);
				}
			}
			
			int[] dr = {0, -1, 0, 1};
			int[] dc = {1, 0, -1, 0};
			while (!q.isEmpty()) {
				int r = q.pollFirst();
				int c = q.pollFirst();
				if (table[r][c] == '&') {
					System.out.println(best[r][c]);
					break;
				}
				
				for (int i = 0; i < 4; i++) {
					int nr = r + dr[i];
					int nc = c + dc[i];
					if (0 <= nr && nr < R && 0 <= nc && nc < C) {
						boolean heavy = (table[r][c] == '#' && (table[nr][nc] == '.'||table[nr][nc] =='&'));
						int ncost = best[r][c] + (heavy ? 1 : 0);
						if (best[nr][nc] > ncost) {
							best[nr][nc] = ncost;
							if (heavy) {
								q.add(nr);
								q.add(nc);
							} else {
								q.addFirst(nc);
								q.addFirst(nr);
							}
						}
						
						
					}
				}
			}
			
			
		}
	}
}

Measured memory_bytes: 32964
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;






int main()
{
	int n, i, j, k, xx, yy;
	cin >> n;
	pair<int, int> p[n];
	
	
	for (i = 0; i < n; ++i)
	{
		cin >> xx >> yy;
		p[i] = make_pair(xx, yy);
	}
	
	
	sort(p, p+n);
	int ans;
	
	map<pair<int, int>, int> mymap;
	
	int dx, dy;
	
	for (i = 0; i < n - 1; ++i)
	{
		for (j = i+1; j < n; ++j)
		{
			dx = p[j].first - p[i].first;
			dy = p[j].second - p[i].second;
			mymap[make_pair(dx, dy)]+=1;
		}
	}
	
	int maxv = 0;
	
	for (auto it = mymap.begin(); it != mymap.end(); ++it)
	{
		//cout << it->first.first << " " << it->first.second << "		 " <<  it->second << endl;
		if (it->second > maxv)
		{
			maxv = it->second;
		}
	}
	
	ans = n - maxv;
	
	
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	string s; cin >> s;
	int n=s.size();
	if(n%2==1){
		cout << "No" << endl;
		return 0;
	}
	bool ans = true;
	for(int i=0; i<n-1; i+=2){
		if(s[i]!='h'||s[i+1]!='i'){
			ans = false;
			break;
		}
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}




Measured memory_bytes: 256