akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m;
    cin>>n>>m;
    if(abs(n-m)>1)
    {
        cout<<0<<endl;
        return 0;
    }
    if(n==m)
    {
    ll brojac=1;
    for(ll i=1;i<=n;i++)
    {
        brojac*=i;
        brojac%=1000000007;
    }
    for(ll i=1;i<=n;i++)
    {
        brojac*=i;
        brojac%=1000000007;
    }
    brojac*=2;
    brojac%=1000000007;
    cout<<brojac<<endl;
    }
    else
    {
        ll brojac=1;
        if(n<m)
            swap(n,m);
        for(ll i=1;i<=n;i++)
    {
        brojac*=i;
        brojac%=1000000007;
    }
    for(ll i=1;i<=m;i++)
    {
        brojac*=i;
        brojac%=1000000007;
    }
    cout<<brojac<<endl;
    }
    return 0;
}

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

const int MAX_N = 200000;
const int MAX_PRIMES_SIZE = 20000;
int primes[MAX_PRIMES_SIZE];
int primesSize;
const int P_LOOP_SIZE = 100;

void setPrimes() {
    fill_n(primes, MAX_PRIMES_SIZE, 0);
    primes[0] = 2;
    primesSize = 1;
    for (int i = 3; i < MAX_N; i += 2) {
        bool isPrime = true;
        for (int j = 0; j < primesSize; j++) {
            if (i % primes[j] == 0) {
                isPrime = false;
                break;
            }
        }
        if (isPrime == true) {
            primes[primesSize++] = i;
        }
    }
}

int main() {
    setPrimes();
    while (true) {
        int n, p;
        cin >> n >> p;
        if (n == -1 && p == -1) {
            break;
        }
        int *start;
        for (int i = 0; i < MAX_PRIMES_SIZE; i++) {
            if (primes[i] > n) {
                start = primes + i;
                break;
            }
        }
        multiset<int> pSet;
        for (int i = 0; i < P_LOOP_SIZE; i++) {
            for (int j = i; j < P_LOOP_SIZE; j++) {
                pSet.insert(*(start + i) + *(start + j));
            }
        }
        int i = 0;
        for (set<int>::iterator it = pSet.begin(); it != pSet.end(); it++) {
            if (i == p - 1) {
                cout << *it << endl;
                break;
            }
            i++;
        }
    }
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

char S[123456];

int main() {

	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: 256
#include<stdio.h>

int main(void){
	int h,w,i,j=0;
	while(1){
		scanf("%d %d",&h,&w);
		if((h==0)&&(w==0))break;
		for(i=1;i<=h;i++){
			if((i%2)!=0){
				for(j=0;j<(w/2);j++){
					printf("#.");
				}
				if((w%2)!=0)printf("#");
				printf("\n");
			}else{
				for(j=0;j<(w/2);j++){
				printf(".#");
				}
				if((w%2)!=0)printf(".");
				printf("\n");
			}
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2044
//do not think about past and stay in this moment
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
int prime[1000005];
void seive(){
	for(int i=2;i<1000005;++i){
		if(prime[i]==0)
		for(int j=2*i;j<1000005;j+=i)
			prime[j]=1;
	}
}			
int digit(int n){
	int xp=0;
	while(n!=0){
		n/=10;
		xp++;
	}
	return xp;
}
void q1(){
	string s,t;
	cin>>s>>t;
	cout<<t<<s;
}
void q2(){
	int a,b,k;
	cin>>a>>b>>k;
	int mn=min(a,k);
	a-=mn; k-=mn;
	mn=min(b,k);
	b-=mn; k-=mn;
	cout<<a<<" "<<b;
}
void q3(){
	int x;
	cin>>x;
	seive();
	while(prime[x])
	x++;
	cout<<x<<endl;
}
void q4(){
	
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t=1;
	while(t--)
	q2();
	return 0;
}
	


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    mod = 10**9+7
    S = input().strip()
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0] = 1
    m = 1
    for n in range(N):
        c = S[N-n-1]
        for i in range(10):
            if c == "?" or int(c) == i:
                for j in range(13):
                    dp[n+1][(j + i*m) % 13] += dp[n][j] % mod
        m = m * 10 % 13
    print(dp[N][5] % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61916
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		//int n = Integer.parseInt(sc.next());
		//long res=n;
		//int l = Integer.parseInt(sc.next());
		//int sum=0;
		//String s = sc.next();
		//int a = Integer.parseInt(sc.next());
		//String t = sc.next();

		if(a==b&&a==c) {
			System.out.println(1);
		}else if(a==b||b==c||a==c){
			System.out.println(2);
		}else {
			System.out.println(3);
		}
		//System.out.println((a+b)*c/2);
	}
}




Measured memory_bytes: 21332
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    for (int i = 0; i < 3; i++) cout << s[i];
    cout << '\n';
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;int n,sum,i;main(){cin>>n;sum=n;for(i=2;i*i<=n;i++){if(n%i==0){sum=sum/i*(i-1);while(n%i==0){n/=i;}}}if (n!=1) {sum=sum/n*(n-1);}cout<<sum<<endl;}

Measured memory_bytes: 1160
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        sc.close();
        int pos;
        for(int i=s.length-t.length;i>=0;i--){
            pos = 0;
            while(pos < t.length && (s[i+pos]==t[pos] || s[i+pos] =='?'))pos++;
            if(pos == t.length){
                printKey(i,s,t);
                return;
            }
        }

        System.out.print("UNRESTORABLE");
        System.out.flush();
    }
    public static void printKey(int pos,char[] s,char[] t){
        StringBuilder sb = new StringBuilder();
        
        for(int i=0;i<s.length;i++){
            if(i>=pos && i < pos+t.length){
                sb.append(t[i-pos]);
            }else if(s[i] == '?'){
                sb.append('a');
            }else {
                sb.append(s[i]);
            }
        }
        System.out.print(sb.toString());
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) {
        cin >> a[i];
    }
    int sum = 1;
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for(int i = 1; i < n; i++) {
        if(n == 1)break;
        if(a[i] == a[i-1])continue;
        sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int li[] = new int[n];
        for (int i = 0; i < n; i++) {
			 li[i] = sc.nextInt();
        }
        //System.out.println(li[1]);
        boolean h = true;
		int cnt = 0;
		while (h) {
			for (int k = 0; k < n; k++) {
				if (li[k] % 2 != 0) {
					h = false;
					break;
				} else if (k == n-1) {
                    cnt++;
                }
                li[k] = li[k]/2;
			}
		}
		System.out.println(cnt);
		sc.close();

    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		System.out.print(n +":");
		for(int i = 2; i * i <= n; i++) {
			if(n % i == 0) {
				while(n % i == 0) {
					System.out.print(" " + i);
					n = n / i;
				}
			}
		}
		if(n != 1) {
			System.out.print(" " + n);
		}
		System.out.println();
	}
}


Measured memory_bytes: 26332
open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let Mod = (1e9|>int64)+7L
[<EntryPoint>]
let main argv =
    let A,B,K = RS int64|>fun c->c.[0],c.[1],c.[2]
    (max 0L (A-K))|>stdout.Write
    stdout.Write " "
    if A>=K then B else (max 0L (B-(K-A)))
    |>stdout.WriteLine
    0


Measured memory_bytes: 11220
#include <iostream>
#include <list>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,m,a,b,c,mi,ret;
	int info[100][100];
	while(cin >> n >> m && n){
		ret = 0;
		rep(i,100)rep(j,100)info[i][j] = INT_MAX;
		for(int i=0;i<m;i++){
			cin >> a >> b >> c;
			info[a][b] = info[b][a] = c;
		}
		list<int> X,Y;
		for(int i=1;i<n;i++){
			Y.push_back(i);
		}
		X.push_back(0);
		while(!Y.empty()){
			mi = INT_MAX;
			list<int>::iterator it = X.begin();
			while( it != X.end() ){
				for(int i=0;i<n;i++){
					if( count(Y.begin(),Y.end(),i) )
						if(info[*it][i]<mi){
							a = i;
							mi = info[*it][i];
						}
				}
				++it;
			}
			X.push_back(a);
			it = Y.begin();
			while( it != Y.end() ){
				if((*it)==a){
					Y.erase(it);
					break;
				}
				++it;
			}
			ret+=mi;
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 948
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(N)])

res = M
n = 0
cnt = 0


while(AB[n][1] < res):
    cnt += AB[n][0] * AB[n][1]
    res -= AB[n][1]
    n += 1

cnt += res * AB[n][0]

print(cnt)


Measured memory_bytes: 28656
#include<iostream>
#include<string>
#include <cmath>
#include <ctype.h>
#include<vector>
#include<algorithm>
using namespace std;
string str;
vector<string> field;
char s[101][101];
char b[103][103];
int main() {
    cin >> str;
    sort(str.begin(), str.end());
    bool flag=true;
    for(int i=0; i<str.size()-1; ++i){
        if(str[i+1]==str[i]){
            flag=false;
        break;
        }
    }
    if(flag) cout <<"yes" << endl;
    else cout << "no" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define str string
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 1e5 + 10;
const ll LINF = LLONG_MAX;
int main() {
    fast();

    ll n;
    cin >> n;
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    f(i,1,n)
    {
        if((1<<i)>n)
        {
            cout<<(1<<i-1)<<edl;
            break;
        }
    }   


    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

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

int main() 
{
    unsigned int a = 0, max_num = 11, min_num = 0;

    std::cin >> a;
    if ((min_num < a) && (a < max_num)) {
        a = a + (a * a) + (a * a * a);
        std::cout << a;
    }
    else
    {
        std::cout << "Err a = " << a;
    }

}

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

#define LL long long int
#define mp make_pair
#define FOR(i, n) for(i = 0; i < n; ++i)
typedef vector <int> vi;
typedef vector <LL> vll;
typedef pair<LL, LL> iPair;
const int MOD = 1e9+7;

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

    LL t = 1;
    LL i,j;
    // cin>>t;
    
    while(t--)
    {
        int n;
        cin >> n;

        vi arr(n);
        FOR(i, n) cin >> arr[i];

        vi dp(n);
        dp[0] = 0;
        dp[1] = abs(arr[1] - arr[0]);
        for(int i = 2; i < n; ++i)
        {
            dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]));
        }        
        cout<<dp[n-1];
    }

	return 0;
}


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

int n,m,q;
int res=0;
vector<int> a,b,c,d;

void dfs(vector<int> A) {
  if (A.size()==n+1) {
    int tmp=0;
    rep(i, q) if (A[b[i]]-A[a[i]]==c[i]) tmp+=d[i];
    res=max(res, tmp);
    return ;
  }
  A.push_back(A.back());
  while (A.back()<=m) {
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin>>n>>m>>q;
  a=b=c=d=vector<int>(q);
  rep(i, q) cin>>a[i]>>b[i]>>c[i]>>d[i];
  dfs(vector<int> (1, 1));
  cout<<res<<endl;
}


Measured memory_bytes: 3624
import sys
from collections import deque
def m():
 s=sys.stdin.readlines()
 q=int(s[0].split()[1])
 f=lambda x,y:(x,int(y))
 d=deque(f(*e.split())for e in s[1:])
 t,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n, k;
  cin >> n >> k;
  vll v(n);
  REP(i, n)
    cin >> v[i];

  ll ans = -LLINF;
  priority_queue<ll, vector<ll>, greater<ll>> que;
  for(int a = 0; a <= min(n, k); a++){
    for(int b=0; b<=min(n, k)-a; b++){
     for(int c=0; c <= min(n, k-a-b); c++){
       REP(i, a)
         que.push(v[i]);
       REP(i, b)
         que.push(v[n-i-1]);

       REP(i, c){
         if(!que.empty() && que.top() < 0)
           que.pop();
       }

       ll sum = 0;
       while(!que.empty()){
         sum += que.top();
         que.pop();
       }
       ans = max(ans, sum);

     }
    }
  }

  cout << ans << endl;
  
}


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

int main(void) {
    int n, pos = 0, ans = 0;
    string s;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> s;
    while (s.find("ABC", pos) != string::npos) {
        ans++;
        pos = s.find("ABC", pos) + 3;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
n = gets.strip.to_i
h = gets.strip.split(' ').map(&:to_i)
c = 1
n.times do |i|
  next if i < 1
  r = h[0..(i - 1)].all? { |j| j <= h[i] }
  c += 1 if r && h[i-1] <= h[i]
end
puts c

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
Int MOD=1000000009LL; //<- alert!!!
typedef vector<Int> arr;
typedef vector<arr> mat;
inline arr mul(mat a,arr& b,Int mod){
  arr res(b.size(),0);
  for(int i=0;i<(int)b.size();i++)
    for(int j=0;j<(int)a[i].size();j++)
      (res[i]+=a[i][j]*b[j])%=mod;
  return res;
}
inline mat mul(mat& a,mat& b,Int mod){
  mat res(a.size(),arr(b[0].size(),0));
  for(int i=0;i<(int)a.size();i++)
    for(int j=0;j<(int)b[0].size();j++)
      for(int k=0;k<(int)b.size();k++)
	(res[i][j]+=a[i][k]*b[k][j])%=mod;
  return res;
}
mat base;
inline mat mat_pow(mat a,Int n,Int mod){
  if(base.empty()){
    base=mat(a);
    for(int i=0;i<(int)a.size();i++)
      for(int j=0;j<(int)a[i].size();j++)
	base[i][j]=(i==j);
  }
  mat res(base);
  while(n){
    if(n&1) res=mul(a,res,mod);
    a=mul(a,a,mod);
    n>>=1;
  }
  return res;
}
mat memo[100];
void init(mat a,Int mod){
  base=mat(a);
  for(int i=0;i<(int)base.size();i++)
    for(int j=0;j<(int)base.size();j++)
      base[i][j]=i==j;
  memo[0]=a;
  for(int k=1;k<70;k++)
    memo[k]=mul(memo[k-1],memo[k-1],mod);
}
inline mat mat_pow2(Int n,Int mod){
  mat res(base);
  int k=0;
  while(n){
    if(n&1) res=mul(memo[k],res,mod);
    n>>=1;
    k++;
  }
  return res;
}
//END CUT HERE

typedef pair<Int,Int> P;
signed main(){
  Int w,h,n,cnt=0;
  while(cin>>w>>h>>n,w||h||n){
    Int x[n],y[n];
    for(Int i=0;i<n;i++) cin>>x[i]>>y[i];
    P p[n];
    for(Int i=0;i<n;i++) p[i]=P(y[i],x[i]);
    sort(p,p+n);
    for(Int i=0;i<n;i++) x[i]=p[i].second,y[i]=p[i].first;
    arr a(w,0);
    a[0]=1;
    mat b(w,arr(w,0));
    for(Int i=0;i<w;i++){
      for(Int j=0;j<w;j++) b[i][j]=0;
      b[i][i]=1;
      if(i-1>=0) b[i][i-1]=1;
      if(i+1<w)  b[i][i+1]=1;
    }
    init(b,MOD);
    Int d=1;
    for(Int k=0;k<n;k++){
      if(y[k]==d) continue;
      a=mul(mat_pow2(y[k]-d-1,MOD),a,MOD);
      Int j=k;
      mat c=b;
      while(j<n&&y[k]==y[j]){
	for(Int i=0;i<w;i++) c[x[j]-1][i]=0;
	j++;
      }
      a=mul(c,a,MOD);
      d=y[k];
    }
    a=mul(mat_pow2(h-d,MOD),a,MOD);
    cout<<"Case "<<++cnt<<": "<<a[w-1]<<endl;
  }
  return 0;
}

/*
verified on 2017/06/29
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2397
*/

Measured memory_bytes: 6336
#include "bits/stdc++.h"
using namespace std ;


int h[100005] ;
int c[100005] ;
int main(){
	int N , K ;
	cin >> N >> K;
	for( int i = 1 ; i <= N ; i++ ){
		cin >> h[i] ;
	}
	c[1] = 0 ;
	c[2] = abs(h[2]-h[1]) ;
	for( int i = 3 ; i <= N ; i++ ){
		c[i] = INT_MAX ;
		for( int j = 1 ; j <= K ; j++  ){
			if(i-j >= 1 )
				c[i] = min(c[i-j]+abs(h[i]-h[i-j]), c[i]) ;
			else break ;
		}
	}
	cout << c[N] << endl ;


	return 0 ;
}

Measured memory_bytes: 1024
n = int(input())
list = [list(map(int, input().split())) for i in range(n)]
newlist = sorted(list, key=lambda x:x[1])
x = 0
y = 0
for i in newlist:
	x += i[0]
	if x <= i[1]:
		continue
	else:
		y += 1
		break
if y == 0:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 55264
#include<bits/stdc++.h>
int main(){
    int h,w;std::cin>>h>>w;
    std::vector<int>a(26);
    for(int i=0;i<h*w;i++){
        char c;std::cin>>c;
        a.at(c-'a')++;
    }
    int two=0,one=0;
    for(int x:a){
        if(x%4)two++;
        if(x%2)one++;
    }
    int two_max=((h%2)*w+(w%2)*h)/2;
    std::cout<<(one<=1
            &&two<=two_max
            ?"Yes":"No")<<'\n';
}



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

int main() {
  int h1,m1,h2,m2,k=0;
  cin>>h1>>m1>>h2>>m2>>k;
  
  cout<<h2*60+m2-h1*60-m1-k;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll arr[60];
ll memo[60][60][105];
ll solve(int st,int en,int k){
if(k<=0){
return 0;
}
  if(st>en){
  return 0;
  }
  if(memo[st][en][k]!=-1)return memo[st][en][k];
  ll on=0;
on=max(on,arr[st]+solve(st+1,en,k-1));
on=max(on,arr[en]+solve(st,en-1,k-1));
on=max(on,solve(st+1,en,k-2));
on=max(on,solve(st,en-1,k-2));
     return memo[st][en][k]=on;
}
int main(){
    memset(memo,-1, sizeof memo);
   // cout<<memo[0][0]<<endl;;
int k,n;
cin>>n>>k;
  for(int i=0;i<n;i++){
  cin>>arr[i];
  }

 cout<<solve(0,n-1,k)<<endl;
}


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

int main() {
    string s;
    cin >> s;
    int n = s.length();
    long long ans = 0;
    for(int i = 0; i < (1 << n - 1); i++) {
        long long tmp = 0;
        for(int j = 0; j < n; j++) {
            tmp = tmp * 10 + s[j] - '0';
            if(i & (1 << j)) {
                ans += tmp;
                tmp = 0;
            }
        }
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
S=input()
if int(S[:2])>12 or S[:2]=='00':
  if int(S[2:])>12 or S[2:]=='00':
    print("NA")
  else:
    print("YYMM")
elif int(S[2:])>12 or S[2:]=='00':
  if int(S[:2])>12 or S[:2]=='00':
    print("NA")
  else:
    print("MMYY")
else:
  print("AMBIGUOUS")

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int L;
int tw[22];
vint u, v, w;
signed main() {
    tw[0] = 1;
    for (int i = 1; i < 22; i++)tw[i] = tw[i - 1] * 2;
    cin >> L;

    int N = 1;
    for (int i = 0; i < 20; i++) {
        if (tw[i + 1] > L)break;

        N++;
        u.push_back(i + 1);
        v.push_back(i);
        w.push_back(tw[i]);

        u.push_back(i + 1);
        v.push_back(i);
        w.push_back(0);
    }
    int cur = tw[N - 1];
    L -= cur;
    if (L % 2 == 1) {
        u.push_back(N - 1);
        v.push_back(0);
        w.push_back(cur);
        cur++;
    }
    L /= 2;

    for (int i = 1; i <= 20; i++) {
        if (L % 2 == 1) {
            u.push_back(N - 1);
            v.push_back(i);
            w.push_back(cur);
            cur += tw[i];
        }
        L /= 2;
    }


    cout << N << endl;
    cout << u.size() << endl;
    for (int i = 0; i < u.size(); i++) {
        cout << N - u[i] << " " << N - v[i] << " " << w[i] << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.time.Year;
import java.util.Random;
import java.math.*;

public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        String a = sc.next();
        int R = 0;
        if(a.charAt(0)=='R'){
                R++;
        }
        if(a.charAt(1)=='R'){
                R=R+2;
        }
        if(a.charAt(2)=='R'){
            R = R+4;
        }
        
        if(R==1 || R==2|| R==4 || R==5){
            System.out.println(1);
        }else if(R==3 || R == 6){
            System.out.println(2);
        }else if(R==7){
            System.out.println(3);
        }else{
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 35556
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    int H, W;
    while(1) {
        cin >> H >> W;
        if(H < 1 | W < 1)
            break;
        rep(i, H) {
            rep(j, W) {
                if((i + j) % 2) {
                    cout << '.';
                } else {
                    cout << '#';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3024
def f(p, k, W):
    i = 0
    t = 0
    s = 0
    while i < len(W) and t < k:
        if s + W[i] <= p:
            s += W[i]
            i += 1
        else:
            s = 0
            t += 1
    return i


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

l = 0
r = 100000 * 10000 // k
while r - l > 1:
    mid = (l + r) // 2
    v = f(mid, k, W)
    if v >= n:
        r = mid
    else:
        l = mid

print(r)



Measured memory_bytes: 9564
#include <bits/stdc++.h>
using namespace std;
# define mod 1000000007
int main(){
    long long int n,g,ans=0;
    cin>>n;
    vector<long long int> v, s(n,0);
    
    for(long long int i=0;i<n;i++)
    {
        cin>>g;
        v.push_back(g);
    }
    s[n-1]=v[n-1];
    for(int i=n-2;i>=0;i--)
    {
        s[i]=(v[i]+s[i+1])%mod;
    }
    for(int i=0;i<n-1;i++)
    {
        ans=(ans+(v[i]*s[i+1])%mod)%mod;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6924
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        
        // 4/N=1/h+1/n+1/w
        // 4hnw = Nnw + Nhw + Nhn
        // 4hnw - Nnw - Nhw = Nhn
        // w*(4hn - Nn - Nh) = Nhn
        
        for (long h = 1; h <= 3500; h++) {
            for (long n = 1; n <= 3500; n++) {
                long left = 4*h*n - N*n - N*h;
                long right = N*h*n;
                
                if (left == 0) continue;
                if (left < 0 || right < 0) continue;
                
                if (right % left == 0) {
                    long w = right / left;
                    System.out.println(h + " " + n + " " + w);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 39660
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct Edge {
  int to;
  int diff;

  Edge(int to, int diff) : to(to), diff(diff) {}
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<Edge>> edges(N);
  for (int i = 0; i < M; i++) {
    int v, u, diff;
    cin >> v >> u >> diff;
    v--;
    u--;
    edges[v].push_back(Edge(u, diff));
    edges[u].push_back(Edge(v, -diff));
  }

  vector<LL> pos(N, 0);
  vector<int> used(N, 0);

  bool ok = true;
  stack<int> vs;
  for (int i = 0; i < N; i++) {
    if (used[i] == 1) continue;
    vs.push(i);
    while (!vs.empty()) {
      int v = vs.top();
      vs.pop();
      // if(used[v] == 1) continue;
      used[v] = 1;
      for (auto e : edges[v]) {
        int u = e.to;
        if (used[u] == 1) {
          if (pos[u] - pos[v] != e.diff) ok = false;
        } else {
          vs.push(u);
          pos[u] = pos[v] + e.diff;
          used[u] = 1;
        }
      }
    }
  }
  for (int v = 0; v < N; v++)
    for (auto e : edges[v]) {
      int u = e.to;
      if (pos[u] - pos[v] != e.diff) ok = false;
    }

  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 10112
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >>s;
    string a = s.substr(0, 2);
    string b = s.substr(2, 2);
    int x = stoi(a);
    int y = stoi(b);
    if(x >= 1 && x <= 12 && y >= 1 && y <= 12)
        cout <<"AMBIGUOUS";
    else if(y >= 1 && y <= 12)
        cout <<"YYMM";
    else if(x >= 1 && x <= 12)
        cout <<"MMYY";
    else 
        cout <<"NA";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct Edge{
  double v;
  int d;
};
int main(){
  int n,m,p;
  int i,j,k;
  cin >> n >> m >> p;
  Edge edge[n+1][n+1];
  for(i=0;i<=n;i++){
    for(j=0;j<=n;j++){
      edge[i][j].d=0;
      edge[i][j].v=0;
    }
  }
  for(i=0;i<m;i++){
    cin >> j >> k ;
    cin >> edge[j][k].d >> edge[j][k].v;
    edge[k][j].d=edge[j][k].d;
    edge[k][j].v=edge[j][k].v;
  }
  
  //cout << n << m << p << endl;
  
  double dp[201][2005]={{}};
  //memset(dp,-1,sizeof(dp));
  for(i=0;i<201;i++){
    for(j=0;j<2005;j++){
      dp[i][j]=-1;
    }
  }
  dp[1][0]=0;
  for(i=0;i<p;i++){
    for(j=1;j<=n;j++){
      if(dp[j][i]==-1) continue;
      for(k=1;k<=n;k++){
	if(edge[j][k].d==0) continue;
	dp[j][i+1]=max(dp[j][i+1],dp[j][i]+(edge[j][k].v/edge[j][k].d));
	//cout << i << ":" << j << ":" << k <<"/"<< edge[j][k].d << endl;
	dp[k][i+edge[j][k].d]=max(dp[k][i+edge[j][k].d],dp[j][i]+edge[j][k].v);
      }
    }
  }
  //cout << dp[1][p] << endl;
  printf("%.6lf\n",dp[1][p]);
}

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

#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
unsigned GetDigit(unsigned num){
    return log10(num)+1;
}

signed main(){
    int a;
 string s,t;
cin >> a >> s >> t;
  a*=2;
REP(i,a){
if(i%2==0){
  cout<<s[i/2];
}else{
    cout <<t[i/2];
}
}

             }

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int s=0,n=0,e=0,w=0;
  int i;

  cin>>str;
  rep(i,str.size()){
    if(str[i]=='S')s++;
    else if(str[i]=='E')e++;
    else if(str[i]=='N')n++;
    else if(str[i]=='W')w++;
  }

  if((n>0 && s==0) || (n==0 && s>0))
    cout<<"No"<<endl;
  else if((e>0 && w==0) || (e==0 && w>0))
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k,x;cin>>k>>x;
  rep(i,k*2-1){
    cout<<i+x-k+1<<" ";
  }
  cout<<endl;

  return 0;

}


Measured memory_bytes: 256
#!/usr/bin/env python3
n, k = map(int,input().split())
list_people = list(range(1,n+1))
for i in range(k):
    d = int(input())
    list_get = list(input().split())
    for j in range(d):
        if int(list_get[j]) in list_people:
            list_people.remove(int(list_get[j]))
print(len(list_people))

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

int main()
{
    int N, X, T;

    cin >> N >> X >> T;

    int a, b;

    a = N / X;
    b = N % X;
    if (b != 0)
    {
        cout << T * (a + 1) << endl;
    }
    else
    {
        cout << T * a << endl;
    }
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int n;
    cin >> n;
    vector<ll> p(n);
    ll sum = 0;
    rep(i, n)cin >> p[i], sum+=p[i];
    sort(ALL(p), greater<ll>());
    cout << sum - p[0]/2 << endl;
}

Measured memory_bytes: 256
package main

import (
	. "fmt"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		neg := false
		for ; '0' > b ; b = rc() {
			if b == '-' {
				neg = true
			}
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		if neg {
			return -x
		}
		return
	}
	n,d,s :=r(),r(),0
	d*=d
	for ; n > 0; n-- {
		if x,y:=r(),r(); x*x+y*y <= d {
			s++
		}
	}
	Print(s)
}


Measured memory_bytes: 1832
{-# LANGUAGE BangPatterns #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
-- import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace

solve :: Int -> Int -> [(Int,Int)] -> Int
solve d g pcs = minimum (catMaybes (map f power_ipc))
  where
    power_ipc = power (zip [1..d] pcs)
    f (pos, neg) | cs >= g = Just cn
                 | otherwise = remainCount cn (g - cs) neg
      where
        (cn, cs) = complMark pos

power :: (Ord a) => [a] -> [([a], [a])]
power [] = [([], [])]
power (x:ys) = map (f1 x) zs ++ map (f2 x) zs
  where zs = power ys
        f1 x (ps, qs) = (x:ps, qs)
        f2 x (ps, qs) = (ps, g x qs)
        g x [] = [x]
        g x (z:zs) | x >= z = x:z:zs
                   | otherwise = z : g x zs

complMark [] = (0, 0)
complMark ((i,(p,c)):ipcs) = (num + p, score + 100*i*p + c)
  where (num, score) = complMark ipcs

remainCount !acc !goal [] = Nothing
remainCount !acc !goal ((i,(p,_)):ipcs)
  | 100*i*(p-1) >= goal = Just $ acc + ((goal + 100*i-1) `div` (100*i))
  | otherwise = remainCount (acc+(p-1)) (goal-i*(p-1)) ipcs

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_d,bs_g]:remLines1 = remLines0
      d = readBInt bs_d
      g = readBInt bs_g
      pcs = map (\[x1,x2] -> (readBInt x1,readBInt x2)) remLines1
  in solve d g pcs

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 1148
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    int64 k,a;
    int64 ans = (1LL<<31)-1;
    REP(i,N){
        cin >> k;
        int64 tmp = 0;
        REP(j,k){
            cin >> a;
            tmp += 1LL<<a;
        }
        ans&=tmp;
    }

    int cnt = 0;
    REP(i,M+1){
        if(ans>>i&1) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
S = input()

editS = S[2:-1:]

if S[0] == 'A' and S[1].islower and editS.count('C') == 1\
    and S[-1].islower():
    S = S.replace('A', '')
    S = S.replace('C', '')
    if S.islower():
        print('AC')
    else:
        print('WA')
else:
    print('WA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;

int main(void){
    int a;
    cin>>a;
    cout<<a*a*a+a*a+a<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

int main(){
	int N;
	cin>>N;
	int a[N];
	int total = 0;
	for(int i = 0; i < N; i++){
		cin>>a[i];
		total += a[i];
	}
	int target = ceil((double)total / N);
	//cout<<target<<endl;
	ll ans = 0;
	ll x = 10e6;
	for(int j = -100; j <= 100; j++){
		ans = 0;
		for(int i = 0; i < N; i++){
			ans += (a[i] - j) * (a[i] - j);
		}
		x = min(ans, x);
	}
	cout<<x<<endl;
	return 0;
}


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

void solve()
{
    string s;
    cin >> s;
    int n = s.size();
    vector<int> a(n + 1);
    rep(i, n)
    {
        if (s[i] == '<')
        {
            a[i + 1] = max(a[i + 1], a[i] + 1);
        }
    }
    for (int i = n; i >= 1; i--)
    {
        if (s[i - 1] == '>')
        {
            a[i - 1] = max(a[i - 1], a[i] + 1);
        }
    }
    ll ans = 0;
    rep(i, n + 1) ans += a[i];
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 5856
N, M = map(int, input().split())
s = set()
for _ in range(M):
    a, b = map(int, input().split())
    s.add((a, b))
result = "IMPOSSIBLE"
for m in range(2, N):
    if (1, m) in s and (m, N) in s:
        result = "POSSIBLE"
        break
print(result)

Measured memory_bytes: 37516
S = int(input())

p = 10 ** 9 + 7

memo = [-1 for _ in range(2001)]
memo[0] = 0
memo[1] = 0
memo[2] = 0
memo[3] = 1

for s in range(4, S+1):
    x = 1
    for v in range(3, s):
        x += memo[s - v] % p
    memo[s] = x % p
print(memo[S])


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define int long long
//ask the right questions.		

//let denote the max value when you have capacity_left of w and deciding upon nth item.
int dp[101][100001];

int32_t main() 
{
	int N, W;
	cin >> N >>W;
	int weights[N];
	int value[N];

	int x;
	for(int i=0;i<2*N;i++)
	{
		cin >> x;
		if(i%2==0)
		{
			weights[i/2]=x;
		}
		else
		{
			value[(i-1)/2]=x;
		}
	}

	//trivial case : choosing over no elements
	for(int i=0; i<=W; i++)
	{
		dp[0][i]=0;
	}

	//base case: choosing when wight capacity is 0
	for(int i=0; i<=N; i++)
	{
		dp[i][0]=0;
	}


	//TIP:
	//you are deciding on the ith item: to take or not
	//if you want to take then you look previously for a state which has not seen ith item and with weight gap of at least 
	//weight[i-1] (ie weight of ith item)
	//you need not look for a greater gap as the max value obtained by a state with greater
	//weight capacity will always be equal or greater than max value obtained by a lower weight capacity state.


	// shift i-1 in weights and values
	for(int i=1; i<=N; i++)
	{
		for(int j=1; j<=W; j++)
		{			
			if(j>=weights[i-1])     										//want to take
			{
				dp[i][j] = max(dp[i-1][j], dp[i-1][ j-weights[i-1] ] + value[i-1]);	       		
			}
			else
				dp[i][j] = dp[i-1][j];								//dont want to:		
		}		
	}

	cout << dp[N][W] <<endl;

	return 0;
	
}

Measured memory_bytes: 82420
A,B,C = map(int,input().split())
K = int(input())

check = False
while K > 0:
  if A >= B:
    B = B*2
  else:
    if B >= C:
      C = C*2
  
  if A < B and B < C:
    check = True
    break
  K -= 1
  
if check:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9176
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

 
function main()
  N,M = readint()
  l = 1
  r = N
  for _ in 1:M
    L,R = readint()
    l < L && (l = L)
    r > R && (r = R)
  end
  println(max(0,r-l+1))
    


 

end



main()

Measured memory_bytes: 209976
// 0239
#include <iostream>
#include <vector>
using namespace std;

int main(){
	while(1){
		int n, k, p, q, r;
		vector<vector<int> > sweet;

		cin>>n;
		if(n == 0)
			break;

		sweet.resize(n);
		for(int i=0;i<n;i++){
			cin>>k>>p>>q>>r;

			sweet[i].push_back(k);
			sweet[i].push_back(p);
			sweet[i].push_back(q);
			sweet[i].push_back(r);
			sweet[i].push_back(4*p+9*q+4*r);
		}

		int P, Q, R, C;
		vector<int> edible;

		cin>>P>>Q>>R>>C;
		for(int i=0;i<n;i++)
			if(sweet[i][1] <= P && sweet[i][2] <= Q && sweet[i][3] <= R && sweet[i][4] <= C)
				edible.push_back(sweet[i][0]);

		if(edible.size() != 0)
			for(int i=0;i<edible.size();i++)
				cout<<edible[i]<<endl;
		else
			cout<<"NA"<<endl;
		
	}
	return 0;
}

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

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

vector<pii> con[302];
int dp[301][301][301];

int main() {
    int N,M; cin >> N >> M;
    F0R(i,M) {
        int l,r,x; cin >> l >> r >> x;
        con[r].pb({l,x});
    }
    
    dp[1][0][0] = 3;
    int ans = 0;
    FOR(i,1,N+1) {
        F0R(j,i) FOR(k,j,i) if (dp[i][j][k]) {
            bool y = 1;
            for (auto b: con[i]) {
                int z = 1;
                if (j >= b.f) z ++;
                if (k >= b.f) z ++;
                if (z != b.s) {
                    y = 0;
                    break;
                }
            }
            if (y) {
                if (i == N) ans = (ans+dp[i][j][k]) % MOD;
                else {
                    dp[i+1][j][k] = (dp[i+1][j][k]+dp[i][j][k]) % MOD;
                    dp[i+1][j][i] = (dp[i+1][j][i]+dp[i][j][k]) % MOD;
                    dp[i+1][k][i] = (dp[i+1][k][i]+dp[i][j][k]) % MOD;
                }
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 104832
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Name:- OMHARI 
  Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY)
  Email:- omharicu@gmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
using namespace std; 

#define F               first
#define S               second
#define ull             unsigned long long
#define ll              long long
#define ul              unsigned long
#define db              double
#define ST              string
#define pb              push_back
#define mp              make_pair
#define el              "\n"
#define vll             vector <ll>
#define vl              vector <long int>
#define vi              vector <int>
#define all(v)          (v.begin(), v.end()) 
#define rall(v)         (v.rbegin(), v.rend()) 
#define is_sort(v)      is_sorted all(v)
#define max_of(v)       *max_element all(v)
#define min_of(v)       *min_element all(v)
#define itos(s)         to_string(s)
#define cntone(x)       __builtin_popcountll(x)
#define cntzro(x)       __builtin_clz(x)
#define For(i, a, b)    for(int i=a; i<b; i++)
#define Forr(i, a, b)    for(int i=a; i>=b; i--)
const ll mod = 1e9+7;

void solve()
{
    ST s,t;
    cin>>s>>t;
    int n=s.size(), m=t.size();

    if(s.find(t)!=-1)
    {
        cout<<0;
        return;
    }
    int ans=INT_MAX,cnt=0;
    For(i, 0, n-m+1)
    {
        cnt=0;
        For(j, 0, m)
        {
            if(s[j+i]!=t[j])
            cnt++;
            //cout<<s[j]<<" "<<t[j]<<el;
        }
        //cout<<el;
        ans=min(ans, cnt);
    }
    cout<<ans<<el;
}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    /***************-Code starts from here-***************/
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0; 
} 

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int n,a[101101],ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(&a[1],&a[n+1]);
    for(int i=1;i<=n;i++)
    {
        if(a[i]==a[i-1])
            ans++;
    }
    if(ans%2)
        ans++;
    cout<<n-ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
#define F first
#define S second
const int INF=100000000;

struct Node{
	vector<int> to,from;
};

bool e[5000][5000];

int main(){
	int n,m;
	cin >> n >> m;
	memset(e,0,sizeof(e));
	//vector<vector<int> > e(n,vector<int>(n));
	vector<Node> node(n);
	for(int i=0; i<m; ++i){
		int a,b;
		cin >> a >> b;
		e[--a][--b]=1;
		node[a].to.push_back(b);
		node[b].from.push_back(a);
	}
	queue<int> S;
	vector<int> L;
	for(int i=0; i<n; ++i){
		//cout << node[i].from.size() << endl;
		if(node[i].from.size()==0) S.push(i);
	}
	/*
	for(int i=0; i<S.size(); ++i){
		cout << S[i] << endl;
	}
	*/
	bool other=false;
	while(!S.empty()){
		if(S.size()>1) other=true;
		L.push_back(S.front());
		int ls=S.front();
		S.pop();
		for(int i=0; i<node[ls].to.size(); ++i){
			int nn=node[ls].to[i];
			e[ls][nn]=0;
			bool flag=true; 
			for(int j=0; j<node[nn].from.size(); ++j){
				if(e[node[nn].from[j]][nn]==1){
					flag=false;
					break;
				}
			}
			if(flag) S.push(nn);
			//if(node[node[ls].to[i]].from.size()==0) S.push_back(node[ls].to[i]);
		}
	}
	for(int i=0; i<L.size(); ++i){
		cout << L[i]+1 << endl;
	}
	if(other) cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 27196
from math import acos, cos, sin

pi = acos(-1)
a, b, h, m = map(float, input().split())

theta_h = pi * 2 * (h + m / 60) / 12
theta_m = pi * 2 * m / 60

h_x = cos(theta_h) * a
h_y = sin(theta_h) * a

m_x = cos(theta_m) * b
m_y = sin(theta_m) * b

print(((h_x - m_x) ** 2 + (h_y - m_y) ** 2) ** 0.5)


Measured memory_bytes: 9488