akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define mii map<int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define Loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define loop(n) for(int i = 0; i < n; i++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#define vec vector
#define mod 1000000007
#define all(x) x.begin(), x.end()

int n;
int heights[100005];
int dp[100005];

void solve_itr(){
    cin >> n;
    loop(n) cin >> heights[i+1];
    dp[n] = 0;
    dp[n-1] = abs(heights[n] - heights[n-1]);
    for(int i = n-2; i > 0; i--){
        dp[i] = min(
            dp[i+1] + abs(heights[i] - heights[i+1]), 
            dp[i+2] + abs(heights[i] - heights[i+2])
        );
    }

    
    cout << dp[1] << endl;
}

int go(int step){
    if(step > n) return INT_MAX;
    if(step == n) return 0;
    if(dp[step] == -1){
        dp[step] = min(
            abs(heights[step] - heights[step+1]) + go(step+1),
            abs(heights[step] - heights[step+2]) + go(step+2)
        );
    }
    return dp[step];
}

void solve_rec(){
    cin >> n;
    loop(n) cin >> heights[i+1];
    memset(dp, -1, sizeof(dp));
    cout << go(1) << endl;
}

int32_t main(){
    // solove_itr();
    solve_rec();
}

Measured memory_bytes: 7480
#include <iostream>
#include <climits>

using namespace std;

int main(int argc, char **argv)
{
        int n;
        cin >> n;
        int minr = INT_MAX, maxp = -INT_MAX;
        for (int i = 0; i < n; i++) {
                int r;
                cin >> r;
                if (i > 0)
                        maxp = max(r - minr, maxp);
                minr = min(r, minr);
        }
        cout << maxp << endl;
        return 0;
}

Measured memory_bytes: 1164
#include <iostream>

int main(){
  char c;
  std::cin>>c;
  switch(c){
      case 'A':
      std::cout<<'T';
      break;
      case 'T':
      std::cout<<'A';
      break;
      case 'C':
      std::cout<<'G';
      break;
      case 'G':
      std::cout<<'C';
      break;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

#define CMAX 26

void solve()
{
  ll D; cin >> D;
  vector<ll> c(CMAX + 1); rep1(i, CMAX) cin >> c[i];
  vector<vector<ll>> s(D + 1, vector<ll>(CMAX + 1));
  rep1(i, D) rep1(j, CMAX) cin >> s[i][j];
  vector<ll> last(CMAX + 1, 0);



  ll waight = 10000; 
  vector<ll> t(D + 1);
  //rep1(i, D) {cin >> t[i];}
  rep1(day, D) {
    ll id;
    ll smax = 0;
    ll lmin = INF;
    vector<ll> cpoint(CMAX + 1);
    rep1(ct, CMAX) {
      cpoint[ct] = (day - last[ct]) * waight * c[ct] + s[day][ct];
    }
    rep1(ct, CMAX) {
      if(cpoint[ct] > smax) {
	t[day] = ct;
	smax = cpoint[ct];
      }
    }
    last[t[day]] = day;
  }
  
  rep1(i, D) {
    cout << t[i] << "\n";
  }

  

  ll sat = 0;
  ll dis;
  for(ll day = 1; day <= D; day++) {
    sat += s[day][t[day]];
    last[t[day]] = day;
    dis = 0;
    rep1(i, CMAX) {
      dis += c[i] * (day - last[i]);
    }
    
    sat -= dis;

    //cerr << sat << endl;
  }
  cerr << waight << " " << sat << endl;
  
  
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3836
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        final long x  = scanner.nextLong();

        long div11 = x / 11;
        long res11 = x % 11;
        if(res11 == 0){
            System.out.println(div11*2);
        }
        else if(res11 <= 6){
            System.out.println(div11*2+1);
        }else{
            System.out.println(div11*2+2);
        }

    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const int MAXN = 100000 + 10;
int par[MAXN], cost[MAXN];

int find (int i) {
    if (i == par[i]) return i;
    return par[i] = find(par[i]);
}
void add (int i, int j) {
    int a = find(i);
    int b = find(j);
    if (cost[a] > cost[b]) {
        par[a] = b;
    }
    else par[b] = a;

}

int main() {
//    freopen("test.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m, a, b;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        par[i] = i;
        cin >> cost[i];

    }
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        add (a, b);
    }
    LL ret = 0;
    int tot = 0;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        if (par[i] == i) {
            ret += cost[i];
            tot++;
        }
        else v.push_back(cost[i]);
    }
    if (tot == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (v.size() < tot-2) {
        cout << "Impossible" << endl;
        return 0;
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < tot-2; i++) {
        ret += v[i];
    }
    cout << ret << endl;

    return 0;

}

Measured memory_bytes: 1660
#include <iostream>

using namespace std;



int main() {
	long long k = 9223372036854775806, n = 0;
	cin >> n;

	for (int i = 0; i < 5; i++) {
		long long tmp;
		cin >> tmp;

		if (tmp < k) k = tmp;
	}


	if (n % k != 0) n = n / k + 1;
	else        n = n / k;
	cout << n + 4 << endl;

	//system("pause");

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  int N, A, B;
  cin >> N >> A >> B;
  int ret = 0;
  rep(i,N){
    int t;
    cin >> t;
    if(A <= t && t < B){
      ;
    }else{
      ret++;
    }
  }
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  char cell[h][w];
  for(int i=0;i<h;i++){
    string s;
    cin>>s;
    for(int j=0;j<w;j++){
      cell[i][j]=s.at(j);
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int count=0;
      if(cell[i][j]=='.'){
        for(int k=-1;k<=1;k++){
          for(int l=-1;l<=1;l++){
              if(i+k<0||i+k>=h){continue;}
              else if(j+l<0||j+l>=w){continue;}
              else if(cell[i+k][j+l]=='#'){count++;}
          }
        }
        cell[i][j]=(char)(count+'0');
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<cell[i][j];
    }
    cout<<endl;
  }
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cerr << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

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, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const ll MOD = TEN(9) + 7;
const int MX = TEN(6);

ll inv[MX], fact[MX], ifact[MX];

void init() {
    inv[1] = 1;
    for (int i = 2; i < MX; ++i) {
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
    }
    fact[0] = ifact[0] = 1;
    for (int i = 1; i < MX; ++i) {
        fact[i] = fact[i-1] * i % MOD;
        ifact[i] = ifact[i-1] * inv[i] % MOD;
    }
}

ll comb(int n, int r) {
    if (n < 0 || r < 0 || r > n) return 0;
    return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}

ll solve_sub(int N, int M, int S, int r, int l) {
	ll v = 0;
	for (int i = 0; i <= N - M; ++i) {
		ll rem = S - (ll)r * M - (ll)(l + 1) * i;
		if (rem < 0) break;
		ll t = comb(rem + N, N);
		if (i % 2 == 1) {
			t *= -1;
		}

		t = t * comb(N - M, i) % MOD;
		if (t < 0) t += MOD;
		v = (v + t) % MOD;
	}
	v = v * comb(N, M) % MOD;
	return v;
}

ll solve(int N, int M, int S) {
	ll all = comb(S + N, N);
	ll ng = 0;

	for (int x = 1; (ll)x * M <= S; ++x) { //minimum of bigger part
		ll a = solve_sub(N, M, S, x, x-1) - solve_sub(N, M, S, x+1, x-1);
		ng = (ng + a) % MOD;
		if (ng < 0) ng += MOD;
	}

	return (all - ng + MOD) % MOD;
}

int main() {
	int N, M, L, R;
	cin >> N >> M >> L >> R;

	init();

	ll ans = (solve(N, M, R) - solve(N, M, L-1) + MOD) % MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 23680
R,G,B,N = map(int, input().split())
values = [R,G,B]
values.sort(reverse = True)
a,b,c = values
ans = 0
for i in range(N//a+1):
    p = N - a*i
    for j in range(p//b + 1):
        q = p - b*j
        if q%c == 0:
            ans += 1
print(ans)

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


int main() {

  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2];

  sort(v.begin(), v.end());
  
  cout << v[0] << " " << v[2] << endl;
  
  return 0;
}



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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	long long a, b, x;
	cin >> a >> b >> x;
	cout << (b / x) - (a / x) + !(a % x) << "\n";
}

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


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  ll x[N], y[N];
  FOR(i,0,N) cin >> x[i] >> y[i];
  ll ans = 4e18;
  // x方向2つの点
  FOR(i,0,N) {
    FOR(j,0,N) {
      if(i == j || x[i] >= x[j]) continue;
      // y方向2つの点
      FOR(k,0,N) {
        FOR(l,0,N) {
          if(k == l || y[k] <= y[l]) continue; 
          if(x[i] <= x[k] && x[j] >= x[k] && x[i] <= x[l] && x[j] >= x[l]) {
            if(y[i] <= y[k] && y[i] >= y[l] && y[j] <= y[k] && y[j] >= y[l]) {
              int cnt = 0;
              FOR(c,0,N) {
                if(x[c] >= x[i] && x[c] <= x[j] && y[c] <= y[k] && y[c] >= y[l]) cnt++;
              }
              if(cnt >= K) {
                ans = min(ans, (x[j] - x[i]) * (y[k] - y[l]));
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = solve <$> f >>= B.putStrLn
  where
    f = head <$> B.words <$> B.getLine

solve :: ByteString -> ByteString
solve bs
  | B.last bs == 's' = B.snoc (B.snoc bs 'e') 's'
  | otherwise = B.snoc bs 's'


Measured memory_bytes: 3696
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int N=510;
const char col[4]={'R','Y','G','B'};
int n,m,d;
int main(){
	scanf("%d%d%d",&n,&m,&d);
	for (int i=1;i<=n;puts(""),++i)
		for (int j=1;j<=m;++j){
			int x=(i+j)/d,y=(i-j+m)/d;
			putchar(col[  ((x&1)*2)|(y&1)  ]);
		}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> f(N, 0);
  for (int i = 0; i < N; i++) {
    for (int x = 1; x < 100; x++) {
      for (int y = x; y < 100; y++) {
        if (i+1 > x*x + y*y + x*y + x + y) {
          for (int z = y; z < 100; z++) {
            int tmp = x*x + y*y + z*z + x*y + y*z + z*x;
            if (tmp == i+1) {
              if (x == y || y == z) {
                if (x == z) f[i]++;
                else f[i] += 3;
              }
              else f[i] += 6;
            }
          }
        }
      }
    }
  }
  for (int i = 0; i < N; i++) cout << f[i] << endl;
}


Measured memory_bytes: 3500
import sys
a, b, c = map(int, input().split())
k = int(input())

def f(A,B,C):
    if A < B and B < C:
        return True
    else:
        return False

for i in range(1, k):
    if f(a, b*(2**i), c*(2**(k-i))):
        print('Yes')
        sys.exit()

if f(a,b*(2**k),c):
    print('Yes')
    sys.exit()

if f(a,b,c*(2**k)):
    print('Yes')
    sys.exit()

print('No')

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

typedef long long ll;

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

    int d,g;
    cin >> d >> g;
    vector<int> p(d),c(d);
    for(int i=0;i<d;i++) cin >> p[i] >> c[i];
    int ans = 1e9;
    for(int bit=0;bit<(1<<d);bit++){
        int score=0,num=0,unsolve_max=-1;
        for(int i=0;i<d;i++){
            if(bit & (1<<i)){
                score += 100*(i+1)*p[i]+c[i];
                num += p[i];
            }else{
                unsolve_max = i;
            }
        }
        if(score < g){
            int uku = 100*(unsolve_max+1);
            int need = (g-score+uku-1)/uku;
            if(need >= p[unsolve_max]) continue;
            num += need;
        }
        ans = min(ans,num);
    }
    cout << ans << endl;
    return 0;
}

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

k = 0
for i in range(N):
  if abs(A[i]) > abs(A[k]):
    k = i
ans = []
if A[k] > 0:
  for i in range(N):
    if i != k:
      A[i] += A[k]
      ans.append((k+1, i+1))
  for i in range(N-1):
    A[i+1] += A[i]
    ans.append((i+1, i+2))
else:
  for i in range(N):
    if i != k:
      A[i] += A[k]
      ans.append((k+1, i+1))
  for i in range(N-1)[::-1]:
    A[i] += A[i+1]
    ans.append((i+2, i+1))
print(len(ans))
for x, y in ans:
  print(str(x) + " " + str(y))


Measured memory_bytes: 3064
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for i in range(1, 2 ** 10):
    b, s = i, 0
    cnt = [0 for _ in range(N)]
    while b > 0:
        if b & 1:
            for j in range(N):
                cnt[j] += F[j][s]
        s += 1
        b >>= 1
    sub_ans = 0
    for j in range(N):
        sub_ans += P[j][cnt[j]]
    ans = max(ans, sub_ans)
print(ans)

Measured memory_bytes: 41840
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
  string s;
  cin>>s;
  int n=s.size();
  string ans="yes";
  for(int loop=0;loop<n;++loop){
    for(int loop2=loop+1;loop2<n;++loop2){
      if(s[loop]==s[loop2]){
        ans="no";
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int i,n,x;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        if(i%3==0){
            printf(" %d",i);
        }else{
            for(x = i;x > 0;x /= 10){ 
                if(x%10==3){
                    printf(" %d",i);
                    break;
                }
            }
        }
    }
    printf("\n");
    return 0; /*0?????????*/
}

Measured memory_bytes: 600
N = int(input())
counter = [[0 for _ in range(10)] for _ in range(10)]
for k in range(1, N+1):
  counter[k%10][int(str(k)[0])] += 1
ans = 0
for k in range(1, 10):
  for j in range(1, 10):
    ans += counter[k][j]*counter[j][k]
print(ans)

Measured memory_bytes: 9140
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long int llint;

llint ans;
llint N;
string S;

llint rs, gs, bs;

int main() {
	cin >> N;
	cin >> S;
	
	ans = 0;

	for (int i = 0; i < N; i++) {
		if (S[i] == 'R') { rs++; }
		else if(S[i] == 'G') { gs++; }
		else if(S[i] == 'B'){ bs++; }
	}
	//cout << rs << endl;
	//cout << gs << endl;
	//cout << bs << endl;
	ans = rs * gs * bs;
	/*cout << ans << endl;*/
	int d;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (S[i] == S[j]) {
				continue;
			}
			d = j - i + j;
			if (d >= N || S[d] == S[i] || S[d] == S[j]) {
				continue;
			}
			ans--;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        
        int N=sc.nextInt();
        int[] A=new int[N];
        for(int i=0;i<N;i++){
            A[i]=sc.nextInt();
        }
        
        int sum=Math.abs(A[N-1])+Math.abs(A[0]);
        for(int i=0;i<N-1;i++){
            sum+=Math.abs(A[i]-A[i+1]);
        }
        
        System.out.println(sum+Math.abs(A[1])-Math.abs(A[0])-Math.abs(A[1]-A[0]));
        for(int i=1;i<N-1;i++){
            int dis=0;
            dis=Math.abs(A[i+1]-A[i-1])-Math.abs(A[i]-A[i-1])-Math.abs(A[i+1]-A[i]);
            System.out.println(sum+dis);
        }
        System.out.println(sum+Math.abs(A[N-2])-Math.abs(A[N-1])-Math.abs(A[N-2]-A[N-1]));
    }
}

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

int main(){
    int k, ans = 1;
    cin >> k;
    if (k % 2 == 0 || k % 5 == 0){
        cout << "-1" << endl;
    } else {
        int r;
        r = 10 % k;
        int first = 7 % k;
        int now = first;
        while (now != 0){
            now = now * r + first;
            now = now % k;
            ++ans;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
namespace Solve
{
	const int MAXN=300005;
	int n,m,q;
	struct Point
	{
		int x,y;
		Point(int a=0,int b=0):
			x(a),y(b){}
		bool operator < (const Point &B) const
		{
			if(x==B.x) return y<B.y;
			return x<B.x;
		}
		bool operator == (const Point &B) const
		{
			return x==B.x && y==B.y;
		}
	}P[MAXN];
	int numx[MAXN],numy[MAXN];
	int mxx[MAXN],totx,mxy[MAXN],toty;
	map<Point,bool>mp;
	void work()
	{
		while(scanf("%d%d%d",&n,&m,&q)!=EOF)
		{
			for(int i=1;i<=q;i++)
				scanf("%d%d",&P[i].x,&P[i].y);
			memset(numx,0,sizeof(numx));
			memset(numy,0,sizeof(numy));
			totx=toty=0;
			for(int i=1;i<=q;i++)
				numx[P[i].x]++,numy[P[i].y]++;
			mxx[++totx]=1;
			for(int x=2;x<=300000;x++)
			{
				if(numx[x]>numx[mxx[totx]])
				{
					totx=0;mxx[++totx]=x;
				}
				else if(numx[x]==numx[mxx[totx]])
				{
					mxx[++totx]=x;
				}
			}
			mxy[++toty]=1;
			for(int y=2;y<=300000;y++)
			{
				if(numy[y]>numy[mxy[toty]])
				{
					toty=0;mxy[++toty]=y;
				}
				else if(numy[y]==numy[mxy[toty]])
				{
					mxy[++toty]=y;
				}
			}
			bool fd=false;
			for(int i=1;i<=q;i++)
				mp[P[i]]=true;
			for(int tx=1;tx<=totx;tx++)
			{
				for(int ty=1;ty<=toty;ty++)
				{
					int jud=mp.count(Point(mxx[tx],mxy[ty]));
					if(!jud){fd=true;break;}
				}
			}
			//printf("%d\n",numx[mxx[totx]]+numy[mxy[toty]]);
			if(fd) printf("%d\n",numx[mxx[totx]]+numy[mxy[toty]]);
			else printf("%d\n",numx[mxx[totx]]+numy[mxy[toty]]-1);
			mp.clear();
		}
		return;
	}
}
int main()
{
	#ifdef LOCAL
	freopen("00test.in","r",stdin);
	freopen("00test.out","w",stdout);
	#endif
	Solve::work(); 
	return 0;
}

Measured memory_bytes: 29492
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,ko;
    ll x,y,w,z;
    char hoge,fuga;
    cin>>str;
    if(str[0]=='1')sum++;
    if(str[1]=='1')sum++;
    if(str[2]=='1')sum++;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
using namespace std;
int main()
{
    LL r,d,x;
    scanf("%lld%lld%lld",&r,&d,&x);
    LL ans=x;
    for(int i=1;i<=10;i++){
        ans=r*ans-d;
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}
fn main() {
    input!{
        i: f32
    }
    let p = std::f32::consts::PI;
    println!("{}", i * 2.0 * p);
}


Measured memory_bytes: 2232
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int ans;
int n;
vector<int> a;
bool dp[1000005];

int main(void) {
    cin >> n;
    rep(i, 0, n) {
        int t;
        cin >> t;
        a.pb(t);
    }
    sort(all(a));

    rep(i, 0, n) {
        int t = a[i];
        if (!dp[t]) {
            for (int j=t; j<1000005; j += t) {
                dp[j] = true;
            }
            if (i<n-1 && t==a[i+1]) continue;
            ans++;
        }
        
    }

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



Measured memory_bytes: 5084
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
//const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

void chmin(ll& x, ll y) {
	x = min(x, y);
}

void chmax(ll& x, ll y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

ll a, b, k;

void solve() {
	cin >> k >> a >> b;
	if (b - a >= k - 1 || a % k > b % k || a % k == 0) cout << "OK" << endl;
	else cout << "NG" << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


Measured memory_bytes: 3124
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[200005];
void solve()
{
    int n;
    scanf("%d%s", &n, str);
    int cnt = 0;
    int curr0 = 0, curr1 = n;
    while (curr0<curr1) {
        while (curr0 < n && str[curr0]=='R') {
            curr0++;
            continue;
        }
        curr0++;
        while (curr1 > 0 && str[curr1-1] == 'W') {
            curr1--;
            continue;
        }
        curr1--;
        if (curr0 > curr1) {
            break;
        }
        cnt++;
    }
    printf("%d\n", cnt);

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 1928
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N;cin>>N;
  int c[550],s[550],f[550];
  for(int t=1;t<N;t++)cin>>c[t]>>s[t]>>f[t];

  for(int t=1;t<N;t++){
    int ans=s[t]+c[t];
    for(int k=t+1;k<N;k++){
      if(ans<=s[k]){
        ans=s[k];
      }else{
        if(ans%f[k]!=0)ans+=f[k]-ans%f[k];
      }

      ans+=c[k];
    }
    cout<<ans<<endl;
  }
  cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


struct LazySegmentTree {
  int N;
  vector<ll> node,lazy;
  vector<bool> delay;
  LazySegmentTree(int n_){
    N = 1; while (N < n_) N *= 2;
    node.assign(2*N-1, 0); // 暫定的な最小値
    lazy.assign(2*N-1, 0); // 一様に加えるやつ
    delay.assign(2*N-1, false); // 遅延しているかどうか
  }

  // 遅延評価
  void eval(int k,int l,int r){
    if (!delay[k]) return;
    node[k] += lazy[k];
    if (r-l > 1){
      // 葉ノードでなければlazyを伝播する
      lazy[2*k+1] += lazy[k]; delay[2*k+1] = true;
      lazy[2*k+2] += lazy[k]; delay[2*k+2] = true;
    }
    lazy[k] = 0; delay[k] = false;
  }

  // [a,b) に各々 x を加える。見ているノード k が [l,r)
  void add(int a,int b,ll x,int k=0,int l=0,int r=-1){
    if (r == -1) r = N;
    eval(k,l,r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b){
      lazy[k] += x; delay[k] = true;
      eval(k,l,r);
      return;
    }
    add(a, b, x, 2*k+1, l, (l+r)/2);
    add(a, b, x, 2*k+2, (l+r)/2, r);
    node[k] = min(node[2*k+1], node[2*k+2]);
  }

  // [a,b) の最小値を返す。見ているノード k が [l,r)
  ll getmin(int a,int b,int k=0,int l=0,int r=-1){
    if (r == -1) r = N;
    eval(k,l,r);
    if (b <= l || r <= a) return numeric_limits<ll>::max();
    if (a <= l && r <= b) return node[k];
    ll vl = getmin(a, b, 2*k+1, l, (l+r)/2);
    ll vr = getmin(a, b, 2*k+2, (l+r)/2, r);
    return min(vl,vr);
  }
};

int main() {
  int N,Q; cin >>N >>Q;
  LazySegmentTree lst(N);
  rep(qq, Q){
    int query; cin >>query;
    int s,t; cin >>s >>t; t++;
    if (query == 0){
      ll x; cin >>x;
      lst.add(s,t,x);
    }else{
      cout <<lst.getmin(s,t) <<endl;
    }
  }
}



Measured memory_bytes: 7128
#include<stdio.h>
#include<stdlib.h>
int main(){
  int i,j,k,key,hzi;
  int *hai;
  scanf("%d",&i);
  hai=(int *)malloc(sizeof(int));
  for(j=0;j<i;j++){
    scanf("%ld",&hai[j]);
  }
  for(j=0;j<i;j++){
     printf("%d",hai[j]);
     if(j!=i-1){
       printf(" ");
     }
  }
     printf("\n");
  for(j=1;j<i;j++){
    key=hai[j];
    hzi=j-1;
    while(hzi>=0 && hai[hzi]>=key){
      hai[hzi+1]=hai[hzi];
      hzi--;
    }
    hai[hzi+1]=key;
    for(k=0;k<i;k++){
     printf("%d",hai[k]);
     if(k!=i-1){
       printf(" ");
     }
    }
   printf("\n");
  }
  //free(hai);
return 0;
}




Measured memory_bytes: 2124
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 500, maxm = 110000;
int x[maxm], y[maxm];
int marks[maxn][maxn], lims[maxn][maxn];
bool al[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n, m;
    cin >> n >> m;
    forn(i, m) {
        cin >> x[i] >> y[i];
        --x[i]; --y[i];
    }
    
    forn(i, n) {
        //forn(j, n) marks[i][j] = 0;
        marks[i][i] = m;
        al[i] = 1;
        ford(j, m) {
            if (marks[i][x[j]] > marks[i][y[j]]) swap(x[j], y[j]);
            if (marks[i][x[j]] > 0) {
                al[i] = 0;
                break;
            }
            if (marks[i][y[j]] > 0) {
                marks[i][x[j]] = j;
            }
        }
        if (!al[i]) continue;
        forn(j, n) lims[i][j] = m;
        forn(j, m) {
            if (marks[i][x[j]] > marks[i][y[j]]) swap(x[j], y[j]);
            if (marks[i][x[j]] > j) {
                al[i] = 0;
                break;
            }
            if (marks[i][y[j]] > j) {
                uin(lims[i][x[j]], j);
            }
        }
    }

    int ans = 0;
    forn(i, n) forn(j, i) {
        if (!al[i] || !al[j]) continue;
        bool ok = true;
        forn(k, n) {
            int mark = max(marks[i][k], marks[j][k]);
            int lim = min(lims[i][k], lims[j][k]);
            ok &= mark <= lim;
        }
        if (ok) ++ans;
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> s(m, vector<ll>());
    vector<ll> p(m);
    rep(i, 0, m) {
        ll k;
        cin >> k;
        rep(j, 0, k) {
            ll ts;
            cin >> ts;
            ts--;
            s[i].push_back(ts);
        }
    }
    rep(i, 0, m) cin >> p[i];

    ll ans = 0;
    for(ll i = 0; i < 1LL<<n; i++) {
        bool ok = true;
        rep(j, 0, m) {
            ll cnt = 0;
            for(auto v : s[j]) {
                if (i & 1LL<<v) cnt++;
            }
            if(cnt % 2 != p[j]) ok &= false;
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def resolve():
    S = input()
    while len(S) >= 5:
        if S[-7:] == "dreamer":
            S = S[:-7]
        elif S[-6:] == "eraser":
            S = S[:-6]
        elif S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
        else:
            break
    print("YES" if len(S) == 0 else "NO")
resolve()

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

int main() {
  string a;
  cin >> a;
  int num = stoi(a);
  vector<int> data(4);
  data.at(0) = num / 1000;
  num %= 1000;
  data.at(1) = num / 100;
  num %= 100;
  data.at(2) = num / 10;
  data.at(3) = num % 10;
    
  for (int i = 0; i < 8; i++) {
    bitset<3> op(i);
    int sum = data.at(0);
    for (int j = 0; j < 3; j++) {
      if (op.test(j)) {
        sum += data.at(j + 1);
      }
      else {
        sum -= data.at(j + 1);
      }
    }
    if (sum == 7) {
      string s;
      s += to_string(data.at(0));
      for (int i = 0; i < 3; i++) {
        if (op.test(i)) {
          s += "+" + to_string(data.at(i + 1));
        }
        else {
          s += "-" + to_string(data.at(i + 1));
        }
      }
      s += "=7";
      cout << s << endl;
      break;
    }
  }    
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

d = Counter(D)
t = Counter(T)
for key, value in t.items():
    if d.get(key, 0) < value:
        print('NO')
        exit()
else:
    print('YES')

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

const int INF = 1e9 + 7;

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

    int h, w;
    cin >> h >> w;
    
    set<pair<int, int>> paths;
    multiset<int> lens;

    for (int i = 1; i <= w; i++) 
        paths.insert({i, i}), lens.insert(0);

    for (int i = 1; i <= h; i++) {
        int a, b;
        cin >> a >> b;
        b++;

        pair<int, int> to_insert_path = {0, 0};
        for (auto it = paths.lower_bound({a, 0}); it != paths.lower_bound({b, 0});) {
            auto path = *it;
            it = paths.erase(it);
            lens.erase(lens.find(path.first - path.second));
            if (to_insert_path.second < path.second)
            to_insert_path = {b, path.second};
        }

        if (to_insert_path != make_pair(0, 0)) {
            auto upper = paths.lower_bound({b, 0});
            if (to_insert_path.first <= w && !(upper != paths.end() && to_insert_path.first == upper->first)) {
                paths.insert(to_insert_path);
                lens.insert(to_insert_path.first - to_insert_path.second);
            }
        }

        // for (auto e : paths) {
        //     cout << e.first << "," << e.second << " ";
        // }
        // cout << endl;

        if (lens.empty()) cout << -1 << endl;
        else cout << i + *lens.begin() << endl;        
    }
}

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

int main(void)
{
  int i,n,val1[24],val2[24],N,E,W,S,U,D;

  cin>>U>>S>>E>>W>>N>>D;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>val1[i]>>val2[i];
    if(val1[i]==N&&val2[i]==E) cout<<D<<endl;
    if(val1[i]==W&&val2[i]==N) cout<<D<<endl;
    if(val1[i]==S&&val2[i]==W) cout<<D<<endl;
    if(val1[i]==E&&val2[i]==S) cout<<D<<endl;
    if(val1[i]==E&&val2[i]==N) cout<<U<<endl;
    if(val1[i]==N&&val2[i]==W) cout<<U<<endl;
    if(val1[i]==W&&val2[i]==S) cout<<U<<endl;
    if(val1[i]==S&&val2[i]==E) cout<<U<<endl;
    if(val1[i]==U&&val2[i]==E) cout<<N<<endl;
    if(val1[i]==E&&val2[i]==D) cout<<N<<endl;
    if(val1[i]==D&&val2[i]==W) cout<<N<<endl;
    if(val1[i]==W&&val2[i]==U) cout<<N<<endl;
    if(val1[i]==U&&val2[i]==W) cout<<S<<endl;
    if(val1[i]==W&&val2[i]==D) cout<<S<<endl;
    if(val1[i]==D&&val2[i]==E) cout<<S<<endl;
    if(val1[i]==E&&val2[i]==U) cout<<S<<endl;
    if(val1[i]==U&&val2[i]==S) cout<<E<<endl;
    if(val1[i]==S&&val2[i]==D) cout<<E<<endl;
    if(val1[i]==D&&val2[i]==N) cout<<E<<endl;
    if(val1[i]==N&&val2[i]==U) cout<<E<<endl;
    if(val1[i]==U&&val2[i]==N) cout<<W<<endl;
    if(val1[i]==N&&val2[i]==D) cout<<W<<endl;
    if(val1[i]==D&&val2[i]==S) cout<<W<<endl;
    if(val1[i]==S&&val2[i]==U) cout<<W<<endl;
  }
}


Measured memory_bytes: 1164
#c
x,k,d = map(int,input().split())

num = 0

x = abs(x)

if x//d <k:
    if (k-x//d)%2 == 0:
        num = (x%d)
    else:
        num = abs(x%d-d)
else:
    num = abs(x-d*k)

    
print(num)


Measured memory_bytes: 9164
import java.lang.reflect.Array;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int n = sc.nextInt();
        int total = 0;
        for(int i = 0; i < n; i++) {
            total += sc.nextInt();
        }
        if(a <= total) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e17);
constexpr ll MOD = (1e9+7);

int main() {
  ll n; cin >> n;
  vector<ll> a(3*n); REP(i,3*n) cin >> a[i];
  priority_queue<ll, vector<ll>, greater<ll>> Qs;
  priority_queue<ll> Qg;
  vector<ll> sumf(n+1,0);
  ll S = 0;
  REP(i,n) {
    S += a[i];
    Qs.push(a[i]);
  }
  sumf[0] = S;
  REP(k,n) {
    S += a[n+k]; Qs.push(a[n+k]);
    S -= Qs.top(); Qs.pop();
    sumf[k+1] = S;
  }
  vector<ll> sumb(n+1, 0);
  S = 0;
  REP(i,n) {
    S += a[3*n-1-i];
    Qg.push(a[3*n-1-i]);
  }
  sumb[n] = S;
  REP(k,n) {
    S += a[2*n-1-k]; Qg.push(a[2*n-1-k]);
    S -= Qg.top(); Qg.pop();
    sumb[n-1-k] = S;
  }
  ll res = -INF;
  REP(k,n+1) {
    chmax(res, sumf[k]-sumb[k]);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll X, K, D;
    while(cin>>X>>K>>D){
        X = abs(X);
        ll can = X/D; // tot moves to reach the min pos value near 0
        // deb(X, D, K, can);
        if(K<=can){
            cout<<(X-K*D)<<"\n";
        }else{
            ll mid = X-can*D;
            ll rem = K - can;
            ll ans = mid;
            if(rem&1){
                ans = min(abs(mid-D), mid + D);
            }
            cout<<ans<<"\n";
        }
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    char s[101];
    for(int i=0;i<n;i++) cin >> s[i];
    for(int i=0;i<n;i++){
        if(s[i]=='Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 256
S=input()[::-1]
N=len(S)
X=[0 for i in range(N+1)]
tmp=1
for i in range(N):
    X[i+1]=X[i]+(tmp*int(S[i]))
    X[i+1]%=2019
    tmp=tmp*10
    tmp%=2019
D=dict()
for i in range(N+1):
    if X[i] in D:
        D[X[i]]+=1
    else:
        D[X[i]]=1
ans=0
for k in D:
    i=D[k]
    ans+=(i*(i-1))//2
print(ans)

Measured memory_bytes: 16476
#include <stdio.h>
#include <limits.h>
#define inf INT_MAX
#define white 0
#define gray 1
#define black 1
#define nil -1

int arr[100][100];


int prim();

int n;

int main(){
  scanf("%d",&n);
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&arr[i][j]);
      // printf("%d ",arr[i][j]);
     
    }
    //  printf("\n");
  }
  printf("%d\n",prim());
  
  return 0;
}

int prim(){
  int d[100];
  int pi[100];
  int color[100];
  int i,j;
  for(i=0;i<n;i++){
    d[i]=inf;
    pi[i]=nil;
    color[i]=white;
  }
  d[0]=0;
  
  int mincost,cost=0;
  int u;
  
  while(1){
    u=nil;
    mincost=inf;
    for(i=0;i<n;i++){
      if(color[i]!=black&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }

    if(mincost==inf) break;
    
    color[u]=black;

    for(j=0;j<n;j++){
      if(color[j]!=black&&arr[u][j]<d[j]&&arr[u][j]!=-1){
	pi[j]=u;
	//printf("pi:%d\n",pi[j]);
	d[j]=arr[u][j];
      }
    }
    
 
  }
  for(i=0;i<n;i++){
      if(pi[i]!=nil)cost+=arr[i][pi[i]];
      //printf("cost:%d\n",cost);
    }
  return cost;
}




Measured memory_bytes: 2052
import java.util.*;                                                                                  

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] l = line.split(" ");
        int a = Integer.parseInt(l[0]);
        int b = Integer.parseInt(l[1]);

        int d = a / b;
        int r = a % b;
        double f = (double)a / b;
        System.out.println(d + " " + r + " " + String.format("%f", f));
    }   
}

Measured memory_bytes: 26284