akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int price[41][401][401];
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, ma, mb;
  cin >> n >> ma >> mb;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
  int inf = 100000;
  for (int i = 0; i < 41; i++) {
    for (int j = 0; j < 401; j++) {
      for (int k = 0; k < 401; k++) {
        price[i][j][k] = inf;
      }
    }
  }
  price[0][0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10 * i; j++) {
      for (int k = 0; k <= 10 * i; k++) {
        if (price[i][j][k] == inf) continue;
        price[i + 1][j][k] = min(price[i + 1][j][k], price[i][j][k]);
        price[i + 1][j + a[i]][k + b[i]] = min(price[i + 1][j + a[i]][k + b[i]], price[i][j][k] + c[i]);
      }
    }
  }
  int ans = inf;
  for (int i = 1; i <= 10 * n; i++) {
    for (int j = 1; j <= 10 * n; j++) {
      if (i * mb == j * ma) {
        ans = min(ans, price[n][i][j]);
      }
    }
  }
  if (ans == inf) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 25984
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();
		Counter counter = new Counter(h, w);
		int[][] field = new int[h][w];
		for (int i = 1; i <= n; i++) {
		    int x = sc.nextInt();
		    for (int j = 0; j < x; j++) {
		        field[counter.y][counter.x] = i;
		        counter.next();
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < h; i++) {
		    for (int j = 0; j < w; j++) {
		        if (j > 0) {
		            sb.append(" ");
		        }
		        sb.append(field[i][j]);
		    }
		    sb.append("\n");
		}
		System.out.print(sb);
   }
   
   static class Counter {
       int height;
       int width;
       int y;
       int x;
       
       public Counter (int height, int width) {
           this.height = height;
           this.width = width;
       }
       
       public void next() {
           if (y % 2 == 0) {
               if (x == width - 1) {
                   y++;
               } else {
                   x++;
               }
           } else {
               if (x == 0) {
                   y++;
               } else {
                   x--;
               }
           }
       }
   }
}



Measured memory_bytes: 32108
#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 rep(i,n) for(int i=0;i<(n);++i)
const double pi=acos(-1.0);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;cin >> n >> k;
	vector<ll> a(100001);
	rep(i,n){
		int x,y;cin >> x >> y;
		a.at(x)+=y;
	}
	ll cnt=0;
	rep(i,100001){
		cnt+=a.at(i);
		if(cnt>=k){
			cout << i << endl;
			return 0;
		}
	}
}

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

bool alpha_count[26];

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++) alpha_count[s[i] - 'a'] = true;
    for (int i = 0; i < 26; i++) {
        if (!alpha_count[i]) {
            cout << char(i + 'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main() {
	long long N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	cout << max({ (N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D, (N - 1) / E }) + 5 << endl;
	return 0;
}

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

int main(){
    int n,l;
    std::map<std::string, int> m;
    std::cin >> n;
    std::string str;
    for(int i = 0; i < n; i++){
        std::cin >> str;
        if(m.find(str) == m.end()){
            m[str] = 1;
        }else{
            m[str]++;
        }
    }
    std::cin >> l;
    for(int i = 0; i < l; i++){
        std::cin >> str;
        if(m.find(str) == m.end()){
            m[str] = -1;
        }else{
            m[str]--;
        }
    }

    auto&& ret = std::max_element(m.begin(), m.end(), [](auto&& a, auto&& b){ return a.second < b.second; });

    std::cout << std::max(ret->second,0) << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,K;
#define Maxn 200010
int a[Maxn];
int b[Maxn];
int main(){
	scanf("%d%d",&n,&K);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<=K;++i){
		memset(b,0,sizeof(int)*(n+1));
		for(int i=1;i<=n;++i){
			b[max(0,i-a[i])]++;
			b[min(n+1,i+a[i]+1)]--;
		}
		bool flag=true;
		for(int i=1;i<=n;++i){
			b[i]+=b[i-1];
            if(b[i]!=a[i])flag=false;
            a[i]=b[i];
		}
		if(flag)break;
	}
	for(int i=1;i<=n;++i)printf("%d ",a[i]);
	return 0;
}

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

#define LOCAL 0

#define lli long long int
#define llu unsigned long long int
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const long double EPS = 1e-10;
const int MOD = 1000000007ll;
const int mod1 = 1000000009ll;
const int mod2 = 1100000009ll;
int INF = (int)1e9;
lli INFINF = (lli)1e18;
int debug = 0;
long double PI = acos(-1.0);

using namespace std;

int bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
int bit(lli _mask,int _i){return (_mask&(1ll<<_i))==0?0:1;}
int add(int a,int b,int m=MOD){int x=a+b;while(x>=m)x-=m;while(x<0)x+=m;return x;}
int sub(int a,int b,int m=MOD){int x=a-b;while(x<0)x+=m;while(x>=m)x-=m;return x;}
int mul(int a,int b,int m=MOD){lli x=a*1ll*b;x%=m;while(x<0)x+=m;return (int)x;}
int ldtoint(ld x){return (int)(x+0.5);}lli ldtolli(ld x){return (lli)(x+0.5);}
int powermod(lli _a,lli _b,int _m=MOD){lli _r=1;while(_b){if(_b%2==1)_r=mul(_r,_a,_m);_b>>=1;_a=mul(_a,_a,_m);}return _r;}

template<class T1,class T2>ostream&operator<<(ostream& os,const pair<T1,T2>&p){os<<"["<<p.first<<","<<p.second<<"]";return os;}
template<class T>ostream&operator<<(ostream& os,const vector<T>&v){os << "[";bool first=true;for (T it:v){if (!first)os<<", ";first = false;os<<it;}os<<"]";return os;}
template<class T>ostream&operator<<(ostream& os,set<T>&v){os<<"[";bool first=true;for (T it:v){if(!first)os<<", ";first=false;os<<it;}os<<"]";return os;}
template<class T1,class T2>ostream&operator<<(ostream& os,map<T1,T2>&v){os<<"[";bool first=true;for(pair<T1,T2> it:v){if(!first)os<<", ";first=false;os<<"("<<it.F<<","<<it.S<<")";}os<<"]";return os;}
template<class T>void parr(T a[],int s,int e){cout<<"[";for(int i=s;i<e;i++)cout<<a[i]<<", ";cout<<a[e]<<"]\n";}



int main()
{
if(LOCAL){
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    debug = 1;
}
    srand (time(NULL));

    lli N,M;
    lli ans = 0;
    cin>>N>>M;
    ans += min(N,M/2);
    N -= ans;
    M -= ans*2;
    if(M!=0){
        ans += M/4;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		int x, y;
		int maxX = -101;
		int minY = 101;

		for(int i = 0; i < N; i++) {
			x = sc.nextInt();
			if(x > maxX) {
				maxX = x;
			}
		}
		for(int i = 0; i < M; i++) {
			y = sc.nextInt();
			if(y < minY) {
				minY = y;
			}
		}

		if(X + 1 <= Y && maxX + 1 <= minY && X < maxX && minY <= Y) {
			System.out.println("No War");
		} else {
			System.out.println("War");
		}
	}

}

Measured memory_bytes: 23380
import time
import random


class TreapNode:
    def __init__(self, key, pri):
        self.left = None
        self.right = None
        self.key = key
        self.pri = pri


class Treap:
    def __init__(self):
        self.root = None

    def search_lower(self, key):
        if key == None:
            return None
        ptr = self.root
        ret = None
        while ptr is not None:
            pk = ptr.key
            if pk < key:
                ret = pk
                ptr = ptr.right
            else:
                ptr = ptr.left
        return ret

    def search_higher(self, key):
        if key == None:
            return None
        ptr = self.root
        ret = None
        while ptr is not None:
            pk = ptr.key
            if pk > key:
                ret = pk
                ptr = ptr.left
            else:
                ptr = ptr.right
        return ret

    def insert(self, key):
        pri = random.randrange(0, 2**25)
        ptr = self.root
        elem = TreapNode(key, pri)
        if ptr is None or ptr.pri < pri:
            self.root = elem
        else:
            while True:
                if key < ptr.key:
                    left = ptr.left
                    if left is None or left.pri < pri:
                        ptr.left = elem
                        ptr = left
                        break
                    ptr = left
                else:
                    right = ptr.right
                    if right is None or right.pri < pri:
                        ptr.right = elem
                        ptr = right
                        break
                    ptr = right
        left = elem
        right = elem
        while ptr is not None:
            if key < ptr.key:
                right.left = ptr
                right = ptr
                ptr = ptr.left
            else:
                left.right = ptr
                left = ptr
                ptr = ptr.right
        left.right = None
        right.left = None
        elem.left, elem.right = elem.right, elem.left

# デバッグ用
    def dump(self):
        self.__dump(self.root, 0)

    def __dump(self, idx, dep):
        if idx is not None:
            self.__dump(idx.right, dep + 1)
            for _ in range(0, dep):
                print("   ", end="")
            print([idx.key, idx.pri])
            self.__dump(idx.left, dep + 1)

def main():
    n = int(input())
    p = list(map(int, input().split()))
    idx = [0] * n
    for i in range(0, n):
        idx[i] = i
    idx.sort(key=lambda i: - p[i])
    t = Treap()
    t.insert(-1)
    t.insert(n)
    ans = 0
    for i in idx:
        nex = t.search_higher(i)
        nexnex = t.search_higher(nex)
        pre = t.search_lower(i)
        prepre = t.search_lower(pre)
        if prepre != None:
            ans += p[i] * (pre - prepre) * (nex - i)
        if nexnex != None:
            ans += p[i] * (i - pre) * (nexnex - nex)
        t.insert(i)
    print(ans)


main()


Measured memory_bytes: 83176
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=[("0"*40+bin(A[i])[2:])[-40:] for i in range(N)]

cnt="".join([str(int(sum([int(B[i][j]) for i in range(N)]) < (N+1)//2)) for j in range(40)])
M=("0"*40+bin(M)[2:])[-40:]

for i in range(40):
    if cnt > M:
        cnt=list(cnt)
        cnt[i]=str(int(cnt[i])&int(M[i]))
        cnt="".join(cnt)
    else:
        break

k=int(cnt,2)
print(sum([k^A[i] for i in range(N)]))

Measured memory_bytes: 21868
//
// Created by 加藤英祐 on 2020/04/14.
//
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    vector<int> city(N);
    for (int i = 0; i < M; ++i) {
        int a,b;
        cin >> a >> b;
        city.at(a-1)++;
        city.at(b-1)++;
    }
    for (int i = 0; i < N; ++i) {
        cout << city.at(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
 
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() {
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

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


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  char a, b;
  cin >> a >> b;
  string ans;
  if(a=='H'){
    if(b=='H') ans = "H";
    else ans = "D";
  }else{
    if(b=='H') ans = "D";
    else ans = "H";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;

int main(){
    fastio;
    int n;
    ll ans = 0;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            for(int k = 1; k <= n; ++k){
                ans += __gcd(i, __gcd(j, k));
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#define MAX 1000000007
int main(void){
    // Your code here!
    
    char yoho[4];
    char real[4];
    
    scanf("%s\n",&yoho);
    scanf("%s\n",&real);
    
    int i;
    int ct = 0;
    for(i=0;3>i;i++){
        if(yoho[i]==real[i]) ct++;
    }
    
    printf("%d",ct);

    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<int>> e(n);
	vector<int> d(n);
	for(int i = 0;i < n;i++)d[i] = INF;

	vector<int> in_deg(n,0);
	for(int i = 0;i < n - 1 + m;i++){
		int a,b;
		cin >> a >> b;
		a--,b--;
		e[a].push_back(b);
		in_deg[b]++;
	}

	int s;
	for(int i = 0;i < n;i++){
		if(in_deg[i] == 0)s = i;
	}

	d[s] = 0;
	vector<int> par(n,0);

	queue<int> que;
	que.push(s);
	while(que.size()){
		int now = que.front();
		que.pop();
		for(int next:e[now]){
			in_deg[next]--;
			if(in_deg[next] == 0){
				que.push(next);
				par[next] = now + 1;
			}
		}
	}

	for(int i = 0;i < n;i++){
		cout << par[i] << endl;
	}
}


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

using namespace std;

#define all(a) a.begin(), a.end()
#define pi acos(-1)
#define eps 1e-6
#define inf 1e14

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[8] = {-1, 0, 1, -1, 1, 0, 1, -1};
const int maxn = 2 * 1e5;
const int mod = 1e9 + 7;
const int maxa = 2 * 1e5;

int mul(int a, int b) { return a * 1LL * b % mod;}
int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b;}
int sub(int a, int b) { return a >= b ? a - b : a - b + mod;}
int pow(int a, int k)
{
    int res = 1;
    while (k)
    {
        if (k % 2) res = mul(res, a);
        a = mul(a, a);
        k /= 2;
    }

    return res;
}

int inv(int a)
{
    return pow(a, mod - 2);
}

int dp[maxn], n, h[maxn];

int f(int id)
{
    if (id == n - 1)
        return 0;

    if (dp[id] != -1)
        return dp[id];

    dp[id] = f(id + 1) + abs(h[id] - h[id + 1]);
    
    if (id + 2 <= n - 1)
        dp[id] = min(dp[id], f(id + 2) + abs(h[id] - h[id + 2]));
                     
    return dp[id];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> h[i];

    cout << f(0);
}


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

using namespace std;
typedef long long ll;

const int N = 1000006;

int n;
char s[N];

int fm[N];
int p[N];

ll f(int k){
    ll ans = 0, par = 0;
    int cnt_d = 0, cnt_m = 0;
    
    for(int i = 0; i < k; i++){
        if(s[i] == 'D'){
            cnt_d++;
        }
        else if(s[i] == 'M'){
            par += cnt_d;
            cnt_m++;
        }
        else if(s[i] == 'C'){
            ans += par;
        }
    }

    for(int i = k; i < n; i++){
        if(s[i-k] == 'D'){
            par -= cnt_m;
            cnt_d--;
        }
        else if(s[i-k] == 'M'){
            cnt_m--;
        }
        else if(s[i-k] == 'C'){
        }

        assert(par >= 0);

        if(s[i] == 'D'){
            cnt_d++;
        }
        else if(s[i] == 'M'){
            par += cnt_d;
            cnt_m++;
        }
        else if(s[i] == 'C'){
            ans += par;
        }
    }
    return ans;
}

int main(){

    scanf("%d %s", &n, s);

    fm[n] = n;
    for(int i = n-1; i >= 0; i--){
        if(s[i] == 'M') fm[i] = i;
        else fm[i] = fm[i+1];
        p[i] = int(s[i] == 'C');
    }
    partial_sum(p, p+n, p);

    int q, k;

    scanf("%d", &q);

    while(q--){
        scanf("%d", &k);
        ll ans = f(k);
        printf("%lld\n", ans);
    }

}


Measured memory_bytes: 9216
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::vector<std::vector<int>> a(2, std::vector<int>(n));
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < n; j++){
            std::cin >> a[i][j];
        }
    }

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

    std::cout << dp[1][n - 1] << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



// 10000*a + 5000*b + 1000*c = Y, a+b+c = N
int Y, N;

int solve() {
	for (int a = 0; a <= N; a++) {
		for (int b = 0; b <= N-a; b++) {
			int c = N - a - b;
			if (1000 * c + 5000 * b + 10000 * a == Y) {
				cout << a << " " << b << " " << c << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;

	return 0;
}


int main() {

	cin >> N >> Y;

	solve();


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <map>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (long long i = init; i < (n); i++)

int main()
{
    long long n, k;
    cin >> n >> k;
    map<long long, long long> ab;
    repi(i, n, 0)
    {
        long long a, b;
        cin >> a >> b;
        if (ab.count(a))
        {
            ab[a] += b;
        }
        else
        {
            ab.insert(pair<long long, long long>(a, b));
        }
    }
    long long sum = 0;
    for (auto itr = ab.begin(); itr != ab.end(); itr++)
    {
        sum += itr->second;
        if (sum >= k)
        {
            cout << itr->first << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 4224
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int N,M,A[100001],B[100001];
vint AB[300001];
int main(){
	priority_queue<int> Q;
	scan(N>>M);
	rep(i,N){
		scan(A[i]>>B[i]);
		AB[A[i]].push_back(B[i]);
	}
	ll ans=0;
	rep1(day,M){
		rep(i,(int)AB[day].size()){
			Q.push(AB[day][i]);
		}
		if(Q.size()){
			ans+=Q.top();
			Q.pop();
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 11136
#include <stdio.h>
#include <memory.h>
#include <vector>

using namespace std;

typedef vector<long long> Array;
typedef vector<Array> Matrix;

//FILE *in = freopen("input.txt", "r", stdin);
//FILE *out = freopen("output.txt", "w", stdout);

int N, M, A, B, C, T;
long long S[100];
long long res[100];

Matrix mat;

void input() {
	memset(S, 0, sizeof(S));
	memset(res, 0, sizeof(res));
	mat.clear();
	for(int i = 0; i < N; i++) {
		scanf("%d", &S[i]);
		mat.push_back(Array(N));
		mat[i][i] = 1;
	}
}

Matrix mul(const Matrix &a, const Matrix &b) {
	Matrix res(a.size(), Array(b[0].size()));
	for(int i = 0; i < a.size(); i++) {
		for(int j = 0; j < b[0].size(); j++) {
			for(int k = 0; k < a[0].size(); k++) {
				res[i][j] = (res[i][j] + a[i][k]*b[k][j])%M;
			}
		}
	}
	return res;
}

Matrix matmul(int n) {
	if(n == 1)
		return mat;
	Matrix res = matmul(n/2);
	res = mul(res, res);
	if(n&1)
		res = mul(res, mat);
	return res;
}

void process() {
	for(int i = 0; i < N; i++) {
		if(i-1 >= 0) 
			mat[i][i-1] = A;
		mat[i][i] = B;
		if(i+1 < N)
			mat[i][i+1] = C;
	}

	mat = matmul(T);
}

void output() {
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			res[i] = (res[i] + mat[i][j]*S[j])%M;
		}
	}

	for(int i = 0; i < N - 1; i++) {
		printf("%Ld ", res[i]);
	}
	printf("%Ld\n", res[N-1]);
}

int main() {
	while(true){
		scanf("%d%d%d%d%d%d", &N, &M, &A, &B, &C, &T);
		if(N == 0) break;
		input();
		if(T)
			process();
		output();
	}
	return 0;
}

Measured memory_bytes: 1108
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()
A, B = LI()
P = LI()

a, b, c = 0, 0, 0
for p in P:
    if p <= A:
        a += 1
    elif p <= B:
        b += 1
    else:
        c += 1

print(min(a, b, c))


Measured memory_bytes: 3064
S = list(input())
now = 0
ans = 0
while now < len(S) - 1:
    if S[now] != S[now + 1]:
        for _ in range(2):
            S.pop(now)
        now = max(0, now - 1)
        ans += 2
    else:
        now += 1
print(ans)

Measured memory_bytes: 3956
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define moder 1000003
#define double long double
#define INF LLONG_MAX/10000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int q, x, d, n, kaijo[2000020];
int mypow(int a, int b) {
	if (!b)return 1;
	if (b % 2)return mypow(a, b - 1) * a % moder;
	int memo = mypow(a, b / 2);
	return memo * memo% moder;
}
signed main() {
	kaijo[0] = 1;
	REP(i, 2000010)kaijo[i] = kaijo[i - 1] * i % moder;
	cin >> q;
	rep(i, q) {
		cin >> x >> d >> n;
		if (!d) {
			cout << mypow(x, n) << endl;
			continue;
		}
		int memo = x * mypow(d, moder - 2) % moder;
		if (moder - 1 < memo + n - 1 || !memo)cout << 0 << endl;
		else cout << kaijo[memo + n - 1] * mypow(kaijo[memo - 1], moder - 2) % moder * mypow(d, n) % moder << endl;
	}
	return 0;
}

Measured memory_bytes: 16512
#include <stdio.h>

int main(){
    int N,M,X,A[100];
    int i,cnt;
    scanf("%d",&N);
    scanf("%d",&M);
    scanf("%d",&X);
    for(i=0;i<M;i++){
    scanf("%d",&A[i]);    
    } 
    /*printf("%d,%d\n",A[0],A[1]);
    /*printf("%d,%d\n",input[1],B);
    printf("%d,%d\n",input[2],X);*/
    cnt=0;
    for(i=0;i<M;i++){
        if(A[i]>X){
            cnt++;
        }
    }
    if(M-cnt>cnt){
        printf("%d",cnt);
    }else{
        printf("%d",M-cnt);
    }
    return 0;
}

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

int main(){
  string s; cin >> s ;
  int ans = 0;
  int curr = 0;
  for (int i = 0; i< s.length();i++ ){
    if ((s.at(i) == 'A') || (s.at(i) == 'T') || (s.at(i) == 'C') || (s.at(i) == 'G') ){
      curr++;
    }else{
      ans = max(ans, curr);
      curr = 0;
  }
    if (i==s.length()-1){
      
      ans = max(ans, curr);
  }}
  cout << ans <<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
      int len = s.length(); 
      int ans = 753;
      int x = 0;
      int xx = 753;
      String list[] = s.split("");    
		int[] a = new int[len];
		for(int i=0; i<len; ++i){
			a[i] = Integer.parseInt(list[i]);
		}
      for(int i=0; i<len-2; ++i){
        x = a[i]*100 + a[i+1]*10 + a[i+2];
        xx = Math.abs(753-x);
        if(ans>xx){
          ans = xx;
        }
      }
      System.out.println(ans);
	}
}


Measured memory_bytes: 35684
def get_gcd(a, b)
  rest = a % b

  return b if rest.zero? || rest == b

  get_gcd(b, rest)
end

STDIN.read.chomp.split("\n").each do |list|
  elems = list.split.map(&:to_i).sort_by {|i| -i }
  gcd = get_gcd *elems
  lcm = elems.inject(:*) / gcd

  puts "#{gcd} #{lcm}"
end

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n;
  string s;
  cin >> n >> s;
  string ans = s;
  int status = 0;
  for(int i = 0; i < n; ++i)
  {
    if (s[i] == '(') status++;
    if (s[i] == ')') status--;
    if (status < 0)
    {
      ans = '(' + ans;
      status++;
    }
  }
  for(int i = 0; i < status; ++i)
  {
    ans += ')';
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3576
import copy
s = list(input())
n = len(s)
s2 = copy.deepcopy(s)
la = s[-1]
for i in range(n):
    if s[i] == la:
        s2.append(la)
    else:
        break

n2 = len(s2)
k = int(input())
if n2 == 2*n:
    print(n*k//2)
    exit()
count = 0
for i in range(n2-n+1,n2):
    if s2[i] == s2[i-1]:
        s2[i] = "1"
        count += 1
ans = k*count

c = 0

for i in range(n-1,-1,-1):
    if la == s[i]:
        c += 1
    else:
        break

if n2 > n and (n2-n)%2 and c > 1 and c%2:
    ans -= 1
print(ans)

Measured memory_bytes: 9344
num = gets.to_i
input = gets.to_s.split(" ").map(&:to_i)
answer = 0
for i in 0..num-2 do
  min1 = input.min
  min_index1 = input.index(min1)
  input.delete_at(min_index1)

  min2 = input.min
  min_index2 = input.index(min2)

  input.delete_at(min_index2)
  answer = (min1 + min2) / 2.to_f

  input.push(answer)

end

puts input

Measured memory_bytes: 3836
n = int(input())
b = list(map(int, input().strip().split()))
a = [0] * n

a[0] = b[0]
a[1] = b[0]
for i in range(1,n-1):
    a[i] = min(a[i],b[i])
    a[i+1] = b[i]

print(sum(a))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memset( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

const int MAXN = 200020;
const int INF = 0x3f3f3f3f;

int n, m, v[22], tot, a[MAXN], d[MAXN];
int f[MAXN][22], g[MAXN][22];
int dpl[MAXN << 2], dpr[MAXN << 2], ans[MAXN];

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	scanf( "%d%d", &n, &m );
	for( int i = 1 ; i <= n ; i++ ) scanf( "%d", &a[ i ] );
	while( m ) v[ tot++ ] = m, m >>= 1;
	v[ tot++ ] = 0;
	d[ 1 ] = d[ n + 1 ] = INF;
	for( int i = 2 ; i <= n ; i++ ) d[ i ] = a[ i ] - a[ i - 1 ];
	for( int j = 0 ; j < tot ; j++ )
	{
		for( int i = 1 ; i <= n ; i++ )
			if( d[ i ] > v[ j ] ) f[ i ][ j ] = i;
			else f[ i ][ j ] = f[ i - 1 ][ j ];
		for( int i = n ; i ; i-- )
			if( d[ i + 1 ] > v[ j ] ) g[ i ][ j ] = i;
			else g[ i ][ j ] = g[ i + 1 ][ j ];
	}
	fill( dpr, 0x3f );
	dpr[ 0 ] = n + 1;
	for( int i = 0 ; i < ( 1 << tot ) ; i++ )
		for( int j = 0 ; j < tot ; j++ ) if( !( i >> j & 1 ) )
		{
			if( dpl[ i ] >= n ) dpl[ i | ( 1 << j ) ] = n;
			else dpl[ i | ( 1 << j ) ] = max( dpl[ i | ( 1 << j ) ], g[ dpl[ i ] + 1 ][ j ] );
			if( dpr[ i ] <= 1 ) dpr[ i | ( 1 << j ) ] = 1;
			else dpr[ i | ( 1 << j ) ] = min( dpr[ i | ( 1 << j ) ], f[ dpr[ i ] - 1 ][ j ] );
		}
	for( int i = 0 ; i < ( 1 << tot ) ; i++ )
	{
		if( i & 1 ) continue;
		int l = dpl[ i ], r = dpr[ ( 1 << tot ) - 1 - i - 1 ];
		if( l + 1 >= r ) ans[ 1 ]++;
		else
		{
			int L = f[ l + 1 ][ 0 ], R = g[ l + 1 ][ 0 ];
			if( R + 1 >= r )
			{
				if( L > R )
				{
					int c[ ( l + 1 ) * 1000 ];
					fill( c, 0 );
					return 0;
				}
				ans[ L ]++, ans[ R + 1 ]--;
			}
		}
	}
	for( int i = 1, cur = 0 ; i <= n ; i++ )
	{
		cur += ans[ i ];
		if( cur ) puts( "Possible" );
		else puts( "Impossible" );
	}
}


Measured memory_bytes: 44544
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void solve(long long d, int x, vector<long long> &dp)
{
	if (d == 1) {
		for(int i = 0; i < dp.size() && i < x; i ++) dp[i] = 1;
		return;
	}
	vector<long long> A(dp.size());
	if (d & 1) {
		solve(d - 1, x, A);
		for(int i = 0; i < x; i ++){
			for(int j = 0; j + i < dp.size(); j ++){
				dp[i + j] += A[j]; 
				if (dp[i + j] >= mod) dp[i + j] -= mod;
			}
		}
	}
	else{
		solve(d >> 1, x , A);
		for(int i = 0; i < dp.size(); i ++){
			for(int j = 0; j + i < dp.size(); j ++){
				dp[i + j] += A[j] * A[i] % mod; 
				if (dp[i + j] >= mod) dp[i + j] -= mod;
			}
		}
	}
}

int main()
{
	int x, n;
	long long d;
	while(~scanf("%d%lld%d", &n, &d, &x)) {
		if (!n && !d && !x) break;
		vector<long long> dp(n + 1);
		solve(d, x, dp);
		printf("%lld\n", dp[n]);
	}
	return 0;
}

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

int main(){
    int n , temp ;
    vector<int> v ;
    cin >> n ;
    for(int i=0 ; i<n ;i++){
        cin >> temp  ;
        v.push_back(temp) ;
    }
    sort(v.begin(),v.end()) ;

    cout << v[n/2] - v[(n/2)  -1] <<endl ;
    return 0 ;
}


Measured memory_bytes: 892
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		int N = (int)Long.parseLong(W);

		W = in.readLine();
		String[] Ws = W.split(" ");
		long[] A = new long[Ws.length+2];
		A[0]=0;
		A[A.length-1]=0;
		for (int i = 0; i < Ws.length; i++) {
			A[i+1] = Long.parseLong(Ws[i]);
		}

		long sum = 0;
		for(int i=1;i<A.length;i++){
			sum+=Math.abs(A[i-1]-A[i]);
		}

		long ans = 0;

		for(int i=1;i<A.length-1;i++){
			System.out.println(sum - (Math.abs(A[i-1]-A[i]) + Math.abs(A[i]-A[i+1]))+ Math.abs(A[i-1]-A[i+1]));
		}
	}
}


Measured memory_bytes: 48500
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
using namespace std;

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

int main() {
	

	int n;
	cin >> n;
	vector<int>x, y;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		x.push_back(t);
		y.push_back(t);
		
	}
	sort(y.begin(),y.end());
	int r = y[(n)/2];
	for (int i = 0; i < x.size(); i++) {
		
		if (x[i] < r)cout <<r;
		else cout <<  y[(n  / 2)-1 ];
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    vector<char> s(19);
    for (int i = 0; i < 19; i++) {
        cin >> s.at(i);
        if (s.at(i) == ',') s.at(i) = ' ';
        
        if (i + 1 == 19) {
            cout << s.at(i) << endl;
        }
        else {
            cout << s.at(i);
        }
    }
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


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

  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> kukan;
  vector<char> status_v;
  int count = 1;
  for (int i = 0; i < n; i++) {
    int status = s[i];
    if(status == s[i+1]) count++;
    else if(i == n-2){
      kukan.push_back(count);
      status_v.push_back(status);
      count = 1;
    }
    else {
      kukan.push_back(count);
      status_v.push_back(status);
      count = 1;
    }
  }

  int num = int(kukan.size());

  count = 0;
  int res = -1;
  int res_count = 0;
  int begin = 0;
  for (int i = 0; i < num; i++) {
    // cout << i << endl;
    if(count < k){
      if(status_v[i] == '0') {
        count++;
      }
      res_count += kukan[i];
    }

    if(begin-1 >= 0 && status_v[begin-1] == '1'){
      res_count += kukan[begin-1];
    }
    if(i+1 < num && status_v[i+1] == '1'){
      res_count += kukan[i+1];
    }


    res = max(res_count, res);

    if(begin-1 >= 0 && status_v[begin-1] == '1'){
      res_count -= kukan[begin-1];
    }
    if(i+1 < num && status_v[i+1] == '1'){
      res_count -= kukan[i+1];
    }

    if(count == k && i+1 < num){
      res_count -= kukan[begin];
      if(status_v[begin] == '0') count--;
      else i--;
      begin++;
    }
    // }


  }

  cout << res << endl;

}


Measured memory_bytes: 1020
#include <stdio.h>

int main(void)
{
	int a, b;
	char op;
	for(; ; ) {
		scanf("%d %c %d", &a, &op, &b);
		if(op=='?') break;
		else if(op=='+') printf("%d\n", a+b);
		else if(op=='-') printf("%d\n", a-b);
		else if(op=='*') printf("%d\n", a*b);
		else if(op=='/') printf("%d\n", a/b);
	}
		
	return 0;
}


Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 300010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll h, w, a, b;
    cin >> h >> w >> a >> b;

    init();

    ll ans = 0;
    exrep(j, b, w-1) {
        ans += Comb(h-a-1+j, j)*Comb(w+a-2-j, a-1);
        ans %= mod;
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 7296
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;

#define fir first
#define sec second

typedef long long LL;
typedef pair<int, int> PP;

namespace INPUT {
	const int L = 1 << 15;
	char _buf[L], *S, *T, c;
	char _gc () {
		if (S == T) {
			T = (S = _buf) + fread(_buf, 1, L, stdin);
			if (S == T) return EOF;
		}
		return *S++;
	}
	void readi (int &X) {
		for (c = _gc (); c < '0' || c > '9'; c = _gc ()); X = c & 15;
		for (c = _gc (); c >= '0' && c <= '9'; X = X * 10 + (c & 15), c = _gc ());
	}
}
using INPUT :: readi;

const int Maxn = 1E5 + 5;

int N, M;
struct E {
	int v, nxt;
} adj[Maxn << 1];
int hed[Maxn], TE;

bool vis[Maxn], FLAG;
int col[Maxn], Num[5];

LL Ans;

int nextcol (int c, int k) {
return (3 + c + ((k & 1) ? 1 : (-1)) - 1) % 3 + 1;}

void addedge (int u, int v) {
adj[++TE].v = v, adj[TE].nxt = hed[u], hed[u] = TE;}

void Dfs (int u, int Col) {
	++Num[Col], col[u] = Col, vis[u] = true;
	for (int k = hed[u]; ~k; k = adj[k].nxt) {
		++Num[4];
		if (!vis[adj[k].v]) Dfs (adj[k].v, nextcol (Col, k));
		else if (nextcol (Col, k) != col[adj[k].v]) FLAG = false;
	}
}

int main () {
	readi (N), readi (M);
	memset (hed, -1, sizeof (hed));
	for (int u, v, i = 1; i <= M; ++i)
		readi (u), readi (v),
		addedge (u, v), addedge (v, u);
	memset (vis, false, sizeof (vis));
	for (int i = 1; i <= N; ++i)
	if (!vis[i]) {
		Num[1] = Num[2] = Num[3] = Num[4] = 0, FLAG = true, Dfs (i, 1);
		if (FLAG) {
			if (Num[2] == 0 || Num[3] == 0) Ans += Num[4] / 2;
			else Ans += (LL)Num[1] * Num[2] + (LL)Num[2] * Num[3] + (LL)Num[3] * Num[1];
		} else Ans += (LL)(Num[1] + Num[2] + Num[3]) * (Num[1] + Num[2] + Num[3]);
	}
	printf ("%lld", Ans);
	return 0;
}


Measured memory_bytes: 5888
def isBingo(card):
    for x in range(3):
        if "".join(map(str,card[x]))=="ooo":return True
        if "".join([str(r[x]) for r in card])=="ooo":return True
    if card[0][0]==card[1][1]==card[2][2]:return True
    if card[0][2]==card[1][1]==card[2][0]:return True
    return False

def check(cardlist,numlist):
    for n in numlist:
        for row in range(3):
            for col in range(3):
                if cardlist[row][col]==n:cardlist[row][col]="o"
    return cardlist

a=[[int(i) for i in input().split()] for l in range(3)]
n=int(input())
m=[int(input()) for i in range(n)]
l=check(a,m)
if isBingo(l):print("Yes")
else:print("No")

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

string s;
ll l, a[500001];
ll ans; 

int main()
{
    cin>>s;
    s = " " + s;
    l = s.length() - 1;
    for(int i=1;i<=l;i++) (s[i] == '<') ? (a[i+1] = a[i] + 1) : (a[i+1]);
    for(int i=l;i>=1;i--) (s[i] == '>') ? (a[i] = max(a[i], a[i+1]+1)) : (a[i]);
    for(int i=1;i<=l+1;i++) ans += a[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4760
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a,b,n;
int main() {
	scanf("%lld%lld%lld",&a,&b,&n);
	ll x=min(b-1,n);
	printf("%lld\n",a*x/b-a*(x/b));
//	for (register int i=1;i<=n;++i)
//		printf("%d: %d\n",i,a*i/b-a*(i/b));
	return 0;
}

Measured memory_bytes: 3836
n = int(input())
T = list(map(int, input().split()))
m = int(input())
P = [0] * m
X = [0] * m
for i in range(m):
  P[i], X[i] = map(int, input().split())

for i in range(m):
  print(sum(T) - T[P[i]-1] + X[i])

Measured memory_bytes: 38512
#include <bits/stdc++.h>
 
typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;
 
#define for01(k,n)  for (ll i=k; i<n; i++)
#define for02(k,n)  for (ll j=k; j<n; j++)
#define for03(k,n)  for (ll k=k; k<n; k++)
#define for11(k,n)  for (ll i=k; i<=n; i++)
#define for12(k,n)  for (ll j=k; j<=n; j++)
#define for13(k,n)  for (ll k=k; k<=n; k++)

#define pb push_back
#define mp make_pair
#define pf push_front
#define popf pop_front
#define popb pop_back
#define vll vector<ll>
#define F first
#define S second
#define pp pair <ll, ll>
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define si size()
#define bk back()
#define deci(n)  fixed<<setprecision(n)

#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"

#define mem(a,n) memset(a, n, sizeof(a)); // n = 0 OR -1 only

#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define MOD 1000000007
#define MOD2 998244353

using namespace std;


int main()
{
  string s;
  cin >> s;
  string ans;
  ans += s[0];
  for01(1,s.length())
  {
    if (s[i] != ans.back())
       ans += s[i];
  }
  
  p1(ans.length()-1);
  
  return 0;
}

Measured memory_bytes: 512
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
a = []
d = 0
for i in range(n):
    a.append(list(map(int, input().split())))
    combined1 = [x * y for (x, y) in zip(a[i], b)]
    if sum(combined1) + c > 0:
        d += 1

print(d)



Measured memory_bytes: 9108
mod = 998244353 
n= int(input())
d= list(map(int,input().split()))
if (d[0]!=0) or (0 in d[1:]):
    print(0)
    exit(0)
md=max(d)
def pf(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res
tl=[0]*md
for c in d[1:]:tl[c-1]+=1
if 0 in tl:
    print(0)
    exit(0)
ans=1
for i in range(md-1):ans=(ans%mod*pf(tl[i],tl[i+1],mod))%mod
print(ans)

Measured memory_bytes: 14396
#include<bits/stdc++.h>
#define ft(i,l,r) for(register int i=l;i<=r;i++)
#define fd(i,r,l) for(register int i=r;i>=l;i--)
using namespace std;
int a,b,c;
int main()
{
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
    return 0;
}

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

int main() {
  int a,b;
  char op;
  cin >> a >> op >> b;
  if(op == '+'){
    cout << a+b << endl;
  }
  else{
    cout << a-b << endl;
  }
  
  
}  

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

const int N = 330;
const int inf = 1e9 + 7;

int w[N][N];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, l; cin >> n >> m >> l;
	int a, b, c;
	for (int i = 1; i <= n; i++) for (int j = 1; j<= n; j++) w[i][j] = (i == j ? 0 : inf);
	for (int i = 0; i < m; i++) {
		cin >> a >> b >> c;
		w[a][b] = w[b][a] = c;
	}
	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				w[i][j] = min(w[i][j], w[i][k] + w[k][j]);
	for (int i = 1; i <= n; i++) for (int j = 1; j<= n; j++) w[i][j] = (w[i][j] <= l ? 1 : inf);
	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				w[i][j] = min(w[i][j], w[i][k] + w[k][j]);
	int q; cin >> q;
	while (q--) {
		int s, t; cin >> s >> t;
		cout << (w[s][t] == inf ? -1 : w[s][t] - 1) << "\n";
	}
	return 0;
}


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

using namespace std;
const int N=2e5+5,mod=1e9+7;
long long arr[N];
long long dp[N];
int n;
long long m;

bool valid(int mn , bool flag = false){
    long long res = 0;
    for(int i = 0 ; i < n ; i++){
        int idx = lower_bound(arr,arr+n,mn-arr[i]) - arr;
        if(idx <= i){
            res++;
            res += (n - i - 1) * 2;
        }else{
            res += (n - idx) * 2;
        }
        //if(flag)cout << idx << " " << i << " " << res << endl;
    }
    return res >= m;
}

int bs(int s , int e){
    while(s < e){
        int mid = s + (e - s + 1) / 2;
        if(valid(mid))
            s = mid;
        else
            e = mid - 1;
    }
    return s;
}

long long sum(int s , int e){
    if(s > e)return 0;
    if(s)return dp[e] - dp[s-1];
    return dp[e];
}

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

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

    sort(arr,arr+n);

    for(int i = 0 ; i < n ; i++){
        dp[i] = arr[i];
        if(i)dp[i] += dp[i-1];
    }


    int mn = bs(0 , 2e5 + 3);
    valid(mn,true);
    mn++;
    long long cnt = 0;
    long long ans = 0;
    for(int i = 0 ; i < n ; i++){
        int idx = lower_bound(arr,arr+n,mn-arr[i]) - arr;
        if(idx <= i){
            cnt++;
            ans += arr[i] * 2;

            cnt += (n - i - 1) * 2;
            ans += arr[i] * (n - i - 1) * 2;
            ans += sum(i + 1 , n - 1) * 2;
            //cout << cnt << " " << ans << endl;
        }else{
            cnt += (n - idx) * 2;
            ans += arr[i] * (n - idx) * 2;
            ans += sum(idx , n-1) * 2;
        }
        //cout << cnt << " " << ans << endl;
    }

    ans += (m - cnt) * (mn-1);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string n; cin >> n;
  cout << (n[0] == '9' || n[1] == '9' ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
#define rep_re(i,s,n)for(int i = n;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_M = 100001;

int main() {
	ll a; cin >> a;
	string s; cin >> s;
	cout << ((a >= 3200) ? s : "red") << endl;
	return 0;
}

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

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

    cout << a[n-1]-a[0] << endl;
}

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

int main(){

 int n; cin>>n;
 bool f = false;

 for(int i=0;i<n;i++){

  int x; cin>>x;
  if(x%2 == 1) f = true;
 }

  if(f) cout<<"first"<<endl;
  else cout<<"second"<<endl;

return 0;
}


Measured memory_bytes: 256
n,*name=open(0)
n=int(n)
l=[0]*5
for c in name:
	x=c[0]
	if x=="M":
		l[0]+=1
	elif x=="A":
		l[1]+=1
	elif x=="R":
		l[2]+=1
	elif x=="C":
		l[3]+=1
	elif x=="H":
		l[4]+=1
from itertools import combinations
ans=0
for c in combinations(range(5),3):
	ans+=l[c[0]]*l[c[1]]*l[c[2]]
print(ans)

Measured memory_bytes: 9876