akhauriyash/Code-Regression huggingface dataset:
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/
#include <bits/stdc++.h>
#define newline ("\n")
#define deb(x) cerr << (#x) << " = " << (x) << '\n'
#define FOR(x, n) for (int x = 0; x < n; x++)
#define PI (3.141592653589)

#define MOD 1000000007
using namespace std;

long long weight[101], value[101];

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

    // Pikachu, I choose you
    int n,w;
    cin >> n >> w;
    for(int i = 1;i<=n;i++)
    {
        cin >> weight[i];
        cin >> value[i];
    }
    long long dp[100001];
    for(int i = 0;i<100001;i++)
    {
        dp[i] = LONG_LONG_MAX;
    }
    dp[0] = 0;
    for(int i = 1;i<=n;i++){
        for(int j = 100000;j>=value[i];j--)
        {
            if(dp[j - value[i]] != LONG_LONG_MAX)
            {
                dp[j] = min(dp[j], dp[j - value[i]] + weight[i]);
            }
        }
    }
    for(int i = 100000;i>=0;i--)
    {
        if(dp[i] <= w)
        {
            cout << i ;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>

int main(){
	int a, b, c, d, e;
	std::cin >> a >> b >> c >> d >> e;
	int sum = 0;
	sum += (a > 40 ? a : 40) + (b > 40 ? b : 40) + (c > 40 ? c : 40) + (d > 40 ? d : 40) + (e > 40 ? e : 40);
	std::cout << sum / 5 << std::endl;
	return 0;
}

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

int main(){
	int n1,n2,S[5],cnt=0;
	cin>>n1>>n2;
	for(int i=n1;i<=n2;i++){
		int tmp=i;
		int j=4;
		while(tmp>0){
			S[j]=tmp%10;
			tmp/=10;
			j--;
		}
		if (S[0]==S[4]&&S[1]==S[3])cnt++;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

int n, m;
int p[1000];
int ans;
vector<int> v;

void solve(){
	ans = 0;
	v.clear();
	v.push_back(0);
	for(int i = 0; i < n; i++){
		scanf("%d", &p[i]);
		if(p[i] <= m) v.push_back(p[i]);
	}
	sort(v.begin(),v.end());
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[i]+p[j] <= m) v.push_back(p[i]+p[j]);
		}
	}
	sort(v.begin(),v.end());
	int j = v.size()-1;
	for(int i = 0; i < v.size(); i++){
		while(true){
			if(v[i]+v[j] <= m){
				ans = max(ans,v[i]+v[j]);
				break;
			}
			j--;
		}
	}
	printf("%d\n", ans);
}

int main(){
	while(scanf("%d%d", &n, &m),n||m) solve();
}

Measured memory_bytes: 6616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

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

	long double a,b,x,pi,ans;
	pi=acos(-1);
	cin>>a>>b>>x;
	if((a*a*b)/2.0<=x)
		ans=atan((2.0*(a*a*b-x))/(a*a*a));
	else
		ans=pi/2-atan((2.0*x)/(a*b*b));
	ans=(ans*180.0)/pi;
	cout<<fixed<<setprecision(10)<<ans<<endl;

	
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N,M,V,P; cin >> N >> M >> V >> P;
    vector <ll> A(N);
    vector <ll> pfxsum(N);
    loop(i,0,N) cin >> A[i];
    sort(A.begin(), A.end());
    pfxsum[0]=A[0];
    loop(i,1,N) pfxsum[i]=pfxsum[i-1]+A[i];
    ll ans=P;
    ll index=N-P-1;
    while (index>=0)
    {
        if (index>N-P-1) ans++;
        else if (A[index]+M<A[N-P]) break;
        else if ((P+index)>=V) ans++;
        else  {
            int balance=V-(P+index);
            ll tsum = pfxsum[N-P]-pfxsum[index];
            ll ub=A[index]+M;
            if ((N-P-index)*ub - tsum >= balance*M ) ans++; 
        }
        index--;
    }
    cout << ans << "\n";
    return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

string S;

struct info{
    int val,nes,al;
    info(int val,int nes,int al):val(val),nes(nes),al(al){}
    info(){}
};

info solve(int l,int d,int u){
    if(S[l]=='0'){
        return info(0,l+1,l+1);
    }
    if(isdigit(S[l])){
        info t;
        t.val=S[l]-'0';
        t.nes=l+2;
        if(isdigit(S[l+1])){
            t.val=t.val*10+S[l+1]-'0';
            t.al=l+2;
        }
        else t.al=l+1;

        d++;
        u--;
        if(d/10>S[l]-'0'){
            t.nes=l+1;
        }
        if(u/10<S[l]-'0'&&u<S[l]-'0')t.nes=l+1;
        return t;
    }

    if(S[l]=='^'){
        l+=2;
        info t=solve(l,d,u);
        if(t.val>=u){
            info s=solve(t.al+1,d,u);
            return info(u,t.nes,s.al+1);
        }
        info s=solve(t.al+1,max(d,t.val),u);
        return info(max(t.val,s.val),s.nes,s.al+1);
    }

    l+=2;
    info t=solve(l,d,u);
    if(t.val<=d){
        info s=solve(t.al+1,d,u);
        return info(d,t.nes,s.al+1);
    }
    info s=solve(t.al+1,d,min(u,t.val));
    return info(min(t.val,s.val),s.nes,s.al+1);
}

signed main(){
    int Q;
    cin>>Q;
    while(Q--){
        cin>>S;
        info t=solve(0,0,99);
        cout<<t.val<<" "<<t.nes<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
bool dp[366][16][8][8][8][8];
int dx[]={-2,2,-1,1,0,0,0,0,0};
int dy[]={0,0,0,0,1,-1,0,2,-2};
int t[366][17],p[4],n;
main(){
  while(cin>>n,n){
    int ans=0;
    memset(dp,0,sizeof(dp));
    r(i,n)r(j,16)cin>>t[i][j];
    dp[0][5][1][1][1][1]=1;
    r(a,n-1)r(b,16)r(c,7)r(d,7)r(e,7)r(f,7)
    if(dp[a][b][c][d][e][f]){
      int x1=b%4,y1=b/4;
      r(i,9){
        int x=x1+dx[i],y=y1+dy[i],flag=0;
        if(x<0||y<0||2<x||2<y)continue;
        p[0]=y*4+x,p[1]=y*4+x+1;
        p[2]=(y+1)*4+x,p[3]=(y+1)*4+x+1;
        r(k,4)if(t[a+1][p[k]])flag++;
        if(!flag){
          if(p[0]==0)dp[a+1][p[0]][0][d+1][e+1][f+1]=1;
          else if(p[0]==2)dp[a+1][p[0]][c+1][0][e+1][f+1]=1;
          else if(p[0]==8)dp[a+1][p[0]][c+1][d+1][0][f+1]=1;
          else if(p[0]==10)dp[a+1][p[0]][c+1][d+1][e+1][0]=1;
          else dp[a+1][p[0]][c+1][d+1][e+1][f+1]=1;
        }
      }
    }
    r(b,16)r(c,7)r(d,7)r(e,7)r(f,7)
      if(dp[n-1][b][c][d][e][f])ans++;
    if(t[0][5]||t[0][6]||t[0][9]||t[0][10])ans=0;
    cout<<(ans?1:0)<<endl;
  }
}

Measured memory_bytes: 26540
import bisect,collections,copy,heapq,itertools,math,operator,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
x1,y1,x2,y2 = LI()
vector = (x2-x1,y2-y1)
x3,y3 = x2-vector[1],y2+vector[0]
x4,y4 = x1-vector[1],y1+vector[0]
print(x3,y3,x4,y4)


Measured memory_bytes: 4012
// Problem : C - Repsept
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#define _CRT_SECURE_NO_WARNINGS
#include <queue>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
	int k;cin >> k;
	int a = 7,res = 0,ok = 1;
	while(a % k != 0)
	{
		a = (a * 10 + 7) % k;
		++res;
		if(res == 1e7 + 7)	break;
	}	
	if(a % k == 0)	cout << res+1;
	else cout << -1;
    return 0;
}


Measured memory_bytes: 3192
import java.io.IOException;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) throws IOException {
		
		Scanner sc = new Scanner(System.in);
		Long a = Long.parseLong(sc.next());
		Long b = Long.parseLong(sc.next());
		Long c = Long.parseLong(sc.next());
		
		String ans = "No";
		
		Long d = a * b * 4;
		Long e = (c - a - b);
		if(e > 0) {
			   e = e * e;
		}
		
		if(d  < e) {
			ans = "Yes";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL =LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

ll gcb(ll a, ll b){/// ユークリッドの互除法: O(log)
    
    if(b == 0) return a;
    
    return gcb(b,a%b);
}


ll lcm(ll a, ll b){
    
    return  a/gcb(a,b) * b; ///gcbは約数
}


int main() {
    string s;cin>>s;
    
    ll ans = 0;
    ll wc=0;
    for(auto i = 0;i<s.size();i++){
        
        if(s[i]=='W'){ans+=i-wc; wc++;}
        
    }
    
    cout<<ans<<endl;
    
    return 0;
}










Measured memory_bytes: 640
#create date: 2020-06-27 21:00

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def g(n):
    return n * (n+1) // 2

def main():
    n = ni()
    ans = 0
    for i in range(1, n+1):
        ans += i * g(n//i)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9196
#include <stdio.h>

int main(void){

  int n;
  scanf("%d\n", &n);
  char s[n];
	for (int i = 0; i < n-1; i++) {
		scanf("%c ", &s[i]);
	}
	scanf("%c", &s[n-1]);

	int flag = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'Y') {
			flag = 1;
			break;
		}
	}
	if (flag == 0) {
		printf("Three\n");
	} else {
		printf("Four\n");
	}

  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
using namespace std;
typedef long long ll;
const int maxn=1000050;
int prime[maxn];
int a[maxn];
bool isprime[maxn];
int beused[maxn];
int n,cnt;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
void init(){
	cnt=0;
	for(int i=2;i<maxn;i++){
		if(!isprime[i])	prime[++cnt]=i;
		for(int j=1;j<=cnt;j++){
			if(i*prime[j]>=maxn)	break;
			isprime[i*prime[j]]=1;
			if(i%prime[j]==0)	break;
		}
	}
}
void solve(){
	init();
	scanf("%d",&n);
	int GCD=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		beused[a[i]]++;
		GCD=gcd(GCD,a[i]);
	}
	int flag=1;
	for(int i=1;i<=cnt;i++){
		int tot=0;
		for(int j=prime[i];j<maxn;j+=prime[i])	tot+=beused[j];
		if(tot>=2){
			flag=0;break;
		}
	}
	if(flag)	printf("pairwise coprime\n");
	else if(!flag&&GCD==1)	printf("setwise coprime\n");
	else	printf("not coprime\n");
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 12744
# frozen_string_literal: true

# ENV[Z = 'RUBY_THREAD_VM_STACK_SIZE'] || exec( { Z => '50000000' },'ruby',$0)
s = gets.chomp!
q = gets.to_i
array = readlines.map(&:chomp!).map(&:split)

count = 0
sentou = []
matubi = []
array.each do |command|
  case command.first
  when '1'
    count += 1
  when '2'
    if count.even?
      if command[1] == '1'
        sentou.push command[2]
      else
        matubi.push command[2]
      end
    else
      if command[1] == '1'
        matubi.push command[2]
      else
        sentou.push command[2]
      end
    end
  end
end

if count.odd?
  s.reverse!
  puts matubi.join.reverse! + s + sentou.join
else
  puts sentou.join.reverse! + s + matubi.join
end



Measured memory_bytes: 49972
#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n,d; cin >> n >> d;
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(i%(2*d+1) == 0) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(ll i=a;i<b;i++)
#define rFor(i,a,b) for(ll i=a;i>b;i--)
#define wFor(i,a,b) for(ll i=a;i<b;i+=2)
#define wrFor(i,a,b) for(ll i=a;i>b;i-=2)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//(char-'0') 数字に変換
//vector<vector<int>> data(a,vector<int>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a,b;
  ci(a>>b);
  if(a<10&&b<10)
    co(a*b);
  else
    co(-1);
}

Measured memory_bytes: 768
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<string.h>
#include<map>

using namespace std;

#define ll long long 


int main(){

    ll n,w;
    cin>>n>>w;

    ll weight[n+1],value[n+1];    

    for(int i=1;i<=n;i++){
        cin>>weight[i]>>value[i];
    }

    ll dp[n+1][w+1];

    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(i==0 || w==0) dp[i][j] = 0;
            else{
                dp[i][j] = dp[i-1][j];
                if(weight[i]<=j) dp[i][j] = max(dp[i][j],value[i] + dp[i-1][j-weight[i]]);
            }
        }
    }

    cout<<dp[n][w];

    return 0;
}

Measured memory_bytes: 82464
#include <bits/stdc++.h>
using namespace std;
#define ll long long
double h[1009];
int main(){
  int n;
  double t,a;
  cin >> n;
  cin >> t >> a;
  for(int i=0;i<n;i++) cin >> h[i];
  int ret = 1;
  double temp = abs(a - (t - h[0]*0.006));
  for(int i=1;i<n;i++){
    if(abs(a - (t-h[i]*0.006)) < temp){
      ret = i+1;
      temp = abs(a - (t-h[i]*0.006));
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int inf = 2e18;  
const int mod1 = 998244353;
const int mod = 1e9 + 7;
const int nax = 300005;
int r[nax],c[nax],m,h,w;
set<pii> targets;
void solve()
 {
  cin>>h>>w>>m;
  loop(i,0,m)
   {
    int y,x;
    cin>>y>>x;
    r[y]++;
    c[x]++;
    targets.insert({y,x});
   }
   int idy = max_element(r,r+nax) - r;
   int idx = max_element(c,c+nax) - c;
   int ans = 0;
   loop(i,1,nax)
    {
      int res1 = r[i] + c[idx] - targets.count({i,idx});
      int res2 = r[idy] + c[i] - targets.count({idy,i});
      ans = max({ans,res1,res2});
    }
   cout<<ans;
 }
signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
  /*int t;
  cin>>t;
  while(t--)*/
  solve();
  // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
} 

Measured memory_bytes: 27080
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, K = list(map(int, sys.stdin.buffer.readline().split()))
R, S, P = list(map(int, sys.stdin.buffer.readline().split()))
T = sys.stdin.buffer.readline().decode().rstrip()


def solve(T):
    N = len(T)
    if N == 0:
        return 0
    # dp[i][c]: i 番目に c を出したときのそれまでのスコアの最大値
    dp = [[0, 0, 0] for _ in range(N)]
    dp[0][0] = R if T[0] == 's' else 0
    dp[0][1] = S if T[0] == 'p' else 0
    dp[0][2] = P if T[0] == 'r' else 0
    for i, cpu in enumerate(T[1:], start=1):
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + R * int(cpu == 's')
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + S * int(cpu == 'p')
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + P * int(cpu == 'r')
    return max(dp[-1])


ans = 0
for k in range(K):
    ans += solve(T[k::K])
print(ans)


Measured memory_bytes: 62064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  string a, b; cin >> a >> b;
  string ab = a + b;
  int x = stoi(ab);
  
  repi(i,1,1000) {
    if (i*i == x) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

using ll = long long;

void solve(long long H, long long W, long long M, std::vector<long long> h, std::vector<long long> w){
    vector<int> wcount(W);
    map<int, vector<int>> mp;
    multiset<int> se;
    for(int i = 0;i < M;i++){
        h[i]--, w[i]--;
        wcount[w[i]]++;
        mp[h[i]].push_back(w[i]);
        
    }
    int ans = 0;
    for(int i = 0;i < W;i++){
        se.insert(wcount[i]);
    }
    se.insert(0);
    for(int i = 0;i < H;i++){
        //cout<<i<<endl;
        vector<int> v = mp[i];
        for(auto a : v){
            se.erase(se.find(wcount[a]));
            se.insert(wcount[a] - 1);
        }
        int cnt = v.size() + *se.rbegin();
        //cout<<i<<" "<<cnt<<" "<<v.size()<<" "<<*se.rbegin()<<endl;
        ans = max(cnt, ans);
        for(auto a : v){
            se.erase(se.find(wcount[a] - 1));
            se.insert(wcount[a]);
        }
    }
    cout<<ans<<endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> h(M);
    std::vector<long long> w(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&h[i]);
        scanf("%lld",&w[i]);
    }
    solve(H, W, M, std::move(h), std::move(w));
    return 0;
}


Measured memory_bytes: 56048
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"
#include "cmath"
#include "set"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

int main()
{
  string first = "X";
  string s;
  cin >> s;
  string srev = s;
  reverse(srev.begin(), srev.end());
  int q;
  cin >> q;
  int que;
  bool rev = true;
  for (int i = 0; i < q; i++)
  {
    cin >> que;
    if (que == 1)
    {
      rev = !rev;
    }
    else
    {
      int f;
      cin >> f;
      string c;
      cin >> c;
      if ((rev && f == 1) || (!rev && f == 2))
      {
        first = c + first;
      }
      else
      {
        first = first + c;
      }
    }
  }
  int size = first.size();
  if (!rev)
  {
    reverse(first.begin(), first.end());
  }
  for (int i = 0; i < size; i++)
  {
    if (first[i] == 'X')
    {
      if (rev)
      {
        cout << s;
      }
      else
      {
        cout << srev;
      }
    }
    else
    {
      cout << first[i];
    }
  }
  cout << "\n";
}

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

int main()
{
    int N;
    int A[200];

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

    int res = 0;
    bool exist_odd = false;

    while (true)
    {
        for (int i = 0; i < N; i++)
        {
            if (A[i] % 2 == 1)
            {
                exist_odd = true;
            }
            A[i] /= 2;
        }

        if (exist_odd)
        {
            break;
        }
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 3e18;
const ll fact_table = 1200008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

// インタラクティブ問題の時はこのdefineを外してください
#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
const ll mod = 998244353ll;
// const ll mod = 1000000007ll;
  
ll mypow(ll number1,ll number2, ll mod){
    if(number2 == 0){
        return 1ll;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
/*

ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    assert(n >= r);
    assert(n >= 0);
    assert(r >= 0);
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
bool multicase = false;

ll n,m,num,a,b,c,d,e,q, ans;
ll x[500005], y[500005], z[500005];
string s;

void solve(){
    ll k;
    cin >> k >> s;
    if(s.size() <= k){
        p(s);
    }else{
        pu(s.substr(0, k));
        pu("...");
        el;
    }
    return;
}

int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if(multicase){
        cin >> q;
    }else{
        q = 1; 
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}
















Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
const long long INF = numeric_limits<long long>::max();

int main(void) {
    string s; cin >> s;
    int c = 0;

    for (int i = 0; i < 3; i++) {
        if (s[i] == '1') c++;
    }

    cout << c << endl;

    return 0;
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
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);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};




template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}




int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, ma, mb;
    cin >> n >> ma >> mb;

    int a[n], b[n], c[n];
    rep(i, n){
        cin >> a[i] >> b[i] >> c[i];

    }

    int dp[n+1][401][401];
    fill_n(**dp, (n+1)*401*401, INF);





    dp[0][0][0] = 0;

    rep(i, n){
        rep(ca, 401){
            rep(cb, 401){
                if(dp[i][ca][cb] == INF) continue;
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb]);
                dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);

            }
        }
    }

    int ans = INF;
    FOR(ca, 1, 401){
        FOR(cb, 1, 401){
            if(ca*mb == cb*ma)
                ans = min(ans, dp[n][ca][cb]);
        }
    }


    if(ans == INF)
        ans = -1;

    ppp(ans);



    return 0;
}


Measured memory_bytes: 25984
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        if(N/100 == N%10){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }       
}

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

int main() {
  int x, y;
  cin >> x >> y;
  int g[12] = { 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
  if (g[x - 1] == g[y - 1]) {
    puts("Yes");
  } else {
    puts("No");
  }
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace DigitsParades
{

    class Programk
    {
        static void Main(string[] args)
        {
            var NAB = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var N = NAB[0];
            var A = NAB[1];
            var B = NAB[2];

            long ans = (N / (A + B)) * A;
            ans += Min(N-(N / (A + B)) * (A + B),A);
            Console.WriteLine(ans);
            //  var NM = Console.ReadLine();
        }
    }

    #region スキャナー
    class Scanner
    {
        public Scanner()
        {
            _pos = 0;
            _line = new string[0];
        }

        const char Separator = ' ';
        private int _pos;
        private string[] _line;

        #region スペース区切りで取得

        public string Next()
        {
            if (_pos >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _pos = 0;
            }

            return _line[_pos++];
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }

        #endregion

        #region 型変換

        private int[] ToIntArray(string[] array)
        {
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        private long[] ToLongArray(string[] array)
        {
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }

        private double[] ToDoubleArray(string[] array)
        {
            var result = new double[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = double.Parse(array[i]);
            }

            return result;
        }

        #endregion

        #region 配列取得

        public string[] Array()
        {
            if (_pos >= _line.Length)
                _line = Console.ReadLine().Split(Separator);

            _pos = _line.Length;
            return _line;
        }

        public int[] IntArray()
        {
            return ToIntArray(Array());
        }

        public long[] LongArray()
        {
            return ToLongArray(Array());
        }

        public double[] DoubleArray()
        {
            return ToDoubleArray(Array());
        }

        #endregion
    }
    #endregion  

}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const double PI=3.14159265358979323846;
int main() {
    int n;
    cin >> n;
    vector <int> s(n);
    for(int i=0;i<n;++i) cin >> s[i];
    vector <int> a(n);
    for(int i=0;i<n;++i) {
        a[s[i]-1]=i+1;
    }
    for(int i=0;i<n;++i) cout << a[i] << endl;
}
    


Measured memory_bytes: 1536
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    ll a,b,c,k;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &k);

    if(k%2==0) {
        printf("%lld\n", a-b);
    }
    else {
        printf("%lld\n", (b+c)-(a+c));
    }
    return 0;
}


Measured memory_bytes: 128
from bisect import bisect_left

n,q=map(int,input().split())
work=[list(map(int,input().split())) for _ in range(n)]
work=sorted(work,key=lambda x:x[2])
pos=[int(input()) for _ in range(q)]
ans=[-1]*q
checked=[-1]*q
for s,t,x in work:
  l=bisect_left(pos,s-x)
  r=bisect_left(pos,t-x)
  while l<r:
    if checked[l]==-1:
      checked[l]=r
      ans[l]=x
      l+=1
    else:
      l=checked[l]
for i in ans:
  print(i)

Measured memory_bytes: 74128
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cctype>
using namespace std;
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}

const int maxn = 305;
int n , m , a[maxn][maxn] , cnt[maxn];
bool vis[maxn];
int main()
{
	n = read() , m = read();
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++)
			a[i][j] = read();
	int ans = n;
	for(int i = 1; i <= m; i ++) vis[i] = 1;
	for(int t = 1; t < m; t ++)
	{
		memset(cnt , 0 , sizeof(cnt));
		for(int i = 1; i <= n; i ++)
			for(int j = 1; j <= m; j ++)
			{
				if(vis[a[i][j]])
				{
					++ cnt[a[i][j]];
					break;
				}
			}
		int mx = 0 , pos = 0;
		for(int i = 1; i <= m; i ++) if(vis[i])
		{
			if(mx <= cnt[i]) mx = cnt[i] , pos = i;
		}
		ans = min(ans , mx); vis[pos] = 0;
	}
	printf("%d\n" , ans);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  //in
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> a(n);
  REP(i,n) cin >> x[i] >> y[i] >> a[i];
  
  //xl, xr, yl, yrの範囲を決めていく
  //4点の初期位置を決定
  int xl, xr, yl, yr;
  xl = 0;
  xr = w;
  yl = 0;
  yr = h;  
//REP で4点を更新max, min
  REP(i,n){
    if(a[i] == 1){
      xl = max(xl, x[i]);
    }
    if(a[i] == 2){
      xr = min(xr, x[i]);
    }
    if(a[i] == 3){
      yl = max(yl, y[i]);
    }
    if(a[i] == 4){
      yr = min(yr, y[i]);
    } 
  }

  //仮にr - l <= 0 ならば0

  if(xr - xl <= 0 || yr - yl <= 0){
    cout << 0 << endl;
    return 0;
  }

  //出力
  int ans = (xr - xl) * (yr - yl);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  ll N;
  cin>>N;
  ll a[N+1];
  for(ll i = 0;i<N+1;i++){
    cin>>a[i];
  }
  ll b[N];
  for(ll i = 0;i<N;i++){
    cin>>b[i];
  }
  ll ans = 0;
  for(ll i = 0;i<N;i++){
    if(b[i]>a[i]){
      b[i] -= a[i];
      ans+=a[i];
      a[i] = 0;
      if(b[i]>a[i+1]){
        ans+=a[i+1];
        a[i+1] = 0;
      }
      else{
        a[i+1] -= b[i];
        ans+=b[i];
      }
    }
    else{
      a[i] -= b[i];
      ans += b[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
"""
区間ごとに前処理しておけばよい
"""
#memo[i][j] => iから出発し、jまでのどこかで終点する電車の数
N,M,Q = map(int,input().split())
memo = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    l,r = map(int,input().split())
    for j in range(r,N+1):
        memo[l][j] += 1

for _ in range(Q):
    p,q = map(int,input().split())
    ans = 0
    for i in range(p,q+1):
        ans += memo[i][q]
    print(ans)

Measured memory_bytes: 78728
#include<bits/stdc++.h>
#define     ll          long long
#define     MOD         10e9+7
#define     pb          push_back
#define     vll         vector<long long>
#define     vi          vector<int>
#define     vl          vector<long>
#define     pii         pair<int, int>
#define     all(a)      (a).begin(),(a).end()
#define     rep(i,a,b)  for(int i=a;i<b;i++)
#define     MAX         100002 
#define     ios	      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main() {
    
      string s;
      cin >> s;
      if(s=="ARC")cout << "ABC\n";
      else cout << "ARC\n";
	return 0;
}




Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h){
    cin >> s[i];
    cout << s[i] << endl;
    cout << s[i] << endl;
  }
}

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[] a = new int[2 * N];
    int[] b = new int[2 * N];

    for (int i=0; i < N; i++) {
      int input = sc.nextInt();
      a[input] = sc.nextInt() + 1;
    }

    for (int i=0; i < N; i++) {
      int input = sc.nextInt();
      b[input] = sc.nextInt() + 1;
    }

    int count = 0;

    for (int i=0; i < 2*N; i++) {
      if (b[i] == 0) continue;

      int tmp_min = Integer.MAX_VALUE;
      int tmp_j = 2*N;
      boolean f = false;

      for (int j=i-1; j >= 0; j--){
        if (a[j] != 0) {
          if (b[i] - a[j] > 0 && b[i] - a[j] < tmp_min) {
            tmp_min = b[i] - a[j];
            tmp_j = j;
            f = true;
          }
        }
      }

      if (f) {
        a[tmp_j] = 0;
        count++;
        f = false;
      }
    }

    System.out.println(count);
  }
}


Measured memory_bytes: 23892
h,w = map(int,input().split())
s = [input() for _ in range(h)]

def countSharp(x,y):
    res = 0
    if x!=0:
        res += s[x-1][y]=='#'
    if y!=0:
        res += s[x][y-1]=='#'
    if x!=h-1:
        res += s[x+1][y]=='#'
    if y!=w-1:
        res += s[x][y+1]=='#'
    return res

flag = [[False for _ in range(w)] for oijqd in range(h)]
for i,l in enumerate(s):
    for j,c in enumerate(l):
        if c=='.':
            flag[i][j] = True

for i in range(h):
    for j in range(w):
        if s[i][j]=='#' and countSharp(i,j)>0:
            flag[i][j] = True
            if i!=0:
                flag[i-1][j] = True
            if j!=0:
                flag[i][j-1] = True
            if i!=h-1:
                flag[i+1][j] = True
            if j!=w-1:
                flag[i][j+1] = True

res = True
for l in flag:
    if False in l:
        res = False
        break

print('Yes' if res else 'No')


Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
  int N,i;
  scanf("%d",&N);
  int A[N+1],B[N];
  unsigned long long int ans=0;
  for(i=0;i<=N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<N;i++){
    scanf("%d",&B[i]);
  }
  for(i=0;i<N;i++){
    if(A[i]<B[i]){
      B[i]=B[i]-A[i];
      ans=ans+A[i];
      if(A[i+1]<B[i]){
        ans=ans+A[i+1];
        A[i+1]=0;
      }
      else{
        ans=ans+B[i];
        A[i+1]=A[i+1]-B[i];
      }
    }
    else{
      ans=ans+B[i];
      B[i]=0;
    }
  }
  printf("%llu",ans);
  return 0;
}

Measured memory_bytes: 896
#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;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,t;cin >> n >> t;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    int dp[n+1][t][2]={};
    for(int i=0;i<n;i++){
        for(int j=0;j<t;j++){
            chmax(dp[i+1][j][0],dp[i][j][0]);
            chmax(dp[i+1][j][1],dp[i][j][1]);
            if(j+a[i]<t){
                chmax(dp[i+1][j+a[i]][0],dp[i][j][0]+b[i]);
                chmax(dp[i+1][j+a[i]][1],dp[i][j][1]+b[i]);
            }
            chmax(dp[i+1][j][1],dp[i][j][0]+b[i]);
        }
    }
    int ans=0;
    for(int i=0;i<t;i++){
        chmax(ans,max(dp[n][i][0],dp[n][i][1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 70656
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define MOD 1000000007
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;
typedef unordered_map<int, int> Hash;

// ---
const int Nlim = 200, Xlim = POW_10_5;
int N, X;
int S[Nlim];
int dp[Xlim+1][Nlim+1];

int Ans(int x, int i) {
  if (dp[x][i] != -1) { return dp[x][i]; }
  if (i == N-1) { dp[x][i] = x % S[N-1]; return x % S[N-1]; }

  int ans = 0;
  ans += Ans(x % S[i], i+1);
  ans %= MOD;

  ans += Ans(x, i+1) * (N - (i + 1));
  ans %= MOD;

  dp[x][i] = ans; return ans;
}

signed main() {
  cin >> N >> X;
  REP(i, N) { cin >> S[i]; }

  sort(S, S+N, greater<int>());
  REP(i, Xlim+1) {
    REP(j, Nlim+1) {
      dp[i][j] = -1;
    }
  }
  auto ans = Ans(X, 0);

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 157312
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]
count = 0
for n in range(N):
  cost = 0
  for m in range(M):
    cost += A[n][m]*B[m]
  if cost + C > 0:
    count += 1
print(count)

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    int ca = 0, cb = 0;
    rep(i, n){
        if (s[i] == 'a'){
            if (ca + cb < a + b){
                ca ++;
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
        else if (s[i] == 'b') {
            if (ca + cb < a + b && cb < b){
                cb ++;
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 123;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int a[N];

void solve(){
    int k;
    cin >> k;
    vector<ll> q;
    for (int i = 1; i < 10; i++ )q.pb(i);
    int i = 0;
    while (sz(q) < k){
        ll x = q[i++];
       // cout << x << endl;
        int d = x % 10;
        x *= 10;
        if (d > 0){
            q.pb(x+d-1);
        }
        q.pb(x+d);
        if (d < 9){
            q.pb(x+d+1);
        }
    }
    cout << q[k-1];
}

int main(){
    #ifdef KAZAKH
       // freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++){
        //cout << "case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 1400
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<"IMPOSSIBLE"<<endl;return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
//19234567892927;
const int mod=1e9+7;
const llint big=1e13+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	int n,i,j,ans=0;cin>>n;
	vector<pair<int,int>>hi(n);
	for(i=0;i<n;i++){
		int h,p;cin>>h>>p;
		hi[i]=mp(h+p,h);
	}
	sort(hi.begin(),hi.end());
	static int dp[5005];
	for(j=1;j<=5004;j++){dp[j]=mod;}
	for(i=0;i<n;i++){
		int h=hi[i].sec,p=hi[i].fir-hi[i].sec;
		for(j=i;j>=0;j--){
			if(dp[j]<=h){mineq(dp[j+1],dp[j]+p);maxeq(ans,j+1);}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second
#define pii pair<int, int>

const int N = 2001;
const ll mod = 1e9 + 7;

ll dp[N];

ll f(int S) {
    if (S == 0)
        return 1;
    if (dp[S] != -1)
        return dp[S];

    ll ans = 0;
    for (int i = 3; i <= S; i++)
        ans = (ans + f(S - i)) % mod;
    return dp[S] = ans;
}

void solve() {
    int s;
    cin >> s;
    fill(dp, dp + N, -1);
    cout << f(s) << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


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

int main() {
  
  string a, b, c;
  cin >> a >> b >> c;
  
  int ai = a.size() - 1;
  int bi = b.size() - 1;
  
  
  if (a[ai] == b[0] && b[bi] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;

}

Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあって そんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/pavan/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
	FIO
	
	int n;cin >> n;
	set<int> s;
	forn(i, n){int x;cin >> x;s.insert(x);}
	if(s.size() == n)puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>
#include <stdlib.h>
int asc(const void *a,const void *b){
    return *(int*)a-*(int*)b;
}
int main(void){
    int n,i;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    qsort(a,n,sizeof(int),asc);
    for(i=0;i<n-1;i++){
        if(a[i]==a[i+1]){
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}

Measured memory_bytes: 1788