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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int N, K, d; cin >> N >> K;
	unordered_map <int, int> mp;
	for (int i = 0; i < N; ++i){
		cin >> d;
		++mp[d];
	}
//	assert(m.size() == N);
	set <pair<int,int>> s;
	for (auto it = mp.begin(); it != mp.end(); ++it){
//		cout << *it << " " << m.count(*it) << "\n";
		s.insert(make_pair(it->second, it->first));
	}
//j	cout << s.size() << "\n";
	
	int cnt = 0;
	while (s.size() > K){
//		if (s.size() - *s.begin().first > K){
			cnt += s.begin()->first;	
			s.erase(s.begin());		
	}
	cout << cnt << "\n";	
	return 0;
}


Measured memory_bytes: 20804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n, m;
    cin >> n >> m;
    ll k = m;
    set<int> p;
    for (int i = 2; i <= sqrt(k); i++)
    {   
        if(k % i == 0){
            p.insert(k / i);
            p.insert(i);
        }
    }
    p.insert(1);
    int ans = 0;
    for (auto v : p)
    {   
        if(v * n <= m)
        ans = v;
    }
    cout << (n == 1 ? m : ans) << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {

    int N;
    int d[100] = {0};

    cin >> N;
    for (int i = 0; i < N; i++) cin >> d[i];

    int num[101] = {0};

    for (int i = 0; i < N; i++) {
        num[d[i]] += 1;
    }

    int res = 0;
    for (int i = 1; i <= 100; i++) {
        if (num[i]) {
            res += 1;
        }
    }

    cout << res << endl;

}


Measured memory_bytes: 256
import copy
from sys import stdin


N = int(stdin.readline().rstrip())

L = [ int(x) for x in stdin.readline().rstrip().split()]

count = 0

for i in range(N):
    A = L.pop()
    Ln = copy.copy(L)
    for j in range(len(Ln)):
          B = Ln.pop()
          Lm = copy.copy(Ln)
          for k in Lm:
              C = k
              if ( A != B ) and ( B != C ) and ( C != A ) and ( A + B > C ) and ( B + C > A ) and ( C + A > B ):
                    count+=1
              
          

print(count) 
                


Measured memory_bytes: 9348
#include<iostream>
 using namespace std;
 typedef long long int ll;
 int main(){
 ll A, V;
 cin >> A >> V;
 ll B,W;
 cin >> B >> W;
 ll T;
 cin >> T;
 ll D=abs(A-B);
 ll D2=(V-W)*T;
 puts(D<=D2?"YES":"NO");}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main(void){
  string S;
  cin>>S;
  string A="abcdefghijklmnopqrstuvwxyz";
  int number=0;
  for(int j=0;j<A.length();j++){
      for(int i=0;i<S.length();i++){
          if(S[i]==A[j]){
              number=1;
              break;
          }
      }
      if(number==0){
          cout<<A[j]<<endl;
          return 0;
      }
      number=0;
  }
  cout<<"None"<<endl;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int p[n];
  for (int i=0;i<n;i++) cin >> p[i];
  int count = 0;
  int min = 200001;
  for (int i=0;i<n;i++){
    if (p[i] > min) continue;
    count++;
    min = p[i];
  }
  cout << count;

  return 0;
}

Measured memory_bytes: 1024
if __name__ == "__main__":
    n = input()
    char_string = "qazwsxedcrfvtgbyhnujmikolp"
    char_list = sorted(list(char_string))

    n = int(n)
    result_string = ""
    while 1:
        if n <= 26:
            break
        result_string = char_list[int((n%26)-1)] + result_string
        if (n % 26) == 0:
            n = n//26-1
        else:
            n = n//26
    result_string = char_list[n-1] + result_string
    print(result_string)





        



Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define ulli unsigned lli
#define ld long double
#define pb push_back
#define mp make_pair
#define bp pop_back
#define vi vector<int>
#define vvi vector< vector<int> >
#define vli vector<lli>
#define vvli vector< vector<lli> >
#define pii pair <int, int>
#define pli pair <lli, lli>
#define forn(i,n) for(i=0;i<n;i++)
#define FORN(i,k,n) for(i=k;i<n;i++)
#define rof(i,k,n) for(i=k;i>=n;i--)
#define wh(k) while(k--)
#define mod 1000000007
#define set(a,s) memset(a,s,sizeof(a))

int main()
{
	fast;
	string s,t;
	cin>>s>>t;
	int i,count=0;
	forn(i,3)
	if(s[i]==t[i])
	count++;
	cout<<count<<'\n';
	return 0;
}


Measured memory_bytes: 256
A,B = [int(x) for x in input().split()]
S = input()
flag = True
for ind,i in enumerate(S):
  if(ind!=A):
      if(ord(i)<48 or 57<ord(i)):
         flag = False
         break
  else:
      if(i!='-'):
         flag = False
         break
if(flag):
     print('Yes')
else:
     print('No')
     

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

// ACGT
int dp[2000][4][4][4], mod = 1e9+7;
signed main(){
  int n;cin >> n;
  rep(i,4)rep(j,4)dp[2][i][j][1] = 1;
  repi(i,3,n+1)rep(j,4)rep(k,4)rep(l,4)rep(m,4){
    // AGC, ACG, GAC
    if(j == 1 and k == 2 and l == 0)continue;
    if(j == 1 and k == 2 and m == 0)continue;
    if(j == 2 and k == 1 and l == 0)continue;
    if(j == 1 and k == 0 and l == 2)continue;
    if(j == 1 and l == 2 and m == 0)continue;
    dp[i][j][k][l] += dp[i-1][k][l][m];
    dp[i][j][k][l] %= mod;
  }
  int ans = 0;
  rep(j,4)rep(k,4)rep(l,4){ans += dp[n][j][k][l];ans %= mod;}
  cout << ans << endl;
  return 0;
}





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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 10;

ll n, m;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
long long int n, a[100005], val[100005],set[100005];
int findSet(int x) {
	if (set[x] == x)
		return x;
	return set[x] = findSet(set[x]);
}

void unionSet(int x, int y) {
	int fx = findSet(x);
	int fy = findSet(y);
	if(fx!=fy)
		set[fx] = fy;
}
struct road {
	long long int len,turn1,turn2;
};
struct road rx[100005],ry[100005];
struct retuint {
	long long int x,y,turn;
};
struct retuint retu[100005],retu2[100005];
bool cmp(struct retuint p1, struct retuint p2) {
	if(p1.x<p2.x)	return true;
	if(p1.x>=p2.x)	return false;
}
bool cmp2(struct retuint p1, struct retuint p2) {
	if(p1.y<p2.y)	return true;
	if(p1.y>=p2.y)	return false;
}
long long int fact(long long int val)
{
    long long int te = 1;
    for (long long int i = 1; i <= val; i++)
    {


        te = (te*i);
        te = te;
    }
    return te;
}


bool cmprx(struct road r1, struct road r2) {
	if(r1.len<r2.len)	return true;
	if(r1.len>=r2.len)	return false;
}
bool cmpry(struct road r1, struct road r2) {
	if(r1.len<r2.len)	return true;
	if(r1.len>=r2.len)	return false;
}
int main() {
	int i,j;
	cin>>n;
	for(int i=0; i<=n; i++)	set[i] =i;
	for(i=0; i<n; i++) {
		cin>>retu[i].x>>retu[i].y;
		retu2[i].x = retu[i].x;
		retu2[i].y = retu[i].y;
		retu[i].turn = i+1;
		retu2[i].turn = i+1;
	}
	sort(retu,retu+n,cmp);
	sort(retu2,retu2+n,cmp2);

	for(i=1; i<n; i++) {
		rx[i-1].turn1 = retu[i-1].turn;
		rx[i-1].turn2 = retu[i].turn;
		rx[i-1].len = fabs(retu[i-1].x - retu[i].x);
	}
	for(i=1; i<n; i++) {
		ry[i-1].turn1 = retu2[i-1].turn;
		ry[i-1].turn2 = retu2[i].turn;
		ry[i-1].len = fabs(retu2[i-1].y - retu2[i].y);
	}
	long long int ans = 0;
	sort(rx,rx+n-1,cmprx);
	sort(ry,ry+n-1,cmpry);

	int fc1=0,fc2=0;
	int tt = 0;
	int xx = 100000;
	for(; tt<n-1; ) {
        if (xx<10000000){
		long long int r1 = rx[fc1].len, r2 = ry[fc2].len;
		if(r1<r2) {
			if(findSet(rx[fc1].turn1)!=findSet(rx[fc1].turn2)) {
				ans+=rx[fc1].len;
				unionSet(rx[fc1].turn1,rx[fc1].turn2);
				tt++;
				xx--;
			}
			fc1++;
			xx++;
		} else {
			if(findSet(ry[fc2].turn1)!=findSet(ry[fc2].turn2)) {
				ans+=ry[fc2].len;
				unionSet(ry[fc2].turn1,ry[fc2].turn2);
				tt++;
				xx--;
			}
			fc2++;
			xx++;
		}
        }
	}

	cout<<ans;
	return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
#define ll long long int
const ll M = 1e9+7;
const ll inf = 1e18+5;
using namespace std;
#define debug() for(ll l=0;l<50;l++){}
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
double power(ll x,ll y,ll p){
	ll res = 1;
	x = x % p;
	if(x == 0) return 0;
	while (y > 0){
		if (y & 1) res = (res*x) % p;
		y = y>>1;
		x = (x*x) % p;
		}
	return res;
}

void solve(){
	ll x;
	cin>>x;
	if(x==1) cout<<"0\n";
	else cout<<"1\n";
}

int main(){
	fast;
	ll t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


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

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var L = int.Parse(line[1]);
        var a = new string[n];
        for (int i = 0; i < n; i++) a[i] = Console.ReadLine().Trim();
        var used = new bool[n];
        var ans1 = getAns1(a, n, used);
        var ans = getAns2(a, used, ans1, n);
        Console.WriteLine(ans);
    }
    static bool check(string s)
    {
        var imax = s.Length / 2;
        for (int i = 0; i < imax; i++)
            if (s[i] != s[s.Length - 1 - i]) return false;
        return true;
    }
    static string getAns2(string[] a, bool[] used, List<string> ans1, int n)
    {
        var ans2 = new List<string>();
        for (int i = 0; i < n; i++)
            if (!used[i] && check(a[i])) ans2.Add(a[i]);
        ans2.Sort();
        var ans3 = "";
        for (int i = 0; i < ans1.Count(); i++)
            ans3 += ans1[i];
        var ans4 = getRev(ans3);
        if (ans2.Count() > 0) return ans3 + ans2[0] + ans4;
        else return ans3 + ans4;
    }
    static string getRev(string s)
    {
        var a = s.ToCharArray();
        Array.Reverse(a);
        return new string(a);
    }
    static List<string> getAns1(string[] a, int n, bool[] used)
    {
        var ans1 = new List<string>();
        for (int i = 0; i < n; i++)
            if (!used[i])
            {
                var w = getRev(a[i]);
                for (int j = i + 1; j < n; j++)
                    if (!used[j] && w == a[j])
                    {
                        var t = a[i].CompareTo(w);
                        if (t <= 0) ans1.Add(a[i]);
                        else ans1.Add(w);
                        used[i] = true;
                        used[j] = true;
                        break;
                    }
            }
        ans1.Sort();
        return ans1;
    }
}



Measured memory_bytes: 21092
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;

void main() {
	auto ip = readln.split.to!(int[]), N = ip[0], Y = ip[1];
	foreach(i; 0..N+1) {
		foreach(j; 0..N-i+1) {
			auto k = N - i - j;
			if(10000*i + 5000*j + 1000*k == Y) {
				writefln("%s %s %s", i, j, k);
				return;
			}
		}
	}
	writeln("-1 -1 -1");
}


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

struct Card { char suit, value; };

void bubbleSort(struct Card A[], int N) {
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N - 1; j > i; j--) {
      if (A[j].value < A[j - 1].value) {
        swap(A[j], A[j - 1]);
        flag = 1;
      }
    }
  }
}

void selectionSort(struct Card A[], int N) {
  for (int i = 0; i < N; i++) {
    int minj = i;
    for (int j = i; j < N; j++) {
      if (A[minj].value > A[j].value) minj = j;
    }
    swap(A[i], A[minj]);
  }
}

void print(struct Card A[], int N) {
  for (int i = 0; i < N; i++) {
    cout << A[i].suit << A[i].value;
    if (i != N - 1) cout << " ";
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
  for (int i = 0; i < N; i++) {
    if (C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  Card C1[N], C2[N];
  for (int i = 0; i < N; i++) cin >> C1[i].suit >> C1[i].value;
  for (int i = 0; i < N; i++) C2[i] = C1[i];

  bubbleSort(C1, N);
  selectionSort(C2, N);
  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if (isStable(C1, C2, N)) cout << "Stable";
  else cout << "Not stable";
  cout << endl;

  return 0;
}


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

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static void Main() {
        var s = Console.ReadLine();
        char head = s[0];
        char tail = s.Last();
        Console.WriteLine("{0}{1}{2}", head, s.Length - 2, tail);
    }
}

Measured memory_bytes: 13268
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

/* Euler totiem function, number of coprimes of n in (1,n)
 *  * see https://cp-algorithms.com/algebra/phi-function.html
 *   **/
int phi(int n) {
    int result = n;
    for (int i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

/* We need to find the sum of...
 * number of divisors which is eulers totiem
 * multiplied by that number
 * for all numbers up to x.
 */
void solve() {
    cini(n);

    vi tot(n+1, 1);
    tot[0]=0;
/*
    for(int i=1; i<=n; i++) {
        tot[i]=phi(i);
    }
*/
    for(int i=2; i<=n; i++) 
        for(int j=i; j<=n; j+=i)
            tot[j]++;

    vi dp(n+1);
    for(int i=1; i<=n; i++) 
        dp[i]=dp[i-1]+i*tot[i];

    cout<<dp[n]<<endl;
    
    
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


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


int main() {
  string N;
  cin >> N;
  int size = N.size();
  char P = N.at(size-1);
  if(P=='0'||P=='1'||P=='6'||P=='8'){
    cout << "pon" << endl;
  }
  else if(P=='3'){
    cout << "bon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
  return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <vector>
using namespace std;

vector<int> d[10];

struct mode{
	int n;
	bool has[10];
};

mode dfs[100000];

int main()
{
	int n,m,i,j,a,b,top,tmp,count,ans;
	bool hast[10];
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++) 
	{
		scanf("%d%d",&a,&b);
		if(b!=1) d[a].push_back(b);
		if(a!=1) d[b].push_back(a);
	}
	top=0,dfs[0].n=1,dfs[0].has[1]=1,ans=0;
	while(top>=0)
	{
		tmp = dfs[top].n,count=0;
		//printf("search : %d\n",tmp);
		for(i=1;i<=n;i++) hast[i]=dfs[top].has[i],count+=hast[i];
		top--;
		if(count==n)
		{
			ans++;
			continue;
		}
		for(i=0;i<d[tmp].size();i++)
		{
			if(!(hast[d[tmp][i]]))
			{
				//printf("push : %d\n",d[tmp][i]);
				dfs[++top].n=d[tmp][i];
				for(j=1;j<=n;j++) dfs[top].has[j]=hast[j];
				dfs[top].has[d[tmp][i]] = 1;
				//printf("successed\n");
			}
		}
	}
	printf("%d\n",ans);
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int a,b,c,d;
int main(void){
    cin>>a>>b>>c>>d;
    if(a!=c){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
    
}


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

int main(){
 int n;
 int a[2][12];
 int flg,work,i,j,cnt;
 
 while(1){
	cin>>n;
	if(n==0){break;}
	flg=0;
	for(i=0;i<n;i++){cin>>a[flg][i];}
	cnt=-1;
	
	do{
	 work=0;
	 for(i=0;i<n;i++){
	  a[1-flg][i]=0;
	  for(j=0;j<n;j++){
		 if(a[flg][i]==a[flg][j]){a[1-flg][i]++;}
	  }
	  if(a[flg][i]==a[1-flg][i]){work++;}
	 }
	  
	 flg=1-flg;cnt++;
	}while(work!=n);
	
	cout<<cnt<<endl;
	for(i=0;i<n;i++){
	 if(i){cout<<" ";}
	 cout<<a[flg][i];
	}
	cout<<endl;
 }
 
 return 0;
}

Measured memory_bytes: 1160
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
struct Point{double x,y;};
Point operator +(Point a,Point b){return (Point){a.x+b.x,a.y+b.y};}
Point operator -(Point a,Point b){return (Point){a.x-b.x,a.y-b.y};}
Point operator *(Point a,double b){return (Point){a.x*b,a.y*b};}
double cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
double norm(Point a){return a.x*a.x+a.y*a.y;}
double abs(Point a){return sqrt(norm(a));}
void read(Point &a){a.x=read(),a.y=read();}
void print(Point a){printf("%.10lf %.10lf\n",a.x,a.y);}
double getdistanceLP(Point p0,Point p1,Point p2)
{
	return fabs(cross(p1-p0,p2-p0))/abs(p1-p0);
}
Point getintersection(Point p0,Point p1,Point p2,Point p3)
{
	double x=getdistanceLP(p0,p1,p2),y=getdistanceLP(p0,p1,p3);
	double r=x/(x+y);
	return p2+(p3-p2)*r;
}
int main()
{
	int q=read();while(q--)
	{
		Point p0,p1,p2,p3;
		read(p0),read(p1),read(p2),read(p3);
		print(getintersection(p0,p1,p2,p3));
	}
	return 0;
}



Measured memory_bytes: 3196
N = int(input())
s = input()
sl = [0] * (N + 1)
sr = [0] * (N + 1)
for i in range(N):
    if s[i] == 'W':
        sl[i + 1] = sl[i] + 1
    else:
        sl[i + 1] = sl[i]
for i in range(N , 0, -1):
    if s[i - 1] == 'E':
        sr[i - 1] = sr[i] + 1
    else:
        sr[i - 1] = sr[i]
min_ = N
for i in range(N + 1):
    min_ = min(min_, sl[i] + sr[i])
print(min_)

Measured memory_bytes: 17580
import statistics

n = int(input())
a = []
j = 1
for i in list(map(int, input().split())):
    a.append(i - j)
    j += 1
b = statistics.median((a))
res = 0
for i in range(n):
    res += abs(a[i] - b)

print(int(res))

Measured memory_bytes: 27248
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b, c;
    cin >> a >> b >> c;
    cout << (a == b && b == c ? "Yes" : "No") << endl;
}

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

int main()
{
  i64 n;
  cin >> n;
  vector<i64> d(n);
  for (i64 i = 0; i < n; i++)
    cin >> d[i];
  i64 ans = 0;
  for (i64 i = 0; i < n; i++)
    for (i64 j = i + 1; j < n; j++)
      ans += d[i] * d[j];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
//
#define int long long
#define ALL(x) (x).begin(), (x).end()
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))
// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((a) >> (b)) & 1
#define bitcount(a) __builtin_popcountll((a))
//
typedef long long lint;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;
//
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
//
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N, W;
int v[110], w[110];
vec wary[5];

signed main() {
  cin >> N >> W;
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
    int temp = w[i] - w[0];
    wary[temp].push_back(v[i]);
  }

  for (int i = 0; i < 4; i++) {
    sort(begin(wary[i]), end(wary[i]));
    wary[i].push_back(0);
    reverse(begin(wary[i]), end(wary[i]));
    for (int j = 1; j < wary[i].size(); j++) {
      wary[i][j] += wary[i][j - 1];
    }
  }

  int ans = 0;
  for (int i = 0; i < wary[0].size(); i++) {
    for (int j = 0; j < wary[1].size(); j++) {
      for (int k = 0; k < wary[2].size(); k++) {
        for (int l = 0; l < wary[3].size(); l++) {
          if ((i + j + k + l) * w[0] + j + 2 * k + 3 * l > W) {
            continue;
          }

          int sum = wary[0][i] + wary[1][j] + wary[2][k] + wary[3][l];
          chmax(ans, sum);
        }
      }
    }
  }

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


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


int main(){
    int n,A[110],minj,cnt=0;
    cin>>n;
    for(int i=0;i<n;i++)cin>>A[i];
    bool ok;
    for(int i=0;i<n;i++){
        minj=i;
        ok=0;
        for(int j=i+1;j<n;j++){
            if(A[minj]>A[j]){
                minj=j;
                ok=1;
            }
        }
        swap(A[minj],A[i]);
        if(ok)cnt++;
    }
    for(int i=0;i<n;i++){
        cout<<A[i];
        if(i!=n-1)cout<<" ";
    }
    cout<<endl<<cnt<<endl;

    return 0;
}






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

template<typename T = int, class F = std::plus<T>, class F_INV = std::minus<T>, T E = 0>
struct BinaryIndexedTree {
    const F op = F(); const F_INV op_inv = F_INV();
    int n; vector<T> dat;
    void build(const vector<T>& v) {
        n = v.size(); dat.assign(n, E); for (int i = 0; i < n; ++i) add(i, v[i]);
    }
    void add(int k, T v) { for (int i = k; i < n; i |= i + 1) dat[i] = op(dat[i], v); }
    T query(int a, int b) const {
        T ret = E; if (a == b) return ret;
        for (int i = b - 1; i >= 0; i = (i & (i + 1)) - 1) ret = op(ret, dat[i]);
        return op_inv(ret, query(0, a));
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> com(q), x(q), y(q);
    for (int i = 0; i < q; ++i) cin >> com[i] >> x[i] >> y[i];

    BinaryIndexedTree<int> bit;
    bit.build(vector<int>(n, 0));

    for (int i = 0; i < q; ++i) {
        if (com[i] == 0) {
            bit.add(x[i] - 1, y[i]);
        }
        else {
            cout << bit.query(x[i] - 1, y[i]) << endl;
        }
    }
}



Measured memory_bytes: 4636
sx, sy, tx, ty = list(map(int, input().split()))
s = []
s.append('R'*(tx-sx)+'U'*(ty-sy))
s.append('L'*(tx-sx)+'D'*(ty-sy))
s.append('D'+'R'*(tx-sx+1)+'U'*(ty-sy+1)+'L')
s.append('U'+'L'*(tx-sx+1)+'D'*(ty-sy+1)+'R')
ans = ''.join(s)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  cin>>n;
  vector<string>ch(n);
  for(int i=0;i<n;i++)
    cin>>ch[i];
  bool flag=false;
  int m;cin>>m;
  for(int i=0;i<m;i++){
    string str;cin>>str;
    int j;
    for(j=0;j<n;j++){
      if(ch[j]==str){
	if(flag){
	  cout<<"Closed by"<<" "<<str<<endl;
	  flag=false;
	  break;
	}else{
	  cout<<"Opened by"<<" "<<str<<endl;
	  flag=true;
	  break;
	}
      }
    }
    if(j==n)
      cout<<"Unknown"<<" "<<str<<endl;
  }
  return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    double a,b,h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  int n;cin>>n;
  double J = 0.0;
  double B = 0.0;
  for(int i = 0; n > i; i++){
    double a;string b;cin>>a>>b;
    if(b=="JPY"){
      J += a;
    }else{
      B += a;
    }
  }
  cout << fixed << setprecision(10) << J+380000.0*B << endl;
    
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! flush {
    () => {
        std::io::stdout().flush().unwrap();
    };
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let xs: Vec<i64> = sc.vec(n);
    let mut a = xs[0];
    for i in 1..n {
        a = a / gcd(a, xs[i]) * xs[i];
    }
    put!(a);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.14159265358979323846
using namespace std;
//
int SX,SY,TX,TY;
int main(){
  cin>>SX>>SY>>TX>>TY;
  FOR(i,0,TX-SX){
    cout<<"R";
  }
  FOR(i,0,TY-SY+1){
    cout<<"U";
  }
  FOR(i,0,TX-SX+1){
    cout<<"L";
  }
  FOR(i,0,TY-SY+1){
    cout<<"D";
  }
  cout<<"R";
  cout<<"D";
  FOR(i,0,TX-SX+1){
    cout<<"R";
  }
  FOR(i,0,TY-SY+1){
    cout<<"U";
  }
  FOR(i,0,TX-SX+1){
    cout<<"L";
  }
  FOR(i,0,TY-SY){
    cout<<"D";
  }
  cout<<endl;
  return 0;
}


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

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

typedef long long ll;
typedef unsigned long long ull;

const int mod = 1000000007;
const int inf = 1000000000;
const ll infll = (ll)inf * (ll)inf;

class TaskB {
public:
    void solve(istream& in, ostream& out) {
        int k;
        in >> k;
        vector<ll> a(k);
        for (int i = 0; i < k; i++) {
            in >> a[i];
        }
        ll minres = 2;
        ll maxres = 2;
        for (int i = k - 1; i >= 0; i--) {
            ll new_minres = ((minres - 1) / a[i] + 1) * a[i];
            if (new_minres > maxres) {
                out << -1;
                return;
            }
            minres = new_minres;
            maxres = (maxres / a[i]) * a[i] + a[i] - 1;
        }
        out << minres << " " << maxres;
    }
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    TaskB solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1024
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let r: usize = iterator.next().unwrap().parse().unwrap();

    return format!("{}", r * r);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	int h, w;
	while(scanf("%d%d", &h, &w), h){
		char field[128][128];
		rep(i, h)
			scanf("%s", field[i]);
		
		int distribution = 0;
		bool visited[128][128] = {false};
		rep(i, h) rep(j, w){
			if(!visited[i][j]){
				++distribution;
				char now = field[i][j];
				
				stack<pii> S;
				S.push(pii(i, j));
				while(!S.empty()){
					pii pos = S.top();
					S.pop();
					if(visited[pos.first][pos.second])
						continue;
					visited[pos.first][pos.second] = true;
					
					const int dy[] = {0, -1, 1, 0};
					const int dx[] = {-1, 0, 0, 1};
					rep(i, 4){
						int py = pos.first + dy[i];
						int px = pos.second + dx[i];
						if(py<0 || h<=py || px<0 || w<=px)
							continue;
						
						if(field[py][px] == now)
							S.push(pii(py, px));
					}
				}
			}
		}
		printf("%d\n", distribution);
	}

	return 0;
}

Measured memory_bytes: 0
s=input()

t=int(s[0:2])
u=int(s[2:4])

if t==0:
    if 1<=u and u<=12:
        print("YYMM")
    else:
        print("NA")

elif 1<=t and t<=12:
    if u==0 or 12<u:
        print("MMYY")
    else:
        print("AMBIGUOUS")

else:
    if u==0 or 12<u:
        print("NA")
    else:
        print("YYMM")


Measured memory_bytes: 3060
A = int(input())
list1 = []
for i in range(A):
  a = input()
  list1.append(a)
b =list1.count('AC')
c =list1.count('TLE')
d =list1.count('RE')
e =list1.count('WA')
print('AC x '+ str(b))
print('WA x '+ str(e))
print('TLE x '+str(c))
print('RE x '+str(d))

Measured memory_bytes: 16248
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val re = """([1-9]{1})\s([1-9]{1})""".r
    StdIn.readLine match {
      case re(a, b) => println(a.toInt * b.toInt)
      case _ => println("-1")
    }
  }
}


Measured memory_bytes: 27208
#include <bits/stdc++.h>//期待値dp
using namespace std;

double dp[310][310][310];
int a[310];
int n;

double rec(int x,int y,int z){
    if(dp[x][y][z] >= 0) return dp[x][y][z];// !=-1にしたら動作しなかった
    if(x==0 && y==0 && z==0) return 0.0;

    dp[x][y][z] = 0.0;
    if(x>0) dp[x][y][z] += rec(x-1,y,z) * x;
    if(y>0) dp[x][y][z] += rec(x+1,y-1,z) * y;
    if(z>0) dp[x][y][z] += rec(x,y+1,z-1) * z;
    dp[x][y][z] += n;
    dp[x][y][z] /= (x+y+z);

    return dp[x][y][z];
}

int main(){
    cin >> n;
    int one=0, two=0, three=0;
    for(int i=0;i<n;++i){
        int b; cin >> b;
        if(b==1) one++;
        else if(b==2) two++;
        else three++;
    }
    memset(dp,-1,sizeof(dp));

    cout << fixed << setprecision(10) << rec(one,two,three) << endl;
    return 0;
}


Measured memory_bytes: 233088
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	int n, k;
	cin >> n >> k;
	vector<pair<int, int> > p1, p2;

	for (int i = 1; i * i <= n; ++i) {
		if (i * i == n) {
			p1.push_back({i,1});
			break;
		}
		p1.push_back({i, 1});
		p1.push_back({n / i, 1});
	}

	sort(p1.begin(), p1.end());
	p1[0].second = 1;

	for (int i = 1; i < (int) p1.size(); ++i) {
		p1[i].second = p1[i].first - p1[i - 1].first;
	}

	for (int ii = 1; ii < k; ++ii) {
		p2 = p1;
		int len = (int) p2.size() - 1;
		long long curr = 0;
		for (int i = len; i >= 0; --i) {
			curr += p1[len - i].second;
			curr %= MOD;

			if (i != 0) {
				p2[i].second = (curr * (p2[i].first - p2[i - 1].first)) % MOD;
			}
			else {
				p2[i].second = curr;	
			}
		}
		p1 = p2;
	}

	long long ans = 0;
	for (int i = 0; i < (int) p1.size(); ++i) {
		ans += p1[i].second;
		ans %= MOD;
	}

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

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    map<char,int>mp;
    
    string n;
    cin>>n;
    
    for(int i=0;i<n.size();i++)
    	mp[n[i]]++;
    
    bool flag =false;
    
    for(auto x:mp)
    {
    	if(x.second%2==0)
    		flag=true;
    	else if(x.second%2!=0)
    	{	flag=false;
    		break;}
    }
    if(flag==true)
    	cout<<"Yes";
    else
    	cout<<"No";
    
    
    
    
	return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int top1 = 0,top2 = 0,top3 = 0;

		for (int i = 1;i <= 10;i++) {
			int hill = scanner.nextInt();

			if (hill >= top1) {
				top3 = top2;
				top2 = top1;
				top1 = hill;
			} else if (hill >= top2) {
				top3 = top2;
				top2 = hill;
			} else if (hill >= top3) {
				top3 = hill;
			}
		}

		System.out.println(top1);
		System.out.println(top2);
		System.out.println(top3);
	}
}

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

int main()
{
	int m, f, r;
	int sum;
	while (1) {
		scanf("%d %d %d", &m, &f, &r);

		if (m == -1 && f == -1 && r == -1) {
			break;
		}
		
		if (m == -1 || f == -1) {
			cout << "F" << endl;
		}
		else {
			sum = m + f;
			if (sum >= 80) {
				cout << "A" << endl;
			}
			else if (sum >= 65) {
				cout << "B" << endl;
			}
			else if (sum >= 50) {
				cout << "C" << endl;
			}
			else if (sum >= 30) {
				if (r >= 50) {
					cout << "C" << endl;
				}
				else {
					cout << "D" << endl;
				}
			}
			else {
				cout << "F" << endl;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 3204
#!/usr/bin/env python3

N, x = list(map(int, input().split()))
a_list = list(map(int, input().split()))
a_list = sorted(a_list)
# xよりaが大きい子供にはどう頑張っても配りようがないので最初から除外する
a_list = [a for a in a_list if a <= x]
count = 0
d_list = [0] * N

# 少ない子から順に配っていく
for i, a in enumerate(a_list):
    if i == N - 1:
        # 最後の一人だったら全部押し付ける
        d_list[i] = x
        break

    if x - a >= 0:
        d_list[i] = a
        x -= a
    else:
        d_list[i] = x
        break

ans = len([a for a, d in zip(a_list, d_list) if a == d])

print(ans)


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

int main(void){
    int n;
    cin >> n;
    
    int x[100], y[100], h[100];
    int not_zero;
    int i;
    for(i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] != 0){
            not_zero = i;
        }
    }
    
    bool flag;
    int cx, cy, ans_h;
    for(cx = 0; cx <= 100; cx++){
        for(cy = 0; cy <= 100; cy++){
            ans_h = h[not_zero] + abs(x[not_zero] - cx) + abs(y[not_zero] - cy);
            
            flag = true;
            for(i = 0; i < n; i++){
                if(h[i] != max(ans_h - (abs(x[i] - cx) + abs(y[i] - cy)), 0)){
                    flag = false;
                }
            }
            if(flag == true){
                printf("%d %d %d\n", cx, cy, ans_h);
                return 0;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<vector<int>> children;
  vector<int> hukasa;
  vector<int> kazu;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    kazu = vector<int>(n,1);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
      kazu.at(rx) += kazu.at(ry);
    }
    else{
      par.at(rx) = ry;
      kazu.at(ry) += kazu.at(rx);
    }
  }
  void newkazu(){
    int n = kazu.size();
    for(int i=0;i<n;i++){
      kazu.at(i) = kazu.at(root(i));
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
void hukasa(vector<vector<int>> s,vector<vector<int>> table,int &ans,pii frm,int n,int m){
  int x,y;
  tie(x,y) = frm;
  set<pii> se;
  if(x-1 >= 0)se.insert(pii(x-1,y));
  if(x+1 < n)se.insert(pii(x+1,y));
  if(y-1 >= 0)se.insert(pii(x,y-1));
  if(y+1 < m)se.insert(pii(x,y+1));
  for(auto t:se){
    int tx,ty;
    tie(tx,ty) = t;
    if(s.at(tx).at(ty) && table.at(tx).at(ty) == -1){
      table.at(tx).at(ty) = table.at(x).at(y) + 1;
      ans = max(ans,table.at(tx).at(ty));
      hukasa(s,table,ans,t,n,m);
      table.at(tx).at(ty) = -1;
    }
  }
}
void daiku(int frm,vector<vector<pii>> g,vector<int> &cost,int n){
  priority_queue<pii,vector<pii>,greater<pii>> q;
  q.push(pii(cost.at(frm),frm));
  vector<bool> kakutei(n,false);
  while(!q.empty()){
    pii now = q.top();
    q.pop();
    int n1,n2;
    tie(n1,n2) = now;
    if(kakutei.at(n2))continue;
    kakutei.at(n2) = true;
    for(auto t:g.at(n2)){
      int tx,ty;
      tie(tx,ty) = t;
      if(cost.at(tx) > n1 + ty){
        cost.at(tx) = n1 + ty;
        q.push(pii(cost.at(tx),tx));
      }
    }
  }
}

int main(){
  long long a,b,n;
  cin >> a >> b >> n;
  if(b <= n){
    cout << a * (b-1) / b << endl;
  }
  else cout << a * n / b << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
struct edge {ll to,cost;};
typedef pair<ll,ll> P;
vector<vector<edge>> G(100010);
vector<ll> d;

void dijkstra(ll s){
    // 小さい順に取り出す
    priority_queue<P,vector<P>,greater<P>> pq;
    fill(d.begin(),d.end(),INF);
    d[s] = 0;
    pq.push(P(0,s));
    while(!pq.empty()){
        P p = pq.top();
        pq.pop();
        ll v = p.second;
        if(d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); ++i) {
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                pq.push(P(d[e.to],e.to));
            }
        }
    }
}

int main() {
    int n;
    cin >> n;
    d.resize(100010);
    for (int i = 0; i < n-1; ++i) {
        int a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    int q,k;
    cin >> q >> k;
    k--;
    dijkstra(k);
    for (int i = 0; i < q; ++i) {
        int x,y;
        cin >> x >> y;
        x--,y--;
        ll ans;
        ans = (d[x]+d[y]);
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
	int x, y;
	
	cin >> x >> y;
	
	if(x==2 || y==2) cout << "No";
	else {
		int a[13], b[13];
		for(int i = 0;i<13;i++){
			a[i] =0;
			b[i] =0;
        }

		
		//冗長すぎるが...
		a[1]=1; a[3]=1; a[5]=1; a[7]=1; a[8]=1;a[10]=1;a[12]=1;
		b[4]=1;b[6]=1;b[9]=1;b[11]=1;
		
		if(a[x]==1 && a[y]==1) cout << "Yes";
		else if(b[x]==1 && b[y]==1) cout << "Yes";
		else cout << "No";
	}
	
	cout << endl;
	
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n;
	cin >> n;

	int c[9][9];

	for(int i = 0; i < 9; ++i)
	for(int j = 0; j < 9; ++j)
	c[i][j] = 0;

	for(int i = 1; i <= n; ++i)
	{
		if (i % 10 == 0)
		{
			continue;
		}
		string s = to_string(i);
		c[s.front() - '0' - 1][s.back() - '0' - 1]++;
	}

	int ans = 0;
	for(int i = 0; i < 9; ++i)
	for(int j = 0; j < 9; ++j)
	ans += c[i][j] * c[j][i];

	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
/*struct comp
{
	bool operator()(pi a,pi b) const
	{
		int m1=min(a.f,a.s),m2=min(b.f,b.s);
		return m1<m2;
	}
};*/
 
int main() 
{
	// && has higher precedence than ||
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N;
	cin>>N;
	vi v(N);
	F0R(x,N)
		cin>>v[x];
	sort(v.rbegin(),v.rend());
	ll ans=v[0];
	int c=1,p=1;
	while(c!=N-1)
	{
		ans+=v[p];
		c++;
		if(c==N-1)break;
		ans+=v[p];
		c++;
		p++;
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 4036