akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n, index, weight;
	static double BMI, hight;
	static Map<Integer, Double>map = new HashMap<Integer, Double>();
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	static boolean read(){
		n = sc.nextInt();
		if( n == 0 ) return false;
		for(int i = 0; i < n; i++){
			index = sc.nextInt();
			hight = sc.nextInt() * 0.01;
			weight = sc.nextInt();
			BMI = weight / ( hight * hight );
			map.put( index, Math.abs(BMI - 22.0));
		}
		return true;

	}
	static void solve(){
		double value = Integer.MAX_VALUE;
		int res = 0;
		for(int i = 1; i <= 1000000; i++){
			if( map.containsKey(i) ){
				if( value > map.get(i) ){
					value = map.get(i);
					res = i;
				}
			}
		}
		System.out.println(res);
		map.clear();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

int mod = 1e9 + 7;

ll powMod(ll a, ll n){
	ll ans = 1LL;
	a %= mod;
	while(n > 0){
		if(n&1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		n /= 2; 
	}
	return ans % mod;
}

void solution(){

	ll s; cin >> s;
	if(s < 3){
		cout << 0 << endl;
		return;
	}
	vector<ll> dp(s+1,1);
	dp[0] = dp[1] = dp[2] = 0LL; 
	for(ll cur = 4; cur <= s; cur++){
		for(ll sub = 3; sub <= cur; sub++){
			dp[cur] += dp[cur - sub];
			dp[cur] %= mod;
		}
	}
	cout << dp[s] << endl;



}	


int main(){ 
	fio;
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}

Measured memory_bytes: 3608
import queue

n,m = map(int,input().split())
hen = [[] for i in range(n)]
ans = [0 for i in range(n)]
a,b = 0,0



for i in range(m):
    a,b = map(int,input().split())
    hen[a-1].append(b)
    hen[b-1].append(a)

q = queue.Queue()
q.put(1)

while q.empty() == False:
    head = q.get()
    for h in hen[head-1]:
        if h != 1 and ans[h-1] == 0:
            ans[h-1] = head
            q.put(h)

flag = 0

for i in range(n):
    if i != 0 and ans[i] == 0:
        flag = 1

if flag == 0:
    print('Yes')
    for i in range(n-1):
        print(ans[i+1])
else:
    print('No')


Measured memory_bytes: 34156
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = __importDefault(require("fs"));
var myFile = "data/hello.txt";
var prodFile = "/dev/stdin";
(function () {
    var file = fs_1.default.readFileSync(prodFile, 'utf8');
    var inputs = file.split(/\n/g);
    if (parseInt(inputs[0]) === 1) {
        console.log('Hello World');
    }
    else {
        console.log(parseInt(inputs[1]) + parseInt(inputs[2]));
    }
})();
//# sourceMappingURL=hello.js.map

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

int main(int argc, char *argv[]) {
  int N; cin>>N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V[i];

  sort(V.begin(), V.end());

  double sum = (double)V[0];
  for (int i = 1; i < N; i++) {
    sum = (sum + V[i]) / 2.0;
  }

  cout << fixed << setprecision(6) << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    ll n; cin >> n;
    Vl A(n), B(n);
    rep(i, 0, n) cin >> A[i];
    ll cnt[n+10] = {0};

    // 何も除かないときのペア数 ans
    B = A;
    sort(ALL(B)); // 1 1 1 2 2
    ll a = 0, ans = 0;
    rep(i, 0, n-1){
        if(B[i] == B[i+1]){
            a ++;
            ans += a;
        }else{
            a = 0;
        }
    }

    rep(i, 0, n) {
        cnt[A[i]]++;
    }

    rep(i, 0, n){
        cout << ans - (cnt[A[i]] - 1) << endl;
    }
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 7296
while True:
    n = int(input())
    if n > 0:
        a = n // 5
        b = n // (5**2)
        c = n // (5**3)
        d = n // (5**4)
        e = n // (5**5)
        f = n // (5**6)
        print(a+b+c+d+e+f)
        
    if n == 0:
        break


Measured memory_bytes: 5588
#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int x; scanf("%d", &x); return x; }
long long lin() { long long x; scanf("%lld", &x); return x; }

signed main() { 
        int n;
        cin >> n;
        int ans = 0;
        vector<int> cnt(8, 0);
        rep(i, n) {
                int a;
                cin >> a;
                if (a >= 3200) ans ++;
                else cnt[a / 400] ++;
        }
        int c = 0;
        rep(i, 8) if (cnt[i] > 0) c ++;
        if (c == 0) cout << 1 << ' ' << ans << endl;
        else cout << c << ' ' << c + ans << endl;
        return 0;
}               



Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] T = new int[N];
    for (int i = 0; i < N; i++) T[i] = scanner.nextInt();
    long sum = 0;
    for (int i = 0; i < N; i++) sum += T[i];
    int M = scanner.nextInt();
    int[] P = new int[M];
    int[] X = new int[M];
    for (int i = 0; i < M; i++) {
      P[i] = scanner.nextInt() - 1;
      X[i] = scanner.nextInt();
    }
    for (int i = 0; i < M; i++) System.out.println(sum - T[P[i]] + X[i]);
  }
}


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


int main(void) {
  char a, b;
  cin >> a >> b;

  if (a == 'H') {
    cout << b << endl;
  } else {
    if (b == 'H') {
      cout << 'D' << endl;
    } else {
      cout << 'H' << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3532
#include<iostream>
using namespace std;
static const int MAX = 100;

int SelectionSort(int a[], int n)
{
	int min = 0, res = 0;
	for (int i = 0;i < n;i++) {
		int flag = 0;
		int min = i;
		for (int j = i;j < n;j++)
		{
			if (a[j] < a[min])
			{
				min = j;
				flag = 1;
			}
		}
		
		int temp = a[i];
		a[i] = a[min];
		a[min] = temp;
		if(flag ==1) res++;
	}
	return res;
}

int main()
{
	int n, a[MAX];
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> a[i];
	}
	int res = SelectionSort(a, n);
	for (int i = 0;i < n;i++)
	{
		if(i > 0) cout << " ";
		cout << a[i];
	}
	cout << endl;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3128
fun main(args: Array<String>) {
    var (x, y, a, b, c) = readLine()!!.split(" ").map{it.toInt()}
    var p = readLine()!!.split(" ").map{it.toLong()}
    var q = readLine()!!.split(" ").map{it.toLong()}
    var r = readLine()!!.split(" ").map{it.toLong()}
    var apple = (p.sortedBy{it*-1}.slice(0..x-1) + q.sortedBy{it*-1}.slice(0..y-1) + r).sortedBy{it*-1}.slice(0..(x+y-1))
    println(apple.sum())
}


Measured memory_bytes: 141536
#!/usr/bin/env python3
import sys
import numpy as np

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


def solve(X: int):
    if X>=30:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.7.1 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()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  string s;
  cin >> s;
  vector<string> idx={"dream","dreamer","erase","eraser"};
  ll f=1;
  ll n=s.size();
  ll i=n-1;
  while(1) {
    if(i<4) {
      f=0;
      break;
    }
    ll ff=1;
    for(ll j=0;j<4;j++) {
      ll si=idx[j].size();
      if(i<si-1) continue;
      if(s.substr(i-si+1,si)==idx[j]) {
        ff=0;
        i-=si;
        break;
      }
    }
    if(ff) {
      f=0;
      break;
    }
    if(i<0) break;
  }
  if(f) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const int INF = (int)100100100;

int main() {
    int N; cin >> N;
    multiset<int> a;
    for(int i=0;i<N;i++){
      	a.insert(1);
        int p;
        cin >> p;
        auto ite=a.upper_bound(-p);
        a.erase(ite);
        a.insert(-p);
    }
  	a.erase(1);
    cout << a.size();
}

/*

僕が悪かったです。

 */






Measured memory_bytes: 4992
// This file is a "Hello, world!" in C++ language by GCC for wandbox.

#include<stdio.h>
#include<string.h>

# define N 1050

int main()
{
    //char str[N];
    int n;
    int d1,d2;
    int count=0;
    int flag=0;//cont state?
    int max=0;
    
    scanf("%d",&n);
    
    for(int i=0; i<n; i++){
        scanf("%d %d",&d1,&d2);
        //printf("%d %d\n",d1,d2);
        
        if( d1==d2 ){
         
        //++count;
        if( ++count>=3 ){ 
            flag=1;
            break;
            //flag=1;
                }
        }else if( d1!=d2 ){
        //flag=0;
        count=0;
            
        } 
        
    }
   
        if( flag==1 ) puts("Yes");
        else puts("No");
    //std::cout << "Hello, Wandbox!" << std::endl;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;
int main(){
  int n; cin >>n; ll m=1;
  vector<ll>v(n);
  for(int i=0; i<n; i++){
    cin >>v[i];
    if(!v[i]){cout <<0; return 0;}
  }
  vector<ll>a(n);
  for(int i=0; i<n; i++){
    m*=v[i]; a[i]=m;
    if(i&&a[i]<a[i-1]){cout <<-1; return 0;}
    if(m>1000000000000000000){cout <<-1; return 0;}
  }
  cout <<m;
return 0;}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int minCost(int h[],int start,int n)
{
    int cost=0,i=n-2,arr[n];
    arr[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        int s1=INT_MAX,s2=INT_MAX;
        if (i+1<=n-1)
        {
            s1=abs(h[i+1]-h[i])+arr[i+1];
        }
        if (i+2<=n-1)
        {
            s2=abs(h[i+2]-h[i])+arr[i+2];
        }
        arr[i]=min(s1,s2);
    }
    return arr[0];
}
 

void solve()
{
    int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++)
	    cin>>h[i];
    cout<<minCost(h,0,n)<<"\n";
}
 
int main()
{
	solve();
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007

int ans = 0;
void solve(vector<int> r,vector<int> g,vector<int> b)
{
    // int ans = 0;
    // cout<<r.size()<<endl;
    for(int i=0;i<g.size();i++)
    {
        int q = g[i];
        int x = lower_bound(r.begin(),r.end(),q) - r.begin() - 1;
        int y = lower_bound(b.begin(),b.end(),q) - b.begin();
        if(x == -1)
        {
            continue;
            // x = 0;
        }
        if(y == b.size())
        continue;
        // cout<<x<<" "<<y<<'\n';
        for(int j=x;j>=0;j--)
        {
            int p = q - r[j];
            int f = q + p;
            if(binary_search(b.begin(),b.end(),f))
            {
                ans += b.size() - y - 1;
            }
            else
            ans += b.size() - y ;
            // cout<<ans<<" ";
        }
        // cout<<endl;
        // cout<<ans<<endl;
    }
}
 
int32_t main() 
{
    IO;
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> r;
    vector<int> g;
    vector<int> b;
    // int n = s.length();
    for(int i=0;i<n;i++)
    {
        if(s[i] == 'R')
        r.pb(i);
        if(s[i] == 'G')
        g.pb(i);
        if(s[i] == 'B')
        b.pb(i);
    }
    // int ans = 0;
    solve(r,g,b);
    // cout<<ans<<endl;
    solve(r,b,g);
    // cout<<ans<<endl;
    solve(g,r,b);
    // cout<<ans<<endl;
    solve(g,b,r);
    // cout<<ans<<endl;
    solve(b,r,g);
    // cout<<ans<<endl;
    solve(b,g,r);
    // cout<<ans<<endl;
    // cout<<b.size()<<endl;
    
    cout<<ans;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
string s[10] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};


int main() {
    string x;
    cin >> x;
    if (x == "SUN") {
        cout << 7 << endl;
        return 0;
    }
    for (int i = 0; i < 7; i++)
        if (x == s[i]) {
            cout << 7 - i - 1 << endl;
        }
    return 0;
}

Measured memory_bytes: 256
from math import factorial
import sys
sys.setrecursionlimit(100000)

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n, r) in nCr: return nCr[(n, r)]
    nCr[(n, r)] = cmb(n - 1, r) + cmb(n - 1, r - 1)
    return nCr[(n, r)]

N, K = [int(i) for i in input().split()]
R = N - K
for i in range(K):
    if K <= i or R < i:
        print(0)
    else:
        print(cmb(R + 1, i + 1) * cmb(K - 1, i) % (10 ** 9 + 7))


Measured memory_bytes: 166108
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  cout << (n * (1+n)) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    using namespace std;

    int x;
    int a, b, n;

    cin >> x;
    //cout << x << endl;

    a = x / 500;
    x -= a * 500;
    b = x / 5;

    n = a * 1000 + b * 5;
    cout << n << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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();
    if (B / A > C) {
      System.out.println(C);
    } else {
      System.out.println(B / A);
    }
  }
}

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

int main(void)
{
    int n, cnt=0;
    string a,b,c;
    cin >> n >> a >> b >> c;
    rep(i,n) cnt += set<char>({a[i], b[i], c[i]}).size() - 1;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <cstdio>
#include <algorithm>

using namespace std;

const int kMax = 50000 + 5;
const int kMaxM = 20 + 5;

int n, m;
int coin[kMaxM];
int dp[kMax];

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 0;i < m;++ i) scanf("%d", &coin[i]);
    for(int i = 1;i <= n;++ i) dp[i] = kMax;
    dp[0] = 0;
    for(int j = 0;j < m;++ j) {
        for(int i = 0;i + coin[j] <= n;++ i) {
            dp[i + coin[j]] = min(dp[i + coin[j]], dp[i] + 1);
        }
    }
    printf("%d\n", dp[n]);
    return 0;
}

Measured memory_bytes: 2872
n = int(input())
H = list(map(int, input().split()))

maxh = 0
cumH = [0]
for i in range(n):
    maxh = max(maxh, H[i])
    cumH.append(maxh)

ans = 0
for i in range(n):
    if H[i] >= cumH[i]:
        ans += 1
print(ans)


Measured memory_bytes: 3060
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb push_back
#define mkp make_pair
#define p_q priority_queue
#define INF 1000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

struct edge{
  int from;
  int to;
  int cost;
};

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

  int N, M, a, b, c; cin >> N >> M;
  vector<edge> graph;
  int d[1000];
  fill(d, d+N, 1145141919810931LL);
  d[0] = 0;

  REP(i, M){
    cin >> a >> b >> c;
    graph.pb({a-1, b-1, -c});
  }

  bool close = 0;
  REP(cnt, N){
    REP(i, M){
      int tmp = d[N-1];
      edge e = graph[i];
      if(d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
        if(cnt == N-1 and d[N-1] < tmp){
          close = 1;
          break;
        }
      }
    }
  }

  if(close) cout << "inf" << endl;
  else cout << -d[N-1] << endl;

  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<stack>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
using namespace std;
int main()
{
  int n,q,t;
  string name;

  queue<pair<string,int> > p;

  cin>>n>>q;

  for(int i=0;i<n;i++)
  {
    cin>>name>>t;
    p.push(make_pair(name,t));
  }

  pair<string,int>u;
  int elaps=0,a;

  while(!p.empty())
  {
    u=p.front();
    p.pop();
    a=min(u.second,q);
    u.second-=a;
    elaps+=a;
    if(u.second>0) p.push(u);
    else cout<<u.first<<" "<<elaps<<endl;
  }
}


Measured memory_bytes: 6352
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, K, i;
  cin >> N >> K;
  vi A(N);
  REP(0, N, i) {
    cin >> A[i];
    A[i]--;
    A[i] %= K;
  }

  //set<pi> C;
  vector<pi> C(N);
  i64 S = 0;
  REP(0, N, i) {
    S += A[i];
    S %= K;
    C[i]= {S % K, i};
  }
  sort(all(C));

  /*
  REP(0, N, i) {
    cout << "C " << C[i].first << " " << C[i].second << endl;
  }
  */

  i64 ans = 0;
  S = 0;
  REP(0, N+1, i) {
    i64 R = S % K;
    //cout << "loop " << i << endl;
    //cout << R << endl;
    auto low = lower_bound(all(C), make_pair(R, i));
    auto high = lower_bound(all(C), make_pair(R, i+K-1));
    ans += distance(low, high);
    //cout << distance(low, high) << endl;
    if(i == N) {
      break;
    }
    S += A[i];
    S %= K;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n;
main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a<=c&&c<=b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N=1e5+3;
int n,m;
vector<pair<int,int>> ad[N];
string ans[N];
string dig(int x)
{
	string a=to_string(x);
	int z=6-a.length();
	a=string(z,'0')+a;
	return a;

}
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	
	cin>>n>>m;
	int a,b;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		ad[a].push_back({b,i});
	}
	for(int i=1;i<=n;i++)
	{
		sort(ad[i].begin(),ad[i].end());

		for(int j=0;j<ad[i].size();j++)
		{
			int ii=ad[i][j].second;
			ans[ii]=dig(i)+dig(j+1);
		}
	}

	for(int i=0;i<m;i++)
	{
		cout<<ans[i]<<"\n";

	}


	

	
	
	
}

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

int main(void){

	int i;
	int al[26];
	char c;

	for(i=0;i<26;i++)al[i]=0;

	while(scanf("%c",&c)!=EOF){

		if(c>='a'&&c<='z')al[c-'a']++;
		else if(c>='A'&&c<='Z')al[c-'A']++;

	}

	for(i=0;i<26;i++){
		printf("%c : %d\n",'a'+i,al[i]);
	}

	return 0;

}

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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

#define mp make_pair

int score_index(char c) {
  if (c == 'r') return 0;
  if (c == 's') return 1;
  if (c == 'p') return 2;
}


int main() {
  int n,k,r,s,p;cin>>n>>k>>r>>s>>p;
  vector<int> point = {p,r,s};
  vector<int> score(n);
  string t;cin>>t;
  rep(i,n) {
    score[i] = point[score_index(t[i])];
  }
  // ppa(score);
  rep(i,n-k) {
    if (t[i] == t[i+k]) {
      score[i+k] = 0;
      t[i+k] = 'x';
    }
  }
  // ppa(score);
  // pp(t);
  ll ans = 0;
  rep(i,n) ans += score[i];
  cout << ans << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const  int N=2e5+10;
const int mod = 998244353;
int arr[N];
ll num[N];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&arr[i]);
        num[arr[i]]++;
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        ans += num[i]*(num[i]-1)/2;
    }
    for(int i=1;i<=n;i++){
        ll x = ans - (num[arr[i]] - 1);
        printf("%lld\n",x);
    }
    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans;
  
  ans = min(b, d) - max(a, c);
  if(ans < 0) ans = 0;
  cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc054/tasks/abc054_c
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef set<int> IntSet;
typedef set<int, greater<int>> IntRevSet;

#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

int n, m;
vector<int> v[1000];
int rec(int now, set<int> his) {
    int ans = 0;
    if (his.size() == n) {
        return 1;
    }
    for (auto x : v[now]) {
        if (his.count(x) == 0) {
            set<int> t = his;
            t.insert(x);
            ans += rec(x, t);
        }
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> n >> m;
    REP(i, m) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    set<int> his;
    his.insert(1);
    cout << rec(1, his) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n, w;
    scanf("%d %d", &n, &w);

    vector<pair<int, int>> bg(n);
    REP(i,n){
        scanf("%d %d", &bg[i].first, &bg[i].second);
    }

    vector<int> dp(w + 1, -1);
    dp[0] = 0;
    REP(i,n){
        DEFOR(j,w+1,bg[i].second){
            dp[j] = max(dp[j], dp[j - bg[i].second] + bg[i].first);
        }
    }
    int result = 0;
    DEFOR(i,w+1,0){
        result = max(result, dp[i]);
    }
    cout << result << endl;



    return 0;
}



Measured memory_bytes: 3276
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

int n;
double ans = 1.0;

int main(){
	std::cin >> n;
	ans = n;

	int i = 2;
	while (n != 1){
		bool f = true;
		while(n % i == 0){
			n /= i;
			if (f)ans *= (1.0 - 1.0 / i);
			f = false;
		}
		++i;
	}

	std::cout << (int)ans << std::endl;

	return 0;
}

Measured memory_bytes: 1160
<?php

$str = trim(fgets(STDIN));
$str2 = trim(fgets(STDIN));

$len = strlen($str);
for($i=0; $i<=$len; $i++) {
    if (($isMatch = $str === $str2)) {
        break;
    }
    $str = substr($str, 1).$str[0];
}
echo $isMatch ? 'Yes' : 'No';


Measured memory_bytes: 4728
#include <iostream>
#include <deque>
#include <vector>
using namespace std;
enum Query
{
    push = 0,
    randomAccess = 1,
    pop = 2,
};
std::istream &operator>>(std::istream &is, Query &i)
{
    int tmp;
    if (is >> tmp)
        i = static_cast<Query>(tmp);
    return is;
} //オペレーターオーバーロード
int main()
{
    deque<int> A;
    Query query;
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> query;
        if (query == push) //挿入
        {
            int d, x;
            cin >> d >> x;
            if (d == 0)
            {
                A.push_front(x);
            }
            else if (d == 1)
            {
                A.push_back(x);
            }
        }
        else if (query == randomAccess)
        {
            int p;
            cin >> p;
            cout << A.at(p) << endl;
        }
        else if (query == pop)
        {
            int d;
            cin >> d;
            if (d == 0)
            {
                A.pop_front();
            }
            else if (d == 1)
            {
                A.pop_back();
            }
        }
    }
}


Measured memory_bytes: 4668
#include <stdio.h>
#include <math.h>

int main(void)
{
    int n, s;
    int sn, sn2;
    int i;
    
    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }
        
        sn = sn2 = 0;
        for (i = 0; i < n; i++){
            scanf("%d", &s);
        
            sn += s;
            sn2 += s * s;
        }
        
        printf("%lf\n", sqrt(((double)sn2 - (double)sn * sn / n) / n));
    }

    return (0);
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

int main() {
	optimizar_io
	double L, d1, d2; 

	cin >> L;
	d1 = L / 3.0;
	d2 = L - d1 - d1;
	cout << fixed << setprecision(9) << (d1 * d1 * d2) << "\n"; 
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;

import javax.transaction.xa.Xid;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int n, m;
	static long mod = 998244353;
	static int[][] memo;
	static String s;
	static HashSet<Integer> nodes;
	static HashSet<Integer>[] ad, tree;
	static boolean[] vis, taken;
	static int[] a;
	static TreeSet<Long> al;
	static long[] val;
	static ArrayList<String> aa;
	static char[] b;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		if(sc.nextLine().contains("7"))
			System.out.println("Yes");
		else
			System.out.println("No");
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 32704
#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(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  ll ans = 0;
  int t = n-1;
  rep(i,n){
    int lim = 2;
    if(i==0) lim = 1;
    rep(j,lim){
      if(t > 0){
        ans += a[i];
        t--;
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

bool check(const char c){
    return(c=='A' or c=='C' or c=='G' or c=='T');
}

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

    size_t len{0};

    for(size_t s{0}; s<S.size(); ++s){
        for(size_t n{1}; n<=S.size()-s; ++n){

            string S2 = S.substr(s, n);

            bool result{true};
            for(size_t i{0}; i<S2.size(); ++i){
                if(not check(S2.at(i))){
                    result = false;
                }
            }
            if(result and S2.size()>len){
                len = S2.size();
            }

        }

    }


    cout << len << endl;
}


Measured memory_bytes: 3612
#include<stdio.h>

int func(int i,int j,int k)
{
    int s,t,u;
    s=i+j;
    t=j+k;
    u=k+i;

    if(t>=u&&s>=u){printf("%d",u);}
    else if(s>=t&&u>=t){printf("%d",t);}
    else if(u>=s&&t>=s){printf("%d",s);}  
    
}
int main()
{
    int a, b, c;
    scanf("%d %d %d",&a,&b,&c);

    func(a,b,c);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
using  P=pair<ll,ll>;
int main(){
  ll N;
  cin>>N;
  vector<P> vec;
  for(ll i=0;i<N;i++){
    ll a,b;
    cin>>a>>b;
    vec.push_back(make_pair(b,a));
  }
  sort(vec.begin(),vec.end());
  ll sumtime=0;
  for(ll i=0;i<N;i++){
    //cout<<vec.at(i).first<<" "<<vec.at(i).second<<endl;
    sumtime+=vec.at(i).second;
    if(sumtime>vec.at(i).first){cout<<"No"<<endl;return 0;}
  }
  cout<<"Yes"<<endl;
}

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

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        vec[i] = x;
    }
    int sum = 0;
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
        sum += vec[i] * vec[j];
        }
    }
    
    cout << sum;
}









Measured memory_bytes: 3648
#include <cstdio>
typedef long long ll;
int N ;
ll L[87];
int main ()
{
  scanf ("%d" ,&N);
  L[0]=2LL , L[1]= 1LL;
  for (int i = 2; i <= N ; i++) {
    L[i]= L[i-2] + L[i-1];
  }
  printf ("%lld\n " , L[N]);
}

Measured memory_bytes: 1684
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main (){
    ll n;
    ll mn=1001001001001001;
    cin >> n ;
    rep(i,5){
        ll a;
        cin >> a;
        mn=min(mn,a);
    }
    cout << (n+mn-1)/mn+4 << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map <string,int> mp;
string s;
long long ans=0;
int main(){
	int n;cin>>n;
	while (n--){
		cin>>s;
		sort (s.begin(),s.end());
		ans+=mp[s];
		mp[s]++;
	}
	cout<<ans;
}

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

ans = 0
cnt = 0
m = 10 ** 9
for a in A:
    if a < 0:
        cnt += 1
    ans += abs(a)
    if m > abs(a):
        m = abs(a)

if cnt % 2 == 1:
    print(ans - 2 * m)
else:
    print(ans)


Measured memory_bytes: 14284
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    map<int, int> m;
    REP(i, N) {
        cin >> a.at(i);
        m[a[i]]++;
    }

    priority_queue<int, vector<int>, greater<int>> p;
    for (auto a : m) {
        p.push(a.second);
    }

    ll ans = 0;
    while (p.size() > K) {
        ans += p.top();
        p.pop();
    }

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


Measured memory_bytes: 11516
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	int N;
	cin>>N;
	
	vector<long long> A(1<<N);
	
	long long B = 1000000;
	
	for(int i=0;i<(1<<N);i++){
		scanf("%lld",&A[i]);
	}
	
	vector<vector<pair<long long,long long>>> dp(2,vector<pair<long long,long long>> (1<<N));
	
	for(int i=0;i<=N;i++){
		for(int j=0;j<(1<<N);j++){
			if(i==0){
				dp[0][j] = make_pair(0,A[j]);
			}
			else{
				vector<long long> V;
				V.push_back(dp[1][j].first);
				V.push_back(dp[1][j].second);
				if((j>>(i-1))&1){
					V.push_back(dp[1][j&(~(1<<(i-1)))].first);
					V.push_back(dp[1][j&(~(1<<(i-1)))].second);
				}
				sort(V.rbegin(),V.rend());
				//V.erase(unique(V.begin(),V.end()),V.end());
				dp[0][j].first = V[0];
				dp[0][j].second = V[1];
			}
		}
		swap(dp[0],dp[1]);
	}
	
	vector<long long> ans(1<<N);
	
	for(int i=0;i<(1<<N);i++){
		ans[i] = dp[1][i].first + dp[1][i].second;
		if(i!=0)ans[i] = max(ans[i],ans[i-1]);
	}
	
	for(int i=1;i<(1<<N);i++){
		printf("%lld\n",ans[i]);
		//cout<<ans[i]<<endl;
	}
	
	
	
    return 0;
}

Measured memory_bytes: 15356
grading m f r | elem (-1) [m, f] = "F"
              | m + f >= 80 = "A"
              | m + f >= 65 = "B"
              | m + f >= 50 = "C"
              | m + f >= 30 =
                  if r >= 50 then "C" else "D"
              | otherwise = "F"

main = do
  [m, f, r] <- fmap (map read . words) getLine
  if [m, f, r] == [-1, -1, -1] then
    return ()
  else do
    putStrLn (grading m f r)
    main

Measured memory_bytes: 3796
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define MAX 10000000

int b[110];
bool used[110];
struct edge{int from, to, cost;};

int solve(int a[110][110], int n){
	b[0] = 0;
	//used[0] = true;
	while(1){
		int v = -1;
		for(int i = 0;i < n;i++){
			if(!used[i] && (v == -1 || b[v] > b[i]))v = i;
		}
		if(v == -1)break;
		used[v] = true;
		for(int i = 0;i < n;i++){
			if(a[v][i] != -1)b[i] = min(b[i], b[v] + a[v][i]);
		}
	}
	return 0;
}

int main(){
	int a[110][110], n;
	fill((int*)a, (int*)(a+110), -1);
	fill(b, b+110, MAX);
	fill(used, used, false);
	cin >> n;
	for(int i = 0;i < n;i++){
		int u, k, c, d;
		cin >> u >> k;
		for(int j = 0;j < k;j++){
			cin >> c >> d;
			a[u][c] = d;
		}
	}
	
	solve(a, n);
	for(int i = 0;i < n;i++){
		cout << i << " " << b[i] << endl;
	}
	
	return 0;
}
/*
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
*/

Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

string changeStr(int n){
    string str;
    int copy = n;
    int len = -1;
    while(copy != 0){
        len++;
        copy/=10;
    }
    int K = 1;
    rep(i,len) K*=10;
    rep(i,len + 1){
        if(n / K == 0) str+= '0';
        else str+= ('0' + n / K);
        n%=K; K/=10;
    }
    return str;
}

string solve(string s){
    int count = 1;
    string r;
    rep(i,s.size()){
        if(s[i] == s[i + 1]){
            count++;
            if(i + 1 == s.size()){ //????????????????????????
                r+=( changeStr(count)  + s[i]);
                count = 1;
            }
        }else{
            r+=( changeStr(count)  + s[i]);
            count = 1;
        }
    }
    return r;
}

int main(){
    int n;
    string s;
    while(cin >> n,n){
        cin >> s;
        rep(i,n){
            s = solve(s);
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 1340
N, K = map(int, input().split())
answer = [0] * K
mod = 10**9+7
C_2000 = [0]*2001
C_2000[0] = 1
for i in range(1,2001):
    C_2000[i] = (C_2000[i-1] * i)%mod
def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return (pow_r((x ** 2)%mod, n // 2))%mod
    else:  # standard case ② n is odd
        return (x * pow_r((x ** 2)%mod, (n - 1) // 2))%mod

for i in range(1,K+1):
    M = N-K
    if M - (i-1) < 0:
        answer[i-1] = 0
    else:
        tmp = (C_2000[K-1] * pow_r(C_2000[i-1],mod-2)*pow_r(C_2000[K-i],mod-2))%mod
        tmp = (tmp*C_2000[M+1] * pow_r(C_2000[i],mod-2) * pow_r(C_2000[M+1-i],mod-2))%mod
        answer[i-1] = int(tmp)
print(*answer, sep="\n")

Measured memory_bytes: 44760
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a, b;
  rep(i, n){
    ll x, y;
    cin >> x >> y;
    a.pb(x);
    b.pb(y);
  }
  int kl = 0;
  vector<int> kbit;
  ll ktmp = k;
  while(ktmp){
    kbit.pb(ktmp % 2);
    ktmp /= 2;
    kl++;
  }
  ll res = 0;
  rep(i, kl+1){
    ll ku;
    if(i == kl){
      ku = k;
    }else{
      if(kbit[i] == 0)continue;
      ku = k & ~((ll)1 << i);
      ku = ku | (((ll)1 << i) - 1);
    }
    ll rtmp = 0;
    rep(j, n){
      ll kutmp = ku, atmp = a[j];
      bool flag = true;
      while(atmp){
        if(atmp % 2 == 1 && !(kutmp % 2 == 1)){
          flag = false;
          break;
        }
        atmp /= 2;
        kutmp /= 2;
      }
      if(flag){
        rtmp += b[j];
      }
    }
    res = max(res, rtmp);
  }

  cout << res << endl;
	return 0;
}


Measured memory_bytes: 2036
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  string N;
  cin >> N;
  string N_rev = N;
  reverse(N_rev.begin(), N_rev.end());
  if(N==N_rev)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define llong long long

int main() {
  int w,n;
  scanf("%d %d", &w, &n);
  int data[w+1];
  REP(i,w+1){
    data[i] = i;
  }
  REP(i,n) {
    int a,b;
    scanf("%d,%d", &a, &b);
    swap(data[a],data[b]);
  }
  FOR(i,1,w+1) {
    printf("%d\n",data[i]);
  }
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}


int c[3][3];

int main2() {
  REP(i, 3) REP(j, 3) c[i][j] = nextInt();

  REP(i, 3) {
    int mi = 999;
    REP(j, 3) chmin(mi, c[i][j]);
    REP(j, 3) c[i][j] -= mi;
  }
  bool yes = true;
  REP(i, 3) {
    REP(j, 3) {
      if (c[0][j] != c[i][j]) yes = false;
    }
  }

  cout << (yes ? "Yes":"No") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(n, p);

    vvi dp(n+1, vi(2, 0));
    dp[0][0] = 1;

    rep(i, n) {
        Int(tmp);
        if (tmp % 2) {
            dp[i+1][0] += dp[i][1]; // o
            dp[i+1][0] += dp[i][0]; // x
            dp[i+1][1] += dp[i][0]; // o
            dp[i+1][1] += dp[i][1]; // x
        } else {
            dp[i+1][0] += dp[i][0]; // o
            dp[i+1][0] += dp[i][0];
            dp[i+1][1] += dp[i][1];
            dp[i+1][1] += dp[i][1];
        }
    }

    std::cout << dp[n][p] << endl;

    return 0;
}


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

using namespace std;

const long long MOD = 1000000007;
const int MAX = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  int a;
  cin >> a;
  cout << a+a*a+a*a*a <<endl;
}


Measured memory_bytes: 3636