akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 20001
#define L 10000



int n1=0,n2=0,ttp;

struct Node{
  int sum;
  int area;
};

void push(int *p, int n)
{
  n1=n1+1;
  p[n1]=n;
}

void push1(struct Node *p, int x,int y)
{
  int i,res=0;

  if(p[n2].sum<y){
    n2=n2+1;
    p[n2].sum=y;
    p[n2].area=x-y;
  }

  else {
    p[n2].area += x-y;
    res = n2;
    for(i=n2-1; i>=1; i--){
      if(p[i].sum > y){
	p[n2].area += p[i].area;
	res = i;
      }
    }
    p[res].area = p[n2].area;
    p[res].sum = p[n2].sum;
    n2 = res;
  }
}

int empty(){
  if(n1==0) return 1;
  else return 0;
}

int pop(int *a)
{
  if(empty()==1) return -1;
  else {
    n1 = n1-1;
    return a[n1+1];
  }
}

int main()
{

  int i,j,a,n,r,str1[N];

  char sank[N];

  struct Node A[L];

  A[0].sum = -1;
  scanf("%s",sank);

  for(i=0; ; i++){
    if(sank[i-1]=='/' && sank[i]!='/')ttp=r;

    if(sank[i]=='\\')push(str1,i);

    else if(sank[i]=='/'){
      r=pop(str1);
      if(r!=-1)push1(A,i,r);
    }

    if(sank[i]=='\0')break;
  }

  for(j=1; j<=n2; j++)a+=A[j].area;

  printf("%d\n",a);

  if(n2==0)printf("%d",n2);

  else {
    printf("%d ",n2);
    for(j=1; j<=n2; j++){
      printf("%d",A[j].area);
      if(j!=n2)printf(" ");
    }
  }

  printf("\n");

  return 0;
}



Measured memory_bytes: 2096
n,k,q = map(int,input().split())
a = [0]*(n+1)
for _ in range(q):
    b = int(input())
    a[b] += 1
for i in range(1,n+1):
    if k-(q-a[i])<=0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 4680
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int N = fs.nextInt();
        List<Integer> li = new ArrayList<>();

        for (int i = 0; i < N; ++i) {
            li.add(fs.nextInt());
        }
        Collections.sort(li);

        int ans = Integer.MAX_VALUE;
        int left_most = li.get(0);
        int right_most = li.get(li.size()-1);
        for (int i = left_most; i <= right_most; ++i) {
            int tmp = 0;
            for (int j = 0; j < li.size(); ++j) {
                tmp += (li.get(j) - i) * (li.get(j) - i);
            }
            ans = Math.min(ans, tmp);
        }

        System.out.println(ans);
    }
}

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

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

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

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

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

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

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




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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        long[] h = new long[n];
        for (int i = 0; i < n; i++) {
            h[i] = Long.parseLong(sc.next());
        }
        long ans = Long.MAX_VALUE;
        Arrays.sort(h);
        for (int i = 0; i <= n - k; i++) {
            ans = Math.min(ans, h[k - 1 + i] - h[i]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 48100
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;


string[] operators = ["=","(", ")", "+", "-", "*", "/"];
bool isOperator(string s) {
	return operators.canFind(s);
}
int priority(string op) {
	int i = 0;
	while(operators[i] != op)
		++i;
	return (i+1)/2;
}

string nextToken(ref string s) {
	string t = "";
	while(s[0].isDigit()) {
		t ~= s[0];
		s.popFrontN(1);
	}
	if(t == "") {
		t ~= s[0];
		s.popFrontN(1);
	}
	return t;
}

int apply(string op, int l, int r) {
	switch(op){
		case "+":
			return l+r;
		case "-":
			return l-r;
		case "*":
			return l*r;
		case "/":
			return l/r;
		default:
			return 0;
	}
}

void apply(string op, ref int[] vstack) {
	auto r = vstack.back;
	vstack.popBackN(1);
	auto l = vstack.back;
	vstack.popBackN(1);
	vstack ~= apply(op, l, r);
}

int calc(string s) {
	int[] vstack;
	string[] opstack;
	while(!s.empty()) {
		auto t = nextToken(s);
		if(!t.isOperator()) {
			vstack ~= to!int(t);
		} else {
			if(opstack.empty || t == "(" || t.priority() > opstack.back.priority())
				opstack ~= t;
			else {
				auto op = opstack.back;
				opstack.popBackN(1);
				if(op == "(") {
					continue;
				}
				apply(op, vstack);
				s = t~s;
			}
		}
	}
	return vstack.front;
}
void main() {
	int n = to!int(readln().strip());
	foreach(i; 0..n) {
		auto s = readln().strip();
		writeln(calc(s));
	}
}

Measured memory_bytes: 1084
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = s[0];
            int b = s[1];
            int c = s[2];

            WriteLine(c- (a - b) >= 0 ? c - (a - b):0);
        }
    }
}


Measured memory_bytes: 13268
import math
import queue

mod = 1e9+7

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a):
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def main():
    s = input()
    if s=="Sunny":
        print("Cloudy")
    elif s=="Cloudy":
        print("Rainy")
    else:
        print("Sunny")
    return

if __name__ == '__main__':
    main()

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

using namespace std;

#define ge getchar()
#define Re read()

inline int read() {
	int x; scanf("%d", &x); return x;
}

int main() {
	int n = Re, m = Re, A = Re, B = Re;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++)
			putchar(48 + ((i <= B && j <= A) || (i > B && j > A)));
		putchar('\n');
	}
	return 0;
}


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

int bubbleSort(int A[], int N) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = N - 1; j >= i + 1; j--) {
			if (A[j] < A[j - 1]) {
				swap(A[j], A[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main() {
	int A[100], N, sw;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sw = bubbleSort(A, N);

	for (int i = 0; i < N; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
}


Measured memory_bytes: 3080
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define eps 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



char a, b;

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

  int a_num = a - '0';
  int b_num = b - '0';

  string ans = "";

  if (a_num < b_num) {
    Rep(i, b_num) ans += a;
    cout << ans << "\n";
  } else {
    Rep(i, a_num) ans += b;
    cout << ans << "\n";
  }
}

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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int N = 110, W = 1e5 + 5;
ll dp[N][W], cost[N], profit[N];
int n, w;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> w;
    for (int i = 1; i <= n; i++) cin >> cost[i] >> profit[i];
    for (int i = 0; i <= w; i++) dp[0][i] = 0;
    for (int i = 0; i <= n; i++) dp[i][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= w; j++) {
            if (cost[i] > j) dp[i][j] = dp[i - 1][j];
            else {
                dp[i][j] = max(dp[i - 1][j], profit[i] + dp[i - 1][j - cost[i]]);
            }
        }
    }
    cout << dp[n][w];
    
    return 0;
}


Measured memory_bytes: 80128
#include <iostream>
#include <cmath>
#include <string.h>
using namespace std;

int main(void){
  char KUPC[301];
  int cnt1=0,cnt2=0,cnt3=0,cnt4=0,ans;

  cin >> KUPC;
  for( int i = 0 ; i < strlen(KUPC) ; i++ ){   
    if( KUPC[i] == 'K') cnt1++;
    else if(KUPC[i] == 'U') cnt2++;
    else if(KUPC[i] == 'P') cnt3++; 
    else if(KUPC[i] == 'C') cnt4++;

  }

  ans = min( cnt1 , min( cnt2 , min( cnt3 , cnt4 ) ) );
 
  cout << ans << endl;

  return 0;
}

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

int main(){
    string S;
    cin >> S;
    int flag=0;
    map<char,int> m;
    for(int i=0;i<4;i++)m[S[i]]++;
    for(auto p : m)flag++;
    if(flag==2)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
int H, W, L, P, bit[4009]; bool used[4009][4009]; int lx[4009][4009], rx[4009][4009];
void add(int p, int x) {
	p++;
	while (p <= 4009) { bit[p] += x; p += (p&-p); }
}
int sum(int p) {
	int s = 0; p++;
	while (p >= 1) { s += bit[p]; p -= (p&-p); }
	return s;
}
int main() {
	cin >> H >> W >> L >> P;
	for (int i = 0; i < P; i++) { int a, b; cin >> a >> b; used[a][b] = true; }
	for (int i = 0; i < 4009; i++) { for (int j = 0; j < 4009; j++) { lx[i][j] = 999999; rx[i][j] = 999999; } }
	for (int i = 1; i <= H; i++) {
		int s = 0;
		for (int j = 1; j <= W; j++) {
			if (used[i][j] == true)s = 0; else s++;
			rx[i][j] = min(rx[i][j], s);
		}
		s = 0;
		for (int j = W; j >= 1; j--) {
			if (used[i][j] == true)s = 0; else s++;
			lx[i][j] = min(lx[i][j], s);
		}
	}
	for (int i = 1; i <= W; i++) {
		int s = 0;
		for (int j = 1; j <= H; j++) {
			if (used[j][i] == true)s = 0; else s++;
			rx[j][i] = min(rx[j][i], s);
		}
		s = 0;
		for (int j = H; j >= 1; j--) {
			if (used[j][i] == true)s = 0; else s++;
			lx[j][i] = min(lx[j][i], s);
		}
	}
	int Z = max(H, W); long long ans = 0;
	for (int i = -Z; i <= Z; i++) {
		vector<pair<int, int>>V;
		for (int j = 1; j <= H; j++) {
			int cx = j, cy = j + i; if (cy <= 0 || cy > W)continue;
			V.push_back(make_pair(cx, cy));
		}
		if (V.size() < L)continue;
		vector<pair<int, int>>U;
		for (int j = 0; j < V.size(); j++) {
			U.push_back(make_pair(rx[V[j].first][V[j].second] - j, j));
		}
		sort(U.begin(), U.end(), greater<pair<int, int>>());
		int cx = 0;
		for (int j = 0; j < 4009; j++)bit[j] = 0;
		for (int j = 0; j < V.size(); j++) {
			while (cx < U.size() && U[cx].first >= -j) { add(U[cx].second, 1); cx++; }
			int l = j + L - 1, r = j + lx[V[j].first][V[j].second] - 1;
			if (l > r)continue;
			ans += sum(r) - sum(l - 1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 143396
def main():
    
    n = int(input())

    p_list = list(map(int, input().split()))
    q_list = list(map(int, input().split()))

    head = [0,1,2,6,24,120,720,5040,40320]

    p_ = 0
    q_ = 0
    for i in range(n):
        #print(sorted(p_list[(i):]).index(p_list[i]))
        p_ += (head[(n)-(i+1)])* (sorted(p_list[(i):]).index(p_list[i]) )
        #print(p_)

        #print(sorted(q_list[(i):]).index(q_list[i]))
        q_ += (head[(n)-(i+1)])* (sorted(q_list[(i):]).index(q_list[i]) )
        #print(q_)

        #print(p_list)
        #print('###############')

    print(abs(p_-q_))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <tuple>
using namespace std;
template<typename Type>
class RMQ {
private:
	int size_; std::vector<Type> dat;
public:
	RMQ() : size_(0), dat(std::vector<Type>()) {};
	RMQ(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max());
	}
	template<class T>
	RMQ(T begin_, T end_) {
		int n = end_ - begin_;
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (int i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(int i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[i << 1 | 1]);
		}
	}
	inline Type query(int l, int r) {
		Type ret = std::numeric_limits<Type>::max();
		l += size_; r += size_;
		while (l != r) {
			if (l & 1) ret = std::min(ret, dat[l++]); l >>= 1;
			if (r & 1) ret = std::min(ret, dat[--r]); r >>= 1;
		}
		return ret;
	}
};
long long n, a[200009], s[200009], dp[200009], maxn = 0;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> s[i]; if (i == 1)dp[i] = s[i]; else dp[i] = dp[i - 1] + (s[i] - (a[i] - a[i - 1]));
	}
	RMQ<long long>X(n + 1);
	for (int i = 1; i <= n; i++)X.update(i, -dp[i]);
	for (int i = 1; i <= n; i++) {
		maxn = max(maxn, (s[i] - dp[i]) - X.query(i, n + 1));
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 9088
#include <stdio.h>
#define rep(i,l,r) for((i)=(l);(i)<(r);(i)++)
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>(0)?(a):-(a))
int main(){
    long long n,i,X,Y,H,j=0,flag=1;
    scanf("%lld",&n);
    long long x[n],y[n],h[n];
    rep(i,0,n) scanf("%lld%lld%lld",&x[i],&y[i],&h[i]);
    rep(X,0,101){
        rep(Y,0,101){
            while(!h[j])j++;
            H=h[j]+abs(X-x[j])+abs(Y-y[j]);
            rep(i,0,n){
                if(h[i]!=max(H-abs(X-x[i])-abs(Y-y[i]),0))flag=0;
                else continue;
            }
            if(flag){
                printf("%lld %lld %lld",X,Y,H);
                return 0;
            }
            flag=1;
        }
    }
}

Measured memory_bytes: 128
// https://qiita.com/drken/items/dc53c683d6de8aeacf5a#a-%E5%95%8F%E9%A1%8C---frog-1
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}

int main() {
  int N; cin >> N;
  vector<int> a(N), b(N), c(N);
  REP(i, N) {
    cin >> a[i] >> b[i] >> c[i];
  }

  // vector<vector<int>> dp(100010, vector<int>(3));
  ll dp[100010][3];
  REP(i, 100010) {
    REP(k, 3) {
      dp[i][k] = 0; // 最大値を求めたいので、初期値は3を入れる
    }
  }

  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;

  for(int i = 1; i <= N; ++i) {
    chmax(dp[i][0], dp[i - 1][1] + a[i - 1]);
    chmax(dp[i][0], dp[i - 1][2] + a[i - 1]);
    chmax(dp[i][1], dp[i - 1][0] + b[i - 1]);
    chmax(dp[i][1], dp[i - 1][2] + b[i - 1]);
    chmax(dp[i][2], dp[i - 1][0] + c[i - 1]);
    chmax(dp[i][2], dp[i - 1][1] + c[i - 1]);
  }

  ll max_num = 0;
  max_num = max(dp[N][0], dp[N][1]);
  max_num = max(max_num, dp[N][2]);
  cout << max_num << endl;
}

Measured memory_bytes: 3712
S = input()     # 入力文字列 S
count = 0       # カウンタ
max_r = 0       # 雨の日が連続する回数

# 文字列 Sを一文字ずつループ
for moji in S:
    if moji == "R":
        count += 1
        if max_r < count:
            max_r = count
    else:
        count = 0
print(max_r)

Measured memory_bytes: 9096
// AOJ 2190: Angel Stairs
// 2017.12.10

#include <stdio.h>
#include <string.h>

int n, m;
char t[50002], s[50002];
char tr['G'+1]['#'+1];
char buf[150005], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int check(int k)
{
	int i, j, x, nx, f;

    for (i = 0; i < m; i++) {
		if (k > n-1) return 0;
        x = s[i], f = 0;
        for (j = -1; j <= 1; j++) {
			nx = t[k] + j;
			if (nx < 0) nx += 12;
			else if (nx >= 12) nx -= 12;

            if (x == nx) {
                f = 1, k += j;
                if (j >= 0) k++;
                break;
            }
        }
        if (k < 0 || !f) return 0;
    }
    return k == n;
}

int main()
{
	int cno, i, a, b;

	tr['C'][0] = 0, tr['C']['#'] = 1, tr['D'][0] = 2, tr['D']['#'] = 3;
	tr['E'][0] = 4, tr['F'][0] = 5, tr['F']['#'] = 6;
	tr['G'][0] = 7, tr['G']['#'] = 8, tr['A'][0] = 9, tr['A']['#'] = 10;
    tr['B'][0] = 11;

    fgets(p=buf, 10, stdin), cno = getint();
	while (cno--) {
		fgets(p=buf, 20, stdin);
		n = getint(), m = getint();

		fgets(p=buf, sizeof(buf), stdin);
		for (i = n-1; i >= 0; i--) {
			a = *p++;
			b = *p++;
			if (b == '#') p++; else b = 0;
			t[i] = tr[a][b];
		}

		fgets(p=buf, sizeof(buf), stdin);
		for (i = m-1; i >= 0; i--) {
			a = *p++;
			b = *p++;
			if (b == '#') p++; else b = 0;
			s[i] = tr[a][b];
		}
		puts(check(0) || check(1) ? "Yes" : "No");
	}
	return 0;
}

Measured memory_bytes: 1808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
struct node{int v,k;}a[N],b[N];
int n,na,nb;
ll ans;
bool operator<(node a,node b){return a.k<b.k;}	
priority_queue<int,vector<int>,greater<int> >q;
int main()
{
	int T;scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		ans=0,na=0,nb=0;
		for(int i=1;i<=n;i++)
		{
			int k,l,r;scanf("%d%d%d",&k,&l,&r);
			if(l>r)ans+=r,a[++na]=(node){l-r,k};
			else ans+=l,b[++nb]=(node){r-l,n-k};
		}
		sort(a+1,a+na+1),sort(b+1,b+nb+1);
		for(int i=1;i<=na;i++)
		if(a[i].k)
		{
			if(q.size()<a[i].k)q.push(a[i].v);
			else if(q.size()==a[i].k&&a[i].v>q.top())q.pop(),q.push(a[i].v);
		}
		while(!q.empty())ans+=q.top(),q.pop();
		for(int i=1;i<=nb;i++)
		if(b[i].k)
		{
			if(q.size()<b[i].k)q.push(b[i].v);
			else if(q.size()==b[i].k&&b[i].v>q.top())q.pop(),q.push(b[i].v);
		}
		while(!q.empty())ans+=q.top(),q.pop();
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 5428
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, H: "List[int]"):
    flag = True
    for i in range(0, N-1):
        if H[N-1-i-1] <= H[N-1-i]:
            continue
        elif H[N-1-i-1] == H[N-1-i] + 1:
            H[N-1-i-1] -= 1
            continue
        else:
            flag = False
            break
    if flag==True:
        print('Yes')
    else:
        print('No')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15876
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

typedef complex<double> P;
inline double inp(const P& a, const P& b) {
  return (conj(a)*b).real();
}

P vs[105];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    int x, y;
    scanf("%d%d", &x, &y);
    vs[i] = P(x, y);
  }

  vector<P> cands;
  REP(i, n) {
    if(abs(vs[i]) > 0) {
      cands.push_back(vs[i]);
      REP(j, i) {
        cands.push_back(vs[i] + vs[j]);
      }
    }
  }
  double res = 0;
  for(P d : cands) {
    P cur(0, 0);
    REP(i, n) {
      if(inp(d, vs[i]) > 0) {
        cur += vs[i];
      }
    }
    res = max(res, abs(cur));
  }
  printf("%.15f\n", res);
  return 0;
}


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

const int INF = 2000000000;
const int N_MAX = 100100;

int main() {
    int n; cin >> n;
    vector<int> A(N_MAX), B(N_MAX), C(N_MAX);
    for (int i = 0; i < n; i++) {
        cin >> A[i] >> B[i] >> C[i];
    }

    // dp[i][j]: i日目にjをやった時の幸福度
    // j: 0 => A, 1 => B, 2 => C
    int dp[N_MAX][3] = {};

    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = max(dp[i][1] + B[i], dp[i][2] + C[i]);
        dp[i + 1][1] = max(dp[i][0] + A[i], dp[i][2] + C[i]);
        dp[i + 1][2] = max(dp[i][0] + A[i], dp[i][1] + B[i]);
    }

    int ans;
    ans = max( {dp[n][0], dp[n][1], dp[n][2]} );

    cout << ans << endl;

    return 0;
}


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

int main(){
    vector<int> p;
    bool nonp[300001] = {};

    p.push_back(6);
    for(int i = 12; i < 300001; i += 6) nonp[i] = true;

    for(int i = 1; 7*i+1 < 300001; i++){
        if(!nonp[7*i+1]){
            p.push_back(7*i+1);
            for(int j = 14*i+2; j < 300001; j += 7*i+1) nonp[j] = true;
        }
        if(7*i+6 > 300000)  break;
        if(!nonp[7*i+6]){
            p.push_back(7*i+6);
            for(int j = 14*i+12; j < 300001; j += 7*i+6) nonp[j] = true;
        }
    }

    int n;
    while(cin >> n, n != 1){
        cout << n << ":";
        for(int x : p)  if(n % x == 0)  cout << " " << x;
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vll a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];

	map<ll, ll> mp;
	mp[a[0] + 1]++;
	ll ans = 0;
	for (ll j = 1; j < n; j++) {
		ans += mp[j + 1 - a[j]];
		mp[a[j] + j + 1]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 27416
N, K, Q = gets.chomp.split().map(&:to_i)

ans = Array.new(N, 0)

Q.times do |i|
  ans[gets.to_i - 1] += 1
end


N.times do |i|
  value = K - (Q - ans[i])
  puts value > 0 ? "Yes" : "No"
end

Measured memory_bytes: 3196
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main()
{
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        int tmpx = 0, tmpy = 0;
        int maxx = 0, maxy = 0;
        int dis = 0 ,tmpdis = 0;
        while(true){
            int dx,dy; cin >> dx >> dy;
            if(dx == 0 && dy == 0) break;
            tmpx += dx; tmpy += dy;
            tmpdis = tmpx * tmpx + tmpy * tmpy;
            if(tmpdis > dis){
                dis = tmpdis;
                maxx = tmpx;
                maxy = tmpy;
            }else if(tmpdis == dis){
                if(tmpx > maxx){
                    dis = tmpdis;
                    maxx = tmpx;
                    maxy = tmpy;
                }
            }
        }
        cout << maxx << ' ' << maxy << endl;
    }
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 100000007
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0)
#define ll long long
#define ld long double
#define lcm(a, b) (a * b) / __gcd(a, b)
#define tr(s)                                      \
	for (auto it = v.begin(); it != v.end(); it++) \
		cout << *it << " ";
#define pv(a)                         \
	for (ll i = 0; i < a.size(); i++) \
		cout << a[i] << " ";
#define flu(i, a, b) for (ll i = a; i < b; i++)
#define blu(i, a, b) for (ll i = a; i >= b; i--)
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
char e = '\n';
ll i, j, le;
int main()
{
	IOS;
	int t;
t=1;


	while (t--)
	{
		ll n;
		cin>>n;
		if(n >=400 && n <=599)cout<<8<<e;
		else if (n >=600 && n <= 799)cout<<7<<e;
		else if (n >=800 && n <=999)cout<<6<<e;
		else if (n >=1000 && n <= 1199)cout<<5<<e;
		else if (n >=1200 && n <= 1399)cout<<4<<e;
		else if (n >=1400 && n <= 1599)cout<<3<<e;
		else if (n >=1600 && n <= 1799)cout<<2<<e;
		else if (n >=1800 && n <= 1999)cout<<1<<e;
	}
	return 0;
}


Measured memory_bytes: 3644
/**
*    created: 28.06.2020 02:26:16
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int d, n;
    cin >> d >> n;
    if (d == 0) {
        if (n == 100) cout << 101 << endl;
        else cout << n << endl;
    }
    if (d == 1) {
        if (n == 100) cout << 10100 << endl;
        else cout << 100 * n << endl;
    }
    if (d == 2) {
        if (n == 100) cout << 1010000 << endl;
        else cout << 10000 * n << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

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

signed main(){
	string s,t;
	cin>>s>>t;
	bool ok=1;
	rep(i,s.size())if(s[i]!=t[i]) ok=0;
	cout<<(ok?"Yes":"No")<<endl;
	return 0;
}



Measured memory_bytes: 3624
// A - Red or Not
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int a;
	cin >> a;
	string s;
	cin >> s;

	cout << (a >= 3200 ? s : "red") << endl;

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());
  int sum=0;
  for(int i=0;i<n;i++){
    if(i==n-1){
      sum += p.at(n-1)/2;
      break;
    }
    sum += p.at(i);
  }
  cout << sum << endl;

  return 0;
  
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a[5]={0};
	int guu=0,tyoki=0,paa=0;
	int n=1;
	int i=0;
	while(n!=0)
	{
		for (i=0;i<5;i++)
		{
			scanf("%d",&a[i]);
			
			if (a[i]==0)
			{
				break;
			}
			else if (a[i]==1)
			{
				guu=1;
			}
			else if(a[i]==2)
			{
				tyoki=1;
			}
			else if (a[i]==3)
			{
				paa=1;
			}
		}
		if (a[i]==0)
		{
			break;
		}
		for (i=0;i<5;i++)
		{
			if (guu==1&&tyoki==1&&paa==1)
			{
				printf("3\n");
			}
			else if (guu==1&&tyoki==1&&paa==0)
			{
				if (a[i]==1)
				{
					printf("1\n");
				}
				else
				{
					printf("2\n");
				}
			}
			else if (guu==1&&tyoki==0&&paa==0)
			{
				printf("3\n");
			}
			else if (guu==1&&tyoki==0&&paa==1)
			{
				if (a[i]==1)
				{
					printf("2\n");
				}
				else
				{
					printf("1\n");
				}
			}
			else if (tyoki==1&&paa==1)
			{
				if (a[i]==2)
				{
					printf("1\n");
				}
				else
				{
					printf("2\n");
				}
			}
			else if (tyoki==1&&paa==0)
			{
				printf("3\n");
			}
			else if (paa==1)
			{
				printf("3\n");
			}
			a[i]=0;
		}
			guu=0,tyoki=0,paa=0;
	}
}

Measured memory_bytes: 1012
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

int main () {
   ll n, a, b;
   cin >> n >> a >> b;
   if (a > b || (n == 1 && a != b)) {
      cout << 0;
      return 0;
   }
   ll mi = (n-1) * a + b;
   ll ma = (n-1) * b + a;
   cout << (ma - mi + 1);
}

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

int main()
{
    int n, z, w, a[2000];
    cin >> n >> z >> w;
    REP(i, n)
    cin >> a[i];

    if (n == 1)
        cout << abs(a[0] - w) << endl;
    else
        cout << max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1])) << endl;

    return 0;
}

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

using namespace std;

using ll = long long;

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

    int a, b, x;

    cin >> a >> b >> x;
    if (a <= x && x <= a + b) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


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

using namespace std;

int main() {
	int A, B, sum;
	scanf("%d %d", &A, &B);

	sum = 0;

	if (A > B) {
		sum += A;
		A--;
	}
	else {
		sum += B;
		B--;
	}

	if (A > B) {
		sum += A;
		A--;
	}
	else {
		sum += B;
		B--;
	}

	printf("%d", sum);
}

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

int main()
{
    int n;
    int a,b;

    scanf("%d",&n);
    if(n == 1) printf("Hello World\n");
    else
    {
        scanf("%d%d",&a,&b);
        printf("%d\n",a+b);
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int A[100], i, j, k, l, N, v;
	
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	for (l = 0; l < N; l++) {
		if (l < N - 1) {
				printf("%d ", A[l]);
		} else {
				printf("%d\n", A[l]);
		}
	}
	for (i = 1; i < N; i++) {
		v = A[i];
		for (j = 0; j < i; j++) {
			if (A[j] > A[i]) {
				for (k = i - 1; k >= j; k--) {
					A[k + 1] = A[k];
				}
				A[j] = v;
				break;
			}
		}
		for (l = 0; l < N; l++) {
			if (l < N - 1) {
				printf("%d ", A[l]);
			} else {
				printf("%d\n", A[l]);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 600
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	n2 := n
	ds := 0
	for n2 > 0 {
		ds += n2 % 10
		n2 /= 10
	}

	if n%ds == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

ll F[2000010], I[2000010];

ll modpow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y & 1) {
			ans = ans * x % MOD;
		}
		x = x * x % MOD;
		y /= 2;
	}
	return ans;
}

ll nCr(int n, int r) {
	return F[n] * I[n - r] % MOD * I[r] % MOD;
}

int main() {
	F[0] = I[0] = 1;
	for (ll i = 1;i < 2000010;i++) {
		F[i] = F[i - 1] * i % MOD;
		I[i] = modpow(F[i], MOD - 2);
	}
	int K, ss;
	cin >> K;
	string S;
	cin >> S;
	ss = S.size();
	ll ans = 0;
	for (int i = 0;i <= K;i++) {
		ans += nCr(ss - 1 + K - i, ss - 1) * modpow(25, K - i) % MOD * modpow(26, i) % MOD;
	}
	ans %= MOD;
	cout << ans << endl;
}


Measured memory_bytes: 36496
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

const int MAX = 2e5+5;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    COMinit();
    ll N,M,K;
    cin >> N >> M >> K;
    ll ans = 0 , sum = 0;
    // x方向に2つ選ぶ場合を考える
    // N*M マスから2つ選ぶ方法は　(N*M)^2
    // x軸方向に2つ選ぶ
    for(int i=0;i<M;i++){
        ll dx = i * (M-i);
        sum += dx * (N*N)%mod;
        sum %= mod;
    }
    sum *= COM(N*M-2,K-2);
    ans += sum%mod;
    sum = 0;
    for(int i=0;i<N;i++){
        ll dx = i * (N-i);
        sum += dx%mod* (M*M)%mod;
        sum %= mod;
    }
    sum *= COM(N*M-2,K-2);
    ans += sum%mod;
    cout << ans%mod << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if(B >= C) {
    cout << B+C << endl;
    return 0;
  }
  if(A+B >= C) {
    cout << B+C << endl;
    return 0;
  }
  cout << (A+B)+B+1 << endl;
  return 0;
}

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

int main(){
    int N;
    cin>>N;
    int X[N];
    int min=99*99*100;

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

    for(int j=1;j<=100;j++){
        int sum=0;
        for(int k=0;k<N;k++){
            sum += (X[k]-j)*(X[k]-j);
        }
        min = sum < min ? sum : min;
    }
    cout<<min;
    return 0;
}

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


int main(){
  int n, m;
  int i, j, k, l;
  string s;
  cin >> n;
  long long a[n];
  for(i = 0; i < n; i++){
    cin >> a[i];
  }
  m = 0;
  int flag = 1;
  while(flag == 1){
    for(i = 0; i < n; i++){
      if(a[i]%2 == 0){
        a[i] /= 2;
      } else {
        cout << m << endl;
        return 0;
      }
    }
    m++;
  }

  cout << m << endl;

  return 0;
}


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

int main()
{
  int M,a,b,c,d,a1,b1,c1,d1,sum;

  cin>>M;
  while(1){
    cin>>a>>b>>c>>d;
    sum=a*10+b*50+c*100+d*500-M;
    d1=sum/500;
    sum=sum%500;
    c1=sum/100;
    sum=sum%100;
    b1=sum/50;
    sum=sum%50;
    a1=sum/10;
    sum=sum%10;
    if(a>a1)cout<<"10 "<<a-a1<<endl;
    if(b>b1)cout<<"50 "<<b-b1<<endl;
    if(c>c1)cout<<"100 "<<c-c1<<endl;
    if(d>d1)cout<<"500 "<<d-d1<<endl;
    cin>>M;
    if(M==0)break;
    cout<<endl;
  }
  return 0;
}

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


int main () {
  string S, ans = "Good";
  cin >> S;
  for(int i = 0; i < 3; i++) {
    if (S.at(i) == S.at(i + 1)) {
      ans = "Bad";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n[100000];
    int a[11]= {0};
int num=0;
int t=0;
void fun()
{
    for(int i=0; i<t; i++)
    {
        for(int j=0; j<t; j++)
        {
            for(int k=0; k<t; k++)
            {
                for(int l=0; l<t; l++)
                {
                    for(int z=0; z<t; z++)
                        n[num++]=a[i]*10000+a[j]*1000+a[k]*100+a[l]*10+a[z];
                }
            }
        }
    }
    for(int j=0; j<t; j++)
    {
        for(int k=0; k<t; k++)
        {
            for(int l=0; l<t; l++)
            {
                for(int z=0; z<t; z++)
                    n[num++]=a[j]*1000+a[k]*100+a[l]*10+a[z];
            }
        }
    }
    for(int k=0; k<t; k++)
    {
        for(int l=0; l<t; l++)
        {
            for(int z=0; z<t; z++)
                n[num++]=a[k]*100+a[l]*10+a[z];
        }
    }
    for(int l=0; l<t; l++)
    {
        for(int z=0; z<t; z++)
            n[num++]=a[l]*10+a[z];
    }
    for(int z=0; z<t; z++)
        n[num++]=a[z];
}
int main()
{
    int b[10];
    int m,k;
    scanf("%d%d",&m,&k);
    for(int i=0; i<k; i++)
    {
        scanf("%d",&num);
        a[num]=1;
    }
    for(int i=0; i<=9; i++)
    {
        if(a[i]==0)
            a[t++]=i;
    }
    fun();
    sort(n,n+num);
    for(int i=0;i<num;i++)
    {
        if(n[i]>=m)
        {
            printf("%d\n",n[i]);
            return 0;
        }
    }
    //for(int i=0; i<t; i++)
    //    printf("%d ",a[i]);
    return 0;
}


Measured memory_bytes: 512
// ※※※ 解答不能 ※※※
// j_taka_z 氏.
// https://atcoder.jp/contests/ddcc2020-qual/submissions/8594243
// -> 解説通りだったので, 暗記.
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    LL m, D = 0, S = 0, d, c;
    scanf("%d", &m);
    rep(i, m){
        scanf("%lld %lld", &d, &c);
        D += c;
        S += d * c;
    }
    printf("%lld\n", D - 1 + (S - 1) / 9);
    return 0;
}

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

int main(){
  int a, b, j, result;
  cin >> a >> b;
  j = (a + b) / 2;
  result = (a + b) % 2;
  if(result == 0){
    cout << j << endl;
  }else{
    cout << j + 1 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int H,W; cin >>H >>W;
  int A,B; cin >>A >>B;
  for (int i=0; i<H; i++){
    int ai = i < B ? 0 : 1;
    for (int j=0; j<W; j++){
      int aj = j < A ? 0 : 1;
      int res = (ai+aj)%2;
      cout <<res;
    }
    cout <<endl;
  }
}


Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

string add (string a, string b)
{
	reverse (a.begin(), a.end() );
	reverse (b.begin(), b.end() );

	while (a.length() != b.length()){
		if (a.length() > b.length()){
			b += '0';
		}else if (a.length() < b.length() ){
			a += '0';
		} // end if
	} // end while

	int i;
	string res = "";
	int carry = 0;

	for (i = 0; i < a.length(); ++i){
		int an = a[i] - '0';
		int bn = b[i] - '0';
		if (carry == 1){
			++an;
		} // end if
		if (an + bn >= 10){
			carry = 1;
		}else{
			carry = 0;
		} // end if
		res += ((an + bn) % 10) + '0';
	} // end for

	if (carry == 1){
		res += carry + '0';
	} // end if

	reverse (res.begin(), res.end() );
//	cout << res << endl;
	
	return res;
}
int main()
{
//	cut here before submit 
//	freopen("testcase.nb", "r", stdin);
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;

	int i;
	for (i = 0; i < n; ++i){
		string a,b;
		string res = "";
		getline (cin, a);
		getline (cin, b);
		res = add (a, b);
		if (res.length() > 80){
			cout << "overflow" << endl;
		}else{
			cout << res << endl;
		} // end if		
	} // end for

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <tuple>
#include <string>

int KMP(const std::vector<int>& S, const std::vector<int>& W){
  std::vector<int> T(W.size());
  T[0] = -1;
  int i = 2, j = 0;
  while(i < W.size()){
    if(W[i-1] == W[j]){
      T[i] = j+1;
      i++;
      j++;
    }else if(j > 0){
      j = T[j];
    }else{
      T[i] = 0;
      i++;
    }
  }
  i = 0;
  int m = 0;
  while(m+i < S.size()){
    if(W[i] == S[m+i]){
      i++;
      if(i == W.size()) return m;
    }else{
      m = m+i-T[i];
      if(i > 0) i = T[i];
    }
  }
  return -1;
}

//note: repeated
std::vector<int> KMP_all(const std::vector<int>& S, const std::vector<int>& W){
  std::vector<int> T(W.size());
  T[0] = -1;
  int i = 2, j = 0;
  while(i < W.size()){
    if(W[i-1] == W[j]){
      T[i] = j+1;
      i++;
      j++;
    }else if(j > 0){
      j = T[j];
    }else{
      T[i] = 0;
      i++;
    }
  }
  i = 0;
  int m = 0;
  int ns = S.size();
  std::vector<int> ans(ns);
  while(m < ns){
    if(W[i] == S[(m+i)%ns]){
      i++;
      if(i == W.size()){
        i--;
        ans[m] = 1;
        m = m+i-T[i];
        if(i > 0) i = T[i];
      }
    }else{
      m = m+i-T[i];
      if(i > 0) i = T[i];
    }
  }
  return ans;
}

int main(){
  int N;
  std::cin >> N;
  std::vector<long long> a_arr(N), b_arr(N);
  for(int i = 0; i < N; i++) std::cin >> a_arr[i];
  for(int i = 0; i < N; i++) std::cin >> b_arr[i];
  std::vector<int> cand_arr(N, 1), x_arr(N, 0);
  for(int ib = 0; ib < 30; ib++){
    std::vector<int> bstr1(N), bstr2(N), astr(2*N);
    for(int i = 0; i < N; i++){
      bstr1[i] = (b_arr[i]>>ib)%2;
      bstr2[i] = 1-((b_arr[i]>>ib)%2);
    }
    for(int i = 0; i < N; i++){
      astr[i] = (a_arr[i]>>ib)%2;
      astr[N+i] = astr[i];
    }
    auto kmp1 = KMP_all(astr, bstr1);
    auto kmp2 = KMP_all(astr, bstr2);
    for(int i = 0; i < N; i++){
      if(kmp1[i] < 1 && kmp2[i] < 1){
        cand_arr[i] = 0;
      }else if(kmp2[i] >= 1){
        x_arr[i] += (1<<ib);
      }
    }
  }
  for(int i = 0; i < N; i++){
    if(cand_arr[i] == 1){
      std::cout << i << " " << x_arr[i] << std::endl;
    }
  }

  return 0;
}



Measured memory_bytes: 12028
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main(){

	string s;
	int sum=0;
	while(cin>>s){
		for(int i = 0; i < s.size(); i++){
			if(s[i]>='0'&&s[i]<='9'){
				int j = i+1;
				while(1){
					if(s[j]>='0'&&s[j]<='9'){
						j++;
					}
					else
						break;
				}
				sum+=atoi(s.substr(i,j-i).c_str());
				i=j-1;
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  
  int x = 0;
  int max = 0;
  rep(i, n)
  {
    if (s.at(i) == 'I') x ++;
    else if (s.at(i) == 'D') x --;
    
    if (x > max) max = x;
  }
  
  cout << max;
  return 0;
}


Measured memory_bytes: 256