akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let n:u32=read();
    let s:Vec<char>=read::<String>().chars().collect();

    let mut ans:i32 = 0;
    for i in 0..n {
        let mut map1 = HashMap::new();
        let mut map2 = HashMap::new();
        for j in 0..i {
            let cnt = map1.entry(s[j as usize]).or_insert(0);
            *cnt += 1;
        }
        for j in i..n {
            let cnt = map2.entry(s[j as usize]).or_insert(0);
            *cnt += 1;
        }

        let mut cnt:i32 = 0;
        for (k,_v) in &map1 {
            //debug!(i, k, cnt);
            if map2.contains_key(k) { cnt += 1; }
        }
        ans = max(ans, cnt);
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int main()
{
	string X;
	cin >> X;

	int sNum = 0;
	int ans = 0;
	REP(i, X.length())
	{
		if (X[i] == 'T')
		{
			if (sNum == 0)
			{
				ans++;
				continue;
			}
			sNum--;
			continue;
		}
		sNum++;
	}

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

Measured memory_bytes: 640
input()
x = list(map(int, input().split()))

def insertion_sort(a):
    print(*a)
    for i in range(1, len(a)):
        v = a[i]
        j = i - 1
        while j >= 0 and a[j] > v:
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
        print(*a)

insertion_sort(x)


Measured memory_bytes: 5980
import math

def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


N = int(input())
Primes = primes(55556)
Ans = []
num = 0

while len(Ans) < N:
    if Primes[num] % 5 == 1:
        Ans.append(Primes[num])
        print(Primes[num], end=' ')
    num += 1







Measured memory_bytes: 41584
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


h, w = LI()
for _ in range(h):
    s = SI()
    print(s)
    print(s)


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int,int> pii;
typedef std::pair<int,double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;


void solve(){
    int h,w;
    cin >> h >> w;
    vector<string> f(h);
    rep(i,h) cin >> f[i];
    
    queue<pii> q;
    int v[1000][1000] = {};
    for(int i = 0; i < h; i++){
        for(int j  = 0; j < w; j++){
            if (f[i][j] == '#'){
                q.push({i,j});
                v[i][j] = 1;
            }   
        }
    }
    
    int dx[4] = {0,0,-1,1};
    int dy[4] = {1,-1,0,0};
    int cnt = 0;
    while(q.size()){
        int sz = q.size();
        bool need = false;
        for(int i = 0; i < sz; i++){
            auto now = q.front();
            q.pop();
            for(int j = 0; j < 4;j++){
                int nx = now.first + dx[j];
                int ny = now.second + dy[j];
                if (nx >= 0 && ny >= 0 && nx < h && ny < w && v[nx][ny] == 0){
                    q.push({nx,ny});
                    v[nx][ny] = 1;
                    need = true;
                }
            }
        }
        if (need) cnt++;
    }
    cout << cnt;
}





int main(){
    int T;
    T = 1;
    // cin >> T;
    while(T--){
        solve();
        cout << endl;
    }
}





































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

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

#define ALL(a)  (a).begin(),(a).end()
#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((c).begin(),(c).end())

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

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

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

  int N, X; cin >> N >> X;
  LL ans = 0;
  vector<int> xs(N);
  REP(i,N) cin >> xs[i];

  if(xs[0] > X){
	ans = xs[0] - X;
	xs[0] = X;
  }

  for(int i=1;i+1<N;++i){
	if(xs[i] + xs[i-1] > X){
	  ans += xs[i] + xs[i-1] - X;
	  xs[i] = X - xs[i-1];
	}
  }
  ans += max(0, xs.back() + xs[N-2] - X);
  cout << ans << endl;
	
  return 0;
}


Measured memory_bytes: 640
import sys
readline = sys.stdin.readline

def ceil(a, b):
    return -(-a//b)

def main():
    N = int(readline())
    inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    scr_t, scr_a = 1, 1
    for t, a in inp:
        n = max(ceil(scr_t, t), ceil(scr_a, a))
        scr_t = n * t
        scr_a = n * a

    print(scr_t + scr_a)

if __name__ == '__main__':
    main()

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

int main() {
  int n, p;
  cin >> n >> p;

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

  ll dp[51][2];
  dp[0][0] = 1;
  dp[0][1] = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 0) {
      dp[i + 1][0] = 2 * dp[i][0];
      dp[i + 1][1] = 2 * dp[i][1];
    } else {
      dp[i + 1][0] = dp[i][1] + dp[i][0];
      dp[i + 1][1] = dp[i][0] + dp[i][1];
    }
  }

  cout << dp[n][p] << endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
using namespace std;
bool map[101];
int hin[101][2];
int main(){
	int w,q,a,b;
	char z;
	while(true){
	cin>>w>>q;
	if(w==0&&q==0)break;
	for(int i=0;i<w;i++)map[i]=true;
	for(int u=0;u<q;u++){
		cin>>z;
		if(z=='s'){
			cin>>a>>b;
			bool impossible=true;
			int set=10000;
			for(int i=0;i<=w-b;i++){
				bool t=true;
				for(int j=0;j<b;j++)if(!map[i+j])t=false;
				if(t){impossible=false;set=min(set,i);}
			}
			if(impossible)cout<<"impossible"<<endl;
			else{
				cout<<set<<endl;
				hin[a][0]=set,hin[a][1]=set+b;
				for(int i=set;i<set+b;i++)map[i]=false;
			}
		}
		if(z=='w'){
			cin>>a;
			for(int i=hin[a][0];i<hin[a][1];i++)map[i]=true;
		}
	}
	cout<<"END"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n = gets.to_i
baggage = gets.split.map(&:to_i)
sorted = baggage.sort
sorted_index = sorted.map{ |s| baggage.index(s) }
cost = 0
used = [false] * n
n.times do |s|
  next if used[s]
  cur = s
  count = 0
  loop do
    count += 1
    t = baggage.index(sorted[cur])
    used[cur] = true
    cost += baggage[cur]
    cur = sorted_index[cur]
    break if used[cur]
  end
  cost += [sorted[cur] * (count - 2), sorted[cur] + sorted[0] * (count + 1)].min
end
p cost

Measured memory_bytes: 8852
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using V = vector<int>;
using Vll = vector<ll>;
using VV = vector<V>;
using VVll = vector<Vll>;

char s[1000000];

int main() {
  int n, q;
  scanf("%d%s%d", &n, s, &q);

  VVll t(3, Vll(n+1));
  VV pos(3, V());
  string dmc = "DMC";

  rep(i, n) rep(j, 3) {
    t[j][i+1] = t[j][i];
    if (s[i] == dmc[j]) {
      ++t[j][i+1];
      pos[j].push_back(i);
    }
  }

  rep(_, q) {
    int k; 
    scanf("%d", &k);
    ll ans = 0;
    for (auto c : pos[2]) ans += t[1][c] * (t[0][c] - t[0][max(c-k+1, 0)]);
    for (auto a : pos[0]) ans -= t[1][a+1] * (t[2][min(a+k, n)] - t[2][a+1]);
    printf("%lld\n", ans);
  }
  return 0;
}


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

signed main(){
  int n;cin>>n;
  string s;cin>>s;
  int tmp=0;
  for(char p:s)tmp+=p=='R';
  int ans=0;
  for(int i=0;i<tmp;i++)ans+=s[i]=='W';
  cout<<ans<<endl;
}


Measured memory_bytes: 3752
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
	int f = 0,i;
	for(;;){
		char word[100]={0};
		for(i=0;;i++){
			if(scanf("%c",&word[i]) == EOF){f = 1;word[i]=10; break;}
			if(word[i] == 10){break;}
		}
		for(int l=0;l<26;l++){
			for(i=0;i<(int)strlen(word);i++){
				if(word[i] == 't' && word[i+1] == 'h' && word[i+2] == 'i' && word[i+3] == 's' && word[i+4] == ' '){break;}
				else if(word[i] == 't' && word[i+1] == 'h' && word[i+2] == 'a' && word[i+3] == 't' && word[i+4] == ' '){break;}
				else if(word[i] == 't' && word[i+1] == 'h' && word[i+2] == 'e' && word[i+3] == ' '){break;}
				else if(word[i] == 't' && word[i+1] == 'h' && word[i+2] == 'i' && word[i+3] == 's' && word[i+4] == '\n'){break;}
				else if(word[i] == 't' && word[i+1] == 'h' && word[i+2] == 'a' && word[i+3] == 't' && word[i+4] == '\n'){break;}
				else if(word[i] == 't' && word[i+1] == 'h' && word[i+2] == 'e' && word[i+3] == '\n'){break;}
			}
			if(i != (int)strlen(word)){cout<<word;break;}
			for(i=0;i<(int)strlen(word);i++){
				if(word[i]==122){word[i]=97;}
				else if(word[i]>=97 && word[i]<122){word[i]++;}
			}
		}
		if(f == 1){break;}
	}
	return 0;
}

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

int water = 0;
int sugar = 0;

double concentration(int a, int b) {
    if (a + b == 0) return 0;
    return 100 * (double)b / (a + b);
}

int A, B, C, D, E, F;
bool chmax(double &ma, const double nw, int& mawa, int& masu, const int water, const int sugar) {
    if (ma <= nw) {
        ma = nw;
        mawa = water;
        masu = sugar;
        return true;
    }
    return false;
}

map<pair<int,int>, pair<int,int>> MEMO;
pair<int,int> DFS(const int water, const int sugar) {
    if (MEMO.count({water,sugar}) > 0) return MEMO[{water,sugar}];
    if (water * E == (sugar + C) * 100 && water + sugar + C <= F) {
        MEMO[{water,sugar}] = {water, sugar + C};
        return make_pair(water, sugar + C);
    }

    if (water * E == (sugar + D) * 100 && water + sugar + D <= F) {
        MEMO[{water,sugar}] = {water, sugar + D};
        return make_pair(water, sugar + D);
    }

    int left = F - (water + sugar); 
    double ma = (water + sugar == 0) ? 0 : ((double)sugar * 100 / (water + sugar));
    int mawa = water, masu = sugar;
    int newa, nesu;
    pair<int, int> p;

    if (left >= C) {
        if (water * E >= (sugar + C) * 100) {
            nesu = sugar + C;
            p = DFS(water, nesu);
            chmax(ma, concentration(p.first, p.second), mawa, masu, p.first, p.second);
            if (mawa * E == 100 * masu) goto END;
        }
    }
    if (left >= D) {
        if (water * E >= (sugar + D) * 100) {
            nesu = sugar + D;
            p = DFS(water, nesu);
            chmax(ma, concentration(p.first, p.second), mawa, masu, p.first, p.second);
            if (mawa * E == 100 * masu) goto END;
        }
    }
    if (left > A * 100) {
        newa = water + A * 100;
        p = DFS(newa, sugar);
        chmax(ma, concentration(p.first, p.second), mawa, masu, p.first, p.second);
        if (mawa * E == 100 * masu) goto END;
    }
    if (left > B * 100) {
        newa = water + B * 100;
        p = DFS(newa, sugar);
        chmax(ma, concentration(p.first, p.second), mawa, masu, p.first, p.second);
    }
END:
    MEMO[{water,sugar}] = {mawa,masu};
    return {mawa, masu};
}

int main() {
    cin >> A >> B >> C >> D >> E >> F;

    int water = 0;
    int sugar = 0;
    pair<int,int> ans = DFS(water, sugar);
    cout << ans.first + ans.second << " " << ans.second << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = println(run {
    val n = readLine()!!.toInt()
    val statements = (1..n).map {
        val m = readLine()!!.toInt()
        (1..m).map { readLine()!!.split(" ").map { it.toInt() } }
    }

    var max = 0


    for (pattern in 0 until 1.shl(n)) {
        fun isHonest(i: Int) = pattern shr i and 1 == 1
        fun isContradiction(statement: List<Int>) = pattern shr (statement[0] - 1) and 1 != statement[1]
        val num = Integer.bitCount(pattern)
        if (num <= max || (0 until n).any { person -> isHonest(person) && statements[person].any { isContradiction(it) }}) continue
        max = num
    }
    max
})

Measured memory_bytes: 39900
#!/usr/bin/env python

from sys import stdin, stderr

def main():
   N = int(stdin.readline())
   L = [ a*b for a in xrange(1, 10) for b in xrange(1, 10) ]

   print('Yes' if N in L else 'No')

   return 0

if __name__ == '__main__': main()


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

int main(void){
    int n, k;
    cin >> n >> k;

    int ans = 0;

    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        ans += min(2*x, 2*k -2*x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9 + 7;

int main()
{
    fast();
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];

    ll mx1 = arr[0];
    ll mx2 = arr[1];
    if(mx2>mx1)
        swap(mx2,mx1);

    for(ll i=2;i<n;i++)
    {
        if(arr[i]<=mx2)
            continue;

        if(arr[i]>mx1)
        {
            mx2=mx1;
            mx1 = arr[i];
        }
        else
        {
            mx2=arr[i];
        }
    }

    for(ll i=0;i<n;i++)
    {
        if(arr[i]!=mx1)
            cout<<mx1<<endl;
        else
            cout<<mx2<<endl;
    }
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;
    int ans;
    for(int i=min(a,b); i > 0; i--){
        if (a % i == 0 && b % i == 0){
            cnt++;
            if (k == cnt){
                ans = i;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
n=int(input())
ab=[[] for _ in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    ab[a].append([b,i])
que=deque()
que.append(1)
visited=[0]*(n)
ans=[0]*(n-1)
while que:
    x=que.popleft()
    k=1
    for j in ab[x]:
        if visited[x-1]!=k:
            ans[j[1]]+=k
            visited[j[0]-1]+=k
            k+=1
            que.append(j[0])
        else:
            ans[j[1]]+=(k+1)
            visited[j[0]-1]+=(k+1)
            k+=2
            que.append(j[0])
print(max(ans))
for l in ans:
    print(l)

Measured memory_bytes: 34052
#include <bits/stdc++.h>
using namespace std;
#define sync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,n) for(int i=0; i<int(n); ++i)
#define repp(i,a,n) for(int i=a; i<int(n); ++i)
#define sz(x) (x).size()
#define pq priority_queue
#define pb push_back
#define mp make_pair

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T> &input){for (auto const& i: input) {os << i << " ";}return os;}
template<class T1,class T2> std::ostream& operator<<(std::ostream& os, const std::pair<T1,T2> &input){os << "(" << input.first << ", " << input.second << ')';return os;}

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<pi> vp;
typedef vector<ll> vl;
typedef vector<vi> vvi;


const int maxn = 50;

void pre(){
}

void solve(){
	int sum = 15;
	rep(i,5){
		int x;
		cin >> x;
		sum -= x;
	}
	cout << sum <<endl;
}


int main() {
    sync;
    int cas = 1;
    // cin >> cas;
    pre();
    rep(ca, cas) solve();
    return 0;
}

Measured memory_bytes: 3584
A = int(input())
ans = 0
listA = []
for i in range(A):
    listA.append(list(map(int,input().split())))
listA = listA[::-1]
for i in range(A):
    if (listA[i][0]+ans) % listA[i][1] == 0:
        continue
    if listA[i][1] == 1:
        continue
    ans += listA[i][1]-(listA[i][0]+ans)%listA[i][1]
print(ans)

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define OUT(a) cout << (a) << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll k, a, b;
    ll p[200010];
    string s;

    cin >> k >> a >> b;

    for (ll i = a; i <= b; i++){
      if (i%k==0){
        cout << "OK" << endl;
        return 0;
      }
    }
  
  	cout << "NG" << endl;

    return 0;
}

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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
	int h = ri(), w = ri();
	vector<string> a(h);
	FOR(i,h) cin >> a[i];
	
	FOR(i,a.size()) {
		bool r = true;
		FOR(j,a[i].size())
			if (a[i][j] == '#') r = false;
		if (r) a.erase(a.begin() + i), i--;
	}
	FOR(i,w) {
		if (!a.size() || i >= (int)a[0].size()) break;	
		bool r = true;
		FOR(j,a.size()) if (a[j][i] == '#') r = false;
		if (r) {
			FOR(j,a.size()) a[j].erase(a[j].begin() + i);
			i--;
		}
	}
	for (auto &i : a) {
		for (auto &j : i) cout << j;
		cout << endl;
	}
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  int N;
  cin>>N>>S;
  for(int i=0;i<S.length();i++)
    S[i]=(S[i]-'A'+N)%26+'A';
  cout<<S<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int n, y;
	int a, b, c;
	int i, t, k;
	int flag=0;
	a = b = c = 0;
	scanf("%d %d", &n, &y);
	for (i = 0; i <= n; i++)
	{
		for (t = 0; t <= n-i; t++)
		{
			a = i;
			b = t;
			c = n - i - t;
			if (a * 10000 + b * 5000 + c * 1000 == y)
			{
				flag = 1;
				break;
			}
		}
		if (flag == 1)
		{
			break;
		}
	}
	if (flag == 1)
	{
		printf("%d %d %d\n", a, b, c);
	}
	else
	{
		printf("-1 -1 -1\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
	int a, b, k;
	cin >> a >> b >> k;
	vector<int> ans(0);
	for (int i = 1; i <= min(a, b); i++) {
		if (a % i == 0 && b % i == 0) {
			ans.push_back(i);
		}
	}
	cout << ans[ans.size() - k] << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>

int main()
{
	int n;
	char x;
	int r=0,b=0;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		std::cin>>x;
		if (x=='R')
		{
			r++;
			continue;
		}
		b++;
	}
	if (r>b)
	{
		printf("Yes");
		return 0;
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
	int n, m;
	int t[100],h[100];
	while(scanf("%d%d", &n, &m)){
		int rt = 1000, rh = 1000;
		int T = 0, H = 0;
		if(n == 0 && m == 0) break;
		for(int i = 0; i < n; i++){
			scanf("%d", &t[i]);
			T += t[i];
		}
		for(int i = 0; i < m; i++){
			scanf("%d", &h[i]);
			H += h[i];
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				if(T-t[i]+h[j] == H-h[j]+t[i] && rt+rh > t[i]+h[j]){
					rt = t[i];
					rh = h[j];
				}
			}
		}
		if(rt == 1000) printf("-1\n");
		else printf("%d %d\n", rt, rh);
	}
}

Measured memory_bytes: 1040
N = int(input())
res = N
for i in range(N + 1):

	cc = 0
	t = N - i
	while t > 0:
		cc += int(t % 9)
		t = int(t / 9)
	t = i
#
	while t > 0:
		cc += int(t % 6)
		t = int(t / 6)

	if res > cc:
		res = cc
print(res)

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

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var str = Console.ReadLine();
		var s = new int[str.Length];
		for(int i = 0; i < s.Length; i++)
		{
			s[i] = (int)(str[i]-'0');
		}
		var t = new int[4];//ki-0, guu-0, ki-1, guu-1
		
		for(int i = 0; i < s.Length; i++)
		{
			t[i%2*2+s[i]%2]++;
		}
		Console.WriteLine(Math.Min(t[1],t[2])*2+Math.Min(t[0],t[3])*2);
		
	}
	

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



Measured memory_bytes: 13140
n,m=map(int,input().split())
t=[-1]*n
flag=0
for i in range(m):
  a,b=map(int,input().split())
  if t[a-1]==-1:
    t[a-1]=b
  elif t[a-1]!=b:
    flag=1
if flag==1:
  print(-1)
elif t[0]==0 and n==1:
  print(0)
elif t[0]==0:
  print(-1)
else:
  for j in range(len(t)):
    if t[j]==-1:
      if j==0 and n!=1:
        t[j]=1
      elif j==0:
        t[j]=0
      else:
        t[j]=0
  print(''.join(map(str,t)))

Measured memory_bytes: 3064
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long UInt64;
typedef long long Int64;

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

using namespace std;

typedef pair<int ,int > P;

void solve(int n)
{
	int a[10]={};
	rep(i,n)
	{
		int b;
		cin>>b;
		a[b]++;
	}

	rep(i,10)
	{
		if(a[i]==0) cout<<"-"<<endl;
		else
		{
			rep(j,a[i]) cout<<"*";
			cout<<endl;

		}

	}


}

int main()
{
	int n;
	while(cin>>n)
	{
		if(!n) return 0;
		solve(n);

	}
		return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main()
{

    string str;
    int n,a=0,b=0,c=0,d=0;
    cin>>n;
    while(n--)
    {
        cin>>str;
        if(str=="AC")
            a++;
        else if(str=="WA")
            b++;
        else if(str=="TLE")
            c++;
        else if(str=="RE")
            d++;
    }
    cout<<"AC "<<"x "<<a<<endl;
    cout<<"WA "<<"x "<<b<<endl;
    cout<<"TLE "<<"x "<<c<<endl;
    cout<<"RE "<<"x "<<d<<endl;

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  a--,b--,c--,d--;

  rep(i, a, c+1) {
    if (s[i - 1] == '#' && s[i] == '#') {
      cout << "No" << endl;
      return 0;
    }
  }
  rep(i, b, d+1) {
    if (s[i - 1] == '#' && s[i] == '#') {
      cout << "No" << endl;
      return 0;
    }
  }

  if (c < d) {
    cout << "Yes" << endl;
  } else {
    rep(i, b - 1, d) {
      if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
  }
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x,y; cin >> x >> y;
  if(x%y==0) cout << -1 << endl;
  else cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize ("Ofast")
        #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
        #include <iostream>
        #include <iomanip>
        #include <sstream>
        #include <cstring>
        #include <vector>
        #include <deque>
        #include <queue>
        #include <set>
        #include <map>
        #include <valarray>
        #include <iterator>
        #include <functional>
        #include <limits>
        #include <algorithm>
        #include <numeric>
        #include <cmath>
        #include <cassert>
        #include <unordered_map>
        #include <unordered_set>
        #include <stack>
        using namespace std;
        #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
         #define trace(x) cerr << #x << ": " << x << " " << endl;
     
        typedef int64_t ll;
     
        #define endl '\n'
        #define int ll
        ll mod=1e9+7;
        ll mod1=1e9+5;
        ll power(ll a,ll b)
        {
            if(b==0) return 1;
            else if(b%2==0)
                return power((((a%mod)*(a%mod))%mod),b/2)%mod;
            else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
        }
        int a[100001];
        
        int n,m;
        
     int32_t main()
        {
            IOS
      
        
            cin>>n>>m;
            for(int i=1;i<=n;++i)
                cin>>a[i],a[i]%=m;
        
            map<int,int>m1;
            m1[0]+=1;
            int sum=0;
            int ans=0;

            for(int i=1;i<=n;++i)
            {  
                sum+=a[i];
                sum%=m;
                ans+=m1[sum];
                m1[sum]++;
            }
            cout<<ans;


        }

Measured memory_bytes: 4992
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

S = input()

num = len(S) // 2

if num == 0:
    print(0)
else:
    A = S[0 : num]
    B = list(reversed(S[len(S) - num : ]))
    
    ans = 0

    for a, b in zip(A, B):
        if a != b:
            ans += 1
        
    print(ans)


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

typedef long long ll;
#define int ll
#define pb push_back
const int INF = 1e18, MAX = 3003;

int n, arr[MAX];
vector<vector<int>> dp;

int solve(int left, int right){
	if (left==right){
		if (n&1)
			return dp[left][right] = arr[left];
		else
			return dp[left][right] = -arr[left];
	}

	if (dp[left][right] != INF)
		return dp[left][right];

	if (((left+right)&1) != (n&1))
		return dp[left][right] = max(arr[left] + solve(left+1,right), arr[right] + solve(left,right-1));
	else
		return dp[left][right] = min(-arr[left] + solve(left+1,right), -arr[right] + solve(left,right-1));
}
signed main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>arr[i];

	dp.assign(n+1,vector<int> (n+1, INF));
	cout<<solve(1,n)<<"\n";


	

	return 0;
}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  string sn="snuke";
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      string s;
      cin>>s;
      if(s==sn){
        char c;
        cout<<(char)('A'+j)<<1+i;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc  = new Scanner(System.in);
      	int x = sc.nextInt();
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      	int count;
      	x -= a;
      	count = x / b;
      
      	System.out.println(x-(b*count));
    }
}

Measured memory_bytes: 35684
// nb_9960
  #include <bits/stdc++.h> 
  using namespace std; 
  #define fi(i,a,n) for (ll i=a; i < n; i++) 
  #define ll long long
  #define pb push_back 
  #define mp make_pair 
  #define F first 
  #define S second 
  #define all(x) x.begin(), x.end() 
  #define clr(x) memset(x, 0, sizeof(x)) 
  #define sortall(x) sort(all(x)) 
  typedef pair<ll, ll> pl; 
  typedef vector<ll> vl; 
  typedef vector<pl> vpii; 
  #define sz(a) int((a).size())
  #define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
  #define present(c,x) (c.find(x) != c.end())
  #define cpresent(c,x) (find(all(c),x) != c.end())
  #define MOD 1000000007
  #define PI 3.1415926536

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

    ll t = 1; 
    // cin >> t;

    while (t--) { 
      ll n;
      cin>>n;
      ll cnt=0;
      for(ll a=1;a<n;a++){
        for(ll b=1;b<n;b++){
          if(a*b>=n){
            break;
          }
          else cnt++;
        }
      }
      cout<<cnt<<endl;
    }
    return 0; 
  } 


Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main(void){
  int i = 0;
  int stack[100];
  char s[100];
 
  while(scanf("%s", s) != EOF){
    if (s[0] == '+'){
      stack[i-2] = stack[i-2] + stack[i-1];
      i--;
    } 
    else if(s[0] == '-'){
      stack[i-2] = stack[i-2] - stack[i-1];
      i--;
    } 
    else if(s[0] == '*'){
      stack[i-2] = stack[i-2] * stack[i-1];
      i--;
    }
    else{
      stack[i] = atoi(s);
      i++;  
    }
  }
  printf("%d\n",stack[0]);

  return 0;
}

Measured memory_bytes: 548
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iR = int.Parse(sS[0]);
            sS = Console.ReadLine().Trim().Split(' ');
            int iG = int.Parse(sS[0]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = iG * 2 - iR;

            // 出力
            Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


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

using namespace std;

typedef long long LL;
typedef vector<int>    VI;
typedef vector<bool>   VB;
typedef vector<string> VS;

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int n;
VI ss, gs;

const int INF = INT_MAX / 2;

bool check(int s, int g, VI& gts) {
	rep (i, gts.size()) {
		if (s >= gts[i]) {
			gts[i] = INF;
			return true;
		}
	}
	return false;
}

int main(void) {
	while (1) {
		ss.clear();
		gs.clear();
		cin >> n;
		if (n == 0) break;
		VI gts;
		rep (i, n) {
			int h, m, s;
			scanf("%d:%d:%d", &h, &m, &s);
			int stime = h * 60 * 60;
			stime += m * 60;
			stime += s;
			scanf("%d:%d:%d", &h, &m, &s);
			int gtime = h * 60 * 60;
			gtime += m * 60;
			gtime += s;
			ss.PB(stime);
			gs.PB(gtime);
			gts.PB(gtime);
		}
		sort(ALL(gts));
		reverse(ALL(gts));
		int ans = 0;
		rep (i, n) {
			if (!check(ss[i], gs[i], gts)) {
				ans++;
			}
		}
		cout << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 3268
#include<iostream>
#include<cstring>
using namespace std;
int main(){
  int no[50001],a,b,n;
  
  while(1){
    int flg=0;
    memset(no,0,sizeof(no));
    cin >> n;
    if(n==0)  break;
    for(int i=0;i<n;i++){
      cin >> a;
      no[a]=1;
      if(i==0) b=a;
    }
    for(int i=b;i<=50000;i++){
      if(no[i-1]==0&&no[i]==1&&no[i+1]==0&&i==b){
	if(flg==1)cout << " ";
	flg=1;
	cout<<i;
	for(i++;i<=50000;i++){
	  if(no[i+1]==1){
	    b=i+1;
	    break;
	  }
	}
      }else if(no[i]==1 && no[i+1]==0 && i!=b){
	if(flg==1)cout << " ";
	flg=1;
	cout << b << "-" << i;
	for(i++;i<=50000;i++){
	  if(no[i+1]==1){
	    b=i+1;
	    break;
	  }
	}
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1364
fn main() {
    let mut dividingNumbers = (1..27).rev().map(|x:i32| 2_i32.pow(x as u32)).enumerate();
    // println!("{:?}", dividingNumbers);

    let mut inputs: Vec<u32> = read().trim().split_whitespace().map(|x| x.parse::<u32>().unwrap()).collect();
    // println!("{:?}", inputs);

    let mut count = 0;
    for (index, dividingNum) in dividingNumbers {
        // println!("{}", inputs.iter().all(|x| x%(dividingNum as u32)==0));
        if inputs.iter().all(|x| x%(dividingNum as u32)==0) {
            count = count + (26 - index);
            inputs = inputs.iter().map(|x| x/(dividingNum as u32)).collect();
        }
    }

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

fn read() -> String {
    let mut s = String::new();
    // 最初は無視
    std::io::stdin().read_line(&mut String::new());

    std::io::stdin().read_line(&mut s);
    s.to_string()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
const int MN=1e5+5;
char s[MN];
int n,rt;bool a[MN];
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	reg int i;
	for(i=1;i<=n;++i) a[i]=(s[i]=='1');
	if(!a[1]||a[n]) return 0*puts("-1");
	for(i=1;i<=n-1;++i) if(a[i]!=a[n-i]) return 0*puts("-1");
	for(rt=1,i=2;i<=(n+1)/2;++i)if(a[i])
	{
		printf("%d %d\n",i,rt);
		for(int j=rt+1;j<i;++j) printf("%d %d\n",i,j);
		rt=i;
	}
	printf("%d %d\n",rt+1,rt);++rt;
	for(i=rt+1;i<=n;++i) printf("%d %d\n",rt,i);
	return 0;
}

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

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

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

    ll N,K; cin >> N >> K;

    vector<ll> G[100];

    if(K > (N-1)*(N-2)/2){
        cout << -1 << endl;
        return 0;
    }

    ll now = (N-1)*(N-2)/2;
    queue<P> lis;
    for (int i = 1;i < N;i++){
        for (int j = i+1;j < N;j++){
            lis.push(P(i,j));
        }
    }
    for (int i = 1;i < N;i++){
        G[0].push_back(i);
    }
    ll M = N-1;
    while(now != K){
        G[lis.front().first].push_back(lis.front().second);
        lis.pop();
        M++;
        now--;
    }

    cout << M << endl;

    for (int i = 0;i < N;i++){
        for (int j = 0;j < G[i].size();j++){
            cout << i+1 << " " << G[i][j]+1 << endl;
        }
    }

    return 0;

}

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

using namespace std;

namespace {

#define VEVE(i, a, b) for (ll i = a, __##i = b; i < __##i; ++i)
#define DYDY(i, a, b) for (ll i = a, __##i = b; i > __##i; --i)
#define RARA(x, seq) for (auto &x : seq)
#define SIZE(x) ((ll)(x.size()))
#define ALL(x) x.begin(), x.end()

typedef int64_t ll;
typedef double dd;

void Solve(ll) {
  ll n;
  cin >> n;
  vector<ll> arr(n);
  RARA(a, arr) cin >> a;
  VEVE(i, 0, n) arr[i] -= i + 1;
  sort(ALL(arr));
//  DEBUG(arr);
  ll res = 0;
  const ll med = arr[n / 2];
  RARA(a, arr) res += abs(a - med);
  cout << res << endl;
}

void Init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
}

int32_t main() {
#ifdef AZN
  freopen("input.txt", "r", stdin);
#endif
  Init();
  ll tests = 1;
  VEVE(test, 1, tests + 1) Solve(test);
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int w, h, k, x, y, a;
	struct {int x, y;} d[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
	string s;
	while (cin >> w >> h, w && h)
	{
		x = y = 1, a = 0;
		while (cin >> s, s != "STOP")
		{
			if (s == "FORWARD")
			{
				cin >> k;
				for (; k > 0; k--)
					if (0 < x+d[a].x && x+d[a].x <= w && 0 < y+d[a].y && y+d[a].y <= h)
						x += d[a].x, y += d[a].y;
					else
						break;
			}
			else if (s == "BACKWARD")
			{
				cin >> k;
				for (; k > 0; k--)
					if (0 < x-d[a].x && x-d[a].x <= w && 0 < y-d[a].y && y-d[a].y <= h)
						x -= d[a].x, y -= d[a].y;
					else
						break;
			}
			else if (s == "RIGHT")
				if (a+1 < 4)
					a++;
				else
					a = 0;
			else if (s == "LEFT")
				if (0 <= a-1)
					a--;
				else
					a = 3;
		}
		cout << x << " " << y << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    string s, t;
    bool flag = false;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if (s.length() < t.length())
        for (int i = 0; i < t.length() - s.length(); i++)
            s.append("a");
    
    for (int i = 0; i< min(t.size(), s.size()); i++) {
        if (t[i] > s[i]) {
            flag = true;
            break;
        }
    }
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int N,M;
	cin >> N >> M;
	vector<int> P(M),Y(M);
	vector<vector<pii>> v(N, vector<pii>());
	rep(i,M) {
		cin >> P[i] >> Y[i];
		P[i]--;
		v[P[i]].pb(pii(Y[i],i));
	}
	rep(i,N) {
		sort(v[i].begin(), v[i].end());
	}
	vector<pii> t(M);
	rep(i,N) {
		for(int j=0; j<v[i].size(); j++) {
			t[v[i][j].se] = pii(i+1, j+1);
			//cout << setfill('0') << right << setw(6) << P[i]+1 << setfill('0') << right << setw(6) << j+1 << endl;
		}
	}
	rep(i,M) {
			cout << setfill('0') << right << setw(6) << t[i].fi << setfill('0') << right << setw(6) << t[i].se << endl;
	}


  return 0;
}


Measured memory_bytes: 8576
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, W = iim()
    S = [iim() for i in range(N)]

    dp = [-1]*(W+1)
    dp[0] = 0
    for v, w in S:
        for i in range(W-w+1):
            if dp[i] == -1: continue
            j = i + w
            dp[j] = max(dp[j], dp[i] + v)
    print(max(*dp))

if __name__ == "__main__":
    resolve()



Measured memory_bytes: 6076
#include<cstdio>

using namespace std;

int main(void){
	
	int n;
	while(scanf("%d", &n)!= EOF){
		int s,e;
		for(int j = 0; j < n; j++){
			scanf("%d%d", &s, &e);
		
			if(s <= 5 && e <= 5){
				if(s > e){
					for(int i = s; i >= e; i--){
						if(i != s)printf(" ");
						printf("%d",i);
					}
				}else {
					for(int i = s; i <= e; i++){
						if(i != s)printf(" ");
						printf("%d",i);
					}
				}
			}else if(e > 5 && e <10 && s <= 5){
				for(int i = s; i <= e; i++){
					if(i != s)printf(" ");
					printf("%d",i);
				}
			}else if(s > 5 && e<=5){
				for(int i = s; i < 10; i++){
					if(i != s)printf(" ");
					printf("%d",i);
				}
				for(int i = 5; i >= e; i--){
					printf(" %d",i);
				}
			}else if(s < e && s > 5 && e <10){
				for(int i = s; i <= e; i++){
					if(i != s)printf(" ");
					printf("%d",i);
				}
			}else{
				for(int i = s; i <=9; i++){
					if(i != s)printf(" ");
					printf("%d",i);
				}
				for(int i = 5; i > 0; i--){
					printf(" %d",i);
				}
				for(int i = 0; i <= e; i++){
					printf(" %d",i);
				}
			}
			
			puts("");
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main() {
    double a,b,x; cin >> a >> b >> x;
    double th = 2*x/(a*a);
    double ans;
    if(th>b) ans = atan2(2*b-th,a);
    else {
        double tei = 2*x/(a*b);
        ans = atan2(b,tei);
    }
    double pai = 3.14159265;
    cout << setprecision(10) << ans*180.0/pai << endl;
}



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

ll check_prime(ll n) {
  bool check = true;
  for (int i = 2; i < n; i++) {
    if (n % i == 0) check = false;
  }
  return check;
}

int main() { 
    ll X;
    cin >> X;
    for (int i = X;;i++){
        if(check_prime(i)){
            cout << i <<endl;
            break;
        }
    } return 0;
}

Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

int gcd(int x, int y) {
    int temp;
    while (y != 0) {
        temp = y;
        y = x % y;
        x = temp;
    }
    return (x);
}

int main (void) {
  int N; std::cin >> N;
  
  int ans = 0;
  for(int i=0; i<N; i++) {
    int A; std::cin >> A;
    ans = gcd(A, ans);
  }

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

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  for (int gcd = M / N; gcd >= 1; gcd--) {
    if ((M - (gcd * N)) % gcd == 0) {
      cout << gcd << endl;
      return 0;
    }
  }
}


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

int main(){
   int N;
   cin>>N;
   double ans,a;
   a=N/2+1;
  
   if(N%2==0){
      ans=1.0/2.0;
   }
   if(N%2!=0){
      ans=a/N;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vl a(N),b(N);
    int now=0;
    rep(i,N){
        cin >> a[i];
        now+=a[i];
    }
    rep(i,N){
        cin >> b[i];
    }
    now+=b[N-1];
    int ans=now;
    rep(i,N-1){
        now+=(b[N-2-i]-a[N-1-i]);
        chmax(ans,now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604