akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

bool solve() {
  string S;
  cin >> S;

  for (int i = 0; i < 3; i++) {
    if (S[i] == S[i+1]) {
      return true;
    }
  }
  return false;
}

int main()
{
  if (solve()) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::Usize1;
use std::collections::*;
use std::cmp::*;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        N: usize,
        M: usize,
        H: [u64; N],
    }

    let mut edges: Vec<Vec<usize>> = vec![vec![]; N];

    for _ in 0..M {
        input! {
            fr: Usize1,
            to: Usize1,
        }
        edges[fr].push(to);
        edges[to].push(fr);
    }

    let mut ans = 0;
    for i in 0..N {
        if edges[i].iter().all(|&to| H[to] < H[i]) {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 10572
#include <stdio.h>

int gcd(int, int);

int main(){
  int x, y;

  scanf("%d%d",&x,&y);
  printf("%d\n",gcd(x,y));

  return 0;
}

int gcd(int x, int y){ 
  while(x != 0 && y != 0){
    if(x >= y) x = x % y;
    else y = y % x;
  }

  return x == 0 ? y : x;
}



Measured memory_bytes: 2068
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <complex>
#include <cmath>
#include <stdlib.h>
using namespace std;

#define FOR(i,x) for(int i=0;i<x;i++)

const double EPS = 1e-7;
typedef complex<double> P; /* _ */
struct L { P p, q; L(P p, P q) : p(p), q(q) {} }; /* üª */

// complexÉå¬ÖWªKvÈê
namespace std{
	bool operator < (const P &a, const P &b){ return make_pair(real(a),imag(a)) < make_pair(real(b),imag(b)); }
}

// àÏEOÏEpx(xNga,bÌZ)
double dot(P a, P b) { return real(conj(a)*b); }
double cross(P a, P b) { return imag(conj(a)*b); }
double angle(P a, P b) { return arg(conj(a)*b); }

// _p©ç¼ülÉºëµ½üÌ«
P footPerp(L l, P p) {
	return l.p + (l.q-l.p)*( dot(l.q-l.p, p-l.p) / (abs(l.q-l.p)*abs(l.q-l.p)));
}

// ¼ülÉÎ·é_pÌ
P lineShadow(L l, P p) {
	return footPerp(l, p)+footPerp(l, p)-p;
}

int main(){
	string in;
	while(cin>>in){
		//double x1,y1,x2,y2,xq,yq;
		//sscanf(in.c_str(), "%f,%f,%f,%f,%f,%f", &x1,&y1,&x2,&y2,&xq,&yq);
		double x1 = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);
		double y1 = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);
		double x2 = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);
		double y2 = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);
		double xq = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);
		double yq = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);

		L l = L(P(x1,y1), P(x2,y2));
		P q = P(xq, yq);

		P r = lineShadow(l, q);

		printf("%.7f %.7f\n", real(r), imag(r));
	}
	return 0;
}

Measured memory_bytes: 0
//
// Created on 2020/04/14.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    ll ans;
    ll a,b;
    cin>>a>>b;

    if(abs(a-b)%2!=0){
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    ans = ((b*b) - (a*a))/(2*(b-a));


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


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    string s; cin >> s;
    int tot = 0;
    rep(i, s.size()){
        tot += (s[i] - '0');
        tot %= 9;
    }
    puts(tot % 9 == 0 ? "Yes" : "No");
    return;
}

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

Measured memory_bytes: 3748
#include <stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int i, j, k;
  int n1 = mid -left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  i=0, j=0;
  for(k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  int mid;
  if(left+1 < right) {
    mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",cnt);

  return 0;
}



Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>

using namespace std;

const int MAX = 1001;

int sumj[MAX][MAX],sumo[MAX][MAX], sumi[MAX][MAX];
string data[MAX];
int x,y;

void make(){
  for(int i = 1; i <= y; i++){
    for(int j = 1; j <= x; j++){
      sumj[i][j] = sumj[i-1][j]+sumj[i][j-1]-sumj[i-1][j-1];
      sumo[i][j] = sumo[i-1][j]+sumo[i][j-1]-sumo[i-1][j-1];
      sumi[i][j] = sumi[i-1][j]+sumi[i][j-1]-sumi[i-1][j-1];
      if(data[i][j] == 'J') sumj[i][j]++;
      if(data[i][j] == 'O') sumo[i][j]++;
      if(data[i][j] == 'I') sumi[i][j]++;
    }
  }
}

int main(){
  cin >> y >> x;
  string trash;
  int num;
  cin >> num;
  getline(cin,trash);
  for(int i = 1; i <= y; i++){
    string str;
    getline(cin,str);
    data[i] = " ";
    data[i] += str;
  }
  make();
  for(int i = 0; i < num; i++){
    int po[4];
    cin >> po[0] >> po[1] >> po[2] >> po[3];
    cout << sumj[po[2]][po[3]]-sumj[po[2]][po[1]-1]-sumj[po[0]-1][po[3]]+sumj[po[0]-1][po[1]-1] << " ";
    cout << sumo[po[2]][po[3]]-sumo[po[2]][po[1]-1]-sumo[po[0]-1][po[3]]+sumo[po[0]-1][po[1]-1] << " ";
    cout << sumi[po[2]][po[3]]-sumi[po[2]][po[1]-1]-sumi[po[0]-1][po[3]]+sumi[po[0]-1][po[1]-1] <<endl;
  }
  return 0;
}

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

int N;
int s[10][10];


int make(int n) {
	int c = 0;
	for (int i = 0; i < (n - 1) * 2 + 1; i++) {
		for (int j = 0; j < n; j++) {
			int p = i - j;
			if (p < n && p >= 0) {
				if (i % 2 == 0) {
					s[p][j] = ++c;
				}
				else {
					s[j][p] = ++c;
				}
			}
		}
	}
	return 0;
}

int main(){

	int c = 0;
	while (cin >> N && N != 0) {
		cout << "Case " << ++c << ":" << endl;
		make(N);
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (s[i][j] >= 100) {
					cout << s[i][j];
				}
				else if (s[i][j] >= 10) {
					cout << " " << s[i][j];
				}
				else {
					cout << "  " << s[i][j];
				}
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2956
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll dp[n+1];
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);

    for(ll i=2;i<n;i++)
    {
        ll m=INT_MAX;
        for(ll j=1;j<=k && i-j>=0;j++)
        {
            ll temp=min(dp[i-j]+abs(a[i-j]-a[i]),m);
            if(temp<m)
            {
                m=temp;
            }
        }
        dp[i]=m;
    }
    /*for(ll i=0;i<n;i++)
    {
        cout<<dp[i]<<" ";
    }
    cout<<endl;*/
    cout<<dp[n-1];
}


Measured memory_bytes: 1792
k, n = map(int, input().split())
a = list(map(int, input().split()))
da = [0]*n
for i in range(0, n-1):
    da[i] = a[i + 1] - a[i]

da[n-1] = k - (a[n-1] - a[0])

da.sort()

print(sum(da[:n-1]))


Measured memory_bytes: 26564
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
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 / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
//template< typename T >
//T mod_pow(T x, T n, const T &p) {
//  T ret = 1;
//  while(n > 0) {
//    if(n & 1) (ret *= x) %= p;
//    (x *= x) %= p;
//    n >>= 1;
//  }
//  return ret;
//}
/////////////////// 
//

#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
#define mp make_pair
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
//
//
//

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n, i, sum[50];
 
  cin >> n;
  ll kou[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  pri(kou[n-1]);
  return 0;
}







Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

int main(){
    int N;
    cin >> N;
    
    cout << 0 << endl;
    string prev_ans;
    cin >> prev_ans;
    if(prev_ans == "Vacant"){
        return 0;
    }
    int left = 0;
    int right = N;
    for(int i = 0; i < 19; i++){
        int mid = (left + right) / 2;
        cout << mid << endl;
        string ans;
        cin >> ans;
        if(ans == "Vacant"){
            return 0;
        }
        if(prev_ans == ans){
            if((mid - left + 1) % 2 == 0){
                right = mid;
            } else {
                left = mid;
                prev_ans = ans;
            }
        } else {
            if((mid - left + 1) % 2 == 1){
                right = mid;
            } else {
                left = mid;
                prev_ans = ans;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 852
cnt_dict = {}

N = int(input())
for _ in range(N):
    s = input()
    if cnt_dict.get(s) is not None:
        cnt_dict[s] += 1
    else:
        cnt_dict[s] = 1

M = int(input())
for _ in range(M):
    t = input()
    if cnt_dict.get(t) is not None:
        cnt_dict[t] -= 1


ans =  max(cnt_dict.items(), key=lambda x:x[1])[1]
if ans > 0:
    print(ans)
else:
    print(0)

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int ans = 0,x;

int main(){
  REP(i,3){
    ans *= 10;
    scanf("%d",&x);
    ans += x;
  }
  if(ans%4==0){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
H = LIST()
AB = [LIST() for _ in range(M)]

ma = [0]*N

for A, B in AB:
	ma[A-1] = max(ma[A-1], H[B-1])
	ma[B-1] = max(ma[B-1], H[A-1])

ans = 0
for i in range(N):
	if H[i] > ma[i]:
		ans += 1

print(ans)


Measured memory_bytes: 33024
N=int(input())
A=[0]+list(map(int,input().split()))+[0]
cost=sum(abs(A[i+1]-A[i]) for i in range(N+1))
for i in range(1,N+1):
    print(cost-abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1]))

Measured memory_bytes: 65516
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    a, b, c = map(int, sys.stdin.readline().split())
    a, b = b, a
    a, c = c, a
    print(a, b, c)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


Measured memory_bytes: 38256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//おまじない



int main() {
	//(int)'a'は97 (int)'A'は65
	char a[11], b[11], c[11];
	cin >> a >> b >> c;

	int a1, b1, c1;
	a1 = (int)a[0]-32;
	b1 = (int)b[0]-32;
	c1 = (int)c[0]-32;

	cout << (char)a1 << (char)b1 << (char)c1 << endl;

	return 0;
}


Measured memory_bytes: 256
#abc110 C 最大公約数
N, X = map(int, input().split())
x= list(map(int, input().split()))
distance = [ abs(x[i]-X) for i in range(N)]

def gcd( x , y ):
    while y != 0:
        x,y = y, x%y
    return x

def GCD(lis):
    g = lis[0]
    for i in range(1,len(lis)):
        g = gcd( g , lis[i] )
    return g

maxD = GCD(distance)
print(maxD)    

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a[100000]={};
  int l,r,n,count=0;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>l>>r;
    for(int j=l-1;j<r;j++){
      a[j]++;
    }
  }
  for(int i=0;i<100000;++i){
    if(a[i]!=0){
      count++;
    }
  }
  cout<<count;
  return 0;
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	r := sc.nextInt()
	fmt.Println(r * r)
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
typedef tuple<string, int, int> T;

bool pairCompare(const T& firstElof, const T& secondElof)
{
    if(get<0>(firstElof) != get<0>(secondElof)) return get<0>(firstElof) < get<0>(secondElof);
    if(get<1>(firstElof) != get<1>(secondElof)) return get<1>(firstElof) > get<1>(secondElof);
    return get<2>(firstElof) > get<2>(secondElof);
}

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

    vector<T> v;
    for(int i = 0; i < N; i++) {
        string s;
        int p;
        cin >> s >> p;
        T pr = make_tuple(s, p, i + 1);
        v.push_back(pr);
    }

    sort(v.begin(), v.end(), pairCompare);

    for(int i = 0; i < N; i++) {
        cout << get<2>(v[i]) << endl;
    }

}

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

int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) {
        cin >> A[i];
    }

    deque<int> deq;

    // 全体が偶数
    if (N % 2 == 0) {
        for (int i = 0; i < N; i++) {
            if ((i + 1) % 2 == 0) {
                deq.push_front(A[i]);
            } else {
                deq.push_back(A[i]);
            }
        }
    }
    // 全体が奇数
    else {
        for (int i = 0; i < N; i++) {
            if ((i + 1) % 2 == 0) {
                deq.push_back(A[i]);
            } else {
                deq.push_front(A[i]);
            }
        }
    }

    rep(i, N) {
        cout << deq[i];
        if (i != N - 1) cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 4812
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define rep(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define irep(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define rrep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

const int MOD = 1e9 + 7;

int main() {
    long long a, b, c;
    cin >> a >> b >> c;
    if (a == b&&b == c)
        cout << (a%2==0?-1:0) << endl;
    else {
        int cnt = 0;
        while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
            long long ta = (b + c) / 2;
            long long tb = (a + c) / 2;
            long long tc = (a + b) / 2;
            a = ta, b = tb, c = tc;
            cnt++;
        }
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, a[100000], b[100000], d[100000];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int i = 0; i < n; i++)
		scanf("%d", b + i);
	for (int i = 0; i < n; i++)
		d[i] = a[i] - b[i];
	sort(d, d + n);

	ll total = 0;
	for (int i = 0; i < n; i++)
		total += d[i];
	if (total < 0) {
		printf("-1\n");
		return 0;
	}
	ll minus = 0, ch = 0;
	for (int i = 0; i < n && d[i] < 0; i++)
		minus += d[i], ch++;
	for (int i = n - 1; 0 <= i && minus < 0; i--)
		minus += d[i], ch++;
	printf("%lld\n", ch);
}

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

int N, L[26];

int main(){
	cin >> N;
	memset(L, 10000, sizeof(L));
	for(int i = 0; i < N; i++){
		string st;
		cin >> st;
		int let[26];
		memset(let, 0, sizeof(let));
		for(int j = 0; j < st.length(); j++) let[st[j] - 'a']++;
		for(int j = 0; j < 26; j++) L[j] = min(L[j], let[j]);
	}
	for(int i = 0; i < 26; i++)
		for(int j = 0; j < L[i]; j++) printf("%c", (char)('a' + i));
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    std::cout<<std::fixed<<std::setprecision(10);
    
    int A, B; cin >> A >> B;
    if (A!=1 && B!=1) {
        cout << 1 << endl;
    } else if (A!=2 && B!=2) {
        cout << 2 << endl;
    } else {
        cout << 3 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int n;
	int tp = 0, hp = 0;
	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		string t, h;
		cin >> t >> h;

		for (int j = 0;; j++)
		{
			if (j == t.size() && j == h.size())
			{
				tp++;
				hp++;
				break;
			}
			else
			{
				if (j == t.size())
				{
					hp += 3;
					break;
				}
				else if (j == h.size())
				{
					tp += 3;
					break;
				}
			}
			if (t[j] == h[j])
			{
				continue;
			}
			if (t[j] > h[j])
			{
				tp += 3;
				break;
			}
			else
			{
				hp += 3;
				break;
			}
		}
	}

	cout << tp << " " << hp << endl;
	return 0;
}

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

"""
input:
5 4
0 1
1 2
2 3
3 4

output:
0 1
1 2
2 3
3 4
"""

import sys
from operator import itemgetter

sys.setrecursionlimit(int(3e6))


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        v_from, v_to = map(int, v_detail)
        init_adj_table[v_from].append(v_to)
        # undirected graph
        init_adj_table[v_to].append(v_from)
    return init_adj_table


def graph_dfs(u, visited, parent, low, disc):
    global Time
    # Count of children in current node
    children = 0

    # Mark the current node as visited and print it
    visited[u] = True

    # Initialize discovery time and low value
    disc[u] = Time
    low[u] = Time
    Time += 1

    # Recur for all the vertices adjacent to this vertex
    for v in adj_table[u]:
        # If v is not visited yet, then make it a child of u
        # in DFS tree and recur for it
        if not visited[v]:
            parent[v] = u
            children += 1
            graph_dfs(v, visited, parent, low, disc)

            # Check if the subtree rooted with v has a connection to
            # one of the ancestors of u
            low[u] = min(low[u], low[v])

            ''' If the lowest vertex reachable from subtree
            under v is below u in DFS tree, then u-v is
            a bridge'''
            if low[v] > disc[u]:
                ans.append(sorted([u, v]))
        elif v != parent[u]:  # Update low value of u for parent function calls.
            low[u] = min(low[u], disc[v])

    return None


def bridge():
    visited = [False] * vertices
    disc = [float("Inf")] * vertices
    low = [float("Inf")] * vertices
    parent = [-1] * vertices

    for v in range(vertices):
        if not visited[v]:
            graph_dfs(v, visited, parent, low, disc)

    return ans


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])
    Time = 0
    ans = []

    init_adj_table = tuple([] for _ in range(vertices))
    adj_table = generate_adj_table(v_info)
    res = bridge()
    res.sort()
    for ele in res:
        print(*ele)

Measured memory_bytes: 23916
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
while(1){
  int n;
  cin>>n;
  if(n==0)return 0;
  V<char> d(n);
  for(int i=0;i<n;i++)cin>>d[i];
  V<int> cnt(26,0);
  bool decide=false;
  for(int i=0;i<n;i++){
    cnt[d[i]-'A']++;
    int ma1=0,ind;
    for(int j=0;j<26;j++){
      if(chmax(ma1,cnt[j]))ind=j;
    }
    int ma2=0;
    for(int j=0;j<26;j++){
      if(ind==j)continue;
      chmax(ma2,cnt[j]);
    }
    if(ma1-ma2>n-i-1){
      cout<<char('A'+ind)<<" "<<i+1<<"\n";
      decide=true;
      break;
    }
  }
  if(!decide)cout<<"TIE"<<"\n";
}
}


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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  cout << ( e-a > k ? ":(" : "Yay!" ) << endl; 
}

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

typedef long double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vl;
typedef vector<double> vd;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

#define pi 3.14159265358979
#define eps 1e-9
#define inf 1<<30

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

	return 0;
}


Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

h = math.pi*2/(12*60)
m = math.pi*2/60

angle_M = M * m
angle_H = (H * 60 + M) * h

angle = math.fabs(angle_M - angle_H)

length = math.sqrt(A * A + B * B - 2 * A * B * math.cos(angle))

print(length)

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

using namespace std;

typedef long long ll;

#define MOD 1000000007

int c[10][10];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    c[s[0] - '0'][s[s.size() - 1] - '0']++;
  }
  ll ans = 0;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      ans += (c[i][j] * c[j][i]);
    }
  }
  cout << ans << endl;
  return 0;
}

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


int main(){
    int s,ans,i,j;
    cin >> s;
    int f[1000001];
    f[0]=s;
    ans=0; i=0;
    while(ans==0){
        i++;
        if(f[i-1]%2==0)
            f[i]=f[i-1]/2;
        else
            f[i]=f[i-1]*3+1;
        
        for(j=0;j<i;j++){
            if(f[i]==f[j])
                ans=i+1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
ll X, Y;

int main(){
    ios_base::sync_with_stdio(false);
    cin >> X >> Y;
    cout << fixed;
    if(0 < X && X < Y){
        cout << Y-X;
    }
    else if(X == 0 && Y > 0){
        cout << Y;
    }
    else if(X == 0 && Y < 0){
        cout << -Y+1;
    }
    else if(Y == 0 && X > 0){
        cout << X+1;
    }
    else if(Y == 0 && X < 0){
        cout << -X;
    }
    else if(0 < Y && Y < X){
        cout << X-Y+2;
    }
    else if(Y < 0 && 0 < X && -Y <= X){
        cout << Y+X+1;
    }
    else if(Y < 0 && 0 < X && X < -Y){
        cout << -Y-X+1;
    }
    else if(X < 0 && 0 < Y && -X <= Y){
        cout << Y+X+1;
    }
    else if(X < 0 && 0 < Y && Y < -X){
        cout << -X-Y+1;
    }
    else if(X < Y && Y < 0){
        cout << Y-X;
    }
    else if(Y < X && X < 0){
        cout << X-Y+2;
    }
    else{
        cout << "invalid";
    }
    cout << endl;
    return 0;
}


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

int main() {  
  int64_t H, W;
  
  cin >> H >> W;
  
  int64_t total;
  
  if (W == 1 || H == 1) {
    total = 1;
  }

  else {
    total = (H * W + 1) / 2;
  } 
  cout << total << endl;
}



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

#define MAX_V 2010

struct UnionFind{
    int n;
    vector<int> par;

    UnionFind(int n = 0){
        init(n);
    }

    void init(int n = 0){
        par.resize(n);
        for(int i = 0 ; i < n ; ++i){
            par[i] = i;
        }
        return;
    }

    int root(int x){
        if(x == par[x]){
            return x;
        }
        return par[x] = root(par[x]);
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        par[x] = y;
        return;
    }
};

int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v){
    G[u].push_back(v);
    G[v].push_back(u);
}

bool dfs(int v){
    used[v] = true;
    for(int i = 0 ; i < G[v].size() ; ++i){
        int u = G[v][i], w = match[u];
        if(w < 0 || !used[w] && dfs(w)){
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching(){
    int res = 0;
    memset(match, -1, sizeof(match));
    for(int v = 0 ; v < V ; ++v){
        if(match[v] < 0){
            memset(used, 0, sizeof(used));
            if(dfs(v)){
                ++res;
            }
        }
    }
    return res;
}

int main(){
    int n, m;
    cin >> n >> m;
    V = n * 2;
    vector<int> x(m), y(m);
    for(int i = 0 ; i < m ; ++i){
        cin >> x[i] >> y[i];
        --x[i];
        --y[i];
        add_edge(x[i], y[i] + n);
    }
    // for(int i = 0 ; i < n ; ++i){
    //     add_edge(n * 2, i);
    // }
    // for(int i = n ; i < n * 2 ; ++i){
    //     add_edge(i, n * 2 + 1);
    // }

    UnionFind uf(m);
    for(int i = 0 ; i < m ; ++i){
        for(int j = 0 ; j < i ; ++j){
            if(x[i] == x[j] || y[i] == y[j]){
                uf.unite(i, j);
            }
        }
    }

    map<int, int> mp;
    for(int i = 0 ; i < m ; ++i){
        ++mp[uf.root(i)];
    }

    int maxi = 0;
    for(auto x : mp){
        maxi += x.second - 1;
    }

    int mini = m - bipartite_matching();

    cout << mini << " " << maxi << endl;

    // for(int i = 0 ; i < n * 2 ; ++i){
    //     cout << i << " " << match[i] << endl;
    // }

    return 0;
}


Measured memory_bytes: 3256
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    string S, Sa, Sb;
    string s, sa, sb;

    cin >> S;

    size_t size = S.length();

    Sa = S.substr(0, (size-1)/2);
    Sb = S.substr(((size+3)/2)-1);

    s = S;
    sa = Sa;
    sb = Sb;

    reverse(s.begin(), s.end());
    reverse(sa.begin(), sa.end());
    reverse(sb.begin(), sb.end());

    if(S==s && Sa==sa && Sb==sb) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    
    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

int main() {
	long int n,d;
	cin >> n;
	cin >> d;
	vector<int> x(n);
	vector<int> y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		cin >> y[i];
	}
	int count=0;
	for (int i = 0; i < n; i++) {
		double tmp = sqrt(pow(x[i], 2.0) + pow(y[i], 2.0));
		if ( tmp <= d)
			count++;
	}
	cout << count;
}

Measured memory_bytes: 4900
// abc147_b
#include <iostream>
#include <math.h>
#include <cstring>
#include <iomanip>
#include <algorithm>

#define US unsigned short
#define UI unsigned int
#define UC unsigned char
#define UL unsigned long
#define ULL unsigned long long
using namespace std;

int main(int argc, char const *argv[])
{
    string s;
    US o = 0;
    cin >> s;
    for (size_t i = 0; i < s.length() / 2; i++)
        if (s[i] != s[s.length() - i - 1])
            o++;
    cout << o << endl;
}


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

int main() {
  int x,y,z,k;
  cin>>x>>y>>z>>k;
  vector<long> a(x),b(y),c(z),d,e;
  for (size_t i = 0; i < x; i++) {
    cin>>a[i];
  }
  for (size_t i = 0; i < y; i++) {
    cin>>b[i];
  }
  for (size_t i = 0; i < z; i++) {
    cin>>c[i];
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  
  for (size_t i = 0; i < min(x,k); i++) {
    for (size_t j = 0; j < min(y,k); j++) {
      d.push_back(a[x-1-i]+b[y-1-j]);
    }
  }
  sort(d.begin(),d.end());
  
  for (size_t i = 0; i < min(k,x*y); i++) {
    for (size_t j = 0; j < min(z,k); j++) {
      e.push_back(d[min(x,k)*min(y,k)-1-i]+c[z-1-j]);
    }
  }
  sort(e.begin(),e.end());
  int t = min(k,x*y)*min(z,k)-1;
  for (size_t i = 0; i < k; i++) {
    cout<<e[t-i]<<endl;
  }
}

Measured memory_bytes: 43112
#include <iostream>

using namespace std;

int main() {
  while (true) {
    int a;
    cin >> a;
    if (a == 0) {
      break;
    }

    for (int i = 0; i < 9; i++) {
      int b;
      cin >> b;
      a -= b;
    }
    cout << a << endl;
  }
  return 0;
}


Measured memory_bytes: 3004
def main():
    n = int(input())
    B = list(map(int, input().split()))
    ans = B[0]
    for b1, b2 in zip(B, B[1:]):
        ans += min(b1, b2)
    ans += B[-1]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
using System;

namespace AOJ.Volume1
{
    public class DeliveryFee
    {
        public static int Main()
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }

                ulong fee = 0;
                for (int i = 0; i < n; i++)
                {
                    var input = Console.ReadLine().Split(' ');
                    int length = int.Parse(input[0]) + int.Parse(input[1]) + int.Parse(input[2]);
                    int weight = int.Parse(input[3]);

                    // サイズ判定
                    // 下記に当てはまらない場合は0
                    if (length <= 60 && weight <= 2) { fee += 600; }
                    else if (length <= 80 && weight <= 5) { fee += 800; }
                    else if (length <= 100 && weight <= 10) { fee += 1000; }
                    else if (length <= 120 && weight <= 15) { fee += 1200; }
                    else if (length <= 140 && weight <= 20) { fee += 1400; }
                    else if (length <= 160 && weight <= 25) { fee += 1600; }
                }
                Console.WriteLine(fee);
            }
            return 0;
        }
    }
}

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

int main(){
  string s;
  cin >> s;
  if(s == "SUN"){
    cout << "7" << endl;
  }
  if(s == "MON"){
    cout << "6" << endl;
  }
  if(s == "TUE"){
    cout << "5" << endl;
  }
  if(s == "WED"){
    cout << "4" << endl;
  }
  if(s == "THU"){
    cout << "3" << endl;
  }
  if(s == "FRI"){
    cout << "2" << endl;
  }
  if(s == "SAT"){
    cout << "1" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

#define PUT 0
#define REMOVE 1
#define CHECK_PLANE 2

int cnt;
int m[10][10];
int ans[10][10];

bool is_origin[10][10];
bool make_rect(int now,int x,int y,int width,int height,int flag,
	       int r,int c){
  rep(i,height){
    rep(j,width){
      if ( flag == PUT )m[y+i][j+x]=now;
      else if ( flag == REMOVE && is_origin[y+i][x+j] == false){
	m[y+i][j+x]=0;
      }else if (flag == CHECK_PLANE){
	if ( m[y+i][j+x]!=0 && m[y+i][j+x]!=now)return false;
      }
    }
  }
  return true;
}

void solve(int num,int now,int *number,int *x,int *y,int *size,int r,int c){
  if ( now == num){
    cnt++;
    rep(i,r)rep(j,c)ans[i][j]=m[i][j];
    return;
  }

  if ( cnt > 1)return;
  
  int cur=number[now];
  REP(k,1,size[now]+1 && cnt <1){
    if ( size[now]%k != 0)continue;
    int h=k,w=size[now]/k;
    int hstart=max(0,y[now]-h+1),wstart=max(0,x[now]-w+1);
    REP(i,hstart,y[now]+1 && i+h <=r && cnt < 1){
      REP(j,wstart,x[now]+1 && j+w <=c && cnt < 1){
	if ( make_rect(cur,j,i,w,h,CHECK_PLANE,r,c) ){
	  make_rect(cur,j,i,w,h,PUT,r,c);
	  solve(num,now+1,number,x,y,size,r,c);
	  make_rect(cur,j,i,w,h,REMOVE,r,c);
	}
      }
    }
  }
}


main(){
  int c,r,n;
  while(cin>>c>>r>>n && c){
    pair<int,int> in[n];
    int x[n],y[n],size[n],tmp[100+1],num[100+1];
    rep(i,n)cin>>in[i].second>>in[i].first;
    sort(in,in+n,greater<pair<int,int> >());
    rep(i,n)tmp[in[i].second]=i,size[i]=in[i].first,num[i]=in[i].second;
    rep(i,r){
      rep(j,c){
	cin>>m[i][j];
	if ( m[i][j] != 0){
	  x[tmp[m[i][j]]]=j;
	  y[tmp[m[i][j]]]=i;
	  is_origin[i][j]=true;
	}
	is_origin[i][j]=false;
      }
    }
    cnt = 0;

    solve(n,0,num,x,y,size,r,c);
    if ( cnt == 1){
      rep(i,r){
	rep(j,c){
	  if ( j)cout << ' ';
	  cout <<ans[i][j];
	}
	cout << endl;
      }
    }else cout << "NA"<<endl;
  }
}

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

using namespace __gnu_pbds; 
using namespace std;

using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
#define endl        	"\n"
#define int         	long long int  
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define pll         	pair<ll,ll>
#define vec     		vector<ll>
#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod     		1000000007

ll mod_pow(ll a,ll b)
{
    ll res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    
    return res;
}

void solve()
{
	ll k,i,n,m=0,c=0,ans=0;
	cin>>k>>n;
	ll a[n],dif[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	for(ll i=0;i<n-1;i++)
	    dif[i]=a[i+1]-a[i];
	dif[n-1]=k-a[n-1]+a[0];
    sort(dif,dif+n);
    for(ll i=0;i<n-1;i++)
        ans+=dif[i];
    cout<<ans;
	return;
}
signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        s: chars,
    }

    for i in 0..s.len() {
        if s[i] == 'U' || s[i] == 'D' {
            continue;
        }
        if i & 1 == 0 && s[i] == 'R' {
            continue;
        } else if i & 1 > 0 && s[i] == 'L' {
            continue;
        }
        println!("No");
        return;
    }
    println!("Yes");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int left = a + b, right = c + d;
  if (left > right) {
    cout << "Left" << endl;
  } else if (left < right) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
from collections import Counter

def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    if x!=1:
      retlist.append(x)
    return retlist

N=int(input())

if N==1:
  print(0)
  exit()

cnt=Counter()
for i in range(N):
  a=get_factors(i+1)
  acounter=Counter(a)
  cnt=cnt+acounter
values,counts=zip(*cnt.most_common())
ans=0
five=0
three=0
sevfou=0
twofou=0
fourteen=0
for c in counts:
  if c>=74:
    sevfou+=1
  if c>=24:
    twofou+=1
  if c>=14:
    fourteen+=1
  if c>=4:
    five+=1
  if c>=2:
    three+=1
ans+=(five*(five-1)/2)*(three-2)
ans+=(fourteen*(five-1))
ans+=(twofou*(three-1))
ans+=(sevfou)
print(int(ans))

Measured memory_bytes: 3436
import sys
sys.setrecursionlimit(2000000)
s=input()
d='dream'
dr='dreamer'
e='erase'
er='eraser'
l=len(s)
def solve(s,end):
    if end==-1:
        print('YES')
        exit(0)
    if s[end-6:end+1]==dr:
        end-=7
    elif s[end-5:end+1]==er:
        end-=6
    elif s[end-4:end+1]==e or s[end-4:end+1]==d:
        end-=5
    else:
        print('NO')
        exit(0)
    solve(s,end)
solve(s,l-1)

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

int main() {
	int n;
	cin >> n;
	int d[n];
	for (int i = 0; i < n; i++) cin >> d[i];
	set<int> s;
	for (int i = 0; i < n; i++) {
		s.insert(d[i]);
	}
	cout << s.size() << endl;
}

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

int n;
int x[101][101];
int color[101], a[101], b[101];
int t;

void  DFS_VISIT(int u) {
	color[u] = 1;
	a[u] = ++t;
	for (int v = 0;v < n;v++) {
		if (x[u][v] == 0) {
			continue;
		}
		if (color[v] == 0) {
			DFS_VISIT(v);
		}
	}
		color[u] = 2;
		b[u] = ++t;

}

void DFS() {
	for (int u = 0;u < n;u++) {
		color[u] = 0;
	}
	t = 0;
	for (int u = 0;u < n;u++) {
		if (color[u] == 0) {
			DFS_VISIT(u);
		}
	}
	for (int u = 0;u < n;u++) {
		cout << u + 1<<" " << a[u]<<" " << b[u] << endl;;
	}
}

int main() {
	cin >> n;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) {
			x[i][j] = 0;
		}
	}
	int u, k, v;
	for (int i = 0;i < n;i++) {
		cin >> u >> k;
		u = u - 1;
		for (int j = 0;j < k;j++) {
			cin >> v;
			v = v - 1;
			x[u][v] = 1;
		}
	}

	DFS();

	return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int ret[310000];
long long cnt(int a,int k){
	long long ret=0;
	long long ks=1;
	for(int i=0;i<=a;i++){
		ret+=ks;
		ks*=k;
		if(ret>10000000)return ret;
	}
//	printf("%d: %lld\n",a,ret);
	return ret;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	if(a%2==0){
		printf("%d",a/2);
		for(int i=1;i<b;i++){
			printf(" %d",a);
		}
		printf("\n");
		return 0;
	}else if(a==1){
		for(int i=0;i<(b+1)/2;i++){
			if(i)printf(" ");
			printf("1");
		}
		printf("\n");
		return 0;
	}
	int pos=-1;
	for(int i=0;i<b;i++){
		long long key=cnt(b-i,a);
		if(key<1000000){
			int at=i;
			while(1){
				long long lim=cnt(b-at,a);
				long long pp=lim-1-pos;
		//		printf("%lld %lld\n",lim,pp);
				if(pp<2){
					for(int j=0;j<at;j++){
						if(j)printf(" ");
						printf("%d",ret[j]);
					}
					printf("\n");return 0;
				}
				pp-=2;
				ret[at]=pp/(cnt(b-at-1,a)*2)+1;
				pos++;
				pos-=((a+1)/2-ret[at])*cnt(b-at-1,a)*2;
				at++;
			}
			break;
		}else{
			pos++;
			ret[i]=(a+1)/2;
		}
	}
	for(int i=0;i<b;i++){
		if(i)printf(" ");
		printf("%d",ret[i]);
	}
	printf("\n");
}

Measured memory_bytes: 3328