akhauriyash/Code-Regression huggingface dataset:
n = int(input())

s =[[] for _ in range(n)]

for i in range(n):
    a_tmp = int(input())
    for _ in range(a_tmp):
        x,y = map(int,input().split())
        s[i].append([x,y])

#print(s)

mx = 2**n


def hantei(num):
    flag=0
    bi =[0 for _ in range(n)]
    for j in range(n):
        bi[j] = (num>>j)%2
    
    for j in range(n):
        if((num>>j)%2 == 1):
            for x,y in s[j]:
                if(y != bi[x-1]):
                    flag = 1
                    return flag
    
    return flag

ans = 0 
for i in range(mx):
    if(hantei(i) == 0):
        #print(i)
        ans = max(ans,bin(i)[2::].count("1"))
        
print(ans)

#print(bin(3)[2::].count("1"))
#print(hantei(3))

Measured memory_bytes: 3064
H, W = gets.split.map(&:to_i)
board = H.times.map { gets.chomp }

ans =
  [
    '#' * (W + 2),
    board.map do |row|
      '#' + row + '#'
    end,
    '#' * (W + 2)
  ].flatten.join("\n")
puts ans


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

using namespace std;

int main(){
	int N, M;
	while(cin >> N >> M){
		vector<vector<int>> X(M);
		for(int i=0;i<N;i++){
			int x; cin >> x;
			X[x%M].push_back(x);
		}
		int res = X[0].size()/2;
		for(int i=1;i<=M-i;++i){
			if(i == M-i){
				res += X[i].size()/2;
			} else {
				auto cnt = [](vector<int>& v) -> int {
					int res = 0;
					sort(v.begin(), v.end());
					for(int j=0;j+1<v.size();++j){
						if(v[j] == v[j+1]){
							++res;
							++j;
						}
					}
					return res;
				};
				int c1 = cnt(X[i]);
				int c2 = cnt(X[M-i]);
				int p = min(X[i].size(), X[M-i].size());
				res += p;
				res += min(c1, ((int)X[i].size()-p)/2);
				res += min(c2, ((int)X[M-i].size()-p)/2);
			}
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
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;
}
int main() {
ll n,t,a;
cin >> n >> t >> a;
ll h[n];
for (ll i = 0; i < n; i++){
    cin >> h[i];
}
long double temp[n];
for (ll i = 0; i < n;i++){
    temp[i] = t - 0.006 * h[i];
}
long double dist = 1e9;
ll ans = 0;
for (ll i = 0; i < n; i++) {
    if(chmin(dist,abs(a-temp[i]))){
        ans = i+1;
    }
}
cout << ans << endl;
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    string A, B, C;
    cin >> N >> A >> B >> C;

    int ret = 0;

    for (int i = 0; i < N; i++) {
        if (A[i] != B[i] && B[i] != C[i] && C[i] != A[i]) {
            ret += 2;
            continue;
        }

        if (A[i] != B[i] || B[i] != C[i] || C[i] != A[i]) {
            ret++;
            continue;
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
/*input
5 2
2 4 5 1 3
3 4 -10 -8 8
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=5e3+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=3.14159265358979323846;
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    ll res=0LL;
    while(b){
        if(b&1) res=(res+a)%MOD;
        a=(a+a)%MOD;
        b>>=1;
    }
    return res%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
ll c[maxn],p[maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    ll n,k;
    cin>>n>>k;
    REP(i,n) cin>>p[i],--p[i];
    REP(i,n) cin>>c[i];
    ll ans=-INF64;
    REP(i,n){
        ll cur=0;
        ll mx=-INF64;
        ll mx2=-INF64;
        int a=i;
        ll stps=1;
        a=p[a];
        while(a!=i){
            ++stps;
            a=p[a];
        }
        REP(j,min(stps,k)){
            cur+=c[p[a]];
            MXTO(ans,cur);
            MXTO(mx,cur);
            if(j<(k%stps)){
                MXTO(mx2,cur);
            }
            a=p[a];
        }
        if(k>stps){

            if(cur>0) MXTO(ans,max(cur*(k/stps)+mx2,mx+cur*(k/stps-1)));
        }
    }
    cout<<ans;
}



Measured memory_bytes: 3728
#include <string.h>

char *suits = "SHCD";
int cards[4][13];

int indexof(char *str, char ch) {
	return (int)(strchr(str, ch) - str);
}

int main() {
	char suit;
	int n, rank, i, j;
	scanf("%d\n", &n);
	for (; n > 0; n--) {
		scanf("%c %d\n", &suit, &rank);
		cards[indexof(suits, suit)][rank - 1] = 1;
	}
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			if (!cards[i][j]) {
				printf("%c %d\n", suits[i], j + 1);
			}
		}
	}
}


Measured memory_bytes: 2064
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

		int n = sc.nextInt();
		String[] s = new String[n];
		Set<String> set = new HashSet<>();
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			s[i] = str;
			set.add(str);
		}

		int m = sc.nextInt();
		String[] t = new String[m];
		for (int i = 0; i < m; i++) {
			t[i] = sc.next();
		}

		int max = 0;
		for (String key : set) {
			int plus = 0;
			for (String strS : s) {
				if (key.equals(strS))
					plus++;
			}
			int minus = 0;
			for (String strT : t) {
				if (key.equals(strT))
					minus++;
			}
			// debug
//			System.out.println("key : " + key);
//			System.out.println(" plus : " + plus);
//			System.out.println(" minus : " + minus);

			int tmp = plus - minus;
			if (tmp > max)
				max = tmp;
		}
		System.out.println(max);

		sc.close();
	}
}


Measured memory_bytes: 23252
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, readline().split())
V = list(map(int, readline().split()))

MAX = min(N, K) + 1

ans = 0
for a in range(MAX):
    for b in range(MAX):
        if a + b >= MAX:
            continue
        jewels = []
        for i in range(a):
            jewels.append(V[i])
        for j in range(b):
            jewels.append(V[-(j + 1)])
        jewels = sorted(jewels)
        total = sum(jewels)
        if K - (a + b) <= 0:
            ans = max(total, ans)
            continue
        for i in range(K - a - b):
            if i < len(jewels) and jewels[i] < 0:
                total += abs(jewels[i])
        ans = max(total, ans)
print(ans)

Measured memory_bytes: 3440
#include <stdio.h>
int main(void)
{
	int a, b;
	int syu;
	int menseki;

	scanf("%d%d", &a, &b);
	menseki = a * b;
	printf("%d", menseki);
	syu = a * 2 + b * 2;
	printf(" %d\n", syu);
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    vector<int> a;
    vin(a,3);
    sort(a.begin(), a.end());
    int sum = 0;
    rep(i, 3) sum += a[i];
    if (a[2]%2 == sum%2) {
        cout << (a[2]*3-sum)/2 << endl;
    }
    else {
        cout << ((a[2]+1)*3-sum)/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s[3];
  cin>>s[0]>>s[1]>>s[2];
  int turn=0;
  char ans;
  while(1){
    if(s[turn].empty()){
      ans=turn+'A';
      break;
    }
    int tmp=s[turn][0]-'a';
    s[turn].erase(s[turn].begin());
    turn=tmp;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import math
abx = input().split(' ')

a = int(abx[0])
b = int(abx[1])
x = int(abx[2])

all_S =a*a*b
empty_area = all_S -x
#print(x,empty_area)
if empty_area > x:
    small_s = (all_S/2) - (empty_area - (all_S/2))
    y = ((small_s*2)/(a*b) -a) *(-1)
    sita = math.degrees(math.atan((a - y)/b))
    print(90 - sita)
else:
    y = ((empty_area*2/(a*a))-b) * (-1)
    #print(y)
    sita = math.degrees(math.atan((b - y)/a))
    print(sita) 

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

int main() {
  string s, t;
  cin >> s >> t;
  vector<vector<int>> v(s.size(), vector<int>(1 << 8, -1));
  for (int _ = 0; _ < 2; _++) {
    for (int i = s.size() - 1; i >= 0; i--) {
      int j = (s.size() + i - 1) % s.size();
      v[j] = v[i];
      v[j][s[i]] = i;
    }
  }
  ll r = 0, p = 0;
  bool b = false;
  for (int i = s[0] == t[0]; i < t.size(); i++) {
    if (v[p][t[i]] == -1) {
      b = true;
      break;
    }
    if (v[p][t[i]] <= p) r++;
    p = v[p][t[i]];
  }
  cout << (b ? -1 : r * int(s.size()) + p + 1) << endl;
}


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

int main(){
    while(1){
        int n; cin>>n;
        if(n == 0) return 0;
        for(int i=0; i<n; i++){
            int x1, y1, z1, w1, x2, y2, z2, w2;
            cin>>x1>>y1>>z1>>w1>>x2>>y2>>z2>>w2;

            int x3 = x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2;
            int y3 = x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2;
            int z3 = x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2;
            int w3 = x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2;

            cout << x3 << " " << y3 << " " << z3 << " " << w3 << endl;
        }
    }
}



Measured memory_bytes: 3084
#-------------------------------------------------------------------------------
# coding: utf-8
# Created:     16/12/2015

import sys
io = sys.stdin

while True:
    arr = io.readline().split()
    h, w = int(arr[0]), int(arr[1])
    if h==0 and w ==0 : break

    for x in xrange(h):
        print "#"*w
    print

pass

Measured memory_bytes: 6428
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

type Bfs struct {
	Maze [][]int
	Res  [][]int

	Deque *list.List

	Height int
	Width  int

	GoalH int
	GoalW int
}

func NewBfs(maze [][]int, h, w, gh, gw int) *Bfs {
	bfs := &Bfs{
		Maze:   maze,
		Deque:  list.New(),
		Height: len(maze),
		Width:  len(maze[0]),
		GoalH:  gh,
		GoalW:  gw,
	}

	bfs.Res = make([][]int, bfs.Height)
	for i := 0; i < bfs.Height; i++ {
		bfs.Res[i] = make([]int, bfs.Width)
		for j := 0; j < bfs.Width; j++ {
			bfs.Res[i][j] = 100000000
		}
	}

	bfs.Deque.PushBack([]int{h, w, 0})
	return bfs
}

func (b *Bfs) debugRes() {
	fmt.Println("<----")
	for _, v := range b.Res {
		fmt.Println(v)
	}
	fmt.Println("---->")
}

func (b *Bfs) debugDeque() {
	for v := b.Deque.Front(); v != nil; v = v.Next() {
		fmt.Println(v)
	}
}

func (b *Bfs) search() int {
	for b.Deque.Len() > 0 {
		elm := b.Deque.Front()
		q := elm.Value.([]int)
		h, w, cost := q[0], q[1], q[2]
		b.Deque.Remove(elm)

		if h == b.GoalH && w == b.GoalW {
			return cost
		}

		dirH := []int{0, -1, 1, 0, 0}
		dirW := []int{0, 0, 0, -1, 1}
		// cost 0
		for i := 0; i < 5; i++ {
			checkH := h + dirH[i]
			checkW := w + dirW[i]

			if checkH < 0 || checkH > (b.Height-1) {
				continue
			}
			if checkW < 0 || checkW > (b.Width-1) {
				continue
			}
			if b.Res[checkH][checkW] <= cost {
				continue
			}

			if b.Maze[checkH][checkW] == 0 {
				b.Res[checkH][checkW] = cost
				if i > 0 {
					b.Deque.PushFront([]int{checkH, checkW, cost})
				}
			} else {
				b.Res[checkH][checkW] = -1
			}
		}

		// cost 1
		for i := -2; i <= 2; i++ {
			for j := -2; j <= 2; j++ {
				checkH := h + i
				checkW := w + j

				if checkH < 0 || checkH > (b.Height-1) {
					continue
				}
				if checkW < 0 || checkW > (b.Width-1) {
					continue
				}
				if i == 0 && j == 0 {
					continue
				}
				if b.Res[checkH][checkW] <= cost+1 {
					continue
				}

				if b.Maze[checkH][checkW] == 0 {
					b.Res[checkH][checkW] = cost + 1
					b.Deque.PushBack([]int{checkH, checkW, cost + 1})
				} else {
					b.Res[checkH][checkW] = -1
				}
			}
		}
	}
	return -1
}

func main() {
	sc.Split(bufio.ScanWords)

	h, w := nextInt(), nextInt()
	ch, cw := nextInt(), nextInt()
	dh, dw := nextInt(), nextInt()

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

	maze := make([][]int, h)
	maze[0] = make([]int, w)

	for i := 0; i < h; i++ {
		maze[i] = make([]int, w)
		n := nextString()
		for j, v := range n {
			if v == '#' {
				maze[i][j] = 1
			} else {
				maze[i][j] = 0
			}
		}
	}

	b := NewBfs(maze, ch, cw, dh, dw)
	ans := b.search()
	fmt.Println(ans)
}


Measured memory_bytes: 37556
using namespace std;

#include <cstdio>
#include <cstdint>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

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

    int     K = 0;
    int     A = 0;
    int     B = 0;
    cin >> K;
    cin >> A >> B;

    string  ans = "NG";

    int k = 0;
    for(k = A; k < B+1; k++){
        if(k%K == 0){
            ans = "OK";
        }
    }
    cout << ans << "\n";
    return 0;
    
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;

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

    vector<ll> A(N+1, 0);
    vector<ll> B(N, 0);
    for(int i = 0; i < N+1; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];

    ll count = 0;

    for(int i = N-1; i >= 0; i--) {
        ll Bi = B[i];
        ll tmp = 0;
        tmp = max(B[i]-A[i+1], (ll)0);
        A[i+1] -= B[i] - tmp;
        B[i] = tmp;

        tmp = max(B[i]-A[i], (ll)0);
        A[i] -= B[i] - tmp;
        B[i] = tmp;
        count += Bi - tmp;
    }

    cout << count << endl;


}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String ans ;
		String A = S.replace("eraser","");
		String B = A.replace("erase","");
		String C = B.replace("dreamer","");
		String D = C.replace("dream","");
		if(D.length() == 0){
			ans = "YES";
		}else{
			ans = "NO";
		}
			System.out.println(ans);
	}
}


Measured memory_bytes: 28376
// #includes {{{
#include <bits/stdc++.h>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

int x,y;

int main(){
	cin>>x>>y;
	Int ans0 = 0x3f3f3f3f3f3f3f3fll;
	REP(b,0x100){
		Int ans = __builtin_popcount(b);
		Int x0=x,y0=y;
		if(b&1)x0*=-1;
		if(b&2)y0*=-1;
		if(x0>y0)continue;
		ans+=y0-x0;
		ans0=min(ans,ans0);
	}
	cout<<ans0<<endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> xs(n);
    for (int i = 0; i < n; i++) {
        cin >> xs[i];
    }
    int min = 10000000;
    for (int p = 1; p <= 100; p++) {
        int s = 0;
        for (int x : xs) {
            s += (x - p) * (x - p);
        }
        if (min > s) {
            min = s;
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int dp[1 << 12][1000];
int a[1000], mask[1000];
constexpr int inf = 1e9;

template <class T, class U> inline void smax(T &a, U b) { a = a > b ? a : b; }
template <class T, class U> inline void smin(T &a, U b) { a = a < b ? a : b; }

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < 1 << n; i++) for(int j = 0; j < m; j++) dp[i][j] = inf;
  for(int i = 0; i < m; i++) {
    int b;
    cin >> a[i] >> b;
    for(int j = 0; j < b; j++) {
      int c;
      cin >> c;
      mask[i] |= 1 << (c - 1);
    }
  }
  dp[mask[0]][0] = a[0];
  dp[0][0] = 0;
  for(int i = 0; i < 1 << n; i++)
  for(int j = 1; j < m; j++)
  {
    smin(dp[i | mask[j]][j], dp[i][j-1] + a[j]);
    smin(dp[i][j], dp[i][j-1]);
  }
  int ans = inf;
  smin(ans, dp[(1 << n) - 1][m-1]);
  if(ans == inf) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 16256
#include <iostream>
#include <bits/stdc++.h>
#define PB push_back
#define F(i,a,b)  for(i=a;i<b;i++)
#define FE(i,a,b)  for(i=a;i<=b;i++)
#define FR(i,a,b) for(i=a;i>b;i--)
#define LL long long
#define MAX(a,b) (a<b?b:a)
#define ABS(x) (x<0?(-x):x)
#define ALL(c) (c).begin(),(c).end()
#define WATCH(x) cout << (#x) << " is " << (x) << endl
#define vi vector<int>
#define vs vector<string>
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
using namespace std;
string ConvertToBin(LL s)
{
    string res = "";
    while(s != 0) {
        res += (char)('0' + s % 2);
        s /= 2;
    }
    reverse(res.begin() , res.end());
    return res;
}

void PrintVec(vector<int> &v)
{
    for(vector<int>::iterator it = v.begin() ; it != v.end(); ++it)
    cout<<*it<<" ";
}

vector<int> Populate(vector<int> &v,int n)
{
    int num;
    for(int i=0;i<n;i++)
    {
        cin>>num;
        v.push_back(num);
    }
    return(v);
}

int sumofdigits(int n)
{
    int sm=0;
    while(n)
    {
        sm=sm+(n-(n/10)*10);
         n=n/10;
    }
    return(sm);
}

bool isprime(int n)
{
    int i=0;
    FE(i,2,sqrt(n))
    {
        if(n%i==0)
        return(false);
    }
    return(true);
}







/*--------------------------time to code-------------------------------*/



int main()
{
    int n;
    cin>>n;
    int arr[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        cin>>arr[i][j];
    }
  //  for(int i=0;i<n;i++)
    int ans[n+1][3];
    for(int i=0;i<3;i++)
    ans[0][i]=0;
    for(int i=1;i<n+1;i++)
    {
        ans[i][0]=arr[i-1][0]+max(ans[i-1][1],ans[i-1][2]);
        ans[i][1]=arr[i-1][1]+max(ans[i-1][0],ans[i-1][2]);
        ans[i][2]=arr[i-1][2]+max(ans[i-1][0],ans[i-1][1]);
    }
    cout<<max(ans[n][0],max(ans[n][1],ans[n][2]));
    return(0);
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    string l;
    cin>>l;
    int n=l.size();
    ll dp[n][2];
    dp[0][0]=2;
    dp[0][1]=1;
    for(int i=0;i<n-1;i++){
        if(l[i+1]=='0'){
            dp[i+1][0]=dp[i][0]%MOD;
            dp[i+1][1]=3*dp[i][1]%MOD;
        }else{
            dp[i+1][0]=2*dp[i][0]%MOD;
            dp[i+1][1]=(dp[i][0]+3*dp[i][1])%MOD;
        }
    }
    cout<<(dp[n-1][0]+dp[n-1][1])%MOD<<endl;
}


Measured memory_bytes: 2048
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        HashSet<String> l = new HashSet<String>();

        for(int i = 0; i < n; i++){
            String output = scanner.next();
            if(output.equals("insert")){
                l.add(scanner.next());
            }else{
                if(l.contains(scanner.next())){
                    System.out.println("yes");
                }else{
                    System.out.println("no");
                }
            }
        }
    }
}



Measured memory_bytes: 258708
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int a,b;  cin >> a >> b;
  if(8 < max(a,b)){
    cout << ":(";
  }else{
    cout << "Yay!";
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int d=sc.nextInt();

		ArrayList<ArrayList<Integer>> x = new ArrayList<>();
		for(int i=0; i<n; i++) {
			ArrayList<Integer> t = new ArrayList<>();
			for(int j=0; j<d; j++) {
				t.add(sc.nextInt());
			}
			x.add(t);
		}

		int ans = 0;
		for(int i=1; i<n; i++) {

			for(int j=0; j<i; j++) {
				long s = 0;
				for(int k=0; k<d; k++) {
					int y=x.get(i).get(k);
					int z=x.get(j).get(k);
					s += Math.abs(y-z)*Math.abs(y-z);
				}
				double sq = Math.sqrt(s);
				int sd = (int)sq;
				if(sq-sd==0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 35796
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

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

    int ans =0;
    for (int i=0;i<n;i++) {
        int c=0;
        while (a[i]%2==0) {
            a[i] /= 2;
            c++;
        }
        ans += c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

using namespace std;
using ll = long long;
using P = pair<int,int>;

int main()
{


    int n ; cin>>n;
    map<string,int> cnt;
    int mx = 0 ;
    for(int i = 0 ; i<n ; i++)
    {
        string g;
        cin>>g;
        cnt[g]++;
        mx = max(mx , cnt[g]);
    }

    vector<string> v;
    for(auto x : cnt)
    {
        if(x.second == mx)
        {
            v.push_back(x.first);
        }
    }
    sort(v.begin() , v.end());
    for(auto x : v)
    {
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 28784
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    String s = scan.next();
    if(a>=3200){
      System.out.println(s);
    }
    else{
      System.out.println("red");
    }
  }
}


Measured memory_bytes: 21844
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 0
e = max(c)
if b in c:
    print("POSSIBLE")
    exit()
if e < b:
    print("IMPOSSIBLE")
    exit()
for i in c:
    d = g_c_d(d, i)
for i in c:
    if (i - b) % d == 0:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")
exit()


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

int n,q,ans = 0;
char t[200010],d[200010];
string s;

bool C(int x){
	for(int i = 0;i < q;i++){
		if(s[x] == t[i]){
			x += (d[i] == 'L') ? -1 : 1;
		}
		if(x < 0) return true;
		if(x >= n) return false;
	}
	return false;
}

signed main(){
	cin >> n >> q >> s;
	for(int i = 0;i < q;i++){
		cin >> t[i] >> d[i];
	}
	for(int a = 0;a < 2;a++){
		int low = -1,up = n;
		while(up - low > 1){
			int mid = (up + low) / 2;
			if(C(mid)) low = mid;
			else up = mid;
		}
		ans += low + 1;
		reverse(s.begin(),s.end());
		for(int i = 0;i < q;i++){
			d[i] = ((d[i] == 'L') ? 'R' : 'L');
		}
	}
	cout << n - ans << endl;
}

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

bool is_different(int Li, int Lj, int Lk) {
  return Li != Lj && Lj != Lk && Lk != Li;
}

bool can_make_triangle(int Li, int Lj, int Lk) {
  return (Li > Lj && Li > Lk && Li < Lj + Lk) ||
         (Lj > Lk && Lj > Li && Lj < Lk + Li) ||
         (Lk > Li && Lk > Lj && Lk < Li + Lj);
}

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

  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }

  int num_cases = 0;
  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      for (int k = j + 1; k < N; k++) {
        if (!is_different(L.at(i), L.at(j), L.at(k))) continue;
        if (can_make_triangle(L.at(i), L.at(j), L.at(k))) num_cases++;
      }
    }
  }

  cout << num_cases << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	ll n;
	cin>>n;
	for(ll i=0;i<s.size();i++){
		if(s[i]=='a'){
			continue;
		}
		else if('z'-s[i]+1<=n){
			n-='z'-s[i]+1;
			s[i]='a';
		}
	}
	for(ll i=s.size()-1;i>=0;i--){
		if(s[i]=='a'){
			continue;
		}
		else{
			s[i]=s[i]+n;
			n=0;
			break;
		}
	}
	if(n!=0){
		n%=26;
		s[s.size()-1]=s[s.size()-1]+n;
	}
	cout <<s;
	// your code goes here
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
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 ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int> > Matrix;
const int MOD = 1e9+7;

int main(){
string s[3]; REP(i,3)cin>>s[i];

int l=0,k=0,m=0;
char turn='a';
char res;
while(1){
  if(turn=='a'){
     if(l==s[0].size()){
         res='A';
         break;
     }
      turn=s[0][l];
      l++;
  }else if(turn=='b'){
     if(k==s[1].size()){
         res='B';
         break;
     }
      turn=s[1][k];
      k++;
      
  }else if(turn=='c'){
     if(m==s[2].size()){
         res='C';
         break;
     }
      turn=s[2][m];
      m++;
  }
}
cout<<res<<endl;
}

Measured memory_bytes: 256
N = int(input())
arr = []
for i in range(N):
  arr.append(int(input()))
max_inds = []
max_v = arr[0]
for i in range(N):
  if arr[i] > max_v:
    max_v = arr[i]
for i in range(N):
  if arr[i] == max_v:
    max_inds.append(i)
for i in range(N):
  if len(max_inds) >= 2:
    print(max_v)
  else:
    if i == max_inds[0]:
      cop = arr.copy()
      del cop[i]
      print(max(cop))
    else:
      print(max_v)


Measured memory_bytes: 20444
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

class BinaryIndexedTree {
public:
    BinaryIndexedTree(ll N) : N_(N), bit_(N + 1, 0) {}
    void add(ll a, ll w) {
        for (ll x = a; x <= N_; x += (x & -x)) {
            bit_[x] += w;
        }
    }
    ll sum(ll a) {
        ll result = 0;
        for (ll x = a; x > 0; x -= (x & -x)) {
            result += bit_[x];
        }
        return result;
    }
private:
    ll N_;
    vector<ll> bit_;
}; 

int main() {
    ll N, M;
    cin >> N >> M;

    struct P {
        ll l, r;
        bool operator<(const P& rhs) const {
            return r - l < rhs.r - rhs.l;
        }
    };

    vector<P> ps(N);
    for (ll i = 0; i < N; i++) {
        cin >> ps[i].l >> ps[i].r;
    }
    sort(ps.begin(), ps.end());

    BinaryIndexedTree bit(M + 1);

    ll c = 0;
    //O(M)のループ
    for (ll d = 1; d <= M; d++) {
        //幅がd未満のものを数えておく
        //d自体のループに含まれているわけではないのでこのループはO(M)とは別にO(N)
        while (c < N && (ps[c].r - ps[c].l) < d) {
            //bit使っているのでここでO(log M),全体O(N log M)
            bit.add(ps[c].l, 1);
            bit.add(ps[c].r + 1, -1);
            c++;
        }

        //幅がd以上の駅には必ず停まることができる
        ll ans = N - c;

        //それ未満の場合はシミュレーション
        //このループはO(log d)なので間に合う
        for (ll i = 0; i <= M; i += d) {
            //ここでO(log M).全体でO(M (log M)^2)
            ans += bit.sum(i);
        }
        cout << ans << endl;
    }
}

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

#define int long long

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

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

signed main(){
    int N;cin>>N;

    int K=-1;
    for(int i=1;i<=111111;i++)if(i*(i-1)/2==N)K=i;

    if(K==-1){
        cout<<"No"<<endl;
        return 0;
    }

    vector<vint>S(K);
    int u=0,v=1;
    rep(i,N){
        S[u].pb(i);S[v].pb(i);
        if(v==K-1){
            u++;
            v=u+1;
        }
        else{
            v++;
        }
    }
    cout<<"Yes"<<endl;
    cout<<K<<endl;
    rep(i,K){
        cout<<S[i].size();
        rep(j,S[i].size())cout<<" "<<S[i][j]+1;
        cout<<endl;
    }
}


Measured memory_bytes: 3200
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  l <- unsafeTextToDouble <$> T.getLine :: IO Double
  print $ l ^ 3 / 27

unsafeTextToDouble :: T.Text -> Double
unsafeTextToDouble s = case T.double s of
  Right (x, _) -> x


Measured memory_bytes: 508
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Tue Feb 11 19:59:55 JST 2020
 **/

signed main() {
    Int a, b;
    cin >> a >> b;
    string x(b, '0' + a), y(a, '0' + b);
    cout << min(x, y) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

class unionFindTree {
private:
	vector <int> tree;
	vector <int> rank;

public:
	unionFindTree() {}

	unionFindTree(int sz) {
		tree = vector <int> (sz);
		for(int i = 0; i < tree.size(); i++) {
			tree[i] = i;
		}
		rank = vector <int> (sz, 0);
	}

	unionFindTree(const unionFindTree &o) {
		tree = o.tree;
		rank = o.rank;
	}

	unionFindTree &operator=(const unionFindTree &o) {
		tree = o.tree;
		rank = o.rank;
		return (*this);
	};

	int root(int x) {
		return tree[x] == x ? x : tree[x] = root(tree[x]);
	}

	bool same(int a, int b) {
		return root(a) == root(b);
	}

	void unite(int a, int b) {
		a = root(a);
		b = root(b);
		if(a == b)return;

		if(rank[a] < rank[b]) swap(a, b);

		tree[b] = a;
		rank[a] += rank[a] == rank[b];
	}

	int size() {
		return tree.size();
	}
};

class Kruskal : public unionFindTree{
private:
	struct edge {
		int u, v, cost;
		bool operator< (const edge& e) const {
			return cost < e.cost;
		}
	};
	vector <edge> es;
	int V;

public:
	Kruskal(int v, int e) : unionFindTree(v){
		V = v;
		es = vector <edge> (e);
	}

	void addEdge(int start, int end, int cost) {
		es.push_back({start, end, cost});
	}

	int execute() {
		sort(es.begin(), es.end());
		int res = 0;
		for(int i = 0; i < es.size(); i++) {
			edge e = es[i];
			if(!same(e.u, e.v)) {
				unite(e.u, e.v);
				res += e.cost;
			}
		}
		return res;
	}
};


signed main() {
	int v, e;
	cin >> v >> e;
	Kruskal pear(v, e);
	rep (i, e) {
		int s, t, w;
		cin >> s >> t >> w;
		pear.addEdge(s, t, w);
		pear.addEdge(t, s, w);
	}
	cout << pear.execute() << endl;
}








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

#define ED return 0;
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define MAX 99999999
#define LONGMAX 99999999999999
#define FI first
#define SE second

int main(){
    int N;
    cin >> N;
    vector<long int> vec (N);
    cin >> vec.at(0);
    for(int i = 1;i < N;i++){
        long int test;
        cin >> test;
        vec.at(i) = vec.at(i-1) + test;
    }
    vec.push_back(0);
    SORT(vec)
    long long int answer = 0;
    int count = 1;
    for(int i = 0;i < N;i++){
        if(vec.at(i) == vec.at(i+1)){
            answer += count;
            count++;
        }
        else{
            count = 1;
        }
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <map>
#include <algorithm>
#include <functional>


int main()
{
	double N = 0, ans = 0;
	std::cin >> N;

	ans = ceil(N * 0.5);

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


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

int main() {
	// your code goes here
	string vect1;
	string vect2;
	cin>>vect1;
	cin>>vect2;
	long long res = 0;
	for(long long i = 0; i < vect1.size(); i++)
	{
	    if(vect1[i] != vect2[i])
	    {
	        res++;
	    }
	}
	cout << res <<endl;
	return 0;
}


Measured memory_bytes: 3456
N = int(input())
S = input()

S1, S2 = S[:N], S[N:][::-1]

dic = {}
keys = []
Ans = 0

for i in range(2 ** N):
    red, blue, red2, blue2 = "", "", "", ""
    # 半分ずつbit全探索
    bits = bin(2 ** N + i)[3:]
    for j in range(N):
        if bits[j] == "0":
            red += S1[j]
            red2 += S2[j]
        else:
            blue += S1[j]
            blue2 += S2[j]
    # あとで数える際に使うので記録しておく
    keys.append(red2 + "-" + blue2)
    # 半分全列挙
    key = red + "-" + blue
    if key not in dic.keys():
        dic[key] = 1
    else:
        dic[key] += 1

for key in keys:
    Ans += dic.get(key, 0)

print(Ans)

Measured memory_bytes: 56588
<?php
//$N = (int)trim(fgets(STDIN));
$S = trim(fgets(STDIN));
//list($A,$B) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));


printf("%s\n",substr($S,0,3));


Measured memory_bytes: 15964
import sys
import re
import queue
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []



def main():
	N = i_input()

	x_y_list = []

	for i in range(0,N):
		tmpx,tmpy = i_map()
		x_y_list.append((tmpx,tmpy))

	z_list = []
	w_list = []
	for i in range(0,N):
		tmpz = x_y_list[i][0] + x_y_list[i][1]
		tmpw = x_y_list[i][0] - x_y_list[i][1]
		z_list.append(tmpz)
		w_list.append(tmpw)

	print(max(max(map(lambda x : (x),z_list))-min(map(lambda x: (x), z_list)),max(map(lambda x : (x),w_list))-min(map(lambda x: (x),w_list))))
	
	return


if __name__ == '__main__':
	main()

Measured memory_bytes: 53476
import numpy as np
n = int(input())
aa = np.array(list(map(int, input().split())))
ret = np.zeros(n, int)
coeff = 1
while aa.sum() > 0:
    if ((aa%2).sum())%2 == 0:
        ret += coeff * (aa%2)
    else:
        ret += coeff * (1-aa%2)
    aa = aa//2
    coeff *= 2
ret = [str(r) for r in ret]
print(' '.join(ret))

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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
vector<pair<string,int>>v;
map<pair<string,int>,int>mp;
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    init();
    int n;
    cin>>n;
    string s;
    int x;
    for(int i=0;i<n;i++){
        cin>>s>>x;
        v.push_back({s,-x});
        mp[{s,-x}]=i+1;
    }
    sort(all(v));
    for(int i=0;i<n;i++){
        printf("%d\n",mp[v[i]]);
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

bool used[10];
bool tabu[10];
int keisu[10];
int ans;
int cnt; // 文字数


void dfs(int k, int sum){
    if (k == cnt) {
        if (sum == 0) {
            ans++;
        }
        return;
    }
    
    for (int i = 0; i < 10; i++) {
        if (used[i] || (i == 0 && tabu[k])) {
            continue;
        }
        used[i] = true;
        dfs(k + 1, sum + i * keisu[k]);
        used[i] = false;
    }
    return;
}

int main(){
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        vector<string> str(n);
        map<char, int> id;
        cnt = 0;
        ans = 0;
        
        for (int i = 0; i < 10; i++) {
            used[i] = false;
            tabu[i] = false;
            keisu[i] = 0;
        }

        for(int i = 0; i < n; i++){
            cin >> str[i];
            string s = str[i];
            for (int j = 0; j < s.size(); j++) {
                if (id.find(s[j]) == id.end()) {
                    id[s[j]] = cnt++;
                }
                if (j == 0 && s.size() > 1) { // 0にならない記号か
                    tabu[id[s[j]]] = true;
                }
                if (i != n - 1) {
                    keisu[id[s[j]]] += (int)pow(10, s.size() - j - 1);
                }else{
                    keisu[id[s[j]]] -= (int)pow(10, s.size() - j - 1);
                }
            }
        }
        dfs(0, 0);
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1256
if __name__ == '__main__':
    ken_num, city_num = list(map(int, input().split()))
    data = []
    for i in range(city_num):
        element = list(map(int, input().split()))
        element.append(i)
        data.append(element)

    data = sorted(data, key=lambda x: (x[0], x[1]))

    count = 1
    ken_num = 1
    ans_data = {}

    for i in range(city_num):
        number = data[i][2]
        if data[i][0] != ken_num:
            count = 1
            ken_num = data[i][0]
        chr = "{0:06d}".format(ken_num) + "{0:06d}".format(count)
        ans_data.update({number:chr})
        count += 1

    for i in range(city_num):
        print(ans_data[i])

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

int main(){
	int N;
	cin>>N;
	int x[N],y[N],b[N],p[N];
	for(int i=0;i<N;i++){
		cin>>x[i]>>y[i]>>b[i]>>p[i];
	}
	int all[N];
	for(int i=0;i<N;i++){
		int goke;
		int kgoke=0;
		if(b[i]>=5&&p[i]>=2){
			goke=(x[i]*b[i]+y[i]*p[i])*0.8;
			all[i]=goke;
		}else{
			goke=x[i]*b[i]+y[i]*p[i];
			if(b[i]<5&&p[i]<2){
				kgoke=(x[i]*5+y[i]*2)*0.8;
			}
			if(b[i]<5&&p[i]>=2){
				kgoke=(x[i]*5+y[i]*p[i])*0.8;
			}
			if(b[i]>=5&&p[i]<2){
				kgoke=(x[i]*b[i]+y[i]*2)*0.8;
			}
			if(goke>kgoke&&kgoke!=0){
				all[i]=kgoke;
			}else{
				all[i]=goke;
			}
		}
	}
	for(int i=0;i<N;i++){
		cout<<all[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <string>
 
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<string> blue(n);
    for (int i = 0; i < n; i++) {
        cin >> blue[i];
    }
    int m;
    cin >> m;
    vector<string> red(m);
    for (int i = 0; i < m; i++) {
        cin >> red[i];
    }
 
    int ans = 0;
    auto calc = [&](string s) {
        int buf = 0;
        for (string t: blue) {
            if (t == s) buf++;
        }
        for (string t: red) {
            if (t == s) buf--;
        }
        return buf;
    };
 
    for (string t: blue) {
        ans = max(ans, calc(t));
    }
 
    cout << ans << endl;
    return 0;
}

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

using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/

#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second

#define what_is(x)     cerr << #x << " is " << x << endl;

///*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)
{
    cout << endl ;
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
int ini()
{
    int x;
    scanf("%d",&x);
    return x;
}
long long inl()
{
    long long x;
    scanf("%lld",&x);
    return x;
}

const int N = (int) 2e5 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);

string s[1009];
ll dp[1002][1002];

int main()
{

    int h,w,i,j;
    h=ini();
    w=ini();
    for(int i=0; i<h; i++)
    {
        cin>>s[i];
    }
    for(int i=0; i<w; i++)
    {
        if(s[0][i]=='#')
        {
            for(int j=i; j<w; j++)
            {
                dp[0][j]=0;
            }
            break;
        }
        dp[0][i]=1;
    }
    for(int i=0; i<h; i++)
    {
        if(s[i][0]=='#')
        {
            for(int j=i; j<w; j++)
            {
                dp[j][0]=0;
            }
            break;
        }
        dp[i][0]=1;
    }

    for(int i=1; i<h; i++)
    {
        for(int j=1; j<w; j++)
        {
            if(s[i][j]=='#')
            {
                dp[i][j]=0;
                continue;
            }
            dp[i][j]=dp[i][j-1]+dp[i-1][j];
            if(dp[i][j]>=M){
                dp[i][j]%=M;
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
    return 0;
}





Measured memory_bytes: 9088
import java.io.*;
import java.util.*;
import java.lang.*;

class Main{

    public static void main(String args[])throws IOException{
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

	//StringBuffer s = new StringBuffer("a->b");
	//s.replace(s.indexOf("->"),s.indexOf("->")+2,"  ");
	//System.out.println(s);

	int n;
	String sn;
	sn = in.readLine();
	n = Integer.parseInt(sn);
	for(int cnt = 1;cnt <= n;cnt++){
	    LinkedList<Character> list = new LinkedList<Character>();
	    boolean[] used = new boolean[27];
	    String input = new String();
	    for(int i=0;i<27;i++)used[i] = false;
	    input = in.readLine();
	    StringBuffer line = new StringBuffer(input);
	    list.add(line.charAt(0));
	    used[line.charAt(0)-'a'] = true;
	    while(!(line.indexOf("->") == -1 && line.indexOf("<-") == -1)){
	
		if(line.indexOf("<-") == -1 || ( line.indexOf("<-") != -1 &&    line.indexOf("->") != -1 &&line.indexOf("->") < line.indexOf("<-") )){
		       

		char c = line.charAt(line.indexOf("->")+2);    
		    if(!used[c-'a']){
			list.addLast(c);
			used[c-'a'] = true;
		    }
		    int pos = line.indexOf("->");
		    line.replace(pos,pos+2,"  ");
  
		}
		else if(line.indexOf("->") == -1 ||  (line.indexOf("->") != -1 && line.indexOf("<-") != -1  &&  line.indexOf("->") > line.indexOf("<-"))){
		   
		    char c = line.charAt(line.indexOf("<-")+2);	
		    if(!used[c-'a']){
			list.addFirst(c);
			used[c-'a'] = true;
		    }
		    int pos = line.indexOf("<-");
		    line.replace(pos,pos+2,"  ");
		}
		else{
		    System.out.println("WTH");
		}
	
	    }
	    for(int i=0;i<list.size();i++){
		System.out.print(list.get(i));
	    }
	    System.out.println("");
	}

    }

}

Measured memory_bytes: 11000