akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{
    class Program
    {
        

        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            
            var vals = Console.ReadLine().Split(' ').
                Select(x => long.Parse(x)).ToList();
            var N = vals[0];

            
            


            Console.WriteLine((1000-N%1000)%1000);
            Console.Out.Flush();
        }
        




    }
}




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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    
    int n; 
    cin >> n;
    
    
    int digit = n % 10;
    
    if(digit == 2 || digit == 4 || digit == 5 || digit == 7 || digit == 9){
        cout << "hon" << "\n";
        
    }
    else if( digit == 0 || digit == 1 || digit == 6 || digit == 8){
        cout << "pon" << "\n";
    }
    else{
        cout << "bon" << "\n";
    }
    return 0;
}

Measured memory_bytes: 3644
import fractions


def lcm(x, y):
    return int((x * y) // fractions.gcd(x, y))

n, m = [int(i) for i in input().split()]
s = input()
t = input()

span = fractions.gcd(n, m)
for i in range(span):
    if s[int(n/span)*i] != t[int(m/span)*i]:
        print("-1")
        exit()
print(lcm(n, m))

Measured memory_bytes: 5852
# C - Energy Drink Collector
# https://atcoder.jp/contests/abc121/tasks/abc121_c

n, m = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]

AB.sort()

drink = 0
ans = 0
for a, b in AB:
  num = min(m - drink, b)
  m -= num
  ans += a * num
  if m == 0:
    break

print(ans)

Measured memory_bytes: 27880
#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 FOR(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 vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#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*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    int n,neg=0;
    cin >> n;
    vint a(n);
    rep(i,n){
        cin >> a[i];
        if(a[i]<0) neg++;
    }

    int res=0;
    if(neg%2==0){
        rep(i,n){
            res+=abs(a[i]);
        }
        cout<<res<<endl;
    }else{
        int min=INF;
        rep(i,n){
            res+=abs(a[i]);
            chmin(min,abs(a[i]));
        }
        //cout<<res<<endl;
        //cout<<min<<endl;
        cout<<res-min*2<<endl;
    }
}

Measured memory_bytes: 3916
/*********************
*@Author:   CKang *
*@Language: C++11    *
*********************/
#include<bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
//#define DEBUG
#define RI register int
#define endl "\n"

using namespace std;

typedef long long ll;
//typedef __int128 lll;
//const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-9;
const int INF = 0x3fffffff;
const ll LINF = 0x3fffffffffffffff;

inline ll read(){
    long long x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

void solve(){
    string s;
    cin>>s;
    if(s=="ABC")
        puts("ARC");
    else
        puts("ABC");
    return ;
}

int main()
{
#ifdef DEBUG
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout)
#endif
    //cout.tie(0);
    //for(ll t=read();t;t--)
        solve();
#ifdef DEBUG
    printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Fuck You !" << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n, m, u[2005], v[2005];
vector<int> T[2005];
int par[2005][2005];
int occ[2005][2005];
vector<int> hv[2005][2005];
vector<int> cur;
int dep[2005][2005];

void dfs(int cv, int rt)
{
	rep(i, T[cv].size()) {
		int nv = T[cv][i];
		if(nv == par[rt][cv]) continue;
		par[rt][nv] = cv;
		dep[rt][nv] = dep[rt][cv] + 1;
		dfs(nv, rt);
	}
}

int find_v(int cu, int cv)
{
	return occ[cu][cv];
}

void gen_path(int cu, int cv, int tv)
{
	if(occ[cu][cv] != -1) return;
	if(cv != tv) {
		occ[cu][cv] = tv;
		rep(i, hv[cu][cv].size()) cur.push_back(hv[cu][cv][i]);
		hv[cu][cv].clear();
		hv[cv][cu].clear();
	}
	rep(i, T[cv].size()) {
		int nv = T[cv][i];
		if(nv == par[cu][cv]) continue;
		gen_path(cu, nv, tv);
	}
}

vector<int> G[2005];
bool vis[2005];

int gen_tot(int v)
{
	vis[v] = true;
	int ret = 1;
	rep(i, G[v].size())
	if(!vis[G[v][i]]) ret += gen_tot(G[v][i]);
	return ret;
}

int main()
{
	scanf("%d%d", &n, &m);
	rep(i, n - 1) {
		int eu, ev;
		scanf("%d%d", &eu, &ev);
		T[eu].push_back(ev);
		T[ev].push_back(eu); 
	}
	rep(i, m) scanf("%d%d", &u[i], &v[i]);
	
	rep1(i, n) {
		par[i][i] = -1;
		dep[i][i] = 0;
		dfs(i, i);
	}
	
	queue<int> que;
	rep(i, m) que.push(i);
	
	memset(occ, -1, sizeof(occ));
	
	while(!que.empty()) {
		int ce = que.front();
		que.pop();
		if(u[ce] == v[ce]) continue;
		int cw = find_v(u[ce], v[ce]);
		if(cw != -1) {
			u[ce] = cw;
			que.push(ce);
			continue;
		}
		cw = find_v(v[ce], u[ce]);
		if(cw != -1) {
			v[ce] = cw;
			que.push(ce);
			continue;
		}
		cur.clear();
		gen_path(u[ce], v[ce], v[ce]);
		rep(i, cur.size()) {
			if(u[cur[i]] == u[ce]) u[cur[i]] = v[ce];
			else v[cur[i]] = v[ce];
			que.push(cur[i]);
		}
		cur.clear();
		gen_path(v[ce], u[ce], u[ce]);
		rep(i, cur.size()) {
			if(u[cur[i]] == v[ce]) u[cur[i]] = u[ce];
			else v[cur[i]] = u[ce];
			que.push(cur[i]);
		}
		hv[u[ce]][v[ce]].push_back(ce);
		hv[v[ce]][u[ce]].push_back(ce);
	}
	
	int ans = 0;
	rep1(i, n) {
		rep1(j, n) G[j].clear();
		rep(j, m) if(dep[i][u[j]] - dep[i][v[j]] == dep[u[j]][v[j]]) G[v[j]].push_back(u[j]);
		else if(dep[i][v[j]] - dep[i][u[j]] == dep[v[j]][u[j]]) G[u[j]].push_back(v[j]);
		rep1(j, n) vis[j] = false;
 		ans += gen_tot(i) - 1;
	}
	printf("%d\n", ans / 2);
	return 0;
}

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

public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		List<Sp> spl = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			spl.add(new Sp(i+1, next(), ni()));
		}
		Comparator<Sp> comparator = Comparator.comparing(Sp::getS).reversed().thenComparing(Sp::getP).reversed();
		spl.sort(comparator);
		spl.stream().forEach(sp -> System.out.println(sp.getIdx()));
	}
	
	static class Sp {
		private int idx;
		private String s;
		private int p;
		public Sp(int idx, String s, int p) {
			this.idx = idx;
			this.s = s;
			this.p = p;
		}
		public int getIdx() {
			return this.idx;
		}
		public String getS() {
			return this.s;
		}
		public int getP() {
			return this.p;
		}
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 26708
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define INF 2000'000'000

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n, k, ans = 2e9;

bool valid(int mid, vector < int > & v){
	int steps = 0;
	for(int i : v){
		steps += (i + mid-1) / mid - 1;
		if(steps > k)
			return false;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	//freopen("in", "r", stdin);
	cin >> n >> k;
	vector < int > v(n);
	for(int & i : v)
		cin >> i;
		
	for(int low = 1, high = 1000'000'000;  low <= high; ){
		int mid = (low + high) / 2;
		if(valid(mid, v))
			high = mid-1, ans = mid;
		else
			low = mid + 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3960
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
p=list(map(float,input().split()))

dp=[defaultdict(float) for i in range(n)]

dp[0][1]=p[0]
dp[0][-1]=1-p[0]
# print(dp)
for i in range(n-1):
    for j in range(-i-1,i+2):
        # print(i,j)
        if j==0:
            dp[i+1][1]+=dp[i][0]*p[i+1]
            dp[i+1][-1]+=dp[i][0]*(1-p[i+1])
        else:
            dp[i+1][j+1]+=dp[i][j]*p[i+1]
            dp[i+1][j-1]+=dp[i][j]*(1-p[i+1])
ans=0.0
for i in range(n):
    ans+=dp[-1][i+1]
# print(dp)
# print(dp[0])
# print(dp[-1])
print(ans)

Measured memory_bytes: 803872
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = new String[3];
        for (int i = 0 ; i < 3 ; i++) {
            s[i] = sc.next();
        }
        String ans = "";
        ans += s[0].substring(0, 1) + s[1].substring(1, 2) + s[2].substring(2, 3);
        System.out.println(ans);
    }

}

Measured memory_bytes: 22740
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32


def solve(N: int):
    print(str(N).count('2'))
    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
    solve(N)

if __name__ == '__main__':
    main()


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

#define INF 999999;

int main(){
    
    
    int N;
    string S;
    
    cin >> N;
    cin >> S;
    int ans = INF;
    int count_r = 0;//右にある白い石の個数
    int count_l = 0;//左にある黒い石の個数

    for(int i=0; i<N; i++){
        if(S[i] == '.')count_r++;
    }
    ans = min(ans, count_r);
    
    for(int i=0; i<N; i++){
        if(S[i] == '#'){
            count_l++;
        }else{
            count_r--;
        }
        ans = min(ans, count_r + count_l);
    }
    
    cout << ans << endl;
    
    return 0;
    
}


Measured memory_bytes: 640
import collections
S = list(input())
Q = int(input())

ans = collections.deque(S)
rev = False

for _ in range(Q):
    query = input().split()
    if query[0] == '1':
        rev = not rev
    else:
        if query[1] == '1':
            if rev:
                ans.append(query[2])
            else:
                ans.appendleft(query[2])
        else:
            if rev:
                ans.appendleft(query[2])
            else:
                ans.append(query[2])

if rev:
    print("".join(reversed(ans)))
else:
    print("".join(ans))


Measured memory_bytes: 79992
import fractions

A, B, C, D = map(int, input().split())


def baisuu(suuji, shita, ue):
    saishou, shouamari = divmod(shita, suuji)
    saidai, daiamari = divmod(ue, suuji)
    ans = saidai - saishou
    if shouamari == 0:
        ans += 1
    return ans


cbai = baisuu(C, A, B)
dbai = baisuu(D, A, B)
koubai = C * D // fractions.gcd(C, D)
koubaibai = baisuu(koubai, A, B)

print(B - A + 1 - cbai - dbai + koubaibai)


Measured memory_bytes: 5588
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, i;
   cin >> n >> i;
   cout << n-i+1 << endl;
   return 0;
}


Measured memory_bytes: 256
//writer: Sakura
//name: Partition

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=m/n;i>0;i--){
		if(m%i==0){
			printf("%d\n",i);
			exit(0);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
typedef long long ll;
using namespace std;
const int MOD=1e9+7;
int a;

int main(void) {
	cin >> a;
	int x[4];
	x[3] = a % 10; a /= 10; x[2] = a % 10; a /= 10;
	x[1] = a % 10; a /= 10; x[0] = a % 10; a /= 10;

	for (int i = 0; i < 8; i++) {
		int sum = x[0];

		for (int j = 0; j < 3; j++) {
			if (i & (1 << j))sum += x[j + 1];
			else sum -= x[j + 1];
		}
		if (sum == 7) {
			cout << x[0];
			for (int j = 0; j < 3; j++) {
				if (i & 1 << j)cout << "+" << x[j + 1];
				else cout << "-" << x[j + 1];
			}
			cout<<"=7" << endl;
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    int N;
    cin >> N;
    string s,t;
    cin >> s >> t;
    rep(i,N) cout << s.at(i) << t.at(i);
    return 0;
}


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

int main(){
  int debt=100000, n;
  cin >> n;
  for(int i=0;i<n;i++){
    debt += debt*(5.0/100.0);
    if(debt%1000!=0){
      debt=(debt/1000)*1000+1000;
    }
  }
  if(debt%1000!=0){
      debt=(debt/1000)*1000+1000;
  }
  cout << debt << endl;
  return 0;}

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

int dx[4] = {0,-1,1,0};
int dy[4] = {-1,0,0,1};
int w,h,c,ans,color_cnt;

int colorConut(const vector<vector<int> >& a){
	int s=0;
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			if( a[y][x] == -1 ) s++;
		}
	}
	return s;
}

void change(vector<vector<int> >& a, int x, int y, int prev_c, int next_c){
	for(int i=0 ; i < 4 ; i++ ){
		int mx = x + dx[i];
		int my = y + dy[i];
		if( mx < 0 || my < 0 || mx >= w || my >= h ) continue;
		if( a[my][mx] == prev_c ){
			a[my][mx] = next_c;
			change( a , mx , my , prev_c , next_c );
		}
	}
}

void solve(const vector<vector<int> >& a, int cnt){
	if( cnt == 6 ){
		vector<vector<int> > b = a;
		b[0][0] = -1;
		change( b , 0 , 0 , c , -1 );
		ans = max( ans , colorConut(b) );
	}else{
		for(int i=1 ; i <= 6 ; i++ ){
			vector<vector<int> > b = a;
			if( a[0][0] == i ) continue;
			b[0][0] = i;
			change( b , 0 , 0 , a[0][0] , i );
			solve( b , cnt+1 );
		}
	}
}

int main(){
	while( cin >> h >> w >> c , h || w || c ){
		vector<vector<int> > a;
		for(int y=0 ; y < h ; y++ ){
			vector<int> v;
			for(int x=0 ; x < w ; x++ ){
				int e;
				cin >> e;
				v.push_back( e );
			}
			a.push_back( v );
		}
		ans = 0;
		solve( a , 1 );
		cout << ans << endl;
	}
}

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

using namespace std;
const int N=500+10;
int a[N][N],h,w,cnt;
int ans[N*N][4];

int main()
{
    cin>>h>>w;
    cnt=0;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=h-1;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(a[i][j]%2!=0)
            {
                a[i][j]--;
                a[i+1][j]++;
                cnt++;
                ans[cnt][0]=i;
                ans[cnt][1]=j;
                ans[cnt][2]=i+1;
                ans[cnt][3]=j;

            }
        }
    }
    for(int j=1;j<=w-1;j++)
    {
        if(a[h][j]%2!=0)
        {
            a[h][j]--;
            a[h][j+1]++;
            cnt++;
            ans[cnt][0]=h;
            ans[cnt][1]=j;
            ans[cnt][2]=h;
            ans[cnt][3]=j+1;


        }
    }
    cout<<cnt<<endl;
    for(int i=1;i<=cnt;i++)
    {
        cout<<ans[i][0]<<' '<<ans[i][1]<<' '<<ans[i][2]<<' '<<ans[i][3]<<endl;
    }
    return 0;
}


Measured memory_bytes: 7040
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll Q;
    cin >> Q;
    string pre = "";
    string suf = "";
    bool dir = true;
    REP(i, 0, Q) {
        ll t;
        cin >> t;
        if (t == 1) {
            dir = !dir;
        } else {
            ll f;
            string c;
            cin >> f >> c;
            if (f == 1) {
                if (dir) {
                    pre = c + pre;
                } else {
                    suf = suf + c;
                }
            } else {
                if (dir) {
                    suf = suf + c;
                } else {
                    pre = c + pre;
                }
            }
        }
    }
    string ans = pre + S + suf;
    if (!dir) {
        reverse(ans.begin(), ans.end());
    }
    cout << ans << endl;
}


Measured memory_bytes: 1388
import java.util.Scanner;
public class Main{
public static void main(String srg[]){
	Scanner scan = new Scanner(System.in);
    int a=scan.nextInt();
	
    int b=10;
  	int count=0;
  	for(int i=0;i<4;i++){
      
      int c =a%b;
      if(c==2)count++;
      a=a/10;
    }
  
    System.out.println(count);
    scan.close();
}
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 30; ++i) {
    for (int j = 0; j < 30; ++j) {
      if (4 * i + j * 7 == n) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <tuple>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }
template<typename V> void printVec(V v) {ll i=0;for(auto x : v){std::cout << " [" << i++ << "] " << x;} print();}


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

  ll D, G;
  std::cin >> D >> G;

  std::vector< std::pair<ll, ll> > vp(D);
  std::vector< ll > vsum(D, 0LL);
  for (ll i = 0; i < D; i++) {
    std::cin >> vp[i].first >> vp[i].second;
    vsum[i] = vp[i].first * (i+1) * 100 + vp[i].second;
  }

  ll ans = INF;
  for (ll S = 0; S < std::pow(2, D); S++) {
    ll cnt = 0;
    ll residual = G;
    ll state = S;
    std::vector< bool > is_use(D, false);
    for (ll i = 0; i < D; i++) {
      if (state % 2 == 1) {
	cnt += vp[i].first;
	residual -= vsum[i];
	is_use[i] = true;
      }
      state /= 2;
    }

    for (ll i = D-1; i >= 0; i--) {
      if (residual <= 0) break;
      if (is_use[i]) continue;
      ll score = (i+1) * 100;
      ll num = std::min((residual + score - 1) / score, vp[i].first - 1);
      residual -= num * score;
      cnt += num;
    }
    if (residual <= 0) ans = std::min(ans, cnt);
  }

  print(ans);
  return 0;
}


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

int main(){
	int n;
	cin>>n;
	vector<int> b(n-1);
	for (int i = 0; i < n-1; i++) {
		cin>>b[i];
	}
	int ans=0;
	ans+=b[0]+b[n-2];
	for (int i = 0; i < n-2; i++) {
		ans+=min(b[i],b[i+1]);
	}
	cout<<ans<<endl;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    string S, T;
    cin >> S >> T;

    ll n = (ll)S.size();
    vector<Vi> pos(26);
    for (ll i = 0; i < n; i++) {
        pos[S[i] - 'a'].emplace_back(i);
    }

    bool ok = true;
    ll cur = -1;
    for (const auto& c : T) {
        ll a = c - 'a';
        ll b = cur / n;
        ll p = cur % n;

        if (pos[a].size() == 0) {
            ok = false;
            break;
        }

        ll idx = upper_bound(pos[a].begin(), pos[a].end(), p) - pos[a].begin();

        if (idx < (ll)pos[a].size()) {
            p = pos[a][idx];
        }
        else {
            ++b;
            p = pos[a][0];
        }

        cur = b * n + p;
    }

    if (ok)
        cout << cur + 1 << "\n";
    else
        cout << -1 << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

string s;
int res = 0;
int main(){
    cin >> s;
    int i = 0,j = s.size()-1;
    while(i < j){
        if(s[i] != s[j]) {res += 1;i++;j--;}
        else{
            i++;
            j--;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
import Data.Functor((<$>))

main :: IO ()
main = do 
        q  <- read.last.words <$> getLine
        xs <- map ((\[n, t] -> (n, read t)).words).lines <$> getContents
        mapM_ (putStrLn.(\(n, t) -> unwords [n, show t])) $ solve xs [] [] q 0

solve :: [(String, Int)] -> [(String, Int)] -> [(String, Int)] -> Int -> Int -> [(String, Int)]
solve []            [] zs _ _   = reverse zs
solve []            ys zs q cnt = solve (reverse ys) [] zs q cnt
solve ((n, t) : xs) ys zs q cnt = let t'   = t - q
                                      cnt' = cnt + q
                                      m    = cnt' + t'
                                  in if t' > 0 then solve xs ((n, t') : ys) zs q cnt'
                                               else solve xs ys  ((n, m) : zs) q m

Measured memory_bytes: 35268
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int N;
    bool flag = false;
    cin >> N;
    for(int i=1; i<50001; i++) {
        if((int) ((double) i * 1.08) == N) {
            flag = true;
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;


	return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        var n = Console.ReadLine();
        Console.WriteLine(Console.ReadLine().Split().Select(x => int.Parse(x)).OrderByDescending(x => x).Where((co, index) => index % 2 != 0).Sum());
    }
} 

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

using namespace std;
#define pi 3.14159265

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, l = 0;
	long long N, A[200000] = { 0 }, b[210000] = { 0 };
	cin >> N;
	for (i=0; i < N; i++) {
		cin >> A[i];
		b[i + 1] = b[i] + A[i];
		if (b[i + 1] == 0)ans++;
	}

	sort(b + 1, b + N + 1);
	j = 1;
	for (i = 1; i < N; i++) {
		if (b[i] == b[i + 1])j++;
		else {
			ans += j*(j - 1) / 2;
			j = 1;
		}
	}
	if(j!=1)
		ans += j*(j - 1) / 2;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3456
n = int(input())
s = {}

for i in range(n):
    t = input()
    if t not in s:
        s[t] = 1
    else:
        s[t] += 1

s = sorted(s.items(), key=lambda x:x[1], reverse=True)

cnt = s[0][1]
ans = []
for i in range(len(s)):
    if s[i][1] == cnt:
        ans += [s[i][0]]
    else:
        break

ans.sort()
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 111064
from collections import Counter
from itertools import accumulate
n = int(input())
a = list(map(int,input().split()))
ac = list(accumulate(a))
cac = Counter(ac)
ans = 0
cac[0] += 1
for i in cac.values():
    ans += (i * (i-1)) // 2
print(ans)

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

int64_t Euclid(int64_t a, int64_t b){
  if(a < b){
    swap(a,b);
  }
  int64_t r = a%b;
  while(r != 0){
    a = b;
    b = r;
    r = a %b;
  }
  return b;
}

int main(){
  int64_t A, B;
  cin >> A >> B;
  int64_t x = Euclid(A,B);
  cout << x * (A/x) * (B/x) << endl;
}
  

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

ll mod_pow(ll n, ll p, ll mod){
    n %= mod;
    if(p==0) return 1;
    ll res = mod_pow(n*n%mod, p/2, mod);
    if(p%2==1) res = res * n % mod;
    return res;
}

struct combination {
    combination(ll Nmax, ll mod){
        (this -> MOD) = mod;
        (this -> Nmax) = Nmax;
        factorial.resize(Nmax+1, 1);
        inverse_factorial.resize(Nmax+1, 1);
        init_factorial();
    }

    ll calc(ll n, ll r){
        ll ret = (factorial[n]*inverse_factorial[r])%MOD;
        ret = (ret*inverse_factorial[n-r])%MOD;
        return ret;
    }

    private:
        ll MOD, Nmax;
        vector<ll> factorial;
        vector<ll> inverse_factorial;

        void init_factorial(){
            for(ll i=1; i<=Nmax; i++){
                factorial[i] = (factorial[i-1] * i)%MOD;
            }
            inverse_factorial[Nmax] = mod_pow(factorial[Nmax], MOD-2, MOD);
            for(ll i=Nmax-1; i>=1; i--){
                inverse_factorial[i] = (inverse_factorial[i+1]*(i+1))%MOD;
            }
        }
};

int main(){
    int r1, c1, r2, c2;  cin >> r1 >> c1 >> r2 >> c2;
    ll mod = 1e9 + 7;
    combination comb = combination(r2+c2+50, mod);
    ll ans = 0;
    for(int r=r1; r<=r2; r++){
        ll temp = ((c2+1)*comb.calc(c2+r+1, c2+1))%mod;
        temp %= mod;
        temp -= (c1 * comb.calc(c1+r, c1))%mod;
        while(temp<0)
            temp += mod;
        temp %= mod;
        temp *= mod_pow(r+1, mod-2, mod);
        temp %= mod;
        ans += temp;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
#define  fi first
#define  se second 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int dx[4]={-1,0,1,0}, dy[4]={0,-1,0,1} ,INF=1e9+9;


int main()
{
    li n,k,ma=INF;
    cin>>n>>k;    
    for(int i=1;i<=n;i++) if(pow(2,i)+k*(n-i)<ma)ma=pow(2,i)+k*(n-i);
    cout<<ma<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    string s;

    while (getline(cin, s)) {
        for (int i = 0; i < s.size(); i++) {
            if (s[i] >= 'a' && s[i] <= 'z') {
                s[i] = s[i] - ' ';
            }
        }

        cout << s << endl;
    }

    return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N, C;
  C = 0;
  cin >> N;
 vector<int> V(N);
 vector<int> W(N);
 for(int i = 0; i < N; i++){
   cin >> V.at(i);
   cin >> W.at(i);
 }
 for(int i = 0; i < (N - 2); i++){
   if(V.at(i) == W.at(i) && V.at(i+1) == W.at(i+1) && V.at(i+2) == W.at(i+2)){
     C++;
   }
 }
  if(C > 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3616
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,k = LI()
    a = LI()
    r = [0] * (k+1)
    for i in range(1,k+1):
        f = False
        for c in a:
            if c > i:
                break
            if r[i-c] == 0:
                f = True
                break
        if f:
            r[i] = 1

    if r[k] == 1:
        return 'First'

    return 'Second'


print(main())


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main() {
    int N,K,sum=0,M=0;

    cin >> N >> K;

    vector<int> d(K);
    vector<int> A(N);
    vector<int> tmp(N,0);

    rep(i,K){
        cin >> d.at(i);
        rep(j,d.at(i)){
            cin >> tmp.at(j);
            A.at(tmp.at(j)-1) = 1;
        }
    }

    rep(i,N){
        if(A.at(i)==1){
            sum += 1;
        }
    }

    cout << N-sum << endl;



}

Measured memory_bytes: 3636
def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def cross(a, b):
    return a.real * b.imag - a.imag * b.real


n = int(input())
vertices = [complex(*map(int, input().split())) for _ in range(n)]
edges = [(p0, p1, p1 - p0) for p0, p1 in zip(vertices, vertices[1:] + [vertices[0]])]

q = int(input())
while q:
    q -= 1
    p = complex(*map(int, input().split()))
    counter = 0
    for p0, p1, edge in edges:
        a, b = p0 - p, p1 - p
        if a.imag > b.imag:
            a, b = b, a
        crs = cross(a, b)
        if a.imag <= 0 and 0 < b.imag and crs < 0:
            counter += 1
        if crs == 0 and dot(a, b) <= 0:
            print(1)
            break
    else:
        print(2 if counter % 2 else 0)

Measured memory_bytes: 7820
# 類題（同じ問題): ABC 036 D
# https://atcoder.jp/contests/abc036/tasks/abc036_d
# 解法参考: https://qiita.com/Kiri8128/items/cbaa021dbcb07b5fdb92

from collections import deque

N=int(input())
G=[[] for _ in range(N)]
mod = 10**9+7

for i in range(N-1):
  x,y=map(int,input().split())
  G[x-1].append(y-1)
  G[y-1].append(x-1)
  
dp = [[0]*2 for _ in range(N)]

P = [-1] * N # P[i] はiの親。iが根なら-1
Q = deque([0]) # queue。根にするやつを最初に追加
R = [] # トポロジカルソート
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in G[i]:
        if a == P[i]: continue
        P[a] = i
        G[a].remove(i) #Gを子リストにする。
        deque.append(Q, a)

# トポロジカルソート逆順（葉）から順にみていく
for a in R[::-1]:
  # aが葉のとき
  if len(G[a])==0:
    dp[a][0] = 1
    dp[a][1] = 1
  # aが合流地点のとき: 部分木の情報をまとめる
  elif len(G[a])>1:
    # いったん値をリセットする
    dp[a][0] = 1
    dp[a][1] = 1
    for c in G[a]:
      dp[a][1] *= sum(dp[c]) # aの値が白の場合は、aの子cの色は何でもいい
      dp[a][0] *= dp[c][1] # 一方、aの値が黒の場合は、aの子cは全て白でなければいけない
    dp[a][0] %= mod
    dp[a][1] %= mod
  b = P[a]
  if b == -1:break
  dp[b][0] += dp[a][1] % mod
  dp[b][1] += dp[a][0]+dp[a][1] % mod

print(sum(dp[0])%mod)

Measured memory_bytes: 40896
n,k = map(int,input().split())
p = list(map(int,input().split()))
l = []
count = 0
for i in range(n):
    count += (p[i]+1)/2
    l.append(count)
ansl = []
for i in range(n-k):
    ansl.append(l[i+k]-l[i])
if n == k:
    ansl.append(l[n-1])
print(max(ansl))

Measured memory_bytes: 24556
#include <iostream>
#include <vector>
#include <string>

using namespace std;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;

int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  i8 a, b;
  cin >> a >> b;
  
  if(a > b) {
    for(i32 i = 0; i < (i32)(a-'0'); ++i) cout << b;
  } else {
    for(i32 i = 0; i < (i32)(b-'0'); ++i) cout << a;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 * Created 2017/06/01.
 */
public class Main {
  public static void main(String[] args) {
    //??\?????¨?????????
    Scanner sc = new Scanner(System.in);
    ArrayList<ArrayList<Integer>> ary_ans = new ArrayList<>();
    while (true) {
      ArrayList<Integer> ary = new ArrayList<>();
      int input1 = Integer.parseInt(sc.next());
      int input2 = Integer.parseInt(sc.next());
      if (input1 == 0 && input2 == 0) break;
      ary.add(input1);
      ary.add(input2);
      Collections.sort(ary);    //??????????????§?????????????????????????´???´????????????
      ary_ans.add(ary);
    }
    //System.out.println(ary_ans);//????????????????´???´???????????? ????????????????????????????´???´???????????????????????????

    //????????¨???????????????????°?????°???????
    for (int i = 0; i < ary_ans.size(); i++) {
      for (int j = 0; j < ary_ans.get(i).size(); j++) {
        System.out.println(ary_ans.get(i).get(j) + " " + ary_ans.get(i).get(j + 1));
        if (j == ary_ans.get(i).size()) ;
        break;
      }
    }
  }
}

Measured memory_bytes: 38048
#include <stdio.h>
int main(void){
   int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=1.0*a/b;
    printf("%d %d %.8lf",d,r,f);
    return 0;
}



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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;

using value_type = i64;


signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    vector<int> t(n, 0);
    for(int i = 0; i < m; ++i){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
        ++t[a[i]], ++t[b[i]];
    }
    for(auto& x : t)
        if(x & 1){
            cout << "NO" << endl;
            return 0;
        }
    cout << "YES" << endl;


}


Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int N = 101010;

inline char get(void) {
	static char buf[100000], *S = buf, *T = buf;
	if (S == T) {
		T = (S = buf) + fread(buf, 1, 100000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}
template<typename T>
inline void read(T &x) {
	static char c; x = 0; int sgn = 0;
	for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
	for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
	if (sgn) x = -x;
}

int n, Gcnt, x, y;
struct edge {
	int to, next;
	edge(int t = 0, int n = 0):to(t), next(n) {}
};
edge G[N << 1];
int head[N], vis[N];

inline void AddEdge(int from, int to) {
	G[++Gcnt] = edge(to, head[from]); head[from] = Gcnt;
	G[++Gcnt] = edge(from, head[to]); head[to] = Gcnt;
}
inline bool Check(int u, int f) {
	bool ck = 1; int cnt = 0;
	for (int i = head[u]; i; i = G[i].next) {
		if (G[i].to == f) continue;
		ck &= Check(G[i].to, u); cnt++;
	}
	if (!cnt) {
		vis[u] = 1;
		if (!vis[f]) {
			vis[f] = 1; return 1;
		} else return 0;
	}
	if (!vis[u]) vis[u] = vis[f] = 1;
	return ck;
}

int main(void) {
	read(n);
	for (int i = 1; i < n; i++) {
		read(x); read(y);
		AddEdge(x, y);
	}
	if (Check(1, 0) && n % 2 == 0) puts("Second");
	else puts("First");
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/*Coding Space*/
int main(){
  int r; cin >> r;
  if(r < 1200)
    cout <<"ABC" << endl;
  else if(r < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
}

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

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

int main() {
    int h ,w;
    cin >> h >> w;
    vector<string> v(h);
    for(auto& e: v) cin >> e;

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(v[i][j] == '.') {
                int cnt = 0;
                for(int k = 0; k < 9; k++) {
                    if(i + dx[k] < 0 || h <= i + dx[k] || j + dy[k] < 0 || w <= j + dy[k]) continue;
                    if(v[i+dx[k]][j+dy[k]] == '#') cnt++;
                } 
                v[i][j] = '0' + cnt;
            }
        }
    }

    for(auto e : v) cout << e << endl;

    return 0;
}

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

#define INF (1<<29)
 
using namespace std;
 
int main(void){
  
  int n,m,p,a,b,x,y,z,in;
  double dp[(1<<8)][31],graph[31][31];
  vector<int>t;
  
  while(cin >> n >> m >> p >> a >> b){
    if(!(n|m|p|a|b))break;
    
    t.clear();
    
    fill(graph[0],graph[31],-1);
    fill(dp[0],dp[(1<<8)],INF);

    for(int i=0;i<n;i++){
      cin >> in;
      t.push_back(in);
    }
    
    for(int i=0;i<p;i++){
      cin >> x >> y >> z;
      graph[x][y]=graph[y][x]=z;
    }
    
    dp[0][a]=0;
    double res=INF;
    for(int S=0;S<(1<<8);S++){
      res=min(res,dp[S][b]);
      for(int v=1;v<=m;v++){
	for(int i=0;i<n;i++){
	  if(!(S>>i & 1)){
	    for(int u=1;u<=m;u++){
	      if(graph[v][u]>0){
		dp[S|(1<<i)][u]=min(dp[S|(1<<i)][u],dp[S][v]+graph[v][u]/t[i]);
	      }
	    }
	  }
	}
      }
    }
    if(res==INF)printf("Impossible\n");
    else printf("%.3f\n",res);
  }
  
  return 0;
}

Measured memory_bytes: 1308
#include <stdio.h>

int main()
{
	int a;
	scanf("%d", &a);
    
    if(a>=0 && a<=1000)
	 	printf("%d",1000-a) ;
    if(a>1000 && a<=2000)
	 	printf("%d",2000-a) ;
    if(a>2000 && a<=3000)
	 	printf("%d",3000-a) ;
    if(a>3000 && a<=4000)
	 	printf("%d",4000-a) ;
    if(a>4000 && a<=5000)
	 	printf("%d",5000-a) ;
    if(a>5000 && a<=6000)
	 	printf("%d",6000-a) ;
    if(a>6000 && a<=7000)
	 	printf("%d",7000-a) ;
    if(a>7000 && a<=8000)
	 	printf("%d",8000-a) ;
    if(a>8000 && a<=9000)
	 	printf("%d",9000-a) ;
    if(a>9000 && a<=10000)
	 	printf("%d",10000-a) ;
}



Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
typedef pair<int,int> P;
typedef pair<int,P> PP; 
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1e9+7;

vector<int> g[111111];
vector<P> bs;
vector<int> pre(111111,-1),low(111111,-1);
int t;

int dfs(int x=0,int p=-1){
  if(pre[x]!=-1)return pre[x];
  low[x]=pre[x]=t++;
  for(int i=0;i<g[x].size();i++){
    if(g[x][i]==p)continue;
    low[x]=min(low[x],dfs(g[x][i],x));
  }
  if(p!=-1&&low[x]==pre[x]){
    if(p<x)swap(p,x);
    bs.pb(P(x,p));
  }
  return low[x];
}

signed main(){
  int v,e;
  cin>>v>>e;
  for(int i=0;i<e;i++){
    int s,t;
    cin>>s>>t;
    g[s].pb(t);
    g[t].pb(s);
  }
  dfs();
  sort(all(bs));
  for(auto a:bs)cout<<a.fi<<" "<<a.se<<endl;
  return 0;
}



Measured memory_bytes: 9396
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
int ans[1<<20];
int pat1[8] = {0,1,0,1,1,0,1,0};
int main()
{
    int n,m,k;

    while (~scanf("%d %d", &m, &k)) {
        n = (1<<m);
        if (k>n-1 || (m==1 && k==1)) {
            puts("-1");
            continue;
        }

        if (k==0) {
            REP(i,0,2*n-1) ans[i] = i/2;
        } else {
            ans[0] = 0;
            ans[1] = k;
            ans[2] = 0;
            
            int pos=3;
            int s=0;
            REP(i,0,n-1) if(i!=0 && i!=k) ans[pos++] = i, s^=i;
            assert(s==k);
            ans[pos++] = k;
            for (int i=n-1; i>=0; i--) if(i!=0 && i!=k) ans[pos++] = i;
        }

        REP(i,0,2*n-1) printf("%d%c", ans[i], i==2*n-1 ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <string>

using namespace std;

int main(){
  string s;
  cin >> s;
  int mini, maxi;
  
  for(int i = 0; i < s.length(); i++){
    if(s[i] == 'A'){
      mini = i;
      break;
    }
  }
  for(int i = s.length() - 1; i >= 0; i--){
    if(s[i] == 'Z'){
      maxi = i;
      break;
    }
  }
  
  cout << maxi - mini + 1 << endl;
  return 0;
}

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

using namespace std;

typedef int64_t ll;
typedef long double ld;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	ll l = c*d/__gcd(c, d);

	ll x = ((b/c)*c - ceil((ld)a/c)*c)/c + 1;
	ll y = ((b/d)*d - ceil((ld)a/d)*d)/d + 1;
	ll z = ((b/l)*l - ceil((ld)a/l)*l)/l + 1;

	cout << (b-a+1) - (x+y-z);

/*
 * 10 40 6 8
 * #: 31
 * #6: (36-12)/6+1 = 
 */

	return 0;
}




Measured memory_bytes: 512
#!/usr/bin/env python3
(n, ), *dot = [[*map(int, i.split())] for i in open(0)]
red = sorted(dot[:n])
blue = sorted(dot[n:])
for c, d in blue:
    o = [[a, b] for a, b in red if a < c and b < d]
    if o:
        red.remove(max(o, key=lambda x: x[1]))
print(n - len(red))


Measured memory_bytes: 67012
#include<bits//stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int c=3;
    for(int i=0;i<N;i++){
        char a;
        cin>>a;
        if(a=='Y'){
            c++;
          	break;
        }
        else{
        }
    }
    if(c==4){
        cout<<"Four"<<endl;
    }
    else{
        cout<<"Three"<<endl;
    }
}

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

int main(){
    int N,K; cin>>N>>K;
    int x=0;
    int ans=0;
    for(int i=1;i<=N;i++){
        cin>>x;
        int A=x*2;
        int B=(K-x)*2;
        ans=ans+min(A,B);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/24
// Problem:Katana Thrower _ re_d.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

static const int MOD = 1e9 + 7;
static const int MAX_N = 1;

int main()
{
  LCIN(N, H);
  vector< pair< int, int > > d(N);
  int aMax = 0;
  REP(i, N) {
    scanf("%d %d", &d[i].first, &d[i].second);
    aMax = max(aMax, d[i].first);
  }

  sort(ALL(d), [](pair< int, int > x, pair< int, int > y) {
      return x.second > y.second;
  });

  int ans = 0;
  ll sum = 0ll;
  REP(i, 1e9 + 1) {
    if (sum >= H) break;
    if (d[i].second > aMax) {
      sum += d[i].second;
      ans++;
    } else {
      ans += ((H - sum) + aMax - 1) / aMax;
      sum = H;
    }
    //  debug(sum);
    // debug(ans);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1024