akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)

int main(void)
{
  int a[3];
  scanf("%d %d %d", &a[0], &a[1], &a[2]);

  qsort(a, 3, sizeof(int), acs);

  printf("%d\n", a[0] + a[1]);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

signed main(void) {
    int A, B, C; cin >> A >> B >> C;
    cout << min(B / A, C) << endl;
    return 0;
}

Measured memory_bytes: 256
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    ll a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;
    cin >> k;
    cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

ll dp[51][51][3000];

int main(){
    int n,k;
    cin >> n >> k;
    if(k%2==1){
        cout << 0 << endl;
        return 0;
    }
    dp[0][0][0] = 1;
    for(int i=0;i<=n-1;i++){
        for(int j=0;j<=i;j++){
            for(int s=0;s<=k;s++){
                if(j!=0){
                    if(s+2*(j-1)<=k){
                        dp[i+1][j-1][s+2*(j-1)] += dp[i][j][s]*(j*j);
                        dp[i+1][j-1][s+2*(j-1)] %= mod;
                    }
                }
                if(s+2*j<=k){
                    dp[i+1][j][s+2*j] += dp[i][j][s]*(2*j+1);
                    dp[i+1][j][s+2*(j)] %= mod;
                }
                if(s+2*(j+1)<=k){
                    dp[i+1][j+1][s+2*(j+1)] += dp[i][j][s];
                    dp[i+1][j+1][s+2*(j+1)] %= mod;
                }
            }
        }
    }
    // rep(i,n+1){
    //     rep(j,n+1){
    //         rep(s,k+1){
    //             cout << i << " " << j << " " << s << " "  <<dp[i][j][s] << endl; 
    //         }
    //     }
    // }
    cout << dp[n][0][k] << endl;
    return 0;
}

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
ll n,m,k;
string s[12];
ll cc[12][1005];
ll check(ll a,ll b,ll c,ll d){
    return cc[c][d]+cc[a-1][b-1]-cc[a-1][d]-cc[c][b-1];
}
// ll dp[12][1005][12][1005];
// ll rec(ll a,ll b,ll c,ll d){
//     if(dp[a][b][c][d]!=-1) return dp[a][b][c][d];
//     if(check(a,b,c,d)<=k) return dp[a][b][c][d]=0;
//     ll ans=hell;
//     // ans=hell;
//     rep(i,a,c-1) ans=min(ans,1+rec(a,b,i,d)+rec(i+1,b,c,d));
//     rep(j,b,d-1) ans=min(ans,1+rec(a,b,c,j)+rec(a,j+1,c,d));
//     return dp[a][b][c][d]=ans;
//     // else return 0;
// }
void solve(){
    cin>>n>>m>>k;
    rep(i,0,n-1) cin>>s[i];
    rep(i,0,n-1){
        rep(j,0,m-1) cc[i+1][j+1]=cc[i][j+1]+cc[i+1][j]-cc[i][j]+(s[i][j]-'0');
    }
    // rep(i,1,n) rep(j,1,m) cout<<cc[i][j]<<" \n"[j==m];
    // memset(dp,-1,sizeof(dp));
    // cout<<dp[4][5][6][7]<<" ";
    // cout<<rec(1,1,n,m);
    ll temp=(1<<(n-1))-1;
    ll ans=INF;
    // temp=0;
    for (int s=temp; ;s=(s-1)&temp){
        ll poss=1;
        ll cnt=__builtin_popcountll(s);
        vector<ll> fk;
        fk.pb(0);
        rep(j,0,n-2) if((1ll<<j)&s) fk.pb(j+1);
        fk.pb(n);
        // rep(i,0,sz(fk)-1) cout<<fk[i]<<" ";
        // cout<<endl;
        ll zz=1;
        // cout<<sz(fk);
        rep(i,1,m){
            // cout<<i<<" ";
            rep(j,1,sz(fk)-1){
                ll prev=fk[j-1]+1;
                ll curr=fk[j];
                // cout<<prev<<" "<<curr<<endl;
                if(check(prev,zz,curr,i)<=k) {
                    // cout<<check(prev,zz,curr,i)<<endl;
                    continue;
                }
                else{
                    if(i==zz){
                        poss=0;
                        break;
                    }
                    else{
                        cnt++;
                        zz=i;
                        i--;
                        break;
                    }
                }
            }     
            // cnt++;
        }
        // cout<<poss<<" "<<s<<" "<<cnt<<endl;
        if(poss) ans=min(ans,cnt);
        if (s==0) break;
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 384
import sys
from operator import itemgetter
input=sys.stdin.readline
n,x=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=list(zip(*a))
t=max(b[0])
a.sort(key=itemgetter(1),reverse=True)
ans=0
for i in range(n):
  if a[i][1]>=t:
    x-=a[i][1]
    ans+=1
  if x<=0:
    print(ans)
    break
else:
  ans+=(x+t-1)//t
  x=0
  print(ans)

Measured memory_bytes: 36084
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,q;
  cin>>n;
  vector <int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  cin>>q;
  for(int i=0,k;i<q;i++){
    cin>>k;
    cout<<distance(a.begin(),lower_bound(a.begin(),a.end(),k))<<endl;
  }

  return 0;

}



Measured memory_bytes: 3108
from sys import stdin
N,Y=list(map(int,stdin.readline().strip().split()))
count=0
flag=False
if abs(N)-abs(Y)==0:
    print(1)
    exit()
if N>Y and abs(N)>abs(Y) or N>Y and N<0:
    count+=1
    N*=-1
    flag=True
YY=abs(Y)
NN=abs(N)
ans=0
if YY>NN:
    ans=YY-NN
else:
    ans=NN-YY
N+=ans
if Y==N:
    print(count+ans)
else:
    print(count+ans+1)

Measured memory_bytes: 3064
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
}

ll dp[2010][2010];

int main(void) {

  ll n;
  pair<ll, ll> a[2500];
  cin >> n;
  rep(i, n) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }

  sort(a, a + n, greater< pair<ll, ll> >());
  for (ll x = 0; x < n; x++) {
    for (ll y = 0; y <= x + 1; y++) {
      dp[x + 1][y] = dp[x][y] + a[x].first*abs(a[x].second-(n-x+y));
      if (x < y) dp[x + 1][y] = 0;
      if (y > 0) {
	dp[x+1][y] = max(dp[x+1][y], dp[x][y-1] + a[x].first*abs(a[x].second-y));
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i <= n - 1; i++) ans = max(ans, dp[n][i]);

  cout << ans << endl;

}

  


Measured memory_bytes: 26312
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    str N;cin>>N;
    int f=0;
    if(N[0]==N[1] || N[1]==N[2]||N[2]==N[3])f=1;
    if(f>0) cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;



    return 0;
}


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

int main(int argc, const char * argv[]) {
    int N, T;
    int c[1000];
    int t[1000];
    
    cin >> N >> T;
    for (int i = 0; i < N; i++) {
        cin >> c[i] >> t[i];
    }
    
    int min_cost = numeric_limits<int>::max();
    for (int i = 0; i < N; i++) {
        if (T >= t[i]) {
            if (min_cost > c[i]) {
                min_cost = c[i];
            }
        }
    }
    
    if (min_cost == numeric_limits<int>::max()) {
        cout << "TLE" << endl;
    } else {
        cout << min_cost << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
a,b,m=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))

ans=min(al)+min(bl)
        
for i in range (m):
        x,y,c=map(int,input().split())
        kouho=al[x-1]+bl[y-1]-c
        if kouho<ans:
           ans=kouho
print(ans)

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


using namespace std;



int main(){
    int n , k ;scanf("%d %d" , &n , &k) ;
    int h[n + 10] ;


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

    int jump[n + 10] = {0 , abs(h[1] - h[0] ) } ;
    //cout<< jump[0] << "   " << jump[1] << "\n\n" ;

    for(int i = 2 ; i < n ; i++)
        jump[i] = 2e9 ;


    for(int i = 2 ; i < n ; i++)
        for(int j = 1 ; j <= i && j <= k ; j++)
            jump[i] = min(jump[i - j] + abs(h[i] - h[i - j]) , jump[i] ) ;





    printf("%d\n" , jump[n - 1]) ;
}





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

using namespace std;


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


Measured memory_bytes: 512
n, a, b = map(int, input().split())
m = max(a, b)
mod = 10 ** 9 + 7

def binary(n):
    return bin(n)[2:]

# バイナリ法
def pow_by_binary_exponentiation(a, x, n): # a^x mod n
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * a) % n
    return y

ans = pow_by_binary_exponentiation(2, n, mod)
ans -= 1

N = max(a, b)
fact = [1] * (N + 1)

for i in range(N):
    fact[i + 1] = fact[i] * (i + 1) % mod


def comb(r):
    c = n
    for i in range(1, r):
        c = (c * (n - i)) % mod
    c = c * pow_by_binary_exponentiation(fact[r], mod - 2, mod) % mod
    return c

ans = (ans - comb(a)) % mod
ans = (ans - comb(b)) % mod
print(ans)


Measured memory_bytes: 65852
#include <iostream>
#include <vector>

bool solve() {
    int n, m;
    std::cin >> n >> m;
    if (n == 0) return false;

    std::vector<int> xs(n), ys(m);
    for (auto& x : xs) std::cin >> x;
    for (auto& y : ys) std::cin >> y;

    int i = 0;
    for (int t = 0; t < m; ++t) {
        i += ys[t];
        if (i >= n - 1) {
            std::cout << t + 1 << "\n";
            break;
        }

        i += xs[i];
        if (i >= n - 1) {
            std::cout << t + 1 << "\n";
            break;
        }
    }

    return true;
}

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

    while (solve()) {}

    return 0;
}



Measured memory_bytes: 3052
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int a, b, c;
		
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		
		if( (a < b) && (b < c)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
	}

}

Measured memory_bytes: 26180
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD  998244353 
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;
#define int ll 

struct MyCombination {
public:
	vector<long long> fac, ifac;
	ll mpow(ll x, ll n) { //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
		ll ans = 1;
		while (n != 0) {
			if (n & 1) ans = ans * x % MOD;
			x = x * x % MOD;
			n = n >> 1;
		}
		return ans;
	}
	ll comb(ll a, ll b) { //aCbをmod計算
		if (a == 0 && b == 0)return 1;
		if (a < b || a < 0)return 0;

		ll tmp = ifac[a - b] * ifac[b] % MOD;

		return tmp * fac[a] % MOD;
	}

	MyCombination(long long SIZE = 200001) {
		fac.resize(SIZE);
		ifac.resize(SIZE);
		fac[0] = 1;
		ifac[0] = 1;
		for (ll i = 0; i < SIZE - 1; i++) {
			fac[i + 1] = fac[i] * (i + 1) % MOD; // n!(mod M)
			ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
		}
	}

};

int opow(int x, int n) {
	int res = 1;
	rep(i, n) {
		res *= x;
		res %= MOD;
	}

	return res;
}
signed  main() {
	MyCombination myc;

	int N, M, K; cin >> N >> M >> K;

	int sum = 0;

	for (int k = 0; k < K + 1; k++) {
		int temp = M * myc.mpow(M - 1, N - k -1);
		temp %= MOD;

		int semp = myc.comb(N - 1, k);

		sum += (temp * semp) % MOD;
		sum %= MOD;
	}

	cout << sum << endl;
}

Measured memory_bytes: 6228
#include <cstdio>
typedef long long ll;
typedef unsigned long long ull;

ll mod_pow(ull x, ull n, ull mod) {
    ull res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main(void) {
    ull m, n;
    scanf("%lld %lld", &m, &n);
    printf("%lld\n", mod_pow(m, n, 1000000007));
    return 0;
}

Measured memory_bytes: 1024
X, Y, A, B, C = map(int, input().split())
P = [int(a) for a in input().split()]
Q = [int(a) for a in input().split()]
R = [int(a) for a in input().split()]
S = sorted([p * 4 for p in P] + [q * 4 + 1 for q in Q] + [r * 4 + 2 for r in R])[::-1]

Z = X + Y
ans = 0
for s in S:
    a, t = s>>2, s & 3
    if t == 0:
        if X:
            ans += a
            X -= 1
            Z -= 1
    elif t == 1:
        if Y:
            ans += a
            Y -= 1
            Z -= 1
    else:
        ans += a
        Z -= 1
    if not Z: break
print(ans)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string A, B, C;
  cin >> A >> B >> C;
  if (A.back() == B.front() && B.back() == C.front())
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
  return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())

def nCr(n,r,p):
    r=min(r,n-r)
    if r==0:
        return 1
    x,y=1,1
    for i in range(r):
        x=x*(n-i)%p
        y=y*(i+1)%p
    return x*pow(y,p-2,p)%p

if (x + y) % 3 != 0:
    print(0)
else:
    ans = 0
    n = (x + y)//3
    for i in range(n+1):
        a = n - i
        b = i
        if a + 2 * b == x and 2 * a + b == y:
            ans += nCr(n, min(a, b), 10**9 + 7)
            ans = ans % (10**9 + 7)
    print(ans)

Measured memory_bytes: 40428
#include<bits/stdc++.h>
using namespace std;
string s,t;
int main()
{
	cin>>s>>t;
	bool ok=true;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!=t[i])
		{
			ok=false;
			break;
		}
	}
	if(ok)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) max(x,y)-min(x,y)
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[11111111];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h,j;
  cin >>a>>b;
  cout <<(a+b)%24<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

string S;
int N;
int a[80005];
int dp[11], next[11];

int rev(int n)
{
	return (-n + 11) % 11;
}

int main(void)
{
	while(1){
		cin >> S;
		if(S == "0") break;
		N = S.size();
		
		int n;
		for(int i = 0; i < N; i++) {
			n = S[i] - '0';
			if(i % 2) n = rev(n);
			a[i] = n;
		}
		
		int ans = 0;
		for(int i = 0; i < 11; i++) dp[i] = 0;
		for(int i = 0; i < N; i++){
			ans += dp[rev(a[i])];
			for(int j = 0; j < 11; j++){
				next[(j + a[i])%11] = dp[j];
			}
			for(int j = 0; j < 11; j++) dp[j] = next[j];
			if(a[i]) dp[a[i]]++;
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3624
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>

using namespace std;

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vector<int> p(n);
    cin >> p;
    for (auto& x : p) x--;

    vector<int> pos(n);
    for (int i = 0; i < n; ++i) pos[p[i]] = i;

    int64_t ans = 0;
    set<int> on_pos;
    on_pos.insert(-1);
    on_pos.insert(n);
    for (int i = 0; i < n; ++i) {
        auto right_it = on_pos.lower_bound(pos[i]);
        auto left_it = prev(right_it);
        int left = *left_it;
        int right = *right_it;
        ans += int64_t(pos[i] - left) * int64_t(right - pos[i]) * (i + 1);
        on_pos.insert(pos[i]);
    }
    cout << ans;
}


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

#define ldb long double

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    ldb sum;
    cin >> sum;
    
    ldb l = sum / 3.0;
    sum -= l;
    
    ldb b = sum / 2.0;
    
    ldb h = sum - b;
    
    ldb maxArea = l * b * h;
    
    cout << fixed << setprecision(12) << maxArea;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
     
int main() {
    	
      signed int a, b;
      std::cin >> a >> b;
      
      int ret1 = a + b;
      int ret2 = a - b;
      int ret3 = a * b;
      
      if(ret1 >= ret2 && ret1 >= ret3) {
      	std::cout << ret1;
      }
      else if (ret2 >= ret1 && ret2 >= ret3) {
      	std::cout << ret2;
      } else {
      	std::cout << ret3;
      }
    	
       return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>    
using namespace std;
#define anuj ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define ll long long int
#define si(x)    scanf("%d",&x)
#define sl(x)    scanf("%I64d",&x)
#define ss(s)    scanf("%s",s)
#define all(v)  sort(v.begin(),v.end())
#define rall(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl '\n'
typedef pair<int, int>    pii;
typedef vector<int>        vi;
typedef vector<pii>        vpii;
typedef vector<vi>        vvi;
const int mod = 1000000007;
const int N = 2e5+5;
const int LG = 20;
int a[N];

int32_t main(){
    anuj;
    // #ifndef ONLINE_JUDGE
    // freopen("inputf.txt", "r", stdin);
    // freopen("outputf.txt", "w", stdout);
    // #endif

    int n,W;
    cin >> n >> W;

    vi weight(n),value(n);

    fo(i,n) cin >> weight[i] >> value[i];

    int sm=0;
    fo(i,n) sm+=value[i];

    int dp[n+1][sm+1];

    fo(i,n+1) fo(j,sm+1){
        if(j==0) dp[i][j]=0;
        else dp[i][j]=INT_MAX;
    }


    for(int item=1;item<=n;item++){
        for(int val=1;val<=sm;val++){
            dp[item][val]=dp[item-1][val];
            if(value[item-1]<=val)
                dp[item][val]=min(dp[item][val],dp[item-1][val-value[item-1]]+weight[item-1]);
        }
    }

    int ans=0;
    fo(i,sm+1) if(dp[n][i]<=W) ans=i;
    cout << ans;
}

Measured memory_bytes: 82416
import sys
sys.setrecursionlimit(10**9)

n = int(input())

from collections import defaultdict
d = defaultdict(list)

for _ in range(n-1):
    a,b,c = map(int,input().split())
    d[a-1].append((b-1, c))
    d[b-1].append((a-1, c))

q,k = map(int,input().split())

global dist
dist = [-1 for _ in range(n)]
def dfs(l, pos):
    dist[pos] = l
    for to, c in d[pos]:
        if dist[to] == -1:
            dfs(l+c,to)

dfs(0, k-1)

for _ in range(q):
    x,y = map(int,input().split())
    print(dist[x-1] + dist[y-1])


Measured memory_bytes: 141096
import java.util.*;

/**
 * E Main
 *
 * @date 2020.09.19
 * @author 焼き鮭 <yaki-shake@up-tri.me>
 */

public class Main {
  Scanner sc;

  public static void main(String[] args) {
    new Main().execute();
  }

  public void execute() {
    this.sc = new Scanner(System.in);

    int n = sc.nextInt();

    int[][] points = new int[n][4];
    int maxi_2 = -1;
    int mini_2 = -1;
    int maxi_3 = -1;
    int mini_3 = -1;

    for (int i = 0; i < n; i++) {
      int x = sc.nextInt();
      int y = sc.nextInt();
      points[i][0] = x;
      points[i][1] = y;
      points[i][2] = x + y;
      points[i][3] = x - y;
      if (maxi_2 == -1 || points[maxi_2][2] < points[i][2]) {
        maxi_2 = i;
      }
      if (maxi_3 == -1 || points[maxi_3][3] < points[i][3]) {
        maxi_3 = i;
      }
      if (mini_2 == -1 || points[mini_2][2] > points[i][2]) {
        mini_2 = i;
      }
      if (mini_3 == -1 || points[mini_3][3] > points[i][3]) {
        mini_3 = i;
      }
    }

    int a = (points[maxi_2][2] - points[mini_2][2]);
    int b = (points[maxi_3][3] - points[mini_3][3]);

    System.out.println(a < b ? b : a);
  }
}


Measured memory_bytes: 57376
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << ", "
template <typename T> ostream& operator<<(ostream& _o_, const vector<T>& _v_){ \
 if(!_v_.empty()){_o_<<'[';copy(_v_.begin(),_v_.end(),ostream_iterator<T>(_o_,", "));_o_<<"\b\b]";}return _o_;}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef unsigned int uint;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unsigned char uchar;
struct secure_hash {
 static uint64_t splitmix64(uint64_t x) {
  x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); }
 size_t operator()(uint64_t x) const {
  static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };
template<typename T> using V = vector<T>;
template<typename T, typename U> using umap = unordered_map<T,U,secure_hash>;
template<typename T> using uset = unordered_set<T,secure_hash>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using max_heap = priority_queue<T>;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    V<ll> a(n);
    rep(i,0,n) cin >> a[i];
    rep(i,1,n) a[i] += a[i-1];
    V<V<ll>> dp(n, V<ll>(n, LLONG_MAX));
    for (int i = 0; i < n; ++i) {
        dp[i][i] = 0;
    } 
    for (int l = n-2; l >= 0; --l) {
        for (int r = l+1; r < n; ++r) {
            for (int i = l; i < r; ++i) {
                dp[l][r] = min(dp[l][r], dp[l][i] + dp[i+1][r] + a[r] - (l > 0 ? a[l-1] : 0));
            }
        }
    }
    cout << dp[0][n-1] << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;

signed main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A+B >= C) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



i64 n, a[303030], L[101010], R[101010];
void solve(){
	cin >> n;
	for(int i = 0; i < 3*n; i++){
		cin >> a[i];
	}
	
	i64 ans = -LINF;
	priority_queue<int,vector<int>,greater<int>> q;
	priority_queue<int> qq;
	for(int i = 0; i < n; i++){
		q.push(a[i]);
		qq.push(a[i+2*n]);
		L[0] += a[i];
		R[0] += a[i+2*n];
	}
	for(int i = 0; i < n; i++){
		q.push(a[i+n]);
		L[i+1] = L[i] + a[i+n] - q.top();
		q.pop();
	}
	for(int i = 0; i < n; i++){
		qq.push(a[2*n-1-i]);
		R[i+1] = R[i] + a[2*n-1-i] - qq.top();
		qq.pop();
	}
	for(int i = 0; i <= n; i++){
		chmax(ans, L[i]-R[n-i]);
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 5236
#include<stdio.h>

#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i){
    int l, r, largest;
    l=2*i;
    r=l+1;

    if(l <= H && A[l] > A[i]){
        largest=l;
    }
    else{
        largest=i;
    }
    if(r<=H && A[r] > A[largest]){
        largest=r;
    }
    if(largest!=i){
        int temp;
        temp=A[i];
        A[i]=A[largest];
        A[largest]=temp;
        maxHeapify(largest);
    }
}


int main(void){
    
    scanf("%d", &H);
    for(int i=1; i<=H; i++){
        scanf("%d", &A[i]);
    }
    for(int i=H/2; i>=1; i--){
        maxHeapify(i);
    }
    for(int i=1; i<=H; i++){
        printf(" %d", A[i]);
    }
    printf("\n");

    return 0;
}



Measured memory_bytes: 3696
#include<iostream>
#include<algorithm>

using namespace std;

#define INFTY 1000000001

typedef struct card{
  char mark;
  int num;
} card;

//安定で高速
void merge(card *A, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int i, j;

  card L[n1 + 10], R[n2 + 10];
  for(i = 0;i < n1;i++) L[i] = A[left + i];
  for(i = 0;i < n2;i++) R[i] = A[mid + i];

  L[n1].num = INFTY;
  R[n2].num = INFTY;

  i = 0;
  j = 0;

  for(int k = left;k < right;k++){
    if(L[i].num <= R[j].num){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
  }
}

void mergeSort(card *A, int left, int right){
  if(left + 1 < right){
    int mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(card *A, int p, int r){
  int x = A[r].num;
  int i = p - 1;
    for(int j = p;j < r;j++){
      if(A[j].num <= x){
        i++;
        swap(A[i], A[j]);
      }
    }
    swap(A[i + 1], A[r]);
  return i + 1;
}

void quicksort(card *A, int p, int r){
  if(p < r){
    int q = partition(A, p, r);
    quicksort(A, p, q - 1);
    quicksort(A, q + 1, r);
  }
}

int main(){

  int n;
  card a[100010], b[100010];

  cin >> n;
  for(int i = 0;i < n;i++){
    char mark;
    int num;

    cin >> mark >> num;
    a[i].mark = mark;
    a[i].num = num;
    b[i].mark = mark;
    b[i].num = num;
  }

  quicksort(a, 0, n - 1);
  mergeSort(b, 0, n);

  bool flag = true;
  for(int i = 0;i < n;i++){
    if(a[i].mark != b[i].mark){
      flag = false;
      break;
    }
  }

  if(flag) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  for(int i = 0;i < n;i++) cout << a[i].mark << ' ' << a[i].num << endl;

  return 0;
}



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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> a(n), b(n); rep(i, n) cin >> a[i] >> b[i];
	vector<pair<int, int>> v(n);
	rep(i, n) v[i] = make_pair(b[i], a[i]);
	sort(v.begin(), v.end());

	int now = 0;
	bool flag = true;
	rep(i, n) {
		int limit = v[i].first;
		int time = v[i].second;
		if (now + time > limit) {
			flag = false;
			break;
		} else {
			now += time;
		}
	}
	printf("%s\n", flag ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 3328
//#typedef int ll
// include
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <tuple>
// namespace
using namespace std;
// typedef
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
// const
const int inf = 1e9;
const int mod = ((int)1e9 + 7);
// loop
#define rep(i, n) for(int i = 0, i##_mx = n; i < i##_mx; i++)
#define brep(i, b, e) for(int i = b; i < e; i++)
#define erep(i, b, e) for(int i = b; i <= e; i++)
#define rrep(i, b, e) for(int i = b; i >= e; i--)
// STL
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
// function
int gcd(int a, int b){return b ? gcd(b, a % b) : a;}
void prime(vint& v, int n){brep(i, 2, n){bool fg = false; for(auto e : v){if(i % e == 0){fg = true;}} if(fg){continue;} v.pb(i);}}
void in(vint& v){for(auto& i : v){cin >> i;}}
void in(vll& v){for(auto& i : v){cin >> i;}}

signed main(){
    int n, x;
    cin >> n >> x;
    
    vint l;
    l.resize(n);
    in(l);
    
    int ans = 1, sum = 0;
    for(auto e : l){
        sum += e;
        if(sum <= x){
            ans++;
        }
    }
    
    cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T> >;

const ll MOD=1e9+7;

int N,M;

int val[100100];
int comp[100100];
vector<set<pii>> comps;



int main(){

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

  cin>>N>>M;
  for(int i=0;i<N;i++) cin>>val[i];
  for(int i=0;i<N;i++) comp[i]=i,comps.pb({{val[i],i}});

  if(M==N-1){
    cout<<"0\n";
    return 0;
  }

  for(int i=0;i<M;i++){
    int x,y;cin>>x>>y;
    int j0=comp[x],j1=comp[y];
    if(comps[j0].size()<comps[j1].size()){
      for(auto& pr:comps[j0]) comp[pr.snd]=j1,comps[j1].insert(pr);
      comps[j0].clear();
    }else{
      for(auto& pr:comps[j1]) comp[pr.snd]=j0,comps[j0].insert(pr);
      comps[j1].clear();
    }
  }


  ll res=0;
  int K=0;
  for(auto& s: comps){
    // cout<<s.size()<<endl;
    if(s.size()==0) continue;
    res+=s.begin()->fst;
    s.erase(s.begin());
    K++;
  }

  min_queue<int> q;
  for(auto&s: comps){
    // cout<<s.size()<<endl;
    for(auto pr:s) q.push(pr.fst);
  }

  for(int i=0;i<K-2;i++){
    if(q.empty()){
      cout<<"Impossible\n";
      return 0;
    }
    // cout<<q.top()<<endl;
    res+=q.top();
    q.pop();
  }

  cout<<res<<'\n';

  return 0;
}


Measured memory_bytes: 12716
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    let mut arr: Vec<u128> = Vec::new();
    for i in 0..n {
        let x: u128 = read();
        arr.push(x);
        if i >= k {
            if arr[i - k] < arr[i] {
                println!("Yes");
            } else {
                println!("No");
            }
        }
    }
}

Measured memory_bytes: 5276
N, M = map(int, input().split())
l = [0 for _ in range(N)]
AC = 0
WA = 0
for _ in range(M):
  p, S = input().split()
  p = int(p) - 1
  if l[p] != None and S == "WA":
    l[p] += 1
  if l[p] != None and S == "AC":
    AC += 1
    WA += l[p]
    l[p] = None
print(AC, WA)

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

using namespace std;

int main(){
  int n; cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  
  int dp[n+1]; memset(dp, 0, sizeof(dp));
  dp[0] = 0;
  dp[1] = abs(arr[1] - arr[0]);
  dp[2] = min(dp[1] + abs(arr[1] - arr[2]), dp[0] + abs(arr[0] - arr[2]));
  for (int i = 2; i < n; i++){
    int a = dp[i-1] + abs(arr[i-1] - arr[i]);
    int b = dp[i-2] + abs(arr[i-2] - arr[i]);
    dp[i] = min(a, b);
  }
  
//   for (auto i : dp) cout << i << " ";
  cout << endl;
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n;
  cin >> n;
  int a[n];
  int b[n];
  rep(i,n)cin >> a[i] >> b[i];
  int ans=0;
  rep(i,n-2){
    if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2])ans++;
  }
  if(ans>0)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
ll dp[100001];
int q(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void) {
  int a,b;
  scanf("%d %d",&a,&b);
  PRN((a+b)/2);
  return 0;
}


Measured memory_bytes: 2136
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int c[20],i,n,a[20], b[20], t;
	cin >> n ;
	i = 1;
	t = 0;
	while (i <= n) {
		cin >> a[i];
		i++;
	}
	i = 1;
	while (i <= n) {
		cin >> b[i];
		c[i] = a[i] - b[i];
		if (c[i] > 0) {
			t = t + c[i];
		}
		i++;
	}
	
	printf("%d\n", t );



	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())

arr=[]

for i in range(m):
    b = list(map(int,input().split()))
    arr.append(b)

arr.sort(key=lambda x: x[1])

#print(arr)

ans=1
start=0
fin=10**10
for i,j in arr:
    if fin > i >= start:
        start = max(i,start)
        if j<=fin:
            fin = min(j,fin)
            #print(i,j)
    elif i >= fin:
        ans+=1
        start = i
        fin = j

print(ans)
        
        

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

 							

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
  ll a,b,c,d,e,k;
	cin>>a>>b>>c>>d>>e>>k;
	if(e-a>k){
		cout<<":(";
		return 0;
	}cout<<"Yay!";
}
	


Measured memory_bytes: 256
s = gets.chomp

ans = 10 ** 9
("a".."z").each do |c|
  count = 0
  t = s.chars

  until t.uniq.count == 1
    (t.length - 1).times do |i|
      t[i] = ([t[i], t[i + 1]].include?(c) ? c : t[i])
    end
    count += 1
    t.pop
  end

  ans = count if count <= ans
end
puts ans


Measured memory_bytes: 1788
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

using ll = long long int;

int main(void) {
  int x, a;
  cin>> x >> a;
  if(x < a)
    std::cout << 0 << std::endl;
  else
    std::cout << 10 << std::endl;
  return 0;
}



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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(const T x, const S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 2000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

int n, m;
int sx, sy;
int tx, ty;
int vx[5555];
int vy[5555];
int maze[5555][5555];

int main()
{
  cin >> n >> m;
  rep(i, n) cin >> vx[i] >> vy[i];
  
  vi x, y;
  rep(i, n){
    x.pb(vx[i]);
    y.pb(vy[i]);
  }
  sort(ALL(x));  x.erase(unique(ALL(x)), x.end());
  sort(ALL(y));  y.erase(unique(ALL(y)), y.end());
  rep(i, n){
    vx[i] = lower_bound(ALL(x), vx[i]) - x.begin();
    vy[i] = lower_bound(ALL(y), vy[i]) - y.begin();
  }
  rep(i, n) maze[vx[i] + 1][vy[i] + 1] += 1;
  rep(i, n + 1) rep(j, n) maze[i][j + 1] += maze[i][j];
  rep(i, n) rep(j, n + 1) maze[i + 1][j] += maze[i][j];
  
  rep(i, m){
    cin >> sx >> sy >> tx >> ty;
    tx += 1;
    ty += 1;
    ll ret = 0;
    int lx = lower_bound(ALL(x), tx) - x.begin();
    int ly = lower_bound(ALL(y), ty) - y.begin();
    int rx = lower_bound(ALL(x), sx) - x.begin();
    int ry = lower_bound(ALL(y), sy) - y.begin();

    ret += maze[lx][ly];
    ret += maze[rx][ry];
    ret -= maze[rx][ly];
    ret -= maze[lx][ry];

    cout << ret << endl;
  }

  return 0;
}

Measured memory_bytes: 109868
n = int(input())
arr = list(map(int,input().split()))

dp = [0 for i in range(n)]
j = 2
dp[0] = 0
dp[1] = abs(arr[1]-arr[0])
for i in range(2,len(arr)):
    op1 = dp[i-1]+abs(arr[i]-arr[i-1])
    op2 = dp[i-2]+abs(abs(arr[i]-arr[i-2]))
    # print('op1',op1,'op2',op2)
    dp[i] = min(op1,op2)

# print(dp)
print(dp[-1])

Measured memory_bytes: 13928
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 1e5 + 20 ;
int ss , n , a[N] , o ;

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

	cin >> ss >> n ;

	for (int i = 0 ; i < n ; i ++) cin >> a[i] , o += a[i] & 1 ;

	if (o > 2) return cout << "Impossible\n" , 0;

	bool fl = 0 ;
	for (int i = 0 ; i < n ; i ++) {
		if (!fl && (a[i] & 1)) swap(a[0] , a[i]) , fl = 1 ;
		else if (a[i] & 1) swap(a[n - 1] , a[i]) ;
	}

	for (int i = 0 ; i < n ; i ++) cout << a[i] << ' ' ; cout << '\n' ;

	vector <int> vec ;
	if (a[0] > 1) vec.push_back(a[0] - 1) ; 
	for (int i = 1 ; i < n - 1 ; i ++) vec.push_back(a[i]) ;
	if (n > 1) vec.push_back(a[n - 1] + 1) ;
	else vec.push_back(1) ;

	cout << vec.size() << '\n' ;
	for (int x : vec) cout << x << ' ' ;
	cout << '\n' ;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int n, x = INF;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a, p = 0;
        cin >> a;
        while(a % 2 == 0){
            a/=2;
            p++;
        }
        x = min(x, p);

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


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int ans = 1;
		for(int i = 0 ; i < n ; i++) {
			if(ans * 2 > ans + k) {
				ans += k;
			} else {
				ans *= 2;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
//2017-8-22
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define Forr(i, a, b) for(int i = (a); i >= (int)(b); --i)

#define N (100000+5)

int r[N], a[N], b[N], ans[N];
int odd[N], even[N], n1, n2;

int main(){
	int n, m, sum = 0;
	
	scanf("%d%d", &n, &m);
	For(i, 1, m){
		scanf("%d", &r[i]);
		sum += r[i];
	}

	if(m == 1){
		printf("%d\n", r[1]);
		if(n == 1) printf("1\n1\n");
		else printf("2\n%d %d\n", 1, r[1]-1);
		return 0;
	}

	if(m == 2 && r[1] == 1 && r[2] == 1){
		printf("1 1\n");
		printf("1\n2\n"); return 0;
	}

	if(m == 2){
		sort(r+1, r+m+1);
		For(i, 1, m) printf("%d ", r[i]); puts("");
		if(r[1] == 1) printf("1\n%d\n", r[1]+r[2]);
		else printf("2\n%d %d\n", r[1]+1, r[2]-1);
		return 0;
	}

	For(i, 1, m) if(r[i]%2) odd[++n1] = r[i]; else even[++n2] = r[i];	
	
	int an = 0;
	if(n1 == 1){
		printf("%d ", odd[1]);
		For(i, 1, n2) printf("%d ", even[i]); puts("");

		if(odd[1] > 1) ans[++an] = odd[1]-1;
		if(n2) ans[++an] = 2; else ans[++an] = 1;
		For(i, 1, n2-1) ans[++an] = even[i];
		if(even[n2] > 1) ans[++an] = even[n2]-1;
	
	}else if(n1 == 2){
		printf("%d ", odd[1]);
		For(i, 1, n2) printf("%d ", even[i]); puts("");
		printf("%d ", odd[2]);

		if(odd[1] > 1) ans[++an] = odd[1]-1;
		ans[++an] = 2;
		For(i, 1, n2) ans[++an] = even[i];
		if(odd[2] > 1) ans[++an] = odd[2]-1;
	}else if(!n1){
		For(i, 1, n2) printf("%d ", even[i]);
		ans[++an] = 1;
		For(i, 1, n2-1) ans[++an] = even[i];
		if(even[n2] > 1) ans[++an] = even[n2]-1;
	}else{
		puts("Impossible"); return 0;
	}

	printf("%d\n", an);
	For(i, 1, an) printf("%d ", ans[i]); puts("");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
typedef long long ll;
/**
 * Uncomment the #define below if problem contains multiple test cases
 */
// #define MULTIPLE_TESTS 1

void solve() {
  int n;
  cin >> n;

  int res = n % 1000;
  int used = n / 1000;
  if (res != 0) {
    res -= 1000;
  }
  cout << abs(res) << endl;
}

int main() {
  FAST_IO;
  int t = 1;
#ifdef MULTIPLE_TESTS
  cin >> t;
#endif

  while (t--) {
    solve();
  }

  return 0;
}

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

int X;

int main(){
  cin >> X;
  if (X==7 or X==5 or X==3) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

int main() {
  vector<char> n(3);
  for (int i =0;i < 3;i++) {
  cin >> n.at(i);
  }

  if (n.at(0) == n.at(2)) {
     cout << "Yes" << endl;
  }
  else {
     cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	int h,w,n;
	cin >> h >> w >> n;
	int big = max(h, w);
	cout << (n + big - 1) / big << endl;
}

Measured memory_bytes: 256