akhauriyash/Code-Regression huggingface dataset:
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let m = v[1];
	let mut a:Vec<Vec<char>> = Vec::new();
	let mut b:Vec<Vec<char>> = Vec::new();
	for i in 0..n{
		let mut buf = String::new();
		io::stdin().read_line(&mut buf).expect("");
		let cur:Vec<char> = buf.trim().chars().collect();
		a.push(cur);
	}
	for i in 0..m{
		let mut buf = String::new();
		io::stdin().read_line(&mut buf).expect("");
		let cur:Vec<char> = buf.trim().chars().collect();
		b.push(cur);
	}
	
	let mut exist = false;
	for i in 0..n {
		for j in 0..n {
			if i+m-1 >= n || j+m-1 >= n {
				continue;
			}
			let mut flag = true;
			for k in 0..m {
				for o in 0..m {
					if a[(i+k) as usize][(j+o) as usize] != b[k as usize][o as usize] {
						flag = false;
					}
				}
			}
			if flag {
				exist = true;
			}
		}
	}
	if exist {
		println!("Yes");
	}else{
		println!("No");
	}
	
}

Measured memory_bytes: 4352
# include <stdio.h>
int main()
{
    int n, x, t=1;
    scanf("%d%d",&n,&x);
    if(x == 1 || x == 2*n-1)
        return 0*puts("No");
    puts("Yes");
    for(int i=1; i<n-1; ++i)
    {
        while(t==x || t==x-1 || t==x+1) ++t;
        printf("%d\n",t++);
    }
    printf("%d\n%d\n%d\n",x-1,x,x+1);
    for(int i=1; i<n-1; ++i)
    {
        while(t==x || t==x-1 || t==x+1) ++t;
        printf("%d\n",t++);
    }
    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main(void){
	int a, b, c, i;
	int count = 0;
	scanf("%d %d %d", &a, &b, &c);
	for(i = a; i <= b; i++){
		if(c % i == 0){
			count+=1;
		}
	}
	printf("%d\n", count);
	return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

#define MT make_tuple

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

  LL A, B, C, N;
  cin >> A >> B >> C >> N;

  LL ans = 2 * (A*B + B*C + C*A);
  set<tuple<LL,LL,LL>> del;

  REP(i,N){
	LL x, y, z;
	cin >> x >> y >> z;
	if(del.count(MT(x,y,z))) continue;

	int cnt = 0;
	if(x-1 < 0 || del.count(MT(x-1,y,z)))
	  ++cnt;
	if(A <= x+1 || del.count(MT(x+1,y,z)))
	  ++cnt;
	if(cnt == 0) ans += 2;
	else if(cnt == 2) ans -= 2;

  	cnt = 0;
	if(y-1 < 0 || del.count(MT(x,y-1,z)))
	  ++cnt;
	if(B <= y+1 || del.count(MT(x,y+1,z)))
	  ++cnt;
	if(cnt == 0) ans += 2;
	else if(cnt == 2) ans -= 2;

  	cnt = 0;
	if(z-1 < 0 || del.count(MT(x,y,z-1)))
	  ++cnt;
	if(C <= z+1 || del.count(MT(x,y,z+1)))
	  ++cnt;
	if(cnt == 0) ans += 2;
	else if(cnt == 2) ans -= 2;

	del.insert(MT(x,y,z));
  }

  cout << ans << endl;

  return 0;
}

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

int main()
{
    const int MAX_N = 100;
    int N, K;
    int X[MAX_N];

    cin >> N >> K;
    for (int i = 0; i < N; ++i)
    {
        cin >> X[i];
    }

    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        int tmp = min(X[i], K - X[i]);
        ans += tmp;
    }
    cout << ans * 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <unordered_map>
#include <queue>
#include <map>
#include <sstream>
#include <set>
#include <cstdlib>
#include <ctime>
#include <unordered_set>
#include <bitset>
#include <chrono>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
//#pragma GCC optimize(3, "Ofast", "inline")
#define MAX_INF 0x3f3f3f3f
template <class T, class C>
void print(C name, T a)
{
	cout << name << ": " << a << endl;
}
template <class T>
T gcd(T a, T b)
{
	return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b, ll p)
{
	ll ans = 1;
	a %= p;
	while (b)
	{
		if (b & 1)
			ans = ans * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return ans;
}
template <typename _Tp>
void read(_Tp &x)
{
	char ch;
	bool flag = 0;
	x = 0;
	while (ch = getchar(), !isdigit(ch))
		if (ch == '-')
			flag = 1;
	while (isdigit(ch))
		x = x * 10 + ch - '0', ch = getchar();
	if (flag)
		x = -x;
}
template <class T>
void print(T x)
{
	if (x < 0)
	{
		x = -x;
		putchar('-');
	}
	if (x > 9)
		print(x / 10);
	putchar(x % 10 + '0');
}
const ll mod = 998244353;
const ll inf = 1e18;
ll add(ll x, ll t)
{
	x %= mod;
	t %= mod;
	return (x + t) % mod;
}
ll del(ll ans, ll x)
{
	ans %= mod;
	ans += mod;
	x %= mod;
	return (ans - x) % mod;
}
ll mul(ll ans, ll x)
{
	ans %= mod;
	x %= mod;
	return (ans * x) % mod;
}
#define fir(i, a, b) for (int i = a; i <= b; i++)
const int maxn = 1e5 + 20, N = 2010, M = 3000 + 10;
ll a[maxn];
int main()
{
	int n;
	cin>>n;
	fir(i,1,n)
	scanf("%lld",&a[i]);
	ll ans=0;
	fir(i,1,n)
	{
		fir(j,i+1,n)
		{
			if(a[i]==a[j])
			continue;
			fir(k,j+1,n)
			{
				if(a[j]==a[k]||a[i]==a[k])
				continue;
				ll t[3]={a[i],a[j],a[k]};
				sort(t,t+3);
				if(t[0]+t[1]>t[2])
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3260
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ABC073C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            Dictionary<int, int> a = new Dictionary<int, int>();            
            for(int i=0;i<N;i++) {
                int tmp = int.Parse(Console.ReadLine());
                if(a.ContainsKey(tmp)) {
                    a[tmp]++;
                } else {
                    a.Add(tmp, 1);
                }
            }
            int count = 0;
            foreach(var i in a){
                if(i.Value % 2 == 1) count++;
            }
            Console.WriteLine(count);
        }
    }
}


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

using namespace std; 

int n, m; 
int S[3005][3005]; 
int C[3005][3005]; 
int pw2m[3005], pw2mm[3005];  


int add(int x, int y) {
    return (x += y) >= m ? x - m : x; 
}

void work() {
    S[0][0] = C[0][0] = 1; 
    for (int i = 1; i <= n + 1; i++) {
        C[i][0] = 1;   
        for (int j = 1; j <= i; j++) {
            S[i][j] = add(S[i - 1][j - 1], 1ll * S[i - 1][j] * j % m); 
            C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]); 
        }
    }
    pw2m[0] = pw2mm[0] = 1; 
    for (int i = 1; i <= n; i++)
        pw2m[i] = 1ll * pw2m[i - 1] * 2 % m, 
        pw2mm[i] = 1ll * pw2mm[i - 1] * 2 % (m - 1);  
}

int fpw(int x, int k, int p) {
    int ret = 1; 
    while (k) {
        if (k & 1) ret = 1ll * ret * x % p; 
        x = 1ll * x * x % p; k >>= 1; 
    }
    return ret; 
}

int main() {
    cin >> n >> m;
    work(); 
    int ans = 0;  
    for (int i = 0; i <= n; i++) {
        int pig = 0; 
        for (int j = 0; j <= i; j++) {
            int t1 = fpw(2, pw2mm[n - i], m);
            int t2 = fpw(pw2m[n - i], j, m);  
            pig = add(pig, 1ll * S[i + 1][j + 1] % m * t1 % m * t2 % m); 
        }
        ans = add(ans, 1ll * pig * C[n][i] % m * ((i & 1) ? m - 1 : 1) % m); 
    }
    cout << ans << '\n'; 
    return 0; 
}

Measured memory_bytes: 69504
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    S = input()

    aa = int(S[:2])
    bb = int(S[2:])

    # print(aa,bb)
    if (aa > 12 and bb > 12) or (aa == 0 and bb == 0):
        print("NA")
    elif aa >= 1 and aa <= 12 and bb >= 1 and bb <= 12:
        print("AMBIGUOUS")
    elif aa >= 1 and aa <= 12:
        print("MMYY")
    elif bb >= 1 and bb <= 12:
        print("YYMM")
    else:
        print("NA")


if __name__ == '__main__':
    main()

    

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int r1, r2;
  cin >> r1 >> r2;

  // 解答
  printf("%.8f\n", (double)(r1 * r2) / (r1 + r2));

  return 0;
}


Measured memory_bytes: 256
k,n = gets.split(' ').map(&:to_i)
res = []
a = gets.split(' ')
b = a << a[0]
c = b.each_cons(2) do |v|
  if v[1].to_i > v[0].to_i
    res << v[1].to_i - v[0].to_i
  else
    res << (k - v[0].to_i) + v[1].to_i
  end
end
res.delete_at(res.index(res.max))
puts res.inject(&:+)

Measured memory_bytes: 19332
#include <iostream>
#include <vector>
#include <array>
#include <cmath>
#include <string>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <limits>  //std::numeric_limits<int>::max(), min()

int main (void) {

  int N, M;
  std::cin >> N >> M;

  std::vector<int> stack(N+1);
  for(int i=0; i<M; i++) {
    int L, R; std::cin >> L >> R;
    stack[L-1]++;
    stack[R]--;
  }

  for(int i=0; i<N+1; i++) {
    if ( i > 0 ) stack[i] += stack[i-1];
  }

  int ans = 0;
  for(int i=0; i<N+1; i++) {
    if ( stack[i] == M ) ans++;
  }

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

  return 0;
}

Measured memory_bytes: 640
import math
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
N = int(input())
arr = list(map(int, input().split()))
M = max(arr)
arr.sort()
check = [0]*(M+1)
flg = True
for i in arr:
    for k in make_divisors(i):
        if check[k] != 0 and k != 1:
            flg = False
            break
        else:
            check[k] = 1
    if not flg:
        break
if flg:
    print('pairwise coprime')
    exit()
first = arr[0]
for i in range(1,N):
    first = math.gcd(first,arr[i])
if first == 1:
    print('setwise coprime')
else:
    print('not coprime')

Measured memory_bytes: 189500
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

int main()
{
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> x[i] >> y[i];
  double sum = 0.0;
  vector<int> v(n);
  for(int i = 0;i < n;i++)
  {
    v[i] = i+1;
  }
  do
  {
    for(int i = 0;i < n-1;i++)
    {
      sum += dist(v[i],v[i+1]);
    }
  } while(next_permutation(v.begin(),v.end()));
  int Factorial = 1;
  for(int i = 2;i <= n;i++)
  {
    Factorial *= i;
  }
  cout << fixed << setprecision(10) << sum / Factorial << endl;
}


Measured memory_bytes: 512
T1,T2,A1,A2,B1,B2=map(int,open(0).read().split())
D1,D2=(A1-B1)*T1,(A1-B1)*T1+(A2-B2)*T2
if D1*D2>0:print(0)
elif D2==0:print("infinity")
else:print(-D1//D2*2+1-(-D1%D2==0))

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Reading a Chord
public class Main{

	boolean ok(boolean[] a, boolean[] b){
		for(int i=0;i<12;i++)if(a[i]!=b[i])return false;
		return true;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		String[] tones = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
		String[] add = {"","7","M7","m","m7"};
		int[][] adds = {{4,7},{4,7,10},{4,7,11},{3,7},{3,7,10}};
		String[] tension = {"","-9","9","+9","-11","11","+11","","-13","13","+13"};
		int T = sc.nextInt();
		while(T--!=0){
			int n = sc.nextInt();
			boolean[] t = new boolean[12];
			for(int i=0;i<n;i++){
				String c = sc.next();
				for(int k=0;k<12;k++)if(tones[k].equals(c)){
					t[k] = true; break;
				}
			}
			List<String> res = new ArrayList<String>();
			for(int b=0;b<12;b++)for(int a=0;a<5;a++){
				boolean[] r = new boolean[12];
				r[b] = true;
				for(int k:adds[a])r[(b+k)%12] = true;
				if(ok(r, t)){
					res.add(tones[b]+add[a]); continue;
				}
				for(int k=1;k<11;k++){
					if(k==7)continue;
					int x = (b+k)%12;
					boolean p = r[x];
					r[x] = true;
					if(ok(r, t))res.add(tones[b]+add[a]+"("+tension[k]+")");
					r[x] = p;
				}
				r[(b+7)%12] = false; r[(b+18)%12] = true;
				if(ok(r, t))res.add(tones[b]+add[a]+"(-5)");
				r[(b+18)%12] = false; r[(b+8)%12] = true;
				if(ok(r, t))res.add(tones[b]+add[a]+"(+5)");
			}
			if(res.isEmpty())System.out.println("UNKNOWN");
			else{
				for(int i=0;i<res.size();i++)System.out.print(res.get(i)+(i==res.size()-1?"\n":" "));
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a=new int[n];
		int[] g=new int[n+1];
      	long al=0;
		for(int i=0;i<n;i++){
			a[i]= sc.nextInt();
          	al+=g[a[i]];
          	g[a[i]]++;
		}
      	long all=0;
      	for(int i=0;i<n;i++){
          all+=g[i]*(g[i]-1)/2;
        }  
      	//System.out.println(all);
		//System.out.println(al);

		for(int i=0;i<n;i++){
			System.out.println(al-g[a[i]]+1);
		}
		
	}
}


Measured memory_bytes: 100976
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    A = readInts()
    import math
    nokori = n - k
    #print(nokori)
    cnt = 1
    cnt += math.ceil(nokori/(k-1))
    print(cnt)




if __name__ == '__main__':
  main()


Measured memory_bytes: 14008
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>=1;
    }
    return res;
}


int main(){
    ld a,b;
    cin >> a >> b;
    ll ans = floor(a*b);
    cout << ans << endl;

}



Measured memory_bytes: 3728
n, m = [int(i) for i in input().split()]
ans = [input().split() for _ in range(m)]

is_ac = [0 for i in range(n)]
cnt_wa = [0 for i in range(n)]
for p, s in ans:
  p = int(p) - 1
  if is_ac[p]:
    continue
  if s == 'AC':
    is_ac[p] = 1
  else:
    cnt_wa[p] += 1

cor = sum(is_ac)
pena = 0
for p, c in enumerate(is_ac):
  if c:
    pena += cnt_wa[p]

print(cor, pena)

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

int main(){
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  int k = K - 1;
  
  if (S.at(k) == 'A'){
    S.at(k) = 'a';
  }
  else if (S.at(k) == 'B'){
    S.at(k) = 'b';
  }
  else {
    S.at(k) = 'c';
  }
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, d, i, ans=0;

    cin >> n >> d;
    for(i=0;i<n;i++){
        double x, y, xx, yy;
        cin >> x >> y;
        xx=x*x;yy=y*y;
        if(sqrt(xx+yy)<=d){
            ans++;
        }
    }

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



Measured memory_bytes: 3820
#include<stdio.h>

int partition(int *,int,int);
int A[100000];

int main()
{
  int i,m,n;
  scanf("%d",&n);

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

  for(i=0;i<n;i++)
    {
      if(i>0)
	{
	  printf(" ");
	}
      if(m==i)
	{
	  printf("[%d]",A[i]);
	}
      else printf("%d",A[i]);
    }
  printf("\n");
  
  return 0;
}


int partition(int A[],int p,int r)
{
  int x,l,j,i;
  x=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++)
    {
      if(A[j]<=x)
	{
	  i=i+1;
	  l=A[i];
	  A[i]=A[j];
	  A[j]=l;
	}
    }
  l=A[i+1];
  A[i+1]=A[r];
  A[r]=l;

  return i+1;
}

Measured memory_bytes: 988
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const ll mod=1e+9;
typedef pair<ll,ll> P;
#define fi first
#define se second
int main(){
  string s;
  cin>>s;
  for(char c='a';c<='z';c++){
    bool check=true;
    for(int i=0;i<s.size();i++){
      if(s.at(i)==c)check=false;
    }
    if(check){
      cout<<c<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}

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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            var t = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            Console.WriteLine((s[0] - t[0]) * (s[1] - t[1]));

        }
    }
}


Measured memory_bytes: 11220
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> C(n);
    for (auto & c : C) {
        cin >> c.first >> c.second;
    }
    sort(C.begin(), C.end());
    ll res = 0;
    for (auto & c : C) {
        //cerr << "m is " << m << endl;
        if (m >= c.second) {
            //cerr << c.second << " * " << c.first << " = " << c.second * c.first << endl;
            res += c.second * c.first;
            m -= c.second;
        } else {
            //cerr << m << " * " << c.first << " = " << m * c.first << endl;
            res += m * c.first;
            break;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 1792
function Main(input) {
  const inputSplit = input.split('\n');
  console.log(`ABC${inputSplit[0]}`);
}
//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
tmp = []
for i in range(N):
    H[i] = abs((T-H[i]*0.006)-A)
ans = min(H)
for j in range(N):
    if H[j] == ans:
        ans = j+1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl;
#define STOP assert(false);
#else
#define dump(x) ;
#define LINE 	;
#define dumpV(v);
#define STOP 	;
#endif

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


int main(){
	ll p, q;
	cin >> p >> q;
	ll g = __gcd(p, q);
	p /= g;
	q /= g;
	ll ans = 1LL;
	for(ll i = 2LL; i * i <= q; i++) {
		if(q % i == 0) {
			ans *= i;
			while(q%i == 0) q /= i;
		}
	}
	ans *= q;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3100
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        int[]x = new int[5];

        for(int i=0; i<5; i++){
        x[i] = sc.nextInt();
        if(x[i]==0){
            System.out.println(i+1);
    }         
}
}
}

Measured memory_bytes: 35812
/* ***********************************************
Author        :yang12138
Created Time  :2017/9/5 12:35:21
File Name     :D.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;

const int N=1e5+10;

int a[N];
vector<int>dat;

void solve(){
	int n;
	scanf("%d",&n);

	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		if(a[i]==i) dat.push_back(i);
	}

	int ans=0;
	for(int i=0;i<dat.size();){
		if(i+1<dat.size() && dat[i+1]==dat[i]+1) ans++,i+=2;
		else ans++,i++;
	}
	printf("%d\n",ans);
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	
	solve();
    
    return 0;
}


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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
//#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define tcase int _; cin>> _; for( ; _; --_)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 998244353;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

void solve(){
	int n, s;
	cin>> n >> s;

	vi a(n);

	for(int &i: a) cin>> i;

	int dp[n*s + 1];

	memset(dp, 0, sizeof(dp));
	int ans = 0;

	for(int i = 0; i<n; ++i){
		dp[0] = mod(dp[0] + 1, MOD);

		for(int j = s; j >=0; --j){
			if(j + a[i] <= s) dp[j + a[i]] = mod(dp[j + a[i]] + dp[j], MOD);
		}
		ans = mod(ans + dp[s], MOD);
	}
	cout<< ans << endl;
}

int32_t main(){
	fastio;
	solve();
	return 0;
}

Measured memory_bytes: 38716
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,cnt=0;
    scanf("%d",&n);
    int arr[n];
    for(int i=0;i<n;i++)
    scanf("%d",&arr[i]);
     for(int i=0;i<n-1;i++)
         for(int j=0;j<n-i-1;j++)
         {
             if(arr[j]>arr[j+1])
             {
                 swap(arr[j],arr[j+1]);
                 cnt++;
             }
         }
 for(int i=0;i<n-1;i++)
    printf("%d ",arr[i]);
printf("%d\n",arr[n-1]);
 printf("%d\n",cnt);
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main()
{
  int N, T, A, i, ans = 1;
  cin >> N >> T >> A;
  int H[N];
  T *= 1000;
  A *= 1000;
  for (i = 0; i < N; ++i) {
    cin >> H[i];
    H[i] = abs(T-H[i]*6-A);
  }
  int now = H[0];
  for (i = 0; i < N; ++i) {
    if ( H[i] < now) {
      now = H[i];
      ans = i+1;
    }
  }
  cout << ans ;
  return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

// ------------------------------------------------------------------------------------------

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a * b ) / 2 << endl;

  return 0;
}

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

int main(){
    vector <vector <int> > c(3, vector <int> (3));
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> c[i][j];
        }
    }

    int ok=0;
    int a12=c[0][0]-c[1][0], a23=c[1][0]-c[2][0], a31=c[2][0]-c[0][0], b12=c[0][0]-c[0][1], b23=c[0][1]-c[0][2], b31=c[0][2]-c[0][0];
    
    for(int i=0; i<3; i++){
        if(c[0][i]-c[1][i] != a12){
            ok++;
        }
        if(c[1][i]-c[2][i] != a23){
            ok++;
        }
        if(c[2][i]-c[0][i] != a31){
            ok++;
        }
        if(ok != 0){
            break;
        }
    }
    for(int i=0; i<3; i++){
        if(c[i][0]-c[i][1] != b12){
            ok++;
        }
        if(c[i][1]-c[i][2] != b23){
            ok++;
        }
        if(c[i][2]-c[i][0] != b31){
            ok++;
        }
        if(ok != 0){
            break;
        }
    }
    if(ok == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(void) {
  int x;cin>>x;
  cout<<x/500*1000+(x%500)/5*5<<endl;
  return 0;
}

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

int main(){
    int n, w_limit;
    cin >> n >> w_limit;
    vector<int> v(n);
    vector<int> w(n);
    for(int i = 0; i < n; i++) cin >> v[i] >> w[i];
    
    vector<vector<int> > memo(n+1, vector<int>(w_limit+1, 0));
    
    //for(int i = 0; i <= w_limit; i++) memo[0][i] = 0;
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= w_limit; j++){
            if(j - w[i] >= 0){
                memo[i+1][j] = max(memo[i][j], memo[i][j-w[i]]+v[i]);
            }else{
                memo[i+1][j] = memo[i][j];
            }
        }
    }
    
    cout << memo[n][w_limit] << endl;
    return 0;
}
    


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

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;
// Tの最小公倍数を求めよ
ll gcd(ll a,ll b){
	if(b == 0) return a;
	return gcd(b, a%b);
}
int main(){
	int N;
	ll T[110];
	cin >> N;
	rep (i,N){
		cin >> T[i];
	}
	rep(i,N-1){
		T[i+1] = T[i]/gcd(T[i],T[i+1])*T[i+1];
	}
	cout << T[N-1] << endl;;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(void){
    int a,b,s,n;
    while(cin >> a >> b){
             
    n=0;
    s=a+b;
    while(s!=0){
    s=s/10;
    n=n+1;
    }
    cout << n << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int INF=1e9;
int main(){
    int wf[100][100];
    int N,M;
    while(scanf("%d%d",&N,&M),N||M){
        fill_n(*wf,10000,INF);
        for(int i=0;i<N;i++)wf[i][i]=0;

        while(M--){
            int type;scanf("%d",&type);
            if(type){
                int a,b,c;
                scanf("%d%d%d",&a,&b,&c);
                a--;b--;
                wf[a][b]=min(wf[a][b],c);
                wf[b][a]=min(wf[b][a],c);
                for(int i=0;i<N;i++){
                    for(int j=0;j<N;j++){
                        int v1=wf[i][a]+wf[a][b]+wf[b][j];
                        int v2=wf[i][b]+wf[b][a]+wf[a][j];
                        wf[i][j]=min(wf[i][j],min(v1,v2));
                    }
                }
            }
            else{
                int a,b;
                scanf("%d%d",&a,&b);
                a--;b--;
                if(wf[a][b]==INF)puts("-1");
                else printf("%d\n",wf[a][b]);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1076
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <fstream>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <stack>
#include <map>
#include <set>
#if __cplusplus > 199711L
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//	tree<key, mapped = null_type, cmp = less<key>, rb_tree_tag, tree_order_statistics_node_update> name;
//	order_of_key
//	find_by_order
#endif

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fs first
#define sc second
#define abs(a) ((a) < 0 ? -(a) : (a))
#define sqr(a) ((a) * (a))

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

inline pair<pair<bool, bool>, pair<string, bool> > useinout();

void init() {
#ifdef SOL
	if (useinout().fs.fs)
		freopen("input.txt", "r", stdin);
	if (useinout().fs.sc)
		freopen("output.txt", "w", stdout);
#else
	srand(time(0));
	const string file = useinout().sc.fs;
	if (!file.empty()) {
		freopen((file + ".in").c_str(), "r", stdin);
		freopen((file + ".out").c_str(), "w", stdout);
	}
	if(useinout().sc.sc) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
}

int solve();

void finish(int exitval) {
	fflush(stdout);
#ifdef SOL
	fprintf(stderr, "\nexit value: %d\ntime: %.3lf ms\n", exitval, 1000. * clock() / CLOCKS_PER_SEC);
#endif
}

int main() {
	init();
	int exitval = solve();
	finish(exitval);
	return (0);
}

const double eps = 1e-9;
const int mod = (int) 1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;

inline pair<pair<bool, bool>, pair<string, bool> > useinout() {
	return (mp(mp(0, 0), mp("", 0)));
}

int a[maxn];

int solve() {

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	ll ans = a[0] - 1;
	int mx = 1;
	for (int i = 1; i < n; i++) {
		if (a[i] > mx + 1) {
			a[i]--;
			int cnt = a[i] / (mx + 1);
			ans += cnt;
		} else if (a[i] == mx + 1) {
			mx = mx + 1;
		}
//		cout << ans << endl;
	}
	printf("%lld\n", ans);

	return (0);
}

// by Andrey Kim


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

using namespace std;
typedef long long int lli;

#define all(arr) arr.begin(),arr.end()
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define MOD 1000000007

template <typename T>
void input(vector<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.push_back(temp);
}

template <typename T>
void output(vector<T> arr) {
  for(auto x:arr) cout<<x<<" ";
  cout<<endl;
}


template <typename T>
void input_set(set<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.insert(temp);
}

lli mul(lli a, lli b) {
  return (a%MOD*b%MOD)%MOD;
}

lli power(lli a,lli b) {
  lli ans = 1;
  while(b > 0) {
    if(b&1)
      ans = mul(ans, a);
    a = mul(a,a);;
    b >>= 1;
  }
  return ans;
}

void solve() {
  int n=5;
  vector<int> arr;
  input(arr, 5);
  for(int i=0; i<5; i++)
    if(arr[i]==0)
      cout << i + 1 << endl;

}

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

  lli testcases=1;
  while(testcases--) {
    solve();
  }
}



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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;


string solve(ll A, ll B, ll C) {
    if (C - (A + B) < 0)
        return "No";

    ll t = 4 * A * B;
    ll s = (C - (A + B)) * (C - (A + B));
    if (t < s)
        return "Yes";
    return "No";
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C;
    cin >> A >> B >> C;
    cout << solve(A, B, C) << endl;
    return 0;
}

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

public class Main {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));

        int N = nextInt();
        int K = nextInt();

        int cnt[] = new int[N+1];

        for(int i = 0; i<K; i++){
            int d = nextInt();
            for(int j = 0; j<d; j++){
                cnt[nextInt()] ++;
            }
        }
        
        int ans = 0;
        for(int i = 1; i<= N; i++){
            if(cnt[i]==0){
                ans++;
            }
        }
    
        System.out.println(ans);

    }
    
      
    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

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

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

Measured memory_bytes: 33460
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

s = STR()
a = []
i = 0
while i < len(s):
    if s[i] == 'A':
        a.append(0)
        i += 1
    elif i < len(s) - 1 and s[i:i + 2] == 'BC':
        a.append(1)
        i += 2
    else:
        a.append(2)
        i += 1
debug(a)
arr = []
bgn = -1
end = -1
for i in range(len(a)):
    if bgn == -1 and a[i] != 2:
        bgn = i
    if a[i] == 2 and end == -1:
        end = i
        arr.append(a[bgn:end])
        bgn = -1
        end = -1
arr.append(a[bgn:len(a) + 1])
debug(arr)
ans = 0
for b in arr:
    num0 = 0
    for i in b:
        if i == 0:
            num0 += 1
        if i == 1:
            ans += num0
print(ans)


Measured memory_bytes: 82552
def solve():
    N = int(input())
    
    def dfs(s, mx):
        if len(s) == N:
            print(s)
        else:
            for i in range(ord('a'), ord(mx)+1):
                m = ord(mx)+1 if i == ord(mx) else ord(mx)
                dfs(s + chr(i), chr(m))
    dfs('', 'a')

solve()

Measured memory_bytes: 4340
package main

import(
	"fmt"
)

func main(){
	var n,l int
	fmt.Scanln(&n,&l)
	r:=l+n-1
	sum:=(l+r)*n/2
	ans:=sum
	if l>=0{
		ans=sum-l
	} else if r<=0{
		ans=sum-r
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    for (int i = 1; i <= N; i++){
        if(i < 10){
            ans++;
        }else if (i >= 100 && i <= 999){
            ans++;
        }else if (i >= 10000 && i <= 99999){
            ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    S = "*" + input()
    N = len(S) - 1

    if S[N] == "1":
        return print(-1)
    if S[1] == "0":
        return print(-1)

    edge = []
    cur_u = 1
    cur_v = 2

    for i in range(1, N // 2 + 1):
        if S[i] != S[N - i]:
            return print(-1)

        edge.append([cur_u, cur_v])
        if S[i] == "1":
            cur_u = cur_v
        cur_v += 1

    for i in range(cur_v, N + 1):
        edge.append([cur_u, i])

    for i in range(N - 1):
        print(*edge[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 87200
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define N 3939
vector<int> gr[N];
int num[N],dp[N];
vector<int> out;
int dfs(int v){
	if(dp[v]>=0) return dp[v];
	dp[v]=1;
	rep(i,gr[v].size()){
		if(num[v]<=num[gr[v][i]]) continue;
		if(dfs(gr[v][i])>0) dp[v]=0;
	}
	return dp[v];
}
int main()
{
	int n,a,b;
	cin>>n;
	rep(i,n) cin>>num[i];
	rep(i,n-1){
		cin>>a>>b;a--;b--;
		gr[a].pb(b);gr[b].pb(a);
	}
	memset(dp,-1,sizeof(dp));
	rep(i,n){
		if(dfs(i)<1) out.pb(i+1);
	}
	int m=out.size();
	rep(i,m){
		cout<<out[i];
		if(i<m-1) cout<<' ';else cout<<endl;
	}
}


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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int memo[1000000];
int res(int n) {
  if(n == 0) return 0;
  if(memo[n] != -1) return memo[n];
  int ans = n;
  for(int i = 1; i <= n; i *= 6) {
    ans = min(ans, res(n - i) + 1);
  }

  for(int i = 1; i <= n; i *= 9) {
    ans = min(ans, res(n - i) + 1);
  }

  return memo[n] = ans;
}

int main() {
  
  int N; 
  cin >> N;
  vector<int> dp(1000000);
  for(int i = 0; i < 1000000; i++) {
    dp[i] = N;
  }
  dp[0] = 0;
  for(int n = 0; n < N; n++) {
    for(int i = 1; n + i <= N; i *= 6) {
      dp[n + i] = min(dp[n + i], dp[n] + 1);
    }
    for(int j = 1; j + n <= N; j *= 9) {
      dp[n + j] = min(dp[n + j], dp[n] + 1);
    } 
  }

  cout << dp[N];
  
  return 0;
}

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

int main(){
    ll int n,k,l;
    vector<ll> s;
    cin >> n;
  n--;
    while(n>=0){
        k=n%26;
        n/=26;
      n--;
        s.push_back(k);
    }
    l=s.size();
    for(int i=l-1;i>=0;i--){
        cout << (char)(s[i]+'a');
    }
}

Measured memory_bytes: 3600
N, M = map(int,raw_input().split())
S = []
for i in range(M):
        S.append(map(int, raw_input().split()))

toN =[]
first = []
end = False

for i in range(M):
    if S[i][1] == N:
        toN.append(S[i][0])

for i in range(M):
    if S[i][0] == 1:
        first.append(S[i][1])

toN = set(toN)
first = set(first)

if toN.intersection(first):
    print "POSSIBLE"

else:
    print "IMPOSSIBLE"

Measured memory_bytes: 50020
#include<iostream>

using namespace std;

int main(void){
	int n;
	int i[1001],p[1001],q[1001],r[1001];
	int lp,lq,lr,lc;
	while(1){
		bool ch=false;
		scanf("%d",&n);
		if(n==0)break;
		for(int a=0;a<n;a++){
			scanf("%d%d%d%d",&i[a],&p[a],&q[a],&r[a]);
		}
		scanf("%d%d%d%d",&lp,&lq,&lr,&lc);
		for(int a=0;a<n;a++){
			if(lp>=p[a] && lq>=q[a] && lr>=r[a] && lc>=p[a]*4+q[a]*9+r[a]*4)ch=true,printf("%d\n",i[a]);
		}
		if(!ch)printf("NA\n");
	}
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int MAX = 100000;

int V, E;
VI G[MAX];
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

struct init{
    init(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
} init;


void input(){
  std::cin >> V >> E;
  REP0( i, E ){
    int s, t;
    std::cin >> s >> t;
    G[s].PB(t);
    G[t].PB(s);
  }
}


void dfs( int current, int prev ) {
  // ノード current を訪問直後
  prenum[current] = lowest[current] = timer;
  timer++;

  visited[current] = true;

  int next;

  REP0( i, G[current].size() ){ // currentに接続する頂点集合G[current]について,
    next = G[current][i]; // i番目を next とおき,
    if ( !visited[next] ) { // nextがdfs未訪問ならば
      parent[next] = current;
      dfs( next, current );
      // next の探索が完了した直後の処理
      lowest[current] = min( lowest[current], lowest[next] );
    } else if ( next != prev ) { // nextがdfsで訪問済みならば,
      //すなわちcurrent->next がback-edgeの場合,
      lowest[current] = min( lowest[current], prenum[next] );
    }
  }

}


void art_points() {
  REP0( i, V ) visited[i] = false;
  timer = 1;
  dfs( 0, -1 ); // 0:root

  set<int> ap;
  int np = 0;
  for (int i = 1; i < V; i++) {
    int p = parent[i];
    if ( p == 0 ) np++; // np:rootの子の数
    else if ( prenum[p] <= lowest[i] ) ap.insert(p);
    // prenum[p] : 頂点 i の親 p のdfs訪問順
    // lowest[i] :  min( i のdfs訪問順, dfs外の枝で接続する頂点の訪問順, dfs木における i の子すべてのlowest )
    // すなわち, dfsでの訪問が, dfs外の枝も含めた訪問順より速いかどうか？
  }
  if ( np > 1 ) ap.insert(0);

  for ( set<int>::iterator it = ap.begin(); it != ap.end(); it++ ) {
    std::cout << *it << '\n';
  }
}


int main(int argc, char const *argv[]) {
  input();
  art_points();
  return 0;
}



Measured memory_bytes: 7032
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


def main():
    a = input()
    if ord(a) >= ord("a") and ord(a) <= ord("z"):
        print("a")
    else:
        print("A")


if __name__ == '__main__':
    main()


Measured memory_bytes: 77352
#include <stdio.h>
#define MAX 300000
int main(void) {
    int n, i, cnt=0, ans=MAX-1;
    char s[MAX];
    scanf("%d %s", &n, s);
    
    for(i=1; i<n; i++) {
        if(s[i]=='E')
            cnt++;
    }
    ans = cnt;
    for(i=1; i<n; i++) {
        if(s[i-1]=='E' && s[i]=='E')
            cnt--;
        else if(s[i-1]=='W' && s[i]=='W') {
            cnt++;
        }
        if(cnt<ans)
            ans = cnt;
    }
    
    printf("%d\n", ans);
    return 0;
}


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

int c[3][3];
int main()
{
	REP(i, 0, 3) REP(j, 0, 3) cin >> c[i][j];

	int mn[3];
	REP(i, 0, 3) {
		mn[i] = min(min(c[i][0], c[i][1]), c[i][2]);
	}
	REP(i, 0, 3) REP(j, 0, 3) c[i][j] -= mn[i];

	bool flag = true;
	REP(j, 0, 3) {
		if (c[0][j] != c[1][j] || c[1][j] != c[2][j]) flag = false;
	}

	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

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

		long a = sc.nextLong();
		long sum = 1;
		if(a > 0 & a <= (10*10*10*10*10)){
		for (long i = 1; i <= a; i++) {
			sum = sum * i;
			sum = sum % (10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7);
		}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 23892