akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{     
  long long a,b,t1,i,t2,g=1;
  scanf("%lld %lld",&a,&b);
  t1=a;
  t2=a;
  if(t1>b)
  t1=b;
  if(t2<b)
  t2=b;
  for(i=t1;i<=t2;i++)
  {
  	if(fabs(a-i)==fabs(b-i))
  	{printf("%lld",i);g=0;break;
	  }
  }
  if(g==1)
  printf("IMPOSSIBLE");
}

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

#define ll long long

inline ll read() {
    ll x = 0, f = 1; char ch = getchar();
    for(; ch < '0' || ch>'9'; ch = getchar())
        if(ch == '-') f = -f;
    for(; ch >= '0' && ch <= '9'; ch = getchar())
        x = x * 10 + ch - '0';
    return x * f;
}

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

inline void chkmax( int &a, int b ) { if(a < b) a = b; }

#define _ read()

#define ln endl

const int N = 1e6 + 5;
const int mod = 998244353;
int f[N], mu[N], a[N], p[N], vis[N], inv[N], cnt, n;

inline int power( int a, int b ) 
{
	int tmp = 1;
	while(b)
	{
		if(b & 1) tmp = 1ll * tmp * a % mod;
		a = 1ll * a * a % mod; 
		b >>= 1;
	} 
	return tmp;
}

int main()
{
	n = _; 
	// inv[1000000] = power(1000000, mod - 2); 
	for( int i = 1000000; i; i-- )
		inv[i] = power(i, mod - 2);
	mu[1] = 1;
	for ( int i = 2; i <= 1000000; i++ ) 
	{
		if(!vis[i]) p[++cnt] = i, mu[i] = -1;
		for ( int j = 1; j <=cnt && i * p[j] <= 1000000; j ++ ) 
		{
			vis[i * p[j]] = 1; 
			if( i % p[j] ) mu[i * p[j]] = -mu[i];
			else { mu[i * p[j]] = 0; break; }  
		}
	}
	int sum = 0;
	for( int i = 1, x; i <= n; i++ )
		a[x = _]++, sum = (sum + x) % mod;
	// cout << sum << ln;
	for( int i = 1; i <= 1000000; i++ )
	{
		for( int j = 1; j * i <= 1000000; j++ ) 
			f[i] = ( f[i] + 1ll * a[i * j] * j % mod * i % mod ) % mod;
		f[i] = 1ll * f[i] * f[i] % mod;
	}
	int ans = 0;
	for( int i = 1; i <= 1000000; i++ )
	{	
		int tot = 0;
		for( int j = 1; i * j <= 1000000; j++ )
			tot = ( tot + 1ll * mu[j] * f[i * j] % mod ) % mod;
		ans = ( ans + 1ll * tot * inv[i] % mod ) % mod;
		// ans = ans + tot / i;
	}
	// cout << inv[2] << ln;	
	// cout << ans << ln;
	// ans = ( ans - sum ) / 2;
	ans = 1ll * ( ans - sum + mod ) % mod * inv[2] % mod;
	cout << ans << ln;
}

Measured memory_bytes: 21632
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	El3zba;
	int k, x;
	cin >> k >> x;
	if (k == 1)return cout << x << endl, 0;
	set<int>ans;
	ans.insert(x);
	int tempk = k,tempx=x;
	while (k>1)
	{
		x--;
		ans.insert(x);
		k--;
	}
	k = tempk;
	x = tempx + 1;
	while (k-- > 1)
		ans.insert(x), x++;
	for (auto&x : ans)
		cout << x << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() { 
    int n;
    cin>>n;
    VI a(n-1);
    rep(i,n-1) cin>>a[i];

    ll sum=0;
    rep(i,n-2){
      sum+=min(a[i],a[i+1]);
    }
    sum+=a[0]+a[n-2];
    cout<<sum<<endl;
}



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

int main(){
  long n,sum=0,x,q,b,c; cin>>n;
  map<long,long> mp;
  
  rep(i,n){
    cin>>x;
    sum+=x;
    mp[x]++;
  }
  
  cin>>q;
  
  
  rep(i,q){
    cin>>b>>c;
    sum+=(c-b)*mp[b];
    mp[c]+=mp[b];
    mp[b]=0;
    cout<<sum<<endl;
  }
  

}

Measured memory_bytes: 9544
// Virtual

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

// Utility
#define ALL(X) (X).begin(), (X).end()
#define RANGE(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
namespace std {
template<class ...Ts>        istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { i >> x.first >> x.second; return i; }
template<class T>            istream& operator>>(istream& i, vector<T>& x)    { for (auto& y : x) { i >> y; } return i; }
}

// Debugging
#define DD(X) std::cout << #X ": " << (X) << std::endl << std::flush
namespace std {
template<class ...Ts>        ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; apply([&](auto&& y, auto&&... ys){ o << y; ((o << ", " << ys), ...); }, x); o << ")"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { o << tie(x.first, x.second); return o; }
template<class T>            ostream& operator<<(ostream& o, const vector<T>& x)    { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const set<T1, T2>& x)  { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& x)  { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
}

// Main
void mainCase() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> edges(m, {0, 0});
  cin >> edges;

  vector<vector<int>> adj(n, vector<int>(0, 0));
  RANGE(i, 0, m) {
    auto [x, y] = edges[i];
    adj[x - 1].push_back(y - 1); // zero-based index
    adj[y - 1].push_back(x - 1);
  }

  vector<int> distances(n, -1);
  vector<int> parents(n, -1);

  // Min heap
  set<tuple<int, int, int>> heap; // (distance, vertex, parent)
  heap.insert({0, 0, -1});
  while (!heap.empty()) {
    auto top = heap.begin();
    auto [dist, v0, p0] = *top;  heap.erase(top);
    if (distances[v0] != -1) { continue; }
    distances[v0] = dist;
    parents[v0] = p0;
    for (auto v1 : adj[v0]) {
      if (distances[v1] != -1) { continue; }
      heap.insert({dist + 1, v1, v0});
    }
  }
  // DD(adj);
  // DD(edges);
  // DD(distances);
  // DD(parents);

  bool disconn = false;
  RANGE(i, 0, n) {
    if (distances[i] == -1) {
      disconn = true;
      break;
    }
  }

  if (disconn) {
    cout << "No" << endl;
    return;
  }

  cout << "Yes" << endl;
  RANGE(i, 1, n) {
    int j = parents[i] + 1; // one-based index
    cout << j << endl;
  }
}

int main() {
  mainCase();
  return 0;
}


Measured memory_bytes: 19640
#include<stdio.h>
int main()
{
	long long int a,b,d;
	scanf("%lld %lld %lld",&a,&b,&d);
	long long int ans;
	if(b>d||a==1&&b!=d)
		ans=0;
	else if(a<=2)
		ans=1;
	else
		ans=(a-2)*(d-b)+1;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N=200005;
#define inf 1e18+8
const int mod=1e9+7;
#define pii pair<int, int>
#define vi vector<int>
#define vf vector<float>
#define sz(x) x.size()
#define float double
#define set multiset
//#define all((int)x) begin(x), end(x)
#define vpii vector<pair<int,int> > 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int arr[N];
int n,k;
#define PI 3.14159265

signed main()
{
  
       // cout<<sin();
        int x1;cin>>x1;
        float x=0,y=1;
        int cnt=1;
        int theta=0;
        while(true)
        {
            theta=theta+x1;
            //cout<<theta;
       //     if(theta<=360) cout<<theta;
            x=x+sin(theta*PI/180);
            y=y+cos(theta*PI/180);
            cnt++;
            if(abs(x)<0.001 && abs(y)<0.001)
            {
                cout<<cnt;
                break;
                return 0;
            }

        }

}
 
    

Measured memory_bytes: 3888
from collections import defaultdict
import bisect

S = input()
T = input()

d = defaultdict(list)
for i, s in enumerate(S, start=1):
    d[s].append(i)

ans = 0
i = 0

for t in T:
    if not d[t]:
        print(-1)
        exit()

    if i >= d[t][-1]:
        ans += len(S)
        i = d[t][0]
        continue

    pos = bisect.bisect_right(d[t], i)
    i = d[t][pos]

ans += i
print(ans)


Measured memory_bytes: 7924
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
const double inf=1e9;
typedef long long ll;
typedef pair<int,int>pr;
const ll mod=1e9+7;
ll _pow(ll  a,ll b) {
    ll ans=1;
    while(b) {
        if(b&1)
            ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}

int main(){
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll a,b;
  cin>>a>>b;
  if((a+b)%2==0){
    cout<<(a+b)/2<<endl;
  }
  else{
    cout<<"IMPOSSIBLE"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b+1 >= c) cout << b+c << endl;
    else cout << a+2*b+1 << endl;
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())
opened = []
x = 1
while True:

    if (A * x) % B == C:
        print('YES')
        exit(0)
    else:
        if (A * x) % B in opened:
            print('NO')
            exit(0)
        opened.append((A * x) % B)
        x += 1


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <set>
#include <climits>

using namespace std;

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

int main() {
    int A, B;
    scanf("%d %d", &A, &B);
    printf("%d\n", max(0, (A - B * 2)));
    return 0;
}



Measured memory_bytes: 256
<?php

$max = 51000;
$arr = new \SplFixedArray($max + 1);
for ($i = 2; $i <= $max; $i++) {
    $arr[$i] = 1;
}
for ($i = 2, $len = sqrt($max); $i <= $len; $i++) {
    if (!$arr[$i]) {
        continue;
    }

    for ($j = $i, $len2 = $max / $i; $j <= $len2; $j++) {
        $arr[$i * $j] = 0;
    }
}

while (($line = trim(fgets(STDIN))) !== '') {
    sscanf($line, '%d', $n);
    for ($i = $n - 1; $i >= 2; $i--) {
        if ($arr[$i]) {
            echo "$i ";
            break;
        }
    }

    for ($i = $n + 1; $i < $max; $i++) {
        if ($arr[$i]) {
            echo "$i\n";
            break;
        }
    }
}

Measured memory_bytes: 9384
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int vx[]={ 0, 1,-1, 0, 0,-1,-1, 1, 1, 2,-2, 0, 0};
int vy[]={ 0, 0, 0, 1,-1,-1, 1,-1, 1, 0, 0, 2,-2};
int x,y,size;
int map[10][10];
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
map[i][j]=0;
}
}
int nm_ans=0,max_ans=0;
while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
switch(size){
case 1:
for(int i=0;i<5;i++){
if((min(x+vx[i],y+vy[i])>=0)&&max(x+vx[i],y+vy[i])<10){
map[x+vx[i]][y+vy[i]]++;
}
}
break;
case 2:
for(int i=0;i<9;i++){
if((min(x+vx[i],y+vy[i])>=0)&&max(x+vx[i],y+vy[i])<10){
map[x+vx[i]][y+vy[i]]++;
}
}
break;
case 3:
for(int i=0;i<13;i++){
if((min(x+vx[i],y+vy[i])>=0)&&max(x+vx[i],y+vy[i])<10){
map[x+vx[i]][y+vy[i]]++;
}
}
break;
}
}
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
if(map[i][j]>max_ans){
max_ans=map[i][j];
}
if(map[i][j]==0){
nm_ans++;
}
}
}
cout<<nm_ans<<endl;
cout<<max_ans<<endl;
return 0;
}

Measured memory_bytes: 1208
/*
Dont BLUNDER
*/
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;*/
 
//#define d long double
#define int long long
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define inf (int)1e18
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod1=998244353;
int const mod=1000000007;
#define l first
#define r second
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 #define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// ******** Using PBDS ********
 /*typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
                os; */
 
int modexp(int x, int n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}
 
int modinv(int n)
{
	return modexp(n,mod-2);
}
int go(int x)
{
    int ans=0;
    for(int i=1;i<=x;i++)
    {
        if((i)*(i+1)<=2*x)
        {
            ans=i;
        }
        else
        break;
    }
    return ans;
}


signed main() {
	haha
	long  double a,b;
	cin>>a>>b;
	a*=b;
	//cout<<fixed<<setprecision(20)<<a<<endl;
	cout<<(int)(a);




}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
typedef tuple<double,ll,ll>T;
#define PI 3.14159265358979
#define MOD 998244353

int main(){
  ll N,K;
  string S;
  cin>>N>>K>>S;
  vector<ll>A;
  vector<ll>B;
  ll i=0;
  if(S[0]=='0'){A.push_back(0);}
  while(i<N){
  	if(S[i]=='1'){
      ll a=1;
      int flag=0;
      while(flag==0){
        i++;
        if(i==N){break;}
        if(S[i]=='1'){a+=1;}
        if(S[i]=='0'){flag=1;}
      }
      A.push_back(a);
    }
  	else{
      ll b=1;
      int flag=0;
      while(flag==0){
        i++;
        if(i==N){break;}
        if(S[i]=='0'){b++;}
        if(S[i]=='1'){flag=1;}
      }
      B.push_back(b);
    }
  }
  if(S[N-1]=='0'){A.push_back(0);}
  ll ans=0;
  ll sum=0;
  if(B.size()<=K){cout<<N;return 0;}
  if(A.size()>B.size()){
    rep(j,K){sum=sum+A[j]+B[j];}
    sum+=A[K];
    ans=sum;
    for(ll j=K;j<B.size();j++){
      sum=sum-A[j-K]-B[j-K];
      sum=sum+A[j+1]+B[j];
      ans=max(ans,sum);
    }
  }
  cout<<ans;
}

Measured memory_bytes: 1404
n = int(input())
s = [list(input()) for i in range(n)]
r = []
l = []
ans = 0
for i in s:
    now = 0
    c = 0
    for j in i:
        if j =="(":
            now += 1
        else:
            now -= 1
        c = min(c,now)
    if c == 0:
        ans += now
    elif now >= 0:
        l.append([c,now])
    else:
        r.append([c-now,now])

l.sort(reverse =True)
r.sort()
for i,j in l:
    if ans + i < 0:
        print("No")
        exit()
    else:
        ans += j

for i,j in r:
    if ans +i+j < 0:
        print("No")
        exit()
    else:
        ans += j
if ans == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 255344
#include <bits/stdc++.h>
#define int long long
#define inf (int)(3e18)
#define mod (int)(1e9+7)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,c;
int x[114514],v[114514];
int sumle1[114514],sumle2[114514];
int sumri1[114514],sumri2[114514];
signed main(){
	cin>>n>>c;
	for(int i=1;i<=n;i++)cin>>x[i]>>v[i];
	{
		int sum=0;
		for(int i=1;i<=n;i++){
			sumle1[i]=sumle1[i-1];
			sumle2[i]=sumle2[i-1];
			sum+=v[i];
			sumle1[i]=max(sumle1[i],sum-x[i]);
			sumle2[i]=max(sumle2[i],sum-x[i]*2);
		}
	}
	{
		int sum=0;
		for(int i=n;i>=1;i--){
			sumri1[i]=sumri1[i+1];
			sumri2[i]=sumri2[i+1];
			sum+=v[i];
			sumri1[i]=max(sumri1[i],sum-(c-x[i]));
			sumri2[i]=max(sumri2[i],sum-(c-x[i])*2);
		}
	}
	int ans=0;
	rep(i,n+1){
		ans=max(ans,sumle1[i]+sumri2[i+1]);
		ans=max(ans,sumle2[i]+sumri1[i+1]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 5120
def insetion_sort(A, n, g, cnt) :
        cnt = 0
        for i in range(g, n) :
            v = A[i]
            j = i - g
            while j >= 0 and A[j] > v :
                A[j+g] = A[j]
                j = j -g
                cnt += 1
            A[j+g] = v
        return cnt


def shell_sort(A, n) :
        cnt = 0
        count = 0
        G_sub = []
        h = 1
        while h <= n :
                G_sub.append(h)
                h = 3 * h + 1
        m = len(G_sub)
        G = G_sub[::-1]

        for i in range(m) :
                count += insetion_sort(A, n, G[i], cnt)

        print(m)
        if len(G) == 1 :
                print(G[0])
        else :
                print(" ".join(map(str, G)))
        print(count)


def main() :
        n = int(input())
        nums = []
        for i in range(n) :
                nums.append(int(input()))

        shell_sort(nums, n)
        for i in range(n) :
                print(nums[i])

if __name__ == '__main__' :
        main()

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

using namespace std;

int main(){
	string n;
	cin>>n;
	int k=0;
	for(int j=0;j<3;j++){
		if(n[j]==n[j+1]) k=1;
	}
	if(k==1) cout<<"Bad";
	else cout<<"Good";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, m; std::cin >> n >> m;
  std::multiset< int, std::greater< int > > set;
  loop(n) {
    int x; std::cin >> x;
    set.insert(x);
  }
  loop(m) {
    auto x = *set.begin();
    set.erase(set.begin());
    set.insert(x / 2);
  }
  auto ret = 0LL;
  for (auto x : set)
    { ret += x; }
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N;
map<int, int> Mp; // unordered_mapとは異なり、昇順で保存される。

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

  cin >> N;
  int a;
  vector<int> vec;
  rep(i, N){
    cin >> a;
    if (Mp[a]==0) vec.push_back(a);
    Mp[a] += 1;
  }
  if (vec.size() > 3) {
    cout << "No" << "\n";
    return 0;
  }
  if (vec.size() == 1){
    if (vec[0]==0) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
  }

  if (N%3!=0) {
    cout << "No" << "\n";
    return 0;
  }

  if (vec.size() == 2){
    int a = vec[0];
    int b = vec[1];
    if (a!=0 && b!=0){
      cout << "No" << "\n";
      return 0;
    }
    if (Mp[0]==N/3) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
  }

  for (auto it=Mp.begin(); it !=Mp.end(); ++it){
    int cnt = it->second;
    if (cnt != N/3){
      cout << "No" << "\n";
      return 0;
    }
  }

  if ((vec[0] ^ vec[1] ^ vec[2])==0) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  return 0;
}

Measured memory_bytes: 4216
#include<iostream>
using namespace std;
int main(){
    int a,b,result;
    char op;
    
    while(1){
        cin >> a >> op >> b;
        if(op == '?')break;
        else if (op == '+'){
            cout << a+b << endl;
        }
        else if (op == '-'){
            cout << a-b <<endl;
        }
        else if (op == '*'){
            cout << a*b <<endl;
        }
        else if (op == '/'){
            cout << a/b <<endl;
        }
    }
    return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L[i];
  sort(L.rbegin(), L.rend());
  int sum = accumulate(L.begin(), L.end(), 0);
  if (L[0] < sum - L[0]) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}


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

#define ll long long
#define all(x) x.begin(),x.end()
#define MAX 300005

int main()
{
    string s, t;
    cin >> s >> t;
    
    ll ans = 0;
    
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i]) ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  vector<int> siz;

  UnionFind(int N)
      : par(N), rank(N), siz(N) {  //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++) {
      par[i] = i;
      rank[i] = 0;
      siz[i] = 1;
    }
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {  // xとyの木を併合
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return;
  }

  bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

  int size(int x) { return siz[root(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind u(n);

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    u.unite(x, y);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, u.size(i));
  }

  cout << ans << endl;
}

Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

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

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;
}

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


map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}

signed main() {
  int N, P;
  cin >> N >> P;
  auto pf = prime_factor(P);
  int ans = 1;
  for (auto item : pf) {
    auto Fi = item.fi;
    auto Se = item.se;
    ans *= pow(Fi, Se / N);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    //static long ans = 0;
    static int[] c;
    static int[][] dc;
    static int[] last;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int d = sc.nextInt();
        c = sc.nextIntArray(26);
        dc = new int[d][26];
        last = new int[26];
        for(int i = 0; i < d; i++){
            for(int j = 0; j < 26; j++){
                dc[i][j] = sc.nextInt();
            }
        }
        int[] schedule = sc.nextIntArray(d);
        int q = sc.nextInt();
        for(int i = 0; i < q; i++){
            int di = sc.nextInt()-1;
            int ci = sc.nextInt();
            schedule[di] = ci;
            checkAns(schedule);
        }
    }
    
    public static void checkAns(int[] s){
        int d = s.length;
        last = new int[26];
        long ans = 0;
        for(int i = 0; i < d; i++){
            int hold = s[i]-1;
            last[hold] = i+1;
            ans += dc[i][hold];
            ans = calc(i+1,ans);
        }
        System.out.println(ans);
        return;
    }
    
    public static long calc(int d, long ans){
        for(int i = 0; i < 26; i++){
            ans -= c[i] * (d-last[i]);
        }
        return ans;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 53016
package main

import "fmt"

func check(as, bs []string) bool {
	la := len(as)
	lb := len(bs)
	for j := 0; j <= la-lb; j++ {
	OUTER:
		for i := 0; i <= la-lb; i++ {
			for y := 0; y < lb; y++ {
				if as[j+y][i:i+lb] != bs[y] {
					continue OUTER
				}
			}
			return true
		}
	}
	return false
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	as := make([]string, n)
	bs := make([]string, m)
	for i := range as {
		fmt.Scan(&as[i])
	}
	for i := range bs {
		fmt.Scan(&bs[i])
	}

	ans := ""
	if check(as, bs) {
		ans = "Yes"
	} else {
		ans = "No"
	}
	fmt.Println(ans)
}


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

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

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

	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}

	int s = 0;
	int ans = INF;
	for (int i = 0; i < n-1; i++) {
		s += a[i];
		sum -= a[i];

		ans = min(ans, abs(s - sum));
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
import math
n,m=map(int,input().split())
N=math.factorial(n)
if abs(n-m)>1:
    print(0)
elif abs(n-m)==0:
    print(2*N*N%(10**9+7))
elif n>m:
    print((N*N//n)%(10**9+7))
else:
    print(N*N*m%(10**9+7))

Measured memory_bytes: 10816
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
      int b=sc.nextInt();
        System.out.println(a+b/2);
    }
}

Measured memory_bytes: 23764
if __name__=="__main__":
  n=int(input())
  a=[int(i) for i in input().split()]
  stools=0
  for i in range(1, n):
    if a[i]<a[i-1]:
      stools+=a[i-1]-a[i]
      a[i] += a[i-1] - a[i]
  print(stools)
      

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

using namespace std;

int main()
{
    int H, R;
    cin >> H >> R;
    if (-H == R) {
        cout << 0 << endl;
    } else if (-H > R) {
        cout << -1 << endl;
    } else {
        cout << 1 << endl;
    }        
    return 0;
}

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

struct s{
    int id, vote;
    bool operator<(const struct s& right) const{
        return (vote == right.vote)?(id <= right.id):(vote > right.vote);
    }
};

int main(){
    int n, m;
    struct s q[100];
    while( true ){
        cin >> n >> m;
        if( n == 0 && m == 0 ) break;
        for(int i = 0; i < m; i++){
            q[i].id = i+1;
            q[i].vote = 0;
        }
        for(int i = 0; i < n*m; i++){
            int k; 
            cin >> k;
            q[i%m].vote += k;
        }
        sort(q, q + m);
        for(int i = 0; i < m; i++){
            if( i ) cout << ' ';
            cout << q[i].id;
        }
        cout << endl;
    }
    return 0;
}

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

int n ;

bool check(int mid , int* a , int* f , int k){
	for(int i = 0 ; i < n ; i++){
		if(a[i]*f[i] > mid){
			k -= a[i] - mid/f[i] ;
		}
		if(k < 0) return false ;
	}
	return true ;
}

int bs(int* a , int* f , int k ){
	int l = 0 , r = a[0]*f[n-1] ;
	int mid ;
	int ans = r ;
	while(l <= r ) {
		mid = (l+r)/2 ;
		if(check(mid,a,f,k)){
			ans = mid ;
			r = mid - 1 ;
		}else{
			l = mid + 1;
		}
	}
	return ans ;
}

int32_t main(){
	int k ;
	cin >> n >> k ;
	int a[n] , f[n] ;
	for(int i = 0 ; i < n ; i++) cin >> a[i] ;
	for(int i = 0 ; i < n ; i++) cin >> f[i] ;
	sort(a,a+n,greater<int>()) ;
	sort(f,f+n) ;
	cout << bs(a,f,k) ;
	return 0 ;
}


Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		
		String s = sc.next();
		int loss = 0;
		for (int i=0;i<s.length();i++) {
			if (s.charAt(i)=='x') {
				loss++;
			}
		}
		System.out.println(loss>=8 ? "NO" : "YES");
	}
}


Measured memory_bytes: 22100
n=input()
a=[]

a=map(int,raw_input().split())

b=[0]*100001
c=0
while c <= n-2:
    b[a[c]]+=1
    c+=2

d=[0]*100001
e=1
while e <= n-1:
    d[a[e]]+=1
    e+=2

f=sorted(b)[-2]
g=sorted(d)[-2]



if max(b) == n/2 and max(d) == n/2 and b.index(max(b)) == d.index(max(d)):
    print(n/2)
elif max(b) == n/2 and max(d) == n/2 and b.index(max(b)) != d.index(max(d)):
    print(0)
elif b.index(max(b)) == d.index(max(d)):
    print(n-max(b)-max(f,g))
else:
    print(n-max(b)-max(d))


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

int main(){
    int N;
    cin >> N;
    long distances[N][N];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cin >> distances[i][j];
        }
    }
    long ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            bool if_road = true;
            for(int k = 0; k < N; k++){
                if(distances[i][k] + distances[k][j] == distances[i][j] && i != k && j != k){
                    if_road = false;
                }else if(distances[i][k] + distances[k][j] < distances[i][j]){
                    cout << -1 << endl;
                    return 0;
                }
            }
            ans += if_road * distances[i][j];
        }
    }
    cout << ans / 2 << endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
const ll MOD = 1e9+7;

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\stdout", "w", stdout);
    }

    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    FOR(i, m)
        cin >> a[i];

    ll dp[n+1];
    memset(dp, 0, (n+1)*sizeof(ll));
    dp[0] = 1;
    int k = 0;
    FOR1(i, n){
        if (k<m && i==a[k]){
            while(k<m && i==a[k])
                k++;
            continue;
        }
        dp[i] = dp[i-1];
        if (i-2>=0)
            dp[i] += dp[i-2];
        dp[i] %= MOD;
    }
    cout << dp[n] << '\n';

    //if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ABC119A
{
    public partial class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var S = ss.Next(DateTime.Parse);
            sw.WriteLine(S <= new DateTime(2019, 4, 30) ? "Heisei" : "TBD");
            //---------------------------------
        }
    }

    public class StreamScanner
    {
        static readonly char[] Separator = { ' ' };
        readonly StreamReader streamReader;

        string[] line = new string[0];
        int index = 0;

        public StreamScanner(Stream stream)
        {
            this.streamReader = new StreamReader(stream);
        }

        public string Next()
        {
            return Next(s => s);
        }

        public string[] Next(int x)
        {
            return Next(s => s, x);
        }

        public string[][] Next(int x, int y)
        {
            return Next(s => s, x, y);
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (index < line.Length) return parser(line[index++]);
            index = 0;
            line = streamReader.ReadLine()?.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }

    public partial class Program
    {
        static void Main()
        {
            Excute(Console.OpenStandardInput(), Console.OpenStandardOutput());
        }

        public static void Excute(Stream input, Stream output)
        {
            var ss = new StreamScanner(input);
            var sw = new StreamWriter(output);
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }
}

Measured memory_bytes: 11612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }



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

  sort(a,a+N,greater<ll>());

  ll SecondNum = -1;

  FOR(i,1,N-1){
    // cout << a[i] << " " << a[0]/2 << endl;
    if(abs(a[i]-a[0]/2)<abs(SecondNum-a[0]/2)) SecondNum = a[i];
  }

  // ll ans = 1;

  // cout << a[0] << " " << SecondNum << endl;

  // FOR(i,1,SecondNum){
  //   ans *= a[0] - i + 1;
  //   ans /= i;
  // }

  // cout << ans << endl;

  cout << a[0] << " " << SecondNum << endl;





}



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

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

inline void Main() {
  // code
  int a,b;cin>>a>>b;
  if(a>=13) cout<<b<<endl;
  else if(6<=a && a<13) cout<<b/2<<endl;
  else cout<<0<<endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define maxn 300005

lli x[maxn],y[maxn];
int n;

pair<lli,lli> find_range(lli n1)
{
     return {x[n1],y[n1]};
}

int main() {
    fastio;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x[i]>>y[i];
    }
    sort(x,x+n);
    sort(y,y+n);
    if(n&1)
    {
        pair<lli,lli> pr=find_range(n/2);
        cout<<pr.s-pr.f+1<<"\n";
    }
    else{
        pair<lli,lli> pr1=find_range(n/2-1);
        pair<lli,lli> pr2=find_range(n/2);
        lli a1=(pr1.f+pr2.f)/2;
        lli a2=(pr1.s+pr2.s)/2;
        lli ans=(a2-a1+1)*2;
        if((pr1.f+pr2.f)&1)
            ans--;
        if((pr1.s+pr2.s)%2==0)
            ans--;
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 6732
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

h,w=map(int,input().split())
n=int(input().rstrip())
a=[int(i) for i in input().split()]
nh,nw=0,0
ans=[[0]*w for i in range(h)]
now=True
for i,j in enumerate(a,1):
    for _ in range(j):
        if nw<0:
            nh+=1
            nw+=1
            now=not now
        elif nw>=w:
            nh+=1
            nw-=1
            now=not now
        ans[nh][nw]=i
        if now:
            nw+=1
        else:
            nw-=1
for i in ans:
    print(*i)

Measured memory_bytes: 3920
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 19;

int n, m, k;

void solve(int test)
{
  string s;
  cin >> n >> k >> s;
  int cnt = 1;
  for (int i = 1; i < n; ++i) {
    if (s[i] != s[i - 1]) {
      ++cnt;
    }
  }
  cnt -= 2 * k;
  cnt = max(cnt, 1);
  cout << n - cnt << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  bool flag = false;
  reverse(s.begin(), s.end());
  reverse(t.begin(), t.end());
  for (int i = 0; i < s.length(); i++) {
    int cnt = 0;
    if (!flag)
      for (int j = 0; j < t.length(); j++)
        if (s[i + j] == t[j] || s[i + j] == '?') cnt++;

    if (cnt == t.length()) {
      flag = true;
      for (int k = 0; k < t.length(); k++) s[i + k] = t[k];
    }
  }

  for (int i = 0; i < s.length(); i++)
    if (s[i] == '?') s[i] = 'a';

  reverse(s.begin(), s.end());

  if (!flag)
    cout << "UNRESTORABLE" << endl;
  else
    cout << s << endl;
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll n, a;
  cin >> n;
  int n2 = 0;
  int n4 = 0;
  for(int i = 0; i < n; ++i)
  {
    cin >> a;
    if (a % 4 == 0) n4++;
    else if (a % 2 == 0) n2++;
  }
  cout << ((n4 + n2 / 2 >= n / 2) ? "Yes" : "No");
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    string s;
    cin >> s;
    if(s=="SAT"){
        cout << 1 << endl;
    }else if(s=="FRI"){
        cout << 2 << endl;
    }else if(s=="THU"){
        cout << 3 << endl;
    }else if(s=="WED"){
        cout << 4 << endl;
    }else if(s=="TUE"){
        cout << 5 << endl;
    }else if(s=="MON"){
        cout << 6 << endl;
    }else if(s=="SUN"){
        cout << 7 << endl;
    } 
}


Measured memory_bytes: 256
program redistribution
  implicit none
  integer(8), parameter :: modu = 1000000007
  integer :: s
  integer(8) :: m(3, 3) = 0
  read(*,*) s
  if (s < 6) then
    write(*,'(i0)') s / 3
    stop
  end if
  m(1, 1) = 1
  m(2, 1) = 1
  m(3, 2) = 1
  m(1, 3) = 1
  m = modmatpow(m, s - 6)
  write(*,'(i0)') mod(m(1, 1) + m(1, 1) + m(1, 2) + m(1, 3), modu)
contains
  function modmatmul(x, y) result(res)
    integer(8), parameter :: modu = 1000000007
    integer(8), intent(in) :: x(3, 3), y(3, 3)
    integer(8) :: tmp, res(3, 3)
    integer :: i, j, k
    do j = 1, 3
      do i = 1, 3
        res(i, j) = 0
      end do
      do k = 1, 3
        tmp = y(k, j)
        do i = 1, 3
          res(i, j) = mod(res(i, j) + x(i, k) * tmp, modu)
        end do
      end do
    end do
  end
  function modmatpow(x, n) result(res)
    integer(8), intent(in) :: x(3, 3)
    integer, intent(in) :: n
    integer(8) :: res(3, 3), tmp(3, 3)
    integer :: m
    res(1, 1) = 1
    res(2, 1) = 0
    res(3, 1) = 0
    res(1, 2) = 0
    res(2, 2) = 1
    res(3, 2) = 0
    res(1, 3) = 0
    res(2, 3) = 0
    res(3, 3) = 1
    tmp = x
    m = n
    do while (m > 0)
      if (btest(m, 0)) res = modmatmul(res, tmp)
      tmp = modmatmul(tmp, tmp)
      m = rshift(m, 1)
    end do
  end
end program redistribution

Measured memory_bytes: 2892
X, K, D = [int(v) for v in input().split()]

X = abs(X)
m = X // D
p = K - m if m <= K else 0

if p == 0:
    print(X - (K*D))
else:
    X -= m * D
    if p & 1:
        print(abs(X-D))
    else:
        print(X)

Measured memory_bytes: 9196
#include<iostream>
#include<vector>
#include<cstring>
#include<map>
#include<bitset>
#include<assert.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<set>
#include<queue>
#define long long long
using namespace std;
const int N=1e6,mod=1e9+7;
int aa[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n,k;cin>>n>>k;
  if(k==1||k==n+n-1)cout<<"No\n",exit(0);
  cout<<"Yes\n";

  aa[n]=k;aa[n-1]=k-1;aa[n+1]=k+1;
  int cnt=0;
  for(int i=1;i<=n+n-1;i++)
  {
    if(aa[i])continue;cnt++;
    if(cnt>=k-1&&cnt<=k+1){i--;continue;}
    aa[i]=cnt;
  }
  for(int i=1;i<=n+n-1;i++)cout<<aa[i]<<" ";cout<<endl;
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  bool ans = true;
  for(int i=0; i<s.size(); i++){
    if(i%2 == 0){
      if(s.at(i) != 'R' && s.at(i) != 'U' && s.at(i) != 'D'){
        ans = false;
      }
    }else{
      if(s.at(i) != 'L' && s.at(i) != 'U' && s.at(i) != 'D'){
        ans = false;
      }
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256