akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def main():
    # sys.stdin = open("sample.txt")
    S = Scanner.string()
    cnt = 0
    ans = 0
    for s in S:
        if s == "S":
            cnt += 1
        else:
            if cnt > 0:
                cnt -= 1
                ans += 1
    print(len(S) - ans * 2)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 42456
def green_bin(n, sli):

    ans = 0
    count = {}

    for i in sli:
        i.sort()
        if ''.join(i) in count:
            ans += count[''.join(i)]
            count[''.join(i)] += 1

        else:
            count[''.join(i)] = 1

    return ans

def main():
    n = int(input())
    sli = [list(str(input()))for i in range(n)]
    print(green_bin(n, sli))

if __name__ == '__main__':
    main()

Measured memory_bytes: 39084
S = list(input())
ans = "AC"
if S[0] != "A":
    ans = "WA"
else:
    count = 0
    for i in S[2:-1]:
        if i == "C":
            count += 1
    if count != 1:
        ans = "WA"
    else:
        for i in S:
            if i not in ["A","C"] and str.islower(i) != True:
                ans = "WA"
print(ans)

Measured memory_bytes: 3064
void main()
{
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], m = tmp[1];
    string s = readln.chomp;

    int[] move;
    while (n > 0)
    {
        bool ok;
        foreach_reverse (i; 1 .. m+1)
        {
            if (n - i < 0) continue;

            if (s[n-i] == '0')
            {
                ok = true;
                n -= i;
                move = i ~ move;
                break;
            }
        }

        if (!ok)
        {
            break;
        }
    }

    if (n == 0)
    {
        move.to!(string[]).join(" ").writeln;
    }
    else
    {
        writeln(-1);
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 6396
# エラトステネスの篩
import math
def Eratosthenes(n):
    if n < 2:
        return None
    prime = [2]
    limit = math.ceil(n**0.5)
    data = list(range(3, n+1, 2))
    p = -1
    while p < limit:
        p = data[0]
        prime.append(p)
        data = [d for d in data if d%p != 0]
    return prime + data

q = int(input())
L, R = [], []
for _ in range(q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

r_max = max(R)

# r_maxまでの素数を記録する
memo1 = [0]*(r_max+1)
primes = Eratosthenes(r_max)
for p in primes:
    memo1[p] = 1

# r_maxまでの2017に似た数を記録する
memo2 = [0]*(r_max+1)
for p in primes:
    if (p+1)%2 == 0:
        if memo1[(p+1)//2] == 1:
            memo2[p] = 1
            
# 2017に似た数の累積和
import itertools
accum = list(itertools.accumulate(memo2))

# 出力
for i in range(q):
    print(accum[R[i]] - accum[L[i]-1])

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

using namespace std;

typedef long long ll;
#define ar array

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    map<int, int> mp;
    ll ans = 0;
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        int x;
        cin >> x;
        ans += mp[i-x];
        mp[x+i]++;
    }
    cout << ans;
    return 0;
}
/*

*/


Measured memory_bytes: 20624
import java.util.*;
import static java.lang.System.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int n = Integer.parseInt(sc.next());
int l = Integer.parseInt(sc.next());
String[] s=new String[n];
for(int i=0;i<n;i++){s[i]=sc.next();}
Arrays.sort(s);
for(String i:s){out.print(i);}
out.println();
}}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e9
typedef long long ll;
ll mod =  1e9 + 7;

long long fast_exp(long long a, long long b)
{
    if(b <= 0)
       return 1;
    else
    {
       long long res = 1;
       res = fast_exp(a,b/2);
       res = (res*res)%mod;
       if(b%2 == 1)
          res = (res*a)%mod;
       return res;
 
    }
}



int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    ll n,x;
    cin>>n;
    vector <ll> c;
    for(ll i = 0; i<n ; i++)
    {
        cin>>x;
        c.pb(x);
    }
    sort(c.begin(),c.end());
    ll ans = 0;
    for(ll i = 0; i<n ; i++)
    {
        ll contr =  (fast_exp(2,i) + i*fast_exp(2,i-1))%mod;
        contr = (contr * fast_exp(2,n-i-1))%mod;
        contr = (contr * c[n-1-i])%mod;
        ans = (ans + contr)%mod;
    }
    ll mulfact = fast_exp(2,n);
    cout<<(ans * mulfact)%mod<<endl;
    

    return 0; 
    
}

















Measured memory_bytes: 2420
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}


#define int ll
int dist[20][100][100];
int cost[20][30000];
int ans[100];
vector<pair<int,int>> vertexs[100];

void solve() {
	vector<int> final_ans;
	while (true) {
		int n, m, c, s, g;
		cin >> n >> m >> c >> s >> g;
		if (n == 0) {
			REP(q, final_ans.size()) {
				cout << final_ans[q] << endl;
			}
			return;
		}
		s--;
		g--;
		vector<tuple<int, int, int>> edges[20];
		REP(i, m) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			d--;
			a--;
			b--;
			edges[d].push_back(make_tuple(a, b, c));
		}
		//calc dijkstra
		REP(k, 20) {
			REP(i, n) {
				REP(q, n) {
					dist[k][i][q] = 1e9;
				}
				vertexs[i].clear();
			}
			REP(i, edges[k].size()) {
				vertexs[get<0>(edges[k][i])].push_back(mp(get<1>(edges[k][i]), get<2>(edges[k][i])));
				vertexs[get<1>(edges[k][i])].push_back(mp(get<0>(edges[k][i]), get<2>(edges[k][i])));
			}

			REP(i, n) {
				dist[k][i][i] = 0;
				priority_queue<pair<int, int>,vector<pair<int,int>>,greater<pair<int, int>>> next;
				next.push(mp(0, i));
				while (next.empty() == false) {
					pair<int, int> now = next.top();
					next.pop();
					if (now.first != dist[k][i][now.second]) continue;
					for (auto x : vertexs[now.second]) {
						int cost = now.first + x.second;
						if (dist[k][i][x.first] > cost) {
							dist[k][i][x.first] = cost;
							next.push(mp(cost, x.first));
						}
					}
				}
			}
		}
		
		vector<int> p;
		REP(i, c) {
			int a;
			cin >> a;
			p.push_back(a);
		}

		REP(i, c) {
			vector<pair<int, int>> costing;
			REP(q, p[i] - 1) {
				int b;
				cin >> b;
				costing.push_back(mp(b, -1));
			}
			costing.push_back(mp(20000, -1));
			REP(q, p[i]) {
				cin >> costing[q].second;
			}
			reverse(ALL(costing));
			for (int q = 1; q <= 20000; ++q) {
				while (costing.back().first < q) costing.pop_back();
				cost[i][q] = cost[i][q - 1] + costing.back().second;
			}
		}

		REP(i, n) {
			ans[i] = 1e18;
		}
		ans[s] = 0;
		priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> next;
		next.push(mp(0, s));
		while (next.empty() == false) {
			pair<int, int> now = next.top();
			next.pop();
			if (now.first != ans[now.second])continue;
			REP(q, 20) {
				REP(j, n) {
					if (dist[q][now.second][j] == 1e9) continue;
					int next_cost = now.first + cost[q][dist[q][now.second][j]];
					if (ans[j] > next_cost) {
						ans[j] = next_cost;
						next.push(mp(ans[j], j));
					}
				}
			}
		}
		if (ans[g] == 1e18) {
			ans[g] = -1;
		}
		final_ans.push_back(ans[g]);
	}
}
#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 8420
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
 
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
 
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
 
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
 
    return result
 
list=input().split(" ")
n=int(list[0])
m=int(list[1])
k=int(list[2])
 
niko1=int((n*(n+1)*(2*n+1)/6 - (n+1)*n*(n+1)/2 + n*n*(n+1)/2)/2)
niko2=int((m*(m+1)*(2*m+1)/6 - (m+1)*m*(m+1)/2 + m*m*(m+1)/2)/2)
niko1=niko1%(10**9+7)
niko2=niko2%(10**9+7)
niko1=niko1*m
niko2=niko2*n
niko1=niko1%(10**9+7)
niko2=niko2%(10**9+7)
niko1=niko1*m
niko2=niko2*n
niko1=niko1%(10**9+7)
niko2=niko2%(10**9+7)
niko=niko1+niko2
kosu=cmb(m*n-2, k-2)
kosu=kosu%(10**9+7)
kotae=int(niko*kosu)
kotae=kotae%(10**9+7)

print(kotae)

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

int GCD(int a, int b){
  if(a<b){swap(a,b);}  
  if(a%b==0){return b;}
  else{return GCD(a%b,b);}
}

int main() {
  int n; cin>>n;
  vector<int> v(n);
  rep(i,n){cin>>v[i];}
  int g= GCD(v[0],v[1]);
  rep(i,n){
    g=GCD(g,v[i]);
    if(g==1)break;
  }
  cout<<g;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

P getAB(int n) {
	// n の先頭文字
	int a = n % 10;
	// n の末尾文字
	int b = 0;
	while (n) {
		b = n;
		n /= 10;
	}
	return P(a, b);
}

int main() {
	int N;
	ll result = 0;
	map<P, int> pairs;
	cin >> N;


	for(int i = 1; i <= N; i++) {
		P p = getAB(i);
		// 出現pairをカウント
		pairs[p] += 1;
	}

	// 組み合わせ数の計算
	for(int i = 1; i<= N; i++) {
		P p = getAB(i);
		P q(p.second, p.first);
		result += pairs[q];
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import numpy as np

N,S, *A = map(int, sys.stdin.buffer.read().split())
mod = 998244353

answer = np.zeros(S+1).astype(np.int64)
answer[0] = 1

for a in A:
  if a<=S:
    answer[a:] = (2*answer[a:]+answer[:-a])%mod
    answer[:a] = (2*answer[:a])%mod
  else:
    answer = (2*answer)%mod

print(answer[S])

Measured memory_bytes: 27584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <math.h>
#include <stdio.h>
#define INF 1000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long int ll;
using namespace std;

int main() {

	ll h,n = 1,kai = 0; cin >> h;
	while (h != 1) {
		kai += n;
		h /= 2; n *= 2;
	}
	cout << n + kai << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

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

    int n; cin >> n;
    int res=0;
    range(i,1,n+1){
        string s=to_string(i);
        if(s.size()%2==1) res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3764
fn main() {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).unwrap();
  let mut s = s.split_whitespace();
  let n: i32 = s.next().unwrap().parse().unwrap();
  let l: i32 = s.next().unwrap().parse().unwrap();
  let sum = n*l+n*(n-1)/2;
  let a = (l..l+n).min_by_key(|x| x.abs()).unwrap();
  println!("{}", sum-a);
}

Measured memory_bytes: 2108
#include<stdio.h>
int main(void)
{
  int i,n,a,num[52]={};
  char b;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf(" %c",&b);
      scanf("%d",&a);

  switch(b)
    {
    case 'S':
  num[a-1]=a;
  break;
    case 'H':
      num[a+12]=a;
      break;
    case 'C':
      num[a+25]=a;
      break;
    case 'D':
      num[a+38]=a;
      break;
    }
    }
  for(i=0;i<52;i++)
    {
      if(num[i]==0)
	{
	  if(i<=12){
	    printf("S %d\n",i+1);}
	
	  else if(i<=25){
	    printf("H %d\n",i-12);}
	  else if(i<=38){
	  printf("C %d\n",i-25);}
	  else{
	  printf("D %d\n",i-38);}
	}
    }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
using namespace std;
int main(){
int a, b;
cin >> a >> b;
int diff;
diff = b - a;
int sum;
sum = 0;
for (int i=0; i<diff; i++){
sum = diff * (1+ diff);
sum /= 2;
sum -= b;
}
cout << sum << endl;
}

Measured memory_bytes: 256
/* #                          */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <functional>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/
int N;

void sol() {

}

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;

    int s1 = n * (n - 1) / 2;
    int s2 = m * (m - 1) / 2;
    cout << s1 + s2 << endl;
    return 0;
}

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

int main(){
 long L,R;
  cin >> L >> R;
  long long ans =2*1e+9;
  
  if(R-L>=2019){cout << "0" << endl;return 0;}
    for(long l=L;l<R;l++){
      for(long r=l+1;r<=R;r++){
        if(l<r&&ans>(l*r)%2019)ans=(l*r)%2019;
      }
    }
    cout << ans <<endl;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll A,B;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>A>>B;
    if((A-B)%2==0){
        cout<<(A+B)/2<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
#define ALL(x) (x).begin(),(x).end()

int main(){
	ll N, A, B;
	cin >> N >> A >> B;
	if((B - A) % 2 == 0) {
		cout << (B - A) / 2 << endl;
	} else {
		cout << min(A + (B - A - 1) / 2, N - B + 1 + (B - A - 1) / 2) << endl;
	}
}

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



int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(), h.end());
    ll ans = 0;
    rep(i,n-k) ans += h[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4836
T = int(input())
for i in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = input()
    base = []
    for i in range(1,N+1):
        temp = A[-i]
        for x in base:
            temp = min(temp,temp^x)
        if temp != 0:
            if S[-i] == '1':
                print('1')
                break
            else:
                base.append(temp)
    else:
        print('0')

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

int digsum(int x){
	int ret=0;
  while(x>0){
  ret+=x%10;
    x/=10;
  }
return ret;
  
}

int main(){
	int n;cin>>n;
  	int y=digsum(n);
  cout<<((n%y==0)?"Yes":"No")<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define loop(i, a, b) for(int i = a; i < b; i++)
#define pb push_back

const int maxn = 1e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define MAX 1002

char grid[MAX][MAX];
ull dp[MAX][MAX] = {};




int main()
{
	int h, w;
	fastIO;

	cin >> h >> w;
	loop(i, 0, h)
	loop(j, 0, w)
		cin >> grid[i][j];
	dp[0][0] = 0;
	if(grid[0][1] == '.')
		dp[0][1] = 1;
	if(grid[1][0] == '.')
		dp[1][0] = 1;

	loop(i, 0, h)
	loop(j, 0, w)
	{
		if(grid[i][j] == '.')
		{	
			if(grid[i - 1][j] == '.')
				dp[i][j] += (dp[i - 1][j]) % Mod;
			if(grid[i][j - 1] == '.')
				dp[i][j] = ((dp[i][j]) + (dp[i][j - 1])) % Mod;
		}
	}

	cout << dp[h - 1][w - 1];

	return 0;
}

Measured memory_bytes: 9088
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] arr = new long[n + 1];
		for (int i = 1; i <= n; i++) {
		    arr[i] = arr[i - 1] + sc.nextLong();
		}
		long total = arr[n];
		long min = Long.MAX_VALUE;
		for (int i = 1; i < n; i++) {
		    min = Math.min(min, Math.abs(arr[i] * 2 - total));
		}
		System.out.println(min);
   }
}



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

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

ll gcd(ll x, ll y){
	return y?gcd(y, x%y):x;
}

int main(){
	ll k,n;
	cin>>k>>n;
	cout<<min(k%n,abs(k%n-n))<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000
#define LL long long 
int Rank[20][MAX];
int arr[100000],cum[100000],lcp[100000];
struct Tuple
{
    int left,right,pos;
};
bool compare(const Tuple &a, const Tuple &b)
{
    return a.left == b.left ? a.right < b.right : a.left < b.left;
}
void counting_sort(Tuple t[] , int n)
{
    int count[MAX+9];
    Tuple temp[n + 9];
    memset(count , 0 , sizeof count);

    for(int i = 0 ;i < n ; i++)
        count[t[i].right + 1]++;

    for(int i = 1 ; i  < MAX ; i++)
        count[i] += count[i-1];

    for(int i = 0 ; i<n ; i++)
    {
        temp[count[t[i].right +1] - 1] = t[i];
        count[t[i].right + 1]--;
    }   

    memset(count , 0 , sizeof count);

    for(int i = 0 ; i < n ; i ++)
        count[t[i].left + 1] ++;

    for(int i = 1 ; i<MAX ; i++)
        count[i] += count[i-1];

    for(int i = n- 1; i>=0 ; i--)
    {
        t[count[temp[i].left + 1] - 1] = temp[i];
        count[temp[i].left + 1]--;
    }
}
void suffix_array(char s[],int n)
{

    for(int i=0;i<n;i++)
        Rank[0][i] = s[i] - 97;

    Tuple t[n+9];


    for(int stp = 1 , cnt = 1 ; (cnt>>1) < n ; cnt<<=1 , stp++)
    {
        for(int i=0;i<n;i++)
        {
            t[i].left = Rank[stp-1][i];
            t[i].right = i+cnt < n ? Rank[stp-1][i + cnt] : -1;
            t[i].pos = i;
        }
        //sort(t,t+n,compare);
        counting_sort(t , n);
        for(int i=0;i<n;i++)
            Rank[stp][t[i].pos] = i > 0 && t[i-1].left == t[i].left && t[i-1].right == t[i].right ? Rank[stp][t[i-1].pos] : i;
    }
    int pos = ceil(log(n)/log(2));
    for(int i = 0;i<n;i++)
        arr[Rank[pos][i]] = i;
}
void lcpArray(char s[],int n)
{
        int k=0,sum = 0;
        vector<int> rank(n,0);
        for(int i=0; i<n; i++) rank[arr[i]]=i;
                lcp[0] = 0;
        for(int i=0; i<n; i++, k?k--:0)
        {
                if(rank[i]==n-1) {k=0; continue;}
                int j=arr[rank[i]+1];
                while(i+k<n && j+k<n && s[i+k]==s[j+k]) k++ ;
                lcp[rank[i] + 1] = k;
        }
}
int main()
{
    char s[100000];
    scanf("%s",s);
    int  n = strlen(s);
    suffix_array(s,n);
    lcpArray(s , n);
    cum[0] = n - arr[0];
    for(int i = 1;i < n;i++){
        cum[i] = cum[i-1] + (n - arr[i] - lcp[i]);
    }
    int q=1;
    //scanf("%d",&q);
    while(q--)
    {
        int a ;
        scanf("%d",&a);
        int pos ;
        pos = lower_bound(cum , cum + n , a) - cum;
        int i , j;
        for(int j = 0 , i = arr[pos] ; j< a - cum[pos-1] + lcp[pos] ; j++,i++)
            printf("%c",s[i]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 7040
K = gets.to_i
count = 0
len = 0

def g(l)
    a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    loop{
        break if a[0].to_s.size >= l
        n = a.shift
        m = n % 10
        if m > 0
            a << n * 10 + m - 1
        end
        a << n  * 10 + m
        if m < 9
            a << n * 10 + m + 1
        end
    }
    a
end

loop{
    len += 1
    a = g(len)
    #warn a.inspect
    if a.size >= K - count
        #warn K - count
        puts a[K - count - 1]
        break
    end
    count += a.size
}


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

int main(){
    int m;
    cin>>m;
    int n;
    cin>>n;
    int arr[n];
    long long int ans=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        ans=ans+arr[i];
    }
    if(ans>m){
        cout<<"-1";
    }else{
        cout<<m-ans;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

struct mint{
    ll x;
    mint():x(0){}
    mint(ll x):x((x%MOD+MOD)%MOD){}
    mint operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
    mint operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
    mint operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
    mint operator+(const mint& a)const{ return mint(*this) += a;}
    mint operator-(const mint& a)const{ return mint(*this) -= a;}
    mint operator*(const mint& a)const{ return mint(*this) *= a;}
    bool operator==(const mint& a)const{ return x == a.x;}
};


mint dp[101][101][256];

void mainmain(){
	int n;
	cin>>n;
	int K;
	cin>>K;
	vint a(n);
	rep(i,n) cin>>a[i];
	sort(ALL(a));
	dp[0][0][0].x = 1;
	rep(i,n){
		rep(j,i+1){
			rep(k,256){
				dp[i+1][j][k] += dp[i][j][k];
				dp[i+1][j+1][k^a[i]] += dp[i][j][k];
			}
		}
	}
	mint f(1);
	mint ans(0);
	rep(i,n){
		f *= mint(i+1);
		ans += f*dp[n][i+1][K];
	}
	cout << ans.x << endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 21244
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <cstdio>

using namespace std;

int main()
{
	int n;

	cin >> n;

	string str;
	
	str = std::to_string(n);

	bool flg = false;

	for (int i = 0; i < 3; ++i)
	{
		if (str[i] == '7')
		{
			flg = true;
			break;
		}
	}

	if (flg)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3692
import std.stdio : readln, writeln, writefln;
import std.array : array, split;
import std.conv  : to;
import std.range.primitives;
import std.range : enumerate, iota, repeat, retro, assumeSorted;
import std.algorithm.searching  : all, any, canFind, count, countUntil;
import std.algorithm.comparison : max, min, clamp;
import std.algorithm.iteration  : each, group, filter, map, reduce, permutations, sum, uniq;
import std.algorithm.sorting    : sort;
import std.algorithm.mutation   : reverse, swap;

void main() {
    string s;
    scan(s);

    writeln("2018", s[4 .. $]);
    
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.array : split;
    import std.conv  : to;
    import std.range.primitives;

    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

typedef long long ll;

#define F first 
#define S second 
#define PB push_back
#define MP make_pair 
#define rep(i,a,b) for (ll i=a;i<b;i++)

typedef vector<int> vi;
typedef pair<int,int> pi;


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

    cout<<n*n<<endl; 

    return 0; 
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(void) {
    char c;
    cin >> c;

    if (c == 'A') cout << "T" << endl;
    if (c == 'T') cout << "A" << endl;
    if (c == 'C') cout << "G" << endl;
    if (c == 'G') cout << "C" << endl;

    return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b){
    if(b != c){
      cout << "Yes" << endl;
      return 0;
    }
  }else{
    if(b == c){
      cout << "Yes" << endl;
      return 0;
    }
    if(a == c){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <climits>
#include <cmath>
#define lli long long int
#define M 1000000007
using namespace std ;

int eval(vector<vector<char> > &grid, vector<vector<lli> > &dp, int x,int y,int m,int n)
{
	if(x == m && y == n) return 1 ;
	if(x >= grid.size() || y >= grid[0].size() || grid[x][y] == '#') return 0 ;

	if(dp[x][y] != -1) return dp[x][y] ;

	return dp[x][y] = (eval(grid,dp,x+1,y,m,n) + eval(grid,dp,x,y+1,m,n)) % M ; 
}

int main(int argc, char const *argv[])
{
	int h,w; 
	cin>>h>>w ;

	vector<vector<char> > grid(h,vector<char> (w)) ;
	vector<vector<lli> > dp(h,vector<lli>(w,-1)) ;

	for(int i = 0 ; i < h; i++)
		for(int j = 0 ; j < w; j++)
			cin>>grid[i][j] ;

	cout<<eval(grid,dp,0,0,h-1,w-1)<<endl ;

	return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#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,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d) ? "Yes" : "No") << endl;
	return 0;
}
 

Measured memory_bytes: 256
N=gets.to_i
h=Hash.new(0)
N.times do
  s = gets.chomp
  h[s[0]] += 1 if s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H'
end

ans = 0
h.values.combination(3) do |l,m,n|
  ans += l*m*n
end
puts ans


Measured memory_bytes: 1788
from functools import lru_cache
import sys

sys.setrecursionlimit(1000000)

A,B,C,D,E,F = map(int,input().split())
# (water,sugar)
E2 = 100 * E / (100 + E)

@lru_cache(maxsize=10000)
def dfs(w,s):
    global A,B,C,D,E,F
    #print('dfs',w,s)
    inf = 1 << 60
    if w + s > F:
        return (-1, w, s)
    if w + s == 0:
        d = (-1, w, s)
    else:
        d = ((100 * s) / (w + s), w, s)
    #print(d)
    d1 = dfs(w + 100*A, s)
    if d1[0] <= E2:
        d = max(d, d1)
    d1 = dfs(w + 100*B, s)
    if d1[0] <= E2:
        d = max(d, d1)
    d1 = dfs(w, s + C)
    if d1[0] <= E2:
        d = max(d, d1)
    d1 = dfs(w, s + D)
    if d1[0] <= E2:
        d = max(d, d1)

    return d

ans = dfs(0,0)
print(ans[1]+ans[2],ans[2])


Measured memory_bytes: 77272
#include<iostream>

using namespace std;

int main(){
    
    int a,b;
    cin >> a >> b;
    int matrix[a][b] = {0};
    int vector[b]    = {0};
    
    for(int i=0; i<a; ++i){
        for(int j=0; j<b; ++j){
            cin >> matrix[i][j]; 
        }
    }
    
    for(int j=0; j<b; ++j){
        cin >> vector[j];
    }
    
    int num = 0;
    
    for(int i=0; i<a; ++i){
        num = 0;
        for(int j=0; j<b; ++j){
            num += matrix[i][j] * vector[j];
        }
        cout << num << endl;
    }
    
    return 0;

}


Measured memory_bytes: 3116
n, m, c = gets.split.map(&:to_i)
bs = gets.split(nil, m).map(&:to_i)
results = n.times.map do
  as = gets.split(nil, m).map(&:to_i)
  (0..m-1).map {|i| as[i] * bs[i]}.inject(:+) + c > 0
end

puts results.count(true)


Measured memory_bytes: 1788
#include<iostream>
#include<cstring>
int main(void)
{
  using namespace std;
  int k;
  string s;
  cin >> k;
  cin >> s;
  
  if(k >= s.size())
  {
    cout << s;
  }
  else 
  {
    for(int i = 0; i < k; i++) cout << s[i];
    cout << "...";
  }
  
  return 0;  
}

Measured memory_bytes: 3624
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut a: Vec<usize> = a;
    let mut alice_score = 0;
    let mut bob_score = 0;

    a.sort();
    a.reverse();

    for (i, num) in a.iter().enumerate() {
        if i % 2 == 0 {
            alice_score += *num;
        } else {
            bob_score += *num;
        }
    }

    println!("{}", alice_score - bob_score);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll N, K;
    cin >> N >> K;

    ll l = 0;
    ll r = K + 1;

    while(l + 1 < r){
        ll m = (l + r) / 2;
        ll now = m;
        ll sum = 0;
        for(ll i = 0; i < N; i++){
            if(now == 0)break;
            sum += now;
            now /= 2;
        }
        if(sum <= K) l = m;
        else r = m;
    }

    cout << l << endl;
    return 0;
}
 
 



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  string N; cin >> N;
  auto ans = N.find('7') != N.npos;
  cout << (ans ? "Yes" : "No") << CRLF;
  return;
}

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

  gErr = 0;

  solve();

  return gErr;
}


Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>
#define FOR(arg, ini, end) for(int arg = ini; arg < end; arg++)


using namespace std;

int main(int argc, const char * argv[]) {
    
    int h, w, n;
    cin >> h >> w >> n;

    map<pair<int, int>, unsigned long> m;
    #if 0
    FOR(i, 0, h-2){
        FOR(j, 0, w-2){
            m[make_pair(i, j)] = 0;
        }
    }
    #endif

    FOR(i, 0, n) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        FOR(r, 0, 3) {
            FOR(c, 0, 3) {
                int nr = a-2+r, nc = b-2+c;
                if ( nr<h-2 && nc<w-2 && 0<=nr && 0<=nc){
                    m[make_pair(nr, nc)]++;
                }
            }
        }
    }

    unsigned long c[10]={0};
    for(map<pair<int, int>, unsigned long>::iterator it = m.begin(), itEnd=m.end(); it!=itEnd; it++){
        // cout << (*it).first.first << " " << (*it).first.second << ":" << (*it).second << endl;
        c[(*it).second]++;
    }
    unsigned long cn = (unsigned long)(h-2)*(unsigned long)(w-2);
    FOR(i, 0, 10) {
        cn -= c[i];
    }
    c[0] = cn;

    FOR(i, 0, 10) {
        cout << c[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
 
template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N,Q; cin >> N>>Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21724
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int n;
int x[111111];
int l,q;
int a[111111];
int b[111111];

int e[111111][33];
int main(void){
  scanf("%d",&n);
  for(int i = 0; i < n; i++){
    scanf("%d",x+i);
  }
  x[n] = x[n-1]+1;
  x[n+1] = 1111111111;

  scanf("%d %d",&l,&q);
  for(int i = 0; i < q; i++){
    scanf("%d %d",a+i,b+i);
    a[i]--;b[i]--;
    if(a[i] > b[i]) swap(a[i],b[i]);
  }

  for(int i = 0; i < n; i++){
    e[i][0] = i;
    e[i][1] = (upper_bound(x,x+n+2,x[i]+l)-x-1);
  }
  e[n][0] = n;
  e[n][1] = n;
  e[n+1][0] = n+1;
  e[n+1][1] = n+1;

  for(int k = 2; k < 33; k++){
    for(int i = 0; i <= n+1; i++){
      e[i][k] = e[e[i][k-1]][k-1];
    }
  }

  /*
  for(int k = 0; k < 33; k++){
    for(int i = 0; i <= n; i++){
      printf("%3d ",e[i][k]);
    }
    puts("");
  }
  //*/

  for(int i = 0; i < q; i++){
    int ans = 0;
    int np = a[i];
    while(1){
      if(e[np][1] >= b[i]){
	ans++;
	break;
      }

      int *p = (upper_bound(e[np],e[np]+33,b[i])-1);
      ans += 1<<(p-e[np]-1);
      if(b[i] == *p) break;

      if(np > *p){
	//cout << "aa " << np << " " << *p << endl;
      }
      np = *p;
     
    }
    printf("%d\n",ans);
  }
}


Measured memory_bytes: 14848
#include <iostream>
#include <vector>
#include <string>
#define ll long long
#define MOD 1000000007
#define MAX 10000000
using namespace std;

vector<int> white(MAX);
vector<int> black(MAX);
int main(){
  int n,k; cin >> n >> k;
  string s; cin >> s;
  int w=0,b=0;
  for(int i=0;i<n;i++){
    if(s[i]=='0'){
      white[w]++;
      if(black[b]!=0) b++;
    }
    else{
      black[b]++;
      if(white[w]!=0) w++;
    }
  }
  int res=0;
  for(int i=0;i<k;i++){
    res+=white[i];
    res+=black[i];
  }
  if(s[0]!='0'){
    res+=black[k];
    int ans = res;
    for(int i=0;i<n;i++){
     res += black[i+k+1] + white[i+k] - black[i] - white[i];
     ans = max(ans,res);
    }
    cout << ans;
  }else{
    int ans = res;
    res=res+white[k]+black[k]-white[0];
    ans = max(ans,res);
    for(int i=0;i<n;i++){
      res += black[i+k+1]+white[i+k+1]-white[i+1]-black[i];
      ans = max(ans,res);
    }
    cout << ans;
  }
  return 0;
}

Measured memory_bytes: 78592
#include <iostream>

using namespace std;

int main()
{
  int N,L;
  cin >> N >> L;
  int S = 0;

  int r = 0;
  if( L>0 )
    r = 1;
  else
    r = min((-L)+1, N);
  for(int i=1;i<N+1;i++)
    {
      if( i == r )
	continue;
      S += L+i-1;
    }
      
  cout << S << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

//ll mod = 1000000007;
ll mod = 998244353;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

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

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}

vector<pair<ll, ll>> prime_factorize(ll N) {
	vector<pair<ll,ll>> res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0; 
		while (N % a == 0) {
			++ex;
			N /= a;
		}
		res.push_back({ a, ex });
	}
	if (N != 1) res.push_back({ N, 1 });
	return res;
}


int main() {
	int n, k;
	cin >> n >> k;
	vector<int> value(n);
	for (int i = 0; i < n; i++) {
		cin >> value[i];
	}
	sort(value.begin(), value.end());
	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans += value[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
n = int(input())
s = list(input())
s = list(map(lambda x : ord(x)+n, s))
for i in range(len(s)):
    if s[i] >= 91:
        s[i] = s[i] - 26
    else:
        pass
s = list(map(lambda x : chr(x), s))
t = ''.join(s)
print(t)


Measured memory_bytes: 3188