akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    """
    2つのリストの関係を調べる云々は「二部グラフの完全マッチング問題」というカテゴリ名で呼ばれる。
    そしてこれに対しては「Hallの定理」というのが有効らしい。高校数学の美しい物語参照。

    特に大事なのがHall条件と呼ばれる方で、一見これはAの全ての部分集合を見ないといけないが
    部分集合のサイズが大きいと即座に|A| ¥subset |¥Gamma(A)|となるケースが多いよう？

    本問ではAが同一の元のみからなるケースのみ考えればよく（maspyさんブログ参照）、
    任意のx¥in Aに対して|{i|ai == x}| + |{i|bi == x}| <= Nが成り立てば答えはYesとなる。

    実際の二部グラフの構成方法は、|{i|ai == x}| + |{i|bi == x}|が大きいxから順にペアを作れば良い。

    ここで実装の注意点として、たくさん出てくる数から優先的に処理しないといけないが、
    ここにheapqを使うと２回ポップして出てきた数同士でペアを作る発想になるものの、
    一方からポップした数がBに存在しない等の場合何度もポップしてBにその数が含まれるかチェックすることになり
    非常に非効率になる。なのでheapqは使ってはいけない。

    なのでここでは
        hist[(出てきた回数)]=(その回数A+Bから出てくる数の集合)
    としてhistはリストで管理しないといけない。

    これむずすぎん？？？必要なデータ構造多すぎて訳わからんくなる。
    """
    num_kinds = defaultdict(int)
    hist = [set() for _ in range(N + 1)]
    for x in A + B: num_kinds[x] += 1
    for x, times in num_kinds.items():
        if times > N:
            print("No")
            return
        hist[times].add(x)
    print("Yes")

    num_to_idx_A = defaultdict(set)
    num_to_idx_B = defaultdict(set)
    num_to_cnt_A = defaultdict(int)
    num_to_cnt_B = defaultdict(int)
    for i, a in enumerate(A):
        num_to_idx_A[a].add(i)
        num_to_cnt_A[a] += 1
    for i, b in enumerate(B):
        num_to_idx_B[b].add(i)
        num_to_cnt_B[b] += 1


    B_new = [0] * N
    for times in range(N, 0, -1):
        nums = list(hist[times])
        l = len(nums)
        x, y = -1, -1
        if l == 2:
            x, y = nums
            if not num_to_idx_A[x]: x, y = y, x
        elif l == 1:
            x = nums[0]
            if num_to_idx_A[x]:
                y = -1
                for num in num_to_cnt_B:
                    if num != x:
                        y = num
                        break
            else:
                y = x
                x = -1
                for num in num_to_cnt_A:
                    if num != y:
                        x = num
                        break
        elif l == 0:
            x = -1
            for num in num_to_cnt_A:
                x = num
                break
            y = -1
            for num in num_to_cnt_B:
                if num != x:
                    y = num
                    break

        idxA = num_to_idx_A[x].pop()
        B_new[idxA] = y
        num_to_idx_B[y].pop()

        num_to_cnt_A[x] -= 1
        num_to_cnt_B[y] -= 1
        if num_to_cnt_A[x] == 0: del num_to_cnt_A[x]
        if num_to_cnt_B[y] == 0: del num_to_cnt_B[y]

        hist[num_kinds[x]].discard(x)
        hist[num_kinds[y]].discard(y)
        num_kinds[x] -= 1
        num_kinds[y] -= 1
        hist[num_kinds[x]].add(x)
        hist[num_kinds[y]].add(y)

    print(" ".join(map(str, B_new)))



if __name__ == "__main__":
    main()


Measured memory_bytes: 299644
import itertools


def func():
    index = list(range(5))
    p = list(itertools.permutations(index))

    time = []
    for i in range(5):
        time.append(int(input()))

    mn = 1e1000

    for i in p:
        sum = 0
        for k in range(5):

            reminder = time[i[k]] % 10
            if reminder == 0:
                reminder = 10
            if k == 4:
                sum += time[i[k]]
            else:
                sum += time[i[k]] + (10 - reminder)
        mn = min(mn, sum)

    print(mn)


if __name__ == '__main__':
    func()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <variant>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

constexpr int C = 200000;

vecint xpy(400001, -1e8);
vecint xmy(400001, -1e8);

struct P {
  int y,x;
};

union UP {
  P p;
  uint64_t v;
};

int solve1(vector<tuple<UP,char>>& vt) {
  for (auto&&e:xpy) e = -1e8;
  for (auto&&e:xmy) e = -1e8;

  sort(ALL(vt), [] (auto&& lhs, auto&& rhs) {
      auto&&[pl,ul] = lhs;
      auto&&[pr,ur] = rhs;
      return pl.v < pr.v;
  });
  int mn = 1e8;
  int last_u_x = -1;
  int last_u = -1e8;
  for (auto&&[p,u] : vt) {
    int x = p.p.x;
    int y = p.p.y;
    switch (u) {
      case 'R':
        xpy[x+y] = x;
        xmy[x-y+C] = x;
        break;
      case 'U':
        mn = min(mn, (x - xpy[x+y]) * 10);
        last_u_x = x;
        last_u = y;
        break;
      case 'D':
        mn = min(mn, (x - xmy[x-y+C]) * 10);
        if (x == last_u_x) {
          mn = min(mn, (y - last_u) * 5);
        }
        break;
    }
  }
  return mn;
}

int solve2(vector<tuple<UP,char>>& vt) {
  for (auto&&e:xpy) e = -1e8;
  for (auto&&e:xmy) e = -1e8;

  int mn = 1e8;
  for (auto itr = rbegin(vt); itr != rend(vt); ++itr) {
    auto&&[p,u] = *itr;
    int x = p.p.x;
    int y = p.p.y;
    switch (u) {
      case 'R':
        xpy[x+y] = x;
        xmy[x-y+C] = x;
        break;
      case 'U':
        mn = min(mn, (x - xpy[x+y]) * 10);
        break;
      case 'D':
        mn = min(mn, (x - xmy[x-y+C]) * 10);
        break;
    }
  }
  return mn;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  scanf("%d", &n);
  char nl = getchar();
  vector<tuple<UP,char>> vt;
  vt.reserve(n);
  REP(i,n) {
    int x=0,y=0;
    while (true) {
      int c = getchar();
      if (c < '0') break;
      x *= 10;
      x += c - '0';
    }
    while (true) {
      int c = getchar();
      if (c < '0') break;
      y *= 10;
      y += c - '0';
    }
    char c = getchar();
    char ign = getchar();
    vt.emplace_back(UP{P{y,x}},c);
  }
  int mn = 1e8;
  REP(i,2) {
    mn = min(mn, solve1(vt));
    for (auto&&[p,u] : vt) {
      p.p.x = C - p.p.x;
      p.p.y = C - p.p.y;
      switch (u) {
        case 'L': u = 'R'; break;
        case 'R': u = 'L'; break;
        case 'U': u = 'D'; break;
        case 'D': u = 'U'; break;
      }
    }
    mn = min(mn, solve2(vt));
    if (i == 1) break;
    for (auto&&[p,u] : vt) {
      int tmp = p.p.x;
      p.p.x = p.p.y;
      p.p.y = tmp;
      switch (u) {
        case 'L': u = 'D'; break;
        case 'R': u = 'U'; break;
        case 'U': u = 'R'; break;
        case 'D': u = 'L'; break;
      }
    }
  }
  if (mn >= 1e8) {
    cout<<"SAFE\n";
  } else {
    cout<<mn<<"\n";
  }
  return 0;
}


Measured memory_bytes: 9632
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	long long int k;
	int n;
	cin>>n>>k;
	int v[n];
    int town, count=0,i=0;
    int a[n];
    memset(v,-1,sizeof v);
    v[0]=0;

    for(int j=0;j<n;j++)
    cin>>a[j];
    if(k<n)
    {
    while(count<k)
    {
    i=a[i]-1;
    count++;    
    }
    }  
    else
    { 
    while(count<k)
    {
    i=a[i]-1;
    count++;
    if(v[i]==-1)
    {
    v[i]=count;
    }
    else
    {
    town=i;
    break;	
    }
    }

    int r=(k-v[town])%(count-v[town]);
    i=town;
    while(r>0)
    {
    	i=a[i]-1;
    	r--;
    }
    }
    cout<<i+1;
    return 0;
}

Measured memory_bytes: 4720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define local
//if you find any bug in my code, please tell me.
ll comb(int n, int m)
{
    ll ans=1;
    for(int i=1; i<=m; i++)
    {
        ans*=n-i+1;
        ans/=i;
    }
    return ans;
}
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    int n,a,b,i,j;
    double sum=0;
    ll v[55],cnt=0;
    cin>>n>>a>>b;
    for(i=0; i<n; i++)
        cin>>v[i];
    sort(v,v+n);
    reverse(v,v+n);
    for(i=0; i<a; i++)
        sum+=1.0*v[i];
    int x=a-1,y=a-1;
    while(v[x-1]==v[x]&&x-1>=0) x--;
    while(v[y]==v[y+1]&&y+1<n) y++;
    for(i=a; i<=(x?a:b); i++)
        cnt+=comb(y-x+1,i-x);
    printf("%.10f\n%lld",sum/a,cnt);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    
    ll N,a,Ans=0;
    vector<ll> A;
    cin >> N;
    REP(i,N){
        cin >> a;
        A.push_back(a);
    }
    
    REP(i,N){
        if(i%2==0 && A[i]%2==1){
            Ans++;
        }
    }
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int i=1;
    while(a>0&&c>0)
    {
        if(i%2!=0)
        {
            c=c-b;
            if(c<=0)
            break;
        }
        if(i%2==0)
        {
            a=a-d;
            if(a<=0)
            break;
        }
        i++;
    }
    if(i%2!=0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3636
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define    all(x)   x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(10)<<fixed
#define    mems(dp,x)   memset(dp,x,sizeof(dp))
const    ld   PI=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}

const int NM=100001;// size upto which u want
ll factmod[NM];
ll factmodinv[NM];
void ncrprecal()
{
    factmodinv[0]=1;
    factmod[0]=1;
    for(ll i=1;i<NM;i++)
    {
        factmod[i]=(i*factmod[i-1])%mo;
        factmodinv[i]=modinv(factmod[i]);
    }
}

ll ncrmp(ll n,ll r){if(n==r||r==0)return 1;if(n<r)return 0;return mmul(mmul(factmod[n],factmodinv[r]),factmodinv[n-r]);}


int main()
{
io
ncrprecal();
int testcases=1;//cin>>testcases;
while(testcases--)
{
	

ll n,k;
cin>>n>>k;
ll b=n-k+1;

for(int i=1;i<=k;i++)
{
cout<<mmul(ncrmp(b,i),ncrmp(k-1,i-1))<<"\n";	
}
	


}return 0;}

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

typedef long long  LL;
int n,cnt[26];
LL ans;
char a[200010];

void work()
{
	scanf("%s",a+1),n=strlen(a+1),ans=1LL*n*(n-1)/2;
	for (int i=1; i<=n; i++)  cnt[a[i]-'a']++;
	for (int i=0; i<26; i++)  ans-=1LL*cnt[i]*(cnt[i]-1)/2;
	printf("%lld",ans+1);
}

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


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstring>
#define MAX 200005
using namespace std;
int count_num[MAX];

bool cmp(int a,int b){
	return a > b;
}
void PutNUM()
{
	for(int i = 0; i < 10; i++)
		cout << count_num[i] <<" ";
	cout << endl;	
}
int main( )
{
	memset(count_num,0,sizeof(count_num));
	int n,k;
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		count_num[a]++;
	}
//	PutNUM();
	sort(count_num,count_num + MAX,cmp);
	int sum = 0;
//	PutNUM();
	for(int i = 0; i < k; i++)
		sum += count_num[i];
	cout << n - sum << endl;
	return 0;
}



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

using namespace std;

int main()
{  
    int n;
    cin>>n;
    map<string,int> mp;
    for(int i = 1;i<=n;i++)
    {

        string temp = to_string(i);
        char c1 = temp[0];
        char c2 = temp.back();
        temp.clear();
        temp += c1;
        temp += c2;
        mp[temp]++;
    }

    long long answer = 0;

    for(pair<string,int> p:mp)
    {

        string s = p.first;
        if(s[0] == s[1])
        {
            int x = p.second;
            answer += (x * x);
        }
        else
        {
            int x = p.second;
            swap(s[0],s[1]);
            int y = mp[s];
            answer += (x*y);
        }
        
    }

    cout<<answer;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<bool> vb;
long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
long long int min(long long int a,long long int b){
  if(a<b)
    return a;
  else
    return b;
}
long long int binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
    }
  return res;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
 
//############################ENDOFTEMPLATE############################

void solve(){
  string s,t;
  cin>>s>>t;
  int n = s.length();
  int m = t.length();

  vector<string> ans;
  for(int i = 0;i<=n-m;i++){
    string temp = s.substr(0);
    bool flag = true;
    for(int j = 0;j<m;j++){
      if(temp[j+i]=='?')
        temp[j+i] = t[j];

      else if(temp[j+i]!=t[j]){
        flag = false;
        break;
      }

    }
    for(int k = 0;k<n;k++){
      if(temp[k]=='?')
        temp[k] = 'a';
    }

    if(flag)
      ans.push_back(temp);
  }

  if(ans.size()==0){
    cout<<"UNRESTORABLE";
    return;
  }

  sort(ans.begin(),ans.end());
  cout<<ans[0];
}
 
 
 
 
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  //freopen("moobuzz.in","r",stdin);
  //freopen("moobuzz.out","w",stdout);
  int t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 3648
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int main()
{
	int n=read(),cnt=0,tmp=n;
	if(n<=2) return puts("No"),0;
	while(tmp) cnt++,tmp>>=1; cnt--;
	if((1<<cnt)==n) return puts("No"),0; puts("Yes");
	printf("1 2\n2 3\n3 %d\n%d %d\n%d %d\n",n+1,n+1,n+2,n+2,n+3);
	for(int i=4;i<=(n-1);i+=2)
	{
		printf("%d %d\n%d %d\n%d %d\n%d %d\n",n+1,i+n,n+i,n+i+1,n+1,i+1,i+1,i);
	}
	if(n%2==0)
	{
		for(int i=2;i<=n-1;i++)
		{
			int t=n^1^i;
			if(t>=2&&t<=n-1)
			{
				int p1=0,p2=0;
				if(i%2==0) p1=i+n; else p1=i;
				if(t%2==0) p2=t+n; else p2=t;
				printf("%d %d\n%d %d\n",p1,n,p2,n+n);
				break;
			}
		}
	}
	return 0;
}

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

int main(){
	int n;
	cin>>n;
	vector<int> a(9,0);
	for(int i=0;i<n;i++){
		int b;
		cin>>b;
		if(b>=3200)b=3200;
		a[b/400]++;
	}
	
	int ans=0;
	for(int i=0;i<8;i++){
		if(a[i]!=0)ans++;
	}
	if(ans==0){
		ans++;
		a[8]--;
	}
	cout<<ans<<" "<<ans+a[8]<<endl;
	return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    ll N;
    cin >> N;
    for(ll n=1;n<3501;n++){
        for(ll h=1;h<3501;h++){
            if ((4*h*n-N*n-N*h)>0&&(n*N*h)%(4*h*n-N*n-N*h)==0){
                cout << h << " " << n << " " << (n*N*h)/(n*(4*h-N)-N*h);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
def main():
    n,k = map(int,input().split())
    a = list(sorted(map(int,input().split())))
    mi = 0
    MA = a[n-1]
    if(k == 0):
        print(MA)
        return
    while(True):
        m = mi + (MA - mi)//2
        if(MA == 1):
            print(1)
            return
        count = 0
        for i in a:
            plus = i//m - 1 if i%m == 0 else i//m 
            count += plus
        if(MA - mi <= 0):
            if(k >= count):
                print(m)
            else:
                print(mi)
            break
        if(k < count):
            mi = m+1
        else:
            MA = m
        





if __name__ == "__main__":
    main()

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

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

    vector<long long int> x(n), y(n), h(n);
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i] >> h[i];
    }

    long long int height;
    for(int cx=0; cx<=100; cx++){
        for(int cy=0; cy<=100; cy++){
            bool flag = true;
            int after;

            for(int i=0; i<n; i++){
                if(h[i] != 0){
                    height = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                    break;
                }
            }

            for(int i=0; i<n; i++){
                if(h[i] != max(height - abs(x[i] - cx) - abs(y[i] - cy), 0LL)){
                    flag = false;
                    break;
                }
            }

            if(flag == true){
                cout << cx << " " << cy << " " << height << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
function main() {

  var str = input[1].split(' ');
  str.reverse();
  var ary = str.join(' ');

  console.log(ary);
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});


Measured memory_bytes: 15260
// @uthor........ _|EE|_

#include<bits/stdc++.h>
#define int long long
#define double long double
#define vi vector<int>
#define vpi vector<pair<int,int> >
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define set set<int>
#define u_set unordered_set<int>
#define pb push_back
#define M 1000000007
#define endl "\n"
#define BRISK ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

signed main()
{
    BRISK;
    int n,W;
    cin>>n>>W;
    int w[n],v[n];
    for(int i=0;i<n;i++)cin>>w[i]>>v[i];

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

    cout<<dp[n-1][W];
}


Measured memory_bytes: 78336
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int h, w, d;
int cost[90001];
unordered_map<int, P> m;

int main() {
    cin >> h >> w >> d;
    REP(i,h) {
        REP(j,w) {
            int a;
            cin >> a;
            m[a] = P(i,j);
        }
    }
    
    for (int i = d + 1; i <= h * w; i++) {
        P pi = m[i];
        P pp = m[i-d];
        cost[i] = cost[i-d] + abs(pi.first - pp.first) + abs(pi.second - pp.second);
    }
    
    int q;
    cin >> q;
    REP(i,q) {
        int l, r;
        cin >> l >> r;
        cout << cost[r] - cost[l] << endl;
    }
}


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

int main() {
    
    int x,a,b;
    cin >> x >> a >> b;
    x-=a;
    int c = x/b;
    x -= c*b;
    cout << x << endl;
	// your code goes here
	return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String[] tmpArray = br.readLine().split(" ");

		int array[] = new int[n];

		for(int i = 0; i < n ; i++){
			array[i] = Integer.parseInt(tmpArray[i]);
		}

		long two = 0;

		for(int i = 0; i < n; i++){
			two += numOfTwo(array[i]);
		}

		System.out.println(two);
	}

	static int numOfTwo(int n){
		int result = 0;

		while(n % 2 == 0){
			n /= 2;
			result++;
		}

//		System.out.println(result);
		return result;
	}

}


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

int main(){
    while(true){
        char grade;
        int m, f, r; cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1) break;
        if(m == -1 || f == -1){
            grade = 'F';
        }
        else if (m + f >= 80){
            grade = 'A';
        }
        else if (m + f >= 65){
            grade = 'B';
        }
        else if (m + f >= 50){
            grade = 'C';
        }
        else if (m + f >= 30){
            (r >= 50) ? grade = 'C' : grade = 'D';
        }
        else{
            grade = 'F';
        }
        cout << grade << endl;
    }
}


Measured memory_bytes: 3120
using System;
using System.Linq;

namespace MSolutionB
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = CIN.String();
            int Count = 0;
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == 'o')
                {
                    Count++;
                }
            }

            Count += 15 - S.Length;
            Console.WriteLine(Count >= 8 ? "YES" : "NO");
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 11092
import java.util.*;

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

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        long THREASHOLD=1000000000000000000L;
        int N = sc.nextInt();
        long[] A = new long[N];
        boolean zero = false;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextLong();
            if (A[i] == 0) zero = true;
        }
        if (zero) {
            System.out.println("0");
            return;
        }

        long ans = 1;
        for (int i = 0; i < N; i++) {
            if (ans > ans*A[i] || ans*A[i]  < 0 || ans*A[i] > THREASHOLD) {
                ans = -1;
                break;
            }
            ans *= A[i];
        }

        System.out.println(ans);
        return;
    }

}

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct edge{
    int from, to;
    lint cost;

    bool operator<(const edge &right) const {
        return cost > right.cost;
    }
};

vector< vector<edge> > g;

int main(){
    int v, e;
    cin >> v >> e;
    g.resize(v);
    rep(i, e){
        int s, t;
        lint w;
        cin >> s >> t >> w;
        g[s].push_back({s, t, w});
        g[t].push_back({t, s, w});
    }
    lint ans = 0;
    vector<bool> done(v, false);
    done[0] = true;
    priority_queue<edge> que;
    rep(i, g[0].size()){
        que.push(g[0][i]);
    }
    while(!que.empty()){
        edge now = que.top();
        que.pop();
        if(done[now.to]){
            continue;
        }
        done[now.to] = true;
        ans += now.cost;
        rep(i, g[now.to].size()){
            if(!done[g[now.to][i].to]){
                que.push(g[now.to][i]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10276
#include<bits/stdc++.h>
#define int ll
#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;
const int N = 3005;
int ar[N][N];
int dp[N][N][6];


signed main(){

#ifndef ONLINE_JUDGE
	freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    int R , C , K;
    cin >> R >> C >> K;
    fo(_ , K){
        int r , c , v;
        cin >> r >> c >> v;
        ar[r - 1][c - 1] = v;
    }


    auto relax = [](int & a , int b){ a = max(a , b) ; };
   
    dp[0][0][0] = 0;
    fo(i , R)
        fo(j , C)
            fo(k , 4){
                if(k < 3){
                    relax(dp[i][j + 1][k + 1] , dp[i][j][k] + ar[i][j]);
                    relax(dp[i + 1][j][0] , dp[i][j][k] + ar[i][j]);
                }
                relax(dp[i][j + 1][k] , dp[i][j][k]);
                relax(dp[i + 1][j][0] , dp[i][j][k]);
            }
    
//    fo(k , 3){
//        fo(i , R + 1){
//            fo(j , C + 1) cout << dp[i][j][k] << " ";
//            cout << '\n';
//        }
//        cout << '\n';
//    }

    auto ans = max(
                *max_element(dp[R][C - 1] , dp[R][C - 1] + 4) , 
                *max_element(dp[R - 1][C] , dp[R - 1][C] + 4)
    );
    
    cout << ans << '\n';

    return 0;

}



Measured memory_bytes: 496644
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    System.out.println(solve(k));
  }
  static int solve(int k){
    if(k % 2 == 0 || k % 5 == 0){
      return -1;
    }
    int num = 7;
    int count = 1;
    while(count <= k){
      int r = num % k;
      if(r == 0){
        return count;
      } else {
        num = (r * 10) + 7;
        count++;
      }
    }
    return -1;
  }
}


Measured memory_bytes: 35792
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

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

typedef pair<int, pair<int, int>> edge;


signed main() {
	int n;
	cin >> n;
	int h[n];
	REP (i,n) cin >> h[i];
	int ans = 1;
	int ma = h[0];
	FOR (i,1,n) {if (h[i] >= ma) ans++;ma = max(ma,h[i]);}
	cout << ans << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; 
    cin >> n;
    vi a(n); 
    map<int, int, greater<int>> mp;
    rep(i, n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    
    sort(rall(a));
    
    ll tot = 0;
    int cnt = 0;
    int j = 0;
    bool flag = false;
    
    rep(i, n){
        if(i == 0) continue;
        if(j == 0){
            tot += a[j];
            j++;
        }
        else if(!flag){
            tot += a[j];
            flag = true;
        }else{
            tot += a[j];
            j++;
            flag = false;
        }
        // cout << i << " " << tot << endl; 
    }
    
    /*
    for(auto [k, v] : mp){
        // cout << k << " " << v << endl;
        if(cnt == 0) {
            if(cnt + v >= n-1){
                tot += k * (n-1);
                break;
            }
            cnt += v;
            tot += k * v;
            cout << tot << " " << cnt << endl;
        }
        else {
            if(cnt + v >= n-1){
                tot += k * ((n-1) - cnt);
                break;
            }
            cnt += v + 1;
            tot += k * (v + 1);
            cout << tot << " " << cnt << endl;
        }
    }
    */
    cout << tot << endl;
    return;
}

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

Measured memory_bytes: 13404
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int n, m;
bool b[50];
signed main() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++)b[i] = 1;
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		bool b1[50];
		for (int i = 1; i <= m; i++)b1[i] = 0;
		for (int j = 0; j < k; j++) {
			int p; cin >> p;
			b1[p] = 1;
		}
		for (int i = 1; i <= m; i++)if (!b1[i])b[i] = 0;
	}
	int cnt = 0;
	for (int i = 1; i <= m; i++)cnt += b[i];
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
    int f,s;
    int sum,cnt;
    while (cin >> f >> s)
    {
        sum = f+s;
        cnt = 0;
        while (sum)
            sum /= 10 , cnt ++;
        printf("%d\n",cnt);
    }
}

Measured memory_bytes: 1144
import math

while True:
    q = int(input())
    
    if q==-1:
        break
    
    x = q/2
    
    while True:
        if math.sqrt((x**3-q)**2) < 0.00001*q :
            print(f'{x:.6f}')
            break
        
        x = x - (x**3-q)/(3*x**2)


Measured memory_bytes: 5736
MOD = 10**9 + 7
N = int(input())
a = input()
b = input()
ans = 0
i = 0
beforeState = True
while i < N:
    if i == 0:
        if a[i] == b[i]:
            ans = 3
            beforeState = True
        else:
            ans = 6
            i += 1
            beforeState = False
    else:
        if a[i] == b[i]:
            if beforeState:
                ans *= 2
            else:
                ans *= 1
            beforeState = True
        else:
            if beforeState:
                ans *= 2
            else:
                ans *= 3
            beforeState = False
            i += 1
    ans = ans%MOD
    i += 1
print(ans)

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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif


void solve(ll N, vector<ll> A) {
    int ans = 0;
    ll sm = accumulate(A.begin(), A.end(), 0ll);
    ll D = N * (N + 1) / 2;
    if (sm % D != 0) {
        cout << "NO" << endl;
        return;
    }
    ll K = sm / D;

    vector<ll> X;
    for (int i = 0; i < N; i++) {
        X.push_back(A[(i + 1) % N] - A[i]);
    }
    for (int i = 0; i < N; i++)
        X[i] -= K;

    ll sum = 0;
    for (int i = 0; i < N; i++) {
        if (X[i] > 0 || X[i] % N != 0) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;

}


void main_(istream &cin) {
    ll N;
    cin >> N;
    vector<ll> A(N - 1 + 1);
    for (int i = 0; i <= N - 1; i++) {
        cin >> A[i];
    }
    solve(N, A);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





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

int main(){
    int n;
    cin>>n;
    long long a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    
    sort(a,a+n);
    int cnt=1,ans=0;

    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]){
            cnt++;
        }
        else {
            if(cnt>a[i-1]){
                ans+=cnt-a[i-1];
            }
            else if(cnt<a[i-1]){
                ans+=cnt;
            }
            cnt=1;
        }
    }

    if(cnt>a[n-1]){
         ans+=cnt-a[n-1];
    }
    else if(cnt<a[n-1]){
         ans+=cnt;
    }
    

    cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int n, m;
int x[100005];
int y[100005];

const int MOD = 1000000007;

int main() {
  scanf("%d%d", &n, &m);
  for(int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  for(int i = 0; i < m; i++) {
    scanf("%d", &y[i]);
  }
  ll xx = 0;
  {
    int s = n-1;
    for(int i = n-1; i >= 0; i--) {
      xx += s * (ll)x[i];
      xx %= MOD;
      xx += MOD;
      xx %= MOD;
      s -= 2;
    }
  }
  ll yy = 0;
  {
    int s = m-1;
    for(int i = m-1; i >= 0; i--) {
      yy += s * (ll)y[i];
      yy %= MOD;
      yy += MOD;
      yy %= MOD;
      s -= 2;
    }
  }
  printf("%lld\n", (xx*yy) % MOD);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n;
  rep(i,1,n+1)
  {
    ll p=n/i;
    ll fi=i,la=p*i;
    m=(fi+la)*p/2;
    k+=m;
  }
  cout<<k;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
  // cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3608
while True:
    H, W = list(map(int, input().split()))
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i % 2 == 0:
                if j % 2 == 0:
                    print("#", end = "")
                else:
                    print(".", end = "")
            else:
                if j % 2 == 0:
                    print(".", end = "")
                else:
                    print("#", end = "")
        print()
    print()


Measured memory_bytes: 7000
/*  -*- coding: utf-8 -*-
 *
 * 2820.cc: Binary Sequence
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_E2 = 1 << 18; // = 262144

/* typedef */

template <typename T, const int MAX_E2>
struct SegTreeFG {
  int n, e2;
  int ls[MAX_E2], rs[MAX_E2];
  T fs[MAX_E2], gs[MAX_E2];
  bool dfs[MAX_E2];
  SegTreeFG() {}

  void init(int _n) {
    n = _n;
    for (e2 = 1; e2 < n; e2 <<= 1);
    for (int i = 0, j = e2 - 1; i < e2; i++, j++)
      ls[j] = i, rs[j] = i + 1;
    for (int j = e2 - 2; j >= 0; j--)
      ls[j] = ls[j * 2 + 1], rs[j] = rs[j * 2 + 2];
  }

  T &get(int i) { return fs[e2 - 1 + i]; }
  void set(int i, T v) { get(i) = v; }

  T f() { return fs[0]; }
  T g() { return gs[0]; }
  
  void setall() {
    for (int j = e2 - 2; j >= 0; j--) {
      int j0 = j * 2 + 1, j1 = j0 + 1;
      fs[j] = fs[j0] + fs[j1];
      gs[j] = gs[j0] + gs[j1] + get(rs[j0] - 1) * get(ls[j1]);
    }
  }

  T get_range(int r0, int r1, int k) {
    int i0 = ls[k], i1 = rs[k];
    if (r1 <= i0 || i1 <= r0) return 0;
    if (r0 <= i0 && i1 <= r1) return fs[k];

    int k0 = k * 2 + 1, k1 = k0 + 1;
    if (dfs[k]) {
      fs[k0] = fs[k1] = fs[k] / 2;
      gs[k0] = gs[k1] = gs[k] / 2;
      dfs[k0] = dfs[k1] = true;
      dfs[k] = false;
    }

    T v0 = get_range(r0, r1, k0);
    T v1 = get_range(r0, r1, k1);
    return v0 + v1;
  }
  T get_range(int r0, int r1) { return get_range(r0, r1, 0); }

  void set_range(int r0, int r1, T v, int k) {
    int i0 = ls[k], i1 = rs[k];
    if (r1 <= i0 || i1 <= r0) return;
    if (r0 <= i0 && i1 <= r1) {
      fs[k] = v * (i1 - i0);
      gs[k] = v * (i1 - i0 - 1);
      dfs[k] = true;
      return;
    }

    int k0 = k * 2 + 1, k1 = k0 + 1;
    if (dfs[k]) {
      fs[k0] = fs[k1] = fs[k] / 2;
      gs[k0] = gs[k1] = gs[k] / 2;
      dfs[k0] = dfs[k1] = true;
      dfs[k] = false;
    }

    set_range(r0, r1, v, k0);
    set_range(r0, r1, v, k1);

    fs[k] = fs[k0] + fs[k1];
    gs[k] =
      gs[k0] + gs[k1] +
      get_range(rs[k0] - 1, rs[k0]) * get_range(ls[k1], ls[k1] + 1);
  }
  void set_range(int r0, int r1, T v) { set_range(r0, r1, v, 0); }
};

/* global variables */

char s[MAX_N + 4];
SegTreeFG<int,MAX_E2> st;

/* subroutines */

/* main */

int main() {
  int n, q;
  scanf("%d%s%d", &n, s, &q);

  st.init(n);

  for (int i = 0; i < n; i++) st.set(i, s[i] - '0');
  st.setall();
  //printf("f=%d, g=%d\n", st.f(), st.g());

  while (q--) {
    int li, ri, bi;
    scanf("%d%d%d", &li, &ri, &bi);
    li--;

    st.set_range(li, ri, bi);
    printf("%d\n", st.f() - st.g());
  }

  return 0;
}



Measured memory_bytes: 7372
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type Work struct {
	Cost, Deadline int
}
type Works []Work
func (w Works) Len() int {
	return len(w)
}

func (w Works) Less(i, j int) bool {
	return w[i].Deadline < w[j].Deadline
}

func (w Works) Swap(i, j int) {
	w[i], w[j] = w[j], w[i]
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	var ws []Work
	for i:= 0; i < n; i++ {
		ws = append(ws, Work{nextInt(), nextInt()})
	}
	sort.Sort(Works(ws))

	now := 0
	for i := 0; i < n; i++ {
		now += ws[i].Cost

		if ws[i].Deadline < now {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    pi arr[n];
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        arr[i] = MP(x, i);
    }
    sort(arr, arr + n);
    for(int i = 0; i < n; i++) {
        cout << arr[i].S+1 << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1664
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: usize = read();
    let b: usize = read();
    let c: usize = read();

    println!("{} {} {}", c, a, b);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long int 
using namespace std;
int main()
{
   ll a,b,c,k;
   cin>>a>>b>>c>>k;
   if(k<=a)cout<<k;
   else if(k>a&&k<=a+b)cout<<a;
   else if(k>a+b&&k<=a+b+c)cout<<(a+((k-(a+b))*(-1)));
}

Measured memory_bytes: 3624
import math
from functools import reduce


K = int(input())


def gcd(*numbers):
    return reduce(math.gcd, numbers)

sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            sum += gcd(a, b, c)

print(sum)

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

using namespace std;

typedef long long ll;

int cnt[2][100001];
int mx[2][2];
int main()
{

//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  int a[n];
  for(int i = 0;i < n;i++)
    cin >> a[i];
  for(int i = 0;i < n;i++)
    cnt[i & 1][a[i]]++;
  for(int i = 0;i <= 100000;i++){
    for(int j = 0;j < 2;j++){
      if(cnt[j][i] >= cnt[j][mx[j][1]])
        mx[j][0] = mx[j][1], mx[j][1] = i;
      else if(cnt[j][i] > cnt[j][mx[j][0]])
        mx[j][0] = i;
    }
  }
  if(mx[0][1] == mx[1][1]){
    cout << n - max(cnt[0][mx[0][0]] + cnt[1][mx[1][1]], cnt[0][mx[0][1]] + cnt[1][mx[1][0]]);
  }else{
    cout << n - cnt[0][mx[0][1]] - cnt[1][mx[1][1]];
  }
  return 0;
}


Measured memory_bytes: 1408
a = int(input(""))
b = int(input(""))
c = int(input(""))
x = int(input(""))

d = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                d+=1

print(d)


Measured memory_bytes: 3060
li = [int(i) for i in input()]

for i in range(2**3):
    ans = str(li[0])
    tmp = li[0]
    for j in range(3):
        if (i>>j)&1:
            tmp += li[j+1]
            ans += '+'+str(li[j+1])
        else:
            tmp -= li[j+1]
            ans += '-'+str(li[j+1])
    if tmp == 7:
        ans += '=7'
        print(ans)
        exit()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <map>
#include <string>

using namespace std;

// ??????????????§??????????????¢?´¢?????????????????????

int main(){
	
	map<string, int> m;
	map<string, int>::iterator ite;
	
	int n, num;
	
	cin >> n;
	
	string str;
	
	for(int i = 0; i < n; i++){
		
		cin >> str >> num;
		ite = m.find(str);
		if(ite != m.end()){
			ite -> second += num;
		}else{
			m.insert(make_pair(str, num));
		}
	}
	for(int i = 1; i <= 5; i++){
		for(ite = m.begin(); ite != m.end(); ite++){
			if((ite -> first).size() == i){
				cout << ite -> first << " " << ite -> second << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1224
#include "iostream"
#include "string"
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n;
    cin>>s;
    
    if(s.length()>n)
    {
        s=s.substr(0,n)+"...";
        
    }

    cout<<s<<endl;
    return 0;
    
    
    
}


Measured memory_bytes: 3100
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}			
		}
	}
}

void Show(vector<int> N) {
	for (int i = 0; i < N.size(); i++) {
		cout << N[i];
		if (i != N.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	string A, B;
	cin >> A >> B;
	int N = stoi(A + B);
	for (int i = 1; i <= 100100; i++) {
		if (N%i == 0 && N / i == i) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <iterator>
#include <list>
using namespace std;

int main() {
	int q, query, xd;
	cin >> q;
	list<int> L;
	list<int>::iterator a = L.begin();
	for (int i = 0; i < q; i++) {
		cin >> query;
		switch (query) {
		case 0:
			cin >> xd;
			L.insert(a, xd);
			advance(a, -1);
			break;
		case 1:
			cin >> xd;
			advance(a, xd);
			break;
		default:
			advance(a, 1);
			L.erase(prev(a));
		}
	}
	for (int& i : L) cout << i << endl;
}


Measured memory_bytes: 18664