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

using namespace std;

int main() {
	int n;
	cin >> n;
	
	if (n % 1000 == 0) cout << 0 << '\n';
	else if (n < 1000) {
		cout << 1000 - n << '\n';
	}
	else cout << 1000 - (n % 1000) << '\n';
	
	return 0;
}

Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(isr);
		Main me = new Main();
		System.out.println(me.fact(Integer.parseInt(in.readLine())));
	}
	private long fact(long n){
		if(n==0)
			return 1;
		else
			return n*fact(n-1);
	}
}

Measured memory_bytes: 16860
#include <algorithm>
#include <cstdio>

using namespace std ;

typedef long long LL ;
const int N=2e6+10 ;

int to[N<<1] , nxt[N<<1] , dir[N<<1] , lst[N] ;
inline void add ( int u , int v )
{
	static int cnt=0 ;
	++cnt,to[cnt]=v,nxt[cnt]=lst[u],dir[cnt]=1,lst[u]=cnt,
	++cnt,to[cnt]=u,nxt[cnt]=lst[v],dir[cnt]=-1,lst[v]=cnt;
}

int n , m ;

int d[N] , c[N] , siz , fail , edge , cnt[3] ;
inline void Dfs ( int x )
{
	int i , y , C ;
	d[x]=1,++siz,cnt[c[x]]++;
	for ( i=lst[x],y=to[i] ; i ; i=nxt[i],y=to[i] )
	{
		C=(c[x]+3+dir[i])%3,
		edge+=(dir[i]==1);
		if ( !d[y] )
			c[y]=C,Dfs(y);
		else
			if ( c[y]!=C ) fail=1;
	}
	return ;
}

int main ()
{
	int i , u , v ;
	scanf("%d%d",&n,&m);
	for ( i=1 ; i<=m ; i++ )
		scanf("%d%d",&u,&v),
		add(u,v);
	LL res=0 ;
	for ( i=1 ; i<=n ; i++ )
		if ( !d[i] )
		{
			edge=siz=fail=cnt[0]=cnt[1]=cnt[2]=0;
			Dfs(i);
			if ( fail )
				res+=(LL)(siz)*(LL)(siz);
			else if ( !cnt[0] || !cnt[1] || !cnt[2] )
				res+=(LL)(edge);
			else
				res+=(LL)(cnt[0])*(LL)(cnt[1])
					+(LL)(cnt[1])*(LL)(cnt[2])
					+(LL)(cnt[2])*(LL)(cnt[0]);
		}
	printf("%lld\n",res);
	return 0 ;
}


Measured memory_bytes: 16768
#include<iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main()
{
	long double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	long double res = sqrtl((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	cout << fixed << setprecision(8) << res << endl;
	return 0;
}


Measured memory_bytes: 3296
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    ll p[a],q[b],r[c];
    for (ll i = 0; i < a; i++) {
        cin >> p[i];
    }
    for (ll i = 0; i < b; i++) {
        cin >> q[i];
    }
    for (ll i = 0; i < c; i++) {
        cin >> r[i];
    }
    sort(p,p+a);
    sort(q,q+b);
    sort(r,r+c);
    ll ret = 0;
    for (ll i = a - 1; i >= a - x; i--){
        ret += p[i];
    }
    for (ll i = b - 1; i >= b - y; i--){
        ret += q[i];
    }
    ll count = c - 1;
    ll marka = a - x;
    ll markb = b - y;
    while (count >= 0) {
        if ((p[marka] < q[markb])||(markb >= b)) {
            if (p[marka] >= r[count]) {
                break;
            }
            else {
                ret = ret - p[marka] + r[count];
                marka++;
                count--;
            }
        }
        else {
           if (q[markb] >= r[count]) {
                break;
            }
            else {
                ret = ret - q[markb] + r[count];
                markb++;
                count--;
            } 
        }
    }
    cout << ret;
    return 0;
}

Measured memory_bytes: 2560
program sequence_sum
  implicit none
  integer(8) :: n, num, k, tmp, a(0:100000) = 0
  integer :: x, m, b(0:100000) = 0, period, offset, rem, i
  read(*,*) n, x, m
  tmp = m
  if (n <= 2 * m) then
    num = x
    do k = 2, n
      x = mod(int(x, 8) * x, tmp)
      if (x == 0) exit
      num = num + x
    end do
    write(*,'(i0)') num
    stop
  end if
  a(1) = x
  b(x) = 1
  do i = 2, m + 1
    x = mod(int(x, 8) * x, tmp)
    a(i) = a(i - 1) + x
    if (b(x) > 0) then
      offset = b(x) - 1
      period = i - b(x)
      exit
    end if
    b(x) = i
  end do
  num = (n - offset) / period
  rem = int(n - offset - num * period)
  write(*,'(i0)') a(offset) + (a(offset + period) - a(offset)) * num + &
    a(offset + rem) - a(offset)
end program sequence_sum

Measured memory_bytes: 3516
// template ver2.02

// include
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>

using namespace std;

// conversion
inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

// typedef
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

// util
#define MP make_pair
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define CLR(a) memset((a), 0 , sizeof(a))
template<class T, class C> inline bool in(T e, C c) {return c.find(e) != c.end();}
template<class T> inline bool in(T x, T a, T b) {return a <= x && x < b;}

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define RREP(i, n) RFOR(i, 0, n)

// IO
#define PRA(a, n) cout << a[0]; FOR(itr, 1, n) {cout << " " << a[itr];} cout << endl;
#define PRF(x, w) cout << setprecision((w)); cout << setiosflags(ios::fixed); cout << (x) << endl;

// constant
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = (int)1e9;
const int DI[] = {0, 1, 0, -1};
const int DJ[] = {1, 0, -1, 0};

// debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DUMPA(a, n) cerr << #a << " = {" << a[0]; FOR(itr, 1, n) { cout << ", " << a[itr]; } cerr << "}" << endl;
#define DUMPAA(a, n, m) REP(itr, n) {REP(jtr, m) {cout << a[itr][jtr] << " ";} cout << endl;}

// template end

const int N_MAX = 10000;

const int DICE[7][4] =
{
    {},
    {2, 3, 5, 4},
    {6, 3, 1, 4},
    {2, 6, 5, 1},
    {2, 1, 5, 6},
    {1, 3, 6, 4},
    {5, 3, 2, 4},                    
};

int n;
string cmds[N_MAX];

void init()
{
}

void solve()
{
    int ans = 1;
    int top = 1;
    int front = 2;
    REP(i, n) {
        int east;
        REP(j, 4) if (DICE[top][j] == front) east = DICE[top][(j + 1) % 4];
        int west = 7 - east;
        int bottom = 7 - top;
        int back = 7 - front;
        if (cmds[i] == "North") {
            top = front;
            front = bottom;
        }
        if (cmds[i] == "East") {
            top = west;
        }
        if (cmds[i] == "West") {
            top = east;
        }
        if (cmds[i] == "South") {
            front = top;   
            top = back;            
        }
        if (cmds[i] == "Right") {
            front = east;
        }
        if (cmds[i] == "Left") {
            front = west;
        }
        ans += top;
    }
    cout << ans << endl;
}

int main()
{
    init();
    while (cin >> n, n) {
        REP(i, n) cin >> cmds[i];
        solve();        
    }
    return 0;
}


Measured memory_bytes: 1520
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
int main(){
    ll N;
    cin >> N;
    vector<ll> num(N);
    rep(i,N)cin >> num[i];
    ll memo[100005];
    memo[0] = 0;
    memo[1] = abs(num[0] - num[1]);
    for(ll i = 2;i<N;i++){
        memo[i] = min(memo[i - 1] + abs(num[i] - num[i - 1]),memo[i - 2] + abs(num[i] - num[i - 2]));
    }
    cout << memo[N - 1] << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int n,k,s,aa[220000],cnt=0,cnta=INF;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>aa[i];
        if(cnta>aa[i]){
            cnta=aa[i];
            cnt++;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 1792
def permutation(lst):
    if len(lst) == 0:
        return []
    if len(lst) == 1:
        return [lst]
    res = []
    for i in range(len(lst)):
       m = lst[i]
       remLst = lst[:i] + lst[i+1:]
       for p in permutation(remLst):
           res.append([m] + p)
    return res

dist = lambda x1, y1, x2, y2 : ((x1-x2)**2 + (y1-y2)**2)**.5
n = int(input())
d = [[0] * n for _ in range(n)]
pnts = []
for _ in range(n):
	x, y = map(int, input().split())
	pnts.append((x, y))
for i in range(n):
	for j in range(n):
		d[i][j] = d[j][i] = dist(pnts[i][0], pnts[i][1], pnts[j][0], pnts[j][1])
paths = permutation(list(range(n)))
res = 0
for path in paths:
    for j in range(n-1):
        res += d[path[j]][path[j+1]]
print(round(res/len(paths), 6))


Measured memory_bytes: 65884
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ll n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	a--;
	b--;
	c--;
	d--;
	string s;
	cin >> s;
	if (c > d){
		ll current = a;
		bool special = true;
		while (current < c && b <= d){
			special = true;
			if (current+1 < n && s[current+1] == '.'){
				if (current+1 == b){
					if (current+2 < n && s[current+2] == '.' && current+2 <= c){}
					else {
						do{
							if (b+1 < n && s[b+1] == '.')b++;
							else if (b+2 < n && s[b+2] == '.')b+=2;
							else {
								cout << "No" << endl;
								return 0;
							}
						} while (b == c && b<=d);
						special = false;
					}
				}
				else {
					special = false;
					current++;
				}
				
			} 
			if (special && current+2 < n && s[current+2] == '.'){
				if (current+2 == b){
					do {
						if (b+1 < n &&s[b+1] == '.'){b++;current += 2;}
						else if (b+2 < n &&s[b+2] == '.'){b+=2;current +=2;}
						else {
							cout << "No" << endl;
							return 0;
						}
					} while (b == c && b<=d);	
				}
				else current+=2;
				special = false;
			}  
			if (special){
				cout << "No" << endl;
				return 0;
			}
		}
		if (b > d || c != current){
			cout << "No" << endl;
			return 0;
		}
		current = b;
		while (current < d){
			if (current+1 < n && s[current+1] == '.')current++;
			else if (current+2 < n && s[current+2] == '.')current+=2;
			else {
				cout << "No" << endl;
				return 0;
			}
		}
		if (current != d){
			cout << "No" << endl;
			return 0;
		}
	} else {
		ll current = b;
		bool special = true;
		while (current < d && a <= c){
			special = true;
			if (s[current+1] == '.'){
				if (current+1 == a){
					if (current+2 < n && s[current+2] == '.' && current+2 <= d){}
					else {
						do{
							if (s[a+1] == '.')a++;
							else if (s[a+2] == '.')a+=2;
							else {
								cout << "No" << endl;
								return 0;
							}
						} while (a == d && a<=c);
						current++; special = false;
					}
				}
				else {current++; special = false;}
			} 
			if (special && s[current+2] == '.'){
				if (current+2 == a){
					do {
						if (s[a+1] == '.')a++;
						else if (s[a+2] == '.')a+=2;
						else {
							cout << "No" << endl;
							return 0;
						}
					} while (a == d && a <= c);	
				}
				current+=2;
				special = false;
			}
			if (special){
				cout << "No" << endl;
				return 0;
			}  
		}
		if (a > c || d != current){
			cout << "No" << endl;
			return 0;
		}
		current = a;
		while (current < c){
			if (s[current+1] == '.')current++;
			else if (s[current+2] == '.')current+=2;
			else {
				cout << "No" << endl;
				return 0;
			}
		}
		if (current != c){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	cin >> n;
	
}

// 15 1 3 15 13
// ...#.#...#.#...
// x.y#.#...#.#...
// x..#.#.y.#.#...

Measured memory_bytes: 640
import bisect

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()

a2=[]
for i1 in range(N):
    a2.append(bisect.bisect_left(C,B[i1]+1))

a2c=[0]*(N+1)
for i1 in range(N-1,-1,-1):
    a2c[i1] = a2c[i1+1] + N - a2[i1]

ans=0
for i0 in range(N):
    a1 = bisect.bisect_left(B,A[i0]+1)
    ans += a2c[a1]
print(ans)


Measured memory_bytes: 107876
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (((x - r) >= 0) && ((x + r) <= W) && ((y + r) <= H) && (y - r) >= 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}



Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int x;
    cin >> x;
    if(x == 0){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn main() {
    let data:i64 = read();
    println!("{:?}",i64::pow(data,3));
}



Measured memory_bytes: 5028
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let s = a.iter().sum::<usize>();
    if s >= h {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main()
{
	ll x;
	cin>>x;
	ll t=x;
	ll c1=0,c2=0;
	c1=t/500;
	t=x-500*c1;
	c2=t/5;
	cout<<1000*c1+5*c2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=4e3+10,mod=1e9+7;
int fac[maxn],ifac[maxn];
inline int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=(ll)res*x%mod;
		x=(ll)x*x%mod;
		y>>=1;
	}
	return res;
}
inline int C(int n,int m){
	if(m>n || n<0 || m<0) return 0;
	return (ll)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
inline void init(int n){
	fac[0]=1;
	REP(i,1,n) fac[i]=(ll)i*fac[i-1]%mod;
	ifac[n]=ksm(fac[n],mod-2);
	DREP(i,n,1) ifac[i-1]=(ll)i*ifac[i]%mod;
}
inline int solve(int n,int m){
	return (C(n+m,m)-C(n+m,m-1)+mod)%mod;
}
int main(){
	int n=read(),m=read();
	init(maxn-10);
	printf("%lld\n",(ll)(solve(n,m-1)-solve(n,m-2)+mod)*ksm(2,max(n-m-1,0))%mod);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100100100;//10^17
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

int gcd(int a, int b){
    if(a % b == 0) return b;
    else return (gcd(b, a%b));
}



int main(){
    int N;
    cin >> N;
    vector<int> c(N), s(N), f(N);
    rep(i, N - 1)cin >> c[i] >> s[i] >> f[i];
    rep(i, N){
        ll ans = 0;
        for(int j = i; j < N - 1; j++){//jからj+1への時間を逐次足していく
            if(ans < s[j]) ans = s[j] + c[j];//１本目に乗れる
            else{
                if(ans % f[j] != 0){//ansに最も近いansに書き換え
                    ans += f[j] - (ans % f[j]);
                }
                ans += c[j];
            }
            // cout << "j: " << j << " ans: " << ans << endl;
        }
        cout << ans << endl;
    }
} 

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

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

const int mod = 1e9+7;
const int inf = 2e18;

int32_t main()
{	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int a;
	cin>>a;
	cout<<a+a*a+a*a*a<<'\n';

	return 0;
}	

Measured memory_bytes: 3652
using System;

namespace D___Lamp
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var H = read[0];
            var W = read[1];
            
            string[] map = new string[H];
            for(int i = 0 ; i < H ; i++) map[i] = Console.ReadLine();
            
            var lightupLeft = new int[H,W];
            var lightupRight = new int[H,W];
            var lightupAbove = new int[H,W];
            var lightupBelow = new int[H,W];

            for(int h = 0 ; h < H ; h++)
            {
                lightupLeft[h,0] = map[h][0] == '#' ? 0 : 1;
                for(int w = 1 ; w < W ; w++)
                {
                    lightupLeft[h,w] = map[h][w] == '#' ? 0 : lightupLeft[h,w-1] + 1;
                }
            }

            for(int h = 0 ; h < H ; h++)
            {
                lightupRight[h,W-1] = map[h][W-1] == '#' ? 0 : 1;
                for(int w = W-2 ; w >= 0 ; w--)
                {
                    lightupRight[h,w] = map[h][w] == '#' ? 0 : lightupRight[h,w+1] + 1;
                }
            }

            for(int w = 0 ; w < W ; w++)
            {
                lightupAbove[0,w] = map[0][w] == '#' ? 0 : 1;
                for(int h = 1 ; h < H ; h++)
                {
                    lightupAbove[h,w] = map[h][w] == '#' ? 0 : lightupAbove[h-1,w] + 1;
                }
            }

            for(int w = 0 ; w < W ; w++)
            {
                lightupBelow[H-1,w] = map[H-1][w] == '#' ? 0 : 1;
                for(int h = H-2 ; h >= 0 ; h--)
                {
                    lightupBelow[h,w] = map[h][w] == '#' ? 0 : lightupBelow[h+1,w] + 1;
                }
            }

            var lightupTotal = new int[H,W];
            var lightupMax = 0;
            for(int h = 0 ; h < H ; h++)
            {
                for(int w = 0 ; w < W ; w++)
                {
                    lightupTotal[h,w] = lightupLeft[h,w] + lightupRight[h,w] +lightupAbove[h,w] + lightupBelow[h,w];
                    lightupMax = Math.Max(lightupMax,lightupTotal[h,w]);
                }
            }

            Console.WriteLine(lightupMax-3);
        }
    }
}


Measured memory_bytes: 105792
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;

int main(void){
    int a,b;
    cin>>a>>b;
    cout<<(a+b)%24<<endl;
    
    return 0;
}


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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int nax = 2222;

vector<int> a;
int dp[nax][nax][2];
int n,z,w;

int calc(int idx,int other,int turn){
	if(idx == n)return abs(a[idx-1] - a[other]);
	int &ret = dp[idx][other][turn];
	if(ret != -1)return ret;
	if(turn == 1){
		if(idx == n-1)ret = calc(idx+1,other,turn);
		else ret = min(calc(idx+1,other,turn) , calc(idx+1,idx,!turn));
	}else{
		ret = max(calc(idx+1,other,turn) , calc(idx+1,idx,!turn));
	}
	// cout << turn << ' ' << idx << ' ' << ret << endl;
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
	#endif
	cin>>n>>z>>w;
	n+=2;
	a.resize(n);
	a[0] = z;a[1] = w;
	for(int i=2;i<n;i++){
		cin>>a[i];
	}

	memset(dp,-1,sizeof(dp));
	cout << calc(2,1,0) << '\n';
}

Measured memory_bytes: 39040
let parent i = int_of_float (floor (float_of_int i) /. 2.)

let left i = 2*i

let right i = 2*i + 1

let () =
  let h = read_int () in
  let t = Array.make (h + 1) 0 in
  for i = 1 to h do
    t.(i) <- Scanf.scanf "%d " (fun i -> i);
  done;
  for i = 1 to h do
    Printf.printf "node %d: key = %d, " i t.(i);
    if parent i >= 1 then Printf.printf "parent key = %d, " t.(parent i);
    if left i <= h then Printf.printf "left key = %d, " t.(left i);
    if right i <= h then Printf.printf "right key = %d, " t.(right i);
    print_newline ();
  done

Measured memory_bytes: 2496
import math

def main():
    a,b,h,m = map(int,input().split())
    d = 0
    ans = 0

    ad = 360 * h / 12 + 30 * m / 60
    bd = 360 * m / 60

    if ad < bd:
        d = bd - ad
    else:
        d = ad - bd
    
    if d > 180:
        d = 360 - d

    cosc = math.cos(math.radians(d))
    ans = math.sqrt( a**2 + b**2 - 2*a*b*cosc)
    
    print(ans)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
using pll = pair<long,long>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back

int main() {
  int n,cnt=0;
  cin>>n;
  for(int a=1;a<=n-1;a++) {
    cnt+=(n-1)/a;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 3568
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF = 100100100;
using namespace std;

ll sol(ll x) {
    int a = x % 4;
    switch (a) {
    case 0:
        return x;
    case 1:
        return 1;
    case 2:
        return x + 1;
    case 3:
        return 0;
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll A, B;
    cin >> A >> B;

    cout << (sol(B) ^ sol(A - 1)) << endl;

    return 0;
}

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

int n;
double x[100],y[100];

double distance(double p){
double sum=0;
for(int i=0;i<n;i++){
double w=abs(x[i]-y[i]);
sum+=pow(w,p);
}
return pow(sum,1/p);
}

int main(){
cout<<fixed<<setprecision(12);
cin>>n;
for(int i=0;i<n;i++){
cin>>x[i];
}
for(int i=0;i<n;i++){
cin>>y[i];
}
cout<<distance(1)<<endl;
cout<<distance(2)<<endl;
cout<<distance(3)<<endl;

double mx=0;
for(int i=0;i<n;i++){
mx=max(mx,abs(x[i]-y[i]));
}
cout<<mx;
return 0;
}


Measured memory_bytes: 3448
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0,(i##_len)=(n);(i)<(i##_len);(i)++)
#define rep2(i,a,b) for(ll (i)=(a),(i##_len)=(b);(i)<=(i##_len);(i++))
#define rrep(i,n) ll(i)=(n);ll now=-1;while((i)--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)<<"\n"
#define vll vector<ll>
#define pb push_back
using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> T abs(T x){return max(x,-x);}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm(T m,T n) {return m*n/gcd(m,n);}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm<T>(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
template<class T> T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here

void solve(string S){
    sort(all(S));
    S.erase(unique(all(S)), S.end());
    reverse(all(S));

    rep(i, 26) {
        if (S != "" && S.at(int(S.size()) - 1) == char('a' + i)) {
            S.pop_back();
            continue;
        }
        cout << char('a' + i) << "\n";
        return;
    }
    cout << "None\n";
}

int main() {
    string S;
    cin >> S;
    solve(S);
    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    bool is_next = false;
    if(s.length() % 2 != 0)
    {
        cout << "No" << endl;
        return 0;
    }
    
    for(char &x: s)
    {
        if(is_next)
        {
            if(x != 'i')
            {
                cout << "No" << endl;
                return 0;
            }
            is_next = false;
        }
        else
        {
            if(x == 'h') is_next = true;
            else
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#list(map(int,input().split()))
n = int(input())
www = list(map(int,input().split()))
ans = 100000
for i in range(n-1):
  s_l = sum(www[:(i+1)])
  s_r = sum(www[(i+1):])
  ans = min(ans, abs(s_l-s_r))
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int mxn=1e5+5,mod=1e9+7;

int dp[mxn][2],n,x,y;

vector<int>adj[mxn];

bool been[mxn];

void dfs(int );

int main()
{
    cin>>n;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs(1);

    cout<<(dp[1][0]+dp[1][1])%mod;


    return 0;
}
void dfs(int u)
{
    been[u]=1;
    ll yup=1,nah=1;

    for(auto v:adj[u])
    {
        if(!been[v])
        {
            dfs(v);
            yup=yup*dp[v][0]%mod;
            nah=nah*(1ll*dp[v][1]+dp[v][0])%mod;
        }
    }
    if(adj[u].size() == 1 && u!=1)
    {
        dp[u][0]=1;
        dp[u][1]=1;
    }
    else
    {
        dp[u][0]=nah;
        dp[u][1]=yup;
    }
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int N=200;
char s[N], t[N];
int main() {
    int i, j, n;
    scanf("%d%s%s", &n, s, t);
    for(i=0; i<n; i++) {
        for(j=i; j<n; j++) if(s[j]!=t[j-i]) break;
        if(j==n) break;
    }
    printf("%d\n", n+i);
    return 0;
}

Measured memory_bytes: 256
def solve n,s,a
  if n == 1 then
    if s>=a and s<=9 then
      return 1
    else
      return 0
    end
  end
  result = 0
  (a..s).each do |i| 
    result += solve(n-1, s-i, i+1)
  end

  return result
end

while line = STDIN.gets
  if line == "0 0\n" then break end
  n, s = line.chomp.split(' ').map { |item| item.to_i }
  puts solve(n,s,0)
end

Measured memory_bytes: 8720
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;




long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}

bool c;
int N,C,H,R,G, M,K,W,a[10],ltl[26],g,k,X,ans,con,iti[100000];
string S,s,SB,SA,SS,b;

int main() {
	cin >> R;
	cin >> G;



cout <<(2*G)-R<<endl;
	return 0;
}




Measured memory_bytes: 256
#include<iostream>

using namespace std;
int N;
int p[100005];
int main(void) {

	cin >> N;
	int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp; p[i] = tmp;
	}

	int count2 = 0;
	int state = 0;

	for (int i = 1; i <= N; i++) {
		if (p[i] == i && state == 1) { state = 0; count2++; }
		else if (p[i] == i) { state = 1; }
		else { state = 0; }
	}

	int count = 0;

	for (int i = 1; i <= N; i++) {
		if (p[i] == i) { count++; }
	}

	int count1 = count - 2 * count2;

	//cout << "count1= " << count1 << "  count2= " << count2 << endl;
	cout << count1 + count2 << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 768
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Gary Ye
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextInt();
            long a = in.nextInt();
            long b = in.nextInt();

            if (a == b) {
                out.println(1);
            } else if (n == 1 || a > b) {
                out.println(0);
            } else {
                long smallest = a * (n - 1) + b;
                long largest = a + (n - 1) * b;
                long result = largest - smallest + 1;
                out.println(result);
            }
        }

    }
}



Measured memory_bytes: 23508
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[] P = new int[N];
			int[] Q = new int[N];
			StringBuffer p = new StringBuffer();
			StringBuffer q = new StringBuffer();
			StringBuffer start = new StringBuffer();
			for(int i = 1;i<=N;i++) {
				start.append(i);
			}
			
			for(int i =0;i<N;i++) {
				P[i] = scan.nextInt();
				p.append(P[i]);
			}
			
			for(int i =0;i<N;i++) {
				Q[i] = scan.nextInt();
				q.append(Q[i]);
			}
			
			String s = start.toString();
			String A =p.toString(); 
			String B =q.toString(); 
			int a=0;
			int b=0;
			int count = 1;
			while (true) {
				 // System.out.println(s);
				  if(s.equals(A))a=count;
				  if(s.equals(B))b=count;
				  s = nextPermutation(s);
				  count++;
				  if (s.equals("Final")) break;
				  }
			
			System.out.println(Math.abs(a-b));
			
			
			
			
			
			
		}
		
		
	}
	
	
	
	private static String nextPermutation (String s) {
		/*入力した文字列(数列、英語小文字、英語大文字)の次の順番を返すメソッド
		 * String s = "ABC";
		 * while (true) {
		 * System.out.println(s);
		 * s = nextPermutation(s);
		 * if (s.equals("Final")) break;
		 * }
		 * とmainメソッド に書けばN文字の文字列をN!文小さい物から順に列挙することができる*/

		ArrayList<Character> list = new ArrayList<>();
		for (int i=0; i<s.length(); i++) list.add(s.charAt(i));

		int pivotPos = -1;
		char pivot = 0;
		for (int i=list.size()-2; i>=0; i--) {
			if (list.get(i) < list.get(i+1)) {
				pivotPos = i;
				pivot = list.get(i);
				break;
			}
		}

		if (pivotPos==-1 && pivot==0) return "Final";

		int L = pivotPos+1, R = list.size()-1;
		int minPos = -1;
		char min = Character.MAX_VALUE;
		for (int i=R; i>=L; i--) {
			if (pivot < list.get(i)) {
				if (list.get(i) < min) {
					min = list.get(i);
					minPos = i;
				}
			}
		}

		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));

		StringBuilder sb = new StringBuilder();
		for (int i=0; i<list.size(); i++) sb.append(list.get(i));

		return sb.toString();

	}
	
	
	
	

}


Measured memory_bytes: 46200
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define rep(i, x, y) for (int i = (x); i <= (y); i ++)
using namespace std;

const int N = 100010;
int n;
int a[N];
map<int, int> M;
map<int, bool> vis;

int main()
{
	scanf("%d", &n);
	rep(i, 1, n){
		scanf("%d", &a[i]);
		M[a[i]] ++;
	} int ans = 0;
	rep(i, 1, n){
		if (vis.count(a[i])) continue;
		if (M[a[i]] >= a[i]){
			ans += M[a[i]] - a[i];
		} else {
			ans += M[a[i]];
		}
		vis[a[i]] = 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
//万合以致，向阳而生——背叛时代，忠于时间//
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(register int i=0; i<n; i++)
#define Forn(i, n) for(register int i=1; i<=n; i++)
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define mid l+r>>1
#define lid id<<1|1
#define rid (id<<1)+2
#define lson lid, l, mid
#define rson rid, mid, r
#define rank Rank

inline int in()
{
    char c=getchar();
    int neg=1, x=0;
    while(!isdigit(c)) (c=='-')?neg=-1, c=getchar():c=getchar();
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
    return neg*x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=1e4+5;
const int MAX2=2005;
const int n=32;

typedef bitset<1000005> bs;

bitset<MAX> dp[MAX2];
bs State;
int N, K, st[MAX*100];
char tmp[MAX];
string dat[MAX2], S, ret;

struct Seg_Bitset
{
    bs val[n*2+10];
    Seg_Bitset() { forn(i, n*2+10) val[i].reset(); }
    inline void print(bs&t)
    {
        forn(i, S.size()) cout<<t[i];
        puts("");    
    }
    inline int query(int id, int l, int r)
    {
//        cout<<id<<" "<<(char)(l+'a')<<" "<<(char)(r+'a')<<endl;
//        print(val[id]);
//        print(State);
        if(l+1==r) 
        {
            State&=val[id];
            return l;//id l+n-1
        }
        if((val[lid]&State).none()) return query(rson);
        return query(lson); 
    }
}seg;

int main()
{
    N=in(), K=in();
    forn(i, N) scanf("%s", tmp), dat[i]=tmp, st[i]=S.size(), S+=dat[i];
    forn(i, S.size()) seg.val[S[i]-'a'+n-1][i]=1;
    for(int id=n-2; id>-1; id--)
        seg.val[id] |=(seg.val[lid]|seg.val[rid]);
    State[0]=1;
    dp[N][0]=1;
    st[N]=S.size();
    for(int i=N-1; i>-1; i--)
        dp[i]=(dp[i+1]|(dp[i+1]<<dat[i].size()));
    forn(i, K)
    {
        forn(j, N) if(State[st[j]]) State[st[j+1]]=1;
/*        if(i==7)
        for(int j=0; j<S.size(); j++)
            cout<<State[j];*/
        forn(j, N) 
        {
            int tk=K-i-dat[j].size();
            if(tk<0) State[st[j]]=0;
            else if(!dp[j+1][tk]) State[st[j]]=0;
        }
//        puts("");
//        cout<<i<<endl;
        int tmp=seg.query(0, 0, n);
//        cout<<i<<endl;
//        cout<<tmp<<endl; 
        ret+=tmp+'a';
        State<<=1;
//        cout<<i<<":\n";
//        forn(j, S.size()) if(State[j]) cout<<j<<" ";
//        puts("");
    }
    puts(ret.c_str());
    return 0;
}

Measured memory_bytes: 15936
#include <iostream>

using namespace std;

int main(){
    string S;
    cin>>S;

    int len = S.length();
    int start_idx=0;
    int sub_len=0;
    for(int i=0; i<len; ++i){
        if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
            int j=i+1;
            for(; j<len;){
                if(S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T'){
                    ++j;
                }else{
                    break;
                }
            }
            if(sub_len < j-i){
                sub_len = j-i;
                start_idx = i;
            }
        }
    }
    cout<<sub_len<<endl;

    return 0;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var abc string
	fmt.Scan(&abc)
	if strings.Contains(abc, "a") && strings.Contains(abc, "b") && strings.Contains(abc, "c") {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
using namespace std;
const int N = 1e5+5;
void fast(){std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
int n,a=1,ans=0;
int main()
{
	fast();
	cin>>n;
	while(n--)
	{
		int x;
		cin>>x;
		if(x==a)
		{
			a++;
		}
		else
			ans++;
	}
	if(a==1)ans=-1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;

void solve_main()
{
	QWORD A, B;

	cin >> A >> B;

	if ((A + B) % 2 != 0) {
		cout << "IMPOSSIBLE" << endl;
	} else {
		cout << (A + B) / 2 << endl;
	}

}

int main()
{
#ifdef FOR_IDE
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
#endif

	solve_main();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int a, b;
    cin >> a >> b;
    if (a*b %2 ==0) OUT("Even")
    else OUT("Odd")

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

struct Dice
{
  int label[7];
  void Roll(std::string dir)
  {
    std::string tmp;
    for(int i=0; i<dir.length(); ++i){
      if( dir[i] == 'E' ){
        tmp = label[1];
        label[1] = label[4];
        label[4] = label[6];
        label[6] = label[3];
        label[3] = tmp[0];
      }else if( dir[i] == 'N' ){
        tmp = label[1];
        label[1] = label[2];
        label[2] = label[6];
        label[6] = label[5];
        label[5] = tmp[0];
      }else if( dir[i] == 'S' ){
        tmp = label[1];
        label[1] = label[5];
        label[5] = label[6];
        label[6] = label[2];
        label[2] = tmp[0];
      }else if( dir[i] == 'W' ){
        tmp = label[1];
        label[1] = label[3];
        label[3] = label[6];
        label[6] = label[4];
        label[4] = tmp[0];
      }else if( dir[i] == 'R' ){
        tmp = label[2];
        label[2] = label[3];
        label[3] = label[5];
        label[5] = label[4];
        label[4] = tmp[0];
      }
    }
  }
  int top(){
    return label[1];
  }
  int front(){
    return label[2];
  }
  int right(){
    return label[3];
  }
  int left(){
    return label[4];
  }
  int back(){
    return label[5];
  }
  int bottom(){
    return label[6];
  }
};


int main()
{
  Dice d;
  for(int i=1; i<=6; ++i){ std::cin >> d.label[i]; }

  int n;
  std::cin >> n;

  while( n-- ){
    int top, front;
    std::cin >> top >> front;

    if(d.left() == top) d.Roll("E");
    if(d.right() == top) d.Roll("W");
    while(d.top() !=  top) d.Roll("N");
    while(d.front() != front) d.Roll("R");

    std::cout << d.right() << std::endl;
  }


  return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
long long n , x[300000] , jenis;
map<long long , int>m;
vector<int>v;
bool cek;
//m.count(x[i]) buat cari apakah ada x[i] di map nya
int main(){
	cin >> n;
	for(int i = 1 ; i <= n ; i++){
		cin >> x[i];
		if(m[x[i]] == 0) {
      jenis++;
      v.pb(x[i]);
    }
		m[x[i]]++;
		if(x[i] != 0)cek = true;
	}
	sort(v.begin() , v.end());
  if(!cek){
    cout << "Yes" << endl; 
    return 0;
  }
	if(v.size() == 3){
		if(m[v[0]] == n/3 && m[v[1]] == n/3 && m[v[2]] == n/3){
			if((v[0]^v[1]^v[2])== 0){
				cout << "Yes" << endl;
        return 0;
			}	
		}	
	}
	else if(v.size() == 2){
		if(v[0] == 0 && m[v[1]] == 2*n/3){
			cout << "Yes" << endl;
      return 0;
		}
	}
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 8972
#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n){
        rep(i, n){
            int year, month, day, days = 0;
            cin >> year >> month >> day;
            while(++days){
                day++;
                if(year % 3 == 0 && day == 21){
                    month++; day = 1;
                }else if(year % 3 != 0 && month % 2 == 1 && day == 21){
                    month++; day = 1;
                }else if(year % 3 != 0 && month % 2 == 0 && day == 20){
                    month++; day = 1;
                }
                if(month == 11){
                    month = 1; year++;
                }
                if(year == 1000) break;
            }
            cout << days << endl;
        }
    }
}

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

int main(){
  int n,m = 0;

  cin >> n;
  if((n/100)==1){
    m++;
  }
  if((n-(n/100)*100)/10==1){
    m++;
  }
  if((n-(n/10)*10)==1){
    m++;
  }
  
  cout << m << endl;
}

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

void solve(long long N, long long A, long long B){
  long long acc = 0;

  REP(i, N) {
    long long current = 0;
    long long tmp = (i+1);
    while(tmp > 0) {
      current += (tmp % 10);
      tmp /= 10;
    }

    if(current >= A && current <= B) acc += (i+1);
  }

  cout << acc << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const ll MOD = 1e9 + 7;

bool isevenstring(string s)
{
    if (s.size() % 2 == 1)
    {
        return false;
    }
    int half = s.size() / 2;
    rep(i, half)
    {
        if (s[i] != s[half + i])
        {
            return false;
        }
    }
    return true;
}

int main(int argc, char const *argv[])
{

    string s;
    cin >> s;
    rep(i, 1, s.size())
    {
        cerr << s.substr(0, s.size() - i) << endl;
        if (isevenstring(s.substr(0, s.size() - i)))
        {
            cout << s.size() - i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import string
S = list(input())
K = int(input())
dic = {}
letters=string.ascii_lowercase[::-1]
for id,i in enumerate(letters):
  dic[i] = id + 1
while K > 0:
  SS = S
  for i in range(len(S)):
    if S[i] == "a":
      pass
    else:
      if K >= dic[S[i]]:
        K -= dic[S[i]]
        S[i] = "a"
      else:
        pass
  if SS == S:
    break
if K > 0:
  K %= 26
  V = 0
  if dic[S[-1]] > K:
    V = dic[S[-1]] - K
  else:
    V = (dic[S[-1]] + K) % 26 + 2
  for k,v in dic.items():
    if v == V:
      S[-1] = k
print(*S,sep="")

Measured memory_bytes: 7484
import math

N = int(input())
plan = [tuple(map(int, input().split())) for _ in range(N-1)] + \
    [(0, 0, 0)]

ans = []
for i in range(N):
    time = 0
    for j in range(i+1, N):
        c, s, f = plan[j-1]
        next_c, next_s, next_f = plan[j]
        if time <= s:
            time = c + s
        else:
            if (time - s) % f == 0:
                time += c
            else:
                time += c + (f - (time - s) % f)
    ans.append(time)


print(*ans, sep='\n')


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

int main()
{
    long long K;
    std::cin >> K;

    // キューに 1~9 までのルンルン数を入れる
    std::queue<long long> que;
    for (int i = 1; i <= 9; i++)
        que.push(i);

    // 下記をK回繰り返す
    // 1. キューからルンルン数を取り出す
    // 2. 取り出した値から新しいルンルン数を生成してキューに入れる
    long long x;
    for (int k = 1; k <= K; k++)
    {
        // ルンルン数をキューから取り出す
        x = que.front();
        que.pop();

        // 新しいルンルン数を追加する
        if (x%10 != 0) que.push(10*x + (x%10) - 1);
        que.push(10*x + (x%10));
        if (x%10 != 9) que.push(10*x + (x%10) + 1);
    }

    std::cout << x << std::endl;

    return 0;
}

Measured memory_bytes: 1792