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

typedef long long int lli;

bool seive[seive_len];
lli primeSeive[seive_len];

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

lli lcm(lli a, lli b) {
  lli gcd_ = gcd(a, b);
  lli lcm_ = (a*b)/gcd_;
  return lcm_;
}

lli fastPower(lli a, lli b) {
  lli res=1;
  while(b > 0) {
    if(b&1)
      res *= a;
    a *= a;
    b >>= 1;
  }
  return res;
}

lli fastPowerMODp(lli a, lli b, lli MOD) {
  a %= MOD;
  lli res = 1;
  while(b) {
    if(b%2 == 1)
      res = (res*a)%MOD;
    a = (a*a)%MOD;
    b >>= 1;
  }
  return res%MOD;
}

void multiply(lli a[][2], lli b[][2], lli MOD) {
  lli res[2][2];
  memset(res, 0, sizeof(res));
  for(lli i=0;i<2;i++) {
    for(lli j=0;j<2;j++) {
      for(lli k=0;k<2;k++) {
        res[i][j] += a[i][k]*b[k][j]%MOD;
      }
    }
  }
  for(lli i=0;i<2;i++)
    for(lli j=0;j<2;j++)
      a[i][j] = res[i][j];
}

void matrixExpo(lli a[][2], lli n, lli MOD) {
  if(n == 0 || n == 1)
    return;
  lli b[][2] = {{1,1}, {1,0}};
  matrixExpo(a, n/2, MOD);
  multiply(a, a, MOD);
  if(n%2)
    multiply(a, b, MOD);
}

void makeSeive() {
  for(lli i=2;i*i<=seive_len;i++) {
    if(seive[i]) {
      for(lli j=i*i;j<=seive_len;j+=i)
        seive[j] = false;
    }
  }
}

void makePrimeSeive() {
  for(lli i=1;i<seive_len;i++)
    primeSeive[i] = i;
  for(lli i=4;i<seive_len;i+=2)
    primeSeive[i] = 2;
  for(lli i=3;i*i<seive_len;i++) {
    if(primeSeive[i] == i) {
      for(lli j=i*i;j<seive_len;j+=i) {
        if(primeSeive[j] == j)
          primeSeive[j] = i;
      }
    }
  }
}

bool isPrime(lli n) {
  for(lli i=2;i<=sqrt(n);i++) {
    if(n%i == 0)
      return false;
  }
  return true;
}

lli mod(lli x, lli MOD) {
  x %= MOD;
  if(x<0)
    x += MOD;
  return x%MOD;
}

lli inverse(lli x, lli MOD) {
  x = mod(x, MOD);
  if(x == 1)
    return x;
  return mod((-MOD/x)*inverse(MOD%x, MOD)%MOD, MOD);
}

lli NcR(lli n, lli r, vector<lli> fact, vector<lli> ifact, lli MOD) { 
  lli ret = (ifact[n - r]*ifact[r])%MOD;
  ret = (ret*fact[n])%MOD;
  return ret;
}

void getInput(vector<lli>& a, lli n) {
  lli x;
  for(lli i=0;i<n;i++) {
    cin >> x;
    a.push_back(x);
  }
}

void testCase() {
  lli i, a, b, c ,d;
  cin >> a >> b >> c >> d;
  lli res = max({(a*c), (a*d), (c*b), (d*b)});
  cout << res;

}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
	lli t=1;
	// cin >> t;
  // makePrimeSeive();
  // FILE* fp;
  // fp = fopen("out.txt", "w");
	for(lli i=1;i<=t;i++) {
    // fprintf(fp, "Case #%d:\n", i);
    // cout << "Case #" << i << ":" << ' ';
		testCase();
    cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 3708
#include <stdio.h>

int main(){
    int a, b, c, d, e, k, ab, ac, ad, ae, bc, bd, be, cd, ce, de;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &d);
    scanf("%d", &e);
    scanf("%d", &k);
    
    ab = b - a;
    ac = c - a;
    ad = d - a;
    ae = e - a;
    bc = c - b;
    bd = d - b;
    be = e - b;
    cd = d - c;
    ce = e - c;
    de = e - d;

    if(ab > k || ac > k || ad > k || ae > k || bc > k || bd > k || be > k || cd > k || ce > k || de > k){
        printf(":(\n");
    } else {
        printf("Yay!\n");
    }
    
    return 0;
}

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

#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll n;
v1 a;
graph g;
v1 lis;
v1 ans;

ll dfs(ll from, ll to, v1& lis){
    ll x = lower_bound(lis.begin(),lis.end(),a[to])-lis.begin();
    ll prev = lis[x];
    lis[x] = a[to];
    ll ret = lower_bound(lis.begin(),lis.end(),INF)-lis.begin();
    ans[to] = ret;
    for(auto p : g[to]){
        if(p.first == from) continue;
        chmax(ret, dfs(to, p.first, lis));
    }
    lis[x] = prev;
    return ret;

}

int main(){
    cin >> n;
    a = v1(n+1);
    for(ll i = 1;i <= n;i++){
        cin >> a[i];
    }
    for(ll i = 1;i < n;i++){
        ll u,v;
        cin >> u >> v;
        g[u][v] = g[v][u] = 0;
    }
    lis = v1(n+1, INF);
    ans = v1(n+1);
    dfs(0, 1, lis);
    for(ll i = 1;i <= n;i++){
        cout << ans[i] << endl;
    }

}


Measured memory_bytes: 58252
//解説あり
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int k, t;
int mx = -1;

int main(void) {
  cin >> k >> t;
  rep(i, 0, t) {
    int a;
    scanf("%d", &a);
    mx = max(mx, a);
  }
  
  cout << max(mx-1-(k-mx), 0) << endl;
  
  
  
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,s,o;
void rec(int d,int k,int x){
  if(d>n) return;
  else if(d==n){
    if(x==s) o++;
  }else{
    for(int i=k+1;i<=9;i++){
      rec(d+1,i,x+i);
    }
  }
}
int main(){
  cin >> n >> s;
  while(n!=0){
    o=0;
    rec(0,-1,0);
    cout << o << endl;
    cin >> n >> s;
  }
  return 0;
}



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

#define ll long long

signed main()
{
  int x,a,b;
  cin >> x >> a >> b;
  if(a>=b){cout << "delicious";}
  else if((b-a)<=x){cout << "safe";}
  else{cout << "dangerous";} 
}

Measured memory_bytes: 3596
function main(input) {
  input = input.trim().split("\n");
  const n = Number(input[0]);
  const ps = input[1].split(" ").map(a => Number(a));
  const indices = [];
  for(let i = 0; i < n; i++) {
    const p = ps[i];
    if (i+1 !== p) indices.push(i);
  }
  let result = "NO";
  if (indices.length === 0 || indices.length === 2) result = "YES";
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	static int[] MASK = { 1, 2, 4 };

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int M = Integer.parseInt(in.readLine());
		int result = (24- M) + 24;
		System.out.println(result);
	}
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;
int n, dig;
string str;

int st, en;

int F(int pos, int suru, int choto, int s, int f){
  if (pos >= dig){
    if (s == st && f == en){
      return 1;
    }
    return 0;
  }
  int sum = 0;
  if (choto){
    for (int i = 0; i < 10; i++){
      sum += F(pos + 1, suru | (i != 0), choto, (s == 0) ? i : s, (pos == dig - 1) ? i : 0);
    }
  } else {
    int d = str[pos] - '0';
    for (int i = 0; i <= d; i++){
      sum += F(pos + 1, suru | (i != 0), i < d, (s == 0) ? i : s, (pos == dig - 1) ? i : 0);
    }
  }
  return sum;
}

int main(){
  FASTER;
  //int n;
  cin >> n;
  str = to_string(n);
  string fw = str;
  string rev = str;
  reverse(rev.begin(), rev.end());
  dig = str.size();
  ll ans = 0;
  for (int f = 1; f < 10; f++){
    for (int l = 1; l < 10; l++){
      st = f;
      en = l;
      str = fw;
      int a = F(0, 0, 0, 0, 0);
      st = l;
      en = f;
      //str = rev;
      int b = F(0, 0, 0, 0, 0);
      ans += (a * b);
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    while(sc.hasNextInt()){
      int pasta = Integer.MAX_VALUE;
      int juice = Integer.MAX_VALUE;

      for(int i = 0; i < 3; i++){
        pasta = Math.min(pasta, sc.nextInt());
      }
      for(int i = 0; i < 2; i++){
        juice = Math.min(juice, sc.nextInt());
      }

      System.out.println(pasta + juice - 50);
    }
  }
}

Measured memory_bytes: 17364
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define debug(var) do{cout << #var << " : "; print(var); } while(0)
using namespace std;
typedef long long ll;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }
const ll INF = 1e18;
const int MOD = 1e9+7;

ll dp[110][101000];
int weight[1010];
int value[1010];

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

	int N, W; cin >> N >> W;
	rep(i, N) cin >> weight[i] >> value[i];

	// dp[i][sum_value]:= i番目までの品物を使ってvalueを得るための最小重量
	// dp[i+1][sum_value] = min(dp[i][sum_value-v]+w, dp[i][sum_value])

	rep(i, 110) rep(j, 101000) dp[i][j] = INF;
	dp[0][0] = 0;

	rep(i, N) rep(sum_v, 101000) {
		int w = weight[i];
		int v = value[i];
		// 選ばない
		dp[i+1][sum_v] = min(dp[i][sum_v], dp[i+1][sum_v]);
		// 選ぶ
		if (sum_v>=v) dp[i+1][sum_v] = min(dp[i][sum_v-v]+w, dp[i][sum_v]);
	}

	int ans = 0;
	rep(j, 101000) if (dp[N][j]<=W) ans = max(ans, j);

	cout << ans << endl;
}

Measured memory_bytes: 87040
#include<iostream>
#include<vector>
#include<string>
#include<map>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

vector<int> change(int N, const vector<int>& A) {
    vector<int> res(N, 0);
    rep(i, 0, N) {
        ++res[max(0, i - A[i])];
        if (i + A[i] + 1 < N) {
            --res[i + A[i] + 1];
        }
    }
    rep(i, 1, N) {
        res[i] += res[i - 1];
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    rep(i, 0, K) {
        vector<int> B = change(N, A);
        if (A == B) {
            break;
        }
        swap(A, B);
    }
    rep(i, 0, N) {
        cout << A[i] << " \n"[i + 1 == N];
    }
    return 0;
}

Measured memory_bytes: 4764
#include<bits/stdc++.h> 
#include<random> 
#define int long long 
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back 
#define mod 1000000007 
using namespace std; 
void fastio() 
{ 
    #ifndef ONLINE_JUDGE 
    freopen("INPUT.txt","r",stdin); 
    freopen("OUTPUT.txt","w",stdout); 
    #endif 
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL) ; 
    cout.tie(NULL); 
}

signed main() 
{ 
    fastio(); 
    int t=1;
  //  cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
       n--;
      int sum=((n+1)*n)/2;
       cout<<sum<<'\n';
       
    }
}


Measured memory_bytes: 3700
def main():
    n = int(input())
    nums = input()
    print(nums)
    nums = nums.split(' ')
    nums = [int(i) for i in nums]
    insertion_sort(n, nums)


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


if __name__ == "__main__":
    main()



Measured memory_bytes: 5604
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);	
		int n = stdin.nextInt();
		if(n/10%9==0||n%10%9==0&&n%10!=0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 23636
import java.io.*;
import java.util.*;

public class Main {
	static final StdIn in = new StdIn();
	static final PrintWriter out = new PrintWriter(System.out);
	
	public static void main(String[] args) {
		int n=in.nextInt(), ans=696969;
		for(int a=1; a<n; ++a) {
			int a2=a, b=n-a, ca=0;
			while(a2>0) {
				ca+=a2%10;
				a2/=10;
			}
			while(b>0) {
				ca+=b%10;
				b/=10;
			}
			ans=Math.min(ca, ans);
		}
		out.println(ans);
		out.close();
	}
	
	static class StdIn {
    	final private int BUFFER_SIZE = 1 << 16;
    	private DataInputStream din;
    	private byte[] buffer;
    	private int bufferPointer, bytesRead;
    	public StdIn() {
    		din = new DataInputStream(System.in);
    		buffer = new byte[BUFFER_SIZE];
    		bufferPointer = bytesRead = 0;
    	}
    	public StdIn(InputStream in) {
    		try{
    			din = new DataInputStream(in);
    		} catch(Exception e) {
    			throw new RuntimeException();
    		}
    		buffer = new byte[BUFFER_SIZE];
    		bufferPointer = bytesRead = 0;
    	}
    	public int nextInt() {
    		int ret = 0;
    		byte c = read();
    		while (c <= ' ')
    			c = read();
    		boolean neg = (c == '-');
    		if (neg)
    			c = read();
    		do
    			ret = ret * 10 + c - '0';
    		while ((c = read()) >= '0' && c <= '9');

    		if (neg)
    			return -ret;
    		return ret;
    	}
    	public int[] readIntArray(int n) {
    		int[] ar = new int[n];
    		for(int i=0; i<n; ++i)
    			ar[i]=nextInt();
    		return ar;
    	}
    	private void fillBuffer() throws IOException {
    		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
    		if (bytesRead == -1)
    			buffer[0] = -1;
    	}
    	private byte read() {
    		try{
    			if (bufferPointer == bytesRead)
    				fillBuffer();
    			return buffer[bufferPointer++];
    		} catch(IOException e) {
    			throw new RuntimeException();
    		}
    	}
    	public void close() throws IOException {
    		if (din == null)
    			return;
    		din.close();
    	}
    }
}

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

using namespace std;

#define ll long long
#define ar array



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

	int k,x;
	cin >> k >> x;
	if(k*500 >= x){
		cout << "Yes";
	}else{
		cout<<"No";
	}

	return 0;
}


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

#include <math.h> 

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
    ll X; cin >> X;

    for(int i=X; i <= pow(10, 6);i++){
        if(IsPrime(i)){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

long long int furui(long long int x,long long int y){
  
  if(x==0||y==0)
    return x+y;
  else if(x<y)
    return furui(x,y%x);
  else
    return furui(x%y,y);
}

int main(){
  int n,i;
  long long int t[100],a=1;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%lld",&t[i]);
  for(i=0;i<n;i++){
    if(a<t[i])
      a=t[i]/furui(a,t[i])*a;
    else
      a=a/furui(a,t[i])*t[i];
  }
  printf("%lld\n",a);
}

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

main(){
  int A, B, ans;
  cin >> A >> B;
  if (A > B){
    ans = A + (A - 1);
  }
  else if (B > A){
    ans = B + (B - 1);
  }
  else{
    ans = A + B;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long n,sum=0;
  cin >> n;
 
  for(int i=0;i<=n;i++){
 if( i%3==0 || i%5 ==0 || i%15 == 0)
   sum+=0;
  else sum+=i;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3620
n = int(input())
a = list(map(int,input().split()))
result = 0
for index in range(len(a)):
    diff = 0
    if index != 0:
        diff = a[index-1] - a[index]
        if diff > 0:
            result += diff
            a[index] = a[index-1]

print(result)

Measured memory_bytes: 32032
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if ((a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0)
			System.out.println("Possible");
		else
			System.out.println("Impossible");
		sc.close();
	}
}

Measured memory_bytes: 21844
#include <bits/extc++.h>
using namespace std;
using i64=int64_t;

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

    int d,t,s; cin>>d>>t>>s;
    if(s*t<d) cout<<"No\n";
    else cout<<"Yes\n";
}


Measured memory_bytes: 3648
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt

  val al = List.fill(n)(sc.nextInt)
  val bl = List.fill(n)(sc.nextInt)
  val cl = List.fill(n - 1)(sc.nextInt)


  val res = al.foldLeft((0,-10)){case ( (sum, pre), ii) =>
    val i = ii - 1
    val newsum = sum + bl(i) + (if(i == pre + 1) cl(i - 1) else 0)
    (newsum, i)
  }._1

  println(res)

}


Measured memory_bytes: 25540
#include<iostream>
using namespace std;
int main(){
  int i;
  int a[5];
  int b[5];
  int c[5];
  int b_min=9;
  int idx_min;
  int r=0;
  
  for(i=0;i<5;i++){
    cin >> a[i];
    b[i]=a[i]%10;
    
    if(b[i]==0){
      b[i]=10;
      c[i]=a[i];
    }
    else
    {
      c[i]=(a[i]/10+1)*10;
    }
  }
  
  for(i=0;i<5;i++){
    if(b[i]<b_min){
      b_min=b[i];
      idx_min=i;
    }
  }
  
  for(i=0;i<5;i++){
    r+=c[i];
  }
  
  r=r-c[idx_min]+a[idx_min];
  
  cout << r << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int A[100000];
    for(int i=0;i<n;i++) cin>>A[i];
    
    for(int i=0;i<n;i++) A[i]=A[i]%2;
    
    int num[2];
    for(int i=0;i<n;i++) num[A[i]]++;
    
    if(num[1]%2==1) cout<<"NO";
    else cout<<"YES";
}

Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

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

    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        const ll start = i;
        const ll n = (N / i);
        const ll end = n * i;
        ans += ((start + end) * n) / 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3544
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}
static const ll INF = 1e18;

int main() {
  int n, m; cin >> n >> m;
  vector<pair<ll, ll>> a;
  rep(i, n){
    ll x; cin >> x;
    a.pb(make_pair(x, 1));
  }
  rep(j, m){
    ll x, y; cin >> x >> y;
    a.pb(make_pair(y, x));
  }

  sort(ALL(a));
  reverse(ALL(a));

  ll ans = 0, i = 0;

  while(n){
    ans += a[i].first * lmin(a[i].second, n);
    n -= lmin(a[i].second, n);
    i++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 7432
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin >> n;
  string s;
  cin >> s;
  vector<ll> r, g, b;
  for (int i = 0; i < s.length(); ++i)
  {
    if (s[i] == 'R')
      r.push_back(i);
    else if (s[i] == 'G')
      g.push_back(i);
    else
      b.push_back(i);
  }

  ll ans = 0;
  for (int i = 0; i < r.size(); ++i)
  {
    for (int j = 0; j < g.size(); ++j)
    {
      ll temp;
      if (g[j] > r[i])
      {
        temp = g[j] - r[i];
        ll val = g[j];
        ll count = upper_bound (b.begin(), b.end(), val) - b.begin();
        count = b.size() - count;
        if (binary_search(b.begin(), b.end(), val + temp))
          count--;
        ans += count;
      }
    }
  }
  for (int i = 0; i < r.size(); ++i)
  {
    for (int j = 0; j < b.size(); ++j)
    {
      ll temp;
      if (b[j] > r[i])
      {
        temp = b[j] - r[i];
        ll val = b[j];
        ll count = upper_bound (g.begin(), g.end(), val) - g.begin();
        count = g.size() - count;
        if (binary_search(g.begin(), g.end(), val + temp))
          count--;
        ans += count;
      }
    }
  }
  for (int i = 0; i < g.size(); ++i)
  {
    for (int j = 0; j < r.size(); ++j)
    {
      ll temp;
      if (r[j] > g[i])
      {
        temp = r[j] - g[i];
        ll val = r[j];
        ll count = upper_bound (b.begin(), b.end(), val) - b.begin();
        count = b.size() - count;
        if (binary_search(b.begin(), b.end(), val + temp))
          count--;
        ans += count;
      }
    }
  }
  for (int i = 0; i < g.size(); ++i)
  {
    for (int j = 0; j < b.size(); ++j)
    {
      ll temp;
      if (b[j] > g[i])
      {
        temp = b[j] - g[i];
        ll val = b[j];
        ll count = upper_bound (r.begin(), r.end(), val) - r.begin();
        count = r.size() - count;
        if (binary_search(r.begin(), r.end(), val + temp))
          count--;
        ans += count;
      }
    }
  }
  for (int i = 0; i < b.size(); ++i)
  {
    for (int j = 0; j < g.size(); ++j)
    {
      ll temp;
      if (g[j] > b[i])
      {
        temp = g[j] - b[i];
        ll val = g[j];
        ll count = upper_bound (r.begin(), r.end(), val) - r.begin();
        count = r.size() - count;
        if (binary_search(r.begin(), r.end(), val + temp))
          count--;
        ans += count;
      }
    }
  }
  for (int i = 0; i < b.size(); ++i)
  {
    for (int j = 0; j < r.size(); ++j)
    {
      ll temp;
      if (r[j] > b[i])
      {
        temp = r[j] - b[i];
        ll val = r[j];
        ll count = upper_bound (g.begin(), g.end(), val) - g.begin();
        count = g.size() - count;
        if (binary_search(g.begin(), g.end(), val + temp))
          count--;
        ans += count;
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 3724
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  bool tf = false;
  while (n>0) {
    if (n%10==9) tf = true;
    n /= 10;
  }
  if (tf) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//出力準備（AutoFlushを切る）
		var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
		Console.SetOut(sw);
		//解答
		Solve();
		//出力終了
		Console.Out.Flush();
	}

	//Kが偶数の場合の処理
	static long Ans(long X, long K, long D){
		//とどまらない場合の最善の移動回数
		long m = Math.Abs(X)/D;
		//とどまった方が良い場合
		if(m < 1){
			return Math.Abs(X);
		}
		else if(m >= K){
			return Math.Abs(X) - K*D;
		}
		else{
			//mが偶数の場合
			if(m%2 == 0){
				return Math.Abs(X) - m*D;
			}
			//奇数の場合
			else{
				//さらに一個先へ行く場合
				long forward = m+1<=K ? Math.Abs(X) - (m+1)*D : X;
				//戻る場合
				long back = m-1>=0 ? Math.Abs(X) - (m-1)*D : X;

				//マシな方
				return Math.Min(Math.Abs(forward),Math.Abs(back));
			}
		}
	}

	static void Solve()
	{
		//読み込む
		string[] S = Console.ReadLine().Split(' ');
		long X = long.Parse(S[0]);
		long K = long.Parse(S[1]);
		long D = long.Parse(S[2]);

		long ans = 0;

		//Kが偶数の場合
		if(K % 2 == 0){
			ans = Ans(X,K,D);
		}
		//奇数の場合
		else{
			//一回進むか戻った後は、偶数の場合と同じ
			ans = Math.Min(Ans(X+D,K-1,D), Ans(X-D,K-1,D));
		}

		Console.WriteLine(ans);

	}
}


Measured memory_bytes: 17964
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int ev = 0;
long long dp[10][8];
vector<int> a;

int f(int sm, int ct) {
    long long& ret = dp[sm][ct];
    if (ret < 0) {
        ret = 0;
        for (int i : a) {
            int p = ct > ev ? i : i * 2 % 10 + i * 2 / 10;
            ret += f((sm + p) % 10, ct - 1);
        }
    }
    return ret;
}

int main() {
    int m;
    string s;
    cin >> m >> s >> m;
    a.assign(m, 0);
    for (int& i : a)
        cin >> i;
    int sm = 0, od = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[s.size() - i - 1] == '*') {
            ++(i % 2 ? ev : od);
        } else {
            int p = (s[s.size() - i - 1] - '0') * (i % 2 + 1);
            sm += p % 10 + p / 10;
        }
    }
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < 10; ++i)
        dp[i][0] = !i;
    cout << f(sm % 10, ev + od) << endl;
    return 0;
}

Measured memory_bytes: 3308
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  while (true) {
    int n, x; cin >> n >> x;
    if (n == 0 && x == 0) break;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
          // debug3(i,j,k);
          ll sum = i + j + k;
          if (sum == x) ans++;
          else if (sum > x) break;
        }
      }
    }
    outl(ans);
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}



Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    // 何列目で下に下がるか、のみで決まるので、N通り列挙して最大を取れば良さそう
    int N;
    cin >> N;
    vector<vector<int>> v;
    for (int i = 0; i < 2; ++i)
    {
        vector<int> w(N);
        for (int j = 0; j < N; ++j)
        {
            cin >> w[j];
        }
        v.push_back(w);
    }
    int max_count = 0;
    for (int i = 0; i < N; ++i)
    {
        auto c = accumulate(v[0].begin(), v[0].begin() + i + 1, 0);
        c += accumulate(v[1].begin() + i, v[1].end(), 0);
        max_count = max(c, max_count);
    }
    cout << max_count << endl;
    return 0;
}

Measured memory_bytes: 768
#include<iostream>
    const int oo = 1e9;
    using namespace std;
    void fast(){
    	std::ios_base::sync_with_stdio(0);
    	cin.tie(NULL); cout.tie(NULL);
    }
     
     
    int main(){
    	fast();
    int a ;cin>>a;
    cout<<"ABC"<<a<<endl;
    	return 0;
    }
    //mosta7il_

Measured memory_bytes: 256
function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const N=input[0].split(' ')[0]-0;
  const M=input[0].split(' ')[1]-0;
  console.log(N===M?'Yes':'No');
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  



  


Measured memory_bytes: 29580
/*
????????????????????????????????¨??¢?´¢??????????????§?????????
?????¢?´¢????????¶???????????????????£???????????????????????????????????????????????????????

*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int w, h;
int grid[25][25];
int sx, sy, gx, gy;
int ans;

int dfs(int posx, int posy, int cnt){
  //test
  //cout<<"[ "<<posx<<" , "<<posy<<" ]"<<" cnt: "<<cnt<<endl;
  for(int i=0; i<4; i++){
    if(grid[posy+dy[i]][posx+dx[i]] == 1){
      continue;
    }
    if(posy+dy[i] == -1 || posy+dy[i] == h || posx+dx[i] == w || posx+dx[i] == -1 ){
      continue;
    }

    int nx = posx;
    int ny = posy;
    while(1){
      nx += dx[i];
      ny += dy[i];
      if(nx < 0 || w <=  nx || ny < 0 || h <= ny){
        break;
      }
      else if(grid[ny][nx] == 3){
        return cnt + 1;
      }
      else if(grid[ny][nx] == 1 && cnt < 10){
        grid[ny][nx] = 0;
        int dfscnt = dfs(nx - dx[i], ny - dy[i], cnt+1);
        grid[ny][nx] = 1;
        ans = min(ans, dfscnt);
        break;
      }
    }
  }

  return ans;

}

int main() {
  while(true){

    cin>>w>>h;
    if(w==0 &&  h==0) break;

    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
        cin>>grid[i][j];
        if(grid[i][j] == 2) sx = j, sy = i;
        if(grid[i][j] == 3) gx = j, gy = i;
      }
    }

    int posx = sx, posy = sy;
    ans = 11;

    int tmp = dfs(posx, posy, 0);

    if(tmp > 10) cout<<-1<<endl;
    else cout<<tmp<<endl;

  }


  return 0;
}

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

int main(){
    int r,c;
    cin >> r >> c;
    vector<vector<int>> vec(r, vector<int>(c+1,0));
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            cin >> vec.at(i).at(j);
            vec.at(i).at(c)+=vec.at(i).at(j);
        }
    }

    vector<int> sum(c+1,0);
    for(int i=0; i<c; i++){
        for(int j=0; j<r; j++){
            sum.at(i)+=vec.at(j).at(i);
        }
        sum.at(c)+=sum.at(i);  
    }

    for(int i=0; i<r; i++){
        for(int j=0; j<=c; j++){
            cout << vec.at(i).at(j);
            if (j==c) {cout << endl;}
            else {cout << " ";}
        }
    }
    for (int i=0; i<=c; i++){
        cout << sum.at(i);
        if (i==c) {cout << endl;}
        else {cout << " ";}
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  int cnt=0;
  for(int i=0;i<N;i++){
    cin >> p.at(i);
    if(p.at(i)!=(i+1)){
      cnt = cnt + 1;
    }
  }
  
  if(cnt == 0 || cnt == 2){
    cout <<"YES"<< endl;
  } else{
    cout <<"NO"<< endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin>>n;
  vector<int>dp(3);
  
 
  for(int day = 0;day < n;day++){
  	vector<int>new_dp(3,0);
  	 vector<int>c(3);
    cin>>c[0]>>c[1]>>c[2];
    for(int i = 0;i<3;i++){
      for(int j = 0;j<3;j++){
        if(i!=j){
          new_dp[j]=max(new_dp[j],dp[i]+c[j]);
        }
      }
     
    }
     dp = new_dp;
  }
    cout<<max(dp[0],max(dp[1],dp[2]));
    return 0;
  }


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
    int N;
    string S;
    int x = 0;
    int ans = 0;
    cin >> N >> S;
    for(int i=0;i<N;i++){
        if(S.at(i) == 'I'){
            x++; 
            ans = max(ans,x);
        }
        if(S.at(i) == 'D'){
            x--;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
def main():
    (N, H) = map(int, input().split(' '))

    max_atks_swing = 0
    atks_throw = []
    for i in range(N):
        s, t = map(lambda x: int(x), input().split(' '))
        if max_atks_swing < s:
            max_atks_swing = s
        atks_throw.append(t)
    
    filtered_atks_throw = sorted(
                            filter(lambda x: max_atks_swing < x, atks_throw)
                            ,reverse=True
                          )

    n = 0
    remain = H
    for atk in filtered_atks_throw:
        n += 1
        remain -= atk
        
        if remain <= 0:
            return n

    q, mod = divmod(remain,max_atks_swing)

    return n + q + (1 if mod > 0 else 0)


print(main())


Measured memory_bytes: 8280
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define cls(s,v) memset(s,v,sizeof(s))
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 0x3f3f3f3f;
inline int read(){
	int out = 0,flag = 1; char c = getchar();
	while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
	while (c >= 48 && c <= 57){out = (out << 1) + (out << 3) + c - 48; c = getchar();}
	return flag ? out : -out;
}
int main(){
	int n = read(),ans = 0;
	for (int i = 1; i <= n; i++){
		int a = read();
		if (i & 1) ans += (a & 1);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3760
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	ll x = inf;
	ll y = -inf;

	for (ll i = 0; i < n; i++)
	{
		ll a;
		cin >> a;

		x = min(x, a);
		y = max(y, a);
	}

	println(abs(y - x));
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int k, x;

	scanf("%d %d", &k, &x);

	//総額がX円以上か判定する
	if (500 * k >= x) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define ten(n) ((int)1e##n)
#define fst first
#define snd second
using ll=long long;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pil=pair<int,ll>;using pli=pair<ll,int>;
using vs=vector<string>;using vvs=vector<vs>;using vvvs=vector<vvs>;
using vb=vector<bool>;using vvb=vector<vb>;using vvvb=vector<vvb>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<class T> bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
ll ri(){ll l;cin>>l;return l;} string rs(){string s;cin>>s;return s;}
template<class T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<'('<<p.fst<<", "<<p.snd<<')';}
template<class T>ostream&operator<<(ostream&o,const vector<T>&t){o<<"{";rep(i,sz(t))o<<t[i]<<",";o<<"}"<<endl;return o;}
#ifdef LOCAL
vs s_p_l_i_t(const string&s,char c){vs v;stringstream ss(s);string x;while(getline(ss,x,c))v.emplace_back(x);return move(v);}
void e_r_r(vs::iterator it){cerr<<endl;}
template<class T,class... Args>void e_r_r(vs::iterator it,T a,Args... args){cerr<<it->substr((*it)[0]==' ',it->length())<<" = "<<a<<", ";e_r_r(++it,args...);}
#define out(args...){vs a_r_g_s=s_p_l_i_t(#args,',');e_r_r(a_r_g_s.begin(),args);}
#else
#define out(args...)
#endif

void Main() {
  int n = ri();

  vector<int> A(n);
  rep(i, n) A[i] = ri();

  sort(all(A));

  int ok = n;
  int ng = -1;

  vector<ll> R(sz(A)+1);
  rep(ii, sz(A)) R[ii+1] = R[ii] + A[ii];
  //out(A);
  //out(R);

  // 大きさA[x]は制覇できるか
  auto check = [&](int x) -> bool {
    //自分×2より小
    ll cur = A[x];
    while (1) {
      ll can = cur * 2;
      int ub = upper_bound(all(A), can) - A.begin();
      ll new_size = R[ub];
      //out(x, A[x], cur, can, ub, new_size);
      if (new_size == cur) break;
      cur = new_size;
    }
    //out(cur, R[n]);
    return cur == R[n];
  };

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    bool c = check(mid);
    //cout << "ok: " << ok << ", ng: " << ng << ", ";
    //cout << "check(" << mid << ") -> " << c << endl;
    if (c) ok = mid;
    else ng = mid;
  }

  cout << (n-ok) << endl;




}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 1408
import sys
A, B, C, K = map(int, input().split())
c = 0
if K <= A:
    c += K
    print(c)
    sys.exit()
else:
    c += A
    K -= A
if K <= B:
    print(c)
    sys.exit()
else:
    K -= B
    c -= K
    print(c)

Measured memory_bytes: 9164
#include<stdio.h>
#define N 100000

typedef struct {
  char m;
  int n;
} Card;

Card A[N];
Card B[N];

int Partition(Card A[], int p, int r){
  int x, i, j; 
  Card temp;
  x = A[r].n;
  i = p - 1;
  for(j = p; j < r; j++){
    if(A[j].n <= x){
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }  
  temp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = temp;
  return i + 1;
}
void QuickSort(Card A[], int p, int r){
  int q;
  if(p < r){
    q = Partition(A, p, r);
    QuickSort(A, p, q - 1);
    QuickSort(A, q + 1, r);
  }
}

void Merge(Card B[],int left, int mid, int right){
  int n1, n2;
  n1 = mid - left;
  n2 = right - mid;
  Card L[n1 + 1], R[n2 + 1];
  int i, j, k;
  for(i = 0; i < n1; i++){
    L[i] = B[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = B[mid + i];
  }
  L[n1].n = N;
  R[n2].n = N;
  i = 0;
  j = 0;
  for(k = left; k < right; k++){
    if(L[i].n <= R[j].n){
      B[k] = L[i];
      i++;
    } else {
      B[k] = R[j];
      j++;
    }
  }
}

void MergeSort(Card B[], int left, int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right) / 2;
    MergeSort(B, left, mid);
    MergeSort(B, mid, right);
    Merge(B, left, mid, right);
  }
}


int judge(int n){
  int i, j;
for(i = 0; i < n; i++){
  if(A[i].m != B[i].m) return 1;
 }
 return 0;
}

int main(){
  int n, i;
  char g;
  scanf("%d%c", &n, &g);
  for(i = 0; i < n; i++){
    scanf("%c%d%c", &A[i].m, &A[i].n, &g);
    B[i] = A[i];
  }
  QuickSort(A, 0 ,i - 1);
  MergeSort(B, 0, n);
  if(judge(n) == 0) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0; i < n; i++) printf("%c %d\n", A[i].m, A[i].n);
  return 0;

}

Measured memory_bytes: 2948
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

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

int n;
ll c[26];
ll d[400][26];

ll calc(vector<int> &contest){
	ll last[26];
	
	memset(last,-1,sizeof(last));
	
	ll res=0;
	rep(x,0,n){
		res+=d[x][contest[x]];
		last[contest[x]]=x;
		
		rep(y,0,26) res-=c[y]*(x-last[y]);
	}
	
	return res;
}

//store curr best
ll best;
vector<int> ans;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	//freopen("sample2.in","r",stdin);
	
	auto begin_time=chrono::steady_clock::now().time_since_epoch().count();
	
	cin>>n;
	rep(x,0,26) cin>>c[x];
	
	rep(x,0,n){
		rep(y,0,26) cin>>d[x][y];
	}
	
	vector<int> curr;
	rep(x,0,n){
		curr.push_back(0);
	}
	
	ll val=calc(curr);
	
	best=val;
	ans=curr;
	
	while (chrono::steady_clock::now().time_since_epoch().count()-begin_time<1900000000){
		rep(zzz,0,375){ //try a few times to go to a smaller place
			int idx=rng()%n;
			int type=curr[idx];
			
			curr[idx]=rng()%26;
		
			ll temp=calc(curr);
			if (temp>val){
				val=temp;
				
				if (best<val){
					best=val;
					ans=curr;
				}
				
				goto ok;
			}
			else{
				curr[idx]=type;
			}
		}
		
		//cout<<"reached "<<val<<endl;
		
		//almost maxima. screw  around
		rep(x,0,2){
			curr[rng()%n]=rng()%26;
			val=calc(curr);
		}
		
		ok:;
	} 
	
	//pls uncomment later
	rep(x,0,n) cout<<ans[x]+1<<endl;
	
	//cout<<"debug: "<<best<<endl;
}


Measured memory_bytes: 3756
import java.util.Scanner;
public class Main

{
    public static void main(String arg[])
    {
        int a,b;
        @SuppressWarnings("resource")
		Scanner scan=new Scanner(System.in);
        a=scan.nextInt();
        b=scan.nextInt();
        if(a%b==0||a==b)
        {
        	System.out.println(-1);
        	System.exit(0);
        }
        int c=a;
        while(2>1)
        {
            c=c+a;
            if(c%a==0&&c%b!=0)
            {
            System.out.println(c);
            break;
            }
            if(c>b&&a%b==0)
            {
                System.out.println("Hello"+-1);
            break;
            }
        }
    }
}


Measured memory_bytes: 22740
#include <cstdio>

inline int read(){
	char c=getchar(); int x=0,ft=1;
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') ft=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
	return x*ft;
}

const int N=2e5+5;

int n,a[N],s[N],c[N],top;

void insert(int x){
	if(s[top]<x) s[++top]=x,c[top]=1; else ++c[top];
}

bool check(int k){
	top=0;
	for(int i=2;i<=n;++i) if(a[i-1]>=a[i]){
		while(top&&s[top]>a[i]) --top; insert(a[i]);
		while(top&&c[top]==k){
			int pos=s[top--]; if(pos==1) return 0; insert(pos-1);
		}
	}
	return 1;
}

int main(){
	n=read();
	for(int i=1;i<=n;++i) a[i]=read();
	int l=1,r=n,mid;
	while(l<r){
		mid=(l+r)>>1;
		if(check(mid)) r=mid; else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);


int main(){
  string S;
  cin >> S;
  bool AC = true;
  int tmp, cnt = 0;
  for(int i=2; i<S.size()-1; i++){
    if(S[i] == 'C'){
      cnt++;
      tmp = i;}
  }
  if(cnt != 1) AC = false;
  else if(S[0] != 'A') AC = false;
  rep(i, S.size()){
    if(i != tmp && i != 0){
      if(isupper(S[i]))
         AC = false;
         }
  }
 if(AC) cout << "AC" << endl;
      else cout << "WA" << endl;
 }


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

using namespace std;
typedef long long LL;
typedef long long LL;
static LL INF = (1LL<<62);

const int MAX = 100002;
int PARENT[MAX] = {0};
int RANK[MAX] = {0};

void init(int L){
	if(L<1) return;
	for(int i=0; i<L; i++){
		PARENT[i]=i;
		RANK[i]=0;
	}
}

int root(int x){
	if(x<0) return -1;
	if(PARENT[x]==x){
		return x;
	}
	else{
		PARENT[x] = root(PARENT[x]);
		return PARENT[x];
	}
}

int same(int x, int y){
	if(x==y) return 1;
	if(root(x)==root(y)){
		return 1;
	}
	else{
		return 0;
	}
}

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

	int a = root(x);
	int b = root(y);
	if(a==b) return;

	if(RANK[x]<RANK[y]){
		PARENT[b] = a;
	}
	else{
		PARENT[a] = b;
		if(RANK[x]==RANK[y]) RANK[x] += RANK[y];
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M; cin >> N >> M;
	vector<int> P;
	for(int i=0; i<N; i++){
		int p; cin >> p;
		P.push_back(p-1);
	}

	init(N);
	for(int i=0; i<M; i++){
		int x, y; cin >> x >> y;
		combine(x-1, y-1);
	}
	for(int i=0; i<N; i++){
		root(i);
	}
	int ans = 0;
	for(int i=0; i<N; i++){
		if(same(i, P[i]) == 1){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 4620
N, A, B = map(int, input().split())
S = input()
dom = 0
glo = 0
ans = []
for i in S:
  if i == 'c':
    ans.append('No')
    continue
  elif i == 'a':
    if dom + glo < A + B:
      dom += 1
      ans.append('Yes')
    else:
      ans.append('No')
  else:
    if (dom + glo < A + B) and (glo < B):
      glo += 1
      ans.append('Yes')
    else:
      ans.append('No')
for i in range(len(S)):
  print(ans[i])

Measured memory_bytes: 4784