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

using namespace std;

typedef long long LL;
typedef vector<int>    VI;
typedef vector<vector<int>>    VVI;
typedef vector<bool>   VB;
typedef vector<string> VS;

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define RANGE(x, min, max) min <= x && x <= max

const int DX[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int DY[] = {-1, -1, -1, 0, 0, 1, 1, 1};

int w, h;
VVI cs;

void dfs(int y, int x) {
	cs[y][x] = 0;
	rep (i, 8) {
		int ny = y + DY[i];
		int nx = x + DX[i];
		if (RANGE(nx, 0, w - 1) && RANGE(ny, 0, h - 1) && cs[ny][nx]) {
			dfs(ny, nx);
		}
	}
}

int main(void) {
	while (1) {
		cs.clear();
		cin >> w >> h;
		if (w == 0 && h == 0) break;
		cs.resize(h, VI (w));
		rep (i, h) rep (j, w) {
			cin >> cs[i][j];
		}
		int ans = 0;
		rep (i, h) rep (j, w) {
			if (!cs[i][j]) continue;
			dfs(i, j);
			ans++;
		}
		cout << ans << endl;
	}
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    vector<int> cnt(2003, 0);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = a[i] + 1; j <= 2000; j++) {
            ans += cnt[j];
        }

        for (int j = 0; j < i; j++) {
            cnt[a[i] + a[j]]++;
        }
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;


int N;
int a[101];

ll jijo(int x){
    ll ans=0;
    REP(i,N){
        ans+=(a[i]-x)*(a[i]-x);
    }
    return ans;
}

int main(){
    
    cin>>N;
    REP(i,N)cin>>a[i];
    
    ll ans=1e10;
    for(int i=-100;i<=100;i++){
        ans=min(ans,jijo(i));
    }
    
    cout<<ans<<endl;
    
    return 0;
}

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

int main()
{

    ll n,i,j,k,l,a,b,c,d,m,f1,f2,s,x;

    cin>>n;
    c=0;
    j=n-1;
    k=(j*(j+1))/2;
    cout<<k<<endl;

    return 0;
}


Measured memory_bytes: 256
def is_prime(n):
    if n == 2:
        return True
    if (n < 2) or (n % 2 == 0):
        return False
    stop = int(n**0.5) + 1
    for i in range(3, stop, 2):
        if n % i == 0:
            return False
    return True

x = int(input())
while not is_prime(x):
    x += 1
print(x)

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

using namespace std;

#define ops cout<<"ops"<<endl;
#define freopens freopen("cowpatibility.in", "r", stdin);freopen("cowpatibility.out", "w", stdout);
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define DIM 100007
#define DIMM 50007
#define INF 10000000000000000007.0
#define X 31
#define eps 0.0000001
#define PI 3.14159265358979323846
#define MAX 25
#define MODULO (long long)1000000007

const long double gr=(1+sqrt(5))/2;

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I,I> pII;
typedef pair<ll,ll> pllll;
typedef pair<ld,ld> pldld;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef char cr;
typedef string str;

ll n,k;
ll a[DIM],d[DIM];

int main()
{
    //ops;
    //freopens;
    fast;
    //ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4;

    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    d[2]=abs(a[1]-a[2]);
    for(int i=3;i<=n;i++){
     d[i]=INF;
     for(int j=1;j<=k;j++){
      if((i-j)<1)break;
      d[i]=min(d[i],(d[i-j]+abs(a[i-j]-a[i])));
     }
    }
    cout<<d[n]<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,k;
    cin>>n>>k;
    ll ans=1;
    ll tmp=k;
    for(ll i=0; i<n; i++) {
        if(tmp > n){
            break;
        }else{
            tmp = tmp*k;
            ans++;
        }
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int r = scan.nextInt();
        int g = scan.nextInt();
        int b = scan.nextInt();
        int x = 100 * r + 10 * g + b;
        boolean answer = x % 4 == 0;
        System.out.println(answer ? "YES" : "NO");
    }
}


Measured memory_bytes: 21844
use std::vec::Vec;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (a, b, c, d) = {
      let v: Vec<i64> = read_vec();
      (v[0], v[1], v[2], v[3])
    };

    if (a - c).abs() <= d || ((a - b).abs() <= d && (b - c).abs() <= d) {
      println!("Yes");
    } else{
      println!("No");
    }
}


Measured memory_bytes: 4352
N, M = map(int, input().split())
S = str(input())
T = str(input())

from fractions import gcd
L = N * M // gcd(N, M)
step_s = L // M
step_t = L // N
stop = N // step_s
flag = True

for i in range(stop):
  #print(i, S[i * step_s], T[i * step_t])
  if S[i * step_s] != T[i * step_t]:
    flag = False
    break

if flag:
  print(L)
else:
  print(-1)

Measured memory_bytes: 5304
main = do
  _      <- getLine
  colors <- getLine
  let noRs = length $ filter (== 'R') colors
  let noWs = length $ filter (== 'W') colors
  let scanFunction ((rL, wL), (rR, wR)) 'R' = ((rL + 1, wL), (rR - 1, wR))
      scanFunction ((rL, wL), (rR, wR)) 'W' = ((rL, wL + 1), (rR, wR - 1))
  let ops ((rL, wL), (rR, wR)) = max wL rR
  print $ minimum $ map ops $ scanl scanFunction ((0, 0), (noRs, noWs)) colors


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string S;
    cin >> S;

    int max = 0;
    REP(i, S.length())
    {
        if (S[i] == 'A')
        {
            FOR(j, S.length(), i + 1)
            {
                if (S[j] == 'Z')
                {
                    max = j - i + 1;
                }
            }
            break;
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int x;
	int y;
	int i;
	int a;
	
	while (1){
		scanf("%d %d", &x, &y);
		
		if (x == 0 && y == 0){
			break;
		}
		
		if (x <= y){
			printf("%d %d\n", x, y);
		}
		else if(y < x){
			printf("%d %d\n", y, x);
		}
	}
	
	return (0);
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int a[202020],b[202020];
long long suma[202020],sumb[202020];
int main()
{
	int l,n;
	long long ans=0;
	scanf("%d%d",&l,&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=l-a[i];
	}
	suma[0]=sumb[0]=0;
	for(int i=1;i<=n;i++)
	{
		suma[i]=suma[i-1]+a[i];
		sumb[i]=sumb[i-1]+b[i];
	}
	for(int i=0;i<=n;i++)
	{
		if(i==n-i)
			ans=max(ans,(suma[i]+sumb[n]-sumb[i])*2-min(a[i],b[i+1]));
		else if(i<n-i)
		{
			ans=max(ans,(suma[i]+sumb[i+i+1]-sumb[i+1])*2+b[i+1]);
			ans=max(ans,(suma[i]+sumb[i+i]-sumb[i])*2-a[i]);
		}
		else
		{
			ans=max(ans,(sumb[n]-sumb[i]+suma[i-1]-suma[i-n+i-1])*2+a[i]);
			ans=max(ans,(sumb[n]-sumb[i]+suma[i]-suma[i+i-n])*2-b[i+1]);
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4992
def B_Theater(N, C):
    people = 0
    for i in range(0, len(C), 2):
        people += C[i + 1] - C[i] + 1
    return people

N = int(input())
C = [[int(i) for i in input().split()] for i in range(N)]
x = []
for s in C:
    x.extend(s)
C=x
print(B_Theater(N, C))

Measured memory_bytes: 3188
#include<iostream>

using namespace std;

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

  if(a == b){
    x = c;
  } else if(a == c){
    x = b;
  } else {
    x = a;
  }

  cout << x << endl;    

  return 0;
}



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  ll l;
  while(cin >> s >> l){
    if(s == "0" && l == 0) break;
    ll c = 0;
    map<string,ll> m;
    m[s] = 0;
    if(s != "0"){
      while(1){
        while(s.size() != l) s = "0"+s;
        sort(all(s));
        string min = s;
        reverse(all(s));
        string max = s;
        ll n = (ston(max,1) - ston(min,1));
        ++c;
        s = to_string(n);
        if(m.count(s) > 0){
          cout << m[s] << " " << s << " " << c-m[s] << endl;
          break;
        }
        else{
          m[s] = c;
        }
      }
    }
    else{
      cout << 0 << " " << 0 << ' ' << 1 << endl;
    }
  }
  return 0;
}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main(){
  int n,a,b; cin >> n >> a >> b;
  vll v(n); rep(i,n) cin >> v[i];

  sort(rall(v));
  double ave = (double)accumulate(v.begin(),v.begin()+a,0ll) / a;
  printf("%.10f\n",ave);

  int x = 0; rep(i,n) if(v[a-1] == v[i]) x++;

  vvll C(x+1);
  C[0].pb(1);
  FOR(i,1,x+1){
    C[i].resize(i+1);
    rep(j,i) rep(k,2)
      C[i][j+k] += C[i-1][j];
  }
  //dump(x,C);

  if(v[0] != v[a-1]){
    int y = 0; rep(i,a) if(v[a-1] == v[i]) y++;
    cout << C[x][y] << endl;
  }else{
    ll ans = 0;
    FOR(i,a,min(x+1,b+1)) ans += C[x][i];
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <tuple>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;

using ll=long long;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vll> vl2d;
typedef vector <vi> vi2d;
typedef vector <char> vc;
typedef vector <bool> vb;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <char,int> mci;
typedef map <int,int> mii;
typedef map <long,long> ml;
typedef map <string,string> mss;
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define foreach(x,arr) for(auto& x:arr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define endl '\n' // Normal `cout << endl` flushes the output every time wich hit performance badly
#define INF 1000000000
#define MOD 1000000007
#define deb(x) cout<<#x<<": "<<x<<endl;
#define printArray(arr) for(auto x: arr) { cout<<x<<"\n"; }
#define printMatrix(mat) for(auto x: mat) { cout<<" "; printArray(x); cout<<endl; }
#define printMap(mmap) for(auto p: mmap) { cout<< p.first<<": "<<p.second<<endl; }
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define forch(ch,str) for(char& c : str)
#define FILL(a,b) memset(a,b,sizeof(a))
//Swift related stuff
#define append push_back
#define nil nullptr
#define guard(_condition) if (bool(_condition)){}
#define count size()
#define let auto
#define var auto
#define startsWith(str) rfind(str, 0)
#define prq priority_queue
#define tostr(argument) to_string(argument)
#define alphabet "abcdefghijklmnopqrstuvwxyz"

void join(const vector<string>& v, char c, string& s) {

   s.clear();

   for (vector<string>::const_iterator p = v.begin();
        p != v.end(); ++p) {
      s += *p;
      if (p != v.end() - 1)
        s += c;
   }
}

ll cost(vll costs, int n, int k) {
    vll dp(n, INF);
    dp[0] = 0;
    rep(i, 1, n) {
        rep(j, 1, k+1) {
            guard(i-j >= 0) else {
                break;
            }
            dp[i] = min(dp[i], abs(costs[i]-costs[i-j]) + dp[i-j]);
        }
    }
    return dp[n-1];
}


int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); // Fast input
    
    int n, k;
    cin>>n;
    cin>>k;
    vll arr;
    rep(i, 0, n) {
        ll num;
        cin>>num;
        arr.append(num);
    }
    cout<<cost(arr, n, k)<<endl;
    return 0;
}


Measured memory_bytes: 2804
/*B - Strings with the Same Length*/
#include <bits/stdc++.h>

using namespace std;

int main(){
	
	string cad1, cad2;
	int tam;

	cin >> tam;
	cin >> cad1 >> cad2;

	for (int i = 0; i < tam; ++i)
		cout << cad1[i] << cad2[i];

	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))

for i in range(n):
    p[i]=(p[i]+1)/2
buf=0
maxi=0
for i in range(k):
    buf+=p[i]
maxi=buf
for i in range(k,n):
    #print(buf)
    buf+=p[i]
    buf-=p[i-k]
    if maxi<buf:
        maxi=buf
print(maxi)

Measured memory_bytes: 71792
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();
        int a[] = new int[3];
        for (int i = 0; i < s.length(); i++) {
            if ("a".equals(s.substring(i, i + 1))) {
                a[0]++;
            } else if ("b".equals(s.substring(i, i + 1))) {
                a[1]++;
            } else {
                a[2]++;
            }
        }
        if (Arrays.stream(a).max().getAsInt() - Arrays.stream(a).min().getAsInt() > 1) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }
}

Measured memory_bytes: 36940
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
 
const double EPS = 1e-8, PI = acos(-1);
const int MAXN = 105;
 
struct point {
	double x, y;
	int id;
	
	point() {}
	point(double _x, double _y, int _id = -1) : x(_x), y(_y), id(_id) {}
	bool operator<(const point &another) const;
};
 
struct ans {
	double val;
	int id;
 
	ans() {}
	bool operator<(const ans &another) const
	{
		return id < another.id;
	}
};
 
int tot, n;
point p[MAXN], s[MAXN], normal[MAXN];
ans an[MAXN];
bool visited[MAXN];
 
int sgn(double x)
{
	if (fabs(x) < EPS) return 0;
	return (x > 0 ? 1 : -1);
}
 
double det(const point &a1, const point &a2, const point &b1, const point &b2)
{
	return ((a2.x - a1.x) * (b2.y - b1.y) - (a2.y - a1.y) * (b2.x - b1.x));
}
 
double dot(const point &a1, const point &a2, const point &b1, const point &b2)
{
	return ((a2.x - a1.x) * (b2.x - b1.x) + (a2.y - a1.y) * (b2.y - b1.y));
}
 
double dist(const point &p1, const point &p2)
{
	return sqrt((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y));
}
 
bool point::operator<(const point &another) const
{
	if (sgn(det(p[0], *this, p[0], another)) == 0)
		return dist(p[0], *this) < dist(p[0], another);
	else
		return det(p[0], *this, p[0], another) > 0;
}
 
void graham()
{
	double min_y = p[0].y, min_x = p[0].x;
	int index = 0;
	for (int i = 1; i <= n - 1; i++) {
		if (p[i].y < min_y || (sgn(p[i].y - min_y) == 0 && p[i].x < min_x)) {
			min_y = p[i].y;
			min_x = p[i].x;
			index = i;
		}
	}
	swap(p[0], p[index]);
	sort(p + 1, p + n);
	s[0] = p[0]; s[1] = p[1];
	tot = 2;
	for (int i = 2; i <= n - 1; i++) {
		while (tot >= 2 && sgn(det(s[tot - 1], p[i], s[tot - 1], s[tot - 2]) < 0)) tot--;
		s[tot++] = p[i];
	}
}
 
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf %lf", &p[i].x, &p[i].y);
		p[i].id = i;
	}
	graham();
	for (int i = 0; i < tot; i++) {
		if (i == 0) {
			normal[i].y = -(s[i].x - s[tot - 1].x);
			normal[i].x = s[i].y - s[tot - 1].y;
			normal[i].id = s[i].id;
		}
		else {
			normal[i].y = -(s[i].x - s[i - 1].x);
			normal[i].x = s[i].y - s[i - 1].y;
			normal[i].id = s[i].id;
		}
	}
	point zero(0, 0);
	for (int i = 0; i < tot; i++) {
		if (i == tot - 1) {
			an[i].val = acos(dot(zero, normal[i], zero, normal[0]) / dist(zero, normal[i]) / dist(zero, normal[0])) / PI / 2;
			an[i].id = normal[i].id;
		}
		else {
			an[i].val = acos(dot(zero, normal[i], zero, normal[i + 1]) / dist(zero, normal[i]) / dist(zero, normal[i + 1])) / PI / 2;
			an[i].id = normal[i].id;
		}
	}
	memset(visited, false, sizeof(visited));
	for (int i = 0; i < tot; i++) visited[s[i].id] = true;
	for (int i = 0; i < n; i++)
		if (!visited[i]) {
			an[tot].val = 0.0000000;
			an[tot++].id = i;
		}
	sort(an, an + n);
	for (int i = 0; i < n; i++) printf("%.8f\n", an[i].val);
	return 0;
}


Measured memory_bytes: 640
raw_a, raw_b, raw_c = map(int, input().split())

# 偶奇をそろえたい
# 2 6 3
# 4 6 3
# 6 6 3
# 6 6 5
# 6 6 7
# 7 7 7

a_guuki = raw_a % 2
b_guuki = raw_b % 2
c_guuki = raw_c % 2

if a_guuki == b_guuki == c_guuki:
    a = raw_a
    b = raw_b
    c = raw_c
    if a == b == c:
        print(0)
        exit()
    max_number = max(a, b, c)
    if max_number == a:
        print((a-b)//2 + (a-c)//2)
        exit()
    if max_number == b:
        print((b-a)//2 + (b-c)//2)
        exit()
    if max_number == c:
        print((c-a)//2 + (c-b)//2)
        exit()

elif a_guuki == b_guuki:
    a = raw_a
    b = raw_b
    c = raw_c
elif a_guuki == c_guuki:
    a = raw_a
    b = raw_c
    c = raw_b
elif b_guuki == c_guuki:
    a = raw_b
    b = raw_c
    c = raw_a

ans = 0

ans += abs(a-b)//2 + 1  # aとbをそろえて偶奇をcに合わせる

ans += (max(a, b)+1 - c) // 2  # cをa、bに合わせる

print(ans)

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

int main() {
	int K,X;
	cin >> K >> X;

  int s = (X - K) + 1;
  int e = (X + K) - 1;

  for(int i = s; i<=e;i++){
    cout << i << " ";
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int answer =  Integer.MIN_VALUE;
        int min = scan.nextInt();
        for(int x = 0; x < n - 1; x++){
            int r = scan.nextInt();
            answer = Math.max(answer, r - min);
            min = Math.min(min, r);
        }
        System.out.println(answer);

    }
}


Measured memory_bytes: 98864
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<cstring>
#include<vector>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REV(i,a,b) for(int i=(a)-1;i>=(b);i--)

using namespace std;

typedef long long ll;

int n;
int k;

bool isprime(int n){
  for(int i=2;i*i<=n;i++){
    if (n % i == 0) return false;
  }
  return true;
}

int main(){
  cin >> n;
  int ans=0;
  REP(i,n){
    cin >> k;
    if(isprime(k)) ans++;
  }
  cout << ans<<endl;
  return 0;

}


Measured memory_bytes: 3088
def solve():
  N, K = map(int, input().split())
  maxK = sum(range(1, N - 1))
  if maxK < K:
    print(-1)
    return
  M = N - 1 + (maxK - K)
  print(M)
  for i in range(1, N):
    for j in range(i + 1, N + 1):
      if M == 0: return
      print(i, j)
      M -= 1

solve()


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i = 0; i < n; i++)
const int N = 1e5+3;
const int INF = 1e9;

int digit(int t){
  int cnt = 0;
  while(t /= 10) cnt++;
  return cnt + 1;
}

int main(){

  ll n; cin >> n;
  int ans = INF;
  for(int i = 1; i <= sqrt(n); i++){
    if(n % i) continue;
    int B = n / i;
    int res = max(digit(B),digit(i));
    ans = min(ans,res);
  }
  cout << ans << endl;

  return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M;
const int MAX_N = 1000;
struct edge{
	int to;
	ll cost;
};
vector<edge> G [MAX_N],rG [MAX_N];
int vis [MAX_N];
ll minCost [MAX_N];
const ll INF = 1e18;

void dfs(int curr,vector<edge> G [],int k)
{
	vis [curr] |= k;
	for(const auto& it : G [curr]) if((vis [it.to] & k) == 0){
		dfs(it.to,G,k);
	}
}

int main()
{
	scanf("%d%d",&N,&M);
	FOR(i,0,M){
		int u,v;
		ll w;
		scanf("%d%d%lld",&u,&v,&w);
		G [u - 1].push_back(edge{v - 1,w});
		rG [v - 1].push_back(edge{u - 1,w});
	}

	dfs(0,G,1);
	dfs(N - 1,rG,2);

	fill(minCost,minCost + N,-INF);
	minCost [0] = 0;
	FOR(i,0,N){
		bool update = false;
		FOR(j,0,N) for(const auto& it : G [j]) if(vis [j] == 3 && vis [it.to] == 3){
			if(minCost [it.to] < minCost [j] + it.cost){
				minCost [it.to] = minCost [j] + it.cost;
				update = true;
			}
		}
		if(update == false) break;
		if(update && i == N - 1){
			puts("inf");
			return 0;
		}
	}

	printf("%lld\n",minCost [N - 1]);

	return 0;
}


Measured memory_bytes: 384
#![allow(unused)]

use proconio::{input, fastout};
use proconio::marker::{Chars, Usize1};

#[fastout]
fn main() {
    input! {
        a: char,
    }

    if a <= 'Z' {
        println!("A");
    } else {
        println!("a");
    }
}


Measured memory_bytes: 2108
#include <stdio.h>
#define MAX 500000

int cnt=0;
void merge(int *,int,int,int);
void mergeSort(int *,int,int);

int main(){
  int A[MAX],n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    if(i)
      printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}

void merge(int *A,int left,int mid,int right){
  int i,j,k,n1,n2,L[MAX/2+1],R[MAX/2+1];
  n1 = mid - left;
  n2 = right - mid;
  for(i=0;i<n1;i++)
    L[i] = A[left + i];
  for(i=0;i<n2;i++)
    R[i] = A[mid + i];
  L[n1] = 2000000000;
  R[n2] = 2000000000;
  i=j=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
    }
  }
}

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



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

int main (){
    string s;
    cin >>s;
    if(s.at(2) == s.at(3) && s.at(4) == s.at(5)){
        cout <<"Yes" <<endl;
    }
    else{
        cout <<"No" <<endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
vector<int> G[2000];
vector<P> E;
int dist[2000];
void dfs(int v, int par, int depth) {
	dist[v] = min(dist[v], depth);
	for (int to : G[v]) {
		if (to == par) continue;
		dfs(to, v, depth+1);
	}
}
int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
		E.emplace_back(a, b);
	}
	if (K % 2) {
		int ans = 1 << 30;
		for (int i = 0; i < N - 1; i++) {
			fill(dist, dist + N, 1 << 30);
			dfs(E[i].first, -1, 0);
			dfs(E[i].second, -1, 0);
			int cnt = 0;
			for (int j = 0; j < N; j++) {
				if (dist[j] > K / 2) cnt++;
			}
			ans = min(ans, cnt);
		}
		cout << ans << endl;
	}
	else {
		int ans = 1 << 30;
		for (int i = 0; i < N; i++) {
			fill(dist, dist + N, 1 << 30);
			dfs(i, -1, 0);
			int cnt = 0;
			for (int j = 0; j < N; j++) {
				if (dist[j] > K / 2) cnt++;
			}
			ans = min(ans, cnt);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MD 1000000007
using namespace std;
typedef long long ll;
ll dp[101][100100],v[101];
int n,k;

ll ds(int id, int c) {
	if(id == n) {return c==0;}
	if(c == 0) {return 1;}
	if(c < 0) {return 0;}
	if(dp[id][c] != -1) {return dp[id][c];}
	ll re = ds(id,c-1);
	re += ds(id+1,c)-ds(id+1,c-v[id]-1);
	re += MD;
	re %= MD;
	//printf("ds %lld %d %d\n",re,id,c);
	//printf("%lld %d %d\n",re,id,c);
	//for(int i=0;i<=min(v[id],(ll)c);i++) {
		//re += ds(id+1,c-i);
	//}
	return dp[id][c] = re%MD;
}
int main() {
	scanf("%d %d ",&n,&k);
	for(int i=0;i<n;i++) {
		int t;
		scanf("%d ",&t);
		v[i] = t;
	}
	memset(dp,-1,sizeof(dp));
	printf("%lld\n",ds(0,k));
}


Measured memory_bytes: 85504
#include<stdio.h>
#include<stdlib.h>
typedef struct A{char m;int n,f;}A;
A D[100005];
int N,i,flg=0;
void sw(A *a,A *b)
{
	A c=*a;
	*a=*b;
	*b=c;
}

int pt(int p,int r)
{
	int i,j,pos;
	A x;
	x=D[r];
	i=p-1;
	for(j=p;j<r;j++)
	{
		if(D[j].n<=x.n)
		{
			sw(&D[++i],&D[j]);
		}
	}
	sw(&D[i+1],&D[r]);
	return i+1;
}

void qs(int p,int r)
{
	int q;
	if(p<r)
	{
		q=pt(p,r);
		qs(p,q-1);
		qs(q+1,r);
	}
}


int main()
{
	scanf("%d\n",&N);
	for(i=1;i<=N;i++)
	{
		scanf("%c %d\n",&D[i].m,&D[i].n);
		D[i].f=i;
	}
		
	qs(1,N);
	for(i=2;i<=N;i++)
		if(D[i-1].n==D[i].n&&D[i-1].f>D[i].f)
			flg=1;
	puts(flg?"Not stable":"Stable");
	for(i=1;i<=N;i++)
		printf("%c %d\n",D[i].m,D[i].n);
	return 0;
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define PII pair<int,int>
#define ll long long
int N=INT_MAX;
ll INF1=1e9 + 5;
ll INF2=1e18L + 5;
map<int ,int>my;
int h[10005];

int main(){
	int n;
	cin>>n;
	int a[n],a2[n-1];
	for(int i=0;i<n-1;i++){
		cin>>a2[i];
	}
	a[0]=a2[0];
	for(int i=1;i<n;i++){
		a[i]=a2[i-1];
	}
	for(int i=1;i<n;i++){
		if(a[i-1]>a[i]){
			a[i-1]=a[i];
		}
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		ans+=a[i];
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

template <class T>
struct SegmentTree{
  using F = function<T(T,T)>;
  F f;
  T inf;
  int n;
  vector<T> node;

  SegmentTree(vector<T> v,T inf,F f):inf(inf),f(f){
    n = 1; while(n < v.size()) n *= 2;
    node.resize(2*n-1,inf);
    for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
    for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1],node[2*i+2]);
  }

  void update(int k,T val){
    k += n-1;
    node[k] = val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  void add(int k,T val){
    k += n-1;
    node[k] += val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  T getval(int a,int b){ return getval(a,b,0,0,n); }
  T getval(int a,int b,int k,int l,int r){
    //区間[a, b)の値を返す
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return node[k];
    T vl = getval(a, b, 2*k+1, l, (l+r)/2);
    T vr = getval(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }
};

signed main(){

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

  SegmentTree<int> seg(w,0,[&](int x,int y){
    return (x + y);
  });
  int ans = 1<<30;
  for(int i = 0; i < n; i++){
    ans = min(ans,abs(seg.getval(0,i+1) - seg.getval(i+1,n)));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var p = 0
    var ans = 0L
    readLine()!!.split(' ').forEachIndexed { i, v ->
        val a = v.toInt()
        if (i == 0) p = a
        else {
            if (a < p) {
                ans += (p - a)
            } else p = a
        }
    }
    println (ans)
}


Measured memory_bytes: 63544
main = do
    s <- getLine
    k <- readLn
    putStrLn $ solve k s

solve :: Int -> String -> String
solve k (x : []) = (:[]) . toEnum $ a + (((fromEnum x) - a + k) `mod` 26)
    where a = fromEnum 'a'
solve 0 xs = xs
solve k (x:xs) | c <= k = 'a' : solve (k-c) xs
               | otherwise = x : solve k xs 
    where a = fromEnum 'a'
          c = (26 - (fromEnum x - a)) `mod` 26

Measured memory_bytes: 5116
import sys
import os
import math

def file_input():
    f = open('input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()

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

    for i in range(M):
        for j in range(A[i]):
            N -= 1
            if N==-1 :
                break
        else:
            continue
        break

    print(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10008
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <cstdlib>  // abs() for integer
#include <cmath>

using namespace std;

int main(void) {
    int N,A,B;
    cin >> N >>A >>B;
    int answer;
    if (N*A<B) answer =N*A;
    else answer = B;
    cout << answer;
    return 0;
}

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


int main()
{
  string S;
  cin >> S;
  if(S=="ABC")
    cout << "ARC" << endl;
    else
      cout << "ABC" << endl;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        String s = sc.next();

        if (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }



    }
}


Measured memory_bytes: 23892
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n; cin>>n;
    string ans="Yes";
    vector<vector<int>> d(n+1,vector<int>(3,0));
    rep(i,n)rep(j,3){
        cin>>d[i+1][j];
    }
    rep(i,n){
        int d1=d[i+1][0]-d[i][0];
        int d2=abs(d[i+1][1]-d[i][1])+abs(d[i+1][2]-d[i][2]);
        if(d1<d2 || (d2-d1)%2)
        ans="No";
    }
    cout<<ans<<endl;
}

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

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

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

int main(){
	int x[4],y[4];
	cin>>x[0]>>y[0]>>x[1]>>y[1];
	int a=x[1]-x[0],b=y[1]-y[0];
	if(a>0&&b>0||a<0&&b<0){
		x[2]=x[1]-b;
		y[2]=y[1]+a;
		x[3]=x[2]-a;
		y[3]=y[2]-b;
	}
	if(a>0&&b<0||a<0&&b>0){
		x[2]=x[1]-b;
		y[2]=y[1]+a;
		x[3]=x[2]-a;
		y[3]=y[2]-b;
	}
	if(a==0){
		x[2]=x[1]-b;
		y[2]=y[1];
		x[3]=x[2];
		y[3]=y[0];
	}
	if(b==0){
		x[2]=x[1];
		y[2]=y[1]+a;
		x[3]=x[0];
		y[3]=y[2];
	}
	cout<<x[2]<<" "<<y[2]<<" "<<x[3]<<" "<<y[3];
	return 0;
}


Measured memory_bytes: 256
def main():
    x = int(input())
    ans = 1
    for i in range(2, int(x**0.5)+1):
        b = i
        p = 1
        while b**(p+1) <= x:
            p += 1
        ans = max(ans, b**p)
    print(ans)

if __name__ == "__main__":
    main()

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int h, w;
    cin >> h >> w;
    vs s(h+1);
    s[0] = string(w+1, '.');
    rep1(i, h) {
        string si;
        cin >> si;
        s[i] = '.' + si;
    }
    vector<vi> dp(h+1, vi(w+1, INF));
    dp[0][1] = dp[1][0] = 0;
    rep(i, h) rep(j, w) {
        if (s[i+1][j+1]=='#'&&s[i][j+1]=='.') dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1]+1);
        else dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1]);
        if (s[i+1][j+1]=='#'&&s[i+1][j]=='.') dp[i+1][j+1] = min(dp[i+1][j+1], dp[i+1][j]+1);
        else dp[i+1][j+1] = min(dp[i+1][j+1], dp[i+1][j]);
    }
    cout << dp[h][w] << endl;
    return 0;
}


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

const int N = 2e5;

template <class T, class U> inline void smax(T &a, U b) { a = a > b ? a : b; }
template <class T, class U> inline void smin(T &a, U b) { a = a < b ? a : b; }

int a[N];
ll solve() {
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if(a[0] > 0) return -1;
  int t = 0;
  for(int i = n - 1; i >= 0; i--) {
    if(t > a[i]) return -1;
    smax(t, a[i]);
    t--;
  }
  {
    ll t = a[n - 1];
    ll ans = t;
    t--;
    for(int i = n - 2; i >= 0; i--) {
      if(t < a[i]) ans += a[i];
      smax(t, a[i]);
      t--;
    }
  return ans;
  }
}

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


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

using namespace std;

int main(){
    int n,m;
    cin >>n>>m;
    string s;
    cin>>s;
    int dp[n+1]={};
    int i,j,k;
    for(i=2;i<=n;i++){
        if(s.substr(i-2,2) == "AC")dp[i]++;
        dp[i]+=dp[i-1];
    }
    for(i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        cout << dp[r]-dp[l] <<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();
        int[] count = new int[N];
        for (int i = 0; i < N; i++) {
            if (i == 0) {
                count[i] = 0;
                continue;
            }
            int e = 0;
            if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                e++;
            }
            count[i] = count[i-1] + e;
        }
        for (int i = 0; i < Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r - 1] - count[l - 1]);
        }
    }
}

Measured memory_bytes: 65028
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define ll long long
using namespace std;

int dp[100002][3];

int main(){
    int n,m;
    cin>>n>>m;
    ll val[n],wt[n];
    for(int i = 0; i < n; i++)cin>>wt[i]>>val[i];
    int i, w;
    ll K[n+1][m+1];

   // Build table K[][] in bottom up manner
   for (i = 0; i <= n; i++)
   {
       for (w = 0; w <= m; w++)
       {
           if (i==0 || w==0)
               K[i][w] = 0;
           else if (wt[i-1] <= w)
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
           else
                 K[i][w] = K[i-1][w];
       }
   }
   cout<<K[n][m];
    return 0;
}



Measured memory_bytes: 79104
n=gets.chomp.to_i
dice_array=[]
(1..n).each do |i|
  d=gets.split.map(&:to_i)
  if d[0]==d[1]
    dice_array << 1
  else
    dice_array << 0
  end
end
cnt=0
flg=0
dice_array.each do |a|
  if a==1
    cnt += 1
    if cnt == 3
      flg=1
      break
    end
  else
    cnt=0
  end
end
if flg==1
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 14272
#include <bits/stdc++.h>
using namespace std;
int a[100000][3];
int dp[100000][3];
int vacation(int i,int j,int n)
{
    if(i==n)
        return 0;
    int sum = 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    for(int k = 0;k<3;k++)
    {
        if(k!=j||i==0)
        sum = max(sum,a[i][k] + vacation(i+1,k,n));
    }
    return dp[i][j] = sum;
}


int main()
{
    long long int n;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i = 0;i<n;i++)
        for(int j=0;j<3;j++)
            cin>>a[i][j];
    cout<<vacation(0,0,n)<<"\n";
    return 0;
}


Measured memory_bytes: 10368
import math
N, M = map(int, input().split())
ans = 1

for i in range(1, int(math.sqrt(M))+1):
    if M % i == 0.0:
        if M // i >= N and ans < i:
            ans = i
        if M // (M // i) >= N and ans < (M // i):
            ans = M // i
print(ans)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc161/tasks/abc161_d>
 問題文============================================================
 D - Lunlun Number
 =================================================================
 解説=============================================================
 
 
 
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll K; cin >> K;
    
    deque<ll> dq;
    for(int i = 1; i <= 9;i++) dq.push_back(i);
    
    for(int k = 0; k < K-1;k++){
        ll x = dq.front(); dq.pop_front();
        
        if(x%10 != 0) dq.push_back(10*x+x%10-1);
        dq.push_back(10*x + x%10);
        if(x%10 != 9) dq.push_back(10*x+x%10+1);
    }
    res = dq.front();
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <climits>
#include <stack>
#define ll long long int
#define MOD 1000000007


using namespace std ;




int main(){
ios::sync_with_stdio(false) ;cin.tie(0) ;cout.tie() ;
int n ,  m ;
cin>>n>>m ;
vector<int>arr[n+1] ;

for(int i = 0  ; i<  m ; ++i)
{
   int a , b ;
   cin>>a>>b ;
   arr[a].push_back(b) ;
   arr[b].push_back(a) ;
 }

 for(int i = 0  ;  i< arr[1].size() ; ++i)
 {
    for(int j =  0  ; j   < arr[arr[1][i]].size() ; ++j)
    {
       if(arr[ arr[1][i]][j] == n)
       {
       cout<<"POSSIBLE\n" ;
       return 0 ;
       }

    }

 }
 cout<<"IMPOSSIBLE\n" ;

return  0 ;
}

Measured memory_bytes: 12016
while True:
    n=int(input())
    if n==0:break
    mem=[]
    crime=-1
    for _ in range(n):
        mem.append(set([int(i) for i in input().split()][1:]))
    o=set([int(i) for i in input().split()][1:])
    for e,i in enumerate(mem):
        if o.intersection(i)==o:
            if crime==-1:crime=e+1
            else:
                crime=-1
                break
    print(crime)


Measured memory_bytes: 6324
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    string S;
    cin >> S;

    int length = S.size();
    int half = length / 2;
    int ans;
    if (length % 2 == 0)
    {
        vector<int> left(2);
        vector<int> right(2);
        for (int i = 0; i < half; i++)
        {
            if (S[i] == '0')
            {
                left[0]++;
            }
            else
            {
                left[1]++;
            }
        }
        for (int i = half; i < S.size(); i++)
        {
            if (S[i] == '0')
            {
                right[0]++;
            }
            else
            {
                right[1]++;
            }
        }
        ans = min(left[0], right[1]) + min(left[1], right[0]);
    }
    else
    {
        int ans1, ans2;
        vector<int> left1(2);
        vector<int> right1(2);
        // left 6 right 7
        for (int i = 0; i < half; i++)
        {
            if (S[i] == '0')
            {
                left1[0]++;
            }
            else
            {
                left1[1]++;
            }
        }
        for (int i = half; i < S.size(); i++)
        {
            if (S[i] == '0')
            {
                right1[0]++;
            }
            else
            {
                right1[1]++;
            }
        }
        ans1 = min(left1[0], right1[1]) + min(left1[1], right1[0]);

        vector<int> left2(2);
        vector<int> right2(2);
        // left 7 right 6
        for (int i = 0; i <= half; i++)
        {
            if (S[i] == '0')
            {
                left2[0]++;
            }
            else
            {
                left2[1]++;
            }
        }
        for (int i = half + 1; i < S.size(); i++)
        {
            if (S[i] == '0')
            {
                right2[0]++;
            }
            else
            {
                right2[1]++;
            }
        }
        ans1 = min(left2[0], right2[1]) + min(left2[1], right2[0]);
        ans = max(ans1, ans2);
    }
    cout << ans * 2 << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using ll=long long;

//a>0,b>0
ll gcd(ll a, ll b)
{
  ll r;
  if(a<b) swap(a,b);
  while((r=a%b)!=0){
    a = b;
    b = r;
  }
  return b;
}
void solve(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  a-=c+1;
  if(a>0)
    a%=b;
  a+=c+1;
  if(a<b||b>d){
    cout<<"No\n";
    return;
  }
  if(b<=c){
    cout<<"Yes\n";
    return;
  }
  ll x=gcd(b,d);
  ll i=a-b;
  if(i>0)
    i%=x;
  i+=b;
  if(i-x>c)
    cout<<"No\n";
  else
    cout<<"Yes\n";
}

int main(){ _;
  int t;cin>>t;
  REP(i,t){
    solve();
  }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin >> p[i];
  int tmp;
  int ans=0;
  for(int i=0;i<n-2;i++){
    if(p[i]==i+1){
      ans++;
      tmp=p[i];
      p[i]=p[i+1];
      p[i+1]=tmp;
    }
  }
  if(p[n-1]==n||p[n-2]==n-1){
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768