akhauriyash/Code-Regression huggingface dataset:
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define rep(i,n) for(LL i=0;i<n;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n,option) f(i,0,n)cout<<v[i]<<option;
#define all(a) a.begin(),a.end()
#define size(s) ((int)s.size())
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INT_INF 1<<29
#define LL_INF 1LL<<60
#define MOD 10000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<int>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using vpi = vector<pi>;

#pragma endregion


//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0) {
			return false;
		}
	}
	return true;
}

void y_n(bool p) {
	if (p)_y();
	else _n();
}

void Y_N(bool p) {
	if (p) _Y();
	else _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b)*b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= 1000000007;
	}
	return ret;
}

#pragma endregion


/************************************************************************/
signed main(void) {
	cin.tie(0); ios::sync_with_stdio(false);

	while (1) {
		int n, a, b, c, x;
		cin >> n >> a >> b >> c >> x;
		if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0) {
			break;
		}
		vi y(n);
		f_vI(y, n);
		int ans = 0;
		int i = 0;
		while (ans < 10001) {
			if (y[i] == x) {
				i++;
			}
			if (i >= n)break;
			x = ((a*x + b) % c);
			ans++;
		}
		if (ans > 10000) {
			cout << -1;
		}
		else {
			cout << ans;
		}
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

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

    ll ans=0;
    while(x<=y){
        ans+=1;
        x*=2;
    }
    cout << ans << endl;
    return 0;
}

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

void rotate( int* a, int* x, int n, int b, int m, int e )
{
    for( int k = 0; k < e - b; k++ )
    {
        int i = b + k;
        int j = b + ( k + e - m ) % ( e - b );
        x[j] = a[i];
    }

    for( int i = 0; i < n; i++ )                                //配列aの値を更新することを忘れない。
        a[i] = x[i];
}

int main()
{
    int n, q;
    int b, m, e;

    cin >> n;

    int a[n], x[n];

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

    for( int i = 0; i < q; i++ )
    {
        cin >> b >> m >> e;
        rotate( a, x, n, b, m, e );
    }
        
    for( int i = 0; i < n; i++ )
    {
        if( i != n - 1 )
            cout << x[i] << " ";
        else
            cout << x[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int fun(char *);
int fun(char *s)
{
    char t[17]="CODEFESTIVAL2016";
    int i,ans=0;
    int n=strlen(s);
    for(i=0;i<n;i++)
    {
        if(t[i]!=s[i])
        {
            ans++;
        }
    }
    return ans;
}
int main()
{
    char a[17];
    scanf("%s",a);
    printf("%d\n",fun(a));
    return 0;
}

Measured memory_bytes: 128
function main(input){
    num = parseInt(input);
    sen = 0;
    go = 0;
    sen = Math.floor(num/500);
    go = Math.floor((num - sen*500)/5);
    out = sen*1000 + go*5;
    console.log(out);

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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


int main(){

    string S;
    cin >> S;
    if(S=="Sunny"){
        cout << "Cloudy" << endl;
    }else if(S=="Cloudy"){
        cout << "Rainy" << endl;
    }else if(S=="Rainy"){
        cout << "Sunny" << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 250005;

vector<pll> A[2][MX];
int D[MX];
int N;

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", D+i);
	for(int t = 0; t < 2; t++){
		int m = 0;
		ll lsum = 0, rsum = 0;
		for(int i = 1; i <= N; i++){
			rsum += D[i];
			while(m+1 <= i && lsum + D[m+1] <= rsum - D[m+1]){
				lsum += D[m+1];
				rsum -= D[m+1];
				m++;
			}
			if(lsum == rsum) A[t][i].emplace_back(lsum, rsum);
			else{
				A[t][i].emplace_back(lsum, rsum);
				A[t][i].emplace_back(lsum + D[m+1], rsum - D[m+1]);
			}
		}
		reverse(D+1, D+N+1);
	}
	ll ans = 1e18;
	for(int i = 2; i <= N-2; i++){
		for(pll c1 : A[0][i]){
			for(pll c2 : A[1][N-i]){
				vector<ll> tp;
				tp.push_back(c1.first);
				tp.push_back(c1.second);
				tp.push_back(c2.first);
				tp.push_back(c2.second);
				sort(tp.begin(), tp.end());
				ans = min(ans, tp.back() - tp[0]);
			}
		}
	}
	printf("%lld\n", ans);
}


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

#define N 100005

using namespace std;

int n,ans;

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();bool f=1;
	while(!isdigit(ch)){
		if(ch=='-')f^=1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=(2*f-1);
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

void init(){
	cin>>n;
}

int dig(int num){
	int r=0;
	while(num>0){
		r+=num%10;
		num/=10;
	}
	return r;
}
 
int main(){
	init();
	ans=INT_MAX;
	for(register int i=1;i<n;i++){
		int j=n-i;
		if(dig(i)+dig(j)<ans)
		ans=dig(i)+dig(j);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
#define PI 3.141592653589

int main(){
    int x, y, a=1000000, b=-1000000;
long c = 0;
    cin >> y;
    for(int i = 0;i < y;i++){
        cin >> x;
        c += x;
        if(a>x)a=x;
        if(b<x)b=x;
    }
    cout <<a<<" "<<b<<" "<<c<<endl;
    return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b, c, d; cin >> a >> b >> c >> d;
    cout << (a != c);
}



Measured memory_bytes: 256
import copy

N = int(input())
X = list(map(int, input().split()))

x = copy.deepcopy(X)
x.sort()

x1 = x[N // 2 - 1]
x2 = x[N // 2]

for xx in X:
    if xx <= x1:
        print(x2)
    else:
        print(x1)

Measured memory_bytes: 32688
import sys
input = sys.stdin.readline

import collections

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
    n = int(input())
    a_li = list(map(int, input().rstrip().split()))
    c = collections.Counter(a_li)
    total = 0
    dict_1 = {}
    dict_2 = {}
    for k, v in c.items():
        if v > 1:
            num = combinations_count(v, 2)
            total += num
            dict_1[k] = num
            if v - 1 > 1:
                dict_2[k] = combinations_count(v-1, 2)
            else:
                dict_2[k] = 0
        else:
            dict_1[k] = 0
            dict_2[k] = 0

    for a in a_li:
        ans = total - dict_1[a] + dict_2[a]
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38964
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 2e5 + 10;

int a[N], ctr[N];

int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		++ctr[a[i]];
	}

	sort(ctr, ctr + n + 1, greater <int>());
	int ans = n;
	for (int i = 0; i < k; ++i) {
		ans -= ctr[i];
	}

	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
queue<int> A;
stack<int> B;

int main()
{
  int H, W, N, a;
  cin >> H >> W >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    for (int j = 0; j < a; j++)
    {
      int b = i + 1;
      A.push(b);
    }
  }
  for (int h = 0; h < H; h++)
  {
    if (h % 2 == 0)
    {
      for (int w = 0; w < W; w++)
      {
        cout << A.front();
        if (w != W - 1)
          cout << ' ';
        A.pop();
      }
    }
    else
    {
      for (int w = 0; w < W; w++)
      {
        int f = A.front();
        B.push(f);
        A.pop();
      }
      for (int w = 0; w < W; w++)
      {
        while (!B.empty())
        {
          cout << B.top();
          B.pop();
          if (!B.empty())
          {
            cout << ' ';
          }
        }
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    vector<double> q(n);
    rep(i, n) q[i] = ((double)p[i] + 1.0) / 2.0;
    vector<double> sum(n + 1);
    rep(i, n) sum[i + 1] = sum[i] + q[i];
    double ans = 0;
    for (int i = k; i <= n; i++)
        ans = max(ans, sum[i] - sum[i - k]);
    printf("%.8lf\n", ans);
}


Measured memory_bytes: 4992
n = int(input())
edgeArray = [list(map(int, input().split())) for i in range(n)]
edgeList = []
rootList = [-1 for i in range(n)]
sumLength = 0

def getRoot(x):
    r = rootList[x]
    if r < 0:
        rootList[x] = x
    elif r != x:
        rootList[x] = getRoot(r)
    return rootList[x]
        
for i in range(n):
    for j in range(i):
        if edgeArray[i][j] != -1:
            edgeList.append([edgeArray[i][j], i, j])
edgeList.sort(key=lambda x: x[0])
for e in edgeList:
    x = getRoot(e[1])
    y = getRoot(e[2])
    if x != y:
        sumLength += e[0]
        rootList[x] = rootList[y] = min(x, y)
print(sumLength)

Measured memory_bytes: 6292
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
void input()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
using namespace std;
typedef long long ll ;
const long long N = 1e5,OO=0x3f3f3f3f;
ll n,weight,w[105],v[105];
ll dp[105][N+5];

int main()
{
    cin>>n>>weight;
    for(int i=0; i<n; i++)
        cin>>w[i]>>v[i];

    for(int i=0; i<105; i++)
        for(int j=0; j<=N; j++)
            dp[i][j]=1e18;

    dp[0][v[0]]=w[0];
    for(int i=1; i<n; i++)
    {
        dp[i][v[i]]=w[i];
        for(int j=0; j<=N; j++)
        {
            ll &ret=dp[i][j];
            ret=min(ret,dp[i-1][j]);
            if(v[i]<=j)
                ret=min(ret,w[i]+dp[i-1][j-v[i]]);
            }
    }
    for(int i=N; i>=0; i--)
        if(dp[n-1][i]<=weight)
        {
            cout<<i<<endl;
            break;
        }
}


Measured memory_bytes: 85576
#include <bits/stdc++.h>
#define Keep_calmYou_are_still_learning ios_base::sync_with_stdio(false);cin.tie(NULL);//freopen("out.txt","w",stdout);
typedef long long ll;
typedef long double ld;
using namespace std;

ll n , m;
vector<vector<ll>> adj;
vector<ll> lvl,dp;

ll dfs(ll s)
{
    if (dp[s]!=-1)
        return dp[s];
    dp[s]=0;
    for ( ll i=0;i<adj[s].size();i++)
            dp[s]=max(dp[s],dfs(adj[s][i]));
    dp[s]++;
    return dp[s];
}

int main()
{
    Keep_calmYou_are_still_learning;

    cin>>n>>m;
    adj=vector<vector<ll>> (n+1);
    lvl=vector<ll> (n,0);
    dp=vector<ll> (n,-1);
    for (ll x,y,i=0;i<m;i++)
        cin>>x>>y,lvl[y-1]++,adj[x-1].push_back(y-1);
    ll ans=0;
    for (ll i=0;i<n;i++)
        if (lvl[i]==0)
            ans=max(ans,dfs(i)-1);
    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 12032
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  int n;
  cin >> n;
  
  ll a[n];
  REP(i,n){
    cin >> a[i];
  }
  
  REP(i,n-1){
    a[i+1] += a[i];
  }
  
  ll ans1 = 0,cnt = 0;
  REP(i,n){
    if(i%2 == 0){
      if(a[i]+cnt <= 0) {
        ans1 += -(a[i]+cnt)+1;
        cnt += -(a[i]+cnt)+1;
      }
    }
    else{
      if(a[i]+cnt >= 0) {
        ans1 += a[i]+cnt+1;
        cnt -=  a[i]+cnt+1;
      }
    }
  }
  
  ll ans2 = 0;cnt = 0;
  REP(i,n){
    if(i%2 == 1){
      if(a[i]+cnt <= 0) {
        ans2 += -(a[i]+cnt)+1;
        cnt += -(a[i]+cnt)+1;
      }
    }
    else{
      if(a[i]+cnt >= 0) {
        ans2 += a[i]+cnt+1;
        cnt -= a[i]+cnt+1;
      }
    }
  }
  
  cout << min(ans1,ans2) << endl;

  return 0;
}


Measured memory_bytes: 1024
H = int(input())
W = int(input())
N = int(input())

if H < W:
  count = N // W
  rate = N / W
  if count < rate:
     count += 1
  print(count)
else:
  count = N // H
  rate = N / H
  if count < rate:
     count += 1
  print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
  int r,D,x;
  cin >>r>>D>>x;
  vector<int> vec(10);
  vec.at(0)=r*x-D;
  for(int i=1;i<10;i++){
    vec.at(i)=vec.at(i-1)*r-D;
  }
  for(int i=0;i<10;i++){
    cout <<vec.at(i)<<endl;
  }
}
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>


using namespace std;

int dp[1001][1001];

int main() {
	string s1,s2;
	cin >> s1 >> s2;
	
	const int l1 =  s1.length();
	const int l2 =  s2.length();

	for (int p1 = 0; p1 <= l1; p1++) {
		for (int p2 = 0; p2 <= l2; p2++) {
			dp[p1][p2] = 0;
		}
	}

	for (int p1 = 0; p1 <= l1; p1++) {
		dp[p1][0] = p1;

	}
	for (int p2 = 0; p2 <= l2; p2++) {
		dp[0][p2] = p2;		
	}





	for (int p1 = 1; p1 <= l1; p1++) {
		for (int p2 = 1; p2 <= l2; p2++) {
			if (s1.at(p1-1) == s2.at(p2-1)) {
 				dp[p1][p2] = min(min(dp[p1-1][p2] + 1
 					,dp[p1][p2-1] + 1)
 					,dp[p1-1][p2-1]);
			} else {
 				dp[p1][p2] = min(min(dp[p1-1][p2] + 1
 					,dp[p1][p2-1] + 1)
 					,dp[p1-1][p2-1]+1
 					);
			}
		}
	}

	cout << dp[l1][l2] << endl;



	return 0;
}

Measured memory_bytes: 5096
package main

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

type Scanner struct {
  sc *bufio.Scanner
  buf []byte
}

func NewScanner(r io.Reader) *Scanner {
  s := &Scanner{
    sc: bufio.NewScanner(r),
  }
  s.sc.Split(bufio.ScanWords)
  s.sc.Buffer(s.buf, 200000)
  return s
}

func (s *Scanner) nextInt() int {
  if s.sc.Scan() {
    i, err := strconv.Atoi(s.sc.Text())
    if err != nil {
      panic(err)
    }
    return i
  }
  panic("failed to scan")
}

func (s *Scanner) nextString() string {
  if s.sc.Scan() {
    return s.sc.Text()
  }
  panic("failed to scan")
}

func solve(r io.Reader) {

  sc := NewScanner(r)
  N := sc.nextInt()
  Q := sc.nextInt()
  S := sc.nextString()
  dp := make([]int, N)
  
  c := 0
  for i := 0; i < N-1; i++ {

    dp[i] = c
    if S[i] == 'A' && S[i+1] == 'C' {
      c++
    }
  }
  dp[N-1] = c
  for i := 0; i < Q; i++ {
    l := sc.nextInt()
    r := sc.nextInt()
    fmt.Println(dp[r-1] - dp[l-1])
  }
}

func main() {
  solve(os.Stdin)
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long mod = 1e9 + 7;
long long phi[N] = {};
bool isp[N] = {};
int n, k;
void init() {
    isp[1] = true;
    for (int i = 1; i <= k; i++)
        phi[i] = i;
    for (int i = 2; i <= k; i++)
        if (!isp[i]) {
            phi[i]--;
            for (int j = i << 1; j <= k; j += i) {
                isp[j] = true;
                phi[j] = phi[j] / i * (i - 1);
            }
        }
    for (int i = 1; i <= k; i++)
        phi[i] = (phi[i] + phi[i - 1]) % mod;
}
long long ksm(long long a, long long b) {
    if (b == 1) return a % mod;
    else if (b & 1) return a * ksm(a * a % mod, b >> 1) % mod;
    else return ksm(a * a % mod, b >> 1);
}
int main() {
    cin >> n >> k;
    init();
    long long ans = 0, t, l = k, r;
    while (l) {
        t = k / l;
        l = k / (t + 1);
        r = k / t;
        ans = (ans + (phi[r] - phi[l]) * ksm(t, n)) % mod;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4516
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  b.append(0)
k = 0
if(n%2==1):
  k = (n-1)//2
  m = -1
else:
  k = n//2
  m = 1
for i in range(n):
  if(i%2==0):
    b[k+m*i//2]=a[i]
  else:
    b[k-m*(i+1)//2]=a[i]
ans = ""
for i in range(n):
  ans += str(b[i])+" "
print(ans)  
   
 

 

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

int main(){
    int q;
    cin >> q;
    set<int> s;
    for(int i=0; i<q; i++){
        int a, x;
        cin >> a >> x;
        if(a == 0){
            s.insert(x);
            cout << s.size() << endl;
        }else if(a == 1){
            cout << s.count(x) << endl;
        }else if(a == 2){
            s.erase(x);
        }else{
            int y;
            cin >> y;
            auto first = s.lower_bound(x);
            auto last = s.upper_bound(y);
            for(auto itr = first; itr != last; ++itr) {
                cout << *itr << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 12392
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

// Binary Indexed Tree
template <class T> struct BIT {
    vector<T> d;

    BIT() = default;
    BIT(int n) { init(n); }
    void init(int n) { d.assign(n + 1, 0); }

    // a: 1-indexed
    inline void add(int a, T x) {
        for (int i = a; i < (int)d.size(); i += i & -i) {
            d[i] = d[i] + x;
        }
    }

    // [1, a]
    // a: 1-indexed
    inline T sum(int a) {
        T res = 0;
        for (int i = a; i > 0; i -= i & -i) {
            res = res + d[i];
        }
        return res;
    }

    // [a, b)
    // a, b: 1-indexed
    inline T sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
};

template <typename T> map<T, int> coordinate_compression(vector<T> x) {
    int n = x.size();
    vector<int> y(n);
    iota(y.begin(), y.end(), 0);
    sort(y.begin(), y.end(), [&](int i, int j) { return x[i] < x[j]; });
    map<T, int> res;
    for (int i : y) if (!res.count(x[i])) {
        int j = res.size();
        res[x[i]] = j;
    }
    return res;
}

int Q;
int c[200010], a[200010], b[200010];

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

    vector<int> as[2];
    cin >> Q;
    REP (i, Q) {
        cin >> c[i];
        if (c[i] == 1) {
            cin >> a[i] >> b[i];
            as[0].push_back(a[i]);
            as[1].push_back(-a[i]);
        }
    }
    map<int, int> zip[2], cnt;
    REP (i, 2) zip[i] = coordinate_compression<int>(as[i]);
    using P = pair<int, int>;
    tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update> s[2];
    BIT<int> bit[2];
    REP (i, 2) bit[i].init(zip[i].size());
    int sumb = 0;
    REP (i, Q) {
        if (c[i] == 1) {
            s[0].insert(P(a[i], cnt[a[i]]++));
            s[1].insert(P(-a[i], cnt[-a[i]]++));
            sumb += b[i];
            bit[0].add(zip[0][a[i]] + 1, a[i]);
            bit[1].add(zip[1][-a[i]] + 1, -a[i]);
        } else {
            int med = s[0].find_by_order((s[0].size() - 1) / 2)->first;
            int num0 = s[0].order_of_key(P(med + 1, 0));
            int num1 = s[1].order_of_key(P(-med + 1, 0));
            cout << med << " " << sumb + (num0 * med - bit[0].sum(zip[0][med] + 1)) + (-num1 * med - bit[1].sum(zip[1][-med] + 1)) << endl;
        }
    }
}

Measured memory_bytes: 47948
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;

struct Node {
    Node *prev,*next;
    int key;
};

Node *nil;

Node* searchList(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void init(){
    nil = (Node *)malloc(sizeof(Node));//new Node;
    nil->prev = nil;
    nil->next = nil;
}
void printList(){
  Node* cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void insertNode(int x){
    Node *p = (Node *)malloc(sizeof(Node)); //new Node;
    p->key = x;
    p->prev = nil;
    //今回入ったノードのnextにこれまで入っていた先頭の要素のポインターを設定
    p->next = nil->next;
    //元あったノードのprev側ポインターに今回追加する要素(p)のポインターを設定する
    nil->next->prev = p;
    nil->next = p;
    p->prev = nil;

}

void deleteNode(Node* t){
    if(t == nil) return;
    t->next->prev = t->prev;
    t->prev->next = t->next;
    free(t);
}

void deleteFirst(){
    if(nil->next == nil) return;
    deleteNode(nil->next);
}
void deleteLast(){
    if(nil->prev == nil) return;
    deleteNode(nil->prev);
}
void deleteKey(int key){
    deleteNode(searchList(key));
}

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

    int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insertNode(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
            if ( com[6] == 'F' ) deleteFirst();
            else if ( com[6] == 'L' ) deleteLast();
      } else {
	deleteKey(key); nd++; 
      }
      size--;
    }
  }

  printList();


    // free(nil);
    return 0;
}


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

int main(){
  int N,L;
  cin>>N>>L;
  
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  
  sort(S.begin(),S.end());
  
  for(int i=0;i<N;i++){
    cout << S.at(i);
  }
  cout<<endl;
  
  return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
MOD=10**9+7
max_n=2*10**5
fac=[1]*(max_n+1)
inv=[1]*(max_n+1)
ifac=[1]*(max_n+1)
for n in range(2,max_n+1):
    fac[n]=(fac[n-1]*n)%MOD
    inv[n]=MOD-inv[MOD%n]*(MOD//n)%MOD
    ifac[n]=(ifac[n-1]*inv[n])%MOD
def comb(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    return (fac[n]*ifac[k]*ifac[n-k])%MOD
print(sum([(comb(N,k)*comb(N-1,k))%MOD for k in range(min(N,K)+1)])%MOD)

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    string s;
    cin>>s;
    int s_size = s.size();
    int count = 1;
    int ans = s_size;
    REP(i, 1, s_size){
        if(s[i-1] != s[i]){
            ans = min(ans, max(i, s_size-i));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3724
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;
int main(void) {
	char x[1], y[1];
	cin >> x[0] >> y[0];
	if (x[0] < y[0])
		cout << '<';
	else if (x[0] > y[0])
		cout << '>';
	else
		cout << '=';
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int c,x,y,z=1;

	scanf("%d %d",&x,&y);
	if(y > x){
		c = x;
		x = y;
		y = c;
	}
	for( ;z!=0; ){
		z = x%y;
		x = y;
		y = z;
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 592
#pragma GCC optimize("O3")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>ll(b);i--)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
#define INF 1000000000000 
#define MOD 1000000007 
#define MAXR 100000 
#define PB push_back 
#define MP make_pair 
#define F first 
#define S second 
#define Umap unordered_map
#define Uset unordered_set


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

    int A, B, C, K;
    cin >> A >> B >> C >> K;

    REP(i, K) {
        if (B <= A) B *= 2;
        else if (C <= B) C *= 2;
    }   

    bool flag = false;
    if (B > A && C > B) flag = true;

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3652
INF = 1<<29
def dijkstra(pos, route, cost)
  arr = [pos]
  dist = [INF]*($n+1)
  dist[pos] = 0
  until arr.empty?
    a = arr.min{ |x, y| dist[x] <=> dist[y] }
    arr.delete(a)
    route[a].each do |b|
      d = dist[a] + cost[a][b]
      if (old = dist[b]) > d
        dist[b] = d
        if old == INF
          arr << b 
        end
      end
    end
  end
  dist
end

while l = gets
  $n, m, s, g1, g2 = l.split.map(&:to_i)
  break if $n == 0
  route = ($n+1).times.map{ [] }
  r_route = ($n+1).times.map{ [] }
  cost = ($n+1).times.map{ [0]*($n+1) }
  r_cost = ($n+1).times.map{ [0]*($n+1) }
  m.times do
    b1, b2, c = gets.split.map(&:to_i)
    route[b1] << b2; r_route[b2] << b1
    cost[b1][b2] = c
    r_cost[b2][b1] = c
  end
  dist_s = dijkstra(s, route, cost)
  dist_g1 = dijkstra(g1, r_route, r_cost)
  dist_g2 = dijkstra(g2, r_route, r_cost)
  res = INF
  (1..$n).each{ |i| res = [res, dist_s[i] + dist_g1[i] + dist_g2[i]].min }
  p res
end

Measured memory_bytes: 9784
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;
ll MOD=998244353;

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


int main(){
    ll X,Y,Z;cin>>X>>Y>>Z;
    cout<<Z<<" "<<X<<" "<<Y<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1e18
int n;
int a[111];
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	int ans=0;
	for(int i=1;i<=100;i++){
		int cnt=0;
		rep(j,n){
			if(a[j]>=i){
				if(j==0||a[j-1]<i)cnt++;
			}
		}
		ans+=cnt;
	}
	cout<<ans<<endl;
	return 0;
}


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

int frog(int n, int h[])
{
	int dp[n]={INT_MAX};
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2; i<n; i++)
	{
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	}
	return dp[n-1];
}

int main()
{
	int n;
	cin >> n;
	int h[n];
	for(int i=0; i<n; i++)
		cin >> h[i];
	int ans = frog(n, h);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4304
H, W, K = map(int, input().split())


def pattern(n):
    if n < 1:
        return 1
    elif n == 1:
        return 2
    elif n == 2:
        return 3
    else:
        return pattern(n-2) + pattern(n-1)


def memorize(func):
    cache = {}

    def inner(*args):
        if args in cache:
            return cache[args]
        else:
            ret = func(*args)
            cache[args] = ret
            return ret

    return inner


@memorize
def count(h, W, K):
    if h == 0:
        if K == 1:
            return 1
        else:
            return 0
    ret = 0
    if 1 < K:
        ret += count(h-1, W, K-1) * pattern(K-3) * pattern(W-K-1)
    ret += count(h-1, W, K) * pattern(K-2) * pattern(W-K-1)
    if K < W:
        ret += count(h-1, W, K+1) * pattern(K-2) * pattern(W-K-2)
    return ret


print(count(H, W, K) % 1000000007)

Measured memory_bytes: 3316
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    A = LMIIS()
    maxNumBits = len(bin(max(A)))-2
    numBitsOne = [0]*maxNumBits
    numBitsZero = [0]*maxNumBits

    for a in A:
        for i,b in enumerate(bin(a)[2:][::-1]):
            if b == '1':
                numBitsOne[i] += 1
    
    for i in range(maxNumBits):
        numBitsZero[i] = N - numBitsOne[i]

    numAnsBitsOne = []
    numAnsBits = list(map(lambda t : t[0]*t[1] , 
[t for t  in zip(numBitsOne,numBitsZero)]))
    
    ans = 0
    for i in range(maxNumBits):
        ans += numAnsBits[i] * 2**i
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 124304
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int i,j,t;
    boost;

    ll a,b,n,x;
    cin>>a>>b>>n;
    x=min(b-1,n);
    a*=x;
    a/=b;
    cout<<a;

    return 0;
}



Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
const int N=100009;
int n,a[N],ans;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    for(int i=1;i<=n;i++)
        if(i+1>a[i+1])
        {
            for(int j=i+1;a[j]==i;j++)
                ans^=1;
            ans|=(a[i]-i)&1;
            puts(ans? "First":"Second");
            return 0;
        }

    return 0;
} 


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int cnt = 0,ans = 0;
    string s;
    cin>>s;
    int n = s.length();
    rep(i,0,n){
        if(s[i]=='p'&&cnt > 0){
            cnt--;
        }
        else if(s[i]=='p'&&cnt<=0){
            cnt++;ans--;
        }
        else if(s[i]=='g'&&cnt>0){
            cnt--;ans++;
        }
        else{
            cnt++;
        }
    }
    cout<<ans<<endl;
}

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

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

ll K,Q;
vll d;

void solve(){
    ll n,x,m;
    cin>>n>>x>>m;
    x%=m;
    ll zero=0;
    ll sum=x;
    F0R(i,K){
        ll val=d[i]%m;
        ll timer=(n-1)/K;
        if((n-1)%K>i){
            timer++;
        }
        if(val==0){
            zero+=timer;
        }else{
            sum+=(timer*val);
        }
    }
    ll out=(sum/m)-(x/m);
    cout<<(n-1)-(out+zero)<<endl;
}



int main(){
    
    cin>>K>>Q;
    d.resize(K);
    F0R(i,K){
        cin>>d[i];
    }
    while(Q--){
        solve();
    }
    return 0;
}


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

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

    int count[10][10];
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            count[i][j] = 0;
        }
    }

    for (int i = 1; i <= N; i++) {
        string str = to_string(i);
        int head = stoi(str.substr(0, 1));
        int tail = stoi(str.substr(str.length() - 1, 1));

        count[head][tail]++;
    }

    int res = 0;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            res += count[i][j] * count[j][i];
        }
    }

    cout << res;
}


Measured memory_bytes: 256
s = list(input())
n = len(s)

r = 0

a = (n-1) / 2
b = (n+3) / 2

s_1 = s[:int(a)]
s_2 = s[int(b-1):]


def cond(l=None):
    if l is None:
        l = []
    
    l_rev = list(reversed(l))
    if l == l_rev:
        return 0
    else:
        return 1


for l in (s, s_1, s_2):
    r = cond(l)
    
    if r != 0:
        break

if r == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<stdio.h>

long long int absh(long long int x);

int main(void)
{
    int n,i;

    scanf("%d",&n);

    long long int a[n],sum=0;

    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
        sum+=a[i];
    }

    long long int x=a[0],abs=absh(sum-2*a[0]);
    for(i=1;i<n-1;i++){
        x+=a[i];
        if(absh(sum-2*x)<abs)
            abs=absh(sum-2*x);
    }

    printf("%lld",abs);

    return 0;
}

long long int absh(long long int x)
{
    if(x<0)
        return -x;
    else
        return x;
}

Measured memory_bytes: 1664
solve :: [Int] -> String
solve [c11,c12,c13,c21,c22,c23,c31,c32,c33]
  | c11-c12-c21+c22 == 0 && c12-c13-c32+c33 == 0 && c11-c13-c22+c23-c31+c32 == 0 = "Yes"
  | otherwise =	"No"

main = getContents >>= putStrLn . solve . concat . map (map read . words) . lines

Measured memory_bytes: 508
#include <iostream>

long max(long T, long A, long min_pole[])
{
    long right = min_pole[0] / T;
    if (min_pole[0] % T != 0) right++;

    long left = min_pole[1] / A;
    if (min_pole[1] % A != 0) left++;

    return right >= left? right : left; 
}

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

    long T[N];
    long A[N];
    int i;
    for (i = 0; i < N; i ++) {
        std::cin >> T[i] >> A[i];
    }

    long min_pole[2] = {1, 1};
    for (i = 0; i < N; i++) {
        if (T[i] < min_pole[0] || A[i] < min_pole[1]) {
            long n = max(T[i], A[i], min_pole);
            min_pole[0] = T[i] * n;
            min_pole[1] = A[i] * n;
        } else {
            min_pole[0] = T[i];
            min_pole[1] = A[i];
        }
    }
    
    std::cout << min_pole[0] + min_pole[1];

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<57;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

string s,t;
int q;

int main(){
	cin>>s>>t>>q;
	int S=s.size(),T=t.size();
	vi a(S+1),b(T+1);
	for(int i=0;i<S;i++) a[i+1]=(s[i]=='A'?1:2);
	for(int i=0;i<T;i++) b[i+1]=(t[i]=='A'?1:2);
	for(int i=1;i<=S;i++) a[i]+=a[i-1];
	for(int i=1;i<=T;i++) b[i]+=b[i-1];
	for(int i=0;i<q;i++){
		int A,B,C,D;
		cin>>A>>B>>C>>D;
		if((a[B]-a[A-1])%3==(b[D]-b[C-1])%3) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 1664
import java.util.Scanner;
class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M1 = sc.nextInt();
        int D1 = sc.nextInt();
        int M2 = sc.nextInt();
        int D2 = sc.nextInt();
        if(M1 == M2) {
        		System.out.println(0);
        } else {
        		System.out.println(1);
        }
    }
}

Measured memory_bytes: 23252
/******************************************
*    AUTHOR:         JULIAN FERRES        *
*    INSTITUITION:   FIUBA                *
******************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())

const int N = 22;
const int mod = 1e9+7;
vector<vi> can(N, vi(N,0));
int n; vi dp(1<<N,0); //girls matched

void add(ll &a, ll b){
	a+= b;
	if(a>=mod) a-= mod;
}

int main()
{
	FIN;
	cin >> n;
	forn(i,n) forn(j,n) cin >> can[i][j];
	dp[0] = 1;
	forn(mask,1<<n){
		ll i = __builtin_popcount(mask);
		forn(j, n)
		{
			if(can[i][j] && !((1<<j) & mask))
				add(dp[(1<<j)^mask],dp[mask]);
		}
	}
	

	cout << dp[(1<<n)-1] << endl;

    return 0;
}


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

void printv(vector<int> v) {
  for (int i : v)
    cout << i << " ";
  cout << endl;
}

int main() {
  int n, W;
  cin >> n >> W;
  vector<int> v(n+1);
  vector<int> w(n+1);
  rep(i, n) { cin >> v[i+1] >> w[i+1]; }
  vector<vector<int>> V(n+1, vector<int>(W+1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= W; j++) {
      if (j - w[i] >= 0) {
        V[i][j] = max(V[i-1][j],max(V[i-1][j-w[i]]+v[i], V[i][j-w[i]]+v[i]));
      } else
        V[i][j] = V[i - 1][j];
    }
  }
  cout << V[n][W] << endl;
}



Measured memory_bytes: 6860
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define all(x) x.begin(), x.end()
#define ll long long
#define INF 2e9
using namespace std;

void Main() {
    int n, h;
    cin >> n;
    int cnt = 0, tmp, max = -INF, ans;
    rep(i, 0, n) {
        int H;
        cin >> H;
        if (i == 0) {
            tmp = H;
            continue;
        }
        if (tmp >= H) {
            tmp = H;
            cnt++;
        } else {
            tmp = H;
            cnt = 0;
        }
        if (cnt > max) {
            max = cnt;
            ans = max;
        }
    }
    cout << ans << endl;
    // int H[n];
    // rep(i, 0, n) { cin >> H[i]; }
    // int max = -INF, cnt, ans;
    // rep(i, 1, n) {
    //     if (H[i - 1] >= H[i]) {
    //         cnt++;
    //     } else {
    //         cnt = 0;
    //     }
    //     if (cnt > max) {
    //         max = cnt;
    //         ans = cnt;
    //     }
    // }
    // cout << ans << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,n,m,k,l,sum=0,sum1=0,ans=0,flag=0,red,green,x,y,a,b,colr,ct=0,ct1=0,ct2=0,cnt=0;
    string s;
    char ch;
    cin>>x>>y>>red>>green>>colr;
    long long int r[red+100],g[green+100],c[colr+100];
    vector<long long int>v;
    for(i=0; i<red; i++)
    {
        cin>>r[i];
    }
    for(i=0; i<green; i++)
    {
        cin>>g[i];
    }

    sort(r,r+red);
    sort(g,g+green);
    for(i=red-1; i>=0; i--)
    {
        ct++;
        v.push_back(r[i]);
        if(ct==x)
            break;
    }
    for(i=green-1; i>=0; i--)
    {
        ct2++;
        v.push_back(g[i]);
        if(ct2==y)
            break;
    }
    for(i=0; i<colr; i++)
    {
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    for(i=v.size()-1;i>=0;i--)
    {
        cnt++;
        sum=sum+v[i];
        if(cnt==x+y)
            break;
    }

cout<<sum<<endl;
}


Measured memory_bytes: 7920
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000


int main(){
	
	int N;
	cin>>N;
	
	vector<string> V[10];
	
	V[3] = {
		".aa",
		"d..",
		"d.."
	};
	
	V[4] = {
		"aabc",
		"ccbc",
		"dfgg",
		"dfbb"
	};
	
	V[5] = {
		"aabbc",
		"c.aac",
		"cd..d",
		"gd..d",
		"gaabb"
	};
	
	V[7] = {
		"aabbc..",
		"....cab",
		"aa...ab",
		"..ggddc",
		"..a..gc",
		"..a..gd",
		"aa.bb.d"
	};
	
	if(N<=2){
		cout<<-1<<endl;
		return 0;
	}
	
	vector<string> ans(N,string(N,'.'));
	
	int k = 0;
	if(N%3==0){
		k=3;
		for(int i=0;i<N;i+=k){
			for(int y=i;y<i+k;y++){
				for(int x=i;x<i+k;x++){
					ans[y][x] = V[k][y%k][x%k];
				}
			}
		}
	}
	else{
		int X,Y,Z=-1;
		for(int i=0;i<=1000;i++){
			for(int j=0;j<=1000;j++){
				int A = i*4 + j*5;
				if(A>N)continue;
				A = N - A;
				if(A%7!=0)continue;
				X = i;
				Y = j;
				Z = A/7;
				break;
			}
			if(Z!=-1)break;
		}
		assert(X*4+Y*5+Z*7==N);
		k=4;
		for(int i=0;i<4*X;i+=k){
			for(int y=i;y<i+k;y++){
				for(int x=i;x<i+k;x++){
					ans[y][x] = V[k][y%k][x%k];
				}
			}
		}
		k=5;
		for(int i=4*X;i<4*X+5*Y;i+=k){
			for(int y=i;y<i+k;y++){
				for(int x=i;x<i+k;x++){
					ans[y][x] = V[k][(y-i)%k][(x-i)%k];
				}
			}
		}
		k=7;
		for(int i=4*X+5*Y;i<N;i+=k){
			for(int y=i;y<i+k;y++){
				for(int x=i;x<i+k;x++){
					ans[y][x] = V[k][(y-i)%k][(x-i)%k];
				}
			}
		}
	}
	
	
	
	for(int i=0;i<N;i++)cout<<ans[i]<<endl;

    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  string s;
  s = to_string(n);

  bool result = false;

  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == '7'){
      result = true;
      break;
    }
  }
  if(result){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;

}

Measured memory_bytes: 3692
from sys import stdin
for line in stdin:
    a, b = map(int, line.strip('\n').split(' '))
    if a == 0 and b == 0:
        break
    print('\n'.join(['#'*b] + ['#' + '.'*(b-2) + '#'] * (a-2) +['#'*b]), end='\n\n')


Measured memory_bytes: 5644
#include <iostream>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  int a , b, c , x;
  cin >> a >> b >> c >> x;
  int sum = 0;
  for(int A = 0;A <= a;A++){
    for(int B = 0;B <= b;B++){
      for(int C = 0;C <= c;C++){
        int X = 500*A + 100*B + 50*C;
        if(X == x)sum++;
      }
    }
  }
  cout << sum << "\n";
}



Measured memory_bytes: 256