akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template <typename _tp> inline void read(_tp&x){
	char ch=getchar(),ob=0;x=0;
	while(ch!='-'&&!isdigit(ch))ch=getchar();if(ch=='-')ob=1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();if(ob)x=-x;
}

const int N = 601000;
int sg[N], tag[N];

vector <int> vec[N];
vector <int> :: iterator itr;

void build(int l, int r, int x) {
	sg[x] = -l;
	if(l == r) return ;
	int mid = l + r >> 1;
	build(l, mid, x<<1);
	build(mid+1, r, x<<1|1);
}

inline void down(int x) {
	int&v = tag[x];
	sg[x<<1] += v, tag[x<<1|1] += v,
	sg[x<<1|1] += v, tag[x<<1] += v,
	v = 0;
}

void upd(int l, int r, int x, int L) {
	if(L <= l) return ++sg[x], ++tag[x], void();
	int mid = l + r >> 1; if(tag[x]) down(x);
	if(L <= mid) upd(l, mid, x<<1, L);
	upd(mid+1, r, x<<1|1, L);
	sg[x] = max(sg[x<<1], sg[x<<1|1]);
}

int qry(int l, int r, int x, int R) {
	if(r <= R) return sg[x];
	if(tag[x]) down(x);
	int mid = l + r >> 1, res = qry(l, mid, x<<1, R);
	if(mid < R) res = max(res, qry(mid+1, r, x<<1|1, R));
	return res;
}

int n, m;

int main() {
	read(n), read(m);
	for(int i=1,l,r;i<=n;++i) {
		read(l), read(r);
		vec[r].push_back(l);
	}
	
	build(0, m, 1);
	
	int Ans = m;
	for(int r=m+1;r>1;--r) {
		for(itr = vec[r].begin(); itr != vec[r].end(); ++ itr)
			upd(0, m, 1, *itr);
		Ans = max(Ans, qry(0,m,1,r-1) + r - 1);
	}
	Ans = max(Ans, n);
	printf("%d\n", Ans-m);
	return 0;
}

Measured memory_bytes: 22272
#include <cstdio>
using namespace std;

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

  int a = (n/1000)%10;
  int b = (n/100)%10;
  int c = (n/10)%10;
  int d = (n/1)%10;

       if (a+b+c+d == 7) { printf("%d+%d+%d+%d=7\n",a,b,c,d); }
  else if (a+b+c-d == 7) { printf("%d+%d+%d-%d=7\n",a,b,c,d); }
  else if (a+b-c+d == 7) { printf("%d+%d-%d+%d=7\n",a,b,c,d); }
  else if (a+b-c-d == 7) { printf("%d+%d-%d-%d=7\n",a,b,c,d); }
  else if (a-b+c+d == 7) { printf("%d-%d+%d+%d=7\n",a,b,c,d); }
  else if (a-b+c-d == 7) { printf("%d-%d+%d-%d=7\n",a,b,c,d); }
  else if (a-b-c+d == 7) { printf("%d-%d-%d+%d=7\n",a,b,c,d); }
  else if (a-b+c-d == 7) { printf("%d-%d-%d-%d=7\n",a,b,c,d); }
}

Measured memory_bytes: 128
using System;

namespace ABC124A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            int sum = 0;
            for(int i = 0; i < 2; i++) {
                if (A > B)
                {
                    sum = A + sum;
                    A--;
                }
                else
                {
                    sum = B + sum;
                    B--;
                }
            }
            Console.WriteLine(sum);
            
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
		int n;
		cin>>n;
		if(n%10==7){
			cout<<"Yes"<<endl;
		}else {
			n/=10;
			if(n%10==7){
				cout<<"Yes"<<endl;
			}else {
				n/=10;
				if(n==7){
					cout<<"Yes"<<endl;
				}else {
					cout<<"No"<<endl;
				}
			}
			
		}
	return 0;
	
}


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

int n,k;

vector<int> vec;
vector<int> dp;

bool solve(int stones)
{
	if(dp[stones]!=-1)
		return dp[stones];
	bool ans=false;
	if(stones==0)
		return true;
	for(int i=0; i<n; i++)
	{
		if((stones-vec[i]>0&&!solve(stones-vec[i]))||(stones-vec[i]==0))
		{
			ans=true;
			break;
		}
	}
	return dp[stones]=ans;
}	

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	vec.resize(n);
	dp.assign(k+1,-1);
	for(int i=0; i<n; i++)
	{
		cin>>vec[i];
	}
	if(solve(k))
		cout<<"First";
	else
		cout<<"Second";
	return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
 
int main()
{
	int N;
	cin >> N;
	int result = 0;
	vector<int> A(N + 1, 0);
	vector<int> C(N, 0);

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

	int prev = A[1];
	for (int i = 2; i <= N; i++) {
		if (A[i] == prev + 1) {
			result += C[prev];
		}
		prev = A[i];
	}

	cout << result;
  
	return 0;
}



Measured memory_bytes: 256
#include <set>
#include<algorithm>
#include<iostream>
#include<functional>
#define ll long long
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5;

pii val[maxn + 11];
int pos[maxn + 11];

int main() {
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> val[i].first;
		val[i].second = i;
	}sort(val + 1, val + 1 + n);
	for (int i = 1;i <= n;i++)
		pos[i] = val[i].second;
	set <int> s;
	set <int> ::iterator itl, itr;
	s.insert(0); s.insert(n + 1);s.insert(n + 2);s.insert(-1);
	ll ans = 0;
	for (int i = n; i >=1; i--) {
		itl = s.lower_bound(pos[i]); itr = itl--;
		int l = *itl;
		int r = *itr;
		if (l == 0) {
			itr++;
			int R = *itr;
			if (r != n + 1) {
				ans += 1ll * pos[i] * (R - r) * i;
			}
		}
		else if (r == n + 1) {
			itl--;
			int L = *itl;
			ans += 1ll * (l - L) * (n - pos[i] + 1) * i;
		}
		else {
			itl--; itr++;
			int L = *itl; int R = *itr;
			ans += (1ll * (l - L) * (r - pos[i]) + 1ll * (R - r) * (pos[i] - l)) * i;
		}
		s.insert(pos[i]);
	}
	cout << ans << endl;
}

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

int main(int argc, char *argv[]){
    char *p, s[1004]={0};
	int n;
	for(scanf("%d ", &n);n--;){
		fgets(s, 1002, stdin);
		for(p=s;p=strstr(p, "Hoshino");*(p+=6)='a');
		printf("%s", s);
    }
    return 0;
}

Measured memory_bytes: 0
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		Random r = new Random();
		int N = sc.nextInt();
		long L = sc.nextLong();
		long T = sc.nextLong();
//		int N = r.nextInt(10);
//		long L = r.nextInt(100);
//		long T = r.nextInt(1000);
		int[] x = new int[N];
		boolean[] w = new boolean[N];
		ArrayList<Integer> cw = new ArrayList<>();
		ArrayList<Integer> ccw = new ArrayList<>();
		for(int i=0; i<N; i++) {
			x[i] = sc.nextInt();
			w[i] = sc.nextInt()==1;
//			x[i] = (i==0 ? 0 : x[i-1]) + r.nextInt(9) + 1;
//			w[i] = r.nextInt(2)==1;
			if(w[i])
				cw.add(x[i]);
			else
				ccw.add(x[i]);
		}
		Collections.reverse(cw);
		
		if(cw.size()==0 || ccw.size()==0) {
			for(int i=0; i<N; i++) {
				pw.println((x[i]+(w[i]? T%L : L-(T%L)))%L);
			}
		} else {
//			long t=0;
//			boolean dirCW = true;
//			int cwIdx=0;
//			int ccwIdx=(-1-Collections.binarySearch(ccw, cw.get(0)))%ccw.size();
//			int lane1 = -1, lane2 = -1;
//			boolean dir1=false;
//			boolean init = true;
//			while(t<2*L) {
//				if(init) {
//					t += (ccw.get(ccwIdx)-cw.get(cwIdx)+L) % L;
//					cwIdx++;
//					ccwIdx++;
//					init = false;
//				} else if(dirCW) {
//					int next = ccw.get(ccwIdx%ccw.size()) - ccw.get((ccwIdx-1)%ccw.size());
//					if(next<=0)
//						next += L;
//					t += next;
//					ccwIdx++;
//				} else {
//					int next = cw.get((cwIdx-1)%cw.size()) - cw.get(cwIdx%cw.size());
//					if(next<=0)
//						next += L;
//					t += next;
//					cwIdx++;
//				}
//				if(lane1==-1 && t>=2*(T%L)) {
//					lane1 = dirCW ? cw.get((cwIdx-1)%cw.size()) : ccw.get((ccwIdx-1)%ccw.size());
//					dir1 = dirCW;
//				}
//				if(lane2==-1 && t>=2*L) {
//					lane2 = dirCW ? cw.get((cwIdx-1)%cw.size()) : ccw.get((ccwIdx-1)%ccw.size());
//				}
//				dirCW ^= true;
//			}
//			int gap2 = Arrays.binarySearch(x, lane2) - Arrays.binarySearch(x, cw.get(0));
			
			int[] pos = new int[N];
			for(int i=0; i<N; i++)
				pos[i] = (int)((x[i]+(w[i]? T%L : L-(T%L)))%L);
			Arrays.sort(pos);
			
//			lane1 = (int)((lane1 + (dir1 ? T : L-(T%L)))%L);
//			int idx = Arrays.binarySearch(pos, lane1);
//			if(idx<N-1 && pos[idx]==pos[idx+1] && !dir1)
//				idx++;
////				idx = (idx-1+N)%N;
//			idx = (idx - Arrays.binarySearch(x, cw.get(0)) + N)%N;
//			idx = (int)((idx + ((long)gap2+N)*(T/L))%N);
			
			
			long cnt = 0;
			for(int ccwx : ccw) {
				long dis = (ccwx-cw.get(0)+L)%L;
				cnt = (cnt + (2*T + L-dis-1)/L)%N;
			}
			
			int a = Arrays.binarySearch(pos, (int)((cw.get(0)+T)%L));
			if(a>0 && pos[a-1]==pos[a])
				a--;
			int cidx = (a - Arrays.binarySearch(x, cw.get(0)) - (int)cnt + N + N)%N;
			
			for(int i=0; i<N; i++)
				pw.println(pos[(cidx+i)%N]);
//			if(cidx!=idx) {
//				pw.println("OK :"+cidx);
//				pw.println("NG :"+idx);
//			}
		}
		
		sc.close();
		pw.close();
	}
}


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

using namespace std;

bool array_equal(int arr1[], int arr2[], int N){
  for(int i=1; i<=N; i++)
    if(arr1[i] != arr2[i])
      return false;
  return true;
}

int main(void){
  int N;
  cin >> N;
  int P[N], Q[N], arr_p[N], arr_q[N];
  int i;
  for(i=1; i<=N; i++)
    cin >> P[i];
  for(i=1; i<=N; i++)
    cin >> Q[i];

  //P, Qと比較する用の順列を格納する配列
  for(i=1; i<=N; i++){
    arr_p[i] = i;
    arr_q[i] = i;
  }

  //P, Qが順列の何番目かを格納する変数
  int p = 1, q = 1;
  //Pの処理
  do{
    if(array_equal(P, arr_p, N) == 0)
      p++;
    else
      break;
  }while(next_permutation(arr_p+1, arr_p+N+1) );

  //Qの処理
  do{
    if(array_equal(Q, arr_q, N) == 0)
      q++;
    else
      break;
  }while(next_permutation(arr_q+1, arr_q+N+1) );
  

  //cout << "p : "<<p<<endl;
  //cout << "q : "<<q<<endl;
  cout << abs(p-q) << endl;
  
  return 0;
}


Measured memory_bytes: 256
H, W, M = map(int, input().split())
hk = [[0, i] for i in range(H + 1)]
wk = [[0, j] for j in range(W + 1)]
s = set()
for i in range(M):
    h, w = map(int, input().split())
    hk[h][0] += 1
    wk[w][0] += 1
    s.add((h, w))
hk.sort(reverse=True)
wk.sort(reverse=True)
colmax = wk[0][0]
ans = 0
for lowacc, i in hk:
    if lowacc + colmax <= ans:
        break
    for colacc, j in wk:
        if lowacc + colacc <= ans:
            break
        else:
            ans = max(ans, lowacc + colacc - ((i, j) in s))
print(ans)


Measured memory_bytes: 127680
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
  static void Main(string[] args) {
    int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    int N = input[0];
    int A = input[1];

    int[] x = new int[N + 1];
    input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    for (int i = 0; i < N; ++i) {
      x[i + 1] = input[i];
    }

    long[,,] dp = new long[N + 1, N + 1, N * A + 1];

    for (int i = 0; i < N; ++i) dp[i, 0, 0] = 1;

    for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= i; ++j) {
        for (int k = 1; k <= N * A; ++k) {
          if (k < x[i]) {
            dp[i, j, k] = dp[i - 1, j, k];
          } else {
            dp[i, j, k] = dp[i - 1, j, k] + dp[i - 1, j - 1, k - x[i]];
          }
        }
      }
    }

    long ans = 0;
    for (int j = 1; j <= N; ++j) {
      ans += dp[N, j, j * A];
    }

    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 60256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INT 1000000000

int a[2000];

int main() {
  while(1) {
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    REP(i, n)
      scanf("%d", &a[i]);
    int min = INT_MAX;
    for(int i = 0; i < n; i++) {
      for(int j = i + 1; j < n; j++) {
        if (min > abs(a[i] - a[j]))
          min = abs(a[i] - a[j]);
      }
    }
    printf("%d\n", min);
  }
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = long long;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[51][52];



signed main(){
	IOS;
	ll n;
	cin >> n;
	vec<ll> a(n),b(n),am(n),bm(n);
	REP(i,n)cin >> a[i];
	REP(i,n)cin >> b[i];
	ll ans = 0;
	for(ll i = 0;i < 30;i++){
		ll mod = (1ll << i + 1);
		REP(j, n)am[j] = a[j] % mod;
		REP(j, n)bm[j] = b[j] % mod;
		sort(ALL(bm));
		ll cnt = 0;
		ll t = (1ll << i);
		REP(j, n){
			cnt += lower_bound(ALL(bm),2 * t - am[j]) - lower_bound(ALL(bm),t - am[j]);
			cnt += lower_bound(ALL(bm),4 * t - am[j]) - lower_bound(ALL(bm),3 * t - am[j]);
		}
		if(cnt % 2)ans += (1ll << i);
	}
	dump(ans);
}

Measured memory_bytes: 8576
w,h,n=map(int,input().split())
x1=0
x2=w
y1=0
y2=h

for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if x1<x:
            x1=x
    elif a==2:
        if x<x2:
            x2=x
    elif a==3:
        if y1<y:
            y1=y
    else:
        if y<y2:
            y2=y

if x2<=x1 or y2<=y1:
    print(0)
else:
    print((x2-x1)*(y2-y1))

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

int main(void){
    int a1, a2, a3;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a1 >> a2 >> a3;
    cout << (a1 + a2 + a3 <= 21? "win" : "bust") << "\n";
    return 0;
}

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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
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; }

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 
ll fff(ll n, vector<ll>& v, ll i, ll j, ll rl){
  ll can = 0;
  ll can_i = 0;

  cout << v[0]<<endl;
  
  // right
  if(rl == 0){
    rep(k, n){
      if(v[k]*(j-k)>can){
	can = v[k]*(j-k);
	can_i = k;
      }
      //cout << can<<endl;
    }
    v[can_i] = 0;
    return can;
  }
  // left
  else{
    rep(k, n){
      if(v[k]*(k-i)>can){
	can = v[k]*(k-i);
	can_i = k;
      }
      //cout << can<<endl;

    }
    v[can_i] = 0;
    return can;
  }
  
}


int main(){
  ll n,m;

  cin>>n>>m;

  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(m);
  vector<ll> d(m);
  
  rep(i, n){
    cin >> a[i];
    cin >> b[i];
  }
  rep(i, m){
    cin >> c[i];
    cin >> d[i];
  }

  rep(i, n){
    ll dis = 10000000000;
    ll ans = 0;
    rep(j, m){
      ll x = abs(a[i]-c[j]);
      ll y = abs(b[i]-d[j]);
      if(dis > (x + y ) ){
    	ans = j+1;
	dis = x+y;
      }
    }
    cout << ans<<endl;
  }
  
  //cout<<tmp<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define MAXN 200000 + 5
#define ll long long
#define int long long
using namespace std;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define con continue
#define endl "\n"
 
//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 
signed main(){
    int h , a;
    cin >> h >> a;
    cout << (h / a) + ((h % a) ? 1 : 0);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
import string
characters = list(string.ascii_lowercase)
lettercount = dict()
for character in characters :
    lettercount[character] = []
for i in range(n) :
    si = input()
    for character in characters :
        lettercount[character] += [si.count(character)] 
for character in characters :
    lettercount[character] = min(lettercount[character])
lettercount = sorted(list(lettercount.items()), key = lambda x : x[0])
ans = ""
for lettertuple in lettercount :
    ans += lettertuple[0] * lettertuple[1]
print(ans)

Measured memory_bytes: 3896
N = int(input())
A = [int(x) for x in input().split()]

count = 1
flag = ""

for i in range(N - 1):
    d = A[i + 1] - A[i]

    if flag == "":
        if d > 0:
            flag = "P"
        elif d < 0:
            flag = "M"

    elif (flag == "P" and d < 0) or (flag == "M" and d > 0):

        count += 1
        flag = ""

print(count)


Measured memory_bytes: 14252
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()

# 四方に一回り大きいグリッドを作る
grid = [['#'] * (W+2) for i in range(H+2)]
for i in range(1,H+1):
    row = list(input())
    for j in range(1, W+1):
        grid[i][j] = row[j-1]

dp = [[0] * (W+2) for i in range(H+2)]
# スタート地点に1通りを初期値設定
dp[1][1] = 1
for i in range(1,H+1):
    for j in range(1, W+1):
        # 現在位置が壁なら何もできない
        if grid[i][j] == '#':
            continue
        # 上が壁でなければ、値を持ってくる
        if grid[i-1][j] != '#':
            dp[i][j] += dp[i-1][j]
        # 左が壁でなければ、値を持ってくる
        if grid[i][j-1] != '#':
            dp[i][j] += dp[i][j-1]
# ゴール地点の値を確認する
print(dp[H][W] % MOD)


Measured memory_bytes: 166396
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
	int a,b,c;
	int k;
	cin>>a>>b>>c>>k;
	if(k<a) cout<<k<<endl;
	else if(k>=a&&k<=b) cout<<a<<endl;
	else cout<<a-(k-a-b)<<endl;
	
	return 0;
} 

Measured memory_bytes: 3576
#include <stdio.h>

int main(){
  int total;
  scanf("%d", &total);
  int A[total];
  int i, j;
  for(i=0; i<total; ++i){
	scanf("%d", &A[i]);
  }
  int count=0;
  int min, tmp, index;
  for(i=0; i<(total-1); ++i){
	min=A[i];
	tmp=A[i];
	for(j=(i+1); j<total; ++j){
	  if(min>A[j]){
		min=A[j];
		index=j;
	  }
	}
	if(min!=tmp){
	  ++count;
	  A[i]=min;
	  A[index]=tmp;
	}	  
	
  }

  for(i=0; i<total; ++i){
	printf("%d", A[i]);
	if(i<(total-1))
	  printf(" ");
  }
  printf("\n%d\n", count);
  return 0;
}



Measured memory_bytes: 2100
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]
ans = -1
for i in range(10 ** n):
    tmp = str(i)
    if len(tmp) == n:
        flg = True
        for l in lst:
            if tmp[l[0] - 1] != str(l[1]):
                flg = False
                break
        if flg == True:
            ans = i
            break
print(ans)

Measured memory_bytes: 3064
n=int(input())
l=list(map(int,input().split()))

cnt=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            a=l[i]
            b=l[j]
            c=l[k]
                
            if(a!=b and b!=c and c!=a)and (l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[i]+l[k]>l[j]) :
                cnt+=1

print(cnt)

Measured memory_bytes: 9168
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;

int main(void) {
  ll N, D, ans = 0;
  cin >> N >> D;
  rep(_, N) {
    ll x, y;
    cin >> x >> y;
    if (x * x + y * y <= D * D)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
C = []
for i in range(3):
    C.append(list(map(int,input().split())))
for i in range(0,2):
    for j in range(0,2):
        if C[i][j] + C[i+1][j+1] != C[i+1][j] + C[i][j+1]:
            print('No')
            exit()
if C[0][0] + C[2][2] != C[0][2] + C[2][0]:
    print('No')
    exit()
print('Yes')

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 0; i < n + 1; ++i) {
        for (int j = 0; j < m + 1; ++j) {
            if (n * j + m * i - 2 * i * j == k) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
#define ll long long 
#define mod 1000000007
string s1,s2;
int i=0,j=0;
void f1();
void f2();
void f1()
{
	if(i>=(int)s1.size()) return;
	cout<<s1[i];
	i++;
	f2();
}

void f2()
{
	if(j>=(int)s2.size()) return;
	cout<<s2[j];
	j++;
	f1();
}

int main()
{
	cin>>s1>>s2;
	f1();
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N;
ll color[100100];
vector<PLL> edges[100100]; // {nxt, ID}: 次の頂点nxt, その辺のID

void dfs(ll cur, ll par, ll col) {
  ll i = 0;
  for (auto e : edges[cur]) {
    ll nxt = e.first, id = e.second;
    if (nxt == par) {
      continue;
    }
    while(i == col) {
      i++;
    }
    color[id] = i;
    dfs(nxt, cur, i);
    i++;
  }
}

signed main() {
  cin >> N;
  rep(i,N-1) {
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back({b, i});
    edges[b].push_back({a, i});
  }
  dfs(0, -1, -1);

  ll _max = 0;
  rep(i,N-1) { _max = max(_max, color[i]+1); }
  cout << _max << endl;
  rep(i,N-1) {
    cout << color[i]+1 << endl;
  }
}


Measured memory_bytes: 9856
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 2 - 170;

ll pow_ (ll x, ll n, ll M){
    ll u = 1;
    if(n > 0){
        u = pow_(x, n/2, M);
        if (n % 2 == 0) u = (u*u) % M;
        else u = (((u * u)% M) * x) % M;
    }
    return u;
};

int main() {
    string s;
    cin >> s;
    vector<ll> v(s.length()+1, 0), v2(s.length()+1, 0),
               v3(s.length()+1, 0), v4(s.length()+1, 0);
    for (int i = 0; i < s.length(); ++i) {
        if(s[i] == 'A') v[i+1] = v[i]+1;
        else v[i+1] = v[i];
        if(s[i] == '?') v3[i+1] = v3[i]+1;
        else v3[i+1] = v3[i];
    }
    for (int j = static_cast<int>(s.length() - 1); j > 0; --j) {
        if(s[j] == 'C') v2[j-1] = v2[j]+1;
        else v2[j-1] = v2[j];
        if(s[j] == '?') v4[j-1] = v4[j]+1;
        else v4[j-1] = v4[j];
    }
    ll ans = 0;
    for (int k = 1; k < s.length()-1; ++k) {
        if(s[k] != 'B' && s[k] != '?') continue;
        ll p = ((((v[k]*3+v3[k])*(v2[k]*3+v4[k])) % MOD) * pow_(3, v3[k]+v4[k]-2, MOD)) % MOD;
        if(v3[k]+v4[k]-2 < 0){
            for (int i = 0; i < 2-v3[k]-v4[k]; ++i) {
                p /= 3;
            }
        }
        ans = (ans + p)%MOD;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int a = in.nextInt();
        int b = in.nextInt();
        int k = in.nextInt();

        int count = 0;
        int x = a < b ? a : b;
        for (int i = 1; i <= x; i++) {
            if (a % i == 0 && b % i == 0) {
                sb.append(i + "_");
                count++;
            }
        }
        String ans = sb.toString();
        System.out.println(ans.split("_")[count-k]);
    }
}

Measured memory_bytes: 22740
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        string str = Console.ReadLine();
        string out1 = "";
        int inde = 0;
        int others = 0;
        //foreach (char c in str)
        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == '(')
            { 
                out1 = out1 + "(";
                others = others + 1;
            }
            if (str[i] == ')')
            {
                if (others == 0)
                {
                    out1 = "(" + out1 + ")";
                }
                else
                {
                    out1 = out1 + ")";
                    others = others - 1;
                }
            }
        }
        for (int i = 0; i < others; i++)
        {
            out1 = out1 + ")";
        }
        Console.WriteLine(out1);
    }
}

Measured memory_bytes: 11092
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

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

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n,x,y,l;
vpi pos;
vi lens,d;
map<int,int> tempd;

const char vec[4] = {'L', 'D', 'U', 'R'};
signed main(){
    I(n);
    REP(i,n){
        I(x); I(y);
        pos.eb(x,y);
        lens.pb(abs(x) + abs(y));
        if (i && lens[i]%2 != lens[i-1]%2 ){
            cout << -1 << endl;
            return 0;
        }
    }
    int ld = 33;
    
    // REP(i,ld) d.pb(1LL << i);
    // if (lens[0]%2 == 0) d.pb(1);
    printf("%lld\n",ld + (lens[0]%2==0));
    REP(i,ld) printf("%lld ", 1LL<<i);
    if (lens[0]%2 == 0) printf("1");
    printf("\n");

    int dsum = (1LL << ld) - 1;


    for (auto p: pos){
        int px = p.first;
        int py = p.second - 1 + (lens[0]%2);
        
        int u = px + py;
        int v = px - py;
        int du = (u+dsum)/2;
        int dv = (v+dsum)/2;

        REP(i,ld){
            int mask = 1LL << i;
            printf("%c", vec[((mask&du)>0) * 2 + ((mask&dv)>0)]);
        }
        if (lens[0]%2 == 0) printf("U");
        printf("\n");

    }
}

Measured memory_bytes: 256
/* ex4_1
   moka223711 */

#include <stdio.h>

int main(void){
    // n本の木があり、1〜nの番号がついている
    // 番号iの木に監視員がつき、i-dからi+dまでの木を監視できる
    // すべての木を監視するのに必要な監視員の数の最小値を求める
    
    int n, d, ans = 0;
    scanf("%d %d", &n, &d);
    
    // 監視員はi-dからi+dまでの2d+1本の木を監視できる
    // nを2d+1で割った商を求め、余りがあったときはもう一人監視員を加える
    ans = n / (2*d + 1);
    if(n % (2*d + 1) != 0){
        ans++;
    }
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	const LL INF = 1LL << 60;
	while (true) {
		LL n = -1, k = -1;
		cin >> n >> k;
		if (n <= 0 || k < 0) break;
		vector<LL> a(n), f(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		for (int i = 0; i < n; ++i) {
			cin >> f[i];
		}
		sort(a.begin(), a.end());
		sort(f.rbegin(), f.rend());
		LL left = -1, right = INF;
		while (right - left > 1) {
			LL mid = (right + left) / 2;
			LL r = k;
			for (int i = 0; i < n; ++i) {
				LL x = mid / f[i];
				if (x <= 0) {
					r -= a[i];
				} else {
					r -= max(0LL, a[i] - x);
				}
			}
			if (r < 0) {
				left = mid;
			} else {
				right = mid;
			}
		}
		cout << right << endl;
	}
	return 0;
}


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

using namespace std;

int main()
{
	int x, y, n, k;
	cin >> n >> k >> x >> y;
	
	int xsum = x * k, ysum = y * (n - k);
	if(n < k){
		xsum = x * n;
	}
	if(ysum < 0){
		ysum = 0;
	}
	cout << xsum + ysum << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main(){
    int d,h;
	while(cin>>d){
		h=0;
		for(int i=1;i<600/d;i++)
			h+=(i*d)*(i*d)*d;
		cout<<h<<endl;
	}
	return 0;
}


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

int main(){string a,b;cin>>a>>b;
           if(a[0]==b[2]){
             if(a[1]==b[1]&&a[2]==b[0]){
               cout<<"YES"<<endl;
             }
             else{
               cout<<"NO"<<endl;
             }
           }
           else{
             cout<<"NO"<<endl;
           }
          }

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

li = [-1] * N

for s, c in SC:
    if li[s - 1] == -1:
        li[s - 1] = c
    else:
        if not li[s - 1] == c:
            print(-1)
            exit()

ans = ""

if N == 1:
    print(max(0, li[0]))
    exit()

for i in range(N):
    if i == 0:
        if li[i] == 0:
            print(-1)
            exit()
        else:
            ans += str(max(li[i], 1))

    else:
        ans += str(max(0, li[i]))

print(ans)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll mod = 1000000007;

bool secinc(const pair<ll, ll> a, const pair<ll, ll> b) {
  return a.second < b.second;
}

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

  int n;
  cin >> n;

  vector<pair<ll, ll>> robots;

  rep(i, n) {
    ll x, l, s, e;
    cin >> x >> l;
    s = x - l;
    e = x + l;
    robots.emplace_back(s, e);
  }

  sort(robots.begin(), robots.end(), secinc);

  ll ans = n;
  ll last = -INF;
  for (auto robo : robots) {
    if (robo.first >= last) {
      last = robo.second;
    } else {
      ans--;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  string S;
  cin >> S;
  
  int Ans = 0;
  if( S.size() > 1){
  	for (int i = 1; i < S.size(); i++){
    	if ( S.at(i-1) == '0' && S.at(i) == '0' ) {
          S.at(i) = '1';
          Ans += 1;
          //cout << "pass" ;
        }
		else if (S.at(i-1) == '1' && S.at(i) == '1'){
          S.at(i) = '0';
          Ans += 1;
          //cout << "pass" ;
        }
      //cout << Ans << endl;
    }
  }
  cout << endl;
  cout << Ans << endl;
  
}

Measured memory_bytes: 512
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int X, A; cin >> X >> A;

    int ans = X < A ? 0 : 10;
    cout << ans << endl;

    return 0;
}

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

def g(num):
    ans = []
    for i in range(1, num+1):
        if num % i == 0:
            ans.append(i)
    return ans
a = g(A)
b = g(B)

r = list(set(a) & set(b))
r.sort(reverse=True)

print(list(r)[K-1])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 25

struct Info{
	Info(){

		value = 0,weight = 0;
	}
	Info(ll arg_value,ll arg_weight){
		value = arg_value;
		weight = arg_weight;
	}
	bool operator<(const struct Info &arg) const{

		return weight < arg.weight;
	}

	ll value,weight;
};

ll N,W;
ll POW[SIZE];
ll table_B[1 << 21];
Info info[45];


int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%lld %lld",&N,&W);

	for(int i = 0; i < N; i++){

		scanf("%lld %lld",&info[i].value,&info[i].weight);
	}

	if(N == 1){

		if(info[0].weight <= W){

			printf("%lld\n",info[0].value);
		}else{

			printf("0\n");
		}

		return 0;
	}

	vector<int> A,B;
	for(int i = 0; i < N/2; i++){

		A.push_back(i);
	}
	for(int i = N/2; i < N; i++){

		B.push_back(i);
	}

	vector<Info> vec_A,vec_B;
	for(int state = 0; state < POW[A.size()]; state++){

		ll sum_w = 0;
		ll sum_value =0;
		for(int loop = 0; loop < A.size(); loop++){
			if(state & POW[loop]){
				sum_w += info[A[loop]].weight;
				sum_value += info[A[loop]].value;
			}
		}
		vec_A.push_back(Info(sum_value,sum_w));
	}
	sort(vec_A.begin(),vec_A.end());

	for(int state = 0; state < POW[B.size()]; state++){

		ll sum_w = 0;
		ll sum_value =0;
		for(int loop = 0; loop < B.size(); loop++){
			if(state & POW[loop]){
				sum_w += info[B[loop]].weight;
				sum_value += info[B[loop]].value;
			}
		}
		vec_B.push_back(Info(sum_value,sum_w));
	}
	sort(vec_B.begin(),vec_B.end());

	table_B[0] = vec_B[0].value;
	for(int i = 1; i < vec_B.size(); i++){

		//ある重さ以下の最大価値を求める
		table_B[i] = max(table_B[i-1],vec_B[i].value);
	}

	int tail = vec_B.size()-1;
	ll ans = 0;
	for(int i = 0; i < vec_A.size(); i++){

		while(tail >= 0 && vec_A[i].weight+vec_B[tail].weight > W)tail--;
		if(tail < 0)break;

		ans = max(ans,vec_A[i].value+table_B[tail]);
	}

	printf("%lld\n",ans);

	return 0;
}




Measured memory_bytes: 44084
import math

pi = math.acos(-1)

a, b, h, m = (int(x) for x in input().split())

s_ang = h * 30 + m * 0.5
l_ang = m * 6

ang = min(abs(s_ang - l_ang), 360-abs(s_ang-l_ang))

rad = math.radians(ang)

c = math.sqrt(pow(a, 2) + pow(b, 2) - 2*a*b*math.cos(rad))

if ang == 0:
    c = abs(a-b)
elif ang == 180:
    c = a+b
    
print('{:.10f}'.format(c))



Measured memory_bytes: 9464
require 'prime'
 
primes = Prime.each(1_000_000).to_a
 
while (n = gets.to_i) > 0
    i = 0
    j = (primes.find_index{|x| x > n} || primes.size) - 1
 
    count = 0
    while
        s = primes[i] + primes[j]
        count += 1 if s == n
        break if i == j
        if s < n
            i += 1
        else
            j -= 1
        end
    end
    p count
end

Measured memory_bytes: 18240
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,m,x,y;
	int tmp;
	cin >> n >> m >> x >> y;
	int maxx=x;
	int miny = y;
	rep(i, n) {
		cin >> tmp;
		maxx = max(maxx, tmp);
	}
	rep(i, m) {
		cin >> tmp;
		miny = min(miny, tmp);
	}
	if (maxx >= miny)cout << "War" << endl;
	else cout << "No War" << endl;

	return 0;
}

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

#define endl '\n'
#define int long long

int32_t main()
{
    int n;
    cin >> n;
    int a[n],b[n],c[n];
    for(int i=1;i<=n;i++){
    	cin >> a[i];
    }
    for(int i=1;i<=n;i++){
    	cin >> b[i];
    }
    for(int i=1;i<n;i++)
    	cin >> c[i];
    int ans=0;
    for(int i=1;i<n;i++){
    	if(a[i]+1 == a[i+1])
    	    ans+=c[a[i]];
    	ans+=b[i];
    }
    ans+=b[n];
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

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

int px, py, n, X[10], Y[10];

bool dfs(int x, int y, int t) {
	if (!(x >= 0 && x < 10 && y >= 0 && y < 10)) return false;
	if (t > 0) {
		if (!(X[t - 1] - 1 <= x && x <= X[t - 1] + 1 && Y[t - 1] - 1 <= y && y <= Y[t - 1] + 1)) return false;
		if (t == n) return true;
	}
	
	bool res = false;
	REP(i, 12) {
		int nx = x + dx[i], ny = y + dy[i];
		if (dfs(nx, ny, t + 1)) res = true;
	}
	return res;
}

int main() {
	while (true) {
		cin >> px >> py;
		if (!px && !py) break;		
		cin >> n;
		REP(i, n) scanf("%d %d", &X[i], &Y[i]);
		
		if (dfs(px, py, 0)) puts("OK");
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <queue>
#include <climits>
#include<cmath>
#include <sstream>
#include <iomanip>

bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.second < another.second;
}


int main()
{

    int64_t a,b;
    //int64_t c = 1;
    
    std::cin>> a;

    std::vector< std::pair< int64_t, int64_t > > data( a );

    for( int i = 0; i < a; i++ )
    {
        std::cin>> data[i].first;
        std::cin>> data[i].second;
    }

    std::sort( data.begin(), data.end(), sort_pair );
    int64_t c = 0;
    int64_t current = 0;
    bool first = true;
    std::string result = "Yes";

    for( int i = 0; i < a; i++ )
    {
        if( current != data[i].first )
        {
            current = data[i].second;
            
            if( i != 0 )
            {
                if( data[i-1].second < c )
                {
                    result = "No";
                    break;
                }
            }
        }
        
        c += data[i].first;
    }

    if( data.back().second < c )
    {
        result = "No";
    }

    std::cout<< result;
    
}


Measured memory_bytes: 3456
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define rep(index,num) for(int index=0;index<num;index++)
#define eps 1e-15
typedef long long ll;
int main(){
	int N,K,X,Y,hoge;
	scanf("%d %d %d %d",&N,&K,&X,&Y);
	if(K>N) hoge=N*X;
	else hoge=K*X+(N-K)*Y;
	printf("%d\n",hoge);
	return 0;
}


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

using namespace std;

const int N = 81; 
const int Z = 80*80*2+10; 
bitset<N*N*4> dp[N][N];
int a[N][N];

void solve() {
    int n,m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int x; cin >> x;
            a[i][j] -= x;
            if (a[i][j] < 0) a[i][j]*=-1;
        }
    }
    dp[0][0][Z+a[0][0]] = 1;
    dp[0][0][Z-a[0][0]] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (i==0 && j==0)continue;
            if (i) (dp[i][j] |= dp[i-1][j] << a[i][j]) |= dp[i-1][j] >> a[i][j];
            if (j) (dp[i][j] |= dp[i][j-1] << a[i][j]) |= dp[i][j-1] >> a[i][j];
        }
    }
    const int lim  = N*N*2; 
    for (int i = 0; i < lim; i++) {
        if (dp[n-1][m-1][Z+i] || dp[n-1][m-1][Z-i]) {
            cout << i; return;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 21120
def main():
    n, m = map(int, input().split())
    answer = 0
    cost = [list(map(int, input().split())) for _ in range(n)]
    cost.sort(key=lambda x: x[0])
    for c, num in cost:
        if m < 0:
            break
        answer += c * min(m, num)
        m -= min(m, num)
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 29020
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int rate = 380000;
int main(){
   int N;
   cin >> N;
   float x[N];
   string s[N];

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

   float sum=0;

   for(int i=0;i<N;i++){
     if(s[i]=="JPY"){
        sum += x[i];
     }else{
        sum += 380000*x[i];
     }
   }
   cout << sum <<endl;


  return 0;
}

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

main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,d;
	cin>>n>>d;
	vector<ll>h(n);
	vector<ll>dp(n);
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
		dp[i]=INT_MAX;
	}
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
		for(int j=i;j>-1 && i-j<=d;j--)
		{
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n-1];
}

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

int main() {
  int a,b,c,d;
  
  cin >> a >> b >> c >> d;
  int x = c - a;
  int y = d - b ;
  cout << c-y << " " << d+x << " " << a-y << " " << b+x;
}


Measured memory_bytes: 256
// header {{{
// header {{{
#include <bits/stdc++.h>
using namespace std;
 
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
 
#define ASSERT(expr...) assert((expr))
 
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
 
using f32 = float;
using f64 = double;
// }}}
 
constexpr i64 INF = 1'010'000'000'000'000'017LL;
 
constexpr i64 MOD = 1'000'000'007LL;
 
constexpr f64 EPS = 1e-12;
 
constexpr f64 PI = 3.14159265358979323846;
 
#define M5 100007
 
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define ll long long int
#define VI vector <ll>
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
 
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
 
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
 
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}
 
// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
 
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}
 
//--------------------------------------------------------------------
 
 
 
void solve() {
    string S;
    cin >> S;
    int N = S.length();
    if(N%2==1){
        cout << "No";
        return;
    }
    REP(i,N/2){
        if(S[i*2]!='h' || S[i*2+1] != 'i'){
            cout << "No";
            return;
        }
    }
    cout << "Yes";

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

Measured memory_bytes: 256