akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

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

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
#define endl        	"\n"
#define int         	long long int  
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b)
{
    ll res = 1;
    while(b)
    {
        if(b&1) res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a)
{
	return mod_pow(a,mod-2);
}

const int N = 200005;

int vis[N];

void solve()
{
	ll n,k;
	
	cin>>n>>k;
	
	int a[n+1];
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	
	ll tot = 1;
	
	vis[1] = 1;
	
	int id = 1;
	
	while(vis[a[id]] == 0)
	{
		id = a[id];
		
		vis[id] = 1;
		
		tot++;
	}
	
	if(k < tot)
	{
		
		fill(vis,0);
		
		vis[1] = 1;
	
		id = 1;
		
		k--;
		
		while(vis[a[id]] == 0)
		{
			if(k == 0)	
			{
				cout<<a[id];
				return;
			}
			
			id = a[id];
			
			vis[id] = 1;
			
			k--;
		}
	}
	else
	{
		fill(vis,0);
		
		vis[1] = 1;
	
		id = 1;
		
		while(vis[a[id]] == 0)
		{
			id = a[id];
			
			vis[id] = 1;
		}
		
		fill(vis,0);
		
		id = a[id];
		
		vis[id] = 1;
		
		vector<int> seq;
		
		seq.pb(id);
		
		while(vis[a[id]] == 0)
		{
			id = a[id];
			
			vis[id] = 1;
			
			seq.pb(id);
		}
		
		k = k - tot + seq.size();
		
		cout<<seq[k%seq.size()];
		
		return;
	}
}


signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 8336
#include <stdio.h>
#define E 0
#define O 1
#define Q 2

int solve(int s[8][8],int);
int state(int board[8][8],int,int);
int Ans[8][8];

int main(){
    int n,i,j,count,s;
    int board[8][8];
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            board[i][j]=E;
        }
    }

    scanf("%d",&count);
    
    for(n=0;n<count;n++){
        scanf("%d%d",&i,&j);
        board[i][j]=Q;
        state(board,i,j);
    }
    for(i=0;i<8;i++)
        solve(board,0);
    /*
    while(count!=8){
        s=0;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                if(board[i][j]==0){
                    s++;
                    board[i][j]=2;
                    count++;
                    if(state(board,i,j)==-1)break;
                }
            }
        }
        if(s==0){
            printf("Can't Solve this!\nWe can put %d Qs!\n",count);
            break;
        }
        
    }*/
    
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(Ans[i][j]==Q)printf("Q");
            else printf(".");
        }
        printf("\n");
    }
    
    return 0;
}

int state(int board[8][8],int ver,int sid){
    int i,j;
    
    //?¨???¨???
    for(i=0;i<8;i++){
        if(board[i][sid]!=Q) board[i][sid]=O;
        if(board[ver][i]!=Q) board[ver][i]=O;
    }
    
    //???????????????
    for(i=ver-1,j=sid+1;i>=0&&j<8;i--,j++){
        if(board[i][j]!=Q)board[i][j]=O;
        else return -1;
    }
    //???????????????
    for(i=ver+1,j=sid+1;i<8&&j<8;i++,j++){
        if(board[i][j]!=Q)board[i][j]=O;
        else return -1;
    }
    //???????????????
    for(i=ver-1,j=sid-1;i>=0&&j>=0;i--,j--){
        if(board[i][j]!=Q)board[i][j]=O;
        else return -1;
    }
    //???????????????
    for(i=ver+1,j=sid-1;i<8&&j>=0;i++,j--){
        if(board[i][j]!=Q)board[i][j]=O;
        else return -1;
    }
    return 0;
}

int solve(int s[8][8],int sid){
    int i,j,sum=0,res=0,ii,jj;
    int p[8][8];
    
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            p[i][j]=s[i][j];
            if(p[i][j]==Q){
                sum++;
            }
        }
    }
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(p[i][j]==Q)state(p,i,j);
        }
    }
    
    if(sum==8){
        //printf("\ncount = %d , sid = %d\n",sum,sid);
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                Ans[i][j]=p[i][j];
                //if(p[i][j]==Q)printf("Q");
                //else printf(".");
            }
            //printf("\n");
        }
        return 0;
    }
    if(sid>=8)return -1;
    
    for(i=0;i<8;i++){
        if(p[i][sid]==E){
            p[i][sid]=Q;
            res++;
            if(solve(p,sid+1)==0){
                return 0;
            }
            p[i][sid]=E;
        }
    }
    if(res==0){
        solve(p,sid+1);
    }
    
    return -1;
}

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

using namespace std;
using ll = long long;
using Lll = list<ll>;
using Vll = vector<ll>;
using Matll = vector<Vll>;

#define rep(a,x,i,f) for(ll a = i; a < f; a+=x )
#define repR(a,x,i,f) for(ll a = i; a > f; a-=x )

ll ms = 1123456789;

int main() 
{
  ll n,max;
  cin >> n;
  Matll dh(n,Vll(3));


  rep(i,1,0,n)
    rep(j,1,0,3)
      cin >> dh[i][j];

  rep(i,1,1,n)
  {
    dh[i][0] += dh[i-1][1] > dh[i-1][2] ? dh[i-1][1] : dh[i-1][2];
    dh[i][1] += dh[i-1][0] > dh[i-1][2] ? dh[i-1][0] : dh[i-1][2];
    dh[i][2] += dh[i-1][1] > dh[i-1][0] ? dh[i-1][1] : dh[i-1][0];
  }
  
  --n;
  max = 
  dh[n][0] > dh[n][1] && dh[n][0] > dh[n][2] ? 0 :
  dh[n][1] > dh[n][2] && dh[n][1] > dh[n][0] ? 1 :
                                               2; 

  cout << dh[n][max] << endl;
}


Measured memory_bytes: 7680
# 20/4/20 Youtube解説の方法
n = int(input())
s = input()

ans = 0
for i in range(1000):
    t = list(str(i).zfill(3))
    ti = 0
    for j in range(n):
        if s[j] == t[ti]:
            ti += 1
            if ti == 3: break
    else:
        continue
    ans += 1

print(ans)

Measured memory_bytes: 41180
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long LL;

using namespace std;

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

int main() {

  LL N, X;
  cin >> N >> X;

  std::vector<LL> x(N,0);
  for(LL i=0; i<N; i++) {
    cin >> x[i];
  }

  LL ans = abs(X-x[0]);
  for(LL i=0; i<N; i++) {
    ans = gcd(ans, abs(X-x[i]));
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
int main() {

    int n,m,i,j;
    int a,b;
    int A[100][100] = {{0}};
    int B[100] = {0};
    int c[100] = {0};

    scanf("%d %d " ,&n,&m);

    for(j=0; j<n; j++) {
        for(i=0; i < m; i++) {
            scanf("%d",&a);
            A[j][i] = a;
        }
    }

    for(j=0; j<m; j++) {
        scanf("%d",&b);
        B[j] = b;
    }

    for(j=0;j<n ; j++){ 
        for(i = 0; i<m; i++){
            c[j] = c[j] + A[j][i]*B[i];
        }
    }

    for(i=0;i<n;i++) {
        printf("%d\n",c[i]);
    }
return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main(){
  ll N;cin>>N;
  vl A(N);rep(i,N)cin>>A[i];
  vector<ll> p(N);
  rep(i,N){
    p[A[i]-1]++;
  }
  

  ll ans =0;
  rep(i,N){
    ans +=p[i]*(p[i]-1)/2;
  }
  rep(i,N){
    ll k =ans -p[A[i]-1]*(p[A[i]-1]-1)/2+(p[A[i]-1]-1)*(p[A[i]-1]-2)/2;
    cout <<k<<endl;  
  }

}
  


Measured memory_bytes: 5760
#include<iostream>
#include<cstdio>
using namespace std;
int a[101000],b[101000];
int main()
{
	int n;scanf("%d",&n);long long sum=0,tot=1ll*n*(n+1)/2,tot2=0;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i];
	if(sum%tot!=0)return 0*puts("NO");a[0]=a[n];
	int Max=0;for(int i=1;i<=n;i++)b[i]=a[i]-a[i-1],Max=max(Max,b[i]);
	for(int i=1;i<=n;i++)tot2+=(Max-b[i])/n,b[i]=(b[i]%n+n)%n;b[0]=b[n];
	for(int i=1;i<=n;i++)if(b[i]!=b[i-1])return 0*puts("NO");
	long long lst=sum-tot2*tot;
	if(lst/n%tot!=0)return 0*puts("NO");
	if(lst<0)return 0*puts("NO");
	return 0*puts("YES");
 } 

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(string[] args){
    var ans=0;
    var vals = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
    int A=vals[0];
    int B=vals[1];
    if(A<=5)ans=0;
    else if(A<=12) ans=B/2;
    else ans=B;
    Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11220
from collections import Counter
n,m=map(int, input().split())
a=list(map(int, input().split()))
c=Counter(a)
for i in range(m):
    x,y=map(int, input().split())
    c[y]+=x
ans=0
for i in sorted(c, reverse=True):
    if n>c[i]:
        ans+=c[i]*i
        n-=c[i]
    else:
        ans+=n*i
        n=0
    if n<=0:break
print(ans)

Measured memory_bytes: 32448
char s[9],a[6];main(n){for(;~scanf("%*d,%s",s);a[(s[1]+s[0]-64)%10]++)s[1]-=s[1]?64:0;printf("%d\n%d\n%d\n%d\n",a[1],a[2],a[3],a[5]);exit(0);}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    int n; cin >> n;
    int a[21],b[21],c[21];
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=1;i<=n;i++) cin >> b[i];
    for(int i=1;i<n;i++) cin >> c[i];
    int sum=b[a[1]]; int pre=a[1];
    for(int i=2;i<=n;i++){
        if(pre!=n&&pre+1==a[i]){
            sum += b[a[i]]+c[pre];
            pre = a[i];
        }else{
            sum += b[a[i]];
            pre = a[i];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
import sys,collections,math,random,itertools;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()

import numpy
def primesfrom2to(n):
    """ Input n>=6, Returns a array of primes, 2 <= p < n """
    sieve = numpy.ones(n/3 + (n%6==2), dtype=numpy.bool)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[       k*k/3     ::2*k] = False
            sieve[k*(k-2*(i&1)+4)/3::2*k] = False
    return list(numpy.r_[2,3,((3*numpy.nonzero(sieve)[0][1:]+1)|1)])

lis = primesfrom2to(55555)
lis2 = []
for e in lis:
    if e % 5 == 1:
        lis2.append(str(e))
ans = random.sample(lis2,n)
print(" ".join(ans))

Measured memory_bytes: 13476
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define all(v) v.begin(), v.end()
  #define mod INT_MAX 
  const int MOD=1e9+7;
  const int N=2e5+2;

  int32_t main()
  {
    /*#ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
    #endif*/
       IOS
      string s,t;
      cin>>s>>t;
      int ans=0;
      for(int i=0;i<s.length();i++)
      {
      	if(s[i]!=t[i])
      		ans++;
      }
      cout<<ans;
       
       return 0;
     }

Measured memory_bytes: 3832
import java.math.BigDecimal;
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int[] values = new int[N];

        int sum = 0;
        for (int i = 0; i < N; i++) {
            int value = sc.nextInt();
            sum += value;
            values[i] = value;
        }
        Arrays.parallelSort(values);

        int index = 0;
        while (sum % 10 == 0) {
            if (index >= N) {
                sum = 0;
                break;
            }
            if (values[index] % 10 != 0) {
                sum -= values[index];
            }
            index++;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

  



  int a,b,c;

  cin >> a>>b>>c;
  int ans;

  vector<int> v;
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);

  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  // for(int x :v)
  //   cout<<x<<endl;

  int d1 = v[0]-v[1];
  // cout<<d1<<endl;
  v[2]+=d1;
  int d2 = (v[0] - v[2]) /2;
  if(((v[0] - v[2])%2)==1)
    d2+=2;
  ans=d1+d2;


  cout<<ans<<endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  int w,a,b;
  cin>>w>>a>>b;
  int ans=abs(a-b)-w;
  if(ans<0)cout<<0<<endl;
  else cout<<ans<<endl;
}

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


int main()
{
    int n;
    cin >> n ;
    int sum=0,pre;
    bool ok=true;
    rep(i,n)
    {
        int a; cin >> a;
        if(ok){
            sum+=a;
            pre=a;
            ok=false;
            continue;
        }
        
        if(a>pre)sum+=a-pre;
        pre=a;
        if(a==0)ok=true;
    }
    cout<<sum<<endl;
    return 0;
}

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

int main() {
  int n, q;
  std::cin >> n;
  std::vector<int> s(n);
  for (int i = 0; i < n; ++i)
    std::cin >> s.at(i);
  std::cin >> q;
  std::vector<int> t(q);
  for (int i = 0; i < q; ++i)
    std::cin >> t.at(i);

  int count = 0;
  for (auto i : t) {
    std::size_t l = 0, r = s.size();
    while (l < r) {
      int m = (r + l) / 2;
      int j = s.at(m);
      if (i == j) {
        ++count;
        break;
      }
      if (i > j)
        l = m + 1;
      else
        r = m;
    }
  }

  std::cout << count << std::endl;
}



Measured memory_bytes: 3292
N, A, B = map(int, input().split())

ans = 0

for x in range(1, N + 1):
    SUM = 0
    num = x
    while x > 0:
        SUM += (x % 10)
        x //= 10
    if A <= SUM <= B:
        ans += num
        
print(ans)

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

using namespace std;

int n, a[210], ans;

int main() {
    cin >> n;
    n *= 2;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    for (int i = 2; i <= n; i += 2) {
        ans += min(a[i], a[i - 1]);
    }
    cout << ans;
}


Measured memory_bytes: 256
package main

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

// input に使うやつ
var rdr = bufio.NewReaderSize(os.Stdin, 10000)

func readLine() string {
	buf := make([]byte, 0, 10000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

// string から int へ
func atoi(s string) int {
	i, _ := strconv.Atoi(s)
	return i
}

// 一つの文字を int として読み込み
func readInt() int {
	return atoi(readLine())
}

// 複数の文字を int のスライスとして読み込み
func readInts() []int {
	in := readLine()
	ins := strings.Split(in, " ")
	out := make([]int, len(ins))
	for i, v := range ins {
		out[i] = atoi(v)
	}
	return out
}

func main() {
	in := readInt()

	fmt.Println(3 * in * in)
}


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

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

int tGcd(int a, int b, int c){
    return gcd(c,gcd(a , b));
}


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

    int a;
    int s = 0;
    cin >> a ;

    for(int i =1; i<= a; i++){
        for(int j = 1; j <= a; j++){
            for(int k = 1; k <= a; k++){
                s+=tGcd(i,j,k);
            }
        }
    }
    cout << s;
}

Measured memory_bytes: 3652
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	const int start = 0;
	const int next = 1;
	string s;
	cin >> s;
	LL k;
	cin >>k;

	LL r = 0;

	LL n = SIZE(s);
	int mode = start;
	LL renzoku = 1;
	LL naibu = 0;
	LL renzoku_start=1;
	FOR(i,1,n){
		if(s[i] == s[i-1]){
			renzoku ++;
		}
		else{
			if(mode == start){
				mode = next;
				renzoku_start = renzoku;
			}
			naibu += renzoku / 2;
			renzoku = 1;
		}
	}

	dump(naibu)
	dump(renzoku)
	dump(renzoku_start)
	dump(mode)

	if(mode == start){ // 全部同じ
		cout << k*n/2 << endl;
		return ;
	}

	if(s[0] == s[n-1]){ // 最初と最後が同じ
		naibu -= renzoku_start/2;
		r = renzoku_start/2;
		r +=  renzoku /2;
		r += k*naibu;
		r += (k-1) * ((renzoku + renzoku_start) / 2);
		cout << r << endl;
		return;
	}

	r = k*naibu;
	r += k*(renzoku/2);

	cout << r << endl;




	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        bool flg = true;
        string t;
        int c = 0;
        
        while (flg)
        {
            flg = false;
            for (int i=(n-1); i>=1; i--)
            {
                if (int.Parse(s[i])<int.Parse(s[i-1]))
                {
                    t = s[i];
                    s[i] = s[i-1];
                    s[i-1] = t;
                    flg = true;
                    c++;
                }
            }
        }
        
        Console.WriteLine(string.Join(" ", s));
        Console.WriteLine(c.ToString());
    }
}


Measured memory_bytes: 9132
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
    ll N,C,K;
    cin>>N>>C>>K;
    priority_queue<ll,vector<ll>,greater<ll>> T;
    REP(i,N)
    {
        ll tmp;
        cin>>tmp;
        T.push(tmp);
    }

    int res = 1;
    int left = C - 1;
    ll start = T.top(); T.pop();
    while(!T.empty())
    {
        ll next = T.top(); T.pop();
        if(left==0 || next-start>K)
        {
            res++;
            left=C-1;
            start = next;
        } 
        else
        {
            left--;
        }
    }
    cout << res<<endl;
    
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define maxs 202020
#define mme(i,j) mememset(i,j,sizeof(i))
using namespace std;
char s[maxs];
string res;
int main()
{
    int n;
    while(~scanf("%d",&n)){
        res.clear();
        scanf("%s",s);
        int len=strlen(s),lef=0;

        for(int i=0;i<len;i++)
        {
            if(s[i]==')')
            {
                res+=')';
                res.insert(0,"(");
            }
            if(s[i]=='('){
                res+='(';
                i++;
                lef=1;
                while(i<n&&lef>0){
                    if(s[i]==')')
                    {
                        lef--;
                        res+=')';
                    }
                    else if(s[i]=='('){
                                lef++;
                                res+='(';
                    }
                    i++;
                }
                i--;
                while(lef){
                    res+=')';
                    lef--;
                }

            }
        }
        cout<<res<<endl;
    }
    return 0;
}

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

int main(){
	int n ; cin>>n;
    if( n <= 1 ){
    	cout << "0" << endl;
        return 0;
    }
  	vector<int > a(n),dp(n);
  	for(int i=0;i<n;i++)
      cin>> a[i];
    dp[0] = 0;dp[1] = abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
    	dp[i] = min( dp[i-1]+abs(a[i]-a[i-1]) , dp[i-2] + abs( a[i]-a[i-2]) );
    
    }
    cout << dp[n-1] << endl;
    
    return 0;
	
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

const int INF = 1001001001;
int n, a[100100], b[]={1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};

main(){
    for(int i=0; i<100100; i++){
        a[i] = INF;
    }a[0] = 0;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        for(int j=0; j<12 && i+b[j]<100100; j++){
            a[i+b[j]] = min(a[i+b[j]], a[i]+1);
        }
    }
    printf("%d\n", a[n]);
    return 0;
}

Measured memory_bytes: 512
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_A = [0]
for i,a in enumerate(A, 1):
    tmp = sum_A[i-1] + a
    if tmp <= K:
        sum_A.append(tmp)
        mark_A = i
    else:
        break
    
sum_B = [0]
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B.append(tmp)
        mark_B = i
    else:
        break
    
ans = 0
j = len(sum_B) - 1

for i,a in enumerate(sum_A):
    while sum_B[j] > K - a:
        j -= 1
        
    ans = max(ans, i+j)
    
print(ans)

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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    
    rep(i, 0, h) cin >> s[i];
    rep(i, 0, h){
        bool flag = true;
        rep(j, 0, w){
            if(s[i][j] == '#'){
                flag = false;
                break;
            }
        }
        if(flag){
            rep(j, 0, w){
                s[i][j] = '0';
            }
        }
    }
    rep(i, 0, w){
        bool flag = true;
        rep(j, 0, h){
            if(s[j][i] == '#'){
                flag = false;
                break;
            }
        }
        if(flag){
            rep(j, 0, h){
                s[j][i] = '0';
            }
        }
    }
    rep(i, 0, h){
        bool flag = false;;
        rep(j, 0, w){
            if(s[i][j] == '0') continue;
            else{
                cout << s[i][j];
                flag = true;
            }
        }
        if(flag) cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int goal[MAX][65];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,K;cin>>N>>K;
    vector<int> to(N);
    for(int i=0;i<N;i++){
        cin>>to[i];
        to[i]--;
        
        goal[i][0]=to[i];
    }
    
    for(int j=1;j<65;j++){
        for(int i=0;i<N;i++){
            goal[i][j]=goal[goal[i][j-1]][j-1];
        }
    }
    
    int now=0;
    
    for(int j=0;j<63;j++){
        if(K&(1LL<<j)){
            now=goal[now][j];
        }
    }
    
    cout<<now+1<<endl;
}



Measured memory_bytes: 54696
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
long K= scan.nextLong();
long N=100;
int i=0;
while(N<K){

     N= (long) (N*1.01);
    i=i+1;



}

System.out.println(i);

        // write your code here
    }
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;



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

    string s; cin >> s;
    int siz = s.size();
    REP(i,siz) cout << 'x';
    cout << endl;
    return 0;
}



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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int N, M;
int WA[105000];
bool AC[105000];

void solve()
{
    cin >> N >> M;
    int WAnum = 0;
    int ACnum = 0;
    for (int i = 1; i <= N; i++) {
        WA[i] = 0;
        AC[i] = false;
    }

    while (M--) {
        int p;
        string S;
        cin >> p >> S;

        if (AC[p]) continue;
        if (S == "AC") {
            AC[p] = true;
            ++ACnum;
            WAnum += WA[p];
        }
        else if (S == "WA") {
            ++WA[p];
        }
    }

    cout << ACnum << " " << WAnum << endl;
}

int main()
{
    solve();
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const ll INF = 1<<21;
static const ll MOD = 1e9 + 7;

bool pairCompare(const pair<int, int>& firstElof, const pair<int, int>& secondElof) {
    return firstElof.first > secondElof.first;
}

int main(void) {
    string S;
    cin >> S;

    int former, latter;
    former = (S.at(0)-48)*10+(S.at(1)-48);
    latter = (S.at(2)-48)*10+(S.at(3)-48);
    
    if(1<=latter&&latter<=12&&(former<=0||13<=former)) cout << "YYMM" << endl;
    else if(1<=former&&former<=12&&(latter<=0||13<=latter)) cout << "MMYY" << endl;
    else if(1<=former&&former<=12&&1<=latter&&latter<=12) cout << "AMBIGUOUS" << endl;
    else cout << "NA" << endl;
    
    return (0);
}


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

int main() {
    int X, Y;
    cin >> X >> Y;

    if(Y % 2 == 1){
        cout << "No" << endl;
        return 0;
    }

    if(X * 2 > Y){
        cout << "No" << endl;
    }else if(X * 4 < Y){
        cout << "No" << endl;
    }else{
        for(int i = 0; i < 50; i++){
            if((Y - 4 * i) / 2 == X - i){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
    }
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

VI g[100005];
VI g0(100005, INF);
VI g1(100005, INF);
VI g2(100005, INF);


min_priority_queue<pair<int, pair<int, int>>> pq;
int s, t;

void solve() {


	pq.push({ 0,{0,s} });
	g0[s] = 0;

	while (!pq.empty()) {
		auto p = pq.top();
		pq.pop();
		int a = p.first;
		int b = p.second.first;
		int c = p.second.second;

		for (int i : g[c]) {
			if (b == 0) {
				if (g1[i] > a) {
					g1[i] = a;
					pq.push({ a,{1,i} });
				}
			}
			if (b == 1) {
				if (g2[i] > a) {
					g2[i] = a;
					pq.push({ a,{2,i} });
				}
			}
			if (b == 2) {
				if (g0[i] > a) {
					g0[i] = a+1;
					pq.push({ a+1,{0,i} });
				}
			}
			
		}
	}

}


int main() {
	
	int n, m;
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
	}
	
	cin >> s >> t;
	s--; t--;


	solve();

	if (g0[t] == INF)cout << -1 << endl;
	else cout << g0[t] << endl;




}



Measured memory_bytes: 6912
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int c = 0;

        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        for(int i=0;i<n-1;i++){
            int min = i;
            for(int j=i+1;j<n;j++){
                if(a[j]<a[min]){
                    min = j;
                } 
            }
            if(a[i]>a[min]){
                int b = a[i];
                a[i] = a[min];
                a[min] = b;
                c++;
            }
        }
        for(int i=0;i<n;i++){
            if(i==n-1) System.out.println(a[i]);
            else System.out.print(a[i]+" ");
        }
        System.out.println(c);
        sc.close();
    }
}


Measured memory_bytes: 26316
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

 struct UF {
	vector<int>par;//親
	vector<int>Rank;//木の深さ
    vector<int>sz;//要素数

    UF(int n){init(n);}

	//初期化
	void init(int n) {
		par.resize(n); Rank.resize(n);sz.resize(n);
		for (int i = 0; i < n; i++) {
			par[i]= i;
			Rank[i] = 0;
            sz[i]=1;
		}
	}

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	//xとyの属する集合を併合
	bool unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return false;//すでに同じ集合に属している

		if (Rank[x] < Rank[y]) {//高さが小さい方を下に
			par[x] = y;
            sz[y]+=sz[x];
		}
		else {
			par[y] = x;
			if (Rank[x] == Rank[y])Rank[x]++;//同じだとrankが変わらないままになるので増やす（それ以外は大きい方のrankが採用される）
            sz[x]+=sz[y];
		}
		return true;
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}

    int size(int k){//要素数を求める
        return sz[find(k)];
    }
};

using P = pair<ll, int>;
void solve()
{
	int n,m;
	cin >> n >> m;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll ans = 0;
	UF tree(n);
	rep(i,m){
		int x, y;
		cin >> x >> y;
		tree.unite(x, y);
	}
  if(m==n-1){
    cout << 0 << "\n";
    return;
  }
  if (n-2*(n-1-m)<0)
	{
		cout << "Impossible\n";
		return;
	}
	vector<P> p(n);
	rep(i,n){
		p[i] = {a[i], i};
	}
	sort(all(p));
	set<int> st;//連結成分の個数
	rep(i,n){
    st.emplace(tree.find(i));
  }
  int sz = st.size();
  vector<bool> used(n);
  set<int> st2;
  int pos = 0;
  rep(i, n)
  {
    int x = p[i].second;
    if (!used[tree.find(x)])
    {
      ans += p[i].first;
      used[tree.find(x)] = true;
      st2.emplace(x);
    }
  }
  int num = 2 * (n - 1 - m) - sz;
  rep(i,n){
    int x = p[i].second;
    if (!st2.count(x))
    {
      ans += p[i].first;
      --num;
    }
    if(num==0)
      break;
  }
  cout << ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}



Measured memory_bytes: 8448
#include<iostream>
#include<algorithm>
#include<math.h>
#include <iterator>
#include <map>
#include<cmath>
using namespace std;


int main (){
    int n;
    cin>>n;
    int x[n];
    for(int i=0;i<n;i++)cin>>x[i];
    int counter=1,mini=x[0];
   for(int i=1;i<n;i++)if(mini>=x[i])counter++,mini=x[i];
   cout<<counter<<endl;

	return 0;
}











Measured memory_bytes: 1024
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    auto P = minmax_element(A.begin(), A.end());

    cout << *P.second - *P.first << '\n';
    return 0;
}

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

def dfs(value, use):
    if value > N:
        return 0

    res = int(use == 0b111)
    res += dfs(value * 10 + 7, use | 0b001)
    res += dfs(value * 10 + 5, use | 0b010)
    res += dfs(value * 10 + 3, use | 0b100)

    return res

print(dfs(0, 0))


Measured memory_bytes: 42728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  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;
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()

	ans := int(math.Ceil((-1 + math.Sqrt(1+8*float64(N))) / 2))
	out(ans)
}


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

int a,b,c,d, recA, recB;
int main () {
	
	cin >> a >> b >> c >> d;
	
	recA = a*b;
	recB = c*d;
	
	if (recA > recB)
		cout << recA;
	else 
		cout << recB;
return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func f(n int) int {
	if n%2 == 0 {
		return n / 2
	}
	return 3*n + 1
}

func main() {
	var s, p, a, ans int
	L := make([]int, 0)
	fmt.Scan(&s)
	for i := 1; ; i++ {
		if i == 1 {
			a = s
		} else {
			a = f(p)
		}
		L = append(L, a)
		p = a
		found := false
		if i >= 3 {
			for j := len(L) - 2; j >= 0; j-- {
				if a == L[j] {
					ans = i
					found = true
				}
			}
		}
		if found {
			break
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
n = int(input())

a = input().split()

d = {}
for i in a:
    d[i] = d.get(i,0)+1
    
for i in d:
    d[i] = d[i]//2

s = []
for i in d:
    s += [int(i)]*int(d.get(i))
if(len(s)>=2):
    s.sort()
    print(s[-1]*s[-2])
else:
    print(0)

Measured memory_bytes: 20880
w, h, n = map(int, input().split())
x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    x_min = max(x_min, x)
  elif a == 2:
    x_max = min(x_max, x)
  elif a == 3:
    y_min = max(y_min, y)
  else:
    y_max = min(y_max, y)
if x_max > x_min and y_max > y_min:
  print((x_max-x_min)*(y_max-y_min))
else:
  print('0')

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    for (int i = 0;i < n;i++) {
        cin >> a[i] >> b[i];
    }
    int dp[h + 1];
    for (int j = 0;j <= h;j++) {
        dp[j] = 1e9;
    }

    for (int j = 0;j <= h;j++) {
        for (int i = 0;i < n;i++) {
            if (j - a[i] <= 0) {
                chkmin(dp[j], b[i]);
            }else {
                chkmin(dp[j], dp[j - a[i]] + b[i]);
            }
        }
    }

    cout << dp[h];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define F first
#define S second
#define random(x) (rand()%x)
const int maxn=200005,INF=0x3f3f3f3f,mod=1000000007;
ii a[maxn];
int main(){
	int n,ans=0,t,k;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i].F);
	}
	sort(a,a+n);
	for(int i=n-1;i>0;i--){
		if(a[i].S) continue;
		t=1;
		while(t<=a[i].F) t<<=1;
		k=upper_bound(a,a+i,ii(t-a[i].F,0))-a;
		if(k>0&&k<=i&&a[k-1].S==0&&a[i].F+a[k-1].F==t){
			ans++;
			a[k-1].S++;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int a,b[4],c;
	cin >> a;
	REPR(i, 3) {
		b[i] = a % 10;
		a = a / 10;
	}
	REP(i, i < (1 << 3)) {
		c = b[0];
		REP(j, 3) {
			if (i&(1 << j)) c += b[j + 1];
			else c -= b[j + 1];
		}
		if (c == 7) {
			cout << b[0];
			REP(j, 3) {
				if (i&(1 << j)) cout << '+' << b[j + 1];
				else cout << '-' <<  b[j + 1];
			}
			cout << "=7" << endl;
			break;
		}
	}
}


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

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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

	ll N;
	cin >> N;
	ll a = N/2;
	ll b = N-a;

	cout << a * b << endl;

	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


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

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

    int cnt = 0;
    if(str[0] == '1'){
        cnt++;
    }
    if(str[1] == '1'){
        cnt++;
    }
    if(str[2] == '1'){
        cnt++;
    }
  cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>

typedef long long ll;
using namespace std;


int sum(int i,int* bit){
	int s = 0;
	while(i > 0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int i, int x,int* bit,int n){
	while(i <= n){
		bit[i] += x;
		i += i & -i;
	}	
}

int main()
{
	int T;
	while(~scanf("%d",&T)){
		if(T==0) break;
		int* bit = new int[T+1]();	
		int res=numeric_limits<int>::min();
		for(int t=1;t<=T;t++){
			int tmp;
			scanf("%d",&tmp);
			add(t,tmp,bit,T);
		}

		for(int a=0;a<=T;a++){
			for(int b=a+1;b<=T;b++){
				res=max(sum(b,bit) - sum(a,bit),res);
			}
			//cout << sum(a,bit) << endl;
		}
		
		printf("%d\n",res);
	}
}

Measured memory_bytes: 928
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
int k,n;
int cun[200005];
int main()
{
	scanf("%d%d",&k,&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&cun[i]);	
	}
	sort(cun+1,cun+1+n);
	int ans=0;
	for(int i=1;i<n;i++)
	{
		ans=max(ans,cun[i+1]-cun[i]);
	}
	ans=max(ans,k-cun[n]+cun[1]);
	ans=k-ans;
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 896
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll cnt;

int main(){
	string s;
	cin >> s;
	arep(1,i,s.length()){
			if(s[i]!=s[i-1])
				cnt++;
		}
		cout << cnt << endl;
	}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
#define ll long long
#define mod (ll)1000000007
using namespace std;
vector<string> al;
int main()
{
    for(int i = 0; i <= 9; i++){
        for(int j = 0; j <= 9; j++){
            for(int k = 0; k <= 9; k++)
            {
                string s = "";
                s+=(i+'0');
                s+=(j+'0');
                s+=(k+'0');

                al.push_back(s);
            }
        }
    }

    int n;
    cin>>n;
    string s;

    cin>>s;

    // int f[10];
    // memset(f,0,sizeof(f));
    // for(auto i:s)
        // f[i-'0']++;


    // int fc[10];
    int ans = 0;
    // memset(f,0,sizeof(f));
    // cout<<s<<"\n";
    for(auto c: al){
       // if(c == "224")
            // cout<<c<<"\n";
       int j = 0;
       for(int i = 0; i < n; i++){

            if(j == 3)
            {
                ans++;
                j = 0;
                break;
            } 
            if(s[i] == c[j]){
                // if(c == "224")
                    // cout<<c[j]<<" "<<s[i]<<"\n";
                j++;
            }
       }
       if(j == 3)   ans++;
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h> 
#include <time.h>
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 1e6+10;
const int N = 1e5+10;
const int E = 2e5+10;  
int n,k;
map<string,bool> m;
string t;

int main(){
	cin>>n;
	int ans = 0;
	F(i,1,n){
		cin>>t;
		if(!m[t]){
			m[t] = 1;
			ans++;
		}	
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 19232
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<ld> a(n);
    rep(i, n) cin >> a[i];
    ld sum = 0;
    rep(i, n) sum += 1 / a[i];
    println(1/sum)
    
    return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,sum=0,a;
  int ans;
  cin >> n >> m;
  for(int i = 0; i<m; i++){
    cin >> a;
    sum += a;
  }
  if(n-sum < 0){
    ans = -1;
  }else{
    ans = n-sum;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604