akhauriyash/Code-Regression huggingface dataset:
//OPTIMIZATONS
#pragma GCC optimize("02")
//CODE
#include<bits/stdc++.h>
// uncomment the below code to use int as long long
#define int long long
// uncomment the below code to use float as double
//#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

using namespace std;
const int mod = 1e9 + 7;
int power(int a,int b){
	if(b==0) return 1;
	if(b==1) return a;
	int t = power(a,b/2);
	t = (t*t)%mod;
	if(b&1) return (t*a)%mod;
	return t%mod;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n,k;
	cin>>n>>k;
	//cout<<power(9,3)<<endl;
	int ans = 0;
	int ways[k+1];
	for(int i=k;i>=1;i--){
		int cur = power(k/i,n);
		ways[i] = cur;
		for(int j=2;i*j<=k;j++){
			ways[i] = ((ways[i]-ways[i*j])+mod)%mod;
		}
		ans += (i*ways[i])%mod;
		ans %= mod;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 4360
/*
** author:mahmoud magdy
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
int a[100005];
int dp[100005];
int n , k;
int solve(int i){
 if(i>=n)return 1e9;
 if(i==n-1)
    return 0;
 if(dp[i]!=-1)
      return dp[i];
 int mn=1e9;
 for(int j=1;j<=k;++j){
 int ch1=abs(a[i]-a[i+j])+solve(i+j);
 mn=min(ch1,mn);
 }
 return dp[i]=mn;
}
int main()
{
    fast();
    n=D();k=D();
    for(int i=0;i<n;++i){
        a[i]=D();
    }
    memset(dp,-1,sizeof dp);
    cout<<solve(0)<<endl;
}


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

#define pi(a) printf("%d\n",a)
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define INF 0x3f3f3f3f
using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}


const int N = 2e5 + 10;

struct Seg_Tree {
    struct T {
        int l, r, ans, add;
    } t[N * 4];

    void build(int p, int l, int r) {
        t[p].l = l, t[p].r = r, t[p].ans = t[p].add = 0;
        if (l == r) return;
        int mid = (l + r) >> 1;
        build(p << 1, l, mid);
        build(p << 1 | 1, mid + 1, r);
    }

    void spread(int p) {
        if (t[p].add) {
            t[p << 1].ans = t[p].l - t[p].add;
            t[p << 1].add = t[p].add;
            t[p << 1 | 1].ans = ((t[p].l + t[p].r) >> 1) + 1 - t[p].add;
            t[p << 1 | 1].add = t[p].add;
            t[p].add = 0;
        }
    }

    void change(int p, int l, int r, int c) {
        if (l <= t[p].l && t[p].r <= r) {
            t[p].ans = t[p].l - c, t[p].add = c;
            return;
        }
        spread(p);
        int mid = (t[p].l + t[p].r) >> 1;
        if (l <= mid)change(p << 1, l, r, c);
        if (r > mid)change(p << 1 | 1, l, r, c);
        t[p].ans = min(t[p << 1].ans, t[p << 1 | 1].ans);
    }

    int ask(int p, int x) {
        if (t[p].l == t[p].r)return x - t[p].ans;
        spread(p);
        int mid = (t[p].l + t[p].r) >> 1;
        return x <= mid ? ask(p << 1, x) : ask(p << 1 | 1, x);
    }
} tr;

int n, m, now = 1;

int main() {
    n = qr(), m = qr();
    tr.build(1, 1, m);
    repi(i, 1, n) {
        int l = qr(), r = qr();
        if (now >= l && now <= r)tr.change(1, now, r, -INF), now = r + 1;
        else if (now < l)tr.change(1, l, r, tr.ask(1, l - 1));
        if (now > m) {
            repi(j, i, n)puts("-1");
            return 0;
        }
        pi(i + tr.t[1].ans);
    }
    return 0;
}


Measured memory_bytes: 11952
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{

    internal class Solution
    {
        public int N;
        public int[] P;

        public void Run()
        {
            N = Input.ReadInt();
            P = new int[N];
            for (int i = 0; i < N; i++)
            {
                P[i] = Input.ReadInt() - 1;
            }

            // Position of Array P
            var Pos = new int[N];
            for (int i = 0; i < N; i++)
            {
                Pos[P[i]] = i;
            }

            // connected
            var C = new int[N - 1];
            for (int i = 0; i < N - 1; i++)
            {
                if (Pos[i] < Pos[i + 1]) C[i] = 1;
                else C[i] = 0;
            }

            // count
            int mx = 0;
            int count = 0;
            for (int i = 0; i < N - 1; i++)
            {
                if (C[i] == 1)
                {
                    count++;
                    mx = Math.Max(mx, count);
                }
                else
                {
                    count = 0;
                }
            }

            int ret = (N -1)- mx;
            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

void solve(){
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

void fnInput(vector<int>& rvnMtrx)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnMtrx.resize(nMaxSiz + 1);

  for (int i = 0; i < nMaxSiz; ++i)
    cin >> rvnMtrx[i] >> rvnMtrx[i + 1];
}

int fnMtrxChainMultpl(vector<vector<int>>& rvvnDetDP, const vector<int>& cnrvnMtrx)
{
  for (int i = 1; i < cnrvnMtrx.size(); ++i)  rvvnDetDP[i][i] = 0;

  const int cnMaxSiz = cnrvnMtrx.size() - 1;
  for (int nDif = 1; nDif <= cnMaxSiz - 1; ++nDif)
    for (int nRow = 1; nRow <= cnMaxSiz - nDif; ++nRow)
    {
      int nCol = nRow + nDif;
      for (int nx = nRow; nx <= nCol - 1; ++nx)
        rvvnDetDP[nRow][nCol] =
          min(rvvnDetDP[nRow][nCol],
              rvvnDetDP[nRow][nx] + rvvnDetDP[nx + 1][nCol] 
                                  + cnrvnMtrx[nRow - 1] * cnrvnMtrx[nx] * cnrvnMtrx[nCol]);
    }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnDetDP; 
  vector<int> vnMtrx;

  fnInput(vnMtrx);
  vvnDetDP.resize(vnMtrx.size(), vector<int>(vnMtrx.size(), INT_MAX));

  fnMtrxChainMultpl(vvnDetDP, vnMtrx);
  cout << vvnDetDP[1][vnMtrx.size() - 1] << endl;
  return 0;
}

Measured memory_bytes: 3256
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
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 x,ll y){
    if(x<y) swap(x,y);
    //xの方が常に大きい
    ll r;
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}
ll MOD=1000000007;
int main(){
    ll N;cin>>N;
    ll T=1;
    ll n=1;
    ll E=1;
    rep(i,N){
        T=(T*10)%MOD;
        n=(n*9)%MOD;
        E=(E*8)%MOD;
    }
    ll ans=(T%MOD)-(2*n%MOD)+(E%MOD);
    while(ans<0){
        ans+=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		knapSack();
	}
	
	public static void knapSack() {
		Scanner sc = new Scanner(System.in);
		int items = sc.nextInt();
		int weight = sc.nextInt();
		
		int[] values = new int[items];
		int[] weights = new int[items];
		for(int i =0;i<items;i++) {
			weights[i] = sc.nextInt();
			values[i] = sc.nextInt();
		}
		
		long[][]dp = new long[items+1][weight+1];
		knapSackHelper(dp, items,weight,weights, values);
		System.out.println(dp[items][weight]);
	}

	private static long knapSackHelper(long[][] dp, int items, int WT, int[] weights, int[] values) {
	//	System.out.println("items "+ items +" WT "+ WT + "current Item ");
		if(items <=0) {
			return 0;
		}
		
		if(dp[items][WT]!=0) {
			return dp[items][WT];
		}
		
		if(WT>=weights[items-1]) {
			dp[items][WT] = knapSackHelper(dp, items-1,WT-weights[items-1],weights,values)+values[items-1];
		}
		
		dp[items][WT] = Math.max(dp[items][WT], knapSackHelper(dp, items-1, WT, weights, values));
		//System.out.println("dp ["+ items+"]["+WT+"] "+dp[items][WT]);
		
		return dp[items][WT];
	}
}


Measured memory_bytes: 140588
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
  while(true){
  
    int d,n,m,longs=0;

    cin>>d;
    if(d==0){
      break;
      cout<<"breaking"<<endl;
    }
    cin>>n;
    cin>>m;

    vector<int> dn,kn;
    
    dn.push_back(0);//??¬?????????
    for(int i=1;i<n;i++){
      int in;
      cin >>in;
      dn.push_back(in);
    }
    dn.push_back(d);//??¬?????????
    
    //?????????
    for(int i=0;i<m;i++){
      int in;
      cin >>in;
      kn.push_back(in);
    }

    //???????????°??¨
    /*
     for(int i=0;i<kn.size();i++){
      cout<<"k["<<i<<"]="<< kn[i]<<endl;
    }
    */
    
    //?????????
    sort(dn.begin(), dn.end());

    //???????????°??¨
    /*
     for(int i=0;i<dn.size();i++){
      cout<<"d["<<i<<"]="<< dn[i]<<endl;
    }
    */
    
    //????????¢?´¢
    for(int i=0; i<kn.size(); i++){
      //????????¢?´¢???????????????
      int low=0,high=dn.size()-1,mid;
      for(mid=(low+high)/2 ; dn[mid]!=kn[i] && low<=high ; mid=(low+high)/2){
	if(kn[i]>dn[mid]){
	  low=mid+1;
	}else{
	  high=mid-1;
	}
      }

      //test??¨
      //cout <<"low="<<low<<"  high="<<high<<"   i="<<i<<" k.size="<<kn.size()<<"  dn.size="<<dn.size()<< endl;
      
      if(dn[mid]==kn[i]){
      }else if(abs(dn[high]-kn[i])<abs(dn[low]-kn[i])){
	longs+=abs(dn[high]-kn[i]);
      }else{
	longs+=abs(dn[low]-kn[i]);
      }
      
    }
    cout << longs<<endl;
      //???????????§
 
  }
}

Measured memory_bytes: 3396
def gcd(a,b):
  while b:
    a,b = b,a % b    
  return a

a,b,c,d = map(int,input().split())

a_c = (a-1)//c
a_d = (a-1)//d
a_cd = (a-1)//(c*d//gcd(c,d))

b_c = b//c
b_d = b//d
b_cd = b//(c*d//gcd(c,d))

bb = b - (b_c + b_d - b_cd) 
aa = (a-1) - (a_c + a_d - a_cd)

print(bb - aa)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

#define M 10000000/* your task*/
#define L 14

char H[M]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}


int find(char str[]){

    /* your task */
    if(H[getKey(str)]==1) return 1;
    return 0;

}

int insert(char str[]){

    /* your task */
    H[getKey(str)]=1;

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}


Measured memory_bytes: 11472
#include <iostream>
using namespace std;
int w,h;
int mp[31][31];
int memo[4][31][31];
int memo2[31][31];
int c[4];
int ans;
int cnt;
string str = ">v<^";

void saiki(int x,int y,int dir,int cost) {
  int dx[] = {1,0,-1,0};
  int dy[] = {0,1,0,-1};

  
  if(x == w-1 && y == h-1 && ans > cost) ans = cost;
  else if(memo[dir%4][y][x]>cost && ans > cost){
    memo[dir%4][y][x] = cost;
    cnt++;
    
    //    cout << str[dir%4];
    //  cout <<" "<< x <<" " << y <<" cost="<<cost<<endl
    
    for(int i=0;i<4;i++){
      int ii = (i+dir%4)%4;
      int nx = x + dx[ii];
      int ny = y + dy[ii]; 
      if(nx < 0 || nx >= w || ny < 0 || ny >= h ) continue;
      if(i == mp[y][x]) {
	saiki(nx,ny,(dir+i),cost);
      }
      else
      saiki(nx,ny,(dir+i),cost+c[i]);
      
    }
  }
}

int main() {
  
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;


    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	cin >> mp[i][j];


    for(int i=0;i<4;i++)cin >> c[i];



    for(int i=0;i<4;i++)
      for(int j=0;j<31;j++)
	for(int k=0;k<31;k++)
	  memo[i][j][k] = 1000000000;

    ans = 1000000000;
    cnt = 0;
    saiki(0,0,0,0);

    cout << ans<< endl;
    //  cout << cnt <<endl;
  }

  return 0;
}

Measured memory_bytes: 1388
N, K = map(int, input().split())
j = 0
ls1 = []
ls2 = []

for i in range(1, K+1):
    d = int(input())
    ls1.append(input().split())
for i in range(len(ls1)):
    for j in ls1[i]:
        ls2.append(j)
        x = set(ls2)
print(N - len(x))

Measured memory_bytes: 9616
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;

bool cmp(int a,int b)
{
    return a>b;
}

int main()
{
    ll n,ans=0;
    cin>>n;
    if(n<3)
    {
        cout<<0<<endl;
    }
    else
    {
        ll a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        for(int i=0;i<n-2;i++)
        {
            for(int j=i+1;j<n-1;j++)
            {
                for(int z=j+1;z<n;z++)
                {
                    if(a[i]+a[j]>a[z]&&(a[i]!=a[j])&&a[j]!=a[z])
                    {
                        ans++;
                    }
                    else if(a[i]+a[j]>a[z]&&(a[i]==a[j])||(a[j]==a[z]))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3644
package main

import (
	"fmt"
)

func firstChar(s string) string {
	return s[:1]
}

func lastChar(s string) string {
	return s[len(s)-1:]
}

func main() {
	var n int
	var word string

	fmt.Scan(&n)

	exist := make(map[string]bool)
	words := make([]string, n)

	isOK := true
	for i := 0; i < n; i++ {
		fmt.Scan(&word)

		if exist[word] {
			isOK = false
		}
		words[i] = word
		exist[word] = true
	}

	if isOK {
		for i := 1; i < n; i++ {
			if firstChar(words[i]) != lastChar(words[i-1]) {
				isOK = false
				break
			}
		}
	}
	if isOK {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,W;
  cin>>n>>W;
  vll w(n),v(n);
  rep(i,n) cin>>w[i]>>v[i];
  vvll dp(110,vll(100010));
  for(int i=0;i<n;i++){
    for(int j=0;j<=W;j++){
      if(w[i]<=j){
        dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i][j]);
      }
      else dp[i+1][j]=dp[i][j];
    }
  }
  COUT(dp[n][W]);
}


Measured memory_bytes: 87296
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a;
    cin>>a;

    double d=0;

    if(a%2==0)
    {

        d=a/2;
        d/=a;

    }

    else
    {
        d=(int)a/2;
        d+=1;
        d/=a;

    }
    cout<<d<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

signed main(){
    int k;
    cin>>k;
    if(k%2==0) cout<<(k/2)*(k/2)<<endl;
    else cout<<(k/2)*(k/2+1)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<bool> b(n, true);
    for(int i=0; i<k; i++)
    {
        int d;
        cin >> d;
        for(int j=0; j<d; j++)
        {
            int a;
            cin >> a;
            b.at(a-1) = false;
        }
    }
    int cnt=0;
    for(auto t : b)
    {
        if(t) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

#define fs first
#define se second
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int h = in(), w = in();

	rep(i, w + 2) cout << '#';
	puts("");

	rep(i, h) {
		cout << "#";
		rep(j, w) {
			char c;
			cin >> c;
			cout << c;
		}
		cout << "#\n";
	}

	rep(i, w + 2) cout << '#';
	puts("");
}



Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <complex>

using namespace std;
typedef long long ll;


typedef complex<double> xy_t;
double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }

typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

vector<int> G[100005];
std::vector<P> tree[100010];

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

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define re(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
#define lb lower_bound
#define ub upper_bound

ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans=0;
ll a,b,c,d,e,h,w;
ll x[500005],y[500005],z[500005];
char s[100005],t[100005];
vector <ll> aa,bb;
bool ok=false;
bool check[100005];

int main(){
    ll an=0,bn=0;
    cin>>n>>a>>b;
    cin>>s;
    for(i=0;i<n;i++){
        if(s[i]=='c')p("No");
        if(s[i]=='a'){
            if(an+bn<a+b){
                p("Yes");
                an++;
            }else{
                p("No");
            }
        }
        if(s[i]=='b'){
            if(an+bn<a+b && bn<b){
                p("Yes");
                bn++;
            }else{
                p("No");
            }
        }
    }

   
    return 0;
}


Measured memory_bytes: 7168
#include <cstdio>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;

typedef complex<double> P;

double cross(const P& a, const P& b)
{
	return a.real() * b.imag() - a.imag() * b.real();
}

struct comp
{
	bool operator()(const P& a, const P& b) const
	{
		return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
	}
};

vector<P> convex_hull(vector<P>& ps)
{
	sort(ps.begin(), ps.end(), comp());
	int k = 0, n = ps.size();
	vector<P> qs(n * 2);
	
	for(int i = 0; i < n; ++i){
		while(k > 1 && cross(qs[k-1] - qs[k-2], ps[i] - qs[k-1]) <= 0) k--;
		qs[k++] = ps[i];
	}
	
	for(int i = n - 2, t = k; i >= 0; --i){
		while(k > t && cross(qs[k-1] - qs[k-2], ps[i] - qs[k-1]) <= 0) k--;
		qs[k++] = ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int main()
{
	int n;
	double x, y;
	vector<P> ps;
	while(1){
		scanf("%d", &n);
		if(n == 0) break;
		
		ps.resize(n);
		for(int i = 0; i < n; ++i){
			scanf("%lf,%lf", &x, &y);
			ps[i] = P(x,y);
		}
		
		printf("%d\n", n - (int)convex_hull(ps).size());
	}
}

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

int main () {
	int x, y,count=0;
	char c;
	double a=0.0, b=0.0;
	while(cin >> x) {
		cin >> c;
		cin >> y;
		a += x*y;
		b += y;
		count++;
	}
	b /= count;
	y = (int)b + ( ( b - (int)b ) < 0.5 ? 0 : 1 );
	cout << a << "\n" << y << endl;
	return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>
#define SIZE 100
int main (void)
{
  int n, m, l;
  long c;
  int i, j, k;
  int a[SIZE][SIZE] = {{0},{0}},  b[SIZE][SIZE] = {{0},{0}};

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

  for(i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      scanf("%d", &a[i][j]);
  for (j = 0; j < m; j++)
    for (k = 0; k < l; k++)
      scanf("%d", &b[j][k]);
  

  for (i = 0; i < n; i++) {
    c = a[i][0] * b[0][0];
    for(j = 1; j < m; j++)
      c += a[i][j] * b[j][0];
    printf("%ld", c);
    for (k = 1; k < l; k++) {
      c = a[i][0] * b[0][k];
      for(j = 1; j < m; j++)
	c += a[i][j] * b[j][k];
      printf(" %ld", c);
    }
    putchar('\n');
  }
  return 0;
}

  

Measured memory_bytes: 692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> P;

int main() {
    int K, X;
    cin >> K >> X;
    
    for (int i=X-K+1; i<=X+K-1; i++) {
        cout << i << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    private static HashSet<Integer>[] g;
    private static int N;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        int M = sc.nextInt();
        g = new HashSet[N+1];
        for(int i=0; i<=N; i++){
            g[i] = new HashSet<>();
        }
        int[][] edge = new int[M][2];
        for(int i=0;i<M;i++){
            edge[i][0] = sc.nextInt();
            edge[i][1] = sc.nextInt();
            g[edge[i][0]].add(edge[i][1]);
            g[edge[i][1]].add(edge[i][0]);
        }
        int cnt = 0;
        for(int i=0;i<M; i++){
            int left = edge[i][0];
            int right = edge[i][1];
            if(isBridge(left,right)) cnt++;
        }
        System.out.println(cnt);
    }
    private static boolean isBridge(int left, int right){
        boolean[] visited = new boolean[N+1];
        LinkedList<Integer> fringe = new LinkedList<>();
        fringe.add(left);
        visited[left]=true;
        while(fringe.size()>0){
            int cur = fringe.remove();
            for(Integer w:g[cur]){
                if(cur==left&&w==right) continue;
                if(!visited[w]){
                    visited[w]=true;
                    fringe.add(w);
                }
            }
        }
        return !visited[right];
    }
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <string.h>
#include <algorithm>

int main(void) {
    char input1[256] = "";
    scanf("%s", input1);
    int i=0;
    while(input1[i] != '\0') {
        input1[i] = 'x';
        ++i;
    }
    printf("%s\n", input1);
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 400001;


int sum(ll n){
  int res = 0;
  while(n){
    res += n % 10;
    n /= 10;
  }
  return res;
}
bitset<100001> bb[2];
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int k;
  cin >> k;
  set<int> ss;
  int x = 1;
  for(int i = 0;i < k;i++){
    x *= 10;
    x %= k;
    ss.insert(x);
  }
  if(*ss.begin() == 0){
    cout << 1;
    return 0;
  }
  for(auto el : ss){
    bb[1][el] = 1;
  }
  int lim = sum(k);
  for(int i = 2;i < lim;i++){
    bb[i&1] = bb[i&1^1];
    for(auto el : ss){
      bb[i&1] |= (bb[i&1^1] << el);
      bb[i&1] |= (bb[i&1^1] >> (k - el));
      if(bb[i&1][0]){
//        cout << el << endl;
        cout << i;
        return 0;
      }
    }
  }
  cout << lim;
}


Measured memory_bytes: 3712
using System;
using System.Collections.Generic;
using System.Linq;
 
static class MainClass {

  public static void Main (string[] args) {
    var N = Console.ReadLine();
   // var list = Console.ReadLine().Split(' ').Select(long.Parse);
      var ans = "";
      switch(N){
        case "A":
          ans = "T";
          break;
        case "T":
          ans = "A";
          break;
        case "C":
          ans = "G";
          break;
        case "G":
          ans = "C";
          break; 
      }

      Console.WriteLine(ans);
 
  }
  
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

int main(){
    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;

    if(U == S) A--;
    if(U == T) B--;
    cout << A << " " << B << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n , k = IN()
	#s = input()
	al = LIN()
	pre_aa = [-1]*n
	pos = 0
	pre_aa[0]=0
	for i in range(1, k+1):
		pos = al[pos]-1
		if pre_aa[pos] >= 0:
			loop = i - pre_aa[pos]
			break
		pre_aa[pos] = i
	else:
		return pos + 1
	
	#pa((k,i,loop))
	for _ in range((k - i) % loop):
		pos = al[pos]-1
	
	print(pos + 1)
	
	
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 32424
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

int a[3];

int main() {
    a[0]=read(),a[1]=read(),a[2]=read(); sort(a,a+3);
    if (a[0]&a[1]&a[2]&1) printf("%lld\n",1ll*a[0]*a[1]);
    else puts("0");
    return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A[] = { 1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51 };
	int K;
	cin >> K;
	cout << A[K - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss 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
typedef long long ll;
typedef long double ld;
//typedef ll long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef pair<ll,pair<ll,ll> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000 + 7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)2e18
# define LN 20  
# define EPS 1e-9
typedef pair<ll,pair<ll,ll> > pii;
# define INF1 1e9
# define maxn 1000006
# define offset 100005
const ld eps = 1e-10L;
//# define ll short
/*void LPS()
{
	len = s.length();
    lps[0] = 0;
    for(ll i=1;i<len;i++){

        ll j = lps[i-1];
        while(j > 0 && s[j] != s[i])    j = lps[j-1];
        if(s[i] == s[j])    j++;
        lps[i] = j;
    }
}*/

/*************************************************
struct Coupon {
	ll l;
	ll r;
	ll id;

	Coupon(ll l, ll r, ll id): l(l), r(r), id(id) {} // Initialization

	bool operator<(const Coupon& c) { // Sorting
		return l < c.l;    
	}
};

**************************************************/
bool vis[1002][1002];
int d[1002][1002];
int n,m;
char a[1002][1002];

queue<pair<int,int> >q;

int dr[] = {-1, 1, 0, 0};
int dc[] = {0,0,-1,1};
bool isvalid(int x,int y)
{
	if(x<1 || x>n || y<1 || y>m || vis[x][y]) return false;
	return true;
}


void bfs()
{
	while(!q.empty())
	{
		int x = q.front().ff;
		int y = q.front().ss;
		q.pop();
		for(int i=0;i<4;i++)
		{
			int nx = x + dr[i];
			int ny = y + dc[i];
			if(isvalid(nx,ny))
			{
				d[nx][ny] = d[x][y] + 1;
				vis[nx][ny] = 1;
				q.push(mp(nx,ny));
			}
		}
	}
}


int main()
{
	cin >> n >> m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin >> a[i][j];
			if(a[i][j]=='#')
			{
				d[i][j] = 0;
				vis[i][j] = 1;
				q.push(mp(i,j));
			}
		}
	}

	bfs();
	int ans = 0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			ans = max(ans,d[i][j]);

	cout << ans;
}

Measured memory_bytes: 14352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;int a[105];
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		if(a[0]==a[n-1])
		{
			cout<<0<<endl;
		}
		else
		{
			int sum,ans=1111111;
			for(int i=a[0];i<=a[n-1];i++)
			{
				sum=0;
				for(int j=0;j<n;j++)
					sum+=(i-a[j])*(i-a[j]);
				ans=min(sum,ans);
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n-1)]
graph = [[] for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
  graph[b].append(a)
ans = n
rad = k//2
for center in range(1,n+1):
  stack = [center]
  dep = [[-1,-1] for _ in range(n+1)]
  dep[center] = [0,0]
  while stack:
    x = stack.pop()
    for i,y in enumerate(graph[x]):
      if x == center:
        dep[y] = [1,i+1]
        stack.append(y)
      else:
        if dep[y][0] == -1:
          stack.append(y)
          dep[y][0] = dep[x][0]+1
          dep[y][1] = dep[x][1]
  anstmp = 0
  bonus = [0]*(len(graph[center])+1)
  for i in range(1,n+1):
    if dep[i][0] <= rad:
      anstmp += 1
    if dep[i][0] == rad+1:
      bonus[dep[i][1]] += 1
  if k%2:
    anstmp += max(bonus)
  ans = min(n-anstmp,ans)
print(max(ans,0))

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

int main(){
    int N, M=0, tmp=0;
    cin >> N;
    vector<int> a(2*N), b(2*N);
	
    for(int i=1; i<=N; i++){
	cin >> a[i];
    }


    for(int i=N; i>0; i--){
	tmp = a[i];
	for(int j=2*i; j<=N; j+=i){
	    tmp ^= b[j];
	}
	b[i] = tmp;
	if(b[i] == 1)
	    M++;
    }
    
    cout << M << endl;
    for(int i=1; i<=N; i++){
	if(b[i] == 1)
	    cout << i << " ";	
    }

}




Measured memory_bytes: 3968
#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; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/
int main()
{
    int N, M;
    cin >> N >> M;
    map<int, string> mp;
    int ac = 0, wa = 0;
    vector<int> was(N, 0);
    REP(i, M) {
        int a;
        string b;
        cin >> a >> b;
        if(a > N) {
            continue;
        }
        if(b == "AC" && mp[a] == "AC") {
            // continue;
        } else if(b == "WA" && mp[a] == "AC") {
            // continue;
        } else if(b == "WA") {
            mp[a] = b;
            was.at(a-1)++;
            // wa++;
        } else if(b == "AC") {
            mp[a] = b;
            ac++;
            wa += was.at(a-1)++;
        }
        // cout << ac << " " << wa << endl;
    }
    
    cout << ac << " " << wa << endl;
    return 0;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n;
int k;
int dp[110][110000];
vector<int> a;
int main() {
    cin >> n >> k;
    a.resize(n+1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 0; i <= a[0]; i++) dp[0][i] = 1;
    for (int i = 1; i <= n; i++) {
        int sum = 0;
        for (int j = 0; j <= k; j++) {
            sum += dp[i-1][j];
            if (j > a[i]) sum -= dp[i-1][j - a[i] - 1];
            sum %= MOD;
            if (sum < 0) sum += MOD;
            // cout << sum << endl;
            dp[i][j] = sum;
        }
        // int cnt = -1;
        // do{
        //     cnt++;
        //     // printf("%d\n", cnt);
        //     for (int j = 0; j <= a[i] && j <= k; j++) {
        //         if (cnt + j < 110000) {
        //             dp[i+1][cnt + j] += dp[i][j];
        //             dp[i+1][cnt + j] %= MOD;
        //         }
        //     }
        // } while (cnt <= k && dp[i][cnt] != 0);
    }
    cout << dp[n][k] << endl;
    return 0;
}

Measured memory_bytes: 43064
import sys
input = sys.stdin.buffer.readline

def main():
    H,N = map(int,input().split())
    x = []
    ma = 0
    for _ in range(N):
        a,b = map(int,input().split())
        ma = max(ma,a)
        x.append((a,b))
    INF = 10**18
    
    dp = [INF for _ in range(H+ma+1)]
    dp[0] = 0
    for i in range(1,H+ma+1):
        dp[i] = min(dp[i-a]+b for a,b in x)
    
    print(min(dp[H:]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/

ll res(ll a,ll b,ll x){
  ll r1=a*x/b;
  ll r2=x/b;
  return r1-a*r2;
}

int main()
{
  ll a,b,n;cin>>a>>b>>n;
  ll ans;
  if(b==1){
    ans=res(a,b,n);
  }else if(n>=b-1){
    ans=res(a,b,b-1);
  }else{
    ans=res(a,b,n);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>

int main(void)
{
	int i,j,m;
	int data[10];
	for(i=1;i<=5;i++){
		scanf("%d",&data[i-1]);
	}
	j=data[1]/data[3];
	if(data[1]%data[3]!=0){
		j++;
	}
	m=data[2]/data[4];
	if(data[2]%data[4]!=0){
		m++;
	}
	if(j>=m){
		printf("%d\n",data[0]-j);
	}else{
		printf("%d\n",data[0]-m);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i,N) cin >> p[i];
    vector<int> t(N+K-1);
    int pos = 1;
    int cnt = 0;
    for(int i=0; i<N-K+1; i++){
        while(pos < i+K){
            if(p[pos-1] > p[pos]) cnt++;
            pos++;
        }
        t[i] = cnt;
        if(p[i] > p[i+1]) cnt--;
    }
    pos = 0;
    set<int> se;
    vector<bool> so(N+K+1,true);
    for(int i=0; i<N-K; i++){
        while(pos < i+K+1){
            se.insert(p[pos]);
            pos++;
        }
        if(*se.begin()==p[i] and *se.rbegin()==p[pos-1]) so[i] = false;
        se.erase(p[i]);
    }
    int ans = 0;
    bool all = false;
    for(int i=0; i<N-K+1; i++){
        if(so[i]){
            if(t[i]) ans++;
            else all = true;
        }
    }
    ans += all;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 11904
#include<stdio.h>
main()
{
        int i, j, k, n, count[4][13] = {0};
        char l;
        scanf("%d", &n);
        for(i = 0; i < n; i++){
                scanf("%*c%c %d", &l, &k);
                switch(l){
                case 'S':
                        count[0][k - 1] = 1;
                        break;
                case 'H':
            count[1][k - 1] = 1;
                        break;
                case 'C':
            count[2][k - 1] = 1;
            break;
                case 'D':
            count[3][k - 1] = 1;
            break;
                }
        }
        for(j = 0; j < 4; j++){
                switch(j){
                case 0:
                        l = 'S';
                        break;
                case 1:
                        l = 'H';
                        break;
                case 2:
                        l = 'C';
                        break;
                case 3:
                        l = 'D';
                        break;
                }
                for(i = 0; i < 13; i++){
                        if(!count[j][i]){
                                printf("%c %d\n", l, i + 1);
                        }
                }
        }
}

Measured memory_bytes: 1796
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <queue>
#include <stack>
#include <tuple>

using namespace std;


typedef long long ll;
const int MAX_V = 210;
const int INT_INF = 1<<30;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
struct edge {
	int cap, cost;
};
int V;

edge G[MAX_V][MAX_V];
int h[MAX_V], dist[MAX_V];
int prevv[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap, int cost) {
	G[from][to] = (edge){1, cost};
	G[to][from] = (edge){0, -cost};
}

int bit_matching_cost(int s, int t, int &f) {
	f = 0;
	int res = 0;
	fill_n(h, V, 0);
	while (true) {
		fill_n(dist, V, INT_INF);
		dist[s] = 0;

        fill_n(used, V, false);
        while (true) {
            int v = -1;
            for (int i = 0; i < V; i++) {
                if (!used[i] && (v == -1 || dist[i] < dist[v])){
                    v = i;
                }
            }
            if (v == -1) break;
            used[v] = true;

			for (int i = 0; i < V; i++) {
				edge &e = G[v][i];
				if (e.cap > 0 && dist[i] > dist[v] + e.cost + h[v] - h[i]) {
					dist[i] = dist[v] + e.cost + h[v] - h[i];
					prevv[i] = v;
				}
			}
        }
		if (dist[t] == INT_INF) {
			return res;
		}
		for (int v = 0; v < V; v++) {
			h[v] += dist[v];
		}
		f++;
		res += h[t];
		for (int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][v];
			e.cap -= 1;
			G[v][prevv[v]].cap += 1;
		}
	}
	return res;
}
int cost[MAX_V][MAX_V];


const int MAX_N = 105;
int N;
int W[MAX_N][MAX_N], E[MAX_N][MAX_N];
bool F[MAX_N][MAX_N], F2[MAX_N][MAX_N];

int main(int argc, char *argv[]) {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			scanf("%d", &(W[i][j]));
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			scanf("%d", &(E[i][j]));
		}
	}
	int min_f = 0, f = 0;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < N; j++) {
			F[i][j] = (s[j] == 'o');
			if (F[i][j]) {
				min_f = min(min_f, -E[i][j]);
				f += E[i][j];
			}
		}
	}
	min_f *= -1;
	V = (N+1)*2;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (F[i][j]) {
				add_edge(i, N+j, 1, -E[i][j]+min_f);
			} else {
				add_edge(i, N+j, 1, W[i][j]+min_f);
			}
		}
	}
	for (int i = 0; i < N; i++) {
		add_edge(N*2, i, 1, 0);
	}
	for (int i = 0; i < N; i++) {
		add_edge(N+i, N*2+1, 1, 0);
	}
	int f1 = 0;
	f += bit_matching_cost(N*2, N*2+1, f1);
	f -= min_f*N;
	int c = 0;
	vector<T> q;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (F[i][j] == G[i][N+j].cap) {
				c++;
				q.push_back(T(i, j, F[i][j]));
			}
		}
	}
	printf("%d\n%d\n", f, c);
	for (T t: q) {
		printf("%d %d %s\n", get<0>(t)+1, get<1>(t)+1, get<2>(t) ? "erase" : "write");
	} 
    return 0;
}

Measured memory_bytes: 1764
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      long X = sc.nextLong();
      long K = sc.nextLong();
      long D = sc.nextLong();
      
      // 算出
      long absX = Math.abs(X);
      long div = absX / D;
      long min1 = absX % D;
      long min2 = Math.abs(min1 - D);
      
      long result = 0L;
      if(K < div){
        result = absX - D * K;
      }else{
        if(div % 2 == 1){
          if(K % 2 == 1){
            result = min1;
          }else{
            result = min2;
          }
        }else{
          if(K % 2 == 0){
            result = min1;
          }else{
            result = min2;
          }
        }
      }
      
      // 出力
      System.out.println(result);
    }

}

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

int main(){
  ll Q,H,S,D,N;
  cin >> Q >> H >> S >> D >> N;
  Q *= 4;
  H *= 2;
  ll t = min(Q,min(H,S));
  if(N==1){
    cout << t*N << endl;
  }else{
    if(N%2){
      cout << min(t*N,D*(N/2)+t) << endl;
    }else{
      cout << min(t*N,D*N/2) << endl;
    }
  }
}


Measured memory_bytes: 256