akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

int h, w;
vector<vector<char>> s;

int c[800][800];
int x[800][800], y[800][800];

void solve() {
	cin >> h >> w;
    s.assign(h, vector<char>(w));
    rep(i, 800) {
        rep(j, 800) {
            c[i][j] = x[i][j] = y[i][j] = 0;
        }
    }
    rep(i, h) {
        rep(j, w) {
            cin >> s[i][j];
            if(s[i][j] == '#') c[i + j + 20][i - j + 350] ++;
        }
    }
    rep(i, 700) {
        rep(j, 700) {
            y[i][j + 1] = y[i][j] + c[i][j];
        }
    }
    rep(i, 700) {
        rep(j, 700) {
            x[i + 1][j] = x[i][j] + c[i][j];
        }
    }
    int ans = 0;
    rep(i, 700) {
        for(int j = 1; j < 700; ++ j) {
            for(int k = j + 1; k < 700; ++ k) {
                if(!c[j][i] || !c[k][i]) continue;
                int d = k - j;
                if(i - d >= 0) ans += x[k + 1][i - d] - x[j][i - d];
                if(i + d < 700) ans += x[k + 1][i + d] - x[j][i + d];
            }
        }
    }
    rep(i, 700) {
        for(int j = 1; j < 700; ++ j) {
            for(int k = j + 1; k < 700; ++ k) {
                if(!c[i][j] || !c[i][k]) continue;
                int d = k - j;
                if(i - d >= 0) ans += y[i - d][k] - y[i - d][j + 1];
                if(i + d < 700) ans += y[i + d][k] - y[i + d][j + 1];
            }
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 15488
//
// Created by yamunaku on 2019/08/19.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    string s,t;
    cin >> s >> t;
    int n=s.size();
    int m=t.size();
    mti nx(n, vi(26,-1));
    vi a(26,-1);
    per(i,n){
        a[s[i]-'a']=n+i;
    }
    per(i,n){
        rep(j,26){
            nx[i][j]=a[j]-i;
        }
        a[s[i]-'a']=i;
    }
    ll now=n-1;
    rep(i,m){
        if(nx[now%n][t[i]-'a']<0){
            cout << -1 << endl;
            return 0;
        }
        now+=nx[now%n][t[i]-'a'];
    }
    cout << now-(n-1) << endl;
    return 0;
}


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

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

  double ans = 0;
  for (int i = 1; i <= n; i++) {
    double tmp;
    int sum = i;
    tmp = 1.0 / n;
    while (sum < k) {
      sum = sum * 2;
      tmp = tmp * 0.5;
    }
    ans += tmp;
  }
  printf("%0.10f\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, t[100000], x[100000], y[100000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}

	int posx = 0, posy = 0, time = 0;
	for (int i = 0; i < n; i++) {
		if(t[i]-time < abs(x[i]-posx) + abs(y[i]-posy)){
			cout << "No" << endl;
			return 0;
		}
		elif(t[i]-time > abs(x[i]-posx) + abs(y[i]-posy)){
			if((t[i]-time-(abs(x[i]-posx)+abs(y[i]-posy))) % 2 != 0){
				cout << "No" << endl;
				return 0;
			}
		}
		posx = x[i], posy = y[i], time = t[i];
	}

	cout << "Yes" << endl;

	return 0;
}

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

const int MN = 101234;
int mx = 0;
int dp[MN], col[MN];
vector <int> adj[MN];

int LogDo(int x) {
	int ans = -1;
	for (int i = 0; i < 30; i++)
		if (x >> i & 1)
			ans = i;
	return ans;
}

void dfs(int v = 0, int p = 0) {
	int ans = 0, pre = 0;
	for (int u: adj[v]) {
		if (u == p) 
			continue;
		dfs(u, v);
		int msk = (dp[u] >> col[u] | 1) << col[u];
		ans = max(ans, LogDo(msk & dp[v] & -1) + 1);
		dp[v] |= msk;
		while (dp[v] >> ans & 1)
			ans++;
	}
	col[v] = ans;
	mx = max(mx, ans);
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	dfs();
//	for (int i = 0; i < n; i++)
//		cerr << dp[i] << '&' << col[i] << endl;
	cout << mx;
}


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

int main() {
  int A,B,count = 0;
  cin >> A >> B;
  
  for(int i=A; i<=B; i++){
    
    int s = i%10, t = i/10000 % 10;
    int u = i/10%10, v = i/1000 % 10;
    if(s == t&&u == v)
    	count++;
  
  }
  cout << count << endl;
}




Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
 
public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	static int n;
	public static void main(String[] __){
		
		n=s.nextInt();
		long a[]=new long[n];
		for(int i=0;i<n;i++) a[i]=s.nextInt();
		if(a[0]!=0) {
			long r1=solve(Arrays.copyOf(a,a.length));
			long r2=Math.abs(a[0])+1;
			a[0]=-a[0]/Math.abs(a[0]);
			r2+=solve(Arrays.copyOf(a,a.length));
			//System.out.println(r1);
			//System.out.println(r2);
			System.out.println(Math.min(r1,r2));
		}else {
			a[0]=1;
			long r1=1+solve(Arrays.copyOf(a,a.length));
			a[0]=-1;
			long r2=1+solve(Arrays.copyOf(a,a.length));
			//System.out.println(r1);
			//System.out.println(r2);
			System.out.println(Math.min(r1,r2));
		}
	}
	private static final long solve(long[]a) {
		long sum[]=new long[n];
		sum[0]=a[0];
		long res=0;
		for(int i=1;i<n;i++) {
			sum[i]=a[i]+sum[i-1];
			if(sum[i-1]>0) {
				long t=-sum[i-1]-1;
				if(a[i]>t){
					res+=a[i]-t;
					a[i]=t;
				}
			}else {
				long t=-sum[i-1]+1;
				if(a[i]<t){
					res+=t-a[i];
					a[i]=t;
				}
			}
			sum[i]=a[i]+sum[i-1];
		}
		
		//System.out.println(Arrays.toString(a));
		return res;
	}
}

Measured memory_bytes: 60892
#include<iostream>
#include<vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int i;
  for(i=0;i<N;i++)cin >> A[i];
  vector<int> cnt(N,0);
  for(i=0;i<N;i++)cnt[A[i]-1]++;
  long long ans = 0;
  for(i=0;i<N;i++)ans += (long long)cnt[i]*(cnt[i]-1)/2;
  for(i=0;i<N;i++)cout << ans-cnt[A[i]-1]+1 << endl;
}

Measured memory_bytes: 4096
N = int(input())
T, A = (map(int, input().split()))
H = list(map(int, input().split()))
m = 10 ** 100
num = 0
for i in range(len(H)):
	H[i] = T - H[i] * 0.006
	if m > abs(A - H[i]):
		m = abs(A - H[i])
		num = i + 1
	# m = min(m, abs(A - H[i]))
print(num)

Measured memory_bytes: 38512
// ConsoleApplication22.cpp: 定义控制台应用程序的入口点。
//

#include<stdio.h>


int main()
{
	int a, b, c;
	int x, y, z;
	int t=0;

	scanf("%d%d%d", &a, &b, &c);

	if (a > b)
	{
		if (b > c)
		{
			x = a;
			y = b;
            z = c;
		}	
		else if (a > c)
		{
			x = a;
			y = c;
			z = b;
		}
		else
		{
			x = c;
			y = a;
			z = b;
		}
	}
	else if(c<a)
	{
		x = b;
		y = a;
		z = c;
	}
	else if(b>c)
	{
		x = b;
		y = c;
		z = a;
	}
	else
	{
		x = c;
		y = b;
		z = a;
	}

	if ((y - z) % 2 == 0)
	{
		t = (2 * x - y - z) / 2;
	}
	else
	{
		t = (2 * (x + 1) - y - z - 1) / 2 + 1;
	}
	printf("%d", t);
    return 0;
}



Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 300;

int n, m, a[maxn][maxn], cur[maxn];
bool ban[maxn];
pair<int, int> item[maxn];
int cnt[maxn], ans;

bool Calc(void) {
  memset(cnt, 0, sizeof cnt);
  for (int i = 0; i < n; ++i) {
    while (ban[a[i][cur[i]]]) {
      ++cur[i];
    }
    ++cnt[a[i][cur[i]]];
  }
  int cnt_item = 0;
  for (int i = 0; i < m; ++i) {
    if (!ban[i]) {
      item[cnt_item++] = {-cnt[i], i};
    }
  }
  sort(item, item + cnt_item);
  ans = min(ans, -item[0].first);
  for (int i = 0; item[i].first == item[0].first; ++i) {
    ban[item[i].second] = true;
    if (--cnt_item == 0) {
      return false;
    }
  }
  return true;
}

int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", a[i] + j);
      --a[i][j];
    }
  }
  ans = 1e9;
  while (Calc()) ;
  printf("%d\n", ans);
  return 0;
}


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

int main(){
    int64_t n,max,min;
    min = 10000000000;
    max = -100000000000;
    cin  >> n;
    int R[n];
    for (int i = 0; i < n; i++) cin >> R[i];
    for(int i = 0; i < n;i++){
        if ( max < R[i]-min){
            max = R[i] - min;
        }
        if( min > R[i]) min = R[i];
    }
    cout << max << endl;
}


Measured memory_bytes: 3872
#include<stdio.h>
int main(void)
{
double v,t,y,n;
int N;
while(~scanf("%lf",&v))
{
t=v/9.8;
y=4.9*t*t;
n=(y+5)/5;
if(n-(int)n>0)
{
N=(int)n+1;
}
else
{
N=(int)n;
}

printf("%d\n",N);
}
return 0;
}

Measured memory_bytes: 628
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        String s 	   = sc.next();
        for(int i = 0 ; i < s.length()-1 ; i++){
        	if(s.charAt(i) == s.charAt(i+1)){
            	System.out.println("Bad");
                break;
            }
            if(i == s.length()-2){
            	System.out.println("Good");
            }
        }
    }
}



Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) (a)>0?(a):-(a)
#define llong long long

int gcd3(int,int,int);
int gcd(int,int);

int main(){
	int N; scanf("%d",&N);
	N++;
	llong cnt=0;
	rep(i,1,N){ rep(j,1,N){ rep(k,1,N){
		cnt += gcd3(i,j,k);
	}}}
	printf("%lld",cnt);
	return 0;
}

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

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


Measured memory_bytes: 1732
// https://atcoder.jp/contests/abc147/tasks/abc147_c
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N;
    scanf("%d", &N);
    vector<int> A(N);
    vector<vector<int>> x(N), y(N);
    REP(i, N)
    {
        scanf("%d", &A[i]);
        if (0 == A[i]) continue;
        x[i].resize(A[i]), y[i].resize(A[i]);
        REP(j, A[i])
        {
            scanf("%d %d", &x[i][j], &y[i][j]);
            --x[i][j];
        }
    }
    int ans = 0;
    vector<int> res(N, 0); // 1 : 正直者, 0:不親切
    ll blim = 1LL << N;
    // i + 1 桁目のビットが立っている場合 i 番目の人が正直者であるとして、bit全探索を行う
    for (ll b = 0; b < blim; ++b)
    {
        // b に基づいて res に値を格納する
        REP(i, N)
        {
            int bflag  = (b >> i) & 1;
            if (bflag == 0) res[i] = 0;
            else
            {
                res[i] = 1;
            }
        }

        // 正直者と仮定した人(res[i] == 1)の証言をチェック
        bool ok = true;
        REP(i, N)
        {
            if (res[i] == 0) continue;
            REP(j, A[i])
            {
                if (res[x[i][j]] != y[i][j])
                {
                    ok = false;
                    break;
                }
            }
        }
        if (ok)
        {
            int cnt = 0;
            REP(i, N)
            {
                if (res[i] == 1)
                    ++cnt;
            }
            ans = max(ans, cnt);
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3792
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y

n = ini()
a = inl()
a = sorted(a,reverse = True)
c = 1
j = 0
ans = 0
for i in range(1,n):
        ans += a[j]
        c += 1
        if c == 2:
                c = 0
                j += 1
print(ans)


Measured memory_bytes: 105240
import math
t = int(input())
if t%2==0 or t%5==0:
    print(-1)
else:
    i=1
    s=7
    while 1:
 
        if s%t==0:
            print(i)
            break
 
        else:
            i += 1
            s = (s * 10 + 7) % t
            continue

Measured memory_bytes: 9176
from math import gcd
A, B, C, D = map(int, input().split())

def lcm(c, d):
  return c * d // gcd(c, d)

def divc(x):
  """ [A, B]にxの倍数がいくつあるかを返す"""
  b = B // x
  r = B % x
  a = A // x
  s = A % x
  res = b - a
  if s == 0:
    res += 1
  return res

ans = B - A + 1 - (divc(C) + divc(D) - divc(lcm(C, D)))

print(ans)

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

        long long n,k,s=0,i;
        cin>>n;
        long long a[1000001]={0},v[n];
        for(i=0;i<n;i++){
            cin>>v[i];s=s+v[i];a[v[i]]++;
        }cin>>k;
        for(i=0;i<k;i++){
            long long b,c;
            cin>>b>>c;
        s=s+a[b]*(c-b);
        cout<<s<<endl;
        a[c]=a[c]+a[b];
        a[b]=0;
        }
        
    return 0;
}


Measured memory_bytes: 12148
fun main(args: Array<String>?): Unit {
    val (m, _) = readLine()!!.trim().split(' ').map(String::toInt)
    val chocolate = Array(m){ readLine()!!.trim().split(' ').map(String::toInt).toIntArray()}
    chocolate.forEach {
        it[0] = (it.first() + 1) % 2
        it[it.lastIndex] = (it.last() + 1) % 2
    }
    chocolate[0].indices.forEach { chocolate[0][it] = (chocolate[0][it] + 1) % 2 }
    println(
            chocolate.sumBy { if (it.any{it == 0}) it.count { it == 1 } + 1 else it.size - 1 }
    )
}


Measured memory_bytes: 36888
/*
ID: Aman Raj
LANG: C++
TASK: subset
*/
#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long int ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
//hr
using namespace std;
using namespace __gnu_pbds;
//hy
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;
  //# define mod 1e9+7
   ll gcd(ll a,ll b)
   {
       if(a==0)return b;
       return gcd(b%a,a);
   }
//kj
int main()
{
    ll n,d; cin>>n>>d;

     ll a=n/(2*d+1);if(n%(2*d+1)!=0)a++;
      cout<<a;

      return 0;
}


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

int main () {
  int n, k;
  string s;
  cin >> n >> k;
  cin >> s;
  if(s.at(k-1) =='A')
    s.at(k-1) = 'a';
  else if(s.at(k-1) =='B')
    s.at(k-1) = 'b';
  else if(s.at(k-1) =='C')
    s.at(k-1) = 'c';
  cout << s;
}


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

int dp[2][2019];

int main()
{
	string s;
	cin >> s;
	//s.insert(s.begin(),'0');
	int n = s.size();

	int ans = 0;
	for(int i = 0;i<n;++i)
	{
		int x = s[i]-'0';
		dp[1][x]++;
		for(int j = 0;j<2019;j++)
		{
			dp[1][(j*10+x)%2019]+= dp[0][j];
		}
		ans += dp[1][0];
		for(int j = 0;j<2019;j++)
		{
			dp[0][j]=dp[1][j];
			dp[1][j]=0;
		}
	}
	
	cout<<ans<<endl;
}

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

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int a = arr[0];
    int b = arr[1];
    int ans = 0;
    for (int i = a; i <= b; i++) {
      string s = i.ToString();
      if (s[0] == s[4] && s[1] == s[3]) ans++;
    }
    Console.WriteLine(ans);
  }
}

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

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

    sort(bars.begin(), bars.end(), greater<int>());

    int acc = 0;
    for (int i=0;i<n-2;i++){
        for (int j=i+1;j<n-1;j++){
            if (bars[i] > 2 * bars[j]){
                continue;
            } else {
                for (int k=j+1;k<n;k++){
                    if (bars[i] < bars[j] + bars[k]){
                        acc++;
                    }
                }
            }
        }
    }
    cout << acc << endl;
    return 0;
    
}

Measured memory_bytes: 256
from heapq import *
N,M,S,T=map(int,input().split())
S,T=S-1,T-1
u,v,a,b=0,0,0,0
Gy=[[] for i in range(N)]
Gs=[[] for i in range(N)]
for i in range(M):
  u,v,a,b=map(int,input().split())
  u,v=u-1,v-1
  Gy[v].append((u,a))
  Gy[u].append((v,a))
  Gs[v].append((u,b))
  Gs[u].append((v,b))
Dy=[0]*N
Ds=[0]*N
INF=10**15
def ijk(s,D,G):
  global INF
  for i in range(len(D)):
    D[i]=INF
  D[s]=0
  Q=[]
  heapify(Q)
  heappush(Q,(0,s))
  p,v,e=0,0,0
  while len(Q):
    p=heappop(Q)
    v=p[1]
    if D[v]<p[0]:
      continue
    for i in range(len(G[v])):
      e=G[v][i]
      if D[e[0]]>D[v]+e[1]:
        D[e[0]]=D[v]+e[1]
        heappush(Q,(D[e[0]],e[0]))

ijk(S,Dy,Gy)
ijk(T,Ds,Gs)
Q=[Dy[i]+Ds[i] for i in range(N)]
P=[INF]
for i in range(N):
  P.append(min(P[i],Q[-i-1]))
for i in range(N):
  print(INF-P[-i-1])

Measured memory_bytes: 130120
#include <iostream>
using namespace std;
struct Card
{
	char suit;
	char value;
};

int N;
Card t,t1;
void print(struct Card A[], int N);
void bubble(struct Card A[], int N);
void selection(struct Card A[], int N);
bool isStable(struct Card A[], struct Card B[], int N);
int main()
{
	Card A[100], B[100];
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i].suit >> A[i].value;
	}
	for (int i = 0; i < N; i++)
		B[i] = A[i];
	bubble(A, N);
	selection(B, N);
	print(A, N);
	cout << "Stable" << endl;
	print(B, N);
	if (isStable(A, B, N))
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}
	return 0;
}
void print(struct Card A[], int N)
{
	for (int i = 0; i < N; i++)
	{
		cout << A[i].suit << A[i].value;
		if (i != N - 1)cout << " ";
	}
	cout << endl;
}
void bubble(struct Card A[], int N)
{
	for (int i = 0; i < N; i++)
	{
		for (int j = N - 1; j > i;j--)
			if (A[j].value < A[j - 1].value)
			{
			//	char temp = 0;
				t = A[j];
				A[j] = A[j - 1];
				A[j - 1]= t;
			}
	}
}
void selection(struct Card B[], int N)
{
	
	for (int i = 0; i < N; i++)
	{
		int minj = i;
		for (int j = i; j < N; j++)
		{
			if (B[j].value < B[minj].value)
			{
				minj = j;
			}
			//char temp;
	
		}
		t1 = B[i];
		B[i] = B[minj];
		B[minj] = t1;

	}
	//print(B, N);
}
bool isStable(struct Card A[], struct Card B[],int N)
{
	for (int i = 0; i < N; i++)
	{
		if (A[i].suit != B[i].suit) return false;
	}
	return true;

}

Measured memory_bytes: 3096
#include<stdio.h>

int n,t,finder[500],d[500],f[500],P[500][500];

void explorer(int u){
  int v;

  // 0 is yet. 1 is judging. 2 is alleady.

  finder[u]=1; //探索開始
  t++;
  d[u]=t;
  for(v=1;v<=n;v++){
    if(P[u][v]==1){
      if(finder[v]==0) explorer(v);
    }
  }
  t++;
  f[u]=t;
  finder[u]=2; //探索終了
}

int main(){

  //int P[500][500];
  int i,j,u,k,v;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      P[u][v]=1;
    }
  }

  for(i=0;i<n;i++){
    finder[i]=0;
  }

  for(u=1;u<=n;u++){
    if(finder[u] == 0) explorer(u);
  }

  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  
  /*
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      printf("%d",P[i][j]);
      if(j!=n) printf(" ");
    }
    printf("\n");
    }*/

  
  
}



Measured memory_bytes: 2088
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

int main()
{
    ll N,K,P,Q=0;
    cin>>N>>K;
    P=N/K;
    if(K%2==0){
        Q=N/(K/2)-P;
    }
    cout<<P*P*P+Q*Q*Q<<endl;


    return 0;
}

Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;
const MOD: usize = 1_000_000_007;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let n: usize = itr.next().unwrap().parse().unwrap();
    let s: Vec<char> = itr.next().unwrap().chars().collect();
    let _: Vec<char> = itr.next().unwrap().chars().collect();

    let mut num = Vec::new();
    let mut i = 0;
    while i < n {
        if i + 1 < n && s[i] == s[i + 1] {
            num.push(2);
            i += 1;
        } else {
            num.push(1);
        }
        i += 1;
    }

    // 最初2: 6
    // 最初1: 3
    let mut ans = if num[0] == 1 { 3 } else { 6 };
    for i in 1..num.len() {
        if num[i - 1] == 1 {
            ans = ans * 2 % MOD;
        } else {
            if num[i] == 2 {
                ans = ans * 3 % MOD;
            }
        }
    }
    println!("{}", ans);
}


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

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

    int idea = 0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int x = 0;x<=c;x++){
                if((500*i+100*j+50*x)==sum){
                   //cout << i << ' ' << j << ' ' << x << endl;
                    idea++;
                }
            }
        }
    }

    cout << idea << endl;
    return 0;
}


Measured memory_bytes: 256
/*
Character Drawing Adapted from FAKEUPDATE.NET
		   _    _____         _
		   \`,""   ,'7"r-..__/ \
		  ,'\ `, ,',','    _/   \
		 /   \, 7 / /     (   \ |
		J     \/ j  L______\  / |
		L   __JF"""/""\"\_,    /
		L,-"| O|  f O |  L_  _/
		F   \_ /  \__/   `-  j|
			.-'    `"""    ,' |          _..====.._
			\__/         r"_  A        ,' _..---.._`,
			 `-.______,,-L// / \  ___,' ,'_..:::.. `,`,
					  j   / / / 7"    `-<""=:'  '':. \ \
					 /   <,' /  F  . i , \   `,    :T W I
					 |    \,'  /    >X<  |     \   :| | L
					 |     `._/    ' ! ` |      I  :| |  G
					  \           \     /       |  :H T  |
					 __>-.__   __,-\   |        |  S P   |
					/     /|   | \  \  \_       | 'A R   |
				   /   __/ |   |  L  L   \      K./ /    L
				  /   |    |   4  I  I    |    E./ /   ,'
				 J    \    I    L F  I    |    // / _,'
		_________|     |   F    |J   F    |   //_/-'
		\   __   |    /   J     |/  J     |  /="
		\\  \_\  \__,' \  F     |   F     |
		\\\_____________\/      F__/      F
		 \\| 计算机编程 |_____/  (______/
		  \/从入门到入土/
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
#include <functional>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	string sOpr;
	int i, iAltitude = 0, iMax = 0;
	cin >> sOpr >> sOpr;
	for (i = 0; i < sOpr.length(); ++i){
		if (sOpr[i] == 'I')
			++iAltitude;
		else
			--iAltitude;
		iMax = max(iAltitude, iMax);
	}
	cout << iMax << endl;
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    int N; cin >> N;
    map<string, int> m;
    string s;
    REP(i, N) {
        cin >> s;
        m[s] += 1;
    }
    int M; cin >> M;
    REP(i, M){
        cin >> s;
        if(m.count(s)) m[s] -= 1;
    }
    int mx = 0;
    for(auto p: m){
        mx = max(mx, p.second);     
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int N = 0;
	int a[200];
	int i = 0;
	int count = 0;

	scanf("%d\n", &N);
	for (i=0; i < N; i++) {
		scanf("%d", &a[i]);
	}

	for (i=0; i <= N; i = i + 2) {
		if (((i + 1) % 2 != 0) & (a[i] % 2 != 0)) {
			count++;
		}
	}
	
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 1736
n=int(input())
a=list(map(int,input().split()))
amax=max(a)
amin=min(a)
ans=1000000000000
for i in range(amin,amax+1):
  t=0
  for j in range(n):
    t=t+(a[j]-i)**2
  ans=min(t,ans)
print(ans)

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

const int MOD = 1e9+7;

int main() {
    int n;
    string s1, s2;
    cin >> n >> s1 >> s2;

    long long ans = 0;
    for(int i = 0; i < n; i++) {
        if(s1[i] == s2[i]) {
            if (i == 0) {
                ans += 3;
            } else if(s1[i-1] == s2[i-1]) {
                ans = ans * 2 % MOD;
            } else {
                ans = ans % MOD;
            }
        } else {
            if(i == 0){
                ans += 6;
            } else if(s1[i-1] == s2[i-1]) {
                ans = ans * 2 % MOD;
            } else {
                ans = ans * 3 % MOD;
            }
            i++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
fn main() {
    let n = read::<u32>();
    println!("{}", n * 800 - (n / 15) * 200);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }

vector<bool> flag;
void init(int x){ // x以下の素数テーブルpriを生成 O(n)
    for(int i = 2; i <= x; i++){
        if(flag[i]) continue;
        for(int j = i+i; j <= x; j+=i) flag[j] = true;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    flag.resize(55555+10,false);
    init(55555+10);
    int cnt=0;
    for(int i=11;i<=55555+10;i+=5){
        if(!flag[i]){
            cout<<i;
            cnt++;
            if(cnt==n) break;
            cout<<" ";
        }
    }
    cout<<endl;
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

signed main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int ans = 0;
	for (int i = 2; i < n ; i++) {
		for (int j = 1; j < i; j++) {
			int mn = a[i] - a[j] + 1;
			int ind = lower_bound(a, a + n, mn) - a;
			if (ind < j) ans += j - ind;
		}
	}
	cout << ans << "\n";
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,k,n) for(int (i)=(k);(i)<(n);(i)++)
using namespace std;
typedef long long int ll;

void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i+1;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}



int main() {
    ll K,N;
    cin >> K >> N;
    int A[N];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A,A+N);
    ll min = 11451489319;
    ll sum = 0;
    for(int i=0;i<N;i++){
        ll plus;
        if(i==N-1){
            plus = A[N-1] -A[0];
        }else{
            plus =  K - (A[i+1] - A[i]);
        }
        if(plus<min){
            min = plus;
        }

    }
    cout << min << endl;


}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    int n, m;
    while (cin >> n >> m, n) {
        VV data(m, V(3));
        rep(i, m) {
            int t, s, d;
            cin >> t >> s >> d;
            s--, d--;
            data[i] = {t, s, d};
        }
        sort(all(data));

        vector<bool> infected(n, false);
        infected[0] = true;
        rep(i, m) {
            if (infected[data[i][1]]) infected[data[i][2]] = true;
        }

        int ans = 0;
        rep(i, n) {
            ans += infected[i];
        }

        cout << ans << endl;

    }
}

Measured memory_bytes: 3932
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>


int main() {
    int a, b, c, d; std::cin >> a >> b >> c >> d;
    while (true) {
        c -= b;
        if (c <= 0) {
            std::cout << "Yes" << std::endl;
            return 0;
        }
        a -= d;
        if (a <= 0) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    return 0;
}

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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    vector<int> num(26, 0);
    for (int i = 0; i < H; ++i) {
        cin >> a[i];
        for (char c : a[i]) {
            num[c - 'a']++;
        }
    }
    int odd_num = 0;
    int num4 = 0;
    for (int i = 0; i < 26; ++i) {
        num4 += num[i] / 4;
        if (num[i] % 2 == 1) {
            odd_num++;
        }
    }

    if (H % 2 == 0 && W % 2 == 0) {
        if (odd_num == 0 && H * W / 4 <= num4)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    } else if (H % 2 == 1 && W % 2 == 1) {
        if (odd_num == 1 && (H - 1) * (W - 1) <= num4 * 4)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    } else {
        //必ずHが奇数ということにする
        if (H % 2 == 0)
            swap(H, W);

        if (odd_num == 0 && (H - 1) * W / 4 <= num4)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}


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

#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

using namespace std;

int main(){

  int n,b,f,r,v;
  int i,j,k;
  int num[4][3][10]={0};

  cin >>n;

  for(i=0;i<n;i++){
    cin >>b >>f >>r >>v;
    num[b-1][f-1][r-1]+=v;
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	cout <<" " <<num[i][j][k];
      }
      cout <<endl;
    }
    if(i<3) cout <<"####################" <<endl;
  }

  return 0;
}

Measured memory_bytes: 1168
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;
const lli inf = 1e18;

int n;
int a[maxn];

void read_input()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
}

void solve()
{
    lli sum = 0, ans = inf;
    for(int i = 1; i <= n; ++i)
        sum += a[i];
    lli x = 0;
    for(int i = 1; i < n; ++i)
    {
        x += a[i];
        lli y = sum - x;
        ans = min(ans, abs(x - y));
    }
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 4368
#ABC155B
n=int(input())
a=list(map(int,input().split()))
res=True
for i in range(len(a)):
    if a[i]%2==0 and (a[i]%3!=0 and a[i]%5!=0):
        res=False
if res:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){

     int x;

     cin>>x;

     int u, ult, l;
     bool ok;

     l = 1;
     u = x%10;
     x /= 10;
     while(x != 0 ){
          if( x%10 == u){
               l++;
          }
          else{
               l=1;
               u = x%10;
          }
          x/=10;
          if( l>=3) {
              cout<<"Yes";
              return 0;
    }
     }


    cout<<"No";


return 0;
}


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

int main(){
    map<string, int> word;
    string s;
    string outen;
    string outlen;
    int maxen;
    int maxlen;
    maxen = 0;
    maxlen = 0;
    while(cin >> s){
        if(word.find(s) != word.end()){
            word[s]++;
            if(word[s] > maxen){
                outen = s;
                maxen = word[s];
            }
            if(s.size() > maxlen){
                outlen = s;
                maxlen = s.size();
            }
        }else{
            word.insert(map<string, int>::value_type(s, 1));
            if(s.size() > maxlen){
                outlen = s;
                maxlen = s.size();
            }
            if(word[s] > maxen){
                outen = s;
                maxen = word[s];
            }
        }
    }
    cout << outen << " " << outlen << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int p[n];
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> p[i];
  }

  int memo[n];
  int result, count[4] = {0};
  for (i = 0; i < 4; i++) {
    for (j = 0; j < n; j++) {
      memo[j] = p[j];
    }

    if (p[0] >= i) {
      memo[0] -= i;
      count[i] += i;

      for (j = 0; j < n; j++) {
        if (memo[j] > 0) {
          if (j == (n - 1)) {
            count[i] += memo[j];
            memo[j] -= memo[j];

          } else {
            count[i] += (memo[j] * 2);
            memo[j + 1] -= memo[j];
            memo[j] -= memo[j];
          }
        }
      }
    } else {
      count[i] = 2147483647;
    }
  }

  result = count[0];
  for (i = 0; i < 4; i++) {
    if (result > count[i]) {
      result = count[i];
    }
  }
  cout << result << endl;
  return 0;
}



Measured memory_bytes: 3148
/*2019/07/29 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
typedef long long int ll;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
/*
int asc_t(const void *a,const void *b){return ((user_t*)a)->score - ((user_t*)b)->score;}
int desc_t(const void *a,const void *b){return ((user_t*)b)->score - ((user_t*)a)->score;}
*/

int main(){
    int k,x;
    scanf("%d %d",&k,&x);

    for(int i=x-k+1;i<=x+k-1;i++){
        printf("%d ",i);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define FUNC 180.0/(4*atan(1))
using namespace std;
int main(void)
{
	double xy,a,b,c,d,r=6378.1;
	while(1) {
		cin>>a>>b>>c>>d;
		if(a==-1&&b==-1&&c==-1&&d==-1) break;
		a/=FUNC,b/=FUNC,c/=FUNC,d/=FUNC;
		xy=r*(acos(sin(a)*sin(c)+cos(a)*cos(c)*cos(d-b)));
		cout<<(int)(xy+0.5)<<endl;
	}
}

Measured memory_bytes: 3472
#include <stdio.h>
typedef long long int ll;

int main(){
  int k,a,b;
  scanf("%d%d%d",&k,&a,&b);

  //a<=b+2 たたきつづけるのがよい．
  if(a>=b-2){
    printf("%d\n",1+k);
    return 0;
  }

  //それ以外　できるだけ円と交換するのが良い．
  ll bis=1;
  int yen=0;
  int i=1;
  while(i<=k){
    //最後のターンのみ別処理
    if(i==k){
      if(yen==1){
        bis+=b;
        yen=0;
      }
      else{
        bis++;
      }
      break;
    }

    //最後じゃないターン
    if(yen==1){
      bis+=b;
      yen=0;
    }
    else if(bis<a){
      bis++;
    }
    else if(bis>=a){
      bis=bis-a;
      yen++;
    }
    i++;
  }
  printf("%lld\n",bis);
  return 0;
}


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

int main() {
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    bool rev = false;
    string head = "", tail = "";
    for (int z = 0; z < Q; z++) {
        int T;
        cin >> T;
        if (T == 1){
            rev = !rev;
        }
        if (T == 2) {
            int F;
            cin >> F;
            char c;
            cin >> c;
            if ((F == 1) == (!rev)) {
                head += c;
            }else {
                tail += c;
            }
        }
    }
    reverse(head.begin(), head.end());
    if (!rev) {
        cout << head << S << tail << endl;
    }else {
        reverse(head.begin(), head.end());
        reverse(S.begin(), S.end());
        reverse(tail.begin(), tail.end());
        cout << tail << S << head << endl;
    }
    return 0;
}

Measured memory_bytes: 1088
from  collections import deque
N=int(input())
P=[int(i) for i in input().split()]
inf = 10**20
table=[[0]*(N+2) for i in range(N+2)]
for i in range(1,N+1):
    if P[i-1]>0:
        table[i][N+1]=P[i-1]
    else:
        table[0][i]=-P[i-1]
    for j in range(2*i,N+1,i):
        table[i][j]=inf
        
def bfs(x):
    visit[x]=0
    h=deque()
    h.append(x)
    while h:
        y=h.popleft()
        for i in range(N+2):
            if visit[i]==-1 and table[y][i]>0:
                visit[i]=visit[y]+1
                h.append(i)
    return 0

def dinic(s,t,f):
    if s==t:
        return f
    for i in range(N+2):
        if visit[i]>visit[s] and table[s][i]>0:
            df = dinic(i,t,min(f,table[s][i]))
            if df>0:
                table[s][i]-=df
                table[i][s]+=df
                return df
    return 0

ans=0
while True:
    visit=[-1]*(N+2)
    bfs(0)
    #print(table,visit)
    if visit[N+1]==-1:
        break
    while True:
        df=dinic(0,N+1,inf)
        if df==0:
            break
        ans+=df
        #print(ans)
num=sum([p for p in P if p>0])
print(num-ans)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int a, b, v, w;
    cin >> a >> v >> b >> w;

    swap(a, b);
    swap(v, w);

    int t;
    cin >> t;

    int dist = abs(a-b);
    w -= v;
    if (w > 0 && (dist + w - 1) / w <= t) {
        cout << "YES" << endl;        
    }   
    else {
        cout << "NO" << endl;
    }   

}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n, m, a[1000], b[1000], c[1000], INF = 1e9;

int main() {
	cin >> n >> m;
	inc(i, m) {
		cin >> a[i] >> b[i];
		inc(j, b[i]) {
			int x; cin >> x;
			x--;
			c[i] |= 1 << x;
		}
	}
	
	vector<int> dp(1 << n, INF);
	dp.front() = 0;
	inc(i, m) {
		inc(j, 1 << n) {
			setmin(dp[j | c[i]], dp[j] + a[i]);
		}
	}
	
	
	cout << (dp.back() == INF ? -1 : dp.back()) << endl;
	
	return 0;
}


Measured memory_bytes: 256