akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

int n;
string s;
vector<pii> neg, pos;

void fail(){
    cout << "No\n";
    exit(0);
}

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

    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> ws >> s;

        int sum = 0, mn = 0;

        for(auto &k : s){
            if(k == '(') sum++;
            else sum--;

            mn = min(sum, mn);
        }

        if(sum >= 0) pos.emplace_back(-mn, sum);
        else neg.emplace_back(mn, sum);
    }

    sort(pos.begin(), pos.end());

    int st = 0;
    for(auto &k : pos){
        if(st - k.first < 0) fail();

        st += k.second;
    }

    sort(neg.begin(), neg.end(), [&] (pii a, pii b){
        return a.second - a.first > b.second - b.first;
    });

    for(auto &k : neg){
        if(st + k.first < 0) fail();

        st += k.second;
    }

    if(st != 0) fail();

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

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

const int INF=1234567;
int c[101][101];

int main()
{
    int D,N;
    int a[100],e[100],r[100];
    while(scanf(" %d %d", &D, &N),D)
    {
        rep(i,N) scanf(" %d %d %d", &a[i], &e[i], &r[i]);

        fill(c[0],c[101],INF);
        c[D][0]=0;
        queue<pi> que;
        que.push(pi(D,0));
        while(!que.empty())
        {
            pi v=que.front();
            que.pop();
            int rem=v.fi, ex=v.se;
            rep(i,N)
            {
                if(ex<r[i]) continue;

                int nr=max(0,rem-a[i]), ne=min(100,ex+e[i]);
                if(c[nr][ne] > c[rem][ex]+1)
                {
                    c[nr][ne] = c[rem][ex]+1;
                    que.push(pi(nr,ne));
                }
            }
        }

        int ans=INF;
        rep(i,101) ans=min(ans,c[0][i]);

        if(ans==INF) printf("NA\n");
        else printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int sum = 700;
  for(int i=0;i<3;i++){
    if(s[i] == 'o'){
    sum = sum + 100;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long int n;
    cin >> n;
    long long int A[n] = {0};
    long long int counter[n+1] = {0};
    for(int i = 0; i < n; i++){
        cin >> A[i];
        counter[A[i]] += 1;
    }
 
    long long int sum = 0;
    for(int i = 1; i <= n; i++){
        if(counter[i] > 1){
            long long int x = counter[i];
            sum += x * (x-1) / 2;
        }
    }
 
    for(int i = 0; i < n; i++){
        long long int a = counter[A[i]];
        if(a > 1){
            long long int x = sum - (a-1);
            cout << x << endl;
        }else{
            cout << sum << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())
#define SORTDESC(c) sort((c).begin(), (c).end(), greater<short>());
#define DEBUG

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef pair<long,long> pr;
typedef map<double,pr> mp;
typedef vector<short> vs;

short t, N;
long a,b;
vs cards;

int main(void){
	cin >> N;
    REP(i, N){
        cin >> t;
        cards.push_back(t);
    }
    sort(cards.begin(), cards.end(), greater<short>());
    REP(i, N){
        if (i % 2 == 0){
            a += cards[i];
        }
        else {
            b += cards[i];
        }
    }

    cout << a - b;
    
	return 0;
}

Measured memory_bytes: 256
s = int(input())
ans_list = [s]
i = 1
while 1:
    if ans_list[-1]%2 == 0:
        a = int(ans_list[-1]/2)
    else:
        a = 3 * ans_list[-1] + 1
    if a in ans_list:
        print(i+1)
        break
    else:
        ans_list.append(a)
        i += 1

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int>P;
 
int main() {
 string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='?'){
      if(i==s.size()-1){
        cout<<'D'<<endl;
      }
      else{
      cout<<'D';
      }
    }
    else{
      if(i==s.size()-1){
        cout<<s.at(i);
      }
      else{
      cout<<s.at(i);
      }
    }
  }
}

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

int a[6], b[6];

double check(double k) {
	double res = 0;
	for (int i=0;i<6;i++) {
		res+=max(k*a[i],(1-k)*b[i]);
	}
	return res;
}

int main() {
	for (int i=0;i<6;i++) scanf("%d",&a[i]);
	for (int i=0;i<6;i++) scanf("%d",&b[i]);
	double ans = 100;
	for (int i=0;i<6;i++) if (a[i]+b[i]) ans = min(ans,check(1.*b[i]/(a[i]+b[i])));
	printf("%1.9f\n",ans/100.);

	return 0;
}

Measured memory_bytes: 384
from operator import itemgetter

li = list(map(int, input().split()))
N = li[0]
M=li[1]
L = []
K=[]
for i in range(N):
    L.append([])
    

for i in range(M):
    li = list(map(int, input().split()))
    L[li[0] - 1].append([li[1], i])
    K.append(0)

for i in range(N):
        O = L[i]

        O.sort()
        for j in range(len(O)):
                K[O[j][1]]=str(i+1).zfill(6)+str(j+1).zfill(6)

for i in range(M):
        print(K[i])

Measured memory_bytes: 42824
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(c) c.begin(),c.end()



int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '7')
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No" ;

    return 0;
}


Measured memory_bytes: 3628
from sys import stdin
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義
N,K=list(map(int,(stdin.readline().strip().split())))
if N%K==0:print(0)
else:
    M=10**19
    while(True):
        M = N
        N=N%K
        if M==N:
            M = N
            N-=K
            if N<=0:
                if abs(N)<abs(M):
                    print(abs(N))
                    break
                else:
                    print(abs(M))
                    break

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
from itertools import product

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


COST = np.array([2, 5, 5, 4, 5, 6, 3, 7, 6])

N, M = ds_in()
A_list = np.array(ds_in())
A_cost = COST[A_list - 1]  # 0始まりで取得

min_cost = min(A_cost)
base_num = max(A_list[A_cost == min_cost])

if N % min_cost == 0:
    print(int(str(base_num) * (N//min_cost)))
    exit()

# 本数をmin_costのmodを考え、cost最小のものを記憶
mod_cost = {i: [-1, 10**6] for i in range(1, min_cost)}
for a, c in zip(A_list, A_cost):
    mod = c % min_cost
    if mod > 0:
        if c < mod_cost[mod][1]:
            mod_cost[mod][1] = c
            mod_cost[mod][0] = a
        elif c == mod_cost[mod][1]:
            mod_cost[mod][0] = max(a, mod_cost[mod][0])

# 存在しないmodは除く
for i in range(1, min_cost):
    if mod_cost[i][1] > 10:
        del mod_cost[i]

N_mod = N % min_cost
upper = []
for m in mod_cost.keys():
    upper.append([i for i in range(0, min_cost + 1)])


ans = []
for cand in product(*upper):
    if N_mod == sum(map(lambda x, y: x*y, mod_cost.keys(), cand)) % min_cost:
        temp_N = N
        num_list = []
        for x, y in zip(mod_cost.keys(), cand):
            num_list.extend([mod_cost[x][0]] * y)
            temp_N -= mod_cost[x][1] * y
        if temp_N >= 0:
            num_list.extend([base_num] * (temp_N // min_cost))
            num_list.sort()
            ans.append(int(''.join(map(str, num_list[::-1]))))

print(max(ans))


Measured memory_bytes: 14524
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

string str[100] = {};

int main(void) {

	lli L, N;
	cin >> N >> L;

	for (int i = 0; i < N; i++) {
		cin >> str[i];
	}

	sort(str,str+N);

	for (int i = 0; i < N; i++) {
		cout << str[i];
	}




	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
 int a,b,d,r;
 double f;
 scanf("%d %d",&a,&b);
 d=a/b;
 r=a%b;
 f=1.00000000000000*a/b;
 printf("%d %d %.14lf\n",d,r,f);
 return 0;
}

Measured memory_bytes: 1068
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;

ll ex_euclid(ll a, ll b, ll &x, ll &y){
  if (b == 0){
    x = 1;
    y = 0;
    return a;
  }
  ll d = ex_euclid(b, a%b, y, x);
  y -= a/b * x;
  return d;
}

ll modinv(ll a, ll p){
  ll x, y, d;
  d = ex_euclid(a, p, x, y);
  assert(d == 1);
  return ((x % MOD) + MOD) % MOD;
}

const int maxN = 4000;
ll fac[maxN], inv[maxN], finv[maxN];

// O(N) precomputation
void modnCk_init(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i=2; i<maxN; i++){
    fac[i] = fac[i-1] * i % MOD;
    //    inv[i] = modinv(i, MOD); // O(logN)
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD; // O(1)
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

// O(1) with O(N) precomputation
ll modnCk(int n, int k){
  if (k<0) return 0;
  if (n < k) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(int argc, const char * argv[]) {
  int N, K;
  cin >> N >> K;
  ll red, blue;
  int nb, kb, nr, kr;
  modnCk_init();
  for (int i=1; i<=K; i++){
    nb = K-1;
    kb = K-i;
    blue = modnCk(nb, kb);
    nr = N-K+1;
    kr = N-K-i+1;
    red = modnCk(nr, kr);
    cout << blue*red%MOD << endl;
  }
  
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#define f(X) for(c=0;c<X;c+=v[p++]);if(c-X)continue;
using namespace std;
main(){
    for(int n;cin>>n,n;){
        int v[50],s,p,c;
        for(s=0;s<n;s++){string t;cin>>t;v[s]=t.size();}
        for(s=p=0;;p=++s){f(5);f(7);f(5);f(7);f(7);cout<<s+1<<endl;break;}
    }
}

Measured memory_bytes: 1204
import copy

n = int(input())
P = list(map(int, input().split()))
P2 = copy.deepcopy(P)
P2.sort()

cnt = 0
for p, p2 in zip(P, P2):
    if p != p2:
        cnt += 1

if cnt == 0 or cnt == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2*1e18;
const ld PI=3.14159265358979323846;
int main()
{
    ll a,b;
    cin>>a>>b;
    cout<<a*b;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
    private static int countDigits(long x) {
        int result = 0;
        while (x > 0) {
            result++;
            x /= 10;
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int result = Integer.MAX_VALUE;
        for (long i = 1; i * i <= n; i++) {
            if (n % i > 0) {
                continue;
            }
            result = Math.min(result, Math.max(countDigits(i), countDigits(n / i)));
        }
        System.out.println(result);
    }
}

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

template <int MOD = 1000000007>
struct Mint{
    int x;

    Mint() : x(0) {}
    Mint(long long t){
        x = t % MOD;
        if(x < 0) x += MOD;
    }
    
    Mint pow(int n){
        Mint res(1), t(x);
        while(n > 0){
            if(n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint & operator += (Mint a){
        x += a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    
    Mint & operator -= (Mint a){
        x += MOD - a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }

    Mint & operator *= (Mint a){
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint & operator /= (Mint a){
        return (*this) *= a.inv();
    }

    Mint operator + (Mint a) const { return Mint(x) += a; }
    Mint operator - (Mint a) const { return Mint(x) -= a; }
    Mint operator * (Mint a) const { return Mint(x) *= a; }
    Mint operator / (Mint a) const { return Mint(x) /= a; }

    Mint operator - () const{ return Mint(-x); }

    bool operator == (const Mint a){ return x == a.x; }
    bool operator != (const Mint a){ return x != a.x; }
    bool operator < (const Mint a){ return x < a.x; }

    friend ostream & operator << (ostream & os, const Mint &a){
        return os << a.x;
    }

    friend istream & operator >> (istream & is, Mint &a){
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main(){
    int n;
    cin >> n;
    ll c[n];
    rep(i,n){
        cin >> c[i];
    }
    sort(c, c + n);
    reverse(c, c + n);
    Mint<> k = Mint<>(2).pow(n - 1);
    Mint<> ans = 0;
    rep(i,n){
        ans += k * Mint<>(c[i]);
        k += Mint<>(2).pow(n - 2);
    }
    cout << ans * Mint<>(2).pow(n) << endl;
    return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


const int MAXN = 200005;
int c[MAXN], seen[MAXN];
modint dp[MAXN];

void solve() {
    int N; cin >> N;
    dp[0] = 1;
    memset(seen, -1, sizeof(seen));
    rep(i, N) cin >> c[i];
    rep(i, N){
        dp[i+1] = dp[i];
        if(c[i] != c[i+1]){
            if(seen[c[i]] != -1){
                dp[i+1] = dp[i+1] + dp[seen[c[i]]+1];
            }
            seen[c[i]] = i;
        }
    }
    cout << dp[N].n << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
//#pragma GCC optimize(2)
using namespace std;
const int N=1e6+1;
const int M=1e9+7;
const double eps=1e-6;
typedef complex<double>C;
const double PI(acos(-1.0));
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a, LL b,LL M) { return b ? b & 1 ? a*pw(a, b - 1,M) % M : pw(a*a%M, b>>1,M) : 1; }
//log() = ln() , log(x)/log(y)=log(y)-base-x
//INT_MAX 127,INT_MIN 128
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
LL n,k;
int main(){
	cin>>n>>k;
	if(!k){
		cout<<n*n<<endl;
		return 0;
	}
	LL s=0,t=n+1;
	FOR(i,k+1,n){
		
		s+=t/i*(i-k)+max(0LL,t%i-k);
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }

    vector<int> dp(n+1,0);
    dp[1]=0;
    dp[2]=abs(v[1]-v[0]);

    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(v[i-1]-v[i-2]),dp[i-2]+abs(v[i-1]-v[i-3]));
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long l = 1;
        long prev = 0;
        for(int i = 0; i < n; i++){
            long temp = sc.nextLong()/2;
            l = lcm(l,temp);
            if(i == 0){
                prev = divide2(temp);
            }else{
                if(prev != divide2(temp)){
                    System.out.println(0);
                    return;
                }
            }
        }
        if(m < l){
            System.out.println(0);
        }else{
            if((m/l) % 2 == 0){
                System.out.println(m/(l*2));
            }else{
                System.out.println(1+m/(l*2));
            }
        }
        
    }

    private static long divide2(long l){
        long ret = 0;
        while(l % 2 == 0){
            ret++;
            l /= 2;
        }
        return ret;
    }
    
    private static long gcd(long a, long b)
    {
        while (b > 0)
        {
            long temp = b;
            b = a % b; // % is remainder
            a = temp;
        }
        return a;
    }
    
    private static long lcm(long a, long b)
    {
        return a * (b / gcd(a, b));
    }
}

Measured memory_bytes: 48828
H,W = map(int,input().split())

lst = [str(input()) for _ in range(H)]

#print(lst)

def check(y,x):
    if x < 0 or x >= W or y < 0 or y >= H:
        return 0
    elif lst[y][x] == '#':
        return 1
    else:
        return 0


fin = [[] for _ in range(H)]
for j in range(H):
    for i in range(W):
    
        sol = 0
        if lst[j][i] == '#':
            sol = '#'
        else:
            
            sol += check(j-1,i)
            sol += check(j+1,i)
            sol += check(j,i-1)
            sol += check(j,i+1)
            sol += check(j-1,i-1)
            sol += check(j+1,i+1)
            sol += check(j+1,i-1)
            sol += check(j-1,i+1)
        fin[j].append(str(sol))    
    print(*fin[j],sep = '')

Measured memory_bytes: 9276
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = getLine >>= putStrLn . solve
solve :: String -> String
solve (a:b:c:d:_)
  | a == b && b /= c && c == d = "Yes"
  | a == c && b /= c && b == d = "Yes"
  | a == d && d /= c && b == c = "Yes"
  | otherwise = "No"


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
int n;
long long a[maxn],v[maxn];
long long ans1,ans2,ans3,ans4;
long long minn=INT_MAX;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		v[i]=v[i-1]+a[i];
	}
	int l=1,r=3;
	for(int i=2;i<n-1;i++)
	{
		while(l<i&&abs(v[l]-v[0]-(v[i]-v[l]))>=abs(v[l+1]-v[0]-(v[i]-v[l+1])))
		{
			l++;
		}
		while(r<n&&abs(v[r]-v[i]-(v[n]-v[r]))>=abs(v[r+1]-v[i]-(v[n]-v[r+1])))
		{
			r++;
		}
		ans1=v[l]-v[0];
		ans2=v[i]-v[l];
		ans3=v[r]-v[i];
		ans4=v[n]-v[r];
		minn=min(minn,max(ans1,max(ans2, max(ans3,ans4)))-min(ans1, min(ans2, min(ans3,ans4))));
	}
	cout<<minn;
}

Measured memory_bytes: 3328
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
    Mbak Seulgi Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m;
    int tc;
    cin >> ans;
    cout << 1 - ans << endl;
    return 0;
}


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

int main(){
string s;cin >> s;
int res;
if(s=="SUN") res=7;if(s=="MON") res=6;if(s=="FRI") res=2;if(s=="THU") res=3;if(s=="WED") res=4;if(s=="TUE") res=5;if(s=="SAT") res=1;
cout << res << endl;
}

Measured memory_bytes: 256
def solve():
    _, _, X, Y = map(int, input().split())
    x = map(int, input().split())
    y = map(int, input().split())
    max_x = max(x)
    min_y = min(y)

    if X >= Y or max_x >= min_y or min_y <= X < Y or max_x >= Y > X:
        print("War")
        return

    print("No War")
    

if __name__=='__main__':
    solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
template<class T>
void input(vector<T>& vec,int n){
	vec.resize(n);
	for(int i=0;i<n;i++){
		cin >> vec[i];
	}
}
int N;
vector<int> a,b,c;
int main(){
	cin >> N;
	input(a,N);
	input(b,N);
	input(c,N-1);
	int ans = 0;
	for(int i=0;i<N;i++){
		ans += b[a[i]-1];
		if(i>0&&a[i-1]==a[i]-1)ans += c[a[i-1]-1];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		boolean[] x=new boolean[n+1];
		Arrays.fill(x,false);
		int[] y=new int[n+1];
		int sum=0,num=0;
		for(int i=0;i<m;i++) {
			int a=sc.nextInt();
			String s=sc.next();
			if(s.equals("AC")) {
				x[a]=true;
			}else {
				if(!x[a])
					y[a]++;
			}
		}
		for(int i=0;i<n+1;i++) {
			if(x[i]&&y[i]>0)
				num+=y[i];
			if(x[i])
				sum++;
		}
		System.out.print(sum+" "+num);
	}
} 

Measured memory_bytes: 63672
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  int h[N];
  for(int i=0;i<N;i++) cin >> h[i];

  int ans = 0;
  for(int i=0;i<N;i++){
    bool isok = true;
    for(int j=0;j<i;j++){
      if(h[i] < h[j]) isok = false;
    }
    if(isok) ans++;
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	double a[100],n;
    cin>>n;
    double sum=0,m;
    for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	sum/=n;
	for(int k=0;k<n;k++){
		a[k]=abs(a[k]-sum);
	}
	m=a[0];
	int ans=0;
	for(int l=1;l<n;l++){
		if(m>a[l]){
			m=a[l];
			ans=l;
		}
	}
	cout<<ans<<endl;
}


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

int main(){
 ll i,j,k,n,m;
  string p,q;
  cin>>p;
  cin>>q;
  ll ans=0;
  for(i=0;i<p.size();i++) {
   ans+=(p[i]==q[i]); 
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int[] point = new int[count];
        for(int index = 0; index < count; index++) {
          point[index] = sc.nextInt();
        }
      
        Arrays.sort(point);
        int min = point[0];
        int max = point[count - 1];
        int answer = Integer.MAX_VALUE;
        for(int n = min; n <= max; n++) {
          int total = 0;
          for(int p : point) {
            total += (int)StrictMath.pow(n - p, 2);
          }
          if(answer > total) {
            answer = total;
          }
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
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;
typedef unsigned long long ull;

int N;
int C[505];
int S[505];
int F[505];

int solve(int pos){
  int tm = 0;
  REP(i,pos,N-1){
    if(tm <= S[i]){
      tm = S[i];
    }
    if(tm%F[i]!=0){
      tm += F[i] - (tm%F[i]);
    }
    tm += C[i];
  }

  return tm;
}



int main(){
  cin >> N;
  rep(i,N-1){
    cin >> C[i] >> S[i] >> F[i];
  }

  rep(i,N-1){
    cout << solve(i) << endl;
  }
  cout << 0 << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    string s,t;
    while (cin >> s >> t) {
        int x[128] = {0};
        int y[128] = {0};
        const int n = s.size();
        FOR(i,0,n)
            x[s[i]]++, y[t[i]]++;
        VI A,B;
        FOR(i,0,SZ(x)) {
            A.push_back(x[i]);
            B.push_back(y[i]);
        }
        sort(ALL(A));
        sort(ALL(B));
        if (A == B)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}


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

// Aの個数、Bの個数はmod3で同一視しても良い(?)
int main(){
    string s, t;
    cin >> s >> t;
    s = 'C'+s, t = 'C'+t;
    int slen = s.length(), tlen = t.length();
    vector<int> ssum(slen, 0), tsum(tlen, 0);
    for(int i = 1; i < slen; i++) ssum[i] = ssum[i-1]+(s[i]=='A');
    for(int i = 1; i < tlen; i++) tsum[i] = tsum[i-1]+(t[i]=='A');
    
    bool wf[9][9] = {};
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            wf[i*3+j][(i+2)%3*3+(j+2)%3] = true;
        }
    }

    for(int k = 0; k < 9; k++){
        for(int i = 0; i < 9; i++){
            for(int j = 0; j < 9; j++){
                if(wf[i][k] && wf[k][j])    wf[i][j] = true;
            }
        }
    }

    int q;
    cin >> q;
    while(q-- > 0){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int sa = ssum[b]-ssum[a-1];
        int sb = b-a+1-sa;
        int ta = tsum[d]-tsum[c-1];
        int tb = d-c+1-ta;
        sa %= 3, sb %= 3, ta %= 3, tb %= 3;
        cout << (wf[sa*3+sb][ta*3+tb] ? "YES" : "NO") << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<utility>
#include<climits>
#include<cstring>
#include<string>
#include<cmath>
#include<bitset>

using namespace std;

#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define f first
#define s second
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mx 1000001

int main() {
    fastio;
    #ifndef ONLINE_JUDGE
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );
    #endif
    int l,r,d,cnt=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++)
        {
            if(i%d==0)
                cnt++;
        }
    cout<<cnt<<"\n";
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  int ans = min(A*N, B);

  cout << ans << endl;

  return 0;
}

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

using ll = long long;

// 繰り返し自乗法(x^nをmで割った余り) O(logn)
ll power(ll x, ll n, ll m) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, m);
    if (n % 2 == 0) res = (res * res) % m;
    else res = (((res * res) % m) * x) % m;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  reverse(s.begin(), s.end());
  
  ll keep = 0, ans= 0;
  map<ll, ll> mp;
  mp[0]++;
  for (ll i = 0; i < s.size(); i++) {
    keep += ((s[i] - '0') * power(10, i, 2019)) % 2019;
    keep %= 2019;
    ans += mp[keep];
    mp[keep]++;
  }
  
  cout << ans << '\n';
}

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

int main(void){
    int n,m;
    cin >> n >> m;
    
    int ans[n];
    for(int i=0;i<n;i++)    ans[i] = 0;
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        
        ans[a-1]++;
        ans[b-1]++;
    }
    
    for(int i=0;i<n;i++){
        cout << ans[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define VMAX 50
#define EMAX 500
#define DMAX 20
#define TRUE 1
#define FALSE 0
#define NOTUSED 0
#define END -1
#define ROOT -1
using Graph=vector<vector<int>>;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    // 友達関係の受け取り
    int n,m;
    cin>>n>>m;

    UnionFind G(n);

    REP(i,m){
        int a,b;
        cin>>a>>b;

        G.unite(a,b);
    }
    
    // 質問の受け取り
    int q;
    cin>>q;

    vector<pair<int,int>> link(q);
    REP(i,q){
        cin>>link[i].first>>link[i].second;
    }

    // 判定
    REP(i,q){
        if(G.same(link[i].first,link[i].second)){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }
}


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

int main()
{
    int n,m,c,v1,v2;
    c=1;
    cin>>n>>m;
    vector <int> balls(n);
    for(int i=0;i<n;i++)
    balls[i]=1;
    vector <bool>puede (n);
    puede[0]=true;
    while(m--)
    {
     cin>>v1>>v2;
     balls[v1-1]--;
     balls[v2-1]++;
     if(puede[v1-1]&&!puede[v2-1])
     {puede[v2-1]=true;
     c++;
     }
     if(balls[v1-1]==0&& puede[v1-1]){
         puede[v1-1]=false;
        c--;
     }
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 640
N,M,C = map(int,(input().split()))
B = list(map(int,(input().split())))
A = [0]*N
ans = 0
for i in range(N):
    A[i] = list(map(int,(input().split())))
for i in range(N):
    s = 0
    for j in range(M):
        s += A[i][j] * B[j]
    if s + C > 0:
        ans += 1
print(ans)

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

int factorial(int N) {
    if (N == 1) {
        return 1;
    }
    return N * factorial(N-1);
}


int main()
{
//    cout << factorial(1) << endl;
//    cout << factorial(2) << endl;
//    cout << factorial(3) << endl;
    int N; cin >> N;
    vector<pair<int, int>> points(N);
    for (int i = 0; i < N; i++) {
        cin >> points[i].first >> points[i].second;
    }

    double d=0, d_ave=0;
    int cnt = 0;
    for (int i=0; i<N; i++) {
        for (int j=i+1; j<N; j++) {
            //cout << i+1 << ' ' << j+1 << endl;
            d = (points[i].first - points[j].first) * (points[i].first - points[j].first)
              + (points[i].second - points[j].second) * (points[i].second - points[j].second);
            d_ave += sqrt(d);
        }
    }
    double deno = factorial(N);
    double nume = 2 * factorial(N-1);
    d_ave = nume * d_ave / deno;
    //cout << d_ave << endl;
    printf("%.8f\n", d_ave);
    return 0;
}

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

int main() {
  int n, d; cin >> n >> d;
  vector<vector<int>> x(n,vector<int>(d));
  rep(i,n) rep(j,d) cin >> x.at(i).at(j);

  int ans = 0;

  for (int i = 0; i < n-1; i++)
  {
    for(int r = i+1; r < n; r++){
      int sum = 0;
      for (int j = 0; j < d; j++)
      {
        sum += pow(x.at(i).at(j) - x.at(r).at(j), 2);
      }
      double y = sqrt(sum);
      int z = y;
      if(y==z) ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

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

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

double W, H, x, y;
int main(void){
    cin >> W >> H >> x >> y;
    cout << setprecision(10);
    cout << W*H/2 << ' ';
    int res = (x==W/2) and (y==H/2)?1:0;
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int keta(long long int i){
	int k = 0;
	while(i > 0){
		i = i/10;
		k++;
	}
	return k;
}

int main(){
	long long int p;
	cin >> p;
	int ret = 11;
	double sp = sqrt(p);
	for(int i = 1;i <= sp;i++){
		if (p%i == 0){
			long long int r2 = p/i;
			int k = keta(r2);
			if(ret > k) ret = k;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		string str = cin.next();
		int S = 0, N = 0, E = 0, W = 0;
		for (int i = 0; i < str.Length; i++)
		{
			switch (str[i])
			{
				case 'S': S++; break;
				case 'N': N++; break;
				case 'E': E++; break;
				case 'W': W++; break;
				default: break;
			}
		}
		if ((S != 0 && N == 0) || (S == 0 && N != 0))
		{
			Console.WriteLine("No");
			return;
		}
		if ((E != 0 && W == 0) || (E == 0 && W != 0))
		{
			Console.WriteLine("No");
			return;
		}
		Console.WriteLine("Yes");
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 2776
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e8;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
int w, n;
vi va;

int main(){
    cin >> w >> n;
    rep(i, w)va.push_back(i + 1);
    rep(i, n){
        int a, b;
        scanf("%d, %d", &a, &b);
        a--; b--;
        swap(va[a], va[b]);
    }
    rep(i, w)cout << va[i] << endl;
}

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

int main(){
    int x ;
    int h,m,s ;
    cin >> x ;
    m = x/60; s = x%60 ;
    h = m/60; m = m%60 ;
    cout <<h<<":"<<m<<":"<<s <<endl ;
    return 0 ;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
//#define cin fin
//#define cout fout
using namespace std;

//ifstream fin("file.in");
//ofstream fout("file.out");

const int nmax=1e3+5;
const int mod=1e9+7;
const int mod1=998244353;

int a,b,c,d;


int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> a >> b >> c >> d;
    a--;
    int x=a/c;
    int y=a/d;
    int z=a/((c*d)/__gcd(c,d));
    int a1=x+y-z;
    a1=a-a1;
    x=b/c;
    y=b/d;
    z=b/((c*d)/__gcd(c,d));
    int b1=x+y-z;
    b1=b-b1;
    cout<<b1-a1;
}


Measured memory_bytes: 256
import sys
N=int(input())

H=[int(x) for x in input().rstrip().split()]
flag=0
mi=-1
for i in range(N-1):

  if H[i]<=H[i+1] and mi<=H[i]:
    mi=max(mi,H[i]-1)
    continue
  elif H[i+1]<H[i]:
    H[i]=H[i]-1
    mi=max(mi,H[i])
  if H[i+1]<H[i] or H[i]<mi:
    flag=1
    print("No")
    sys.exit()

if flag==0:
  print("Yes")



Measured memory_bytes: 14704
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, L;
  cin >> N >> L;
 
  int R = L + N - 1;
 
  int eat;
  if (R <= 0)
  {
    eat = R;
  }
  else if (L >= 0)
  {
 
    eat = L;
  }
  else
  {
    eat = 0;
  }
 
  int answer = (((R + L) * (R - L + 1)) / 2) - eat;
 
  cout << answer << endl;
}

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

long long func(long long n){
    long long ret = 1;
    for(long long i = 1; i <= n; i++){
        ret = (ret * i) % mod; 
    }
    return ret;
}
int main(){
    long long n, m;
    cin >> n >> m;

    long long ans = 0;
    if(n == m){
        ans = func(n) * func(m) * 2 % mod;
    }
    else if(abs(n-m) == 1){
        ans = func(n) * func(m) % mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	char ss[10001];
	int ioi,joi,i;
	while(0<=scanf(" %s ",ss)){
		ioi=joi=0;
		for(i=0;;i++){
			if(ss[i]=='\0')break;
			if(ss[i]=='I' && ss[i+1]=='O' && ss[i+2]=='I')++ioi;
			if(ss[i]=='J' && ss[i+1]=='O' && ss[i+2]=='I')++joi;
		}
		printf("%d\n%d\n",joi,ioi);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>

using namespace std;

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

int main(void){
  LL n, h;
  cin >> n >> h;

  vector<LL> vb(n);
  LL max_a = 0;

  for (int i = 0; i < n; i++) {
    LL tmp_a;
    cin >> tmp_a >> vb[i];
    if (tmp_a > max_a) max_a = tmp_a;
  }

  sort(vb.begin(), vb.end(), greater<LL>());

  int cnt = 0;

  for (int i = 0; i < n; i++) {
    if (max_a < vb[i]){
      h -= vb[i];
      cnt ++;
    } else {
      break;
    }

    if (h <= 0) {
      cout << cnt << endl;
      return 0;
    }
  }

  if (h % max_a) cnt += (h / max_a) + 1;
  else cnt += h / max_a;

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

/**
 * 
 */

/**
 * @author yuki
 * 
 */
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		for (int i = 0; i < N; i++) {
			int[] len = new int[3];
			for (int j = 0; j < 3; j++) {
				len[j] = scanner.nextInt();
			}
			Arrays.sort(len);
			if (len[0]*len[0]+len[1]*len[1]==len[2]*len[2]){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 23376
object Main extends App{
    val Array(a,b) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val target = (a.toString + b.toString).toInt
    val upper_limit = (target/2.0).ceil.toInt
    if((1 to upper_limit).map(e => e*e).exists(_ == target)) println("Yes") else println("No")
}

Measured memory_bytes: 28004
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#define SIZE 2005

using namespace std;
typedef pair <int,int> P;

vector <int> vec[SIZE];
int par[SIZE][SIZE];
int id[SIZE][SIZE];
bool use[SIZE][SIZE];
int ans;

void dfs(int v,int p,int rt)
{
	par[rt][v]=p;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p) dfs(to,v,rt);
	}
}
void add(int a,int b)
{
	if(id[a][b]==b||id[b][a]==a) return;
	if(id[a][b]!=-1) add(id[a][b],b);
	else if(id[b][a]!=-1) add(id[b][a],a);
	else
	{
		vector <P> nxt;
		for(int t=0;t<2;t++)
		{
			use[a][b]=true;
			id[a][b]=b;
			queue <int> que;
			que.push(b);
			while(!que.empty())
			{
				int v=que.front();que.pop();
				for(int i=0;i<vec[v].size();i++)
				{
					int to=vec[v][i];
					if(to!=par[a][v])
					{
						if(id[a][to]!=-1)
						{
							if(use[a][to])
							{
								use[to][a]=use[a][to]=false;
								nxt.push_back(P(to,b));
							}
						}
						else
						{
							id[a][to]=b;
							que.push(to);
						}
					}
				}
			}
			swap(a,b);
		}
		for(int i=0;i<nxt.size();i++) add(nxt[i].first,nxt[i].second);
	}
}
void dfs2(int v,int p,int b)
{
	if(id[b][v]==v)
	{
		ans++;
		b=v;
	}
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p) dfs2(to,v,b);
	}
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--,b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	for(int i=0;i<n;i++) dfs(i,-1,i);
	memset(id,-1,sizeof(id));
	memset(use,false,sizeof(use));
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--,b--;
		add(a,b);
	}
	ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<vec[i].size();j++)
		{
			int to=vec[i][j];
			dfs2(to,i,i);
		}
	}
	printf("%d\n",ans/2);
	return 0;
}


Measured memory_bytes: 36224