akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main{
  static boolean[][] field = new boolean[12][12];
  
  public static void paint(int x, int y){
    field[x][y] = false;
    if (x > 0 && field[x-1][y]) {
      paint(x-1,y);
    }
    if (y > 0 && field[x][y-1]) {
      paint(x,y-1);
    }
    if (x < 11 && field[x+1][y]) {
      paint(x+1,y);
    }
    if (y < 11 && field[x][y+1]) {
      paint(x,y+1);
    }
  }
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while (sc.hasNext()) {
      for (int i = 0; i < 12; i++) {
        String str = sc.next();
        for (int j = 0; j < 12; j++) {
          if (str.charAt(j) == '1') {
            field[i][j] = true;
          }
          else {
            field[i][j] = false;
          }
        }
      }
      int num = 0;
      for (int i = 0; i < 12; i++) {
        for (int j = 0; j < 12; j++) {
          if (field[i][j]) {
            paint(i,j);
            num++;
          }
        }
      }
      System.out.println(num);
    }
  }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define each(e,v) for(auto&& e:(v))
#define DEBUG(x) cout<<#x<<": "<<x<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
const long long INF = 1e9;

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    long long mini = INF;
    FOR(i, a.front(), a.back()+1) {
        long long sum = 0;
        rep(j, n) {
            sum += pow(a[j] - i, 2);
        }
        mini = min(mini, sum);
    }
    cout << mini << endl;
    return 0;
}


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

int main() {
    int N,maxl=0,ind = 0,total=0;
    cin >> N;
    vector<int> length(N);

    for (int i = 0; i < N; ++i){
        cin >> length.at(i);
    }

    // max
    for (int i = 0; i < N; ++i){
        if (maxl < length.at(i)){
            maxl = length.at(i);
            ind = i;
        }
    }

    for (int i = 0; i < N; ++i){
        if (i != ind ){
            total += length.at(i);
        }
    }

    if (total > maxl){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
        
}

Measured memory_bytes: 256
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb emplace_back
#define koto_memory(a) cout<<(sizeof(a)/1048576.0)<<" MB";
#define res(v) sort(all(v)),v.erase(unique(all(v)), v.end());
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
#define deb(x) cout<<"\n["<<#x<<" = "<<x<<"]\n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int n;double k,a[N];
bool f(double len){
	int cut=0;
	rep(i,1,n){
		if(a[i]<=len)continue;
		double y=a[i];
		cut+=(a[i]-1)/len;
	}
	return (cut<=k);
}
void solve(){
	cin>>n>>k;
	rep(i,1,n)cin>>a[i];
	sort(a+1,a+1+n);
	double l=0,r=inf;
	while(abs(r-l)>1){
		int m=(l+r)/2;
		if(f(m))r=m;
		else l=m;
	}
	// if(f(l))
	cout<<(int)ceil(l+1);
	// else cout<<l+1;
}
int32_t main()
{
  ibs;cti;
  solve();return 0;
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

Measured memory_bytes: 6836
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = []
    for _ in range(M):
        b, c = map(int, input().split())
        BC.append((b, c))

    BC = sorted(BC, key=lambda x: -x[1])
    n = 0
    for b, c in BC:
        n += b
        A += [c] * b
        
        if n >= N:
            break

    A = sorted(A, key=lambda x: -x)
    return sum(A[:N])


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 36476
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

constexpr int INF = 1e9+7;
constexpr ll INFL = 9*1e18;

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

// constexpr int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// constexpr int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

int inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;}


// TODO: write
int main() {
  int a,b,c;cin>>a>>b>>c;
  print(a+b+c - max(a,max(b,c)));
  return 0;
}

Measured memory_bytes: 3632
// D - Cake 123
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,n) for(int i=0;i<(n);++i)

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

	vector<ll> A(X), B(Y), C(Z);
	rp(i,X) cin>>A[i];
	rp(i,Y) cin>>B[i];
	rp(i,Z) cin>>C[i];

	vector<ll> AB;
	for(auto a:A) for(auto b:B) AB.push_back(a + b);
	sort(AB.rbegin(), AB.rend());

	vector<ll> ABC;
	int e = min(K, (int)AB.size());
	for(auto c:C) rp(d,e) ABC.push_back(c + AB[d]);

	sort(ABC.rbegin(), ABC.rend());
	rp(i,K) cout<<ABC[i]<<"\n";
}

Measured memory_bytes: 43240
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N = sc.nextInt();
		double ans = 0;
		for(int i = 0; i < N; i++) {
			double x = sc.nextDouble();
			String u = sc.next();
			if(u.equals("JPY")) ans += x;
			else ans += x * 380000.0;
		}
		System.out.println(BigDecimal.valueOf(ans).toPlainString());
	}
}


Measured memory_bytes: 23380
#include <iostream>
using namespace std;
 
int main () {
  int n;
  cin >> n;
  int h[n];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  long long ans = 0;
  for (int num = 0; num <= 100; num++) {
    bool ok = false;
    for (int i = 0; i < n; i++) {
      if (h[i] == 0) {
        ok = false;
      }
      else {
        if (ok == false) {
          ans++;
          ok = true;
        }
        h[i]--;
      }
    }
  }
  cout << ans << endl;
}

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

const ll INF = 1e18;
const int MX = 2005;

int main() {
  ll n,W;
  cin >> n >> W;
  ll w[n],v[n];
  rep(i,n) cin >> w[i] >> v[i];
  ll dp[n+10][100010]; 
  rep(i,n+10) rep(j,100010) dp[i][j] = INF;
  dp[0][0] = 0;
  rep(i,n){
    rep(j,100010){
      if(j >= v[i]){
        dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]] + w[i]);
      }else{
        dp[i+1][j] = dp[i][j];
      }
    }
  }
  ll ans = 0;
  rep(j,100010){
    if(dp[n][j] <= W){
      ans = j;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 86144
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int n,m;
int win[5001],lose[5001],mat[5001];
char fie[5001][5001];
int id[5001];
bool used[5001];
int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)mat[i]=n-1;
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--,b--;
		win[a]++,lose[b]++;
		mat[a]--,mat[b]--;
		fie[a][b]=1;
		fie[b][a]=-1;
	}
	bool f=false;
	memset(used,false,sizeof(used));
	for(int i=0;i<n;i++){
		int cnt=0,k=-1;
		for(int j=0;j<n;j++)if(mat[j]+win[j]==n-1-i && !used[j])cnt++,k=j;
		if(cnt>=2)f=true;
		id[i]=k;
		used[k]=true;
		for(int j=0;j<n;j++){
			if(fie[k][j]==0){
				fie[k][j]=1;
				fie[j][k]=-1;
				lose[j]++;
				mat[j]--,mat[k]--;
				win[k]++;
			}
		}
	}
	for(int i=0;i<n;i++)printf("%d\n",id[i]+1);
	if(f)puts("1");
	else puts("0");
	return 0;
}

Measured memory_bytes: 25700
def insertion_sort(A, n, g):
  global cnt
  for i in range(g, n):
    v = A[i]
    j = i - g
    while j >= 0 and A[j] > v:
      A[j+g] = A[j]
      j -= g
      cnt += 1
    A[j+g] = v


def shell_sort(A, n):
  global cnt
  cnt = 0
  G = [1]
  for i in range(100):
    if G[-1]*3 + 1 > n:
      break 
    G.append(G[-1]*3 + 1)
  G.reverse()
  m = len(G)

  for i in range(m):
    insertion_sort(A, n, G[i])

  print(m)
  print(*G)


n = int(input())
A = [int(input()) for _ in range(n)]
shell_sort(A, n)
print(cnt)
print(*A, sep='\n')


Measured memory_bytes: 53304
//最小公倍数と最大公約数を求める
#include<iostream>
#include<cstdio>
#include<algorithm>
unsigned long a,b;//aとbの最小公倍数と最大公約数を求める
unsigned long G,L;//最大公約数と最小公倍数
int GCD(int x,int y){
  int c;
  c = x%y;
  if(c ==0)
    return y;
  else{
    return (GCD(y,c));
 }
}

int main(){
  while(scanf("%lu %lu",&a,&b) != EOF){
    if(a >b)
     G = GCD(a,b);
    else if(a <b)
      G = GCD(b,a);
    else
      G = a;
    
    L = (a*b)/G;
  printf("%lu %lu\n",G,L);

  }
  return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N 100010
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,a[N],V,P;
bool check(int x){
	int res=V-(n-x+1)-(P-1);
	if(a[x]+m<a[P])return false;
	if(res<=0)return true;
	ll tot=0;
	for(int i=P;i<x;++i){
		tot+=(a[x]+m)-a[i];
	}
	return tot>=1LL*res*m;
}
int main(){
	n=read(),m=read(),V=read(),P=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	sort(a+1,a+n+1,greater<int>());
	int l=P,r=n+1,ans=0;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid)){
			ans=mid,l=mid+1;
		}
		else{
			r=mid;
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 4000
#include <iostream>
#include <vector>
#include <queue>
#include <set>

#define MAX (int)1e5
using namespace std;

typedef pair<int,int> p;

int par[MAX+1]; //親
int ran[MAX+1]; //　木の深さ
int size[MAX+1];

int ans[MAX+1];
int valency[MAX+1];
// n個で初期化
void init(int n){
  for(int i=0;i<n;i++){
    par[i] = i;
    ran[i] = 0;
    size[i] = 1;
  }
}

// 木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  //cout << ran[x] << " " << ran[y] << endl;
  if(x == y)
    return;

  if(ran[x] < ran[y]){
    par[x] = y;
    size[y] = size[y] + size[x]; 
  }else{
    par[y] = x;
    size[x] = size[x] + size[y]; 
    if(ran[x] == ran[y])
      ran[x]++;
  }
}

bool same(int x,int y){
  return find(x) == find(y);
}


int main(void){
  int N,M,K;
  cin >> N >> M >> K;
  init(N+1);
  vector<p> con;
  vector<p> block;
  // init
  for(int i=1;i<=N;i++){
    valency[i] = 0;
  }
  for(int m=0;m<M;m++){
    int a,b;
    cin >> a >> b;
    con.push_back(make_pair(a,b));
  }
  for(int k=0;k<K;k++){
    int c,d;
    cin >> c >> d;
    block.push_back(make_pair(c,d));
  }
  // 友達リストでグラフを連結
  for(int i=0;i<M;i++){
    p edge = con[i];
    //次数計算
    //cout << "p:" << edge.first << " " << edge.second << endl;
    valency[edge.first]++;
    valency[edge.second]++;
    unite(edge.first,edge.second);
  }

  //ブロックを考えずに計算
  for(int i=1;i<=N;i++){
    //親ノードをみる
    int pare = find(i);
    ans[i] = size[pare] - valency[i] - 1;
  }
  //ブロック分を引く
  for(int i=0;i<K;i++){
    p bl = block[i];
    if(same(bl.first,bl.second)){
      ans[bl.first] -= 1;
      ans[bl.second] -= 1;
    }
  }

  for(int i=1;i<=N;i++){
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}


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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  if (n < 3) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  while (n >= 3) {
    n -= 3;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> a(N);
	rep(i,N)cin>>a[i];
	int ans = 0;
	rep1(i,N-1){
		if((a[i-1]<a[i]&&a[i]<a[i+1])||(a[i-1]>a[i]&&a[i]>a[i+1])){
			ans++;
			//cerr<<a[i-1]<<a[i]<<a[i+1]<<endl;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

void solve(){
    int n, k;
    cin >> n >> k;
    int ans = k;
    while(--n) ans *= (k - 1);
    cout << ans;
}

 
int main() {
    barsik;
    int q = 1;
    //cin >> q;
    while(q--) solve();
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def main():
# 整数の入力
    n = int(input())
    
    l = []
    for i in range(1, n+1):
        
        if (i % 3 != 0) and (i % 5 != 0):
            l.append(i)
    print(sum(l))

if __name__ == '__main__':
    main()

Measured memory_bytes: 29980
#include<stdio.h>
int main(){
  int h,w,d[10][10000],i,j,k,s,sum,max;
  while(scanf("%d %d",&h,&w),w||h){
    for(i=0;i<h;i++){
      for(j=0;j<w;j++)scanf("%d",&d[i][j]);
    }
    for(i=max=0;i<1<<h;i++){
      for(j=sum=0;j<w;j++){
	for(k=s=0;k<h;k++){
	  if((i>>k)%2==d[k][j])s++;
	}
	if(s>h-s)sum+=s;
	else     sum+=h-s;
      }
      if(max<sum)max=sum;
    }
    printf("%d\n",max);
  }
  return 0;
}

Measured memory_bytes: 988
n,k=map(int,input().split())

s=input()
now=s[0]

L=[0]
for c in s:
    if c==now:
        L[-1]+=1
    else:
        now=c
        L.append(1)
"""
zen_max=max(L)
cen_max=max(L[1:-1])
ans=zen_max
if zen_max != cen_max:
    ans-=1
"""

ans=sum(L)-len(L)

choice=len(L)//2

if choice<=k:
    print(n-1)
else:
    print(ans+2*k)


Measured memory_bytes: 3956
import itertools
import math

N = int(input())
path = []

for _ in range(N):
    x, y = map(int, input().split())
    path.append([x,y])

permutations = list(itertools.permutations(range(N), N))

total = 0.0

def distance(x1, y1, x2, y2):
    return math.sqrt((x1 - x2) ** 2.0 + (y1 - y2) ** 2.0)

for p in permutations:
    for i in range(len(p) - 1):
        x1, y1 = path[p[i]]
        x2, y2 = path[p[i + 1]]
        d = distance(x1,y1,x2,y2)
        total += d

print(total / len(permutations))

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

vector<string> split(string s) {
  vector<string> res;
  string t = "";
  for (int r = 0; r < s.size(); ++r) {
    if (s[r] == ' ' || s[r] == ',' || s[r] == '.') {
      res.push_back(t);
      t = "";
    } else {
      t += s[r];
    }
  }

  return res;
}

vector<string> ex(string s) {
  vector<string> v = split(s), res;
  for (int i = 0; i < v.size(); ++i) {
    if (2 < v[i].size() && v[i].size() < 7) {
      res.push_back(v[i]);
    }
  }
  return res;
}

int main() {
  string s;

  getline(cin, s);

  vector<string> v = ex(s);
  for (int i = 0; i < v.size(); ++i) {
    cout << v[i] << (i + 1 == v.size() ? "\n" : " ");
  }
}

Measured memory_bytes: 3180
import java.util.*;

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

        solve_149_C();
      
        return;
    }

    private static void solve_149_C() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int prime = A;
        boolean judge = true;

        do {
            judge = true;   // Initialize
            for (int i = 2; i * i <= prime; i++) {
                if ((prime % i) == 0) {
                    judge = false;
                    prime++;
                    break;
                }
            }
        }while(!judge);

        if(true == judge) {
            System.out.println(prime);
        }
    }
}

Measured memory_bytes: 23892
fn lcm(a: usize, b: usize) -> usize {
    let mut x = std::cmp::max(a, b);
    let mut y = std::cmp::min(a, b);
    while y != 0 {
        let tmp = y;
        y = x % y;
        x = tmp;
    }
    a * b / x
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let v: Vec<usize> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (a, b, c, d) = (v[0], v[1], v[2], v[3]);
    let a = a - 1;
    let lcm = lcm(c, d);
    let mut ans = b - a;
    ans -= b / c - a / c;
    ans -= b / d - a / d;
    ans += b / lcm - a / lcm;
    println!("{}", ans);
}


Measured memory_bytes: 4352
//arc064_c.cpp
//Sun Jun 10 12:20:09 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

int main(){
	ll n,x;
	cin >> n >> x;

	ll ans = 0;

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

	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
typedef vector<int> vi;

// Source is from 2004 POI. Cave

vector<int> gph[100005];
int n;

int ret;

int f(int x, int p){
	int cnt[22] = {};
	for(auto &i : gph[x]){
		if(i == p) continue;
		int v = f(i, x);
		for(int i=0; i<20; i++){
			cnt[i] += ((v >> i) & 1);
		}
	}
	int lst = -1;
	for(int i=20; i>=0; i--){
		if(cnt[i] >= 2){
			lst = i;
			break;
		}
	}
	int mask = 0;
	for(int i=lst+1; i<20; i++){
		if(cnt[i] == 0){
			ret = max(ret, i);
			for(int j=i+1; j<20; j++){
				if(cnt[j]) mask |= (1<<j);
			}
			mask |= (1<<i);
			return mask;
		}
	}
	assert(0);
}

int main(){
	cin >> n;
	for(int i=1; i<n; i++){
		int s, e;
		scanf("%d %d",&s,&e);
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	f(1, -1);
	cout << ret <<endl;
}



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

int main()
{
    int n,r,ans=1e9,a[102];
    cin>>n;
    for(int i=0;i<n;i++){ 
        cin>>a[i];
    } 
    for(int i=0;i<=100;i++){ 
        int c=0;
        for(int j=0;j<n;j++){ 
            c+=(a[j]-i)*(a[j]-i);
        }
        ans=min(ans,c);
    } 
    cout<<ans<<'\n';
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define MAX (1001)
using namespace std;
int main(void){
    string s, t;
    cin >> s;
    cin >> t;
    
    int min = MAX;
    
    for(int i = 0; i <= s.length() - t.length(); i++){
        string tmp = s.substr(i, t.length());
        int count = 0;
        for(int j = 0; j < t.length(); j++){
            if(tmp.at(j) != t.at(j)) count++;
        }
        if(count < min) min = count;
    }
    
    cout << min << endl;
    
}

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

template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

void calc(vector<int>& dp, int mp, int damage, int max_hp) {
	for(int i = 0; i < max_hp; ++i) {
		chmin(dp[min(max_hp, i + damage)], dp[i] + mp);
	}
}

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

	const int INF = 1e7;

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

		int m;
		cin >> m;

		const int max_hp = *max_element(hp.begin(), hp.end());
		vector<int> all_dp(max_hp + 1, INF), single_dp(max_hp + 1, INF);
		all_dp[0] = single_dp[0] = 0;

		for(int i = 0; i < m; ++i) {
			int mp, damage;
			string ignore, target;
			cin >> ignore >> mp >> target >> damage;

			if(target[0] == 'S') {
				calc(single_dp, mp, damage, max_hp);
			}
			else {
				calc(all_dp, mp, damage, max_hp);
			}
		}

		for(int i = max_hp; i > 0; --i) {
			chmin(single_dp[i - 1], single_dp[i]);
		}

		int ans = INF;
		for(int i = 0; i <= max_hp; ++i) {
			int tmp = all_dp[i];
			for(const auto& h : hp) {
				if(h <= i) continue;
				tmp += single_dp[h - i];
			}

			chmin(ans, tmp);
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1864
#include<iostream>
using namespace std;
int main(){
    int a,b,x;
    char op;
    cin >> a >> op >> b;
    while(op!='?'){
        if ( op == '+' ){x=a+b;}
        else if ( op == '-' ){x=a-b;} 
        else if ( op == '*' ){x=a*b;}
        else if ( op == '/' ){x=a/b;}
        cout << x << endl;
        cin >> a >> op >> b;
    }return 0;
}


Measured memory_bytes: 3092
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

#A, B = [int(x) for x in input().split()]

N = int(input())
S = input()

num = defaultdict(int)

for s in S:
    num[s] += 1

cnt = 1
for s in num:
    cnt = cnt * (num[s] + 1)
    cnt = cnt % (10 ** 9 + 7)

cnt = cnt -1
cnt = cnt % (10 ** 9 + 7)

print (cnt)

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

int main() {
	char b;
	cin >> b;
	if (b == 'A')
		cout << 'T';
	if (b == 'T')
		cout << 'A';
	if (b == 'C')
		cout << 'G';
	if (b == 'G')
		cout << 'C';
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#define y1 askjdkasldjlkasd
#include <bits/stdc++.h>
#undef y1

using namespace std;

#define pb push_back
#define mp make_pair
#define fi(a, b) for(int i=a; i<=b; i++)
#define fj(a, b) for(int j=a; j<=b; j++)
#define fo(a, b) for(int o=a; o<=b; o++)
#define fdi(a, b) for(int i=a; i>=b; i--)
#define fdj(a, b) for(int j=a; j>=b; j--)
#define fdo(a, b) for(int o=a; o>=b; o--)
#define sz(x) (int)x.size()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while (0)
#endif

double START_TIME;

void exit() {
#ifdef LOCAL	
	cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl;
#endif	
	exit(0);
}

template<typename A, typename B>
ostream& operator<<(ostream& os, pair<A, B> p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, vector<T> v) {
	fi(0, sz(v) - 1) {
		os << v[i] << " ";
	}
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, set<T> t) {
	for (auto z : t) {
		os << z << " ";
	}
	return os;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, map<T1, T2> t) {
	cerr << endl;
	for (auto z : t) {
		os << "\t" << z.first << " -> " << z.second << endl;
	}
	return os;
}

#ifdef LOCAL
#define dbg(x) {cerr << __LINE__ << "\t" << #x << ": " << x << endl;}
#define dbg0(x, n) {cerr << __LINE__ << "\t" << #x << ": "; for (int ABC = 0; ABC < n; ABC++) cerr << x[ABC] << ' '; cerr << endl;}
#else
#define dbg(x) while(0){}
#define dbg0(x, n) while(0){}
#endif

#ifdef LOCAL
#define ass(x) if (!(x)) { cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); }
#else
#define ass(x) assert(x)
#endif

///////////////////////////////////////////////////

vi a;
int n;

void bad() {
	printf("No\n");
	exit(0);
}

void ok() {
	printf("Yes\n");
	exit(0);
}

bool check(vi a, vpii v) {
	while (sz(a) < n) {
		int w = a[sz(a) - 1] ^ a[sz(a) - 2];
		int p = -1;
		fo(0, sz(v) - 1) {
			if (v[o].first == w) {
				p = o;
				break;
			}
		}
		if (p == -1 || v[p].second == 0) return false;
		v[p].second--;
		a.pb(w);
	}
	fi(0, sz(a) - 1) {
		int v1 = a[(i - 1 + n) % n];
		int v2 = a[(i + 1) % n];
		if (a[i] != (v1 ^ v2)) return false;
	}
	return true;
}

void solve () {
	sort(a.begin(), a.end());
	vpii v;
	fi(0, sz(a) - 1) {
		if (sz(v) > 0 && v.back().first == a[i]) {
			v.back().second++;
		} else {			
			v.pb(mp(a[i], 1));
		}
	}		
	if (sz(v) > 3) {
		bad();
	}

	dbg(a);
	dbg(v);

	fi(0, sz(v) - 1) {
		v[i].second--;
		fj(0, sz(v) - 1) {
			if (v[j].second == 0) continue;
			v[j].second--;
			vi b;
			b.pb(v[i].first);
			b.pb(v[j].first);
			if (check(b, v)) ok();
			v[j].second++;
		}
		v[i].second++;
	}
	bad();
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	START_TIME = (double)clock();
#endif

	scanf("%d", &n);
	a = vi(n);
	fi(0, n - 1) scanf("%d", &a[i]);
		
	solve();

	exit();
	return 0;
}





Measured memory_bytes: 1656
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back

using namespace std;

const ll sz=1e5+5;
const ll szz=1e6+6;
const ll mod=1e9+7;

int main()
{
	Ryuga;



	clock_t startTime=clock();

	ll n;
	cin >> n;
	vector<ll> v(n), pref(n), suf(n);
	rep(i, 0, n) {
		cin >> v[i];
		pref[i] = v[i];
		suf[i] = v[i];
	}
	rep(i, 1, n) 
		pref[i] = __gcd(pref[i - 1], pref[i]);
	for(ll i=n-2;i>=0;i--) 
		suf[i] = __gcd(suf[i + 1], suf[i]);
	ll ans = 1;
	rep(i, 0, n) 
	{
		ll p, s;
		if (i - 1 >= 0) 
			p = pref[i - 1]; 
		else
			p = suf[i + 1];
		

		if (i + 1 < n) 
			s = suf[i + 1]; 
		else 
			s = pref[i - 1];
		
		ans = max(ans, __gcd(p, s));
	}
	cout << ans << '\n';

	cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...

Measured memory_bytes: 2560
#include<cstdio>
#include<algorithm>
#include<set>
#define maxn 100005
#define maxm 15
#define LL long long
using namespace std;
typedef pair<int,int> PII;
set<PII> used;
int h,w,n,dir[9][2]={{0,0},{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
PII a[maxn];
LL ans[maxm];
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i].first,&a[i].second);
	sort(a+1,a+n+1);
	ans[0]=1ll*(h-2)*(w-2);
	for(int i=1;i<=n;i++)
	{
		int cnt,x=a[i].first,y=a[i].second;
		//if(x==1||y==1||x==h||y==w) continue;
		for(int j=0;j<9;j++)
		{
			cnt=0;
			int tx=x+dir[j][0],ty=y+dir[j][1];
			if(tx<=1||ty<=1||tx>=h||ty>=w) continue;
			if(used.find(PII(tx,ty))!=used.end()) continue;
			cnt+=upper_bound(a+1,a+n+1,PII(tx-1,ty+1))-lower_bound(a+1,a+n+1,PII(tx-1,ty-1));
			cnt+=upper_bound(a+1,a+n+1,PII(tx,ty+1))-lower_bound(a+1,a+n+1,PII(tx,ty-1));
			cnt+=upper_bound(a+1,a+n+1,PII(tx+1,ty+1))-lower_bound(a+1,a+n+1,PII(tx+1,ty-1));
			ans[cnt]++;
			ans[0]--;
			used.insert(PII(tx,ty));
			//printf(" * %d %d %d\n",tx,ty,cnt);
		}
	}
	for(int i=0;i<=9;i++) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 43264
N = int(input())

ST = list()

for i in range(N):
    s, t = input().split()
    ST.append([s, t])

X = input()

result = None

for s, t in ST:
    t = int(t)
    if result is None:
        if s == X:
            result = 0
    else:
        result += t

print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0,(i##_len)=(n);(i)<(i##_len);(i)++)
#define rep2(i,a,b) for(ll (i)=(a),(i##_len)=(b);(i)<=(i##_len);(i++))
#define Yes(n) cout<<((n)?"Yes\n":"No\n")
#define pb push_back
using namespace std;
using ll = long long;

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(a>b){a=b;return true;}return false;}
template<class T> T abs(T x){return max(x,-x);}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm(T m,T n) {return m*n/gcd(m,n);}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm<T>(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
vector<string> split(const string&s,char d){vector<string>r;stringstream ss(s);string k;while(getline(ss,k,d))if(!k.empty())r.pb(k);return r;}

// Template ends here

int main() {
    int n, m, c, cnt = 0; cin >> n >> m >> c;
    vector<int> B(m); rep(i, m) cin >> B.at(i);

    rep(i, n) {
        int dot_product = 0;
        rep(j, m) {
            int a; cin >> a;
            dot_product += a * B.at(j);
        }

        cnt += (dot_product + c > 0);
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
int main()
{
  int N, t[110000] = {0}, x[110000] = {0}, y[110000] = {0};
  std::cin >> N;
  std::string result = "Yes";
  
  for(int i = 1; i <= N; i++)
  {
    std::cin >> t[i] >> x[i] >> y[i];  
  }
  
  for(int i = 1; i <= N; i++)
  {
    int time = t[i] - t[i-1];
    int dist = std::abs(x[i] - x[i - 1]) + std::abs(y[i] - y[i - 1]);
    if((time < dist) || (time % 2 != dist % 2))
    {
      result = "No";
      break;
    }
  }
    
  std::cout << result;
  return 0;
}

Measured memory_bytes: 4396
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String[] s = new String[sc.nextInt()];
		sc.next();
		Arrays.setAll(s, i -> sc.next());
		Arrays.stream(s).sorted().forEach(System.out::print);
		System.out.println();
	}
}


Measured memory_bytes: 37416
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;



int main()
{
	int H, A;
	cin >> H >> A;
	cout << H / A + ((H%A)!=0) << endl;
}

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

const int N = 1e5 + 5;
ll l, r;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> l >> r;
    
    if(r - l +1>=2019){
        cout << 0 << "\n";
    }else{
        long long ans = 2019;
        for (int i = l; i < r; i++){
            for (int j = i+1; j <= r; j++){
                ans = min(ans, 1ll * i * j % 2019);
            }
        }
        cout << ans << "\n";
    }
    
    
    
    return 0;
}


Measured memory_bytes: 256
//E.H//
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n,arr[100005];
int byk[100005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    int maxi=-1;
    int mini=1000000000;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        byk[arr[i]]++;
        maxi=max(maxi,arr[i]);
        mini=min(mini,arr[i]);
    } 
    if(maxi==mini){
        if(maxi==n-1 || 2*maxi<=n){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    else if(maxi==mini+1){
        int x=byk[mini];
        int y=byk[maxi];
        if(x+1<=maxi && maxi<=x+(y/2)) {
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    else cout<<"No"<<endl;
}

Measured memory_bytes: 4300
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,mx;
  cin >> a >> b;
  mx=a+b;
  c=a-b;
  if(mx<c)mx=c;
  c=a*b;
  if(mx<c)mx=c;
  cout << mx << endl;
}
  


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

int main(){
  long long x;
  cin>>x;
  long long ans=0;
  while(x>=500){
    x-=500;
    ans+=1000;
  }
  while(x>=5){
    x-=5;
    ans+=5;
  }
  cout<<ans<<endl;
    
  return 0;
}

Measured memory_bytes: 3572
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        char[] Sc = S.toCharArray();

        int index = Sc.length/2;
        int count = 0;

        for(int i=0; i < index ; i++) {
            if(Sc[i] != Sc[(Sc.length-1)-i]){
               count++;
           }
        }
        System.out.println(count);

    }
}


Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int ans = 0;
  string S, T; cin>>S>>T;
  REP(i,S.length()) {
    if(S[i] != T[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3488
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

mint factorial(ll n) {
  mint answer = 1;
  while (n > 1) {
    answer *= n;
    n--;
  }
  return answer;
}

mint combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

mint permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

// setprecision(8) 桁数指定
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  string s;
  cin >> s;
  REP(i, s.size()) { cout << 'x'; }
  cout << endl;
  return 0;
}

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

int arr[100000];
int arr2[100000];

int main()
{
	int n;
	std::cin >> n;
	for (int i = 0; i < n; i++)
	{
		std::cin >> arr[i];
	}
	for (int i = n-2; 0 <= i; i--)
	{
		int min = INT_MAX;
		for (int j = 1; j <= 2; j++)
		{
			if (i + j < n) {
				int dif = std::abs(arr[i] - arr[i + j]) + arr2[i + j];
				if (dif < min)
					min = dif;
			}
		}
		arr2[i] = min;
	}
	std::cout << arr2[0] << std::endl;
}

Measured memory_bytes: 1024
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str;
	int a[]=new int[4];
	while((str=input.readLine())!=null)
	    {
		String str_ary[]=str.split(",");
		
		if(str_ary[1].equals("A"))a[0]++;
		if(str_ary[1].equals("B"))a[1]++;
		if(str_ary[1].equals("AB"))a[2]++;
		if(str_ary[1].equals("O"))a[3]++;
		
	    }
	for(int i=0;i<4;i++)
	    {
		System.out.println(a[i]);
	    }
    }
}

Measured memory_bytes: 16980
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

// vi g[N];
// int a[N];

void solve() {
  int i, j, k, w;
  int a[3][3];
  fo(i,3) fo(j,3) cin >> a[i][j];
  int f[3][3] = {0};
  int n; cin >> n;
  vi b(n);
  fo(i,n) cin >> b[i];
  fo(i,n){
    fo(j,3){
      fo(k,3){
        if(a[j][k]==b[i]) f[j][k]=1;
      }
    }
  }
  int ans = 0;
  fo(i,3){
    if(f[i][0]==1 && f[i][1]==1 && f[i][2]==1)  ans++;
  }
  fo(i,n){
    if(f[0][i]==1 && f[1][i]==1 && f[2][i]==1)  ans++;
  }
  if(f[0][0]==1 && f[1][1]==1 && f[2][2]==1)  ans++;
  if(f[0][2]==1 && f[1][1]==1 && f[2][0]==1)  ans++;

  if(ans>0) cout << "Yes";
  else cout << "No";

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    // cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
#include <cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

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

  for(int i = 0; i < 10; i++)
    {
      for(int j = 0; j < 10; j++)
        {
          if(n == i * j)
            {
              cout << "Yes" << endl;
              return 0;
            }
        }
    }
  cout << "No" <<endl;
}


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

#define ArrayNum 1000000

vector<int> g;

int insertionSort(int a[],int n,int g){
  int i,j,cnt=0,v;

  for(i=g;i<n;i++){
    v= a[i];
    j=i-g;
    while(j>=0 && a[j]>v){
      a[j+g]=a[j];
      j=j-g;
      cnt++;
    }
    a[j+g]=v;
  }
  return cnt;
}

void shellSort(int a[], int n){
  int i,cnt=0,m;
  
  for(int h=1;;){
    if(h>n)
      break;
  g.push_back(h);
  h=3*h+1;
  }
  m=g.size();
  for(i=m-1;i>=0;i--)
    cnt=cnt+insertionSort(a,n,g[i]);

  cout << m << "\n";
  for(i=m-1;i>0;i--)
    cout << g[i] << " ";
  cout << g[0] << "\n";
  cout << cnt << "\n";
  for(i=0;i<n;i++)
    cout << a[i] << "\n";

}

int main(void){
  int i,n,a[ArrayNum];
  cin >> n;
  for(i=0;i<n;i++)
    cin >> a[i];
  shellSort(a,n);

}



Measured memory_bytes: 7008
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

h, w = MAP()
s = []
for i in range(h):
    s.append(input())
a = [[0]*w for i in range(h)]
b = [[0]*w for i in range(h)]

for i in range(h):
    tmp = 0
    for j in range(w):
        if s[i][j] == '.':
            tmp += 1
            a[i][j] = tmp
        else:
            tmp = 0
    tmp = 0
    for j in range(w-1, -1, -1):
        if s[i][j] == '.':
            tmp = max(tmp, a[i][j])
            a[i][j] = tmp
        else:
            tmp = 0

ans = 0
for j in range(w):
    tmp = 0
    for i in range(h):
        if s[i][j] == '.':
            tmp += 1
            b[i][j] = tmp
        else:
            tmp = 0
    tmp = 0
    for i in range(h-1, -1, -1):
        if s[i][j] == '.':
            tmp = max(tmp, b[i][j])
            b[i][j] = tmp
        else:
            tmp = 0
        ans = max(ans, a[i][j]+b[i][j]-1)
print(ans)

Measured memory_bytes: 138428
def index(n:int, a: int):
    if a % 2 == 0:
        i = n // 2 - a // 2
        j = (i + 1) * -1
        return (i, j) if i != n // 2 else (i,)
    else:
        i = (n // 2 - 1) - (a - 1) // 2
        j = (i + 1) * -1
        return (i, j)

n = int(input())
line = [0 for _ in range(n)]
for a in map(int, input().split()):
    for i in index(n, a):
        line[i] += 1
else:
    if n == 1 and line == [1]:
        print(1)
    elif n % 2 == 0 and set(line) == {2}:
        print(2 ** (n // 2) % (10 ** 9 + 7))
    elif n % 2 == 1 and set(line) == {1, 2} and line[n//2] == 1:
        print(2 ** ((n - 1) // 2) % (10 ** 9 + 7))
    else:
        print(0)

Measured memory_bytes: 11248
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;cin>>x;
    ll sum=0;
    for(int i=1;i<=x;i++){
        sum+=i;
        if(sum>=x){
            cout<<i<<endl;
            return 0;
        }
    }
    
}

Measured memory_bytes: 256