akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
// template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    int n, m;
    cin >> n >> m;
    
    map<pii, int> mp;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        mp[pii(a, b)] = 1;
        mp[pii(b, a)] = 1;
    }
    
    rep3(i, 2, n) {
        if (mp[pii(1, i)] && mp[pii(i, n)]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 37760
def main(N,K,p):
    sumi = 0
    ruiseki = [0] * (N+1)
    for i in range(N):
        ruiseki[i+1] = ruiseki[i] + p[i]
    for j in range(N-K+1):
        sumi = max(sumi, (ruiseki[j+K]-ruiseki[j]))
    return (sumi + K) / 2
N,K = map(int,input().split())
p = list(map(int,input().split()))
print(main(N,K,p))


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

map <int,pair<int,int> > m;
bool vis[3][3];
int N;
int main(){
	for (int i=0;i<3;i++){
		for (int j=0;j<3;j++){
			int a; cin>>a; m[a] = make_pair(i,j);
        }
    }
  
  	cin>>N;
  	
  	for (int i=0;i<N;i++){
		int a; cin>>a;
      	if (m.find(a) != m.end()) vis[m[a].first][m[a].second] = 1;
    }
  	
  	for (int i=0;i<3;i++){
		if (vis[i][0] && vis[i][1] && vis[i][2]){
			cout<<"Yes";
          	return 0;
        }
      	
      	if (vis[0][i] && vis[1][i] && vis[2][i]){
			cout<<"Yes";
          	return 0;
        }
    }
  
  if (vis[0][0] && vis[1][1] && vis[2][2]){
		cout<<"Yes";
    	return 0;
  }
  
  if (vis[2][0] && vis[1][1] && vis[0][2]){
		cout<<"Yes";
          return 0;
  }
  cout<<"No";

}


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

int main(void)
{
  int n,m,i,j,num[100],max=0;
  char red[100][11],blue[100][11];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s",blue[i]);
    }
  scanf("%d",&m);
  for(i=0;i<m;i++)
    {
      scanf("%s",red[i]);
    }
  for(i=0;i<100;i++)
    {
      num[i] = 0;
    }
  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  if(strcmp(blue[i],blue[j]) == 0)
	    {
	      num[i]++;
	    }
	}
    }
  for(i=0;i<n;i++)
    {
      for(j=0;j<m;j++)
	{
	  if(strcmp(blue[i],red[j]) == 0)
	    {
	      num[i]--;
	    }
	}
    }
  for(i=0;i<n;i++)
    {
      if(max < num[i])
	{
	  max = num[i];
	}
    }
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 128
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
//#define MOD 1000000007
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll n;
    cin >> n;
    list<ll> b;
    if (n % 2 == 0) {
        rep(i, n) {
            ll a;
            cin >> a;
            if (i % 2 != 0) b.push_front(a);
            else b.push_back(a);
        }
    } else {
        rep(i, n) {
            ll a;
            cin >> a;
            if (i % 2 == 0) b.push_front(a);
            else b.push_back(a);
        }
    }
    for(ll i : b) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 1e5+5;
 
int n, m, cur;
int u[N], v[N], ans[N];
 
struct DSU
{
	int connected;
	int par[N], sz[N];
 
	void init(int n) 
	{
		for(int i=1;i<=n;i++)
		{
			par[i]=i;
			sz[i]=1;
		}
		connected=n;
	}
 
	int getPar(int k)
	{
		while(k!=par[k])
		{
			par[k]=par[par[k]];
			k=par[k];
		}
		return k;
	}
 
	int getSize(int k)
	{
		return sz[getPar(k)];
	}
 
	void unite(int u, int v)
	{
		int par1=getPar(u), par2=getPar(v);
 
		if(par1==par2)
			return;
 
		connected--;
 
		if(sz[par1]>sz[par2])
			swap(par1, par2);
 
		cur -= sz[par1] * sz[par2];
		sz[par2]+=sz[par1];
		sz[par1]=0;
		par[par1]=par[par2];
	}
};
 
DSU dsu;
 
int32_t main()
{
	IOS;
	cin>>n>>m;
	dsu.init(n);
	cur=n*(n-1)/2;
	for(int i=1;i<=m;i++)
		cin>>u[i]>>v[i];
	for(int i=m;i>=1;i--)
	{
		ans[i] = cur;
		dsu.unite(u[i], v[i]);
	}
	for(int i=1;i<=m;i++)
		cout<<ans[i]<<endl;
	return 0;
}
 

Measured memory_bytes: 5248
#include <stdio.h>
int main(){
  int a,b,c,k;
  int sum = 0;
  scanf("%d %d %d %d",&a,&b,&c,&k);
  if(a >= k) sum += k;
  else{ 
	sum += a;
	k -= a;
	if(b < k){
		k -= b;
		if(c >= k) sum -= k;
		else sum -= c;}
	}
		
  printf("%d",sum);
}	
	

Measured memory_bytes: 1736
use std::io;
use std::str::FromStr;
use std::iter::Map;
use std::str::SplitWhitespace;

fn split_to_i64<'r>(buf: &'r String) -> Map<SplitWhitespace, impl FnMut(&'r str) -> i64> {
    let mp = buf
        .split_whitespace()
        .map(|n| i64::from_str(n).unwrap())
        .into_iter();

    return mp;
}

fn get_int() -> i64 {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf);
    buf.pop();
    return i64::from_str(&buf).unwrap();
}

fn get_int_itr<'r>(buf: &'r mut String) -> Map<SplitWhitespace, impl FnMut(&'r str) -> i64> {
    let stdin = io::stdin();
    stdin.read_line(buf);
    return split_to_i64(buf);
}

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf);
    buf.pop();
    let mut it = split_to_i64(&buf);
    let N = it.next().unwrap();
    let K = it.next().unwrap();
    let mut friends: Vec<i32> = Vec::with_capacity(101);
    for i in 0..101 {
        friends.push(0);
    }
    for i in 0..K {
        let mut buf1 = String::new();
        let d = get_int();
        let mut it = get_int_itr(&mut buf1);
        for j in 0..d {
            let id = it.next().unwrap();
            // println!("{}", id);
            friends[id as usize] += 1;
        }
    }
    let mut res = 0;
    for i in 1..(N+1) {
        if friends[i as usize] == 0 {
            res += 1;
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 2144
'''
A[i]<A[j]
F[i]<F[j]
となる組み合わせが存在したと仮定

max(A[i]*F[i],A[j]*F[j])=A[j]*F[j]
>A[i]*F[j]
>A[j]*F[i]
より、この場合はiとjを入れ替えたほうが最適となる。

結局
Aを昇順ソート
Fを降順ソート
するのが最適となる。
問題は修行の割当である。
順序を保ったまま修行していっても問題ない
3,2->1,2と
3.2->2,1は同じとみなせるため
二分探索
成績をmidにするために必要な修行コスト
lowならK回より真に大
highならK回以下
'''
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]
A.sort()
F.sort(reverse=True)
low=-1
high=max(A)*max(F)+1
while(high-low>1):
    mid=(high+low)//2
    tmp=0
    for i in range(N):
        #A[i]*F[i]-mid<=X*F[i]
        x=(A[i]*F[i]-mid+F[i]-1)//F[i]
        if x<0:
            continue
        tmp+=x
    if tmp<=K:
        high=mid
    else:
        low=mid
print(high)


Measured memory_bytes: 113692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

vector<pair<ll,int>> V;
map<ll,int> mp;
ll N;

int rec(int ind,ll K){
  if(ind==V.size()){
    if(K==1) return 0;
    ll X=N;
    while(X%K==0&&X>1) X/=K;
    if(X%K==1) return 1;
    else return 0;
  }
  int ret=0;
  ll a=1;
  for(int i=0;i<=V[ind].second;i++){
    ret+=rec(ind+1,K*a);
    a*=V[ind].first;
  }
  return ret;
}

int main(){
  cin>>N;
  ll X=N;
  for(ll i=2;i*i<=X;i++){
    if(X%i) continue;
    int cnt=0;
    while(X%i==0) cnt++,X/=i;
    V.push_back({i,cnt});
  }
  if(X>1) V.push_back({X,1});
  ll ans=rec(0,1);
  
  X=N-1;
  for(ll i=2;i*i<=X;i++){
    while(X%i==0){
      mp[i]++;
      X/=i;
    }
  }
  if(X>1) mp[X]++;
  ll res=1;
  for(auto m:mp) res*=(m.second+1);
  ans+=res-1;

  cout<<ans<<endl;
  return 0;
}


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

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  
  while(A%B!=0){
    int tmp=A%B;
    A=B;
    B=tmp;
  }
  if(C%B==0){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = 9000000000000;
const ll mod = 2e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

int bd[2010][2010];

signed main() {
	int n,k;
	cin >> n >> k;
	REP (i,n) {
		int x,y;
		char z;
		cin >> x >> y >> z;
		if (z == 'B') {
			bd[x % (2 * k)+1][y % (2 * k)+1]++;
		} else {
			bd[(x + k) % (2 * k)+1][y % (2 * k)+1]++;
		}
	}
	// REP (i,2*k+1) {
	// 	REP (j,2*k+1) {
	// 		cout << bd[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	REP (i,2 * k + 1) {
		FOR (j,1,2 * k + 1) {
			bd[i][j] += bd[i][j-1];
		}
	}
	FOR (i,1,2 * k + 1) {
		REP (j,2 * k + 1) {
			bd[i][j] += bd[i-1][j];
		}
	}	
	int ans = -1;
	REP (i,k+1) {
		REP (j,k+1) {
			int a,b,c,d,e;
			a = bd[i][j];
			b = bd[i][2*k] - bd[i][j+k];
			c = bd[i+k][j+k] - bd[i][j+k] - bd[i+k][j] + bd[i][j];
			d = bd[2*k][j] - bd[i+k][j];
			e = bd[2*k][2*k] - bd[i+k][2*k] - bd[2*k][j+k] + bd[i+k][j+k];
			int tmp = a + b + c + d + e;
			ans = max(ans,max(tmp,bd[2*k][2*k]-tmp));
		}
	}
	// REP (i,2*k+1) {
	// 	REP (j,2*k+1) {
	// 		cout << bd[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	cout << ans << endl;
}

Measured memory_bytes: 33024
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int H = sc.nextInt();
   int W = sc.nextInt();
   char[][] ccc = new char[H][W];
   for(int i =0;i<H;i++)
   {
     ccc[i] = sc.next().toCharArray();
   }
   for(int i=0;i<H;i++)
   {
     for(int k=0;k<W;k++) System.out.print(ccc[i][k]);
     System.out.println();
     for(int k=0;k<W;k++) System.out.print(ccc[i][k]);
     System.out.println();
   }
 }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])  
#define md 1000000007
#define MAXN 200005

int main()
{   
    ios::sync_with_stdio(false);

    ll n, k;
    cin >> n >> k;
    ll a[n+1];
    ll vis[n+1];
    MEM(vis, 0);
    loop(i,1, n+1) {
    	cin >> a[i];
    }
    ll cycle = 1;
    ll next = a[1], start;
    vis[1] = 1;
    vll v;
    v.pb(1);
    while (1) {
    	// cout << "ll: " << next << endl;
    	if (vis[next]) {
    		start = next;
    		break;
    	}
    	vis[next] = 1;
    	v.pb(next);
    	next = a[next];
    	cycle++;
    }
    int f = 0, sI;
    vll newV;
    
    for (int i = 0 ; i < v.size() ; i++) {
    	// cout << v[i] << "gg" << endl;
    	if (v[i] == start) {
    		f = 1;
    		sI = i+1;
    	}
    	if (f == 1) {
    		newV.pb(v[i]);
    	}

    }
    // cout << "si : " << sI << endl;
    if (k > sI) {
    	k -= (sI-1);
    	cout << newV[k%(newV.size())] << endl;
    }
    else {
    	cout << v[k] << endl;;
    }
    return 0;
}




Measured memory_bytes: 10704
#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() {
    ll a;
    double b;
    cin >> a >> b;
    ll bd = b * 100 + 0.1;
    a *= bd;
    a /= 100;
    printf("%lld\n", a);
    return 0;
}


Measured memory_bytes: 3788
from bisect import bisect_right
import math
import numpy as np

def primes(n):
    yield 2
    import numpy as np
    nn = int(math.sqrt(n)+1)
    a = np.arange(1, nn+1)
    b = a * a.reshape((nn, 1))
    b = b[1:,1:]
    c = b.reshape((nn-1)*(nn-1), )
    notprimes = set(c)
    for p in range(3, n+1, 2):
        if p not in notprimes:
            yield p

def bunkai(N):
    result = dict()
    for p in primes(int(math.sqrt(N))+1):
        if N == 1:
            return result
        count = 0
        while N % p == 0:
            count += 1
            N /= p
        if count != 0:
            result[p] = count
    
    if N != 1:
        result[N] = 1
    
    return result


def main():
    N = int(input())

    s = np.arange(math.log(N,2)+1, dtype=np.int32)
    S = (s * (s + 1) ) // 2
    p_list = bunkai(N)

    ans = 0
    for c in p_list.values():
        i = bisect_right(S, c) - 1
        #print(f"c={c} i={i}")
        ans += i
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 59832
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

ll N, ans = 1, t;

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
  if x < min(A):
    print(cnt)
    break
  elif i == N-1 and x-A[0] > 0:
    print(N-1)
    break
  elif i == N-1 and x-A[0] == 0:
    print(N)
    break
  else:
    x -= min(A)
    A.remove(min(A))
    cnt += 1

Measured memory_bytes: 3064
char buf[2<<20],out[6];
sz;
cnt[1<<20];
main()
{
	read(0,buf,2<<20);
	int N=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(int i=0;i<N;i++)
	{
		int A=0;
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		cnt[A]++;
	}
	int ans=0;
	for(int i=1;i<=1000000;i++)
	{
		if(cnt[i])
		{
			ans+=cnt[i]<2;
			for(int j=i+i;j<=1000000;j+=i)cnt[j]=0;
		}
	}
	int osz=6;
	do{
		out[--osz]=ans%10+'0';
	}while(ans/=10);
	write(1,out+osz,6-osz);
}


Measured memory_bytes: 6984
#include <iostream>
#include <queue>
#include <math.h>
using namespace std;

int main(void)
{
    int k, n; cin >> k >> n;
    queue<int> a;
    int _a;
    for (int i = 0; i < n; i++) 
    {
        cin >> _a;
        a.push(_a);
    }

    int ans = k;
    int d, s, t1, t2;
    for (int i = 0; i < n; i++)
    {
        s = a.front(); a.pop();
        t1 = a.front();
        t2 = a.back();
        d = min(t2 - s, k - (t1 - s));
        ans = min(ans, d);
        a.push(s + k);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4488
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)

long long M = 1000000007;

int n;
typedef vector<vector<long long>> Mat;

int main(int argc, char const *argv[]) {
    string s;cin>>s;
    int n = s.length();
    int d;cin>>d;
    vector<vector<long long>> dp(n+1,vector<long long>(d,0)),dp9(n+1,vector<long long>(d,0));
    dp[0][0] = 1;
    dp9[0][0] = 1;
    for(int i=0;i<n;++i){
        for(int k=0;k<d;++k){
            for(int l=0;l<10;++l){
                dp9[i+1][k] += dp9[i][(((k-l)%d)+d)%d];
                dp9[i+1][k] %= M;
            }
        }
        char c = s[n-i-1];
        int m = c - '0';
        for(int k=0;k<d;++k){
            for(int l=0;l<m;++l){
                dp[i+1][k] += dp9[i][(((k-l)%d)+d)%d];
                dp[i+1][k] %= M;
            }
            dp[i+1][k] += dp[i][(((k-m)%d)+d)%d];
            dp[i+1][k] %= M;
        }
    }
    cout<<(dp[n][0]+M-1)%M<<endl;
    return 0;
}

Measured memory_bytes: 16640
### constant

DXYS = [[-1, 0], [0, 1], [1, 0], [0, -1]]

### main

loop do
  n = gets.to_i
  break if n == 0

  ops = (n - 1).times.map{gets.split.map(&:to_i)}

  sqs = [[0, 0]]
  min_x = max_x = min_y = max_y = 0

  ops.each do |ni, di|
    xi = sqs[ni][0] + DXYS[di][0]
    yi = sqs[ni][1] + DXYS[di][1]
    sqs << [xi, yi]

    min_x = xi if min_x > xi
    max_x = xi if max_x < xi
    min_y = yi if min_y > yi
    max_y = yi if max_y < yi
  end
  #p [min_x, max_x, min_y, max_y]

  w = max_x - min_x + 1
  h = max_y - min_y + 1
  puts [w, h].join(' ')
end

Measured memory_bytes: 6120
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<map>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    int N;
    ll M,A[110000];
    cin>>N>>M;
    for(int i=0;i<N;i++) cin>>A[i];
    map<ll,int> V;
    ll sum=0;
    V[0]++;
    for(int i=0;i<N;i++){
        sum+=A[i];
        sum%=M;
        V[sum]++;
    }
    ll ans=0;
    for(auto it=V.begin();it!=V.end();it++){
        ll x=it->second;
        ans+=x*(x-1)/2;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4992
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll d,t,s;
    cin>>d>>t>>s;
    if(d<=t*s){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
}

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

using namespace std;

typedef long long int ll;

inline void deBugMode() {
    #ifndef ONLINE_JUDGE
    freopen("debug.in", "r", stdin);
    #endif // ONLINE_JUDGE
}

inline void optimizeIt() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
}

inline int ABS(const int &x) {
    return max(x, -x);
}

const int NMax = 1e5 + 5;
const int LIM = 1e5;
const int MOD = 1000000007;

int main(){
    //deBugMode();
    optimizeIt();

    char c;
    cin >> c;

    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        cout << "vowel";
    } else {
        cout << "consonant";
    }

    return 0;

}


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


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {
    cin.tie(0);
    cin.sync_with_stdio(0);
}



int main() {
    fast();
    double n;cin>>n;
    double pi=3.14159265358979323;
    cout<<fixed<<setprecision(9)<<2*pi*n;


}

Measured memory_bytes: 3800
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include<set>
#include <vector>

#define F first
#define S second
#define MAX_V 110
#define INF (1<<29)

using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> P3;

struct edge{int to,d,e;};

vector<edge>g[MAX_V];
int d[MAX_V][101],n,m,l;

void dijkstra(int s){
  priority_queue<P3,vector<P3>,greater<P3> >que;

  fill(d[0],d[MAX_V],INF);
  d[s][l]=0;
  que.push(P3(0,P(l,s)));

  while(!que.empty()){
    P3 p=que.top();que.pop();
    int v=p.S.S;
    if(d[v][p.S.F]<p.F)continue;
    if(v==n){
      cout << p.F << endl;
      return;
    }

    for(int i=0;i<g[v].size();i++){
      edge e=g[v][i];
      if(d[e.to][p.S.F]>d[v][p.S.F]+e.e){
        d[e.to][p.S.F]=d[v][p.S.F]+e.e;
        que.push(P3(d[e.to][p.S.F],P(p.S.F,e.to)));
      }

      if(p.S.F-e.d>=0 && d[e.to][p.S.F-e.d]>d[v][p.S.F]){
        d[e.to][p.S.F-e.d]=d[v][p.S.F];
        que.push(P3(d[e.to][p.S.F-e.d],P(p.S.F-e.d,e.to)));
      }
    }
  }
}

int main(void){

  while(cin >> n >> m >> l,n|m|l){
    for(int i=0;i<MAX_V;i++)g[i].clear();
    int a,b,d1,e;
    for(int i=0;i<m;i++){
      cin >> a >> b >> d1 >> e;
      edge e1,e2;
      e1.to=b,e1.d=d1,e1.e=e;
      e2.to=a,e2.d=d1,e2.e=e;
      g[a].push_back(e1);
      g[b].push_back(e2);
    }

    dijkstra(1);
  }

  return 0;
}

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

void chmin(int&a, int b) {
  if (a > b) a = b;
}

int main() {
  int A[5];

  for (int i = 0; i < 5; i++) {
    cin >> A[i];
  }
  
  int mod_min = 10;
  for (int i = 0; i < 5; i++) {
    if (A[i] % 10) {
      chmin(mod_min, A[i] % 10);
    }
  }
  
  int ans = 0;
  if (mod_min == 10) {
    for (int i = 0; i < 5; i++) {
    ans += A[i];
    }
    cout << ans << endl;
  } else {
    for (int i = 0; i < 5; i++) {
      if (A[i] % 10) {
        ans += A[i] + (10-(A[i]%10));
    } else {
        ans += A[i];
      }
    } 
  
    cout << ans - 10 + mod_min << endl;

  }
}

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

int main() {
    string S;
    cin >> S;
    if (S == "ABC") {
        cout << "ARC"<< endl;
    }
    else {
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3596
#include<stdio.h>

#define H 2000000

int size;
int A[H];

int left(i){
  return i*2;
}

int right(i){
  return i*2+1;
}

void maxHeapify(int i){
  int l = left(i);
  int r = right(i);
  int tmp,largest;
  // ????????????????????????????????§???????????§????????????????????¶
  if(l<=size && A[l]>A[i]) largest = l;
  else largest = i;
  if(r<=size && A[r]>A[largest]) largest = r;

  if(largest != i){ // i ???????????????????????§????????´???
      tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest); // ?????°??????????????????
      }

}
void  buildMaxHeap(){
  int i;
  for(i=size/2;i>=1;i--){
    maxHeapify(i);
      }
}


int main(void){
  int i;
  scanf("%d",&size);
  
  for(i=1;i<=size;i++) scanf("%d",&A[i]);

  buildMaxHeap();

  for(i=1;i<=size;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 2556
#include <stdio.h>

int main(void){

	int s = 100000;
	int i, n;

	scanf("%d",&n);
	for(i=1; i<=n; i++){
		s = s * 1.05;
		if(s % 1000 != 0){
			s = (s/1000 + 1) * 1000;
		}
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 1748
#include<stdio.h>

int main(void){
    int N, a, b, c;//a:100の位　b:10の位　c:1の位
    
    scanf("%d",&N);
    a = N / 100;
    b = (N /10) - (a * 10);
    c = N % 10;

    if(a== 7 || b == 7 || c == 7){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1624
n = int(input())
As = list(map(int, input().split()))
M = [-1]*n
p, q = 0, 1
for i in range(n+1):
  A = As[i]
  A = A-1
  if not(M[A] < 0):
    p, q = M[A], i
    break
  M[A] = i
#print(p, q)

MAX = 200000
MOD = 1000000007
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD
def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD

for k in range(1, n+2):
  # C_{n+1}_k-C_{n-1+p-q}_{k-1}
  r1 = COM(n+1, k)
  r2 = COM(n+p-q, k-1)
  r = (r1-r2)%MOD
  print(r)


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

#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> v(n);
    set<int> st;
    for(int i=0; i<n; ++i) {
        int a;
        cin >> a;
        if(st.find(a)!=st.end()) st.erase(a);
        else st.insert(a);
    }
    cout << st.size() << endl;
    return 0;
}



Measured memory_bytes: 5760
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include <string>
using namespace std;
int main()
{
    int N,M;
    string a,b;
    string c;
    cin>>a;
    for(int i=0;i<a.length();i++)
    printf("x");
    return 0;
}


Measured memory_bytes: 256
def line_input(f, type):
    return f(map(type, input().split(" ")))

n, m = line_input(tuple, int)

if n == 1 and m == 1:
    ans = 1

elif n == 1:
    ans = m - 2

elif m == 1:
    ans = n - 2

else:
    ans = (n - 2) * (m - 2)

print(ans)

Measured memory_bytes: 3060
/*---------------------------*\
____________Mari000____________         
________Mostafa  Shehab________    
\*---------------------------*/

#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
typedef long long ll;
typedef long double ld;
//template <class Type>

ll power(ll x,ll y,ll p);
int Bit(ll x);
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}

const int N=1e5 + 5;
char arr[N];

int n,m,z;
int i,j;

int main(){
	scanf("%d%d%d",&n,&m,&z);
	if(abs(n-m)<=abs(n-z))
		puts("A");
	else
		puts("B");


	

}










ll power(ll x,ll y,ll p){ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
    while (y > 0){ 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;
    }
    return res; 
}


int Bit(ll x){
	if(!x)
		return 0;
	return 1+Bit(x>>1);
}


















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

int main() {

  string S;
  cin >> S;

  for(int i = 0;i < S.size();i++) {
    if(S[i] == '?') S[i] = 'D';
  }

  cout << S << endl;
  
  

}


Measured memory_bytes: 3740
//
// Created by 10034 on 2020/7/29.
//

#include <iostream>
#include <cstring>
using namespace std;
const int mod=1e9+7,N=1000100;
char s[N];
typedef long long LL;
int qmi(int a,int b){
    int res=1;
    while(b){
        if(b&1) res=(LL)res*a%mod;
        b>>=1;
        a=(LL)a*a%mod;
    }
    return res;
}
int fac[N*2];
int C(int a,int b){
//    cout<<fac[a]<<" "<<qmi(fac[a-b],mod-2)<<" "<<qmi(fac[b],mod-2)<<endl;
    return (LL)fac[a]*qmi(fac[a-b],mod-2)%mod*qmi(fac[b],mod-2)%mod;
}
int main(){
    fac[0]=1;
    for(int i=1;i<N*2;++i){
        fac[i]=(LL)fac[i-1]*i%mod;
    }
    int n,m;
    cin>>m;
    cin>>s;
    int res=0;
    n=strlen(s);
    for(int i=0;i<=m;++i){
        res=(LL)(res+(LL)qmi(26,i)*C(n+m-i-1,n-1)%mod*qmi(25,m-i)%mod)%mod;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 11980
#include <bits/stdc++.h>
using namespace std;
int num[1000];
int main()
{
	string a;
	cin>>a;
	if(a[0]==a[1]&&a[1]==a[2]) puts("Yes");else
	if(a[1]==a[2]&&a[2]==a[3]) puts("Yes");else
	puts("No");
	return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        w: Chars,
    }

    let mut alpha: Vec<usize> = vec![0;26];
    for i in 0..w.len() {
        alpha[w[i] as usize - 'a' as usize] += 1;
    }

    for i in alpha {
        if i%2==0 {
            continue;
        } else {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void print_preorder(const vector<pair<int, int> >& nodes, const int r){
  //cout << '?' << endl;
  if(r<0) return;
  //cout << '?' << endl;
  cout << ' ' << r;
  print_preorder(nodes, nodes[r].first);
  print_preorder(nodes, nodes[r].second);
}

void print_inorder(const vector<pair<int, int> >& nodes, const int r){
  if(r<0) return;
  print_inorder(nodes, nodes[r].first);
  cout << ' ' << r;
  print_inorder(nodes, nodes[r].second);
}
  

void print_postorder(const vector<pair<int, int> >& nodes, const int r){
  if(r<0) return;  
  print_postorder(nodes, nodes[r].first);
  print_postorder(nodes, nodes[r].second);
  cout << ' ' << r;
}

int main(){
  std::ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<pair<int, int> > nodes(n);
  vector<bool> is_root(n,true);

  for(int i=0; i<nodes.size(); ++i){
    int j; cin >> j;
    auto& v = nodes[j];
    
    cin >> v.first;
    cin >> v.second;
    if(v.first >= 0)  is_root[v.first]  = false;
    if(v.second >= 0) is_root[v.second] = false;
  }

  // cout << "---" << endl;
  // for(auto v : nodes){
  //   cout << v.first << ' ' << v.second << endl;
  // }
  // cout << "---" << endl;

  const int r =
    (nodes.size() > 0) ? 
    find(is_root.begin(), is_root.end(), true)
    - is_root.begin() : -1;

  //cout << '?' << endl;
  
  // Preorder
  cout << "Preorder" << endl;
  print_preorder(nodes, r); cout << endl;
  cout << "Inorder" << endl;
  print_inorder(nodes, r); cout << endl;
  cout << "Postorder" << endl;
  print_postorder(nodes, r); cout << endl;
  
  
  
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

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


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

map<int,int> mp[20];
int now[20];
int t;
int cnt =0;

void dfs(int i)
{
    if(i == t+1){
        for(int i = 1;i <= t;++i){
            if(now[i] == 1){
                for(auto it : mp[i]){
                    if(now[it.first] != it.second){
                        return ;
                    }
                }
            }
        }
        int tmp = 0;
        for(int i = 1;i <= t;++i) if(now[i] == 1) tmp++;
        cnt = max(tmp,cnt);
        return ;
    }
    now[i] = 1;
    dfs(i+1);
    now[i] = -1;
    dfs(i+1);
}

int main()
{
    cin>>t;
    for(int j = 1;j <=t;++j){
        int a;
        cin>>a;
        for(int i = 1;i <= a;++i){
            int x,y;
            cin>>x>>y;
            if(y == 1)mp[j][x] = y;
            else mp[j][x] = -1;
        }
    }
    dfs(1);
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	
	double A, B;
	scanf("%lf%lf", &A, &B);
	if (A > B) {
		printf("GREATER");
	}
	else if (A < B) {
		printf("LESS");
	}
	else {
		printf("EQUAL");
	}



	return 0;

}

Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n,m;
    cin >> n >> m;
    VI x(m),y(m);
    REP(i,m){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }

    VI vi(n,1);
    vector<bool> vb(n,false);
    vb[0]=true;

    REP(i,m){
        if (vb[x[i]]){
            if (vi[x[i]]==1){
                vb[x[i]]=false;
            }
            vb[y[i]]=true;
        }
        vi[x[i]]--;
        vi[y[i]]++;
    }

    int ans = 0;
    REP(i,n){
        if (vb[i] && vi[i]>0){
            ans++;
        }
    }

    cout << ans << ENDL;
    
    return 0;
}

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

int i, a, b, c = -1;

int main() {
    cin >> a >> b;

    for(i = 1; i < 3000; i++)
        if(floor(0.08*i) == a && floor(0.1*i) == b) {
            c = i;
            break;
        }
    cout << c;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
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; }
typedef long long ll;

int main() {
    int N;
    string S;
    cin >> N >> S;
    int res = 0;

    for (int i = 0; i < 1000; i++) {
        int c[3] = {i / 100, (i / 10) % 10, i % 10};
        int f = 0;
        for (int j = 0; j < N; j++) {
            if (S[j] == ('0' + c[f])) f++;
            if (f == 3) break;
        }
        if (f == 3) res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
/* 
 * Created by solzard on 2020-03-05.
 * B - Bingo
 */
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

bool IsBingo(int player) {
  std::unordered_set<int> winnable_conditions
      {0b111000000, 0b000111000, 0b000000111, 0b100100100, 0b010010010, 0b001001001, 0b100010001, 0b001010100};
  for (const auto &condition : winnable_conditions) {
    if ((player & condition) == condition) return true;
  }
  return false;
}

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

  std::vector<int> sheet(9);
  std::unordered_set<int> bingo;
  int n, b;
  rep(i, 9) {
    std::cin >> sheet[i];
  }
  std::cin >> n;
  rep(i, n) {
    std::cin >> b;
    bingo.emplace(b);
  }
  int player = 0;
  rep(i, 9) {
    if (bingo.find(sheet[i]) != std::end(bingo)) {
      player |= 1 << i;
    }
  }
  std::cout << (IsBingo(player) ? "Yes" : "No") << "\n";
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	if (a > b || a != b && n == 1)cout << 0 << endl;
	else if (n == 1 && a == b)cout << 1 << endl;
	else {
		ll lb = b - a;
		lb *= (n - 2LL);
		cout << lb + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3604
/* 解答時間→ : */
#include <algorithm>	//sort, binary_search等々
#include <functional>	//greaterなど
#include <iomanip>		//各種マニピュレータ
#include <iostream>		//基本入出力
#include <string>		//文字列処理
#include <vector>		//STLの花形vector
using namespace std;

//中央はboard[99][99]
const int size = 199;
int board_height[size][size], board_num[size][size];
const int dice_[6][6] =	{{0,4,2,5,3,0},
						 {3,0,6,1,0,4},
						 {5,1,0,0,6,2},
						 {2,6,0,0,1,5},
						 {4,0,1,6,0,3},
						 {0,3,5,2,4,0}};

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0)
			break;
		for(int i = 0; i < size; i++){
			for(int j = 0; j < size; j++){
				board_height[i][j] = 0;
				board_num[i][j] = 0;
			}
		}
		for(int i = 0; i < n; i++){
			int t1, t2;	//上面,前面
			cin >> t1 >> t2;
			int posx = 99, posy = 99;
			while(1){
				//dice[0-3]=前、右、後、左面
				int dice[4], dice_flg[4] = {0};
				//前面はposy-1、右面はposx+1とする
				dice[0] = t2;
				if(board_height[posx][posy] > board_height[posx][posy-1])
					dice_flg[0] = 1;
				dice[2] = 7 - dice[0];
				if(board_height[posx][posy] > board_height[posx][posy+1])
					dice_flg[2] = 1;
				dice[1] = dice_[t1 - 1][t2 - 1];
				if(board_height[posx][posy] > board_height[posx+1][posy])
					dice_flg[1] = 1;
				dice[3] = 7 - dice[1];
				if(board_height[posx][posy] > board_height[posx-1][posy])
					dice_flg[3] = 1;
				int movedir = -1, movemax = 0;
				for(int j = 0; j < 4; j++){
					if((dice_flg[j] == 1)&&(movemax<dice[j])){
						movedir = j;
						movemax = dice[j];
					}
				}
				//移動
				//
				//　d0=t2
				//d3t1d1
				//　d2　
				if(movemax >= 4){
					switch(movedir){
						case 0:
							--posy;
							t2 = t1;
							t1 = dice[2];
							break;
						case 1:
							++posx;
							t1 = dice[3];
							break;
						case 2:
							++posy;
							t2 = 7 - t1;
							t1 = dice[0];
							break;
						case 3:
							--posx;
							t1 = dice[1];
							break;
					}
				}else{
					board_num[posx][posy] = t1;
					++board_height[posx][posy];
					break;
				}
			}
		}
		int count[6] = {0};
		for(int i = 0; i < size; i++){
			for(int j = 0; j < size; j++){
				if(board_num[i][j] != 0)
					count[board_num[i][j] - 1]++;
			}
		}
		for(int i = 0; i < 6; i++){
			cout <<  count[i];
			if(i != 5)
				cout << " ";
			else
				cout << "\n";
		}
	}
	cout << flush;

	return 0;
}

Measured memory_bytes: 1472
N = list(map(int, list(input())))

flag = False

for i in range(2):
	for j in range(2):
		for k in range(2):
			B = (N[1] if i == 0 else -N[1])
			C = (N[2] if j == 0 else -N[2])
			D = (N[3] if k == 0 else -N[3])
			if sum([N[0], B, C, D]) == 7:
				print(N[0],end='')
				if i == 0:
					print('+',end='')
				else:
					print('-',end='')
				print(N[1],end='')
				if j == 0:
					print('+',end='')
				else:
					print('-',end='')
				print(N[2],end='')
				if k == 0:
					print('+',end='')
				else:
					print('-',end='')
				print(N[3],end='')
				print('=7')
				flag = True
				break
		if flag:
			break
	if flag:
		break

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
    int n,a;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i){
        a = i;
        if(a % 3 == 0){
            printf(" %d",i);
        }else {
            while(10 < a){
                if(a % 10 ==3){
                    printf(" %d",i);
                    break;
                }else {
                    if(a / 10 ==3){
                    printf(" %d",i);
                    break;
                    }
                a = a/10;
                }
            }
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2060
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;
typedef pair<int,int>P;

int main(){

  int n,m;cin>>n>>m;
  int p[m+10],y[m+10];
  P num[m+10];
  rep(i,0,m){
    cin>>p[i]>>y[i];
    num[i].second=p[i];
    num[i].first=y[i];
  }

  sort(num,num+m);

  vector<int>v[100010];

  rep(i,0,m){
    v[num[i].second-1].push_back(num[i].first);
  }

  string digit[]={"00000","0000","000","00","0",""};

  rep(i,0,m){
    string s=to_string(p[i]);

    int index=upper_bound(v[p[i]-1].begin(),v[p[i]-1].end(),y[i])-v[p[i]-1].begin();
    string t=to_string(index);

    cout<<digit[s.size()-1]<<p[i]<<digit[t.size()-1]<<index<<endl;
  }

  return 0;
}


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

using namespace std;

typedef long long int lli;

int n, s;

bool used[10];

lli dfs(bool used[10], int now, int sum)
{
	if (sum > s) return 0;

	if (now == n) {
		if (sum == s) return 1;
		return 0;
	}

	int res = 0;

	for (int i = 0; i < 10; ++i) {
		if (used[i]) continue;
		used[i] = true;
		res += dfs(used, now + 1, sum + i);
		used[i] = false;
	}

	return res;
}

lli fact(int n)
{
	if (n <= 1) return 1;
	return n * fact(n - 1);
}

int main()
{
	while (cin >> n >> s, n || s) {
		memset(used, false, sizeof(used));
		cout << dfs(used, 0, 0) / fact(n) << endl;
	}
}

Measured memory_bytes: 1156
a = list(map(int,input().split()))

while sum(a) != 0:
	aa = [[1 for i in range(a[0])] for j in range(a[1])]
	for i in range(a[2]):
		k = list(map(int,input().split()))
		if k[0] == 1:
			if a[0] //2 >= k[1]:
				for m in range(a[1]):
					for n in range(k[1]):
						aa[m][2*k[1] - n - 1] += aa[m][n]
					aa[m] = aa[m][k[1]:]
				a[0] -= k[1]
			else:
				for m in range(a[1]):
					for n in range(a[0] - k[1]):
						aa[m][a[0]-(2*(a[0]-k[1])-n-1)-1] += aa[m][a[0]-n-1]
					aa[m].reverse()
					aa[m] = aa[m][a[0]-k[1]:]
				a[0]-=(a[0]-k[1])
		elif k[0] == 2:
			if a[1] // 2 >= k[1]:
				for n in range(a[0]):
					for m in range(k[1]):
						aa[2*k[1]-m-1][n] += aa[m][n]
				a[1] -= k[1]
				aa = aa[k[1]:]
			else:
				for n in range(a[0]):
					for m in range(a[1]-k[1]):
						aa[a[1]-(2*(a[1]-k[1])-m-1)-1][n] += aa[a[1]-m-1][n]
				aa.reverse()
				aa = aa[a[1]-k[1]:]
				a[1] -= (a[1] - k[1])

	for i in range(a[3]):
		p = list(map(int,input().split()))
		print(aa[p[1]][p[0]])
	a = list(map(int,input().split()))


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

int main(){
  int r, g, b;
  cin >> r >> g >> b;
  if((r * 100 + g * 10 + b) % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
num = int(input())
value = input().split()
cost = input().split()

value, cost = [int(i) for i in value], [int(i) for i in cost]

ans_arr = sorted([value[i]-cost[i] for i in range(num)])[::-1]
ans = 0
for i in ans_arr:
  if i>0:
    ans += i

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
    int n;
    cin>>n;
    while(n>=0){
        if(n%4==0){cout<<"Yes"<<endl;return 0;}
        n-=7;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
char a[100005];
int f=0;
void read(int &x){
	int f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){
		if(s=='-')f=-1;s=getchar();
	}
	while(s>='0'&&s<='9'){
		x=x*10+s-'0';s=getchar();
	}
	x*=f;
}
void print(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) print(x/10);
	putchar(x%10+'0');
}
int main() {
	cin>>s;
	for(int i=0; i<s.size(); i++) {
		if(s[i]!='B') a[++f]=s[i];
		else {
			f--;
			if(f<0) f=0;
		}
	}
	for(int i=1; i<=f; i++) cout<<a[i];
	cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
/* clang-format off */
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll n, a;
  cin >> n >> a;
  vector<ll> x(n);
  REP(i, n) { cin >> x.at(i); }
  sort(ALL(x));
  ll g = abs(x.at(0) - a);
  REP(i, n - 1) { g = __gcd(g, x.at(i + 1) - x.at(i)); }
  cout << g << "\n";
  return 0;
}


Measured memory_bytes: 1024
n = gets.to_i

backet = {}
n.times do |i|
  backet[i+1] = gets.to_i
end

idx = 1
count = 0
loop do
  idx = backet[idx]
  count += 1
  break if idx == 2

  if count > n
    count = -1
    break
  end
end

puts count


Measured memory_bytes: 8572
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
using namespace std;

int n;
int top[100], bottom[100];
int dp[100][100];

int solve(int l, int r) {
    if (0 <= dp[l][r]) return dp[l][r];
    if (l == r) return 0;
    int ret = INT_MAX;
    for (int i=l+1; i<=r; ++i) {
        ret = min(ret, solve(l,i-1) + solve(i,r) + top[l] * bottom[i-1] * top[i] * bottom[r]);
    }
    return dp[l][r] = ret;
}

int main() {
    memset(dp, -1, sizeof dp);
    cin >> n;
    for (int i=0; i<n; ++i) {
        cin >> top[i] >> bottom[i];
    }
    cout << solve(0, n-1) << endl;
    return 0;
}

Measured memory_bytes: 1208
def solve(N, X):
    ans = 0
    for a in range(1, N+1):
        for b in range(a+1, N+1):
            c = X - a - b
            if b < c <= N:
                ans += 1
    return ans


while True:
    N, X = tuple(map(int, input().split()))
    if N == 0 and X == 0:
        break
    print(solve(N, X))


Measured memory_bytes: 5600