akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;
vector<vector<int>> state(MAX,vector<int>(7,0));

vector<int> dx={-1,0,0,1},dy={0,-1,1,0};

void DFS(int u,int v,int goal,int when){
    stack<pair<int,int>> ST;
    ST.push(make_pair(u,v));
    state[u][v]=when;
    
    while(!ST.empty()){
        int a=ST.top().first,b=ST.top().second;
        ST.pop();
        for(int i=0;i<4;i++){
            int c=a+dx[i],d=b+dy[i];
            if(c<0||c>=goal||d<0||d>=7) continue;
            if(state[c][d]==0){
                ST.push(make_pair(c,d));
                state[c][d]=when;
            }
        }
    }
}

int main(){
    
    ll N;
    int M,Q;cin>>N>>M>>Q;
    vector<int> A(Q);
    for(int i=0;i<Q;i++){
        cin>>A[i];
    }
    if(M%7==0){
        for(int i=0;i<Q;i++){
            int a=A[i]/7,b=A[i]%7;
            state[a][b]=-1;
        }
        int now=0;
        for(int i=0;i<M/7;i++){
            for(int j=0;j<7;j++){
                if(state[i][j]==0){
                    now++;
                    DFS(i,j,M/7,now);
                }
            }
        }
        set<pair<int,int>> se;
        for(int j=0;j<7;j++){
            if(state[0][j]>=0&&state[M/7-1][j]>=0) se.insert(make_pair(state[0][j],state[M/7-1][j]));
        }
        
        cout<<7*N/M*now-(7*N/M-1)*se.size()<<endl;
    }else{
        for(int i=0;i<Q;i++){
            for(int j=0;j<7;j++){
                int a=(A[i]+M*j)/7,b=(A[i]+M*j)%7;
                state[a][b]=-1;
            }
        }
        int now=0;
        for(int i=0;i<M;i++){
            for(int j=0;j<7;j++){
                if(state[i][j]==0){
                    now++;
                    DFS(i,j,M,now);
                }
            }
        }
        set<pair<int,int>> se;
        for(int j=0;j<7;j++){
            if(state[0][j]>=0&&state[M-1][j]>=0) se.insert(make_pair(state[0][j],state[M-1][j]));
        }
        
        cout<<N/M*now-(N/M-1)*se.size()<<endl;
    }
}




Measured memory_bytes: 7872
N = int(input())
counts = dict()
counts["AC"] = 0
counts["WA"] = 0
counts["TLE"] = 0
counts["RE"] = 0
for i in range(N):
    S = input()
    counts[S] += 1
    
stats = ["AC", "WA", "TLE", "RE"]
for e in stats:
    print(e + " x " + str(counts[e]))

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;

#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2);

int main()
{
  int N,M;cin>>N>>M;
  vector<int> K(N);
  vector<vector<int>> s(M);
  for (int i=0;i<M;i++)
  {
    cin>>K[i];
    for (int j=0;j<K[i];j++)
    {
      int a;cin>>a;
      a--;
      s[i].push_back(a);
    }
  }
  
  vector<int> p(M);
  for (int i=0;i<M;i++)
    cin>>p[i];
  
  int ans=0;
  for (int bit=0;bit<(1<<N);bit++)
  {
    //bitを固定した時に電球が全て点灯するかどうか
     int count=0; //点灯した電球の数
    
     for (int i=0;i<M;i++)//電球が点灯するかどうか
     {
       int nn=0;
       for (int k=0;k<K[i];k++)
       {
         if (1 & (bit>>s[i][k])){
           nn++; 
           //cout<<"==="<<endl;
         }
       }
       if (nn % 2 == p[i]) count++;
     }
    if (count==M) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int mx = 1e9+7;
int N = 1e5+5;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    vector<int>dp(n,mx);
    dp[0] =0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<=(i+2);j++)
    {
        if(j<n)
        {
            dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, i;
  cin >> N;
  i64 A = 0, B = 0;
  REP(0, N, i) {
    i64 d;
    cin >> d;
    A += d;
    B += d * d;
  }
  cout << (A * A - B) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn str_to_ints(s: String) -> std::vec::Vec<i64> {
    let mut ret = std::vec::Vec::new();
    let ws = s.split_whitespace();
    for w in ws {
        ret.push(w.parse().unwrap());
    }
    ret
}

fn read_ints() -> std::vec::Vec<i64> {
    str_to_ints(read_line())
}

fn main() {
    let n = read_ints()[0];
    let mut p: std::vec::Vec<i64> = std::vec::Vec::new();
    for i in 0..n {
        p.push(read_ints()[0]);
    }

    let mut sum_p: i64 = 0;
    let mut max_p: i64 = 0;
    for i in 0..n {
        sum_p += p[i as usize];
        max_p = std::cmp::max(max_p, p[i as usize]);
    }
    let ret: i64 = sum_p - max_p / 2;

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

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main(){
    char s;
    int a = 0;
    for(int i = 0; i < 4; i++){
        cin >> s;
        if(s == '+'){
            a++;
        }else{
            a--;
        }
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
dd = [
    [(0, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (0, 0)],
    [(0, 1), (1, 1), (1,  0), (0, -1), (-1,  0), (-1, 1), (0, 0)]
]
sx, sy, gx, gy = map(int, raw_input().split())
n = input()
P = {tuple(map(int, raw_input().split())) for i in xrange(n)}
lx, ly = map(int, raw_input().split())

INF = 10**18

dist = {(0, sx, sy): 0}
que = [(0, 0, sx, sy)]
while que:
    co, t, x, y = heappop(que)
    if dist.get((t, x, y), INF) < co:
        continue
    ox, oy = dd[x%2][abs(x*y*t) % 6]
    if (x+ox, y+oy) not in P and abs(x+ox) <= lx and abs(y+oy) <= ly:
        if co < dist.get(((t+1)%6, x+ox, y+oy), INF):
            dist[(t+1)%6, x+ox, y+oy] = co
            heappush(que, (co, (t+1)%6, x+ox, y+oy))
    for dx, dy in dd[x%2]:
        if dx == ox and dy == oy:
            continue
        nx = x+dx; ny = y+dy
        if (nx, ny) in P or abs(nx)>lx or abs(ny)>ly:
            continue
        if co+1 < dist.get(((t+1)%6, nx, ny), INF):
            dist[(t+1)%6, nx, ny] = co+1
            heappush(que, (co+1, (t+1)%6, nx, ny))
v = min(dist.get((t, gx, gy), INF) for t in xrange(6))
print -1 if v == INF else v

Measured memory_bytes: 44816
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(sc.next());

		int[] arr = new int[n];

		int maxAll = 0;
		int maxIndex = 0;

		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sc.next());
			if (arr[i] > maxAll) {
				maxAll = arr[i];
				maxIndex = i;
			}
		}

		for (int i = 0; i < n; i++) {
			if (i != maxIndex) {
				System.out.println(maxAll);
			} else {
				int max = 0;
				for (int j = 0; j < n; j++) {
					if(j==i)continue;
					if(max < arr[j]) {
						max = arr[j];
					}
				}
				System.out.println(max);
			}
		}
	}
}

Measured memory_bytes: 92224
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
string s;
bool b7, b5, b3;
int ans = 0;
void bfs(string a) {
	if (a.size() >= s.size()) {
		return;
	}
	a += '7';
	b7 = false, b5 = false, b3 = false;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == '7') {
			b7 = true;
		}
		if (a[i] == '5') {
			b5 = true;
		}
		if (a[i] == '3') {
			b3 = true;
		}
	}
	if (b7 == true && b5 == true && b3 == true) {
		if (s.size() > a.size() || s >= a) {
			ans++;
		}
	}
	bfs(a);
	a.erase(a.end()-1,a.end());
	a += '5';
	b7 = false, b5 = false, b3 = false;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == '7') {
			b7 = true;
		}
		if (a[i] == '5') {
			b5 = true;
		}
		if (a[i] == '3') {
			b3 = true;
		}
	}
	if (b7 == true && b5 == true && b3 == true) {
		if (s.size() > a.size() || s >= a) {
			ans++;
		}
	}
	bfs(a);
	a.erase(a.end() - 1, a.end());
	a += '3';
	b7 = false, b5 = false, b3 = false;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == '7') {
			b7 = true;
		}
		if (a[i] == '5') {
			b5 = true;
		}
		if (a[i] == '3') {
			b3 = true;
		}
	}
	if (b7 == true && b5 == true && b3 == true) {
		if (s.size()>a.size()||s >= a) {
			ans++;
		}
	}
	bfs(a);
	a.erase(a.end() - 1, a.end());
}
int main() {
	cin >> s;
	string n = "";
	bfs(n);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;


template
<class T>
struct heap
{
private:
	multiset<T, greater<T>>big;
	multiset<T, less<T>>sml;
public:
	void insert(T x)
	{
		big.insert(x);
		sml.insert(x);
	}
	void erase(T x)
	{
		big.erase(big.find(x));
		sml.erase(sml.find(x));
	}
	T getMax()
	{
		assert(big.size() && sml.size());
		return *big.begin();
	}
	T getMin()
	{
		assert(big.size() && sml.size());
		return *sml.begin();
	}
};

LL difference(vector<pair<LL, LL>>&vec)
{
	sort(vec.begin(), vec.end(), [](const pair<LL, LL>& p1, const pair<LL, LL>& p2)
	{
		if (p1.first == p2.first)
			return p1.second > p2.second;
		return p1.first < p2.first;
	});
	heap<LL>S,T;
	for (int i = 0; i < vec.size(); ++i)S.insert(vec[i].first);
	for (int i = 0; i < vec.size(); ++i)T.insert(vec[i].second);
	LL ans = (S.getMax() - S.getMin()) * (T.getMax() - T.getMin());
	for (int i = 0; i < vec.size(); ++i)
	{
		S.erase(vec[i].first);
		S.insert(vec[i].second);
		T.erase(vec[i].second);
		T.insert(vec[i].first);
		ans = min(ans, (S.getMax() - S.getMin()) * (T.getMax() - T.getMin()));
	}
	return ans;
}

int main(void)
{
	LL N;
	vector<pair<LL, LL>>vec;
	cin >> N;
	heap<LL> L, R;
	int sind, lind;
	LL minv = LLONG_MAX, maxv = 0;
	LL minpar = 0, maxpar = LLONG_MAX;
	for (int i = 0; i < N; ++i)
	{
		LL x, y;
		cin >> x >> y;
		if (x > y)swap(x, y);
		vec.push_back({ x, y });
		L.insert(x);
		R.insert(y);
		if (minv > x)
		{
			minv = x;
			minpar = y;
			sind = i;
		}
		else if (minv == x && minpar > y)
		{
			minv = x;
			minpar = y;
			sind = i;
		}
		if (maxv < y)
		{
			maxv = y;
			maxpar = x;
			lind = i;
		}
		else if (maxv == y && maxpar < x)
		{
			maxv = y;
			maxpar = x;
			lind = i;
		}
	}
	LL ans = (L.getMax() - L.getMin()) * (R.getMax() - R.getMin());
	if (sind == lind)
	{
		LL diff = difference(vec);
		LL can = diff;
		ans = min(ans, can);
	}
	else
	{
		auto small = vec[sind];
		auto large = vec[lind];
		//sindとlindの2箇所を削除する(後ろから)
		vec.erase(vec.begin() + max(sind, lind), vec.begin() + max(sind, lind) + 1);
		vec.erase(vec.begin() + min(sind, lind), vec.begin() + min(sind, lind) + 1);
		swap(small.first, small.second);
		vec.insert(vec.begin(), small);
		vec.push_back(large);
		LL diff = difference(vec);
		LL can = diff;
		ans = min(ans, can);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 79340
#include<iostream>
using namespace std;
#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;
int L[MAX / 2 + 2], R[MAX / 2 + 2];
llong merge(int A[], int n, int left, int mid, int right){
int i, j, k;
llong cnt = 0;
int n1 = mid - left;
int n2 = right - mid;
for(i = 0; i < n1; i++) L[i] = A[left + i]; 
for(i = 0; i < n2; i++) R[i] = A[mid + i]; 
L[n1] = R[n2] = SENTINEL;
i = j = 0;
for(k = left; k < right; k++){
if(L[i] <= R[j]){
A[k] = L[i++];
}else{
A[k] = R[j++];
cnt += n1 - i; 
}
}
return cnt;
}
llong mergeSort(int A[], int n, int left, int right){
int mid;
llong v1, v2, v3;
if(left + 1 < right){
mid = (left + right) / 2;
v1 = mergeSort(A, n, left, mid);
v2 = mergeSort(A, n, mid, right);
v3 = merge(A, n, left, mid, right);
return v1 + v2 + v3;
}else return 0;
}
int main(){
int A[MAX], n, i;
cin >> n;
for(i = 0; i < n; i++){
cin >>A[i];
}
llong ans = mergeSort(A, n, 0, n);
cout << ans << endl;
return 0;
}


Measured memory_bytes: 4688
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >>n;
    double ans = 0.0;
    if(n%2 == 0){
        ans = 0.5;
    }
    else{
        double N = n * 1.0;
        double num = (n/2) + 1;
        ans = num / N;
    }
    cout <<fixed <<setprecision(10) <<ans;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long H, W;
bool ban[10][10];

bool valid(int y, int x){
	return (y>=0 && y < H && x  >= 0 && x < W);
}


int main(){
	cin >> H >> W;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			char tmp;
			cin >> tmp;
			if(tmp == '#'){
				ban[i][j] = true;
			}
		}
	}

	int curx = 0;
	int cury = 0;

	while(1){
		ban[cury][curx] = false;
		if(valid(cury + 1, curx) && ban[cury+1][curx]){
			cury++;
		}else if(valid(cury, curx+1) && ban[cury][curx+1]){
			curx++;
		}else{
			break;
		}
	}

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(ban[i][j]){
				cout << "Impossible" << endl;
				return 0;
			}
		}
	}

	cout << "Possible" << endl;
	return 0;


}



Measured memory_bytes: 256
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    mc = 0
    for i in range(1, n):
        cnt = 0
        ts1 = dict(collections.Counter(s[:i]).most_common()).keys()
        ts2 = dict(collections.Counter(s[i:]).most_common()).keys()
        for k, in ts1:
            if k in ts2:
                cnt += 1
        mc = max(mc, cnt)
    print(mc)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 39664
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		int h = in.nextInt();
		int w = in.nextInt();
		String[] a = new String[h];
		for (int i = 0; i < h; i++) {
			a[i] = in.next();
		}
 
		boolean[] row = new boolean[h];
		Arrays.fill(row, false);
		boolean[] col = new boolean[w];
		Arrays.fill(col, false);
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i].charAt(j) == '#') {
					row[i] = true;
					col[j] = true;
				}
			}
		}
 
		for (int i = 0; i < h; i++) {
			if (row[i]) {
				for (int j = 0; j < w; j++) {
					if (col[j]) {
						System.out.print(a[i].charAt(j));
					}
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 25560
//よるかつ
//前に解説ACしたから今度は自力で
//2分探索解法

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

int main() {
  ll n,m,k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  vector<ll> sumA(n+1);
  vector<ll> sumB(m+1);
  rep(i,n)
    sumA[i+1] = sumA[i]+a[i];
  rep(i,m){
    sumB[i+1] = sumB[i]+b[i];
  }
  ll ans = -1;
  //aで全探索
  rep(i,n+1){
    int now_c =0;
    if(sumA[i]>k) continue;
    now_c+=i;
    ll remain = k-sumA[i];
    int now = upper_bound(sumB.begin(),sumB.end(),remain)-sumB.begin();
    now_c+=now-1;
    if(ans<now_c) ans = now_c;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9584
def binary_search(arr, target)
  left = 0
  right = arr.size

  while left < right
    mid = (left + right) / 2

    if arr[mid] == target
      return mid
    elsif target < arr[mid]
      right = mid
    else
      left = mid + 1
    end
  end

  nil
end

gets
s = gets.split.map(&:to_i)

gets
t = gets.split.map(&:to_i)

count = 0

t.each do |n|
  count += 1 if binary_search(s, n)
end

puts count

Measured memory_bytes: 17284
// D - Lucky PIN
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; string S; cin>>N>>S;
	int ans = 0;
	for(int i=0; i<1000; i++){
		int d=100; char c =  i/d%10+'0';
		for(int j=0; j<N; j++)
			if(S[j]==c){
				if(d==1){ ans++; break; }
				d/=10; c =  i/d%10+'0';
			}
	}
	cout<< ans <<endl;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var Q = int.Parse(Console.ReadLine());
            var array = new int[Q][];

            for (var i = 0; i < Q; i++)
                array[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var min = array.Min(a => a[0]);
            var max = array.Max(a => a[1]);

            var all = new long[max + 1];
            all[1] = 0;
            for (var i = Math.Max(min, 2); i <= max; i++)
            {
                if (i % 2 == 1)
                {
                    if (IsPrime(i) && IsPrime((i + 1) / 2))
                        all[i] = all[i - 2] + 1;
                    else
                        all[i] = all[i - 2];
                }
                else
                    all[i] = all[i - 1];
            }

            for (var i = 0; i < Q; i++)
            {
                Console.WriteLine(all[array[i][1]] - all[array[i][0] - 1]);
            }
        }

        public static bool IsPrime(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    // 素数ではない
                    return false;
                }
            }

            // 素数である
            return true;
        }
    }
}


Measured memory_bytes: 25148
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
//#define LOCAL
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif // LOCAL
using ll = long long;
int n;
int d[nax] ;
ll c[nax];
int cur;
int mer(int x, int y){
    x += y;
    return (x % 10) + (x / 10);
}
/*
ll bf(int x, ll len){
    ll res = 0;
    if(len == 1) return 0;
    if(x + x < 10){
        res += (len / 2);
        res += bf( mer(x, x),  len / 2);
        if(len % 2){
            int sum = ((len - 1) * x) % 10;
            if(sum + x < 10)
                res ++;
            else res += 2;
        }
    }
    else{
        res += (len / 2) * 2;
        res += bf(get(x), len / 2);
        if(len % 2){
            int sum = ((len - 1) * x) % 10;
            if(sum + x < 10)
                res ++;
            else res += 2;
        }
    }
    return res;
}*/
pair<ll, int> bf(int x, ll len){
    if(len == 1){
        return make_pair(0LL, x);
    }
    auto p = bf(x, len / 2);
    auto q = p;
    q.first += p.first;
    if(q.second + p.second < 10){
        q.first ++;
        q.second = p.second + q.second;
    }
    else{
        q.first += 2;
        q.second =  mer(p.second, q.second);
    }
    if(len % 2){
        p = make_pair(0LL, x);
        if(q.second + p.second < 10){
        q.first ++;
        q.second = p.second + q.second;
    }
    else{
        q.first += 2;
        q.second =  mer(p.second, q.second);
    }
    }
    return q;
}
ll ans, tot;


int main(){
    scanf("%d", &n);
    int sum = 0;
    for(int i = 1 ;i <= n; i++){
        scanf("%d %lld", &d[i], &c[i]);
        auto res = bf(d[i], c[i]);
        eprintf("res :%lld %d\n", res.first, res.second);
        ans += res.first;
        if(i == 1){
            sum = res.second;
            continue;
        }
        if(sum + res.second < 10){
            sum += res.second;
            ans += 1;
        }
        else{
            sum = mer(sum, res.second);
            ans += 2;
        }

    }
    printf("%lld\n", ans);
}

/*
    Long time no see!
    Atcoder...
*/


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

vector<vector<int>> adj(100001);

int dfs(int node,vector<int>& vu){
	if (vu[node] != -1) return vu[node];
	if (adj[node].empty()) return 0;
	for (auto& i:adj[node]) vu[node]=max(vu[node],1+dfs(i,vu));
	return vu[node];
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	vector<int> vu(n+1,-1);
	for (int i=0; i<m; ++i){
		int a,b;
		cin >> a >> b;
		adj[a].emplace_back(b);
	}
	int maxi=0;
	for (int i=1; i<=n; ++i) maxi=max(maxi,dfs(i,vu));
	cout << maxi;
	return 0;
}

Measured memory_bytes: 8192
import sys
import math
N,M = map(int,input().split())

if not ( 0 <= N <= 100 and 0 <= M <= 100 ): sys.exit()
if not ( 2 <= N+M ): sys.exit()
if not ( isinstance(N,int) and isinstance(M,int) ): sys.exit()

ans = 0
if N >= 2:
    ans += math.factorial(N) // (math.factorial(N - 2) * math.factorial(2))
if M >= 2:
    ans += math.factorial(M) // (math.factorial(M - 2) * math.factorial(2))
print(ans)

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

public class Main {
	public static void main (String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] firstLine = br.readLine().split(" ", 4);
		int x = Integer.parseInt(firstLine[0]);
		int y = Integer.parseInt(firstLine[1]);
		int z = Integer.parseInt(firstLine[2]);
		int k = Integer.parseInt(firstLine[3]);
		long[] xs = new long[x];
		String[] secondLine = br.readLine().split(" ", x);
		for (int i = 0; i < x; i++) {
			xs[i] = Long.parseLong(secondLine[i]);
		}
		
		long[] ys = new long[y];
		String[] thirdLine = br.readLine().split(" ", y);
		for (int i = 0; i < y; i++) {
			ys[i] = Long.parseLong(thirdLine[i]);
		}
		long[] zs = new long[z];
		String[] fourthLine = br.readLine().split(" ", z);
		for (int i = 0; i < z; i++) {
			zs[i] = Long.parseLong(fourthLine[i]);
		}
		long[] xys = new long[x * y];
		int idx = 0;
		for (int i = 0; i < x; i++) {
			for (int j = 0; j < y; j++) {
				xys[idx] = xs[i] + ys[j];
				idx++;
			}
		}
		Arrays.sort(xys);
		long[] xyzs = new long[k * z];
		idx = 0;
		for (int i = Math.max(x * y - k, 0); i < x * y; i++) {
			for (int j = 0; j < z; j++) {
				xyzs[idx] = xys[i] + zs[j];
				idx++;
			}
		}
		Arrays.sort(xyzs);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < k; i++) {
			sb.append(xyzs[xyzs.length - 1 - i]).append("\n");
		}
		System.out.print(sb);
	}
}


Measured memory_bytes: 59308
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] a = in.next().toCharArray();
        int l = a.length;
        for (int i = 0; i < l; ++i) {
            if (a[i] == 'B') {
                for (int j = i; j >= 0; --j) {
                    if (a[j] != 'B' && a[j] != '.') {
                        a[j] = '.';
                        break;
                    }
                }
            }
        }
        for (char x : a) {
            if (Character.isDigit(x)) System.out.print(x);
        }
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int cnt[26];
signed main(){
	int h,w;
	cin>>h>>w;
	int ok1 = 0, ok2 = 0;
	if( h % 2 == 1 && w % 2 == 1 ) ok1 ++;
	if( h % 2 == 1 ) ok2 += w/2;
	if( w % 2 == 1 ) ok2 += h/2;
	for(int i=0;i<h;i++){
		string st;
		cin>>st;
		for(int j=0;j<w;j++){
			cnt[ st[j] - 'a' ] ++;
		}
	}
	for(int i=0;i<=25;i++){
		if( cnt[i] % 4 == 1 ) ok1--;
		if( cnt[i] % 4 == 2 ) ok2--;
		if( cnt[i] % 4 == 3 ){ ok1--; ok2--; }
	}
	if( ok1 >= 0 && ok2 >= 0 ){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*****************************************************START******************************************************************/


int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int T = 1;
	 //cin >> T;
	// cin.ignore(); must be there when using getline(cin, s)
	while (T--)
	{
		ll n,m,k; cin >> n >> m >> k; 
		vector<ll>A(n+1),B(m+1);
		A[0] = 0 , B[0] = 0; 
		for(int i=1;i<=n; i++){
			ll a; cin >> a; 
			A[i] = A[i-1] + a;
		}for(int i=1; i<=m; i++){
			ll b; cin >> b;
			B[i] = B[i-1] + b;
		}
		
		for(auto x : A){
			cerr << x << "  " ;
		}
		cerr << endl;
		
		int ans = 0; 
		for(int i = 0 , j = m ; i <= n; i++){
			
			if(A[i] > k ){
				break;
			}
			
			while(A[i] + B[j] > k && j > 0){
				j--; 
			}
			
			//cerr << i << " " << j << endl;
			ans = max(ans , i + j);
		}
		cout << ans << endl; 
		
				
	}
	return 0;
}


Measured memory_bytes: 6804
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	lli a,b,c,t,temp1,temp2,x,y,temp,q,d,k,mod=1e9+7;
	cin>>a>>b;
	
	cout<<(a*(a-1)/2)+(b*(b-1)/2);
}


Measured memory_bytes: 3636
#include <string>
#include <iostream>
#include <cassert>
using namespace std;

int abc101_c(int n, int k) {
	if (n == k) {
		return 1;
	}
	if ((n - 1) % (k - 1) == 0){
		return (n - 1)/ (k - 1);
	}
	return (n - 1) / (k - 1) + 1;
}

void abc_101_c_test() {
	
	assert(abc101_c(4, 3) == 2);
	assert(abc101_c(3, 3) == 1);
	assert(abc101_c(8, 3) == 4);
	assert(abc101_c(7, 4) == 2);
	assert(abc101_c(7, 4) == 2);
	
	assert(abc101_c(7, 2) == 6);
	assert(abc101_c(7, 2) == 6);
}


int main()
{
	//abc_101_c_test();
	int n, k;
	int pos = 0;
	cin >> n >> k;
	while (true) {
		int a;
		cin >> a;
		if (a == 1) {
			break;
		}
		pos++;
	}
	
	cout << abc101_c(n, k) << endl;

	return 0;
}



Measured memory_bytes: 256
N = int(input())
str_list = []
for i in range(N):
    str_list.append(input())

a = str_list.count("AC")
w = str_list.count("WA")
t = str_list.count("TLE")
r = str_list.count("RE")

print("AC x",a)
print("WA x",w)
print("TLE x",t)
print("RE x",r)

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

int main()
{
  int n, k;
  cin >> n >>k;
  int v[n];
  for (int i = 0; i < n; ++i) cin >> v[i];
  
  int max = 0;
  for (int i = 1; i <= min(n, k); ++i) {
    for (int j = 0; j <= i; ++j) {
      priority_queue<int, vector<int>, greater<int>> q;
      for (int l = 0; l < j; ++l) q.push(v[l]);
      for (int l = 0; l < i-j; ++l) q.push(v[n-l-1]);
      int sum = 0;
      int m = k-i;
      while (!q.empty()) {
        if((q.top() < 0) && (m > 0)) {
          q.pop();
          --m;
        }
        else {
          sum += q.top();
          q.pop();
        }
      }
      if (sum > max) {
        max = sum;
      }
    }
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int a[4];
	for(int i = 0; i < 3; i++)
		scanf("%d",&a[i]);
	sort(a,a+3);
	if(a[0]+a[1] == a[2])
	printf("Yes");
	else
	printf("No");
return 0;	
}

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

long long C(int x,long long y){
  long long ans=1;
  for(int i=1;i<=y;i++){
    ans=ans*(x-i+1)/i;
  }
  return ans;
}


int main() {
  long long N,c=1,ans=0;
  cin>>N;
  vector<string> S(N);
  vector<long long> cc(N);
  for(int i=0;i<N;i++){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    S.at(i)=s;
  }
  sort(S.begin(),S.end());
  for(int i=0;i<N;i++){
    if(i!=N-1&&S.at(i)==S.at(i+1)){
      c++;
    }
    else{
      cc.at(i)=C(c,2);
      c=1;
    }
  }
  for(int i=0;i<cc.size();i++){
    ans+=cc.at(i);
  }
  cout<<ans;
 // cout<<C(100000 ,2);
        
    
}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>

std::vector<int> factrize(int n)
{
	std::vector<int> res;
	for (int i = 2; i * i <= n; i++)
	{
		while (n % i == 0)
		{
			res.push_back(i);
			n /= i;
		}
	}
	if (n != 1)
		res.push_back(n);
	return res;
}

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> res = factrize(n);
	std::cout << n << ": ";
	for (std::vector<int>::iterator i = res.begin(); i != res.end(); i++)
	{
		std::cout << *i;
		if (i != res.end() - 1)
			std::cout << ' ';
	}
	std::cout << std::endl;
}


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

int cal(int a,int b,int h){
	int d ;
  d = (a + b)*h/2;
    return d;
}

int main(){
  int a,b,h;
  
  cin >> a;
  cin >> b;
  cin >> h;
  
  cout << cal(a,b,h);
  return 0;
}

Measured memory_bytes: 3572
K,A,B=map(int, input().split())
#操作K回ビスケットを最大化
if A+2>=B:
    print(K+1)
    exit()

if 1+K-2<A:
    print(K+1)
    exit()

res=K-(A-1)
ans=A
if res%2==1:
    ans+=1
ans+=(res//2)*(B-A)

print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
using namespace std;
int n, k;
long long int a[200005], s[200005], ps = 0;
const long long MOD = 1e9 + 7;
int main() {
  scanf("%d %d", &n, &k);
  long long res = 1;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n);

  if (k % 2) {
    res = a[n - 1];
    int w = res > 0 ? 1 : -1;
    int l = 0, r = n - 2, cnt = 1;
    while (cnt < k && l < r) {
      if (w * a[l] * a[l + 1] > w * a[r] * a[r - 1]) {
        s[ps++] = a[l++];
        s[ps++] = a[l++];
        cnt += 2;
      } else {
        s[ps++] = a[r--];
        s[ps++] = a[r--];
        cnt += 2;
      }
    }
  } else {
    res = 1;
    int l = 0, r = n - 1, cnt = 0;
    while (cnt < k && l < r) {
      if (a[l] * a[l + 1] > a[r] * a[r - 1]) {
        s[ps++] = a[l++];
        s[ps++] = a[l++];
        cnt += 2;
      } else {
        s[ps++] = a[r--];
        s[ps++] = a[r--];
        cnt += 2;
      }
    }
  }
  for (int i = 0; i < ps; ++i) {
    res = (1l * (s[i] % MOD) * res) % MOD;
  }
  res = (res % MOD + MOD) % MOD;
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 4812
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
    int h, a;
    scanf("%d %d", &h, &a);
    printf("%d\n", h / a + (h % a ? 1 : 0));
    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  ll A[N]; FOR(i,0,N) cin >> A[i];
  sort(A, A + N);
  reverse(A, A + N);
  ll j = 0, cnt = 0, ans = 1;
  while(j < N - 1) {
    if(A[j] == A[j+1]) {
      cnt += 2;
      ans *= A[j];
      j += 2;
      if(cnt == 4) {
        cout << ans << '\n';
        return 0;
      }
    } else {
      j++;
    }
  }
  cout << 0 << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
     long long int a,i,sum=0;
     cin>>a;
     for(i=1;i<=a;i++)
     {
          if(i%3==0||i%5==0)
               continue;
          else
               sum=sum+i;
     }
     cout<<sum;
     return 0;
}


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

ll A[200005], B[200005];

map< pair<ll, ll>, ll> mp;
map< pair<ll, ll>, int> used;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res % mod;
}
int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  int n;cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i]>>B[i];
    if(A[i] == 0 && B[i]==0){
      mp[{0,0}]++;
    } else if (A[i]==0) {
      mp[{0,-1}]++;
    } else if (B[i]==0){
      mp[{1,0}]++;
    } else {
      if (A[i]<0){
        A[i]=-A[i],B[i]=-B[i];
      }
      ll g = __gcd(abs(A[i]), abs(B[i]));
      A[i]/=g;
      B[i]/=g;
      mp[{A[i], B[i]}]++;
    }
  }
  ll mod=1000000007;
  ll ans=1;
  ll zz=0;
  for(auto& kv : mp) {
    ll t=1;
    auto pll = kv.first;
    auto cnt = kv.second;
    if (used[pll])continue;
    if (pll.first == 0 && pll.second==0) {zz=cnt;}
    else {
      pair<ll, ll> pll2 = {pll.second,pll.first};
      if(pll.second<0){pll2.first*=-1;}
      else {pll2.second*=-1;}
      t = modpow(2, cnt, mod) + modpow(2, mp[pll2] ,mod) -1ll;
      used[pll2]=1;
    }
    used[pll]=1;
    ans *= t; ans %= mod;
  }
  ans = (zz+ans-1ll+mod)%mod;
  cout<<ans<<endl;
  
  return 0;
}


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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int a[1<<18];

int main(){
	int n;cin>>n;
	multiset<int>se;
	rep(i,1<<n){
		scanf("%d",&a[i]);
		se.insert(a[i]);
	}
	sort(a,a+(1<<n),greater<>());
	vector<int>v{a[0]};
	se.erase(se.find(a[0]));
	int cnt=1;
	rep(i,n){
		int X=1<<i;
		assert(v.size()==X);
		rep(j,X){
			auto it=se.lower_bound(v[j]);
			if(it==se.begin()){
				puts("No");return 0;
			}
			it--;
			v.push_back(*it);
			se.erase(it);
		}
		sort(v.begin(),v.end(),greater<>());
		cnt+=X;
	}
	puts("Yes");
}

Measured memory_bytes: 16252
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
 
const int N = 200001;
vector <int> E[N];//建立N个vector,第i个vector存储与i节点相临接的结点。
 
int main(){
    //下边这句话的作用是加快c++读写速度。
	ios_base::sync_with_stdio(false);
	queue <int> que;
	//读入数据
	int n,m,x,y;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>x>>y;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	for(int i=0;i<E[1].size();i++){
	    que.push(E[1][i]);
	}
	bool possible = false;
	while(!que.empty()){
	    int temp = que.front();
	    que.pop();
	    for(int i=0;i<E[temp].size();i++){
	        if(E[temp][i] == n){
	            possible = true;
	            break;
	        }
	    
	    }
	}
	if(possible) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 12400
#include <bits/stdc++.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define for1(a,b,i) for(int i=a;i<=b;++i)
#define FOR2(a,b,i) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
inline int read() {
	int f=1,sum=0;
	char x=getchar();
	for(;(x<'0'||x>'9');x=getchar()) if(x=='-') f=-1;
	for(;x>='0'&&x<='9';x=getchar()) sum=sum*10+x-'0';
	return f*sum;
}

#define M 50
int n;
ll f[M][M];
char s[M],a[M],b[M];

int main() {
	//freopen("a.in","r",stdin);
	n=read();
	scanf("%s",s+1);
	ll ans=0;
	FOR2((1<<n)-1,0,i) {
		int cnt=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for1(1,n,j) 
			if(i>>j-1&1) a[++cnt]=s[j];
			else b[j-cnt]=s[j];
		memset(f,0,sizeof(f));
		f[0][0]=1;
		for1(0,n-1,j) for1(0,cnt,k) {
			if(!f[j][k]) continue;
			if(k!=cnt&&s[2*n-j]==a[k+1]) f[j+1][k+1]+=f[j][k];
			if(s[2*n-j]==b[j+1-k]) f[j+1][k]+=f[j][k]; 
		}
		ans+=f[n][cnt];
	}
	cout<<ans<<endl;
}

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

int main(){
    int n,*p,*q;
    cin >> n;
    p = new int [n];
    q = new int [n];
    for (int i = 0; i < n; i++){
        cin >> p[i];
    }
    for (int i = 0; i < n; i++){
        q[n-1-i] = p[i];
    }
    for (int i = 0; i < n; i++){
        cout << q[i];
        if(i != (n-1)){
            cout << " ";
        }
    }
    cout << endl;
    delete [] p;
    delete [] q;
}


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

int gcd(int x,int y){
    int a=x;
    int b=y;
    while(true){
        a=a%b;
        if(a==0)return b;
        else swap(a,b);
    }

}

int main(){
    int n,x;cin >>n>>x;
    vector<int> y(n);
    for(auto&& w:y)cin>>w;
    for(auto && w:y)w-=x;
    int ret=abs(y[0]);
    for(auto&& w:y)ret=gcd(ret,abs(w));
    cout<<ret;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  int i,j;
  for(i=0;i<h;i++){
    cin >> s[i];
  }
  i=0;
  j=0;
  int chk = 1;
  s[0][0]='.';
  while(i!=w-1 || j != h-1){
    if(j<h-1&&s[j+1][i]=='#'){
      j++;
      s[j][i]='.';
    }else if(i<w-1&&s[j][i+1]=='#'){
      i++;
      s[j][i]='.';
    }else{
      chk = 0;
      break;
    }
  }
  
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(s[i][j]=='#')chk=0;
    }
  }
  if(chk==0)cout<<"Impossible"<<endl;
  else cout << "Possible"<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int W,H,x,y,r;
	scanf("%d\n",&W);
	scanf("%d",&H);
	scanf("%d",&x);
	scanf("%d",&y);
	scanf("%d",&r);
	if(x-r<0||y-r<0||x+r>W||y+r>H)
	printf("No\n");
	else if(x-r>=0||x+r<=W||y-r>=0||y+r<=H)
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
#define all(v) (v).begin(),(v).end()
typedef pair<ll,ll> P;
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll inf=100000000000000000;
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}

int main(){
ll n,k;
cin>>n>>k;
vector<P> p(n);
for(int i=0;i<n;i++)cin>>p.at(i).fi>>p.at(i).se;
sort(all(p));
for(int i=0;i<n;i++){
    k-=p.at(i).se;
    if(k<=0){
        cout<<p.at(i).fi<<endl;
        return 0;
    }
}
}

Measured memory_bytes: 1920
#include <time.h>
char s[99];
main(i,j,a,b,c,d,e){
	if(sizeof(time_t)!=8)exit(1);
	struct tm T;
	memset(&T,0,sizeof(T));
	T.tm_year=2012-1900;
	T.tm_mon=12-1;
	T.tm_mday=21;
	time_t t,t0=mktime(&T);
	for(;scanf("%s",s),*s!='#';){
		for(j=i=0;i<strlen(s);i++)if(s[i]=='.')j++;
		if(j==2){
			sscanf(s,"%d.%d.%d",&a,&b,&c);
			T.tm_year=a-1900;
			T.tm_mon=b-1;
			T.tm_mday=c;
			t=(mktime(&T)-t0)/86400%1872000;
			printf("%lld.%lld.%lld.%lld.%lld\n",t/144000,t/7200%20,t/360%20,t/20%18,t%20);
		}else{
			sscanf(s,"%d.%d.%d.%d.%d",&a,&b,&c,&d,&e);
			t=(a*144000LL+b*7200+c*360+d*20+e)*86400+t0;
			localtime_r(&t,&T);
			printf("%d.%d.%d\n",T.tm_year+1900,T.tm_mon+1,T.tm_mday);
		}
	}
exit(0);}

Measured memory_bytes: 656
#include<stdio.h>
int main(void){
   int i,n,a[100];
   int max,min;

   scanf("%d",&n);
   for(i=0;i<n;i++){
      scanf("%d",&a[i]);
   }
   max=min=a[0];
   for(i=0;i<n;i++){
      if(max<a[i]){
         max=a[i];
      }
      else if(min>a[i]){
         min=a[i];
      }
   }
   printf("%d\n",max-min);
   return 0;
}


Measured memory_bytes: 128
# include <bits/stdc++.h>
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define ll long long int
#include <tr1/unordered_map>
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define f(i,a,b)  for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#include <map>
using namespace std;

int main()
{


     flash;
     ///////////////////////////////////////////////////////////////////////////////////////
int n;
cin>>n;
map <string,int> mu;
mu["AC"]=0;
mu["WA"]=0;
mu["TLE"]=0;
mu["RE"]=0;
for(int i=0;i<n;i++)
{
  string s;
  cin>>s;
  mu[s]++;
}
cout<<"AC x "<<mu["AC"]<<endl;
cout<<"WA x "<<mu["WA"]<<endl;
cout<<"TLE x "<<mu["TLE"]<<endl;
cout<<"RE x "<<mu["RE"]<<endl;






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

     return 0;

}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define comp(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define infile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvli;
const int M = 1e9+7;
const int N = 2e5;
ll po(int,int);


void solve(){
 ll x,y;
 cin>>x>>y;
 if((4*x-y)>=0 && (y-2*x)>=0 && (4*x-y)%2==0 && (y-2*x)%2==0) cout<<"Yes\n";
 else cout<<"No\n";
  
    
} 





int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    
	return 0;
	
	
}


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}


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

int main(){
    long long n,y;cin >> n >> y;
    long long a,b,c;
    bool flag = false;
    int l[3] = {(int)n,0,0};
    for (int i=0;i<(n+2)*(n+1)/2;i++){
        if (l[0]*10000+l[1]*5000+l[2]*1000==y){flag = true; break;}
        else{
            if(l[1]==0){
                l[0]--;
                l[1] = l[2]+1;
                l[2]=0;
            }else{
                l[1]--;
                l[2]++;
            }
        }
    }
    if(flag){
        cout << l[0] << " " << l[1] << " " << l[2] << endl;
    }else{
        cout << -1 << " " << -1 << " " << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) 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 MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


print(48 - int(input()))


Measured memory_bytes: 69484
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int d, n; cin >> d >> n;
  if (n == 100) n++;
  if (d == 0) cout << n << endl;
  else if (d == 1) cout << n * 100 << endl;
  else if (d == 2) cout << n * 10000 << endl;
}


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

int main(){
  string s;
  cin >> s;
  int count = 0;
  rep(i,4){
    if(s[i] == '2') ++count;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 088 A - Infinite Coins
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/01
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cmath>
using namespace std;

int n, a;

void solve() {
    if ((n % 500) <= a) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

}

int main() {

    scanf("%d", &n);
    scanf("%d", &a);

    solve();

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	char s;
	double n,max=0,a=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		if(s=='I')max++;
		else if(s=='D')max--;
		if(a<=max)a=max;
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
  N = int(input())
  As = list(map(int, input().split()))
  
  ans_list = [0] * N
  
  for i in As:
    ans_list[i - 1] += 1
   
  for i in range(N):
    ans = ans_list[i]
    print(ans)

if __name__ == "__main__":
  main()

Measured memory_bytes: 99832
let n = Scanf.scanf "%d\n" (fun x -> x)

let rec solve i sumt suma =
  if i = 0 then (sumt + suma)
  else
    let t, a = Scanf.scanf "%d %d\n" (fun x y -> x, y) in
    let x = 
      if (suma / a) < (sumt / t) then
        (if sumt mod t = 0 then sumt / t else (sumt / t) + 1)
      else
        (if suma mod a = 0 then suma / a else (suma / a) + 1)
    in 
    solve (i - 1) (t * x) (a * x)

let () = solve n 1 1 |> Printf.printf "%d\n"

Measured memory_bytes: 768
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    h, w, k = geta(int)
    c = []
    for _ in range(h):
        c.append(gete())

    ans = 0
    for b in range(2**(h+w)):
        ih = []
        iw = []
        for i in range(h):
            ih.append(b & 1 == 1)
            b >>= 1
        for i in range(w):
            iw.append(b & 1 == 1)
            b >>= 1

        rem = 0
        for i in range(h):
            if ih[i]:
                continue
            for j in range(w):
                if iw[j]:
                    continue
                if c[i][j] == "#":
                    rem += 1

        if rem == k:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9532