akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
long long int abs(long long int n)
{
	if (n < 0)
		n *= -1;
	return n;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	long long int a[200005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int sum[200005];
	sum[0] = 0;
	for (i = 0; i < n; i++)
		sum[i + 1] = sum[i] + a[i];
	long long int ans = 1000000000000000000;
	for (i = 1; i < n; i++)
		if (ans > abs(sum[i] - sum[n] + sum[i]))
			ans = abs(sum[i] + sum[i] - sum[n]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int nxt_in(){int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';return n?-x:x;}
#define in nxt_in()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "atcf16e"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

const int N=100010;

int n,q,it=1;
int a[N],b[N],base[N];
int sum[N*26],ed[N*26];
int nxt[N*26][26],cnt[N][26][26];
string s[N];

void add(int i,int j,const string&s){
    if(j==s.size()){
        ed[i]++;
        sum[i]++;
        return;
    }
    int t=s[j]-'a';
    if(!nxt[i][t]) nxt[i][t]=++it;
    add(nxt[i][t],j+1,s);
    sum[i]++;
}

int que(int i,int j,const string&s,int x){
    base[x]+=ed[i];
    if(j==s.size()) return 1;
    forinc(t,0,25) cnt[x][s[j]-'a'][t]+=sum[nxt[i][t]];
    que(nxt[i][s[j]-'a'],j+1,s,x);
}

main(){
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    fasty;
    cin>>n;
    forinc(i,1,n){
        cin>>s[i];
        add(1,0,s[i]);
    }
    forinc(i,1,n) que(1,0,s[i],i);
    cin>>q; while(q--){
        int x; cin>>x;
        forinc(i,0,25){
            char ch; cin>>ch; a[ch-'a']=i; b[i]=ch-'a';
        }
        int ret=0;
        forinc(i,0,25){
            forinc(j,0,a[i]-1){
                ret+=cnt[x][i][b[j]];
            }
        }
        cout<<ret+base[x]<<"\n";
    }
}



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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

ld A, B, H, M;

ld solve() {
    ld theta = H/12+M/60/12 - M/60;
    theta *= 2*M_PI;
    return sqrt(A*A + B*B - 2 * A*B*cos(theta));
}

int main() {
    cout << fixed << setprecision(15);
    cin >> A >> B >> H >> M;
    cout << solve() << endl;
}

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

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

    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    for (int i = n-1; i >= 0; i -= 2) {
        cout << a[i] << " ";
    }
    for (int i = n%2; i < n; i += 2) {
        cout << a[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int a[200010];
map<int, int> mp;
signed main()
{
    int n;
    cin >> n;
    REP(i, n)
        cin >> a[i];
    for (int i = 0; i < n; i++)
    {
        if(mp[a[i]]!=0){
            cout << "NO" << endl;
            return 0;
        }
        mp[a[i]]++;
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 14336
#include <iostream>
using namespace std;
#define MAX 100005
#define NILL -1

struct Node{ int p,l,r;};

Node T[MAX];
int n,D[MAX];

void print(int u){
  int i,c;

  cout << "node " << u <<": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if( T[u].p == NILL) cout << "root, ";
  else if( T[u].l == NILL ) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[" ;

  for( i = 0,c = T[u].l;c != NILL;i++,c = T[c].r ){
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

void rec(int u,int p){
  D[u] = p;
  if(T[u].r != NILL) rec(T[u].r, p);
  if(T[u].l != NILL) rec(T[u].l, p + 1);
}

int main(){
  int i,j,d,v,c,l,r;

  cin >> n;
  for(i = 0;i < n;i++) T[i].p=T[i].l=T[i].r=NILL;

  for(i = 0;i < n;i++){
    cin >> v >> d;
    for(j = 0;j < d;j++){
      cin >> c;
      if(j == 0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i = 0;i < n;i++){
    if(T[i].p == NILL) r = i;
  }

  rec(r,0);

  for(i = 0;i < n;i++) print(i);

  return 0;
}



Measured memory_bytes: 7768
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] S = sc.next().split("");
        int[] ans = new int[S.length];
        int count = 0;
        for (int i = 0; i < S.length-1; i++) {
            String now = S[i];
            String next = S[i+1];
            if (now.equals("R")) {
                count++;
            }
            if ((now+next).equals("RL")) {
                int rin = (count+1)/2;
                int lin = (count)-rin;
                ans[i] += rin;
                ans[i+1] += lin;
                count = 0;
            }
        }
        for (int i = S.length-1; 0 < i; i--) {
            String now = S[i];
            String next = S[i-1];
            if (now.equals("L")) {
                count++;
            }
            if ((next+now).equals("RL")) {
                int lin = (count+1)/2;
                int rin = (count)-lin;               
                ans[i] += lin;
                ans[i-1] += rin;
                count = 0;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i : ans) {
            sb.append(i+" ");
        }
        System.out.println(sb);
    }
}


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

int main() {
    vector<string> strs = {
        "SUN","MON","TUE","WED","THU","FRI","SAT"
    };
    string S;
    cin >> S;
    auto itr = strs.end() -  find(strs.begin(), strs.end(), S);
    cout << itr << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

#define fix(n) cout<<fixed<<setprecision(n);
#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // srand((unsigned)time(NULL));
  // fix(12)

  string s; cin >> s;
  ll q; cin >> q;
  s.reserve(q + 1);

  vector<string> left, right;
  
  bool rev = false;
  for (int i = 0; i < q; i++) {
    int t; cin >> t;

    if (t == 1) {
      rev = !rev;
    } else {
      int f; cin >> f;
      string c; cin >> c;

      if ((f == 1 && !rev) || (f == 2 && rev)) {
        left.push_back(c);
      } else {
        right.push_back(c);
      }
    }
    // outl(s)
  }

  reverse(left);
  ostringstream osLeft;
  copy(left.begin(), left.end(), ostream_iterator<std::string>(osLeft));

  ostringstream osRight;
  copy(right.begin(), right.end(), ostream_iterator<std::string>(osRight));

  s = osLeft.str() + s + osRight.str();

  if (rev) reverse(s);

  outl(s)
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

ll calc(ll x, ll N, ll K)
{
    return x * (-(N-1)) + (K - x);
}

ll func(ll diff, ll N, ll K)
{
    // -N * x + 1 * y = diff && x + y = K
    ll ok = K, ng = -1;
    while (ok - ng > 1) {
        // DUMP2(ok, ng);
        ll m = (ok + ng) / 2;
         (calc(m, N, K) <= diff ?  ok : ng) = m;
    }
    return ok;
}

void exit_no()
{
    cout << "NO" << endl;
    exit(0);
}

int main()
{
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<int> A(N), diff(N);
    ll sum = 0LL, sum_i = 0LL;
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
        sum_i += (i+1);
    }
    rep(i, N) diff[i] = A[(i+1)%N] - A[i];

    if (sum % sum_i != 0) exit_no();

    ll K = sum / sum_i;
    ll sum_k = 0LL;
    rep(i, N) {
        int k = func(diff[i], N, K);
        // DUMP2(diff[i], k);
        if (calc(k, N, K) != diff[i]) exit_no();
        sum_k += k;
    }

    // DUMP(sum_k);
    cout << (sum_k == K ? "YES" : "NO") << endl;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;


int main() {
#ifdef LOCAL
  assert(freopen("a.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  
  cout << (2 * k - 1 <= n ? "YES" : "NO") << "\n";

}



Measured memory_bytes: 256
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

N, A, B = l_inpl()
X = l_inpl()

ans = 0
for i in range(N-1):
    XA = (X[i+1] - X[i])*A
    if XA < B:
        ans += XA
    else:
        ans += B

print(ans)

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int h,w;
char field[55][55];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  cin >> h >> w ;
  rep(i,h){
    rep(j,w){
      cin>>field[i][j];
    }
  }
  
  rep(i,h){
    rep(j,w){
      if(field[i][j]=='.') continue;
      bool ok =false;
      rep(k,4){
        int nx=i+dx[k],ny=j+dy[k];
        if(0<=nx && nx<w && 0<=ny || ny<h ){
          if(field[nx][ny]=='#') ok=true;
        }
      }
      if(!ok){
          cout<<"No"<<endl;
          return 0;
      }      
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}
  



Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

t,x = I()
print(t/x)


Measured memory_bytes: 10196
#include <stdio.h>
int main(void){
    int a, b, c;
    1 <= a, b, c <= 10000;
    scanf("%d %d %d",&a, &b, &c);
    if(a < b && b < c)
         printf("%d %d %d\n",a, b, c);
    else if(a <= c && c <= b)
        printf("%d %d %d\n",a, c, b);
    else if(b <= a && a <= c)
        printf("%d %d %d\n",b, a, c);
    else if(b <= c && c <= a)
        printf("%d %d %d\n",b, c, a);
    else if(c <= a && a <= b)
        printf("%d %d %d\n",c, a, b);
    else if(c <= b && b <= a)
        printf("%d %d %d\n",c, b, a);
    return 0;
}



Measured memory_bytes: 2104
fun main(args: Array<String>) {
    val N = readLine()!!.toLong()
    for (n in 1..3500) {
        for (h in 1..3500) {
            val w = (N * n * h).toDouble() / (4 * n * h - N * h - N * n).toDouble()
            if (w - Math.floor(w) == 0.0 && w > 0) {
                println("$n $h ${w.toLong()}")
                return
            }
        }
    }
}

Measured memory_bytes: 31712
import sys
n = input()
data = list(map(int, sys.stdin.readline().split()))

ans = 1

over=False
zero=False

if 0 in data:
    zero=True

for num in data:
    ans*=num
    if(ans>1000000000000000000):
        over=True
        break

if ans>1000000000000000000:
    over=True

if zero:
    print("0")
elif over:
    print("-1")
else:
    print(ans)


Measured memory_bytes: 21596
#include <stdio.h>
#define DOT(v1, v2) (v1.x * v2.x + v1.y * v2.y)
#define CROSS(v1, v2) (v1.x * v2.y - v1.y * v2.x)
#define NORM(v) (v.x * v.x + v.y * v.y)

typedef struct { double x, y; } point_t;
typedef point_t vector_t;
typedef struct { point_t p0, p1; } segment_t;
typedef segment_t line_t;

static vector_t minus(vector_t v1, vector_t v2) {
  vector_t ret = { v1.x - v2.x, v1.y - v2.y };
  return ret;
}

static char *clockwise(segment_t s, point_t p) {
  vector_t a = minus(s.p1, s.p0);
  vector_t b = minus(p, s.p0);
  double c = CROSS(a, b);
  double d = DOT(a, b);
  double na = NORM(a);
  double nb = NORM(b);
  if (c > 0.0) return "COUNTER_CLOCKWISE";
  if (c < 0.0) return "CLOCKWISE";
  if (d < 0.0) return "ONLINE_BACK";
  if (nb > na) return "ONLINE_FRONT";
  return "ON_SEGMENT";
}

int main(int argc, char **argv) {
  int q, i;
  segment_t s;
  point_t p;

  scanf("%lf %lf %lf %lf", &s.p0.x, &s.p0.y, &s.p1.x, &s.p1.y);
  scanf("%d", &q);
  for (i = 0; i < q; ++i) {
    scanf("%lf %lf", &p.x, &p.y);
    printf("%s\n", clockwise(s, p));
  }
}


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

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

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

  if (a + b == 15) {
    cout << "+"
         << "\n";
  } else if (a * b == 15) {
    cout << "*"
         << "\n";
  } else {
    cout << "x"
         << "\n";
  }
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        a--;
        p[i] = a;
    }
    int index = 0;
    int count = 0;
    while (1)
    {
        if (index >= N - 1)
            break;
        if (p[index] != index)
            index++;
        else
        {
            swap(p[index], p[index + 1]);
            count++;
            index++;
        }
    }
    if (p[N - 1] == N - 1)
        count++;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_parityll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   ll a,b;
   cin>>a>>b;
   
   ll ans = inf;
   for(ll i=1;i<1000000;i++)
   {
       ld f1 = (ld)0.08 * i;
       ld f2 = (ld)0.10 * i;
       f1 = floor(f1);
       f2 = floor(f2);
       if(f1 == a && f2 == b)
       {
           cout<<i;
           return 0;
       }
   }
   cout<<-1;
   
   
   
   return 0;        
}  
   

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(int, H, W, A, B);
    auto ans = makeV(0, H, W);

    rep(i, 0, H) {
        rep(j, 0, W) {
            int num = (j < A);
            if (i < B) num = 1 - num;
            ans[i][j] = num;
        }
    }

    rep(i, 0, H) {
        rep(j, 0, W) cout << ans[i][j];
        print();
    }

    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(void){
    
    string S;
    cin >> S;
    string T = "AKIHABARA";
    int ptr = 0;
    string ans = "YES";
    for(int i = 0; i < T.size(); i++){
        //cout << T[i] << " "<< S[ptr] << endl;
        
        
        if(T[i] == S[ptr])ptr++;
        else if(T[i] == 'A') continue;
        else ans = "NO";
        
        
    }
    
    if(ptr != S.size())ans = "NO";
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int x, c, d;
    scanf("%d %d %d", &x, &c, &d);
    c = x - c;
    d = x - d;

    c = c*c;
   d =d*d;

   if(c<d)
    {
        printf("A");
    }
    else
    {
        printf("B");
    }

    return 0;
}

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

typedef long long ll;
typedef vector<ll> vi;

vi v;
int n;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    while(cin >> n)
    {
        v = vi(n);
        for(int i = 0; i < n; i++)
            cin >> v[i];

        ll x = 0, s = 0, l = 0, ans = 0;
        for(int i = 0; i < n; i++)
        {
            x ^= v[i]; s += v[i];
            if(x == s)
                ans += (i-l+1);
            else
            {
                while(x != s)
                {
                    x ^= v[l];
                    s -= v[l];
                    l++;
                }
                ans += i-l+1;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MOD 1000000007

typedef long long ll;

ll ctr[26];

int main(void)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	int n;
	std::cin>>n;
	std::string s;
	std::cin>>s;
	for(int i=0;i<n;i++)
	ctr[s[i] - 'a']++;
	ll ans = 1;
	for(int i=0;i<26;i++)
	ans = ((ans%MOD) * (((ctr[i]%MOD) + (1%MOD))%MOD))%MOD;
	ans = ((ans%MOD) - (1%MOD) + MOD)%MOD;
	std::cout<<ans<<"\n";
	return 0;	
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

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

    int ans = 0;
    for (int i=0; i<=a; i++) {
        for (int j=0; j<=b; j++) {
            int yen = 500*i + 100*j;
            if (yen > x) continue;
            if ((x-yen)/50 <= c) ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3132
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=[0]+list(map(int,input().split()))
for i in range(n):
	a[i+1]+=a[i]
for i in range(m):
	b[i+1]+=b[i]
from bisect import bisect_right
ans=0
for i in range(n+1):
	if k-a[i]>=0:
		r=bisect_right(b,k-a[i])
		ans=max(r+i-1,ans)
print(ans)


Measured memory_bytes: 39880
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

int main(){
	int n;
	scanf("%d", &n);
	int base, base_, cnt, cnt_, l, r, s, ans = 0, i, q, nxt, j;
	base = base_ = 10, cnt = cnt_ = l = r = s = 1;
	for(; l < 100000000; ++ l){
		while(s < n){
			if((++ r) == base)
				base *= 10, ++ cnt;
			s += cnt;
		}
		if(s == n && (++ ans) == MOD)
			ans = 0;
		s -= cnt_;
		if(l + 1 == base_)
			base_ *= 10, ++ cnt_;
	} base = base_ / 10;
	for(i = 9; i <= n; i = nxt + 1){
		q = n / i, nxt = n / q;
		for(j = i, r = n - q * j; j <= nxt; ++ j, r -= q, base = (base * 10LL) % MOD){
			if(r >= q) continue;
			cnt = (base * 9LL) % MOD;
			if(r == 0){
				ans = ans + cnt - q + 1;
				if(ans >= MOD) ans -= MOD;
				else if(ans < 0) ans += MOD;
			}
			ans = ans + (q - r - 1) / (j + 1) + bool(r);
			if(ans >= MOD) ans -= MOD;
		}
	} printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    /*while(n>0)
    {
        int sum=n%10;
        n/=10;
        if(sum==7)
        {
            c=1;break;
        }

    }*/
    if(a[0]=='7'||a[1]=='7'||a[2]=='7')
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3576
#include<iostream>
#include<string>
//#define TEST
using namespace std;
int main()
{
#ifdef TEST
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
int n;
cin>>n;
string s;
cin>>s;
int e[307272];
int cnt=0;
for(int i=0;i<n;i++)
    {
     if(s[i]=='E') cnt++;
     e[i]=cnt;
    }

int ans=10000000;
for(int i=0;i<n;i++)
    ans=min(ans,(i-e[i])+(cnt-e[i]+(s[i]=='E')));
cout<<ans;

return 0;
}

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

int main() {
  char c;
  cin >> c;
  if(c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def gcd(x,y):
  if x>y: x,y = y,x
  while x:
    x,y = y%x, x
  return y

def lcm(x,y):
  return x*y//gcd(x,y)

N = int(input())
ans = 1
for _ in range(N):
  ans = lcm(ans, int(input()))
print(ans)


Measured memory_bytes: 3060
package main

import (
	. "fmt"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	const m int = 1e9 + 7
	pow := func(x, n int) int {
		res := 1
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % m
			}
			x = x * x % m
		}
		return res
	}
	var n, k, s int
	Scan(&n, &k)
	ans := make([]int, k+1)
	for i := k; i > 0; i-- {
		v := pow(k/i, n)
		for j := 2 * i; j <= k; j += i {
			v -= ans[j]
		}
		ans[i] = v % m
		s += i * ans[i]
	}
	Print((s%m + m) % m)
}


Measured memory_bytes: 2584
/***

   Author : Md. Jashim Uddin
   From   : RMSTU

 ***/
#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     ll              long  long int
#define     fast            ios_base :: sync_with_stdio(false);cin.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)
#define     forn(i,n)       for(int i=1;i<=n;i++)
#define      mx               1000000
int main()
{
   map < string,int > m;
   string s;

    int n,c=0;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
         cin>>s;
      int tm =  m[s]++;
      if(tm==0)
      {
          c++;
      }
    }
    cout<<c<<endl;


    return 0;
}


Measured memory_bytes: 19156
H, W = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

L = [0] * 10

for i in range(10):
  L[i] = c[i][1]

for i in range(10):
  for j in range(10):
    if j == 1:
      continue
    for k in range(10):
      if L[j] + c[k][j] < L[k]:
        L[k] = L[j] + c[k][j]

ans = 0
for l in A:
  for x in l:
    if x != -1:
      ans += L[x]

print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	vector<string> s(a);
	for (int i = 0; i < a; i++) {
		cin >> s[i];
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < a; i++) {
		cout << s[i];
	}
}

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

int main() {
  string s,t;
  cin>>s>>t;
  int ans=10000;
  for (int i=0;i<s.length()-t.length()+1;i++){
    int cnt=0;
    for (int j=0;j<t.length();j++){
      if (s[i+j]!=t[j]) cnt++;
    }
    ans=min(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3184
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    s = input()
    if s[1]=='B':
        print("ARC")
    else:
        print("ABC")
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9040
fn main() {
    let n = read::<isize>();
    let mut sp: Vec<(String, isize)> = Vec::new();
    for _ in 0..n {
        let v = read_vec::<String>();
        sp.push((v[0].clone(), v[1].parse::<isize>().ok().unwrap()));
    }
    let mut v: Vec<_> = sp.into_iter().enumerate().collect();
    v.sort_by_key(|&(_, (ref a, b))| (a.clone(), -b));
    for (i, _) in v {
        println!("{}", i+1);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
n = int(input())
t,a = map(int, input().split())
h = map(int, input().split())
index = 0
minh = 100000
for e,i in enumerate(h):
    nowh = abs(a-(t-i*0.006))
    if minh > nowh:
        minh = nowh
        index = e
print(index+1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100000 + 10 ;
int main()
{
	int n;
	scanf("%d",&n);
	int a[maxn]={0};
	int max1=0;
	for(int i=0;i<n;i++)
	{
		int b;
		scanf("%d",&b);
		a[b-1]++;
		a[b]++;
		a[b+1]++;
	}
	for(int i=0;i<100000;i++)
	{
		if(max1<a[i])
		{
			max1=a[i];
		}
	}
	printf("%d\n",max1);
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	int a[N];
	f(i, N)a[i] = 0;
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	f(i, n){
		scanf("%d", &x);
		if (x % 2 == 1)v = false;
	}
	if(v)printf("second\n");
	else printf("first\n");


	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>
#include <math.h>
using namespace std;

#define ll long long

int main(){
    int N,Q;
    string S;
    cin >> N >> Q >> S;
    int l[Q],r[Q],ans[Q],d[N],count = 0;
    for(int i = 0;i < Q;i++)cin >> l[i] >> r[i];
    for(int i = 0;i < N - 1;i++){
        d[i] = count;
        if(S[i] == 'A' && S[i+1] == 'C')count++;
    }
    d[N-1] = count;
    for(int i = 0;i < Q;i++){
        ans[i] = d[r[i]-1] - d[l[i]-1];
    }
    for(int i = 0;i < Q;i++)cout << ans[i] << endl;
    return 0;
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

const int MAX_N=3005;
int n;
ll a[MAX_N],dp[MAX_N][MAX_N];
bool turn=true;

int main(){
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> a[i];
    dp[i][i]=a[i];
  }
  for(int i=1;i<n;++i){
    turn=!turn;
    for(int j=0;j+i<n;++j){
        int l=j,r=j+i;
        if(i==1){
            dp[l][r]=-abs(a[l]-a[r]);
            continue;
        }
        if(!turn){
            dp[l][r]=min(-a[l]+dp[l+1][r],-a[r]+dp[l][r-1]);
        }else{
            dp[l][r]=max(a[l]+dp[l+1][r],a[r]+dp[l][r-1]);
        }
    }
  }
  if(n%2==0){
    cout << -dp[0][n-1] << endl;
  }else{
   cout << dp[0][n-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 70016
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#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 all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , K , a[N] , b[N] , lft[N] , rgt[N];
ll s[N] , dpL[N] , dpR[N];
vi V;

struct SegmentTree{
  int n , a[N << 4];
  int Min(int c,int l,int r,int pos) {
    if(l==r) return a[c];
    else {
      int mid=(l+r)>>1;
      return min(a[c],pos<=mid?
          Min(c<<1,l,mid,pos):Min(c<<1|1,mid+1,r,pos));
    }
  }
  void modify(int c,int l,int r,int L,int R,int x) {
    if(L<=l&&r<=R) a[c]=x;
    else {
      int mid=(l+r)>>1;
      if(L<=mid) modify(c<<1,l,mid,L,R,x);
      if(R>mid) modify(c<<1|1,mid+1,r,L,R,x);
    }
  }
  int Min(int pos) {
    return Min(1,0,n-1,pos);
  }
  void modify(int L,int R,int x) {
    modify(1,0,n-1,L,R,x);
  }
  void init(int _n) {
    n = _n;
    memset(a,0x37,sizeof(a));
  }
}sgt;

int main(){
  scanf("%d%d",&n,&K);
  ll ans = 0;
  rep(i,1,n+1) {
    scanf("%d%d",a+i,b+i);
    ans += a[i] * 2;
    s[i] = s[i-1] + a[i];
    if(b[i] == 1) {
      if(a[i] * 2 > K)
        return puts("-1") , 0;
      lft[i] = (-2 * s[i] % K + K) % K;
      rgt[i] = (-2 * s[i-1] % K + K) % K;
      V.pb(lft[i]);
      V.pb(rgt[i]);
      V.pb((lft[i] + 1) % K);
      V.pb((rgt[i] - 1 + K) % K);
    }
  }
  sort(all(V));
  V.erase(unique(all(V)),V.end());
  rep(i,1,n+1) if(b[i] == 1){
    lft[i] = lower_bound(all(V),lft[i])-V.begin();
    rgt[i] = lower_bound(all(V),rgt[i])-V.begin();
  }
  sgt.init(sz(V));
  per(i,1,n+1) if(b[i] == 1){
    int x = sgt.Min(lft[i]);
    if(x > n) dpL[i] = 0;
    else dpL[i] = dpR[x] + (V[rgt[x]] - V[lft[i]] + K) % K;
    x = sgt.Min(rgt[i]);
    if(x > n) dpR[i] = 0;
    else dpR[i] = dpR[x] + (V[rgt[x]] - V[rgt[i]] + K) % K;
    int l = (lft[i] + 1) % sz(V);
    int r = (rgt[i] - 1 + sz(V)) % sz(V);
    if(l <= r) sgt.modify(l , r , i);
    else sgt.modify(0 , r , i) , sgt.modify(l , sz(V) - 1 , i);
  }
  ll ans2 = *min_element(b+1,b+1+n)==2?0:1ll<<62;
  sgt.init(sz(V));
  rep(i,1,n+1) if(b[i] == 1){
    int x = sgt.Min(lft[i]);
    if(x > n) ans2 = min(ans2 , dpL[i]);
    x = sgt.Min(rgt[i]);
    if(x > n) ans2 = min(ans2 , dpR[i]);
    int l = (lft[i] + 1) % sz(V);
    int r = (rgt[i] - 1 + sz(V)) % sz(V);
    if(l <= r) sgt.modify(l , r , 0);
    else sgt.modify(0 , r , 0) , sgt.modify(l , sz(V) - 1 , 0);
  }
  printf("%lld\n",ans + ans2);
  return 0;
}


Measured memory_bytes: 12144
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int word_convert( int one_word );

int main(void)
{
	char word[101];
	char sentence[101];
	int one_word;
	int pause;
	int word_cou = 0;
	int match_cou = 0;
	int word_len = 0;
	int len_cou;
	int total_match = 0;
	
	while( ( one_word = getchar() )!= '\n' )
	{
		word[word_cou] = word_convert(one_word);

		word_cou++;
	}
		
	word_len = word_cou;

	word_cou = 0;
	
	while( ( pause = getchar() ) != EOF)
	{
		if( pause != ' ' && pause != '\n')
		{
			sentence[word_cou] = word_convert(pause);
			word_cou++;
		}else
		{
			len_cou = 0;

			if( word_cou == word_len )	
			{
				for( len_cou = 0; len_cou < word_len; len_cou++ )
				{
					if( sentence[len_cou] == word[len_cou] )
					{
						match_cou++;
					}else
					{
						break;
					}

					if( match_cou == word_len )
					{
						total_match++;
					}
				}
				match_cou = 0;
			}
			word_cou = 0;
		}
	}
	
	printf( "%d\n", total_match );
	return 0;
}

int word_convert( int one_word )
{
	if( islower( one_word ) )
	{
		return one_word;
	}else
	{
		return tolower( one_word );
	}
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vb=vector<bool>;

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    
    int n,m;cin >> n >> m;
    vi like(m,0);
    rep(i,n){
        int k;cin >> k;
        rep(j,k) {
            int a;cin >> a;
            like[a-1]++; 
        }
    }
    
    int ans = 0;
    rep(i,m) 
        if(like[i]==n) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void){
    long long N, len, mini;
    scanf("%lld", &N);

    len = sqrt(N);

    mini = N  - 1;
    for(int i = 1; i <= len; i++){
        if(N % i == 0){
            mini = min(mini, i + (N / i) - 2);
        }
    }

    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, M = MI()
    if N == M:
        print("Yes")
    else:
        print("No")

    
if __name__ == "__main__":
	main()

Measured memory_bytes: 9188
#include<stdio.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;
string ch[1000];
int main()
{
    int n,l;
    cin>>n>>l;
    for(int i=0;i<n;i++)
       cin>>ch[i];
    sort(ch,ch+n);
    for(int i = 0;i<n;i++)
        cout<<ch[i];
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define N 200010
using namespace std;
typedef long long ll;
struct node
{
	int from,to,next;ll value;
}e[N];
int tot,st[N],vis[N];
int n,m,r,c,x,y;ll z,min1,min2,val[N];
void cut()
{
	puts("No");
	exit(0);
}
void add(int x,int y,ll z)
{
	e[++tot].to=y;
	e[tot].from=x;
	e[tot].value=z;
	e[tot].next=st[x];
	st[x]=tot;
}
void dfs(int now,ll p)
{
	if (vis[now])
	{
		if (p!=val[now])
			cut();
		return;
	}
	val[now]=p,vis[now]=1;
	if (now>=r)
		min2=min(min2,(ll)val[now]);
	else
		min1=min(min1,(ll)val[now]);
	for (int i=st[now];i;i=e[i].next)
		dfs(e[i].to,e[i].value-val[now]);
}
main()
{
	scanf("%d%d%d",&r,&c,&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d%lld",&x,&y,&z);x--,y--;
		add(x,y+r,z),add(y+r,x,z);
	}
	for (int i=0;i<r+c;i++)
		if (!vis[i])
		{
			min1=min2=1e18+10;
			dfs(i,0);
			if (min1+min2<0)
				cut();
		}
	puts("Yes");
}

Measured memory_bytes: 11136
package main
import "fmt"
func main() {
  var n int
  var s string
  var m,t,leftwest,righteast int
  fmt.Scan(&n)
  fmt.Scan(&s)
  leftwest,righteast = 0,0
  for i:=0;i<n;i++ {
    if s[i:i+1] == "E" { righteast++ }
  }
  m = n+1
  for i:=0;i<n;i++ {
    if s[i:i+1] == "E" { righteast-- }
    t = leftwest+righteast
    if m > t { m = t }
    if s[i:i+1] == "W" { leftwest++ }
  }
  fmt.Println(m)
}

Measured memory_bytes: 2432
// 参考: https://atcoder.jp/contests/abc158/submisscons/10628064
// paihuさんありがとうございました。

package main

import (
	"fmt"
)

func main() {
	var str []byte
	var psNum int

	fmt.Scan(&str)
	fmt.Scan(&psNum)

	var T, F int
	var addChar string
	var flontStr []byte = make([]byte, 0)
	var reverse bool = false

	for i := 0; i < psNum; i++ {
		fmt.Scan(&T)

		switch T {
		case 1:
			reverse = !reverse
		case 2:
			fmt.Scan(&F, &addChar)
			switch F {
			case 1:
				if reverse {
					str = append(str, addChar...)
				} else {
					flontStr = append(flontStr, addChar...)
				}
			case 2:
				if reverse {
					flontStr = append(flontStr, addChar...)
				} else {
					str = append(str, addChar...)
				}
			}
		}
	}

	flontStr = reverseSlice(flontStr)

	flontStr = append(flontStr, str...)

	if reverse {
		flontStr = reverseSlice(flontStr)
	}

	fmt.Println(string(flontStr))
}

// reverseSlice はbyte型のスライスを逆並びにして返す関数
func reverseSlice(tByte []byte) []byte {
	for i, j := 0, len(tByte)-1; i < j; i, j = i+1, j-1 {
		tByte[i], tByte[j] = tByte[j], tByte[i]
	}
	return tByte
}


Measured memory_bytes: 7552
#include<iostream>

using namespace std;

int main()
{
	int n, t, c[100], d[100], sum, a = 0;

	cin >> n;
	cin >> t;

	for (int i = 0; i < n; i++) {
		cin >> c[i];

		cin >> d[i];
	}

	sum = c[0];

	for (int i = 0; i < n; i++) {
		if (sum >= c[i]) {
			if (t >= d[i]) {
				sum = c[i];

				a = 1;
			}
		}
	}

	if (a == 0) {
		cout << "TLE" << endl;
	}
	else {
		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 123;
ll n, m, a[N], f[3][N];

void upd(int c, int x, ll y) {
	for (; x < m; x |= (x + 1))
		f[c][x] += y;
}

ll get(int c, int x) {
	ll res = 0;
	for (; x >= 0; x = (x & (x + 1)) - 1)
		res += f[c][x];
	return res;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> a[i], a[i]--;
	for (int i = 1; i <= n; i++) {
		if (a[i] < a[i - 1]) {
			ll need = (a[i - 1] - a[i] + m - 1) / m;
			a[i] += need * m;
		}
		if (i > 1) {
			int l = (a[i - 1] + 1) % m;
			int r = a[i] % m;
			int c = (a[i - 1] + 1) / m;
			if (l > r) {
				upd(0, l, a[i - 1] + 1);
				upd(1, l, 1);
				upd(2, l, c * m);
				l = 0;
				c++;
			}
			upd(0, l, a[i - 1] + 1);
			upd(1, l, 1);
			upd(2, l, c * m);
			upd(0, r + 1, -(a[i - 1] + 1));
			upd(1, r + 1, -1);
			upd(2, r + 1, -c * m);
		}
	}
	ll res = 1e18;
	for (int i = 0; i < m; i++) {
		ll s = get(0, i);
		ll num = get(1, i);
		ll c = get(2, i);
		res = min(res, (a[n] - a[1]) - (c + num * i - s));
	}
	cout << res;
}


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


int main() {
#ifndef ONLINE_JUDGE
	//for getting input from input.txt
	freopen("input.txt" , "r" , stdin) ;
	//for writing output to output.txt
	freopen("output.txt" , "w" , stdout) ;
#endif
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	long long n  ;
	cin >> n ;

	long long i = 2 ;
	long long cnt = 0 ;
	long long ans = 0 ;

	for (int i  = 2 ; i < 1000010 ; ++i) {
		int cnt = 0 ;
		while (n % i == 0)  {
			cnt++ ;
			n = n / i ;
		}
		for (int j = 1  ; j < 1000  ; ++j) {
			if (cnt < j) {
				break ;
			}
			ans++  ;
			cnt -= j  ;
		}
	}
	if (n > 1) {
		ans++ ;
	}
	cout << ans ;

}

Measured memory_bytes: 3652
N, M = map(int, input().split())
LR = [[int(i) for i in input().split()] for _ in range(M)]

minTemp = min(LR[0])
maxTemp = max(LR[0])
for i in range(M):
    if minTemp <= min(LR[i]):
        minTemp = min(LR[i])
    if max(LR[i]) <= maxTemp:
        maxTemp = max(LR[i])

count = 0
for i in range(minTemp, maxTemp + 1):
    count += 1
print(count)


Measured memory_bytes: 21156
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ia = new int[n];
        for(int i = 0; i < n; i++){
            ia[i] = sc.nextInt();
        }
        upheap(ia);
        heapsort(ia);
        long sum = 0;
        for(int i = 1; i < n; i++){
            sum += ia[i / 2];
        }
        System.out.println(sum);
        sc.close();
    }

    static void upheap(int[] a){
        for(int i = a.length / 2; i >= 0; i--){
            heapfy(a, i, a.length - 1);
        }
    }

    static void heapsort(int[] a){
        int len = a.length;
        for(int i = len - 1; i >= 0; i--){
            int tmp;
            tmp = a[0];
            a[0] = a[i];
            a[i] = tmp;
            heapfy(a, 0, i-1);
        }
    }

    static void heapfy(int[] a, int n, int l){
        int tmp;
        if(2 * n + 2 <= l){
            if(a[2*n+1] <= a[2*n+2]){
                if(a[n] <= a[2*n+1]){
                    return;
                } else {
                    tmp = a[2*n+1];
                    a[2*n+1] = a[n];
                    a[n] = tmp;
                    heapfy(a, 2*n+1, l);
                }
            } else {
                if(a[n] <= a[2*n+2]){
                    return;
                } else {
                    tmp = a[2*n+2];
                    a[2*n+2] = a[n];
                    a[n] = tmp;
                    heapfy(a, 2*n+2, l);
                }
            }
        } else if(2 * n + 1 <= l){
            if(a[n] <= a[2*n+1]){
                return;
            } else {
                tmp = a[2*n+1];
                a[2*n+1] = a[n];
                a[n] = tmp;
                heapfy(a, 2*n+1, l);
            }
        } else {
            return;
        }
    }
}

Measured memory_bytes: 60244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = int(j); i < (int)(n); i++)
#define repll(i, j, n) for (ll i = ll(j); i <= (ll)(n); i++)
#define repback(i, n, k) for (int i=int(n); i >= (int)(k); --i)
typedef long long ll;

int main() {
    ll L, R;
    cin >> L >> R;
    R = min(R, L+4038); //1...2019が2019周期で繰り返されるので、2019個だけ調べる
    ll ans = 2018; //mod2019の中で最大の数
    repll(i, L, R){
        repll(j, i+1, R){
            ll x = (i*j) % 2019;
            ans = min(ans, x);   //小さいほうを選択        
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;



int main()
{
	int n;
	cin >> n;
	n -= 1;
	vector<int> c(n), s(n), f(n);
	for (int i = 0; i < n; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}

	for (int i = 0; i < n; i++) {
		int t = s[i];
		for (int j = i; j < n-1; j++) {
			t += c[j];
			int temp = s[j+1];
			while (true) {
				if (temp >= t) {
					t = temp;
					break;
				}
				temp += f[j + 1];
			}
		}
		t += c[n - 1];
		cout << t << endl;
	}
	cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 256