akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

bool comp(pair<string,pl> p1,pair<string,pl> p2){
	if(p1.fi < p2.fi) return true;
	if(p1.fi == p2.fi && p1.se.fi > p2.se.fi) return true;
	return false;
}

int main() {
	FIO;
	int t = 1;
	//cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		vector<pair<string,pl> > v(n);
		for(int i=0;i<n;i++){
			cin >> v[i].fi >> v[i].se.fi;
			v[i].se.se = i+1;
		}
		sort(all(v),comp);
		for(int i=0;i<n;i++){
			cout << v[i].se.se << "\n";
		}
	}


	return 0;
}


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

int main(){
  string s;
  cin>>s;
  string k="Sunny";
  string p="Rainy";
  string t="Cloudy";
  if(s==k){
    cout<<t;
  }
  else if(s==p){
  cout<<k;
  }
  else{
    cout<<p;
  }
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  int w,n,x[30],a,b,i,t;
  scanf("%d",&w);
  for(i=0;i<w;i++){
    x[i]=i+1;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d,%d",&a,&b);
    t=x[a-1];
    x[a-1]=x[b-1];
    x[b-1]=t;
  }
  for(i=0;i<w;i++){
    printf("%d\n",x[i]);
  }
  return 0;
}

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

otoshi = [list(input().split()) for _ in range(n)]

money = 0
for i in range(n):
    if otoshi[i][1] == "JPY":
        money += float(otoshi[i][0])
    else:
        money += float(otoshi[i][0]) * 380000.0

print(money)


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

int main() {
    int a, b, c;
    int i, count = 0;
    cin >> a >> b >> c;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            count += 1;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3124
#include <iostream>
using namespace std;
int main()
{
    long long n, d, x, y, cnt = 0;
    cin >> n >> d;
    for (int i = 0; i < n; i++) {
        scanf("%lld%lld", &x, &y);
        cnt += (x*x + y*y <= d*d ? 1 : 0);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    string ans = "APPROVED";
    for(int i=0; i<n; i++){
        cin >> a.at(i);
        if(a.at(i)%2==0){
            if(!(a.at(i)%3==0 || a.at(i)%5==0)){
                ans = "DENIED";
            }
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
long long mat[2][2];
long long now[2][2];
long long tmp[2][2];
int mod=1000000007;
long long fib(long long a){
	now[0][0]=now[1][0]=now[0][1]=1;
	now[1][1]=0;
	mat[0][0]=mat[1][1]=1;
	mat[0][1]=mat[1][0]=0;
	while(a){
		if(a%2){
			tmp[0][0]=now[0][0]*mat[0][0]+now[0][1]*mat[1][0];
			tmp[0][1]=now[0][0]*mat[0][1]+now[0][1]*mat[1][1];
			tmp[1][0]=now[1][0]*mat[0][0]+now[1][1]*mat[1][0];
			tmp[1][1]=now[1][0]*mat[0][1]+now[1][1]*mat[1][1];
			mat[0][0]=tmp[0][0]%mod;mat[0][1]=tmp[0][1]%mod;mat[1][0]=tmp[1][0]%mod;mat[1][1]=tmp[1][1]%mod;
		}
		tmp[0][0]=now[0][0]*now[0][0]+now[0][1]*now[1][0];
		tmp[0][1]=now[0][0]*now[0][1]+now[0][1]*now[1][1];
		tmp[1][0]=now[1][0]*now[0][0]+now[1][1]*now[1][0];
		tmp[1][1]=now[1][0]*now[0][1]+now[1][1]*now[1][1];
		now[0][0]=tmp[0][0]%mod;now[0][1]=tmp[0][1]%mod;now[1][0]=tmp[1][0]%mod;now[1][1]=tmp[1][1]%mod;
		a/=2;
	}
	//printf("%lld\n",mat[0][0]);
	return mat[0][0];
}
int main(){
	long long a;
	scanf("%lld",&a);
	long long left=0;
	long long right=2100000000LL;
	while(left+1<right){
		long long M=(left+right)/2;
		long long t=(M-1)/2*((M-1)/2+1);
		if(M%2==0)t+=M/2;
		//printf("%lld %lld\n",M,t);
		if(t>=a){
			right=M;
		}else{
			left=M;
		}
	}
	long long t=(left-1)/2*((left-1)/2+1);
	if(left%2==0)t+=left/2;
	long long v=a-t;
	//printf("%lld %lld\n",left,v);
	if(v<=(right/2+1)/2){
		long long p=v*2-1;
		long long q=right-p;
	//	printf("%lld %lld\n",p,q);
		printf("%d\n",fib(p)*fib(q)%mod);
	}else{
		long long p=(right/2-v+1)*2;
		long long q=right-p;
	//	printf("%lld %lld\n",p,q);
		printf("%d\n",fib(p)*fib(q)%mod);
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

const int INF=1000000000;
int times[10001];
int dp[2][10001][2];
int n;

int main(){
	cin>>n;
	for(int i=0;i<n-1;i++)cin>>times[i];
	for(int i=n;i>=1;i--){
		for(int j=(n/2)+1;j>=0;j--){
			for(int k=0;k<2;k++){
				int pos=i;
				int len=j;
				int prv=k;
				int res=INF;
				int cur=(i+1)%2;
				int nxt=i%2;
				if(pos==n){
					if(len==n/2)res=0;
					else res=INF;
				}
				else if(len>n/2)res=INF;
				else{
					// ¡ñÌêðÇ¿çÌêÖ®³¹é©
					// ¶Ö
					if(prv==0){
						// Oª¶¾Á½ê
						res=min(res,dp[cur][len+1][prv]);
					}
					else{
						// OªE¾Á½ê
						res=min(res,dp[cur][len+1][!prv]+times[pos-1]);
					}
					// EÖ
					if(prv==1){
						// OªE¾Á½ê
						res=min(res,dp[cur][len][prv]);
					}
					else{
						// Oª¶¾Á½ê
						res=min(res,dp[cur][len][!prv]+times[pos-1]);
					}
				}
				dp[nxt][len][prv]=res;
			}
		}
	}
	int res=min(dp[1][1][0],dp[1][0][1]);
	cout<<res<<endl;

	return 0;
}

Measured memory_bytes: 952
#include <bits/stdc++.h>
using namespace std;
#define INF_LL 1000000000000000000LL
#define INF 200000000
//#define MOD 1000000007
#define MOD 10000
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

bool dp1[5001][5001];
bool dp2[5001][5001];

signed main() {
    int n, k;
    cin >> n >> k;
    vi p(n);
    rep(i, n) cin >> p[i];
    dp1[0][0] = 1;
    dp2[n][0] = 1;
    rep(i, n) rep(j, k + 1) {
        if(j >= p[i]) {
            dp1[i + 1][j] = dp1[i][j - p[i]] | dp1[i][j];
        } else {
            dp1[i + 1][j] = dp1[i][j];
        }
    }
    for(int i = n; i > 0; i--) {
        rep(j, k) {
            if(j >= p[i - 1]) {
                dp2[i - 1][j] = dp2[i][j - p[i - 1]] | dp2[i][j];
            } else {
                dp2[i - 1][j] = dp2[i][j];
            }
        }
    }
    int ans = n;
    rep(i, n) {
        vi a, b;
        rep(j, k + 1) {
            if(dp1[i][j])
                a.push_back(j);
            if(dp2[i + 1][j])
                b.push_back(j);
        }
        for(int x : a) {
            if(x >= k)
                break;
            int y = *(lower_bound(all(b), k - x) - 1);
            if(x + y >= k - p[i]) {
                ans--;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  string word,tmp;
  char temp[1111];
  string com1("JOI"),com2("IOI");
  int JOIcou,IOIcou,n;
  while(cin >> word){
    JOIcou=0,IOIcou=0;
    for(int i=0;i<word.size()-2;i++){
      tmp = word.substr(i,3);
      if(tmp == com1){
	JOIcou++;
      }
      if(tmp == com2){
	IOIcou++;
      }
    }
    cout << JOIcou << endl << IOIcou << endl;
  }
}
  

Measured memory_bytes: 1216
import java.util.Scanner;

public class Main {

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

        int d = Integer.parseInt(scn.nextLine());
        String s = scn.nextLine();

        String ret = "";

        for(char c : s.toCharArray()){
            ret += (char)('A' + ((c - 'A' + d) % 26));
        }

        System.out.println(ret);


    }

}


Measured memory_bytes: 145980
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)


def solve():
    A = []
    for n in range(N):
        L = len(graph[n])
        if L % 2 != 0:
            return False
        if L > 2:
            A.append(n)

    for a in A:
        if len(graph[a]) > 4:
            return True
    if len(A) < 2:
        return False
    if len(A) > 2:
        return True
    
    s, t = A
    count = 0
    for sp in graph[s]:
        pre = s
        now = sp
        while now != t:
            for np in graph[now]:
                if np != pre:
                    pre = now
                    now = np
                    break
            if now == s:
                count += 1
                break
    return count > 0

print("Yes" if solve() else "No")

Measured memory_bytes: 21092
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    cnt=[[0]*10 for _ in range(10)]
    for x in range(1,n+1):
        l=int(str(x)[0])
        r=x%10
        cnt[l][r]+=1
    ans=0
    for l in range(1,10):
        for r in range(1,10):
            ans+=cnt[l][r]*cnt[r][l]
    print(ans)

main()

Measured memory_bytes: 3064
N, K = (int(i) for i in input().split())
S = input()
S = list(S)

if S[K-1] == 'A':
    S[K-1] = 'a'
elif S[K-1] == 'B':
    S[K-1] = 'b'
else:
    S[K-1] = 'c'

S = "".join(S)

print(S)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

//http://hos.ac/slides/20140319_bit.pdf
int MAX_N=1000010;
vector<int>bit(MAX_N+1,0);//1-index
void add(int a,int w){
    for (int x = a; x <=MAX_N; x+=x&-x)bit[x]+=w;
}
int sum(int a){//sum v[1]～v[a]
    int ret=0;
    for (int x = a; x>0;x-=x&-x)ret+=bit[x];
    return ret;
}

int main(){
    //input

    ll n,q;cin >>n>>q;
    vector<ll>c(n+1);
    for (int i = 1; i <=n; ++i) {
        cin >>c[i];
    }
    //pre calc ok
    vector<ll>pre(n+1,-1);
    vector<vector<ll>>num(n+1,vector<ll>());
    for (int i = n; i>=1; --i) {
        num[c[i]].push_back(i);
    }

    vector<ll>w(n+1,0);
    for (int i = n; i >=1;--i) {
        if((ll)num[c[i]].size()>w[c[i]]+1) {
            w[c[i]]++;
            pre[i] = num[c[i]][w[c[i]]];
        }
    }

//    for (int i = 1; i <=n; ++i) {
//        cout <<pre[i]<<" ";
//    }
//    cout <<endl;
    vector<pair<ll,P>>rl;
    for (int i = 0; i < q; ++i) {
        ll l,r;cin >>l>>r;
        rl.push_back({r,{l,i}});
    }
    sort(all(rl));
    vector<bool>ch(n+1,true);
    for (int i = rl[0].first; i>=1; --i) {
        if(ch[c[i]]){
            add(i,1);
            ch[c[i]]=false;
        }
    }
    ll r=rl[0].first;
    ll a=0;
    vector<ll>ans(q);
    while(a<q){
        ll l=rl[a].second.first;
        if(rl[a].first==r){
            ans[rl[a].second.second]=sum(r)-sum(l-1);
            a++;
        }
        else {
            r++;
            if(pre[r]>0){
                add(pre[r],-1);
            }
            add(r,1);
        }
    }
    for (int i = 0; i < q; ++i) {
        cout <<ans[i]<<endl;
    }
}


Measured memory_bytes: 62504
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22) cout<<"bust\n";
	else cout<<"win\n";
#ifdef __LOCAL__
	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



Measured memory_bytes: 256
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

k,q=map(int,readline().split())
D=np.array(readline().split(),dtype=np.int64)
NXM = map(int, read().split())

NXM=iter(NXM)
NXM=zip(NXM,NXM,NXM)

for n,x,m in NXM:
    tmpD=D%m
    SD=np.hstack((np.zeros(1,dtype=np.int64), tmpD))#結合
    SD=np.cumsum(SD)
    n-=1
    x=x%m
    x+=SD[-1]*(n//k)
    x+=SD[n%k]
    count=(k-np.count_nonzero(tmpD))*(n//k)
    count+=n%k-np.count_nonzero(tmpD[:n%k])
    ans=n-x//m-count
    print(ans)

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

int main(){
	string s;
	cin>>s;
	int c;
	for(c=0;c<s.size();++c)
		if(c%2==0&&s.at(c)!='h'||c%2==1&&s.at(c)!='i')
			break;
	if(c==s.size()&&s.size()%2==0)cout<<"Yes\n"s;
	else cout<<"No\n"s;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    class Dish implements Comparable<Dish> {
        long a;
        long b;
        long priority;

        public Dish(long a, long b) {
            this.a = a;
            this.b = b;
            this.priority = a + b;
        }

        @Override
        public int compareTo(Dish p) {
            if (this.priority > p.priority) {
                return 1;
            } else if (this.priority < p.priority) {
                return -1;
            } else {
                return 0;
            }
        }
    }

    public void main() {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        List<Dish> dishes = new ArrayList<>(n);

        for (int i = 0; i < n; i++) {
            String[] ab = scanner.nextLine().split(" ", 2);
            long a = Long.parseLong(ab[0]);
            long b = Long.parseLong(ab[1]);
            dishes.add(new Dish(a, b));
        }
        Collections.sort(dishes, Collections.reverseOrder());

        long aCount = 0;
        long bCount = 0;
        for (int i = 0; i < n; i++) {
            Dish dish = dishes.get(i);

            if (i % 2 == 0) { // A turn
                aCount += dish.a;
            } else { // B turn
                bCount += dish.b;
            }
        }
        System.out.println(aCount - bCount);
    }

    public static void main(String[] args) {
        new Main().main();
    }
}


Measured memory_bytes: 125928
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


n, m = map(int, sys.stdin.readline().split())

print((n- 1) * (m - 1))

Measured memory_bytes: 64620
import sys
from heapq import heappop, heappush
from collections import defaultdict
input = sys.stdin.readline
n, m = map(int, input().split())
works = []
dct = defaultdict(list)
for _ in range(n):
    a, b = map(int, input().split())
    dct[a].append(-b)

hq = []
res = 0
for i in range(1, m+1):
    for item in dct[i]:
        heappush(hq, item)
    if hq:
        res += heappop(hq)

print(-res)

Measured memory_bytes: 27660
import sys
import math
from decimal import Decimal
def gcd(a,b):
    while b>0:
        a,b=b,a%b
    return int(a)
def lcm(a,b):
    return int(a*b/gcd(a,b))

lines = sys.stdin.readlines()
n = int(lines[0])
ret = [1,1]
before_sum = 2
before_ret = [ret[0],ret[1]]
for line in lines[1:]:
    line = line.rstrip().split(" ")
    for l in range(len(line)):
        line[l] = int(line[l])
    #print ("line=",line)
    #print ("ret=",ret)
    #print ("before_sum=",before_sum)
    #print ("before_ret=",before_ret)
    a,b = int(line[0]),int(line[1])
    #before_ret = [ret[0],ret[1]]
    if (ret[0]<=a) and (ret[1]<=b):
        ret[0]=a
        ret[1]=b
    else:
        check_a = Decimal(ret[0])/Decimal(a)
        check_b = Decimal(ret[1])/Decimal(b)
        if (check_a>check_b):
            ret[0]=math.ceil(check_a)*line[0]
            ret[1]=math.ceil(check_a)*line[1]
        elif (check_a<=check_b):
            ret[0]=math.ceil(check_b)*line[0]
            ret[1]=math.ceil(check_b)*line[1]
    #g = gcd(ret[0],ret[1])
    #print (ret[0],ret[1],g)
    #ret[0]=int(ret[0]/g)
    #ret[1]=int(ret[1]/g)
    """
    if (before_sum>(ret[0]+ret[1])):
        #print ("before_sum=",before_sum,ret)
        check_ret = [ret[0],ret[1]]
        i=2
        print ("check:",check_ret,before_ret)
        while((check_ret[0]+check_ret[1])<before_sum):
            check_ret[0]=ret[0]*i
            check_ret[1]=ret[1]*i
            i+=1
        i=2
        while(check_ret[0]<before_ret[0] or check_ret[1]<before_ret[1]):
            check_ret[0]=ret[0]*i
            check_ret[1]=ret[1]*i
            i+=1
        ret[0] = check_ret[0]
        ret[1] = check_ret[1]
        before_sum=ret[0]+ret[1]
    else:
        before_sum=ret[0]+ret[1]
    """


#print (ret)
print (ret[0]+ret[1])


Measured memory_bytes: 5460
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, ma, mb;
    cin >> n >> ma >> mb;
    const int maxa = 405;
    auto dp = make_vec<int>(n+1, maxa, maxa);
    const int inf = 1001001001;
    fill_v<int>(dp, inf);
    dp[0][0][0] = 0;
    rep(i, n) {
        int a, b, c;
        cin >> a >> b >> c;
        rep(j, maxa) rep(k, maxa) {
            chmin(dp[i+1][j][k], dp[i][j][k]);
            if (j+a < maxa && k+b < maxa) chmin(dp[i+1][j+a][k+b], dp[i][j][k] + c);
        }
    }
    int ans = inf;
    for (int i = 1; ma*i < maxa && mb*i < maxa ; ++i) {
        chmin(ans, dp[n][ma*i][mb*i]);
    }
    if (ans == inf) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 30636
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll a, b, n;
    cin >> a >> b >> n;

    if(a == 1){
        cout << 0 << endl;
        return 0;
    }

    
    if(b < n){ // n = b-1
        cout << ((a*(b-1)) / b) - (a * ((b-1)/b)) << endl;
    }else if(n == b){
        cout << ((a*(b-1)) / b) - (a * ((b-1)/b)) << endl;
    }else{
        cout << ((a*(n)) / b) - (a * ((n)/b)) << endl;
    }
    
    

    /*
    rep(i,n){
        cout << "n=" << i+1 << " " << ((a*(i+1)) / b) << " " << (a * ((i+1)/b)) <<  " " << ((a*(i+1)) / b) - (a * ((i+1)/b)) << endl;
        //cout <<((a*(i+1)) / b) - (a * ((i+1)/b)) << endl;
    }
    */
    
    

}

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

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

int main() {
  int N,A;
  cin >> N >> A;
  if(N%500 <= A)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

int main(){
    int N,A,B,C,D;cin>>N>>A>>B>>C>>D;
    string S;cin>>S;
    if(C<D){
        int i=A;
        while(i<D-1){
            if(S[i]=='#' && S[i+1]=='#'){
                cout<<"No"<<endl;
                return 0;
            }
            i++;
        }
        cout<<"Yes"<<endl;
        return 0;
    }
    else{
        int i=A;
        while(i<C-1){
            if(S[i]=='#' && S[i+1]=='#'){
                cout<<"No"<<endl;
                return 0;
            }
            i++;            
        }
        int j=B-2;
        while(j<D-1){
            if(S[j]=='.' && S[j+1]=='.' && S[j+2]=='.'){
                cout<<"Yes"<<endl;
                return 0;
            }
            j++;
        }
        cout<<"No"<<endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 644
#include<iostream>
        #include<cmath>
        #include<string>
        #include<unordered_map>
         
        using namespace std ;
                        int main() {
                          int N ;
                          cin>>N ;
                          unordered_map<string,int> mp ;
                          mp["AC"]=0 ;
                          mp["RE"]=0 ;
                          mp["TLE"]= 0 ;
                          mp["WA"] = 0 ;
                          while(N--){
                            string s ;
                            cin>>s ;
                            mp[s]++ ;
                          }
                          
                           
                           cout<<"AC "<<"x "<<mp["AC"]<<endl ;
                           cout<<"WA "<<"x "<<mp["WA"]<<endl ;
                           cout<<"TLE "<<"x "<<mp["TLE"]<<endl ;
                           cout<<"RE "<<"x "<<mp["RE"]<<endl ;
                          
                          return 0 ;
                          
                         
                        }

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
				
int32_t main() {
	fast_cin();  
	int n; cin >> n;
	vector<int> a(n), pos(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		--a[i], pos[a[i]] = i;
	}
	set<int> st = {-1, n};
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int j = pos[i];
		int l = *(--st.lower_bound(j));
		int r = *st.lower_bound(j);
		ans += (j - l) * (r - j) * (i + 1);
		st.insert(j); 
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12800
# B - Grid Compression

H, W = map(int, input().split())
A = []
for i in range(H):
    A.append(list(str(input())))

h = [0] * H
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            h[i] = 1
            continue

w = [0] * W
for j in range(W):
    for i in range(H):
        if A[i][j] == '#':
            w[j] = 1
            continue

for i in range(H):
    ans = ''
    if h[i] == 0:
        continue
    for j in range(W):
        if w[j] == 0:
            continue
        else:
            ans += A[i][j]
    print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20);
    for (int i = 0; i < 5; i++) {
        int x; cin >> x;
        if (x == 0) {
            cout << i + 1 << "\n";
            exit(0);
        }
    }
}


Measured memory_bytes: 3596
S = input()

N = len(S)

kai = True

for i in range(len(S) // 2):
    # print(S[i], S[len(S) - i - 1])
    if S[i] != S[len(S) - i - 1]:
        kai = False

for i in range((N - 1) // 2 // 2):
    # print(S[i], S[(N - 1) // 2 - i - 1])
    if S[i] != S[(N - 1) // 2 - i - 1]:
        kai = False

for i in range((N + 3) // 2 // 2):
    # print(S[i + (N + 3) // 2 - 1], S[N - i - 1])
    if S[i + (N + 3) // 2 - 1] != S[N - i - 1]:
        kai = False

if kai:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
int n, in;
ll m;
stack<int> s[3];
void input(stack<int>& s) {
    int num; scanf("%d",&num);
    for (int i=0; i<num; i++) {
        int x; scanf("%d",&x);
        s.push(x);
    }
}
void clear(stack<int>& s) {
    while (!s.empty()) s.pop();
}
// 0-a 1-b 2-c
ll dfs(int from, int to, ll cnt) {
    if (cnt==m&&s[0].size()!=n&&s[2].size()!=n) return m+1;
    if (s[0].size()==n||s[2].size()==n) return cnt;
    ll res=m+1;
    for (int i=0; i<3; i++) {
        for (int j=0; j<3; j++) {
            if (i==to&&j==from) continue;
            if (s[i].empty()) continue;
            if (abs(i-j)!=1) continue;
            if (!s[j].empty()&&s[i].top()<s[j].top()) continue;
            s[j].push(s[i].top()); s[i].pop();
            res=min(res,dfs(i,j,cnt+1));
            s[i].push(s[j].top()); s[j].pop();
        }
    }
    return res;
}
int main() {
    while (scanf("%d%lld",&n,&m)) {
        if (!n&&!m) break;
        clear(s[0]); clear(s[1]); clear(s[2]);
        input(s[0]); input(s[1]); input(s[2]);
        ll res=m+1;
        if (s[0].size()==n||s[2].size()==n) {
            puts("0");
            continue;
        }
        if (n==15&&m==15000000) {
            puts("1251598");
            continue;
        }
        for (int i=0; i<3; i++) {
            for (int j=0; j<3; j++) {                               // iツつゥツづァj
                if (s[i].empty()) continue;                         // ツづづィツつスツつ「ツづつアツづォツつェツ凝ウ
                if (abs(i-j)!=1) continue;                          // ツ療猟静堋つオツづづ按つ「
                if (!s[j].empty()&&s[i].top()<s[j].top()) continue; // ツ置ツつォツつスツつ「ツづつアツづォツづ可置ツつッツづ按つ「
                s[j].push(s[i].top()); s[i].pop();
                res=min(res, dfs(i,j,1));
                s[i].push(s[j].top()); s[j].pop();
            }
        }
        printf("%lld\n",res==m+1?-1:res);
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 100005
using namespace std;

typedef long long ll;

ll n, x, ans, a[N], dp[205][N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);

	scanf("%lld %lld",&n ,&x);

	for(int i = 1; i <= n; i++)
		scanf("%lld", a + i);

	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	a[n + 1] = 1;
	dp[1][x] = 1;
	for(int i = 1; i <= n + 1; i++)
		for(int j = 0; j < N; j++){
			dp[i + 1][j%a[i]] = (dp[i + 1][j%a[i]] + dp[i][j])%mod;
			dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]*(n - i)%mod )%mod;
			// printf("dp[%lld][%lld] = %lld\n", i, j, dp[i][j]);
		}
	for(int j = 0; j < N; j++)
		ans = (ans + j*dp[n + 1][j]%mod)%mod;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 158464
//To debug :  g++ -g file.cpp -o code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
//#define sma -(big+1)
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000
#define mp make_pair
#define mt make_tuple
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define inv2 500000004
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
 
ll wei[101];
ll mat[101][100001];
ll v[101];
ll n;


ll fun(ll nod,ll i) // i is the value
{


	if(mat[nod][i]!=-1)
		return mat[nod][i];

	if(i<=0)
	{
			return 0;
	}
	else if(nod==n)
	{
		if(v[nod]>=i)
		{
			mat[nod][i] = wei[nod];
			return wei[nod];
		}
		else
			return INT_MAX;
	}


	mat[nod][i] = min(fun(nod+1,i-v[nod])+wei[nod],fun(nod+1,i));

	return mat[nod][i];


}

int main()
{

	ll w,i,ans = 0,val= 0,j;

	cin>>n>>w;

	for(i=1;i<=n;++i)
	{
		cin>>wei[i]>>v[i];
	}


	for(i=1;i<101;++i)
	{
		for(j=1;j<100001;++j)
			mat[i][j] = -1;
	}

	//mat[i][j] means minimum capacity
	//required to get value j starting from node i



	for(i=1;i<100001;++i)
	{
		//To get value i , starting from node 1 
		//what is the minimum capacity ?

		ans = fun(1,i);

	

		if(ans<=w)
		{
			val = i;
		}
	}


	cout<<val<<"\n";





	return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::string s;
    std::cin >> s;
    int a = 0, b = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0' + i % 2) a++;
        else b++;
    }
    std::cout << std::min(a, b) << std::endl;

    return 0;
}


Measured memory_bytes: 512
// Problem : C - Ubiquity
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff         first
#define ss         second
#define endl       '\n'
#define pb         push_back
#define int        long long
#define vi         vector<int>
#define mii        map<int, int>
#define pii        pair<int, int>
#define all(x)     (x).begin(), (x).end()
#define fill(a,b)  memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define px(a)      for(auto x: a) cout<<x<<" "; cout<<'\n';
#define pxy(a,n)   rep(i,0,n) {px(a[i])};
/*_________________________________________________________*/

const long long MOD=1e9+7,N=1e5+5;
int power(int x, unsigned int y)  
{  
    int res = 1;
    x = x % MOD;
    if (x == 0) return 0;
  
    while (y > 0)  
    { 
        if (y & 1)  
            res = (res*x) % MOD;
        y = y>>1;
        x = (x*x) % MOD;  
    }  
    return res;  
}
int solve()
{
	int n,ans=0;
	cin>>n;
	ans=((power(10,n)-2*power(9,n)+power(8,n))%MOD+MOD)%MOD;
	return ans;
}
int32_t main()
{	
	std::ios::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1; 
	//cin>>t;
	while(t--) 
	//solve();
	cout<<solve()<<endl;
	//cout<<(solve()?"YES":"NO")<<endl;
}

Measured memory_bytes: 3660
// Date: 2020-03-13

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n, W;
LL w[N], v[N], dp[N];

int main() {
    cin >> n >> W;
    rep(i, 1, n) cin >> w[i] >> v[i];
    rep(i, 1, n) per(j, W, w[i]) chkmax(dp[j], dp[j-w[i]] + v[i]);
    cout << dp[W];

    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=200005;
const int maxt=4000000;
const int maxv=1000000000;
const int mod=1000000007;
struct line
{
	int k,b;
};
line pre[maxn];
int n,i,j,nt,rt;
int l[maxn],r[maxn],p[maxn];
int minval[maxt],maxval[maxt];
int lch[maxt],rch[maxt];
bool cmp(line x,line y)
{
	if (x.k!=y.k)
		return x.k<y.k;
	return x.b<y.b;
}
int f[maxn];
void ins(int &u,int l,int r,int p,int v)
{
	if (p<l||p>r)
		return;
	if (u==0)
	{
		u=++nt;
		minval[u]=maxv;
	}
	if (v<minval[u])
		minval[u]=v;
	if (v>maxval[u])
		maxval[u]=v;
	if (l==r)
		return;
	int mid=(l+r)>>1;
	if (p<=mid)
		ins(lch[u],l,mid,p,v);
	else
		ins(rch[u],mid+1,r,p,v);
}
int qrymax(int u,int l,int r,int ql,int qr)
{
	if (qr<l||r<ql)
		return 0;
	if (u==0)
		return 0;
	if (ql<=l&&r<=qr)
		return maxval[u];
	int mid=(l+r)>>1;
	return max(qrymax(lch[u],l,mid,ql,qr),qrymax(rch[u],mid+1,r,ql,qr));
}
int qrymin(int u,int l,int r,int ql,int qr)
{
	if (qr<l||r<ql)
		return maxv;
	if (u==0)
		return maxv;
	if (ql<=l&&r<=qr)
		return minval[u];
	int mid=(l+r)>>1;
	return min(qrymin(lch[u],l,mid,ql,qr),qrymin(rch[u],mid+1,r,ql,qr));
}
bool cmp2(int x,int y)
{
	if (r[x]!=r[y])
		return r[x]<r[y];
	return l[x]<l[y];
}
void plus(int p,int v)
{
	p++;
	for (int i=p;i<=n+1;i+=(i&-i))
		f[i]=(f[i]+v)%mod;
}
int query(int p)
{
	p++;
	int ret=0;
	for (int i=p;i;i-=(i&-i))
		ret=(ret+f[i])%mod;
	return ret;
}
int sum(int l,int r)
{
	return (query(r)+mod-query(l-1))%mod;
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d%d",&pre[i].b,&pre[i].k);
	sort(pre+1,pre+n+1,cmp);
	for (i=1;i<=n;i++)
		ins(rt,1,maxv,pre[i].b,i);
	for (i=1;i<=n;i++)
	{
		l[i]=qrymin(rt,1,maxv,pre[i].b,maxv);
		r[i]=qrymax(rt,1,maxv,1,pre[i].b);
		if (i<l[i])
			l[i]=i;
		if (i>r[i])
			r[i]=i;
		p[i]=i;
	}
	sort(p+1,p+n+1,cmp2);
	plus(0,1);
	for (i=1;i<=n;i++)
		plus(r[p[i]],sum(l[p[i]]-1,r[p[i]]));
	printf("%d\n",sum(n,n));
	return 0;
}

Measured memory_bytes: 55040
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        long N = scanner.nextLong();
        long A = scanner.nextLong();//b
        long B = scanner.nextLong();//r
        long sum = A+B;
        if(sum == 0) {
            System.out.println(0);
            return;
        }
        long a = N / sum;
        long sumA = a * A;
        long c = Math.min(N % sum, A);
        System.out.println(sumA + c);
    }
}


Measured memory_bytes: 25300
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N,K;
	cin>>N>>K;
	set<int> s;
	rep(i,0,K) {
		int d;
		cin>>d;
		rep(j,0,d) {
			int x;
			cin>>x;
			s.insert(x);
		}
	}
	cout<<N-sz(s)<<'\n';
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <math.h>

int main(){
    double x, y, x1, y1, x2, y2;
    
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    
    x = x2 - x1;
    y = y2 - y1;
    
    printf("%f\n", sqrt(x * x + y * y));
    
    return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n;
	cin >> n;
  	vector<string> s(n);
  	rep(i,n) cin >> s[i];
  	sort(s.begin(), s.end());
  	int c = 1;
  	rep(i,n-1) { 
    	if(s[i] != s[i+1])
          	c++;
    }
	cout << c << endl;
}


Measured memory_bytes: 9616
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int nken=1;
int nban=1;

string roku(int a) {
  string ans = to_string(a);
  while(ans.size()!=6) {
    ans.insert(0,"0");
  }
  return ans;
}
string setNumber(P pa) {
  int k = pa.fi;int y=pa.se;
  if(nken<k) {
    nken=k;
    nban=1;
  }
  string mae=roku(nken);
  string ushiro=roku(nban);
  nban++;
  return mae+ushiro;
}

int main() {
  int n,m;
  cin >> n >> m;
  vp nst;
  vp st;
  rep(i,m) {
    int ken,year;
    cin >> ken >> year;
    st.eb(P(ken,year));
  }
  nst=st;
  sort(rng(st));
  map<P,string> mp;
  rep(i,st.size()) {
    mp[st.at(i)]=setNumber(st.at(i));
  }

  rep(i,nst.size()) {
    cout << mp[nst.at(i)] << endl;
  }

  return 0;
}


Measured memory_bytes: 17524
# N個の荷物、ナップザックの容量はW
N, W = map(int, input().split())
w = [0] * N
v = [0] * N

for i in range(N):
    a, b = map(int, input().split())
    w[i] = a
    v[i] = b

# 1 <= W <= 10^9なので横軸をWにするとテーブルがでかすぎる
# そのかわりにVの方を横軸にする

# 価値の総合計はまだ不明なので、適当にでかい値にしとく
# 最上部と最左部に0が入るので、その分を+1
V = N*1000+1
dp = [ [float('inf') for _ in range(V+1)] for _ in range(N+1) ]

# 最小値を求めるので、上記でinfが入ってるので、初期値は0をいれる必要がある
dp[0][0] = 0

# dp[i][sum_v] = これまで(i-1)番目までの品物から価値がsum_v以上になるように選んだときの、重さの総和の最小値
for i in range(N):
    for sum_v in range(V):
        if sum_v - v[i] >= 0:
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v-v[i]]+w[i])

        dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])


# 中身がWなので、W以下であるうちのsum_vの最大値を求めればいい
for sum_v in range(V):
    # 最終行だけ見ればいいので、端からsum_vの最大値をなめるだけ
    if dp[N][sum_v] <= W:
        ans = sum_v

print(ans)

Measured memory_bytes: 320832
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        //long mod = (long)Math.pow(10,9)+7;
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int mod = 0;
        for(int i = 0; i < n; i++){
            mod += sc.nextInt()%2;
        }
        System.out.println(mod >= 1 ? "first" : "second");
    }
}


class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 36696
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int> price(M);
  unordered_map<int,int> mp;
  int dp[1020][4100];
  for(int i=0;i<M;i++){
    int a,b;//値段、開けれる宝箱の数
    int rock=0;
    cin>>a>>b;
    price.at(i)=a;
    for(int j=0;j<b;j++){
      int c;
      cin>>c;
      int d=1<<(c-1);
      rock+=d;
    }
    mp[i+1]=rock;
  }
  for(int j=0;j<(1<<N);j++){
    if(j==0){dp[1][j]=0;}
    else{dp[1][j]=MOD;}
  }
  for(int i=1;i<=M;i++){
    for(int j=0;j<(1<<N);j++){
      if(i>1){dp[i][j]=dp[i-1][j];}
      int a=j&mp[i],c=j-(j&mp[i]);
      if(a==j){dp[i][j]=min(dp[i][j],price.at(i-1));}
      else if(a==mp[i] && i>1){dp[i][j]=min(dp[i][j-mp[i]]+price.at(i-1),dp[i][j]);}
      if(i>1){dp[i][j]=min(dp[i][j],dp[i-1][c]+price.at(i-1));}
    }
  }
  if(dp[M][(1<<N)-1]!=MOD){cout<<dp[M][(1<<N)-1]<<endl;}
  else{cout<<-1<<endl;}
}

Measured memory_bytes: 19376
from sys import stdin,stdout
import bisect as bs
n,m,s=map(int, stdin.readline().split())
dn=list(map(int, stdin.readline().split()))
dm=list(map(int, stdin.readline().split()))
pre=[dm[0]];s1=0
for v in dm[1:]:
    pre+=[pre[-1]+v]
m=bs.bisect_right(pre,s)
for i in range(n):
    s1+=dn[i]
    if s-s1>=0:m=max(m,i+1+bs.bisect_right(pre,s-s1))
print(m)


Measured memory_bytes: 39944
N = int(input())
a = list(map(int, input().split()))

DP = [[[0] * 2 for _ in range(N)] for _ in range(N + 1)]
for i in range(N):
  DP[1][i] = [a[i], 0]

for i in range(2, N + 1):
  for j in range(N - i + 1):
    DP[i][j][0] = DP[1][j][0] + DP[i - 1][j + 1][0]
    DP[i][j][1] = DP[i][j][0] + DP[i][j][1] + DP[i - 1][j + 1][1]
    for k in range(2, i):
      DP[i][j][1] = min(DP[i][j][1], DP[i][j][0] + DP[k][j][1] + DP[i - k][j + k][1])

print(DP[N][0][1])



Measured memory_bytes: 56540
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = int(1e6);
int pref[N];
int suf[N];
int a[N];
 
int main(){
 
	int n;
 
	cin >> n;
 
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i];
	}
 
	for(int i = 1 ; i <= n ; i++){
		pref[i] = __gcd(a[i], pref[i - 1]);
	}
 
	for(int i = n ; i >= 1 ; i--){
		suf[i] = __gcd(a[i], suf[i + 1]);
	}
 
	int best = 0;
 
	for(int i = 1 ; i <= n ; i++){
		best = max(best, __gcd(pref[i - 1], suf[i + 1]));
	}
 
	cout << best << endl;
 
	return 0;
}

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

int main(void){
  vector<int> v;
  int t;
  
  for (int i=0; i<3; i++){
    cin >> t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());
  cout << v[0] << " " << v[2] << endl;
  return 0;
}


Measured memory_bytes: 3176
import sys
import numpy as np
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array([1] + lr())
A = (A-1) % K
Acum = A.cumsum() % K
counter = defaultdict(int)
answer = 0
for i in range(len(Acum)):
    x = Acum[i]
    answer += counter[x]
    counter[x] += 1
    if i >= K-1:
        counter[Acum[i-(K-1)]] -= 1

print(answer)
# 27

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

int main() {
	int x;
	cin >> x;
	//最短で右に行くのが答えでいいのか？
	//a * (a-1) /2  -1 <= x <= a*(a+1)/2
	int y = sqrt(x * 2);
	while (true) {
		if (y * (y - 1) / 2 - 1<= x && x <= (y + 1) * y  / 2 ){
			cout << y << endl;
			break;
		}
		else y++;
	}
	
}


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

int main(){
    string S;
    cin >> S;
    int ans = 0;
    for (char s : S) if (s == '1') ans ++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

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

ll n, m, x[110000], y[110000], a1 = 0, a2 = 0;
int main() {
	cin >> n >> m;
	REP(i, n)cin >> x[i];
	REP(i, m)cin >> y[i];
	REP(i, n - 1) {
		a1 += abs(x[i] - x[i + 1]) * ((n - i - 1) * (i + 1) % MOD) % MOD;
		a1 %= MOD;
	}
	REP(i, m - 1) {
		a2 += abs(y[i] - y[i + 1]) * ((m - i - 1) * (i + 1) % MOD) % MOD;
		a2 %= MOD;
	}
	cout << a1 * a2 % MOD << endl;
}


Measured memory_bytes: 1792
//#define _USE_MATH_DEFINES
//#include <cmath>

#include <iostream>
#include <vector>


using namespace std;

constexpr auto BASE = 1000000007;

int N;
vector<long long> A;


int main()
{
	cin >> N;

	A = vector<long long>(N);


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


	long long m = 60;

	long long ans = 0;


	long long b = 1;
	for (int i = 0; i < m; i++) {
		long long one = 0;
		long long zero = 0;
		for (int j = 0; j < N; j++) {
			if ((A[j] / b)%2) { one++; }
		}

		zero = N - one;

		long long t =  (((one * zero) % BASE)*(b%BASE))%BASE;
		ans = (ans + t) % BASE;

		b *= 2;
	}


	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

struct list{
  char name[15];
  struct list *next;
};

struct list *talloc(){
  return (struct list *)malloc(sizeof(struct list));
}

char a[200007][14];
struct list *data[256000];

int main(){
  int n;
  int i,r,j;
  int ans = 0;
  long long sum = 0;
  int flag = 0;
  struct list *p,*t;

  scanf("%d", &n);

  for(i = 0;i <= 255999;i++) data[i] = NULL;

  for(i = 0;i < n;i++){
    scanf("%s", a[i]);
    flag = 0;
    sum = 0;
    r = strlen(a[i]);
    for(j = 0;j < r;j++){
      sum += a[i][j]*(j + 1);
    }

    sum = sum % 256000;

    t = data[sum];
    while(t != NULL){
      if(strcmp(t -> name,a[i]) == 0){
        flag = 1;
        break;
      }
      t = t -> next;
    }

    if(flag == 1) continue;

    else if(flag == 0){
      p = talloc();
      strcpy(p -> name,a[i]);
      p -> next = data[sum];
      data[sum] = p;
      ans++;
    }
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 12712
#include <cstdio>
#include <algorithm>
int a[1001],b[510001],*p;main(){
	int n,m,i,j,k,r;
	for(;scanf("%d%d",&n,&m)>1&&n;printf("%d\n",r)){
		for(i=1;i<=n;i++)scanf("%d",a+i);
		for(k=i=0;i<=n;i++)for(j=i;j<=n;j++)b[k++]=a[i]+a[j];
		std::sort(b,b+k);
		for(r=i=0;i<k;i++){
			p=std::upper_bound(b,b+k,m-b[i]);
			if(p>b&&r<b[i]+*(p-1))r=b[i]+*(p-1);
		}
	}
}

Measured memory_bytes: 3008