akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <random>
using namespace std;

#define rep(i, N) for (int i=0; i<N; ++i)
#define llong long long

template <typename T, int size0>
void fill(T (&a)[size0], T value)
{
	fill_n(a, size0, value);
}
template <typename T, int size0, int size1>
void fill(T (&a)[size0][size1], T value)
{
	fill_n(a[0], size0 * size1, value);
}
template <typename T, int size0, int size1, int size2>
void fill(T (&a)[size0][size1][size2], T value)
{
	fill_n(a[0][0], size0 * size1 * size2, value);
}


const int MAX_N = 1e+5;
const int MAX_M = 1e+5;

int N;
int M;
pair<int, int> e[MAX_M];
int xi[MAX_N];
int ci[MAX_N];
int dp[MAX_N];

int solve(int i)
{
	if (dp[i] != -1) return dp[i];

	int max_path = 0;
	dp[i] = 0;
	rep(j, ci[i])
	{
		clog << e[xi[i] + j].first << ", " << e[xi[i] + j].second << endl;
		max_path = max(max_path, 1 + solve(e[xi[i] + j].second));
	}

	return dp[i] = max_path;
}

int main ()
{
	cin >> N >> M;
	rep(i, M)
	{
		cin >> e[i].first >> e[i].second;
		--e[i].first;
		--e[i].second;
	}

	sort(e, e+M);

	int prev = -1;
	rep(i, M)
	{
		for (int j=prev+1; j<=e[i].first; ++j)
		{
			xi[j] = i;
		}
		++ci[e[i].first];

		prev = e[i].first;
	}

	fill(dp, -1);

	int longest_path = 0;
	rep(i, N)
	{
		clog << "[" << i << "]" << endl;
		longest_path = max(longest_path, solve(i));
	}

	cout << longest_path << endl;

	return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    long long mod=1000000007;
    long long N,M;
    cin >> N>>M;
    vector<long long> a(M);
    for (long long i=0; i<M; i++) {
        cin>>a[i];
    }
    
    vector<long long> steps(N+1,1), dp(N+1,0);
    
    for (int i=0; i<M; i++) {
        steps[a[i]]=0;
    }
    
    
    long long ans=1;
    
    
    dp[0]=1;
    if (steps[1]==1) {
        dp[1]=1;
    }
    
    for (long long i=2; i<N+1; i++) {
        if (steps[i]==0) {
            dp[i]=0;
            
            if (steps[i-1]==0) {
                ans=0;
                break;
            }
        }
        else{
            dp[i]=(dp[i-1]+dp[i-2])%mod;
        }
    }
    
    ans=dp[N];
    
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#define INF 1e8
using namespace std;
#define ll long long

#define MAX 100020
int main(void){
    
ll a,b,k;
cin>>a>>b>>k;

if(a>=k){
    cout<<a-k<<" "<<b;
}else{
    k=k-a;
    cout<<0<<" ";
    if(b>=k){
        cout<<b-k;
    }else{
        cout<<0;
    }
}

}

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

c = abs(0 - A[0])
for i in range(1, N):
    c += abs(A[i - 1] - A[i])
c += abs(A[N - 1] - 0)
print(c - abs(0 - A[0]) - abs(A[0] - A[1]) + abs(0 - A[1]))
for i in range(1, N - 1):
    print(c - abs(A[i - 1] - A[i]) -
          abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]))
print(c - abs(A[N - 2] - A[N - 1]) - abs(A[N - 1] - 0) + abs(A[N - 2] - 0))


Measured memory_bytes: 14040
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)((n>>m)&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

ll n,m,ans;
ll x[1010],y[1010],z[1010];
ll q[1010];

int main(){
	scanf("%lld%lld",&n,&m);
	rep(i,0,n)scanf("%lld%lld%lld",x+i,y+i,z+i);
	rep(j,0,8){
		rep(i,0,n)q[i]=(bit(j,2)?x[i]:-x[i])+(bit(j,1)?y[i]:-y[i])+(bit(j,0)?z[i]:-z[i]);
		sortdown(q,n);
		ll temp=0;
		rep(i,0,m)temp+=q[i];
		ans=max(ans,temp);
	}
	printf("%lld\n",ans);
	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod=1000000007;
//head

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

    int n, k;
    cin >> n >> k;
    vector<bool> p(n+1,false);
    for(int i = 0; i < k; i++) {
        int s;
        cin >> s;
        for(int i = 0; i < s; i++) {
            int c;
            cin >> c;
            p[c]=true;
        }
    }
    int cnt = 0;
    for(bool e : p) {
        cnt += e;
    }
    cout << n - cnt << endl;
    return 0;
}


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

int n, k, s;
int main() {
	int i;
	cin >> n >> k >> s;
	for(i=0; i<k; i++) printf("%d ", s);
	for(; i<n; i++) printf("%d ", s<1e9 ? s+1 : 1);
	return 0;
}

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

using namespace std;

int H, W, K;
int cumsum[12][1010];

int CountWhite(int x1, int y1, int x2, int y2) {
  return cumsum[y2 + 1][x2 + 1] - cumsum[y2 + 1][x1] - cumsum[y1][x2 + 1] + cumsum[y1][x1];
}

int Count(const vector<int>& cuts, const vector<string>& S) {
  int x1 = 0;
  int x2 = 0;
  int count = 0;
  while (x2 < W) {
    int now = 0;
    for (int i = 0; i + 1 < cuts.size(); i++) {
      int y1 = cuts[i];
      int y2 = cuts[i + 1] - 1;
      now = max(now, CountWhite(x1, y1, x2, y2));
    }
    if (now > K) {
      if (x1 == x2) {
	return -1;
      } else {
	count++;
	x1 = x2;
      }
    } else {
      x2++;
    }
  }
  return count;
}

int main() {
  cin >> H >> W >> K;
  vector<string> S(H);
  for (int y = 0; y < H; y++) cin >> S[y];

  memset(cumsum, 0, sizeof(cumsum));
  for (int y = 0; y <= H; y++) {
    for (int x = 0; x <= W; x++) {
      int add = 0;
      if (y == H || x == W) add = 0;
      else add = (S[y][x] == '1') ? 1 : 0;
      cumsum[y + 1][x + 1] = cumsum[y + 1][x] + cumsum[y][x + 1] - cumsum[y][x] + add;
    }
  }

  int answer = numeric_limits<int>::max();
  for (int cut = 0; cut < (1 << H); cut++) {
    if ((cut & 1) == 0) continue;
    vector<int> cuts;
    for (int y = 0; y < H; y++) {
      if (cut & (1 << y)) {
	cuts.push_back(y);
      }
    }
    cuts.push_back(H);

    int max_cut = Count(cuts, S);
    if (max_cut != -1) {
      answer = min(answer, max_cut + (int)cuts.size() - 2);
    }
  }
  cout << answer << endl;

  return 0;
}


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

int main(void){
    int n, m;
    int l_max, l_tmp;
    int r_min, r_tmp;
    int res = 0;
    
    cin >> n >> m;
    
    l_max = 0;
    r_min = n;
    for (int i = 0; i < m; i++) {
        cin >> l_tmp >> r_tmp;
        l_max = max(l_max, l_tmp);
        r_min = min(r_min, r_tmp);
    }
    res = max(r_min - l_max + 1, res);
    cout << res << endl;
}


Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n, q;
	cin >> n >> q;
	vector<pair<int,int>> s;
	int dp[200002];
	for (int i = 0; i < 200002; i++) {
		dp[i] = 0;
	}

	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		if (b < a) { swap(a, b); }
		s.push_back(make_pair(a,b));
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < q; i++) {
		int a, b;
		cin >> a >> b;
		dp[a] += b;
	}

	for (int i = 0; i < n-1; i++) {
		dp[s[i].second] += dp[s[i].first];
	}

	for (int i = 1; i <= n; i++) {
		cout << dp[i] << " ";
	}

	cout << endl;


	return 0;
}

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


signed main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vi ni(n);
    rep(i, n) cin >> a[i];
    rep(i, n){
        while(a[i] % 2 == 0){
            ni[i]++;
            a[i] /= 2;
        }
    }
    ll ans = 0;
    rep(i, n){
        ans += ni[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 3644
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,c = map(int,ipt().split())
    d = [[int(i) for i in ipt().split()] for j in range(c)]
    cs = [[int(i) for i in ipt().split()] for j in range(n)]
    di = [defaultdict(int) for i in range(3)]
    for i in range(n):
        for j in range(n):
            di[(i+j)%3][cs[i][j]] += 1

    cost = [[0]*c for i in range(3)]
    for i in range(3):
        for j in range(c):
            sm = 0
            for k in range(c):
                sm += d[k][j]*di[i][k+1]
            cost[i][j] = sm

    cm = [[(ci,i) for i,ci in enumerate(cost[j])] for j in range(3)]
    cm[0].sort()
    cm[1].sort()
    cm[2].sort()
    mi = 10**18
    for i in range(3):
        for j in range(3):
            for k in range(3):
                nm = cm[0][i][0]+cm[1][j][0]+cm[2][k][0]
                if cm[0][i][1] != cm[1][j][1] != cm[2][k][1] != cm[0][i][1] and mi > nm:
                    mi = nm

    print(mi)


    return None

if __name__ == '__main__':
    main()


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  for(int i=0; i<n-1; ++i){
    if(s[i] == s[i+1]){
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
    if(i<n-2 && s[i] == s[i+2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 3752
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if((a%3==0)||(b%3==0)||((a+b) %3 == 0)){
      System.out.println("Possible");
    }else{
      System.out.println("Impossible");
    }
  }
}

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

int main(){
    int N; cin >> N;
    vector<int> B;
    int temp;
    for(int i = 0; i < N; i++){
        cin >> temp;
        B.push_back(temp);
    }
    int idx = 1;
    for(int i = 0; i < N; i++){
        if(B[i] == idx) idx += 1;
    }
    if(idx == 1) cout << -1 << endl;
    else cout << N - idx + 1 << endl;
}

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

int main() {
  int a, b, d, r;
  double f;
  cin >> a >> b;
  d = a / b;
  r = a % b;
  f = double(a) / double(b);
  cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int n,k; cin >> n >> k;

  if(n<k){
    cout << min(n,abs(n-k));
  }
  else{
    
    int x = n/k;

    if(n%k==0){
      cout << 0;
    }else{
      int a = x - 1;
      int b = x;
      int c = x + 1;
      vector<int> ans;
      ans.pb(abs(n - a*k));
      ans.pb(abs(n - b*k));
      ans.pb(abs(n - c*k));
      sort(all(ans));
      cout << ans[0];
    }
  }

  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N-M+1) :
    for j in range(N-M+1) :
        a = True
        for k in range(M) :
            for l in range(M) :
                if A[i+k][j+l] != B[k][l] :
                    a = False
                    break
                else :
                    continue
                break
        if a :
            print('Yes')
            exit()
                    
print('No')

Measured memory_bytes: 9060
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

string s;
int a, b, c, d;
string t[9];

int main(){
  while (cin >> s, s != "#"){
    cin >> a >> b >> c >> d, a--, b--, c--, d--;
    rep(i, 9) t[i] = "";
    int ii = 0;
    each(c, s){
      if (c == 'b') t[ii] += "b";
      if (isdigit(c)) t[ii] += string(c - '0', '.');
      if (c == '/') ii++;
    }
    ii++;
    t[a][b] = '.';
    t[c][d] = 'b';
    string res;
    rep(i, ii){
      int ct = 0;
      rep(j, t[i].size()){
        if (t[i][j] == '.') ct++;
        if (t[i][j] == 'b'){
          if (ct > 0){
            res += '0' + ct;
            ct = 0;
          }
          res += 'b';
        }
      }
      if (ct > 0) res += '0' + ct;
      if (i + 1 < ii) res += "/";
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 3168
import math
import numpy as np
N = int(input())
A = [int(_) for _ in input().split()]
B = [A[i] - i for i in range(N)]
B.sort()
C = np.array(B)
print(np.sum([abs(C[i]-C[math.floor(N/2)]) for i in range(N)]))

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

int N, M, L[100000], R[100000];

int main(){
    cin >> N >> M;
    int l = 1, r = N;
    for(int i = 0; i < M; i++){
        cin >> L[i] >> R[i];
        l = max(l, L[i]);
        r = min(r, R[i]);
    }
    cout << max(0, r - l + 1) << endl;
}


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

int main(){
  ll n,ans=0;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  reverse(a,a+n);
  for(int i=1;i<n;i++){
    ans+=a[i/2];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5144
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int X;
  cin>>X;
  bool prime[1000000];
  for(int i=0;i<1000000;++i) prime[i] = true;
  prime[0] = false;
  prime[1] = false;
  for(int i=2;i<1000000;++i) {
    if(prime[i]) {
      for(int j=2;i*j<1000000;++j) prime[i*j] = false;
    }
  }
  int ans;
  for(int i=X;i<1000000;++i) {
    if(prime[i]) {
      ans = i;
      break;
    }
  }
  cout<<ans<<endl;
}



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

int n;
vector<vector<P>> v;

bool judge(int bit){
    for (int i = 0; i < n; i++){
        if(!(bit & (1 << i)))
            continue;
        for(P xy : v[i]){
            int x = xy.first;
            int y = xy.second;
            if (y == 1 && !(bit & (1 << x)))
                return false;
            if(y==0 && (bit & (1 << x)))
                return false;
        }
    }
    return true;
}

int main(){
    cin >> n;
    v.resize(n);
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        v[i].resize(a);
        for (int j = 0; j < a; j++){
            cin >> v[i][j].first >> v[i][j].second;
            v[i][j].first--;
        }
    }
    int res = 0;
    for (int bit = 0; bit < (1 << n); bit++){
        if(judge(bit)){
            int count = 0;
            for (int i = 0; i < n; i++){
                if(bit & (1<<i))
                    count++;
            }
            res = max(res, count);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
r,s,p = map(int,input().split())
score_map = {'r':r, 's':s, 'p':p}
t = input()
history = [0] * n
score = 0
for i in range(n):
    opposite = t[i]
    if opposite == 'r':
        hand_win = 'p'
    elif opposite == 's':
        hand_win = 'r'
    else:
        hand_win = 's'

    if i + 1 <= k:
        score += score_map[hand_win]
        history[i] = hand_win
    else:
        if history[i-k] == hand_win:
            continue
        else:
            score += score_map[hand_win]
            history[i] = hand_win
print(score)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = -INF;
    for (ll x : {a, b}) {
        for (ll y : {c, d}) {
            ll t = x * y;
            cmax(ans, t);
        }
    }
    cout << ans << endl;
}


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

long long int N, C, d[3][33], D[33][33], E[3][33], c, i[3], a;

int main(){
    scanf("%lld%lld", &N, &C);
    for(int i = 0; i < C; ++i)
        for(int j = 0; j < C; ++j)scanf("%lld", D[i] + j);
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            scanf("%lld", &c);
            ++d[(i + j) % 3][c - 1];
        }
    }
    for(int I = 0; I < 3; ++I){
        for(int j = 0; j < C; ++j){
            for(int k = 0; k < C; ++k){
                E[I][j] += d[I][k] * D[k][j];
            }
        }
    }
    a = 124935826435924053;
    for(i[0] = 0; i[0] < C; ++i[0]){
        c = E[0][i[0]];
        for(i[1] = 0; i[1] < C; ++i[1]){
            if(i[0] == i[1])continue;
            c += E[1][i[1]];
            for(i[2] = 0; i[2] < C; ++i[2]){
                if(i[0] == i[2] || i[1] == i[2])continue;
                c += E[2][i[2]];
                a = min(a, c);
                c -= E[2][i[2]];
            }
            c -= E[1][i[1]];
        }
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 384
package main

import "fmt"

func main(){
	var n int
	fmt.Scan(&n)
	if n%10 == 2 || n%10 == 4 || n%10 == 5 || n%10 == 7 || n%10 == 9{
		fmt.Println("hon")
	} else if n%10 == 3 {
		fmt.Println("bon")
	} else {
		fmt.Println("pon")
	}
}


Measured memory_bytes: 1752
a = input().split()

t_h = int(a[0])
t_a = int(a[1])
a_h = int(a[2])
a_a = int(a[3])

i = 0

while True:
  #高橋ターン
  if(i%2==0):
    a_h = a_h - t_a
    if(a_h <= 0):
      print("Yes")
      break
  #青木ターン
  elif(i%2!=0):
    t_h = t_h - a_a
    if(t_h <= 0):
      print("No")
      break
  i = i + 1

Measured memory_bytes: 61744
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int t=0,i,n,k,c,s1,s2,s,e,o,j,a,b;
   cin>>k>>a>>b;
   for(i=a;i<=b;i++)
   {
       if(i%k==0)
       {
           t=1;
           break;
       }
   }
   if(t==1) puts("OK");
   else puts("NG");
}








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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e9

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1e9+7;
const int MAX_N=200001;

int main(){
	string s;
	cin>>s;
	int cnt=0;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]==s[i+1]){
			cnt++;
		}else{
			cnt=0;
		}
		if(cnt==2){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>

int main(){
    
    int n, d, x, a;
    int cnt = 0;

    std::cin >> n >> d >> x;

    for(size_t i = 0; i < n; i++){
        int day = 1;
        std::cin >> a;
        while(day <= d){
            day += a;
            cnt++;
        }
    }

    std::cout << cnt + x << std::endl;

    return 0;
}

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

int main() {
  int a,b,i,j,e;
  char d;
  cin>>a>>b;
  vector<int>c(b*2);
  for(i=0;i<b*2;i++)
  cin>>c.at(i);
  for(i=0;i<a;i++){
    e=0;
    for(j=0;j<b*2;j++){
      if(c.at(j)==i+1)
        e++;
    }
    cout<<e<<endl;
  }
}


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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int H,W;
	cin >> H >> W;
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	int ans[H][W];
	int it = 0;
	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			while(a[it] == 0) it++;
			int k = j;
			if(i&1) k = W-j-1;
			ans[i][k] = it;
			--a[it];
		}
	}
	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			cout << ans[i][j] + 1<< ' ';
		}
		cout << endl;
	}
}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

struct shi{int num,parent,year; ll id;};
bool cmp(shi a, shi b){
	return a.year < b.year;
}

bool cmp2(shi a, shi b){
	return a.num < b.num;
}

int main(void){
	int n,m,p,y;
	cin>>n>>m;
	vector<shi> ken[100004];
	rep(i,m){
		cin>>p>>y;
		shi s;
		s.num = i;
		s.parent = p;
		s.year = y;
		ken[p].push_back(s);
	}
	vector<shi> all;
	reps(i,n){
		sort(ken[i].begin(),ken[i].end(),cmp);
		rep(j,ken[i].size()){
			ken[i][j].id = ken[i][j].parent * (ll)1000000 + (j+1);
			all.push_back(ken[i][j]);
		}
	}
	sort(all.begin(),all.end(),cmp2);
	rep(i,m){
		cout<<setfill('0')<<setw(12)<<right<<all[i].id<<endl;
	}
	return 0;
}


Measured memory_bytes: 10484
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N; cin >> N;
	vector<int> X;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		X.push_back(a);
	}
	vector<int> Y(X);
	sort(Y.begin(), Y.end());
	int left = Y[N / 2 - 1];
	int right = Y[N / 2];

	// debug
	// cout << "left=" << left << endl;
	// cout << "right=" << right << endl;

	for (int i = 0; i < N; i++) {
		if (X[i] < right) cout << right << endl;
		else cout << left << endl;
	}
	//system("pause");
	return 0;

}

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

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;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
double dp[310][310][310];
bool memo[310][310][310];
int N;

double f(int x,int y, int z) {
  if(memo[x][y][z]) return dp[x][y][z];
  memo[x][y][z]=true;
  dp[x][y][z]=0;
  int s = x+y+z;
  if(x!=0) dp[x][y][z]+=f(x-1,y,z)*(x);
  if(y!=0) dp[x][y][z]+=f(x+1,y-1,z)*(y);
  if(z!=0) dp[x][y][z]+=f(x,y+1,z-1)*(z);
  dp[x][y][z]+=N;
  dp[x][y][z]/=s;
  return dp[x][y][z];
}

int main() {
  cin>>N;
  vector<int> v(3,0);
  for(int i = 0; i < N; i++){
    int x;
    cin>>x;
    v[x-1]++;
  }
  dp[0][0][0] = 0;
  memo[0][0][0] = true;
  cout<<fixed<<setprecision(10);
  cout<<f(v[0],v[1],v[2])<<endl;
}

Measured memory_bytes: 256256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	string a,b;
	bool flg;
	cin>>a>>b;
	flg=true;
	if(a=="H"){
		if(b=="D"){
			flg=false;
		}
	}
	else{
		if(b=="H"){
			flg=false;
		}
	}
	cout<<((flg)?"H":"D")<<endl;
	return 0;
}
	

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		sc.close();

		int area = (a + b) * h / 2;

		System.out.println(area);

	}

}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
const int mod = 1e9 + 7;


int main(){
    int n;
    cin >> n;
    int a;
    ll sum = 0;
    map<ll, ll> mp;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        sum += a;
        mp[a]++;
    }

    int q;
    cin >> q;
    int b, c;
    for (int i = 0; i < q; ++i) {
        cin >> b >> c;
        int num = mp[b];
        mp.erase(b);
        mp[c] += num;
        sum += (c - b) * num;
        cout << sum << endl;
    }
}

Measured memory_bytes: 7476
S = [i for i in input()]
T = [i for i in input()]
N = len(T)
ans = 10**10
for i in range(len(S)-N+1):
     X = S[i:i+N]
     a = N
     for j in range(N):
         if X[j] == T[j]:
             a -= 1
     ans = min(ans, a)
print(ans)

Measured memory_bytes: 9124
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

template<typename T>
struct SegmentTree {
private:
	int sz, n;
	vector<T> data;
	function<T(T, T)> f;
	T identity_element;
public:
	/* constructor */
	SegmentTree() {}
	SegmentTree(
		vector<T> v, // initial data
		T identity_element, // identity element
		function<T(T, T)> f // operation
	) {
		sz = v.size();
		n = 1; while (n < sz) n <<= 1;
		this->f = f;
		this->identity_element = identity_element;
		data.resize(2 * n - 1, identity_element);
		for (int i = 0; i < sz; ++i)
			data[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; --i)
			data[i] = f(data[2 * i + 1], data[2 * i + 2]);
	}
	/* update query */
	void update(int idx, const T val) {
		idx += n - 1;
		data[idx] = val;
		while (idx) {
			idx = (idx - 1) >> 1;
			data[idx] = f(data[2 * idx + 1], data[2 * idx + 2]);
		}
	}
	/* get query */
	T get(int left, int right, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		if (r <= left || right <= l) return identity_element;
		if (left <= l && r <= right) return data[k];
		T val_l = get(left, right, 2 * k + 1, l, (l + r) / 2);
		T val_r = get(left, right, 2 * k + 2, (l + r) / 2, r);
		return f(val_l, val_r);
	}
};

int N, x;
vector<int> a;
SegmentTree<int> rmq;
void input() {
	cin >> N >> x;
	a.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> a[i];
	vector<int> a_rep(2 * N);
	for (int i = 0; i < N; ++i)
		a_rep[i] = a_rep[i + N] = a[i];
	rmq = SegmentTree<int>(
		a_rep, (1 << 30),
		[](int p, int q) {
			return min(p, q);
		}
	);
}

ll solve(int k) {
	ll res = 0;
	res += (ll)k * x;
	for (int i = 0; i < N; ++i)
		res += rmq.get(i + N - k, i + N + 1);
	return res;
}

int main() {
	input();
	ll res = (1LL << 60);
	for (int k = 0; k < N; ++k)
		res = min(res, solve(k));
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 384
/* ex9_1
   bonbonc    */

#include <stdio.h> 
#include<stdlib.h>
#include<string.h>
#define SIZE 100
typedef struct{
    int size;//スタックの大きさ
    int count;//スタックの要素数
    char data[SIZE];//データを格納する配列
    char *top;//一番上の要素のポインタ
} stack;

void initialize_stack(stack *stk);//スタックを初期化する関数
void print_stack(stack *stk);//スタックの中身を出力する関数
void push(stack *stk,char token);//スタックに要素を追加する関数
char pop(stack *stk);//スタックから要素を取り出す関数

stack stk;

int main(void){
    int i=0;//ループ用変数
    char string[SIZE];//入力を受け取るchar配列

    initialize_stack(&stk);//スタックを初期化

    scanf("%s", string);//入力を受け取る
    for(i=0;i<strlen(string);i++){//stringを一文字ずつ見ていく
        if(string[i]=='0' || string[i]=='1'){//0か1ならスタックにプッシュ
            push(&stk,string[i]);
        }else if(string[i]=='B'){//Bならスタックから一文字pop、スタックがからの場合は何もしない
            if(stk.count>0){
                pop(&stk);
            }
        }
    }  
    print_stack(&stk);//stackの中身を出力
    printf("\n");
    return 0;
}

void initialize_stack(stack *stk){//スタックの初期化
    stk->count = 0;//要素数を0にする
    stk->size = SIZE;//スタックの大きさをSIZEにする
    stk->top = &(stk->data[SIZE]);//topを配列の末尾にする
}

void push(stack *stk,char token){//スタックにプッシュする
    if(stk->count>=stk->size){
        printf("Error: stack overflow.");//これ以上プッシュ出来ないとき終了する
        exit(1);
    }else{
        stk->top--;//topを配列の一つ手前にする
        *(stk->top)=token;//topにtokenを格納
        stk->count++;//要素数を1増やす
    }
    return;
}

char pop(stack *stk){
    char ret_char;//返す文字
    if(stk->count<=0){
        printf("Error: stack underflow");//返す文字が無いとき、終了
        exit(1);
    }else{
        ret_char = *(stk->top);//topの文字をret_charに代入
        stk->count--;//要素数を1減らす
        stk->top++;//topを1つ後ろにずらす
        return ret_char;//ret_charを返す
    }

}

void print_stack(stack *stk){
    int i=0,j=0;
    for(i=0;i<stk->count;i++){//要素数の数だけループを回す
        j = SIZE-i-1;//配列を後ろから参照するためのインデックスを準備
        putchar((stk->data[j]));//一文字ずつ出力する
    }
    return;
}

Measured memory_bytes: 1608
<?php

$sc = new Scanner();

$a = [];
$b = [];
$d = [];

$N = $sc->nextInt();

for($i = 0; $i < $N; $i++) {
    $a[] = $sc->nextInt();
}

$all_plus = true;
for($i = 0; $i < $N; $i++) {
    $b[] = $sc->nextInt();
    $d[] = $a[$i] - $b[$i];
    if ($d[$i] < 0) {
        $all_plus = false;
    }
}

if (array_sum($a) < array_sum($b)) {
    echo '-1' . PHP_EOL;
    exit;
}
if ($all_plus) {
    echo 0 . PHP_EOL;
    exit;
}
sort($d);
$cnt = 0;
$total = 0;
foreach($d as $v) {
    if ($v < 0) {
        $cnt++;
        $total += $v;
    } else {
        break;
    }
}

for($i = $N-1; $i > 0; $i--) {
    $total += $d[$i];
    $cnt++;
    if ($total >= 0)  {
        break;
    }
}
echo $cnt . PHP_EOL;

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}


Measured memory_bytes: 29292
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
#include <tuple>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
typedef tuple<double, int, int, int> T;
int n,m;
double best[30][30][31];
int dist[30][30];
int limit[30][30];
void exec()
{
	cin >> n >> m;
	if(n==0&&m==0){
		exit(0);
	}
	memset(dist,-1,sizeof(dist));
	memset(limit,-1,sizeof(limit));
	int start,goal;
	cin >> start >> goal;
	start--;
	goal--;
	for(int i=0;i<m;i++){
		int x,y,d,c;
		cin >> x >> y >> d >> c;
		x--;
		y--;
		dist[x][y]=dist[y][x]=d;
		limit[x][y]=limit[y][x]=c;
	}
	fill(best[0][0],best[0][0]+30*30*31,1e20);
	priority_queue<T, vector<T>, greater<T> > q;
	q.push(T(0,start,start,0));
	best[start][start][0]=0;
	while(q.size())
	{
		double t=get<0>(q.top());
		int f=get<1>(q.top());
		int p=get<2>(q.top());
		int s=get<3>(q.top());
		q.pop();
		if(t>best[start][start][s])continue;
		for(int i=0;i<n;i++){
			if(i==p)continue;
			for(int ss=max(s-1,1);ss<=min(s+1,limit[f][i]);ss++){
				assert(dist[f][i]>0);
				double tt=t+dist[f][i]/(double)ss;
				if(tt<best[i][f][ss]){
					best[i][f][ss]=tt;
					q.push(T(tt,i,f,ss));
				}
			}
		}
	}
	double ret=1e20;
	for(int i=0;i<n;i++)
	{
		ret=min(ret,best[goal][i][1]);
	}
	if(ret==1e20){
		cout << "unreachable" << endl;
	}
	else
	{
		cout << ret << endl;
	}
}

int main() {
	cout << setprecision(10);
	while(1)exec();
}

Measured memory_bytes: 1972
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    ll sm =0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sm += a[i];
    }
    ll p = (n*(n+1))/2;
    if(sm%p!=0){
        cout << "NO" << endl;
        return 0;
    }
    ll cnt = sm/p;
    bool flag = 0;
    ll sss = 0;
    for(int i=0;i<n;i++){
        ll s,t;
        if(i==n-1){
            s = a[n-1];
            t = a[0];
        }else{
            s = a[i];
            t = a[i+1];
        }
        if(s+cnt-t<0){
            flag = 1;
            break;
        }
        if((s+cnt-t)%n!=0){
            flag = 1;
            break;
        }else{
            sss += (s+cnt-t)/n;
        }
    }
    if(flag){
        cout <<"NO" << endl;
    }else{
        if(sss==cnt){
            cout <<"YES" << endl;
        }else{
            cout <<"NO" << endl;
        }
    }
    return 0;
}

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

int main(void){
  int i = 0;
  int result = 0;
  char str[8];
  char plus = '+';

  scanf("%s", str);
  for(int b=0; b<4; b++){
    if(str[b]==plus){
      i++;
    }else{
      i--;
    }
  }
  printf("%d",i);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int k;
  cin >> k;
  vector<ll> a;
  for(int i = 0; i < k; i++){
    ll x;
    cin >> x;
    a.pb(x);
  }
  if(a[k - 1] != 2){
    cout << -1 << endl;
    return 0;
  }
  ll ld = 2;
  ll rd = 3;
  for(int i = k - 2; i >= 0; i--){
    if(ld > rd){
      cout << - 1 << endl;
      return 0;
    }
    ld = ((ld + a[i] - 1) / a[i]) * a[i];
    rd = (rd / a[i]) * a[i] + a[i] - 1;
    if(ld > rd){
      cout << - 1 << endl;
      return 0;
    }
  }
  cout << ld << " " << rd << endl;
	return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#define N 300010
#define MOD 998244353
using namespace std;
typedef long long ll;
ll n,a,b,c;
ll P,Q[N];
ll extgcd(ll a,ll b,ll &x,ll &y) {
	if(b) {
		ll k=extgcd(b,a%b,x,y);
		ll t=x;x=y;
		y=t-a/b*y;
		return k;
	} else {
		x=1;y=0;
		return a;
	}
}
inline ll C(int x) {
	return P*Q[x]%MOD*Q[n-x]%MOD;
}
inline ll solve() {
	ll x,y,d,k,m;
	d=extgcd(a,b,x,y);
	if(c%d) return 0;
	k=c/d;x*=k;y*=k;
	if(y<0) {
		k=x;x=y;y=k;
		k=a;a=b;b=k;
	}
	k=b/d;
	m=(x-k+1)/k;
	x-=m*b/d,y+=m*a/d;
	P=Q[1]=1;
	for(int i=2;i<=n;++i) {
		P=P*i%MOD;
		Q[i]=(MOD-MOD/i)*Q[MOD%i]%MOD;
	}
	Q[0]=1;for(int i=2;i<=n;++i) Q[i]=Q[i]*Q[i-1]%MOD;
	ll ans=0;
	for(;x<=n&&y>=0;x+=b/d,y-=a/d) {
		if(y<=n) {
			ans+=C(x)*C(y);
			ans%=MOD;
		}
	}
	return ans;
}
int main() {
	cin>>n>>a>>b>>c;
	cout<<solve()<<endl;
	return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,k,c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<pair<ll,ll>> tmp;
    for(i = 0;i < n;++i){
        if(s.at(i) == 'o'){
            tmp.emplace_back(i,i + c);
        }
    }
    ll dame = 0;
    ll last = -1;
    map<pair<ll,ll>, ll> mp;
    for(i = 0;i < tmp.size();++i){
        if(tmp.at(i).first <= last) continue;
        last = tmp.at(i).second;
        ++dame;
        mp[tmp.at(i)] = 1;
    }
    if(dame > k){
        cout << endl;
        return 0;
    }
    ll usiro = 0;
    ll hazi = 1e9+7;
    vector<ll> ans;
    for(i = tmp.size()-1;i >= 0;--i){
        if(hazi <= tmp.at(i).second) continue;
        hazi = tmp.at(i).first;
        if(mp.count(tmp.at(i))) ans.push_back(tmp.at(i).first + 1);
        ++usiro;
        if(usiro == k){
            break;
        }
    }
    ll m = ans.size();
    for(i = 0;i < m;++i){
        cout << ans.at(m-1-i) << endl;
    }
    return 0;
}

Measured memory_bytes: 20976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
bool isvalid(int x,int y,int row,int col)
{
    if(x>=0&&y>=0&&x<row&&y<col)
    {
        return true;
    }
    return false;
}
int main()
{
    ll row,col;
    cin>>row>>col;
    vector<vector<char>> grid(row,vector<char>(col));
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cin>>grid[i][j];
        }
    }
    vector<vector<ll>> dp(row,vector<ll>(col));
    bool ta=true;
    for(int i=0;i<col;i++)
    {
        if(grid[0][i]=='.')
        {
            dp[0][i]=1;
        }
        else
        {
            break;
        }
    }
    for(int i=0;i<row;i++)
    {
        if(grid[i][0]=='.')
        {
            dp[i][0]=1;
        }
        else
        {
            break;
        }
    }
    for(int i=1;i<row;i++)
    {
        for(int j=1;j<col;j++)
        {
            if(grid[i][j]!='#')
            {
                if(isvalid(i-1,j,row,col))
                {
                    dp[i][j]=(dp[i][j]%mod+dp[i-1][j]%mod)%mod;
                }
                if(isvalid(i,j-1,row,col))
                {
                    dp[i][j]=(dp[i][j]%mod+dp[i][j-1]%mod)%mod;
                }
            }
        }
    }
    cout<<dp[row-1][col-1];
}

Measured memory_bytes: 9088
#include <iostream>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <sstream>
#include <cstdio>
#include <string>


using namespace std;
const int N=2e3+5;
int n,w[N],b[N],x;//w[x] 编号x的位置.
int dp[N][N],cw[N][N],cb[N][N];
int main()
{
    memset(cw,0,sizeof(cw));
    memset(cb,0,sizeof(cb));
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++)
    {
        char op[2];
        scanf("%s%d",op,&x);
        if(op[0]=='W')
            w[x]=i;
        else
            b[x]=i;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<i;j++)
            if(w[i]<w[j])
                cw[i][0]++;
        for(int j=1;j<=n;j++)
        {
            cw[i][j]=cw[i][j-1];
            if(w[i]<b[j])
                cw[i][j]++;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<i;j++)
            if(b[i]<b[j])
                cb[0][i]++;
        for(int j=1;j<=n;j++)
        {
            cb[j][i]=cb[j-1][i];
            if(b[i]<w[j])
                cb[j][i]++;
        }
    }
    int c1=0,c2=0;
    for(int i=1;i<=n;i++)
    {
        c1+=cw[i][0],c2+=cb[0][i];
        dp[i][0]=c1,dp[0][i]=c2;
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            dp[i][j]=min(dp[i-1][j]+cw[i][j],dp[i][j-1]+cb[i][j]);
    cout<<dp[n][n]<<'\n';
    return 0;
}


Measured memory_bytes: 50360
#include <stdio.h>
#define swap(type, x, y)  do{ type t = x; x = y; y = t; }while(0)

void quick(long array[], int left, int right){
  int pl = left, pr = right;
  long x = array[(pl + pr) / 2];
  do{
    while(array[pl] > x)  pl++;
    while(array[pr] < x)  pr--;
    if(pl <= pr){
      swap(long, array[pl], array[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(array, pl, right);
  if(pr > left)  quick(array, left, pr);
}

int main(){
  int n;  scanf("%d", &n);
  long a[300005];
  for(int i=1; i<=n*3; i++)
    scanf("%ld", a+i);
  quick(a, 1, n*3);
  long ans = 0;
  for(int i=n+1; i<=n*2; i++)
    ans += a[i];

  long anss = 0;
  for(int i=1; i<=n; i++)
    anss += a[i*2];

  // anss = anss>ans ? anss : ans;
  printf("%ld\n", anss);
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}




int main(){
  ll n;
  ll a[10010],b[10010],ans=0,c[10010];
  vector<ll> g[100010];
  bool reached[100010]={0};
  ll cnt=0;
  queue<ll> q;
  ll ansans[100010];

  cin >> n;

  FOR(i,n-1){
    cin >> a[i] >> b[i];
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  
  FOR(i,n){
    cin >> c[i];
    ans+=c[i];
  }
  sort(c,c+n);
  reverse(c,c+n);
  cout << ans-c[0] << endl;
  q.push(1);
  ansans[1]=c[0];
  cnt++;
  while(!q.empty()){
    
    
    
    for(auto i:g[q.front()]){
      if(!reached[i]){
        q.push(i);
        ansans[i]=c[cnt];
        cnt++;
      }
    }
    reached[q.front()]=1;
    q.pop();
  }
  FOR(i,n){
    cout << ansans[i+1] <<endl;
  }
  
  

  
}


Measured memory_bytes: 3584
import math
import pprint
import fractions
import collections
import itertools
from decimal import *
X,N=map(int,input().split())
p=list(map(int,input().split()))
n=len(p)
d={}
l=[i-1 for i in range(104)]
#print(l)
i=0
while i<n:
    for j in range(len(l)):
        if p[i]==l[j]:
            l.pop(j)
            break
    #print(l)
    #input()
    i=i+1
minim=float("inf")
l2=[]
for i in range(len(l)):
    if minim>abs(l[i]-X):
        minim=abs(l[i]-X)
        l2=[]
        l2.append(l[i])
    elif minim==abs(l[i]-X):
        l2.append(l[i])
#l2=list(l2)
#print(type(l2))
print(min(l2))



Measured memory_bytes: 72796
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b;
    cin >> a >> b;

    cout << max(a + b, max(a - b, a * b)) << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int n;
  cin>>n;
  double x,ans=0;
  string y;

  for(int i=0;i<n;i++)
  {
    cin>>x>>y;
    if(y=="JPY") ans+=x;
    else ans+=380000*x;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, A, B;
  // string op;
  cin >> N >> A >> B;
  if (N * A <= B)
  {
    cout << N * A << endl;
  }else
  {
    cout << B << endl;
  }
  
}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define pb  push_back
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
int n;
cin>>n;
string s[n];
int a[n],c=0;
FOR(i,n)
{
	cin>>s[i];
}
sort(s,s+n);
if(n==1)
{
	c++;
}
else
{
	FORA(i,0,n-2)
{   if(i<n-2)
{
	
	if(s[i]!=s[i+1])
	{
		c++;
	}
}
else
{
	if(s[i]!=s[i+1])
	{
		c+=2;
	}
		if(s[i]==s[i+1])
	{
		c+=1;
	}
}
	
}
}
cout<<c<<endl;

return  0;
}




Measured memory_bytes: 9896
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    int x; cin >> x;
    int a, b;
    cin >> a;
    cin >>b;
    x -= a;
    cout << x%b << endl;

}

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

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

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;

int main(){
	int n; cin >> n; int a[n], b[n];
	Rep(i, n){
		cin >> a[i];
		if(i > 0){
			a[i] += a[i-1];
		}
	}
	Rep(i, n){
		cin >> b[i];
		if(i > 0){
			b[i] += b[i-1];
		}
	}
	int ans = 0;
	Rep(i, n){
		if(i == 0){
			ans = max(ans, a[0] + b[n-1]);
		}else{
			ans = max(ans, a[i] + b[n-1] - b[i-1]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256