akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18

#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

class LazySegTree{
private:
	int n;
	vector<ll> node, lazy;
	vector<bool> lazyFlag;
public:
	LazySegTree(vector<ll> v){
		int sz = v.size();
		n = 1; while(n < sz) n *= 2;
		node.resize(2*n-1, 0);
		lazy.resize(2*n-1, 0);
		lazyFlag.resize(2*n-1, false);
		REP(i, sz) node[i+n-1] = v[i];
		for(int i = n-2;i >= 0;i--) node[i] = node[2*i+1]+node[2*i+2];
	}

	void eval(int k, int l, int r){
		if(lazyFlag[k]){
			node[k] += lazy[k] * (r-l);
			if(r-l > 1){
				lazy[2*k+1] += lazy[k];
				lazy[2*k+2] += lazy[k];
				lazyFlag[2*k+1] = lazyFlag[2*k+2] = true;
			}
			lazy[k] = 0;
			lazyFlag[k] = false;
		}
	}

	void add(int a, int b, ll x, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;
		eval(k, l, r);
		if(b <= l || r <= a) return;

		if(a <= l && r <= b){
			lazy[k] += x;
			lazyFlag[k] = true;
			eval(k, l, r);
		}else{
			add(a, b, x, k*2+1, l, (l+r)/2);
			add(a, b, x, k*2+2, (l+r)/2, r);
			node[k] = node[k*2+1] + node[k*2+2];
		}
	}

	ll query(int a, int b, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;
		eval(k, l, r);

		if(b <= l || r <= a) return 0;
		if(a <= l && r <= b) return node[k];

		return query(a, b, k*2+1, l, (l+r)/2) + query(a, b, k*2+2, (l+r)/2, r);
	}
};


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

	int N;
	int a = 0, b = 0;
	cin >> N;
	REP(i, N){
		int A, B;
		cin >> A >> B;
		if(a < A){
			a = A;
			b = B;
		}
	}
	cout << a+b << endl;
}


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

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    ll n;
    cin >> n ;
    ll maxi = 0;
    ll sum = 0;
    for (int z=0;z<n;z++) {
    	ll temp;
    	cin >> temp;
    	sum += temp;
    	maxi = max(maxi,temp);
    }
    if (maxi < sum-maxi) cout << "Yes" << endl;
    else cout << "No" << endl;
    cin >> n;
}


Measured memory_bytes: 256
sub parin {
    $s = @_[0];
    return $s eq reverse($s);
}

use integer;
$s = <>;
chop($s);
$n = length($s);
print parin($s)
  && parin(substr($s, 0, ($n - 1) / 2))
  && parin(substr($s, ($n + 1) / 2))
  ? Yes
  : No

Measured memory_bytes: 4708
#include <iostream>
#include <algorithm>

#define SIZE 200000

using namespace std;

int main() {
    long long int A,B,i,j,k,N,M,K,Q,X;
  //  long long int A[100][100];

  cin >> X;
  if (X < 30)
    cout << "No" << endl;
  else
     cout << "Yes" << endl;

    return 0;


}


Measured memory_bytes: 3628
Option Infer On
Imports System.Collections.Generic
Imports System.Console
Imports System.Math

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim lowest = Integer.MaxValue
        Dim highest = Integer.MinValue

        For i = 0 To N - 1
            Dim ai = NextInt()
            lowest = Min(lowest, ai)
            highest = Max(highest, ai)
        Next

        WriteLine(highest - lowest)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 20316
# -*- coding: utf-8 -*-
import sys
import queue
input = sys.stdin.readline
def ii(): return int(input().rstrip())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    n = ii()
    g = [[] for i in range(n)]
    for i in range(n - 1):
        a, b = mi()
        g[a - 1].append((b - 1, i))
        g[b - 1].append((a - 1, i))
    color = max([len(g[i]) for i in range(n)])
    print(color)
    q = queue.Queue()
    ans = [-1 for i in range(n - 1)]
    idx = 0
    q.put((0, 0))
    while not q.empty():
        t, idx = q.get()
        for e in g[t]:
            if ans[e[1]] != -1:
                continue
            idx += 1
            ans[e[1]] = idx
            q.put((e[0], idx))
    print(*map(lambda x: x % color + 1, ans), sep="\n")
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 79388
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
  int t1=0,t0=0;
  rep(i,s.length())
  {
    if(i&1)t1+=s[i]-'0';
    else t0+=s[i]-'0';
  }
  int l=s.length();
  cout<<min(l/2-t1+t0,l-l/2-t0+t1)<<endl;

  return 0;

}


Measured memory_bytes: 512
#include<algorithm>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<stack>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
const double PI = acos(-1);  // PI = 3.141593...

int main() {
    int n;
    cin >> n;
    vector<int> b(n-1);
    rep(i, n-1) cin >> b[i];

    int ans = b[0] + b[n-2];
    for(int i = 0; i < n-2; ++i) {
        ans += min(b[i], b[i+1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<array>
#include<list>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<functional>
#include<memory>

using namespace std;

using ll = unsigned long long;

using vec = vector<int>;
using mat = vector<vec>;


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

	vec A(N);

	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	sort(A.begin(), A.end());

	if (N % 2 == 0)
	{
		ll ans = 0;

		for (int i = 0; i < N; ++i)
		{
			ans += 2 * ((i < N / 2) ? (-A[i]) : A[i]);
		}
		ans += A[N / 2 - 1];
		ans -= A[N / 2];

		cout << ans << endl;

		return 0;
	}


	ll ansA = 0, ansB = 0;

	for (int i = 0; i < N; ++i)
	{
		ansA += 2 * ((i < N / 2) ? (-A[i]) : A[i]);
		ansB += 2 * ((i > N / 2) ? A[i] : (-A[i]));
	}

	ansA -= A[N / 2] + A[N / 2 + 1];
	ansB += A[N / 2] + A[N / 2 - 1];

	cout << ((ansA > ansB) ? ansA : ansB) << endl;

	return 0;
}

Measured memory_bytes: 640
N,W = map(int, input().split())
VW  = [list(map(int, input().split())) for _ in range(N)]
VW  = sorted(VW, key=lambda x:x[1])
# print(VW)
# exit()

dp = [0] * (W+1) # $B2ACM$N:GBgCM(B

for i in range(W):
    for v,w in VW:
        # print(i,v,w)
        if i+w <= W:
            dp[i+w] = max(dp[i+w], dp[i]+v) 

# print( (dp) )
print( max(dp) )



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

int main(){
	
	string s;
	int n,f;
	cin>>s>>n;
	int k=s[0]-'0';
	for(int i=1;i<s.size();i+=2){
		if(s[i]=='+')k+=(s[i+1]-'0');
		else k*=(s[i+1]-'0');
	}
	f=(k==n);
	int a=s[0]-'0',c=0;
	for(int i=1;i<s.size();i+=2){
		if(s[i]=='+'){
			c+=a;
			a=s[i+1]-'0';
		}
		else{
			a*=(s[i+1]-'0');
		}
	}
	c+=a;
	f+=(2*(c==n));
	cout<<"ILMU"[f]<<endl;
	
	return 0;
}


Measured memory_bytes: 1196
#include<cstdio>
#include<algorithm>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
#define MAX 100
#define INFTY (1<<21)
int n, m, G[MAX][MAX], E[MAX*MAX];

int eprim( int base ){
    int d[MAX];
    bool visited[MAX];
    rep(i, n){ d[i] = INFTY; visited[i] = false;}
    d[0] = 0;
    int cnt = 0, ans = 0;

    while(1){
	int u, minv = INFTY;
	rep(i, n){
	    if ( !visited[i] && minv > d[i]){
		minv = d[i]; u = i;
	    }
	}
	if ( minv == INFTY ) break;
	if ( u != 0 && ans < minv ) ans = minv;
	cnt++;
	visited[u] = true;
	rep(v, n){
	    if ( visited[v] || G[u][v] == INFTY || base > G[u][v]) continue;
	    d[v] = min( d[v], G[u][v] - base );
	}
    }
    return ( cnt != n )?INFTY:ans;
}

void compute(){
    int minv = INFTY;
    rep(i, m) minv = min ( minv, eprim(E[i]) );
    printf("%d\n", (minv == INFTY)?-1:minv);
}

main(){
    int s, t, e;
    while(1){ 
	scanf("%d %d", &n, &m);
	if ( n == 0 && m == 0 ) break;
	rep(i, n) rep(j, n) G[i][j] = INFTY;
	rep(i, m){
	    scanf("%d %d %d", &s, &t, &e);s--; t--;
	    G[s][t] = G[t][s] = E[i] = e;
	}
	compute();
    }
}

Measured memory_bytes: 816
W,H,N=map(int,input().split())
x_max=W
x_min=0
y_max=H
y_min=0
for i in range(N):
  x,y,a=map(int,input().split())
  if a==1:
    if x>x_min:
      x_min=x
  elif a==2:
    if x<x_max:
      x_max=x
  elif a==3:
    if y>y_min:
      y_min=y
  else:
    if y<y_max:
      y_max=y
if x_min>x_max or y_min>y_max:
  print(0)
else:
  print((x_max-x_min)*(y_max-y_min))

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

int main(void){
    int i,str_length,flag,j;
    string s;
    flag = 0;

    cin >> s;
    str_length = s.size();


    for(i=0; i<str_length - 1; i++){
        for(j=i+1; j<str_length; j++){
            if(s.at(i) == s.at(j)){
                flag = 1;
                break;
            }

        }
        if(flag == 1)   break;
    }

    if(flag == 0){
        cout << "yes" << endl;
    }else if(flag == 1){
        cout << "no" << endl;
    }else{
        cout << "=)"<< endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */



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

    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) { cin >> p[i]; }
    int ans = 0;
    int minv = 10000000;
    rep(i, n) {
        if (p[i] <= minv) ++ans;
        chmin(minv, p[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        a: [usize; n + 1],
    }
    let mut acc = a.clone();
    for i in (0..n).rev() {
        acc[i] += acc[i + 1];
    }

    let mut b = vec![0usize; n + 1];
    if a[0] > 1 {
        println!("-1");
        return;
    }
    b[0] = 1 - a[0];

    for i in 1..n {
        if 2 * b[i - 1] < a[i] {
            println!("-1");
            return;
        }
        b[i] = min(acc[i + 1], 2 * b[i - 1] - a[i]);
    }
    if n > 0 && 2 * b[n - 1] < a[n] {
        println!("-1");
        return;
    }
    // eprintln!("{:?}", acc);
    // eprintln!("{:?}", b);
    println!("{}", (0..=n).map(|i| a[i] + b[i]).sum::<usize>());
}


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

using namespace std;

#define ll long long
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cmax(a,b)		a = max (a, b)
#define cmin(a,b)		a = min (a, b)
#define cadd(a,b)		a = add (a, b)
#define cpop(a,b)		a = pop (a, b)
#define cmul(a,b)		a = mul (a, b)
#define pii			pair<int, int>
#define fi			first
#define se			second

const int MAXN = 205;
const int oo = 0x3f3f3f3f;
const int mod = 998244353;

pii operator + (const pii &a, const pii &b) {return make_pair(a.fi + b.fi, a.se + b.se);}
pii operator - (const pii &a, const pii &b) {return make_pair(a.fi - b.fi, a.se - b.se);}
int operator ^ (const pii &a, const pii &b) {return a.fi * b.se - a.se * b.fi;}

inline int add(int a, int b){a += b; return a >= mod ? a - mod : a;}
inline int pop(int a, int b){a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b){return 1LL * a * b % mod;}

int N, f[MAXN], C[MAXN][MAXN], nodes[MAXN], top = 0, ans = 0;
pii a[MAXN];
bool vaild[MAXN][MAXN];

void calc(int x, int y) {
	top = 0; nodes[++top] = x; nodes[++top] = y;
	up (i, 1, N) if (i != x && i != y) {
		if (((a[i] - a[x]) ^ (a[i] - a[y])) == 0) nodes[++top] = i;	
	}
	cpop(ans, f[top]);
	up (i, 1, top) up (j, 1, top) vaild[nodes[i]][nodes[j]] = vaild[nodes[j]][nodes[i]] = 0;
}

int main(){
	scanf("%d", &N);
	up (i, 1, N) scanf("%d%d", &a[i].fi, &a[i].se);
	C[0][0] = 1;
	up (i, 1, N) {
		C[i][0] = 1;
		up (j, 1, i) C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
	} 
	up (i, 3, N) up (j, 3, i) cadd(f[i], C[i][j]);
	up (i, 1, N) up (j, i + 1, N) vaild[i][j] = 1;
	ans = f[N];
	up (i, 1, N) up (j, i + 1, N) if (vaild[i][j])
		calc(i, j);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   char a, b;
   cin >> a >> b;
   if ((a == 'H' && b == 'H') || (a == 'D' && b == 'D'))
   {
      cout << "H" << endl;
   }
   else
   {
      cout << "D" << endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 1
ll getMultiple(ll num, ll d)
{
	return num/d;
}
int main()
{	
	ios_base::sync_with_stdio(0);
	ll a,b,c,d;
	while(cin>>a>>b>>c>>d){
		ll x = getMultiple(b,c) - getMultiple(a-1,c);
		ll y = getMultiple(b,d) - getMultiple(a-1,d);
		ll lcm = c/__gcd(c,d);
		lcm*=d;
		ll z = getMultiple(b,lcm) - getMultiple(a-1,lcm);
		ll total = x+y-z;
		ll ans = (b-a+1)-total;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){ 

 int a,b;
 scanf("%d%d",&a,&b);
 if(a < b){
 printf("a < b\n");
 }else if(a > b){
 printf("a > b\n");
 }else{
 printf("a == b\n");
 }
  return 0;
 } 
  

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,m,h,w,sum,val;
long long a[505][505];
int main(){
	n=read(),m=read(),h=read(),w=read();sum=n*m;
	if (n%h==0&&m%w==0){
		puts("No");
		return 0;
	}
	puts("Yes");
	if (n%h){
		for (int i=0;i<n;++i){
			for (int j=0;j<m;++j){
				if (i%h==h-1) printf ("%d ",-6666*(h-1)-1);
				else printf ("6666 ");
			}
			cout<<endl;
		}
		return 0;
	}
	else{
		for (int i=0;i<n;++i){
			for (int j=0;j<m;++j){
				if (j%w==w-1) printf ("%d ",-6666*(w-1)-1);
				else printf ("6666 ");
			}
			cout<<endl;
		}
		return 0;
	}
	/*
	a[h-1][w-1]=-1000;
	a[0][0]=999;
	long long sum=0;
	for (int i=0;i<n;++i)
		for (int j=0;j<m;++j){
			if (i>=n/h*h||j>=m/w*w) sum+=a[0][0];
			sum+=a[i%h][j%w];
		}
	if (sum<=0){
		puts("No");
		return 0;
	}
	for (int i=0;i<n;++i){
		for (int j=0;j<m;++j){
			if (i>=n/h*h||j>=m/w*w) printf ("%lld ",a[0][0]);
			else printf ("%lld ",a[i%h][j%w]);
		}
		cout<<endl;
	}*/
}


Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    int r, D, x;
    cin >> r >> D >> x;
    for(int i=0; i<10; i++){
        x = r*x-D;
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(ll i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


int h, w;
string s[55];
int cnt[55][55];
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main(void) {
	cin >> h >> w;
	rep(i, h)cin >> s[i];
	rep(i, h)rep(j, w) {
		if(s[i][j] == '#') continue;
		int d = 0;
		rep(k, 8) {
			int ny = i + dy[k], nx = j + dx[k];
			if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
			if(s[ny][nx] == '#') d++;
		}
		cnt[i][j] = d;
	}

	rep(i, h){rep(j, w) {
			if(s[i][j] == '.') printf("%d", cnt[i][j]);
			else printf("%c", s[i][j]);
		}
		printf("\n");
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i=0;i<N;i++){
    cin >> X.at(i);
  }
  sort(X.begin(),X.end());

  vector<int> P(X.at(N-1)-X.at(0)+1);
  P.at(0)=X.at(0);
  for(int i=1;i<P.size();i++){
    P.at(i)=P.at(0)+i;
  }

  vector<int> vitality(P.size(),0);
  for(int i=0;i<P.size();i++){
    for(int j=0;j<N;j++){
      vitality.at(i) += (P.at(i)-X.at(j))*(P.at(i)-X.at(j));
    }
  }
  sort(vitality.begin(),vitality.end());
  cout << vitality.at(0) << endl;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

priority_queue<ll, vector<ll>, greater<ll>> p;
priority_queue<ll, vector<ll>, greater<ll>> q;
priority_queue<ll> r;

int main()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    rep(i, a)
    {
        ll inp_p;
        cin >> inp_p;
        p.push(inp_p);
    }
    rep(i, b)
    {
        ll inp_q;
        cin >> inp_q;
        q.push(inp_q);
    }
    rep(i, c)
    {
        ll inp_r;
        cin >> inp_r;
        r.push(inp_r);
    }

    rep(j, a - x)
    {
        p.pop();
    }
    rep(j, b - y)
    {
        q.pop();
    }

    while (true) {
        if (r.size() == 0) {
            break;
        }
        if (p.top() <= r.top() && q.top() <= r.top()) {
            if (p.top() <= q.top()) {
                p.pop();
                p.push(r.top());
                r.pop();
            } else {
                q.pop();
                q.push(r.top());
                r.pop();
            }
        } else if (p.top() <= r.top()) {
            p.pop();
            p.push(r.top());
            r.pop();
        } else if (q.top() <= r.top()) {
            q.pop();
            q.push(r.top());
            r.pop();
        } else {
            break;
        }
    }

    ll sum = 0;
    rep(i, x)
    {
        sum += p.top();
        p.pop();
    }
    rep(i, y)
    {
        sum += q.top();
        q.pop();
    }

    cout << sum << endl;
}

Measured memory_bytes: 3316
//In the name of ALLAH
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
const bool DEBUG = false;
#define cerr if(DEBUG)cerr
using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long long maxn = 2e5 + 5;
const long long INF = 1e18 + 1;
const long long inf = 1e9 + 5;
const long long M = 1e9 + 7;
const int lg = 21;

ll n, b, a[maxn];

ll f(ll b){
	ll ans = 0;
	for(int i = 0; i < n; i++)
		ans += abs(a[i] - b);
	return ans;
}

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i], a[i] -= (i + 1);
	sort(a, a + n);
	cout << f(a[n / 2]) << endl;	
	return 0;
}


Measured memory_bytes: 1792
n = gets.to_i

arr = []
n.times do
  arr << gets.split.map(&:to_i)
end

arr.each do |ia|
  ia.sort!
  if ((ia[0]**2 + ia[1]**2) == ia[2]**2)
    puts 'YES'
  else
    puts 'NO'
  end
end

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

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

int main(){
	int n;
	while( cin >> n, n ){
		int pl[10], f=0;
		rep(i,n) pl[i] = 0;
		rep(i,100){
			char c;
			cin >> c;
			if( c == 'M' )
				pl[i%n]++;
			else if( c == 'L' ){
				pl[i%n] += f+1;
				f = 0;
			}else if( c == 'S' ){
				f += pl[i%n]+1;
				pl[i%n] = 0;
			}
		}
		sort( pl, pl+n );
		cout << pl[0];
		rep(i,n-1){
			cout << " " << pl[i+1];
		}
		cout << " " << f << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int[] apple = new int[n];
        for(int i = 0; i < n; i++){
            apple[i] = l + i;
        }
        int taste = 0;
        for(int i = 0; i < n; i++){
            taste = taste + apple[i];
        }
        int taste2 = 0;
        int sub = 100000;
        int eaten = 0;
        for(int i = 0; i < n; i++){
            taste2 = taste - apple[i];
            if(sub > Math.abs(taste-taste2)){
                sub = Math.abs(taste - taste2);
                eaten = i;
            }
        }
        System.out.print(taste - apple[eaten]);
    }
}

Measured memory_bytes: 21716
from collections import deque
h,w=map(int,input().split())

field=[]
m=[]
INF=10**6

for i in range(h):
    row=list(input())
    field.append(row)
    m.append([INF for i in range(w)])

dx=[1,0,-1,0]
dy=[0,1,0,-1]

queue=deque()
for i in range(h):
    for j in range(w):
        if field[i][j]=="#":
            m[i][j]=0
            queue.append([i,j])

while len(queue)>0:
    y,x=queue.popleft()
    for k in range(4):
        nx=x+dx[k]
        ny=y+dy[k]
        if 0<=ny<h and 0<=nx<w:
            if m[ny][nx]>m[y][x]+1 and field[ny][nx]==".":
                m[ny][nx]=m[y][x]+1
                queue.append([ny,nx])
                field[ny][nx]="#"

ans=0

for i in range(h):
    ans=max(ans,max(m[i]))

print(ans)

Measured memory_bytes: 177884
<?php
fscanf(STDIN, "%d %d",$a, $b);
if($a % 3 === 0){
  echo 'Possible';
}elseif($b % 3 === 0){
  echo 'Possible';
}elseif(($a + $b) % 3 === 0){
  echo 'Possible';
}else{
  echo 'Impossible';
}

?>

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    int N;
    scanf("%d", &N);
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < N; i++) {
        string tmp = s.substr(i, N - i);
        if (tmp == t.substr(0, N - i)) {
            cout << N + i << endl;
            return 0;
        }
    }
    cout << 2 * N << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5,mo=998244353;
int n,i,x,ans=1;
int a1[3],a2[3];
char c[N];
int main(){
	scanf("%d%s",&n,c+1);
	for(i=1;i<=n;++i)ans=1ll*ans*i%mo;
	for(i=1;i<=n*3;++i){
		x=c[i]=='R'?0:(c[i]=='G'?1:2);
		if(a2[x])ans=1ll*ans*a2[x]--%mo;
		else if(a1[(x+1)%3])ans=1ll*ans*a1[(x+1)%3]--%mo,++a2[(x+2)%3];
		else if(a1[(x+2)%3])ans=1ll*ans*a1[(x+2)%3]--%mo,++a2[(x+1)%3];
		else ++a1[x];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;

typedef vector< vector<int> > graph;

graph g;
vector<int> match;
vector<bool> visit;

bool search(int u){
	if(u<0) return true;
	for(int i=0;i<g[u].size();i++){
		int next = g[u][i];
		if(visit[next]) continue;
		visit[next] = true;
		if(search(match[next])){
			match[u] = next, match[next] = u;
			return true;
		}
	}
	return false;
}

int maximumMatch(int L, int R){
	int res = 0;
	match.assign(L+R, -1);
	for(int i=0;i<L;i++){
		visit.assign(L+R, false);
		res += search(i);
	}
	return res;
}

int gcd(int a, int b){ return b==0 ? a : gcd(b, a%b); }

int main(){
	int m, n;
	int blue[500], red[500];
	while(cin >> m >> n){
		if(!(m||n)) break;
		for(int i=0;i<m;i++) cin >> blue[i];
		for(int i=0;i<n;i++) cin >> red[i];
		g.assign(m+n, vector<int>());
		for(int i=0;i<m;i++)
			for(int j=0;j<n;j++)
				if(gcd(blue[i],red[j])!=1){
					g[i].push_back(j+m);
					g[j+m].push_back(i);
				}
		cout << maximumMatch(m,n) << endl;
	}
}

Measured memory_bytes: 2928
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), output("\n"))
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	if(n/100*5>=n%100){
		cout << 1 << endl;
	}else{
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
import math
import copy
import fractions
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, m = map(int, input().split())

status = getSomeInputListInt(m)
condition = getInputListInt()

ans = 0
mask = []

for i in range(len(status)):
    mask.append(0b0)
    for j in range(1, status[i][0]+1):
        tmp = 1
        tmp = tmp << (status[i][j] - 1)
        mask[i] = mask[i] | tmp

for i in range(2**n):
    flg = True
    for j in range(m):
        masked = i & mask[j]
        oneCnt = bin(masked).count("1")
        if oneCnt % 2 != condition[j]:
            flg = False
            break

    if flg:
        ans += 1

print(ans)





Measured memory_bytes: 20112
#include<stdio.h>
int main(void){
  int temp=0,k=0,m,n;
  scanf("%d%d",&m,&n);
  if(m<n){
    temp=n;
    n=m;
    m=temp;
  }
  while(n!=0){
    k=m%n;
    m=n;
    n=k;
  }
  printf("%d\n",m);
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll N, M; cin >> N >> M;
    map<ll, ll, greater<ll>> m;
    for (int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        m[A]++;
    }
    for (int i = 0; i < M; i++) {
        ll B, C;
        cin >> B >> C;
        m[C] += B;
    }
    ll res = 0;
    ll cnt = 0;
    for (auto x : m) {
        ll d = N - cnt;
        if (d <= x.second) {
            res += d * x.first;
            break;
        } else {
            cnt += x.second;
            res += x.second * x.first;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N, K;
    cin >> N >> K;
    int ans = INT_MAX;
    for (int i = 0; i < (1 << N); i++) {
        int x = 1;
        for (int j = 0; j < N; j++) {
            if ((1 << j) & i) {
                x *= 2;
            }
            else {
                x += K;
            }
        }
        ans = min(ans, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const ll mod = 1e9 + 7;

int n, k;
int dp[105][100005];
int a;

int main(){
    fio;
    cin >> n >> k;
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        cin >> a;
        ll v = 0;
        for(int j = k; j > k - a; j--) v = (v + dp[i-1][j]) % mod;
        for(int j = k; j >= 0; j--){
            if(j >= a) v = (v + dp[i-1][j-a]) % mod;
            dp[i][j] = v;
            v = (v + mod - dp[i-1][j]) % mod;
        }
        //cout << "dp[" << i <<"] : "; for(int j = 0; j <= k; j++) cout << dp[i][j] << ' '; cout << '\n';
        //for(int j = 1; j <= k; j++) dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
    }
    cout << dp[n][k] << '\n';
}

Measured memory_bytes: 40832
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());

            long min = long.MaxValue;
            var rootN = Math.Sqrt(N);
            for (int i = 1; i <= rootN; i++)
            {
                var a = i;
                var b = N / a;
                var c = a + b - 2;
                if (N % i == 0
                    && c<min)
                {
                    min = c;
                }
            }

            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  vector<mint> sums(n+1, 0);
  rrep(i, n){
    sums.at(i) = sums.at(i+1) + a.at(i);
  }
  mint ans = 0;
  rep(i, n){
    mint add = sums.at(i+1) * a.at(i);
    ans += add;
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 5620
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

N,P = map(int,input().split())
W,B = np.array([input().split() for _ in range(N)], dtype=np.int64).T

#(100-P)W - PB の和が0以上
#全員青の状態から始めて、改善量が高い人から順にとる

X = B.sum()*P # 改善しないといけない値

improve = (100-P)*W + P*B
improve.sort()
improve = improve[::-1]
np.cumsum(improve, out=improve)

answer = (improve < X).sum() + 1
print(answer)

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

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	string s, t;
	cin >> s >> t;
	reverse(s.begin(), s.end());
	reverse(t.begin(), t.end());
	rep(i, m + k + 5) s.push_back('0');
	rep(i, n + k + 5) t.push_back('0');
	for (int i = n + m - 1; i >= 0; i --) {
		if (s[i] == '1' && t[i] == '1') {
			s[i] = '0';
			t[i] = '0';
			s[i + 1] ++;
			t[i + 1] ++;
			int life = k - 1;
			int j = i + 1;
			while (life) {
				if (s[j] == '2') {
					s[j] = '0';
					s[j + 1] ++;
				} else if (t[j] == '2') {
					t[j] = '0';
					t[j + 1] ++;
				} else if (s[j] == '1' && t[j] == '1') {
					life --;
					s[j] = '0';
					t[j] = '0';
					s[j + 1] ++;
					t[j + 1] ++;
				} else {
					break;
				}
				j ++;
			}
			if (s[j] == '2') {
				s[j] = '0';
				s[j + 1] ++;
			}
			if (t[j] == '2') {
				t[j] = '0';
				t[j + 1] ++;
			}
		}
	}
	while (s.back() == '0') s.pop_back();
	while (t.back() == '0') t.pop_back();
	reverse(s.begin(), s.end());
	reverse(t.begin(), t.end());
	cout << s << endl;
	cout << t << endl;
        return 0;
}


Measured memory_bytes: 14344
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000;
const int MOD = (int)1e9 + 7;

signed main()
{
    int n, d;
    cin >> n >> d;
    vector<vector<int> > v(n, vector<int> (d));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            int x;
            cin >> x;
            v[i][j] = x;
        }
    }

    int count = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i == j) continue;
            double s = 0;
            for (int k = 0; k < d; k++)
            {
                s += pow(v[i][k] - v[j][k], 2);
            }
            double ss = sqrt(s);
            double diff = ((int)ss - ss);
            if (diff == 0) count++;
        }
    }
    cout << count / 2 << "\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int x, y, z;
  cin >> x >> y >> z;
  int k;
  cin >> k;
  vector<ll> a(x);
  rep(i, x) cin >> a.at(i);
  vector<ll> b(y);
  rep(i, y) cin >> b.at(i);
  vector<ll> c(z);
  rep(i, z) cin >> c.at(i);
  vector<ll> ab(x*y);
  rep(i, x)rep(j, y){
    ab.at(i*y+j) = a.at(i)+b.at(j);
  }

  sort(ab.rbegin(), ab.rend());
  sort(c.rbegin(), c.rend());
  ab.push_back(-1e18);
  c.push_back(-1e18);
  vector<ll> ans(k);
  vector<int> indexs(z, 0);
  rep(i, k){
    ll mx = -1e18;
    int adi = -1;
    rep(j, z){
      ll add = c.at(j) + ab.at(indexs.at(j));
      if(add > mx){
        mx = add;
        adi = j;
      }
    }
    if(adi == -1) return 1;
    ans.at(i) = mx;
    indexs.at(adi)++;
  }
  for(auto o : ans){
    cout << o << endl;
  }
  return 0;
}

Measured memory_bytes: 18820
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n,a,b;
		cin >> n >> a >> b;
		int ans = (n/(a+b))*a;
		if(a!=0) ans += min(a,n%(a+b));
		cout<<ans;
	}
}

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

struct restaurant
{
    string name; int val;int index;
    bool operator<(const restaurant & A) const{
        if(name==A.name)
            return val<A.val;
        return name>A.name;}
};

int main()
{
    int T,i; cin>>T;
    priority_queue<restaurant> pq;
    for(i=1;i<=T;i++)
    {
        string A;int B;cin>>A;cin>>B;cin.ignore();
        pq.push({A,B,i});
    }
    while(!pq.empty())
    {
        cout<<pq.top().index<<endl;
        pq.pop();
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//const unsigned long long mod=1000000007;
int main(){
  string s;
  cin>>s;
  int best=0,maxi=0;
  for(int i=0;i<3;i++){
      if(s[i]=='R'){
          maxi++;
      }else{
      maxi=0;
      }
       best=max(best,maxi);
  }
    cout<<best<<"\n";
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i : x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll c = __gcd(A, B);
  auto facs = factorize(c);
  int ans = sz(facs) + 1;
  cout << ans << '\n';
  return 0;
}

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

int A[100010], cnt[100010];
int main() {
    int N, K; scanf("%d%d", &N, &K);
    for(int i=0; i<N; i++) {
        scanf("%d", &A[i]);
    }

    int r = 0, sum = 0, ans = N+1;
    for(int l=0; l<N; l++) {
        while(sum < K && r < N) {
            if(!cnt[ A[r] ] && A[r] <= K) sum++;
            cnt[ A[r++] ]++;
        }
        
        while(l < r) {
            if(--cnt[ A[l] ] == 0 && A[l] <= K) break;
            l++;
        }
        if(sum == K && ans > r - l) ans = r - l;
        if(A[l] <= K) sum--;
    }
    printf("%d\n", (ans == N+1 ? 0 : ans));
    return 0;
}


Measured memory_bytes: 3464
from collections import defaultdict

def main():
    N, P = map(int, input().split())
    S = list(map(int,list(input())))
    S_mod = [0] * N
    if P == 2:
        for i in range(N-1,-1,-1):
            if S[i] % 2 == 0:
                S_mod[i] = 1
        S_mod.reverse()
        ans = 0
        cnt = 0
        for i in range(N):
            if S_mod[i] == 1:
                cnt += 1
                ans += cnt
            else:
                ans += cnt
        print(ans)
        exit()
    if P == 5:
        for i in range(N-1,-1,-1):
            if S[i] % 5 == 0:
                S_mod[i] = 1
        S_mod.reverse()
        ans = 0
        cnt = 0
        for i in range(N):
            if S_mod[i] == 1:
                cnt += 1
                ans += cnt
            else:
                ans += cnt
        print(ans)
        exit()



    ten = 1
    for i in range(N-1,-1,-1):
        S_mod[i] = (S[i] * ten) % P
        ten *= 10
        ten %= P
    S_mod.reverse()
    S_acc = [0] * (N+1)
    for i in range(N):
        S_acc[i+1] = (S_acc[i] + S_mod[i]) % P
    d = defaultdict(int)
    for i in range(N+1):
        d[S_acc[i]] += 1
    ans = 0
    for i, j in d.items():
        if j >= 2:
            ans += (j * (j-1)) // 2

    print(ans)
    





if __name__ == "__main__":
    main()

Measured memory_bytes: 61552
// #include <bits/stdc++.h>
#include <iostream> // cin, cout, string
#include <algorithm> // sort, min, max
#include <vector>
#include <utility> // pair, swap
#include <functional>

using namespace std;

// #define int long long

using ll = long long;
using ld = long double;

using vi = vector<int>;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
// constexpr int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

int M, K;

inline int pow2(int i) {
  return i==0 ? 1 : 2*pow2(i-1);
}

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

  cin >> M >> K;
  const int pm = pow2(M);

  if(pm <= K) cout << -1 << endl;
  else if(M==0) cout << "0 0" << endl;
  else if(M==1) {
    if(K==0) cout << "0 0 1 1" << endl;
    else cout << -1 << endl;
  } else {
    rep(i, pm) {
      if(i!=K) cout << i << ' ';
    }
    cout << K;
    rrep(i, pm) {
      if(i!=K) cout << ' ' << i;
    }
    cout << ' ' << K << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int h, w;
  while (cin >> h >> w, h) {
    vector<vector<string>> map(h, vector<string>(w));

    for (auto &seq : map) {
      for (auto &v : seq) {
        char c;
        cin >> c;
        v = c;
      }
    }

    int cx = 0;
    int cy = 0;
    while (true) {
      string str = map[cy][cx];
      map[cy][cx] = "0";
      if (str == ">") {
        ++cx;
      } else if (str == "<") {
        --cx;
      } else if (str == "^") {
        --cy;
      } else if (str == "v") {
        ++cy;
      } else if (str == ".") {
        cout << cx << " " << cy << endl;
        break;
      } else if (str == "0") {
        cout << "LOOP" << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 3392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int h,w; cin >> h >> w;
    char s[h+2][w+2];
    for(int i = 0; i < h+2; i++){
        for(int j = 0; j < w+2; j++){
            if(i == 0 || i == h+1 || j == 0 || j ==w+1){
                s[i][j] = '.';
            }else{
                cin >> s[i][j];
            }
        }
    }
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(s[i][j] == '#'){
                if(s[i-1][j] == '.' && s[i+1][j] == '.' && s[i][j-1] == '.' && s[i][j+1] == '.'){
                    cout << "No" << endl; return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef long long ll;

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

int main() {
    int n; cin >> n;
    vector<ll> a(n); repp(i,0,n) cin >> a[i];

    deque<ll> res;
    repp(i,0,n) {
        if (i%2) res.push_back(a[i]);
        else res.push_front(a[i]);
    }
    if (n%2) {
        repp(i,0,n) {
            if (i > 0) cout << " ";
            cout << res.front(); res.pop_front();
        }
    } else {
        repp(i,0,n) {
            if (i > 0) cout << " ";
            cout << res.back(); res.pop_back();
        }
    }
    cout << endl;
}


Measured memory_bytes: 5884
import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String str = br.readLine();
			String[] strArray = str.split(" ");
			
			int x = Integer.parseInt(strArray[0]);
			int y = Integer.parseInt(strArray[2]);
			if(strArray[1].equals("?")){
				  break;
			}
			if(strArray[1].equals("+")){
				System.out.println(x+y);
			}
			if(strArray[1].equals("-")){
				System.out.println(x-y);
			}
			if(strArray[1].equals("*")){
				System.out.println(x*y);
			}
			if(strArray[1].equals("/")){
				System.out.println(x/y);
			}
		}
	}
}

Measured memory_bytes: 24352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int k;
 string s;
  cin>>k>>s;
  int n=s.size();
  if(n<=k)cout<<s<<endl;
  else{
    for(int i=0;i<k;i++){
      cout<<s[i];
    }
    cout<<"...";
  }
  
}

Measured memory_bytes: 3628