akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> P(N);

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

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

	int ans = 0;
	for (int i = 0; i < K; i++)
	{
		//cout << P[i] << endl;
		ans += P[i];
	}
		cout << ans << endl;

}


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>

using namespace std;

int h[100050], a[100050], b[100050];

int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++){
		scanf("%d", &h[i]);
	}
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	for (int i = 1; i <= m; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		a[u]++, a[v]++;
		if (h[u] > b[v]) b[v] = h[u];
		if (h[v] > b[u]) b[u] = h[v];
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		if (a[i] == 0 || h[i] > b[i]) ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2900
N, M = (int(x) for x in input().split())
L = []
for i in range(N):
  A, B = (int(x) for x in input().split())
  L.append((A,B))
L.sort()
tn = 0
tm = 0
for i in range(N):
  if L[i][1] < M-tn:
    tn += L[i][1]
    tm += L[i][0]*L[i][1]
  else:
    tm += L[i][0]*(M-tn)
    print(tm)
    quit()

Measured memory_bytes: 22564
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

const int kMaxN = 205;
int n, a[kMaxN], ans;

int main() {
  scanf("%d", &n);
  n <<= 1;
  for (int i = 1; i <= n; ++i)
    scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i += 2)
    ans += a[i];
  return printf("%d\n", ans), 0;
}

Measured memory_bytes: 128
S = int(input())
y1 = 1
if S >= 10 ** 9:
	x1 = 10 ** 9
	if S % x1 == 0:
		y2 = S // x1
	else:
		y2 = (S // x1) + 1 
else:
	x1 = 10 ** 9
	y2 = 1

x2 = x1 * y2 - S 

print(0, 0, x1, y1, x2, y2)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
int n, k, c;
char s[N];
int L[N], R[N];
int main() {
	scanf("%d%d%d", &n, &k, &c);
	scanf("%s", s + 1);
	int cur = 1, d = 0;
    while(cur<=n)
    {
        if(s[cur]=='o')
        {
            L[++d]=cur;
            cur+=c;
        }
        cur++;
    }
    cur=n;d=0;
    while(cur>=1)
    {
        if(s[cur]=='o')
        {
            R[++d]=cur;
            cur-=c;
        }
        cur--;
    }
    if(L[k+1])puts("");
    else
    {
        reverse(R+1,R+1+d);
        for(int i=1;i<=d;i++)
            if(L[i]==R[i])printf("%d\n",L[i]);
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
int x;

void solve()
{
    scanf("%d", &x);
    for (int ans = 8, i = 400; i <= 1999;ans--,i+=200)
    {
        if(x>=i && x<i+200)
        {
            printf("%d\n", ans);
            return;
        }
    }
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
        solve();
    TIME__END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 3796
# -*- coding: utf-8 -*-
def call(n):
    for i in (range(1,n+1)):
        x = i
        if(x % 3 == 0):
            print(" {0}".format(i), end="")
        else:
            while(x):
                if(x % 10 == 3):
                    print(" {0}".format(i), end="")
                    break;
                x = int(x / 10)
    print()

input = int(input().strip())
call(input)

Measured memory_bytes: 7944
import bisect
x = int(input())
def eratosthenes(limit):
    A = [i for i in range(2,limit+1)]
    P = []
    time = 0
    while True:
        prime = min(A)
        
        if prime > limit**0.5:
            break
        P.append(prime)
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
    for a in A:
        P.append(a)
    return P
L = eratosthenes(100005)
y = bisect.bisect_left(L,x)
print(L[y])

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

bool ar[105];
int ans, n, t;

int main() {
	#ifdef LUNU
	freopen("in.txt", "r", stdin);
	#endif
	scanf("%d", &n);
	set<int> ans;
	for(int i = 0; i < n; i += 1) {
		scanf("%d", &t);
		ans.insert(t);
	}
	printf("%d", (int)ans.size());
	return 0;
}

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


const int INF = 1e+9;

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


    vector<int> numA(100001, 0);
    for( int i = 0; i < N; ++i ) ++numA[A[i]];

    int numDistinct = 0, numEven = 0;
    for( int i = 0; i < numA.size(); ++i ){
        if( numA[i] > 0 ){
            ++numDistinct;
            if( numA[i] % 2 == 0 ) ++numEven; 
        }
    }

    if( numEven % 2 == 0 ) cout << numDistinct << endl;
    else cout << numDistinct-1 << endl;

    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

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

        public void Solve(ConsoleInput cin)
        {
            // ここに処理を書く
            int x = cin.ReadInt;

            bool isSosu = false;
            while (!isSosu)
            {
                bool ng = false;
                for (int i = 2; i < x; i++)
                {
                    if (x % i == 0)
                    {
                        ng = true;
                        break;
                    }
                }

                if (ng)
                {
                    x++;
                }
                else
                {
                    isSosu = true;
                }
            }

            Console.WriteLine(x);
        }
    }

    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 <iostream>
#include <string>
using namespace std;
int main(void){
    int N, Y;
    cin >> N >> Y;
    int a = -1, b = -1, c = -1;
    char s = ' ';
    for (int x = 0; x <= N; x++){
        for(int y = 0; y <= N - x; y++){
            int z = N - x - y;
            if (x * 10000 + y * 5000 + z * 1000 == Y && z >= 0){
                a = x;
                b = y;
                c = z;
            }
        }
    }
    
    cout << a  << s << b << s << c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
vector<vector<pair<int, int>>> s(101, vector<pair<int, int>>(101));
vector<vector< int>> sflag(101, vector<int>(101, 0));
int n, m, l;

vector<vector<long long>> slv(101, vector<long long>(101, 0));
vector<vector<int>> slvflag(101, vector<int>(101, 0));

int main() {
	while (true) {
        for (int i = 0; i < 101; i++) {
			for (int j = 0; j < 101; j++) {
				slv[i][j] = 0;
				slvflag[i][j] = 0;
                sflag[i][j]=0;
                slvflag[1][j] = 1;
			}
		}
		cin >> n >> m >> l;
		if (n == 0&& m==0&&l==0)return 0;

		for (int i = 0; i < m; i++) {
			int a, b, d, e;
			cin >> a >> b >> d >> e;
			s[b][a] = make_pair(d, e);
			sflag[b][a] = 1;
			s[a][b] = make_pair(d, e);
			sflag[a][b] = 1;
		}
		for(int time = 0;time <= n;time++){
            for (int i = 0; i <=n; i++) {
			    for (int j = 0; j <=l; j++) {
                    if(slvflag[i][j]==1){
                        for(int a=1;a<=n;a++){
                            if(sflag[i][a]==1){
                                if(slvflag[a][j]==0){
                                    slv[a][j] = slv[i][j]+s[i][a].second;
                                    slvflag[a][j]=1;
                                }else{
                                    slv[a][j] =min(slv[a][j], slv[i][j]+s[i][a].second);
                                }
                                int x = j + s[i][a].first;
                                if(x<=l){

                                    if(slvflag[a][x]==0){
                                        slv[a][x] = slv[i][j];
                                        slvflag[a][x]=1;
                                    }else{
                                        slv[a][x] = min(slv[i][j],slv[a][x]);
                                    }
                                }


                            }
                        }
                    }
                }
            }

            


        }
        
		cout  << slv[n][l] <<endl;

		
	}
}

Measured memory_bytes: 3228
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
H = get_ints

max = 0
count = 0
H.each do |h|
  if h >= max
    count += 1
    max = h
  end
end

puts count


Measured memory_bytes: 14268
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
using namespace std;

int keta(long long int a){
    int cou=0;
    while(a!=0){
        a/=10;
        cou++;
    }
    return cou;
}

int main(void){
    const long long int mod=1000000007;
    long long int n,m=0,a[200005],plsum=0,misum=0,pl=0,mi=0;
    cin>>n;
    for(long long int i=0;i*i<=n;i++){
        m=i;
    }
     for(int i=m;i>=0;i--){
        if(n%i==0){cout<<keta(n/i);return 0;}
    }
    
}


Measured memory_bytes: 256
//#include "stdafx.h"
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
int a,b,k,c;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	set<int>st;
	set<int>::iterator it;

	cin>>a>>b>>k;

	for(int i=a;(c<k&&i<=b);i++){
		c++;
		st.insert(i);
	}

	c=0;
	for(int i=b;(c<k&&i>=a);i--){
		c++;
		st.insert(i);
	}
	
	for(it=st.begin();it!=st.end();it++)
		cout<<*it<<"\n";
	
	return 0;
}



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

int main(){
  int W,H;cin>>W>>H;
  vector<pair<int,int> > v(W+H);
  rep(i,W){
    int p; cin>>p;
    v[i]={p,0};
  }
  rep(i,H){
    int p; cin>>p;
    v[i+W]={p,1};
  }
  sort(v.begin(),v.end());
  int a[2]={W+1,H+1};
  ll ans=0;
  rep(i,H+W){
    int x=v[i].second,y=(x+1)%2;
    ans+=1LL*a[y]*v[i].first;
    a[x]=max(0,a[x]-1);
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    int A, B, C, X;
    std::cin >> A >> B >> C >> X;
    int cnt = 0;
    for(int a = 0; a <= A; a++){
        for(int b = 0; b <= B; b++){
            for(int c = 0; c <= C; c++){
                int cash = a * 500+ b * 100 + c * 50;
                if(cash == X) cnt++;
            }
        }
    }

    std::cout << cnt << std::endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import bisect

def main():
    n, m = map(int, input().split())
    A = [0] * n
    for i in range(m):
        a, b = map(int, input().split())
        A[a-1] += 1
        A[b-1] += 1
    for a in A:
        print(a)

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,M,count2,maxcount = 0,Ans = 1;
    
    cin >> N;
    
    for (int i = 1; i <= N; i++){
        count2 = 0;
        M = i;
        while (M%2 == 0){
         count2 ++;
         M = M / 2;
        }
        if (maxcount < count2){
            maxcount = count2;
             Ans = i;
        }
        
        
    }
   cout << Ans << endl;
}


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

#define IOS cin.tie(0);ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)     for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(N);
    map<string,int> mp;
    ll ans=0;
    rep(i,N){
        SCIN(s);
        sort(all(s));
        ans+=mp[s];
        mp[s]++;
        
    }
    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 11136
s = list(map(int, input()))
s = s[::-1]
n = len(s)
ans = 0

for bit in range(1<<n-1):
    digit = 0
    for i in range(n):
        ans = ans + s[i] * (10 ** digit)
        if (bit & (1<<i)):
            digit = 0
        else:
            digit = digit + 1

print(ans)
    


Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
  int time = 0;
  int h = 0;
  int m = 0;
  int s = 0;

  scanf("%d", &time);

  h = time / 3600;
  time %= 3600;
  m = time / 60;
  s = time % 60;

  printf("%d:%d:%d\n", h, m, s);

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
long INF=10000000000;

//関数


//main関数
int main() {
    
    
    //入力
    long H,W;
    cin>>H>>W;
    vector<vector<char>> A(H,vector<char>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>A.at(i).at(j);
        }
    }
    
    //計算
    vector<vector<long>> cost(H,vector<long>(W,INF));
    vector<vector<long>> queue(0,vector<long>(2));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(A.at(i).at(j)=='#'){
                vector<long> state(2);
                state.at(0)=i;
                state.at(1)=j;
                queue.push_back(state);
                
                cost.at(i).at(j)=0;
            } 
        }
    }
    long k=0;
    while(k<queue.size()){
        long h=queue.at(k).at(0),w=queue.at(k).at(1);
        if(h+1<H && cost.at(h+1).at(w)>cost.at(h).at(w)+1) {
            vector<long> state(2);
                state.at(0)=h+1;
                state.at(1)=w;
                queue.push_back(state);
                
                cost.at(h+1).at(w)=cost.at(h).at(w)+1;
        }
        if(h-1>=0 && cost.at(h-1).at(w)>cost.at(h).at(w)+1) {
            vector<long> state(2);
                state.at(0)=h-1;
                state.at(1)=w;
                queue.push_back(state);
                
                cost.at(h-1).at(w)=cost.at(h).at(w)+1;
        }
        if(w+1<W && cost.at(h).at(w+1)>cost.at(h).at(w)+1) {
            vector<long> state(2);
                state.at(0)=h;
                state.at(1)=w+1;
                queue.push_back(state);
                
                cost.at(h).at(w+1)=cost.at(h).at(w)+1;
        }
        if(w-1>=0 && cost.at(h).at(w-1)>cost.at(h).at(w)+1) {
            vector<long> state(2);
                state.at(0)=h;
                state.at(1)=w-1;
                queue.push_back(state);
                
                cost.at(h).at(w-1)=cost.at(h).at(w)+1;
        }
        
        k++;
    }
    
    
    long ans=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
           // cout<<cost.at(i).at(j)<<" ";
            ans=max(ans,cost.at(i).at(j));
        }
       // cout<<endl;
    }
    
    
 
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 64804
pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());
	let n: usize = iter.read();

	let nums = {
		let mut t: Vec<u32> = (0..n).into_iter().map(|_| iter.read()).collect();
		t.sort();
		t
	};

	let len = nums.len();
	if 1 == len % 2 {
		println!("0");
		return;
	}

	let midi2 = len / 2;
	let midi1 = midi2 - 1;

	let mid1 = nums[midi1];
	let mid2 = nums[midi2];

	println!("{}", mid2 - mid1);
}


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

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

template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}

template <typename T> void print(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void print(const T &value, const Args&... args){std::cout << value << " ";print(args...);}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  std::vector<int> a(5);

  while(cin >> a){
    REP(i,5){
      if(a[i] == 0){
        cout << i+1 << "\n";
      }
    }
    
    
    
  }

  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;
ll arr[2006];
vector <int> g[2005];
int n;

void bfs (int node) {
    int vis[n+2] = {0};
    int dis[n+2] = {0};
    queue <int> q;
    q.push(node);
    vis[node] = 1;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int j : g[v]) {
            if (vis[j] == 0) {
                vis[j] = 1;
                dis[j] = dis[v]+1;
                q.push(j);
            }
        }
    }
    // cout << "STRAT" << endl;
    // for (int i=1; i<=n; i++) {
    //     cout << dis[i] << " ";
    // }
    // cout << "END" << endl;
    for (int i=node; i<=n; i++) {
        arr[dis[i]]++;
    }
}

void testCase() {
//    int n;
    cin >> n;
    int x, y;
    cin >> x >> y;
    for (int i=1; i<n; i++) {
        g[i].push_back (i+1);
        g[i+1].push_back (i);
    }
    g[x].push_back (y);
    g[y].push_back (x);
    for (int i=1; i<n; i++) {
        bfs (i);
    }
    for (int i=1; i<n; i++)
        cout << arr[i] << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

int h,n,sum,x;

int main()
{
    cin >> h >> n;
    for (int i=0;i<n;i++)
    {
        cin >> x;
        sum+=x;
    }
    if (sum>=h)cout << "Yes\n";
    else cout << "No\n";
    return 0;
}



Measured memory_bytes: 256
/*
 * ALDS1_4_C.cpp
 *
 *  Created on: Apr 26, 2018
 *      Author: 13743
 */

#include<cstdio>

using namespace std;

const int SIZE = 100000001;
int table[SIZE];

int getKey(char* s) {
	int key = 0;
	int exp = 1;
	for(int i=0; s[i]!='\0'; i++) {
		switch(s[i]) {
		case 'A': key += 4 * exp; break;
		case 'C': key += 3 * exp; break;
		case 'G': key += 2 * exp; break;
		default: key += 1 * exp; break;
		}
		exp *= 5;
	}
	return key;
}

void insert(char* s) {
	int key = getKey(s);
	int hash = key % SIZE;
	while(true) {
		if(table[hash] == 0 || table[hash] == key) {
			table[hash] = key; break;
		}
		hash = (hash + (1 + (key%(SIZE-1)))) % SIZE;
	}
}

bool find(char* s) {
	int key = getKey(s);
	int hash = key % SIZE;
	while(true) {
		if(table[hash] == key) {
			return true;
		}
		else if(table[hash] == 0) {
			return false;
		}
		hash = (hash + (1 + (key%(SIZE-1)))) % SIZE;
	}
	return false;
}

int main() {
	int n;
	scanf("%d", &n);
	char d[10];
	char s[13];
	for(int i=0; i<n; i++) {
		scanf("%s %s", d, s);;
		if(d[0] == 'i') {
			insert(s);
		}
		else {
			if(find(s)) printf("yes\n");
			else printf("no\n");
		}
	}
}





Measured memory_bytes: 19548
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

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


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

  ll N;
  cin >>N;
  ll flag = 0;

  vector<string> vec(N);

  for (ll i = 0; i < N; i++) {
    cin >>vec.at(i);
  }

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

  ll count_max=1;

  vector<string> ans;
  ll tmp = 1;
  for (ll i = 0; i < N-1; i++)
  {
    
    if (vec.at(i) == vec.at(i + 1))
    {
      tmp++;
      continue;
    }
    //cout << tmp << endl;

    if(count_max==tmp){
      ans.push_back(vec.at(i));
      tmp = 1;
    }
    else if(count_max<tmp){
      while(ans.size()>0){
        ans.pop_back();
      }
      ans.push_back(vec.at(i));
      count_max = tmp;
      tmp = 1;
    }
    else{
      tmp = 1;
    }
  }
  if (count_max == tmp)
  {
    ans.push_back(vec.at(N-1));
  }
  else if (count_max < tmp)
  {
    while (ans.size() > 0)
    {
      ans.pop_back();
    }
    ans.push_back(vec.at(N-1));
    count_max = tmp;
    tmp = 1;
  }
  else
  {
    tmp = 1;
  }

  sort(ans.begin(), ans.end());
  for (ll i = 0; i < ans.size(); i++)
  {
    cout << ans.at(i) << endl;
  
}

}

Measured memory_bytes: 14960
#include<iostream>

using namespace std ;

int main()

{
	float m5_limites[] = { 35.5 ,37.5 ,40.0 ,43.0 ,50.0 ,55.0 ,70.0 } ;
	float m1_limites[] = { 71.0 ,77.0 ,83.0 ,89.0 ,105.0 ,116.0 ,148.0 } ;
	string lank[] = { "AAA" ,"AA" ,"A" ,"B" ,"C" ,"D" ,"E" ,"NA" } ;

	float m5 ,m1 ;

	while( cin >> m5 >> m1 )
	{
		int i = 0 ;
		while( i < 7 && !( m5 < m5_limites[ i ] && m1 < m1_limites[ i ] ) )
			i++ ;
		cout << lank[ i ] << endl ;
	}

	return 0 ;
}

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

using namespace std;

int main()
{
    long long n, m;
    scanf("%lld %lld", &n, &m);
    long long macht=1;
    for(int i=1; i<=m; i++)
    {
        macht *= 2;
    }
    long long a = (n-m)*100+m*1900;
    long long ans = macht*a;
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

#define ll long long int
ll M=1000000007;
const int N=1010;
int co[N][N], dp[N][N], vis[N][N], n, w;
int di[2] = {1, 0}, dj[2] = {0, 1};
void dfs(int r, int c) {
	if (r > n || c > w) return;
	if (r == n-1 && c == w-1) {dp[r][c]=1;return;}
	vis[r][c]=1;
	for (int i=0; i<2; i++){
		int ti= r+di[i], tj = c+dj[i];
		if (ti < n &&  tj< w) {
		    //cout<<ti<<" "<<tj<<" bahar";
			if (!vis[ti][tj] && co[ti][tj]==1) {

				dfs(ti, tj);
				dp[r][c] =(dp[r][c]%M+dp[ti][tj]%M)%M;
				//cout<<ti<<"idhardpse"<<tj<<" "<<dp[r][c]<<"\n";
			}
			else if (vis[ti][tj] && co[ti][tj]==1) {
			    
				dp[r][c] = (dp[r][c]%M+dp[ti][tj]%M)%M;
				
			}
		}
	}
}

int main () {
	char a,b;
	memset(dp, 0, sizeof(dp));
	memset(vis, 0, sizeof(vis));
	
	cin>>n>>w;
	for (int i=0; i<n; i++) {
		for (int j=0;j<w;j++) {
			cin>>a;
			if (a=='.')co[i][j] = 1;
			else co[i][j]=0;
		}
	}
	dfs(0,0);
	cout<<dp[0][0];
	//for (int i=0;i<n;i++) {for (int j=0; j<w; j++) cout<<dp[i][j]<<" "; cout<<"\n";}
}

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

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<pii, ll> ppiil;
typedef pair<pii, int> ppiii;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define btoe(obj) (obj).begin(), (obj).end()
#define pb push_back
#define str to_string
#define mkp make_pair
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
void chmax(ll &a, ll b) { a = max(a, b); }
void chmin(ll &a, ll b) { a = min(a, b); }

template<typename T>
void print(T out) {
    cout << out << '\n';
}

template<typename T1, typename T2>
void print(pair<T1, T2> out) {
    cout << out.first << ' ' << out.second << '\n';
}

template<typename T>
void print(vector<T> A) {
    rep(i, 0, A.size()) {
        cout << A[i];
        cout << (i == A.size()-1 ? '\n' : ' ');
    }
}

template<typename T>
void print(set<T> S) {
    vector<T> A(btoe(S));
    print(A);
}

ll sum(vector<ll> A) {
    ll res = 0;
    for (ll a: A) res += a;
    return res;
}

ll max(vector<ll> A) {
    ll res = -INF;
    for (ll a: A) chmax(res, a);
    return res;
}

ll min(vector<ll> A) {
    ll res = INF;
    for (ll a: A) chmin(res, a);
    return res;
}

ll sum(ll A[], int len) {
    ll res = 0;
    rep(i, 0, len) res += A[i];
    return res;
}

ll max(ll A[], int len) {
    ll res = -INF;
    rep(i, 0, len) chmax(res, A[i]);
    return res;
}

ll min(ll A[], int len) {
    ll res = INF;
    rep(i, 0, len) chmin(res, A[i]);
    return res;
}

ll toint(string s) {
    ll res = 0;
    for (char c : s) {
        res *= 10;
        res += (c - '0');
    }
    return res;
}

int toint(char c) {
    return c - '0';
}

// 条件を満たす最大値を見つける二分探索
ll bisearch_max(ll mn, ll mx, function<bool(ll)> func) {

    ll ok = mn;
    ll ng = mx;
    while (ok+1 < ng) {
        ll mid = (ok+ng) / 2;
        if (func(mid)) {
            // 上を探しに行く
            ok = mid;
        } else {
            // 下を探しに行く
            ng = mid;
        }
    }
    return ok;
}

ll X, Y, Z, K;
vector<ll> A, B, C, ans;

// K個以上の3つ組が達成できるような最大の値mを探す
bool check(ll m) {
    ll sm = 0;
    for (ll a : A) {
        for (ll b : B) {
            ll cnt = Z - (lower_bound(btoe(C), m-a-b) - C.begin());
            sm += cnt;
        }
    }
    return sm >= K;
}

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

    cin >> X >> Y >> Z >> K;
    A.resize(X);
    B.resize(Y);
    C.resize(Z);
    rep(i, 0, X) cin >> A[i];
    rep(i, 0, Y) cin >> B[i];
    rep(i, 0, Z) cin >> C[i];
    sort(btoe(C));

    ll res = bisearch_max(0, INF, check);

    for (ll a : A) {
        for (ll b : B) {
            ll idx = lower_bound(btoe(C), res-a-b) - C.begin();
            rrep(i, Z-1, idx-1) {
                ll c = C[i];
                ans.pb(a+b+c);
            }
        }
    }
    sort(btoe(ans));
    reverse(btoe(ans));
    // K個まで出力
    rep(i, 0, K) print(ans[i]);
    return 0;
}


Measured memory_bytes: 132704
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

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

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	int a,b;
	cin>>a>>b;
	if(a>8 || b>8){
		cout<<":("<<endl;
	}else{
		cout<<"Yay!"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename S, typename T>
void xmin(S&a, T const&b){if(b<a) a=b;}
template<typename S, typename T>
void xmax(S&a, T const&b){if(b>a) a=b;}

signed main()
{
    #ifdef LOCAL_RUN
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    int TTT; cin >> TTT; while(TTT--){
    #else
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    #endif // LOCAL_RUN

    int n, q;
    cin >> n >> q;
    vector<vector<int> > v(n+1);
    for(int i=0;i<q;++i){
        int a, b;
        cin >> a >>b;
        v[a].emplace_back(b);
    }
    int ans = 0;
    unordered_set<int> s;
    for(int i=0;i<=n;++i){
        if(s.count(i)){
            s.clear();
            ++ans;
        }
        s.insert(v[i].begin(), v[i].end());
    }
    cout << ans << "\n";


    #ifdef LOCAL_RUN
    }
    #endif // LOCAL_RUN
    return 0;
}


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    int K,S;
    cin >> K >> S;

    ll ans = 0;

    rep(X,K+1)
    {
        rep(Y,K+1)
        {
            if( S-X-Y >= 0 && S-X-Y <= K )ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <sstream>
#include <numeric>
#include <queue>
#include <sstream>
#include <set>
using namespace std;



int main(){
    string s ;
    cin >> s ;
    bool end = false ;
    string a = "a" ;
    a.at(0) -= 1 ;
    string p = a ;
    while(end == 0){
        int i = 0 ;
        while (1)
        {
            if (p.at(0) == 'z')
            {
                break ;
            }
            bool ok = true ;
            p.at(0) = p.at(0) + 1 ;
            for (size_t j = 0; j < s.size() ; j++)
            {
                
                if (p.at(0) == s.at(j))
                {
                    ok = false ;
                    break ;
                }
                
            }
            if (ok == true)
            {
                cout << s+p << endl ;
                return 0 ;
            }
            
            i ++ ;
        }
        if (s.size() == 0)
        {
            cout << "-1" << endl ;
            return 0 ;
        }else
        {
            p = s.at(s.size()-1) ;
            s.pop_back() ;
        }
        
        
        
    }
    
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b)
{
	ll res = 1;
	a %= mod;
	assert(b >= 0);
	for (; b; b >>= 1)
	{
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
	}
	return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

static uint MD = mod;
struct ModInt
{
	using M = ModInt;
	uint v;
	ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
	M &set_v(uint _v)
	{
		v = (_v < MD) ? _v : _v - MD;
		return *this;
	}
	explicit operator bool() const { return v != 0; }
	M operator-() const { return M() - *this; }
	M operator+(const M &r) const { return M().set_v(v + r.v); }
	M operator-(const M &r) const { return M().set_v(v + MD - r.v); }
	M operator*(const M &r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
	M operator/(const M &r) const { return *this * r.inv(); }
	M &operator+=(const M &r) { return *this = *this + r; }
	M &operator-=(const M &r) { return *this = *this - r; }
	M &operator*=(const M &r) { return *this = *this * r; }
	M &operator/=(const M &r) { return *this = *this / r; }
	bool operator==(const M &r) const { return v == r.v; }
	M pow(ll n) const
	{
		M x = *this, r = 1;
		while (n)
		{
			if (n & 1)
				r *= x;
			x *= x;
			n >>= 1;
		}
		return r;
	}
	M inv() const { return pow(MD - 2); }
	friend ostream &operator<<(ostream &os, const M &r) { return os << r.v; }
};
using Mint = ModInt;

ll gcd(ll a,ll b,ll c) {
	ll d = gcd(a,b);
	return gcd(d,c);
}
//head
// cin >> t;
// for (int cas = 1; cas <= t; ++cas)
// {
// 	cout << "Case #" << cas << ": ";
// }
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	int ans = 0;
	rep(i,1,n+1) {
		rep(j,1,n+1) {
			rep(k,1,n+1) {
				ans += gcd(i,j,k);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

bool sosu(int a){
  if(a > 1000000){
	FOR(i,2,a/1000){
	  if(a%i==0) return false;
	}
  }else  if(a > 10000){
	FOR(i,2,a/100){
	  if(a%i==0) return false;
	}
  }else if(a > 100){
	FOR(i,2,a/10){
	  if(a%i==0) return false;
	}
  }else{
	if(a==1) return false;
	if(a==2) return true;
	FOR(i,2,a/2+1){
	  if(a%i==0) return false;
	}
  }
  return true;
}

 
int main(){

  while(1){
	int n;
	int c = 0;
	cin >> n;
	if(n==0) break;
	FOR(i,n+1,2*n+1){
	  if(sosu(i)) c++; //cout << i << endl;
	}

	cout << c << endl;

  }
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
"""
D - Decayed Bridges
https://atcoder.jp/contests/abc120/tasks/abc120_d#

"""
import sys

class DisjointSet(object):
    def __init__(self, n):
        self.rank = []
        self.p = []
        self.size = []
        for i in range(n+1):
            self.makeSet(i)

    def makeSet(self, x):
        self.p.insert(x, x)
        self.rank.insert(x, 0)
        self.size.insert(x, 1)

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.size[self.p[x]] += self.size[self.p[y]]
            self.p[y] = self.findSet(x)
        else:
            self.size[self.p[y]] += self.size[self.p[x]]
            self.p[x] = self.findSet(y)
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def findSet(self, x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]


def solve(bridges, N, M):
    ans = [(N**2 - N)//2]
    d = DisjointSet(N)
    for f, t in reversed(bridges):
        if d.same(f, t):
            ans.append(ans[-1])
        else:
            n1 = d.size[d.p[f]]
            n2 = d.size[d.p[t]]
            ans.append(ans[-1] - (n1*n2))
            d.unite(f, t)
    return ans


def main(args):
    N, M = map(int, input().split())
    bridges = []
    for _ in range(M):
        f, t = map(int, input().split())
        bridges.append([f, t])
    ans = solve(bridges, N, M)

    for a in (ans[::-1])[1:]:
        print(a)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 27172
from math import ceil

a,b=map(int,input().split())
if a%3==0 or b%3==0:
    print(0)
    exit()

#候補1 min(a,b)
#候補2
memory1=1000000000000
for i in range(1,b):
    ar1=a*i
    ar2=(b-i)*ceil(a/2)
    ar3=(b-i)*(a//2)
    p=max(ar1,ar2,ar3)-min(ar1,ar2,ar3)
    if p<memory1:
        memory1=p
    else:
        break
#候補3
memory2=1000000000000
for i in range(1,a):
    ar1=b*i
    ar2=(a-i)*ceil(b/2)
    ar3=(a-i)*(b//2)
    p=max(ar1,ar2,ar3)-min(ar1,ar2,ar3)
    if p<memory2:
        memory2=p
    else:
        break

print(min(min(a,b),memory1,memory2))

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int k;
    cin >> k;
    for(int i = 0; i < n; i++){
        if(s.at(k-1) != s.at(i)){
            s.at(i) = '*';
        }
    }
    cout << s << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;
Vi c,s,f;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    c.resize(n-1);
    s.resize(n-1);
    f.resize(n-1);
    rep(i,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }
    rep(i,n-1){
        ll t = 0;
        repi(j,i,n-1){
            if(t<s[j])
                t = s[j];
            else if(t % f[j] == 0);
            else
                t = f[j] * ( ( (ll)t/f[j] )+ 1);
            t += c[j];
        }
        print(t);
    }
    print(0);
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
int main(void) {

    int n,i,S[13],H[13],C[13],D[13],num;
    char s[100];
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%s %d",&s,&num);
        if(strcmp("S",s)==0){
            S[num] = num;
        }
        if(strcmp("H",s)==0){
            H[num] = num;
        }
        if(strcmp("C",s)==0){
            C[num] = num;
        }
        if(strcmp("D",s)==0){
            D[num] = num;
        }
    }
    for(i=1;i<14;i++){
        if(S[i]!=i){
            printf("S %d\n",i);
        }
    }
    for(i=1;i<14;i++){
        if(H[i]!=i){
            printf("H %d\n",i);
        }
    }
    for(i=1;i<14;i++){
        if(C[i]!=i){
            printf("C %d\n",i);
        }
    }
    for(i=1;i<14;i++){
        if(D[i]!=i){
            printf("D %d\n",i);
        }
    }
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;

#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif




int main(int argv, char* argc[])
{
    FASTIO


    ll n,cnt=0;
    cin>>n;
    vll v(n);
    map<ll,ll> mp;
    rep(i,n)
    {
        cin>>v[i];
        ++mp[i-v[i]];
    }
    rep(i,n)
    {
        cnt+=mp[i+v[i]];
        if(v[i]==0)
            --cnt;
    }
    cout<<cnt;

    return 0;
}


Measured memory_bytes: 27292
import itertools
n = int(input())
string = str(1)
for i in range(2, n + 1):
    string += str(i)

    
string_list = []    
a = tuple(input().split(" "))
b = tuple(input().split(" "))
for i in itertools.permutations(string):
    string_list.append(i)


for i,j in enumerate(string_list):
    if j == a:
        A = i + 1
    if j == b:
        B = i + 1
print(abs(A - B))


Measured memory_bytes: 7924