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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n;
	cin>>n;
	vec<ll> A(n);
	REP(i,n) cin>>A[i];

	auto merge = [&](auto &&self, vec<ll>& a)->ll{
		//マージソートしながら転倒数を数えて返す
		int n=a.size();
		if(n<=1) return 0;

		vec<ll> b(a.begin(), a.begin()+n/2);
		vec<ll> c(a.begin()+n/2, a.end());
		ll con=0;
		con += self(self,b);//ソートして左側の転倒数を返す
		con += self(self,c);//ソートして右側の転倒数を返す

		int bi=0,ci=0;
		REP(ai,n){
			if(bi<b.size() && (ci==c.size() || b[bi]<=c[ci])){
				a[ai]=b[bi++];
			}else{
				con+=b.size()-bi;//c[ci]以下の大きさのbはbi個→大きいのはb.size()-bi個
				a[ai]=c[ci++];
			}
		}
		return con;
	};

	cout<<merge(merge,A)<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 7768
n = int(input())
b_list = list(map(int, input().split()))
b_list.append(b_list[-1])
a_list = [0] *n
a_list[0] = b_list[0]
for i in range(1,n):
    #print(i)
    if b_list[i-1] <= b_list[i]:
        a_list[i] = b_list[i-1]
    else:
        a_list[i] = b_list[i]
    #print(a_list)
print(sum(a_list))

Measured memory_bytes: 9020
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int count = 0;
		for (int a = 1; a <= K; a++) {
			for (int b = 1; b <= K; b++) {
				 for (int c = 1; c <= K; c++) {
					 int min = c;
					 if (b < c) min = b;
					 if (a < b) min = a;
					 int com = 0;
					 for (int i = min; 1 <= i ; i--) {
						 if (a%i == 0 && b%i == 0 && c%i == 0) {
							 com = i;
							 break;
						 }
					 }
					 count += com;
				 }
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 36488
#include <iostream>
#include <map>
#include <string>
#include <cmath>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
typedef long long int LL;

// 012 <--> 753
const string i2c = "753";
const map<char, int> c2i = {{'7', 0}, {'5', 1}, {'3', 2}};
int main() {
  int n;

  cin >> n;

  int ans = 0;;
  for (int d = 3; d < 10; d++) {
    for(int b = 0; b < pow(3, d); b++) {
      string str;

      int cb = b;

      for (int i = 0; i < d; i++) {
        str.push_back(i2c[cb % 3]);
        cb /= 3;
      }

      bool cnt[3];
      fill(cnt, cnt+3, false);

      for (char c : str) {
        cnt[c2i.at(c)] = true;
      }

      bool judge = true;
      rep(i, 3) {
        if (not cnt[i]) judge = false;
      }
      if (not judge) continue;

      if (stoi(str) <= n) ++ans;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  long n;
  cin >> n;
  long s = 0;
  long c = n/15;
  s = c *(c-1)/2*8*15 + 60*c;
  
  for(long i = c*15+1; i<=n;++i){
    if(i%3!=0&&i%5!=0) s+= i;
  }
  
  cout << s << endl;
}

Measured memory_bytes: 3676
// import chie template :) {{{
import std.stdio,
       std.algorithm,
       std.array,
       std.string,
       std.math,
       std.conv,
       std.range,
       std.container,
       std.bigint,
       std.ascii,
       std.typecons;
// }}}
// tbh.scanner {{{
class Scanner {
  import std.stdio;
  import std.conv : to;
  import std.array : split;
  import std.string : chomp;

  private File file;
  private dchar[][] str;
  private uint idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  private dchar[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    dchar[] s;
    while (s.length == 0) {
      s = file.readln.chomp.to!(dchar[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(uint len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  int n = cin.next!int;
  writeln(n / 3);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

   int x,a,i,max;
   x=i=max=0;
   scanf("%d",&a);
   char s[a];

   scanf("%s",s);
   while(s[i]!='\0'){
      if(s[i]=='I') x++;
      else if(s[i]=='D') x--;
      if(max<x) max=x;
      i++;
   }
   printf("%d",max);
   return 0;
}

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


int main() {
    string S, T;
    cin >> S >> T;

    bool ans = false;
    for (int i = 0; i < T.size(); ++i) {
        T = T.back() + T.substr(0, T.size()-1);
        if (S == T) {
            ans = true;
            break;
        }
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, a[2010], dp[2010][2010];
int solve(int fst, int snd) {
    int &val = dp[fst][snd];
    if(~val) return val;
    if(fst == N-1 || snd == N-1) return val = abs(a[fst] - a[snd]);

    if(fst < snd) {
        // first
        if(fst == snd - 1) {
            for(int k=snd+1; k<N; k++) {
                chmax(val, solve(k, snd));
            }
            return val;
        }
        else {
            return val = solve(fst+1, snd);
        }
    }
    else {
        // second
        if(snd == fst - 1) {
            val = INF;
            for(int k=fst+1; k<N; k++) {
                chmin(val, solve(fst, k));
            }
            return val;
        }
        else {
            return val = solve(fst, snd+1);
        }
    }
}

signed main() {
    cin >> N;
    N += 2;
    rep(i,0,N) cin >> a[i];
    memset(dp, -1, sizeof(dp));

    cout << solve(0, 1) << endl;
    return 0;
}

Measured memory_bytes: 31872
#include<iostream>
using namespace std;
void call(int n);
int main() {
    int n;
    cin >> n;
    call(n);
}
void call(int n) {
    for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0) {
            cout << " " << i;
            continue;
        } 
        for (int j = i; j > 0; j /= 10) {
            if (j % 10 == 3) {
                cout << " " << i;
                break;
            }
        }
    }
    cout << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)
typedef pair<int, int> P;

int main() {
    int n, m;
    cin >> n >> m;
    int ans = n*(n-1)/2+m*(m-1)/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    for y in range(h):
        cnt=y%2
        for x in range(w):
            if cnt==0:
                if x%2==0:
                    print("#",end='')
                else:
                    print(".",end='')
            else:
                if x%2==0:
                    print(".",end='')
                else:
                    print("#",end='')
        print()
    print()

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

using ll = long long; 

int main() {
  ll N, A, B;
  cin >> N >> A >> B;

  ll ans = 0;
  ll rem = 0; 
  ans = (N / (A+B))*A;
  rem = N % (A+B);
  ans += min(rem, A); 
  cout << ans << endl;
}

Measured memory_bytes: 384
using System;

class PG{
    public static void Main(string[] args){
        int n=int.Parse(Console.ReadLine());
        int count=0;
        for(int i=0;i<n;i++){
            if(IsPrime(int.Parse(Console.ReadLine()))){
                count++;
            }
        }
        Console.WriteLine(count);
    }
    public static bool IsPrime(int n){
        for(int i=2;i<=Math.Sqrt(n);i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }
}


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

using namespace std;

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

const int N = 3e3+10;

pll dp[N][N];
int a[N];

pll rec(int l, int r) {
	if(l==r) {
		return {a[l], 0};
	} else {
		pll f = {0, 0};
		if(dp[l][r] != f) return dp[l][r];
		int x = a[l], y = a[r];
		pll p1 = rec(l+1, r);
		pll p2 = rec(l, r-1);

		swap(p1.first, p1.second);
		swap(p2.first, p2.second);

		p1.first += x;
		p2.first += y;
		pll p = max(p1, p2);
		dp[l][r] = p;
		return p;
	}
}

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

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

	pll p = rec(0, n-1);
	cout << p.first - p.second;
}

Measured memory_bytes: 85748
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	static long mod = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] c = sc.next().toCharArray();
		int[] alcount = new int['z' - 'a' + 1];
		Arrays.fill(alcount, 0);
		for(int i = 0; i < c.length; i++) {
			alcount[(int)(c[i] - 'a')]++;
		}
		long ans = 1;
		for(int i = 0; i < alcount.length; i++) {
			if(alcount[i] == 0) continue;
			ans *= (long)alcount[i] + 1;
			ans %= mod;
		}
		System.out.println((ans + mod - 1) % mod);
	}
}


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

int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int ans=0;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		if(t<a||b<=t)ans++;
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
      	for (char c : s.toCharArray()) {
        	if (c == '7') {
            	System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 35680
from collections import deque

S = list(input())
d = deque(S)
Q = int(input())

flag = 0
for _ in range(Q):
    q = input()
    if q == "1":
        flag += 1
    else:
        _, t, c = q.split()
        if flag % 2 == 0:
            if t == "1":
                d.appendleft(c)
            else:
                d.append(c)
        else:
            if t == "2":
                d.appendleft(c)
            else:
                d.append(c)

if flag % 2 == 1:
    d.reverse()
print("".join(list(d)))


Measured memory_bytes: 9204
### main

n, rn, ln = gets.strip.split(' ').map{|s| s.to_i}

scores = n.times.map{0}
shots = n.times.map{0}

prev_d = 0
prev_t = 0

rn.times do
  d, t, x = gets.strip.split(' ').map{|s| s.to_i}
  d -= 1

  shots[prev_d] += t - prev_t
  scores[d] += x

  if x > 0
    if scores[prev_d] < scores[d]
      prev_d = d
    elsif scores[prev_d] == scores[d]
      prev_d = [prev_d, d].min
    end
  elsif x < 0 && d == prev_d
    prev_d = (0...n).max do |a, b|
      (cmp = scores[a] <=> scores[b]) != 0 ? cmp : (b <=> a)
    end
  end

  prev_t = t
end

shots[prev_d] += ln - prev_t

max_d = (0...n).max do |a, b|
  (cmp = shots[a] <=> shots[b]) != 0 ? cmp : (b <=> a)
end

puts (max_d + 1)

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

using namespace std;
using ll = long long;

#define REP(i,n) for(int (i)=0,i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(x) cout << x << endl
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

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

    cout << 3 * a * a << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int time;
	int h,m,s;
	
	scanf( "%d", &time);
	h=time/3600;
	time=time%3600;
	m=time/60;
	s=time%60;
	printf( "%d:%d:%d\n", h, m, s);
	
	return 0;
}

Measured memory_bytes: 1020
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
#define F first
#define S second
constexpr auto INF = 1000000000;
constexpr auto LLINF = 9223372036854775807;
constexpr auto mod = 1000000007;

int main() {

	int n;
	cin >> n;
	vector<pair<int, int>> a(n), b(n);
	FOR(i, n)cin >> a[i].F >> a[i].S;
	FOR(i, n)cin >> b[i].F >> b[i].S;

	SORT(a); SORT(b);
	int ans = 0;
	FOR(i, b.size()) {
		pair<int, int> m = { -1,-1 };
		FOR(j, a.size()) {
			if (a[j].F < b[i].F && a[j].S < b[i].S) {
				if (m.S < a[j].S)m = { j,a[j].S };
			}
		}
		if (m.F != -1) {
			ans++;
			b.erase(b.begin() + i);
			a.erase(a.begin() + m.F);
			i--;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool judge = false;
  for(int i = 0;i < s.size();i++){
    for(int j = 0;j < s.size();j++){
      string S = s;
      if(i+j <= s.size()){
        S.erase(i,j);
        if(S == "keyence"){
          judge = true;
          break;
        }
      }
    }
  }
  if(judge == true)cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int N, M;
  while(cin>>N>>M && N){
    vector<int> s(N), t(N);
    vector<int> rope(M);
    REP(i, N) cin>>s[i]>>t[i];
    REP(i, M) cin>>rope[i];
    sort(rope.begin(), rope.end());
    vector<int> sum_mod[2];
    REP(i, 2) sum_mod[i] = vector<int>(M);
    REP(i, M - 1){
      sum_mod[0][i + 1] = sum_mod[0][i] + ((i % 2 == 0) ? (rope[i + 1] - rope[i]) : 0);
      sum_mod[1][i + 1] = sum_mod[1][i] + ((i % 2 == 1) ? (rope[i + 1] - rope[i]) : 0);
    }
    ll ans = 0;
    REP(i, N){
      bool rev = (s[i] > t[i]);
      if(rev) swap(s[i], t[i]);
      int b_idx = upper_bound(rope.begin(), rope.end(), s[i]) - rope.begin();
      int e_idx = upper_bound(rope.begin(), rope.end(), t[i]) - rope.begin();
      if(b_idx == e_idx){
        ans += (t[i] - s[i]);
        //if(!rev) printf("%d->%d %lld\n", s[i], t[i], ans - tmp);
        //else printf("%d->%d %lld\n", t[i], s[i], ans - tmp);
        continue;
      }
      assert(b_idx < e_idx);
      e_idx--;
      if(!rev){
        int mod = (b_idx + 1) % 2;
        ans += sum_mod[mod][e_idx] - sum_mod[mod][b_idx];
        ans += (rope[b_idx] - s[i]);
        if(e_idx % 2 == mod){
          ans += (t[i] - rope[e_idx]);
        }
      }else{
        int mod = (e_idx) % 2;
        ans += sum_mod[mod][e_idx] - sum_mod[mod][b_idx];
        ans += (t[i] - rope[e_idx]);
        if((b_idx + 1) % 2 == mod){
          ans += (rope[b_idx] - s[i]);
        }
      }
      //if(!rev) printf("%d->%d %lld\n", s[i], t[i], ans - tmp);
      //else printf("%d->%d %lld\n", t[i], s[i], ans - tmp);
    }
    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 3500
#include <stdio.h>

int main(void){
  long N;
  long A[262144];
  long max = 0;
  long long sum = 0;
  int i;
  
  scanf("%ld", &N);
  for(i = 0; i < N; i++)
    scanf("%ld", &A[i]);
  
  for(i = 0; i < N; i++){
    if(A[i] < max)
      sum += max - A[i];
    else
      max = A[i];
  }
  
  printf("%lld\n", sum);
  
  return 0;
}

Measured memory_bytes: 3272
import java.util.*;


class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int X = sc.nextInt();
		
		System.out.println( X >= A && X <= (A + B) ? "YES" : "NO");
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
long long mod=1000000000+7,n,m,h,w,jie[200003],ans;
long long mi(long long x,long long t)
{
	if(t==1)
		return x;
	long long sum=mi(x,t/2);
	sum=(sum*sum)%mod;
	if(t%2==1)
		sum=(sum*x)%mod;
	return sum;
}
long long c(long long n,long long m)
{
	return (mi((jie[n-m]*jie[m])%mod,mod-2)*jie[n])%mod;
}
int main()
{
	cin>>n>>m>>h>>w;
	jie[0]=1,jie[1]=1;
	for(long long i=2; i<=200000; i++)
		jie[i]=(jie[i-1]*i)%mod;
	for(long long i=1; h+i<=n&&w+i<=m; i++)
		ans=(ans+(c(n+w-h-1,w+i-1)*c(h+m-w-1,m-w-i)%mod))%mod;
	cout<<ans;
	return 0;
}

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

using namespace std;

using ll = long long;

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

    ll ans = 0;
    for (ll x = 1; x * x <= n; x++) {
        if (n % x != 0) continue;
        ll m = n / x - 1;
        if (m <= 0) continue;
        if (n / m == n % m) ans += m;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define int ll

signed main(){
    int n,m;
    cin >> n >> m;
    if(n*2>=m){
        printf("%lld\n",m/2);
    } else {
        int ans = n;
        m -= 2*n;
        ans += m/4;
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String bus = sc.next();
		sc.close();

		if(bus.charAt(0) == bus.charAt(1)) {
			if(bus.charAt(1) == bus.charAt(2)) {
				System.out.println("No");
			}else {
				System.out.println("Yes");
			}
		}else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 100005


int main(){


    ll n,s,ans = INF,sum = 0;
    cin >> n >> s;
    vector<ll> arr(n);
    REP(i,n){
        cin >> arr[i];
    }

    ll left = 0,right = 0;
    while(right <= n && left <= right){ 
        if(sum < s){
            //まだ右に伸ばせる
            sum += arr[right];
            right++;
        }else{
            //もう右に伸ばせないのでこの区間の長さが求まった
            ans = min(ans,right-left);
            sum -= arr[left];
            left++;
        }
    }
    if(ans == INF){
        ans = 0;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3624
a, b, degC = gets.split( " " ).map { |val| val.to_f }
radC = degC*Math::PI/ 180.0
h = Math.sin( radC ) * b
S = (a*h)/2
x = Math.cos( radC ) * b
x -= a
c = Math.sqrt(  x**2 + h**2  ) 
L = a + b + c

puts( S )
puts( L )
puts( h )

Measured memory_bytes: 6192
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


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

   }
  
   int ans = 0;
  
   for(int i = 0;i<n;i++){
     
      for(int j = i;j<n;j++){
        
        int tmp = a[i];
        a[i]=a[j];
        a[j]=tmp;
        
        int sum = 0;
         for(int k = 1;k<n;k++){
        //   cout << a[k]<<endl;
           if(a[k-1]<a[k]){
             sum=sum+1;
           }
           
         }
          int tmp2 = a[i];
        a[i]=a[j];
        a[j]=tmp2;
       
        
        if(sum==n-1){
          
          cout <<"YES"<<endl;
          ans = 1;
          break;
        }
        

      }
      if(ans==1){
 
        
        break;
   }
     
     
   }
  
   if(ans==0){
   cout <<"NO"<<endl;
   }
  
   
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = (S / 60)/60;
		int m = S /60 - h * 60;
		int s = S - h * 60 * 60 - m *60;

		System.out.println(h + ":" + m + ":" + s);
		sc.close();
	}
}

Measured memory_bytes: 26216
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//		String W	 = in.readLine();
		//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		Map<Long, Long> nums = new HashMap<>();

		long ans = 0;

		for(int i = 0;i<N ; i++) {
			A[i] = sc.nextLong();
			ans += A[i];
			Long tmp = nums.get(A[i]);
			if(tmp == null) {
				tmp =0L;
			}
			nums.put(A[i], ++tmp);
		}
		long Q = sc.nextLong();
		long[] B = new long[(int)Q];
		long[] C = new long[(int)Q];
		for(int i = 0;i<Q ; i++) {
			B[i] = sc.nextLong();
			C[i] = sc.nextLong();
			Long tmpB = nums.get(B[i]);
			if(tmpB == null) {
				tmpB = 0L;
			}
			ans += (C[i]-B[i])*tmpB;
			Long tmpC = nums.get(C[i]);
			if(tmpC == null) {
				tmpC = 0L;
			}
			nums.put(C[i], tmpC + tmpB);
			nums.put(B[i],  0L);
			System.out.println(ans);
		}
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}



}


Measured memory_bytes: 69612
N = int(input())
S = [input() for i in range(N)]

ch = "MARCH"
xs = [0] * 5

for s in S:
    if s[0] in ch:
        i = ch.index(s[0])
        xs[i] += 1

from itertools import combinations

def calc(xs):
    r = 0
    for ys in combinations([0, 1, 2, 3, 4], 3):
        r += xs[ys[0]] * xs[ys[1]] * xs[ys[2]]
    return r

print(calc(xs))



Measured memory_bytes: 9808
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N;
int l,r;
int main(){
	cin>>N;
	int A=0;
	for(int i=0;i<N;i++){
		cin>>l>>r;
		A+=r-l+1;
	}
	cout<<A<<endl;

	return 0;
}


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

a,b,c = map(int,input().split())

p = 3
if a==b:
    p = p-1
    if b==c:
        p = p-1
    else:
        pass
elif b==c:
    p = p-1
elif a==c:
    p = p-1
else:
    pass

print(p)

Measured memory_bytes: 2940
from heapq import *

N, M = map(int, input().split())
*A, = map(int, input().split())
minusA = [-a for a in A]
heapify(minusA)
while M:
    maxA = - heappop(minusA)
    heappush(minusA, - (maxA >> 1))
    M -= 1
print(sum(-a for a in minusA))

Measured memory_bytes: 14180
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,sum=0,ans;
  cin>>n>>m;
  int a[m];
  for(int i=0;i<m;i++)
  {
      cin>>a[i];
  }
  sum=accumulate(a, a+m,sum); 
  ans=n-sum;
  if(ans>=0)
  {
      cout<<ans;
  }
  else
  cout<<"-1";
}

Measured memory_bytes: 3660
N = gets.to_i
ps = []
N.times{|i|
  x, y, h = gets.split.map(&:to_i)
  ps << {
    :x => x,
    :y => y,
    :h => h
  }
}

ps.sort!{|a, b|
  v = -1 if a[:h] > b[:h]
  v = 1 if a[:h] < b[:h]
  v = 0 if a[:h] == b[:h]
  v
}

for x in 0..100
  for y in 0..100
    ps.each{|p|
      bh = (x - p[:x]).abs + (y - p[:y]).abs + p[:h]
      correct = true
      ps.each{|pp|
        next if pp == p
        eh = [bh - (x - pp[:x]).abs - (y - pp[:y]).abs, 0].max
        next if eh == pp[:h]
        correct = false
        break
      }
      if correct
        puts "#{x} #{y} #{bh}"
        exit
      end
    }
  end
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
 
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
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 A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const int MOD=(1e9)+7;
const int mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
using namespace std;
set<lol> s;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k;
  cin >>k;
  lol ans,tmp=7%k;
  int i=1;
  while(tmp){
    tmp*=10;
    tmp+=7;
    tmp%=k;
    if(s.find(tmp)!=s.end()){
      cout <<"-1\n";
      return (0);
    }
    s.insert(tmp);
    i++;
  }
  cout <<i<<'\n';
  return (0);
}

Measured memory_bytes: 50408
#include <bits/stdc++.h>
using namespace std;
int sum[200005];
map<int,int> mp;
int main()
{
    int ans=0;
    string s;
    cin >>s;
    mp[0]=1;
    int len=s.size(),x=0,cnt=1;
    for(int i=len-1;i>=0;i--)
    {
        x=((s[i]-'0')*cnt+x)%2019;
        ans+=mp[x];
        mp[x]++;
        cnt=cnt*10%2019;
    }
    cout <<ans<<endl;
}

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


int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  if((b/a>=2 && b/a<4 && (2*a-b)%2==0 && (b)%2==0)||(b==4*a)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }



}

Measured memory_bytes: 3648
#include <stdio.h>

int Bubblesort(int *,int);
void swap (int *,int *);
  
int main()
{
  int i,n,a[100],b;

  scanf("%d",&n);

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

  b=Bubblesort(a,n);
  
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i<n-1){
      printf(" ");
    }
  }
    printf("\n");
  printf("%d\n",b);
  
  return 0;
  
}

void swap(int *x,int *y){
  int temp;

  temp=*x;
  *x=*y;
  *y=temp;
}

int Bubblesort(int *a, int n){

  int i,j,count=0;

  for(i=0;i<n-1;i++){
    for(j=n-1;j>=i+1;j--){
      if(a[j]<a[j-1]){
	swap(&a[j],&a[j-1]);
	count++;
      }
    }
  }
  return count;
}
  



Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

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

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

int n,k,a[200000];
map<int,int> mp;
vector<int> v;

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

	cin>>n>>k;
	REP(i,n) {
		cin>>a[i];
		mp[a[i]-1]++;
	}
	for(auto x:mp) {
		v.pb(x.se);
	}
	sort(ALL(v));
	//reverse(ALL(v));
	int i=0;
	int cnt=0;
	while (v.size()-i>k) {
		cnt+=v[i];
		i++;
	}
	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 11512
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

// int main() {
//     ll A[4];
//     rep(i,3){
//         cin >> A[i];
//     }
//     //sort(A,A+3);
//     cout << min(A[0]*A[1],A[2]) << endl;
// }

int main(){
    char X[4],Y[4];cin >> X >> Y;
    cout <<(X[0]==Y[2] && X[1]==Y[1] && X[2]==Y[0] ? "YES" : "NO")<<endl;;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace CompetitiveProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int quot = n / 111;
            int rest = n % 111;


            if(rest != 0)
            {
                Console.WriteLine(111 * (quot + 1));
            }else{
                Console.WriteLine(111 * quot);
            }

        }
    }
}


Measured memory_bytes: 13140
(H, W) = map(int, input().split())
a = []
for i in range(H):
    a.append(list(map(int, input().split())))
#print("a: ")
#print(a)

odd_flag = []
for i in range(len(a)):
    odd_flag.append(list())
    for j in range(len(a[i])):
        if a[i][j]%2 != 0:
            odd_flag[i].append(True)
        else:
            odd_flag[i].append(False)
#print("odd_flag: ")
#print(odd_flag)

odd_sum = 0
for i in range(len(odd_flag)):
    odd_sum += odd_flag[i].count(True)
#print(odd_sum)

def move(h, w):
    if h%2 == 0:
        if w == W-1:
            return (h+1, w)
        else:
            return (h, w+1)
    else:
        if w == 0:
            return (h+1, w)
        else:
            return (h, w-1)

s_h = 0
s_w = 0
N = 0
ans = ""
move_flag = False
while odd_sum >= 2:
    # 移動先到着
    if move_flag is True and odd_flag[s_h][s_w] is True:
        move_flag = False
        (s_h, s_w) = move(s_h, s_w)
        odd_sum -= 2
    # 移動中
    elif move_flag is True and odd_flag[s_h][s_w] is False:
        if len(ans) > 0:
            ans += "\n"
        ans += str(s_h+1) + " " + str(s_w+1) + " "
        (s_h, s_w) = move(s_h, s_w)
        ans += str(s_h+1) + " " + str(s_w+1)
        N += 1
    # 移動すべきものなし
    elif move_flag is False and odd_flag[s_h][s_w] is False:
        (s_h, s_w) = move(s_h, s_w)
    # 移動元到着
    elif move_flag is False and odd_flag[s_h][s_w] is True:
        move_flag = True
        if len(ans) > 0:
            ans += "\n"
        ans += str(s_h+1) + " " + str(s_w+1) + " "
        (s_h, s_w) = move(s_h, s_w)
        ans += str(s_h+1) + " " + str(s_w+1)
        N += 1

print(N)
print(ans)



Measured memory_bytes: 13352
#include <iostream>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	int A;
	if (a == b && b != c) {
		A = 2;
	}
	else if (a == c && a != b) {
		A = 2;
	}
	else if (b == c && a != c) {
		A = 2;
	}
	else if (a == b && b == c) {
		A = 1;
	}
	else {
		A = 3;
	}

	cout << A << endl;

	return 0;
}

Measured memory_bytes: 256
N=int(input())
cnt,zero,one,two,three,four,more=0,0,0,0,0,0,0
d=0
A=list(map(int,input().split()))
B=A[:]
for i in range(N):
  while B[i]%2==0:
    if B[i]%2==0:
      B[i]=B[i]//2
      cnt=cnt+1
  if cnt==0:
    zero += 1
  elif cnt==1:
    one += 1
  elif cnt==2:
    two += 1
  elif cnt==3:
    three += 1
  elif cnt==4:
    four += 1
  else:
    more += 1
  cnt=0
#print(zero,one,two,three,four,more)
if one%2==0:
  d=0
else:
  d=1
if (zero+d)>(two+three+four+more+1):
  print("No")
else:
  print("Yes")

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

int main() {
    int n; cin >> n;
    vector<int> a;
    for (int i = 0; i < n; ++i) {
        int x; cin >> x;
        a.push_back(x);
    }
    int best = (int) 1e9;
    for (int foo = -100; foo <= 100; ++foo) {
        int cost = 0;
        for (int i = 0; i < n; ++i) cost += (foo - a[i]) * (foo - a[i]);
        best = min(best, cost);
    }
    cout << best << '\n';
    return 0;
}


Measured memory_bytes: 256
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	V alp[26];
	int n=0;
	char c;
	while((c=getchar())!='\n'){
		alp[c-'a'].push_back(n);
		n++;
	}
	REP(i, 0, 26){
		if(alp[i].size()) alp[i].push_back(n+alp[i][0]);
		else alp[i].push_back(1e9);
	}

	ll ans = 0, now = -1;
	while((c=getchar())!='\n'){
		ll next = *std::upper_bound(ALL(alp[c-'a']), now);
		if(next==1e9){
			puts("-1");
			return 0;
		}
		ans += next - now;
		now = next % n;
	}
	printf("%ld\n", ans);
	return 0;
}



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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n, y, d, m;

int main() {
   cin >> n;
   while (n--) {
      cin >> y >> m >> d;
      auto judge = [&]() -> int {
         if (y == 1000 && m == 1 && d == 1) return -1;
         int add = 20;
         if (y % 3 != 0 && m % 2 == 0) {
            add--;
         }
         return add;
      };
      if (judge() == -1) {
         cout << 0 << endl;
         continue;
      }

      auto go = [&]() {
         m++;
         if (m == 11) m = 1, d = 1 , y++;
      };

      int cnt = 0;
      cnt += judge() - d + 1;
      go();
      while (1) {
         if (y == 1000 && m == 1 && d == 1) break;
         cnt += judge();
         go();
      }
      cout << cnt << endl;
   }

   return 0;
}


Measured memory_bytes: 3092
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
import bisect as bi
import heapq 
'''
#------------------PYPY FAst I/o--------------------------------#

def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
'''
#------------------Sublime--------------------------------------#

#sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))

def find_gt(a, x):
    #'Find leftmost value greater than x'
    i = bi.bisect_right(a, x)
    if i != len(a):
        return i
    else:
        return -1


def main():
    try:
        n=I()
        l=list(In())
        d={}
        for x in l:
            if d.get(x,0)!=0:
                d[x]+=1
            else:
                d[x]=1
        
        for i in range(1,n+1):
            if d.get(i,0)!=0:
                print(d[i])
            else:
                print(0)

            
    except:
        pass
        
M = 998244353
P = 1000000007

if __name__ == '__main__':
    main()

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

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

    if ((N[0] == N[1] && N[1] == N[2]) ||
        (N[1] == N[2] && N[2] == N[3]))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N, M;
	cin >> N >> M;
	if (N == M)
		puts("Yes");
	else
		puts("No");
}


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

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

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    solve(n);
  }
  return 0;
}



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

void insert(int code);
void find(int code);

/*
A:1
C:2
G:3
T:4
 */

char dictionary[262145];

main(){

  int i,j,n,code;
  char command[7], op;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",command);
    j=0; code=0;
    while(j<=8){
      scanf("%c",&op);
      if(op=='\n') break;
      switch(op){
      case 'A':
	code+=1*pow(4,j);
	break;
      case 'C':
	code+=2*pow(4,j);
	break;
      case 'G':
	code+=3*pow(4,j);
	break;
      case 'T':
	code+=4*pow(4,j);
	break;
      default:
	j--;
      }
      j++;
    }
    if(command[0] == 'i'){ // insert
      insert(code);
    }else if(command[0] == 'f'){ // find
      find(code);
    }
  }

  return 0;

}

void insert(int code){
  dictionary[code] = 1;
}

void find(int code){
  if(dictionary[code] == 1) printf("yes\n");
  else printf("no\n");
}

Measured memory_bytes: 488
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clear(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return x * flag;
}

#define Maxn 100009
int n, a[Maxn];
LL ans;
int main() {
#ifdef Qrsikno
	freopen("AGC003_2.in", "r", stdin);
	freopen("AGC003_2.out", "w", stdout);
#endif
	n = read();
	rep(i, 1, n) a[i] = read();
	rep(i, 2, n + 1){
		int x = i - 2, y = i - 1, z = i;
		if(a[z] >= a[y] - a[x]) {
			if(a[y] < a[x]) 
				a[x] -= a[y], ans += a[y], a[y] = 0;
			else ans += a[x], a[y] -= a[x], a[x] = 0, a[z] -= a[y], ans += a[y], a[y] = 0; 
		}else{ 
			a[y] -= a[x], ans += a[x], a[x] = 0, ans += a[y] / 2, a[y] %= 2;
			if(a[z]) a[z] -= a[y], ans += a[y], a[y] = 0;
		}
		ans += a[x] / 2, a[x] %= 2;
		ans += a[y] / 2, a[y] %= 2;
	}
	rep(x, 1, n) 
		ans += a[x] / 2, a[x] %= 2;
	printf("%lld\n", ans);
	return 0;
}


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

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

using namespace std;

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

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; }

int main()
{
  ll X, Y;
  cin >> X >> Y;

  ll ans=1;
  
  for(ll i=1;X<=Y;i++)
    {
      X*=2;
      if(X<=Y)
	ans++;
    }
  cout<<ans;

  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



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

bool month(int n) {
    return n > 0 && n < 13;
}

int main() {
    int S;
    cin >> S;
    int a = (S / 100) % 100;
    int b = S % 100;
    if(month(a) && month(b)) cout << "AMBIGUOUS" << endl;
    else if(month(a)) cout << "MMYY" << endl;
    else if(month(b)) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
al=0
bo=0
 
for i in range(n):
    if i==0 or i%2==0:
        al+=a.pop(0)
    else:
        bo+=a.pop(0)
 
print(al-bo)

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<algorithm>
#define RI register int
#define CI const int&
#define int long long
using namespace std;
const int N=100005;
struct frac
{
	int x,y;
	inline frac(CI X=0,CI Y=0)
	{
		x=X; y=Y;
	}
	friend inline bool operator < (const frac& A,const frac& B)
	{
		return 1.0*A.x*B.y<1.0*A.y*B.x;
	}
	friend inline bool operator > (const frac& A,const frac& B)
	{
		return 1.0*A.x*B.y>1.0*A.y*B.x;
	}
}ans(0,1);
struct data
{
	int a,b,val;
	friend inline bool operator < (const data& A,const data& B)
	{
		return A.val<B.val;
	}
}p[N]; int pfx[N],n,sum;
inline int gcd(CI x,CI y)
{
	return y?gcd(y,x%y):x;
}
signed main()
{
	//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
	RI i; for (scanf("%lld",&n),i=1;i<=n;++i)
	scanf("%lld%lld",&p[i].a,&p[i].b),
	p[i].val=max(p[i].a,p[i].b),sum+=max(p[i].b-p[i].a,0LL);
	for (sort(p+1,p+n+1),i=1;i<=n;++i) pfx[i]=pfx[i-1]+p[i].val;
	#define calc(x) (pfx[x]-((x)>=i?p[i].val:0))
	for (i=1;i<=n;++i)
	{
		int cur=sum; if (p[i].a>p[i].b) cur+=p[i].b-p[i].a;
		int l=1,r=n,mid; while (l<=r)
		if (calc(mid=l+r>>1)<=cur) l=mid+1; else r=mid-1;
		//printf("%lld %lld\n",p[i].a,p[i].b);
		frac ret(cur-calc(l-1),p[i].b);	ret=min(ret,frac(1,1));
		ret.x+=ret.y*(l-1-(l>i)); ans=max(ans,ret);
	}
	#undef calc
	int g=gcd(ans.x,ans.y*=n); return printf("%lld %lld",ans.x/g,ans.y/g),0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int a,b; cin >> a >> b;
	cout << (b < a ? a-1: a) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int N;
  cin >> N;
  for(int i=0;i<N;i++){
    char x;
      cin >> x;
    if(x=='Y'){
    cout << "Four" << endl;
    break;}
    else if(i<N-1){continue;}
    if(i=N){
      cout << "Three" << endl;
    }
}
}

Measured memory_bytes: 256