akhauriyash/Code-Regression huggingface dataset:
using System;

namespace _0576
{
    class Program
    {
        static void Main(string[] args)
        {
            int days = int.Parse(Console.ReadLine());
            int kokugopage = int.Parse(Console.ReadLine());
            int sansupage = int.Parse(Console.ReadLine());
            int kokugo = int.Parse(Console.ReadLine());
            int sansu = int.Parse(Console.ReadLine());
            int kokugoday = kokugopage / kokugo + 1;
            if(kokugopage % kokugo==0)
            {
                kokugoday--;
            }
            int sansuday = sansupage / sansu + 1;
            if (sansupage % sansu == 0)
            {
                sansuday--;
            }
            if (kokugoday>=sansuday)
            {
                Console.WriteLine(days - kokugoday);
            }
            else if (kokugoday < sansuday)
            {
                Console.WriteLine(days - sansuday);
            }
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else 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,a,b;
    cin>>n>>a>>b;
    for(ll i=a;i<=b;i++){
        if(i%n==0){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <unordered_map>
#include <cmath>

int main() {
	int a; 
	std::string s;
	std::cin >> a >> s;

	if (a < 3200)
	{
		std::cout << "red" << "\n";
	} else {
		std::cout << s << "\n";
	}
}

Measured memory_bytes: 256
def calc_gcd(a, b):
    if a < b:
        (a, b) = (b, a)
    if b == 0:
        return a
    return calc_gcd(b, a%b)
    
x, y = map(int, input().split())
assert 1 <= x and x <= 10000000000, "xは範囲外です"
assert 1 <= y and y <= 10000000000, "yは範囲外です"
if x == y:
    print(x)
elif x == 0 or y == 0:
    print(0)
else:
    if x < y:
        (x, y) = (y, x)
    d = calc_gcd(x, y)
    print(d)


Measured memory_bytes: 5600
import java.util.Scanner;

public class Main{
	static public void  main(String[] args){
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();

		boolean yes;
		if (n % 2 == 0){
			yes = (n /  2 >= k );
		}else{
			yes = (n /  2 + 1 >= k );

		}
		if(yes){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}
}


Measured memory_bytes: 21716
S = input()

c = 0
cum = [c]
for s in S:
    if s == "1":
        c += 1
    else:
        c -= 1
    cum.append(c)
max_cum = [None] * (len(S) + 1)
max_cum[-1] = cum[-1]
for i in reversed(range(len(S))):
    max_cum[i] = max(cum[i], max_cum[i + 1])
z = max_cum[0]


def f(m):
    c = 0
    fz = c
    add = 0
    for i, s in enumerate(S):
        if s == "1":
            c += 1
        elif s == "0":
            c -= 1
            fz = min(fz, c)
        elif add + max_cum[i + 1] + 2 <= m:
            c += 1
            add += 2
        else:
            c -= 1
            fz = min(fz, c)
    return fz


fz = f(z)
fz1 = f(z + 1)

ans = min(z - fz, z + 1 - fz1)
print(ans)

Measured memory_bytes: 58720
#include <iostream>
using namespace std;
int V,E,s,t,d,A[100][100]={};
int INF=2000000000;
void WarshallFloyd(){
    for(int k=0;k<V;k++){
        for(int i=0;i<V;i++){
            if(A[i][k] == INF)continue;
            for(int j=0;j<V;j++){
            if(A[k][j] == INF)continue;
                A[i][j]=min(A[i][j],A[i][k]+A[k][j]);
            }
        }
    }
}
int main(){

    cin>>V>>E;
    for(int i=0;i<V;i++){
        for(int j=0;j<V;j++){
            if(i==j){
                A[i][j]=0;
            }
            else{
                A[i][j]=INF;
            }
        }
    }
    for(int i=0;i<E;i++){
        for(int j=0;j<V;j++){
            cin>>s>>t>>d;
            A[s][t]=d;
            //A[t][s]=d;
        }
    }
    WarshallFloyd();
    for(int i=0;i<V;i++){
        if(A[i][i]<0){
            cout<<"NEGATIVE CYCLE"<<endl;
            return 0;
        }
    }
    for(int i=0;i<V;i++){
        for(int j=0;j<V;j++){
            if(j==V-1){
                if(A[i][j]==INF){
                   cout<<"INF";
                }
                else{
                    cout<<A[i][j];
                }
           }
           else{
               if(A[i][j]==INF){
                  cout<<"INF"<<" ";
                }
                else{
                   cout<<A[i][j]<<" ";
                }
            }
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3160
#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,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

void fill(int x, vector<int> &dp) {
    if(dp[x]) {
        return;
    }
    for(int i = 1;i*x <= 1e6;i++) {
        dp[i*x] = true;
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> v;
    v.reserve(N);
    map<int, int> dic;
    vector<int> dp(1e6 + 1, false);

    REP(i, N) {
        int x;
        cin >> x;
        dic[x]++;
    }
    for(auto i : dic) {
        if(1 == i.second) {
            v.push_back(i.first);
        }else{
            fill(i.first, dp);
        }
    }
    sort(ALL(v));
    int res = 0;
    for(auto i : v) {
        if(!dp[i]) {
            res++;
        }
        fill(i, dp);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 17252
# include <cstdio>
# include <iostream>
# include <vector>
# include <map>
# include <set> 
# include <algorithm> 
# include <string>
# include <cstring>
# include <queue> 
# include <stack> 
# include <cstdlib> 
# include <cassert> 

using namespace std ; 

// #define maxN 1000001 
// #define VI vector<int> 
// #define pb push_back 
// #define UnsignedSize (sizeof(unsigned)*8)

// unsigned pflag[maxN/UnsignedSize+1] ; 

// VI primes ; 

// void setBit(unsigned *pflag, int pos)
// {
//     int bytePos = pos / UnsignedSize ; 
//     int bitPos = pos % UnsignedSize ; 
//     pflag[bytePos] = pflag[bytePos] | (1<<bitPos) ; 
// }


// bool isBitSet(unsigned *pflag, int pos)
// {
//     int bytePos = pos / UnsignedSize ; 
//     int bitPos = pos % UnsignedSize ; 
//     return (pflag[bytePos] & (1<<bitPos)) ; 
// }

// void sieve(){
//     //memset(pflag,0,sizeof(pflag)) ; 
//     setBit(pflag, 0) ; 
//     setBit(pflag, 1) ;
//     primes.pb(2) ; 
//     for(int i = 4 ; i < maxN; i+=2) 
//         setBit(pflag, i) ; 
//     for(int i = 3 ; i*i < maxN; i+=2)
//     {
//         if(isBitSet(pflag, i)) continue ; 
//         //primes.pb(i) ; 
//         for(int j=i*i; j  < maxN; j +=(2*i) )
//             setBit(pflag, j) ; 
//     } 
//     for(int i = 3 ; i < maxN; i+=2){
//         if(isBitSet(pflag, i)) continue; 
//         primes.pb(i) ; 
//     }
//     // int sz = primes.size();
//     // for(int i = 0 ; i < sz; ++i)
//     //     cout << primes[i] << "\n" ; 
// }

int binsearch(int toFind, int L, int sz, vector<int>& data)
{
	int low = L , high = sz -1;
	int mid ; 
	while(low<=high)
	{
		mid = (low+high)/2; 
		if(data[mid]==toFind)
			return mid ; 
		else if(data[mid]< toFind)
			low = mid + 1 ; 
		else 
			high = mid - 1 ; 
	}
	return -1; 
}

int main()
{
	// sieve() ; 
	int N ; 
	cin >> N ; 
	
	// multiset< int >  S ;  
	// set< int 
	set<int> S; 
	map<int, int > F ; 
	int oneCount = 0 ; 
	int sub = 0 ; 
	for(int i = 0 ; i < N ; ++i){
		int x ; 
		cin >> x;
		if(x==1) ++oneCount ; 
		S.insert(x); 
		F[x]++; 
		if(F[x]==2)--sub; 
	} 
	// sort(A.begin(), A.end()) ; 
	if(oneCount==1){
		cout << "1\n";
		return 0 ; 
	}
	if(oneCount > 1){
		cout << "0\n";
		return 0 ; 
	}
	if(N==1)
	{
		cout << "1\n";
		return 0 ;  
	}

	int newN = S.size(); 
	if(N > 1 && newN==1)
	{
		cout << "0\n";
		return 0 ; 
	}

	N = newN ; 
	vector< int > A(newN+1); 
	vector< bool > visited(newN+1,false);

	set<int>::iterator it = S.begin(); 
	
	for(int i = 0; it != S.end(); ++it, ++i)
	{
		A[i] = *(it); 
	}

	int maxVal = A[newN-1] ; 
	int answer = newN ; 
	for(int i = 0 ; i < newN-1 ; ++i)
	{
		if(visited[i]) continue ;
		int t = A[ i ] ; 
		
		for(int j = t ; j <= maxVal; j+=t)
		{
			int pos = binsearch(j, i+1, newN, A) ; 
			if(pos==-1)continue; 
			if(!visited[pos])
			{
				if(F[j] < 2 )--answer; 
				visited[pos]=true; 
				continue; 
			}
		}
	}
	//assert(answer + sub >= 0 ) ; 
	if(answer+sub <0 )cout << "0\n" ; 
	else cout << answer + sub << "\n" ; 
	return 0 ; 
}

Measured memory_bytes: 22140
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    int ans = 0;
    rep(i, n) Rep(j, i + 1, n) ans += d[i] * d[j];
    cout << ans << endl;
}

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

int check_a(char *snake)
{
    int n;
    
    if (snake[strlen(snake) - 1] != '~'){
        return (0);
    }
    snake[strlen(snake) - 1] = '\0';

    if (*snake != '='){
        return (0);
    }
    
    n = 0;
    while (*snake != '#'){
        if (*snake != '='){
            return (0);
        }
        n++;
        snake++;
    }
    snake++;
    while (n > 0){
        if (*snake != '='){
            return (0);
        }
        n--;
        snake++;
    }
    if (*snake != '\0'){
        return (0);
    }
    return (1);
}

int check_b(char *snake)
{
    int n;
    
    if (snake[strlen(snake) - 1] != '~' || 
        snake[strlen(snake) - 2] != '~'){
        return (0);
    }
    snake[strlen(snake) - 2] = '\0';

    if (*snake != 'Q'){
        return (0);
    }
    
    while (*snake != '\0'){
        if (*snake != 'Q'){
            return (0);
        }
        snake++;
        if (*snake != '='){
            return (0);
        }
        snake++;
    }
    return (1);
}

int main(void)
{
    int n;
    char snake[1000];
    int i;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%s", snake);
        if (snake[0] == '>'){
            if (snake[1] == '\''){
                if (check_a(&snake[2]) == 1){
                    printf("A\n");
                    continue;
                }
            }
            else if (snake[1] == '^'){
                if (check_b(&snake[2]) == 1){
                    printf("B\n");
                    continue;
                }
            }
        }
        printf("NA\n");
    }
    return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int main(){
	int N,D;
	cin >> N >> D;
	cout << (N-1)/(2*D+1)+1 << endl;
	return 0;
}



Measured memory_bytes: 384
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final Map<Integer, AtomicInteger> countMap = new HashMap<>();
        for (int i = 0; i < n; i++) {
            countMap.computeIfAbsent(scanner.nextInt(), count -> new AtomicInteger())
                    .incrementAndGet();
        }

        int answer = 0;
        for (final Map.Entry<Integer, AtomicInteger> map : countMap.entrySet()) {
            if (map.getValue().get() >= map.getKey()) {
                answer += map.getValue().get() - map.getKey();
            } else {
                answer += map.getValue().get();
            }
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 63812
//dhruv
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define ll long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define fro(i,j,n) for(int i = (j);i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second
const int mod = 1e9 + 7;
const int inf = 1e18 + 5;
 
template<typename T>
T binpow(T a,T b,T modi){
	T res = 1;
	while(b){
		if(b&1){
			res = (res*a)%modi;
		}
		b /= 2;
		(a *= a) %= modi;
	}
	return res;
}
 
 
template<typename T>
T binpow(T a,T b){
	T res = 1;
	while(b){
		if(b&1){
			res = (res*a);
		}
		b /= 2;
		a *= a;
	}
	return res;
}
 
template<typename T>
T add(T a,T b){
	return (a + b)%mod;
}
template<typename T>
T sub(T a,T b){
	return add(a,mod - b);
}
template<typename T>
T mul(T a,T b){
	return (a*b)%mod;
}
template<typename T>
T inv(T a){
	return binpow(a,mod - 2,mod);
}

int make_int(string s){
	int x = 0;
	reverse(s.begin(),s.end());
	string tmp = s;
	for(int i = 0;i < s.length(); ++i){
		x *= 10;
		x += (int)(tmp.back() - '0');
		tmp.pop_back();
	}
	return x;
}
 
string make_string(int s){
	string x;
	while(s){
		x.push_back(char(s%10 + '0'));
		s /= 10;
	}
	reverse(x.begin(),x.end());
	return x;
}

random_device rd;
mt19937 g(rd());

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

const int N = 100;

vi fact;

void factorial(){
	fact.resize(N);
	fact[0] = 1,fact[1] = 1;
	fro(i,2,N){
		fact[i] = (fact[i - 1]*i)%mod;
	}
}

int nCr(int n,int r){
	return (mul(fact[n],inv(mul(fact[r],fact[n - r]))));
}

int nPr(int n,int r){
	return(mul(nCr(n,r),fact[r]));
}

// Linear Seive


int lp[N + 1];
vector<int> pr;
void ls(){
	for(int i = 2;i <= N; ++i){
		// means prime
		if(lp[i] == 0){
			lp[i] = i;
			pr.push_back(i);
		}
		for(int j = 0;j < pr.size() && pr[j] <= lp[i] && i*pr[j] <= N; j++){
			lp[i*pr[j]] = pr[j];
		}
	}
}


// getting the prime factorisation

vector<int> getfc(int n){
	vi factors;
	while(n != 1){
		int x = lp[n];
		factors.push_back(x);
		while(n%x == 0){
			n /= x;
		}
	}
	return factors;
}

int gcd(int a,int b){
	while(b){
		a %= b;
		swap(a,b);
	}	
	return a;
}

int h,w,k;

bool ok(int x,int y){
	bool res = (x >= 0 and x < h and y >= 0 and y < w);
	return res;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	// shuffle(all(a),g);
	cin >> h >> w >> k;
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	--x1,--x2,--y1,--y2;
	vector<vector<char>> a(h,vector<char>(w));	
	ffor(i,h){
		ffor(j,w){
			cin >> a[i][j];
		}
	}
	vvi dist(h,vi(w,inf));
	queue<pii> q;
	if(a[x1][y1] != '@'){
		dist[x1][y1] = 0;
		q.push({x1,y1});
	}

	while(!q.empty()){
		auto tp = q.front();
		q.pop();
		int xxx = tp.first;
		int yyy = tp.second;
		for(int i = 0;i < 4; ++i){
			for(int z = 1;z <= k; ++z){
				int xx = xxx + dx[i]*z;
				int yy = yyy + dy[i]*z;
				if(!ok(xx,yy) or a[xx][yy] == '@' or dist[xx][yy] <= dist[xxx][yyy]) break;
				if(dist[xx][yy] > dist[xxx][yyy] + 1){
					dist[xx][yy] = dist[xxx][yyy] + 1;
					q.push({xx,yy});
				}
			}
		}
	}

	dist[x2][y2] == inf ? cout << -1 : cout << dist[x2][y2];
	return 0;
}	

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


int main(){
  int D,N;
  cin >> D >> N;
  if(N == 100){
  if(D == 0){ cout << ( N + 1 ) << endl; }
  if(D == 1){ cout << ( N + 1 )* 100 << endl; }
  if(D == 2){ cout << ( N + 1 )* 10000 << endl; }
  }else{
    if(D == 0){ cout << N << endl; }
  if(D == 1){ cout << N * 100 << endl; }
  if(D == 2){ cout <<  N * 10000 << endl; }

  }
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> c(N-1);
  vector<int> s(N-1);
  vector<int> f(N-1);

  rep(i,N-1){
    cin >> c[i] >> s[i] >> f[i];
  }

  rep(k,N-1){ // k = 出発駅
    int currentTime = 0;
    FOR(i,k,N-1){
      if(currentTime <= s[i]){
        currentTime = s[i] + c[i];
        //cout << currentTime << " " << s[i] << ' ' << c[i] << endl;
      }else{
        //cout << "else" << endl;
        //cout << f[i] - currentTime % f[i] << endl;
        if(currentTime % f[i] != 0) currentTime += f[i] - currentTime % f[i];
        currentTime += c[i];

      }
      //cout <<"k = " << k << ';'<<currentTime << endl;
    }
    cout << currentTime << endl;
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
a = sorted(list(map(int, input().split())))
c = 0
while a[1] != a[2]:
    c += 1
    a[0] += 1
    a[1] += 1
if a[0] == a[1]:
    pass
elif (a[1] - a[0]) & 1:
    c += 2 + (a[1] - a[0]) // 2
else:
    c += (a[1] - a[0]) // 2
print(c)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]

class Util():
    def round_up(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

N = cin.int()
A = cin.mapInt()
print(sum(A) - N)

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

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, m, x;
    cin >> n >> m >> x;
    vll c(n);
    vvll arr(n, vll(m));
    for (ll i = 0; i < n; i++)
    {
        cin >> c[i];
        for (ll j = 0; j < m; j++)
        {
            cin >> arr[i][j];
        }
    }
    ll i, cost = LLONG_MAX;
    for (i = 0; i < (1 << n); i++)
    {
        vector<ll> tt(m, 0);
        ll temp = 0;
        for (ll j = 0; j < n; j++)
        {
            if (i & (1 << j))
            {
                temp += c[j];
                for (ll k = 0; k < m; k++)
                {
                    tt[k] += arr[j][k];
                }
            }
        }
        for (ll i = 0; i < m; i++)
        {
            if (tt[i] < x)
            {
                temp = LLONG_MAX;
            }
        }
        cost = min(cost, temp);
    }
    cout << ((cost > 1e7)?(-1):(cost)) << endl;
    return 0;
}

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

#define MAX_N 100
#define MAX_W 10000

int main(){
    int N, W;
    cin >> N >> W;

    int v[1001], w[1001];
    for(int i=0;i<N;i++)
        cin >> v[i] >> w[i];

    int dp[MAX_N+1][MAX_W+1];   //dp[i][j] : 品物i個重さjの時の価値

    for(int i=1;i<=N;i++){      //扱う品物の数を増やしていく
        for(int j=0;j<=W;j++){      //重さの総和を増やしていく
            if(j < w[i-1])              //i-1番目の品物の重さがj未満
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1]);
        }
    }
    
    cout << dp[N][W] << endl;

    return 0;
}


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

using namespace std;

#define INF 1e9
typedef long long ll;

struct P{
  int x,y;
  P(int x,int y) : x(x),y(y) {}
};

ll getValue(vector<int> &v){
  ll res = 0LL;
  for(auto x : v){
    res *= 10LL;
    res += x;
  }
  return res;
}

vector<int> getState(ll x){
  vector<int> res;
  while(x > 0LL){
    res.push_back(x%10LL);
    x /= 10LL;
  }
  if(res.size() == 8){ res.push_back(0); }
  reverse(res.begin(),res.end());
  return res;
}

P getPos(int x){
  x--;
  return P(x%3,x/3);
}

int getMD(ll x){
  vector<int> v = getState(x);
  int res = 0;
  for(int i = 0 ; i < 9 ; i++){
    if(v[i] == 0){ continue; }
    P tp = getPos(v[i]);
    res += abs(i%3-tp.x) + abs(i/3-tp.y);
  }
  return res;
}

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

bool inField(int x,int y){
  return (0 <= x && x < 3 && 0 <= y && y < 3);
}

bool solve(int sp,ll st,int step,int prev){
  int md = getMD(st);
  if(md == 0){ return true; }
  if(md + step > LIMIT){
    return false;
  }
  int x = sp%3,y = sp/3;
  for(int i = 0 ; i < 4 ; i++){
    int nx = x + dx[i],ny = y + dy[i];
    if(abs(i-prev) == 2){ continue; }
    if(!inField(nx,ny)){ continue; }
    vector<int> v = getState(st);
    int nsp = ny*3 + nx;
    swap(v[sp],v[nsp]);
    if(solve(nsp,getValue(v),step+1,i)){
      return true;
    }
  }
  return false;
}

int main(){
  int sp = -1;
  vector<int> v(9);
  for(int i = 0 ; i < 9 ; i++){
    cin >> v[i];
    if(v[i] == 0){ sp = i; }
  }
  ll st = getValue(v);
  for(LIMIT = 0 ; LIMIT < 35 ; LIMIT++){
    if(solve(sp,st,0,INF)){
      cout << LIMIT << endl;
      break;
    }
  }
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; string s; cin >> N >> s;
	int cur = 0;
	for (char c : s) cur += (c == 'E');
	int ans = cur;
	for (char c : s) {
		if (c == 'E') {
			cur--;
		} else {
			cur++;
		}
		ans = min(ans, cur);
	}
	cout << ans << '\n';

	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long D)
{
    while (A > 0 && C > 0)
    {
        C = max(C - B, 0LL);
        if (C == 0LL)
        {
            cout << YES << endl;
            return;
        }
        A = max(A - D, 0LL);
        if (A == 0LL)
        {
            cout << NO << endl;
            return;
        }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    long long D;
    scanf("%lld", &D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 3684
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		PriorityQueue<Query> begins = new PriorityQueue<Query>(new Comparator<Query>() {
		    public int compare(Query q1, Query q2) {
		        return q1.begin - q2.begin;
		    }
		});
		PriorityQueue<Query> ends = new PriorityQueue<Query>(new Comparator<Query>() {
		    public int compare(Query q1, Query q2) {
		        return q1.end - q2.end;
		    }
		});
		int m = sc.nextInt();
		Query[] queries = new Query[m];
		for (int i = 0; i < m; i++) {
		    queries[i] = new Query(sc.nextInt(), sc.nextInt(), sc.nextInt());
		    begins.add(queries[i]);
		    ends.add(queries[i]);
		}
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i <= n; i++) {
		    while (begins.size() > 0 && begins.peek().begin == i) {
		        Query q = begins.poll();
		        if (map.containsKey(q.value)) {
		            q.left = map.get(q.value);
		        }
		    }
		    while (ends.size() > 0 && ends.peek().end == i) {
		        Query q = ends.poll();
		        if (map.containsKey(q.value)) {
		            q.right = map.get(q.value);
		        }
		    }
		    if (i == n) {
		        break;
		    }
		    if (map.containsKey(arr[i])) {
		        map.put(arr[i], map.get(arr[i]) + 1);
		    } else {
		        map.put(arr[i], 1);
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (Query q : queries) {
		    sb.append(q).append("\n");
		}
		System.out.print(sb);
	}
	
	static class Query {
	    int begin;
	    int end;
	    int value;
	    int left;
	    int right;
	    
	    public Query(int begin, int end, int value) {
	        this.begin = begin;
	        this.end = end;
	        this.value = value;
	    }
	    
	    public String toString() {
	        return String.valueOf(right - left);
	    }
	}
}



Measured memory_bytes: 35752
#include<string>
#include<iostream>
using namespace std;
int main()
{
	string s;
	int i, cnt;
	cin >> s;
	cnt = 0;
	for (i = 0; i < s.length(); i++) {
		if (s[i] == 'x') {
			cnt++;
		}
	}
	if (cnt >= 8) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll dpr[202020][16], dpl[202020][16], A[202020];
int N;



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

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

	for (int j = 0; j <= 15; j++)dpr[N - 1][j] = 2 * j;
	for (int i = N - 2; i >= 0; i--) {
		ll p1 = 1;
		for (int j = 0; j <= 15; j++) {
			ll p2 = 1; int cnt = 0;
			while (p1*A[i] > p2*A[i + 1]) { p2 *= 4LL; cnt++; }
			if (cnt >= 15)dpr[i][j] = dpr[i + 1][15] + 2 * j + 2LL*((ll)(cnt - 15))*((ll)(N - i - 1));
			else dpr[i][j] = dpr[i + 1][cnt] + 2 * j;
			p1 *= 4LL;
		}
	}


	for (int i = 0; i < N; i++)A[i] *= -2LL;
	for (int j = 0; j <= 15; j++)dpl[0][j] = 2 * j + 1;
	for (int i = 1; i < N; i++) {
		ll p1 = 1;
		for (int j = 0; j <= 15; j++) {
			ll p2 = 1; int cnt = 0;
			while (p2*A[i - 1] > p1*A[i]) { p2 *= 4LL; cnt++; }
			if (cnt >= 15)dpl[i][j] = dpl[i - 1][15] + 2 * j + 2LL*((ll)(cnt - 15))*((ll)i);
			else dpl[i][j] = dpl[i - 1][cnt] + 2 * j;
			dpl[i][j]++;
			p1 *= 4LL;
		}
	}

	ll ans = dpr[0][0];
	for (int i = 0; i < N; i++) {
		ans = min(ans, dpr[i + 1][0] + dpl[i][0]);
	}
	puts(ans);
	return 0;
}

Measured memory_bytes: 52096
#ifdef _WIN32
#define DEBUG	1
#endif

#define _CRT_SECURE_NO_WARNINGS
#define MATH_PI 3.14159265358979323846264338327950288419716939
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;

#ifdef DEBUG
#include "include.h"
#else
inline void wait(){}
inline void dout(const char *arg, ...){}
#endif

template<typename T>inline void swap(T a, T b){T t = a; a = b; b = t;}

#define CLIP(ptr, min, max) {if((min)<=(max)){if(ptr<(min)){ptr=(min);}if(ptr>(max)){ptr=(max);}}}
#define max(a, b) a > b ? a : b;
#define min(a, b) a > b ? b : a;
#define Sin(deg) sin((deg)*MATH_PI/180)
#define Cos(deg) cos((deg)*MATH_PI/180)
#define Tan(deg) tan((deg)*MATH_PI/180)
#define Rad(deg) ((deg)*MATH_PI/180)
#define ff(param, num) for(int param=0 ; param<num ; ++param)
#define fi(num) for(int i=0 ; i<num ; ++i)
#define fj(num) for(int j=0 ; j<num ; ++j)
#define fk(num) for(int k=0 ; k<num ; ++k)
#define fl(num) for(int l=0 ; l<num ; ++l)
#define ffr(param, num) for(int param=num-1 ; param>=0 ; --param)
#define fir(num) for(int i=num-1 ; i>=0 ; --i)
#define fjr(num) for(int j=num-1 ; j>=0 ; --j)
#define fkr(num) for(int k=num-1 ; k>=0 ; --k)
#define flr(num) for(int l=num-1 ; l>=0 ; --l)
#define gi(p) Scanf("%d", p)
#define gi2(p1, p2) Scanf2("%d %d", p1, p2)
#define gi3(p1, p2, p3) Scanf3("%d %d %d", p1, p2, p3)
#define gi4(p1, p2, p3, p4) Scanf4("%d %d %d %d", p1, p2, p3, p4)
#define gll(p) Scanf("%lld", p)
#define gll2(p1, p2) Scanf2("%lld %lld", p1, p2)
#define gll3(p1, p2, p3) Scanf3("%lld %lld %lld", p1, p2, p3)
#define gll4(p1, p2, p3, p4) Scanf4("%lld %lld %lld %lld", p1, p2, p3, p4)
#define gf(p) Scanf("%f", p)
#define gf2(p1, p2) Scanf2("%f %f", p1, p2)
#define gf3(p1, p2, p3) Scanf3("%f %f %f", p1, p2, p3)
#define gf4(p1, p2, p3, p4) Scanf4("%f %f %f %f", p1, p2, p3, p4)
#ifdef DEBUG
#define gc(buf) fscanf(local_in.fp, "%s", buf)
#define Scanf(expr, p) fscanf(local_in.fp, expr, &p)
#define Scanf2(expr, p1, p2) fscanf(local_in.fp, expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) fscanf(local_in.fp, expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) fscanf(local_in.fp, expr, &p1, &p2, &p3, &p4)
#else
#define gc(buf) Scanf("%s", buf)
#define Scanf(expr, p) scanf(expr, &p)
#define Scanf2(expr, p1, p2) scanf(expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) scanf(expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) scanf(expr, &p1, &p2, &p3, &p4)
#endif
#define ans(p) cout << p << endl;
signed main() {

	int ii, jj, kk, ll;
	int N;
	int ret = 0;
	int flag = 0;
	char cbuf[8192];

	int A, B;
	gi2(A, B);
	if(B % A == 0){
		ret = A + B;
	}else{
		ret = B - A;
	}

	ans(ret);

	wait();

	return 0;
}

Measured memory_bytes: 256
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
if a[0]>1 or a[0]==1 and n>1:
    print(-1)
    exit()
sm = 0  #a[n]
b = a[n]
c = [0]*(n+1)
c[0] = 1
for i in range(n):
    c[i+1] = min(BIG,2*(c[i]-a[i]))
    if c[i+1]<a[i+1]:
        print(-1)
        exit()
c[n] = a[n]
IMAX = 50
for i in range(n-1,-1,-1):
    b = (b+1)//2 + a[i]
    if i<IMAX and b>2**i:
        print(-1)
        exit()
    c[i] = min(c[i],c[i+1]+a[i])
    if i<IMAX:
        c[i] = min(c[i],2**i)
        #if i>0:
        #    c = min(c,2*(2**(i-1)-a[i-1]))
    #sm += c
    #ddprint(f"{i=} b {b} ci {c[i]}")
#ddprint(c)
print(sum(c))


Measured memory_bytes: 85780
def c_traveling_salesman_around_lake():
    K, N = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]  # ソート済
    A.append(A[0] + K)  # N 番の家と 1 番の家の間の距離も調べたい

    return K - max(A[i + 1] - A[i] for i in range(N))

print(c_traveling_salesman_around_lake())

Measured memory_bytes: 26444
// ABC_161_C

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

int main()
{
	ll n, k;
	cin >> n >> k;

	ll modulo = n % k;

	ll ans = min(modulo, k-modulo);

	cout << ans << "\n";

	return 0;
}

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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define sl1(a)  scanf("%lld",&a)
#define sl2(a,b)  scanf("%lld %lld",&a,&b)
#define sl3(a,b,c)  scanf("%lld %lld %lld",&a,&b,&c)
#define PI 3.1415926535897932


int main(){
    int mod=1000000007;
    int n,m,l;
    sc3(n,m,l);
    int a[n][m];
    int b[m][l];
    rep(i,n) rep(j,m) sc1(a[i][j]);
    rep(i,m) rep(j,l) sc1(b[i][j]);
    rep(i,n) rep(j,l) {
        long long  p=0ll;
        rep(k,m) p+=a[i][k]*b[k][j];
        printf("%lld",p);
        printf(j==l-1?"\n":" ");
    }
    return 0;
}



Measured memory_bytes: 3260
while True:
  w, h = map(int, input().split())
  if w == 0:break
  mp = [input().split() for _ in range(h)]
  points = {}
  
  for y in range(h):
    for x in range(w):
      if mp[y][x] == "S":
        sx, sy = x, y
        points[0] = [(x, y)]
      elif mp[y][x] == "G":
        gx, gy = x, y
      elif mp[y][x] == ".":
        pass
      else:
        if int(mp[y][x]) not in points: points[int(mp[y][x])] = []
        points[int(mp[y][x])].append((x, y))
  
  keys = sorted(points.keys())
  points[keys[-1] + 1] = [(gx, gy)]

  dist = {}
  dist[(0, sx, sy)] = 0
  for key in keys:
    for fx, fy in points[key]:
      score = dist[(key, fx, fy)]
      for tx, ty in points[key + 1]:
        cost = abs(fx - tx) + abs(fy - ty)
        if (key + 1, tx, ty) not in dist or dist[(key + 1, tx, ty)] > score + cost:
          dist[(key + 1, tx, ty)] = score + cost
  print(dist[(keys[-1] + 1, gx, gy)])


Measured memory_bytes: 6800
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
int main() {


	int n;
	std::cin >>n ;
	std::vector< int> ax;
	std::vector< int> ay;
	std::vector<unsigned long long int> ah;
	ax.resize(n);
	ay.resize(n);
	ah.resize(n);

	int flga = 0;
	int flgb = 0;
	for (int i = 0; i < n; ++i)
	{
		std::cin >> ax[i] >> ay[i] >> ah[i];
		if ((flga == 0) && (ah[i] != 0))
		{
			flga = i;
		}
		else if ((flgb == 0) && (ah[i] != 0))
		{
			flgb= i;
		}
	}

	std::deque< std::vector< unsigned long long int> >  bxyh;
	for (int i = 0; i < 101; ++i) {
		for (int j = 0; j < 101; ++j) {
			std::vector< unsigned long long int> tmpbxyh;
			tmpbxyh.resize(3);
			tmpbxyh[0] = i;
			tmpbxyh[1] = j;
			unsigned long long int tmph1 = ah[flga] + std::abs(ax[flga] - i) + std::abs(ay[flga] - j);
			tmpbxyh[2] = tmph1;
				bxyh.push_back(tmpbxyh);
		}
	}

	for (int i = 0; i < n; ++i) {
		if (i == flga) continue;
		int cntx = bxyh.size() - 1;

		while ((bxyh.size() > 1) && (cntx >= 0))
		{
			
			int tmpx = std::abs(ax[i] - (int)bxyh[cntx][0]);
			int tmpy = std::abs(ay[i] - (int)bxyh[cntx][1]);
			long long int tmph = ah[i] + tmpx + tmpy;
			if (ah[i] != 0) {
				if (tmph != bxyh[cntx][2])
				{
					if (cntx == (bxyh.size() - 1)) {
						bxyh.pop_back();
					}
					else if (cntx == 0) {
						bxyh.pop_front();
					}
					else {
						bxyh.erase(bxyh.begin() + cntx);
					}
				}
			}
			else {
				if (tmph < bxyh[cntx][2])
				{
					if (cntx == (bxyh.size() - 1)) {
						bxyh.pop_back();
					}
					else if (cntx == 0) {
						bxyh.pop_front();
					}
					else {
						bxyh.erase(bxyh.begin() + cntx);
					}
				}
			}
			cntx--;
		}
	}
	std::cout << bxyh[0][0] <<" " << bxyh[0][1] <<" " << bxyh[0][2] << std::endl;


	return 0;
}

Measured memory_bytes: 768
nums=[int(x) for x in input().split()]
V,E = nums[0],nums[1]
graph = {x:[] for x in range(V)}

for i in range(E):
    nums=[int(x) for x in input().split()]
    a,b = nums[0]-1,nums[1]-1
    graph[a].append(b)
    graph[b].append(a)


if __name__ == '__main__':
	goal = V - 1
	mids = graph[0]
	for isl in mids:
		if goal in graph[isl]:
			print("POSSIBLE")
			exit(0)
	print("IMPOSSIBLE")

Measured memory_bytes: 55444
N = int(input())
h = list(map(int, input().split()))

possible_range_lengths = []

now = h[0]
range_length = 0
for i in range(N-1):
    if now >= h[i+1]:
        range_length += 1
    else:
        possible_range_lengths.append(range_length)
        range_length = 0
    now = h[i+1]
possible_range_lengths.append(range_length)

print(max(possible_range_lengths))

Measured memory_bytes: 14252
def check(*a_list):
    count = 0
    for i in a_list:
        if count % 2 == 0:  # 奇数
            if i == "L":
                return "No"
        else:  # 偶数
            if i == "R":
                return "No"
        count += 1
    return "Yes"

S = input()
print(check(*S))


Measured memory_bytes: 2940
# -*- coding:utf-8 -*-

def solve():
    N, K = list(map(int, input().split()))
    Ps = list(map(int, input().split()))

    kitai = []  # kitai[i] := p[i]の期待値
    for p in Ps:
        kitai.append(((1+p)*p/2)*(1/p))

    # 尺取法でさがすぜ
    # まずは初期状態を計算する
    ans = 0
    for i in range(0, K):
        ans += kitai[i]

    # つぎにしゃくとっていくぜ
    total = ans
    for i in range(K, N):
        total = total + kitai[i] - kitai[i-K]
        if total > ans:
            ans = total

    print(ans)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 25060
#include<bits/stdc++.h>
using namespace std;
int main(){
  char button[11][11]={
    {'.',',','!','?',' '},
    {'a','b','c'},
    {'d','e','f'},
    {'g','h','i'},
    {'j','k','l'},
    {'m','n','o'},
    {'p','q','r','s'},
    {'t','u','v'},
    {'w','x','y','z'}
  };
  int n;
  cin>>n;
  for(int j=0;j<n;j++){
    string s;
    cin>>s;
    int cnt=0,index=-1;
    for(int i=0;i<s.size();i++){
      if(s[i]=='0'){
        if(index==-1){
          cnt=0;
          continue;
        }
        cnt--;
        cnt%=strlen(button[index]);
        cout<<button[index][cnt]<<flush;
        cnt=0;
        index=-1;
      }else{
        cnt++;
        index=s[i]-'1';
      }
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 3048
N=int(input())
h=list(map(int, input().split()))

dp=[0]*N
dp[1]=abs(h[0]-h[1])

for i in range(2,N):
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]) , dp[i-1]+abs(h[i]-h[i-1]))
print(dp[N-1])

Measured memory_bytes: 13928
#include <stdio.h>

int main(void){
    char s[100];
    char p[100];
    int count=0;
    int i=0;
    while(1){
        scanf("%c",&s[count]);
        if(s[count]=='\n'){
            break;
        }
        count++;
    }
    int u[count*3];
    for(i=0;i<count*2;i++){
        if(i<count){
            u[i]=s[i];
        }else if(i<count*2){
            u[i]=s[i-count];
        }
    }
    int k = 0;
    while(1){
        scanf("%c",&p[k]);
        if(p[k]=='\n'){
            break;
        }
        k++;
    }
    int t=0;
    for(i=0;i<count*2;i++){
        t = 0;
        while(u[i+t] == p[t]){
            t++;
            if(t==k){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0; /*0?????????*/
}

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

cums = [0]
cump = [0]
for a in A:
    cums.append(cums[-1] + a)
    cump.append(cump[-1] + max(0,a))

ans = 0
for i in range(N-K+1):
    tmp = cump[i] + cump[-1] - cump[i+K]
    tmp += max(0, cums[i+K] - cums[i])
    ans = max(ans, tmp)
print(ans)

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

int main(){
  int N, L;
  cin >> N >> L;
  string a[110];
  string ans;
  for(int i = 0; i < N; i++)cin>>a[i];
  sort(a, a + N);
  for(int i = 0; i < N; i++){
    ans += a[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
  int n,t,a,h,i,r;
  double d=1000.0,c;
  scanf("%d%d%d",&n,&t,&a);
  for(i=1;i<=n;i++){
    scanf("%d",&h);
    c=fabs(a-(t-h*0.006));
    if(c<d){ d=c; r=i; }
  }
  printf("%d",r);
}

Measured memory_bytes: 128
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
a,b = inp
p [a+b,a-b,a*b].max 

Measured memory_bytes: 1788
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

ll mod = 1000000007 ;
//long double pie = acos(-1) ;

void yorn(bool a){if(a) cout << "Yes" ; else cout << "No" ; cout << endl ;}
//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	map<ll,ll> s ;
	vll num(0) ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		if(s.count(a)) s[a]++ ;
		else{
			s[a] = 1 ;
			num.push_back(a) ;
		}
	}
	if(s.size()==1){
		yorn(num.at(0)==0) ;
		return 0 ;
	}
	if(s.size()==2){
		yorn(n%3==0&&s.count(0)&&s[0]==n/3) ;
		return 0 ;
	}
	if(s.size()==3){
		if(n%3!=0) yorn(0) ;
		else yorn(s[num.at(0)]==s[num.at(1)]&&s[num.at(1)]==s[num.at(2)]&&(num.at(0)^num.at(1)^num.at(2))==0) ;
		return 0;
	}
	yorn(0) ;
}


Measured memory_bytes: 8672
n=int(input())
s={"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(n):
    v=input()
    if v[0] in s:
        s[v[0]]+=1
l=list(s.values())
ans=0
for a in range(5):
    for b in range(a+1,5):
        for c in range(b+1,5):
            ans+=l[a]*l[b]*l[c]         
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int
main(int argc, char argv[])
{
  int x, a;
  scanf("%d %d", &x, &a);
  
  int ans;
  if(x < a) ans = 0;
  else ans = 10;
  
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
# K - Stones
def main():
    N, K, *A = map(int, open(0).read().split())
    dp = [0] * (K + 1)
    for i in range(1, K + 1):
        for a in A:
            if i - a >= 0:
                dp[i] |= dp[i - a] ^ 1
    print("First" if dp[-1] else "Second")


if __name__ == "__main__":
    main()


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

using namespace std;
const long long INF = 1LL <<60;

int main(void){
  int N,K;
  cin >>N >>K;
  long h[N],dp[N];
  long i,j,l,tmp;
 
  dp[0]=0;
  cin>>h[0];
  for(i=1;i<N;i++){
    cin>>h[i];
    i<K ? l=i+1 : l=K+1;
    dp[i]=INF;
    for(j=1;j<l;j++){
      dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
      //cout<<tmp;
    }
    //dp[i]=tmp;
  }
  
  cout<<dp[N-1]<<endl;
  
  return 0;
}
  

  

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

int main()
{
    int n;
    cin >> n;
    int a[n] = {};
    int sum = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a+n);
    if(sum - a[n-1] > a[n-1]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>

using namespace std;
using  ull = unsigned long long int;

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


int main() {
	

	int x, a, b,sub;
	cin >> x >> a >> b;
	sub = b - a;
	if (sub <= 0)cout << "delicious" << endl;
	else if (sub <= x)cout << "safe" << endl;
	else cout << "dangerous" << endl;



	return 0;
}

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

using std::cin;
using std::cout;

int main(int argc, char* argv[]) {
  int n, m;
  cin >> n >> m;

  std::vector<long> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  std::make_heap(a.begin(), a.end());
  for (int i = 0; i < m; ++i) {
    std::pop_heap(a.begin(), a.end());
    a[n - 1] /= 2;
    std::push_heap(a.begin(), a.end());
  }

  long total = 0;
  for (int i = 0; i < n; ++i) {
    total += a[i];
  }

  cout << total;

  return 0;
}


Measured memory_bytes: 1024
#if 0
????????£????????????1.5h
????????????????????¨????????§?????????????????§?°??????????????¨?????????????????????????????????????????¨?????????????
????????????????????????????????????????????????????????????????????????????????´??????(????????¨?????????????????¢??????)???

#endif

#include <utility>
#include <algorithm>
#include <iostream>
using namespace std;

int N,M;
pair<int,int> PD[10010];
int main(){
	while (cin>>N>>M && N!=0){ //N!=0??§?????????N=0,M=0??????????????????????????????????????????
		int d,p;
		int S=0; //????¨??????????
		for(int i=0; i<N; ++i){
			cin >> d >> p;
			PD[i]=make_pair(p,d);
		}
		sort(PD,PD+N);
		reverse(PD,PD+N); //PD.first??????????????±??????????????????
		for(int i=0; i<N; ++i)
			S+=PD[i].first*PD[i].second; //??????0?????´????????????S?????????
		for(int i=0; i<N; ++i){
			if(M<=0) break; //??????????¶???????????????£???????????????????????????
			int guarded = min(M,PD[i].second); //????????¨??¨????????????????????????????????¨?????¨???????????????????¶????
			S-=PD[i].first*guarded;
			M-=guarded; //????????????
		}
		cout << S << endl;
	}
}

/*for(int i=0; i<N; ++i){
			totd+=PD[i].second; //???????????§???????¨??????¢=????????£???????¨???????(1?????¢=1?????????)
			if(totd+PD[i+1].second>=M){
				last =i; //??????????????£??¨???????????????????????????????????????
				break; 
			}
		}
		for(int i=last+2; i<N; ++i){//?\???????????????????????¨??????????(????????????????????¨??????????????????)
			tote += PD[i].first*PD[i].second;
		}
		tote += (PD[last+1].second-(M-totd))*PD[last+1].first; //?????¨???????????????????????????????????????????¶????
		cout << tote <<endl;*/

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fst first
#define snd second

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    auto b = p;
    sort(ALL(b));
    int miss = 0;
    for (int i = 0; i < n; i++)
    {
        if (p[i] != b[i])
            miss++;
    }
    if (miss <= 2)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct {
    int x,y;
}Vec;

typedef struct{
    int A;
    Vec *Tes;
} Human;

int main(){
    int N,i,j;
    // 入力---------
    scanf("%d",&N);
    Human *Hum = malloc(sizeof(Human)*N);
    for(i=0;i<N;i++){
        scanf("%d",&Hum[i].A);
        Hum[i].Tes=malloc(sizeof(Vec)*Hum[i].A);
        for(j=0;j<Hum[i].A;j++) scanf("%d %d",&Hum[i].Tes[j].x,&Hum[i].Tes[j].y);
    }
    int bit,max=0;
    for(bit=0;bit<(1<<N);bit++){
        int flag=0,num=0;
        for(i=0;i<N && (!flag);i++){
            if((bit>>i)&1) {//i桁目のビットが立っていたらHum[i]が正直者
                num++;
                for(j=0;j<Hum[i].A;j++){//証言に合致するか検証
                    int index = Hum[i].Tes[j].x-1;
                    //証言に合致しないものを見つけたら旗を立てる
                    if(((bit>>index)&1)!=Hum[i].Tes[j].y) {
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(!flag && max < num) max = num;
    }
    printf("%d\n",max);
}

Measured memory_bytes: 1696