akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(){
	char ss[1000],out[1000],syuu[16];
	int i,j,a,flag;
	strcpy(syuu,"END OF INPUT");
	
	while(fgets(ss,sizeof(ss),stdin)!=NULL){
				
		for(i=0;;i++){
			if(ss[i]=='\0')break;
			if(ss[i]<32)ss[i]='\0';
		}
		
		if(0==strcmp(ss,syuu))break;
		
		i=0;
		j=0;
		flag=0;
		if(ss[0]==' '){
			flag=1;
			out[0]=0+'0';
			i=1;
			j=1;
			out[1]='\0';
		}

		while(1){
			if(ss[i]=='\0')break;
			if(0!=i)++i;
			if(flag==1){
				--i;
				flag=0;
			}
			for(a=0;;a++){
				if(ss[a+i]==' ' || ss[a+i]=='\0')break;
			}
			
			out[j]=a+'0';
			out[j+1]='\0';
			if(ss[a+i]=='\n')--out[j];
			++j;
			i=i+a;
		}
		printf("%s\n",out);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#define N1 1501
#define N2 1000
using namespace std;
int dh[N1*N2],dw[N1*N2];
int main(){
  int N,M,h[N1],w[N1];
  vector<int> H,W;
  while(1){
    cin >> N >> M;
    if(N==0&&M==0) break;
    for(int i=0;i<N;i++){
      cin >> h[i];
      if(i>0) h[i]+=h[i-1];
    }
    for(int i=0;i<M;i++){
      cin >> w[i];
      if(i>0) w[i]+=w[i-1];
    }
    for(int i=0;i<N1*N2;i++) dh[i]=dw[i]=0;
    int l=1;
    while(l!=N+1){
      for(int i=l-1;i<N;i++){
	dh[h[i]-h[i-l]]++;
      }
      l++;
    }
    l=1;
    while(l!=M+1){
      for(int i=l-1;i<M;i++){
	dw[w[i]-w[i-l]]++;
      }
      l++;
    }/*
    sort(H.begin(),H.end());
    sort(W.begin(),W.end());
    for(int i=0;i<N1;i++){
      for(int j=0;j<N2;j++){
	dh[i][j]=dw[i][j]=0;
      }
    }
    H.clear();
    W.clear();
    */
    int sum=0;
    for(int i=0;i<N1*N2;i++){
      if(dh[i]!=0&&dw[i]!=0) sum+=dh[i]*dw[i];
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 12892
s=input()
idx=len(s)
d={'dream':5,'dreamer':7,'erase':5,'eraser':6}

while True:
	f=True
	for i in d:
		if idx-d[i]>=0 and s[idx-d[i]:idx]==i:
			idx-=d[i]
			f=False
			break
	
	if f:
		print('NO')
		break
	if idx==0:
		print('YES')
		break


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

struct Team{
	vector<bool> is_solve;
	vector<int> WA;
	int team_id, time, solved;
	Team(){}
	Team(int P, int id){
		is_solve = vector<bool>(P, false);
		WA = vector<int>(P, 0);
		team_id = id;
		time = 0;
		solved = 0;
	}
};
bool operator<(const Team &a, const Team &b){
	if( a.solved == b.solved ){
		if( a.time == b.time ){
			return a.team_id > b.team_id;
		}
		return a.time < b.time;
	}
	return a.solved > b.solved;
}
bool operator==(const Team &a, const Team &b){
	return a.solved == b.solved && a.time == b.time;
}

int main(){
	int M, T, P, R;
	while( cin >> M >> T >> P >> R, M ){
		vector<Team> v;
		for(int i = 0; i < T; i++){
			v.push_back( Team(P, i) );
		}
		
		for(int i = 0; i < R; i++){
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			t--; p--;
			if( j == 0 ){ // Correct Answer
				for(int k = 0; k < v.size(); k++){
					if( v[k].team_id == t ){
						v[k].is_solve[p] = true;
						v[k].solved++;
						v[k].time += m;
						v[k].time += 20 * v[k].WA[p];
						break;
					}
				}
			}else{ // Wrong Answer
				for(int k = 0; k < v.size(); k++){
					if( v[k].team_id == t ){
						v[k].WA[p]++;
						break;
					}
				}
			}
		}
		
		sort(v.begin(), v.end());
		for(int i = 0; i < v.size(); i++){
			if( i ){
				bool flag = (v[i-1] == v[i]);
				cout << (flag? "=" : ",");
			}
			cout << v[i].team_id + 1;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1268
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

using namespace std;
typedef long long ll;
const ll MAXN = 2e5+2;
vector<bool> used(MAXN,false);
vector<vector<int>> v;
int path[MAXN];
int ans[MAXN];
ll sum = 0;

void dfs(int s){
    used[s] = true;
    ans[s] = sum;
    for(int i = 0; i < v[s].size(); i++){
        int to = v[s][i];
        if(!used[to]){
            sum += path[to];
            dfs(to);
            sum -= path[to];
        }
    }
}


int main(){
    int n,q;
    cin >> n >> q;
    v.resize(n+1);
    for(int i = 1; i < n; i++){
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i = 1; i <= q; i++){
        int p,x;
        cin >> p >> x;
        path[p] += x;
    }
    sum += path[1];
    dfs(1);
    for(int i = 1; i <= n; i++){
        cout << ans[i] << " ";
    }
    // for(int i = 1; i <= n; i++){
    //     cout << i << ": ";
    //     for(int j = 0; j < v[i].size(); j++){
    //         cout << v[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    return 0;
}

Measured memory_bytes: 24064
from sys import stdin
##  input functions for me
def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

## main ##
N = ri()
V = ria()
C = ria()

ma = 0
for i in range(N):
    ma += max(0, V[i] - C[i])

print(ma)






Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k;
    cin >> n >> k;
    vl a(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n-k){
        if(a[k+i]>a[i]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4780
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 200020
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int a[N],b[N],n;
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		int x=read(),y=read();
		a[i]=x+y,b[i]=x-y;
	}
	printf("%d\n",max(*max_element(a+1,a+n+1)-*min_element(a+1,a+n+1),*max_element(b+1,b+n+1)-*min_element(b+1,b+n+1)));
	return 0;
}



Measured memory_bytes: 5216
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 500
long long n, m, k, k2;
char a[N + 1][N + 1];
bool b[N + 1][N + 1];

void dfs(int x, int y){
	b[x][y] = true;
	if (a[x][y] == '#')k++;
	else k2++;
	if (x > 0){
		if (a[x][y] != a[x - 1][y] && !b[x - 1][y])dfs(x - 1, y);
	}
	if (y > 0){
		if (a[x][y] != a[x][y - 1] && !b[x][y - 1])dfs(x, y - 1);
	}
	if (x < n - 1){
		if (a[x][y] != a[x + 1][y] && !b[x + 1][y])dfs(x + 1, y);
	}
	if (y < m - 1){
		if (a[x][y] != a[x][y + 1] && !b[x][y + 1])dfs(x, y + 1);
	}
	return;
}


int main(){
	f(i, N + 1){
		f(j, N + 1){
			a[i][j] = 0;
			b[i][j] = false;
		}
	}
	long long x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%lld %lld", &n, &m);
	f(i, n)scanf("%s", a[i]);

	f(i, n){
		f(j, m){
			if (!b[i][j]){
				k = 0;
				k2 = 0;
				dfs(i, j);
				ans += (k*k2);
			}
		}
	}

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


	return 0;
}


Measured memory_bytes: 13056
let n = readInt()
let a = readArray().map { Int($0)! }

var acc = 0
var min = 0

for num in a {
  if min > num {
    acc = acc &+ (min - num)
  } else {
    min = num
  }
}

print(acc)

@inlinable @inline(__always) func readInt() -> Int { Int(readLine()!)! }
@inlinable @inline(__always) func readArray(_ separator: Character = " ") -> [String] { readLine()!.split(separator: separator).map(String.init) }


Measured memory_bytes: 21224
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    # A = [885, 8, 1, 128, 83, 32, 256, 206, 639, 16, 4, 128, 689, 32, 8, 64, 885, 969, 1]
    # N = len(A)

    n_satisfied = 0
    sum_lr = 0
    xor_lr = 0
    l, length = 0, 0

    while True:
        while l + length != N and \
                sum_lr + A[l + length] == xor_lr ^ A[l + length]:
            sum_lr += A[l + length]
            xor_lr ^= A[l + length]
            length += 1

        # print("l, length", l, length)
        n_satisfied += length

        if l == N:
            break

        sum_lr -= A[l]
        xor_lr -= A[l]
        l += 1
        length -= 1

    print(n_satisfied)


Measured memory_bytes: 24424
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	int sum = 0;
  	int x=n;
	while (x != 0) {
		sum += (x % 10);
		x /= 10;
	}
	if (n%sum == 0) {
		cout << "Yes";
	}
	else cout << "No";
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var x1, x2, x3, x4, x5 int
	fmt.Scan(&x1, &x2, &x3, &x4, &x5)
	for i, v := range []int{x1, x2, x3, x4, x5} {
		if v == 0 {
			fmt.Println(i + 1)
		}
	}
}


Measured memory_bytes: 1752
#include <stdio.h>

int pow2(int a){
	int i=0,ans=1;
	for(i=0;i<a;i++)
		ans*=2;
	return ans;
}

int main(int argc, char const *argv[]){
	int n,m;
	scanf("%d%d",&n,&m);
	printf("%d",(m*1900+(n-m)*100)*pow2(m));
	return 0;
}

Measured memory_bytes: 128
# https://atcoder.jp/contests/agc008/tasks/agc008_a

import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    x, y = input_int_list()
    if x == y:
        print(0)
    elif abs(abs(x) - abs(y)) == 0:
        print(1)
    elif (x == 0 and y > 0) or (y == 0 and x < 0):  # 0 が含まれ符号反転なし
        print(abs(abs(x) - abs(y)))
    elif (x == 0 and y < 0) or (y == 0 and x > 0):  # 0が含まれ符号反転あり
        print(abs(abs(x) - abs(y)) + 1)
    elif (x < 0 and y > 0) or (x > 0 and y < 0):  # +/-混在
        print(abs(abs(x) - abs(y)) + 1)
    elif y < x:  # y のほうが小さい
        print(abs(abs(x) - abs(y)) + 2)
    else:
        print(abs(abs(x) - abs(y)))
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 62064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long[] a = new long[N];
    long[] sum = new long[N];
    for(int i = 0; i < N; i++) {
      a[i] = sc.nextLong();
      if(i == 0) {
        sum[i] = a[i];
      } else {
        sum[i] = sum[i - 1] + a[i];
      }
    }
    long ans = Long.MAX_VALUE;
    for(int i = 0; i < N - 1; i++) {
      long x = sum[i];
      long y = sum[N - 1] - sum[i];
      ans = Math.min(ans, Math.abs(x - y));
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 85460
/*********************************************JMD**********************************************/
//                                  |\  |     | |   |   /\                                   //
    //                              | \ |     | |---|  /--\                              //
        //                          |  \| |___| |   | /    \1999                     //
/*******************************************************************************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define mem(x,val) memset(x,val,sizeof(x))
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define f(i,n) forr(i,0,n)
#define sz(x) ll((x).size())
#define all(x) ((x).begin(),(x).end())
#define asc(x) ((int)(x))
#define precision(x) cout<<fixed<<setprecision((x));

const ll mod=1e9 + 7;

/*******************************************************************************************/

void solve()
{
    ll a,b;
    cin>>a>>b;

    cout<<(a*b)/(__gcd(a,b));

    return;
}

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

    ll t=1;
    //cin>>t;
    clock_t launch=clock();

    while(t--)
    {
        solve();
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;
int main() {
  vector <int> n(4);
  for (int i = 0; i < 4; i++) {
	  cin >> n[i];
	}
  sort(n.begin(), n.end());
  int m = n[0] + 10 * n[1] + 100 * n[2] + 1000 * n[3];
  if (m == 9741) {
	  cout << "YES" << endl;
	} else {
	  cout << "NO" << endl;
	}
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define iter(el, arr) for(auto& el : arr)
#define ALL(a) a.begin(), a.end()

#define ld long double
#define ll long long
#define pii pair<int, int>
#define pll pair<ll,ll>
#define MP make_pair
#define MT make_tuple
#define SZ(a) ll((a).size())
#define X first
#define Y second

#define endl '\n'
#define PB push_back
#define has(i, m) (m.find(i) != m.end())

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define vch vector<char>
#define vvi vector<vi>
#define vvll vector<vll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define pdd pair<ld, ld>
#define vpll vector<pll>
#define vpdd vector<pdd>
#define pq priority_queue
#define mod 1000000007
using namespace std;

const ll INF = 1e18;
const ll MAXN = 100001;

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("Out.txt", "w", stdout);

	ll q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;

	ll ans;
	ll mi = min(min(q*8LL, h*4LL), min(s*2LL, d));
	if (mi == q*8LL)
	{
		ans = 4LL * n*q;
	}
	else
	{
		if (mi == h*4LL)
		{
			ans = 2LL * n*h;
		}
		else
		{
			if (mi == s*2LL)
			{
				ans = n*s;
			}
			else
			{
				if (n % 2 == 0)
					ans = n*d / 2;
				else
				{
					ans = (n / 2)*d;
					mi = min(min(q*4LL, h*2LL), s);
					if (q*4LL == mi)
						ans += 4LL * q;
					else
						if (h*2LL == mi)
							ans += 2LL * h;
						else
							ans += s;
				}
			}
		}
	}


	cout << ans;
	//cin >> n;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

#[allow(unused_variables)]
fn main() {
    input! {
      n: usize, a: usize, b: usize,
      mut s: String
    };

    // let a_c = s.chars().filter(|x| *x == 'a').count();
    // let b_c = s.chars().filter(|x| *x == 'b').count();

    let mut limit = a + b;
    let mut b_limit = b;

    let mut count = 0;

    for c in s.chars() {
        let ans = match c {
            'a' => {
                if limit > 0 {
                    limit -= 1;
                    "Yes"
                } else {
                    "No"
                }
            }
            'b' => {
                if limit > 0 && b_limit > 0 {
                    limit -= 1;
                    b_limit -= 1;
                    "Yes"
                } else {
                    "No"
                }
            }
            _ => "No",
        };

        println!("{}", ans);

        count += 1;
    }
}


Measured memory_bytes: 2368
#include<iostream>
#include<queue>
using namespace std;
char a[22][22];

int n,m;

struct pos{
	int x;
	int y;
	int step;
};

pos make_pos(int a,int b,int c){
	pos ret;
	
	ret.x=a;
	ret.y=b;
	ret.step=c;
	
	return ret;
}

int bfs(int sx,int sy,int ex,int ey){
	bool vis[n+2][m+2];
	
	for(int i=0;i<=n+1;++i)
		for(int j=0;j<=m+1;++j)
			if(a[i][j]=='#')
				vis[i][j]=true;
			else
				vis[i][j]=false;
	
	queue<pos> q;
	q.push(make_pos(sx,sy,0));
	vis[sx][sy]=true;
	int move[2][4]={{0,0,-1,1},{-1,1,0,0}};  //位移增量 
	
	while(!q.empty()){
		pos fr=q.front();
		q.pop();
		if(fr.x==ex&&fr.y==ey)
			return fr.step;
			
		pos newpo;
		for(int i=0;i<4;++i){
			int nx=fr.x+move[0][i];
			int ny=fr.y+move[1][i];
			if(vis[nx][ny])
				continue;
			vis[nx][ny]=true;
			newpo=make_pos(nx,ny,fr.step+1);
			q.push(newpo);
		}
	}
	return 0;
}

int main(){
	for(int i=0;i<22;++i)
		for(int j=0;j<22;++j)
			a[i][j]='#';
	
	cin>>n>>m;
	
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			cin>>a[i][j];
	
	int maxv=0;
	
	for(int i1=1;i1<=n;++i1)
		for(int j1=1;j1<=m;++j1){
			if(a[i1][j1]=='#')
				continue;
			for(int i2=1;i2<=n;++i2)
				for(int j2=1;j2<=m;++j2){
					if(a[i2][j2]=='#')
						continue;
					if(i1==i2&&j1==j2)
						continue;
					
					maxv=max(maxv,bfs(i1,j1,i2,j2));
				}
		}
	
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define EPS (1e-10)
using namespace std;

class Point{
public:
  int x, y;
};
class Segment{
public:
  Point p1, p2;
};

double norm(Point a){
  return a.x*a.x+a.y*a.y;
}

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

int ccw(Point p0, Point p1, Point p2){
  Point a;
  a.x=p1.x-p0.x;
  a.y=p1.y-p0.y;
  Point b;
  b.x=p2.x-p0.x;
  b.y=p2.y-p0.y;
  if(cross(a, b) > EPS) return 1;
  if(cross(a, b) < -EPS) return -1;
  if(dot(a, b) < -EPS) return 2;
  if(norm(a) < norm(b)) return -2;
  return 0;
}

bool isIntersect(Point p1, Point p2, Point p3, Point p4){
  return ( ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
	   ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0 );
}

bool isIntersect(Segment s1, Segment s2){
  return isIntersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

main(){
  int n;
  while(cin >> n){
    for(int i=0;i<n;i++){
      int xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
      cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
      Point a, b, c, k, s;
      a.x=xp1;
      a.y=yp1;
      b.x=xp2;
      b.y=yp2;
      c.x=xp3;
      c.y=yp3;
      k.x=xk;
      k.y=yk;
      s.x=xs;
      s.y=ys;
      Segment ab, bc, ca, ks;
      ab.p1=b;
      ab.p2=a;
      bc.p1=c;
      bc.p2=b;
      ca.p1=a;
      ca.p2=c;
      ks.p1=s;
      ks.p2=k;
      int count=0;
      if(isIntersect(ks, ab)) count++;
      if(isIntersect(ks, bc)) count++;
      if(isIntersect(ks, ca)) count++;
      if(count==1) cout << "OK" << endl;
      else cout << "NG" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 864
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define Set set<int>
#define int long long
#define P pair<int,int>
const int maxn = 2e3+5;
const int INF = 1e17 +6;
using namespace std;
int n,m,a[maxn],b[maxn],c[maxn],ans;
string k[maxn];
int hang[maxn][maxn],lie[maxn][maxn];
int32_t main()
{
    IOS;
    cin>>n>>m;
    fu(i,1,n)
    {
        cin>>k[i];
        fu(j,0,m-1)
        {
            if(k[i][j]=='.') {
                hang[i][j] = hang[i][j - 1] + 1;
            } else {//#
                fd(t,j-2,0) {
                    if(j-2<0)break;
                    if(k[i][t]=='#' or k[i][t+1]=='#')break;
                    if(k[i][t]=='.')hang[i][t] = hang[i][j - 1];
                    else break;
                }
            }
        }
        if(k[i][m-1]=='#')continue;
        fd(t,m-2,0) {
            if(t<0)break;
            if(k[i][t]=='#' or k[i][t+1]=='#')break;
            if(k[i][t]=='.')hang[i][t] = hang[i][m - 1];
            else break;
        }
    }
    fu(i,0,m-1)//lie
    {
        fu(j,1,n)
        {
            if(k[j][i]=='.')
            {
                lie[j][i]=lie[j-1][i]+1;
            }else{
                fd(t,j-2,0) {
                    if(j-2<0)break;
                    if(k[t][i]=='#' or k[t+1][i]=='#')break;
                    if(k[t][i]=='.')lie[t][i] = lie[j-1][i];
                    else break;
                }
            }
        }
        if(k[n][i]=='#')continue;
        fd(t,n-1,0) {
            if(t<0)break;
            if(k[t][i]=='#' )break;
            if(k[t][i]=='.')lie[t][i] = lie[n][i];
            else break;
        }
    }
    int mm=-INF;
    fu(i,1,n)
    {
        fu(j,0,m-1)
        {
            if(k[i][j]=='#')continue;
            mm=max(mm,hang[i][j]+lie[i][j]-1);
        }
    }
    if(mm<0)mm=0;
    cout<<mm;
    return 0;
}


Measured memory_bytes: 67328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

int main(){
    ll h;
    int n;
    cin>>h>>n;
    int a[n];
    int sum=0;;
    rep(i,n) {
        cin>>a[i];
        sum+=a[i];
    }
    if(h<=sum) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const long long mod = 1000000007;
// auto mod int
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main(){
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];
    mint ans = 1;
    if (k==n) {
        rep(i, n) ans *= a[i];
        cout << ans << endl;
        return 0;
    }
    int npos = 0;
    rep(i, n) if (a[i] >= 0) ++npos;
    bool ok = false;
    if (npos>0 || k%2==0) ok = true;
    if (ok) {
        vi pos, neg;
        rep(i, n) {
            if (a[i] >= 0) pos.pb(a[i]);
            else neg.pb(a[i]);
        }
        VSORT(neg);
        if (npos>0&&k%2==1) {
            VSORT(pos);
            ans *= pos.back(); pos.pop_back();
            reverse(all(pos));
        }
        else RSORT(pos);
        vll x;
        for (int i=0; i<sz(pos); i+=2) x.pb((ll)(pos[i])*pos[i+1]);
        for (int i=0; i<sz(neg)-1; i+=2) x.pb((ll)(neg[i])*neg[i+1]);
        RSORT(x);
        rep(i, k/2) ans *= x[i];
    }
    else {
        RSORT(a);
        rep(i, k) ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    string s; int a, b;
    while (cin >> s >> a >> b) {
        cout << s << " " << a + b << " " << a * 200 + b * 300 << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>

int main(int argc, char* argv)
{
  int n, x, c;
  int i, j ,k;

  scanf("%d %d", &n, &x);
  while((n != 0)||(x != 0)){
    c = 0;
    for(i = 1; i < n; i++){
      for(j = i + 1; j < n; j++){
        for(k = j + 1; k <= n; k++){
          if((i + j + k) == x){
            c++;
          }
        }
      }
    }
    printf("%d\n", c);
    scanf("%d %d", &n, &x);
  }

  return(0);
}

Measured memory_bytes: 600
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class DLuckyPIN {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        string s;
        in >> s;
        vector<string> c;
        rep(i,10){
            rep(j,10){
                rep(k,10){
                    string t=to_string(i)+to_string(j)+to_string(k);
                    c.push_back(t);
                }
            }
        }
        vector<int> p(10,-1);
        for(int i=0;i<10;i++){
            for(int j=0;j<n;j++){
                if(s[j]-'0'==i){
                    p[i]=j;
                    break;
                }
            }
        }
        int ans=0;
        for(int i=0;i<c.size();i++){
            int cnt=0;
            for(int j=p[c[i][0]-'0'];j<n;j++){
                if(j<0){
                    break;
                }
                if(s[j]==c[i][cnt]){
                    cnt++;
                    if(cnt==3){
                        ans++;
                        if(n==4)
//                        out << c[i] << endl;
                        break;
                    }
                }
            }
        }
        out << ans << endl;
	}
};


int main() {
	DLuckyPIN solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 384
import math

def main():
    X = input()
    mini = 100000

    for index in range(len(X)-2):
        if mini > abs(int(X[index:index+3]) - 753):
            mini = abs(int(X[index:index+3]) - 753)
    print (mini)




if __name__ == '__main__':
    main()


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

void linking(int value, int counter, char* ans)
{
	char t[10];
	sprintf(t, "%d", value);
	sprintf(ans, "%d", value);

	int i;
	for (i = 0; i < counter-1; i++) {
		strcat(ans, t);
	}

}

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	
	char ans[10];
	if (a > b) {
		linking(b, a, ans);
	}
	else {
		linking(a, b, ans);
	}

	printf("%s", ans);

	return 0;
}

Measured memory_bytes: 128
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n, x;
LL sz[55];
LL pat[55];

LL calc(int level,LL num){
    if(level == 0)return 1LL;
    if(num == 1LL)return 0LL;
    else if(num <= 1LL + sz[level - 1])return calc(level - 1, num - 1LL);
    else if(num == 2LL + sz[level - 1])return pat[level - 1] + 1LL;
    else if(num <= 2LL + 2LL*sz[level - 1])return pat[level - 1] + 1LL + calc(level - 1, num - 2LL - sz[level - 1]);
    else return 2*pat[level - 1] + 1LL;
}

int main(){
    INIT;
    cin >> n >> x;
    sz[0] = 1LL, pat[0] = 1LL;
    for(int i = 1;i <= 50;i++)sz[i] = 3LL + sz[i - 1]*2LL;
    for(int i = 1;i <= 50;i++)pat[i] = 1LL + pat[i - 1]*2LL;
    cout << calc(n, x) << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int[] num = new int[2];
		while(sc.hasNextLine()){
			String[] str =sc.nextLine().split(" ");
			num[0] = Integer.parseInt(str[0]);
			num[1] = Integer.parseInt(str[1]);
			if(num[0]==0 && num[1]==0){
				break;
			}
			if(num[0]>num[1]){
				int store =num[0];
				num[0] =num[1];
				num[1] =store;
			}
			System.out.println(num[0]+" "+num[1]);
		}
	}
}

Measured memory_bytes: 35012
import itertools
n,m = map(int,input().split())
l = [tuple(map(int, input().split())) for _ in range(m)]
judge = tuple(map(int, input().split()))
count =0
switch = list(itertools.product([0,1], repeat=n)) #nがtupleの要素数
for i in range (len(switch)):
    #スイッチ全探索
    for j in range(m):
        cnt = 0
        #各電球に焦点
        for k in range(l[j][0]):
            #電球のスイッチ条件に焦点
            cnt += switch[i][l[j][k+1]-1]
        if cnt % 2 != judge[j]:
            break
        else:
            if j == m-1:
                count += 1
print(count)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> d(k);
	rep(i, k) cin >> d[i];
	for (int i = 1; i <= 999999; ++i) {
		if (i < n) continue;
		vector<int> res;
		int tmp = i;
		while (tmp) {
			res.emplace_back(tmp % 10);
			tmp /= 10;
		}
		bool elf = false;
		for (auto& c : res) {
			rep(j, k) if (c == d[j]) elf = true;
		}
		if (!elf) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}


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

using namespace std;
using ll = long long int;

const int mod = 1e9 + 7;

int extendedEuclid(ll a,ll m, ll &x,ll &y){
    if(a == 0){
        x = 0;
        y = 1;
        return m;
    }

    ll x1, y1;
    ll g = extendedEuclid(m%a, a, x1, y1);
    x = y1 - (m / a)*x1;
    y = x1;

    return g;
}

ll modInv(ll a) {

    ll x, y;
    ll g = extendedEuclid(a, mod, x, y);

    if (g != 1) return 0;

    return ((x % mod + mod) % mod);
}

int main() {

    int x, y;
    cin >> x >> y;

    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    ll n, m;
    n = (2 * y - x) / 3;
    m = (2 * x - y) / 3;

    if (n < 0 || m < 0) {
        cout << 0 << endl;
        return 0;
    }

    ll num = 1;
    for (ll i = max(n, m) + 1; i <= n + m; i++) {
        num *= i;
        num %= mod;
    }

    ll denom = 1;
    for (ll i = 2; i <= min(n, m); i++) {
        denom *= i;
        denom %= mod;
    }

    cout << (num * modInv(denom)) % mod << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int X,A;
  scanf("%d%d",&X,&A);
  if(X<0||X>9||A<0||A>9){
    while(1){
      scanf("%d%d",&X,&A);
      if(X>=0&&X<=9&&A>=0&&A<=9){
        break;
      }
    }
  }
  if(X>=A){
    printf("10\n");
  }
  else{
    printf("0");
  }
  return 0;
}
    

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define isFile 0
#define NAME "taskA"
#define scan 1
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;

#define mp make_pair
#define pb push_back
#define fr first
#define sc second

#define ins insert
#define all(v) v.begin(), v.end()
#define rep(i,a,n) for (int i=a;i<n;i++)
#define bit(n, i) (n >> i) & 1
#define bpc(x) __builtin_popcountll(x)
#define rev(a) reverse(all(a))
#define skip continue
#define read(a) for(auto &i : a) cin >> i
#define print(a) for(auto i : a) cout << i << ' '
#define unique(a) sort(all(a));    a.resize(unique(all(a)) - a.begin())

//                D  R  U   L
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

void faster() {
    if (isFile) {
        freopen(NAME".in", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    if (scan) {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
}

const ll  INF = 1e18;
const int inf = 2e9;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ld  PI = acos(-1);
const ld  EPS = 3E-16;
const int ALPHA = 26;
const int N = (int)3e2 + 5;
const int M = 123;

void solve() {
    ll L;
    cin >> L;
    double A = (double) L / 3;
    cout << setprecision(10) << A * A * A << endl;
}

int main() {
    faster();
    int t = 1;
//    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MOD 1000000007
using namespace std;
int f[10002][100][2]={0};
char k[10001];
int main()
{
    int D,n;
    int i,j,l;
    scanf("%s",k);
    scanf("%d",&D);
    n=strlen(k);
    f[0][0][1]=1;
    for(i=0;i<n;i++)
    {
	for(j=0;j<D;j++)
	{
	    for(l=0;l<=9;l++)
	    {
		f[i+1][(j+l)%D][0]+=f[i][j][0];
		f[i+1][(j+l)%D][0]%=MOD;
 	    }
	    for(l=0;l<=k[i]-'0';l++)
	    {
		if(l==k[i]-'0')
		{
		    f[i+1][(j+l)%D][1]+=f[i][j][1];
		    f[i+1][(j+l)%D][1]%=MOD;
		}
		else
		{
		    f[i+1][(j+l)%D][0]+=f[i][j][1];
		    f[i+1][(j+l)%D][0]%=MOD;
		}
	    }
	}
    }
    printf("%d\n",(MOD+f[n][0][0]+f[n][0][1]-1)%MOD);
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int k,n,i;
    long long int c=0,h[1000000];
    cin >> n >> k;
    for(i=0;i<n;i++)
    {
        cin >> h[i];
    }
    sort(h,h+n,greater<int>());
    for(i=k;i<n;i++)
    {
        c+=h[i];
    }
    {
        cout << c << endl;
    }

    return 0;

}


Measured memory_bytes: 5112
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top=0, stac[101];
char s[100];

void push(int x){
    top++;
    stac[top]=x;
}

int pop(){
    top--;
    return stac[top+1];
}

int main(void){
    int a, b, result;
    while(scanf("%s", s) != EOF){
        if(s[0] == '+')     push(pop() + pop());
        else if(s[0] == '-'){
            a=pop(); b=pop();
            push(b-a);
        }
        else if(s[0] == '*')push(pop() * pop());
        else push(atoi(s)); //atoiは数値変換
    }
    printf("%d\n", pop());

    return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
  string line;
  int a,b;
  getline (cin,line);
  stringstream(line) >> a >> b;
  cout << a/b << ' ' << a%b << ' ' << fixed << double(a)/double(b) << '\n';
  return 0;
}

Measured memory_bytes: 3276
import collections

N = int(input())
A = [0] + list(map(int, input().split()))


for i in range(1, N + 1):
    A[i] = A[i] + A[i - 1]
# print(A)

ans = 0
cnter = dict(collections.Counter(A))
for val in cnter.values():
    ans += val * (val - 1) // 2
print(ans)



Measured memory_bytes: 113104
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int n,x,y; cin>>n>>x>>y;
    vector<int>ans(n);
    for(int i=1;i<n;i++) {
        for(int j=i+1;j<=n;j++) {
            int min_dist=min(abs(i-j),abs(x-i)+abs(y-j)+1);
            ans[min_dist]++;
        }
    }
    for(int i=1;i<n;i++) {
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 3628
import heapq,math
n,m=map(int,input().split())
def aaa(x):
    return -1.0*float(x)
a=list(map(aaa,input().split()))
heapq.heapify(a)
for _ in range(m):
    x=heapq.heappop(a)*-1
    x/=2
    heapq.heappush(a,x*-1)

for i in range(n):
    a[i]*=-1

for i in range(n):
    a[i]=math.floor(a[i])

print(sum(a))


Measured memory_bytes: 82968
#include<bits/stdc++.h>
#define M  1000005
#define LL long long
using namespace std;

int main(){
	int n;
	cin>>n;
	int c=0;
	c+=n/500*1000;
	n%=500;
	c+=n/5*5;
	cout<<c<<endl;
	
	return 0;
}

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

int main() {
  int k,a,b;
  cin >> k >> a >> b;
  int t=0;
  
  for(int i=a; i<=b; i++){
    if(i%k == 0){
      t=1;
      cout << "OK" << endl;
      break;
    }
  }
  
  if(t == 0){
    cout << "NG" << endl;
  }
	return 0;
}


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

using namespace std;
static const int MAX = 200000;

int main() {
	int R[MAX],  n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> R[i];
	int maxv = -2000000000;
	int minv = R[0];
	for (int i = 1; i < n; i++){
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;
	return 0;
}


Measured memory_bytes: 3860
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
//#define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/
 
int32_t main()
{
	fastio();
	int n;
	cin>>n;
	int x[n+1],y[n+1],t[n+1];
	x[0]=y[0]=t[0]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i]>>x[i]>>y[i];
	}	

	for(int i=1;i<=n;i++)
	{
		int dis=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
		if(dis>(t[i]-t[i-1]) || dis%2!=(t[i]-t[i-1])%2)
		{
			cout<<"No\n";
			return 0;
		}
	}	
	cout<<"Yes\n";
}


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

using namespace std;

int main() {
  string A, B;
  cin >> A >> B;
  int num_A, num_B;
  cin >> num_A >> num_B;
  string C;
  cin >> C;
  
  if (C == A) {
    --num_A;
  } else {
    --num_B;
  }
  cout << num_A << " " << num_B << endl;
  
  return 0;
}


Measured memory_bytes: 256
def inpl():
    return list(map(int, input().split()))


def solve(i):
    def getChoco(choco, w):
        for i in range(H):
            if S[i][w] == "1":
                choco[t[i]] += 1
        return choco

    t = {}
    t[0] = 0
    x = 0
    for h in range(H - 1):
        if (i >> h) % 2 == 1:
            x += 1
            t[h + 1] = x
        else:
            t[h + 1] = x
    choco = [0 for _ in range(x + 1)]
    ret = x
    # print(i, t)

    for w in range(W):
        choco = getChoco(choco, w)
        if any(c > K for c in choco):
            choco = getChoco([0 for _ in range(x + 1)], w)
            if any(c > K for c in choco):
                return H + W - 2
            else:
                ret += 1
    return ret


H, W, K = inpl()
S = [input() for _ in range(H)]

ans = H + W - 2
for i in range(2**(H - 1)):
    ans = min(ans, solve(i))

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> a(n); for (auto&& e : a) cin >> e;
  V<> b(m); for (auto&& e : b) cin >> e;
  V<lint> pre(500);
  for (int i = 1; i < 500; ++i) {
    for (int e : a) pre[i] += e % i;
  }
  V<> c(200002);
  for (int e : a) ++c[e];
  for (int i = 200000; i; --i) c[i - 1] += c[i];
  lint s = accumulate(begin(a), end(a), 0LL);
  lint res = 0;
  for (int e : b) {
    if (e < 500) res += pre[e];
    else {
      lint q = 0;
      for (int i = 0; i <= 200000; i += e) {
        q += (lint)(c[i] - c[min(i + e, 200001)]) * i;
      }
      res += s - q;
    }
  }
  cout << res << '\n';
}


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

int n;
vector<vector<int> > br;
vector<int> dep;
vector<bool> done;

void dfs(int id,int d)
{
	dep[id]=d+1;
	done[id]=true;
	for(int i=0;i<br[id].size();i++)
	{
		int nxid=br[id][i];
		if(done[nxid]==false)
			dfs(nxid,dep[id]);
	}
}


int main()
{
	cin >> n;
	br=vector<vector<int> >(n);
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin >> a >> b;
		a--;b--;
		br[a].push_back(b);
		br[b].push_back(a);
	}

	dep=vector<int>(n,1000000);
	done=vector<bool>(n,false);
	dfs(0,0);
	int mx=0;
	int id=0;
	for(int i=0;i<n;i++)
		if(dep[i]>mx)
		{
			mx=dep[i];
			id=i;
		}
	done=vector<bool>(n,false);
	dfs(id,0);
	int ans=0;
	for(int i=0;i<n;i++)
		if(dep[i]>ans)
			ans=dep[i];
	ans--;
	cout << (ans%3==1 ? "Second":"First") << endl;
}

Measured memory_bytes: 21376
#include <iostream>
#include <utility>
#include <queue>
#include <string>

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    int timecounter = 0;

    queue<pair<string, int>> que;
    for(int i = 0; i < n; i++) {
        string s;
        int time;
        cin >> s >> time;
        pair<string, int> p(s, time);
        que.push(p);
    }
    int count = 0;
    while(count < n) {
        pair<string, int> p = que.front();
        que.pop();

        if(p.second <= q) {
            timecounter += p.second;
            cout << p.first << " " << timecounter << endl;
            count += 1;
        } else {
            p.second -= q;
            timecounter += q;
            que.push(p);
        }
    }
    return 0;
}


Measured memory_bytes: 6256
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		if (a + b == c + d) {
			System.out.println("Balanced");
		} else if (a + b > c + d) {
			System.out.println("Left");
		} else {
			System.out.println("Right");
		}
	}
}


Measured memory_bytes: 23124
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;

long long gcd(long long x, long long y){
			if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }
int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i<N; i++){
        cin >> A[i];
    }
if(N == 1){
    cout << A[0] << endl;
}
else{
    long long ans = gcd(A[0],A[1]);
    for(int i = 2; i< N;i++){
    ans = gcd(ans,A[i]);
}
cout << ans << endl;
}
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

struct RollingHash {
    static const int b1 = 1007, b2 = 2009;
    static const int m1 = 1000000007, m2 = 1000000009;
    vector<ll> h1, h2, p1, p2;

    RollingHash(const string &s) {
        int n = s.size();
        h1.assign(n + 1, 0);
        h2.assign(n + 1, 0);
        p1.assign(n + 1, 1);
        p2.assign(n + 1, 1);
        REP(i, n) {
            h1[i + 1] = (h1[i] * b1 + s[i]) % m1;
            h2[i + 1] = (h2[i] * b2 + s[i]) % m2;
            p1[i + 1] = (p1[i] * b1) % m1;
            p2[i + 1] = (p2[i] * b2) % m2;
        }
    }

    inline pair<ll, ll> get(int l, int r) const {
        ll res1 = h1[r] - h1[l] * p1[r-l] % m1;
        if (res1 < 0) res1 += m1;
        ll res2 = h2[r] - h2[l] * p2[r-l] % m2;
        if (res2 < 0) res2 += m2;
        return {res1, res2};
    }

    inline int getLCP(int a, int b) const {
        int ok = 0, ng = h1.size() - b;
        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
            if (get(a, a + mid) == get(b, b + mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
};

int main() {
    int N, ans = 0;
    string S;
    cin >> N >> S;
    RollingHash rh(S);
    REP(i, N) FOR(j, i + 1, N) ans = max(min(rh.getLCP(i, j), j - i), ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512