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

LL n, p, i, j, mod;
LL ar[100], dp[50][2];

LL fun(LL i, LL sum)
{
    if(i==n){ if(sum==p) return 1;  else return 0;}
    if(dp[i][sum]!=-1) return dp[i][sum];

    LL x=0;
    x = fun(i+1,(sum+ar[i])%2);
    x += fun(i+1,sum);

 return dp[i][sum]=x;
}
int main()
{
      scanf("%lld %lld", &n, &p);

      for(i=1; i<=n; i++) scanf("%lld", &ar[i]);
      memset(dp,-1,sizeof dp);

      LL ans = fun(0,0);
      printf("%lld\n", ans);

return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    char x[1000];
    int sum;
    do {
        sum = 0;
        scanf("%s", x);
        for (int i = 0; x[i] != '\0'; i++) {
            sum += x[i] - '0';
        }
        if (sum != 0) printf("%d\n", sum);
    } while(sum != 0);
        return 0;
}



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

int main() {
  int num=753, min=999;
  string s;
  cin >> s;

  for (int i=0; i<s.size()-2; i++) {
    int dif=abs(num-stoi(s.substr(i, 3)));

    if (dif<min) min=dif;
  }

  cout << min;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

int cap = 40'0000;
int *data;
int head, tail;

void init() {
    data = new int[cap];
    head = cap / 2 - 1;
    tail = cap / 2;
}

void push(int d, int x) {
    if (d == 0) {
        data[head] = x;
        head--;
    } else {
        data[tail] = x;
        tail++;
    }
    if (head == -1 || tail == cap - 1) {
        cap *= 2;
        int new_data[cap];
        int len = tail - head - 1;
        memcpy(new_data + cap / 4, data, cap / 2);
        head += cap / 4;
        tail += cap / 4;
        //free(data);
        data = new_data;
    }
}

void randomAccess(int p) {
    cout << data[head + p + 1] << endl;
}

void pop(int d) {
    if (d == 0) {
        head++;
    } else {
        tail--;
    }
}

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

    init();

    while (Q--) {
        int q, d, x, p;
        cin >> q;
        switch (q) {
            case 0:
                cin >> d >> x;
                push(d, x);
                break;
            case 1:
                cin >> p;
                randomAccess(p);
                break;
            case 2:
                cin >> d;
                pop(d);
                break;
        }
    }
}



Measured memory_bytes: 5112
n = input()
k = int(input())
l = len(n)
dp = [[[0]*(k+1) for i in range(2)] for j in range(l+1)]
d = []
for i in range(l):
    d.append(int(n[i]))
dp[1][0][0] = 0
dp[1][0][1] = 1
dp[1][1][0] = 1
dp[1][1][1] = d[0]-1

for i in range(l):
    for small in range(2):
        for j in range(k+1):
            if j==k:
                if small==0 and d[i]==0:
                    dp[i+1][small][j] += dp[i][small][j]
                else:
                    dp[i+1][1][j] += dp[i][small][j]
            else:
                a = 10 if small else d[i]+1
                for x in range(a):
                    z=j if x==0 else j+1
                    dp[i+1][small or x<d[i]][z] += dp[i][small][j]


print(dp[l][0][k]+dp[l][1][k])

Measured memory_bytes: 40432
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&d[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(d)))

	count := 1
	for i := 0; i < n-1; i++ {
		if d[i] != d[i+1] {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
int main() {
    string s;
    int ans = 753;
    cin >> s;
    for(int i = 0; i < s.size() - 2; i++){
        string c;
        c = s.substr(i, 3);
        auto num = atoi(c.c_str());
        if(abs(753 - num) < ans) ans = abs(753 - num);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>


int main(){
	std::string str;
	std::cin >> str;
	int odd = 0, even = 0, marker = -1;
	std::vector<int> vec(str.length());
	for(int i = 0; i < str.length(); i++){
		if(str[i] == 'R' && marker == -1){
			odd = 0;
			even = 1;
			marker = i;
			continue;
		}
		if(str[i] == 'R' && str[i - 1] == 'L'){
			odd = 0;
			even = 1;
			marker = i;
			continue;
		}
		if(str[i] == 'R'){
			if((i - marker) % 2 == 1){
				odd++;
			}else{
				even++;
			}
			continue;
		}
		if(str[i] == 'L' && str[i-1] == 'R'){
			if((i - marker) % 2 == 0){
				vec[i] += even;
				vec[i-1] += odd;
			}else{
				vec[i] += odd;
				vec[i-1] += even;
			}
			marker = i;
		}
		if(str[i] == 'L'){
			if((i - marker) % 2 == 0){
				vec[marker]++;
			}else{
				vec[marker-1]++;
			}
		}
	}
	for(int i = 0; i < vec.size() - 1; i++){
		std::cout << vec[i] << " ";
	}
	std::cout << vec[vec.size()-1] << std::endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define PI acos(-1)
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define sp fixed<<setprecision
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int MOD = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        cout<<n*n<<endl;
        //cout<<"Case #"<<ti<<": ";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<cctype>
#include <fstream>
#include <time.h>
#include <iterator>





#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 REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;


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

	int X; cin >> X;
	int sum = 0;
	REP(i, X+10) {
		sum += i;
		if (sum >= X) {
			print(i);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
  ll n;cin >>n;
  vector<ll> a(n), b(n), diff_plus;
  ll sum_a =0;
  ll sum_b =0;
  ll cnt = 0;
  ll sum_minus = 0;
  for(ll i=0;i<n;++i) {
    cin >> a[i];
    sum_a += a[i];
  }
  for(ll i=0;i<n;++i) {
    cin >> b[i];
    sum_b += b[i];
    ll diff = a[i] - b[i];
    if(diff > 0) {
      diff_plus.push_back(diff);
    } else if(diff < 0) {
      ++cnt;
      sum_minus += diff;
    }
  }
  if(sum_a< sum_b){
    cout << -1 << endl;
    return 0;
  }
  sort(all(diff_plus), greater<ll>());
  for(ll i=0;i<diff_plus.size();++i){
    if(sum_minus>=0) break;
    sum_minus += diff_plus[i];
    ++cnt;
  }
  cout << cnt << endl;


  return 0;
}


Measured memory_bytes: 2428
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Aoj.ALDS.Chapter10A
{
    class Program
    {
        public static int[] dp;
        public static int Fibonacci(int n)
        {
            if (n < 0)
                throw new System.ArgumentException("");

            if (dp[n] > 0)
                return dp[n];

            if (n == 0 || n == 1)
            {
                dp[n] = 1;
                return dp[n];
            }

            dp[n] = Fibonacci(n - 2) + Fibonacci(n - 1);

            return dp[n];
        }

        public static void Solve()
        {
            int n = int.Parse(Console.ReadLine());

            dp = new int[n + 1];

            int f = Fibonacci(n);
            Console.WriteLine(f);
        }


        public static void Main()
        {
            // Console.SetIn(new System.IO.StreamReader("Aoj/AlgorithmsAndDataStructures/Input/10_DP_A_01.txt"));
            // var sw = new Stopwatch();
            // sw.Start();

            Solve();

            // Console.WriteLine("{0}ms", sw.ElapsedMilliseconds);
        }
    }
}

Measured memory_bytes: 9184
N, M = map(int, input().split())
start = []
end = []
for i in range(M):
    L, R = map(int, input().split())
    start.append(L)
    end.append(R)
start_max = max(start)
end_min = min(end)
print(max(0, end_min - start_max + 1))

Measured memory_bytes: 11016
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register
#define maxn 1200000
#define inf 0x7f7f7f7f
#define mod (ll)(1e9+7)
#pragma GCC optimize(3)
#pragma -fcrossjumping
#pragma -fdefer-pop
#pragma -fmerge-constans
#pragma -fthread-jumps
#pragma -floop-optimize
#pragma -fif-conversion
#pragma -fif-conversion2
#pragma -fdelayed-branch
#pragma -fguess-branch-probability
#pragma -fcprop-registers
#pragma -fforce-mem
#pragma -foptimize-sibling-calls
#pragma -fstrength-reduce
#pragma -fgcse
#pragma -fcse-follow-jumps
#pragma -frerun-cse-after-loop
#pragma -fdelete-null-pointer-checks
#pragma -fextensive-optimizations
#pragma -fregmove
#pragma -fschedule-insns
#pragma -fsched-interblock
#pragma -fcaller-saves
#pragma -fpeephole2
#pragma -freorder-blocks
#pragma -fstrict-aliasing
#pragma -funit-at-a-time
#pragma -falign-functions
#pragma -fcrossjumping
#pragma -finline-functions
#pragma -fweb
#define int ll
inline ll read()
{
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
inline ll print(ll x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>=10)
    {
        print(x/10);
    }
    putchar(x%10+'0');
}
ll a,b;
inline ll gcd(ll a,ll b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
ll num[maxn],tot;
inline void fj(ll x)
{
    for(rg int i=1;i*i<=x;++i)
    {
        if(x%i==0)
        {
            num[++tot]=i;
            if(i!=x/i) num[++tot]=x/i;
        }
    }
}
int prime[maxn],cnt;
int Num[maxn];//统计素数个数 
int n;
ll ans;
inline void fj1(int x)
{
    if(x==1) prime[++cnt]=1,num[cnt]=1;
    for(rg int i=2;i*i<=x;++i)
    {
        if(x%i==0)
        {
            prime[++cnt]=i;
            Num[cnt]=1;
            x/=i;
            while(x%i==0)
            {
                x/=i;
                Num[cnt]++;
            }
        }
    }
    if(x>1)//x为质数 
    {
        prime[++cnt]=x;
        num[cnt]=1;
    }
}
signed main()
{
    a=read(),b=read();
    ll c=gcd(a,b);
    fj(c);
    fj1(c);
    if(a==1||b==1) cout<<1;
    else cout<<cnt+1;
}

Measured memory_bytes: 4352
// 解説後
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

// 試合の識別子を作る関数
// a<bのときをb優先で数えたときの値を返す
inline uint32_t make_id(uint32_t a, uint32_t b, uint32_t N) noexcept {
  if (a > b) std::swap(a, b);
  const uint32_t offset = a + 1 + a * (a + 1) / 2;  // a>=bのときを数えないためのオフセット。初項1、公差1の等比数列のn=a+1までの和
  return a * N + b - offset;
}

// 全日程を完遂するには試合日程の前後関係が矛盾しなければ良い
// => 試合日程の前後関係をグラフにしたとき、閉路が存在しなければ良い
//
// 全試合の日数はそれ以前にやるべき試合がないものから順にこなしていくことで計算できる
// => 試合日程の前後関係のグラフにおいて、入次数が0の頂点を順々にグラフから切り離していく操作に相当する
// => 全試合の日数は最大経路の頂点数に等しい
int solve_E() {
  uint32_t N = 0;  // 選手の人数
  std::cin >> N;
  const uint32_t num_ids = (N - 1) + (N - 1) * (N - 2) / 2;
  const uint32_t max_id = num_ids - 1;

  // 試合日程の前後関係の有向グラフを作る
  std::unordered_map<uint32_t, std::vector<uint32_t>> graph;
  for (uint32_t i = 0; i < N; ++i) {
    uint32_t a;
    std::cin >> a;
    for (uint32_t j = 1; j <  N - 1; ++j) {
      uint32_t b;
      std::cin >> b;
      graph[make_id(i, a - 1, N)].push_back(make_id(i, b - 1, N));
      a = b;
    }
  }

  // 試合日程の前後関係のグラフの最長経路を調べる
  std::vector<uint32_t> stack;
  stack.reserve(num_ids);
  std::vector<bool> visited(num_ids);
  std::vector<bool> finished(num_ids);
  std::vector<size_t> distances(num_ids);  // idから終点までの経路長
  size_t result = 0;  // 経路の最大長
  for (uint32_t start_id = 0; start_id < num_ids; ++start_id) {
    // 頂点が訪問済みでなければ、そこからの最長経路を計算する
    if (!visited[start_id]) {
      // 深さ優先探索
      stack.push_back(start_id);
      visited[start_id] = true;
      while (true) {
        const uint32_t id = stack.back();

        // 子供を調べる
        bool all_visited = true;  // すべての子供が訪問済みかどうか
        size_t max_distance = 0;  // 子供の経路の最大長
        for (auto child : graph[id]) {
          // 未訪問でれば、それに訪問する
          if (!visited[child]) {
            stack.push_back(child);
            visited[child] = true;
            all_visited = false;
            break;
          }

          // 閉路が存在すれば、その日程は完遂できない
          if (!finished[child]) {
            std::cout << "-1";
            return 0;
          }

          // 子から終点までの最大長を計算する
          max_distance = std::max(max_distance, distances[child]);
        }

        // すべての子供に訪問済みであれば、ひとつ前に戻る
        if (all_visited) {
          stack.pop_back();
          finished[id] = true;
          distances[id] = max_distance + 1;
          if (stack.empty()) break;
        }
      }
    }

    // グラフ全体での経路の最大長を計算する
    result = std::max(result, distances[start_id]);
  }

  // 結果発表
  std::cout << result;
  return 0;
}

int main() { return solve_E(); }


Measured memory_bytes: 59556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine().split(" ")[0]);
		boolean[] hasSnack = new boolean[N];
		
		while (sc.hasNextLine()) {
			sc.nextLine();
			for (String snk : sc.nextLine().split(" ")) {
              int snki = Integer.parseInt(snk) - 1;
              if (hasSnack[snki])
              	continue;
              N--;
			  hasSnack[snki] = true;
            }
		}
		
		System.out.println(N);
	
	}

}

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



int main(){
  string S;
  cin>>S;
  int N;
  N=S.size();
  
  bool can=true;
  for(int i=0;i<(N-1)/2;i++){
    if(S.at(i)!=S.at(N-i-1)){
      can=false;
      break;
    }
  }
  for(int i=0;i<((N-1)/2)/2;i++){
    if(S.at(i)!=S.at((N-1)/2-1-i)){
      can=false;
      break;
    }
       }
  reverse(S.begin(),S.end());
  for(int i=0;i<((N-1)/2)/2;i++){
    if(S.at(i)!=S.at((N-1)/2-1-i)){
      can=false;
      break;
    }
  }

  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
    
 
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;


int main() {

  double A, B;
  cin >> A >> B;
  int min8 = 100000, max8 = 0;
  int min10 = 100000, max10 = 0;

  REP(i, 100000){
    int tmp = (int)(i * 0.08);
    if(i * 0.08 >= A && i * 0.08 < (A+1)){
      min8 = min(min8, i);
      max8 = max(max8, i);
    }
  }
  // cout << min8 << " " << max8 << endl;
  REP(i, 100000){
    int tmp = (int)(i * 0.10);
    if(tmp >= B && tmp < (B+1)){
      min10 = min(min10, i);
      max10 = max(max10, i);
    }
  }
    // cout << min10 << " " << max10 << endl;

// cout << min10 << max10 << endl;

int _min = max(min8, min10);
if(_min > max8 || _min > max10)_min = -1;

cout << _min << endl;


    
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

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


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

    int i = 1, j = (N+1)/2, count = 0;
    // 前半
    while(i < j){
        cout << i << " " << j << endl;
        ++i, --j, ++count;
        if(count == M) return 0;
    }
    // 後半
    i = (N+1)/2+1, j = (N%2 == 0)? N-1: N;
    REP(k, M){
        cout << i << " " << j << endl;
        ++i, --j, ++count;
        if(count == M) return 0;
    }

    return 0;
}

Measured memory_bytes: 3196
//abc126_b.cpp
//Sat May 25 18:50:24 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int first = n/100;
	int second = n-first*100;

	int firstflag = -1;
	if (first>=1 && first<=12){
		firstflag = 1;
	}else {
		firstflag = 0;
	}

	int secondflag = -1;
	if (second>=1 && second<=12){
		secondflag = 1;
	}else {
		secondflag = 0;
	}

	if (firstflag == 1 && secondflag == 1){
		cout << "AMBIGUOUS" << endl;
	}else if (firstflag == 0 && secondflag == 0){
		cout << "NA" << endl;
	}else if (firstflag == 0){
		cout << "YYMM" << endl;
	}else if (secondflag == 0){
		cout << "MMYY" << endl;
	}
//	printf("%.4f\n",ans);
}

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

int main(){
  int x,t;
  cin >> x >> t;
  if(x < t) cout << 0 << endl;
  else cout << x-t << endl;
}

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

int n, m, a[200100];

bool test(int x) {
	for (int i = x + 1; i <= n; i++)
		if (a[i] + a[n - i + x + 1] < m)
			return false;
	return true;
}

int main() {
	scanf("%d %d", &n, &m);
	n *= 2;
	for (int i = 1; i <= n; i++)
		scanf("%d", a + i);
	sort(a + 1, a + n + 1);
	int l = 0, r = n / 2, ans = 0;
	while (l <= r) {
		int m = (l + r) >> 1;
		if (test(m * 2)) {
			ans = m;
			r = m - 1;
		} else
			l = m + 1;
	}
	int p = ans * 2;
	ans = 0;
	
	for (int i = p + 1; i <= n; i++)
		ans = max(ans, a[i] + a[n - i + p + 1] - m);
	for (int i = 1; i <= p; i++)
		ans = max(ans, a[i] + a[p - i + 1]);
	printf("%d\n", ans);
}

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

using namespace std;
typedef long long ll;
typedef pair< ll , string > P;

int main(){
	ll h;
	ll st = 0;
	cin >> h;
	
	while( h > 1 ){
		h  = floor( h / 2);
		st++;
	}
	cout << ( long long )( 2 * (long long )pow( 2 , st ) - 1  );
}


Measured memory_bytes: 256
// 6/14 リアルタイム参加
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
    int res = -1;

    rep(i, 5) {
        int x;
        cin >> x;
        if (x == 0) res = i + 1;
    }
    cout << res << endl;
}

Measured memory_bytes: 3624
import sys
def f(a,b):
  c=b*9-9
  A=range(10)
  if b==1:x=1 if a in A else 0
  else:x=sum([f(a-e,b-1)for e in A if 0<=a-e<=c])
  return x
for n in map(int,sys.stdin):print f(n,4)

Measured memory_bytes: 4212
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

const LL rev2 = 500000004;

int N;
int Q;
int A[3145];
LL dp[3145][3145];
LL pw2 = 1;

int main() {
  scanf("%d%d", &N, &Q);
  rep(i, N) {
    scanf("%d", &A[i]);
  }

  rep(i, N) {
    rep(j, N) {
      if (A[i] < A[j]) dp[i][j]++;
    }
  }

  rep(i, Q) {
    pw2 *= 2;
    pw2 %= MOD;

    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;

    rep(j, N) {
      if (j == y) continue;
      if (j == x) continue;
      LL t = (dp[x][j] + dp[y][j]) * rev2 % MOD;
      dp[x][j] = dp[y][j] = t;
      LL s = (dp[j][x] + dp[j][y]) * rev2 % MOD;
      dp[j][x] = dp[j][y] = s;
    }
    LL u = (dp[x][y] + dp[y][x]) * rev2 % MOD;
    dp[x][y] = dp[y][x] = u;
  }

  LL ans = 0;
  rep(i, N) {
    rep(j, i) {
      ans += dp[i][j] * pw2;
      ans %= MOD;
    }
  }
  printf("%lld\n", ans);
}


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

int main() {
    int n, m, temp;
    cin >> n;
    int a[n];

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

    for (int i = 0; i < n; i++) {
        m = i;
        while (m > 0 && a[m] < a[m-1]) {
            temp = a[m];
            a[m] = a[m-1];
            a[m-1] = temp;
            m--;
        }
        for (int k = 0; k < n; k++) {
            cout << a[k];
            if (k == n-1) cout << endl;
            else cout << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
#define FOR(i, a, b) for(LL i=(LL)(a);i<(LL)(b);i++)
#define REP(i,x) for(LL i=0;i<(LL)(x);i++)
#define MOD_PRIME = 1e9 + 7;

LL sub(LL x, LL k)
{
    LL diff_one = 0;
    if(x > k)
    {
        diff_one = x - k;
    }
    else
    {
        diff_one = k - x;
    }

    if(x > diff_one)
    {
        // 1回で引く量
        LL diff2 = x - diff_one;
        // 何回連続で引けるか
        LL temp = x / diff2;
        diff_one = x - temp * diff2;
        return sub(diff_one, k);
    }
    else
    {
        return x;
    }

    return x;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // cout << fixed << setprecision(10);
    LL n, k;
    cin >> n >> k;

    cout << sub(n, k) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#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 FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

LL sum1[501][501];
LL sum2[501][501];
LL sum3[501][501];

void init() {

}

void input() {

}

// int l[200010], r[200010];

void solve() {
  int n, m, q;
  cin >> n >> m >> q;
  REP(i, 501) REP(j, 501) sum1[i][j] = 0;
  REP(i, 501) REP(j, 501) sum2[i][j] = 0;
  REP(i, 501) REP(j, 501) sum3[i][j] = 0;
  REP(i, m) {
    int l, r;
    cin >> l >> r;
    sum1[l][r]++;
  }
  REP(i, 501) FOR(j, i, 501) {
    FOR(k, i, j+1) sum2[i][j] += sum1[k][j];
  }
  REP(_, q){
    int l, r;
    cin >> l >> r;
    LL res = 0;
    FOR(i, l, r+1) res += sum2[l][i];
    cout << res << endl;
  }
}

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


Measured memory_bytes: 6784
N, M = gets.split.map(&:to_i)
Xs = gets.split.map(&:to_i)

Xs.sort!
sum = 0
diff = []

(Xs.length - 1).times do |i|
  diff.push( [Xs[i + 1] - Xs[i], i] ) 
end

diff.sort!{ |b, a| a[0] <=> b[0] }

diff = diff.slice(0, N-1)

diff.sort!{ |b, a| b[1] <=> a[1] }

#1 2    10 12 14

head = Xs[0]

diff.length.times do |i|
  
  b_i = (diff[i][1])
  
  sum += Xs[b_i] - head

  head = Xs[b_i+1]
  
end

sum += Xs.last - head

puts sum


Measured memory_bytes: 15888
#include<bits/stdc++.h>
using namespace std;
#define N 2019

int n,m;
char s[N][N];
int a[N][N];
int ans,cnt;

int main()
{
	
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		scanf("%s",&s[i]);
	
	ans=1;
	for(int i=0;i<n;i++)
	for(int j=0;j<=m;j++)
		if(j==m || s[i][j]=='#')
		{
			for(int k=j-1;k>=0 && s[i][k]=='.';k--)
				a[i][k]=cnt;
			cnt=0;
		}
		else cnt++;
		
	for(int j=0;j<m;j++)
	for(int i=0;i<=n;i++)
		if(i==n || s[i][j]=='#')
		{
			for(int k=i-1;k>=0 && s[k][j]=='.';k--)
				a[k][j]+=cnt;
			cnt=0;
		}
		else cnt++;
	
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
		ans=max(ans,a[i][j]);
	printf("%d\n",ans-1);
	
	return 0;
}

Measured memory_bytes: 20096
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int K;
  cin >> K;
  if (K < 10) {
    cout << K << endl;
    return 0;
  }
  vector<vector<int64>> v(10);
  for (int i = 1; i < 10; i++) {
    v[0].push_back(i);
  }
  debug(v);
  for (int i = 1; i < 10; i++) {
    for (int j = 0; j < v[i - 1].size(); j++) {
      int last_keta = v[i - 1][j] % 10;
      if (last_keta == 0) {
        v[i].push_back(v[i - 1][j] * 10 + 0);
        v[i].push_back(v[i - 1][j] * 10 + 1);
      } else if (last_keta == 9) {
        v[i].push_back(v[i - 1][j] * 10 + 8);
        v[i].push_back(v[i - 1][j] * 10 + 9);
      } else {
        v[i].push_back(v[i - 1][j] * 10 + last_keta - 1);
        v[i].push_back(v[i - 1][j] * 10 + last_keta);
        v[i].push_back(v[i - 1][j] * 10 + last_keta + 1);
      }
    }
  }
  int64 sum = 0;
  int keta = 0;
  int banme = 0;
  for (int i = 0; i < 10; i++) {
    sum += v[i].size();
    if (sum >= K) {
      keta = i;
      banme = v[i].size() - (sum - K) - 1;
      break;
    }
  }
  sort(v[keta].begin(), v[keta].end());
  cout << v[keta][banme] << endl;
  return 0;
}

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

int main() {
  int a,b;
  cin >>a>>b;
  char A[a][a];
  char B[b][b];
  for(int i=0;i<a;i++) cin >> A[i];
  for(int i=0;i<b;i++) cin >> B[i];
  
  for(int i=0;i<a;i++){
    for(int j=0;j<a;j++){
      bool br=false;
      for(int k=0;k<b;k++){
        for(int l=0;l<b;l++){
          if(A[i+k][j+l] != B[k][l]){
            br = true;
            break;
          }
        }
        if(br) break;
        if(k == b-1){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
from collections import Counter

def resolve():
    # 方針
    # LCMを求めたい
    #  Aを素因数分解して、素因数ごとに肩のmaxを取りに行く
    #  max同士を掛け合わせる
    # B = X / A : 逆元
    #  B = A^(p-2) , p: 素数 prime

    # たくさんの数の素因数分解
    #     (1こだけの場合。Xに対し、sqrt(X)まで順に見て割り切れなければ素数として判定)
    #  (1) 素数列挙
    #    エラトステネスの篩
    #     素数と決まった数の倍数を消していく(最初は2)
    #     次の数にいく。消されてなければ素数。その数の倍数を消していく。(2乗となる倍数から開始すれば良い)　-> O(NloglogN)
    #     
    #  (2) 素因数分解
    #     上記の操作の時、何で割られたかメモしていく。すでに書かれているものは上書きしない。
    #     例:36. 36 ->2-> 18 ->2-> 9 ->3-> 3(prime) = 2x2x3x3 (sorted)
    #    => 素因数分解の完了
    # 
    MOD = 10**9 + 7
    N = int(input())
    A = list(map(int, input().split()))

    # 素数列挙 & 割った数の計算
    MX = int(10**6)
    L = [0] * (MX + 1)
    L[0] = -1
    L[1] = -1
    primes = []

    for i in range(2, MX+1):
        if L[i]:
            continue
        primes.append(i)
        L[i] = i
        for j in range(i*i, MX+1, i):
            if L[j] == 0:
                L[j] = i

    def factor(x: int):
        res = []
        while x != 1:
            prime = L[x] if L[x] != 0 else x
            res.append(prime)
            x /= prime
            x = int(x)
        return res

    max_e = {}
    for a in A:
        a = Counter(factor(a))
        for key, v in a.items():
            if not key in max_e:
                max_e[key] = v
            else:
                if v > max_e[key]:
                    max_e[key] = v
    # print(max_e)

    def modinv(a, mod=10**9+7):
        return pow(a, mod-2, mod)

    lcm = 1
    for key, v in max_e.items():
        lcm *= key ** v

    # print(max_e)
    # print(lcm)
    lcm %= MOD
    # print(lcm)

    ans = 0
    for i in range(N):
        b = lcm * modinv(A[i]) 
        ans += b

    print(int(ans % MOD))


def resolve_ref():
    from fractions import gcd
    
    mod = 10 ** 9 + 7
    
    N = int(input())
    A = list(map(int, input().split()))
    
    L = 1
    for a in A:
        L *= a // gcd(L, a)
    
    print(L)
    L %= mod
    print(L)
    
    print(sum(L * pow(a, mod - 2, mod) for a in A) % mod)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 15440
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
  int n,sum=0,ans=0; cin>>n;
  string s; cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='I'){
      sum++;
    }
    else{
      sum--;
    }
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int cnt[10800];
int main(){  
	int n, q, m, d;
	while(cin >> n >> q, n | q){
		fill(cnt, cnt + 10800, 0);
		int res = 0;
		int mx = 0;
		for(int i = 0;i < n;i++){
			cin >> m;
			for(int j = 0;j < m;j++){
				cin >> d;
				cnt[d]++;
				mx = max(mx, cnt[d]);
			}
		}
		for(int i = 10799;i >= 0;i--){
			if(mx >= q && cnt[i] == mx)res = i;
		}
		cout << res << endl;
	}
	return 0;
}

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

int main(){
	int K,A,B;

	cin >> K >> A >> B;

	int flg = 0;
	for(int i = A; i <= B; i++){
		if(i % K == 0){
			flg++;
			break;
		}

	}
	if(flg == 1)
		cout << "OK" << endl;
	else
		cout << "NG" << endl;
	
}

Measured memory_bytes: 3632
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main()
{
   int num[3] = { 0, 0, 0 };
   
   cin >> num[0] >> num[1] >> num[2];

   for( int i = 0;  i < 2; i++ )
   {
      for( int j = 1; j < 3; j++ )
      {
         if( num[ i ] >= num[ j ] )
         {
            int swap = num[ i ];
            num[ i ] = num[ j ];
            num[ j ] = swap;
         }
      }
   }
   cout << num[0] << " " << num[1] << " " << num[2] << endl;
   return 0;
}

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

#define INF INT_MAX
#define ll long long

using namespace std;

int main(){
	int kk,s;
	cin >> kk >> s;
	int ans = 0;
	for(int i = 0;i <= kk;i++){
		for(int j = i;j <= kk;j++){
			for(int k = j;k <= kk;k++){
				if(i+j+k == s && (i == j && j == k )) ans++;
				else if(i+j+k == s && (i != j && j != k && i != k )) ans += 6;
				else if(i+j+k == s) ans += 3;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#define debug_interval ' '
#define dump_interval ','
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
 
//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


//}
int n,m,ans=LLONG_MAX,t,c;

main(){
	cin>>n>>m;
	rep(i,n){
		cin>>c>>t;
		if(t<=m)ans=min(ans,c);
	}
	if(ans==LLONG_MAX)cout<<"TLE"<<endl;
	else cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main () {
    int in;
    scanf ("%d", &in);
    char inp[in];
    scanf("%s", inp);
    
    if (in % 2!=0)
	{
		printf("No");
		return 0;
	}
	
	for (int i=0;i<in/2;i++)
	{
		if(inp[i] != inp[in/2+i])
		{
			printf("No");
			return 0;
		}
	}
	printf("Yes");
    return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <bitset>
using namespace std;
using ll = long long;

const int N = 5 * (int)1e4;
struct Change {
	int tx;
	int ty;
	int i;
};

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

	int n, m, t;
	cin >> n >> m >> t;

	vector<pair<int, int>> evs(m);
	for (auto& pr : evs) {
		cin >> pr.first >> pr.second;
		--pr.first;
		--pr.second;
	}

	if (t == 1) {
		// Uniforming
		vector<bitset<N>> bits(n);
		for (int i = 0; i < n; ++i) bits[i][i] = 1;
		for (int i = 0; i < m; ++i) {
			int a, b;
			tie(a, b) = evs[i];
			bits[a] |= bits[b];
			bits[b] |= bits[a];
		}
		int s = -1;
		for (int i = 0; i < n; ++i) {
			if (bits[i].count() == n) s = i;
		}
		if (s == -1) {
			cout << -1 << '\n';
		} else {
			bits[s] &= ~bits[s];
			bits[s][s] = 1;

			string res(m, '_');
			for (int i = m-1; i >= 0; --i) {
				int a, b;
				tie(a, b) = evs[i];
				if (bits[s][a]) {
					res[i] = '^';
					bits[s][b] = 1;
				} else if (bits[s][b]) {
					res[i] = 'v';
					bits[s][a] = 1;
				} else {
					res[i] = '^';
				}
			}
			cout << res << '\n';
		}
	} else {
		// Non-uniforming
		// DP: does there exist an assignment that has both wire x and wire y active at this point
		// Initially everything is possible, and every wire removes at most one possibility,
		// but could add new ones. Maintain what is NOT POSSIBLE

		vector<bitset<N>> bits(n);
		for (int i = 0; i < n; ++i) bits[i][i] = 1;

		vector<Change> pre;
		for (int j = 0; j < m; ++j) {
			int a, b;
			tie(a, b) = evs[j];
			bits[a][b] = 1;
			bits[b][a] = 1;

			bitset<N> can = bits[a] ^ bits[b];
			for (int i = can._Find_first(); i < N; i = can._Find_next(i)) {
				if (bits[a][i] == 1) {
					pre.push_back({a, i, j});
					bits[a][i] = 0;
					bits[i][a] = 0;
				} else {
					pre.push_back({b, i, j});
					bits[b][i] = 0;
					bits[i][b] = 0;
				}
			}
		}
		int x = -1;
		int y = -1;
		for (int a = 0; a < n; ++a) {
			int b = (~bits[a])._Find_first();
			if (b < n) {
				x = a;
				y = b;
			}
		}
		if (x == -1) {
			cout << -1 << '\n';
		} else {
			string res(m, '_');
			for (int i = m-1; i >= 0; --i) {
				int a, b;
				tie(a, b) = evs[i];

				// Make no change to positions unless necessary
				if (a == x || a == y) res[i] = '^';
				else if (b == x || b == y) res[i] = 'v';
				else res[i] = '^';

				// Check if change to positions is necessary
				while(! pre.empty() && pre.back().i == i) {
					auto ch = pre.back();
					pre.pop_back();
					
					if (ch.tx == y && ch.ty == x) swap(x, y);
					if (ch.tx == x && ch.ty == y) {
						if (x == a) {
							res[i] = '^';
							x = b;
						} else {
							res[i] = 'v';
							x = a;
						}
					}
				}
			}
			cout << res << '\n';
		}
	}
}


Measured memory_bytes: 308216
import sys
input = sys.stdin.readline
N = int(input())
li = [0] * N
for i in range(N) :
    p = int(input())
    li[i] = p
li.sort()
sum = 0
for i in range(N) :
    sum+=li[i]
    if i == N-1 :
        sum+= li[i]//2
        sum-= li[i]
print(sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int N;
string S[1000010];
vector<int> rv;
vector<P> rl;
map<int, deque<int>> idx;

struct segtree {
    int size;
    vector<int> node;
    
    segtree(int n) {
        size = 1;
        while (size<n) size *= 2;
        node.resize(2*size-1);
        fill(node.begin(), node.end(), -1000000);
    }
    
    void update(int k, int a) {
        k += size-1;
        node[k] = a;
        while (k>0) {
            k = (k-1)/2;
            node[k] = max(node[2*k+1], node[2*k+2]);
        }
    }
    
    int query(int a, int b, int k, int l, int r) {
        if (r<=a || b<=l) return -1000000;
        if (a<=l && r<=b) return node[k];
        else {
            int vl = query(a, b, 2*k+1, l, (l+r)/2);
            int vr = query(a, b, 2*k+2, (l+r)/2, r);
            return max(vl, vr);
        }
    }
    
    int get(int a, int b) {
        return query(a, b, 0, 0, size);
    }
};

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) cin >> S[i];
    rep(i, N) {
        int l = 0;
        int r = 0;
        rep(j, S[i].size()) {
            if (S[i][j]=='(') l++;
            else {
                if (l>0) l--;
                else r++;
            }
        }
        //cout << r << " " << l << endl;
        rl.pb(P(r, l));
        //cout << r << " " << l-r << endl;
    }
    sort(rl.begin(), rl.end());
    segtree st(N);
    rep(i, N) st.update(i, rl[i].second);
    rep(i, N) idx[rl[i].second].pb(i);
    rep(i, N) rv.pb(rl[i].first);
    
    int bal = 0;
    rep(i, N) {
        int j = upper_bound(rv.begin(), rv.end(), bal)-rv.begin();
        int M = st.get(0, j);
        if (M==-1000000) {
            cout << "No" << endl;
            exit(0);
        }
        int k = idx[M].front();
        //cout << j << endl;
        idx[M].pop_front();
        st.update(k, -1000000);
        bal -= rl[k].first;
        bal += rl[k].second;
        //cout << bal << endl;
    }
    
    if (bal==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 62536
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    
    ll ans= max(a*c,b*d);
    ans = max(ans, a*d);
    ans=max(ans,b*c);
    
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



int N;
int A[101010];
//-----------------------------------------------------------------
int main() {
	cin >> N;
	rep(i, 0, N) scanf("%d", &A[i]);

	int odd = 0, even = 0;
	rep(i, 0, N) {
		if (A[i] % 2)
			odd++;
		else
			even++;
	}

	if (odd % 2 == 0)
		printf("YES\n");
	else
		printf("NO\n");
}

Measured memory_bytes: 640
use v5.18; # strict say state
use warnings;
use List::Util qw(max min sum);

chomp (my ($r1, $g1, $b1, $n) = split / /, <STDIN>);
my $ans = 0;
my $r = max($r1, $g1, $b1);
my $b = min($r1, $g1, $b1);
my $g = sum($r1, $g1, $b1) - $r - $b;
for my $i (0..$n) {
  last if $r * $i > $n;
  for my $j (0..$n) {
    last if $r * $i + $g * $j > $n;
    my $c = $n - $r * $i - $g * $j;
    $ans++ if $c % $b == 0 && $c <= $n * $b;
  }
}
say $ans;

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

int main(){
	char s[101];
	ll k;
	int res =0,i=0,j=0;
	bool flag=true;
	cin>>s>>k;
	//cout<<"11"<<endl;
	while(flag){
		if(s[i] != '1'){
			res = s[i]-'0';
			flag = false;
			i++;
		}else{
			i++;
		}
	}
	if(i>strlen(s)){
		cout<<"1"<<endl;
	}else{
		if(k<i){
			cout<<"1"<<endl;
		}else{
			cout<<res<<endl;
		}
	}


}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  vector<int> a(m + 1);
  vector<int> b(m + 1);
  vector<ll> c(m + 1);

  REP(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--; c[i] = -c[i];
  }

  vector<ll> dist(n + 1, LLINF);
  dist[0] = 0;

  REP(i, n - 1) {
    REP(j, m) {
      if(dist[a[j]] == LLINF) continue;
      if(dist[b[j]] > dist[a[j]] + c[j]) {
        dist[b[j]] = dist[a[j]] + c[j];
      }
    }
  }

  ll ans = dist[n - 1];

  vector<bool> negative(n + 1, false);

  REP(i, n) {
    REP(j, m) {
      if(dist[a[j]] == LLINF) continue;

      if (dist[b[j]] > dist[a[j]] + c[j]) {
        dist[b[j]] = dist[a[j]] + c[j];
        negative[b[j]] = true;
      }

      if (negative[a[j]] == true) {
        negative[b[j]] = true;
      }
    }
  }

  if(negative[n - 1]) cout << "inf" << endl;
  else cout << -ans << endl;
}


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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);

	string S , T ;
	cin >> S >> T ;
	map<char,char> Trans;
	int n = S.size();

	rep(i,n){
		if(!Trans.count(S[i])){
			Trans[S[i]] = T[i];
		}else { // 既にそれを keyとするのが存在していて、値が変わるのはダメ
			char ever = Trans[S[i]];
			if(ever != T[i]){//移動先が違うものっていうのは
				coN();
				return 0;
			}
		}
	}

	map<char,char> RevTrans;

	rep(i,n){
		if(!RevTrans.count(T[i])){
			RevTrans[T[i]] = S[i];
		}else { // 既にそれを keyとするのが存在していて、値が変わるのはダメ
			char ever = RevTrans[T[i]];
			if(ever != S[i]){//移動先が違うものっていうのは
				coN();
				return 0;
			}
		}
	}
	coY();
}


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

int main(){
  string s;
  cin >> s;
  
  int counter = 0;
  if(s[0]=='1') counter++;
  if(s[1]=='1') counter++;
  if(s[2]=='1') counter++;
  
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n,k;
    cin>>n>>k;

    int cnt;
    for(int i=0;i<n;i++){
        int h;
        cin>>h;

        if(h>=k)
            cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}  




Measured memory_bytes: 256
#include<cstdio>
#include<vector>
std::vector<char>s;
int l,cur=0;char c;
int main()
{       
        s.push_back(' ');
        while(scanf("%c",&c)==1){if(c>='a' && c<='z') s.push_back(c); else break;}
        scanf("%d",&l);
        int siz=s.size();
        for(int i=1;i<siz;i+=l)
                printf("%c",s[i]);
        return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
vint G[111111];

int latte[111111];
int ma=0;
void dfs(int v,int p){
    vint lis;
    for(auto u:G[v]){
        if(u==p)continue;
        dfs(u,v);
        lis.pb(latte[u]);
        chmax(latte[v],latte[u]);
    }
    sort(all(lis));
    reverse(all(lis));

    if(G[v].size()==2){
        if(p==-1){
            chmax(ma,latte[G[v][0]]+latte[G[v][1]]+1);
        }
        else{
            latte[v]++;
        }
    }
    if(lis.size()>=2){
        chmax(ma,lis[0]+lis[1]);
    }
}

signed main(){
    cin>>N;
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);G[b].pb(a);
    }

    dfs(0,-1);
    chmax(ma,latte[0]);
    rep(i,N)if(G[i].size()==1)ma++;
    cout<<ma<<endl;
    return 0;
}


Measured memory_bytes: 7296