akhauriyash/Code-Regression huggingface dataset:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))


h,w = inpl()
s = [input() for i in range(h)]
d = dict()
ld = dict()
i = 0
dx = [-1,0,1,0]
dy = [0,1,0,-1]
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    #根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
        
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

#初期化
uf = UnionFind(h*w)
for y in range(h):
    for x in range(w):
        if s[y][x] == '.':
            d[(y,x)] = i
            i += 1
for y in range(h):
    for x in range(w):
        if s[y][x] == '.':
            continue
        l = []
        for dir in range(4):
            nx = x+dx[dir]; ny = y+dy[dir]
            if nx<0 or nx>=w or ny<0 or ny>=h:
                continue
            if s[ny][nx] == '#':
                continue
            if l == []:
                ld[(y,x)] = d[(ny,nx)]
            l.append(d[(ny,nx)])            
            uf.union(l[0],d[(ny,nx)])

# print(ld)
res = 0
for key,value in ld.items():
    res += uf.size(value)
print(res)

Measured memory_bytes: 94164
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
using namespace std;

void solve() {
	int A, B;
	cin >> A >> B;
	int N = 1, counter = 0;
	while (true) {
		if (B > N) {
			counter++;
			N += (A - 1);
		}
		else break;
	}
	cout << counter << endl;
	return;
}

//////////////////////////////
//////////////////////////////

int main() {
#ifdef DEBUGTIME
	for (int time = 0; time < DEBUGTIME; time++) {
		solve();
		cout << "####################" << endl;
	}
#else
	solve();
#endif
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double total = 0;

        for(int i=0;i<n;i++){
            String a=sc.next();
            String u=sc.next();
            if(u.equals("JPY")){
                int a_ = Integer.parseInt(a);
                total+=a_;
            }else{
                double a_=Double.parseDouble(a);
                total+=a_*380000.0;

            }
        }
        System.out.println(total);
    }

}

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

using namespace std;

typedef pair<long, int> P;

int main(){
    int N;
    long A[100000];
    long B[100000];
    P C[100000];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i] >> B[i];
        C[i] = P(A[i]+B[i], i);
    }
    long T = 0;
    long A_ = 0;
    sort(C, C+N);
    for(int i = N-1; i >= 0; i--){
        if((N-1-i)%2 == 0) T += A[C[i].second];
        else A_ +=  B[C[i].second];
    }
    cout << T - A_ << endl;
}

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


int t[100];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	int n=s.size();
	int ans=300;
	for(int i=0;i<26;i++){
		for(int j=0;j<n;j++)
			if(s[j]=='a'+i)
				t[j]=1;
			else
				t[j]=0;
		if(accumulate(t,t+n,0)==n){
			ans=0;
			continue;
		}
		else if(accumulate(t,t+n,0)==0)
			continue;
		for(int j=n;;j--){
			if(accumulate(t,t+j,0)==j){
				ans=min(ans,n-j);
				break;
			}
			for(int k=0;k<j-1;k++)
				t[k]=t[k]|t[k+1];
		}

	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 110;
int main() {
    long long x, y;
    scanf("%lld %lld", &x, &y);
    long long ans = x;
    set<long long>vstd;
    if(x%y == 0){
        puts("0");
        exit(0);
    } else if(y%x == 0){
        printf("%lld\n", x);
        exit(0);
    }
    if(x > y) {
        long long lower = (x/y - 1ll) * y;
        x -= lower;
    }
    do {
        vstd.insert(x);
        ans = min(ans, x);
        x = abs(x - y);
    }while(!vstd.count(x));
    printf("%lld\n", ans);
    return 0;
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}

int main(){

    int n;

    cin >> n;

    FOR(i,1,3501){
        FOR(j,1,3501){
            ll nhw = (ll)n*i*j;
            ll tmp = (ll)4*i*j - n*i-n*j;
            if(tmp > 0 && nhw%tmp == 0){
                cout << i << " " << j << " " << nhw/tmp << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

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

int main()
{
	int a, b, c[101], i, d, e, f = 0;
	scanf("%d %d", &a, &b);
	for (i = 0; i < b; i++)
	{
		scanf("%d", &c[i]);
	}
	if (b == 0)
	{
		printf("%d", a);
		return 0;
	}
	

	qsort(c, b, sizeof(int), compare_int);

	for (i = 0; i < b; i++)
	{
		d = c[i] - a;
		if (i == 0)
		{
			e = d;
			f = i;
		}
		else if (abs(e) > abs(d))
		{
			e = d;
			f = i;
		}	
	}

	for (i = 1;; i++)
	{
		if (c[f - i] != c[f] - i)
		{
			printf("%d", c[f] - i);
			break;
		}
		else if (c[f + i] != c[f] + i)
		{
			printf("%d", c[f] + i);
			break;
		}
	}
}

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

int INF = 100000000;
bool res = true;

struct edge {
	int to;
	int cost;
};

typedef pair<int, int> P;
vector<int> vis(100010, INF);
vector<edge> G[100010];

void bfs(int k) {
	queue<P> que;
	que.push(P(k, 0));
	vis[k] = 0; //訪れた

	while (!que.empty()) {
		P p = que.front(); que.pop();
		int s = p.first;

		for (int i = 0; i < G[s].size(); i++) {
			edge e = G[s][i];

			//cout << e.to << " " << e.cost << endl;

			if (vis[e.to] == INF) {
				vis[e.to] = vis[s] + e.cost;
				que.push(P(e.to, vis[e.to]));
			}
			else if (vis[e.to] != vis[s] + e.cost) {
				res = false;
			}
		}
	}
}

int main() {
	int n, m;
	int l, r, d;

	cin >> n >> m;

	for (int i = 1; i <= m; i++) {
		cin >> l >> r >> d;

		G[l].push_back(edge{ r, d }); // [100010]を付けると解決
		G[r].push_back(edge{ l, -d });
	}

	for (int i = 1; i <= n; i++) {
		if (vis[i] == INF && G[i].size() != 0) bfs(i); //まだ訪れていないかつG[i]の要素があるとき幅優先探索
	}

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

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

long long int N, K, s = 1, t = 1;

long long int dsum(long long a){
    long long ret = 0;
    while(a){
        ret += a % 10;
        a /= 10;
    }
    return ret;
}

long double f(long long a){
    long long ret = dsum(a), d = __gcd(ret, a);
    return a / static_cast<long double>(ret);
}

vector<long long> ans;
long double a = f(1), b;

int main(){
    scanf("%lld", &K);
    N = 1000000000000000;
    for(long long int i = 1; i <= N; i += s){
        b = f(i + s);
        if(a < b){
            s = t;
            b = f(i + s);
        }
        if(a > b){
            if(s == t)t *= 10;
        }else{
            ans.push_back(i);
        }
        //printf("%lld : %.12Lf\n", i, a);
        swap(a, b);
    }
    for(int i = 0; i < K; ++i)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Runtime.InteropServices.ComTypes;

class Program
{
    static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
    static long mod = 1000000007;
    static void Main(string[] args)
    {
        var N = long.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var fir = A[0];
        var dic = new SortedDictionary<long, long>();

        for (int i = 0; i < N; i++)
        {
            var res = (A[0] + A[i]) - (i - 0);
            if (dic.ContainsKey(res))
            {
                dic[res]++;
            }
            else
            {
                dic.Add(res, 1);
            }
        }

        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            var tmp =   fir - A[i] - i;
            if (dic.ContainsKey(tmp))
            {
                ans += dic[tmp];
            }

        }

        Console.WriteLine(ans);
    }



}


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

int main() {
	int64_t N;
	cin >> N;
	// 配列の作成
	vector<pair<int64_t, int64_t>> dat(N);
	for (int64_t i = 0; i < N; i++) {
    	cin >> dat[i].second >> dat[i].first;	
    }
	sort(dat.begin(), dat.end());
	// 0がB,1がA 昇順
	int64_t t = 0;
	for (int64_t i = 0; i < N; i++) {
		t += dat[i].second;
		if (dat[i].first < t) {
			cout << "No" << endl;
			break;
		}
		if ( i == N-1) {
			cout << "Yes" << endl;
		}
	}
	
}

Measured memory_bytes: 6392
N, M = map(int,input().split())
each_s = []
for _ in range(M):
  each_s.append(list(map(int,input().split()))[1:])
p = list(map(int,input().split()))

switch = 2**N
answer = 0

for i in range(switch):
  lamp = []
  bit = format(i,"#010b")[::-1]
  for j in range(len(each_s)):
    count = 0
    for k in each_s[j]:
      if(bit[k-1] == "1"):
        count += 1
    lamp.append(count % 2)
  if lamp == p:
    answer += 1
print(answer)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
int ctoi(char c){
	switch(c){
		case '0':
			return 0;
		case '1':
			return 1;
		case '2':
			return 2;
		case '3':
			return 3;
		case '4':
			return 4;
		case '5':
			return 5;
		case '6':
			return 6;
		case '7':
			return 7;
		case '8':
			return 8;
		case '9':
			return 9;
		default: 
			return -1;
	}
}
int main(){
	char arg[11];
	char* a = arg;
	scanf("%s",arg);
        int n = atoi(arg);
	int sum=0;
	for(;*a!='\0';a++){
           if(ctoi(*a)==-1){
		   return 0;
	   }else{
		   sum += ctoi(*a);
	   }
	}
	if(n%sum==0){
		printf("Yes");
	}else{
		printf("No");
	}
}


Measured memory_bytes: 128
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        var nab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = nab[1];
        var b = nab[2];
        var total = a + b;
        var current = 0;
        var bCount = 0;
        foreach (var c in Console.ReadLine())
        {
            if (c == 'a') if (current >= total) goto end;
            if (c == 'b') if (current >= total || bCount >= b) goto end; else bCount++;
            if (c == 'c') goto end;
            Console.WriteLine("Yes");
            current++;
            continue;
            end:;
            Console.WriteLine("No");
        }
    }
}


static class Reader
{
    const int BUF_SIZE = 1 << 12;
    static Stream Stream = Console.OpenStandardInput();
    static byte[] Buffer = new byte[BUF_SIZE];
    static int ptr = 0;
    static void Move() { if (++ptr >= Buffer.Length) { Stream.Read(Buffer, 0, BUF_SIZE); ptr = 0; } }


    public static long NextLong
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            long res = 0; while (Buffer[ptr] < 48) Move();
            do { res = res * 10 + (Buffer[ptr] ^ 48); Move(); } while (48 <= Buffer[ptr]);
            return res;
        }
    }
}


Measured memory_bytes: 15840
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;

	cin >> N;

	vector<string> S(N);
	vector<string> s;

	for(int i = 0; i < N; i++) {
		cin >> S[i];
	}

	sort(S.begin(), S.end(), greater<string>());

	int max = 0;
	string res = S[0];
	int count = 1;

	//s.push_back(res);

	cout << endl;

	for(int i = 1; i < N; i++) {
		if(res == S[i]) {
			count++;
		} else {
			if(count == max) {
				s.push_back(res);
			} else if(count > max) {
				max = count;
				s.clear();
				s.push_back(res);
			}
			res = S[i];
			count = 1;
		}
	}

	if(count == max) {
		s.push_back(res);
	} else if(count > max) {
		max = count;
		s.clear();
		s.push_back(res);
	}

	for(int i = s.size() - 1; i >= 0; i--) {
		cout << s[i] << endl;
	}
}

Measured memory_bytes: 14576
import math

# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

# 素数判定
def callIsPrime(input_num=1000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

# 関数の呼び出し
prime_list = callIsPrime(100004)


X = int(input())

for v in prime_list:
    if X<=v:
        print(v)
        break

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

int main() {
	int N,total = 0;
	cin>>N;
	int keta=0;
	int i = N;
	while(i!=0){
		i = i/10;
		keta++;
	}
	if(keta==2) {
		total = 9;
	}
	else if(keta==4){
		total = 909;
	}
	else if(keta==6){
		total = 90909;
	}
	else if(keta==1){
		total = N;
	}
	else if(keta==3){
		total = 9 + N-99;
	}
	else{
		total = 909 + N-9999;
	}
	cout << total << endl;
}

Measured memory_bytes: 256
import sys


def solve(inp):
    (N, K, Q) = map(int, inp.readline().strip().split(' '))
    A = [int(inp.readline().strip()) for i in range(Q)]

    wins = [0 for i in range(N)]
    for a in A:
        wins[a - 1] += 1

    for win in wins:
        if Q - win < K:
            print("Yes")
        else:
            print("No")

    return ""


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8648
N, X = map(int, input().split())

a = [1]
p = [1]
for i in range(N):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)
  
def f(n, x):
  if n == 0:
    return 0 if x <= 0 else 1
  elif x <= 1 + a[n - 1]:
    return f(n - 1, x - 1)
  else:
    return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1])

print(f(N, X))

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

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'



int main()
{
	#ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	string s1 , s2 ;
	cin >> s1 >> s2;
	if(s1.size() == 1 && s2.size() == 1) cout << stoi(s1)*stoi(s2) ;
	else cout << -1 ;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}

int main() {
    int a, b;
    cin >> a >> b;
//    vector<long> as(n);
    cout << max(max(a + b, a - b), a * b) << endl;
}

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

int main() {
  int N, K, sum = 0;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++){
    int x;
    cin >> x; 
    if (abs(K-x) < x){
      sum += abs(K-x)*2;
    }
    else{
      sum += x*2;
    }
  }
  
  cout << sum << endl;
}

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

int main(){
    long long X, K, D;
    cin >> X >> K >> D;
    if(abs(X)-abs(K*D)>=0){
        cout << abs(X)-abs(K*D) << endl;
        return 0;
    }

    long long coef;
    coef = floor(abs(X)/abs(D));
    if((K-coef)%2==0) cout << abs(X) - coef * abs(D) << endl;
    else cout << (coef+1)*abs(D) - abs(X) << endl;
}

Measured memory_bytes: 3616
from heapq import heappush, heappop
INF = 10 ** 20

n, m, k, s = map(int, input().split())
p, q = map(int, input().split())
z_dist = [INF] * n
que = []
for _ in range(k):
  c = int(input()) - 1
  z_dist[c] = 0
  heappush(que, (0, c))

edges = [[] for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  edges[a].append(b)
  edges[b].append(a)

while que:
  total, node = heappop(que)
  for to in edges[node]:
    if z_dist[to] > total + 1:
      z_dist[to] = total + 1
      heappush(que, (total + 1, to))

cost = [INF] * n
cost[0] = 0
que = []
heappush(que, (0, 0))
while que:
  total, node = heappop(que)
  for to in edges[node]:
    if to == n - 1:
      if cost[to] > total:
        cost[to] = total
        continue
    if z_dist[to] == 0:
      continue
    if z_dist[to] <= s:
      price = q
    else:
      price = p

    if cost[to] > total + price:
      cost[to] = total + price
      heappush(que, (total + price, to))

print(cost[n - 1])


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

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007ll
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

namespace{
    std::chrono::system_clock::time_point t;
    void tic(){t=TIME;}
    void toc(){fprintf(stderr,"TIME : %lldms\n",MILLISEC(TIME-t));}
}

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}

int width,height;
int m,n;

string a[60];
string b[60];

int main(){
    int i,j,k;
    int x,y;
    cin >> n >> m;
    
    cin.ignore();
    
    for (i=0;i<n;++i){
        cin >> a[i];
    }
    for (i=0;i<m;++i){
        cin >> b[i];
    }
    
    for (i=0;i<=n-m;++i){
        for (j=0;j<=n-m;++j){
            for (y=0;y<m;++y){
                for (x=0;x<m;++x){
                    if (b[y][x]!=a[j+y][i+x]) goto next;
                }
            }
            cout << "Yes" << endl;return 0;
            next:;
        }
    }
    cout << "No" << endl;return 0;

    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
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; }

int main() {
        ll N;
        ll ans[100005] = {};
        map<ll,Pl> mp;

        cin >> N;
        for (ll i = 1; i <= N; i++) {
                ll a;
                cin >> a;
                if (mp.find(a) == mp.end()) mp[a].first = i;
                mp[a].second++;
        }

        ll total = 0;
        ll minv = N;
        for (auto itr = mp.rbegin(); itr != mp.rend(); itr++) {
                auto v = *itr;
                auto it2 = itr;
                it2++;

                ll prev;
                if (it2 == mp.rend()) prev = 0;
                else prev = it2->first;

                total += v.second.second; 
                minv = min(minv, v.second.first);
                ans[minv] += total * (v.first - prev);
        }

        for (ll i = 1; i <= N; i++) {
                cout << ans[i] << el;
        }

        return (0);
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll d,t,s;
  cin>>d>>t>>s;
  if(d<=s*t)
    yes;
  else
    no;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll findlcm(ll arr[],ll n)
{
    ll ans = arr[0]/2;
    for (int i = 1; i < n; i++)
        {ans=((((arr[i]/2) * ans))/(gcd((arr[i]/2), ans)));
          if(ans>1e9)
          {
              return 0;
          }
        }
    return ans;
}
int main()
{
     ll n,m;
     cin>>n>>m;
     ll a[n];
     for(int x=0;x<n;x++)
        cin>>a[x];
     ll f=m;
     ll gc=0;
     ll g=findlcm(a,n);
     ll w=g;
     ll co=0;
     while(w>0 && w%2==0)
     {
         w/=2;
         ++co;
     }
     ll h=pow(2,co);
     bool k=true;
     for(int x=0;x<n;x++)
     {   if(a[x]%(2*h)==0)
         {ll s=a[x]/(2*h);
         if(s%2==0)
         k=false;
         }
         else
            k=false;
     }
    if(g==0 || !k)
        cout<<"0";
    else
    {
        ll d=m/g;
        if(d%2==0)
            cout<<d/2;
        else
            cout<<d/2+1;
    }
}


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

 using namespace std;

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

   vector<int> p(N);
   vector<int> ascending(N);

   for (int i = 0; i < N; i++) {
     cin >> p.at(i);
     ascending.at(i) = i + 1;
   }

   string ans = "NO";
   int counter = 0;

   for (int i = 0; i < N; i++) {
       p.at(i) = p.at(i) - ascending.at(i);
       if (p.at(i) != 0) counter++;
   }

   if (counter == 0 || counter == 2) ans = "YES";

   cout << ans << endl;
}


Measured memory_bytes: 256
/*
 * @Author       : nonameless
 * @Date         : 2020-09-13 20:14:14
 * @LastEditors  : nonameless
 * @LastEditTime : 2020-09-13 20:38:55
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int)x.size()
#define toStr(name) (#name)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const double eps = 1e-6;
const double PI  = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll LNF  = 0x3f3f3f3f3f3f3f3f;
inline int gcd(int a, int b) { return b ? gcd(b,a % b):a;}
inline ll  gcd(ll  a, ll  b) { return b ? gcd(b,a % b):a;}
inline int lcm(int a, int b) { return a * b / gcd(a, b); }

template<class T>
inline void read(T &x){
    x = 0;
    int f = 1;
    char c = getchar();
    while(c < '0' || c > '9') if(c == '-') { f = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
    x = x * f;
}

template<class T>
inline void out(string a, T x){ cout << a << " = " << x << endl; }

const int mod = 1e9 + 7;

const int N = 1e6 + 10;

ll f[N];

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

ll C(ll a, ll b){
    return f[a] * (qpow(f[b] * f[a - b] % mod, mod - 2)) % mod;
}



int main(){

    f[0] = 1;
    for(int i = 1; i < N; i ++) f[i] = f[i - 1] * i % mod;

    ll n; read(n);
    if(n == 1) puts("0");
    else{
        ll ans = qpow(10, n);
        ll t1 = 0;
        for(int i = 1; i <= n; i ++){
            t1 = (t1 + C(n, i) * qpow(8, n - i) * 2 % mod) % mod;
        }
        t1 = (t1 + qpow(8, n)) % mod;
        ans = (ans - t1 + mod) % mod;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 11448
n=int(input())
import math
p=list(map(float,input().split()))
for i in range(n):
    p[i]=p[i]*100
dp=[[0]*(n) for i in range(n+1)]
dp[0][0]=(100-p[0])/100
for i in range(1,n):
    dp[0][i]=dp[0][i-1]*(100-p[i])/100
# print(dp[0][1],1-p[2],dp[0][1]*(1-p[2]))
for i in range(1,n+1):
    for j in range(i-1,n):
        if j==0:
            temp1=1 
            temp2=0 
        else:
            temp1=dp[i-1][j-1]
            temp2=dp[i][j-1]
        dp[i][j]=temp1*p[j]/100+temp2*(100-p[j])/100
        dp[i][j]=dp[i][j]
ans=0
# print(dp)
for i in range(n//2+1,n+1):
    ans+=dp[i][n-1]
print(ans)
        

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int H, W;
string s[510];
bool r[2][510][510];

int main() {
	cin >> H >> W;
	rep(i, H) {
		rep(j, W) {
			if (j == 0) {
				r[0][i][j] = 1;
			} else if (j == W-1) {
				r[1][i][j] = 1;
			} else {
				r[i&1][i][j] = 1;
			}
		}
	}

	rep(i, H) {
		cin >> s[i];
		rep(j, W) {
			if (s[i][j] == '#') {
				r[0][i][j] = r[1][i][j] = 1;
			}
		}
	}

	rep(tt, 2) {
		if (tt) puts("");
		rep(i, H) {
			rep(j, W) {
				printf("%c", r[tt][i][j] ? '#' : '.');
			}
			puts("");
		}
	}

	return 0;
}

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

int main()
{
  int64_t N, bef = 0;
  cin >> N;
  vector<int64_t> A(N + 1);
  for (int i = 0; i <= N; i++)
  {
    cin >> A.at(i);
  }
  bef = accumulate(A.begin(), A.end(), 0LL);
  for (int i = 0; i < N; i++)
  {
    int64_t b;
    cin >> b;
    A.at(i) -= b;
    if (A.at(i) >= 0)
      continue;
    b = abs(A.at(i));
    A.at(i) = 0;
    A.at(i + 1) -= b;
    if (A.at(i + 1) < 0)
      A.at(i + 1) = 0;
  }
  int64_t aft = accumulate(A.begin(), A.end(), 0LL);
  cout << bef - aft << endl;
}

Measured memory_bytes: 3920
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>
#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>

#define INF 100100100

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>t(n), x(n), y(n);
	for (int i = 0; i < n; i++)cin >> t[i] >> x[i] >> y[i];
	for (int i = 0; i < n; i++) {
		if (i == 0&&t[i]<x[i]+y[i]) {
			puts("No");
			return 0;
		}
		else if(i ==0 && (t[i]-x[i] - y[i])%2!= 0) {
			puts("No");
			return 0;
		}
		else if (i > 0&&t[i] - t[i-1] < abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])) {
			puts("No");
			return 0;
		}
		else if (i > 0&&(t[i]-t[i-1]-(abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])))%2 != 0) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}



Measured memory_bytes: 1408
#include <vector>
#include <iostream>
#include <algorithm>
int n, k, t;
std::vector<int> vec;
int ans = 1000000001;
int main() {
    std::cin >> n >> k;
    for (int i = 0; i < n; i++) {
        std::cin >> t;
        vec.push_back(t);
    }
    std::sort(vec.begin(), vec.end());
    for (int i = 0; i + k -1 < n; i++) {
        int diff = vec[i+k-1] - vec[i];
        if (diff < ans) {
            ans = diff;
        }
    }
    std::cout << ans << std::endl;
    
}


Measured memory_bytes: 892
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n),w;
  rep(i,n) cin>>v[i];
  ll tmp=1;
  rep(i,n){
    w.push_back(v[tmp%n]*2);
    tmp+=2;
  }
  ll res=Svec(v);
  tmp=0;
  rep(i,n/2){
    res-=w[tmp%n];
    tmp++;
  }
  ll a=res;
  vector<ll> ans(n);
  rep(i,n) v[i]*=2;
  ans[n-1]=v[n-1]-a;
  rep(i,n-1){
    ans[n-2-i]=v[n-2-i]-ans[n-1-i];
  }
  rep(i,n){
    cout<<ans[i]<<' ';
  }
  cout<<endl;
}

Measured memory_bytes: 3684
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
y = x
if y < a[0]:
    print(0)
else:
    for i in range(n):
        x = x - a[i]
        if x > 0:
            continue
        elif x == 0:
            print(i+1)
            break
        elif x < 0:
            print(i)
            break
if x > 0 and y > a[0]:
    print(n-1)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

const int max_n = 1e5 + 5;

int dp[max_n];

int main () {
	make2(n, K);
	makev(v, n);
	dp[0] = 0;
	FOR(i,1,K+1) {
		dp[i] = 0;
		FORE(j, v) {
			int m = *j;
			if (i-m >= 0 && dp[i-m]==0) {
				dp[i] = 1;
				break;
			}
		}
	}
	dp[K] == 0 ? puts("Second") : puts("First");


}	





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

using namespace std;

void del(int x, int y, string s[12])
{
	if(x!=0&&s[x-1][y]=='1'){s[x-1][y]='0';del(x-1,y,s);}
	if(x!=11&&s[x+1][y]=='1'){s[x+1][y]='0';del(x+1,y,s);}
	if(y!=0&&s[x][y-1]=='1'){s[x][y-1]='0';del(x,y-1,s);}
	if(y!=11&&s[x][y+1]=='1'){s[x][y+1]='0';del(x,y+1,s);}
}

int main(void)
{
	while(1)
	{
		string s[12];
		for(int i=0;i<12;i++)
		{
			cin>>s[i];
		}
		string gomi;
		getline(cin,gomi);
		if(cin.eof())break;
		int n=0;
		for(int x=0;x<12;x++)
		{
			for(int y=0;y<12;y++)
			{
				if(s[x][y]=='1'){
					n++;
					del(x,y,s);
				}
			}
		}
		cout<<n<<endl;
	}
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
ll dp[55][5005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;cin>>n>>a;
    vector<int> k(n);
    rep(i,n)cin>>k[i];
    rep(i,n)k[i]-=a;
    memset(dp,0,sizeof(dp));
    dp[0][2500]=1;
    rep(i,n)for(int s=0;s+k[i]<5000;s++){
        if(dp[i][s]==0)continue;
        dp[i+1][s]+=dp[i][s];
        dp[i+1][s+k[i]]+=dp[i][s];
    }
    cout<<dp[n][2500]-1<<endl;
    return 0;
}


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

int main() {
  int N,X,Y;
  cin >> N >> X >> Y;
  vector<int>ans(N-1);
  for(int i=1;i<N+1;i++){
    for(int j=i+1;j<N+1;j++){
      int x;
      x=min(j-i,abs(Y-j)+abs(X-i)+1);
      ans.at(x-1)++;
    }
  }
  for(int i=0;i<N-1;i++){
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 3640
public class Main {
	public static void main(String[] args) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			String s = sc.next();
			String p = sc.next();
			int cnt = 0;

			while (cnt != s.length()) {
				if (s.contains(p)) {
					System.out.println("Yes");
					return;
				}

				s = s.substring(1) + s.charAt(0);
				cnt++;
			}

			System.out.println("No");
		}
	}
}


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

char str[110];
int Count, Max;
int main()
{
	scanf("%s", str);
	for (int i=0; i<3; i++) if (str[i]=='R') Count++; else Max = max(Max, Count), Count=0;
	Max = max(Max, Count);
	printf("%d\n", Max);
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000000000
int main(){
  int n,w1;
  cin>>n>>w1;
  vector<int> w(n+1),v(n+1);
  for(int i=1;i<=n;i++)
     cin>>w[i]>>v[i];
  
  long long dp[w1+1][n+1];
  memset(dp,0,sizeof(dp));
  //for(int i=1;i<=w1;i++)
    //dp[i][0]=inf;
  
  for(int i=1;i<=w1;i++){
    for(int j=1;j<=n;j++){
      if(i-w[j]>=0)
        dp[i][j]=max(dp[i][j-1],dp[i-w[j]][j-1]+v[j]);
      else
        dp[i][j]=dp[i][j-1];
    }
  }
  cout<<dp[w1][n];
}


Measured memory_bytes: 79104
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		
		
        // 文字列の入力
        int [] b = new int[a];
		int[][] d = new int[a][a];
		int[][] e = new int[a][a];
		for(int i = 0; i < a; i++){
            b[i] = sc.nextInt();
          //System.out.println(b[i] + "and");
            for(int j = 0; j < b[i]; j++){
                d[i][j] = sc.nextInt();
                d[i][j] --;
              //System.out.print(d[i][j]);
                e[i][j] = sc.nextInt();
              //System.out.println(e[i][j]);
            }
        }
        int [] c = new int[a];
        int f = 0;
        int g = 0;
        boolean h = false;
		for(int i = 0; i < (int)Math.pow(2, a ); i++){
              int l = 1;
			for(int j = 0; j < a; j++){
                c[j] = (i / l) % 2;
              l = l * 2;
            }
            h = true;
            for(int j = 0; j < a && h; j++){
                for(int k = 0; k < b[j] && h; k++){
                    if(c[j] == 1 && e[j][k] != c[d[j][k]] ){
                        h = false;
                      //System.out.println(i  + "と" + j + "と" + k);
                    }
                }
            }
            if(h){
              
                for(int j = 0; j < a; j++){
                    f += c[j];
                }
                if(f > g){
                    g = f;
                  //System.out.println(i);
                }
                f = 0;
            }
            
		}
      
		System.out.println(g);
		
		
	}
}

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

int main(){
    int h,w;
    cin>>h>>w;
    int cnt=0;
    rep(i,h){
        string s; cin>>s;
        int n=s.size();
        rep(j,n){
            if(s[j]=='#')cnt++;
        }
    }
    if(cnt==h+w-1)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}

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

int main(){

  cin.tie(0); //cin高速化
  ios::sync_with_stdio(false); //cin高速化
  
  string s;
  int w;
  cin >> s >> w;
  int n = s.size();
  string a;
  for(int i=0;i<n;i=i+w){
    string str = s.substr(i,w);
    a += str[0];
  }
  cout<<a<<endl;
    
  return 0;
}
    

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

int main(){
    long long int i, n, k = 100, c = 0;

    cin >> n;

    for(i = 100; k < n; i++){
        k = k * 1.01;
        c++;
    }

    cout << c << "\n";

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int N;
	cin >> N;
	vector<int> A(N), B(N), C(N-1);
	for(int i=0; i<N; i++) cin >> A[i];
	for(int i=0; i<N; i++) cin >> B[i];
	for(int i=0; i<N-1; i++) cin >> C[i];

	ll ans = B[A[0]-1];
	for(int i=1; i<N; i++){
		ans += B[A[i]-1];
		if(A[i]==A[i-1]+1) ans += C[A[i-1]-1];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

import itertools
#ans = 0
cnt = 0
dis_ = 0
sum_ = 0
for route in itertools.permutations(range(N), N):
    cnt += 1
    #ans = 0
    #print(i)
    #dis = 0
    dis_ = 0
    for i in range(N - 1):
        dis = (xy[route[i]][0] - xy[route[i + 1]][0])**2 + (xy[route[i]][1] - xy[route[i + 1]][1])**2
        dis = dis**0.5
        dis_ += dis
    sum_ += dis_

print(sum_ / cnt)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int c1,c5,c10,c50,c100,c500;
	scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
	if(c1+(c5*5)+(c10*10)+(c50*50)+(c100*100)+(c500*500)>=1000){
		printf("1\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}



Measured memory_bytes: 2624
input = gets(nil).chomp

c = 0
f = 0

input.split("\n").each do |line|
  h = line.split(",").map(&:to_i)
  if h[0]**2 + h[1]**2 == h[2]**2
    c += 1
  elsif h[0] == h[1]
    f += 1
  end
end

puts c
puts f

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

int main(){

    int x, y;
   
    while(1){
        cin >> x >> y;
        
        if (x == 0 && y == 0) break;

        if(x > y){
            cout << y << " " << x <<endl;
        }else{
            cout << x << " " << y <<endl;
        }
    }


    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vll a(n);
    rep(i,n) cin>>a[i];
    vi b(3);
    rep(i,n){
        int cnt=0;
        while(a[i]%2==0){
            cnt++;
            if (cnt==2) break;
            a[i]/=2;
        }
        b[cnt]++;
    }
    if (b[1]==0){
        if (b[0]<=b[2]+1){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }else{
        if (b[0]<=b[2]){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int n,m,x,y,t;

	scanf("%d%d%d%d",&n,&m,&x,&y);
	while(n--){
		scanf("%d",&t);
		x=x>t?x:t;
	}
	while(m--){
		scanf("%d",&t);
		y=y<t?y:t;
	}
	if(x<y)
		printf("No ");
	printf("War\n");
	return 0;
}

Measured memory_bytes: 128
MOD = 1000000007
def modpow(a, n, mod) :
    ret = 1
    while n > 0:
        if n % 2 == 1:
            ret = ret * a % mod        
        a = a * a % mod
        n = n // 2
    return ret

N = int(input())

ret1 = modpow(10,N,MOD) 
ret2 = modpow(8,N,MOD)
ret3 = modpow(9,N,MOD)
ret = (ret1 - ret3 - ret3 + ret2) % MOD
print(ret)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

int n,k;
cin >> n >> k;

double ans = 0;

for(int i = 1; i <= n ;i++){
    double now = (double)1 / n;
    int a = i;
    while(a < k ){
        a *= 2;
        now /= 2;
    }
    ans += now;
}

cout << fixed << setprecision(12) << ans << endl;

return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    int x, y;
    cin >> x >> y;

    int ans = 0;

    if(x >= 0 && y >= 0){
        if(x <= y){
            cout << abs(y - x) << endl;
        } else {
            if(y == 0){
                cout << 1 + x - y << endl;
            } else {
                cout << 2 + x - y << endl;
            }
        }
    } else if(x <= 0 && y <= 0){
        if(x > y){
            if(x == 0){
                cout << 1 + abs(abs(y) - abs(x)) << endl;
            } else {
                cout << 2 + abs(abs(y) - abs(x)) << endl;
            }
        } else {
            cout << abs(y - x) << endl;
        }
    } else if(x < 0 && y >= 0){
        cout << 1 + abs(abs(y) - abs(x)) << endl;
    } else if(x >= 0 && y < 0){
        cout << 1 + abs(abs(y) - abs(x)) << endl;
    } else {
        cout << 1 + abs(abs(y) - abs(x)) << endl;
    }
}


Measured memory_bytes: 256