akhauriyash/Code-Regression huggingface dataset:
from collections import Counter

s = input()

flag = 1
if not s[0] == "A":
    flag = 0

c = Counter(s[2:-1])
if not c["C"] == 1:
    flag = 0

small = set([chr(i) for i in range(ord("a"), ord("z") + 1)])

for i, w in enumerate(s):
    if (i == 1 or i == len(s)-1) and not(w in small):
        flag = 0

if flag:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3316
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


#mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

def main():
	c=input().rstrip().decode('utf-8')
	ans=chr(ord(c)+1)
	print(ans)


if __name__ == "__main__":
	main()


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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

void solve(long long K) {
    long long s = 7;
    rep (i, K) {
        if (s % K == 0) {
            cout << i + 1 << endl;
            return;
        }
        s = s * 10 + 7;
        s %= K;
    }
    cout << -1 << endl;
}

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


Measured memory_bytes: 3728
#include "bits/stdc++.h"
using namespace std;
int main(){
	string S;
	cin>>S;

	int posa=20000000,posz=-2000000;
	int len=0;
	for(int i=0;i<S.size();i++){
		if(S[i] == 'A') posa = min(posa, i);
		if(S[i] == 'Z') posz = max(posz, i);
	}
	len = posz - posa + 1;

	cout<< len <<endl;

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>

using namespace std;

#define BUF_SIZE 1024

class Stack{
public:
	Stack(int stack_size):
		m_index(0){
		m_array = new int[stack_size];
	};
	~Stack(){
		delete[] m_array;
	};
	void push(int var){
		m_array[m_index++] = var;
	};
	int pop(){
		return m_array[--m_index];
	};

	bool isEmpty(){
		return m_index == 0;
	};

private:
	int* m_array;
	int m_index;
};

int main(){
	char buf[BUF_SIZE];

	for(int i = 0; i < BUF_SIZE; i++){
		buf[i] = 'e';
	}
	fgets(buf,BUF_SIZE,stdin);

	Stack stack(BUF_SIZE);

	bool numFLG = false;
	int S = 0,op1=0,op2=0;

	for(int i = 0;buf[i] != 'e'; i++){
		if(buf[i] >= '0' && buf[i] <= '9'){
			numFLG = true;
			S = 10*S + (buf[i] - '0');
		}else{
			if(numFLG){
				stack.push(S);
				S = 0;
				numFLG = false;
			}

			if(buf[i] == '+'){
				op2 = stack.pop();
				op1 = stack.pop();
				stack.push(op1+op2);
			}else if(buf[i] == '-'){
				op2 = stack.pop();
				op1 = stack.pop();
				stack.push(op1-op2);
			}else if(buf[i] == '*'){
				op2 = stack.pop();
				op1 = stack.pop();
				stack.push(op1*op2);
			}
		}
	}

	op1 = stack.pop();
	printf("%d\n",op1);
}



Measured memory_bytes: 3216
#include <set>
#include <map>
#include <cmath> 
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
LL dd,Ans,p[20];
LL dfs(LL l,LL r,LL d){
	if(l>=r){
		if(d==0)return l==r?10:1;
		return 0;
	}
	if(d%10==0){
		if(l!=1)return 10*dfs(l+1,r-1,d/10);
		return 9*dfs(l+1,r-1,d/10); 
	}
	LL D=d%10-10;
	LL next=d-D+D*p[r-l];
	if(l==1)return (9+D)*dfs(l+1,r-1,abs(next)/10);
	return (10+D)*dfs(l+1,r-1,abs(next)/10); 
} 
int main() {
	scanf("%lld",&dd);
	p[0]=1;
	for(int i=1;i<=18;i++)p[i]=p[i-1]*10;
	for(int i=2;i<=18;i++)
		Ans+=dfs(1,i,dd);
	printf("%lld",Ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  long X; cin >> X;//101 <= X <= 10^18
  long nowDiposit = 100;
  int count = 0;
  do{
    nowDiposit *= 1.01;
    count += 1;
  }while(nowDiposit < X);
  cout << count << endl;
  return 0;
}

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

int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	int res = 0;
	for(int i = 0; i < n; ++i){
		if(a[i]==1&&i==0){
			swap(a[0],a[1]);
			++res;
			continue;
		}
		if(a[i]==n&&i==n-1){
			swap(a[n-1],a[n-2]);
			++res;
			continue;
		}
		if(a[i]==i+1){
			if(a[i+1]<=i+2){
				swap(a[i],a[i+1]);
				++res;
				continue;
			}
			swap(a[i-1],a[i]);
			++res;
			continue;
		}

	}
	cout << res;
	
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  long long n;
  cin >> n;
  if(n%2==1)cout << "0"<< endl;
  else{
    long long i=10;
    long long sum = 0;
    while(n/i>0){
      sum += n/i;
      i = i*5;
    }
    cout << sum << endl;
  }
}


Measured memory_bytes: 256
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto tmp = readln.split.to!(long[]);
    auto N = tmp[0], K = tmp[1];
    const as = readln.split.to!(long[]);
    const i = N.iota.find!(i => as[i] == 1).front;

    int cnt = 0;
    if (N > 0) {
        N -= K;
        cnt++;
    }
    while (N > 0) {
        N -= K-1;
        cnt++;
    }
    writeln(cnt);
}


Measured memory_bytes: 4036
class UnionFind
  attr_reader :parent, :rank
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end

  def same_parent?(id_x, id_y)
    get_parent(id_x) == get_parent(id_y)
  end
end
#n = gets.chomp.to_i
n,m = gets.chomp.split.map(&:to_i)

bridge = Array.new(m)
m.times do |i|
  bridge[i] = gets.chomp.split.map(&:to_i)
end

bridge.reverse!

def count(n)
  n*(n-1)/2
end

all_count = count(n)
ans = Array.new(m+1)
ans[0] = all_count

uf = UnionFind.new(n+1)
sizes = {}
sizes.default = 1
m.times do |i|
  a, b = bridge[i]
  ap = uf.get_parent(a)
  bp = uf.get_parent(b)
  if ap == bp
    ans[i+1] = ans[i]
    next
  end
  uf.unite(a,b)
  asize = sizes[ap]
  bsize = sizes[bp]
  new_size = asize + bsize
  sizes[uf.get_parent(a)] = new_size
  ans[i+1] = [ans[i] - count(new_size) + (count(asize) + count(bsize)), 0].max
end

ans.reverse!
ans.shift
ans.each do |e|
  puts e
end


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

void solve() {
  int n; cin >> n;
  vi32 a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  vi32 o(n);
  iota(all(o), 0);
  sort(all(o), [&](int i, int j) { return b[i] < b[j]; });
  i64 sum = 0;
  rep(i, n) {
    sum += a[o[i]];
    if (sum > b[o[i]]) no();
  }
  yes();
}


Measured memory_bytes: 2560
import sys
sys.setrecursionlimit(10**6+1) #再帰関数の上限,10**5以上の場合python


def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None


#N, Q = map(int, input().split())
N, Q = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
#L = tuple(int(input()) for i in range(N)) #改行ベクトル
#S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

edge = [[] for i in range(N)]
for i in range(N-1):#木の場合M=N-1
    a,b,c,w = map(int,input().split())
    edge[a-1].append((b-1,c-1,w))
    edge[b-1].append((a-1,c-1,w)) #有向のばあいコメントアウト



#ダブリングによるLCA, 前処理NlogN, 呼び出しlogN, 安定  
def dfs(start):
    q=[(start,-1,0,0)]
    pars=[-1]*N
    depth=[-1]*N
    dist=[-1]*N
    while len(q):
        e,p,d,dis=q.pop()#ここをpopleftにすると幅優先探索BFSになる
        if depth[e]!=-1:continue
        pars[e]=p
        depth[e]=d
        dist[e]=dis
        for ne,c,w in edge[e]:
            q.append((ne,e,d+1,dis+w))
    return pars,depth,dist
pars,d,dist=dfs(0)
ln=N.bit_length()
dp=[[-1]*N for _ in range(ln+1)]
dp[0]=pars
for i in range(1,ln+1):
    for j in range(N):
        dp[i][j]=dp[i-1][dp[i-1][j]]


# LCAの計算
def lca(u, v):
    du = d[u]; dv = d[v]
    if du > dv:
        du, dv = dv, du
        u,v=v,u
    dif=dv-du
    for i in range(ln+1):
        if (dif>>i)&1:
            v=dp[i][v]
    if u==v:return u
    for i in range(ln,-1,-1):
        pu=dp[i][u];pv=dp[i][v]
        if pu!=pv:
            u,v=pu,pv
    return pars[u]

q=Q
qs = tuple(tuple(map(int, input().split())) for i in range(Q)) #改行行列
ans=[0]*Q
qn=[[] for _ in range(N)]
for i,(x,y,u,v) in enumerate(qs):
    a=lca(u-1,v-1)
    ans[i]=dist[u-1]+dist[v-1]-2*dist[a]
    qn[u-1].append((i,x-1,y,1))
    qn[v-1].append((i,x-1,y,1))
    qn[a].append((i,x-1,y,-2))

cc=[[0,0] for _ in range(N-1)]

dfq=[(0,None,0,-1)]
def dfs2(e,c,d,p):
    if c!=None:
        cc[c][0]+=1
        cc[c][1]+=d
    for qi,x,y,sgn in qn[e]:
        ans[qi]+=(y*cc[x][0]-cc[x][1])*sgn
    for ne,nc,nd in edge[e]:
        if ne==pars[e]:continue
        dfs2(ne,nc,nd,e)
    if c!=None:
        cc[c][0]-=1
        cc[c][1]-=d
dfs2(0,-1,0,None)
printl(ans)

# n=N
# A = [0]*q
# C = [[] for _ in range(n)]
# num = [0]*n
# cum = [0]*n
# for i in range(q):
#   x, y, u, v = map(int, input().split())
#   u -= 1
#   v -= 1
#   a = lca(u, v)
#   C[u].append((i, x, y, 1))
#   C[v].append((i, x, y, 1))
#   C[a].append((i, x, y, -2))
# dist = 0
# stack = [0]
# def dfs2(v):
#   global dist
#   for i, x, y, b in C[v]:
#     A[i] += (dist + num[x]*y - cum[x]) * b
#   for nv, c, d in edge[v]:
#     c+=1
#     if nv ==pars[v]:continue
#     dist += d
#     num[c] += 1
#     cum[c] += d
#     dfs2(nv)
#     dist -= d
#     num[c] -= 1
#     cum[c] -= d
# dfs2(0)
# print(*A, sep="\n")

Measured memory_bytes: 215352
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

int main(){
    int l, r, d; cin >> l >> r >> d;
    int ans;
    cout << r / d - (l - 1) / d << endl; 
    
}

Measured memory_bytes: 3628
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int a, b, c, x, y;
	ll ans = 0;
	cin >> a >> b >> c >> x >> y;

	if (a + b > c * 2){
		if (x < y){
			ans += x * 2 * c;
			y -= x;
			x = 0;
		}
		else {
			ans += y * 2 * c;
			x -= y;
			y = 0;
		}
	}

	if (x){
		if (a > c*2){
			ans += x * 2 * c;
			x = 0;
		}
		else {
			ans += x * a;
			x = 0;
		}
	}
	
	if (y){
		if (b > c*2){
			ans += y * 2 * c;
			y = 0;
		}
		else {
			ans += y * b;
			y = 0;
		}
	}

	cout << ans << endl;




}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;cin>>n;
    int h[n];
    for(int i = 0;i<n;i++) cin>>h[i]; 
    int ans = 0;
    while(true){
      int k0 = 0;
      for(int i = 0;i<n;i++){
        if(h[i] == 0) k0++;
      }
      if(k0 == n){
        cout<<ans;
        return 0;
      }
      int zgai = 0;//0以外が出た回数
      int ss = 1000;//最小値
      int soko = n;
      for(int i = 0;i<n;i++){
      	if(h[i] != 0){
          zgai+= 1;
          ss = min(ss,h[i]);
        }
        if(zgai != 0){
          if(h[i] == 0){
            soko = i;
            break;
          }
        }
      }
      //cout<<ss<<endl;;
      for(int i = 0;i<soko;i++){
        if(h[i] == 0) continue;
      	h[i]-=ss;
      }
      ans+= ss;
    }
    return 0;
}

Measured memory_bytes: 3616
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    //int[] count = new int[N];
    String str = sc.next();

    if(N >= 3200){
        System.out.println(str);
    }else{
        System.out.println("red");
    }
    
    //if(str[0].equals("H"))
  }
}

Measured memory_bytes: 21204
N = int(input())
S = input()

countW = 0
for i in range(N):
    if S[i] == '.':
        countW += 1
countB = N - countW

count = 0
counter = [countW]
for i in range(N):
    if S[i] == '#':
        count += 1
    else:
        countW -= 1
    counter.append(count + countW)

print(min(counter))


Measured memory_bytes: 11264
void main()
{
    long n = readln.chomp.to!long;
    long[] a = readln.split.to!(long[]);

    long snuke = a[0], raccoon = a[1..$].sum;
    long diff = abs(snuke-raccoon);
    foreach (i; 1 .. n-1)
    {
        snuke += a[i], raccoon -= a[i];
        diff = min(diff, abs(snuke - raccoon));
    }

    diff.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 11008
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)

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

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  struct ex{
    ll a,b;
  };
  vector<ex>e(n);
  rep(i,n)cin>>e[i].a;
  rep(i,n)cin>>e[i].b;
  sort(all(e),[](ex x,ex y){return x.a-x.b>y.a-y.b;});
  ll sa=0,sb=0;
  ll cnt=0;
  rrep(i,n){
    if(e[i].a<e[i].b){
      sa+=e[i].a;
      sb+=e[i].b;
      cnt++;
    }
  }
  rep(i,n){
    if(sa>=sb)break;
    if(e[i].a>e[i].b){
      sa+=e[i].a;
      sb+=e[i].b;
      cnt++;
    }
  }
  if(sa>=sb){
    cout<<cnt<<endl;
  }
  else cout<<-1<<endl;


  return 0;

}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
   int i,j;
   char x[4][4];

   for(i=0; i<3; i++){
      scanf("%s",&x[i]);
   }


   printf("%c%c%c\n",x[0][0],x[1][1],x[2][2]);

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
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);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<ll> a(n);
  rep(i,n){
    cin>>a[i];
  }
  sort(all(a));
  int idx=0;
  rep(i,n-1){
    ll g=__gcd(a[i],a[i+1]);
    a[i]=g;
    a[i+1]=g;
  }
  cout<<a[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(){
	int i,j,n,m,win = 1,sports[1001],member[1001],score[1001] = {0};
	scanf("%d%d",&n,&m);
	for(i = 1;i <= n;i++){
		scanf("%d",&sports[i]);
	}
	for(i = 1;i <= m;i++){
		scanf("%d",&member[i]);
	}

	for(i = 1;i <= m;i++){
		for(j = 1;j <= n;j++){
			if(member[i] >= sports[j]){
				score[j] ++;
				break;
			}
		}
	}
	for(i = 1;i <= n;i++){
		if(score[win] < score[i]){
			win = i;
		}
	}
	printf("%d\n",win);
	return 0;
}

Measured memory_bytes: 608
#include <cstdio>
#include <algorithm>
using namespace std;

double dp[101][101][11][11][5];
int stb[16], s[101];
int L, A, B;

/*
prv
	0: 左トン
	1: 右トン
	2: 左コツ
	3: 右コツ
	4: none
*/
double dfs(int len, int scr, int cmb, int prc, int prv){
	cmb = min(cmb, 10);
	scr = min(scr, 100);

	double &ret = dp[len][scr][cmb][prc][prv];
	if(ret < 0.0){
		if(scr >= 100){
			ret = 1.0;
		}
		else if(len == L){
			ret = 0.0;
		}
		else if(s[len] == 0){
			ret = dfs(len + 1, scr, cmb, 10, 4);
		}
		else if(prv == 4){
			ret = dfs(len + 1, scr, 0, 10, 4);
			for(int k = -2; k <= -1; ++k){
				ret = max(ret, dfs(len + 1, scr + A + B * cmb, cmb + 1, 10, s[len] * 2 + k));
			}
		}
		else{
			ret = dfs(len + 1, scr, 0, 10, 4);
			for(int k = -2; k <= -1; ++k){
				int nxt = s[len] * 2 + k;
				int npc = max(0, stb[prv * 4 + nxt] - 10 + prc);
				double ps = dfs(len + 1, scr + A + B * cmb, cmb + 1, npc, nxt);
				double pf = dfs(len + 1, scr, 0, npc, nxt);
				ret = max(ret, 0.1 * (npc * ps + (10 - npc) * pf));
			}
		}
	}

	return ret;
}


int main(){
	while(1){
		for(int i = 0; i < 16; ++i){
			if(scanf("%d", &stb[i]) != 1){ return 0; }
		}
		scanf("%d", &L);
		for(int i = 0; i < L; ++i){
			scanf("%d", &s[i]);
		}
		scanf("%d%d", &A, &B);
		A /= 100;
		B /= 100;

		fill(****dp, ****dp + sizeof(dp) / sizeof(double), -1.0);

		printf("%f\n", dfs(0, 0, 0, 10, 4));
	}
}

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

const int nil = -1;

struct Node {int p, l, r;};
Node T[10000];
int n, d[10000], sib[10000], deg[10000], h[10000];

void print(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "sibling = " << sib[u] << ", ";
    cout << "degree = " << deg[u] << ", ";
    cout << "depth = " << d[u] << ", ";
    cout << "height = " << h[u] <<  ", ";


    if (T[u].p == nil) cout << "root";
    else if (T[u].l != nil || T[u].r != nil) cout << "internal node";
    else cout << "leaf";
    cout << endl;
}

void rec_depth(int u, int p) {
    d[u] = p;
    if (T[u].r != nil) rec_depth(T[u].r, p + 1);
    if (T[u].l != nil) rec_depth(T[u].l, p + 1);
}

void rec_height(int u, int k) {
    h[u] = max(h[u], k);
    if (T[u].p != nil) rec_height(T[u].p, k + 1);
}

int main(void) {
    int p, l, r;
    cin >> n;
    for (int i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = sib[i] = nil;

    for (int i = 0; i < n; i++) {
        cin >> p >> l >> r;
        T[p].l = l;
        T[p].r = r;
        T[l].p = T[r].p = p;
        sib[r] = l;
        sib[l] = r;
        deg[p] = min(1, l + 1) + min(1, r + 1);
    }

    for (int i = 0; i < n; i++) {
        if (T[i].p == nil) rec_depth(i, 0);
        if (T[i].l == nil && T[i].r == nil) rec_height(i, 0);
    }

    for (int i = 0; i < n; i++) print(i);

    return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
struct UnionFind{
    int n;
    set<int> dame;
    vi p;
    vi use;
    UnionFind(int N):n(N){
        p.resize(n);
        use.resize(n);
    	iota(all(p),0);
    	rep(i,n){
    	    int tmp;
    	    cin>>tmp;
    	    unite(i,tmp+i);
    	}
    }
    void unite(int a, int b){int c=root(a),d=root(b); if(c!=d) p[c]=d; else if(a!=b) dame.insert(root(a));}
    int root(int a){return p[a]=(p[a]==a?a:root(p[a]));}
    bool same(int a, int b){return root(a)==root(b);}
    void useable(){
        set<int> tmp;
        for(auto i :dame)tmp.insert(root(i));
        dame=tmp;
        rep(i,n){
            use[i]=dame.find(root(i))==dame.end();
        }
    }
};
int main(){
	int n;
	cin>>n;
	UnionFind uf(n);
	//rep(i,n)cout<<uf.p[i]<<",";cout<<endl;
	uf.useable();
    //for(auto i :uf.use)cout<<i<<",";cout<<endl;
    vi turn(n,-1);
    turn[0]=0;
    queue<int> que;
    que.push(0);
    while(turn[n-1]==-1){
        int c=que.front();que.pop();
        range(d,1,7){
            if(c+d<n && uf.use[c+d] && turn[uf.p[c+d]]==-1){
                que.push(uf.p[c+d]);
                turn[uf.p[c+d]]=turn[c]+1;
            }
        }
    }
    cout<<turn[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 4568
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

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

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;

//2051
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// long long?
	int N;
	cin >> N;

	ll ans = 0;
	rep(i, N) {
		ll tmp = 0;
		cin >> tmp;
		ans += (tmp - 1);
	}

	cout << ans << endl;

	return 0;
}

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

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

using namespace std;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}

int main() {
    int N;
    cin >> N;
    vector<vector<int>> x(N), y(N);
    REP(i, N) {
        int A;
        cin >> A;
        x[i].resize(A);
        y[i].resize(A);
        REP(j, A) {
            cin >> x[i][j] >> y[i][j];
            --x[i][j];
        }
    }

    int result = -1;
    REP(bit, 1 << N) {
        vector<int> is_honest(N);
        REP(i, N) {
            is_honest[i] = (bit >> i) & 1;
        }
        bool contradiction = false;
        REP(i, N) {
            REP(j, x[i].size()) {
                if (is_honest[i] && y[i][j] != is_honest[x[i][j]]) {
                    contradiction = true;
                    goto out_loop;
                }
            }
        }
        out_loop:
        if (!contradiction) {
            amax(result, __builtin_popcount(bit));
        }
    }
    assert(result >= 0);
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
class Solver():
  def __init__(self):
    self._N = int(input())
    self._data = list(map(int, input().split()))
    self._ans  = [0 for i in range(self._N)]
  
  def print_member(self):
    print("N = {}".format(self._N))
    for i in self._data:
      print(i, end=" ")
      
  
  def solve(self):
    flag = True
    for i in reversed(range(1,self._N+1)):
      i_mul   = i
      sum_mul = 0
      while(i_mul<self._N+1):
        sum_mul += self._ans[i_mul-1]
        i_mul   += i
      if(sum_mul%2 != self._data[i-1]):
        self._ans[i-1] += 1
        self._ans[i-1] %= 2
             
    if(flag):
      print(sum(self._ans))
      for i in range(self._N):
        if(self._ans[i]):
          print(i+1, end=" ")
          
if __name__ == '__main__':
  solver = Solver()
  solver.solve()

Measured memory_bytes: 7100
#include<iostream>
using namespace std;
int main(){
    int r, c;
    cin >> r >> c;
    int i, j;
    long long result[r+1][c+1];
    int tmp;
    for(i=0; i<r+1; i++){
        for(j=0; j<c+1; j++){
            result[i][j]=0;
        }
    }
    for(i=0; i<r; i++){
        for(j=0; j<c; ++j){
            cin >> result[i][j];
            tmp = result[i][j];
            result[i][c] += tmp;
            result[r][j] += tmp;
            result[r][c] += tmp;
        }
        
    }
    for(i = 0; i<=r; i++){
        for(j=0; j<=c; j++){
            if(j) {
                cout << " " <<result[i][j];
            } else {
                cout << result[i][j];
            }
        }
        cout << endl;
    } 
    return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
bool is1(char c){
    if(c=='0'){
        return 0;
    }else{
        return 1;
    }
}
int main(){
    char tmp;
    while(cin >> tmp){
        vector<vector<bool>> is(12, vector<bool>(12));
        for(int i=0; i<12; i++){
            for(int j=0; j<12; j++){
                if(!(i==0 && j==0)) cin >> tmp;
                is[i][j]=is1(tmp);
            }
        }

        int cnt=0;
        for(int i=0; i<12; i++){
            for(int j=0; j<12; j++){
                if(is[i][j]){
                    cnt++;
                    stack<pair<int, int>> s;
                    s.push({i,j});
                    while(!s.empty()){
                        int x=s.top().first;
                        int y=s.top().second;
                        s.pop();

                        is[x][y]=0;

                        if(x>0 && is[x-1][y]) s.push({x-1,y});
                        if(x<11 && is[x+1][y]) s.push({x+1,y});
                        if(y>0 && is[x][y-1]) s.push({x,y-1});
                        if(y<11 && is[x][y+1]) s.push({x,y+1});
                    }
                }
            }
        }
        cout << cnt << endl;

    }
}


Measured memory_bytes: 3100
package main

import (
	"fmt"
)

func main() {
	var n, d, x int
	fmt.Scan(&n, &d, &x)
	sum := 0
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		for i, j := 1, 1; i <= d; i, j = j * tmp + 1, j + 1 {
			sum++
		}
	}
	fmt.Println(sum + x)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define li long int
#define ll long long
using namespace std;

ll a,b;

void INP(){
    cin>>a>>b;
}

void solve(){
    if(a>b) swap(a,b);
    for(int i=1;i<=b;i++)
        cout<<a;
}

int main(){
    INP();
    solve();
    return 0;
}


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

void run(void){
  int n,q;
  scanf("%d%d",&n,&q);
  int *p=(int *)calloc(n+2,sizeof(int));
  p[1]=p[2]=1;
  int now=1;
  while(q--){
    int a,b;
    scanf("%d%d",&a,&b);
    int s=p[a];
    p[a]=p[b];
    p[b]=s;
    if(now==a || now==b){
      now^=a^b;
    }
    p[now-1]=p[now+1]=1;
  }
  int ans=0;
  for(int i=1;i<=n;i++) ans+=p[i];
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        int b10th = -1, b5th = -1, b1th = -1;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), y = sc.nextInt();

        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                if (i + j > n) {
                    break;
                }
                int k = n - i - j;
                if (10000*i + 5000*j + 1000*k == y) {
                    b10th = i; b5th = j; b1th = k;
                }
            }
        }

        System.out.println(b10th + " " + b5th + " " + b1th);
    }
}


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

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


Measured memory_bytes: 3632
s = raw_input()
first = int(s[0:2])
second = int(s[2:])
if 1 <= first <= 12 and 1 <= second <= 12:
	print "AMBIGUOUS"
elif 1 <= first <= 12:
	print "MMYY"
elif 1 <= second <= 12:
	print "YYMM"
else:
	print "NA"


Measured memory_bytes: 2568
#include <cstdio>
#include <iostream>
using namespace std;
int field[21][21];
int main() {
    int n;
    while (scanf("%d",&n)) {
        if (!n) break;
        for (int i=0; i<21; i++) for (int j=0; j<21; j++) field[i][j]=0;
        for (int i=0; i<n; i++) {
            int x, y; scanf("%d%d",&x,&y);
            field[y][x]=1;
        }
        int m; scanf("%d",&m);
        int rx=10, ry=10;
        int cnt=0;
        for (int i=0; i<m; i++) {
            char d; cin>>d;
            int dist; scanf("%d",&dist);
            if (d=='N') {
                for (int j=0; j<dist; j++) {
                    ry++;
                    if (field[ry][rx]) {
                        field[ry][rx]=0;
                        cnt++;
                    }
                }
            }
            if (d=='E') {
                for (int j=0; j<dist; j++) {
                    rx++;
                    if (field[ry][rx]) {
                        field[ry][rx]=0;
                        cnt++;
                    }
                }
            }
            if (d=='S') {
                for (int j=0; j<dist; j++) {
                    ry--;
                    if (field[ry][rx]) {
                        field[ry][rx]=0;
                        cnt++;
                    }
                }
            }
            if (d=='W') {
                for (int j=0; j<dist; j++) {
                    rx--;
                    if (field[ry][rx]) {
                        field[ry][rx]=0;
                        cnt++;
                    }
                }
            }
        }
        if (cnt!=n) puts("No");
        else puts("Yes");
    }
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	Main m = new Main();
	m.answer();
    }

    private Scanner scan = new Scanner(System.in);
    private static final int MAX = 100000;
    private final int[] count;

    public Main() {
	count = new int[MAX+1];
	
	int N = Integer.parseInt(scan.next());
	for (int i = 0; i < N; i++) {
	    int a = Integer.parseInt(scan.next());
	    count[a]++;
	}

	scan.close();
    }

    public final void answer() {
	int[] result = new int[MAX+1];
	for (int i = 0; i <= MAX; i++) {
	    result[i] =  count[i];
	    if(i > 0) result[i] += count[i-1];
	    if(i < MAX) result[i] += count[i+1];
	}

	Arrays.sort(result);
	System.out.println(result[MAX]);
    }
}


Measured memory_bytes: 48592
#include <stdio.h>
#include <math.h>
// using namespace std;
int N;
int i = 2;
long long num;
char buf[8], out[20];
char k;
s;
size_t ii;
int main()
{
  s = read(0, buf, 8);
  for (;;)

  {
    k = buf[ii++];
    if (k < '0')
      break;
    N = N * 10 + k - '0';
  }
  // printf("%d\n", N);
  long long ans = (long long)N * (N + 1) - 1;

  for (; i * i <= N; i++)
  {
    num = N / i;
    // ans += (long long)(num - i + 1) * i * (i + num) - i * i;
    ans += (num * num - i * i + num) * i;
  }
  printf("%lld\n", ans);
}


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

int main() {
    int x, y;
    cin >> x >> y;

    int ans = 0;
    if (x==3) ans += 100000;
    if (x==2) ans += 200000;
    if (x==1) ans += 300000;

    if (y==3) ans += 100000;
    if (y==2) ans += 200000;
    if (y==1) ans += 300000;

    if (x==1 && y==1) ans += 400000;

    cout << ans << endl;
}

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

using namespace std;

class DisjointSet{
public:
    vector<int> p;
    DisjointSet(int n){
        p.resize(n);
        for(int i=0;i<n;i++){
            p[i] = i;
        }
    }

    void unite(int x,int y){
        x = findSet(x);
        y = findSet(y);
        
        p[x] = y;
    }
    
    bool same(int x,int y){
        return findSet(x) == findSet(y);
    }
    int findSet(int x){
        if(x!=p[x]){
            //p[x]??????????????????????????§??????????????????
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};
int main(int argc, const char * argv[]) {
    int n,q;
    cin >> n >> q;
    
    DisjointSet ds(n);
    for(int i=0;i<q;i++){
        int com,x,y;
        cin >> com >> x >> y;
        if(com == 0){
            ds.unite(x, y);
        }else{
            if(ds.same(x, y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3220
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        double[] a=new double[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        
        Arrays.sort(a);
        
        double m=a[n-1];
        int r=0;
        for(int i=0;i<n;i++){
            if(a[i]>=m/2){
                if(i==0){
                    r=i;
                    break;
                }else{
                    if(a[i]-m/2<m/2-a[i-1]){
                        r=i;
                    }else{
                        r=i-1;
                    }
                    break;
                }
            }
        }
        int N=(int) m;
        int R=(int) a[r];
        System.out.println(N+" "+R);
    }
}

Measured memory_bytes: 57208
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,m;
	cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];
	int dp[n+1];
	dp[1]=0;
	dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
	{
		int c=k;
		m=dp[i-1]+abs(a[i-1]-a[i]);
		for(int j=i;j>1;j--)
		{
			dp[i]=min(dp[j-1]+abs(a[j-1]-a[i]),m);
			m=min(dp[j-1]+abs(a[j-1]-a[i]),m);
			c--;
			//cout<<"c "<<c<<endl;
			if(c<=0) break;
		}
		//cout<<i<<"->"<<dp[i]<<endl;
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
N=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=[a,b,c,d,e]

f=min(k)

if N%f==0:
  time=N//f+4
else:
  time=N//f+5
  
print(time)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;]
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

double p,q,a,n,syou;
int ans;

int check(double a,double b)
{
	return (a - b < 1e-9 && b - a < 1e-9)?0:1;
}


void dfs(double sum,int seki,int now,int mae)
{
	for(int i = mae;i < a;i++)
	{
		if(seki * i > a)break;
		double aa = (double)1/i;
		int tmp = check(syou,sum+aa);
		if(tmp == 0)
		{
			ans++;
		}
		else if(sum+aa < syou && now < n)
		{
			dfs(sum+aa,seki*i,now+1,i);
		}
	}
}

int main()
{
	
	while(cin>>p>>q>>a>>n,p != 0)
	{
		syou = p/q;
		ans = 0;
		dfs(0,1,1,1);
		cout << ans << endl;
	}	
	
	return 0;
}

Measured memory_bytes: 3136
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#define ll long long

using namespace std;
int a[10];
int main()
{
    int n;
    scanf("%d",&n);
    int con=0;
    while(n){
    a[con++]=n%10;
    n/=10;
    }
    int f=0;
    for(int i=0,j=con-1;i<=j;i++,j--){
        if(a[i]!=a[j]){
            f=1;
            break;
        }
    }
    if(f) printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <limits.h>
#include <memory.h>


using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef vector<double> vec;
typedef vector<vec> mat;



int main() {
	string a,b,c;
	cin>>a>>b>>c;

	int i=0,j=0,k=0;
	char turn='a';
	while(i<=a.size() && j<=b.size() && k<=c.size()){
		if(turn=='a'){
			if(i==a.size()){
				i++;break;
			}
			turn=a[i++];
		}
		else if(turn=='b'){
			if(j==b.size()){
				j++;break;
			}
			turn=b[j++];
		}
		else if(turn=='c'){
			if(k==c.size()){
				k++;break;
			}
			turn=c[k++];
		}

	}
	if(i>a.size())
		cout<< 'A'<<endl;
	if(j>b.size())
		cout<< 'B'<<endl;
	if(k>c.size())
		cout<< 'C'<<endl;

	return 0;
}




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

typedef long long ll;
typedef unsigned long long ull;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

typedef long double D;
typedef complex<D> P;

#define X real()
#define Y imag()

const D eps=1e-8;
const D inf=1e12;

D cross(P a,P b){ return (conj(a)*b).Y; }
D dot(P a,P b){ return (conj(a)*b).X; }

struct L : public vector<P>{
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

bool intersectLL(L l,L m){
  return abs(cross(l[1]-l[0],m[1]-m[0]))>eps||abs(cross(l[1]-l[0],m[0]-l[0]))<eps;
}

P crosspoint(L l,L m) {
  D A=cross(l[1]-l[0],m[1]-m[0]);
  D B=cross(l[1]-l[0],l[1]-m[0]);
  if (abs(A)<eps&&abs(B)<eps) return m[0]; // same line
  if (abs(A)<eps) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0]+B/A*(m[1]-m[0]);
}

int n;
P ps[111];

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  rep(i,n){
    D x,y;
    cin>>x>>y;
    ps[i]=P(x,y);
  }
  if(n%2==1){
    cout<<"NA"<<endl;
    return 0;
  }
  rep(i,n/2){
    if(abs(norm(ps[i]-ps[i+1])-norm(ps[(i+n/2)%n]-ps[(i+n/2+1)%n]))>eps){
      cout<<"NA"<<endl;
      return 0;
    }
    if(intersectLL(L(ps[i],ps[i+1]),L(ps[(i+n/2)%n],ps[(i+n/2+1)%n]))){
      cout<<"NA"<<endl;
      return 0;
    }
  }
  P res=crosspoint(L(ps[0],ps[n/2]),L(ps[1],ps[n/2+1]));
  printf("%.10Lf %.10Lf\n", res.X,res.Y);
	return 0;
}

Measured memory_bytes: 3340
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    int n,m;
    cin >> n >> m;
    if(n == 1 && m == 1) cout << 1 << '\n';
    else if(n == 1 || m == 1) cout << max(n,m) - 2 << '\n';
    else cout << (n - 2) * (m - 2) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const double eps = 1e-10;
  
int main() {
  int N;
  cin >> N;
  int s = 0;
  rep(i,N) {
    int l,r;
    cin >> l >> r;
    s += r-l+1;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
/*
memo for solution
*/
#include <cstdlib> 
#include <numeric>
#include <cstring>
#include <cstdio> 
#include <cfloat> 
#include <map> 
#include <cassert>
#include <cmath> 
#include <climits> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <iomanip>
#include<sys/time.h>
using namespace std; 
double e_time(void){static struct timeval now;gettimeofday(&now, NULL);return (double)(now.tv_sec  + now.tv_usec/1000000.0);}
#define REP(i,b,n) for(int i=b;i<n;i++) 
#define rep(i,n)      REP(i,0,n) 
#define pb push_back  
#define mp make_pair 
#define ALL(C)   (C).begin(),(C).end() 
#define fe(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr != (c).end();itr++)
#define BITSHIFT(X)     ( (1<<(X)) )
#define CONTAIN(S,X) ( ((S)&BITSHIFT(X)) != 0)
typedef complex<double>P; 
typedef long long ll; 
typedef unsigned long long ull; 
typedef pair<int,int> pii; 
typedef vector<int> vint;
template<class T> void vp(T &a,int p){rep(i,p)cout << a[i]<<" ";cout << endl;}  
template<class T> T ceilUp(const T& a,const T& b){return (a+b-1)/b;}
const ll mod =   1000000009;
inline ll modadd(ll a,ll b){a %= mod;b %= mod;return (a+b)%mod;}
inline ll modsub(ll a,ll b){a %= mod;b %= mod;a-=b;a%=mod;if (a<0)a+=mod;return a;}
inline ll modmul(ll a,ll b){a %= mod;b %= mod;return (a*b)%mod;}
inline ll modeq(ll a,ll b,ll m){a = (a%m+m)%m; b = (b%m+m)%m;return a == b;}
//ll modpow(ll n,ll p){if (p == 0)return 1;if (p == 1)return n;ll ret=mypow(n,p/2);ret=ret*ret%mod;if (p&1)ret=ret*n%mod;return ret;}
//ll getinv(ll a){return mypow(a,mod-2);}
ll mypow(ll n,ll p){
  if (p == 0)return 1;
  if (p == 1)return n;
  ll ret=mypow(n,p/2);
  ret=ret*ret;
  if (p&1)ret=ret*n;
  return ret;
}


int main(){
  int n, m;
  cin >> n >> m;
  int mini = 1, maxi = n;
  rep(i,m){
    int l, r;
    cin >>l >>r;
    mini = max(mini, l);
    maxi = min(maxi, r);
  }
  cout << max(0, maxi-mini + 1) << endl;

  return 0;
}


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;
    int Y;
    cin >> N;
    cin >> Y;
    vector<int> ans(3);
    bool flag = false;
    for(int i=0; i<=N; ++i) {
        for(int j=0; j<=N-i; ++j) {
            int k = N - i - j;
            if(10000*i + 5000*j + 1000*k == Y) {
                ans[0] = i;
                ans[1] = j;
                ans[2] = k;
                flag = true;
                break;
            } 
        }
        if(flag) break;
    }
    if(ans[0] == 0 && ans[1] == 0 && ans[2] == 0) rep(i,3) ans[i] = -1;
    rep(i,3) {
        if(i==2) {
            cout << ans[i] << endl;
        } else {
            cout << ans[i] << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <bitset>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = false;

ll ans = 20000;
ll H, W, N;
int addMap[10][1001];

int cutTest( vector<bool> &isCut ){


    int ans = 0;

    if(isCut[H - 1] == 0) return -1;
    if(DEBUG){
        for(int i = 0; i < isCut.size(); i++) cout << isCut[i];
        cout << endl;
    }

    int tail = 0;
    vector< vector<ll> > nowMap;
    for(int i = 0; i < isCut.size(); i++){
        if( isCut[i] ){
            ans ++;
            vector< ll > tmpMap(W + 1);
            int head = i;
            for(int w = 0; w <= W; w++){
                for(int num = tail; num <= head; num++){
                    tmpMap[w] += addMap[num][w];
                }
            }
            nowMap.push_back( tmpMap );
            tail = head + 1;

            if(DEBUG){
                for(int w = 0; w <= W; w++ ){
                    cout << tmpMap[w];
                }
                cout << endl;
            }

        }
    }




    tail = 0;
    for(int w = 1; w <= W; w++){

        // 仮にここで切ったとする
        int head = w;
        bool flag = true;
        for(int i = 0; i < nowMap.size(); i++){
            int choco = nowMap[i][head] - nowMap[i][tail];
            if(choco <= N) continue;
            else flag = false;
        }

        // ダメだった
        if(!flag){
            if( head == tail + 1){
                return -1;
            }
            else{
                ans ++;
                tail = head - 1;
            }
        }

    }

    if(DEBUG){
        cout <<"-----------------\n"; 
    }
    return ans - 1;
}

void dfs( vector<bool> &isCut, int depth ){

    if(depth == H){
        ll ret = cutTest( isCut );
        if( ret == -1 ) return ;
        if( ret < ans ) ans = ret;
        return;
    }

    isCut[depth] = 0;
    dfs( isCut, depth + 1 );

    isCut[depth] = 1;
    dfs( isCut, depth + 1 );

}


int main(){

    cin >> H >> W >> N;

    vector<string> data(H);
    for(int i = 0; i < H; i++) cin >> data[i];
    
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            addMap[i][j] = 0;
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 1; j <= W; j++){
            addMap[i][j] = addMap[i][j - 1];
            if( data[i][j - 1] == '1' ) addMap[i][j] ++;
        }

        if(DEBUG){
            for(int j = 1; j <= W; j++){
                cout << addMap[i][j];
            }
            cout << endl;

        }


    }

    vector<bool> isCut(H);
    dfs(isCut, 0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
x1,y1,x2,y2=map(int,input().split())
v = (x2-x1, y2-y1)
v23 = (-v[1], v[0])
v34 = (-v23[1], v23[0])
print(x2+v23[0], y2+v23[1], x2+v23[0]+v34[0], y2+v23[1]+v34[1])

Measured memory_bytes: 3064