akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

const int INF=1000000000;

int N;
string words[101];
int vals[101];
string obj;
int mem[201];
int dp[5001];

int main(){
  int cs=0;
  while(cin>>N&&N){
    for(int i=0;i<N;i++)cin>>words[i]>>vals[i];
    cin>>obj;
    for(int j=obj.size();j>=0;j--){
      int res=0;
      if(j==obj.size())res=0;
      else{
	for(int k=0;k<N;k++){
	  if(j+words[k].size()<=obj.size()
	     &&obj.compare(j,words[k].size(),words[k])
	     ==0){
	    res=max(res,mem[j+words[k].size()]+vals[k]);
	  }
	}
      }
      mem[j]=res;
    }
    int maxLen=mem[0];
    for(int i=0;i<=maxLen;i++){
      int res=INF;
      if(i==0)res=0;
      else{
	for(int j=0;j<N;j++){
	  if(i-vals[j]>=0){
	    res=min(res,dp[i-vals[j]]
		    +(int)words[j].size());
	  }
	}
      }
      dp[i]=res;
    }
    cout<<"Case "<<cs+1<<": "<<dp[maxLen]<<endl;
    cs++;
  }

  return 0;
}

Measured memory_bytes: 944
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n; i >= 0; i--)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

void chmax(int& a,int b){
	if(b > a){
		a=b;
	}
}

int ans=0;
char ma[101][101];
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
void dfs(int y,int x,char c){
		ma[y][x]='.';
		rep(i,4){
			if(ma[y+dy[i]][x+dx[i]]==c){
				dfs(y+dy[i],x+dx[i],c);
			}
		}
}
int main(){
	int H,W;
	while(cin >> H >> W,H&&W){
		ans=0;
	rep(i,H){
		rep(j,W){
			cin>>ma[i][j];
		}
	}
	rep(i,H){
		rep(j,W){
		if(ma[i][j]!='.'){
			dfs(i,j,ma[i][j]);
			ans++;
		}
		}
	}
	cout << ans << endl;
	}
}

Measured memory_bytes: 1632
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    if(k%2==0 || k%5==0){
      System.out.println(-1);
    }
    else if(k==1 || k==7){
      System.out.println(1);
    }
    else{
    int rem =7;
    int count=1;
    while(rem!=0){
      rem=(rem*10+7)%k;
      count++;
    }
    System.out.println(count);
    }
  }
}

Measured memory_bytes: 35688
program C;
var
  na, nb, nc: Int64;
  x, y: Int64;

function Solve: Int64;
begin
  Result := x * na + y * nb;

  while (0 < x) and (0 < y) do
  begin
    if 2 * nc < na + nb then
    begin
      Inc(Result, 2 * nc - na - nb);
      Dec(x);
      Dec(y);
    end
    else
      break;
  end;

  while 0 < x do
  begin
    if 2 * nc < na then
    begin
      Inc(Result, 2 * nc - na);
      Dec(x);
    end
    else
      break;
  end;

  while 0 < y do
  begin
    if 2 * nc < nb then
    begin
      Inc(Result, 2 * nc - nb);
      Dec(y);
    end
    else
      break;
  end;

end;

begin
  ReadLn(na, nb, nc, x, y);

  WriteLn(Solve);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline LL rd() {
	char ch=nc(); LL i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=1e5+50, mod=1e9+7;
int n;
LL a[N],A,B;
inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
struct ST {
	int sum[N*4], tag[N*4];
	inline void build(int k,int l,int r) {
		if(l==r) {
			sum[k]=!l; return;
		} int mid=(l+r)>>1;
		build(k<<1,l,mid); 
		build(k<<1|1,mid+1,r);
		sum[k]=add(sum[k<<1],sum[k<<1|1]);
	}
	inline void clear(int k) {sum[k]=0; tag[k]=1;}
	inline void clear() {clear(1);}
	inline void pushdown(int k) {if(tag[k]) clear(k<<1), clear(k<<1|1), tag[k]=0;}
	inline int ask(int k,int l,int r,int L,int R) {
		if(L<=l && r<=R) return sum[k];
		pushdown(k); int mid=(l+r)>>1;
		if(R<=mid) return ask(k<<1,l,mid,L,R);
		else if(L>mid) return ask(k<<1|1,mid+1,r,L,R);
		else return add(ask(k<<1,l,mid,L,R),ask(k<<1|1,mid+1,r,L,R));
	}
	inline void inc(int k,int l,int r,int pos,int v) {
		if(l==r) {sum[k]=add(sum[k],v); return;}
		pushdown(k); int mid=(l+r)>>1;
		if(pos<=mid) inc(k<<1,l,mid,pos,v);
		else inc(k<<1|1,mid+1,r,pos,v);
		sum[k]=add(sum[k<<1],sum[k<<1|1]);
	}
} f,g;

int main() {
	n=rd(), A=rd(), B=rd();
	for(int i=1;i<=n;i++) a[i]=rd();
	sort(a+1,a+n+1); a[0]=-1e18;
	f.build(1,0,n);
	g.build(1,0,n);
	for(int i=2;i<=n;i++) {
		int pos=upper_bound(a,a+n+1,a[i]-A)-a-1;
		int sumg=f.ask(1,0,n,0,pos);
		if(a[i]-a[i-1]<B) f.clear();
		
		pos=upper_bound(a,a+n+1,a[i]-B)-a-1;
		int sumf=g.ask(1,0,n,0,pos);
		if(a[i]-a[i-1]<A) g.clear();
		
		if(sumg) g.inc(1,0,n,i-1,sumg);
		if(sumf) f.inc(1,0,n,i-1,sumf);
	}
	cout<<add(f.sum[1],g.sum[1]);
}

Measured memory_bytes: 6912
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = LI()
s.sort(reverse=True)
use = [s[0]]
rest = s[1:]
for _ in range(n):
    new_use = []
    que = deque(rest)
    for i in use:
        rest_tmp = []
        while que:
            x = que.popleft()
            if i > x:
                new_use.append(x)
                break
            else:
                rest_tmp.append(x)
        que += rest_tmp
    use += new_use
    use.sort(reverse=True)
    rest = list(que)
    rest.sort(reverse=True)
if len(use) == 2**n:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 134088
#include <iostream>
#include <cstdio>
#include <atcoder/fenwicktree>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rep2(i,s,t) for(int i = s; i <= t; ++i)
#define rev(i,n) for(int i = n-1; i >= 0; --i)
#define rev1(i,n) for(int i = n; i > 0; --i)
#define rev2(i,s,t) for(int i = s; i >= t; --i)
#define F first
#define S second
using namespace std;
using namespace atcoder;
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(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
int main()
{
  int n,q; scanf("%d %d", &n, &q);

  fenwick_tree<ll> fw(n);
  rep(i,n) {
    ll a; scanf("%lld", &a);
    fw.add(i, a);
  }

  rep(i,q) {
    int t; scanf("%d", &t);
    if(t == 0) {
      ll p, x; scanf("%lld %lld", &p, &x);
      fw.add(p, x);
    }
    else {
      int l, r; scanf("%d %d", &l, &r);
      printf("%lld\n", fw.sum(l, r));
    }
  }
  return 0;
}


Measured memory_bytes: 8252
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

#define rep(i,n) for(int i=0; i<int(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		int K, P;
		cin >> K >> P;
		if (K%P != 0)
			cout << K%P << endl;
		else
			cout << P << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int main(void){
  int a,b,c;
  int count = 0;
  cin >> a >> b >> c ;

  for(;b - a >= 0; a++){
    if(c % a == 0){
      count++;
    }
  }
  cout << count <<endl;
  return 0;
}



Measured memory_bytes: 3112
#include<stdio.h>

int main(){
    int dice1[6]={};
    for(int i=0;i<6;i++){
        scanf("%d",&dice1[i]);
    }
    int dice2[6]={};
    for(int i=0;i<6;i++){
        scanf("%d",&dice2[i]);
    }
    int dicepos[6][6]={{1,6,2,3,5,4},{2,5,6,3,1,4},{3,4,2,6,5,1},{4,3,2,1,5,6},{5,2,1,3,6,4},{6,1,2,4,5,3}};
    for(int i=0;i<6;i++){
        if((dice1[dicepos[0][0]-1]==dice2[dicepos[i][0]-1])&&(dice1[dicepos[0][1]-1]==dice2[dicepos[i][1]-1])){
            if(
                dice1[dicepos[0][2]-1]==dice2[dicepos[i][2]-1]
                &&dice1[dicepos[0][3]-1]==dice2[dicepos[i][3]-1]
                &&dice1[dicepos[0][4]-1]==dice2[dicepos[i][4]-1]
                &&dice1[dicepos[0][5]-1]==dice2[dicepos[i][5]-1]){
                printf("Yes\n");
                return 0;
            }else if(
                dice1[dicepos[0][3]-1]==dice2[dicepos[i][2]-1]
                &&dice1[dicepos[0][4]-1]==dice2[dicepos[i][3]-1]
                &&dice1[dicepos[0][5]-1]==dice2[dicepos[i][4]-1]
                &&dice1[dicepos[0][2]-1]==dice2[dicepos[i][5]-1]){
                printf("Yes\n");
                return 0;
            }else if(
                dice1[dicepos[0][4]-1]==dice2[dicepos[i][2]-1]
                &&dice1[dicepos[0][5]-1]==dice2[dicepos[i][3]-1]
                &&dice1[dicepos[0][2]-1]==dice2[dicepos[i][4]-1]
                &&dice1[dicepos[0][3]-1]==dice2[dicepos[i][5]-1]){
                printf("Yes\n");
                return 0;
            }else if(
                dice1[dicepos[0][5]-1]==dice2[dicepos[i][2]-1]
                &&dice1[dicepos[0][2]-1]==dice2[dicepos[i][3]-1]
                &&dice1[dicepos[0][3]-1]==dice2[dicepos[i][4]-1]
                &&dice1[dicepos[0][4]-1]==dice2[dicepos[i][5]-1]){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

Matrix mIdentity(ll n) {
    Matrix A(n, Array(n));
    for(int i = 0; i < n; ++i)
        A[i][i] = 1;
    return A;
}

Matrix mMul(const Matrix &A, const Matrix &B) {
    Matrix C(A.size(), Array(B[0].size()));
    for(int i = 0; i < C.size(); ++i)
        for(int j = 0; j < C[i].size(); ++j)
            for(int k = 0; k < A[i].size(); ++k)
                (C[i][j] += (A[i][k] % MOD) * (B[k][j] % MOD)) %= MOD;
    return C;
}
// O( n^3 log e )
Matrix mPow(const Matrix &A, ll e) {
    return e == 0 ? mIdentity(A.size()) : e % 2 == 0 ? mPow(mMul(A, A), e / 2) : mMul(A, mPow(A, e - 1));
}

void solve() {
    ll n, a, b;
    cin >> n >> a >> b;
    vec<ll> P(n);
    if(n < a + b - 1 or n > a * b) {
        cout << -1 << en;
        return;
    }

    ll ret = n - b;
    ll id = 1;
    vvec<int> ans(b);
    REP(i, b) {
        if(ret) {
            REP(j, a - 1) {
                ans[i].push_back(id);
                id++;
                ret--;
                if(!ret)
                    break;
            }
        }
        ans[i].push_back(id);
        id++;
    }

    REP2(i, b) {
        for(auto x : ans[i])
            cout << x << " ";
    }
    cout << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


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

int main() {
    int length;
    cin >> length;
    int array[length + 1];
    int array_check[length + 1];
    int swap_cout = 0;
    
    for (int i = 1; i <= length; i++) {
        cin >> array[i];
        array_check[i] = i;
        if (array[i] != array_check[i]) {
            swap_cout++;
        }
    }

    if (swap_cout == 2 or swap_cout == 0) {
        cout << "YES" << endl;
    } else if (swap_cout > 0) {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
typedef pair<int,int> P;
#define mod 1000000007


int main(){
   vector<int>a(5);
   int last;
   int mi=inf;
   int ans=0;
   rep(i,5) {
       int x;
       cin >> x;
       a[i]=x;
       int p=x%10;
       if(p!=0){
           if(p<=mi) {
               mi=min(mi,p);
               last=i;
           }
       }
   }
   rep(i,5){
       if(i==last) ans+=a[i];
       else{
           if(a[i]%10==0) ans+=a[i];
           else ans+=a[i]+10-a[i]%10;
       }
   }
   cout << ans <<endl;
   return 0;
}


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

int main() {
  int L,R;
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  L = A + B; //左の皿の重りの重さ
  R = C + D; //右の皿の重りの重さ
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (L == R){
    cout << "Balanced" << endl;
  }
  else if (L < R){
    cout << "Right" << endl;
  }
}

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

int main() {

    int a,b;

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

Measured memory_bytes: 760
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int d, ans;
  while(cin >> d){
    ans = 0;
    for(int i = 0; i < 600; i += d){
      ans += d * i * i;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
  int n, m; cin >> n >> m;
  vector<int> as(m);
  vector<int> cs(m, 0);

  for (int i = 0; i < m; i++) {
    int a, b; cin >> as[i] >> b;
    for (int j = 0; j < b; j++) {
      int c; cin >> c;
      cs[i] = cs[i] | (1<<(c-1));
    }
  }
  
  map<int, int> memo;
  memo.insert(make_pair(0, 0));
  for (int i = 0; i < m; i++) {
    map<int, int> next;
    for(auto it = memo.begin(); it != memo.end(); it++) {
      int key = it->first; 
      int value = it->second;
      if (next.find(key) == next.end()) {
        next[key] = value;
      }
      if (next[key] > value) {
        next[key] = value;
      }

      int next_key = key | cs[i];
      int next_value = value + as[i];
      if (next.find(next_key) == next.end()) {
        next[next_key] = next_value;
      }
      if (next[next_key] > next_value) {
        next[next_key] = next_value;
      }
    }
    memo = next;
  }
  int ans = -1;
  if (memo.find((1<<n)-1) != memo.end()) {
    ans = memo[(1<<n)-1];
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 640
// glory be to the sky
#include<cstdio>
#include<bits/stdc++.h> 
#define pb push_back
using namespace std;
	
typedef long long ll; 

int main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	string input;
	vector<char> output;
	cin >> input;
	for (int i = 0; i < input.length(); i++) {
		if (input[i] == '0') output.pb('0');
		else if (input[i] == '1') output.pb('1');
		else if (output.size()) output.pop_back(); 
	}
	for (int i = 0; i < output.size(); i++) cout << output[i];
	return 0;	
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <map>
#include <algorithm>
#include <random>
#include <complex>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const int MN = 501*1000*1000;

ll gcd(ll a, ll b) {
    if (!a) return b;
    return gcd(b%a, a);
}
ll ext_gcd(ll a, ll b, ll &x, ll &y) {
    ll d = a;
    if (b) {
        d = ext_gcd(b, a%b, y, x);
        y -= a / b*x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

bitset<MN> mp;

int w, d, n, m, t, u, h;
int x;
void init() {
    m = t-m%t;
    u = gcd(t, w+d), h = gcd(t, m);
    ll xx, y;
    ext_gcd(m, t, xx, y);
    x = ((xx % t) + t) % t;
}
int solve() {
    init();
    int res = 0, c = 0;
    int l = 0;

    int tt = t/2;
    int s = 0;
    int i, j;
    int th = t/h;
    for (i = 0; i < tt; i += h) {
        if (s<n) {
            l = (l+u-1) /u*u;
            res += max(0, (i-l - w + u) / u);
            l = i+1;
        }
        s += x; s %= th;
    }

    for (; i < t; i += h) {
        if (s<n) {
            l = (l+u-1) /u*u;
            res += max(0, (i-l - w + u) / u);
            l = i+1;
        }
        s += x;
        s %= th;
    }
    l = (l+u-1) / u * u;
    res += max(0, (t-l-w+u)/u);
    return res;
}

int main() {
    cin >> w >> d >> n >> m >> t; w++; d--;
    printf("%.20f\n", 1.0 * solve() / (t / u));
    return 0;
}

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

//a contains b
bool check(string a,string b){
  int n = a.length();
  int m = b.length();

  for(int i=0;i<n;i++){
    bool flg = true;

    for(int j=0;j<m;j++){
      if(a[(i + j) % n] != b[j]){
        flg = false;
        break;
      }
    }
    if(flg){
      return true;
    }
  }

  return false;
}

int main(){
  string a;
  int n;

  while(cin>>a>>n){
    int res = 0;

    for(int i=0;i<n;i++){
      string b;
      cin>>b;

      if(check(b,a)){
        res++;
      }
    }
    cout<<res<<endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#define MAXA 100000
#define MAX 20000000000
#define s(i) scanf("%d", &(i))
#define p(i) printf("%d", (i))
#define ps() printf(" ") 
#define rer(i,j,k) for((i)=(j);(i)<(k);++(i))
#define ret(i,j,k) for((i)=(j);(i)>(k);--(i))
using namespace std;
int num[MAXA] = {0};
int main(){
	int n, x, i, Count = 0, sum = 0;
	cin >> n >> x;
	rer(i,0,n){
		cin >> num[i];
		sum += num[i];
		if(sum <= x){
			Count++;
		}
	}
	cout << Count+1 << endl;
	return 0;
} 

Measured memory_bytes: 256
/* In the name of ALLAH */
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<string>

// MAXIMUM and MINIMUM elements
#define mx_ari(a)   *max_element(a , a+sizeof(a)/4)
#define mn_ari(a)   *min_element(a , a+sizeof(a)/4)
#define mx_arl(a)   *max_element(a , a+sizeof(a)/8)
#define mn_arl(a)   *min_element(a , a+sizeof(a)/8)
#define mx_vec(v)   *max_element(v.begin() , v.end())
#define mn_vec(v)   *min_element(v.begin() , v.end())
// COUNT the occurence of an element
#define cnt_ari(a,b)   count(a , a+sizeof(a)/4 , b)
#define cnt_arl(a,b)   count(a , a+sizeof(a)/8 , b)
#define cnt_vec(v,b)   count(v.begin() , v.end() , b)
// INPUTs
#define sci(a)        scanf("%d",&a)
#define scii(a,b)     scanf("%d %d",&a,&b)
#define sciii(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scl(a)        scanf("%lld",&a)
#define scll(a,b)     scanf("%lld %lld",&a,&b)
#define sclll(a,b,c)  scanf("%lld %lld %lld",&a,&b,&c)
#define scf(a)        scanf("%f",&a)
#define scff(a,b)     scanf("%f %f",&a,&b)
#define scfff(a,b,c)  scanf("%f %f %f",&a,&b,&c)
#define scd(a)        scanf("%ld",&a)
#define scdd(a,b)     scanf("%lf %lf",&a,&b)
#define scddd(a,b,c)  scanf("%lf %lf %lf",&a,&b,&c)
// OUTPUTs
#define pri(a)        printf("%d ",a)
#define prii(a,b)     printf("%d %d ",a,b)
#define priii(a,b,c)  printf("%d %d %d ",a,b,c)
#define prl(a)        printf("%lld ",a)
#define prll(a,b)     printf("%lld %lld ",a,b)
#define prlll(a,b,c)  printf("%lld %lld %lld ",a,b,c)
#define prd(a)        printf("%.4lf ",a)
#define prdd(a,b)     printf("%.4lf %.4lf ",a,b)
#define prddd(a,b,c)  printf("%.4lf %.4lf %.4lf ",a,b,c)
#define prf(a)        printf("%.4f ",a)
#define prff(a,b)     printf("%.4f %.4f ",a,b)
#define prfff(a,b,c)  printf("%.4f %.4f %.4f ",a,b,c)
// LOOPs
#define foi(i,n)      for(int i=0;i<n;i++)
#define fol(i,n)      for(long long int i=0;i<n;i++)
#define fod(i,n)      for(double i=0;i<n;i++)
#define fof(i,n)      for(float i=0;i<n;i++)
// NEWLINEs
#define nwl           << "\n"
#define nl            printf("\n");
// PAIRs and PUSHbacks
#define mp            make_pair
#define pb            emplace_back
// IMPORTANTs
#define ll          long long
#define ull         unsigned long long int
#define mod         1000000007
#define lcm(a,b)     (a*b) / __gcd(a,b)

using namespace std;





int main()
{
   int n; cin >> n;
   int a[n] , cost[n] , dp[n];
   foi(i,n){
      cin >> a[i];
   }

   cost[n-1] = 0;
   cost[n-2] = abs(a[n-1] - a[n-2]);

   for(int i=n-3; i>=0 ; i--){
      cost[i] = min(cost[i+2]+abs(a[i] - a[i+2]) , cost[i+1]+abs(a[i] - a[i+1]));
   }

   cout << cost[0];

   return 0;
}

Measured memory_bytes: 4340
n, m = map(int, input().split())
a_b = [list(map(int, input().split())) for i in range(n)]
c_d = [list(map(int, input().split())) for i in range(m)]

for i in range(n):
    min_dis = 400000000
    min_dis_ind = 0
    for j in range(m):
        tmp = abs(a_b[i][0] - c_d[j][0]) + abs(a_b[i][1] - c_d[j][1])
        if min_dis > tmp:
            min_dis = tmp
            min_dis_ind = j
    print(min_dis_ind  + 1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve() {
	int n;
	cin >> n;
	int x = -1, y = -1;
	for (int i = 2; i * i <= n; ++i) {
		if (n % i == 0) {
			x = i;
			y = n / i;
		}
	}
	if (x == -1 && y == -1) {
		x = 1;
		y = n;
	}
	cout << (x - 1) + (y - 1);
}

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


#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// test
	solve();

	return 0;
}

Measured memory_bytes: 3668
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
#define dbg(vec) for (size_t _ = 0; _ < vec.size(); ++_){std::cerr << #vec << "[" << _ << "] : " << vec[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

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

  int n; cin >> n;
  vi b(n - 1);
  rep(i, n - 1) cin >> b[i];

  vi a(n);

  a[n - 1] = b[n - 2];

  for (int i = n - 2; i >= 1; --i) {
      if (b[i - 1] < b[i]) {
          a[i] = b[i - 1];
      } else {
          a[i] = b[i];
      }
  }

  a[0] = b[0];
  //dbg(a);
  cout << accumulate(all(a), int()) << '\n';

  return 0;
}

Measured memory_bytes: 256
import statistics
import math
# N = int( input())
D,G = list(map(int,input().split(" ")))

items = []

for i in range(D):
    p,c = list(map(int,input().split(" ")))
    items.append((p,c))

ans = 10e9
for  i in range(2**D):
    # print("--"*20)
    # print("i=",i)
    socre = 0
    co = 0
    notzenkan = []
    for j in range(D):
        if ((i >> j)& 1): #最初に全完する問題を解き終える
            socre += (j + 1 ) * 100 *items[j][0] +  items[j][1]
            co += items[j][0]
        else:
            notzenkan.append(j)
    notzenkan = notzenkan[::-1]
    # print(socre)
    for q in notzenkan:
        if socre >= G:
                break
        question_num = items[q][0]
        for num in range(question_num):
            socre += (q + 1 ) *100
            co += 1
            if socre >= G:
                break
        # print(socre)
    if co < ans and socre >= G:
        # print(co)
        ans = co
print(ans)






Measured memory_bytes: 5200
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int H, N;
    cin >> H >> N;
    ll dp1[10100];
    ll dp2[10100];
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    rep(i, H + 1) {
        dp1[i] = INF;
        dp2[i] = INF;
    }
    // dp[i][j]:=[0,i)の魔法で、jダメージ与えるときの最小魔力
    int state = 0;
    dp1[0] = 0;
    dp2[0] = 0;
    for(int i = 0; i < N; i++) {
        if(state == 0) {
            for(int j = 0; j < H; j++) {
                dp2[min(H, j + A[i])] =
                    min(dp2[min(H, j + A[i])], dp2[j] + B[i]);
            }
            for(int j = 0; j <= H; j++) {
                dp1[j] = dp2[j];
            }
        } else {
            for(int j = 0; j < H; j++) {
                dp1[min(H, j + A[i])] =
                    min(dp1[min(H, j + A[i])], dp1[j] + B[i]);
            }
            for(int j = 0; j <= H; j++) {
                dp2[j] = dp1[j];
            }
        }
        state = 1 - state;
    }
    cout << dp1[H] << endl;
    return 0;
}

Measured memory_bytes: 384
import * as fs from 'fs';

//in
// 10
//out
// Yes
const main = (inp: string) => {
    const n :number= parseInt(inp);
    for (let i:number =1; i<10;i++){
        for (let j :number =1;j<10 ;j++){
            if (n === i*j) {
                console.log('Yes');
                return;
            }
        }
    }

    console.log('No');

};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)

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

int N;
vector<pii> G[100010];
int Q,K;
ll D[100010];

void DFS(int v,ll l)
{
    if(D[v] != -1)return;
    D[v] = l;

    for(int i = 0; i < G[v].size(); i++)
    {
        pii now = G[v][i];
        DFS(now.se,now.fi + l);
    }
    return;
}

int main()
{
    memset(D,-1,sizeof(D));
    scanf("%d",&N);
    for(int i = 0; i < N - 1; i++)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        G[a].pb(mk(c,b));
        G[b].pb(mk(c,a));
    }
    scanf("%d%d",&Q,&K);
    DFS(K,0);
    for(int i = 0; i < Q; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        printf("%lld\n",D[x] + D[y]);
    }
    return 0;
}


Measured memory_bytes: 14336
from collections import defaultdict


def solve(s, l):

    for i in range(1, len(s) - 1):
        # ひつじ
        if l[i] == 1:
            if s[i] == "o":
                l[i + 1] = l[i - 1]
            else:
                l[i + 1] = -1 * l[i - 1]
        # おおかみ
        else:
            if s[i] == "o":
                l[i + 1] = -1 * l[i - 1]
            else:
                l[i + 1] = l[i - 1]

    if l[0] == 1:
        if s[0] == "o":
            ok1 = l[1] == l[-1]
        else:
            ok1 = l[1] != l[-1]
    # おおかみ
    else:
        if s[0] == "o":
            ok1 = l[1] != l[-1]
        else:
            ok1 = l[1] == l[-1]

    if l[-1] == 1:
        if s[-1] == "o":
            ok2 = l[0] == l[-2]
        else:
            ok2 = l[0] != l[-2]
    # おおかみ
    else:
        if s[-1] == "o":
            ok2 = l[0] != l[-2]
        else:
            ok2 = l[0] == l[-2]

    return ok1 and ok2

def main():
    N = int(input())
    S = input()
    ans = [None] * N
    ans[0] = 1
    ans[1] = 1
    if solve(S, ans):
        print(*["S" if x == 1 else "W" for x in ans], sep="")
        return

    ans = [None] * N
    ans[0] = 1
    ans[1] = -1
    if solve(S, ans):
        print(*["S" if x == 1 else "W" for x in ans], sep="")
        return

    ans = [None] * N
    ans[0] = -1
    ans[1] = 1
    if solve(S, ans):
        print(*["S" if x == 1 else "W" for x in ans], sep="")
        return

    ans = [None] * N
    ans[0] = -1
    ans[1] = -1
    if solve(S, ans):
        print(*["S" if x == 1 else "W" for x in ans], sep="")
        return

    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7876
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	ll n; cin >> n; n--;
	string s="";
	while(n>=0){
		int p=n%26;
		s+=(char)('a'+p);
		n-=26;
		if(n<0)
			break;
		n/=26;
	}
	reverse(ALL(s));
	cout << s << endl;
	return 0;
}


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

set<string> st;

int main(){
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i, n){
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 19236
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	bits := make([]int, 32)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
		for ii := 31; ii >= 0; ii-- {
			on := 1 & (aa[i] >> uint(ii))
			bits[ii] += on
			if on == 1 {
				break
			}
		}
	}
	sort.Ints(aa)
	var ans int64
	for i := 31; i >= 0; i-- {
		minus := minint(bits[i], m)
		if bits[i] >= m {
			sort.Ints(aa)
		}
		bits[i] -= minus
		if i > 0 {
			bits[i-1] += minus
		}
		for ii := 0; ii < minus; ii++ {
			aa[n-1-ii] >>= 1
		}
		m -= minus
	}
	for i := 0; i < n; i++ {
		ans += int64(aa[i])
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}

func minint(a int, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 3584
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int l[105];

int main() {
	int n, x;
	cin >> n >> x;
	REP(i, n)scanf("%d", &l[i]);
	REP(i, n) {
		x -= l[i];
		if (x < 0) {
			printf("%d\n", i + 1);
			return 0;
		}
	}
	printf("%d\n", n + 1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	vector<bool> n(10, false);
	for (int i = 0; i < 4; ++i) {
		int a;
		cin >> a;
		n[a] = true;
	}

	if (n[1] && n[9] && n[7] && n[4]) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

bool pal(string s)
{
    int S = s.size();
    rep(i,S)if(s[i]!=s[S-1-i]) return false;
    return true;
}

int solve()
{
    string s;
    cin >>s;
    int S = s.size();

    string t = "";
    vector<int> idx;
    rep(i,S)if(s[i]!='x')
    {
        t+=s[i];
        idx.pb(i);
    }

    if(t.size()==0) return 0;
    if(!pal(t)) return -1;

    int T = t.size();
    int ct = 0;
    int l = idx[(T-1)/2], r = idx[T/2];
    // dbg(l);dbg(r);
    while(l>=0 || r<S)
    {
        // printf(" N %d %d\n", l,r);
        if(l==-1)
        {
            ++ct;
            ++r;
        }
        else if(r==S)
        {
            --l;
            ++ct;
        }
        else
        {
            if(s[l]==s[r])
            {
                --l;
                ++r;
            }
            else
            {
                if(s[l]=='x')
                {
                    --l;
                    ++ct;
                }
                else if(s[r]=='x')
                {
                    ++r;
                    ++ct;
                }
                else assert(false);
            }
        }
    }

    return ct;
}

int main()
{
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 1148
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    
		String str = "";
		try {
			while ((str = in.readLine()) != null) {
				String[] nums = str.split(" ");

				double a = Double.parseDouble(nums[0]);
				double b = Double.parseDouble(nums[1]);
				double c = Double.parseDouble(nums[2]);
				double d = Double.parseDouble(nums[3]);
				double e = Double.parseDouble(nums[4]);
				double f = Double.parseDouble(nums[5]);
				
				double x = (e * c - b * f) / (a * e - b * d);
				double y = (a * f - d * c) / (a * e - b * d);
				if (x == -0.0) x = 0.0;
				if (y == -0.0) y = 0.0;
				System.out.printf("%.3f %.3f\n", x, y);
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    int mul4 = 0;
    int even = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if (a%4==0) mul4++;
        if (a%2==0) even++;
    }
    int b1 = n-even;
    int b2 = even-mul4;
    int b4 = mul4;
    if (b4+1>=b1+(b2>0)*1) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int maxm(int a, int b)
{
	if(a>b)
		return a;
	else
		return b;
}
int main()
{
	char s[102], i, n, max, v;
	while(~scanf("%d %s", &n, s))
	{
		v = 0;
		max = 0;
		for(i=0; i<n; i++)
		{
			if(s[i]=='I') v++;
			else v--;
			max = maxm(v, max);
		}
		printf("%d\n", max);
	}
}

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

using namespace std;

const int maxn = 5000 + 7;

int n, A, B, pos[maxn], dp[maxn], a[maxn], ans;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp" ,"r")) freopen("test.inp", "r", stdin);
    cin >> n >> A >> B;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    a[n + 1] = 1e15;
    for(int i = 1; i <= n + 1; i++)
    {
        dp[i] = 1e15;
        ans = 0;
        for(int j = i - 1; j >= 0; j--)
        {
            if(a[j] > a[i]) ans++;
            else
            {
                dp[i] = min(dp[i], dp[j] + ans * A + (i - j - 1 - ans) * B);
            }
        }
    }
    cout << dp[n + 1];
}

Measured memory_bytes: 512
import java.util.*;
public class Main { 
	static int[][] map;
	static int[] dp;
	static int INF = 1 << 24;
	static int n;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			n = stdIn.nextInt();
			if(n == 0) break;
			map = new int[n][n+1];
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n+1; j++) {
					map[i][j] = stdIn.nextInt();
				}
			}
			dp = new int[1 << n];
			Arrays.fill(dp, INF);
			dp[0] = 0;
			dp();
			System.out.println(dp[(1 << n)-1]);
			
		}
	}
	public static void dp() {
		
		for(int j = 0; j < (1 << n); j++) {
			if(dp[j] < INF) {
				for(int k = 0; k < n; k++) { //つぎはどこ
					if((j & (1 << (k))) == 0) {
						for(int l = 0; l < n; l++) {
							if(l == 0) {
								dp[(j | 1 << k)] = Math.min(dp[j | 1 << k], dp[j] + map[k][l]);
							}
							if((j & (1 << l)) != 0) {
								dp[(j | 1 << k)] = Math.min(dp[(j | 1 << k)], dp[j] + map[k][l+1]);
							}
						}
					}
				}
			}
		}
	}
}

Measured memory_bytes: 35560
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        Map<String, Map<Integer,Integer>> map = new TreeMap<>();
        
        for(int i = 0; i < N; i++){
            
            String S = sc.next();
            Map<Integer, Integer> map2 = map.get(S);
            if (map2 == null) {
                map2 = new TreeMap<>( (s1, s2) -> s2 - s1 );
                map.put(S, map2);
            }

            int P = sc.nextInt();
            map2.put(P, i+1);
        }
        
        for( String key : map.keySet() ){
            Map<Integer, Integer> m2 = map.get(key);
            for( int i : m2.keySet() ){
                System.out.println(m2.get(i));
            }
        }
    }
}


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

int main() {
  string t;
  cin >> t;
  int n = t.size();
  rep(i,n) if (t[i] == '?') t[i] = 'D';
  cout << t << endl;
}

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

int main(){

    int N, X;
    cin >> N >> X;
    vector<int> m(N);
    for(int i = 0; i < N; i++) cin >> m[i];

    int ans = N;
    X -= accumulate(m.begin(), m.end(), 0);
    int min_donut = *min_element(m.begin(), m.end());
    while(X >= min_donut){
        X -= min_donut;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
 
dp = [float("inf")] * (2 * 10000 + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if (i + a[j]) > 2 * 10000:
            dp[2 * 10000] = min(dp[2 * 10000], dp[i] + b[j])
            continue
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
 
ans = float('inf')
for j in range(h, 2 * 10000 + 1):
    ans = min(ans, dp[j])
print(ans)

Measured memory_bytes: 42844
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn func2(k: i64, memo: &Vec<i64>, memo2: &Vec<Vec<i64>>) -> i64 {
    if k == 0 {
        return 0;
    }
    let mut i = 1;
    while (1 << i) <= k {
        i += 1;
    }
    cmp::max(memo[i-1] + func2(k - (1 << (i-1)), memo, memo2), memo2[i-1][0])
}

fn func(k: i64, memo: &Vec<i64>, memo2: &mut Vec<Vec<i64>>) -> i64 {
    if k == 0 {
        return 0;
    }
    let mut i = 1;
    let mut tar = 2;
    while tar <= k {
        memo2[i][0] = cmp::max(memo2[i-1][0], memo2[i-1][1]);
        if (tar << 1) - 1 > k {
            memo2[i][1] = memo[i] + func2(k-tar, memo, memo2);
        } else {
            memo2[i][1] = memo[i] + memo2[i][0];
        }
        tar *= 2;
        i += 1;
    }
    cmp::max(memo2[i-1][0], memo2[i-1][1])
}

fn main() {
    let nk: Vec<i64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nk[0] as usize;
    let k = nk[1];
    let a: Vec<i64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut memo = vec![0i64; 60];

    for i in 0..60 {
        let mut p = 0i64;
        let mut q = 0i64;
        let tar = 1i64 << i;
        for j in 0..n {
            memo[i] += (a[j] ^ tar) - a[j];
        }
    }

    let sum = a.iter().fold(0, |acc, val| acc + val);

    let mut memo2 = vec![vec![0i64; 60]; 60];

    memo2[0][0] = 0;
    memo2[0][1] = memo[0];

    println!("{}", sum + func(k, &memo, &mut memo2));
}


Measured memory_bytes: 8444
/* minimum_spanning_tree_prim.cpp
    プリム法で最小全域木とそのコストを求める（隣接行列 向き）
    計算量: O(|E|log|V|)

    verified: AOJ ALDS1_12_A Minimum Spanning Tree
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_A&lang=jp
 */

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

vector<vector<int>> G;  // 隣接行列での表現

/* Prim : プリム法で minimum spanning tree を求める構造体
    入力: 隣接行列でのグラフ G
    最小全域木の重みの総和: sum
    計算量: O(|V|^2)
*/
struct Prim {
    const int INF = 1e9;
    int sum;              // MSTの重みの総和
    int n;                // 頂点数
    vector<int> mincost;  // 既に確定した頂点からの最小コスト（確定済みから行けない時は INF）
    vector<bool> used;    // 既に確定したかどうか
    Prim(vector<vector<int>> const& Graph) {
        init(Graph);
    }
    void init(vector<vector<int>> const& Graph) {
        n = (int)Graph.size();
        mincost.assign(n, INF);
        used.assign(n, false);
        sum = 0;
        mincost[0] = 0;  // 始め頂点0からスタートさせる
        while (true) {
            int v = -1;
            for (int u = 0; u < n; u++) {  // コストが最小で行ける頂点 v を探す
                if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
            }
            if (v == -1) break;  // MST ができたので終了
            used[v] = true;
            sum += mincost[v];
            for (int u = 0; u < n; u++) {  // 確定した頂点から行ける頂点について、最小コストを更新
                if (Graph[v][u] != -1) mincost[u] = min(mincost[u], Graph[v][u]);
            }
        }
    }
};

int main() {
    int n;
    cin >> n;
    G.assign(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> G[i][j];
        }
    }
    Prim prim(G);
    cout << prim.sum << endl;
    return 0;
}



Measured memory_bytes: 3168