akhauriyash/Code-Regression huggingface dataset:
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << endl
#else
const bool test = false;
#define dump(x) 
#endif

#else
const bool test = false;
#define dump(x) 
#endif

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}

void solve();

signed main()
{
    cout << fixed << setprecision(20);
    solve();
    while (true)
    {
        char s[MAX];
        if (scanf("%s", s) == EOF)
            break;
        int n = strlen(s);
        for (int i = n - 1; i > -1; i--)
        {
            ungetc(s[i], stdin);
        }
        solve();
    }
    return 0;
}

int N, A, B;
int h[MAX];

bool ok(int v) {
    int rest = v;
    rep(i, N) {
        int magic1 = h[i] - B * v;
        if (magic1 > 0) {
            rest -= magic1 / (A - B) + (magic1 % (A - B) != 0);
        }
    }
    if (rest >= 0) return true;
    else return false;
}

void solve() {
    cin >> N >> A >> B;
    rep(i, N) cin >> h[i];
    
    int l = -1, r = (int)1e10; 
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (ok(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}


Measured memory_bytes: 1024
#include "stdio.h"
int main()
{
  int n, m;
  scanf ("%d",&n);
  scanf ("%d",&m);
  int a[m];
  int i;
  for (i=0; i<m; i++)
    {
      scanf ("%d",&a[i]);
    }
  int sum=0, fsum;
  for (i=0; i<m; i++)
    {
      sum=sum+a[i];
    }
  int ch=n;
  fsum=n-sum;
  if (fsum<0)
    printf ("-1\n");
  else
    printf ("%d\n",fsum);
  return 0;
}

Measured memory_bytes: 1716
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	public static void printArray(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + ", ");
		}
		System.out.println();
	}

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] h = nextIntArray(sc, N);
		int[] dp = new int[N];
		for (int i = 1; i < N; i++) {
			// System.out.println("i = " + i);
			int min = Integer.MAX_VALUE;
			for (int j = 1; j <= K; j++) {
				if (i - j < 0) continue;
				int cost = dp[i - j] + Math.abs(h[i] - h[i - j]);
				// System.out.println("cost = " + cost);
				min = Math.min(min, cost);
			}
			dp[i] = min;
		}
		// printArray(dp);
		System.out.println(dp[N - 1]);
	}
}


Measured memory_bytes: 50568
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    d = []
    for _ in range(n):
        f, s = [int(x) for x in input().split()]
        d.append((s, f))
    d.sort()
    cur = 0
    for b, a in d:
        cur += a
        if cur > b:
            print("No")
            return
    print("Yes")


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""


Measured memory_bytes: 35276
K = int(input())

if K < 10:
  queue = range(1,K+1)
  count = K
else:
  count = 9
  queue = [1,2,3,4,5,6,7,8,9]

while count != K:
  for x in queue:
    if x%10 != 0:
      queue.append(10*x + (x%10) - 1)
      count += 1
      if count == K:
        break

    queue.append(10*x + (x%10))
    count += 1
    if count == K:
      break

    if x%10 != 9:
      queue.append(10*x + (x%10) + 1)
      count += 1
      if count == K:
        break

print(queue[-1])




Measured memory_bytes: 7220
n = int(input())
ls = list(map(int, input().split()))

count = 0

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            tmp = []
            tmp.append(ls[i])
            tmp.append(ls[j])
            tmp.append(ls[k])
            tmp.sort()
            if tmp[0] + tmp[1] > tmp[2]:
                if tmp[0] != tmp[1] and tmp[1] != tmp[2] and tmp[2] != tmp[0]:
                    count += 1

print(count)


Measured memory_bytes: 9196
/**
 *  Polygonal Line Search (PKU 2684)
 *  by Kenji Inoue, 2006-12-29
 **/

#include <iostream>
#include <complex>

using namespace std;

typedef complex<int> P;

int main() {
  int n;
  P p[51][11];
  int m[51];

  while (cin >> n, n) {
    for (int i=0; i<=n; i++) {
      cin >> m[i];
      for (int j=0; j<m[i]; j++) {
        cin >> p[i][j].real() >> p[i][j].imag();
      }
    }

    for (int i=1; i<=n; i++) {
      if (m[0] != m[i]) { continue; }

      bool success;
      int ox1, oy1, ox2, oy2; // origins

      for (int k=0; k<4; k++) {
        for (int j=0; j<m[0]; j++) {
          p[0][j] *= P(0, 1);
        }

        success = true;
        ox1 = p[0][0].real(); oy1 = p[0][0].imag();
        ox2 = p[i][0].real(); oy2 = p[i][0].imag();
        for (int j=0; j<m[0]; j++) {
          if (p[0][j].real() - ox1 != p[i][j].real() - ox2) { success = false; break; }
          if (p[0][j].imag() - oy1 != p[i][j].imag() - oy2) { success = false; break; }
        }
        if (success) { cout << i << endl; break; }

        success = true;
        ox1 = p[0][m[0]-1].real(); oy1 = p[0][m[0]-1].imag();
        ox2 = p[i][0].real(); oy2 = p[i][0].imag();
        for (int j=0; j<m[0]; j++) {
          if (p[0][m[0]-1-j].real() - ox1 != p[i][j].real() - ox2) { success = false; break; }
          if (p[0][m[0]-1-j].imag() - oy1 != p[i][j].imag() - oy2) { success = false; break; }
        }

        if (success) { cout << i << endl; break; }
      }
    }
    cout << "+++++" << endl;
  }

  return 0;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  string S, T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  string U;
  cin >> U;
  if (S == U)
    A--;
  else
    B--;
  cout << A << ' ' << B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<vector<int>> vv(n,vector<int>(26));
  rep(i,n){
    string s;
    cin >> s;
    for(char c : s){
      int x = c - 'a';
      vv[i][x] ++;
    }
  }
  for(int i=0;i<26;i++){
    int tmp = 1000000000;
    for(int j=0;j<n;j++){
      tmp = min(tmp,vv[j][i]);
    }
    rep(j,tmp) cout << (char)(i+'a');
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

import javax.rmi.ssl.SslRMIClientSocketFactory;

public class Main{
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan=new Scanner(System.in);
		int cnt=0;
		int n=scan.nextInt();
		int[] arr1=new int[n];
		
		for(int i=0;i<n;i++){
			arr1[i]=scan.nextInt();
		}
		int m=scan.nextInt();
		for(int i=0;i<m;i++){
			int t=scan.nextInt();
			for(int j=0;j<n;j++){
				if(t==arr1[j])
				{
					cnt++;
					break;
				}
					
			}
		}
		
		System.out.println(cnt);
	}

}



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

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> time(N, 0);
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> time[i];
        if (i >= 1 && time[i] <= time[i-1] + T) {
            ans += time[i] - time[i-1];
        }else{
            ans += T;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

struct Edge {
    int to, id;
    Edge(int to, int id): to(to), id(id) {}
};

vector<Edge> g[55];

vector<int> es;
bool dfs(int v, int goal, int p = -1) {
    if (v == goal) return true;
    for(auto e: g[v]) {
        if (e.to == p) continue;
        if (dfs(e.to, goal, v)) {
            es.push_back(e.id);
            return true;
        }
    }
    return false;

}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }
    cin >> m;
    vector<int> eset(m);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        es = vector<int>();
        dfs(a, b);
        for(int e: es) {
            eset[i] |= 1LL<<e;
        }
    }
    int ans = 0;
    rep(bit, (1<<m)) {
        int mask = 0;
        rep(i, m) {
            if (bit & (1 << i)) mask |= eset[i];
        }
        int white = __builtin_popcountll(mask);
        int cnt = 1LL<<(n - 1 - white);
        if (__builtin_popcountll(bit) % 2 == 0) ans += cnt;
        else ans -= cnt;
    }
    cout << ans << endl;



    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cmath>

int main()
{
	int n,d,x,y,s=0;
	scanf("%d %d",&n,&d);
	for (int i=0;i<n;i++){
		scanf("%d %d",&x,&y);
		if ((double)x*x+(double)y*y<=(double)d*d) s++;
	}
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 1736
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

/*int par[100000];

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

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

int min(int a, int b){
    if(a > b) return b;
    else return a;
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    par[x] = y;
}*/

int main(){

	int D,L;
	cin >> D >> L;

	int answer = 0;

	answer += D/L;
	answer += D%L;

	cout << answer << endl;
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 999999797
#define N 100001

int n, k, ar[100001], dp[100001];

int solve(int idx) {
        if (idx == n - 1)
                return 0;
        int &ret = dp[idx];
        if (ret != -1) return ret;
        ret = 1e9;
        for (int i = 1; i <= k; i++) {
                if (idx + i < n)
                        ret = min(solve(idx + i) + abs(ar[idx] - ar[idx + i]), ret);
        }
        return ret;
}

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> n>> k;
        for (int i = 0; i < n; i++) {
                cin >> ar[i];
        }
        memset(dp, -1, sizeof dp);
        cout << solve(0);
return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main()
{
    int n;
    cin >> n;
    int arr[n + 1];
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        sum += arr[i];
    }
    int target = (int)ceil(1.0 * sum / n);
    int cost1 = 0, cost2 = 0, cost3 = 0;
    for(int i = 0; i < n; i++)
        cost1 += (arr[i] - target) * (arr[i] - target);
    for(int i = 0; i < n; i++)
        cost2 += (arr[i] - (target - 1)) * (arr[i] - (target - 1));
    for(int i = 0; i < n; i++)
        cost3 += (arr[i] - (target + 1)) * (arr[i] - (target + 1));
    cout << min(cost1, min(cost2, cost3));
    return 0;
}

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

string a[3];

char tate(){
	for(int i=0;i<3;i++){
		if(a[0][i]==a[1][i]&&a[0][i]==a[2][i]&&a[0][i]!='+'){
			return a[0][i];
		}
	}
	return '+';
}

char yoko(){
	for(int i=0;i<3;i++){
		if(a[i][0]==a[i][1]&&a[i][0]==a[i][2]&&a[i][0]!='+'){
			return a[i][0];
		}
	}
	return '+';
}

char naname(){
	if(a[1][1]==a[2][2]&&a[1][1]==a[0][0]&&a[0][0]!='+')return a[1][1];
	else if(a[0][2]==a[1][1]&&a[1][1]==a[2][0]&&a[0][2]!='+')return a[1][1];
	return '+';
}

int main(){
	while(cin>>a[0],a[0]!="0"){
		for(int i=1;i<3;i++)cin>>a[i];
		if(tate()!='+')cout<<tate();
		else if(yoko()!='+')cout<<yoko();
		else if(naname()!='+')cout<<naname();
		else cout<<"NA";
		cout<<endl;
	}
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<(b);++i)
#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
#define pi pair<int,int>
#define mk(a,b) make_pair(a,b)
#define mygc(c) (c)=getchar()
#define mypc(c) putchar(c)
#define fi first
#define se second
#define ls(x) t[x].lson
#define rs(x) t[x].rson
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 200005;
const int maxm = 1000005;
const int inf = 2147483647;
typedef long long ll;
const double eps = 1e-9;
const long long INF = 9223372036854775807ll;
ll qpow(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c;b>>=1;}return ans;}
inline void rd(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
inline void rd(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
inline void rd(db *x){scanf("%lf",x);}
inline int rd(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
inline void rd(int a[],int n){FOR(i,0,n)rd(&a[i]);}
inline void rd(ll a[],int n){FOR(i,0,n)rd(&a[i]);}
template <class T, class S> inline void rd(T *x, S *y){rd(x);rd(y);}
template <class T, class S, class U> inline void rd(T *x, S *y, U *z){rd(x);rd(y);rd(z);}
template <class T, class S, class U, class V> inline void rd(T *x, S *y, U *z, V *w){rd(x);rd(y);rd(z);rd(w);}
inline void wr(int x){if(x < 10) putchar('0' + x); else wr(x / 10), wr(x % 10);}
inline void wr(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
inline void wr(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
inline void wr(db x, char c){printf("%.15f",x);mypc(c);}
inline void wr(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
inline void wr(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> inline void wrn(T x){wr(x,'\n');}
template<class T, class S> inline void wrn(T x, S y){wr(x,' ');wr(y,'\n');}
template<class T, class S, class U> inline void wrn(T x, S y, U z){wr(x,' ');wr(y,' ');wr(z,'\n');}
template<class T, class S, class U,class H> inline void wrn(T x, S y, U z,H h){wr(x,' ');wr(y,' ');wr(z,' ');wr(h,'\n');}
template<class T> inline void wra(T x[], int n){int i;if(!n){mypc('\n');return;}FOR(i,0,n-1)wr(x[i],' ');wr(x[n-1],'\n');}
char s[maxn];

int main(){
	rd(s);
	int n=strlen(s);
	int sum=0;
	FOR(i,0,n){
		sum+=s[i]-'0';
	}
	if(sum%9==0)wrn("Yes");else wrn("No");
} 

Measured memory_bytes: 3812
//                             In The Name Of Allah                                           
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 

const int N = 1e5 + 100, OO = 100, T = 10, M = 100, P = 6151, SQ = 280, lg = 30;
typedef pair <int, int> pii;
vector <pii> v[N];
bool mark[N], nis[N];
int is[N], c[5], cnt;

bool dfs(int x) {
	bool b = false;
	mark[x] = true;
	c[is[x]]++;
	cnt++;
	for(auto u : v[x]) {
		int p = (is[x] + u.ss) % 3;
		if(mark[u.ff]) {
			if(is[u.ff] != p)
				b = true;
		}
		else {
			is[u.ff] = p;
			b |= dfs(u.ff);
		}
	}
	return b;
}

int32_t main() {
	use_fast;
 	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		v[x].pb({y, 1});
		v[y].pb({x, 2});
	}
	queue <int> q;
	for(int i = 1; i <= n; i++) {
		int b1 = false, b2 = false;
		for(auto u : v[i]) {
			if(u.ss == 2)
				b1 = true;
			else
				b2 = true;
		}
		if(b1 && b2)
			nis[i] = true, q.push(i);
	}
	while(!q.empty()) {
		int t = q.front();
		q.pop();
		for(auto u : v[t]) 
			if(nis[u.ff] == false)
				nis[u.ff] = true, q.push(u.ff);
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(nis[i])
			continue;
		for(auto u : v[i])
			if(!mark[u.ff])
				ans++;
		mark[i] = true;
	}
	for(int i = 1; i <= n; i++) {
		if(!mark[i]) {
			cnt = 0;
			c[0] = c[1] = c[2] = 0;
			is[i] = 0;
			if(!dfs(i)) 
				ans += c[0] * c[1] + c[1] * c[2] + c[2] * c[0];
			else
				ans += cnt * cnt;
		}
	}
	cout << ans << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04 
5- ...
*/



Measured memory_bytes: 19984
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define mk make_pair
#define endl "\n"
#define ff first
#define ss second
#define mt make_tuple
#define mod 1000000007
#define pi 3.141592653589793238
#define float long double
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod%mod;a=a*a%mod;}return res;}
int main()
{
    fastio;
    float i,j,k,n,m,t;
    float a,b,h;
    cin>>a>>b>>h>>m;
    float ang1=(m/60)*(2*pi);
    float ang2=(h/12)*(2*pi)+(m/60)*(pi/6);
    float dif=abs(ang1-ang2);
    if(dif>pi)
    {
        dif=2*pi-dif;
    }
    float tp=a*a+b*b-2*a*b*cos(dif);
    float ans=sqrt(tp);
    cout<<fixed<<setprecision(25)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{

    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    int ans = 1;
    int D = 0;

    rep(i, N)
    {
        D = D + L[i];
        if (D <= X)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100100;
int n,k,q,a;
int num[N];
int main()
{
    scanf("%d%d%d",&n,&k,&q);
    //for(int i=1;i<=n;i++)
    //num[i]=k;
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&a);
        num[a]++;
    }//3 1 3 2
    for(int i=1;i<=n;i++)
    {
        if(q-num[i]>=k)
            puts("No");
        else
            puts("Yes");
    }
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long target = sc.nextLong();
        long balance = 100;
        int year = 0;

        for (;;) {
            year++;
            balance += balance * 0.01;
            if (balance >= target) {
                System.out.println(year);
                System.exit(0);
            }
        }
    }
}

Measured memory_bytes: 35936
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    ll A,B,C,D,E,F;
    cin>>A>>B>>C>>D>>E>>F;
    double mv = -1;
    ll mall, msug;
    for (ll a=0; 100*A*a<=F; a++)
        for (ll b=0; 100*A*a+100*B*b<=F; b++)
            for (ll c=0; 100*A*a+100*B*b+C*c<=F; c++)
                for (ll d=0; 100*A*a+100*B*b+C*c+D*d<=F; d++){
                    ll all = (C*c+D*d)+100*(A*a+B*b); 
                    ll sug = C*c+D*d;
                    if (a+b<=0)
                        continue;
                    else if (C*c+D*d > E*(A*a+B*b))
                        continue;
                    else if ( ((double)sug)/all > mv){
                        mv = ((double)sug)/all;
                        mall = all;
                        msug = sug;
                    }
                }
    cout<<mall<<" "<<msug<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    S = input()
    T = input()

    s_dict = {}
    t_dict = {}

    for ch_s, ch_t in zip(S, T):
        if ch_t in t_dict.keys():
            if t_dict[ch_t] != ch_s:
                print("No")
                return
        else:
            t_dict[ch_t] = ch_s

        if ch_s in s_dict.keys():
            if s_dict[ch_s] != ch_t:
                print("No")
                return
        else:
            s_dict[ch_s] = ch_t
        #print("s",s_dict)
        #print("t",t_dict)

    print('Yes')
    return


main()

Measured memory_bytes: 3632
///http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_C
#include <bits/stdc++.h>
using namespace std;

int main(){

    int a, b;
    char c;

    while(c!='?'){
        cin >> a >> c >> b;
        if(c == '+') cout << a+b << endl;
        else if(c == '-') cout << a-b << endl;
        else if(c == '*') cout << a*b << endl;
        else if(c == '/') cout << a/b << endl;
    }
    return 0;
}



Measured memory_bytes: 3088
h,w=gets.split.map(&:to_i)
s=[]
for i in 1..h
  s<<gets.chop
end
for i in 0...h
  for j in 0...w
    if s[i][j]=='#'
      next
    end
    c=0
    for dx in -1..1
      for dy in -1..1
        nx=i+dx
        ny=j+dy
        if 0<=nx&&nx<h&&0<=ny&&ny<w
          c+=s[nx][ny]=='#'?1:0
        end
      end
    end
    s[i][j]=c.to_s
  end
end
puts s

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

using namespace std;

typedef long long ll;

ll n, m;
ll h[10010];
ll sh[10010];
ll w[15010];
ll sw[15010];

int main(){
    
    while(cin >> n >> m, n){
        sh[0] = sw[0] = 0;
        for(ll i = 0; i < n; i++){
            cin >> h[i];
            sh[i+1] = sh[i] + h[i];
        }
        for(ll i = 0; i < m; i++){
            cin >> w[i];
            sw[i+1] = sw[i] + w[i];
        }
        
        vector<ll> u;
        vector<ll> v;
        
        for(ll i = 0; i < n+1; i++){
            for(ll j = i+1; j < n+1; j++){
                u.push_back(sh[j] - sh[i]);
            }
        }
        
        for(ll i = 0; i < m+1; i++){
            for(ll j = i+1; j < m+1; j++){
                v.push_back(sw[j] - sw[i]);
            }
        }
        
        sort(u.begin(), u.end());
        sort(v.begin(), v.end());
        /*
        for(ll i = 0; i < u.size(); i++) cout << u[i] << " ";
        cout << endl;
        for(ll i = 0; i < v.size(); i++) cout << v[i] << " ";
        cout << endl;
	*/
        int cnt = 0;
        for(ll i = 0; i < u.size(); i++){
            //cout << u[i] << endl;
            cnt += upper_bound(v.begin(), v.end(), u[i]) - lower_bound(v.begin(), v.end(), u[i]);
        }
        cout << cnt << endl;
    }
}

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

int main(){
  int N; cin >> N;
  double c=0;
  for(int i=0; i<N; i++){
    double tmp; cin >> tmp;
    c+=(1/tmp);
  }
  cout << setprecision(10) << 1/c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int N = 10000;
bool Check(int x){
	for(int i=2;i<=sqrt(x);i++){
		if(x%i==0){
			return false;
		}
	}
	return true;
}
int main(){
	int n,num=0;
	int val;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>val;
		if(Check(val))
			num++;
	}
	cout<<num<<endl;
}


Measured memory_bytes: 3088
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long MOD = 998244353;

int main(){
    ll H,N;
    cin>>H>>N;
    vector<plong> p(N);
    for(ll i=0;i<N;i++){
        cin>>p[i].first>>p[i].second;
    }
    ll dp[N+1][H+1];
    const ll INF = 9999999999;
    for(ll i=0;i<N+1;i++){
        for(ll j=0;j<H+1;j++){
            dp[i][j] = INF;
        }
    }
    dp[0][0]=0;
    for(ll i=0;i<N;i++){
        for(ll j=0;j<=H;j++){
            chmin(dp[i+1][j],dp[i][j]);
            chmin(dp[i+1][min(j+p[i].first,H)],dp[i+1][j]+p[i].second);
        }
    }
    cout<<dp[N][H]<<endl;
}


Measured memory_bytes: 78464
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  ll ans=0,sum=0;
  map<ll,ll> m;
  m[0]=1;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    sum+=a;
    if(m.find(sum)==m.end()) m[sum]=1;
    else{
      ans+=m[sum];
      m[sum]++;
    }
  }
  cout<<ans<<endl;
}

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


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; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

int main(){
    int h,w; cin >> h >> w;
    string maze[h];
    vector<vector<int>> dist(h,vector<int>(w,-1));

    rep(i,h){cin >> maze[i];}

    int sx=0,sy=0,gx=w-1,gy=h-1;

    queue<pair<int,int>> que;
    que.push(make_pair(sy,sx));
    dist[sy][sx]=0;
    while(!que.empty()){
        pair<int,int> p=que.front();
        que.pop();
        int x=p.second, y=p.first;
        rep(i,4){
            int nx=x+dx[i]; int ny=y+dy[i];
            if(nx>=0 && nx<w && ny>=0 & ny<h && maze[ny][nx]=='.'){
                if(dist[ny][nx]==-1){
                    que.push(make_pair(ny,nx));
                    dist[ny][nx]=dist[y][x]+1;
                }
            }
        }
    }
    //rep(i,h){rep(j,w){cout << dist[i][j] << ' ';}cout << endl;}
    if(dist[gy][gx]==-1) cout << -1 << endl;
    else{
        int road=0;
        rep(i,h){rep(j,w){if(maze[i][j]=='.') road++;}}
        cout << road-dist[gy][gx]-1 << endl;
    } 
}

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

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


long lcm(long a, long b){
    return a / gcd(a,b) * b;    //オーバーフロー防止
}


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

    vector <long> t(n);
    rep(i,n) cin >> t[i];

    if(n==1) {
        cout << t[0] << endl;
        return 0;
    }

    long tmp = t[0];

    for(int i=0; i<n; i++){
        tmp = lcm(tmp, t[i]);
    }

    cout << tmp << endl;

}


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

int main() {
	char n;
	cin>>n;
	string a,b,perm;
	char c;
	for(char i='0';i<n;i++){
		cin>>c;
		a+=c;
	}
	for(char i='0';i<n;i++){
		cin>>c;
		b+=c;
	}
	for(char i='1';i<=n;i++){
		perm+=i;
	}
	int i=0,j[2],k=0;
	do{
		if(perm==a){
			j[k++]=i;
		}
		if(perm==b){
			j[k++]=i;
		}
		if(k==2)break;
		i++;
	}while(next_permutation(perm.begin(),perm.end()));
	cout<<j[1]-j[0];
}



Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
   int n;
   cin >> n;
   int a[3 * n];
   rep(i, 3 * n) cin >> a[i];
   sort(a, a + 3 * n);
   ll ans = 0;
   for(int i = n; i < 3 * n;i+=2)
       ans += a[i];
   cout << ans << endl;
   return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int k, s;
    cin >> k >> s;
    ll ans = 0;
    rep(x, k+1) rep(y, k+1) {
        int z = s - x - y;
        if (z >= 0 && z <= k) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int dp[3][100005];

int main()
{jizz
	int n,k,a,b,c;
	cin >> n;
	for(int i=1;i<=n;++i)
	{
		cin >> a >> b >> c;
		dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a;
		dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b;
		dp[2][i]=max(dp[0][i-1],dp[1][i-1])+c;
	}
	cout << max({dp[0][n],dp[1][n],dp[2][n]}) << "\n";
}

Measured memory_bytes: 1408
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
    ll a = 0, b = 0, c = 0, k = 0;
    cin >> a >> b >> c >> k;
    int ans = a-b;
    if (k%2 == 0) cout << ans << endl;
    else cout << -ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict as dd
from collections import deque as dq
input = sys.stdin.readline
N = int(input())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
d1 = [float("inf")] * (N + 1)
d1[1] = 0
Q = dq([])
Q.append(1)
while len(Q):
  p = Q.popleft()
  for q in e[p]:
    if d1[q] > d1[p] + 1:
      d1[q] = d1[p] + 1
      Q.append(q)
dn = [float("inf")] * (N + 1)
dn[N] = 0
Q.append(N)
while len(Q):
  p = Q.popleft()
  for q in e[p]:
    if dn[q] > dn[p] + 1:
      dn[q] = dn[p] + 1
      Q.append(q)
#print(d1, dn)
f = 0
for i in range(1, N + 1):
  if d1[i] <= dn[i]:
    f += 1
if f > N // 2: print("Fennec")
else: print("Snuke")

Measured memory_bytes: 74076
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main(){
int n,k;
  cin >> n>>k;
  cout <<(n-1)*(k-1);
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		vector<pair<int, int> > v;
		
		for (int i = 0; i < n; i++){
			int stNo;
			scanf("%d", &stNo);
			
			int frame = 0;
			int frameScore[10] = {0}, remain[10] = {0};
			int prev = -1;
			int ct = 0;
			while (frame < 10){
				int pin;
				scanf("%d", &pin);
				frameScore[frame] += pin;
				
				if (frame == 9){
					if (ct == 1 && frameScore[frame] < 10) frame++;
					else if (ct == 2) frame++;
					ct++;
				}
				
				for (int j = 0; j < 10; j++){
					if (remain[j]){
						frameScore[j] += pin;
						remain[j]--;
					}
				}
				
				if (frame < 9){
					if (prev + pin == 10){
						remain[frame] = 1;
						frame++;
						prev = -1;
					}
					else if (pin == 10){
						remain[frame] = 2;
						frame++;
						prev = -1;
					}
					else if (~prev){
						frame++;
						prev = -1;
					}
					else if (prev == -1) prev = pin;
				}
			}
			
			int sum = 0;
			for (int j = 0; j < 10; j++) sum += frameScore[j];
			v.push_back(make_pair(-sum, stNo));
		}
		
		sort(v.begin(), v.end());
		for (int i = 0; i < n; i++){
			printf("%d %d\n", v[i].second, -v[i].first);
		}
	}
	
	return (0);
}

Measured memory_bytes: 1036
w, h, n = map(int, input().split())
x_left = 0
x_right = w
y_bottom = 0
y_top = h
for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    x_left = max(x_left, x)
  if a == 2:
    x_right = min(x_right, x)
  if a == 3:
    y_bottom = max(y_bottom, y)
  if a == 4:
    y_top = min(y_top, y)

if x_right - x_left < 0  or  y_top - y_bottom < 0:
  print(0)
else:
  print((x_right - x_left) * (y_top - y_bottom))


Measured memory_bytes: 38256
use std::io;
use std::cmp;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin
        .read_line(&mut buf)
        .unwrap();
    let n: i64 = buf.trim().parse().unwrap();

    buf = String::new();
    stdin
        .read_line(&mut buf)
        .unwrap();
    let k: i64 = buf.trim().parse().unwrap();

    buf = String::new();
    stdin
        .read_line(&mut buf)
        .unwrap();
    let x: Vec<i64> = buf.split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect();

    let mut ans = 0;
    for i in x {
        ans += cmp::min(i*2, (k-i)*2);
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)


# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

from functools import reduce

MOD = 10**9+7

N,K = map(int,input().split())

c = N-K+1

res = [1]*(K+1)
n = c
for i in range(1, K+1):
    res[i] *= n
    n *= c-i
    n %= MOD

n = reduce(lambda x,y: (x*y)%MOD, range(1,K+1), 1)
n = modinv(n, MOD)

for i in reversed(range(1, K+1)):
    res[i] *= n
    res[i] %= MOD
    n *= i
    n %= MOD

c = K-1
n = 1
for i in range(1, K+1):
    res[i] *= n
    n *= c-i+1
    n %= MOD

n = reduce(lambda x,y: (x*y)%MOD, range(1,K), 1)
n = modinv(n, MOD)

for i in reversed(range(1, K+1)):
    res[i] *= n
    res[i] %= MOD
    n *= i-1
    n %= MOD



for a in res[1:]:
    print(a)


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

using namespace std;

int n;

int main()
{
	string s;
	cin >> s;
	n = s.size();
	for (int i = 0; i < n; i++) {
		if(i == 4) {
			cout << " ";
		}
		cout << s[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;

int a[100001];
 
int main() {

    ll n;
    cin >> n;
    ll sum = 0;
    rep(i,n) {
        ll b;
        cin >> b;
        sum += b;
        a[b]++;
    }
    ll q;
    cin >> q;
    rep(i,q) {
        ll b,c;
        cin >> b >> c;
        sum += (c-b)*a[b];

        cout<<sum<<'\n';
        
        a[c] += a[b];
        a[b] = 0;
    }


 return 0;
}

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


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

    int n,x,t;
    cin >> n >> x >> t;
    int ans = ((n-1)/x+1) * t;
    cout << ans ;


    return 0;
}


Measured memory_bytes: 3608
n, m, x = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(n)]
ans = 9**9
flag = False

for i in range(2**n):# Yes Or No で　2のn乗
    cost = 0
    a = [0]*m
    for j in range(n):
        if (i >> j) & 1: # を n 回右にシフトして 1 と論理積を取る（最下位の桁が 1 かチェック）
            cost += c[j][0]
            for k in range(m):
                a[k] += c[j][k+1]
    if min(a) >= x:
        flag = True
        ans = min(ans, cost)

print(ans if flag else -1)

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
    while (1) {
        int n, m, p;
        cin >> n >> m >> p;
        if (!n) return 0;
        --m;
        vector<int> x(n);
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            cin >> x[i];
            sum += x[i];
        }
        cout << (x[m] ? sum * (100 - p) / x[m] : 0) << "\n";
    }
}



Measured memory_bytes: 2996
/*
    AUTHOR : TANMAY SINHA
    INORMATION TECHNOLOGY
    BIT MESRA ,RANCHI
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define rep(j,L,R) for(j=L;j<R;j++)
#define per(i,L,R) for(i=L;i>= R;i--)
#define all(con) (con).begin(),(con).end()
#define fi first
#define se second
#define foreach(iter,con) for(auto iter=(con).begin(); iter!=(con).end(); iter++)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll power1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}

ll h[100005];
int main()
{
   SPEED
   ll n,i,k,j;
   cin>>n>>k;
   for(i=0;i<n;i++)
    cin>>h[i];
   vl dp(n+1,mod);
   dp[0]=0;
   dp[1]=abs(h[1]-h[0]);
   if(n==2)
   {
       cout<<dp[1];
       return 0;
   }

   for(i=0;i<n;i++)
   {
       for(ll j = i+1;j<=i+k;j++)
        if(j<n)
       dp[j] = min(dp[j],abs(h[i]-h[j])+dp[i]);
   }
   cout<<dp[n-1];
}







Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll M;
    cin >> M;
    vector<ll> d(M), c(M);
    string S;
    ll sum = 0, cnt = 0, index = 0;
    rep(i, M) {
        cin >> d[i] >> c[i];
        sum += (d[i] * c[i]);
        cnt += c[i];
    }
    cnt--;
    cnt += (sum - 1) / 9LL;
    cout << cnt << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    ve<int> a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.rbegin(), b.rend());
    sort(c.begin(), c.end());
    ve<ll> sb(n+1);
    sb[0] = 0;
    rep(i,n){
        int k = upper_bound(c.begin(), c.end(),b[i])-c.begin();
        sb[i+1] = sb[i] + n-k;
    }
    ll ans = 0;
    rep(i,n){
        int k = upper_bound(b.rbegin(), b.rend(), a[i])-b.rbegin();
        ans += sb[n-k];
    }
    cout << ans << endl;
}

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

int main(){
	vector<ll> v(3);
	rep(i,3) cin>>v[i];
	sort(all(v));
	ll red, blue;
	if(v[2]%2==0){
		red=v[2]/2; blue=v[2]/2;
	} else {
		red=v[2]/2; blue=v[2]-v[2]/2;
	}
	red*=v[0]*v[1]; blue*=v[0]*v[1];
	cout<<abs(red-blue)<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define maxi 100005
using namespace std;

ll n;
ll dp[maxi];
ll a[maxi];
ll func(ll i)
{
    if(i==n-1)
    {
        return 0;
    }
    if(i>n-1)
        return 1e9+10;

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

  ll x=abs(a[i]-a[i+1])+func(i+1);
  ll y=abs(a[i]-a[i+2])+func(i+2);

  return dp[i]=min(x,y);



}


int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    memset(dp,-1,sizeof(dp));
   ll ans= func(0);
   cout<<ans<<endl;



    return 0;
}


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


int main()
{
	double w, h;
	int x, y;
	cin >> w >> h >> x >> y;

	char mode;
	if (x == w / 2 && y == h / 2) {
		mode = '1';
	} else {
		mode = '0';
	}

	double area = w * h / 2;

	cout << fixed << setprecision(9) << area << " " << mode << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)


typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


/*************************************************************************/
//多次元配列の確保及び初期化用マクロ
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
/*************************************************************************/



const ll INF = 1e9 + 7;


int main() {

	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;

	int maxi = a + b;
	vector<int> cnt(5, 0);
	int tmp = 0;

	for (int i = 0; i < s.size(); i++)
	{

		if (s[i] == 'a')
		{
			if (tmp < maxi)
			{
				cout << "Yes" << endl;
				tmp++;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else if (s[i] == 'b')
		{
			if (tmp < maxi && cnt[s[i]-'a'] < b)
			{
				cout << "Yes" << endl;
				tmp++;
				cnt[s[i] - 'a']++;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else
		{
			cout << "No" << endl;
		}
	}






	return 0;
}


Measured memory_bytes: 896
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
using namespace std;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>

int main() {
	int R, G;
	cin >> R >> G;

	int x = 2 * G - R;
	cout << x << endl;
}

Measured memory_bytes: 256