akhauriyash/Code-Regression huggingface dataset:
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
-10 5 -4"""
        output = """19"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5
10 -4 -8 -11 3"""
        output = """30"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """11
-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000"""
        output = """10000000000"""
        self.assertIO(input, output)
def resolve():
    N=int(input())
    A=[int(i) for i in input().split()]
    d2=sum([1 if i<0 else 0 for i in A])%2
    B=[abs(i) for i in A]
    bs=sum(B)
    if d2==0:
        print(bs)
    else:
        print(bs-2*min(B))

if __name__ == "__main__":
    resolve()

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

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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

ll pow2[42];
ll n = 0;
ll func(ll x)
{
  ll ret = 0;
  REP(i, n) {
    if (i == 0) {
      if (x % 4 == 1 || x % 4 == 2) ret += 1;
      continue;
    }
    ll nx = x % pow2[i + 1] - pow2[i] + 1;
    if (nx > 0) ret += (nx % 2) * pow2[i];
  }
  return ret;
}

int main()
{
  pow2[0] = 1;
  REP(i, 41) pow2[i + 1] = pow2[i] * 2;

  ll A, B;
  cin >> A >> B;

  ll tmp = B;
  while (tmp) n++, tmp /= 2;

  ll ans = func(A - 1) ^ func(B);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
<?php

$n = trim(fgets(STDIN));
$h = explode(' ', trim(fgets(STDIN)));
$h = array_reverse($h);

$c = 0;
for($i=0; $i<$n-1; $i++){
  if ($h[$i] < $h[$i+1]) $h[$i+1]--;
  if ($h[$i] >= $h[$i+1]) $c++;  
}

echo $c == $n-1? 'Yes' : 'No';

?>

Measured memory_bytes: 16884
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
using namespace std;
  
#define int long long int 
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
typedef vector<vi> vvi;
const int mod = 1e9 + 7; 

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define debug(...) cerr << "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define TC int t; cin >> t; while (t--) 

void Panda() {
    int n, x, t;
    cin >> n >> x >> t;
    cout << (n % x == 0 ? n / x * t : (n / x + 1) * t) << endl;
}
  
int32_t main() {
 
    FAST;

    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout); 
    
    Panda();

    return 0; 
} 

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = set([int(input()) for _ in range(m)])
ans = 1
dp = [0] * (n + 3)
dp[0] = 1
for i in range(n):
    if i + 1 not in a:
        dp[i + 1] += dp[i]
    if i + 2 not in a:
        dp[i + 2] += dp[i]
print(dp[n] % (10 ** 9 + 7))

Measured memory_bytes: 462708
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
string s;
cin>>s;
int x=0,y=0,z=0;
if (s[0]=='A') x=1;
for (int i=2 ;i<=s.size()-2 ;i++){
    if(s[i]=='C')
        y++;
}
for (int i=0 ;i<s.size();i++){
    if(isupper(s[i])){
        z++;
    }
}
if(x==1 && y==1 && z==2) cout<<"AC";
else cout<<"WA";
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
char in[110];
int main(){
	scanf("%s",in);
	for(int i=0;in[i];i++){
		for(int j=i+1;in[j];j++){
			if(in[i]=='C'&&in[j]=='F'){printf("Yes\n");return 0;}
		}
	}
	printf("No\n");
}

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

int main() {
  vector<int> S;
  S.push_back(0);
  vector<int> x = {3, 5, 7};
  int prev = 0;
  for (int i = 1; i <= 9; i++) {
    int len = S.size();
    for (int j = prev; j < len; j++) {
      for (int k = 0; k < 3; k++) {
        S.push_back(S[j] * 10 + x[k]);
      }
    }
    prev = len;
  }

  int N, ans = 0;
  cin >> N;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] <= N) {
      bool f3 = false, f5 = false, f7 = false;
      int M = S[i];
      while (M > 0) {
        int m = M % 10;
        M /= 10;
        if (m == 3)
          f3 = true;
        else if (m == 5)
          f5 = true;
        else if (m == 7)
          f7 = true;
        else {
          f3 = false;
          break;
        }
      }
      if (f3 && f5 && f7) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
let nil = -1;;
type node =
  {
    mutable parent:int;
    mutable left:int;
    mutable right:int;
  };;

let tree = Array.init 25 (fun x -> { parent=nil; left=nil; right=nil; });;

let rec inorder = function
    i when i = nil -> ()
  | i ->
     inorder tree.(i).left;
     Printf.printf " %d" i;
     inorder tree.(i).right
;;

let rec preorder = function
    i when i = nil -> ()
  | i ->
     Printf.printf " %d" i;
     preorder tree.(i).left;
     preorder tree.(i).right
;;

let rec postorder = function
    i when i = nil -> ()
  | i ->
     postorder tree.(i).left;
     postorder tree.(i).right;
     Printf.printf " %d" i
;;

let rec get_root = function
    -1 -> nil
  | i -> if tree.(i).parent = nil then i
         else get_root (i-1)
;;

let rec read = function
    0 -> ()
  | i ->
     let (id,left,right) = Scanf.scanf " %d %d %d\n" (fun x y z -> (x,y,z)) in
     tree.(id).left <- left;
     tree.(id).right <- right;
     if left <> nil then tree.(left).parent <- id;
     if right <> nil then tree.(right).parent <- id;
     read (i-1)
;;

let () =
  let n = read_int () in
  read n;
  let root = get_root (n-1) in
  print_endline "Preorder";
  preorder root;print_newline();
  print_endline "Inorder";
  inorder root;print_newline();
  print_endline "Postorder";
  postorder root;print_newline()
;;

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

int main() {
  string S,T; cin >>S >>T;
  rep(i,0,S.size()) {
    if (S==T) {
      cout <<"Yes" <<endl;
      return 0;
    }
    char temp=S[S.size()-1];
    S.erase(S.size()-1); 
    S.insert(S.begin(),temp);
  }
  cout <<"No" <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int insertionSort(int N,int A[]){
  int v,j;
  for(int i = 1; N > i; i++){
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
    }
    A[j+1] = v;
    for(int i = 0; N > i; i++){
      cout << A[i];
      if(N == i + 1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }
}
int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i = 0; N > i; i++){
    cin >> A[i];
    cout << A[i];
    if(N == i + 1){
      cout << endl;
    } else {
      cout << " ";
    }
  }
  insertionSort(N,A);
}


Measured memory_bytes: 3092
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
       
        for(int i = 0; i < n ; i++){
          a[i] = sc.nextInt();
        }
      
        Arrays.sort(a);
        int ans = 0;
        for(int i = 0; i < n ; i++){
          int same = 1;
          for(int j = i + 1; j < n; j++){
            if(a[i] == a[j]){
              same++;
            }else{
              break;
            }
          }
          i += same-1;
          if(same % 2 != 0){
            ans++;
          }
          
        }
      
          System.out.println(ans);
	}
}


Measured memory_bytes: 58352
#include<iostream> 
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++) 

int main() {
    int N, A;
    cin >> N;
    cin >> A;
    if (N%500 <= A) {
        cout << "Yes" << endl;
    } else cout << "No" << endl;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
g = Array.new(n + 1) { [1, nil] }
g[0][0] = nil
g[1][1] = true

m.times do
  x, y = gets.split.map(&:to_i)

  g[x][0] -= 1
  g[y][0] += 1
  g[y][1] = true if g[x][1]
  g[x][1] = nil if g[x][0] == 0
end

puts g.map(&:last).count(true)

Measured memory_bytes: 10108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        String S = sc.next();
        int min = 0x3f3f3f3f;
        for (int i=0; i<S.length()-2; i++) {
            if (Math.abs(Integer.parseInt(S.substring(i, i+3))-753) < min) {
                min = Math.abs(Integer.parseInt(S.substring(i, i+3))-753);
            }
        }
        System.out.println(min);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22612
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let a: usize = sc.read();
    let b: usize = sc.read();
    let diff = b - a;
    let mut res = 1;
    for i in 2..diff {
        res += i;
    }
    println!("{}", res - a);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
s = list(str(input()))

x = int(s[0] + s[1])
y = int(s[2] + s[3])

if (x == 0 or 13 <= x) and (1 <= y and y <= 12):
    print('YYMM')
elif (1 <= x and x <= 12) and (y == 0 or 13 <= y):
    print('MMYY')
elif (1 <= x and x <= 12) and (1 <= y and y <= 12):
    print('AMBIGUOUS')
else:
    print('NA')


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

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

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

	void merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion

int main()
{
	long long n, m; cin >> n >> m;
	vector<long long> res(m);
	vector<int> a(m), b(m);
	rep(i, 0, m - 1)
	{
		cin >> a[i] >> b[i];
		--a[i], --b[i];
	}

	UnionFind uf(n);

	long long cur = n * (n - 1) / 2;
	
	rep(i, 0, m - 1)
	{
		res[i] = cur;
		if (uf.issame(a[m - 1 - i], b[m - 1 - i]))continue;

		long long sa = uf.size(a[m - 1 - i]), sb = uf.size(b[m - 1 - i]);
		cur -= sa * sb;
		uf.merge(a[m - 1 - i], b[m - 1 - i]);
	}

	reverse(all(res));
	rep(i, 0, m - 1)cout << res[i] << endl;
}

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

int main(){
  long long  N ;
  cin >> N ;
  set<int>a;
  long long b ;
  for(int i=0;i<N;i++){
    cin >> b ;
    a.insert(b);
  }
  
  if(a.size()==N) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

Measured memory_bytes: 9600
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
const ll mod =1e18 + 7;
ll exp(ll a , ll b){
	if(b == 0)	return 1;
	int x = b % 2 == 0 ?   ((exp(a , b/2)%mod)*(exp(a , b / 2)%mod))%mod :  (a%mod*exp(a , b - 1) % mod)%mod;
	return x;
}
const int nax = 1e6 + 7;
int ans[nax];
int a[nax];
multiset< int > st;
vector< int > g[nax];
void dfs(int u , int p){
	st.insert(a[u]);
	int flag = -1;
	auto it = st.lower_bound(a[u]);
	if(++it != st.end()){
		flag = *it;
		st.erase(it);
	}
	ans[u] = st.size();
	for(auto v: g[u]){
		if(v == p) continue;
		dfs(v , u);
	}
	if(flag != -1) st.insert(flag);
	st.erase(st.find(a[u]));
	
}
int main(){
	fast;
	int n;
	cin >> n;
	//int a[n + 1];
	for(int i = 1; i <= n ; i++){
		cin >> a[i];
	}				
	for(int i = 1, x , y ; i <= n - 1 ; i++){
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}	
	dfs(1 , 0);		
	for(int i = 1 ; i <= n ; i++)
		cout << ans[i] << endl;
	//cout << endl;																																															
	return 0;
}


Measured memory_bytes: 49244
#!/usr/bin/env python3
import sys
from itertools import combinations

def solve(N: int, A: "List[int]", B: "List[int]"):
    answer = 10**10
 
    ## 奇数indexにくるものを決め打ち
    for c in combinations(range(N), N//2):
        even, odd= [], []
        
        for i in range(N):
            if i in c:
                odd.append((A[i] if i % 2 == 1 else B[i],i))
            else:
                even.append((A[i] if i % 2 == 0 else B[i],i))
    
        even.sort()
        odd.sort()
        t = []
        ind = []
        
        for i in range(N//2):
            t.append(even[i][0])
            t.append(odd[i][0])
            ind.append(even[i][1])
            ind.append(odd[i][1])
        else:
            if N%2 == 1:
                t.append(even[-1][0])
                ind.append(even[-1][1])
        
        if t != sorted(t):
            continue

        tentousuu = 0
        for i in range(N-1):
            for j in range(i+1,N):
                if ind[i] > ind[j]:
                    tentousuu += 1
        
        if answer > tentousuu:
            answer = tentousuu

    if answer == 10**10:
        print(-1)
    else:
        print(answer)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 44892
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

LL f(LL n)
{
    if (n < 2)
    {
        return 0;
    }
    return n * (n - 1) / 2;
}

int main()
{
    IOS;
    int n;
    cin >> n;
    LL ans = 0;
    vector<LL> a(n, 0), cnt(n + 1, 0);
    FOR(i, 0, n)
    {
        cin >> a[i];
        ++cnt[a[i]];
    }
    FOR(i, 0, n + 1) { ans += f(cnt[i]); }
    FOR(i, 0, n) { cout << ans - f(cnt[a[i]]) + f(cnt[a[i]] - 1) << '\n'; }
}


Measured memory_bytes: 5760
n,k = map(int, input().split())
p = [[0,0]]
for i in range(n):
    a,b = map(int, input().split())
    p.append([a,b])
p.sort()
ans = 0
p.pop(0)
for i in range(n):
    ans+=p[i][1]
    if ans>=k:
        print(p[i][0])
        exit()
    else:
        continue

Measured memory_bytes: 20104
#include<bits/stdc++.h>
using namespace std;
string s;
int f[27];
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++)
	f[s[i]-'a']++;
	for(int i=0;i<26;i++)
	if(f[i]>1){
		cout<<"no"<<"\n";
		return 0;
	}
	cout<<"yes"<<"\n";
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef int64_t ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst) : src(src), dst(dst), weight(1) {}
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}


typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

// http://www.prefield.com/algorithm/graph/dijkstra.html
void dijkstra(const Graph &g, int s, vector<Weight> &dist) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  vector<int> prev(n, -1);

  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    for (Edge f: g[e.dst]) {
      if (dist[f.dst] > e.weight + f.weight) {
        dist[f.dst] = e.weight + f.weight;
        Q.push(Edge(f.src, f.dst, e.weight + f.weight));
      }
    }
  }
}

int main(){
  int N, M;
  cin >> N >> M;
  Graph g(3 * N);
  REP(i, M) {
    int u, v;
    cin >> u >> v; --u; --v;
    REP(k, 3) g[3 * u + k].push_back(Edge(3 * u + k, 3 * v + (k + 1) % 3));
  }
  int S, T;
  cin >> S >> T; --S; --T;

  vector<Weight> dist;
  dijkstra(g, 3 * S, dist);
  int ret = dist[3 * T];
  if (ret == INF) {
    ret = -1;
  } else {
    ret /= 3;
  }

  cout << ret << endl;

  return 0;
}



Measured memory_bytes: 18944
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int h, w, n; cin >> h >> w >> n;
	vi a(n); rep(i, n) cin >> a[i];
	vi col;
	vector<vi> ans(h, vi(w));
	
	int sz = 0;
	rep(i, n) rep(j, a[i]) col.pb(i + 1);
	
	rep(i, h){
		if(i % 2) for(int j = w - 1; j >= 0; j--) ans[i][j] = col[sz++];
		else rep(j, w) ans[i][j] = col[sz++];
		rep(j, w) cout << ans[i][j] << (j==w-1?"\n":" ");
	}
	
	return 0;
}

Measured memory_bytes: 512
#[allow(dead_code)]
struct Utree {
    n: usize,
    par: Vec<usize>,
    rank: Vec<usize>,
    size: Vec<usize>,
}
#[allow(dead_code)]
impl Utree {
    fn new(n: usize) -> Utree {
        let par: Vec<usize> = (0..n).collect();
        let rank: Vec<usize> = vec![0; n];
        let size: Vec<usize> = vec![1; n];
        Utree {
            n: n,
            par: par,
            rank: rank,
            size: size,
        }
    }
    fn find(&mut self, x: usize) -> usize {
        if self.par[x] == x {
            x
        } else {
            let parent = { self.par[x] };
            let ret = self.find(parent);
            self.par[x] = ret;
            ret
        }
    }
    fn unite(&mut self, x: usize, y: usize) {
        let x_root = self.find(x);
        let y_root = self.find(y);
        if x_root == y_root {
            return;
        };
        if self.rank[x_root] < self.rank[y_root] {
            self.par[x_root] = y_root;
            self.size[y_root] += self.size[x_root];
        } else {
            self.par[y_root] = x_root;
            self.size[x_root] += self.size[y_root];
            if self.rank[x_root] == self.rank[y_root] {
                self.rank[x_root] += 1;
            }
        }
    }
    fn is_same(&mut self, x: usize, y: usize) -> bool {
        let x_root = self.find(x);
        let y_root = self.find(y);
        x_root == y_root
    }
    fn get_size(&mut self, x: usize) -> usize {
        let x_root = self.find(x);
        self.size[x_root]
    }
}

fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse::<usize>().unwrap();
    let k: usize = iter.next().unwrap().parse::<usize>().unwrap();
    let l: usize = iter.next().unwrap().parse::<usize>().unwrap();
    
    use std::collections::HashMap;
    // let mut road = vec![HashSet::new();n];
    // let mut rail = vec![HashSet::new();n];
    let mut road = Utree::new(n);
    let mut rail = Utree::new(n);
    for _ in 0..k {
        let p: usize = iter.next().unwrap().parse::<usize>().unwrap() - 1;
        let q: usize = iter.next().unwrap().parse::<usize>().unwrap() - 1;
        road.unite(p, q);
    }
    for _ in 0..l {
        let r: usize = iter.next().unwrap().parse::<usize>().unwrap()-1;
        let s: usize = iter.next().unwrap().parse::<usize>().unwrap()-1;
        rail.unite(r, s);
    }

    let mut hmap: HashMap<(usize, usize), usize> = HashMap::new();
    for i in 0..n {
        let pair = (road.find(i), rail.find(i));
        *hmap.entry(pair).or_insert(0) += 1;
    }

    for i in 0..n {
        let pair = (road.find(i), rail.find(i));
        print!("{}", hmap.get(&pair).unwrap());
        if i != n-1 {print!(" ")}
        else {print!("\n")};
    }
}


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

using namespace std;

int sol(int x){
	for(int i=1;i<=x;i++){
		int v=i*(i+1);
		if(v%x==0) return i;
	}
	return -1;
}
vector<pair<long long,int>> prime_divs(long long x){
	vector<pair<long long,int>> res;
	for(long long i=2;i*i<=x;i++){
		if(x%i!=0) continue;
		
		int cnt=0;
		while(x%i==0){
			x/=i;
			cnt++;
		}
		res.push_back(make_pair(i,cnt));
	}
	if(x>1) res.push_back(make_pair(x,1));
	return res;
}
__int128 inv(__int128 a,__int128 mod){
	__int128 b=mod,p=1,q=0;
	while(b){
		__int128 c=a/b,d=a;
		a=b;
		b=d%b;
		d=p;
		p=q;
		q=d-c*q;
	}
	return (p+mod)%mod;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	long long x;
	cin >> x;
	x*=2;
	
	vector<pair<long long,int>> pds=prime_divs(x);
	int n=(int)pds.size();
	
	long long res=x-1;
	for(int i=0;i<(1<<n);i++){
		long long le=1,ri=1;
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				for(int k=0;k<pds[j].second;k++) le*=pds[j].first;
			}else{
				for(int k=0;k<pds[j].second;k++) ri*=pds[j].first;
			}
		}
		
		if(le==1 || ri==1) continue;
		__int128 invle=inv(le,ri);
		if((res+1)/le>=invle){
			res=min(res,(long long)(le*invle-1));
		}
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 3676
import java.util.*;

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

        int a = sc.nextInt();
        float sum = 0;
        int[] numarray = new int[a];
        float[] resultarray = new float[a];
        for (int i = 0; i < a; i++) {
            numarray[i] = sc.nextInt();
        }
        for (int i = 0; i < numarray.length; i++) {
            resultarray[i] = (float) 1 / numarray[i];
        }
        for (int j = 0; j < resultarray.length; j++) {
            sum = sum + resultarray[j];
        }
        sum = 1 / sum;

        System.out.println(sum);
    }
}


Measured memory_bytes: 23380
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

#define MAX 1010

const int c[8] = { 1,2,1,2,1,4,1,4 };

int hash(int i){
  int ret = 0;
  REP(j,8){
    int now = (i+j)%8;
    ret *= 10;
    ret += c[now];
  }
  return ret;
}

int main(){
  int p[8];
  while(cin>>p[0]){
    int ansIdx;
    int ansmax = 0;
    int anshsh;
    REP(i,7) cin>>p[i+1];
    REP(i,8){
      int sum = 0;
      REP(j,8){
	int now = (i+j)%8;
	sum += min(p[j], c[now]);
      }
      if(ansmax <= sum){
	if(ansmax == sum){
	  int tmp = hash(i);
	  if(anshsh > tmp){
	    anshsh = tmp;
	    ansIdx = i;
	  }
	}else{
	  ansIdx = i;
	  ansmax = sum;
	  anshsh = hash(i);
	}
      }
    }
    REP(j,8){
      int now = (ansIdx+j)%8;
      printf("%d%c",c[now],(j==7?'\n':' '));
    }
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long k = sc.nextLong();
		int work = -1;
		for(int i = 0; i < s.length() && i < k; i++){
			work = Integer.parseInt(s.substring(i,i+1));
			if(work != 1) break;
		}
		System.out.print(work);
	}
}


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

#define INF 10000000

int main(){
	int n,m,C[20];
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> C[i];
	}
	int T[50001];
    	for(int j = 0;j <= n; j++){
       	T[j] = INF;
	}
    	T[0] = 0;

    	for(int i = 0;i < m; i++){
       	for(int j = C[i];j <= n; j++){
            		T[j] = min(T[j], T[j - C[i]] + 1);
		}	
	}
    	cout << T[n] << endl;

	return 0;
}


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

public class Program
{
    static long n;
    static long l;

    static List<string> s;

    static string output;

    public static void Main(string[] args)
    {
        Input();
        Proc();
        Output();
    }

    static void Input()
    {
        string[] input = null;

        // スペース区切りの整数の入力(横、個別)
        input = Console.ReadLine().Split(' ');

        n = long.Parse(input[0]);
        l = long.Parse(input[1]);

        // 文字列の入力(N行)
        s = new List<string>();
        for (long idx = 0; idx < n; idx++)
        {
            s.Add(Console.ReadLine());
        }
    }

    static void Proc()
    {
        s.Sort();

        for (int idx = 0; idx < s.Count; idx++)
        {
            output += s[idx];
        }
    }

    static void Output()
    {
        // 出力
        Console.WriteLine(output);
        output = string.Empty;
    }
}


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

int main(){
  while(1){
  int m,l,r;
  cin>>m>>l>>r;
  if(!m&&!l&&!r)break;

  int a[300];
  for(int i=0;i<m;i++)cin>>a[i];

  sort(a,a+m);
  reverse(a,a+m);
  int gap=0,n;
  for(int i=l-1;i<r;i++)
    if(a[i]-a[i+1]>=gap)n=i,gap=a[i]-a[i+1];
  
  cout <<n+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1176
N = int(input())
H = list(map(int, input().split(" ")))

record = 0
tmp_rec = 0
ans = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        tmp_rec += 1
        if i == N-2:
            if tmp_rec > record:
                record = tmp_rec
    else:
        if tmp_rec > record:
            record = tmp_rec
        tmp_rec = 0

print(record)


Measured memory_bytes: 14224
using System;
class Prpgram
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        string[] inputlist = input.Split(' ');
        int H = int.Parse(inputlist[0]);
        int A = int.Parse(inputlist[1]);
        int turn = 0;

        while (true)
        {
            turn++;
            H = (H - A);

            if (H <= 0) break;
            else continue;
        }

        Console.Write(turn);

    }
}

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> b(n);
    REP(i,n-1)cin >> b[i];
    int ans = 0;

    ans += b[0];
    REP(i,n-2){
        ans += min(b[i],b[i+1]);
    }
    ans += b[n-2];

    cout << ans << endl;

    return 0;
}

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

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll x = n/(a+b);
    ll y = n-x*(a+b);
    if(y>a)y=a;

    ll ans = x*a+y;

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

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

int main()
{
	int number = 0;
	for(;;){
		int N, M, r;
		cin >> N >> M;
		if(N == 0 && M == 0)
			break;
		cin >> r;

		vector<vector<int> > student(M+1);
		vector<int> num(M+1);
		for(int i=0; i<r; ++i){
			int t, n, m, s;
			cin >> t >> n >> m >> s;
			if(s == 1){
				if(num[m] == 0)
					student[m].push_back(t);
				++ num[m];
			}else{
				-- num[m];
				if(num[m] == 0)
					student[m].push_back(t);
			}
		}

		int q;
		cin >> q;
		for(int i=0; i<q; ++i){
			int ts, te, m;
			cin >> ts >> te >> m;
			int answer = 0;
			for(unsigned j=0; j<student[m].size(); j+=2){
				if(student[m][j] <= te && student[m][j+1] >= ts)
					answer += min(student[m][j+1],te) - max(student[m][j],ts);
			}
			cout << answer << endl;
		}

	}

	return 0;
}

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

#define len(x) ((int)(x).size())
#define log(x) cout << (x) << endl
#define rep(i, n) for (int i = 0; i < (int)n; ++i)

int n;
string s;

bool is(string t, int i, int j) {
	if (j >= n) return false;
	for (int k=i,l=0;k<=j;++k,++l)
		if (t[l]!=s[k])
			return false;
	return true;
}

int main() {
	cin >> s;
	n = len(s);

	rep (i, n) {
		if (s[i] == 'd') {
			if (is("dream",i,i+4)) {
				if (is("er",i+5,i+6)&&!is("erase",i+5,i+9)) i += 6; // "dreamer"
				else i += 4; // "dream"
			}
			else return log("NO"),0;
		}
		else if (s[i] == 'e') {
			if (is("erase",i,i+4)) {
				if (is("r",i+5,i+5)) i += 5; // "eraser"
				else i += 4; // "erase"
			}
			else return log("NO"),0;
		}
		else return log("NO"),0;	
	}
	log("YES");
}




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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  long long ans = 0;
  long long n; cin >> n;
  auto proc = [&](long long d) {
    if (d > 1) {
      --d;
      if (n % d == n / d) ans += d;
    }
  };
  for (long long d = 1; d * d <= n; ++d) if (n % d == 0) {
    proc(d);
    if (d * d != n) proc(n / d);
  }
  cout << ans << '\n';
}


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


int main(){
    int n,s,i;
    double sq,su;
    scanf("%d",&n);
    while(n){
        sq = su = 0;
        for(i=0;i<n;i++){
            scanf("%d",&s);
            sq += s*s;
            su += s;
        }
        sq /= n;
        su /= n;
        printf("%f\n",sqrt(sq-su*su));
        scanf("%d",&n);
    }
}

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

int box[100001];

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    memset(box, 0, sizeof(box));
    rep(i, N) box[i] = 1;
    bitset<100001> check;
    check[0] = 1;
    rep(i, M) {
        int x, y; cin >> x >> y;
        --x; --y;
        if(!check[x]) {
            box[x]--;
            box[y]++;
            continue;
        }
        if(box[x] == 1) {
            box[x] = 0;
            box[y]++;
            check[x] = 0;
            check[y] = 1;
        }else if(box[x] > 1) {
            check[y] = (check[y] | check[x]);
            --box[x]; ++box[y];
        }
    }
    cout << check.count() << endl;
    return 0;
}

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

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

	int n, k;
	cin >> n >> k;
	vector<int> a[101];

	// cout << n << k << endl;
	set<int> w;
	for (int i = 0; i < k; i++) {
		int d;
		cin >> d;
		// cout << d << "\n";
		for (int j = 0; j < d; j++) {
			int e;
			cin >> e;
			// cout << e << " ";
			a[i].push_back(e);
			w.insert(e);
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (w.find(i) == w.end()) 
			ans++;
	}

	cout << ans << "\n";
}

Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<52;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

class Union_Find_Tree{
	public:
	vi Par,Rank,Size;
	Union_Find_Tree(int n){
		Par=Rank=vi(n);
		Size=vi(n,1);
		for(int i=0;i<n;i++) Par[i]=i;
	}
	int Find_Par(int x){
		if(Par[x]==x) return x;
		return Par[x]=Find_Par(Par[x]);
	}
	int Find_Size(int x){
		return Size[Find_Par(x)];
	}
	bool Unite(int x,int y){
		x=Find_Par(x);
		y=Find_Par(y);
		if(x==y) return 0;
		if(Rank[x]<Rank[y]){
			Par[x]=y;
			Size[y]+=Size[x];
		}
		else{
			Par[y]=x;
			Size[x]+=Size[y];
			if(Rank[x]==Rank[y]) Rank[x]++;
		}
		return 1;
	}
	bool Same(int x,int y){
		return Find_Par(x)==Find_Par(y);
	}
};

int n,m;

int main(){
	cin>>n>>m;
	Union_Find_Tree uft1(n),uft2(n*2);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		uft1.Unite(u,v);
		uft2.Unite(u,v+n);
		uft2.Unite(v,u+n);
	}
	ll num0=0,num1=0,N=0;
	vi b(n);
	for(int i=0;i<n;i++){
		int p=uft1.Find_Par(i);
		if(!b[p]){
			if(uft1.Find_Size(p)==1){
				N++;
				b[p]--;
			}
			else{
				num0+=(uft2.Same(i,i+n)?1:2);
				num1++;
				b[p]++;
			}
		}
	}
	ll ans=N*n*2-N*N;
	for(int i=0;i<n;i++){
		int p=uft1.Find_Par(i);
		if(b[p]==1){
			b[p]++;
			if(uft2.Same(i,i+n)) ans+=num1;
			else ans+=num0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4224
// Bismillaahirrahmaanirrahiim
/* Author	: Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

/* MACROS SAMPAH */
#define jehian using
#define mau namespace
#define libur std
#define cepet {ios_base::sync_with_stdio(0);cin.tie(0);}

jehian mau libur;
/* MACROS FOR TYPE */
typedef long l;
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

/* MACROS FOR PRINT */
#define nl printf("\n");
#define sp printf(" ");

/* MACROS FOR FUNCTION AND METHOD */
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define eb emplace_back
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) for(int _je = sizeof(x)/sizeof(x[0]); _je--;) x[_je] = y

/* MACROS FOR ATTRIBUTE */
#define fi first
#define se second

/* MACROS FOR SCAN */
#define scc(x) scanf("%c", &x)
#define scd(x) scanf("%Lf", &x)
#define scf(x) scanf("%f", &x)
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scld(x) scanf("%Lf", &x)
#define scui(x) sci(x)
#define scul(x) scl(x)
#define scull(x) scll(x)
#define special pair<ll,pll>

ll MIN = 1e9;


int main(){
	ll N, K;
	cin >> N >> K;
	ll res = 1;
	for (ll i = 0; i < N; ++i){
		if (res * 2 < res + K){
			res *= 2;
		} else {
			res += K;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
puts 1.step(N, 2).count {|n|
  cnt = 0
  1.step((n**0.5).to_i + 1) do |i|
    if n % i == 0
      cnt += 1
      cnt += 1 if i != n / i
    end
  end
  cnt == 8
}


Measured memory_bytes: 3836
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
vector<vector<char> > c(10, vector<char>(5));
int main()
{
  c[1][0] = '.';c[1][1] = ',';c[1][2] = '!';c[1][3] = '?';c[1][4] = ' ';
  FOR(i,0,3) c[2][i] = 'a' + i;
  FOR(i,0,3) c[3][i] = 'd' + i;
  FOR(i,0,3) c[4][i] = 'g' + i;
  FOR(i,0,3) c[5][i] = 'j' + i;
  FOR(i,0,3) c[6][i] = 'm' + i;
  FOR(i,0,4) c[7][i] = 'p' + i;
  FOR(i,0,3) c[8][i] = 't' + i;
  FOR(i,0,4) c[9][i] = 'w' + i;
  int n;
  cin >> n;
  while(n--) {
    string s;
    cin >> s;
    int cnt = 0;
    char now;
    string ans = "";
    FOR(i,0,s.length()) {
      if(s[i] == '0' && now != '0') {
        cnt--;
        if(now == '1') cnt %= 5;
        else if(now == '7' || now == '9') cnt %= 4;
        else cnt %= 3;
        ans += c[now-'0'][cnt];
        now = '0';
        cnt = 0;
      } else if(s[i] != '0'){
        now = s[i];
        cnt++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n;
pii p[125252];

const int N = 1<<17;
map<int,int> seg[2*N];

int query(int x,int y,int a,int b,int k){
  if(b<=x)return 0;
  else if(x<=a){
    return seg[k].upper_bound(y)->second;
  }else{
    int m = (a+b)/2;
    return max(query(x,y,a,m,2*k+1),query(x,y,m,b,2*k+2));
  }
}
void update(int x,int y,int v){
  x += N-1;
  x = 2*x + 1;
  while(x!=0){
    x = (x-1)/2;
    if(seg[x].lower_bound(y)->second>=v)continue;
    seg[x][y] = v;
    auto it = seg[x].lower_bound(y);
    while(it!=seg[x].begin()){
      it--;
      if(it->second <= v){
        seg[x].erase(it++);
      }else{
        break;
      }
    }
  }
}

int main(){
  scanf("%d",&n);
  set<int> Z;
  REP(i,n){
    int a,b;
    scanf("%d%d",&a,&b);
    p[i] = pii(a+b,a);
    Z.insert(b);
  }
  // zaatu
  Z.insert(2e9);
  Z.insert(-2e9);
  map<int,int> M;
  {
    int it = 0;
    for(int x : Z){
      M[x] = it++;
    }
  }
  // seg init
  REP(i,2*N-1)seg[i][2e9] = 0;
  // calc
  int ans = 0;
  sort(p,p+n);
  reverse(p,p+n);
  REP(i,n){
    int x = p[i].second;
    int y = p[i].first-x;
    int xx = M.upper_bound(x)->second;
    int yy = M[y];
    int v = query(xx,y,0,N,0);
    CHMAX(ans,v+1);
    update(yy,x,v+1);
  }
  printf("%d\n",ans);
  return 0;
}

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

#define Fi first
#define Se second
#define mp make_pair
#define bug cout << "check\n";
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;


const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;


int a[2][105];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; cin >> n;
	for(int i = 1; i <= 2; ++i)
		for(int j = 1; j <= n; ++j)
			cin >> a[i][j];
	for(int i = 1; i <= 2; ++i) {
		for(int j = 1; j <= n; ++j) {
			if(i == 1) 
				a[i][j] = a[i][j] + a[i][j-1]; 
			else
				a[i][j] = max(a[i][j] + a[i-1][j], a[i][j] + a[i][j-1]);
			}
	}
	cout << a[2][n] << endl;
	//cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define __STDC_FORMAT_MACROS
#define p64 PRId64

#include <algorithm>
#include <cinttypes>
#include <cstdio>
#include <vector>

using namespace std;
using ll = int64_t;

int main()
{
    int N, K;
    if (scanf("%d%d", &N, &K) < 2) return 0;

    vector<int> x(N, 0);
    vector<int> y(N, 0);

    vector<int> xary(N, 0);
    vector<int> yary(N, 0);

    for (int i = 0; i < N; i++)
    {
        if (scanf("%d%d", &x[i], &y[i]) < 2) return 0;
        xary[i] = x[i], yary[i] = y[i];
    }

    sort(xary.begin(), xary.end());
    sort(yary.begin(), yary.end());

    ll ans = ((ll)xary[N - 1] - xary[0]) * ((ll)yary[N - 1] - yary[0]);
    for (int i = 0; i < N; i++)
        for (int j = i + 1; j < N; j++)
            for (int k = 0; k < N; k++)
                for (int l = k + 1; l < N; l++)
                {
                    int cnt = 0;

                    for (int m = 0; m < N; m++)
                    {
                        if (xary[i] <= x[m] && x[m] <= xary[j]
                            && yary[k] <= y[m] && y[m] <= yary[l])
                            cnt++;
                    }

                    if (K <= cnt)
                        ans = min(ans,
                        ((ll)xary[j] - xary[i]) * ((ll)yary[l] - yary[k]));
                }

    printf("%" p64 "\n", ans);
    return 0;
}

Measured memory_bytes: 256
N, L = map(int, input().split())

T = []
for i in range(N):
    t = L + (i + 1) - 1
    T.append(t)

min_abs = abs(T[0])
min_abs_i = 0

for i, ti in enumerate(T):
    # min_abs = min(min_abs, abs(ti))
    abs_ti = abs(ti)
    if abs_ti < min_abs:
        min_abs_i = i
        min_abs = abs_ti

# print(T)
# print(min_abs)
# print(min_abs_i)

ans = sum(T) - T[min_abs_i]
print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <queue>
using namespace std;
#define N 100050
int head[N],to[N<<1],nxt[N<<1],cnt,n,tmp[22],f[N][22],ans;
inline void add(int u,int v) {
	to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt;
}
void merge(int *a,int *b) {
	int i;
	for(i=0;i<=20;i++) a[i]+=b[i];
}
void dfs(int x,int y) {
	int i;
	for(i=head[x];i;i=nxt[i]) if(to[i]!=y) dfs(to[i],x);
	memset(tmp,0,sizeof(tmp));
	for(i=head[x];i;i=nxt[i]) if(to[i]!=y) merge(tmp,f[to[i]]);
	int k=0;
	for(i=20;i>=0;i--) {
		if(tmp[i]>1) {
			k=i+1; break;
		}
	}
	for(;tmp[k];k++) ;
	memcpy(f[x]+k,tmp+k,sizeof(int)*(20-k));
	f[x][k]++;
	ans=max(ans,k);
}
int main() {
	scanf("%d",&n);
	int i,x,y;
	for(i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	dfs(1,0); printf("%d\n",ans);
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ff first
#define ss second
long double pi = 3.14159265359 ;
const int N=2e5+5;
const int mod=1e9+7;
 
int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1LL)
            res = res * a;
        a = a * a;
        b >>= 1LL;
    }
    return res;
}
 
int32_t main()
{
    IOS;
    
    long double a,b,c;
    cin>>a>>b;
    long double hh,mm,x;
    cin>>hh>>mm;
    x=abs(((60.0*hh)-(11.0*mm))/2.0);
    x*=pi;
    x/=180.0;
    c=(a*a) + (b*b) - (2.0*a*b*cos(x));
    c=sqrtl(c);
    cout<<fixed<<setprecision(12)<<c;
}


Measured memory_bytes: 4184
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
signed main(){
    vector<int>dp(51,0LL),dp2(51,0LL);
    int n,x; cin >> n >> x;
    rep(i,51){
        if(i == 0){
            dp[0] = dp2[0] = 1LL;
        } else {
            dp[i] = dp[i-1] + dp[i-1] + 3;
            dp2[i] = dp2[i-1] + dp2[i-1] + 1;
        }
    }
    function<int(int,int)>cal = [&](int i,int x) -> int{
        if(i == 0 or  x == 0) return x != 0;
        return (dp[i-1] + 2 > x ? cal(i-1,x-1) :cal(i-1,x - dp[i-1] - 2) + dp2[i-1] + 1);
    };
    cout << cal(n,x) << endl;
}


Measured memory_bytes: 256