akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
    int n, A[100];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> A[i];
        
    for (int i = n - 1; i >= 0; i-- ){
        if (i != n - 1) cout << " ";
    
        cout << A[i];
    }
    
    cout << endl;
    
            
    return 0;
}

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

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

  double ans = 0.0;
  double prob = 1.0 / (double)n;
  for (int i = 0; i < n; i++) {
    int dice = i + 1;
    if (dice >= k) {
      ans += 1.0;
      continue;
    }

    int coin = 0;
    while (dice < k) {
      coin++;
      dice *= 2;
    }
    ans += pow(0.5, coin);
  }
  ans *= prob;
  printf("%.10lf\n", ans);
}

Measured memory_bytes: 640
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
T = LIST()
M = INT()
PX = [LIST() for _ in range(M)]

for p, x in PX:
	tmp = T.copy()
	T[p-1] = x
	print(sum(T))
	T = tmp


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

using namespace std;

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

const int N = 1e5 + 5;

ll l,r;
ll f(ll n) {
  if (n <= 4) {
    int res = 0;
    for (int i = 1 ; i <= n ; i++)
     res ^= i;
    return res;
  }
  ll res = 0;
  ll k = n / 4 * 4;
  k += 3;
  if (k >= n)
    k -= 4;
  for (ll i = k + 1 ; i <= n ; i++)
    res ^= i;
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> l >> r;
  cout << (f(l - 1) ^ f(r)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
typedef long long ll;

int n,k,m;
string s,t;

int main() {
  cin >> n ;
  int x[n];
  rep(i,n) cin >> x[i];
  int a[n]; 
  rep(i,n) a[i]=x[i];
  sort(a,a+n);
  rep(i,n){
    if(x[i]<=a[n/2-1])
    cout << a[n/2] << endl;
    else 
    cout << a[n/2-1] << endl;
  }
}

Measured memory_bytes: 3712
using System;
public class Box {
    public static void Main() {
        long N = long.Parse(Console.ReadLine());
        string[] read = new string[N];
        read = Console.ReadLine().Split(' ');
        int[] A = new int[N];
        long sum = 0;
        long sumlo = 0;
        for (int i = 0; i < N; i++) {
            sumlo += i + 1;
        }
        for (int i = 0; i < N; i++) {
            A[i] = int.Parse(read[i]);
            sum += A[i];
        }
        if (sum % sumlo != 0) {
            Console.WriteLine("NO");
        } else {
            long loop = sum / sumlo;
            bool NO = false;
            long check = 0;
            for (int i = 0; i < N; i++) {
                if (i == N - 1) {
                    check = A[0] - A[N - 1];
                } else {
                    check = A[i + 1] - A[i];
                }
                NO = true;
                if ((check - loop) % N == 0) {
                    if (check - loop <= 0) {
                        if ((check - loop) / N >= -1 * loop) {
                            NO = false;
                        }
                    }
                }



                /*for (int j = 0; j <= loop; j++) {
                    NO = true;
                    if (i == N - 1) {
                        if (A[0] - A[N-1] == loop - j * N) {
                            NO = false;
                            break;
                        }
                    } else {
                        if (A[i + 1] - A[i] == loop - j * N) {
                            NO = false;
                            break;
                        }
                    }
                }*/

                if (NO) {
                    break;
                }
            }
            if (NO) {
                Console.WriteLine("NO");
            } else {
                Console.WriteLine("YES");
            }
        }


    }
}

Measured memory_bytes: 12888
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

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

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  
  int a,b;cin>>a>>b;
  if((a+b)%2)cout << "IMPOSSIBLE" << endl;
  else cout << (a+b)/2 << endl;
}

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

int main(){
    string s; cin >> s;
    char memo=s[0];
    int ans=0;
    if(s[0]!='0') ans++;
    s[0]='0';
    for(int i=1; i<s.length(); i++){
        if(i%2==0){
            if(s[i]!='0') ans++;
        }
        if(i%2==1){
            if(s[i]!='1') ans++;
        }
    }
    int ans2=0;
    s[0]=memo;
    if(s[0]!='1') ans2++;
    s[0]='1';
    for(int i=1; i<s.length(); i++){
        if(i%2==0){
            if(s[i]!='1') ans2++;
        }
        if(i%2==1){
            if(s[i]!='0') ans2++;
        }
    }
    cout << min(ans,ans2) << endl;
return 0;
}

Measured memory_bytes: 512
W, H, N = map(int, input().split())
x0, y0 = 0, 0

for _ in range(N):
    xi, yi, a = map(int, input().split())
    if a == 1:
        x0 = max(xi, x0)
    elif a == 2:
        W = min(xi, W)
    elif a == 3:
        y0 = max(yi, y0)
    elif a == 4:
        H = min(yi, H)

ans = (W-x0)*(H-y0)
# if ans < 0:
#     ans = 0
# print(ans)
print(ans if x0 < W and y0 < H else 0)

Measured memory_bytes: 3064
import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))


def f(s, t):
	# print(s, t)
	ans = 0
	for i in range(len(t)):
		ans += (s[i] != t[i])
	return(ans)

def main():
	s = input().strip(); t = input().strip()
	ans = f(s, t)

	for i in range(1, len(s)-len(t)):
		ans = min(ans, f(s[i:i+len(t)], t))
	print(ans)


if __name__ == "__main__":
	main()


Measured memory_bytes: 85592
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n;
    cin>>n;
    int a=1,b=1;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        int p=max((a+x-1)/x,(b+y-1)/y);
        a=p*x;
        b=p*y;
    }
    cout<<a+b<<endl;
    return 0;
}

Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

def main():
    N, K = geta(int)
    h = geta(int)

    INF = 1 << 60
    dp = [INF] * N
    dp[0], dp[1] = 0, abs(h[0] - h[1])

    for i in range(2, N):
        lb = i - K if i > K else 0
        for j in range(lb, i):
            tmp = dp[j] + abs(h[j] - h[i])
            if tmp < dp[i]:
                dp[i] = tmp

    print(dp[N - 1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 13928
#include "bits/stdc++.h" // {{{
using namespace std;
#define val         const auto
#define eb          emplace_back
#define emp         emplace
#define fi          first
#define se          second
#define X           first
#define Y           second
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i < (int)(n); ++i)
#define ALL(x)      begin(x), end(x)
#define TMPLT(T,U)  template<class T, class U>
#define ten(p)      ((long long)(1e##p))
#define FILL(a,v)   memset((a), (v), sizeof(a))
#define FAST()      ios::sync_with_stdio(false), cin.tie(nullptr)
#ifndef DEBUG
#define debug(...)
#define show(x)
#define show2(x,y)
#define LN()
#endif
typedef long long ll;
typedef pair<int,int> pii;
namespace ydk{
TMPLT(T,U) inline bool chmax(T &a, U b){return b>a ? a=b,1 : 0;}
TMPLT(T,U) inline bool chmin(T &a, U b){return b<a ? a=b,1 : 0;}
TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y)
{ return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); }
TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; }
constexpr int INF   = 0x3f3f3f3f;
constexpr ll LINF   = 0x3f3f3f3f3f3f3f3fLL;
// }}}

constexpr int MX = ten(4) + 10;

void Xx_main_xX()
{
    int N, W;
    int v[MX], w[MX];
    static int dp[2][MX];

    cin >> N >> W;
    rep(i, N) cin >> v[i] >> w[i];

    FILL(dp, 0);
    int *now = dp[0],  *nxt = dp[1];

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= W; ++j) {
            chmax(nxt[j], now[j]);
            if (j + w[i] <= W) {
                chmax(nxt[j + w[i]], nxt[j]+v[i]);
            }
        }
        swap(now, nxt);
    }

    outl(now[W]);
    return;
}

} // {{{

signed main(){cout << fixed << setprecision(9); ydk::Xx_main_xX(); return 0;} // }}}




Measured memory_bytes: 3208
#include<stdio.h>
int main(void)
{
    int count[26],i;
    char in;
    for(i=0;i<26;i++)
    {
        count[i] = 0;
    }
    while( scanf("%c",&in)!= EOF )
    {
        if(in>='a' &&in<='z') count[in-'a']++;
        else if(in>='A'&&in<='Z') count[in-'A']++;
    }
    for(i=0;i<26;i++)
    {
        printf("%c : %d\n",97+i,count[i]);
    }
    return 0;
}

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

int H, W;
string s[100];
bool vis[100][100];
bool dfs(int x, int y) {
    if (x == H-1 && y == W-1) return true;
    vis[x][y] = true;
    const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
    for (int i = 0; i < 4; i++) {
        int u = x + dx[i], v = y + dy[i];
        if (0 <= u && u < H && 0 <= v && v < W
            && s[u][v] != '#' && !vis[u][v] && dfs(u, v))
            return true;
    }
    return false;
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) cin >> s[i];
    const string req[4] = {"6314", "2020", "1364", "5050"};
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            if (s[i][j] != req[i%4][j%4]) s[i][j] = '#';
    cout << (dfs(0, 0) ? "YES\n" : "NO\n");
}



Measured memory_bytes: 3708
n,l=map(int,input().split())
t=list(map(int,input().split()))
for i in range(n-1):
    if t[i]+t[i+1]>=l:
        print('Possible')
        print(*(list(range(1,i+1))+list(range(n-1,i+1,-1))),sep='\n')
        print(i+1)
        exit()
print('Impossible')

Measured memory_bytes: 19996
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int a,b,x,y,z,ans;
    cin >> a>> b;
    x=a+b;
    y=a-b;
    z=a*b;
    
    if( (x>=y) && (x>=z) )ans = x;
    if( (y>=x) && (y>=z) )ans = y;
    if( (z>=x) && (z>=y) )ans = z;
    cout << ans <<endl;    
    return 0;
}

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

const int N = (2e5) + 5;
int n, a[N];
int k;

int main() { // claudio van
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  if (k < n) {
    sort(a, a + n);
    ll sum = 0;
    for (int i = 0; i < n - k; ++i) {
      sum += a[i];
    }
    cout << sum << "\n";
  } else {
    cout << 0 << "\n";
  }
  return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <unordered_map>

using namespace std;

typedef long long ll;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> s(1e6 + 1, 0);
	vector<int> small;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < 1000) {
			small.push_back(a[i]);
		}
		else {
			for (int j = 1; j <= 1000; j++) {
				if (a[i] * j > 1e6)
					break;
				s[a[i] * j]++;
			}
		}
	}

	int otv = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] < 1000) {
			int ok = 0;
			for (int x : small) {
				if (x == a[i] && ok == 0) {
					ok = 1;
					continue;
				}
				else if (x == a[i] && ok == 1) {
					ok = 2;
					break;
				}
				
				if (a[i] % x == 0) {
					ok = 2;
					break;
				}
			}

			if (ok != 2)
				otv++;
		}
		else {
			int ok = 0;
			if (s[a[i]] != 1)
				ok = 2;
			for (int x : small) {
				if (a[i] % x == 0) {
					ok = 2;
					break;
				}
			}
			if (ok != 2)
				otv++;
		}
	}

	cout << otv;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 8936
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int A,B,C,D;
int main(){
  cin>>A>>B>>C>>D;
  prin(max(A*B,C*D));
  return 0;
}


Measured memory_bytes: 256
def solve(X):
    for a in range(1 + X // 100):
        for b in range(1 + X // 101):
            for c in range(1+ X // 102):
                for d in range(1 + X // 103):
                    for e in range(1 + X // 104):
                        for f in range( 1 + X // 105):
                            if a*100 + b*101+ c*102 + d * 103 + e * 104 + f * 105 == X:
                                return 1
                            elif a*100 + b*101+ c*102 + d * 103 + e * 104 + f * 105 > X:
                                break
                #        if a*100 + b*101+ c*102 + d * 103 + e * 104 + f * 105 > X:
                 #           break
              #      if a*100 + b*101+ c*102 + d * 103 + e * 104 + f * 105 > X:
               #         break
            #    if a*100 + b*101+ c*102 + d * 103 + e * 104 + f * 105 > X:
             #       break
          #  if a*100 + b*101+ c*102 + d * 103 + e * 104 + f * 105 > X:
           #     break
        #if a*100 + b*101+ c*102 + d * 103 + e * 104 + f * 105 > X:
         #   break
    return 0

X = int(input())
print(solve(X))

Measured memory_bytes: 42988
import java.util.Scanner;


public class Main {

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

	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int x = sc.nextInt();

	int sumv, cnt=0;
	for ( int i=0; i<a+1; i++ ) {
	    for ( int j=0; j<b+1; j++ ) {
		for ( int k=0; k<c+1; k++ ) {
		    sumv = 500*i + 100*j + 50*k;
		    if ( sumv == x ) {
			cnt++;
		    }
		}
	    }
	}
	System.out.println(cnt);
    }
    
}

Measured memory_bytes: 24148
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(ins):
    n, k, *h = map(int, ins.split())
    costs = [0] * n
    for i, _h in enumerate(h):
        if i == 0:
            continue
        start = max(0, i - k)
        cost = min(_c + abs(_h - _h_) for _c, _h_ in zip(costs[start:i], h[start:i]))
        costs[i] = cost
    return costs[-1]


if __name__ == "__main__":
    print(solve("\n".join([input(), input()])))


Measured memory_bytes: 14440
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {

    ll d,t,s;
    cin>>d>>t>>s;
    ll ans;
    ans=s*t;
    if(ans<d)
    cout<<"No"<<endl;
    else
    cout<<"Yes"<<endl;
}


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

int solve(int a, int b) {
	int r;
	r = a % b;
	if (r == 0) return b;
	else return solve(b, r);
}

int main() {
	int a, b;
	int gcd, lcm;

	while (cin >> a >> b) {
		gcd = solve(a, b);
		lcm = a / gcd * b;
		cout << gcd << " " << lcm << endl;
	}

	return 0;
}

Measured memory_bytes: 3080
import math
N=int(input())
A=list(map(int,input().split()))
L=[0]*(N+1)
R=[0]*(N+1)
for i in range(N):
    L[i]=math.gcd(L[i-1],A[i])
for i in range(N-1,0,-1):
    R[i]=math.gcd(R[i+1],A[i])
ans=0
for i in range(0,N):
    ans=max(ans,math.gcd(L[i-1],R[i+1]))
print(ans)


Measured memory_bytes: 21164
pay, num = gets.chomp.split
unluck_num = gets.chomp.split.map(&:to_i).sort

def like_it?(num, pay)
 num.each { |n|  return false if pay.to_s.chars.map(&:to_i).include?( n ) }
 return true
end

until like_it?( unluck_num, pay)
 pay = pay.to_i + 1
end
puts pay


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

const long long mod = 1e9 + 7;
long long n, k;
int u, v;
vector<int>edge[100000 + 5];
long long ans[100000 + 5];
bool vis[100000 + 5];
long long sumvis[100000 + 5];
void dfs(int u, int fa)
{
	vis[u] = 1;
	sumvis[u]++;
	int up = edge[u].size();
	int temp = k;
	for (int i = 0; i < up; i++)
	{
		int v = edge[u][i];
		sumvis[v]++;
		temp -= sumvis[v] - 1;
	}
	temp = max(0, temp);
	ans[u] = temp;
	for (int i = 0; i < up; i++)
	{
		int v = edge[u][i];
		if (v != fa)
			dfs(v, u);
	}
}

int main()
{
	scanf("%lld%lld", &n, &k);
	for (int i = 1; i <= n-1; i++)
	{
		scanf("%d%d", &u, &v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	dfs(1, 0);
	ans[0] = 1ll;
	for (int i = 1; i <= n; i++)
		ans[i] = ans[i] * ans[i - 1] % mod;
	cout << ans[n] << endl;
	return 0;
}

Measured memory_bytes: 10880
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n;
		// n=s.length();
		ll a[n];
		rep(i,n)
		{
			cin>>a[i];
		}
		a[0]--;
		repe(i,1,n-1)
		{
			if(a[i]<a[i-1])
			{
				cout<<"No";
				return 0;
			}
			if(a[i]>a[i-1]) a[i]--;
		}
		if(n==1 || a[n-1]>=a[n-2]) cout<<"Yes";
		else cout<<"No";
		
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#define INF 100000000
using namespace std;

int main(){
        int N;cin >> N;
        int ans = INF;
        vector<long long> A(N);

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

        for(int i=0;i<N;i++){
                int x=0;
                while(A[i]%2 == 0){
                        A[i] /= 2;
                        x++;
                }
            ans = min(ans, x);
        }
        cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int t = scanner.nextInt();

        final List<Food> list = IntStream.range(0, n)
                .mapToObj(i -> new Food(scanner.nextInt(), scanner.nextInt()))
                .collect(Collectors.toList());

        final int[][] naturalDp = dp(list, n, t);
        Collections.reverse(list);
        final int[][] reverseDp = dp(list, n, t);
        Collections.reverse(list);

        int max = 0;
        for (int i = 0; i < n; i++) {
            final int deliciousness = list.get(i).deliciousness;
            for (int j = 0; j < t; j++) {
                final int current = (i > 0 ? naturalDp[i - 1][j] : 0) + (i < n - 1 ? reverseDp[n - i - 2][t - 1 - j] : 0) + deliciousness;
                max = Math.max(max, current);
            }
        }

        System.out.println(max);
    }

    private static int[][] dp(final List<Food> list, final int n, final int t) {
        final int[][] dp = new int[n][t];
        for (int i = list.get(0).time; i < t; i++) {
            dp[0][i] = list.get(0).deliciousness;
        }
        for (int i = 1; i < n; i++) {
            System.arraycopy(dp[i - 1], 0, dp[i], 0, t);
            final Food food = list.get(i);
            for (int j = 0; j < t - food.time; j++) {
                dp[i][j + food.time] = Math.max(dp[i][j + food.time], dp[i - 1][j] + food.deliciousness);
            }
        }

        return dp;
    }

    private static class Food {
        final int time;
        final int deliciousness;

        Food(final int time, final int deliciousness) {
            this.time = time;
            this.deliciousness = deliciousness;
        }
    }
}


Measured memory_bytes: 121960
def give(list):
    i=0
    count=0
    count1=0
    while i<len(list)-2:
        if list[i]=='A':
            count1+=1
            if list[i]=='A' and list[i+1]=='B' and list[i+2]=='C':
                list[i+2]='A'
                
                i+=2
                count+=count1
                count1-=1
                
            else:
                i+=1
        else:
            count1=0
            i+=1
    return count
s=list(input())
print(give(s))


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  cin >> A;
  vector<int> vec(A);
  int sum = 0;
  for(int i=0;i<A;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  
  for(int i=0;i<A-1;i++){
    sum += vec.at(i);
  }
  cout << sum + vec.at(A-1)/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn=1e5+5;
int h[maxn],m,n;
vector<ll > g[maxn];
int main()
{
 cin>>n>>m;
 for(int i=0;i<n;i++) cin>>h[i];
 for(int i=1;i<=m;i++) 
 {
 	 int a,b;
	  cin>>a>>b;
	  a--,b--;
	  g[a].push_back(b);
	  g[b].push_back(a);
 }
ll ans=0;
for(int i=0;i<n;i++)
{
	bool f=true;
	for(int j=0;j<g[i].size();j++)
	{
		
		  if(h[g[i][j]]>=h[i])f=false;
	}
	if(f)ans++;
}
cout<<ans;
return 0;
}


Measured memory_bytes: 9832
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
int main(){
	
	char s[1000];
	while(cin.getline(s,1000)){
		for(int i=0;s[i]!='\0';i++){
			if(((s[i]-s[i+1]+26)%26=='t'-'h')&&(((s[i+1]-s[i+2]+26)%26==('h'-'e'+26)%26)||(((s[i+1]-s[i+2]+26)%26==('h'-'i'+26)%26)&&((s[i+2]-s[i+3]+26)%26==('i'-'s'+26)%26))||(((s[i+1]-s[i+2]+26)%26==('h'-'a'+26)%26)&&((s[i+2]-s[i+3]+26)%26==('a'-'t'+26)%26)))){
				for(int j=0;s[j]!='\0';j++){
					if((s[j]!=' ')&&(s[j]!='.')&&(s[j]!='\n')){
						putchar((s[j]+'t'-s[i]-'a'+26)%26+'a');
					}else{
						putchar(s[j]);
					}
				}cout<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1112
#include<algorithm>
#include<cmath>
#include<cstdint>
#include<cstdio>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(b); ++i)
#define rep(i,n) for(int i=0; i<n; ++i)
#define all(v) begin(v), end(v)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const double PI = acos(-1.0);

bool check(vector<string> vs) {
        int used[13] = {};
        int h = vs.size();
        int w = vs[0].size();
        int nf = 0;
        int nfidx = 0;

        rep(i, w) {
                if (used[i]) continue;
                bool found = false;
                loop(j, i+1, w) {
                        if (used[j]) continue;
                        bool ok = true;
                        rep(k, h) {
                                if (vs[k][i] != vs[h-1-k][j]) {
                                        ok = false;
                                        break;
                                }
                        }
                        if (ok) {
                                found = true;
                                used[i] = 1;
                                used[j] = 1;
                                break;
                        }
                }
                if (!found) {
                        nf++;
                        nfidx = i;
                        if (w % 2 == 0) {
                                return false;
                        }
                        if (2 <= nf) {
                                return false;
                        }
                }
        }

        if (w % 2 == 0) {
                return true;
        }

        rep(k, h) {
                if (vs[k][nfidx] != vs[h-1-k][nfidx]) {
                        dump(h-1-k);
                        return false;
                }
        }

        return true;
}

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

  int h, w;
  cin >> h >> w;
  vector<string> in(h);
  rep(i,h) cin >> in[i];

  rep(_, 500000) {
          random_shuffle(all(in));
          if (check(in)) {
                  cout << "YES" << endl;
                  return 0;
          }
  }

  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class aizu_judge
{
    static void Main()
    {
        int count = 0;
        int[] num = Console.ReadLine().Split().Select(int.Parse).ToArray();
        for (int i = num[0]; i < num[1] + 1;i++ )
        {
            if (num[2] % i == 0)
                count++;
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 9552
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int n; std::cin >> n;

  std::vector<int> ans(n+1);
  rep(x,std::sqrt(n)) rep(y,std::sqrt(n)) rep(z,std::sqrt(n)) {
    if ( x <= 0 || y <= 0 || z <= 0 ) continue;
    int t = x*x + y*y + z*z + x*y + y*z + z*x;
    if ( t > n ) continue;
    ans[t]++;
  }

  for(int i=1; i<=n; i++) std::cout << ans[i] << std::endl;
  return 0;
}



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

using namespace std; 

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


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


ll N;

ll hoge(ll v) {
	v--;
	if(v && N%v==N/v) {
		return v;
	}
	return 0;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	ll ret=0;
	for(ll a=1;a*a<=N;a++) if(N%a==0) {
		ret+=hoge(a);
		if(a*a!=N) ret+=hoge(N/a);
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>


using namespace std;

namespace {

}

int main()
{
	set<char> head = { 'M', 'A', 'R', 'C', 'H' };

	int N = 0;
	cin >> N;

	vector<string> S(N);
	map<char, int> number;

	for (auto& elem : S){
		cin >> elem;
		if (head.find(elem[0]) != head.end()){ // なければ追加。
			++number[elem[0]];
		}
	}

	long long sum = 0;
	set<set<char>> used;
	for (auto& elem1 : number){ 
		for (auto& elem2 : number){
			if (elem1.first == elem2.first){
				continue;
			}
			for (auto& elem3 : number){
				set<char> curCmb = { elem1.first, elem2.first, elem3.first };
				if (curCmb.size() < 3){
					continue;
				}

				if (used.find(curCmb) == used.end()){
					// まだ使用していない。
					used.insert(curCmb);
					sum += static_cast<long long>(number[elem1.first]) * number[elem2.first] * number[elem3.first];
				}
			}
		}
	}

	cout << sum;

	return 0;
}

Measured memory_bytes: 6144
module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = int
printer = unlines . (:[]) . show

solver x = (x + 1) `div` 2

Measured memory_bytes: 508
#include <stdio.h>

int main(){
    long long unsigned int h, w;
    scanf("%llu %llu", &h, &w);

    if(h == 1 || w == 1){
        printf("%d\n", 1);
        return 0;
    }

    long long unsigned int ans = 0;
    for(long long unsigned int i=0; i<w; i++){
        if(i%2==0){
            ans+= (h+1)/2;
        }else{
            ans+= h/2;
        }
    }
    printf("%llu\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod=1e9+7;
       

int main(){
 ll h,k;
  cin >>h >>k;
  if(h==1 || k==1){cout << 1 << endl;
                  return 0;}
  if(h%2==1 && k%2==1){cout << h*k/2+1 << endl;}else{cout << h*k/2 << endl;}
}

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

#define eps 1e-10

int main() {

  long long int n, q;
  cin >> n >> q;

  vector< long long int > x, y, z, r, l;

  for ( long long int i = 0; i < n; i++ ) {

    long long int in_x, in_y, in_z, in_r, in_l;
    cin >> in_x >> in_y >> in_z >> in_r >> in_l;
    x.push_back( in_x );
    y.push_back( in_y );
    z.push_back( in_z );
    r.push_back( in_r );
    l.push_back( in_l );

  }

  vector< long long int > sx, sy, sz, dx, dy, dz;

  for ( long long int i = 0; i < q; i++ ) {

    long long int in_x, in_y, in_z;
    cin >> in_x >> in_y >> in_z;
    sx.push_back( in_x );
    sy.push_back( in_y );
    sz.push_back( in_z );
    cin >> in_x >> in_y >> in_z;
    dx.push_back( in_x );
    dy.push_back( in_y );
    dz.push_back( in_z );

  }

  for ( long long int i = 0; i < q; i++ ) {

    long long int ans = 0;

    long long int vx = dx[i] - sx[i];
    long long int vy = dy[i] - sy[i];
    long long int vz = dz[i] - sz[i];

    for ( long long int j = 0; j < n; j++ ) {

      long long int vsx = x[j] - sx[i];
      long long int vsy = y[j] - sy[i];
      long long int vsz = z[j] - sz[i];
      long long int vdx = x[j] - dx[i];
      long long int vdy = y[j] - dy[i];
      long long int vdz = z[j] - dz[i];

      long long int vs = vsx * vx + vsy * vy + vsz * vz;
      long long int vd = vdx * -vx + vdy * -vy + vdz * -vz;

      if ( vs > 0 && vd > 0 ) {

	double a = sqrt( vsx * vsx + vsy * vsy + vsz * vsz );
	double b = sqrt( vx * vx + vy * vy + vz * vz );
	double c = sqrt( vdx * vdx + vdy * vdy + vdz * vdz );

	double h = sqrt( ( a * b * 2 + c * c - a * a - b * b ) * ( a * b * 2 - ( c * c - a * a - b * b ) ) ) / ( b * 2 );

	if ( h - r[j] <= eps ) ans += l[j];

      }

    }

    cout << ans << endl;

  }


  return 0;

}

Measured memory_bytes: 1224
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int m = sc.nextInt();
            if(n+m==0)break;
            int[][]data = new int[m][3];
            int[] com= new int[n];
            com[0]=1;
                    
            for (int i = 0; i < data.length; i++) {
                data[i][0]=sc.nextInt();
                data[i][1]=sc.nextInt()-1;
                data[i][2]=sc.nextInt()-1;
            }
            Arrays.sort(data,new Comparator<int[]>(){
                @Override
                public int compare(int[] arg0, int[] arg1) {
                    return arg0[0]-arg1[0];
                }
            });
            for (int i = 0; i < data.length; i++) {
                int s = data[i][1];
                int d = data[i][2];
                if(com[s]>0){
                    com[d]=1;
                }
            }
            int ans=0;
            for (int i = 0; i < com.length; i++) {
                if(com[i]>0)ans++;
            }
            System.out.println(ans);
        }
    }

}

Measured memory_bytes: 177444
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define INF 9223372036854775807
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0;
string s;
bool flag;
#pragma endregion
#define MAX 111111


int main(void) {
  vll a, b;
  cin >> n;
  FOR(i, 0, n) {
	cin >> tmp;
	a.pb(tmp);
	cin >> tmp;
	b.pb(tmp);
  }
  RFOR(i, 0, n) {
	a[i] += ans;
	if (a[i] % b[i] != 0) ans += b[i] - (a[i] % b[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2156
def main():

    N = int(input())

    testimony_person = []
    testimony_judge = []

    for i in range(N):
        n = int(input())
        tmp_person = []
        tmp_judge = []
        
        for j in range(n):
            per, jud = map(int, input().split())
            tmp_person.append(per)
            tmp_judge.append(jud)
        
        testimony_judge.append(tmp_judge)
        testimony_person.append(tmp_person)


    max_honest = 0


    for i in range(2 ** N):
        N_honest = 0
        person_A = [0 for i in range(N)]
        person_T = [-1 for i in range(N)]
        FLAG = 1
        
        
        for j in range(N):

            bits = i >> j
            if (bits & 1):
                N_honest += 1
                person_A[j] = 1
                
                for k in range(len(testimony_person[j])):
                    p = testimony_person[j][k]
                    judge = testimony_judge[j][k]

                    if (person_T[p - 1] == -1):
                        person_T[p - 1] = judge
                    elif (person_T[p - 1] != judge):
                        FLAG = 0
                        break
        
        for i in range(N):
            if (person_T[i] != -1 and person_A[i] != person_T[i]):
                FLAG = 0
                break
        
        
        if (FLAG):
            max_honest = max(max_honest, N_honest)

    print(max_honest)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
let _ =
  Scanf.scanf "%d %d %d" @@ fun n h w ->
  Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y))
  |> Array.to_list
  |> List.fold_left (fun ac (a, b) ->
      if a >= h && b >= w then ac+1 else ac) 0
  |> Printf.printf "%d\n"



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define Maxn 100
#define rint register int
using namespace std;

int read() {
  rint s = 0, f = 1; register char ch = getchar();
  while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
  while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); }
  return s * f;
}

int n;
char s[Maxn];
int cnt[Maxn][30], ans[Maxn << 3], tot = 0;

void input() {
  n = read();
  for (rint i = 1; i <= n; ++i) {
  	scanf("%s", s + 1);
		int len = strlen(s + 1);
		for (rint j = 1; j <= len; ++j) ++cnt[i][s[j] - 'a']; 
	}
} 

namespace Solution {
  void solve() {
  	for (rint i = 0; i < 26; ++i) {
  	  rint mn = 0x3f3f3f3f;
  	  for (rint j = 1; j <= n; ++j) mn = min(mn, cnt[j][i]);
  	  for (rint j = 1; j <= mn; ++j) ans[++tot] = i + 'a';
	  }
	  for (rint i = 1; i <= tot; ++i) putchar(ans[i]);
	  puts("");
	}
}

signed main() {
  input();
  Solution :: solve();
  return 0;
}

Measured memory_bytes: 256
import math

def main():
  N = int(input())
 # X = [int(input().split()) for _ in range(N)]
  X = list(map(int,input().split()))
  
  #住民がいる座標の最小値から最大値までで検討する
  start = min(X) 
  end = max(X)
  
  
  power = list()
  ans = 10000000000
  
  for i in range(start, end + 1):
    for n in X:
      power.append((i - n)**2)
    if ans > sum(power):
      ans = sum(power)
      
    power.clear()
    
  print(ans)
  
main()

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

int main(void) {
	int s;
	cin >> s;
	vector<int> vec;
	vec.push_back(s);
	while (true) {
		int size = vec.size();
		int num = vec[size - 1];
		if (num % 2 == 0) {
			num /= 2;
		}
		else {
			num = 3 * num + 1;
		}

		for (int i = 0; i < vec.size(); i++) {
			if (vec[i] == num) {
				cout << size + 1 << endl;
				return 0;
			}
		}
		vec.push_back(num);

	}
}

Measured memory_bytes: 256
digit_number [a, b] = length (show (a + b))

main = do
  s <- getContents
  putStr . unlines . map eachline . lines $ s
  where
    eachline = show . digit_number . map read . words
    -- "2" <- 2 <- [5,7] <- ["5","7"] <- "5 7"

Measured memory_bytes: 4036
a, b, n = map(int, input().split())

ans = 0
if b > n:
    x = n
    ans = int(a * x // b) - int(a * (x // b))
else:
    x = n
    ans1 = int(a * x // b) - int(a * (x // b))
    x = (n//b)*b-1
    ans2 = int(a * x // b) - int(a * (x // b))
    ans = max(ans1,ans2)
print(ans)


Measured memory_bytes: 9196
#include<iostream>
#include<cmath>
using namespace std;
int mmax(int a,int b,int c){
	return max(a,max(b,c));
}
int main(){
	int m,n;
	while(cin>>m>>n){
		cout<<mmax(m-n,m+n,m*n)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
sd = gets.chomp
t = gets.chomp

(sd.size-1).downto(0) do |i|
  if sd[i] == t[0] || sd[i] == '?'
    ok = true
    for j in 0..(t.size-1) do
      if sd[i+j] != '?' && sd[i+j] != t[j]
        ok = false
      end
    end
    if ok
      sd[i, t.size] = t
      puts sd.gsub('?', 'a')
      exit
    end
  end
end
puts 'UNRESTORABLE'


Measured memory_bytes: 2044
N, A, B, C, D = map(int, input().split())
S = '$' + input() + '$'

def isOk(fr, to):
    if S[fr: to + 1].count('##') > 0:
        return False
    return True

if not (isOk(A, C) and isOk(C, D)):
    print('No')
    exit()

def canSwitch():
    if A + 1 == B and D < C and S[A: A + 3] == '...':
        return True
    if B + 1 == A and C < D and S[B: B + 3] == '...':
        return True
    if C + 1 == D and B < A and S[C - 1: D + 1] == '...':
        return True
    if D + 1 == C and A < B and S[D - 1: C + 1] == '...':
        return True
    if A < B and S[B - 1: B + 2] == '...':
        return True
    if B < A and S[A - 1: A + 2] == '...':
        return True
    if C < D and S[C - 1: C + 2] == '...':
        return True
    if D < C and S[D - 1: D + 2] == '...':
        return True
    if S[max(A, B): min(C, D) + 1].count('...'):
        return True
    return False

if A < B and D < C or B < A and C < D:
    if not canSwitch():
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 3700
#include <iostream>
using namespace std;
int main (void) {
    int W, H;
    int N;

    cin >> W >> H >> N;

    int x0 = 0;
    int y0 = 0;
    int x1 = W;
    int y1 = H;
    for (int i = 0; i < N; i++) {
        int x, y;
        int a;
        cin >> x >> y >> a;
        if (a == 1) {
            x0 = max(x0, x);
        } else if (a == 2) {
            x1 = min(x1, x);
        } else if (a == 3) {
            y0 = max(y0, y);
        } else {
            y1 = min(y1, y);
        }
    }

    if (x1 - x0 > 0 && y1 - y0 > 0) {
        cout << (y1 - y0) * (x1 - x0) << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			for (int i = 0; i < n; i++) {
				int ai = sc.nextInt();
				if (ai % 2 == 0) {
					if (ai % 3 == 0 || ai % 5 == 0) {
					} else {
						System.out.println("DENIED");
						return;
					}
				}
			}
			System.out.println("APPROVED");
		}
	}

}


Measured memory_bytes: 23124
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val letters: String = sc.nextLine()
    if (letters.head != 'A') println("WA")
    else if (letters.slice(2, letters.length - 1).filter(_ == 'C').length != 1) println("WA")
    else if (letters.slice(1, letters.length).filter(_.isUpper).length != 1) println("WA")
    else println("AC")
  }

}


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

int N, W;
vector<int> v, w;
int dp[10010];
int rec(int W) {
	if (W == 0) {
		return 0;
	}
	if (dp[W] != -1)return dp[W];
	int res = 0;
	for (int i = 0; i < N; ++i) {
		if (W - w[i] >= 0) {
			res = max(res, rec(W - w[i]) + v[i]);
		}
		else {
			continue;
		}
	}
	return dp[W] = res;
}

int main(void) {

	cin >> N >> W;

	v.resize(N);
	w.resize(N);
	for (int i = 0; i < 10010; ++i) {
		dp[i] = -1;
	}
	for (int i = 0; i < N; ++i) {
		cin >> v[i] >> w[i];
	}
	cout << rec(W) << endl;

	return 0;
}


Measured memory_bytes: 3576
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int Z = sc.nextInt();
		int W = sc.nextInt();
		
		int[] a = new int[N];
		for(int i=0; i<N; i++)
			a[i] = sc.nextInt();
		
		int ans = Math.abs(a[N-1]-W);
		
		int[] dp = new int[N+1];
		
		for(int i=N-1; i>=1; i--) {
			//Y draws Nth
			int min=Math.abs(a[N-1]-a[i-1]);
			
			int maxV=0;
			//Y draws [i+1, N-1]th
			for(int j=N-1; j>i; j--) {
				int max = Math.abs(a[N-1]-a[j-1]);
				if(j<N-1)
					maxV = Math.max(maxV, dp[j+1]);
				max = Math.max(max, maxV);
				if(max<min) {
					min = max;
				}
			}
			dp[i] = min;
		}
		
		for(int i=1; i<N; i++)
			ans = Math.max(ans, dp[i]);
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 28172
#include<bits/stdc++.h>
using namespace std;
long long t[200005];
int main()
{
	long long a;
	scanf("%lld",&a);
	for(int i=1;i<=a;i++)
	{
		scanf("%lld",&t[i]);
	}
	long long max=t[1];
	long long s=0;
	for(int i=2;i<=a;i++)
	{
		if(t[i]<=max)
		{
			s=s+(max-t[i]);
		}
		else
		{
			max=t[i];
		}
	}
	printf("%lld",s);
	return 0;	
} 

Measured memory_bytes: 5268
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[200010];
priority_queue<int>q;
signed main()
{
	int n,i,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1,greater<int>());
	q.push(a[1]);
	for(i=2;i<=n;i++)
	{
		ans+=q.top();
		q.pop();
		q.push(a[i]);
		q.push(a[i]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6864
N, M = [int(str) for str in input().strip().split()]
AB = [[int(str) for str in input().strip().split()] for _ in range(M)]

B_A = [[] for i in range(N + 1)]
for ab in AB:
    B_A[ab[1]].append(ab[0])
for b_a in B_A:
    b_a.sort()


right = 0
ans = 0
for i in range(N + 1):
    if len(B_A[i]):
        if B_A[i][-1] > right:
            ans += 1
            right = i - 1

print(ans)

Measured memory_bytes: 31796
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#define mod 998244853 
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    int a[n], s=0, s1=0, m=10000000;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        s+=a[i];
    }
    for(int i = 0; i < n-1; i++)
    {
        s1+=a[i];
        s-=a[i];
        m=min(m, abs(s1-s));
    }
    cout << m << '\n';
}

Measured memory_bytes: 256
t = int(input())
ans = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
for i in range(t):
    n = input()
    ans[n] += 1
print("AC x %d" %(ans['AC']))
print("WA x %d" %(ans['WA']))
print("TLE x %d" %(ans['TLE']))
print("RE x %d" %(ans['RE']))

Measured memory_bytes: 69876
unittest
{
	assert( [ "3 1", "4 1 5" ].parse.expand.solve == 5 );
	assert( [ "8 9", "7 9 3 2 3 8 4 6" ].parse.expand.solve == 0 );
	assert( [ "3 0", "1000000000 1000000000 1000000000" ].parse.expand.solve == 3000000000 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto hs = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], hs );
}

auto solve( long k, long[] hs )
{
	hs.sort();
	if( hs.length <= k ) return 0;
	else                 return hs[ 0 .. $ - k ].sum;
}


Measured memory_bytes: 11632