akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  arrst(s,3);

  bool ok=true;
  int next=0;
  int id[3]={0,0,0};
  while(ok){
    if(id[next]==s[next].size()){
      ok=false;
      char ans='A'+next;
      prt(ans);
      return 0;
    } else {
      id[next]++;
      next = s[next][id[next]-1]-'a';
    }
  }
}


Measured memory_bytes: 256
import sys

# 商品の数，ナップサックの許容重量
n, c = list(map(int, input().split()))

# 制約より起こり得る商品価値の総和の最大値+余分
M = (10 ** 3) * n + 10

# n=1のときの例外処理
if n == 1:
    w, v = map(int, input().split())
    ans = v if c >= w else 0
    print(ans)
    sys.exit()

# DPリスト
dp = [[float("inf")] * M for i in range(n)]
dp[-1][0] = 0

for i in range(n):
    w, v = map(int, input().split())
    # 配るDP
    for j in reversed(range(M)):
        dp[i][j] = dp[i - 1][j]
        if j + v < M:
            dp[i][j + v] = min(dp[i - 1][j + v], dp[i - 1][j] + w)

ans = 0
for i in range(M):
    if dp[-1][i] <= c:
        ans = max(i, ans)

print(ans)


Measured memory_bytes: 303832
N = int(input())
H = list(map(int,input().split()))

max_height = []

for i in range(N):
  if i == 0:
    max_height.append(H[i])
  else:
    max_height.append(max(max_height[-1], H[i]))
    
ans = 0
    
for i in range(N):
  if H[i] >= max_height[i]:
    ans += 1
    
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
int main(){
	int a, b;
	while(1){
		scanf("%d%d", &a, &b);
		if(a == 0 && b == 0) return 0;
	for(int i = 0; i < a; i++){
		for(int j = 0; j < b; j++){
			if((i+j)%2==0) putchar('#');
			else putchar('.');
		}
		puts("");
	}
	puts("");
	}
}


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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	vi a(n);
	REP(i, n) cin >> a[i];
	int ans = 0;
	REP1(i, n-1){
		if(a[i] == a[i - 1] ){ a[i] = -1;
		ans++;
		}
	}
	cout << ans << "\n";
	return 0;
}


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

int main(void) {
	double  x1, y1, x2, y2, d;
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	d = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
	printf("%f\n", sqrt(d));
	return 0;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;

/*
  https://atcoder.jp/contests/abc074/tasks/arc083_b

*/
static const int MAX = 300;
static const long long INFTY = (1LL<<32);

int n;
long long d[MAX][MAX];  //d[i][j]の最短コストを記録するDPテーブル

void floyd() {

  for( int k = 0; k < n; k++){         //経由する頂点数
    for(int i = 0; i < n; i++){         //始点
      if( d[i][k] == INFTY ) continue;

      for(int j = 0; j < n; j++){       //終点
      if( d[k][j] == INFTY ) continue;

      d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      //i -> j   i -> k -> j //iからｊへの最短経路を示す
      }
    }
  }
}


int main(){
  cin >> n;

  int a[n][n];
  //d[][]に入力
  REP(i,n)REP(j,n) cin >> a[i][j];
  REP(i,n)REP(j,n) d[i][j] =  a[i][j];
  floyd();

  //条件を満たさない場合
  REP(i,n)REP(j,n){
    if(d[i][j] < a[i][j]){
      cout << -1 << endl;
      return 0;
    }
  }




  //必要のない経路を削除する
  //どこかを経由する最短経路が存在するならば， 直接つなぐ道路はカットできる．connect[i][j]　で管理
  //存在しないならば， 直接接続する道路は残す

  bool ex[n][n];
  REP(i,n)REP(j,n) ex[i][j] = true;

  for( int k = 0; k < n; k++){         //経由する頂点数
    for(int i = 0; i < n; i++){         //始点
      for(int j = 0; j < n; j++){       //終点
        if(i == j || j == k || k == i) continue;
        if(a[i][j] == a[i][k]+a[k][j]){
          ex[i][j] = false;
        }
      }
    }
  }

  ll sum = 0;
  REP(i,n)REP(j,n){
    if(ex[i][j]) sum += a[i][j];
  }

  cout << sum/2 << endl;
  return 0;
}


Measured memory_bytes: 4660
import itertools

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

d = list(sorted(map(sum, itertools.product(a, b)), reverse=True))
c.sort(reverse=True)
e = list(sorted(map(sum, itertools.product(c[:k], d[:k])), reverse=True))
for v in e[:k]:
    print(v)

Measured memory_bytes: 141204
n = int(input())
l = list(map(int,input().split()))

dp = [0 for i in range(n+1)]
dp[0] = 0
dp[1] = abs(l[1]-l[0])

for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(l[i-1]-l[i]),dp[i-2]+abs(l[i-2]-l[i]))

print(dp[n-1])


Measured memory_bytes: 13928
// author : ayush_nishad
// Road to Expert since : 30 Aug 2020
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define all(x)  x.begin(),x.end()
#define w(x) int x;cin>>x; while(x-->0)
#define memset(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

}
/*
think fast
think simple
*/
void mysol()
{
	string s;
	cin>>s;
	if(s.back()=='s')
		s+="es";
	else
		s+='s';
	cout<<s;
}

int32_t main()
{
    fast();
    // w(t)
    {
        mysol();
    }
    //cerr << sizeof(dp)*(1e-6) << " megabytes\n";
    return 0;
}


Measured memory_bytes: 3612
N = int(input())
mod = 998244353
# DP ナップサックぽいやつ
# DP[i][j] := a_0からa_iまでの部分集合で和がjになるものの個数
# 配るDPの方が場合分けがなくて簡潔に書ける 計算量増えるかも
# DP[i-1][j]→DP[i][j]とDP[i][j + a_i ]に配る

aaa = [int(input()) for _ in range(N)]

sum_now = 0
DP = [[0] * (sum(aaa)+1) for i in range(N)]
DP2 = [[0] * (sum(aaa)+1) for i in range(N)]

a = aaa[0]
DP[0][0] = 2
DP[0][a] = 1

DP2[0][0] = 1
DP2[0][a] = 1

sum_now += a

for i in range(1, N):
	a = aaa[i]
	for j in range(sum_now + 1):
		DP[i][j] += DP[i-1][j] * 2
		DP[i][j] %= mod
		DP[i][j + a] += DP[i-1][j]

		DP2[i][j] += DP2[i-1][j]
		DP2[i][j] %= mod
		DP2[i][j + a] += DP2[i-1][j]

	sum_now += a

# print(DP2)
minimum_invalid_length = int((sum_now+1)//2)
num_too_long = sum (DP[N-1][minimum_invalid_length:])
if (sum(aaa) %2 == 0):
	num_too_long -= DP2[N-1][int(sum(aaa) /2)]
# print(num_too_long)
# print(sum(aaa))
print((3** N - num_too_long * 3) % mod )


Measured memory_bytes: 457112
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = 0, b = 0, c = 0, count = 0;
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		for(int i = a; i <= b; i++) {
			if(c % i == 0) {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 26328
#![allow(unused_imports)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};

fn main() {
    input! {
        n: usize,
        arr: [i32; n],
    }
    let p = n % 2;
    let mut ans = Vec::new();
    for i in 0..(n+1)/2 { ans.push(arr[(n - 1) - 2*i]); }
    for i in 0..n/2 { ans.push(arr[2*i + p]); }
    for a in ans {
        print!("{} ", a);
    }
}


Measured memory_bytes: 10364
object Main {

  def main(args: Array[String]): Unit = {
    import scala.io.StdIn._

    val (_before, _after) = readLine().splitAt(2)
    val before = _before.toInt
    val after = _after.toInt

    if (before >= 1 && before <= 12 && after >= 1 && after <= 12) {
      println("AMBIGUOUS")
    } else if (before >= 1 && before <= 12) {
      println("MMYY")
    } else if (after >= 1 && after <= 12) {
      println("YYMM")
    } else {
      println("NA")
    }

  }

}

Measured memory_bytes: 25408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    string s,t;
    cin >> s >> t;
    rep(i, s.size()){
        if (s == t) {
            Yes;
            return 0;
        }
        s =s.substr(1, s.size()-1) + s[0];
    }
    No;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,q,ans=0;
    cin >> n >> q;
    map<string,int> task;
    queue<string> rrsch;
    for(int i=0;i<n;i++){
        string name;
        int time;
        cin >> name >> time;
        task[name] = time;
        rrsch.push(name);
    }
    while(!rrsch.empty()){
        string f = rrsch.front();
        rrsch.pop();
        if(task[f]<=q){
           ans += task[f];
           cout << f << ' ' << ans << endl;
        } 
        else{
            task[f]-=q;
            ans += q;
            rrsch.push(f);
        } 
    }
}


Measured memory_bytes: 9068
ns = Hash.new 0
$<.each_line do |l|
  a, b = l.split.map(&:to_i)
  if a.zero? and b.zero?
    puts ns.each_value.count(&:odd?) == 2 && ns[1].odd? && ns[2].odd? ? 'OK' : 'NG'
    ns.clear
    next
  end
  ns[a] += 1
  ns[b] += 1
end

Measured memory_bytes: 8784
import sys
input = sys.stdin.readline

s = input()[:-1]
t = input()[:-1]
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            dp[i+1][j+1] = dp[i][j]+1
        else:
            if dp[i+1][j]>dp[i][j+1]:
                dp[i+1][j+1] = dp[i+1][j]
            else:
                dp[i+1][j+1] = dp[i][j+1]

ci, cj = len(s), len(t)
ans = []

while ci!=0 and cj!=0:
    if s[ci-1]==t[cj-1]:
        ci -= 1
        cj -= 1
        ans.append(s[ci])
    else:
        if dp[ci][cj]==dp[ci-1][cj]:
            ci -= 1
        else:
            cj -= 1

ans.reverse()
print(''.join(ans))

Measured memory_bytes: 112220
#include <iostream>
#include <algorithm> //min
typedef long long ll;

using namespace std;

int main() {

	ll L, R;
	cin >> L >> R;

	//余りは最大でも2018
	int mod_min = 2018;

	//余りは2019周期でパターンが同じなのでRの範囲を縮める
	R = min(R, L + 4038);

	for (ll i = L; i <= R; i++)
	{
		for (ll j = i + 1; j <= R; j++)
		{

			int mod = (i * j) % 2019;
			//cout << mod << "\n";

			mod_min = min(mod_min, mod);
			//if (mod < mod_min) {
			//	mod_min = mod;
			//}
		}
	}

	cout << mod_min << endl;

	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

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

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

using namespace std;

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main(void){
    string a, b, c, d, e;
    vector<pair<int, int>> l;

    cin >> a >> b >> c >> d >> e;
    
    int len = a.length();
    char o = a[len-1];
    l.push_back(make_pair(ctoi(o), (int)atoi(a.c_str())));
    len = b.length();
    o = b[len-1];
    l.push_back(make_pair(ctoi(o), (int)atoi(b.c_str())));
    len = c.length();
    o = c[len-1];
    l.push_back(make_pair(ctoi(o), (int)atoi(c.c_str())));
    len = d.length();
    o = d[len-1];
    l.push_back(make_pair(ctoi(o), (int)atoi(d.c_str())));
    len = e.length();
    o = e[len-1];
    l.push_back(make_pair(ctoi(o), (int)atoi(e.c_str())));

    sort(l.rbegin(), l.rend());

    int ans = 0;
    int u = 10;
    for(int i = 0; i < 5; i++){
        if(l[i].first != 0){
            ans += l[i].second + 10 - l[i].first;
            if(l[i].first < u) u = l[i].first;
        }
        else{
            ans += l[i].second;
        }
    }
    ans -= 10;
    ans += u;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

int a[100010],k,n,dis[100010],ans,in[100010],cnt,f[100010];
struct edge{int to,lt;}e[100010];bool vis[100010];

void addedge(int x,int y)
{
	e[++cnt].to=y;e[cnt].lt=in[x];in[x]=cnt;
}

void dfs(int x,int fa)
{
	vis[x]=1;f[x]=1;
	for(int i=in[x];i;i=e[i].lt)
	{
		int v=e[i].to;
		if(v==fa||vis[v])	continue;
		dis[v] = dis[x]+1;
		dfs(v,x);f[x]=max(f[x],f[v]+1);
	}
	if(dis[x]>1&&f[x]>=k){f[x]=0;ans++;}
}

int main()
{
	int i,j,x,y;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(i!=1)	addedge(a[i],i);
	}
	dfs(1,1);
	if(a[1]!=1)	ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7296
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<int> A;
int main()
{
    cin >> N;
    A.resize(N);
    for (auto &val : A)
    {
        cin >> val;
    }
    int left = 0;
    int right = 0;
    int value = 0;
    ll result = 0;
    while (left < N)
    {
        while (right < N)
        {
            int res = value & A[right];
            if (res == 0)
            {
                int len = right - left + 1;
                result += len;
                // cerr << left << " " << right << " " << result << endl;
                value ^= A[right++];
            }
            else
            {
                break;
            }
        }
        value ^= A[left];
        left++;
    }
    
    // ll len = right - left;

    cout << result << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int Mod=1e9+7,N=1e5+10;
#define pb push_back
#define f first
#define s second
int n,a[N],dp[N];
int main()
{
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  dp[1]=0,dp[2]=abs(a[2]-a[1]);
  for(int i=3;i<=n;i++) dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  cout<<dp[n]<<endl;
  return 0;
}


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

    using namespace std;

    bool visited[100005];
    int path[100005];
    vector<int>adj[100005];
    queue<pair<int,int>>q;

    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        memset(visited,sizeof(visited),false);
        int n,m;
        cin>>n>>m;
        int x,y;
        bool flag=false;
        for(int i=0;i<m;i++){
            cin>>x>>y;
            adj[x].push_back(y);
            adj[y].push_back(x);
            if(x==1 || y==1)
                flag=true;
        }
        if(!flag){
            cout<<"NO";
            return 0;
        }
        q.push({1,1});
        while(q.size()){
            auto k=q.front();
            q.pop();
            int x=k.first;
            int y=k.second;
//            cout<<x<<" "<<y<<"\n";
            if(!visited[x]){
                visited[x]=true;
                for(int i=0;i<adj[x].size();i++){
                    q.push({adj[x][i],x});
                    if(path[adj[x][i]]==0)
                        path[adj[x][i]]=x;
                }
            }
        }
        cout<<"Yes"<<"\n";
        for(int i=2;i<=n;i++)
            cout<<path[i]<<"\n";
        return 0;
    }


Measured memory_bytes: 12096
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
using namespace std;
const int N=400010;
int fa[N],pa[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
struct Dat {
    int x,y,id;
    inline bool operator < (const Dat &A) const {
	return 1LL*y*A.x==1LL*x*A.y?id<A.id:1LL*x*A.y<1LL*y*A.x;
    }
} g[N];
set <Dat> W;
inline int find(int x) {return pa[x]==x?x:pa[x]=find(pa[x]);}
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) pa[i]=i;
    for(int i=2;i<=n;i++) fa[i]=gi();
    for(int i=1;i<=n;i++)
	g[i]=(Dat){gi(),1,i},W.insert(g[i]);
    long long ans=0;
    while(!W.empty()) {
	Dat t=*W.begin(),k;W.erase(t);
	int x=find(fa[t.id]);
	if(!x) continue;
	ans+=1LL*(t.y-t.x)*g[x].x;
	W.erase(g[x]),k=t;
	k.x+=g[x].x,k.y+=g[x].y,k.id=++n;
	pa[n]=pa[x]=n,pa[find(t.id)]=n;
	fa[n]=fa[x],fa[t.id]=n;
	g[n]=k,W.insert(k);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 20608
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7 ;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
 
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%MOD,e/2);
    return e%2==0 ? temp : (temp*n)%MOD;
}
int LIM=2e5+100;
v64 fact(LIM,1);
v64 inverse(LIM,1);
ll choose(int n,int r)
{
    if (r>n)
        return 0;
    ll ans=(fact[n]*inverse[r])%MOD;
    ans=(ans*inverse[n-r])%MOD;
    return ans;
}
void norm(ll &n)
{
    n%=MOD;
    n+=MOD;
    n%=MOD;
}
void solve()
{
    // cout <<choose(5,2)<<endl;
    int n,k;
    cin>>n>>k;
    v64 arr(n);
    for (int i=0; i<n; i++)
        cin>>arr[i];
    sort(all(arr));
    ll ans=0;
    map<ll,ll> counter;
    for (int i=0; i<n; i++)
        counter[arr[i]]++;
    ll sum=0;
    for (auto it=counter.begin(); it!=counter.end(); it++)
    {

        ll a=sum;
        ll b=it->second;
        for (int j=1; j<=b; j++)
        {
            ll temp=choose(n-a-b,k-j);
            // cout << it->first<<" "<< it->second<<" "<<ans<<" "<< temp<<" "<<choose(2,1)<<endl;
            ll t2=choose(a,k-j);
            temp=(t2-temp+MOD)%MOD;
            temp=(temp*choose(b,j))%MOD;
            norm(temp);
            ans=(ans+temp*it->first)%MOD;
            norm(ans);
        }
        sum+=it->second;
        // ll a=sum+it->second;
        // ll temp=((choose(a-1,k-1)*(it->first))%MOD);
        // temp=(temp*it->second)%MOD;
        // ans=ans+((choose(a-1,k-1)*(it->first))%MOD);
        // ans%=MOD;
        // ans+=MOD;
        // ans%=MOD;
        // ans=ans-(choose(n-a-1,k-1)*(it->first))%MOD;
        // ans%=MOD;
        // ans+=MOD;
        // ans%=MOD;
        // sum=a;
    }
    cout <<ans<<endl;
}
 
int main() {
    fast_cin();
    int t=1;
    // cin >> t;
    for (int i=1; i<LIM; i++)
    {
        fact[i]=(fact[i-1]*i)%MOD;
        inverse[i]=exp(fact[i],MOD-2);
    }
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 9984
#include <stdio.h>
#include <string.h>

#define MAX 100

void findCube(int s[MAX][MAX], int top[MAX], int num, int *pile, int *height);
void fallCube(int s[MAX][MAX], int top[MAX], int pile, int height);
void newPile(int s[MAX][MAX], int top[MAX], int num);

int main ( void ) {
	int i, j;
	int n, from, to;
	int s[MAX][MAX], top[MAX];
	int tmp;
	int pa, ha, pb, hb;

	while(1){
		scanf("%d",&n);
		if(n == 0) break;

		memset(top,0,sizeof(top));
		for(i=0;i<n;i++){
			top[i] = 1;
			s[i][0] = i+1;
		}

		while(1){
			scanf("%d%d",&from,&to);
			if(from == 0 && to == 0) break;

			findCube(s,top,from,&pa,&ha);
			findCube(s,top,to,&pb,&hb);

			if(to == 0){
				if(ha == 0) continue;
				fallCube(s,top,pa,ha);
				tmp = s[pa][--top[pa]];
				newPile(s,top,tmp);
			}

			else if(pa == pb && ha < hb){
				fallCube(s,top,pa,ha);
				tmp = s[pa][--top[pa]];
				findCube(s,top,to,&pb,&hb);
				s[pb][top[pb]++] = tmp;
			}

			else if(pa != pb){
				fallCube(s,top,pa,ha);
				tmp = s[pa][--top[pa]];
				s[pb][top[pb]++] = tmp;				
			}
		}

		for(i=0;i<MAX-1;i++){
			for(j=i+1;j<MAX;j++){
				if(top[i] > top[j]){
					tmp = top[i];
					top[i] = top[j];
					top[j] = tmp;
				}
			}
		}

		for(i=0;i<MAX;i++){
			if(top[i] > 0) printf("%d\n",top[i]);
		}
		printf("end\n");
	}

	return 0;
}

void findCube(int s[MAX][MAX],int top[MAX],int num,int *pile,int *height){
	int i,j;

	for(i=0;i<MAX;i++){
		for(j=0;j<top[i];j++){
			if(s[i][j] == num){
				*pile = i;
				*height = j;
				return;
			}
		}
	}

	*pile = *height = -1;
}

void fallCube(int s[MAX][MAX],int top[MAX],int pile,int height){
	int tmp;

	while(top[pile] > height + 1){
		tmp = s[pile][--top[pile]];
		newPile(s,top,tmp);
	}
}

void newPile(int s[MAX][MAX],int top[MAX],int num){
	int i;

	for(i=0;i<MAX;i++){
		if(top[i] == 0){
			s[i][top[i]++] = num;
			return;
		}
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int top,S[1000];

void push(int);
int pop();

int main(){

  int x,y;
  top=0;
  char s[100];

  while( scanf("%s",s) != EOF){
    if( s[0] == '+'){
      x = pop();
      y = pop();
      push(x+y);
    }
    else if( s[0] == '-'){
      x = pop();
      y = pop();
      push(y-x);
    }
    else if( s[0] == '*'){
      x = pop();
      y = pop();
      push(x*y);
    }
    else push(atoi(s));
  }
  printf("%d\n",pop());
  return 0;
}

void push(int t){
  S[++top] = t;
}

int pop(){
  top--;
  return S[top+1];
}



Measured memory_bytes: 2108
N,K = map(int,input().split())

nmin = N

if N < K:
    for i in range(5):
        N = abs(N-K)
        if N < nmin:
            nmin = N
    print(nmin)
elif N == K:
    print(0)
else:
    n = N % K
    print(min(n,K-n))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

void solve()
{
    int n;
    cin >> n;
    int cnt[4] = {};
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        if (s == "AC") {
            ++cnt[0];
        } else if (s == "WA") {
            ++cnt[1];
        } else if (s == "TLE") {
            ++cnt[2];
        } else {
            ++cnt[3];
        }
    }
    cout << "AC x " << cnt[0] << '\n';
    cout << "WA x " << cnt[1] << '\n';
    cout << "TLE x " << cnt[2] << '\n';
    cout << "RE x " << cnt[3] << endl;
}

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

    /* int T; */
    /* cin >> T; */
    /* for (int t = 0; t < T; ++t) { */
        solve();
    /* } */
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 1e2 + 10;

int n, k, a[N], b[N], ans;

int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    for (int rock = 1; rock <= min(n,k); ++rock) {
        for (int l = 0; l <= rock; ++l) {
            int res = 0, ct = 0, tmp = k - rock;
            for (int i = 0; i < l; ++i) b[ct++] = a[i];
            for (int i = n-1; i >= n - rock + l; --i) b[ct++] = a[i];
            sort(b, b + ct);
            for (int i = 0; i < min(tmp, ct); ++i) if (b[i] < 0) b[i] = 0; else break;
            for (int i = 0; i < ct; ++i) res += b[i];
            ans = max(ans, res);
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong r,d,x;
    cin >> r >> d >> x;
    rep(i,10){
        x = r*x - d;
        cout << x << endl;
    }
}

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

typedef struct
{
  double x;
  double y;
}Point;


int kock(int n,Point p1,Point p2)
{
  Point s,t,u;

  if(n == 0)
    {
      return ;
    }
  
  s.x = (2*p1.x + 1*p2.x)/3;
  s.y = (2*p1.y + 1*p2.y)/3;
  t.x = (1*p1.x + 2*p2.x)/3;
  t.y = (1*p1.y + 2*p2.y)/3;
  u.x = (t.x - s.x)*cos(M_PI*60/180) - (t.y - s.y)*sin(M_PI*60/180) + s.x;
  u.y = (t.x - s.x)*sin(M_PI*60/180) + (t.y - s.y)*cos(M_PI*60/180) + s.y;
  
  
  kock(n -1,p1,s);
  printf(" %.8lf %.8lf\n",s.x,s.y);
  kock(n - 1,s,u);
  printf(" %.8lf %.8lf\n",u.x,u.y);
  kock(n - 1,u,t);
  printf(" %.8lf %.8lf\n",t.x,t.y);
  kock(n - 1,t,p2);
  
}

int main()
{
  int n;

  Point P1 = {0,0};
  Point P2 = {100,0};
  

  scanf("%d",&n);
  
  printf(" %.8lf %.8lf\n",P1.x,P1.y);
  kock(n,P1,P2);
  printf(" %.8lf %.8lf\n",P2.x,P2.y);

  return 0;
}



Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t m,b,c,j,ans=0;
  cin>>m>>b>>c;
  vector<int64_t> x(m);
  for(j=0;j<m;j++) cin>>x.at(j);
  for(j=1;j<m;j++) ans+=min(b*(x.at(j)-x.at(j-1)),c);
  cout<<ans<<endl;
}

Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

struct Entry {
	Entry(){ }
	Entry(const Entry &obj) : name(obj.name), w(obj.w), s(obj.s) { }
	Entry &operator=(const Entry &obj){ name = obj.name; w = obj.w; s = obj.s; return *this; }
	string name;
	int w, s;
};

struct WeightComparator {
	bool operator()(const Entry &a, const Entry &b){ return a.w < b.w; }
};

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<Entry> entries;
		int wsum = 0;
		while(n--){
			Entry e;
			cin >> e.name >> e.w >> e.s;
			wsum += e.w;
			entries.push_back(e);
		}
		priority_queue<Entry, vector<Entry>, WeightComparator> q;
		while(!entries.empty() || !q.empty()){
			vector<Entry>::iterator it = entries.begin();
			while(it != entries.end()){
				if((*it).s >= wsum - (*it).w){
					q.push(*it);
					it = entries.erase(it);
				}else{
					++it;
				}
			}
			wsum -= q.top().w;
			cout << q.top().name << endl;
			q.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 0
//ALDS1-1-D: Maximum Profit
//2019.05.24

#include <stdio.h>

int main(void){
  int n, t;
  int rt, rj;
  int min_present = 1000000000;
  int max_profit = -1000000000+1;

  scanf("%d\n", &n);
  scanf("%d\n", &rj);
  min_present = rj;
  for (t = 1; t < n; t++) {
    scanf("%d\n", &rt);
    if (rj < min_present) min_present = rj;
    if (max_profit < rt - min_present) max_profit = rt - min_present;
    rj = rt;
  }
  printf("%d\n", max_profit);

  return 0;
}



Measured memory_bytes: 2104
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
  int a,b;
  cin>>a>>b;
  int c,d,e;
  c=a+b;
  d=a-b;
  e=a*b;
  cout<<max(c,max(d,e))<<endl;
  return 0;
}

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ABeginner {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, R;
        cin >> N >> R;
        if (N >= 10) {
            cout << R << endl;
        } else {
            cout << R + 100 * (10 - N) << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ABeginner solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
# A - ><
S = input()
N = len(S)+1
INF = 1000000
ans = [0]*N
tmp = 0
for i in range(N-1):
    if S[i]=='<':
        tmp += 1
    else:
        tmp = 0
    ans[i+1] = tmp
tmp = 0
for i in range(N-2,-1,-1):
    if S[i]=='>':
        tmp += 1
    else:
        tmp = 0
    ans[i] = max(ans[i],tmp)
print(sum(ans))

Measured memory_bytes: 23336
#include <stdio.h>

int main()
{
  int n, x, y, i, j;
  
  scanf("%d", &n);
  
  if (n == 2) {
    puts("-1");
    return 0;
  }
  
  if (n == 3) {
    puts("aa.");
    puts("..a");
    puts("..a");
    return 0;
  }
  
  x = n / 4 - 1;
  y = n % 4 + 4;
  
  for (i = 0; i < x; i++) {
    for (j = i; j > 0; j--)
      printf("....");
    printf("aabc");
    for (j = x-i-1; j > 0; j--)
      printf("....");
    for (j = y; j > 0; j--)
      putchar('.');
    putchar('\n');
    
    for (j = i; j > 0; j--)
      printf("....");
    printf("ddbc");
    for (j = x-i-1; j > 0; j--)
      printf("....");
    for (j = y; j > 0; j--)
      putchar('.');
    putchar('\n');
    
    for (j = i; j > 0; j--)
      printf("....");
    printf("bcaa");
    for (j = x-i-1; j > 0; j--)
      printf("....");
    for (j = y; j > 0; j--)
      putchar('.');
    putchar('\n');
    
    for (j = i; j > 0; j--)
      printf("....");
    printf("bcdd");
    for (j = x-i-1; j > 0; j--)
      printf("....");
    for (j = y; j > 0; j--)
      putchar('.');
    putchar('\n');
  }
  
  if (y == 4) {
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("aabc\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("ddbc\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("bcaa\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("bcdd\n");
  }
  
  if (y == 5) {
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("aabba\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("bcc.a\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("b..cb\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("a..cb\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("abbaa\n");
  }
  
  if (y == 6) {
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("aabc..\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("ddbc..\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("..aabc\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("..ddbc\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("bc..aa\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("bc..dd\n");
  }
  
  if (y == 7) {
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("aabbcc.\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("dd.dd.a\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("..d..da\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("..d..db\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("dd.dd.b\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("..d..dc\n");
    
    for (i = 4*x; i > 0; i--)
      putchar('.');
    printf("..d..dc\n");
  }
  
  return 0;
}

Measured memory_bytes: 1152
# https://atcoder.jp/contests/abc057/tasks/abc057_c
# なるべく√Nに近い約数を2つ探し、それにF(A,B)を適応すればよい


def F(A, B):
    return max(len(str(A)), len(str(B)))


N = int(input())
from math import sqrt

ans = 11
for i in range(1, int(sqrt(N)) + 1):
    if N % i == 0:
        ans = min(ans, F(N // i, i))
print(ans)


Measured memory_bytes: 39280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge*i=G[x];i;i=i->nxt)
typedef long long ll;
typedef pair<int,int> pii;
const int inf=~0u>>1,MOD=1e9+7;
inline int rd() {
    int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
const int N=1e5+11;
int n,a[N],b[N];
int f[N],g[N];
int main(){
	n=rd();
	rep(i,1,n)a[i]=rd();
	rep(i,1,n)b[i]=rd();
	f[1]=a[1];
	rep(i,2,n)f[i]=f[i-1]+a[i];
	rep(i,1,n)g[i]=max(g[i-1],f[i])+b[i];
	cout<<g[n]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;
  ll a = n % k;
  cout << min(a, abs(a - k)) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
   int x,n;
   scanf("%d %d",&x,&n);
   if(n == 0)
      printf("%d", x);
   else
   {
      int p[n];
      int marcador = 0, menos = 1, mais = 1;
      int gambiarraMenos = 0, gambiarraMais = 0;
      for(int i = 0; i<n; i++)
      {
         scanf(" %d", &p[i]);
         if(p[i] == x)
            marcador = 1;
      }
      for(int j=0;;j++)
      {
         gambiarraMenos = 0;
         gambiarraMais = 0;
         for(int i=0; i<n; i++)
         {
            if(marcador == 0)
            {
               printf("%d", x);
               return 0;
            }
            else
            {
               if(x-menos == p[i])
               {
                  menos++;
                  gambiarraMenos = 1;
                  gambiarraMais = 1;
                  break;
               }
               else if(x+mais == p[i])
               {
                  mais++;
                  gambiarraMais = 1;
                  gambiarraMenos = 1;
                  break;
               }
            }
         }
         if(gambiarraMenos == 0 && menos <= mais)
         {
               printf("%d\n", x-menos);
               return 0;
         }
         else if(gambiarraMais == 0 && mais < menos)
         {
               printf("%d\n", x+mais);
               return 0;
         }
      }
   }
   return 0;
}


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

struct Task
{
    char name[10];
    int rtime;
};


Task task[100000];
int head,tail,n,q,len=100000;

void unit()
{
    head=0;
    tail=0;
    cin>>n>>q;
}
void enquene(Task t)
{
    task[tail]=t;
    tail=(tail+1)%len;
}

Task dequene()
{
    Task t=task[head];
    head=(head+1)%len;
    return t;
}

int main()
{
    unit();
    Task t;
    int ftime=0;
    for(int i=0; i<n; i++)
    {
        cin>>t.name;
        cin>>t.rtime;
        enquene(t);

    }
    while(head!=tail)
    {
        t=dequene();
        if(t.rtime>q)
        {
            t.rtime-=q;
            ftime+=q;
            enquene(t);
        }
        else
        {
            ftime+=t.rtime;
            cout<<t.name<<" "<<ftime<<endl;
        }

    }
    return 0;
}





Measured memory_bytes: 4640
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def divisor(n):
        i = 1
        table = []
        while i * i <= n:
            if n % i == 0:
                table.append(i)
                table.append(n // i)
            i += 1
        table = list(set(table))
        return table


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)

    def list(self):
        return self.__q

    def length(self):
        return len(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e30)


def main():
    # sys.stdin = open("Sample.txt")
    A, B, C, X, Y = Scanner.map_int()
    C *= 2
    ans = 0
    if A + B > C:
        a = min(X, Y)
        ans += a * C
        X -= a
        Y -= a
    if A < C:
        ans += A * X
    else:
        ans += C * X
    if B < C:
        ans += B * Y
    else:
        ans += C * Y
    print(ans)
    return


if __name__ == "__main__":
    main()


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

//頂点数がn,枝数がm
//bellman_ford bf(n,m);
//適宜add_edge
//bf.comp(出発点)でdに最短路長が入る
//負の有向閉路には3種類存在することに注意する

template<typename T> class BellmanFord {
public:
  struct edge {
    int from, to;
    T cost;
  };
  int V;
  T inf;
  vector<T> d;
  vector<edge> es;
  BellmanFord(int node_size) : V(node_size), inf(numeric_limits<T>::max() / 2), d(V, inf) {}
  void add(int from, int to, T cost) {
    es.push_back((edge) {from, to, cost});
  }
  //sからの最短路長およびsからたどり着ける負の閉路の検出(trueなら負の閉路が存在する)
  bool solve(int s) {
    int cnt = 0;
    d[s] = 0;
    while (cnt < V) {
      bool update = false;
      for (auto& e : es) {
        if (d[e.from] != inf && d[e.to] > d[e.from] + e.cost) {
          d[e.to] = d[e.from] + e.cost;
          update = true;
        }
      }
      if (!update) break;
      cnt++;
    }
    return (cnt == V);
  }
  //すべての負の閉路の検出(trueなら負の閉路が存在する)
  bool find_negative_loop() {
    fill(d.begin(), d.end(), (T)0);
    int cnt = 0;
    while (cnt < V) {
      bool update = false;
      for (auto& e : es) {
        if (d[e.to] > d[e.from] + e.cost) {
          d[e.to] = d[e.from] + e.cost;
          update = true;
        }
      }
      if (!update) break;
      cnt++;
    }
    return (cnt == V);
  }
  // s, t 間の最短距離が非有界
  bool shortest_path_infinite(int s, int t) {
    d[s] = 0;
    for (int i = 0; i < 2 * V - 1; i++) {
      for (auto& e : es) {
        if (d[e.from] != inf && d[e.to] > d[e.from] + e.cost) {
          d[e.to] = d[e.from] + e.cost;
          if (i >= V-1) {
            if (e.to == t) return true;
            d[e.to] = -inf;
          }
        }
      }
    }
    return false;
  }
};

int main() {
  ios::sync_with_stdio(false);
  int N, M, P;
  cin >> N >> M >> P;
  BellmanFord<long> BF(N);
  for (int i = 0; i < M; i++) {
    int A, B, C;
    cin >> A >> B >> C;
    BF.add(--A, --B, P - C);
  }
  if (BF.shortest_path_infinite(0, N - 1)) return cout << -1 << "\n", 0;
  cout << max(0L, -BF.d.at(N - 1)) << "\n";
}

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

int main() {
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    int x = x2 - x1;
    int y = y2 - y1;
    cout << x2 - y << " " << y2 + x << " " << x1 - y << " " << y1 + x << endl;
}


Measured memory_bytes: 3564
import sys
from collections import deque

read = sys.stdin.buffer.read


def main():
    N, Q, *ABPX = map(int, read().split())

    A = ABPX[0 : 2 * N - 2 : 2]
    B = ABPX[1 : 2 * N - 2 : 2]
    P = ABPX[2 * N - 2 :: 2]
    X = ABPX[2 * N - 1 :: 2]

    G = [[] for _ in range(N)]
    for a, b in zip(A, B):
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)

    Y = [0] * N
    for p, x in zip(P, X):
        Y[p - 1] += x

    C = [0] * N
    C[0] = Y[0]
    seen = [False] * N
    stack = deque([0])

    while stack:
        v = stack.pop()
        seen[v] = True
        for nv in G[v]:
            if not seen[nv]:
                stack.append(nv)
                C[nv] = C[v] + Y[nv]

    print(*C)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 101408