akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::pair;
using std::make_pair;

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

int main(void) {
    int n;
    pair<int, int> now; // ????±?, ??????
    int number;
    pair<int, int> coord;
    int y_max;
    int y_min;
    int x_max;
    int x_min;

    while (1) {
        std::cin >> n;
        if (n == 0) {
            break;
        }

        number = 0;
        y_max = -1e09;
        y_min = 1e09;
        x_max = -1e09;
        x_min = 1e09;

        vector<pair<int, int> > map;
        map.push_back(make_pair(0, 0));

        for (int i = 0; i < n - 1; i++) {
            std::cin >> now.first >> now.second; 
            number++;
            coord = map[now.first];
            map.push_back(make_pair(coord.first + dy[now.second], coord.second + dx[now.second]));
        }
        for (int j = 0; j < map.size(); j++) {
            coord = map[j];
            if (y_max < coord.first) {
                y_max = coord.first;
            }
            if (y_min > coord.first) {
                y_min = coord.first;
            }
            if (x_max < coord.second) {
                x_max = coord.second;
            }
            if (x_min > coord.second) {
                x_min = coord.second;
            }
        }

        cout << x_max - x_min + 1 << " " << y_max - y_min + 1 << endl;

    }
    return 0;
}

Measured memory_bytes: 2960
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>

const int MAXN = 5e5 + 10, MOD = 998244353;

int n, k;
int fac[MAXN], ifac[MAXN];
inline int Qpow(int A, int B) { int ans = 1; for (; B; A = 1LL * A * A % MOD, B >>= 1) if (B & 1) ans = 1LL * ans * A % MOD; return ans; }
inline int inv(int A) { return Qpow(A, MOD - 2); }

inline int binom(int n, int m) { if (n < m || m < 0) return 0; return 1LL * fac[n] * ifac[m] % MOD * ifac[n - m] % MOD; }
inline void init(void) {
	fac[0] = 1;
	for (int i = 1; i < MAXN; ++i) fac[i] = 1LL * fac[i - 1] * i % MOD;
	ifac[MAXN - 1] = inv(fac[MAXN - 1]);
	for (int i = MAXN - 2; ~i; --i) ifac[i] = 1LL * ifac[i + 1] * (i + 1) % MOD;
	return;
}

int main(void) {
	scanf("%d%d", &n, &k), init();
	int ans = 0;
	for (int i = 1; i <= k; ++i) {
		int R = i, B = k - R;
		if (R < n) continue;
		if (R == B) ans = ans + binom(k - 1, R) - binom(k - 1, (R << 1) - n + 1);
		else if (R > B) ans = ans + binom(k, R) - binom(k, (R << 1) - n + 1);
		while (ans >= MOD) ans -= MOD;
		while (ans < 0) ans += MOD;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4096
#include<stdio.h>
#include<string.h>
int main(void)
{
    char str[1000];
    int n,i;
    int count = 0;
    scanf("%s",str);
    n = strlen(str);
    for(i=0;i < n/2;i++){
        if(str[i] != str[n-i-1]){
            count++;
        } 
    }
    printf("%d",count);
    return 0;
}

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


typedef struct edge{
  int to;
  int cost;
} edge;

vector<vector<edge>> Tree(100001);
vector<int> color(100001,-1);

void coloring(int n){
  if(color[n]==-1){
    for(int i=0;i<Tree[n].size();i++){
      int P=Tree[n][i].to;
      int D=Tree[n][i].cost;
      if(color[P]==0){
        if(D%2==0){
          color[n]=0;
          break;
        }else{
          color[n]=1;
          break;
        }
      }else if(color[P]==1){
        if(D%2==0){
          color[n]=1;
          break;
        }else{
          color[n]=0;
          break;
        }
      }
    }
  }
  for(int i=0;i<Tree[n].size();i++){
    int P=Tree[n][i].to;
    if(color[P]==-1) coloring(P);
  }
  return ;
}

int main(){
  int N;
  cin >> N;
  for(int i=1;i<=N-1;i++){
    int a,b,c;
    cin >> a >> b >> c;
    edge e;
    e.to = b; e.cost = c;
    Tree[a].push_back(e);
    e.to = a;
    Tree[b].push_back(e);
  }
  color[1] = 0;
  coloring(1);
  for(int i=1;i<=N;i++){
    cout << color[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 8704
#include <fstream>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <cassert>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <regex>

using namespace std;

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


//#define LOCAL_DEBUG
int main() {
#ifdef LOCAL_DEBUG
	freopen("input1.txt","r", stdin);
#endif
	ll N, A, B;
	cin >> N >> A >> B;

	ll ans = 0;
	int x; cin >> x;
	for (int i = 1; i < N; i++) {
		int nx; cin >> nx;
		ans += min(A * (nx - x), B);
		x = nx;
	}

	cout << ans << endl;


 	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
const int INF = 1e9;
const int MOD = 1e9+7;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int H, W, A, B; cin >> H >> W >> A >> B;
    int x = 1, y = 0;
    REP(i, H)
    {
        if(i == B) swap(x, y);
        REP(j, W)
        {
            if(j < A) cout << x;
            else cout << y;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1280
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#define debug cout

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n);i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<=(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

vint v;

int main() {
	int a,b,c,d,e;
	while(cin>>a>>b){
		v.clear();
		if(a<=0){
			cout<<0<<endl;
		}else if(a==1){
			cout<<1<<endl;
		}else{
			v.PB(2);
			v.PB(3);
			c=2;
			d=3;
			repn(i,3,a){
				v.PB(e=(c+d)%1001);
				c=d;
				d=e;
			}
			sort(all(v));
			int res=1;
			rep(i,sz(v)-1){
//debug<<v[i]<<" ";
				if(v[i+1]-v[i]>=b)++res;
			}
//debug<<v[sz(v)-1]<<endl;
			cout<<res<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define N 2005
#define pii pair<int,int>
deque<int> q1,q2;
char t[N];
int n,ans=1e9;
int tol[N],tor[N];
int mx[N];
int calc(int step){
    int ret=step;
    deque<int> a=q1;
    for(int i=0;i<n;i++){
        a[i]=a[i]!=q2[(i-step+n)%n]? 1:0;
        ret+=a[i];
        if(a[i]==1&&tol[i]<=step)
            a[i]=0;
    }
    for(int i=1;i<=step;i++) a.push_back(a.front()),a.pop_front();
    memset(mx,0,sizeof(mx));
    for(int i=0;i<n;i++)
        if(a[i]==1) mx[tol[i]]=max(mx[tol[i]],tor[i]-step);
    for(int i=n-1;i>=0;i--) mx[i]=max(mx[i],mx[i+1]);
    int t=1e9;
    for(int i=0;i<n;i++) t=min(t,i+mx[i+1]);
    return ret+t*2;
}
int main(){
    scanf("%s",t+1);
    n=strlen(t+1);
    bool is0=true;
    for(int i=1;i<=n;i++) q1.push_back(t[i]-'0'),is0&=(t[i]=='0');
    scanf("%s",t+1);
    int dl=-1,dr=-1;
    for(int i=1;i<=n;i++){
        q2.push_back(t[i]-'0');
        if(t[i]=='1') dr=n-i;
        if(t[i]=='1'&&dl==-1) dl=i-1;
    } 
    if(!is0&&dr==-1) return puts("-1"),0;
    else if(is0&&dr==-1) return puts("0"),0;
    for(int i=0;i<n;i++){
        if(q2[i]==1) dr=0;
        else dr++;
        tol[i]=dr;
    }
    for(int i=n-1;i>=0;i--){
        if(q2[i]==1) dl=0;
        else dl++;
        tor[i]=dl;
    }
    for(int i=0;i<n;i++) ans=min(ans,calc(i));
    reverse(q1.begin(),q1.end());
    reverse(q2.begin(),q2.end());
    for(int i=0;i<n/2;i++)
        swap(tol[i],tor[n-i-1]),swap(tor[i],tol[n-i-1]);
    if(n%2==1) swap(tol[n/2],tor[n/2]);
    for(int i=0;i<n;i++) ans=min(ans,calc(i));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	int z = a * b;
	if(z % 2 == 0) printf("Even\n");
	else printf("Odd\n");
}

Measured memory_bytes: 128
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]
dict = {}
 
if M == 0 :
    if N == 1 :
        print(0)
    else :
        print(10**(N-1))
    exit()
 
for x in L :
    dict.setdefault(x[0],[])
    dict[x[0]].append(x[1])
dict.setdefault(1,[1])
 
for k,v in dict.items():
    dict[k] = set(v)
 
ansList = ["0"]*N
for i in range(N) :
    if i+1 in dict :
        ansList[i] = str(list(dict[i+1])[0])
 
isZeroHead = 2 <= N and ansList[0] == "0"
isOverlapping = any([ 2 <= len(v) for v in dict.values()])  
ans = -1 if isZeroHead or isOverlapping else int("".join(ansList))
 
# print(dict)
# print("isZeroHead :",isZeroHead)
# print("isOverlapping :",isOverlapping)
print(ans)

Measured memory_bytes: 9184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		StringTokenizer st = new StringTokenizer(str, " ");
		int W = Integer.parseInt(st.nextToken());
		int H = Integer.parseInt(st.nextToken());
		int x = Integer.parseInt(st.nextToken());
		int y = Integer.parseInt(st.nextToken());
		int r = Integer.parseInt(st.nextToken());

		if(x-r < 0 || y-r < 0 || x+r > W || y+r > H) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}

}

Measured memory_bytes: 24328
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var T = ReadLine().Split().Select(long.Parse).ToArray();
        var A = ReadLine().Split().Select(_ =>long.Parse(_)).ToArray();
        var B = ReadLine().Split().Select(_ => long.Parse(_)).ToArray();

        var dif1 = (A[0] - B[0])*T[0];
        var dif2 = (A[1] - B[1]) * T[1];

        if (dif1 + dif2 == 0)
        {
            WriteLine("infinity");
        }
        else if ((dif1 >= 0 && dif1+ dif2 <= 0)||(dif1<=0&&dif1 + dif2>=0))
        {
            long ans = 1;
            ans += Abs(dif1 / (dif1+dif2))*2;
            if (dif1 % Abs(dif1 + dif2) == 0) ans--;
            WriteLine(ans);
        }
        else WriteLine(0);
    }
}


Measured memory_bytes: 28172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int sum_all = 0;
  for (int i = 1; i <= N; i++) {
    int sum = 0;
    int num = i;
    while (1) {
      sum += num % 10;
      num /= 10;
      if (num == 0) {
        if (A <= sum && sum <= B) sum_all += i;
        break;
      }
    }
  }
  cout << sum_all;
}
  


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

int main() {
    int N; cin >> N;
    set<string> ans;
    auto f = [&](auto &&f, string s, int n) -> void {
        int len = s.size();
        if(len == N) {
            ans.insert(s);
            return;
        }
        for(int i = 0; i <= n; ++i) {
            char c = (char)'a' + i;
            f(f, s + c, n + (i == n));
        }
    };
    f(f, "a", 1);
    for(auto &a : ans) cout << a << '\n';
    return 0;
}


Measured memory_bytes: 12416
// 1 Dimensional World's Tale

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>

using namespace std;

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    int x;
    int y;

    int x_max = -200;
    for (int i = 0; i < N; i++) {
        cin >> x;
        if (x > x_max) {
            x_max = x;
        }
    }

    int y_min = 200;
    for (int i = 0; i < M; i++) {
        cin >> y;
        if (y < y_min) {
            y_min = y;
        }
    }

    bool war_happen = true;

    for (int i = X+1; i <= Y; i++) {
        if (x_max < i && i <= y_min) {
            war_happen = false;
            break;
        }
    }

    if (war_happen) {
        cout << "War" << endl;
    } else {
        cout << "No War" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import itertools

n = int(input())
lst = [str(input())[0] for i in range(n)]
l_march = ["M","A","R","C","H"]
l_a = []
for i in l_march:
    l_a.append(lst.count(i))
l_b = list(itertools.combinations(range(5),3))
ans=0
for i in l_b:
    ans += l_a[i[0]]*l_a[i[1]]*l_a[i[2]]
print(ans)

Measured memory_bytes: 3968
#include <bits/stdc++.h>
//#include <atcoder/math>
//using namespace atcoder;
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;
ll  LINF = 1e18;

int main(){
	int n;cin >> n;
	vector<int> p(n),a(n),b(n),sum(n);
	rep(i,n) {
		int ind;cin >> ind;
		ind--;
		sum[ind] = INF - n + i; 	
	}
	
	rep(i,n) {
		a[i] = i+1;
		b[i] = sum[i]-a[i];
	}
	for(int i = 1;i < n;i++){
		if(a[i] <= a[i-1]) {
			b[i] -= (a[i-1]-a[i]+1);
			a[i] = a[i-1]+1;
		}
		if(b[i]>=b[i-1]){
			a[i] += b[i]-b[i-1]+1;
			b[i] = b[i-1]-1;
		}
	}
	rep(i,n) cout << a[i] << " ";
	cout << endl;
	rep(i,n) cout << b[i] << " ";
	cout << endl;

}

Measured memory_bytes: 3904
#include <algorithm>
#include <iostream>
#include <string>

int main() {
  std::string s[3];
  std::cin >> s[0] >> s[1] >> s[2];

  for (int i = 0; i < 3; ++i) {
    std::transform(s[i].cbegin(), s[i].cend(), s[i].begin(), toupper);
    std::cout << s[i][0];
  }
  std::cout << std::endl;

  return 0;
}


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

typedef long long ll;
const ll INF = 1LL << 60;

inline bool chmin(ll& a, ll b) { if (a > b) { a = b; return true; } return false; }
inline bool chmax(ll& a, ll b) { if (a < b) { a = b; return true; } return false; }

int N;
int K;
vector<ll> height;
vector<ll> cost;

int main() {

  cin >> N >> K;

  height = vector<ll>(N+K,0);
  cost = vector<ll>(N+K,INF);

  for (ll i=0; i<N; i++){
    cin >> height.at(i);
  }

  cost.at(0) = 0;
  for (ll i=0; i<N; i++){
    for (ll j=0; j<K; j++){
      chmin(cost.at(i+j+1), cost.at(i)+abs(height.at(i+j+1) - height.at(i)));
    }
  }

  cout << cost.at(N-1) << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
const int inf=0x3f3f3f3f;
long long a[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>a[i];
    long long sum=0;
    for(int i=2;i<=n;i++)
    {
    	if(a[i]<a[i-1])
    	{
    		sum+=a[i-1]-a[i];
    		a[i]=a[i-1];
    	}
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 5200
#include<cstdio>
#include<iostream>
using namespace std;
int a,b,c,d,e;
int main(){
  scanf("%d%d%d",&a,&b,&c);
  d=max(a,b);d=max(c,d);
  e=min(a,b);e=min(c,e);
  printf("%d",d-e);
}

Measured memory_bytes: 256
lista=[3,5,7]
count=0
lim=int(input())
while True:
    t=lista.pop(0)
    if t>lim:
        break
    c=list(str(t))
    if c.count("3") and c.count("5") and c.count("7"):
        count+=1
    lista.append(10*t+3)
    lista.append(10*t+5)
    lista.append(10*t+7)
print(count)

Measured memory_bytes: 5924
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int cout = 0;
	int[] a = new int[n];
	for(int i=0; i<n; i++) {
		a[i] = sc.nextInt();
	}
	for(int i=0; i<n; i++) {
		if(a[i] % 2 == 1) {
			cout++;
		}
	}
	if(cout % 2 == 1) {
		System.out.println("NO");
	} else {
		System.out.println("YES");
	}
}
}


Measured memory_bytes: 49872
# C - H and V
def main():
    H, W, K, *C = open(0).read().split()
    H, W, K, C = int(H), int(W), int(K), "".join(C)
    res = 0
    for bit in range(1 << (H + W)):
        cnt_black = sum(
            C[i * W + j] == "#" and not (bit >> i) & 1 and not (bit >> (j + H)) & 1
            for i in range(H)
            for j in range(W)
        )
        if cnt_black == K:
            res += 1
    print(res)


if __name__ == "__main__":
    main()


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

using namespace std;
int nums[20]={10};
int K;
int test(int nums[] ,int now){
  if(nums[now+1]==10){
    if(nums[now]>=9){
      nums[now+1]=1;
      nums[now]=0;
    }else{
      nums[now]++;
    }
    return nums[now];
  }
  //cout<<abs(nums[now+1]-nums[now])<<" "<<nums[now+1]<<" "<<nums[now]<<"\n";
  if(abs(nums[now+1]-nums[now]-1)>1){//繰り上げrunrun
    int result=test(nums,now+1);
    return nums[now]=(result-1>=0)? result-1 : 0;
  }else{//繰り上げ9
    nums[now]++;
    if(nums[now]>9){
        int result=test(nums,now+1);
        return nums[now]=(result-1>=0)? result-1 : 0;
    }
    return nums[now];
  }
}
void show(){
  int w;
  for(int i=0; nums[i]!=10;i++){
    w=i;
  }
  for(int i=w; i>=0;i--){
    if(nums[i]!=10)cout<<nums[i];
  }
  cout<<"\n";
}
int main()
{
  for(int i=0;i<20;i++){
    nums[i]=10;
  }
  nums[0]=0;
  cin>>K;
  for(int i=0; i<K; i++){
    test(nums,0);
  //  show();
  }
  show();
  return 0;
}




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

int main(){
  int n,counter=0;
  cin >> n;
  int* A = new int[n];

  for(int i=0;i<n;i++) cin >> A[i];

  for(int i=0;i<n;i++){
    int minj = i;
    for(int j=i;j<n;j++){
      if(A[j] < A[minj]){
        minj = j;
      }
    }
    if(minj != i){
      A[i] ^= A[minj]; A[minj] ^= A[i]; A[i] ^= A[minj];
      counter++;
    }
  }
  for(int i=0;i<n;i++){
    cout << (i != 0 ? " " : "") << A[i];
  }
  cout << endl << counter << endl;
  delete[] A;
}


Measured memory_bytes: 3048
#include <stdio.h>
#include<string.h>
int main()
{
long int a=0,b=0,w=0,i,str1=0,str2=0,flag,j,count=1;
char x[200000];
scanf("%s",x);
i=0;
while(x[i]!='A' && i<strlen(x))
{
    i++;
}
if(x[i]!='A')
{
    printf("0");
    exit(0);
}
j=strlen(x);
while(x[j-1]!='Z' && i!=j)
{
   j--;
   
}
if(i==j)
{
    printf("0");
}else{
    printf("%ld",j-i);
}
   
 return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python
"""AtCoder Beginner Contest 171: B - Mix Juice
https://atcoder.jp/contests/abc17/tasks/abc171_b
"""


def main():
    N, K = list(map(int, input().split()))
    Ps = list(map(int, input().split()))

    ans = 0
    Ps.sort()
    for p in Ps[0:K]:
        ans += p
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
a,b = map(int, input().split())
if (a <= 0 and b >= 0):
    print ("Zero")
    exit()
if (a < 0 and b < 0):
    diff = b - a + 1
    if (diff % 2 == 0):
        print ("Positive")
    else:
        print ("Negative")
    exit()
if (a > 0 and b > 0):
    print ("Positive")
    exit()


Measured memory_bytes: 43120
def c_grid_repainting(H, W, Grid):
    delta = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    for h in range(H):
        for w in range(W):
            if Grid[h][w] == '.':  # 白マスは無視
                continue
            black = 0  # マス(h,w)に隣り合った黒マスの数
            for dh, dw in delta:
                is_internal = 0 <= h + dh < H and 0 <= w + dw < W
                if is_internal and Grid[h + dh][w + dw] == '#':
                    # 隣のマスはキャンバスの内部で、黒だった
                    black += 1
            if black == 0:
                # 黒マス候補の隣に黒マスがなかった。そのマスは塗れない
                return 'No'
    return 'Yes'

H,W = [int(i) for i in input().split()]
Grid = [input().strip() for _ in range(H)]
print(c_grid_repainting(H, W, Grid))

Measured memory_bytes: 3064
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cassert>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

typedef std::pair <int, int> pii;
typedef long long ll;
typedef std::vector <ll> vll;

using namespace std;


int main() {
	int testCnt;
	cin >> testCnt;
	while (testCnt--) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		if (a < b) cout << "No" << endl;
		else if (d < b) cout << "No" << endl;
		else {
			if (c >= b - 1) {
				cout << "Yes" << endl;
				continue;
			}
			d = d % b;
			a = a % b;
			if (a > c) {
				cout << "No" << endl;
				continue;
			}
			ll f = (c + 1) - a;
			ll s = (b - 1) - a;
			if (d == 0) {
				cout << "Yes" << endl;
				continue;
			}
			if (b - 1 - (c + 1) + 1 >= d) {
				cout << "No" << endl;
				continue;
			}
			if (f % d > s % d || f % d == 0) 
				cout << "No" << endl;
			else {
				ll diff = __gcd(d, b);
				if (s - f + 1 >= diff || f % diff == 0)
					cout << "No" << endl;
				else if (f % diff > s % diff) cout << "No" << endl;
				else cout << "Yes" << endl;
			}		
			continue;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <numeric>
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;

#define ll long long int
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repp(i, n) for(ll i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
const ll MOD = 1e9 + 7;
set<char> alphabet = { 'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z' };



int main() {
    int N;
    cin >> N;
    vi A(N+1);
    repp(i, N)cin >> A[i];
    vi ans(N+1);
    ll sum = 0;
    for (int i = 2; i <= N; i++) {
        if (i % 2 == 0)sum -= A[i];
        else sum += A[i];
    }
    sum -= A[1];
    sum = -sum;
    ll x = sum / 2;
    ans[1] = 2 * (A[1] - x);
    for (int i = 1; i < N; i++) {
        ans[i + 1] = A[i] - ans[i] / 2;
        ans[i + 1] *= 2;
    }
    repp(i, N)cout << ans[i] << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define mod          10000007
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1};  // 8 Direction
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
//string S, T, U;

ll countBits(ll n)
{
    ll cnt = 0;
    while (n)
    {
        cnt++;
        n >>= 1;
    }
    return cnt;
}
ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x=1, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL
    
    bitset<40> b1;
    cin>>n;
    x = countBits(n);
    f0(i,x)
    {
        b1[i]=1;
    }
    cout<<b1.to_ullong()<<endl;
    return 0;
}


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

using namespace std;

const pair<int, int> INF{12345, 54321};

pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {
	return {a.first - b.first, a.second - b.second};
}

long long operator*(const pair<int, int> &a, const pair<int, int> &b) {
	return a.first * b.second - a.second * b.first;
}

long long dot(const pair<int, int> &a, const pair<int, int> &b) {
	return a.first * b.first + a.second * b.second;
}

bool intersect(const pair<int, int> &a1, const pair<int, int> &a2, const pair<int, int> &b1, const pair<int, int> &b2) {
	auto diff = a2 - a1;
	auto cross1 = diff * (b1 - a1);
	auto cross2 = diff * (b2 - a1);
	return cross1 * cross2 < 0;
}

bool segintersect(const pair<int, int> &a1, const pair<int, int> &a2, const pair<int, int> &b1, const pair<int, int> &b2) {
	return intersect(a1, a2, b1, b2) && intersect(b1, b2, a1, a2);
}

long long mag2(const pair<int, int> &a) {
	return a.first * a.first + a.second * a.second;
}

bool colinear(const pair<int, int> &a, const pair<int, int> &b, const pair<int, int> &c) {
	return abs(dot(b - a, c - a)) * dot(b - a, c - a) == -mag2(b - a) * mag2(c - a);
}

int main() {
	int n, q;
	cin >> n;
	vector<pair<int, int>> polygon;
	for(int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		polygon.emplace_back(x, y);
	}
	cin >> q;

	for(int j = 0; j < q; j++) {
		int x, y;
		cin >> x >> y;
		pair<int, int> p{x, y};

		bool iscolinear = false;
		int nintersects = 0;
		for(int i = 0; i < n; i++) {
			if(colinear(p, polygon[i], polygon[(i+1)%n])) {
				iscolinear = true;
			}
			else if (segintersect(p, INF, polygon[i], polygon[(i+1)%n])) {
				nintersects++;
			}
		}

		if(iscolinear) {
			cout << "1\n";
		}
		else {
			cout << ((nintersects % 2) * 2) << '\n';
		}
	}

	return 0;
}



Measured memory_bytes: 3116
_n = gets.to_i
a = gets.split.map(&:to_i)
ans = 0
cum = [0]
a.each { |e| cum << cum[-1] + e }
mod = 10**9 + 7

a.each_with_index do |e, idx|
  ans += e * cum[idx] % mod
end

puts ans % mod

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
const ll MOD = 1000000007;

const int MAX = 2000005;
ll modFact[MAX];
ll modInv[MAX];
ll modFactInv[MAX];

// calc nCr % mod
ll comb(int n, int r) {
  return modFact[n] * (modFactInv[r] * modFactInv[n - r] % MOD) % MOD;
}

void init() {
  modFact[0] = modFact[1] = 1;
  modFactInv[0] = modFactInv[1] = 1;
  modInv[1] = 1;
  REP(i, 2, MAX) {
    modFact[i] = modFact[i - 1] * i % MOD;
    modInv[i] = MOD - modInv[MOD % i] * (MOD / i) % MOD;
    modFactInv[i] = modFactInv[i - 1] * modInv[i] % MOD;
  }
}

int main() {
  init();

  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  sort(all(a));

  ll ans = 0;
  rep(i, n) {
    int j = n - i - 1;
    if (j < k - 1) break;
    ans = (ans + a[n - 1 - i] * comb(j, k - 1) % MOD) % MOD;
    ans = (ans + MOD - a[i] * comb(j, k - 1) % MOD) % MOD;
  }
  while (ans < 0) ans += MOD;

  cout << ans << endl;
}


Measured memory_bytes: 47872
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX = 100010;
ll inv[MAX],fact[MAX],fi[MAX],mod = 1000000007;

void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}

ll x[100010],ans = 0,sum = 0;
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	inverse();
	for(i=1;i<n;i++){
		sum += inv[i];
		(ans += sum*(x[i] - x[i - 1])%mod) %= mod;
	}
	(ans *= fact[n - 1]) %= mod;
	cout << ans << endl;
}

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 3000 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);


void solve(int testCase){

    string s , t;
    cin >> s >> t;

    int n = s.length();
    int m = t.length();

    vector < vi > dp(n+1 , vi(m+1 , 0));
    vector < vii > p(n+1 , vii(m+1 , make_pair(0 , 0)));

    for(int i = 1 ; i <= n ; i ++){
            for(int j = 1 ; j <= m ; j ++){
                    if(s[i-1] == t[j-1]){
                            p[i][j] = {i - 1 , j - 1};
                            dp[i][j] = 1 + dp[i-1][j-1];
                    }
                    else {
                            if(dp[i-1][j] > dp[i][j-1]){
                                    p[i][j] = {i - 1 , j};
                                    dp[i][j] = dp[i-1][j];
                            }
                            else {
                                    p[i][j] = {i , j - 1};
                                    dp[i][j] = dp[i][j-1];
                            }
                    }
            }
    }

    int x = n , y = m;
    string ans = "";
    while( x > 0 && y > 0 ){
            int px = p[x][y].first;
            int py = p[x][y].second;

            if(dp[px][py] == dp[x][y] - 1){
                    ans += s[x-1];
            }

            x = px;
            y = py;
    }

    reverse(ans.begin() , ans.end());
    cout << ans << endl;
}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 106112
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

main = do
  [n,maxW] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  items <- U.replicateM n $ do
    [w,v] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (w, fromIntegral v :: Int64)
  print $ solve maxW items U.! maxW

solve :: Int -> U.Vector (Int, Int64) -> U.Vector Int64
solve maxW xs
  | U.null xs = U.replicate (maxW + 1) 0
  | otherwise = let (w,v) = U.head xs
                    a = solve maxW (U.tail xs)
                in U.generate (maxW + 1)
                   $ \i -> if w <= i
                           then max (a U.! i) (a U.! (i - w) + v)
                           else a U.! i


Measured memory_bytes: 81916
from operator import itemgetter
from heapq import heappush,heappop
N = int(input())
table=[]
for i in range(N):
    a,b = map(int,input().split())
    table.append([a,b,i])
A = sorted(table,key=itemgetter(0))
B = sorted(table,key=itemgetter(1))

graph=[]
for k in range(N):#距離、点
    graph.append((min(abs(A[k][0]-A[k-1][0]),abs( A[k][1]-A[k-1][1])),A[k][2],A[k-1][2]))
for k in range(N):
    graph.append((min(abs(B[k][0]-B[k-1][0]),abs( B[k][1]-B[k-1][1])),B[k][2],B[k-1][2]))

class Unionfindtree:
    def __init__(self,number):
        self.par = [i for i in range(number)]
        self.rank = [0]*(number)

    def find(self,x):#親を探す xの親を示す
        if self.par[x] ==x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self,x,y):#x,yを繋げる
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return 
        if self.rank[px]<self.rank[py]:
            self.par[px]=py
        else:
            self.par[py]=px
        if self.rank[px]==self.rank[py]:
            self.rank[px] +=1
    
    def connect(self,x,y):#親が同じかみる
        return self.find(x)==self.find(y)
#クラスカル法
kei = Unionfindtree(N)
graph.sort()
dist =0
for d,i,j in graph:
    if not kei.connect(i,j):
        kei.union(i,j)
        dist +=d
print(dist)


Measured memory_bytes: 54100
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int ,string> P;

int main(){
    string s1,s2;
    cin>>s1>>s2;
    int n1=s1.length();
    int n2=s2.length();
    int dp[n1+1][n2+1];
    fill(dp[0],dp[n1+1],1e5);
    for(int i=0;i<=n1;i++)dp[i][0]=i;
    for(int i=0;i<=n2;i++)dp[0][i]=i;
    for(int i=1;i<=n1;i++){
        for(int j=1;j<=n2;j++){
            dp[i][j]=min({dp[i-1][j]+1,dp[i][j-1]+1,s1[i-1]==s2[j-1]?dp[i-1][j-1]:dp[i-1][j-1]+1});
        }
    }
    cout<<dp[n1][n2]<<endl;
}

Measured memory_bytes: 7072
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

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

    string s,t; cin >> s >> t;
    sort(all(s));
    sort(all(t));
    reverse(all(t));
    if(s<t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int n,m,t;
int a[10005];

int main(void){
	scanf("%d%d%d",&n,&m,&t);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int ans=a[0]-m;
	for(int i=0;i<n-1;i++){
		if(a[i+1]-a[i]>=2*m){
			ans+=(a[i+1]-a[i])-2*m;
		}
	}
	if(t-a[n-1]>=m){
		ans+=t-a[n-1]-m;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3232
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        if (a.length() > b.length()) {
            System.out.println("GREATER");
        } else if (a.length() < b.length()) {
            System.out.println("LESS");
        } else {
            if (a.compareTo(b) < 0) {
                System.out.println("LESS");
            } else if (a.compareTo(b) > 0) {
                System.out.println("GREATER");
            } else {
                System.out.println("EQUAL");
            }
        }

    }

}

Measured memory_bytes: 22740
#include <stdio.h>

#define MAX 100

int bubbleSort(int *,int);

int main(void)
{
  int array[MAX],N,i,count;

  scanf ("%d",&N);
  for (i = 0 ; i < N ; i++)
    scanf ("%d",&array[i]);

  count = bubbleSort(array,N);

  for (i = 0 ; i < N ; i++){
    printf ("%d",array[i]);
    if (i < N-1)
      printf (" ");
    else printf ("\n");
  }

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

  return 0;
}

int bubbleSort(int *array,int N)
{
  int flag,j,c,count=0;

  flag = 1; //逆の隣接要素が存在する

  while (flag){
    flag = 0;
    for (j = N-1 ; j >= 1 ; j--){
      if (array[j] < array[j-1]){
	c = array[j];
	array[j] = array[j-1];
	array[j-1] = c;
	flag = 1;
	count++;
      }
    }
  }
  return count;
}

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

int main(){
    int n, k; cin >> n >> k;
    int a[n]; rep(i, n) cin >> a[i];

    bool dp[k+1] = {0};
    loop(i, 1, k+1)rep(j, n) if(i-a[j]>=0 && !dp[i-a[j]]) dp[i] = true;
    cout << (dp[k] ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

struct POST {
    int number;
    int depth;
    string name;
    Vec<POST> reply;
};

void init_data (POST &data, string m, int k) {
    data.number = 0;
    data.depth = 0;
    data.name = m;
    return;
}

void history (Vec<int> &parent, Vec<int> &pursue_list, int k) {
    int temp = k;
    while (1) {
        if (temp == 0) {
            break;
        }
        temp = parent[temp];
        pursue_list.push_back(temp);
    }
    return;
}

void pursue (POST &data, Vec<int> &pursue_list, int pursue_len, int now_depth, int k, string m, int i) {
    if (now_depth == pursue_len - 1) {
        // data.reply???POST??????push_back
        POST new_data;
        new_data.number = i;
        new_data.depth = data.depth + 1;
        string dot(new_data.depth, '.');
        new_data.name = dot + m;
        data.reply.push_back(new_data);
    } else {
        int loop = 0;
        while (1) {
            if (data.reply[loop].number == pursue_list[pursue_len - now_depth - 2]) {
                // recursion
                pursue(data.reply[loop], pursue_list, pursue_len, now_depth + 1, k, m, i);
                break;
            } else {
                loop++;
            }
        }
    }
    return;
}

void dump(POST& data) {
    cout << "NUMBER = " << data.number << endl;
    cout << "DEPTH = " << data.depth << endl;
    cout << "NAME = " << data.name << endl;
    cout << "REP = " << (int)data.reply.size() << endl;
    return;
}

void dfs (POST& data) {
    int rep_len = (int)data.reply.size();
    for (int i = 0; i < rep_len; i++) {
        cout << data.reply[i].name << endl;
        dfs(data.reply[i]);
    }
    return;
}

void output (POST& data) {
    dfs(data);
    return;
}

int main(void) {
    int n;
    cin >> n;
    POST data;
    Vec<int> parent;
    parent.push_back(-1);

    int k;
    string m;
    cin >> k >> m;
    k--;
    init_data(data, m, k);
    cout << m << endl;

    for (int i = 1; i < n; i++) {
        cin >> k >> m;
        k--;
        // make_data <- int k, string m, DATA
        parent.push_back(k);
        Vec<int> pursue_list;
        pursue_list.push_back(k);
        history(parent, pursue_list, k);
        int pursue_len = (int)pursue_list.size();
        pursue (data, pursue_list, pursue_len, 0, k, m, i);
    }

    output(data);

    return 0;
}

Measured memory_bytes: 4476
import sys

def main():

    inp = sys.stdin.readline
    n, m = [int(i) for i in inp().split()]
    
    d = {}
    for _ in range(m):
        s, c = [int(i) for i in inp().split()]
        
        if s in d.keys():
            if d[s] != c:
                print(-1)
                exit()
        else:
            d[s] = c

    tmp = ""
    for i in range(1, n + 1):
        if i in d.keys():
            if i == 1 and d[i] == 0 and n > 1:
                print(-1)
                exit()
            tmp += str(d[i])
        else:
            if i == 1 and n > 1:
                tmp += "1"
            else:
                tmp += "0"

    print(tmp)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>=22) cout << "bust";
    else cout << "win";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int A[3][3];
bool checked[3][3];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i, 0, 3) rep(j, 0, 3) {
        cin >> A[i][j];
        checked[i][j] = false;
    }
    int N;
    cin >> N;
    int B;
    rep(i, 0, N) {
        cin >> B;
        rep(j, 0, 3) rep(k, 0, 3) {
            if (A[j][k] == B) {
                checked[j][k] = true;
            }
        }
    }
    rep(i, 0, 3) {
        bool is_ok = true;
        rep(j, 0, 3) {
            if (!checked[i][j]) {
                is_ok = false;
            }
        }
        if (is_ok) {
            cout << "Yes" << endl;
            return 0;
        }
        is_ok = true;
        rep(j, 0, 3) {
            if (!checked[j][i]) {
                is_ok = false;
            }
        }
        if (is_ok) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    bool is_ok = true;
    rep(i, 0, 3) {
        if (!checked[i][i]) {
            is_ok = false;
        }
    }
    if (is_ok) {
        cout << "Yes" << endl;
        return 0;
    }
    is_ok = true;
    rep(i, 0, 3) {
        if (!checked[i][2 - i]) {
            is_ok = false;
        }
    }
    if (is_ok) {
        cout << "Yes" << endl;
        return 0;
    }
    else {
        cout << "No" << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int N,M,K,A,cnt=0;
  cin>>N>>M;
  int ans[M];
  for(int i=0;i<M;i++) ans[i]=0;
  
  for(int i=0;i<N;i++){
    cin>>K;
    for(int j=0;j<K;j++){
      cin>>A;
      ans[A-1]++;
    }
  }
  
  for(int i=0;i<M;i++){
    if(ans[i]==N) cnt++;
  }
  
  cout<<cnt<<endl;
  
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
signed main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++){
		double x1, x2, x3, x4, y1, y2, y3, y4;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		if (x1 == x2) {
			printf("%.10f %.10f\n", x1, y3 + (y4 - y3)/(x4 - x3)*(x1 - x3));
		}
		else if (x3 == x4) {
			printf("%.10f %.10f\n", x3, y1 + (y2 - y1)/(x2 - x1)*(x3 - x1));
		}
		else {
			double k1 = (y2 - y1) / (x2 - x1), k2 = (y4 - y3) / (x4 - x3);
			double p1 = y1 - (k1*x1), p2 = y3 - (k2*x3);
			double x = (p2 - p1) / (k1 - k2), y = k1 * x + p1;
			printf("%.10f %.10f\n", x, y);
		}
	}
}


Measured memory_bytes: 3272
s = gets.chomp.split("")
size = s.size
t = "abcdefghijklmnopqrstuvwxyz".split("")
for i in 0..size-1
  if t.include?(s[i])
    t.delete(s[i])
  end
end
if t.size == 0
  puts "None"
else
  puts t[0]
end

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

int main(){
	/*input*/
	vector<vector<int> >c(3, vector<int>(3));
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			cin >> c[i][j];
		}
	}
	/*calculaiton*/
	bool flag = false;	//true:Yes false:No
	for(int b1 = 0; b1 <= min(c[0][0], min(c[0][1], c[0][2])); b1++){
		int a1, a2, a3;
		a1 = c[0][0] - b1;
		a2 = c[0][1] - b1;
		a3 = c[0][2] - b1;
		if(c[1][0] - a1 == c[1][1] - a2 && c[1][1] - a2 == c[1][2] - a3 && c[2][0] - a1 == c[2][1] - a2 && c[2][1] - a2 == c[2][2] - a3)flag = true;
	}
	/*output*/
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256