akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC075B
{
    class Program
    {
        static bool isBomb(List<string> src, int x, int y)
        {
            return src[y][x] == '#';
        }

        static int countBomb(int maxX, int maxY, List<string> src, int x, int y)
        {
            var count = 0;

            if (x > 0)
            {
                if (y > 0)
                {
                    if (isBomb(src, x - 1, y - 1)) { count++; }
                }

                if (isBomb(src, x - 1, y)) { count++; }

                if (y < (maxY - 1))
                {
                    if (isBomb(src, x - 1, y + 1)) { count++; }
                }
            }

            if (y > 0)
            {
                if (isBomb(src, x, y - 1)) { count++; }
            }

            if (y < (maxY - 1))
            {
                if (isBomb(src, x, y + 1)) { count++; }
            }

            if (x < (maxX - 1))
            {
                if (y > 0)
                {
                    if (isBomb(src, x + 1, y - 1)) { count++; }
                }

                if (isBomb(src, x + 1, y)) { count++; }

                if (y < (maxY - 1))
                {
                    if (isBomb(src, x + 1, y + 1)) { count++; }
                }
            }

            return count;
        }

        static void Main(string[] args)
        {
            var nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
            var h = nums[0];
            var w = nums[1];

            var input = new List<string>();
            foreach (var _ in Enumerable.Range(0, h))
            {
                input.Add(Console.ReadLine());
            }

            var output = new int[h, w];

            foreach (var y in Enumerable.Range(0, h))
            {
                foreach (var x in Enumerable.Range(0, w))
                {
                    output[y, x] = countBomb(w, h, input, x, y);
                }
            }

            var sb = new StringBuilder();
            foreach (var y in Enumerable.Range(0, h))
            {
                foreach (var x in Enumerable.Range(0, w))
                {
                    if (isBomb(input, x, y))
                    {
                        sb.Append("#");
                    }
                    else
                    {
                        sb.Append(output[y, x]);
                    }
                }
                sb.AppendLine();
            }

            Console.Write(sb.ToString());
        }
    }
}


Measured memory_bytes: 11348
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {s: String};
    let s: String = s;

    let mut count = 0;
    let s1 = &s[0..s.len() / 2];
    let s2 = &s[s.len() / 2..];

    for (i, j) in s1.chars().zip(s2.chars().rev()) {
        if i != j {
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 2176
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5 + 10 , MOD = 1e9 + 7;


int main(){
	ios_base::sync_with_stdio(NULL);cin.tie(nullptr);cout.tie(nullptr);
        string str;
        cin >> str;
        if(str.back() == '3') cout << "bon\n";
        else if(str.back() == '0' || str.back() == '1' || str.back() == '6' || str.back() == '8') cout << "pon\n";
        else cout << "hon\n";
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
int gcd(int a,int b) {return __gcd(a,b);}//if you use gcc to compile, use this

signed _main(){
  int N,ans=0; cin >> N;
  v<int> R,G,B;
  rep(i,N){
    char c; cin >> c;
    if(c=='R') R.push_back(i);
    else if(c=='G') G.push_back(i);
    else if(c=='B') B.push_back(i);
  }
  /*
  fore(j,G){
  int r=lower_bound(R.begin(),R.end(),j)-R.begin();
  int b=B.end()-upper_bound(B.begin(),B.end(),j);
  cout << r << " " << b << endl;
  int tp=0;
  fore(i,R){
  int tmp=j-i;
  if(tmp<=0) continue;
  int bank=j+tmp;
  if(binary_search(B.begin(),B.end(),bank)){
  //acout << i << " " << j << " " << bank << "\n";
  //tp--;
}
}
ans+=r*b+tp;
cout << ans << endl;
}
*/
int tp=0;
fore(x,R) fore(y,G){
  //if(x<y) swap(x,y);
  int tmp=x-y;
  int bank=x+tmp;
  if(binary_search(B.begin(),B.end(),bank)){
    tp--;
  }
  bank=y-tmp;
  if(binary_search(B.begin(),B.end(),bank)){
    tp--;
  }
  if(tmp%2==0){
    bank=y+tmp/2;
    if(binary_search(B.begin(),B.end(),bank)){
      tp--;
    }
  }
}
cout << SZ(R)*SZ(G)*SZ(B)+tp << endl;
return 0;
}


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

int main()
{
  int64_t n,m,sum;
  m=0;
  sum=0;
  cin>>n;
  vector<int64_t> a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a.at(i);
    if(a.at(i)<0)
    {
      m++;
      a.at(i)*=-1;
    }
    sum+=a.at(i);
  }
  sort(a.begin(),a.end());
  if(m%2==0)
    cout<<sum<<endl;
  else
    cout<<sum-a.at(0)*2<<endl;
}

Measured memory_bytes: 3988
#include <stdio.h>
int main(){
    int a,b,c;
    scanf("%d%d",&a,&b);
    c =a + b;
   if(a%3==0||b%3==0||c%3==0){
      printf("Possible");
   }else{
      printf("Impossible");
   }
   return 0;
}

Measured memory_bytes: 128
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b = map(int, input().split())
if 1 <= a and a <= 9 and 1 <= b and b <= 9:
    print(a*b)
else:
    print(-1)


Measured memory_bytes: 60012
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};



int32_t main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

#ifndef ONLINE_JUDGE
freopen("input.txt","rt",stdin);
freopen("output.txt","wt",stdout);
#endif 

string s,t;
cin>>s>>t;

int ans=0;
for(int i=0;i<s.size();i++)
{
    ans+=s[i]!=t[i];
}
cout<<ans<<"\n";



}






Measured memory_bytes: 3800
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
typedef long long int ll;
using namespace std;
int main(){
ll N,K;
cin >> N >> K;
ll x[N];
ll m=0;
ll p=0;
ll count=0;
ll ans=pow(10,10);
int center=1000;
int num_center=0;
for(int i=0;i<N;i++){
	cin >> x[i];
}
for(int i=0;i<N-K+1;i++){
	int left=x[i];
	int right=x[i+K-1];
	int signl = (left > 0)-(left < 0);
	int signr = (right > 0)-(right < 0); 
	if(signl==signr){
		if(abs(left)>abs(right)){
			if(ans>abs(left)){
				ans=abs(left);
			}
		}else{
			if(ans> abs(right)){
				ans=abs(right);
			}
		}
	}else{
		if(abs(left)>abs(right)){
			if(2*abs(right)+abs(left)<ans){
				ans=abs(left)+2*abs(right);
			}
		}else{
			if(2*abs(left)+abs(right)<ans){
				ans=abs(right)+2*abs(left);
			}
		}
	}
}
cout << ans << endl;		
}

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

using namespace std;

int main(void) {
  int N;
  string S;
  cin >> N >> S;
  
  map<char, long long> ch;
  ch.emplace('R', 0);
  ch.emplace('G', 0);
  ch.emplace('B', 0);

  for (int i = 0; i < N; i++) {
    ch[S[i]]++;
  }

  long long total = ch['R'] * ch['G'] * ch['B'];

  if (total == 0) {
    cout << 0 << endl;
  } else {
    long long ans = total;
    for (int i = 1; i*2 < N; i++) {
      for (int j = 0; j + i*2 < N; j++) {
        if (S[j] != S[j+i] && S[j+i] != S[j+i*2] && S[j+i*2] != S[j])
        {
          ans--;
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=7+1e9;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}
ll getInv(ll x,ll p){return qpow(x,p-2,p);}

int main(){
    int n; scanf("%d",&n);
    vector<ll> a(n+1);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    map<ll,int> ck;
    for(int i=1;i<=n;i++){
        if(ck[a[i]-i]) ck[a[i]-i]++;
        else ck[a[i]-i]=1;
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        if(ck[-a[i]-i]) ans+=ck[-a[i]-i];
    }
    printf("%lld\n",ans);
}

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

namespace _058
{
    class Program
    {
        // 058-C
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = new string[n];
            for (int i = 0; i < n; i++)
            {
                s[i] = Console.ReadLine();
            }

            Dictionary<char, int[]> data = new Dictionary<char, int[]>();
            for (int i = 0; i < s[0].Length; i++)
            {
                char x = s[0][i];
                if(data.ContainsKey(x))
                {
                    data[x][0] += 1;
                }
                else
                {
                    var ary=new int[n];
                    ary[0] = 1;
                    data.Add(x,ary);
                }
            }

            for (int i = 1; i < n; i++)
            {
                for (int j = 0; j < s[i].Length; j++)
                {
                    char x = s[i][j];
                    if(data.ContainsKey(x))
                    {
                        data[x][i] += 1;
                    } 
                }
            }

            string ans = "";
            foreach(var k in data.Keys.OrderBy(x=>x))
            {
                for (int i = 0; i < data[k].Min(); i++)
                {
                    ans += k;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13408
#include <iostream>

int main()
{
	std::string s;
	std::cin >> s;
	
	char c = 'a';
	while (c <= 'z') {
		if (s.find(c) == std::string::npos) {
			break;
		}
		c++;
	}
	
	if (c > 'z') std::cout << "None" << std::endl;
	else std::cout << c << std::endl;
	
	return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back  
#define INF 10000000000

 

 int main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   string s,t,u;
   ll a,b;
   cin>>s>>t;
   cin>>a>>b;
   cin>>u;
   if(u == s){
   	cout<<a-1<<" "<<b;
   }else{
   	cout<<a<<" "<<b-1;
   }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,ans=1;
    cin>>n;
    for(;;){
      if(n<ans*2){
        cout<<ans<<endl;
        return(0);
      }
      else{
        ans*=2;
      }
    }
    return(0);
}

Measured memory_bytes: 256
/*************************************************************************
> File Name: test.cpp
> Author: Akira 
> Mail: qaq.febr2.qaq@gmail.com 
************************************************************************/

//#pragma comment(linker, "/STACK:102400000,102400000")
#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
#define ALL(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
using namespace std;                                                                                              

#define MaxN 100005
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
template<typename T> T abs(T val){return val>0?val:-val;}
inline int max2(int a, int b) {return ((a > b)? a : b);}
inline int min2(int a, int b) {return ((a < b)? a : b);}
inline int max3(int a, int b, int c) {return max2(a, max2(b, c));}
inline int min3(int a, int b, int c) {return min2(a, min2(b, c));}
template <class T> inline void read(T &ret) {char c; ret=0;while((c=getchar())<'0'||c>'9');while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar();}
template <class T> inline void out(T x) {if(x>9) out(x/10);putchar(x%10+'0');}


int w[2],s[2],E,F;

int DP[3001];
void CompletePack(int cost, int weight, int tot) //O(N*V)
{
    for(int v=cost;v<=tot;v++)            // 顺序遍历，使得每种物品可以被选择无限次
        DP[v] = max(DP[v], DP[v-cost]+weight);
}

bool is[33];
void cal(int cost, int tot)
{
    is[0] = 1;
    for(int v=cost;v<=tot;v++)
    {
        is[v] |= is[v-cost];
    }
}

int main()
{
    //std::ios::sync_with_stdio(false);
    while(~scanf("%d%d%d%d%d%d", &w[0], &w[1], &s[0], &s[1], &E, &F))
    {
        CLR(DP);
        CLR(is);
        for(int i=0;i<2;i++)
            CompletePack(s[i], s[i], F);
        int limit = F/100;

        for(int i=0;i<2;i++)
            cal(w[i], limit);

        int s1 = 0, s2 = 0;
        for(int i=0;i<=limit;i++)
        {
            // debug(i)debug(is[i])
            if(is[i])
            {
                int water = i*100;
                int sugar = min(DP[i*E],F-water);
                // debug(water) debug(sugar)
                if( s1*(sugar+water) <= s2*(sugar) )
                {
                    s1 = sugar;
                    s2 = sugar + water;
                }
            }
        }
        printf("%d %d\n", s2, s1);
    }

    // system("pause");
    //printf("%lld\n", ((x)%mod+mod)%mod );
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll N, K;
  cin >> N >> K;
  N %= K;
  N = min(N, K-N);
  cout << N << '\n';
  return 0;
}

Measured memory_bytes: 3512
n = gets.to_i
r = n % 11
q = n / 11
if r >= 1 && r <= 6
  ans = (q + 1) * 2 - 1
elsif r >= 7 && r <= 11
  ans = (q + 1) * 2
elsif r == 0
  ans = q * 2
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef vector<int> vi;
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 105;
lint a[MAXN];
struct LinearBase {
	lint bs[60];
	LinearBase () {
		memset(bs, 0, sizeof(bs));
	}
	inline void insert(lint x) {
		for (int i = 59; ~i; --i) {
			if (x >> i & 1) {
				if (bs[i]) {
					x ^= bs[i];
				} else {
					bs[i] = x; return;
				}
			}
		}
	}
	inline bool inc(lint x) {
		for (int i = 59; ~i; --i) {
			if (x >> i & 1) {
				if (bs[i]) {
					x ^= bs[i];
				} else {
					return false;
				}
			}
		}
		return true;
	}
	inline bool inc(const LinearBase & x) {
		bool flag = true;
		for (int i = 0; i != 60; ++i) {
			flag &= inc(x.bs[i]);
		}
		return flag;
	}
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int T;
	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		rep (i, 1, n) {
			cin >> a[i];
		}
		string s;
		cin >> s;
		s = '0' + s;
		LinearBase a0, a1;
		int res = 0;
		per (i, n, 1) {
			if (s[i] == '0') {
				a0.insert(a[i]);
				a1 = LinearBase();
			} else {
				a1.insert(a[i]);
			}
			if (!a0.inc(a1)) {
				res = 1; break;
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3640
#define _CRT_SECURE_NO_WARNINGS
#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")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

signed main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	vin(a);
	int m = *mx(a);
	pair<int, int> ans;
	int d = -inf;
	for (int i = 0; i < n; ++i)
	{
		if (m == a[i])
		{
			continue;
		}
		int nd = min(a[i], m - a[i]);
		if (d < nd)
		{
			d = nd;
			ans = { a[i], m };
		}
	}
	swap(ans.first, ans.second);
	pout(ans);
	sp;
}	

Measured memory_bytes: 888
import java.util.*;
class Main {
  public static void main(String[] args){
    System.out.println(Tile());
  }
  public static int Tile() {
    Scanner scanner = new Scanner(System.in);
    String str = scanner.nextLine();
    	if(str.length() == 1) return 0;
  
    String tmp = str.substring(0,1);
    int result = 0;
    for(int i= 1; i < str.length(); i++){
    	if(tmp.equals(str.substring(i, i+1))){
        	result++;
            tmp = tmp.equals("0") ? "1" : "0";
        }else{
        	tmp = str.substring(i, i+1);
        }
    }
    return result;
  }
}

Measured memory_bytes: 36292
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <numeric>
#include <functional>

using namespace std;

int main()
{
  int n, K;
  scanf("%d%d", &n, &K);
  int digit[10] = { 0, };
  for (int i = 0; i < K;i++) {
    int val;
    scanf("%d", &val);
    digit[val] = 1;
  }
  for (int i = n; ; i++) {
    string s = to_string(i);
    bool fail = false;
    for (auto c : s) {
      if (digit[c - '0']) {
        fail = true;
        break;
      }
    }
    if (fail)
      continue;
    printf("%d\n", i);
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int x, a;
    cin >> x >> a;

    if(x < a) {
        cout << 0 << endl;
    } else {
        cout << 10 << endl;
    }
    return 0;
} /*atcoder*/


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

using namespace std;
typedef long long ll;
const ll MOD = 1000000000 + 7;
int main() {
    ll n, i, j, k;
    cin >> n;
    vector<ll> c(n);
    vector<vector<ll>> place(2 * 100000 + 20);
    for(i = 0; i < n; i++) {
        cin >> c[i];
        place[c[i]].push_back(i);
    }
    vector<ll> dp(n, 0);
    dp[0] = 1;
    for(i = 1; i < n;i++){
        dp[i] = (dp[i]+dp[i - 1])%MOD;
        int it = lower_bound(place[c[i]].begin(), place[c[i]].end(), i) - place[c[i]].begin();
        if(it == 0) continue;
        it--;
        if(i-place[c[i]][it]>1){
            dp[i] = (dp[i] + dp[place[c[i]][it]]) % MOD;
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
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; }
const long long MOD = 1000000007;
const long long INF = (1LL << 29);
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int k, s; cin >> k >> s;
	int cnt = 0;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			int a = s - i - j;
			if (!(a > k || a < 0)) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        try (Scanner sc = new Scanner (System.in)){
            while(true){
                int n = sc.nextInt();
                if(n==0){
                    break;
                }
                int [] scores = new int[n];
                double sum =0;
                for(int i=0;i<scores.length;i++){
                    scores[i]=sc.nextInt();
                    sum += scores[i];
                }
                double ave = sum/n;
                double varp=0;
                double var =0;
                for(int i=0;i<scores.length;i++){
                    varp += (scores[i]-ave)*(scores[i]-ave);
                }
                var = varp/n;
                System.out.printf("%f\n",Math.sqrt(var));
            }
        }
    }
}


Measured memory_bytes: 31820
#include<bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define pb push_back
#define popb pop_back
#define popf pop_front
#define pf push_front
#define si size()
#define mp make_pair 
#define mt make_tuple
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound

#define ask(i,m,n) for(lli i=m;i<n;i++)
#define anket ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
 
#define endl "\n"
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a,b) cout<<a<<" "<<b<<"\n"
#define o3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
using namespace std;

#define prime1 1000000007
#define prime2 998244353

lli modadd(lli n,lli m , lli mod){
    lli sum = ((n+m)%mod+mod)%mod;
    return sum;
}

lli modsub(lli n,lli m,lli mod){
    lli diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}

lli modpro(lli n,lli m, lli mod){
    lli pro = ((n*m)%mod+mod)%mod;
    return pro;
}

lli powmod(lli x,lli y,lli mod){
    x %= mod;
    y %= mod;
    lli res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}

lli moddiv(lli n,lli m,lli mod){
    //return n/m mod (mod) or n*(m)^-1 mod (mod)
    lli a = powmod(m,mod-2,mod);
    //this is because of fermats thm i.e. a^-1 = a^p-2 mod(p) check
    //multiplying p on both sides
    lli res = modpro(a,n,mod);
    return res;
}




int main() {
	anket;
	lli n;
	cin>>n;
	lli a[n],b[n];
	ask(i,0,n){
	    cin>>a[i];
	    b[i]=a[i];
	}
	sort(b,b+n);
	lli ans=0;
	for(lli i=0;i<n;i++){
	    lli d=0;
	    for(lli j=i;j<n;j++){
	        if(b[j]==b[i]){
	            d++;
	        }
	        else{
	            break;
	        }
	    }
	    i += d-1;
	    ans += d*(d-1)/2;
	}
	ask(i,0,n){
	    lli c = upper_bound(b,b+n,a[i]) - lower_bound(b,b+n,a[i]);
	    o1(ans-c+1);
	}
	
	
	return 0;
}




Measured memory_bytes: 5760
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
	int64_t x;
	mint(int64_t x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(int64_t t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}

	//for prime mod
	mint inv() const { return pow(mod-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
	vector<mint> frac, ifrac;
	combination(int n):frac(n+1), ifrac(n+1) {
		assert(n < mod);
		frac[0] = 1;
		for (int i = 1; i <= n; ++i) frac[i] = frac[i-1]*i;
		ifrac[n] = frac[n].inv();
		for (int i = n; i >= 1; --i) ifrac[i-1] = ifrac[i]*i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return frac[n]*ifrac[k]*ifrac[n-k];
	}
} c(100010);

//head



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vi x(n);
	rep(i, n) cin >> x[i];
	if(n == 2) {
		cout << x[1]-x[0] << endl;
		return 0;
	}

	vector<mint> sum(n);
	rep(i, n-1) {
		sum[i+1] += sum[i] + x[n-2-i] - x[i];
	}

	mint ans;
	rep(i, n-1) {
		if(sum[i+1].x != 0) ans += sum[i+1] * c.frac[i] * c.frac[n-3-i] * c(n-1, 2+i);
		ans += c.frac[i] * c.frac[n-2-i] * c(n-1, 1+i) * (x[n-1] - x[n-2-i]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 6108
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, x int
	fmt.Scan(&N, &x)

	var a []int
	var arg int
	for i := 0; i < N; i++ {
		fmt.Scan(&arg)
		a = append(a, arg)
	}

	var sum int

	for _, v := range a {
		sum += v
	}

	if sum == x {
		fmt.Println(N)
		return
	}

	sort.Ints(a)
	var max int
	sum = 0
	for i := 0; i < len(a); i++ {
		sum += a[i]
		max = i
		if sum > x {
			break
		}
	}

	fmt.Println(max)
}



Measured memory_bytes: 1840
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

//----------------------------------------------------------------------

#define MAX 1000

int main(void) {
  cin >> n >> k;

  FOR(i, k + 1, n + 1) {
	temp = n / i;
	ans += temp * (i - k);
	temp = n - temp * i;
	if (temp >= k) {
	  if (k != 0) {
		ans += temp - k + 1;
	  }
	  else {
		ans += temp - k;
	  }
	}
	cnt++;
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
    const int INF = 1e9;
    const int MAX_V = 200 + 10;
    const int MAX_E = 40000;
    int V, E, R;
    int d[MAX_V][MAX_V];
    vector<int> v;

    cin >> V >> E >> R;
    for (int i = 0; i < R; ++i){
        int r;
        cin >> r;
        v.push_back(r);
    }
    sort(v.begin(), v.end());
    for (int i = 1; i <= V; ++i){
        for (int j = 1; j <= V; ++j) {
            if (i == j) d[i][j] = 0;
            else d[i][j] = INF;            
        }
    }

    for (int i = 0; i < E; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
    }

    for (int k = 1; k <= V; ++k)
        for (int i = 1; i <= V; ++i)
            for (int j = 1; j <= V; ++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    
    long long ans = INF;
    do {
        long long sum = 0;
        for (int i = 0; i < R-1; ++i){
            sum += d[v[i]][v[i+1]];
        }
        ans = min(ans, sum);
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;
const int N = 1e5 + 10;
#define int long long
int dp[N];

int32_t main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1];
		int p6, p9;
		p6 = p9 = 1;
		while (p6 <= i) {
			dp[i] = min(dp[i],dp[i -  p6]);
			p6 *= 6;
		}
		while (p9 <= i) {
			dp[i] = min(dp[i], dp[i - p9]);
			p9 *= 9;
		}
		dp[i] ++;
	}
	cout << dp[n] << endl;

}


Measured memory_bytes: 1024
// AOJ 1091
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

int main(void)
{
	double a, l, x;

	while (scanf("%lf %lf %lf", &a, &l, &x) != EOF){

		double s = 0, ret = 0;

		s = (a + l + l) / 2.0;
		ret += sqrt(s * (s - a) * (s - l) * (s - l));

		s = (l + l + x) / 2.0;
		ret += (sqrt(s * (s - l) * (s - ((l + x) / 2.0)) * (s - ((l + x) / 2.0))) * 2.0);

		printf("%.08lf\n", ret);
	}

	return 0;
}

Measured memory_bytes: 1240
import java.util.Scanner

import scala.annotation.tailrec
import scala.io.StdIn

object Main {
  def main(args: Array[String]) = {
    val S = StdIn.readLine()

    val (zeros, ones) = S.partition(_ == '0')
    println(zeros.length.min(ones.length) * 2)

    /*
    @tailrec
    def calc(target: Char, remains: String, pre: String = "", num: Int = 0): (String, Int) = {
      if (remains.isEmpty) (pre, num)
      else if (pre.isEmpty) calc(remains.head, remains.tail, pre + target, num)
      else {
        val (r, n) = if (pre.last != target) (pre.init, num + 2) else (pre + target, num)
        calc(remains.head, remains.tail, r, n)
      }
    }

    @tailrec
    def loop(target: String, total: Int = 0): Int = {
      val (pre, num) = calc(target.head, target.tail)
      println(pre)
      if (num == 0) total else loop(pre, total + num)
    }

    println(loop(S))
    */
  }
}


Measured memory_bytes: 29436
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

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

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

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

	ll fa, fb;
	if (a % 2 == 1) {
		fa = (((a-1) / 2) % 2) ^ (a-1);
	}
	else {
		fa = (a / 2) % 2;
	}

	if (b % 2 == 0) {
		fb = ((b / 2) % 2) ^ b;
	}
	else {
		fb = ((b+1) / 2) % 2;
	}
	cout << (fa ^ fb) << endl;
}


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

int main(){
  string s;
  cin>>s;
  int N=s.size();
  int a=-1;int b=-1;
  if(s[0]==s[N-1])a=1;
  if(N%2)b=1;
  if(a*b==1)cout<<"Second"<<endl;
  else cout<<"First"<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;
using int32 = __uint32_t;

int check(int a, int n){
    if(a == 1)return 0;
    int zp = floor(n/(a - 1)) * a;
    if(zp == n)return a - 1;
    return 0;
}

void solve() {
    int n;
    cin >> n;

    int ans = 0;
    for(int i = 1; i* i <= n; i++){
        if(n % i == 0){
            ans += check(i, n);
            if(n/i != i)ans  += check(n/i, n);
        }
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


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

using namespace std;

vector <int> V;
int A[101010];
int n, ans;

int main()
{
	int i;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",A+i);
		V.push_back(A[i]);
	}
	
	sort(V.begin(), V.end());
	V.erase(unique(V.begin(), V.end()), V.end());
	
	for(i=0;i<n;i++){
		if((lower_bound(V.begin(), V.end(), A[i]) - V.begin() + i) & 1) ans++;
	}
	
	printf("%d\n",ans/2);
	
	return 0;
}

Measured memory_bytes: 1148
# input
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [None for _ in range(N)]
# initiate
dp[0] = 0

for i in range(1, N):
    min_ = min(dp[k] + abs(H[k]-H[i]) for k in range(max(0, i-K), i))
    dp[i] = min_

print(dp[-1])
pass

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

ll f(ll n){
  if(n%2 == 1)return 0;
  else{
    n /= 2;
    ll ans = 0;
    while(n >= 5){
      n /= 5;
      ans += n;
    }
    return ans;
  }
}
int main(){
  ll n; cin >> n;
  cout << f(n) << endl; 
}

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

int main() {
  string S ;
  cin >> S;
  if (S[0] != S[1] && S[1] != S[2] && S[2] !=S [0]) {
  cout << "Yes" << endl;
}
else {
  cout << "No" << endl;
}

  return 0;
  }


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

int main() {
  int N;
  cin >> N;
  int a, b, c, d;
  d = N % 10;
  c = (N % 100 - d) / 10;
  b = (N % 1000 - d - 10 * c) / 100;
  a = (N - d - 10 * c - 100 * b) / 1000;
  
  if (a == b && b == c) {
    cout << "Yes" << endl;
  }
  else if (b == c && c == d) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

int main(){
	int n, q, query, x, t;
	
	cin>>n>>q;
	
	stack<int> sta[n];
	
	for(int i = 0; i < q; i++){
		cin>>query>>t;
		
		if(query == 0){
			cin>>x;
			sta[t].push(x);
		} else if(query == 1){
			if(!sta[t].empty())cout<<sta[t].top()<<endl;
		} else {
			if(!sta[t].empty())sta[t].pop();
		}
	}
	
	return 0;
}


Measured memory_bytes: 4424
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
#include<map>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
using std::map;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
const int N=100010;
void failed()
{
	printf("-1\n");
	exit(0);
}
map<ll,int> mp;
pll a[N];
int s[N];
ll d[N];
int n;
int b[N];
vector<int> g[N];
vector<pii> ans;
int sz[N];
ll f[N];
ll h[N];
void dfs(int x,int fa)
{
	sz[x]=1;
	for(auto v:g[x])
	{
		dfs(v,x);
		sz[x]+=sz[v];
		f[x]+=f[v]+sz[v];
	}
}
void dfs2(int x,int fa)
{
	for(auto v:g[x])
	{
		h[v]=h[x]+(n-sz[v])-sz[v];
		dfs2(v,fa);
	}
}
int main()
{
	open2("f");
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&d[i]);
		s[i]=1;
		a[i]=pll(d[i],i);
		mp[d[i]]=i;
	}
	sort(a+1,a+n+1,std::greater<pll>());
	for(int i=1;i<n;i++)
	{
		int x=a[i].second;
		int fa=mp[d[x]-(n-s[x])+s[x]];
		if(!fa||b[fa])
			failed();
		g[fa].push_back(x);
		ans.push_back(pii(fa,x));
		s[fa]+=s[x];
		b[x]=1;
	}
	int rt=a[n].second;
	dfs(rt,0);
	h[rt]=f[rt];
	dfs2(rt,0);
	for(int i=1;i<=n;i++)
		if(h[i]!=d[i])
			failed();
	for(auto v:ans)
		printf("%d %d\n",v.first,v.second);
	return 0;
}

Measured memory_bytes: 21236
#include <bits/stdc++.h>
using namespace std;
int last(int x){
    return x%10;
}
int first(int x){
    return (x / pow(10, floor( log10(x) ) ));
}

int main(){
    int n;
    int mp[10][10]{};
    cin >> n;
    for(int i=1;i<=n;i++){
        mp[first(i)][last(i)]++;
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        ans += mp[last(i)][first(i)];
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

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

void solve(int n){
    vector<int> day(31);
    rep(i, n){
        int d;
        cin >> d;

        rep(j, d){
            int x;
            cin >> x;
            day[x] |= (1LL << i);
        }
    }

    vector<int> map(n);
    rep(i, n){
        map[i] = 1LL << i;
    }
    for(int i = 1; i <= 30; i++){
        int tmp = 0;
        rep(j, n){
            if((day[i] >> j) % 2 == 1LL){
                tmp |= map[j];
            }
        }
        rep(j, n){
            if((day[i] >> j) % 2 == 1LL){
                map[j] |= tmp;
            }
            if(map[j] == (1LL << n) - 1LL){
                cout << i << endl;
                return;
            }
        }
    }
    cout << -1 << endl;
    return;
}

signed main(){
    while(true){
        int n;
        cin >> n;

        if(n == 0){
            break;
        }

        solve(n);
    }

    return 0;
}



Measured memory_bytes: 2960
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
string s[6] = {"Sunny", "Cloudy", "Rainy", "Sunny", "Cloudy", "Rainy"};
int main(void)
{

	string t; cin >> t;
	int n = t.size();
	t = " " + t;
	for (int i = 1; i <= n; ++i) {
		if (i & 1 && t[i] == 'L')
			return 0 * puts("No");
		if (i % 2 == 0 && t[i] == 'R')
			return 0 * puts("No");
	}
	puts("Yes");
	return 0;
}

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

#define ll long long
using namespace std;

int main() {
//    string s, t;
//    cin>>s>>t;
//    ll ans = 0;
//    for (int i = 0; i <= s.length(); ++i) {
//        if  (s[i] != t[i]){
//            ans++;
//        }
//    }
//    cout<<ans;
    ll a;
    cin>>a;
    cout<<a +a*a*a+a*a;
}


Measured memory_bytes: 3620
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 		int num = sc.nextInt();
      	
      	int height[] = new int[num];
      	int kouho[] = new int[num];
      	int maximum = 0;
      	int maximum_kouho = 0;
      	height[0]=sc.nextInt();
      	for(int i=1;i<num;i++){
        	height[i] = sc.nextInt();
          	if(height[i]<=height[i-1]){ 
              maximum_kouho=maximum_kouho+1;
            }else{
              if(maximum_kouho>maximum){
              	maximum = maximum_kouho;
              }
                maximum_kouho = 0;
            }
        }
      	              if(maximum_kouho>maximum){
              	maximum = maximum_kouho;
              }
		
      	
		System.out.println(maximum);
	}
}

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

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define li long long
#define ld long double
#define x first
#define y second
#define pt pair<int, int>
#define pll pair<li, li>
#define forn(i, t) for(int i = 0; i < (t); i++)
#define fore(i, f, t) for(int i = (f); i < (t); i++)
#define forr(i, f, t) for(int i = (f) - 1; i >= (t); i--)
#define all(x) (x).begin(), (x).end()
#define ins insert

using namespace std;


const int INF = 1e9;
const int MOD = 1e9 + 7;
const li INF64 = 1e18;
const ld EPS = 1e-7;

mt19937 myrand(time(NULL));

const int N = 100 * 1000 + 13;

int n;
vector<int> g[N];


bool read(){
	if(scanf("%d", &n) != 1)
		return 0;
	forn(i, n)
		g[i].clear();
	forn(i, n - 1){
		int f, t;
		scanf("%d%d", &f, &t);
		--f, --t;
		g[f].pb(t);
		g[t].pb(f);
	}
	return 1;
}

int dp[N];

void dfs(int v, int p = -1){
	dp[v] = 0;
	int cnt = 0;
	for (auto u : g[v]) if (u != p){
		++cnt;
		dfs(u, v);
		dp[v] ^= dp[u] + 1;
	}
}

void solve(){
	dfs(0);
	printf(dp[0] ? "Alice\n" : "Bob\n");
}


int main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
	#endif
	while(read())
		solve();
	return 0;
}

Measured memory_bytes: 17324
fn main() {
    if {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        line.trim().parse::<i64>().unwrap()
    } >= 3200 {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        println!("{}", line.trim());
    } else {
        println!("red");
    }
}


Measured memory_bytes: 4352
import java.util.*;

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

    while(true){
      int n = s.nextInt();
      int m = s.nextInt();

      if(n==0 && m==0){
        break;
      }

      int[] a = new int[n];
      for(int i=0; i<n; i++){
        a[i] = s.nextInt();
      }

      int ans = 0;
      for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
          if(i==j){
            continue;
          }
          int l = a[i] + a[j];
          if(ans < l && l <= m){
            ans = l;
          }
        }
      }

      if(ans==0){
        System.out.println("NONE");
      }else{
        System.out.println(ans);
      }
    }
    
  }
}


Measured memory_bytes: 50784
#include <stdio.h>
#define M 100000
typedef struct {
  char name[10];
  int t;
} QUEUE;

QUEUE que[M];
int front, rear;

void Enqueue(QUEUE x) {
  if (rear == M) rear = 0;
  que[rear] = x;
  rear++;
}

QUEUE Dequeue(void) {
  if (M == front) front = 0;
  return que[front++];
}

int main(int argc, char const *argv[]) {
  int i, n, q, exet = 0;
  QUEUE queue;
  scanf("%d %d", &n, &q);
  for (i = 0; i < n; i++) {
    scanf("%s %d", queue.name, &queue.t);
    Enqueue(queue);
  }

  while (n != 0) {
    queue = Dequeue();
    if (queue.t > q) {
      queue.t = queue.t - q;
      exet = exet + q;
      Enqueue(queue);
    } else {
      exet = exet + queue.t;
      printf("%s %d\n", queue.name, exet);
      n--;
    }
  }
  return 0;
}

Measured memory_bytes: 3300