akhauriyash/Code-Regression huggingface dataset:
program main
  implicit none
  integer N,X,L(100),D,i
  read(*, *) N, X
  read(*, *) (L(i), i = 1,N)
  D = 0
  do i = 1,N
    D = D+L(i)
    if (D>X) then
      write(*, *) i
      exit
    else if(i == N) then
      write(*, *) N+1
      exit
    end if
  end do
end program main


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    pair<int, int> max1, max2;
    max1 = make_pair(-1, 0), max2 = make_pair(-1, 0);
    for(int i=0; i<n; i++){
        int tmp = 0;
        cin >> tmp;
        a[i] = tmp;
        if(tmp >= max1.second){
            max2 = max1;
            max1.first = i;
            max1.second = tmp;
            continue;
        }

        if(tmp >= max2.second){
            max2.first = i;
            max2.second = tmp;
            continue;
        }
    }


    for(int i=0; i<n; i++){
        if(i==max1.first){
            cout << max2.second << endl;
            continue;
        }

        cout << max1.second << endl;
    }


    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	int D,T,S;
	cin>>D>>T>>S;
	
	if(S*T>=D)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int X,A,B;
  cin>>X>>A>>B;
  cout<<(X-A)%B;
return 0;}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define inlld2(x, y) scanf("%lld%lld", &x, &y)
#define inlld3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define ind2(x, y) scanf("%d%d", &x, &y)
#define ind3(x, y, z) scanf("%d%d%d", &x, &y, &z)

const int N=1e5+5;
const int MOD=1e9+7;

typedef long long ll;
typedef long double ld;

using namespace std;

ll n;
map<string, int>mep;

int main()
{
    cin>>n;
    for(ll a=1; a<=n; a++)
    {
        string x;
        cin>>x;
        mep[x]++;
    }
    int maxi=0;
    for(auto it:mep)
        maxi=max(maxi, it.second);
    vector<string>ans;
    for(auto it:mep)
        if(it.second==maxi)
            ans.pb(it.first);
    sort(ans.begin(), ans.end());
    for(auto x:ans)
        cout<<x<<"\n";
    return 0;
}

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

using namespace std;

int main(void) {
    string s, t;
    cin >> s >> t;
    int count = 0;
    int slen = (int)(s.length());
    int tlen = (int)(t.length());
    for(int i = 0; i < slen - tlen + 1; i++){
        int tmpcount = 0;
        for(int j = 0; j < tlen; j++){
            if(s.at(i + j) == t.at(j)){
                tmpcount += 1;
            }
        }
        if(tmpcount > count){
            count = tmpcount;
        }
    }
    cout << tlen - count << endl;
    return 0;
}

Measured memory_bytes: 3628
/** author: __nishad__ **/
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    ll a, b, c, k, res=0;
    cin>>a>>b>>c>>k;

    if(k <= a){
            res = k;
    }
    else if(k <= a+b){
        if(k < a+b)
            res = a;
        else if(k == a+b)
            res = a;
    }
    else if(k <= a+c+b){
        if(k < a+b+c)
            res = a-(k-a-b);
        else if(k == a+b+c)
            res = a-c;
    }

    cout<<res;
}






























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

int main() {
  int N; cin >> N;
  int l[1001],r[1001];
  for ( int i = 0; i < N; i++ ) cin >> l[i] >> r[i];
  int sum = 0;
  for ( int i = 0; i < N; i++ ) {
    sum += r[i]-l[i]+1;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np
import itertools

n,m,x = map(int,input().split())
BookList = [list(map(int, input().split())) for i in range(n)]
SkillList = np.zeros(m) 
mincost = 10000000
cost = 0
NumList = list(range(n))

def python_list_add(in1, in2):
    wrk = np.array(in1) + np.array(in2)
    return wrk.tolist()


for k in range(1,ｎ+1):
    for comb in itertools.combinations(NumList, k):
        #print(comb)
        for para in comb:
            SkillList = python_list_add(SkillList,BookList[para][1:])
            cost += BookList[para][0]
        #print(SkillList)

        if min(SkillList) >= x:
            if mincost > cost:
                mincost = cost
        cost = 0
        SkillList = np.zeros(m)
 #   print('mincost,k',mincost,k)

if mincost != 10000000:
    print(mincost)
else:
    print(-1)


Measured memory_bytes: 27412
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000000+7
using namespace std;
typedef long long ll;

int main(){
  string s; cin >> s;
  int num1 = count(all(s), '1');
  int num0 = count(all(s), '0');
  cout << min(num1, num0)*2 << endl;
  return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;

//bool comp(
//
//	st pll &a, const pll &b) {
//	return a.first < b.first;
//}
//std::vector<int> enum_div(int n)//nの約数を列挙
//{
//	std::vector<int> ret;
//	for (int i = 1; i*i <= n; ++i)
//	{
//		if (n%i == 0)
//		{
//			ret.push_back(i);
//			if (i != 1 && i*i != n)
//			{
//				ret.push_back(n / i);
//			}
//		}
//	}
//	return ret;
//}


template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}
int main()
{
	priority_queue<int> q;
	string s = {};
	ll h = 0, w = 0, k = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, ans = 0;
	ll x[300005] = {};
	ll y[620] = {};
	ll y2[302][302] = {};
	cin >> a;
	for (ll i = 1; i <= a; i++)
	{
		cin >> x[i];
	}
	for (ll i = 1; i <= a; i++)
	{
		b = x[i];
		c = 0;
		while (b > 0)
		{
			if (b % 2 == 1)
			{
				y[c]++;
			}
			b = b/2;
			c++;
		}
	}
	//for (int i = 0; i < 60; i++)
	//{
	//	cout << y[i] << endl;

	//}
	//cout << endl;

	for (ll i = 0; i <= 100; i++)
	{
		c = 1;
		for (int j = 0; j < i; j++)
		{
			c *= 2 % 1000000007;
		}
		//c = (ll(pow(2, i)) % 1000000007);
		c %= 1000000007;
		ans += y[i] * (a - y[i]) % 1000000007 *c% 1000000007;
		//cout << ans << endl;
		//cout << (ll(pow(2, i)) % 1000000007) << endl;
		//cout << endl;
		ans = ans %1000000007;
	}
	//cout << 10000000000 % 1000000007 * 10000001% 1000000007 << endl;
	cout << ans << endl;

	//for (int i = 1; i < a; i++)
	//{
	//	for (int j = i+1; j <= a; j++)
	//	{
	//		ans += x[i] ^ x[j];
	//		ans %= 1000000007;
	//	}
	//}



	//cout<<factorial<10><<endl;

	//cin >> a >> b;
	//for (int i = 0; i < a; i++)
	//{
	//	cin >> s[i];
	//	if (s[i] >= b)
	//	{
	//		ans++;
	//	}
	//}

	//cout << ans << endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}


Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>

char a[1001],b[29]={'X','Y','Z','A','B','C','D','E','F','G'
					,'H','I','J','K','L','M','N'
					,'O','P','Q','R','S','T','U'
					,'V','W','X','Y','Z'};

int main(){
	int i,j,c,d;
	scanf("%s",&a);
	c=strlen(a);
	for(i=0;i<c;i++){
		for(j=3;j<29;j++){
			if(a[i]==b[j]){
				d=j-3;
				a[i]=b[d];
				break;
			}
		}
	}
	printf("%s\n",a);
	return 0;
}
	

Measured memory_bytes: 524
class FindAnswer
def makeDatabase
	database = Array.new(19,0)
	10.times { |a|
		10.times { |b|
			10.times { |c|
				10.times { |d|
				e =  a+b+c+d
				break if e > 18
				database[e] += 1
				}
			}
		}
	}
	return database
end

def orORor(num)
	num > 18 ? 36 - num : num
end

end

aa = FindAnswer.new
table = aa.makeDatabase

while input = STDIN.gets
	input = input.to_i
	if input > 36
		puts 0
		else
		get = aa.orORor(input)
		puts table[get]
	end
end

Measured memory_bytes: 6080
#include <stdio.h>
int main() {
	int n, m, p, ans = 0;
	char s[110][11] = {}, t[110][11] = {};
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%s", s[i]);
	}
	scanf("%d", &m);
	for (int i = 0; i < m; i++)
	{
		scanf("%s", t[i]);
	}
	for (int i = 0; i < n; i++)
	{
		p = 0;
		for (int j = i; j < n; j++)
		{
			for (int k = 0; (s[i][k] == s[j][k]) && (k < 11); k++)
			{
				if (s[i][k] == '\0')
				{
					p++;
					break;
				}
			}
		}
		for (int j = 0; j < m; j++)
		{
			for (int k = 0; (s[i][k] == t[j][k]) && (k < 11); k++)
			{
				if (s[i][k] == '\0')
				{
					p--;
					break;
				}
			}
		}
		ans = (p > ans) ? p : ans;
    }
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;
 
public class  Main{
	static int[]disttou;
	static int[]disttov;
	static LinkedList<Integer>[]adj;
	static int u,v;
	static void bfs(int root) {
		if(root==u) {
			disttou[root]=0;
		}
		else {
			disttov[root]=0;
		}
		LinkedList<Integer>q=new LinkedList<Integer>();
		q.add(root);
		boolean[]v=new boolean[adj.length];
		v[root]=true;
		while(!q.isEmpty()) {
			int cur=q.removeFirst();
			for(int j:adj[cur]) {
				if(!v[j]) {
					v[j]=true;
					q.add(j);
					if(root==u) {
						disttou[j]=disttou[cur]+1;
					}
					else {
						disttov[j]=disttov[cur]+1;
					}
				}
			}
		}
	}
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();u=sc.nextInt()-1;v=sc.nextInt()-1;
		disttou=new int[n];
		disttov=new int[n];
		adj=new LinkedList[n];
		for(int i=0;i<n;i++)adj[i]=new LinkedList<Integer>();
		for(int i=0;i<n-1;i++) {
			int x=sc.nextInt()-1,y=sc.nextInt()-1;
			adj[x].add(y);
			adj[y].add(x);
		}
		bfs(u);
		bfs(v);
		int ans=0;
		for(int i=0;i<n;i++) {
			if(disttou[i]<disttov[i]) {
				ans=Math.max(ans, disttov[i]-1);
			}
		}
		pw.println(ans);
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 57624
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int dist_square(const vector<int>& v1, const vector<int>& v2) {
  int d = 0;
  for (int i = 0; i < v1.size(); ++i) {
    d += (v1[i] - v2[i]) * (v1[i] - v2[i]);
  }
  return d;
}

int main() {
  int N, D; cin >> N >> D;
  vector<vector<int>> v(N);
  for (int i = 0; i < N; ++i) {
    v[i].resize(D);
    cin >> v[i];
  }

  set<int> s;
  for (int i = 0; i <= 400; ++i) s.insert(i*i);

  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      if (s.count(dist_square(v[i], v[j]))) ++cnt;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(10**9)
n=int(input())
l=[[] for i in range(n)]
C=[0]*n
for i in range(n-1):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    l[a].append([b,c])
    l[b].append([a,c])
def dfs(now,par,cost):
    C[now]=cost
    L=l[now]
    for i in range(len(L)):
        if L[i][0]==par:
            continue
        dfs(L[i][0],now,cost+L[i][1])
Q,K=map(int,input().split())
K-=1
dfs(K,K,0)
for i in range(Q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(C[x]+C[y])

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

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

  int cnt = 0;
  int ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'g') {
      cnt++;
    } else {
      if (cnt < 1) {
	ans--;
      } else {
	cnt--;
      }
    }
  }
  ans += cnt / 2;

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int N,K,m;
vector<int> D(10);

void dfs(int a){
  if(a>=N){m=min(a,m); return;}
  else{
    for(int i=0;i<=9;i++){
      bool w=true;
      for(int j=0;j<K;j++){if(i==D[j])w=false;}
      if(w){dfs(a*10+i);}
    }
  }
}
 
int main() {
  cin >> N >> K;
  for(int i=0;i<K;i++)cin >> D[i];
  m=100000;
  for(int i=1;i<=9;i++){
    bool q=true;
    for(int j=0;j<K;j++){if(i==D[j])q=false;}
    if(q){dfs(i);}
  }
  cout << m << endl;
}

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

const string ans[7]={"null","one pair","two pair","three card","straight","full house","four card"};

int main(void){
	int a[5];
	while(scanf("%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4])!=EOF){
		int cnt[13]={},ans_num=0,tmp=0;
		for(int i=0;i<5;++i) ++cnt[a[i]-1];
		for(int i=0,count=0;i<13+1;++i){
			if(cnt[(i+13)%13]>1)break;
			if(cnt[(i+13)%13]==1)++count;
			if(cnt[(i+13)%13]==0)count=0;
			if(count==5) ans_num=4;
		}
		if(!ans_num){
			for(int i=0;i<13;++i){
				if(cnt[i]==4){ans_num=6;break;}
				if(cnt[i]==3)tmp+=3;
				if(cnt[i]==2)tmp+=2;
			}
			if(tmp==5)ans_num=5;
			if(tmp==4)ans_num=2;
			if(tmp==3)ans_num=3;
			if(tmp==2)ans_num=1;
		}
		cout<<ans[ans_num]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
	
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int D = input.nextInt();
      
		int X[][] = new int[N][D];
	
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = input.nextInt();
			}
		}
		int totalInt = 0;
		for(int k = 0; k < N; k++){
			
			for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			}
				
		}
		System.out.println(totalInt);
		
		
	}	
}


Measured memory_bytes: 22740
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int a,b;
	int d,r;
	
	cin>>a>>b;
	
	d=a/b;
	r=a%b;
	

	printf("%d %d %.9f",d,r,(double)a/b);
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


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 (a > b)
    {
        a = b;
        return 1;
    }
    return 0; 
}

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

    int dp[s.size()+1][3];
    memset(dp, 0, sizeof(dp));
    /* dp[i][j] で 
    1.i文字目まで見たか, 
    2.前の文字の長さが j 文字の時  を表現*/
    dp[1][0] = dp[2][1] = 1;
    rep(i, s.size()+1) {
        if (i >= 1 && s[i-1] != s[i])
        {
            chmax(dp[i+1][1], dp[i][1]+1);
        }
        if (i >= 2 && (s[i-2] != s[i] || s[i-1] != s[i+1]))
        {
            chmax(dp[i+2][2], dp[i][2]+1);
        }
        chmax(dp[i+2][2], dp[i][1] + 1); // 1 -> 2
        chmax(dp[i+1][1], dp[i][2] + 1); // 2 -> 1
        // rep(i, s.size() + 1) {
            // cout << dp[i][1] << " " << dp[i][2] << endl;
        // }
    }
    cout << max(dp[s.size()][1], dp[s.size()][2]) << endl;
    return 0;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    int x[N+1], y[M+1];

    cin >> x[N];
    cin >> y[M];

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

    sort(x, x+N+1);
    sort(y, y+M+1);

    if (x[N] < y[0]) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define Z 10005
using namespace std;
int d[Z+1];
int main(){
	int n,m,k,r,l;
	while(true){
		cin>>n>>k>>m>>r;
		if(!(n+m+k+r))break;
		rep(i,0,Z)d[i]=0;
		k=1,l=n;
		rep(i,0,Z)d[i]+=k/l,k%=l,k*=10;
		if(m)rep(i,1,n){k=1,l=i*n;rep(j,0,Z)d[j]+=k/l,k%=l,k*=10;}
		for(int i=Z;i>0;i--)d[i-1]+=d[i]/10,d[i]%=10;
		cout<<d[0]<<".";
		rep(i,1,r+1)cout<<d[i];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int n, m;
string fi[1000];

void solve() {
    // red
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            bool is = false;
            if (i == 0) is = true;
            else if (i != n-1) {
                if (j & 1) is = true;
                if (fi[i][j] == '#') is = true;
            }
            if (is) cout << '#';
            else cout << '.';
        }
        cout << endl;
    }
    cout << endl;
    
    // blue
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            bool is = false;
            if (i == n-1) is = true;
            else if (i != 0) {
                if (!(j & 1)) is = true;
                if (fi[i][j] == '#') is = true;
            }
            if (is) cout << '#';
            else cout << '.';
        }
        cout << endl;
    }
    cout << endl;
}

int main() {
    while (cin >> n >> m) {
        for (int i = 0; i < n; ++i) cin >> fi[i];
        solve();
    }
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if (C >= A && C <= B) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  
  
  return 0;  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size();
const int INF=1e9;

int main(){
  ll n,k;cin>>n>>k;
  vll x(n);
  rep(i,0,n){
    cin>>x[i];
  }
  ll ans=INF;
  rep(i,0,n-k+1){
    if(x[i+k-1]<0){
      ans=min(ans,-x[i]);
    }
    else{
      if(x[i]<0){
        ans=min(ans,min(x[i+k-1]-2*x[i],x[i+k-1]*2-x[i]));
      }
      else{ans=min(ans,x[i+k-1]);}
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int H, W;
pii v[200010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> W >> H;
  for (int i = 0; i < W; i++) {
    int p;
    cin >> p;
    v[i] = {p, 0};
  }
  for (int i = 0; i < H; i++) {
    int q;
    cin >> q;
    v[i + W] = {q, 1};
  }
  sort(v, v + H + W);
  ll ans = 0;
  int a = 0, b = 0;
  for (int i = 0; i < H + W; i++) {
    if (v[i].second == 0) {
      ans += (ll)(H + 1 - b) * v[i].first;
      a++;
    } else {
      ans += (ll)(W + 1 - a) * v[i].first;
      b++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1920
#include <cstdio>

using namespace std;

#define rep(i,x) for(int i=0;i<(int)(x);++i)

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

char mp[20][22];
int H, W;

void dfs(int y, int x)
{
    if (y < 0 || y >= H || x < 0 || x >= W || mp[y][x] == '#' || mp[y][x] == ' ') return;

    mp[y][x] = ' ';

    rep(i, 4) dfs(y + dy[i], x + dx[i]);
}

int main()
{
    while (scanf("%d %d", &W, &H), H || W) {
        int sy, sx;

        rep(i, H) rep(j, W) {
            scanf("\n%c", &mp[i][j]);
            if (mp[i][j] == '@') sy = i, sx = j, mp[i][j] = '.';
        }

        dfs(sy, sx);

        int cnt = 0;

        rep(i, H) rep(j, W) if (mp[i][j] == ' ') cnt++;

        printf("%d\n", cnt);
    }
}

Measured memory_bytes: 1028
s = input()
ans = [0] * len(s)
x = 0
y = 'R'
z = []
for i in s:
    if y == i:
        x += 1
    else:
        z.append([y,x])
        x = 1
        y = i
z.append([y,x])
ans = [0] * len(s)
i = 0
j = 0
while i < len(z):
    x = z[i][1]
    if z[i][0] == 'R':
        j += x-1
        if x % 2 == 0:
            ans[j] += x // 2
        else:
            ans[j] += x // 2 + 1
        ans[j+1] += x // 2
        j -= x-1
        j += x
    if z[i][0] == 'L':
        if x % 2 == 0:
            ans[j] += x // 2
        else:
            ans[j] += x // 2 + 1
        ans[j-1] += x // 2
        j += x
    i += 1
print(' '.join(map(str,ans)))

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

using namespace std;

int N;
int MX;
char output[500][500];

void PRINT() {
  for(int i=0; i<MX; i++) {
    cout << output[i] << endl;
  }
}

int main() {
  
  int Tc; cin >> Tc;
  bool blank = 0;
  while(Tc--) {
    if(blank) cout << endl;
    blank = 1;
    
    cin >> N;
    MX = N;
     
    for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
	output[i][j] = ' ';
      }
    }
    
    for(int i=0; i<N; i++) output[i][N] = 0;
    
    int cnt = 0;
    
    //////////////// phase 1 START
    
    int x = 0, y = N-1;
    for(int i=0; i<N; i++) {
      output[y-i][x] = '#';
    }
    y -= N-1;
    cnt ++;
    if(cnt == MX) goto EXIT;
        
    for(int i=0; i<N; i++) {
      output[y][x+i] = '#';
    }
    x += N-1;
    cnt ++;
    if(cnt == MX) goto EXIT;
    
    for(int i=0; i<N; i++) {
      output[y+i][x] = '#';
    }
    y += N-1;
    cnt ++;

    if(cnt == MX) goto EXIT;
    
    //////////////// phase 1 END
    
    
    //////////////// phase 2 START
    
    while(1) {
      
      N -= 2;
      for(int i=0; i<N; i++) {
	output[y][x-i] = '#';
      }
      
      x -= N-1;
      cnt ++;
      if(cnt == MX) goto EXIT;
      
      for(int i=0; i<N; i++) {
	output[y-i][x] = '#';
      }
      y -= N-1;
      cnt ++;
      if(cnt == MX) goto EXIT;
      
      N -= 2;
      
      for(int i=0; i<N; i++) {
	output[y][x+i] = '#';
      }
      x += N-1;
      cnt ++;
      if(cnt == MX) goto EXIT;
      
      for(int i=0; i<N; i++) {
	output[y+i][x] = '#';
      }
      y += N-1;
      cnt ++;
      if(cnt == MX) goto EXIT;
    }
    //////////////// phase 2 END
    
  EXIT:;
    PRINT();
  }
  
  return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
int main(){
	int N,x,y,b,p,i,sum,s;
	scanf("%d",&N);
	for(i=0;i!=N;i++){
		scanf("%d%d%d%d",&x,&y,&b,&p);
		sum=(x*b)+(y*p);
		if(b<5){
			b=5;
		}
		if(p<2){
			p=2;
		}
		s=(x*b+y*p)/10*8;
		if(sum<s){
			printf("%d\n",sum);
		}
		else{
			printf("%d\n",s);
		}
	}
}

Measured memory_bytes: 1028
h, w, k = list(map(int, input().split()))
c = [list(input()) for _ in range(h)]
ans = 0

from itertools import product
for row_bit in product(range(2), repeat=h):
  for col_bit in product(range(2), repeat=w):
    black_cnt = 0
    for i in range(h):
      for j in range(w):
        # bitに0が立っているときは塗らない
        if c[i][j] == '#' and (row_bit[i]==0 and col_bit[j]==0):
          black_cnt += 1
    if black_cnt == k:
      ans += 1
print(ans)

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

/*............................*/

#define uint uint64_t
#define mx 5001
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define mp make_pair
#define pb push_back
#define inf INT_MAX
#define mod 1000000007
#define pi acos(-1)
#define eps 1e-8
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / __gcd(a, b)
#define input(ara, n)          \
   for (int i = 0; i < n; i++) \
   scanf("%d", &ara[i])
#define inputl(ara, n)                   \
   for (long long int i = 0; i < n; i++) \
   scanf("%lld", &ara[i])
#define printcase(p) printf("Case %d: ", p)
#define pf(a) printf("%d\n", a);
#define pfl(a) printf("%lld\n", a);
#define pfi(a) printf("%d ", a);
#define pfll(a) printf("%lld ", a);
#define sc(a) scanf("%d", &a)
#define scc(a, b) scanf("%d %d", &a, &b)
#define sccdbl(a, b) scanf("%lf %lf", &a, &b)
#define sccc(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scccdbl(a, b, c) scanf("%lf %lf %lf", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define sccl(a, b) scanf("%lld %lld", &a, &b)
#define scccl(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#include <bits/stdc++.h>
using namespace std;
int main()
{
   // int t;
   // sc(t);
   // while (t--)
   // {

   // }
   int x;
   sc(x);
   if (x == 0)
   {
      pf(1);
   }
   else
   {
      pf(0);
   }
   return 0;
}

Measured memory_bytes: 3808
#include<iostream>
#include<set>
#include <cstdio>
#include<vector>
#include<algorithm>

using namespace std;
	int n ;
    vector<vector<int> > ed;
int f(int v){
    int res=0;
    vector<int> chi(ed[v].size());
    for(int i=0; i<ed[v].size(); i++){
	chi[i] = f(ed[v][i]);
    }
    sort(chi.rbegin(), chi.rend());
    int mx = 0;
    for(int i=0;i<chi.size(); i++){
	mx = max(chi[i]+i+1, mx);
    }
    res+=mx;
    return res;
}
int main(){
    cin>>n;
    vector<int > a(n+1);
    ed.clear(); ed.resize(n+1, vector<int>(0));
    for(int i=0; i<n-1; i++){
	scanf("%d", &a[i+2]);
	ed[a[i+2]].push_back(i+2);
    }
    

    int res=f(1);
    cout<<res<<"\n";
    
}

Measured memory_bytes: 17024
x, k, d = gets.split.map(&:to_i)
if x.abs >= k * d
  puts x.abs - k * d
else
  if x < 0
    n = x.abs / d
    p = x + n * d
    puts (k - n).even? ? p.abs : (p + d).abs
  else
    n = x / d
    p = x - n * d
    puts (k - n).even? ? p.abs : (p - d).abs
  end
end

Measured memory_bytes: 14408
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n,x;
  cin>>n>>x;
  int now=0,ans=1;
  rep(i,n){
    int l;
    cin>>l;
    now+=l;
    if(now<=x) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

struct edge{
  int to,w;
};
vector<vector<edge> > g;
vector<int> ans;

void dfs(int v,int p=-1,int c=0){
  ans[v]=c;
  rep(i,g[v].size()){
    int nv=g[v][i].to;
    int dist=g[v][i].w;
    if(nv==p) continue;
    dfs(nv,v,dist%2==0?c:1-c);
  }
}

int main(){
  int N; cin >> N;
  g.resize(N);
  ans.resize(N);
  rep(i,N-1){
    int a,b,c;
    cin >> a >> b >> c;
    a--; b--;
    g[a].push_back(edge{b,c});
    g[b].push_back(edge{a,c});
  }
  dfs(0);
  rep(i,N){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 12672
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;


int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++)
		if (S[i] == 'o')ans++;
	ans += 15 - S.size();
	if (ans >= 8)cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64

int main(){
    int now,goal;
    cin >> now >>goal;
    cout << int(goal*2 - now ) << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x) 
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define fo(i, a, b) for (int i = a; i <= b; ++i)

int main() {
    //freopen("in.txt", "r", stdin);
    int t, x; cin >> t >> x;
    cout << fixed << setprecision(5) << (double)t/x << '\n';
}



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

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

	cin >> k;
	cin >> a >> b;

	for(int i=a; i<=b; i++){
		if(i % k == 0){
			cout << "OK";
			return 0;
		}
	}

	cout << "NG";
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n;
    int i,j;
    cin >> n;
    vector<int> a;
    for(i = 0;i < n;i++){
        cin >> j;
        j--;
        a.push_back(j);
    }
    int s = 0;
    for(i = 0;i < n;i++){
        if(i == a[a[i]]){
            s++;
        }
    }
    cout << s/2 << endl;
}

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

int H, W, h, w, a[505][505];
long long ret;

int main () {
	scanf("%d%d%d%d", &H, &W, &h, &w);
	for (int i = 1; i <= H; i += h) for (int j = 1; j <= W; j += w) {
		a[i][j] = 1e9 - 1;
		ret += 1e9 - 1;
	}
	for (int i = h; i <= H; i += h) for (int j = w; j <= W; j += w) {
		a[i][j] = -1e9;
		ret -= 1e9;
	}
	if (ret <= 0) return puts("No"), 0;
	puts("Yes");
	for (int i = 1; i <= H; ++i) for (int j = 1; j <= W; ++j) printf("%d%c", a[i][j], j == W ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
using namespace std;
int W,H,n;
map<int,int> area;

struct Info{
	int x,y,w,h;
	Info(int x,int y,int w,int h) : x(x) , y(y) , w(w) , h(h) {}
	Info(){x=y=w=h=-99999;}
};

map<int,vector<Info> > info;

int c[11][11];
int ok = 0;
int current[11][11];
int answer[11][11];

int dfs(map<int,vector<Info> >::iterator it){
	if( ok >= 2 ) return 0;
	if( it == info.end()){
		int bad = 0;
		for(int i = 0 ; i < H ; i++){
			for(int j = 0 ; j < W ; j++){
				if( current[i][j] == 0 ) bad = true;
			}
		}
		if( bad ) return 0;
		ok++;
		rep(i,11)rep(j,11) answer[i][j] = current[i][j];
		return 0;
	}else{
		vector<Info> &v = it->second;
		for(int i = 0 ; i < v.size() ; i++){
			int chk = 1;
			for(int y = 0 ; y < v[i].h ; y++){
				for(int x = 0 ; x < v[i].w ; x++){
					chk &= current[v[i].y+y][v[i].x+x] == 0;
				}
			}
			if( !chk ) continue;
			for(int y = 0 ; y < v[i].h ; y++){
				for(int x = 0 ; x < v[i].w ; x++){
					current[v[i].y+y][v[i].x+x] = it->first;
				}
			}
			it++;
			dfs(it);
			it--;
			for(int y = 0 ; y < v[i].h ; y++){
				for(int x = 0 ; x < v[i].w ; x++){
					current[v[i].y+y][v[i].x+x] = 0;
				}
			}
		}
		return 0;
	}
}
int main(){
	while(cin >> W >> H >> n && W){
		info.clear();
		for(int i = 0 ; i < 11 ; i++)
			for(int j = 0 ; j < 11 ; j++)
				answer[i][j] = current[i][j] = 0;
		for(int i = 0 ; i < n ; i++){	
			int a,b;
			cin >> a >> b;
			area[a] = b;
		}
		rep(i,H)rep(j,W) cin >> c[i][j];
		for(int sx = 1 ; sx <= W ; sx++){
			for(int sy = 1 ; sy <= H ; sy++){
				int cnt = 0 , number = 0;
				for(int i = 0 ; i <= H - sy ; i++){
					for(int j = 0 ; j <= W - sx ; j++){
						int cnt = 0 , number;
						for(int k = 0 ; k < sy ; k++){
							for(int l = 0 ; l < sx ; l++){
								int C = c[i+k][j+l];
								if( C != 0 ){
									cnt++;
									number = C;
								}
							}
						}
						if( cnt == 1 && area[number] == sx * sy ){
							info[number].push_back(Info(j,i,sx,sy));
						}
					}
				}
			}
		}
		ok = 0;
		dfs(info.begin());
		if( ok != 1 ){
			cout << "NA" << endl;
		}else{
			rep(i,H){
				rep(j,W) cout << (j?" ":"") << answer[i][j];
				cout << endl;
			}
		}
	}
}

Measured memory_bytes: 916
#include "bits/stdc++.h"
#define   LF      '\n'
#define   ALL(x)  x.begin(), x.end()
#define   LEN(x)  (int)x.size()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}

#define int long long
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

int N;
int x[105], y[105], h[105];


int comp(int X, int Y, int k)
{
  for (int i = 0; i < N; ++i) {
    const int tmp = max(0LL, k - abs(X - x[i]) - abs(Y - y[i]));
    if (tmp - h[i]) return (tmp - h[i]);
  }
  return 0;
}

signed main()
{
  cin >> N;

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

  for (int y = 0; y <= 100; ++y) {
    for (int x = 0; x <= 100; ++x) {

      int low = 0;
      int hi = 1'000'100'001;

      while(hi - low > 1) {
        const int mid = (low + hi) / 2;
        const int p = comp(x, y, mid);

        if (p == 0) {
          cout << x << ' ' << y << ' ' << mid << endl;
          return 0;
        }
        else if (p < 0) {
          low = mid;
        }
        else {
          hi = mid;
        }
      }
    }
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  if(n * m == 1) {
    cout << 1 << endl;
    return 0;
  } else if(n == 1 || m == 1) {
    cout << n * m - 2 << endl;
    return 0;
  } else {
    cout << (n - 2) * (m - 2) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args) { 
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int n1[]=new int[n];
		int m1[]=new int[m];
		int vote[]=new int[n];
		for(int i = 0;i<n;i++)
			n1[i]=sc.nextInt();	
		for(int i=0;i<m;i++)
			m1[i]=sc.nextInt();
		for(int i=0;i<m;i++){
			for(int j=0;j<n;j++){
				if(m1[i]>=n1[j]){					
					vote[j]++;break;	
				}
			}
		}
		int no1=0,ans=0;
		for(int i=0;i<n;i++){
			if(vote[i]>no1){
				no1=vote[i];
				ans=i+1;
			}
		}
		System.out.println(ans);
	}
}

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

int main(){
  int N,K,a,answer;
  answer=0;
  cin>>N>>K;
  vector<int> ball(N,0);
  for (int i=0;i<N;i++){
    cin>>a;
    ball.at(a-1)++;
  }
  sort(ball.begin(),ball.end(),greater<int>());
  for (int i=0;i<N;i++){
    if (i+1>K){
      answer+=ball.at(i);
    }
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    string S;
    cin>>S;
    int N=S.size();
    for(int i=1; i<=N; i++) {
        string w=S.substr(0,N-i);
        if(w.size()%2==1) continue;
        else {
            int n=w.size();
            bool ok=true;
            for(int j=0; j<(n/2); j++)  {
                if(w[j]!=w[j+(n/2)]) ok=false;
            }
            if(ok) {
                cout<<n<<endl;
                return 0;
            }
            else {
                continue;
            }
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main() {
    string s, ans = "NO", str;
    cin >> s;
    rep(i, s.size()) {
        rep(j, s.size() - i) {
            str = s; str.erase(i, j);
            if (str == "keyence") ans = "YES";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
    z->parent=y;
    if(y==NIL){
      root=z;
    }
    else if(z->key<y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
  

void inorder(Node u){
  if (u->left != NIL){
    inorder(u->left);
  }
  printf(" %d", u->key);
  if (u->right != NIL){
    inorder(u->right);
  }
}
void preorder(Node u){
  printf(" %d",u->key);
  if (u->left != NIL){
    preorder(u->left);
  }
  if (u->right != NIL){
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int w, h;

char c[20][20];
bool visit[20][20];

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

void dfs(int y, int x) {
  visit[y][x] = true;
  REP(i, 4) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (0 <= ny && ny < h && 0 <= nx && nx < w && c[ny][nx] == '.' &&
        !visit[ny][nx])
      dfs(ny, nx);
  }
}

int main() {
  while (cin >> w >> h) {
    if (w == 0 && h == 0) break;
    REP(i, h) REP(j, w) cin >> c[i][j];
    REP(i, h) REP(j, w) visit[i][j] = false;
    REP(i, h) REP(j, w) {
      if (c[i][j] == '@') dfs(i, j);
    }
    int ans = 0;
    REP(i, h) REP(j, w) {
      if (visit[i][j]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 1e9 + 7;
const ll maxn = 200005;
char s[500],s1[500],s2[500];
int check1(){//判断是否回文 
	int m=strlen(s);
	for(int i=0;i<m/2;i++)
		if(s[i]!=s[m-i-1]) return 0;
	return 1;
}
int check2(){//判断是否回文 
	int m=strlen(s1);
	for(int i=0;i<m/2;i++)
		if(s1[i]!=s1[m-i-1]) return 0;
	return 1;
}
int check3(){//判断是否回文 
	int m=strlen(s2);
	for(int i=0;i<m/2;i++)
		if(s2[i]!=s2[m-i-1]) return 0;
	return 1;
}
int main(){  
	cin.tie(0);
    ios::sync_with_stdio(false);
	int n,m,k,flag=0;
	scanf("%s",s);
	if(check1()){
		for(int i=0;i<(strlen(s)-1)/2;i++){
			s1[i]=s[i];
		}
		s1[(strlen(s)-1)/2]='\0';
		if(check2()){
			for(int i=(strlen(s)+3)/2-1;i<strlen(s);i++){
				s2[i]=s[i];
			}
			s2[(strlen(s)+3)/2]='\0';
			if(check3()) flag=1;
		}
	}
	
	
	if(flag) printf("Yes");
	else printf("No");
    return 0;
}




Measured memory_bytes: 256
from collections import deque
n = int(input())
D = []
for _ in range(n):
  D.append(int(input()))
D.sort()
A = deque(D)
B = deque()
B.append(A.popleft())

maxflag = 0
while True:
  if len(A) == 0:
    break
  if len(A) == 1:
    a = A.pop()
    B.appendleft(a)
    break
  if maxflag % 2 == 0:
    a = A.pop()
    b = A.pop()
  else:
    a = A.popleft()
    b = A.popleft()
  B.appendleft(a)
  B.append(b)
  maxflag += 1
ans = 0
for i in range(len(B)-1):
  ans += abs(B[i] - B [i+1])

A = deque(D)
B = deque()
B.append(A.pop())

maxflag = 1
while True:
  if len(A) == 0:
    break
  if len(A) == 1:
    a = A.pop()
    B.appendleft(a)
    break
  if maxflag % 2 == 0:
    a = A.pop()
    b = A.pop()
  else:
    a = A.popleft()
    b = A.popleft()
  B.appendleft(a)
  B.append(b)
  maxflag += 1
ans2 = 0
for i in range(len(B)-1):
  ans2 += abs(B[i] - B [i+1])
print(max(ans, ans2)) 



Measured memory_bytes: 87696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e2+10;
int a[maxn];
int b[maxn];
int main(){
	int n,m,x,y,z;
	cin>>n>>m>>x>>y;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	sort(a,a+n);
	sort(b,b+m);
	if(b[0]<a[n-1]||a[n-1]>y||b[0]<=x){
		cout<<"War"<<endl;
		return 0;
	}
	if(b[0]>a[n-1]&&b[0]<=y){
		cout<<"No War"<<endl;
		//cout<<"zsds";
		return 0;
	}
	cout<<"War"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define fi first
#define se second
const int inf = 1e9;
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = 1;i <= n;i++)

int a[4][104], dp[4][104];
int main(){
	int n;
	scanf("%d", &n);
	rrep(i,2)rrep(j,n)scanf("%d", &a[i][j]);
	for(int i = 1;i <= 2;i++){
		for(int j = 1;j <= n;j++){
			dp[i][j] = max(dp[i-1][j], dp[i][j-1])+a[i][j];
		}
	}
	printf("%d\n", dp[2][n]);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    ll N,M;
    cin >> N >> M;
    priority_queue<pair<ll,ll>> A;
    vector<ll> score(N);
    for(ll i=0; i<N; i++){
        ll t;
        cin >> t;
        score.at(i)=t;
        A.push(make_pair(t,i));
    }
    vector<ll> Y(N);
    for(ll i=0; i<M; i++){
        Y.at(A.top().second)++;
        pair<ll,ll> T(A.top().first,A.top().second);
        A.pop();
        ll a=T.first/2;
        ll b=T.second;
        A.push(make_pair(a,b));
    }
    for(ll i=0; i<N; i++){
        score.at(i)=score.at(i)/(pow(2,Y.at(i)));
    }
    ll ans=0;
    for(ll i=0; i<N; i++){
        ans+=score.at(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3440
#!/usr/bin/env python3
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ds = [b[i] - a[i] for i in range(N)]
p = sum(x // 2 for x in ds if x > 0)
m = sum(-x for x in ds if x < 0)
print(('No', 'Yes')[m <= p])


Measured memory_bytes: 4600