akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 100000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** DSL_1 - A : Set - Disjoint Set: Union Find Tree **/
const int MAX_N = 10000;
int par[MAX_N];
int rank[MAX_N];

void init(int n)
{
	rep(i, n) {
		par[i]=i;
		rank[i]=0;
	}
}

int find(int x)
{
	if (par[x] == x) {
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y) return;
	
	if (rank[x] < rank[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
}

bool same(int x, int y)
{
	return find(x) == find(y);
}

int main()
{
	int n, q;
	cin>>n>>q;
	init(n);
	rep(i, q) {
		int a, b, c;
		cin>>a>>b>>c;
		if (a) {
			cout << same(b, c) << endl;
		} else {
			unite(b, c);
		}
	}
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    map<string, ll> m;
    m["AC"]=0;
    m["TLE"]=0;
    m["WA"]=0;
    m["RE"]=0;
  for (int i = 0; i < n; ++i)
  {
  	string s;
  	cin >> s;
  	m[s]++;
  }
  
  	cout <<  "AC x " << m["AC"] <<"\n";
  	cout <<  "WA x " << m["WA"] <<"\n";
  	cout <<  "TLE x " << m["TLE"] <<"\n";
  	cout <<  "RE x " << m["RE"] <<"\n";
  
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main () {
	int x;
	cin >> x;
	while (1) {
		bool flag = true;
		for (int i =2; i< x; i++) {
			if (x % i == 0)  {
				flag = false;
			}
		}
		if (flag) {
			cout << x <<endl;
			return 0;
		} else {
			x++;
		}
	}
}

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

using namespace std;

long long ans = 0;

void decrease(int &a, int &b) {
	int k = min(a, b);
	a -= k;
	b -= k;
	ans += k;
}

int main() {
	int n;
	cin >> n;
	vector <int> a(n + 1);
	for (int i = 0; i < n + 1; i++) {
		cin >> a[i];
	}
	vector <int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		decrease(a[i], b[i]);
		decrease(a[i + 1], b[i]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
ln = []
cnt = 1
ans = 0

for i in range(n):
    ln.append(''.join(sorted(input())))

ln.sort()

for i in range(len(ln)-1):
    if ln[i] == ln[i+1]:
        cnt += 1
    else:
        ans += cnt*(cnt - 1)/2
        cnt = 1

ans += cnt*(cnt - 1)/2

print(int(ans))


Measured memory_bytes: 10640
from collections import defaultdict

n=int(input())
a=list(map(int,input().split()))

d=defaultdict(int)
for b in a:
    d[b] +=1

c=0
for k,v in d.items():
    if(k>v):
        c+=v
    else:
        c+=v-k

print(c)

Measured memory_bytes: 18672
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;

ll mod = 1000000000 + 7;

ll modplus(ll a, ll b){
	ll ans = a + b;
	ans %= mod;
	return ans;
}
ll modminus(ll a, ll b){
	ll ans = a - b;
	ans %= mod;
	if(ans < 0) ans += mod;
	return ans;
}
ll modmul(ll a, ll b){
	ll ans = a * b;
	ans %= mod;
	return ans;
}

ll modpow(ll A, ll P){
	ll a = A, p = P;
	if(p == 0) return 1;
	if(p == 1) return a;
	ll adash = modmul(a,a);
	if(p % 2) return modmul(modpow(adash, p / 2), a);
	else return modpow(adash, p / 2);
}
ll moddiv(ll a, ll b){
	ll divisor = modpow(b, mod - 2);
	return modmul(a,divisor);
}

vector<ll> FIB(10,0);
ll fib(ll n){
	if(FIB[n] != 0)return FIB[n];
	if(n == 0){
		FIB[n] = 1;
		return FIB[n];
	}
	if(n == 1){
		FIB[n] = 2;
		return FIB[n];
	}
	FIB[n] = modplus(fib(n-1), fib(n-2));
	return FIB[n];
}

ll countLeft(ll n, ll W){
	ll left = n - 2;
	ll right = n + 1;
	ll ans = 1;
	if(left >= 0) ans = fib(left);
	if(right <= W-1) ans = modmul(fib(W - right - 1),ans);
	return ans;
}

ll countCenter(ll n, ll W){
	ll left = n - 1;
	ll right = n + 1;
	ll ans = 1;
	if(left >= 0) ans = fib(left);
	if(right <= W-1) ans = modmul(fib(W - right - 1),ans);
	return ans;
}
ll countRight(ll n, ll W){
	ll left = n - 1;
	ll right = n + 2;
	ll ans = 1;
	if(left >= 0) ans = fib(left);
	if(right <= W-1) ans = modmul(fib(W - right - 1),ans);
	return ans;
}
int main(){
	ll H, W, K;
	cin >> H >> W >> K;
	ll count[H+1][W];
	for(ll i=0;i<H+1;i++){
		for(ll j=0;j<W;j++){
			count[i][j] = 0;
		}
	}
	count[0][0] = 1;
	for(ll i=0;i<H;i++){
		for(ll j=0;j<W;j++){
			if(j-1 >= 0) count[i+1][j-1] = modplus(modmul(count[i][j],countLeft(j,W)),count[i+1][j-1]);
			count[i+1][j] = modplus(modmul(count[i][j],countCenter(j,W)),count[i+1][j]);
			if(j+1 < W) count[i+1][j+1] = modplus(modmul(count[i][j],countRight(j,W)),count[i+1][j+1]);
		}
	}
	cout << count[H][K-1] << endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, Q, *A = map(int, read().split())

    B = [0] * N
    for a in A:
        B[a - 1] += 1

    ans = [0] * N
    for i, b in enumerate(B):
        if Q >= K + b:
            ans[i] = 'No'
        else:
            ans[i] = 'Yes'

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 20388
#include "bits/stdc++.h"
using namespace std;
#define maxn 301
#define rep(i,n) for(int i=0; i<int(n); ++i)
#define pb push_back
#define mp make_pair

const int mod = 1000000000 + 7;
int cnt[26];


void solve(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    int bad = (H / h) * (W / w);
    int good = H*W - bad;
    if( (h*w - 1) * bad >= good ){
        cout << "No";
        return;
    }
    int g = 1, b;
    while(1){
        g ++;
        b = g * (h*w - 1) + 1;
        if(good * g > bad * b) break;
    }
    cout << "Yes" <<endl;
    rep(i,H){
        rep(j,W){
            if(i%h==h-1 && j%w==w-1) cout << - b; else cout << g;
            if(j < W - 1) cout << ' '; else cout << endl;
        }
    }
}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    solve();
}

Measured memory_bytes: 1408
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll all_xor = 0;
    rep(i, 40) {
        ll tmp;
        rep(j, n) {
            //if (i == 4) cout << a[j] << " " << (1LL<<i) << " " << (a[j] & (1LL<<i)) << endl;
            if (j == 0) {
                tmp = a[j] & (1LL<<i);
                //cout << flg << endl;
            }
            else {
                tmp = tmp ^ (a[j] & (1LL<<i));
            }
            //if (i == 4) cout << tmp << endl;
        }
        all_xor += tmp;
        //cout << i << " " << all_xor << endl;
    }
    //cout << all_xor << endl;
    rep(i, n) {
        ll ans = 0;
        rep(j, 40) {
            ans += (all_xor & 1LL<<j) ^ (a[i] & 1LL<<j);
        }
        if (i != 0) cout << " ";
        cout << ans;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
void test_cases(){
    string s;
    cin >> s;
    int n = s.length();
    cout << s;
    if(s[n - 1] == 's'){
        cout << "es";
    }
    else{
        cout << "s";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tt = 1;
//    cin >> tt;
    while(tt--){
        test_cases();
    }
    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
#include <stdlib.h>

void chmax(long *a, long b) {
    if(*a < b) *a = b;
}


int main(void) {

    int N, W; scanf("%d %d", &N, &W);

    int w[N], v[N];
    for(int i = 0; i<N; i++) {
        scanf("%d %d", &w[i], &v[i]);
    }

    //🥺

    long **dp; 
    dp = malloc((N+1) * sizeof(long *));
    for(int i = 0; i<N+1; i++) {
        dp[i] = malloc((W+1) * sizeof(long));
    }

   for(int i = 0; i < N; i++) {
        for(int wp = 0; W-wp >= 0; wp++) {

            if(wp - w[i] >= 0) {
                chmax(&dp[i+1][wp], dp[i][wp-w[i]] + v[i]);
            }

            chmax(&dp[i+1][wp], dp[i][wp]);

        }
    }

    printf("%ld\n", dp[N][W]);

    for(int i = 0; i<N+1; i++) {
        free(dp[i]);
    }
    free(dp);

    return 0;
}

Measured memory_bytes: 78592
import java.util.*;

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

        int N = sc.nextInt();
        int[] h = new int[N];

        h[0] = sc.nextInt();
        int ans = h[0];
        for(int i = 1; i < N; i++){
            h[i] = sc.nextInt();
            if(h[i-1] >= h[i]) continue;
            ans += h[i] - h[i-1];
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
n=int(input())
a=input().split()

for i in a:
    if i=='0':
        print("0")
        quit()
ans=1
p = 1000000000000000000 / ans
for i in a:
    #print(ans," ",p)
    if(int(ans)<=p):
        ans=ans*int(i)
        if(int(ans)>p):
            print("-1")
            quit()
    else:
        print("-1")
        quit()
print(ans)



Measured memory_bytes: 19388
// Ivan Carvalho
// Problem Q - Educational Dynamic Programming Contest - AtCoder
// Link : https://atcoder.jp/contests/dp
#include <bits/stdc++.h>
#define LSOne(S) ((S) & (-S))
using namespace std;

typedef long long ll;

const int MAXN = 2*1e5 + 10;

ll bit[MAXN],dp[MAXN];
ll h[MAXN],a[MAXN];
int N;

void update(int x, ll val){
	while(x <= N){
		bit[x] = max(bit[x],val);
		x += LSOne(x);
	}
}

ll query(int x){

	ll ans = 0;
	while(x > 0){
		ans = max(ans,bit[x]);
		x -= LSOne(x);
	}

	return ans;

}

int main(){

	scanf("%d",&N);

	for(int i = 1;i<=N;i++){
		scanf("%lld",&h[i]);
	}
	for(int i = 1;i<=N;i++){
		scanf("%lld",&a[i]);
	}

	for(int i = 1;i<=N;i++){
		dp[i] = query(h[i] - 1) + a[i];
		update(h[i],dp[i]);
	}

	ll best = 0;
	for(int i = 1;i<=N;i++) best = max(best,dp[i]);
	printf("%lld\n",best);

	return 0;

}

Measured memory_bytes: 6528
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int N, T, a[107], c[107], used[4][4]; string s[107], m[4];
int rec(int x, int y, int d, int v) {
	if (d == s[v].size()) return 1;
	int ret = 0;
	for (int i = -1; i <= 1; i++) {
		for (int j = -1; j <= 1; j++) {
			int tx = x + j, ty = y + i;
			if (0 <= tx && tx <= 3 && 0 <= ty && ty <= 3 && !used[ty][tx] && m[ty][tx] == s[v][d]) {
				used[ty][tx] = 1;
				ret += rec(tx, ty, d + 1, v);
				used[ty][tx] = 0;
			}
		}
	}
	return ret;
}
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> s[i] >> a[i];
	for (int i = 0; i < 4; i++) cin >> m[i];
	cin >> T;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				if (m[j][k] == s[i][0]) {
					used[j][k] = 1;
					c[i] += rec(k, j, 1, i);
					used[j][k] = 0;
				}
			}
		}
	}
	int dp[10009] = { 0 };
	for (int i = 0; i < N; i++) {
		int x = c[i];
		for (int j = 1; x > 0; j <<= 1) {
			int mul = min(j, x);
			for (int k = T; k >= s[i].size() * mul; k--) dp[k] = max(dp[k], dp[k - s[i].size() * mul] + a[i] * mul);
			x -= mul;
		}
	}
	cout << dp[T] << endl;
	return 0;
}

Measured memory_bytes: 3200
h = int(input())
w = int(input())
n = int(input())

v  = 200 / 100

if n / max(h, w) - n // max(h, w) == 0:
    print(n // max(h, w))
elif n / max(h, w) == 1:
    print(1)
elif n / max(h, w) < 1:
    print(1)
else:
    print(n // max(h, w) + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int x=n%10;
    if(x==3)cout<<"bon"<<endl;
    else if(x==0||x==1||x==6||x==8)cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    double l;
    cin >> l;

    printf("%12.12lf\n", (l/3)*(l/3)*(l/3));
    return 0;
}

Measured memory_bytes: 256
var lines =[];

var readline = require("readline");
var rl = readline.createInterface({
  input:  process.stdin,
  output: process.stdout
});

rl.on('line',function(x){
  lines.push(x);
});

rl.on('close',function(){
 var n   = Number(lines[0]);
 var tmp = lines[1].split(" ");
 var l   = Array(n);
 var sum = 0;
 
 for(var i=0;i<n;i++){
     l[i]=Number(tmp[i]);
     sum=sum+l[i];
 }

 l.sort(function(a,b){return(b-a);});
 console.log(sum-l[0]>l[0]? "Yes":"No");
});

Measured memory_bytes: 7500
import itertools
n,k = map(int,input().split())
unlike = list(map(int,input().split()))
like = []
for i in range(0,10):
    if not(i in unlike):
        like.append(i)
i = 1
ans = 0
while(i < 99):
    current = list(itertools.product(like,repeat=i))
    for j in range(len(current)):
        h = int("".join(map(str,(list(current[j])))))
        if n <= h:
            print(h)
            exit()
    i += 1

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

char str[4] = {'M', 'T', 'S', 'H'};
int d[5] = {44, 14, 63, 28, 0};
int main(){
	int c, x, ans = 0, t = 1911;
	scanf("%d%d", &c, &x);
	if(!c){
		int i = 0;
		for(i;i < 4;i++){
			if(x <= t)break;
			t += d[i+1];
		}
		printf("%c%d\n", str[i], d[i]-(t-x));
	}else{
		for(int i = 0;i != c-1;i++)ans += d[i];
		printf("%d\n", ans+1868+x-1);
	}
	return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)


int main() {
    ll n, m, a;
    cin >> n >> m;
    priority_queue<ll> pq;
    rep1(i, n){
        cin >> a;
        pq.push(a);
    }
    ll num;
    rep1(i,m){
        num = pq.top(); pq.pop();
        num /= 2;
        pq.push(num);
    }
    ll ans = 0;
    while (!pq.empty()) {
        num = pq.top(); pq.pop();
        ans += num;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
using namespace std;
#define ll long long
#define inf (999999999)
#define fi first
#define se second
#define MOD 1e9+7
#define PI acos(-1.0)
//--------------------------------------------------------------------------------------------------//
int a[55];
int main() {
	int n,k;
	cin >> n>>k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	ll sum = 0;
	for (int i = 0; i < k; i++) {
		sum += a[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i=0;i<n;i++) a[i] = sc.nextInt();
    Arrays.sort(a);
    System.out.println(a[n-1]-a[0]);
  }
}

Measured memory_bytes: 21844
while True:
    input_line = input()
    n, x = [int(s) for s in input_line.split(' ') if s]
    if n == 0 and x == 0:break
    ret = 0
    for i in range(1,n-1):
        for j in range(i+1,n+1):
            if x-i-j > n or x-i-j <= j: 
                # print(i,j)
                continue
            else: 
                ret += 1
                # print(i,j,x-i-j)

    print(ret)


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

using namespace std;

int main(void) {
	int N;
	cin >> N;
	int res = 0;
	char c,prev = ' ';
	for (int i = 0; i < N; ++i) {
		cin >> c;
		if (c != prev) {
			++res;
			prev = c;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll N, K;
    cin >> N >> K;
    vector<ll>A, B;
    B.push_back(0);
    for(ll i = 0; i < N; i++){
        ll x;
        cin >> x;
        if(x == 0)K--;
        if(x < 0)A.push_back(-x);
        if(x > 0)B.push_back(x);
    }
    A.push_back(0);
    reverse(A.begin(), A.end());
    ll ans = 1000000000;
    for(ll i = 0; i <= K; i++){
        ll j = K - i;
        if(i >= A.size() || j >= B.size())continue;
        ans = min(ans, 2 * A[i] + B[j]);
        ans = min(ans, A[i] + 2 * B[j]);
        
    }
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(false);\
				cin.tie(0);\
				cout.tie(0)
#define REP(_i, _a) for(int _i = 0; _i < (int)_a; ++_i)
#define FOR(_i, _a, _b) for(int _i = (int)_a; _i <= (int)_b; ++_i)
#define FORD(_i, _a, _b) for(int _i = (int)_a; _i >= (int)_b; --_i)
#define RESET(_a, _value) fill_n(_a,sizeof(_a)/sizeof(_a[0]),_v)
#define ALL(_a) _a.begin(), _a.end()
#define SIZE(_a) _a.size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define newline '\n';

// DEBUG UTIL
#define DEBUG(args...) { cerr << "> "; \
						 string _s = #args; \
						 replace(_s.begin(), _s.end(), ',', ' '); \
						 stringstream _ss(_s); istream_iterator<string> _it(_ss); \
						 err(_it, args); }

void err(istream_iterator<string> it) { cerr << endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << ": " << a << " ";
	err(++it, args...);
}

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const int INF = 2e9;

const int MAX_N = 50;

int H, W;

bool visited[MAX_N+5][MAX_N+5];
char grid[MAX_N+5][MAX_N+5];

void test() {

}

void read() {
	cin >> H >> W;
	REP(i, H) {
		cin >> grid[i];
	}
}

void dfs(int i, int j) {
	visited[i][j] = true;
	if (j+1 < W && grid[i][j+1] == '#' && !visited[i][j+1]) dfs(i, j+1);
	if (j-1 >= 0 && grid[i][j-1] == '#' && !visited[i][j-1]) dfs(i, j-1);
	if (i+1 < H && grid[i+1][j] == '#' && !visited[i+1][j]) dfs(i+1, j);
	if (i-1 >= 0 && grid[i-1][j] == '#' && !visited[i-1][j]) dfs(i-1, j);
}

void solve() {
	REP(i, H) {
		REP(j, W-1) {
			if (grid[i][j] == '#' && grid[i][j+1] == '#' && !visited[i][j]) {
				dfs(i, j);
			}
		}
	}

	REP(i, H-1) {
		REP(j, W) {
			if (grid[i][j] == '#' && grid[i+1][j] == '#' && !visited[i][j]) {
				dfs(i, j);
			}
		}
	}

	REP(i, H) {
		REP(j, W) {
			if (grid[i][j] == '#' && !visited[i][j]) {
				cout << "No\n";
				return;
			}
		}
	}
	cout << "Yes\n";
}

int main() {
	FAST_IO;
	
	test();

	int TC = 1;
	// cin >> TC;
	FOR(tc, 1, TC) {
		read();
		solve();
	}

	return 0;
}


Measured memory_bytes: 384
#include <iostream>



using namespace std;

int N;



int main()
{

	cin >> N;

	long long ans = 0;


	for (int i = 1; i <= N ; i++) {
		if (i % 3 && i % 5) {
			ans += (long long)i;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200020],cnt[200020],ans[200020],res=0;
int main ()
{
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }

    for(ll i=1;i<=n;i++)
    {
        ans[i]=cnt[i]*(cnt[i]-1)/2;
        res+=ans[i];
    }
    for(ll i=1;i<=n;i++)
    {
        cout<<res-(cnt[a[i]]-1)<<endl;
    }
    return 0;
}



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

using ll = long long;
const ll amari = 1e9+7;
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	string s;
	cin >> s;
	string b = "",w = "";
	for(int i = 0; i < s.size(); i++){
		string bl = "0";
		string wh = "1";
		if(i % 2 == 0){
			b = b + bl;
			w = w + wh;
		}
		else{
			b = b + wh;
			w = w + bl;
		}
	}
	int bsum = 0;
	int wsum = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] != b[i])bsum++;

		if(s[i] != w[i])wsum++;
	}
	cout << min(bsum,wsum) << endl;
	return 0;
}
//g++

Measured memory_bytes: 904
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, M;
    cin >> N >> M;

    vector<vector<int>> G(N);
    vector<int> in(N, 0);
    rep(i, N + M - 1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        in[v]++;
    }

    int root;
    rep(i, N) {
        if (in[i] == 0) root = i; 
    }

    vector<int> ans(N, -1);
    queue<int> V;
    V.push(root);
    
    while (!V.empty()) {
        int v = V.front(); V.pop();
        rep(i, G[v].size()) {
            int to = G[v][i];
            in[to]--;
            if (in[to] == 0) {
                V.push(to);
                ans[to] = v;
            }
        }
    }

    rep(i, N) cout << ans[i] + 1 << endl;

    return 0;
}

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

void High(int* m)
{
	for (int i = 9; i > 0; i--)
	{
		for (int j = i - 1; j >= 0; j--)
		{
			if (m[i] > m[j])
			{
				int temp;
				temp = m[i];
				m[i] = m[j];
				m[j] = temp;
			}
		}
	}
}

int main(void)
{
	int m[10];

	for (int i = 0; i < 10; i++)
		cin >> m[i];
	High(m);
	for (int i = 0; i < 3; i++)
		cout << m[i] << endl;
	return 0;
}



Measured memory_bytes: 3120
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int i=0; i<t; i++) {
            solve(sc);
        }
    }
    static void solve(Scanner sc) {
        long n = sc.nextLong();
        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();
        long d = sc.nextInt();

        Set<Long> visited = new HashSet<>();
        PriorityQueue<Node> q = new PriorityQueue<>();
        q.offer(new Node(n, 0));
        long md = Long.MAX_VALUE / d;
        while(!q.isEmpty()) {
            Node node = q.poll();
            long num = node.n;
            if(visited.contains(num)) {
                continue;
            }
            visited.add(num);
            if(node.n == 1) {
                System.out.println(node.d + d);
                return;
            }
            if(num%2 == 0) {
                if(!visited.contains(num/2)) {
                    q.offer(new Node(num/2, node.d + Math.min(a, d * Math.min(md,num/2))));
                }
            } else {
                if(!visited.contains((num-1)/2)) {
                    q.offer(new Node((num-1)/2, node.d + d + Math.min(a, d *  Math.min(md,(num-1)/2))));
                }
                if(!visited.contains((num+1)/2)) {
                    q.offer(new Node((num+1)/2, node.d + Math.min(a + d, d * Math.min(md, (num - (num-1)/2)))));
                }
            }
            if(num%3 == 0) {
                if(!visited.contains(num/3)) {
                    q.offer(new Node(num/3, node.d + Math.min(b, d * Math.min(md, num/3 * 2))));
                }
            } else {
                int r = (int)(num % 3);
                int p = 3 - r;
                if(!visited.contains((num-r)/3)) {
                    q.offer(new Node((num-r)/3, node.d + Math.min(d * r + b, Math.min(md, (num-(num-r)/3)) * d)));
                }
                if(!visited.contains((num+p)/3)) {
                    q.offer(new Node((num+p)/3, node.d + Math.min(d * p + b, Math.min(md, (num-(num+p)/3)) * d)));
                }
            }
            if(num%5 == 0) {
                if(!visited.contains(num/5)) {
                    q.offer(new Node(num/5, node.d + Math.min(c, d * Math.min(md, (num - num/5)))));
                }
            } else {
                int r = (int)(num % 5);
                int p = 5 - r;
                if(!visited.contains((num-r)/5)) {
                    q.offer(new Node((num-r)/5, node.d + Math.min(d * r + c, Math.min(md, (num-(num-r)/5)) * d)));
                }
                if(!visited.contains((num+p)/5)) {
                    q.offer(new Node((num+p)/5, node.d + Math.min(d * p + c, Math.min(md, (num-(num+p)/5)) * d)));
                }
            }
        }

    }

    static class Node implements Comparable<Node>{
        long n;
        long d;
        Node(long n, long d) {
            this.n = n;
            this.d = d;
        }
        @Override
        public int compareTo(Node node) {
            return Long.compare(d, node.d);
        }
    }

}

Measured memory_bytes: 48580
/**
 *  author: sjay05
 *  date: 13.09.20 11:45:33
**/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  cout << (x == 0 ? 1 : 0) << '\n';
  return 0;
}



Measured memory_bytes: 3608
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
#include<deque>
#include<chrono>
using namespace std;
#define pi 3.141592653589793238


#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
typedef vector<ll> vi;
typedef vector<vi> vvi;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    
    //cin >> T;
    while (T--) {
        string s;
        cin >> s;
        cout << s.substr(0, 3) ;
    }

    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	string first, second, third;
	bool flag;
	cin >> first >> second >> third;
	flag = first.back() == second.front() && second.back() == third.front();
	cout << (flag ? "YES" : "NO") << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
def mark(a, b):
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                a[i][j] = 0


def check_h(a):
    for row in a:
        if row == [0, 0, 0]:
            return True


def check_v(a):
    for col in range(3):
        if [row[col] for row in a] == [0, 0, 0]:
            return True


def check_c(a):
    if [a[i][i] for i in range(3)] == [0, 0, 0] or [a[i][2 - i] for i in range(3)] == [0, 0, 0]:
        return True


def resolve():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    for _ in range(N):
        B = int(input())
        mark(A, B)
    if check_h(A) or check_v(A) or check_c(A):
        print("Yes")
    else:
        print("No")
resolve()

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

struct node
{
	long long a,b,c;
};
bool operator < (node x,node y)
{
	if(x.a!=y.a) return x.a<y.a;
	if(x.b!=y.b) return x.b<y.b;
	return x.c<y.c;
}

const int N=1e5+5;
int n,m,k,T;
long long a[N],b[N],c[N];
priority_queue<pair<long long,node> > q;
map<pair<long long,node>,int> M;

long long calc()
{
	int i;
	pair<long long,node> gg=q.top();q.pop();
	int A=gg.second.a,B=gg.second.b,C=gg.second.c;
	if(A<n)
	{
		pair<long long,node> pp;
		pp.first=a[A+1]+b[B]+c[C];
		pp.second.a=A+1;
		pp.second.b=B;
		pp.second.c=C;
		if(!M[pp]) q.push(pp),M[pp]=1;
	}
	if(B<m)
	{
		pair<long long,node> pp;
		pp.first=a[A]+b[B+1]+c[C];
		pp.second.a=A;
		pp.second.b=B+1;
		pp.second.c=C;
		if(!M[pp]) q.push(pp),M[pp]=1;
	}
	if(C<k)
	{
		pair<long long,node> pp;
		pp.first=a[A]+b[B]+c[C+1];
		pp.second.a=A;
		pp.second.b=B;
		pp.second.c=C+1;
		if(!M[pp]) q.push(pp),M[pp]=1;
	}
	return a[A]+b[B]+c[C];
}

int main()
{
	int i,j,x;
	scanf("%d%d%d%d",&n,&m,&k,&T);
	for(i=1;i<=n;++i) scanf("%lld",&a[i]);sort(a+1,a+n+1);reverse(a+1,a+n+1);
	for(j=1;j<=m;++j) scanf("%lld",&b[j]);sort(b+1,b+m+1);reverse(b+1,b+m+1);
	for(x=1;x<=k;++x) scanf("%lld",&c[x]);sort(c+1,c+k+1);reverse(c+1,c+k+1);
	
	pair<long long,node> pp;
	pp.first=a[1]+b[1]+c[1];
	pp.second.a=1,pp.second.b=1,pp.second.c=1;
	q.push(pp);
	long long ret=0;
	
	while(T--) printf("%lld\n",calc());
	return 0;
}

Measured memory_bytes: 1152
l,r=gets.split.map(&:to_i)
k=1
while 2019*k<l
  k+=1
end

if 2019*k<=r
  puts 0
else
  ans=10**19
  (l..r).to_a.combination(2) do |i,j|
    ans=[(i*j)%2019,ans].min
  end
  puts ans
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n,r;
	cin>>n>>r;
	if(n>10){
		cout<<r<<endl;
	}
	else{
		ll x=r;
		x+=(100*(10-n));
		cout<<x<<endl;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// const ll INF = 1e18;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll factorial(ll n) {
    ll x = 1;
    reps(i, n) {
        x *= i;
    }
    return x;
}

double distance(double xi, double xj, double yi, double yj) {
    return sqrt(pow(xi-xj,2)+pow(yi-yj,2));
}

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

    cin >> N;
    vector<double> x(N);
    vector<double> y(N);

    rep(i, N) {
        cin >> x[i];
        cin >> y[i];
    }

    double d[N][N];

    rep(i, N) {
        rep(j, N) {
            double dist = distance(x[i], x[j], y[i], y[j]);
            d[i][j] = dist;
            d[j][i] = dist;
        }
    }

    vector<ll> p(N);
    rep(i, N) {
        p[i] = i;
    }

    double sum = 0.0;
    do {
        rep(i, N-1) {
            sum += d[p[i]][p[i+1]];
        }
    } while(next_permutation(all(p)));

    double ans = sum/factorial(N);
    cout << setprecision(10) << ans << endl;

    return 0;
}


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


int main(){
    ll N;cin>>N;
    ll a[100010];
    rep(i,0,N)cin>>a[i];
    vector<pair<ll,ll> > ev(100010),od(100010);
    rep(i,0,N){
        if(i%2==0){
            ev.at(a[i]).first++;
            ev.at(a[i]).second=a[i];
        }
        else{
            od.at(a[i]).first++;
            od.at(a[i]).second=a[i];
        }
    }
    sort(ev.begin(),ev.end(),greater<>());
    sort(od.begin(),od.end(),greater<>());
    if(ev.at(0).second==od.at(0).second){
        cout<<min(N-ev.at(0).first-od.at(1).first,N-ev.at(1).first-od.at(0).first)<<endl;
    }
    else cout<<N-ev.at(0).first-od.at(0).first<<endl;
}






Measured memory_bytes: 4096
using System;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            new Program().calc();
        }
 
        Scanner cin;
        int R0, W0, C, R;
 
        void calc()
        {
            cin = new Scanner();
 
            for (;;)
            {
                R0 = cin.nextInt();
                W0 = cin.nextInt();
                C = cin.nextInt();
                R = cin.nextInt();
                if (R0 == 0) break;
 
                int X = 0;
                while (R0 + X * R < C * W0) ++X;
 
                Console.WriteLine(X);
 
            }
 
        }
    }
 
    class Scanner
    {
        string[] s;
        int i;
 
        char[] cs = new char[] { ' ' };
 
        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        public string next()
        {
            if (i < s.Length) return (s[i++]);
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return (next());
        }
        public int nextInt()
        {
            return (int.Parse(next()));
        }
        public long nextLong()
        {
            return (long.Parse(next()));
        }
        public double nextDouble()
        {
            return (double.Parse(next()));
        }
    }
 
}

Measured memory_bytes: 8916
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    ll a,b,k; cin >> a >> b >> k;
    if (k>a) {
        k -= a;
        a = 0;
        b -= k;
        if (b<0) b = 0;
    }
    else {
        a -= k;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>


using namespace std;

int main() {
	int N, P;
	string S;
	cin >> N >> P >> S;
	long long ans = 0;
	if (P == 2 || P == 5) {
		for (int i = 0; i < N; i++) {
			int x = S[i] - '0';
			if (x%P == 0) {
				ans += i + 1;
			}
		}
	}
	else {
		vector<int>mod(P, 0);
		long long ten = 1;
		vector<int>d(N + 1);
		for (int i = N-1; i >=0; i--) {
			int x = (S[i] - '0')*ten%P;
			d[i] = (d[i + 1] + x) % P;
			ten *= 10;
			ten %= P;
		}
		for (int i = N; i >= 0; i--) {
			ans += mod[d[i]];
			mod[d[i]]++;
		}

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

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

#define ld long double
const ld pi = acos(-1);
int N , L , arr[3003]; ld avex , avey;

int main(){
	cin >> N >> L; for(int i = 1 ; i <= N ; ++i) cin >> arr[i];
	
	for(int i = 1 ; i <= N ; ++i)
		for(int j = i + 1 ; j <= N ; ++j){
			int num = N - 2 - 2 * (j - i - 1);
			avex += num * cos(pi * (arr[i] + arr[j]) / L);
			avey += num * sin(pi * (arr[i] + arr[j]) / L);
		}

	avex = avex * 6 / N / (N - 1) / (N - 2);
	avey = avey * 6 / N / (N - 1) / (N - 2);
	cout << fixed << setprecision(10) << avex << ' ' << avey << endl; return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();

        int[] ls = new int[Q];
        int[] rs = new int[Q];
        for (int i = 0; i < Q; i++) {
            ls[i] = sc.nextInt() - 1;
            rs[i] = sc.nextInt() - 1;
        }

        char[] chars = S.toCharArray();
        int[] acCount = new int[N];
        int count = 0;
        for (int i = 1; i < S.length(); i++) {
            if (chars[i-1] == 'A' && chars[i] == 'C') {
                count++;
            }
            acCount[i] = count;
        }

        for (int i = 0; i < Q; i++) {
            int ans = acCount[rs[i]] - acCount[ls[i]];
            System.out.println(ans);
        }

    }

}

Measured memory_bytes: 82016
#include <iostream>
#include <map>
#include <queue>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> CP;

int main() {
    int w, h, count;
    int dx[] = {-1, 0, 1, 0};
    int dy[] = {0, -1, 0, 1};
    int wall[60][60];
    bool has_arrived[30][30];
    while (true) {
        queue<CP> q;
        cin >> w >> h;
        if (w == 0 && h == 0) {
            break;
        }
        for (int y=0; y<2*h-1; y++) {
            for (int x=0; x<w-1+y%2; x++) {
                cin >> wall[x][y];
            }
        }
        for (int y=0; y<h; y++) {
            for (int x=0; x<w; x++) {
                has_arrived[x][y] = false;
            }
        }
        q.push(CP(1, P(0, 0)));
        has_arrived[0][0] = true;
        while (q.size() > 0) {
            count = q.front().first;
            P pos = q.front().second;
            int x = pos.first;
            int y = pos.second;
            q.pop();
            if (x == w-1 && y == h-1) {
                break;
            }
            for (int i=0; i<4; i++) {
                int nx = x+dx[i];
                int ny = y+dy[i];
                if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
                    continue;
                }
                if (has_arrived[nx][ny]) {
                    continue;
                }
                if (wall[min(x, nx)][ny+y] != 0) {
                    continue;
                }
                q.push(CP(count+1, P(nx, ny)));
                has_arrived[nx][ny] = true;
            }
        }
        if (has_arrived[w-1][h-1]) {
            cout << count << endl;
        }
        else {
            cout << 0 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1228
#include <stdio.h>
int main(void){
    
    int m,r,f;
    while(1){
        scanf("%d %d %d",&m,&r,&f);
        
        if(m==-1&&r==-1&&f==-1)
        break;
    
        else if(m==-1||r==-1){
            printf("F\n");
        }
    
        else if((m+r)>=80){
            printf("A\n");
        }
    
        else if((m+r)>=65&&(m+r)<80){
            printf("B\n");
        }
    
        else if((m+r)>=50&&(m+r)<65){
            printf("C\n");
        }
   
        else if((m+r)>=30&&(m+r)<50){
            if(f>=50){
                printf("C\n");
            }
            else{
                printf("D\n");
        }
        }
   
   
        else if((m+r)<=30&&(m+r)>=0){
       
            printf("F\n");
        }
   
   
      
   
    }
    return 0;
}


Measured memory_bytes: 2072
a,b,c,d=map(int,input().split())
import fractions
#cとdの最小公倍数
lcm=c*d//fractions.gcd(c,d)
count1=b-(b//c+b//d-b//lcm)
count2=(a-1)-((a-1)//c+(a-1)//d-(a-1)//lcm)

print(count1-count2)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()

const int MAXN = 1e6 + 10;
ll k, n;
ll a[MAXN], pref[MAXN];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> k >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];
	for(int i = 2; i <= n; ++i) pref[i] = a[i] - a[i - 1];
	pref[1] = a[1] - a[n] + k;
	ll sum = accumulate(pref + 1, pref + n + 1, 0ll);
	ll ans = 1e18;
	for(int i = 1; i <= n; ++i) ans = min(ans, sum - pref[i]);
	cout << ans;
	return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n;

int main(void){
	scanf("%lld",&n);
	int ans=0;
	ll v=n;
	int dig=0;
	vector<ll> vec;
	while(v>0LL){
		vec.push_back(v%10LL);
		v/=10LL;
		dig++;
		ans+=9;
	}
	reverse(vec.begin(),vec.end());
	ans-=9;
	int now=0;
	for(int i=0;i<vec.size();i++){
		dig--;
		now+=vec[i];
		ans=max(ans,now);
		ans=max(ans,now+dig*9-1);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
K = int(input())

l = []

def c(depth, a, d):
    ans = 0
    if depth == d:
        l.append(a)
        return
    if int(a[-1]) - 1 >= 0:
        c(depth + 1, a + str(int(a[-1]) - 1), d)
    c(depth + 1, a + a[-1], d)
    if int(a[-1]) + 1 <= 9:
        c(depth + 1, a + str(int(a[-1]) + 1), d)
    return

for d in range(10):
    for i in range(1, 10):
        c(0, str(i), d)
        
print(l[K - 1])

Measured memory_bytes: 88432
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int main()
{	
   int t,i;
   int n[100005],x[100005],y[100005];
   int sum[100005];
   int flag=1;
   scanf("%d",&t);
   n[0]=0;
   x[0]=0,y[0]=0;
   for(i=1;i<=t;i++)
   {
   	scanf("%d %d %d",&n[i],&x[i],&y[i]);
   } 
   	for(i=1;i<=t;i++)
   	{
   	   	sum[i]=x[i]+y[i];
   	    if(n[i]<sum[i])
   	     flag=-1;
   	   	if(((n[i]-n[i-1])%2==0&&(x[i]+y[i]-x[i-1]-y[i-1])%2!=0)||(((n[i]-n[i-1])%2!=0&&(x[i]+y[i]-x[i-1]-y[i-1])%2==0)))
   	   	 flag=-1;
   }
   	if(flag == -1)
     	printf("No");
   	else
   	   printf("Yes");
	
	
	
	return 0;
}

Measured memory_bytes: 1280
#if 0

#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int A[30+10];
int N;

int main() {
  A[0] = 1; A[1] = 1; A[2] = 2;
  for (int i = 3; i <= 30; i++) {
    A[i] = A[i-1] + A[i-2] + A[i-3];
  }
  while (cin >> N && N) {
    cout << (((A[N]+10-1)/10)+365-1)/365 << endl;
  }
}



Measured memory_bytes: 3004
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <iomanip>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)
int main() {
	long long a,b;
	cin >> a >> b;
	if (a > 0) {
		cout << "Positive" << endl;
	}
	else if (b >= 0) {
		cout << "Zero" << endl;
	}
	else {
		int hoge = (abs(a) - abs(b));
		if (hoge % 2 == 0) {
			cout << "Negative" << endl;
		}
		else {
			cout << "Positive" << endl;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define debug cout<<"debug"<<endl;
const int maxn=1e6+10;
const ll inf=1e12+10;
using namespace std;

vector<ll> v;
map<ll,ll> mp;
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;	
}
int fastpow(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1) ans*=a;
		b>>=1;a*=a;
	}
	return ans;
}
int main()
{
	int T;
	T=1;
	while(T--)
	{
		mp.clear();
		v.clear();
		int n,m;
		ll ans=0;
		cin>>n>>m;
		ll gcdans=1,lcmans=0,maxn=0;
		for(int i=0;i<n;i++) 
		{
			ll x;cin>>x;
			x=x/2;
			if(mp[x]==0) 
			{
				v.push_back(x),mp[x]=1;
				maxn=max(maxn,x);
				if(i==0) lcmans=x;
				else lcmans=lcm(lcmans,x);	
			}
		} 
		ll temp=1;
		int flag=0;
		for(int i=0;i<v.size();i++)
		{
			if(lcmans/v[i]%2==0) flag=1;
		}
		if(lcmans>m) flag=1;
		if(flag) cout<<0<<endl;
		else 
		{
			temp=m/lcmans;
			ans=temp/2;
			if(temp&1) ans++;
			cout<<ans;			
		}
	}
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

int ans[101010];

int main(){
    int n; cin >> n;
    for(int i=1; i<=100; i++){
        for(int j=1; j<=100; j++){
            for(int k=1; k<=100; k++){
                ans[i*i+j*j+k*k+i*j+j*k+k*i]++;
            }
        }
    }
    for(int i=1; i<=n; i++) cout << ans[i] << "\n";
}

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  vector<bool> inc(n);
  int st = 0, ans = 0;
  for (int i = 1; i < n; ++i) {
    if (p[i] < p[i - 1]) {
      st = i;
    }
    if (i - st + 1 >= k) {
      if (!ans) {
        ans = 1;
      }
      inc[i - k + 1] = true;
    }
  }
  auto compute = [&](vector<int> &fill, auto func) {
    priority_queue<int, vector<int>, decltype(func)> q(func);
    for (int i = 0; i < k; ++i) {
      q.push(i);
    }
    for (int i = 0; i <= n - k; ++i) {
      q.push(i + k - 1);
      while (!q.empty() && q.top() < i) {
        q.pop();
      }
      fill[i] = p[q.top()];
    }
  };
  auto fmin = [&](int i, int j) {
    return p[i] < p[j];
  };
  auto fmax = [&](int i, int j) {
    return p[i] > p[j];
  };
  vector<int> mi(n - k + 1), ma(n - k + 1);
  compute(mi, fmax);
  compute(ma, fmin);
  for (int i = 0; i <= n - k; ++i) {
    if (!inc[i] && (i == 0 || !(mi[i - 1] == p[i - 1] && ma[i] == p[i + k - 1]))) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4452
N = int(input())
x = [list(map(int, input().split())) for i in range(N)]
sumx = 0

for i in range(N):
  for j in range(N):
    sumx += ((x[j][1] - x[i][1])**2 + (x[j][0] - x[i][0])**2) ** (1/2) 

ans = sumx / N
print(ans)

Measured memory_bytes: 3060
def solve():
    Sa = list(input())
    Sb = list(input())
    Sc = list(input())
    # print(Sa)
    turn = 'a'
    while True:
        if turn == 'a':
            if not Sa: break
            turn = Sa.pop(0)
        elif turn == 'b':
            if not Sb: break
            turn = Sb.pop(0)
        elif turn == 'c':
            if not Sc: break
            turn = Sc.pop(0)
            
    print(turn.upper())
    
solve()

Measured memory_bytes: 3060