akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  ll n,m;cin>>n>>m;
  ll ans = 0;
  if(n == 1 || m == 1){
    if(n == 1 && m == 1){
      ans = 1;
    }else{
      ans = max(n,m) - 2;
    }
    print(ans);
    return 0;
  }
  ans = (n-2) * (m-2);
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int a,b ;

int main(void){
    
    scanf("%d%d",&a,&b) ;
    
    if ( a+b<24 ){
        printf ("%d",a+b) ;
    } else {
        printf ("%d",a+b-24) ;
    }

    return 0 ;
    
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] S = new String[10000];
		int EM,EMJ,n;
		while((n = sc.nextInt()) != 0){
			for(int i = 0; i < n; i++){
				int pm = sc.nextInt();
				int pe = sc.nextInt();
				int pj = sc.nextInt();
				EM = (pm + pe) / 2;
				EMJ = (pm + pe + pj) / 3;
				if((pm == 100 || pe == 100 || pj == 100) || EM >= 90 || EMJ >= 80){
					S[i] = "A";
				}else{
					if(EMJ >= 70 || (EMJ >= 50 && (pm >= 80 || pe >= 80))){
						S[i] = "B";
					}
					else{
						S[i] = "C";
					}
				}
			}
			for(int k = 0; k < n; k++){
				System.out.println(S[k]);
			}
		}
	}
}

Measured memory_bytes: 28264
def printArray(A):
  strA = [str(i) for i in A]
  print(" ".join(strA))

def insertion(A,N):
  for i in range(1,N):
    printArray(A)
    v = A[i]
    j = i - 1
    
    while j >= 0 and A[j] > v:
      A[j+1] = A[j]
      j -= 1
    
    A[j + 1] = v
  printArray(A)
    
N = int(input())
A = list(map(int,input().split()))

insertion(A,N)


Measured memory_bytes: 5604
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc079/tasks/abc079_a


"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    N = input().strip()
    ans = 'No'
    if N[0] == N[1] == N[2]:
        ans = 'Yes'
    elif N[1] == N[2] == N[3]:
        ans = 'Yes'

    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
    


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

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

  vector<vector<int>> v(2, vector<int>(n));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) {
      cin >> v.at(i).at(j);
    }
  }

  int ans = 0;
  // 下に移動するタイミングが n パターンある
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j <= i; j++) {
      sum += v.at(0).at(j);
    }
    for (int j = i; j < n; j++) {
      sum += v.at(1).at(j);
    }
    ans = max(ans, sum);
  }

  cout << ans << endl;
  return 0;
}


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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string ss;
    char str[500005];
    int h,t;
    char ch;
    int cnt=0;
    int x,y,z,t1;
    cin>>ss;
    cin>>t1;
    for(int i=200001;i<200001+ss.length();i++)
        str[i]=ss[i-200001];
    h=200000;
    t=200001+ss.length();
    while(t1--){
        cin>>x;
        if(x==1){
            cnt++;
        }
        else {
            cin>>y>>ch;
            if(y==1){
                if(cnt%2==0){
                    str[h--]=ch;
                }
                else{
                    str[t++]=ch;
                }
            }
            else if(y==2){
                if(cnt%2==0){
                    str[t++]=ch;
                }
                else {
                    str[h--]=ch;
                }
            }
        }
    }
    if(cnt%2==0){
        for(int i=h+1;i<t;i++)
            cout<<str[i];
    }
    else {
        for(int i=t-1;i>h;i--)
            cout<<str[i];
    }
    return 0;
}


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

int main() {
  long long N, K; cin >> N >> K;
  long long h[N]; for (long long i = 0; i < N; i++) cin >> h[i];
  
  long long dp[N];
  for (long long i = 0; i < N; i++) dp[i] = 10000000000;
  dp[0] = 0;
  for (long long i = 0; i < N; i++){
    for (long long j = 1; j <= min(i, K); j++){
      dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  cout << dp[N - 1] << endl;
}

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

int main()
{
	char X, Y;

	cin >> X >> Y;

	if (X < Y)
	{
		cout << "<" << endl;
	}
	else
		if (X == Y)
		{
			cout << "=" << endl;
		}
		else
		{
			cout << ">" << endl;
		}
	return 0;
}

Measured memory_bytes: 256
s=str(input())

N=int(input())
cnt=0
f=''
b=''
for i in range(N):
  inp=str(input())
  if len(inp)==1:
    cnt+=1
  else:
    F,c=int(inp[2]),inp[4]
    if F==1:
      if cnt%2==0:
        f=c+f
      else:
        b+=c
    else:
      if cnt%2==0:
        b+=c
      else:
        f=c+f
if cnt%2==0:
  print(f+s+b)
else:
  ans=f+s+b
  L=len(ans)
  if L==1:
    print(ans)
  else:
    if L%2==1:
      f=ans[0:L//2]
      s=ans[L//2]
      b=ans[L//2+1:L]
      f_=''.join(list(reversed(b)))
      b_=''.join(list(reversed(f)))
      print(f_+s+b_)
    else:
      f=ans[0:L//2]
      b=ans[L//2:L]
      f_=''.join(list(reversed(b)))
      b_=''.join(list(reversed(f)))
      print(f_+b_)

Measured memory_bytes: 5408
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

C = defaultdict(int)
# 売る，買う，何もしないの金額を追う
C[0] = 1000

for i in range(N):
    nc = defaultdict(int)

    for n, c in C.items():
        # 買う
        n0 = n + c // A[i]
        c0 = c - (c // A[i]) * A[i]
        nc[n0] = max(nc[n0], c0)

        # 売る
        c1 = c + n * A[i]
        n1 = 0
        nc[n1] = max(nc[n1], c1)

        # そのまま
        nc[n] = max(c, nc[n])

    C = nc

print(max(C.values()))


Measured memory_bytes: 9460
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;
double n, m;
int main(int argc, const char * argv[]){
    cin>>n>>m;
    int x = ((1900 * m) + (100 * (n - m))) * pow(2, m);
    cout<<x<<endl;
    return 0;
}


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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>

typedef long long ll;

int main() {
  int A, B;
  cin >> A >> B;
  cout << A * B - (A + B - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
 
using namespace std;
 
int main(void){
  int in=0,l=0;
  string s;
  vector<int>v[101];
 
  while(getline(cin,s)){
    for(int i=0;i<=s.size();i++){
      if(s[i]==',' || i==s.size())v[l].push_back(in),in=0;
      else if(s[i]!=',')in*=10,in+=s[i]-'0'; 
    }
    l++;
  }
 
  int dp[101][101];
 
  fill(dp[0],dp[101],0);
   dp[0][0]=v[0][0];
 
  for(int i=1;i<l;i++){
    for(int j=0;j<v[i].size();j++){
      dp[i][j]=dp[i-1][j]+v[i][j];
      if(i<=l/2 && j)dp[i][j]=max(dp[i][j],dp[i-1][j-1]+v[i][j]);
      if(i>l/2)dp[i][j]=max(dp[i][j],dp[i-1][j+1]+v[i][j]);
    }
  }
  cout << dp[l-1][0] << endl;
 
  return 0;
}

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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B==C+D){
    cout<<"Balanced"<<endl;
    return 0;
  }
  else if(A+B>C+D){
    cout<<"Left"<<endl;
    return 0;
  }
  cout<<"Right"<<endl;
  return 0;
}

    

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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;

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

  int N,A,B;
  cin >> N >> A >> B;
  string S;
  cin >> S;

  int a = 0;
  int b = 0;
  REP(i,N) {
    if (a + b >= A + B) {
      cout << "No" << endl;
    } else if (S[i] == 'a') {
      a += 1;
      cout << "Yes" << endl;
    } else if (S[i] == 'b' && b < B){
      b += 1;
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3780
import sys
sys.setrecursionlimit(10**7)
INF=10**18

def main():
    N,Z,W=map(int,input().split())
    a=list(map(int,input().split()))
    dic={}
    def rec(z,w,now,t):
        if dic.get((now,t),None)!=None:
            return dic[(now,t)]
        if now>=N-1:
            return abs(z-w)
        if not t:
            res=-INF
            for i in range(now+1,N):
                r=rec(a[i],w,i,1)
                res=max(res,r)
        else:
            res=INF
            for i in range(now+1,N):
                r=rec(z,a[i],i,0)
                res=min(res,r)
        dic[(now,t)]=res
        return res

    return rec(Z,W,-1,0)
    
print(main())


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

int main()
{
  int N;
  cin>>N;
  vector<pair<int, int>> vec;
  
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    vec.push_back(make_pair(b,a));
  }
  sort(vec.begin(),vec.end());
  bool flag=true;
  int now=0;
  for(int i=0;i<N;i++){
    now+=vec[i].second;
    if(vec[i].first<now) {
      flag=false;
      break;
    }
  }
    
  cout<<( (flag)? "Yes":"No"  );
}


Measured memory_bytes: 2420
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

n, m = map(int, input().split())

if n == m:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

//ei1333さんのGitHubから https://ei1333.github.io/luzhiled/

//グラフ用テンプレ
//edge := 重み付き辺
//Edges := 重み付き辺集合
//WeightedGraph := 重み付きグラフ
//UnWeightedGraph := 重みなしグラフ
//Matrix := 距離行列
template< typename T >
struct edge {
	int src, to;
	T cost;
	edge(int to, T cost) : src(-1), to(to), cost(cost) {}
	edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
	
	edge &operator=(const int &x) {
		to = x;
		return *this;
	}
	operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
//テンプレここまで

//Dijkstra : E log(V)
template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
	const auto MINF = numeric_limits< T >::max();
	vector< T > dist(g.size(), MINF);

	using Pi = pair< T, int >;
	priority_queue< Pi, vector< Pi >, greater< Pi > > que;
	dist[s] = 0;
	que.emplace(dist[s], s);
	while(!que.empty()) {
		T cost;
		int idx;
		tie(cost, idx) = que.top();
		que.pop();
		if(dist[idx] < cost) continue;
		for(auto &e : g[idx]) {
			auto next_cost = cost + e.cost;
			if(dist[e.to] <= next_cost) continue;
			dist[e.to] = next_cost;
			que.emplace(dist[e.to], e.to);
		}
	}
	return dist;
}
//

int main() {
	int ans = 0;
	int tmp;
	int n;
	int a, b, c;
	cin >> n;
	int q, k;
	WeightedGraph< ll > G(n+1);
	REP(i, n-1){
		cin >> a >> b >> c;
		G[a].emplace_back(b, c);
		G[b].emplace_back(a, c);
	}
	cin >> q >> k;
	auto dis = dijkstra(G, k);
	REP(i, q){
		cin >> a >> b;
		cout << dis[a] + dis[b] << endl;
	}
}

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

unsigned long int q, h, s, d, n;

unsigned long int solve() {
    unsigned long int res=0;
    if (n%2) {
        // odd
        res += (n-1)*d/2 + s;
    } else {
        res += n*d/2;
    }
    return res;
}

int main() {
    std::cin >> q >> h >> s >> d
             >> n;
    if (2*q < h) h = 2*q;
    if (2*h < s) s = 2*h;
    if (2*s < d) d = 2*s;

    std::cout << solve() << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<ll> A(N, 0);
  vector<ll> AA(N, 0);
  map<ll, ll> mp;
  REP(i, N){
    cin >> A[i];
    if(i){
      AA[i] = A[i] + AA[i-1];
    }else{
      AA[i] = A[i];
    }
    mp[AA[i]] += 1;
  }
  ll ans = 0;
  REP(i, N){
    if(AA[i] == 0) ans++;
    mp[AA[i]]--;
    ans += mp[AA[i]];
  }
  cout << ans << endl;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define int long long

int ret_int( char c ) {
  if( c == 'T' || c == 'K' || c == 'Q' || c == 'J' ) return 10;
  else if( c == 'A' ) return 11;
  else return (c - '0');
}

signed main(){
  int N;
  cin >> N;
  while( N-- ) {
    int sum = 0;
    int flag = 0;
    char a, b;
    cin >> a >> b;
    if( a == 'A' ) flag++;
    if( b == 'A' ) flag++;
    if( a == 'A' && b == 'A' ) sum = 12;
    else sum = ret_int( a ) + ret_int( b );

    char card[8];
    for(int i=0; i<8; i++) cin >> card[i];
    if( sum == 21 ) cout << "blackjack" << endl;
    else {
      for(int i=0; i<8; i++) {
	while( sum > 21 && flag) {
	  sum-=10;
	  flag--;
	}
	if( sum > 17 ) {
	  break;
	}
	else if( sum == 17 ) {
	  if( flag ) {
	    if( card[i] == 'A' ) {
	      if( sum + 11 > 21 ) sum++;
	      else sum += 11, flag = true;
	    } else {
	      sum += ret_int( card[i] );
	    }
	  }
	  else break;
	}else {
	  if( card[i] == 'A' ) {
	    if( sum + 11 > 21 ) sum++;
	    else sum += 11, flag = true;
	  } else {
	    sum += ret_int( card[i] );
	  }
	}
      }

      if( sum > 21 ) cout << "bust" << endl;
      else cout << sum << endl;
    }
  }
}
 

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 3.14159
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
    int n;cin>>n;
    int a[n+1];
    int c[n+1]={0};
    for(int i=2;i<=n;++i)
    {
    	cin>>a[i];
    	c[a[i]]++;
    }
    for(int i=1;i<=n;++i)
    {
    	cout<<c[i]<<"\n";
    }




    return 0;
}

Measured memory_bytes: 5180
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main(){
    Int N;cin >> N;
    Int a,b;cin >> a >> b;
    Int ama = 0;
    if(a==0){
        cout << 0 << endl;
        return 0;
    }
    if(N%(a+b)<a){
        ama = N%(a+b);
    }
    else{
        ama = a;
    }

    cout << (N/(a+b))*a+ama << endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <math.h>

using namespace std;

int main() {
long x,y;
cin >> x;
y=100;
for (int i =0; i>=0;i++){
    y=y*1.01;
    if(x<= y){
        cout << (i+1);
        break;
    }
}
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X;
  cin>>X;
  if(X>1799){
    cout<<1<<endl;
  }
  else if(X>1599){
    cout<<2<<endl;
  }
  else if(X>1399){
    cout<<3<<endl;
  }
  else if(X>1199){
    cout<<4<<endl;
  }
  else if(X>999){
    cout<<5<<endl;
  }
  else if(X>799){
    cout<<6<<endl;
  }
  else if(X>599){
    cout<<7<<endl;
  }
  else if(X>399){
    cout<<8<<endl;
  }
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC150A
{
    class Program
    {
        static void Main(string[] args)
        {
            int k, x;

           var word = Console.ReadLine().Split(' ');

            k = int.Parse(word[0]);
            x = int.Parse(word[1]);

            if (500 * k >= x)
                Console.WriteLine("Yes");

            else
                Console.WriteLine("No");

            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>

using namespace std;

int main(){
  int n, num, right, left;
  bool flag;

  cin >> n;

  for(int i = 0; i < n; i++){
    right = 0;
    left = 0;
    flag = true;
    for(int j = 0; j < 10; j++){
      cin >> num;

      if(right < num){
        right = num;
      }else if(left < num){
        left = num;
      }else{
        flag = false;
      }

    }

    if(flag){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#define sz(a) (int)(a).size()

using namespace std;

typedef vector<int> vi;
typedef long long ll;

int c(int a,int b){
	return abs(a-b);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++)
		cin>>h[i];
	int dp[n];
	dp[0]=0;
	dp[1]=c(h[0],h[1]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+c(h[i],h[i-1]), dp[i-2]+c(h[i],h[i-2]));
	}
	cout<<dp[n-1]<<"\n";
	
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define X first
#define Y second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<
#define debug(...) fprintf(stderr, __VA_ARGS__)

int main()
{
  int n;
  scanf("%d", &n);
  int m;
  scanf("%d", &m);
  int w[n], v[n];
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &w[i], &v[i]);
  }
  vector<ll> a[4]; ll b[4]; memset(b, -1, sizeof b);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      if (b[j] == -1 || b[j] == w[i]) {
        a[j].pb(v[i]);
        if (b[j] == -1)
          b[j] = w[i];
        break;
      }
    }
  }
  for (int i = 0; i < 4; i++) {
    sort(a[i].begin(), a[i].end(), greater<int>());
  }
  vector<ll> pre[4];
  for (int i = 0; i < 4; i++) {
    if (a[i].size() == 0) continue;
    pre[i].pb(a[i][0]);
    for (int j = 1; j < a[i].size(); j++)
      pre[i].pb(pre[i][j - 1] + a[i][j]);
  }
  ll rj = 0;
  for (int i = 0; i <= pre[0].size(); i++)
    for (int j = 0; j <= pre[1].size(); j++)
      for (int k = 0; k <= pre[2].size(); k++)
        for (int l = 0; l <= pre[3].size(); l++)
          if (i * b[0] + j * b[1] + k * b[2] + l * b[3] <= m)
            rj = max((i == 0 ? 0 : pre[0][i - 1]) + (j == 0 ? 0 : pre[1][j - 1]) + (k == 0 ? 0 : pre[2][k - 1]) + (l == 0 ? 0 : pre[3][l - 1]), rj);
  printf("%lld\n", rj);
  return 0;
}


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


int main() {
    string S;
    cin >> S;

    bool ans = true;
    bool aCheck = false;
    bool cCheck = false;


    if (S[0] == 'A') aCheck = true;
    else ans = false;
    
    for (int i = 1; i < S.size(); ++i) {
        if (S[i] >= 'a' && S[i] <= 'z') continue;
        else if (i >= 2 && i <= S.size() - 2 && !cCheck) {if (S[i] == 'C') cCheck = true;}
        else ans = false;
    }

    if (ans && aCheck && cCheck) cout << "AC" << endl;
    else cout << "WA" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 18;
char cn[cm], * ci = cn, ct;
const int dm = 1 << 16;
char dn[dm], * di = dn;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	fread(cn, 1, cm, stdin);
	int K = getint(), Q = getint();
	int D[5000];
	rep(i, K) D[i] = getint();

	rep(i, Q) {
		int N = getint(), X = getint(), M = getint();
		N--;
		X %= M;

		int N2 = N / K;
		N %= K;

		ll kosuu = 0, kosuu2 = 0;
		ll kazu = 0, kazu2 = 0;
		rep(i, N) {
			int kari = D[i] - int(double(D[i]) / M) * M;
			if (kari) {
				kosuu++;
				kazu += kari;
			}
		}
		for (int i = N; i < K; i++) {
			int kari = D[i] - int(double(D[i]) / M) * M;
			if (kari) {
				kosuu2++;
				kazu2 += kari;
			}
		}
		kosuu *= N2 + 1;
		kazu *= N2 + 1;
		kosuu2 *= N2;
		kazu2 *= N2;
		kosuu += kosuu2;
		kazu += kazu2 + X;

		kosuu -= kazu / M;

		putint(kosuu);
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#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 FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int N;


int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    vector<vector<int>> G(N);
    vector<ll> seen(N);
    map<pii,ll> m;

    rep(i,N-1){
        int a,b,c;
        cin >> a >> b >>c;
        --a;--b;
        G[a].PB(b);
        G[b].PB(a);
        m[pii(a,b)] = c;
        m[pii(b,a)] = c;

    }

    int Q,K;
    cin >> Q >> K;
    --K;

    queue<pii> q;
    q.push(pii(K,K));
    
    while(!q.empty()){
        int from = q.front().first;
        int to = q.front().second;
        q.pop();
        
        if(to != from){
            seen[to] = seen[from] + m[pii(from,to)];
        }

        for(int i:G[to]){
            if(!seen[i] && i != K){
                q.push(pii(to,i));
            }
        }
    }

    rep(i,Q){
        int x,y;
        cin >> x >> y;
        --x;--y;
        cout << seen[x] + seen[y] << endl;
    }



    //rep(i,N)cout << seen[i] << endl;


    



    
}

Measured memory_bytes: 21368
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N, L;
  string s[110];
  int res=0;
  cin >> N >> L;
  rep(i,N) cin >> s[i];

  sort(s, s+N);

  rep(i,N) cout << s[i];
  cout << endl;
}


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

using namespace std;

int main(){

	int a, b, c, d, e, k;
	cin>> a >> b >> c >> d >> e >> k;

	if(e-a>k){
		cout<< ":(" << endl;
	}else{
		cout<< "Yay!" << endl;
	}

}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
X = 0
for i in range(N):
  A = list(map(int, input().split()))
  D = [A[j] * B[j] for j in range(M)]
  if sum(D) + C > 0:
    X += 1
print(X)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <deque>
#include <string>
#include <cmath>
#include <stack>
#include <map>
#include <cstdio> 
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int a, b;  cin >> a >> b;
	if (b % a == 0) {
		cout << a + b << '\n';
	}
	else {
		cout << b - a << '\n';
	}



}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,i;
    cin>>n;
    string s;
    while(n>0)
    {
        int r=n%26;
        s+=(r==0)?'z':char(r+'a'-1);
        n-=(r==0)?26:r;
        n/=26;
    }
    reverse(s.begin(),s.end());
    cout<<s;
    return 0;
}

Measured memory_bytes: 3652
a,b = map(int,input().split())

if a < 0 and b < 0:
    if (b - a + 1) % 2 == 0:
        print('Positive')
    else:
        print('Negative')
elif (a < 0 and b > 0) or (a == 0 or b == 0):
    print('Zero')
else:
    print('Positive')
    



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define TR(X) ({ if(1) cerr << "Trace: " << (#X) << " = " << (X) << endl; })

vector<bool> visited;

void calculate(vector<vector<ll> > &adj, vector<ll> &value, ll cur, ll pred) {
	value[cur] += value[pred];
	visited[cur] = true;
	for(ll nxt: adj[cur]) if(!visited[nxt]) calculate(adj, value, nxt, cur);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n,q; cin >> n >> q;
	visited.assign(n, false);
	vector<vector<ll> > adj(n);
	vector<ll> value(n);
	for(ll i = 0; i < n - 1; i++) {
		ll a,b; cin >> a >> b;
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for(ll i = 0; i < q; i++) {
		ll p,x; cin >> p >> x;
		p--;
		value[p] += x;
	}
	visited[0] = true;
	for(ll nxt: adj[0]) calculate(adj, value, nxt, 0LL);
	for(ll i = 0; i < n; i++) cout << value[i] << " \n"[i == n - 1];
}



Measured memory_bytes: 27392
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<cmath>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define DBG cout << '!' << endl;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int kazu[1000100];

int main()
{
	int n;
	cin >> n;
	
	REP(i,n)
	{
		int tmp;
		cin >> tmp;
		kazu[tmp]++;
		kazu[tmp+1]++;
		kazu[tmp+2]++;
	}
	
	int ans = 0;
	int ret = 0;
	REP(i,1000001)
	{
		if(kazu[ans]<kazu[i])
		{
			ans = i;
		}
	}
	
	cout << kazu[ans] << endl;
	
//	SHOW1d(kazu,1000);
		
	return 0;
}

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

int main() {
	int n;
	bool a[4][13];
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 13; j++)
			a[i][j] = true;
	cin >> n;
	for (int i = 0; i < n; i++) {
		char c;
		int r;
		cin >> c >> r;
		switch (c) {
		case 'S':
			a[0][r - 1] = false;
			break;
		case 'H':
			a[1][r - 1] = false;
			break;
		case 'C':
			a[2][r - 1] = false;
			break;
		case 'D':
			a[3][r - 1] = false;
			break;
		}
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (a[i][j]) {
				switch (i) {
				case 0:
					cout << "S " << j + 1 << endl;
					break;
				case 1:
					cout << "H " << j + 1 << endl;
					break;
				case 2:
					cout << "C " << j + 1 << endl;
					break;
				case 3:
					cout << "D " << j + 1 << endl;
					break;
				}
			}
		}
	}
}


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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define VI(v,n) vector<int> v(n);REP(i,n){assert(0<scanf("%d",&v[i]));}

int main(){
  INT(n); VI(as, n);
  int ans = n;
  map<int, int> me, mo;
  REP(i, n){
    if (i % 2 == 0){
      if (me.count(as[i])){
        me[as[i]]++;
      } else {
        me[as[i]] = 1;
      }
    } else {
      if (mo.count(as[i])){
        mo[as[i]]++;
      } else {
        mo[as[i]] = 1;
      }
    }
  }
  vector<pair<int, int>> ve, vo;
  ve.EB(0, 0); vo.EB(0, 0);
  for(auto p: me){
    ve.EB(p.second, p.first);
  } sort(ve.rbegin(), ve.rend());
  for(auto p: mo){
    vo.EB(p.second, p.first);
  } sort(vo.rbegin(), vo.rend());
  REP(i, 2){
    REP(j, 2){
      if (ve[i].second != vo[j].second){
        ans = min(ans, n - ve[i].first - vo[j].first);
      } else if (ve[i].second == 0){
        ans = min(ans, n / 2);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int MAX_N = 100010;
ll INF = 1LL<<60;
vector<vector<P>> edges(MAX_N);
vector<ll> dist(MAX_N,INF);

void dijkstra(int s) {
    priority_queue<P,vector<P>,greater<P>> que;
    dist[s] = 0;
    que.push(P(0,s));
 
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v =  p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0;i < edges[v].size();++i) {
            P e = edges[v][i];
            if (dist[e.first] > dist[v]+e.second) {
                dist[e.first] = dist[v]+e.second;
                que.push(P(dist[e.first],e.first));
            }
        }
    }
}

int main() {
    int n,m;
    cin >> n >> m;
    for (int i = 0;i < m;++i) {
        int l,r,c;
        cin >> l >> r >> c;
        edges[l-1].push_back(P(r-1,c));
    }
    for (int i = 1;i < n;++i) edges[i].push_back(P(i-1,0));
    dijkstra(0);
    cout << (dist[n-1] < INF ? dist[n-1] : -1) << endl;
    return 0;
}

Measured memory_bytes: 9468
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n,m;
	cin>>n>>m;
	int s[n+1],t[m+1];
	forci(1,n+1)	cin>>s[i];
	forci(1,m+1)	cin>>t[i];
	int dp[n+1][m+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			dp[i][j]=0;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i]==t[j])
				dp[i][j]=(1+(dp[i-1][j]+dp[i][j-1])%mod)%mod;
			else
				dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+mod)%mod;
		}
	}
	cout<<dp[n][m]+1;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}


Measured memory_bytes: 34816
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n <= 9){ cout << n;}
  if (10 <= n && n <= 99) {cout << 9;}
  if (100 <= n && n <= 999){ cout << n-90;}
  if (1000 <= n && n <= 9999){ cout << 909;}
  if (10000 <= n && n <= 99999){ cout << n-9090;}
  if (n == 100000){ cout << 90909;}
}


Measured memory_bytes: 256
n, a = int(input()), list(map(int, input().split()))

print(' '.join(map(str, a)))

for i in range(1, n):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j + 1] = a[j]
        j -= 1
    a[j + 1] = v
    print(' '.join(map(str, a)))

Measured memory_bytes: 7640
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e6 + 3)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}
int exp(int a, int b){
    LL res = 1;
    LL sum = a;
    for(int i=0;i<30;++i){
        if(BIT(i)&b){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
    }
    return res;
}

int main(){
    LL N, X;
    cin >> N >> X;
    N-=X;
    LL ans = 0;
    while(N!=0&&X!=0){
        if(N>=X){
            LL d = N / X;
            ans += d * X * 3;
            N %= X;
        }else{
            LL d = X / N;
            ans += d * N * 3;
            X %= N;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;  cin >> s;
    sort(s.begin(), s.end());
    if (s == "abc") {
      cout << "Yes" << '\n';
    } else {
      cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
  // ifstream cin("../test.txt");
  int l[10];
  int v1, v2;
  while (cin >> l[0]) {
    int L = l[0];
    char c;
    for (int i = 1; i < 10; i++) {
      cin >> c >> l[i];
      L += l[i];
    }
    cin >> c >> v1;
    cin >> c >> v2;

    float t = (float)L / (v1 + v2);
    float d = t * v1;
    for (int i = 0; i < 10; i++) {
      d -= l[i];
      if (d <= 0) {
        cout << i+1 << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int N;
  cin >> N;
  vector<int> A(N), B(N-1);
  for(auto& e : B) cin >> e;
  A[0] = A[1] = B[0];
  for(int i=1; i<N-1; i++) {
    chmin(A[i], B[i]);
    A[i+1] = B[i];
  }
  int ans = 0;
  for(auto e : A) ans += e;
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int n;cin>>n;
    set<int>s;
    for(int i=0;i<n;i++)
    {
        int x;cin>>x;
        s.insert(x);
    }
    if(s.size()==n)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}

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

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int n = inputs[0];
            int k = inputs[1];

            var vs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int[] vls = new int[n + 1];
            vls[0] = 0;
            for (int i = 1; i <= n; i++)
            {
                vls[i] = vls[i - 1] + vs[i - 1];
            }

            int[] vrs = new int[n +1];
            vrs[0] = 0;
            for (int i = 1; i <= n; i++)
            {
                vrs[i] = vrs[i - 1] + vs[n - i];
            }

            int max = -1;
            for (int lout = 0; lout <= n; lout++)
            {
                var minValuesInLeft = new List<int>(n);
                for (int i = 0; i < lout; i++)
                {
                    if (vs[i] < 0)
                    {
                        minValuesInLeft.Add(vs[i]);
                    }
                }

                for (int rout = 0; rout <= n; rout++)
                {
                    if (n < lout + rout) { break; }

                    var minValuesInRight = new List<int>(n);
                    for (int i = 0; i < rout; i++)
                    {
                        if (vs[n - i - 1] < 0)
                        {
                            minValuesInRight.Add(vs[n - i - 1]);
                        }
                    }

                    var minValues = new List<int>(n);
                    minValues.AddRange(minValuesInLeft);
                    minValues.AddRange(minValuesInRight);
                    minValues.Sort();

                    for (int kin = 0; kin <= k; kin++)
                    {
                        if (k < lout + rout + kin) { break; }

                        int total = vls[lout] + vrs[rout] - minValues.Take(kin).Sum();

                        if (max < total)
                        {
                            max = total;
                        }
                    }
                }
            }

            Console.WriteLine(max);
        }
    }
}

Measured memory_bytes: 17484
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(ll i=0; i < n; i++)
#define reps(i, n) for(ll i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;
int n;

int main() {
  int n;cin >> n;
  int ans=0;
  int step=0;
  ll s;
  cin >> s;
  rep(i,n-1){
    ll h;cin >> h;
    if(s>=h)step++;
    else step=0;
    ans=max(step,ans);
    s=h;
  }
  cout << ans;
}

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

int main(){
    
    int W, H, x, y, r;
    
    cin >> W >> H >> x >> y >> r;
    
    if (x+r<=W){
        if (x-r>=0){
            if(y+r<=H){
                if(y-r>=0){
                    cout << "Yes" << '\n';
                }else{
                    cout << "No" << '\n';
                }
            }else{
                cout << "No" << '\n';
            }
        }else{
            cout << "No" << '\n';
        }
    }else{
        cout << "No" << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, A, B;
  cin >> K;
  cin >> A >> B;
  bool flag = false;
  for(int i = A; i <= B; i++){
    if(i%K == 0){
      flag = true;
      break;
    }
  }
  if(flag) cout << "OK" << endl;
  else cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;
    vector<long long> A(N);
    priority_queue<int> pq;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        pq.push(A[i]);
    }
    while(M > 0){
        long long q = pq.top();
        pq.pop();
        q /= 2;
        pq.push(q);
        M--;
    }
    long long ans = 0;
    int n = pq.size();
    for(int i = 0; i < n; i++){
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1660
#include <stdio.h>

#define MAX 100000
#define INFINITY 2000000000

struct Card{
  char s;
  int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void marge(struct Card[],int,int,int);
void margeSort(struct Card[],int,int);
int partition(struct Card[],int,int,int);
void quickSort(struct Card[],int,int,int);

int main(){
  int n,i,j,v;
  int stable=1;
  struct Card A[MAX],B[MAX];
  char S[10];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].s=B[i].s=S[0];
    A[i].value=B[i].value=v;
  }
  margeSort(A,0,n);
  quickSort(B,n,0,n-1);
  for(i=0;i<n;i++){
    if(A[i].s != B[i].s)stable=0;
  }

  if(stable ==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].s,B[i].value);
  }

  return 0;
}

void marge(struct Card A[],int left,int mid,int right)
{
  int i,j,k,n1,n2;

   n1=mid-left;
   n2=right-mid;
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1].value=INFINITY;
  R[n2].value=INFINITY;
  i=0;
  j=0;
  for(k=left;k<right;k++)
    {
      if(L[i].value<=R[j].value){
	A[k]=L[i++];
      }
      else {
	A[k]=R[j++];
      }
    }
}

void margeSort(struct Card A[],int left,int right)
{
  int mid;  
  if(left+1<right){
    mid = (left+right)/2;
    margeSort(A,left,mid);
    margeSort(A,mid,right);
    marge(A,left,mid,right);
  }
}


int partition(struct Card A[],int n,int p,int r){

  int i,j;
  struct Card t,x;
  x=A[r];
  i=p-1;

  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }

  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

Measured memory_bytes: 2952
#include<stdio.h>
int main (){
  int n;
  scanf("%d",&n);
  int a[n];
  int b[n];
  for (int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int i=0;i<n;i++){
    b[a[i]]=i+1;
  
  }
for (int i=0;i<n;i++){
  printf("%d ",b[i+1]);
}
  printf("\n");
}
        
    
  

Measured memory_bytes: 1536
import collections
n = int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
l = collections.Counter(prime_factorize(n))

cnt = 0
for c in l.values():
    cnt += int((-1 +((1-4*(-2*c))**0.5))/2)
print(cnt)

Measured memory_bytes: 9724