akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#ifdef DEBUG
#include<conio.h>
#endif // DEBUG


int main () {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif // DEBUG
    
    int a, b;
    scanf("%d %d", &a, &b);
    if(a > b) printf("a > b\n");
    else if(a < b) printf("a < b\n");
    else printf("a == b\n");

#ifdef DEBUG
    getch();
#endif // DEBUG
    return 0;
}




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

int main(){
    int A,B,C;
    string op;
    cin>>A>>op>>B;
    if(op=="+"){
    C=A+B;
    cout<<C<<endl;
    
            }
    else{
        C=A-B;
        cout<<C<<endl;
    }
    return 0;
}

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

int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << (char)(s1.at(0) - 'a' + 'A') << (char)(s2.at(0) - 'a' + 'A') << (char)(s3.at(0) - 'a' + 'A') << endl;
}

Measured memory_bytes: 3564
import java.util.*;

public class Main{

public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int[] mountains = new int[10];

for(int i=0; i<10; i++){
mountains[i] = sc.nextInt();
}

Arrays.sort(mountains);
System.out.println(mountains[9]);
System.out.println(mountains[8]);
System.out.println(mountains[7]);
}


}

Measured memory_bytes: 26372
#include <bits/stdc++.h>
#include <vector>
#define rep(i,l,r) for(int i = l; i < r; ++i)
#define ll long long
using namespace std;

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

    int ans = 0;

    rep(i, 1, sqrt(n)) {
        rep(j, i, n+1) {
            if(i*j >= n) break;
            if(i==j) ans += 1;
            else ans += 2;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3676
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N, X = map(int, input().split())
    l = list(map(int, input().split()))

    if X not in l:
        l.append(X)
    l.sort()

    ans = None
    for i in range(len(l) - 1):
        diff = l[i + 1] - l[i]
        if ans is None:
            ans = diff
        else:
            ans = gcd(ans, diff)
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;

// https://freestylewiki.xyz/fswiki/wiki.cgi?page=AtCoder+Beginner+Contest+066

ll mod = 1000000007;
ll factorial[100002];
ll mod_factorial[100002];

ll pow(ll factor, ll q) {
  if (q == 1) {
    return factor % mod;
  }
  if (q % 2 == 0) {
    ll sub = pow(factor, q / 2);
    return ((sub % mod) * (sub % mod)) % mod;
  } else {
    return ((factor % mod) * (pow(factor, q - 1) % mod)) % mod;
  }
}
void init() {
  for (ll i = 0; i <= 100001; i++) {
    if (i == 0 || i == 1) {
      factorial[i] = 1;
    } else {
      factorial[i] = ((i % mod) * (factorial[i - 1] % mod)) % mod;
    }
  }
  for (ll i = 0; i <= 100001; i++) {
    if (i == 0 || i == 1) {
      mod_factorial[i] = 1;
    } else {
      mod_factorial[i] = pow(factorial[i], mod -2 ) % mod;
    }
  }
}
ll C(ll n, ll k) {
  if (n < k) {
    return 0;
  }
  ll sub = ((factorial[n] % mod) * (mod_factorial[k] % mod)) % mod;
  return ((sub % mod) * (mod_factorial[n - k] % mod)) % mod;
}

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

  vector<ll> list(N + 1);
  map<ll, int> m;
  ll v;
  for (ll i = 0; i < N + 1; i++) {
    cin >> list[i];
    m[list[i]]++;
    if (m[list[i]] == 2) {
      v = list[i];
    }
  }

  ll fv = -1, sv = -1;
  for (ll i = 0; i < N + 1; i++) {
    if (list[i] == v && fv == -1) {
      fv = i;
    } else if (list[i] == v && sv == -1) {
      sv = i;
    }
  }

  init();
  for (ll i = 1; i <= N + 1; i++) {
    if (i == 1) {
      cout << N << endl;
    } else {
      if (i == N + 1) {
        cout << 1 << endl;
      } else {
        ll sub = (C(N + 1, i) % mod + mod - C(fv + N - sv, i - 1) % mod) % mod;
        cout << sub << endl;
      }
    }
  }
  return 0;
}


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

vector<unsigned long long> calc_lucas(int N) {
    vector<unsigned long long> result(N+1);
    result.at(0) = 2LL;
    result.at(1) = 1LL;
    for (int i = 2; i <= N; i++) {
        result.at(i) = result.at(i-1) + result.at(i-2);
    }
    return result;
}

int main() {
    // receive input
    int N;
    cin >> N;

    vector<unsigned long long> result(N);
    //calculation of Luca Number
    result = calc_lucas(N);

    // show result
    cout << result.at(N) << endl;
}



Measured memory_bytes: 256
h = [0] * 2019
h[0] = 1

cur = 0
p10 = 1

gets.to_s.chomp.bytes.reverse_each do |c|
  cur = ( cur + ( c - 48 ) * p10 ) % 2019 # p '0'.ord 48
  h[cur] += 1
  p10 = p10 * 10 % 2019
end

ans = 0
h.each{|i| ans += i * (i-1) / 2}

puts ans

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

public class Main{
	static long mod = 1000000007;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		long[] acount = new long[n];
		for (int i = 1; i < n; i++) {
			for (int j = 0; j < i; j++) {
				if (a[i] < a[j]) {
					acount[i]++;
				}
			}
		}
		long[] maecount = new long[n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (a[i] < a[j]) {
					maecount[i]++;
				}
			}
		}
		long ans = 0;
		for (int i = 0; i < n; i++) {
			ans += acount[i] * k;
			ans %= mod;
			long kake = k * (k - 1) / 2 % mod;
			ans += maecount[i] * kake;
			ans %= mod;
		}
		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 || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
 
#define ll long long int
#define ld long double
#define pb push_back
#define pq priority_queue
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vvll vector<vector<ll>>
#define vvi vector<vector<int>>
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define MODNUM 1000000007
#define lp(i,a,b) for(ll i=a; i<b; i++)
#define all(v) v.begin(), v.end()
 
using namespace std;
 
ll mex(ll a, ll b, ll m) {
	if(b==0) return 1;
	if(b%2) return a*mex((a*a)%m,(b-1)/2,m)%m;
	else return mex((a*a)%m,b/2,m);
}
 
int x,y;
void exteu(ll a, ll m) {
	if(m==0) { x=1;y=0; }
	else {
		exteu(m,a%m);
		ll temp = x;
		x=y;
		y=temp-(a/m)*y;
	}
}
 
ll fact(ll n) 
{	ll prod=1;
	for(ll i=2; i<=n; i++) {
		prod*=i;
	}
	return prod;
}
 
ll gcd(ll a, ll b) {
	if(b==0) return a;
	return gcd(b, a%b);
}
 
// bool isprime[200001];
// void makesieve() {
// 	memset(isprime, true, sizeof(isprime));
// 	for (int i = 2; i <= sqrt(200000); ++i)
// 	{
// 		/* code */
// 		if(isprime[i]) {
// 			for (int j = i*i; j <= 200000; j+=i)
// 			{
// 				/* code */
// 				isprime[j]=false;
// 			}
// 		}
// 	}
// }
// 
// 1 2 4 5 8
void solve() {
	ll a;cin>>a;
	cout<<a+a*a+a*a*a;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll TESTS=1;
	// cin >> TESTS;
	// makesieve();
	while(TESTS--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3636
import math
from copy import copy
di = {}
di[0] = 0
for i in range(1, 2*(10**6)+1):
    di[i] = 0
for i in range(1, 2*(10**6)+1):
    count = 0
    for j in range(int(math.log2(i))+4):
        if (i>>j)&1:
            count += 1
    di[i] = di[i%count] + 1
n = int(input())
x = list(input())
x.reverse()
count = 0
for i in x:
    if i =='1':
        count += 1
mod_p = count + 1
mod_m = count - 1
di_p = {}
di_m = {}
for i in range(n):
    di_p[i] = pow(2, i, mod_p)
    if mod_m >= 1:
        di_m[i] = pow(2, i, mod_m)
s_p = 0
s_m = 0
for i in range(n):
    if x[i] == '1':
        s_p += di_p[i]
        if mod_m >= 1:
            s_m += di_m[i]
    else:
        continue
for i in range(n-1, -1, -1):
    sm = copy(s_m)
    sp = copy(s_p)
    if x[i] == '1' and (mod_m == 0 or mod_m == -1):
        print(0)
    elif x[i] == '1':
        sm -= di_m[i]
        sm %= mod_m 
        print(di[sm]+1)
    else:
        sp += di_p[i]
        sp %= mod_p
        print(di[sp]+1)


Measured memory_bytes: 247344
import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {

    val s = StdIn.readLine()
    val ans = s.foldLeft(Vector(0)){(acc, c) =>
      if (List('A', 'C', 'G', 'T').contains(c)) {
        (acc.head + 1) +: acc
      } else {
        0 +: acc
      }}.max
    println(ans)
  }
}


Measured memory_bytes: 25280
//お勉強中
//これは高速ゼータ変換の応用なの？

//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 16;
char cn[cm], * ci = cn;
inline int getint() {
	char C = *ci++;
	int A = C - '0';
	while ((C = *ci++) >= '0') A = A * 10 + C - '0';
	return A;
}

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

	fread(cn, 1, cm, stdin);

	int N = getint(), M = getint();
	int n = 1 << N;
	int dp[1 << 12];
	rep(i, n) dp[i] = 1e9;

	rep(i, M) {
		int A = getint();
		int B = getint();
		int C = 0;
		rep(j, B) {
			int c = getint();
			C += 1 << (c - 1);
		}
		dp[C] = min(dp[C], A);
	}

	rep(j, N) {
		rep (i, n) {
			if (!(i >> j & 1)) dp[i] = min(dp[i], dp[i | 1 << j]);
		}
	}

	rep1(i, n - 1) {
		int k = 1 << 31 - __builtin_clz(i);
		for (int j = i - 1 & i; j >= k; j = j - 1 & i) {
			dp[i] = min(dp[i], dp[j] + dp[i ^ j]);
		}
	}

	if (dp[n - 1] >= 1e9) printf("-1");
	else printf("%d", dp[n - 1]);


	Would you please return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

// 実験
//int n = 5, k = 3;
//vector<vector<ll>> a;
//
//void dfs(vector<ll> v) {
//  if(v.size()) a.push_back(v);
//  if(v.size() == n) return;
//
//  REP(i, k) {
//    vector<ll> u(v);
//    u.push_back(i+1);
//    dfs(u);
//  }
//}

// k^nとか持てるはずがないのが出てきたのでずれとかの別の小さい値で持たないといけないのはわかる
// 明らかに真ん中に近い列として k/2 を並べるものがあるのはわかる
// 長さがN未満の列がある分ずれる
// このずれを高速に求められないといけない
// 実験 or 数学するとこのずれは n/2
// 数列を辞書順で一つ前のものに戻す→ならしO(1)でできる　
// この戻す処理の雰囲気にAGC029 C - Lexicographic constraintsを感じる

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

  // 実験
//  dfs({});
//  sort(ALL(a));
//  ll half = ceil((int)a.size(), 2);
//  cout << "half=" << half << endl;
//  for(int i=max(half-10, 0LL); i<min(half+10, (ll)a.size()); ++i) {
//    cout << i << " " << a[i] << endl;
//  }
//
//  return 0;

  ll n, k;
  cin >> k >> n;

  if(k%2 == 0) {
    cout << k/2;
    REP(i, n-1) cout << " " << k;
    cout << endl;
    return 0;
  }

  vector<ll> ans(n, ceil(k, 2LL));
  REP(i, n/2) {
    if(ans.back() == 1) ans.pop_back();
    else {
      ans[ans.size()-1]--;
      while(ans.size() != n) ans.push_back(k);
    }
  }

  REP(i, ans.size()) cout << ans[i] << " ";
  cout << endl;

  return 0;
}

Measured memory_bytes: 4608
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = [[-1] + [int(x)-1 for x in row.split()][::-1] for row in sys.stdin.readlines()]

A.append([-1])

def f(cand):
    cand1 = set()
    can_use = []
    for n in cand:
        if A[A[n][-1]][-1] == n:
            can_use.append(n)
    for n in can_use:
        A[n].pop()
        cand1.add(n)
        if A[n][-1] != -1:
            cand1.add(A[n][-1])
    return len(can_use),cand1

answer = 0
rest = N*(N-1)
cand = set(range(N))
while True:
    answer += 1
    x,cand = f(cand)
    if x == 0:
        answer = -1
        break
    rest -= x
    if rest == 0:
        break

print(answer)



Measured memory_bytes: 76124
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
#define int long long
using namespace std;
int INF = 1e9;
int32_t main()
{
	string s;
	cin >> s;
	int next[26][s.size()+1];
	for (int i=0; i < 26; i++){
		next[i][s.size()] = INF;
	}
	for (int i=s.size()-1;i>=0;i--){
		next[s[i] - 'a'][i] = i;
		for (int j=0; j < 26; j++){
			if (j == s[i] - 'a') continue;
			next[j][i] = next[j][i+1];
		}
	}
	int dp[s.size()+1];
	dp[s.size()] = 1;
	for (int i=s.size() - 1; i>=0; i--){
        int maximum = -1;
        for (int j=0; j < 26; j++){
			maximum = max(maximum, next[j][i]);
        }
        if (maximum == INF) dp[i] = 1;
        else dp[i] = dp[maximum+1] + 1;
	}
	int ans = dp[0];
	vector<vector<int> > vh;
	for (int i=0; i < 26; i++){
		vector<int> help;
		vh.push_back(help);
	}
	for (int i=0; i < s.size(); i++){
		vh[s[i] - 'a'].push_back(i);
	}
	int u[26];
	for (int i=0; i < 26; i++){
		u[i] = 0;
	}
	int last = -1;
	string answer = "";
	while (ans > 0){
        for (int j=0;j < 26; j++){
			while (u[j] != vh[j].size() && vh[j][u[j]] <= last){
				u[j]++;
			}
			if (u[j] == vh[j].size()){
				if (ans == 1){
					answer += j + 'a';
					ans--;
					break;
				}
				continue;
			}
			int ind = vh[j][u[j]];
			if (dp[ind+1] == ans - 1){
				answer += j + 'a';
				ans--;
				last = ind;
				break;
			}
        }
	}
	cout << answer << endl;
    return 0;
}

Measured memory_bytes: 44548
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int A[100000];
  cin >> N;
  for(int i=1; i<=N; i++){
    cin >> A[i];
  }
  int B[100000];
  
  for(int i=1; i<=N; i++){
    B[A[i]]=i;
  }
  for(int i=1; i<=N; i++){
    cout << B[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
int gz[2005][2005],heng[2005][2005],shu[2005][2005],a[2005][2005];
int main(int argc, char** argv) {
	int n,m,q;
	ios::sync_with_stdio(false);
	cin >> n >> m >> q;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			char c;
			cin >> c;
			if(c-48) a[i][j]=1;
			gz[i][j]=gz[i-1][j]+gz[i][j-1]-gz[i-1][j-1]+a[i][j];
			heng[i-1][j]=heng[i-2][j]+heng[i-1][j-1]-heng[i-2][j-1]+(a[i][j]==a[i-1][j]&&a[i][j]==1),shu[i][j-1]=shu[i-1][j-1]+shu[i][j-2]-shu[i-1][j-2]+(a[i][j]==a[i][j-1]&&a[i][j]==1);
		}
	}
	while(q--)
	{
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		cout << gz[c][d]-gz[a-1][d]-gz[c][b-1]+gz[a-1][b-1]-heng[--c][d]+heng[a-1][d]+heng[c][b-1]-heng[a-1][b-1]-shu[++c][--d]+shu[a-1][d]+shu[c][b-1]-shu[a-1][b-1] << "\n";
	}
	return 0;
}

Measured memory_bytes: 64640
#include<stdio.h>
#define n 200000

int main(){

int R[n],maxv=-1000000000,minv,num,j;
  scanf("%d",&num);
  for(j=0;j<num;j++){
    scanf("%d",&R[j]);
}
  minv = R[0];
  for(j=1;j<num;j++){
    if(maxv<R[j]-minv)maxv=R[j]-minv;
    if(minv>R[j])minv=R[j];
}
printf("%d\n",maxv);

  return 0;
}



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

using namespace std;

#define int long long
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back

int mod=1e9+7;

int solve(int n){
    return n*(n-1)/2;
}

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

    int a[n];
    rep(i,0,n) cin>>a[i];

    map<int,int> mp;
    for(int i=0;i<n;i++) mp[a[i]]++;

    int sum=0;
    for(auto k:mp){
        if(k.second>=2) sum+=(solve(k.second));
    }
    for(int i=0;i<n;i++){
        int tmp=mp[a[i]];
        if(tmp==2){
            cout<<sum-(tmp-1)<<endl;
            continue;
        }else{
            tmp--;
            cout<<sum-(tmp)<<endl;
        }
    }
}

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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

int main(){

    int n;
    cin >> n;
    int p[n];
    REP(i,n) cin >> p[i];

    int now = 0;
    int ans = 0;
    for(int i = 0;i<n;i++){
        if(now == 0 && p[i] == i+1){
            now++;
        }else if(now == 1){
            ans++;
            now = 0;
        }
    }
    if(now == 1)ans++;
    cout << ans;
    
}


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


int main(){

    int N, p[10];
    cin >> N;
    for( int i = 0; i < N; i++ ) cin >> p[i];

    int max_price = 0, sum = 0, j;
    for( int i = 0; i < N; i++ ){
        if( max_price <= p[i]  ){
            max_price = p[i];
            j = i;
        }
    }

    for( int i = 0; i < N; i++ ){
        if( i == j  ) sum += p[i]/2;
        else sum += p[i];
    }
    
    cout << sum << endl;

    return 0;

}

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

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

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
  int n;
 
  scanf("%d",&n);
  
  if(n<=100 && n>=64)
    printf("64\n");
  
if(n<=63 && n>=32)
      printf("32\n");
 
  if(n<=31 && n>=16)
     printf("16\n");
    
  if(n<=15 && n>=8)
     printf("8\n");
    
  if(n<=7 && n>=4)
    printf("4\n");
  
   if(n<=3 && n>=2)
      printf("2\n");
  
  if(n==0 )
     printf("0\n");
  
 if(n==1)
    printf("1\n");
  
  return 0;
}
  
  

Measured memory_bytes: 128
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
  public static void Main() {
    var nml = Console.ReadLine().Split().Select(int.Parse).ToArray();
    var n = nml[0];
    var m = nml[1];
    var l = nml[2];
    int [][] arriveCost = Enumerable
      .Repeat(0, n)
      .Select(_ => Enumerable.Repeat(l + 1, n).ToArray())
      .ToArray();

    List< Tuple< int, int > >[] neibours
      = Enumerable.Repeat(0, n)
      .Select(_ => new List< Tuple< int, int > >())
      .ToArray();
    foreach (int i in Enumerable.Range(0, n))
      { arriveCost[i][i] = 0; }
    foreach (int _ in Enumerable.Range(0, m)) {
      var abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
      var a = abc[0] - 1;
      var b = abc[1] - 1;
      var c = abc[2];
      arriveCost[a][b] = Min(arriveCost[a][b], c);
      arriveCost[b][a] = Min(arriveCost[b][a], c);
    }

    foreach (int i in Enumerable.Range(0, n))
    foreach (int j in Enumerable.Range(0, n))
    foreach (int k in Enumerable.Range(0, n)) {
      arriveCost[j][k] = Min(arriveCost[j][k], arriveCost[j][i] + arriveCost[i][k]);
    }

    foreach (int i in Enumerable.Range(0, n))
    foreach (int j in Enumerable.Range(0, n)) {
      arriveCost[i][j] = arriveCost[i][j] <= l ? 1 : int.MaxValue / 2;
    }

    foreach (int i in Enumerable.Range(0, n))
    foreach (int j in Enumerable.Range(0, n))
    foreach (int k in Enumerable.Range(0, n)) {
      arriveCost[j][k] = Min(arriveCost[j][k], arriveCost[j][i] + arriveCost[i][k]);
    }

    StringBuilder builder = new StringBuilder();
    var q = int.Parse(Console.ReadLine());
    foreach (int _ in Enumerable.Range(0, q)) {
      var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
      var s = st[0] - 1;
      var t = st[1] - 1;
      builder.AppendLine((int.MaxValue / 2 == arriveCost[s][t] ? -1 : arriveCost[s][t] - 1)
        .ToString());
    }
    Console.WriteLine(builder.ToString());
  }
}


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

int main() {
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  
  if (a == 0){
  cout << 1 << endl ;
  } 
  else if(b == 0){
  cout << 2 << endl ;
  } 
  else if (c == 0){
  cout << 3 << endl ;
  } 
  else if (d == 0){
  cout << 4 << endl ;
  } 
  else{
  cout << 5 << endl ;
  } 


}

Measured memory_bytes: 3516
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int d(int h, int w) {
	return h*h+w*w;
}

int main() {
	int h, w;
	while(cin >> h >> w, h) {
		int dhw = d(h, w), bestd = INF, ansh, answ;
		FOR(i, 1, 150) {
			FOR(j, i+1, 150) {
				int dij = d(i, j);
				if(dhw == dij && h < i) {
					ansh = i;
					answ = j;
					goto show;
				}
				if(dhw < dij && dij < bestd) {
					ansh = i;
					answ = j;
					bestd = d(i, j);
				}
			}
		}
show:
		cout << ansh << " " << answ << endl;
	}

	return 0;
}

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

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 long long ll;
//typedef unsigned long long ull;
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;
//typedef unsigned int uint;

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;

string S;

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

	cin >> S;

	int N = SZ(S) - 1;
	string ts;
	int ans = 0;

	for (int i = 0; i < (1 << N); i++)
	{
		for (int j = 0; j < N; j++)
		{
			ts += S[j];
			if (i&(1 << (N - j - 1)))
			{
				ans += stoll(ts);
				ts.clear();
			}
		}
		ts += S[N];
		ans += stoll(ts);
		ts.clear();
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0

if(X >= 500):
 for i in range(A+1):
   for j in range(B+1):
     for k in range(C+1):
      if((500*i+100*j+50*k)==X):
        count += 1   
 print(count)

else:
 for j in range(B+1):
    for k in range(C+1):
      if((100*j+50*k)==X):
        count += 1   
 print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    ll S;
    cin >> S;
    if(S % 1000000000 == 0) {
        cout << 0 << " " << 0 << " " << 1000000000 << " " << 1 << " " << 0 << " " << (S + 1000000000 - 1) / 1000000000 << endl;
    }
    else {
        cout << 0 << " " << 0 << " " << 1000000000 << " " << 1 << " " << 1000000000 - (S % 1000000000) << " " << (S + 1000000000 - 1) / 1000000000 << endl;
    }
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::cmp::{max, min} ;

fn main() {
    input! {
        n: usize,
        p: [usize; n],
    }
    let mut ans = 0;
    let mut min = *(p.first().unwrap());
    for &p_i in &p {
        if  p_i <= min {
            min = p_i;
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define FORs(i,st) for(auto i : st)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    cin>>h>>w;
    vector<vector<ll>> v(h,vector<ll>(w,-1));
    deque<P> que;
    FOR(i,0,h){
      string s;
      cin>>s;
      FOR(j,0,w){
        if(s[j] == '#'){
          que.push_back(P(i,j));
          v[i][j] = 0;
        }
      }
    }

    while(!que.empty()){
      ll row = que.front().first;
      ll clm = que.front().second;
      que.pop_front();
      if(v[min(row+1,h-1)][clm] == -1){
        v[min(row+1,h-1)][clm] = v[row][clm] + 1;
        que.push_back(P(min(row+1,h-1), clm));
      }
      if(v[max(row-1,(ll)0)][clm] == -1){
        v[max(row-1,(ll)0)][clm] = v[row][clm] + 1;
        que.push_back(P(max(row-1,(ll)0), clm));
      }
      if(v[row][min(clm+1,w-1)] == -1){
        v[row][min(clm+1,w-1)] = v[row][clm] + 1;
        que.push_back(P(row, clm+1));
      }
      if(v[row][max(clm-1,(ll)0)] == -1){
        v[row][max(clm-1,(ll)0)] = v[row][clm] + 1;
        que.push_back(P(row, clm-1));
      }
    }

    ll ans = 0;
    FOR(i,0,h){
      FOR(j,0,w){
        ans = max(ans,v[i][j]);
      }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 24500
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    int N; cin>>N;
    for (int i = 1; i < 10; ++i) {
        for (int j = 1; j < 10; ++j) {
            if(i*j==N) {cout<<"Yes"<<endl;return 0;}
        }
    }
    cout<<"No"<<endl;

    return 0;
}

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

#define ll long long

int main()
{
    double L;
    std::cin >> L;

    //std::cout << L * L * L / 27.0 << std::endl;
    printf("%.7f\n", L*L*L/27);

    return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
typedef pair<int,int> pint;
const ll mod= 1e9+7;
const int inf=1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

ll x[3][100];
int main(){
  int n,c;
  cin>>n>>c;
  ll a[c][c];
  rep(i,c)rep(j,c)cin>>a[i][j];
  rep(i,n)rep(j,n){
    int y;cin>>y;
    y--;
    x[(i+j)%3][y]+=1;
    }
  ll dist[3][c];
  rep(i,3)rep(j,c)dist[i][j]=0;
  rep(i,3)rep(j,c)rep(k,c)
    dist[i][j]+=a[k][j]*x[i][k];
  ll ans=longinf;
  rep(i,c)rep(j,c)rep(k,c){
    if(i==j||j==k||k==i)continue;
    ans=min(dist[0][i]+dist[1][j]+dist[2][k],ans);
    }
  cout<<ans<<endl;
    

  return 0;
  }


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    for (int i = N; i <= 999; ++i)
    {
        if (i % 111 == 0)
        {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n,m = map(int,input().split())
    a = [list(map(int, input().split())) for i in range(n)]
    a.sort(key=lambda x:x[0])

    res = 0
    for i in a:
        mm = min(m,i[1])
        res += i[0]*mm
        m -= mm
        if m <= 0:
            break
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 64472
import java.util.Scanner

fun main(args: Array<String>) {
	val scanner = Scanner(System.`in`)
	val n = scanner.nextInt()
	val rs = Array(n){Pair(scanner.nextInt(), scanner.nextInt())}
	val bs = mutableListOf<Pair<Int, Int>>()
	repeat(n){bs.add(Pair(scanner.nextInt(), scanner.nextInt()))}

	rs.sortByDescending { Math.max(it.first, it.second) }
	bs.sortBy { Math.min(it.first, it.second) }
	var ans = 0

	for (r in rs) {
		for (b in bs){
			if (r.first<b.first && r.second<b.second) {
				ans++
				bs.remove(b)
				break
			}
		}
	}
	println(ans)
}

Measured memory_bytes: 36040
<?php 
fscanf(STDIN, "%d %d %d", $n, $a, $b);

$ans_arr = array();

for ($i=1; $i <$n+1 ; $i++) {
  $arr = array();
  $arr = str_split($i);
  if($a <= array_sum($arr) && array_sum($arr) <= $b){
    $ans_arr[] = $i;
  }
}
echo array_sum($ans_arr);

 ?>


Measured memory_bytes: 5108
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] d = new int[n];
        for(int i = 0; i < n; i++){
            d[i] = stdIn.nextInt();
        }
        Arrays.sort(d);
        System.out.println(d[ n / 2] - d[n /2 - 1]);    
    }
}

Measured memory_bytes: 50824
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <functional>
using namespace std;

#define rep(p,q) for(int i = p; i < q;i++)

//1

int main(void) {
	vector<int> mountain = vector<int>();
	rep(0, 10) {
		int x;
		cin >> x;
		mountain.push_back(x);
	}
	sort(mountain.begin(), mountain.end(), greater<int>());
	rep(0, 3) {
		cout << mountain[i] << endl;
	}
}



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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  int result = INT_MAX;
  for (i = 0; i < n - k + 1; i++) {
    result = min(result, h[i + k - 1] - h[i]);
  }

  cout << result << endl;


  return 0;
}


Measured memory_bytes: 640
a = []

for i in range(3):
  inp = list(map(int, input().split()))
  a.extend(inp)

# ビンゴ開始
n = int(input())
for i in range(n):
  n = int(input())
  if n in a:
    idx = a.index(n)
    a[idx] = 0

# 縦
for i in range(3):
  idx1 = 3 * 0 + i
  idx2 = 3 * 1 + i
  idx3 = 3 * 2 + i
  if a[idx1] == 0 and a[idx2] == 0 and a[idx3] == 0:
    print('Yes')
    exit(0)

# 横
for i in range(3):
  idx1 = 3 * i
  idx2 = 3 * i + 1
  idx3 = 3 * i + 2
  if a[idx1] == 0 and a[idx2] == 0 and a[idx3] == 0:
    print('Yes')
    exit(0)

# ななめ
if (a[0] == 0 and a[4] == 0 and a[8] == 0) or (a[2] == 0 and a[4] == 0 and a[6] == 0):
  print('Yes')
  exit(0)

print('No')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int sum = 0;
    for(int i = 1; i <= n; i++){
        int x = i;
        int s = 0;
        while(x > 0){
            s += x%10;
            x /= 10;
        }
        if(s >= a && s <= b) sum += i;
    }
    cout << sum;
}

Measured memory_bytes: 256
import sys
sysinput = sys.stdin.readline

N = int(sysinput())
P = list(map(int, sysinput().split()))
memo_mini = N
i_count = 0
for i in range(0, N):
  if memo_mini >= P[i]:
      i_count +=1
      memo_mini = P[i]
  else:
    pass
  
print(i_count)

Measured memory_bytes: 23572
import math
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

N = I()
L = LI()
count =0
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      flag = 0
      l1 = [L[i],L[j],L[k]]
      l = sorted(l1)
      for n in range(3):
        if(l.count(l[n])>1):
          flag = 1
      if(flag == 0):
        if(l[1]-l[0] < l[2] and l[1]+l[0] > l[2]):
          count += 1
print(count)

Measured memory_bytes: 9244
#include <stdio.h>
#include <algorithm>
#define SIZE 100005
  int dp[SIZE][3], val[SIZE][3];

  int main(void) {
        int n;
        scanf("%d",&n);
        for(int i=0; i<n; i++) scanf("%d %d %d",&val[i][0],&val[i][1],&val[i][2]);

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

        for(int i=1; i<n; i++) {
                dp[i][0] = val[i][0] + std::max(dp[i-1][1], dp[i-1][2]);
                dp[i][1] = val[i][1] + std::max(dp[i-1][0], dp[i-1][2]);
                dp[i][2] = val[i][2] + std::max(dp[i-1][0], dp[i-1][1]);
        }

        printf("%d",std::max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}));
        return 0;
  }






Measured memory_bytes: 2560
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int n;
string s;

void reverse(int l, int r) {
  while (l < r) {
    swap(s[l], s[r]);
    l++; r--;
  }
}

bool isPalindrome(int l, int r) {
  while (l < r) {
    if (s[l] != s[r]) {
      return false;
    }
    l++; r--;
  }
  return true;
}

int main() { 

  getline(cin, s);
  n = sz(s);

  long long ans = 1 + 1ll * n * (n + 1) / 2;

  // map<string, vector<string>> res;
  // set<string> st;
  // for (int i = 0; i < n; i++) {
  //   for (int j = i; j < n; j++) {
  //     reverse(i, j);
  //     st.insert(s);
  //     res[s].push_back(to_string(i) + " " + to_string(j) + " " + to_string(isPalindrome(i, j)));
  //     // cout << i << " " << j << " " << s << endl;
  //     reverse(i, j);
  //     // if (isPalindrome(i, j)) {
  //     //   ans--;
  //     // }
  //   }
  // }
  // for (auto p : res) {
  //   cout << p.first << endl;
  //   for (auto x : p.second) {
  //     cout << x << endl;
  //   }
  //   cout << endl;
  // }
  // cout << "Right count is " << sz(st) << endl;

  // for (int i = 0; i < n; i++) {
  //   for (int j = i; j < n; j++) {
  //     for (int k = i; k <= j; k++) {
  //       for (int l = k; l < n; l++) {
  //         if (k == i && l == j) {
  //           continue;
  //         }
  //         if (isPalindrome(i, j) && isPalindrome(k, l)) {
  //           ans--;
  //         }
  //       }
  //     }
  //   }
  // }

  map<char, int> cnt;
  for (int i = 0; i < n; i++) {
    cnt[s[i]]++;
    ans -= cnt[s[i]];
  }

  cout << ans << endl;

  return 0;
}


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

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static long Calc(int[] xs) {
        var sum = new long[xs.Length];
        sum[0] = xs[0];
        for (int i = 1; i < xs.Length; i++) {
            sum[i] = sum[i - 1] + xs[i];
        }

        long ans = long.MaxValue;
        for (int i = 0; i < xs.Length - 1; i++) {
            long a = sum[i];
            long b = sum[xs.Length-1] - a;

            ans = Math.Min(ans, Math.Abs(a - b));
        }
        return ans;
    }

    static void Main() {
        ReadInt();
        var xs = ReadInts();
        Console.WriteLine(Calc(xs));
    }
}

Measured memory_bytes: 31580
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Segment_Tree{
	private:
	int n;
	vi date;
	public:
	Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vi(2*n-1);
	}
	void Update(int k,int x){
		k+=n-1;
		date[k]+=x;
		while(k>0){
			k=(k-1)/2;
			date[k]=date[k*2+1]+date[k*2+2];
		}
	}
	int Query(int a,int b){
		a+=n-1;b+=n-1;
		int m=0;
		while(a<b){
			if(a%2==0) m+=date[a++];
			if(b%2==0) m+=date[--b];
			a/=2;b/=2;
		}
		return m;
	}
	int Open(int k){return date[k+n-1];}
};

int n,q;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>q;
	Segment_Tree st(n);
	for(int i=0;i<q;i++){
		int t,A,B;
		cin>>t>>A>>B;
		if(t) cout<<st.Query(A,B+1)<<endl;
		else st.Update(A,B);
	}
}


Measured memory_bytes: 3900
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

c = 0
for i in range (N):
    if B[i] >= A[i]:
        c += A[i]
        if A[i+1] >= B[i] -A[i]:
            A[i+1] -= B[i] - A[i]
            c += B[i] - A[i]
        else:
            c += A[i+1]
            A[i+1] = 0
    else:
        c += B[i]

print(c)

Measured memory_bytes: 82020
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,m,a,b,ans=1,x,y;
    vector<pair<int,int>> C;
    cin>>n>>m;
    rep(i,m) cin>>a>>b,C.push_back(make_pair(a,b));
    sort(C.begin(),C.end());
    x=C[0].first,y=C[0].second;
    rep(i,m-1){
        if(x>=C[i+1].second||y<=C[i+1].first) ans++,x=C[i+1].first,y=C[i+1].second;
        else x=max(x,C[i+1].first),y=min(y,C[i+1].second);
    }
    cout<<ans;
}

Measured memory_bytes: 1400
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"


def main():
    S = input()
    rlc = [(k, len(list(g))) for k, g in groupby(S)]
    ans = 0
    for i in range(1, len(rlc) - 1):
        a, b, c = rlc[i - 1], rlc[i], rlc[i + 1]
        if a[0] == "J" and b[0] == "O" and c[0] == "I":
            if b[1] <= a[1] and b[1] <= c[1]:
                ans = max(ans, b[1])
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 80548
from itertools import permutations
num, target = map(int, input().split(" "))
coin = [1000, 5000, 10000]
for i in range(num + 1):
    for j in range(num + 1 - i):
        k = num - i - j
        if target == (1000 * k + 5000 * j + 10000 * i):
            print(i, j, k)
            exit()
else:
    print(-1, -1, -1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m;
int a[10];
int num[10]={-1,2,5,5,4,5,6,3,7,6};
int dp[10010];
string ans="";
int main(){
	cin>>n>>m;
	REP(i,10010)dp[i]=-1;
	REP(i,m)cin>>a[i];
	sort(a,a+m,greater<int>());
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<m;j++){
			if(i-num[a[j]]>=0){
				if(dp[i-num[a[j]]]!=-1){
					dp[i]=max(dp[i],dp[i-num[a[j]]]+1);
				}
			}
		}
		//cout<<i<<endl;
	}
	int n1=n;
	//REP(i,16)cout<<i<<" "<<dp[i]<<endl;
	for(int i=0;i<dp[n];i++){
		for(int j=0;j<m;j++){
			if(n1-num[a[j]]>=0&&dp[n1-num[a[j]]]+1==dp[n1]){
				ans=ans+to_string(a[j]);
				n1-=num[a[j]];
				break;
			}
		}
		//cout<<n1<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256