akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;


map<string,int> card;
int main(){
        int ans = 0;
        int N; cin >> N;
        string s[100],t[100];
        rep(i,N){
                cin >> s[i];
                card[s[i]]++;
        }
        int M; cin >> M;
        rep(i,M){
                cin >> t[i];
                card[t[i]]--;
        }
        rep(i,N){
                ans = max(ans,card[s[i]]);
        }
        cout << ans <<endl;
        return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        int res = 0;
        for (int a=0; a<=A; a++) {
            for (int b=0; b<=B; b++) {
                int c = (X - a * 500 - b * 100) / 50;
                if (c >= 0 && c <= C)
                    res++;
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 23124
#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 N,D;
  cin>>N>>D;
  vector<vector<int>> A(N,vector<int>(D));
  rep(i,N){
    rep(j,D)cin>>A[i][j];
  }
  int ans=0;
  rep(i,N){
    for(int j=i+1;j<N;j++){
      int co=0;
      rep(k,D){
        int SQ=abs(A[i][k]-A[j][k]);
        co+=SQ*SQ;
      }
      for(int k=0;k<=co;k++){
        if(k*k==co)ans+=1;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353

class Segtree:
    def __init__(self, A, ide_ele, segfunc, initialize=True):
        self.n = len(A)
        self.size = 2 ** (self.n - 1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        if initialize:
            self.data = [ide_ele] * self.size + A + [ide_ele] * (self.size - self.n)
            for i in range(self.size - 1, 0, -1):
                self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
        else:
            self.data = [ide_ele] * (2 * self.size)

    def update(self, k, x):
        k += self.size
        self.data[k] = x
        while k > 0:
            k = k >> 1
            self.data[k] = self.segfunc(self.data[2 * k], self.data[2 * k + 1])

    def query(self, l, r):
        L, R = l + self.size, r + self.size
        s = self.ide_ele
        while L < R:
            if R & 1:
                R -= 1
                s = self.segfunc(s, self.data[R])
            if L & 1:
                s = self.segfunc(s, self.data[L])
                L += 1
            L >>= 1
            R >>= 1
        return s


n = I()
XD = sorted(LIR(n))
X = []
D = []
for x, d in XD:
    X += [x]
    D += [d]

last = [l for l in range(n)]
st = Segtree(last, -INF, max)
for i in range(n - 2, -1, -1):
    r = bisect_left(X, X[i] + D[i])
    ret = st.query(i, r)
    st.update(i, ret)
    last[i] = ret

dp = [1] * (n + 1)
for j in range(n - 1, -1, -1):
    k = last[j]
    dp[j] = (dp[j + 1] + dp[k + 1]) % mod


print(dp[0])


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

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

#define fr first
#define sc second

const ll MOD = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= MOD;
	if(k%2 == 1){
		ret *= x; ret %= MOD;
	}
	return ret;
}

ll f[100010],g[100010];
void init(){
	f[0] = 1;
	g[0] = 1;
	for(int i = 1 ; i < 100010 ; i ++){
		f[i] = f[i-1]*i;
		f[i] %= MOD;
		g[i] = modpow(f[i],MOD-2);
	}
}
ll C(ll n,ll k){
	if(n<k)return 0;
	ll ret = f[n];
	//ret *= g[k]; ret %= MOD;
	ret *= k+1; ret %= MOD;
	ret *= g[n-k]; ret %= MOD;
	return ret;
}

int main(){
	init();
	ll n,m;
	ll a[20];
	cin >> n >> m;
	for(int i = 1 ; i <= m ; i ++){
		cin >> a[i];
		a[i] = (1<<n)+2-a[i]-1;
	}
	reverse(a+1,a+m+1);
	
	static ll dp[20][1<<16] = {};
	dp[0][0] = 1;
	for(int i = 0 ; i < m ; i ++){
		for(int s = 0 ; s < (1<<n) ; s ++){
			for(int t = 0 ; t < n ; t ++){
				if((s>>t)&1)continue;
				dp[i+1][s+(1<<t)] += dp[i][s]*C(a[i+1]-s-1,(1<<t)-1);
				dp[i+1][s+(1<<t)] %= MOD;
			}
			dp[i+1][s] += dp[i][s];
			dp[i+1][s] %= MOD;
			//cout << i << " " << s << " " << dp[i][s] << endl;
		}
	}
	ll ret = 0;
	for(int s = 1 ; s < (1<<n) ; s ++){
		int cnt = 0;
		for(int t = 0 ; t < n ; t ++){
			if((s>>t)&1)cnt ++;
		}
		
		//cout << m << " " << s << " " << dp[m][s] << endl;
		dp[m][s] *= f[(1<<n)-1-s];
		dp[m][s] %= MOD;
		//cout << dp[m][s] << endl;
		if(cnt&1)ret += dp[m][s];
		else ret += MOD-dp[m][s];
	}
	ret %= MOD;
	ret *= 1<<n;
	ret %= MOD;
	ret = f[(1<<n)]+MOD-ret;
	ret %= MOD;
	cout << ret << endl;
}



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

#define ll long long int
#define ff first
#define ss second
#define pb push_back

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    int b[n - 1];
    for (int i = 0; i < n - 1; i++)
    {
        cin >> b[i];
    }
    ll ans = b[n - 2];
    for(int i = n - 3; i >= 0; --i)
    {
        if(b[i] < b[i + 1])
            ans += b[i];
        else ans += b[i + 1];
    }
    ans += b[0];
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	string s;
	int N, K;
	cin >> N >> K;
	cin >> s;

	s[K - 1] = s[K-1] - 'A' + 'a';
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    N,A,B = list(map(int, input().split()))
    ans = 0

    if A == 0 and B == 0:
        print(ans)
        return

    if A+B > N:
        if A > N:
            ans = N
        else:
            ans = A
    else:
        ans = A*(N//(A+B))
        if N%(A+B) >= A:
            ans += A
        else:
            ans +=  N%(A+B)

    print(ans)


main()

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    string s;
    int a;

    cin >> a;
    cin >> s;

    if(a>=3200){
        cout << s;
    }else{
        cout << "red";
    }
    cout << endl;
    return 0;
}


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

namespace AtCoder.Contest.A
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();
			int n = cin.nextInt();
			int[] a = cin.ArrayInt(n);

			Array.Sort(a);
			Array.Reverse(a);

			int ans = 0;

			for (int i = 0; i < n; i++)
			{
				ans+=a[i]*(i % 2 == 0 ? 1 : -1);
			}

			Console.WriteLine(ans);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return next();
			i = 0;
			return s[i++];
		}

		public int nextInt()
		{
			return int.Parse(next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextInt() + add;
			}
			return Array;
		}

		public long nextLong()
		{
			return long.Parse(next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextLong() + add;
			}
			return Array;
		}

		public double nextDouble()
		{
			return double.Parse(next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;


ll i,j,k;
ll kaijou[2000+1];
ll gyakugen[2000+1];
long long ruijou(long long x, long long y){
    if(y==0) return 1;
    else if(y%2==0) return ruijou(x*x%mod,y/2);
    else return x*ruijou(x,y-1)%mod;
}

ll combination(ll n,ll c){
    if(n<c)return 0;
    return ((kaijou[n]*gyakugen[c])%mod)*gyakugen[n-c]%mod;
}
ll mo(ll x){
    ll ans=x%mod;
    if(x>=0)return ans;
    return ans+mod;
}


int main(){
    ll A,B,K;
    cin>>A>>B>>K;

    ll cnt=0;
    ll ans;
    ll ka=min(A,B);
    while(cnt<K){
        if(A%ka==0&&B%ka==0){
            cnt++;
            ans=ka;
        }
        ka--;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin>>s;
  
  string t="";
  t+=s[0];
  t+=s[1];

  string r="";
  r+=s[2];
  r+=s[3];

  int a=(s[0]-'0')*10+(s[1]-'0');
  int b=(s[2]-'0')*10+(s[3]-'0');

  if(a>=1&&a<=12){
    if(b>=1&&b<=12) cout<<"AMBIGUOUS"<<endl;
    else cout<<"MMYY"<<endl;
  }else{
    if(b>=1&&b<=12) cout<<"YYMM"<<endl;
    else cout<<"NA"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
n=int(input())
data=[list(map(int,input().split())) for _ in range(n)]
x_past=0
y_past=0
t_past=0
for t,x,y in data:
  if abs(x-x_past)+abs(y-y_past)>t-t_past:
    print("No")
    exit()
  if (abs(x-x_past)+abs(y-y_past))%2!=(t-t_past)%2:
    print("No")
    exit()
  x_past=x
  y_past=y
  t_past=t
print("Yes")

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

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

int main() {
	int w, h, ans, x, y;
	int c[52][52], f[52][52];
	stack< pair<int, int> > s;
	while(1) {
		cin >> w >> h;
		if(!w&&!h) break;
		for(int i=0; i<h+2; ++i) for(int j=0; j<w+2; ++j) {
			c[i][j] = 0; f[i][j] = 0;
		}
		ans = 0;
		
		for(int i=1; i<=h; ++i) for(int j=1; j<=w; ++j) {
			cin >> c[i][j];
		}
		for(int i=1; i<=h; ++i) for(int j=1; j<=w; ++j) {
			if(c[i][j]&&!f[i][j]) {
				ans++;
				s.push( pair<int, int>(i, j) );
				while(!s.empty()) {
					y = s.top().first; x = s.top().second;
					s.pop();
					f[y][x] = 1;
					for(int k=0; k<8; ++k) {
						if(c[y+dy[k]][x+dx[k]]&&!f[y+dy[k]][x+dx[k]]) {
							s.push( pair<int, int>(y+dy[k], x+dx[k]) );
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1296
import copy
x = int(input())
y = list(map(int,input().split()))

result = 0
for (i, v) in enumerate(y):
  z = copy.deepcopy(y)
  c = copy.deepcopy(x) - 1 - i
  r = 0
  for j in range(c):
    r = r + z.pop()
  result = result + r * v

print(result)



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

int main(int argc, char const* argv[])
{
    int cake = 16;
    int a, b;
    cin >> a >> b;
    if (a <= cake / 2 && b <= cake / 2) {
        cout << "Yay!";
    } else {
        cout << ":(";
    }
    return 0;
}


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

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	string s; cin >> s;
	if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi") {
		cout << "Yes";
	} else {
		cout << "No";
	}

	return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(a, b);
  string ans;
  if (a + b == 15) ans = "+";
  else if (a * b == 15) ans = "*";
  else ans = "x";

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char masu[60][60];
int kekka[60][60];
int main() {
  int h,w;
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>masu[i][j];
      kekka[i][j]=0;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(masu[i][j]=='.'&&masu[i][j+1]=='.'&&j+1<w){
        masu[i][j]='#';
        masu[i][j+1]='#';
      }
      if(masu[i+1][j]=='#' && i+1<h ){
        kekka[i][j]=1;
      }
      if(masu[i][j+1]=='#' && j+1<w){
        kekka[i][j]=1;
      }
      if(masu[i-1][j]=='#' && i-1>=0){
        kekka[i][j]=1;
      }
      if(masu[i][j-1]=='#' && j-1>=0){
        kekka[i][j]=1;
      }
    }
  }  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(kekka[i][j]!=1){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int IsPrime(int n){
	int i;
	if(n==1) return 0;
	if(n==2) return 1;
	else if(n%2==0) return 0;
	for(i=3;i*i<=n;i+=2) if(n%i==0)	return 0;
	return 1;
}

int main(void){
	int i , n;
	while(scanf("%d" , &n)!=EOF){
		for(i=n-1;;i--){
			if(IsPrime(i)){
				printf("%d " , i);
				break;
			}
		}
		for(i=n+1;;i++){
			if(IsPrime(i)){
				printf("%d\n" , i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
import math

N = int(input())
lists = [ int(v) for v in input().split(" ") ]

total = 0

for l in lists:
  if l % 2 == 0:
    while True:
      if l % 2 == 0:
        l = int(l/2)
        total += 1      
      else:
        break
print(total)

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k ==u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);


}

Node treeSuccessor(Node x){
  Node y;
  
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else{
    if(y == y->parent->left) y->parent->left = x;
    else y->parent->right = x;
  }
  if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
    z->parent = y;
  

  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
  else y->right = z;
  }
}

int find(Node x,int k){
  while(x != NIL && k != x->key){
    if(k < x->key) x = x->left;
    else x = x->right;
  }
  return x;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }

}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}




Measured memory_bytes: 20480
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,k=0,i,j;
	char w[100];
	char al[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	scanf("%s", w);
	n=strlen(w);
	for(i=0; i<26; i++)
	{
		for(j=0; j<n; j++)
		{
			if(al[i]==w[j])
			k++;
		}
		if(k%2!=0)
		{
			printf("No\n");
			break;
		}
		if(i==25)
		printf("Yes\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
from collections import defaultdict


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    for x in a:
        d[x] += 1
    diff = {}
    sum_ = 0
    for key, value in d.items():
        num = value * (value - 1) // 2
        sum_ += num
        diff[key] = num - (value - 1) * (value - 2) // 2
    for x in a:
        print(sum_ - diff[x])


if __name__ == "__main__":
    main()


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

int main() {
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  vector<vector<int>> ans(h, vector<int>(w));
  vector<int> input(h*w);
  int total = 0;
  for(int i=1;i<=n;i++) {
    int a;
    cin >> a;
    for(int j=total;j<total+a;j++) {
      input[j] = i;
    }
    total += a;
  }

  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      ans[i][j] = input[i*w+j];
    }
  }

  for(int i=1;i<h;i+=2) {
    reverse(ans[i].begin(), ans[i].end());
  }

  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}


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

int main() {
	int A,B,C;
	cin >> A >> B >> C;
	int ans;
	if (A >= B && A >= C) {
		ans = 10*A + B + C;
		//cout << "A" << endl;
	} else if (B >= A && B >= C) {
		ans = 10*B + C + A;
		//cout << "B" << endl;
	} else if (C >= A && C >= B) {
		ans = 10*C + A + B;
		//cout << "C" << endl;
	} else {
		cout << "bug" << endl;
		cout << A << "," << B << "," << C << endl;
	}
	cout << ans << endl;
	return 0;
}



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

int main(){
   long N; cin>>N;
   ll sum = 1;
   bool flag = false;
   rep(i, N){
       ll A;
       cin>>A;

        int len1 = to_string(A).length()-1;
        int len2 = to_string(sum).length()-1;
        if(sum%(ll)pow(10, len2) * A%(ll)pow(10, len1) > 10){
            len1 += 1;
        }

       sum *= A;

        if(len1 + len2 > 18){
            flag = true;
        }
       if(sum > 1000000000000000000 || A > 1000000000000000000){
           flag = true;
       } 
        if(A == 0){
            cout << 0 << endl;
            return 0;
        }
   }

    if(flag){
        cout << "-1" << endl;
        return 0;
    }
   cout << sum << endl;
}


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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const long long inf = 1e9+7;
const long long mod = 1e9+7;

int main(){
    ll n,m;
    map<ll,ll>d;

    cin>>n;
    rep(i,n){
        ll D;
        cin>>D;

        d[D]++;
    }

    cin>>m;
    rep(i,m){
        ll t;
        cin>>t;

        d[t]--;

        if(d[t]<0){
            cout<<"NO"<<endl;
            return 0;
        }
    }

    cout<<"YES"<<endl;

}


Measured memory_bytes: 16044
import java.io.*;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    /*public static StreamTokenizer in;
    static {
        try{
            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(new BufferedInputStream(System.in))));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static int nextInt() throws IOException{ in.nextToken(); return (int)in.nval; }*/
    public static void main(String[] args) throws IOException{
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextLong();
        long ans=0;
        if(c<b)
            ans=a*c/b;
        else{
            long i=2*b-1;
            BigInteger v=new BigInteger(a+"").multiply(new BigInteger(i+""));
            //System.out.println(v);
            v=v.divide(new BigInteger(b+""));
            long q=v.longValue();
            long e=i/b;
            e*=a;
            //System.out.println(q+"  "+e);
            ans=q-e;
            }
            System.out.println(ans);
    }
}


Measured memory_bytes: 39056
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define int long long   
#define mod 1000000009
#define garou ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int pow(int p,int r,int m){
	int ans=1;
	while(r>0){
     if(r&1){
		 ans=((ans%m)*(p%m))%m;
	 }
	 r=r>>1;
     p=((p%m)*(p%m))%m;
	}
	return ans;
}
int popcount(int n){
	int ans=0;
	REP(i,0,32){
		if((n&(1<<i)))
		ans++;
	}
	return ans;
}
int binary(string x,int m){
	int n=x.length();
	int ans=0,j=0;
	for(int i=n-1;i>=0;i--){
    if(x[i]!='0')
     ans=(ans+pow(2,j,m))%m;
	j++;
	}
	return ans;
}
signed main() {
	garou;
   int n;
   cin>>n;
string x;
cin>>x;
int one=0;
int n1=x.length();
REP(i,0,n){
	if(x[i]=='1')
	one++;
}
int a=binary(x,one+1);
int b=0;
if(one>1)
b=binary(x,one-1);
REP(i,0,n1){
	if(x[i]=='1'&&(one-1)==0){
		cout<<0<<endl;
		continue;
	}
	int c=0;
	if(x[i]=='0')
	c=(a+pow(2,n1-i-1,one+1))%(one+1);
	else
	c=(b-pow(2,n1-i-1,one-1)+one-1)%(one-1);
	int re=0;
   while(c){
	   c%=popcount(c);
     re++;
   }
   cout<<re+1<<endl;
}
}

Measured memory_bytes: 3848
/*
    Don’t practice until you get it right. Practice until you can’t get it wrong.
*/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld double
#define pii pair<ll,ll>
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vp vector<pii>
#define pb push_back
#define mp make_pair
#define sc(a) scanf("%lld",&a);
#define sd(a) scanf("%lf",&a);
#define test() ll tt;cin>>tt;for(ll testcase=1;testcase<=tt;testcase++)
#define all(v) v.begin(),v.end()
#define vivek_ghosh ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000055
#define mod 1000000007
#define ff first
#define ss second
const int INF=0x3f3f3f3f;
const ll int inf = LLONG_MAX;

ll power(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

ll modinv(ll a,ll m)
{
    ll g =__gcd(a, m);
    ll res=power(a, m-2, m);
    return res;
}

vb prime(MAX,true);
vl prm;
void sieve()
{
	prime[0] = prime[1] = false;
	for(ll p=2;p*p<MAX;p++)
	{
		if(prime[p])
		{
			for(ll i=p*p;i<MAX;i+=p)
				prime[i] = false;
		}
	}
	for(ll p=2;p<MAX;p++)
	{
		if(prime[p])
			prm.pb(p);
	}
}


ll n,m,t,i,j,k,q,x,y,ans=0,cnt=0,sum=0,mx=-1,mn=INT_MAX;
string s;

int main()
{
	vivek_ghosh;
	
	cin>>s;
	n = int(s.size());
	i=0,j=n-1;
	while(i<j)
    {
        if(s[i] != s[j])
            ans++;
        i++;
        j--;
    }
    
    cout<<ans<<endl;
	
	
	
	
	
	return 0;
}







Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
using namespace std;
const int PMAX = 120000;

int main() {
  bool isnp[PMAX+1];
  int p[10000];
  int x;
  memset(isnp, 0, sizeof(bool)*(PMAX+1));

  for (int i=2; i*i<=PMAX; i++) {
    if (!isnp[i]) {
      for (int j=2*i; j<=PMAX; j+=i) {
        isnp[j] = true;
      }
    }
  }
  p[0] = 2;
  x = 1;
  for (int i=3; i<=PMAX; i++) {
    if (!isnp[i]) {
      p[x] = p[x-1] + i;
      ++x;
    }
    if (x >= 10000) break;
  }

  while (scanf("%d", &x) && x) {
    printf("%d\n", p[x-1]);
  }
  return 0;
}

Measured memory_bytes: 1188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		sc.close();

		int ans = B + C - A;
		System.out.println(ans >= 0 ? ans : 0);
	}
}

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

int main() {

  int N;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  int total =0;

  for(int i=0;i<N;i++){
    cin >> s.at(i) >> t.at(i);
    total +=t.at(i);
  }

  string X;
  cin >> X;

  int second =total;
  for(int i=0;i<N;i++){
    second -= t.at(i);
    if(s.at(i) ==X){
      break;
    }

  }
  
  cout << second << endl;

}

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

int main(){
    int n, cnt=0; cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 1; i < n-1; i++){
        if((p[i-1]<p[i] && p[i]<p[i+1]) || (p[i-1]>p[i] && p[i]>p[i+1])) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
N, X = map(int, input().split())
x = list(map(int, input().split()))

x.append(X)
x.sort()
diff = list(set([i-j for i, j in zip(x[1:], x[:-1])]))

if len(diff) == 1:
  print(diff[0])
  exit()

comm = diff[0]
for i in diff:
  while i > 0:
    comm, i = i, comm%i

print(comm)

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

int main()
{
    int n,k,d,b,i,j,c;

    cin>>n>>k;

    int a[n+5]={0};

    for(i=0;i<k;i++){
        cin>>d;

        for(j=0;j<d;j++){
            cin>>b;
            a[b]++;
        }
    }
    c=0;
    for(i=1;i<=n;i++){
        if(a[i]==0){
            c++;
        }
    }
    cout<<c<<endl;

    return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int A[100010];
    rep(i, N) cin >> A[i];
    sort(A, A + N);
    A[N] = INF;
    int ok = 200001;
    int ng = 0;
    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        int cnt = 0;
        rep(i, N) {
            auto itr = lower_bound(A, A + N, mid - A[i]);
            //cout << mid << " " << A[i] << " " << distance(A, itr) << endl;
            cnt += N - distance(A, itr);
        }
        if(cnt <= M) ok = mid;
        else ng = mid;
    }
    int ans = 0;
    rep(i, N) {
        auto itr = lower_bound(A, A + N, ok - A[i]);
        int cnt = N - distance(A, itr);
        M -= cnt;
        ans += A[i] * cnt;
    }
    cout << ans * 2 + M * (ok - 1) << endl;

    return 0;
}


Measured memory_bytes: 4420
def projection(x1, y1, x2, y2, x0, y0):
    if x2 == x1:
        return (x2, y0)
    m = float(y2 - y1) / float(x2 - x1)
    b = y1 - m * x1 # intercept of the original line                                                                                             
    xp = (x0 + (m * y0) - (m * b)) / (1. + (m * m))
    yp = ((m * x0) + ((m * m) * y0) + b) / (1. + (m * m))
    return (xp, yp)

x1, y1, x2, y2 = map(float, input().split())
q = int(input())
for _ in range(q):
    x0, y0 = map(float, input().split())
    ans = projection(x1, y1, x2, y2, x0, y0)
    print(ans[0], ans[1])


Measured memory_bytes: 5628
P = 10**9+7
N, M = map(int, input().split())
S = [int(a) for a in input().split()]
T = [int(a) for a in input().split()]
X = [[1] * (M+1)] + [[1]+[0]*M for _ in range(N)]
for i in range(N):
    for j in range(M):
        X[i+1][j+1] = (X[i+1][j] + X[i][j+1] - (X[i][j] * (S[i] != T[j])))%P
print(X[N][M])


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tsii = tuple<string, int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,cnt=0;
    cin>>n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
        a[i]--;
        if(a[i]!=i) cnt++;
    }
    
    if(cnt>2) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  vl a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  
  ll ans=0;
  vl d(n);
  rep(i, n) d[i]=a[i]-b[i];
  sort(all(d));
  ll lack=0;
  rep(i, n) {
    if(d[i]<0) {lack+=d[i]; ans++;}
    else break;
  }
  ll k=n-1, add=0;
  while(add+lack<0){
    if(d[k]<0) {cout << "-1" << newl; return 0;}
    add+=d[k];
    k--; ans++;
  }
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 5544
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;

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

	pair<int,bool> arr[n+1] ;

	arr[0].first=-1 ;

	for(int i=1;i<=n;i++){
		cin>>arr[i].first ;
		arr[i].second=false ;
	}

	int source=1 ;
	int steps=1 ;

	while(arr[source].second==false){

		//cout<<arr[source].first<<" "<<arr[source].second<<"\n" ;

		if(arr[source].first==2)
			{	
				cout<<steps ;
				return ;
			}

		arr[source].second=true ;
		source=arr[source].first ;
		steps++ ;
	
	}
		
	cout<<-1 ;

}	

int main(){
	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 4324
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
// using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;

//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const double pi = 3.14159265359;
const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
//const ll mod = 998244353 ;
const ll mod=1e9+7;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return (((a+mod)%mod)*(b+mod)%mod)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline ll modInverse(ll n, ll p){ return power(n, p-2)%p; }

/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 

ll i,j,k,l,m,r,n;
ll a[MAX],b[MAX];

void stArt()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

void eNd()
{
	#ifndef ONLINE_JUDGE
  	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  	#endif
}

int main()
{
 
stArt();
fast
//cout << setprecision(15) << fixed;

	ll x;
	cin >> x >> n;
	vll v(101,1);
	fr(i,0,n)
	{
		cin >> k;
		v[k] = 0;
	}
	ll mn = x;
	ll ans = 0;
	fr(i,1,v.size())
	{
		if(v[i] == 1 && mn > abs(i-x))
			mn = abs(i-x), ans = i;
	}
	if(mn > abs(101-x))
		ans = 101;
	cout << ans;


 eNd();
  return 0;
 
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef unsigned long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const int i_INF = 2147483647;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, 0, n)a[i] = 111111;
	vector<int> b(n);
	rep(i, 0, n - 1) {
		cin >> b[i];
		if (a[i] > b[i])a[i] = b[i];
		a[i + 1] = b[i];
	}
	int ans = 0;
	rep(i, 0, n)ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

a,b = ria()

l = []
m = 0
for i in range(1000):
  m += i
  l.append(m)

print(l[b-a] - b)

Measured memory_bytes: 3828
from collections import deque

class FloppyCube:

    solution = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 
		 2, 2, 2, 4, 4, 4, 6, 6, 6, 5, 5, 5,
		 3, 3, 3, 3, 3, 3, 3, 3, 3 ];

    def __init__( self ):
        self.face = []
        self.step = 0

    def copy( self, s ):
        for i in range(30):
            self.face.append(s.face[i])
        self.step = s.step

    def IsSolved( self ):
        for i in range(30):
            if self.face[i] != self.solution[i] : return False
        return True

    def Swap( self, n, m ):
        self.face[n],self.face[m] = self.face[m],self.face[n]
    
    def Rotate( self, side ):
        if side == 0:
            self.Swap( 12, 17 )
            self.Swap( 9, 11 )
            self.Swap( 6, 21 )
            self.Swap( 7, 22 )
            self.Swap( 8, 23 )
        elif side == 1:
            self.Swap( 14, 15 )
            self.Swap( 18, 20 )
            self.Swap( 0, 27 )
            self.Swap( 1, 28 )
            self.Swap( 2, 29 )
        elif side == 2:
            self.Swap( 11, 18 )
            self.Swap( 12, 14 )
            self.Swap( 2, 21 )
            self.Swap( 5, 24 )
            self.Swap( 8, 27 )
        else:
            self.Swap( 9, 20 )
            self.Swap( 15, 17 )
            self.Swap( 0, 23 )
            self.Swap( 3, 26 )
            self.Swap( 6, 29 )
        

n = int(input())
s = FloppyCube()
for i in range(n):
    s.step = 0
    s.face = list(map(int,input().split()))

    q = deque()
    q.append(s)
    
    while q :
        s = q.popleft()
        if s.IsSolved(): break
        
        s.step += 1
        if s.step <= 8:
            for i in range(4):
                t = FloppyCube()
                t.copy( s )
                t.Rotate(i)
                q.append(t)
    print(s.step)
    



Measured memory_bytes: 40060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main() {
  int n;
  cin >> n;
  vector<int> count (4,0);
  rep(i,n){
    string s;
    cin >> s;
    if(s=="AC") count[0]++;
    else if (s=="WA") count[1]++;
    else if (s=="TLE") count[2]++;
    else if (s=="RE") count[3]++;
    
  }

  cout << "AC x " << count[0] << endl;
  cout << "WA x " << count[1] << endl;
  cout << "TLE x " << count[2] << endl;
  cout << "RE x " << count[3] << endl;

  return 0;
}


Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int t[10][10];


int check(const string &s) {
	int x = 0;
	rep(i, 4)x = t[x][s[i] - '0'];
	return x;
}

bool check2(const string &s) {
	int x = 0;
	rep(i, 5)x = t[x][s[i] - '0'];
	return x == 0;
}


bool f(int a) {
	string s;
	s += a / 1000 % 10 + '0';
	s += a / 100 % 10 + '0';
	s += a / 10 % 10 + '0';
	s += a / 1 % 10 + '0';
	s += check(s) + '0';

	
	for(char &d : s) {
		char c = d;
		rep(i,10) {
			if (c == i + '0')continue;
			d = i + '0';
			if (check2(s)) {
				return false;
			}
		}
		d = c;
	}
	rep(i,4) {
		if (s[i] == s[i + 1])continue;
		swap(s[i], s[i + 1]);
		if (check2(s)) {
			return false;
		}
		swap(s[i], s[i + 1]);
	}
	return true;
}



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

	rep(i, 10)rep(j, 10)cin >> t[i][j];

	int a = 0;
	rep(i, 10000) if (!f(i))a++;
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 3220
#include <cstdio>
#include <cmath>

const int LIM = 1e6;
int arr[LIM]; 

int main() {
	int n;
	while(scanf("%d", &n) == 1 && n) {
		int sum = 0;
		for(int i = 1; i <= n; i++) scanf("%d", &arr[i]), sum += arr[i];
		double avg = sum / (double)n, stddev = 0.0;
	//	printf("%lf\n", avg);
		for(int i = 1; i <= n; i++) stddev += pow(arr[i] - avg, 2.0);
		stddev /= n;
		printf("%.8lf\n", sqrt(stddev)); 
	}
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  if(N<=999) cout << "ABC" << endl;
  else cout << "ABD" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int n;
    int count = 0;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    for (int i = 0; i < n; i++) {
        cin >> p.at(i);
    }
    for (int i = 0; i < n; i++) {
        q.at(i) = i + 1;
    }
    for (int i = 0; i < n; i++) {
        if (p.at(i) == q.at(i)) count++;
    }
    if (count < n - 2) cout << "NO" << endl;
    else cout << "YES" << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

map <int, int> D;
char A[200010];
int B[200020];

void solve() {
	scanf("%s", A+1);
	int n = (int)strlen(A+1);
	for(int i=1;i<=n;i++) B[i] = 1<<(A[i] - 'a');
	for(int i=1;i<=n;i++) B[i] ^= B[i-1];
	D[0] = 0;
	for(int i=1;i<=n;i++) {
		int ans = 1e9;
		rep(j, 27) {
			int t = B[i] ^ 1 << j;
			if(j == 26) t = B[i];
			if(D.find(t) != D.end()) {
				ans = min(ans, D[t] + 1);
			}
		}
		if(D.find(B[i]) == D.end()) D[B[i]] = ans;
		else D[B[i]] = min(D[B[i]], ans);
		if(i == n) printf("%d\n", ans);
	}
	
}

int main(){
	int Tc = 1; // scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		// printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}

Measured memory_bytes: 10624
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  int key;
  struct node *right;
  struct node *left;
  struct node *parent;
};

typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;

  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }

  z->parent=y;

  if( y == NIL ){
    root=z;
  }
  else{
    if( z->key < y->key ){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
}

void inorder(Node u){
  if( u == NIL )
    return;

  inorder(u->left);

  printf(" %d",u->key);

  inorder(u->right);
}

void preorder(Node u){
  if( u == NIL )
    return;

  printf(" %d",u->key);
  
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  char com[20];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    
    if( strcmp(com,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    else if( strcmp(com,"print")==0 ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



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

constexpr int INF = (1<<30)-1;

int dp1[1000045], dp2[1000045];
bool solve() {
    int N;
    cin >> N;
    if (N == 0) return (false);
    
    cout << dp1[N] << " " << dp2[N] << endl;
    return (true);
}

int main() {
    fill_n(dp1, 1000045, INF);
    fill_n(dp2, 1000045, INF);
    
    dp1[0] = 0;
    dp2[0] = 0;
    for (int i = 0; i <= 1000000; i++) {
        for (int j = 1; i + j * (j + 1) * (j + 2) / 6 <= 1000000; j++) {
            int val = j*(j+1)*(j+2)/6;
            dp1[i + val] = min(dp1[i + val], dp1[i] + 1);
            if (val & 1) dp2[i + val] = min(dp2[i + val], dp2[i] + 1);
        }
    }
    while (solve());
    return (0);
}


Measured memory_bytes: 10880
def main():
    array = [int(input()) for _ in range(6)]
    k = array[-1]
    array = array[:-1]

    minimum = min(array)
    maximum = max(array)
    if maximum-minimum > k:
        print(':(')
        return
    print('Yay!')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// ABC085B - Kagami Mochi
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func newLine() string {
	sc.Scan()
	return sc.Text()
}
func main() {
	N, _ := strconv.Atoi(newLine())
	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i], _ = strconv.Atoi(newLine())
	}
	sort.Sort(sort.Reverse(sort.IntSlice(d)))
	count := 1
	beforeNum := d[0]
	for i := 1; i < N; i++ {
		if beforeNum != d[i] {
			count++
			beforeNum = d[i]
		} else {

		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

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

    string ans = "Yes";
    if (S == "AAA") ans = "No";
    if (S == "BBB") ans = "No";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256