akhauriyash/Code-Regression huggingface dataset:
import java.util.*;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> A = new ArrayList<>();
		int x;
		int q;
		int y;
		x=sc.nextInt();
		
		for(int i=0;i<x;i++) {
			q = sc.nextInt();
			
			if(q==0) {
			y=sc.nextInt();	
			A.add(y);
				
		}
			else if(q==1) {
				y=sc.nextInt();	
				System.out.println(A.get(y));
			}else if(q==2) {
				A.remove(A.size() - 1);
			}else {
				System.out.println("error");
			}
		
	}
	
}
}



Measured memory_bytes: 140176
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())

A = inpl()
B = A[:]

# 累積和
for i in range(1, N):
    B[i] = B[i] + B[i - 1]

ans = INF
mid_l = 0
mid_r = 2
t = B[-1]
for mid in range(1, N - 1):
    while B[mid] > B[mid_l] + B[mid_l + 1]:
        mid_l += 1
    while t > B[mid_r] + B[mid_r + 1] - B[mid]:
        mid_r += 1

    p = B[mid_l]
    q = B[mid] - p
    r = B[mid_r] - p - q
    s = t - r - p - q

    ans = min(ans, max(p, q, r, s) - min(p, q, r, s))

print(ans)


Measured memory_bytes: 25668
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int c1, c2, c3, c4;
			c1 = c2 = c3 = c4 = 0;
			for (char c : line.toCharArray()) {
				c1++;
				if (c >= '0' && c <= '9') {
					c2++;
				} else if (c >= 'A' && c <= 'Z') {
					c3++;
				} else {
					c4++;
				}
			}
			if (c1 > 5 && c2 > 0 && c3 > 0 && c4 > 0) {
				System.out.println("VALID");
			} else {
				System.out.println("INVALID");
			}
		}
	}
}

Measured memory_bytes: 17064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    int n, m;
    cin >> n >> m;

    int a[300][300];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }

    int r = n;
    int p[300] = {}, o[300] = {};
    for (int k = 0;; k++) {
        int q[300] = {};
        for (int i = 0; i < n; i++) {
            q[a[i][p[i]]]++;
        }
        size_t b = max_element(q, q + m) - q;
        r = min(r, q[b]);
        if (k >= m - 2) break;

        o[b] = 1;
        for (int i = 0; i < n; i++) {
            while (o[a[i][p[i]]]) p[i]++;
        }
    }

    cout << r << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int cnt = 0;
    if(s[0] == 'R' && s[1] == 'S' && s[2] == 'S') {
        cout << '1' << endl;
    }
     else if(s[0] == 'S' && s[1] == 'R' && s[2] == 'S') {
        cout << '1' << endl;
    }
    else if(s[0] == 'S' && s[1] == 'S' && s[2] == 'R') {
        cout << '1' << endl;
    }
    else if(s[0] == 'R' && s[1] == 'R' && s[2] == 'S') {
        cout << '2' << endl;
    }
    else if(s[0] == 'S' && s[1] == 'R' && s[2] == 'R') {
        cout << '2' << endl;
    }
    else if(s[0] == 'R' && s[1] == 'S' && s[2] == 'R') {
        cout << '1' << endl;
    }
    else if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
        cout << '3' << endl;
    }
    else{
        cout << '0' <<endl;
    }
}









Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define debug(x) cerr << #x << ": " << x << "\n";
#define INF (1<<29) //53687091
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=(int) 1e5;
static const int MOD=(int) 1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
ll N;

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin >> N;
    
    if(N%2==0) cout<<N<<"\n";
    else cout<<N*2ll<<"\n";
    
    return 0;
}


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

int main()
{
    _LL n, r;
    cin >> n >> r;
    if( n < 10 )
    {
        cout << (r + 100 * (10 - n) );
    }
    else
    {
        cout << r;
    }
}

Measured memory_bytes: 3544
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  int n;
  cin >> n;
  char s[n];
  for(int i = 0; i < n; i++){
    cin >> s[i];
    if(s[i] == 'Y'){
      cout << "Four" << endl; return 0;
    }
  }
  cout << "Three" << endl;
  return 0;
}

Measured memory_bytes: 256
N=gets.to_i
A=gets.split.map(&:to_i)
h=Hash.new{|h,k|h[k]=0}
A.each do |a|
  h[a]+=1
end
sum=A.inject :+
Q=gets.to_i
Q.times do
  b,c=gets.split.map(&:to_i)
  sum-=b*h[b]
  sum+=c*h[b]
  p sum
  h[c]+=h[b]
  h[b]=0
end

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

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

int main(void)
{
    ll a,b,c,k,sum=0;
    cin >> a >> b >> c >> k;
    while(k>0 && a>0)
    {
        sum++;
        k--;
        a--;
    }
    while(k>0 && b>0)
    {
        k--;
        b--;
    }
    while(k>0 && c>0)
    {
        sum--;
        k--;
        c--;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
	ll a,b;
	cin>>a>>b;
	vector<double> mpq;
	mpq.push_back(0);
	double ans = 0.0;
	for(ll i=1;i<=a;i++)
	{
		ll c;
		cin>>c;
		double jk = 1.0*(c+1)/2;
		mpq.push_back(jk+mpq[i-1]);
		if(i-b>=0)
		{
			ans = max(ans,mpq[i] - mpq[i-b]);
		}
	}
	cout << setprecision(10) << ans << endl; 
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <cstring>

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))

#define INF (int)1e9+7

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

typedef long long ll;

using namespace std;
 
ll f(ll x){
  if( x % 4 == 0 ) return x;
  if( x % 4 == 1 ) return 1;
  if( x % 4 == 2 ) return x + 1;
  if( x % 4 == 3 ) return 0;
}
 
int main(){
  ll a, b;
  
  cin >> a >> b;

  cout << ( f(b)^f(a - 1) ) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using pii=pair<int,int>;
pii x[200010];
int y[200010];
int main(){ _;
  int n;cin>>n;
  int n2=n/2;
  REP(i,n){
    cin>>x[i].first;
    x[i].second=i;
  }
  sort(x,x+n);
  REP(i,n2){
    y[x[i].second]=n2;
    y[x[i+n2].second]=n2-1;
  }
  REP(i,n){
    cout<<x[y[i]].first<<endl;
  }
}


Measured memory_bytes: 4608
#include <cstdio>
#include <algorithm>
using namespace std;
int a[35],cnt;
int main()
{
 int n;
 scanf("%d",&n);
 if(n==0)printf("0");
 else
 {
  while(n!=0)
  {
   a[++cnt]=abs(n%2);
   if(n>=0)n/=-2;
   else n=(n-1)/(-2);
  }
  for(int i=cnt;i>=1;i--)
   printf("%d",a[i]);
 }
 return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;


typedef long long int lli;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<float, float> ff;
typedef vector<ii> vii; 
typedef vector<ff> vff;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vi ab(n);
    for (int i=0;i<n;i++) {cin >> ab[i];}
    vi ac(n+1);
    for (int i=0;i<n;i++) {cin >> ac[ab[i]];}
    vi ad(n);
    for (int i=0;i<n-1;i++) {cin >> ad[i+1];}
    long sum = ac[ab[0]];

    int prev = ab[0];
    for (int i = 1; i < n; i++)
    {
        if(prev==ab[i]-1){
            // cout<<prev<<" "<<ab[i]<<" "<<ad[ab[i]-1]<<endl;
            sum += ad[ab[i]-1];
        }
        // cout<<ac[ab[i]]<<endl;
        sum += ac[ab[i]];
        prev = ab[i];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
fact = [1] * 51
for i in range(2, 51):
    fact[i] = fact[i-1] * i

def Combination(n, k):
    return fact[n] // fact[k] // fact[n-k]

N, A, B = map(int, input().split())
v = sorted(list(map(int, input().split())))[::-1]
MAX = sum(v[:A])
print(MAX/A)
M = max(v[:A])
m = min(v[:A])
if M != m:
    c1, c2 = v[:A].count(m), v.count(m)
    print(Combination(c2, c1))
else:
    c = v.count(m)
    L = min(B, c)
    ans = 0
    for i in range(A, L+1):
        ans += Combination(c, i)
    print(ans)


Measured memory_bytes: 3064
def main():
    X, K, D = map(int, input().split())
    X = abs(X)
    if X >= K * D:
        return X - K * D
    else:
        div = X // D
        mod = [X % D, abs(X % D - D)]
        return mod[(K - div) % 2]

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 61864
a, b, c = map(int, input().split())

score1 = abs(b - a) + abs(c - b)
score2 = abs(c - a) + abs(b - c)
score3 = abs(a - b) + abs(c - a)
score4 = abs(c - b) + abs(a - c)
score5 = abs(a - c) + abs(b - a)
score6 = abs(b - c) + abs(a - b)

print(min([score1, score2, score3, score4, score5, score6]))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define int int64_t
#define double long double
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
#define all(v) v.begin(),v.end()
using namespace std;
//using pr = pair<int, int>;
using tup = tuple<int, int, int>;
using vec = vector<int>;
using vvec = vector<vec>; //プロトタイプ宣言
//int myfunc(int, vvec); //グローバル変数
//int N, M; //vvec data(N, vec(M));
//関数：
int gauss(int n)
{
    int ans = 0;
    for(int i=1; i<=n; i++)
        ans += i;
    return ans;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    int lg = S.size();
    lg++;
    vec d(lg);
    d[0] = 1;
    d[lg-1] = 1;
    int ans = 0;
    int cmp = 0;
    for(int i=1; i<lg-1; i++)
    {
        if(S[i] != S[i-1])
        {
            d[i] = 1;
            if(S[i-1] == '<')
            {
                cmp = d[i-1];
                ans += gauss(d[i-1]);
            }
            else 
            {
                ans += gauss(d[i-1]);
                ans -= min(d[i-1], cmp);
            }
        }
        else
        {
            d[i] = d[i-1] + 1;
        }
    }
    ans += gauss(d[lg-2]);
    if(S[lg-2] == '>') ans -= min(d[lg-2], cmp);
    cout << ans << endl;
    return 0;
}
//std::string str;
//str = std::to_string(int i);
//bitset<3> s(N);
//int ans = (char)grid - '0';


Measured memory_bytes: 4764
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int main() {
    string s;
    vector<string> v;
    while(cin >> s) {
        if (s.back() == '.' || s.back() == ',') {
            s.pop_back();
        }
        if (s.size() > 2 && s.size() < 7) {
            v.push_back(s);
        }
    }
    REP(i,v.size()-1) cout << v[i] << " ";
    cout << v.back() << endl;
    return 0;
}

Measured memory_bytes: 3016
from collections import Counter
A=list()
B=list()
N=int(input())
L=list(map(int,input().split()))
for i in range(N):
  if i%2==0:
    A.append(L[i])
  else:
    B.append(L[i])
c = Counter(A)
a = c.most_common()
c = Counter(B)
b = c.most_common()

if a[0][0]!=b[0][0]:
  print(N-a[0][1]-b[0][1])
  exit()

if len(a)==1 and len(b)==1:
  print(N//2)
  exit()
if len(a)==1:
  print(N-a[0][1]-b[1][1])
  exit()
if len(b)==1:
  print(N-a[1][1]-b[0][1])
  exit()
else:
  s=max(a[0][1]+b[1][1],a[1][1]+b[0][1])
  print(N-s)

Measured memory_bytes: 25832
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll,ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll T=1;
//	cin >> T;
	ll t=0;
	while(t++<T){
    ll X;
    cin >> X;
    if(X>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
	}
return 0;
}


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

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

    int n;
    cin>>n;

    int m=n;
    int ans=0;

    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;

        if(p<=m)ans++;
        m=min(p,m);
    }

    cout<<ans<<"\n";

    return 0;
}


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

using ll = long long;

long long int pick2Ball(long long int a){
  return a*(a-1)/2;
}

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

  int max_num = 0;
  rep(i,n){max_num =  max(max_num,A[i]);}
  max_num+=2;
  vector<int> basket(max_num,0);

  rep(i,n){
    basket[A[i]]++;
  }

  long long int  all_pattern = 0;
  for(int i=0;i<max_num;i++){
    all_pattern += pick2Ball(basket[i]);
  }

  long long ans = 0;
  for(int i=0;i<n;i++){
    ans = all_pattern - pick2Ball(basket[A[i]]) + pick2Ball(basket[A[i]]-1);
    cout << ans << endl;
  }
  
}

Measured memory_bytes: 4096
#include <stdio.h>
#include <iostream>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <limits.h>
#include <map>
#include <string>
#include <bitset>
#include <vector>
using namespace std;
long long a1[305][305],a2[305][305];
int main() {
    int n,m,l,q;
    cin>>n>>m>>l;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            if(i==j) a1[i][j]=0;
            else a1[i][j]=INT_MAX;
        }
    for(int i=1;i<=m;i++)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        a1[a][b]=c;
        a1[b][a]=c;
    }
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                if(a1[i][j]>a1[i][k]+a1[k][j])
                    a1[i][j]=a1[i][k]+a1[k][j];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            if(i==j)
                a2[i][j]=0;
            else if(a1[i][j]<=l) a2[i][j]=1;
            else a2[i][j]=INT_MAX;
        }
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                if(a2[i][j]>a2[i][k]+a2[k][j])
                    a2[i][j]=a2[i][k]+a2[k][j];
    cin>>q;
    while(q--)
    {
        int s,t;
        scanf("%d%d",&s,&t);
        if(a2[s][t]>=INT_MAX) printf("-1\n");
        else printf("%lld\n",a2[s][t]-1);
    }
}


Measured memory_bytes: 5248
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long m = Long.parseLong(sc.next());
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        long gcd = gcd(n,m);
        for (int i = 0; i < gcd; i++) {
            if (s[(int) (n/gcd*i)] != t[(int) (m/gcd*i)]) {
                System.out.println(-1);
                return;
            }
        }

        long lcm = lcm(n,m);
        System.out.println(lcm);
    }

    private static long gcd(long a, long b) {
        if (a % b == 0) return b;
        return gcd(b, a%b);
    }

    private static long lcm(long a, long b) {
        return a / gcd(a,b) * b;
    }
}

Measured memory_bytes: 40408
#include<bits/stdc++.h>
#define rep(i,s,e) for(int i = s;i<e;i++)
using namespace std;
int main()
{
   int t;
   cin>>t;
    int a[t];
    int b[t];
    long long sum = 0;
    long long m = 1e18;
    rep(i,0,t){
        cin>>a[i]>>b[i];
        sum+= a[i];
        if(a[i]>b[i]){
            m = m>b[i]? b[i]:m;
        }
      }
    if(m>1e15) cout<<"0\n"<<endl;
    else cout<<sum-m<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 2000009
#define ll long long
#define ld long double
#define ff first
#define ss second
#define inf 1000000005
#define mod 1000000007
using namespace std;
ll n, W, w[100009], v[100009];

int main() {
    //ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>W;
    vector<ll> dp(W + 1);
    for(int i=1;i<=n;i++)
        cin>>w[i]>>v[i];
    for(int i=1;i<=n;i++) {
        vector<ll> newdp = dp;
        for(ll j=w[i];j<=W;j++) {
            newdp[j] = max(newdp[j], dp[j - w[i]] + v[i]);
            //cout<<i<<" "<<j<<" "<<newdp[j]<<endl;
        }
        dp = newdp;
    }
    cout<<dp[W];
}


Measured memory_bytes: 4852
#include<bits/stdc++.h>
using namespace std;
int a[100005]={0};
int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int b;
		scanf("%d",&b);
		a[b]++;
		a[b+1]++;
		a[b-1]++;
	}
	int max=0;
	for(int i=1;i<=100000;i++)
	{
		if(a[i]>max)
		max=a[i];
	}
	printf("%d",max);
	return 0; 
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Long[] a = new Long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(sc.next());
        }
        sc.close();

        // 主処理
        long count = 0;
        for (int i = 1; i < n; i++) {
            if (a[i] < a[i - 1]) {
                long diff = a[i - 1] - a[i];
                count += diff;
                a[i] += diff;
            }
        }
        long result = count;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 64352
n,x=map(int,input().split())
line=list(map(int,input().split()))
Sum=[0]
sum=0
for i in range(n):
  sum+=line.pop()
  Sum.append(sum)
Ans=10**18
for k in range(1,n):
  p=0
  for i in range(n+k-1//k):
    if i==0:
      if n>=k:
        p+= (Sum[k])*5
      else:
        p+=(Sum[n])*5
        break
    else:
      if n> (k*i +k):
        p+= (Sum[k*i +k]-Sum[k*(i-1) +k])*(2*i +3)
      else:
        p+= (Sum[n]-Sum[k*(i-1) +k])*(2*i +3)
        break
  ans=(n+k)*x + p
  Ans=min(Ans,ans)
print(Ans)

Measured memory_bytes: 99536
#include <iostream>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
const int SIZE = 181 + 1;
const int MAX = 1000000;
 
int T[SIZE];
int cost1[MAX], cost2[MAX];
 
int main( void )
{  
    for(int i=0; i < SIZE; ++i) T[i] = i * (i + 1) * (i + 2) / 6;
 
    fill(cost1, cost1+MAX, MAX);
    fill(cost2, cost2+MAX, MAX + MAX);
    cost1[0] = cost2[0] = 0;
    for(int i=0; i < MAX; ++i) {
        //if(cost1[i] < 6) {
            for(int j=0; j < SIZE; ++j) {
                int tj = T[j];
                if(i + tj < MAX && cost1[i] < 5)
                    cost1[i + tj] = min(cost1[i + tj], cost1[i] + 1);
                if((T[j] & 1) && (i + tj < MAX)) {
                        cost2[i + tj] = min(cost2[i + tj], cost2[i] + 1);
                }
            }
    }
    int n;
    while(cin >> n, n) {
        cout << cost1[n] << ' ' << cost2[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 8972
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
class Solution
{
    static void Main(String[] args)
    {

        var s = Console.ReadLine().Split();
        var n = Convert.ToUInt64(s[0]);
        var a = Convert.ToUInt64(s[1]);
        var b = Convert.ToUInt64(s[2]);
        var c= a+b;
       
        UInt64 answer = (n/c)*a;
        answer+=Math.Min(n%(a+b),a);

       
        Console.WriteLine(answer);








    }

}


Measured memory_bytes: 13268
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T& v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

const int INF = 333333333;

int main() {
  int n, m; in(n),in(m);
  int G[n][n];
  vector<int> A(m),B(m),C(m);
  loop(i,0,n) loop(j,0,n) {
    if (i==j) G[i][j] = 0;
    else G[i][j] = INF;
  }
  loop(i,0,m) {
    int a, b, c; in(a),in(b),in(c);
    a--;b--;
    G[a][b] = G[b][a] = c;
    A[i] = a;
    B[i] = b;
    C[i] = c;
  }
  
  loop(k,0,n)
    loop(i,0,n)
      loop(j,0,n)
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
  
  int cnt = 0;
  loop(i,0,m) {
    cnt += G[A[i]][B[i]] < C[i];
  }
  
  print(cnt);
  return 0;
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
a, b, k = map(int, input().split())
m = max(a,b)
al = [i for i in range(1,m+1) if a%i==0]
bl = [i for i in range(1,m+1) if b%i==0]
ans = sorted(list(set(al)&set(bl)))[::-1]
print(ans[k-1])


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        String out = "EQUAL";
        if(a.length() != b.length()){
            if(a.length() > b.length()){
                out = "GREATER";
            }else{
                out = "LESS";
            }
            System.out.println(out);
            System.exit(0);
        }else{
            if(a.compareTo(b) < 0){
                out = "LESS";
            }else if(a.compareTo(b) > 0){
                out = "GREATER";
            }
        }
        System.out.print(out);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define LL long long
#define RG register
#define R RG int
using namespace std;
const int N=1009;
int x[N],y[N];
int main(){
	ios::sync_with_stdio(0);
	R n,i,k,mx=0,L,cnt=1;RG bool tp;
	cin>>n;
	for(i=1;i<=n;++i)cin>>x[i]>>y[i],mx=max(mx,max(abs(x[i]),abs(y[i])));
	tp=(x[1]+y[1])&1;
	for(i=2;i<=n;++i)
		if(((x[i]+y[i])&1)!=tp)return cout<<"-1\n",0;
	for(L=1;L<=mx;L<<=1)++cnt;
	cout<<cnt+!tp<<endl;
	for(k=L;k;k>>=1)cout<<k<<' ';
	cout<<(tp?"":"1")<<endl;
	for(i=1;i<=n;++i){
		for(k=L;k;k>>=1){
			if(abs(x[i])>abs(y[i]))
				if(x[i]>0)x[i]-=k,cout<<'R';
				else      x[i]+=k,cout<<'L';
			else
				if(y[i]>0)y[i]-=k,cout<<'U';
				else      y[i]+=k,cout<<'D';
		}
		if(!tp){
			k=1;
			if(abs(x[i])>abs(y[i]))
				if(x[i]>0)x[i]-=k,cout<<'R';
				else      x[i]+=k,cout<<'L';
			else
				if(y[i]>0)y[i]-=k,cout<<'U';
				else      y[i]+=k,cout<<'D';
		}
		cout<<endl;
	}
	return 0;
}


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

#define si(v) v.size()
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (n); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int a, b, c; cin >> a >> b >> c;
  if (c >= a && c <= b) cout << "Yes\n";
  else cout << "No\n";
  
  return (0);
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

class Parser {
public:
	using Iter = string::const_iterator;
	Iter it;
	Parser(Iter it) :it(it) {}
	void cmp(char expected) { if (*it != expected)cerr << *it << " is not " << expected << endl; assert(*it == expected); }
	/*
	EBNF
	???=???,{('+'|'-'),???}; //??°???????????????????????¨??????????¨??????§?????????
	???=c,{('*'|'/'),c};
	c ='('???')' | integer;
	*/
	int a() {
		int ret = b();
		while (true) {
			if (*it == '+') {
				it++;
				ret += b();
			}
			else if (*it == '-') {
				it++;
				ret -= b();
			}
			else break;
		}
		return ret;
	}
	int b() {
		int ret = c();
		while (true) {
			if (*it == '*') {
				it++;
				ret *= c();
			}
			else if (*it == '/') {
				it++;
				ret /= c();
			}
			else break;
		}
		return ret;
	}
	int c() {
		int ret;
		if (*it == '(') {
			it++;
			ret = a();
			cmp(')');
			it++;
		}
		else ret = integer();
		return ret;
	}
	int integer() {
		int ret = 0;
		while (isdigit(*it)) {
			ret *= 10;
			ret += *it - '0';
			it++;
		}
		return ret;
	}
};

signed main() {
	int n; cin >> n; cin.ignore();
	for (string s; getline(cin, s) && s != "$"; ) {
		s += "$";
		Parser P(s.begin());
		cout << P.a() << endl;
	}
	return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N = 100005;
#define M 998244353
#define double long double
#define BINF 10000000000001
#define MAXN 500005
#define init(arr,val) memset(arr,val,sizeof(arr))
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;

int dp[3005][3005];
int n, s;
int a[N], p[N];

int foo(int pos, int sum){
    if(sum < 0)
        return 0;
    
    if(pos == n){
        if(sum == 0){
            return 1;
        }
        return 0;
    }

    if(dp[pos][sum] != -1)
        return dp[pos][sum];

    int res = 0;

    res = 2 * foo(pos + 1, sum);
    res %= M;
    res += foo(pos + 1, sum - a[pos]);
    res %= M;

    return dp[pos][sum] = res;
}

#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);



    init(dp, -1);
    p[0] = 1;
    for(int i = 1; i < 3005; i++)
        p[i] = (2 * p[i - 1]) % M;
    
    cin >> n >> s;
    for(int i = 0; i < n; i++)
        cin >> a[i];

    int ans = foo(0, s);

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


Measured memory_bytes: 74436
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,a,b,c,d;
char str[MAXN+1];
bool go(int x,int y)
{
    for(int i=x;i<=y;i++)
    {
        if(str[i]=='#'&&str[i+1]=='#') return false;
    }
    return true;
}
int main()
{
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    scanf("%s",str+1);
    if(!go(a,c)||!go(b,d)) {puts("No"); return 0;}
    if(c<d) puts("Yes");
    else
    {
        bool f=false;
        for(int i=b;i<=d;i++)
        {
            if(str[i]!='#'&&str[i-1]!='#'&&str[i+1]!='#') f=true;
        }
        if(f) puts("Yes"); else puts("No");
    }
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>s;
            if(s=="snuke"){
                cout<<char(j-1+'A');
                cout<<i<<endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
# region
import sys

DEBUG = True if (len(sys.argv) > 1 and sys.argv[1] == "DEBUG") else False


def dp(value):
    if DEBUG:
        print(value)
    return


def input_text(split=" "):
    # 入力
    result = []
    while True:
        try:
            row = list(
                map(lambda x: int(x) if x.isdecimal() else x, input().split(split))
            )
            result.append(row)
        except EOFError:
            break
    return result


# endregion
it = input_text()

n = {i + 1 for i in range(it[0][0])}  # 展望台の数
m = it[0][1]  # 道の数
h = it[1]  # 標高
ab = it[2:]

for x in ab:
    a = h[x[0] - 1]
    b = h[x[1] - 1]

    if a == b:
        if x[0] in n:
            n.remove(x[0])
        if x[1] in n:
            n.remove(x[1])
        continue

    l = x[0] if a < b else x[1]
    if l in n:
        n.remove(l)

print(len(n))


Measured memory_bytes: 108392
#include <bits/stdc++.h>
using namespace std;
//using lint = long long;

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v[111111],v1;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

double o[3111];
double l[311][333][333];
int j[1];
int e;


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> s[222][22];
//priority_queue<P> q;
queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

//string r,r1;
char r[2222][1111];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;

}


double f(int n,int m,int c)
{
    if(n<0||m<0||c<0) return 0;
    if(n==m&&m==c&&c==0) return 0;
    if(l[n][m][c]>=0) return l[n][m][c];
    l[n][m][c]=(((double)(a-n-m-c)/(a)))/(1-((double)(a-n-m-c)/(a)));
    return l[n][m][c]+=1+f(n-1,m+1,c)*n/(n+m+c)+f(n,m-1,c+1)*m/(n+m+c)+f(n,m,c-1)*c/(n+m+c);
}

int main()
{
    memset(l,-1,sizeof(l));
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
    {
        scanf("%d",&d);
        if(d==1) n++;
        if(d==2) m++;
        if(d==3) c++;
    }
    printf("%.9lf",f(c,m,n));
}





Measured memory_bytes: 272768
#include <stdlib.h>
#include <iostream>

using namespace std;

int getAddScore(int** nums, int count, int pNo, int N);

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

	int** numbers = new int*[N];
	int* score = new int[N];
	for (int i = 0; i < N; i++) {
		numbers[i] = new int[3];
		score[i] = 0;
		cin >> numbers[i][0] >> numbers[i][1] >> numbers[i][2];
	}

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < N; j++)
			score[j] += getAddScore(numbers, i, j, N);
	}

	for (int i = 0; i < N; i++) {
		cout << score[i] << endl;
	}

	for (int i = 0; i < N; i++) {
		delete[] numbers[i];
	}
	delete[] numbers;
	delete[] score;

	return 0;
}

int getAddScore(int** nums, int count, int pNo, int N)
{
	int myNum = nums[pNo][count];
	for (int i = 0; i < N; i++) {
		if (nums[i][count] == myNum && i != pNo)
			return 0;
	}
	return myNum;
}

Measured memory_bytes: 1200
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  ll A, B;
  get(A, B);
  if ((10000000 + B - A) % 2 == 0) {
    print(A + (B - A) / 2);
  } else {
    print("IMPOSSIBLE");
  }
  return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    R = [[int(x) for x in input().split()] for i in range(N)]
    B = [[int(x) for x in input().split()] for i in range(N)]
    B.sort()
    selected = set()
    for b in B:
        r_lst = []
        for i in range(len(R)):
            if i in selected: continue
            r = R[i]
            if r[0] < b[0] and r[1] < b[1]:
                r_lst.append(i)
        if len(r_lst) == 0:
            continue
        rym = -1
        rym_i = -1
        for i in r_lst:
            if rym < R[i][1]:
                rym = R[i][1]
                rym_i = i
        selected.add(rym_i)
    return len(selected)
if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 3064
fn c_streamline() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).expect("input error");
    let mn: Vec<u32> = input.split_whitespace()
        .map(|s| s.parse::<u32>().expect("parse error"))
        .collect();
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).expect("input error");
    let mut xi: Vec<i32> = input.split_whitespace()
        .map(|s| s.parse::<i32>().expect("parse error"))
        .collect();

    if mn[0] >= mn[1] {
        println!("0");
        return;
    }

    xi.sort();
    let mut distance: Vec<i32> = xi.iter()
        .take(xi.len() -1)
        .enumerate()
        .map(|(i, val)| (xi[i + 1] - val).abs())
        .collect();
    distance.sort();

    println!("{}",
             distance.iter()
             .take((mn[1] - mn[0]) as usize)
             .map(|&n| n)
             .sum::<i32>());
}

fn main() {
    c_streamline();
}


Measured memory_bytes: 6396
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back
 const ll mod = 1000000007;

 int main() {
	ll L, R;
	cin >> L >> R;

	if(R - L >= 2018){
		L = 0; R = 2018;
	}else{
		L %= 2019;
		R %= 2019;
		if(R < L){
			R += 2019;
		}
	}

	int m = 2019;
	for(int i = L; i < R; i++){
		for(int j = L+1; j <= R; j++){
			int ij = (i * j) % 2019;
			if(m > ij){
				m = ij;
			}
		}
	}

	cout << m<< endl;

	return 0;
 }

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

const ll MOD=1000000007;

ll power(ll A,ll B,ll M){
    if(B==0){
        return 1;
    }
    else if(B%2==0){
        ll s=power(A,B/2,M);
        return (s*s)%M;
    }
    else{
        return ((A%M)*power(A,B-1,M))%M;
    }
}


int main(){
    ll X,Y;
    cin>>X>>Y;
    if((X+Y)%3!=0){
        cout<<0<<endl;
    }
    else if((2*X-Y)%3!=0||(2*Y-X)%3!=0){
        cout<<0<<endl;
    }
    else{
        ll m=(2*X-Y)/3;
        ll n=(2*Y-X)/3;
        ll k=m+n;
        ll s=min(m,n);
        queue<ll>comb;
        if(s<0){
            cout<<0<<endl;
        }
        else if(s==0){
            cout<<1<<endl;
        }
        else if(s==1){
            cout<<k%MOD<<endl;
        }
        else{
            comb.push(k%MOD);
            for(ll i=1;i<s;i++){
                ll combi=comb.front();
                comb.push((((combi*power(i+1,MOD-2,MOD))%MOD)*((k-i)%MOD))%MOD);
                comb.pop();
            }
            cout<<(comb.front())%MOD<<endl;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int a[5];
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	int k;
	cin >> k;
	if (a[4] - a[0] > k) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}
	
}


Measured memory_bytes: 256
def func(i):
    S = format(i, "b")
    S = (3-len(S)) * "0" + S
    ret = [""] * 3
    for i in range(3):
        ret[i] = "+" if S[i] == "1" else "-"
    return ret


def calc(n, op):
    ret = int(n[0])
    for i in range(3):
        if op[i] == "+":
            ret += int(n[i+1])
        else:
            ret -= int(n[i+1])
    return ret


n = list(input())


for i in range(8):
    op = func(i)
    if calc(n, op) == 7:
        print(n[0]+op[0]+n[1]+op[1]+n[2]+op[2]+n[3]+"=7")
        break

Measured memory_bytes: 3064
#include<iostream>
#include<map>
using namespace std;
int main(){
  int N;
  cin >> N;
  map<int, int> m;
  for(int i=0; i<N; i++){
    int ai, bi;
    cin >> ai >> bi;
    if(m.find(bi)==m.end()){
      m[bi]=0;
    }
    m[bi]+=ai;
  }
  int s=0;
  for(auto it: m){
    s += it.second;
    if(s > it.first){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    // fastio
    ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s,h;
    string str,str1;
    cin>>n;
    ll cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0 && i%15!=0)
        {
            cnt+=i;
        }
    }
    cout<<cnt;
}


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

int main() {
  string s;
  cin >> s;
  int sum = 0;
  if (s.at(0)=='1')
    sum++;
  if (s.at(1)=='1')
    sum++;
  if (s.at(2)=='1')
    sum++;
  
  cout << sum << endl;    
}



Measured memory_bytes: 256
import io.StdIn._

object Main extends App {
  val firstLine = readLine.split(" ").map(_.toInt)
  val N = firstLine(0)
  val M = firstLine(1)
  val K = firstLine(2)

  val uf = UnionFind.of(N)
  val friendCount = Array.fill(N)(0)
  val blocks = Array.fill(N)(Array.empty[Int])

  for (_ <- 0 until M) {
    val friendship = readLine.split(" ").map(_.toInt - 1) // 入力は 1始まり、プログラム上は0始まり
    val a = friendship(0);
    val b = friendship(1);
    uf.unite(a, b)
    friendCount(a) = friendCount(a) + 1
    friendCount(b) = friendCount(b) + 1
  }
  for (_ <- 0 until K) {
    val blockship = readLine.split(" ").map(_.toInt - 1)
    val a = blockship(0)
    val b = blockship(1)
    blocks(a) = blocks(a) :+ b
    blocks(b) = blocks(b) :+ a
  }

  for (i <- 0 until N) {
    val blockCount = blocks(i).count(block => uf.same(i, block))
    val ans = uf.size(i) - 1 - friendCount(i) - blockCount
    print(s"${ans} ")
  }
  print("\n")
}

/**
 * d(x) == a として
 * x がツリーの根であれば: a はツリーのサイズ（ノード数) に -1 をかけた数
 * x がツリーの根でなければ: a は関連ノードのインデックス番号
 *
 * @param d
 */
case class UnionFind(d: Array[Int]) {
  def root(x: Int): Int = if (d(x) < 0) x else {
    val rt = root(d(x))
    d(x) = rt // memoization
    rt
  }

  def unite(x: Int, y: Int): Boolean = {
    val xRoot = root(x)
    val yRoot = root(y)

    if (xRoot == yRoot) false
    else {
      if (xRoot < yRoot) {
        d(xRoot) = d(xRoot) + d(yRoot)
        d(yRoot) = xRoot
      } else {
        d(yRoot) = d(yRoot) + d(xRoot)
        d(xRoot) = yRoot
      }
      true
    }
  }

  def same(x: Int, y: Int): Boolean = root(x) == root(y)

  def size(x: Int): Int = -1 * d(root(x))
}

object UnionFind {
  def of(n: Int) = UnionFind(Array.fill[Int](n)(-1))
}


Measured memory_bytes: 110452
console.log((args=>{
  const [[H,W],...tmp] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  const A = tmp.slice(10);
  const dp = tmp.slice(0,10);
  for ( let k = 0; k < 10; k++ ) {
    for ( let i = 0; i < 10; i++ ) {
      for ( let j = 0; j < 10; j++ ) {
        dp[i][j] = Math.min( dp[i][j], dp[i][k] + dp[k][j] );
      }
    }
  }
  let cost = 0;
  for ( let i = 0; i < H; i++ ) {
    for ( let j = 0; j < W; j++ ) {
      if ( A[i][j] === -1 || A[i][j] === 1 ) continue;
      cost += dp[A[i][j]][1];
    }
  }
  return `${cost}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 33308
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>


using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から
#define REP(i,N) for(int j=i;j<N;j++) //iから

typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

#define MOD ((ll)1e+9 + 7)




//cout<<fixed<<setprecision(10);
int main(){
    int r,D;
    int x[11];
    cin>>r>>D>>x[0];
    rep(i,10){
        x[i+1]=r*x[i]-D;
    }
    REP(1,11){
        cout<<x[j]<<endl;
    }

    return 0;
}



Measured memory_bytes: 3572