akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    FOR(i, 1, 10)
        FOR(j, 1, 10)
        if (N == i * j) {
            cout << "Yes" << endl;
            return 0;
        }

    cout << "No" << endl;
    return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    while(cin >> n >> a >> b, n or a or b)
    {
        vector<int> v(n);
        for(int i = 0; i < n; i++) cin >> v[i];
        sort(v.begin(), v.end(), greater<int>());
        int ans = -1, gap = 0;
        for(int i = a; i <= b; i++)
        {
            int s = v.front(), t = v.back();
            for(int j = 0; j < i; j++) s = min(s, v[j]);
            for(int j = i; j < v.size(); j++) t = max(t, v[j]);
            int d = abs(s - t);
            if(d >= gap)
            {
                gap = d;
                ans = i;
            }
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 3104
#include<stdio.h>
int main()
{
    int m,n,i;
    scanf("%d",&m);
    if(m>=1&&m<2) printf("1\n");
    else if(m>=2&&m<4) printf("2\n");
    else if(m>=4&&m<8) printf("4\n");
    else if(m>=8&&m<16) printf("8\n");
    else if(m>=16&&m<32) printf("16\n");
    else if(m>=32&&m<64) printf("32\n");
    else printf("64\n");
    return 0;
}

Measured memory_bytes: 128
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());
        String s = sc.next();
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < s.length(); i++){
            char c = s.charAt(i);
            c += n;
            if(c > 'Z') c -= 26;
            sb.append(c);
        }
        
        System.out.println(sb);
    }
}

Measured memory_bytes: 24020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    ll N,M,X;
    cin >> N >> M >> X;

    vector<vector<int>> A(N,vector<int>(M,0));
    vector<int> C(N);
    REP (i,N) {
        cin >> C[i];
        REP (j,M) {
            cin >> A[i][j];
        }
    }

    int ans = 10000000;
    int ptn = 1<<N;

    bool buyed = false;
    REP (mask,ptn) {
        vector<int> grasp(M);
        int charge = 0;
        REP (i,N) {
            if ((mask>>i)&1) {
                charge += C[i];
                REP (j,M) {
                    grasp[j] += A[i][j];
                }
            }
        }

        bool chk = true;
        REP (j,M) {
            if (grasp[j] < X) {
                chk = false;
            }
        }
        if (chk) {
            ans = min(ans,charge);
            buyed = true;
        }
    }

    if (buyed) {
        cout << ans << endl;
    }
    else {
        cout << -1 << endl;
    }

    return 0;
}


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

int main()
{
  string s;
  cin >> s;
  uint64_t cnt = 0;
  for (int i = 0; i < s.length(); i++) {
    if (i % 2 == s[i] - '0') cnt++;
  }
  cout << min(cnt, s.length() - cnt) << endl;
}

Measured memory_bytes: 512
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include <iostream>
#include <vector>
using namespace std;

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> N_array(N);

    for (int i=0; i<N;i++){
        N_array.at(i) =K;
    }

    for (int i=0; i<Q; i++){
        int winner;
        cin >> winner;
        N_array[winner -1 ]++;
       // for (int j=0; j<N; j++){
         //   N_array[j]--;
            //cout << N_array[j];
        //}
    }
    //for(int i=0;i<N;i++) N_array[i] = N_array[i] - Q;

    for (int i;i<N;i++){
        if (N_array[i] > Q){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int A, B, C;
  cin >> A >> B >> C;

  cout << std::max({A, B, C}) * 9 + A + B + C << endl;
  return 0;
}


Measured memory_bytes: 256
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

vector<int> p;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i,n){
		int x;
		cin >> x;
		p.push_back(x);
	}
	int cnt = 0;
	for(int i = 1;i < n-1;++i){
		cnt += ((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1]));
	}
	cout << cnt << '\n';
	return 0;
}


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

typedef pair<long long, long long> data_t;

int main(){
  string s;
  cin>>s;
  int max=0;
  for(int i=0;i<s.size();i++){
    int tmp=0;
    if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){
      tmp=1;
      while(s[i+tmp]=='A'||s[i+tmp]=='T'||s[i+tmp]=='G'||s[i+tmp]=='C')
        tmp++;
    }
    if(tmp>max)
      max=tmp;
  }
  cout<<max<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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(){
    ll N; cin >> N;
    map <ll,ll> mp;
    rep(i,N){
        ll a; cin >> a;
        mp[a]++;
    }
    
    ll ans=0;
    for (auto i:mp){
        if (i.first>i.second) ans+=i.second;
        else ans+=i.second-i.first;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

bool solve(){
	int n; cin >> n;
	vi a(n); rep(i, n) cin >> a[i];
	sort(all(a));
	if((a.back() + 1) / 2 != a[0]) return 0;
	rep(i, n - 1) if(a[i + 1] > a[i] + 1) return 0;
	
	if(a.back() % 2){
		if(a[0] != a[1]) return 0;
		if(n > 2 && a[1] == a[2]) return 0;
	}
	else{
		if(a[0] == a[1]) return 0;
	}
	return 1;
}
int main(){
	cout << (solve() ? "Possible" : "Impossible") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
using namespace std;


int main()
{
    ll a;
    cin>>a;
    ll c=100;
    int k=0;
    while(c<a)
    {
        c=c*1.01;
        k++;
    }
    cout<<k;

    return 0;
}


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

using namespace std;

#define N 1001

int vis[N][N] = {0};
string s[N];
int n, m;
int dp[N][N] = {0};
const int mod = 1e9 + 7;

long long solve(int i, int j)
{
	if (i == n - 1 && j == m - 1)
		return 1;
	if (i >= n || j >= m)
		return 0;
	if (vis[i][j]) return dp[i][j];
	vis[i][j] = 1;
	if (s[i][j] == '#')
		return dp[i][j] = 0;
	return dp[i][j] = (solve(i + 1, j) + solve(i, j + 1)) % mod;
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> s[i];
	cout << solve(0, 0) << endl;
	return 0;
}


Measured memory_bytes: 9216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	private int W;
	private int H;
	private int x;
	private int y;
	private int r;

	public void Solve()
	{
		W = GetInt();
		H = GetInt();
		x = GetInt();
		y = GetInt();
		r = GetInt();

		bool f = ok(x, y) && ok(x + r, y) && ok(x - r, y) && ok(x, y + r) && ok(x, y - r);
		WriteLine(f ? "Yes" : "No");
	}

	private bool ok(int s, int t) => 
		(s >= 0) && (s <= W) && (t >= 0) && (t <= H);
}

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

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

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}


Measured memory_bytes: 19984
d,g = map(int, input().split())
pq = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")
# iを状態にする
for i in range(2**d):
    hoge = 0
    score = 0
    cnt = 0
    for j in range(d):
        if i & 1<<j:
            score += (j+1)*100*pq[j][0] + pq[j][1]
            cnt += pq[j][0]
        else:
            hoge = j
    tmp = max(0, -(-(g - score)//((hoge+1)*100)))
    #print(bin(i), cnt,score, tmp)
    if tmp <= pq[hoge][0]:
        ans = min(ans, cnt+tmp)
print(ans)

Measured memory_bytes: 3064
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    n, k, q = map(int, input().split())

    winners = []
    for w in range(q):
        winners.append(int(input()))

    score = [k - q] * n

    for w in winners:
        winner = w - 1

        score[winner] += 1

    for s in score:
        if s > 0:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 11132
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli a=0ll,b=0ll,n=0ll;
    cin>>a>>b>>n;
    if(n<b)
        cout<<(1ll*a*n)/b;
    else
    {
        cout<<max((1ll*a*(n-1ll))/b-(1ll*a*((n-1ll)/b)),(1ll*a*(b-1ll)/b));
    }
    cout<<endl;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
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

bool AC[100010];
int cnt[100010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int p; string S; cin >> p >> S;
        p--;
        if(S == "AC") AC[p] = true;
        if(!AC[p]) cnt[p]++;
    }
    int AC_count = 0;
    int WA_count = 0;
    rep(i, 100001) {
        if(AC[i]) {
            AC_count++;
            WA_count += cnt[i];
        }
    }
    cout << AC_count << " " << WA_count << endl;

    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<cmath>
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int x,y,flag=0,count=0;
  cin>>x>>y;
  int xmin=0,ymin=0,xmax=0,ymax=0;
  std::vector<int> f(100);
  f[1]=1;
  f[2]=2;
  for(int i=3;i<f.size();i++){
    f[i]=f[i-1]+f[i-2];
  }
  while(flag==0){
    if(x==0&&y==0) break;
    else{
      count++;
      if(count%4==1) xmax+=f[count];
      else if(count%4==2) ymax+=f[count];
      else if(count%4==3) xmin-=f[count];
      else ymin-=f[count];
      if((x>=xmin&&x<=xmax)&&(y>=ymin&&y<=ymax))
        flag=count;
    }
  }
  int color=(flag%3)+1;
  cout<<color<<endl;
  return 0;
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge{
  ll from,to,dis;
};
bool cmp(edge a,edge b){
  return a.dis<b.dis;
}
ll par[200010];
ll len[200010];
void init(ll n){
  for(ll i=0;i<n;i++){
    par[i]=i;
    len[i]=0;
  }
}
ll root(ll n){
  if(par[n]==n)return n;
  return par[n]=root(par[n]);
}
void unit(ll a,ll b){
  a=root(a);
  b=root(b);
  if(a==b)return;
  if(len[a]<len[b]){
    par[a]=b;
  }
  else{
    par[b]=a;
    if(len[a]==len[b])len[a]++;
  }
}
int main(){
  ll n,m,k;cin>>n>>m>>k;
  ll c[n];
  ll now=1;
  for(int i=0;i<n;i++){
    cin>>c[i];
    if(c[i]==0){
      c[i]=now+100000;
      now++;
    }
  }
  vector<edge> v;
  for(int i=0;i<m;i++){
    ll a,b,w;cin>>a>>b>>w;
    a--;b--;
    edge e={a,b,w};
    v.push_back(e);
  }
  sort(v.begin(),v.end(),cmp);
  init(200001);
  ll ans=0;
  ll cnt=0;
  for(int i=0;i<m;i++){
    edge e=v[i];
    ll f=e.from,t=e.to,d=e.dis;
    f=c[f],t=c[t];
    if(root(f)!=root(t)){
      unit(f,t);
      ans+=d;
      cnt++;
    }
    if(cnt==k-1){
      cout<<ans<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 7280
from heapq import *
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class Dice:
    def __init__(self,top,bot,lef,rig,fro,bac):
        self.top = top
        self.bot = bot
        self.lef = lef
        self.rig = rig
        self.fro = fro
        self.bac = bac

    def up(self):
        top, bac, bot, fro = self.fro, self.top, self.bac, self.bot
        return Dice(top,bot,self.lef,self.rig,fro,bac)

    def down(self):
        top, bac, bot, fro = self.bac, self.bot, self.fro, self.top
        return Dice(top,bot,self.lef,self.rig,fro,bac)

    def right(self):
        top, rig, bot, lef = self.lef, self.top, self.rig, self.bot
        return Dice(top,bot,lef,rig,self.fro,self.bac)

    def left(self):
        top, rig, bot, lef = self.rig, self.bot, self.lef, self.top
        return Dice(top,bot,lef,rig,self.fro,self.bac)

    def state(self):
        return (self.top, self.rig, self.bot, self.lef, self.fro, self.bac)

def main():
    n=int(input())
    if n==1:
        print(1)
        print(1)
        exit()
    if n==2:
        print(2)
        print(0)
        print(11)
        exit()
    print(n-1)
    for i in range(n-1):
        print("1"+"0"*i+"1")

main()



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

int main(int argc, char const *argv[])
{
	int n, x; cin >> n >> x;
	vector<int> l(n); rep(i, n) cin >> l[i];

	int d = 0;
	int ans = 1;
	rep(i, n) {
		d += l[i];
		if (d <= x) ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin >> N;
  vector<int> data(N);
  for(int i = 0; i < N; ++i){
    cin >> data.at(i);
  }
  
  sort(data.begin(), data.end());
  
  cout << data.at(N/2) - data.at(N/2 - 1) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

void solve()
{
	string s[] = { "", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts" };
	int n, m;
	while (cin >> n >> m, n || m)
	{
		int v[20] = { 0 };
		v[0] = 1;
		for (int i = 0; i < m; ++i)
		{
			for (int j = 19; j >= 0; --j)
			{
				v[j] *= n;
				v[j + 1] += v[j] / 10000;
				v[j] = v[j] % 10000;
			}
		}
		for (int i = 19; i >= 0; --i)
		{
			if (v[i] != 0)
			{
				cout << v[i] << s[i];
			}
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, m;
int p[N];

int find(int x)
{
	if (x != p[x]) p[x] = find(p[x]);
	return p[x];
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i <= n; i ++ ) p[i] = i;
	for (int i = 0; i < m; i ++ )
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		int pa = find(a), pb = find(b);
		p[pa] = pb;
	}
	
	set<int> S;
	for (int i = 1; i <= n; i ++ ) S.insert(find(i));
	printf("%d\n", S.size());
	return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new ABC127().SolveC(new ConsoleInput(Console.In, ' '));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
  class ABC127
    {
    	public void SolveC(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var m = cin.ReadInt;
            var L = new int[m];
            var R = new int[m];
            for (int i = 0; i < m; i++)
            {
                L[i] = cin.ReadInt;
                R[i] = cin.ReadInt;
            }
            int min = L.Max();
            int max = R.Min();
            if (max < min) WriteLine(0);
            else WriteLine(max - min + 1);
            ReadLine();
        }
    }
}


Measured memory_bytes: 15952
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map
#include<cmath>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 10000007

typedef  long long ll;

using namespace std;

ll gcd(ll a,ll b){
    if (b==0)return a;
    return gcd(b,a%b);
}

ll deg(int i){
  ll ret = 1;
  while(i != 0){
    if(i/10 == 0){
      break;
    }
    i/=10;
  }
  
  return i;
}

void solve(){
  int n;cin >> n;
  ll c[10][10];
  for(int i = 0;i <10;i++){
    for(int j =0;j < 10;j++){
      c[i][j] = 0;
    }
  }
  ll ans = 0;
  for(int i = 1;i <= n;i++){
    c[deg(i)][i%10]++;
  }
  for(int i = 0;i < 10;i++){
    for(int j = 0;j < 10;j++){
      ans += c[i][j]*c[j][i];
    }
  }
  cout << ans << endl;
}


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


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N;
  cin>>N;
  vector<ll> a(N+1), x(N+1, 0);
  vector<ll> ans;
  rep(i,1,N+1)
    cin>>a[i];
  for (int i=N; i>=1; i--) {
    ll s = 0;
    for (int j=2*i; j<=N; j+=i) {
      s += x[j];
    }
    s %= 2;
    if (s == a[i]) {
      x[i] = 0;
    } else {
      x[i] = 1;
      ans.push_back(i);
    }
  }

  cout<<ans.size()<<endl;
  rep(i,0,ans.size()){
    cout<<ans[i];
    if (i == ans.size() -1) {
      cout<<endl;
    } else {
      cout<<" ";
    }
  } 
}


Measured memory_bytes: 4980
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	static List<List<Integer>> list;
	static boolean[] visit;
	static int mx = 100001;
	static int mx2 = 200003;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		list = new ArrayList<>(mx2);
		for (int i = 0; i < mx2; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			int x = Integer.parseInt(sa[0]);
			int y = Integer.parseInt(sa[1]) + mx;
			list.get(x).add(y);
			list.get(y).add(x);
		}
		br.close();

		long ans = 0;
		visit = new boolean[mx2];
		for (int i = 1; i <= mx; i++) {
			if (!visit[i]) {
				int[] cnt = dfs(i, 0, new int[2]);
				ans += (long) cnt[0] * cnt[1];
			}
		}
		System.out.println(ans - n);
	}

	static int[] dfs(int cur, int p, int[] cnt) {
		visit[cur] = true;
		cnt[cur / mx]++;
		for (int next : list.get(cur)) {
			if (next != p && !visit[next]) {
				dfs(next, cur, cnt);
			}
		}
		return cnt;
	}
}


Measured memory_bytes: 68876
#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue> 
#include<cmath>
#include<utility>
#include<set>
#define M 1000000007
using namespace std;
int main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int h, n, a, b;
  cin >> h >> n;
  long long dp[h+10002];
  long long spell[10001];
  for(int i = 0; i < 10001; i++)
  {
    spell[i]=-1;
  }
  for(int i = 0; i < n; i++)
  {
    cin >> a >> b;
    if(b < spell[a] || spell[a]==-1)
      spell[a]=b;
  }
  for(int i = 1; i <= h+10000; i++)
  {
    dp[i]=-1;
    for(int j = 1; j <= i/2; j++)
    {
      if(dp[i-j]!=-1 && dp[j]!=-1 && (dp[i-j]+dp[j] < dp[i] || dp[i]==-1))
      {
        dp[i]=dp[j]+dp[i-j];
      }
    }
    for(int j = 1; j <= (int)(sqrt((double)(i))); j++)
    {
      if(i%j == 0)
      {
        if(dp[j]!=-1 && (dp[j]*(i/j) < dp[i] || dp[i]==-1))
          dp[i]=dp[j]*(i/j);
        if(dp[i/j]!=-1 && (dp[i/j]*(j) < dp[i] || dp[i]==-1))
          dp[i]=dp[i/j]*(j);
      }
    }
    if(i < 10001 && spell[i]!=-1 && (spell[i] < dp[i] || dp[i]==-1))
      dp[i]=spell[i];
  }
  long long mi=20000000000000;
  for(int i = h; i < h+10000; i++)
    if(dp[i]!=-1 && dp[i] < mi)
      mi=dp[i];
  cout << mi << '\n';
}

Measured memory_bytes: 512
# https://twitter.com/tempura_cpp/status/1259483252919635969

n, k = gets.to_s.split.map{|e|e.to_i}
a = [0] + gets.to_s.split.map{|e|e.to_i}

c = 1

while k > 0
  
  c = a[c] if k[0] == 1
  
  na = Array.new(n+1)
  
  (n+1).times{ |i| na[i] = a[a[i]] }
  
  a.clear
  a = na
  k >>= 1
end

puts c

Measured memory_bytes: 30604
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string S;
  cin >> S;

  ll ans = S.size()/2;

  if(S.size()%2==1){
    ll head = S.size()/2;
    ll tail = head;
    char tmp = S[head];
    while(tail>=0){
      if(S[head]==tmp && S[tail]==tmp){
        ans++;
        head++;
        tail--;
      }else{
        break;
      }
    }
  }else{
    ll head = S.size()/2;
    ll tail = head-1;
    char tmp1 = S[head];
    char tmp2 = S[tail];
    if(tmp1==tmp2){
      while(tail>=0){
        if(S[head]==S[tail] && S[head]==tmp1){
          ans++;
          head++;
          tail--;
        }else{
          break;
        }
      }
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int a[5], ans = 0;
	for (int i = 0; i < 5; i++){
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < 5; i++){
		ans += a[i];
		if (i == 4) break;
		if (ans % 10 != 0){
			ans += 10 - (ans % 10);
		}
	}
	while (next_permutation(a, a + 5)){
		int c = 0;
		for (int i = 0; i < 5; i++){
			c += a[i];
			if (i == 4) break;
			if (c % 10 != 0){
				c += 10 - (c % 10);
			}
		}
		ans = min(ans, c);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

#define FOR(idx, begin, end) for(int idx = (begin); idx < int(end); ++idx)
#define DBG(x) cerr << #x << ": " << x << "\n"

using namespace std;
typedef long long lint;
const int MOD = 1000000007;

int main() {

	cin.tie(0);

	int N, K;
	cin >> N >> K;

	vector<int> num(K);
	FOR(i, 0, K) cin >> num[i];

	while (true){

		FOR(j, 0, K) {
			FOR(k, 0, to_string(N).length()) {
				if (to_string(N)[k] - '0' == num[j]) {
					j = K - 1;
					k = to_string(N).length();
				}
				if (j == K - 1 and k == to_string(N).length() - 1) {
					cout << N;
					return 0;
				}
			}
		}

		N++;
	} 

	return -1;
}

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

int main(){
    string S, T;
    vector<int> bfr(26, -1), aft(26, -1);
    
    cin >> S >> T;

    for (int i = 0; i < S.size(); i++){
        int a = S[i] - 'a'; // a: 0, b: 25
        int b = T[i] - 'a';

        if (bfr[a] != -1 || aft[b] != -1){
            if(bfr[a] != b || aft[b] != a){
                cout << "No" << endl;
                return 0;
            }
        }
        bfr[a] = b;
        aft[b] = a;
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    char ans,k='a';
    queue<char>a,b,c;
    for(int i=0;i<(int)s1.size();i++)a.push(s1[i]);

    for(int i=0;i<(int)s2.size();i++)b.push(s2[i]);

    for(int i=0;i<(int)s3.size();i++)c.push(s3[i]);
    while(1)
    {
        if(k=='a')
        {
            if(a.size()==0)
            {
                ans='A';
                break;
            }
            else
                k=a.front();
                a.pop();

        }
           if(k=='b')
        {
            if(b.size()==0)
            {
                ans='B';
                break;
            }
            else
                k=b.front();
                b.pop();

        }
           if(k=='c')
        {
            if(c.size()==0)
            {
                ans='C';
                break;
            }
            else
                k=c.front();
                c.pop();

        }
    }
    cout<<(char)(ans)<<endl;
    return 0;
}



Measured memory_bytes: 256
def main():
    S = input()

    ans = 0
    tmp = 0
    for s in S:
        if s == 'R':
            tmp += 1
        else:
            if ans < tmp:
                ans = tmp
            tmp = 0

    if ans < tmp:
        ans = tmp

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9032
D,G = gets.split.map(&:to_i)
p = []
c = []
for i in 0..D-1
    p[i],c[i] = gets.split.map(&:to_i)
end

a = []
m = 0
answer = []
score = []

[0, 1].repeated_permutation(D) do |bits|
    a[m] = bits 
    m += 1
end

for i in 0..(2**D)-1

    answer[i] = 0
    score[i] = 0

    for j in 0..D-1

        if a[i][j] == 1

            answer[i] += p[j]
            score[i] += (p[j] * 100*(j+1)) + c[j]

        end

    end

    j = 0
    

    while score[i] < G && j <= D-1
        
        k = D-1-j

        if a[i][k] == 0

                if score[i]+(100*(k+1)*(p[k]-1)) >= G 

                    answer[i] += (0..p[k]-1).bsearch{|n| 100*(k+1)*n+score[i] >= G}
                    score[i] = G 

                else

                    answer[i] += p[k]-1
                    score[i] += 100*(k+1)*(p[k]-1)

                end

        end

        j += 1

    end

    if score[i] < G 

        answer[i] = p.inject(:+)

    end

end

puts answer.min

Measured memory_bytes: 1916
import java.util.*;

class Main {
  public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  Integer array[] = {a,b,a-1,b-1};
  Arrays.sort(array, Comparator.reverseOrder());
  int ans = array[0]+array[1];
  System.out.println(ans);
  }
}

Measured memory_bytes: 21844
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
Vl = LI()
Cl = LI()
ans = 0
for i in range(N):
    if Vl[i] - Cl[i] > 0:
        ans += Vl[i] - Cl[i]
print(ans)

Measured memory_bytes: 3888
//Author:Nirmit Shah
//201701044
//Daiict,Gandhinagar
 
#include<bits/stdc++.h>
using namespace std;
 
//Macros
#define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define error std::cerr
#define INF LONG_LONG_MAX
//#define MINF=LONG_LONG_MIN
#define MOD 1000000007
#define pii pair<int,int>
#define forn(i,j,n) for(ll i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define ull unsigned long long
 
//Debugging
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
 
#define all(c) c.begin(),c.end()
 
ll min(ll x,ll y)
{
    if(x>y)
        return y;
    return x;
}
 
ll max(ll x,ll y)
{
    if(x>y)
        return x;
    return y;
}
 
ll gcd(ll x,ll y)
{
    if(!x)
        return y;
    return gcd(y%x,x);
}
 
ll calcpower(ll x, ll y)
{
    ll ans = 1;
    x = x % MOD;
    while (y > 0)
    {
        if (y & 1)
            ans = (ans*x) % MOD;
 
            y = y>>1;
            x = (x*x) % MOD;
    }
    return ans;
}
 
/*bool prime[1000005];
void Sieve(ll n)
{
    for(int i=0; i<1000005; i++)
        prime[i] = true;
    prime[1] = false;
    prime[0] = false;
 
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p])
        {
            for (ll i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }
}*/

int main()
{
    Fast;
    int n,t,a;
    cin>>n>>t>>a;
    vector<float> h(n);
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=0;i<n;i++)
    {
        h[i]=t-h[i]*0.006;
        h[i]=abs(h[i]-a);
    }
    
    int j=-1;
    float min=99999;
    for(int i=0;i<n;i++)
    {
        if(h[i]<min)
        {
            min=h[i];
            j=i+1;
        }
    }
    cout<<j;
}

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

int main(){
  char s[2][3];
  int counter = 0;
  for(int i = 0; i < 2; i++){
    for(int j = 0; j < 3; j++){
      cin >> s[i][j];
    }
  }
  for(int i = 0; i < 3; i++){
    if(s[0][i] == s[1][2 - i]){
      counter++;
    }
  }
  if(counter == 3){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())

def Main(N):
    B = 100
    ans = [0]*(6*B*B+1)
    for i in range(1, B+1):
        for j in range(1, B+1):
            for k in range(1, B+1):
                a = i*i+j*j+k*k+i*j+j*k+k*i
                ans[a] += 1
    return ans

            
        
                    
out = Main(N)
for i in range(1, N+1):
    print(out[i])

Measured memory_bytes: 9456
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] s = sc.next().split("T");
		int x = Integer.parseInt(sc.next());
		int y = Integer.parseInt(sc.next());
		if (s.length == 0) {
			if (x == 0 && y == 0)
				System.out.println("Yes");
			else
				System.out.println("No");
			return;
		}
		int[] sx = new int[(s.length + 1) / 2 - 1];
		int[] sy = new int[s.length / 2];
		for (int i = 1; i < s.length; i++) {
			if (i % 2 == 0)
				sx[i / 2 - 1] = s[i].length();
			else
				sy[i / 2] = s[i].length();
		}
		boolean[][] dpx = new boolean[sx.length + 1][20000];
		boolean[][] dpy = new boolean[sy.length + 1][20000];
		int center = 10000;
		dpx[0][center + s[0].length()] = true;
		dpy[0][center] = true;
		for (int i = 1; i <= sx.length; i++) {
			int t = sx[i - 1];
			for (int j = 0; j < 20000; j++) {
				if (j - t >= 0 && dpx[i - 1][j - t] || j + t < 20000 && dpx[i - 1][j + t])
					dpx[i][j] = true;
			}
		}
		for (int i = 1; i <= sy.length; i++) {
			int t = sy[i - 1];
			for (int j = 0; j < 20000; j++) {
				if (j - t >= 0 && dpy[i - 1][j - t] || j + t < 20000 && dpy[i - 1][j + t])
					dpy[i][j] = true;
			}
		}
		if (dpx[sx.length][center + x] && dpy[sy.length][center + y])
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 164948
fun main(args: Array<String>) {
    val a = arrayOf(1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)
    val i = getInt()
    println(a[i - 1])
}

fun getInt() = readLine()!!.toInt()

Measured memory_bytes: 33712
N, M = map(int, input().split())

ac_chk = [0]*(N+1)
wa_chk = [0]*(N+1)
wa = 0
ac = 0

for i in range(M):
	p, S = input().split()
	p = int(p)
	if ac_chk[p] == 0:
		if S == "AC":
			ac_chk[p] = 1
			ac += 1
			wa += wa_chk[p]
			continue
		if S == "WA":
			wa_chk[p] += 1
			continue
	else:
		continue
print(ac, wa)

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int a, b;
  cin >> a >> b;
  if (a >= 13)
    cout << b << endl;
  else if (6 <= a && a <= 12)
    cout << b / 2 << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 256
// nomura2020_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N;
    cin >> N;
    vector<ll> A(N+1);
    REP(i, N+1) cin >> A[i];

    vector<ll> max_num(N+1);
    max_num[0] = 1;
    REPN(i, 1, N+1){
        max_num[i] = min((ll)1e17, 2 * max_num[i-1]) - A[i];
        if (max_num[i] < 0){
            print(-1);
            return 0;
        }
    }
    //    print(max_num);

    vector<ll> vec_num(N+1);
    vec_num[N] = A[N];
    REPN_REV(i, 1, N+1){

        ll n = max_num[i-1];

        if (vec_num[i] > 2 * n){
            print(-1);
            return 0;
        } else{
            vec_num[i-1] = min(n, vec_num[i]) + A[i-1];
        }
//        print(i, n, vec_num[i], vec_num[i-1]);
    }

//    print(vec_num);

    if (vec_num[0] > 1){
        print(-1);
        return 0;
    }
    ll ans = accumulate(ALL(vec_num), 0ll);
    print(ans);


    return 0;
}


Measured memory_bytes: 5580
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = 1000000007;
int INF = 1e8;
ll n;
vector<int> distToLast;
vector<bool> visit;

int dfs(P start, map<P, vector<P>>& m) {
	int id = n * start.first + start.second;
	if (distToLast[id] >= 0) return distToLast[id];

	if (visit[id] > 0) return INF;
	visit[id] = true;
	int dist = 0;
	for (auto e : m[start]) {
		dist = max(dist, dfs(e, m));
	}
	visit[id] = false;
	distToLast[id] = min(INF, dist+1);
	return distToLast[id];
}

int main(void)
{
	cin >> n;
	map<P, vector<P>> input;
	set<P> s;
	rep(i, n) {
		vector<P> ps(n - 1);
		rep(j, n - 1) {
			int t;
			cin >> t;
			t--;
			auto p = make_pair(min(t, i), max(t, i));
			ps[j] = p;
		}
		rep(j, n - 2) {
			input[ps[j]].push_back(ps[j + 1]);
		}
		s.insert(ps[0]);
	}
	int d = 0;
	visit.assign(n* n, false);
	distToLast.assign(n * n, -1);
	for (auto e : s) {
		d = max(d, dfs(e, input));
	}
	if (d == INF) {
		cout << -1 << endl;
		return 0;
	}
	cout << d << endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(),(a).end()

template<typename T1, typename T2> inline void chkmin(T1 & x, const T2 & y) {if (y < x) x = y;}
template<typename T1, typename T2> inline void chkmax(T1 & x, const T2 & y) {if (x < y) x = y;}

struct fq{
	int l, ind;
};

const int N = 5e5 + 10;
int n, q;
int a[N];
vector<fq> have[N];

void read() {
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		have[r].push_back({l, i});
	}
}

int tree[N];

void upd(int pos, int val) {
	for (; pos < N; pos |= pos + 1) {
		tree[pos] += val;
	}
}

int get(int r) {
	int ans = 0;
	for (; r >= 0; r = (r & (r + 1)) - 1) {
		ans += tree[r];
	}
	return ans;
}

int get(int l, int r) {
	return get(r) - get(l - 1);
}

int ans[N];
int last[N];

void run() {
	fill(last, last + N, -1);
	for (int i = 0; i < n; i++) {
		if (last[a[i]] != -1) {
			upd(last[a[i]], -1);
		}
		upd(i, 1);
		last[a[i]] = i;
		for (auto [l, ind] : have[i]) {
			ans[ind] = get(l, i);
		} 
	}
}

void write() {
	for (int i = 0; i < q; i++) {
		cout << ans[i] << "\n";
	}
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(20), cout.setf(ios::fixed);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 33220
num = list(map(int, input()))
fi = num[0]
if num[0] == num[1] and num[1] == num[2]:
    print('Yes')
elif num[1] == num[2] and num[2] == num[3]:
    print('Yes')
elif fi == num[1] and fi == num[2] and fi == num[3]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
# include <bits/stdc++.h>
  typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second
#define all v.begin(),v.end()
#define fio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef unsigned long long ulll;
 
using namespace std ;
int main () {

  int a,b,c;
  cin>>a>>b>>c;
  
  if(a==b)
  cout<<c;
  
  if(b==c)
  cout<<a;
  
  if(a==c)
    cout<<b;
   
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>
#include <assert.h>
#include <vector>
#include <cstring>
#include <random>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

int main() {

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

    int n;
    cin >> n;

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

    sort(all(a));

    int opt = -1;
    for (int i = 0; i < n - 1; ++i) {
        if (opt == -1) {
            opt = a[i];
        } else {
            if (a.back() % 2 == 0) {
                if (abs(a[i] - a.back() / 2) < abs(opt - a.back() / 2)) {
                    opt = a[i];
                }
            } else {
                int d = min(abs(a[i] - a.back() / 2), abs(a[i] - a.back() / 2 - 1));
                int x = min(abs(opt - a.back() / 2), abs(opt - a.back() / 2 - 1));
                if (d < x) {
                    opt = a[i];
                }
            }
        }
    }

    cout << a.back() << " " << opt << "\n";

}



Measured memory_bytes: 640