akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int N,K;
string s;
main()
{
	scanf("%d%d",&N,&K);cin >> s;
	string t = s;
	reverse(t.begin(),t.end());s += t;
	string m = s.substr(0,N);
	for(int i = 1;i <= N;i ++)
		m = min(m,s.substr(i,N));
	int l = 1;
	while(l < m.size() && m[0] == m[l])
		l ++;
	long long k = l;K --;
	if(K > 17) k = N;
	else k <<= K;
	string ans = "";
	while(ans.size() < N && k > 0)
		k --,ans += m[0];
	ans += m.substr(l,N-ans.size());
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
void rev(char *s){
	int l=strlen(s),i;
	for(i=0;i<l/2;i++){
		char t=s[i];
		s[i]=s[l-1-i];
		s[l-1-i]=t;
	}
}
char T[4][8]={"dream","dreamer","erase","eraser"};
int main(){
	int i=0,c,l;
	char s[100001];
	for(i=0;i<4;i++)rev(T[i]);
	scanf("%s",s);
	l=strlen(s);
	rev(s);
	for(;c<l;){
		int k=-1;
		for(i=0;i<4;i++){
			if(!strncmp(s+c,T[i],strlen(T[i]))){
				k=strlen(T[i]);
				break;
			}
		}
		if(k<0){
			puts("NO");
			return 0;
		}
		c+=k;
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	vector<pii>A(N);
	REP(i, N) {
		int a, b;
		cin >> a >> b;
		A[i] = pii(a + b, a - b);
	}
	SORT(A);
	int ans = 0;
	int T = -INF;
	REP(i, N) {
		if (T <= A[i].second) {
			ans++;
			T = A[i].first;
		}
	}



	cout << ans << endl;

	return 0;
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	ll a,b,ta,tb;
	cin >> a >> b;
	ta = a,tb = b;
	map<ll,ll> mp;
	mp[1]++;
	for(ll i = 2; i*i <= max(ta,tb); i++){
		if(a%i == 0 && b%i == 0){
			while(a%i == 0) a /= i;
			while(b%i == 0) b /= i;
			mp[i]++;
		}	
		while(a%i == 0) a /= i;
		while(b%i == 0) b /= i;
	}

	if(a < b) swap(a,b);
	if(a%b == 0) mp[b]++;

	cout << mp.size() << endl;
 	return 0;
}


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

#define MAX 1299809

int main(){

	  vector<int> pri;
	  bool is_p[MAX]={};
	  for(int i=2; i<MAX; i++) is_p[i] = true;
	  for(int i=2; i<MAX; i++){
			if( is_p[i] ) {
				  pri.push_back(i);
				  for(int j=2; i*j<MAX; j++)
						is_p[i*j] = false;
			}
	  }
	  int n;
	  while(cin >> n,n){
			
			int index = lower_bound(pri.begin(), pri.end(), n) - pri.begin();
			if( n == pri[index])
				  cout << 0 << endl;
			else
				  cout << pri[index] - pri[index-1]  << endl;
			
	  }
			
}

Measured memory_bytes: 2992
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>

using i64 = int64_t;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

std::string YES = "YES";
std::string NO = "NO";

using namespace std;

int main() {
    int a[3];

    REP(i, 3) {
        cin >> a[i];
    }
    sort(a, a + 3);
    if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
        cout << YES;
        return 0;
    }
    cout << NO;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, n-2){
    if (s.substr(i, 3) == "ABC") ans++;
  }
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

int main() {

	long long n, m;
	cin >> n >> m;

	if (n *2== m) {
		cout << n << endl;
		return 0;
	}

	if (n*2 > m) {
		cout << m / 2 << endl;
	}

	if (n * 2 < m) {
		cout << n+(m/2-n)/2 << endl;
	}

	return 0;

}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())

x = [input().rstrip() for i in range(n)]

print('AC x {0}\nWA x {1}\nTLE x {2}\nRE x {3}'.format(x.count('AC'), x.count('WA'), x.count('TLE'), x.count('RE')))

Measured memory_bytes: 79312
n = int(input())
s = [input() for i in range(n)]
s,s2,ans = s+s,[],0
for i in range(n):
	x = ""
	for j in s: x+=j[i]
	s2.append(x)
for i in range(n):
	flag = True
	for j in range(i,i+n):
		if s[j][1:n]!=s2[j-i][1+i:n+i]:
			flag = False
			break
	if flag: ans += n
print(ans)

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	
	public static int isPrime(int num) {
		
		for (int i = 2; i <= Math.floor(Math.sqrt(num)); i++) {
			if(num%i == 0) {
				return 0;
			}
		}
		return 1;
	}
	
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int primeCount = 0;
		int numOfTests = Integer.parseInt(in.next());
		
		for(int i = 0; i < numOfTests; i++) {
			primeCount += isPrime(Integer.parseInt(in.next()));
		}
				
		System.out.println(primeCount);
	}
}



Measured memory_bytes: 40096
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat Apr 28 21:11:57 2018
//
package main

import (
	"fmt"
)

var N int
var S []string

func is_valid(i, j int) bool {
	arr := make([][]uint8, N)
	for i := range arr {
		arr[i] = make([]uint8, N)
	}

	for x := 0; x < N; x++ {
		for y := 0; y < N; y++ {
			k, l := (x+i)%N, (y+j)%N
			arr[x][y] = S[k][l]
		}
	}

	for x := 0; x < N; x++ {
		for y := 0; y < N; y++ {
			if arr[x][y] != arr[y][x] {
				return false
			}
		}
	}
	return true
}

func main() {
	fmt.Scan(&N)
	S = make([]string, N)
	for i := range S {
		fmt.Scan(&S[i])
	}

	count := 0
	for i := range S {
		if is_valid(i, 0) {
			count += N
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int n,q,a,b,c,i,x[100010];
string s;
int main(){
  for(cin>>n>>q>>s,i=1;i<n;++i){
    x[i+1]=x[i];
    if(s[i-1]=='A'&&s[i]=='C')x[i+1]++;
  }
  // vector<int> l(q),r(q);
  // for(i=0;i<q;++i)cin>>l[i]>>r[i];
  for(i=0;i<q;++i){
    int a,b;cin>>a>>b;
    int ans=x[b]-x[a];
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n;
  string s;cin>>s;
  //vi a(n),b(n);
  int col=-1;
  REP(i,n){
    if (s[i]!=col)ans++;
    col=s[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 512
D,N = map(int,input().split())
a = []
if D == 0:
    if N == 100:
        print(101)
    else:
        print(N)
elif D == 1:
    if N == 100:
        print(10100)
    else:
        print(N*100)
else:
    if N == 100:
        print(10000*101)
    else:
        print(10000*N)

Measured memory_bytes: 3060
S=input()
aho=[]
for i in range(len(S)-2):
  n=int(S[i])*100+int(S[i+1])*10+int(S[i+2])
  if 753-n>=0:
    aho.append(753-n)
  else:
    aho.append(n-753)
print(min(aho))
  

Measured memory_bytes: 2940
import sys

#fin = open("test.txt", "r")
fin = sys.stdin

n, m = map(int, fin.readline().split())

A = [[] for i in range(n)]
for i in range(n):
	A[i] = list(map(int, fin.readline().split()))

b = [0 for i in range(m)]

for i in range(m):
	b[i] = int(fin.readline())

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

for i in range(n):
	for j in range(m):
		c[i] += A[i][j] * b[j]

for i in range(n):
	print(c[i])

Measured memory_bytes: 8060
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n,m,ans=0;
    cin>>n>>m;
    long long a[m];
    vector <long long> dp(50001,50002);
    f(i,0,m){
        cin>>a[i];
    }
    sort(a,a+m);
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(i+a[j]>n) break;
            dp[i+a[j]]=min(dp[i+a[j]],dp[i]+1);
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  int s = 0;
  rep(i,n) s ^= a[i];
  vi b(n);
  rep(i,n){
    b[i] = a[i] ^ s;
    cout << b[i] << " "; 
  }
}


Measured memory_bytes: 4724
local mab, mce, mfl, msq, mmi, mma = math.abs, math.ceil, math.floor, math.sqrt, math.min, math.max

local function lower_bound(ary, x, right)
  if(x <= ary[1]) then return 1 end
  local num = right
  if(ary[num] < x) then return num + 1 end
  local min, max = 1, num
  while(1 < max - min) do
    local mid = mfl((min + max) / 2)
    if(ary[mid] < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local ior = io.input()
local n, m = ior:read("*n", "*n")
local bc = {}
for i = 1, n do
  local a = ior:read("*n")
  local tmp = {1, a}
  table.insert(bc, tmp)
end
for i = 1, m do
  local b, c = ior:read("*n", "*n")
  local tmp = {b, c}
  table.insert(bc, tmp)
end
table.sort(bc, function(x, y) return x[2] > y[2] end)

local sum = 0
local rem = n
for i = 1, n + m do
  local num, val = bc[i][1], bc[i][2]
  num = mmi(rem, num)
  sum = sum + val * num
  rem = rem - num
  if rem == 0 then break end
end
print(99999999999999 < sum and "100000000000000" or sum)


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

//------------Constants----------------

//------------Variables----------------
string s,s1,s2;
int l,c,d1=0,d2=0;
//------------Functions----------------

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//------------Input--------------------
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> s;
//------------Work---------------------
    l=s.length();
    s1='0';
    s2='1';
    c=0;
    for (int i=0; i<l; i++){
        if (c==0) { s1+='1'; s2+='0'; c=1;} else { s1+='0'; s2+='1'; c=0;}
    }
    for (int i=0; i<l; i++){
        if (s[i]!=s1[i]) d1++;
        if (s[i]!=s2[i]) d2++;
    }
    cout << min(d1,d2);
}


Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	ll a, b, x;
	cin >> a >> b >> x;
	ll ans = 0;
	if (a == 0) {
		ans = b / x + 1;
	}
	else {
		ans = (b / x + 1) - ((a - 1) / x + 1);
	}
	printf("%lld\n", ans);
	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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A+B >= C) {
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import collections

n = int(input())
s = [input() for i in range(n)]
t = collections.Counter(s)
tm = t.most_common()
x = [tm[i][0] for i in range(len(tm)) if tm[i][1]==tm[0][1]]
x.sort()
for i in range(len(x)):
    print(x[i])

Measured memory_bytes: 48872
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W,D;
  cin>>H>>W>>D;
  int a[H+1][W+1];
  int x[H*W+1],y[H*W+1];
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      cin>>a[i][j];
      x[a[i][j]]=i,y[a[i][j]]=j;
    }
  }
  int S[H*W+1];
  for(int i=1; i<=H*W; i++){
      S[i+D]=S[i]+(abs(x[i+D]-x[i])+abs(y[i+D]-y[i]));
  }
  int Q;
  cin>>Q;
  for(int i=0; i<Q; i++){
    int a,b;
    cin>>a>>b;
    cout<<S[b]-S[a]<<endl;
  }
} 

Measured memory_bytes: 2560
sub f{
	#print$_+0,$/;
	$M[$_]=1;
	$M[$_]||&f for@{$G[$_]};
	unshift@s,$_+0;
}
$%=<>;
/ /,push@{$G[$`]},$' for<>;
#print"$_ : @{$G[$_]}\n"for 1..$%;
$M[$_]||f for 1..$%;
#print"@s\n";
map{$\+=$-=($p=$p[$_])-$\;$p[$_]+=$-=$p+1-$p[$_]for@{$G[$_]}}@s;
print

Measured memory_bytes: 75264
H, W = [int(_) for _ in input().split()]

m = [' ' * (W + 2)]
for i in range(H):
    m.append(' ' + input() + ' ')
m.append(' ' * (W + 2))

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if m[i][j] != '#': continue
        if not (m[i][j - 1] == '#' or \
                m[i][j + 1] == '#' or \
                m[i + 1][j] == '#' or \
                m[i - 1][j] == '#'):
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3064
from fractions import gcd
from functools import reduce


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


N = int(input())
T = [int(input()) for _ in range(N)]

print(lcm(*T))


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

using namespace std;
typedef long long ll;
const int inf = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;
const ll mod = 998244353;

bool check(int x, int l, int r) {
    return (x >= min(l, r) && x <= max(l, r));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    multiset<pair<int, int>> l, r;


    for (int i = 0; i < n; ++i) {
        pair<int, int> cur;
        cin >> cur.first >> cur.second;
        l.insert(cur);
        swap(cur.first, cur.second);
        r.insert(cur);
    }

    multiset<pair<int, int>> l1 = l, r1 = r;

    ll res = 0;
    for (int t = 0; t < 2; ++t) {
        int x = 0;
        ll cur = 0;
        for (int i = 0; i < n; ++i) {
            if (i % 2 == t) {
                auto nxt = *l.rbegin();
                l.erase(l.find(nxt));
                swap(nxt.first, nxt.second);
                if (!check(x, nxt.first, nxt.second)) {
                    cur += abs(nxt.second - x);
                    x = nxt.second;
                }
                r.erase(r.find(nxt));

            } else {
                auto nxt = *r.begin();
                if (!check(x, nxt.first, nxt.second)) {
                    cur += abs(nxt.first - x);
                    x = nxt.first;
                }
                swap(nxt.first, nxt.second);
                r.erase(r.begin());
                l.erase(l.find(nxt));
            }
        }

        l = l1, r = r1;

        cur += abs(x);
        res = max(res, cur);
    }

    cout << res;

    return 0;
}


Measured memory_bytes: 21120
#include <iostream>

using namespace std;

int main() {
	float K = 0.006, ans, LL = 0, UL = 0;
	int N, T, A, H[1000], a, ULN = 0 , LLN = 0;
	cin >> N >> T >> A;
	LL = T - 100000 * K;
	UL = 5000;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	for (int i = 0; i < N; i++) {
		ans = T - H[i] * K;
		if (ans >= A &&UL>ans) {
			UL = ans;
			ULN = i + 1;
		}
		if (ans < A && LL < ans) {
			LL = ans;
			LLN = i + 1;
		}
	}
	if (A < 0) A = -A;
	if (UL < 0)UL = -UL;
	if (LL < 0)LL = -LL;
	if (UL < A) UL = A - UL;
	else UL = UL - A;
	if (LL > A)LL = LL - A;
	else LL = A - LL;
	if (UL >= LL) {
		cout << LLN << endl;
	}
	else {
		cout << ULN << endl;
	}
}

Measured memory_bytes: 256
n,m,v,p = gets.split.map &:to_i
as = gets.split.map &:to_i

as_count = {}

as.each{ |a|
	if as_count[a] == nil then
		as_count[a] = 1
	else
		as_count[a] += 1
	end
}

as_key = as_count.keys.sort

sec = as.sort{|a,b| b <=> a}[p-1]
sec_index = as_key.index{ |x| x == sec }

count = as.count { |x| x == sec }

result = 0
#res = {}

totals = {}
count_sum = 0

sec_index.downto(0){ |i|
	if i == sec_index then
		totals[as_key[i]] = 0
	else
		count_sum += as_count[as_key[i + 1]]

		totals[as_key[i]] = totals[as_key[i + 1]] + (as_key[i + 1] - as_key[i]) * count_sum
	end
}

#print totals
#puts


as_key.each_with_index{ |a, i|
=begin
	if res[a] == true then
		result += 1
	elsif res[a] == false then
		next
	end
=end
	if sec <= a then
		result += as_count[a]
#		res[a] = true
		next
	end
	
	diff = sec - a

#	a_index = as_key.bsearch_index{ |x| x >= a }

=begin
	total = 0

	as_key[a_index .. sec_index].each{ |aa|
		total += as_count[aa] * (aa - a)
	}
=end
	
	if [diff, (totals[a] * 1.0 / (n - v)).ceil].max <= m then
		result += as_count[a]
#		res[a] = true
		next
	end

#	res[a] = false
}

puts result

Measured memory_bytes: 27384
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,k,idx;
  cin >> n >> k;
  ll a[n];
  bool dp[k+1],can;
  fill(dp,dp+k+1,false);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<=k;i++){
    can=false;
    for(int j=0;j<n;j++){
      idx = i-a[j];
      if(idx<0){
        break;
      }
      can = (!dp[idx]||can);
    }
    dp[i]=can;
  }
  if(dp[k]){
    cout <<"First\n";
  }else{
    cout <<"Second\n";
  }
}


Measured memory_bytes: 384
N,D = map(int,input().split())
X = [list(map(int,input().split())) for i in range(N)]


A = [i**2 for i in range(1,201)]


ans = 0

for i in range(N-1) :
    for j in range(i+1,N) :
        calc = 0
        for k in range(D) :
            calc += (X[i][k] - X[j][k])**2
        
        if calc in A :
            ans += 1
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#define mod 1000000007
using namespace std;
typedef long long ll;
bool chmax(ll &a,ll b){
    if(a>b)return 0;
    a=b; return 1;
}
bool chmin(ll &a,ll b){
    if(a<b)return 0;
    a=b; return 1;
}

#define N 2010
ll n;
ll idw[N],idb[N];
ll f[N][N],w[N][2*N],b[N][2*N];
int main(){
    cin>>n;
    for(int i=0;i<2*n;i++){
	char c; ll a;
	cin>>c>>a;
	if(c=='W')idw[a]=i;
	if(c=='B')idb[a]=i;
    }
    for(int i=0;i<n;i++){
	w[0][i]=b[0][i]=0;
    }
    for(int i=1;i<=n;i++){
	for(int j=0;j<=2*n;j++){
	    w[i][j]=w[i-1][j]+(j<=idw[i]);
	    b[i][j]=b[i-1][j]+(j<=idb[i]);
	}
    }
    for(int i=0;i<=n;i++)for(int j=0;j<=n;j++){
	if(i==0&&j==0){f[i][j]=0; continue;}
	f[i][j]=1e17;
	if(i)chmin(f[i][j],f[i-1][j]+b[j][idw[i]]);
	if(j)chmin(f[i][j],f[i][j-1]+w[i][idb[j]]);
    }
    ll ans=f[n][n];
    for(int i=1;i<=n;i++)for(int j=1;j<i;j++){
	ans+=idw[i]<idw[j];
	ans+=idb[i]<idb[j];
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 157952
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  vint A(n);
  rep(i,n) cin >> A[i];
  int ans = 0;
  rep(i,n){
    while(A[i] % 2 == 0){
      ans++;
      A[i] /= 2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		int res = 0;
		if (k - a <= 0) {
			System.out.println(k);
		} else {
			res += a;
			k -= a;
			if (k - b <= 0) {
				System.out.println(res);
			} else {
				k -= b;
				System.out.println(res + -1 * k);
			}
		}
	}
}


Measured memory_bytes: 35756
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    int n = s.size();
    bool ok = false;
    if (s == "keyence") ok = true;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            string tmp = s.substr(0,i);
            tmp += s.substr(j+1);
            if (tmp == "keyence") ok = true;
        }
    }
    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n, m;
    cin >> n >> m;

    vector<int> p(m);
    vector< vector<int> > r(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        p[i] = b;
        REP(j, a, b + 1){
            r[j].push_back(i);
        }
    }

    bool flag = true;
    int ans = 0;
    rep(i, n){
        if(r[i].empty()){
            flag = false;
            break;
        }
        int right = 0;
        for(auto x : r[i]){
            right = max(right, p[x]);
        }
        i = right;
        ++ans;
    }

    if(flag){
        cout << ans << endl;
    }else{
        cout << "Impossible" << endl;
    }

    return 0;
}


Measured memory_bytes: 3236
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

long long  smallnumber(long long a, long long b){
    if(a<b){
        return(a);
    } else {
        return(b);
    }
}

int main(void){
    long long q,h,s,d,n;
    scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
    long long ans;
    if (q*4<s){
        s=q*4;
    }
    if (h*2<s){
        s=h*2;
    }
    ans=smallnumber(n*s,(n/2)*d+(n%2)*s);
        
    printf("%lld\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  int ans = 0;
  for(int i=1;i<=n;i+=2){
    int count = 0;
    for(int j=1;j<=i;j++){
      if(i%j==0) count++;
    }
    if(count==8) ans++;
  }
  cout << ans << endl;
}


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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF INT_MAX
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	int n; cin>>n;
	vi num(n); forn(i, n) cin>>num[i];
	bool isValid = true;
	for(int a: num) isValid = isValid && (a%2==1||a%3==0||a%5==0);
	if(isValid) cout<<"APPROVED"<<endl; else cout<<"DENIED"<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	while(t--)
		solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int x[100000];
bool query(int i) {
    string V = "Vacant";
    string M = "Male";
    string F = "Female";
    cout << i << endl;
    string s;
    cin >> s;
    if (s == V) return 1;
    if (s == M) x[i] = 1;
    if (s == F) x[i] = 2;
    return 0;
}
bool check(int l, int r) {
    if (l == r) return 1;
    if (l > r) swap(l, r);
    return (x[l] == x[r] && (r-l) % 2 == 0) || (x[l] != x[r] && (r-l) % 2 == 1);
}
int main () {
    cin >> N;
    if (query(0)) return 0;
    if (query(N-1)) return 0;
    int k = 2;
    int L = 0, R = N-1;
    while (1) {
        int M = (L+R)/2;
        if (query(M)) return 0;
        k++;
        if (!check(L, M)) {
            R = M;
        }
        else if (!check(M, R)) {
            L = M;
        }
        else {

        }
        if (k == 20) {
            return 1;
        }
    }
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
long long int fact(long long int n){ 
   n--;
   return (n*(n+1))/2;
    
} 
int main()
{
   long long int n,ans=0;
   string s;
   map<string,long long int>cnt;
   cin>>n;
   while(n--){ 
       cin>>s;
       sort(s.begin(),s.end());
       cnt[s]++;
      // cout<<s<<endl; 
   } 
   for(auto &i:cnt){ 
       ans+=fact(i.second);
       //cout<<i.second<<endl; 
   }
   cout<<ans<<endl; 
   
 
    return 0;
}


Measured memory_bytes: 11136
/*
   ,##.                   ,==.
 ,#    #.                 \ o ',
#        #     _     _     \    \
#        #    (_)   (_)    /    ; 
 `#    #'                 /   .'  
   `##'                   "=="
*/

#include <bits/stdc++.h>
#define ll long long
#define null NULL

using namespace std;

const ll INF = 1e18;

const ll mx = 1e6;
ll n, a[mx], b[mx], sum, s = INF, ne;

signed main() {
	cin >> n;
	for (ll i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
	}
	for (ll i = 0; i < n; ++i) {
		sum += a[i];
		if (a[i] > b[i])
			s = min(s, b[i]);
		if (a[i] != b[i])
			ne = 1;
	}
	if (ne == 0) {
		cout << 0 << endl;
		return 0;
	}
	cout << sum - s << endl;
}

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

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

  LL sum = 0;
  rep(i, n) sum += b[i];

  for (int i = 0; i < n - 1; i ++) {
    if (a[i] + 1 == a[i + 1]) {
      sum += c[a[i] - 1];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

signed main()
{
	int H, A;
	cin >> H >> A;
	double d = H / (double)A;
	cout << ceil(d) << endl;
}



Measured memory_bytes: 256
N = int(input())

min_sum = None
for A in range(1,N):
  B = N - A
  a = [int(i) for i in list(str(A))]
  b = [int(i) for i in list(str(B))]
  y = sum(a) + sum(b)
  if min_sum is None or y < min_sum:
    min_sum = y
print(min_sum)

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

vector<int> to[101];
vector<int> d(101,-1);

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int u, k;
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            int v;
            cin >> v;
            to[u].push_back(v);
        }
    }

    queue<pair<int, int> > q;
    q.push(make_pair(1,0));

    while(q.size() > 0){
        pair<int, int> p = q.front();
        q.pop();
        int i = p.first;
        int t = p.second;

        if(d[i] != -1) continue;
        d[i] = t;
        for(int j = 0; j < to[i].size(); j++){
            q.push(make_pair(to[i][j], t+1));
        }
    }

    for(int i = 1; i <= n; i++){
        cout << i << " " << d[i] << endl;
    }

    return 0;
}


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

int main(){
	while(1){	
		int n, count=0;
		long before[13], after[13], c[13];
	
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i)scanf(" %ld", &before[i]);
				
		//loop
		while(1){
			
			for(int i=0; i<=12; ++i) c[i]=0;
			
			for(int i=0; i<n; ++i){
				for(int j=0; j<n; ++j){
					if(before[i] == before[j]) c[i]++;
				}
			}
				
			for(int i=0; i<n; ++i) after[i]=c[i];	
			
			bool flag=true;
			for(int i=0; i<n; ++i){
				if(before[i]!=after[i]){
					flag=false;
					break;	
				}
			}
			if(flag) break;
			
			/*
			for(int i=0; i<n; ++i){
				printf("%ld", after[i]);
				if(i<n-1) printf(" ");
			}
			printf("\n");
			*/
			
			count++;
			for(int i=0; i<n; ++i) before[i]=after[i];
		}
		
		printf("%d\n", count);
		for(int i=0; i<n; ++i){
			printf("%ld", after[i]);
			if(i<n-1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1192
//  D - Summer Vacation

package main

import "fmt"
import "container/heap"

func main() {
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	// k 日目までに有効な仕事の支払い
	jobs := map[int][]int{}

	for i := 0; i < N; i++ {
		var offset, pay int
		fmt.Scanf("%d %d", &offset, &pay)

		if offset > M {
			continue
		}

		deadline := M - offset

		if jobs[deadline] == nil {
			jobs[deadline] = []int{}
		}

		jobs[deadline] = append(jobs[deadline], pay)
	}

	total := 0

	h := &IntHeap{}
	heap.Init(h)

	for d := M - 1; d >= 0; d-- {
		if _, ok := jobs[d]; ok {
			for _, p := range jobs[d] {
				heap.Push(h, -p)
			}
		}

		if h.Len() > 0 {
			total += heap.Pop(h).(int) * -1
		}
	}

	fmt.Println(total)
}

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 12800
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

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

bool isPrime(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  string N;
  ll K;
  cin >> N >> K;
  vector<bool> D(10, true);

  for (ll i = 0; i < K; i++) {
    ll d;
    cin >> d;
    D[d] = false;
  }

  ll n = stoll(N);
  ll ans = -1;
  for (ll i = n; i <= 10 * n; i++) {
    string str = to_string(i);

    bool valid = true;
    for (char s : str) {
      if (D[s - '0'] == false) {
        valid = false;
        break;
      }
    }

    if (valid == false) {
      continue;
    } else {
      ans = i;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  Long k;
  cin >> k;
  Long ans = 0;
  fore(a, 0, k) fore(b, 0, k) fore(c, 0, k) {
    ans += __gcd(__gcd(a + 1, b + 1), c + 1);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <locale>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

int main() {
    string s;
    cin >> s;
    int flag =1;
    if((s[2] == s[3])&&(s[4] == s[5])){
        flag = 0;
    }
    if(flag == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [input() for i in range(n)]
d = {}

for i in range(4):
  for j in range(3):
    d.setdefault(i, []).append(j)
    if type(d[i][j]) == int:
      d[i][j] = []
    for k in range(10):
      d[i][j].append(0)

for i in range(len(s)):
  d[int(s[i].split()[0])-1][int(s[i].split()[1])-1][int(s[i].split()[2])-1] += int(s[i].split()[3])

for k,v in d.items():
	if k > 0:
		print('#'*20)
	for i in v:
		print(' '+' '.join(map(str,i)), end='')
		print()



Measured memory_bytes: 5616
h,n=map(int,input().split())
mahou=[list(map(int,input().split())) for i in range(n)]
INF=10**10
dp=[INF]*(h+1)#そのHPを与えるのに必要な最小MP
dp[0]=0
for hp in range(h+1):
  for use in mahou:
    dp[hp]=min(dp[max(0,hp-use[0])]+use[1],dp[hp])
print(dp[h])

Measured memory_bytes: 41072
l1 = [int(input()) for _ in range(5)]
l2 = [0] * 5
flag = 10
idx = -1

for i in range(5):
    l2[i] = l1[i] % 10
    if l2[i] != 0 and l2[i] < flag:
        flag = l2[i]
        idx = i
for j in range(5):
    if j == idx:
        continue
    while l1[j] % 10 != 0:
        l1[j] += 1
print(sum(l1))


Measured memory_bytes: 3060
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem2150 : Matsuzaki Number **/
const int MAX = 1e6;
int main()
{
	bool isPrime[MAX];
	memset(isPrime, 1, sizeof(isPrime));
	isPrime[0]=false, isPrime[1]=false;
	for (int i=2; i<MAX; i++) {
		if (isPrime[i]) {
			for (int j=2; i*j<MAX; j++) {
				isPrime[i*j]=false;
			}
		}
	}
	
	while (true) {
		int N, P;
		cin>>N>>P;
		if (N==-1&&P==-1) break;
		
		vector<int> pp;
		for (int i=N+1; i<MAX&&pp.size()<=P; i++) {
			if (isPrime[i])
				pp.push_back(i);
		}
		
		vector<int> m;
		for (int i=0; i<pp.size(); i++) {
			for (int j=i; j<pp.size(); j++) {
				m.push_back(pp[i]+pp[j]);
			}
		}
		
		sort(m.begin(), m.end());
		cout << m[P-1] << endl;
	}
}

Measured memory_bytes: 2256
object Main extends App {
  val sc = new java.util.Scanner(System.in) 
  var a = sc.nextLong()
  var b = sc.nextLong()
  var c = sc.nextLong()
  var ans = 0

  if (a == b && b == c) {
    if (a % 2 == 0) {
      println(-1)
    } else {
      println(0)
    }
  } else {
    println(calc(0, a, b, c))
  }
  
  def calc(acc: Int, a: Long, b: Long, c: Long): Int = {
    if (hasOdd(a,b,c)) {
      acc
    } else {
      calc(acc + 1, b/2 + c/2, a/2 + c/2, a/2 + b/2)
    }
  }
  
  def hasOdd(a: Long, b: Long, c: Long): Boolean = {
    a % 2 != 0 || b % 2 != 0 || c % 2 != 0
  }
}

Measured memory_bytes: 55176
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
              int K = sc.nextInt();
              String N = sc.next();
              if(K >= N.length()){
                System.out.println(N);
              } else {
                System.out.println(N.substring(0, K) + "...");
              }              
      }
    }

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

int main() {
  long long n;
  long long m = 1000000007;
  cin >> n;
  // 10^n
  long long tens = 1;
  for (int i = 0; i < n; i++) {
    tens *= 10;
    if (tens >= m) {
      tens %= m;
    }
  }
  // 9^n
  long long nins = 1;
  for (int i = 0; i < n; i++) {
    nins *= 9;
    if (nins >= m) {
      nins %= m;
    }
  }
  // 8^n
  long long eis = 1;
  for (int i=0; i < n; i++) {
    eis *= 8;
    if (eis >= m) {
      eis %= m;
    }
  }
  long long ans = (tens - (2*nins)%m + eis) % m;
  if (ans < 0) ans += m;
  cout << ans << endl;
}

Measured memory_bytes: 3616
import java.util.Scanner;
import java.util.Arrays;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    char[] in = sc.next().toCharArray();
    Arrays.sort(in);
    System.out.println(new String(in).equals("abc") ? "Yes" : "No");
  }
}




Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll n,q;
	cin>>n;
	string s;
	cin>>s;
	cin>>q;
	vector<set<ll>> v(26);
	REP(i,0,s.size()){
		v[s[i]-'a'].insert(i);
	}
	REP(i,0,q){
		ll x;
		cin>>x;
		if(x == 1){
			ll y;
			char z;
			cin>>y>>z;
			y--;
			v[s[y] - 'a'].erase(y);
			s[y] = z;
			v[s[y] - 'a'].insert(y);
		}
		else {
			ll y,z;
			cin>>y>>z;
			y--; z--;
			ll sum = 0;
			REP(j,0,26){
				auto it = v[j].lower_bound(y);
				if(it != v[j].end()){
					ll k = *it;
					if(k <= z){
						sum++;
					}
				}
			}
			cout<<sum<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 24196
import fractions


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


a, b, c, d = map(int, input().split())

cntC = b // c - (a - 1) // c
cntD = b // d - (a - 1) // d
cntCandD = b // lcm(c, d) - (a - 1) // lcm(c, d)

# print(cntC, cntD, cntCandD)
print(b - a + 1 - cntC - cntD + cntCandD)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=998244353;

bool ok(int x){
    if(0<x && x<=12) return true;
    else return false;
}

int main(void){
    int s;
    cin>>s;
    int l=s/100,r=s%100;
    if(ok(l)){
        if(ok(r)) puts("AMBIGUOUS");
        else puts("MMYY");
    }
    else{
        if(ok(r)) puts("YYMM");
        else puts("NA");
    }
    return 0;
}

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

int main() {
   long long int a,b,k;
    cin>>a>>b>>k;
    long long int t=k;
    if(k>a){
        long long int c=(k-a);
        long long int d=b-c;
        if(d<0) cout<<0<<" "<<0;
        else cout<<0<<" "<<d;
    }
    else{
        cout<<(a-k)<<" "<<b;
    }
    return 0;
    
}

Measured memory_bytes: 256
S = gets.chomp

c1 = 0
c2 = 0

S.each_char.with_index do |ch, i|
  if i.even?
    c1 += 1 if ch == '1'
    c2 += 1 if ch == '0'
  else
    c1 += 1 if ch == '0'
    c2 += 1 if ch == '1'
  end
end

puts [c1, c2].min


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

#define Z 2500

using edge = pair<ll, pll>;

int main()
{
    ll N, M, S;
    cin >> N >> M >> S;
    vector<vector<edge>> G(N);
    REP(i,0,M) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        --u; --v;
        G[u].pb(edge(v, pll(a, b)));
        G[v].pb(edge(u, pll(a, b)));
    }
    vec C(N), D(N);
    REP(i,0,N) cin >> C[i] >> D[i];

    S = MIN(S,Z);
    mat dp(N, vec(Z+1, INF));
    priority_queue<pair<ll,pll>, vector<pair<ll,pll>>, greater<pair<ll,pll>>> Q;
    dp[0][S] = 0;
    Q.push(make_pair(0, pll(0, S)));

    while(!Q.empty()) {
        
        auto p = Q.top(); Q.pop();
        ll v = p.second.first, s = p.second.second, time = p.first;
        if(time > dp[v][s]) continue;

        if(s + C[v] <= Z) {
            ll ns = s + C[v];
            ll ntime = time + D[v];
            if(dp[v][ns] > ntime) {
                dp[v][ns] = ntime;
                Q.push(make_pair(ntime, pll(v, ns)));
            }
        }

        FORR(e,G[v]) {
            if(s < e.second.first) continue;
            ll nv = e.first;
            ll ns = s - e.second.first;
            ll ntime = time + e.second.second;
            if(dp[nv][ns] > ntime) {
                dp[nv][ns] = ntime;
                Q.push(make_pair(ntime, pll(nv, ns)));
            }
        }

    }

    REP(v,1,N) {
        ll res = INF;
        REP(s,0,Z+1) res = MIN(res,dp[v][s]);
        PR(res);
    }

    return 0;
}

/*



*/

Measured memory_bytes: 7320