akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<string,string> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

int main() {
    int n;cin>>n;
    string s;cin>>s;
    string front = s.substr(0,n),back = s.substr(n,n);
    reverse(back.begin(),back.end());
    map<P,ll> ma;
    for(int bit = 0;bit<(1<<n);bit++) {
        string a = "",b = "";
        rep(i,n) {
            if((bit>>i)&1) a += front[i];
            else b += front[i];
        }
        ma[P(a,b)]++;
    }

    ll ans=0;

    for(int bit = 0;bit<(1<<n);bit++) {
        string a = "",b = "";
        rep(i,n) {
            if((bit>>i)&1) a += back[i];
            else b += back[i];
        }
        ans += ma[P(b,a)];
    }

    cout<<ans<<endl;
}

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

struct P{ 
    double x, y;
    
};
 
void koch(int n, P a, P b){
  if(n == 0)
      return;
  P s, t, u;
  double th = M_PI * 60.0/ 180.0;
  s.x = (2.0 * a.x +1.0*b.x) / 3.0;
  s.y = (2.0 * a.y +1.0 *b.y) / 3.0;
  t.x = (1.0 * a.x +2.0*b.x) / 3.0;
  t.y = (1.0 * a.y +2.0 *b.y) / 3.0;
  u.x = (t.x - s.x)*cos(th) - (t.y - s.y)* sin(th) + s.x;
  u.y = (t.x - s.x)*sin(th) + (t.y - s.y)* cos(th) + s.y;

 koch(n-1, a, s);
 printf("%.8f %.8f\n", s.x, s.y);
 koch(n-1, s, u);
 printf("%.8f %.8f\n", u.x, u.y);
 koch(n-1, u, t);
 printf("%.8f %.8f\n", t.x, t.y);
 koch(n-1, t, b);

}

int main(){
  P a, b;
  int n;
  scanf("%d", &n);
  
  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;
 
  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}








Measured memory_bytes: 2620
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 100 * 1000 + 50;
	int arr[MAXN];
	long long mod = 1e9 + 7;
int main(){
	int n, k;
	cin >> n >> k;
	for(int i = 0; i <= n + 5; i++){
		arr[i] = i;
	}
	long long ans  = 0;
	long long MAX = 0, MIN = 0;
	
		for(int i = 0; i < k; i++){
			MIN += arr[i];
		}	
		for(int i = n; i >= n + 1 - k ; i--){
			MAX += arr[i];
		}	
		ans += ((MAX - MIN + 1) % mod);
		int cnt1 = k ;
		int cnt2 = n + 1 - k - 1;
	for(int j = k + 1; j <= n + 1; j++){
		MIN += arr[cnt1] % mod;
		cnt1++;
		MAX += arr[cnt2] % mod;
		cnt2--;
		ans = ans + ((MAX - MIN + 1)) % mod;
	}
		cout << ans % mod;
	return 0;
}

Measured memory_bytes: 4380
import Control.Monad
import Control.Applicative
main = do
  nums <- map read <$> lines <$> getContents
  forM_ nums $ \i -> do
    print $ length $ [() | a<-[0..9], b<-[0..9], c<-[0..9], d<-[0..9], a + b + c + d == i]


Measured memory_bytes: 4068
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7
ctr = Counter(A)
if N%2:
    if ctr[0] != 1:
        print(0)
        exit()
    for i in range(2,N,2):
        if ctr[i] != 2:
            print(0)
            exit()
else:
    for i in range(1,N,2):
        if ctr[i] != 2:
            print(0)
            exit()
print(2**(N//2) % MOD)


Measured memory_bytes: 14820
#include <iostream>
using namespace std;
int a[100005];
int main()
{
    int n;
    cin>>n;
    int t1=0,t2=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%4==0)
            t1++;
        else if(a[i]%2==0)
            t2++;
    }
    int flag=0;
    int m;
    if(t2%2==0) m=t2;
    else m=t2-1;
    if((n-m)/2<=t1)flag=1;
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>


int main()
{
	int K;
	int X;

	std::cin >> K >> X;

	for (int i = X - (K - 1); i <= X + (K - 1); ++i)
	{
		if (i == X + (K - 1))
		{
			std::cout << i << std::endl;
		}
		else
		{
			std::cout << i << " ";
		}
	}

	return 0;
}

Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())

can=list(map(int,input().split()))

degrees=[]

for i in can:
    degrees.append(t-i*0.006)

#print(degrees)

ans=[]

for j in degrees:
    ans.append(abs(j-a))

#print(ans)

print(ans.index(min(ans))+1)


Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	a := nextInt()
	b := nextInt()
	m := max(a, b)
	for i := 0; i < m; i++ {
		if a-i == -b+i {
			fmt.Println(i)
			return
		}
	}
	fmt.Println("IMPOSSIBLE")
}

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

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(n);
	rep(i, n) {
		int p, q;
		cin >> p >> q;
		a[i] = {p, q};
	}
	sort(all(a));
	ll ans = 0;
	priority_queue<int> pq;
	int p = 0;
	for(int i = 1; i <= m; i++) {
		while(p < n) {
			if(a[p].first > i) break;
			pq.push(a[p].second);
			p++;
		}
		if(!pq.empty()){
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1660
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a,b,c;
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		int ans = 0;
		if(a<b){
			ans += a;
			if(b<c){
				ans += b;
			}else{
				ans += c;
			}
		}else{
			ans += b;
			if(a<c){
				ans += a;
			}else{
				ans += c;
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 22864
//19
#include<iostream>
#include<algorithm>

using namespace std;

void rot(char (*d)[8]){
  char t[7][8]={};
  for(int i=0;i<7;i++){
    for(int j=0;j<7;j++){
      t[j][6-i]=(d[i][j]=='-')?'|':
	(d[i][j]=='|')?'-':
	d[i][j];
    }
  }
  copy(t[0],t[7],d[0]);
}

void lr(char (*d)[8]){
  for(int i=0;i<7;i++){
    for(int j=0;j<3;j++){
      swap(d[i][j],d[i][6-j]);
    }
  }
}

void ud(char (*d)[8]){
  for(int i=0;i<7;i++){
    for(int j=0;j<3;j++){
      swap(d[j][i],d[6-j][i]);
    }
  }
}

int main(){
  for(char g[21][58];cin>>g[0],g[0][0]!='0';){
    for(int i=1;i<21;i++){
      cin>>g[i];
    }
    int e[2][6];
    for(int i=0;i<2;i++){
      char (*d)[58]=(char (*)[58])(g[0]+i*29);
      for(int j=0;j<6;j++){
	int y[]={0,7,7,7,7,14};
	int x[]={7,0,7,14,21,7};
	char f[9][7][8]={{"#######","#.....#","#...|.#","#.....#","#...|.#","#..-..#","#######"},{"#######","#..-..#","#...|.#","#..-..#","#.|...#","#..-..#","#######"},{"#######","#..-..#","#...|.#","#..-..#","#...|.#","#..-..#","#######"},{"#######","#.....#","#.|.|.#","#..-..#","#...|.#","#.....#","#######"},{"#######","#..-..#","#.|...#","#..-..#","#...|.#","#..-..#","#######"},{"#######","#..-..#","#.|...#","#..-..#","#.|.|.#","#..-..#","#######"},{"#######","#..-..#","#...|.#","#.....#","#...|.#","#.....#","#######"},{"#######","#..-..#","#.|.|.#","#..-..#","#.|.|.#","#..-..#","#######"},{"#######","#..-..#","#.|.|.#","#..-..#","#...|.#","#..-..#","#######"}};
	char cf[7][8];
	for(int i=0;i<7;i++){
	  copy(d[y[j]+i]+x[j],d[y[j]+i]+x[j]+7,cf[i]);
	  cf[i][7]=0;
	}
	if(j%2==0){
	  lr(cf);
	}else if(j==1){
	  rot(cf);
	  lr(cf);
	}else if(j==3){
	  rot(cf);
	  rot(cf);
	  rot(cf);
	  lr(cf);
	}else{
	  lr(cf);
	  ud(cf);
	}
	int k;
	for(k=0;;k++){
	  if(equal(f[k][0],f[k+1][0],cf[0]))break;
	}
	e[i][j]=k;
      }
    }
    int w=0;
    for(int i=0;i<6;i++){
      for(int j=0;j<6;j++){
	w+=(e[0][i]>e[1][j])-(e[0][i]<e[1][j]);
      }
    }
    cout<<((w<0)?"LOW":"HIGH")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1140
a = io.read("*number")
b = io.read("*number")
c = io.read("*number")
x = io.read("*number")
ans = 0

for i = 0, a do
  for j = 0, b do
    for k = 0, c do
      if i*500+j*100+k*50 == x then
        ans = ans + 1
      end
    end
  end
end
print(ans)

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

using namespace std;

int main() {
  std::string argstr;
  cin >> argstr;

  int first = 0;
  int firstPos = argstr.find_first_of(',');
  int lastPos = argstr.find_last_of(',');
  int last = argstr.size();
  // cout << firstPos;
  // cout << lastPos;
  // cout << last;
  string a = argstr.substr(first, firstPos);
  string b = argstr.substr(firstPos + 1, lastPos - firstPos - 1);
  string c = argstr.substr(lastPos + 1, last - lastPos - 1);

  cout << a << " " << b << " " << c << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	long long X,Y,y;
	cin >> X >> Y;

	string s;
	//cin >> s;

	//int A[5]
	//sort(A, A + 5);
	bool flag = false;
	y = Y;
	for (long long i = 0; i < X; i++)
	{
		y += -2;
	}
	if (y == 0)
	{
		flag = true;
	}
	for (long long i = 0; i < X; i++)
	{
		y += -2;
		if (y == 0)
		{
			flag = true;
			break;
		}
	}
	if (flag == true)
	{
		cout << "Yes" << endl;
		return 0;
	}
	else
	{
		cout << "No" << endl;
		return 0;
	}
}

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

using namespace std;

int main(){
  int n;
  int minVal = INT_MAX;
  int maxVal = -INT_MAX;
  scanf("%d", &n);
  while(n--){
    int x;
    scanf("%d", &x);
    minVal = min(minVal, x);
    maxVal = max(maxVal, x);
  }
  printf("%d\n", maxVal - minVal);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    int N,M;
    int K;
    cin >> N >> M;
    K=pow(2,(double)M);
    cout << (M*1900+(N-M)*100)*K  << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef long long ll;
typedef pair<int,int>P;
#define MAX 1e9
struct edge{int to,cost;};

int main() {
  	int s,w;
  	cin >>s>>w;
  	if(w>=s){cout<<"unsafe"<<endl;}
  	else{cout<<"safe"<<endl;}
}

Measured memory_bytes: 3624
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from queue import PriorityQueue as pq

# from itertools import accumulate
# from collections import deque
import random


def main():
    n = int(input())
    l=[["",0,0] for i in range(n)]
    # eprint(l)
    for i in range(n):
        s,m=input().split()
        m=-int(m)
        l[i][0]=s
        l[i][1]=m
        l[i][2]=i+1
    # eprint(l)
    l.sort()
    # eprint(l)
    for x in l:
        print(x[2])

if __name__ == '__main__':
    main()


Measured memory_bytes: 65900
#include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

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

  string s;
  cin >> s;

  int size = s.size();
  for (int i = 2; i < size; i=i+2) {
    bool result = true;
    for (int j = 0; j < (size-i)/2; j++) {
      if (s[j] != s[j + (size-i)/2]) {
        result = false;
        break;
      }
    }
    if (result) {
      cout << size - i << eol;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifdef LOCAL
	#define debug(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define debug(...) 42
#endif

#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define mem(x,val) memset(x,val,sizeof x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

inline string getString(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string getLine(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
typedef long long ll;

const int S=100100;
int main()
{
	int n,x,y;
	while(~sf("%d %d %d",&n,&x,&y))
	{
		int ara[n+5];
		mem(ara,0);
		for(int i=1;i<=n-1;i++)
		{
			for(int j=i+1;j<=n;j++)
			{
				int dis1=j-i;
				int dis2=abs(i-x)+abs(y-j)+1;
				int dis=min(dis1,dis2);
				ara[dis]++;
			}
		}

		for(int i=1;i<=n-1;i++)pf("%d\n",ara[i]);
	}
    return 0;
}



































Measured memory_bytes: 3756
#include<iostream>
using namespace std;
int main(){
	int ans[10];
	int dice[1005]; //m
	int map[1005]; //n
	int n,m;
	int a=0;
	int i=0;
	int p=0;
	int pp=0;
	
	while(1){
		cin>>n>>m; //現在地n-1で到達
		if(n==0 && m==0)break;
		for(i=0;i<n;i++){
			cin>>map[i];
		}
		for(i=0;i<m;i++){
			cin>>dice[i];
		}//代入完了
		i=0;
		while(1){
			p+=dice[i];
			pp=map[p];
			p+=pp;
			if(p>=n-1)break;
			i++;
		}
		ans[a]=i+1;
		a++;
		for(i=0;i<n;i++){
			map[i]=0;
		}
		for(i=0;i<m;i++){
			dice[i]=0;
		}
		p=0;
	}
	for(i=0;i<a;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}
	



Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
#define N 51
string s[N];
int n;
int cnt['z'+1][N];
int minn['z'+1];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	memset(minn,10,sizeof(minn));
	for(int i=1;i<=n;i++)
		cin>>s[i];
	for(int i=1;i<=n;i++)
	{
		int siz=s[i].size();
		for(int j=0;j<siz;j++)
			++cnt[int(s[i][j])][i];
	}
	for(int i=1;i<=n;i++)
		for(int j='a';j<='z';j++)
			minn[j]=min(minn[j],cnt[int(j)][i]);
	for(int i='a';i<='z';i++)
		for(int j=1;j<=minn[i];j++)
			cout<<char(i);
	//cout<<minn[i];
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,x;
    scanf("%d%d%d",&a,&b,&c);
    x=a;
    a=b;
    b=x;
    x=a;
    a=c;
    c=x;
    printf("%d %d %d",a,b,c);
}


Measured memory_bytes: 128
n = int(input())
s = []
for _ in range(n):
  x = input()
  s.append("".join(sorted(x)))

s = sorted(s)

j = 0
x = []
for i in range(1, n):
  if s[i] == s[i-1]:
    j += 1
  else:
    if j > 0:
      x.append(j)
      j=0
if j > 0:
  x.append(j)

def func(n):
  return (n+1)*n/2

ret = sum(map(func, x))

print(int(ret))

Measured memory_bytes: 11356
#!/usr/bin/env python
# coding: utf-8
#


def main(input_str):
    # bit = bin(int(input_str))
    # l = list(map(int, list(bit[2:])))
    l = list(map(int, list(input_str)))
    # print(sum(l))
    if int(input_str) % sum(l) == 0:
        print('Yes')
    else:
        print('No')
    


if __name__ == '__main__':
    try:

        main(input().strip())
    except EOFError:
        pass


Measured memory_bytes: 2940
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    s=[a[0]]*n
    for i in range(1,n):
        s[i]=s[i-1]+a[i]

    flag=True
    #1,-1,...
    for i in range(n):
        if i%2==0:
            if s[i]<=0:
                flag=False
                break
        else:
            if s[i]>=0:
                flag=False
                break

    if flag:
        print(0)
    else:  #-1,1,...
        flag=True
        for i in range(n):
            if i%2==0:
                if s[i]>=0:
                    flag=False
                    break
            else:
                if s[i]<=0:
                    flag=False
                    break
        if flag:
            print(0)
        else:
            cnt1=0
            s1=s[:]
            f1=0
            #1,-1,...
            for i in range(n):
                if i%2==0:
                    if s1[i]+f1<=0:
                        cnt1+=abs(1-s1[i]-f1)
                        f1+=1-s1[i]-f1
                else:
                    if s1[i]+f1>=0:
                        cnt1+=abs(-1-s1[i]-f1)
                        f1+=-1-s1[i]-f1
            
            cnt2=0
            s2=s[:]
            f2=0
            #-1,1,...
            for i in range(n):
                if i%2==0:
                    if s2[i]+f2>=0:
                        cnt2+=abs(-1-s2[i]-f2)
                        f2+=-1-s2[i]-f2
                else:
                    if s2[i]+f2<=0:
                        cnt2+=abs(1-s2[i]-f2)
                        f2+=1-s2[i]-f2
            print(min(cnt1,cnt2))

if __name__=="__main__":
    main()

Measured memory_bytes: 14332
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String s=sc.next(); 
  if(s.contains("a")&&s.contains("b")&&s.contains("c")){
  System.out.println("Yes");
  }else{System.out.println("No");}
}}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

const int moveTo[][2] = {{-1,1},{0,1},{1,1}};

int stage[17][17];
int dp[17][17];

int main(){
	int w,h;
	while(~scanf("%d %d",&w,&h)){
		if(w==h && h==0) break;
		memset(stage,-1,sizeof(stage));
		memset(dp,0,sizeof(dp));
		for(int y=0;y<h;y++){
			for(int x=0;x<w;x++){
				scanf("%d",&stage[y][x]);
			}
		}

		//space:0 tree:1 jump:2
		for(int x=0;x<w;x++){
			if(stage[0][x]!=1) dp[0][x] = 1;
		}

		for(int dy=1;dy<=h;dy++){
			for(int dx=0;dx<w;dx++){
				if(stage[dy][dx] != 1){			
					for(int j=0;j<3;j++){
						int sx = dx - moveTo[j][0];
						int sy = dy - moveTo[j][1];
						if(sx < 0 || sx >= w || sy < 0 || sy >= h-1) continue;

						//space:0 tree:1 jump:2
						if(stage[sy][sx]!=0) continue;
						if(stage[dy][dx]==2 && dx != sx) continue;

						dp[dy][dx] += dp[sy][sx];
					}

					int sx = dx;
					int sy = dy-2;
					if(sx >=0 && sx < w && sy >= 0 && sy < h-1){
						//space:0 tree:1 jump:2
						if(stage[sy][sx] == 2){
							dp[dy][dx] += dp[sy][sx];
						}
					}
				}
			}
		}

		int res=0;
		for(int y=h-1;y<=h;y++){
			for(int x=0;x<w;x++){
				res += dp[y][x];
			}
		}

		printf("%d\n",res);
	}

}

Measured memory_bytes: 3144
#include<stdio.h>
#define N 100000

void partition(int,int,int *);
void change(int *,int *);

int main()
{
  int i,A[N],n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%d",&A[i]);
  }
  partition(0,n-1,A);
  return 0;
}

void partition(int l,int r,int *A)
{
  int i=l,j,temp,x = A[r];
  for(j=l;j<r;j++)
  {
    if(A[j]<=x)
    {
      change(&A[i++],&A[j]);
    }
  }
    change(&A[i],&A[r]);
    for(j=l;j<=r;j++)
    {
      if(j>l)printf(" ");
      if(j==i)printf("[%d]",A[j]);
      else printf("%d",A[j]);
    }

  printf("\n");
}

void change(int *a,int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}



Measured memory_bytes: 2248
/* ABC111 */
/* A */
#include <iostream>
#include <string>
using namespace std;

int main(void){

    int n;
    cin >> n;

    int ans = 0;
    ans += (10 - (n/100)) * 100;
    ans += (10 - (n%100)/10) * 10;
    ans += 10 - (n%10);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long
main(){
  string s;
  int k,n,d=0,d2=0;
  bool f=false,g=false;
  cin>>s>>k;
  n=s.size();
  for(int i=1;i<n;++i){
    if(i==n-1)f=true;
    if(s[i]==s[i-1])d++,i++;
  }
  if(!f){
    s=s+s;
    for(int i=n;i<2*n;++i){
      if(i==2*n-1)g=true;
      if(s[i]==s[i-1])d2++,i++;
    }
  }
  cout<<(f?k*d:(g?k/2*(d+d2)+(k%2)*d:d+(k-1)*d2));
}

Measured memory_bytes: 256
//author:emre yazicioglu
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fori(a,b,c) for(ll a = b;a < ll(c);a++)
#define pb push_back
const int N = 2e5 + 7;
ll n,m,ans,a[N],b[N],arr[N];
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);

	cin >> n;
	ll sum=0;
	fori(i,0,n+1){
		cin >> a[i];
	}
	fori(i,0,n)
		cin >> b[i];

	fori(i,0,n){
		if(b[i]>=a[i]){
			sum+=a[i];
			b[i]-=a[i];
			sum += min(b[i],a[i+1]);
			a[i+1]=max(0ll,a[i+1]-b[i]);
		}
		else
			sum+=b[i];
	}
	// sum+=min(a[n],b[n-1]);
	cout << sum;
}

Measured memory_bytes: 2816
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {n:usize,m:usize}
    println!("{}", (n - 1) * (m - 1));
}


Measured memory_bytes: 4352
import time

def sum_A(A, n):
    dic = {}
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    A = sorted(A)
    #start = time.time()
    solve = sum_A(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"
    #end = time.time()
    #print end - start

Measured memory_bytes: 12392
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());

        int diff = A - 2 * B;
        System.out.println(Math.max(diff, 0));
    }
}

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

int main() {
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  vector<int> U(M);
  priority_queue<int, vector<int>, greater<int>> ans;
  
  for(int i=0;i<N;i++){
    cin >> C.at(i);
    for(int j=0;j<M;j++){
      cin >> A.at(i).at(j);
    }
  }
  
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
  bitset<12> s(tmp);  // 12ビットのビット列として扱う
  //cout << "tmp : " << tmp << endl;
  // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    bool flag = true;
    int cost=0;
    for(int i=0;i<N;i++){
        if(s.test(i)) {
          cost += C.at(i);
        }
    }
    for(int j=0;j<M;j++){
      int sum = 0;
      for(int i=0;i<N;i++){
        if(s.test(i)) {
          sum += A.at(i).at(j);
        }
      }
      //cout << "j : " << j <<  endl;
      //cout << "sum : " << sum << endl;
      //cout << "cost : " << cost << endl;
      //cout << "j : " << j << " sum : " << sum << " cost : " << cost << endl;
      if(sum < X) {
        flag = false;
      }
    }
    if(flag){
      ans.push(cost);
    }
  }
  
  if(!ans.empty()) {
    cout << ans.top() << endl;
  }
  else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3648
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author G. Guarnieri
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int testNum = in.nextInt() * 100 + in.nextInt() * 10 + in.nextInt();
            if (testNum % 4 == 0) {
                out.println("YES");
            }
            else {
                out.println("NO");
            }
        }

    }
}



Measured memory_bytes: 20560
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;

#define INF (i64)(1e18)
#define MOD (i64)(1e9+7)
#define REP(i, n) for(i64 i = 0; i < (n); i++)
#define RANGE(i, a, b) for(i64 i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) ((i64)(v).size())
template<class T> inline void chmax(T &a, const T &b) { if (a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if (a > b) a = b; }

int main() {
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int>> v(m);
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    v[i] = {a, b};
  }
  sort(ALL(v), [](tuple<int, int> p1, tuple<int, int> p2) { return get<1>(p1) < get<1>(p2); });
  int prev = get<1>(v[0])-1;
  int ans = 1;
  RANGE(i, 1, m) {
    if (get<0>(v[i]) > prev) {
      ans++;
      prev = get<1>(v[i])-1;
    }
  }
  cout << ans << endl;
  return 0;
}


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

signed main(){
  string s; cin >> s;
	int p = 0, g = 0, ans = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'p'){
			if(p < g) p++;
			else g++, ans--;
		}
		if(s[i] == 'g'){
			if(p < g) p++, ans++;
			else g++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
n=int(input())
abc=[list(map(int,input().split())) for _ in [0]*(n-1)]
q,k=map(int,input().split())
xy=[list(map(int,input().split())) for _ in [0]*q]

g=[[] for _ in [0]*n]
[g[b-1].append([a-1,c]) for a,b,c in abc]
[g[a-1].append([b-1,c]) for a,b,c in abc]

inf=10**15
dist=[None for _ in [0]*n]
dist[k-1]=0
q=[k-1]
while q:
    i=q.pop()
    gg=g[i]
    for j,k in gg:
        if dist[j]==None:
            dist[j]=dist[i]+k
            q.append(j)
for x,y in xy:
    print(dist[x-1]+dist[y-1])

Measured memory_bytes: 90196
fun main(args: Array<String>) {
    val s = readLine()!!
    val t = readLine()!!

    val n = s.length
    val sArr = IntArray(26){0}
    val tArr = IntArray(26){0}
    repeat(n) {
        sArr[s[it] - 'a']++
        tArr[t[it] - 'a']++
    }

    var ans = true
    repeat(n) {
        if (sArr[s[it] - 'a'] != tArr[t[it] - 'a']) ans = false
    }

    if (ans) println("Yes")
    else println("No")
}


Measured memory_bytes: 34652
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine().trim();
		final int n = Integer.parseInt(line);

		line = br.readLine().trim();
		String[] arr = line.split(" ");
		br.close();

		long min = 1000000;
		long max = -1000000;
		long sum = 0;
		for (int i = 0; i < n; i++) {
			long v = Long.parseLong(arr[i]);
			min = Math.min(min, v);
			max = Math.max(max, v);
			sum += v;
		}
		System.out.println(min + " " + max + " " + sum);
	}
	
}

Measured memory_bytes: 28644
#include<bits/stdc++.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define next(i)((i+1)%n)
#define prev(i)((i+n-1)%n)
using namespace std;
typedef long long ll;

ll a[2010];
ll dp[2010][2010];
int main() {
	ll n; scanf("%lld", &n);
	rep(i, n)scanf("%lld", &a[i]);
	rep(i, n)dp[i][i] = a[i];
	rep(t, n - 1)rep(i, n) {
		ll j = (i + t) % n;
		if ((j + n - i) % n & 1) {
			dp[prev(i)][j] = max(dp[prev(i)][j], dp[i][j] + a[prev(i)]);
			dp[i][next(j)] = max(dp[i][next(j)], dp[i][j] + a[next(j)]);
		}
		else {
			if (a[prev(i)] > a[next(j)])
				dp[prev(i)][j] = max(dp[prev(i)][j], dp[i][j]);
			else dp[i][next(j)] = max(dp[i][next(j)], dp[i][j]);
		}
	}
	ll Max = 0;
	rep(i, n)Max = max(Max, dp[i][prev(i)]);
	printf("%lld\n", Max);
}

Measured memory_bytes: 34640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var k = nk[1];
            Console.WriteLine(Console.ReadLine().Split(' ').Select(num => int.Parse(num)).Where(num => num >= k).Count());
        }
    }
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    const int N = 100 + 5;
    int g[4][n];
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> g[i][j];
      }
    }

    int dp[4][N];
    fill(&dp[0][0], &dp[2 - 1][N - 1] + 1, 0);

    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < n; ++j) {
        setmax(dp[i + 1][j], dp[i][j] + g[i + 1][j]);
        setmax(dp[i][j + 1], dp[i][j] + g[i][j + 1]);
      }
    }

    cout << dp[1][n - 1] + g[0][0] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# xor shift（F_2上の多項式）に関する gcd を計算する

from functools import reduce

X = int(readline().split()[1],2)
A = [int(x,2) for x in readlines()]

MOD = 998244353

def gcd(a,b):
    if a < b:
        a,b = b,a
    while b:
        LA = a.bit_length()
        LB = b.bit_length()
        a ^= b << (LA - LB)
        if a < b:
            a,b = b,a
    return a

g = reduce(gcd,A)

# g の "倍数" で、X以下のものを作る方法の数を数える
# 上位の桁を決めると、gの倍数は一意に決まる。
# よって、上位の桁がXに一致するときのみが問題

LX = X.bit_length()
Lg = g.bit_length()
answer = X >> (Lg - 1)

prod = 0
x = X; Lx = LX
while Lx >= Lg:
    prod ^= g << (Lx - Lg)
    x ^= g << (Lx - Lg)
    Lx = x.bit_length()

if prod <= X:
    answer += 1

answer %= MOD
print(answer)


Measured memory_bytes: 3812
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace boost::multiprecision;

int main() {
	cpp_dec_float_100 L;
	cin >> L;
	L = L / 3;
	cout << setprecision(10) << L * L * L << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    if (s[0] != '1' || s[n - 1] != '0') {
        cout << -1 << "\n";
        return 0;
    }
    for (int i = 0; i < n - 1; ++i) {
        if (s[i] != s[n - 2 - i]) {
            cout << -1 << "\n";
            return 0;
        }
    }
    int curr = 0;
    int used = 1;
    cout << curr + 1 << " " << used + 1 << "\n";
    for (int i = 1; i < n - 1; ++i) {
        if (s[i] == '1') {
            used++;
            cout << curr + 1 << " " << used + 1 << "\n";
            curr = used;
        } else {
            used++;
            cout << curr + 1 << " " << used + 1 << "\n";
        }
    }
    return 0;
}

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

struct Point{
  double x, y;
};

void koch(int n, struct Point a, struct Point b){
  if(n == 0) return;
  struct Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n - 1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n - 1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n - 1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n - 1, t, b);
}

int main(){
  struct Point a, b;
  int n;

  scanf("%d", &n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}

Measured memory_bytes: 640
eval'N,M='+`tr ' ' ,`
O=10**9+7
F=t=1,*(1..M).map{t=t*_1%O}
p (0..N).sum{|k|~0**k*F[M-k]*(F[k]*F[N-k]*F[M-N]**2).pow(O-2,O)}*F[N]*t%O

Measured memory_bytes: 22300
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int mex=2005;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++) 

int main()
{
  int n;
  cin>>n;
  int arr[n];
  set<int> st;
  int cnt=1;
  fo(i,0,n)
  {cin>>arr[i];
  
  if(i)
  {
    if(*st.bg>=arr[i]) cnt++;  
  }
  st.insert(arr[i]);
  }
  cout<<cnt;
}


Measured memory_bytes: 10368
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>

int a, b, c;

int main() {
	std::cin >> a >> b >> c;
	double t = (a * 1.0) / (c * 1.0);
	if (t - b * 1.0 >= 1e-8) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int i,n;
  char s[101];
  cin >> s;
  for(i=0;;i++){
    if(s[i]!='1'){
      break;
    }
  }
  cin >> n;
  if(i>=n){
    cout << 1;
  }else{
    cout << s[i];
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int partition(int A[], int p, int r) {

    int x = A[r];
    int i = p - 1;

    for (int j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            int tmp = A[j];
            A[j] = A[i];
            A[i] = tmp;
        }
    }

    int tmp = A[i + 1];
    A[i + 1] = A[r];
    A[r] = tmp;

    return i + 1;
}

int main() {

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

    int A[num];
    for (int i = 0; i < num; i++) {
        scanf("%d", &A[i]);
    }

    int p = partition(A, 0, num - 1);

    for (int i = 0; i < num; i++) {
        if (i == p) {
            printf("[%d]", A[i]);
        } else {
            printf("%d", A[i]);
        }
        if (i != num - 1) {
            printf(" ");
        } else {
            printf("\n");
        }
    }

    return 0;
}



Measured memory_bytes: 2068
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  if (a * n <= b){
    cout << a * n << '\n';
  }
  else{
    cout << b << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    Scanner sc = new Scanner(System.in);
    Person [][] n = new Person[3][8];
    Person [] n2 = new Person[6];
     
    void doIt(){
    	for(int i = 0 ; i < 3 ; i++){
            for(int j = 0 ; j < 8 ; j++){
                n[i][j] = new Person(sc.nextInt() , sc.next()); 
            }
        } 
    	Arrays.sort(n[0]);
        Arrays.sort(n[1]);
        Arrays.sort(n[2]);
        n2[0] = new Person(n[0][2].n , n[0][2].time);
        n2[1] = new Person(n[0][3].n , n[0][3].time);
        n2[2] = new Person(n[1][2].n , n[1][2].time);
        n2[3] = new Person(n[1][3].n , n[1][3].time);
        n2[4] = new Person(n[2][2].n , n[2][2].time);
        n2[5] = new Person(n[2][3].n , n[2][3].time);
        Arrays.sort(n2);
        System.out.println(n[0][0]);
        System.out.println(n[0][1]);
        System.out.println(n[1][0]);
        System.out.println(n[1][1]);
        System.out.println(n[2][0]);
        System.out.println(n[2][1]);
        System.out.println(n2[0]);
        System.out.println(n2[1]);
    }
 
     
    public static void main(String[] args){
        new Main().doIt();
    }
     
    class Person implements Comparable<Person>{
        int n;
        String time;
        Person(int n , String time){
            this.n = n;
            this.time = time;   
        }
         
        @Override
        public int compareTo(Person p){
            return time.compareTo(p.time);
        }
         
        @Override
        public String toString(){
            return n + " " + time;
        }
         
    }
     
}

Measured memory_bytes: 26244
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	std::string s, t;

	std::cin >> s >> t;

	std::sort(s.begin(), s.end());
	std::sort(t.begin(), t.end());
	std::reverse(t.begin(), t.end());

	int min = std::min(s.length(), t.length());

	for (size_t i = 0; i < min; i++)
	{
		if (s[i] < t[i]) {
			std::cout << "Yes" << std::endl;
			return 0;
		}
		else if (s[i] > t[i]) {
			std::cout << "No" << std::endl;
			return 0;
		}
	}

	if (s.length() >= t.length()) {
		std::wcout << "No" << std::endl;
		return 0;
	}

	std::cout << "Yes" << std::endl;
}


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


void solve(){
    string s; cin >> s;
    for(int i = 0; i < s.size()-2; i++){
        if(s[i] == s[i+1] || s[i] == s[i+1] || s[i] == s[i+2] || s[i+1] == s[i+2]){
            cout << i+1 << " " << i+3 << "\n";
            return;
        }
    }
    for(int i = 0; i < s.size()-1; i++){
        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2 << "\n";
            return;
        }
    }
    cout << "-1 -1\n";
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    bool multitest = false;
//    multitest = true;
    if(multitest){
        int t; cin >> t;
        while(t--)
            solve();
    }
    else
        solve();
}






Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R, G;
    cin >> R >> G;
    cout << ((G-R) * 2) + R << endl;

    return 0;
}


Measured memory_bytes: 256
K_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(K_list[int(input())-1])

Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().run();
        return 0;
    }

    int N;
    void run()
    {
        while(true)
        {
            N = int.Parse(Console.ReadLine());
            if (N == 0) return;
            Dictionary<int, int> dic = new Dictionary<int, int>();
            for (int i = 1; i < N; i++)
            {
                dic[i * i % N] = 1;
                
            }
            int[] array = new int[N];
            foreach (int item in dic.Keys)
            {
                foreach (int item2 in dic.Keys)
                {
                    array[getnum(item - item2)]++;
                }
            }

            for (int i = 1; i <= N / 2; i++)
            {
                Console.WriteLine(array[i]);
            }

        }
    }

    int getnum(int a)
    {
        a %= N;
        if (a < 0) a += N;
        return Math.Min(a, N - a);
    }
}

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

using namespace std;

int main() {
    #ifdef LOCAL
    freopen("in", "r", stdin);
    #endif // LOCAL
    ios::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> p(n), c(n);
    for (int i = 0; i < n; i++) cin >> p[i], p[i]--;
    for (int i = 0; i < n; i++) cin >> c[i];
    vector<vector<int>> grps;
    vector<int> curgrp;
    vector<long long> prd;
    long long cprd = 0;
    set<int> vis;
    for (int i = 0; i < n; i++) {
        if (vis.count(i)) continue;
        int k = i;
        while (!vis.count(k)) {
            vis.insert(k);
            curgrp.push_back(k);
            cprd += c[p[k]];
            k = p[k];
        }
        grps.push_back(curgrp);
        curgrp.clear();
        prd.push_back(cprd);
        cprd = 0;
    }
//    for (auto g : grps) {
//        for (auto e : g) cerr << e << ' ';
//        cerr << endl;
//    }
    long long ans = numeric_limits<long long>::min();
    for (int i = 0; i < grps.size(); i++) {
        auto &grp = grps[i];
        for (int j = 0; j < grp.size(); j++) {
            long long cum = 0;
            for (int len = 0; len < min<int>(k, grp.size()); len++) {
                cum += c[p[grp[(j + len) % grp.size()]]];
                ans = max<long long>({ans, cum, cum + (k - len - 1) / grp.size() * prd[i]});

//                cerr << "j: " << j << ", len: " << len << ", cum: " << cum << ", prd: " << prd[i] << ", ans: " << ans << endl;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3936
from collections import defaultdict
N = int(input())
tree = [[] for i in range(N)]  # 入力で与えられる木: [[to, 辺のindex],]
degrees = defaultdict(int)  # 各頂点の次数を記録

for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    tree[a].append([b, i])
    tree[b].append([a, i])
    degrees[a] += 1
    degrees[b] += 1


# 最大次数色使えば必ず塗り分けられる
ans_K = max(degrees.values())
ans_c = [-1] * (N - 1)


# [現在見ている頂点, 直前を何色で塗ったか]
stack = [[0, -1]]
visited = [False] * N
while stack:
    fr, pre_color = stack.pop()
    visited[fr] = True
    painting = 1  # これから何色で塗ろうとするか

    for to, index in tree[fr]:
        if visited[to]:
            continue

        if painting == pre_color:
            painting += 1

        ans_c[index] = painting
        stack.append([to, painting])

        # 塗ったら違う色に変える
        painting += 1


print(ans_K)
print(*ans_c, sep='\n')


Measured memory_bytes: 53976
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <random>
#include <ctime>
#include <queue>
using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
int n, k, q;
int a[N];

bool solve(int len){
    for(int i = 0; i < n; ++i){
        int min_val = a[i];
        int max_val = min(a[i] + len, (int)1e9);
        int sum = 0;
        int aa = 0;
        int bb = 0;
        for(int j = 0; j <= n; ++j){
            if(a[j] < min_val){
                sum += max(min(aa + bb - k + 1, aa), 0);
                aa = 0;
                bb = 0;
            }
            else if(a[j] <= max_val){
                aa++;
            }
            else{
                bb++;
            }
        }
        if(sum >= q) return true;
    }
    return false;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin >> n >> k >> q;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int mans = 1e9 + 5;
    int l = 0;
    int r = 1e9;
    while(l <= r){
        int mid = l + (r - l) / 2;
        if(solve(mid)){
            mans = mid;
            r = mid - 1;
        }
        else{
            l = mid + 1;
        }
    }
    cout << mans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;

int main(){
  int n,d,x;
  int a;
  int eaten=0;
  cin >> n >> d >> x;
  LOOP(i,n){
    cin>>a;
    eaten+=(d-1)/a+1;
  }
  cout<<x+eaten<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000000000000000
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define pii pair<ll, pair<ll, char>>
const ll mod = 1000000007;
ll n;
string solve() {
	cin>>n;
	vector<vector<int>>a(n, vector<int>(2));
	for(int i = 0; i < n; i++) {
		cin>>a[i][0]>>a[i][1];
	}
	for(int i = 2; i < n; i++) {
		if(a[i][0] == a[i][1] && a[i-1][0] == a[i-1][1] && a[i-2][0] == a[i-2][1]) return "Yes";
	}
	return "No";
}
int main() {
	io
	ll t = 1;
	//cin>>t;
	while(t--) {
		cout<<solve()<<endl;
		//solve();
	}
}


Measured memory_bytes: 3656