akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <sstream>
#include <cassert>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <ctime>

using namespace std;

#define en '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())

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

const int INF = 1e9 + 7;
const ll INFLL = 1e18;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int MAX_SIZE = 5e5;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

bool IS_ONE_TEST = 1;
ld START_TIME, TIME;

void fast_in_out() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void solve() {
    char a;
    cin >> a;
    cout << (a >= 'a' ? 'a' : 'A') << en;
}

int main() {
    START_TIME = clock();
    fast_in_out();
    int TESTS = 1;
    if (!IS_ONE_TEST) cin >> TESTS;
    while (TESTS--) { solve(); }
#ifdef __APPLE__
    TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    cerr << en << TIME * 1000 << " ms." << en;
#endif
    return 0;
}

/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


Measured memory_bytes: 3004
import numpy as np
st=input().split()
N=int(st[0]);K=int(st[1])
S=set([])
st=input().split()
P=[0]*(N+1)
Q=[0]*(N+1)
for i in range(N):
    k=int(st[i])
    S.add(k)
    P[k-1]+=1
    Q[P[k-1]-1]-=1
    Q[P[k-1]]+=1
out=0
change=0
count=0
if len(S)<=K:
    print(0)
else:
    for i in range(1,N+1):
        flag=1
        for j in range(Q[i]):
            change+=i
            count+=1
            if count==max([len(S)-K,0]):
                flag=0
                break
        if flag==0:
            break
    print(change)


Measured memory_bytes: 46256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  long a, b, c=0, d=0, e, f, g, h, n;
  cin >> a >> b;
  string s, t={};
  rep(i,0,b+2) t+='#';
  co(t);
  rep(i,0,a){
    cin >> s;
    cout << '#' << s << '#' << endl;
  }
  co(t);
  
  return 0;
  
}

Measured memory_bytes: 256
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy


def odd(n): return n & 1


def even(n): return not odd(n)


def comb(n, m):
    r = 1
    for i in range(1, n+1):
        r *= i
    for i in range(1, m+1):
        r //= i
    for i in range(1, n-m+1):
        r //= i
    return r


N, P = map(int, input().split())
A = [int(n) % 2 for n in input().split()]
cnt0 = len([a for a in A if a == 0])
cnt1 = len([a for a in A if a == 1])
ans = 0
if odd(P):
    for i in range(cnt1 + 1):
        if odd(i):
            ans += comb(cnt1, i)
else:
    for i in range(cnt1 + 1):
        if even(i):
            ans += comb(cnt1, i)
ans *= pow(2, cnt0)
print(ans)


Measured memory_bytes: 81496
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for(int i = 1;;i++){
            int num = sc.nextInt();
            if(num == 0){
                break;
            }
            System.out.println("Case " +i+ ": " + num);
        }
    }
}


Measured memory_bytes: 41560
#include<stdio.h>
#include<math.h>
int main(void)
{
    double d,e;
    double x=0.0,y=0.0,a=-M_PI/2;
    for(;;){
        scanf("%lf,%lf",&d,&e);
        if(d == 0 && e == 0)break;
        x+=cos(a)*d;
        y+=sin(a)*d;
        a+=e/180*M_PI;
    }
    printf("%d\n%d\n",(int)x,-(int)y);
    return 0;
}

Measured memory_bytes: 632
#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SQR(x) (x) * (x)
#define itn int

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

signed main() {
  int H, W, N;
  cin >> H >> W >> N;
  deque<int> a(N);
  REP(i, N) {
    cin >> a[i];
  }
  vector<vector<int>> ans(H, vector<int>(W));
  int current = 1;
  REP(i, H) {
    if (i % 2) {
      REP(j, W) {
        ans[i][j] = current;
        if (!--a[0]) {
          a.pop_front();
          current++;
        }
      }
    } else {
      for (int j = W - 1; j >= 0; j--) {
        ans[i][j] = current;
        if (!--a[0]) {
          a.pop_front();
          current++;
        }
      }
    }
  }
  REP(i, H) {
    REP(j, W) {
      cout << ans[i][j];
      if (j != W - 1) {
        cout << " ";
      } else {
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
  
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef node* Node;
#define NIL NULL
 
node array[500000];
int size=0;
 
Node root = NIL;
  
Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}
  
Node treeSearch(Node u, int k){
  Node i=u;
  while(i!=NIL){
    if(i->key==k)return i;
    else if(i->key<k)i=i->right;
    else i=i->left;     
  }
  return NIL;
}
  
Node treeSuccessor(Node x){
  if(x->right!=NIL)return treeMinimum(x->right);
  Node 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;
    
  //free(y);
}
  
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = &array[size++];
  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,x;
  char str[20];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s", str);
    if(str[0]=='f'){
      scanf("%d",&x);
      Node t=treeSearch(root,x);
      if (t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(str[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(str[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }
 
  return 0;
}


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

int main(void){
	int n;
	int a[100];	
	int i;
	int ret;

	int min,ave;

	scanf("%d",&n);

	ave = 0;

	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		a[i] *= 1000;
		ave += a[i];
	}
	ave /= n;
	min = 100000;
	ret = 0;
	for(i=0;i<n;i++){
		if(min>abs(a[i]-ave)){
			min = abs(a[i]-ave);
			ret = i;
		}
	}

	if(n==1){
		printf("0\n");
	}
	else{
		printf("%d\n",ret);
	}
	return 0;
}


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

typedef long long ll;

ll distance(ll a,ll b){
	return labs(a)+labs(b);
}

ll n,t,p,q,mt,mp,mq;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		ll dis;
		cin>>t>>p>>q;
		t-=mt;
		p-=mp;
		q-=mq;
		dis=distance(p,q);
		if(t<dis){
			cout<<"No"<<endl;
			return 0;
		}else{
			if((t-dis)%2==1){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a[111];
    cin>>n;
    double ave=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ave+=a[i];
    }
    ave/=(double)n;
    int ans;
    double min=9999999;
    for(int i=0;i<n;i++){
        double de=abs(ave-a[i]);
        if(min>de){
            min=de;
            ans=i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();	
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
//ruogu_alter
const int N = 2e5 + 5;
int sz[N], mx[N], n, par[N], res[N], f[N], pp[N];
vector<int> g[N], v[N];
//
void init(int x, int p, int l) {
  mx[x] = l; l = max(l, x); pp[x] = p;
  rep(i, g[x].size()) {
    int to = g[x][i];
    if (to == p) continue;
    init(to, x, l);
  }
}
int findset(int x) {
  return par[x] == x ? x : par[x] = findset(par[x]);
}
void unite(int x, int y) {
  x = findset(x); y = findset(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  par[y] = x; sz[x] += sz[y];
}
void dfs(int x) {
  for (int to : g[x]) {
    if (to == pp[x]) continue;
    dfs(to);
    if (x && x < mx[x] && to < mx[x]) {
      for (int t : g[to]) if (t < mx[x]) f[to] += f[t];
      ++f[to];
    }
  }
}
void dfs2(int x, int nowx, int nowy) {
  if (x) res[x] += res[mx[x]] - nowy; 
  for (int to : g[x]) {
    if (to == pp[x]) continue;
    if (x > nowx) dfs2(to, x, f[to]);
    else dfs2(to, nowx, nowy);
  }
}
int main() {
  n = getint();
  rep(i, n - 1) {
    int x = getint() - 1, y = getint() - 1;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }
  init(0, -1, -1);
  rep(i, n) par[i] = i, sz[i] = 1;
  for (int i = 1; i < n; i++) v[mx[i]].emplace_back(i);
  rep(i, n) {
    for (int x : v[i]) if (x > i) {
      for (int to : g[x]) if (to < i && to != pp[x]) {
        f[to] = sz[findset(to)];
      }
    }
    for (int x : v[i]) {
      if (x < i) res[x] += sz[findset(x)];
      else {
        for (int to : g[x]) if (to < i) {
          res[x] += sz[findset(to)];
        }
        ++res[x];
      }
    }
    for (int to : g[i]) if (to < i) {
      unite(i, to);
    }
  }
  dfs(0);
  dfs2(0, -1, -2);
  rep(i, n) if (i) printf("%d ", res[i]);
  return 0;
}


Measured memory_bytes: 35320
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
import copy

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    que = deque()

    for n in range(N):
        cmd = sl()
        if cmd[0] == 'insert':
            que.appendleft(cmd[1])
        elif cmd[0] == 'delete' and cmd[1] in que:
            que.remove(cmd[1])
        elif cmd[0] == 'deleteFirst' and len(que) > 0:
            que.popleft()
        elif cmd[0] == 'deleteLast' and len(que) > 0:
            que.pop()
    print(*que)


if __name__ == '__main__':
    main()



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

using namespace std;
typedef long long int ll;
ll a, b, c, d;
int main() {
    
    ll n, i;
    string s;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>s;
        if(s[0]=='A')
        {
            a++;
        }
        else if(s[0]=='W')
        b++;
        else if(s[0]=='T')
        c++;
        else
        d++;
    }
    printf("AC x %lld\n", a);
    printf("WA x %lld\n", b);
    printf("TLE x %lld\n", c);
    printf("RE x %lld\n", d);
    
    return 0;
}

Measured memory_bytes: 3716
#include <stdio.h>

void factorize(int num, int divisor[], int *index);

int
main(void)
{
  int a, b, c, i;
  int count = 0;
  scanf("%d%d%d", &a, &b, &c);
  for (i = a; i <= b; i++) {
    if (c % i == 0) {
      count++;
    }
  }
  printf("%d\n", count);
}

void
factorize(int num, int divisor[], int *index)
{
  *index = 0;
  while (num % 2 == 0) {
    num = num / 2;
    divisor[*index] = 2;
    *index += 1;
    printf("*index = %d\n", *index);
    printf("divisor[%d] = %d\n", *index, 2);
  }

  int i;
  for(i = 3; i * i < num; i += 2) {
    while (num % i == 0) {
      num = num / i;
      divisor[*index] = i;
      *index += 1;
      printf("*index = %d\n", *index);
      printf("divisor[%d] = %d\n", *index, i);
    }
  }

  if (num > 1) {
    divisor[*index] = num;
    *index += 1;
    printf("*index = %d\n", *index);
    printf("divisor[%d] = %d\n", *index, num);
  }
}

Measured memory_bytes: 1828
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	ll suml=a+b,sumr=a+b;
	if((n==1 && a!=b) || (a>b)) {
		puts("0");
		return 0;
	}
	if(n==1 && a==b){
		cout << 1 << endl;
		return 0;
	}

	n -= 2;
	for(int i=0; i<n; i++){
		suml += a;
		sumr += b;
	}
	// cout << n << " " << suml << " " << sumr << endl;
	ll ans = sumr-suml+1;
	cout << ans << endl;

    return 0;
}

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


int count2[100001];
bool visited[100001];
vector<int>v[100001];


int compute(int n)
{
    int ele;
    if(v[n].size()==0)
    return 0;
    if (visited[n]==true)
    return count2[n];
    visited[n]=true;
    
    
    
    
    for(int i=0;i<v[n].size();i++)
    {
        ele=v[n][i];
        // visited[ele]=true;
        if(count2[ele]!=-1)
        count2[n]=max(count2[n],count2[ele]+1);
        else
        count2[n]=max(count2[n],compute(ele)+1);
        
        
    }
    return count2[n];
    
}
int main()
{
    int N,M,a,b,top,ele;
    cin>>N>>M;
    
    for(int i=0;i<M;i++)
    {
        cin>>a>>b;
        v[a].push_back(b);
    }
   
    for(int i=0;i<=N;i++)
    visited[i]=false;
    for(int i=0;i<=N;i++)
    count2[i]=-1;
 int ans=0;

    for(int i=1;i<=N;i++)
    {
        if(visited[i]==false)
        {
            
            // cout<<compute(i)<<"\n" ;   
            ans=max(ans,compute(i));
        }            
    }
    cout<<ans<<"\n";
    
 
  
    
    
}

Measured memory_bytes: 11620
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define p(s) cout<<(s)<<endl
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9+7;

int a,b,c,n;
string s;
int main() {
	cin>>a>>b>>c;
	if(a==b){
		p(c);
	}else if(a==c){
		p(b);
	}else{
		p(a);
	}
	return 0;
}


Measured memory_bytes: 256
n=int(input())
ls=list(map(int,input().split()))
ans=1
for i in range(n):
    if ls[i]==0:
        print(0)
        quit()
for i in range(n):
    if ans>10**18:
        ans=-1
        break
    ans=ans*ls[i]
if ans>10**18:
    ans=-1
print(ans)

Measured memory_bytes: 21656
from heapq import heappush, heappop, heapify
N = int(input())
v = [int(i) for i in input().split()]
heapify(v)

while len(v) > 1:
  a = heappop(v)
  b = heappop(v)
  heappush(v,(a+b)/2)
print(heappop(v))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using i64 = long long;

i64 n, k;
constexpr i64 mod = 1000000007;
std::vector<std::deque<int>> g;

i64 dfs(int v, int p, i64 r) {
    if (r <= 0) return 0;
    i64 ret = r;
    i64 cr = v == 0 ? k - 1 : k - 2;
    for (int c : g[v]) {
        if (c == p) continue;
        ret = ret * dfs(c, v, cr--) % mod;
    }
    return ret;
}

int main() {
    std::cin >> n >> k;
    g.resize(n);
    for (int i = 1; i < n; i++) {
        int u, v;
        std::cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    std::cout << dfs(0, -1, k) << std::endl;

    return 0;
}


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

B = list(map(int, input().split()))

A_all = []
for i in range(N):
    A = list(map(int, input().split()))
    A_all.append(A)

count = 0
F = []
for i in range(N):
    formula = 0
    for j in range(M):
        formula = formula + A_all[i][j]*B[j]
    F.append(formula + C)
    if F[i] > 0:
        count += 1
print(count)


Measured memory_bytes: 3064
#![allow(non_snake_case, unused_macros, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap};

// Main
fn main(){
    input!{
        s: chars,
    }
    let n = s.len();
    let mut ai = 0;
    let mut zi = 0;
    for i in 0..n{
        if s[i]=='A'{
            ai = i;
            break;
        }
    }
    for i in 0..n{
        if s[n-1-i]=='Z'{
            zi = n-1-i;
            break;
        }
    }
    println!("{}", zi-ai+1);
}



Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		String line;
		while ((line = reader.readLine()) != null) {
			if (line.isEmpty()) {
				break;
			}
			String maru = getNum('o', line);
			String batu = getNum('x', line);
			if (check(maru)) {
				System.out.println("o");
			} else if (check(batu)) {
				System.out.println("x");
			} else {
				System.out.println("d");
			}
		}

	}

	private static boolean check(String a) {
		if (a.contains("123") || a.contains("456") || a.contains("789")) {
			return true;
		}
		if ((a.contains("1") && a.contains("5") && a.contains("9"))
				|| (a.contains("3") && a.contains("5") && a.contains("7"))) {
			return true;
		}
		char[] chs = new char[a.length()];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				chs[i * 3 + j] = a.charAt(j * 3 + i);
			}
		}
		String b = String.valueOf(chs);
		if (b.contains("147") || b.contains("258") || b.contains("369")) {
			return true;
		}
		

		return false;
	}

	private static String getNum(char a, String line) {
		char[] chs = line.toCharArray();
		for (int i = 0; i < chs.length; i++) {
			if (chs[i] == a) {
				chs[i] = (char) (i + 1 + '0');
			}
		}
		return String.valueOf(chs);
	}
}

Measured memory_bytes: 16872
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

using namespace std;



int main()

{
	int a,b,c;

	cin >>a>>b>>c;

	if ((a - b) == (b - c))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}


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

using namespace std;

int main() {

int n,k;
cin >> n;
cin >> k;
int x[101],count[101];
int ans = 0 ;

for(int i = 0;i < n;i++){
  cin >> x[i];
  count[i] = min(x[i],abs(k-x[i]));
ans += count[i];
}

cout << ans*2 <<endl;

}


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

int main() {
    int N;
    int t[110000],x[110000],y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;

    for(int i = 0; i < N; i++){
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }

    bool can = true;
    for(int i = 0; i < N; i++){
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if(dt < dist){
            can = false;
        }
        if(dist % 2 != dt % 2){
            can = false;
        }
    }
    cout << (can ? "Yes": "No") << endl;
}

Measured memory_bytes: 1408
N, A, B=map(int, input().split())
k=N//(A+B)
if N%(A+B)==0:
    print(k*A)
elif k*(A+B)+A<=N:
    print(k*A +A)
elif k*(A+B)+A>=N:
    print(k*A +N-k*(A+B))

Measured memory_bytes: 3064
N = int(input())
A = [int(x) for x in input().split(' ')]
B = [int(x) for x in input().split(' ')]
C = [int(x) for x in input().split(' ')]

ans = B[A[0]-1]
for i in range(1, N):
    ans += B[A[i]-1]
    if A[i-1] + 1 == A[i]:
        ans += C[A[i-1]-1]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6+20 , M = 4e6+20 , INF = 0x3f3f3f3f;
struct edge { int ver,val,next; } e[M*2];
int n,m,t=1,Head[N],vis[M],dis[N],cnt;
map < pair<int,int> , int > v;
inline void insert(int x,int y,int v)
{
    e[++t] = (edge){y,v,Head[x]} , Head[x] = t;
    e[++t] = (edge){x,v,Head[y]} , Head[y] = t;
}
inline int Hash(int x,int y)
{
    if ( v.count( make_pair(x,y) ) )
        return v[make_pair(x,y)];
    else return v[make_pair(x,y)] = ++cnt;
}
inline void input(void)
{
    scanf("%d%d",&n,&m); cnt = n;
    for (int i=1;i<=m;i++)
    {
        int x,y,v;
        scanf("%d%d%d",&x,&y,&v);
        int t1 = Hash(x,v) , t2 = Hash(y,v);
        insert( t1 , t2 , 0 );
        insert( x , t1 , 1 );
        insert( y , t2 , 1 );
    }
}
inline void Dijkstra(void)
{
    memset( dis , 0x3f , sizeof dis );
    memset( vis , 0x00 , sizeof vis );
    priority_queue < pair<int,int> > Heap;
    dis[1] = 0 , Heap.push( make_pair(0,1) );
    while ( !Heap.empty() )
    {
        int x = Heap.top().second; Heap.pop();
        if ( vis[x] ) continue; vis[x] = true;
        for (int i=Head[x];i;i=e[i].next)
        {
            int y = e[i].ver;
            if ( dis[y] > dis[x] + e[i].val )
                dis[y] = dis[x] + e[i].val ,
                Heap.push( make_pair( -dis[y] , y ) );
        }
    }
}
int main(void)
{
    input();
    Dijkstra();
    if ( dis[n] == INF ) puts("-1");
    else printf("%d\n",dis[n]/2);
    return 0;
}


Measured memory_bytes: 69372
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
		for(int i=0;i<b;i++)
		printf("%d",a);
	}
	else{
		for(int i=0;i<a;i++)
		printf("%d",b);
	}printf("\n");
	
	return 0;
}

Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

#include <queue>
//https://cpprefjp.github.io/reference/queue/priority_queue/pop.html
//std::priority_queue<ll> que;
//que.push(val);
//ll getv = que.top();
//que.pop();
typedef pair<string,ll> P;  
priority_queue<P,vector<P>, greater<P> > que;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;
map<string,ll> count_map;
/*
max 448,000,000
count_map['0']=0;
for(auto x : count_map) {
    string key = x.first;
    ll value = x.second;
}
*/

int main(){

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

    cin >> N;
 
    string S;
    ll PP;
    for( ll ni = 1 ; ni <=N ; ni++ ){
        cin >> S;
        cin >> PP;
        PP = PP * -1;
        string key = S + to_string(PP);
        que.push(P(S,PP));
        count_map[key]=ni;

    }
    for( ll ni = 1 ; ni <=N ; ni++ ){
        auto X = que.top();
        string key = X.first + to_string(X.second);
        cout << count_map[key] << endl;
        que.pop();

    }

}

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

int main()
{
		int r, c, i, j;
		cin >> r >> c;
		int X[r+1][c+1];
		for (i=0; i<r+1; i++) for (j=0; j<c+1; j++) X[i][j] = 0;
		for (i=0; i<r; i++) for (j=0; j<c; j++) cin >> X[i][j];
		for (i=0; i<r; i++) {
				for (j=0; j<c; j++) X[i][c] += X[i][j];
				for (j=0; j<c+1; j++) X[r][j] += X[i][j];
		}
		for (i=0; i<r+1; i++) {
				for (j=0; j<c+1; j++) {
						if (j==c) cout << X[i][j];
						else cout << X[i][j] << " ";
				}
				cout << endl;
		}
}

Measured memory_bytes: 3068
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int K = scan.nextInt();
        int X = scan.nextInt();
        if (X <= K * 500) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21332
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,c; 
    cin>>n>>c; 
    vector <vi> g(c+1,vi (c+1)), three(3,vi(c+1,0)); 
    for (int i=1;i<=c;i++){ 
    	for (int j=1;j<=c;j++){ 
    		cin >> g[i][j] ; 
    	}
    } 
    for (int i=1;i<=n;i++) { 
    	for (int j=1;j<=n;j++) { 
    		int x; cin>>x ; 
    		three[(i+j)%3LL][x]++ ; 
    	} 
    } 
    int ans = 1e9 ; 
    for (int i=1;i<=c;i++){
    	int a = 0 ; 
    	for (int cc=1;cc<=c;cc++ ){
    		if (cc == i) continue;
    		a += three[0][cc] * g[cc][i] ; 
    	}
    	for (int j=1;j<=c;j++) { 
    		int b = 0 ; 
    		if (i == j) continue ; 
    		for (int cc=1;cc<=c;cc++ ) { 
	    		if (cc == j) continue ; 
	    		b += three[1][cc] * g[cc][j]  ; 
	    	}
    		for (int k=1;k<=c;k++){
    			if (i == k or j == k) continue ; 
    			int t = 0 ; 
    			for (int cc=1;cc<=c;cc++ ) { 
		    		if (cc == k) continue ; 
		    		t += three[2][cc] * g[cc][k] ; 
		    	} 
    			ans = min(ans,a+b+t) ; 
    		}
    	}
    }
    co (ans) ; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3612
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Text;

namespace Atcoder
{
    class Program
    {
        private const long COMDIV = 1000000007;
        static void Main(string[] args)
        {
            var r = int.Parse(Console.ReadLine());
            Console.WriteLine(r * 2 * Math.PI);
        }
    }
}

Measured memory_bytes: 27572
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,y;cin>>n>>y;
  bool iscon=true;
  lvector ans{-1,-1,-1};
  for(ll i=0;i<=n;++i) {
    for(ll j=0;i+j<=n;++j) {
      if(y==10000*i+5000*j+1000*(n-i-j)) {
        ans={i,j,n-i-j};
        iscon=false;
      }
      if(!iscon) break;
    }
    if(!iscon) break;
  }
  rep(i,3) printf("%lld ",ans[i]);
  return 0;
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
using namespace std;

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

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

  int h, w;
  cin >> h >> w;
  vector<string> grid(h); // 実質vector<vector<char>>
  rep(i,h) cin >> grid[i];

  int res = -1;
  // 二重ループでスタート地点を全探索してBFS
  rep(sh, h) {
    rep(sw, w) {
      if(grid[sh][sw] == '#') continue; // 壁はスタートにしない
      queue<pair<int, int>> que; // pair<int, int>のqueueで座標を持つ
      vector<vector<int>> dist(h, vector<int> (w, -1)); // h * wのint型の二次元配列を-1で初期化(=未探索)
      dist[sh][sw] = 0;
      que.push({sh, sw});
      // BFS
      while(!que.empty()) {
        int vh = que.front().fi;
        int vw = que.front().se;
        que.pop();
        //四方向
        rep(dir, 4) {
          int nvh = vh + dy[dir];
          int nvw = vw + dx[dir];

          // いつもの範囲外をはじくやつ
          if(nvh < 0) continue;
          if(nvw < 0) continue;
          if(nvh >= h) continue;
          if(nvw >= w) continue;
          if(dist[nvh][nvw] != -1) continue;
          if(grid[nvh][nvw] == '#') continue;

          dist[nvh][nvw] = dist[vh][vw]+1;
          que.push({nvh, nvw});
        }
      }
    // 配列を縦に舐めて列ごとに*max_elementで更新
    rep(i, h) res = max(res, (int)*max_element(dist[i].begin(), dist[i].end()));
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    #h0,w0h1,w1 = map(int, input().split())
    s=input()
    while s!="0":
        print(sum(int(c) for c in s))
        s=input()

main()



Measured memory_bytes: 5616
import itertools
n,m = map(int,input().split())
M = [[0] * n for i in range(n)]

for i in range(m):
  a,b = map(int,input().split())
  M[a-1][b-1] = 1
couse = list(itertools.permutations(range(n)))
result = 0
#M = np.array(M)
for c in couse:
  con = 0
  if(c[0] == 0):
    for i in range(len(c)-1):
      if(M[c[i]][c[i+1]] == 1 or M[c[i+1]][c[i]] == 1):
        con += 1
        #print(c[i],c[i+1])
    if (len(c)-1 == con):
      result += 1
print(result)

Measured memory_bytes: 45296
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "DataStructure.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
typedef pair<int, int> p;
const int INF = 1000000000;
int main(){
	int n, W; cin >> n >> W;
	int dp[101][10001];
	int *v = new int[n];
	int *w = new int[n];
	for (int i = 0; i < n; i++)
		cin >> v[i] >> w[i];
	fill(dp[0], dp[n + 1], 0);
	for (int i = 0; i < n; i++)for (int j = 0; j <= W; j++) {
		if (w[i] > j)
			dp[i + 1][j] = dp[i][j];
		else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
	}
	cout << dp[n][W] << endl;
	delete[] v, w;
	return 0;
}

Measured memory_bytes: 7032
#include <bits/stdc++.h>
#include <math.h>
#include <cstdlib> //絶対値 abs()
using namespace std;


int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(a*b*c==175 && a+b+c==17){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}

}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int w,a,b,d,e;
	scanf("%d %d %d",&w,&a,&b);
	if(a<b){
		d=a+w;
		e=b-d;
		if(b<d){
			printf("0");
		}else{
		printf("%d",e);
	}
	}else if(a>b){
		d=b+w;
		e=a-d;
		if(a<d){
			printf("0");
		}else{
		printf("%d",e);
	}
	}else{
		printf("0");
	}
	return 0;
}

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

int main() {
  long double l; cin >> l;
  cout << fixed << setprecision(10) << l*l*l/27 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
typedef long long ll;
map<int, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string str;
	getline(cin, str);
	for (int i = 0; i < str.size(); i++) {
		if (str[i] >= 'a' && str[i] <= 'z') str[i] += 'A' - 'a';
		else if (str[i] >= 'A' && str[i] <= 'Z') str[i] += 'a' - 'A';
	}
	cout << str << endl;
	return 0;
}


Measured memory_bytes: 3160
# -*- coding: utf-8 -*-

import sys
import os
import math


N = int(input())
s_list = []
for i in range(N):
    s_list.append(input().strip())

alphabets = 'abcdefghijklmnopqrstuvwxyz'

for c in alphabets:
    min_count = float('inf')
    for s in s_list:
        count = s.count(c)

        if count < min_count:
            min_count = count
    print(c * min_count, end='')
print()


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>

using namespace std;

typedef long long ll;

//operation1 -> nodeのデータ同士の統合の演算
template <class Monoid> struct SegTree {
	int N;
	vector<Monoid> node;
	std::function<Monoid(Monoid, Monoid)> operation;
	Monoid unit;//単位元

	std::function<bool(Monoid, Monoid)> comp;
	Monoid not_find_sgn;

	SegTree(vector<Monoid>& data, std::function<Monoid(Monoid, Monoid)> op, Monoid U) {
		//データ　演算　単位元
		operation = op;
		unit = U;
		int size = data.size();
		N = 1;
		while (N < size)N <<= 1;
		node.resize(2 * N - 1, unit);

		for (int i = 0; i < size; i++) {
			node[i + N - 1] = data[i];
		}

		for (int i = N - 2; i >= 0; i--) {
			node[i] = operation(node[i * 2 + 1], node[i * 2 + 2]);
		}
	}

	SegTree() = default;

	void update(int pos, Monoid val) {
		pos += N - 1;
		node[pos] = val;
		while (pos > 0) {
			pos = (pos - 1) / 2;
			node[pos] = operation(node[pos * 2 + 1], node[pos * 2 + 2]);
		}
	}

	Monoid getval(int a, int b, int idx, int l, int r = -1) {
		//[a, b)を求める。　使い方はgetval(a, b, );
		if (r == -1)r = N;
		if (b <= l || r <= a)return unit;
		if (a <= l && r <= b)return node[idx];
		Monoid left = getval(a, b, idx * 2 + 1, l, (l + r) / 2);
		Monoid right = getval(a, b, idx * 2 + 2, (l + r) / 2, r);
		return operation(left, right);
	}

	Monoid getval(int a, int b) {
		//ラッパー。
		return getval(a, b, 0, 0, -1);
	}

};

int N;
string S;
ll cnt[2020];

ll modpow(ll a, ll b) {
	ll base = 1, kakeru = a;
	while (b > 0) {
		if (b & 1)base *= kakeru, base %= 2019;
		kakeru *= kakeru, kakeru %= 2019;
		b >>= 1;
	}
	return base;
}

int main() {
	cin >> S;
	N = S.size();

	reverse(S.begin(), S.end());

	ll ans = 0;

	vector<int> csum(N + 1);
	int times = 1;
	for (int i = 0; i < N; i++) {
		csum[i + 1] = csum[i];
		csum[i + 1] += (S[i] - '0') * times;
		csum[i + 1] %= 2019;
		(times *= 10) %= 2019;
	}

	cnt[0]++;
	for (int i = 0; i < N; i++) {
		ans += cnt[(csum[i + 1])];
		cnt[csum[i + 1]]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4344
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        cin >> B[i];
    }
    rep(i,N){
        cin >> C[i];
    }
    sort(all(A));
    sort(all(C));
    ll ans = 0;
    rep(i,N){
        ll up;
        ll bottom;
        if (A[N - 1] < B[i]) up = N;
        else if (A[0] >= B[i] ) up = 0;
        else{
            ll left = 0;
            ll right = N - 1;
            while(true){
                if (right - left == 1){
                    up = left + 1;
                    break;
                }
                else if (A[(right + left) / 2] >= B[i]){
                    right = (right + left) / 2;
                }
                else if (A[(right + left) / 2] < B[i]){
                    left = (right + left) / 2;
                }
            }
        }
        if (C[0] > B[i]) bottom = N;
        else if (C[N - 1] <= B[i]) bottom = 0;
        else{
            ll left = 0;
            ll right = N - 1;
            while(true){
                if (right - left == 1){
                    bottom = N - right;
                    break;
                }
                else if (C[(right + left) / 2] <= B[i]){
                    left = (right + left) / 2;
                }
                else if (C[(right + left) / 2] > B[i]){
                    right = (right + left) / 2;
                }
            }
        }
        ans += up * bottom;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
import math,cmath
e=1e-6
def f(m):
  c=1j*math.acos(a/2)
  p1=cmath.exp(b+c)+p
  p2=cmath.exp(b-c)+p
  s1,s2=2,2
  for k in N:
    if k in[i,i1]:continue
    if abs(X[k]-p1)<1+e:s1+=1
    if abs(X[k]-p2)<1+e:s2+=1
  return max(m,s1,s2)

while 1:
  n=input()
  if n==0:break
  N=range(n)
  X=[]
  for i in N:
    x,y=map(float,input())
    X+=[x+1j*y]
  m=1
  for i in N:
    p=X[i]
    for i1 in range(i+1,n):
      a,b=cmath.polar(X[i1]-p)
      b*=1j
      if a<=2:m=f(m)
  print m

Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll) 1000000007
#define P pair<ll, ll>

ll n, a, b, c, d;
string s;
int main() {
	cin >> n >> a >> b >> c >> d;
	a--;
	b--;
	c--;
	d--;
	cin >> s;
	FOR(i, a, c) {
		if (s[i] == '#' and s[i + 1] == '#') {
			cout << "No" << endl;
			return 0;
		}
	}
	FOR(i, b, d) {
		if (s[i] == '#' and s[i + 1] == '#') {
			cout << "No" << endl;
			return 0;
		}
	}
	if (c > d) {
		FOR(i, b, d + 1) {
			if (s[i - 1] == '.' and s[i + 1] == '.' and s[i] == '.') {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	else {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define pb push_back
#define N 1000500
typedef long long int ll;
using namespace std;
int main(void){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	fast;
	int i;
	string s;
	cin>>s;
	int n=s.length();
	ll dp[n+1][2];
	memset(dp,0,sizeof dp);
	//dp[1][0]=s[0]-'0';
	//dp[1][1]=10-(s[0]-'0');
	dp[0][1]=1;
	for(i=0;i<n;i++){
		int k=s[i]-'0';
		dp[i+1][0]=min(dp[i][0]+k,dp[i][1]+10-k);
		dp[i+1][1]=min(dp[i][0]+k+1,dp[i][1]+10-k-1);
	}
	cout<<dp[n][0]<<endl;
}


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

int cnt[10][10];

int main()
{
  int n;
  cin >> n;
  
  for(int i = 1; i <= n; i++)
  {
    string s = to_string(i);
    cnt[s[0]-'0'][s.back()-'0']++;
  }
  
  int res = 0;
  rep(i,10) rep(j,10)
  {
    res += cnt[i][j] * cnt[j][i];
  }
  cout << res << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main() {
    int unused __attribute__((unused));

    char s[3];
    scanf("%s", s);
    int cnt=0;
    if(s[0]=='1'){
        cnt+=1;
    }
    if (s[1] == '1') {
        cnt += 1;
    }
    if (s[2] == '1') {
        cnt += 1;
    }
    printf("%d",cnt);
    
    return 0;

}


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

int n;
int w, h;
int sw, sh;
int cnt[100][100];

int getCount(int sy, int sx) {
	int ret = 0;
	for (int i = 0; i < sh; i++) {
		for (int j = 0; j < sw; j++) {
			int y = sy + i;
			int x = sx + j;
			if (y >= h || x >= w) return 0;
			ret += cnt[y][x];
		}
	}
	return ret;
}

int main() {
	while (cin >> n) {
		if (!n) break;
		cin >> w >> h;
		
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cnt[i][j] = 0;
			}
		}
		
		for (int i = 0; i < n; i++) {
			int x, y;
			cin >> x >> y;
			x--; y--;
			cnt[y][x]++;
		}
		cin >> sw >> sh;
		
		int ans = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				ans = max(ans, getCount(i, j));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<string> vec(n);
	vector<long long> ans(5, 0);
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
		if(vec[i][0]=='M')ans[0]++;
		if(vec[i][0]=='A')ans[1]++;
		if(vec[i][0]=='R')ans[2]++;
		if(vec[i][0]=='C')ans[3]++;
		if(vec[i][0]=='H')ans[4]++;
	}
	long long res = 0;
	for(int i = 0; i < 5; ++i){
		for(int j = i + 1; j < 5; ++j){
			for(int k = j + 1; k < 5; ++k){
				res += ans[i] * ans[j] * ans[k];
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 6144
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

*/
/*#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <string>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <assert.h>*/

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (ll x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e3 + 6;

ll A, B;

bool bit(ll mask, ll i) {
    return ((mask >> i) & 1);
}

int main() {
	ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //freopen("in", "r", stdin);

    cin >> A >> B;
    if (A == B) {
        cout << "1\n";
        return 0;
    }

    ll r = 0;
    forn(i, 1, 61) {
        if (bit(A, i) != bit(B, i)) r = i;
    }
    forn(i, r + 1, 61) {
        if (bit(A, i)) A = (A ^ (1ll << i));
        if (bit(B, i)) B = (B ^ (1ll << i));
    }
    ll k = -1;
    forn(i, 0, 61) {
        if ((1ll << r) + (1ll << i) <= B) k = i;
        else break;
    }

    ++k;
    ll ans = (1ll << r) - A;
    PLL a = PLL((1ll << r), (1ll << r) + (1ll << k) - 1);
    PLL b = PLL((1ll << r) + A, 2ll * (1ll << r) - 1);
    
    if (a.S < b.F) ans += a.S - a.F + 1 + b.S - b.F + 1;
    else ans += max(b.S, a.S) - a.F + 1;
    
    cout << ans << "\n";

    return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	ll N, K, ans=0;
	ll t[100005], d[100005];

	cin >> N >> K;
	rep(i,N) cin >> t[i] >> d[i];

	vector<pll> st;
	rep(i,N) st.emplace_back(d[i], t[i]);
	sort(all(st));

	ll count = 0, sum = 0;
	set<int> used;
	vector<ll> sec;
	rep(i,N){
		auto p = st.back();
		if( count++ < K ){
			if( used.count(p.Y) ){
				sec.push_back(p.X);
			}
			used.insert(p.Y);
			sum += p.X;
		}else if( sec.size() && !used.count(p.Y) ){
			sum -= sec.back();
			sec.pop_back();
			used.insert(p.Y);
			sum += p.X;
		}
		chmax(ans, sum + (ll)used.size() * (ll)used.size());
		st.pop_back();
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6768