akhauriyash/Code-Regression huggingface dataset:
object Main extends App {
  val in = scala.io.Source.stdin.getLines().toIndexedSeq
  .map(_.split(' ').map(_.toInt))
  val in0 = in.head
  val H = in0(1)
  val W = in0(2)
  val ls = in.tail
  
  val ret = ls.count(e => e(0) >= H && e(1) >= W)
  println(ret)
}


Measured memory_bytes: 28752
import sys
input = sys.stdin.readline

n,k = map(int,input().split())
A = list(map(int,input().split()))
mod = 10**9 + 7

# from random import randint
# n = 10
# k = 4
# A = []
# for i in range(10):
#     A.append(randint(-20,20))
# anss=0
# for i in range(n):
#     for j in range(i+1,n):
#         for ii in range(j+1,n):
#             for jj in range(ii+1,n):
#                 anss = max(anss, A[i]*A[j]*A[ii]*A[jj])
# print(anss)
# print(A)


B = [[], []]
for i in range(n):
    if A[i] >= 0:
        B[0].append(A[i])
    else:
        B[1].append(A[i])
B[0].sort(reverse=True)
B[1].sort()

if k % 2 == 1 and len(B[0]) == 0:
    ans = 1
    ind = len(B[1])-1
    for i in range(k):
        ans = (ans * B[1][ind]) % mod
        ind -= 1
    print(ans)
elif k == n and len(B[1]) % 2 == 1:
    ans = 1
    for i in range(n):
        ans = (ans * A[i]) % mod
    print(ans)
else:
    k0 = min(len(B[0]), k)
    k1 = k-k0
    if k1%2==1:
        k0 -= 1
        k1 += 1
    # print(B,k0,k1)
    while k1+1 < len(B[1]) and k0-2 >= 0 and B[1][k1]*B[1][k1+1] > B[0][k0-1]*B[0][k0-2]:
        k1 += 2
        k0 -= 2
        # print(k0,k1)
        # print(k1+1 < len(B[1]),B[1][k1]*B[1][k1+1] , B[0][k0-1]*B[0][k0-2])
    ans = 1
    for i in range(k0):
        ans = (ans * B[0][i]) % mod
    for i in range(k1):
        ans = (ans * B[1][i]) % mod
    print(ans)



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

const int N = 2e5+5;
int f[N];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,x;
    cin>>n;
    for(int i=1;i<n;i++)
        cin>>x,f[x]++;
    for(int i=1;i<=n;i++)
        cout<<f[i]<<'\n';
    return 0;
}


Measured memory_bytes: 4376
using System;

public class AtCoder{
	public static void Main(){
		
		int n;
		n = int.Parse(Console.ReadLine().Trim());
		string[] s;
		int[] x = new int[n];
		int[] y = new int[n];
		int[] h = new int[n];
		int z = 0;
		int ansz;
		
		for (int i = 0; i<n; i++){
			s = Console.ReadLine().Trim().Split(' ');
			x[i] = int.Parse(s[0]);
			y[i] = int.Parse(s[1]);
			h[i] = int.Parse(s[2]);
		}
		
		
		bool f = true;
		for (int a = 0; a <= 100; a++){
			for (int b = 0; b <= 100; b++){
				f = true;
				ansz = -1;
				for (int i = 0; i<n; i++){
					if(f){
						if(h[i]!=0){
							z = h[i] + Math.Abs(x[i]-a)+Math.Abs(y[i]-b);
							if(ansz==-1) ansz = z;
							if(ansz!=z) f = false;
						}
					}
				}
				if(f){
					for (int i = 0; i<n; i++){
						z = ansz - Math.Abs(x[i]-a) - Math.Abs(y[i]-b);
						if (z<0) z = 0;
						if(h[i] != z) f = false;
					}
				}
				if(f) Console.WriteLine(a+" "+b+" "+ansz);
			}
		}
	}
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a; cin>>a;
	int sve=0;
	vi vec(a);
	rep(i,0,a){
		int b;  cin>>b;
		vec[i]=b;
	}
	ll ans=MOD;
	rep(i,-101,101){
		ll cnt=0;
		rep(j,0,a){
			cnt+=(i-vec[j])*(i-vec[j]);
		}
		ans=min(ans,cnt);
	}
	cout<<ans;
	
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	rep(i, N) cin >> A[i];
	
	rep(i, N) B[A[i]-1] = i+1;
	rep(i, N) cout << B[i]<<endl;
	
	

	return 0;
}

Measured memory_bytes: 1664
N,A,B = map(int,input().strip().split(' '))

answer = 0

def sum_deci(n):
    out_sum_deci = 0
    
    while(n > 0):
        out_sum_deci = n % 10 + out_sum_deci
        n = int(n / 10)
        
    return out_sum_deci

'''
print(sum_deci(N))
'''

for i in range(N + 1):
    if ((A <= sum_deci(i)) and (sum_deci(i) <= B)):
        answer += i

print(answer)

    
    
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int dp[43][420][420];

int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    rep(i, n+1)rep(j, 415)rep(k, 415) dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    rep(i, n) rep(j, 415) rep(k, 415) {
        chmin(dp[i+1][j][k], dp[i][j][k]);
        chmin(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
    }
    int ans = INF;
    srep(i, 1, 415) srep(j, 1, 415) {
        if(i * mb == j * ma) chmin(ans, dp[n][i][j]);
    }
    cout << (ans == INF? -1 : ans) << endl;
}

Measured memory_bytes: 28928
#include <stdio.h>
#define MAX 100000

int Partition(int *,int);

int main() {
  int i,n,A[MAX],m;

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

  for(i = 0; i < m ; i ++) {
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[m]);

  for(i = m + 1; i < n; i++) {
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n]);

  return 0;
}

int Partition(int *A, int n) {
  int x,i,j,a;
  x = A[n];
  i = 0;
  for(j = 0; j < n; j++) {
    if(A[j] <= x) {
      a = A[i];
      A[i] = A[j];
      A[j] = a;
      i++;
    }
  }
  A[n] = A[i];
  A[i] = x;
  return i;
}



Measured memory_bytes: 2084
#include<stdio.h>
#define MAX 100000

typedef struct{
  char name[100];
  int time;
} roll;

void enqueue(roll);
roll dequeue(void);
int tail=0;
int head=0;


roll Q[MAX];

int main(void){
  int data;
  int q,i;
  int Queue=0;
  roll x;

  scanf("%d%d",&data,&q);
  
  for(i=0;i<data;i++){
    scanf("%s%d",x.name,&x.time);
    enqueue(x);
    
  }
  
  while(1){
    
    if(head == tail) break;
    
    if(Q[head].time > q){
      x = dequeue();
      x.time -= q;
      enqueue(x);
      Queue += q; 
    }
    else{
      x = dequeue();
      
      printf("%s %d\n",x.name,x.time+Queue);
      Queue += x.time;
    }
  }
  return 0;
}

void enqueue(roll x){
  Q[tail] = x;
  if(tail+1 == MAX){
    tail = 0;
  }
  else {
    tail++;
  }
}

roll dequeue(){
  
  roll x;

  x = Q[head];

  if(head+1 == MAX){
    head = 0;
  }
  
  else{ head++;  }
  return x;
}



Measured memory_bytes: 12012
n,t= map(int,input().split())
ct = sorted([list(map(int, input().split())) for _ in range(n)])
m=1001
for i in range(n):
    if(ct[i][1]<=t):
        m=min(m,ct[i][0])
if(m==1001):
    print("TLE")
else:
    print(m)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n, l, ans=0, abmin=INT_MAX,abf;
  cin >> n >> l;
  vi a(n);
  rep(i,0,n){
    a[i]= l+i;
    ans+= a[i];
    if(abmin> abs(a[i])){
      abmin= abs(a[i]);
      abf=i;
    }
  }
  ans-= a[abf];

  cout << ans;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<time.h>
#include<stdlib.h>
#include<string>

using namespace std;

int main(){
    int a = 0; cin >> a;
    string b; cin >> b;
    if(a % 2 == 1){
        cout << "No";
        return 0;
    }
    else{
        string mae = b.substr(0, a/2);
        string ush = b.substr(a/2, a-1);
        if(mae == ush){
            cout << "Yes";
        }
        else cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
typedef long long ll;
const ll INF = 1LL << 60;
ll n, m, k, y,a, q, d, w = 0, sum = 0, ans = INF;
int main(void) {
	cin >> n; vector<ll> v(n + 1, 0);
	req(i, n) {
		cin >> v[i];v[i] += v[i - 1];
	}
	req(i, n-1) {
		ans = min(ans, (ll)abs(v[n] -v[i] - v[i]));
	}cout << ans << endl;
}

Measured memory_bytes: 4832
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
using namespace std;

int DP(int n)
{
    if (n < 10)
    {
        return n;
    }
    int diff;
    if (n % 10 == 0)
    {
        diff = 0;
    }
    else
    {
        string str_num = to_string(n);
        int front = str_num.front() - '0';
        int back = str_num.back() - '0';
        int length = str_num.length();
        if (front < back)
        {
            diff = 2 * (pow(10, length - 2) - 1) / 9;
        }
        else if (front > back)
        {
            diff = 2 * (pow(10, length - 1) - 1) / 9;
        }
        else
        {
            if (length > 2)
            {
                str_num.pop_back();
                str_num.erase(str_num.begin());
                int inner = stoi(str_num);
                diff = 2 * ((pow(10, length - 2) - 1) / 9 + 2 + inner) - 1;
            }
            else
            {
                diff = 3;
            }
        }
    }

    return diff + DP(n - 1);
}

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

    int ans = DP(n);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15872
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		print();
	}

	private static void print() throws IOException {
		int a;
		int b;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] num = str.split(" ", 0);
		a = Integer.parseInt(num[0]);
		b = Integer.parseInt(num[1]);

		int area = a * b;
		int lengthOfAround = a * 2 + b * 2;
		System.out.println(area + " " + lengthOfAround);

	}


}

Measured memory_bytes: 24220
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define dame {cout<< -1 <<"\n"; return;}
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------


//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    multiset<ll> st;
    rep(i,N) st.emplace(A[i]);
    ll ans=0;
    while(!st.empty()){
        auto enditr=prev(st.end());
        ll x=*enditr;
        st.erase(enditr);
        ll y=1;
        while(y<=x) y=y<<1;
        y=y-x;
        auto itr=st.find(y);
        if(itr!=st.end()){
            ++ans;
            st.erase(itr);
        }
    }

    cout<< ans <<"\n";


}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

int main() {
    int n;
    string s;
    cin >> n;
    map<string, int> words;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        words[s]++;
    }
    int mx = 0;
    for (pair<string, int> j : words) {
        mx = max(mx, j.second);
    }
    vector<string> p;
    for (pair<string, int> k : words) {
        if (k.second == mx) p.push_back(k.first);
    }
    sort(p.begin(), p.end());
    for (const string& l1 : p) {
        cout << l1 << endl;
    }
}


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

	int t = 1;
	//cin >> t;
	while(t--){
		int n;
		cin >> n;
		cout << ((ceil((double)n / 1000) * 1000) - n) << endl;
	}

	return 0;
}

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

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

    vector<int>vec2={99,111,222,333,444,555,666,777,888,999};
    
    
        for(int i = 1;i < vec2.size();i++){
            if(vec2.at(i-1) < N && N <= vec2.at(i)){
                cout << vec2.at(i) << endl;
            }
        }
    
}


Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
RC110C
"""


s = list(input())
t = list(input())
n = len(s)

def exchange(a,b,c):
    if a != b and a!=c:
        return(a)
    elif a == b:
        return(c)
    elif a == c:
        return(b)

ans = 'Yes'

seen = set()
for i in range(n):
    sl = s.pop()
    tl = t.pop()
    if sl == tl:
        seen.add(sl)
    elif sl != tl and not tl in seen and not sl in seen:
        s = list(map(lambda a: exchange(a,sl,tl),s))
        seen.add(tl)
    else:
        ans = 'No'
        break

print(ans)





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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    int n,m;
    cin>>n>>m;
    vector<ll> dp(n+1);
    vector<bool> ok(n+1,true);
    rep(i,0,m){
        int a;
        cin>>a;
        ok[a]=false;
    }
    dp[0]=1;
    rep(i,0,n){
        for(int j=i+1;j<=min(n,i+2);j++){
            if(ok[j]){
                dp[j]+=dp[i];
                dp[j]%=INF;
            }
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1024
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        '''
        要素xが属するグループの根を返す
        '''
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        '''
        要素xが属するグループと要素yが属するグループとを併合する
        '''
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        '''
        要素xが属するグループのサイズ（要素数）を返す
        '''
        return -self.parents[self.find(x)]

    def same(self, x, y):
        '''
        要素x, yが同じグループに属するかどうかを返す
        '''
        return self.find(x) == self.find(y)

    def members(self, x):
        '''
        要素xが属するグループに属する要素をリストで返す
        '''
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        '''
        各要素の親要素の番号を格納するリスト
        '''
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        '''
        グループの数を返す
        '''
        return len(self.roots())

    def all_group_members(self):
        '''
        {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        '''
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def kruskal(v: int, edges: list):
    """
    v: 頂点数
    edges: 各辺のstart end weightのリスト
    """
    edges.sort(key=lambda edge: edge.weight)
    uf = UnionFind(v)
    mst = []
    for edge in edges:
        if not uf.same(edge.start, edge.end):
            uf.union(edge.start, edge.end)
            mst.append(edge)
    return mst

V, E = map(int, input().split())

from collections import namedtuple
Edge = namedtuple("Edge", ['start', 'end', 'weight'])
edges = []
for _ in range(E):
    s, t, w = map(int, input().split())
    edges.append(Edge(s, t, w))

mst = kruskal(V, edges)
print(sum([e.weight for e in mst]))


Measured memory_bytes: 25552
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	string s;
	cin >> s;
	REP(i, s.length()) {
		if ((s[i] == 'L' && i % 2 == 0) || (s[i] == 'R' && i % 2 == 1)) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(int i = (int)k; i < (int)n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(int i = (int)n; i > (int)k; i--)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl;

typedef long long ll;

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

    int N; cin >> N;
    int a[100000 +1];
    REP(i,1,N+1) cin >> a[i];

    int num[100000 +3];
    memset(num,0,sizeof(num));
    REP(i,1,N+1) {
        num[a[i]] += 1;
        num[a[i]+1] += 1;
        num[max(0,a[i])-1] += 1;
    }

    cout << *max_element(num+1, num+100000 +2) << endl;
    return 0;
}


Measured memory_bytes: 1024
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include <iostream>
#include <algorithm>
#include <math.h>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#endif


#define fastIO ios_base::sync_with_stdio(0), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define mkp make_pair
/*#define NUMTOSTR(x)  (unsigned char)((x) + 48);*/
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long  ull;
using namespace std;



int main() {
	fastIO;
	int a, b;
	cin >> a >> b;
	if (min(a, b) < 1 || max(a, b) > 9) cout << -1;
	else cout << a * b;
	return 0;
}


Measured memory_bytes: 3664
#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>;

int main() {
  int x;
  cin >> x;
  if(x==0) cout  << 1 << endl;
  else cout << 0 << endl;
  return 0;
}




Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 10000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
// input vector
template<typename T>
void invec(vector<T> &A){for(T& a : A) cin >> a;}


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

i64 H, W; cin >> H >> W;

if (H%3 == 0 || W%3 == 0){
    cout << "0\n";
    return 0;
}

i64 mini = H * W;
// 横3分割. 縦辺の長さの差は1にできる．横3分割も同様．
if (H > 2) mini = W;
if (W > 2) mini = min(mini, H);

// ト 型分割．縦辺を横にずらして探索
rep(i, 1, W){
    VI S{H*i, (W-i)*(H/2), (W-i)*(H/2 + H%2)};
    mini = min(mini, *max_element(ALL(S)) - *min_element(ALL(S)));
}
// T 型分割
rep(i, 1, H){
    VI S{W*i, (H-i)*(W/2), (H-i)*(W/2 + W%2)};
    mini = min(mini, *max_element(ALL(S)) - *min_element(ALL(S)));
}

cout << mini << "\n";
}
// 書いて考える．場合分け
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/05/01 10:44:45 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

using namespace std;

#define	int	long long
#define MOD 1000000007;
#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 rrep(i, n) for (int i = (n); i >= 0; --i)

typedef long long			ll;
typedef vector<int>			VI;
typedef vector<vector<int>>	VVI;
typedef pair<int, int>		PII;

// TOP
void	Main()
{
	int	h, w;
	cin >> h >> w;
	VVI	V(h + 1, VI(w + 1));
	rep(i, w + 1)
		V.at(0).at(i) = 100;
	rep(i, h + 1)
		V.at(i).at(0) = 100;
	vector<string>	S(h + 1);
	rep(i, w + 1)
	S.at(0) += '.';
	rep(i, h)
	{
		cin >> S.at(i + 1);
		S.at(i + 1) = '.' + S.at(i + 1);
	}
	rep2(i, 1, h + 1)
	{
		rep2(j, 1, w + 1)
		{
			if (i == 1 && j == 1)
			{
				if (S.at(1).at(1) == '#')
					V.at(1).at(1) = 1;
				else
					V.at(1).at(1) = 0;
			}
			else if (S.at(i).at(j) == '.')
			{
				V.at(i).at(j) = min(V.at(i - 1).at(j), V.at(i).at(j - 1));
			}
			else
			{
				int	u, l;
				u = V.at(i - 1).at(j);
				if (S.at(i - 1).at(j) != '#')
					u++;
				l = V.at(i).at(j - 1);
				if (S.at(i).at(j - 1) != '#')
					l++;
				V.at(i).at(j) = min(u, l);
			}
		}
	}
	cout << V.back().back() << endl;
}
// END

int32_t	main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 384
import collections
import sys
readline = sys.stdin.readline


def main():
    x = int(readline().rstrip())
    y = 100
    num = 0
    while 10 ** 18 >= y:
        y = int(y * 1.01)
        num += 1
        if x <= y:
            print(num)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9396
#include <iostream>

int main()
{
  char c;
  std::cin >> c;

  std::string s = "A";
  if('a' <= c && c <= 'z') {
    s = 'a';
  } else if('A' <= c && c <= 'Z') {
    s = "A";
  }

  std::cout << s << std::endl;

  return 0;
}


Measured memory_bytes: 3592
from math import *

n = int(input())
a = list(map(int,input().split()))

sn = abs(a[0])
for i in range(n-1):
    sn += abs(a[i]-a[i+1])
sn += abs(a[n-1])
#print(sn)
p = sn
p -= abs(a[0])+abs(a[1]-a[0])-abs(a[1])
print(p)

for i in range(1,n-1):
    p = sn
    p -= abs(a[i]-a[i-1])+abs(a[i]-a[i+1])-abs(a[i+1]-a[i-1])
    print(p)
    
p = sn
p -= abs(a[n-2]-a[n-1])+abs(a[n-1])-abs(a[n-2])
print(p)

Measured memory_bytes: 64236
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int i,j,n,w1;
	int v[100],w[100];
	int *temp,*last,*next;
	
	scanf("%d %d",&n,&w1);
	for(i=0;i<n;i++) scanf("%d %d",&v[i],&w[i]);
	
	w1++;
	last=(int *)calloc(w1,sizeof(int));
	next=(int *)calloc(w1,sizeof(int));
	for(i=0;i<n;i++){
		for(j=0;j<w1;j++){
			if(j-w[i]>=0 && last[j-w[i]]+v[i]>last[j]) next[j]=last[j-w[i]]+v[i];
			else next[j]=last[j];
//			printf("%3d",next[j]);
		}
		temp=last;
		last=next;
		next=temp;
//		printf("\n");
	}
	printf("%d\n",last[w1-1]);
	free(last);
	free(next);
	return 0;
}

Measured memory_bytes: 684
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    rep(i, M) cin >> B[i];
    int ans = 0;
    rep(i, N){
        int total = 0;
        rep(j, M){
            int a;
            cin >> a;
            total += a*B[j];
        }
        total += C;
        if(0 < total) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
public class Main
{
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;
		public FastReader()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt()
		{
			return Integer.parseInt(next());
		}
		long nextLong()
		{
			return Long.parseLong(next());
		}
		double nextDouble()
		{
			return Double.parseDouble(next());
		}
		String nextLine()
		{
			String str ="";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}
	public static void main(String[] args)
	{
		FastReader fs=new FastReader();
		int k=fs.nextInt();
      	String s="ACL";
        for(int i=0;i<k;i++)
        {
          System.out.print(s);
        }
	}
}

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

int main()
{
  string s;
  cin >> s;
  int price = 700;
  rep(i, 3) if (s[i] == 'o') price += 100;
  cout << price << endl;
}

Measured memory_bytes: 256
//verma_ankit484

#include<bits/stdc++.h>

typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const ll mod = (ll) 1e9+7;

using namespace std;

int main()
{
  IOS
  #ifdef AV
  freopen("int.txt", "r", stdin);
  #endif
  ll a, b;
  cin >> a >> b;
  ll c = 0;
  ll k = 1;
  while(k < b) {
    k += (a-1);
    c++;
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
unsigned n,t,block[9],res;
inline unsigned getBlock(unsigned rating)
{
    if (rating < 400) return 1; else
		if (rating < 800) return 2; else
			if (rating < 1200) return 3; else
				if (rating < 1600) return 4; else
					if (rating < 2000) return 5; else
						if (rating < 2400) return 6; else
							if (rating < 2800) return 7; else
								if (rating < 3200) return 8; else return 0;
}
int main()
{
    scanf("%u",&n);
    for (register unsigned i(0);i<n;++i) scanf("%u",&t),++block[getBlock(t)];
    for (register unsigned i(1);i<9;++i)
		if (block[i]) ++res;
    if (res) printf("%u %u",res,res+block[0]); else printf("1 %u",block[0]);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  vector<Int> h(n);
  for(Int i=0;i<n;i++) cin>>h[i];
  const Int INF = 1e15;
  vector<Int> dp(n,INF);
  dp[0]=0;
  for(Int i=0;i<n;i++)
    for(Int j=1;j<=k;j++)
      if(i+j<n) chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
  
  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1920
#include <cstdio>
int main() {
	int n, i, j, s, m, a[5000];
	while (scanf("%d", &n) && n) {
		for (i = 0; i < n; i++) scanf("%d", &a[i]);
		m = -2147483647;
		for (i = 0; i < n; i++, s = 0)
			for (j = i; j < n; j++)
				if ((s += a[j]) > m) m = s;
		printf("%d\n", m);
	}
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
class b{
  public static void Main(){
    String input = Console.ReadLine();
    char[] str = input.ToCharArray(0, input.Length);
    if(str[0] == '?' && input.Length == 1){
      str[0] = 'D';
    }
    else if(str[0] == '?'){
      if(str[1] == 'D'){
        str[0] = 'P';
      }
      else{
        str[0] = 'D';
      }
    }
    for(int i=1; i<input.Length-1; i++){
      if(str[i] == '?'){
        if(str[i-1] == 'P'){
          str[i] = 'D';
        }
        else{
          str[i] = 'D';
        }
      }
    }
    if(str[input.Length-1] == '?'){
      str[input.Length-1] = 'D';
    }
    for(int i=0; i<input.Length; i++){
      Console.Write(str[i]);
    }
    Console.WriteLine();
  }
}


Measured memory_bytes: 17760
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int x, a, b; cin >> x >> a >> b;
  if(abs(x - a) < abs(x - b)) cout << "A" << endl;
  else cout << "B" << endl;
  return;
}

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


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

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var str = Console.ReadLine();

        var strArray = str.ToCharArray();

        for(var i = 0; i < N - 1; i++)
        {
            if(strArray[i] == strArray[i + 1])
            {
                strArray[i] = 'X';
            }
        }

        var ans = strArray.Where(x => x != 'X')
            .Count();

        Console.WriteLine(ans);
    }
}


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

long long  memo[101][10][1001];

long long dfs(int i, int j, int k)
{
    long long res = 0;
    if(j == 0 && k == 0) {
        return 1;
    } else if(i > 100 || j < 0 || k < 0){
        return 0;
    } else if(memo[i][j][k] >= 0){
        return memo[i][j][k];
    } else {
        res += dfs(i + 1, j, k);
        res += dfs(i + 1, j - 1, k - i);
    }
    return memo[i][j][k] = res;
}

int main()
{
    fill((long long*)memo, (long long*)(memo + 101), -1);
    int n, s;
    while(cin>> n >> s, n || s){
        cout << dfs(0, n, s) << endl;
    }
}

Measured memory_bytes: 9056
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<vector>

//#include <bits/stdc++.h>

using namespace std;

//Choose a cell that was not chosen before 
//and contains one or more coins,
//then move one of those coins to a vertically or horizontally adjacent cell.
//Maximize the number of cells containing an even number of coins.
int maze[600][600];
typedef struct node {
	int x, y, lx, ly;
}Node;
vector<Node> vec;
int main()
{
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> maze[i][j];
		}
	}
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (maze[i][j] % 2 == 1)//奇数
			{
				if (j + 1 < w&&maze[i][j + 1] % 2 == 1)
				{
					vec.push_back({ i,j,i,j + 1 });
					maze[i][j + 1]++;
					continue;
				}
				if (i + 1 < h&&maze[i + 1][j] % 2 == 1)
				{
					vec.push_back({ i,j,i + 1,j });
					maze[i + 1][j]++;
					continue;
				}
				if (j + 1 < w&&maze[i][j + 1] % 2 == 0)
				{
					vec.push_back({ i,j,i,j + 1 });
					maze[i][j + 1]++;
					continue;	
				}
				if (i + 1 < h&&maze[i + 1][j] % 2 == 0)
				{
					vec.push_back({ i,j,i + 1,j });
					maze[i + 1][j]++;
					continue;
				}
			}
		}

	}
	cout << vec.size() << endl;
	for (int i = 0; i < vec.size(); i++)
	{
		cout << vec[i].x +1<< " " << vec[i].y +1<< " " << vec[i].lx+1 << " " << vec[i].ly +1<< endl;
	}
	return 0;
}

Measured memory_bytes: 5360
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef vector<int> vi;

#define mp make_pair
#define pb push_back

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
 
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
 
const int MOD = 1000000007;
double PI = 4*atan(1);

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	string s; cin >> s;
	F0R(i,s.length()) {
		if (i<(s.length()-1) && s[i] == s[i+1]) {
			cout << (i+1) << " " << (i+2);
			return 0;
		}
		if (i<(s.length()-2) && s[i] == s[i+2]) {
			cout << (i+1) << " " << (i+3);
			return 0;
		}
	}
	cout << -1 << " " << -1;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  string s;
  cin >> s;
  vector<vector<char>> v(2);
  for(int i=0;i<s.length();i++){
    v[i%2].push_back(s[i]);
  }
  int ozero = 0,ezero = 0;
  for(int i=0;i<v[0].size();i++){
    if(v[0][i]=='0') ozero++;
  }
  for(int i=0;i<v[1].size();i++){
    if(v[1][i]=='0') ezero++;
  }
  cout << min(ozero+(v[1].size()-ezero),ezero+(v[0].size()-ozero)) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N;
	cin >> N;
	double ans = 0;
	for (int i = 0; i < N; i++) {
		double tmp; string s;
		cin >> tmp;
		cin >> s;
		if (s == "JPY") {
			ans += tmp;
		}
		else {
			ans += tmp * 380000.0;
		}
	}
	cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  
  string S;
  cin >> S;
  
  int val = stoi(S.substr(0,3));
  int diff = abs(stoi(S.substr(0,3))-753);
  for (int i=0;i<S.size()-2;i++){
    if (diff>abs(stoi(S.substr(i,3))-753)){
      diff = abs(stoi(S.substr(i,3))-753);
      val = stoi(S.substr(i,3));
    }
  }
  
  cout << diff << endl;
                 
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = LLONG_MAX;
const ll N =(1e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;

int x[N];
int arr[N];
int pre[N];
void solve(){
	int n,a,b;
	cin >> n >> a >> b;
	for(int i = 1;i <= n;i++)
		cin >> x[i];
	for(int i=1;i<n;i++){
		arr[i] = x[i+1]  -x[i];
	}
	sort(arr+1,arr+n);
	for(int i =1;i<n;i++)
		pre[i] = pre[i-1] + arr[i];
	int ans= INF; 
	for(int i=0;i<=n;i++){
		ans = min(ans,b*i + (pre[n-i-1] * a));
	}
	cout << ans << endl;
}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

Measured memory_bytes: 5992
def main():
    N, T = map(int, input().split())
    m = 1001
    for _ in range(N):
        c, t = map(int, input().split())
        if T >= t and m > c:
            m = c
    if m == 1001:
        print('TLE')
    else:
        print(m)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 200010;
template <typename T> void inline read(T &x) {
	T f = 1;
	char ch = getchar();
	for (; '0' > ch || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (x = 0; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= f;
}
int n;
char s[N];
int tmp, ans;
int main() {
	read(n);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++) if (s[i] == 'R') tmp++;
	for (int i = 1; i <= tmp; i++) if (s[i] == 'W') ans++;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
int N;
int main(){
    cin >> N;
    cout << 800*N - 200*floor(N/15) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n, p;
    string s;
    cin >> n >> p >> s;
    if (10 % p == 0) {
        ll ans = 0;
        rep(i, n) {
            if ((s[i] - '0') % p == 0) {
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }
    vector<int> d(n + 1);
    int ten = 1;
    for (int i = n - 1; i >= 0; --i) {
        int a = ((s[i] - '0') * ten) % p;
        d[i] = (d[i+1] + a) % p;
        ten *= 10; ten %= p;
    }
    vector<int> cnt(p);
    ll ans = 0;
    for (int i = n; i >= 0; --i) {
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define all(n) n.begin(),n.end()
#define yn(x) cout << (x ? "Yes":"No") << endl;

int main() {
  string s;
  cin >> s;
  if(s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  
  return 0;
}


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

const int mod = 1e9+7;

int main(){
  int n, m; cin >> n >> m; int n0 = 1, n1 = 0, n2 = 0;
  bool safe[n]; fill(safe, safe+n, true);
  for(int i=0; i<n; i++) {
    int c; cin >> c; c--; safe[c] = false;
  }
  
  for(int i=0; i<n; i++) {
    if (safe[i]) n1 = (n0 + n1) % mod;
    if (i != n-1 && safe[i+1]) n2 = (n0 + n2) % mod;
    //cout << i << " " << n0 << " " << n1 << " " << n2 << endl;
    n0 = n1; n1 = n2; n2 = 0;
  }
  cout << n0 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if(a+b==c || b+c==a || c+a==b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int P[3][100010];
int DP[3][100010];

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

	cin >> N;
	rep(k, 0, 3)rep(i, 0, N)
	{
		cin >> P[k][i];
	}
	rep(i, 0, 3)
	{
		sort(P[i], P[i] + N);
	}
	rep(i, 0, 3)rep(j, 0, N)
	{
		if (i == 0)
		{
			DP[i][j]++;
		}
		else
		{
			int itr = lower_bound(P[i - 1], P[i - 1] + N, P[i][j]) - P[i - 1];
			itr--;
			if (itr >= 0)
			{
				DP[i][j] += DP[i - 1][itr];
			}
		}
		if (j > 0)DP[i][j] += DP[i][j - 1];
	}

	cout << DP[2][N - 1] << endl;

	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
        v[i]*=-1;
    }
    sort(v.begin(),v.end());
    int first=0,second=0;
    for(int i=0;i<n;i++)
    {
        if(i%2==0)
        {
            first+=(v[i]*-1);
        }
        else
        second+=(v[i]*-1);
    }
    cout<<first-second;
}

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

typedef long long int64;
const int MAX = 2e5 + 5;
int n, a[MAX];
int64 m, t[MAX], sum[MAX];

pair <int64, int64> f(int x) {
	int64 cnt = 0, tot_sum = 0;
	for(int i = 1; i <= n; i++) {
		int64 c = t[max(1, x - a[i])];
		int64 s = sum[max(1, x - a[i])];

		cnt += c;
		tot_sum += s;
		tot_sum += c * a[i];
	}

	return { cnt, tot_sum };
}

int main() {
	scanf("%d%lld", &n, &m);

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

	for(int i = 1e5; i > 0; i--) {
		t[i] += t[i + 1];
		sum[i] += sum[i + 1];
	}

	int st = 1, nd = 2e5, x = 0;

	while(st <= nd) {
		int mid = (st + nd) >> 1;

		if(f(mid).first >= m) {
			x = max(x, mid);
			st = mid + 1;
		}

		else nd = mid - 1;
	}

	auto o = f(x + 1);
	int64 ans = 1LL * (m - o.first) * x + o.second;

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2176
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    s= input().strip()


    diff = 0
    cnt_inbal = 0
    cnt_l = 0
    for i in range(n):
        if s[i]=='(':
            diff += 1
            cnt_l += 1
        else:
            diff -= 1
            if diff < 0:
                cnt_inbal += 1
                diff = 0

    for i in range(cnt_inbal):
        s = '(' + s


    for i in range(cnt_l + cnt_inbal - (n - cnt_l)):
        s += ')'

    print(s)
        
        


solve()


Measured memory_bytes: 3064