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

class Main {

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

        char[] ss = s.next().toCharArray();

        if (ss[2] != ss[3]) {
            System.out.println("No");
            return;
        }
        if (ss[4] != ss[5]) {
            System.out.println("No");
            return;
        }
        System.out.println("Yes");
    }

}


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

int main()
{
    int N,Z,W;cin >> N >> Z>>W;
    vector<int> vec;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec.push_back(b);
    }
    if(N == 1)cout<<abs(vec.front()-W)<<endl;
    else cout<<max(abs(vec.back()-W),abs(vec.at(N-2)-vec.at(N-1)))<<endl;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

vector<pair<char,int>> P;
int N;
string S;

bool solve(int l)
{
	for(int i=0;i<P.size();i++) {
		if(S[l]==P[i].first) l+=P[i].second;
		if(l<0) return true;
		if(l>=N) return false;
	}
	return false;
}

bool solve2(int l)
{
	for(int i=0;i<P.size();i++) {
		if(S[l]==P[i].first) l+=P[i].second;
		if(l>=N) return true;
		if(l<0) return false;
	}
	return false;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int Q, s=0, e, ans=0;
	cin>>N>>Q>>S; P.resize(Q);
	for(int i=0;i<Q;i++) {
		char t;
		cin>>P[i].first>>t;
		P[i].second=t=='L' ? -1:1;
	}
	e=N-1;
	while(s<=e) {
		int m=(s+e)>>1;
		if(solve(m)) s=m+1;
		else e=m-1;
	}
	ans+=s;
	s=0, e=N-1;
	while(s<=e) {
		int m=(s+e)>>1;
		if(solve2(m)) e=m-1;
		else s=m+1;	
	}
	ans+=N-s;
	cout<<N-ans<<'\n';
	return 0;
}

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

int main() {
  int N;
  int k = 1;
  cin >> N;

  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
      
      if (s == "Y") {
        cout << "Four" << endl;
        k ++;
        break;
      
    }
  }
  if (k == 1) {
    cout << "Three" << endl;
  }   
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

int main()
{
	int n, k;
	cin >> n >> k;
	ll a[n];
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	ll ans = 10000000000;
  	k--;
	for (int i = 0; i + k < n; i++)ans = min(ans, a[i + k] - a[i]);
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n,i;
  cin>>n>>i;
  cout<<n-i+1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
#define N_MAX 100005
typedef long long ll;
double xf[N_MAX];
double xl[N_MAX];
string u[N_MAX];
int main() {
	int N;
  	cin >> N;
  	double sum = 0;
  	for(int i = 0; i < N; i++){
      	double x;
    	cin >> x >> u[i];
      	cerr << x << endl;
      	if(u[i] == "JPY"){
        	xl[i] = x;
          	xf[i] = 0;
        } else {
         	xl[i] = 0;
          	xf[i] = (double)380000*x;
        }
    }
  	for(int i = 0; i < N; i++){
      	cerr << xl[i] << ' ' << xf[i] << endl;
    	sum = sum + xl[i] + xf[i];
    }
  	cout << sum << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N, X;
    cin >> N >> X;
    int pos = 0;
    int count = 0;
    for (int i = 0; i < N; ++i)
    {
        if (pos <= X)
        {
            ++count;
        }
        int Li;
        cin >> Li;
        pos += Li;
    }
    if (pos <= X)
    {
        ++count;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

static const int INF = 1e9 + 7;

int n, m, r;
vector<int> check;
vector<vector<int>> cost;
int dp[1 << 8][201];

int dfs(int bit, int now){
    if(bit == ((1 << r) - 1)){
        return 0;
    }
    if(~dp[bit][now]) return dp[bit][now];
    int res = INF;
    for(int i = 0; i < r; i++){
        if((1 << i) & bit){
            continue;
        }
        res = min(res, dfs(bit ^ (1 << i), i) + cost[check[now]][check[i]]);
    }
    return dp[bit][now] = res;
}

int main(){
    cin >> n >> m >> r;
    check.resize(r);
    for(auto&& i : check){
        cin >> i;
        i--;
    }
    cost.resize(n, vector<int>(n, INF));
    for(int i = 0; i < n; i++){
        cost[i][i] = 0;
    }
    for(int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        cost[a - 1][b - 1] = cost[b - 1][a - 1] = c;
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
            }
        }
    }
    memset(dp, -1, sizeof(dp));
    int ans = INF;
    for(int i = 0; i < r; i++){
        ans = min(ans, dfs(1 << i, i));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 640
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        System.out.println(Math.min((b/a),c));
    }
}


Measured memory_bytes: 36132
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i) 
#define per(i,a,b) for(int i=a;i>=b;--i)
#define rvc(i,S) for(int i=0;i<(int)S.size();++i)

#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define maxn 400020
#define N 8000020
#define int long long
using namespace std;
int a[maxn];
int n,x;
int sum=0;
signed main()
{ cin>>n>>x;
 int tmp=x;
  rep(i,1,n) {scanf("%d",&a[i]);sum+=a[i];}
  sort(a+1,a+n+1);
  int ans=0;
  rep(i,1,n)
   { if(x>=a[i]) {ans++; x-=a[i];}
   }
  if(sum<tmp) ans--;
  cout<<ans<<endl;	
	
 return 0;	
}

Measured memory_bytes: 256
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
 */
import java.util.*;
import java.awt.*;
import java.awt.Graphics.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt(),m=sc.nextInt(),l=sc.nextInt();
        int[][] a=new int[n][m];
        int[][] b=new int[m][l];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j]=sc.nextInt();
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < l; j++) {
                b[i][j]=sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < l; j++) {
                long c=0;
                for (int k = 0; k < m; k++) {
                    c+=(long) a[i][k]*(long) b[k][j];
                }
                out.print(c);
                if(j!=l-1)out.print(" ");
                else out.println();
            }
        }
    }
}


Measured memory_bytes: 55328
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 100000;
int main()
{
  int n,m,a,b,i,res=0;
  int h[N_MAX];
  bool g[N_MAX];
  cin >> n >> m;
  fill(g,g+n,1);
  for(i=0;i<n;i++)
    cin >> h[i];
  for(i=0;i<m;i++){
    cin >> a >> b;
    if(h[a-1]<=h[b-1]) g[a-1]=0;
    if(h[a-1]>=h[b-1]) g[b-1]=0;
  }
  for(i=0;i<n;i++)
    res+=g[i];
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3672
#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    string a,b,c;
    cin >> a >> b >> c;
    
    if(a[a.size()-1] != b[0])
    {
        cout << "NO";
    }
    else if(b[b.size()-1] != c[0])
    {
        cout << "NO";
    }
    if(a[a.size()-1] == b[0] and b[b.size()-1] == c[0])
       {
        cout << "YES";
    }
}


Measured memory_bytes: 3028
#include<iostream>
using namespace std;
int main() {
	int n,count = 0;
	cin >> n;    
	for (int i = 1; i <= n; i++) {
		if (i % 2 == 1) {
			count++;
		}
	}
	double output = (double)count / (double)n;
	cout << output;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp    make_pair
#define pb    push_back
#define F     first
#define pi 	  3.14159265358979323846
#define S     second
#define ll    long long
#define ld    long double
#define sz(s) (ll)s.size() 
#define vl    vector < ll >
#define pll   pair < ll, ll >
#define ml    map < ll, ll >
#define mod   1000000007
#define qe	  998244353
#define MAXN  100005
#define mx    10000005
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define inv(i,a,b)  for(i=a;i>=b;i--)
#define all(a)  (a).begin(),(a).end()
using namespace std;
int main(){
//	#ifndef ONLINE_JUDGE
//    if (fopen("input.txt", "r"))
//    {
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
//    }
//	#endif
	IOS;
	ll t,n,l,l1;
	ll i,j,m,mn,q,d,x,y,sum=0,r,p,k,c;
	string s,s1;
	cin>>n>>k;
	ll a[n],dp[k+1]={0};
	rep(i,0,n)cin>>a[i];
	rep(i,1,k+1){
		rep(j,0,n){
			ll z=1;
			if(a[j]<=i){
				z^=dp[i-a[j]];
			dp[i]|=z;
			}
		}
	}
//	rep(i,0,k+1)cout<<dp[i]<<" ";
	if(dp[k])cout<<"First";else cout<<"Second";
}

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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

bool seen[100010]={false};

void g(ll j,vector<vector<ll>> &a){
    seen[j]=true;
    for(ll k=0;k<a[j].size();k++){
        if(seen[a[j][k]]==false){
            g(a[j][k],a);
        }
    }
}

int main() {
    ll n,m;cin>>n>>m;
    ll x[m],y[m],z[m];
    vector<vector<ll>> a(n);
    for(ll i=0;i<m;i++){
        cin>>x[i]>>y[i]>>z[i];
        a[x[i]-1].push_back(y[i]-1);
        a[y[i]-1].push_back(x[i]-1);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(seen[i]==false){
            g(i,a);
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 11264
s = input()
n = len(s)
ans = 0
if n % 2 == 0:
    for a, b in zip(s[:n//2], reversed(s[n//2:])):
        if a != b:
            ans += 1
else:
    for a, b in zip(s[:n//2], reversed(s[n//2+1:])):
        if a != b:
            ans += 1
print(ans)

Measured memory_bytes: 3060
using namespace std;
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 1000000007
#define mod 998244353
#define sec setprecision
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
int main() {
	int n; cin >> n;
	vector<int>a(n); rip(i, n)cin >> a[i];
	sort(all(a));
	ll sum = 0;
	sum += a[n - 1];
	int j = n-1;
	rip(i, n - 2) {
		if (i % 2 == 0)j--;
		sum += a[j];
	}
	cout << sum << endl;
}

Measured memory_bytes: 4048
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> x >> k >> d;
  if (x >= 0) {
    ll kai = x / d;
    x -= d * min(k, kai);
    k -= min(k, kai);
    if (k == 0) {
      Cout(abs(x));
      return 0;
    }
  } else {
    ll kai = -x / d;
    x += d * min(k, kai);
    k -= min(k, kai);
    if (k == 0) {
      Cout(abs(x));
      return 0;
    }
  }
  rep(i, 3) {
    if (k == 0) break;
    if (abs(x + d) < abs(x)) {
      x += d;
      k--;
    } else if (abs(x - d) < abs(x)) {
      x -= d;
      k--;
    }
  }
  if (k % 2 == 0)
    Cout(abs(x));
  else {
    ans = min(abs(x + d), abs(x - d));
    Cout(ans);
  }
  return 0;
}

Measured memory_bytes: 3652
import sys
input = sys.stdin.readline

mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))

NN = 4*10**5 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

P = [0, 1]
for k in range(2, N+1):
    P.append(inverse[k]+P[-1])

ans = 0
for i, a in enumerate(A):
    ans += (P[i+1]+P[N-i]-1) * g1[N] * a % mod
    ans %= mod

print(ans)

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

#define llint long long int

using namespace std;

int main(){
  int n;
  cin >> n;
  if(n){
    int max_d = n/4+1;
    for(int i = 0; i <= max_d; i++){
      int temp = n;
      temp -= 4*i;
      if(temp%7 == 0){
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}

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

int gcd(int a, int b){ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

int gcd3(int a, int b, int c){
    return gcd(a,gcd(b,c));
}

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

    int sum=0;
    for (int i=1;i<K+1;i++){
        for (int j=1;j<K+1;j++){
            for (int k=1;k<K+1;k++){
                sum+=gcd3(i,j,k);
            }
        }
    }
    cout << sum << endl;
}

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

#define rep(i, n) for(int i=0; i<n; i++)

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

    int score = 0;
    rep(i, n-1) if(s[i] == s[i+1]) score++;

    cout << min(n-1, score+2*k) << endl;
    return 0;
}


Measured memory_bytes: 512
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
#include <stack>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;
template <class T> T gcd(T n, T m){return m ? gcd(m, n%m):n;}

const int N = 200000;
const int MOD = 1e9+7;

int main(){
    int n;
    cin>>n;
    vector<pair<int,int> > task;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        task.emplace_back(b, a);
    }
    sort(task.begin(),task.end());
    ll sum=0;
    bool done=true;
    for(auto v:task){
        sum+=v.second;
        if(sum>v.first){
            done=false;
            break;
        }
    }
    if(done) cout << "Yes"<<endl;
    else cout << "No" << endl;
}

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

const int dx[6] = {1,1,0,-1,-1,0};
const int dy[6] = {0,1,1,0,-1,-1};
const int MAXN = 10;
const int NONE = -1;
const int INF = (1<<28);

int N, C;
int G[MAXN][MAXN];
bool vis[MAXN][MAXN];

// テヲツ按サテ」ツつ甘・ツ?、:(テ」ツつーテ」ツδォテ」ツδシテ」ツδ療」ツ??テ」ツ?ィテゥツ堋」テヲツ篠・テ」ツ?療」ツ?ヲテ」ツつ凝」ツ??テ」ツつーテ」ツδォテ」ツδシテ」ツδ療」ツ?ォテ」ツ??」ツ?湘」ツ?、テ・ツ青ォテ」ツ?セテ」ツつ古」ツ?ヲテ」ツ??」ツつ凝」ツ??
pair<int,int> dfs(int x, int y) {
  pair<int,int> res(0, 1);
  vis[y][x] = true;
  for(int i = 0; i < 6; ++i) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx < 0 || nx >= N) continue;
    if(ny < 0 || ny >= N) continue;
    if(G[ny][nx] == 0) {
      res.first = 1;
      continue;
    }
    if(G[ny][nx] != G[y][x]) continue;
    if(vis[ny][nx]) continue;

    pair<int,int> p = dfs(nx, ny);
    res.first |= p.first;
    res.second += p.second;
  }
  return res;
}

int putNum(int x, int y, int num) {
  int res = 0;
  G[y][x] = num;
  fill(vis[0], vis[MAXN], false);
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      if(!vis[i][j] && G[i][j] != 0 && G[i][j] != NONE) {
        pair<int,int> p = dfs(j, i);
        if(!p.first) {
          if(G[i][j] == num) {
            res -= p.second;
          } else {
            res += p.second;
          }
        }
      }
    }
  }
  G[y][x] = 0;
  return res;
}

int main() {
  while(cin >> N >> C && (N|C)) {
    fill(G[0], G[MAXN], NONE);
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < i+1; ++j) {
        cin >> G[i][j];
      }
    }

    int res = -INF;
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < N; ++j) {
        if(G[i][j] == 0) {
          res = max(res, putNum(j, i, C));
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdbool.h>

void Island(int x,int y,int number);
void solve(int w,int h);

int map[52][52]={{0}};

int main(void){
  int w,h;
  while(scanf("%d%d",&w,&h) && w!=0 && h!=0){
    solve(w,h);
  }
  return 0;
}

void solve(int w,int h){
  int i,j;
  int x,y;
  int number=2;
  
  for(i=0;i<52;i++) for(j=0;j<52;j++) map[i][j]=0;
  
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      scanf("%d",&map[i][j]);
    }
  }
  for(x=1;x<=h;x++){
    for(y=1;y<=w;y++){
      if(map[x][y]==1){
        Island(x,y,number);
        number++;
      }
    }
  }
  printf("%d\n",number-2);
  return 0;
}


void Island(int x,int y,int number){
  int i,j;
  map[x][y]=number;
  for(i=-1;i<=1;i++){
    for(j=-1;j<=1;j++){
      if(map[x+i][y+j]==1){
        Island(x+i,y+j,number);
      }
    }
  }
}

  

Measured memory_bytes: 788
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	string s;
	int countg = 0;
	int countp = 0;
	int point = 0;

	cin >> s;
	countg++;
	if (s[0] == 'p') {
		point--;
	}
	FOR(i, 1, s.size() - 1) {
		if (countp == countg) {
			countg++;
			if (s[i] == 'p') {
				point--;
			}
		}
		else {
			countp++;
			if (s[i] == 'g') {
				point++;
			}
		}
	}
	cout << point << endl;
	return 0;
}

Measured memory_bytes: 512
s = input()
t = input()

st = []

for i,c in enumerate(s):
    if i + len(t) > len(s):
        break
    if c == t[0] or c == '?':
        isok = True
        for j, c2 in enumerate(t):
            if s[i+j] == c2 or s[i+j] == '?':
                continue
            else:
                isok = False
        if isok:
            st.append((s[:i] + t + s[i+len(t):]).replace('?', 'a'))
st.sort()
print('UNRESTORABLE' if len(st)==0 else st[0])


Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

def main():
    k,s = map(int, input().split())

    ans = 0
    for x in range(k+1):
        for y in range(k+1):
            z = s - x - y
            if 0 <= z and z <= k:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
	int a,b,n;
	while(scanf("%d%d%d",&a,&b,&n) == 3){
		int r = a % b;
		int s  = 0;
		for(int i = 0; i < n; i++){
			r *= 10;
			s += r / b;
			r %= b;
		}
		printf("%d\n",s);
	}
	return 0;
}



Measured memory_bytes: 3160
#include <stdio.h>

int fibonacci(int);

int main(){
  int n;

  scanf("%d",&n);
  if(n < 0 || n > 44)return 0;
  
  printf("%d\n",fibonacci(n));
  
  return 0;
}

int fibonacci(int n){
  int i,F[n+1];
  F[0] = 1;
  F[1] = 1;
  for(i = 2; i < n+2; i++)F[i] = F[i -2] + F[i - 1];
  return F[n];
}



Measured memory_bytes: 2112
var
	n,i:Longint;
	ans,sum,t:int64;
	a:array[1..200000]of Longint;
begin
	read(n);
	ans:=1000000000000000000;
	for i:=1 to n do begin
		read(a[i]);
		sum:=sum+a[i];
	end;
	for i:=1 to n-1 do begin
		t:=t+a[i];
		if ans>abs(sum-t*2)then ans:=abs(sum-t*2);
	end;
	writeln(ans);
end.


Measured memory_bytes: 896
#include <stdio.h>

long long abs(long long A);
int main(void)
{
    long long X,K,D,M,q,r,ans=0;
    scanf("%lld %lld %lld",&X,&K,&D);
    X=abs(X);
    D=abs(D);
    q=X/D;
    r=X%D;

    M=K-q;

    if(M<=0){
        ans=X-K*D;
        // printf("A");
    } else {
        if(M%2==0){
            ans=X%D;
            // printf("B");
        } else {
            ans=abs(D-X%D);
            // printf("C");
        }
    }
    printf("%lld",ans);
    return 0;
}

long long abs(long long A)
{
    if(A<0) A=(-1)*A;
    return A;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn = 2e5+10;
const int inf = 0x3f3f3f3f;
int n;
ll num[maxn],ans,a[maxn];
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	rep(i,1,n) {
		int x;
		cin>>x;
		a[i]=x;
		num[x]++;
	}
	rep(i,1,n) {
		ans+=num[i]*(num[i]-1)/2;
	}
	rep(i,1,n) {
		cout<<ans-num[a[i]]+1<<'\n';
	}
	return 0;
}

Measured memory_bytes: 4736
#include<stdio.h>
int main()
{
	int a,b[200000],i,u=1,m,c[200000]={0},t=0,t1;
	scanf("%d",&a);
	for(i=1;i<=a;i++)
	{
	scanf("%d",&b[i]);
	c[b[i]]++;
	}
	while(t<a/2)
	{
		t=c[u]+t;
		t1=u;
		u++;
	}
	if(t>a/2)
	{
		m=0;
	}
	else
	{
		for(i=u;;i++)
		{
			if(c[i]!=0)
			{
				m=i-t1;
				break;
			}
		}
	}
	printf("%d",m);
}

Measured memory_bytes: 1280
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N int
var S string

func main() {
	sc.Split(bufio.ScanWords)

	N = nextInt()
	S = nextStr()

	if N == 2 {
		if S[0] == S[1] {
			fmt.Println(1)
		} else {
			fmt.Println(0)
		}
		return
	}
	ans := 0
	for i := 1; i < N-1; i++ {
		tmp := 0
		for j := 0; j < i; j++ {
			if !strings.Contains(string(S[:j]), string(S[j])) && strings.Contains(string(S[i:]), string(S[j])) {
				tmp++
			}
		}

		ans = maxInt(ans, tmp)
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1772
i=61,c,f[],m,s;main(y){for(;s?++f[y*12+*f+"=>?2J13IK<@V&"[--s]]:~scanf("%d,%d,%d",f,&y,&s)?s=s*4+1:++i<180?i%12>1?m=fmax(m,f[i]),f[i]||++c:1:!printf("%d\n%d\n",c,m););}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
#define ll long long
static const int MAX = 100010;
static const ll INFTY = 1e12;
static const int NUMMAX = 300;


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

  vector<int> A(N), B(N), C(N);
  int ans = 0;

  REP(i, N){
    cin >> A[i];
    A[i]--;
  }
  REP(i, N){
    cin >> B[i];
  }
  REP(i, N-1){
    cin >> C[i];
  }

  REP(i, N){
    ans += B[A[i]];
    if( i > 0 && ( A[i] - A[i-1] == 1 )){
      ans += C[A[i-1]];
    }
  }

  cout << ans << endl;



  return 0;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> a(n), s(n + 1);
  for (double& x : a) cin >> x;
  rep(i, 0, n) s[i + 1] = s[i] + ((a[i] * (a[i] + 1.0)) / 2.0) / a[i];

  double ans = 0;
  rep(i, 0, n - k + 1) { ans = max(ans, s[i + k] - s[i]); }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 6372
n, k = [int(i) for i in input().split()]
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
print(len(Base_10_to_n(n, k)))

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll K;
  string S;
  cin >> K;
  cin >> S;
  ll N = S.size();
  if (N <= K)
    cout << S << endl;
  else {
    REP(i, K) cout << S[i];
    cout << "..." << endl;
  }
  return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long n;
    cin >> n;
    if (n & 1) cout << 0 << '\n';
    else {
        long long zeros = 0;
        for (long long d = 5; d <= n; d *= 5) {
            zeros += n / (d * 2);
        }
        cout << zeros << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
module Main where

-- import Debug.Trace
import Data.List
import qualified Data.Sequence as S
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
import Data.Maybe
import qualified Data.Map as M
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad
import Text.Printf

data Tree a = Nil | Node a (Tree a) (Tree a) deriving (Show)
data Command = Print | Insert Int deriving (Show)
data Order = Preorder | Inorder deriving (Eq, Show)

sInsert = B.pack "insert"
sPrint  = B.pack "print"

solve :: [Command] -> [([Int], [Int])]
solve = iter Nil where
    iter :: Tree Int-> [Command] -> [([Int], [Int])]
    iter _ [] = []
    iter rt (c:cs) = case c of
        Print    -> (preorder rt, inorder rt):(iter rt cs)
        Insert x -> iter (insert x rt) cs

    insert x = iter where
        iter (Node y l r)             
                | x < y     = Node y (iter l) r
                | otherwise = Node y l (iter r) 
        iter Nil = Node x Nil Nil 

    preorder = toList Preorder
    inorder  = toList Inorder
    toList ord = iter where
        iter Nil = []
        iter (Node id l r)
            | ord == Preorder = id:(iter l) ++ iter r
            | ord == Inorder  = (iter l) ++ id:iter r
            
readIntLn:: IO Int
readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

readCommand:: IO Command
readCommand = do
    l <- B.words <$> B.getLine
    return $ case l of
        [sInsert, n] -> Insert $ (fst . fromJust) (B.readInt n)
        [sPrint]     -> Print

printl:: [Int] -> IO ()
printl [] = putStrLn ""
printl (x:xs) = do
    putStr $ ' ':(show x)
    printl xs

print':: [([Int], [Int])] -> IO ()
print' [] = return ()
print' ((x, y):xs) = do
    printl y
    printl x
    print' xs

main :: IO() 
main = do
    n <- readIntLn
    l <- replicateM n readCommand
    print' $ solve l



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

int n, m, t, p, mm, nn;
int memo[100][100];
int d, c, x, y;

int main() {
  int i, j, a, ans;
  while(1) {
    cin >> n >> m >> t >> p;
    if(n + m + t + p == 0) break;
    nn = n;
    mm = m;
    ans = 0;
    for(i = 0; i < 100; ++i)
      for(j = 0; j < 100; ++j) memo[i][j] = 0;
    for(i = 0; i < m; i++)
      for(j = 0; j < n; j++) memo[i][j] = 1;
    for(a = 0; a < t; a++) {
      cin >> d >> c;
      if(d == 1) {
        for(i = 0; i < mm; i++)
          for(j = 0; j < c / 2; j++) { swap(memo[i][j], memo[i][c - j - 1]); }
        if(c <= nn / 2)
          nn -= c;
        else
          nn = c;
        for(i = 0; i < mm; i++)
          for(j = 0; j < nn; j++) {
            if(j < c)
              memo[i][j] += memo[i][j + c];
            else
              memo[i][j] = memo[i][j + c];
            memo[i][j + c] = 0;
          }
      }
      else {
        for(i = 0; i < c / 2; i++)
          for(j = 0; j < nn; j++) { swap(memo[i][j], memo[c - i - 1][j]); }
        if(c <= mm / 2)
          mm -= c;
        else
          mm = c;
        for(i = 0; i < mm; i++)
          for(j = 0; j < nn; j++) {
            if(i < c)
              memo[i][j] += memo[i + c][j];
            else
              memo[i][j] = memo[i + c][j];
            memo[i + c][j] = 0;
          }
      }
      /*for(i = 0; i < m; i++)
        for(j = 0; j < n; j++)
          if(i >= mm || j >= nn) memo[i][j] = 0;*/
      /*for(i = 0; i < m; i++) {
        for(j = 0; j < n; j++) cout << memo[i][j] << " ";
        cout << endl;
      }
      cout << endl;*/
      // cout << n << " " << nn << " " << m << " " << mm << endl;
    }
    for(a = 0; a < p; a++) {
      cin >> x >> y;
      cout << memo[y][x] << endl;
      // if(memo[y][x] == 96)
      // cout << n << " " << m << " " << t << " " << p << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3052
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func isPrime(a int) bool {
	for j := 2; j*j <= a; j++ {
		if a%j == 0 {
			return false
		}
	}
	return true
}

func main() {
	a, b, m := nextInt(), nextInt(), nextInt()
	minA, minB := 1<<63-1, 1<<63-1
	as, bs := make([]int, a), make([]int, b)

	for i := 0; i < a; i++ {
		as[i] = nextInt()
		if as[i] < minA {
			minA = as[i]
		}
	}
	for i := 0; i < b; i++ {
		bs[i] = nextInt()
		if bs[i] < minB {
			minB = bs[i]
		}
	}

	res := minA + minB
	for i := 0; i < m; i++ {
		x, y, c := nextInt(), nextInt(), nextInt()
		if as[x-1]+bs[y-1]-c < res {
			res = as[x-1] + bs[y-1] - c
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 5504
#include <cstdio>
#include <cctype>
int N,A[200005],F[200005];
long long Ans;
inline void read(int &Res) {
	char ch=getchar();
	for (Res=0; !isdigit(ch); 
	ch=getchar());
	for (; isdigit(ch); ch=getchar()) 
	Res=(Res<<3)+(Res<<1)+ch-48;
}
int main() {
	read(N);
	for(int i=1; i<=N; ++i)read(A[i]);
	if(A[1]) return puts("-1"),0;
	for(int i=1; i<N; ++i)
	if(A[i+1]-A[i]>1)
	return puts("-1"),0;
	for(int i=2; i<=N; ++i)
	if(A[i]-A[i-1]==1)F[i]=F[i-1]+1,F[i-1]=0;
		else F[i]=A[i];
	for(int i=1; i<=N; ++i)
	Ans+=F[i];
	printf("%lld\n",Ans);
	return 0;
}

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

int n, k, arr[200010];
int cnt = 0;
map <int, int> m;

signed main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    if (m[arr[i]] == 0) {
      cnt += 1;
    }
    m[arr[i]] += 1;
  }
  vector <int> vec;
  for (auto x : m) {
    //rev[x.second] = x.first;
    vec.push_back(x.second);
  }
  sort(vec.begin(), vec.end());
  int res = 0;
  for (int i = 0; i < vec.size(); i++) {
    if (cnt <= k) break;
    res += vec[i];
    cnt -= 1;
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll LINF = 1ll << 55;
const ll MOD = 1e9 + 7;
const ll MAXN = 400 + 5;
const ll MAXK = 1e5 + 10;

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

template<typename T>
ostream& operator<< (ostream& out, vector<T>& vec) {
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        out << *it << " ";
    }
    return out;
}

template<typename T>
istream& operator>> (istream& in, vector<T>& vec) {
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        in >> *it;
    }
    return in;
}

int main() {
    ll N, M, X;
    cin >> N >> M >> X;
    ll a;
    vll nums(N + 1);
    for (int i = 0; i < M; ++i) {
        cin >> a;
        nums[a] = 1;
    }
    ll ans = INF;
    ll cur = 0;
    for (int i = X + 1; i < N; ++i) {
        if (nums[i]) {
            ++cur;
        }
    }
    ans = min(ans, cur);
    cur = 0;
    for (int i = 1; i < X; ++i) {
        if (nums[i]) {
            ++cur;
        }
    }
    ans = min(ans, cur);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    ost;
#define rep(i,l,r)   for (int i = (l); i < (r); i++)
#define here cout << " Hey!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
template <typename T>
void etch(T V) {
	for (auto x : V)	cout << x << ' ' ;
	cout << '\n';
}
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld EPS = 1e-12;
const ld PI = 3.141592653589793116;
int modular_exp(int base,int exp, int mod)
{
    int ans =1;
    while(exp)
    {
        if(exp%2)   ans = ans%mod*base%mod;
        base = (base%mod*base%mod)%mod;
        exp/=2;
        ans%=mod;
    }
    return ans;
}
int32_t main()
{
	SYNC
	vi dp(N);
	dp[0] = 0;
	for (int i = 1; i < N; i++) {
		dp[i] = dp[(i)%(__builtin_popcountll(i))] + 1;
	}
	int n; cin >> n;
	string s; cin >> s;
	int cnt_bits = 0, val = 0;
	for (auto it : s) 
		cnt_bits += (it == '1');
	debug(cnt_bits);
	int val_1 = 0, val_0 = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '0')	continue;
		if (cnt_bits > 1) {
			val_0 += modular_exp(2,n - i - 1, cnt_bits-1);
			val_0 %= (cnt_bits-1);
		}
		val_1 += modular_exp(2, n - i - 1, cnt_bits+1);
		val_1 %= (cnt_bits+1);
	}
	debug(val_1);
	for (int i = 0; i < n; i++) {
		if(s[i] == '1') {
			if (cnt_bits == 1) {
				cout << "0\n";
				continue;
			}
			int nv = val_0;
			nv -= modular_exp(2, n - i - 1, cnt_bits-1);
			nv %= (cnt_bits-1);
			if (nv < 0)
				nv += (cnt_bits-1);
			cout << dp[nv] + 1 << '\n';
		}else {
			int nv = val_1;
			nv += modular_exp(2,n - i - 1, cnt_bits+1);
			nv %= (cnt_bits+1);
			cout << dp[nv] + 1 << '\n';
		}
	}
	debug(dp[11]);
	return 0;
}

Measured memory_bytes: 5164
import java.io.*
import java.util.*
import java.lang.Math.*


fun main() {
    val N = rd.readInt()
    val A = rd.readLongArray().sorted().reversed()

    val B = ArrayList<Long>()
    B.add(A[0])

    for (i in 1 until N) {
        B.add(A[i])
        B.add(A[i])
    }

    var ans = B[0]

    for (i in 1 until N-1) {
        ans += B[i]
    }

    println(ans)
}


//val rd = debug.Reader("abc", "173", "d", "sample-1")
val rd = Reader()
fun main(args: Array<String>) {
    Thread(null, MainThread(), "mainThread", 128 * 1024 * 1024).start()
}


const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
class MainThread : Runnable {
    override fun run() { main() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 80608
n = gets.to_i
hash = {}
n.times do
  s,t = gets.split(' ')
  hash[s] = t.to_i
end
x = gets.chomp
sum = 0
check = 0
hash.each do |k,v|
  if k == x || check == 1
    check = 1
    if k != x
      sum += v
    end
  end
end
puts sum

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main(int argc, char const *argv[])
{
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll m = min({a, b, c, d, e});
    cout << (4 + (n + m - 1) / m) << endl;

    return 0;
}


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

int n;
int c[1002];
vector<int> t[1002], cost[1002];

int solve(int id, int pre) {
  int res = 0;
  for (int i = 0; i < t[id].size(); i++) {
    int to = t[id][i];
    if (to == pre) continue;
    int cut_cost = cost[id][i];

    if (c[to] > 0) {
      res += cut_cost;
    } else {
      res += min(solve(to, id), cut_cost);
    }
  }
  return res;
}

int main() {
  while (cin >> n) {
    for (int i = 1; i < n; i++) {
      cin >> c[i];
    }
    for (int i = 0; i < n; i++) {
      t[i].clear();
      cost[i].clear();
    }
    for (int i = 0; i < n - 1; i++) {
      int u, v, p;
      cin >> u >> v >> p;
      t[u].push_back(v);
      cost[u].push_back(p);
      t[v].push_back(u);
      cost[v].push_back(p);
    }
    cout << solve(0, -1) << endl;
  }
}

Measured memory_bytes: 1332
#include<iostream>
#define inf 100000007
using namespace std;

char kiban[20][15];
int X[8]={0,1,0,-1,1,-1,-1,1};
int Y[8]={-1,0,1,0,1,-1,1,-1};
int ans=inf;

bool in(int h,int w)
{
  if(h<0 || w<0 || 15<=w || 21<=h)return false;
  return true;
}

void move(int h,int w,int sum)
{
  bool check[8]={};
  if(18<=h){
    ans=min(ans,sum);
    return;
    }
  for(int k=0;k<8;k++){
    if(kiban[h+Y[k]][w+X[k]]=='.')continue;
    for(int i=1;i<40;i++){
      int a=h+Y[k]*i,b=w+X[k]*i;
      if(a==19){
	ans=min(ans,sum+1);
	continue;
      }
      if(!in(a,b))break;
      if(kiban[a][b]=='.'){
	check[k]=true;
	break;
      }
    }
  }
  for(int k=0;k<8;k++){
    if(!check[k])continue;
    int a=h,b=w;
    for(int i=1;i<20;i++){
      a+=Y[k];
      b+=X[k];
      if(kiban[a][b]=='.')break;
      kiban[a][b]='.';
    }
    move(a,b,sum+1);
    int H=h,W=w;
    for(int i=1;i<20;i++){
      H+=Y[k];
      W+=X[k];
      if(H==a && W==b)break;
      kiban[H][W]='x';
    }
  }
}

int main()
{
  int h,w;
  for(int i=0;i<19;i++){
    for(int j=0;j<15;j++){
      cin>>kiban[i][j];
      if(kiban[i][j]=='O'){
	h=i;
	w=j;
	kiban[i][j]='.';
      }
    }
  }
  for(int i=0;i<15;i++)kiban[19][i]='.';
  move(h,w,0);
  if(ans==inf)cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1144
x,y = map(int,input().split())
ans = 0
if x>=0 and y>=0:
	ans = abs(y-x) if x<=y else 2+abs(y-x)
	if x!=0 and y==0:
		ans -= 1
elif x>=0 and y<0:
	ans = 1+abs(y+x)
elif x<0 and y>=0:
	ans = 1+abs(y+x) if y!=0 else abs(y+x)
else:
	ans = abs(y-x) if x<=y else 2+abs(y-x)
print(ans)

Measured memory_bytes: 3064