akhauriyash/Code-Regression huggingface dataset:
<?php

$chars = array();

while (false !== ($chr = fgetc(STDIN))) {
    $code = ord(strtolower($chr));
    if ($code < ord('a') || ord('z') < $code) {
        continue;
    }

    if (! isset($chars[$code])) {
        $chars[$code] = 0;
    }

    $chars[$code] += 1;
}

for ($i = ord('a'); $i <= ord('z'); $i++) {
    $amount = isset($chars[$i]) ? $chars[$i] : 0;
    echo chr($i)." : $amount\n";
}

Measured memory_bytes: 6628
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
fun solve(H: Int, W: Int, N: Int, a: IntArray){
    val ans = IntArray(H * W)
    var cur = 0
    for(i in 0 until N){
        for(j in 0 until a[i]){
            ans[cur] = i + 1
            cur++
        }
    }
    for(h in 0 until H){
        val ret = ans.slice(h*W until h*W + W)
        if(h % 2 == 0){ pw.println(ret.joinToString(separator=" ")) }
        else pw.println(ret.reversed().joinToString(separator=" "))
    }
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val H = sc.next().toInt()
    val W = sc.next().toInt()
    val N = sc.next().toInt()
    val a = IntArray(N)
    for (i in 0 until N) {
        a[i] = sc.next().toInt()
    }
    solve(H, W, N, a)
}



Measured memory_bytes: 36508
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}


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

  ll N,A,B;
  cin >> N >> A >> B;
  string s;cin >> s;

  ll world=0,aboard=0;
  rep(i,N){
    if(s[i]=='a' && world<A+B){
      world++;
      cout << "Yes" << endl;
    }
    else if(s[i] == 'b' && world< A+B && aboard<B){
      world++,aboard++;
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
   if (a%b == 0){
       return(b);
   }else{
       return(gcd(b, a%b));
   }
}

int main() {
  int n,ij,ans=0;
  cin >> n;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
        ij = gcd(i,j);
        ans += gcd(ij,k);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <cstring>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long int64;
int P[200000] = {0,};
int M[200000] = {0,};

int main() {
	//memset(P, 0, sizeof(P));
	//memset(P, 0, sizeof(M));
	int N;
	cin >> N;
	int tmp;
	int64 ans = 0;
	for (int i = 0; i < N; ++i) {
		cin >> tmp;
		if (i+tmp < 200000) ++P[i+tmp];
		if (i-tmp > 0) ++M[i-tmp];
	}
	for (int i = 1; i < N; ++i) {
		ans += (int64)P[i] * M[i];
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 5216
#include"bits/stdc++.h"
using namespace std;
#define int long long
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
constexpr long long inf = 1e17;
constexpr int mod = 1000000007;

signed main() {
	int x, y; cin >> x >> y;
	if (y % 2 == 0 && 2 * x <= y && y <= 4 * x)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using ll = long long;
ll N, k, posp, negp, zedp, cn, c0, cp;
const int maxn = 2e5 + 1;
ll a[maxn];

ll solveneg() {
  vector<ll> pos(a + N - cp, a + N);
  vector<ll> neg(a, a + cn);
  ll r = pos[0] * neg.back();
  ll l = pos.back() * neg[0];
  reverse(pos.begin(), pos.end());
  reverse(neg.begin(), neg.end());
  while(l <= r) {
    ll mi = l + (r - l) / 2;
    ll cnt = 0;
    for (int i = 0, j = 0; i < neg.size(); i++) {
      for (; j < cp && neg[i] * pos[j] <= mi; j++);
      cnt += j;
    }
    if (cnt < k)
      l = mi + 1;
    else 
      r = mi - 1;
  }
  return l;
}

ll solvepos() {
  vector<ll> pos(a + N - cp, a + N);
  vector<ll > neg(a, a + cn);
  reverse(neg.begin(), neg.end());
  ll l = LLONG_MAX, r = LLONG_MIN;
  /*
  if (neg.size() >= 2) {
        l = min(l, neg[0] * neg[1]);
        r = max(r, neg[cn - 1] * neg[cn - 2]);
    }
    if (pos.size() >= 2) {
        l = min(l, pos[0] * pos[1]);
        r = max(r, pos[cp - 1] * pos[cp - 2]);
    }
  */
  // -1 -2 -3 -4 -5
  if (pos.size() > 0) {
    l = pos[0] * pos[0];
    r = pos.back() * pos.back();
  }
  if (neg.size() > 0) {
    l = min(l, neg[0] * neg[0]);
    r = max(r, neg.back() * neg.back());
  }
  while(l <= r) {
    ll mi = l + (r - l) / 2;
    ll cnt = 0;
    for (int i = cp - 1, j = 0; i >= 0; i--) {
      for (; j < i && pos[i] * pos[j] <= mi; j++);
      cnt += min(j, i);
    }
    for (int i = cn - 1, j = 0; i >= 0; i--) {
      for (; j < i && neg[i] * neg[j] <= mi; j++);
      cnt += min(j, i);
    }
    if (cnt < k)
      l = mi + 1;
    else 
      r = mi - 1;
  }
  return l;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> k;
  cp = 0, cn = 0, c0 = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] > 0) {
      cp++;
    } else if (a[i] < 0) {
      cn++;
    } else c0++;
  }

  posp = cp * (cp - 1) / 2 + cn * (cn - 1) / 2;
  zedp = c0 * (cn + cp) + c0 * (c0 - 1) / 2;
  negp = cn * cp;

  ll ans;
  sort(a, a + N);
  if (k > zedp + negp) {
    k -= (zedp + negp);
    ans = solvepos();
  }
  else if (k <= negp) {
    ans = solveneg();
  } else {
    ans = 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
//int date[13]={-1,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
	//freopen("010.in","r",stdin);
	//freopen("010.out","w",stdout);
	string a;
	cin>>a;
	int ans = 1000000;
	for(int i=0;i<a.length()-2;i++){
		int sum=0;
		for(int j=0;j<3;j++){
			sum = sum * 10 + a[j+i]-'0';
		}
		//cout<<sum<<endl;
		ans = min(ans, abs(753-sum));
	}
	cout <<ans;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(S: str):

    for i, s in enumerate(S):
        if (i+1) % 2 == 1:
            if s == "L":
                print(NO)
                return
        else:
            if s == "R":
                print(NO)
                return

    print(YES)


    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

count = 0
n = readi()

for i in range(1, n + 1):
    if len(str(i)) % 2 == 1:
        count += 1
print(count)

Measured memory_bytes: 6864
#include<stdio.h>

int table[101],temp,frag,n;

void search(){
  int k;

  for(k=3; k<=n; k++)    if(table[k]%2 != 0 || table[k] == 0) frag=1;
  for(k = 1; k <=2; k++) if(table[k] != 1) frag = 1;
}

int main(){

  int i,j,A,B;

    for(i=0; i<101; i++){
      table[i]=0;
    }
    n = 2;

    while(scanf("%d%d",&A,&B)!=EOF){
 
      if(A > n) n = A;
      else if(B > n) n = B;

      if(A==0 && B==0){
	frag=0;
	search();
	
	if(frag==0) printf("OK\n");
	else printf("NG\n");

	for(i=0; i<101; i++){
	  table[i]=0;
	}
	n = 2;
      }

      else{
	table[A]++;
	table[B]++;
     }

    }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	int n, k; std::cin >> n >> k;
	std::string str; std::cin >> str;
	int section = 1;
	for (auto i = 1; i < n; ++i) {
		if (str[i] != str[i - 1]) ++section;
	}
	int erased = std::max(1, section - 2 * k);
	std::cout << n - erased << std::endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 43;
const int S = 18;
const int mod = 1e9 + 7;

void add(int &x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
}

int n, bad = 0;
int d[2][1 << S];

void read() {
  int x, y, z;
  cin >> n;
  cin >> x >> y >> z;

  y += z;
  x += y;

  bad = (1 << z) | (1 << y) | (1 << x);
}

void kill() {
  int *cur = d[0];
  int *nxt = d[1];

  cur[1] = 1;

  int full = (1 << S) - 1;

  for (int i = 0; i < n; ++i) {
    fill(nxt, nxt + (1 << S), 0);

    for (int mask = 1; mask < (1 << S); mask += 2)
      for (int a = 1; a <= 10; ++a) {
        int nmask = ((mask << a) | 1) & full;
        if ((nmask & bad) != bad)
          add(nxt[nmask], cur[mask]);
      }

    swap(cur, nxt);
  }

  int ans = 0;
  for (int mask = 0; mask < (1 << S); ++mask)
    add(ans, cur[mask]);

  ll pw = 1;
  for (int i = 0; i < n; ++i)
    pw = (10 * pw) % mod;

  ans = pw - ans;
  if (ans < 0)
    ans += mod;
  cout << ans << endl;
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <iostream>
#include <forward_list>
using namespace std;

#define SCAN_INT(i) scanf("%d", i)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define PRINT_INT(i) printf("%d\n", i)
#define PRINT_TWO_INT(i, j) printf("%d %d\n", i, j)
#define PRINT_THREE_INT(i, j, k) printf("%d %d %d\n", i, j, k)

bool isATCG(char b)
{
    if (b == 'A' || b == 'T' || b == 'G' || b == 'C')
        return true;
    return false;
}

int main()
{
    char b;
    char S[10];
    int counts[10];
    for (int i = 0; i < 10; i++)
    {
        S[i] = 'e';
        counts[i] = 0;
    }

    scanf("%s", S);

    int currentCounter = 0;
    for (int i = 0; i < 10; i++)
    {
        if (S[i] == 'e')
            break;
        if (!isATCG(S[i]))
        {
            currentCounter++;
        }
        else
            counts[currentCounter]++;
    }
    int ans = 0;
    for (int i = 0; i < 10; i++)
    {
        ans = max(ans, counts[i]);
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
import collections
B=[]
C=[]
for i,a in enumerate(A):
  B.append(a-i)
  C.append(-a-i)
C=collections.Counter(C)
ans=0
for b in B:    
  ans+=C[b]
print(ans)

Measured memory_bytes: 145408
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int A, B, C, K, res;

int main(){
    cin >> A >> B >> C >> K;

    int maxV = max(A, B);
    maxV = max(maxV, C);

    if(maxV == A){
        res += A * pow(2,K) + B + C;
    } else if(maxV == B){
        res += B * pow(2,K) + A + C;
    } else if(maxV == C){
        res += C * pow(2,K) + A + B;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
n,t = map(int,input().split())
ct_list = [list(map(int,input().split())) for hoge in range(n)]
ans_list = []
for hoge in ct_list:
  if hoge[1] <= t:
    ans_list.append(hoge[0])
if len(ans_list) > 0:
  print(min(ans_list))
else:
  print('TLE')

Measured memory_bytes: 3060
# 何回目のアタックだよこれ（前回までのは当然読んですら無い）
# 単純にa<bのとき貯めれるだけためて残りをbにぶっこむのじゃ駄目なの?
k, a, b = map(int, input().split())
if a >= b or b - a <= 2:
    # 貯めるだけムダなので全振り
    print(1 + k)
    exit()
x = a  # はじめてa枚貯まってから1円に交換したターン
d = k - x  # x時点での残りターン

if d % 2 == 0:
    # 直前で止めて+1したほうがいい
    print(a + (b - a) * (d // 2) + 1)
else:
    # そのまま交換したほうがいい
    print(b + (b - a) * (d // 2))


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    string s;
    cin>>s;
    ll n = s.length();
    ll m_bit = 1LL<<(n-1);
    ll ans=0;

    rep(bit,m_bit){
        ll x = 0;
        ll tmp = 0;
        rep(i,n){
            ll now = s[i]-'0';
            if(i==0){
                tmp = now;
                continue;
            }
            if(bit & (1LL<<(i-1))){
                x += tmp;
                tmp = now;
            }else{
                tmp *= 10;
                tmp += now;
            }
        }
        x += tmp;
        ans += x;
    }

    cout<<ans<<endl;
    return  0;
}


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

using namespace std;

using ll = long long;

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

    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;

    int res = 0;
    for (int i = 0; i < n; ++i) {
        set<char> cnt;
        cnt.insert(a[i]);
        cnt.insert(b[i]);
        cnt.insert(c[i]);
        if (cnt.size() == 2) ++res;
        else if (cnt.size() == 3) res += 2;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pb push_back
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;
int k,x;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>k>>x;
	if(k*500>=x) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int t = 0;
    rep(i, K) {
        if (t == 0) {
            if (A % 2) --A;
            B += A / 2;
            A = A / 2;
            t = 1;
        } else {
            if (B % 2) --B;
            A += B / 2;
            B = B / 2;
            t = 0;
        }
    }
    cout << A << " " << B << "\n";
    return 0;
}


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

int main(){
  string str;
  cin >> str;
  
  for(int bit = 0; bit <(1<<3) ; bit++){
    int tmp = (int)(str[0] - '0');
    for(int i = 0; i < 3; ++i){
      if(bit&(1<<i)) tmp += (int)(str[i+1] - '0');
      else tmp -= (int)(str[i+1] - '0');
    }
    if(tmp == 7){
      cout << str[0];
      for(int i = 0; i < 3; ++i){
        if(bit & (1<<i)) cout << '+';
        else cout << '-';
        cout <<str[i+1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
}

 
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#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()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
int copy(int x){
	return x;
}

int main(){
	int n;cin>>n;
	vector<vector<int>> a(n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n - 1; j++) {
			int x;cin>>x;x--;a[i].pb(x);
		}
		a[i].pb(-1);
	}
	vector<int> now(n);
	vector<int> cnt(n,0);
	vector<bool> used(n,false);
	for(int i = 0; i < n; i++) {
		now[i] = a[i][0]; 
	}
	int i = 0;
	int ans = 0;
	while(i <= n * (n - 1) / 2){
		i++;
		bool flag = true;
		for(int i = 0; i < n; i++) {
			
			if (now[i] != -1 && now[now[i]] == i && used[now[i]] == false && used[i] == false){//やりたい同士のとき
				int tmp = copy(now[i]);
				cnt[i]++;
				cnt[tmp]++;
				now[i] = a[i][cnt[i]];
				now[tmp] = a[tmp][cnt[tmp]];
				used[i] = true;
				used[tmp] =true;
				// for(int i = 0; i < n; i++) {
				// 	cout << now[i] << endl;
				// }
			}
		}
		for(int i = 0; i < n; i++) {
				used[i] = false;
			}
			for(int i = 0; i < n; i++) {
				if (now[i] != -1){
					flag = false;
				}
			}
			ans++;
			if (flag){
				cout << ans << endl;
				return 0;
			}
		
	}
	
	for(int i = 0; i < n; i++) {
		if (now[i] != -1){
			cout << -1 << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 5120
#include <stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > L;
int main(void) {
  P team[55][12];
  L mama[55];
  int M, T, Q, R;
  int m, t, p, j;
  while(1){
    memset(team,0,sizeof(team));
    memset(mama,0,sizeof(mama));
    scanf("%d %d %d %d", &M, &T, &Q, &R);
    if(M==0 & T==0) break;
    for ( int i = 0; i < R; i++ ) {
      scanf("%d%d%d%d",&m,&t,&p,&j);
      t--;
      if(j==0) team[t][p]=P(m+team[t][p].first,1);
      else team[t][p]=P(20+team[t][p].first,0);
    }

    for(int i=0;i<T;i++){
      for(int l=1;l<=Q;l++){
        if(team[i][l].second==1){
          mama[i].first--;
          mama[i].second.first+=team[i][l].first;
        }
      }

      mama[i].second.second= -i;
    }

    sort(mama,mama+T);

//    for(int i=0;i<T;i++) cout << "first :" << mama[i].first << "second.first :" << mama[i].second.first << "second.second :" << mama[i].second.second << endl;

    for(int i=0;i<T;i++){
    if(i==T-1) {
      printf("%d\n",-mama[i].second.second+1);
      break;
    }
    if(mama[i].first==mama[i+1].first && mama[i].second.first == mama[i+1].second.first){
      printf("%d=",-mama[i].second.second+1);
    }
    else  printf("%d,",-mama[i].second.second+1);
    }
  }

  return 0;
}

Measured memory_bytes: 1196
##### 解けた #####

N=int(input())
K=int(input())
X=list(map(int,input().split(" ")))
dsum=0 # 距離の合計

# 各ボールについて
for xi in range(len(X)):
    dsum+=(min(X[xi],K-X[xi]))*2

print(dsum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, y;
    cin >> n >> y;
    for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) {
        if (y - i * 10000 - j * 5000 >= 0) {
            if (i + j + (y - i * 10000 - j * 5000) / 1000 == n) {
                cout << i << ' ' << j << ' ' << (y - i * 10000 - j * 5000) / 1000;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1";
}


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

long int Gcm(long int a,long int b){

    long int temp=0;
    long int r=1;
    //aとbの最大公約数を求める
    //a,b入力を行う（a>b）。a=b*q+rの形で計算していく
    //b%rの値が０になったときのbがa,bの最大公約数(cとする)となる
    //最小公倍数は、c*a'=a,c*b'=bを満たすa',b'とcとの積である
    if(a<b){
        temp = a;
        a = b;
        b = temp;
    }
    while(r!=0){
        r = a%b;
        a = b;
        b = r;//aが最大公約数
    }
    return a;
}

int main(){
    long int x,y;
    long int gcd,lcm;

    while(cin >> x >> y){

    gcd = Gcm(x,y);

    x = x/gcd;
    y = y/gcd;

    lcm = x * y * gcd;

    cout << gcd <<" "<< lcm << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
a, b, c = map(int, input().split())

a, b, c = sorted([a, b, c])

dif_a = c-a
dif_b = c-b
result = dif_b
dif_a -= dif_b
if dif_a%2==0:
    result += dif_a//2
else:
    result -= (-dif_a)//2 - 1
print(result)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(void){
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    double ans1=pow(x2-x1,2)+pow(y2-y1,2);
    double ans2=sqrt(ans1);
    printf("%.5lf",ans2);
    return 0;
}


Measured memory_bytes: 3296
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    String b=gs();


	   
	    	//System.out.print(max);

        if (b.charAt(0)=='A') {
        	System.out.print("T");
        }else if (b.charAt(0)=='C') {
        	System.out.print("G");
        }else if (b.charAt(0)=='G') {
        	System.out.print("C");
        }else if (b.charAt(0)=='T') {
        	System.out.print("A");
        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35780
import sys
from collections import deque
sys.setrecursionlimit(500000)
input=sys.stdin.readline
n,q=map(int,input().split())
edge=[[] for i in range(n)]
cost=[0]*n
for i in range(n-1):
  p,s=map(int,input().split())
  p-=1;s-=1
  edge[p].append(s)
  edge[s].append(p)
for i in range(q):
  x,c=map(int,input().split())
  x-=1
  cost[x]+=c
visited=[False]*n
queue=deque([0])
visited[0]=True
while len(queue)!=0:
  a=queue.popleft()
  for i in edge[a]:
    if visited[i]==True:continue
    queue.append(i)
    visited[i]=True
    cost[i]+=cost[a]
for i in range(n):
  cost[i]=str(cost[i])
print(" ".join(cost))


Measured memory_bytes: 68368
#include<iostream>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,t[100010],a[100010],tM[100010],tm[100010],aM[100010],am[100010];
int main(){
	cin >> n;
	REP(i,n)
		cin >> t[i];
	REP(i,n) 
		cin >> a[i];

	tM[0] = t[0];
	tm[0] = t[0] - 1;

	FOR(i,1,n) {
		if(t[i - 1] < t[i]) {
			tM[i] = t[i];
			tm[i] = t[i] - 1;
		}else {
			tM[i] = t[i];tm[i] = 0;
		}
	}

	aM[n - 1] = a[n - 1];
	am[n - 1] = a[n - 1] - 1;
	REP(i,n - 1) {
		if(a[i] > a[i + 1]) {
			aM[i] = a[i];
			am[i] = a[i] - 1;
		}else {
			aM[i] = a[i];am[i] = 0;
		}
	}

	ll ans = 1;

	REP(i,n) {
		(ans *= max(0ll,min(tM[i],aM[i]) - max(tm[i],am[i]))) %= 1000000007;
		//cout << max(0ll,min(tM[i],aM[i]) - max(tm[i],am[i])) << endl;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int64_t Q, H, S, D, N; cin >> Q >> H >> S >> D >> N;

H = min(2*Q, H);
S = min(2*H, S);

if (S*2 <= D) cout << N*S << endl;
else cout << N/2 * D + N % 2 * S << endl;

}

// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 256
from sys import stdin


## This code doesn't pass the test
# def get_result(data):
#     H, N = data[0]
#     A_and_B = np.array(data[1:])
#     calc_efficient = np.array(list(map(lambda x: float(x[0] / x[1]), A_and_B)))
#     sorted_index = np.argsort(-calc_efficient)

#     cost = 0
#     remainder_H = H
#     for i in sorted_index:
#         A, B = A_and_B[i]
#         quotient = remainder_H // A
#         if quotient > 0:
#             cost += B * quotient
#             remainder_H = remainder_H - A * quotient
#         else:
#             if remainder_H > 0:
#                 continue
#             else:
#                 break

#     return cost

## 答え (DP, ナップザック問題の典型らしい) (pythonだとTLEになる)
# 自分の解法は典型的なハマり方をしたっぽい

def get_result(data):
    # 初期化
    H, N = data[0]
    A_and_B = data[1:]
    A = [0 for _ in range(N)]
    B = [0 for _ in range(N)]
    for i in range(N):
        Ai, Bi = A_and_B[i]
        A[i] = Ai
        B[i] = Bi

    # 最小化問題だから無限で初期化
    # DP[j] = Aの和が j の時の最小コスト (魔力)
    # 計算量は、O(NH)なのでHが少なくなるようにテーブルは作る
    inf = float("inf")
    # N × H (制約条件) のテーブルを作成
    dp =[inf for _ in range(H+1)]
    # 初期値
    dp[0] = 0

    # DP (コードはなんとなく理解できた)
    for i in range(H):
        for j in range(N):
            # 魔力1つずつについてloopさせる
            if (i+1) - A[j] < 0:
                dp[i+1] = min(dp[i+1], dp[0] + B[j])
            else:
                dp[i+1] = min(dp[i+1], dp[i+1-A[j]] + B[j])

    return dp[H]

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


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

int main(){
  int board[3][3];
  rep(i,3) rep(j,3) cin >> board[i][j]; 

  int ans_a[3], ans_b[3];
  int ans_board[3][3];
  ans_a[0] = 0;
  rep(i,3){
    ans_b[i] = board[0][i];
  }
  rep(i,3){
    ans_a[i] = board[i][0] - ans_b[0];
  }
  rep(i,3) rep(j,3) ans_board[i][j] = ans_a[i] + ans_b[j];

  bool ans = true;
  rep(i,3) rep(j,3) if(board[i][j] != ans_board[i][j]) ans = false;

  puts(ans? "Yes":"No");

  return 0;
}

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


int main(){
    int n;
    cin >> n;
    int m = 1000005;
    vector<int> ans(m, 0), a(n, 0);
    int maxidx = 0;
    rep(i, n){
        cin >> a[i];
        maxidx = max(a[i], maxidx);
    }
    
    set<int> nums;
    for (auto i: a){
        if (ans[i] != 0){
            ans[i] = 2;
            continue;
        }
        for (int j = i; j < m; j += i){
            ans[j] += 1;
        }
    }
    int cnt = 0;
    for (auto i: a) if (ans[i] == 1) cnt ++;
    cout << cnt << endl;
}


Measured memory_bytes: 7996
n = int(input())
arr = list(map(int, input().split()))

mod = 10 ** 9 + 7

res = 0
for d in range(60):
    one = sum(x & 1 for x in arr)
    res += one * (n - one) * (1 << d)
    res %= mod
    arr = [x >> 1 for x in arr]

print(res)


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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    ll n, k;
    cin >> n >> k;
    cout << min(n%k, k - n%k) << "\n";
}

int main()
{
    FAST_IO;
    // #ifndef ONLINE_JUDGE 
      // OC;
    // #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
red=[list(map(int,input().split()))+[0] for i in range(h)]+[[0 for i in range(w+1)]]
blue=[list(map(int,input().split()))+[0] for i in range(h)]+[[0 for i in range(w+1)]]
field=[[[0 for h in range(6500)] for i in range(w+1)] for j in range(h+1)]
field[0][0][abs(red[0][0]-blue[0][0])]=1
for i in range(h):
    for j in range(w):
        for f in range(6401):
            if field[i][j][f]==1:
                field[i][j+1][f+abs(red[i][j+1]-blue[i][j+1])]=1
                field[i][j+1][abs(f-abs(red[i][j+1]-blue[i][j+1]))]=1
                field[i+1][j][f+abs(red[i+1][j]-blue[i+1][j])]=1
                field[i+1][j][abs(f-abs(red[i+1][j]-blue[i+1][j]))]=1
for i in range(6500):
    if field[h-1][w-1][i]==1:print(i);exit()


Measured memory_bytes: 421204
import * as fs from "fs";

// inputで受け取り配列化する
const input = fs.readFileSync("/dev/stdin", "utf8").split("\n");
const [N, K] = input[0].split(" ").map(Number);
const h = input[1].split(" ").map(Number);

const dp = Array(N).fill(Infinity);
dp[0] = 0;

for (let index = 1; index < N; index++) {
  const times = K > index ? index : K;
  for (let j = 0; j < times; j++) {
    const _index = index - 1 - j;
    const jump = Math.abs(h[index] - h[_index]) + dp[_index];
    if (jump < dp[index]) {
      dp[index] = jump;
    }
  }
}

console.log(dp[dp.length - 1]);


Measured memory_bytes: 41296
#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;

int toInteger(string a) {
    int ret = 0;
    int keta = 0;
    for(int r = (int)a.size() - 1; r >= 0; r--) {
        ret += (a[r] - '0') * pow(10, keta++);
    }
    return(ret);
}

int main(void) {
    string input;
    map<int, int> count, check;
    set<int> s;
    //先月
    while(getline(cin, input)) {
        if(input.empty()) break;
        int pos = (int)input.find(',');
        int a = toInteger(input.substr(0, pos));
        if(count.count(a) == 0) {
            count[a] = 1; check[a] = 1;
        } else count[a]++;
        s.insert(a);
    }
    //今月
    while(getline(cin, input)) {
        if(input.empty()) break;
        int pos = (int)input.find(',');
        int a = toInteger(input.substr(0, pos));
        if(count.count(a) == 0) {
            count[a]++;
        } else{ count[a]++; if(check.count(a) != 0) check[a]++;}
        s.insert(a);
    }
    set<int>::iterator ite;
    for(ite = s.begin(); ite != s.end(); ite++) {
        if(check[*ite] >= 2 && check[*ite] <= 1000) {
            cout << *ite << " " << count[*ite] << endl;
        }
    }

    return(0);
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <set>
#include <functional>
#include <algorithm>
#include <cmath>
#define REP(i,N) for(int i=0;i<N;i++)
using namespace std;
using vi=vector<int>;

int main() {
	int N, K;
	cin >> N >> K;
	if (N >= K * 2 - 1)cout << "YES"; else cout << "NO";
	return 0;
}

Measured memory_bytes: 256
n, m = list(map(int, input().split(" ")))
ab = [list(map(int, input().split(" "))) for i in range(m)]

town = [0 for i in range(n)]

for i in range(len(ab)):
    x, y = ab[i]
    town[x - 1] += 1
    town[y - 1] += 1

print("\n".join(map(str, town)))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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 gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

struct Edge {
    int to;
    int cost;
};

vector<Edge> G[10];

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

int H,W;
cin >> H >> W;
rep(i,10) {
    rep(j,10) {
        int c;
        cin >> c;
        G[j].push_back(Edge{i,c});
    }
}

priority_queue <pii, vector<pii>, greater<pii>> que;
vi dp(10,INF);
dp[1] = 0;
que.emplace(0, 1);
while(!que.empty()) {
    pii p = que.top(); que.pop();
    int v = p.second;
    if(dp[v] < p.first) continue;
    for(auto e : G[v]) {
        if (dp[e.to] > dp[v] + e.cost) {
            dp[e.to] = dp[v] + e.cost;
            que.emplace(dp[e.to], e.to);
        }
    }
}

map<int,int> mp;
rep(i,H) {
    rep(j,W) {
        int a;
        cin >> a;
        mp[a]++;
    }
}
ll ans = 0;
rep(i,10) {
    ans += mp[i] * dp[i];
}

cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

  int ninzu;
  char akaao[101];
  scanf("%d",&ninzu);
  scanf("%s",akaao);

  int i;
  int aka = 0;
  int ao = 0;
  for(i=0;i<ninzu;i++){
    if(akaao[i]=='R'){
      aka++;
    }else if(akaao[i]=='B'){
      ao++;
    }
  }

  if(aka>ao){
    printf("Yes");
  }else{
    printf("No");
  }
  
  return 0;
}


Measured memory_bytes: 128
#! -*- coding: utf-8 -*-

import sys

n = int(raw_input())
print 0
sys.stdout.flush()
status_0 = raw_input()
start = 0
end = n-1
check = end
i = 1
if status_0 == "Vacant":
    pass
else:
    while 1:
        print check
        sys.stdout.flush()
        status = raw_input()
        if status == "Vacant":
            break
        elif status == status_0:
            if check % 2 == 0:
                start = check
            else:
                end = check
        else:
            if check % 2 == 0:
                end = check
            else:
                start = check
        check = start+(end-start)/2

quit()


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


const int MAX = 510000;
const int mod = 998244353;

long long fac[MAX]; //i!%mod=fac[i]
long long finv[MAX]; //pow(i!,-1)%mod=finv[i]
long long inv[MAX]; //pow(i,-1)%mod=inv[i]

// テーブルを作る前処理
void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(int argc, char const *argv[])
{
	cominit();
	int n;
	long long a,b,k;
	cin>>n>>a>>b>>k;
	long long ans=0LL;
	for (long long i = 0; i <= n; ++i)
	{
		if ((k-a*i)%b==0&&(k-a*i)/b<=n)
		{
			long long j=(k-a*i)/b;
			ans+=com(n,i)*com(n,j)%mod;
			ans%=mod;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[200010],ans;
int main(){
	cin>>n>>m;
	for (int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	if (m>=n){
		cout<<0<<endl;
		return 0;
	}
	for (int i=0;i<n-m;i++) ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
/* This Template is property of Pranav Khiste aka desmond_kaneki*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define vll vector<ll>
#define pb push_back
#define qll queue<ll>
#define mp make_pair
#define fst first
#define snd second
#define pll pair<ll,ll>
#define vpll vector<pll>
#define debug(x) cout<<#x<<' '<<x<<endl;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'
#define mod 1000000007
#define SUP LLONG_MAX
#define INF LLONG_MIN
#define test() ll var;  cin>>var; while(var--)
#define fileio freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);  // use cin cout only!!
main()
{
    fastio;
    ll l,r,d;
    cin>>l>>r>>d;
    ll a,b;
    a=l/d;
    if(l%d==0);
    else
        a++;
    b=r/d;
    cout<<b-a+1<<endl;

}


Measured memory_bytes: 3644
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;

int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい

string alpha="abcdefghijklmnopqrstuvwxyz";

int n;



int main(){
	cin>>n;
	int ans=1;
	int ma=0;
	rep(i,n){
		int j=i;
		int k=0;
		while(j%2==0){
			j/=2;
			k++;
		}
		if(k>ma){
			ma=k;
			ans=i;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}


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

from itertools import chain

if __name__ == '__main__':

    H, W = map(int, input().split())
    C = []
    dp = []
    for i in range(H):
        l = input().split()
        C.append([int(x) for x in l])
        dp.append([(int(x) + 1) % 2 for x in l])

    for i in range(1, H):
        for j in range(1, W):
            if C[i][j] == 0:
                dp[i][j] = min(dp[i - 1][j], dp[i][j - 1],
                               dp[i - 1][j - 1]) + 1
                
    max_width = max(list(chain.from_iterable(dp)))
    print(max_width**2)



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

int main() {
	int x, y;
	while(cin >> x >> y) {
		if(x != 0 | y != 0) { 
			cout << ((x < y) ? x : y ) << " " << ((x < y) ? y : x) << endl; 
		}
		else break;

	}
		return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;
const char c[11] = "abcdefghij";
set<string> S;
int N;
void eval(vector<char>v){
  string s;
  for(auto it:v) s+=it;
  S.insert(s);
  return;
}

void dfs(vector<char> v, int d) {
  //printf("==== d:%d====\n", d);                                                        
  if(N==d) { eval(v); return; }
  FOR(i, 0, d) {
    if(i!=0) {
      auto t = find(v.begin(),v.end(), c[i-1]);
      if(t == v.end()) break;
    }
    v.push_back(c[i]);
    //printf("pusing %c\n", c[i]);                                                       
    dfs(v, d+1);
    v.pop_back();
  }
  return;
}

int main()
{
  cin >> N;

  vector<char> v;
  v.push_back('a');
  dfs(v, 1);
  for(auto it:S) cout << it << endl;
  return 0;
}


Measured memory_bytes: 14208
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>
#include<limits>
#include <unordered_map>
#include <numeric>
#include <array>
#include <queue>
#include <chrono>

using namespace std;
using  ull = unsigned long long int;

#define rep(i,n,m) for(long long int i=n;i<(long long int)(m);i++)
#define INF (1<<29)
#define MD 1000000007

int main() {

	string str, key, un, ans;
	un = "UNRESTORABLE";

	cin >> str;
	cin >> key;

	ans = str;

	int word;
	bool flag;
	bool ch = false;

	rep(i, 0, str.length()) {
		flag = false;
		word = 0;

		if ((str[i]=='?' || str[i] == key[0]) && i <= str.length() - key.length()) {

			rep(j, 0, key.length()) {
				if (str[j+i] == '?'||str[j+i]==key[j])word++;

				if (key.length() <= word)flag = true;
			}


		}

		if (flag) {
			ans = str;
			rep(j, 0, key.length()) {
				ans[i + j] = key[j];
			}
			ch = true;

		}

	}


	if (ch) {

		rep(i, 0, ans.length()) {
			if (ans[i] == '?')ans[i] = 'a';
		}
		cout << ans << endl;
	}
	else cout << un << endl;



	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define vi(v)	vector < int > v;
#define	all(v)	v.begin(), v.end()

using namespace std;
int main()
{
	long long int n,k;
	cin>>n>>k;

        cout<<min(k - (n%k), n%k)<<'\n';
    //else if(n%k!=0&&n<k)
     //   cout<<min(n%k, n);
    //else
     //   cout<<"0";

return 0;
}

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

int main() {
  int M = 100000;
  std::vector<int> prime(M+1, 1);
  prime[0] = prime[1] = 0;
  for (int i = 2; i*i <= M; ++i)
    if (prime[i])
      for (int j = i*i; j <= M; j += i)
        prime[j] = 0;

  std::vector<int> res(M+1);
  for (int i = 1; i <= M; ++i)
    if (prime[i] && prime[(i+1)/2])
      res[i] = 1;

  for (int i = 1; i <= M; ++i)
    res[i] += res[i-1];

  int Q;
  scanf("%d", &Q);

  for (int i = 0; i < Q; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", res[r]-res[l-1]);
  }
}


Measured memory_bytes: 1408
N = int(input())
T, A = map(int,input().split())
H = list(map(int,input().split()))

delta = abs(T-H[0]*0.006-A)
ans = 0
for i in range(1,N):
	tmp = abs(T-H[i]*0.006-A)
	if (tmp < delta):
		delta = tmp
		ans = i
print(ans+1)

Measured memory_bytes: 3064
//
// Created by 10034 on 2020/7/27.
//

#include <iostream>
using namespace std;
typedef long long LL;
bool st[1000010];
int main(){
    LL res=0,n;
    cin>>n;
    for(int i=1;i<=n;++i){
        for(int j=i;j<=n;j+=i){
            res+=j;
        }
    }
    cout<<res<<endl;


    return 0;
}

Measured memory_bytes: 3184
/*
	Author: Luis Manuel D�az Bar�n (LUISMO)
	Problem:
	Online Judge:
	Idea:
*/
#include<bits/stdc++.h>
// Types
#define ll long long
#define ull unsigned long long
// IO
#define sf scanf
#define pf printf
#define mkp make_pair
#define fi first
#define se second
#define endl "\n"

using namespace std;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = 1e16 + 3;
const int mod = 1e9 + 7;
const int lim = 2e5 + 2;

ll N, W;
ll vi[200];
ll wi[200];

ll dp[lim][200];
bool mark[lim][200];

ll DynamicProgramming(int V, int idx)
{
    if(V == 0)
       return 0;

    if(idx == 0)
        return inf;

    if(mark[V][idx])
        return dp[V][idx];

    mark[V][idx] = true;

    ll curr = inf;

    if(V - vi[idx] >= 0)
    {
        ll aux = DynamicProgramming(V - vi[idx], idx - 1);
        curr = wi[idx] + aux;
    }
    ll aux = DynamicProgramming(V, idx - 1);

    curr = min(curr, aux);

    // updating dp state
    dp[V][idx] = curr;
    return curr;
}


void solve()
{
    cin >> N >> W;

    for(int i = 1; i <= N; i++)
    {
        cin >> wi[i] >> vi[i];
    }

    ll answ = 0;
    for(int i = 1; i <= 100003; i++)
    {
        if(i == 30)
        {

            int k = max(5, 9);
        }

        ll aux = DynamicProgramming(i, N);
        if(aux <= W)
        {
            // cout << aux << endl;
            answ = i;
        }
    }
    cout << answ;
}

void fastIO()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
}

void IO()
{
	if(fopen("d:\\lmo.in","r") != NULL)
	{
		freopen("d:\\lmo.in","r",stdin);
	}
	else if(fopen("/media/Beijing/lmo.in","r") != NULL)
	{
		freopen("/media/Beijing/lmo.in", "r", stdin);
	}
}

int main()
{
	IO();

	fastIO();

	solve();
}


Measured memory_bytes: 178432
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long N;
    cin >> N;
    int rn = pow(N, 0.5);
    long long ans = N - 1;
    for (int i = 2; i <= rn; i++)
    {
        if (N % i == 0)
        {
            ans = min(ans, N / i + i - 2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256