akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int k, x;
    cin >> k >> x;
    if(k * 500 >= x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
n = int(input())
lst = list(map(int, input().split()))
count = {"gray":0,"brown":0,"green":0,"lightblue":0,"blue":0,"yellow":0,"orange":0,"red":0}
free = 0

for i in lst:
    if i<400:
        count["gray"]+=1
    elif i<800:
        count["brown"]+=1
    elif i<1200:
        count["green"]+=1
    elif i<1600:
        count["lightblue"]+=1
    elif i<2000:
        count["blue"]+=1
    elif i<2400:
        count["yellow"]+=1
    elif i<2800:
        count["orange"]+=1
    elif i<3200:
        count["red"]+=1
    else:
        free+=1

ans = 0
for i in count.values():
    if i!=0:
        ans+=1

print(max(ans,1), ans+free)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};

int main(){
	int N,K; cin >> N >> K;
	vector<ll> h(N);
	for (int i; i<N; i++){
		cin >> h[i];
	}
	ll ans = INF;
	sort(h.begin(), h.end());
	for(int i = 0; i<= N-K; i++){
		ans = min(ans, h[K+i-1] - h[i]);
	}
	cout << ans << endl;
	// cout << N << K <<endl;
	
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string b;
  cin >> b;
  if(b == "A"){
    cout << "T" << endl;
  }
  if(b == "T"){
    cout << "A" << endl;
  }
  if(b == "G"){
    cout << "C" << endl;
  }
  if(b == "C"){
    cout << "G" << endl;
  }
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll N;
    string S;
    cin >> N >> S;
    ll R = 0, W = 0; //しきりより右にある赤,しきりより左にある白
    ll ans = 1e9;
    loop(i, N) if (S[i] == 'R') R++;
    ans = min(ans, max(R, W));
    loop(i, N)
    {
        if (S[i] == 'R')
        {
            R--;
        }
        else
        {
            W++;
        }
        ans = min(ans, max(R, W));
    }

    putout(ans);
    return 0;
}


Measured memory_bytes: 3752
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;

const int SIZE=2e5+7;
const int Mod=1e9+7;
long long f[SIZE];
long long a[SIZE];
int n;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	REP(i,n)cin>>a[i];
	for(int i=n-1;i>=0;i--)
		f[i]=(f[i+1]+a[i+1])%Mod;
	long long ans=0;
	REP(i,n-1)
		ans=(ans+a[i]*f[i])%Mod;
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 6720
int main(){
	int a,b,c,d,e,f,g,h,n,m;
	scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h);
	n=a*e+a/10*g+b*f+b/20*h;
	m=c*e+c/10*g+d*f+d/20*h;
	puts(n>m?"hiroshi":n<m?"kenjiro":"even");
	return 0;
}

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

//5000000000000000

int main() {
	string s;
	cin >> s;
	unsigned long long K;
	cin >> K;

	bool flags = false;
	for (int i = 0; i < K; ++i) {
		if (s[i] != '1') {
			flags = true;
			break;
		}
	}

	for (int i = 0; i < s.length() && flags; ++i) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
	}

	cout << 1 << endl;
	return 0;
}

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

using namespace std;

int n;
int a[101010];

int main() {
	scanf("%d", &n);
	int mx = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
		mx = max(mx, a[i]);
	}
	int x = mx >> 1;
	int k = 0;
	for (int i = 0; i < n; ++i) {
		if (abs(a[i] - x) < abs(k - x)) {
			k = a[i];
		}
	}
	printf("%d %d\n", mx, k);
	return 0;
}

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

using namespace std;

int main(void)
{
    int n;
    cin >> n;
    map<int,int> mm;
    for(int i=1;i<=n;i++)mm[i]=0;

    for(int i=0;i<n-1;i++){
        int x; cin >> x;
        mm[x]++;
    }
    for(auto it:mm){
        cout << it.second << endl;
    }

    return 0;
}


Measured memory_bytes: 13016
/**
 *   @FileName	c.cpp
 *   @Author	kanpurin
 *   @Created	2020.05.16 18:39:29
**/

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

int main() {
    int n,m,x;cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    constexpr long long LLINF = 1e18 + 1;
    ll ans = LLINF;
    for (int i = 0; i < (1<<n); i++) {
        ll sum_c = 0;
        vector<ll> sum_a(m);
        for (int j = 0; j < n; j++) {
            if (i & (1<<j)) {
                sum_c += c[j];
                for (int d = 0; d < m; d++) {
                    sum_a[d] += a[j][d];
                }
            }
        }
        bool ok = true;
        for (int j = 0; j < m; j++) {
            if (sum_a[j] < x) ok = false;
        }
        if (ok) ans = min(ans,sum_c);
    }
    if (ans == LLINF) {
        cout << -1 << endl;
    }
    else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define mer make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;
typedef pair<int,pair<int,int> > ipii;
typedef pair<pii,pii> pi4;
const int vbi=999999999;

/*void cin_bin(){
	char bin[10000];
	gets(bin);
}*/

vector<int> jz10_2(int a){
	vector<int> ans;
	while(a!=0){
		ans.pb(a%2);
		a/=2;
	}
	reverse(ans.begin(),ans.end());
	return ans;
}

ll a,b;
void play_it(bool who){
	if(who){
		if(a%2==1)
			a--;
		a/=2;
		b+=a;
	}
	else{
		if(b%2==1)
			b--;
		b/=2;
		a+=b;
	}
}

int main(){
	//my new name is Veex
	//clock_t start1=clock();
	int k;
	cin>>a>>b>>k;
	for(int i=1;i<=k;i++){
		if(i%2==1)
			play_it(true);
		else
			play_it(false);
	}
	cout<<a<<' '<<b;
	//cout<<endl<<((double)(clock()-start1)/CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int abs(int n){
  if(n < 0){
    n *= -1;
  }
  return n;
}


int main(void){
  int n , a , b , c;
  scanf("%d %d %d %d",&n,&a,&b,&c);
  
  int l[n];
  for(int i = 0;i < n;i ++){
    scanf("%d",&l[i]);
  }
  
  int max = 1;
  for(int i = 0;i < n;i ++){
    max *= 4;
  }
  
  int aa,bb,cc;
  int q,ans = 1000000000,count , j;
  
    for(int i = 0;i < max;i ++){
      q = i;
      aa = bb = cc = 0;
      count = 0;
      j = 0;
      while(q > 0){
        if(q %4 == 1){
          if(aa > 0){
            count += 10;
          }
            aa += l[j];
        }
        if(q%4 == 2){
          if(bb > 0){
            count += 10;
          }
          bb += l[j];
        }
        if(q%4 == 3){
          if(cc > 0){
            count += 10;
          }
          cc += l[j];
        }
        j ++;
        q /= 4;
      }
      if(aa == 0||bb == 0||cc == 0){
        continue;
      }
      count += abs(a - aa) + abs(b - bb) + abs(c - cc);
      if(ans > count){
        ans = count;
      }
    }
      
      printf("%d",ans);
      
      return 0;
    }
  

Measured memory_bytes: 128
s = input()
ans = 0
cntA = 0
for i in range(0, len(s) - 1):
    if s[i] == 'A':
        cntA += 1
    elif s[i: i + 2] == "BC":
        ans += cntA
    elif i > 0 and s[i - 1: i + 1] == "BC":
        continue
    else:
        cntA = 0
print(ans)
# print(*data, sep='\n')


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

typedef long long ll;

int main()
{
    int N, A;
    int X[55];
    ll dp[55][5500] = {};

    cin >> N >> A;

    dp[0][2600] = 1;

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

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

    cout << dp[N][2600] - 1 << endl;


    return (0);
}


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


using namespace std;

int main(){

  int H,W;
  int sum=0;
int tmp=10000000;

  cin>>H>>W;

  int A[H+1][W+1];

  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
  cin>>A[i][j];
    }
  }


for(int n=1;n<=H;n++){
for(int m=1;m<=W;m++){

  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){


sum=sum+min(abs(i-n),abs(j-m))*A[i][j];

 
    }
  }


if(sum<=tmp){tmp=sum;}
sum=0;

}
}

cout<<tmp<<endl;

  return 0;
}



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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll R[200005];

int main() {
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> R[i];
    }

    ll max = -INF;
    ll min = R[0];
    FOR(i, N, 1) {
        max = std::max(max, R[i] - min);
        min = std::min(R[i], min);
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 4608
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	REP(i, h) cin >> s[i];
	REP(i, h){
		REP(j, w){
			int n = 0;
			if(s[i][j] == '#'){
				cout << '#';
				continue;
			}
			for(int k = -1; k <= 1; ++k){
				for(int l = -1; l <= 1; ++l){
					if(k + i < 0 || k + i >= h) continue;
					if(l + j < 0 || l + j >= w) continue;
					if(s[k + i][l + j] == '#'){
						n += 1;
						// cout << "IJKL" << i << j << k << l << "\n";
					}
				}
			}
			cout << n;
		}
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int main() {
	int A[100] = {};
	int i = 12,e,cnt=0;
	while (i--) fscanf(stdin, "%d", &e), A[e-1]++;
	for (i = 0; i < 100; i++) if (A[i]) { if (A[i] % 4 == 0) cnt += A[i] / 4; }
	if (cnt == 3) puts("yes");
	else puts("no");
	return 0;
}

Measured memory_bytes: 584
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for A in range(a+1):
    for B in range(b+1):
        for C in range(c+1):
            if 500*A + 100*B + 50*C == x:
                cnt += 1

print(cnt)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n,k;
  cin >> n >> k;
  ll cnt = 0;
  ll lower=0,upper=0;
  ll p = 1000000007;
  for(ll i=k;i<=n+1;i++){
    lower = i*(i-1)/2;
    upper = i*(2*n-i+1)/2;
    cnt = cnt + (upper - lower + 1) % p;
  }
  cout << cnt % p<< endl;
  return(0);
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define per(i,m,n) for(lli i=m-1;i>=n;i--)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int x;
  cin>>x;
  if(x<1200)cout<<"ABC"<<endl;
  else cout<<"ARC"<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort()
b.sort()
c.sort()

def n_smaller_a(num):
    if num>a[n-1]:
        return n
    if num<=a[0]:
        return 0
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if a[mid]>=num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2

    if a[left]==num:
        return left
    else:
        return left+1

def n_bigger_c(num):
    if num >= c[n-1]:
        return 0
    if num < c[0]:
        return n
    left=0
    right=n-1
    mid=(left+right)//2
    while right-left>1:
        if c[mid]>num:
            right=mid
        else:
            left=mid
        mid=(left+right)//2
    if c[right]==num:
        return n-right-1
    else:
        return n-right

ans = 0

for i in range(n):
    ans+=n_bigger_c(b[i])*n_smaller_a(b[i])
print(ans)


Measured memory_bytes: 23328
#include<stdio.h>
int main(void)
{
	int a,b,c,max;

	scanf("%d %d %d",&a,&b,&c);


	if(a>b){
		max=a;
		a=b;
		b=max;
	}
	if(b>c){
		max=b;
		b=c;
		c=max;
	}

	if(a>b){
		max=a;
		a=b;
		b=max;
	}

	printf("%d %d %d\n",a,b,c);

	return 0;
}



Measured memory_bytes: 2032
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<cstdlib>

using namespace std;

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

int main(){
    long int n;
    cin >> n;
    long int ans = 0;
    for (int i = 1; i <= n; i++){
        if (i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }
    cout << ans << endl;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (long long i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int h,w;
int fld[10][10];
int sx,sy;
int num,ans;
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

void dfs(int x,int y,int cnt) {
	REP(i,4) {
		int nx=x,ny=y;
		while (true) {
			nx+=dx[i],ny+=dy[i];
			if(nx<0||nx>=w||ny<0||ny>=h) break;
			if(fld[ny][nx]==1) {
				fld[ny][nx]=0;
				dfs(nx,ny,cnt-1);
				fld[ny][nx]=1;
				break;
			}
			else if(fld[ny][nx]==2&&cnt==0) {
				ans++;
				return;
			}
		}
	}
	return;
}

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

    while(true) {
	cin>>w>>h;
	if(w==0) break;
	num=ans=0;
	REP(i,h) {
		REP(j,w) {
			cin>>fld[i][j];
			if(fld[i][j]==2) sy=i,sx=j;
			else if(fld[i][j]==1) num++;
		}
	}

	dfs(sx,sy,num);

	cout<<ans<<endl;
    }

	return 0;
}



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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define rep(i, n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) cout << setfill('0') << setw(len) << right << a << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

signed main() {
    int n, q;
    string s;
    cin >> n >> q >> s;
    vi a = vi(q), b = vi(q);
    vi ac = vi(n, 0);
    rep(i, q) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }

    for (int i = 1; i < n; ++i) {
        ac[i] = ac[i - 1];
        if (s[i - 1] == 'A' && s[i] == 'C') {
            ac[i]++;
        }
    }

    rep(i, q) {
        cout << ac[b[i]] - ac[a[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
program main
  implicit none
  logical::PRIME(10**5)=.true.
  integer::cnt(0:10**5)=0
  integer::i,j
  integer::Q,l,r
  Prime(1)=.false.
  do i=2,10**5
    if(.not.PRIME(i))cycle
    j=2
    do while(j*i<=10**5)
      PRIME(j*i)=.false.
      j=j+1
    end do
    if(Prime((i+1)/2))then
      cnt(i)=1
    endif
  end do
  do i=2,10**5
    cnt(i)=cnt(i)+cnt(i-1)
  end do
  
  read*,Q
  do i=1,Q
    read*,l,r
    print"(i0)",cnt(r)-cnt(l-1)
  end do
end program main

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

int main() {
  string s;
  cin >> s;
  
  int a_position = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i)=='A') {
      a_position = i;
      break;
    }
  }

  int z_position = 0;
  for (int i = s.size()-1; 0 < i; i--) {
    if (s.at(i)=='Z') {
      z_position = i;
      break;
    }
  }

  cout << z_position-a_position+1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define IN_OUT(n) ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) , cout << fixed << setprecision(n)
#define F first
#define S second
typedef pair<int,int> pii;
typedef pair<pii,int> tpi;
typedef pair<pii,pii> qpi;
typedef long long ll;
const int MOD = 1e9 + 7;
const int MAX = 1e5;
const int INF = 2e9;
int MA = -INF , MI = INF;

int cost[12][12] , amo[10] , dp[12][12];

int32_t main()
{
	IN_OUT(10);
	int n , m;
	cin>>n>>m;
	
	for(int i=0 ; i<10 ; i++)
	{
		for(int j=0 ; j<10 ; j++)
			cin >> dp[i][j];
	}
	
	for(int i=0 ; i<10 ; i++)
	{
		for(int k=0 ; k<10 ; k++)
			for(int j=0 ; j<10 ; j++)
				dp[k][j] = min( dp[k][j] , dp[k][i] + dp[i][j] );
	}
	
	int ans = 0;
	for(int i=1 ; i<=n ; i++)
	{
		for(int j=1 ; j<=m ; j++)
		{
			int x;
			cin >> x;

			if( x != -1 )
				ans += dp[x][1];
		}
	}

	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include        <bits/stdc++.h>
#define ll      long long int
#define pb      push_back
#define mp      make_pair
#define F       first
#define S       second
#define MOD     1000000007
#define pii     pair<int,int>
#define vi      vector<int>
#define fio     ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define N       200010
#define M       21
using namespace std;
#define nn       5000000000000000

ll expo(ll base, ll exponent) {								//return base^exponent modulo modulus
    ll ans = 1;
    while(exponent !=0 ) {
        if((exponent&1) == 1) {
            ans = ans*base ;
            ans = ans%MOD;
        }
        base = base*base;
        base %= MOD;
        exponent>>= 1;
    }
    return ans;
}

vector<ll> v,vv;

int main()
{
    fio;
    //cout<<expo((ll)2,(ll)nn)<<endl;
    ll k,x;
    string s;
    cin>>s>>k;
    ll c=0;
    ll n=s.length(),in=-1;
    for(int i=0; i<n; i++){
    	if(s[i]!='1'){
    		in=i;
    		break;
    	}
    }

    if(in==-1){
    	cout<<1;
    	return 0;
    }

    if(k<=in){
    	cout<<1;
    }
    else{
    	cout<<s[in];
    }

    
    return 0;
}













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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF (int)(1e9)

struct edge{int from,to,w;};
bool operator < (const edge &e, const edge &f) {
  return e.w != f.w ? e.w > f.w :
    e.from != f.from ? e.from < f.from : e.to < f.to;
}

vector<edge> g[1000];


int w,h;
int getpos(int x,int y){
  return x*h+y;
}
int MAX_POS(){
  return w*h;
}

// http://www.prefield.com/algorithm/graph/dijkstra.html
vi dijkstra(int s) {
  vi dist(MAX_POS(),INF);
  dist[s] = 0;
  priority_queue<edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push((edge){-2, s, 0}); !Q.empty(); ) {
    edge e = Q.top(); Q.pop();
    // if (prev[e.to] != -1) continue;
    REP(i,g[e.to].size()){
      edge f = g[e.to][i];
      if (dist[f.to] > e.w+f.w) {
        dist[f.to] = e.w+f.w;
        Q.push((edge){f.from, f.to, e.w+f.w});
      }
    }
  }
  return dist;
}

void addE(int from,int to){
  // if(from>1000 || to>1000)return;
  g[from].push_back((edge){from,to,1});
  g[to].push_back((edge){to,from,1});
}

int main(){
  while(true){
    cin>>w>>h;
    if(w==0 && h==0)break;
    // init
    REP(i,1000)g[i] = vector<edge>();
    // input
    REP(i,2*h-1){
      if(i%2==0){
        // yoko kabe
        REP(j,w-1){
          int t;
          cin >> t;
          if(t==0) addE(getpos(j,i/2),getpos(j+1,i/2));
          assert(j+1<=w-1);
          assert(i/2<=h-1);
        }
      }else{
        // tate kabe
        REP(j,w){
          int t;
          cin >> t;
          if(t==0) addE(getpos(j,i/2),getpos(j,i/2+1));
          assert(j<=w-1);
          assert(i/2+1<=h-1);
        }
      }
    }
    // dijkstra
    vi dist = dijkstra(0);
    if(dist[dist.size()-1]==INF){
      cout << 0 << endl;
    }else{
      cout << dist[dist.size()-1]+1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1304
#include <bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define int ll

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

  int N;
  cin>>N;
  vector<ll>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  ll Max=-INF;
  int Maxi;
  for(int i=0;i<N;i++){
    if(Max<A[i]){
      Maxi=i;
      Max=A[i];
    }
  }
  ll Min=INF;
  int Mini;
  for(int i=0;i<N;i++){
    if(Min>A[i]){
      Mini=i;
      Min=A[i];
    }
  }
  vector<pair<ll,ll>>ans;
  if(abs(Max)>=abs(Min)){
    for(int i=0;i<N;i++)A[i]+=A[Maxi],ans.push_back({Maxi+1,i+1});
    for(int i=0;i<N-1;i++)if(A[i]>A[i+1])A[i+1]+=A[i],ans.push_back({i+1,i+1+1});
  }
  else{
    for(int i=0;i<N;i++)A[i]+=A[Mini],ans.push_back({Mini+1,i+1});
    for(int i=N-1;i>=1;i--)if(A[i-1]>A[i])A[i-1]+=A[i],ans.push_back({i+1,i-1+1});
  }
  cout<<ans.size()<<endl;
  for(auto it:ans){
    cout<<it.first<<" "<<it.second<<endl;
  }
  return 0;
}



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

typedef unsigned long long ULL;
typedef long long LL;

const int PI = 3.1415926535;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 100007;


int main() {
	
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int n; cin >> n;
	vector <int> ar(n + 7);
	for (int i = 0; i < n; i++) 
		cin >> ar[i];
	int sofar = ar[0];
	LL ans = 0;
	for (int i = 1; i < n; i++) {
		if (ar[i] >= sofar) {
			sofar = ar[i];
		}
		else {
			ans += (sofar - ar[i]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3988
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int R = sc.nextInt();
    int C = sc.nextInt();
    int k = sc.nextInt();
    long[][] p = new long[R][C];
    for(int i = 0; i < k; i++) {
      int r = sc.nextInt() - 1;
      int c = sc.nextInt() - 1;
      long v = sc.nextLong();
      p[r][c] = v;
    }
    long[][][] dp = new long[R][C][4];
    if(p[0][0] > 0) {
      dp[0][0][1] = p[0][0];  
    }
    for(int i = 0; i < R; i++) {
      for(int j = 0; j < C; j++) {
        //下へ行く
        if(i != (R - 1)) {
          for(int m = 0; m < 4; m++) {
            dp[i + 1][j][0] = Math.max(dp[i + 1][j][0], dp[i][j][m]);
            if(p[i + 1][j] > 0) dp[i + 1][j][1] = Math.max(dp[i + 1][j][1], dp[i][j][m] + p[i + 1][j]);
          }
        }
 
        //右へ行く
        if(j != (C - 1)) {
          for(int m = 0; m < 4; m++) {
            dp[i][j + 1][m] = Math.max(dp[i][j + 1][m], dp[i][j][m]);
            if((p[i][j + 1] > 0) && (m > 0)) dp[i][j + 1][m] = Math.max(dp[i][j + 1][m], dp[i][j][m - 1] + p[i][j + 1]);
          }
        }
      }
    }
    long ans = dp[R - 1][C - 1][0];
    ans = Math.max(ans, dp[R - 1][C - 1][1]);
    ans = Math.max(ans, dp[R - 1][C - 1][2]);
    ans = Math.max(ans, dp[R - 1][C - 1][3]);
    System.out.println(ans);
  }
}

Measured memory_bytes: 719936
down = []
edge = []
pool = []
for i,c in enumerate(input()):
    if c == "\\":
        down.append(i)
    elif c == "/" and down:
        left = down.pop()
        area = i - left
        
        while edge:
            if edge[-1] > left:
                edge.pop()
                area += pool.pop()
            else:
                break
        
        edge.append(left)
        pool.append(area)
print(sum(pool))
print(" ".join(map(str,[len(pool)]+pool)))



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

int main()
{
    int n;
    string s, t;
    cin >> n >> s >> t;

    int i;
    for (i = 0; i < n; i++) {
        if (s.substr(i, n - i) == t.substr(0, n - i)) break;
    }

    cout << n + i << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(long long A, long long B){
    int tap = 1;
    int cnt = 0;
    while(tap < B){
        tap--;
        tap += A;
        cnt++;
    }

    cout << cnt << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

    int hapiness = 0;
    {
        // hapiness for R
        for (int i = 0; i < N - 1; i++) {
            if (S[i] == 'R' && S[i + 1] == 'R') {
                hapiness++;
            }
        }

        // hapiness for L
        for (int i = N - 1; i > 0; i--) {
            if (S[i] == 'L' && S[i - 1] == 'L') {
                hapiness++;
            }
        }
    }

    // printf("initial_hapiness: %d\n", hapiness);

    cout << min(N - 1, hapiness + 2 * K) << endl;

    return 0;
}


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

using namespace std;

#define rep(i, n)	for(int i = 0; i < (n); ++i)
#define repA(i, a, n)	for(int i = a; i <= (n); ++i)
#define repD(i, a, n)	for(int i = a; i >= (n); --i)
#define trav(a, x)	for(auto& a : x)
#define fix(a)	cout << setprecision(a); cout << fixed;
#define fast	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);
#define clr(a)	memset(a, 0, sizeof(a))
#define all(x)	(x).begin(), (x).end()
#define rall(x)	(x).rbegin(), (x).rend()
#define len(x)	((int)(x).size())
#define vi	vector<int>
#define vl	vector<ll>
#define vpii	vector<pair<int, int>>
#define vpll	vector<pair<ll, ll>>
#define ff	first
#define ss	second
#define mp	make_pair
#define pb	push_back

typedef long long ll;
typedef long double ld;

int main() {
	fast;
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++)
		cin>>arr[i];
	ll ans = 0;
	for(int i = 0; i < n - 1; i++) {
		int del=0;
		if(arr[i] > arr[i + 1])
			del = arr[i] - arr[i + 1];
		ans += del;
		arr[i + 1]+=del;
	}
	cout << ans;
}

Measured memory_bytes: 3952
N,M=map(int,input().split())
AB=[]
for i in range(N):
  AB.append(list(map(int,input().split())))
AB=sorted(AB,key=lambda x: x[0])
#print(AB)

ans=0
num=0
for i in range(N):
  if num+AB[i][1]>=M:
    ans+=AB[i][0]*(M-num)
    break
  else:
    num+=AB[i][1]
    ans+=AB[i][0]*AB[i][1]
  #print(ans)
print(ans)

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


int main(){
    int a,b,c; cin>>a>>b>>c;
    printf("%d %d %d\n", a, b, 3*c-a-b);
    printf("%d %d %d\n", -2*a-b+4*c, c, 2*a+b-2*c);
    printf("%d %d %d\n", a+b-c, 2*c-b, -a+2*c);
    return 0;
}

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

int main(){
	int N;
	int W;
	cin>>N>>W;
	int v[N]; 
	int w[N];
	int DP[N+1][W+1];
	for(int i=0;i<N;i++){
		cin>>v[i]>>w[i];
	}
	for(int i=0;i<=W;i++){
		DP[0][i]=0;
	}
	for(int i=1;i<=N;i++){
		for(int j=0;j<=W;j++){
			if(j<w[i-1]){
				DP[i][j]=DP[i-1][j];
			}else{
				if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1]){
					DP[i][j]=DP[i-1][j];
				}else{
					DP[i][j]=DP[i-1][j-w[i-1]]+v[i-1];
				}
			}
		}
	}
	
	cout<<DP[N][W]<<endl;
	return 0;
}

Measured memory_bytes: 7012
#include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}

#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define pii pair <int, int>
#define print(x) for(auto it : x) cout << it << ' ';
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (int)(2e18);
const int mod = (int)(1e9) + 7; // check modulo
const double eps = (1e-6);

int cnt[N], a[N];

void solve(int test) {
    int n; cin >> n;
    int all = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        all ^= a[i];
    }
    for(int i = 1; i <= n; ++i) {
        cout << (a[i] ^ all) << ' ';
    }

}

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test = 1;// cin >> test;
    for(int tt = 1; tt <= test; ++tt) {
        solve(tt);
    }


    return 0;
}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

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

  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  vector<ll> v;
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);
  int index = max_element(v.begin(), v.end())-v.begin();
  v[index] *= pow(2, k);
  cout << accumulate(v.begin(), v.end(), 0) << endl;
  return 0;
}


Measured memory_bytes: 256
import math

while True:
    d, w, h = [int(x) for x in input().split()]
    if d == w == h == 0:
        break
    dw = math.sqrt(d * d + w * w)
    dh = math.sqrt(d * d + h * h)
    wh = math.sqrt(w * w + h * h)
    min_ = min(dw, dh, wh)
    n = int(input())
    for i in range(n):
        r = int(input()) * 2
        if r > min_:
            print('OK')
        else:
            print('NA')

Measured memory_bytes: 7696
import sys
sys.setrecursionlimit(10**9)
MOD=10**9+7
N=int(input())

tree=[[] for _ in range(N+1)]
for _ in range(N-1):
  A,B=map(int,input().split())
  tree[A].append(B)
  tree[B].append(A)
#print(tree)

def dfs(u,par):
  visited[u]=True
  ret=1
  for v in tree[u]:
    if not visited[v]:
      ret+=dfs(v,u)

  if par>0:
    tree_dic[(u,par)]=ret
  return ret
  
visited=[False]*(N+1)
tree_dic={}
dfs(1,0)
#print(tree_dic)

bumbo=pow(2,N,MOD)
bunshi=(pow(2,N,MOD)-1-N*pow(2,N-1,MOD))%MOD
for x in tree_dic.values():
  term=(pow(2,x,MOD)-1)*(pow(2,N-x,MOD)-1)
  bunshi+=term  
  bunshi%=MOD
#print(bunshi,bumbo)

answer=bunshi*pow(bumbo,MOD-2,MOD)
answer%=MOD
print(answer)

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

#define ll long long 
#define pb push_back
ll mod =  998244353;
ll modexpo(ll a,ll b)
{
	if(b==0)
	{
		return 1;
	}
	if(b==1)
	{
		return a%mod;
	}
	else 
	{
		ll temp = modexpo(a,b/2);
		temp = temp*temp;
		temp %= mod;
		if(b%2==0)
		{
			return temp%mod;
		}
		else
		{
			return (temp*a)%mod;
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t;
	t = 1;
	//cin >> t;
	while(t--)
	{
		ll n;
		cin >> n;
		ll arr[n];
		ll i;
		ll cnt[n] = {0};
		for(i=0;i<n;i++)
		{
			cin >> arr[i] ;
			cnt[arr[i]]++;
		}
		if(arr[0] != 0)
		{
			cout <<0 << endl;
		}
		else
		{
			ll count = 0;
			ll ans = 1;
			ll prev = 1;
			for(i=1;i<n;i++)
			{
				if(cnt[i] == 0)
				{
					break;
				}
				count += cnt[i];
				ans *= modexpo(prev,cnt[i]);
				prev = cnt[i];
				ans %= mod;

			}
			if(count != n-1)
			{
				

				cout << 0 << endl;
			}
			else
			{
				cout << ans << endl;
			}

		}
	}

	return 0;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    just, less = 0, INF
    for d in input()[::-1]:
        d = int(d)
        njust = min(just + d, less + d + 1)
        nless = min(just + (10-d), less + (9-d))
        just, less = njust, nless
    print(min(just, less + 1))
resolve()

Measured memory_bytes: 58224
w, h, n = gets.chomp.split.map(&:to_i)
s = []
h.times do |i|
  s[i+1] = " " + "." * w
end
n.times do
  x, y, a = gets.chomp.split.map(&:to_i)
  if a == 1
    h.times do |i|
      s[i+1][1..x] = "#" * x
    end
  elsif a == 2
    h.times do |i|
      s[i+1][x+1..w] = "#" * (w - x)
    end
  elsif a == 3
    y.times do |i|
      s[i+1][1..w] = "#" * w
    end
  else
    (h - y).times do |i|
      s[h-i][1..w] = "#" * w
    end
  end
end
cnt = 0
h.times do |i|
  cnt += s[i+1].count(".")
end
p cnt

Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	vector<vector<int>> graph(n, vector<int>());
	vector<int> deg(n);
	vector<int> a(n - 1), b(n - 1);
	rep(i, n - 1) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		graph[a[i]].pb(b[i]);
		graph[b[i]].pb(a[i]);
		deg[a[i]]++;
		deg[b[i]]++;
	}
	int cnt = 0;
	queue<int> que;
	rep(i, n) if (deg[i] == 1) que.push(i);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		if (deg[p] != 1) continue;
		int q = -1;
		for (int i : graph[p]) {
			if (deg[i]) q = i;
		}
		if (q != -1) cnt++;
		else {
			cout << "First" << endl;
			return 0;
		}
		deg[p] = 0; deg[q] = 0;
		for (int i : graph[q]) {
			if (i == p || !deg[i]) continue;
			deg[i]--;
			if (deg[i] == 1) {
				que.push(i);
			}
		}
	}
	cout << (cnt * 2 != n ? "First" : "Second") << endl;
}

Measured memory_bytes: 9088
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		if(K == 0) {
			System.out.println((long)N * N);
			return;
		}
		long ans = 0;
		for(int i = K+1; i <= N; i++)
			ans += N / i * (i - K) + Math.max(0, N % i - K + 1);
		System.out.println(ans);
	}

}

Measured memory_bytes: 23764
N,M = gets.split(' ').map(&:to_i)
#n,k=gets.split(' ').map(&:to_i)
A=gets.split(' ').map(&:to_i).sort
#tajigen = Array.new(4) { Array.new(2,0) }
#maze = h.times.map { gets.chomp }
A_min = A[0]
A_max = A.last

$a_cnt = Array.new(A_max+1,0)

A.each do |i|
  $a_cnt[i] += 1
end

for i in 1..A_max
  $a_cnt[i] += $a_cnt[i-1]
end

cnt = 0
def countup(mid)
  cnt = 0
  A.each do |i|
    put = mid-i
    if put >= A_max
      next
    elsif put < A_min
      cnt += N
    else
      cnt += N-$a_cnt[put]
    end
    break if cnt > M
  end
  return cnt
end

min = A_min - 1
max = A_max * 2 + 1

while (max-min)!=1
  mid = (max+min)/2
  if countup(mid)>=M
    min=mid
  else
    max=mid
  end
end
#puts max

A_rui = Array.new(N+1,0)
for i in 0..N-1
  A_rui[i+1] = A_rui[i] + A[N-1-i]
end
#puts A_rui

ans = 0
a_count = 0

for i in 0..N-1
  x=max-A[i]
  if x<=A_min
    ans += A[i] * N + A_rui[N]
    a_count += N
  elsif x>A_max
    next
  else
    t = N - $a_cnt[x-1]
    ans += A_rui[t] + A[i]*t
    a_count += t
  end
end

ans -= (a_count-M)*max if a_count > M
puts ans


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

/*  using namespace  */
using namespace std;

/*  local var  */

/*  define  */
#define loop(i,j) for(int i = 0; i < j; i++)

/*  typedef  */
typedef long long ll;

/*  function  */
//None

/*  main program  */
int main()
{
	ll A,B;	
	cin>>A>>B;
	A--;
	loop(i,A) cout<<B+i-A<<" ";
	loop(i,A+1) cout<<B+i<<" ";
	cout<<endl;
}



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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while (A > 0 || C > 0) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            break;
        }

        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            break;
        }
        
        
    }
        
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(void)
{
	int data[31];
	int d,i;
	
	for(i=1;i<31;i++)data[i]=0;
	
	for(i=1;i<=28;i++){
		scanf("%d",&d);
		data[d]=1;
	}
	for(i=1;i<=30;i++){
		if(data[i]==0){
			printf("%d\n",i);
		}
	}
	return 0;
}


Measured memory_bytes: 2044
a,b = open(0).read().split()
na = len(a)
nb = len(b)

ans = float('inf')
for i in range(na-nb+1):
#     print(a[i:i+nb])
    tmp = nb
    for j in range(nb):
        if a[i+j] == b[j]:
            tmp -= 1
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 67740
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second 
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define pp pair<ll,ll> 
#define sz(v) int(v.size())
#define hell (ll)1000000007
#define hell1 (ll)100000009
#define hell2 (ll)998244353
ll t = 1 ;
void solve()
{
    ll n , k ;
    cin >> n >> k ;
    rep( i , -1000000 , 1000001 ){
        if( abs(i-k)<n)
            cout << i << ' ' ;
    }
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin>>t ;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a[102],x,n;
	int i,t;
	scanf("%d%d",&x,&n);
	for(i=0;i<=101;i++)
	{
		a[i]=0;
	}
	for(i=0;i<n;i++)
	{
		scanf("%d",&t);  //从1开始 
		a[t]=1;
	}
	i=0;
	while(1)
	{
		if(x-i>=0&&a[x-i]==0)
		{
			printf("%d",x-i);
			break;
		}
		if(x+i<=101&&a[x+i]==0)
		{
			printf("%d",x+i);
			break;
		}
		i++;
	}
	return 0;
}

Measured memory_bytes: 1736
#include <stdio.h>
int main(void){
    int n,a,b,c,d,i=0;
    scanf("%d",&n);
    while(1){
    scanf("%d %d %d",&a,&b,&c);
    if(a<=b){
        d=a;
        a=b;
        b=d;
    }
    if(b<=c){
        d=b;
        b=c;
        c=d;
    }
    if(a<=b){
        d=a;
        a=b;
        b=d;
    }
    if(a*a==b*b+c*c){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
    i++;
    if(i==n){
        break;
    }
    }
    return 0;
}

Measured memory_bytes: 580
//
//  sublime text 3,
//  emre yazicioglu
//

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
#define pb push_back
#define fi first
#define se second
#define INF (ll) 1e18 + 7

const ll mod = 1e9 + 7;
const int N = 2e6 + 7;
ll mn = INF, mx = -INF;
ll n, m, k, s, q, t;
ll a, b, c, d, e;
ll ans, cur, sum, cnt;
ll ar[N], dp[N];
string str; bool h[N];
pll pp[N]; vll v;
ll p[N]{1};

ll fe(ll a, ll b) {
  if(b == 0)
    return 1;
  ll t = fe(a, b / 2);
  return (b & 1 ? (t * t) % mod * a % mod : (t * t) % mod) % mod;
}

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

  // freopen("../in.txt","r",stdin);
  // freopen("../out.txt","w",stdout);

  cin >> a >> b;
  if((a + b) % 3 != 0) {
    cout << 0;
    return 0;
  }
  for(int i = 1; i <= N; i++)
    p[i] = (p[i - 1] * i) % mod;
  c = (a + b) / 3;
  n = (c + a - b) / 2;
  m = c - n;
  if(n < 0 || m < 0) {
    cout << 0;
    return 0;
  }
  cout << p[c] * fe(p[n], mod - 2) % mod * fe(p[m], mod - 2) % mod;
}

Measured memory_bytes: 17920
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  
  REP(i,ty-sy) cout << 'U';
  REP(i,tx-sx) cout << 'R';
  REP(i,ty-sy) cout << 'D';
  REP(i,tx-sx) cout << 'L';
  cout << 'L';
  REP(i,ty-sy+1) cout << 'U';
  REP(i,tx-sx+1) cout << 'R';
  cout << "DR";
  REP(i,ty-sy+1) cout << 'D';
  REP(i,tx-sx+1) cout << 'L';
  cout << 'U';

  return 0;
}

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

using namespace std;

long long ans = 1;
vector<int> charas(26,0);

int main() {
	int N;
	string str;

	cin >> N >>str;

	for (int i = 0; i < N; i++) {
		charas[str[i] - 'a']++; 
	}

	//文字iを選ぶor選ばない

	for (int i = 0; i < 26; i++) {
		ans =( ans * (charas[i] + 1) )% ((int)1e9 + 7);
	}
	if(ans != 0) ans--;
	else ans = ((int)1e9 + 7) - 1;
	
	cout << ans << endl;

	return 0;
}

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

int main() {
  int a, b, c, i;
  cin >> a >> b >> c;
  
  bool ans = false;
  for(i = 1; i <= 100; i++){
    if((a * i) % b == c){
      ans = true;
      break;
    }
  }
  
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int x;
	cin >> x;
	string s;
	if(x==25) s="Christmas";
	if(x==24) s="Christmas Eve";
	if(x==23) s="Christmas Eve Eve";
	if(x==22) s="Christmas Eve Eve Eve";
	cout << s  << endl;

	return 0;
}

Measured memory_bytes: 256