akhauriyash/Code-Regression huggingface dataset:
//                                  _                 ______   ______   ______   ______
//                                 | |               |  __  | |  __  | |  __  | |____  |
//    __ _   ____    _____    _  _ | |____           | |__| | | |__| | | |__| |      | |
//  / _` | |  __| /  __  |  / _` | |  __  |          |____  | |____  | |____  |      | |
// | (_| | | |    | |  | | | (_| | | |__| |  ______   ____| |  ____| |  ____| |      | |
//  \__,_| |_|    |_|  |_|  \__,_| |______| |______| |______| |______| |______|      |_|

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define endl '\n'
#define REP(i, n) for(int i=0; i<n; i++)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9+7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
  // #endif
  FAST();
  //Code goes past here:

  string str;
  cin>>str;

  int i=0;
  while(i<str.length()){
    if(str[i]=='h' && str[i+1]=='i')
      i+=2;
    else{
      cout<<"No\n";
      exit(0);
    }
  }
  cout<<"Yes\n";

  return 0;
}


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

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long



int main(){
  LL cp,n,s=0;
  cin>>n;
  if(n/10==0){
    cout<<n<<endl;
    return 0;
  }
  cp=n;
  while(true){
    if(n>=10 && n%10!=9)
      break;
    else if(n<10){
      s+=n;
      cout<<s<<endl;
      return 0;
    }
    n/=10;
    s+=9;
  }
  s=0;
  n=cp;
  while(true){
    if(n==0)
      break;
    if(n<10){
      s+=n-1;
      break;
    }
    n/=10;
    s+=9;
  }
  cout<<s<<endl;
  return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rept(i,k,n) for(ll i = (k); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;
typedef tuple<int,int,int> Tii;
long long powm(long long a, long long b, long long mod=1000000007){
    if(b<0) b+=mod-1;
    if(b>0){
        if(b%2==1) return a*powm(a*a%mod,b/2)%mod;
        else return powm(a*a%mod,b/2)%mod;
    }else{
        return 1;
    }
}


void exptb(long long a, long long mod, vector<long long> &tb){
    tb[0]=1;
    for(long long i=1;i<tb.size();i++){
        tb[i]=tb[i-1]*a%mod;
    }
}
ll mod = 1e10;
int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n+1,0),b(m+1,0);
    rep(i,n){
        cin>>a[i+1];
        a[i+1]+=a[i];

    } 
    rep(i,m){
        cin>>b[i+1];
        b[i+1]+=b[i];

    } 
    ll ans=0;
    rep(i,n+1){
        ll s = k-a[i];
        if(s<0) break;
        int re = upper_bound(b.begin(),b.end(),s)-b.begin()-1;
        ans=max(ans,i+re);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6428
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using System.Threading.Tasks;

namespace B_Digits
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] n = new int[4];
            for (int i = 0; i < 4; i++) {
                n[i] = int.Parse(ReadLine());
            }
            int result = 0;
            int sum = 0;
            for (int j =0;j<n[0]+1;j++) {
                for (int k = 0; k <n[1]+1; k++) {
                    for (int l = 0; l <n[2]+1; l++) {
                        sum = j * 500 + k * 100 + l * 50;
                        if (sum == n[3]) {
                            result++;
                           
                        }
               
                    }
               
                }
            }
        
            WriteLine("{0}",result);
            ReadKey();

        }
    }
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;



int main() {
    li a;
    cin>>a;
    cout<<3*a*a<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define mk make_pair
#define pp pair<int,int>
#define ppl pair<long long int,long long int>
#define vec vector<int> 
#define finput ifstream cin;cin.open("in.txt")
#define foutput ofstream cout;cout.open("out.txt") 

//solve()
int main(){
	int a,b;
	cin>>a>>b;
	cout<<a*b - a - b + 1;	
}

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

ll N, A[100000];

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];

  map<ll, ll> mp;
  REP(i, 0, N) {
    mp[A[i] - 1]++;
    mp[A[i]]++;
    mp[A[i] + 1]++;
  }

  ll ans = 0;
  REP(i, -1, 100010) {
    ans = max(ans, mp[i]);
  }

  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  for(int i = 0; i < N; i++) cin >> h[i];
  vector<int> DP(N, 0);
  DP[1] = abs(h[1] - h[0]);
  int cost1, cost2;
  for(int i = 2; i < N; i++) {
    cost1 = abs(h[i] - h[i - 1]);
    cost2 = abs(h[i] - h[i - 2]);
    if(DP[i - 1] + cost1 <= DP[i - 2] + cost2) DP[i] = DP[i - 1] + cost1;
    else DP[i] = DP[i - 2] + cost2;
  }
  cout << DP[N - 1] << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array


# Eratosthenes????????????????????´??°limit??????????´???°???????????????
# ???????????????????????´??§?????????????????¢?????´???????????????????¬???§???pp.410-412
def sieve_of_eratosthenes(limit, typecode="L"):
    # ??´??°i????´???°??§????????????table[i]?????????
    # ??????????????????True??§?????????????????????
    table = array.array("B", (True for i in range(limit)))
    # 0, 1????????????????´???°??§?????????
    table[0] = False
    table[1] = False
    # ?´???°???????´?????????????
    # primes = array.array(typecode)
    for i in range(2, limit):
        if table[i]:  # i????´???°??§????????¨???
            # primes.append(i)  # ?´???°?????????????????????
            for j in range(i * 2, limit, i):  # i????¶???????i????????°????????????
                table[j] = False  # ?´???°??§???????????????????????????
    # return primes
    return table


if __name__ == "__main__":
    table = sieve_of_eratosthenes(123456 * 2 + 1)
    while True:
        n = int(input())
        if n == 0:
            break
        else:
            print(sum(table[n + 1: 2 * n + 1]))

Measured memory_bytes: 7824
n,a,b = map(int,input().split())

a_cnt,b_cnt,cnt = 0,0,0
s = input()
cnt = a+b
for i in range(n):
    if s[i] == "a":
        if a_cnt + b_cnt < cnt:
            a_cnt +=1#print(a_cnt + b_cnt)
            print("Yes")
        else:
            print("No")
        
    elif s[i] == "b":
        if a_cnt + b_cnt < cnt and b_cnt < b:
            b_cnt +=1
            print("Yes")
        else:
            print("No")
        
    elif s[i] == "c":
        print("No")


Measured memory_bytes: 9268
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	string a, b, c; cin >> a >> b >> c;
	int cnt = 0;
	rep(i, 0, N) {
		if (a[i] == b[i] && b[i] == c[i])
			continue;
		if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) {
			cnt++;
		}
		else {
			cnt += 2;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

#define MAX_H (100)
#define MAX_W (100)
#define SIZE_BUF (30)
#define NUM_ALPHA (26)

void pick_center(int *cnts, int n) {
  for (int i = 0; i < n; i++) {
    if (cnts[i] % 2 == 1) {
      cnts[i]--;
      return;
    }
  }
  for (int i = 0; i < n; i++) {
    if (cnts[i] > 0) {
      cnts[i]--;
      return;
    }
  }
}

void pick_center_line(int *cnts, int n, int num) {
  int t = num;
  if (t > 0) {
    for (int i = 0; i < n; i++) {
      if (cnts[i] % 4 == 2) {
        cnts[i] -= 2;
        t -= 2;
        if (t == 0) {
          return;
        }
      }
    }
  }
  if (t > 0) {
    for (int i = 0; i < n; i++) {
      if (i < n) {
        if (cnts[i] >= t) {
          cnts[i] -= t;
          t = 0;
        } else {
          t -= cnts[i];
          cnts[i] = 0;
        }
        if (t == 0) {
          return;
        }
      }
    }
  }
}

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int H, W;
  char ass[MAX_H * MAX_W], buf[SIZE_BUF];
  scanf("%d %d", &H, &W);
  fgets(buf, SIZE_BUF, stdin);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf("%c", &ass[j + i * W]);
    }
    fgets(buf, SIZE_BUF, stdin);
  }

  // count each letter
  int cnts[NUM_ALPHA] = {};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cnts[ass[j + i * W] - 'a']++;
    }
  }

  // try composing a palindrome matrix
  int possible = 1;
  // pick the element in the middle if there is one
  if (H % 2 == 1 && W % 2 == 1) {
    pick_center(cnts, NUM_ALPHA);
  }
  // check that all the counts are even at this point
  for (int i = 0; i < NUM_ALPHA; i++) {
    if (cnts[i] % 2 != 0) {
      possible = 0;
      break;
    }
  }

  // try picking characters in the middle of each row
  // (not including the character in the middle of the matrix)
  if (H % 2 == 1) {
    pick_center_line(cnts, NUM_ALPHA, (W / 2) * 2);
  }
  if (W % 2 == 1) {
    pick_center_line(cnts, NUM_ALPHA, (H / 2) * 2);
  }
  // check that all counts are divisible by 4 at this point
  // check that all the counts are even at this point
  for (int i = 0; i < NUM_ALPHA; i++) {
    if (cnts[i] % 4 != 0) {
      possible = 0;
      break;
    }
  }
  if (possible) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

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

  int H,W,K;
  cin >> H >> W >> K;
  vector<string> c(H);
  repr(i, H, 0) cin >> c[i];

  int ans = 0;
  for (int i = 0; i < (1 << H); ++i) {
    vector<bool> hbit(H);
    for (int b = 0; b < H; ++b) {
      if ((i >> b) & 1) hbit[b] = true;
    }

    for (int j = 0; j < (1 << W); ++j) {
      vector<string> s = c;
      vector<bool> wbit(W);
      for (int b = 0; b < W; ++b) {
        if ((j >> b) & 1) wbit[b] = true;
      }

      for (int b = 0; b < H; ++b) {
        if (hbit[b]) {
          for (int k = 0; k < W; ++k) {
            s[b][k] = '&';
          }
        }
      }

      for (int b = 0; b < W; ++b) {
        if (wbit[b]) {
          for (int k = 0; k < H; ++k) {
            s[k][b] = '&';
          }
        }
      }

      int cnt = 0;
      for (int b = 0; b < H; ++b) {
        for (int k = 0; k < W; ++k) {
          if (s[b][k] == '#') {
            cnt ++;
          }
        }
      }

      if (cnt == K) {
        ans += 1;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <algorithm>

using namespace std;

int gcd (int a, int b)
{
    for (; b;)
    {
        a %= b;
        swap (a, b);
    }

    return a;
}

int main ()
{
   // freopen ("file.in", "r", stdin);

    int n, k;
    scanf ("%d %d", &n, &k);

    int ma = 0, cm;
    for (int i = 1; i <= n; ++i)
    {
        int x;
        scanf ("%d", &x);

        ma = max (ma, x);

        if (i == 1) cm = x;
        else cm = gcd (cm, x);
    }

    if (k <= ma && (k % cm == 0))
        printf ("POSSIBLE\n");

    else printf ("IMPOSSIBLE\n");

    return 0;
}


Measured memory_bytes: 128
import sys
readline = sys.stdin.readline

res = []
def fill(K, f):
    if K.count(-1) == 0:
        res.append(K)
        return 
    else:
        idx = []
        for i in range(N):
            if K[i] == -1:
                idx.append(i)
        kc = len(idx)
        for S in range(1, 1<<kc):
            if not S & 1:
                continue
            K2 = K[:]
            for j in range(kc):
                if S & (1<<j):
                    K2[idx[j]] = f
            fill(K2, f+1)
            
            
N = int(readline())
fill([-1]*N, 0)
res.sort()
res = [''.join(map(lambda x: chr(x+97), r)) for r in res]
print('\n'.join(res))


Measured memory_bytes: 93020
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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


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

    int res = 0;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                int index = 0;
                for(int x = 0; x < N; x++){
                    if(index == 0 && s[x] - '0' == i){
                        index++;
                    }
                    else if(index == 1 && s[x] - '0' == j){
                        index++;
                    }
                    else if(index == 2 && s[x] - '0' == k){
                        res++;
                        break;
                    }
                }
            }
        }
    }

    cout << res << endl;


    return 0;
}




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

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)2e5 + 7;
const int INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

int n, a[N];
int cnt[N];
int main (){
  scanf ("%d", &n);
  forn (i, 1, n) scanf ("%d", a + i), cnt[a[i]]++;
  int mx = 0;
  forn (i, 1, N - 1){
    mx = max(mx, cnt[i] + cnt[i - 1] + cnt[i + 1]);
  }
  printf ("%d\n", mx);
  return 0;
}


Measured memory_bytes: 1024
class cmbs(object):
    def __init__(self, mod=9007199254740997):
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 2 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)

    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)

    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v.sort(reverse=True)
    m = sum(v[:A])/A
    print(m)
    if v.count(v[A-1]) == N:
        c = cmbs()
        a = 0
        for i in range(A, B+1):
            a += c.cmb(N, i)
        print(a)
    elif v[0] == v[A-1]:
        c = cmbs()
        a = 0
        for i in range(A, min(v.count(v[A-1]), B) + 1):
            a += c.cmb(v.count(v[A-1]), i)
        print(a)
    elif v.count(v[A-1]) == 1:
        print(1)
    else:
        c = cmbs()
        r = A - v.index(v[A-1])
        print(c.cmb(v.count(v[A-1]), r))
main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int x, y, z;
  cin >> x >> y >> z;
  cout << (x - z) / (y + z) << endl;
}


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

using namespace std;

const int mod = 998244353;

int qpow(int base,int tms)
{
	int tmp = 1;
	while(tms)
	{
		if(tms & 1) tmp = tmp * 1ll * base % mod;
		base = base * 1ll * base % mod;
		tms >>= 1;
	}
	return tmp;
}

int dp[2][405][405][2];
int n;
int a[405],b[405];
int fact[405],inv[405];

int C(int n,int r)
{
	return fact[n] * 1ll * inv[r] % mod * inv[n - r] % mod;
}

int main()
{
	fact[0] = inv[0] = 1;
	for(int i = 1;i <= 400; ++ i)
		fact[i] = fact[i - 1] * 1ll * i % mod,
		inv[i] = qpow(fact[i],mod - 2);
	scanf("%d",&n);
	int su = 0,su2 = 0;
	for(int i = 1;i <= n; ++ i) scanf("%d%d",&a[i],&b[i]),su += a[i],su2 += b[i] - 1;
	int cur = 1,nxt = 0;
	dp[0][0][0][1] = 1;
	for(int i = 1;i <= n; ++ i)
	{
		cur ^= 1; nxt ^= 1;
		memset(dp[nxt],0,sizeof(dp[nxt]));
		for(int j = 0;j <= 1; ++ j)
		{
			for(int k = 0;k <= su2; ++ k)
				for(int l = 0;l <= su; ++ l)
					if(dp[cur][k][l][j])
					{
						dp[nxt][k][l][j] = (dp[nxt][k][l][j] + dp[cur][k][l][j]) % mod;
						for(int p = 0,pw = 1;p < b[i]; ++ p,pw = pw * 1ll * a[i] % mod)
							dp[nxt][k + p][l + a[i]][j ^ 1] = (dp[nxt][k + p][l + a[i]][j ^ 1] + dp[cur][k][l][j] * 1ll * inv[p] % mod * pw % mod) % mod;
					}
		}
	}
	int as = 0;
	for(int j = 0;j <= 1; ++ j)
	{
		int sgn = j ? mod - 1 : 1;
		for(int k = 0;k <= su2; ++ k)
			for(int l = 0;l <= su; ++ l)
				as = (as + dp[nxt][k][l][j] * 1ll * sgn % mod * su % mod * qpow(qpow(l,mod - 2),k + 1) % mod * fact[k] % mod) % mod;
	}
	printf("%d\n",as);
}

Measured memory_bytes: 6380
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long LL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int M = 1200000;
const int inf = 0x3f3f3f3f;
int main() {
	LL n,a,b;
	cin>>n>>a>>b;
	if(a>b) swap(a,b);
	LL ans;
	if((b-a)&1) {
		ans=min(a-1+(b-a+1)/2,n-b+(b-a+1)/2);
	}
	else ans=(b-a)/2;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double h,w,x,y;
	cin>>w>>h>>x>>y;
	cout<<w*h/2.0<<" ";
	if(2.0*x==w&&2.0*y==h)
	{
		cout<<"1";
	}
	else
	{
		cout<<"0";
	}
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	vector<int> cnt(9);
	for(int i = 0;i < N;i++) {
		if(vec.at(i) >= 3200) {
			cnt.at(8)++;
		}
		else {
			cnt.at(vec.at(i) / 400)++;
		}
	}
	int cn2 = 0;
	for(int i = 0;i < 8;i++) {
		if(cnt.at(i) != 0) {
			cn2++;
		}
	}
  	int eight = 8;
	if(cnt.at(8) == 0) {
		cout << cn2 << " " << cn2 << endl;
	}
	else {
		if(cn2 == 0) {
			cout << 1 << " " << cnt.at(8) << endl;
		}
		else {
			cout << cn2 << " " << cnt.at(8) + cn2 << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const double PI = 3.14159265358979323846264338327950;
const LL MOD = 1000000007;

#define PrintLn(X) cout << X << endl
#define Loop(n) for(int loop_ = n; loop_; --loop_)
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

int main(void)
{
	char s[100];
	scanf("%s", s);

	char ans[100] = "";
	Rep(i, strlen(s)){
		switch(s[i]){
			case '0': ans[strlen(ans)] = '0'; break;
			case '1': ans[strlen(ans)] = '1'; break;
			case 'B': if(strlen(ans)) ans[strlen(ans) - 1] = '\0'; break;
		}
	}
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define x first
#define y second
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //assert(freopen("input.txt","r",stdin));
    //assert(freopen("output.txt","w",stdout));
    int a[10];
    int i;
    for(i=1;i<=5;i++)
        cin>>a[i];
    for(i=1;i<=5;i++){
        if(a[i]!=i){
            cout<<i;
        }
    }
    return 0;
}

Measured memory_bytes: 3640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int count = 0;
            for (int i = 105; i <= n; i += 2) {
                int d = 0;
                for (int j = 1; j <= i; j++)
                    if (i % j == 0)
                        d += 1;
                if (d == 8)
                    count++;
            }
            out.println(count);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



Measured memory_bytes: 22100
// 参考: a5ua様
#include <bits/stdc++.h>
using namespace std;

int main () {

    int H, W;
    scanf("%d %d", &H, &W);

    int a[H][W];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            scanf("%d", &a[i][j]);
        }
    }

    vector<tuple<int, int, int, int>> ans;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (a[i][j] % 2 != 0) {
                a[i][j]--;
                if (j + 1 < W) {
                    a[i][j+1]++;
                    ans.emplace_back(i + 1, j + 1, i + 1, j + 2);
                }
                else if (i + 1 < H) {
                    a[i+1][j]++;
                    ans.emplace_back(i + 1, j + 1, i + 2, j + 1);
                }
            }
        }
    }

    printf("%d\n", (int)ans.size());
    for(auto &t : ans) {
        int y1, x1, y2, x2;
        tie(y1, x1, y2, x2) = t;

        printf("%d %d %d %d\n", y1, x1, y2, x2);
    }

    return 0;
}

Measured memory_bytes: 5104
N = int(input())
A = list(map(int, input().split()))

cash = 1000
stock = 0

for i in range(len(A)-1):
  next_trend = A[i+1] - A[i]
  price = A[i]
  
  
  if next_trend > 0 : #上がりするので最大限株へ
    n = cash//price
    cash, stock = cash - n*price, stock + n
  if next_trend < 0: #値下がりするので最大限現金化
    cash = cash + stock*price
    stock = 0
  #print(next_trend, price, cash,stock)

if stock:
  cash += stock*A[-1]
  
print(cash)
    

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back

const int maxv = 1e4 + 5;
const int inf = 0x3f3f3f3f;
int V, d[maxv], c[maxv], m, res;
struct edge {
    int to, dis, cost;
    bool operator>(const edge& o) const {
        if (dis == o.dis) return cost > o.cost;
        return dis > o.dis;
    }
};
vector<edge> g[maxv];

void dij(int s) {
    priority_queue<edge, vector<edge>, greater<edge> > que;
    inc(i, 1, V) d[i] = c[i] = inf;
    d[s] = c[s] = 0;
    que.push({s, 0, 0});
    while (!que.empty()) {
        edge p = que.top();
        que.pop();
        int v = p.to;
        if (d[v] < p.dis || (d[v] == p.dis && c[v] < p.cost)) continue;
        for (int i = 0; i < g[v].size(); i++) {
            edge e = g[v][i];
            if (d[e.to] > d[v] + e.dis ||
                (d[e.to] == d[v] + e.dis && c[e.to] > e.cost)) {
                d[e.to] = d[v] + e.dis;
                c[e.to] = e.cost;
                que.push({e.to, d[e.to], c[e.to]});
            }
        }
    }
}

int u, v, x, y;

int main() {
    while (scanf("%d %d", &V, &m) != EOF && V) {
        inc(i, 1, V) g[i].clear();
        inc(i, 1, m) {
            scanf("%d %d %d %d", &u, &v, &x, &y);
            g[u].pb({v, x, y});
            g[v].pb({u, x, y});
        }
        dij(1);
        res = 0;
        inc(i, 1, V) res += c[i];
        printf("%d\n", res);
    }
}


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

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

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template <typename P, typename Q>
ostream& operator<<(ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T> v)
{
  os << "(";
  each (i, v)
    os << i << ",";
  os << ")";
  return os;
}

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

  vector<int> a(3);
  while (cin >> a[0] >> a[1] >> a[2]) {
    sort(a.begin(), a.end());
    cout << (a[2] - a[1]) + (a[1] - a[0]) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
#include <cstdint>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
#define mod 1000000007
typedef long long ll;

unsigned gcd(int a, int b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}


ll comb(int n, int r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

int compare_char(const void* left, const void* right) {
	char *left_char = (char *)left;
	char *right_char = (char *)right;

	return strcmp(left_char, right_char);
}

int main(){

	ios::sync_with_stdio(false);
	cin.tie(0);

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	ll i, j, k, l, m, n, len, a, b, c;
	ll B, C, D, N, M, K,num_R,num_G,num_B, ans;
	ll sum = 0, sum_B = 0, sum_C = 0, max, min, count=0, W;
	ll **dp;
	char S[200000];


	
	cin >> N >> K;


	N = N % K;
	ll temp = abs(N - K);
	ans = std::min(N, temp);
	cout << ans << endl;

	return 0;


}
    

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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  
  int sum = (r * 100) + (g * 10) + b;

  if (sum % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)			// repeat reverse

#endif


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

	c -= (a - b);
	if (c <= 0)
		cout << 0;
	else
		cout << c;

	return 0;
}


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

#define N 101

class Stack {
public:
    void initialize();
    bool isEmpty();
    bool isFull();
    void push(const int);
    int pop();
    Stack(const int);
    ~Stack();
    
private:
    int top, STACKSIZE;
    vector<int> S;
};

void addition(Stack &s) {
    int a = s.pop(), b = s.pop();
    s.push(a+b);
}

void subtraction(Stack &s) {
    int a = s.pop(), b = s.pop();
    s.push(b - a);
}

void multiplication(Stack &s) {
    int a = s.pop(), b = s.pop();
    s.push(b * a);
}

int main() {
    Stack _s(N);
    char s[N];

    while(scanf("%s", s) != EOF) {
        if(s[0] == '+') {
            addition(_s);
        }

        else if(s[0] == '-') {
            subtraction(_s);
        }

        else if(s[0] == '*') {
            multiplication(_s);
        }

        else {
            _s.push(atoi(s));
        }
    }

    cout << _s.pop() << endl;

    return 0;
}

Stack::Stack(const int s) : top(0) {
    STACKSIZE = s;
    vector<int> tmp(STACKSIZE, 0);
    S = tmp;
}

Stack::~Stack() {
    //cout << "STACK DELETED" << endl;
}

void Stack::initialize() {
    top = 0;
}

bool Stack::isEmpty() {
    return (top == 0);
}

bool Stack::isFull() {
    return (top >= STACKSIZE-1);
}

void Stack::push(const int x) {
    if(isFull()) {
        cout << "Overflow!" << endl;
        exit(1);
    }

    top += 1;
    S[top] = x;
}

int Stack::pop() {
    if(isEmpty()) {
        cout << "Underflow" << endl;
        exit(2);
    }

    top -= 1;
    return (S[top+1]);
}


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

vector<int> card;
int ans;

bool adj(int x, int y){
    return (x%4 < 3 && (y-x == 1 || y-x == 5))
            || y-x == 4 || (x%4 && y-x == 3);
}

void dfs(){
    if( card.size() < ans ) ans = card.size();
    if( ans == 0 ) return;
    for(int i = 1; i <= 5; i++){
        vector<int> ind;
        for(int j = 0; j < card.size(); j++){
            if( card[j] == i ){
                ind.push_back(j);
            }
        }
        for(int j = 0; j < ind.size(); j++){
            for(int k = j+1; k < ind.size(); k++){
                int p1 = ind[j], p2 = ind[k];
                if( adj(p1, p2) ){
                    card.erase(card.begin() + p2);
                    card.erase(card.begin() + p1);
                    dfs();
                    card.insert(card.begin() + p1, i);
                    card.insert(card.begin() + p2, i);
                }
            }
        }
    }
}

int main(){
    int N;
    cin >> N;
    while( N-- > 0 ){
        card = vector<int>(0);
        ans = 100;
        for(int i = 0; i < 20; i++){
            int a;
            cin >> a;
            card.push_back(a);
        }
        dfs();
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>

using namespace std;

int main(){
  int n; cin>>n;
  int S[n+1];
  for(int i=0;i<n;i++){
    cin>>S[i];
  }
  int q; cin>>q;
  int sum=0;
  for(int i=0;i<q;i++){
    int t; cin>>t;
    int j=0;
    while(true){
      if(t==S[j]){
        if(j<n+1){
          sum++;
        }
        break;
      }
      j++;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3104
// ハッシュ法について
// http://takatakamanbou.hatenablog.com/entry/2015/04/11/155405

#include <stdio.h>
#include <string.h>

#define M 1046527 // 最大入力行数 1000000 だからか
#define NIL (-1)
#define L 14 // 文字列の長さが12だからか

//charの2次元配列について
// http://ratan.dyndns.info/MicrosoftVisualC++/tajigenchar.html
char H[M][L];

int getChar(char ch)
{
	if( ch == 'A' ) return 1;
	else if( ch == 'C' ) return 2;
	else if( ch == 'G' ) return 3;
	else if( ch == 'T' ) return 4;
	else return 0;
}

// long long int型
// https://www.wdic.org/w/TECH/long%20long
long long getKey(char str[])
{
	long long sum = 0, p = 1, i;
	for ( i = 0; i < strlen(str); i++) {
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for (i = 0;; i++)
	{
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h], str) == 0 ) return 1;
		else if( strlen(H[h]) == 0 ) return 0;
	}
	return 0;
}

int insert(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for (i = 0;; i++)
	{
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h], str) == 0 ) return 1;
		else if( strlen(H[h]) == 0 ) {
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main()
{
	int i, n, h;
	char str[L], com[9];
	// 初期化処理
	// https://teratail.com/questions/22786
	for( i = 0; i < M; i++ ) H[i][0] = '\0';
	scanf("%d", &n); // 入力行数
	for (i = 0; i < n; i++)
	{
		scanf("%s %s", com, str); // ex ) com ... insert str ... ACA
		if (com[0] == 'i') {
			insert(str);
		} else {
			if(find(str)) {
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 16980
character(10**5) S
character A
integer L,DP(0:12,0:1),kt(6)
read*,S;L=len_trim(S)
DP=0;DP(0,0)=1
kt=[1,10,9,12,3,4]
do i=1,L
  A=S(L-i+1:L-i+1);ikt=mod(i-1,6)+1
  if(A=="?")then
  do j=0,9
    do k=0,12
      jj=mod(j*kt(ikt)+k,13)
      DP(jj,1)=mod(DP(jj,1)+DP(k,0),10**9+7)
    end do
  end do
  else
    jj=(ichar(A)-48)*kt(ikt)
    do j=0,12
      DP(mod(jj+j,13),1)=DP(j,0)
    end do
  endif
  DP(:,0)=DP(:,1);DP(:,1)=0
end do
print"(i0)",DP(5,0)
end

Measured memory_bytes: 700
from collections import deque

N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9 + 7

P = [a for a in A if a >= 0]
N = [a for a in A if a < 0]

def canPositive():
    for i in range(0, len(N) + 1, 2):
        p = K - i
        if p < 0:
            break
        if len(P) >= p:
            return True
    return False

if not canPositive():
    A.sort(key=lambda a: abs(a))
    ans = 1
    for a in A[:K]:
        ans *= a
        ans %= MOD
    print(ans)
    exit()

if not P or not N or len(A) == K:
    A.sort(key=lambda a: abs(a), reverse=True)
    ans = 1
    for a in A[:K]:
        ans *= a
        ans %= MOD
    print(ans)
    exit()

P.sort(key=lambda a: abs(a))
N.sort(key=lambda a: abs(a))
P = deque(P)
N = deque(N)

ans = 1
sign = 1
while K > 0:
    ans %= MOD
    if ans == 0:
        break
    if K == 1:
        if sign < 0:
            ans *= N.pop()
        else:
            ans *= P.pop()
        break

    if len(P) >= 2 and len(N) >= 2:
        p = P[-1] * P[-2]
        n = N[-1] * N[-2]
        if p > n:
            ans *= P.pop()
            K -= 1
        else:
            ans *= N.pop() * N.pop()
            K -= 2
        continue
    if len(P) <= 1 or len(N) <= 1:
        if len(N) == 0:
            ans *= P.pop()
            K -= 1
            continue

        if len(P) == 0:
            ans *= N.pop()
            K -= 1
            sign *= -1
            continue

        if len(P) == len(N) == 1:
            ans *= P.pop() * N.pop()
            K -= 2
            sign *= -1
            continue

        if len(N) == 1:
            n = N.pop()
            if sign < 0:
                ans *= n
                K -= 1
                sign *= -1
            continue

        if len(P) == 1:
            p = P.pop()
            if K % 2 == 1 and sign > 0 or K % 2 == 0 and sign < 0:
                ans *= p
                K -= 1
            continue

print(ans % MOD)


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    char s[100003];
    Scs(s);
    char s1 = s[0];
    char s2 = s[1];
    if( s[0] == s[1] ){
        printf ("1 2\n");
        return 0;
    }
    int N = strlen(s);
    Repe(i,N,2){
        if( s[i] == s1 ){
            printf ("%d %d\n", i-1 , i+1);
            return 0;
        }
        if( s[i] == s2 ){
            printf ("%d %d\n", i , i+1);
            return 0;
        }
        s1 = s[i-1];
        s2 = s[i];
    }
    printf ("%d %d\n", -1, -1);

    return 0;
}



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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e9
#define MOD 1000000007

int main()
{

    ll n;
    cin >> n;
    double t, a;
    cin >> t >> a;
    vector<double> v;
    for(ll i = 0; i < n; i++)
    {

        double x;
        cin >> x;
        v.pb(x);
    }
    double mn = 1000000000.0;
    ll ans = 0;
    for(ll i = 0; i < n; i++)
    {

        double x = v[i];
        double y = t-x*.006;
        double j = abs(y-a);
        if(j < mn)
        {

            ans = i;
            mn= j;
        }
    }
    cout << ans+1;
}


Measured memory_bytes: 256
from collections import defaultdict

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

def main():
    num, l = map(int, input().split())
    data = [i + l for i in range(num)]

    ans = data[0]
    for i in range(num):
        if abs(ans) > abs(data[i]):
            ans = data[i]

    print(sum(data) - ans)



if __name__ == '__main__':
    main()



Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  ll N;
  cin>>N;
  ll a;
  ll ans = 0;
  ll temp = 0;
  for(int i = 0;i<N;i++){
    cin>>a;
    if(a != 0){
      temp += a;
    }
    else{
      ans += temp/2;
      temp = 0;
    }
  }
  ans += temp/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#define i(a,b) a=a<b?a:b
#define f(a) for(a=0;a++<n;)
d,a[101][101],b[101][101],u,v,c;main(n){scanf("%d%*d",&n);f(u)f(v)b[u][v]=1e8;for(;~scanf("%d%d%d",&u,&v,&c);a[u][v]=a[v][u]=b[u][v]=b[v][u]=c);f(c)f(u)f(v)i(b[u][v],b[u][c]+b[c][v]);f(u)f(v)d+=a[u][v]>b[u][v];printf("%d\n",d/2);}

Measured memory_bytes: 256
while True:
    n=input()
    if n==0:
        break
    a,b=[0,0]
    for i in range(n):
        ai,bi=map(int,raw_input().split())
        if ai>bi:
            a+=ai+bi
        elif ai<bi:
            b+=ai+bi
        else:
            a+=ai
            b+=bi
    print a,b

Measured memory_bytes: 4508
#include<cstdio>
int a[100+5],f[100+5];
int n,t=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		if(f[i])
			continue;
		if(a[i]==a[i+1])
		{
			f[i]=1;
			f[i+1]=1;
			t++;
		}
	}
	printf("%d\n",t);
	return 0;
}


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

int main(){
    int h,n;
    cin >> h >> n;
    vi a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];
    vector<ll> dp(300000,LINF);
    dp[0] = 0;
    ll ans = LINF;
    rep(j,h+10001){
        rep(i,n){
            if(j-a[i]>=0){
                dp[j] = min(dp[j],dp[j-a[i]] + b[i]);
                if(j>=h) ans = min(ans,dp[j]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int sz = 1001;

int n, m;
int xx1, yy1;
int xx2, yy2;
string grid[sz];
int used[sz][sz];

bool valid_point(int x, int y) {
	if (x >= 0 && x < n && y >= 0 && y < m && !used[x][y] && grid[x][y] != '#')
		return 1;
	return 0;
}

void bfs() {
	set<pair<int, pair<int, int>>> q;
	q.insert({ 1, {xx1, yy1} });
	while (q.size()) {
		pair<int, pair<int, int>> v = *q.begin();
		q.erase(q.begin());
		int x = v.second.first;
		int y = v.second.second;
		if (used[x][y])
			continue;

		used[x][y] = v.first;

		for (int i = -2; i <= 2; i++) {
			for (int j = -2; j <= 2; j++) {
				if (valid_point(x + i, y + j)) {
					q.insert({ used[x][y] + (abs(i) + abs(j) > 1 ? 1 : 0) , {x + i, y + j} });
				}
			}
		}
		
	}
}

void solve() {
	cin >> n >> m;
	cin >> xx1 >> yy1;
	cin >> xx2 >> yy2;
	xx1--;
	yy1--;
	xx2--;
	yy2--;
	for (int i = 0; i < n; i++)
		cin >> grid[i];
	
	bfs();

	if (used[xx2][yy2] == 0)
		cout << -1;
	else
		cout << used[xx2][yy2] - 1;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

Measured memory_bytes: 9476
# include <bits/stdc++.h>
# pragma GCC optimize("Ofast")
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define forn(i, n) for (int i = 0; i < int(n); i++)
# define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define fore(i, l, r) for (int i = int(l); i < int(r); i++)
# define in freopen("in.txt", "r", stdin)
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
 
using namespace std;
 
const ll INF = 1e18;
const int mod = 1e9 + 7;
const ll N = 1e3 + 7;
typedef vector < vector < ll > > matrix;

int main()
{
    speed;
    int n;
    cin >> n;
    vector < int > vc(n);
    forn(i, n) cin >> vc[i];
    sort(all(vc));
    int ans = 0;
    ford( i, n ) {
    	ford( j, i ) {
    		auto it = lower_bound(all(vc), vc[i] + vc[j]);
    		int dst = distance(it, vc.end());
    		ans += (n - 1 - i) - dst;
    	}
    }
    cout << ans;
    time;
}

Measured memory_bytes: 256