akhauriyash/Code-Regression huggingface dataset:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_6_C&lang=jp
#  Lower Bound : python3
#  2018.11.26 yonezawa

import sys
input = sys.stdin.readline

def LowerBound(d,l):
    max = len(l) -1
    min = 0
    mid = max // 2
    while True:
        if (l[mid] > d ):
            max = mid
        elif (l[mid] == d ):
            while l[mid] == d and mid >= 0:
                mid -= 1
            return mid + 1
        else:
            min = mid
        mid =  (max + min ) // 2 

        if ( mid == max or mid == min ):
            if ( l[mid] == d or l[max] == d):
                while l[mid] == d and mid >= 0:
                    mid -= 1
                return mid+1
            if ( l[max] < d ):
                return len(l)
            if ( l[mid] > d):
                return min
            return max
def main():
    nl = int(input())
    l = list(map(int,input().split()))

    for i in range(int(input())):
        n = int(input())
        result = LowerBound(n,l)
        print (result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16848
#include <bits/stdc++.h>
using namespace std;
int main(){
    // Your code here!
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int dp[k+1];
    for(int i=0;i<=k;i++)
    {
        dp[i]=0;
    }
    for(int i=1;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i-a[j]>=0&&!dp[i-a[j]])
            {
                dp[i]=true;
            }
        }
    }
    if(dp[k])
    {
        cout<<"First"<<'\n';
    }
    else
    {
        cout<<"Second";
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define P pair<ll, ll>
#define VI vector<ll>
#define int long long
using namespace std;

int A, B;

void solve() {
  cout << max(A+B, max(A-B, A*B)) << endl;
}

signed main() {
  cin >> A >> B;

  solve();
}


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

string mp[6] = {"abcde", "fghij", "klmno", "pqrst", "uvwxy", "z.?! " };

int main() {
    string s;
    while(cin>>s) {
        if(s.length()%2) {
            cout<<"NA"<<endl;
            continue;
        }

        string res = "";
        for(int i=0; i<s.length(); i+=2) {
            if(s[i] >= '7' || s[i] <= '0' || s[i+1] >= '6' || s[i+1] <= '0') {
                cout<<"NA"<<endl;
                goto NEXT;
            }
            res += string(1, mp[s[i]-'1'][s[i+1]-'1']);
        }

        cout<<res<<endl;
    NEXT:;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, j = 0, s = 0;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) 
    {
        cin >> a[i];
        b[i] = 1;
    }
    sort(a, a + n);
    for (int i = 1; i < n; i++)
    {
        if (a[i] == a[i - 1]) b[j]++;
        else j++;
    }
    for (int i = 0; i <= j; i++) 
        s += b[i] % 2;
    cout << s;
}

Measured memory_bytes: 4368
N = int(input())

P = list(map(int,input().split()))
Q = list(map(int,input().split()))

q = [[]]

for i in range(N):

    nq = []
    for j in range(len(q)):

        for k in range(N):
            k += 1

            if k not in q[j]:
                ad = q[j].copy()
                ad.append(k)
                nq.append(ad)

    q = nq

q.sort()

a = None
b = None

for i in range(len(q)):

    if " ".join(map(str,q[i])) == " ".join(map(str,P)):
        a = i
    if " ".join(map(str,q[i])) == " ".join(map(str,Q)):
        b = i

print (abs(a-b))

            
    


Measured memory_bytes: 16980
import collections
H,W,N = map(int,input().split())
abList = []
for _ in range(N):
    a,b = map(int, input().split())
    abList.append((a-1,b-1))
memo = []

for a,b in abList:
    for i in range(a-1,a+2):
        if H < i+2 or i < 1:
            continue
        for j in range(b-1, b+2):
            if W < j+2 or j < 1:
                continue
            memo.append((i,j))
x = collections.Counter(memo)
result = [0 for _ in range(9)]
s = 0
for k,v in x.items():
    if int(v) < 10:
        result[int(v)-1] += 1
    s += int(v)
print((W-2)*(H-2) - len(x))
for x in result:
    print(x)

Measured memory_bytes: 192992
N=int(input())
ans=10000000
for i in range(1,int(N**0.5)+1):
  if N%i == 0:
    a=len(str(i))
    b=len(str(N//i))
    L=max(a,b)          
    if ans > L:
      ans=L

print(ans) 


Measured memory_bytes: 3060
import sys
from collections import deque
import copy

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, Z, W] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    input_raw = read_func().strip().split()
    A = []
    for i in range(N):
        A.append(int(input_raw[i]))

    if N > 1:
        print max(abs(A[N - 1] - W), abs(A[N - 2] - A[N - 1]))
    else:
        print abs(A[0] - W)

  


if __name__ == '__main__':
    main()


Measured memory_bytes: 3056
using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		while(true){
			var ss=Console.ReadLine().Split(' ');
			if(ss[1][0]=='X')break;
			Sol mySol =new Sol(ss);
			mySol.Solve();
		}
	}
}

class Sol{
	public void Solve(){
		char T='L';
		if(V[0]<='Z' && V[0]>='A')T='U';
		for(int i=0;i<V.Length;i++){
			if(V[i]=='_'){
				T='D';break;
			}
		}
		
		List<String> words=new List<String>();
		if(T=='D'){
			var A=V.Split('_');
			for(int j=0;j<A.Length;j++)words.Add(A[j]);
		}
		if(T=='U'||T=='L'){
			int from=0;
			int cnt=1;
			for(int j=1;j<V.Length;j++){
				if(V[j]<='Z' && V[j]>='A'){
					words.Add(V.Substring(from,cnt));
					from=j;
					cnt=1;
				}else{
					cnt++;
				}
			}
			words.Add(V.Substring(from,cnt));
		}
		for(int i=0;i<words.Count;i++){
			var snew=words[i].ToCharArray();
			if(snew[0]<='Z' && snew[0]>='A')snew[0]+=(char)('a'-'A');
			if(Next=='L'){
				if(i>0)snew[0]-=(char)('a'-'A');
				Console.Write("{0}",new String(snew));
			}
			if(Next=='U'){
				snew[0]-=(char)('a'-'A');
				Console.Write("{0}",new String(snew));
			}
			if(Next=='D'){
				Console.Write(i==0?"{0}":"_{0}",new String(snew));
			}
			
		}
		Console.WriteLine("");
	}

	String V;
	char Next;
	public Sol(String[] ss_){
		V=ss_[0];Next=ss_[1][0];
	}




	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

Measured memory_bytes: 5460
#include <iostream>

using namespace std;

int main()
{
    int h,w;

    cin >> h >> w;

    while((h!=0)||(w!=0)){
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cout << '#';
            }
            cout<<endl;
        }
        cout<<endl;
        cin >> h >> w;
    }


    return 0;
}



Measured memory_bytes: 3096
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True, end="")

N = _I()
X=[]
for i in range(N):
	x=[]

	for j in range(_I()):
		x.append(LI())
	X.append(x)
	
#print(X)
ans=[]

#2の15乗通りしかないので、全部見る
def dfs(idx, ls):
	if idx == N:
		# あってるか確認
		ok = True
		#print("ls",ls)
		for lidx, l in enumerate(ls):
			#print(lidx , l)
		
			if l != 1: continue
			for x in X[lidx]:
				#print("x",x)
			
				if ls[x[0]-1] != x[1]:
					ok=False
					break
		if ok:
			#print("ok", ls)
		
			ans.append(sum(ls))
		
			
		
		
		return
	# 通りを作る
	dfs(idx+1, ls+[0])
	dfs(idx+1, ls+[1])

dfs(0, [])
print(max(ans))

				
			
		
	
		
	
	


Measured memory_bytes: 6484
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
const int N = 5;

long long int dfs(long long int n){
    if(n == 0) return 1;
    else return dfs(n - 1) * n;
}

int main(){
    long long int n;
    cin >>n;
    cout <<dfs(n) <<endl;
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}


int main(){
  string s;
  cin>>s;
  if(s[2]==s[3]&&s[4]==s[5]){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    
    public static void main(String[] args){
        
        Scanner sc =new Scanner(System.in);
        
        int count=0;
        
        while(true){
        	
        int n=sc.nextInt();
        int x=sc.nextInt();
        
        if(n==0&&x==0) break;
        
        for(int i=1;i<=n;i++)
         for(int j=i+1;j<=n;j++)
          for(int k=j+1;k<=n;k++)
        	  if(i+j+k==x) count++; 
        
        System.out.println(count);
        count=0;
        
}
}
}



Measured memory_bytes: 26712
h, w = map(int, input().split())
s=[input() for _ in range(h)]
for i in range(h):
    ss = ''
    for j in range(w):
        if s[i][j] == '#':
            ss += '#'
        else:
            counter = 0
            for k in [-1, 0, 1]:
                for l in [-1, 0, 1]:
                    if 0 <= i+k <= h-1 and 0 <= j+l <= w-1 and s[i+k][j+l] == '#':
                        counter += 1
            ss += str(counter)
    print(ss)


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N; cin >> N;
  long double A[N]; rep(i,N) cin >> A[i];
  ll ta[N]; rep(i,N) ta[i] = A[i] * pow(10,9) + 1e-2;

  ll p25[21][21] = {};
  rep(i,N) {
    ll p2 = 0, p5 = 0;
    while (ta[i]%2==0) { ta[i]/=2; p2++; }
    while (ta[i]%5==0) { ta[i]/=5; p5++; }
    p2 = min(20ll,p2); p5 = min(20ll,p5);
    p25[p2][p5]++;
  }

  ll result = 0;
  rep(x,441) repr(y,x,441) {
    ll xi = x/21, xj = x%21;
    ll yi = y/21, yj = y%21;
    if (xi+yi>=18&&xj+yj>=18) {
      if (x==y) result += p25[xi][xj] * (p25[xi][xj]-1) / 2;
      else result += p25[xi][xj] * p25[yi][yj];
    }
  }
  // rep(i,21) debug(p25[i],p25[i]+21);

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

Measured memory_bytes: 8408
def main():
    # 1.input
    a,b,c,d = map(int, input().split())
    
    
    #2. judge
    if abs(a-c) <= d:
        print("Yes")
    elif abs(a-b) <= d and abs(b-c) <= d:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

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

const ll MOD = 1000000007;

ll N;
vector<ll> E[100000];
ll dp[100000][2];

void dfs(ll v, ll p) {
  dp[v][0] = 1;
  dp[v][1] = 1;

  for (ll u : E[v]) if (u != p) {
    dfs(u, v);

    dp[v][0] *= dp[u][1];
    dp[v][0] %= MOD;

    dp[v][1] *= (dp[u][0] + dp[u][1]) % MOD;
    dp[v][1] %= MOD;
  }
}

int main(void) {
  cin >> N;
  REP(i, 0, N - 1) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    E[x].push_back(y);
    E[y].push_back(x);
  }

  dfs(0, -1);

  cout << (dp[0][0] + dp[0][1]) % MOD << endl;
}

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

using ll = long long int;
using P = pair<ll, ll>;
using P3 = pair<ll,P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9) + 7;
constexpr ll MODS[] = {ll(1e9) + 7, ll(1e9)+9};
constexpr ll base = 5e5+9;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-8;

ll f(ll x){
    if(x <= 0) return 0;
    x--;
    return x/3+x/5;
}

ll g(ll x){
    if(x <= 0) return 0;
    x--;
    return x/3+x/5-x/15;
}

// [a,b)
ll cnt_fb(ll a, ll b){
    return f(b)-f(a);
}

ll cnt_fb_n(ll a, ll b){
    return g(b)-g(a);
}

ll len_d(ll d){
    return 9*pow(10,d-1)*d - cnt_fb_n(pow(10,d-1),pow(10,d))*d + 4*cnt_fb(pow(10,d-1),pow(10,d));
}

ll len_d(ll a, ll b, ll d){
    return (b-a)*d - cnt_fb_n(a,b)*d + 4*cnt_fb(a,b);
}

bool test(){
    string s = "";
    int n, m = 0;
    cin >> n;
    for(int i=1;i<n;i++){
        if(i%3==0) s += "Fizz", m++;
        if(i%5==0) s += "Buzz", m++;
        if(i%3>0 && i%5>0) s += to_string(i);
    }
    cout << s.size() << endl;
    cout << s << endl;
    ll tmp = 0;
    for(int i=1;pow(10,i)<=n;i++){
        tmp += len_d(i);
    }
    cout << tmp << endl;

    // int d;
    // cin >> d;
    // for(int i=pow(10,d-1);i<pow(10,d);i++){
    //     if(i%3==0) s += "Fizz", m++;
    //     if(i%5==0) s += "Buzz", m++;
    //     if(i%3>0 && i%5>0) s += to_string(i);
    // }
    // cout << s.size() << endl;
    // cout << s << endl;
    // cout << len_d(d) << endl;
    // cout << cnt_fb(pow(10,d-1),pow(10,d)) << endl;
    // cout << m << endl;
    return false;
}

bool solve(){
    ll s, n = 0, d = 1;
    cin >> s;
    s--;
    while(1){
        ll tmp = len_d(d);
        if(n+tmp <= s){
            n += tmp;
            d++;
        }
        else break;
    }
    ll base = pow(10,d-1);
    // len of [0,base) <= s
    ll ok = 0, ng = base*10+1;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
        if(n + len_d(base, base+mid, d) <= s){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    n += len_d(base, base+ok, d);
    string str = "";
    for(ll i=0;i<1000;i++){
        ll num = base+ok+i;
        if(num%3==0) str += "Fizz";
        if(num%5==0) str += "Buzz";
        if(num%3>0 && num%5>0) str += to_string(num);
    }
    ll dif = s-n;
    cout << str.substr(dif,20) << endl;
    return false;
}

int main(){
    solve();
    // test();
    // int t; cin >> t; for(;t>0;t--) solve();
    return 0;
}


Measured memory_bytes: 3468
s=input()
a=[["","A"],["","A"],["","A"],["","A"]]
for i in range(16):
    num=[]
    for j in range(4):
        num.append(i%2)
        i=i//2
    x=a[0][num[0]]+"KIH"+a[1][num[1]]+"B"+a[2][num[2]]+"R"+a[3][num[3]]
    if s==x:
        print("YES")
        exit()
print("NO")


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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()

ll gcd(ll a, ll b);

ll sum(int n);

void go(){
   int n;cin>>n;
   map<string, vector<pair<int, int>>> cnt;
   set<string> cities; 
   for(int i=0;i<n;i++){
      string ci;cin>>ci;
      int score;cin>>score;
      cnt[ci].pb(mk(score, i+1));
      cities.insert(ci);
   }
   for(auto it=cities.begin();it!=cities.end();it++){
      sort(cnt[*it].begin(), cnt[*it].end(), greater<>());
      for(auto p : cnt[*it]){
         cout << p.second << endl;
      }

      //cout << *it << endl;
   }

}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

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

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin>>S;
    for(int i=0;i<S.size();i++){
        if(i%2==0){cout<<S[i];}
    }
    cout<<endl;
    return 0;
}


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

public class Main {
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        long y , x;
        long sum = 0;
        String input = br.readLine();
        x = Long.parseLong(input);
        String[] list = br.readLine().split(" ");
        long ma = Long.parseLong(list[0]);
        long mi = Long.parseLong(list[0]);
        for (int i = 0; i < x; i ++)
        {
        	y = Integer.parseInt(list[i]);
        	ma = Math.max(ma, y);
        	mi = Math.min(mi, y);
        	sum += y;
        }	
        System.out.println(mi +" " +  ma +" " + sum);
	}

}

Measured memory_bytes: 28660
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
long long k,s,ans;
using namespace std;
int main()
{
	cin>>k>>s;
	for(int i=0;i<=k;i++)
	{
		for(int j=0;j<=k;j++)
		{
			if((s-i-j)<=k&&(s-i-j)>=0) ans++;	
		}
	}
	cout<<ans;
	return 0;
}

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

bool f(int n){
	int m=n;
	int num=0;
	while(m>0){
		num+=m%10;
		m/=10;
	}
	if(n%num==0) return true;
	else return false;
}

int main(){
	int n;
	cin >> n;
	if(f(n)) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>
#include <sstream>

using namespace std;

class abc084_C {
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        vector<tuple<int, int, int>> trains;
        trains.reserve(N);
        for (int i = 1; i <= N - 1; ++i) {
            int c, s, f;
            in >> c >> s >> f;
            trains.emplace_back(c, s, f);
        }
        vector<int> res(N, 0);
        res[N - 1] = 0;
        for (int i = 0; i < N - 1; ++i) {
            res[i] = 0;
            for (int j = i; j < N - 1; ++j) {
                int c, s, f;
                tie(c, s, f) = trains[j];
                res[i] = max(res[i], s);
                if (res[i] % f)
                    res[i] += f - res[i] % f;
                res[i] += c;
            }
        }
        for (int x : res)
            out << x << "\n";
    }
};


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

	abc084_C solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

ll c[501], s[501], f[501];

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n; cin >> n;
    for (int i = 0; i < n - 1; i++) {
        cin >> c[i] >> s[i] >> f[i];
    }

    for (int i = 0; i < n - 1; i++) {
        ll ans = 0;
        for (int j = i; j < n - 1; j++) {
            if (ans < s[j]) {
                ans = s[j];
            } else {
                if (ans % f[j] != 0) {
                    ans = ans + f[j] - ans % f[j];
                }
            }
            ans += c[j];
        }
        cout << ans << '\n';
    }

    cout << "0\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
    int t;
    cin >> t;
    vector<string> c(10);
    c[1] = ".,!? ";
    c[2] = "abc";
    c[3] = "def";
    c[4] = "ghi";
    c[5] = "jkl";
    c[6] = "mno";
    c[7] = "pqrs";
    c[8] = "tuv";
    c[9] = "wxyz";
    while(t--){
        string s;
        cin >> s;
        string ans = "";
        int t = 0;
        int n = s.size();
        for(int i = 0; i < n; i++){
            if(s[i] > '0'){
                t++;
            }else{
                if(t){
                    int m = c[s[i-1]-'0'].size();
                    ans += c[s[i-1]-'0'][(t+m-1)%m];
                    t = 0;
                }
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3148
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n,m;
	int xc,yc;
	int x[200],y[200];
	int a[1000],b[1000];
	while(true){
	cin>>m;
	if(m==0)
		break;
	for(int i=0;i<m;i++)
		cin>>x[i]>>y[i];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for(int i=0;i<n;i++){
		int t=0;
		for(int j=0;j<m;j++){
			for(int k=0;k<n;k++){
				if(a[i]-x[0]+x[j]==a[k]&&b[i]-y[0]+y[j]==b[k])
					t++;
			}
		}
		if(t==m){
			xc=a[i]-x[0];
			yc=b[i]-y[0];
		}
	}
	cout<<xc<<" "<<yc<<endl;
	}
	return 0;
}

Measured memory_bytes: 1168
import sys
sys.setrecursionlimit(10**6) 

class Node:
    def __init__(self, parent, left, right):
        self.p = parent
        self.l = left
        self.r = right


n = int(input())
node = {}
for i in range(n):
    node[i] = Node(-1, -1, -1)


for j in range(n):
    temp = list(map(int, input().split()))
    if temp[1] != -1:
        node[temp[0]].l = temp[1]
        node[temp[1]].p = temp[0]
    if temp[2] != -1:
        node[temp[0]].r = temp[2]
        node[temp[2]].p = temp[0]


def pre_parse(T, u, pre_list):
    if u == -1:
        return
    pre_list.append(u)
    pre_parse(T, T[u].l, pre_list)
    pre_parse(T, T[u].r, pre_list)

def in_parse(T, u, in_list):
    if u == -1:
        return
    in_parse(T, T[u].l, in_list)
    in_list.append(u)
    in_parse(T, T[u].r, in_list)

def post_parse(T, u, post_list):
    if u == -1:
        return
    post_parse(T, T[u].l, post_list)
    post_parse(T, T[u].r, post_list)
    post_list.append(u)


for k, v in node.items():
    if v.p == -1:
        root = k

pre_list = []
in_list = []
post_list = []
pre_parse(node, root, pre_list)
in_parse(node, root, in_list)
post_parse(node, root, post_list)

print('Preorder')
print('', *pre_list)
print('Inorder')
print('', *in_list)
print('Postorder')
print('', *post_list)


Measured memory_bytes: 5616
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll r,d,x;
	cin>>r>>d>>x;
	for(ll i=1;i<=10;i++)
	{
	x=r*x-d;
	cout<<x<<endl;	
	}	
}

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

using namespace std;

int main() {
    double x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(8) << sqrt(pow((x2-x1),2)+pow((y2-y1),2));
    return 0;
}



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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

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

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

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;


const int INF = 1000000000;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int H, W; cin >> H >> W;
	vector<vi> grid (H, vi (W));
	F0R(i, H) {
		F0R(j, W) {
			char c; cin >> c;
			grid[i][j] = c == '#';
		}
	}
	
	priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> q;
	vector<vi> dist (H, vi (W, INF));
	dist[0][0] = grid[0][0];
	q.push({dist[0][0], {0, 0}});
	while (!q.empty()) {
		pii v = q.top().second;
		int d_v = q.top().first;
		q.pop();
		if (dist[v.second][v.first] != d_v) continue;

		if (v.first + 1 < W) {
			int d = !grid[v.second][v.first] && grid[v.second][v.first + 1];
			if (d + d_v < dist[v.second][v.first + 1]) {
				dist[v.second][v.first + 1] = d + d_v;
				q.push({d + d_v, {v.first + 1, v.second}});
			}
		}

		if (v.second + 1 < H) {
			int d = !grid[v.second][v.first] && grid[v.second + 1][v.first];
			if (d + d_v < dist[v.second + 1][v.first]) {
				dist[v.second + 1][v.first] = d + d_v;
				q.push({d + d_v, {v.first, v.second + 1}});
			}
		}
	}
	print(dist[H-1][W-1]);
}

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

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

  vector<int> l(q), r(q);
  rep(i, q) cin >> l[i] >> r[i];

  int cnt = 0;
  vector<int> c(n + 1);
  rep(i, n - 1) {
    if (s.substr(i, 2) == "AC") ++cnt;
    c[i + 1] = cnt;
  }
  rep(i, q) {
    int ans = c[r[i] - 1] - c[l[i] - 1];
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 4492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
int main(){
    ll a, b;
    cin>>a>>b;
    if((a+b)%3==0){
        cout<<"Possible";
        return 0;
    }
    if(a%3==0){
        cout<<"Possible";
        return 0;
    }
    if(b%3==0){
        cout<<"Possible";
        return 0;
    }
    cout<<"Impossible";

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

struct Combinations {
    
    long long mod;
    vector< long long > inv;
    vector< long long > fact;
    vector< long long > inv_fact;
    
    Combinations (int n, int m) : inv(n), fact(n), inv_fact(n), mod(m) {
        inv[1] = 1;
        for (long long i = 2; i < n; i++) {
            inv[i] = inv[mod%i] * (mod - mod / i) % mod;
        }
        fact[0] = inv_fact[0] = 1;
        for (long long i = 1; i < n; i++) {
            fact[i] = (fact[i-1] * i) % mod;
            inv_fact[i] = (inv_fact[i-1] * inv[i]) % mod;
        }
    }
    
    long long nPr(long long n, long long r) {
        if (n < r || r < 0) return 0;
        return fact[n] * inv_fact[n-r] % mod;
    }
    
    long long nCr(long long n, long long r) {
        if (n < r || r < 0) return 0;
        return nPr(n,r) * inv_fact[r] % mod;
    }
    
    long long nHr(long long n, long long r) {
        return nCr(n+r-1,r);
    }
    
};
/*
 usage:
 O(N);
 Combination C(N,inf);//Nまでの全てのcombination, %inf;
 C.nCr(a,b); // aCbの値
 C.nPr,  C.nHrなどもある
 */
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N , K ;
    cin >> N >> K ;
    Combinations C(N+1, MOD);
    
    
    for(ll i = 1; i <= K; i++){
        cout << (C.nCr(N-K+1, i) * C.nCr(K-1, i-1)) % MOD << endl;
    }
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
"fmt"
)

func main() {
	var n, ac, wa, tle, re, i int32
	_, _ = fmt.Scan(&n)
	s := make([]string, n)
	for i=0; i<n; i++ {
		_, _ = fmt.Scan(&s[i])
	}

	for i=0; i<n; i++{
		if s[i]=="AC"{
			ac += 1
		}else if s[i]=="WA"{
			wa += 1
		}else if s[i]=="TLE"{
			tle += 1
		}else if s[i]=="RE" {
			re += 1
		}
	}
	fmt.Printf("AC x %d\n", ac)
	fmt.Printf("WA x %d\n", wa)
	fmt.Printf("TLE x %d\n", tle)
	fmt.Printf("RE x %d\n", re)
}


Measured memory_bytes: 6848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		String ans = s.substring(0, k-1) + s.toLowerCase().charAt(k-1) + s.substring(k);
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int cnt;
    while(cin>>s)
    {
        cnt=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='1')cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <complex>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;


int main() {
	int n; cin >> n;
	cout << n * 32 << endl;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = 1e9 + 7;
const int MX = (int)2e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

void pre(){
}	

void solve(){
	ll x, k, d;
	cin >> x >> k >> d;
	ll dist = abs(x);

	ll res = 9e18;

	// if(k == 1)
	// 	res = abs(dist - d);
	// else{
		if(k % 2 == 0)
			res = min(res, dist); // maybe this is okay?
		ll steps_to_origin = min(k, dist / d);
		ll rem = k - steps_to_origin;
		if(rem & 1)
			res = min(res, abs(dist - (steps_to_origin + 1) * d)); // try taking one more step, now u should cross the origin to the other side
		else
			res = min(res, abs(dist - steps_to_origin * d));
	// }
	
	cout << res << "\n";
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	// freopen("input.in", "r", stdin);
	// freopen("output.out", "w", stdout);

	int t;
	t = 1;
	// cin >> t;
	// pre();
	for(int i = 1; i <= t; ++i){
		// cout << "Case #" << i << ": \n";
		solve();
	}

	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <stack>

using namespace std;
typedef long long  ll;
const ll INF = 1000000007;
const ll mod = 1000000007;


int main()
{
	int N, W;
	cin >> N >> W;
	vector<ll> w(N), v(N);
	for (ll i = 0; i < N; i++)
	{
		cin >> w[i] >> v[i];
	}
	vector<vector<ll>> dp(110, vector<ll>(100101, INF));
	dp[0][0] = 0;
	for (ll i = 0; i < N; i++)
	{
		for (ll j = 0; j < 100100; j++)
		{
			if (j >= v[i]) {
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
			}
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		}
	}
	ll ans = 0;
	for (ll i = 0; i < 100101; i++)
	{
		if (dp[N][i] <= W)
		{
			ans = max(ans, i);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    bool flag = true;
    map<int, int> mp;
    for(int j = 0; j < n; ++j) {
        cin >> a[j];

        if(flag) {
            for(long long int i=1 ; i*i<=a[j]; ++i) {
                if(a[j]%i == 0) {
                    mp[i]++;
                    if(i != 1 && mp[i] >= 2) {
                        flag = false;
                    }
                    if(i!=1 && i*i!=a[j]) {
                        mp[a[j]/i]++;
                        if(a[j]/i != 1 && mp[a[j]/i] >= 2) {
                            flag = false;
                        }
                    }
                }
            }
            mp[a[j]]++;
            if(a[j] != 1 && mp[a[j]] >= 2) {
                flag = false;
            }
        }
    }

    int gcd = __gcd(a[0], a[1]);
    for(int i = 2; i < n; ++i) {
        gcd = __gcd(gcd, a[i]);
    }

    if(gcd == 1) {
        if(!flag) {
            cout << "setwise coprime" << '\n';
        } else {
            cout << "pairwise coprime" << '\n';
        }
    } else {
        cout << "not coprime" << '\n';
    }
}


Measured memory_bytes: 7612
#include <stdio.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    long a[n];
    for(i=0;i<n;i++) scanf("%ld",&a[i]);
    long max=a[0];
    for(i=1;i<n;i++){
        if(max>a[i]+1){
            printf("No");
            return 0;
        }
        if(max<a[i]) max=a[i];
    }
    printf("Yes");
    return 0;
}


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

#define ll long long
#define pb push_back

const int maxn = 5e5 + 20;

int d[maxn] , a[maxn] , n , mx[maxn * 4];

vector<int> adj[maxn];

void update(int p , int val , int s = 0 , int e = n , int v = 1)
{
	if(e - s < 2)
	{
		mx[v] = val;
		return;
	}

	int m = (s + e) / 2;
	if(p < m)
		update(p , val , s , m , 2 * v);
	else
		update(p , val , m , e , 2 * v + 1);

	mx[v] = max(mx[2 * v] , mx[2 * v + 1]);
}

int get(int l , int r , int s = 0 , int e = n , int v = 1)
{
	if(l <= s && e <= r)
		return mx[v];
	if(r <= s || e <= l)
		return -1;

	int m = (s + e) / 2;
	return max(get(l , r , s , m , 2 * v) , get(l , r , m , e , 2 * v + 1));
}

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

	memset(mx , -1 , sizeof mx);

	int k;
	cin >> n >> k;

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

		a[x] = i;
	}

	for(int i = 0; i < n; i++)
	{
		int v = get(a[i] - k + 1 , a[i]);
		if(v >= 0)
			adj[a[v]].pb(a[i]) , d[a[i]]++;

		v = get(a[i] , a[i] + k);
		if(v >= 0)
			adj[a[v]].pb(a[i]) , d[a[i]]++;

		update(a[i] , i);
	}

	set<int> st;
	for(int i = 0; i < n; i++)
		if(!d[i])
			st.insert(i);

	for(int _ = 0; _ < n; _++)
	{
		assert(!st.empty());

		int v = *st.begin();
		st.erase(v);

		for(auto u : adj[v])
		{
			d[u]--;
			if(!d[u])
				st.insert(u);
		}

		a[v] = _;
	}

	for(int i = 0; i < n; i++)
		cout << a[i] + 1 << " ";
	cout << endl;
}
















Measured memory_bytes: 49536
n,m = map(int,input().split())
plist = []
for _ in range(n):
    plist.append([int(x) for x in input().split()])

plist.sort()

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)

Measured memory_bytes: 21612
# N <= 50
# K <= 100



def solve(V, K):
    hiscore = 0
    for k in range(0, K+1):
        lscore = sum(V[:k])
        rV = list(reversed(V[k:]))
        neg = [v for v in V[:k] if v < 0]
        for rk in range(0, K+1-k):
            neg0 = list(neg)
            rscore = lscore + sum(rV[:rk])
            neg0.extend(v for v in rV[:rk] if v < 0)
            score = rscore - sum(sorted(neg0)[:K-k-rk])
            if score > hiscore:
                #print(k, rk)
                hiscore = score
    print(hiscore)


N, K = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]
solve(V, K)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define MOD (1e9+7)
#define rep(i, x, n) for(int i = x; i < n; i++)
#define repr(i, x, n) for(int i = x; i > n; i--)
#define pii pair<int,int>
#define ll long long
const long long iinf = 1e18;
const int inf = 1e9;
int dir4[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int knight[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{-1,2},{1,-2},{-1,-2}};

using namespace std;

int bound[50];

vector <ll> prime; // Stores generated primes
char sieve[1000020]; // 0 means prime
void primeSieve ( int n ) {
    sieve[0] = sieve[1] = 1; // 0 and 1 are not prime
 
    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= n; i += 2 ) sieve[i] = 1; // Remove multiples of 2
 
    int sqrtn = sqrt ( n );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( sieve[i] == 0 ) {
            for ( int j = i * i; j <= n; j += 2 * i ) sieve[j] = 1;
        }
    }
 
    for ( ll i = 3; i <= n; i += 2 ) if ( sieve[i] == 0 ) prime.push_back(i);
}


void solve()
{
    long long  n;

    cin >> n;
    if(n == 1LL){
        cout << 0;
        return;
    }
    int cnt = 0;
    for(int i = 0; i < prime.size() && prime[i]<=n; i++){
        int k = 0;
        while(n %  prime[i] == 0){
            k++;
            n /= prime[i];
        }
        int add = 0;
        
        for(int j = 0; k >= bound[j]; j++) add++;
        cnt += add;

    }

    if(n != 1) cnt++;
    cout << cnt;
    
}
//new line is printed in the main

int main()
{
    int t = 1;
        //cin >> t; // comment out if no test case is required
    // int i = 1;
    primeSieve ( 1000010 );
    for(int i = 0; i < 10; i++) bound[i] = ((i+1)*(i+2))/2;
    // for(int i = 0; i < 10; i++) cout << bound[i] << " ";
    while(t--){
        //cout << "Case " << i++ << ": ";
        solve();
        printf("\n");
    }
    return 0;
}


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

// グローバルにしておく
int N, M;
vector<int> visited;
vector<vector<int>> G;
int num_visited = 0;
int ans = 0;

void dfs(int now){
    visited[now] = 1;
    num_visited++;
    // すべての頂点を訪れたなら
    if(num_visited == N){
        ans++;
    }
    for(int i=0; i<G[now].size(); i++){
        int next = G[now][i];
        if(!visited[next]) dfs(next);
    }
    visited[now] = 0;
    num_visited--;
}

int main() {
    cin >> N >> M;
    G = vector<vector<int>>(N); // サイズを確保する
    visited = vector<int>(N, 0);
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        // 頂点番号を 0-indexed とする
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    // 頂点番号 0 からDFSを始める
    dfs(0);
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
import time
from collections import deque
from collections import defaultdict
from copy import deepcopy

t = time.time()
def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

n = iip()
el = defaultdict(lambda :[])
for i in range(n-1):
    a, b = iip()
    el[a-1].append((b-1, i))
    el[b-1].append((a-1, i))

#print(el)

def main():
    color = [None for i in range(n-1)]
    cmax = 0
    que = deque()
    que.append((0, 0))

    while que:
        parent, used_color =que.popleft()
        children = el[parent]
        cn = 1

        for child, edge_num in children:
            el[child].remove((parent, edge_num))

            if cn == used_color:
                cn += 1
            color[edge_num] = cn
            cmax = max(cn, cmax)
            que.append((child, cn))
            
            cn += 1



    print(cmax)
    for i in color:
        print(i)



main()

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        long n = sc.nextLong();

        System.out.println(n * (n-1) / 2);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

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

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

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

Measured memory_bytes: 22996
#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>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (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);

  ll n;cin>>n;
  vector<ll>a(3),b(3),ab(3),ba(3);
  rep(i,3)cin>>a[i];
  rep(i,3)cin>>b[i];
  rep(i,3){ba[i]=b[i]-a[i];ab[i]=a[i]-b[i];}
  ll dn=0;
  ll xm=n/a[0]+1;
  rep(x,xm){
    if(ba[0]<=0&&x!=0)break;
    ll ym=(n-a[0]*x)/a[1]+1;
    rep(y,ym){
      if(ba[1]<=0&&y!=0)break;
      ll d=n-a[0]*x-a[1]*y;
      ll z=d/a[2];
      if(ba[2]<=0){z=0;y=max(y,ym-2);}
      chmax(dn,x*ba[0]+y*ba[1]+z*ba[2]);
    }
  }
  n+=dn;
  dn=0;
  xm=n/b[0]+1;
  rep(x,xm){
    if(ab[0]<=0&&x!=0)break;
    ll ym=(n-b[0]*x)/b[1]+1;
    rep(y,ym){
      if(ab[1]<=0&&y!=0)break;
      ll d=n-b[0]*x-b[1]*y;
      ll z=d/b[2];
      if(ab[2]<=0){z=0;y=max(y,ym-2);}
      chmax(dn,x*ab[0]+y*ab[1]+z*ab[2]);
    }
  }
  n+=dn;
  cout<<n<<endl;
  return 0;

}


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

using namespace std;

#define rep(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define drep(i, a, n) for (int i = a, _n = n; i >= n; --i)
#define debug(x) cout << #x <<" = "<< x << endl
#define M 100005

int n;

int x[M], y[M];

int fa[M], tot[M];

int Find (int x) {
	if (x == fa[x]) return x;
	return fa[x] = Find(fa[x]);
}

vector<int> X[M];

set<int> S[M];

bool mark[M];

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

	rep(i, 1, M - 5) fa[i] = i;

	rep(i, 1, n) {
		scanf ("%d%d", x + i, y + i);
		X[x[i]].push_back(y[i]);
	}
	
	rep(i, 1, M - 5) {
		int fu;
		if (X[i].size()) fu = Find(X[i][0]);
		for (int j = 1; j < X[i].size(); ++j) {
			int fv = Find(X[i][j]);
			fa[fv] = fu;
		}
	}

	rep(i, 1, M - 5) {
		int fu;
		if (X[i].size()) fu = Find(X[i][0]);
		for (int j = 0; j < X[i].size(); ++j)
			S[fu].insert(X[i][j]);
	}

	long long ans = 0;

	rep(i, 1, M - 5) if (X[i].size()) {
		int fu = Find(X[i][0]);
		ans += 1LL * S[fu].size();
	}

	printf ("%lld\n", ans - n);

	return 0;
}


Measured memory_bytes: 12800
import Foundation

let N = Int(readLine()!)!
var answer = 0
var lengthOfN = 0

func power(_ x: Int, _ n: Int) -> Int {
  var result = 1
  if n >= 1 {
    for _ in 1...n {
      result *= x
    }
  }
  return result
}

if N % 10 == 0 {
  answer = 10
} else {
  var tN = N
  while tN != 0 {
    tN /= 10
    lengthOfN += 1
  }
  tN = N
  var i = lengthOfN, j: Int
  while i > 0 {
    i -= 1
    j = power(10, i)
    answer += tN / j
    tN %= j
  }
}

print(answer)

Measured memory_bytes: 1024