akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int X, Y, Z; cin >> X >> Y >> Z;
    int ans = X / (Y + Z);
    if(ans*(Y+Z)+Z > X) ans--;
    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]

# print(A)
sorted_A = sorted(A)
max_A = sorted_A[-1]
second_max_A = sorted_A[-2]

for i in range(N):
    if A[i] != max_A:
        print(max_A)
    else:
        print(second_max_A)



Measured memory_bytes: 14152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}
//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}

struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(9);
    }
} All_init;


int main()
{

    string s;
    cin>>s;
    ll w;
    cin>>w;
    for(ll i=0;i<s.size();i+=w){
        cout<<s[i];
    }
    cout<<endl;



    
}


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

int X[100100],Y[100100];
int dp[100100];

int main(){
	int h,w,k,a;
	
	cin >> h >> w >> k;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> a;
			X[a]=i,Y[a]=j;
		}
	}
	
	for(int i=k+1;i<=h*w;i++){
		dp[i]= dp[i-k] + abs(X[i]-X[i-k])+abs(Y[i]-Y[i-k]);
	}
	
	int q,l,r;
	cin >> q;
	while(q--){
		cin >> l >> r;
		cout << dp[r]-dp[l] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2176
<?php
fscanf(STDIN, '%d', $x);
$ans = 1;
for($b = 2; $b <= $x; $b++) {
    $power = $b * $b;
    for($p = 2; ; $p++) {
        if($power > $x) break;
        $ans = max($ans, $power);
        $power *= $b;
    }
}
echo $ans. "\n";

Measured memory_bytes: 4728
#include<vector>
#include<queue>
#include<iostream>
#include<set>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
long long n, x, y, m, k, c = 0, l=0;
set<int>s1, s2, s3;
queue<long long>v1, v2;
int main()
{
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != t[i])
			c++;
	}
	cout << c;
}

Measured memory_bytes: 3848
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiConsumer;

public class Main {

    //グローバル変数を定義

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

    void run() {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int count = 0;

        for(int i=1; i<=k; i+=2){
            for(int j=2; j<=k; j+=2){
                count++;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 23124
n, m = map(int, input().split())

cnt = [0 for i in range(m)]
for i in range(n):
    a = list(map(int, input().split()))
    for j in range(a[0]):
        cnt[a[j + 1] - 1] += 1
ans = 0
for i in range(m):
    if cnt[i] == n:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 10'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  int64 k;
  cin >> n >> k;
  vector<int> a(n), b(n);
  for (int& x : a) {
    cin >> x;
  }
  for (int& x : b) {
    cin >> x;
  }
  sort(begin(a), end(a), greater<int>());
  sort(begin(b), end(b));
  int64 l = 0;
  int64 r = inf64;
  while (l < r) {
    int64 mid = (l + r) / 2, add = 0;
    bool ok = true;
    for (int i = 0; i < n; ++i) {
      int64 x = mid / b[i];
      if (x < a[i]) {
        add += a[i] - x;
      }
      ok &= add <= k;
    }
    if (ok) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << l << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 1792
N = int(input())

a, b = [], []
for i in range(N):
    x, y = map(int, input().split())
    a.append(x + y)
    b.append(x - y)
a.sort()
b.sort()

ans = max(a[-1] - a[0], b[-1] - b[0])
print(ans)


Measured memory_bytes: 104788
package main

import (
	"fmt"
)

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

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	fmt.Println(min(a, b) + min(c, d))
}


Measured memory_bytes: 512
N = int(input())
AB = []
for i in range(N):
  ab = tuple(map(int,input().split()))
  AB += [ab]

AB_on_A = sorted(AB)
AB_on_B = sorted(AB,key=lambda x:x[1])
if N%2==0:
  min_num = AB_on_A[N//2-1][0]+AB_on_A[N//2][0]
  max_num = AB_on_B[N//2-1][1]+AB_on_B[N//2][1]
  print(max_num-min_num+1)
else:
  min_num = AB_on_A[N//2][0]
  max_num = AB_on_B[N//2][1]
  print(max_num-min_num+1)

Measured memory_bytes: 42428
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int l2[210000];

int main(){
  bool flag=false;
  int N,M;
  cin>>N>>M;

  int l1[200000],count1=0,count2=0,a,b;

  for(int i=0;i<M;i++){
    cin>>a>>b;
    if(a==1) l1[count1++]=b;
    else if(b==N) l2[a]=1;
  }
  for(int i=0;i<count1;i++){
    if(l2[l1[i]]==1) flag=true;
  }
  if(flag) cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;

  
  
}


Measured memory_bytes: 1408
#include<stdio.h>
int main(){
    char s[10];
    scanf("%s",s);
    if(s[0]=='S'){
        printf("Cloudy\n");
    }
    if(s[0]=='C'){
        printf("Rainy\n");
    }
    if(s[0]=='R'){
        printf("Sunny\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    const int MAX=1000000;
    vector<bool> pri(MAX+1,true);
    pri[0]=pri[1]=false;
    for(int i=2;i<=sqrt(MAX);i++){
        if(pri[i]){
            for(int j=i*i;j<=MAX;j+=i){
                pri[j]=false;
            }
        }
    }
    int N,X;
    for(;;){
        scanf("%d%d",&N,&X);
        if(N==0&&X==0) break;
        vector<bool> has(X+1,false);
        has[0]=true;
        int in;
        for(int i=0;i<N;i++){
            scanf("%d",&in);
            for(int j=0;j<=X;j++){
                if(has[j]&&(j+in<=X)) has[j+in]=true;
            }
        }
        int ret=-1;
        for(int i=X;i>=0;i--){
            if(pri[i]&&has[i]){
                ret=i;
                break;
            }
        }
        if(ret==-1) printf("NA\n");
        else printf("%d\n",ret);
    }
}

Measured memory_bytes: 1060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
a = list(map(int, input().split()))

ans = 0
up = None
prev = None
for v in a:
    if prev == v:
        continue
    if prev is not None:
        if up is None:
            up = (prev <= v)
        else:
            if (prev <= v) != up:
                ans += 1
                up = None
    prev = v
print(ans + 1)


Measured memory_bytes: 84580
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

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

using namespace std;
typedef long long int ll;

int main() {
  ll x, y;
  cin >> x >> y;
  ll p2=1, cnt=0;
  while(x*p2<=y){
    p2 *= 2;
    ++cnt;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void	kame(int *x, int *y)
{
  	*x = *x - 1;
  	*y = *y - 2;
}

void	tsuru(int *x, int *y)
{
  	*x = *x - 1;
  	*y = *y - 4;
}

int	main(void)
{
  	int	x;
  	int	y;
	
	scanf("%d %d", &x, &y);
	
  	if (2 * x <= y)
    { 
	  	while (2 * x < y && x > 0)
    	{
      		tsuru(&x, &y);
        }
      	if (2 * x == y)
        {
          	printf("Yes");
        }
      	else
        {
          	printf("No");
        }
    }
    else
    {
      	printf("No");
    }
  	return (0);
}

Measured memory_bytes: 1728
import sys
import math
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
s=list(input())
t=list(input())
for al in ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]:
    num=[nu for nu,chra in enumerate(s) if chra==al]
    if len(set([t[i] for i in num])) >=2:
        print("No")
        exit()
for al in ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]:
    num=[nu for nu,chra in enumerate(t) if chra==al]
    if len(set([s[i] for i in num])) >=2:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 11932
n, k = map(int,input().split())
ab = []
for i in range(n):
  (a, b) = map(int, input().split())
  ab.append((a, b))

ab = sorted(ab, key=lambda k:k[0])

b = 0

for i in ab:
  b += i[1]
  if b >= k:
    print(i[0])
    exit()

Measured memory_bytes: 18960
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX



 
void solve()
{
   string s;
   cin >> s;
   int c[s.size()+1] = {0};
   int curr = 0;
   rep(i,0,s.size()-1)
   {
     curr = curr*10+s[i]-'0';
     curr %= 2019;
     c[i+1] = curr;
   }
   int mul = 1;
   for(int i=s.size(); i>=0; i--)
    {
        c[i] *= mul;
        mul *= 10;
        mul %= 2019;
        c[i] %= 2019;
    }

   int cnt[2019] = {0};
   rep(i,0,s.size())
    cnt[c[i]]++;
   int ans = 0;
   rep(i,0,2018)
    ans += (cnt[i]*(cnt[i]-1))/2;
   cout << ans << endl;
}


signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 5296
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<tuple<int, int, int, int>> A(N);
    rep(i,N) {
        int w,s,v; cin >> w >> s >> v;
        A[i] = make_tuple(w+s,w,s,v);
    }

    sort(all(A));
    vector<vector<ll>> dp(N+1, vector<ll>(20001));
    rep(i,N) {
        int a,w,s,v;
        tie(a,w,s,v) = A[i];
        rep(j,s+1) {
            chmax(dp[i+1][j+w],dp[i][j] + v);
        }
        rep(j,20001) {
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    cout << *max_element(all(dp[N])) << ln;
}

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


int main() {
  int n, k;
  cin >> n >> k;
  vector<int> cnt(n+1,0);
  int kind;
  rep(i, n) {
    int x;
    cin >> x;
    if (cnt.at(x) == 0) kind++;
    cnt[x]++;
  }
  
  if (kind <= k) {
    cout << 0 << endl;
    return 0;
  }
  
  sort(all(cnt));
  int l = 0;
  while (cnt[l] == 0) {
    l++;
  }
  int ans = 0;
  for (int i = l; i < l + (kind - k); i++) {
    ans += cnt[i];
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

class LowLink():
    def __init__(self,G):
        self.N = len(G)
        self.G = G
        self.low = [-1] * self.N
        self.ord = [-1] * self.N
    
    def _dfs(self,v,time,p = -1):
        self.ord[v] = self.low[v] = time
        time += 1

        isArticulation = False
        cnt = 0
        for e in self.G[v]:
            if self.low[e] < 0:
                cnt += 1
                self._dfs(e,time,v)
                self.low[v] = min(self.low[v],self.low[e])
                if p != -1 and self.ord[v] <= self.low[e]:
                    isArticulation = True
                if self.ord[v] < self.low[e]:
                    self.bridge.append((v,e))
            elif e != p:
                self.low[v] = min(self.low[v],self.ord[e])
        
        if p == -1 and cnt >= 2:
            isArticulation = True
        if isArticulation:
            self.articulation.append(v) 

    def build(self):
        self.articulation = []
        self.bridge = []
        self._dfs(0,0)
    

def main():
    V,E = map(int,input().split())
    G = [[] for _ in range(V)]
    for _ in range(E):
        a,b = map(int,input().split())
        G[a].append(b)
        G[b].append(a)
    
    lowlink = LowLink(G)
    lowlink.build()
    ans = lowlink.articulation
    ans.sort()
    if ans:
        print('\n'.join(map(str,ans)))
if __name__ == '__main__':
    main()


Measured memory_bytes: 21292
import java.io.*;
import java.util.*;

public class Main implements Runnable {
	public static void main (String[] args) {new Thread(null, new Main(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int n = fs.nextInt();
		int res = 0;
		for(int i = 1; i <= n; i++) {
			String it = ""+i;
			if(it.length()%2 == 1) res++;
		}
		out.println(res);
		
		out.close();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}

Measured memory_bytes: 34516
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    String s = sc.next();
    int ss = s.length();
    if(k >= ss){
      System.out.println(s);
    }else{
      System.out.println(s.substring(0,k) + "...");
    }
  }
}

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

using namespace std;
typedef long long ll;

#define eps 0.000001

int main() {
  ll N; cin >> N;
  ll D; cin >> D;
  vector<vector<ll> > X(N, vector<ll>(D));
  for (ll j=0; j < N; ++j)
    for (ll k=0; k < D; ++k)
      cin >> X[j][k];

  ll count = 0;

  for (ll j=0; j < N; ++j) {
    for (ll k=j+1; k < N; ++k) {
      double d = 0;
      for (ll l=0; l < D; ++l) {
        d += (X[j][l] - X[k][l]) * (X[j][l] - X[k][l]);
      }
      d = sqrt(d);
      if (d - (ll)d < eps) count += 1;
    }
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
//arc092_c.cpp
//Fri Jul 26 21:28:51 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	vector<P> a;
	vector<P> b;

	for (int i=0;i<n;i++){
		int tempa,tempb;
		cin >> tempa >> tempb;
		a.push_back(make_pair(tempa,tempb));
	}

	for (int i=0;i<n;i++){
		int tempc,tempd;
		cin >> tempc >> tempd;
		b.push_back(make_pair(tempc,tempd));
	}

	sort(a.begin(),a.end());
	sort(b.begin(),b.end());

	int chose[n];
	fill(chose,chose+n,0);

	int ans = 0;
	for (int i=0;i<n;i++){
		int temp = -1;
		for (int j=0;j<n;j++){
			if (a[j].first<b[i].first && 
				a[j].second<b[i].second &&
				chose[j] == 0){
				if (temp == -1 || 
					a[j].second > a[temp].second){
					temp = j;
				}
			}
		}
		if (temp != -1){
			ans++;
			chose[temp]=1;
		}
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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

    using namespace std;

    bool visited[100005];
    int path[100005];
    vector<int>adj[100005];
    queue<int>q;

    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        memset(visited,sizeof(visited),false);
        int n,m;
        cin>>n>>m;
        int x,y;
        bool flag=false;
        for(int i=0;i<m;i++){
            cin>>x>>y;
            adj[x].push_back(y);
            adj[y].push_back(x);
            if(x==1 || y==1)
                flag=true;
        }
        if(!flag){
            cout<<"NO";
            return 0;
        }
        q.push(1);
        while(q.size()){
            int x=q.front();
            q.pop();
//            cout<<x<<" "<<y<<"\n";
            if(!visited[x]){
                visited[x]=true;
                for(int i=0;i<adj[x].size();i++){
                    q.push(adj[x][i]);
                    if(path[adj[x][i]]==0)
                        path[adj[x][i]]=x;
                }
            }
        }
        cout<<"Yes"<<"\n";
        for(int i=2;i<=n;i++)
            cout<<path[i]<<"\n";
        return 0;
    }


Measured memory_bytes: 11248
<?php
list($x, $y) = explode(" ", trim(fgets(STDIN)));
if($x == 1 && $y == 1){
  echo 1;
}elseif($x == 1){
  echo max($y - 2, 0);
}elseif($y == 1){
  echo max($x - 2, 0);
}else{
  echo ($x-2)*($y-2);
}

Measured memory_bytes: 4604
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N, P = map(int, input().split())
f = Counter(prime_factorize(P))

ans = 1
for k, v in f.items():
    if v >= N:
        ans *= k ** (v//N)
print(ans)


Measured memory_bytes: 3316
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 

using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    int count = 0;
    vector<int> a(N);
    for(int i = 0;i < N; i++)cin >> a.at(i);
    
    for(int i = 0;i < N; i++){
        while(a.at(i) > 0){
            count++;
            for(int j = i; j < N; j++){
                if(a.at(j) > 0){
                    a.at(j)--;
                }
                else{
                    break;
                }
            }
            
            
        }
        
    }
    cout << count << endl;
    
    
    
}


Measured memory_bytes: 256
read x
m=1
for b in `seq 2 32`
do
    if((b*b>x))
    then
        break
    fi
    p=$b
    while((p<=x))
    do
        p=$((p*b))
    done
    if((p/b>m))
    then
        m=$((p/b))
    fi
done
echo $m

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

using namespace std;

#define all(container)     (container).begin(), container.end()
#define rall(container)    (container).begin(), container.end()
#define sz(container)      (int) (container).size()

using ll = long long;

#ifdef LOCAL_DEFINE
    #include "DEBUG.hpp"
#else
    #define debug(...) 0
#endif
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> b[i];
    vector<int> arr(n);
    iota(all(arr), 1);
    int aa = 0, bb = 0, cnt = 0;
    do {
        bool ok = true;
        for (int i = 0; i < n; i++) {
            if (a[i] != arr[i]) {
                ok = false;
                break;
            }
        }
        if (ok) aa = cnt;
        ok = true;
        for (int i = 0; i < n; i++) {
            if (b[i] != arr[i]) {
                ok = false;
                break;
            }            
        }
        if (ok) bb = cnt;
        ++cnt;
    } while(next_permutation(all(arr)));
    cout << abs(aa - bb) << '\n';
    return 0;
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(1000000)
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

N = I()
sr = SR(N)

c = collections.Counter(sr)

print("AC x {}".format(c["AC"]))
print("WA x {}".format(c["WA"]))
print("TLE x {}".format(c["TLE"]))
print("RE x {}".format(c["RE"]))


Measured memory_bytes: 34484
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> s;
  n = 0;
  if(s.at(0)=='1'){
    n = n+1;
  }
  if(s.at(1)=='1'){
    n = n+1;
  }
  if(s.at(2)=='1'){
    n = n+1;
  }
  cout << n << endl;
}

Measured memory_bytes: 256
import sys

def exhaustiveSearch(A, m, i, s):
    if A[i] == m:
        return True
    elif i == len(A) - 1 or m < 0 or m > s:
        return False

    return exhaustiveSearch(A, m, i + 1, s) or exhaustiveSearch(A, m - A[i], i + 1, s)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    A = map(int, lines[1].split())
    M = map(int, lines[3].split())
    s = sum(A)

    for m in M:
        if exhaustiveSearch(A, m, 0, s):
            print "yes"
        else:
            print "no"

Measured memory_bytes: 6476
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  string s;
  while (cin >> n, n) {
    int K[n];
    for (int i = 0; i < n; ++i) cin >> K[i];
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i]-K[i%n] < 'a' && s[i] >= 'a') {
	s[i] = 'Z' - 'a' - K[i%n] + s[i] + 1;
	if (s[i] < 'A') s[i] = 'z' - 'A' + s[i] + 1;
      } else if (s[i]-K[i%n] < 'A' && s[i] >= 'A') {
	s[i] = 'z' - 'A' - K[i%n] + s[i] + 1;
	if (s[i] < 'a') s[i] = 'Z' - 'a' + s[i] + 1;
      }else s[i] -= K[i%n];
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    string S;
    cin >> S;
    int X = 0;
    int Y = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == '0') {
            X++;
        }
        else {
            Y++;
        }
    }
    cout << min(X,Y)*2 << endl;
}


Measured memory_bytes: 3732
#include<stdio.h>
main(){
  char tmp[10],a[2]="ox";
  int i,j,flg;
  while(scanf("%s",tmp)!=EOF){
    flg=0;

  for(i=0;i<2;i++){
    if(tmp[0]==a[i]&&tmp[3]==a[i]&&tmp[6]==a[i]){printf("%c\n",a[i]);flg=1;break;}
    else if(tmp[1]==a[i]&&tmp[4]==a[i]&&tmp[7]==a[i]){printf("%c\n",a[i]);flg=1;break;}
    else if(tmp[2]==a[i]&&tmp[5]==a[i]&&tmp[8]==a[i]){printf("%c\n",a[i]);flg=1;break;}
    else if(tmp[0]==a[i]&&tmp[1]==a[i]&&tmp[2]==a[i]){printf("%c\n",a[i]);flg=1;break;}
    else if(tmp[3]==a[i]&&tmp[4]==a[i]&&tmp[5]==a[i]){printf("%c\n",a[i]);flg=1;break;}
    else if(tmp[6]==a[i]&&tmp[7]==a[i]&&tmp[8]==a[i]){printf("%c\n",a[i]);flg=1;break;}
    else if(tmp[0]==a[i]&&tmp[4]==a[i]&&tmp[8]==a[i]){printf("%c\n",a[i]);flg=1;break;}
    else if(tmp[2]==a[i]&&tmp[4]==a[i]&&tmp[6]==a[i]){printf("%c\n",a[i]);flg=1;break;}
  }
  if(flg==0)printf("d\n");
  }
  return 0;
}

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

int main(){
  string s;
  cin >> s;

  string sun = "Sunny",clo = "Cloudy",rai = "Rainy";
  if(s == sun) cout << clo << endl;
  else if (s == clo) cout << rai << endl;
  else cout << sun << endl;

}


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

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N-1);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    for(int i = 0; i < N-1; i++) cin >> C[i];
    ll ans = 0;
    for(int i = 0; i < N; i++)
    {
        ans += B[A[i]-1];
        if(i != N-1 && A[i+1]-A[i] == 1) ans += C[A[i]-1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

def or_less(array, x):
    # arrayの中のx以下のものの個数
    # arrayの中のx以下のもののうちの最大値
    index = bisect_right(array, x)
    if index == 0:
        or_less_int = -float('inf')
    else:
        or_less_int = array[index - 1]
    return [index, or_less_int]

N, M, K = getNM()
A = getList()
B = getList()

A_imos = copy.deepcopy(A)
for i in range(N - 1):
    A_imos[i + 1] += A_imos[i]

B_imos = copy.deepcopy(B)
for i in range(M - 1):
    B_imos[i + 1] += B_imos[i]

ans = 0

for i in range(M):
    if B_imos[i] <= K:
        ans = (i + 1)

for i in range(N):
    if A_imos[i] > K:
        continue
    index = or_less(B_imos, K - A_imos[i])[0]
    ans = max(ans, (i + 1) + index)
print(ans)

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    map<int,int> mp;
    rep(i,n){
        cin >> a[i];
        a[i] += i+1;
        mp[a[i]]++;
    }
    ll ans = 0;
    rep(i,n){
        if((i+1)*2 >a[i]){
            int d = (i+1)*2-a[i];
            ans += mp[d];
            if(d == a[i]) ans--; 
        }
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;

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


int bfs(const vector<string> &v, int x, int y){
  int h = v.size(), w = v[0].size();
  vector<vector<int>> dist(h, vector<int>(w, -1));
  queue<pair<int,int>> que;
  
  
  int res = 0;
  que.push({x, y});
  dist[x][y] = 0;
  
  while(!que.empty()){
    int x = que.front().first, y = que.front().second;
    res = max(res, dist[x][y]);
    que.pop();
    
    for(int i=0; i<4; i++){
      int nx = x + dx[i], ny = y + dy[i];
      if(nx<0 || h<=nx || ny<0 || w<=ny) continue;
      if(v[nx][ny]=='#') continue;
      if(dist[nx][ny]==-1){
        dist[nx][ny] = dist[x][y] + 1;
        que.push({nx, ny});
      }
    }
  
  }

  return res;
}

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for(int i=0; i<h; i++) cin >> v[i];
    
    
  int res = 0;
  for (int x = 0; x < h; ++x) {
    for (int y = 0; y < w; ++y) {
      if (v[x][y] == '#') continue;
        res = max(res, bfs(v, x, y));
    }
  }
  cout << res << endl;
 
  return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

const string YES = "YES";
const string NO = "NO";

void solve(std::string S){
    ll a=0, b=0, c=0;
    for(auto t: S){
        if(t == 'a')
            a++;
        if(t == 'b')
            b++;
        if(t == 'c')
            c++;
    }
    if( max(a, max(b, c)) -  min(a, min(b, c)) < 2){
        cout << YES<<endl;
    }
    else{
        cout << NO << endl;
    }
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
typedef unsigned long long ll;

const int NMAX = 110;

ll lcm(ll a, ll b) {
    ll A, B;
    if (a < b) {
        A = a;
        B = b;
    }
    else {
        A = b;
        B = a;
    }
    ll r;
    while (A!=0) {
        r = B%A;
        B=A;
        A=r;
    }

    return a/B*b;
}

int main() {
    int N;
    ll T[NMAX];

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

    for (int i = N-1; i>=1; i--) {
        T[i] = lcm(T[i], T[i+1]);
    }

    cout << T[1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N, K; std::cin >> N >> K;
  std::vector<int> H(N);
  for (int i = 0; i < N; ++i) std::cin >> H[i];

  std::sort(H.rbegin(), H.rend());
  LL sum = 0;
  for (int i = K; i < N; ++i) {
    sum += (LL)H[i];
  }

  std::cout << sum << std::endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main () {
  long long n;
  cin >> n;
  vector<int> two(34);
  for (int i = 0; i < 34; i++) {
    two[i] = 0;  
  }  
  long long  sub = 1;
  long long i = 0;
  while (1) {
    if (n == 0) {
      break;  
    }
    sub = sub * 2;
    long long subsub = (n < 0) ? -1*n : n;
    if (subsub % sub != 0 || subsub < sub) {
      two[i] = 1;
      if (i % 2 == 0) {
        n = n - pow(2,i);   
      }   
      else {
        n = n + pow(2,i);  
      }  
      two[i] = 1;
    }  
    i++;
  }
  int l = -1;
  reverse(two.begin(), two.end());
  for (int i = 0; i < 34; i++) {
    if (two[i] == 1) {
      cout << two[i];  
      l = 1;
    }  
    else {
      if (l == 1) {
        cout << two[i];  
      }    
    }
  }
  if (l < 0) {
    cout << 0 << endl;  
  }
  else {
    cout << endl;  
  }
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    map <int, int> c;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ans += a[i];
        c[a[i]]++;
    }
    int q;
    cin >> q;
    while (q--) {
        int x, y;
        cin >> x >> y;
        ans -= c[x] * (ll) x;
        c[y] += c[x];
        ans += c[x] * (ll) y;
        c[x] = 0;
        cout << ans << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 7964
import math

H, W = map(int, input().split())

if H <= 1 or W <= 1:
    print(1)
    exit()

odd = int(math.ceil(W / 2.0) * math.ceil(H / 2.0))
even = int(math.floor(W / 2) * math.floor(H / 2))

print(odd + even)

Measured memory_bytes: 38384
#include<cmath>
#include<string>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<fstream>
#include<algorithm>

using namespace std;
long long a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(a-b==b-c)
	cout<<"YES";
	else
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

// FAIL
void fail(){ print(-1); std::exit(0); }
//void fail(){ print("No"); std::exit(0); }

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

  std::string S;
  std::cin >> S;
  std::map< std::string, std::string > ms;

  ms["Sunny"]  = "Cloudy";
  ms["Cloudy"] = "Rainy";
  ms["Rainy"]  = "Sunny";

  print(ms[S]);

  return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
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)*}
    };
}
 
#[allow(unused_macros)]
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)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        num: usize,
        weight: usize,
        baggage: [(usize, usize); num],
    }

    let mut dp = vec![vec![0; weight+1]; num+1];

    for i in 0..num {
        for j in 0..weight+1 {
            //selcet
            if baggage[i].0 <= j {
                let tmp = dp[i][j-baggage[i].0];
                chmax(&mut dp[i+1][j], tmp + baggage[i].1);
            }

            //not select
            let tmp = dp[i][j];
            chmax(&mut dp[i+1][j], tmp);
        }
    }

    println!("{}", dp[num][weight]);
}

fn chmax<T: Ord>(a: &mut T, b: T) -> bool {
    if *a < b {
        *a = b;
        return true;
    }
    false
}


Measured memory_bytes: 106748
from collections import deque

H, W = map(int, input().split())
grid = [input() for _ in range(H)]

dxdy = [(-1,0), (1,0), (0,-1), (0,1)]
INF = 999999
que = deque()

dist = [[INF] * W for _ in range(H)]
for i, row in enumerate(grid):
    for j, s in enumerate(row):
        if s == "#":
            dist[i][j] = 0
            que.append(i*W + j)

ans = 0
while len(que) > 0:
    num = que.popleft()
    h = num // W
    w = num % W
    for dx, dy in dxdy:
        nx = w + dx
        ny = h + dy
        if ny<0 or ny>=H or nx<0 or nx>=W:
            continue
        if dist[ny][nx] == INF:
            que.append(ny * W + nx)
        dist[ny][nx] = min(dist[ny][nx], dist[h][w]+1)
        ans = max(ans, dist[ny][nx])

print(ans)

Measured memory_bytes: 82908
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    string s;
    cin>>s;
    if(s[0]=='9' || s[1]=='9')cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
inline ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ll char_to_ll(char c) { return (int)(c - '0'); }
inline ll string_to_ll(string s) { return atoi(s.c_str()); }
inline bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    VL A(3);
    rep(i, 0, 3) cin >> A[i];
    sort(ALL(A));
    rep(i, 0, 2) cout << A[i] << " ";
    cout << A[2] << endl;

    return 0;
}



Measured memory_bytes: 3140
#!/usr/local/bin/python3
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,x = f()
    l = f()

    a = []
    a.append(0)

    for i in l:
        a.append(a[-1] + i)

    ans = 0 
    for i in a:
        if i <= x:
            ans += 1
    
    print(ans)

solve()


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int a,b,sum,mx;
int main(void)
{
    for(int i=1;i<=5;i++){
        cin >> a;
        b=(a+9)/10*10;
        mx=max(b-a,mx);
        sum+=b;
    }
    cout << sum-mx;
    return 0;
}

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

int main() {
  int n, i, sum1 = 0, sum2 = 0;
  cin >> n;
  vector<int> a(n);
  for(i = 0 ; i < n ; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  if(n % 2 == 0){
    for(i = 0; i < n / 2; i++){
      sum1 += a.at(2 * i);
      sum2 += a.at(2 * i + 1);
    }
  }else{
    for(i = 0; i <= (n - 1) / 2; i++){
      sum1 += a.at(2 * i);
      if(2 * i + 1 >= n) break;
      sum2 += a.at(2 * i + 1);
    }
  }
  cout << sum1 - sum2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define ll long long
const int inf = 1000000000; // 10^9

int main(){
    int n, m, p[110000], wa[110000] = {}, cntcrr = 0, cntwa = 0;
    bool crr[110000] = {};
    string s[110000];

    cin >> n >> m;
    rep(i, m) cin >> p[i] >> s[i];

    rep(i, m){
        if(crr[p[i]] == 0 && s[i] == "WA") wa[p[i]]++; //p[i]がまだACされていないかつWAしたらWAのカウントを+1
        else if(s[i] == "AC") crr[p[i]] = true; //ACしたらp[i]問目のフラグを正解にする
    }
    for(int i = 1; i < n + 1; i++){
        if(crr[i] == 1){
            cntcrr++;
            cntwa += wa[i];
        }
    }
    cout << cntcrr << " " << cntwa << endl;

    return 0;
}

Measured memory_bytes: 6784
<?php
// B
fscanf(STDIN, '%d %d %d %d', $N, $M, $X, $Y);
$x = array_map('intval', explode(' ', trim(fgets(STDIN))));
$y = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = (max($x) < $Y && min($y) > $X && max($x) < min($y)) ? 'No War' : 'War';
echo $ans;

Measured memory_bytes: 4728
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ave = (a + b) / 2;

        if( (a + b) % 2 == 1 ) ave++;
        
        System.out.println(ave);
    }
}
 

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




int main(){
    string n;
    cin>>n;
    int s=0;
    for(int i=0;i<n.length();i++)
    {
        s+=(n[i]-'0');
    }
    if(s%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
}


       
    
    
    

Measured memory_bytes: 3724