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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int k = sc.nextInt();

		for(int i = 0; i < Math.pow(2, n); i++) {
			int bitArray[] = new int[n];
			int temp = i;
			int count = 0;
			for(int j = 0; temp > 0; j++) {
				if(temp % 2 == 1) {
					bitArray[j] = 1;
					count++;
				}
				temp /= 2;
			}

			if(count == k) {
				System.out.print(i + ":");  //順列のインデックス
				for(int j = 0; j < n; j++) {
					if(bitArray[j] == 1) System.out.print(" " + j);
				}
			}
			if(count == k) System.out.println();
		}
	}

}



Measured memory_bytes: 72724
#include <iostream>
using namespace std;
int main() {
  char s[200001];
  char t[200001];
  cin >> s >> t;
  int i;
  int cnt = 0;
  for (i=0; s[i]!='\0'; i++) if (s[i] != t[i]) cnt++;
  cout << cnt;
  return 0;
}

Measured memory_bytes: 4012
N,K = map(int,input().split())
A = [-1] + list(map(int,input().split()))
 
visit = [False for i in range(N+1)]
now = 1
cnt = 0
while True:
    if visit[now]:
        break
    visit[now] = True
    now = A[now]
    cnt += 1
cnt2 = 0
visit2 = [False for i in range(N+1)]
while True:
    if visit2[now]:
        break
    visit2[now] = True
    now = A[now]
    cnt2 += 1
 
if cnt >= K:
    ans = 1
    for i in range(K):
        ans = A[ans]
 
else:
    K -= cnt
    K = K%cnt2
    ans = now
    for i in range(K):
        ans = A[ans]
print(ans)

Measured memory_bytes: 32364
#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)
#define f first
#define s second

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

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;

ll loss(vector<pii>& arr) {
	sort(arr.begin(), arr.end());
	multiset<int> vals;
	int size = 0;
	ll ans = 0;
	for (pii val : arr) {
		int K = val.first;
		int diff = val.second;
		
		vals.insert(diff);
		size++;

		while (size > K) {
			--size;
			ans += *--vals.end();
			vals.erase(--vals.end());
		}
	}
	return ans;
}

void solve() {
	int N; cin >> N;
	vector<pii> wantL;
	vector<pii> wantR;

	ll ans = 0;

	F0R(i, N) {
		int K, L, R; cin >> K >> L >> R;
		if (L > R) {
			ans += L; 
			wantL.push_back({K, R - L});
		} else {
			ans += R;
			wantR.push_back({N-K, L - R});
		}
	}
	print(ans + loss(wantL) + loss(wantR));
	
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T; cin >> T;
	F0R(i, T) solve();
}

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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 1e2+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
struct res{
	int id;
	string name;
	int score;
	bool operator<(const res& y){
		if (name == y.name) return score > y.score;
		return name < y.name;
	}
};
res a[N];
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i].name >> a[i].score;
		a[i].id = i + 1;
	}
	sort(a, a+n);
	for(int i=0; i<n; i++) cout << a[i].id << endl;
	
	return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
max_move = 0
pre = h[0]
move = 0
for i in range(1,n):
  if pre < h[i]:
    max_move = max(max_move,move)
    move = 0
    pre = h[i]
  else:
    move += 1
    pre = h[i]
max_move = max(max_move,move)
print(str(max_move))

Measured memory_bytes: 14224
#include<stdio.h>

int main(void){
int a,b,c,x;
scanf("%d %d %d",&a,&b,&c);
if(a>b){
x=a;
a=b;
b=x;
}
if(b>c){
x=b;
b=c;
c=x;
}
if(a>b){
x=a;
a=b;
b=x;
}
printf("%d %d %d\n",a,b,c);

return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N; cin >> N;
    vec A(N); readv(A);
    SORT(A);
    vec B(N);

    int ans = 0, m = INF;
    if(N % 2 == 0){
        B[0] = A[N / 2 - 1];
        B[N - 1] = A[N / 2];
        REP(i, N / 2 - 1){
            B[2 * i + 1] = A[N - 1 - i];
            B[N - 2 - 2 * i] = A[i];       
        }
        REP(i, N - 1) ans += llabs(B[i + 1] - B[i]);
    }else{
        int ans1 = 0;
        B[0] = A[N / 2 - 1];
        B[N - 1] = A[N / 2];
        REP(i, N / 2){
            B[2 * i + 1] = A[N - 1 - i];
            if(i != N / 2 - 1) B[N - 2 - 2 * i - 1] = A[i];    
        }
        //REP(i, N) cout << B[i] << endl;
        REP(i, N - 1) ans1 += llabs(B[i + 1] - B[i]);

        int ans2 = 0;
        B[0] = A[N / 2];
        B[N - 1] = A[N / 2 + 1];
        REP(i, N / 2){
            if(i != N / 2 - 1) B[2 * i + 1 + 1] = A[N - 1 - i];
            B[N - 2 - 2 * i] = A[i];    
        }
        REP(i, N - 1) ans2 += llabs(B[i + 1] - B[i]);
        ans = max(ans1, ans2);
    }


    cout << ans;
    
    return 0;
}

Measured memory_bytes: 1792
// E - Handshake
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using ll = long long;
using vl = vector<ll>;
#define all(x) (x).begin(),(x).end()

ll N,M;
vl A;
vl csum; // 累積和

auto check(ll x){ // (x<=ai+aj となる aj の個数) < M?
	ll count = 0; // aj の区間[j,N] 個数集計
	ll total = 0; // x 以上(上部)の値集計
	for(auto ai:A){
		ll j = lower_bound(all(A), x-ai) - A.begin(); // x<=ai+aj -> x-ai<=aj
		count += N - j; // aj の区間[j,N] 個数集計
		total += ai * (N - j); // ai 集計
		total += csum[N] - csum[j]; // aj の区間[j,N] 値集計
	}
	return make_pair(count, total);
}

ll solve(){
	sort(all(A));

	csum.resize(N+1); rp(i,0,N) csum[i+1] = csum[i] + A[i]; // 累積和

	// 二分探索
	ll lower_limit = 2*A[0], upper_part = 2*A[N-1]; // 下限, 上部:[下限+1, 上限]
	while(lower_limit + 1 < upper_part){ // l+1 < r
		ll x = (lower_limit + upper_part)/2;
		if(check(x).first < M) upper_part = x; else lower_limit = x;
	}

	ll m, upper_total; tie(m, upper_total) = check(upper_part); // 上部集計

	return upper_total + lower_limit * (M-m); // 上部 + 下限
}

int main(){
	cin>>N>>M;
	A.resize(N); rp(i,0,N) cin>>A[i];
	cout<< solve() <<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll A,B;
ll gcd(ll a,ll b){
if(a<b) swap(a,b);
if(a%b==0) return b;
else return gcd(a%b,b);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>A>>B;
cout<<lcm(A,B)<<endl;
}
    


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

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

Measured memory_bytes: 3616
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int a[2010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),x=gi();ll ans=1e18;
	for(int i=1;i<=n;++i)a[i]=gi();
	for(int i=0;i<n;++i){
		ll res=1ll*i*x;
		for(int j=1;j<=n;++j)res+=a[j];
		ans=std::min(ans,res);
		int _an=a[n];
		for(int i=n;i>1;--i)a[i]=std::min(a[i],a[i-1]);
		a[1]=std::min(a[1],_an);
	}
	printf("%lld\n",ans);
	return 0;
}


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

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		String s = sc.next();
		String t = sc.next();
		println(t + s);
	}
}


Measured memory_bytes: 22740
from collections import defaultdict
dicA = defaultdict(int) 

H,W = map(int,input().split())
C = []
min_step = []
for i in range(10):
  temp = list(map(int,input().split()))
  C.append(temp)
  min_step.append(temp[1])
#print(C)
#print(min_step)

def dfs(n,k,now): #0indexの数字nから1に行くのに最短の値。nowステップ進んで今kにいる。
  if now > min_step[n]:
    return
  for i in range(10):
    if i == 1: #kから0に行ったときは、現状の最短とどちらが近いかを比較。
      #print(min_step[n],now+ C[k][1])
      min_step[n] = min(min_step[n],now+ C[k][1])
    if i != k:
      if C[k][i]+now < min_step[n]: #iを経由しても現状の最短よりも近い。
        #print(n,i,now,C[k][i])
        dfs(n,i,C[k][i]+now)

for i in range(10):
  if i == 1:
    continue
  for j in range(10):
    if i!=j:
      dfs(i,j,C[i][j])

#print(min_step)

for i in range(H):
  temp = list(map(int,input().split()))
  for j in range(W):
    if temp[j] == -1:
      continue
    dicA[temp[j]] +=1 #数字を0indexに
ans = 0
#print(dicA)
for x in dicA.keys():
  ans += min_step[x]*dicA[x]
print(ans)

Measured memory_bytes: 9392
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var an, n int
	fmt.Scanf("%d", &n)

	a := BufScan(n)
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			an += a[i-1] - a[i]
			a[i] = a[i-1]
		}
	}
	fmt.Println(an)
}
func BufScan(n int) []int {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var inInts []int
	for i := 0; i < n; i++ {
		sc.Scan()
		tmp, _ := strconv.Atoi(sc.Text())
		inInts = append(inInts, tmp)
	}
	return inInts
}


Measured memory_bytes: 9544
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
const lli INF = 1e18L+5;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
//cout.precision(9);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
		lli n,i,z,ans=0;
		cin>>n;
		vector<lli> a,b;
		for(i=0;i<n+1;i++)
		{
			cin>>z;
			b.pb(z);
		}
		for(i=0;i<n;i++)
		{
			cin>>z;
			a.pb(z);
		}
		for(i=0;i<n;i++)
		{
			//what_is(ans);
			if(a[i]>b[i])
			{
				ans+=b[i];
				a[i]-=b[i];
				b[i]=0;
			}
			else
			{
				ans+=a[i];
				b[i]-=a[i];
				continue;
			}
			if(a[i]>b[i+1])
			{
				ans+=b[i+1];
				a[i]-=b[i+1];
				b[i+1]=0;
			}
			else
			{
				ans+=a[i];
				b[i+1]-=a[i];
			}
		}
		cout<<ans<<endl;
    }
}


Measured memory_bytes: 2676
N = int(input())
T,A = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
min = 10**5
ans = 0
for index,i in enumerate(H):
    tmp = T - i*0.006
    if(abs(tmp-A)<min):
        ans = index
        min = abs(tmp-A)
print(ans+1)

Measured memory_bytes: 3064
#from collections import Counter

def main():
    N = int(input())
    if N==1:
        print(1)
        exit()
    elif N==2:
        print(5)
        exit()

    divs = [1]*(N+10)

    for i in range(2, N+1):
        max_t = N // i
        for j in range(1, max_t+1):
            val = i*j
            divs[val] += 1
    ans = 0
    for i in range(1, N+1):
        ans += i * divs[i]
    print(ans)
if __name__ == "__main__":
    main()

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



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

  for(int i = min(a, b); i >= 1; --i){
    if(a%i == 0 && b%i == 0){
      --k;
      if(k == 0){
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}



 

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, x, y);
    int b = y/2 - x;
    int a = x - b;
    
    CoutYn(y % 2 == 0 && a >= 0 && b >= 0);
}


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

using namespace std;

int main(){
    
    char ch;
    
    while(1){
        
        scanf("%c", &ch);
        
        if( isalpha(ch)){
            if(islower(ch)) printf( "%c", toupper(ch));
            else printf("%c", tolower(ch));
            
        }else{
            printf("%c", ch);
        }
        
        if(ch =='\n') break;
    }
    
    return 0;
    
}


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

int main(){
    int N, L[11], s = 0; cin >> N;
    for(int i=0;i<N;i++) {cin >> L[i]; s += L[i];}

    if(*max_element(L, L+N)*2<s) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

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

using namespace std;

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

void trace(int A[], int N) {
    for (int i = 0; i < N; ++i) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

using ll = long long;
using P = pair<int, int>;

const unsigned long long INF = 1LL << 60;

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

int n;
int a[10010];

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];

    int min = 1000000;
    int max = -1000000;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        int c = a[i];
        if (c < min) {
            min = c;
        }
        if (c > max) {
            max = c;
        }
        sum += c;
    }
    printf("%d %d %lld\n", min, max, sum);
}



Measured memory_bytes: 3236
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        dist **= 0.5
        if dist.is_integer():
            ans += 1
print(ans)


Measured memory_bytes: 9276
#include<iostream>

using namespace std;

int main()
{
	int i, k,ans;
	ans = 0;
	cin >> i;
	cin >> k;
	int *n = new int[i];

	for (int j=0;j+k<=i;j++)
	{
		ans++;
	}
	cout << ans;
	return 0;
}

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

#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main(){
    int n;
    string s,t;
    cin >> n >> s >> t;
    
    for(int i = 0; i < n; i++){
        if(s.substr(i) == t.substr(0, n-i)){
            cout << n + i << endl;
            return 0;
        }
    }

    cout << n*2 << endl;
    return 0;
}


Measured memory_bytes: 256
class card:

    def __init__(self,cv):
        c = cv[0:1]
        v = int(cv[1:2])
        self.c = c
        self.v = v
    

    def self_str(self):
        q = str(str(self.c) + str(self.v))
        return q


n = int(input())
a = list(map(card, input().split()))


b = a[:]
c = a[:]

for i in range(n):
    for j in range(n-1, i, -1):
        if b[j].v < b[j-1].v:
            b[j], b[j-1] = b[j-1],b[j]

print(" ".join(x.self_str() for x in b))

coua = ["" for i in range(10)]
coub = ["" for i in range(10)]
conb = ""
for i in range(n):
    for j in range(n):
        if i != j:
            if a[i].v == a[j].v:
                coua[a[i].v] += a[i].c
            if b[i].v == b[j].v:
                coub[b[i].v] += b[i].c
if coua == coub:
     conb = "Stable"
else:
    conb = "Not stable"
print(conb)





for i in range(n):
    mini = i
    for j in range(i, n):
        if c[j].v < c[mini].v:
            mini = j
    c[mini], c[i] = c[i], c[mini]

print(" ".join(x.self_str() for x in c))

couc = ["" for i in range(10)]
conc = ""
for i in range(n):
    for j in range(n):
        if i != j:
            if c[i].v == c[j].v:
                couc[c[i].v] += c[i].c
if coua == couc:
     conc = "Stable"
else:
    conc = "Not stable"

print(conc)

Measured memory_bytes: 7852
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String s = "";
        for (int i = 0; i < k; i++) {
            s += "ACL";
        }
        System.out.println(s);
    }
}

Measured memory_bytes: 38388
#include<stdio.h>

int main(){
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if((x-r)<0||(x+r)>W||(y-r)<0||(y+r)>H)printf("No\n");
else printf("Yes\n");
return 0;
}

Measured memory_bytes: 584
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()
	t := make([]int, N+1)
	for i := 0; i < M; i++ {
		a, b := sc.NextInt(), sc.NextInt()
		if a > b {
			a, b = b, a
		}
		t[a] += 1
		t[b] -= 1
	}
	c := 0
	for i := 1; i < N+1; i++ {
		c += t[i]
		if c%2 == 1 {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define all(a) (a).begin(),(a).end()
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
constexpr ll inf = 1ll<<30;
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

signed main(){
  int n, m;
  while(cin >> n >> m, n){
    vi c(m); rep(i,m) cin >> c[i];
    vi x(n); rep(i,n) cin >> x[i];
    vvi dp(n+1, vi(256,inf)); // dp[i][j] : yi番目がjの時の最小コスト
    dp[0][128] = 0;
    rep(i,n) rep(j,256) rep(k,m){ // dp[i][j]からc[k]を使った時
      int next = j + c[k];
      if(next < 0) next = 0;
      else if(255 < next) next = 255;
      chmin(dp[i+1][next], dp[i][j] + (x[i] - next)*(x[i]-next));
    }
    cout << *min_element(all(dp[n])) << endl;
  }
}


Measured memory_bytes: 43800
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
using namespace std;
using ll = long long;

void chmax(ll &x, ll y) {
  x = max(x, y);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(3), b(3);
  rep(i, 3) cin >> a[i];
  rep(i, 3) cin >> b[i];
  const ll inf = 1e18;
  vector<ll> dp(5000*5000+1, -inf);
  dp[n] = 0;
  rep(k, 3) {
    for (int i = 5000*5000; i >= a[k]; i--) {
      chmax(dp[i - a[k]], dp[i] + b[k]);
    }
  }
  vector<ll> dp1(5000*5000+1, -inf);
  for (int i = 0; i <= 5000 * 5000; i++) {
    if (0 <= i + dp[i] && i + dp[i] <= 5000*5000) {
      dp1[i + dp[i]] = 0;
    }
  }
  rep(k, 3) {
    for (int i = 5000*5000; i >= b[k]; i--) {
      chmax(dp1[i - b[k]], dp1[i] + a[k]);
    }
  }
  ll ans = 0;
  for (int i = 0; i <= 5000*5000; i++) {
    ans = max(ans, i + dp1[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 390912
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
set<int> enum_div(int n)//nの約数を列挙
{
	set<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.insert(i);
			if(i*i!=n)
			{
				ret.insert(n/i);
			}
		}
	}
	return ret;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;

    set<int> st = enum_div(N - 1);
    set<int> st2 = enum_div(N);
    for(auto& e: st2) st.insert(e);
    st.erase(1);
    st.insert(2);
    st.insert(N);
    int ans = 0;
    for(auto e: st) {
        int num = N;
        while(num % e == 0) num /= e;
        if(num % e == 1) ans++;
    } 
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 4120
#include<bits/stdc++.h>
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
const int N=505;
int color[3][N],change[N][N],x[N][N];
int n,m,ans=1e9;
vii v[3];


int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			v[(i+j)%3].pb(mp(i-1,j-1));
	for(int i=0;i<m;i++)
		for(int j=0;j<m;j++)
			cin>>change[i][j];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>x[i][j],x[i][j]--;
	for(int i=0;i<3;i++)
		for(int j=0;j<m;j++)
			for(int k=0;k<v[i].size();k++)
				color[i][j]+=change[x[v[i][k].F][v[i][k].S]][j];
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(i==j)continue;
			for(int k=0;k<m;k++)
			{
				if(k==i||k==j)continue;
				ans=min(ans,color[0][i]+color[1][j]+color[2][k]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3364
#include <bits/stdc++.h>
using namespace std;
int N, L;

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

    vector<int> taste(N, 0);
    int min = 1000000;
    int num = 0;
    int sum = 0;
    for(int i = 0; i < N; ++i) {
        taste.at(i) = L + i;
        int r = abs(taste.at(i) - 0);
        if(r < min) {
            min = r;
            num = i;
        }
    }

    for(int i = 0; i < N; ++i) {
        sum += taste.at(i);
    }

    cout << sum - taste.at(num) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    string s;
    cin>>s;
    int a=(s[0]-'0')*10+(s[1]-'0');
    int b=(s[2]-'0')*10+(s[3]-'0');
    if(a==0&&b==0){
        cout<<"NA"<<endl;
        return 0;
    }
    if(a==0&&b>12){
        cout<<"NA"<<endl;
        return 0;
    }
    if(a>12&&b==0){
        cout<<"NA"<<endl;
        return 0;
    }
    if(a==0&&b<13){
        cout<<"YYMM"<<endl;

    }
    if(b==0&&a<13){
        cout<<"MMYY"<<endl;
    }

    if(a>12&&b>12){
        cout<<"NA"<<endl;
        return 0;
    }

    if(0<a&&a<=12){

        if(0<b&&b<=12){
            cout<<"AMBIGUOUS"<<endl;
            return 0;
        }else if(b>12){
            cout<<"MMYY"<<endl;
            return 0;
        }

    }else if(a>12){
        if(b<=12&&b>0){
            cout<<"YYMM"<<endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int A = sc.nextInt();
	    int B = sc.nextInt();
	    
	    int byTrain = N * A;
	    int byTaxi = B;
	    
	    System.out.println(Math.min(byTrain, byTaxi));
	}	
}	

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;

bool isPrime(ll n)
{
	if(n==1||n==2||n==3||n==5||n==7)
		return 1;
	else
	{
		ll i,j,k,l,m;
		for(i=2;i<=sqrt(n);i++)
		{
			if(n%i==0)
				return 0;
		}
		return 1;
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	ll x,a;
	cin>>x>>a;
	if(x<a)
		cout<<0;
	else
		cout<<10;
	return 0;
}
	

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

using namespace std;

const string fir = "First";
const string sec = "Second";

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if( s[0] == s[n-1] ) {
    if( ( n - 2 ) & 1 ) puts(sec.c_str());
    else                puts(fir.c_str());
  } else {
    if( ( n - 2 ) & 1 ) puts(fir.c_str());
    else                puts(sec.c_str());
  }
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) { return false; }
    }

    return true;
};

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

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

template <class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    string S;
    cin >> S;
    YESNO(S[0] != S[1] || S[1] != S[2], "Yes", "No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int sum = 0;
  for(int i = 0; i<N; i++){
    int l,r;
    cin >> l >> r;
    sum += r-l+1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

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

fn main() {
    let N: usize = read();
    let orig: Vec<usize> = (0..N).map(|_| read()).collect();
    let mut sorted: Vec<usize> = orig.clone();
    sorted.sort();
    let min_median = sorted[(N - 1) / 2];
    let max_median = sorted[N / 2];
    for v in orig {
        if v <= min_median {
            println!("{}", max_median);
        } else {
            println!("{}", min_median);
        }
    }
}


Measured memory_bytes: 10364
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> l(n, 0);
    Rep(i, 1, n){
        if(s[i] == 'E') l[0]++;
    }
    Rep(i, 1, n){
        l[i] = l[i-1];
        if(s[i-1] == 'W') l[i]++;
        if(s[i] == 'E') l[i]--;
    }

    SORT(l);
    pr(l[0]);
}

Measured memory_bytes: 1796
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
	int n,i =0,k;
	cin >> n;
	vector<int>a(n+1);
	rep(i, n-1) {
		cin >> k;
		a.at(k)++;
	}
	rep2(i,1, n+1) {
		cout << a.at(i) << endl;
	}
	
	return 0;
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
typedef pair<ll,ll> P;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

ll maxN=1e9;
int main(){
    ll N,K,S; cin>>N>>K>>S;
    if(S<maxN){
        rep(i,N) {
            if(i<K) cout<<S<<' ';
            else cout<<S+1<<' ';
        }
        cout<<endl;
    }

    else {
        rep(i,N){
            if(i<K) cout<<S<<' ';
            else cout<<1<<' ';
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1280
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL memo[101010];

int main(){
    
    // 1. 入力情報.
    int N, a, b, c, Q;
    LL S = 0;
    scanf("%d", &N);
    rep(i, N){
        scanf("%d", &a);
        S += (LL)a;
        memo[a]++;
    }
    scanf("%d", &Q);
    
    // 2. クエリ回答.
    rep(i, Q){
        // 2-1. 和を再計算.
        scanf("%d %d", &b, &c);
        LL t = memo[b];
        S = S - (LL)b * t + (LL)c * t;
        
        // 2-2. 操作結果を保存.
        memo[c] += t;
        memo[b] = 0;
        
        // 2-3. 出力.
        printf("%lld\n", S);
    }
    return 0;
    
}

Measured memory_bytes: 4560
def myAnswer(N:int)->int:
   K = len(str(N)) #桁数
   if(K == 1):return N
   c = N // 10**(K-1) #最上位の桁の数
   if((c*10**(K-1) + int("9"*(K-1)))<= N):
      return c + 9 *(K - 1)
   else:
      return c + 9 *(K - 1) -1 


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   print(myAnswer(N))

if __name__ == '__main__':
   main()

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

int main(){
    ll N;
    cin >> N;
    vector<ll> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    sort(all(vec));
    ll ans = 0;
    vector<ll> vec_ans(2 * N - 1);
    rep(i,N - 1){
        vec_ans[i * 2] = vec[i];
        vec_ans[i * 2 + 1] = vec[i];
    }
    vec_ans[2 * N - 2] = vec[N - 1];
    rep(i,N - 1){
        ans += vec_ans[2 * N - 2 - i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 7972
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  cout<<n*(n+1)/2<<endl;
  return 0;
}



Measured memory_bytes: 256
import sys
a, b = map(int, input().split())
if a != 0 and a%3 == 0:
	print("Possible")
	sys.exit()
if b != 0 and b%3 == 0:
	print("Possible")
	sys.exit()
if a != 0 and b != 0 and (a+b)%3 == 0:
	print("Possible")
	sys.exit()

print("Impossible")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>
#include <map>
#include <set>
#include <bitset>

#define forin(i, f, t) for(ll i = f; i < t; i++)

using namespace std;
using ll = long long;
using ULL = unsigned long long;
using Pair = pair<ll, ll>;

const int MAX = 500;
ll trains[MAX + 1][MAX + 1];
ll cft[MAX + 1][MAX + 1];

int main() {
    ll n, m, q;
    cin >> n >> m >> q;
    
    for (auto i = 0; i < m; i++) {
        ll l, r;
        cin >> l >> r;
        trains[l][r]++;
    }
    for (auto i = 0; i < MAX + 1; i++) {
        ll count = 0;
        for (auto j = i; j < MAX + 1; j++) {
            count += trains[i][j];
            cft[i][j] = count;
        }
    }
    
    for (auto i = 0; i < q; i++) {
        ll p, q;
        cin >> p >> q;
        ll sum = 0;
        for (auto k = p; k <= q; k++) {
            sum += cft[k][q];
        }
        cout << sum << endl;
    }
    
}



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

int main(){
    ll int a,b,x;
    cin>>a>>b>>x;
    ll int n,m;
    n=a/x;
    m=b/x;
    cout<<m-n+(a%x==0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int m,n,d[511];
	bool b[255],e[255];
	queue<int> q;
	for(;;){
		scanf("%d",&m);
		if(!m)break;
		scanf("%d",&n);
		rep(i,511)d[i]=0;
		rep(i,255)b[i]=e[i]=0;
		rep(i,n)scanf("%d",d+i+1);
		int f=1;
		while(f){
			f=0;
			for(int i=n;i>=0;i--){
				reps(j,1,m){
					int c=d[i+j]+i+j;
					if(!b[i])if(c>n || (in(c,0,n) && b[c])){
						b[i]=1;
						f=1;
						break;
					}
				}
			}
		}
		f=b[0];
		e[0]=1;
		q.push(0);
		while(!q.empty()){
			int p=q.front();
			q.pop();
			reps(i,1,m){
				int c=d[p+i]+i+p;
				if(in(c,0,n) && !e[c]){
					if(b[c]){
						e[c]=1;
						q.push(c);
					}
					else f=0;
				}
			}
			if(!f)while(!q.empty())q.pop();
		}
		puts(f?"OK":"NG");
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define chmax(x, v) x = max(x, v)
#define chmin(x, v) x = min(x, v)
#define OO pow(10, 9)+1
using namespace std;

signed main()
{
    int nb_items, t_sac;
    cin >> nb_items >> t_sac;
    
    int t_item[nb_items], v_item[nb_items];
    for (int i=0;i<nb_items;++i)cin>>t_item[i]>>v_item[i];
    
    int dp[100*1000+1];
    for (int i=0;i<=100*1000;++i)dp[i]=OO;
    dp[0] = 0;
    
    for (int item = 0; item < nb_items; ++ item)
    {
        for (int v_cur = 100*1000; v_cur >= v_item[item]; --v_cur)
        {
            if (dp[v_cur-v_item[item]]  + t_item[item] <=t_sac) chmin(dp[v_cur], dp[v_cur - v_item[item]] + t_item[item]);
            
        }
    }
   int i = 100*1000;
   while ( dp[i] == OO) --i;
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define sc(x) cin >> x
#define sc2(x, y) cin >> x >> y
#define sc3(x, y, z) cin >> x >> y >> z
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define debugn(i, n, a) rep(i, n)cout << " --- " << a[i] << "\n";
#define debugin(i, n, a) rep(i, n)printf(" --- %10d\n", a[i])
#define debugi2n(i, n, a, b) rep(i, n)printf(" --- %10d %10d\n", a[i], b[i])
#define debugiin(i, n, a) rep(i, n)printf(" --- %10d %10d\n", a[i].first, a[i].second)
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;;testcase++){
    int(w);
    if(w == 0)break;
    int(n);

    int v[n], d[n];
    rep(i, n)scanf("%d,%d", &v[i], &d[i]);

    ll dp[n + 1][w + 1];
    rep(i, n + 1)rep(j, w + 1)dp[i][j] = 0;

    rep1(i, n + 1)rep(j, w + 1){
      dp[i][j] = dp[i - 1][j];
      if(j - d[i - 1] >= 0)dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - d[i - 1]] + v[i - 1]);
    }

    per(i, w + 1)if(dp[n][w] != dp[n][i])break;
    i++;
    printf("Case %d:\n%lld\n%d\n", testcase + 1, dp[n][w], i);
  }
  return 0;
}

Measured memory_bytes: 9024