akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int cards[5];

bool check ()
{
     for (int i = 0; i < 5; i++) if (cards[i] > 0) return true;
     return false;
}

void ref() { for (int i = 0; i < 5; i++) cards[i] = 0; }

int main()
{
     while (scanf("%d,%d,%d,%d,%d", &cards[0], &cards[1], &cards[2], &cards[3], &cards[4]) != EOF) {
          int yaku = 0;

          sort(cards, cards + 5);

          if (check() && cards[0] == cards[1] && cards[1] == cards[2] && cards[2] == cards[3]) {yaku = 6; ref();}
          if (check() && cards[1] == cards[2] && cards[2] == cards[3] && cards[3] == cards[4]) {yaku = 6; ref();}
          if (check() && cards[0] == cards[1] && cards[1] == cards[2] && cards[3] == cards[4]) {yaku = 5; ref();}
          if (check() && cards[2] == cards[3] && cards[3] == cards[4] && cards[0] == cards[1]) {yaku = 5; ref();}
          if (check() && cards[0] + 1 == cards[1] && cards[1] + 1 == cards[2] && cards[2] + 1 == cards[3] && cards[3] + 1 == cards[4]) {yaku = 4; ref();}
          if (check() && cards[0] == 1 && cards[1] == 10 && cards[2] == 11 && cards[3] == 12 && cards[4] == 13) {yaku = 4; ref();}

          int tmp = 0;
          for (int i = 0; i < 5 && check(); i++) {
               int t = cards[i];
               cards[i] = 0;
               if (t == 0) continue;
               for (int j = 0; j < 5; j++) {
                    if (i == j) continue;
                    if (cards[j] == 0) continue;
                    if (t == cards[j]) tmp++;
               }
               yaku = tmp;
          }

          switch (yaku) {
          case 1: cout << "one pair" << endl; break;
          case 2: cout << "two pair" << endl; break;
          case 3: cout << "three card" << endl; break;
          case 5: cout << "full house" << endl; break;
          case 6: cout << "four card" << endl; break;
          case 4: cout << "straight" << endl; break;
          default: cout << "null" << endl;
          }
     }

     return 0;
}

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


void solve(std::string S){
  long long N = S.size();
  long long rightb = 0;
  long long count = 0;

  for(long long i = N-1; i >= 0; i--){
    if(S[i] == 'B') {
      count += (((N-1) - i) - rightb);
      rightb++;
    }
  }

  cout << count << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
  std::cin >> S;
    solve(S);
    return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;

void dfs(int i, int c, std::string s){
    if(i == N){
        std::cout << s << std::endl;
        return;
    }

    for(int j=0;j<=c;++j){
        std::string t = s;
        t += ('a' + j);
        dfs(i + 1, c, t);
    }

    std::string t = s;
    t += ('a' + (c + 1));
    dfs(i + 1, c + 1, t);
}

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

  std::cin >> N;

  dfs(1, 0, "a");
}


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

int main(){
int H[100000],W[100000];
int c=0;
for(int i=1;i<100000;i++){
cin>>H[i]>>W[i];
c++;
if(H[i]==0 && W[i]==0){
goto aa;
}
}
aa:;
for(int i=1;i<c;i++){
for(int j=0;j<H[i];j++){
for(int k=0;k<W[i];k++){
    if((j==0 || j==(H[i]-1)) || (k==0 || k==(W[i]-1))){
    cout<<"#";
    }
    else{
    cout<<".";
    }
}
cout<<endl;
}
cout<<endl;
}
return 0;
}



Measured memory_bytes: 3112
#include<stdio.h>
#include<string.h>
int main()
{
  char s[7];
  int l=0,c=0;
  scanf("%s",s);
  l=strlen(s);
  
  if(l==6)
  {
    for(int i=0;i<6;i++)
    {
      if(s[i]>=97 && s[i]<=122)
      {
        c=c+1;
      }
    }
    if(c==6)
    {
      if(s[2]==s[3] && s[4]==s[5])
      {
        printf("Yes");
      }
      else
        printf("No");
  }
  }
  return 0;
}


Measured memory_bytes: 128
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

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

print(ans)


Measured memory_bytes: 2940
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

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

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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define sortv(v) sort(v.begin(),v.end());
#define sorta(a,n) sort(a,a+n);
#define arrayin(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define arrayout(a,n) for(int i=0;i<n;i++) cout<<" ";cout<<"\n";
#define whatIs(x) cout<<#x<<" is "<<x<<endl;
#define fillA(a,value) memset(a,value,sizeof(a));
#define len(s) s.length()
#define reached cout<<"reached "<<endl;
#define INF INT_MAX //Infinity
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define MOD 1000000007
#define fi first
#define se second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vi64 vector<lli>
#define viii vector<tuple<int,int,int>>
#define prq priority_queue<int>
#define mii map<int,int>
#define msi multiset<int>
#define nl "\n"
#define sii set<int,int>
#define sz size

typedef long long int lli;
typedef unsigned long long int ulli;
typedef double ld;

using namespace std;

int main()
{
	fio;
	/*int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
	}*/
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(c<a)
	{
		if(d<a) cout<<"0"<<endl;
		else if(d>b)
		{
			cout<<b-a<<endl;
		}
		else
		{
			cout<<d-a<<endl;
		}
	}
	else
	{
		if(c<b)
		{
			if(d<b) cout<<d-c<<endl;
			else cout<<b-c<<endl;
		}
		else
		{
			cout<<"0"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;


int N;
vector<int> A;

int main()
{

	cin >> N;

	A = vector<int>(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}

	double ans = 0.0;

	for (int i = 0; i < N; i++) {
		ans += (double)1 / A.at(i);
	}

	ans = 1 / ans;
	cout << fixed;
	cout << setprecision(10) << ans << endl;



	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;

ll solve(void);
ll gcd(ll x, ll y);

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

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

ll solve(void)
{
	ll n, k;
	cin >> n >> k;

	ll m = n / k;
	ll a1 = abs(n - k * m), a2 = abs(n - k * (m+1));
	
	cout << min(a1, a2) << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  while(n!=0){
    int i;
    double s[1000]={},sum=0,a=0;
    for(i=0;i<n;i++){
      cin >> s[i];
      sum+=s[i];
    }
    for(i=0;i<n;i++){
      a+=((sum/n)-s[i])*((sum/n)-s[i])/n;
    }
    printf("%.5f\n",sqrt(a));
    cin >> n;
  }
   
  return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


  int arr[1001];


int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

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

    for(int i = 1; i <= n; i++)
    {
      int k;
      cin >> k;

      vector<int> v;

      for(int i = 0; i < k; i++)
      {
        int x;
        cin >> x;
        arr[x]++;

      }

    }




    int ans = 0;

    for(int i = 1; i<= m ; i++)if(arr[i] == n)ans++;


      cout << ans;
    return 0;   
}


Measured memory_bytes: 3608
#include<stdio.h>

int main(void) {
	int i,N,n,A,B,sum,Asum=0;
	scanf("%d %d %d",&N,&A,&B);
	for(i=1;i<=N;i++) {
		sum=0;
		n = i;
		while(n) {
			sum += n%10;
			n/=10;
		}
		if(sum>=A && sum<=B) {
			Asum += i;
		}
	}
	printf("%d",Asum);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it;}cout<<endl;}


int main() {
    ll m;
    cin>>m;
    ll a[m];
    rep(i, m){
        cin>>a[i];
    }
    ll sum = 0;
    rep(i, m){
        while(a[i]%2==0){
            sum++;
            a[i]/=2;
        }
    }
    pr(sum);
}



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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
ll kosu [200005];
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)
    {
        cin >> a[i];
        kosu[a[i]]++;
    }
    ll sum = 0;
    rep(i,200005)
    {
        sum += (kosu[i]*(kosu[i]-1))/2;
    }
    rep(i,n)
    {
        cout << sum - (kosu[a[i]]-1) << endl;
    }

}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    int count = 0;
    for (auto i = 100; i > 0; i--) {
        if(a % i == 0 and b % i == 0) count++;
        // cout << i << " " << count << endl;
        if(count == k) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		int A = F, B = F, C = F, X = F / 50, s = 0;
		for (var a = 0; a <= A; a++)
			for (var b = 0; b <= B; b++)
			{
				var c = X - 10 * a - 2 * b;
				if (0 <= c && c <= C) s++;
			}
		WriteLine(s);
	}
}


Measured memory_bytes: 13140
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int a[]=new int[3];
		int z=0;
		while(z<3){
			a[z]=stdIn.nextInt();
			z++;
		}z=0;
		Arrays.sort(a);
		System.out.println((a[1]-a[0])+(a[2]-a[1]));
	}
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll N, K;

signed main()
{
    cin >> N >> K;

    if(K == 0) {
        printf("%lld\n", N * N);
        return 0;
    }

    ll ans = 0;
    for(ll b = 1; b <= N; ++b) {
        ll x = (N / b) + 1;
        ll y = x * K;
        ll z = (N % b) + 1;
        if((N % b) >= K) { z = K; }
        ll w = y - (K - z) - 1;
        ll res = N - w;
        //DBG("b: %lld res: %lld\n", b, res);
        if(res > 0) { ans += res; }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	using T = tuple<int, int, int>;
	for (int N, M, C, s, g; cin >> N >> M >> C >> s >> g&&N;) {
		static int dist[21][101][101], p[21], q[21][51], r[21][51];
		static int fare[21][20001], cost[101][101];
		s--; g--;
		memset(dist, 0x3f, sizeof(dist));
		memset(cost, 0x3f, sizeof(cost));
		rep(i, 0, M) {
			int x, y, d, c;
			cin >> x >> y >> d >> c;
			x--; y--; c--;
			chmin(dist[c][x][y], d);
			chmin(dist[c][y][x], d);
		}
		rep(c, 0, C)
			cin >> p[c];
		rep(c, 0, C) {
			rep(i, 0, p[c] - 1)
				cin >> q[c][i];
			rep(i, 0, p[c])
				cin >> r[c][i];
		}
		rep(c, 0, C)rep(k, 0, N)rep(i, 0, N)rep(j, 0, N)
			chmin(dist[c][i][j], dist[c][i][k] + dist[c][k][j]);
		rep(c, 0, C) {
			int idx = 0;
			fare[c][0] = 0;
			rep(i, 0, 20000) {
				if (idx < p[c] - 1 && i == q[c][idx]) idx++;
				fare[c][i + 1] = fare[c][i] + r[c][idx];
			}
		}
		rep(c, 0, C)rep(i, 0, N)rep(j, 0, N)
			if (dist[c][i][j] < INF)
				chmin(cost[i][j], fare[c][dist[c][i][j]]);
		rep(k, 0, N)rep(i, 0, N)rep(j, 0, N)
			chmin(cost[i][j], cost[i][k] + cost[k][j]);
		cout << (cost[s][g] == INF ? -1 : cost[s][g]) << endl;
	}
	return 0;
}

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

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

  vector<int> city(N,0);

  for(int i = 0; i < M; i++){
	int a, b;
    cin >> a >> b;

    city.at(a-1)++;
    city.at(b-1)++;
  }

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


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int dp[5][4444];

int solve(int k,int sum){
  if(k==3) return sum>1000?0:1;
  if(k==2 && sum>2000) return 0;
  if(k==1 && sum>3000) return 0;
  if(dp[k][sum]) return dp[k][sum];

  int ret = 0;
  for(int i = 0; i <= 1000 && i <= sum; i++){
    ret += solve(k+1,sum-i);
  }
  return dp[k][sum] = ret;
}
int main(void){
  int n;
  for(int i = 0; i <= 4000; i++){
    solve(0,i);
    //cout << i << endl;
  }
  while(cin >> n){
    cout << solve(0,n) << endl;
  }
}

Measured memory_bytes: 1204
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;

signed main(){
    string S;
    cin>>S;
    int l = S.length();
    if(S[0]!='A'){
        cout<<"WA"<<endl;
        return 0;
    }
    int cnt = 0;
    for(int i=2;i+2<=l;i++){
        if(S[i]=='C')cnt++;
    }
    if(cnt!=1){
        cout<<"WA"<<endl;
        return 0;
    }
    for(int i=0;i<l;i++){
        if(S[i]=='A'||S[i]=='C')continue;
        if(islower(S[i]))continue;
        cout<<"WA"<<endl;
        return 0;
    }
    if(S[l-1]=='A'||S[l-1]=='C'){
        cout<<"WA"<<endl;
        return 0;
    }
    cout<<"AC"<<endl;

}

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

using namespace std;
typedef long long ll;

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

int main(){
    string s;
    getline(cin, s);

    vector<mint> p3(s.size() + 1);
    p3.at(0) = 1;
    for(int i = 1; i < p3.size(); ++i){
        p3.at(i) = p3.at(i - 1) * 3;
    }

    ll na = 0, nq = 0, naq = 0, nqb = 0, nqq = 0, nab = 0;
    mint ans = 0;
    for(char c : s){
        if(c == 'A'){
            na += 1;
        }else if(c == 'B'){
            nqb += nq;
            nab += na;
        }else if(c == '?'){
            ans *= 3;
            ans += naq * p3.at(max((nq - 1), 0LL))
                + nqb * p3.at(max((nq - 1), 0LL))
                + nqq * p3.at(max((nq - 2), 0LL))
                + nab * p3.at(nq);

            nqq += nq;
            naq += na;
            nq += 1;
        }else{  // c == 'C'
            ans += naq * p3.at(max((nq - 1), 0LL))
                + nqb * p3.at(max((nq - 1), 0LL))
                + nqq * p3.at(max((nq - 2), 0LL))
                + nab * p3.at(nq);
        }
    }
    cout << ans.v << endl;
    return 0;
}


Measured memory_bytes: 1216
void main()
{
    string s = readln.chomp;

    s[0..$-8].writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////		
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto i:a)
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
map<ll, vl>g;
ll vis[100010], dp[100010];
ll dfs(ll node)
{
	if (vis[node])
		return dp[node];
	vis[node] = 1;
	FOR(i, 0, g[node].size())
	{
		dp[node] = max(dp[node],1+dfs(g[node][i]));
	}
	return dp[node];
}
void solve()
{
	IN(n)IN(m);
	FOR(i, 0, m)
	{
		IN(in1)IN(in2);
		g[in1].pb(in2);
	}
	ll ans = 0;
	FOR(i, 1, n + 1)
	{
		//what(dfs(i))
		ans = max(ans, dfs(i));
	}
	cout << ans;
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}

Measured memory_bytes: 20748
#include <stdio.h>
int main(){
  int n,i,j,k,v,A[1000];

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<n;i++){
    if(i==n-1){
      printf("%d",A[n-1]);
    }
    else{
    printf("%d ",A[i]);
  }
  }
  
  printf("\n");
  for(i=1;i<n;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--; 
    }  
    A[j+1]=v;
    for(k=0;k<n;k++){
       if(k==n-1){
      printf("%d",A[n-1]);
    }
       else{
	 printf("%d ",A[k]);
       }
    }
    printf("\n");
  }
  return 0;
}

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

long long int N, a;

int main(){
    scanf("%lld", &N);
    while(N){
        a += N % 10;
        N /= 10;
    }
    if(a == 1)a = 10;
    printf("%lld", a);
    return 0;
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> as(n);
	for (auto &&a : as)
	{
		cin >> a;
	}

	// x < s / 4m
	// x * 4 * m < s

	int sum = 0;
	for (auto &&a : as)
	{
		sum += a;
	}

	int cnt = 0;
	for (auto &&a : as)
	{
		if (sum <= 4 * a * m)
		{
			cnt++;
		}
	}

	cout << ((m <= cnt) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=100010;
int n,a[N];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    sort(a+1,a+n+1,greater<int>());
    int sg=0;
    for(int i=1;i<=n;i++){
        if(a[i+1]<=i){
            int pos=i;
            while(a[pos+1]==i)pos++;
            if((a[i]-i+1)&(pos-i+1)&1)puts("Second");
            else puts("First");
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 640
N, M = map(int, input().split())
arr = list([] for i in range(N+1))
for i in range(M):
    A,B = map(int, input().split())
    arr[A].append(B)
    arr[B].append(A)

from collections import deque
q = deque()
vis = [0 for i in range(N+1)]

def BFS(t):
    count = 1
    q.append(t)
    while q:
        x = q.popleft()
        for i in arr[x]:
            if vis[i] == 0:
                vis[i] = 1
                count += 1
                q.append(i)
    return count

ans = 0
for i in range(1,N+1):
    if vis[i] == 0:
        vis[i] = 1
        ans = max(BFS(i),ans)

print(ans)

Measured memory_bytes: 119960
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M,K = LI()
A = LI()
B = LI()

cusumA = [A[0]]*N
cusumB = [B[0]]*M

for i in range(1,N):
    cusumA[i] = cusumA[i-1]+A[i]

for i in range(1,M):
    cusumB[i] = cusumB[i-1]+B[i]

ans = 0
for i in range(N):
    left = K-cusumA[i]
    if left < 0:
        break
    p = bisect_right(cusumB,left)
    num = i+1+p
    if num > ans:
        ans = num

p = bisect_right(cusumB,K)
if p > ans:
    ans = p

print(ans)

Measured memory_bytes: 121884
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
using vll=vector<ll>;
using vi=vector<int>;
int main(){
  string s;
  cin>>s;
  int n=s.length(),i,c=0;
  for(i=0;i<n;i++) if(i%2==0 && s.at(i)=='0' || i%2==1 && s.at(i)=='1') c++;
  cout<<min(c,n-c)<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    #define int long long
    int h,w,n;
    cin>>h>>w>>n;
    map<pair<int,int>,int>black;
    set<pair<int,int>>s;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        for(int j=-1;j<=1;j++){
            for(int k=-1;k<=1;k++){
                int x=a+j,y=b+k;
                if(x>0 && y>0 && x<h-1 && y<w-1){
                    black[{x,y}]++;
                    s.insert({x,y});
                }
            }
        }
    }
    int ans[10]={};
    for(auto itr=s.begin();itr!=s.end();itr++){
        ans[black[{(*itr).first,(*itr).second}]]++;
    }
    ans[0]=(h-2)*(w-2);
    for(int i=1;i<10;i++)ans[0]-=ans[i];
    for(int i:ans)cout<<i<<endl;
    return 0;
}


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

int main() {
	
	int a,b,c,aa;
	int ans=3;
	
	cin>>a>>b>>c;
	
	if(a==b){
		aa+=1;
	}
	if(a==c){
	
		aa+=1;
	}
	if(c==b){
	
		aa+=1;
	}
	
	if(aa==0)ans=3;
	if(aa==1)ans=2;
	if(aa==2)ans=2;
	if(aa==3)ans=1;
	
	cout<<ans<<endl;
	
	return 0;
}

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

int n;
string testCase;
string verdicts[4] = {"AC", "WA", "TLE", "RE"};
map<string, int> testCasesCount;

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> testCase;
        testCasesCount[testCase]++;
    }
    for (auto testCase : verdicts)
    {
        cout << testCase << " x " << testCasesCount[testCase] << '\n';
    }
    cin >> n;
}

Measured memory_bytes: 3664
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cstdlib>
#include<cassert>
#include<random>
using namespace std;

const int e=1e9+7;

int cut(int n){
    if(n>255){n=255;}
    if(n<0){n=0;}
    return n;
}

int dp[25000][256];


int main(){
    while(1){
    
        
        
    int n,m;
    fill(&dp[0][0],&dp[24999][256],e);
    vector<int> in,c;
    cin>>n>>m;
        if(n==0 && m==0){break;}
    for(int i=0;i<m;i++){
        int d;
        cin>>d;
        c.push_back(d);
    }
    for(int i=0;i<n;i++){
        int d;
        cin>>d;
        in.push_back(d);
    }
    dp[0][128]=0;
    
    for(int i=0;i<n;i++){
        for(int t=0;t<256;t++){
            for(int h=0;h<c.size();h++){
                if(dp[i][t]!=e){
                    dp[i+1][cut(t+c[h])]=min(dp[i+1][cut(t+c[h])],dp[i][t]+(int)pow((in[i]-cut(t+c[h])),2));
                }
            }
        }
    }
    int ans=e;
    for(int i=0;i<256;i++){
        ans=min(ans,dp[n][i]);
    }
    cout<<ans<<endl;
    
        
        
    }
    return 0;
}


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

int main() {
	int a, b;
	while (true) {
		cin >> a >> b;
		if (a == 0 && b == 0) break;
		if (a < b) cout << a << " " << b << endl;
		else cout << b << " " << a << endl;
	}
	return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){

    double a,b,h,m;
    cin>>a>>b>>h>>m;

    double PI=acos(-1);
    //cout<<PI<<endl;

    double one=2*PI*((h+(m/60))/12);
    double second=2*PI*(m/60);
    double theta=abs(one-second);
    theta=min(theta,2*PI-theta);
    //cout<<theta*(360/(2*PI))<<endl;
    if(theta==PI){
        cout<<a+b<<endl;
    }
    else if(theta==0){
        cout<<abs(a-b)<<endl;
    }
    else{
        double ans=sqrt(a*a+b*b-2*a*b*cos(theta));
        printf("%.9lf\n",ans);
    }
    //cout<<4.56425719433005567605*4.56425719433005567605<<endl;

    return 0;

}
/*

*/


Measured memory_bytes: 4224
#include <stdio.h>
#include <math.h>

int main(void){
    long long n;
    scanf("%lld", &n);

    long long a, b, i;

    for(i=1; i<=sqrt(n); i++){
        if(n%i == 0){
            a = i;
            b = n/i;
        }
    }

    printf("%lld", a+b-2);
    
}

Measured memory_bytes: 128
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
using namespace std;

int main(){
  
  int n; cin >> n;
  vector<string> s(n);
  vector<int> p(n);
  vector<int> index(n);
  
  int i,j,k,tempp,tempi;
  string temps;
  
  for (i=0; i<n; i++){
    cin >> s[i];
    cin >> p[i];
    index[i]=i+1;
  }
  
  for (i=0; i<n-1; i++){
    for (j=0; j<n-i-1; j++){
      if (s[j]>s[j+1]){
      	temps=s[j];
        s[j]=s[j+1];
        s[j+1]=temps;
        
        tempp=p[j];
        p[j]=p[j+1];
        p[j+1]=tempp;
        
        tempi=index[j];
        index[j]=index[j+1];
        index[j+1]=tempi;
      }
    }
  }
  
  vector<int> same(n);
  same[0]=1;
  int count=0;
  
  for (i=0; i<n; i++){
    if (s[i]!=s[i+1]){
      count++;
    }
    
    same[count]++;
  }
  
  int now=0;
  
  for (i=0; i<n; i++){
    for (j=0; j<same[i]; j++){
      for (k=0; k<same[i]-j-1; k++){
        if (p[now+k]<p[now+k+1]){
			temps=s[now+k];
        	s[now+k]=s[now+k+1];
        	s[now+k+1]=temps;
        
        	tempp=p[now+k];
        	p[now+k]=p[now+k+1];
        	p[now+k+1]=tempp;
        
        	tempi=index[now+k];
        	index[now+k]=index[now+k+1];
        	index[now+k+1]=tempi;
        }
      }
    }
    
    now += same[i];
  }
  
  for (i=0; i<n; i++){
    cout << index[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                          
using namespace std;
map<int,int>cnt;
struct point{
	int x, y, t;
}m[100005];
int n,x,y,t;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t>>x>>y;
		m[i].x=x,m[i].y=y,m[i].t=t;
	}
	m[0].x=0,m[0].y=0,m[0].t=0;
	for(int i=1;i<=n;i++) {
		int s,t;
		s=abs(m[i].x-m[i-1].x)+abs(m[i].y-m[i-1].y);
		t=abs(m[i].t-m[i-1].t);
		if(s>t||s%2!=t%2) {cout<<"No"<<endl;return 0;}
	}
	cout<<"Yes"<<endl;
    return 0;
}
//68871358
//76140264
//25446011
//200841159
//914174775

Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
int main(){
   double a,b,h,m; 
  cin >> a >> b >> h >> m  ;
  double A=30*h+m/2;
  double B=6*m;
  double deg=abs(A-B);
  double rad=deg*PI/180.0;
  double ans=a*a+b*b-2*a*b*cos(rad);
  cout << fixed << setprecision(12) << sqrt(ans) << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define PI acos(-1.0)
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define MOD 1000000007
#define MOD1 1000000005
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, 1};
int dy4[] = {1, -1, 1, -1};

int main()
{
    #ifndef ONLINE_JUDGE
    freopen ("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    #endif
    int n, i;
    cin>>n; string s;
    map <string, int> mp;
    for(i=0;i<n;i++){
        cin>>s;
        mp[s]++;
    }
    cout<<"AC"<<" x "<<mp["AC"]<<endl;
    cout<<"WA"<<" x "<<mp["WA"]<<endl;
    cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
    cout<<"RE"<<" x "<<mp["RE"]<<endl;
    return 0;
}


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

const int MAX = 1'000'001;
int n,m,l,r,lft=0,rght=MAX;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>l>>r;
		if(l>lft)
			lft=l;
		if(r<rght)
			rght=r;
	}
	if(rght-lft+1<0)
		cout<<0;
	else
		cout<<rght-lft+1;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<ll> sum(n), b(n);
    rep(i,n){
        ll ai, bi;
        cin >> ai >> bi;
        sum[i] = ai + bi;
        b[i] = bi;
    }
    sort(rall(sum));
    ll sumAB = 0, sumB = 0;
    rep(i,n){
        if (i % 2  == 0) sumAB += sum[i];
        sumB += b[i];
    }
    cout << sumAB-sumB << endl;
    return 0;
}

Measured memory_bytes: 4788
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.min

object Solve {

  private val br = BufferedReader(InputStreamReader(System.`in`))
  private val out = PrintWriter(System.out)

  fun solve() {

    val MOD: Long = 1_000_000_007L

    val n = br.readLine()!!.toInt()
    val a = br.readLine()!!.split(' ').map { it.toLong() }

    var back = mutableListOf(0L)

    var sum = 0L

    for (i in n - 1 downTo 0) {
      sum += a[i]
      sum %= MOD
      back.add(sum)
    }

    var ans = 0L

    for (i in 1 until n) {
      ans += (a[i - 1] * back[n - i]) % MOD
      ans %= MOD
    }

    out.println(ans % MOD)
    out.flush()
  }
}

fun main(args: Array<String>) {
  Solve.solve()
}

Measured memory_bytes: 75296
#include <stdio.h>

long long x_c[] = {1, 5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069, 262141, 524285, 1048573, 2097149, 4194301, 8388605, 16777213, 33554429, 67108861, 134217725, 268435453, 536870909, 1073741821, 2147483645, 4294967293, 8589934589, 17179869181, 34359738365, 68719476733, 137438953469, 274877906941, 549755813885, 1099511627773, 2199023255549, 4398046511101, 8796093022205, 17592186044413, 35184372088829, 70368744177661, 140737488355325, 281474976710653, 562949953421309, 1125899906842621, 2251799813685245, 4503599627370493};
long long y_c[] = {1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, 4398046511103, 8796093022207, 17592186044415, 35184372088831, 70368744177663, 140737488355327, 281474976710655, 562949953421311, 1125899906842623, 2251799813685247};

// Level, 下から食べる枚数, 食べたパティの枚数
void burger(int l, long long *x, long long *y)
{
	// L0バーガはパティのみ
	if (l == 0) {
		if (*x > 0) {
			(*x)--;
			(*y)++;
		}
		return;
	}

	if (*x >= x_c[l]) {
		(*x) -= x_c[l];
		(*y) += y_c[l];
		return;
	}

	// L >= 1
	//最下層のパン
	if (*x > 0) { (*x)--; }
	// L-1バーガー
	if (*x > 0) { burger(l - 1, x, y); }
	// パティ
	if (*x > 0) { (*x)--; (*y)++; }
	// L-1バーガー
	if (*x > 0) { burger(l - 1, x, y); }
	//最上層のパン
	if (*x > 0) { (*x)--; }

	return;
}

int main(int argc, char *argv[])
{
	int n;
	long long x, y;

	scanf("%d %llu", &n, &x);
	y = 0;
	burger(n, &x, &y);

	printf("%llu\n", y);
	return(0);
}


Measured memory_bytes: 128
A, B = map(int, input().split())
S = input()

count = 0
for i in range(len(S)):
    if (S[i] == '-'):
        count += 1

if count == 1:
    if (S[A] == '-'):
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 3060
from math import cos, radians, sqrt

a, b, h, m = map(int, input().split())

h = h*(360/12) + 30*(m/60)
m = m*(360/60)

deg = min(abs(h-m), abs(m-h))

ans = (a**2 + b**2 - 2*a*b*cos(radians(deg)))

print(sqrt(ans))


Measured memory_bytes: 9500
#include<iostream>
#include<string>
#include<queue>
using namespace std;
int main(){
	int n,q;
	cin >> n >> q;
	queue<string> names;
	queue<int> times;
	int t,roop;
	string name;
	for(roop=0;roop<n;roop++){
		cin >> name >> t;
		names.push(name);
		times.push(t);
	}
	int currenttime=0;
	while(n){
		t=times.front();
		times.pop();
		name=names.front();
		names.pop();
		if(q<t){
			currenttime+=q;
			t-=q;
			names.push(name);
			times.push(t);
		}else{
			currenttime+=t;
			cout << name << " " << currenttime << endl;
			n--;
		}
	}
	return 0;
}


Measured memory_bytes: 5728
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int N = sc.nextInt();
      String S = sc.next();
      char data[]= new char[N];

      char c;

      int count = N;

        for(int i = 0;i<N;i++){
          c = S.charAt(i);
          data[i]=c;
        }

        for(int i = 0;i<N-1;i++){
          if(data[i]==data[i+1]){
            count = count-1;
          }
        }
        System.out.println(count);
  }
}

Measured memory_bytes: 28352
S=str(input())
if S[0]=='A':
    S=S[1:]
else:
    print('WA')
    exit()

S_part=S[1:-1]
if S_part.count('C') != 1:
    print('WA')
    exit()
else:
    S_part = S_part.replace('C','')
    S_part = S[0]+ S_part + S[-1]

    for i in range(len(S_part)):
        if S_part[i] >='A' and S_part[i]<='Z':
            print('WA')
            exit()
    else:
        print('AC')

Measured memory_bytes: 3064
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
if n == 1:
  print(0)
  exit()
  
facs = factorization(n)

nums = []

for fac in facs:
  for i in range(1, fac[1]+1):
    nums.append(fac[0]**i)
    
nums = list(set(nums))
cnt = 0
nums.sort()

for num in nums:
  if n % num == 0:
    n = n / num
    cnt += 1
    
print(cnt)

Measured memory_bytes: 9504
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
const double PI = 3.14159265359;

int main()
{
    int N; cin >> N;
    map<LLONG, LLONG> value2NumMap;
    LLONG sum = 0;
    for (int i = 0; i < N; ++i)
    {
        LLONG a; cin >> a;
        sum += a;
        ++value2NumMap[a];
    }
    int Q; cin >> Q;
    for (int i = 0; i < Q; ++i)
    {
        LLONG b, c; cin >> b >> c;
        LLONG num = value2NumMap[b];
        value2NumMap[b] = 0;
        value2NumMap[c] += num;
        sum -= b * num;
        sum += c * num;
        cout << sum << endl;
    }
}


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

long long A[100005];

int main() {
    
    int K;
    cin >> K;
    
    for(int i=1; i<=K; i++)
        cin >> A[i];
    
    long long minn = 2, maxx = 2;
    
    for(int i=K; i>=1; i--)
    {
        maxx = maxx/A[i] * A[i];
        minn = ( minn/A[i] + (minn%A[i]>0) ) * A[i];
        
        if(maxx < minn)
        {
            printf("-1\n");
            return 0;
        }
        
        maxx = (maxx + A[i] - 1);
    }
    
    cout << minn << " " << maxx << endl;
    return 0;
}


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

int main(){
  int N;
  long long x;
  cin >> N >> x;
  vector<long long> a(N);
  for(int i=0; i<N; i++) cin >> a.at(i);
  vector<long long> b(N);
  for(int i=0; i<N; i++) b.at(i)=a.at(N-1-i);
  long long ans1=0;
  for(int i=0; i<N-1; i++){
    if(a.at(i)+a.at(i+1)>x){
      int cnt=a.at(i)+a.at(i+1)-x;
      ans1+=cnt;
      if(cnt<=a.at(i+1)){
        a.at(i+1)-=cnt;
      }
      else{
        a.at(i+1)=0;
      }
    }
  }
  long long ans2=0;
  for(int i=0; i<N-1; i++){
    if(b.at(i)+b.at(i+1)>x){
      int cnt=b.at(i)+b.at(i+1)-x;
      ans2+=cnt;
      if(cnt<=b.at(i+1)){
        b.at(i+1)-=cnt;
      }
      else{
        b.at(i+1)=0;
      }
    }
  }
  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 1792
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime
def run_length_encode(s):
    count = 1
    code = []
    target = s[0]
    for i in range(1, len(s)):
        if target == s[i]: count += 1
        else:
            code.append((target, count))
            target = s[i]
            count = 1
    code.append((target, count))
    return code

N = iin()
h = iln()

dp = [10**9] * (N)
dp[0] = 0

for i in range(N-1):
    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]))
    if i+2 < N:
        dp[i+2] = min(dp[i+2], dp[i]+ abs(h[i]-h[i+2]))
print(dp[N-1])



Measured memory_bytes: 16464
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner kb = new Scanner(System.in);
		int numItems = kb.nextInt();
		int maxWeight = kb.nextInt();

		//i is weight, dp[i] is value at weight i
		long[] dp = new long[maxWeight+1];
		//fill with -1 so we know that we dont know anything there
		Arrays.fill(dp, -1);
		//base case, have nothing
		dp[0] = 0;
		
		//consider items
		//build up the array
		for(int i = 0; i < numItems; i++) {
			int weight = kb.nextInt();
			long value = kb.nextLong();
			for(int j = maxWeight; j >= 0; j--) {
				//-1 means no way to get to state, so we cant build off this
				if(dp[j] == -1) {
					continue;
				}
				//if inbounds
				if(weight+j <= maxWeight) {
					dp[weight+j] = Math.max(dp[weight+j], dp[j]+value);
				}
			}
		}
		
		long max = 0;
		for(int i = 0; i < dp.length; i++) {
			max = Math.max(dp[i], max);
		}
		System.out.println(max);

	}

}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/04  Problem: ABC 043 C / Link: http://abc043.contest.atcoder.jp/tasks/abc043_c  ----- */


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

	LL N; cin >> N;
	vector<LL> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	auto f = [&](LL b) {
		LL sum = 0;
		for (auto it : a) {
			sum += (b - it)*(b - it);
		}
		return sum;
	};

	LL ans = LINF;
	FOR(i, -100, 100 + 1) {
		ans = min(ans, f(i));
	}


	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a + (b - 1)) / b; }
int positive_surplus(int &a) { return (a + MOD) % MOD; }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

class CBigArray {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int N, K;
    cin >> N >> K;
    vector<pair<int, int>> check(N);
    rep(i, N) {
      int temp1, temp2;
      cin >> temp1 >> temp2;
      check[i] = {temp1, temp2};
    }
    sort(ALL(check));
    int sum = 0;
    rep(i, check.size()) {
      sum += check[i].second;
      if (sum >= K) {
        cout << check[i].first << endl;
        return;
      }
    }
  }
};


signed main() {
  CBigArray solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 1792