akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc() {
	ll a, b;
	ll ans = 0;

	cin >> a >> b;

	rep(i, 1251){
		if ((ll)(i*0.08) == a && (ll)(i*0.10) == b){
			ans = i;
		    cout << ans << "\n";
		    return;
		}
	}

	ans = -1;
	cout << ans << "\n";
}

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

	solve_abc();

	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 = Integer.parseInt(sc.nextLine());
    String[] strings = new String[N];
    for (int i = 0; i < N; i++) {
      strings[i] = sc.nextLine();
    }
    int happyness = solve(strings);
    System.out.println(happyness);
  }

  private static int solve(String[] strings) {

    int[][] ans = new int[strings.length][3];
    for (String str : strings) {
      String[] s = str.split(" ");
      ans[0][0] = Integer.parseInt(s[0]);
      ans[0][1] = Integer.parseInt(s[1]);
      ans[0][2] = Integer.parseInt(s[2]);
      break;
    }
    for (int i = 1; i < strings.length; i++) {
      String[] s = strings[i].split(" ");
      ans[i][0] = Math.max(ans[i - 1][1], ans[i - 1][2]) + Integer.parseInt(s[0]);
      ans[i][1] = Math.max(ans[i - 1][0], ans[i - 1][2]) + Integer.parseInt(s[1]);
      ans[i][2] = Math.max(ans[i - 1][0], ans[i - 1][1]) + Integer.parseInt(s[2]);
    }

    return Math.max(
        Math.max(ans[strings.length - 1][0], ans[strings.length - 1][1]),
        ans[strings.length - 1][2]);
  }
}


Measured memory_bytes: 134980
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll> a(n);rep(i,n){cin>>a.at(i);}
    vector<vector<ll> > dp(n,vector<ll>(n,-1));
    function<ll(int,int)> solve = [&](int from, int to){
        assert(0<=from&&from<=to&&to<=n-1);
        if(dp[from][to]!=-1){return dp[from][to];}
        if(to-from<=1){
            return max(a.at(from), a.at(to));
        }
        ll res = max(a.at(from)+min(solve(from+2,to),solve(from+1,to-1)),
        a.at(to)+min(solve(from+1,to-1),solve(from,to-2)));
        return dp[from][to] = res;

    };
    ll sum_a = solve(0,n-1);
    ll sum_b=0;
    rep(i,n){
        sum_b += a.at(i);
    }
    sum_b -= sum_a;
    ll res = sum_a-sum_b;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 72960
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = ll(1e15)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;

int main() {
	ll N; string S, T; cin >> N >> S >> T;
	rep(i, N) {
		cout << S[i] << T[i];
	}
	cout << endl;
	return 0;
}


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;
typedef pair<int, int> P;
const int mod = 2019;
int main(void) {
    ll l, r; cin >> l >> r;
    if(r-l>2018) cout << 0;
    else{
        int m = 2020;
        for(int i=l;i<=r;i++) {
            for(int j=i+1;j<=r;j++) {
                m = min(((i%mod)*(j%mod))%mod,m);
            }
        }
        cout << m;
    }
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
	char s[200001];
	scanf("%s",&s);
	int i=0;
	int hoge=0,piyo=0;
	for(i=0;;i++){
		if(s[i]=='A'){
			hoge=i;
			break;	
		}
	}

	
	for(i=(int)strlen(s)-1;;i--){
		if(s[i]=='Z'){
			piyo=i;
			break;
		}
	}
	
	printf("%d\n",piyo-hoge+1);

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H.at(i);
	}
	sort(H.begin(), H.end());
	reverse(H.begin(), H.end());
	if (K <= N) {
		for (int i = 0; i < K; i++) {
			H.at(i) = 0;
		}
	}
	else {
		for (int i = 0; i < N; i++) {
			H.at(i) = 0;
		}
	}
	long long int ans = 0;
	for (int i = 0; i < N; i++) {
		ans = ans + H.at(i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

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

int main() {
    int h, w, m;   cin >> h >> w >> m;
    vector<int> a (h, 0), b(w, 0), a_(h, 0), b_(w, 0);
    vector<P> v(m);
    for (int i = 0; i < m; i++) {
        cin >> v[i].first >> v[i].second;
        v[i].first--;
        v[i].second--;
        a[v[i].first]++;
        a_[v[i].first]++;
        b[v[i].second]++;
        b_[v[i].second]++;
    }

    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());

    int k = a[0], l = b[0], i = 0, j = 0;

    while (i < h && k == a[i])
        i++;

    while (j < w && l == b[j])
        j++;

    if (i * j > m) {
        cout << k + l << endl;
        return 0;
    }

    int cnt = 0;
    for (int c = 0; c < m; c++) {
        if (a_[v[c].first] == k && b_[v[c].second] == l) {
            cnt++;
        }
    }

    if (cnt == i*j)
        cout << k + l-1 << endl;
    else 
        cout << k + l  << endl;

    return 0;
}

Measured memory_bytes: 10392
#include <iostream>

using namespace std;
long long x[100010],v[100010],ret1[100010],ret2[100010],n,c,ans = 0,ret,mx;
int main(){
	int i;
	cin >> n >> c;
	for(i=0;i<n;i++){
		cin >> x[i] >> v[i];
	}
	ret = 0; mx = 0;
	for(i=0;i<n;i++){
		ret += v[i];
		mx = max(mx,ret - x[i]);
		ret1[i] = mx;
	}
	ans = mx;
	ret = 0; mx = 0;
	for(i=n-1;i>=0;i--){
		ret += v[i];
		mx = max(mx,ret - (c - x[i]));
		ret2[i] = mx;
	}
	ans = max(mx,ans);
	ret = 0;
	ret2[n] = 0;
	for(i=0;i<n;i++){
		ret += v[i];
		ans = max(ans,ret - 2*x[i] + ret2[i+1]);
	}
	ret = 0;
	for(i=n-1;i>=1;i--){
		ret += v[i];
		ans = max(ans,ret - 2*(c - x[i]) + ret1[i-1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
check = ['dream', 'dreamer', 'erase', 'eraser']
    
s=input()

end = len(s)

while 0 < end:
    if s[end-5:end] in check:
        end -= 5
    elif s[end-6:end] in check:
        end -= 6
    elif s[end-7:end] in check:
        end -= 7
    else:
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 39792
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;

int main(){
    int X,Y;
    cin >> X >> Y;
    ll ans = 0;
    if(X == 1 && Y == 1){
        ans = 1000000;
    } else if((X == 1 && Y == 2) || (X==2&&Y==1)){
        ans = 500000;
    } else if((X ==1&&Y==3)||(X ==3&&Y==1)){
        ans = 400000;
    } else if((X ==2&&Y==3)||(X ==3&&Y==2)){
        ans = 300000;
    } else if((X ==2&&Y==2)){
        ans = 400000;
    } else if((X ==3&&Y==3)){
        ans = 200000;
    } else if(X == 1 || Y == 1){
        ans = 300000;
    } else if(X == 2 || Y == 2){
        ans = 200000;
    } else if(X == 3 || Y == 3){
        ans = 100000;
    }
    cout << ans << endl;
}



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

int main()
{
	string s;
  	cin>>s;
  	int n = s.length();
  	
  	if(s[n-1] == '2'|| s[n-1] == '4'||s[n-1] == '5'||s[n-1] == '7'||s[n-1] == '9')
    { 
      cout<<"hon";
      return 0;
    }
  	
  	if(s[n-1] == '0'||s[n-1] == '1'||s[n-1] == '6'||s[n-1] == '8')
    {
      cout<<"pon";
      return 0;
    }
  	if(s[n-1] == '3')
      cout<<"bon";
  
  	return 0;
}


Measured memory_bytes: 3608
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall as f
def main():
  t=np.fromfile(open(0),'i',sep=' ')
  n,m,l=t[:3]
  m=m*3+3
  print('\n'.join((f(f(csr_matrix((t[5:m:3],(t[3:m:3],t[4:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n).astype(int)%n-1).astype(str).tolist()))
main()

Measured memory_bytes: 28852
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll sum;
ll a,b,c,d;


int main()
{
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	ll csum=0;
	ll dsum=0; 
	
	
	csum=b/c-a/c;
	if(a%c==0) csum++;
	//printf("%lld\n",csum);
    dsum=b/d-a/d;
	if(a%d==0) dsum++;
	//printf("%lld\n",dsum);
	if(a%(c*d)==0) dsum--;
	
	ll tmp=c*d/__gcd(c,d);
	ll tmpb=b/tmp;
	ll tmpa=a/tmp;
	ll ans=tmpb-tmpa;
	//printf("%lld %lld ta %lld tb %lld\n",tmp,c*d,tmpa,tmpb);
	
	printf("%lld",b-a-csum-dsum+ans+1);
	
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;

char s[200],t[200];
int L;

bool judg (int si,int ti)
{
	int i;
	for (i=1;i<=L;i++)
	{
		if (si==L)
		{
			si=0;
		}
		if (s[si]!=t[ti])
		{
			return false;
		}
		si++;
		ti++;
	}
	return true;
}




int main()
{
    scanf ("%s\n",s);
    scanf ("%s\n",t);
	L=strlen (s);
	int i;
	for (i=0;i<=L-1;i++)
	{
		if (judg(i,0))
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
    return 0;
} 



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  rep(i, ll(s.size())) {
    if (s[i] == '+') ans++;
    if (s[i] == '-') ans--;
  }

  cout << ans << endl;

  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,P;
string S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>P>>S;
	ll ret=0;
	
	if(P==2 || P==5) {
		FOR(i,N) {
			if((S[i]-'0')%P==0) ret+=(i+1);
		}
	}
	else {
		reverse(ALL(S));
		map<int,int> mp;
		mp[0]=1;
		ll cur=0,p10=1;
		FORR(c,S) {
			cur=(cur+(c-'0')*p10)%P;
			ret+=mp[cur];
			mp[cur]++;
			(p10*=10)%=P;
		}
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 916
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        N: usize,
    }

    let n = N % 10;
    let p = match n {
        2 | 4 | 5 | 7 | 9 => "hon",
        0 | 1 | 6 | 8 => "pon",
        3 => "bon",
        _ => ""
    };
    println!("{}", p);
}

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

int dp[10005];

int main() {
  int n, ww; cin >> n >> ww;
  for (int i = 1; i < 10005; i++)
    dp[i] = -0x3f3f3f3f;
  for (int i = 0; i < n; i++) {
    int v, w; cin >> v >> w;
    for (int i = w; i <= ww; i++)
      dp[i] = max(dp[i], dp[i - w] + v);
  }
  int ans = 0;
  for (int i = 0; i <= ww; i++)
    ans = max(ans, dp[i]);
  cout << ans << endl;
}


Measured memory_bytes: 3136
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll a;
            ld b;
            cin>>a>>b;
            ll ans=a*b;
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3748
"""def power(x, y): 
    res = 1
    x=x
    while (y > 0): 
        if ((y & 1) == 1) : 
            res = (res * x) 
        y = y >> 1
        x = (x * x)
    return res""" 
"""def fact(n):
    if(n==0):
        return 1
    if(n==1):
        return 1
    return fact(n-1)+fact(n-2)"""

import math
#import combinations

#t=int(input())
#for _ in range(t):
#n=int(input())
s=input()
#arr=list(map(int,input().split()))
#n,k=map(int,input().split())
#count=0
#arr=list(map(int,input().split()))
if(s[2]==s[3] and s[4]==s[5]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38748
#include <stdio.h>
#include <math.h>
main(){
  int i,j,n,code;
  char cm[7],op,dict[262145];
  for(i=0,scanf("%d %s",&n,cm);i<n;i++,scanf("%s",cm)){
    for(j=code=op=0;op!='\n';scanf("%c",&op))
      if(op=='A') code+=1*pow(4,j++);
      else if(op=='C') code+=2*pow(4,j++);
      else if(op=='G') code+=3*pow(4,j++);
      else if(op=='T') code+=4*pow(4,j++);
    if(cm[0]=='i') dict[code] = 1;
    if(cm[0]=='f') dict[code] ? printf("yes\n") : printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 496
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    vector<ll> b(n+1, 0);
    rep(i, 0, n){
        b[a[i]]++;
    }
    ll ans = 0;
    rep(i, 1, n+1){
        ans += b[i] * (b[i]-1) / 2;
    }
    rep(i, 0, n){
        ll c = b[a[i]] * (b[a[i]] - 1) / 2;
        ll d = (b[a[i]] - 1) * (b[a[i]] - 2) / 2;
        cout << ans - c + d << endl;
    }
    return 0;
}


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	    // 引数で標準入力System.inを指定する
	    Scanner scanner = new Scanner(System.in);
		try {

		    // 1行目を取得(a)
//		    int input_text１ = scanner.nextInt();
			String[] line1Array = scanner.nextLine().split(" ");
			int pL = Integer.parseInt(line1Array[0]);
			int pR = Integer.parseInt(line1Array[1]);
			int pd = Integer.parseInt(line1Array[2]);

			int answer = 0;

			for (int i = pL; i <= pR; i++) {
				if (i %pd == 0) answer++;
			}

			System.out.printf("%d", answer);

		} finally {
		    // Scannerクラスのインスタンスをクローズ
		    scanner.close();
		}
	}
}

Measured memory_bytes: 35668
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;

void ABC085A()
{
	string s;
	cin >> s;
	s[0] = '2';
	s[1] = '0';
	s[2] = '1';
	s[3] = '8';
	cout << s << endl;
}
int main()
{
  ABC085A();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e3+7;
const ll mod = 1e9 + 9;
#define afdafafafdafaf y1;
int ar[maxn], n, m;
int ans[maxn];
int f[maxn];

int main()
{
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", ar + i);
        f[ar[i]]++;
    }
    for(int i=1;i<maxn;i++){
        f[i] += f[i-1];
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(i != j){
                ll pre = ans;
                int x = ar[i], y = ar[j];
                int mn = abs(ar[i] - ar[j]), mx = ar[i] + ar[j];
                ans += f[mx-1] - f[mn];
                if(x > mn && x < mx)ans--;
                if(y > mn && y < mx)ans--;
            }
        }
    }
    printf("%lld\n", ans / 3);


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100

void dfs(void);
void visit(int);

int n,a[N][N],color[N],t,d[N],f[N]; //d=start,f=finish

int main(){
  int i,j,k,x,u;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      a[i][j] = 0;
    }
  }
  for(i = 0;i < n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j = 0;j < k;j++){ //x=連結
      scanf("%d",&x);
      x--;
      a[u][x] = 1;
    }
  }

  dfs();

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

void dfs(void){
  int u;
  for(u = 0;u < n;u++){
    color[u] = 0; //0=白（未到達）
  }
  t = 0;
  for(u = 0;u < n;u++){
    if(color[u] == 0) visit(u);
  }
}

void visit(int r){
  int i;
  color[r] = 1; //1=灰（到達地点）
  d[r] = ++t;
  for(i = 0;i < n;i++){
    if(a[r][i] == 0) continue; //つながっていないから
    if(color[i] == 0) visit(i);
  }
  color[i] = 2; //2=黒（いきどまり）
  f[r] = ++t;
}



Measured memory_bytes: 2128
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())


def makeS(len, n, k, res):
    #print(len, n, k, res)
    ans = []
    if len == n:
        return [res]

    for i in range(k + 1):
        s = chr(97+i)
        if i == k:
            l = makeS(len, n + 1, k + 1, res + s)
        else:
            l = makeS(len, n + 1, k, res + s)

        ans += l

    return ans


ans = makeS(N, 0, 0, "")

print("\n".join(ans))


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

int main() {
  
  string A, B;
  cin >> A >> B;
  
  if(A.at(0) == B.at(2) && A.at(1) == B.at(1) && A.at(2) == B.at(0))
    cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int N, M; cin >> N >> M;
		if (N == 0) break;
		int r; cin >> r;
		vector<int> t(r), n(r), m(r), s(r);
		for (int i = 0; i < r; i++)
			cin >> t[i] >> n[i] >> m[i] >> s[i];
		int q; cin >> q;
		while (q--) {
			int ts, te, _m; cin >> ts >> te >> _m;
			int x = 0, start, end, ans = 0;
			for (int i = 0; i < r; i++) {
				if (m[i] != _m) continue;
				if (s[i]) {
					if (x == 0) start = t[i];
					x++;
				}
				else {
					x--;
					if (x == 0) {
						end = t[i];
						ans += max(0, min(te, end) - max(ts, start));
					}
				}
			}
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int main(){
  string S;
  cin >> S;
  int n= S.size();

  rep(i,n){
    cout << 'x';
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int k,n;
int a,num[200000];
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a;
        num[a-1]++;
    }
    sort(num,num+n);
    int sum=0;
    for(int i=1;i<=k;i++){
        sum+=num[n-i];
    }
    cout<<n-sum<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        ll n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << floor_sum(n, m, a, b) << endl;
    }
}



Measured memory_bytes: 3688
#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
# import numpy as np
INF = float("inf")


def solve(N: int, M: int, Q: int, L: "List[int]", R: "List[int]", p: "List[int]", q: "List[int]"):
    a = [[0]*(N+1) for _ in range(N+1)]
    for l, r in zip(L, R):
        a[l][r] += 1

    a = [list(itertools.accumulate(x)) for x in a]
    a = [list(itertools.accumulate(s[::-1]))[::-1] for s in zip(*a)]

    for pp, qq in zip(p, q):
        # 転置略して逆指定
        print(a[qq][pp])
    # print(*a, sep="\n")

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    p = [int()] * (Q)  # type: "List[int]"
    q = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        p[i] = int(next(tokens))
        q[i] = int(next(tokens))
    solve(N, M, Q, L, R, p, q)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27968
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

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

    int sumall = 0;
    for (int i = 1; i <= n; i++) {
        int sum = 0;
        int itmp = i;
        sum += itmp / 10000;
        itmp %= 10000;
        sum += itmp / 1000;
        itmp %= 1000;
        sum += itmp / 100;
        itmp %= 100;
        sum += itmp / 10;
        itmp %= 10;
        sum += itmp;
        if (a <= sum && sum <= b) {
            sumall += i;
        }
    }

    cout << sumall << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  v(string) cmd(3);
  rep(i,3) {
    cin >> cmd[i];
  }
  vi pos(3,0);
  int now=0;
  while(1) {
    if(pos[now]>=sz(cmd[now])) {
      cout << char(now+'A') << endl;
      return 0;
    }
    int next = cmd[now][pos[now]]-'a';
    pos[now]++;
    now=next;
  }

  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e3;
const int inf=1e9;
int main(){
  int N;cin>>N;
  cout<<(N-1)/2<<endl;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    ans = 0
    a, b, c, k = map(int, input().split())
    if a >= k:
        ans = k
    else:
        ans = a
        if b < (k-a):
            ans += -1*(k-a-b)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9184
#ifndef UNION_FIND_HPP
#define UNION_FIND_HPP

#include <vector>

namespace tklib {

class UnionFind {
private:
    std::vector<int> par;
    int components;

public:
    UnionFind(int n) : par(n, -1), components(n) {}

    bool unite(int x, int y) {
        if ((x = find(x)) == (y = find(y))) {
            return false;
        } else {
            if (par[x] < par[y]) std::swap(x, y);
            par[y] += par[x];
            par[x] = y;
            --components;
            return true;
        }
    }

    int find(int x) {
        if (par[x] < 0) return x;
        else return par[x] = find(par[x]);
    }

    int size(int x) {
        return -par[find(x)];
    }

    int count() {
        return components;
    }
};

} // namespace tklib

#endif // UNION_FIND_HPP


#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, M, K; cin >> N >> M >> K;
    using pp = pair<int, int>;
    map<pp, int> A;
    vector<pp> block(K);
    tklib::UnionFind uf(N);

    for(int i=0; i<M; ++i) {
        int a,b; cin >> a >> b; --a; --b;
        A[pp(min(a, b), max(a, b))] = 1;
        uf.unite(a, b);
    }
    vector<int> cnt(N);
    for(int i=0; i<N; ++i) cnt[i] = uf.size(i) - 1;
    for(auto p : A) {
        int a = p.first.first, b = p.first.second;
        cnt[a] -= 1; cnt[b] -= 1;
    }

    for(int i=0; i<K; ++i) {
        int a, b; cin >> a >> b; --a; --b;
        if(a > b) swap(a, b);
        if(uf.find(a) == uf.find(b) && !A[pp(a, b)]) {
            --cnt[a]; --cnt[b];
        }
    }

    for(int i=0; i<N; ++i) cout << cnt[i] << (i+1==N ? '\n' : ' ');
}

Measured memory_bytes: 14848
#include<bits/stdc++.h>
#define ll long long
#define P pair<ll, ll>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>>G(n);
    vector<int>p(m), y(m);
    for(int i=0;i<m;i++){
        cin >> p[i] >> y[i];
        p[i]--;
        G[p[i]].push_back(i);
    }

    vector<ll>ans(m);

    for(ll i=0;i<n;i++){//県順にみる。
        if(G[i].empty()) continue;
        vector<pair<ll, ll>> yy;
        for(auto g:G[i]) yy.push_back({y[g], g});//gは市の番号
        sort(yy.begin(), yy.end());
        for(ll j=0;j < (ll)yy.size();j++){
            ans[yy[j].second] = (i+1)*1000000 + j+1;
        }
    }
    for(int i=0;i<m;i++) printf("%012lld\n", ans[i]);
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(x) ((x)<(0)?-(x):(x))

using namespace std;
using ll = long long;


signed main(){
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	
	cout << n * n * n << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define int long long int
using namespace std;
signed main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    /*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    int n; cin>>n;
    int x=100;
    int count=0;
    while(x < n){
        x = (int)((x*1.0) +((x*1.0)/100));
        count++;
    }
    cout<<count<<endl;
}

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

ll a, b, c, k;

int main() {
  cin >> a >> b >> c >> k;
  cout << (k % 2 == 0 ? a - b : b - a) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[] prime = new boolean[300000];
		for (int i = 0; i < prime.length; i++)
			prime[i] = false;
		for (int i = 7; i < prime.length; i += 7) {
			prime[i - 1] = true;
			if (i + 1 < prime.length)
				prime[i + 1] = true;
		}
		for (int i = 6; i < prime.length; i++)
			if (prime[i])
				for (int j = i * 2; j < prime.length; j += i)
					prime[j] = false;
		while (true) {
			int n = sc.nextInt();
			if (n == 1)
				break;
			System.out.print(n + ":");
			for (int i = 0; i < prime.length; i++)
				if (prime[i] && n % i == 0)
					System.out.print(" " + i);
			System.out.println();
		}
		sc.close();
	}
}

Measured memory_bytes: 24112
t, x, y = 0, 0, 0
N = int(input())
info = []
for i in range(N):
    infocstr = input().split()
    infoc = []
    for num in infocstr:
        infoc.append(int(num))
    info.append(infoc)
    
for infoi in info:
    time = infoi[0] - t
    need = abs(x-infoi[1])+abs(y-infoi[2])
    d = time - need
    if d < 0 or d % 2 == 1:
        print('No')
        break
    t, x, y = infoi[0], infoi[1], infoi[2]
        
else:
    print('Yes')
    


Measured memory_bytes: 21108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()
int first_fixed_size_subset(int n, int k) { return (1 << k) - 1; }

int next_fixed_size_subset(int n, int k, int& s) {
  int x = s & -s, y = s + x;
  s = (((s & ~y) / x) >> 1) | y;
  if (s >= (1 << n)) return 0;
  return s;
}

struct Card {
  int R, B;
};

struct Hoge {
  bool red;
  int v;
};

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

  vector<Card> C(N);
  rep(i, N) {
    if (i % 2 == 0) {
      cin >> C[i].R;
    } else {
      cin >> C[i].B;
    }
  }
  rep(i, N) {
    if (i % 2 == 0) {
      cin >> C[i].B;
    } else {
      cin >> C[i].R;
    }
  }

  int nRed = (N + 1) / 2;
  int red = first_fixed_size_subset(N, nRed);

  int ans = 1e9;

  do {
    int cost = 0;

    vector<Hoge> foo(N);
    rep(i, N) {
      if ((red >> i) & 1) {
        foo[i] = Hoge{true, C[i].R};
      } else {
        foo[i] = Hoge{false, C[i].B};
      }
    }

    bool flag = true;
    for (int i = 0; flag; i++) {
      flag = false;
      for (int j = N - 1; j >= i + 1; --j) {
        if (foo[j].v < foo[j - 1].v) {
          swap(foo[j], foo[j - 1]);
          flag = 1;
          ++cost;
        }
      }
    }

    do {
      flag = false;
      rep(i, N - 1) {
        if (foo[i].v == foo[i + 1].v &&
            (i % 2 == 0 && !foo[i].red && foo[i + 1].red)) {
          swap(foo[i], foo[i + 1]);
          ++cost;
        }
      }
    } while (flag);

    rep(i, N) {
      if (i % 2 == 0 && !foo[i].red) {
        int j = i + 1;
        while (j < N && foo[i].v == foo[j].v && !foo[j].red) ++j;
        if (j == N || foo[i].v != foo[j].v) goto hoge;
        for (int k = j; k > i; --k) {
          swap(foo[k], foo[k - 1]);
          ++cost;
        }
      }
      if (i % 2 == 1 && foo[i].red) {
        int j = i + 1;
        while (j < N && foo[i].v == foo[j].v && foo[j].red) ++j;
        if (j == N || foo[i].v != foo[j].v) goto hoge;
        for (int k = j; k > i; --k) {
          swap(foo[k], foo[k - 1]);
          ++cost;
        }
      }
    }

    ans = min(ans, cost);
  hoge:;
  } while (next_fixed_size_subset(N, nRed, red));

  cout << (ans == 1e9 ? -1 : ans) << endl;

  return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    if h % 3 == 1:
        a = h//3
        b = a*2
        if w % 2 == 0:
            l1 = [(a+1)*w,b*w//2]
            l2 = [a*w,(b+1)*w//2]
            ans1 = min(max(l1)-min(l1),max(l2)-min(l2))
        else:
            c = w//2
            l1 = [(a+1)*w,b*(c+1),b*c]
            l2 = [a*w,(b+1)*(c+1),(b+1)*c]
            ans1 = min(max(l1)-min(l1),max(l2)-min(l2))
    else:
        a = h//3
        b = h//3*2
        c = w//2
        if w % 2 == 0:
            l1 = [(a+2)*w,b*c]
            l2 = [(a+1)*w,(b+1)*c]
            l3 = [a*w,(b+2)*c]
            l4 = [max(l1)-min(l1),max(l2)-min(l2),max(l3)-min(l3)]
            ans1 = min(l4)
        else:
            #print(a,b,c)
            l1 = [(a+2)*w,b*c,b*(c+1)]
            l2 = [(a+1)*w,(b+1)*c,(b+1)*(c+1)]
            l3 = [a*w,(b+2)*c,(b+2)*(c+1)]
            l4 = [max(l1)-min(l1),max(l2)-min(l2),max(l3)-min(l3)]
            ans1 = min(l4)
    ans1 = min(ans1,w)
    a = h
    h = w
    w = a
    if h % 3 == 1:
        a = h//3
        b = a*2
        if w % 2 == 0:
            l1 = [(a+1)*w,b*w//2]
            l2 = [a*w,(b+1)*w//2]
            ans2 = min(max(l1)-min(l1),max(l2)-min(l2))
        else:
            c = w//2
            l1 = [(a+1)*w,b*(c+1),b*c]
            l2 = [a*w,(b+1)*(c+1),(b+1)*c]
            ans2 = min(max(l1)-min(l1),max(l2)-min(l2))
    else:
        a = h//3
        b = a*2
        c = w//2
        if w % 2 == 0:
            l1 = [(a+2)*w,b*c]
            l2 = [(a+1)*w,(b+1)*c]
            l3 = [a*w,(b+2)*c]
            l4 = [max(l1)-min(l1),max(l2)-min(l2),max(l3)-min(l3)]
            ans2 = min(l4)
        else:
            #print(a,b,c)
            l1 = [(a+2)*w,b*c,b*(c+1)]
            l2 = [(a+1)*w,(b+1)*c,(b+1)*(c+1)]
            l3 = [a*w,(b+2)*c,(b+2)*(c+1)]
            l4 = [max(l1)-min(l1),max(l2)-min(l2),max(l3)-min(l3)]
            ans2 = min(l4)
    ans2 = min(ans2,w)
    print(min(ans1,ans2))

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

class A
{
	static void Main() => Console.WriteLine(string.Join("\n", new int[int.Parse(Console.ReadLine())].Select(_ => Solve())));

	static long Solve()
	{
		var h = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long n = h[0], d = h[4], Mx = (1L << 60) / d;
		var ops = new[] { (2, h[1]), (3, h[2]), (5, h[3]) };

		var m = n <= Mx ? n * d : 1L << 60;
		var set = new HashSet<long>();
		var pq = PQ<(long x, long cost)>.Create(v => v.cost);
		pq.Push((n, 0));

		while (pq.Any())
		{
			var (x, cost) = pq.Pop();
			if (x <= Mx) m = Math.Min(m, cost + x * d);
			if (x == 1) return m;
			if (set.Contains(x)) continue;
			set.Add(x);

			foreach (var (p, c) in ops)
			{
				var div = x / p;
				for (int i = -p + 1; i < p; i++)
				{
					var nx = div + i;
					if (nx > 0) pq.Push((nx, cost + c + Math.Abs(nx * p - x) * d));
				}
			}
		}
		return -1;
	}
}

class PQ<T> : List<T>
{
	public static PQ<T> Create<TKey>(Func<T, TKey> getKey, T[] vs = null, bool desc = false)
	{
		var c = Comparer<TKey>.Default;
		return desc ?
			new PQ<T>(vs, (x, y) => c.Compare(getKey(y), getKey(x))) :
			new PQ<T>(vs, (x, y) => c.Compare(getKey(x), getKey(y)));
	}

	Comparison<T> c;
	public T First => this[0];

	PQ(T[] vs, Comparison<T> _c)
	{
		c = _c;
		if (vs != null) foreach (var v in vs) Push(v);
	}

	void Swap(int i, int j) { var o = this[i]; this[i] = this[j]; this[j] = o; }
	void UpHeap(int i) { for (int j; i > 0 && c(this[j = (i - 1) / 2], this[i]) > 0; Swap(i, i = j)) ; }
	void DownHeap(int i)
	{
		for (int j; (j = 2 * i + 1) < Count;)
		{
			if (j + 1 < Count && c(this[j], this[j + 1]) > 0) j++;
			if (c(this[i], this[j]) > 0) Swap(i, i = j); else break;
		}
	}

	public void Push(T v)
	{
		Add(v);
		UpHeap(Count - 1);
	}
	public T Pop()
	{
		var r = this[0];
		this[0] = this[Count - 1];
		RemoveAt(Count - 1);
		DownHeap(0);
		return r;
	}
}


Measured memory_bytes: 61576
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
#ifdef VC
#define scanf scanf_s
#endif
#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int alp[30] = {};
string S;
ll used = 0LL;
int ans = 0;

int main(){
	string s, t;
	cin >> s >> t;
	bool flg = false;
	int l = s.length();
	for (int i = 0; i < l; i++) {
		for (int j = 0; j < l; j++) {
			if (s[j] != t[(i + j) % l])break;
			if (j == l - 1)flg = true;
		}
		if (flg)break;
	}
	if (flg)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
ll longinf=1ll<<60;
int inf=1<<29;
int dh[]={1,-1,0,0};
int dw[]={0,0,1,-1};
//mleしなければぜんぶllでかく。

ll keta(ll n){
      ll pos=0;
      while(n>0){
            n/=2;
            pos++;
      }
      return pos;
}
int main(){
      cin.tie(0);
      ios::sync_with_stdio(false);
      ll n,k;
      cin>>n>>k;
      ll a[n];
      rep0(i,n) cin>>a[i];
      ll keta_k=keta(k);
      ll max_under[keta_k]; //k=2^j-1の場合のmaxを格納する
      fill(max_under,max_under+keta_k,0);
      ll cnt0[keta_k];
      ll cnt1[keta_k];
      fill(cnt0,cnt0+keta_k,0);
      fill(cnt1,cnt1+keta_k,0);
      ll b[n];
      rep0(i,n) b[i]=a[i];
      vector<ll> kouho;
      rep0(i,n){
            rep0(j,keta_k){
                  if(b[i]&1) cnt1[j]++;
                  else cnt0[j]++;
                  b[i]>>=1;
            }
      }
      rep0(j,keta_k){
            rep0(hoge,j){
                  if(cnt1[hoge]<cnt0[hoge]) max_under[j]+=(1ll<<hoge);
            }
      }
      /*rep0(j,keta_k){
            cout<<max_under[j]<<endl;
      }*/
      ll pos=0;
      rep0(j,keta_k){
            if((k>>(keta_k-1-j))&1){
                  kouho.push_back(pos+max_under[keta_k-1-j]);
                  pos+=(1ll<<(keta_k-1-j));
            }
      }
      kouho.push_back(k);
      ll ans=0;
      for(auto ans_k:kouho){
            ll pos=0;
            rep0(i,n){
                  pos+=(ans_k^a[i]);
            }
            if(pos>ans) ans=pos;
            //cout<<ans_k<<endl;
      }
      cout<<ans<<endl;


      return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector <ll> a(n);
    vector <vector <ll>> bc(m,vector <ll> (2));

    rep(i,n){
        cin >> a[i];
    }

    rep(i,m){
        cin >> bc[i][1] >> bc[i][0];
    }

    sort(bc.begin(),bc.end());
    sort(a.begin(),a.end());
    int k=0;

    rep(i,m){
        
        if(a[k]>=bc[m-i-1][0]){
            break;
        }
        rep(j,bc[m-i-1][1]){
            if(a[k]>=bc[m-i-1][0]){
                break;
            }
            a[k]=bc[m-i-1][0];
            ++k;
            if(k==n){
                break;
            }
        }
    }

    ll ans=0;
    rep(i,n){
        ans+=a[i];
        //cout << a[i] << endl;


    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
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;}
ll const INF = 1001001001001001001;


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

int n,m,x;
cin >> n >> m >> x;

vl c(n);
vvi a(n,vi(m));
rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
}

ll ans = INF;
for(int S = 0; S < (1 << n); ++S) {
    vl und(m);
    ll money = 0;
    rep(i,n) {
        if(S & bit(i)) {
            rep(j,m) {
                und[j] += a[i][j];
            }
            money += c[i];
        }
    }
    bool ok = true;
    rep(j,m) {
        if(und[j] < x) ok = false;
    }
    if(ok) chmin(ans, money);
}

if(ans == INF) cout << -1 << endl;
else cout << ans << endl;

return 0;
}

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

int main() {
  int N, T, A;
  cin >> N >> T >> A;

  int X;
  double min_abs_num = DBL_MAX;
  double min_abs_i = 1;
  for (int i = 1; i <= N; i++) {
    cin >> X;
    double abs_num = abs((T - X * 0.006) - A);
    if (abs_num < min_abs_num) {
      min_abs_num = abs_num;
      min_abs_i = i;
    }
  }

  cout << min_abs_i << endl;
}

Measured memory_bytes: 3760
rows = [list(map(int, input().split())) for i in range(3)]
bingo = rows

# Add columns to bingo list
for i in range(3):
    bingo.append([rows[0][i], rows[1][i], rows[2][i]])

# Add diagonals to bingo list
bingo.append([rows[0][0], rows[1][1], rows[2][2]])
bingo.append([rows[0][2], rows[1][1], rows[2][0]])

N = int(input())

selected_numbers = [int(input()) for i in range(N)]

result = 'No'
for numbers in bingo:
    matched_numbers = set(numbers) & set(selected_numbers)
    if len(matched_numbers) == 3:
        result = 'Yes'
        break

print(result)

Measured memory_bytes: 3064
#import<bits/stdc++.h>
using namespace std;long L,R,D,M=998244353,l,r,d=1,z,A['   '];map<long,int>m;main(){cin>>l>>r;for(m[l]=1;l--;d=d*10%M)A[l]=(z+=d)%=M;for(;cin>>L>>R>>D;cout<<z<<" "){z=(z+D*(A[--L]-A[R]))%M;auto t=m.lower_bound(l=L);for(d=t->second;z=(z-t->second*(A[l]-A[r=min(R,t->first)])%M+M)%M,r<R;t=m.erase(t))l=t->first;m[L]=d;m[R]=D;}}

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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;
const int mod = 1e9 + 7;


int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  vector< int > dp(N + 1); // dp[i] : 基準点より小さいものの個数がi個あるときのうく
  for(int i = N - 1; i >= 0; i--) dp[i] = 1;

  for(int i = N - 1; i > 0; i--) {
    vector< int > dp2(i + 5);
    for(int j = 0; j <= i; j++) {
      int up_count = j;
      int down_count = i - j;

      if(S[i - 1] == '<') {
        (dp2[0] += dp[j]) %= mod;
        (dp2[up_count] += mod - dp[j]) %= mod;
        /*
        for(int k = 1; k <= up_count; k++) {
          (dp2[up_count - k] += dp[j]) %= mod;
        }
         */
      } else {
        (dp2[up_count] += dp[j]) %= mod;
        (dp2[up_count + down_count] += mod - dp[j]) %= mod;
        /*
        for(int k = 1; k <= down_count; k++) {
          (dp2[up_count + (k - 1)] += dp[j]) %= mod;
        }
         */
      }
    }
    for(int j = 1; j < dp2.size(); j++) {
      (dp2[j] += dp2[j - 1]) %= mod;
    }
    dp.swap(dp2);
  }

  cout << accumulate(begin(dp), end(dp), 0LL) % mod << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
ll power(ll x,ll y,ll p) 
{ 
    ll res=1;  
    x=x%p;
    while (y > 0) 
    { 
        if(y&1) 
            res=(res*x)%p; 
        y=y>>1;
        x=(x*x)%p;   
    } 
    return res; 
}
ld dp[3005][3005];
ld arr[3005];
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll i,j,n;
 	cin >> n;
 	for(i=1;i<=n;i++)
 		cin >> arr[i];
 	dp[1][1] = arr[1];
    dp[1][0] = 1 - arr[1];
    for(i=2;i<=n;i++)
 	{
 		for(j=0;j<=i;j++)
 		{
			dp[i][j] = dp[i-1][j-1] * arr[i];
			if(i - 1 >= j)
				dp[i][j] += dp[i-1][j]  * (1 - arr[i]);
 		}
 	}
    ll x = (n + 1) / 2;
    ld ans = 0;
    for(i=x;i<=n;i++)
	   ans += dp[n][i];
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 139392
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(ll i=a;i<=(ll)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;
vector<ll> v(51);
vector<ll> vv(51);
ll solve(ll a,ll b) {
    if(a==0) return b>0?1:0;
    if(b<=1+v[a-1]) return solve(a-1,b-1); 
    return vv[a-1]+1+solve(a-1,b-v[a-1]-2);
}
void pre() {
    ll t=1,c=1;v[0]=1;vv[0]=1;
    repp(i,1,50) {
        t=t*2+3;
        c=c*2+1;
        v[i]=t;vv[i]=c;
    }
}
int main() {
    cs
    pre();
    ll n,q;
    cin>>n>>q;
    cout<<solve(n,q);

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
// vector 型
template<class T>
std::ostream& operator<<(std::ostream& os, const vector<T>& v){
  // ここでストリームに obj を書き込みます。
  int n=v.size();
  rep(i,n){
    cout << v.at(i) << (i==n-1?"":" ");
  }
  return os;
}
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int h,w; cin >>h >>w;
  vector<vector<int>> vec(h,vector<int>(w));
  int cnt=0;
  rep(i,h)rep(j,w){
    int a; cin >>a;
    cnt^=(vec[i][j]=a%2);
  }
  int down=1,have=0,pri,prj;
  vector<vector<int>> ans;
  rep(j,w){
    rep(i,h){
      int ii;
      ii=down?i:h-i-1;
      if(have){
        vector<int> add={pri+1,prj+1,ii+1,j+1};
        ans.push_back(add);
      }
      if(vec[ii][j]) have^=1;
      pri=ii;prj=j;
    }
    down^=1;
  }
  int n=ans.size();
  print(n);
  rep(i,n) print(ans[i]);
}

Measured memory_bytes: 9904
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    readint();
    auto ss = assumeSorted(readints());
    readint();
    auto ts = readints();

    int ans = 0;
    foreach (t; ts) {
        if (ss.contains(t))
            ans++;
    }
    writeln(ans);
}

Measured memory_bytes: 6896
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
ans = 0
r = 0
l = len(s)-1
while r < l:
  if s[r] == s[l]:
    r += 1
    l -= 1
  elif s[r] == "x":
    ans += 1
    r += 1
  elif s[l] == "x":
    ans += 1
    l -= 1
  else:
    print(-1)
    exit()

print(ans)

Measured memory_bytes: 3316