akhauriyash/Code-Regression huggingface dataset:
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	seg := Segment{}
	seg.init(n)
	for i := 0; i < n; i++ {
		seg.maximize(i, getNextInt(scanner))
	}
	for i := 0; i < m; i++ {
		seg.maximize(seg.top(), seg.bucket[seg.h-1][0]>>1)
	}

	var ans int64
	for i := 0; i < n; i++ {
		ans += int64(seg.bucket[0][i])
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

// Segment ...
type Segment struct {
	n, h, i, chunk int
	unit           []int
	bucket         [][]int
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int, 1)
	seg.bucket[0] = make([]int, n)

	chunk := 16
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
	}
	seg.h = len(seg.unit)
	seg.chunk = chunk
}

func (seg *Segment) maximize(index, value int) {
	seg.bucket[0][index] = value
	for seg.i = 0; seg.i < seg.h-1; seg.i++ {
		s := index - index%seg.chunk
		t := s + seg.chunk
		if t > len(seg.bucket[seg.i]) {
			t = len(seg.bucket[seg.i])
		}
		parent := index / seg.chunk
		max := 0
		for i := s; i < t; i++ {
			if max < seg.bucket[seg.i][i] {
				max = seg.bucket[seg.i][i]
			}
		}
		seg.bucket[seg.i+1][parent] = max
		index /= seg.chunk
	}
}

func (seg *Segment) top() int {
	index := 0
	for seg.i = seg.h - 2; seg.i >= 0; seg.i-- {
		s := index * seg.chunk
		t := s + seg.chunk
		if t > len(seg.bucket[seg.i]) {
			t = len(seg.bucket[seg.i])
		}
		for i := s; i < t; i++ {
			if seg.bucket[seg.i][i] == seg.bucket[seg.i+1][index] {
				index = i
				break
			}
		}
	}

	return index
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, a[100000];
    long long total = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        total += a[i];
    }
    sort(a, a + n, greater<int>());
    int colors = 1;
    for (int i = 1; i < n; ++i) {
        total -= a[i - 1];
        if (a[i - 1] > total * 2) break;
        ++colors;
    }
    cout << colors << '\n';
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        if(n>=10)
        System.out.println(k);
        else
        System.out.println(k+100*(10-n));
        
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

bool cmp(pii& a, pii& b) {
  return a.second < b.second;
}
int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 1;
  ll n;
  cin >> n;
  // ll n, k;
  // cin >> n >> k;
  // ll n, m, k;
  // cin >> n >> m >> k;
  ll arr[n];
  fi(0, n) {
    cin >> arr[i];
  }
  int dir = -1;
  fi(1, n) {
    if(arr[i] == arr[i - 1])
      continue;

    if(dir == -1) {
      dir = arr[i] > arr[i - 1] ? 1 : 0;
      continue;
    }

    if((dir && arr[i] > arr[i - 1]) || (!dir && arr[i] < arr[i - 1]))
      continue;

    ans++;
    dir = -1;
    // dir = arr[i] > arr[i - 1] ? 1 : 0;
  }
  cout << ans << endl;
  return 0;
}



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

int main(int argc, char **argv)
{
    int N;
    std::cin >> N;
    std::vector<int> s(N);
    for(int i = 0; i < N; i++){
        std::cin >> s.at(i);
    }
    
    int sum = 0;
    std::vector<int> not_10x;
    for(int i = 0; i < N; i++){
        sum += s.at(i);
        if(s.at(i) % 10 != 0){
            not_10x.push_back(s.at(i));
        }
    }
    std::sort(not_10x.begin(), not_10x.end());

    if(sum % 10 == 0){
        if(not_10x.size() > 0)
            sum -= not_10x.at(0);
        else
            sum = 0;
    }
    std::cout << sum << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

int main() {
	int n, k;

	std::cin >> n >> k;

	std::vector<int> p(26);
	std::set<std::string> se;
	for (int i = 0; i < n; i++) {
		std::string s;
		std::cin >> s;
		se.insert(s);
	}
	for (auto i : se) {
		p[i[0] - 'A']++;
	}

	int ans = 0;
	while(true){
		int count = 0;
		std::sort(p.begin(), p.end());
		std::reverse(p.begin(), p.end());
		for (int j = 0; j < 26; j++) {
			if (p[j] > 0) {
				p[j]--;
				count++;
			}
			if (count == k) {
				ans++;
				break;
			}
		}
		if (count < k) break;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 1280
a = input()
b = int(len(a))
c = int(0)
d = int(0)
e = int(0)
for i in range(b):
  if a[i] == "W":
    c += 1

for i in range(b):
  if a[i] == "W":
    e = e + int(i) - d
    d += 1

print(e)


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

int main() {
	int n, k;
	cin >> n >> k;
	int arr[1005] = { 0 };
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	int sum = 0;
	for (int i = 0; i < k; i++) {
		sum += arr[i];
	}
	cout << sum;
//	system("pause");
	return 0;
}

Measured memory_bytes: 3200
def gcd(a, b):
  if a <= b:
    a, b = b, a
  while a % b:
  	a, b = b, a % b
  return b

def lcm(a, b):
  return int(a * b / gcd(a, b))

A, B = map(int, input().split())
print(lcm(A, B))


Measured memory_bytes: 2940
n = int(input())
h = list(map(int, input().split()))
flag = 0
result = 1
for i in range(n-1):
	if h[i]==h[i+1]+1 and flag==0:
		flag=1
	elif h[i]==h[i+1] and flag==1:
		continue
	elif h[i]<=h[i+1]:
		flag=0
	else:
		result = 0
if result:
	print("Yes")
else:
	print("No")

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

int main(){

  int N; cin >> N;
  vector<int> v(N);
  for(int i=0; i<N; i++)
    cin >> v.at(i);
  sort(v.begin(), v.end());
  
  double sol = v.at(0);
  for(int i=1; i<N; i++){
    sol = (sol + v.at(i))/2;
  }
  cout << sol << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b/a, c) << endl;
}

Measured memory_bytes: 256
##import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
s=[list(input()) for _ in range(h)]
seen=[[0]*w for _ in range(h)]
d=deque()
ch-=1
cw-=1
dh-=1
dw-=1
res=[]
p=[[0,1],[0,-1],[1,0],[-1,0]]

seen[ch][cw]=1
d.append(ch*w+cw)
ans=0
while True:
    z=d.pop()
    x=z//w #縦
    y=z%w
    res.append([x,y])
    for v in p:
        i,j=v
        if 0<=x+i<h and 0<=y+j<w and seen[x+i][y+j]==0:
            if s[x+i][y+j]==".":
                d.append((x+i)*w+(y+j))
                seen[x+i][y+j]=1
    if seen[dh][dw]==1:
        break
    if not d:
        ans+=1
        for z in res:
            x,y=z
            for i in range(3):
                for j in range(3):
                    if 0<=x+i<h and 0<=y+j<w and seen[x+i][y+j]==0 and s[x+i][y+j]==".":
                        z=(x+i)*w+(y+j)
                        d.append(z)
                        seen[x+i][y+j]=1
                    if 0<=x-i<h and 0<=y-j<w and seen[x-i][y-j]==0 and s[x-i][y-j]==".":
                        z=(x-i)*w+(y-j)
                        d.append(z)
                        seen[x-i][y-j]=1
                    if 0<=x+i<h and 0<=y-j<w and seen[x+i][y-j]==0 and s[x+i][y-j]==".":
                        z=(x+i)*w+(y-j)
                        d.append(z)
                        seen[x+i][y-j]=1
                    if 0<=x-i<h and 0<=y+j<w and seen[x-i][y+j]==0 and s[x-i][y+j]==".":
                        z=(x-i)*w+(y+j)
                        d.append(z)
                        seen[x-i][y+j]=1
        res=[]
    if not d:
        print(-1)
        exit()
print(ans)

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
 rep(i,5){
   int c ; 
   cin >> c ;
   if(c == 0) {
     cout << i +1 ;
     break ;
   }
 }


}


Measured memory_bytes: 3592
N, K = map(int, input().split())

MOD = 10 ** 9 + 7

c = [0] * (K + 1)
for i in range(K, 0, -1):
    t = pow(K // i, N, MOD)
    for j in range(2, K // i + 1):
        t -= c[i * j]
        t %= MOD
    c[i] = t

result = 0
for i in range(1, K + 1):
    result += c[i] * i
    result %= MOD
print(result)


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,k;
    cin >> n >> k;
    vector<int32> a(n);
    int32 sum = 0;
    REP(i,n){
        cin >> a[i];
        sum += a[i];
    }
    vector<int32> div;
    for(int32 x = 1; x * x <= sum; ++x){
        if(sum % x == 0){
            if(x * x == sum){
                div.pb(x);
            }else{
                div.pb(x);
                div.pb(sum / x);
            }
        }
    }
    sort(div.rbegin(), div.rend());
    for(int32 ans : div){
        vector<int32> remain(n);
        REP(i,n){
            remain[i] = (a[i] % ans + ans) % ans;
        }
        sort(ALL(remain));
        vector<int32> psum(n+1,0);
        vector<int32> nsum(n+1,0);
        REP(i,n){
            psum[i+1] = psum[i] + remain[i];
        }
        FORR(i,n-1,0){
            nsum[i] = nsum[i+1] + (ans - remain[i]);
        }
        int32 cnt = INF;
        REP(i,n+1){
            if(psum[i] == nsum[i])cnt = min(cnt,psum[i]);
        }
        // cout << ans << " " << cnt << endl;
        if(cnt > k)continue;
        ANS(ans);
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
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 n; cin >> n;
  vi x(n), y(n);
  rep(i,n) cin >> x[i] >> y[i];
  map<pii,int> pq;
  for(int i = 0; i < n; i++) rep(j,n){
    if(i == j) continue;
    int p = x[i] - x[j];
    int q = y[i] - y[j];
    pq[mp(p,q)]++;
  }
  int ans = n;
  for(auto c : pq) {
    int cnt = c.second;
    chmin(ans, n - cnt);
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
from queue import deque
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

h,w = map(int,stdin.readline().rstrip().split())
ch,cw = map(int,stdin.readline().rstrip().split())
dh,dw = map(int,stdin.readline().rstrip().split())
inf = 10**10

ch -= 1
cw -= 1
dh -= 1
dw -= 1

def main():
    li = [["" for i in range(w)]for j in range(h)]

    for i in range(h):
        s = stdin.readline().rstrip()
        for j in range(w):
            li[i][j] = s[j]

    que = deque()

    mx = []
    my = []

    for i in range(-2,3):
        for j in range(-2,3):
            if i == 0 and j == 0:
                continue
            mx.append(i)
            my.append(j)

    lin = [[inf for i in range(w)]for j in range(h)]
    lin[ch][cw] = 0#ここをスタートの座標に変えること
    que.append((ch,cw))#ここもスタートの座標に変えること

    dx = [1,0,-1,0]
    dy = [0,1,0,-1]

    while que:
        k = que.popleft()
        x = k[0]
        y = k[1]
        no_magic = set()#魔法を使わずに行ける

        for i,j in zip(dx,dy):
            nx = x + i
            ny = y + j

            if nx < 0 or nx >= h or ny < 0 or ny >= w:
                continue
            elif li[nx][ny] == "#":
                continue
            else:
                if lin[nx][ny] > lin[x][y]:
                    que.appendleft((nx,ny))
                    no_magic.add((nx,ny))
                    lin[nx][ny] = lin[x][y]# 直接行ける
        
        for i,j in zip(mx,my):
            nx = x + i
            ny = y + j

            if nx < 0 or nx >= h or ny < 0 or ny >= w:
                continue
            elif li[nx][ny] == "#":
                continue
            else:
                if lin[nx][ny] > lin[x][y]+1:
                    if (nx,ny) not in no_magic:
                        que.append((nx,ny))
                    lin[nx][ny] = lin[x][y]+1# 魔法を使っていける

    if lin[dh][dw] == inf:
        print(-1)
    else:
        print(lin[dh][dw])

if __name__ == "__main__":
    main()

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

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1){
    for(int u : to[v]){
        if(u == p)continue;
        ans[u] += ans[v];
        dfs(u,v);
    }
}
int main(){
    int n,q;
    cin >> n >> q;
    for(int i = 0;i < n - 1;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    for(int i = 0;i < q;i++){
        int p,x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0);

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

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

using namespace std;
typedef long long ll;
typedef vector<ll> vi;

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

	int x;
	for(int i = 0; i < 5; ++i) {
		cin >> x;
		if(x == 0) return cout << i+1 << "\n", 0;
	}

	return 0;
}

Measured memory_bytes: 3648
sx, sy, tx, ty = map(int,input().split())
ans = []
firstup = (ty-sy)*['U']
firstright = (tx-sx)*['R']
firstdown = (ty-sy)*['D']
firstleft = (tx-sx)*['L']
second_offset = ['L']
secoudup = firstup+['U']
secondright = firstright + ['R']
second_offset2 = ['D']
second_offset3 = ['R']
secounddown = firstdown +['D']
secondleft = firstleft + ['L']
second_offset4 = ['U']
ans = firstup+firstright+firstdown+firstleft+second_offset+secoudup+secondright+second_offset2+second_offset3+secounddown+secondleft+second_offset4
print(''.join(ans))


Measured memory_bytes: 3432
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pbi pair<bool,int>
#define pob pop_back
#define all(a) a.begin(),a.end()
#define fio ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define i64 long long int
#define mem(x,y) memset(x,y,sizeof(x))
#define fill(arr,b) fill(arr, arr+sizeof(arr)/sizeof(arr[0]), b)
#define maxarr(n,arr,m) m =-1e9;for(int i=0;i<n;i++)if(arr[i]>m) m=arr[i];
#define read freopen("input.txt","r",stdin);

const double pi = acos(-1.0);
const int maxn = (i64)1e9+7;

int main()
{
    i64 x;
    cin>>x;
    i64 y=100,cnt=0;
    while(y<x)
    {
        y += y/100;
        cnt++;
    }
    cout<<cnt;

    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 1000
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t,a;
    boost;

    cin>>n;
    map<string,vector<pii>> mp;
    rep(i,0,n)
    {
        string s;
        cin>>s>>a;
        if(mp.find(s)!=mp.end())
        {
            mp[s].pb({a,i+1});
        }
        else
        {
            vector<pii> v;
            v.pb({a,i+1});
            mp[s]=v;
        }
    }


    for(auto it=mp.begin();it!=mp.end();it++)
    {
        sort(it->S.begin(),it->S.end());
        for(i=it->S.size()-1;i>=0;i--)
        {
            cout<<it->S[i].S<<'\n';
        }
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int N = 100;
static const int INF = 100000;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];


int prim() {
    int u, minv;
    int color[N], d[N], p[N];
    for (int i = 0; i < n; i++){
        color[i] = WHITE;
        d[i] = INF;
        p[i] = -1;
    }

    d[0] = 0;

    while(true) {
        minv = INF;
        u = -1;
        // Tからの距離がもっとも短いものを次のノードとして選ぶ
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) break; // なければ修了
        color[u] = BLACK; // uをT側に取り込む
        // d[]を更新(Tからの距離を更新)
        for (int v = 0; v < n; v++){
            if (color[v] != BLACK && M[u][v] != INF){
                if (M[u][v] < d[v]) {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] != -1) sum += M[i][p[i]];
    }
    return sum;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int e;
            cin >> e;
            M[i][j] = (e == -1) ? INF : e;
        }
    }

    cout << prim() << endl;

    return 0;
}


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

char tile[30][30];
int W, H;
int ix, iy;
int cnt;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

void dfs(int x, int y){
	tile[y][x] = '#';
	cnt++;
	for (int i = 0; i < 4; i++){
		int X = x + dx[i];
		int Y = y + dy[i];
		if (0<=X && X<W && 0<=Y && Y<H && tile[Y][X]!='#'){
			dfs(X, Y);//関数の再起
		}
	}
}





int main(){

	while (cin >> W >> H, W + H != 0){
		for (int y = 0; y < H; y++){
			for (int x = 0; x < W; x++){
				cin >> tile[y][x];
				if (tile[y][x] == '@'){
					ix = x;
					iy = y;
				}
			}
		}
		dfs(ix, iy);

		cout << cnt << endl;
		cnt = 0;
	}

	return 0;
}



Measured memory_bytes: 3044
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

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

using namespace std;

typedef long long ll;

bool prime_table[300005]; // is_prime[i]がtrueならiは素数

void sieve_of_era(int n) {
  for (int i = 0; i <= n; i++) { prime_table[i] = true; }

  prime_table[0] = false;
  prime_table[1] = false;

  for (int i = 2; i <= n; i++) {
    if (prime_table[i]) {
      for (int j = 2 * i; j <= n; j += i) {
        prime_table[j] = false;
      }
    }
  }
}

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

	sieve_of_era(300000);
  // cnt[x] := (0, x] の素数
  int cnt[300000] = {0}; 
  for (int i = 1; i < 300000; i++) {
    if (prime_table[i]) {
      cnt[i] = cnt[i-1]+1;
    } else {
      cnt[i] = cnt[i-1];
    }
  }

  while (true) {
    int n; cin >> n;
    if (!n) { break; }
    cout << cnt[2*n]-cnt[n] << endl;
  }

  return 0;
}



Measured memory_bytes: 4580
# https://atcoder.jp/contests/abc148/tasks/abc148_c

def gcd(a, b)
  return a if b.zero?
  gcd(b, a % b)
end

# REF:最小公倍数
def lcm(a, b)
  a * b / gcd(a, b)
end

A, B = gets.split.map(&:to_i)

puts lcm(A, B)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const ll modu = 998244353;
#define all(x) (x).begin(),(x).end()

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int N;
    cin >> N;
    vector<int> D(N),E(N);
    REP(i,N)cin >> D[i];
    int maxis = 0;
    ll match = 1;
    REP(i,N){
        if(i == 0)if(D[i] != 0)match = 0;
        E[D[i]]++;
        maxis = max(maxis,D[i]);
    }
    REP(i,maxis+1){
        if(i == 0){
            if(E[0] != 1)match = 0;
        }else{
            ll pow = 1;
            REP(l,E[i]){
                pow*=E[i-1];
                pow%=modu;
            }
            match*=pow;
            match%=modu;
        }
    }
    cout <<match<< "\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);


const int INF = INT_MAX;


int main() {
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i] >> b[i] >> c[i];

    /**
     * dp[i][j]
     * i <= n, j < 3
     * i日めに j(0==A, 1==B, 2==C)をした場合の最大の幸福度
     */
    vector<vector<int>> dp(n+1, vector<int>(3, 0));
    rep(i, n) {
        // Aをやる, その場合は前日にAはできない
        dp[i+1][0] = max(dp[i][1] + a[i], dp[i][2] + a[i]);
        // Bをやる, その場合は前日にBはできない
        dp[i+1][1] = max(dp[i][0] + b[i], dp[i][2] + b[i]);
        // Cをやる, その場合は前日にCはできない
        dp[i+1][2] = max(dp[i][1] + c[i], dp[i][0] + c[i]);
    }

    // n日目に, A,B,C をやったときに一番幸福度が高いのが答え
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;

    return 0;
}


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

using namespace std;

int main() {
	vector<double> length(10);
	double v1, v2;
	char comma;

	while (cin >> length[0]) {
		for (int i = 1;i <= 9;i++) {
			cin >> comma >> length[i];
		}
		cin >> comma >> v1 >> comma >> v2;

		double total = 0;
		for (int i = 0;i < 10;i++) {
			total += length[i];
		}

		double hit = total / (v1 + v2) * v1;

		for (int i = 0;i < 10;i++) {
			hit -= length[i];
			if (hit <= 0) {
				cout << i + 1 << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1224
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int H,W;
    char[][] s;
    int[] dx = {0, 1, 0, -1};
    int[] dy = {-1, 0, 1, 0};

    private void solve() {
        H = nextInt();
        W = nextInt();

        s = new char[H][];
        for(int i = 0;i < H;i++) {
            s[i] = next().toCharArray();
        }

        boolean[][] paint = new boolean[H][W];
        for(int i = 0;i < H;i++) {
            for(int j = 0;j < W;j++) {
                for(int k = 0;k < 4;k++) {
                    int ny = i + dy[k];
                    int nx = j + dx[k];

                    if (ny >= H || ny < 0 || nx >= W || nx < 0) {
                        continue;
                    }

                    if (s[i][j] == '#' && s[ny][nx] == '#') {
                        paint[i][j] = true;
                        paint[ny][nx] = true;
                    }
                }
            }
        }

        for(int i = 0;i < H;i++) {
            for(int j = 0;j < W;j++) {
                if (s[i][j] == '#' && paint[i][j]) {
                    continue;
                }

                if (s[i][j] == '.' && !paint[i][j]) {
                    continue;
                }
                out.println("No");
                return;
            }
        }
        out.println("Yes");
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

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


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

int main(){ //できたじゃねーかよーーー。個数を持つのね。なるほど。
int n,q;
cin >> n;
vector<int> num(100010);
ll sum=0;
rep(i,n){
    int a;
    cin >> a;
    num[a]++;
    sum +=a;
}
vector<ll> s(100010);
cin >> q;
rep(i,q){
    int b,c;
    cin >> b >> c;
    num[c] += num[b];
    s[i]= sum + (c-b)*num[b];
    num[b]=0;
    sum = s[i];
    cout << s[i] << endl;
}

//rep(i,q) cout << s[i] << endl;

}

Measured memory_bytes: 4520
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {

		int X,A,B;
		cin >> X>>A>>B;
		cout <<(X-A)%B << endl;
	
}

Measured memory_bytes: 256
import math
a,b,hour,min = map(int,input().split())

arad = math.radians(360*((hour+min/60)/12))
brad = math.radians(360*min/60)
p = (a*math.cos(arad),a*math.sin(arad))
q = (b*math.cos(brad),b*math.sin(brad))

print(math.dist(p,q))


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

using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;

    if (b - a <= 0) {
        cout << "delicious" << endl;
    } else if (b - a <= x) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
    return 0;
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

typedef vector<map<char, ll>> vmcl;

void Main()
{
  ll n; cin >> n;
  vs s(n); rep(i, n) cin >> s[i];
  vmcl ans(n);
  rep(i, n)
  {
    rep(j, s[i].size())
    {
      if(ans[i].count(s[i][j])) ans[i][s[i][j]]++;
      else ans[i][s[i][j]] = 1;
    }
  }
  /*
  rep(j, n)
  {
    for(char i = 'a';i <= 'z';i++)
    {
      cout << ans[j][i] << " ";
    }
    cout << endl;
  }
  */
  for(char i = 'a';i <= 'z';i++)
  {
    ll A = MAX;
    rep(j, n)
    {
      A = min(A, ans[j][i]);
    }
    rep(k, A)
    {
      cout << i;
    }
  }
  fin("");
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

int main(){
 char b;
  cin >> b;
   if(b =='A') cout << "T" << endl;
   else if(b =='T') cout << "A" << endl;
  else if (b == 'C') cout << "G" << endl;
  else if(b =='G') cout << "C" << endl;
    }

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){	

	int N, K, h[100000], dp[100001];
	cin >> N >> K;
	for(int i = 0; i < N; i++){
		cin >> h[i];
	}
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	dp[2] = abs(h[0] - h[2]);	
	for(int i = 3; i <= K; i++){
		dp[i] = abs(h[0] - h[i]);
	}
	for(int i = K + 1; i < N; i++){
		dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
		for(int j = 2; j <= K; j++){
			dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}
	cout << dp[N - 1] << endl;

	return 0;
}

Measured memory_bytes: 1024
def solve(sa, sb, sc):
    S = {'a': sa, 'b': sb, 'c': sc}
    C = {'a': 0, 'b': 0, 'c': 0}
    turn = 'a'
    while True:
        if C[turn] == len(S[turn]):
            return turn.upper()
        C[turn] += 1
        turn = S[turn][C[turn] - 1]

_sa, _sb, _sc = [input() for _ in range(3)]
print(solve(_sa, _sb, _sc))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define lli long long int
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
#define gcd(A,B) __gcd(A,B)
#define lcm(A,B) A/(__gcd(A,B))*B
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define ld long double
#define modulo 998244353
#define usecppio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<int,double> pid;

int g;
int arr[102000];
int main()
{
    int n;
    scanf("%d",&n);
    for (int i = 0; i<n; i++)
        scanf("%d",arr+i);
    g = arr[0];
    for (int i = 1; i<n; i++)
        g = gcd(arr[i],g);
    printf("%d",g);
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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 &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit
int N, K;
vector<ll> A;

bool check(ll x) {
    ll sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += (A[i] - 1 + x) / x;
    }

    return sum <= K + N;
}


void solve() {
    cin >> N >> K;
    A.resize(N);
    REP(i, N) cin >> A[i];

    ll ng = 0, ok = (ll) 2e9;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if (check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << ok << endl;


}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


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

int main()
{
	long long W, H, x, y;
	long double max;
	long double kouho1, kouho2;
	int flag=0;
	scanf("%lld%lld%lld%lld", &W, &H, &x, &y);
	if (x == 0 || y == 0)
	{
		max = W*H / 2.0;
		
	}
	else if (x == W&&y == H)
	{
		max = W*H / 2.0;
		flag = 0;
	}
	else
	{
		if (x > (W - x))kouho1 = H*(W - x);
		else kouho1 = H*x;

		if (y > (H - y))kouho2 = W*(H - y);
		else kouho2 = W * y;

		if (kouho1 > kouho2)max = kouho1;
		else max = kouho2;

		if (W % 2 == 0 && H % 2 == 0)
		{
			if(x == W / 2 && y == H / 2)flag = 1;
		}

		if(W == H)
		{
			max= W*H / 2.0;
		}
	}
	printf("%llf %d\n", max, flag);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
sum = 0
for i in range(0,N):
  sum = sum + B[A[i]-1]
for i in range(1,N):
  if A[i-1]+1 == A[i]:
    sum = sum + C[A[i-1]-1]
print(sum)

Measured memory_bytes: 3064
#include<stdio.h>

using namespace std;

int main(){
  int a,b,c,x;
  int n=0;
  int i,j,k;
  scanf("%d%d%d%d", &a,&b,&c,&x);
  for(i=0;i<=a;++i){
    for(j=0;j<=b;++j){
      for(k=0;k<=c;++k){
        if(500*i+100*j+50*k==x) ++n;
      }
    }
  }
  printf("%d\n",n);
  return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

//
template <class T>
inline 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;
}
//

long long memo[101010];

long long modpow(long long a, int p) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    int halfP = p / 2;
    long long half = modpow(a, halfP);
    return half * half;
  } else {
    return a * modpow(a, p - 1);
  }
}
long long func(long long a) {
  memo[0] = 0;
  memo[1] = 1;
  if (memo[a] != 0) return memo[a];

  return memo[a] = a * func(a - 1);
}

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

  int n;
  cin >> n;
  vector<string> s(n);
  map<string, lint> mp;
  rep(i, n) {
    string t;
    cin >> t;
    sort(all(t));
    mp[t]++;
  }

  auto it = mp.begin();
  lint ans = 0;
  while (it != mp.end()) {
    // cout << it->second << endl;
    ans += it->second * (it->second - 1) / 2;
    it++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12032
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif /* __DEBUG__ */

int main()
{
  std::string S;
  std::cin >> S;
  
  std::vector<unsigned> v(26, 0);
  for (char c : S) {
    ++v[c - 'a'];
  }
  
  for (unsigned i = 0; i < 26; ++i) {
    if (v[i] == 0) {
      std::cout << static_cast<char>('a' + i) << std::endl;
      return 0;
    }
  }
  
  std::cout << "None" << std::endl;
  
  return 0;
}

Measured memory_bytes: 512
using System;
using System.Linq;

namespace abc088_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(x); Array.Reverse(x);
            int ret = 0;
            for (int i = 0; i < n; i++)
            {
                if (i % 2 == 0)
                {
                    ret += x[i];
                }
                else
                {
                    ret -= x[i];
                }
            }
            Console.WriteLine(ret);
        }
    }
}

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

int num[10];
int a = 0;

int dfs(int i) {
	if (i == 9) {
		int s[10] = {};
		for (int j = 0; j < 9; j++) {
			s[num[j]]++;
			if (s[num[j]] > 1) return 0;
		}
	
		int a = num[0];
		int b = num[1] * 10 + num[2];
		int c = num[3] * 100 + num[4] * 10 + num[5];
		int d = num[6] * 100 + num[7] * 10 + num[8];
		
		if (a + b + c == d) return 1;
		else return 0;
	}
	
	int d = 0;
	
	if (num[i] != -1) {
		d += dfs(i + 1);
	}
	else {
		for (int j = 1; j < 10; j++) {
			num[i] = j;
			d += dfs(i + 1);
		}
		num[i] = -1;
	}
	
	return d;
}

int main() {
	
	for (int i = 0; i < 9; i++) {
		cin >> num[i];
		if (num[i] == -1) a++;
	}
	
	if (a == 9) {
		cout << 168 << endl;
	}
	else {
		cout << dfs(0) << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;


int main(){
    string s; cin >> s;
    int k; cin >> k;

    rep(i, s.size()){
        if(s[i] == 'a') continue;
        if(k >= ('z' - s[i] + 1)){
            k -= (('z' - s[i]) + 1);
            s[i] = 'a';
        }
    }
    k %= 26;
    rep(i, k){
        if(s[s.size() - 1] == 'z') s[s.size() - 1] = 'a';
        else s[s.size() - 1]++;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

int N, M, P, K, L;
bool T[200][200];

int main(void) {
  while(cin >> N, N) {
    REP(i, 0, 200) REP(j, 0, 200) T[i][j] = false;
    REP(i, 1, N + 1) {
      cin >> M;
      REP(j, 0, M) {
        cin >> P;
        T[i][P] = true;
      }
    }

    cin >> K;
    vector<int> R;
    REP(i, 0, K) {
      cin >> L;
      R.push_back(L);
    }

    int ans = -1;
    REP(i, 1, N + 1) {
      bool f = true;
      REP(j, 0, R.size()) if(!T[i][R[j]]) f = false;
      if(f) {
        if(ans == -1) ans = i;
        else {
          ans = -1;
          goto END;
        }
      }
    }

END: cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main()
{
    long long N ,A, B;
    cin >> N >> A >> B;
    if (N <= A)
    {
        cout << N << endl;
        return 0;
    }

    long long p = (N / (A + B)) * A;
    long long q = (N % (A + B));
    if (q > A) q = A;
    long long ans = p + q;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
typedef long long int LL;
vector<LL> v1[2];

LL abst(LL a){
	if(a<0)return -a;
	return a;
}

int main(){
	int n;
	int i,j,k;
	LL a,b,c;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a>>b;
		v1[0].push_back(b);
		v1[1].push_back(a);
	}
	sort(v1[0].begin(),v1[0].end());
	sort(v1[1].rbegin(),v1[1].rend());
	
	a=0,b=0;
	for(i=0;i<n;i++){
		if(v1[0][i]>=a){b+=abst(a);break;}
		b+=a-v1[0][i];
		a=v1[0][i];
		if(v1[1][i]<=a){b+=abst(a);break;}
		b+=v1[1][i]-a;
		a=v1[1][i];
	}
	a=0,c=0;
	for(i=0;i<n;i++){
		if(v1[1][i]<=a){c+=abst(a);break;}
		c+=v1[1][i]-a;
		a=v1[1][i];
		if(v1[0][i]>=a){c+=abst(a);break;}
		c+=a-v1[0][i];
		a=v1[0][i];
	}
	if(b<c)b=c;
	cout<<b<<endl;
	return 0;
}
		


Measured memory_bytes: 2036