akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
static class Program{
	const int mod=1000000007;
	const long o=1;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		int[] a=sc.Ia;
		long ans=Gcd(a[0],a[1]);
		for(int i=2;i<n;i++){ans=Gcd(ans,a[i]);}
		Console.WriteLine(ans);
	}
	static long Gcd(long a,long b){
		long c=Math.Max(a,b)%Math.Min(a,b);
		b=Math.Min(a,b);
		while(c!=0){
			a=b%c;
			b=c;
			c=a;
		}
		return b;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 20576
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n; cin >> n;
  vector<int> a(n);
  int cnt_minus = 0;
  ll sum = 0;

  REP(i,n) {
    cin >> a[i];
    if (a[i] < 0) cnt_minus++;
    a[i] = abs(a[i]);
    sum+=a[i];
  }

  sort(ALL(a));
  if (cnt_minus%2) {
    sum -= a[0]*2;
  }
  COUT(sum);

  return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>


int S[12][1002];
int main(){
  int H, W, K;
  scanf("%d", &H);
  scanf("%d", &W);
  scanf("%d", &K);
  int ans = 100000000;
  for (int i=0; i<H; i++){
    std ::string s;
    std::cin >> s;
    for (int j=0; j<W; j++){
      S[i][j]=int(s[j])-int('0');
    }
  }
  for (int i=0; i<(1<<(H-1)); i++){
    //printf("----- i=%d ----\n", i);
    std::vector<int > cut;
    for (int j=0; j<H-1; j++){
      if ((i & (1<<j)) != 0){
	cut.push_back(j);
      }
    }
    std::vector<int > sum(cut.size()+1, 0);
    int j=0;
    bool ok = true;
    int verticalcut = 0;
    while (j<W){
      //printf("j=%d\n", j);
      int counter=0;
      std::vector<int > next(cut.size()+1, 0);
      //      printf("step0\n");
      for (int k=0; k<H; k++){
	//printf("S[%d][%d]=%d\n", k, j, S[k][j]);
	next[counter] += S[k][j];
	//printf("next[%d]=%d\n", counter, next[counter]);
	if (counter<cut.size() && k==cut[counter]) counter++;
      }
      //printf("next[0]=%d\n", next[0]);
      //printf("step1\n");
      for (int k=0; k<cut.size()+1; k++){
	if (next[k]>K){
	  ok=false;
	  //printf("next[%d]=%d>K\n", k, next[k]);
	  break;
	}
      }
      if (!ok) break;
      //printf("step2\n");
      bool check = false;
      for (int k=0; k<cut.size()+1; k++){
	//printf("next[%d]+sum[%d]=%d+%d\n", k,k,next[k], sum[k]);
	if (next[k]+sum[k]>K){
	  //printf("out vertical cut at k=%d\n", k);
	  std::copy(next.begin(), next.end(), sum.begin());
	  verticalcut++;
	  check=true;
	  break;
	}
      }
      if (!check){
	for (int k=0; k<cut.size()+1; k++){
	  sum[k]+=next[k];
	}
      }
      j++;
    }
    if (ok){
      //printf("OK i=%d, ans =%d\n", i, cut.size()+verticalcut);
      ans = std::min(ans,(int)cut.size()+verticalcut);
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
// 木の直径
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

#define MAX 100000
#define INFTY ( 1 << 30 )

class Edge
{
    public:
        int t, w;
        Edge(){}
        // t : 辺の end 側,  w : 辺の重み
        Edge(int t, int w): t(t), w(w){}
};

vector<Edge> G[MAX];
int n;

// 任意のスタート点から、各頂点までの距離を保持する配列
int d[MAX];

void bfs(int s)
{
    for(int i = 0; i < n; i++)
    {
        // 距離情報の初期化
        d[i] = INFTY;
    }

    queue<int> Q;
    // スタート点の情報を設定する
    Q.push(s);
    d[s] = 0;

    int u;

    while( !Q.empty() )
    {
        u = Q.front();
        Q.pop();

        for(unsigned int i = 0; i < G[u].size(); i++)
        {
            Edge e = G[u][i];

            // 未訪問の頂点について, 始点からの距離を求める
            if( d[e.t] == INFTY )
            {
                d[e.t] = d[u] + e.w;
                Q.push(e.t);
            }
        }
    }
}

void solve()
{
    // 適当な始点 s から最も遠い節点 tgt を求める
    bfs(0);

    int maxv = 0;
    int tgt = 0;

    for(int i = 0; i < n; i++)
    {
        if( d[i] == INFTY )
        {
            continue;
        }

        if( maxv < d[i] )
        {
            maxv = d[i];
            tgt = i;
        }
    }

    // tgt から最も遠い節点の距離 maxv を求める
    bfs(tgt);

    maxv = 0;

    for(int i = 0; i < n; i++)
    {
        if( d[i] == INFTY )
        {
            continue;
        }

        maxv = max(maxv, d[i]);
    }

    cout << maxv << endl;
}

int main(void)
{
    int s, t, w;

    cin >> n;

    for(int i = 0; i < n - 1; i++)
    {
        cin >> s >> t >> w;

        // 双方向に設定する
        G[s].push_back(Edge(t, w));
        G[t].push_back(Edge(s, w));
    }

    solve();

    return 0;
}



Measured memory_bytes: 9784
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  ll n,k;
  cin >> n >> k;
  int ans = 0;
  while(n > 0){
    n /= k;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
const int INF = INT_MAX/3;
const double EPS = 1e-14;

template<typename U, typename T>
void chmin(U &x, T y) { x = min(x, y); }

template<typename U, typename T>
void chmax(U &x, T y) { x = max(x, y); }

typedef long long int lli;

int main() {
  lli n;
  cin >> n;
  lli s = 1, ans = 0;
  while (s <= n) {
    s *= 2;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1156
import java.io.*;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int a = fs.nextInt();
        int b = fs.nextInt();
        if( a < b * 2 ){
            System.out.println( 0 );
            return;
        }
        System.out.println( a - b - b);
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) {
                return buffer[ptr++];
            } else {
                return -1;
            }
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
                throw new NumberFormatException();
            }
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


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

int main() {
    /* 入力部分 */
    int N,M;
    cin >> N;
    vector<string> s(N);
    for(int i=0;i<N;i++) {
        cin >> s.at(i);
    }
    cin >> M;
    vector<string> t(M);
    for(int i=0;i<M;i++) {
        cin >> t.at(i);
    }
    
    /* 計算部分 */
    int buf1 = 0; // 
    int buf2 = 0; //
    for(int i=0;i<N;i++) {
        buf1 = 0;
        for(int j=0;j<N+M;j++) {
            if(j<N) {
                if (s.at(i) == s.at(j)) {
                    buf1++;
                }
                //青のカード探索
            }else{
                if (s.at(i) == t.at(j-N)) {
                    buf1--;
                }
                //赤のカード探索
            }
        }
        buf2 = max(buf2,buf1);
    }
    cout << buf2 << endl;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int n,a,b,c,d[100];
	scanf("%d",&n);
	scanf("%d %d",&a,&b);
	scanf("%d",&c);
	for(int i=0;i<n;i++)scanf("%d",&d[i]);
	sort(d,d+n);
	int res=0;
	for(int i=0;i<n;i++) {
		int sum=0;
		for(int j=0;j<i;j++)sum+=d[n-j-1];
		res=max(res,(sum+c)/(a+b*i));
	}
	printf("%d\n",res);
}

Measured memory_bytes: 1044
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main(){

    vector<string> v;
    string str;

    cin >> str;
    int counter = 0;

    while(true){
        string tmp;
        cin >> tmp;
        if(tmp=="END_OF_TEXT") break;
        v.push_back(tmp);
    }

    for(int i=0; i<v.size(); i++){
        for(int j=0; j<v[i].size(); j++){
            if((v[i][j]<=90)&&(v[i][j]>=65)) v[i][j] += 32;
        }
        for(int j=0; j<str.size(); j++){
            if((str[j]<=90)&&(str[j]>=65)) str[j] += 32;
        }
        if(v[i] == str) counter++;
    }

    cout << counter << endl;

    return 0;
}


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


int main(){
    long long h, n;
    cin >> h >> n;

    vector<pair<long long, long long> > ab(n);
    vector<long long> b(n);

    for(long long i = 0; i < n; i++){
        cin >> ab[i].first >> ab[i].second;
    }

    vector<long long> dp(h+1, 1e9);

    sort(ab.begin(), ab.end());

    dp[0] = 0;

    for(long long i = 0; i <= h; i++){
        for(long long j = 0; j < n; j++){
            if(i < ab[j].first){
                dp[i] = min(dp[i], ab[j].second);
            }
            else{
                dp[i] = min(dp[i], dp[i-ab[j].first]+ab[j].second);
            }
            

            //printf("dp[%d] %d\n", i, dp[i]);
        }
    }

    printf("%lld\n", dp[h]);

    return 0;
}

Measured memory_bytes: 384
class SegmentTree:
    def __init__(self, a):
        self.padding = 0
        self.n = len(a)
        self.N = 2 ** (self.n-1).bit_length()
        self.seg_data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-self.n)
        for i in range(2*self.N-2, 0, -2):
            self.seg_data[(i-1)//2] = self.seg_data[i] + self.seg_data[i-1]
    
    def __len__(self):
        return self.n
    
    def update(self, i, x):
        idx = self.N - 1 + i
        self.seg_data[idx] += x
        while idx:
            idx = (idx-1) // 2
            self.seg_data[idx] = self.seg_data[2*idx+1] + self.seg_data[2*idx+2]
    
    def query(self, i, j):
        # [i, j)
        if i == j:
            return self.seg_data[self.N - 1 + i]
        else:
            idx1 = self.N - 1 + i
            idx2 = self.N - 2 + j # 閉区間にする
            result = self.padding
            while idx1 < idx2 + 1:
                if idx1&1 == 0: # idx1が偶数
                    result = result + self.seg_data[idx1]
                if idx2&1 == 1: # idx2が奇数
                    result = result + self.seg_data[idx2]
                    idx2 -= 1
                idx1 //= 2
                idx2 = (idx2 - 1)//2
            return result
    
    @property
    def data(self):
        return self.seg_data[self.N-1:self.N-1+self.n]

N, Q = map(int, input().split())
A = list(map(int, input().split()))
st = SegmentTree(A)
ans = []
for _ in range(Q):
    t, i, j = map(int, input().split())
    if t:
        ans.append(st.query(i, j))
    else:
        st.update(i, j)

print(*ans, sep='\n')

Measured memory_bytes: 159864
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    int w, a, b;
    cin >> w >> a >> b;
    if(abs(a-b)<=w) { cout << 0 << endl; return 0;}
    int ans = abs(a-b)-w;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
n = int(input())
kotae = 0

if n <= 9:
    kotae = n
elif n <= 99:
    while n % 11 != 0:
        n = n + 1
    kotae = n
else:
    while n % 111 != 0:
        n = n + 1
    kotae = n

print(kotae)

Measured memory_bytes: 3060
import java.io.*;class Main{
public static void main(String[]_)throws Exception{
int i,j,k;
float l[]=new float[8];
BufferedReader B=new BufferedReader(new InputStreamReader(System.in));
for(String s;(s=B.readLine())!=null;System.out.println(k>0?"NO":"YES")){
_=s.split(",");
for(k=j=0;j<2;j++){
for(i=0;i<8;i++)l[i]=Float.valueOf(_[(4*j+i)%8]);
if(
((l[0]-l[2])*(l[5]-l[1])+(l[1]-l[3])*(l[0]-l[4]))*
((l[0]-l[2])*(l[7]-l[1])+(l[1]-l[3])*(l[0]-l[6]))<0)k++;
}
}
}
}

Measured memory_bytes: 9820
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <map>

#define ll long long

using namespace std;

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

    for(int i = 0 ; i<k ; i++)
    {
        cout<<s<<" ";
    }
    for(int i = 0 ; i<n-k ; i++)
    {
        if(s-1>=1)
        cout<<s-1<<" ";
        else
        cout<<s+1<<" ";
    }
    cout<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
#define pb push_back

typedef vector<ll> vll;
typedef vector<vll> vvll;

const int N = 57;
const int M = 1e9 + 7;
ll n, k;

vvll ident(int n) {
    vvll ans(n, vll(n, 0));
    for(int i = 0; i < n; ++i) ans[i][i] = 1;
    return ans;
}

vvll mult(vvll a, vvll b) {
    vvll ans(a.size(), vll(b[0].size()));

    for(int i = 0; i < a.size(); ++i) {
        for(int j = 0; j < b[0].size(); j++) {
            ans[i][j] = 0;
            for(int l = 0; l < a.size(); l++) {
                ans[i][j] = (ans[i][j] + a[i][l] * b[l][j])%M;
            }
        }
    }
    return ans;
}

vvll fast_exp(vvll mat, ll k) {
    vvll ans = ident(n);
    while(k) {
        if(k&1) ans = mult(ans, mat);
        k >>= 1;
        mat = mult(mat, mat);
    }
    return ans;
}

int main() {
    cin >> n >> k;
    vvll mat(n, vll(n));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> mat[i][j];
        }
    }

    vvll ans = fast_exp(mat, k);
    
    ll tot = 0;
    for(vll & aux : ans) for(ll & x : aux) tot = (tot + x)%M;
    cout << tot << endl;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
left, right = map(int, input().split())
for _ in range(M-1):
    c_left, c_right = map(int, input().split())
    if c_left > left:
        left = c_left
    if c_right < right:
        right = c_right

if right >= left:
    print(right-left+1)
else:
    print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    int C[N], A[12][12];
    for(int i = 0; i < N; ++i){
        cin >> C[i];
        for(int j = 0; j < M; ++j){
            cin >> A[i][j];
        }
    }

    const int INF = 1001001001;
    int sum[M], sm, ans=INF;
    
    for(int s = 0; s < 1<<N; ++s){//12を使う使わない全探索
        //init
        for(int j = 0; j < M; ++j) sum[j] = 0;
        sm=0;
        
        //calc
        for(int i = 0; i < N; ++i){
            if(s>>i&1){
                sm += C[i];
                for(int j = 0; j < M; ++j) sum[j] += A[i][j];
            }
        }
        //OK?
        bool ok = true;
        for(int j = 0; j < M; ++j){
            if(sum[j] < X) ok = false;
        }
        if(ok) ans = min(ans, sm);
    }
    if(ans == INF) ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    long long int x,sum = 100;
    cin >> x;
    for(long long int i = 0;i < x;i++){
        sum *= 1.01;
        if(x <= sum){
            cout << i+1 << endl;
            break;
        }
    }
    
}

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

struct Point{
  double x;
  double y;
};

void koch(int n, struct Point a, struct Point b){
  if(n==0)return;
  struct Point s, t, u;
  double rad =M_PI*60.0/180.0;
  
  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)* cos(rad) -(t.y-s.y)* sin(rad) +s.x;
  u.y=(t.x-s.x)* sin(rad) +(t.y-s.y)* cos(rad) +s.y;
  koch(n-1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n-1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n-1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n-1, t, b);
}

int main(){
  struct Point a, b;
  int n;
  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;

  scanf("%d", &n);
  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}

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

#define REP(i,n) for(int i = 0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long, long> pl;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll pos[n];
    REP(i,n){
        ll a; cin >> a; a--;
        pos[a] = i;
    }
    set<ll> lower;
    ll ans = 0;
    REP(i,n){
        ll wh = pos[i];
        lower.insert(wh);
        auto low = lower.lower_bound(wh);
        auto upp = lower.upper_bound(wh);
        ll fir, en;
        if(low==lower.begin()){
            fir = 0;
        }else{
            fir = *(--low) + 1;
        }
        if(upp==lower.end()){
            en = n-1;
        }else{
            en = *upp-1;
        }
        ans += (i+1) * (en-wh + 1) * (wh-fir + 1);
    }
    cout << ans << endl;
 
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void no(){
  cout << -1 << endl;
  exit(0);
}

int main(){
  ll n; cin >> n;
  //0-indexed
  vector<vector<ll>> a(n, vector<ll>(n-1));
  REP(i,n) REP(j,n-1){
    cin >> a[i][j];
    a[i][j]--;
  }
  //試合にIDを割り当てる
  vector<vector<ll>> id(n, vector<ll>(n,0));
  ll V = 0; //頂点数
  REP(i,n) REP(j,n) if(i<j) id[i][j] = V++;
  auto toID = [=](ll i, ll j){
    if(i>j) swap(i,j);
    return id[i][j];
  };
  vector<vector<ll>> to(V);
  vector<ll> deg(V,0);
  REP(i,n){
    REP(j,n-1) a[i][j] = toID(i,a[i][j]);
    REP(j,n-2) {
      to[a[i][j]].push_back(a[i][j+1]);
      deg[a[i][j+1]]++;
    }
  }
  stack<ll> st;
  REP(i,V) if(deg[i]==0) st.push(i);
  // dp[i] = 頂点iを始点とするパス長の最大値
  vector<ll> topo, dp(V,0);
  while(!st.empty()){
    ll cv = st.top();
    st.pop();
    topo.push_back(cv);
    FOREACH(nv,to[cv]){
      deg[nv]--;
      dp[nv] = max(dp[nv],dp[cv]+1);
      if(deg[nv]==0) st.push(nv);
    }
  }

  //トポロジカルソート列に全頂点が格納されていない場合，閉路がある
  if(SZ(topo)!=V) no();

  ll ans = 0;
  REP(i,V) ans = max(ans,dp[i]+1);
  cout << ans << endl;
}



Measured memory_bytes: 64496
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int K,T,mx=0;
    cin>>K>>T;
    
    rep(i,T){
        int x; cin>>x;
        chmax(mx,x);
    }
    
    int ans=mx-(K-mx)-1;
    cout1(max(0,ans))
}

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

using namespace std;

using int64 = long long;

const int INF = 1 << 30;

vector< int > g[2000];
int N, A[2000];
bool v[2000];
vector< int > ord;

void dfs(int idx) {
  v[idx] = true;
  ord.emplace_back(A[idx]);
  for(int i = 0; i < N; i++) {
    if(v[i]) continue;
    if(__gcd(A[i], A[idx]) == 1) continue;
    dfs(i);
  }
}

int main() {
  cin >> N;
  for(int i = 0; i < N; i++) cin >> A[i];
  sort(A, A + N);
  for(int i = 0; i < N; i++) {
    if(!v[i]) dfs(i);
  }
  for(int i = 0; i < N; i++) {
    for(int j = i + 1; j < N; j++) {
      if(__gcd(ord[i], ord[j]) != 1) {
        g[i].emplace_back(j);
      }
    }
  }
  vector< int > deg(N);
  for(int i = 0; i < N; i++) for(int j : g[i]) ++deg[j];
  priority_queue< pair< int, int > > que;
  for(int i = 0; i < N; i++) if(deg[i] == 0) que.emplace(ord[i], i);
  vector< int > ord2;
  while(que.size()) {
    auto p = que.top();
    que.pop();
    ord2.emplace_back(p.second);
    for(auto to : g[p.second]) {
      if(--deg[to] == 0) que.emplace(ord[to], to);
    }
  }
  for(int i = 0; i < N; i++) cout << ord[ord2[i]] << " ";
  cout << endl;
}



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

#define ft first
#define sd second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

const int MAXN = 200 * 1000 + 23;





bool check(int);
void inp();
void gedit();

int n, q, ans;
string s;
char save = 'L';
pcc c[MAXN];

int main() {
	inp();
	gedit();
	save = 'R';
	reverse(s.begin(), s.end());
	gedit();
	cout << n - ans;
	return 0;
}
void inp() {
	cin >> n >> q >> s;
	for (int i = 0; i < q; i++)
		cin >> c[i].ft >> c[i].sd;
}
bool check(int v) {
	for (int i = 0; i < q; i++) {
		if (c[i].ft == s[v])
			v = v + ((c[i].sd == save)? -1: 1);
		if (v < 0)
			return true;
	}
	return false;
}
void gedit() {
	int up = n + 1, dw = -1;
	while (up - dw > 1) {
		int m = ((up + dw) >> 1);
		if (check(m))
			dw = m;
		else
			up = m;
	}
	ans += up;
}

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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define sec second
#define fori(i, a, b) for(int i = int(a); i < int(b); i++)
#define cc(x)	cout << #x << " = " << x << endl
#define ok		cout << "ok" << endl

typedef pair<int,int> ii;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

const long long N = 1e5 + 10; 
long long n, cost[N];
long long dp[N];

long long pog(long long at, long long n, long long cost[]){
	if(at >= n) return 0;
	
  	long long &r = dp[at];
  	if(r != -1) return r;

	long long L = pog(at+1, n, cost) + abs(cost[at+1]-cost[at]);
	long long R = pog(at+2, n, cost) + abs(cost[at+2]-cost[at]);

	return r = min(L, R);
}

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

	memset(dp, -1, sizeof dp);
	cin >>n;

	for(int i = 0; i < n; i++)
		cin >>cost[i];
	
	cost[n] = INF;
	cout <<pog(0, n-1, cost) <<endl;
	return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n,k;
int store[100005];
int mod=1e9+7;
int power(int x,int y,int p)
{ 
    int res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if((y & 1)==1) 
            res = (res * x) % p; 
        y = y >> 1;  
        x = (x * x) % p;  
    } 
    return res; 
} 

int32_t main() 
{
    IOS;
    cin>>n>>k;
    for(int i=k;i>=1;i--)
    {
        int ans=power(k/i,n,mod);
        for(int j=2;i*j<=k;j++)
            ans=(ans-store[i*j]+mod)%mod;
        store[i]=ans;
    } 
    int sum=0;
    for(int i=1;i<=k;i++)
        sum=(sum+(i*store[i])%mod)%mod;
    print(sum);
}   


Measured memory_bytes: 4384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  rep(i, n) {
    // rep 一回につき、一数列
    while (i + 1 < n && a[i] == a[i + 1]) i++;

    if (i + 1 < n && a[i] < a[i + 1]) {
      while (i + 1 < n && a[i] <= a[i + 1]) i++;
    } else if (i + 1 < n && a[i] > a[i + 1]) {
      while (i + 1 < n && a[i] >= a[i + 1]) i++;
    }
    
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
string s;

int main() {
    ll A, V, B, W;
    ll T;
    cin >> A >> V >> B >> W >> T;
    if (A == B)puts("YES");
    else if (0 < (V - W) && (V - W) * T >= abs(B - A))puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
#define debug(x) cerr << #x << " = " << x << endl

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    a.push_back(0);
    int c1 = 0, c2 = inf;
    for(int i = n-2; i >= 0; i--){
        int t = min(c1 + abs(a[i] - a[i+1]), c2 + abs(a[i] - a[i+2]));
        c2 = c1;
        c1 = t;
    }
    cout << c1 << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define M 100000
#define SENTIMENTAL 2000000000

typedef struct{
  char suit;
  int value;
}Card;

Card L[M/2+2],R[M/2+2];

void merge(Card *,int,int,int,int);
void mergeSort(Card *,int,int,int);
int partition(Card *,int,int,int);
void quickSort(Card *,int,int,int);

int main() {

  int n,i,v;
  Card A[M],B[M];
  char S[10];
  int stable = 1;

  scanf("%d",&n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable == 1) printf("Stable\n");
  else printf("Not stable\n");
  
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;

}

void merge(Card A[],int n,int left,int mid,int right) {

  int i,j,k;
  int n1 = mid - left;
  int n2 = right - mid;

  for(i=0;i<n1;i++) L[i] = A[left+i];
  for(i=0;i<n2;i++) R[i] = A[mid+i];

  L[n1].value = R[n2].value = SENTIMENTAL;
  i = j = 0;

  for(k=left;k<right;k++) {
    if(L[i].value <= R[j].value) A[k] = L[i++];
    else A[k] = R[j++];
  }

}

void mergeSort(Card A[],int n,int left,int right) {

  int mid;

  if(left+1 < right) {
    mid = (left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }

}

int partition(Card A[],int n,int p,int r) {

  int i,j;
  Card t,x;

  x = A[r];
  i = p - 1;

  for(j=p;j<r;j++) {
    if(A[j].value <= x.value) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }

  t = A[i+1]; A[i+1] = A[r]; A[r] = t;

  return i+1;

}

void quickSort(Card A[],int n,int p,int r) {

  int q;

  if(p < r) {

    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);

  }

}

       



Measured memory_bytes: 4100
#include<bits/stdc++.h>
using namespace std;
string a;
int main(){
    cin >> a;
    if(a == "SUN"){
        cout << '7' << endl;
    }
    if(a == "MON"){
        cout << '6' << endl;
    }
    if(a == "TUE"){
        cout << '5' << endl;
    }
    if(a == "WED"){
        cout << '4' << endl;
    }
    if(a == "THU"){
        cout << '3' << endl;
    }
    if(a == "FRI"){
        cout << '2' << endl;
    }
    if(a == "SAT"){
        cout << '1' << endl;
    }
    return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    d = input()
    n = int(input())
    qs = [input() for e in range(n)]
    s = []
    e = []
    r = False
    for q in qs:
        if q == '1':
            r = not(r)
        elif q.startswith("2 1"):
            e.append(q[-1]) if r else s.append(q[-1])
        else:
            s.append(q[-1]) if r else e.append(q[-1])
    print("".join(e[::-1]) + d[::-1] + "".join(s) if r else "".join(s[::-1]) + d + "".join(e))

Measured memory_bytes: 18952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  string s,t;
  cin >> s >> t;
  vector<ll> A[26];
  for (int i = 0; i < s.size(); i++) {
    A[s[i] - 'a'].push_back(i+1);
  }
  ll ans = 0;
  for (int i = 0; i < t.size(); i++) {
    char c = t[i];
    ll spot = ans % s.size();
    if (A[c - 'a'].size() == 0) {
      cout << -1 << endl;
      return 0;
    }
    auto itr = upper_bound(A[c-'a'].begin(),A[c-'a'].end(),spot);
    if (itr == A[c-'a'].end()) {
      ans += s.size() + A[c-'a'][0] - spot;
    } else {
      ans += *itr - spot;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1724
#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() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

int main(){
    int a,b,c;
    int k;
    cin >> a >> b >> c >> k;
    for(int i=0;i<=k;i++){
        int newb = b * powl(2,i);
        int newc = c * powl(2,(k-i));
        if(a < newb && newb < newc){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3700
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n  = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(sc.next());
		Arrays.sort(a);
		System.out.println(a[n - 1] - a[0]);
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)

vector<ll> G[100001]; //隣接リスト
bool used[100001];
vector<ll> ansL;
vector<ll> ansR;

void dfsL(ll x){
	used[x]=true;
	ansL.pb(x);

	rep(i,sz(G[x])){
		if(!used[G[x][i]]){
			dfsL(G[x][i]);
			return;
		}
	}
}
void dfsR(ll x){
	used[x]=true;
	ansR.pb(x);

	rep(i,sz(G[x])){
		if(!used[G[x][i]]){
			dfsR(G[x][i]);
			return;
		}
	}
}

int main(){
	//input
	ll N,M; cin>>N>>M;
	//初期化
	rep(i,100001) used[i]=false;

    rep(i,M){
		ll A,B; cin>>A>>B;
		G[A].pb(B);
		G[B].pb(A);
	}

	dfsL(1);
	dfsR(1);

	cout<<sz(ansL)+sz(ansR)-1<<endl;
	rrep1(i,sz(ansL)-1) cout<<ansL[i]<<" ";
	rep(i,sz(ansR)) cout<<ansR[i]<<" ";
}

Measured memory_bytes: 10100
#include<bits/stdc++.h>
#include<vector>
#include<iterator>
#include<algorithm>
#include<iomanip>
#include <string.h>
#include<set>

#define ll long long
using namespace std;
int main()
{
	ll d,s,t;
	cin >> d >> s >> t;
	ll sum=s*t;
	if(sum >= d){
        cout << "Yes"<<"\n";
	}
	else{
        cout << "No"<<"\n";
	}

}


Measured memory_bytes: 3588
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, intmax_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, intmax_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

    string s, t; cin >> s >> t;

    auto dp = make_v(0, s.length() + 1, t.length() + 1);
    for (size_t i = 0; i < s.length(); ++i) {
        for (size_t j = 0; j < t.length(); ++j) {
            if (s[i] == t[j]) {
                chmax(dp[i + 1][j + 1], dp[i][j] + 1);
            }
            chmax(dp[i + 1][j + 1], dp[i + 1][j]);
            chmax(dp[i + 1][j + 1], dp[i][j + 1]);
        }
    }

    string res = "";
    size_t i = s.length(), j = t.length();
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i][j - 1]) {
            j--;
        } else if (dp[i][j] == dp[i - 1][j]) {
            i--;
        } else if (dp[i][j] == dp[i - 1][j - 1] + 1) {
            i--, j--;
            res = s[i] + res;
        }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	string S;
	cin >> S;

	string front = S.substr(0, S.size() / 2);
	string back = S.substr((S.size() + 3) / 2 - 1, S.size() / 2);

	//cout << S << " " << front << " " << back << endl;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] != S[S.size() - i - 1])
		{
			cout << "No" << endl;
			return;
		}
	}

	for (int i = 0; i < front.size(); i++)
	{
		if (front[i] != front[front.size() - i - 1])
		{
			cout << "No" << endl;
			return;
		}
	}
	for (int i = 0; i < back.size(); i++)
	{
		if (back[i] != back[back.size() - i - 1])
		{
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  int n;
  cin >> n;
  vector<ll> a(n + 1), b(n);
  rep(i, n + 1) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll ans = 0;
  rep(i, n) {
    ll toubatsu = min(a[i], b[i]);
    ans += toubatsu;
    b[i] -= toubatsu;
    toubatsu = min(a[i + 1], b[i]);
    ans += toubatsu;
    a[i + 1] -= toubatsu;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

int main() {
	int top = 0, n, a;
	bool color[8] = { false };
	cin >> n;
	REP(i, n) {
		cin >> a;
		if (a >= 3200)
			top++;
		else
			color[a / 400] = true;
	}

	int used = count(color, color + 8, true), c, d;
	if (used == 0)
		c = 1;
	else
		c = used;

	d = used + top;

	cout << c << " " << d << endl;

	return 0;
}

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

int main()
{
	int i = 0;
	cin >> i;
	if (i / 3600>=0)
	{
		cout << i / 3600 << ":";
	}
	else
	{
		cout << 0;
	}
	if (i / 60 >= 0)
	{
		cout << (i / 60)-((i/3600)*60) << ":";
	}
	else
	{
		cout << 0;
	}
	if (i >= 0)
	{
		cout << i - (i / 60*60)  << endl;
	}
	else
	{
		cout << 0;
	}

}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int a, b, c, d;
	cin >> a >> b >> c >> d;	
	int cnt = 1;
	while(1) {
		if(cnt & 1) {
			c -= b;
			if(c <= 0) {
				cout << "Yes";
				return 0;
			}
		}
		else {
			a -= d;
			if(a <= 0) {
				cout << "No";
				return 0;
			}
		}
		cnt++;
	}
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  vector<PII> xs(N);
  cin >> xs;

  VVI ends(32);
  for(auto p: xs)
	ends[p.FF].PB(p.SS);

  int ans = 0;
  priority_queue<int,VI,greater<int>> pq;
  FOR(t,1,32){
	for(int e: ends[t])
	  pq.push(e);
	while(!pq.empty() && pq.top() < t)
	  pq.pop();

	if(!pq.empty()){
	  ans += 100;
	  pq.pop();
	}
	else{
	  ans += 50;
	}
  }
  
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3196
package main

import (
	"fmt"
	"math"
)

func main() {
	N := scanInt()
	if N == 1 {
		fmt.Println("Hello World")
	}
	if N == 2 {
		A, B := scanInt2()
		fmt.Println(A + B)
	}
}

/*
	Snippets
*/
func scanInt() (a int) {
	fmt.Scan(&a)
	return
}
func scanInt2() (a, b int) {
	fmt.Scan(&a, &b)
	return
}
func scanInt3() (a, b, c int) {
	fmt.Scan(&a, &b, &c)
	return
}
func scanInts(n int) []int {
	A := make([]int, n)
	for i := 0; i < n; i++ {
		A[i] = scanInt()
	}
	return A
}
func scanInts2(n int) ([]int, []int) {
	A, B := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		A[i], B[i] = scanInt2()
	}
	return A, B
}
func scanInts3(n int) ([]int, []int, []int) {
	A, B, C := make([]int, n), make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		A[i], B[i], C[i] = scanInt3()
	}
	return A, B, C
}
func scanMatrix(n, m int) [][]int {
	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = scanInts(m)
	}
	return A
}
func scanStr() (s string) {
	fmt.Scan(&s)
	return
}
func scanStrs(n int) []string {
	S := make([]string, n)
	for i := 0; i < n; i++ {
		S[i] = scanStr()
	}
	return S
}
func getAbs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func getPow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}
func getMin(nums ...int) (int, int) {
	if len(nums) == 0 {
		panic("funciton getMin() requires at least one argument.")
	}
	min := nums[0]
	pos := 0
	for i := 1; i < len(nums); i++ {
		if min > nums[i] {
			min = nums[i]
			pos = i
		}
	}
	return min, pos
}
func getMax(nums ...int) (int, int) {
	if len(nums) == 0 {
		panic("funciton getMax() requires at least one argument.")
	}
	max := nums[0]
	pos := 0
	for i := 1; i < len(nums); i++ {
		if max < nums[i] {
			max = nums[i]
			pos = i
		}
	}
	return max, pos
}
func getGcd(a, b int) int {
	if b == 0 {
		return a
	}
	return getGcd(b, a%b)
}
func getLcm(a, b int) int {
	return a * b / getGcd(a, b)
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

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

    int r = 0;
    while (static_cast<int>(1.08 * r) < n) {
        r++;
    }

    if (static_cast<int>(1.08 * r) == n) {
        cout << r << endl;
    } else {
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int main(){
  ll r0, w0, c, r;
  while (cin >> r0 >> w0 >> c >> r, r0){
    if (r0 >= c * w0){
      cout << "0\n";
      continue;
    }
    ll res = 0;
    for (ll i = 1ll << 30; i; i >>= 1){
      if (r0 + i * r < c * w0){
        r0 += i * r;
        res += i;
      }
    }
    cout << res + 1 << endl;
  }
}

Measured memory_bytes: 3184
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if (a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if (b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if (b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if (c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
    else 
        cout << c << " " << b << " " << a << endl;
}


Measured memory_bytes: 3100
A, B, C, D = map(int, input().split())

def gcd(a, b):
  while b != 0:
    a, b = b, a % b
  return a

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

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

Measured memory_bytes: 38512