akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    odd = even = even4 = 0
    for a in A:
        if a % 4 == 0:
            even4 += 1
        elif a % 2 == 0:
            even += 1
        else:
            odd += 1
    if even == 0:
        print("Yes" if even4 >= odd - 1 else "No")
    else:
        print("Yes" if even4 >= odd else "No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 58736
import scala.io.StdIn.readLine

case class Dice(var d:Array[String]) {

  def rollOnce(dir:Char)  =
    dir match {
      case 'S' => Array(4,0,2,3,5,1)
      case 'N' => Array(1,5,2,3,0,4)
      case 'W' => Array(2,1,5,0,4,3)
      case 'E' => Array(3,1,0,5,4,2)
    }

  def roll(dirs:String) = d = dirs.foldLeft(Array(0,1,2,3,4,5)) { (x,y) => rollOnce(y).map(x) }.map(d)

  override def toString() = d(0)
}

object Main extends App {
  val faces = readLine.split(" ")
  val dice = Dice(faces)
  dice.roll(readLine)

  println(dice)
}

Measured memory_bytes: 44008
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>

using namespace std;


int main() {
    int A,B; cin>>A>>B;
    int ans;
    if(A>=13) ans=B;
    if(6<=A && A<=12)ans=B/2;
    if(A<=5) ans=0;
    
    cout<<ans<<endl;
    
    
    
}
    


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

using namespace std;
using ll = long long;

const ll md = 1e9 + 7;

int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0);
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ll tot = 0;
    ll cur = i;
    while (cur > 0) {
      tot++;
      cur /= 10;
    }
    if (tot & 1) {
      ans += 1;
    }
  }
  cout << ans <<  '\n';
  return 0;
}


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

long long gcd(long long a , long long b)
{
    return b == 0 ? a : gcd(b,a%b) ;
}

long long lcm(long long a , long long b)
{
    long long res = gcd(a,b) ;
    return a/res*b ;
}

long long s[123] ;

int main()
{
    int n ;
    while(~scanf("%d",&n)){

        for(int i = 0 ; i < n ; i ++)
            scanf("%lld",&s[i]) ;
        long long ans = s[0] ;
        for(int i = 1 ; i < n ; i ++)
            ans = lcm(s[i],ans) ;
        printf("%lld\n",ans) ;
    }
    return 0 ;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

int main(){
  int n;
  cin >> n;
  int ans=0;
  while(n>0){
   if(n%10==2){
    ans++; 
   }
    n/=10;
  }
  cout << ans << endl;
return 0;}


Measured memory_bytes: 764
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mod;
int h,w;
int mx=-1;
vector<int> adj[1000];
bool vis[20][20];
int level[20][20];
string s[20];
int zrr[100005];
void fact(){
	zrr[0]=1;
	for(int i=1;i<100005;++i){
		zrr[i]=i*zrr[i-1];
		zrr[i]%=mod;
	}
}
int modexp(int x){
	int y=mod-2;
	int res=1;
	while(y>0){
		if(y&1){
			res*=x;
			res%=mod;
		}
		x*=x;
		x%=mod;
		y/=2;
	}
	return res;
}
void solve(){	
	int n,r; cin>>n>>r;
	int x=0;
	while(n!=0){
		++x;
		n/=r;
	}
	cout<<x<<"\n";
}

// -----------------------------------------------------------------------


int32_t main()
{
	mod=1e9+7;
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}


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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
//void __print(vector<bool> x) {int f = 0; cerr << '{'; for (auto i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
//void _print() {cerr << "]\n";}

#ifndef ONLINE_JUDGE
#define ANTHRO(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define ANTHRO(x...)
#endif

template<typename... T>
void read(T&... args) {
	((cin >> args), ...);
}

template<typename... T>
void writ(T&&... args) {
	((cout << args << " "), ...);
}
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define EPS 1e-9
/*
	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    No, nothing good starts in a getaway car
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/
ll cval(ll a,ll b){
	if(a%b==0) return a/b;
	else return (a/b)+1;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,d; cin>>a>>b>>c>>d;
    if(cval(c,b)<=cval(a,d)) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

int main(void){
	string s;
	map<char,int> mp;
	cin >> s;
	for(auto i:s){
		mp[i]+=1;
	}
	for(auto itr=mp.begin();itr!=mp.end();++itr){
		if(itr->second%2==1){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
n,k=gets.split.map &:to_i
a=gets.split.map &:to_i
kl=(k-1)*k/2%1000000007
kr=k*(k+1)/2%1000000007
ans = 0
n.times do |i|
  c = 0
  i.times do |j|
    c += 1 if a[j] < a[i]
  end
  ans += c*kl
  c = 0
  (n-i).times do |j|
    c += 1 if a[i+j] < a[i]
  end
  ans += c*kr
  ans %= 1000000007
end
p ans


Measured memory_bytes: 1788
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Contests.NOMURA2020
{
    /// <summary>
    /// 
    /// </summary>
    static class B
    {
        static void Main(string[] args)
        {
            var t = Next();

            Console.WriteLine(t.Replace('?', 'D'));
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 26992
#!/usr/bin/env python3
class WeightedUnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.weight = [0] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            px = self.find(self.parents[x])
            self.weight[x] += self.weight[self.parents[x]]
            self.parents[x] = px
            return px

    def union(self, x, y, w):
        w += self.weight[x] - self.weight[y]
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
            w = -w
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        self.weight[y] = w
        return

    def weig(self, x):
        self.find(x)
        return self.weight[x]

    def diff(self, x, y):
        return self.weight[y] - self.weight[x]

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)


n, m = map(int, input().split())
UF = WeightedUnionFind(n)

for i in range(m):
    l, r, d = map(int, input().split())
    l -= 1;r -= 1
    if UF.same(l, r):
        if d != abs(UF.diff(l, r)):
            exit(print("No"))
    else:
        UF.union(l, r, d)
print("Yes")

Measured memory_bytes: 8944
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include<bits/stdc++.h>

long long int m = 1000000007;
using namespace std;

long long int pow2(long long int a, long long int b){
    long long int resp = 1;
    
    while(b!=0){
        if(b%2==1){
            resp = resp*a%m;
        }
        a = a*a%m;
        b /= 2;
    }
    
    return resp%m;
}

long long int fat(long long int maior, long long int menor){
    long long int resp=1;
    
    for(int i=menor;i<=maior;i++){
        resp*=i;
        resp=resp%m;
    }
    return resp;
}

long long int vs[200010];

int main(){
    vs[0]=1;
    
    for(int i=1;i<200005;i++){
        vs[i] = (vs[i-1]*i)%m;
    }

    long long int a,n,b,r,aux,auxb;
    
    cin >> n >> a >> b;
    
    r = pow2(2, n) - 1;
    
    aux = vs[a];
    aux = pow2(aux, m-2) * fat(n,n-a+1) % m;
    r+= m - aux;
    
    aux = vs[b];
    aux = pow2(aux, m-2) * fat(n,n-b+1) % m;
    r+= m - aux;

  
    cout << r%m << endl;
    
    return 0;
}


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

int main() {
    int k, a, b;
    cin >> k >> a >> b;

    if (b - a <= 2 || a >= k) {
        cout << k + 1 << endl;
        return 0;
    }

    ll ans = 1LL;
    int cnt = 0;
    while (ans < a) {
        cnt++;
        ans++;
    }

    while (cnt + 2 <= k) {
        cnt += 2;
        ans = ans - a + b;
    }

    rep(i, k - cnt) {
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
bool f(int x)
{
    for(int i=2;i*i<=x;i++)
        if(x%i==0)
        return false;
    return true;
}
int main()
{
    FIO;
    int x;
    cin>>x;
    while(true)
    {
        if(f(x))
        {
            cout<<x<<endl;
            return 0;
        }
        x++;
    }
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){


			long a = scan.nextLong();
			long A = Math.abs(a);
			long b = scan.nextLong();
			long B = Math.abs(b);
			long c = scan.nextLong();
			long C = Math.abs(c);
			long d = scan.nextLong();
			long D = Math.abs(d);



			ArrayList<Long>are =new ArrayList<Long>();

			are.add(a*c);
			are.add(a*d);
			are.add(b*c);
			are.add(b*d);



			Collections.sort(are, Collections.reverseOrder());

			System.out.println(are.get(0));



			/*

			if(0<=a&&0<=b) {
				if(c>=0&&d>=0) {
					System.out.println(b*d);
					return;

				}else if(c<0&&d>=0) {
					System.out.println(b*d);return;
				}else if(c<0&&d<0) {
					System.out.println(Math.max(a*d, b*c));return;
				}




			}

			if(0>a&&0<=b) {
				if(c>=0&&d>=0) {
					System.out.println(b*d);return;
				}else if(c<0&&d>=0) {
					System.out.println(Math.max(a*c, b*d));return;
				}else if(c<0&&d<0) {
					System.out.println(a*c);return;
				}


			}


			if (0>a&&b>0){
				if(c>=0&&d>=0) {
					System.out.println(Math.max(a*d, b*c));return;
				}else if(c<0&&d>=0) {
					System.out.println(a*c);return;
				}else if(c<0&&d<0) {
					System.out.println(a*c);return;
				}

			}

			*/




		}


	}


}


Measured memory_bytes: 35748
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 300060
int n,v[N];
long long su[N],su1,su2;
bool check(long long l)
{
	long long mn=0;
	for(int i=1;i<=n;i+=2)
	if(su[i]-mn>=l)
	{
		if(mn>su[i+1])mn=su[i+1];
		if(i==n)return 1;
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&v[i]);
	if(~n&1)
	{
		long long s1=0,s2=0;
		for(int i=1;i<=n;i+=2)s1+=v[i],s2+=v[i+1];
		printf("%lld %lld\n",max(s1,s2),min(s1,s2));
	}
	else
	{
		for(int i=1;i<=n;i++)su1+=v[i]*(i&1),su[i]=su[i-1]+v[i]*(i&1?1:-1),su2+=v[i]*(~i&1);
		long long lb=0,rb=2e10,as=0;
		while(lb<=rb)
		{
			long long mid=(lb+rb)>>1;
			if(check(mid))as=mid,lb=mid+1;
			else rb=mid-1;
		}
		printf("%lld %lld\n",su2+as,su1-as);
	}
}//orzwkr

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

int main() {
	int N;
	cin >> N;
	int(*heights)[100] = new int[100][100];
	int xs[100];
	int ys[100];
	int x, y, h;
	int k = 0;
	while (cin >> x >> y >> h)
	{
		xs[k] = x;
		ys[k++] = y;
		heights[x][y] = h;
	}

	long long int H = 1;
	long long int max_H = 1000000000 + 201;
	int i = 0;
	int Cx = 0;
	int Cy = 0;
	for (Cx = 0; i < N && Cx <= 100; Cx++)
		for (Cy = 0; i < N && Cy <= 100; Cy++)
		{
			long long int temp_H = 0; //作为测试标杆，如果对于每一对坐标，H都与temp_H相等，则说明H正确。
			for (i = 0; i < N; i++)
			{
				if (heights[xs[i]][ys[i]] > 0)
				{
					H = abs(xs[i] - Cx) + abs(ys[i] - Cy) + heights[xs[i]][ys[i]];
					if (temp_H == 0)
						temp_H = H;
					if (H != temp_H || H > max_H)
						break;
				}
				else
				{
					max_H = abs(xs[i] - Cx) + abs(ys[i] - Cy) + heights[xs[i]][ys[i]];
					if (temp_H != 0 && temp_H > max_H)
						break;
				}
			}

		}
	delete[] heights;
	cout << Cx - 1 << ' ' << Cy - 1 << ' ' << H;
}


Measured memory_bytes: 3228
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
//MACROS
#define _crt_secure_no_warnings
#define FREEELO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F
#define MAX 100001
#define MOD 1000000007
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;
typedef unordered_set<int> usi;
typedef unordered_multiset<int> usmi;

vector<vector<int> > g;
int used[MAX];
void dfs(int v){
    used[v] = 1;
    for (auto &to : g[v]){
        if (!used[to]) dfs(to);
    }
}


int main(){
    FREEELO
    int n, m; cin >> n >> m;
    g.resize(n + 1);
    loop(i, m){
        int a, b; cin >> a >> b;
        g[a].pb(b); g[b].pb(a);
    }
    int cnt = 0;
    loop(i, n){
        if (!used[i]){
            cnt++;
            dfs(i);
        }
    }
    cout << cnt - 1 << endl;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int ans;
    REP(i,5){
        int x;
        cin >> x;
        if(x==0)ans=i+1;
    }
    cout << ans << endl;

}


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

int main() {
int n,m;
  cin >> n >> m;
  if(n==m) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

#define int long long

main(){
	int n,c,k;
	int t[100002];

	cin>>n>>c>>k;
	for(int i=0;i<n;i++)cin>>t[i];
	sort(t,t+n);
	int ans=0;
	int mn=-1;
	int cnt=0;
	for(int i=0;i<n;i++){

		if(cnt==0)mn=t[i];
		if(t[i] > mn+k || cnt==c){
			ans+=(cnt-1)/c+1;
			mn=t[i];
			cnt=0;
		}
		cnt++;

		//cout<<cnt<<" "<<ans<<" "<<mn<<endl;
	}

	if(cnt>0)ans+=(cnt-1)/c+1;
	cout<<ans<<endl;
	return(0);
}

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

int main() {
  int n,k;
  string s;
  cin >> n>>s>>k;
  rep(i,s.size()){
    if(s.at(i)!=s.at(k-1)) s[i]='*';
  }
  cout<<s<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
int n,a[200005], b[200005];
int cur = 1, tr[200005], dc[200005];
int c = 100000;
pair<int,int> store[200005];
int f(int u){
	return (a[u] < 0 ? u : a[u] = f(a[u]));
}
void m(int u,int v){
	u = f(u); v = f(v);
	if(u == v) return;
	if(a[u] > a[v]) swap(u,v);
	a[u] += a[v]; a[v] = u;
}
signed main(){
	cin >> n;
	for(int i = 1 ; i <= 200004 ; i ++) a[i] = -1;
	for(int i = 1 ; i <= n ; i ++){
		int x, y;
		cin >> x >> y;
		b[x] = 1; b[c + y] = 1;
		m(x, c + y);
	}
	int ans = 0;
	for(int i = 1 ; i <= 200004 ; i ++){
		if(b[i]){
			if(!dc[f(i)]){
				dc[f(i)] = 1;
				tr[f(i)] = cur;
				cur ++;
			}
			if(i <= c) store[tr[f(i)]].fi ++;
			else store[tr[f(i)]].se ++;
		}
	}
	for(int i = 1 ; i < cur ; i ++)
		ans += store[i].fi * store[i].se;
	cout << ans - n;
}


Measured memory_bytes: 7552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;

int main(){
    ll i,j;
    ll n,m,c;
    cin>>n>>m>>c;
    ll b[m];
    ll x;
    ll ans=0;
    for(i=0;i<m;i++) cin>>b[i];
    for(i=0;i<n;i++){
        ll t=c;
        for(j=0;j<m;j++){
            cin>>x;
            t+=x*b[j];
        }
        if(t>0) ans++;

    }
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    Edge = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        Edge[a-1].append(b-1)
        Edge[b-1].append(a-1)
    Col = [-1] * N
    q = deque()
    q.append((0, 0))
    bipartite = True
    while q:
        nnode, ncol = q.pop()
        if Col[nnode] == -1:
            Col[nnode] = ncol
            for e in Edge[nnode]: q.append((e, ncol ^ 1))
        else:
            if Col[nnode] != ncol:
                bipartite = False
                break
    
    if bipartite:
        zero, one = 0, 0
        for i, n in enumerate(Col):
            if n == 0: zero += 1
            else: one += 1
        print(zero * one - M)
    else:
        print(N * (N - 1) // 2 - M)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 26772
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<stack>
#include<map>
#include<queue>
#include<unordered_map>
#include<cmath>
#include<utility>
 
#include<ctime>
#include<random>
#include<climits>
using namespace std;
typedef long long ll;
ll inf = LLONG_MAX;
int D;
int v=27;
vector<int> c(v,0);
vector<vector<int>> s;
vector<int> last(v,0);
vector<int> t(D+1);

void init(){
    cin >> D;
    s.resize(D+1);
    t.resize(D+1);
    for(int i=0;i<D+1;i++){
        s[i].resize(v);
    }

    for(int i=1;i<27;i++){
        cin >> c.at(i);
    }
    for(int i=1;i<D+1;i++){
        for(int j=1;j<27;j++){
            cin >> s.at(i).at(j);
        }
    }
    /*
    for(int i=1;i<D+1;i++){
        cin >> t.at(i);
    }
    */

}

void init_last(){
  for(int i=0;i<v;i++){
    last.at(i) = 0;
  }
}

ll calc(){
    init_last();
    ll ans = 0;
    for(int i=1;i<D+1;i++){
        ans += s.at(i).at(t.at(i));
        last.at(t.at(i)) = i;
        for(int j=1;j<v;j++){
            ans -= c.at(j) * (i - last.at(j));
        }
    }
    return ans;
}

int main(){
    init();
    std::random_device rd;
 
    std::mt19937 mt(rd());

    //vector<int> t(D+1);

    for(int d=1;d<D+1;d++){
      	ll max_score=-inf;
        ll best_i=0;
        for(int i=1;i<27;i++){
            t.at(d) = i;
            ll score = calc();
            if(score > max_score){
                max_score = score;
                best_i = i;
            }
        }
        t.at(d) = best_i;
    }

    for(int i=1;i<D+1;i++){
        cout << t.at(i) << endl;
    }
  	//cout << calc() << endl;
  
  	return(0);
}


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

// ----------- define --------------
#define int long long
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void MAIN() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1);
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    if (u == 1) a[v]++;
    if (v == n) a[u]++;
  }
  for (int i = 2; i < n; i++) {
    if (a[i] == 2) {
      cout << "POSSIBLE" << '\n';
      return;
    }
  }
  cout << "IMPOSSIBLE" << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 4784
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int f = a*x + b*y;
	int g = 0;
	if (x > y) {
		g = c * 2 * y + a*(x - y);
	}
	if (x == y) {
		g = c * 2 * y;
	}
	if (x < y) {
		g = c * 2 * x + b*(y - x);
	}
	int h = 2 * c*max(x, y);
	cout << min(f, min(g,h)) << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int X, n; cin >> X >> n;
  set<int> st;
  for (int i = 0; i < n; i++) {
    int in; cin >> in;
    st.insert(in);
  }

  int ans;
  int minVal = inf;
  for (int x = -1000; x <= 1000; x++) {
    if (st.find(x) != st.end()) continue;

    int tmp = (int)abs(x - X);
    if (minVal > tmp) {
      ans = x;
      minVal = tmp;
    }
  }

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


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

vector<pair<string, int>> solution(int n){
  if (n==1){
    vector<pair<string, int>> v;
    v.push_back(make_pair("a", 1));
    return v;
  }
  vector<pair<string, int>> v = solution(n-1);
  vector<pair<string, int>> ans;
  for (auto p: v){
    string s = p.first;
    int x = p.second;
    for (int i=0; i<x+1; i++){
      if (i==x) ans.push_back(make_pair(s + char(('a' + i)), x+1));
      else ans.push_back(make_pair(s + char(('a' + i)), x));
    }
  }
  return ans;
}

int main(){
  int n;
  cin >> n;
  vector<pair<string, int>> ans = solution(n);
  for (auto p: ans){
    cout << p.first << endl;
  }
  return 0;
}

Measured memory_bytes: 10080
#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>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli solve(){
	lli n;
	cin>>n;
	vll A(n);
	loop(i, 0, n)	cin>>A[i];
	vector<vector<pii> > dp(n, vector<pii>(n, {1e15, 0}));
	loop(len, 1, n+1){
		lli i = 0;
		lli j = i+len-1;
		if(len == 1){
			while(i < n && j < n){
				dp[i][j] = {0, A[i]};
				i++;
				j++;
			}
		}
		else{
			while(i < n && j < n)
			{	
				lli k = 1;
				while(k < len){
					lli temp = dp[i][j-(len-k)].fi + dp[i][j-(len-k)].se + dp[i+k][j].fi + dp[i+k][j].se; 
					dp[i][j] = {min(temp, dp[i][j].fi), dp[i][j-1].se + A[j]};
					k++;
				}
				i++;
				j++;
			}
		}
	}
//	cout<<"\n";
//	loop(i, 0, n){
//		loop(j, 0, n)	cout<<" ("<<dp[i][j].fi<<" "<<dp[i][j].se<<") ";
//		cout<<"\n";
//	}
	cout<<dp[0][n-1].fi<<"\n";
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 2816
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    b = sorted(list(map(int, input().split())))
    c = sorted(list(map(int, input().split())))

    cnt = 0
    for x in b:
        cnt += bisect_left(a, x)*(n-bisect_right(c, x))
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22720
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        int min = 101;

        for(int i='a'; i<='z'; i++){
            int l=0;
            int max = 0;
            for(int j=0; j<s.length(); j++){
                if((int)s.charAt(j) == i){
                    l = 0;
                }else{
                    l++;
                    if(l>max) max = l;
                }
            }
            if(max < min) min = max;
        }

        System.out.print(min);

    }
}

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

using namespace std;

typedef long long ll;

const int mod = 1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> sk(n);
	for(int i=0;i<n;i++) cin >> sk[i];
	sort(sk.begin(),sk.end());
	ll ans = 0;
	for(int i=n-1;i>=2;i--){
		for(int j=i-1;j>=1;j--){
			if(sk[i]>=2*sk[j]) break;
			for(int k=j-1;k>=0;k--){
				if(sk[i]>=sk[j]+sk[k]){
					break;
				}
				ans++;
			}
		}
	}
	cout << ans << "\n";
	
	return 0;
}

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

int main(){
	int k; cin>>k;
	string s; cin>>s;
	
	if(s.size()<=k){
      cout << s << endl;
      return 0;
    } else {
		for(int i=0; i<k; i++){
			cout << s[i];
		}
	}
	cout << "..." << endl;

}



Measured memory_bytes: 3624
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define up(i, a, b) for (int i = (a); i <= (b); i++)
#define down(i, a, b) for (int i = (a); i >= (b); i--)
#define mem(x, y) memset(x, (y), sizeof x)
#define ff first
#define ss second
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define sc(a) scanf("%d", &a)
#define scl(a) scanf("%lld", &a)
#define scs(a) scanf("%s", a)
#define pr(a, b) printf("%d%c", a, b)
#define prl(a, b) printf("%lld%c", a, b)
#define PQ priority_queue
#define ld long double
#define all(v) v.begin(), v.end()
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> V;

int a[100010];
int main(){
	int x,y;sc(x),sc(y);
	if((x+y)&1)printf("IMPOSSIBLE");
	else pr((x+y)>>1,'\n');
}

Measured memory_bytes: 764
# 1 以上 N 以下の整数のうち、10 進法での各桁の和が A 以上 B 以下であるものの総和を求めてください。
n, a, b = [int(x) for x in input().split()]
total = 0

def digit_sum(num,digitotal = 0):
      while(num > 0):
            digitotal += num%10
            num //= 10
      return digitotal
      
for i in range(1,n+1):
      x = digit_sum(i)
      if x >= a and x <= b:
            #print(i,end=", ")
            total += i

print(total)

Measured memory_bytes: 9172
n = int(input())
s = input()

l = []
r = []
for i in range(n*2):
    if s[i] == 'B':
        if i % 2 == 0:
            l.append(i)
        else:
            r.append(i)

    elif s[i] == 'W':
        if i % 2 == 0:
            r.append(i)
        else:
            l.append(i)

if len(r) != len(l):
    print(0)
else:
    from bisect import bisect_left
    ans = 1
    counter = 0
    for i in reversed(range(len(l))):
        _l = l[i]
        idx = bisect_left(r, _l)

        ans *= max((len(r) - counter - idx), 0)
        ans = ans % (10 ** 9 + 7)
        counter += 1

        # print(idx + counter)
    from math import factorial

    ans *= factorial(len(r))
    print(ans % (10 ** 9 + 7))


Measured memory_bytes: 54108
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    ll k, a, b;
    cin >> k >> a >> b;

    ll ret = k + 1;
    ll c = k - (a - 1);
    if (b - a > 0 && c > 0) {
        ll x = a + (b - a) * (c / 2);
        if (c % 2 == 1)x++;
        ret = max(ret, x);
    }

    cout << ret << endl;
    return 0;
}

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

using namespace std;

int N, M;
int D[100][100];
int E[1000][3];

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            D[i][j] = 1e8;
        }
    }
    for (int i = 0; i < N; i++) {
        D[i][i] = 0;
    }

    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        D[a][b] = min(D[a][b], c);
        D[b][a] = min(D[b][a], c);

        E[i][0] = a;
        E[i][1] = b;
        E[i][2] = c;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < M; i++) {
        int a = E[i][0];
        int b = E[i][1];
        int c = E[i][2];

        if (D[a][b] != c) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = 1e18;

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

    int r = 0, l = 0;
    int cnt = 0;
    rep(i, s.size()){
        if(s[i] == '(') cnt++;
        else {
            if(cnt == 0) l++;
            else cnt--;
        }
    }

    // 最終的にcntには、左括弧が何個余っているかが格納されている
    r = cnt;

    string ans = "";
    rep(i, l) ans += "(";
    ans += s;
    rep(i, r) ans += ")";

    cout << ans << endl;
}

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

int main() {
	int x[10000];
	int i = 0;
	for ( i = 1; i <= 10000; i++) {
		cin >> x[i];
		if (x[i] == 0) break;
	}

	for (int j = 1; j < i; j++) {
		cout << "Case " <<j<<":"<< " "<<x[j]<< endl;
	}

	
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    string s;
    cin >> s;
    
    int g_cnt = 0, p_cnt = 0;
    int n = (int)s.length();
    for(int i = 0; i < n; ++i){
        if(s[i] == 'p')     p_cnt++;
    }
    
    cout << n / 2 - p_cnt << endl;
}

Measured memory_bytes: 512
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l1=LI()
  l2=LI()

  sm1=sum(l1)
  sm2=sum(l2)

  if sm1<sm2:
    return -1

  a=[]
  b=[]
  for i,x in enumerate(l1):
    y=l2[i]
    if x<y:
      a.append(y-x)
    elif x>y:
      b.append(x-y)
  b.sort()

  if len(a)==0:
    return 0

  # print(a)
  # print(b)

  ans=len(a)
  _lenb=len(b)
  _a=a.pop()
  _b=b.pop()
  while True:
    if _b>=_a:
      _b-=_a
      if len(a)<=0:
        break
      else:
        _a=a.pop()

    else:
      _a-=_b
      _b=b.pop()

  return ans+_lenb-len(b)

# main()
print(main())


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

int main() {
    int n; cin >> n;
    vector<int> c(n);
    for(int i = 0; i < n; i ++) {
        int a; cin >> a;
        while(a%2==0) {
            c[i]++;
            a /= 2;
        }
    }
    int ans = *min_element(c.begin(), c.end());
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
   int  N,A,B,C,D,price_X,price_Y;
   scanf( "%d %d %d %d %d" , &N,&A,&B,&C,&D );
   price_X=(N/A+( N%A != 0 ))*B;
   price_Y=(N/C+( N%C != 0 ))*D;
   if( price_X < price_Y ){
	 printf("%d\n" , price_X);
      }else{
    	 printf("%d\n" , price_Y);
      }
   return 0;
}



Measured memory_bytes: 2140
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <pll> v;
ll dp[102][100005];

ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}

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

	ll n,i,m=0,j,k=0,x,y,a,b,w;
	string s;
	
	cin >> n >> w;
	v.pb(mp(0,0));
	for(i=0;i<n;i++)
	{
		cin >> x >> y;
		v.pb(mp(x,y));
		k=max(k,y);
	}
	k*=n;
	m=0;
	for(i=0;i<=n;i++)
		for(j=0;j<=k;j++)
			dp[i][j]=1000000000000000;
	dp[0][0]=0;
	for(i=1;i<=n;i++)
	{
		for(j=0;j<=k;j++)
		{
			if(j<v[i].second)
				dp[i][j]=min(dp[i][j],dp[i-1][j]);
			else
				dp[i][j]=min(dp[i-1][j],min(dp[i][j],v[i].first+dp[i-1][j-v[i].second]));
		}
	}
	m=0;
	for(i=0;i<=k;i++)
		if(dp[n][i]<=w)
			m=i;
	cout << m;
	return 0;
}


Measured memory_bytes: 79232
// atcoder/abc157/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    cout << (n + 1) / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main( ){
  int n,Y,M,D,sum,i;
  cin>>n;
  for(i=0;i<n;i++){
    sum=0;
    cin>>Y>>M>>D;
    sum+=(Y-1)*195+(Y-1)/3*5;
    sum+=(M-1)*20-(M-1)/2+D;
    if(Y%3==0)sum+=(M-1)/2;
    sum=196471-sum;
    cout<<sum<<endl;
     
  }
  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 1e2 + 10;

int n, m;
int w[maxN], v[maxN];
ll dp[maxN][100005];

int main(){
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> w[i] >> v[i];
  }
  for (int pri = 0; pri <= m; ++pri) {
    dp[1][pri] = (pri >= w[1] ? v[1] : 0);
  }
  for (int i = 2; i <= n; ++i) {
    for (int pri = 0; pri <= m; ++pri) {
      dp[i][pri] = dp[i-1][pri];
      if (pri >= w[i]) dp[i][pri] = max(dp[i][pri], dp[i-1][pri-w[i]] + v[i]);
    }
  }
  cout << dp[n][m];
return 0;
}


Measured memory_bytes: 81632
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define ff first
#define ss second
#define ll long long
#define int long long
#define mod 4e18
#define pii pair<ll,ll>
#define vi vector<ll>
#define mii map<ll,ll>
#define pb push_back
#define mp make_pair
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) ll x; cin>>x; while(x--)
#define endl '\n'
#define str string
#define all(v) v.begin(),v.end()
void kehsihba(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
	//kehsihba();
	ll a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	ll f=((a[0]+a[1])-(a[2]));
	if(!f){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
arr1, arr2 = [0], [0]
for i in range(n):
	arr1.append(arr1[i] + A[i])
for i in range(m):
	arr2.append(arr2[i] + B[i])

count = 0
j = m
for i in range(n + 1):
	if arr1[i] > k:
		break
	while arr2[j] > k - arr1[i]:
		j -= 1
	count = max(count, i + j)
print(count)

Measured memory_bytes: 47308
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B && A == C || A != B && A != C && B != C)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
#define enld endl
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    char c; cin >> c;
    if(c >= 'A' && c <= 'Z'){
        cout << 'A' << endl;
    }else{
        cout << 'a' << enld;
    }
    return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
int main(void)
{
  int n,a;
  long sum=0;
  scanf("%d ",&n);
  int data[n];
  for(int i=0;i<n;i++)
    scanf("%d ",&data[i]);
  int min = data[0];
  int max = data[0];
  for(int i=0;i<n;i++)
  {

    if(data[i]<min)
      min=data[i];
    if(data[i]>max)
      max=data[i];
    sum+=data[i];
  }
  printf("%d %d %ld\n",min, max,sum);
}

Measured memory_bytes: 1888
#include <stdio.h>

typedef struct node{
    int parent;
    int left;
    int right;
    int id;
} Node;

void printPre(Node *, int);
void printIno(Node *, int);
void printPos(Node *, int);
 
int main(){
    int i, n, root, buf;
    Node A[32];
    scanf("%d", &n);

	for(i = 0 ; i < n ; i++){
		A[i].parent = -1;
		A[i].left = -1;
		A[i].right = -1;
	}

    for(i = 0 ; i < n ; i++){
		scanf("%d", &buf);
        scanf("%d %d", &A[buf].left, &A[buf].right);
        if(A[buf].left != -1)A[A[buf].left].parent = i;
        if(A[buf].right != -1)A[A[buf].right].parent = i;
    }
	
	for(i = 0 ; i < n ; i++){
		if(A[i].parent == -1){
			root = i;
			break;
		}
	}

	printf("Preorder\n");
    printPre(A, root);
	printf("\n");
	printf("Inorder\n");
    printIno(A, root);
	printf("\n");
	printf("Postorder\n");
    printPos(A, root);
	printf("\n");

    return 0;
}

void printPre(Node *A, int id){
	printf(" %d", id);
	if(A[id].left != -1)printPre(A, A[id].left);
	if(A[id].right != -1)printPre(A, A[id].right);
}

void printIno(Node *A, int id){
	if(A[id].left != -1)printIno(A, A[id].left);
	printf(" %d", id);
	if(A[id].right != -1)printIno(A, A[id].right);
}

void printPos(Node *A, int id){
	if(A[id].left != -1)printPos(A, A[id].left);
	if(A[id].right != -1)printPos(A, A[id].right);
	printf(" %d", id);
}


Measured memory_bytes: 2112
using System;
using System.Linq;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var count = 0;
            var a = input[0];
            var b = input[1];
            
            if(a == 2) count = b - 1;
            else count = b / (a - 1) + (b % (a - 1) > 1 ? 1 : 0);
            
            Console.WriteLine(count);
        }
    }
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pii, pii> ppp;
typedef pair<int, ppp> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int W, H;
pii tp, kp;
int maps[50][50];
bool done[50][50][50][50];

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

bool ok(pii p) {
	if (!(p.fi >= 0 && p.fi < H && p.se >= 0 && p.se < W)) return false;
	if (maps[p.fi][p.se] == 1) return false;
	return true;
}

int main() {
	while (cin >> W >> H, W || H) {
		cin >> tp.se >> tp.fi >> kp.se >> kp.fi;
		tp.se--; tp.fi--; kp.se--; kp.fi--;
		REP(i, H) REP(j, W) scanf("%d", &maps[i][j]);
		
		memset(done, 0, sizeof(done));
		queue<P> que;
		que.push(P(0, ppp(tp, kp)));
		done[tp.fi][tp.se][kp.fi][kp.se] = true;
		
		int ans = INF;
		
		while (!que.empty()) {
			int c = que.front().fi;
			pii p1 = que.front().se.fi, p2 = que.front().se.se;
			que.pop();
			
			if (p1 == p2) { ans = c; break; }
			if (c >= 100) break;
			
			REP(i, 4) {
				pii np1(p1.fi + dy[i], p1.se + dx[i]);
				pii np2(p2.fi + dy[(i+2)%4], p2.se + dx[(i+2)%4]);
				
				bool o1 = ok(np1), o2 = ok(np2);
				if (!o1 && !o2) continue;
				
				np1 = o1 ? np1 : p1;
				np2 = o2 ? np2 : p2;
				if (!chmax(done[np1.fi][np1.se][np2.fi][np2.se], 1)) continue;
				que.push(P(c + 1, ppp(np1, np2)));
			}
		}
		
		if (ans == INF) puts("NA");
		else cout << ans << endl;
		
	}
	return 0;
}

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

#define int long long

using namespace std;

const int MAXN = 3010;

const int MOD = 998244353;

int dp[MAXN][MAXN];

int A[MAXN];

int qpow(int a, int b)
{
	int res = 1;
	while(b)
	{
		if(b&1)res = res*a%MOD;
		a = a*a%MOD;
		b /= 2;
	}
	return res;
}

int inv(int x)
{
	return qpow(x,MOD-2);
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int N, S;
    cin >> N >> S;

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

    int iv = inv(2);

    dp[0][0] = qpow(2,N);

    for(int i = 1 ; i <= N ; i++)
    {
    	for(int j = 0 ; j <= S ; j++)
    	{
    		dp[i][j] = dp[i-1][j];
    		if(j-A[i] < 0)continue;
    		dp[i][j] = (dp[i][j] + dp[i-1][j-A[i]]*iv%MOD)%MOD;
    	}
    }

    cout << dp[N][S] << '\n';

    return 0;
}

Measured memory_bytes: 74220