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

struct Pos{
    int x;
    int y;
    int order;
};
bool asc_x(const Pos& l, const Pos& r) {
    return l.x < r.x;
}
bool asc_y(const Pos& l, const Pos& r) {
    return l.y < r.y;
}

struct Node{
    int x;
    int y;
    int order;
    Node* left;
    Node* right;
};

class Tree{
    Node* root;
    Node* makeTree(vector<Pos>& A, int l, int r, int depth){
        if (l > r) return nullptr;
        if (depth % 2) {
            sort(A.begin() + l, A.begin() + r + 1, asc_y);
        } else {
            sort(A.begin() + l, A.begin() + r + 1, asc_x);
        }
        int mid = (l + r) / 2;
        Node* p = new Node;
        p->x     = A[mid].x;
        p->y     = A[mid].y;
        p->order = A[mid].order;
        p->left  = makeTree(A,       l, mid - 1, depth + 1);
        p->right = makeTree(A, mid + 1,       r, depth + 1);
        return p;
    }
    void find_(Node* n, int sx, int tx, int sy, int ty, int depth, vector<int>& ans){
        if (n == nullptr) return;
        int n_, s, t;
        if (depth % 2) {
            n_ = n->y;
            s  = sy;
            t  = ty;
        } else {
            n_ = n->x;
            s  = sx;
            t  = tx;
        }
        if (n_ >= s) find_(n->left, sx, tx, sy, ty, depth + 1, ans);
        if (n->x >= sx && n->x <= tx && n->y >= sy && n->y <= ty) {
            ans.push_back(n->order);
        }
        if (n_ <= t) find_(n->right, sx, tx, sy, ty, depth + 1, ans);
    }
public:
    Tree(vector<Pos>& A){
        root = makeTree(A, 0, A.size() - 1, 0);
    }
    void find(int sx, int tx, int sy, int ty){
        vector<int> ans;
        find_(root, sx, tx, sy, ty, 0, ans);
        sort(ans.begin(), ans.end());
        for (int i = 0; i < ans.size(); i++) {
            // cout << ans[i] << endl;
            printf("%d\n", ans[i]);
        }
        // cout << endl;
        printf("\n");
    }
};

int main(){
    int n;
    // cin >> n;
    scanf("%d", &n);
    vector<Pos> A(n);
    for (int i = 0; i < n; i++) {
        // cin >> A[i].x >> A[i].y;
        scanf("%d %d", &(A[i].x), &(A[i].y));
        A[i].order = i;
    }
    Tree T(A);
    int q;
    // cin >> q;
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        int sx, tx, sy, ty;
        // cin >> sx >> tx >> sy >> ty;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        T.find(sx, tx, sy, ty);
    }
    return 0;
}



Measured memory_bytes: 30820
#include <bits/stdc++.h>
#include <boost/math/common_factor.hpp>
using namespace std;

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }


// ***************************************

vector<int> ans;


int main(void){

    int N, W;
    cin >> N >> W;

    vector<pair<int, int>> items(N);

    int w, v;
    REP(i, N) {
        cin >> w >> v;
        items[i] = { w, v };
    }

    vector<ll> dp(W + 1);

    REP(j, N){
        w = items[j].first;
        v = items[j].second;
        for(int i = W; i >= 0; i--) {
            if (i - w < 0) continue;
			dp[i] = max(dp[i], dp[i - w] + v);
        }
    }

    cout << dp[W] << endl;

    return 0;
}

Measured memory_bytes: 1024
#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>;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    bool ok = true;
    rep(i,n){
        if (a[i]%2 == 1) continue;
        if (a[i]%3 != 0 && a[i]%5 != 0) ok = false;
    }
    if(ok) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	string S;
	cin >> S;

	if (S[0] == 'A' && S[1] == 'A' && S[2] == 'A') {
		cout << "No";
	}

	else if (S[0] == 'B' && S[1] == 'B' && S[2] == 'B') {
		cout << "No";
	}

	else {
		cout << "Yes";
	}

}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (true) {
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '?') return 0;
    
    if (op == '+') cout << a + b << '\n';
    if (op == '-') cout << a - b << '\n';
    if (op == '*') cout << a * b << '\n';
    if (op == '/') cout << a / b << '\n';
  }
}


Measured memory_bytes: 3136
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut n: isize = read();
    let k: isize = read();
    n %= k;
    if n > (n-k).abs() {
        println!("{}", (n-k).abs());
    } else {
        println!("{}", n);
    }    
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,x,y,z;
  int a[LIMIT2]={0};
  ll s;
  
  scanf("%lld %lld",&k,&s);
  for(x=0;x<=k;x++){
    for(y=0;y<=k;y++){
      z = s-x-y;
      if(0<=z && z<=k) result++;
    }
  }
  printf("%lld\n",result);
  return 0;
}

Measured memory_bytes: 128
N = int(input())
cnt1 = 0
cnt2 = 0
cnt3 = 0
cnt4 = 0
for i in range(N):
  S = input()
  if S == 'AC':
    cnt1 += 1
  elif S == 'WA':
    cnt2 += 1
  elif S == 'TLE':
    cnt3 += 1
  else:
    cnt4 += 1
print( 'AC x ' + str(cnt1) )
print( 'WA x ' + str(cnt2) )
print( 'TLE x ' + str(cnt3) )
print( 'RE x ' + str(cnt4) )

Measured memory_bytes: 9144
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define PB push_back
#define ar2 array<int,2>
typedef long long LL;
const LL P = 1e9+7;
const LL INF = 1e18;
const int N = 1e5+5;
mt19937 rng(time(0));

int T;
LL n, a, b, c, d;
unordered_map<LL, LL> dp;

LL dfs(LL n){
	if (n==0) return 0;
	if (dp[n]) return dp[n];
	LL res = INF;
	if (res/d >= n) res = d * n;
	LL x = n%2, y = n%3, z = n%5;
	res = min(res, min(x*d + dfs((n-x)/2), (2-x)*d + dfs((n-x)/2+1)) + a);
	res = min(res, min(y*d + dfs((n-y)/3), (3-y)*d + dfs((n-y)/3+1)) + b);
	res = min(res, min(z*d + dfs((n-z)/5), (5-z)*d + dfs((n-z)/5+1)) + c);
	//cout<<n<<" "<<res<<endl;
	return dp[n] = res;
}

int main(){
	#ifndef ONLINE_JUDGE
	//freopen("test.in","r",stdin);
	#endif
	cin>>T;
	while(T--){
		cin>>n>>a>>b>>c>>d;
		dp.clear();
		dp[0] = 0;
		dp[1] = d;
		dp[2] = min(d+d, d+a);
		cout<<dfs(n)<<endl;
	}
	return 0;
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define de(c) cout << #c << " = " << c << endl
#define dd(c) cout << #c << " = " << c << " "
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int T;
string str;

int main(int argc, char const *argv[])
{
#ifdef indiewar
    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//    cin >> T;
    T =1;
    while(T--)
    {
        cin >> str;
        ll ans = 0;
        int le = str.size();
        per(i,0,le)
        {
            int tmp = (str[i]-'0');
            if(tmp == 10)
            {
                if(i == 0)
                {
                    ans += 1;
                } else
                {
                    str[i-1]++;
                    ans += 0;
                }
            }
            else
            {
                if (tmp > 11 - tmp)
                {
                    if (i != 0)
                    {
                        str[i - 1]++;
                        ans += 10 - tmp;
                    }
                    else
                    {
                        ans += 11 - tmp;
                    }
                }
                else if (tmp == 5)
                {
                    if (i != 0)
                    {
                        if (str[i - 1] - '0' < 5)
                        {
                            ans += 5;
                        }
                        else
                        {
                            ans += 5;
                            str[i - 1]++;
                        }
                    }
                    else
                    {
                        ans += 5;
                    }
                }
                else
                {
                    ans += tmp;
                }
            }
//            ans += min(str[i]-'0',11-str[i]+'0');
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1948
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

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

    int N = 26;
    int D = scanner.nextInt();
    int[] c = new int[N];
    int[][] s = new int[D][N];
    for (int i = 0; i < N; i++) c[i] = scanner.nextInt();
    for (int i = 0; i < D; i++) for (int j = 0; j < N; j++) s[i][j] = scanner.nextInt();
    int[] t = new int[D];

    int score = 0;
    List<Integer>[] last = new List[N];
    for (int i = 0; i < N; i++) {
      last[i] = new ArrayList<>();
      last[i].add(0);
    }
    for (int d = 0; d < D; d++) {
      int type = -1;
      int max = -36500 * 26;
      for (int i = 0; i < N; i++) {
        int ss = s[d][i];
        for (int j = 0; j < N; j++) if (j != i) ss -= c[j] * (d + 1 - last[j].get(last[j].size() - 1));
        if (ss > max) {
          max = ss;
          type = i;
        }
      }
      t[d] = type;
      last[type].add(d + 1);
      score += max;
    }
    for (int i = 0; i < N; i++) last[i].add(D + 1);

    Random rand = new Random();
    for (int i = 0; i < 10_000_000; i++) {
      int d = rand.nextInt(D) + 1;
      int oldType = t[d - 1];
      int newType = rand.nextInt(N);
      int newScore = update(c, s, t, score, last, d, newType);
      if (newScore > score) {
        score = newScore;
        t[d - 1] = newType;
        int p1 = upperBound(last[newType], d);
        int p2 = upperBound(last[oldType], d);
        last[oldType].remove(p2 + 1);
        last[newType].add(p1 + 1, d);
      }
    }

    for (int i = 0; i < D; i++) {
      System.out.println(t[i] + 1);
    }
  }

  private static int update(int[] c, int[][] s, int[] t, int score, List<Integer>[] last, int d, int newType) {
    int oldType = t[d - 1];
    int p1 = upperBound(last[newType], d);
    int p2 = upperBound(last[oldType], d);
    score += s[d - 1][newType] - s[d - 1][oldType];
    score += c[newType] * (d - last[newType].get(p1)) * (last[newType].get(p1 + 1) - d)
        - c[oldType] * (d - last[oldType].get(p2)) * (last[oldType].get(p2 + 2) - d);
    return score;
  }

  public static int upperBound(List<Integer> a, int k) {
    int left = -1;
    int right = a.size();
    while (right - left > 1) {
      int mid = (left + right) / 2;
      if (a.get(mid) < k) {
        left = mid;
      } else {
        right = mid;
      }
    }
    return left;
  }
}


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

using namespace std;

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

    int P,Q,R; cin>>P>>Q>>R;
    auto ans = min(min(P+Q, Q+R), R+P);
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
//#include "debug.cpp"
const int inf=1e9;
const int M=1e9+7;


int32_t main()
{
    boost;
	cout<<setprecision(15)<<fixed;
	int n,k;
	cin>>n>>k;
	double a[n+1];
	double p[n+1]={0};
	double s=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		p[i]=a[i];
		p[i]*=(p[i]+1);
		p[i]/=2*a[i];
		p[i]+=p[i-1];
		//cout<<p[i]<<endl;
		if(i>=k)
			s=max(s,p[i]-p[i-k]);
	}
	cout<<s<<endl;	
}


Measured memory_bytes: 3456
package main

import (
	"fmt"
)

func main() {
	var n,k int
	fmt.Scan(&n,&k)

	con := (n-1)*(n-2)/2
	if con < k {
		fmt.Println(-1)
	} else {
		con = n*(n-1)/2
		fmt.Println(con-k)

		count := 0
		for i := 1; i < n+1; i++ {
			for j := i+1; j < n+1; j++ {
				if count != k && j != n{
					count++
					continue
				}
				fmt.Println(i,j)
			}
		}
	}

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
    
int run_test(){
	int n;
	cin >> n;
	ll arr[n];
	int p = 1; ll sum = 0;
	for(int i=0;i <n; i++){
		cin >> arr[i];
		if(p == 1){
			sum += arr[i];
		}
		else{
			sum -= arr[i];
		}
		p = !p;
	}
	vector<ll> ans;
	ans.pb(sum);
	for(int i=0; i<n-1; i++){
		ans.pb(arr[i]*2 - sum);
		sum = (arr[i] * 2) - sum;
	}
	for(auto x: ans){
		cout << x << " ";
	}
	cout << "\n";
	return 0;
}
    
int main(){
   FAST;
    ll t;
    t = 1;
     
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 5008
#include <cstdio>
#include <vector>
using namespace std;
 
long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;
 
void insertionSort(int A[], int n, int g) {
  for (int i = g; i < n; ++i) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }
}
 
void shellSort(int A[], int n) {
  for (int h = 1; h <= n; h = 3*h + 1)
    G.push_back(h);
  for (int i = G.size() - 1; i >= 0; --i)
    insertionSort(A, n, G[i]);
}

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    cnt = 0;
    shellSort(A,n);
    printf("%ld\n", G.size());
    for (int i = G.size() - 1; i > 0; --i){
         printf("%d ", G[i]);    
    }
     
    printf("%d\n", G[0]);
    printf("%lld\n", cnt);
    for (int i = 0; i < n; ++i){
         printf("%d\n", A[i]);
    }
   
    return 0;
}

Measured memory_bytes: 6660
S = input()

L = {}

ans = "Yes"
for s in S:
    if s in L.keys():
        L[s] += 1
        if L[s] > 2:
            ans = "No"
    else:
        L[s] = 1
if len(L.keys()) != 2:
    ans = "No"

print(ans)


Measured memory_bytes: 8908
N = int(input())
xs = []
ys = []

for _ in range(N):
    a, b = map(int, input().split())
    xs.append((a, b))
xs.sort(key=lambda l: l[0])

for _ in range(N):
    c, d = map(int, input().split())
    ys.append((c, d))
ys.sort(key=lambda l: l[0])

used = []
ret = 0
for (c, d) in ys:
    l = []
    for (a, b) in xs:
        if a < c and b < d:
            l.append((a, b))

    ab = None
    for (a, b) in l:
        if used.count((a, b)) == 1:
            continue
        if ab is None:
            ab = (a, b)
        elif ab[1] < b:
            ab = (a, b)

    if ab is not None:
        used.append(ab)
        ret += 1

print(ret)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    ll r = 1;
    int p[26] = {};
    for (int i = 0; i < n; i++) {
        p[s[i] - 'a']++;
    }
    for (int j = 0; j < 26; j++) {
        if (p[j] > 0) r *= p[j] + 1, r %= P;
    }
    r += P - 1;
    r %= P;

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;

class Program {
    static int Main(string[] args) {
        string v = Console.ReadLine();

        int W = int.Parse(v.Split(' ')[0]);
        int H = int.Parse(v.Split(' ')[1]);
        int x = int.Parse(v.Split(' ')[2]);
        int y = int.Parse(v.Split(' ')[3]);
        int r = int.Parse(v.Split(' ')[4]);

        string msg = "No";
        if ((r <= x) && (x <= W - r) && (r <= y) && (y <= H - r)) {
            msg = "Yes";
        }
        Console.WriteLine(msg);
        return 0;
    }
}

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)

const ll p = 998244353LL;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n,q;
	cin>>n>>q;

	ll blacks = ll(n-2)*ll(n-2);	

	set<pair<int,int>> rows,cols;

	while(q--)
	{
		int t,x;
		cin>>t>>x;

		// cout << ll(n-2)*ll(n-2) - blacks << endl;

		if(t==1)
		{
			// add a vertical thing

			auto thing = cols.lower_bound({x,0});
			
			if(cols.empty() || thing == cols.begin())
			{
				// left most thing
			
				if(rows.empty()) blacks -= (n-2);
				else blacks -= (*rows.lower_bound({0,0})).ff-2;

				if(rows.empty()) cols.insert({x, n});
				else cols.insert({x, (*rows.lower_bound({0,0})).ff});
			}

			else
			{
				thing--;
				blacks -= (*thing).ss - 2; 
			}
		}

		if(t==2)
		{
			auto thing = rows.lower_bound({x,0});

			// cout << "TING: " << (*cols.lower_bound({0,0})).ff << endl;

			if(rows.empty() || thing == rows.begin())
			{
				if(cols.empty()) blacks -= (n-2LL);
				else blacks -= ((*cols.lower_bound({0,0})).ff-2);

				if(cols.empty()) rows.insert({x, n});
				else rows.insert({x, (*cols.lower_bound({0,0})).ff});
			}

			else
			{
				thing--;
				blacks -= (*thing).ss - 2; 
			}
		}
	}

	cout << blacks << endl;
}

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

int main() {
    int x;
    cin >> x;
    int max=1;
    for(int b=2; b*b<=x; b++) {
        int c = b*b;
        while(c*b<=x) c *= b;
        if(max<c) max = c;
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

int main(void) {
    int n, k;
    string s;
    cin >> n >> s >> k;

    char r = s[k-1];
    REP(i, n) {
        if (s[i] != r) cout << "*";
        else cout << s[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

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

int main(){
    string s;cin>>s;
    s.erase(s.size()-2,2);
    while(!s.empty()){
        string t = s.substr(0,s.size()/2),u = s.substr(s.size()/2,s.size()/2);
        if(t==u){
            cout<<s.size()<<endl;
            return 0;
        }
        s.erase(s.size()-2,2);
    }
}



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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1e9 + 7;
const int N = 5e3 + 5;

typedef long long ll;

pair <int, int> max(pair <int, int> a, pair <int, int> b)
{
      if(a.fr > b.fr) return a;
      if(a.fr < b.fr) return b;
      if(a.sc < b.sc) return a;
      return b;
}

int n, m, numlog[N], a[N][202];
pair <int, int> table[23][N][202];
ll pref[N], ans;


void build(int pos)
{
      for(int i = 0; i <= numlog[n]; i ++)
      {
            for(int j = 1; j <= n; j ++)
            {
                  if(i == 0)
                  {
                        table[i][j][pos] = mk(a[j][pos], j);
                        continue;
                  }
                  int d = min(j + (1 << (i - 1)), n);
                  table[i][j][pos] = max(table[i - 1][j][pos], table[i - 1][d][pos]);
            }
      }
}

pair <int, int> get(int l, int r, int pos)
{
      int curlog = numlog[r - l + 1];
      return max(table[curlog][l][pos], table[curlog][r - (1 << curlog) + 1][pos]);
}

void dv(int l, int r, int opl, int opr)
{
      if(l > r) return ;
      int md = (l + r) >> 1, opt = l;
      ll c = 0;
      for(int i = opl; i <= min(opr, md); i ++)
      {
            ll res = 0;
            for(int j = 1; j <= m; j ++)
                  res += get(i, md, j).fr;
            res -= pref[md - 1] - pref[i - 1];
            if(res > c)
            {
                  c = res;
                  opt = i;
            }
      }
      ans = max(ans, c);
      dv(l, md - 1, opl, opt);
      dv(md + 1, r, opt, opr);
}

int main()
{
      scanf("%d %d", &n, &m);

      for(int i = 2; i <= n; i ++)
            numlog[i] = numlog[i / 2] + 1;

      for(int i = 1; i < n; i ++)
      {
            scanf("%lld", &pref[i]);
            pref[i] += pref[i - 1];
      }

      for(int i = 1; i <= n; i ++)
            for(int j = 1; j <= m; j ++)
                  scanf("%d", &a[i][j]);

      for(int i = 1; i <= m; i ++)
            build(i);

      dv(1, n, 1, n);

      cout << ans << endl;
}


Measured memory_bytes: 110080
#include<stdio.h>
int main(){
int i,j,n,a[10001];
long int min,max,sum=0;
scanf("%d",&n);
for(i =0;i < n;i++){
    scanf("%d",&a[i]);
}
max = a[0];min=a[0];sum=a[0];
for(i=1;i < n;i++){
    if(max < a[i]) max = a[i];
    if(min > a[i]) min = a[i];
    sum += a[i];
}
printf("%ld %ld %ld\n",min,max,sum);
return 0;
}

Measured memory_bytes: 1808
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;
//#define PRINT(x) { std::cout << #x << ": " << x << std::endl; }
#define PRINT(x)

char S[8001] = {};
int X, Y;
int x0 = 0;

char get(char* tbl, int v, int rng)
{
    PRINT(v);
    PRINT(rng);
    if (v < -rng || rng < v)
    {
        return 0;
    }
    PRINT((int)tbl[v + rng]);
    return tbl[v + rng];
}

bool dp(int v0, const vector<int>& v, int vf)
{
    if (v.empty())
    {
        return v0 == vf;
    }
    int sum = 0;
    vector<int> rng;
    rng.push_back(sum);
    for (int i = 0; i < v.size(); ++i)
    {
        sum += v[i];
        rng.push_back(sum);
    }
    int vvf = vf - v0;
    PRINT(vvf);
    PRINT(sum);
    if (vvf < -sum || sum < vvf)
    {
        return false;
    }
    char tbl1[16000];
    char tbl2[16000];
    char* fr_tbl = tbl1;
    char* to_tbl = tbl2;
    memset(fr_tbl, 0, 2 * rng[0] + 1);
    fr_tbl[0] = 1;
    for (int i = 0; i < v.size(); ++i)
    {
        memset(to_tbl, 0, 2 * rng[i + 1] + 1);
        for (int j = -rng[i + 1]; j <= rng[i + 1]; ++j)
        {
            to_tbl[j + rng[i + 1]] = get(fr_tbl, j + v[i], rng[i]) ||
                                     get(fr_tbl, j - v[i], rng[i]);
        }
        std::swap(fr_tbl, to_tbl);
    }
    int ans = get(fr_tbl, vvf, rng[v.size()]);
    return ans;
}

int main(int argc, char *argv[])
{
    scanf("%s", S);
    scanf("%d %d", &X, &Y);
    const int ns = strlen(S);
    int is;
    for (is = 0; is < ns; ++is)
    {
        if (S[is] == 'F') x0 += 1;
        else break;
    }
    ++is;
    int state = 1;              // 1(y) -> 0(x) -> 1(y)...
    vector<int> vx;
    vector<int> vy;
    int v = 0;
    for (; is < ns; ++is)
    {
        if (S[is] == 'F')
        {
            ++v;
        }
        else
        {
            if (state) vy.push_back(v);
            else vx.push_back(v);
            state = !state;
            v = 0;
        }
    }
    if (state) vy.push_back(v);
    else vx.push_back(v);

    if (dp(x0, vx, X) && dp(0, vy, Y))
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 384
x = 1
y = 1
while x != 0 or y != 0:
 n = map(int,raw_input().split())
 x = n[0]
 y = n[1]
 if x == 0 and y == 0:
  break
 elif x <= y:
  print x,y
 elif x >  y:
  print y,x

Measured memory_bytes: 6436
fn main() {
    let n = read::<u32>();
    println!("ABC{}", n);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
   int n,m;
vector<int> v[200005];
vector<int> vis(200005+1),ans(200005+1);
void dfs(int node){
   vis[node]=1;
   queue<int> q;
   q.push(node);
   while(!q.empty()){
      int fr=q.front();
      q.pop();
      rr(v[fr]){
         if(!vis[val]){
            ans[val]=fr;
            q.push(val);
            vis[val]=1;
         }
      }
   }
}
int32_t main(){
   cin>>n>>m;
   rep(i,0,m){
      int a,b;
      cin>>a>>b;
      v[a].pub(b);
      v[b].pub(a);
   }
   dfs(1);
   rep(i,1,n+1){
      if(!vis[i]){
         cout<<"No\n";
         return 0;
      }
   }
   cout<<"Yes\n";
   rep(i,2,n+1)cout<<ans[i]<<"\n";
   return 0;
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int n;
  cin >> n;
  if (n == 2) {
    cout << -1 << endl;
  } else if (n % 2 == 0) {
    vector<vector<int>> res(n);
    for (int i = 0; i < n; ++i) {
      for (int j = 2; j < n; ++j) {
        if (j == n / 2) continue;
        res[i].emplace_back((i + j) % n + 1);
      }
    }
    for (int i = 0; i < n; ++i) {
      if (i < n / 2) res[i].emplace_back((i + 1) % n + 1);
      else res[i].emplace_back((i + n / 2) % n + 1);
    }
    for (int i = 0; i < n; ++i) {
      if (i >= n / 2) res[i].emplace_back((i + 1) % n + 1);
      else res[i].emplace_back((i + n / 2) % n + 1);
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n - 1; ++j) cout << res[i][j] << (j < n - 2 ? " " : "\n");
    }
  } else {
    for (int i = 0; i < n; ++i) {
      for (int j = 1; j < n; ++j) {
        cout << (i + j) % n + 1 << (j < n - 1 ? " " : "\n");
      }
    }
  }
}


Measured memory_bytes: 384
#include <iostream>

int main() {
  // 年齢入力
  int age;
  std::cin >> age;

  // 七五三判定処理
  std::string ans;
  if (age == 7 || age == 5 || age == 3) {
    ans = "YES";
  } else {
    ans = "NO";
  }

  // 出力
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 4e4 + 10;
bool check(vector<int>& v, int x)
{
	bitset<N> b;
	b[20000] = 1;
	for (auto& t : v)
	{
		b = (b << t) | (b >> t);
	}
	return b[20000 + x];
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string str;
	int x, y;
	cin >> str;
	str.push_back('T');
	int o = str.find_first_of('T');
	cin >> x >> y;
	if (o != -1) x -= o;
	else o = str.length();
	int cnt = 0;
	vector<int> v[2];
	int t = 0;
	for (int i = o; i < str.length(); i++)
	{
		if (str[i] == 'T')
		{
			if (cnt) v[t].push_back(cnt);
			cnt = 0;
			t ^= 1;
		}
		else
			cnt++;
	}
	if (check(v[0], x) && check(v[1], y)) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,A,B;cin>>N>>A>>B;
  if(A>B||(N==1&&A<B)){
    cout<<0<<endl;
  }
  else{
    cout<<(N-2)*(B-A)+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define fi first
#define se second
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vl vector<long long>
#define vll vector<pair<long long, long long>>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define fori(i, n) for(ll i = 0; i < n; i++)
#define foris(i, a, b) for(ll i = a; i < b; i++)
#define forise(i, a, b) for(ll i = a; i <= b; i++)
#define ford(i, n) for(ll i = n; i >= 0; i--)
#define fords(i, a, b) for(ll i = a; i >= b; i--)
#define fordse(i, a, b) for(ll i = a; i > b; i--)
#define forr(i, a) for (auto &i: a)
#define rev(a) reverse(a.begin(), a.end())
#define revf(a, b, c) (reverse(a.begin() + b, a.begin() + c))
#define digits(i) (int)((log(i)/(log(10))+1)
#define umap unordered_map
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
const int mod = 1000000007;

int A, B;

int main() {
  io();
  cin >> A >> B;
  
  bool canA = 1 <= A && A <= 9;
  bool canB = 1 <= B && B <= 9;
  
  if(canA && canB) {
    cout << A * B;
  }
  else {
    cout << "-1";
  }
  
  return 0;
}

Measured memory_bytes: 256
using System;

public class Example {
    public static void Main() {
        while (true) {
            int[] size = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), delegate(string value) {
                return int.Parse(value);
            });
            if (size[0] == 0 && size[1] == 0) break;
            for (int i = 0; i < size[0]; i++) {
                for (int j = 0; j < size[1]; j++) {
                    Console.Write("#");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}

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

using namespace std;

int main()
{
  int N, K;
  vector<int> H;
  H.reserve(200000);
  cin >> N >> K;
  int buf;
  for(int in=0;in < N;++in)
  {
    cin >> buf;
    H.push_back(buf);
  }
  sort(H.begin(), H.end());
  

  int64_t HP=0;
  for(int i=0;i<N-K;++i)
  {
    HP += H[i];
  }
 
  cout << HP << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin>>S>>T;
  int N=S.size(),M=T.size(),ans=M;
  for(int i=0;i<N-M+1;i++){
    int cnt=0;
    for(int j=0;j<M;j++)
      if(S[i+j]!=T[j])cnt++;
    ans=min(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.trim().chars();
	let mut check = true;
	let mut flag = true;
	for n in iter {
		if check {
			if n == 'L' {
				flag = false;
				break;
			}
		}else{
			if n == 'R' {
				flag = false;
				break;
			}
		}
		check = !check;
	}
	if flag {
		println!("Yes");
	}else{
		println!("No");
	}
}

Measured memory_bytes: 4352
import Control.Applicative
import Control.Monad
import Data.List

cutrect :: Int -> Int -> Int -> Int -> [[a]] -> [[a]]
cutrect x y w h rect = map ((take w) . (drop x)) (take h (drop y rect))

yesno b = if b then "Yes" else "No"

main = do
  (n:m:_) <- (map read) . words <$> getLine
  a <- replicateM n getLine
  b <- replicateM m getLine

  putStrLn $ (yesno . (elem b) . concat) $ map (\y -> map (\x -> cutrect x y m m a) [0..n-m]) [0..n-m]


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

/**
 * Created by fcdkbear on 15.10.16.
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        long votes1 = 1L;
        long votes2 = 1L;
        int n = in.nextInt();
        for (int i = 0; i < n; ++i) {
            int t = in.nextInt();
            int a = in.nextInt();
            long k1 = (votes1 + t - 1) / t;
            long k2 = (votes2 + a - 1) / a;
            long k = Math.max(k1, k2);
            votes1 = t * k;
            votes2 = a * k;
        }
        out.println(votes1 + votes2);
        out.close();
    }

    static class Pair {
        private long first;
        private int second;

        public Pair(long first, int second) {
            this.first = first;
            this.second = second;
        }

        public long getFirst() {
            return first;
        }

        public void setFirst(long first) {
            this.first = first;
        }

        public int getSecond() {
            return second;
        }

        public void setSecond(int second) {
            this.second = second;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }

}


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

int main() {
    int num_cards, card, turn = 0;
    vector<int> cards;
    int scores[2] = {0, 0};

    cin >> num_cards;
    for(int i = 0; i < num_cards; i++) {
        cin >> card;
        cards.push_back(card);
    }
    sort(cards.begin(), cards.end(), greater<int>());
    for(int c : cards) {
        scores[turn % 2] += c;
        turn++;
    }
    cout << scores[0] - scores[1] << endl;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N;
	ll T, t[200100], ans = 0;
	
	cin >> N >> T;
	
	rep(i, N){
		cin >> t[i];
		if(i == 0)
			continue;
		if(t[i] - t[i-1] < T)
			ans += t[i] - t[i-1];
		else
			ans += T;
	}
	
	cout << ans + T;
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

ll N, K;

ll f(ll n){
  ll res = 0;
  ll a = N/n;
  ll b = 0;
  if(N%n != 0){
    if(N%n >= K && K != 0) b = N%n - K + 1;
    if(N%n >= K && K == 0) b = N%n - K;
  }
  res += a*(n-K) + b;
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  ll ans = 0;
  for(ll i = K+1; i <= N; i++){
    ans += f(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
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; }

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

    for(;k!=0;k--){
        if(b<=a){
            b*=2;
        }
        else if(c<=b) c*=2;
    }

    if(a<b && b<c) cout <<"Yes"<<endl;
    else cout << "No"<<endl;

    return 0;
}


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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
	int n,m,k,ans,cur,res,i,j,q,query,t,c,l,r;
	cin >> n >> m >> k;
	
	vector<int> fri(n,0),pos(n,1);
	
	UnionFind tree(n);
	for(q=0; q<m; q++){
		cin >> l >> r;
		l--; r--;
		if(!(tree.same(l,r))){
			pos[tree.root(r)]=pos[tree.root(l)]+pos[tree.root(r)];
			pos[tree.root(l)]=0;
			tree.unite(l,r);
		}
		fri[l]++;
		fri[r]++;
	}
	
	for(i=0; i<n; i++){
		pos[i]=pos[tree.root(i)];
	}
	
	/*
	for(i=0; i<n; i++){
		cout << pos[i] << ' ';
	}
	cout << endl;
	for(i=0; i<n; i++){
		cout << fri[i] << ' ';
	}
	cout << endl;
	*/
	for(q=0; q<k; q++){
		cin >> l >> r;
		l--; r--;
		if(tree.same(l,r)){
			pos[l]--;
			pos[r]--;
		}
	}
	for(i=0; i<n; i++){
		cout << pos[i]-fri[i]-1 << ' ';
	}
	

}

Measured memory_bytes: 2304
#include<stdio.h>

int main(void){
	
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a < b && b < c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int x,y,z;
  cin>>x>>y>>z;
  swap(x,y);
  swap(x,z);
  cout<<x<<" "<<y<<" "<<z<<endl;

  return 0;
}


Measured memory_bytes: 256
import sys

f = sys.stdin


def bisect(a,v):
    l,r = 0,len(a)-1
    
    while l != r:
        m = (l + r) // 2
        if a[m] < v:
            l = m + 1
        else:
            r = m
    return l

#n = int(f.readline())
a = list(map(int,f))
a[0] = 0
for i in range(1,len(a)):
    a[i] += a[i - 1]

sum_a = a[-1]
third = sum_a // 3

ret = []

for i in range(bisect(a, third)):
    nick1 = bisect(a, a[i] + third)
    
    for ni1 in (nick1-1,nick1):
        second = (sum_a - (a[ni1] - a[i])) // 2
        second = min(second,third)
        nick2 = bisect(a, a[ni1] + second)
        for ni2 in (nick2-1,nick2):
            if len(a) <= ni2:
                break
            piece1 = a[ni1] - a[i]
            piece2 = a[ni2] - a[ni1]
            piece3 = sum_a - piece1 - piece2
            ret.append(min(piece1,piece2,piece3))
print(max(ret))

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

int ans[51];

int main() {
  rep(a,10) rep(b,10) rep(c,10) rep(d,10) ++ans[a+b+c+d];
  int n;
  while( cin >> n ) cout << ans[n] << endl;
  return 0;
}

Measured memory_bytes: 2992
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

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

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

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

	vector<ll> a(N + 2);
	repn(i, N) cin >> a[i];
	a[N + 1] = 0;

	vector<ll> b;

	ll c = 1;
	repn(i, N) {
		if (a[i + 1] != a[i]) { b.push_back(c); c = 1; }
		else { c++; }
	}

	ll ans = 0;
	for (ll c : b) {
		ans += c / 2;
	}
	cout << ans;
	system("PAUSE");

}





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

int main() {
  int x, y;
  cin >> x >> y;

  int minval = min(x, y);
  int maxval = max(x, y);

  string ans;
  if (minval == 2 || maxval == 2) {
    ans = "No";
  } else {
    if (minval == 1) {
      if (maxval == 3 || maxval == 5 || maxval == 7 || maxval == 8 || maxval == 10 || maxval == 12)
        ans = "Yes";
      else
        ans = "No";
    } else if (minval == 3) {
      if (maxval == 5 || maxval == 7 || maxval == 8 || maxval == 10 || maxval == 12)
        ans = "Yes";
      else
        ans = "No";
    } else if (minval == 4) {
      if (maxval == 6 || maxval == 9 || maxval == 11)
        ans = "Yes";
      else
        ans = "No";
    } else if (minval == 5) {
      if (maxval == 7 || maxval == 8 || maxval == 10 || maxval == 12)
        ans = "Yes";
      else
        ans = "No";
    } else if (minval == 6) {
      if (maxval == 9 || maxval == 11)
        ans = "Yes";
      else
        ans = "No";
    } else if (minval == 7) {
      if (maxval == 8 || maxval == 10 || maxval == 12)
        ans = "Yes";
      else
        ans = "No";
    } else if (minval == 8) {
      if (maxval == 10 || maxval == 12)
        ans = "Yes";
      else
        ans = "No";
    } else if (minval == 9) {
      if (maxval == 11)
        ans = "Yes";
      else
        ans = "No";
    } else if (minval == 10) {
      if (maxval == 12)
        ans = "Yes";
      else
        ans = "No";
    } else if (minval == 11) {
      ans = "No";
    } else if (minval == 12) {
      ans = "No";
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256