akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define maxn 100000
char s[maxn+5];
int main(){
	int n,k,w=0;scanf("%d%d%s",&n,&k,s+1);
	for(int i=2;i<=n;i++){
		if(s[i]!=s[i-1]){
			if(!w)w=1,k--;
			if(k==-1)break;
			s[i]^=30;
		}
		else w=0;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='L'&&s[i-1]=='L')ans++;
		if(s[i]=='R'&&s[i+1]=='R')ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
N, M = [int(x) for x in input().split()]
m = {}
m[1] = {
    'count': 1,
    'passed': True
}
for i in range(2,N+1):
    m[i] ={ 
        'count': 1,
        'passed': False
    }
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    m[b]['count'] += 1
    if m[a]['passed']:
        m[b]['passed'] = True
    m[a]['count'] -= 1
    if m[a]['count'] == 0:
        m[a]['passed'] = False
count = 0
for key in m:
    if m[key]['passed']:
        count += 1
print(count)

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,A;
    cin >> H >> A;
    if(H%A == 0) cout << H/A << endl;
  	else cout << H/A + 1 << endl;
}


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

int main() {
	int n,k,sm=0;
	cin >> n >> k;
	vector<int> l(n,0);
	for(int i = 0;i < n;i++)
	{
		cin >> l.at(i);
	}
	sort(l.begin(),l.end());
	for(int i = n - 1;i >= n - k;i--)
	{
		sm += l.at(i);
	}
    cout << sm << endl;
	return 0;
}


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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
  
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<pair<int,int>> vpi;

const int M = 1e9+7;
const int N = 3e5;
ll po(int,int);

int tree[4*N+5];

void update(int n,int s,int e,int id,int val){
    if(s==e){
        tree[n] = val;
        return;
    }
    int mid = (s+e)>>1;
    if(id>=s && id<=mid){
        update(2*n,s,mid,id,val);
        
    }
    else update(2*n+1,mid+1,e,id,val);
    
    tree[n] = max(tree[2*n],tree[2*n+1]);
}
int query(int n,int s,int e,int l,int r){
    if(s>r || e<l) return 0;
    if(s>=l && e<=r) return tree[n];
    int mid = (s+e)>>1;
    return max(query(2*n,s,mid,l,r),query(2*n+1,mid+1,e,l,r));
    
}

void solve(){
    int n;cin>>n;
    int k;cin>>k;
    int el;
    int ans = 0;
    FOR(i,0,n){
        cin>>el;
        int x = query(1,0,N,el-k,el+k);
        ans = max(ans,x+1);
        update(1,0,N,el,x+1);
    }
    
    cout<<ans<<"\n";
    
    

}




int main() {
   
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
    
   #ifndef ONLINE_JUDGE 
   freopen("input.txt", "r", stdin);  
   freopen("output.txt", "w", stdout); 
   #endif 

    int t=1;
    //cin>>t;
    FOR(i,1,t+1){
        //cout<<"Case #"<<i<<": "; 
        solve();
        
    }
    
    return 0;
    
    
}


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}



Measured memory_bytes: 7748
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int arr[4];
    memset(arr,0,sizeof(arr));
    for (int i = 0; i < 4; i++)
    {
        arr[i] = n%10;
        n = n/10;
    }
    if(arr[0]==2 || arr[0]==5 || arr[0]==7 || arr[0]==9 || arr[0]==4)printf("hon\n");
    else if(arr[0]==0 || arr[0]== 1 || arr[0]==6 || arr[0]==8)printf("pon\n");
    else if(arr[0]==3)
    {
        printf("bon\n");
    }
    return 0;
    

}

Measured memory_bytes: 3656
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      a: [usize; n]
   }
   if n % 2 == 1 {
      let mut i = n - 1;
      while i > 0 {
         print!("{} ", a[i]);
         i -= 2;
      }
      print!("{} ", a[0]);
      i = 1;
      while i < n {
         print!("{} ", a[i]);
         i += 2;
      }
   } else {
      let mut i = n - 1;
      loop {
         print!("{} ", a[i]);
         if i == 1 {
            break;
         }
         i -= 2;
      }
      print!("{} ", a[0]);
      i = 2;
      while i < n {
         print!("{} ", a[i]);
         i += 2;
      }
   }
}


Measured memory_bytes: 8316
#include <iostream>
#include <cstring>
#define MOD 1000000007
using namespace std;

int n, sum=0, arr[101], m, p, x;

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)cin>>arr[i];
	for(int i=0;i<n;i++)sum+=arr[i];
	cin>>m;
	for (int i = 0; i < m; ++i){
		cin>>p>>x;
		cout<<sum-arr[p-1]+x<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	nums := make([]int, 3)
	fmt.Scan(&nums[0])
	fmt.Scan(&nums[1])
	fmt.Scan(&nums[2])
	sort.Sort(sort.Reverse(sort.IntSlice(nums)))

	fmt.Println(nums[0]*10 + nums[1] + nums[2])
}


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

int main(){
  int N;
  cin >> N;
  long long INF = 1000000007;
  long long ans=1;
  vector<int> div;
  for(int i=1; i<=N; i++){
    int temp = i;
    for(int j=2; j*j<=i; j++){
      while(temp%j==0){
        div.push_back(j);
        temp/=j;
      }
    }
    if(temp>1) div.push_back(temp);
  }
  sort(div.begin(), div.end());
  div.push_back(INF);
  int cnt=1;
  for(int i=0; i<div.size()-1; i++){
    if(div.at(i)==div.at(i+1)){
      cnt++;
    }
    else{
      ans=ans*(cnt+1)%INF;
      cnt=1;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
def popcount(x):
    return bin(x).count("1")


n=int(input())
x=input()
num=int(x,2)
cnt=popcount(num)

mod1=num%(cnt+1)
mod2=num%(cnt-1) if cnt-1!=0 else 0

for i in range(n):
    if x[i]=="0":
        ans=(mod1+pow(2,n-i-1,cnt+1))%(cnt+1)
    else:
        if cnt-1==0:
            print(0)
            continue
        else:
            ans=(mod2-pow(2,n-i-1,cnt-1))%(cnt-1)
    point=1
    while ans!=0:
        ans %=popcount(ans)
        point +=1
    print(point)

Measured memory_bytes: 81500
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <iomanip>

using namespace std;

mt19937 Rand(16092002);
mt19937_64 BigRand(16092002);

typedef long long ll;

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#endif
    int n;
    scanf("%d", &n);
    vector <int> a(3 * n);
    for (int i = 0; i < 3 * n; i++)
    {
        scanf("%d", &a[i]);
    }
    vector <ll> pref(3 * n, -1e18);
    vector <ll> suf(3 * n, 1e18);
    priority_queue <int, vector <int>, greater <int> > q;
    priority_queue <int> d;
    ll sum = 0;
    for (int i = 0; i < 3 * n; i++)
    {
        q.push(a[i]);
        sum += a[i];
        while (q.size() > n)
        {
            sum -= q.top();
            q.pop();
        }
        if (q.size() == n)
        {
            pref[i] = sum;
        }
    }
    sum = 0;
    for (int i = 3 * n - 1; i >= 0; i--)
    {
        d.push(a[i]);
        sum += a[i];
        while (d.size() > n)
        {
            sum -= d.top();
            d.pop();
        }
        if (d.size() == n)
        {
            suf[i] = sum;
        }
    }
    ll ans = -1e18;
    for (int i = 0; i < 3 * n - 1; i++)
    {
        ans = max(ans, pref[i] - suf[i + 1]);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 7288
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=[I() for i in range(n)]
for i in range(n):
    if lis[i]%2==1:
        print("first")
        exit()
print("second")
    
    
    
    




Measured memory_bytes: 77952
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    if A <= 12:
        B = B // 2
    if A <= 5:
        B = 0
    print(B)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


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

int main(){
    int n;
    while(cin >> n){
        if(n==1){
            cout << 1 << endl;
        }else{
            int total=0;
            for(int i=n;i>=1;i--){
                total+=i;
            }cout << total << endl;
        }
    }
}

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

int main(){
    int n;
    cin >> n;
    int c[n-1],s[n-1],f[n-1];
    for(int i=0; i<n-1; i++){
        cin >> c[i] >> s[i] >> f[i];
    }
    int ans[n];
    fill(ans,ans+n,0);
    for(int i=0; i<n-1; i++){
        for(int j=0; j<=i; j++){
            if(ans[j] < s[i]){
                ans[j] = s[i] + c[i];
            }
            else if(ans[j]%f[i] == 0){
                ans[j] += c[i];
            }
            else{
                ans[j] += (f[i]-ans[j]%f[i]) + c[i];
            }
        }
    }
    for(int i=0; i<n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<complex>
#include<vector>
using namespace std;
#define x second
#define y first
#define M st.size()
typedef complex<double> point;
pair<int,int> a[100000];
vector<int> st;
bool ccw(point a,point b,point c){
  b-=a,c-=a;
  c*=conj(b);
  if(c.imag()<=0)return true;  
  return false;
}

void check(int i){
  while(M>=2){
    int s=st[M-2];
    int e=st[M-1];
    point S=point(a[s].x,a[s].y);
    point E=point(a[e].x,a[e].y);
    point N=point(a[i].x,a[i].y);
    if(ccw(S,E,N))break;
    st.pop_back();
  }
  st.push_back(i);
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i].x>>a[i].y;
  sort(a,a+n);
  for(int i=0;i<n;i++)check(i);
  for(int i=n-2;i>=0;i--)check(i);
  st.pop_back();
  cout<<M<<endl;
  for(int i=M;i>0;i--)cout<<a[st[i%M]].x<<' '<<a[st[i%M]].y<<endl;
  return 0;
}

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

template <class T> inline bool chmax(T& a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  map<int, int> ps;
  int p;
  for(int i = 0; i < N; ++i) {
    cin >> p;
    ps[p] = i;
  }

  int count = 0;
  int max = 0;
  int prev = -1;
  for(auto p : ps) {
    if(prev > p.second) { // index が増加している間はcountをアップ
      count = 0;
    }
    count++;
    chmax(max, count);
    prev = p.second;
  }
  cout << N - max << endl;
  return 0;
}

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

int main()
{
	string s,t;
	int	total=0;
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!=t[i])total++;
	}
	cout<<total;
	return 0;
}

Measured memory_bytes: 3912
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    int n, ans = 0;
    cin >> n;
    int t[n];
    unordered_map<int, int> cnt;
    for(int i=0; i<n; i++){
        cin >> t[i];
        if(cnt.count(t[i])) cnt[t[i]] += 1;
        else cnt[t[i]] = 1;
    }
    sort(t, t+n, greater<>());
    for(int i=0; i<n; i++){
        if(!cnt[t[i]]) continue;
        cnt[t[i]] -= 1;
        int need = 1;
        while(need <= t[i]) need *= 2;
        need -= t[i];
        auto it = cnt.find(need);
        if(it != cnt.end() && it->second){
            cnt[need] = max(0, cnt[need] -1);
            ans ++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 9288
def check(n, i):
    while n >= i and n % i == 0:
        n //= i
    return n % i == 1

def main():
    N = int(input())
    i = 2
    r = set()
    while i * i <= N:
        if N % i == 0:
            if check(N, i):
                r.add(i)
            if check(N, N // i):
                r.add(N // i)
        elif N % i == 1:
            r.add(i)
            if check(N, N // i):
                r.add(N // i)
        i += 1
    if N > 2:
        r.add(N - 1)
    r.add(N)
    return len(r)

print(main())


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    int n;
    cin>>n;
    vector<ll>a(n);
    int zero =0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i] == 0)zero++;
    }
    if(zero >0){
        cout<<0<<endl;
        return 0;
    }
    ll ans = 1;
    for(int i=0;i<n;i++){
        if(a[i]<= 1000000000000000000/ans){
            ans*=a[i];
        }else{
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4040
#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

struct Dict{
    string key;
    int value;
};

void swap(int& d1, int& d2){
    int temp = d1;
    d1 = d2;
    d2 = temp;
}

void swap(Dict& d1, Dict& d2){
    Dict temp = d1;
    d1 = d2;
    d2 = temp;
}

int main()
{
    int n;
    cin >> n;
    Dict dict[100];
    int array[100];
    for(int i=0;i<n;i++){
        cin >> dict[i].key >> dict[i].value;
        array[i] = i+1;
    }

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(dict[i].key > dict[j].key){
                swap(dict[i], dict[j]);
                swap(array[i], array[j]);
            }
            else if(dict[i].key == dict[j].key && dict[i].value < dict[j].value){
                swap(dict[i], dict[j]);
                swap(array[i], array[j]);
            }
        }
    }

    for(int i=0;i<n;i++){
        cout << array[i] << endl;
    }
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  const array = input.split(' ');
  let takahashi = Number(array[0]);
  let aoki = Number(array[2]);
  
  let count = 0;
  let bool = true;
  while(bool) {
    if(count%2 === 0){
      aoki = aoki - Number(array[1]);
      if(aoki <= 0){
        console.log('Yes');
        bool = false;
      }
    } else {
      takahashi = takahashi - Number(array[3]);
      if(takahashi <= 0){
        console.log('No');
        bool = false;
      }
    }
    count++;
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29488
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;

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

int n;
pii dot[100001];

vector <int> x[100001];
vector <int> y[100001];

bool cache[100001];

int cnt = 0;
set <int> ax, ay;
void DFS(int i)
{
	cache[i] = 1;
	cnt++;
	int cx = dot[i].first, cy = dot[i].second;
	ax.insert(cx), ay.insert(cy);
	for (int it : x[cx])
	{
		if (cache[it]) continue;
		DFS(it);
	}
	for (int it : y[cy])
	{
		if (cache[it]) continue;
		DFS(it);
	}
}

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

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a, b; cin >> a >> b;
		dot[i] = { a, b };
		x[a].push_back(i);
		y[b].push_back(i);
	}

	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (cache[i]) continue;
		int cx = dot[i].first, cy = dot[i].second;
		if (x[cx].size()>1 && y[cy].size()>1)
		{
			cnt = 0;
			ax.clear(), ay.clear();
			DFS(i);

			ans += ll(ax.size())*ay.size() - cnt;
		}
	}
	cout << ans;
}

Measured memory_bytes: 18304
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.append(X)
y.append(Y)

def check2():
    return max(x) >= min(y)

if check2():
    print("War")
else:
    print("No War")


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

signed main() {
	int N, M;
	cin >> N >> M;
	
	while (N != 0) {
		vector<int> h, w;
		inputVector(h, N);
		inputVector(w, M);

		map<int, int> hm, wm;

		for (int i = 0; i < h.size(); i++) {
			int len = 0;
			for (int j = i; j < h.size(); j++) {
				len += h[j];
				if (hm.find(len) == hm.end()) {
					hm[len] = 0;
				}
				hm[len]++;
			}
		}

		for (int i = 0; i < w.size(); i++) {
			int len = 0;
			for (int j = i; j < w.size(); j++) {
				len += w[j];
				if (wm.find(len) == wm.end()) {
					wm[len] = 0;
				}
				wm[len]++;
			}
		}

		auto ith = hm.begin();
		auto itw = wm.begin();

		int ret = 0;
		while (true) {
			int hn = (*ith).first;
			int wn = (*itw).first;

			if (hn == wn) {
				ret += (*ith).second * (*itw).second;
				ith++;
				if (ith == hm.end()) break;
			} else if (hn < wn) {
				ith++;
				if (ith == hm.end()) break;
			} else {
				itw++;
				if (itw == wm.end()) break;
			}
		}

		cout << ret << endl;

		cin >> N >> M;
	}

    return 0;
}

Measured memory_bytes: 38400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9+5;
int main()
{
int n;
cin>>n;
int a[n];
for(int i = 0;i<n;i++)
{
	cin>>a[i];
}
vector<int> dp(n,INF);
dp[0]=0;
for(int i = 0; i<n ; ++i)
{
	for(int j : {i+1,i+2})
	{
		if(j<n)
		{
			dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
		}
	}
}
cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
int factorial(int n){
  if(n==0) return 1;
  else return n*factorial(n-1);
}
int f(vector<int> p){
  int n=p.size();
  int a=1;
  vector<int> f(n);
  for(int i=0;i<n-1;i++){
    f.at(p.at(i)-1)=1;
    int c=0;
    for(int j=0;j<p.at(i)-1;j++) if(f.at(j)==0) c++;
    a+=c*factorial(n-1-i);
  }
  return a;
}
int main(){
  int n,i,a,b;
  cin>>n;
  vector<int> p(n),q(n);
  for(i=0;i<n;i++) cin>>p.at(i);
  for(i=0;i<n;i++) cin>>q.at(i);
  a=f(p);
  b=f(q);
  cout<<max(a-b,b-a)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 1000000007;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

ll nCr(ll n,ll k,ll MOD_=1000000007){
    //assert(n>=0&&k>=0&&MOD_>=2);
    ll size=k;
    ll ans=1;
    vector<ll>fact_inv,inv;
    fact_inv.resize(size+5);
    inv.resize(size+5);
    fact_inv[0]=fact_inv[1]=1;
    inv[1]=1;
    for(int i=2;i<size+5;i++){
        inv[i]=MOD_-inv[MOD_%i]*(MOD_/i)%MOD_;
        fact_inv[i]=fact_inv[i-1]*inv[i]%MOD_;
    }
    for(int i=n;i>=n-k+1;i--){
        ans*=i;ans%=MOD_;
    }
    return ans*fact_inv[k]%MOD_;
}

int main(){
   ll X,Y;
   cin>>X>>Y;
   if((X+Y)%3 || X*2<Y || Y*2<X){
      cout<<0<<endl;
      return 0;
   }
   ll min_xy=min(X,Y);
   ll t=(X+Y)/3;
   ll R=min_xy-t;
   cout<<nCr(t,R)<<endl;
}

Measured memory_bytes: 8540
// 典型BFS 最短パスと既存の#を引いたところ以外を#に塗るとしてその数
// たどりつけない場合を読み飛ばしてた...

package main

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

type Pos struct {
	Y, X int
}

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	blacks := 0
	H, W := nextInt(), nextInt()
	T := make([][]int, H)
	for i := 0; i < H; i++ {
		T[i] = make([]int, W)
		line := chars(next())
		for j, c := range line {
			if c == "#" {
				T[i][j] = -1
				blacks++
			}
		}
	}
	T[0][0] = 1
	queue := []Pos{Pos{Y: 0, X: 0}}
	steps := []int{0, 1, 0, -1, 0}
	for len(queue) > 0 {
		nex_queue := []Pos{}
		for _, q := range queue {
			for i := 0; i < 4; i++ {
				ny, nx := q.Y+steps[i], q.X+steps[i+1]
				if 0 <= ny && ny < H && 0 <= nx && nx < W && T[ny][nx] == 0 {
					nexPos := Pos{Y: ny, X: nx}
					T[ny][nx] = T[q.Y][q.X] + 1
					nex_queue = append(nex_queue, nexPos)
				}
			}
		}
		queue = nex_queue
	}
	if T[H-1][W-1] == 0 {
		fmt.Fprintln(out, -1)
	} else {
		fmt.Fprintln(out, H*W-T[H-1][W-1]-blacks)
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    long n = scanner.nextLong();
    long a = scanner.nextLong();
    long b = scanner.nextLong();
    long quot = n / (a + b);
    long surplus = n - (a + b) * quot;
    if (surplus > a) {
      System.out.println(a * quot + a);
    } else {
      System.out.println(a * quot + surplus);
    }
  }
}


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

int main(){
  double x1,x2,y1,y2;

  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  printf("%f\n",sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
  return 0;
}

Measured memory_bytes: 652
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define FOREQ(i, s, n) for (ll i = (s); i <= (ll)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

const ll UPPER = 3652425;
int n, q;
ll vs[100010];
ll ts[100010];
ll xs[100010];
ll qs[100010];

ll serv[100010];
ll work[4000000];
ll ans[100010];
vector<int> end[4000000];

ll a, b, c;
void Push(ll sum, ll day, int &s) {
  while (s < n && vs[s] <= sum) {
    serv[s] = day;
    end[day + xs[s]].push_back(s);
    if (ts[s] == 0) {
      c++;
    } else if (ts[s] == 1) {
      b++;
      c -= day;
    } else if (ts[s] == 2) {
      a++;
      b -= 2 * day;
      c += day * day;
      assert(-2e+18 < b && b < 2e+18);
      assert(-2e+18 < c && c < 2e+18);
      assert(day == 0 || day * day / day == day);
    }
    s++;
  }
}

void Delete(ll day) {
  FORIT(it, end[day]) {
    int type = ts[*it];
    ll start = serv[*it];
    if (type == 0) {
      c--;
    } else if (type == 1) {
      b--;
      c += start;
    } else if (type == 2) {
      a--;
      b += 2 * start;
      c -= start * start;
    }
  }
}

int main() {
  while (scanf("%d %d", &n, &q) > 0) {
    // Init & Input
    MEMSET(serv, 0x0f);
    REP(i, 4000000) { end[i].clear(); }
    //MEMSET(work, 0);
    MEMSET(ans, 0);
    REP(i, n) {
      int v = scanf("%lld %lld %lld", &vs[i], &ts[i], &xs[i]);
      assert(v == 3);
    }
    REP(i, q) {
      int v = scanf("%lld", &qs[i]);
      assert(v == 1);
    }

    // Solve
    a = 0, b = 0, c = 1;
    ll sum = 0;
    int s = 0;
    int t = 0;
    Push(sum, 0, s);
    Delete(0);
    if (t < q && qs[t] == 0) { ans[t++] = sum; }
    FOREQ(day, 1, UPPER) {
      sum += a * day * day + b * day + c;
      work[day] = sum;
      assert(sum >= 0);
      assert(day == 0 || a * day * day / day == a * day);
      assert(day == 0 || b * day / day == b);

      if (t < q && qs[t] == day) { ans[t++] = sum; }
      Push(sum, day, s);
      Delete(day);
    }

    // Print Ans
    REP(i, n) {
      if (serv[i] <= UPPER) {
        printf("%lld\n", serv[i]);
      } else {
        printf("Many years later\n");
      }
    }
    REP(i, q) {
      printf("%lld\n", ans[i]);
    }
  }
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
// ascending order
#define asort(array, N) sort(array, array + N)
// descending order
#define asort_r(array, N) sort(array, array + N, greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	int d[N];
	for(int i = 0; i < N; i++) d[i] = 0;
	for(int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		d[a - 1]++;
		d[b - 1]++;
	}

	for(int i = 0; i < N; i++) cout << d[i] << endl;
}


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

using namespace std;

int n, m;
int a[111111];
set<pair<int, int> > s;
vector<int> g[111111];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d",&n);
	for(int i = 1; i < n; ++i){
		int x, y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	scanf("%d",&m);
	memset(a, -1, sizeof(a));
	for(int i = 1; i <= m; ++i){
		int x, y;
		scanf("%d%d",&x,&y);
		a[x] = y;
		s.insert(make_pair(y, x));
	}
	while (!s.empty()){
		pair<int, int> cur = *s.begin();
		s.erase(s.begin());
		int u = cur.second;
		for(int i = 0; i < g[u].size(); ++i){
			int v = g[u][i];
			if (a[v] == -1) a[v] = a[u] + 1, s.insert(make_pair(a[v], v));
			else if (abs(a[v] - a[u]) != 1){
				printf("No");
				exit(0);
			}
		}
	}
	printf("Yes\n");
	for(int i = 1; i <= n; ++i) printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 11776
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  
  int sum=0;
  
  for(int i=0;i<s.size();i++){
   if(s[i]=='o'){
    sum++; 
   }
  }
  
  cout<<   (15-s.size()+sum >= 8?"YES":"NO")   <<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main(int argc, char const *argv[]) {
  int h, n;
  cin >> h >> n;
  int sum = 0;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    sum += tmp;
  }
  if (sum >= h)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
template<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}

#define MOD 1000000007
typedef long long ll;

int main(){
  int r,g,b;
  cin >> r >> g >> b;
  if((r*100+g*10+b)%4==0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
   int test;
   scanf("%d",&test);
   char arr[test];
   int tle=0,wa=0,ac=0,re=0;
   for (int i = 0; i < test; i++)
   {
      scanf("%s",arr);
      for (int i = 0; i < strlen(arr) -1; i++)
      {
         if(arr[i] == 'A' && arr[i+1] == 'C')
         {
            ac++;
         }
         if(arr[i] == 'R' && arr[i+1] == 'E')
         {
            re++;
         }
         if(arr[i] == 'W' && arr[i+1] == 'A')
         {
            wa++;
         }
          if(arr[i] == 'T' && arr[i+1] == 'L')
         {
            tle++;
         }
      
      }
   
   }
   printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n ",ac,wa,tle,re);

   
}

Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int N = 3002;
const int MOD = 998244353;

typedef long long ll;

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

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

int pw[N];
int dp[N][N];


void init() {
	pw[0] = 1;
	for (int i = 1; i < N; i++) {
		pw[i] = mul(2, pw[i - 1]);
	}
}

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

	int n, s;
	cin >> n >> s;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	int ans = 0;
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= s + 1; j++) {
			//tk
			int nw = min(s + 1, j + a[i]);
			if (j == 0) {
				dp[i + 1][nw] = i + 1;
			} else {
				dp[i + 1][nw] = add(dp[i + 1][nw], dp[i][j]);
			}
			//
			dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= s + 1; j++) {
			if (j + a[i] == s) {
				if (j > 0)
					ans = add(ans, mul(dp[i][j], n - i));
				else 
					ans = add(ans, mul(i + 1, n - i));
			}
		}
	}
	cout << ans << endl;
} 	




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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int N, Y;
  cin >> N >> Y;
  vector<int> v = {1000, 5000};
  vector<int> xyz(3, -1);
  const int m = 2000;
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= m; j++) {
      if (Y - v[0] * i - v[1] * j < 0)
        continue;
      if ((Y - v[0] * i - v[1] * j) % 10000 == 0) {
        if ((Y - v[0] * i - v[1] * j) / 10000 + i + j == N) {
          cout << (Y - v[0] * i - v[1] * j) / 10000 << ' ' << j << ' ' << i
               << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


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

int main() {
  int N;
  cin >> N;
  N = N % 10;
  if(N == 3){
    cout << "bon" << endl;
  }
  else if(N == 0 || N == 1|| N == 6 || N == 8){
    cout << "pon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))

n = onem()
a =[]

for i in range(n):
    k = list(input())
    k.sort()
    a.append(k)

a.sort()
b = s(a)

co = 0

for i in range(len(b)):
    if b[i][1] != 1:
        co += cmb(b[i][1],2)
print(co)




Measured memory_bytes: 34756
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m;
  cin  >> n >> m;
  int work = 0;
  for (int i=0; i<m; i++) {
    int x;
    cin >> x;
    work += x;
  }
  if (work > n) {
    cout << -1 << endl;
  } else {
    cout << n-work << endl;
  }
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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

int main() {
  int n;cin >>n;
  vector<int> h(n);
  rep(i,n)cin >> h[i];
  int ans=0;
  for(int i=100;i>0;i--){
    bool isg=false;
    int g=0;
    rep(j,n){
      if(h[j]==i && (!isg)){g++;isg=true;}
      if(h[j]!=i && isg){isg=false;}
      if(h[j]==i)h[j]--;

    }
    ans+=g;
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,m,x;
  cin>>n>>m>>x;
  bool va[105]={false};
  for(int i=0;i<m;i++){
    int a;
    cin>>a;
    va[a]=true;
  }
  int sum=0,som=0;
  for(int i=0;i<x;i++){
    if(va[i]==true) sum++;
  }
  for(int i=x+1;i<n;i++){
    if(va[i]==true) som++;
  }
  cout<<min(sum,som)<<'\n';
  return 0;
}


Measured memory_bytes: 256
s=input()
t=input()
len_s=len(s)
len_t=len(t)
len_n=len_s-len_t
ans=100000
for i in range(0,len_n+1):
    cnt=0
    for j in range(len_t):
        if s[i+j]!=t[j]:
            cnt+=1

    ans=min(ans,cnt)
print(ans)


Measured memory_bytes: 8984
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> A(N+1), B(N);
	for(auto&v:A)cin >> v;
	for(auto&v:B)cin >> v;
	int64_t ans = 0;
	for(int i=0;i<N;++i){
		if(A[i]<=B[i]){
			ans += A[i];
			B[i]-=A[i];
			if(A[i+1]<=B[i]){
				ans += A[i+1];
				A[i+1]=0;
			}else{
				ans += B[i];
				A[i+1]-=B[i];
			}
		} else {
			ans += B[i];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector <int> l(n);

    REP(i, n) cin >> l[i];

    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());

    int ans = 0;

    REP(i, k){
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {

      
 public static void main(String[] args) {
    
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int N = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
    int W = in.nextInt();
    int[] ws = new int[N+1];
    int[] vs = new int[N+1];
    long ans = 0;
    int sum = 0;
    
    for (int i = 0 ; i < N; ++i) {
        ws[i] = in.nextInt();
        vs[i] = in.nextInt();
        sum += vs[i];
    }
    
    long[][] dp = new long[N+1][sum+1];
    for(int i = 1; i <= sum; i++) {
        dp[0][i] = Integer.MAX_VALUE;
    }
    
    for(int i = 1 ; i <= N; i++) {
        for(int j = 0; j <= sum; j++) {
            if(j >= vs[i-1]) {
                dp[i][j] = Math.min(dp[i-1][j], ws[i-1]+ dp[i-1][j-vs[i-1]]);
            }
            else {
                dp[i][j] = dp[i-1][j];
            }
            
            if(W >= dp[i][j]) {
                ans = Math.max(ans, j);
            }
        }
    }
    
    System.out.println(ans);
  }
  
}

Measured memory_bytes: 126676
using System;
 
class Program{
	static void Main(){
		int n = int.Parse(Console.ReadLine());
		decimal d1, d2, d3, d4;

		while(n-- > 0){
			string[] s = Console.ReadLine().Split(' ');
			decimal[] p = Array.ConvertAll(s, decimal.Parse);
			d1 = p[2] - p[0];
			d2 = p[3] - p[1];
			d3 = p[6] - p[4];
			d4 = p[7] - p[5];
			Console.WriteLine(d1 * d4 - d2 * d3 == 0 ? "YES" : "NO");
		}
	}
}

Measured memory_bytes: 9276
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int n, m;
int ans = 1;

void check(int x) {
  int num = m / x;
  if (num >= n) {
    ans = max(ans, x);
  }
}

int main() { 

  cin >> n >> m;

  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      check(i);
      check(m / i);
    }
  }

  cout << ans << endl;

  return 0;
}


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

class Cube{
public:
    int f[6];
    Cube(){}
    void roll_z(){roll(1, 2, 4, 3);}
    void roll_y(){roll(0, 2, 5, 3);}
    void roll_x(){roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
        int t = f[i];
        f[i] = f[j];
        f[j] = f[k];
        f[k] = f[l];
        f[l] = t;
    }
    void move(char ch){
        if (ch == 'E')
            for (int i = 0; i < 3; i++) roll_y();
        if (ch == 'W') roll_y();
        if (ch == 'N') roll_x();
        if (ch == 'S')
            for (int i = 0; i < 3; i++) roll_x();
    }
};

int main(){
    Cube c;
    string com;

    for(int i = 0; i < 6; i++) cin >> c.f[i];
    cin >> com;

    for(int i = 0; i < com.size(); i++){
        c.move(com[i]);
    }

    cout << c.f[0] << "\n";

}


Measured memory_bytes: 3212
//
//  main.cpp
//  testDebbug
//
//  Created by Manikanta Nallagatla on 18/02/20.
//  Copyright © 2020 Manikanta Nallagatla. All rights reserved.
//
// testDebug.cpp : Defines the entry point for the console application.
//
 
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<set>
#include<functional>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include <fstream>
#include <math.h>
 
using namespace std;
 
 
 
struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
struct TreeLinkNode
{
    int val;
    TreeLinkNode *left;
    TreeLinkNode *right;
    TreeLinkNode *next;
    TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
};
struct ListNode
{
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};
 
template <class T>
void printv1(T v)
{
    cout << v << endl;
}
 
 
template <class T>
void printv2(vector<T> v)
{
    for (auto x : v) {
        cout<<x<<endl;
    }
    cout << endl;
}
 
template <class T>
void printv3(vector<vector<T>> v)
{
    for (auto x : v) {
        for (auto y : x) {
            cout << y << " ";
        }cout << endl;
    }
}
 
void printv4(vector<string> v)
{
    for (auto x : v) {
        for (auto y:x )
        {
            cout << char(y+int('0')) << " ";
        }
        cout << endl;
    }
    cout << endl;
}
 
static auto magic = []() {ios_base::sync_with_stdio(false); cin.tie(nullptr); return false; }();
 
#define POD 1000000007
#define ll long long int
 
 
 
 
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    
    float r;
    cin>>r;
    cout<<(3.1416*r*2)<<endl;
    return 0;
}

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

int main(){
    ll h, w;    cin >> h >> w;
    ll sum=1;
    if(h!=1 && w!=1){    
        sum =  h/2*w;
        if(h%2==1)
            sum += w/2+w%2;
    }
    cout << sum << endl;
}

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

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();}
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);}
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}
 
int solve(int n,int c,Vi x,Vi v){
    Vi af(n+1,-INF);
    af[0]=0;
    int nowv=0,nowd=0;
    REP(i,1,n+1){
        nowv += v[i];
        nowd += (x[i]-x[i-1]);
        af[i]=max(af[i-1],nowv-nowd);
    }

    Vi bf(n+1,-INF);
    bf[0]=0;
    nowv=0,nowd=0;
    REP(i,1,n+1){
        nowv += v[n+1-i];
        nowd += (x[n+2-i]-x[n+1-i]);
        bf[i]=nowv-2*nowd;
    }
    int ret=-INF;
    REP(i,0,n+1){
        chmax(ret,bf[i]+af[n-i]);
    }
    // vout(af);
    // vout(bf);
    return ret;
}


signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
    int n,c;
    cin>>n>>c;
    Vi x(n+2),v(n+2);
    REP(i,1,n+1) cin>>x[i]>>v[i];
    x[n+1]=c;

    Vi x2(n+2),v2(n+2);
    REP(i,0,n+2){
        v2[i]=v[n+1-i];
        x2[i]=c-x[n+1-i];
    }
    // vout(x2);
    // vout(v2);
    cout<<max(solve(n,c,x,v),solve(n,c,x2,v2))<<endl;    
    return 0;
}


Measured memory_bytes: 8032
import sys


def slove():
    input = sys.stdin.readline
    l, r = list(map(int, input().rstrip('\n').split()))
    mt = 10 ** 10
    for i in range(l, r + 1):
        for j in range(i + 1, r + 1):
            mt = min(mt, (i * j) % 2019)
            if mt == 0:
                print(mt)
                exit()
    print(mt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38768