akhauriyash/Code-Regression huggingface dataset:
function Main (input) {
  const inputValue = input.split(/\s/g)[0];
  const sum = inputValue.split('').map((num) => parseInt(num)).reduce((prev, current) => prev + current, 0);
  const result = parseInt(inputValue) % sum === 0 ? 'Yes' : 'No';
  console.log('%s', result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main () {
vector<int> A = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int K;
cin >> K;

cout << A.at(K-1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f;
const int N=2e5+5;
using namespace std;
int a[N];
int b[N];
int main()
{
    int n;cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i&1) b[1]+=a[i];
        else b[1]-=a[i];
    }
    for(int i=2;i<=n;i++)
    {
        b[i]=(b[i-1]-a[i-1])*(-1)+a[i-1];
    }
    for(int i=1;i<=n;i++) cout<<b[i]<<" ";
    return 0;
}


Measured memory_bytes: 4420
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  //ios::sync_with_stdio(false);
  int h,w,n;
  cin>>h>>w>>n;
  int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
  char mp[30][30];
  char mp2[30][30];
  rep(i,h){
    rep(j,w){
      cin>>mp[i][j];
    }
  }
  rep(i,h){
    rep(j,w-1){
      //cout<<i<<" "<<j<<endl;
      rep(k,h){
	rep(l,w){
	  mp2[k][l]=mp[k][l];
	}
      }
      
      swap(mp2[i][j],mp2[i][j+1]);
      rep(k,h){
	rep(l,w){
	  if(mp2[k][l]=='.'){
	    repn(m,k-1){
	      swap(mp2[m][l],mp2[m+1][l]);
	    }
	  }
	}
      }
      bool flag=true,ans=true;
      while(flag){
	//debug(1);
	flag=false;
	int mp3[30][30]={0};
	rep(k,h){
	  rep(l,w){
	    
	    int cnt=1;
	    while(l+cnt < w &&  mp2[k][l]==mp2[k][l+cnt] && mp2[k][l]!='.'){
	      cnt++;
	    }
	    if(cnt>=n){
	      flag=true;
	      rep(m,cnt){
		mp3[k][l+m]=1;
	      }
	    }
	  }
	}
	rep(k,w){
	  rep(l,h){
	    int cnt=1;
	    while(l+cnt < h &&  mp2[l][k]==mp2[l+cnt][k] && mp2[l][k]!='.'){
	      cnt++;
	    }
	    if(cnt>=n){
	      flag=true;
	      rep(m,cnt){
		mp3[l+m][k]=1;
	      }
	    }
	  }
	}
	rep(k,h){
	  rep(l,w){
	    if(mp3[k][l]==1) mp2[k][l]='.';
	  }
	}
	rep(k,h){
	  rep(l,w){
	    if(mp2[k][l]=='.'){
	      repn(m,k-1){
		swap(mp2[m][l],mp2[m+1][l]);
	      }
	    }
	  }
	}
	/*	rep(k,h){
	  rep(l,w){
	    cout<<mp2[k][l];
	  }
	  cout<<endl;
	  }*/
      }
      rep(k,h){
	rep(l,w){
	  //cout<<mp2[k][l];
	  if(mp2[k][l]!='.') ans=false;
	}
	//	cout<<endl;
      }
      if(ans){cout<<"YES"<<endl;return 0;}
    }
  }
  cout<<"NO"<<endl;

  return 0;
}



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

int main() {
    string s,left,right;
    int a, b;
    while (cin >> s, s != "-") {
        cin >> a;
        for (int i = 0; i < a; i++) {
            cin >> b;
            left = s.substr(0, b);
            right = s.substr(b);
            s = right + left;
        }
        cout << s << endl;
    }
    return 0;
}

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

int main() {
  int n;
  vector<int> a;

  while (cin >> n, n) {
    a.resize(n);
    rep (i, n) cin >> a[i];

    sort(a.begin(), a.end());
    int ans = 1001001001;

    rep (i, n-1) {
      ans = min(ans, a[i+1] - a[i]);
    }

    cout << ans << endl;
  }

  return 0;
}

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

int main() {
  int a,b,c,d;cin>>a>>b>>c>>d;
  cout << min(a,b)+min(c,d) << endl;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    Ds = [NLI() for _ in range(N)]
    D = [x - y for x, y in Ds]
    cnt = 0
    for d in D:
        if d == 0:
            cnt += 1
        else:
            cnt = 0
        if cnt == 3:
            print("Yes")
            exit()
    print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 9268
int main()
{
	int d;
	
	scanf("%d", &d);

	switch (d)
	{
	case 22:
		printf("%s", "Christmas Eve Eve Eve\n");
		break;
	case 23:
		printf("%s", "Christmas Eve Eve\n");
		break;
	case 24:
		printf("%s", "Christmas Eve\n");
		break;
	case 25:
		printf("%s", "Christmas\n");
		break;
	default:
		break;
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int mod = 1'000'000'007, maxn = 100100;
int f[4][maxn], pf[4][maxn];
long long s[maxn], a, b;
int main(){
	int n; scanf("%d %lld %lld", &n, &a, &b);
	for(int i = 1; i <= n; i++) scanf("%lld", s + i);
	for(int j = 0; j < 4; j++) f[j][0] = pf[j][0] = 1;
	s[n + 1] = s[n] + b + a;
	int pta = 0, ptb = 0, upa = 0, upb = 0, pt2a = 0, pt2b = 0;
	for(int i = 1; i <= n; i++){
		while(pta + 1 < i && s[pta + 1] + a <= s[i]) pta++;
		while(ptb + 1 < i && s[ptb + 1] + b <= s[i]) ptb++;
		if(pta == i - 1){
			f[0][i] = f[0][i - 1];
		}
		if(ptb == i - 1){
			f[1][i] = f[1][i - 1];
		}
		if(i > 2 && s[i - 2] + a > s[i - 1]) upa = i - 2;
		if(i > 2 && s[i - 2] + b > s[i - 1]) upb = i - 2;
		auto getSum = [&](int v, int l, int r){
			if(l > r) return 0;
			int rr = pf[v][r];
			if(l) rr += mod - pf[v][l - 1];
			if(rr >= mod) rr -= mod;
			return rr;
		};
		while(pt2a + 1 < i && s[pt2a + 1] + a <= s[i + 1]) pt2a++;
		while(pt2b + 1 < i && s[pt2b + 1] + b <= s[i + 1]) pt2b++;
		if(upa <= pt2b && pta == i - 1) f[2][i] = f[0][min(pt2b + 1, i - 1)];
		if(upb <= pt2a && ptb == i - 1) f[3][i] = f[1][min(pt2a + 1, i - 1)];
		{
			if(upb <= i - 2){
				f[0][i] += getSum(2, upb, min(i - 2, pta));
				if(i > 1 && i < n && s[i - 1] + b <= s[i + 1]) f[2][i] += getSum(2, upb, min(i - 2, pta));
			}
		}
		{
			if(upa <= i - 2){
				f[1][i] += getSum(3, upa, min(i - 2, ptb));
				if(i > 1 && i < n && s[i - 1] + a <= s[i + 1]) f[3][i] += getSum(3, upa, min(i - 2, ptb));
			}
		}
		for(int j = 0; j < 4; j++){
			if(f[j][i] >= mod) f[j][i] -= mod;
			pf[j][i] = pf[j][i - 1] + f[j][i];
			if(pf[j][i] >= mod) pf[j][i] -= mod;
		}
	}	
	int ans = f[1][n] + f[0][n];
	if(ans >= mod) ans -= mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a,b,c) min(a,min(b,c))
typedef long long ll;

void ans(bool qus){
    if (qus == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Ans(bool qust){
    if (qust == true)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

////////////////---START---////////////////

int main(){
    int n;
  	cin>>n;
    int count = 0;
    rep(i,n){
        string s = to_string(i+1);
      	
        if(s.size() % 2 == 1){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
SB = sorted(L, key=lambda x:x[1])
flg = 0
cnt = 0
for i in range(N):
    cnt += SB[i][0]
    if SB[i][1] < cnt:
        flg = 1
        break
if flg == 0:
    print('Yes')
else:
    print('No')


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

int count;

void InsertionSort(int *A, int N, int G)
{
	for(int i = G; i < N; ++i)
	{
		int v = A[i], j = i - G;
		while(j >= 0 && A[j] > v)
		{
			A[j + G] = A[j];
			j -= G;
			++count;
		}
		A[j + G] = v;
	}
}

void ShellSort(int *A, int N)
{
	int m = 0, G[20];
	count = 0;
	
	int temp = N;
	while(temp != 0)
	{
		G[m++] = temp / 2;
		temp /= 2;
	}
	
	for(int i = 0; i < m; ++i)
	{
		InsertionSort(A, N, G[i]);
	}
	
	cout << m << endl;
	for(int i = 0; i < m; ++i)
	{
		if(i != 0)
		{
			cout << " ";
		}
		cout << G[i];
	}
	cout << endl << count << endl;
	for(int i = 0; i < N; ++i)
	{
		cout << A[i] << endl;
	}
}

int N, A[1000000]; 
	
int main()
{

	cin >> N;
	for(int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	
	ShellSort(A, N);

    return 0;
}



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


#define ll long long
int main() {



	ll n, k, x,y;
	
	cin>>n>>k>>x>>y;
	ll ky=(n-k);

	if (k<n) cout<<x*k+y*ky<<endl;
	else cout<<x*n;






	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
int main()
{
    char a[10],b[10],c[10];
    scanf("%s %s %s",a,b,c);
    int la,lb,lc;
    la=strlen(a);
    lb=strlen(b);
    lc=strlen(c);
    if(a[la-1]!=b[0])
    {
        printf("NO\n");
        return 0;
    }
    if(b[lb-1]!=c[0])
    {
        printf("NO\n");
        return 0;
    }
    printf("YES\n");
    return 0;
}


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

int main() {

    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int cnt = 0;

    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                
                if (x == ((i * 500) + (j * 100) + (k * 50)) )
                    cnt ++;
                
            }
        }
    }

    cout << cnt << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <cstdio>

typedef long long int lli;
int N, K;
lli arr[5005];
int frontMake[5005][5005];		//frontMake[i][sum] : can make "sum" using arr[1] ~ arr[i]
int backMake[5005][5005];		//backMake[i][sum   : can make "sum" using arr[i] ~ arr[N]
int pSum[5005];

int main(){
	int ans=0, a, b;
	scanf("%d %d", &N, &K);
	for(int i=1; i<=N; ++i)
		scanf("%lld", arr+i);
	++frontMake[0][0];
	for(int i=1; i<=N; ++i){
		for(int sum=0; sum <= 5000; ++sum){
			if(frontMake[i-1][sum]){
				++frontMake[i][sum];
			    if(sum + arr[i] <= 5000)
					++frontMake[i][sum + arr[i]];
			}
		}
	}
	++backMake[N+1][0];
	for(int i=N; i>0; --i){
		for(int sum=0; sum <= 5000; ++sum){
			if(backMake[i+1][sum]){
				++backMake[i][sum];
				if(sum + arr[i] <= 5000)
					++backMake[i][sum + arr[i]];
			}
		}
	}
	for(int i=1; i<=N; ++i){
		if(arr[i] >= K){
			++ans;
		} else{
			pSum[0] = backMake[i+1][0];
			for(int j=1; j<=5000; ++j)
				pSum[j] = pSum[j-1] + backMake[i+1][j];
			for(int j=0; j<=K; ++j){
				a = K-j-1>=0 ? pSum[K-j-1] : 0;
				b = K-j-arr[i]-1>=0 ? pSum[K-j-arr[i]-1] : 0;
				if(frontMake[i-1][j] && a != b){
					++ans;
					break;
				}
			}
		}
	}
	printf("%d\n", N - ans);
}


Measured memory_bytes: 195840
#include<iostream>
#include<stack>
#include<cstdlib>
using namespace std;

int main()
{
    stack<int> S;
    int a, b, x;
    string s;
    
    while( cin >> s)                     
    {
        if( s[0] == '+'){                  
            a = S.top() ; S.pop() ;
            b = S.top() ; S.pop() ;
            S.push(a + b); 
        }else if( s[0] == '-' ){
            b = S.top() ; S.pop() ;
            a = S.top() ; S.pop() ;
            S.push(a - b); 
        }else if( s[0] == '*'){
            a = S.top() ; S.pop() ;
            b = S.top() ;S.pop() ;
            S.push(a * b); 
        }else{                                                             
            S.push(atoi(s.c_str()));       
        }
    }
    
    cout << S.top() <<endl;
    
    return 0;
}


Measured memory_bytes: 3216
use proconio::input;

fn main() {
    input! {
        n: usize,
        x: usize,
    };
    let mut l = vec![];
    l.push((1_usize, 1_usize));
    for i in 1..=n {
        l.push((l[i - 1].0 * 2 + 3, l[i - 1].1 * 2 + 1));
    }

    let mut count = 0;
    let mut level = n;
    let mut offset = 0;
    loop {
        let m = l[level].0 / 2 + 1;
        if x == 1 + offset {
            count += if level == 0 { 1 } else { 0 };
            break;
        } else if x == l[level].0 + offset {
            count += l[level].1;
            break;
        } else if x == m + offset {
            count += l[level - 1].1 + 1;
            break;
        } else if m + offset > x {
            offset += 1;
            level -= 1;
        } else if x > m + offset {
            count += l[level - 1].1 + 1;
            offset += m;
            level -= 1;
        }
    }
    let ans = count;
    println!("{}", ans);
}


Measured memory_bytes: 2120
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
p = 0
for i in range(n):
    if b[i] - a[i] > 0:
        p += a[i]
        b[i] -= a[i]
        if a[i+1] - b[i] >= 0:
            p += b[i] 
            a[i+1] -= b[i]
        else:
            p += a[i+1]
            a[i+1] = 0
    else:
        p += b[i]
print(p)
    

Measured memory_bytes: 18624
x = gets.chomp.split(" ").map(&:to_i)
y = x.sort
z = x.sort.reverse

st = y.pop
sa = 0
while y != []
    sa += (st - y[-1]).abs
    st = y.pop
end
ss = z.pop
sb = 0
while z != []
    sb += (ss - z[-1]).abs
    ss = z.pop
end
puts [sa,sb].min

Measured memory_bytes: 14344
#define SORT(v) sort(v.begin(), v.end())
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <algorithm>
#include <cstdarg>
#include <cstdio>
#include <numeric>

// #include "ane.cpp"

#define INF (int)1e9
#define INFLL (long long)1e18
#define NMAX 200
#define MMAX 200
#define MOD 100000
using namespace std;

// コメントアウトするとdb_printf()を実行しない
#define DEBUG

//
//  ライブラリ
//

// よく使う型のエイリアス
typedef pair<int, int> p;
typedef long long ll;

// よく使う定数[配列]
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// デバッグ用printf
void db_printf(const char* format, ...){
    #ifndef DEBUG
    return;
    #endif
    va_list arg;
    va_start(arg, format);
    vprintf(format, arg);  // コンソールに出力
    va_end(arg);
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// Union-Find Tree
class UnionFindTree{
    struct node{
        int par;
    };
    std::vector<node> T;

    public:
    void init(int num){
        T.resize(num+1);    // ignore T[0]
        for (int i = 1; i <= num; ++i)
        {
            T[i].par = i;
        }
    }
    void unite(int x, int y){
        T[find(y)].par = find(x);
    }
    int find(int x){
        if (T[x].par == x) return x;
        else return T[x].par = find(T[x].par);
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

//
// ライブラリ終了
//


ll N,M,K,A,B,C,D,E;
int dp[NMAX][MMAX] = {};

ll ans = 0;

void solve(){
    // 解答アルゴリズム
}
void debug(){
    // デバッグ用出力
}
void answer(){
    // 解答出力
    printf("%lld\n", (N + 1) * N / 2);
}
int main(int argc, char const *argv[])
{
    // 入力の読み込み，番兵法

    // Fill(dp, -1);
    scanf("%lld", &N);
    solve();
    #ifdef DEBUG
    debug();
    #endif
    answer();

    return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
grid = []
for i in range(h):
    grid.append(list(map(int,input().split())))
ans = []
for i in range(h):
    for j in range(w):
        if j == w-1:
            if grid[i][j] % 2 == 1 and i != h-1:
                grid[i+1][j] += 1
                ans.append([i+1,j+1,i+2,j+1])
        elif grid[i][j] % 2 == 1:
            grid[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])
print(len(ans))
for i in range(len(ans)):
    print(*ans[i])





Measured memory_bytes: 30296
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int m[10][10];
int dx[]={1,0,0,-1};
int dy[]={0,1,-1,0};
struct wolf{
	int m[10][10];
};
int ret=0;
int a,b,c;
void solve(int p,wolf t){
	if(!p){
		int V=0;
		int S=c;
		queue<pair<int,int> > Q;
		Q.push(make_pair(1,1));
		t.m[1][1]=-1;
		while(Q.size()){
			int row=Q.front().first;
			int col=Q.front().second;
			Q.pop();
			V++;
			for(int j=0;j<4;j++){
				if(S==t.m[row+dx[j]][col+dy[j]]){
					t.m[row+dx[j]][col+dy[j]]=-1;
					Q.push(make_pair(row+dx[j],col+dy[j]));
				}
			}
		}
		ret=max(ret,V);
	}else{
		for(int i=1;i<=6;i++){
			if(t.m[1][1]==i)continue;
			wolf u=t;
			int S=t.m[1][1];
			queue<pair<int,int> > Q;
			Q.push(make_pair(1,1));
			u.m[1][1]=i;
			while(Q.size()){
				int row=Q.front().first;
				int col=Q.front().second;
				Q.pop();
				for(int j=0;j<4;j++){
					if(S==u.m[row+dx[j]][col+dy[j]]){
						u.m[row+dx[j]][col+dy[j]]=i;
						Q.push(make_pair(row+dx[j],col+dy[j]));
					}
				}
			}
			solve(p-1,u);
		}
	}
}
int main(){
	wolf W;
	while(scanf("%d%d%d",&a,&b,&c),a){
		ret=0;
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)W.m[i][j]=0;
		for(int i=0;i<a;i++)
			for(int j=0;j<b;j++)
				scanf("%d",&(W.m[i+1][j+1]));
		
		solve(5,W);
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;

int main(){
    string S,T;
    cin>>S>>T;
    int ans=0;
    for(int i=0;i<3;i++){
        if(S.at(i)==T.at(i)) ans++;
    }
    cout<<ans<<endl;
}



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

using namespace std;

int main()
{
  string W;
  cin >> W;
  for(int i = 'a'; i <= 'z'; i++) {
    if(count(begin(W), end(W), i) % 2 == 1) {
      cout << "No" << endl;
      return (0);
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  string n;
  cin >> n;
  int l = n.size();
  int sum = 0;
  rep(i, l){
    sum += n[i]-'0';
  }
  if (sum % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3736
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var s = ReadLine();
		WriteLine(s[1] == s[2] && (s[0] == s[1] || s[2] == s[3]) ? "Yes" : "No");
	}
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long ll;

int main() {
	int n, x;
	while ( cin >> n >> x, n || x ) {
		int ans = 0;
		for (int a = 1; a <= n; ++a)
			for (int b = a+1; b <= n; ++b)
				for (int c = b+1; c <= n; ++c)
					if (a + b + c == x) ++ans;

		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
using System;
using System.IO;
//x=ai*(p+0.5) aiは偶数なので ai=2ai'とすると 
//x=ai' * (2p+1) つまり入力を2で割ったものに、(2p+1)奇数をかけることになる f(x)=xを何回2で割り切れるか、とすると
//f(x)=f(ai')
//したがってこの問題の条件は
//・aiが偶数
//・全てのiについてf(ai')が同じ
//まとめると(x/2^n)=(ai'/2^n)*(2p+1)のうちそれぞれが奇数になる
//これを　x'=ai''*(2p+1) とすると
//lcm(ai'')=L←奇数 最小公倍数とすると
//x'=L*奇数の組
//その奇数の組を2Lでわって切り上げ

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] In = Console.ReadLine().Split(' ');
            int n = int.Parse(In[0]);
            int m = int.Parse(In[1]);
            string[] In2 = Console.ReadLine().Split(' ');
            var A = new int[n];
            for(int i=0; i < n; i++)
            {
                A[i] = int.Parse(In2[i]);
            }
            //a->a'
            for (int i = 0; i < n; i++)
            {
                A[i]/=2;
            }
            //a'->a''
            int t = F(A[0]);
            bool CanDivedeSameTimes = true;
            for(int i=0; i < n; i++)
            {
                if (F(A[i]) != t) CanDivedeSameTimes = false;
                A[i] >>= t;//A[i]/=2^t;
            }
            if (CanDivedeSameTimes)
            {
                m >>= t;
                long l = 1;
                bool IsOverFlow = false;
                for(int i = 0; i < n; i++)
                {
                    l = Lcm(l, A[i]);
                    if (l > m) { IsOverFlow = true; }
                }
                if (IsOverFlow) Console.WriteLine(0);
                else
                {
                    m /= (int)l;
                    int ans = (m + 1) / 2;
                    Console.WriteLine(ans);
                }
            }
            else
            {
                Console.WriteLine(0);
            }
        }
        static int F(int x)
        {//2で何回われるか
            int res = 0;
            while (x % 2 == 0)
            {
                x /= 2;
                res++;
            }
            return res;
        }
        static long Gcd(long a,  long b)
        {
            if (b == 0) return a;
            return Gcd(b,a%b);
        }
        static long Lcm(long a,long b)
        {
            return a / Gcd(a, b) * b;
        }
    }
}


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

int main() {
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	vector<int>xs(n);
	for (int i = 0; i < n; i++)cin >> xs.at(i);
	xs.push_back(x);
	vector<int>ys(m);
	for (int i = 0; i < m; i++)cin >> ys.at(i);
	ys.push_back(y);
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	if (xs.at(n) < ys.at(0))cout << "No War" << endl;
	else cout << "War" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    string s;
    cin >> s;
    ll n = s.size();
    ll cnt1 = 0, cnt2 = 0;
    string s1, s2;
    REP(i, n){
        if(i%2 ==0){
            s1 += '0';
            s2 += '1';
        }
        else{
            s1 += '1';
            s2 += '0';
        }
    }
    //cout << s1 << " " << s2 << endl;
    REP(i, n){
        if(s[i] != s1[i]) cnt1++;
        if(s[i] != s2[i]) cnt2++;
    }
    cout << min(cnt1, cnt2) << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 720
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

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

Measured memory_bytes: 3552
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
bool cmp(int e,int d){
	return e>d;
}
int x,y,a,b,c;
int red[100003],green[100003],white[300009];
int main(){
	scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	for(int i=0;i<a;i++){
		scanf("%d",&red[i]);
	}
	for(int i=0;i<b;i++){
		scanf("%d",&green[i]);
	}
	for(int i=0;i<c;i++){
		scanf("%d",&white[i]);
	}
	int u=x-1,v=y-1,w=0;
	sort(red,red+a,cmp);
	sort(green,green+b,cmp);
	for(int i=0;i<x;i++){
		white[c+i]=red[i];
	}
	for(int i=0;i<y;i++){
		white[c+x+i]=green[i];
	}
	ll ans=0;
	sort(white,white+c+x+y,cmp);
	for(int i=0;i<x+y;i++){
		ans+=white[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int[] array = new int[6];
		for(int i = 0;i < 6;i++) {
			array[i] = sc.nextInt();
		}
		int dif = array[4] - array[0];
		if(dif <= array[5]) {
			System.out.println("Yay!");
		}else {
			System.out.println(":(");
		}
	}

}


Measured memory_bytes: 23252
// Contest.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include"iostream"
#include"string"
#include"vector"
#include"algorithm"

using namespace std;


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

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

	if (e - a <= k) {
		cout << "Yay!"<< endl;
	}

	else {


		cout <<":(" << endl;
	}
	return 0;
}




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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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 (b<a) { a=b; return true; } return false; }

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

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

vector<pair<ll,ll>> factorize(ll n) {
    vector<pair<ll,ll>> res;
    for (ll i = 2; i*i <= n; ++i) {
        if (n%i) continue;
        res.emplace_back(i,0);
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n,1);
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll a,b;
    cin>>a>>b;
    ll g = __gcd(a,b);
    VP vp = factorize(g);
    ll ans = vp.size()+1;
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
	ll a;
	double b;
	cin >> a >> b;
	ll B = b * 100 + 0.1;
	//ll ans = a * b+0.000001;
   //ll B = b;
	cout << a * B/100 << endl;
	return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
int main(){
long N; cin >> N;
long k=N-1; string ans="";
ans=(char)('a'+k%26); k/=26;
while(k){ k--; ans=(char)('a'+k%26)+ans; k/=26; }
cout << ans << "\n";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	char a,b; cin>>a>>b;
	if(a==b) cout<<'H'<<endl;
	else cout<<'D'<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);


int main() {
    int n;
    cin >> n;
    vector<ll> arr(n, 0);
    const ll min_val = ll(INT_MIN) * ll(10000);
    vector<vector<ll>> dp(n, vector<ll>(n, min_val));
    for(auto& val: arr)
        cin >> val;
    auto dfs = [&] (auto& self, int head, int tail) -> ll {
        if (dp[head][tail] != min_val) {
            return dp[head][tail];
        }
        if (head == tail) {
            return arr[head];
        }
        dp[head][tail] = max(arr[head] - self(self, head+1, tail),
                              arr[tail] - self(self, head, tail-1));
        return dp[head][tail];
    };
    cout << dfs(dfs, 0, n-1) << endl;
    return 0;
}




Measured memory_bytes: 72960
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <stdio.h>
using namespace std;

typedef long long ll;

int main()
{
    int N,M;
    cin >> N >> M;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    vector<pair<ll, ll> > pairs(M);
    for(int i=0; i<M; i++){
        int b, c;
        cin >> b >> c;
        pairs[i]=make_pair(c, b);
    }
    sort(A.begin(), A.end());
    sort(pairs.begin(), pairs.end());
    reverse(pairs.begin(), pairs.end());

    int cnt=0;
    ll ans=0;
    int i;
    for(i=0; i<N; i++){
        bool flag=false;
        int j;
        for(j=cnt; j<M; j++){
            if(A[i]<pairs[j].first && pairs[j].second>0){
                pairs[j].second-=1;
                ans+=pairs[j].first;
                flag=true;
                break;
            }
        }
        cnt=j;
        if(flag==false) ans+=A[i];
        if(cnt==M){
            cnt=i;
            break;
        }
    }
    if(i==N) cnt=N;
    for(int i=cnt+1; i<N; i++){
        ans+=A[i];
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int a[125252];

int lop[6];

int main(){
    scanf("%d",&n);
    REP(i,n)scanf("%d",a+i);
    // all 0
    if(count(a,a+n,0)==n){
        puts("Yes"); return 0;
    }
    // fibo
    if(n%3!=0){
        puts("No"); return 0;
    }
    set<int> S;
    REP(i,n)S.insert(a[i]);
    if(S.size() > 3 || S.size() == 1){
        puts("No"); return 0;
    }
    if(S.size() == 2){
        int x = *S.begin(); 
        int y = *S.rbegin();
        int ca=0, cb=0;
        REP(i,n)(a[i]==x ? ca : cb)++;
        if(ca*2==cb)swap(x,y),swap(ca,cb);
        if(ca != 2*cb){
            puts("No"); return 0;
        }
        REP(i,6)lop[i] = i%3==0 ? y : x;
    }else{
        int p[3];
        int it = 0;
        for(int x : S)p[it++]=x;
        for(int x : S)if(count(a,a+n,x)!=n/3){
            puts("No"); return 0;
        }
        REP(i,6)lop[i] = p[i%3];
    }
    REP(i,3){
        int xxx = 0;
        REP(j,3)xxx ^= lop[i+j];
        if(xxx!=0){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
using namespace std;
int main(){
 int n;
 cin>>n;
 for(int i=1;i<=n;i++){
 
    if(i%3==0){
       cout<<" "<<i;
     }
   else {
       int x=i;
       while(x>0){
           if(x%10==3){
               cout<<" "<<i;
               break;
           }
           x/=10;
       }
   }
 
 }
cout<<endl;
return 0;
}

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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N;
    cin >> N;
    vector<vector<char> > S(N, vector<char>(N));
    REP(i, N) REP(j, N) cin >> S[i][j];

    int ans = 0;
    int a= 0;
    REP(b, N) {
        bool ok = true;
        REP(i, N) REP(j, N) {
                int x = i + a;
                int y = j + b;
                if (x >= N) x -= N;
                if (y >= N) y -= N;

                int rx = y;
                int ry = x;

                if (rx < a) rx += N;
                if (ry < b) ry += N;
                rx -= a;
                ry -= b;

                if (S[i][j] != S[rx][ry]) {
                    ok = false;
                    break;
                }
            }

        if (ok) ans++;
    }
    cout << ans * N << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		Integer[] a = new Integer[5];
		
		for(int i = 0; i < 5; i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		
		List<Integer> list = new ArrayList<Integer>();
		
		int time = 0;
		
		Set<Integer> remove = new HashSet<Integer>();
		
		for(int i = 0; i < 5; i++) {
			List<Integer> temp = Arrays.asList(a);
			final int ae = i;
			if(temp.contains(a[i]) && temp.stream().filter(x -> a[ae] == x).count() != 1 && i != a.length-1) {
				time+=a[i]+(10-(a[i]%10));
				remove.add(a[i]);
				continue;
			}
			
			if(remove.contains(a[i]) && i == a.length-1) {
				time+=a[i];
				break;
			}
			
			if(a[i] % 10 == 0) {
				time+=a[i];
			}else{
				list.add(a[i]);
			}
		}
		
		list = sort(list);
		
		for(int i = 0; i < list.size(); i++) {
			if(i != list.size()-1) {
				time+=list.get(i)+(10-(list.get(i)%10));
			}else{
				time+=list.get(i);
			}
		}
		
		System.out.println(time);

	}
	
	public static List<Integer> sort(List<Integer> list){
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		
		for(int i : list) {
			int one = String.valueOf(i).charAt(String.valueOf(i).length()-1) - '0';
			map.put(i, one);
		}
		
		List<Entry<Integer, Integer>> list_entries = map.entrySet().stream().sorted(Collections.reverseOrder(Entry.comparingByValue())).collect(Collectors.toList());
        
       List<Integer> ae = new ArrayList<Integer>();
       
       for(Entry<Integer, Integer> e : list_entries) {
    	   ae.add(e.getKey());
       }
       
       return ae;
	}
}


Measured memory_bytes: 30548
using System;

public class OneCardPoker
{
    static void Main()
    {
        string[] inputs = Console.ReadLine().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries );
        if ( inputs.Length < 2 ) return;

        int a = int.Parse( inputs[ 0 ] );
        if ( a == 1 ) a = 14;
        int b = int.Parse( inputs[ 1 ] );
        if ( b == 1 ) b = 14;

        Console.WriteLine( a > b ? "Alice" : a < b ? "Bob" : "Draw" );
    }
}


Measured memory_bytes: 11092
import itertools

X, K, D = map(int, input().split())

if K % 2 == 0:
  q, mod = divmod(abs(X), D*2)
  if mod <= abs(mod - D*2):
    if q*2 <= K:
      print(mod)
    else:
      print(abs(abs(X)-(K*D)))
  else:
    if q*2 <= K:
      print(abs(mod-D*2))
    else:
      print(abs(abs(X)-(K*D)))
else:
  q, mod = divmod(abs(X)-D, D*2)
  if mod <= abs(mod - D*2):
    if q*2 <= K:
      print(mod)
    else:
      print(abs(abs(X)-(K*D)))
  else:
    if q*2 <= K:
      print(abs(mod-D*2))
    else:
      print(abs(abs(X)-(K*D)))

Measured memory_bytes: 9156
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

/*
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
*/

#define ARRAY_MAX 100005
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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




/******************************************************************************************/



int main() {

	
	ll a, b;
	cin >> a >> b;

	if (abs(a - b) % 2LL) {
		cout << "IMPOSSIBLE" << endl;
	}
	else
	{
		cout << abs(a - b) / 2 + min(a, b) << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
using namespace std;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>

int main() {
	int H, W;
	cin >> H >> W;

	string S[50];
	rep(i, H) {
		cin >> S[i];
	}

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

	rep(i, H) {
		rep(j, W) {
			if (S[i][j] == '#') continue;

			int cnt = 0;
			for (int d = 0; d < 8; d++) {
				int ni = i + dx[d];
				int nj = j + dy[d];

				if (ni < 0 || ni >= H) continue;
				if (nj < 0 || nj >= W) continue;
				if (S[ni][nj] == '#') cnt++;
			}
			S[i][j] = char(cnt + '0');
		}	
	}
	rep(i, H) {
		cout << S[i] << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.ReadLine();
            var max = 0;
            var now = 0;
            foreach (var c in line)
            {
                switch (c)
                {
                    case 'A':
                    case 'C':
                    case 'G':
                    case 'T':
                        if(++now > max)
                        {
                            max = now;
                        }
                        break;
                    default:
                        now = 0;
                        break;
                }
            }
            return max;
        }

        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
    }

    public class ConsoleReader
    {
        public virtual string ReadLine() => Console.ReadLine();
        public int ReadLineInt32() => int.Parse(ReadLine());
        public long ReadLineInt64() => long.Parse(ReadLine());
        public ulong ReadLineUInt64() => ulong.Parse(ReadLine());
        public double ReadLineDouble() => double.Parse(ReadLine());
        public string[] Split() => ReadLine().Split().ToArray();
        public int[] SplitInt32() => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public long[] SplitInt64() => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public ulong[] SplitUInt64() => ReadLine().Split().Select(s => ulong.Parse(s)).ToArray();
        public double[] SplitDouble() => ReadLine().Split().Select(s => double.Parse(s)).ToArray();

        public IEnumerable<string> RepeatReadLines(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLine();
        }
        public IEnumerable<int> RepeatReadLinesInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLineInt32();
        }
        public IEnumerable<long> RepeatReadLinesInt64(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLineInt64();
        }
        public IEnumerable<string[]> RepeatReadLinesSplit(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Split();
        }
    }
    static class DicExt
    {
        public static V GetOrDefault<K, V>(this Dictionary<K, V> dic, K key, V defaultValue = default(V))
        {
            V val;
            return dic.TryGetValue(key, out val) ? val : defaultValue;
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
 
int main(void) {
    int i,j,k;
    int m,f,r;
    
    while(1){
        scanf("%d %d %d", &m,&f,&r);
        //???????????其
        if(m==-1&&f==-1&&r==-1) break;
        
        if(m==-1||f==-1) printf("F\n");
        else if(m+f>=80) printf("A\n");
        else if(m+f>=65 && m+f<80) printf("B\n");
        else if(m+f>=50 && m+f<65) printf("C\n");
        else if(m+f>=30 && m+f<50) {
            if(r>=50) printf("C\n");
            else  printf("D\n");
        }
        else printf("F\n");
    }
        
    return 0;
}

Measured memory_bytes: 584
odd = {'R', 'U', 'D'}
even = {'L', 'U', 'D'}
string = input()
result = 'Yes'
for i, c in enumerate(string, start=1):
    if i % 2 == 0:
        if c not in even:
            result = 'No'
            break
    else:
        if c not in odd:
            result = 'No'
            break
print(result)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    static String changeNumber(String str, char num1, char num2) {
        String tmp = str.replace(num1, '8');
        tmp = tmp.replace(num2, num1);
        tmp = tmp.replace('8', num2);
        return tmp;
    }

    public static void main(String[] args) throws IllegalStateException {
        Map<String, Integer> map = new HashMap<>();
        Deque<String> deque = new ArrayDeque<>();
        map.put("01234567", 0);
        deque.addLast("01234567");

        while(deque.size() > 0) {
            String parent = deque.removeFirst();
            int index = parent.indexOf("0");
            if(index <= 3) {
                String child = changeNumber(parent, '0', parent.charAt(index+4));
                if(!map.containsKey(child)) {
                    map.put(child, map.get(parent)+1);
                    deque.addLast(child);
                }
            }
            if(index >= 4) {
                String child = changeNumber(parent, '0', parent.charAt(index-4));
                if(!map.containsKey(child)) {
                    map.put(child, map.get(parent)+1);
                    deque.addLast(child);
                }
            }
            if(index % 4 <= 2) {
                String child = changeNumber(parent, '0', parent.charAt(index+1));
                if(!map.containsKey(child)) {
                    map.put(child, map.get(parent)+1);
                    deque.addLast(child);
                }
            }
            if(index % 4 >= 1) {
                String child = changeNumber(parent, '0', parent.charAt(index-1));
                if(!map.containsKey(child)) {
                    map.put(child, map.get(parent)+1);
                    deque.addLast(child);
                }
            }
        }

        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            String str = "";
            for(int i = 0; i < 8; i++) str += sc.next();
            if(map.containsKey(str)) System.out.println(map.get(str));
        }
        sc.close();
    } 
}


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

typedef long long int ll;

int main()
{
    ll n, ans = 0;
    cin >> n;
    for(ll i = 1;i <= n;i += 2){
        ll t = 0;
        for(ll j = i;j > 0;j--){
            if(i % j == 0){
                t++;
            }
            //cout << j;
        }
        if(t == 8){
            ans++;
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256