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

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var s = sc.next();
		sc.close();

		if (s.equals(s.toUpperCase())){
			s = "A";
		} else {
			s = "a";
		}

		System.out.println(s);
	}
}


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

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

int main() {
    string str;
    cin >> str;
    long long k;
    cin >> k;
    char ans = '1';
    for(int i=0;i<k;i++){
        if( i == str.length() || str.at(i) != '1' ){
            ans = str.at(i);
            break;
        }
    }
    cout << ans;
    return 0;
}

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

using namespace std;

int main(void){
   int N;
   cin >> N;
   int a[N];
   long long sum = 0;
   for(int i = 0; i < N; i++)
   {
       cin >> a[i] ;
   }

   int max = a[0];

    for(int i =0; i < N; i++)
    {
        if(max > a[i])
        {
            sum = sum +(max-a[i]);
        }
        if(max < a[i])
        {
            max = a[i];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 4372
def ipt(N=0,switch=0):
    if N == 0:
        return list(map(int,input().split()))
    else:
        if switch==0:
            return [list(map(int,input().split())) for _ in range(N)]
        else:
            return [int(input()) for _ in range(N)]

N=int(input())
print(len(set(ipt(N,1))))

Measured memory_bytes: 3060
n = gets.chomp.to_i
rank = 8
if n >= 400 && n <= 599
  rank = 8
elsif n >= 600 && n <= 799
  rank = 7
elsif n >= 800 && n <= 999
  rank = 6
elsif n >= 1000 && n <= 1199
  rank = 5
elsif n >= 1200 && n <= 1399
  rank = 4
elsif n >= 1400 && n <= 1599
  rank = 3
elsif n >= 1600 && n <= 1799
  rank = 2
elsif n >= 1800 && n <= 1999
  rank = 1
end
puts rank

Measured memory_bytes: 14360
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,k,l,t;
    scanf("%d%d",&n,&k);
    int a[n+1];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    l=0;
    for(i=0;i<k;i++){
        l+=a[i];
    }
    printf("%d\n",l);
    return 0;
}


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

int main() {
   int a,b;
   cin>>a>>b;
  int n=0;
  
  if(a>b){ 
    for(int i=0; i<a; i++){
      n=n*10+b;
    }
  }
  else{
    for(int i=0; i<b; i++){
      n=n*10+a;
    }
  }
  
  cout << n << endl;
}

      

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static final int MOD = 1000000000 + 7;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int k = Integer.parseInt(scan.next());
        scan.close();

        long sum = 0;
        for (long i = k; i <= n + 1; i++) {
            sum += (long)(i * (2 * n - i + 1) - i * (i - 1)) / 2 + 1;
            sum %= MOD;
        }

        System.out.println(sum);
    }

}

Measured memory_bytes: 35696
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC002_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var z = scan();
            var a = scan();
            int last=0;
            bool flag=false;
            for (int i = 0; i < z[0]-1; i++)
            {
                if (a[i]+a[i+1]>=z[1])
                {
                    last = i + 1;
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                var sb = new StringBuilder();
                sb.AppendLine("Possible");
                for (int i = 1; i < last; i++)
                {
                    sb.AppendLine(i.ToString());
                }
                for (int i = z[0]-1; i > last; i--)
                {
                    sb.AppendLine(i.ToString());
                }
                sb.AppendLine(last.ToString());
                Console.Write(sb);
            }
            else
            {
                Console.WriteLine("Impossible");
            }
                   
        }
        static int[] scan()
        {
            return
                Array.ConvertAll
                (Console.ReadLine().Split(' '), int.Parse);
        }
    }
}


Measured memory_bytes: 19672
X, Y = map(int,input().split())
def combination(n,r,mod=10**9+7):
    n1 = n+1
    r = min(r,n-r)
    numer = denom = 1
    for i in range(1,r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom,mod-2,mod) % mod

#y=2x以下かつy=(1/2)x以上の位置にいなくてはいけない
if (X+Y) % 3 != 0 or not (X<=2*Y and Y <=2*X):
    ans = 0
else:
    N = (X+Y)//3
    r = Y - N
    ans = combination(N,r)
print(ans)

Measured memory_bytes: 3316
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;

public class Main {
    public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      int count = scanner.nextInt();
      
      Map<Integer, Integer> students = new HashMap();
      for (int i = 0 ; i < count; i++) {
      	int num = scanner.nextInt();
        students.put(num, i + 1);
      }

      for (int i = 0 ; i < count; i++) {
        System.out.print(students.get(i + 1) + " ");
      }
    }
}

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

int main(){
  long long A, B, K;
  cin >> A >> B >> K;
  if(A > K) A -= K;
  else{
    K -= A;
    A = 0;
    B -= K;
    B = max(B,0LL);
  }
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <bitset>
#include <math.h>
#include <vector>
#include <set>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;

using namespace std;

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if((B / A) > C) cout << C << endl;
    else cout << B / A << endl;

    return 0;
}

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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int a[N], b[N];
int main()
{
	int n, m;
	cin >> n >> m;
	int x = 1, y = n;
	set<int> s;
	for(int i = 1; i <= m; i ++)
	{
	if(s.count(abs(x-y)) || s.count(n-abs(x-y)) || abs(x-y)*2==n)
		y --;
		a[i] = x, b[i] = y;
		x ++;
		y--; 
		s.insert(abs(a[i] - b[i]));
		s.insert(n-abs(a[i]-b[i]));
	}
//	for(int i = 1; i <= n; i ++, cout << '\n')
		for(int i = 1; i <= m; i ++)
		{
			cout << a[i] << ' ' << b[i] << '\n';
//			cout << a[i] << ' ' << b[i] << ' ' << abs(a[i] - b[i]) << "      ";
//			a[i] ++;
//			if(a[i] > n) a[i] = 1;
//			b[i] ++;
//			if(b[i] > n)
//				b[i] = 1;
		}




	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

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

#define ONLINE_JUDGE

using namespace std;
#ifndef ONLINE_JUDGE
#define wi(x) cerr << #x << ": " << (x) << '\n';
#else
#define wi(x)
#endif


typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
template<typename T>
inline T getNum() {
    T k = 0;
    int c = getchar(), f = 1;
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
    for (; isdigit(c); c = getchar()) k = k * 10 + c - '0';
    return k * f;
}
#define gn() getNum<int>()
#define gl() getNum<ll>()
clock_t opt, edt;
inline void init() {
#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
//    freopen("../input.txt", "w", stdout);
    opt = clock();
#endif
}

inline void tini() {
#ifndef ONLINE_JUDGE
    edt = clock();
    cerr << "\n#cost: " <<  (double)(edt - opt) / CLOCKS_PER_SEC << "s\n";
#endif
}

bool ish(int l, int r, string s) {
    for (int i = l, j = r; i < j; i++, j--) {
        if (s[i] != s[j]) return false;
    }
    return true;
}

int a[200050];

int main() {
    init();
///////////////////////////////////////////////////////////////////////////////

    int n = gn();
    map<int, ll> cnt;
    ll ANS = 0;
    for (int i = 0; i < n; i++)
        cnt[a[i] = gn()]++;
    for (auto c : cnt) {
        ANS += 1ll * (c.second * (c.second - 1)) / 2;
    }
    for (int i = 0; i < n; i++)
        cout << ANS - cnt[a[i]] + 1 << '\n';


///////////////////////////////////////////////////////////////////////////////
    tini();
}



/*
char Ma[MAXN*2];
int Mp[MAXN*2];
void Manacher(char s[],int len){
    int l=0;
    Ma[l++]='$';
    Ma[l++]='#';
    for(int i=0;i<len;i++){
        Ma[l++]=s[i];
        Ma[l++]='#';
    }
    Ma[l]=0;
    int mx=0,id=0;
    for(int i=0;i<l;i++){
        Mp[i]=mx>i?min(Mp[2*id−i],mx−i):1;
        while(Ma[i+Mp[i]]==Ma[i−Mp[i]])Mp[i]++;
        if(i+Mp[i]>mx){
            mx=i+Mp[i];
            id=i;
        }
    }
}
*/
 /*
 * * abaaba
 * * i:     0 1 2 3 4 5 6 7 8 9 10 11 12 13
 * * Ma[i]: $ # a # b # a # a # b  #  a  #
 * * Mp[i]: 1 1 2 1 4 1 2 7 2 1 4  1  2  1
 */
 /*
char s[MAXN];
int main(){
    while(scanf("%s",s)==1){
        int len=strlen(s);
        Manacher(s,len);
        int ans=0;
        for(int i=0;i<2*len+2;i++)
            ans=max(ans,Mp[i]−1);
        printf("%d\n",ans);
    }
    return 0;
}
*/

Measured memory_bytes: 10240
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;
int a[mx];
int b[mx];
int c[mx];
int n,m;
int t;
int res;
string str;
int main(){
	cin>>n;
	reg(i,1,n){
		scanf("%d",a+i);
	}
	reg(i,1,n){
		scanf("%d",b+i);
	}
	reg(i,1,n-1){
		scanf("%d",c+i);
	}
	reg(i,1,n){
		res+=b[a[i]];
		if(a[i+1]-a[i]==1){
			res+=c[a[i]];
		}
	}
	printf("%d\n",res);
	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);
    	String[] inputNumber = sc.nextLine().split(" ");
    	int tap = Integer.parseInt(inputNumber[0]);
    	int neededTap = Integer.parseInt(inputNumber[1]);
    	
    	int canUse = 1;
    	int result = 0;
    	while(canUse<neededTap) {
    		canUse += tap -1;
    		result++;
    	}
    		
    		
    	
    	System.out.println(result);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2002;

int n, l[MAX], r[MAX];
string a, b;

int solve(int d) {
	int last = n-1;
	while(!(b[last] - '0')) --last;
	for(int i = 0; i < n; i++) {
		if(b[i]-'0') last = i;
		l[i] = min(d, -((i+n-last) % n));
	}
	last = 0;
	while(!(b[last] - '0')) ++last;
	for(int i = n-1; i >= 0; i--) {
		if(b[i]-'0') last = i;
		r[i] = max(d, (last+n-i) % n);
	}

	int ret = INT_MAX, add = 0;
	vector<int> p;
	for(int i = 0; i < n; i++) if(a[i] != b[(i+n+d) % n]) p.push_back(i);

	if(d < 0) {
		sort(p.begin(), p.end(), [] (int x, int y) { return l[x] < l[y]; });
		int curr = 0;
		for(int i = 0; i < p.size() && l[p[i]] <= d; i++) {
			ret = min((curr - l[p[i]]) * 2 + d, ret);
			curr = max(r[p[i]], curr);
			++add;
		}
		if(p.empty() || l[p.size()-1] <= d) ret = min((curr - d) * 2 + d, ret);
	} else {
		sort(p.begin(), p.end(), [] (int x, int y) { return r[x] > r[y]; });
		int curr = 0;
		for(int i = 0; i < p.size() && r[p[i]] >= d; i++) {
			ret = min((r[p[i]] - curr) * 2 - d, ret);
			curr = min(l[p[i]], curr);
			++add;
		}
		if(p.empty() || r[p.size()-1] >= d) ret = min((d - curr) * 2 - d, ret);
	}
	
	return ret + add;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> a >> b;
	n = a.length();
	bool a1 = 0, b1 = 0;
	for(int i = 0; i < n; i++) a1 |= a[i]-'0', b1 |= b[i]-'0';
	if(!b1) cout << (a1 ? -1 : 0), exit(0);

	int ans = INT_MAX;
	for(int d = -n+1; d < n; d++) ans = min(solve(d), ans);
	cout << ans;
}

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

int main(){
    double x1, y1, x2, y2, distance;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    distance=sqrt((pow(x2-x1, 2)+pow(y2-y1, 2)));
    printf("%f\n", distance);

    return 0;
}


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

int main(){
	int n, KStep,k, start, end, j;
	scanf("%d%d", &n,&k);
	int weight[n+1];
	vector<int> ans(n+1, INT_MAX);
	for(int i=0;i<n;i++)
		scanf("%d", &weight[i]);
	ans[0] = 0;
	ans[1] = abs(weight[1] - weight[0]);
	for(int i=2;i<n;i++){

		if(i<k) j = 0;
		else j = i-k;

		for(; j< i;j++){
			KStep = abs(weight[i] - weight[j]) + ans[j];
			if(ans[i] > KStep) ans[i] = KStep;
		}
	}
	/*for(int i=0;i<n;i++)
		printf("%d %d|", i, ans[i]);
	printf("\n");*/
	printf("%d\n", ans[n-1]);

}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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


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

using namespace std;
using ll = long long;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, t;
    cin >> s >> t;
    int ans = t.size();
    for(int i = 0; i < s.size() - t.size() + 1; i++) {
        int cur = 0;
        for(int j = 0; j < t.size(); j++) {
            if(s[i + j] != t[j]) {
                cur++;
            }
        }
        if(cur < ans) {
            ans = cur;
        }
    }
    cout << ans;
    return 0;
}

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

int main(void){
    int ans=0 ;
    char s[120] ;
    cin >> s ;
    if (strlen(s)%2==0){
        for (int i=0; i<strlen(s)/2; i++){
            if (s[i]!=s[strlen(s)-1-i]){
                ans++ ;
            }
        }
    } else {
        for (int i=0; i<(strlen(s)-1)/2; i++){
            if (s[i]!=s[strlen(s)-1-i]){
                ans++ ;
            }
        }
    }
    cout << ans << endl ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if(b==100){
    int c = a*1000 + b;
    
    for(int i=0; i<c; i++){
      if(c == i * i){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  if(b>=10 && b<=99){
    int c = a*100 + b;
    
    for(int i=0; i<c; i++){
      if(c == i * i){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  if(b<10){
    int c = a*10 + b;
    
    for(int i=0; i<c; i++){
      if(c == i * i){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

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

int main(){
    int x,i,m;
    cin>>x;
    for(i=1;i<=x;i++){
        if(i%3==0){
            cout<<" "<<i;
        }
        else{
            m=i;
            while(m!=0){
                if(m%10==3){
                    cout<<" "<<i;
                    break;
                }
                m/=10;
            }
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3100
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadLong;
            long sum = 0;
            for (long i = 1; i < N; i++)
            {
                sum += i;
            }
            Console.WriteLine(sum);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(void)
{
  long int a,b;
 
  while(scanf("%ld %ld",&a,&b)!=EOF){
    long int min;
	min=(a>b?b:a);
    long int i,j,count=0;
	long int s[31];
	int e=1;
	for(j=0;;j++){
	  if(e==0)
	    break;
	  e=0;
	  for(i=2;i<sqrt(min);i++){
	    if(a%i==0 && b%i==0){
		  e=1;
		  a/=i;
		  b/=i;
		  s[j]=i;
		  count+=1;
		  break;
		}
      }
	}
	long int minkou=1,maxkou=1;
	for(i=0;i<count;i++)
	  minkou*=s[i];
	maxkou=minkou*a*b;
	printf("%ld %ld\n",minkou,maxkou);
  }
	

  return 0;
}

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

int main() {
    double x1, y1, x2, y2, x3, y3, xp, yp;

    while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
        double xab = x2 - x1;
        double xbp = xp - x2;
        double xbc = x3 - x2;
        double xcp = xp - x3;
        double xca = x1 - x3;
        double xap = xp - x1;

        double yab = y2 - y1;
        double ybp = yp - y2;
        double ybc = y3 - y2;
        double ycp = yp - y3;
        double yca = y1 - y3;
        double yap = yp - y1;

        double za = xab * ybp - yab * xbp;
        double zb = xbc * ycp - ybc * xcp;
        double zc = xca * yap - yca * xap;

        if ((za < 0 && zb < 0 && zc < 0) || (za > 0 && zb > 0 && zc > 0)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }

        if (cin.eof()) break;
    }

    return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;
int gcd(Int a, Int b) {
 return b != 0 ? gcd(b, a % b) : a;
}
int lcm(Int a, Int b) {
 return a / gcd(a, b)*b;
}

int main(){
  Int n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  Int ans = 0;
  Int mi=min({a,b,c,d,e});
  ans = (n+mi-1)/mi;
  ans+=4;
  cout << ans << endl;
}


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

using namespace std;

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if(k > a){
        ans += a;
        k-=a;
    }
    else{
        cout << k;
        return 0;
    }
    if(k < b){
        cout << ans;
    }
    else{
        k-=b;
    }
    ans += (k*-1);
    cout << ans;
}

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

#define ll long long
#define ar array

const int mxN=2e3;
int n, x, y, ans[mxN];

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

    cin >> n >> x >> y, --x, --y;
    for(int i=0; i<n; ++i) {
        for(int j=i+1; j<n; ++j) {
            int d=min(j-i, abs(i-x)+1+abs(j-y));
            ++ans[d];
        }
    }
    for(int i=1; i<n; ++i)
        cout << ans[i] << "\n";
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;
use std::collections::BTreeSet;

fn main() {
    input! {
        n: usize,
        k: usize,
        v: [Usize1; n]
    }

    let mut loo = Vec::new();
    loo.push(0);
    let mut set = BTreeSet::new();
    set.insert(0);
    let mut len = 1;
    let mut next = v[0];
    while !set.contains(&next) {
        loo.push(next);
        set.insert(next);
        len += 1;
        next = v[next];
    }

    let mut index = 0;
    for i in 0..len {
        if loo[i] == next {
            index = i;
            break;
        }
    }

    let ans = {
        if k < index {
            k
        } else {
            index+(k-index)%(len-index)
        }
    };

    println!("{}",1+loo[ans])
}


Measured memory_bytes: 9676
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define int64_t long long

using namespace std;

void printVec(std::vector<char> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

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

  //sort(td.begin(), td.end(), [](auto& x, auto& y){return x[0] > y[0];});

  int n;
  std::cin >> n;
  int dp[n] = {};
  vector<vector<int64_t>> arr(n, vector<int64_t>(4,0));
  for (int64_t i = 0; i < n; i++) {
    std::cin >> arr[i][0] >> arr[i][1];
    arr[i][2] = arr[i][0] + arr[i][1];
    // std::cout << arr[1][0] <<"-" << arr[i][1] << '\n';
    arr[i][3] = i;
  }

  vector<vector<int64_t>> arr2(arr.begin(), arr.end());
  // sort(arr.begin(), arr.end(), [](auto& x, auto& y){return x[1] > y[1];});
  // sort(arr.begin(), arr.end(), [](auto& x, auto& y){return x[0] > y[0];});
  sort(arr.begin(), arr.end(), [](auto& x, auto& y){return x[2] > y[2];});

  // sort(arr2.begin(), arr2.end(), [](auto& x, auto& y){return x[0] > y[0];});
  // sort(arr2.begin(), arr2.end(), [](auto& x, auto& y){return x[1] > y[1];});
  sort(arr2.begin(), arr2.end(), [](auto& x, auto& y){return x[2] > y[2];});

  int64_t takahashi = 0;
  int64_t aoki = 0;

  int t = 0,a = 0;

  // std::cout << "" << '\n';
  // for (int64_t i = 0; i < n; i++) {
  //   std::cout << arr[i][0] <<" " <<  arr[i][1] <<" " << arr[i][2] << "      " << arr2[i][0] <<" " << arr2[i][1] <<" " << arr2[i][2] <<" " << '\n';
  // }
  // std::cout << "" << '\n';

  for (int64_t i = 0; i < n; i++) {
    while(t < n && dp[arr[t][3]] != 0 ) t++;
    if(t >= n) break;
    // std::cout << arr[t][0] <<  arr[t][1] << '\n';
    takahashi += arr[t][0];
    dp[arr[t][3]] = 1;

    while(a < n && dp[arr2[a][3]] != 0) a++;
    if(a >= n) break;
    // std::cout << arr2[a][0] << arr2[a][1] << '\n';
    aoki += arr2[a][1];
    dp[arr2[a][3]] = 1;
  }

  std::cout << takahashi - aoki << '\n';

  return 0;
}


Measured memory_bytes: 14720
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<set>
#include<algorithm>
#include<map>
#include<ctime>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps = 1e-8;
const int maxn = 200009;
const int inf = 100000009;
const ll mod = 1e9 + 7;
bool dp[81][81][160 * 80];
int a[89][89];
int main()
{
	int h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j)
			scanf("%d", &a[i][j]);
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j) {
			int tmp;
			scanf("%d", &tmp);
			a[i][j] = abs(a[i][j] - tmp);
		}
	dp[1][1][a[1][1]] = true;
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			for (int io = 0; io < 160 * 80; ++io) {
				if (dp[i][j][io]) {
					//cout << i << "," << j << "," << io << endl;
					int p1[] = { 1,0 }, p2[] = { 0,1 };
					for (int k = 0; k < 2; ++k) {
						int p = i + p1[k], q = j + p2[k];
						if (p <= h && q <= w) {
							dp[p][q][io + a[p][q]] = 1;
							dp[p][q][abs(io - a[p][q])] = 1;
						}
					}
				}
			}
		}
	}
	for (int i = 0; i < 160 * 80; ++i) {
		if (dp[h][w][i]) {
			cout << i << endl;
			break;
		}
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 80896
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC107A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, i;
            var word = Console.ReadLine().Split(' ');
            n = int.Parse(word[0]);
            i = int.Parse(word[1]);

            Console.WriteLine(n - i + 1);
            Console.ReadKey();
        }
    }
}


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

template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

int main() {
    int N; cin >> N;
    vector<vector<int>> A(N, vector<int>(N));
    rep(i, N) rep(j, N) cin >> A[i][j];
    vector<int64_t> score(1 << N), dp(1 << N);
    rep(oi, 1 << N) {
        bitset<22> OI(oi);
        rep(i, N) rep(j, N) if(OI[i] && OI[j]) score[oi] += A[i][j];
        score[oi] /= 2;
        for(int sub = oi; sub > 0; sub = (sub - 1) & oi) {
            chmax(dp[oi], dp[oi ^ sub] + score[sub]);
        }
    }
    cout << dp[(1 << N) - 1] << '\n';
}


Measured memory_bytes: 4316
#include <iostream>

using namespace std;

int main(){
  int n, m;
  int count = 0;
  int div = 100000000;
  cin >> n;
  m = n;
  while (div > 0) {
    count += m / div;
    m = m % div;
    div = div/10;
  }
  if (n % count == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>

int main(){
std::string line;
std::cin >> line;
unsigned int A = atoi(line.c_str());
std::cin >> line;
unsigned int B = atoi(line.c_str());

A = (A == 1 ? 14 : A);
B = (B == 1 ? 14 : B);

if (A == B){
std::cout << "Draw" << std::endl;
}
else if (A > B){
std::cout << "Alice" << std::endl;
}
else {
std::cout << "Bob" << std::endl;
}

return 0;
}

Measured memory_bytes: 256
input()
arr = list(map(int, input().split()))
count = 0
for i in range(len(arr)):
    min = arr[i]
    min_index = i
    for j in range(i+1, len(arr)):
        if arr[j] < min:
            min_index = j
            min = arr[j]
    if i != min_index:
        count += 1
        t = arr[i]
        arr[i] = min
        arr[min_index] = t
print(" ".join(map(str, arr)))
print(count)
    


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
        int a, b, k;
        cin >> a >> b >> k;

        int x = min(a, k);
        a -= x;
        k -= x;

        if(k)
            b -= min(b, k);

        cout << a << ' ' << b << '\n'; 


    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 256
mod=998244353
n,s=map(int,input().split())
a=list(map(int,input().split()))

dp=[[0]*(s+1) for _ in range(n)]

if a[0]<=s: dp[0][a[0]]=1

for i in range(1,n):
    for k in range(s+1):
        dp[i][k]=dp[i-1][k]
        if k-a[i]>0: dp[i][k]+=dp[i-1][k-a[i]]
        if a[i]==k: dp[i][k]+=i+1
        dp[i][k]%=mod

ans=0
for i in range(n):
    ans+=dp[i][s]
    ans%=mod
print(ans)

Measured memory_bytes: 112604
inputNumN = list(map(int, input().split()))
N = inputNumN[0]
Q = inputNumN[1]

AB = {}
for i in range(N - 1):
    inputNumAB = list(map(int, input().split()))
    if not AB.get(inputNumAB[0]):
        AB[inputNumAB[0]] = []
    AB[inputNumAB[0]].append(inputNumAB[1])

result = [0] * N
for i in range(Q):
    inputNumPQ = list(map(int, input().split()))
    result[inputNumPQ[0] - 1] += inputNumPQ[1]

for A, B in AB.items():
    for b in B:
        result[b - 1] += result[A - 1]

for r in result:
    print(r, end=' ')


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

int main()
{
    int n,k;
    std::cin >> n >> k;
    std::vector<int> a(n);
    for(int i = 0; i < n; i++)std::cin >> a[i];
    std::sort(a.begin(),a.end(),std::greater<int>());
    long long res = 0;
    for(int i = k; i < n; i++)res += a[i];
    std::cout << res << std::endl;
    
}

Measured memory_bytes: 1024
#include<math.h>
#include<iostream>
#define int long long
using namespace std;
int check(int x,int y){
	int sum=0;
	while(y){
		sum+=y%x;
		y/=x;
	}
	return sum;
}
signed main(){
	int n,s,i,j,k,l;
	cin>>n>>s;
	if(n<s){
		cout<<-1;
		return 0;
	}
	for(i=2;i<=sqrt(n);i++){
		if(check(i,n)==s){
			cout<<i;
			return 0;
		}
	}
	for(i=sqrt(n);i>=1;i--){
		if((n-s)%i==0){
			if((n-s)/i+1>sqrt(n)&&n-((n-s)/i+1)*i<(n-s)/i+1&&n-((n-s)/i+1)*i>=0){
				cout<<(n-s)/i+1;
				return 0;
			}
		}
	}
	if(n==s){
		cout<<n+1;
		return 0;
	}
	cout<<-1;
}

Measured memory_bytes: 384
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
sum = 0

for i in range(len(A1)-1):
    temp = 0
    for j, (k, l) in enumerate(zip(A1[1:], A2[:-1])):
        if j >= i:
            temp += l
        else: 
            temp += k
    sum = max(sum, temp)

print(sum + A1[0] + A2[-1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;

int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = INT_MAX;
    for(ll i = 0; i <= 2 * (x + y); i += 2) {
        ll p1 = i / 2;
        ll p2 = i / 2;
        ll tmp = i * c;
        tmp += max(0LL, x - p1) * a;
        tmp += max(0LL, y - p2) * b;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

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

int main(){
  int i,a,b,c,N,ct,res;
  cin >> N;
  res = 0;
  ct = 0;
  c = 0;
  for(i=0;i<N;i++){
    cin >> a >> b;
    if (a == b)
      ct++;
    else
      ct = 0;
    res = max(res,ct);
  }
  if (res >= 3)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
  ll A,B,C,count=0,flag=0,a,b,c;
  cin>>A>>B>>C;
  while(true){
    if(A%2==1 || B%2==1 || C%2==1){
      flag=0;
      break;
    }
    if(A==B && B==C && C==A){
      flag=1;
      break;
    }
    a=A; b=B; c=C;
    A=(b+c)/2;
    B=(a+c)/2;
    C=(a+b)/2;
    count++;
  }
  if(flag) cout<<-1<<endl;
  else cout<<count<<endl;
}


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

int main()
{
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());
	cout << (s < t ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int A,B;
    cin >>A>>B;
    int x=A+B;
    if(x>23) x-=24;
    cout << x << endl;



}


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

int main() {
    long long N;
    cin >> N;
    vector<long long> a(N);
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    long long ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        if (itr->first <= itr->second) {
            ans += itr->second - itr->first;
        } else {
            ans += itr->second;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5504
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(long long i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(long long i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll>pll;

int main() {
	string s;
	cin>>s;

	long long ans=0,b=0;
	REP(i,s.length()){
		if(s[i]=='B'){
			b++;
		}
		else{
			ans+=b;
		}
	}
	

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) (x&-x)
using namespace std;
const int N = 1e5+7, M = 1e3;
int a[N];
vector<int> vec[M];
int main()
{
    int n;
    scanf("%d", &n);n *= 2;
    if(n==1)
    {
        puts("No");
        return 0;
    }
    for(int i = 1; i*(i+1) <= n; i++)
    {
        if(i*(i+1)==n)
        {
            puts("Yes");
            int siz = i, m = i+1, p = 0;
            for(int i = 1; i <= m; i++)
            {
                int last = p;
                while(vec[i].size()<siz)
                {
                    vec[i].push_back(++p);
                }
                for(int j = i+1; j <= m; j++)
                {
                    vec[j].push_back(++last);
                }
            }
            printf("%d\n", m);
            for(int i = 1; i <= m; i++)
            {
                printf("%d", siz);
                for(int j = 0; j < siz; j++)
                {
                    printf(" %d", vec[i][j]);
                }
                puts("");
            }
            return 0;
        }
    }
    puts("No");
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s; cin >> s;
    int ans;
    if(s == "SUN") ans = 7;
    else if(s == "MON") ans =6;
    else if(s == "TUE") ans = 5;
    else if(s == "WED") ans = 4;
    else if(s == "Thu") ans = 3;
    else if(s == "FRI") ans = 2;
    else if(s == "SAT") ans = 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int[] a = new int[n];
			int[] b = new int[n];
			PriorityQueue<Integer> p = new PriorityQueue<Integer>();
			
			for(int i=0;i<n;i++){
				a[i] = sc.nextInt();
				b[i] = sc.nextInt();
				if(p.contains(b[i])==false) p.add(b[i]);
			}
			
			int x;
			int sum = 0;
			boolean flag = true;
			while(p.size()!=0){
				x = p.poll();
				for(int i=0;i<n;i++){
					if(x==b[i]){
						sum += a[i];
						if(sum>x){
							flag = false;
							break;
						}
					}
				}
				if(flag==false) break;
			}
			if(flag==true) System.out.println("Yes");
			else System.out.println("No");
		}	
	}	
}

Measured memory_bytes: 24244
import sys
print = sys.stdout.write

def insert(key, queue):
    """priority queueに値を代入する.
    
    Args:
        key (int): priority queueに代入する数値.

    Notes:
        indexは扱いやすさのため1~nを想定してしている.
        配列値取得時にはpythonの仕様に合わせて-1としている.
    """
    queue.append(key)
    index = n
    if index == 1:
        return
    parent_index = index//2
    while parent_index and queue[parent_index-1] < key:
        queue[index-1] = queue[parent_index-1]
        index, parent_index = parent_index, parent_index//2
    queue[index-1] = key
    
def extract_max(queue):
    index = 1
    root = queue[0]
    l_index = index*2
    num = n
    while l_index < num:
        ql, qr = queue[l_index-1], queue[l_index]
        bigger = (l_index, ql) if ql > qr else (l_index+1, qr)
        if bigger[1] > root:
            next_index = bigger[0]
            queue[index-1] = queue[next_index-1]
            index = next_index
            l_index = index*2
        else:
            break
        
    if l_index == num:
        if queue[l_index-1] > root:
            queue[index-1] = queue[l_index-1]
            index = l_index
    queue[index-1] = root


def main():
    S = []
    global n
    n = 0
    for operation in sys.stdin.readlines():
        if operation[0] == "i":
            n += 1
            insert(int(operation[7:]), S)
        elif operation[1] == "x":
            print("{}\n".format(S[0]))
            S[0] = S.pop()
            n -= 1
            extract_max(S)
        elif operation == "end":
            break

if __name__ == "__main__":
    main()


Measured memory_bytes: 187196
n, h = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

a = sorted(a, reverse=True)
b = sorted(b, reverse=True)

ans = 0
i = 0
while i < n and b[i] > a[0]:
    h -= b[i]
    ans += 1
    if h <= 0:
        print(ans)
        exit()
    i += 1

print(ans + (h + a[0] - 1) // a[0])


Measured memory_bytes: 17816
N = int(input())
W = list(map(int,input().split()))


ans = 2 ** 30 + 1
for T in range(N+1):
    S1 = sum(W[0:T+1])
    S2 = sum(W[T+1:])
    ans = min(ans,abs(S1-S2))
    
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <math.h>
#include <limits.h>

using namespace std;

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

Measured memory_bytes: 256
#pragma G++ optimize(O2)
#pragma G++ optimize(O3)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
const int N = 16;
LL res[N];
struct node {
    int x, y, p;
}a[N];
int vis[N];
int dis[N];

void solve() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].p);
    }
    memset(res, 0x3f, sizeof res);

    // i：选择哪几个点上添加横线，1为添加，0为不添加
    for(int i = 0; i < (1 << n); i++) {
        int cnt = 0;
        for(int j = 0; j < n; j++) if((i >> j) & 1) vis[++cnt] = j + 1;

        // j:选择的点的所有状态，1为x方向，0为y方向
        for(int j = 0; j < (1 << cnt); j++) {

            for(int k = 1; k <= n; k++) dis[k] = min(abs(a[k].x), abs(a[k].y));

            for(int k = 0; k < cnt; k++) {
                if((j >> k) & 1) {
                    for(int t = 1; t <= n; t++) {
                        dis[t] = min(dis[t], abs(a[t].x - a[vis[k + 1]].x));
                    }
                }
                else {
                    for(int t = 1; t <= n; t++) {
                        dis[t] = min(dis[t], abs(a[t].y - a[vis[k + 1]].y));
                    }
                }
            }
            LL sum = 0;
            for(int k = 1; k <= n; k++) sum += (LL)dis[k] * a[k].p;
            res[cnt] = min(res[cnt], sum);
        }
    }
    for(int i = 0; i <= n; i++) printf("%lld\n", res[i]);
}

int main() {
//    freopen("in.txt", "r", stdin);
    solve();
    return 0;
}


Measured memory_bytes: 3796
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner n = new Scanner(System.in);
        int N = n.nextInt();
        int A[] = new int[N];
        for(int i=0; i < N; i++){
            A[i] = n.nextInt();
        }
        for(int i=0; i < N; i++){
            System.out.print(A[i]);
            if(i==N-1){
                System.out.println("");
            }
            else{
                System.out.print(" ");
            }
        }
        for(int i = 1; i <= N-1 ; i++){
            int v = A[i];
            int j = i - 1;
            while(j >= 0 && A[j] > v){
                A[j+1] = A[j];
                j--;
                A[j+1] = v;
            }
            for(int k=0; k<N; k++){
                System.out.print(A[k]);
                if(k == N-1){
                    System.out.println("");
                }
                else{
                    System.out.print(" ");
                }
            }
        }
    }
}


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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

int N, K;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif
  cout << setprecision(20);

  cin >> N >> K;
  int answer;
  if (K == 1) {
    answer = 0;
  }else {
    answer = N - K;
  }
  cout << answer << endl;

  return 0;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int INF = 1<<28;
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		List<int[]> list = new ArrayList<>();
		for(int i=0;i<m;i++) {
			int[] tmp = new int[2];
			tmp[0] = in.nextInt();
			if(tmp[0]==1) tmp[1] = 2;
			else if(tmp[0]==7) tmp[1] = 3;
			else if(tmp[0]==4) tmp[1] = 4;
			else if(tmp[0]==2 || tmp[0]==3 || tmp[0]==5) tmp[1] = 5;
			else if(tmp[0]==6 || tmp[0]==9) tmp[1] = 6;
			else tmp[1] = 7;
			list.add(tmp);
		}
		int[] dp = new int[n+1];
		for(int i=1;i<=n;i++) {
			dp[i] = -INF;
		}
		for(int i=2;i<=n;i++) {
			for(int j=0;j<list.size();j++) {
				int match = list.get(j)[1];
				if(i-match>=0) {
					dp[i] = Math.max(dp[i], dp[i-match]+1);
				}
			}
		}
		list.sort((a,b)->(-a[0]+b[0]));
		String ans = "";
		int i = n;
		int digit = dp[n];
		while(true) {
			boolean end = false;
			for(int ptr=0;ptr<list.size();ptr++) {
				if(digit==1) {
					if(i-list.get(ptr)[1]==0) {
						ans += list.get(ptr)[0];
						end = true;
						break;
					}
				}else if(i-list.get(ptr)[1]>=0){
					if(dp[i-list.get(ptr)[1]]>=digit-1) {
						ans += list.get(ptr)[0];
						i -= list.get(ptr)[1];
						digit--;
						break;
					}
				}
			}
			if(end) break;
		}
		System.out.println(ans);
		in.close();
	}

}


Measured memory_bytes: 61780
/*------U Have To DO It------*/
/* BY-> RicoProg */
/*        ___ 
           __|__|
          |  |___       */
#include <bits/stdc++.h>
using namespace std;
 
 
//---------------------------------------------------MACROS----------------------------------------------------------
#define ll long long
#define beg(i ,n) for(ll i=0;i<n;i++)
#define beg1(i ,n) for(ll i=1;i<n;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back 
#define mp make_pair
#define nl "\n" 
#define vec(v , n) vector<ll> v(n)
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define pll pair<ll , ll>
#define mii map<int , int>
#define mll map<ll , ll>
#define msi map<string , int>
#define mci map<char , int>
#define f1 first
#define f2 second
 
//---------------------------------------------------GLOBAL----------------------------------------------------------
const ll MOD = 998244353 ;
const ll MAX = 1e5 + 7;
//---------------------------------------------------FUNCTIONS-------------------------------------------------------

void solve(){
	ll n ;
	vector<ll> dp(100001 , 1e18) ;
	cin >> n ;
	vector<ll> ar(n) ;
	beg(i , n) cin >> ar[i] ;
	dp[0] = 0 ;
	beg1(i , n){
		if(i-1 >= 0) dp[i] = min(dp[i] , dp[i-1]+abs(ar[i]-ar[i-1])) ;
		if(i-2 >= 0) dp[i] = min(dp[i] , dp[i-2]+abs(ar[i]-ar[i-2])) ;
	}
	cout << dp[n-1] ;
}
 
//---------------------------------------------------DRIVER----------------------------------------------------------
int main()
{
    fast ;
    int t=1 ;
    //cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}	

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


def calc(num):
    s = list(str(num))[::-1]
    s2 = int(s[-1])
    s1 = int(s[0])

    keta = 0
    while True:
        num = num // 10
        keta += 1
        if num == 0:
            break

    if s1 == s2:
        if keta == 1:
            return 1
        elif keta == 2:
            return 1 + 2
        else:
            ans = 0
            for i in range(keta - 3):
                ans += (10 ** (i+1)) * 2
            ans += (int(''.join(s[1:-1][::-1]))+1) * 2 + 3
            return ans

    elif s1 > s2:
        if keta == 2:
            return 0
        else:
            ans = 0
            for i in range(keta - 2):
                ans += 10 ** i
            return ans * 2
    else:
        if s1 == 0:
            return 0
        else:
            ans = 0
            for i in range(keta - 1):
                ans += 10 ** i
            return ans * 2


# print(10, calc(10))

dp = [0] * (N+1)

for i in range(1, N+1):
    dp[i] = dp[i-1] + calc(i)

# print(dp)
print(dp[N])



Measured memory_bytes: 44252
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    int ans=m;
    rep(i,n-m+1){
        int cnt=0;
        rep(j,m){
            if(s[j+i]!=t[j]) cnt++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans;
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

ll a, b, k;

int main() {

	cin >> a >> b >> k;

	if (a >= k){
		a -= k;
		cout << a << " " << b << endl;
	}
	else if (b >= k - a){
		b -= k - a;
		cout << 0  << " " << b << endl;
	}
	else cout << 0 << " " << 0 << endl;

	return 0;
}



Measured memory_bytes: 256