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

using namespace std;

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

#define inf INT_MAX/3
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

string S,S1;
int N;

int main(){

	cin >> N >> S;
	S1 = S;
	int left=0,right=0;

	REP(i,S.length()){
		switch(S[i]){
		case '(':
			left++;
			break;
		case ')':
			right++;
			break;
		}
		if(S[i] == ')'){
			if (left == right)
				continue;
			if(left < right){
				int sub = right - left;
				right = left;
				REP(j,sub){
					S1.insert(S1.begin(),'(');
				}
			}
		}
	}
	S = S1;
	left=0;
	right=0;
	RREP(i,S.length()){
		switch(S[i]){
		case '(':
			left++;
			break;
		case ')':
			right++;
			break;
		}
		if(S[i] == '('){
			if (left == right)
				continue;
			if(left > right){
				int sub = left - right;
				left = right;
				REP(j,sub){
					S1.insert(S1.end(),')');
				}
			}
		}
	}
	cout << S1 << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
typedef pair<int,int>pii;
const int mxN=2e5+5,M=1e9+7;
//did u check when n=1?
//is mxN correct?

string s;
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>s;
    if(s=="Sunny")cout<<"Cloudy";
    else if(s=="Cloudy")cout<<"Rainy";
    else cout<<"Sunny";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,m,x[55],y[55],v[55],p,t,xi,yi;

vector <int> g[55];

void DFS(int nod){
    v[nod]=1;
    for(int i : g[nod]){
        if(v[i]){
            if(i==yi && nod!=xi) p=0;
        }
        else DFS(i);
    }
}


int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        cin >> x[i] >> y[i];
        g[x[i]].pb(y[i]);
        g[y[i]].pb(x[i]);
    }
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++) v[j]=0;
        v[y[i]]=1; p=1; xi=x[i]; yi=y[i];
        DFS(x[i]);
        t+=p;
    }
    cout << t;
}


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

int main() {
  int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	cout << a[n-1] - a[0] << endl;
	return 0;
}


Measured memory_bytes: 3632
import numpy as np
n1, n2=input().split(' ')
n1 = int(n1)
n2 = int(n2)
n1_1 =  n1 - 1
result = ''
for  i in range(n2 - n1_1, n2 + n1_1 + 1 ,1):
    result += str(i) + ' '
print(result)

Measured memory_bytes: 12380
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>

#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define RREP(i,a) for(long (i)=(a)-1;(i)>=0;(i)--)
#define FORR(i,a,b) for(long (i)=(a)-1;(i)>=(b);(i)--)
#define MOD 1000000007
#define PI acos(-1.0)
#define DEBUG(C) cout<<C<<endl;
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<long,long>
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).begin(),(a).end(),greater<int>())
#define MP(a,b) make_pair(a,b)
#define FORE(a,b) for(auto &&a:b)

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

int main(void){
	int a,b,c; cin>>a>>b>>c;
	if(a<b && b<c) cout<<"Yes";
	else cout<<"No";
	cout<<endl;
}

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

int main() {
    int n, m;
    cin >> n;
    map<int , int> mp;
    rep(i,n){
        int d;
        cin >> d;
        mp[d]++;
    }
    bool ok = true;
    cin >> m;
    rep(i,m){
        int t;
        cin >> t;
        mp[t]--;
        if(mp[t]<0){
            ok = false;
        }
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main(){
  int n,k;
  cin >>n >>k;
  vector<int> a(n);
  vector<int> cnt(200005);
  rep(i,n){
    cin >>a[i];
    cnt[a[i]]++;
  }
  sort(cnt.begin(), cnt.end());
  reverse(cnt.begin(), cnt.end());
  if(cnt[k]==0){
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for(int i = k;;i++){
    ans += cnt[i];
    if(cnt[i]==0){
      cout << ans << endl;
      return 0;
    }
  }
  return 0; 
}

Measured memory_bytes: 4760
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
const int maxn = 1e5;
int n,num[3][105];
int main(){
	int ans[3][105] = {0};
	cin >> n;
	for(int i = 1;i<=2;i++)
		for(int j = 1;j<=n;j++)
			cin >> num[i][j];
	for(int i = 1;i<=2;i++){
		for(int j = 1;j<=n;j++){
			ans[i][j] = num[i][j]+max(ans[i-1][j],ans[i][j-1]);
		}
	}
	cout << ans[2][n] << endl;
	return 0;
}

Measured memory_bytes: 256
K,X=list(map(int,input().split()))
Min = max(X - (K -1),-1000000)
Max = min(X + (K-1),1000000)
ans = []
for i in range(Min,Max+1):
    ans.append(i)
ans = map(str,ans)
ans = ' '.join(ans)
print(ans)

Measured memory_bytes: 38384
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))
list1=[[0 for i in range(W)] for j in range(H)]
#print(list1)
list2=[]
for k in range(N):
    for l in range(A[k]):
        list2.append(k+1)
for m in range(H):
    for n in range(W):
        if m%2==0:
            list1[m][n]=list2[m*W+n]
        else:
            list1[m][W-n-1]=list2[m*W+n]
for o in range(H):
    ans=str(list1[o][0])
    for p in range(W-1):
        ans=ans+" "+str(list1[o][p+1])
    print(ans)
    

Measured memory_bytes: 3572
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws Exception {
	    String line = Io.read();
	    int[] nums = Arrays.stream(line.split(" "))
                .mapToInt(num -> Integer.parseInt(num))
                .toArray();

	    int count5 = 0, count7 = 0;
        for(int num : nums) {
            if (num == 5) {
                count5++;
            } else if (num == 7) {
                count7++;
            }
        }

	    if (count5 == 2 && count7 == 1) {
	        Io.write("YES");
        } else {
	        Io.write("NO");
        }
    }
}

class Io {

    /**
     * 標準入力から1行ずつ受け取る
     * @return
     * @throws IOException
     */
    public static String read() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();

        return line;
    }

    /**
     * 標準出力
     * @param line
     */
    public static void write(String line)
    {
        System.out.println(line);
    }
}

Measured memory_bytes: 26708
O = list(input())
E = list(input())
pw = ""

if len(O) != len(E):
    for i in range(len(O)-1):
        pw += O[i]+E[i]
        if i == len(O)-2:
            pw += O[len(O)-1]
else:
    for j in range(len(O)):
        pw += O[j]+E[j]

print(pw)

Measured memory_bytes: 9060
#!/usr/bin/env python3
import statistics

n = int(input())

a_list = []
b_list = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    a_list.append(a)
    b_list.append(b)

a_median = statistics.median(a_list)
b_median = statistics.median(b_list)

# print(a_median)
# print(b_median)
if n % 2 != 0:
    print(int(b_median-a_median+1))
else:
    print(int(b_median*2-a_median*2+1))


Measured memory_bytes: 28932
class UnionFind
    def initialize(n)
        @par = Array.new(n)
        n.times{ |i| @par[i] = i }
        @rank = Array.new(n, 0)
    end

    def find(x)
        if @par[x] == x
            x
        else
            @par[x] = find(@par[x])
        end
    end

    def unite(x,y)
        x = find(x)
        y = find(y)
        return if x == y

        if @rank[x] < @rank[y]
            @par[x] = y
        else
            @par[y] = x
            @rank[x] += 1 if @rank[x] == @rank[y]
        end
    end

    def same?(x, y)
        find(x) == find(y)
    end
end

# edge = [src, dst, cost]
def kruskal(n, edges)
    edges = edges.sort_by{|edge| edge[2]}
    uf = UnionFind.new(n)
    res = 0
    edges.each do |edge|
        u = edge[0]
        v = edge[1]
        unless uf.same?(u, v)
            uf.unite(u, v)
            res += edge[2]
        end
    end
    return res
end

N = gets.to_i
xys = []
N.times do |i|
    xys[i] = gets.split.map(&:to_i)
    xys[i].unshift(i)
end

sort_x = xys.sort_by{|a| a[1]}
sort_y = xys.sort_by{|a| a[2]}

edges = []
(sort_x.length - 1).times do |i|
    xy1 = sort_x[i]
    xy2 = sort_x[i + 1]
    dist = [(xy1[1] - xy2[1]).abs, (xy1[2] - xy2[2]).abs].min
    edges.push([ xy1[0], xy2[0], dist ])
end

(sort_y.length - 1).times do |i|
    xy1 = sort_y[i]
    xy2 = sort_y[i + 1]
    dist = [(xy1[1] - xy2[1]).abs, (xy1[2] - xy2[2]).abs].min
    edges.push([ xy1[0], xy2[0], dist ])
end

print kruskal(N, edges)

Measured memory_bytes: 50536
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	vector<int> cnt(N);
	rep(i, 0, N) {
		cnt[a[i]]++;
	}

	bool ng = false;
	int mi = *min_element(all(a));
	int ma = *max_element(all(a));
	vector<int> mcnt(N);
	rep(i, 0, ma + 1) {
		mcnt[max(ma - i, i)]++;
	}
	rep(i, mi, ma + 1) {
		if (mcnt[i] > cnt[i]) {
			ng = true;
		}
		else if (mcnt[i] < cnt[i]) {
			if (mcnt[i - 1] == 0)
				ng = true;
		}
	}
	cout << (ng ? "Impossible" : "Possible") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int b, r, g, c, s, t;
    scanf("%d%d%d%d%d%d", &b, &r, &g, &c, &s, &t);
    if(!(b | r | g | c | s | t))break;

    int res = 100;
    res += 5 * b * 16 + 3 * r * 16 + g * 7 + c * 2 + s * 3;
    res += b * 15 + r * 15;
    res -= t * 3;
    pri(res);

//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#define eps 0.0000000001
#define maxn 5009
#define inf 0x3f3f3f3f
#define mod 1000000009
#define ll long long
using namespace std;
ll n,a,b;
int main()
{
    //freopen("d:\\in.txt","r",stdin);
    scanf("%lld%lld%lld",&n,&a,&b);
    if(b<a||(n==1&&a!=b))
    {
        printf("0\n");
        return 0;
    }
    printf("%lld\n",b*(n-1)+a-a*(n-1)-b+1);
    return 0;
}


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

#define mx 500008

#define pii pair<int,int>
#define pi acos(-1.0)
#define pb push_back
#define ss second
#define ff first
typedef long long int ll;
///adjacent move
int fx[4]={0,+1,0,-1};
int fy[4]={+1,0,-1,0};
///knight
ll prime[mx];

ll a[mx],tree[4*mx];
ll n,m;
void build(ll node,ll s,ll e)
{
    if(s==e){
        tree[node]=a[s];
        return;
    }
    ll mid=(s+e)/2;
    ll left=node*2;
    ll right=node*2+1;
    build(left,s,mid);
    build(right,mid+1,e);
    tree[node]=(tree[left]+tree[right]);
}
void update(ll node,ll s,ll e,ll idx,ll val)
{
    if(s>idx || e<idx) return ;
    if(s==e && s==idx) {

        tree[node]=val;
        return;
    }
    ll mid=(s+e)/2;
    ll left=2*node;
    ll right=left+1;
    update(left,s,mid,idx,val);
    update(right,mid+1,e,idx,val);
    tree[node]=tree[left]+tree[right];
}
ll query(ll node,ll s,ll e,ll i,ll j)
{
    if(i>e || j<s)
        return 0;
    if(s>=i && e<=j)
        return tree[node];
    ll mid=(s+e)/2;
    ll left=2*node;
    ll right=left+1;
    ll x=query(left,s,mid,i,j);
    ll y=query(right,mid+1,e,i,j);
    return (x+y);
}
int last[mx];
int tot[mx];
int ans[mx];
vector<pii>v[mx];
int main()
{
    int t=1;
    //cin>>t;
    int c=0;
    while(t--){
        ll n,m;
        memset(ans,0,sizeof(ans));
        memset(last,0,sizeof(last));
        memset(v,0,sizeof(v));
        memset(tree,0,sizeof(tree));
        cin>>n>>m;
        for(int i=1;i<=n;i++) cin>>a[i];
        for(int i=1;i<=m;i++){
            int l,r;
            cin>>l>>r;
            v[r].push_back({l,i});
        }

        for(int i=1;i<=n;i++){
            update(1,1,n,i,1);
            if(last[a[i]]!=0)
            update(1,1,n,last[a[i]],0);
            last[a[i]]=i;
            for(int j=0;j<v[i].size();j++){
                int idx=v[i][j].ss;
                int val=v[i][j].ff;
                ans[idx]=query(1,1,n,val,i);
            }
        }

        for(int i=1;i<=m;i++) cout<<ans[i]<<"\n";


    }
}


Measured memory_bytes: 48816
import java.util.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        long[] A = new long[N];
        for (int i = 0; i < N ;i++) {
            A[i] = sc.nextLong();
            if (A[i] == 0) {
                System.out.println(0);
                return;
            }
        }

        BigInteger ans = BigInteger.ONE;
        for (int i = 0; i < N ;i++) {
            ans = ans.multiply(BigInteger.valueOf(A[i]));
            if (BigInteger.valueOf(1000000000000000000L).compareTo(ans) == -1) {
                System.out.println(-1);
                return;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 61748
#include <iostream>
using namespace std;
int main(void){
    int n;
    std::cin >> n;
    int h[100000];
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }
    
    if(n==1){
        std::cout << "Yes" << std::endl;
        return 0;
    }

    for (int i = 1; i < n; i++) {
        if(h[i-1]>h[i] || h[i-1]<=h[i]-1){
            h[i]--;
        }
        if(h[i-1]>h[i]){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
    return 0;
}


Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))

m = len([ 1 for x in A if x < 0])
if m % 2 == 0:
  print(sum([abs(x) for x in A]))
else:
  print(sum([abs(x) for x in A]) - 2 * min([abs(x) for x in A]))

Measured memory_bytes: 14284
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

piipii c[405];
piipii rotate(piipii x){
    return mp(mp(x.se.se, x.fi.fi), mp(x.fi.se, x.se.fi));
}

ll get_idx(piipii x){
    return x.fi.fi*1ll*1000*1000*1000 + x.fi.se*1ll*1000*1000 + x.se.fi*1ll*1000 + x.se.se;
}
gp_hash_table<ll, int> dp;

void add(piipii p){
    for(int k=0;k<4;k++){
        dp[get_idx(p)]++;
        p = rotate(p);
    }   
}
void del(piipii p){
    for(int k=0;k<4;k++){
        dp[get_idx(p)]--;
        p = rotate(p);
    }
}

int main(){
    int n;
    scanf("%d", &n);   
    for(int i=1;i<=n;i++){
        scanf("%d%d%d%d", &c[i].fi.fi, &c[i].fi.se, &c[i].se.fi, &c[i].se.se);
        add(c[i]);
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        piipii p1 = c[i];
        del(p1);
        for(int j=i+1;j<=n;j++){
            piipii p2 = c[j];
            del(p2);
            for(int k=0;k<4;k++){
                ll res = 1;
                piipii tmp1 = mp(mp(p1.fi.se, p1.fi.fi), mp(p2.fi.se, p2.fi.fi));
                piipii tmp2 = mp(mp(p1.fi.se, p2.fi.fi), mp(p2.se.se, p1.se.fi));
                piipii tmp3 = mp(mp(p1.se.se, p1.se.fi), mp(p2.se.se, p2.se.fi));
                piipii tmp4 = mp(mp(p2.fi.se, p1.fi.fi), mp(p1.se.se, p2.se.fi));
                if(dp.find(get_idx(tmp1)) != dp.end()){
                    res *= dp[get_idx(tmp1)];
                    del(tmp1);
                }
                else res = 0;
                if(dp.find(get_idx(tmp2)) != dp.end()){
                    res *= dp[get_idx(tmp2)];
                    del(tmp2);
                }
                else res = 0;
                if(dp.find(get_idx(tmp3)) != dp.end()){
                    res *= dp[get_idx(tmp3)];
                    del(tmp3);
                }
                else res = 0;
                if(dp.find(get_idx(tmp4)) != dp.end()){
                    res *= dp[get_idx(tmp4)];
                    del(tmp4);
                }
                else res = 0;

                ans += res;

                if(dp.find(get_idx(tmp1)) != dp.end()){
                    add(tmp1);
                }
                if(dp.find(get_idx(tmp2)) != dp.end()){
                    add(tmp2);
                }
                if(dp.find(get_idx(tmp3)) != dp.end()){
                    add(tmp3);
                }
                if(dp.find(get_idx(tmp4)) != dp.end()){
                    add(tmp4);
                }

                p2 = rotate(p2);
            }
            add(p2);
        }
        add(p1);
    }
    printf("%lld\n", ans/3);
}

Measured memory_bytes: 3888
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <cstring>
#include <stack>
#include <cstdio>
#include <complex>
#include <iomanip>
#include <cctype>
#include <cassert>
#include <numeric>
#include <climits>
#include <deque>
#include <random>
#include <functional>
#include <unordered_map>
#define rep(i,n) for(int i=0;i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define show(x) cout << #x << " = " << x << endl;
int main(){
    string s,t;
    cin >> s >> t;
    string ss = t;
    reverse(ss.begin(),ss.end());
    string tt = s;
    reverse(tt.begin(),tt.end());
    if(ss == s and tt == t){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
vList = list(map(int,input().split()))
pList = list(map(int,input().split()))

for i in range(n):
  vList[i] -= pList[i]

resultList = sorted(vList,reverse = True)

count = 0
for i in resultList:
  if i > 0:
    count += i
  else:
    break

print(count)


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

// f(n,k,s) = # partial permutations on n elements with k unmatched elements and total oddness s

const ll N = 55, MOD = 1e9 + 7;
ll dp[N][N][N*N];

void add_mod(ll &x, ll y) {
	x = (x+y) % MOD;
}

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

	dp[0][0][0] = 1;
	FOR(n,0,N-1) FOR(k,0,N-1) FOR(s,0,N*N) {
		ll cur = dp[n][k][s];
		if (cur == 0) continue;

		if (k > 0) add_mod(dp[n+1][k-1][s + 2*(k-1)], k*k*cur);
		if (k > 0) add_mod(dp[n+1][k][s + 2*k], 2*k*cur);
		add_mod(dp[n+1][k+1][s + 2*(k+1)], cur);
		
		add_mod(dp[n+1][k][s + 2*k], cur);
	}

	ll n, s;
	cin >> n >> s;
	cout << dp[n][0][s] << endl;
}



Measured memory_bytes: 68992
# coding: utf-8

def main():
    A = []
    num = [1 for _ in range(101)]
    C = [
        [0, 1, 2],
        [3, 4, 5],
        [6, 7, 8],
        [0, 3, 6],
        [1, 4, 7],
        [2, 5, 8],
        [0, 4, 8],
        [2, 4, 6],
    ]
    ans = 'No'
    
    for _ in range(3):
        for i in list(map(int, input().split())):
            A.append(i)
        

    N = int(input())

    for _ in range(N):
        num[int(input())] -= 1

    for c in C:
        if num[A[c[0]]] == 0 and num[A[c[1]]] == 0 and num[A[c[2]]] == 0:
            ans = 'Yes'
            break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8928
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  ll S;
  cin>>S;
  if(S==1000000000000000000){
    cout<<0<<" "<<0<<" "<<1000000000<<" "<<0<<" "<<1000000000<<" "<<1000000000<<endl;
    return 0;
  }
  ll A=S/1000000000;
  ll B=S%1000000000;
  cout<<0<<" "<<0<<" "<<1000000000<<" "<<1<<" "<<1000000000-B<<" "<<A+1<<endl;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15)+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
using pli=pair<llint,int>;
using daic=priority_queue<pli,vector<pli>,greater<pli>>;
int main(void){
	int n,m,a,b,i,j;cin>>n>>m>>a>>b;
	int ta=0,yo=0,ro=0;
	ro=2*(n/2)*(m/2);
	yo=(n%2)*(m/2);
	ta=(n/2)*(m%2);
	if((a>0&&m==0)||(b>0&&n==0)){cout<<"NO\n";RE;}
	if(a>yo+ro||b>ta+ro||a+b>yo+ro+ta){cout<<"NO\n";RE;}
	if(((n%2==0)||(m%2==0))&&a+b==yo+ro+ta&&(a-yo)%2==1){cout<<"NO\n";RE;}
	cout<<"YES\n";
	vector<string>ans(n,string(m,'.'));
	if(m%2==1){
		for(i=0;i+1<n;i+=2){
			if(b<=0){break;}b--;
			ans[i][m-1]='^';
			ans[i+1][m-1]='v';
		}
	}
	if(n%2==1){
		for(j=0;j+1<m;j+=2){
			if(a<=0){break;}a--;
			ans[n-1][j]='<';
			ans[n-1][j+1]='>';
		}
	}
	for(i=0;i+1<n;i+=2){
		for(j=0;j+1<m;j+=2){
			//cerr<<"de "<<i<<" "<<j<<endl;
			if(a>=2){a-=2;
				  ans[i][j]='<';  ans[i][j+1]='>';
				ans[i+1][j]='<';ans[i+1][j+1]='>';
			}else if(b>=2){b-=2;
				  ans[i][j]='^';  ans[i][j+1]='^';
				ans[i+1][j]='v';ans[i+1][j+1]='v';
			}else if(a>0){a--;
				ans[i][j]='<';  ans[i][j+1]='>';
			}else if(b>0){b--;
				  ans[i][j]='^';
				ans[i+1][j]='v';
			}
		}
	}
	if(b>0){//奥の手
		ans[n-2][m-3]='^';
		ans[n-1][m-3]='v';ans[n-1][m-2]='<';ans[n-1][m-1]='>';
	}
	for(auto it:ans){cout<<it<<endl;}
	RE;
}

Measured memory_bytes: 2304
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main(){
	FIO
	
	int a, b, c;
	cin >> a >> b >> c;
	if((b * 10 + c) % 4)puts("NO");
	else puts("YES");
	return 0;
}


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

#define pb(a) push_back(a)

typedef long long ll;
const ll inf = 1e9+7;
const int dsize = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;
priority_queue<ll,vector<ll>,greater<ll>> ql;
multiset<pair<ll,ll>> qr;

ll inv[dsize],fac[dsize];

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

bool comp(pair<ll,ll> &a,pair<ll,ll> &b) {
	if (a.first==b.first) {return a.second >= b.second;}
	else {return a.first > b.first;}
}

int main() {
    int n;cin>>n;ll sum=0;
    ll suml=0,disl=0,sumr=0,disr=0,maxl=0,maxr=0,minl=inf,minr=inf;
    ll taimahensyu = -inf;
    ll a[3*n];
    pair<ll,ll> back[2*n];
    for(int i=0;i<3*n;i++) {
        cin>>a[i];
        sum+=a[i];
        if (i<n) {
            suml+=a[i];
            ql.push(a[i]);
        } else if (n<=i) {
            sumr+=a[i];
            back[i-n] = {a[i],i};
        }
    }
    sort(back,back+2*n,comp);
    for (int i = 0;i < n;i++) {
    	qr.insert(back[i]);
    	disr+=back[i].first;
    }
    taimahensyu = (suml-disl)-(sumr-disr);
    for(int i=0;i<=n;i++) {
        taimahensyu = max(taimahensyu,(suml-disl)-(sumr-disr));
        if (i==n) break;
        ll now=ql.top();
        ql.pop();
        ql.push(a[n+i]);
        if (qr.find({a[n+i],n+i}) != qr.end()) {
        	qr.erase({a[n+i],n+i});
        	disr-=a[n+i];
        } else {
        	disr-=qr.begin()->first;
        	qr.erase(*qr.begin());
        }
        suml+=a[n+i];
        sumr-=a[n+i];
        disl+=now;
    }
    cout << taimahensyu << endl;
}

Measured memory_bytes: 12788
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner s = new Scanner(System.in);
        System.out.println(Arrays.toString(IntStream.of(s.nextInt(), s.nextInt(), s.nextInt()).sorted().toArray()).replaceAll("[\\[\\],]", ""));
    }
}

Measured memory_bytes: 31960
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;


int main() {
vector<int> vec(3);
for (int i = 0;i < 3;i++) cin >> vec.at(i);
sort(vec.begin(),vec.end());
int ans = vec.at(1) - vec.at(0) + (vec.at(2) - vec.at(1));
cout << ans << endl;



return 0;
}


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

int main()
{
    int n, a;
    cin >> n;
    a = n % 10;
    if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9) cout << "hon" << endl;
    else if (a == 0 || a == 1 || a == 6 || a == 8) cout << "pon" << endl;
    else cout << "bon" << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
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; }

// 素因数分解O(√n)
// 12 -> [(2,2), (3,1)] (2^2*3^1)

vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> 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 () {
  int n = in();
  int ans = 0;
  for (int i = 1; i <= n; i+=2) {
    auto x = factorize(i);
    int cnt = 1;
    for (auto p : x) {
      cnt *= (1+p.se);
    }
    if (cnt == 8) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int n;
	scanf("%d",&n);
	int sx = 0,sy = 0,tim = 0;
	int f  = 0;
	for(int i = 1;i <= n;i++){
		int x,y,t;
		scanf("%d %d %d",&t,&x,&y);
		if(t - tim == abs(x-sx)+abs(y-sy) ||(t-tim-(abs(x-sx)+abs(y-sy)))%2==0 && t-tim>(abs(x-sx)+abs(y-sy)) ){
			sx = x;
			sy = y;
			tim = t;
		}
		else{
			f = 1;
			break;
		}
	}
	if(f) printf("No\n");
	else printf("Yes\n");
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,k,a[200010],b[200010];

int main()
{
	cin>>n>>k;
	rep(i,n) scanf("%d",&a[i]);
	rep(i,k)
	{
		memset(b,0,sizeof(b));
		rep(j,n)
		{
			b[max(0,j-a[j])]++;
			b[min(n,j+a[j]+1)]--;
		}
		int cur=0,ok=1;
		rep(j,n)
		{
			cur+=b[j];
			if(cur<n) ok=0;
			a[j]=cur;
		}
		if(ok) break;
	}
	rep(i,n) printf("%d ",a[i]);
	cout<<endl;
	return 0;
}

Measured memory_bytes: 5364
def main(): 
    s = input()
    t = input()

    cnt = 0
    if s[0] == t[0]:
        cnt += 1
    if s[1] == t[1]:
        cnt += 1
    if s[2] == t[2]:
        cnt += 1
    print(cnt)

if __name__ == "__main__":
    main() 

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define for(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
string S, T;cin >> S >> T;
int count = 0;
for(i, 0, S.size()){
if(S[i] != T[i])count++;}
cout << count << endl;
}

Measured memory_bytes: 3916
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

typedef long long ll;
const int maxn = 200200;

void solve()
{
    int h, n;
    cin >> h >> n;
    ll s = 0;
    for (int i = 0; i < n; i++){
        ll x;
        cin >> x;
        s += x;
    }
    if (h - s <= 0)
        puts("Yes");
    else
        puts("No");
}

void sec(){

}

int main()
{
    int t;
    solve();
    return (0);
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int d[200],l[200],n,x,ans;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>x;
    for(int i=1;i<=n;i++)cin>>l[i];
    for(int i=1;i<=n+1;i++){
        d[i] = d[i-1]+l[i-1];
        if(d[i]<=x){ans++;}
        else break;
    }
    cout<<ans<<newl;


}


Measured memory_bytes: 256
i,t;p(n){for(i=t=2;i*i<=n;++i){n%i?:t++;}return t-2;}main(l,u){for(;scanf("%d",&l),u=l;){for(;p(l);l--);for(;p(u);u++);printf("%d\n",u-l);}return 0;}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int map1[26];
int map2[26];
void bit(){
      int a,b,c;
      cin >> a >> b >> c;
      int ans=0;
      while(a*c>b)c--;
      ans=c;
      cout<<c<<"\n";
}

int main() {
    int t=1;

    while(t--){
        bit();
        
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll A, B; cin >> A >> B;
  ll aa, bb;
  if(B==0){
    cout << 0 << endl;
    return 0;
  }
  else{
    if(B%4==1){
      bb = 1;
    }
    else if(B%4==3){
      bb = 0;
    }
    else{
      ll B_ = B+1;
      if(B_%4==1){
        bb = 1^B_;
      }
      else{
        bb = 0^B_;
      }
    }
  }
  if(A==0){
    cout<< bb << endl;
    return 0;
  }
  A--;
  if(A%4==1){
    aa = 1;
  }
  else if(A%4==3){
    aa = 0;
  }
  else{
    ll A_ = A+1;
    if(A_%4==1){
      aa = 1^A_;
    }
    else{
      aa = 0^A_;
    }
  }
  ll ans = aa^bb;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

LL gcd(LL x, LL y) {
    if (x < y) { swap(x, y); }
    if (y == 0) { return x; }
    return gcd(y, x % y);
}

struct mobile {
    int lb;
    int rb;
    LL lm;
    LL rm;
};

int N;
mobile ms[110];

int get_root() {
    for (int j = 0; j < N; ++j) {
        bool found = false;
        for (int k = 0; k < N; ++k) {
            if (ms[k].lm == j || ms[k].rm == j) {
                found = true;
                break;
            }
        }
        if (!found) {
            return j;
        }
    }
    return -1;
}

LL rec(int x) {
    mobile& m = ms[x];

    LL t = gcd(m.lb, m.rb);

    if (m.lm == -1 && m.rm == -1) {
        return (m.lb + m.rb) / t;
    }

    LL lw, rw, z;
    if (m.lm != -1 && m.rm == -1) {
        lw = rec(m.lm);
        z = (lw * m.lb * m.rb) / gcd(lw * m.lb, m.rb);
        lw *= z / (lw * m.lb);
        rw = lw * m.lb / m.rb;
    } else if (m.lm == -1 && m.rm != -1) {
        rw = rec(m.rm);
        z = (rw * m.rb * m.lb) / gcd(rw * m.rb, m.lb);
        rw *= z / (rw * m.rb);
        lw = rw * m.rb / m.lb;
    } else {
        lw = rec(m.lm);
        rw = rec(m.rm);
        LL z = lw * m.lb / gcd(lw * m.lb, rw * m.rb) * rw * m.rb;
        lw *= z / (lw * m.lb);
        rw *= z / (rw * m.rb);
    }

    assert(lw * m.lb == rw * m.rb);
    return lw + rw;
}

bool solve() {
    cin >> N;
    if (N == 0) {
        return false;
    }
    for (int j = 0; j < N; ++j) {
        cin >> ms[j].lb >> ms[j].rb >> ms[j].lm >> ms[j].rm;
        --ms[j].lm; --ms[j].rm;
    }

    LL root = get_root();
    assert(root != -1);

    cout << rec(root) << endl;

    return true;
}

int main() {
    while(solve());
}

Measured memory_bytes: 3088
def icpc()
  while true
    judges = gets.to_i
    break if judges == 0
    a = []
    for i in 0..judges-1
      a << gets.to_i
    end
    sum = 0
    for i in 0..judges-1
      sum += a[i]
    end
    sum -= (a.max + a.min)
    puts sum/(judges-2)
  end
end

icpc()

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

int main () {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int X = A + B;
  int Y = C + D;
  if (X == Y) {
    cout << "Balanced" << endl;
  }
  else if (X > Y) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
  
}






Measured memory_bytes: 256
in_s = input().rstrip()
lst = list(in_s)
cur=0
while True:
    if cur+1 >= len(lst):
        break
    if lst[cur]!=lst[cur+1]:
        del lst[cur+1]
        del lst[cur]
        cur = max(0,cur-1)
    else:
        cur+=1
 
print(len(in_s) - len(lst))

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll long long

int main() {
	int x;

	cin >> x;
	int ans = 1;
	if (x < 600)
		ans = 8;
	else if (x < 800)
		ans = 7;
	else if (x < 1000)
		ans = 6;
	else if (x < 1200)
		ans = 5;
	else if (x < 1400)
		ans = 4;
	else if (x < 1600)
		ans = 3;
	else if (x < 1800)
		ans = 2;

	//答え
	cout << ans << endl;
}


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

void file() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
}

string a, b;

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

    cin>>a>>b;

    if (b.size() > a.size())
    {
        return cout<<"UNRESTORABLE", 0;
    }

    deque<char>d;
    d.push_back('.');
    for (int i = (int)a.size() - 1; i > b.size(); --i)
    {
        d.push_front(a[i]);
    }
    for (int i = a.size(); i >= 0; --i)
    {
        d.pop_back();
        d.push_front(a[i]);
        int cnt = 0;
        for (int j = 0; j < b.size(); ++j)
        {
            if (b[j] == d[j] or d[j] == '?')
            {
                cnt++;
            }
            else break;
        }
        if (cnt == (int)b.size())
        {
            for(int j = 0; j < i; j++)
                cout<<(a[j] == '?'?'a':a[j]);
            cout<<b;
            for(int j = b.size() + i; j < a.size(); j++)
                cout<<(a[j] == '?'?'a':a[j]);
            return 0;
        }
    }
    cout<<"UNRESTORABLE";

}

Measured memory_bytes: 256
H,W = map(int,input().split(" "))
A = [0]*(H+1)
o = 0
for i in range(H):
    a = list(input())
    o += a.count('#')
    A[i] = a + ['.']

A[-1] = ['.'] * (W+1)

x = 0
y = 0
p = 1

while x < W and y < H:
    right = A[y][x+1] == '#'
    down = A[y+1][x] == '#'
    if right:
        x += 1
        p += 1
    elif down:
        y += 1
        p += 1
    else:
        break

print(['Impossible','Possible'][o == p])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()), ((v).end())
#define INF 1e9
#define EPS 1e-9
#define bitcount __builtin_popcount
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define LSOne(S) (S & (-S))
#define PI acos(-1.0)
#define P(x) cout << #x << " = { " << x << " }\n"
#define tests()  \
    int tttt;    \
    cin >> tttt; \
    while (tttt--)
#define fast_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define file_IO                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout)
typedef long long ll;
int dcmp(long double x, long double y)
{
    return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1;
}
const int MAX = 1e3 + 10;
const int MOD = 1e9 + 7;
int n, m;
int memo[MAX][MAX];
bool vis[MAX];
string grid[MAX];
void read();
void solve();
void clear();
int dp(int i, int j);
int main()
{
#ifndef ONLINE_JUDGE
    file_IO;
#else
    fast_IO;
#endif

    solve();
}
void read()
{
    cin >> n >> m;
    lp(i, n) { cin >> grid[i]; }
}
void clear()
{
    clr(memo, -1);
}
void solve()
{
    read();
    //clear();
    //   cout << dp(0, 0) << '\n';
    memo[n - 1][m - 1] = 1;
    for (int i = n - 1; i >= 0; i--)
    {
        for (int j = m - 1; j >= 0; j--)
        {
            if (grid[i][j] != '#')
            {
                if (i + 1 < n)
                    memo[i][j] += memo[i + 1][j] % MOD;
                if (j + 1 < m)
                    memo[i][j] += memo[i][j + 1] % MOD;
                memo[i][j] %= MOD;
            }
        }
    }
    cout << memo[0][0] % MOD << '\n';
}
int dp(int i, int j)
{
    if (i == n - 1 && j == m - 1)
        return 1;
    int &ret = memo[i][j];
    if (ret != -1)
        return ret;
    int path = 0;
    int path2 = 0;
    if (i + 1 < n && grid[i + 1][j] != '#')
        path = dp(i + 1, j);
    if (j + 1 < m && grid[i][j + 1] != '#')
        path2 = dp(i, j + 1);

    return ret = (path2 % MOD + path % MOD) % MOD;
}

Measured memory_bytes: 8572