akhauriyash/Code-Regression huggingface dataset:
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=n0()
# n=1000000000000001

def num2alpha(num):
    if num<=26:
        return chr(96+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(122)
    else:
        return num2alpha(num//26)+chr(96+num%26)
print(num2alpha(n))

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

int main(){
    int N; cin>>N;
    vector<int> vW(N);

    int total=0;
    rep(i,N){
        int x; cin>>x;
        total += x;
        vW[i]=x;
    }

    int ans = 1e9;
    int left = 0;
    for(int i=0; i<N; i++){
        left += vW[i];
        ans = min(ans , abs(left - (total-left)));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3568
package main

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

func main() {
  io := IO{bufio.NewReaderSize(os.Stdin,100),bufio.NewWriterSize(os.Stdout,100)}
  n,m := io.NextInts()
  g := make([][]int,n)
  r := make([][]int,n)
  for i:=0;i<m;i++ {
    s,t := io.NextInts()
    g[s-1] = append(g[s-1],t-1)
    r[t-1] = append(r[t-1],s-1)
  }
  en := make([]float64,n)
  pn := make([]float64,n)
  pn[n-1] = 1
  for v:=n-2;v>=0;v-- {
    deg := 1/float64(len(g[v]))
    for _,u := range g[v] {
      en[v] += en[u]
      pn[v] += pn[u]
    }
    en[v] = en[v]*deg+1
    pn[v] *= deg
  }
  e1 := make([]float64,n)
  p1 := make([]float64,n)
  p1[0] = 1
  for v:=1;v<n;v++ {
    for _,u := range r[v] {
      deg := 1/float64(len(g[u]))
      e1[v] += (e1[u]+1)*deg
      p1[v] += p1[u]*deg
    }
  }
  ans := en[0]
  for v:=0;v<n-1;v++ {
    if len(g[v]) == 1 { continue }
    deg := len(g[v])
    now := en[0]
    max := 0.0
    for _,u := range g[v] {
      tmp := (e1[v]*pn[u]+p1[v]*en[u]+p1[v]*pn[u])/float64(deg-1)
      now += tmp/float64(deg)
      if max < tmp { max = tmp }
    }
    if ans > now-max { ans = now-max }
  }
  fmt.Printf("%.12f",ans)
}

type IO struct {
  reader *bufio.Reader
  writer *bufio.Writer
}
func(io *IO) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := io.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(io *IO) Println(a ...interface{}) (int,error) {
  return fmt.Fprintln(io.writer,a...)
}
func(io *IO) Flush() error {
  return io.writer.Flush()
}
func(io *IO) NextInts() (int,int) {
  s := strings.Fields(io.NextLine())
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}

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




int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
	int _N, _X, _D; cin >> _N >> _X >> _D;
  __int128 N = _N, X = _X, D = _D;

  
  map<__int128, vector<pair<__int128, __int128>>> Intervals;
  __int128 tot = (X + X + D * (N - 1)) * N / 2;
  if (D == 0) {
    cout << (_X != 0 ? (_N + 1) : 1) << '\n';
    exit(0);
  }
  else if (D < 0) {
    X = X + (N - 1) * D;
    D = -D;
  }
  auto step = 2 * D;
	for (int i = 0; i <= N; ++i) {
    auto mi = (X + X + D * (i - 1)) * i / 2;
    auto ma = (X + D * (N - 1) + X + D * (N - i)) * i / 2;
    auto cls = (step + (ma * 2 - tot) % step) % step;
    Intervals[cls].emplace_back(((mi * 2 - tot) - cls) / step, 
                               ((ma * 2 - tot) - cls) / step + 1);
  }
  __int128 ans = 0;
  for (auto V : Intervals) {
    sort(V.second.begin(), V.second.end());
    __int128 l = -1e30, r = l;
    for (auto P : V.second) {
      __int128 a, b; tie(a, b) = P;
      if (r < a) {
        ans += r - l;
        l = a, r = b;
      }
      r = max(b, r);
    }
    ans += r - l;
  }
  cout << static_cast<unsigned long long>(ans) << '\n';
}



Measured memory_bytes: 28416
#include<iostream>
using namespace std;
int main()
{
	int n,i,k;
	cin>>n>>k;
	int a[200001];
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(i=1;i<=n-k;i++)
	{
		if(a[i]<a[i+k])
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
}

Measured memory_bytes: 4412
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return set(divisors)

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

a, b = map(int, input().split())

common_divisors = make_divisors(a) & make_divisors(b)

ans = 1
for common_divisor in common_divisors:
    if is_prime(common_divisor):
        ans += 1

print(ans)


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

const ll INF = 1LL << 62;

int main() {
  ll n;
  cin >> n;
  vector<ll> x(n), y(n), p(n);
  rep(i, n) cin >> x[i] >> y[i] >> p[i];

  vector<vector<ll>> xsel(1 << n, vector<ll>(n));
  vector<vector<ll>> ysel(1 << n, vector<ll>(n));
  rep(i, 1 << n) {
    rep(j, n) {
      xsel[i][j] = abs(x[j]);
      ysel[i][j] = abs(y[j]);
      rep(k, n) {
        if ((i >> k) & 1) {
          xsel[i][j] = min(xsel[i][j], abs(x[j] - x[k]));
          ysel[i][j] = min(ysel[i][j], abs(y[j] - y[k]));
        }
      }
    }
  }

  vector<ll> ans(n + 1, INF);
  rep(i, 1 << n) {
    ll cnt = __builtin_popcount(i);
    for (ll j = i; j >= 0; j--) {
      j &= i;
      ll cost = 0;
      rep(k, n) {
        if (!((i >> k) & 1)) {
          cost += 1LL * min(xsel[j][k], ysel[i - j][k]) * p[k];
        }
      }
      ans[cnt] = min(ans[cnt], cost);
    }
  }

  for (ll i = 0; i <= n; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 12952
n, m, q = $stdin.readline.chomp.split.map(&:to_i)
ns = Array.new(q) { $stdin.readline.chomp.split.map(&:to_i) }

res = []
(1..m).to_a.repeated_combination(n).each do |a|
  cnt = 0
  q.times do |i|
    i, j, c, d = ns[i]
    cnt += d if a[j - 1] - a[i - 1] == c
  end
  res << cnt
end
puts res.max

Measured memory_bytes: 15496
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
public class Main {
	static FastScanner stdIn=new FastScanner();
	public static void main(String[] args) {
		int N=stdIn.nextInt();
		int s[]=new int[N];
		int sum=0,max=0;
		for(int i=0;i<N;i++){
			s[i]=stdIn.nextInt();
			sum+=s[i];
		}
		if(sum%10==0){
			for(int i=0;i<N;i++){
				if((sum-s[i])%10!=0&&max<sum-s[i])
					max=sum-s[i];
			}
			System.out.println(max);
		}
		else
			System.out.println(sum);
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int value_b[N];
  int check_b[N];
  bool flag=false;
  for(int i=0;i<N;i++){
    cin >> value_b[i];
    if(value_b[i]==2){
      flag = true;
    }
    check_b[i]=0;
  }
  
  if(flag==true){
    int button_on = 1;
    int count = 0;
    while(true){
      if(check_b[button_on-1]>0){
        cout << "-1" <<endl;
        break;
      }
      check_b[button_on-1] += 1;
      count += 1;
      button_on = value_b[button_on-1];
      if(button_on==2){
        cout << count << endl;
        break;
      }
    }
  } else{
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#define INF 1e7
using namespace std;

vector<int> index2;

int w,n;
int val[2][1<<18];
void init(){
	n=1;
	while(n<w)n*=2;
	for(int i=0;i<2*n-1;i++)val[0][i]=val[1][i]=INF;
}

void update(int k,int a){
	k+=n-1;
	val[0][k]=a-(k-(n-1));
	val[1][k]=a-(w-1-(k-(n-1)));
	while(k>0){
		k=(k-1)/2;
		val[0][k]=min(val[0][k*2+1],val[0][k*2+2]);
		val[1][k]=min(val[1][k*2+1],val[1][k*2+2]);
	}
}

int query(int d,int a,int b,int k=0,int l=0,int r=n){
	if(a<=l && r<=b)return val[d][k];
	if(r<=a || b<=l)return INF;
	int vl=query(d,a,b,k*2+1,l,(l+r)/2);
	int vr=query(d,a,b,k*2+2,(l+r)/2,r);
	return min(vl,vr);
}

int a[100001];

int main(void){
	scanf("%d",&w);
	init();
	index2.push_back(-1);
	for(int i=0;i<w;i++){
		scanf("%d",&a[i]);
		if(a[i]==0)index2.push_back(i);
		if(a[i]<0){
			update(i,-a[i]);
		}
	}
	index2.push_back(w);
	int cnt=0;
	for(int i=0;i<w;i++){
		if(a[i]>0){
			int num=0;
			int ld=lower_bound(index2.begin(),index2.end(),i)-index2.begin();
			ld--;
			int dat1=-INF,dat2=-INF;
			if(ld!=0){
				dat1=query(1,index2[ld]+1,i);
				if(dat1>=-(w-1-i))num=max(num,min(dat1+(w-1-i),a[i]));
			}
			int rd=lower_bound(index2.begin(),index2.end(),i)-index2.begin();
			if(rd!=index2.size()-1){
				dat2=query(0,i+1,index2[rd]);
				if(dat2>=-i)num=max(num,min(dat2+i,a[i]));
			}
			cnt+=num;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 4000
#include <stdio.h>
#include <stdlib.h>
 
void maxHeapify( int* , int , int );
void buildMaxHeap( int* , int );
 
int main(){
 
  int *a;
  int n,i,j;
 
  scanf("%d",&n);
  a = malloc(sizeof(int)*(n+1));
 
  for( i=1 ; i<n+1 ; i++ ){
    scanf("%d",&a[i]);
  }
 
  buildMaxHeap( a, n );
 
  for( i=1 ; i<n+1 ; i++ ){
    printf(" %d",a[i]);
  }
 
  printf("\n");
 
  free(a);
 
  return 0;
}
 
void maxHeapify( int *a , int i , int n ){
  int l,r,max,tmp;
 
  max = i;
  l = 2*i;
  r = 2*i+1;
 
  if( l <= n && a[l] > a[i] ) max = l;
 
  if( r <= n && a[r] > a[max] ) max = r;
   
 
  if( max != i ){
    tmp = a[i];
    a[i] = a[max];
    a[max] = tmp;
    return maxHeapify( a, max, n );
  }
 
}
 
 
void buildMaxHeap( int *a , int n ){
  int i;
 
  for( i=n/2 ; i>=1 ; i-- ){
    maxHeapify(a, i, n);
  }
}

Measured memory_bytes: 2472
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int N; cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        if (s == "E869120") ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3208
n,k = map(int,input().split())

red = n-k
blue = k
INF = 10**9 + 7 

def C(n,m):
    if n==0 or m == 0:
        return 1
    res = 1
    for i in range(n,n-m,-1):
        res = (res*i)
    for i in range(1,m+1):
        res //= i
    return res%INF
for i in range(1,k+1):
    bn = blue - i
    bm = i
    if red < bm - 1:
        print(0)
        continue
    rn = red - (bm-1)
    rm = bm+1
    print((C(bn+bm-1,bm-1)*C(rn+rm-1,rm-1))%INF)




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

using namespace std;

int main(){
int N; cin  >> N;
  vector<int> A(N); vector<int> X(N);
  for(int i = 0; i < N; i++){ int a; cin >> a; A[i] = a; X[i] = a;}
  sort(A.begin(),A.end());
  
  for(int i = 0; i < N; i++){
    if( X[i] >= A[N/2]){ cout << A[N/2 - 1] << endl;;}
    else{ cout << A[N/2] << endl;}}
  return 0;}

Measured memory_bytes: 3712
n = int(input())

poll = {}
max_val = 1
for i in range(n):
    name = input()

    if name not in poll:
        poll[name] = 1
    else:
        poll[name] += 1
        max_val = max(poll[name], max_val)

winner = []

for name, vote in poll.items():
    if vote == max_val:
        winner.append(name)
        
winner.sort()
for w in winner:
    print(w)

Measured memory_bytes: 32096
import java.util.*;
 
class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        String s;
        int m,h;
        StringBuilder sb;
        while(true){
            s=in.next();
            if(s.equals("-")) break;
            m=in.nextInt();
            sb=new StringBuilder(s);
            for(int i=0;i<m;i++){
                h=in.nextInt();
                sb.append(sb.substring(0,h));
                sb.delete(0,h);
            }
            System.out.println(sb);
        }
    }
}

Measured memory_bytes: 26220
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n,x,sum=0,i,j,k,count;
        while(true) {
        	count=0;
        	n=scan.nextInt();
        	x=scan.nextInt();
        	if(n==0 && x==0) {
        		break;
        	}
        	for(i=1;i<=n;i++) {
        		for(j=i+1;j<=n;j++) {
        			for(k=j+1;k<=n;k++) {
        				sum=i+j+k;
        				if(sum==x)count++;
        			}
        		}
        	}
        	System.out.println(count);
        }
    }
}



Measured memory_bytes: 26448
#include <bits/stdc++.h>
using namespace std;
template<typename T = int>
vector<T> create_table(size_t a){
  return vector<T>(a);
}

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

using mat = decltype(create_table<int>(2, 3, 3));
int main(){
	string s; cin >> s;
	int len = s.size();
	for(int i = 0; i < len; i++) s[i] -= 'a';
	const int mod = 998244353;
	if(s.size() <= 3){
		queue<string> q;
		set<string> seen;
		seen.insert(s);
		q.push(s);
		while(!q.empty()){
			string u = q.front(); q.pop();
			for(int i = 0; i < len - 1; i++){
				if(u[i] != u[i + 1]){
					int nv = (u[i] + u[i + 1]) * 2;
					nv %= 3;
					string v = u;
					v[i] = nv;
					v[i + 1] = nv;
					if(!seen.count(v)){
						seen.insert(v);
						q.push(v);
					}
				}
			}
		}
		cout << seen.size() << endl;
	} else {
		if(count(s.begin(), s.end(), s[0]) == len){
			cout << 1 << endl;
			return 0;
		}	
		mat f = create_table<int>(2, 3, 3), nf = f;
		f[0][0][0] = 1;
		f[0][1][1] = 1;
		f[0][2][2] = 1;
		for(int i = 1; i < len; i++){
			for(int j = 0; j < 2; j++){
				for(int k = 0; k < 3; k++){
					for(int l = 0; l < 3; l++){
						nf[j][k][l] = 0;			
					}
				}
			}
			for(int j = 0; j < 2; j++){
				for(int k = 0; k < 3; k++){
					for(int l = 0; l < 3; l++){
						for(int n = 0; n < 3; n++){
							(nf[j || (l == n)][(k + n) % 3][n] += f[j][k][l]) %= mod;
						}
					}
				}
			}
			f = nf;
		}
		int ans = 0, sum = 0, all = 0;
		for(int i = 0; i < len; i++){
			sum += s[i];
			sum %= 3;
			if(i + 1 < len && s[i] == s[i + 1]) all = 1;
		}
		ans += 1 - all;
		for(int j = 1; j < 2; j++){
			for(int l = 0; l < 3; l++){
				ans += f[j][sum][l];
				if(ans >= mod) ans -= mod;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b){ if (a > b) { a = b; } }

ll dp[3001][3001][4];
ll f[3000][3000];

int main() {
    int r, c, k, x, y;
    ll v;

    cin >> r >> c >> k;
    for (int i = 0; i < k; ++i) {
        cin >> y >> x >> v;
        f[y - 1][x - 1] = v;
    }
    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            for (int l = 2; l >= 0; --l) {
                if (l > 0 && dp[i][j][l] == 0)
                    continue;
                chmax(dp[i][j][l + 1], dp[i][j][l] + f[i][j]);
            }
            for (int l = 0; l <= 3; ++l) {
                chmax(dp[i + 1][j][0], dp[i][j][l]);
                chmax(dp[i][j + 1][l], dp[i][j][l]);
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i <= 3; ++i) {
        chmax(ans, dp[r - 1][c - 1][i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 355340
import math

while True:
    n = int(input())
    if n==0: break
    
    a = list(map(int, input().split()))
    
    mean = sum(a)/len(a)
    
    v = 0
    for i in a:
        v += (i - mean)**2
    
    v /= len(a)
    sd = math.sqrt(v)
    
    print('%.5f'%sd)


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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int k; cin >> k;
	ll ans = 0;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int l=1;l<=k;l++){
				ans += GCD(GCD(i,j), l);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	
    int n ;
    cin >> n ;
    int a[n],b[n] ;
    for(int i=0;i<n;i++) cin >> a[i] ;
    for(int i=0;i<n;i++) b[i] = a[i] ;

    sort(b,b+n) ;

    for (int i=0;i<n;++i)
    {
        if(a[i]!=b[n-1])
         cout << b[n-1] << endl;
        else
         cout << b[n-2] << endl;
    }
    
	return 0;
}


Measured memory_bytes: 3200
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <forward_list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i]
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion



int32_t main() {
    make(int, x, y);
    if (y % 2 == 0 && x * 2 <= y && x * 4 >= y){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }


    return 0;
}

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

int main(void){
    long long int i, j, k, n, a, b, ans=0, po=0, x[5];
    char name[30];
    for(i=0; i<5; i++) scanf("%lld", &x[i]);
    for(i=0; i<5; i++){
        if(x[i] == 0){
            printf("%lld", i+1);
            break;
        }
    }
    
}

Measured memory_bytes: 1724
from collections import Counter
n=int(input())
a=[input() for i in range(n)]
m=int(input())
b=[input() for i in range(m)]
ca = Counter(a)
cb = Counter(b)
ans = [0]
for s,n in ca.items():
  ans.append(n-cb[s])
print(max(ans))

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  int h, w; cin >> h >> w;
  vector<vector<int> > grid (h, vector<int> (w, 0));
  vector<vector<bool> > wall (h, vector<bool> (w, false));
  for (int i = 0; i < h; i++) {
    string s; cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '#') { wall[i][j] = true; grid[i][j] = 0; }
    }
  }
  grid[0][0] = 1;
  for (int row = 0; row < h; row++) {
    for (int col = 0; col < w; col++) {
      if (row == 0 && col == 0) continue;

      if (!wall[row][col]) {
        if (row == 0) grid[row][col] = grid[row][col-1];
        else if (col == 0) grid[row][col] = grid[row-1][col];
        else grid[row][col] = (grid[row-1][col] + grid[row][col-1])%MOD;
      }
    }
  }
  cout << grid[h-1][w-1] << endl;
  return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    vector<int> sx(N);
    for(int i = 0; i < N; ++i) {
        cin >> X[i];
        sx[i] = X[i];
    }
    sort(sx.begin(), sx.end());

    int n = N / 2 - 1;
    for(int i = 0; i < N; ++i) {
        if(X[i] > sx[n])
            cout << sx[n] << endl;
        else
            cout << sx[n + 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#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() {
  string s;
  cin >> s;
  vector<string> e = {"dreamer", "eraser",
                      "dream", "erase"};
  int cur = s.size();
  while (cur > 0) {
    bool ok = false;
    string eee;
    for (string ee : e) {
      bool ok2 = true;
      for (int j = 0; j < ee.size(); j++) {
        if (cur - (int) ee.size() < 0) {
          ok2 = false;
          break;
        }
        if (s.at(cur - (int) ee.size() + j) != ee.at(j)) {
          ok2 = false;
          break;
        }
      }
      if (ok2) {
        eee = ee;
        ok = true;
        break;
      }
    }
    if (ok) {
      cur -= eee.size();
    } else {
      break;
    }
  }
  cout << (cur == 0 ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void){
        int h, w, i, j;

        for(;;){
                scanf("%d %d",&h,&w);
                if(h == 0 && w == 0)
                        break;
                else{
                        for(i=1; i<=h; i++){
                                if(i % 2 == 1){
                                        for(j=1; j<=w; j++)
                                                if(j % 2 == 1)
                                                        putchar('#');
                                                else
                                                        putchar('.');
                                }else{
                                        for(j=1; j<=w; j++){
                                                if(j % 2 == 1)
                                                        putchar('.');
                                                else
                                                        putchar('#');
                                        }
                                }
                                printf("\n");
                        }
                        printf("\n");
                }
        }
        return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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;}
ll mod= 1e9 + 7;

int INF=1e9;

int R, C;
vector<vector<char>> maze;  // 迷路の内容を保存する配列
vector<vector<int>> dist;   // 距離を記録しておく配列
int sx, sy, gx, gy;  //sx,syはスタート、gx,gyはゴール、（1-index）

int main() {
  bool swt=0;
    cin >> R >> C;
    cin >> sy >> sx;
    cin >> gy >> gx;
    sy--;  // 0始まりに直す
    sx--;
    gy--;
    gx--;

    dist.assign(R, vector<int>(C, INF));   // 初期化
    maze.assign(R, vector<char>(C, '.'));  // 初期化

    rep(i,R) {
      rep(j,C)cin >> maze[i][j];
    }

    queue<pair<int, int>> que;
    queue<pair<int, int>> que2;
    que.emplace(make_pair(sy, sx));  // sから探索する
    dist[sy][sx] = 0;
    while(que.size()!=0 && que.size()!=0){
      while (que.size() != 0) {              // キューの要素がなくなったら終了
        pair<int, int> now = que.front();  // 現在の状態
        que.pop();

        if (now.first == gy && now.second == gx){swt=1;break;}  // 目的地にたどり着いたので終了
        que2.push(now);

        int dy[4] = {0, 0, 1, -1};  // dx,dy は次の探索場所への距離を表す（４方向分）
        int dx[4] = {1, -1, 0, 0};
        for (int i = 0; i < 4; i++) {
            int ny = now.first + dy[i];                            // 次の探索場所の行番号
            int nx = now.second + dx[i];                           // 次の探索場所の列番号
            if (ny < 0 || R <= ny || nx < 0 || C <= nx) continue;  // 迷路の外に出るならスルー
            if (maze[ny][nx] == '#') continue;                     // 障害物があればスルー
            if (dist[ny][nx] != INF) continue;                     //探索済みならスルー
            que.push(make_pair(ny, nx));
            dist[ny][nx] = dist[now.first][now.second];
        }
      }

      if(swt==1)break;

      while(que2.size()!=0){
        pair<int, int> now = que2.front();  // 現在の状態
        que2.pop();
        rep(i,5){
          rep(j,5){
            int ny = now.first + i-2;                            // 次の探索場所の行番号
            int nx = now.second + j-2;                           // 次の探索場所の列番号
            if (ny < 0 || R <= ny || nx < 0 || C <= nx) continue;  // 迷路の外に出るならスルー
            if (maze[ny][nx] == '#') continue;                     // 障害物があればスルー
            if (dist[ny][nx] != INF) continue;                     //探索済みならスルー
            que.push(make_pair(ny, nx));
            dist[ny][nx] = dist[now.first][now.second]+1;
          }
        }
      }

    }
  if(dist[gy][gx]==INF){cout << -1 << endl;}else{cout << dist[gy][gx] << endl;}

}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for (int h = 0; h < H; h++) {
        cin >> a.at(h);
    }

    for (int w = 0; w < W + 2; w++) {
        cout << '#';
    }
    cout << endl;
    for (int h = 0; h < H; h++) {
        cout << '#';
        cout << a.at(h);
        cout << '#' << endl;
    }
    for (int w = 0; w < W + 2; w++) {
        cout << '#';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

A,B,C,K = LI()

if K <= A:
    print(K)
elif K <= A+B:
    print(A)
else:
    print(A-(K-A-B))

Measured memory_bytes: 65348
while(True):
    m,n = map(int,input().split())
    if not m: break
    a = list(range(1,m+1))
    b = [input() for _ in range(n)]
    t = [str(i+1) for i in range(n)]
    t[2::3]   = ["Fizz"]*len(t[2::3])
    t[4::5]   = ["Buzz"]*len(t[4::5])
    t[14::15] = ["FizzBuzz"]*len(t[14::15])
    i=0
    for j in range(n):
        if len(a) <2: break
        if b[j] != t[j]: del a[i]; i = 0 if i >= len(a) else i; continue
        i += 1
        i = i%len(a)
    print(" ".join(str(e) for e in a))


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 24;

int main(void){
    range(i, 1, 10){
        range(j, 1, 10){
            cout << i << "x" << j << "=" << i * j << endl;
        }
    }

	return 0;
}

Measured memory_bytes: 1112
#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 RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

int ceil(int a, int b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

#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;

signed main() {
  i32 x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<i64> A(x), B(y), C(z);
  cin >> A >> B >> C;
  vector<i64> AB(x * y);
  REP(i, x) {
    REP(j, y) {
      AB[i * y + j] = A[i] + B[j];
    }
  }
  sort(ALL(AB));
  i32 w = min(k, x * y);
  vector<i64> ABC(w * z);
  REP(i, w) {
    REP(j, z) {
      ABC[i * z + j] = AB[AB.size() - i - 1] + C[j];
    }
  }
  sort(ALL(ABC));
  auto iter = ABC.end();
  REP(_, k) {
    iter--;
    cout << *iter << endl;
  }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

signed main(){
    int N;
    cin>>N;
    vint A(N);rep(i,N)cin>>A[i];
    int S=accumulate(all(A),0ll);

    vpint lis;
    rep(i,N)lis.pb(pint(abs(S-N*A[i]),i));
    sort(all(lis));
    cout<<lis[0].se<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n;
    string s;
    cin >> n >> s;
    string res  = "";
    res += s[0];
    for(int i = 1; i < n; i++){
    	if(s[i] == res.back())continue;
        else res += s[i];
    }
  cout << res.size() << endl;
  return 0;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int a,b,c,d,e,f,g,h,i,j,k;
    cin>>a>>b>>c;
    d=max(a,max(b,c));
    e=a+b+c-d;
    if(e==d)
       cout<<"Yes";

    else
      cout<<"No";
}

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

int  main()
{
	int x,y; cin >> x >> y;
	if (y % 2)
	{
		cout << "No" << endl;
		return 0;
	}
	int t = x;
	for (int i = 0; i <= x; i++)
	{
		if ((i*2) + ((t-i)*4) == y)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return (0);
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

const lint INF = 1e15;

int main()
{
    lint n;
    cin >> n;
    vector<lint> a(n);
    lint sumA=0,x;
    REP(i, n) {
        cin >> x;
        sumA += x;
        a[i] = x;
    }
    lint sumS=0;
    lint ans=INF;
    FOR(i,0,n-1){
        sumS += a[i];
        //cout << sumS << "\n";
        lint d = abs(sumA - sumS*2);
        ans = min(d, ans);

    }


    cout << ans << "\n";

        return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <functional>
#include <climits>

int main() {
	int r, g, b, n; std::cin >> r >> g >> b >> n;
	int count = 0;
	for (auto ri = 0; ri * r <= n; ++ri) {
		for (auto gi = 0; ri * r + gi * g <= n; ++gi) {
			if ((n - ri * r - gi * g) % b == 0) ++count;
		}
	}
	std::cout << count << std::endl;
}

Measured memory_bytes: 888
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        s: Chars,
        t: Chars,
    }

    let mut mn = t.len();

    for i in 0..=s.len() - t.len() {
        let mut c = 0;
        for j in 0..t.len() {
            if t[j] != s[i + j] {
                c += 1;
            }
        }
        mn = std::cmp::min(mn, c);
    }
    println!("{}", mn);
}


Measured memory_bytes: 2160
import java.util.Scanner;

class Main{
public static void main(String[] args){

Scanner sc = new Scanner(System.in);

int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int x=0;
for(int i=a;i<=b;i++){
if(c%i==0){
x++;
}
}
System.out.println(x);

}
}



Measured memory_bytes: 26340
import java.io.*
import java.util.*
import java.lang.Math.*


fun main() {
    val N = rd.readInt()

    val d = N%10
    val ans = when (d) {
        3 -> "bon"
        in listOf(0,1,6,8) -> "pon"
        else -> "hon"
    }

    println(ans)
}


//val rd = debug.Reader("abc", "168", "a", "sample-1")
val rd = Reader()
fun main(args: Array<String>) {
    Thread(null, MainThread(), "mainThread", 128 * 1024 * 1024).start()
}


const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
class MainThread : Runnable {
    override fun run() { main() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 38340
/*....Abhilash's coding template....*/
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define in insert
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define vll vector<ll>
#define fl(i,a,b) for(ll i=a;i<=b;i++)
#define flr(i,a,b) for(ll i=a;i>=b;i--)
#define print(v) for(auto i=v.begin();i!=v.end();i++){cout<<*i<<" ";}cout<<"\n";
#define tr(c,i) for(decltype((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define test() ll te; cin >> te; while(te--)
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define PI 3.14159265
#define MOD 1000000007
#define M 998244353
#define node pair<ll , pair<ll,ll> >
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

int main()
{
    ll a,b; cin>>a>>b;
    cout<<(a*b)/__gcd(a,b);
}


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

int main()
{
    using ValueType = int;
    using WeightType = std::uint64_t;

    const ValueType max_val = 1000 * 100 + 10;
    const WeightType inf = 1e13;

    auto n = std::size_t();
    auto weight = WeightType();

    std::cin >> n >> weight;

    auto w = std::vector<WeightType>();
    auto val = std::vector<ValueType>();

    for (std::size_t i = 0; i < n; ++i)
    {
        WeightType w0;
        ValueType v0;
        std::cin >> w0 >> v0;
        w.emplace_back(w0);
        val.emplace_back(v0);
    }

    auto dp = std::vector<WeightType>(max_val, inf);
    dp[0] = 0;

    ValueType val_sum = 0;
    for (std::size_t i = 0; i < n; ++i)
    {
        val_sum += val[i];

        for (ValueType v = val_sum - val[i]; 0 <= v; --v)
        {
            if (dp[static_cast<std::size_t>(v + val[i])] >= dp[static_cast<std::size_t>(v)] + w[i])
                dp[static_cast<std::size_t>(v + val[i])] = dp[static_cast<std::size_t>(v)] + w[i];
        }
    }

    ValueType result = 0;
    for (ValueType i = 0; i < max_val; ++i)
    {
        if (dp[static_cast<std::size_t>(i)] <= weight) result = i;
    }

    std::cout << result << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
struct UnionFind {
	vector<int> par;
	UnionFind(int N) : par(N) { rep(i, 0, N)par[i] = i; }
	int root(int x) { return par[x] == x ? x : par[x] = root(par[x]); }
	void unite(int x, int y) { if (!same(x, y)) par[root(x)] = root(y); }
	bool same(int x, int y) { return root(x) == root(y); }
	map<int, int> cnt() { map<int, int> cnt; rep2(v, par)cnt[root(v)]++; return cnt; }
};
int main()
{
	int n, m, x, y, z;
	cin >> n >> m;
	UnionFind tree(n);
	rep(i, 0, m) {
		cin >> x >> y >> z;
		tree.unite(x-1, y-1);
	}
	printf("%d\n", tree.cnt().size());
	return 0;
}

Measured memory_bytes: 8244
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int N;
  int A;
  int B;
  cin >> N >> A >> B;
  if(N*A>B){
    cout << B << endl;
  }
  else{
    cout << N*A << endl;
  }
  return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

const int limit = 50;
const int limit3 = limit * limit * limit;

int m[limit];
vector<int> tree[limit];

const int inf = 1LL << 30;
ll w[limit],v[limit];
int num[limit];

void dfs(int cur){
	w[cur] = m[cur],v[cur] = 1;
	for(auto &nxt:tree[cur]){
		dfs(nxt);
		w[cur] += w[nxt];
		v[cur] += v[nxt];
	}
}

vector<int> sw,sv;

int dp[310 + 1][limit3 + 50];

int main(void){
	int n,x,d;
	cin >> n >> x >> d;

	cin >> m[0],num[0] = inf;
	rep(i,1,n){
		cin >> m[i];
		num[i] = d;
		int p;
		cin >> p;
		tree[p-1].push_back(i);
	}

	dfs(0);

	vector<int> order(n);
	iota(begin(order),end(order),0);
	sort(begin(order), end(order), [&](int a, int b){
		const ll lft = v[a] * w[b];
		const ll rht = v[b] * w[a];
		return (lft > rht);		
	});

	rep(i,n){
		if(w[i] > x) continue;
		int s = min<int>(limit,num[i]), cur = 1;
		while(s >= cur){
			if(w[i] * cur <= x){
				sw.push_back(w[i] * cur);
				sv.push_back(v[i] * cur);
			}
			s -= cur;
			cur <<= 1;
		}
		if(s != 0){
			if(w[i] * s <= x){
				sw.push_back(w[i] * s);
				sv.push_back(v[i] * s);
			}
		}
	}

	const int all = sw.size();
	rep(i,all+1)rep(j,limit3+1) dp[i][j] = inf;
	dp[0][0] = 0;
	
	rep(i,all)rep(j,limit3+1){
		if(dp[i][j] == inf) continue;
		chmin(dp[i + 1][j],dp[i][j]);
		if(j + sv[i] <= limit3) chmin(dp[i + 1][j + sv[i]], dp[i][j] + sw[i]);
	}

	int ans = 0;
	rep(j,limit3+1){
		if(dp[all][j] >  x) continue;
		int cw = dp[all][j],cv = j;
		rep(hoge,n){
			const int i = order[hoge];
			const int rest = max<int>(0, num[i] - limit);
			const int tmp = min<int>((x - cw) / w[i], rest);
			cw += w[i] * tmp;
			cv += v[i] * tmp;
		}
		chmax(ans,cv);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 147712
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;
int main() {
	int A, B, C;
	int d = 0;
	int ans = 0;
	cin >> A >> B >> C;
	if (A < B) {
		d = B;
		B = A;
		A = d;
	}
	if (A < C) {
		d = C;
		C = A;
		A = d;
	}
	if (B < C) {
		d = C;
		C = B;
		B = d;
	}
	A = A - C;
	B = B - C;
	while (A!=0) {
		while (A != B) {
			A--;
			ans++;
		}
		while (A != 0) {
			A -= 2;
			ans++;
			if (A == -1) {
				cout << ans + 1 << endl;
				return 0;
			}
		}
		
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  int px, py;
  cin >> px >> py;
  int res = 0;
  rep (i, n - 1) {
    int x, y;
    cin >> x >> y;
    if ((px < x) == (py > y))  res += abs(x - px) + abs(y - py);
    else res += max(abs(x - px), abs(y - py));
    px = x;
    py = y;
  }
  cout << res << endl;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] txt = Console.ReadLine().Split(' ');

            int len = txt.Length;
            int[] memo = new int[len];

            int maxV = 0;
            string maxS = "", longest = "";

            for (int i = 0; i < len; i++)
            {
                if (longest.Length < txt[i].Length) longest = txt[i];

                for (int j = i + 1; j < len; j++)
                {
                    if (txt[i] == txt[j])
                    {
                        memo[i]++;

                        if (maxV < memo[i])
                        {
                            maxV = memo[i];
                            maxS = txt[i];
                        }
                    }
                }
            }
            Console.WriteLine(maxS + " " + longest);
        }
    }
}

Measured memory_bytes: 8852