akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n)    FOR(i, 0, n)
#define pb           push_back
#define all(a)       (a).begin(), (a).end()
#define UNIQUE(v)    v.erase(unique(all(v)), v.end());
#define fill(a, x)   memset(a, x, sizeof(a))
#define zero(a)      fill(a, 0)
#define minus(a)     fill(a, -1)
#define dbg(x)       cout << #x "=" << x << endl
#define MAX          200000
#define SENTINEL     2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];

ll merge(int A[], int n, int left, int mid, int right) {
  int i, j, k;
  ll cntC = 0;
  int n1 = mid - left;
  int n2 = right - mid;

  for (i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }

  for (i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }

  L[n1] = R[n2] = SENTINEL;
  i = j = 0;

  for (k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
      cntC += n1 - i;
    }
  }
  return cntC;
}

ll mergeSort(int A[], int n, int left, int right) {
  int mid;
  ll v1, v2, v3;

  if (left + 1 < right) {
    mid = (left + right) / 2;
    v1 = mergeSort(A, n, left, mid);
    v2 = mergeSort(A, n, mid, right);
    v3 = merge(A, n, left, mid, right);
    return v1 + v2 + v3;
  } else {
    return 0;
  }
}

int main() {
  int A[MAX], n, i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> A[i];
  }
  ll ans = mergeSort(A, n, 0, n);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 4644
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int total_friends;
  int total_games;
  while(~scanf("%d",&total_friends)){
    scanf("%d",&total_games);
    int targets[101] = {};
    int scores[101] = {};
    for(int game_i = 0; game_i < total_games; game_i++){
      scanf("%d",targets + game_i);
      targets[game_i]--;
    }
    for(int game_i = 0; game_i < total_games; game_i++){
      int to[101] = {};
      for(int friend_i = 0; friend_i < total_friends; friend_i++){
        scanf("%d",to + friend_i);
        to[friend_i]--;
        if(to[friend_i] != targets[game_i]){
          scores[targets[game_i]]++;
        }
        else {
          scores[friend_i]++;
        }
      }
    }
    for(int friend_i = 0; friend_i < total_friends; friend_i++){
      printf("%d\n",scores[friend_i]);
    }
  }
}

Measured memory_bytes: 1192
n = int(input())
txy = [list(map(int,input().split())) for _ in range(n)]

flag = True
txy.insert(0,[0,0,0])
for i in range(n):
    t = txy[i+1][0] - txy[i][0]
    d = abs(txy[i+1][1] - txy[i][1]) + abs(txy[i+1][2]-txy[i][2])
    if t < d:
        flag = False
    elif t == d:
        continue
    elif (t-d) % 2 != 0:
        flag = False

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 60376
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int a = kb.nextInt();
		int b = kb.nextInt();
		int c = kb.nextInt();
		int k = kb.nextInt();
		int count = 0;
		if (k <= a) {
			count += k;
		} else {
			count += a;
			k -= a;
			if (k <= b) {
			} else {
				k -= b;
				if (k <= c) {
					count -= k;
				} else {
					count -= c;
					k -= c;
				}
			}
		}

		System.out.println(count);
		kb.close();
	}
}


Measured memory_bytes: 26952
#include<stdio.h>

int T=1,m[101][101],d[101]={0},a[101],b[101],n;
void visit(int u){
  int v; 
  a[u]=T++;
  d[u]=1;
  for(v=0;v<n;v++){
    if(m[u][v]==1&&d[v]==0){ 
      visit(v);
    }
  }   
  b[u]=T++;  
}

#include<stdio.h>
int main(){
  int k,i,j,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      m[i][j]=0;
 for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
       m[u-1][v-1]=1;      
   }
 }
 for(i=0;i<n;i++)
   if(d[i]==0) visit(i);
 for(i=0;i<n;i++)
   printf("%d %d %d\n",i+1,a[i],b[i]);
 return 0;
}


Measured memory_bytes: 2088
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	if (s[0]==t[2] && s[2]==t[0] && s[1]==t[1]){
		cout<<"YES"<<endl;
	}
	else {
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String[] v = in.next().split(",");
            for (String x : v) out.print(x + " ");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 23252
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	h, w := intScanner(), intScanner()
	s := make([]string, h)
	for i := 0; i < h; i++ {
		s[i] = Scanner()
	}
	u := newUnionFind(h * w)
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if i+1 < h {
				if s[i][j] != s[i+1][j] {
					u.unite(i*w+j, i*w+j+w)
				}
			}
			if i-1 >= 0 {
				if s[i][j] != s[i-1][j] {
					u.unite(i*w+j, i*w+j-w)
				}
			}
			if j+1 < w {
				if s[i][j] != s[i][j+1] {
					u.unite(i*w+j, i*w+j+1)
				}
			}
			if j-1 >= 0 {
				if s[i][j] != s[i][j-1] {
					u.unite(i*w+j, i*w+j-1)
				}
			}
		}
	}
	bs := make(map[int]int)
	ws := make(map[int]int)
	for i := 0; i < h*w; i++ {
		if string(s[i/w][i%w]) == "#" {
			bs[u.root(i)]++
		} else {
			ws[u.root(i)]++
		}
	}
	ans := 0
	for k, v := range bs {
		ans += ws[k] * v
	}
	fmt.Println(ans)
}

type UnionFind struct {
	par []int
}

func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.par = make([]int, N)
	for i := range u.par {
		u.par[i] = -1
	}
	return u
}
func (u UnionFind) root(x int) int {
	if u.par[x] < 0 {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}
func (u UnionFind) unite(x, y int) {
	xr := u.root(x)
	yr := u.root(y)
	if xr == yr {
		return
	}
	u.par[yr] += u.par[xr]
	u.par[xr] = yr
}
func (u UnionFind) same(x, y int) bool {
	if u.root(x) == u.root(y) {
		return true
	}
	return false
}
func (u UnionFind) size(x int) int {
	return -u.par[u.root(x)]
}


Measured memory_bytes: 12800
import java.util.*;
import static java.lang.System.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		D(sc);
	}
	
	public static void A(Scanner sc) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();
		int ret = ((int)(t+0.5)/a)*b;
		out.println(ret);
	}
	
	public static void B(Scanner sc) {
		int max = Integer.MIN_VALUE;
		int sum = 0;
		int N = sc.nextInt();
		int[] subs = new int[N];
		for(int i=0;i<N;i++) {
			subs[i] = sc.nextInt();
 		}
		for(int i=0;i<N;i++) {
			subs[i] -= sc.nextInt();
			if(subs[i]>0) sum+=subs[i];
		}
		out.println(sum);
		
	}
	
	public static void D(Scanner sc) {
		int N = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int count=0;
		long sum = 0;
		for(int i=0;i<N;i++) {
			int n = sc.nextInt();
			if(n<0) count++;
			if(Math.abs(n)<min) min = Math.abs(n);
			sum += Math.abs(n);
		}
		if(count%2==1) sum-=min*2;
		out.println(sum);
	}
}


Measured memory_bytes: 48716
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
      
        int ans = 1;
        
        for (int i = 0; i < n; i++) {
            ans *= i == 0 ? k : k -1;
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define INF ((1LL<<62)-(1LL<<31))
#define min(p,q)((p)<(q)?(p):(q))

#define VCNT (500*50*2)
#define ECNT (5000*50*2*2)
int a,b,c;
int n,m;
int x[5010],y[5010],t[5010];
int v;

typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[ECNT+10];//適宜変える(ecnt)
//	int inv[200010];//逆辺のindex(ecnt)
	int id[VCNT+10];//適宜変える(vcnt)
}G;
G g;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}
//int csort(const void*a,const void*b){ll p=(*(E*)a).c,q=(*(E*)b).c;return p<q?-1:p>q?1:0;}
//void makeinvedge();
void readgraph(){
	//適宜変える

	int ecnt=0;
	rep(i,0,m){
		rep(k,0,c){
			rep(f,0,2){
				g.e[ecnt].s=(x[i]*c+k)*2+f;
				g.e[ecnt].g=(y[i]*c+(a*k+b)%c)*2+(f||y[i]==n-1);
				g.e[ecnt].c=t[i]*k;
				ecnt++;
				g.e[ecnt].s=(y[i]*c+k)*2+f;
				g.e[ecnt].g=(x[i]*c+(a*k+b)%c)*2+(f||x[i]==n-1);
				g.e[ecnt].c=t[i]*k;
				ecnt++;
			}
		}
	}
	g.vcnt=n*c*2;
	g.ecnt=ecnt;
	qsort(g.e,g.ecnt,sizeof(E),esort);
//	qsort(g.e,g.ecnt,sizeof(E),csort);
//	makeinvedge();

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}


//プラキュー（二分ヒープ）（優先度変更ありバージョン）
ll heapN,heap[VCNT+10],heapinv[VCNT+10];
int PQhikaku(int i,int j);//jの方が優先度が高いならtrueを返す
void PQchange(int n);
void heap_utod(int n){
	if(2*n>heapN)return;
	int rflag=(2*n+1<=heapN)&&(PQhikaku(2*n,2*n+1));
	if(PQhikaku(n,2*n+rflag)){
		ll temp=heap[2*n+rflag];
		heap[2*n+rflag]=heap[n];
		heap[n]=temp;
		heapinv[heap[n]]=n;
		heapinv[heap[2*n+rflag]]=2*n+rflag;	
		heap_utod(2*n+rflag);
	}
}
void heap_dtou(int n){
	if(n==1||PQhikaku(n,n/2))return;
	ll temp=heap[n];
	heap[n]=heap[n/2];
	heap[n/2]=temp;
	heapinv[heap[n]]=n;
	heapinv[heap[n/2]]=n/2;
	heap_dtou(n/2);
}
ll PQpop(){
	ll rr=heap[1];
	heapinv[heap[1]]=0;
	heap[1]=heap[heapN--];
	heapinv[heap[1]]=1;
	heap_utod(1);
	return rr;
}
void PQpush(ll n){
	heap[++heapN]=n;
	heapinv[heap[heapN]]=heapN;
	heap_dtou(heapN);
}

//早い方のダイクストラ
//グラフと始点を引いて各点への最短距離・最短経路を返す
//プラキューが必要
//O((E+V)logV)
ll daikusutorappp[VCNT+10];
void daikusutora2(ll s){
	rep(i,0,g.vcnt)daikusutorappp[i]=i==s?0:INF;
	rep(i,0,g.vcnt)PQpush(i);
	while(heapN){
		ll mv=PQpop();
		for(ll t=g.id[mv];t<g.ecnt&&g.e[t].s==mv;t++){
			if(daikusutorappp[g.e[t].g]>daikusutorappp[mv]+g.e[t].c){
				daikusutorappp[g.e[t].g]=daikusutorappp[mv]+g.e[t].c;
				//daikusutorappp[n+g.e[t].g]=mv;//最短経路がいる場合はこれ
				PQchange(g.e[t].g);
			}
		}
	}
}
int PQhikaku(int i,int j){return daikusutorappp[heap[i]]>daikusutorappp[heap[j]];}
void PQchange(int n){if(heapinv[n])heap_dtou(heapinv[n]);}

int main(){
	scanf("%d%d",&n,&m);
	rep(i,0,m){
		scanf("%d%d%d",x+i,y+i,t+i);
		x[i]--,y[i]--;
	}
	scanf("%d%d%d%d",&v,&a,&b,&c);
	readgraph();

	daikusutora2((0*c+v)*2+0);
	ll ans=INF;
	rep(i,0,c)ans=min(ans,daikusutorappp[(0*c+i)*2+1]);
	printf("%lld\n",ans);
}


Measured memory_bytes: 47820
#include<bits/stdc++.h>
#define P pair<int,int>
#define int long long
using namespace std;

int a[100000];
signed main() {
	int b; cin >> b;
	priority_queue<P>Q;
	for (int c = 0; c < b; c++) {
		int d; scanf("%lld", &d);
		Q.push(P(d, c));
	}
	int MIN = LLONG_MAX/3;
	int sum = 0;
	Q.push(P(0, 0));
	while (Q.size() != 1) {
		sum++;
		P n = Q.top(); Q.pop();
		P m = Q.top();
		MIN = min(MIN, n.second);
		a[MIN] += sum*(n.first - m.first);
	}
	for (int i = 0; i < b; i++) {
		printf("%lld\n", a[i]);
	}
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
template<class T> inline bool chmax(T& a, T b){if(a<b) {a=b; return 1;} return 0; }
template<class T> inline bool chmin(T& a, T b){if(a>b) {a=b; return 1;} return 0; }
const long long INF = 1LL << 60;

ll N;
ll a[100010][3];
ll dp[100010][3];
int main(){
	cin>>N;
	REP(i,N)REP(j,3) cin>>a[i][j];
	REP(i,N){
		REP(j,3){
			REP(k,3){
				if(j==k)continue;
				chmax(dp[i+1][k],dp[i][j]+a[i][k]);
			}
		}
	}
  
	ll ans=0;
	REP(i,3) chmax(ans,dp[N][i]);
	cout<<ans<<endl;

}

Measured memory_bytes: 4992
A = list(map(int, input().split()))

if A[0] == A[1] != A[2]:
    print("Yes")
    exit()

if A[1] == A[2] != A[0]:
    print("Yes")
    exit()

if A[2] == A[0] != A[1]:
    print("Yes")
    exit()

print("No")

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

struct C {
  i64 x, y, r;
};
double abs2(C c, C d) {
  return (c.x - d.x) * (c.x - d.x) + (c.y - d.y) * (c.y - d.y);
}
signed main() {
  while (true) {
    i64 n;
    cin >> n;
    if (n == 0) break;
    i64 sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    vector<C> cands;
    vector<C> rat;
    rat.push_back({sx, sy, 0});
    vector<C> cat;
    cat.push_back({tx, ty, 0});
    REP(_, n) {
      i64 x, y, r;
      cin >> x >> y >> r;
      bool s = (x - sx) * (x - sx) + (y - sy) * (y - sy) <= r * r;
      bool t = (x - tx) * (x - tx) + (y - ty) * (y - ty) <= r * r;
      if (s && !t) {
        rat.push_back({x, y, r});
      }
      if (!s && t) {
        cat.push_back({x, y, r});
      }
    }
    sort(rat.begin(), rat.end(), COMP(r));
    sort(cat.begin(), cat.end(), COMP(r));
    queue<i64> que;
    vector<i64> drat(rat.size());
    que.push(0);
    while (que.size()) {
      i64 i = que.front();
      que.pop();
      C c = rat[i];
      FOR(j, i + 1, rat.size()) {
        C d = rat[j];
        if (abs2(c, d) < (d.r - c.r) * (d.r - c.r)) {
          if (drat[j] < drat[i] + 1) {
            drat[j] = drat[i] + 1;
            que.push(j);
          }
        }
      }
    }
    vector<i64> dcat(cat.size());
    que.push(0);
    while (que.size()) {
      i64 i = que.front();
      que.pop();
      C c = cat[i];
      FOR(j, i + 1, cat.size()) {
        C d = cat[j];
        if (abs2(c, d) < (d.r - c.r) * (d.r - c.r)) {
          if (dcat[j] < dcat[i] + 1) {
            dcat[j] = dcat[i] + 1;
            que.push(j);
          }
        }
      }
    }
    i64 ans = 0;
    REP(i, drat.size()) {
      REP(j, dcat.size()) {
        C r = rat[i];
        C c = cat[j];
        if (abs2(r, c) > (r.r + c.r) * (r.r + c.r)) {
          ans = max(ans, drat[i] + dcat[j]);
        }
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 7000
#include<iostream>
#include<vector>
#include<cassert>
#include<cstdio>
#include<map>
#include<algorithm>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
typedef pair<int,int> Pox;//役、得点: 0->ワンペア 1->２ペア 2-> ３カード 3->ストレート , 4->フラッシュ, 5->フルハウス, 6-> フォーカード, 7->ストレートフラッシュ, 8->ロイヤルストレートフラッシュ
struct P
{
  int v;
  char c;
  P(int v=-1,char c='$'):v(v),c(c){}
  bool operator < (const P &a)const
  {
    if(v != a.v)return v < a.v;
    return c < a.c;
  }
};

int S[15],C[15],H[15],D[15],ATK[15];

int main()
{
  int n;
  bool f = true;
  while(cin >> n)
    {  
      if(f)f = false;
      else cout << endl;
      rep(i,13)cin >> S[i];
      rep(i,13)cin >> C[i];
      rep(i,13)cin >> H[i];
      rep(i,13)cin >> D[i];
      rep(i,9)cin >> ATK[i];
    
      rep(F,n)
	{
	  vector<Pox> ans;
	  bool suit = true;
	  vector<P> vec(5);
	  int point = 0;
	  int RSF = 0;
	  map<int,int> index;
	  vector<int> value;

	  rep(i,5)
	    {
	      char a,b,dummy;
	      int A;
	      string s;
	      cin >> s;
	      a = s[0];
	      b = s[1];
	      if('2' <= a && a <= '9')A = a-'0';
	      else if(a == 'A')A = 1;
	      else if(a == 'T')A = 10;
	      else if(a == 'J')A = 11;
	      else if(a == 'Q')A = 12;
	      else if(a == 'K')A = 13;
	      else assert(false);
	      vec[i].v = A;
	      vec[i].c = b;
	      value.push_back(A);
	      if(i && vec[i].c != vec[i-1].c)suit = false;

	      if(b == 'S')point += S[vec[i].v-1];
	      else if(b == 'C')point += C[vec[i].v-1];
	      else if(b == 'H')point += H[vec[i].v-1];
	      else if(b == 'D')point += D[vec[i].v-1];
	      if(vec[i].v == 1 || (10 <= vec[i].v && vec[i].v <= 13))RSF = RSF|(1<<vec[i].v);
	      index[vec[i].v]++;
	    }


	  if(__builtin_popcount(RSF) == 5 && suit)
	    {
	      cout << point*ATK[8] << endl;
	      continue;
	    }

	  sort(value.begin(),value.end());
	  bool RB = true;
	  REP(i,1,value.size())
	    if(value[i] != value[i-1]+1)
	      {
		RB = false;
		break;
	      }

	  if(RB && suit)
	    {
	      cout << point*ATK[7] << endl;
	      continue;
	    }

	  bool four = false;
	  for(map<int,int>::iterator it = index.begin();it != index.end();it++)
	    if(it->second == 2 || it->second == 3)break;
	    else if(it->second == 4)
	      {
		four = true;
		break;
	      }

	  if(four)
	    {
	      cout << point*ATK[6] << endl;
	      continue;
	    }

	  int one=0,three=0;
	  for(map<int,int>::iterator it = index.begin();it != index.end();it++)
	    {
	      if(it->second == 2)one++;
	      else if(it->second == 3)three++;
	    }

	  if(one == 1 && three == 1)
	    {
	      cout << point*ATK[5] << endl;
	      continue;
	    }	 

	  if(suit)
	    {
	      cout << point*ATK[4] << endl;
	      continue;
	    }

	  if(RB || __builtin_popcount(RSF) == 5)
	    {
	      cout << point*ATK[3] << endl;
	      continue;
	    }

	  if(three == 1)
	    {
	      cout<< point*ATK[2] << endl;
	      continue;
	    }

	  if(one == 2)
	    {
	      cout << point*ATK[1] << endl;
	      continue;
	    }

	  if(one == 1)
	    {
	      cout << point*ATK[0] << endl;
	      continue;
	    }
	  cout << 0 << endl;
	}

    }
  return 0;
}

Measured memory_bytes: 1232
/* kadai4_3
   reo012 */

#include<stdio.h>

int sum(int max_num);

int main(void){
    // 雪上何メートルか取得。
    int above_a, above_b, height_a, gap;
    scanf("%d %d", &above_a, &above_b);
    // 高さa,bの差の数は、東側の塔が何番目と同じ。
    gap = above_b - above_a;
    // 西側の塔はgap-1番目で、その塔の高さを計算。
    height_a = sum(gap-1);
    // 積雪は塔の高さ-雪上の高さ
    printf("%d\n", height_a-above_a);
    return 0;
}

// 1からmax_numの和を求める関数を定義。
int sum(int max_num){
    int total=0, i;
    // iを1からmax_numまで動かし、totalに足していく。
    for(i=1; i<=max_num; i++){
        total+=i;
    }
    return total;
}


Measured memory_bytes: 128
#include<iostream>


using namespace std;

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

    if(A+B>C+D){
        cout << "Left"<<endl;
    }
    else if(A+B==C+D){
        cout <<"Balanced"<<endl;
    }
    else{
        cout <<"Right"<<endl;
    }
}


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

int main() {
  long a,b,c,k,x=0;
  cin >> a >> b >> c >> k;
  while(a>=b) b*=2,x++;
  while(b>=c) c*=2,x++;
  if(x<=k) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;



int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
    cout << min(a, min(b, c)) + min(d, e) - 50 << endl;
	return 0;
}


Measured memory_bytes: 3140
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

h1,m1,h2,m2,k=l_in()
print(h2*60+m2-k-h1*60-m1)



Measured memory_bytes: 61652
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1

bool solve() {
  int N;
  cin >> N;
  vector<i64> as(N);
  F0R(i, N) {
    cin >> as[i];
  }
  string S;
  cin >> S;

  while (S.front() == '0') {
    S.erase(S.begin());
    as.erase(as.begin());
    N--;
  }

  // 人1が1回しか行動できないと仮定し、
  // Siが1のときの全てのAiに対し、それ以降に人0が0に出来るか？を求めれば多分OK

  vector<i64> bs;
  RF0(i, N) {

    if (S[i] == '1') {
      sort(rrng(bs));
      int rank = 0;
      RF0(j, 63) {
        if (rank >= bs.size()) break;
        if (!((bs[rank] >> j)&1)) continue;
        F0R(k, bs.size()) {
          if (k == rank) continue;
          if (!((bs[k] >> j) & 1)) continue;
          bs[k] ^= bs[rank];
        }
        rank++;
        sort(rrng(bs));
      }

      i64 n = 0;
      int bi = 0;
      RF0(j, 63) {
        if (!(((as[i] ^ n) >> j) & 1)) continue;
        while (bi < bs.size() && !((bs[bi] >> j) & 1)) bi++;
        if (bi >= bs.size()) break;

        n ^= bs[bi++];
        if (n == as[i]) break;
      }

      if (n != as[i]) return false;
    }
    else {
      bs.push_back(as[i]);
    }
  }
  return true;
}


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int T;
  cin >> T;
  F0R(i, T) {
    cout << (solve() ? 0: 1) << newl;
  }
}
#endif


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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

    int ans = 0;
    for (int i = 1; i <= n; i+=2)
    {
        int count = 0;
        for (int j = 1; j <= i; j++)
        {
            if (i % j == 0)
            {
                count++;
            }
        }

        if (count == 8)
        {
            ans++;
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 384
n=int(input())
counter=[[0 for i in range(9)] for _ in range(9)]


for i in range(1,n+1):
	tmp=str(i)
	f=int(tmp[0])
	l=int(tmp[-1])
	if l != 0:
		counter[f-1][l-1]=counter[f-1][l-1]+1


output=0
for i in range(9):
	for j in range(9):
		output+=counter[i][j]*counter[j][i]

print(output)


Measured memory_bytes: 3064
// 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  int n;
  cin >> n;
  if(n < 1000){
    cout << "ABC" << endl;
  }else{
    cout << "ABD" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int a, b, c;
  cin >> a >> b >> c;
  int m = max(a, max(b, c));
  cout << a+b+c-m << 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 k = sc.nextInt();
    int d = Math.max(a, b);
    d = Math.max(d, c);
    int e = d;
    for (int i = 0; i < k; i++) {
      d *= 2;
    }
    System.out.println(a + b + c + d - e);
  }
}

Measured memory_bytes: 25172
def merge_jibun(A, left, mid, right):
    L = A[left:mid] + [1000000]
    R = A[mid:right] + [1000000]
    # L.append(1000000)
    # R.append(1000000)

    i = 0
    j = 0
    global count
    
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def merge_hoka(A, left, mid, right):
    global count
    inf = 10 ** 9
    L = A[left:mid] + [inf]
    R = A[mid:right] + [inf]
 
    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        # print(L)
        # print(R)
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        # merge_jibun(A, left, mid, right)
        merge_hoka(A, left, mid, right)

n = int(input())
A = list(map(int, input().split()))
count = 0
mergeSort(A, 0, n)

print(' '.join(list(map(str, A))))
print(count)


Measured memory_bytes: 66776
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
LL MOD = 1000000007;
LL fact[1000001];
LL inv_fact[1000001];
LL comb(LL n, LL k) {
	if (n < k) return 0;
	LL ret = fact[n];
	(ret *= inv_fact[k]) %= MOD;
	(ret *= inv_fact[n - k]) %= MOD;
	return ret;
}
LL mod_pow(LL a, LL b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		LL x = mod_pow(a, b / 2);
		return (x*x) % MOD;
	}
	return (mod_pow(a, b - 1)*a) % MOD;
}
int main() {
	int N;
	cin >> N;
	fact[0] = inv_fact[0] = 1;
	for (int i = 1; i <= N; i++) {
		fact[i] = fact[i - 1];
		(fact[i] *= i) %= MOD;
		inv_fact[i] = inv_fact[i - 1];
		(inv_fact[i] *= mod_pow(i, MOD - 2)) %= MOD;
	}
	LL ans = 0;
	LL prev = 0;
	LL now = 0;
	for (int i = 1; i <= N - 1; i++) {
		LL ret = comb(i - 1, N - 1 - i);
		(ret *= fact[i]) %= MOD;
		(ret *= fact[N - 1 - i]) %= MOD;
		now = ret;
		ret = (ret - prev + MOD) % MOD;
		(ret *= i) %= MOD;
		(ans += ret) %= MOD;
		prev = now;
	}
	cout << ans << endl;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define int long long
#define sz(x) (ll)(x.size())
using namespace std;


const int mod = 1e9+7;

int expo_pow(int x,int y){
 if(y == 0) return 1;
  y=y%(mod-1);
  x%=mod;
  if(y==0) y=mod-1;
  int res=1;
  while(y){
    if(y&1) res=(res*x)%mod;
    x=(x*x)%mod;
    y>>=1; 
  }
  return res;
}

ll add()
{
    return 0;
}

template <typename T, typename... Types>
T add(T var1, Types... var2){
    return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod;
}

ll mul(){
    return 1;
}

template <typename T, typename... Types>
T mul(T var1, Types... var2){
    return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod;
}

void solve(){
  int a[2],b[2];
  cin >> a[0] >> a[1];
  cin >> b[0] >> b[1];
  int ans = -1e18;
  for (int i = 0 ; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
      int pro = a[i]*b[j];
      ans = max(ans,pro);
    }
  }
  cout << ans << "\n";
}


signed main(){
  fast;
  int test = 1;
  int i=1;
  while(test--){
    solve();
  }
}





Measured memory_bytes: 3648
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n=in();
  vi a(n); vi b(n); vi c(n-1);
  rep(i,n) cin >> a[i];
  rep(i,n) cin>>b[i];
  rep(i,n-1) cin>>c[i];
  int ret = 0;
  rep(i,n){
    ret += b[a[i]-1];
    dump(ret, a[i], a[i-1]);
    if(i>0 && a[i]-a[i-1]==1) ret += c[a[i-1]-1];
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF INT_MIN 
#define INF INT_MAX 
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 
//int root(int x){return x==f[x]?x:f[x]=root(f[x]);}


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{
 int a,b,m;
 cin>>a>>b>>m;
 VI ar(a),br(b);
 int ans=INF;
 for(int i=0;i<a;i++)cin>>ar[i];
 for(int i=0;i<b;i++)cin>>br[i];
 
 for(int i=0;i<m;i++)
 {
     int x,y,z;
     cin>>x>>y>>z;
     ans=min(ans,ar[x-1]+br[y-1]-z);
 }
 sort(all(ar));sort(all(br));
 ans=min(ans,ar[0]+br[0]);
 cout<<ans<<endl;
}


return 0;
}





Measured memory_bytes: 1792
import math
while True:
    n = int(input())
    if n==0:
        break
    x = list(map(int,input().split()))

    average = sum(x)/n

    stdev = 0
    for i in range(n):
        stdev+=(x[i]-average)**2
        
    stdev/=n
    print(math.sqrt(stdev))


Measured memory_bytes: 5704
#include<bits/stdc++.h>
using namespace std;
using Int = long long;



int main(){
    Int n,k;
    cin>>n>>k;
    vector<Int> h(n);

    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    Int ans = 1E9;
    for(Int i=0;i+k-1<n;i++){
        ans=min(ans,h[i+k-1]-h[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
n,k = map(int,input().split())
*l, = map(int,input().split())
seenl = [1]
seen = {1}
d={}
for index,i in enumerate(l):
  d[index+1]=i
#print(d)
temp=1
for i in range(k):
  temp=d[temp]
  if temp in seen:
    #print('i=',i)
    #print('temp=',temp)
    lenloop = len(seenl)-seenl.index(temp)
    #print('lenloop=',lenloop)
    r = (k-i-1)%lenloop
    temp = seenl[seenl.index(temp):][r]
    break
  seenl.append(temp)
  seen.add(temp)
print(temp)

Measured memory_bytes: 48180
#include <iostream>
#include<algorithm>

using namespace std;
int main()
{
    int ye=0,gray=0,bro=0,g=0,cyan=0,r=0,b=0,oran=0,other=0;
    int n,a,ansmax=0,ansmin=0,ans=0;
    cin>>n;
    for (int i = 0; i < n; i++){
        cin>>a;
        if (a>0&&a<400) gray++;
         if (a>=400&&a<800) bro++;
          if (a>=800&&a<1200) g++;
           if (a>=1200&&a<1600) cyan++;
            if (a>=1600&&a<2000) b++;
             if (a>=2000&&a<2400) ye++;
              if (a>=2400&&a<2800) oran++;
               if (a>=2800&&a<3200) r++;
       if (a>=3200) other++;

    }
    if (gray!=0) ans++;
       if (ye!=0) ans++;
       if (bro!=0) ans++;
       if (g!=0) ans++;
       if (cyan!=0) ans++;
       if (r!=0) ans++;
       if (b!=0) ans++;
       if (oran!=0) ans++;
       if (other>ans) ansmin=ans;
       else ansmin=ans;
       if (ansmin==0) ansmin=1;
       ansmax=ans+other;
    cout<<ansmin<<" "<<ansmax<<endl;
   return 0;
}

Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,q=n1()
AB=n3(n-1)
PX=n3(q)

d={i:[] for i in range(1,n+1)}
for a,b in AB:
    d[a].append(b)
    d[b].append(a)

ans=[0]*(n+1)
for p,x in PX:
    ans[p]+=x

q=deque([1])
c=[False]*(n+1)
c[1]=True
while len(q)>0:
    i=q.popleft()
    for j in d[i]:
        if c[j]==False:
            ans[j]+=ans[i]
            c[j]=True
            q.append(j)

print(*ans[1:])

Measured memory_bytes: 133268
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
abc=[[a,b,a+b] for a,b in ab]
abc.sort(key=lambda x:x[2],reverse=True)
tk=sum([abc[0] for i,abc in enumerate(abc) if i%2==0])
ao=sum([abc[1] for i,abc in enumerate(abc) if i%2==1])
print(tk-ao)


Measured memory_bytes: 39368
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, int &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

int main() {
	for (int n; (n = in());) {
		vector<double> A(n);
		double s {};
		for (auto &a: A)
			s += a = in();
		s /= n;
		outl(count_if(begin(A), end(A), [s](auto a) {return a <= s;}));
	}
}


Measured memory_bytes: 2700
n = input()
a = input()
n = int(n)
a = a.split(' ')
max = int(a[0])
min = int(a[0])
sum = int(a[0])
for i in range(1, n):
    x = int(a[i])
    if x > max:
        max = x
    if x < min:
        min = x
    sum += x

print('%d %d %d'%(min, max, sum))


Measured memory_bytes: 6340
#include<stdio.h>
int main(void)
{
	//変数を定義
	int n, cake = 4, donut = 7,ans = 0,yes = 0;
	scanf("%d", &n);

	for (int i = 0; i <= 100 ;i++) {
		for (int j = 0; j <= 100 ; j++) {
			if (n == cake * i + donut * j) {
				yes++;
				break;
			}
			else if(n < cake * i + donut * j){
				ans++;
				break;
			}
		}
		if (n == cake * i) {
			yes++;
			break;
		}
		if (n == donut * i) {
			yes++;
			break;
		}
	}

	if (yes != 0) {
		printf("Yes\n");
	}
	else if(ans != 0){
		printf("No\n");
	}

	return 0;
}



Measured memory_bytes: 128
//It's not logic, but magic ~~
#include <bits/stdc++.h>
#define debug(x) std::cerr<<"L: "<<__LINE__<<" "<<__FUNCTION__<<"() Var: "<<#x<<" Val: "<<x<<"\n"
typedef long long ll;
#define inf 0x7f7f7f7f

inline void gettime() {debug(clock());}
inline int read() {
	static char c; static int x; int flag = 1;
	while (c = getchar(), !isdigit(c)) if (c == '-') flag = -1;
	x = c - '0';
	while (c = getchar(), isdigit(c))x = (x << 1) + (x << 3) + c - '0';
	return x * flag;
}
inline char achar() {
	static char c;
	while (c = getchar(), !isalpha(c));
	return c;
}

/**
 * 考虑 异或值等于和的条件
 * 等价于区间[l,r]没有数字相同位上同时出现1
 * 这个区间一定是连续的
 * 尺取法即可
 */

int n, ns[200200], cnt[26];
ll ans;

void del(int x) {
	for (int i = 0; x; ++i, x >>= 1)
		if (x & 1)
			--cnt[i];
}

bool ok(int x) {
	for (int i = 0; x; ++i, x >>= 1)
		if (x & 1)
			if (cnt[i])
				return 0;
	return 1;
}

void add(int x) {
	for (int i = 0; x; ++i, x >>= 1)
		if (x & 1)
			++cnt[i];
}

int main() {
	n = read();
	for (int i = 1; i <= n; ++i)
		ns[i] = read();

	int l = 1, r = 0;
	for (; l <= n; del(ns[l++])) {
		while (r < n && ok(ns[r + 1]))
			add(ns[++r]);
		ans += ll(r - l + 1);
	}

	printf("%lld\n", ans);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};



int main(){
  string s; cin>>s;
  set<char> se;
  rep(i,s.size()){
    if(se.count(s[i])){
      puts("no");
      return 0;
    }else
    se.insert(s[i]);
  }
  puts("yes");

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	// c < d
	public static long eukleides(long c, long d){
		if(d % c == 0){
			return c;
		}

		long mod = d % c;

		return eukleides(mod, c);
	}

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

		// input
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextInt();
		long d = scan.nextInt();
		if(c > d){
			long temp = c;
			c = d;
			d = temp;
		}

		long gcd = eukleides(c, d);
		long lcm = (c * d) / gcd;
		long answer = b - b / c - b / d + b / lcm;
		answer -= a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;

		System.out.println(answer);

	}
}



Measured memory_bytes: 23636
while 1:
	n=input()
	if n==0:break
	ls=[0]*n
	for i in range(n):
		game=map(int,raw_input().split())
		score,thrw=0,1
		for flame in range(10):
			if game[thrw]==10:
				score+=sum(game[thrw:thrw+3])
				thrw+=1
			elif game[thrw]+game[thrw+1]==10:
				score+=10+game[thrw+2]
				thrw+=2
			else:
				score+=game[thrw]+game[thrw+1]
				thrw+=2
		else:
			ls[i]=[game[0],score]
	for k,s in sorted(sorted(ls),key=lambda x:x[1],reverse=True):
		print k,s

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

int main() {
    ll N, K; cin >> N >> K;
    vector<ll> l(100000+1);
    int a, b;
    for (int i = 0; i < N; i++){
        cin >> a >> b;
        l[a] += b;
    }
    ll cnt = 0;
    int tmp = 0;
    while (cnt < K) {
        tmp++;
        cnt += l[tmp];
    }
    cout << tmp << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <queue>
#define N 1100
#define pr pair<int, int>
#define fi first
#define se second
using namespace std;

int n, m, a[N][N], mx[] = {-1, 0, 1, 0}, 
    my[] = {0, 1, 0, -1};
char s[N][N];
queue<pr> q;

int main() {
	//freopen("1.in", "r", stdin);
	//freopen("1.out", "w", stdout);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i ++) {
  	scanf("%s", s[i] + 1);
  	for (int j = 1; j <= m; j ++) {
  		if (s[i][j] == '#') {
  			q.push(pr(i, j));
  			a[i][j] = 1;
  		}
  	}
  }
  while (q.size()) {
  	pr e = q.front(); q.pop();
  	for (int k = 0; k < 4; k ++) {
      pr w = pr(e.fi + mx[k], e.se + my[k]);
      if (w.fi < 1 || w.fi > n || w.se < 1 || w.se > m) continue;
      if (a[w.fi][w.se]) continue;
      a[w.fi][w.se] = a[e.fi][e.se] + 1;
      q.push(w);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i ++)
  	for (int j = 1; j <= m; j ++)
  		ans = max(ans, a[i][j] - 1);
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 13840
#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 S(int N) {
  if (N < 10) return N;
  return N % 10 + S(N / 10);
}

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

  CIN(N);
  OK(N % S(N) == 0);

  return 0;
}



Measured memory_bytes: 256
def main():
    N, A, *x = map(int, open(0).read().split())
    MAX_A_x = max(A, max(x))
    x = [xi - A for xi in x]
    # dp[i][j]
    # i 選んだ枚数 0 <= i <= N
    # j 合計 0 <= j <= 2 * N * MAX_A_x
    dp = [[0] * (2 * N * MAX_A_x + 1) for i in range(N + 1)]
    dp[0][N * MAX_A_x] = 1
    for i in range(1, N + 1):
        for j in range(2 * N * MAX_A_x + 1):
            if j - x[i - 1] < 0 or 2 * N * MAX_A_x < j - x[i - 1]:
                dp[i][j] = dp[i - 1][j]
            elif 0 <= j - x[i - 1] <= 2 * N * MAX_A_x:
                dp[i][j] = dp[i - 1][j] + dp[i - 1][j - x[i - 1]]
            else:
                dp[i][j] = 0
    print(dp[N][N * MAX_A_x] - 1)
    return


main()


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define ll long long
using namespace std;
pair <ll, ll> p[100005];
int main()
{
    ll N, K, x, y;
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> x >> y;
        p[i] = {x, y};
    }
    sort(p, p+N);
    ll cnt = 0;
    for(int i = 0; i < N; i++){
        cnt += p[i].second;
        if(cnt >= K){
            cout << p[i].first << "\n";
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1792