akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

struct Node{
    vector<int> friends;
    vector<int> blocks;
    bool next = false;
};

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

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

    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x){
            return x;
        }
        else{
            return par[x] = root(par[x]);
        }
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        par_size[ry] += par_size[rx];
    }

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

    int get_size(int x){
        int rx = root(x);
        return par_size[rx];
    }
};




int main(){

    int N, M, K;
    cin >> N >> M >> K;

    vector<Node> v(N);
    UnionFind tree(N);
    for (int i = 0; i < M; i++){
        int f1, f2;
        cin >> f1 >> f2;
        f1 --;
        f2 --;
        v[f1].friends.push_back(f2);
        v[f2].friends.push_back(f1);
        if(f2 - f1 == 1) v[f1].next = true;
        if(f1 - f2 == 1) v[f2].next = true;
        tree.unite(f1, f2);
    }

    for (int i = 0; i < K; i++){
        int f1, f2;
        cin >> f1 >> f2;
        f1 --;
        f2 --;
        v[f1].blocks.push_back(f2);
        v[f2].blocks.push_back(f1);
    }


    for (int i = 0; i < N; i++){
        int block_cnt = 0;
        for(int j = 0; j < v[i].blocks.size(); j++){
            int id = v[i].blocks[j];
            if( tree.same(i, id) ) block_cnt ++;
        }
        if(i != N - 1) cout << tree.get_size(i) - v[i].friends.size() - block_cnt - 1 << " ";
        else cout << tree.get_size(i) - v[i].friends.size() - block_cnt - 1 << endl;;
    }


}

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

int n;
int a[3531];

int main(){
  scanf("%d", &n);
  for(int i=0;i<n;i++)scanf("%d",a+i);
  int ans = accumulate(a,a+n,-n);
  printf("%d\n", ans);
  return 0;
}

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

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

    int tmp = n;
    vector<int> num;
    while(true){
        if(tmp < 10){
            num.push_back(tmp);
            break;
        }
        num.push_back(tmp % 10);
        tmp /= 10;
    }

    if(n % accumulate(num.begin(), num.end(), 0) == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 1;
vector<pair<int, int>> v;
int n;
long long dp[101] [maxN];
long long knapsack(int at, int weight){
    if(at == n || weight == 0)
        return 0;
    if(dp[at] [weight] != -1)
        return dp[at] [weight];
    long long k = 0;
    if(v[at].first > weight)
        k = knapsack(at + 1, weight);
    else
        k = max(k, max(knapsack(at + 1, weight), knapsack(at + 1, weight - v[at].first) + v[at].second));
    return dp[at] [weight] = k;
}
int main( ){
    int w;
    cin >> n >> w;
    v.resize(n);
    for(int i = 0; i < n; i++)
        cin >> v[i].first >> v[i].second;
    memset(dp, -1, sizeof dp);
    long long ans = knapsack(0, w);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 82508
/***
*	?????§??¬?´???° Crea
****/

#include <iostream>
#include <stdio.h>
using namespace std;

void swap(long x, long y)
{
	long temp = x;
	x = y;
	y = temp;
}

long gcd(long x, long y)
{
	if (x < y){
		swap(x, y);
	}
	while (y > 0){
		int r = x % y;
		x = y;
		y = r;
	}
	return x;
}

int main(void)
{
	long x,	y;

	cin >> x >> y ;
	
	x=gcd(x,y);
	
	cout << x << endl;
	
	return 0;
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    string a, b, c;
    cin >> a >> b >> c;

    cout << (char)(a[0] - 32) << (char)(b[0] - 32) << (char)(c[0] - 32) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

ll extgcd(ll a,ll b, ll &x, ll &y){ //extended Euclidean algorithm, used for modular multiplicative inverse
    ll d = a;
    if (b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1; y = 0;
    }
    return d; //return gcd(a,b)
}

ll mod_inv(ll a, ll m = MOD){ //return inv(a) mod m, ax+my=gcd(a,m)=1, m is prime int, ax-1=mq equiv. ax-mq=1
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m; //From (possibly) negative x to positive x
}

vector<ll> fact,invfact;
void calc_fact(int n, ll m = MOD)
{ //Calculate factorial up to n
    fact.resize(n + 1);
    invfact.resize(n + 1);
    fact[0] = invfact[0] = 1;
    REP(i, n)
    {
        fact[i + 1] = fact[i] * (i + 1) % m;
        invfact[i + 1] = invfact[i] * mod_inv(i + 1) % m;
    }
}
ll perm(int n,int k ,ll m = MOD){
    if(n<0||k<0||k>n)return 0;
    return fact[n] * invfact[n - k] % m;
}
ll comb(int n,int k, ll m = MOD){
    if(n<0||k<0||k>n)return 0;
    return (fact[n] * invfact[n - k] % m) * invfact[k] % m;
}

void solve() {
    int n,m;
    cin >> n >> m;
    ll ans = 0;
    calc_fact(m);
    REP(i,n+1) {
        ll tmp = (comb(m,n)*perm(n,n)) % MOD;
        tmp = (tmp * comb(n,i)) % MOD;
        tmp = (tmp * comb(m-i,n-i)) % MOD;
        tmp = (tmp * perm(n-i,n-i)) % MOD;
        if (i % 2 == 1) tmp = MOD - tmp;
        ans = (ans + tmp) % MOD;
    }
    cout << ans << endl;
}

int main() {
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}


Measured memory_bytes: 11168
#include<stdio.h>
int main(){
  int n,mo,m,y,c,a,t,max,ri,i;
  double r;
  scanf("%d",&n);
  while(n--){
    scanf("%d %d %d",&m,&y,&c);
    max=0;
    while(c--){
      scanf("%d %lf %d",&a,&r,&t);
      mo=m;
      if(a){
	for(i=0;i<y;i++){
	  mo=mo*(1+r);
	  mo-=t;
	}
      }
      else{
	for(i=ri=0;i<y;i++){
	  ri+=(int)(mo*r);
	  mo-=t;
	}
	mo+=ri;
      }//printf("%d\n",mo);
      if(max<mo)max=mo;
    }
    printf("%d\n",max);
  }
  return 0;
}
	

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int MAX = 2000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  ll x, y;
  cin >> x >> y;

  ll n = (x + y) / 3;
  ll k = 2 * n - x;

  if ((x + y) % 3 != 0 || x < 0 || y < 0) {
    cout << 0 << endl;
  } else {
    COMinit();
    ll ans = COM(n, k);

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 47104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b; cin >> a >> b;
	long long thing[3];
	for(int i=0; i<3; i++)
		cin >> thing[i];
	string str; cin >> str;
	int arr[a + 50];
	for(int i=0; i<a; i++)
	{
		if(str[i] == 'r') 	   arr[i] = 2;
		else if(str[i] == 's') arr[i] = 0;
		else				   arr[i] = 1;
	}
	long long ans = 0, dp[a + 50][3] = {0};
	for(int i=0; i<b; i++)
	{
		for(int j=0; j<3; j++)
			if(j == arr[i]) dp[i][j] = thing[j];
		int ind = i;
		for(int j = i + b; j < a; j += b)
		{
			for(int k=0; k<3; k++)
			{
				for(int l=0; l<3; l++)
				{
					if(k == l) continue;
					if(arr[j] == k)
					{
						dp[j][k] = max(dp[j][k], dp[j - b][l] + thing[k]);
					}
					else
					{
						dp[j][k] = max(dp[j][k] ,dp[j - b][l]);
					}
				}
			}
			ind = j;
		}
		ans += max(dp[ind][0], max(dp[ind][1], dp[ind][2]));
	}
//	for(int i=0; i<a; i++)
//	{
//		for(int j=0; j<3; j++)
//			cout << dp[i][j] << ' ';
//		cout << '\n';
//	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3200
A = []
A.append([int(i) for i in input().split()])
A.append([int(i) for i in input().split()])
A.append([int(i) for i in input().split()])
N = int(input())
b = []
check = [[0]*3 for i in range(3)]
for i in range(N):
    new = int(input())
    b.append(new)
    for j in range(3):
        for k in range(3):
            if A[j][k] == new:
                check[j][k] = 1
    
flag = 0

for i in range(3):
    if check[i][0] == 1 and check[i][1] == 1 and check[i][2] == 1:
        flag = 1
    if check[0][i] == 1 and check[1][i] == 1 and check[2][i] == 1:
        flag = 1

if check[0][0] == 1 and check[1][1]==1 and check[2][2] == 1:
    flag = 1
if check[0][2] == 1 and check[1][1]==1 and check[2][0] == 1:
    flag = 1


if flag == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

void func(void)
{
//DEBUG_OUT("----\n");
    uint32 N, M;
    cin >> N;
    vector<uint32> D(N);
    for(uint32 i=0; i<N; i++){
        uint32 d;
        cin >> d;
        D[i] = d;
    }
    sort(D.begin(), D.end());
    cin >> M;
    vector<uint32> T(M);
    for(uint32 i=0; i<M; i++){
        uint32 t;
        cin >> t;
        pair<vector<uint32>::iterator, vector<uint32>::iterator> iter;
        iter = equal_range(D.begin(), D.end(), t);
        if(*iter.first != t){
            cout << "NO" << endl;
            return;
        }else{
            D.erase(iter.first);
        }
    }
    cout << "YES" << endl;

    return;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)



int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,A,B;
  cin >> N >> A >> B;
  cout << min(A*N, B) << endl;
  
  return 0;
    

}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>

using namespace std;

int main(){
  queue<int> q;
  int n,k,u;
  int c[101];
  vector<int>  d[101];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    d[u].resize(k);
    for(int j=0;j<k;j++) cin>>d[u][j];
  }
  for(int i=0;i<=n;i++) c[i]=-1;
  q.push(1);
  c[1]=0;
  int a;
  while(!q.empty()){
    a=q.front(),q.pop();
    for(int i=0;i<d[a].size();i++)
      if( d[a][i]>1 && c[d[a][i]]==-1){
	q.push(d[a][i]);
	c[d[a][i]]=c[a]+1;
      }
  }
  for(int i=1;i<=n;i++) cout<<i<<" "<<c[i]<<endl;
  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
using Graph=vector<vector<int>>;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  lint n;
  lint sum=0;
  cin>>n;
  vector<lint> l;
  map<lint,lint> m;
  rep(i,n){
    int j;
    cin>>j;
    l.pb(j);
    m[j]++;
    sum+=j;
  }
  lint q;
  cin>>q;
  vector<pair<lint,lint>> li;
  rep(i,q){
    pair<lint,lint> d;
    cin>>d.first>>d.second;
    li.pb(d);
  }
  rep(i,q){
    lint b,c;
    b=li[i].first;
    c=li[i].second;
    lint num=m[b];
    m[b]=0;
    m[c]+=num;
    sum-=b*num;
    sum+=c*num;
    cout<<sum<<endl;
  }


}

Measured memory_bytes: 11636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

void solve(int n){
  int h,m,s;
  int imos[86405]={0};
  rep(i,n){
    scanf("%d:%d:%d",&h,&m,&s);
    imos[h*3600+m*60+s]++;
    scanf("%d:%d:%d",&h,&m,&s);
    imos[h*3600+m*60+s]--;
  }
  REP(i,1,86405)imos[i]+=imos[i-1];
  int ans=0;
  rep(i,86405){
    ans=max(ans,imos[i]);
  }
  cout<<ans<<endl;
}

int main(){
  int n;
  while(scanf("%d",&n),n){
    solve(n);
  }
  return 0;
}



Measured memory_bytes: 3544
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define N 105
using namespace std;
char s[105], t[105];
void sort(char *x, int t) {
    if(t == 1) {
        for(int i = 0; x[i] != '\0'; i++) 
            for(int j = i+1; x[j] != '\0'; j++) 
                if(x[i] > x[j]) {
                    char t = x[i];
                    x[i] = x[j];
                    x[j] = t;
                }
    }
    else {
        for(int i = 0; x[i] != '\0'; i++) 
            for(int j = i+1; x[j] != '\0'; j++) 
                if(x[i] < x[j]) {
                    char t = x[i];
                    x[i] = x[j];
                    x[j] = t;
                }
    }        
}

int main() {
    scanf("%s\n%s", s, t);
    sort(s, 1);
    sort(t, 0);
    if(strcmp(s, t) < 0) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

using namespace std;

int main() {

    int X, Y, Z;
    cin >> X >> Y >> Z;

    int x = X;
    int y = Y;
    int z = Z;

    X = z;
    Y = x;
    Z = y;

    cout << X << " " << Y << " " << Z << endl;

    return 0;
}

Measured memory_bytes: 256
program main
implicit None
	integer::n,tm,i,a
	integer,allocatable::c(:),t(:)
	
	read *,n,tm
	
	allocate(c(n))
	allocate(t(n))
	
	do i = 1,n
		read *,c(i),t(i)
	enddo
	
	a = 1001
	
	do i = 1,n
		if(c(i) <= a)then
			if(t(i) <= tm)then
				a = c(i)
			endif
		endif
	enddo
	
	if (a == 1001)then
		print 101,"TLE"
		else
		print 102,a
	endif
	
101 format(a)
102 format(i0)
end program main

Measured memory_bytes: 384
val A = 0
val C = 1
val G = 2
val T = 3

fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val dp = Array(N + 1,  { Array(4, { Array(4, { Array(4, { 0 })})}) })

    // Initialize
    (0..3).forEach { i ->
        (0..3).forEach { j ->
            (0..3).forEach { k ->
                if ((i == A && j ==G && k ==C) || (i == A && j == C && k == G) || (i == G && j == A && k ==C)) {
                    dp[3][i][j][k] = 0
                } else {
                    dp[3][i][j][k] = 1
                }
            }
        }
    }

    (4..N).forEach {n ->
        (0..3).forEach { i ->
            (0..3).forEach { j ->
                (0..3).forEach { k ->
                    (0..3).forEach { x ->
                        // A_GC
                        if (i == A && j != C && k == G && x == C) {

                            // AGC
                        } else if (i == A && j == G && k == C) {

                            // ACG
                        } else if (i == A && j == C && k == G) {

                            // GAC
                        } else if (i == G && j == A && k == C) {

                            // AG_C
                        } else if (i == A && j == G && k != C && x == C) {

                        } else if ((j == A && k ==G && x ==C) || (j == A && k == C && x == G) || (j == G && k == A && x ==C)) {

                        } else {
                            dp[n][j][k][x] = (dp[n][j][k][x] + dp[n-1][i][j][k]) % 1000000007
                        }
                    }
                }
            }
        }
    }

    var answer = 0
    dp[N].forEach { threed ->
        threed.forEach { two2 ->
            two2.forEach {
                answer = (answer + it) % 1000000007
            }
        }
    }
    println(answer)
}

Measured memory_bytes: 34324
N, K = map(int, input().split())
S = input()

c = 0
A = []
if S[0] == '0':
    A.append(0)
for i in range(len(S)-1):
    c += 1
    if S[i] != S[i+1]:
        if S[i] == '0':
            A.append(-c)
        else:
            A.append(c)
        c = 0
if S[-1] == '0':
    A.append(-c-1)
    A.append(0)
else:
    A.append(c+1)


if len(A)//2 <= K:
    print(sum([abs(i) for i in A]))
else:

    d = 2*K+1

    s = sum([abs(i) for i in A[:d]])
    ans = s
    for i in range(0, len(A)-d, 2):
        s = s-A[i]-abs(A[i+1])+abs(A[i+d])+A[i+d+1]
        ans = max(ans, s)
    print(ans)


Measured memory_bytes: 4980
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define rep(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define min3(a,b,c)     min(a,min(b,c))



int main(){ FastIO;

ll n,i,x;cin>>n;
ll a[n]; for(i=0;i<n;i++) cin>>a[i];
x=a[0];
for(i=1;i<n;i++) x=x^a[i];
for(i=0;i<n;i++) cout<<(x^a[i])<<" ";
}

Measured memory_bytes: 5112
use proconio::input;

fn main() {
    input! {
        n: i32,
    }

    let mut ans = "No";
    if n / 100 % 10 == 7 || n / 10 % 10 == 7 || n % 10 == 7 {
        ans = "Yes";
    }
    println!("{}", ans);
}


Measured memory_bytes: 2136
#include <stdio.h>

int main()
{
    int a, b, c, t;
    
    scanf("%d %d %d", &a, &b, &c);// 653 563 536 356
    if (a > b)
    {
        t = a; a = b; b = t;
    }
    if(b > c)
    {
        t = b; b = c; c = t;
    }
    if(a > b)
    {
        t = a; a = b; b = t;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}



Measured memory_bytes: 2728
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 100005
#define M 10005
#define INF 1000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-7
using namespace std;

vector<int>e[N];
int ans;
int n,k;
int dfs(int u,int fa)
{
    int max_dep = 1;
    for(auto v:e[u])
    {
        if(v == fa)continue;
        max_dep = max(max_dep,dfs(v,u)+1);
    }
    //cout<<u<<" "<<max_dep<<endl;
    if(u!=1&&max_dep>=k+(fa == 1))
    {
       // cout<<"change "<<u<<endl;
        ans++;
        max_dep = 0;
    }
    return max_dep;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin>>n>>k)
    {
        int x;
        cin>>x;
        ans = 0;
        if(x!=1)ans++;
        FOR(i,1,n)e[i].clear();
        FOR(i,2,n)
        {
            cin>>x;
            e[x].PB(i);
        }
        dfs(1,-1);
        cout<<ans<<endl;
    }
    return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL a(n), b(n+1);
	rep(i, n) cin >>a[i];
	
	rep(i, n) b[i+1] = b[i] + a[i];
	ll ans = 1LL<<55;;
	rep2(i,1, n-2){
		
		ll bf = b[i+1], af = b[n] - bf;
		int z1 = lower_bound(all(b), bf/2) - b.begin();
		int z2 = lower_bound(all(b), bf+af/2) - b.begin();
	
		rep2(j1, z1-2, z1+3) rep2(j2, z2-2, z2+3){
			if(j1 <0 || j1>=i) continue;
			if(j2 <i || j2 >=n-1) continue;
			ll mn = min({b[j1+1], b[i+1]-b[j1+1], b[j2+1]-b[i+1], b[n] -b[j2+1]});
			ll mx = max({b[j1+1], b[i+1]-b[j1+1], b[j2+1]-b[i+1], b[n] -b[j2+1]});
			ans = min(ans, mx - mn);
		}
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 3328
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define int long long
   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; }
    const int MAX =500005;
const int MOD =998244353;
//const int MOD =1e9+7;
using mint = static_modint<MOD>;
//using mint = modint;
ostream& operator << (ostream& ost, const mint& m){
  ost << m.val();
  return ost;
}
istream& operator >> (istream& ost,  mint& m){
  int a;
  ost >> a;
  m=a;
  return ost;
}

using S=pair<mint,int>;
using F=int;

  vector<mint> FAC={1,1},FINV={1,1},INV={1,1};
  void init(int m){
     for(int i=FAC.size();i<=m;i++){
      FAC.push_back(FAC[i-1]*i);
      INV.push_back(-INV[MOD%i]*(MOD/i));
      FINV.push_back(FINV[i-1]*INV[i]);
    }
  }
  mint fac(int m){
    init(m);
    return FAC[m];
  }
  mint inv(int m){
    init(m);
    return INV[m];
  }
  mint finv(int m){
    init(m);
    return FINV[m];
  }
  mint COM(int n,int k){
    if(n<k || n<0 || k<0)return 0;
    init(n);
    return FAC[n]*FINV[k]*FINV[n-k];
  }


signed main(){
int n;
cin>>n;
int h[2*n];
for(int i=0;i<2*n;i++)cin>>h[i];
sort(h,h+2*n);
int k=1;

deque<vector<mint>> w;
for(int i=1;i<=2*n;i++){
  if(1!=2*n&&h[i]==h[i-1]){
    k++;
    continue;
  }
  vector<mint>v;
  mint a=1;
  
  for(int j=0;j*2<=k;j++){
    v.push_back(fac(k)*finv(k-2*j)*finv(j)*a);
    a*=inv(2);
  }
  w.push_back(v);

  k=1;

}
while(w.size()!=1){
  auto v2=convolution(w[0],w[1]);
  w.pop_front();
  w.pop_front();
  w.push_back(v2);
}
mint a=1;
mint ans=0;
for(int i=n;i>=0;i--){
  if(i<w[0].size())ans+=w[0][i]*fac(2*(n-i))*finv(n-i)*a*(1-i%2*2);
  a*=inv(2);
}
cout<<ans<<endl;




}



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


using namespace std;
 
int main(){
int a,b,c,d;

    cin >> a >> b >> c >> d;

    int max; 
    int min;
    if(a > c){
        max = a;
    }else{
        max = c;
    }

    if(b > d){
        min = d;
    }else{
        min = b;
    }

    if(max > min){
        cout << 0;
    }else{
        cout << min - max;
    }
        return 0;
    

}


Measured memory_bytes: 256
import Control.Applicative
import Data.List
import Control.Monad

main = getLine >>= putStrLn.show.answer.map read.words

answer :: [Int] ->Int
answer [a, b, c, x, y] = (a*x+b*y) `min` calc `min` allC where
    allC = 2*c * max x y
    xycount = (min x y)
    calc = 2*c * xycount + a*(x-xycount) + b*(y-xycount)
    

Measured memory_bytes: 508
#include <iostream>
#include <map>
#include <set>
#include <string>
using namespace std;
set <string> S;
map <string,int> M;
int n;
string str[101];

int saiki(int ima){
  int sum=0;
  string a;
  for(int i=0;i<str[ima].size();i++){
    if(str[ima][i] ==','){
      if(M.count(a)==1 && S.count(a)==0) S.insert(a),sum+=saiki(M[a]);
      else if(S.count(a)==0)sum++;
      S.insert(a);
      a="";
      continue;
    }
    a+=str[ima][i];
  }
  return sum;
}

int main(){

  while(1) {
    cin >>n;
    if(n==0) break;
    S.clear(),M.clear();
    for(int i=0;i<n;i++){
      cin >> str[i];
      string a,b;
      for(int j=0;j<str[i].size();j++){
	if(str[i][j] == ':') M[a]=i,a="";
	if(str[i][j] !=':')a+=str[i][j];
      }
      str[i] = a;
      str[i][str[i].size()-1]=',';
    }
    cout <<saiki(0)<<endl;;
  }
  return 0;
}

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

#define ll int64
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
     
using namespace std;

const int maxn=110000;
int n,h[maxn],f[maxn];
int main(){
    IO;    
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&h[i]);
    f[1]=0,f[2]=abs(h[1]-h[2]);
    for(int i=3;i<=n;i++) f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
    printf("%d",f[n]);    
    return 0;
}

Measured memory_bytes: 1024
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

signed main()
{
    int n, m;
    cin >> n >> m;
    if (n == 1 && m == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    else if (n == 1)
    {
        cout << m - 2 << endl;
        return 0;
    }
    else if (m == 1)
    {
        cout << n - 2 << endl;
        return 0;
    }
    else if (n == 2 || m == 2)
    {
        cout << 0 << endl;
        return 0;
    }
    else
    {
        cout << n * m - 2 * (n - 1) - 2 * (m - 1) << endl;
        return 0;
    }
    return -1;
}

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

int main() {
  ll x;
  cin >> x;
  cout << (x / 500 * 1000) + (x % 500 / 5 * 5) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

ll getC(ll n, ll r) {
    ll ans = 1;
    if (n < r || n <= 0 || r <= 0) return 0;
    for (ll i = 1; i <= r; i++) {
        ans *= n + 1 - i;
        ans /= i;
    }
    return ans;
}

int main() {

    int N, A, B;
    cin >> N >> A >> B;
    vector<ll> v(N);
    rep(i,N) cin >> v[i];

    sort(v.rbegin(), v.rend());
    ll sum = 0;
    rep(i,A) sum += v[i];
    cout << fixed << setprecision(10) << ((double) sum / (double) A) << endl;

    ll ans = 0;
    int top_index = -1;
    int len = 0;

    rep(i,N) {
        if (v[i] == v[A - 1]) len++;
        if (top_index < 0 && v[i] == v[A - 1]) top_index = i;
    }

    int k = A - top_index;
    
    if (v[0] == v[A - 1]) {
        for (int i = A; i <= min(len, B); i++) ans += getC(len, i);
    } else {
        ans = getC(len, k);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3808
#include <iostream>

int main() {
    int N;
    std::cin >> N;

    const int max = N / 7;
    bool flg = false;
    for (int i = 0; i <= max; ++i) {
        const int tmp = N - i*7;
        if (tmp % 4 == 0) {
            flg = true;
            break;
        }
    }
    const auto ret = flg ? "Yes" : "No";

    std::cout << ret << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,i,tmp;
  cin >> n;
  vector<pair<int,int>>pairs(n);
  for(i=0;i<n;i++){
  	cin >> tmp;
    pairs[i]=make_pair(tmp,i+1);
  }

  sort(pairs.begin(),pairs.end());
  
  for(i=0;i<n;i++){
  	cout << pairs[i].second << ' ';
  }
  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define in insert
#define mp make_pair
using namespace std;
const int N = 1e5+123;
int a[N];
int n,m,k;
string s;
set<int>setik;


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

	cin >> n >> m;
	cout << (n - 1) * (m - 1);

}

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

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

  int oven, odd;
  if(K%2 == 0){
    oven = K/2;
    odd = K/2;
  } else if(K%2 == 1){
    oven = K/2;
    odd = K/2 + 1;
  }

  int res = oven * odd;
  cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
   
int a,b;
   
scanf("%d %d",&a,&b);
 
if(a>b)
  printf("a > b\n");
else if(a<b)
  printf("a < b\n");
else
  printf("a == b\n");
 
return 0;
   
}

Measured memory_bytes: 580
#include<stdio.h>
int main(void)
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	if(A==B&&A==C&&C==B){
		printf("No\n");
	}
	else{
		if(A!=B&&A!=C&&C!=B){
			printf("No\n");
		}
			else{
				printf("Yes\n");
			}
		}
	return 0;
}

Measured memory_bytes: 1596
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

map<P,ll> mp;
map<P,bool> used;

ll gcd(ll a,ll b){
    ll M=max(a,b);
    ll m=min(a,b);
    if(m==0){
        return M;
    }
    return gcd(m,M%m);
}

ll modpow(ll a, ll n, ll mod){
    ll ret=1;
    while(n>0){
        if(n&1) ret=ret*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ret;
}

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

    ll zero=0;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        if(a==0 && b==0){
            zero++;
            continue;
        }
        ll g=gcd(abs(a),abs(b));
        a/=g; b/=g;
        if(a>=0 && b<=0){
            mp[P(-a,-b)]++;
        }else if(a<=0 && b<=0){
            mp[P(-a,-b)]++;
        }else{
            mp[P(a,b)]++;
        }
    }

    if(zero==n){
        cout<<n<<endl;
        return 0;
    }

    ll ans=1;
    for(auto p:mp){
        P key=p.first;
        //cout<<key.first<<","<<key.second<<":"<<p.second<<endl;
        if(!used[P(key.first,key.second)]){
            if(key.first>=0 && key.second>=0){
                ll buf=modpow(2,p.second,MOD)+modpow(2,mp[P(-key.second, key.first)],MOD)-1;
                buf%=MOD;
                ans*=buf;
                ans%=MOD;
                used[P(key.first, key.second)]=true;
                used[P(-key.second, key.first)]=true;
            }else{
                ll buf=modpow(2,p.second,MOD)+modpow(2,mp[P(key.second, -key.first)],MOD)-1;
                buf%=MOD;
                ans*=buf;
                ans%=MOD;
                used[P(key.first, key.second)]=true;
                used[P(key.second, -key.first)]=true;
            }

        }
        //cout<<ans<<endl;
    }
    ans+=zero;
    ans--;
    ans=(ans+MOD)%MOD;
    cout<<ans<<endl;

}

Measured memory_bytes: 53584
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
#define min(q,w) ((q)>(w)?(w):(q))
#define max(q,w) ((q)<(w)?(w):(q))
#define PR(...) printf(__VA_ARGS__)
#define EPR(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long LL;
const int N=100500;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
LL n,ans;
LL fj[100][2];
int fj0;
void FJ(LL n)
{
	for(LL i=2;i*i<=n;++i)if(n%i==0)
	{
		fj[++fj0][0]=i;
		for(;n%i==0;n/=i)++fj[fj0][1];
	}
	if(n>1)fj[++fj0][0]=n,fj[fj0][1]=1;
}
void ss(int q,LL e)
{
	if(q>fj0)
	{
		if(e>1)if(n/(e-1)==n%(e-1))ans+=e-1;
		return;
	}
	ss(q+1,e);
	fo(i,1,fj[q][1])ss(q+1,e*=fj[q][0]);
}
int main()
{
	int q,w;
	scanf("%lld",&n);
	FJ(n);
	ss(1,1);
	printf("%lld\n",ans );
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);i++)
#define RREP(i, n) FOR(i, n, 0);
 
int gcd(int a, int b) {
  if(b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
 
signed main () {
  cin.tie(0);
  cout << setprecision(10);
 
  int t; cin >> t;
  REP(i, t) {
    int a, b, c, d; cin >> a >> b >> c >> d;
 
    if(a < b || b > d) {
      cout << "No" << endl;
      continue;
    }
 
    if(c >= b) {
      cout << "Yes" << endl;
      continue;
    }
 
    int g = gcd(b, d);
    int ma = b - g + (a % g);
 
    if(ma > c) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let (n, q) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let id = 0usize;
    let mut st = SegmentTree::new(n, id, |&x, &y| x + y);
    for _ in 0..q {
        let (com, x, y) = {
            let i = read::<usize>();
            (i[0], i[1], i[2])
        };
        if com == 0 {
            let v = st.get(x);
            st.update(x, y + v);
        } else {
            let m = st.apply(x, y + 1);
            println!("{}", m);
        }
    }
}

#[allow(dead_code)]
pub struct SegmentTree<T, F> {
    n: usize,
    v: Vec<T>,
    id: T,
    f: F,
}

impl<T, F> SegmentTree<T, F>
where
    T: Clone,
    F: Fn(&T, &T) -> T,
{
    pub fn new(n: usize, id: T, f: F) -> Self {
        let mut cap = 1;
        while cap <= n { cap *= 2; }
        SegmentTree {
            n: cap,
            v: vec![id.clone(); 2 * cap],
            id: id,
            f: f,
        }
    }

    #[inline]
    pub fn get(&self, i: usize) -> T {
        self.v[i + self.n].clone()
    }

    pub fn update(&mut self, mut i: usize, x: T) {
        i += self.n;
        self.v[i] = x;
        while { i /= 2; i > 0 } {
            self.v[i] = (self.f)(&self.v[i * 2], &self.v[i * 2 + 1]);
        }
    }

    pub fn apply(&mut self, s: usize, t: usize) -> T {
        let (mut x, mut y) = (self.id.clone(), self.id.clone());
        let (mut s, mut t) = (s + self.n, t + self.n);
        while s < t {
            if s % 2 != 0 {
                x = (self.f)(&x, &self.v[s]);
                s += 1;
            }
            if t % 2 != 0 {
                t -= 1;
                y = (self.f)(&self.v[t], &y);
            }
            s /= 2;
            t /= 2;
        }
        (self.f)(&x, &y)
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 7080
import java.net.SecureCacheResponse;
import java.util.*;

public class Main {

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

        int res = 0;
        for (int i = n; i <= 999; i++) {
            if (i == 111 || i == 222 || i == 333 || i == 444 || i == 555
            || i == 666 || i == 777 || i == 888 || i == 999) {
                res = i;
                break;
            }
        }

        System.out.println(res);
    }
}


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

int main(void){
    double x1,x2,y1,y2,x,y;
    
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    x = x2 - x1;
    y = y2 - y1;
    
    printf("%lf\n" , sqrt(x*x+y*y));
    
    return 0;
}


Measured memory_bytes: 2132
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
 
 
int main(){
  ll H1,M1,H2,M2,K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  long long ans = H2*60+M2-(H1*60+M1);
  cout << H2*60+M2-K- (H1*60+M1) << endl;
}

Measured memory_bytes: 3592
import java.util.*;
import java.io.*;
import java.lang.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(in);
		String odd = sc.nextLine();
		String even = sc.nextLine();
		char[] result = new char[odd.length()+even.length()];
		for (int i = 0; i < odd.length(); i++) {
			result[i*2] = odd.charAt(i);
		}
		for (int i = 0; i < even.length(); i++) {
			result[i*2+1] = even.charAt(i);
		}
		out.println(result);
}
}

Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
int main()
{ 
    int x;
    cin>>x;
    int q,r;
    q=x/100;
    r=x%100;
    if(r>q*5){cout<<0<<endl;}
    else{cout<<1<<endl;}
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    if(len([i for i in A if i <= 0])%2):
        print(sum(map(abs,A))-2*min(map(abs,A)))
    else:
        print(sum(map(abs,A)))

    return

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16244
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N;
  cin >> N;
  i64 ans = 0;
  for (i64 i = 1; i <= N; i++)
    ans += (N - 1) / i;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int n,l,sum;
int main(){
    cin>>n>>l;
    sum=l*n+(n-1)*n/2;
    if(l<=0&&l+n-1>=0)cout<<sum<<endl;
    else if(abs(l)<abs(l+n-1))cout<<sum-abs(l)<<endl;
    else cout<<sum+abs(l+n-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N=2009,inf=1e18;
pair <int,int> ar[N];
int n,dp[N][N];
int f(int p,int x){
    if(p<x or x<0)return -inf;
    if(p==0)return 0;
    if(dp[p][x]!=-1)return dp[p][x];
    int r=max(ar[p].f*abs(ar[p].s-x)+f(p-1,x-1),ar[p].f*abs(ar[p].s-(n+1-p+x))+f(p-1,x));
    return dp[p][x]=r;
}
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> ar[i].f;
        ar[i].s=i;
    }
    sort(ar+1,ar+n+1);
    reverse(ar+1,ar+n+1);
    memset(dp,-1,sizeof dp);
    int ans=0;
    for(int i=1;i<=n;i++)
        ans=max(ans,f(n,i));
    cout << ans;
}

Measured memory_bytes: 35348
#include"bits/stdc++.h"
using namespace std;
int main(){
	string s,ans;
	cin>>s;
	for(auto i:s){
		if(ans.size() && i=='B')
			ans.pop_back();
		else if(i=='0')
			ans+='0';
		else if(i=='1')
			ans+='1';
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
int a,b,c,d;
scanf("%d %d %d",&a,&b,&c);

if(a>b){
d=a;
a=b;
b=d;
}

if(b>c){
d=b;
b=c;
c=d;
}

if(a>b){
d=a;
a=b;
b=d;
}

printf("%d %d %d\n",a,b,c);


return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
long long p = 998244353;
long long n, m, x, y, e, f, g;
long long ans;
char s[300005];
long long a[300005][7];
int main() {
	scanf("%lld", &n);
	scanf("%s", s,40);
	m = 3 * n;
	a[0][0] = 0;
	a[0][1] = 0;
	a[0][2] = 0;
	for (int i = 1; i <= m; i++) {
		a[i][0] = a[i - 1][0];
		a[i][1] = a[i - 1][1];
		a[i][2] = a[i - 1][2];
		if (s[i - 1] == 'R')a[i][0]++;
		if (s[i - 1] == 'G')a[i][1]++;
		if (s[i - 1] == 'B')a[i][2]++;
		x = n;
		for (int j = 0; j < 3; j++) {
			if (a[i][j] < x) x = a[i][j];
		}
		a[i][3] = x;
		a[i][4] = a[i][0] - a[i][3];
		a[i][5] = a[i][1] - a[i][3];
		a[i][6] = a[i][2] - a[i][3];
	}
	ans = 1;
	for (long long i = 1; i <= n; i++) {
		ans *= i;
		ans %= p;
	}
	for (int i = m; i > 0; i--) {
		if (a[i][3] == a[i - 1][3]) {
			if (s[i - 1] == 'R')y = 0;
			if (s[i - 1] == 'G')y = 1;
			if (s[i - 1] == 'B')y = 2;
			e = a[i][4];
			f = a[i][5];
			g = a[i][6];
			if (e > f) {
				x = e;
				e = f;
				f = x;
			}
			if (f > g) {
				x = f;
				f = g;
				g = x;
			}
			if (e > f) {
				x = e;
				e = f;
				f = x;
			}
			if (a[i][4 + y] == f) {
				ans *= f;
			}
			else {
				ans *= (g - f);
			}
			ans %= p;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 16896
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        quit()
    for h in range(H):
        for w in range(W):
            h_mod = h % 2
            w_mod = w % 2
            if h_mod == w_mod:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7008
#  --*-coding:utf-8-*--

numOfA,numOfB,M = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = min(A) + min(B)

for _ in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, A[x-1] + B[y-1] - c)

print(ans)


Measured memory_bytes: 18736
def solution():
    a, b, c, x, y = map(int, input().split())
    if x == y:
        print(min((a*x + b*y),(c*2*x)))
    elif x > y:
        print(min((a*x + b*y),(c*2*x),(a*max(x-y, 0) + (c*2*y))))
    else:
        print(min((a*x + b*y),(c*2*y),(b*max(y-x, 0) + (c*2*x))))

solution()


Measured memory_bytes: 3064
from sys import stdin
from itertools import product
# from line_profiler import LineProfiler

def rotate_clockwise(matrix):
    return list(map(list, zip(*matrix)))[::-1]

def main():
    while(True):
        n,m = map(int, stdin.readline().split())
        if not n:
            break
        w = [list(map(int, stdin.readline().split())) for _ in range(n)]
        p = [list(map(int, stdin.readline().split())) for _ in range(m)]
        rp = [p]
        for _ in range(3):
            p = rotate_clockwise(p)
            rp.append(p)
        ds = [[ [i,j,rp[r][i][j]] for i,j in product(range(m),range(m)) if rp[r][i][j] != -1] for r in range(4)]
        flag = True
        for i,j,a in product(range(n-m+1),range(n-m+1),ds):
            for b in a:
                if w[i+b[0]][j+b[1]] - b[2]:
                    break
            else:
                print(j+a[0][1]+1,i+a[0][0]+1)
                flag = False
                break
        if flag: print("NA")

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()


Measured memory_bytes: 7104