akhauriyash/Code-Regression huggingface dataset:
while True:
    W, H = [int(n) for n in input().split()]

    if W == H == 0:
        break

    next_target = []

    room = []
    for n in range(H):
        s = list(input())
        room.append(s)
        for y in range(W):
            if s[y] == '@':
                next_target.append((n, y))

    result = 0

    while len(next_target) > 0:
        t = next_target.pop()

        # ???
        if t[0] - 1 >= 0 and room[t[0] - 1][t[1]] == '.':
            next_target.append((t[0] - 1, t[1]))
            room[t[0] - 1][t[1]] = '@'

        # ???
        if t[1] + 1 < W and room[t[0]][t[1] + 1] == '.':
            next_target.append((t[0], t[1] + 1))
            room[t[0]][t[1] + 1] = '@'

        # ???
        if t[0] + 1 < H and room[t[0] + 1][t[1]] == '.':
            next_target.append((t[0] + 1, t[1]))
            room[t[0] + 1][t[1]] = '@'

        # ???
        if t[1] - 1 >= 0 and room[t[0]][t[1] - 1] == '.':
            next_target.append((t[0], t[1] - 1))
            room[t[0]][t[1] - 1] = '@'

        # ?????????????????????????????????
        result += 1

    print(result)

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int H, W; cin >> H >> W;
  int M = 80 * (H + W) * 2;
  int geta = 80 * (H + W);
  vector<vector<vector<bool>>> mp(H, vector<vector<bool>>(W, vector<bool>(M, false)));
  vector<vector<int>> red(H, vector<int>(W)), blue(H, vector<int>(W));
  REP(i, H) REP(j, W) cin >> red[i][j];
  REP(i, H) REP(j, W) cin >> blue[i][j];
  mp[0][0][geta] = true;
  REP(r, H) REP(c, W) {
    //cerr << r << ',' << c << ':';
    int diff = red[r][c] - blue[r][c];
    REP(v, M) {
      if (not mp[r][c][v]) continue;
      if (r < H - 1) {
        if (v + diff < M) mp[r+1][c][v+diff] = true;
        if (v - diff >= 0) mp[r+1][c][v-diff] = true;
      }
      if (c < W - 1) {
        if (v + diff < M) mp[r][c+1][v+diff] = true;
        if (v - diff >= 0) mp[r][c+1][v-diff] = true;
      }
    }
    //cerr << endl;
  }

  int ans = 80 * 80 * 80 * 80;
  int diff = red[H-1][W-1] - blue[H-1][W-1];
  REP(v, M) {
    if (mp[H-1][W-1][v]) {
      ans = min(ans, min(std::abs(v + diff - geta), std::abs(v - diff - geta)));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 20864
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		if (a >= 13) {
			System.out.println(b);
		} else if (a >= 6 && a <= 12) {
			System.out.println(b / 2);
		} else {
			System.out.println(0);
		}
	}
}


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

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

    string s;
    cin >> s;
    int from = INF, to;
    for (int i = 0; i < s.size(); i++) {
        if (from == INF && s[i] == 'A') from = i;
        else if (from != INF && s[i] == 'Z') {
            to = i;
        }
    }
    int ans = to-from+1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int A = in.nextInt();
		int B = in.nextInt();
		int C = in.nextInt();
		int X = in.nextInt();

		int count = 0;

		for (int i = 0; i <= A; i++) {
			for (int j = 0; j <= B; j++) {
				int c = (X - i * 500 - j * 100) / 50;
				if (c >= 0 && c <= C) {
					count++;
				}

			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <queue>
using namespace std;


int main(){
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC";
    else cout << "ABC";
}

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


int main(){
  int n,i;
  cin >> n;
  vector<int> a(n);
  long long ans,cal;
  ans=0;
  cal=0;
  for(i=0;i<n;++i){
    cin >> a[i];
    if(i>0 && i<=n-1){
      ans+=abs(a[i-1]-a[i]);
    }
  }
  int ini,fin;
  ini=abs(0-a[0]);
  fin=abs(a[n-1]-0);
  for(i=0;i<n;++i){
    cal=ans;
    if(i==0){
      ini=abs(0-a[1]);
      cal+=ini;
      cal-=abs(a[0]-a[1]);
      cal+=fin;
    }else if(i>=1 && i<n-1){
      ini=abs(0-a[0]);
      cal+=ini;
      cal-=abs(a[i]-a[i+1]);
      cal-=abs(a[i-1]-a[i]);
      cal+=abs(a[i-1]-a[i+1]);
      cal+=fin;
    }else if(i==n-1){
      ini=abs(0-a[0]);
      cal+=ini;
      cal-=abs(a[i-1]-a[i]);
      fin=abs(a[n-2]-0);
      cal+=fin;

    }
    cout << cal << endl;
  }
  return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<queue>
#include<limits>
// #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<cmath>
#include<math.h>
#include<iomanip>  
#include<deque> 
#include<stack>
#include<string> 
#include<string.h>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#define ll long long
#define tc(t)  while(t--)
#define V vector
#define Vp vector< pair<int,int> >
#define pb push_back
#define UM unordered_map
#define IT iterator
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define PQ priority_queue
#define _FI ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

 char ar[140000];
vector<ll> SieveOfEratosthenes(ll n) 
{ 
  vector<ll> result;
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
    int count=1;
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        {  
            for (ll i=p*p; i<=n; i += p) 
                {
                  prime[i] = false; 
                }
            count++;
        } 
    } 
  
    for (ll p=2; p<=n; p++) 
       if (prime[p]) 
          {
            result.push_back(p);
          }
    return result;
}



vector<ll> Divisors (ll n)
{
  vector<ll> res;
  for(ll i=1;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      if(n/i==i)
      {
        res.pb(i);
      }
      else
      {
        res.pb(i);
        res.pb(n/i);
      }
    }
  }

  return res;
}

int a[4][2]={ {1,0}, {1,-1}, {1,1}, {2,0} } ;
bool validPoint(int x,int y, int N)
{
    return (x>=0 && x<N && y>=0 && y<N);
}


 
int main()
{
  _FI 
  
  int h;
  cin>>h;
  int n;
  cin>>n;
  V<ll> v(n);
  ll sum=0;
  forn(i,n)
    {
      cin>>v[i];
      sum+=v[i];
    }
  if(h<=sum)
  {
    cout<<"Yes";
  }
  else
  {
    cout<<"No";
  }


  return 0;
}












 // V<double> arr(2*n);
 //  V<double> proper;
 //  V<double> improper;
 //  double sum=0;
 //  for(int i=0;i<2*n;i++)
 //  {
 //      cin>>arr[i];
 //      sum+=arr[i];
 //      if(arr[i]-floor(arr[i])==0)
 //        proper.pb(arr[i]);
 //      else
 //        improper.pb(arr[i]);
 //  }


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

using namespace std;

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

    int n;
    cin >> n;

    vector<int> ar(10005);

    for(int i = 1; i <= 110; i++){
        for(int j = 1; j <= 110; j++){
            for(int z = 1; z <= 110; z++){
                int calc = i*i + j*j + z*z + i*j + j*z + i*z;
                if(calc <= 10005) ar[calc - 1]++;
            }
        }
    }
    for (int x = 0; x < n; x++){
        cout << ar[x] << endl;
    }
    return 0;
}

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

using namespace std;


int main() 
{
	long long  n;
	scanf("%lld",&n);
	long long ans = 0;
	long long i = 0;
	for(i = 1; ans + i < n; i++)
	{
//		printf("%d\n",ans);
		ans += i;
	}
	printf("%lld\n",i);
	return 0;
}


Measured memory_bytes: 764
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;
using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}

const int MAX = 50;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){

 int n;
 cin>>n;
 vector<int> p(n);
 vector<int> piv(n);
 for(int i=0;i<n;i++){
   int x;
   cin>>x;
   p[i] = x;
 }
 for(int i=0;i<n;i++){
   piv[i] = 0;
 }

int ans = 1;
//int min = p[0];
    
// for(int i=0;i<n;i++){
//   int x = p[i];
//   int flag = 0;
//   if(p[i] <= min){
//     min = p[i];
  
//     for(int j=0;j<x;j++){
//       if(piv[j]!=0){
//         flag = 1;
//         break;
//       }
//     }
//     if(flag==0)ans++;
//     piv[p[i]-1] = 1;
//   }
// }

int min = p[0];

for(int i=0;i<n;i++){
  //cout<<min<<endl;
  if(p[i] < min){
    min = p[i];
    ans++;
  }

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

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

void solve(long long N, long long A, long long B, vector<long long> P){
  long long a, b, c;
  a = 0;
  b = 0;
  c = 0;
  for (int i = 0; i < N; i++) {
    if (P[i] <= A) {
      a++;
    } else if (P[i] <= B){
      b++;
    } else {
      c++;
    }
  }
  std::cout << min(a, min(b, c)) << std::endl;
}

int main(){
  long long B;
  long long N;
  long long A;
  scanf("%lld",&N);
  vector<long long> P(N);
  scanf("%lld",&A);
  scanf("%lld",&B);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&P[i]);
  }
  solve(N, A, B, P);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int D;
  cin >> D;
  vector<int> c(26);
  for (int i = 0; i < 26; i++){
    cin >> c[i];
  }
  vector<vector<int>> s(D, vector<int>(26));
  for (int i = 0; i < D; i++){
    for (int j = 0; j < 26; j++){
      cin >> s[i][j];
    }
  }
  vector<int> last(26, -1);
  for (int i = 0; i < D; i++){
    vector<int> d(26, 0);
    for (int j = 0; j < 26; j++){
      d[j] = s[i][j] + c[j] * (i - last[j]);
    }
    int pos = max_element(d.begin(), d.end()) - d.begin();
    cout << pos + 1 << endl;
    last[pos] = i;
  }
}

Measured memory_bytes: 3696
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<52;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

template <class T>
class RMQ{
	private:
	int n;
	vector<T> rmq;
	T Queryfunc(int a,int b,int k,int l,int r){
		if(r<=a||b<=l) return -1;
		if(a<=l&&r<=b) return rmq[k];
		int m=(l+r)/2;
		T vl=Queryfunc(a,b,k*2+1,l,m);
		T vr=Queryfunc(a,b,k*2+2,m,r);
		return max(vl,vr);
	}
	public:
	RMQ(int n_){
		n=1;
		while(n<n_) n*=2;
		rmq=vector<T>(2*n-1,-1);
	}
	void Update(int k,int x){
		k+=n-1;
		rmq[k]=x;
		while(k>0){
			k=(k-1)/2;
			rmq[k]=max(rmq[k*2+1],rmq[k*2+2]);
		}
	}
	T Query(int a,int b){
		return Queryfunc(a,b,0,0,n);
	}
	void Clear(){
		for(int i=0;i<2*n-1;i++) rmq[i]=-1;
	}
	T Open(int k){
		return rmq[k+n-1];
	}
};

int n,m;
vl a;
RMQ<ll> b(5000);

vvl f;
map<int,vi> mp;

void Rec(int s,int t){
	if(s==t) return;
	ll q=b.Query(s,t);
	ll I=*lower_bound(mp[q].begin(),mp[q].end(),s),d=b.Open(I);
	f[s][I]+=d;f[s][t]-=d;
	f[I+1][I]-=d;f[I+1][t]+=d;
	Rec(s,I);
	Rec(I+1,t);
}

int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	a=vl(n);
	vvl tmp(n,vl(m));
	for(int i=1;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin>>tmp[i][j];
	for(int i=1;i<n;i++) a[i]+=a[i-1];
	f=vvl(n+1,vl(n+1));
	for(int i=0;i<m;i++){
		mp.clear();
		b.Clear();
		for(int j=0;j<n;j++){
			b.Update(j,tmp[j][i]);
			mp[tmp[j][i]].push_back(j);
		}
		Rec(0,n);
	}
	for(int i=0;i<=n;i++) for(int j=1;j<=n;j++) f[i][j]+=f[i][j-1];
	for(int j=0;j<=n;j++) for(int i=1;i<=n;i++) f[i][j]+=f[i-1][j];
	ll ans=0;
	for(int i=0;i<n;i++) for(int j=i;j<n;j++) ans=max(ans,f[i][j]-a[j]+a[i]);
	cout<<ans<<endl;
	
}

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

#define ll long long
#define ld long double
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
//    string s;
//    cin >> s;
//    set<char> se;
//    for (auto i = s.begin(); i != s.end(); i++)
//        se.insert(*i);
//    for (char i = 'z'; i!= 'a'; i++){
//        if (se.find(i) == se.end()){
//            cout << i << endl;
//            return 0;
//        }
//    }
//    cout << "None" << endl;
    ll n;
    cin >> n;
    ll a[n+1];
    for (ll i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    ll answ = 0;
    ll kv = 0;
    ll co = 1;
    ll o = 0;
    ll p = 0;
    for (ll i = 2; i <= n; i++){
        if (a[i] != a[i-1]){
            if (co >= 4 && p != 1) {
                kv = max(kv, a[i - 1] * a[i - 1]);
                p = 1;
            }
            if (co >= 2) {
                if (answ == 0 && o == 0){
                    answ = a[i-1];
                    o = 1;
                } else if (o == 1){
                    answ = answ*a[i-1];
                    o = 2;
                }
            }
            co = 1;
        } else {
            co++;
        }
    }
    //cout << kv << " " << answ << " " << o << " " << co << endl;
    if (co >= 4 && p != 1){
        kv = max(kv,a[n]*a[n]);
        p = 1;
    }
    if (co >= 2) {
        if (answ == 0 &&  o == 0){
            answ = a[n];
            o = 1;
        } else if (o == 1){
            answ = answ*a[n];
            o = 2;
        }
    }
    if (o != 2){
        answ = 0;
    }
    cout << max(answ,kv) << endl;
    return 0;
}

Measured memory_bytes: 1024
class UnionFindNode:
    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.rank_ = 1
        self.member_num_ = 1

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()

        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                n_root, child = root, unite_root
            else:
                n_root, child = unite_root, root
            child.parent_ = n_root
            n_root.rank_ = max(n_root.rank_, child.rank_ + 1)
            n_root.member_num_ = n_root.member_num_ + child.member_num_

N, = map(int, input().split())
X,Y = [],[]
for i in range(1, N+1):
    x, y = map(int, input().split())
    X.append((x,i))
    Y.append((y,i))
X = sorted(X, key=lambda x:x[0])
Y = sorted(Y, key=lambda x:x[0])
Es = set()
for i in range(N-1):
    Es.add((tuple(sorted([X[i][1], X[i+1][1]])), abs(X[i][0]-X[i+1][0])))
    Es.add((tuple(sorted([Y[i][1], Y[i+1][1]])), abs(Y[i][0]-Y[i+1][0])))
node_list = [UnionFindNode(i) for i in range(N+1)]
Es = sorted(Es, key=lambda x:x[1])
r = 0
for (x, y), c in Es:
    if node_list[x].find() == node_list[y].find():
        continue
    r += c
    node_list[x].unite(node_list[y])
print(r)


Measured memory_bytes: 130264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, Q, S, T;
ll data[200006];
ll sa[200005] = {};
ll sum = 0;
 
ll calc(ll x, ll y)
{
    if(x > 0) {
        if(y > 0) return ((x - y) * S);
        else return (x * S - y * T);
    } else {
        if(y > 0) return (x * T - y * S);
        else return ((x - y) * T);
    }
}
int main()
{
    cin >> N >> Q >> S >> T;
     
    for(int i = 0; i <= N; i++) {
        scanf("%lld", &data[i]);
    }
    for(int i = 0; i < N; i++) {
        sa[i] = data[i + 1] - data[i];
        if(sa[i] > 0) {
            sum -= S * sa[i];
        } else {
            sum -= T * sa[i];
        }
    }
    while(Q--) {
        ll l, r, x;
        scanf("%lld %lld %lld", &l, &r, &x); l--;
        sum += calc(sa[l], sa[l] + x);
        sa[l] += x;
        if(r < N) {
            sum += calc(sa[r], sa[r] - x);
            sa[r] -= x;
        }
        printf("%lld\n", sum);
    }
    return (0);
}

Measured memory_bytes: 6344
#include<bits/stdc++.h>
     
    using namespace std;
     
    int main(){
      long long  a,b,c;
      cin>>a>>b>>c;
      if ( a%2==0 || b%2==0 || c%2==0) {
        cout<<0;
        return 0;
      }
      long long  tab[3];
      tab[0]=a;
      tab[1]=b;
      tab[2]=c;
      sort(tab,tab+3);
      cout<<tab[1]*tab[0];
    }

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

int main(){
    string s;
    cin >> s;
    int a[2] = {};
    int n = s.length();
    rep(i,n){
        if(s[i] == 'g') a[0]++;
        if(s[i] == 'p') a[1]++;
    }
    int g = (n+1)/2;
    int p = n - g;
    cout << (a[0] - g) << endl;
    return 0;
}

Measured memory_bytes: 512
mod = 10**9+7
MAX_N = 20000000+5

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod


def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

x,p,y,q = map(int,input().split())
 
res = mod_comb_k(p+x,x,mod) - mod_comb_k(p+y+1,y+1,mod) - mod_comb_k(q+x+1,x,mod) + mod_comb_k(q+y+2,y+1,mod)
print(res%mod)

Measured memory_bytes: 637984
//Author : Prakhar Asaiya
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(ll i=a;i<b;++i)
#define REPN(i,a,b) for(ll i=a;i<=b;++i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define ll long long
const int M=1e9+7;



int main()
{/*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#*/
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

     string s,t;
     cin>>s;
     cin>>t;
     bool flag=1;
     if(t.length()==s.length()+1)
     {
     	REP(i,0,s.length())
     	{
     		if(s[i]!=t[i])
     		{
     			cout<<"No\n";
     			flag=0;
     			break;
			}
		}
		if(flag)
		cout<<"Yes\n";
	 }
	 else
	 cout<<"No\n";
 

   return 0;
}


Measured memory_bytes: 3668
import math

def run():
  a, b, x = map(int, input().split())
  if a**2*b/2 > x:
    tan = 2*x/(a*b**2)
    print(90-math.degrees(math.atan(tan)))
  else:
    tan = 2*(a**2*b-x)/(a**3)
    print(math.degrees(math.atan(tan)))
  
if __name__ == '__main__':
  run()

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b)swap(a,b);
    if(b>c)swap(b,c);
    if(a>b)swap(a,b);
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; return(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

ll gcd(ll a, ll b) {
    if (a < b) {
        return gcd(b, a);
    }
    ll c = a % b;
    while (c != 0) {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    cin >> n >> m >> k;
    vl a(n);
    vl b(m);

    IPT(a, n)
    IPT(b, m)

    vl sum_a(n);
    vl sum_b(m);

    sum_a.at(0) = a.at(0);
    sum_b.at(0) = b.at(0);

    REP(i, 1, n) {
        sum_a[i] = sum_a.at(i - 1) + a.at(i);
    }

    REP(i, 1, m) {
        sum_b[i] = sum_b.at(i - 1) + b.at(i);
    }

    auto itr = upper_bound(ALL(sum_b), k);
    ll count = distance(sum_b.begin(), itr);
  	ans = count;
    NREP() {
        if (sum_a.at(i) > k) {
            break;
        }

        auto b_itr = upper_bound(ALL(sum_b), k - sum_a.at(i));

        ll a_count = i + 1;
        ll b_count = distance(sum_b.begin(), b_itr);
        
        if (b_count < 0) b_count = 0;
        ans = max(ans, a_count + b_count);
    }
    MSG(ans)
}


Measured memory_bytes: 9604
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    ll sum = 0;
    ll N;
    cin >> N;
    for (ll n = 1; n <= N; n++) {
        if (n % 3 != 0 && n % 5 != 0) {
            sum += n;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
def cost(h_i, h_j):
    return abs(h_i - h_j)


def main():
    N = int(input())
    H = [int(i) for i in input().split()]

    dp = [10 ** 9] * N
    dp[0] = 0
    dp[1] = cost(H[0], H[1])
    for i in range(2, N):
        dp[i] = min(dp[i - 1] + cost(H[i - 1], H[i]), dp[i - 2] + cost(H[i - 2], H[i]))
    ans = dp[-1]
    print(ans)


if __name__ == '__main__':
    main()


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

map<pair<LL, LL>, LL> _memo;

LL get(LL A, LL B) {
  if (A == B) return 1;
  if (A > B) return 0;

  auto p = make_pair(A, B);
  if (_memo.find(p) != _memo.end()) return _memo[p];

  LL rec = get(A/2, B/2);
  LL result = rec * 2;
  if (B % 2 == 0) {
    LL p2 = 1;
    while (!(p2&B)) p2 <<= 1;
    if (B - p2 + 1 < A) {
      result -= 1;
    }
  }
  if (A % 2 == 1) {
    result -= (rec - get(A/2+1,B/2));
  }

  return _memo[p] = result;
}

int main() {
  LL A, B;
  scanf("%lld%lld", &A, &B);
  LL result = get(A, B);
  printf("%lld\n", result);
}


Measured memory_bytes: 256
import pprint

def dfs(v, n, visited):
    all_visited = True

    for i in range(n):
        if visited[i] is False:
            all_visited = False

    if all_visited:
        return 1

    ret = 0
    for i in range(n):
        if edges[v][i] is False:
            continue
        if visited[i]:
            continue

        visited[i] = True
        ret += dfs(i, n, visited)
        visited[i] = False
    return ret


N, M = tuple(map(int, input().split()))
nmax = 8
edges = [[False] * nmax for _ in range(nmax)]
for _ in range(M):
    A, B = tuple(map(int, input().split()))
    edges[A-1][B-1] = True
    edges[B-1][A-1] = True

visited = [False] * nmax
visited[0] = True
print(dfs(0, N, visited))


Measured memory_bytes: 3572
n, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

dp = [[[-1] * (3 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
dp[0][0][0] = 0
w1 = wv[0][0]

for i, (w, v) in enumerate(wv):
    for j in range(i + 1):
        for k in range(3 * n + 1):
            if dp[i][j][k] != -1:
                dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k])
                w_diff = w - w1
                if j + 1 <= n and k + w_diff <= 3 * n:
                    dp[i+1][j+1][k+w_diff] = max(dp[i+1][j+1][k+w_diff], dp[i][j][k] + v)

ans = 0
for j in range(n + 1):
    w_diff_mx = min(W - w1 * j, 3 * n)
    for k in range(w_diff_mx + 1):
        ans = max(ans, dp[n][j][k])

print(ans)


Measured memory_bytes: 31656
n = int(input())
abc = ['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']
G = [99 for i in range(26)]#こっちが答えのリスト
for i in range(n):
  A = [0 for i in range(26)]
  S = list(input())
  for s in S:
    A[abc.index(s)] += 1
  for j in range(26):
    G[j] = min(G[j], A[j])
L = ""
for i in range(26):
  L += abc[i]*G[i]
print(L)


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

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << endl;
    cout << X << endl;
    cout << Y << endl;
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
count=0
dic = {}
for i in range(len(l)):
    if l[i] in dic:
        dic[l[i]]+=1
    else:
        dic[l[i]]=1
l_set = list(set(l))
m = len(l_set)
for i in range(m-2):
    for j in range(i+1, m-1):
        for k in range(j+1, m):
            x = l_set[i]
            y = l_set[j]
            z = l_set[k]
            if max(x, y, z) < x + y + z - max(x, y, z):
                count+=dic[x]*dic[y]*dic[z]
print(count)

Measured memory_bytes: 68492
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if(a != 1 && b != 1)cout << 1;
    else if(a != 2 && b != 2)cout << 2;
    else cout << 3;
}

Measured memory_bytes: 256
#include<stdio.h>
int main (){
int a,b,c,d,e;
  scanf ("%d%d%d",&a,&b,&c);
  d=a+b+c;
    e=a*b*c;
  if (d==17 && e==175){
  printf ("YES");
  }
  else {
  printf ("NO");
  }
  return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n = int(input())
    pp = LI()
    s = 0
    ans = 0
    for i, p in enumerate(pp, 1):
        if i == p:
            s += 1
        else:
            ans += (s + 1) // 2
            s = 0
    ans += (s + 1) // 2
    print(ans)

main()


Measured memory_bytes: 14388
#include<stdio.h>
#include<iostream>
using namespace std;
string a;
int main()
{
	cin>>a;
	if(a.find_first_of("C")==string::npos)
	{
		puts("No");
		return 0;
	}
	int c=a.find_first_of("C");
	a.erase(0,c);
	a.find("F")==string::npos?puts("No"):puts("Yes");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] assignments = new int[m];

        for (int i=0; i<m; i++) {
            assignments[i] = scan.nextInt();
        }
        
        int totalDays = 0;
        for (int assignment : assignments) {
            totalDays = totalDays + assignment;
        }
        
        if (totalDays > n) {
            System.out.println(-1);
        } else {
            System.out.println(n - totalDays);
        }
    }
}

Measured memory_bytes: 46172
#include <iostream>
#include <algorithm>
#include <utility>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

typedef struct record_{
	public:
	int c;
	int p;
	int id;
	record_(int a1,int a2,int a3){
		c=a1;p=a2;id=a3;
	}
}record;

bool cmp(record a,record b){
	if(a.c > b.c)return true;
	if(a.c==b.c && a.p < b.p)return true;
	if(a.c==b.c && a.p==b.p &&  a.id < b.id)return true;
	return false;
}

int score[50][10];
vector<record> data;
int main(){
	//record d = record(1,2,3);
	while(true){
		data.clear();
		int t,p,r;
		memset(score,0,sizeof score);
		cin >> t >> p >> r;
		if(t==0&&p==0&&r==0)return 0;
		for(int i=0;i<t;i++)data.push_back(record(0,0,i));

		for(int i=0;i<r;i++){
			int tid,pid,time;
			string str;
			cin >> tid >> pid >> time >> str;
			tid--;
			pid--;
			if(str=="WRONG"){
				score[tid][pid]++;
			}else{
				data[tid].c++;
				data[tid].p+=time;
				data[tid].p+=score[tid][pid]*1200;
			}
		}
		sort(data.begin(),data.end(),cmp);
		for(int i=0;i<data.size();i++){
			cout << data[i].id+1 <<" "<< data[i].c<<" " << data[i].p << endl;
		}
	}
}

Measured memory_bytes: 928
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑


int main() {
	ll n, ans;
	cin >> n;
	ans = n;
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {
			while (n % i == 0) { n /= i; }
			ans = ans - ans / i;
		}
	}
	if (n > 1) { ans = ans - ans / n; }
	cout << ans << endl;
}

//1 4 5 6


Measured memory_bytes: 3108
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int N = in.i();
        int H = in.i();
        long[] katana = new long[N];
        Arrays.setAll(katana, i -> in.i() + (in.l() << 30));
        Arrays.sort(katana);
        int c = 0;
        int ans = 0;
        for (int i = N - 1; i >= 0; i--) {
            long k = katana[i];
            int a = (int)(k & (1 << 30) - 1);
            int b = (int)(k >> 30);
            if (b < c) {
                break;
            } else {
                c = max(c, a);
                H -= b;
                ans++;
                if (H <= 0) {
                    c = 0;
                    break;
                }
            }
        }
        if (c > 0) {
            ans += (H - 1) / c + 1;
        }
        out.println(ans);
    }

    static int max(int a, int b) {
        return a < b ? b : a;
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = read(cbuf, 0, cbuf.length);
            } catch (IOException e) {}
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                back();
                break;
            }
        }
    }

    char[] s(final int N) {
        skip();
        char[] s = new char[N];
        for (int i = 0; i < s.length; i++) {
            s[i] = next();
        }
        return s;
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 38628
import os

N,T = (int(x) for x in input().split())
t = [int(i) for i in input().split()]

ans = 0
sum = 0
for i in range(N-1):
    if t[i+1]-t[i]>=T:
        ans += T
    else:
        ans += t[i+1]-t[i]
print(ans+T)


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

int main() {
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int A = x2 - x1;
	int B = y2 - y1;
	
	int x3 = x2 - B;
	int y3 = y2 + A;
	int x4 = x3 - A;
	int y4 = y3 - B;

	printf("%d %d %d %d",x3,y3,x4,y4);
}

Measured memory_bytes: 256
a,b,k = map(int,input().split())

List = []
for i in range(k):
  if a+i <=b:
    List.append(a+i)
  if b-i>=a:
    List.append(b-i)

List = list(set(List))
List= sorted(List)
for i in List:
  print(i)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        int c = 0;
        for (ll i = 2; i * i <= n; i++) {
                int t = 0;
                while (n % i == 0) {
                        n /= i;
                        t++;
                }

                for (int j = 1; j * (j + 1) <= 2 * t; j++) {
                        c++;
                }
        }

        if (n > 1) {
                c += 1;
        }

        cout << c << endl;

        return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>  // ver1.9.7
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a.back()<<endl
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(8);
  vector<Pii> data(4);
  int qw;
  rep(i,0,4){
    cin >> qw;
    rep(j,0,3-i) qw *= 2;
    data[i] = mp(qw,3-i);
  }
  
  sort(ALL(data));
  rep(i,0,4){
    rep(j,0,data[i].second) data[i].first /= 2;
    //cout << data[i].first << endl;
  }
  
  
  int now,ans = 0;
  cin >> now;
  now *= 4;
  
  rep(i,0,4){
    qw = data[i].second;
    if(qw==0){
      ans += (now/8)*data[i].first;
      now -= (now/8)*8;
    }
    else if(qw==1){
      ans += (now/4)*data[i].first;
      now -= (now/4)*4;
    }
    else if(qw==2){
      ans += (now/2)*data[i].first;
      now -= (now/2)*2;
    }
    else if(qw==3){
      ans += (now/1)*data[i].first;
      now -= (now/1)*1;
    }
    //cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	string s1,s2;
	cin >> s1 >> s2;
	if(s1[1]==s2[1]&&s1[0]==s2[2]&&s1[2]==s2[0]){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}

}

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

int main() {
  int a,b;
  cin >> a >> b;
  int A,B;
  A = a * 100;
  B = b * 100;
  int c,d,e,f;
  if(A % 8 == 4){
    c = A / 8 + 1;
  }
  else{
  c = A / 8;
  }
  if((A + 100) % 8 == 0){
    d = (A + 100)/8 - 1;
  }
  else{
  d = (A + 100) / 8 ;
  }
  e = B / 10;
  f = (B + 100) / 10 - 1;
  if(d < e){
    cout << -1 << endl;
  }
  else if(c > f){
    cout << -1 << endl;
  }
  else if((e <= c) && (f <= d)){
    cout << c << endl;
  }
  else if((c <= e) && (d <= f)){
    cout << e << endl;
  }
  else if((c <= e) && (d >= f)){
    cout << e << endl;
  }
  else if((e <= c) && (d <= f)){
    cout << c << endl;
  }
}



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

#define pb(s) push_back(s)
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))

typedef long long ll;


ll N, x;

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

    cin>>N>>x;
    vector<ll> vi;
    for(int i=0;i<N;++i){
        ll a;
        cin>>a;
        vi.pb(a);
    }
    ll sum=0;
    for(int i=1;i<N;++i){
        if(vi[i]+vi[i-1]>x){
            ll dif=(vi[i]+vi[i-1])-x;
            if(vi[i]>=dif){
                vi[i]-=dif;
                sum+=dif;
            }
            else{
                sum+=vi[i];
                dif-=vi[i];
                vi[i]=0;
                vi[i-1]-=dif;
                sum+=dif;
            }
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 1400
#include<stdio.h>
#include<math.h>
 
typedef struct koch{
  double x;
  double y;
}Koch;
 
void point(int , Koch, Koch );
 
int main(){
  Koch x,y; 
  int n;
  
  scanf("%d",&n);

  x.x=0;
  x.y=0;
  y.x=100;
  y.y=0;
    
  printf("%.8f %.8f\n",x.x,x.y);
  point(n,x,y);   
  printf("%.8f %.8f\n",y.x,y.y);
 
  return 0;
}

void point(int n ,Koch x ,Koch y){ 
  Koch a,b,c;
  double r=M_PI*60.0/180.0;
 
  if(n==0) return;
  
  a.x=(2.0*x.x + y.x)/3.0;
  a.y=(2.0*x.y + y.y)/3.0;
 
  b.x=(x.x + 2.0*y.x)/3.0;
  b.y=(x.y + 2.0*y.y)/3.0;
    
  c.x=(b.x-a.x)*cos(r)-(b.y-a.y)*sin(r)+a.x;
  c.y=(b.x-a.x)*sin(r)+(b.y-a.y)*cos(r)+a.y;
    
  if(n>0){
  point(n-1,x,a);
  printf("%.8f %.8f\n",a.x,a.y);
  point(n-1,a,c);
  printf("%.8f %.8f\n",c.x,c.y);
  point(n-1,c,b);
  printf("%.8f %.8f\n",b.x,b.y);
  point(n-1,b,y); 
  } 
}


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

using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

void solve(){
	constexpr int MOD = 1e9 + 7;

	int n;
	cin >> n;

	vector<ll> arr(n);
	for(auto& i : arr) cin >> i;

	auto presum = arr;
	partial_sum(presum.rbegin(), presum.rend(), presum.rbegin());
	for(auto& i : presum) i %= MOD;

	ll ans = 0;

	for(int i = 0; i < n - 1; ++i)
		ans = (ans + arr[i] * presum[i + 1]) % MOD;

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

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


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

ll solve() {
    ll N;
    string S;
    cin >> N >> S;
    vector<int> L(N), R(N);
    int c = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( S[i] == 'W' ) c++;
        L[i] = c;
    }
    c = 0;
    for ( int i = N-1; i >= 0; i-- ) {
        if ( S[i] == 'E' ) c++;
        R[i] = c;
    }
    ll ans = N;
    for ( int i = 0; i < N; i++ ) {
        int nn = 0;
        if ( i > 0 ) nn += L[i-1];
        if ( i < N-1 ) nn += R[i+1];
        if ( ans > nn ) ans = nn;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

int main()
{
    string S, P;
    cin >> S >> P;
    S += S;
    for(int i=0; i<S.size(); ++i)
    {
        if(S.substr(i, P.size()) == P)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <map>

using namespace std;

typedef pair<int,int> Paint;

bool Pairsecond(const Paint& pf,Paint&ps){//sortCompare
  return pf.second < ps.second;
}

#define anyfill(n,s) setw(n) << setfill(s)
#define pb push_back
#define MAX 1000000000
#define MOD 1000000007


/*
確認ポイント
to_string() はC++11以降の実装;
cout<< (char)数値 //数値にあった文字に置き換えられる
cout<< (double)int型/(2など)//小数になる
length(),size()に括弧をつけ忘れてないか;
sort()が使える型//vector,string...
大文字小文字間違えてないか
cout << fixed << 小数計算//正しい小数表記になる(基本6桁)(e記法回避にも使える)
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
sqrt(数値型)でrootが取れる
vector.unique()は隣接した同じ要素を削除するので先にソートをする
*/
int main() { 
  int n;cin>>n;
  int mns = 0;
  int pls = 0;
  vector<int> mns_ar;
  vector<int> pls_ar;
  int mns_sm = 0;
  int pls_sm = 0;
  for(int i = 0; n > i; i++){
    int tmp;cin>>tmp;
    if(tmp < 0){
      mns++;
      mns_ar.push_back(tmp);
      mns_sm += tmp;
    }else{
      pls++;
      pls_ar.push_back(tmp);
      pls_sm += tmp;
    }
  }



  sort(mns_ar.begin(),mns_ar.end(),greater<int>());
  sort(pls_ar.begin(),pls_ar.end(),greater<int>());
  vector<Paint> rooot;
  if(pls == 0){
    rooot.push_back(make_pair(mns_ar[0],mns_ar[mns_ar.size()-1]));
    int ret = mns_ar[0]-mns_ar[mns_ar.size()-1];
    for(int i = 1; mns_ar.size()-1 > i; i++){
      rooot.push_back(make_pair(ret,mns_ar[i]));
     ret = ret-mns_ar[i];
    }
    cout << ret << endl;
  }else if(mns == 0){
    int ret = pls_ar[pls_ar.size()-1];
    pls_ar.pop_back();
    for(int i = 0; pls_ar.size()-1 > i; i++){
      rooot.push_back(make_pair(ret,pls_ar[i]));
      ret = ret-pls_ar[i];
    }
    rooot.push_back(make_pair(pls_ar[pls_ar.size()-1],ret));
    cout << pls_ar[pls_ar.size()-1]-ret << endl;
  }else{
    int mnspl = mns_ar[mns_ar.size()-1];
    mns_ar.pop_back();
    for(int i = 0; pls_ar.size()-1 > i; i++){
      rooot.push_back(make_pair(mnspl,pls_ar[i]));
      mnspl = mnspl-pls_ar[i];
    }
    int onlypls = pls_ar[pls_ar.size()-1];
    rooot.push_back(make_pair(onlypls,mnspl));
    onlypls = onlypls - mnspl;
    for(int i = 0; mns_ar.size() > i; i++){
      rooot.push_back(make_pair(onlypls,mns_ar[i]));
      onlypls = onlypls-mns_ar[i];
    }
    cout << onlypls << endl;
  }
  for(int i = 0; rooot.size() > i; i++){
    cout << rooot[i].first << " " << rooot[i].second << endl;
  }
}




Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int MAXN = 200005;
const int MOD = 1000000007;

int cnt[100][30];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	for(int i=0;i<n;i++){
		string s; cin >> s;
		for(int j=0;j<s.length();j++) cnt[i][s[j]-'a']++;
	}
	for(int i=0;i<26;i++){
		int k = 1e9;
		for(int j=0;j<n;j++) k = min(k,cnt[j][i]);
		for(int j=0;j<k;j++) cout << (char) (i+'a');
	}
	cout << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>					
using namespace std;
bool isprime(int n){
	for(int i = 2;i*i<=n;i++){
		if(n%i==0){
			return false;break;
		}
	}if(n==1){
	return false;
}
	return true;
}	
int main()	
{		long long n;
cin>>n;
for(int i =n;i<n*n;i++){
	if(isprime(i)){
		cout<<i;break;
	}
}														
	return 0; 									
 } 


Measured memory_bytes: 256