akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const ll MOD = 754567754456479;
const int N=30001;

int n;
bitset<1000> b1, b2, b3;
string s;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> s;
  FOR(i, 0, n){
    int c = s[i]-'0';
    b3 |= b2<<(100*c);
    b2 |= b1<<(10*c);
    b1.set(c);
  }
  cout << b3.count() << endl;
}

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


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

    if(K > (N-1)*(N-2)/2){
        cout << "-1" << endl;
        return 0;
    } 

    vector<pair<int,int>> edge;
    rep(i, N-1) edge.push_back(make_pair(1, i+2));

    int from = 2, to = 3;
    rep(i, (N-1)*(N-2)/2 - K){
        if(to == N+1) {from++; to = from+1;}

        edge.push_back(make_pair(from, to));
        to++;
    }   

    cout << edge.size() << endl;
    rep(i, edge.size()){
        cout << edge[i].first << " " << edge[i].second << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
int main() {
int n,d;
cin >> n;
d = n%10;
if((d==2)||(d==4)||(d==5)||(d==7)||(d==9)){
cout << "hon" << endl;
}
else if((d==0)||(d==1)||(d==6)||(d==8)){
cout << "pon" << endl;
}
else cout << "bon" << endl;
return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <set>

class UnionFind {
	std::vector<int> vec;
public:
	UnionFind(int size) : vec(size, -1) {};
	int find(int a) {
		return vec[a] < 0 ? a : vec[a] = find(vec[a]);
	}
	bool same(int a, int b) {
		return find(a) == find(b);
	}
	int size_of(int a) {
		return -vec[find(a)];
	}
	void unite(int a, int b) {
		a = find(a); b = find(b);
		if (a != b) {
			if (vec[a] > vec[b]) std::swap(a, b);
			vec[a] += vec[b];
			vec[b] = a;
		}
	}
};
struct Bridge {
	int to, time;
};
struct Bidirect {
	int a, b, time;
};
int main() {
	int n, m, t; std::cin >> n >> m >> t;
	std::vector<Bidirect> bridges(m);
	std::vector<std::vector<Bridge>> islands(n);
	for (auto& bridge : bridges) {
		std::cin >> bridge.a >> bridge.b >> bridge.time;
		--bridge.a; --bridge.b;
		islands[bridge.a].push_back(Bridge{ bridge.b, bridge.time });
		islands[bridge.b].push_back(Bridge{ bridge.a, bridge.time });
	}
	std::vector<int> depth(n, INT_MAX); depth[0] = 0;
	std::queue<int> queue; queue.push(0);
	while (!queue.empty()) {
		const auto top = queue.front(); queue.pop();
		for (const auto bridge : islands[top]) if (bridge.time > depth[top] && depth[bridge.to] == INT_MAX) {
			depth[bridge.to] = depth[top] + 1;
			queue.push(bridge.to);
		}
	}
	std::vector<long long int> sum_score(n, 0);
	std::vector<int> last_changed(n, t), max_position(n); std::iota(max_position.begin(), max_position.end(), 0);
	std::sort(bridges.rbegin(), bridges.rend(), [](const Bidirect a, const Bidirect b) {return a.time < b.time; });
	UnionFind uft(n);
	for (const auto bridge : bridges) {
		if (uft.same(bridge.a, bridge.b)) continue;
		const auto a_max = max_position[uft.find(bridge.a)];
		const auto b_max = max_position[uft.find(bridge.b)];
		const long long int a_max_size = uft.size_of(bridge.a);
		const long long int b_max_size = uft.size_of(bridge.b);
		sum_score[a_max] += a_max_size * (last_changed[a_max] - bridge.time);
		sum_score[b_max] += b_max_size * (last_changed[b_max] - bridge.time);
		if (depth[a_max] > t) sum_score[a_max] = 0;
		if (depth[b_max] > t) sum_score[b_max] = 0;
		uft.unite(bridge.a, bridge.b);
		const auto new_root = uft.find(bridge.a);
		if (sum_score[a_max] > sum_score[b_max]) {
			max_position[new_root] = a_max;
			last_changed[a_max] = bridge.time;
		}
		else {
			max_position[new_root] = b_max;
			last_changed[b_max] = bridge.time;
		}
	}
	for (auto i = 0; i < n; ++i) {
		const auto max = max_position[uft.find(i)];
		sum_score[max] += uft.size_of(max) * (last_changed[max] - 0LL);
		if (depth[max] > t) sum_score[max] = 0;
		last_changed[max] = 0;
	}
	std::cout << *std::max_element(sum_score.begin(), sum_score.end()) << std::endl;
}



Measured memory_bytes: 16268
def run(N, A, B, C):
    ret = 0
    for i in range(N):
        if A[i] == B[i] and B[i] != C[i]:
            ret += 1
        elif A[i] != B[i] and B[i] == C[i]:
            ret += 1
        elif A[i] == C[i] and A[i] != B[i]:
            ret += 1
        elif A[i] == B[i] and B[i] == C[i]:
            pass
        else:
            ret += 2
    return ret


def main():
    N = int(input())
    A = input()
    B = input()
    C = input()
    print(run(N, A, B, C))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**9)

N,M=map(int,input().split())
graph=[[] for _ in range(N)]

for _ in range(M):
  l,r,d=map(int,input().split())
  l,r=l-1,r-1
  graph[l].append([r,d])
  graph[r].append([l,-d])

def BFD(x):
  global checked,answer,graph
  checked[x]=1
  for i,distance in graph[x]:
    if answer[i]=="first":
      answer[i]=answer[x]+distance
    else:
      if answer[i]!=answer[x]+distance:
        print("No")
        exit()
    
    if checked[i]==0:
      BFD(i)

checked=[0]*N
answer=["first"]*N

for i in range(N):
  if checked[i]==0:
    answer[i]=0
    BFD(i)

print("Yes")

Measured memory_bytes: 136020
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.IOException;
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;
 
public class Main {
    public static void main(String[] args) throws IOException {
         
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int n = Integer.parseInt(br.readLine());
        Set<String> set = new HashSet<String>();
        for(int i = 0; i < n; ++i){
            String[] line = br.readLine().split(" ");
            if(line[0].charAt(0) == 'i')
                set.add(line[1]);
            else
                System.out.println(set.contains(line[1]) ? "yes" : "no");
        }
    }
}


Measured memory_bytes: 191244
#include<bits/stdc++.h>
#define ll long long int
#define mod 10000007
#define pb push_back
#define ru(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define mp make_pair
#define inp(a,n) ru(i,n){cin>>a[i];}
using namespace std;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll po(ll a,ll b,ll m)
{	a%=m;
	ll res=1;
	while(b>0)
	{if(b&1)
	res=(res*a)%m;
	a=(a*a)%m;
	b>>=1;}
	return res;
}
int main()
{
	int t;
	//cin>>t;
	t=1;
	while(t--)
	{
	ll a,b,k;
	cin>>a>>b>>k;
	ll d=a;
	a-=k;
	k-=d;
	if(k>0)
	b-=k;
	if(a<0)
	a=0;
	if(b<0)
	b=0;
	cout<<a<<" "<<b<<"\n";	
	}
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,a,b;cin >> k >> a >> b;
    for(int i=0;i*k<=b;i++){
        if(i*k>=a){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int x,y;
	cin>>x>>y;
	cout<<(x<y?0:10)<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	ary := make([]int, 3)
	ans := [3]int{5, 5, 7}
	fmt.Scanf("%d %d %d", &ary[0], &ary[1], &ary[2])

	sort.Sort(sort.IntSlice(ary))
	for i, v := range ans {
		if v != ary[i] {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

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

		int[] res = new int[n];

		for(int i = 0; i < n; i++) {
			res[sc.nextInt() - 1]=i;
		}
		sc.close();

		StringBuilder sb = new StringBuilder();
		for(Integer r : res) {
			sb.append(" " + String.valueOf(r.intValue() + 1));
		}
		System.out.println(sb.toString().trim());
	}
}


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

bool isEven(string temp) {
	int size = temp.size();
	for (int i = 0; i < size / 2; i++) {
		if (temp[i] != temp[size / 2 + i]) {
			return false;
		}
	}
	return true;
}

int main() {
	string s;
	cin >> s;
	int size = s.size();
	for (int i = size - 2; i > 0; i-= 2) {
		string temp = s.substr(0, i);
		if (isEven(temp)) {
			cout << temp.length() << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans =0;
        
        for(int i=1; i<=N; i++){
            ans += i;
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21716
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 =  int(sys.stdin.readline())

print((N - 1) * N // 2)

Measured memory_bytes: 65772
#include<cstdio>
using namespace std;
int n,k;
int t;
int a[100001];
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if (a[i]==1) t=i;
	}
	if ((n-1)%(k-1)==0) printf("%d",(n-1)/(k-1));
	else printf("%d",(n-1)/(k-1)+1);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int A[n][m],b[m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
           cin>>A[i][j];
        }
    }
    for(int i=0;i<m;i++){
        cin>>b[i];
    }

    for(int i=0;i<n;i++){
        int sum=0;
        for(int j=0;j<m;j++){
            sum+=A[i][j]*b[j];
        }
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 3112
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	if a+b > c+d {
		fmt.Println("Left")
		return
	}
	if a+b < c+d {
		fmt.Println("Right")
		return
	}
	fmt.Println("Balanced")
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    char a,b; cin>>a>>b;
    if((a=='H'&&b=='H')||(a=='D'&&b=='D'))return puts("H")*0;
    puts("D");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

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

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

const int N=300010;
int n,m;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829)+13893829);
	cin>>n>>m;
	if (m/2019*2019>=n)
	{
		cout<<0;
		exit(0);
	}
	n%=2019;
	m%=2019;
	if (m<n) m+=2019;
	int mi=MOD;
	for (int i=n;i<=m;++i) for (int j=i+1;j<=m;++j) mi=min(mi,i*j%2019);
	cout<<mi;
}




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

int main() {
    int N; cin >> N;
    vector<int> b(N);
    rep(i, N){
        cin >> b[i];
        b[i]--;
    }

    vector<int> a;
    rep(i, N){
        int pivot = -1;
        for (int j = b.size()-1; j >= 0; j--){
            if(b[j] == j){
                pivot = j;
                break;
            }
        }

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

        a.push_back(pivot+1);
        b.erase(b.begin()+pivot);
    }

    rep(i, N){
        cout << a[N-1-i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3612
N = int(input())
l = [input() for _ in range(N)]
import collections
l1 = collections.Counter(l).most_common()
l1_max = l1[0][1]
l2 = []
for name, i in l1:
    if i == l1_max:
        l2.append(name)
    else:
        break
l2.sort()
for i in l2:
    print(i)

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


int main() {
    int a,b,c;
    string s;
    cin >> a >> b >> c;
    if((a==b)&&(b!= c))cout << "Yes" << endl;
    else if((c==b)&&(b!= a))cout << "Yes" << endl;
    else if((c==a)&&(c!= b))cout << "Yes" << endl;
    else cout << "No" <<endl;
    
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

typedef long long int ll;

ll weights[105];
ll values[105];

ll knap[205][100005];

bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

int main()
{
    ios::sync_with_stdio(false);

    ll i,j,k,l,m,n,w;

    cin >> n >> w;

    for(i=0;i<n;i++)
    {
        cin >> weights[i] >> values[i];
    }


    for(i=0;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
            if(i==0 || j==0)
                knap[i][j]=0;
            else if(weights[i-1]<=j)
            {
                knap[i][j] = max(values[i-1]+knap[i-1][j- weights[i-1]],knap[i-1][j]);
            }
            else
                knap[i][j] = knap[i-1][j];


            // cout << knap[i][j] << " ";


        }
        // cout << '\n';
    }

    cout << knap[n][w] << '\n';




}

Measured memory_bytes: 80128
#include<iostream>
#include <cmath>
using namespace std;
int main () {
  int N, D;
  cin >> N >> D;
  //vector<int vector<int> > p(N);
  int p[N][D];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> p[i][j];
    }
  }

  int res = 0;
  for (int ip = 0; ip < N; ip++) {
    for (int ip2 = ip+1; ip2 < N; ip2++) {
      double d = 0;        
      for (int j = 0; j < D; j++) {
	d += (double(p[ip][j]) - double(p[ip2][j]))*(double(p[ip][j]) - double(p[ip2][j]));
      }
      
      d = sqrt(d);
      if (int(d) == d) {
	res++;
      }
    }
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int bit[N*2],a[N],s[N],n;
int sum(int i)
{
	int s=0;
	while(i)
	{
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}
void add(int i,int x)
{
	while(i<=200000)
	{
		bit[i]+=x;
		i+=i&-i;	
	}	
}
int check(int x)
{
	memset(bit,0,sizeof(bit));
	s[0]=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=x)
			s[i]=s[i-1]+1;
		else
			s[i]=s[i-1]-1;
	}
	long long tot=0;
	for(int i=0;i<=n;i++)
	{
		tot+=sum(s[i]+100000);
		add(s[i]+100000,1);
	}
	if(tot>=1LL*n*(n+1)/4)
		return 1;
	else
		return 0;
}
int main()
{
	int lb=0,ub=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		ub=max(ub,a[i]+1);
	}
	while(ub-lb>1)
	{
		int mid=(lb+ub)>>1;
		if(check(mid))
			lb=mid;
		else
			ub=mid;
	}
	printf("%d\n",lb);
	return 0;
}


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

int main(){
        string str;
        cin>>str;
        bool ans=false;
        for(int i=0; i<str.size()-1; i++){
                if(str[i]=='A' && str[i+1]=='C'){
                        ans=true;
                        break;
                }
        }
        if(ans) cout<<"Yes";
        else cout<<"No";
        return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 1000005
using namespace std;
struct edge{
	int v, nxt;
}e[N];
int p[N], eid;
void init(){
	memset(p, -1, sizeof p);
	eid = 0;
}
void insert(int u, int v){
	e[eid].v = v;
	e[eid].nxt = p[u];
	p[u] = eid ++;
}
int n, m, fa[N], val[N], vis[N];
void dfs(int u){
	if(vis[u]) return;
	vis[u] = 1;
	for(int i = p[u]; i + 1; i = e[i].nxt){
		int v = e[i].v;
		dfs(v);
		if(val[v] + 1 > val[u]) fa[u] = v, val[u] = val[v] + 1;
	}
}
int main(){
	init();
	scanf("%d%d", &n ,&m);
	for(int i = 1; i <= n + m - 1; i ++){
		int u, v;
		scanf("%d%d", &u, &v);
		insert(v, u);
	}
	for(int i = 1; i <= n; i ++) dfs(i);
	for(int i = 1; i <= n; i ++) printf("%d\n", fa[i]);
	return 0;
}


Measured memory_bytes: 19584
class SegmentTree
  def initialize(arg, e)
    if arg.is_a?(Integer)
      v = Array.new(arg){ e }
    elsif arg.is_a?(Array)
      v = arg
    else
      raise ArgumentError
    end
    
    @e  = e
    @op = Proc.new { yield(_1, _2) }
    
    @n = v.size
    @log = ceil_pow2(@n)
    @leaf_size = 1 << @log
    @d = Array.new(@leaf_size * 2) { e }
    v.each_with_index { |v_i, i| @d[@leaf_size + i] = v_i }
    (@leaf_size - 1).downto(1) { |i| update(i) }
    self
  end
  
  def set(q, x)
    raise ArgumentError if (q < 0 || @n <= q)
    q += @leaf_size
    @d[q] = x
    1.upto(@log) { |i| update(q >> i) }
  end
  
  def get(q)
    raise ArgumentError if (q < 0 || @n <= q)
    d[leaf_size + q]
  end
  
  def prod(l, r)
    sml = @e
    smr = @e
    l += @leaf_size
    r += @leaf_size
    
    while l < r
      if l[0] == 1
        sml = @op.call(sml, @d[l])
        l += 1
      end
      if r[0] == 1
        r -= 1
        smr = @op.call(@d[r], smr)
      end
      l /= 2
      r /= 2
    end
    
    @op.call(sml, smr)
  end
  
  def all_prod
    d[1]
  end
  
  def max_right(l)
    return @n if l == @n
    
    f = Proc.new { yield(_1) }
    
    l += @leaf_size
    sm = @e
    loop do
      l /= 2 while l % 2 == 0
      unless f.call(@op.call(sm, @d[l]))
        while l < @leaf_size
          l = 2 * l
          if f.call(@op.call(sm, @d[l]))
            sm = op(sm, @d[l])
            l += 1
          end
        end
        return l - @leaf_size
      end
      sm = @op.call(sm, @d[l])
      l += 1
      break if (l & -l) == l
    end
    
    @n
  end
  
  private
  
  def update(k)
    @d[k] = @op.call(@d[2 * k], @d[2 * k + 1])
  end
  
  def inspect
    t = 0
    res = "SegmentTree\n  "
    a = @d[1, @d.size - 1]
    a.each_with_index do |e, i|

      res << e.to_s << " "
      if t == i && i < @leaf_size
        res << "\n  "
        t = t * 2 + 2
      end
    end
    res
  end
end

def ceil_pow2(n)
  x = 0
  x += 1 while (1 << x) < n
  x
end

SegTree = SegmentTree
Segtree = SegmentTree

# ABC125
n = gets.to_s.to_i
a = gets.to_s.split.map{ |e| e.to_i }

st = Segtree.new(a, 0) { _1.gcd(_2) }

ans = [st.prod(1, n), st.prod(0, n-1)].max
 
1.upto(n-2) do |i|
  v = st.prod(0, i).gcd st.prod(i+1, n) 
  ans = v if ans < v
end
 
puts ans


# INF = (1 << 60) - 1

# practice
#
# n, q = gets.to_s.split.map{ |t| t.to_i }
# a    = gets.to_s.split.map{ |t| t.to_i }

# st = Segtree.new(a, -INF) { [_1, _2].max }

# q.times do
#   query = gets.to_s.split.map{ |t| t.to_i }
#   if query[0] == 1
#     _, x, v = query
#     st.set(x - 1, v)
#   elsif query[0] == 2
#     _, l, r = query
#     puts st.prod(l - 1, r)
#   elsif query[0] == 3
#     _, x, v = query
#     puts st.max_right(x - 1) { _1 < v } + 1
#   else
#     raise
#   end
# end


Measured memory_bytes: 22924
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int> > Matrix;
const int MOD = 1e9+7;
const int INF =1000000;

// bit全探索
int main() {
int n; cin>>n;
//2^n の全探索
int res=0; 

vector<vector<pair<int,int>>> p(n);

 REP(i,n){//入力
  int a; cin>>a;
  REP(j,a){
      int x,y; cin>>x>>y;
      p[i].push_back({x-1,y});
  }
 }
 

for(int bit = 0; bit < (1<<n); ++bit){
   bool flag=1;
  REP(i,n){
    if(bit&(1<<i)){//i番の人が正直者なら発言の矛盾を調べる
      REP(j,p[i].size()){
        if(p[i][j].second==0&&(bit&(1<<p[i][j].first))){
        flag=0;
        //cout<<"bit="<<bit<<" "<<i<<"番目の人の発言と矛盾"<<endl;
        }
        if(p[i][j].second==1&&!(bit&(1<<p[i][j].first))){
        flag=0;
         //cout<<"bit="<<bit<<" "<<i<<"番目の人の発言と矛盾"<<endl;
        }
      }//repj
    }//if
    
  }//repi
   if(flag){
     int sum=0;
     REP(i,n)if(bit&(1<<i))sum++;
     if(sum>res)res=sum;
   }
  //cout<<"bit="<<bit<<" flag="<<flag<<endl;
}
cout<<res<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int kai[30],i,j,cnt,n,s,d,s1,d1,s2,d2,k;
	kai[0]=1;
	for(i=1;i<=29;i++)	kai[i]=kai[i-1]*2;
//	for(i=0;i<30;i++)	printf("ka=%d\n",kai[i]);
	scanf("%d",&n);
	for(i=0;i<n;i++)	{
		scanf("%d %d",&s,&d);
		if(s<0&& d>0) 	{
			s1=-s;	d1=0;
			s2=d;	d2=0;
		}
		else if(s<0)	{
			s1=-s;	d1=-d;
			d2=-1;
		}
		else {
			s1=d;	d1=s;
			d2=-1;
		}
//		printf("s1=%d d1=%d s2=%d\n",s1,d1,s2);
		cnt=0;
		while(s1>d1)	{
			for(j=29;j>=0;j--)	{
				if(s1%kai[j]==0 && s1-kai[j]>=d1)	{
					s1=s1-kai[j];
					cnt++;
					break;
				}
			}
		}
		if(d2!=-1)	{
			while(s2>d2)	{
				for(j=29;j>=0;j--)	{
					if(s2%kai[j]==0 && s2-kai[j]>=d1)	{
						s2=s2-kai[j];
						cnt++;
						break;
					}
				}
			}		
		}
		printf("%d\n",cnt);
	}
	return 0;
}


Measured memory_bytes: 2724
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> sum(n+1,0);
    rep(i,n) sum[i+1] = sum[i] + a[i];
    map<ll,int> cnt;
    rep(i,n+1) cnt[sum[i]]++;
    ll ans = 0;
    for(auto u : cnt){
        ll num = u.second;
        ans += num * (num-1) / 2;
    }
    cout << ans << endl;
}

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

#define fir first
#define sec second

typedef pair<int,int> pii;
const int maxn = 105;
pii pa[maxn], pb[maxn];
int na, nb;

inline int Length(pii a, pii b) {
	return abs(a.fir - b.fir) + abs(a.sec - b.sec);
}

int main() {
	scanf("%d %d", &na, &nb);
	for (int i=1; i<=na; ++i)
		scanf("%d %d", &pa[i].fir, &pa[i].sec);
	for (int i=1; i<=nb; ++i)
		scanf("%d %d", &pb[i].fir, &pb[i].sec);

	for (int i=1; i<=na; ++i) {
		int mn = INT_MAX, v = -1;
		for (int j=1; j<=nb; ++j) {
			int tmp = Length(pa[i], pb[j]);
			if (tmp < mn) {
				mn = tmp;
				v = j;
			}
		}
		printf("%d\n", v);
	}

	return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M;
vector <Pli> Graph[int(1e5+5)];
bool visited[int(1e5+5)], ans = true;
ll Dist[int(1e5+5)];

int DFS(int start){
  visited[start] = true;
  queue <int> que; que.push(start);
  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < Graph[Q].size(); i++){
      Pli P = Graph[Q][i];
      if (visited[P.se]){
        if (Dist[P.se] != Dist[Q] + P.fi) ans = false;
      }else{
        visited[P.se] = true;
        que.push(P.se);
        Dist[P.se] = Dist[Q] + P.fi;
      }
    }
  }

  return 0;
}


int main(){
  cin >> N >> M;
  for (int i = 0; i < M; i++){
    int L, R; ll D; cin >> L >> R >> D;
    Graph[L].push_back({D, R});
    Graph[R].push_back({-1 * D, L});
  }

  for (int i = 1; i <= N; i++){
    if (!visited[i]) DFS(i);
  }

  if (ans) Yes();
  else No();

  return 0;
}


Measured memory_bytes: 17276
#include <stdio.h>

/*A*/

int main(void){
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if (a + b > c + d){
		printf("Left");
	} else if (a + b == c + d){
		printf("Balanced");
	} else{
		printf("Right");
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
    #define fi first
    #define se second
    #define pb push_back
    #define mp make_pair
    #define SZ(x) ((int)x.size())
    #define ALL(x) x.begin(),x.end()
    #define L(i,u) for (register int i=head[u]; i; i=nxt[i])
    #define rep(i,a,b) for (register int i=(a); i<=(b); i++)
    #define per(i,a,b) for (register int i=(a); i>=(b); i--)
    using namespace std;
    typedef long double ld;
    typedef long long ll;
    typedef unsigned int ui;
    typedef pair<int,int> Pii;
    typedef vector<int> Vi;
    template<class T> inline void read(T &x){
    	x=0; char c=getchar(); int f=1;
    	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
    	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
    }
    template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
    template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
    template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
    inline ui R() {
    	static ui seed=416;
    	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
    }
    const int N = 666666;
    Vi e[N];int n,m,d[N],id[N],pos[N],col[N],A[N],B[N];bool ok[N];
    bool cmp(int x, int y){return d[x]<d[y];}
    int main() {
    	read(n);read(m);rep(i,1,n)read(d[i]),id[i]=i;
    	rep(i,1,m){
    		read(A[i]);read(B[i]);
    		e[A[i]].pb(B[i]);e[B[i]].pb(A[i]);
    	}
    	sort(id+1,id+n+1,cmp);
    	rep(i,1,n)pos[id[i]]=i;
    	rep(i,1,n){
    		int x=0;
    		rep(j,0,SZ(e[id[i]])-1)if(pos[e[id[i]][j]]<i)
    			x=col[e[id[i]][j]]^1;
    		rep(j,0,SZ(e[id[i]])-1)if(pos[e[id[i]][j]]<i&&!ok[e[id[i]][j]])
    			x=col[e[id[i]][j]]^1;
    		col[id[i]]=x;
    		rep(j,0,SZ(e[id[i]])-1)if(pos[e[id[i]][j]]<i&&col[e[id[i]][j]]!=x)
    			ok[id[i]]=1,ok[e[id[i]][j]]|=d[e[id[i]][j]]==d[id[i]];
    	}
    	rep(i,1,n)if(!ok[i]){puts("-1");return 0;}
    	rep(i,1,n)printf("%c",col[i]?'B':'W');puts("");
    	rep(i,1,m)printf("%d\n",max(d[A[i]],d[B[i]]));
    	return 0;
    }

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

vector<ll> A;
vector<ll> G[200001];
int ans[200001] = {0};
vector<ll> dp;

void dfs(ll now, ll par){
  //int cnt = int(dp.size());
  auto ptr = lower_bound(dp.begin(),dp.end(),A[now]);
  ll mae_i = ptr - dp.begin(),mae_v;

  //cout << now << " " << A[now] << " " << ptr-dp.begin() << ":";
  //for(int i(0);i<int(dp.size());i++){
    //cout << dp[i] << " ";
  //}

  //cout << endl;
  if(ptr == dp.end()){
    dp.push_back(A[now]);
    mae_v = -1;
  }else{
    mae_v = dp[ptr-dp.begin()];
    dp[ptr-dp.begin()] = A[now];
  }
  ans[now] = int(dp.size());
  

  for(int i(0);i<int(G[now].size());i++){
    int next = G[now][i];
    if(next != par){
      dfs(next,now);
    }
  }

  if(mae_v == -1){
    dp.pop_back();
  }else{
    dp[mae_i] = mae_v;
  }
}

int main(){
  ll N;
  cin>>N;
  A.resize(N+1);
  for(int i(0);i<N;i++) cin>>A[i+1];
  for(int i(0);i<N-1;i++){
    int u,v;
    cin>>u>>v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1ll,-1);
  for(int i(0);i<N;i++){
    cout << ans[i+1] << endl;
  }
}


Measured memory_bytes: 30760
from fractions import gcd
N = int(input())
t = list(int(input()) for _ in range(N))
tmp = gcd(0, t[0])
ans = tmp
for i in range(1, N):
    l = ans
    tmp = gcd(ans, t[i])
    ans = (l * t[i]) // tmp

print(ans)

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

const int white = 0, gray = 1, black = 2, N = 101;
bool G[N][N];
int n, color[N], d[N], f[N], t;

void init(){
    for (int i = 1; i <= n; i++)
    {
        color[i] = white;
    }
    t = 0;
}
void dfs(int v){
    color[v] = gray;
    t++;
    d[v] = t;
    for (int i = 1; i <= n; i++)
    {
        if (G[v][i] && color[i] == white)
        {
            dfs(i);
        }
    }
    color[v] = black;
    t++;
    f[v] = t;
}

int main(){
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            cin >> v;
            G[u][v] = 1;
        }
    }
    init();
    for (int i = 1; i <= n; i++)
    {
        if (color[i] == white)
        {
            dfs(i);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    
}


Measured memory_bytes: 3092
s = input()
t = input()

diff_min = len(t)
while len(s) >= len(t):
    diff = 0
    for i in range(len(t)):
        if s[i] != t[i]:
            diff += 1
    diff_min = min(diff_min, diff)
    s = s[1:]
print(diff_min)

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N, K;
    cin >> N >> K;

    ll m = N / K;
    ll x = K*m - N;
    ll y = K*(m + 1) - N;
    ll z = K*(m - 1) - N;

    auto ans = min(llabs(x), llabs(y));
    ans = min(ans, llabs(z));

#ifdef DEBUG
    cout << "m = " << m << "\n";
    cout << "x = " << x << "\n";
    cout << "y = " << y << "\n";
    cout << "z = " << z << "\n";
#endif

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3596
import java.util.Scanner;
class Main {
 public static void main(String[] args){
 Scanner scan = new Scanner(System.in);
 int x = scan.nextInt();
 int hours = x / (60 * 60);
 int y = x - (hours * 60 * 60);
 int min = y / 60;
 int sec = y - (min * 60);
 System.out.println(hours + ":" + min + ":" + sec);
 }
 }


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

int binarySearch (vector<int> a, int n, int key) {
  int left = 0;
  int right = n;
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == a.at(mid)) return 1;
    if (key > a.at(mid)) left = mid + 1;
    else if (key < a.at(mid)) right = mid;
  }
  return 0;
}

int main() {
  int n, q, sum = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i ++) cin >> a.at(i);

  cin >> q;
  for (int i = 0; i < q; i ++) {
    int key; cin >> key;
    if (binarySearch(a, n, key)) sum ++;
  }

  cout << sum << endl;
}



Measured memory_bytes: 3544
#include <stdio.h>
#define WHITE 1
#define GRAY 0
#define BLACK -1
#define INF 100000000
#define N 100
 
void bfs(int);
void enqueue(int);
int dequeue(void);
 
int Q[N+1],d[N+1],c[N+1],ts,n,S[N+1][N+1],K[N+1];
int head, tail;
 
int main()
{
  int i,j,u,min;
 
  scanf("%d",&n);
 
  head = 0;
  tail = 1;
 
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&K[u]);
 
    for(j=0;j<K[u];j++){
      scanf("%d",&S[u][j]);
    }
  }
 
  bfs(1);
  for(i=1;i<=n;i++)  {
    if(d[i]==INF) d[i]=-1;
    printf("%d %d\n",i,d[i]);
  }
 
  return 0;
}
 
void bfs(int s){
  int i,u,v;
  for (u=1;u<=n;u++){
    c[u] = WHITE;
    d[u] = INF;
  }
  c[s] = GRAY;
  d[s] = 0;
 
  enqueue(s);
 
  while(head!=tail){
    u = dequeue();
    for(i=0;i<K[u];i++){
      v=S[u][i];
      if (c[v] == WHITE){
    c[v] = GRAY;
    d[v] = d[u] + 1;
    enqueue(v);
      }
      c[u] = BLACK;
    }
  }
}
 
void enqueue(int x){
  Q[tail] = x;
  if (tail + 1 == n) tail = 0;
  else tail++;
}
 
int dequeue(void){ 
  int x;
  x = Q[head];
  if (head + 1 == n) head = 0;
  else head++;
  return x;
}

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

typedef long long int lli;
const lli mod = 1e9 + 7;
void printDP(vector < vector <lli> > dp ){
    for(int i =0;i<dp.size();i++){
        for(int j = 0 ;j<dp[i].size();j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    lli n,m;
    cin >> n >> m;
    vector <lli> v(n+1);
    for(int i =1;i<=n;i++)cin >> v[i];
    vector < vector <lli> >dp(n+1,vector<lli>(m+1));
    dp[0][0]=1;
    for(int i =0;i<=n;i++)dp[i][0]=1;
    for(int i = 1;i<=n;i++){
        vector <lli> sum(m+1);
        sum[0]=1;
        for(int j =1;j<=m;j++)sum[j]=(sum[j-1]+dp[i-1][j])%mod;
        for(int j = 1;j<=m;j++){


            if(j-v[i]<=0)
                dp[i][j]=(dp[i][j] + sum[j])%mod;
            else dp[i][j]=(sum[j]-sum[j-v[i]-1] + mod)%mod;
            if(dp[i][j]>=mod)dp[i][j]-=mod;
        }
    }
   //printDP(dp);
    cout << dp[n][m]<<endl;
}


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

int main(){
	int q;
	cin >> q;
	for(int p=0; p < q; p++){
		int x, y, w, h;
		int cat[2];
		int ans = 0;

		cin >> x >> y >> w >> h;

		int catNum;
		cin >> catNum;

		for(int i=0; i < catNum; i++){
			cin >> cat[0] >> cat[1];
			if(x <= cat[0] && cat[0] <= x+w &&
				y <= cat[1] && cat[1] <= y+h){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

ll dp[222222][4];

void chMax(ll &a, ll b){
	a = max(a, b);
}

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

	ll n;cin >> n;
	vector<ll> v(n);REP(i, n)cin >> v[i];

	REP(i, 222222)REP(j, 4)dp[i][j] = -LLINF;
	dp[0][0] = 0;

	REP(i, n){
		REP(j, 4){
			chMax(dp[i+1][min(3LL, j+1)], dp[i][j]);
			if(n % 2 && i == n-1 && j == 0)continue;
			chMax(dp[min(n, i+2)][j], dp[i][j] + v[i]);
		}
	}

	if(n % 2){
		cout << max(dp[n][1], dp[n][2]) << endl;
	}
	else{
		cout << max(dp[n][0], dp[n][1]) << endl;
	}

	return 0;
}


Measured memory_bytes: 11644
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  int n;
  cin >> n;

  vector<string> v(n);
  set<string> s;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    s.insert(v[i]);
  }

  bool ans = true;
  for (int i = 0; i < n - 1; i++)
    if (v[i][v[i].size() - 1] != v[i + 1][0])
      ans = false;

  if (s.size() != n)
    ans = false;

  cout << (ans ? "Yes" : "No") << endl;
}


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

using namespace std;

typedef long long ll;

const int maxn=1e6+5,mod=1e4+7;
const double pi=acos(-1);

int main()
{
    int N,M;
    while(cin>>N>>M)
    {
        int n=0,m=0;
        if(N>1)
        n=N*(N-1)/2;
        if(M>1)
            m=M*(M-1)/2;
        cout<<m+n<<endl;
    }
    return 0;
}


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

using namespace std;

void Change(string &s, char from, char to)
{
    const int N = s.size();
    int tmp = N - 1;

    while (tmp >= 0) {
        if (s[tmp] == from)
            break;
        --tmp;
    }

    if (tmp == N - 1 || tmp == -1)
        return ;

    s += from;
    // cout << from << " /  " << to << "\n";
    // cout << tmp << " : " << s << "\n";
    for (int i = N - 1; tmp <= i; --i) {
        s[i] = from;
    }
}

int main()
{
    string sf, sr;
    int N;
    bool turn = true;  // true: o, false: x

    cin >> sf;
    N = sf.size();
    sr = sf;
    reverse(sr.begin(), sr.end());
    string o(N, 'o'), x(N, 'x');

    while (sf != o && sf != x && sr != o && sr != x) {
        if (turn) {
            Change(sf, 'o', 'x');
            Change(sr, 'o', 'x');
            o += 'o';
        }
        else {
            Change(sf, 'x', 'o');
            Change(sr, 'x', 'o');
            x += 'x';
        }

        turn = !turn;
    }

    if (sf == o || sr == o)
        cout << "o\n";
    else
        cout << "x\n";

    return 0;
}

Measured memory_bytes: 1192
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

N_MAX = 2 * 10^5
fac = Array{Int}(N_MAX+1)
inv = Array{Int}(N_MAX+1)
MOD = 10^9 + 7
#初期化
function COMINT()
    # 階乗の初期化
    fac[1] = 1
    for i in 1:N_MAX-1
        fac[i+1] = fac[i] * (i+1) % MOD;
    end
    #階乗の逆元
    for i in 1:N_MAX
        inv[i] = powermod(fac[i], MOD-2, MOD)
    end
end


#nCk
function Comb(n, k)
    if n <= 0 || k < 0
        return 0
    end
    if k > n
        return 0
    end
    if k == 0 || n == k
        return 1
    end
    return ((fac[n] * inv[k]) % MOD * inv[n-k])%MOD
end
function H(n, m)
    return Comb(n + m, m)
end
function main()
    COMINT()
    n,k = parseInt.(split(readline()))
    m = min(k, n-1)
    ans = 0
    for i in 0:m
        ans += (Comb(n,i) * H(n-1-i,i)) % MOD
        ans %= MOD
    end
    println(ans)
end

main()



Measured memory_bytes: 155968
#include <iostream>
using namespace std;
int s[10];
int main(void){
    for(int i=0;i<4;i++){
        int a;
        cin>>a;
        s[a]++;
    }
    if(s[1]*s[7]*s[9]*s[4]==1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 












int main()
{
   ll a,b;
   cin>>a>>b;
   ll g=__gcd(a,b);
   int ct=0;
   for(int i=2;i<=sqrt(g);i++)
   {
        if(g%i==0)
        {
             while(g%i==0)g/=i;
             ct++;
        }
   }
   if(g>1)ct++;
   ct++;
   
   cout<<ct;
}







 
 

















Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdint.h>
using namespace std;
#define rep(i,n) for (int64_t i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl

int64_t summ(string &num, int &size, int64_t &x) {
    string data;
    int64_t sum=0;
    rep(i,size) {
        data.push_back(num.at(i));
        if (x & (1<<i)) {
            sum += (int) atoll(data.c_str());
            data = "";
        }
    }
    sum += atoll(data.c_str());
    return sum;
}

int main() {
    string num;
    cin >> num;
    int size = num.size();
    int64_t ma=1; rep(i,size-1) ma *= 2;
    int64_t ans=0;
    rep(i,ma) ans += summ(num, size, i);
    ct(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<bitset>
#include<stdio.h>
using namespace std;
int main(){
  int a[5],tmp,sum,i;
  char e[5];
  for(i=0;i<4;i++){
    scanf("%c",&e[i]);
    a[i]=e[i]-'0';
  }
  for(tmp=0;tmp<(1<<3);tmp++){
      sum=a[0];
    bitset<3> s(tmp);
    for(i=0;i<3;i++){
      if(s.test(i)){
        sum=sum+a[i+1];
      }
      else{
        sum=sum-a[i+1];
      }
    }
    if(sum==7){
      printf("%d",a[0]);
      for(i=0;i<3;i++){
      if(s.test(i)){
        printf("+");
      }
      else{
        printf("-");
      }
        printf("%d",a[i+1]);
      }
      printf("=7\n");
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

ll gcd(ll x, ll y)
{
    while (y > 0)
    {
        ll tmp = y;
        y = x % y;
        x = tmp;
    }
    return x;
}

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> d(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> d[i];
    }

    ll ans = d[0];
    for (ll i = 0; i < n - 1; i++)
    {
        ans = gcd(ans, d[i + 1]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	int total = H * W;
	int blacked = h * W + w * H - h * w;

	cout << total - blacked << endl;
}

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

	solve();
}

Measured memory_bytes: 256