akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

struct edge { int to,cost; };

int main() {
  ll X,Y,Z,K;cin>>X>>Y>>Z>>K;
  vector<ll> AS(X),BS(Y),CS(Z);
  // 組み合わせ
  REP(i,X) cin>>AS[i];
  REP(i,Y) cin>>BS[i];
  REP(i,Z) cin>>CS[i];

  // X*Y*ZがKと同じなら全部
  if (X*Y*Z==K) {
    vector<ll> res;
    REP(x,X)REP(y,Y)REP(z,Z) {
      res.push_back(AS[x]+BS[y]+CS[z]);
    }
    sort(ALL(res),greater<ll>());
    REP(i,K) {
      OUT(res[i]);
    }
    return 0;
  }

  // 以下はX*Y*Z>K
  sort(ALL(AS),greater<ll>());
  sort(ALL(BS),greater<ll>());
  sort(ALL(CS),greater<ll>());

  vector<ll> res;
  REP(x,X)REP(y,Y)REP(z,Z) {
    if ((x+1)*(y+1)*(z+1)>K) continue;
    res.push_back(AS[x]+BS[y]+CS[z]);
  }
  sort(ALL(res),greater<ll>());
  REP(i,K) {
    OUT(res[i]);
  }

  return 0;
}

Measured memory_bytes: 1404
typedef long long ll;

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

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

#include <set>

using namespace std;

ll mod = 1000000007;

ll solve(const vector<ll> &v){
  const int n = v.size();
  ll ret = 0;
  REP(i,n-1){
    const ll d = v[i + 1] - v[i];
    ret += (d * (i + 1)) % mod * (n - (i + 1)) % mod;
    ret %= mod;
  }
  return ret;
}

int main(){
  const int n = getInt();
  const int m = getInt();
  vector<ll> xs(n);
  vector<ll> ys(m);
  REP(i,n) xs[i] = getInt();
  REP(i,m) ys[i] = getInt();

  printf("%lld\n", solve(xs) * solve(ys) % mod);
  return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<int,pii>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell         998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)


int solve( ){

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


return 0;

}

int main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);

 /*   #ifndef ONLINE_JUDGE
    freopen("test.in", "r" , stdin);
    freopen("test.out", "w", stdout);
    #endif
  */
  clock_t time_req;

    // Without using pow function
    time_req = clock();


//cin>>t;
   while(t--)
     {solve();
     }

         time_req = clock() - time_req;
   // cout << "Processor time taken in pow function: "
    //    << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
ans = [0] * (n + 1)
for x in range(1, int(math.sqrt(n))):
    for y in range(1, int(math.sqrt(n))):
        for z in range(1, int(math.sqrt(n))):
            a = x * x + y * y + z * z + x * y + y * z + z * x
            if n >= a >= 1:
                ans[a] += 1
print(*ans[1:],sep="\n")

Measured memory_bytes: 9252
module WeightedDirectedGraph
  (Weight : sig
    type t
    val inf : t
    val zero : t
    val neg_inf : t
    val ( + ) : t -> t -> t
    val compare : t -> t -> int
  end) :
sig
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  val bellman_ford :
    (* 頂点数n *)
    int ->
    (* 辺のリスト
       頂点は0からn-1までの整数でなくてはならない *)
    (int * int * Weight.t) church_list ->
    (* 始点 *)
    int ->
    (* 頂点を受け取り，そこまでの距離を返す関数
       頂点に到達するパスが無ければinfを返し，
       そこに到達するまでに負閉路があればneg_infを返す *)
    (int -> Weight.t)
end =
struct
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  let bellman_ford n es s =
    (* 距離を覚えるやつ *)
    let d = Array.make n Weight.inf in
    (* 経路に負閉路が含まれる頂点を覚えるやつ *)
    let neg = Array.make n false in
    d.(s) <- Weight.zero;
    let es = es.fold (fun (u, v, c) es ->
      let open Weight in
      (* c は u から v への辺の重さ *)
      (* d.(u) + c < d.(v) *)
      (if 0 < compare d.(v) (d.(u) + c) then d.(v) <- d.(u) + c);
      (u, v, c) :: es) [] in
    for i = 2 to n - 1 do
      List.iter (fun (u, v, c) ->
        let open Weight in
        (* c は u から v への辺の重さ *)
        (* d.(u) + c < d.(v) *)
        if 0 < compare d.(v) (d.(u) + c) then
          d.(v) <- d.(u) + c) es
    done;
    (* 手動ループアンローリング *)
    for i = n to 2 * n do
      List.iter (fun (u, v, c) ->
        let open Weight in
        if 0 < compare d.(v) (d.(u) + c) then begin
          d.(v) <- d.(u) + c;
          (* n 回目以降に変更が起こった場合，v までの経路に負閉路が含まれている *)
          neg.(v) <- true
        end) es
    done;
    fun v -> if neg.(v) then Weight.neg_inf else d.(v)
end

module G = WeightedDirectedGraph (struct
  type t = int
  let inf = -123456789012345678
  let zero = 0
  let neg_inf = 123456789012345678
  let ( + ) = ( + )
  let compare x y = compare y x
end)

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let abcs = Array.init m @@ fun _ -> Scanf.scanf "%d %d %d\n" @@ fun a b c -> a - 1, b - 1, c in
  let d = G.bellman_ford n { G.fold = fun f -> Array.fold_right f abcs } 0 (n - 1) in
  if 123456789012345678 <= d
  then print_endline "inf"
  else Printf.printf "%d\n" d


Measured memory_bytes: 3584
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
int main() {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << min(a,b)+min(c,d);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
 
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    
    String originalMsg = sc.next();
    String missingMsg = "";
    for (int i = 0; i < originalMsg.length(); i++) {
      missingMsg = missingMsg + "x";
    }
    
    System.out.println(missingMsg);
    
  }
  
}

Measured memory_bytes: 38656
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

template <typename T>
T mypow(T a, T b)
{
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

vector<ll> fact(200010, 1), inv(200010, 1);

ll comb(int n, int r)
{
    if (r < 0 || n < r)
        return 0;
    ll ret = fact[n] * inv[r] % MOD;
    ret = ret * inv[n - r] % MOD;
    return ret;
}

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

    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    for (int i = 2; i <= 200000; i++)
    {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = mypow(fact[i], (ll)MOD - 2);
    }
    ll ainv = a * mypow(a + b, MOD - 2) % MOD, binv = b * mypow(a + b, MOD - 2) % MOD;
    ll ret = 0;
    for (ll i = n; i < 2 * n; i++)
    {
        ll c = comb(i - 1, n - 1);
        ll sum = mypow(ainv, n) * mypow(binv, i - n) % MOD + mypow(ainv, i - n) * mypow(binv, n) % MOD;
        sum %= MOD;
        ret = (ret + (i * c % MOD) * sum % MOD) % MOD;
    }
    // cout << ret << endl;
    ret = ret * (a + b + c) % MOD;
    ret = ret * mypow(a + b, MOD - 2) % MOD;
    cout << ret << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

#define ll long long

int main(){
    int N;
    cin >> N;
    cout << (double)(N/2+N%2)/N << endl;
    return 0;
}


Measured memory_bytes: 256
//c.c C-To Infinity
#include<stdio.h>

int main(void){
    char buf[101];
    long long k;
    scanf("%s",buf);
    scanf("%lld",&k);
    int i=0;
    while(1){
        if(buf[i]!='1'){
            printf("%c\n",buf[i]);
            return 0;
        }else{
            if((i+1)==k){
                printf("1\n");
                return 0;
            }
        }
        i++;
    }    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K;
  cin >> K;
  vector<long long> q;
  if(K < 10){
    cout << K << endl;
    return 0;
  }else{
    for(int i=1; i<10; i++){
      q.push_back(i);
    }
    int cnt = 9;
    int k = 1;
    while(1){
      long long center =  q[k-1];
      k++;
      for(int i=-1; i<=1; i++){
        int j = center % 10 + i;
        //center = 654だったら、3, 4, 5
        if (j >= 0 && j <= 9){
          q.push_back(j + center*10);
          cnt++;
          if (cnt == K){
            cout << q[cnt-1] << endl;
            return 0;
          }
        }
      }
    }


  }
}


Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
  ll n,k,t;
  cin >> n >> k;
  t= k;
  set<ll> s;
  vector<ll> arr(n);
  for(ll i=0;i<n;i++){
    cin >> arr[i];
  }

  ll g=LLONG_MAX;
  ll a = arr[0];
  s.insert(a);
  vector<ll> path;
  path.push_back(a);

  while(g--){
    a = arr[a-1];
    if(s.find(a)!=s.end()){
      path.push_back(a);
      break;
    }
    path.push_back(a);
    s.insert(a);
  }
  for(ll i=0;i<path.size();i++){
    if(path[i]==a){
      vector<ll> rep;
      for(ll z=i+1;z<path.size();z++){
        rep.push_back(path[z]);
      }
      if(k<=(i+1)){
        cout << path[k-1];
      }
      else{
        ll temp=((k-i-1)%rep.size());
        if(temp==0){
          cout << rep[rep.size()-1];
        }
        else{
          cout << rep[temp-1];
        }
      }
      
      break;
    }
  }
  
  

  

}

Measured memory_bytes: 17296
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
char gri[100][100];
    
    rep(i,100)
        {rep(j,100){
            if(i<50){gri[i][j]='#';}
            else {gri[i][j]='.';}
        }
        }
    int flag=0;
    rep(i,48){
        rep(j,100){
            if(a==0){
                flag=1;
                break;
            }
            
            if((gri[i+1][j]=='#'&&i+1<50)&&(gri[i-1][j]=='#'&&i-1>0)&&(gri[i][j-1]=='#'&&j-1>0)&&(gri[i][j+1]=='#'&&j+1<100)){
                if((gri[i+1][j+1]=='#'&&(i+1<50)&&(j+1<100))&&(gri[i+1][j-1]=='#'&&(i+1<50)&&(j-1>0))&&(gri[i-1][j+1]=='#'&&(i-1>0)&&(j+1<100))&&(gri[i-1][j-1]=='#'&&(i-1>0)&&(j-1>0))){
                gri[i][j]='.';
                a--;
                }
            }
        }
               if(flag==1){
                   break;
               }
    }
        flag=0;
               for(int i=50;i<100;i++){
                   rep(j,100){
                       if(b==0){
                           flag=1;
                           break;
                       }
                       
                       if((gri[i+1][j]=='.'&&i+1<100)&&(gri[i-1][j]=='.'&&i-1>51)&&(gri[i][j-1]=='.'&&j-1>0)&&(gri[i][j+1]=='.'&&j+1<100)){
                           if((gri[i+1][j+1]=='.'&&(i+1<100)&&(j+1<100))&&(gri[i+1][j-1]=='.'&&(i+1<100)&&(j-1>0))&&(gri[i-1][j+1]=='.'&&(i-1>51)&&(j+1<100))&&(gri[i-1][j-1]=='.'&&(i-1>51)&&(j-1>0))){
                               gri[i][j]='#';
                           b--;
                           }
                       }
                          }
                          if(flag==1){
                              break;
                          }
                          }
    cout<<100<<" "<<100<<endl;
    rep(i,100)
    {rep(j,100){
        cout<<gri[i][j];
    }
        cout<<endl;
    }
return 0;
}


Measured memory_bytes: 256
while(True):
    n,m,t,p=map(int,input().split())
    if (n,m,t,p)==(0,0,0,0):
        break
    d=[0 for  i in range(t)]
    c=[0 for  i in range(t)]
    x=[0 for  i in range(p)]
    y=[0 for  i in range(p)]
    nnow,mnow=n,m
    for i in range(t):
        d[i],c[i]=map(int,input().split())
    for i in range(p):
        x[i],y[i]=map(int,input().split())
    paper=[[1 for j in range(n)] for i in range(m)]
    for k in range(t):
        if d[k]==1:
            nnext=max(c[k],nnow-c[k])
            nextpaper=[[0 for j in range(nnext)] for i in range(mnow)]
            if c[k]<=nnow-c[k]:
                for i in range(mnow):
                    for j in range(nnow-c[k]):
                        nextpaper[i][j]+=paper[i][j+c[k]]
                    for j in range(c[k]):
                        nextpaper[i][j]+=paper[i][c[k]-j-1]
            else:
                for i in range(mnow):
                    for j in range(c[k]):
                        nextpaper[i][-j-1]+=paper[i][j]
                    for j in range(nnow-c[k]):
                        nextpaper[i][j]+=paper[i][j+c[k]]
            nnow=nnext        
        else:
            mnext=max(c[k],mnow-c[k])
            nextpaper=[[0 for j in range(nnow)] for i in range(mnext)]
            if c[k]<=mnow-c[k]:
                for j in range(nnow):
                    for i in range(mnow-c[k]):
                        nextpaper[i][j]+=paper[i][j]
                    for i in range(c[k]):
                        nextpaper[-i-1][j]+=paper[i+mnow-c[k]][j]
            else:
                for j in range(nnow):
                    for i in range(mnow-c[k]):
                        nextpaper[-i-1][j]+=paper[mnow-c[k]-1-i][j]
                    for i in range(c[k]):
                        nextpaper[i][j]+=paper[-i-1][j]
            mnow=mnext
        paper=[[nextpaper[i][j] for j in range(nnow)] for i in range(mnow)]
    ans=0
    for i in range(p):
        print(paper[-y[i]-1][x[i]])



Measured memory_bytes: 5648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>

using namespace std;

unsigned long long int GCD(unsigned long long int a, unsigned long long int b)
{
	if (b == 0)
	{
		return(a);
	}
	if (a < b)
	{
		return(GCD(b, a));
	}
	return(GCD(b, a % b));
}

unsigned long long int LCM(unsigned long long int a, unsigned long long int b)
{
	unsigned long long int gcd = GCD(a, b);
	return(a * b / gcd);
}

void solve()
{
	int n;
	while (cin >> n, n)
	{
		vector<unsigned long long int> d(n);
		vector<unsigned long long int> v(n);
		for (int i = 0; i < n; ++i)
		{
			cin >> d[i] >> v[i];
			unsigned long long int t = GCD(d[i], v[i]);
			d[i] /= t;
			v[i] /= t;
		}
		unsigned long long int dk = d[0];
		unsigned long long int vk = v[0];
		for (int i = 1; i < n; ++i)
		{
			dk = dk * d[i] / GCD(d[i], dk);
			vk = GCD(vk, v[i]);
		}
		for (int i = 0; i < n; ++i)
		{
			cout << (v[i] / vk) * (dk / d[i]) << endl;
		}
	}
}

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

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

int N, K;
char D[10];

bool check(char c){
    for(int i=0;i<K;i++){
        if(c == D[i])
            return false;
    }
    return true;
}

int main(){
    cin >> N >> K;
    for(int i=0;i<K;i++)
        cin >> D[i];

    for(int i=N;;i++){
        bool flag = true;
        // 整数→文字列
        string S;
        S = to_string(i);
        //cout << S << endl;
        // 嫌いな数字が含まれているか
        for(int j=0;j<S.size();j++){
            if( !check(S[j]) ){
                flag = false;
                break;
            }
        }
        if( flag ){
            cout << i << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int dt,hoge,n;
	cin>>n;
	rep(p,n){
		cin>>dt;
		cout<<"Case "<<p+1<<":"<<endl;
		rep(q,10){
			hoge=dt*dt;
			hoge-=(int)(hoge/1e6)*1e6;
			hoge/=100;
			cout<<hoge<<endl;
			dt=hoge;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

typedef struct _line{
  int from;
  int to;
}line;

line yoko[30];
int main(){
  int w, n, i, j, a, b;
  int state;
  int result[30] = {0};
  scanf("%d", &w);
  scanf("%d", &n);
  for(i = 0; i < n;i++){
    scanf("%d,%d", &a, &b);
    yoko[i].from = a-1;
    yoko[i].to = b-1;
  }
  for(i = 0;i < w; i++){
    state = i;
    for(j = 0; j < n;j++){
      if(yoko[j].from == state){
	state = yoko[j].to;
      }else if(yoko[j].to == state){
	state = yoko[j].from;
      }
    }
    result[state] = i;
  }
  for(i = 0; i < w; i++){
    printf("%d\n", result[i]+1);
  }
  return 0;
}

	

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int n,mod=1000000007;
    scanf("%d",&n);
    ll a[n];
    for (int i=0;i<n;i++)
    scanf("%lld",&a[i]);
    ll b[n];
    b[n-1]=a[n-1];
    for (int i=n-2;i>=0;i--)
    b[i]=((a[i]%mod)+(b[i+1]%mod))%mod;
    ll sum1=0LL;
    for (int i=0;i<n-1;i++)
    {
        ll val1=((a[i]%mod)*(b[i+1]%mod))%mod;
        sum1=((sum1%mod)+(val1)%mod)%mod;
    }
    printf("%lld\n",sum1);
    return 0;
}

Measured memory_bytes: 6880
def main():
    """
    1 <= N, K <= 2 * 10^5

    a,b,c (ok: a=b=c)

    """
    N, K = map(int, input().split())
    ans = f(N, K)
    assert ans == loop(N, K)
    # ans = TLE(N, K)
    print(ans)


def f(N, K):
    """
    1: a + b = l * K
    2: b + c = n * K
    3: c + a = m * K

    1 + 2 = c + a + 2b = (l + n) * K, 2b = (l + n - m) * K
    2 + 3 = a + b + 2c = (n + m) * K, 2c = (n + m - l) * K
    3 + 1 = b + c + 2a = (m + l) * K, 2a = (m + l - n) * K

    K % 2 == 0
        b = (l + n - m) * K / 2 = 整数
        Kの倍数 or K / 2 の倍数
    K % 2 == 1
        b = (l + n - m) * K / 2 = not 整数
        Kの倍数
    """
    if K % 2 == 1:
        # K の倍数の個数(N>=1より)
        x = N // K
        ans = x ** 3
    else:
        x1 = N // K
        x2 = (N + K // 2) // K
        ans = x1 ** 3 + x2 ** 3

    return ans


def loop(N, K):
    x = [0] * K
    for i in range(1, N+1):
        # K で割ったあまりがある値になる1-Nまでの個数
        x[i % K] += 1

    res = 0
    for a in range(K):
        # a余る数, K-a余る数(a=0 のときb=c=Kなので余りにする)
        b = (K - a) % K
        c = (K - a) % K

        if (b + c) % K == 0:
            res += x[a] * x[b] * x[c]

    return res


def TLE(N, K):
    ans = 0
    for a in range(1, N+1):
        for b in range(1, N+1):
            for c in range(1, N+1):
                if (a + b) % K == 0 and \
                    (b + c) % K == 0 and \
                        (c + a) % K == 0:
                    ans += 1
    return ans


if __name__ == '__main__':
    main()


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

int even(vector<int>& array, int);
void division(vector<int>& array, int);
int main() {
	vector<int> array;
	int i, N, tmp, count = 0;
	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> tmp;
		array.push_back(tmp);
	}
	while (even(array, N) == 1) {
		count++;
		division(array, N);
	}
	cout << count << endl;
	return 0;
}

int even(vector<int>& array, int N) {
	int i;
	for (i = 0; i < N; i++) {
		if (array[i] % 2 != 0) {
			return -1;
		}
	}
	return 1;
}

void division(vector<int>& array, int N) {
	int i;
	for (i = 0; i < N; i++) {
		array[i] = array[i] / 2;
	}
}

Measured memory_bytes: 256
from math import  gcd

k = int(input())
out = 0

# 3つとも同じ数字のとき
out = out + (1 + k) * k / 2

#2つが同じ数字の時
for i in range(k):
    a = i + 1
    b = i + 1
    for j in range(a - 1):
        c = j + 1
        out = out + gcd(a, c) * 6

#3つとも違うとき
for m in range(k):
    a = m + 1
    for n in range(a - 1):
        b = n + 1
        gcd2 = gcd(a, b)
        for o in range(b - 1):
            c = o + 1
            out = out + gcd(gcd2, c) * 6


print(int(out))


Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<pair<pair<string, int>, int>> vp;
	for (int i = 0; i < n; i++) {
		pair <pair<string, int>, int> p;
		cin >> p.first.first >> p.first.second;
		p.first.second = -p.first.second;
		p.second = i + 1;
		vp.push_back(p);
	}

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



Measured memory_bytes: 256
/*
 * @Author: Kaizyn
 * @Date: 2020-03-28 21:12:21
 * @LastEditTime: 2020-03-28 21:16:53
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 2e5+7;
const int MOD = 998244353;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> pii;

int n, k;
int a[N];

inline void solve()
{
    cin >> k >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int res = a[1]-a[n]+k;
    for (int i = 1; i < n; ++i) res = max(res, a[i+1]-a[i]);
    cout << k-res << endl;
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcase = 1;
    // cin >> testcase;
    for (int i = 1; i <= testcase; ++i) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
int N,M;
vector<int>G[1<<17];
int c[1<<17];
pair<int,int>check[1<<17];
int d[1<<17];
pair<int,int>parent[1<<17];
main()
{
	cin>>N;
	vector<pair<int,int> >ids(N);
	for(int i=0;i<N;i++)
	{
		cin>>c[i];
		ids[i]=make_pair(c[i],i);
		d[i]=-1;
	}
	cin>>M;
	for(int i=0;i<M;i++)
	{
		int u,v;cin>>u>>v;u--,v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	sort(ids.begin(),ids.end());
	long ans=0;
	UF uf(N);
	for(int i=0;i<N;)
	{
		int j=i;
		while(i<N&&ids[i].first==ids[j].first)i++;
		for(int k=j;k<i;k++)
		{
			int id=ids[k].second;
			if(d[id]>=j)
			{
				uf.unite(id,ids[d[id]].second);
			}
			d[id]=k;
			for(int v:G[id])
			{
				if(d[v]>=j)
				{
					uf.unite(id,ids[d[v]].second);
				}
				d[v]=k;
			}
		}
		for(int k=j;k<i;k++)
		{
			int id=ids[k].second;
			pair<int,int>pmin=check[id];
			for(int v:G[id])pmin=max(pmin,check[v]);
			int now=pmin.first+1;
			pair<int,int>dis=make_pair(now,c[id]);
			parent[uf.find(id)]=max(parent[uf.find(id)],dis);
		}
		for(int k=j;k<i;k++)
		{
			int id=ids[k].second;
			pair<int,int>dis=parent[uf.find(id)];
			int now=dis.first;
			ans+=now;
			check[id]=max(check[id],dis);
			for(int v:G[id])check[v]=max(check[v],dis);
		}
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 13932
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
int nxt[2<<17][26],nownxt[26];
inline void solve(void){
  string s,t;
  in(s,t);
  int n=s.size(),m=t.size();
  s+=s;
  rep(i,26)nownxt[i]=-1;
  dw(i,n+n,0){
    rep(j,26)nxt[i][j]=nownxt[j];
    nownxt[s[i]-'a']=i;
  }
  int p=-1;
  long ans=0;
  rep(i,m){
    int q=(p<0?nownxt:nxt[p])[t[i]-'a'];
    if(q<0){
      out(-1);
      return;
    }
    ans+=q-p;
    p=q%n;
  }
  out(ans);
}
int main(void){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 21100
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)

#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;
vi a;

int main()
{
    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];
    int mx = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            mx = max(mx, a[i] - a[j]);
            mx = max(mx, a[j] - a[i]);
        }
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
#include <atcoder/modint>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()




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

	int n, q;
	cin >> n >> q;

	vector<atcoder::modint998244353> sumpow(n + 1);
	atcoder::modint998244353 p = atcoder::modint998244353::raw(1);

	for (int i = n; i >= 1; i--) {
		sumpow[i] = p;
		p *= atcoder::modint998244353::raw(10);
	}
	for (int i = 1; i <= n; i++) {
		sumpow[i] += sumpow[i - 1];
	}


	atcoder::modint998244353 ans = sumpow[n];
	map<int, pair<int, int>> seg;
	seg.emplace(0, make_pair(n, 1));

	rep(_, q) {
		int L, R, d;
		cin >> L >> R >> d;
		L--;


		auto it = seg.upper_bound(L);
		if (it != seg.begin()) --it;

		vector<pair<int, pair<int, int>>> v;

		for (; it != seg.end(); ) {
			if (R <= it->first)break;
			ans -= (sumpow[it->second.first] - sumpow[it->first]) * atcoder::modint998244353::raw(it->second.second);

			if (it->first < L) {
				v.emplace_back(it->first, make_pair(L, it->second.second));
			}
			if (R < it->second.first) {
				v.emplace_back(R, make_pair(it->second.first, it->second.second));
			}

			it = seg.erase(it);
		}
		for (auto p : v) {
			ans += (sumpow[p.second.first] - sumpow[p.first]) * atcoder::modint998244353::raw(p.second.second);
			seg.insert(p);
		}

		ans += (sumpow[R] - sumpow[L]) * atcoder::modint998244353::raw(d);
		seg.emplace(L, make_pair(R, d));
		cout << ans.val() << endl;
	}




	return 0;
}


Measured memory_bytes: 16456
using System;
using System.Text;
using System.Collections.Generic;

namespace AOJ2
{
    class Program
    {
        class Point
        {
            public double x;
            public double y;

            public Point(double X, double Y)
            {
                this.x = X;
                this.y = Y;
            }

        }


        static void Main(string[] args)
        {
            List<string> resultList = new List<string>();

            string input;
            while ((input = Console.ReadLine()) != null)
            {
                string[] inputArray = input.Split(' ');
                Point A1 = new Point(double.Parse(inputArray[0]), double.Parse(inputArray[1]));
                Point A2 = new Point(double.Parse(inputArray[2]), double.Parse(inputArray[3]));
                Point B1 = new Point(double.Parse(inputArray[4]), double.Parse(inputArray[5]));
                Point B2 = new Point(double.Parse(inputArray[6]), double.Parse(inputArray[7]));

                if (A1.x >= B1.x && A1.y <= B1.y)
                {
                    if (B2.x >= A1.x && B1.y <= A2.y)
                    {
                        resultList.Add("YES");
                    }
                    else
                    {
                        resultList.Add("NO");
                    }
                }
                else if (A1.x <= B1.x && A1.y <= B1.y)
                {
                    if (B1.x <= A2.x && B1.y <= A2.y)
                    {
                        resultList.Add("YES");
                    }
                    else
                    {
                        resultList.Add("NO");
                    }
                }
                else if (A1.x >= B1.x && A1.y >= B1.y)
                {
                    if (B2.x >= A1.x && B2.y >= A1.y)
                    {
                        resultList.Add("YES");
                    }
                    else
                    {
                        resultList.Add("NO");
                    }
                }
                else
                {
                    if (B1.x <= A2.x && B2.y >= A1.y)
                    {
                        resultList.Add("YES");
                    }
                    else
                    {
                        resultList.Add("NO");
                    }
                }

            }

            foreach (string s in resultList)
            {
                Console.WriteLine(s);
            }


        }


        
    }
}

Measured memory_bytes: 5768
#include<bits/stdc++.h>
using namespace std;
int main() {
	int an,legs;
	int x,n;
	set<int> s;
	
	scanf("%d %d",&x,&n);
	int a[n+1];
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		s.insert(a[i]);
		
	}
	int ans,mini = INT_MAX;
	for(int i=-300;i<=200;i++) {
		if(s.find(i) == s.end()) {
			if(abs(i-x) < mini) {
				mini = abs(i-x);
				ans = i;
			}
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 3792
#include<stdio.h>
 
#define N 200000
 
 
int main(){
 
  int n,i,max,min;
  int kawase[N];
 
  scanf("%d",&n);
 
  for(i = 0;i < n;i++)
    scanf("%d",&kawase[i]);
   
  max = -999999999;
  min = kawase[0];
  for(i = 1;i < n;i++){
     
    if(max <  kawase[i]-min)
      max = kawase[i]-min;
 
    if(min > kawase[i])
      min = kawase[i];
 
  }
       
     
  printf("%d\n",max);
 
  return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

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

const int MAXN = 3500;
const ll INF = 1e13;
const int MOD = 1e9 + 7;
const int LOG = 18;
const double EPS = 1e-9;
const double PI = 3.1415926535;

ll dp[MAXN][MAXN];
ll a[MAXN];

int main() {
    int N;

    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> a[i];

    for(int i = 0; i < N; i++)
        dp[i][i] = a[i];

    for(int len = 2; len <= N; len ++) {
        for(int l = 0; l <= N - len; l++) {
            int r = l + len - 1;
            dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
        }
    }

    cout << dp[0][N - 1] << endl;

    return 0;
}


Measured memory_bytes: 84224
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 100000000000;
#define pp pair<ll, pair<ll, ll>> 
// #define fi first
// #define se second
 
/*--------------------------------------------------------------------------------

--------------------------------------------------------------------------------*/


int main(){
    double n, m, d; cin >> n >> m >> d;
    double ans = 0.;
    if(d == 0.){
        ans = (m-1.)/n;
    }else{
        ans = 2.*(n-d)/(n*n)*(m-1);
    }
    cout << fixed << setprecision(15) << ans << endl;

    return 0;
}


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

#define all(v)   v.begin(), v.end()
#define endl "\n";
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE fast()
#define to_str to_string
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMIN INT_MIN
#define IMAX INT_MAX
#define pow POW
#define INF 1e9

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;
typedef string str;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef pair<int, int> pii;

void fast() {
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
}

bool compare(pii &a, pii &b) {
	return a.F > b.F;
}

ll numOfDigits(ll n) {
	if (!n) return 1;
	return (ll) (log10(n)) + 1;
}

ll POW(ll a, ll b);

/*

*/

ll BN();

int main()
{
    THINK_TWICE_CODE_ONCE;
    //freopen("test cases\\.txt", "r", stdin) ;
    str s; cin>>s;
    str rev =s; reverse(all(rev));
    if(s!=rev) return cout<<"No", 0;
    int n = s.size();
    str s1 = s.substr(0, (n-1)/2), rev1 = s1; reverse(all(rev1));
    if(s1!=rev1) return cout<<"No", 0;
    str s2 = s.substr((n+3)/2-1), rev2 = s2; reverse(all(rev2));
    if(s2==rev2) cout<<"Yes";
    else cout<<"No";
    return 0;
}

ll BN() {
	int low = 1, up = 0;
	int ans = -1;
	while (low <= up) {
		ll mid = (((ll)low + up) / 2);
		if (mid){
			ans = mid;
			low = mid + 1;
		} else
			up = mid - 1;
	}
	return ans;
}

ll POW(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}


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

int main() {
  long long N,K;
  cin >> N >> K;
  long long a=0;
  for(long long i=K; i<=N+1; i++){
    a+=(((2*N-i+1)*i)/2)-((i*(i-1))/2)+1;
  }
 long long b = a%(1000000007);
  cout << b << endl;
}

Measured memory_bytes: 3548
/** author: __nishad__ **/
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"


char a[50][50], b[2500];
int n, m;


int solve(int i, int j)
{
    int count = 0, x=0;
    loop(o, i, i+m){
        loop(p, j, j+m){
            if(b[x] == a[o][p]){
                count++;
                x++;
            }

        }
    }
    return count;

}

int main()
{
    IOS;
    int count, x;

    cin>>n>>m;
    char s;

    loop(i, 0, n){
        loop(j, 0, n){
            cin>>a[i][j];
        }
    }

    loop(i, 0, m*m){
        cin>>b[i];
    }


    loop(i, 0, n){
        loop(j, 0, n){
            int res = 0;
            if(b[0] == a[i][j]){
                count = 0, x=0;
                loop(o, i, i+m){
                    loop(p, j, j+m){
                        if(b[x] == a[o][p]){
                            count++;
                            x++;
                        }

                    }
                }
            }
            if(count == m*m){
                cout<<"Yes";
                return 0;
            }
        }
    }

    cout<<"No";


}






























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

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i=0; i<n; i++)
        cin >> arr[i];

    int costs[n+1];
    costs[0]=0;
    costs[1]=0;

    for(int i=2; i<=n; i++){
        int option=INT_MAX;
        for(int j=1; j<=k; j++){
            if(j>=i){
                continue;
            }
            option = min(option, costs[i-j] + abs(arr[i-1] - arr[i-j-1]));
        }
        costs[i] = option;
    }

    cout << costs[n] << endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS

//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target_ans("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb emplace_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

#define int long long
//#define int unsigned int
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

vi xx = { 1, 0, -1, 0 };
vi yy = { 0, 1, 0, -1 };
string dir = "LRUD";

const int N = 3e5 + 50, oo = 2e18 + 500;
const int mod = 998244353;
//const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const double eps = 1e-9, PI = 2 * acos(0.0);
int n, m, k;
long long cnt = 0;
int lg = 18;
vvi g;
//vi rg[N];
vi visit(N, 0);

vi t;
void add(int ind, int v)
{
	ind++;
	for (int i = ind; i < SZ(t); i += i&-i)
	{
		t[i] += v;
	}
}

int get(int ind)
{
	ind++;
	int res = 0;
	for (int i = ind; i; i -= i&-i)
	{
		res += t[i];
	}
	return res;
}

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("rblock.in", "r", stdin);
	//freopen("rblock.out", "w", stdout);

	cin >> m >> n;

	vpii seg;
	for (int i = 0; i < m; i++)
	{
		int l, r;
		cin >> l >> r;
		seg.pb(r - l + 1, l);
	}

	sort(all(seg));
	vi ans(n);

	int j = 0;
	t.assign(n + 10, 0);
	for (int i = 1; i <= n; i++)
	{
		while (j < m && seg[j].first < i)
		{
			int l = seg[j].second;
			int r = seg[j].first + l - 1;
			add(l, 1);
			add(r + 1, -1);
			j++;
		}

		ans[i - 1] = m - j;
		for (int z = i; z <= n; z += i)
		{
			ans[i - 1] += get(z);
		}
	}

	for (auto x : ans)
	{
		cout << x << endl;
	}
}

Measured memory_bytes: 13588
require 'matrix'
n = gets.to_i
str = gets.chomp

w = Array.new(n, 0)
e = Array.new(n, 0)

acc_w = 0
acc_e = 0

1.upto(n - 1) do |i|
  acc_w += 1 if str[i - 1] == "W"
  w[i] = acc_w
  acc_e += 1 if str[n - i] == "E"
  e[n - i - 1] = acc_e
end

puts (Vector.elements(w) + Vector.elements(e)).min

Measured memory_bytes: 12292
#include  <string>
#include<iostream>
#include<queue>
#include <math.h>
using namespace std;

typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll k, ans=0;
    cin >> k;
    int n=s.length();

    if(s == string(n, s[0])){
        cout << (n*k)/2 << "\n";
        return 0;
    }
    
    ll cnt1=0, cnt2=0;
    string s2 = s+s;
    FOR(i, 1, n){
        if(s[i]==s[i-1]){
            s[i] = '#';
            cnt1 ++;
        }
    }
    // if(s2[0]==s[n-1]){
    //     s2[0] = '#';
    //     cnt2 ++;
    // }
    FOR(i, 1, n*2){
        if(s2[i]==s2[i-1]){
            s2[i] = '#';
            cnt2 ++;
        }
    }
    cnt2 = cnt2-cnt1;
    cout << cnt2*(k-1) + cnt1 << "\n";
    return 0;
}

Measured memory_bytes: 256
import collections


n, m, x = map(int, input().split())
c = collections.defaultdict(int)
for key in map(int, input().split()):
    key = int(key)
    c[key] += 1

forward = 0
backword = 0
touch_x = False

for i in range(n):
    if i == x:
        touch_x = True

    if not touch_x and c[i]:
        forward += 1

    else:
        if c[i]:
            backword += 1


print(min(forward, backword))


Measured memory_bytes: 3316
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if lc != 0
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end

nn = inputs[0][0]
str = inputs[1][0]

if nn % 2 != 0
  puts "No"
  exit
end

ll = nn/2
for i in 0..ll-1
  pd str[i]
  pd str[ll+i]
  if str[i] != str[ll+i]
    puts "No"
    exit
  end
end

puts "Yes"



Measured memory_bytes: 1916
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

istream& operator>> (istream& a, pii& b) {
    cin >> b.first >> b.second;
    return a;
}

ostream& operator<< (ostream& a, const pii& b) {
    cout << "{" << b.first << ", " << b.second << "}";
    return a;
}

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 100;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e15;
    // const int mod = 2600000069; 
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int MAXN = 1e7 + 10;

int r[MAXN];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for (int i = 1; i < MAXN; i++) {
        for (int j = i; j < MAXN; j += i) {
            r[j]++;
        }
    }
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += i * r[i];
    }
    cout << ans;
}
/*

*/


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

int main(){
    string s; cin >> s;
    
    if(s.size()==2) cout << s << endl;
    else{
        for(int i=2;0<=i;i--) cout << s[i];
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;

void solve()
{
    int x;
    cin >> x;
    cout << (1^x) << '\n';
}

int main()
{
    fastIO;
    int t=1;
    // cin >> t;
    while (t--) {
        solve();
    }   
}

Measured memory_bytes: 3608