akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define rep(i,s,e)  for(int i=s;i<e;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second		
#define w(x)		int x; cin>>x; while(x--)
const int INF=1e18;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set

const int mod=1e9+7;

void solve(){
	int H,W;
	cin>>H>>W;

	int dp[H+1][W+1];
	memset(dp,0,sizeof(dp));

	char path[H][W];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>path[i][j];
		}
	}

	dp[0][0]=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(i==0 && j==0){
				dp[i][j]=0;
			}
			else if(i==0 && j==1 && path[i][j]=='.'){
				dp[i][j]=(1)%mod;
			}
			else if(i==1 && j==0 && path[i][j]=='.'){
				dp[i][j]=(1)%mod;
			}
			else if(i==0 && path[i][j]=='.'){
				dp[i][j]=(dp[i][j-1])%mod;
			}
			else if(j==0 && path[i][j]=='.'){
				dp[i][j]=(dp[i-1][j])%mod;
			}
			else{
				if(path[i][j]=='.'){
					if(path[i-1][j]=='.' && path[i][j-1]=='.'){
						dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
					}
					else if(path[i-1][j]=='.'){
						dp[i][j]=(dp[i-1][j])%mod;
					}
					else if(path[i][j-1]=='.'){
						dp[i][j]=(dp[i][j-1])%mod;
					}
				}
			}
		}
	}

	cout<<dp[H-1][W-1]<<'\n';

}
 
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
// #endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 9088
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a

class modint {
private:
  static constexpr long long int MOD = 1000000000 + 7; // (10 ** 9) + 7
  long long int x;

public:
  modint(long long int x) : x(x) {
    while (x < 0) {
      x += modint::MOD;
    }
    this->x = x % modint::MOD;
  }

  modint() : x(0) {}

  modint &operator=(const modint &other) {
    this->x = other.x;
    return *this;
  }

  modint &operator=(const long long int x) {
    if (x < 0) {
      this->x = x + modint::MOD;
    } else {
      this->x = x % modint::MOD;
    }
    return *this;
  }

  modint operator+(const modint &other) const {
    modint ret;
    ret.x = (this->x + other.x) % modint::MOD;
    return ret;
  }

  modint operator-(const modint &other) const {
    modint ret;
    ret.x = (this->x - other.x);
    if (x < 0) {
      ret.x += modint::MOD;
    }
    return ret;
  }

  modint operator*(const modint &other) const {
    modint ret;
    ret.x = (this->x * other.x) % modint::MOD;
    return ret;
  }

  modint &operator+=(const modint &other) {
    this->x = (this->x + other.x) % modint::MOD;
    return *this;
  }

  modint operator<<(const long long int shift) const {
    modint base = modint(2).pow(shift);
    return *this * base;
  }

  modint pow(long long int n) const {
    modint ret;
    ret.x = _pow(n);
    return ret;
  }

  friend std::ostream &operator<<(std::ostream &stream, const modint &value);

private:
  long long int _pow(long long int n) const {
    long long int a = this->x;
    long long res = 1;
    while (n > 0) {
      if (n & 1) {
        res = res * a % modint::MOD;
      }
      a = a * a % modint::MOD;
      n >>= 1;
    }
    return res;
  }
};

std::ostream &operator<<(std::ostream &stream, const modint &value) {
  return stream << value.x;
}

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

int one[60];
void countup(int n) {
  for (int i = 0; i < 60 && n > 0; i++) {
    if (n & 1) {
      one[i]++;
    }
    n >>= 1;
  }
}

void solve() {
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    countup(a);
  }

  modint ans = 0;
  for (int i = 0; i < 60; i++) {
    modint n = one[i] * (N - one[i]);
    ans += (modint(1) << i) * n;
  }

  cout << ans << endl;
}

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


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

int main() {
    int k, s; cin >> k >> s;

    int ans = 0;
    for (int x = 0; x <=k; x++) {
        for (int y = 0; y <=k; y++) {
            int z = s - x - y;
            if (0 <= z && z <= k) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
G = M.times.each_with_object(Hash.new{|h, k| h[k] = []}){|_, h| a, b = gets.split.map(&:to_i); h[a] << b; h[b] << a}

def dfs(path)
  return @acc += 1 if path.size == N
  (G[path[-1]] - path).each{|u| dfs(path + [u])}
end

@acc = 0; dfs([1])
puts @acc


Measured memory_bytes: 1916
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;

int main()
{
	long N;
	cin >> N;
	
	long ans = 0;
	for(long n = 1; n <= N; n ++){
		if(n % 3 != 0 && n % 5 != 0) ans += n;
	}

	
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,sum=0;
	cin >> N;
	vector<ll> A(N),d(N);
	FOR(i,0,N){
		cin >> A[i];
		sum += A[i];
	}
	ll k = sum * 2 / N / (N+1);
	if((sum*2)%((N+1)*N)!=0){
		cout << "NO" << endl;
		return 0;
	}
	FOR(i,0,N){
		ll p = (i-1+N)%N;
		d[i] = A[i] - A[p] - k; 
		if(d[i]>0){
			cout << "NO" << endl;
			return 0;
		}
		if(d[i]%N!=0){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	string s;
	map<string,int> mp;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		if(mp.find(s)!=mp.end())
			mp[s]++;
		else{
			mp.insert(make_pair(s,0));
		}
	}
	vector<pair<int,string> > v;
	for(auto it=mp.begin();it!=mp.end();++it){
		//cout<<it->first<<" "<<it->second<<"@"<<endl;
		v.push_back(make_pair(it->second,it->first));
	}
	sort(v.rbegin(),v.rend());
	if(v.size()==1){
		cout<<v[0].second<<endl;
	}
	else{
		vector<string> p;
	for(int i=0;i<v.size()-1;i++){
		if(v[i].first!=v[i+1].first){
			p.push_back(v[i].second);
			break;
		}
		else
			p.push_back(v[i].second);
	}
	if(v[v.size()-1].first==v[v.size()-2].first&&v[v.size()-1].first==v[0].first)
		p.push_back(v[v.size()-1].second);
	sort(p.begin(),p.end());
	for(int i=0;i<p.size();i++)
		cout<<p[i]<<endl;
}
	return 0;
}

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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int mod = 0;
inline int mul(int x,int y){return 1ll*x*y%mod;}
inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
inline int sq(int x){return 1ll*x*x%mod;}
int pow(int a,int b){return b == 0 ? 1 : ( b&1 ? mul(a,sq(pow(a,b/2))) : sq(pow(a,b/2)));}

int n,k,m,dp[303][303],dps[303][303],C[303][303];
int main() {
	read(n);read(k);read(mod);
	for(int i=0;i<=n;i++)C[i][0] = 1;
	for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) C[i][j] = add(C[i-1][j],C[i-1][j-1]);
	for(int i=1;i<=k;i++){
		dp[1][i] = 1;
		dps[1][i] = (k-i+1)%mod;
	}
	for(int i=2;i<=n+1;i++){
		for(int cs = 0;cs<=k;cs++){
			for(int j=1;j<i-1;j++){
				dp[i][cs] = add(dp[i][cs],mul(C[i-2][j-1],mul(dp[i-j][cs],dps[j][cs+1])));
			}
			dp[i][cs] = add(dp[i][cs],dps[i-1][cs+1]);
		}
		for(int cs = k;cs>=0;cs--)dps[i][cs] = add(dps[i][cs+1],dp[i][cs]);
	}
	cout<<dp[n+1][0]<<endl;
	return 0;
}


Measured memory_bytes: 1280
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
for p in range(1,4):
    tmp = 0
    for x, y in zip(X, Y):
        tmp += abs(x-y)**p
    print(tmp**(1/p))
M = 0
for x, y in zip(X, Y):
     M = max(M, abs(x-y))
print(M)


Measured memory_bytes: 5636
#include <stdio.h>
#include <math.h>

int main (){
	int a,b,i,x,y;
	while(scanf("%d %d",&a,&b)!=EOF){
		i=1;
		while(a>=i){
			if(a%i==0){
				x=a/i;
				if(b%x==0)break;
			}
			i++;
		}
		y=a/x*b;
		printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 596
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}



int main()
{

    fastread();

    ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

    bool flag=false;

    cin>>n;
    vector<ll>v1,v2;
    for(i=0; i<n; i++)
    {
        cin>>a>>b;
        v1.eb(a);

        v2.eb(b);

    }
    sort(vll(v1));
    sort(vll(v2));


    if(n&1)
        cout<<abs(v1[n/2]-v2[n/2])+1<<endl;

    else
    {
        sum=abs(v1[n/2]-v2[n/2])+abs(v1[(n/2)-1]-v2[(n/2)-1])+1;

        cout<<sum<<endl;
    }


}



Measured memory_bytes: 6684
#include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  cin>>n;
  vector<char> minimum(256, numeric_limits<char>::max());
  for(int i=1;i<=n;++i){
    string s;
    cin>>s;
    vector<char> n_chars(256);
    for(int i=0;i<s.size();++i)++n_chars[s[i]];
    for(int i=0;i<minimum.size();++i)
      minimum[i]=min(minimum[i],n_chars[i]);
  }
  for(int i=0; i<minimum.size();++i){
    char c=i;
    int n_chars=minimum[i];
    for(int i=0;i<n_chars;++i)cout<<c;
  }
  cout<<endl;
}


Measured memory_bytes: 256
puts $<.to_a[1..-1].map.with_index{|x,i|
	[x.split[0].to_i,x.split[1].to_i,i]
}.group_by{|x|
	x[0]
}.map{|g|
	g[1].sort_by{|x|
		x[1]
	}.map.with_index(1){|x,i|
		[*x,i]
	}
}.flatten(1).sort_by{|x|
	x[2]
}.map{|x|
	'%06d%06d'%[x[0],x[3]]
}.join("\n")

Measured memory_bytes: 75732
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    val n = StdIn.readInt()
    for(i <- 1 to n){
      if(check_num(i)){print(" %d".format(i))}
    }
    println()
  }

  def check_num(n:Int): Boolean ={
    n match {
      case n if n % 3 == 0 => true
      case n if(n.toString.contains("3")) => true
      case _ => false
    }
  }
}

Measured memory_bytes: 56472
import collections
n,m = map(int,input().split())
a = list(map(int,input().split()))
col = collections.Counter(a)
 
for i in range(m):
  b,c = map(int,input().split())
  col[c] += b
col = sorted(col.items(), key=lambda x:x[0],reverse=True)
 
ans=0
for k,v in col:
  if n <= v:
    ans += k*n
    break
  else:
    ans += k*v
    n -= v
print(ans)

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

using namespace std;

const int Nmax = 2e5 + 10;
const int Mod = 1e9 + 7;
const int oo = 1e9;

long long x;

int main()
{
/**
    #ifndef ONLINE_JUDGE

        ifstream cin("test.in");

    #endif // ONLINE_JUDGE
*/

    cin >> x;

    for(int i = -1000; i <= 1000; i++)
        for(int j = -1000; j <= 1000; j++)
        {
            long long first = 1LL * (1LL * i * i * i - 1LL * j * j * j) * i * i;
            long long second = 1LL * (1LL * i * i - 1LL * j * j) * j * j * j;

            if(first + second == x)
            {
                cout << i << " " << j << "\n";
                return 0;
            }
        }
    return 0;
}


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

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

  for (int i = 0; i < 3; i++) {
    if ('1' == n[i]) {
      n[i] = '9';
    } else {
      n[i] = '1';
    }
  }

  cout << n << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

vector<int> num;

int main()
{
    int res = 9999999;

    for (int i = 0; i < 5; i++)
    {
        int tmp;
        cin >> tmp;
        num.push_back(tmp);
    }

    //sort(num.begin(), num.end());
    next_permutation(num.begin(), num.end());

    do
    {
        int tmp = 0;
        for (int i = 0; i <= 4; i++)
        {
            while (tmp % 10 != 0)
            {
                tmp++;
            }

            tmp += num[i];
        }
        res = min(tmp, res);
    } while (next_permutation(num.begin(), num.end()));

    cout << res;
    return 0;
}

Measured memory_bytes: 256
n = gets.strip.to_i
h = gets.strip.split.map(&:to_i)

min=0
(n-1).times do |index|

#p [min, h[index], h[index+1]]

  min = h[index+1]-1 if h[index+1] > min
  if h[index+1] < min
    puts 'No'
    exit
  end

end

puts 'Yes'


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

int main(){
  //int a[105];
  int n;
  cin >> n;
  int s=0;
  for(int i=1; i<=n; i++){
    int x;
    cin >> x;
    if(x%2==1 && i%2==1) s++;
  }
  cout << s << endl;
}

Measured memory_bytes: 3620
// Aizu Vol-1 0130: Train
// 2017.8.3

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

char *gets(char *);
char buf[1100], *p;
char ans[100], *a, *t;

int main()
{
	int i, n;

	gets(buf), n = atoi(buf);
	for (i = 0; i < n; i++) {
		gets(p = buf);
		memset(ans, 0, sizeof(ans));
		t = a = ans + 50;
		while (*p) {
//			if (isspace(*p)) p++;
//			if (!*p) break;
			if (isalpha(*p)) {
				if (!*a) *a = *p;
			}
			else if (*p == '<') {
				p++, a--;
				if (a < t) t = a;
			}
			else if (*p == '-') p++, a++;
			p++;
		}
		puts(t);
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

int D;
int c[26];
ll s[365][26];

int last[26];

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

    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D) rep(j, 26) cin >> s[i][j];

    ll sum = 0;

    rep(d, D) {
        int x;
        cin >> x;
        x--;
        last[x] = d + 1;
        sum += s[d][x];
        rep(i, 26) sum -= (d + 1 - last[i]) * (c[i]);
        cout << sum << "\n";
    }

    return 0;
}

Measured memory_bytes: 3688
from fractions import gcd
A, B, C, D = map(int, input().split())

def lcm(a, b):
    return (a * b)//gcd(a, b)

left = (A-1)//C + (A-1)//D - (A-1)//lcm(C, D)
right = B//C + B//D - B//lcm(C, D)
ans = (B - A + 1) + (left - right)
print(ans)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

bool fix[111111];
int d[111111];
int D[111111];

struct DSU
{
	int S;
	
	struct node
	{
		int p; ll sum; 
		bool good;
	};
	vector<node> dsu;
	
	DSU(int n)
	{
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0; tmp.good=0;
			dsu.pb(tmp);
		}
	}
	
	void reset(int n)
	{
		dsu.clear();
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0; tmp.good=0;
			dsu.pb(tmp);
		}
	}
	
	int rt(int u)
	{
		if(dsu[u].p == u) return u;
		dsu[u].p = rt(dsu[u].p);
		return dsu[u].p;
	}
	
	void merge(int u, int v)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;
		if(rand()&1) swap(u, v);
		dsu[v].p = u;
		dsu[u].sum += dsu[v].sum;
		dsu[u].good|=dsu[v].good;
	}
	
	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}
	
	void upd(int u)
	{
		u=rt(u);
		dsu[u].good=1;
	}
	
	void updstat(int u, int s)
	{
		u=rt(u);
		dsu[u].sum=s;
	}
	ll getstat(int u)
	{
		return dsu[rt(u)].sum;
	}
};

bool good[111111];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	d[0]=s[0]-'a';
	for(int i=1;i<s.length();i++)
	{
		d[i]=(s[i]-s[i-1]);
		d[i]%=26;
		while(d[i]<0) d[i]+=26;
		////cerr<<i<<' '<<d[i]<<'\n';
	}
	for(int i=1;i<s.length();i++)
	{
		if(i==s.length()-i) D[i]=d[i];
		else D[i]=d[i]+d[s.length()-i];
	}
	int n; cin>>n;
	DSU dsu((int(s.length())+1)/2+3);
	for(int i=1;i<int(s.length())/2+1;i++)
	{
		dsu.updstat(i,D[i]);
	}
	for(int i=0;i<n;i++)
	{
		int l,r; cin>>l>>r; l--;
		if(l==0)
		{
			good[min(r,int(s.length())-r)]=1;
			fix[min(r,int(s.length())-r)]=1;
			dsu.upd(min(r,int(s.length())-r));
			continue;
		}
		
		if(r==s.length())
		{
			good[min(l,int(s.length())-l)]=1; 
			fix[min(l,int(s.length())-l)]=1; 
			dsu.upd(min(l,int(s.length())-l));
			continue;
		}
		if(l>=1&&l==int(s.length())-r)
		{
			
		}
		else
		{
			fix[min(l,int(s.length())-l)]=1; 
			fix[min(r,int(s.length())-r)]=1;
			//cerr<<"MERGE : "<<min(l,int(s.length())-l)<<' '<<min(r,int(s.length())-r)<<'\n';
			dsu.merge(min(l,int(s.length())-l),min(r,int(s.length())-r));
		}
	}
	for(int i=1;i<(int(s.length()))/2+1;i++)
	{
		int u=dsu.rt(i);
		if(dsu.dsu[u].good) continue;
		//cerr<<i<<' '<<u<<' '<<dsu.dsu[u].sum<<'\n';
		if(dsu.dsu[u].sum%26!=0)
		{
			cout<<"NO\n";
			return 0;
		}
	}
	for(int i=1;i<(int(s.length()))/2+1;i++)
	{
		//cerr<<i<<' '<<D[i]<<' '<<fix[i]<<'\n';
		if(D[i]%26==0) continue;
		if(fix[i]) continue;
		cout<<"NO\n"; return 0;
	}
	cout<<"YES\n";
}	


Measured memory_bytes: 2760
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define Maxn 100010
int num[Maxn];
int main(){
	int n;
	scanf("%d",&n);
	int ans=0;
	num[0]=0;
	for(register int i=1;i<=n;++i){
	num[i]=num[i/10]+1;
	if(num[i]%2==1)ans++;
}
cout<<ans<<endl;
} 

Measured memory_bytes: 640
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, m, c;
    cin >> n >> m >> c;
    vector<vector<int>> a(n);
    vector<int> b(m);
    in_arr(int, b, m);
    repi(i, a){
        *i = vector<int>(m);
        in_arr(int, *i, m);
    }
    
    int ret = 0;
    rep(i, n){
        int sum = 0;
        rep(j, m){
            sum += a[i][j] * b[j];
        }
        if(sum + c> 0){
            ++ret;
        }
    }
    cout << ret << endl;
    return 0;
}


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


/* macro */
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define sec second
#define fir first
#define pb push_back



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};



/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




/* main */



signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    vi arr; rep(i,0,3) arr.push_back(input());

    sort(all(arr));

    print(arr[0] + arr[1]);

    
    




    
    



    
    

    







   




    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










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

using namespace std;

int h, w;
string spell[10];

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

set<string> spellset;

string ans;

void cast(int sy, int sx, int y, int x, int d, string word)
{
  if(spellset.count(word)){
    if(ans.size() < word.size() || ans.size() == word.size() && ans > word){
      ans = word;
    }
  } else {
    spellset.insert(word);
  }
  if(sy == y && sx == x) return;
  int ny = (y + dy[d] + h) % h, nx = (x + dx[d] + w) % w;
  cast(sy, sx, ny, nx, d, word + spell[y][x]);
  return;
}

int main()
{
  while(cin >> h >> w, h || w){
    spellset.clear();
    for(int i = 0; i < h; i++) cin >> spell[i];
    ans = "";
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	string word = "";
	for(int k = 0; k < 8; k++){
	  int ny = (i + dy[k] + h) % h, nx = (j + dx[k] + w) % w;
	  cast(i, j, ny, nx, k, word + spell[i][j]);
	}
      }
    }
    cout << (ans.size() > 1 ? ans:"0") << endl;
  }
  return 0;
}

Measured memory_bytes: 33788
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  string s;
  cin >> s;
  
  int size=0;
  while(s[size] != '\0'){
    size++;
  }
  
  cout << s[0] << size - 2 << s[size - 1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
	vector<int> a = {1,4,1,4,1,2,1,2};
	vector<int> p(8);

	while(cin >> p[0]){
		rep(i,7) cin >> p[i + 1];

		vector<pair<int,pair<int, int>>> v;
		rep(i,8){
			int V = 0, sum = 0;
			rep(j,8){
				V += a[(i + j) % 8];
				V *= 10;
				sum += min(a[(i + j) % 8], p[j]);
			}
			v.emplace_back(make_pair(-sum, make_pair(V,i)));
		}
		sort(all(v));

		rep(i,8){
			if(i) cout << ' ';
			cout << a[(i + v.front().second.second) % 8];
		}
		cout << endl;
	}
}



Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int main(void){
    int h,w,ans = 0;
    cin >> h >> w;

    vector<vector<int>> dist(h,vector<int>(w,INT_MAX));
    queue<pair<int,int>> q;
    vector<string> s(h);

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

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            dist[i][j] = 0;
            if(s[i][j] != '#') q.push(pair<int,int>(i,j));  // start地点
            while(!q.empty()){
                auto p = q.front();
                q.pop();
                for(int k = 0;k < 4;k++){
                    int x = p.first + dx[k],y = p.second + dy[k];
                    if(x < 0 || x >= h || y < 0 || y >= w) continue;  // 場外はダメ
                    if(s[x][y] == '#') continue;     // 壁もダメ
                    if(dist[x][y] == INT_MAX){
                        dist[x][y] = dist[p.first][p.second] + 1;
                        ans = max(ans,dist[x][y]);
                        q.push(pair<int,int>(x,y));
                    }
                }
            }

            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    dist[i][j] = INT_MAX;
                }
            }
        }
    }



    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull uint64_t
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mx5 100005
#define mx6 1000005
#define mod 1000000007
#define nfs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

vector<int> gr[mx5];
ll dp[mx5][2] = {};
bool vis[mx5] = {};

void dfs(int u, int pa = 0) {
    vis[u] = 1;
    dp[u][0] = dp[u][1] = 1;
    for (int v:gr[u]) {
        if (v != pa) {
            dfs(v, u);
            dp[u][0] = (dp[u][0] * ((dp[v][0] + dp[v][1]) % mod)) % mod;
            dp[u][1] = (dp[u][1] * dp[v][0]) % mod;
        }
    }
}


int main() {
    nfs
    int i, n, u, v;
    cin >> n;
    for (i = 1; i < n; i++) {
        cin >> u >> v;
        gr[u].pb(v);
        gr[v].pb(u);
    }
    dfs(1);
    cout << (dp[1][0] + dp[1][1]) % mod;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

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

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    i32 N = input();
    vector<i32> h(N + 2);
    range(i, 1, N + 1) cin >> h[i];

    i32 ans = 0;
    range(_, 0, 100) {
        i32 cnt = 0;
        rrange(i, 1, N + 1) {
            if (h[i - 1] == 0 && h[i] != 0) cnt++;
            if (h[i]) h[i]--;
        }

        ans += cnt;
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}

Measured memory_bytes: 256
import sys

def main():
    N,K,Q,*A = map(int, open(0).read().split())

    p = [-Q+K]*N
    for a in A:
        p[a-1] += 1

    for x in p:
        if x > 0:
            print('Yes')
        else:
            print('No')

if __name__=='__main__':
    main()

Measured memory_bytes: 13940
#include <stdio.h>

int main(void){
  int c[3][3];
  int i, j;
  int gyou_a;
  int retu_b;

  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d", &c[i][j]);
    }
  }
  
  gyou_a = 2*c[0][0] - c[0][1] - c[0][2];
  for(i=1;i<3;i++){
    if(gyou_a==2*c[i][0] - c[i][1] - c[i][2]){
    }else{
      printf("No");
      return 0;
    }
  }
  retu_b = 2*c[0][0] - c[1][0] - c[2][0];
  for(i=1;i<3;i++){
    if(retu_b==2*c[0][i] - c[1][i] - c[2][i]){
    }else{
      printf("No");
      return 0;
    }
  }

  printf("Yes");
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=1e5+10;
    int N;
    ll A[MAXN];
    ll dp[MAXN][2];
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N;
        for(int u=1;u<=N;u++){
            cin>>A[u];
        }
        dp[1][0]=A[1];
        dp[1][1]=-A[1];
        for(int u=2;u<N;u++){
            dp[u][0]=max(dp[u-1][0]+A[u],dp[u-1][1]-A[u]);
            dp[u][1]=max(dp[u-1][1]+A[u],dp[u-1][0]-A[u]);
        }
        ll ans=max(dp[N-1][0]+A[N],dp[N-1][1]-A[N]);
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int N, Y;
    cin >> N >> Y;

    int xcnt, ycnt;
    int xres = -1, yres = -1, zres = -1;
    bool found = 0;

    for(xcnt=0; xcnt <= N; xcnt++)
    {
        for(ycnt=0; ycnt <= (N-xcnt); ycnt++)
        {
            int total = 10000*xcnt + 5000*ycnt + 1000*(N-xcnt-ycnt);
            if(total == Y)
            {
                xres = xcnt;
                yres = ycnt;
                zres = N-xcnt-ycnt;
                found = 1;
                break;
            }
        }
        if(found == 1)
        {
            break;
        }
    }

    cout << xres << " " << yres << " " << zres;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k; cin >> n >> k;
	vector<int> a(n),sum(n+1,0);
	rep(i, 0, n) cin >> a[i];
	int ans = 0;
	rep(i, 0, k + 1)rep(l, 0, i + 1) {
		int sub = 0;
		priority_queue<int,vector<int>,greater<int>> pq;
		rep(j, 0, min(l,n)) {
			sub += a[j]; pq.push(a[j]);
		}
		reverse(a.begin(), a.end());
		rep(r, 0, min(i, n) - l) {
			sub += a[r]; pq.push(a[r]);
		}
		reverse(a.begin(), a.end());
		int cnt = k - i;
		while (cnt > 0&&!pq.empty()&&pq.top()<0) {
			cnt--;
			sub -= pq.top(); pq.pop();
		}
		ans = max(ans, sub);
	}
	printf("%d", ans);
	return 0;
}


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

public class Alchemist{
    public static void Main(){
        int N = int.Parse(Console.ReadLine());
        var foods = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
        var min = new double[2];
        for(int i=1;i<N;i++){
            foods = foods.OrderBy(x => x).ToList();
            min[0] = foods[0];
            foods.RemoveAt(0);
            min[1] = foods[0];
            foods.RemoveAt(0);
            foods.Add(min.Average());
        }
        Console.WriteLine(foods[0]);
    }
}

Measured memory_bytes: 13524
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b;
  if (b <= 9) c = a * 10 + b;
  else if (b <= 99) c = a * 100 + b;
  else c = a * 1000 + b;
  if (sqrt(c) - int(sqrt(c)) < pow(0.1, 10))
    cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

LL n, k, b[40], dp[2], INF = 1e18;

int main() {
	cin >> n >> k;
	inc(i, n) {
		LL a;
		cin >> a;
		inc(j, 40) { b[j] += bit(a, j); }
	}
	
	inc(i, 40) {
		LL dp0 = exchange(dp[0], -INF);
		LL dp1 = exchange(dp[1], -INF);
		LL s0 =      b[i]  * (1LL << i);
		LL s1 = (n - b[i]) * (1LL << i);
		LL B = 1 - bit(k, i);
		
		setmax(dp[0], dp0 + s0);
		setmax(dp[B], dp0 + s1);
		setmax(dp[B], dp1 + s0);
		setmax(dp[1], dp1 + s1);
	}
	
	cout << dp[0] << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,k,count=0;
  cin >> n>> k;
  vector<int> data(n,1);
  for(int i = 0 ; i < k ; i++ ) {
    int a;
    cin >> a;
    for ( int j = 0 ; j < a ; j++ ) {
      int b;
      cin >> b;
      data.at(b-1)=0;
    }
  }
  
  for ( int i = 0 ; i < n ; i++ ) {
    if (data.at(i)==0) {
      count++;
    }
  }
  
  cout << n-count<< endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			String S = scan.next();
			
			char[] s = new char[S.length()];
			s = S.toCharArray();
			
			int maxcount = 0;
			int nowcount = 0;
			
			for(int i =0;i<S.length();i++) {
				if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T') {
						nowcount++;
						if(maxcount<nowcount) 
							maxcount =nowcount;
				}else{
					if(nowcount>0&&maxcount<nowcount) {
						maxcount = nowcount;
						nowcount =0;
					}else {
						nowcount = 0;
					}
					
					
				}
				
			}
		
			
			
			System.out.println(maxcount);
			
			
			
			
			
			
		}
		
	}
		

}


Measured memory_bytes: 21972
from collections import deque

N = int(input())
ki = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    ki[u-1].append([v-1, w])
    ki[v-1].append([u-1, w])
f = [False]*N
f[0] = True
c = [0]*N

q = deque([0])
while q:
    now = q.popleft()
    for nxt, w in ki[now]:
        if f[nxt]:
            continue
        if w&1:
            c[nxt] = c[now]^1
        else:
            c[nxt] = c[now]
        q.append(nxt)
        f[nxt] = True


for a in c:
    print(a)

Measured memory_bytes: 46820
#include<iostream>
int main(){
    int a, b, ans;
    char op;
    std::cin >> a >> op >> b;
    while(op!='?'){
        
        if(op=='+') ans = a + b;
        if(op=='-') ans = a - b;
        if(op=='*') ans = a * b;
        if(op=='/') ans = a / b;
        std::cout << ans << std::endl;
        std::cin >> a >> op >> b;
    }
        
}


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

int main() {
  int r,c;
  cin >> r >> c;
  vector<vector<int> > mat(r+1,vector<int>(c+1));
  vector<int> las(c+1);
  
  for(int i =0; i <r+1; i++){
      for(int j=0; j < c+1; j++){
        if(i!=r){
          if(j!=c){
            cin >> mat.at(i).at(j);
            las.at(j)+=mat.at(i).at(j);
            mat.at(i).at(c)+=mat.at(i).at(j);
            cout << mat.at(i).at(j) <<" ";
          }else{
            las.at(j)+=mat.at(i).at(j);
            cout << mat.at(i).at(j) <<endl;
          }
        }else{
          if(j!=c) cout << las.at(j) <<" ";
          else cout << las.at(j) <<endl;
        }
     }
  }
}


Measured memory_bytes: 3168
K, T = map(int, input().split())
A = list(map(int, input().split()))
res = K - max(A)
a = max(A)
if T == 1:
    print(K - 1)
    exit()
if res >= a + 1:
    print(0)
    exit()

ans = a - 1
ans -= res
print(ans)

Measured memory_bytes: 3060
import java.io.*;
import java.util.StringTokenizer;
import static java.lang.Math.*;

public class Main {
  public static void main(String[] args) {
    new Main().solve();
  }

  private void solve() {
    try(InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {

      int n = in.nextInt();
      int[] a = in.mapInt(n);

      int[] colors = new int[9];
      for (int rate : a) {
          int rank = rate >= 3200 ? 8 : rate / 400;
          colors[rank]++;
      }

      int count = 0;
      for (int i = 0; i < 8; i++) {
        count += colors[i] > 0 ? 1 : 0;
      }

      int max = count + colors[8];
      int min = count != 0 ? count : 1;
      out.println(min + " " + max);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  int atoi(String s) { return Integer.parseInt(s); }
  long atol(String s) { return Long.parseLong(s); }

  static class InputReader implements AutoCloseable {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream), 32768);
      st = null;
    }

    public String nextLine() throws IOException {
      return br.readLine();
    }
    public String next() {
      if (st == null || !st.hasMoreTokens()) {
        try { st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      }
      return st.nextToken();
    }
    public int nextInt() { return Integer.parseInt(next()); }
    public long nextLong() { return Long.parseLong(next()); }
    int[] mapInt(int len) {
      int[] ret = new int[len];
      for (int i = 0; i < len; i++) ret[i] = Integer.parseInt(next());
      return ret;
    }
    long[] mapLong(int len) {
      long[] ret = new long[len];
      for (int i = 0; i < len; i++) ret[i] = Long.parseLong(next());
      return ret;
    }
    @Override public void close() throws IOException { br.close(); }
  }
}

Measured memory_bytes: 20692
Scanf.scanf "%d %d %d %d" (fun n m x y ->
    let xx = Array.init n (fun _ -> Scanf.scanf " %d" (fun xx -> xx)) in
    let yy = Array.init m (fun _ -> Scanf.scanf " %d" (fun yy -> yy)) in
    Array.sort compare xx;
    Array.sort compare yy;
    let z = min yy.(0) y in
    print_endline @@
    if x < z && z <= y && yy.(0) >= z && xx.(n - 1) < z then "No War" else "War"
)

Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {

	public static void main(String[] arg) {
		Scanner scan = new Scanner(System.in);
		int s = scan.nextInt();
		int w = scan.nextInt();
		if(s <= w) {
			System.out.println("unsafe");
		}
		else {
			System.out.println("safe");
		}
	}
}


Measured memory_bytes: 35732
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define rep(i,x) for(int i=0;i<x;i++)
string s;
vector<int>vec[26];
vector<P1>ok;
int cnt;
struct BIT
{
	int bit[(1<<18)+5];
	int f(int x)
	{
		return x&-x;
	}
	void add(int i,int x)
	{
		for(int s=i;s<=(1<<18);s+=f(s)) bit[s]+=x;
	}
	int sum(int i)
	{
		int res=0;
		for(int s=i;s>0;s-=f(s)) res+=bit[s];
		return res;
	}
}bit[2];
int main(){
	cin>>s;
	rep(i,s.size()){
		vec[s[i]-'a'].pb(i);
	}
	rep(i,26){
		cnt += vec[i].size()%2;
	}
	if(cnt >= 2){
		puts("-1");
		return 0;
	}
	rep(i,26){
		rep(j,vec[i].size()){
			int k = vec[i].size()-1-j;
			if(j>k) break;
			ok.pb(mp(vec[i][j]-vec[i][k],mp(vec[i][j],vec[i][k])));
		}
	}
	SORT(ok);
	for(int i=1;i<=s.size();i++){
		rep(j,2) bit[j].add(i,1);
	}
	ll x = 0;
	for(int i=0;i<ok.size();i++){
		int a = ok[i].sc.fi,b = ok[i].sc.sc;
		x += bit[0].sum(a);
		x += bit[1].sum(s.size()-1-b);
		bit[0].add(a+1,-1);
		bit[0].add(b+1,-1);
		bit[1].add(s.size()-b,-1);
		bit[1].add(s.size()-a,-1);
	}
	cout<<x<<endl;
}

Measured memory_bytes: 4852
n=int(input())
a=list(map(int,input().split()))

sum=0
min=10**9
minus=0
for i in a:
  if i>=0:
    sum=sum+i
    if min>i:
      min=i
  else:
    minus=minus+1
    sum=sum-i
    if min>-i:
      min=-i
print(sum if minus%2==0 else sum-min*2)

Measured memory_bytes: 14412
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int n, m, a[100001];
vector<int> v[100001];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        v[x%m].push_back(x);
    }

    for (int i = 0; i < m; i++) {
        sort(v[i].begin(), v[i].end());
    }

    long long ans = 0;
    for (int i = 1; i < (m+1)/2; i++) {
        int l = i, r = m-i, cnt = 0;
        if (v[l].size() > v[r].size()) {
            swap(l, r);
        }

        for (int i = 1; i < v[r].size(); i++) {
            if (v[r][i] == v[r][i-1]) {
                cnt++;
                i++;
            }
        }

        int aa = v[l].size(), bb = v[r].size();
        ans += (aa + min(cnt, (bb-aa)/2));
    }
    ans += (v[0].size()/2);
    if (m%2 == 0) {
        ans += (v[m/2].size()/2);
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
    long long n;
    cin>>n;
    long long res=1;
    while (1){
        if((res*res)>n){
            cout<<(res-1)*(res-1)<<endl;
            return 0;
        }
        ++res;
    }

}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

const int  MAX = 1000000;

vector<int> prime;
bool isntprime[MAX+1]; 
	
void init(){
isntprime[0] = isntprime[1] = true;
  int j;	
  for(int i=2;i<= MAX;i++)if(!isntprime[i])for(prime.push_back(i),j=2*i;j<=MAX;j+=i)isntprime[j] = true;
}

inline bool isp(int x) { return !isntprime[x]; }

int sum[MAX];

int main() {
  init();
  for(int i=1;i<=MAX;i+=2) {
    if( isp(i) && isp((i+1)/2) ) {
      ++sum[i];
    }
  }
  REP(i,1,MAX) sum[i] += sum[i-1];

  int Q;
  cin >> Q;
  rep(_,Q) {
    int l,r;
    cin >> l >> r;
    int ans = sum[r];
    if( l - 1 >= 0 ) ans -= sum[l-1];
    cout << ans << endl;
  }
	    
  
  compute();
  return 0;
}


Measured memory_bytes: 6008