akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 typedef pair<int,int> ii;
 typedef vector<ii> vii;
 typedef vector <int > vi;
//vector <vi> adj(MAX); 
priority_queue<ll> v1,v2,v3,v4,v5,v6;
//multimap<ll,ll> m1,m2;
int knapSack(int W, int wt[], int val[], int n)
{
   int i, w;
   int K[n+1][W+1];
 
   // Build table K[][] in bottom up manner
   for (i = 0; i <= n; i++)
   {
       for (w = 0; w <= W; w++)
       {
           if (i==0 || w==0)
               K[i][w] = 0;
           else if (wt[i-1] <= w)
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
           else
                 K[i][w] = K[i-1][w];
       }
   }
 
   return K[n][W];
}
int main()
{
 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
 ios::sync_with_stdio(false);
 cin.tie(0);
 ll arr[100005]={0};
 ll n,k,ans,a,b,temp=0,m=0;
 cin>>n>>k;
 for(ll i=0;i<n;i++)
 {
  cin>>a>>b;
  m=max(m,max(a,b));
  arr[a]+=b;
 }
 //for(ll i=1;i<=m;i++)
 // cout<<arr[i]<<endl;
int f=0;
 for(ll i=1;i<100005;i++)
 {
  if(arr[i]==0)
    continue;
  temp+=arr[i];
  //cout<<temp<<endl;
  if(temp>=k)
  {
    f=1;
    ans=i;
    break;
  }

 }
 if(f==0)
  ans=m;
 cout<<ans<<endl;
return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var L = new long[87];
            L[0] = 2;
            L[1] = 1;
            for (int i = 2; i < L.Length; i++)
            {
                L[i] = L[i - 1] + L[i - 2];
            }

            Console.WriteLine(L[N]);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;


int main(){
    ll N, M;
    cin >> N >> M;
    vll t(M);
    ll sum = 0;
    for(int i=0; i<M; i++){
        cin >> t[i];
        sum += t[i];
    }
    if(sum > N){
        cout << -1;
    }
    else{
        cout << N - sum;
    }
}

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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if (a == b&& b == c) {
		cout << 1 <<endl;
	}
	else if (a == b || b == c || a == c)
	{
		cout << 2<<endl;
	}
	else
	{
		cout << 3<<endl;
	}
}

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

int main() {
  int K,A,B;
  cin >> K >> A >> B;
  
  int check = 0;
  for (int i=A-1;i<B;i++){
    if ((i+1) % K == 0){
      check++;
    }
  }
  
  if (check == 0){
    cout << "NG" << endl;
  } else {
    cout << "OK" << endl;
  }
}


Measured memory_bytes: 3596
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!long;
    auto AS = readln.split.to!(long[]);
    long sum_a;
    foreach (a; AS) sum_a += a;
    auto d = (N+1) * N / 2;
    if (sum_a % d != 0) {
        writeln("NO");
        return;
    }
    auto n = sum_a / d;

    d = 0;
    foreach (i; 0..N) {
        auto a = AS[(i+1)%N] - AS[i];
        if ((n-a)%N != 0 || n-a < 0 || n < (n-a)/N) {
            writeln("NO");
            return;
        }
        d += a;
    }
    
    writeln(d == 0 ? "YES" : "NO");
}


Measured memory_bytes: 4520
# a1 = 0としてよい

A = [0,None,None]
B = [None,None,None]

bl = True
for i in range(3):
  C = [int(x) for x in input().split()]
  for j,c in enumerate(C):
    if A[i] is None:
      A[i] = c - B[j]
    if B[j] is None:
      B[j] = c - A[i]
    if A[i]+B[j] != c:
      bl = False

answer = 'Yes' if bl else 'No'
print(answer)

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

using namespace std;

long long cnt;
vector<int> G;

void insertionSort(int A[], int n, int g) {
	for (int i = g; i < n; ++i) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n) {
	for (int i = 1;;) {
		if (i > n) break;
		G.push_back(i);
		i = 3 * i + 1;
	}
	for (int i = G.size() - 1; i >= 0; --i)
		insertionSort(A, n, G[i]);
}

int main() {
	int n; cin >> n;
	int A[1000000];
	for (int i = 0; i < n; ++i) cin >> A[i];
	cnt = 0;
	shellSort(A, n);
	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; --i) {
		cout << G[i];
		if (i) cout << " ";
	}
	cout << endl << cnt << endl;
	for (int i = 0; i < n; ++i) cout << A[i] << endl;

	return 0;
}


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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (i == N - 1) A.at(i) /= 2;
    ans += A.at(i);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 200005
using namespace std;
typedef long long ll;
typedef double db;
int n,ans[N],tmp;
struct node{int num,id;}a[N];
bool cmp(const node &T1,const node &T2){return T1.num<T2.num;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i].num),a[i].id=i;
	sort(a+1,a+n+1,cmp);
	tmp=n/2+1;
	for(int i=1;i<=n/2;++i) ans[a[i].id]=a[tmp].num;
	tmp--;
	for(int i=n/2+1;i<=n;++i) ans[a[i].id]=a[tmp].num;
	for(int i=1;i<=n;++i) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 4480
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

constexpr double EPS = 1e-7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
#define PI (acos(-1))

constexpr int MOD = 1e9 + 7;

vector<int> k;
vector<vector<int>> s;
vector<int> p;

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int N, M;
	cin >> N >> M;
	k.resize(M);
	s.resize(M);
	p.resize(M);

	for (int i = 0; i < M; i++) {
		int ki;
		cin >> ki;
		vector<int> si(ki);
		for (int j = 0; j < ki; j++) {
			cin >> si[j];
			si[j]--;
		}
		s[i] = si;
	}
	for (int i = 0; i < M; i++) {
		cin >> p[i];
	}

	ll ans = 0;
	for (int bit = 0; bit < (1 << N); bit++) {
		bool ok = true;
		for (int i = 0; i < M; i++) {
			int count = 0;
			for (auto &&sij : s[i]) {
				if (bit & (1 << sij)) {
					count++;
				}
			}
			if (count % 2 != p[i]) {
				ok = false;
				break;
			}
		}

		if (ok) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 888
import sys
sys.setrecursionlimit(10 ** 9)

n, m = map(int, input().split())
root = [-1] * n

def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]
    

def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x
    

def size(x):
    x = r(x)
    return -root[x]


for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    unite(x,y)

"""
max_size = 0
for i in range(n):
    max_size = max(size(i), max_size)
"""
max_size = max(map(size, range(n)))

print(max_size)

Measured memory_bytes: 35704
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <ctime>
#include <list>
using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
typedef pair<int,int> PI;
#ifndef M_PI
const double M_PI=acos(-1);
#endif
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int((a).size()))
#define F first
#define S second
int dx[]={0,1,0,-1,0,0},dy[]={1,0,-1,0,0,0};
int dz[]={0,0,0,0,1,-1};

int n;
double sx[30],sy[30],sz[30];

double dist(double x,double y,double z,int id){
  double tx=x-sx[id];
  double ty=y-sy[id];
  double tz=z-sz[id];
  return sqrt(tx*tx+ty*ty+tz*tz);
}

double rad(double x,double y,double z){
  double ret=dist(x,y,z,n-1);
  rep(i,n-1)ret=max(ret,dist(x,y,z,i));
  return ret;
}

typedef struct _node{
  double x,y,z,r;
  int wh;
  _node(double x,double y,double z,int wh):
    x(x),y(y),z(z),wh(wh),r(rad(x,y,z)){};

  bool operator<(const _node& rn)const{
    if(rn.wh!=wh)return rn.wh<wh;
    return rn.r<r;
  }
}node;

int tx[]={1,1,1,1,-1,-1,-1,-1};
int ty[]={1,1,-1,-1,1,1,-1,-1};
int tz[]={1,-1,1,-1,1,-1,1,-1};
double len[1000];

void solve(){
  rep(i,n)scanf("%lf%lf%lf",sx+i,sy+i,sz+i);
  len[0]=100;
  for(int i=1;i<1000;++i)
    len[i]=len[i-1]/2;
  double ans=10000;
  rep(i,n)rep(j,i)
    ans=min(ans,rad((sx[i]+sx[j])/2,
                    (sy[i]+sy[j])/2,
                    (sz[i]+sz[j])/2));

  priority_queue<node> q;
  q.push(node(50,50,50,0));
  int cu=0;
  int bwh=-1;
  while(!q.empty()){
    node cur=q.top();
    q.pop();
    if(cu==300 && cur.wh==bwh)continue;
    if(cu==300)cu=0,bwh=cur.wh;
    ++cu;
    double rr=len[cur.wh];    
    if(ans<cur.r-rr*sqrt(3)*2+EPS)continue;
    ans=min(ans,cur.r);
    if(cur.wh>25)continue;
    //printf("%.5f %.5f %.5f %.5f %.7f %d\n",cur.x,cur.y,cur.z,cur.r,ans,cur.wh);

    rep(i,8)
      q.push(node(cur.x+rr*tx[i],cur.y+rr*ty[i],cur.z+rr*tz[i],cur.wh+1));
  }

  printf("%.5f\n",ans);
}

main(){
  while(cin>>n,n)
    solve();
}

Measured memory_bytes: 0
Sa = input()
Sb = input()
Sc = input()

list_a = []
list_b = []
list_c = []


for i in str(Sa):
    list_a.append(i)
    
for i in str(Sb):
    list_b.append(i)

for i in str(Sc):
    list_c.append(i)


player = "a"


while player != "A" and player != "B" and player != "C":

    if player == "a":
        try:
            player = list_a[0]
            del list_a[0]
        except:
            player = "A"

    elif player == "b":
        try:
            player = list_b[0]
            del list_b[0]
        except:
            player = "B"

    elif player == "c":
        try:
            player = list_c[0]
            del list_c[0]
        except:
            player = "C"

print(player)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std ;
const int N=110;
int dp[N][N];
int main()
{
    int n;
    cin>>n;
    for (int i=0;i<=9;i++) dp[1][i]=1;
    for (int i=2;i<=10;i++)
        for (int j=0;j<=9;j++)
            dp[i][j]=dp[i-1][j]+dp[i-1][j-1]+dp[i-1][j+1];
    queue<int> ans;
    int l=0,r=0,flag=0;
    for (int i=1;i<=10;i++) 
	{
        for (int j=1;j<=9;j++) 
		{
            if(n<=dp[i][j])
			{
                l=i;
                r=j;
                flag=1;
                break;
            }
            n-=dp[i][j];
        }
        if(flag==1)break;
    }
    l--;
    ans.push(r);
    while(l!=0)
	{
        if(n<=dp[l][r-1])
		{
            r--;
            ans.push(r);
        }
		else
		{
            n-=dp[l][r-1];
            if(n<=dp[l][r]) ans.push(r);
			else
			{
                n-=dp[l][r];
                r++;
                ans.push(r);
            }
        }
        l--;
    }
    while(!ans.empty())
	{
        int res=ans.front();
        cout<<res;
        ans.pop();
    }
    return 0 ;
}

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

using namespace std;

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> d(N);
    int res = 0;

    for (int i = 0; i < N;i++){
        cin >> d[i];
        res += d[i];
    }
    sort(d.begin(), d.end());

    int cnt = N-1;
    for (; X >= res;){
        res += d[0];
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007

using namespace std;

int d,g;
int p[11],c[11],all[11];
bool flag[11];
int ans=MAX;


int main(void){
	int n;
	cin>>n;
	ll ans=0;
	rep(i,n){
		ll tmp;
		cin>>tmp;
		ans+=tmp-1;
	}
	cout<<ans<<endl;
	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll sumD(ll n)
{
    ll ans=0;
    while(n!=0)
    {
        ans+=n%10;
        n/=10;
    }
    return ans;
}

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


    ll ans=0;
    for(i=1;i<=n;i++)
    {
        if(sumD(i)>=a && sumD(i)<=b)
        {
            ans+=i;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, c;
    cin >> a >> b >> c;
    for(int i = b; i < c + 1; i++) {
        if(i % a == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>

#define ll long long
#define ull unsigned long long
#define mod 1000000007

using namespace std;

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

    char s[3];
    char t[3];
    for(int i = 0; i < 3; ++i){
        cin >> s[i];
    }

    int count = 0;
    for(int i = 0; i < 3; ++i){
        cin >> t[i];
        if(s[i] == t[i]) ++count;
    }

    cout << count << endl;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {


    static double s(double a, double b, double c, double d) {
        return Math.abs(a * d - b * c) / 2;
    }

    static double[] p(String s) {
        String[] r = s.split(",");
        return new double[]{
                Double.parseDouble(r[0]),
                Double.parseDouble(r[1])
        };
    }

    public static void main(String... args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        double[] o = p(br.readLine());
        double[] a = p(br.readLine());
        double sum = 0.0;
        String line;
        while ((line = br.readLine()) != null) {
            double[] b = p(line);
            sum += s(a[0] - o[0], a[1] - o[1], b[0] - o[0], b[1] - o[1]);
            a[0] = b[0];
            a[1] = b[1];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 16896
from functools import lru_cache


@lru_cache(maxsize=None)
def lucas(n: int) -> int:
    if n == 0:
        return 2
    elif n == 1:
        return 1
    else:
        return lucas(n - 1) + lucas(n - 2)


N = int(input())
print(lucas(N))


Measured memory_bytes: 3700
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

char s[2003][2003];
char l[2003][2003];
int pr[2003][2003];
int pl[2003][2003];
int pu[2003][2003];
int pd[2003][2003];
int c[2003][2003];
int p[2003];

int main()
{
    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++){
        cin >> s[i][j];
        l[i][j] = '.';
    }
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) if(s[i][j] == '1' && l[i][j] == '.'){
        queue<P> que;
        l[i][j] = 'c';
        que.push(P(i, j));
        while(que.size()){
            int x = que.front().first, y = que.front().second;
            que.pop();
            for(int k = 0; k < 4; k++){
                int xx = x + dx[k], yy = y + dy[k];
                if(xx >= 0 && xx < n && yy >= 0 && yy < m && s[xx][yy] == '1' && l[xx][yy] == '.'){
                    if(k == 0) l[xx][yy] = 'u';
                    if(k == 1) l[xx][yy] = 'l';
                    if(k == 2) l[xx][yy] = 'd';
                    if(k == 3) l[xx][yy] = 'r';
                    que.push(P(xx, yy));
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(l[i][j] == 'u') pu[i][j]++;
            if(l[i][j] == 'd') pd[i][j]++;
            pu[i][j + 1] = pu[i][j];
            pd[i][j + 1] = pd[i][j];
        }
    }
    for(int j = 0; j < m; j++){
        for(int i = 0; i < n; i++){
            if(l[i][j] == 'r') pr[j][i]++;
            if(l[i][j] == 'l') pl[j][i]++;
            pr[j][i + 1] = pr[j][i];
            pl[j][i + 1] = pl[j][i];
        }
    }
    for(int i = n - 1; i >= 0; i--){
        int k = 0;
        for(int j = m - 1; j >= 0; j--){
            if(l[i][j] == 'c') p[j]++;
            k += p[j];
            c[i][j] = k;
        }
    }
    for(int e = 0; e < q; e++){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        x1--; y1--; x2--; y2--;
        int ans = c[x1][y1] - c[x2 + 1][y1] - c[x1][y2 + 1] + c[x2 + 1][y2 + 1];
        ans += pu[x1][y2] + pd[x2][y2] + pl[y1][x2] + pr[y2][x2];
        if(y1 > 0) ans -= pu[x1][y1 - 1] + pd[x2][y1 - 1];
        if(x1 > 0) ans -= pl[y1][x1 - 1] + pr[y2][x1 - 1];
        cout << ans << endl;
    }
}

Measured memory_bytes: 88064
n = int(input())
memo = [-1]*(n+1)

def func(i):
    if i == 0:
        return 2
    if i == 1:
        return 1
    
    if memo[i] != -1:
        return memo[i]
    
    memo[i] = func(i-2) + func(i-1)
    return memo[i]

print(func(n))

Measured memory_bytes: 3060
#define Z(V) for(v=360,m=g();--m;V+=sin(x*z))v-=x=g();V+=sin(v*z)
a;g(){scanf("%d",&a);a?a:exit(0);}main(m,v,x){for(;;){double s=0,t=0,z=.02,e=.000001;Z(s);Z(t);puts(s>t+e?"1":s+e<t?"2":"0");}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
ll A, B, n;
ll cal(ll x) {
	return (A * x) / B - A * (x / B);
}
int main(){
	cin >> A >> B >> n;
	/*for (int i = 0; i <= 100; i++) {
		cout << i << ':' << cal(i) << endl;
	}*/
	if (n >= B - 1)cout << cal(B - 1) << endl;
	else {
		cout << cal(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
N = int(input())
txx = [[0,0,0]] * (N+1)
for i in range(N):
    txx[i] = input().split()
    for j in range(3):
        txx[i][j] = int(txx[i][j])
      
loc = [0,0,0]
output = 'Yes'
for i in range(N):
    dt = txx[i][0] - loc[0]
    dx = txx[i][1] - loc[1]
    dy = txx[i][2] - loc[2]
    if (not(dx + dy <= dt)) or (not((dx + dy - dt) % 2 == 0)):
        output = 'No'
    loc = [txx[i][0],txx[i][1],txx[i][2]]
    
print(output)

Measured memory_bytes: 27352
#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 dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using P=pair<int,int>;

signed _main(){
  int H,W,K; cin >> H >> W >> K;
  vv<char> field(H,v<char>(W));
  vv<int> ans(H,v<int>(W,0));
  int label=1;
  rep(i,H)rep(j,W){
    cin >> field[i][j];
    if(field[i][j]=='#') ans[i][j]=label++;
  }
  rep(i,H)rep(j,W-1){
    if(ans[i][j]!=0){
      if(ans[i][j+1]==0) ans[i][j+1]=ans[i][j];
    }
  }
  rep(i,H)for(int j=W-1;j>=1;j--){
    if(ans[i][j]!=0){
      if(ans[i][j-1]==0) ans[i][j-1]=ans[i][j];
    }
  }
  rep(j,W)rep(i,H-1){
    if(ans[i][j]!=0){
      if(ans[i+1][j]==0) ans[i+1][j]=ans[i][j];
    }
  }
  rep(j,W)for(int i=H-1;i>=1;i--){
    if(ans[i][j]!=0){
      if(ans[i-1][j]==0) ans[i-1][j]=ans[i][j];
    }
  }
  rep(i,H){
    rep(j,W-1){
      cout << ans[i][j] << " ";
    }
    cout << ans[i][W-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
int main()
{
	SPEED
	
	ll n;
	cin >> n;

	vector<ll> arr(n);

	for (ll i = 0; i < n; ++i)
	{
		cin >> arr[i];
	}

	sort(arr.begin(), arr.end(), greater<ll>());

	ll ans = arr[0];

	for (ll i = 1; i < n/2; ++i)
	{
		ans += (2*arr[i]);
	}

	if (n&1)
	{
		ans += arr[n/2];
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 4760
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define INF (1<<30)-1
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vi v(n); rep(i,n) cin >> v[i];
  map<int,int> odd,even;
  rep(i,n){
    if(i % 2 == 0) even[v[i]]++;
    else odd[v[i]]++;
  }
  int mx_odd1 = 0, mx_even1 = 0, num_odd1, num_even1;
  for(auto x : odd) if(chmax(mx_odd1,x.second)) num_odd1 = x.first;
  for(auto x : even) if(x.first != num_odd1 && chmax(mx_even1,x.second)) num_even1 = x.first;

  int mx_odd2 = 0, mx_even2 = 0, num_odd2, num_even2;
  for(auto x : even) if(chmax(mx_even2,x.second)) num_even2 = x.first;
  for(auto x : odd) if(x.first != num_even2 && chmax(mx_odd2,x.second)) num_odd2 = x.first;

  int res = max(mx_odd1+mx_even1,mx_odd2+mx_even2);
  cout << n - res;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 8328
cards= {}
n = int(input())
for i in range(0,n):
    mark, num = input().split()
    cards[mark+num] = 1

for m in ['S', 'H', 'C', 'D']:
    for n in range(1,14):
        card = m+str(n)
        if card in cards:
            pass
        else:
            print('{} {}'.format(m, n))



Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,l;
    cin>>n>>l;
    //vector<int> a;
    int mn1 = INT_MAX;
    int mn = INT_MAX;
    int sum=0;
    for(int i=1;i<=n;i++){
        //a.push_back(l+i-1);
        if(mn1>(abs(l+i-1))){
            mn = l+i-1;
            mn1 = abs(l+i-1);
        }
        sum+=(l+i-1);
    }
    cout<<sum-mn<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
	int A,B;
	scanf("%d %d",&A,&B);
	getchar();
	
	char S[A+B+2] = {0};
	scanf("%s",&S);
	int len = strlen(S);
	int flag = 0;
	
	for (int i = 0; i < len; i++)
	{
		if (48 <= S[i] && S[i] <= 57)
		{
			continue;
		}
		else if (48 > S[i] || S[i] > 57)
		{
			if ( i == A )
			{
				flag = 1;
				continue;
			}
			else if (i != A)
			{
				flag = 0;
				break;
			}
		}
	}
	
	flag ? printf("Yes\n") : printf("No\n");
	
	return 0;
}

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

int main(void)
{
  long long int x,ans=0,n=100;
  scanf("%lld",&x);
  while(n<x)
    {
      n = n + n/100;
      ans++;
    }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    bool flag = false;
    for(int i = 1; i <= 3; i++){
        if(a*b*i % 2 == 1) {
            flag = true;
            break;
        }
    }
    cout << (flag?"Yes":"No");
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int pow(int x) {
    int res = 1;
    for(int i = 1; i <= x; i++) res *= 2;
    return res;
}
void slove() {
    int n, m;
    cin >> n >> m;
    cout << (1900*m + 100 * (n-m)) * pow(m);
}
int main () {
    slove();
    system("pause");
    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int n, m, q;
vi a, b, c, d;
int ans;

void dfs(vi A) {
	if (A.size() == n + 1) {
		int now = 0;
		rep(i, q) {
			if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
		}
		ans = max(ans, now);
		return;
	}

	A.push_back(A.back());
	while (A.back() <= m) {
		dfs(A);
		A.back()++;
	}
}
int main() {
	cin >> n >> m >> q;

	a = b = c = d = vi(q);
	rep(i, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}

	dfs(vi(1, 1));

	cout << ans << endl;
}


Measured memory_bytes: 3564
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import deque

# f(AX) = XB
# f(BX) = flip(X) + A = flip(XB)

N,K = map(int,readline().split())
S = read().rstrip()
S = deque(0 if x == b'A'[0] else 1 for x in S)

# Kが大きいときは、周期で減らせる
U = 10**6
if K > U:
    K = U + (K&1)

flip = 0
for _ in range(K):
    top = S[0]^flip
    if top == 0:
        # A
        S[0] ^= 1
    else:
        # B 
        flip ^= 1
        S.popleft()
        S.append(flip)

if flip == 0:
    A = 'A'; B = 'B'
else:
    A = 'B'; B = 'A'
answer = ''.join(A if x == 0 else B for x in S)
print(answer)

Measured memory_bytes: 6820
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=100010;
int n,q,v;
char buf[4];
vector<int> g[N];
int p[N],dsu[N];
bool marked[N];

int fi(int x) {
    return dsu[x]==x?x:(dsu[x]=fi(dsu[x]));
}

void dfs(int x,int ma) {
    if (marked[x]) {
        for (int i=0;i<g[x].size();i++) {
            dfs(g[x][i],x);
        }
    } else {
        dsu[x]=ma;
        for (int i=0;i<g[x].size();i++) {
            dfs(g[x][i],ma);
        }
    }
}

int main()
{
    while (true) {
        scanf("%d%d",&n,&q);
        if (n==0&&q==0) break;
        memset(p,0,sizeof(p));
        memset(marked,0,sizeof(marked));
        for (int i=1;i<=n;i++) {
            dsu[i]=i;
            g[i].clear();
        }
        for (int i=2;i<=n;i++) {
            scanf("%d",&v);
            p[i]=v;
            g[v].pb(i);
        }
        vector<PII> op;
        marked[1]=1;
        for (int i=1;i<=q;i++) {
            scanf("%s%d",buf,&v);
            if (buf[0]=='M') {
                if (!marked[v]) {
                    marked[v]=1;
                    op.pb(mp(0,v));
                }
            } else {
                op.pb(mp(1,v));
            }
        }
        dfs(1,1);
        ll ans=0;
        for (int i=op.size()-1;i>=0;i--) {
            if (op[i].first) {
                ans+=fi(op[i].second);
            } else {
                int r=fi(p[op[i].second]);
                dsu[op[i].second]=r;
            }
        }
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 15720
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

#include <iostream>
#include <string>

using namespace std;

class AGarden {
public:
    void solve(std::istream& in, std::ostream& out) {
        int A, B;
        in >> A >> B;

        out << (A - 1) * (B - 1) << endl;
    }
};


int main() {
	AGarden solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  if(A <= 5) {
    cout << 0 << endl;
  }
  else if (A>=13) {
    cout << B << endl;
  }
  else {
    cout << B / 2 << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() 
{
	int n, t;
	int i, sub_c, sub_t, min_c = 1001;
	scanf("%d%d", &n, &t);

	for (i = 0; i < n; i++) {
		scanf("%d%d", &sub_c, &sub_t);
		if (sub_t > t)
			continue;
		if (sub_c < min_c) {
			min_c = sub_c;
		}
	}

	if (min_c == 1001) {
		printf("TLE\n");
	}
	else {
		printf("%d\n", min_c);
	}
	return 0;
}

Measured memory_bytes: 128
# coding: utf-8
# Your code here!
s=list(input().replace("BC","Z"))[::-1]
ans=0

def seisan(list):
    count=0
    N=len(list)-1
    for index,content in enumerate(list):
        if content=="A":
            count+=(N-index)
            N-=1
    return count

temp=[]
while s:
    this=s.pop(-1)
    if this=="B" or this=="C":
        ans+=seisan(temp)
        temp.clear()
    else:
        temp.append(this)

print(ans+seisan(temp))
#ちょくだいさん連投ゆるして

Measured memory_bytes: 6308
def func():
    pass


def main():
    o = input()
    e = input()

    ans = ""
    for i in range(len(e)):
        ans += o[i] + e[i]

    if len(o) > len(e):
        ans += o[-1]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, A, B;
  cin >> N >> A >> B;
  vll X(N);
  for(int i = 0; i < N; i++){
    cin >> X.at(i);
  }
  ll ans = 0LL;
  for(int i = 1; i < N; i++){
    ll cost = (X.at(i) - X.at(i-1)) * A;
    ans += min(cost, B);
  }
  cout << ans << endl;
}

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

template<typename type>
struct union_find{
	vector<type>par;
	explicit union_find(size_t n)
		:par(n,-1){}
	type find(type val){
		if(par.at(val)<0)return val;
		return par.at(val)=find(par.at(val));
	}
	bool same(type a,type b){
		return find(a)==find(b);
	}
	void unite(type a,type b){
		a=find(a),b=find(b);
		if(a==b)return;
		if(par.at(a)>par.at(b))swap(a,b);
		par.at(a)+=par.at(b);
		par.at(b)=a;
	}
	int size(size_t i){return -par.at(find(i));}
};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	union_find<int>uf(n);
	for(int i=0;i<m;++i){
		int a,b; cin>>a>>b; --a,--b;
		uf.unite(a,b);
	}
	int ans=0;
	for(int i=0;i<n;++i)ans=max(ans,uf.size(i));
	cout<<ans<<"\n"s;
}


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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> inline void print(T val) { cout << val << '\n'; }

template <typename Iterator> inline void print(Iterator begin, Iterator end) {
  for (auto it = begin; it != end; it = next(it)) {
    cout << *it << ' ';
  }
  cout << '\n';
}

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

  vector<int> a(n);
  int total = 0;

  for (auto &i : a) {
    cin >> i;
    total ^= i;
  }

  for (auto i = 0; i < n; ++i) {
    print(a[i] ^ total);
  }
}

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

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  solve();

  return 0;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    READ(1);
    ll n,m,v,p;cin>>n>>m>>v>>p;
    vector<ll> a(n);
    vi cnt(n);
    FOR(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    cnt[n-1]=1;
    for(int i=n-2;i>=0;--i){
        if (a[i]==a[i+1]){
            cnt[i] = cnt[i+1]+1;
        }else cnt[i]=1;
    }
    int lo=0;
    int hi=n-p-1;
    while(hi>0 && a[hi]==a[hi+1])--hi;
    while(lo+1<hi){
        int mid=lo+(hi-lo)/2;
        if (a[mid]+m<a[n-p]){
            lo=mid;
            continue;
        }
        ll rest=(ll)m*(v-mid-cnt[mid]-p+1);
        int j=mid+cnt[mid];
        while(j<n-p+1 && rest>0){
            ll x=(ll)a[mid]+m-a[j];
            if (x<=0) break;
            rest -= (ll)x*((p==1 || a[j]<a[n-p+1])?cnt[j]:n-p+1-j);
            j += cnt[j];
        }
        if (rest<=0){
            hi=mid-1;
        } else
            lo=mid;
    }
    if (lo<hi) {
        int mid = hi;
        if (a[mid]+m<a[n-p]){
            lo=mid;
        }else {
            ll rest = (ll)m*(v - mid - cnt[mid] - p + 1);
            int j = mid + cnt[mid];
            while (j < n - p + 1 && rest > 0) {
                ll x =  a[mid] + m - a[j];
                if (x <= 0) break;
                rest -= (ll)x*((p==1 || a[j]<a[n-p+1])?cnt[j]:n-p+1-j);
                j += cnt[j];
            }
            if (rest > 0)
                lo = hi;
        }
    }
    if (lo==0){
        int mid = 0;
        if (a[mid]+m<a[n-p]){
            lo=mid;
        }else {
            ll rest = (ll)m*(v - mid - cnt[mid] - p + 1);
            int j = mid + cnt[mid];
            while (j < n - p + 1 && rest > 0) {
                ll x = (ll) a[mid] + m - a[j];
                if (x <= 0) break;
                rest -= (ll)x*((p==1 || a[j]<a[n-p+1])?cnt[j]:n-p+1-j);
                j += cnt[j];
            }
            if (rest <= 0)
                lo = -1;
        }
    }
    cout << n-lo-1;
    return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;


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

   char check;
   bool flag = true;
   for (int i = 0; i < s.size(); i++){
      check = s[i];
      for (int j = 1; j < s.size(); j++){
         if (i != j){
            if (check == s[j]){
               flag = false;
               cout << "no" << endl;
               return 0;
            }
         }
      }
   }
   cout << "yes" << endl;
   return 0;
} 


Measured memory_bytes: 256
#include <stdio.h>

#define ARRAY_MAX 101
#define ZERO 0
#define ONE 1

void view();

	unsigned short ubW_Darray[ ARRAY_MAX ];							/*?????????????±???°???*/
	unsigned char ubW_Dcount;										/*????´???°*/

int main( void )
{

	unsigned char ubW_Ci;											/*????????????i*/
	unsigned char ubW_Cj;											/*????????????j*/
	unsigned short ubW_Dtrade;										/*???????????¨?????°*/
	
	scanf("%d", &ubW_Dcount);											/*????´???°????????????*/
	/*??°?????????????????¨?????????*/
	for( ubW_Ci = ZERO; ubW_Ci < ubW_Dcount; ubW_Ci++){
		scanf("%d", &ubW_Darray[ ubW_Ci ]);							/*??°???????????????*/
	}

	/*?????\???????????¨?????????*/
	for( ubW_Ci = ONE; ubW_Ci < ubW_Dcount; ubW_Ci++){
		view();
		ubW_Dtrade = ubW_Darray[ ubW_Ci ];							/*???????????¨?????°????????????????±????????????????*/
		ubW_Cj = ubW_Ci;											/*?????\??????????????????*/
		/*????????????j???0??\?????????????????????????±???????[ j ]??????????????¨?????°????????§????????´????????????*/
		while( ( ubW_Cj > ZERO ) && ( ubW_Darray[ ubW_Cj - ONE ] > ubW_Dtrade ) ){
			ubW_Darray[ ubW_Cj ] = ubW_Darray[ ubW_Cj - ONE ];			/*?????????????±???????[ j ]????????????????±???????[ j - ONE ]????????????*/
			ubW_Cj--;												/*????????????j?????????????????????*/
		}
		ubW_Darray[ ubW_Cj ] = ubW_Dtrade;						/*?????????????±???????[ j ]??????????????¨?????°????????????*/
	}

	view();
	return ZERO;
}

void view()
{
	
	unsigned char ubW_Cviewi;											/*????????????i*/
	unsigned char ubW_Cviewj;											/*????????????j*/

	/*??°?????¨?????¨?????????*/
	for( ubW_Cviewi = ZERO; ubW_Cviewi < ubW_Dcount; ubW_Cviewi++){
		/*??°???????????????????´??????´???*/
		if( ubW_Cviewi == ubW_Dcount - ONE ){
			printf("%d\n", ubW_Darray[ ubW_Cviewi ]);
		}else
		{
			printf("%d ", ubW_Darray[ ubW_Cviewi ]);							/*??°?????¨???*/
		}
	}
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 n;
  int64 l = 0, r = 0;
  cin >> n;
  REP(i, n) {
    int64 a, b;
    char c;
    cin >> a >> c >> b;
    if (c == '(') l+=b;
    else r += b;
    if (l == r) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
bool vis[MAXN];
vector < vector < int > > adj;
int dp[MAXN];
void dfs(int u){
    if(vis[u]) return;
    if(adj[u].size() == 0) dp[u] = 1;
    vis[u] = true;
    for(auto v : adj[u]){
        if(!vis[v]){
            dfs(v);
        }
    }
    int k = -1;
    for(auto v : adj[u]){
        dp[u] = max(dp[u], dp[v] + 1);
    }
}
int main(){
    int n, m;
    cin >> n >> m;
    adj.resize(n, {});
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        adj[--a].push_back(--b);
    }
    for(int i = 0; i < n; i++){
        if(!vis[i]){
            dfs(i);
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(ans, dp[i]);
    }
    cout << ans - 1 << '\n';
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define sc(x)            scanf("%d",&x)
#define scc(x)           scanf("%c",&x)
#define scl(x)           scanf("%lld",&x)
#define sz(v)	     	(v.size())
#define mem(v, d)		memset(v, d, sizeof(v))
#define oo				2000000100
#define OO				4000000000000000100
#define PI 3.14159265
#define S second
#define F first
typedef unsigned int uint;
typedef long long ll;
//-----------------------------------------------------
const int N = 100100;
const ll MOD = 1000000007;
const double EBS = 1e-7;

int dX[] = {0,0,1,-1};
int dY[] = {1,-1,0,0};

//int GCD(ll num,ll ones) { return !ones ? num : GCD(ones,num%ones); }
//ll lcm(ll a, ll b) { return (a / GCD(a, b)) * b; }
//double Len(ll x,ll y,ll X,ll Y) { return sqrt((X-x)*(X-x)+(Y-y)*(Y-y)); }
/*ll fastP(ll b,ll p)
{
    if(p==0) return 1;
    else if(p==1) return b;
    ll a = fastP(b,p/2);
    if(p%2) return (((a*a))*b);
    else return (a*a);
}*/
//----------------- ------   -------
int freq[2][N],mx[2],x,n;
int main()
{
#ifndef ONLINE_JUDGE
    //freopen("i.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    sc(n);
    vector< pair<int,int> >Even,Odd;
    for(int i=0;i<n;++i){
        sc(x);
        ++freq[i&1][x];
    }
    for(int i = 1;i<N;++i){
        if(freq[0][i]) Even.push_back({freq[0][i],i});
        if(freq[1][i]) Odd.push_back({freq[1][i],i});
    }
    Even.push_back({0,-1});
    Odd.push_back({0,-2});
    sort(Even.rbegin(),Even.rend());
    sort(Odd.rbegin(),Odd.rend());
    n>>=1;
    if(Even[0].second != Odd[0].second){
        cout << n - Even[0].first + n - Odd[0].first << endl;
    }
    else{
        cout << min(n - Even[1].first + n - Odd[0].first,n - Even[0].first + n - Odd[1].first) << endl;

    }




    return 0;
}


Measured memory_bytes: 2044
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		 Scanner scan = new Scanner(System.in);
		 int S = scan.nextInt();
		 int h = S / 3600;
		 int m = (S % 3600) / 60;
		 int s = S % 60;
		 System.out.println(""+h+":"+m+":"+s);
	}
}

Measured memory_bytes: 26372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
VI che={1,3,1,2,1,2,1,1,2,1,2,1};
int a,b;
cin>>a>>b;
if (che.at(a-1)==che.at(b-1))
{
    cout<<"Yes"<<endl;  
}
else
{
    cout<<"No"<<endl;
}

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int H,W;
  cin>>H>>W;
  int K=H*W;
  int ans=1;
  if(H==1||W==1){
    cout<<ans<<endl;
    return 0;
  }
  if(K%2==0)ans=K/2;
  if(K%2!=0)ans=(K/2)+1;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
from fractions import gcd
a, b, c, d = map(int, input().split())

ans = b-a+1
ans -= b//c-(a-1)//c+1
ans -= b//d-(a-1)//d+1
ans += b//(c*d//gcd(c, d))-(a-1)//(c*d//gcd(c, d))+1


print(ans+1)

Measured memory_bytes: 5304
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  LL a, b, c, k;
  cin >> a >> b >> c >> k;
  LL ans = 0;

  if(a >= k) {
    ans = k;
  }
  else if(a + b >= k) {
    ans = a;
  }
  else {
    ans = a - (k - a - b);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }

    class Program
    {
        private string N;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.Next();
        }

        public void Solve()
        {
            Scan();
            var dp = new int[N.Length + 1];
            var dp2 = new int[N.Length + 1];
            dp2[0] = 0;
            var NN = long.Parse(N);
            for (int i = 1; i <= N.Length; i++)
            {
                dp2[i] = dp2[i - 1] + (int)(NN % 10);
                if (NN % 10 != 0)
                {
                    dp2[i] = Math.Max(dp2[i], 9 * (i - 1) + (int)(NN % 10 - 1));
                }
                NN /= 10;
            }
            Console.WriteLine(dp2[N.Length]);
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 11092
#include<cstdio>
#include<algorithm>
using namespace std;
char s[20];

int main()
{
	int ans=0,n=0,sum=0;
	scanf("%s",s);
	for(int i=0;s[i];i++,n++)
		sum+=s[i]-'0';
	ans=s[0]-'0'-1;
	for(int i=1;s[i];i++)
		ans+=9;
	printf("%d\n",max(ans,sum));
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<queue>

using namespace std;

#define INF 1000000007

int main(){
  int n;
  cin >> n;
  vector<pair<int, int> > a;
  for(int i = 0; i < n; i++){
    int t; cin >> t;
    a.push_back({t, i});
  }
  sort(a.begin(), a.end());
  for(int i = 0; i < n; i++){
    cout << a[i].second + 1 << " ";
  }
  cout << endl;
}


Measured memory_bytes: 1780