akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
#define fi first
#define se second
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

void Main()
{
  i64 x;
  cin >> x;
  i64 ans = 0;
  ans += 1000 * (x/500);
  x %= 500;
  ans += 5 * (x/5);
  cout << ans << endl;

}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}



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

int N, W;

long long w[110];
long long v[110];

long long dp[110][100100] = {0};

int main(){
    cin >> N >> W;
    for(int i=0; i < N; i++) cin >> w[i] >> v[i];

    for(int i = 0; i < N; i++){
        for(int j = 0; j <= W; j++){
            if(j - w[i] >= 0) dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    cout << dp[N][W] << endl;

    return 0;
}
    

Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=1e5+10;
const int INF=1e9+7;

int N,M;
vi G[MAX];
void input(){
    cin>>N>>M;
    rep(_,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);
    }
}

int d[MAX];
int dfs(int v){
    if(d[v]!=-1)return d[v];
    int tmp=0;
    rep(i,sz(G[v])){
        int u=G[v][i];
        int p=dfs(u);
        tmp=max(tmp, p+1);
    }
    d[v]=tmp;
    return d[v];
}

int ans;
void solve(){
    rep(i,N)d[i]=-1;
    rep(i,N){
        int tmp=dfs(i);
        ans=max(ans, tmp);
    }
}


void output(){ 
    cout<<ans<<endl;
}

int main(){
    input();
    solve();
    output();
}


Measured memory_bytes: 8832
fun main(args:Array<String>) {
    // numOfAnimalsに動物の総数、numOfLegsにそれらの足の総数をInt型で代入する
    val (numOfAnimals , numOfLegs) = readLine()!!.split(" ").map(String::toInt)
    // ansに"No"を代入しておいてfor文を回している間に条件に合った場合のカウンターにする
    var ans = "No"
    // 鶴がa匹だった場合の組合せをすべてループさせる
    for (a in 0..numOfAnimals){
        // 鶴がa匹だった場合のカメの数
        val b = numOfAnimals - a
        // 2*aで鶴の足の総数、4*bでカメの足の総数。それらを足した数が同じになれば条件に合う
        if(2 * a + 4 * b == numOfLegs){
            ans = "Yes"
        }
    }
    print(ans)
}

Measured memory_bytes: 36480
#include <stdio.h>
#define MAX 45

//int Fibonacci(int);
int aFibonacci(int);

int main(){
    int n;

    scanf("%d",&n);

    printf("%d\n",aFibonacci(n));

    return 0;
}

/*int Fibonacci(int n){
    if(n == 1 || n == 0)return 1;
    
    return Fibonacci(n - 1) + Fibonacci(n -2);
}*/

int aFibonacci(int x){
    int F[MAX];
    F[0] = F[1] = 1;
    for(int i = 2;i < MAX;i++){
        F[i] = F[i - 1] + F[i - 2];
    }
    return F[x];
}


Measured memory_bytes: 2048
#include <stdio.h>

int main(void) 
{
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a == b)
  {
    if (b == c) printf("1");
    else printf("2");
  }
  else
  {
    if (a == c) printf("2");
	else if (b == c) printf("2");
  	else printf("3");  
  }
  return 0;
} 

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

template<class RandomAccessIterator>
void LSD_RadixSort(RandomAccessIterator first, RandomAccessIterator last,
		int maximum, int max_digit,
		::std::function<int(typename RandomAccessIterator::value_type, int)> get_digit){
	using value_type = typename RandomAccessIterator::value_type;

	::std::size_t size = ::std::distance(first, last);
	::std::vector<::std::vector<int>> bucket(maximum+1);
	::std::vector<value_type> v(first, last), tmp;

	int digit = 0;

	for(int digit = 0;digit < max_digit;digit++){
		for(int i = 0;i < size;i++){
			int x = get_digit(v[i], digit);
			bucket[x].push_back(i);
		}

		for(int i = 0;i <= maximum;i++){
			for(int j = 0;j < bucket[i].size();j++){
				tmp.push_back(v[bucket[i][j]]);
			}
			bucket[i].clear();
		}

		::std::swap(v, tmp);
		tmp.clear();
	}
	::std::move(v.begin(), v.end(), first);
}

/*

	

*/

/*

verify:https://beta.atcoder.jp/contests/abc088/submissions/3178401
*/

int get(int x, int dig){
	return x >> dig & 1;
}

int main(void){
	int n;
	::std::vector<int> v;
	std::cin >> n;
	v.resize(n);
	for(int i = 0;i < n;i++) std::cin >> v[i];

	LSD_RadixSort(v.begin(), v.end(), 2, 32, get);
	std::reverse(v.begin(), v.end());
	int res = 0;
	for(int i = 0;i < n;i++) res = res + v[i] * (i%2 ? -1 : 1);
	std::cout << res << std::endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  if(n/1000){
    cout<<"ABD"<<endl;
  }else{
    cout<<"ABC"<<endl;
  }
  return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var pg = new Program();

            pg.Execute();
         
        }

        private void Execute()
        {
            var input = ReadLinesLongList;
            var N = input.ElementAt(0);
            var K = input.ElementAt(1);
            var list = new List<long>();

            if(N%K == 0){
                OutputResult(0);
                return;
            }

            N = N%K;

            while(true){
                if(list.Contains(Math.Abs(N-K))){
                    OutputResult(list.Min());
                    return;
                }else{
                    list.Add(Math.Abs(N-K));
                    N = Math.Abs(N-K);
                }
            }
        }

        private void OutputResult<Type>(Type result){
            Console.WriteLine(result);
        }

        static long ReadLineLong => long.Parse(Console.ReadLine());
        static string ReadLineString => Console.ReadLine();
        static IEnumerable<long> ReadLinesLongList => Console.ReadLine().Split(' ').Select(i => long.Parse(i));
        static IEnumerable<string> ReadLinesStringList => Console.ReadLine().Split(' ');

    }
}


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

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cin >> a.at(i).at(j);
    }
  }

  set<int> hd, wd;
  for(int i=0; i<h; i++){
    bool flg=true;
    for(char x:a.at(i)){
      if(x=='#'){
        flg=false;
        break;
      }
    }
    if(flg){
      hd.insert(i);
    }
  }

  for(int i=0; i<w; i++){
    bool flg=true;
    for(int j=0; j<h; j++){
      if(a.at(j).at(i)=='#'){
        flg=false;
        break;
      }
    }
    if(flg) wd.insert(i);
  }

  for(int i=0; i<a.size(); i++){
    if(hd.find(i)!=hd.end()) continue;
    for(int j=0; j<a.at(0).size(); j++){
      if(wd.find(j)!=wd.end()) continue;
      cout << a.at(i).at(j);
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int len=s.size();
  int len1=len-1;
  int flag=0,flag1=0,flag2=0;
  int q=((len1+2)/2)-1;
  for(int k=0;k<len;k++)
  {
      if(s[k]!=s[len1-k])
      {
          flag=1;

      }
  }
  int p=(len/2)-1;
  for(int i=0;i<=p;i++)
  {
     if(s[i]!=s[p-i])
     {
         flag1=1;
     }


  }

  for(int j=q;j<=len1;j++)
  {
      if(s[j]!=s[len1-j])
      {
          flag2=1;
      }

  }



  if(flag==1 || flag1==1 || flag2==1)
  {
      cout<<"No";
  }
  else
  {
      cout<<"Yes";
  }
  return 0;


}


Measured memory_bytes: 3596
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        t: (i64, i64, i64, i64),
    }
    let a = t.0;
    let b = t.1;
    let c = t.2;
    let k = t.3;

    if k <= a {
        println!("{}", k);
    } else if k <= a + b {
        println!("{}", a);
    } else {
        let p = k - a - b;
        println!("{}", a - p);
    }
}

Measured memory_bytes: 2136
# 出力したい合計値
str_input = input()
sum_all = 0

# strで入力される

# str_input = "1234567891"
# str_input = "9999999999"
# 文字列の長さを読み取る
n = len(str_input)

# 文字列の長さから+を入れる組み合わせの総数を取得

plus_pattern_2 = (2**(n-1))-1

# plus_pattern_2 = 1000

for value in range(plus_pattern_2+1):
    # print("plus_pattarn", value)
    # 右端
    right = n
    
    tmp_number = 0

    for i in range(1, n+1):
        # print(i, "番目")
        # print(bin(value))
        result = value & 1
        if result == 1:
            # print("hit")
            tmp_number = int(str_input[n-i:right])
            # print(tmp_number)
            sum_all += tmp_number
            right = n-i
        value = value >> 1
        # print("next")
        # print("")

    # print("left number")

    tmp_number = int(str_input[n-i:right])
    # print("tmp_number", tmp_number)
    sum_all += tmp_number
    # print("tmp_all", sum_all)

print(sum_all)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main(){
  ll a,b;
  cin >> a >>b;
  if(a*b%2==1){cout << "Odd" << endl;}else{cout << "Even" << endl;}
}

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

using namespace std;

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> b(n);
  REP(i, n + 1){
    cin >> a[i];
  }
  REP(i, n){
    cin >> b[i];
  }
  uint64_t m = 0;
  REP(i, n){
    int p = min(a[i], b[i]);
    m += p;
    int q = min(a[i + 1], b[i] - p);
    m += q;
    a[i + 1] -= q;
  }
  cout << m << endl;
  return 0;
}

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




vector<pair<char, int> > runlength(string str) {
    vector<pair<char, int> > ret;
    int cnt = 1;
    int n = sz(str);
    rep3(i, 1, n) {
        if (str[i] == str[i - 1]) {
            cnt++;
        } else {
            ret.eb(make_pair(str[i - 1], cnt));
            cnt = 1;
        }
    }
    ret.eb(make_pair(str[n - 1], cnt));
    return ret;
}

set<int> make(string s, int k) {
    auto run = runlength(s);
    
    vector<int> tmp;
    int cnt = 0;
    rep(i, sz(run)) { // TTとかあり得る
        // cout << run[i].F << " " << run[i].S << endl;
        if (run[i].F == 'T') { if (run[i].S % 2 == 1) cnt ^= 1; continue; }
        if (cnt == k) tmp.eb(run[i].S);
    }
    
    set<int> st;
    st.insert(0);
    rep(i, sz(tmp)) {
        set<int> s2;
        for (auto e : st) {
            s2.insert(e + tmp[i]);
            if (!(k == 0 && run[0].F == 'F' && i == 0)) s2.insert(e - tmp[i]);
        }
        st = s2;
    }
    return st;
}

string m(string s, int x, int y) {

    auto st = make(s, 0);
    if (st.find(x) == st.end()) return "No";
    
    st = make(s, 1);
    if (st.find(y) == st.end()) return "No";
    return "Yes";
}

int main() {
  string s;
  int x, y;
  cin >> s >> x >> y;
  cout << m(s, x, y) << endl;
}

Measured memory_bytes: 768
def insert(r, n):
    if 0 == len(T):
        T[n] = [None, None]
    else:
        if n < r:
            left = T[r][0]
            if left == None:
                T[r][0] = n
                T[n] = [None, None]
            else:
                insert(left, n)
        if r < n:
            right = T[r][1]
            if right == None:
                T[r][1] = n
                T[n] = [None, None]
            else:
                insert(right, n)

def print_inorder(r):
    left = T[r][0]
    right = T[r][1]
    ans = ""
    if left != None:
        ans += print_inorder(left)
    ans += " {}".format(r)
    if right != None:
        ans += print_inorder(right)
    return ans

def print_preorder(r):
    left = T[r][0]
    right = T[r][1]
    ans = " {}".format(r)
    if left != None:
        ans += print_preorder(left)
    if right != None:
        ans += print_preorder(right)
    return ans




n = int(input())
T = {}

root = None
for i in range(n):
    inst = input()
    if inst[0] == 'i':
        num = int(inst[7:])
        if i == 0:
            root = num
        insert(root, num)
    elif inst[0] == 'p':
        print(print_inorder(root))
        print(print_preorder(root))

Measured memory_bytes: 105660
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int, int> P;

const int N = 101;
const int INF = (1 << 28);

vector<P> G[N];
vector<pair<string, int> > dat;
map<string, int> stoi;
int d[N];

int dijkstra(int s, int t){
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d+N, INF);
	d[s] = 0;
	que.push(make_pair(0, s));
	while(!que.empty()){
		P p = que.top(); que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i=0;i<G[v].size();i++){
			P e = G[v][i];
			if(d[e.first] > d[v] + e.second){
				d[e.first] = d[v] + e.second;
				que.push(P(d[e.first], e.first));
			}
		}
	}
	return d[t];
}

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		string in;
		cin >> in;
		if(in == "goto"){
			cin >> in;
			in = in.substr(0, (int)in.size()-1);
			dat.push_back(make_pair(in, 1));
			G[i].push_back(make_pair(i+1, 1));
		}else{
			in = in.substr(0, (int)in.size()-1);
			dat.push_back(make_pair(in, 0));
			G[i].push_back(make_pair(i+1, 0));
			stoi[in] = i;
		}
	}
	for(int i=0;i<n;i++){
		if(dat[i].second){
			G[i].push_back(make_pair(stoi[dat[i].first], 0));
		}
	}
	cout << dijkstra(0, n) << endl;
	return 0;
}

Measured memory_bytes: 1244
import sys
from collections import deque


input = lambda: sys.stdin.readline().rstrip()


if __name__ == "__main__":
    H, W = map(int, input().split())
    ch, cw = map(lambda x: int(x)-1, input().split())
    dh, dw = map(lambda x: int(x)-1, input().split())
    maze = [list(input()) for _ in range(H)]
    INF = 10**8
    mc = [[INF]*W for _ in range(H)]
    mc[ch][cw] = 0
    walk_que = deque()
    walk_que.append((ch, cw, 0))
    while walk_que:
        y, x, w = walk_que.popleft()
        for ny, nx in [(y+1, x), (y-1, x), (y, x+1), (y, x-1)]:
            if H > ny >= 0 and W > nx >= 0 and mc[ny][nx] > w and maze[ny][nx] == ".":
                mc[ny][nx] = w
                walk_que.appendleft((ny, nx, w))
        for dy in range(-2, 3):
            ny = y + dy
            for dx in range(-2, 3):
                nx = x + dx
                if H > ny >= 0 and W > nx >= 0 and mc[ny][nx] > w+1 and maze[ny][nx] == ".":
                    mc[ny][nx] = w + 1
                    walk_que.append((ny, nx, w+1))
    if mc[dh][dw] == INF:
        print(-1)
    else:
        print(mc[dh][dw])


Measured memory_bytes: 148236
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll H, W;
string s[444];
ll dx[]={-1, 0, 1, 0};
ll dy[]={0, -1, 0, 1};
ll used[444][444];

P dfs(ll x, ll y, ll clr) {
    used[x][y]=1;
    
    
    P p=mkp(0, 0);
    if(s[x][y]=='#') p.fi++;
    else p.se++;
    
    for(ll i=0; i<4; i++) {
        ll tx=x+dx[i];
        ll ty=y+dy[i];
        
        if(tx<0 || ty<0 || tx>=H || ty>=W) continue;
        if((s[x][y]=='#' && s[tx][ty]=='#') || (s[x][y]=='.' && s[tx][ty]=='.')) continue;
        if(used[tx][ty]!=-1) continue;
        
        P t=dfs(tx, ty, clr);
        p.fi+=t.fi;
        p.se+=t.se;
    }
    
    return p;
}

int main(void) {
    ll i, j;
    cin >> H >> W;
    ll clr=0;
    for(i=0; i<H; i++) {
        cin >> s[i];
    }
    ll ans=0;
    memset(used, -1, sizeof(used));
    for(i=0; i<H; i++) {
        for(j=0; j<W; j++) {
            if(s[i][j]=='#') {
                P t=dfs(i, j, clr);
                ans+=t.fi*t.se;
            }
        }
    }
    
    pr(ans);
}














Measured memory_bytes: 17024
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
    matsubi = int(list(input()[:-1])[-1])
    if matsubi == 3:
        print('bon')
    elif matsubi == 0 or matsubi == 1 or matsubi == 6 or matsubi == 8:
        print('pon')
    else:
        print('hon')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
from collections import deque
n,q = map(int,input().split())
ki = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ki[a].append(b)
    ki[b].append(a)
ans = [0]*n
for _ in range(q):
    p,x = map(int,input().split())
    p -= 1
    ans[p] += x

stk = deque()
stk.append((0,-1))
while stk:
    cur,prev = stk.pop()
    for nxt in ki[cur]:
        if nxt == prev: continue
        ans[nxt] += ans[cur]
        stk.append((nxt,cur))

print(*ans)

Measured memory_bytes: 64256
def main():
    n, *a = map(int, open(0).read().split())
    x1 = sum(a[::2]) - sum(a[1::2])
    x = [0] * n
    ans = str(x1)
    tmp = x1
    for i in a[:-1]:
        tmp = 2 * i - tmp
        ans += ' ' + str(tmp)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m;
    cin>>n>>m;
    ll x=1LL*n*m;
    if(n==1 || m==1)
    {
        cout<<"1"<<endl;
    }
    else if(x%2==0)
    {
        cout<<x/2<<"\n";
    }
    else
    {
        cout<<(x/2)+1<<"\n";
    }
}


Measured memory_bytes: 3600
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;


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

	int d = b - a;
	ll sum = 0;
	for (int i = 1; i < d; i++) {
		sum += i;
	}

	cout << sum - a << endl;


}

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

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int N = 5e5;
const int P = 998244353;
llong fact[N+3],finv[N+3];
int n,m;

llong quickpow(llong x,llong y)
{
	llong cur = x,ret = 1ll;
	for(int i=0; y; i++)
	{
		if(y&(1ll<<i)) {y-=(1ll<<i); ret = ret*cur%P;}
		cur = cur*cur%P;
	}
	return ret;
}
llong comb(llong x,llong y) {return x<0||y<0||x<y?0ll:fact[x]*finv[y]%P*finv[x-y]%P;}

int main()
{
	fact[0] = 1ll; for(int i=1; i<=N; i++) fact[i] = fact[i-1]*i%P;
	finv[N] = quickpow(fact[N],P-2); for(int i=N-1; i>=0; i--) finv[i] = finv[i+1]*(i+1ll)%P;
	scanf("%d%d",&n,&m); int lim = min(n,m); llong pwn = quickpow(n+1,m-lim),pwm = quickpow(m+1,n-lim); llong ans = 0ll;
	for(int i=lim; i>=0; i--)
	{
		llong cur = comb(m,i)*comb(n,i)%P*fact[i]%P*pwn%P*pwm%P;
		if(i&1) {ans = (ans-cur+P)%P;} else {ans = (ans+cur)%P;}
		pwn = pwn*(n+1ll)%P,pwm = pwm*(m+1ll)%P;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			//1000000000000001 = 10^15+1

			long N = scan.nextLong();

			long max = 0;
			long count = 1;

			long num = 0;

			while(true) {
				if(max+1<=N&&N<=max+(long)Math.pow(26,count)) {
					num = N-max;
					break;
				}else{
					max = max+(long)Math.pow(26,count);
					count++;
				}
			}

			//System.out.println(num);
			//System.out.println(count);

			StringBuffer sb = new StringBuffer();
			num--;


			for(int i = 0;i<count;i++) {
				long x = num%26;
				num = num/26;
				char c = (char)(x+97);
				//System.out.println(x);
				sb.append(c);
			}

			String S = sb.reverse().toString();

			//System.out.println();
			System.out.println(S);

		}


	}


}


Measured memory_bytes: 35676
import re
import doctest

class IO_for_Contest(object):
    @staticmethod
    def my_input():
        #return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        #TODO: impl this for each problem
        pass

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map( \
                int, \
                re.split('\s+', IO_for_Contest.my_input().strip())))[ : n]
def solve():
    n = IO_for_Contest.read_int()
    print(int(n * (n + 1) / 2))

if __name__ == '__main__':
    #doctest.testmod()
    solve()

Measured memory_bytes: 8920
#!python3.8
# -*- coding: utf-8 -*-
# abc177/abc177_d
import sys
from collections import deque

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

class node:
    def __init__(self, i):
        self.i = i
        self.adj = {self}
        self.visited = False
    
    def join(self, B):
        self.adj.add(B)
        B.adj.add(self)

def bfs(tar):
    q = deque()
    q.append(tar)
    cnt = 0
    while (q):
        tar = q.popleft()
        if not tar.visited:
            cnt += 1
        tar.visited = True
        q.extend(adj for adj in tar.adj if not adj.visited)
    return cnt

def main():
    N, M = i2nn()
    G = [node(i) for i in range(N + 1)]
    for _ in range(M):
        A, B = i2nn()
        G[A].join(G[B])
    ans = 0
    for tar in G[1:]:
        if not tar.visited:
            ans = max(bfs(tar), ans)
    print(ans)
    return

main()


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

using namespace std;

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

        if(H == 0 && W == 0)
        {
            return 0;
        }

        for(int i = 0;i < H;i++)
        {
            for(int j = 0;j < W;j++)
            {
                if(i == 0 || i == (H - 1) || j == 0 || j == (W - 1))
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                    
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}

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

typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    //ios_base::sync_with_stdio(false);
    //cout<<setprecision(20);
    int n;
    cin>>n;
    if(n==3){
        cout<<"2 5 63";
        return 0;
    }
    int k6=0,k2=0,k3=0,k4=0;
    cout<<"2 3 4 9 ";
    n-=4;
    k2++;
    k3+=2;
    k4++;
    if(n%2==1){
        cout<<"6 ";
        k6++;
        n--;
    }
    while(k2<5000&&n>0){
        cout<<k2*6+2<<" ";
        cout<<k4*6+4<<" ";
        k2++;
        k4++;
        n-=2;
    }
    while(k3<5000&&n>0){
        cout<<k3*6+3<<" ";
        k3++;
        cout<<k3*6+3<<" ";
        k3++;
        n-=2;
    }
    while(k6<5000&&n>0){
        cout<<k6*6+6<<" ";
        k6++;
        n--;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define   ll  long long int
#define   sz  1000100

using namespace std;


ll num[sz];


int main()
{


    ll n,b,s=0,k,x,y,a,i,j,d;

    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>num[i];
        s+=num[i];
    }

    for(i=1;i<=n;i++)
    {
        num[i]=num[i-1]+num[i];

    }

        x=num[1];
        y=s-x;
        d=abs(x-y);
        a=d;



    for(i=2;i<n;i++)
    {
        x=num[i];
        y=s-x;

        d=abs(x-y);
        a=min(a,d);
    }


    cout<<a<<endl;


    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for((i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

const int MAX_N = 1000002;
int n, primes[100000], prime_sz = -1;
bool used[100000];
bool sieve[MAX_N];


int solve() {
  int ans = 0;
  fill(used, used + 100000, false);

  for (int i = 0; i < prime_sz; ++i) {
    if (used[i]) continue;
    const int value = n - primes[i];
    const int vl = lower_bound(primes, primes + prime_sz, value) - primes;
    if (used[vl]) continue;
    if (n != primes[i] + primes[vl]) continue;
    used[i] = used[vl] = true;
    ans++;
  }
  return ans;
}

int main() {
  // prime
  primes[0] = 2;
  int cnt = 1;
  fill(sieve, sieve + MAX_N, true);
  sieve[0] = sieve[1] = false;
  for (int i = 4; i < MAX_N; i+=2) sieve[i] = false;
  for (int i = 3; i < MAX_N; i+=2) if (sieve[i]) {
    primes[cnt] = i; cnt++;
    for (int j = i + i; j < MAX_N; j+=i) sieve[j] = false;
  }
  prime_sz = cnt;
  
  while (cin >> n, n) {
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 2252
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<vector>

using namespace std;
int N = 0;
int A[10] = { 0 };
int ans = 0;

void func(int a,int b){
	if (a == N){
		if (N - b > 0)
			ans++;
		return;
	}else{
		if (A[a] % 2 == 0){
			func(a + 1, b + 1);
			func(a + 1, b);
			func(a + 1, b + 1);
		}
		else{
			func(a + 1, b);
			func(a + 1, b + 1);
			func(a + 1, b);
		}
	}
}

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

	func(0,0);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int x;
  cin >> x;
  if (x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
ll x[111111];
ll r[33][111111];
ll l,q;

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	rep(i,n)cin>>x[i];
	cin>>l;
	rep(i,n){
		r[0][i]=upper_bound(x,x+n,x[i]+l)-x-1;
	}
	rep(i,22){
		rep(j,n){
			r[i+1][j]=r[i][r[i][j]];
		}
	}
	cin>>q;
	rep(i,q){
		int a,b;
		cin>>a>>b;
		a--; b--;
		if(a>b)swap(a,b);
		ll res=0;
		int ns=a;
		for(int k=20;k>=0;k--){
			if(r[k][ns]<b){
				ns=r[k][ns];
				res+=1<<k;
			}
		}
		cout<<res+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 19712
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
	  int d = sc.nextInt();
      int n = sc.nextInt();
      int no=1;
      for(int i=0;i<d;i++){
        no*=100;
      }
      int ans=no;
      for(int i=1;i<n;i++){
        ans+=no;
      }
      if(n==100){
         System.out.println(ans+no);
      }else{
        System.out.println(ans);
      }
    }
}

Measured memory_bytes: 35636
import java.util.NoSuchElementException

fun main(args: Array<String>) = FastScanner().run {
    val n = nextInt()
    val a = LongArray(n)
    val b = LongArray(n)
    for (i in 0 until n) {
        a[i] = nextLong()
        b[i] = nextLong()
    }
    var sum = 0L
    for (i in n-1 downTo 0) {
        val cur = sum + a[i]
        sum += cur.ceilDiv(b[i])*b[i] - cur
    }
    println(sum)
}

fun Long.ceilDiv(k: Long): Long = (this + k - 1) / k

class FastScanner {
    private val printable = 33..126
    val `in` = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = `in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun nextInt(): Int {
        val nl = nextLong()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun nextDouble(): Double {
        return next().toDouble()
    }
}

Measured memory_bytes: 31716
n=int(input())
p_list=[int(i) for i in input().split()]

np_list=sorted(p_list)

count=0
for i in range(n):
    if p_list[i]!=np_list[i]:
        count+=1

if count==2 or count==0:
    ans="YES"
else:
    ans="NO"

print(ans)

Measured memory_bytes: 9204
n = int(input())
s1 = input()
s2 = input()
cnt = 1
i = 0
while i <= n-1:
    if i == 0:
        if s1[i] == s2[i]:
            cnt *= 3
            s = 0
        else:
            cnt *= 6
            i += 1
            s = 1
    elif s1[i] == s2[i]:
        if s == 0:
            cnt *= 2
        else:
            cnt *= 1
        s = 0
    else:
        if s == 0:
            cnt *= 2
        else:
            cnt *= 3
        s = 1
        i += 1
    i += 1
print(cnt % (10**9+7))

Measured memory_bytes: 3188
#include <iostream>
#include <string>

int N, K;
std::string S;

int main() {
  std::cin >> N >> K;
  std::cin >> S;
  int cnt_l = 0, cnt_r = 0, cnt_same = 0;
  (S[0] == 'L' ? cnt_l : cnt_r)++;
  for (int i = 1; i < N; ++i) {
    (S[i] == 'L' ? cnt_l : cnt_r)++;
    if (S[i] == S[i-1]) cnt_same++;
  }

  int cnt_pos = (cnt_l-1) + (cnt_r-1);
  std::cout << std::min(N-1, cnt_same + 2*K) << "\n";

  return 0;
}


Measured memory_bytes: 3760
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int k,s;

int main(){
	scanf("%d %d",&k,&s);
	int ans = 0;
	for(int i = 0;i <= k;i++){
		for(int j = 0;j <= k;j++){
			int u = s - i - j;
			if(u >= 0 && u <= k) ans++;
		}
	}
	printf("%d\n",ans);
	return 0;	
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		String data;
		while (true) {
			data = reader.readLine();
			if (data.charAt(0) == '0')
				break;
			StringTokenizer tokenizer = new StringTokenizer(data);
			int month = Integer.parseInt(tokenizer.nextToken())-1;
			int date = Integer.parseInt(tokenizer.nextToken());

			Calendar calendar = Calendar.getInstance();
			calendar.set(2004, month, date);
			int week = calendar.get(Calendar.DAY_OF_WEEK);
			switch (week) {
			case 1:
				System.out.println("Sunday");
				break;
			case 2:
				System.out.println("Monday");
				break;
			case 3:
				System.out.println("Tuesday");
				break;
			case 4:
				System.out.println("Wednesday");
				break;
			case 5:
				System.out.println("Thursday");
				break;
			case 6:
				System.out.println("Friday");
				break;
			default:
				System.out.println("Saturday");
				break;
			}
		}
	}
}

Measured memory_bytes: 16980
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

const int MAX = 3000000;

int main()
{
	int N=0, K = 0;

	cin >> N >> K;

	vector<int> A(N, 0);
	vector<int> DP(N + 1, MAX);

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

	for (int i = 0; i < N; i++) {
		if (DP[A[i]] == MAX) DP[A[i]] = 1;
		else DP[A[i]]++;
	}

	int ans = 0;

	for (int i = 0; i <= N; i++) {
		if (DP[i] < MAX) ans++;
	}

	if (ans <= K) cout << 0 << endl;
	else {
		sort(DP.begin(), DP.end());
		int num = 0;
		for (int i = 0; i < ans - K; i++) {
			num += DP[i];
		}
		cout << num << endl;
	}
    return 0;
}



Measured memory_bytes: 1792
N = int(input())
H = list(map(int,input().split()))
ans,buf=0,0
for i in range(0,len(H)-1):
    if H[i] >= H[i+1]:
        buf += 1
    else:
        ans = max(ans,buf)
        buf = 0
ans = max(ans,buf)
print(ans)        


Measured memory_bytes: 20476
#include <iostream>
#include <map>

#define INPUT_FROM_FILE (0)

#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv) {
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	int n = 0;

#if INPUT_FROM_FILE
	if (!ifs.is_open()) {
		std::cout << "can't open" << std::endl;
		exit(0);
	}
	while (ifs >> n, n > 0) {
#else
	while (std::cin >> n, n > 0) {
#endif
		std::map<char, char> conversion_map;

		int m = 0;

		for (int i = 0; i < n; i++) {
			char prev = 0;
			char post = 0;

#if INPUT_FROM_FILE
			ifs >> prev >> post;
#else
			std::cin >> prev >> post;
#endif
			conversion_map[prev] = post;
		}

#if INPUT_FROM_FILE
		ifs >> m;
#else
		std::cin >> m;
#endif

		for (int i = 0; i < m; i++) {
			char c = 0;

#if INPUT_FROM_FILE
			ifs >> c;
#else
			std::cin >> c;
#endif

			if (conversion_map.find(c) != conversion_map.end()) {
				std::cout << conversion_map[c];
			}
			else {
				std::cout << c;
			}
		}
		std::cout << std::endl;
		}
	return 0;
	}

Measured memory_bytes: 3140
def some_sums(n):
  answer = 0
  a = n // 10
  if a > 0:
    answer = some_sums(a)
  b = n % 10
  answer = answer + b
  return answer

N,A,B = [int(i) for i in input().split()]

some_sums_list = [some_sums(i+1) for i in range(N)]
answer_list = [i+1 for i in range(N) if some_sums_list[i]>=A and some_sums_list[i]<=B]
answer = sum(answer_list)
print(answer)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define X           first
#define Y           second
#define pb          push_back
#define mp          make_pair
#define SZ(X)       (X.size())
#define mst(a,b)    memset((a),(b),sizeof(a))
#define lowbit(a)   ((a)&(-a))
using namespace std;
typedef unsigned long long ull;
typedef long long LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int mod =  1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn = 2e6+50;
ll a[maxn];
int sgn(ll val){
    if(val>=0)return 1;
    return -1;
}
int main() {
#ifdef local
    freopen("inpp", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // local
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;cin>>n>>k;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    ll ans=INF;
    for(int i=1;i+k-1<=n;++i){
        int en=i+k-1;
        if(sgn(a[en])==sgn(a[i])){
            ans=min(ans,max(abs(a[i]),abs(a[en])));
        }else{
            ans=min(ans,(ll)min(2*a[en]-a[i],a[en]-2*a[i]));
        }
//        cout<<i<<" "<<ans<<endl;
    }
    cout<<ans;
    return 0;


}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  for (int i=K; i<N; i++) {
    if (A[i]>A[i-K]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 5000010
char s[maxn];
int dp[maxn][3];
int main()
{
	int n;cin>>n;
	scanf("%s",s+1);
	int sum=0;
	for(int i=n;i>=1;i--)
	{
		for(int j=0;j<3;j++)
			dp[i][j]=dp[i+1][j];
		if(s[i]=='R') dp[i][0]++;
		if(s[i]=='G') dp[i][1]++;
		if(s[i]=='B') dp[i][2]++;
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(s[i]=='R'&&s[j]=='G') if(s[2*j-i]=='B') ans+=dp[j+1][2]-1;else ans+=dp[j+1][2];
			if(s[i]=='G'&&s[j]=='R') if(s[2*j-i]=='B') ans+=dp[j+1][2]-1;else ans+=dp[j+1][2];
			if(s[i]=='R'&&s[j]=='B') if(s[2*j-i]=='G') ans+=dp[j+1][1]-1;else ans+=dp[j+1][1];
			if(s[i]=='B'&&s[j]=='R') if(s[2*j-i]=='G') ans+=dp[j+1][1]-1;else ans+=dp[j+1][1];
			if(s[i]=='B'&&s[j]=='G') if(s[2*j-i]=='R') ans+=dp[j+1][0]-1;else ans+=dp[j+1][0];
			if(s[i]=='G'&&s[j]=='B') if(s[2*j-i]=='R') ans+=dp[j+1][0]-1;else ans+=dp[j+1][0];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3796
#include <cstdio>

int main() {
    char s1[11], s2[11], s3[11];
    scanf("%s %s %s", s1, s2, s3);
    printf("%c%c%c\n", s1[0] - 'a' + 'A', s2[0] - 'a' + 'A', s3[0] - 'a' + 'A');
}

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

ll func(ll n) {
  if(n <= 0) return 0;
  if(n % 4 == 0) {
    return n;
  }else if(n % 4 == 1) {
    return 1;
  }else if(n % 4 == 2) {
    return 1 ^ n;
  }else {
    return 0;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A, B;
  cin >> A >> B;
  cout <<  ll (func(A - 1) ^ func(B)) << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	auto f = vector<vector<int>>(n, vector<int>(10));
	auto p = vector<vector<int>>(n, vector<int>(11));
	for(auto&& g : f) for(auto&& h : g) cin >> h;
	for(auto&& q : p) for(auto&& r : q) cin >> r;
	int ans = -1000000007;
	for(auto i = 1; i < 1 << 10; ++i){
		int sum = 0;
		for(auto j = 0; j < n; ++j){
			int cnt = 0;
			for(auto k = 0, t = i; k < 10 && t > 0; ++k, t >>= 1){
				if(t % 2 && f[j][k]) ++cnt;
			}
			sum += p[j][cnt];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

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


Measured memory_bytes: 256
#include <iostream>
#include <ctime>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include<cstring>
#include <set>
#include <map>
using namespace std;

int a[100010];
int G[105][105];

int main()
{
    int h,w;
    while(scanf("%d%d",&h,&w)!=EOF)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
            scanf("%d",&a[i]);
        int cnt=1;
        for(int i=1;i<=h;++i)
        {
            if(i&1)
            {
                for(int j=1;j<=w;++j)
                {
                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }else
            {
                for(int j=w;j>=1;--j)
                {
                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }
        }
        for(int i=1;i<=h;++i)
        {
            for(int j=1;j<=w;++j)
            {
                if(j!=w) printf("%d ",G[i][j]);
                else printf("%d\n",G[i][j]);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void){

  int N;
  scanf("%d",&N);
  int i;
  double A[N];
  double count=0;
  for(i=0;i<N;i++){
    scanf("%lf",&A[i]);
    count+=(double)1/A[i];
  }
  double ans;
  printf("%lf",(double)1/count);
  

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    int N, P;
    cin >> N >> P;
    bool odd = false;
    REP(i, N) {
        int A;
        cin >> A;
        if (A % 2) odd = true;
    }

    ll ans;
    if (odd) ans = 1LL << (N-1);
    else if (P) ans = 0;
    else ans = 1LL << N;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define FOR(i,a,n) for(register int i=a; i<=n; ++i)
#define FDR(i,a,n) for(register int i=a; i>=n; --i)
#define mem(a) memset(a, 0, sizeof(a))
#define pb push_back()
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 100005;
const int MOD = 1000000009;
int a[maxn];
int main()
{
    int n;
    cin >> n;
    if(n < 1200)puts("ABC");
    else if(n < 2800)puts("ARC");
    else puts("AGC");
    return 0;
}


Measured memory_bytes: 256
X, Y = gets.split.map(&:to_i)

flg = false
0.upto(X) do |tsuru|
  kame = X - tsuru
  if Y == (tsuru * 2 + kame * 4)
    flg = true
    break
  end
end

if flg
  puts("Yes")
else
  puts("No")
end


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

int main(){
	int a, b, k;
	cin >> a >> b >> k;
	int n = __gcd(a, b);
	vector<int> as(0);
	for(int i=1; i*i<=n; i++){
		if(n%i == 0){
			as.push_back(i);
			if(i != n/i) as.push_back(n/i);/*
			cout << i << ' ';
			if(i != n/i) cout << n/i;
			cout << endl;*/
		}
	}
	sort(as.begin(), as.end());
	reverse(as.begin(), as.end());
	cout << as.at(k-1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int k, a[123567], l = 2, r = 2;
signed main() {
	cin >> k; for1(i, k)cin >> a[i];
	for (int i = k; i >= 1; i--) {
		if (l % a[i] != 0)l += a[i] - l % a[i];
		r -= r % a[i];
		if (l > r) {
			cout << "-1\n";
			return 0;
		}
		r += a[i] - 1;
	}
	cout << l << ' ' << r << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    map<int, int> mp;
    for (int i = 0; i < n; ++i) {
      cin >> A[i];
      mp[A[i]]++;
    }
    long long s = 0;
    for (auto m : mp) {
      long long v = (long long)m.second;
      s += v * (v-1) / 2;
    }
    for (int i = 0; i < n; ++i) {
      long long a = mp[A[i]];
      long long ans = s - a * (a-1) / 2 + (a-1) * (a-2) / 2;
      cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 9856
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct T{
  T(){ac=0;t=0;}
  int n,ac,t;
  vector<int> p;
};
bool operator<(T a,T b){
  if(a.ac!=b.ac){
    return a.ac>b.ac;
  }else if(a.t!=b.t){
    return a.t<b.t;
  }else{
    return a.n>b.n;
  }
}
bool operator==(T a,T b){
  return a.ac==b.ac && a.t==b.t;
}

vector<T> team;
int M,T,P,R;


bool input(){
  cin>>M>>T>>P>>R;
  if(M==0&&T==0&&P==0&&R==0)return false;
  team.clear();team.resize(T);
  for(int i=0;i<T;i++){
    team[i].n=i+1;
    team[i].p.resize(P+1);
  }
  return true;
}

void que(){
  for(int i=0;i<R;i++){
    int m,t,p,j;
    cin>>m>>t>>p>>j;
    t--;p--;
    if(j==0){
      team[t].t += team[t].p[p] + m;
      team[t].ac++;
    }else{
      team[t].p[p]+=20;
    }
  }
}

void solve(){
  sort(team.begin(),team.end());
}

void print(){
  for(int i=0;i<team.size()-1;i++){
    cout<<team[i].n;
    if(team[i]==team[i+1]){
      cout<<"=";
    }else{
      cout<<",";
    }
  }
  cout<<team[team.size()-1].n<<endl;
}

int main(){
  while(input()){
    que();
    solve();
    print();
  }
}

Measured memory_bytes: 1240
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>

#include <unordered_map>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <sstream>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    n=abs(n);
    m=abs(m);
    if(n*m==0)return max(n,m);
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    if((a+d-1)/d>=(c+b-1)/b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3624