akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[4];
    rep(i,2){
        cin >> A[i];
    }
    cout << ((A[1]-A[0])%(A[0]-1)==0 ? (A[1]-A[0])/(A[0]-1)+1 : (A[0]>A[1] ? 1 :(A[1]-A[0])/(A[0]-1)+2))  << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  



int main(){
  ll x; cin >> x;
  vector<ll> tar(1001);
  for(ll i=0; i<=1000; i++){
    tar.at(i) = i*i*i*i*i;
    //cout << tar[i] << endl;
  }
  for(int i=0; i<=1000; i++){
    for(int j=0; j<=1000; j++){
      if(x<tar[i]+tar[j]) break;
      if(x!=tar[i]+tar[j]) continue;
      cout << i << ' ' << -j << endl;
      return 0;
    }
  }
  for(int i=0; i<=1000; i++){
    for(int j=0; j<=1000; j++){
      if(tar[i]-tar[j]!=x) continue;
      cout << i << ' ' << j << endl;
      return 0;
    }
  }
  // for(int i=0; i<200; i++){
  //   for(int j=0; j<200; j++){
  //     cout <<tar[i]+tar[j] << ' ' << tar[i] << ' ' << tar[j] << endl;
  //     if(x<tar[i] && x<-tar[j]) continue;
  //     if(x<-tar[i] && x<tar[j]) continue;
  //     if(tar[i]-tar[j]!=x) continue;
  //     
  //     return 0;
  //   }
  // }
  //for(auto x: tar) cout << x << endl;
}

Measured memory_bytes: 3640
#include <iostream>
using namespace std;
  
int main(){
  int W,H,x,y,r;
  cin >> W>>H>>x>>y>>r;
 
  if (0<=x-r and x+r<=W and 0<=y-r and y+r <=H)
  cout << "Yes" << endl;
  else cout << "No" <<endl;
  
  return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void A();

int main()
{
	A();
	fflush(stdout);
	return 0;
}

static void A()
{
	std::string orgs;
	std::cin >> orgs;
	int A, B, C, D;
	
	A = orgs[0] - '0';
	B = orgs[1] - '0';
	C = orgs[2] - '0';
	D = orgs[3] - '0';

	std::string op1, op2, op3;
	int flag[3][2] = { { 1, -1}, { 1, -1}, { 1, -1} };
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				if ((A + B * flag[0][i] + C * flag[1][j] + D * flag[2][k]) == 7) {
					op1 = (flag[0][i] < 1) ? "-" : "+";
					op2 = (flag[1][j] < 1) ? "-" : "+";
					op3 = (flag[2][k] < 1) ? "-" : "+";
				}
			}
		}
	}
	printf("%d%s%d%s%d%s%d=7", A, op1.c_str(), B, op2.c_str(), C, op3.c_str(), D);
}

Measured memory_bytes: 3692
fun main(args: Array<String>) {
    val (H, N) = readInputLine().split(" ").map { it.toInt() }
    val AList = readInputLine().split(" ").map { it.toInt() }

    println(if (AList.sum() >= H) "Yes" else "No")
}

fun readInputLine(): String {
    return readLine()!!
}


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

struct node{
  int key;
  struct node *parent;
  struct node *left;
  struct node *right;
};

typedef struct node * Node;

Node root;

void Insert(int);
void Preorder(Node);
void Inorder(Node);

int main(){
  int i, m, k;
  char in[20];

  scanf("%d",&m);
  for(i = 0; i < m; i++){
    scanf("%s",in);
    if(in[0] == 'i'){
      scanf("%d",&k);
      Insert(k);
    }
    if(in[0] == 'p'){
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
  }

  return 0;
}

void Insert(int k){
  Node y = NULL;
  Node x = root;
  Node v;

  v = malloc(sizeof(struct node));
  v->key = k;
  v->parent = NULL; 
  v->left = NULL;
  v->right = NULL;

  while(x != NULL){
    y = x;
    if(v->key < x->key) x = x->left;
    else x = x->right;
  }

  v->parent = y;

  if(y == NULL) root = v;
  else if(v->key < y->key) y->left = v;
  else y->right = v;

}

void Preorder(Node u){
  printf(" %d", u->key);

  if(u->left != NULL) Preorder(u->left);
  
  if(u->right != NULL) Preorder(u->right);

}

void Inorder(Node u){

  if(u->left != NULL) Inorder(u->left);
  printf(" %d",u->key);

  if(u->right != NULL) Inorder(u->right);
}

Measured memory_bytes: 24040
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var A = one[1];
	var list = nextIntArray();
	var dp = {0 : {0 : 0}};
	for(var i = 0; i < N; i++){
		var maiDp = makeClone(dp);
		var keys = Object.keys(dp).map(Number);
		for(var j = 0; j < keys.length; j++){
			var sumDp = dp[keys[j]];
			var sumKey = Object.keys(sumDp).map(Number);
			for(var k = 0; k < sumKey.length; k++){
				if(maiDp[j + 1] == null){
					maiDp[j + 1] = {};
				}
				if(maiDp[j + 1][sumKey[k] + list[i]] == null){
					maiDp[j + 1][sumKey[k] + list[i]] = 0;
				}
				maiDp[j + 1][sumKey[k] + list[i]] += dp[j][sumKey[k]];
			}
		}
		if(maiDp[1][list[i]] == null){
			maiDp[1][list[i]] = 1;
		}else{
			maiDp[1][list[i]]++;
		}
		dp = maiDp;
		//myerr(dp);
	}
	var output = 0;
	var keys = Object.keys(dp);
	for(var i = 1; i < keys.length; i++){
		if(dp[i][i * A] != null){
			output += dp[i][i * A];
		}
	}
	myout(output);
}


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

int main() {
    int n;
    scanf("%d", &n);
    vector<double> dp(n+1, 0.0);
    vector<double> temp(n+1, 0.0);
    dp[0] = 1.0;
    for (int i=1; i<=n; i++) {
        double p;
        scanf("%lf", &p);
        temp[0] = dp[0]*(1.0-p);
        for (int j=1; j<=i; j++) {
            temp[j] = dp[j]*(1.0-p)+dp[j-1]*p;
        }
        for (int i=0; i<=n; i++) {
            dp[i] = temp[i];
        }
    }
    int l = (n+1)>>1;
    double ans = 0;
    for (int i = l; i<=n; i++) {
        ans += dp[i];
    }

    printf("%.12lf\n", ans);
}

Measured memory_bytes: 384
from math import ceil
from collections import defaultdict as dd
import sys
input=sys.stdin.readline
#t=int(input())
#while t:
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=l[0]
ii=1
cou=0
for i in range(2,n):
    if(cou==2):
        ii+=1
        cou=0
    ans+=l[ii]
    cou+=1
print(ans)


Measured memory_bytes: 104168
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  vector< int > d(n);
  ul mod=998244353;
  for (int i=0; i<n; ++i) cin >> d[i];
  if (d[0]!=0) {
    cout << 0 << endl;
    return 0;
  }
  vector< int > dc(n);
  int dmax=0;
  for (int i=0; i<n; ++i) {
    dmax=max(dmax, d[i]);
    dc[d[i]]++;
  }
  if (dc[0] > 1) {
    cout << 0 << endl;
    return 0;
  }
  ul ans = 1;
  for (int i=1; i<=dmax; ++i) {
    if (dc[i]==0) {
      cout << 0 << endl;
      return 0;
    }
    for (int j=0; j<dc[i]; ++j) {
      ans *= dc[i-1];
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    int num[3];
    int difference;
    int f = 0;
    cin>>num[0]>>num[1]>>num[2];
    sort(num,num+3,greater<int>());
    difference = (num[0] - num[1]) + (num[0] - num[2]);
    if(difference%2 == 1){
        num[0]+=1;
        num[1]+=1;
        difference = (num[0] - num[1]) + (num[0] - num[2]);
        f = 1;
    }
    cout<<difference/2 + f<<endl;

    
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,M,K = I()
A = l()
B = l()
ruiseki = [-1]+list(itertools.accumulate(A))
num = 0
ans = bisect.bisect_right(ruiseki,K)-1
for i in range(M):
    num += B[i]
    if num > K:
        break
    ans = max(ans,bisect.bisect_right(ruiseki,K-num)+i)
print(ans)

Measured memory_bytes: 124740
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;    
typedef long long ll;
#define int long long
const int mod = 1000000007;

int get(int n)
{
    return n * (n - 1) / 2;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    
    
    int n;
    cin >> n;
    
    vector<vector<int>> cnt(n, vector<int>(26, 0));
    map<vector<int>, int> mp;
    for(int i = 0; i < n; ++ i)
    {
        string s;
        cin >> s;
        for(int j = 0; j < s.length(); ++ j)
        {
            ++ cnt[i][s[j] - 'a'];
        }
        ++ mp[cnt[i]];
    }
    int ans = 0;
    for(auto temp : mp)
    {
//        debug(temp.second);
        ans += get(temp.second);
    }
    
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 54144
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	double xa, ya, xb, yb, xc, yc, xd, yd,s1,s2,s3,s4;
	while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF) {
		s1=abs((xc - xa)*(yb - ya) - (xb - xa)*(yc - ya));
		s2 = abs((xc - xa)*(yd - ya) - (xd - xa)*(yc - ya));
		s3 = abs((xb - xa)*(yd - ya) - (xd - xa)*(yb - ya));
		s4 = abs((xb - xc)*(yd - yc) - (xd - xc)*(yb - yc));
		if (s1 + s2 == s3 + s4) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3268
from collections import Counter

def myAnswer(N:int,A:list)-> None:
   dic = Counter(A)
   total =0
   for value in dic.values():
      total += value * (value -1) //2
   for a in A:
      print(total - (dic[a]-1))


def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   myAnswer(N,A[:])
if __name__ == '__main__':
   main()

Measured memory_bytes: 26772
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(n-k):
        if a[i+k] > a[i]:
            print('Yes')
        else:
            print('No')
        
    
        
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 31756
import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions
from operator import itemgetter

import sys
def input():
	return sys.stdin.readline().strip()

H, W = list(map(int, input().split()))

A = []
for i in range(H):
	A.append(input())

num = [[0]*W for _ in range(H)]
black_list = deque()
for i in range(H):
	for j in range(W):
		if A[i][j] == ".":
			num[i][j] = 1000000
		else:
			black_list.append((i, j))
dxy = [(-1, 0), (1, 0), (0, -1), (0, 1)]

max_num = 0
while len(black_list) > 0:
	i, j = black_list.popleft()
	for n in range(4):
		x = i + dxy[n][0]
		y = j + dxy[n][1]
		if x < H and y < W and 0 <= x and 0 <= y:
			if num[x][y] > 10000:
				num[x][y] = num[i][j] + 1
				black_list.append((x, y))
				max_num = max(max_num, num[x][y])

print(max_num)

Measured memory_bytes: 111704
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;

int a[8][2];
vector<int> b(0);
double sum;

double f(int i){
    double ans=0;
    ans = pow((a[b[i]][0] - a[b[i+1]][0]), 2) + pow((a[b[i]][1] - a[b[i+1]][1]), 2);
    return pow(ans, 0.5);
}

int main()
{
    int n; cin >> n;
    //int a[n][2];
    rep(i,n){
        cin >> a[i][0]; cin >> a[i][1];
    }
    rep(i,n) b.pb(i);
    int c = 0;

    do {
        ++c;
        for (int i = 0; i < n - 1; i++) {
            sum += f(i);
        }
    }while (next_permutation(all(b)));   

    double d = sum / c;
    cout << fixed << setprecision(10);
    cout << d << endl;   
}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ code.cpp
./a.out

サンプルのダウンロードは oj d URL
テストは oj t
*/

Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 2005

int H,W;
int U[SIZE][SIZE],D[SIZE][SIZE],L[SIZE][SIZE],R[SIZE][SIZE];
char buf[SIZE][SIZE];


int main(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){

		scanf("%s",buf[row]);
	}

	//Uを計算
	for(int col = 0; col < W; col++){

		if(buf[0][col] == '.'){

			U[0][col] = 0;
		}
	}
	for(int row = 1; row < H; row++){
		for(int col = 0; col < W; col++){
			if(buf[row][col] != '.')continue;

			if(buf[row-1][col] == '.'){

				U[row][col] = U[row-1][col]+1;

			}else{

				U[row][col] = 0;
			}
		}
	}

	//Dを計算
	for(int col = 0; col < W; col++){

		if(buf[H-1][col] == '.'){

			D[H-1][col] = 0;
		}
	}
	for(int row = H-2; row >= 0; row--){
		for(int col = 0; col < W; col++){
			if(buf[row][col] != '.')continue;

			if(buf[row+1][col] == '.'){

				D[row][col] = D[row+1][col]+1;

			}else{

				D[row][col] = 0;
			}
		}
	}

	//Lを計算
	for(int row = 0; row < H; row++){

		if(buf[row][0] == '.'){

			L[row][0] = 0;
		}
	}
	for(int col = 1; col < W; col++){
		for(int row = 0; row < H; row++){
			if(buf[row][col] != '.')continue;

			if(buf[row][col-1] == '.'){

				L[row][col] = L[row][col-1]+1;

			}else{

				L[row][col] = 0;
			}
		}
	}

	//Rを計算
	for(int row = 0; row < H; row++){

		if(buf[row][W-1] == '.'){

			R[row][W-1] = 0;
		}
	}

	for(int col = W-2; col >= 0; col--){
		for(int row = 0; row < H; row++){
			if(buf[row][col] != '.')continue;

			if(buf[row][col+1] == '.'){

				R[row][col] = R[row][col+1]+1;

			}else{

				R[row][col] = 0;
			}
		}
	}

	int ans = 0;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			if(buf[row][col] != '.')continue;

			ans = max(ans,U[row][col]+D[row][col]+L[row][col]+R[row][col]+1);
		}
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 66944
import fractions

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

def saiki(n , t , maxi):

    saikimaxi = 0
    for i in range(n):
        if maxi % t[i] != 0:
            saikimaxi = max(saikimaxi , t[i])

    if saikimaxi != 0:
        return saiki(n , t , lcm(maxi , saikimaxi))
    else:
        return maxi

def multiclocks(n , t):

    maxi = max(t)
    return saiki(n , t , maxi)

def main():
    n = int(input())
    t = [int(input()) for i in range(n)]
    print(multiclocks(n , t))

if __name__ == '__main__':
    main()

Measured memory_bytes: 65388
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
vector<int>ansl;
string s;
int ary[100005] = {0};
int main(){
  int N,flgL = 0,flgR = 0, prc = 0;
  string lu = "lu",ru = "ru", ld = "ld",rd = "rd";

  cin >>N;

  while(N != 0){
    int cnt = 0;
    flgL = 0,flgR = 0, prc = 0;

    for(int i = 0;i<N;i++){
      string foot;
      int nwp = prc;

      cin >>foot;
      if(foot == "lu")flgL = 1;
      if(foot == "ru")flgR = 1;
      if(foot == "ld")flgL = 0;
      if(foot == "rd")flgR = 0;

      if((flgL == 1)&&(flgR == 1))prc = 1;
      if((flgL == 0)&&(flgR == 0))prc = 0;

      if(nwp != prc)cnt++;
    }
    ansl.push_back(cnt);

    cin >>N;
  }

  for(int i = 0;i<(int)ansl.size();i++){
    cout <<ansl[i]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3080
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, k = tin()
	#s = input()
	ret = min(k, n % k, k-(n%k))
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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


void solve(long long X, long long Y, long long Z){
    cout << Z << " " << X << " " << Y << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    solve(X, Y, Z);
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter
input = sys.stdin.readline

N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N-1, -1, -1):
    remain = B[i]
    if remain <= A[i+1]:
        ans += remain
        remain = 0
    else:
        ans += A[i+1]
        remain -= A[i+1]
    if remain <= A[i]:
        ans += remain
        A[i] -= remain
    else:
        ans += A[i]
        A[i] = 0

print(ans)

Measured memory_bytes: 19008
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    LL n, k, q;
    cin >> n >> k >> q;
    vector<LL> a(n+1);
    for(int i = 0; i < q; ++i) {
        int x; cin >> x;
        a[x]++;
    }
    for(int i = 1; i <= n; ++i) cout << (k-q+a[i] > 0?"Yes":"No") << "\n";
    
}


int main() {
    //freopen("input", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3972
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import Counter
from pprint import pprint

def myinput():
    return map(int,input().split())

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n = int(input())
s = [ input() for _ in range(n) ]
m = int(input())
t = [ input() for _ in range(m) ]

sc = Counter(s)
sck = list(sc.keys())
scv = list(sc.values())
# print(sc,sck,scv)
tc = Counter(t)
tck = list(tc.keys())
tcv = list(tc.values())
# print(tc,tck,tcv)

ans = 0
for i in range(len(sc)):
    w = sck[i]
    p = scv[i]
    # print(w,p)
    p2 = tc[w]
    # print(p2)
    M = p - p2
    ans = max(ans,M)
print(ans)

Measured memory_bytes: 39024
N = input()

N = int(N[-1])

if N == 2 or N == 4 or N == 5 or N == 7 or N == 9:
        print("hon")
elif N == 0 or N == 1 or N == 6 or N == 8:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9176
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define output(x) cout<<x<<endl
#define int long long
typedef long long ll;
ll dp[3005][3005];

#define NUM 1000000007

struct _chunk {
	int connect;
	int dist;
	int color;
};

int factorial(int num1, int num2){
    int sum = 1;
    if (num2 < num1-num2) {
    	 num2 = num1-num2;
    }
    for (int i = num1; i > num2; i--)
    {	
        sum *= i;
    }
    
    for (int i = num1-num2; i >= 1; i--) {
    	sum /= i;
    }

    return sum%NUM;
}

signed main(void) {
  int N, K;
  cin >> N >> K;

  rep(i, 3005) {
  	dp[i][0] = 1;
  }
  for(int i = 1; i < 3005; i++) {
  	for(int j = 1; j <= i; j++) {
  		dp[i][j] = (dp[i-1][j-1] + dp[i-1][j])%NUM;
  	}
  }
  for (int i=1; i<=K; i++) {
  	// separate blue in i chunk
  	int blueNum = dp[N-K+1][i];
 
  	// insert red
  	int redNum = dp[K-1][i-1];
 
  	int ans = blueNum * redNum % NUM;
  	
  	cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 69248
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

double EPS = 1e-10;
double PI = 3.141592653589793238462643383279;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }
};

struct circle{
  point p;
  double r;
};

double dot(point a, point b){return (a.x * b.x + a.y * b.y);}
double cross(point a, point b){return (a.x * b.y - a.y * b.x);}
double norm(point a){return sqrt(a.x*a.x+a.y*a.y);}

double dist(point a,point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

double distance_ls_p(point a, point b, point c) {
    if ( dot(b-a, c-a) < EPS ) return norm(c-a);
    if ( dot(a-b, c-b) < EPS ) return norm(c-b);
  return abs(cross(b-a, c-a)) / norm(b-a);
}

int crossCS(point a, point b, circle c){
  double res=distance_ls_p(a,b,c.p);
  double ac=dist(a,c.p);
  double bc=dist(b,c.p);

  if(res>c.r || (ac<c.r && bc<c.r))return 0;
  else if(c.r-res<EPS ||(ac<c.r && bc>=c.r)||(ac>=c.r && bc<c.r))return 1;
  else return 2;
}

int main(void){
  int n,m;
  circle c[100];
  point t,s;

  while(cin >> n,n){
    for(int i=0;i<n;i++)
      cin >> c[i].p.x >> c[i].p.y >> c[i].r;
    
    cin >> m;
    for(int i=0;i<m;i++){
      cin >> t.x >> t.y >> s.x >> s.y;

      int fg=0;
      for(int j=0;j<n;j++)fg+=crossCS(t,s,c[j]);
      
      if(fg==0)cout << "Danger" << endl;
      else cout << "Safe" << endl;
    }
  }
  return 0;
}

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

int n, dp[100005][3] = {0}, abc[3];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
            cin >> abc[j];
        for(int j = 0; j < 3; j++)
            for(int k = 0; k < 3; k++)
                if(j != k)
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[j]);
    }
    int ans = 0;
    for(int i = 0; i < 3; i++)
        ans = max(ans, dp[n][i]);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1408
N, T = map(int, input().split())
A = list(map(int, input().split()))


m = 0
_mini = A[0]
for i in range(1, N):
    _mini = min((_mini, A[i]))
    m = max((m, A[i] - _mini))

ans = 0
mini = A[0]
for i in range(1, N):
    mini = min((mini, A[i]))
    if m == (A[i] - mini):
        ans += 1
print(ans)



Measured memory_bytes: 15020
# https://atcoder.jp/contests/agc041/tasks/agc041_a¥

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

if (b - a) % 2 == 0:
    ans = (b - a) // 2
else:
    ans = min(a - 1, n - b) + 1 + (b - a - 1) // 2
print(ans)

Measured memory_bytes: 38256
int main(){
	char str[200010];
	char lett;
	int len = 0, count = 0;
	scanf("%c", &lett);
	while(lett != '\n'){
		len++;
		str[len] = lett;
		scanf("%c", &lett);
	}
	for(int i = 1; i <= len; i++){
		scanf("%c", &lett);
		if(lett != str[i])
			count++;
	}
	printf("%d", count);
	
	return 0;
}

Measured memory_bytes: 1828
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>

namespace n91 {

void main_() {
  usize n;
  std::cin >> n;
  usize ans = 0_z;
  for (const auto i : rep(1_z, n + 1_z)) {
    usize t = i;
    usize count = 0_z;
    while (t != 0_z) {
      t /= 10_z;
      ++count;
    }
    if (count % 2_z == 1_z) {
      ++ans;
    }
  }
  std::cout << ans << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 256
h,w=list(map(int,input().split()))
rows = [input() for i in range(h)]
grid = [list(row) for row in rows]

expanded_grid = []
expanded_grid.append(list('&'*(w+2)))
for row in rows:
    expanded_grid.append(list('&'+row+'&'))
expanded_grid.append(list('&'*(w+2)))

judge = True

for i in range(h):
    for j in range(w):
        if (grid[i])[j] == '#':
            nearby = [
                
                (expanded_grid[i])[j+1],
                

                (expanded_grid[i+1])[j],
                (expanded_grid[i+1])[j+2],

                
                (expanded_grid[i+2])[j+1]
                
            ]   

            if nearby.count('#') == 0:
                judge = False


if judge:
    print('Yes')
else:
    print('No')









Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if(s.size()==2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

const int _n = 1e5 + 10;
vector<int> Fact(_n), Inv(_n);
const int kmod = 1000000007;

int mul(int a, int b, int mod = kmod)
{
    return (long long)a * b % mod;
}

int add(int a, int b, int mod = kmod)
{
    a += b;
    if (a >= mod)
        a -= mod;
    return a;
}

int sub(int a, int b, int mod = kmod)
{
    a -= b;
    if (a < 0)
        a += mod;
    return a;
}

int power(int base, int index, int mod = kmod)
{
    if (index == 0)
        return 1;
    int temp = power(base, index / 2, mod);
    temp = mul(temp, temp, mod);
    if (index & 1)
        temp = mul(temp, base, mod);
    return temp;
}

int mod_inv(int x, int mod = kmod)
{
    return power(x, kmod - 2);
}

void pre()
{
    Fact[0] = 1;
    for (int i = 1; i < _n; ++i)
        Fact[i] = mul(Fact[i - 1], i);
    Inv[_n - 1] = mod_inv(Fact[_n - 1]);
    for (int i = _n - 2; i >= 0; --i)
        Inv[i] = mul(Inv[i + 1], (1 + i));
}

int ncr(int n, int r)
{
    if (n < 0 || r < 0 || n - r < 0)
        return 0;
    return mul(Fact[n], mul(Inv[r], Inv[n - r]));
}

class Solution
{
private:
public:
    Solution()
    {
        pre();
    }
    ~Solution() {}
    void solveCase()
    {
        int n;
        cin >> n;
        vector<int> prefSum(n + 1);
        for (size_t i = 1; i <= n; i++)
            prefSum[i] = add(prefSum[i - 1], mod_inv(i));
        int res = 0;
        vector<int> X(n);
        for (auto &x : X)
            cin >> x;
        for (size_t i = 1; i < n; i++)
            res = add(res, mul(prefSum[i], X[i] - X[i - 1]));
        res = mul(res, Fact[n - 1]);
        cout << res << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

Measured memory_bytes: 1792
s = int(input())
l = [s]
i = 2
while True:
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
    if l.count(s) == 1:
        print(i)
        break
    else:
        l.append(s)
        i += 1

Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
N, M=input().split()
N=int(N)
M=int(M)
i=0
katu_list=[]
katu_sublist=[]
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
for i in range(M):
 katu_list.append(i+1)
#print(katu_list)
#for i in range(N)
food_list =  [list(map(int, input().split(" ")))for i in range(N)]
#x=[]
#y=[]
#t, x, y = [0]*(N+1), [0]*(N+1), [0]*(N+1)#N+1個の空のリストを作成(原点を入れて##るから一つ増える)
#delta_t=0
#delta_x=0
#delta_y=0
#l=0
#t[0],x[0],y[0]=[0, 0, 0]
#とりあえず入力までは完成した．
#for i in range(N):
# t[i+1], x[i+1], y[i+1] = map(int, input().split())
#child_i =  list(map(int, input().split()))
#w_len=len(w)
#w_list=list(w)
#print(len(w_list))
#print(w_list)
#child_il=sorted(child_i)
#print(child_il)#リストの右端のほうが大きい
i=0
j=0
k=0
l=0
for i in range(N):#N人の人に聞くところ
 #print(katu_sublist)
 #katu_list=katu_sublist   
 #M=len(katu_list)   
 for j in range(food_list[i][0]):
  for k in range(M):
   if food_list[i][j+1]==katu_list[k]:
     katu_sublist.append(katu_list[k])
     #print(katu_sublist)
   else:
       pass
#リストの中身を一旦空っぽにして再度作り上げる
 katu_list=[]
 for l in range(len(katu_sublist)):
   katu_list.append(katu_sublist[l])
 M=len(katu_list)
 katu_sublist=[]#空にしないと貯まるばかり
print(len(katu_list))


Measured memory_bytes: 3188
#include<cstdio>
using namespace std;
const int Mod=1e9+7;
int n,size[5100];
int f[5100][5100],g[5100],tmp[5100];
int edgenum=1,vet[11000],Next[11000],Head[5100];
void addedge(int u,int v){
    vet[++edgenum]=v;
    Next[edgenum]=Head[u];
	Head[u]=edgenum;
}
void dfs(int u,int fa){
	f[u][size[u]=1]=1; int v;
	for (int e=Head[u];e;e=Next[e]){
		v=vet[e];
		if (v!=fa){
			dfs(v,u);
			for (int i=1;i<=size[u]+size[v];i++) tmp[i]=0;
			for (int i=1;i<=size[u];i++)
				for (int j=0;j<=size[v];j++)
					(tmp[i+j]+=1ll*f[u][i]*f[v][j]%Mod)%=Mod;
			for (int i=1;i<=size[u]+size[v];++i) f[u][i]=tmp[i];
			size[u]+=size[v];
		}
	}
	for (int i=2;i<=size[u];i+=2) (f[u][0]+=Mod-1ll*f[u][i]*g[i]%Mod)%=Mod;
}
 
int main(){
	scanf("%d",&n); g[0]=1;
	for (int i=2;i<=n;i+=2) g[i]=1ll*g[i-2]*(i-1)%Mod;
	int u,v;
	for (int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		addedge(u,v); addedge(v,u);
	}
	dfs(1,0);
	printf("%d\n",Mod-f[1][0]);
	return 0;
}

Measured memory_bytes: 100224
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
int main(){
	ll N;
	cin>>N;
	vll A;
	for(int i=0;i<N;i++){
		ll a;
		cin>>a;
		A.pb(a);
	}
	//最初は0
	if(A[0]!=0){
		cout<<-1<<endl;
		return 0;
	}
	ll ans=0;
	//最初から見ていく
	for(int i=1;i<N;i++){
		//2以上昇ってたら無理
		if(A[i]-A[i-1]>=2){
			cout<<-1<<endl;
			return 0;
		}
		//1昇ってたら、1を足す
		if(A[i]==A[i-1]+1)
			ans++;
		//そうでないなら、その数を足す
		else
			ans+=A[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
	string str;
	cin >> str;

	bool a = false, b = false, c = false;
	for (int i = 0; i < 3; i++)
	{
		switch (str[i])
		{
		case 'a':
			a = true;
			break;
		case 'b':
			b = true;
			break;
		case 'c':
			c = true;
			break;
		}

	}
	cout << ((a && b && c) ? "Yes" : "No") << endl;
	return 0;
}


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

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

    int res = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 == 1) {
            res++;
        }
    }

    if (res % 2 == 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 640
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long a = lread();
    long b = lread();
    long h = lread();
    writeln((a + b) * h / 2);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a,b,j;
  while(1){
  scanf("%d %d",&a,&b);
  if(a==0&&b==0){
    break;
  }
 int i, j;
     for ( j = 0; j < a; j++ ){
 for ( i = 0; i < b; i++ ){
         if(j==0||j==a-1||i==0||i==b-1        ){
             printf("#");
         } else {
             printf(".");
         }
     }
     printf("\n");
 }
  printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2104
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[allow(unused_macros)]
macro_rules ! vec_md { ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) } ; ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] } ; ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] } ; }

#[allow(dead_code)]
pub const M: u64 = 1_000_000_007;

fn main() {
    input! {
        s: chars
    }
    let n = s.len();
    let mut dp = vec_md![0u64;n+1;4];
    dp[0][0] = 1;
    for i in 0..n {
        let k = if s[i] == '?' {3} else {1};
        for j in 0..4 {
            dp[i+1][j] = dp[i][j] * k;
            dp[i+1][j] %= M;
        }
        match s[i] {
            '?' => {
                for j in 0..3 {
                    dp[i+1][j+1] += dp[i][j]; 
                    dp[i+1][j+1] %= M;
                }
            },
            _ => {
                let x = (s[i] as u8 - b'A') as usize;
                dp[i+1][x+1] += dp[i][x];
                dp[i+1][x+1] %= M;
            }
        }
    }
    println!("{}", dp[n][3]);
}


Measured memory_bytes: 10492
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

const int CN = 1e5+5;

int n,l[CN],r[CN],id[CN],mnr,pr,mxl,pl;
long long ans = 0;

long long d(int cl,int cr) {return 1ll * max(0, cr - cl + 1);}
bool cmp(int x,int y){
	return d(mxl, r[x]) != d(mxl, r[y]) ? 
	       d(mxl, r[x]) < d(mxl, r[y]) : 
		   d(l[x], mnr) > d(l[y], mnr);
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&l[i],&r[i]);
	
	mnr = 0x7f7f7f7f;
	for(int i=1;i<=n;i++) if(r[i] < mnr) mnr = r[pr = i];
	mxl = 0;
	for(int i=1;i<=n;i++) if(l[i] > mxl) mxl = l[pl = i];
	
	/* in same */
	for(int i=1;i<=n;i++)
	    if(i != pl && i != pr) ans = max(ans, d(mxl, mnr) + d(l[i], r[i]));
	
	/* in diff */
	for(int i=1;i<=n;i++) id[i] = i;
	sort(id + 1, id + n + 1, cmp);
	int premxl = 0;
	for(int i=2;i<=n;i++){
		premxl = max(premxl, l[ id[i - 1] ]);
		ans = max(ans, d(mxl, r[ id[i] ]) + d(premxl, mnr));
	}
	
	printf("%lld",ans);
	
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    cout << (A ^ B ^ 1 ^ 2 ^ 3) << endl;

    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

vector<int>E[5000];
bool used[5000];
int match[5000];
int N;

bool dfs(int u){
	used[u] = true;
	for(int v:E[u]){
		int w=match[v];
		if (w==-1||(!used[w]&&dfs(w))){
			match[u]=v;match[v]=u;
			return true;
		}
    }
    return false;
}
int matching(){
	memset(match,-1,sizeof(match));
	int ans=0;
	for(int i=0;i<N;i++){
		if(match[i]==-1) {
			memset(used,0,sizeof(used));
			if(dfs(i))ans++;
		}
	}
	return ans;
}
int a[500],b[500],c[500],d[500];
signed main(){
	int n;scanf("%d",&n);
	N=n*2;
	rep(i,n){
		scanf("%d%d",&a[i],&b[i]);
	}
	rep(i,n){
		scanf("%d%d",&c[i],&d[i]);
	}
	rep(i,n)rep(j,n){
		if(a[i]<c[j]&&b[i]<d[j]){
			E[i].push_back(j+n);
			E[j+n].push_back(i);
		}
	}
	cout<<matching()<<endl;
}

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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    
    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ h, w ] <- readInts
	board <- replicateM h getLine
	mapM_ putStrLn $ concatMap ( replicate 2 ) board


Measured memory_bytes: 1276
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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;}

#define rep(i,n) for(int i=0;i<(n);i++)

int main(){
    int N,T,min=9999999;
    cin>>N>>T;
    int c[N],t[N];
    rep(i,N) {
        cin>>c[i]>>t[i];
        if(t[i]<=T&&min>c[i]) min=c[i];
    }
    if(min==9999999) {
        cout<<"TLE"<<endl;
        return 0;
    }
    cout<<min<<endl;
    return 0;
}

//a=97,z=122

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

int n, m;

const int maxn = 805;
string s[maxn];
int dis[maxn][maxn];

int K;

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
const int INF = 0x3f3f3f3f;

bool in(int x, int y){
    return x >= 0 and x < n and y >= 0 and y < m;
}

void bfs(vector<pi> st){
    memset(dis, 0x3f, sizeof(dis));
    queue<pi> q;
    for(auto v : st){
        q.push(v);
        dis[v.fi][v.se] = 0;
    }
    while(!q.empty()){
        pi p = q.front(); q.pop();
        int x = p.fi;
        int y = p.se;
        for(int k = 0;k < 4;k++){
            int nx = x + dx[k];
            int ny = y + dy[k];
            if(in(nx, ny)){
                if(s[nx][ny] != '#' and dis[nx][ny] > dis[x][y] + 1){
                    dis[nx][ny] = dis[x][y] + 1;
                    q.push(mp(nx, ny));
                }
            }
        } 
    }
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m >> K;
    int sx, sy;
    for(int i = 0;i < n;i++){
        cin >> s[i];
        for(int j = 0;j < m;j++){
            if(s[i][j] == 'S'){
                sx = i, sy = j;
            }
        }
    }
    bfs({mp(sx, sy)});
    for(int i = 0;i < n;i++){
        if(dis[i][0] <= K or dis[i][m - 1] <= K){
            cout << 1 << endl;
            return 0;
        }
    }
    for(int j = 0;j < m;j++){
        if(dis[0][j] <= K or dis[n - 1][j] <= K){
            cout << 1 << endl;
            return 0;
        }
    }
    int ans = INF;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            if(dis[i][j] <= K){
                ans = min(ans, min(min(i, n - 1 - i), min(j, m - 1 - j)));
            }
        }
    }
    cout << (ans + K - 1) / K + 1 << endl;
    return 0;
}


Measured memory_bytes: 3456