akhauriyash/Code-Regression huggingface dataset:
#!python3

iim = lambda: map(int, input().rstrip().split())
from collections import defaultdict

def resolve():
    N, K, C = iim()
    S = input()

    if C == 0:
        ans = [i+1 for i in range(N) if S[i] == "o"]
        if len(ans) == K:
            print(*ans, sep="\n")
        return

    C1 = C+1
    i, cnt, ax = N-1, 0, [0] * K
    while i >= 0:
        if S[i] != "o":
            i -= 1
        else:
            cnt += 1
            ax[K-cnt] = i
            i -= C1
            if cnt == K:
                break

    ans, cnt, i  = [], 0, 0
    while i < N:
        if S[i] != "o":
            i += 1
        else:
            if i == ax[cnt]:
                ans.append(i+1)
            i += C1
            cnt += 1
            if cnt == K:
                break
    print(*ans, sep="\n")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 16232
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

#define MOD 1000000007

//累乗 O(log N)
long long power(long long x, long long N){
	if(N == 1) return x;
	long long tmp = power(x, N/2);
	if(N%2 == 0) return tmp * tmp % MOD;
	else return tmp * tmp % MOD * x % MOD;
}

//逆元 O(log x)
long long inverse(long long x){
	return power(x, MOD-2);
}

//コンビネーション
struct Combination{
private:
	int N;
	vector<long long> factorial, inv;
public:
	void init(int n){ //初期化する O(N)
		N = n;
		factorial.push_back(1);
		inv.push_back(1);
		for(long long i=1; i<=N; i++){
			factorial.push_back(factorial.back()*i%MOD);
			inv.push_back(inverse(factorial.back()));
		}
	}
	long long fact(int n){
		return factorial[n];
	}
	long long comb(int n, int k){ //nCkを求める O(1)
		return factorial[n] * inv[k] % MOD * inv[n-k] % MOD;
	}
};

LL N, K;
Combination C;
int main(){
	cin >> N >> K;
	C.init(N+K);
	for(int i=0; i<K; i++){
		//青がi+1個のブロックに
		//ひとまず1個ずつ割り振る
		int nokori = K-(i+1);
		//重複組み合わせでnokoriをi+1に割り振り
		//同じものを含む組み合わせ((i+1)-1の棒とnokoriのボールで)
		LL tmp = C.fact(nokori+(i+1)-1) * inverse(C.fact(nokori)) % MOD * inverse(C.fact((i+1)-1)) % MOD;
		//赤を内側のi個のブロックに割り振る
		nokori = (N-K)-i;
		if(nokori < 0){
			cout << 0 << endl;
			continue;
		}
		//重複組み合わせでnokoriを(i+1)+1に割り振り
		//同じものを含む組み合わせ(i+1の棒とnokoriのボールで)
		tmp *= C.fact(nokori+(i+1));
		tmp %= MOD;
		tmp *= inverse(C.fact(nokori));
		tmp %= MOD;
		tmp *= inverse(C.fact(i+1));
		tmp %= MOD;
		cout << tmp << endl;
	}
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#define ll long long 
using namespace std;
const int maxn=5010,inf=1e9;
int n, m;
int a[maxn], b[maxn][210], st[maxn];
ll sum[maxn], Sum[maxn], mp[maxn][maxn];
void read(int &k)
{
    int f=1;k=0;char c=getchar();
    while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
    k*=f;
}
int main()
{
    read(n); read(m);
    for(int i=2;i<=n;i++) read(a[i]), sum[i]=sum[i-1]+a[i];
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) read(b[i][j]);
    for(int i=1;i<=m;i++)
    {
    	int top=0; b[n+1][i]=inf;
    	for(int j=1;j<=n+1;j++)
    	{
    		for(;top && b[j][i]>=b[st[top]][i];top--)
    		{
    			int l=st[top-1]+1, r=j-1, pos=st[top];
//    			printf("qwq%d %d %d %d %d\n", i, l, pos, pos, r);
    			mp[l][pos]+=b[pos][i]; mp[l][r+1]-=b[pos][i];
    			mp[pos+1][pos]-=b[pos][i]; mp[pos+1][r+1]+=b[pos][i];
			}
			st[++top]=j;
		}
	}
	ll ans=0;
    for(int i=1;i<=n;i++)
    {
    	ll now=0;
    	for(int j=i;j<=n;j++)
    	{
    		Sum[j]+=mp[i][j];
    		now+=Sum[j];
//    		printf("%d %d %lld %lld\n", i, j, now, sum[j]-sum[i-1]);
    		if(i>j) continue;
    		ans=max(ans, now-sum[j]+sum[i]);
		}
	}
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 199040
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int ans = m;
  int mini = m;
  FOR(i,0,n){
    int in, out;
    cin>>in>>out;
    m += in - out;
    ans = max(ans, m);
    mini = min(mini, m);
  }
  if(mini < 0) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define int long long
using namespace std;
int print[100005];
struct node{
	int x, y;
}a[100005];
struct node2{
	int h, p;
}f[100005];
int find(int x){
	if (f[x].h==x) return x;
	return f[x].h=find(f[x].h);
}
signed main()
{
	int n, m;
	int ans=0;
	cin >> n >> m;
	for (int i=1;i<=m;i++)
		cin >> a[i].x >> a[i].y;
	for (int i=1;i<=n;i++) f[i].h=i, f[i].p=1;
	int tt=n*(n-1)/2;
	print[m]=0;
	for (int i=m;i>0;i--){
		int xx=find(a[i].x), yy=find(a[i].y);
		if (xx!=yy){
			f[xx].h=yy;
			ans+=f[xx].p*f[yy].p;
			f[yy].p+=f[xx].p;
			print[i-1]=ans;
		}		
		else print[i-1]=print[i];
	}
	for (int i=1;i<=m;i++)
		cout << tt-print[i] << endl;
	return 0;
}
/*
100000 4
1 3
2 30
4 100000
1 2
*/

Measured memory_bytes: 5248
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int N = sc.nextInt();
    int[] p = new int[N];
    int cnt = 0;
    for (int i = 0; i < N; i++) {
      p[i] = sc.nextInt();
    }
    for(int i = 1;i <= N;i++){
      if(p[i-1]==i){
        cnt++;
        i++;
      }
    }
    System.out.println(cnt);
  }
}
        


Measured memory_bytes: 50072
#include<iostream> 
using namespace std; 
struct card { char suit; int num; }; 
void bubble_sort(struct card A[],int n) { for(int i=0;i<n;i++) { for(int j=n-1;j>i;j--) { if(A[j].num<A[j-1].num) { card t=A[j]; A[j]=A[j-1]; A[j-1]=t; } } } } 
void selection_sort(struct card A[],int n) { for(int i=0;i<n;i++) { int mini=i; for(int j=i;j<n;j++) { if(A[j].num<A[mini].num) { mini=j; } } card t=A[i]; A[i]=A[mini]; A[mini]=t; } } 
void print(struct card A[],int n) { for(int i=0;i<n;i++) { cout << A[i].suit<<A[i].num; if(i!=n-1) {cout <<' '; } } cout<<endl; } 
bool is_stable(struct card A[],struct card B[],int n) { for(int i=0;i<n;i++) { if(A[i].suit!=B[i].suit) { return false; } } return true; } 
int main() { int n; cin>>n; struct card cards1[36],cards2[36]; for(int i=0;i<n;i++) { cin>>cards1[i].suit>>cards1[i].num; cards2[i]=cards1[i]; } bubble_sort(cards1,n); selection_sort(cards2,n); print(cards1,n); printf("Stable\n"); print(cards2,n); if(is_stable(cards1,cards2,n)==true) printf("Stable\n"); else printf("Not stable\n"); return 0; }


Measured memory_bytes: 3092
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        N: usize,
        A: usize,
        B: usize,
        C: usize,
        D: usize,
        E: usize,
    }
    let &m = [A, B, C, D, E].into_iter().min().unwrap();
    println!("{}", 4 + (N as f64 / m as f64).ceil() as usize);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <string>
//
const long long maxsize = 1e5 + 7, maxint = 0X3f3f3f3f, con = 21;
double error = 1e-7;
#define _USE_MATH_DEFINES
using namespace std;
//
int n;

/*
long long mini(long long index,long long a,long long b,long long c){
//base
if(index==3)
    return abs(a-b)+abs(a-c)+abs(b-c);
//transit
if(index==0)
    return min(mini(index+1,arr[0],b,c),min(mini(index+1,arr[0]+1,b,c),mini(index+1,arr[0]-1,b,c)));
else if(index==1)
    return min(mini(index+1,a,arr[1],c),min(mini(index+1,a,arr[1]+1,c),mini(index+1,a,arr[1]-1,c)));
else
    return min(mini(index+1,a,b,arr[2]),min(mini(index+1,a,b,arr[2]+1),mini(index+1,a,b,arr[2]-1)));
}
bool check(long long x){
    for(long long i=0;i<v.size()-1;i++){
        if(abs(v[i])>=(x)&&abs(v[i+1])>=(x))
            return 1;
    }
    return 0;
}
long long bin(){
    long long st=0,en=1e9,mid;
    while(st!=en){
        mid=(st+en+1)/2;
        if(check(mid))
            st=mid;
        else
            en=mid-1;
    }
    return st;
}

void sieve(){
primes.push_back(1);
primes.push_back(2);
for(long long i=3;i<=1e6;i+=2){
    if(!l[i]){
        primes.push_back(i);
        if(i<=sqrt(1e6)){
            for(long long u=i*2;u<=1e6;u+=i)
                l[u]=1;
        }
    }
}
}

bool isprime(long long x){
    for(long long i=2;i*i<=x;i++){
        if(x%i==0)
            return 0;
    }
    return 1;
}
long long fastpow(long long m,long long p){
    if(p==0)
        return 1;
    long long left=fastpow(m,(p/2))%con;
    if(p%2==0)
        return (left*left)%con;
    else
        return (((left*left)%con)*(m%con))%con;
}


long long fastpow(long long m,long long p){
    if(p==0)
        return 1;
    long long left=fastpow(m,(p/2))%con;
    if(p%2==0)
        return (left*left)%con;
    else
        return (((left*left)%con)*(m%con))%con;
}
*/



int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("in", "rd", stdin);
    //freopen("out","wd",stdout);
    cin>>n;
    int c=0;
    while(n){
        n/=2;
        c++;
    }
    c--;
    cout<<pow(2,c);
    return 0;
}

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


// ll mi = 100100100100100100;
ll N,A,B,C,D;

map<ll,ll> memo;
ll ans(ll n){
    ll coin;
    if(memo[n] != 0){
        return memo[n];
    }
    if(n == 1){
        coin = D;
    }else if(n == 2){
        coin = min(2*D, A+D);
    }else if(n == 3){
        coin = min(min(3*D, D+B),A + 2*D);
    }else if(n == 4){
        coin = min(min(min(4*D, 2*D+B),2*A + D),2*D + C);
    }else{
        int a = n % 5;
        coin = min(ans((n-a)/5) + C + a*D,ans((n + (5-a))/5) + C + (5-a)*D);
        a = n % 3;
        coin = min(min(ans((n-a)/3) + B + a*D,ans((n + (3-a))/3) + B + (3-a)*D),coin);
        a = n % 2;
        coin = min(min(ans((n-a)/2) + A + a*D,ans((n + (2-a))/2) + A + (2-a)*D),coin);
        if(n < coin / D){
            coin = n*D;
        }
    }
    return memo[n] = coin;
}

int main() {
    int T;
    cin >> T;

    rep(i,T){
        // mi = 100100100100100100;
        cin >> N >> A >> B >> C >> D;
        ll cost = ans(N);
        cout << cost << endl;
        memo.clear();
    }
    return 0;
}

Measured memory_bytes: 4808
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll a,b,c,k;
  cin >> a >> b >> c>> k;
  ll ans=0;
  ans+=min(a,k);
  k-=min(a,k);
  k-=min(b,k);
  ans-=min(c,k);
  cout << ans << endl;
  
  return 0;     
}


Measured memory_bytes: 3636
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

max = max(m)

dp = [[0 for _ in range(max + 1)] for __ in range(n + 1)]
dp[0][0] = 1#[1 for _ in range(max + 1)]
for j in range(n):
  for k in range(max + 1):
    if k >= A[j] and dp[j][k - A[j]]:
      dp[j + 1][k] = 1
    elif dp[j][k]:
      dp[j + 1][k] = 1
for i in range(q):
  if dp[n][m[i]]:
     print("yes")
  else:
    print("no")


Measured memory_bytes: 5964
// Biscuit_Generator
// https://atcoder.jp/contests/abc125/tasks/abc125_a
// date: 2020-08-15T19:20:35.753917

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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(ll) a;i<(ll) b;i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _repd(i,n) repdi(i,0,n)
#define repdi(i,a,b) for(ll i=(ll) b-1;i>=(ll) a;i--)
#define repd(...) _overload3(__VA_ARGS__,repdi,_repd,)(__VA_ARGS__)

#define all(x) x.begin(),x.end()
#define SIZE(x) ((ll)(x).size())

#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

template<typename T, typename ...Args>
void CIN(T& first, Args&... args) {
    ((cin >> first), ..., (cin >> args)); //C++17
}

template<char Sep, typename T, typename ...Args>
void COUNT_NL(const T& first, const Args&... args) {
    ((cout << first), ..., (cout << Sep << args)); //C++17
}

template<typename... Words>
void COUT(Words... words) {
    COUNT_NL<' '>(words...);
    cout << endl;
    return;
}

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange

int solve(void) {
    ll X,K,D;
    CIN(X,K,D);
//    COUT(X,K,D);
    X = abs(X);
    if (K%2 == 0){
        D*=(ll) 2LL;
        K /= 2LL;
    } else {
        if(X>0) {
            X-=(ll) D;
        } else{
            X+=(ll) D;
        }
        K=(ll) (K-1LL)/2LL;
        D*=(ll) 2LL;
    }

    ll cnt = (ll) X / D;
    if ( K < X / D) {
        COUT(abs(X-K*D));
    } else {
        COUT(min(abs(X-cnt*D),abs(X-(cnt+1LL)*D)));
    }
    return 0;
}

int main(void){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);

    solve();
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=55;
int n,pp,num,a=0,b=0;

ll C(int a,int b) {
	ll ret=1;
	bool vis[N];
	memset(vis,0,sizeof(vis));
	for (int i=0;i<b;i++) {
		ret*=(a-i);
		for (int j=b;j>=2;j--) {
			if (ret%j==0&&!vis[j]) {
				vis[j]=1;
				ret/=j;
			}
		}
	}
	return ret;
}

int main() {
	scanf("%d%d",&n,&pp);
	for (int i=0;i<n;i++) {
		scanf("%d",&num);
		if (num&1) a++;
		else b++;
	}//printf("a:%d b:%d\n",a,b);
	ll ans=1;
	for (int i=0;i<b;i++) ans*=2;
	ll tmp=0;
	if (pp&1) {
		for (int i=1;i<=a;i+=2) {
			tmp+=C(a,i);
		}
	} else {
		for (int i=0;i<=a;i+=2) {
			tmp+=C(a,i);
		}
	}//printf("tmp:%lld\n",tmp);
	printf("%lld\n",ans*tmp);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
signed main(){
    
    
    string s;
    cin>>s;
    //int ans=s.size();
    int count=0,max=0;
    for(int i=0;i<s.size();i++){
        
        if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
            count++;
        }
        else{
            max=std::max(count,max);
            count=0;
        } 
        
    
    }
    max=std::max(count,max);
            count=0;
    cout<<max<<endl;
    
	

}

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

int main() {
        int H1, M1, S1, H2, M2, S2;
        rep(i, 3) {
                cin >> H1 >> M1 >> S1 >> H2 >> M2 >> S2;
                int wt = (H2 * 3600 + M2 * 60 + S2) - (H1 * 3600 + M1 * 60 + S1);
                cout << wt / 3600 << " " << (wt % 3600) / 60 << " " << wt % 60 << endl;
        }
return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  int b=1000000000;
  int c=0;
  for (int i = 1; i <= 100; i++) {
    for (int j = 0; j < N; j++) {
      c+=(a.at(j)-i)*(a.at(j)-i);
    }
    b=min(b,c);
    c=0;
  }
  
    cout<<b<<endl;
  
 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    int w = scanner.nextInt();
    int h = scanner.nextInt();
    int n = scanner.nextInt();
    
    // 左端のx座標、右端のx座標、下端のy座標、上端のy座標
    int left = 0;
    int right = w;
    int bottom = 0;
    int top = h;
    
    for(int i = 0; i < n; i++) {
      int x = scanner.nextInt();
      int y = scanner.nextInt();
      int a = scanner.nextInt();
      
      switch(a) {
        case 1:
          // 左端より右にある点（left < xなる点）から左を切り捨てる
          // -> 左端を点のx座標で更新する（left = x）
          if(left < x) {
            left = x;
          }
          break;
        case 2:
          // 右端より左にある点（right > xなる点）から右を切り捨てる
          // -> 右端を点のx座標で更新する（right = x）
          if(right > x) {
            right = x;
          }
          break;
        case 3:
          // 下端より上にある点（bottom < yなる点）から下を切り捨てる
          // -> 下端を点のy座標で更新する（bottom = y）
          if(bottom < y) {
            bottom = y;
          }
          break;
        case 4:
          // 上端より下にある点（top > yなる点）から上を切り捨てる
          // -> 上端を点のx座標で更新する（top = y）
          if(top > y) {
            top = y;
          }
          break;
      }
    }
    
    // ありえない場合
    if(left > right || bottom > top) {
      System.out.println(0);
    // 正常に計算できる場合
    } else {
	  System.out.println((right - left) * (top - bottom));
    }
  }
}

Measured memory_bytes: 36148
#include <iostream>
#include <string>
using namespace std;
main() {
	int n,p,r,a;
	string t;
	cin >> n;
	for(int i=0;i<n;i++){
		a=0;r=0;p=0;
		while(a<3){
			cin >> t;
			if(t=="HIT"){
				r++;
				if(r>3) {r--;p++;}
			} else if(t=="OUT"){
				a++;
			} else {
				p+=r+1;
				r=0;
			}
		}
		cout << p << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
while True:
    H,W=map(int, input().split())
    if H == 0 and W == 0:
        break
    
    for i in range(H):
        if i == 0 or i == H -1:
            print("#" * W)
        else:
            print("#" + "." * (W-2) + "#")
    print()

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

int main(){
  int a;
  int b;
  int c;
  int d;
  int e;
  int k;

  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  cin >> k;

  if (e - a > k) {
    cout << ":(\n";
  } else {
    cout << "Yay!\n";
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
  while(1){
  stack <char> stk[2];
  string str;
  for(int i=0;i<2;i++){
    cin>>str;
    if(str=="-")return 0;
    for(int j=str.size()-1;j>=0;j--) stk[i].push(str[j]);
  }
  cin>>str;
 
  string ans;
  int idx=1,i=0;
  while(i!=(int)str.size()){
    char ima=stk[idx].top();stk[idx].pop();
    if(str[i]==ima){
      if(idx==1) idx=0;
      i++;
    }
    else{
      ans+=ima;
      if(idx==0) idx=1;
    }
  }
  for(int i=0;i<2;i++)
    while(!stk[i].empty()) ans+=stk[i].top(),stk[i].pop();
 
   cout <<ans<<endl;
 
  }
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#define ll long long int
using namespace std;


int main(void) {
    ll N;
    cin >> N;
    ll ans = 1e20;
    for(ll i = 1; i*i <= N; i++)/* i*iは小さい方の値は必ず√ｎ以下今回はｎを小さい方値にしてる　min(i,j)<=√nとなる*/ {
        if(N % i != 0) continue;
        ll j = N/i;
        ans = min(ans, i + j - 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long ryuka[100];
long long calc (int i){
	ryuka[i] = ryuka[i-1] + ryuka[i-2];
	return 0;
}
int main () {
	int n;
	cin >> n;
	ryuka[0] = 2;
	ryuka[1] = 1;
	for (int i = 2; i <= n; ++i)
	{
		calc(i);
	}
	cout << ryuka[n] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,ll>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

ll gcd(ll a,ll b){
    while(b!=0){
        a%=b;
        swap(a,b);
    }
    return a;
}

int main() {
    int N;
    cin>>N;
    vector<ll> A(N);
    rep(i,N)cin>>A.at(i);
    int x=A.at(0);
    rep(i,N){
        x=gcd(x,A.at(i));
    }
    cout<<x<<endl;
}

Measured memory_bytes: 4012
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    lint x;
    cin >> x;
    lint t = 1;
    while(t * (t + 1) < x * 2){
        t++;
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    map<string, vector<int>> m;
    map<int, int> id;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        string s;
        int p;
        cin >> s >> p;
        m[s].push_back(p);
        id[p] = i + 1;
    }
    for (auto it : m)
    {
        auto v = it.second;
        sort(v.begin(), v.end(), greater<int>());
        for (auto i : v)
        {
            cout << id[i] << endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>

const int MAX_S = 100000;

using namespace std;

static inline void my_strcpy( char* dst, char* src, int num) {
    for( int i=0; i<num; i++) {
        dst[i] = src[i];
    }
    dst[num] = '\0';
}

static inline bool isfrontstr( const char* str, char* target) {
    int length = strlen(str);
    for( int i=0; i<length; i++ ) {
        if( str[i] != target[i] ) return false;
    }
    return true;
}

int main()
{
    char buf[MAX_S+2];
    char *p_str;

    queue<char*> q_readp; 

    cin >> buf;
    p_str = buf;
   
    q_readp.push(p_str);

    while(!q_readp.empty()) {

        if( q_readp.front()[0] == '\0' ) {
            printf("YES\n");
            return 0;
        }
        if( isfrontstr("dream",q_readp.front()) ) {
            q_readp.push(q_readp.front()+5);
        }
        if( isfrontstr("dreamer",q_readp.front()) ) {
            q_readp.push(q_readp.front()+7);
        }
        if( isfrontstr("erase",q_readp.front()) ) {
            q_readp.push(q_readp.front()+5);
        }
        if( isfrontstr("eraser",q_readp.front()) ) {
            q_readp.push(q_readp.front()+6);
        }
        q_readp.pop();

    }
    printf("NO\n");
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int tree[maxn],a[maxn][3],s[maxn],w[maxn];
int b[3];
int inv[2],flip[2];
int i,j,k,l,t,n,m,now;
bool czy;
int lowbit(int x){
    return x&-x;
}
void change(int x,int v){
    while (x>0){
        tree[x]+=v;
        x-=lowbit(x);
    }
}
int query(int x){
    int t=0;
    while (x<=n){
        t+=tree[x];
        x+=lowbit(x);
    }
    return t;
}
int main(){
    scanf("%d",&n);
    fo(j,0,2)
        fo(i,1,n) scanf("%d",&a[i][j]);
    fo(i,1,n){
        fo(j,0,2) b[j]=a[i][j];
        sort(b,b+3);
        if (b[1]!=b[0]+1||b[2]!=b[1]+1||b[2]%3!=0||a[i][1]!=b[1]){
            printf("No\n");
            return 0;
        }
        if (a[i][0]>a[i][2]) inv[i%2]^=1;
        s[i]=b[2]/3;
        if ((i-s[i])%2){
            printf("No\n");
            return 0;
        }
    }
    fo(i,1,n) w[s[i]]=i;
    for(i=1;i<=n;i+=2){
        now=w[i]+2*query(w[i]);
        flip[1]=(flip[1]+abs(i-now)/2)%2;
        change(w[i],1);
    }
    fo(i,0,n) tree[i]=0;
    for(i=2;i<=n;i+=2){
        now=w[i]+2*query(w[i]);
        flip[0]=(flip[0]+abs(i-now)/2)%2;
        change(w[i],1);
    }
    czy=1;
    if (inv[0]!=flip[1]||inv[1]!=flip[0]) czy=0;
    if (czy) printf("Yes\n");else printf("No\n");
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main()
{
    lli a, b, x, a_diff, b_diff, count=0;
    cin >> a >> b >> x;
    if(a==0) count=b/x+1;
    else count=b/x-(a-1)/x;
    cout << count << 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;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n, m;
  cin >> n >> m;

  cout << n*(n-1)/2+m*(m-1)/2 << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

#define int ll

using namespace std;

#ifdef __LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e5 + 20;
#endif

//tg: @galebickosikasa
 
const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	char x;
	cin >> x;
	if ('A' <= x && x <= 'Z') {
		cout << 'A';
	} else cout << 'a';







}

Measured memory_bytes: 3604
#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<utility>
#include<cmath>
#define pb push_back
#define ll long long
#define inf 1000000009
using namespace std;
ll idx[100009];
multiset<ll> ids;
int main(){
	ll n;
	cin>>n;
	vector<ll> p;
	for(int i=1;i<=n;i++){
		ll x;
		cin>>x;
		p.pb(x);
		idx[x] = i;
	}
	ids.insert(0);
	ids.insert(0);
	ids.insert(n+1);
	ids.insert(n+1);
	ll ans = 0;
	for(int i=n;i>=1;i--){
		ll cid = idx[i];
		multiset<ll>::iterator it = ids.upper_bound(cid);
		ll r1 = *it;
		it++;
		ll r2 = *it;
		it = ids.upper_bound(cid);
		it--;
		ll l1 = *it;
		it--;
		ll l2 = *it;
		ll comb = (r2 - r1) * (cid - l1) + (l1 - l2) * (r1 -cid);
		ans += i * comb;
		ids.insert(cid);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6516
#include<bits/stdc++.h>
#define inf 1<<29
#define linf 1e16
#define eps (1e-8)
#define mod 1000000007
#define pi acos(-1)
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
};
typedef Segment Line;

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

Point project(Segment s,Point p){
  Vector base=(s.p2-s.p1);
  double r=(dot(p-s.p1,base)/base.norm());
  return (s.p1+base*r);
}

Point reflect(Segment s,Point p){
  return p+(project(s,p)-p)*2;
}

Polygon reflect(Line l,Polygon p){
  FOR(i,0,p.size())p[i]=reflect(l,p[i]);
  return p;
}

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

bool intersect(Line l,Segment s){
  return ccw(l.p1,l.p2,s.p1)*ccw(l.p1,l.p2,s.p2)<0;
}

int n;
Point s;
bool used[10]={};

int check(vector<Segment> vs){
  FOR(i,1,vs.size()){
    FOR(j,0,i){
      if(intersect(Line(s,vs[j].p1),vs[i]))continue;
      if(intersect(Line(s,vs[j].p2),vs[i]))continue;
      if(intersect(Line(s,vs[i].p1),vs[j]))continue;
      if(intersect(Line(s,vs[i].p2),vs[j]))continue;
      return 0;
    }
  }
  return 1;
}

int rec(Polygon p,vector<Segment> vs){
  if(vs.size()==p.size())return check(vs);
  int res = 0;
  FOR(i,0,p.size()){
    if(used[i])continue;
    used[i]=true;
    Segment e(p[i],p[(i+1)%p.size()]);
    vs.pb(e);
    res+=rec(reflect(e,p),vs);
    vs.pop_back();
    used[i]=false;
  }
  return res;
}

int main()
{
  while(cin>>n && n){
    Polygon p;
    vector<Segment> vs;
    cin>>s.x>>s.y;
    FOR(i,0,n){
      int x,y;
      cin>>x>>y;
      p.pb(Point(x,y));
    }
    cout<<rec(p,vs)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3204
// AOJ Volume 0 Problem 0042

#include <stdio.h>
#include <string.h>

int main(void)
{
	int data_set;
	int w, n;
	int value, weight;
	int i, j;
	int bag[1001];
	int max;
	
	data_set = 1;
	while (1){
		scanf("%d", &w);
		if (w == 0){
			break;
		}
		
		memset(bag, 0, sizeof(bag));

		scanf("%d", &n);
		for (i = 0; i < n; i++){
			scanf("%d,%d", &value, &weight);
			for (j = w; j > 0; j--){
				if ((bag[j] != 0) && (j + weight <= w)){
					if (bag[j] + value > bag[j + weight]){
						bag[j + weight] = bag[j] + value;
//						printf("(%d:%d)", j + weight, value);
					}
				}
			}
			if (weight <= w && bag[weight] < value){
				bag[weight] = value;
			}
		}
		max = 1;
		for (i = 1; i <= w; i++){
//			printf("%d:%d  ", i, bag[i]);
			if (bag[max] < bag[i]){
				max = i;
			}
		}
		printf("Case %d:\n", data_set++);
		printf("%d\n%d\n", bag[max], max);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

int main() {
  int n;
  while(cin>>n,n) {
    REP(i,n) {
      int m,e,j;
      cin >> m >> e >> j;
      char c;
      if (m == 100 || e == 100 || j == 100)
        c = 'A';
      else if (m + e >= 180)
        c = 'A';
      else if (m + e + j >= 240)
        c = 'A';
      else if (m + e + j >= 210)
        c = 'B';
      else if (m + e + j >= 150 && (m >= 80 || e >= 80))
        c = 'B';
      else
        c = 'C';
      cout << c << endl;
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, i, c;
  cin >> a >> b;
  vector<int> way(a);
  for(i=0;i<2*b;i++) {
    cin >> c;
    way.at(c-1)++;
  }
  for(i=0;i<a;i++) {
    cout << way.at(i) << endl;
  }
  return 0;
}

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

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

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        string s; cin >> s;
        int k; cin >> k;
        int n = sz(s);
        vector<string> a;
        for (int i = 0; i < n; i++) {
                string ss;
                for (int j = i; j < n && j - i + 1 <= k; j++) {
                        ss += s[j];
                        a.emplace_back(ss);
                }
        }

        sort(all(a));
        a.resize(unique(all(a)) - a.begin());
        cout << a[k - 1] << '\n';
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 4284
///
// File:  1367.cpp
// Author: ymiyamoto
//
// Created on Wed Nov 29 07:40:28 2017
//

#include <array>
#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;

int32_t main()
{
  uint32_t n, m;
  cin >> n >> m;

  vector<uint32_t> q(m, 0);
  for (uint32_t i = 0; i < m; i++) {
    cin >> q[i];
  }

  vector<bool> printed(n + 1, 0);
  for (int32_t i = q.size() - 1; i >= 0; i--) {
    if (!printed[q[i]]) {
      cout << q[i] << endl;
      printed[q[i]] = true;
    }
  }

  for (uint32_t i = 1; i <= n; i++) {
    if (!printed[i]) {
      cout << i << endl;
      printed[i] = true;
    }
  }
  return 0;
}

Measured memory_bytes: 3264
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length();i+=2) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int main(){
    int a,b;cin>>a>>b;
    cout<<max({a*b,a+b,a-b})<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#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 Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll>>
#define INF 999999999999

int main(){
  string S,T;
  int count=0;
  cin>>S>>T;
  rep(i,3){
    if(S[i]==T[i]) count++;
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
  int b[27] = {};
  
  for(int i = 2;i<=N;i++){
    int dairi = i;
    for(int k = 0;k<25;k++){
      if(dairi%a[k] == 0){
        b[k] ++;
        dairi = dairi/a[k];
        k = -1;
      }
    }
  }
  
  int c[5] = {2,4,14,24,74};
  int d[5] = {};
  for(int i = 0;i<25;i++){
    for(int k = 0;k<5;k++){
      if(b[i] >= c[k]){
        d[k] ++;
      }
    }
  }
  cout << (d[1]*(d[1]-1)/2)*(d[0]-2) + d[2]*(d[1]-1)+(d[0]-1)*d[3]+d[4] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 110


int main() {
  int A[3][3];

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      scanf("%d", A[i] + j);
    }
  }

  int N, e[SIZE] = {};
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    int B;
    scanf("%d", &B);
    e[B] = true;
  }

  bool ans = false;

  for (int i = 0; i < 3; i++) {
    ans |= e[A[i][0]] && e[A[i][1]] && e[A[i][2]];
    ans |= e[A[0][i]] && e[A[1][i]] && e[A[2][i]];
  }
  ans |= e[A[0][0]] && e[A[1][1]] && e[A[2][2]];
  ans |= e[A[2][0]] && e[A[1][1]] && e[A[0][2]];

  puts(ans ? "Yes" : "No");

  return 0;
}


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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define fastio    ios::sync_with_stdio(0); cin.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  fastio;
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  int n;
  cin >> n;
  vvi cnt(10, vi(10));
  for (int i = 1; i < 10; i++) if (i <= n) cnt[i][i]++;
  
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      bool ok = true;
      for (int k = 0, m = 1; ok; k++, m *= 10) {
        for (int l = 0; l < m; l++) {
          int cur = j, r = 10;
          for (int t = l; t; r *= 10, t /= 10) {
            cur += t % 10 * r;
          }
          cur += i * m * 10;
          if (cur > n) {
            ok = false;
            break;
          }
          // cout << i << ' ' << j << ' ' << cur << endl;
          cnt[i][j]++;
        }
      }
    }
  }

  ll tot = 0;
  for (int i = 1; i <= n; i++) {
    int f = i, e = i % 10;
    while (f > 9) f /= 10;
    tot += cnt[e][f];
  }
  cout << tot;

  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

bool check(int n, const vector<int>& d) {
  while (n != 0) {
    if (EXIST(d, n % 10)) return false;
    n /= 10;
  }
  return true;
}

int main(int argc, char* argv[])
{
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int sum = a[i] + a[i+1];
    if (sum > x) {
      int tmp = min(a[i+1], sum - x);
      a[i+1] -= tmp;
      ans += tmp;
      sum -= tmp;
      if (sum > x) {
        a[i] -= (sum - x);
        ans += (sum - x);
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int str = scan.nextInt();
        int s2 = scan.nextInt();
        int a = 0;
        switch (str) {
            case 1:
                if (s2 == 2) {
                    a = 3;
                } else {
                    a = 2;
                }
                break;

            case 2:
                if (s2 == 1) {
                    a = 3;
                } else {
                    a = 1;
                }
                break;
            case 3:
                if (s2 == 1) {
                    a = 2;
                } else {
                    a = 1;
                }
                break;
        }

        System.out.println(a);
    }
}

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

int main()
{
    int a,b,c,d,sum,i,j,k;
   while( scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
   {
       sum=0;
    for(i=0;i<=a;i++)
        for(j=0;j<=b;j++)
        for(k=0;k<=c;k++)
        if((500*i+100*j+50*k)==d)
            sum++;
            printf("%d\n",sum);
   }
    return 0;
}



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

int main() {
    long long int N,M;
    cin >> N >> M;
    long long int mn, mx;
    long long int tmn, tmx;
    mx = 1;
    mn = N;
    
    while(cin >> tmx >> tmn)
    {
        mn = min(mn,tmn);
        mx = max(mx,tmx);
    }
    if(mn - mx + 1 >= 0){
        cout << mn - mx + 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

constexpr LL kMax = 1000000000000000000;

int main() {
  int N; cin >> N;
  vector<LL> A(N); cin >> A;
  for (LL a : A) {
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(A.rbegin(), A.rend());

  LL v = A[N-1];
  for (int i = 0; i < N-1; ++i) {
    long double w = 1e18 / v;
    if (w < A[i]) {
      cout << -1 << endl;
      return 0;
    }
    v *= A[i];
  }
  if (v > kMax) {
      cout << -1 << endl;
      return 0;
  }
  cout << v << endl;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int count=0;
    for(int i=0;i<N;i++){
        cin >> A.at(i);
        if(A.at(i)%2==1) count++;
    }
    if(count%2==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>

using namespace std;
using ll = long long;

int main(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5])cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main (){
    int N = 0;
    cin >> N;
    int ans = 0;
    //for (size_t p = 1; p < N+1; p++)
    //{
    //ans = 0;
    int c;
    vector<int> A(10001);
    for (size_t i = 1; i < 101; i++)
    {
        for (size_t j = 1; j < 101; j++)
        {
            for (size_t k = 1; k < 101; k++)
            {
                c = i*i+j*j+k*k+i*j+j*k+k*i;
                if (c<=10000)
                {
                    A.at(c)++;
                }
                
            }
            
        }
        
    }
    for (size_t i = 0; i < N; i++)
    {
        cout << A.at(i+1) << endl;
    }
    
    //cout << ans << endl;
    //}
    
    
}

Measured memory_bytes: 3456
mod = 10 ** 9 + 7
n, m = map(int, input().split())
As = [int(input()) for _ in range(m)]
d = [0 for i in range(n + 1)]
d[n] = 1
for a in As:
    d[a] = -1
for i in range(n - 1, -1, -1):
    if d[i] < 0:
        d[i] = 0
        continue
    if i == n - 1:
        d[i] = d[i + 1]
    else:
        d[i] = (d[i + 1] + d[i + 2]) % mod
print(d[0])


Measured memory_bytes: 7832
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  vector <int> a(n);
  map <int,int> s;
  for (int i; i<n; i++){
    cin >> a[i];
  }
  for ( int i; i<n; i++){
  	s[a[i]]=i+1;
  }
  sort(a.begin(),a.end());
  for(int i; i<n; i++){
  cout << s[a[i]] << " ";
  }
}

Measured memory_bytes: 5888
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    long long A,B;
    A=B=0;
    REP(i,N){
        int d;
        cin >> d;
        A+=d;
    }
    REP(i,M){
        int d;
        cin >> d;
        B+=d;
    }
    cout << A*B << endl;
    return 0;
}



Measured memory_bytes: 3100