akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  int ans1,ans2;
  ans1 = ans2 = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == '#') ans1++;
  }
  int key;
  for (int i = 0; i < N; i++) {
    if (S[i] == '#') {
      key = i;
      break;
    }
  }
  for (int i = key; i < N; i++) {
    if (S[i] == '.') ans2++;
  }
  int ans4;
  ans4 = min(ans1,ans2);
  int ans3;
  vector<int> data(N,0);
  vector<int> ans(N,0);
  int h = 0;
  for (int i = 0; i < N; i++) {
    if(S[i] == '#') {
      data[h] = i;
      h++;
    }
  }
  for (int i = 0; i < h; i++) {
    ans[i] = i + N - 1 - data[i] - (h - 1 - i);
  }
  ans3 = ans[0];
  for (int i = 1; i < h; i++) {
    if(ans[i] < ans3) ans3 = ans[i];
  }
  cout<<min(ans4,ans3)<<endl;
  return 0;
}


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

int main() {
  int n,i,ans=0;
  string s;
  cin >>n>>s;
  
  for(i=0;i<n;i++){
    int cnt=0;
    
    for(char c='a';c<='z';c++){
      bool left=false,right=false;
      
      for(int j=0;j<i;j++)
        if(s[j]==c)
          left=true;
      for(int j=i;j<n;j++)
        if(s[j]==c)
          right=true;
      
      if(left&&right)
        cnt++;
    }
    ans=max(ans,cnt);
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include<stdio.h>

int main (void){

int a,b,c,d;

double a2,b2,e;

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

c=a/b;

d=a%b;

a2=a;

b2=b;

e=a2/b2;

printf("%d %d %f\n",c,d,e);

return 0;

}

Measured memory_bytes: 636
#include<cstdio>
#include<algorithm>
typedef long long LL;
const int MAXN = 100000+10;
const int INF = 0x3f3f3f3f;
int n, t, e;
LL x[MAXN], f[MAXN];
int main(){
   // freopen("t.in", "r", stdin);
    scanf("%d%d%d", &n, &e, &t);
    for(int i=1; i<=n; ++i) scanf("%lld", &x[i]);
    int j=0;
    LL mn = 1e14;
    for(int i=1; i<=n; ++i){
        while((x[i]-x[j+1])*2>=t){
            mn = std::min(mn, f[j] - 2*x[j+1]);
            j++;
        }
        f[i] = std::min(f[j]+t, mn + 2*x[i]);
    }
    printf("%lld\n", f[n]+e);
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int main()
{
  char a;
  cin >> a;

  if (a >= 0x41 && a <= 0x5a)
  {
    cout << 'A' << endl;
  }
  else if (a >= 0x61 && a <= 0x7a)
  {
    cout << 'a' << endl;
  }
  return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  int maxl=0, minr=n+1;
  for(int i=0; i<m; i++){
    int l, r;
    cin >> l >> r;
    maxl=max(maxl, l);
    minr=min(minr, r);
  }
  cout << max(0, minr-maxl+1);
  return 0;
}
    

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }

const ll INF=1e18;

struct edge{ll to,cost;};


struct PP{
    ll min_d,vert;
};

bool operator> (const PP &p1, const PP &p2){
    return p1.min_d > p2.min_d;
};


class Dijkstra{
public:
    ll n;//頂点数,辺数
    V<V<edge>> G;
    V<ll> d;
    V<ll> pr;

    explicit Dijkstra(ll sz_n){
        n=sz_n;
        G.resize(sz_n);
        d.resize(sz_n);
        pr.resize(sz_n);
    }

    void add_edge(ll from,ll to,ll cost){
        G[from].push_back((edge){to,cost});
        G[to].push_back((edge){from,cost});//有向辺の場合は削除
    }

    void exe(ll s){//頂点sからの最短距離
        priority_queue<PP,vector<PP>,greater<PP>> que;
        rep(i,n) d[i]=INF;
        d[s]=0;
        que.push(PP{0,s});//pair...first->最短距離、second->頂点

        while(!que.empty()){
            PP p=que.top();que.pop();
            ll v=p.vert;
            if(d[v]<p.min_d) continue;
            for(int i=0;i<(int)G[v].size();i++){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(PP{d[e.to],e.to});
                    pr[e.to]=v;
                }
            }
        }
    }

    ll dist_to(ll t){
        return d[t];
    }

    //頂点tへの最短路
    vector<ll> get_path(ll t){
        vector<ll> path;
        for(;t!=-1;t=pr[t]) path.push_back(t);//tがsになるまでprev[t]をたどっていく
        reverse(all(path));
        return path;
    }

};


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    Dijkstra ds(n);
    rep(i,n-1){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        ds.add_edge(a,b,c);
    }
    int Q;ll k;
    cin>>Q>>k;
    k--;
    ds.exe(k);
    while(Q--){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        out(ds.dist_to(x)+ds.dist_to(y));
    }
}


Measured memory_bytes: 14852
fun main(args: Array<String>) {
  	var (N, K) = readLine()!!.split(" ").map{ it.toInt() }
    var xList = readLine()!!.split(" ").map(String::toInt)
    
    var value = 0
    
    xList = xList.sorted()
    
    for (n in 0 until K) {
        value += xList[n]
    }

    println(value.toString())
}

Measured memory_bytes: 40684
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);

	char s[11], t[12];
	bool flag = true;
	int i, length;

	scanf("%[^\n]", s);
	getchar();
	scanf("%[^\n]", t);

	length = strlen(s);

	for (i = 0; i < length; i++) {
		if (s[i] != t[i])
			flag = false;
	}

	if(flag)
		printf("Yes\n");
	else if(!flag){
		printf("No\n");
	}
}

Measured memory_bytes: 3684
#include <iostream>

using namespace std;

int main(void){
	int n;
	cin >> n;
	int num[4];
	for(int i=3;i>=0;--i){
		num[i] = n%10;
		n = n / 10;
	}
	for(int i=0;i<(1<<3);++i){
		char op[3];
		for(int j=0;j<3;++j){
			if((i >> j)%2)op[j] = '+';
			else op[j] = '-';
		}
		int res = num[0];
		for(int j=0;j<3;j++){
			if(op[j] == '+')res += num[j+1];
			else res -= num[j+1];
		}
		if(res == 7){
			for(int j=0;j<4;++j){
				cout << num[j];
				if(j < 3)cout << op[j];
			}
			cout << "=7" << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
a = LI()

s,t = 0,0  # 4の倍数の個数、4の倍数でない偶数の個数
for i in range(N):
    if a[i] % 4 == 0:
        s += 1
    elif a[i] % 2 == 0:
        t += 1

if s >= N//2 or t >= N-2*s:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 85248
#include <iostream>
#include <algorithm>

using namespace std;

int main(void)
{
    int N, i, a[101], x=0, y=0;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> a[i];
    }

    sort(a+1, a+N+1);
    reverse(a+1, a+N+1);

    for(i=1; i<=N; i++){
        if(i%2==1){
            x += a[i];
        }

        else{
            y += a[i];
        }
    }

    cout << x-y << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int n, m;
    std::cin >> n >> m;
    long long total = 0;
    for(int i = 0; i < m; i++){
        int a;
        std::cin >> a;
        total += a;
    }
    if(n < total){
        std::cout << -1 << std::endl;
    }else{
        std::cout << n-total << std::endl;
    }
}


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

int main() {
    // double A, B;
    // cin >> A , B;
    // cout << "ceil: " << ceil((A + B) / 2.0) << endl;

    int a, b;
    cin >> a >> b;

    if ((a + b) % 2 == 0) {
        cout << (a + b) / 2 << endl;
    } else {
        cout << (a + b) / 2 + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
//#define for(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define print(x) std::cout << x << std::endl;

using namespace std;

typedef long long ll;

template<class T, class U> std::string replace(std::string s, const T& target, const U& replacement, bool replace_first = 0, bool replace_empty = 0);
bool isContain(int value, int under, int top);
vector<int> range(int x);

int main(void) {
	//Program Start

	vector<int> annt(5);
	rep(i,5){
		cin >> annt[i];
	}

	vector<int> calced(5);
	rep(i,5) {
		calced[i] = (annt[i] % 10);
		if(calced[i] == 0) calced[i] = 10;
	}

	int min = calced[0];
	int min_index = 0;

	rep(i,5) {
		if(calced[i] < min) {
			min = calced[i];
			min_index = i;
		}
	}


	
	int sum = 0;
	
	rep(i,5) {
		if(i == min_index) sum += annt[i];
		else if(annt[i] % 10 == 0) sum += annt[i];
		else sum += (annt[i] / 10 + 1) * 10;
	}

	cout << sum << endl;


ProgramEndPointLabel:;

	//Program End
	//system("pause");

	return 0;
}


vector<int> range(int y) {
	vector<int> result(y);
	for (int i = 0; i < y; i++)
		result[i] = i;
	return result;
}

bool isContain(int value, int under, int top) {
	if (under <= value && value <= top) return true;
	return false;
}

template<class T, class U> std::string replace(std::string s, const T& target, const U& replacement, bool replace_first, bool replace_empty) {
	using S = std::string;
	using C = std::string::value_type;
	using N = std::string::size_type;
	struct {
		auto len(const S& s) { return s.size(); }
		auto len(const C* p) { return std::char_traits<C>::length(p); }
		auto len(const C  c) { return 1; }
		auto sub(S* s, const S& t, N pos, N len) { s->replace(pos, len, t); }
		auto sub(S* s, const C* t, N pos, N len) { s->replace(pos, len, t); }
		auto sub(S* s, const C  t, N pos, N len) { s->replace(pos, len, 1, t); }
		auto ins(S* s, const S& t, N pos) { s->insert(pos, t); }
		auto ins(S* s, const C* t, N pos) { s->insert(pos, t); }
		auto ins(S* s, const C  t, N pos) { s->insert(pos, 1, t); }
	} util;

	N target_length = util.len(target);
	N replacement_length = util.len(replacement);
	if (target_length == 0) {
		if (!replace_empty || replacement_length == 0) return s;
		N n = s.size() + replacement_length * (1 + s.size());
		s.reserve(!replace_first ? n : s.size() + replacement_length);
		for (N i = 0; i < n; i += 1 + replacement_length) {
			util.ins(&s, replacement, i);
			if (replace_first) break;
		}
		return s;
	}

	N pos = 0;
	while ((pos = s.find(target, pos)) != std::string::npos) {
		util.sub(&s, replacement, pos, target_length);
		if (replace_first) return s;
		pos += replacement_length;
	}
	return s;
}


Measured memory_bytes: 256
//#include "b_impl.hpp"

//int main() {
//  freopen("/Users/simon/tmp/test.txt", "r", stdin);
//  // freopen("/Users/simon/tmp/test_output.txt", "w", stdout);
//  int num_cases;
//  cin >> num_cases;
//  for (int i = 0; i < num_cases; ++i) {
//    cout << "Case #" << i + 1 << ": ";
//    solve();
//  }
//}

#include <bits/stdc++.h>
using namespace std;

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

void solve() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;

  if (d < b || a < b) {
    cout << "No" << endl;
    return;
  }

  if (b <= c + 1) {
    cout << "Yes" << endl;
    return;
  }

  long long g = gcd(b, d);

  long long k = (b - a % b);
  if (k % g != 0) {
    k = k / g;
  } else {
    k = k / g - 1;
  }
  long long mx = a % b + k * g;
  if (mx <= c) {
    cout << "Yes" << endl;
    return;
  }

  cout << "No" << endl;
}

int main() {


  int num_cases;
  cin >> num_cases;
  for (int i = 0; i < num_cases; ++i) {
    solve();
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;

unsigned long long int f[86+1];

int main(void){

    int n;
    cin>>n;
    
    f[0]=2;
    f[1]=1;
    
    for(int i=2; i<n+1; i++){
        f[i]=f[i-1]+f[i-2];
    }
    
    cout<<f[n]<<endl;
    
    
}


Measured memory_bytes: 256
import sys

#print("Please enter a value of N")
n = int(input())
if isinstance(n,int) == False:
    print("Input value is not a type of int.")
    sys.exit()
elif n < 1 or 100 < n:
    print("Input value is not in this range [0,100].")
    sys.exit()
else:
    if n%2 == 0:
        a = float(1/2)
    else:
        a = float(((n+1)/2)/n)
    
    print(a)

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    ll ans = 0;
    for(ll i=1; i<=N; i++){
        ll a;
        cin >> a;
        if(i%2==1 && a%2==1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll l, r, d; cin >> l >> r >> d;
    ll ans = (r/d) - ((l-1)/d);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
using System;
using System.IO;
using System.Linq;

namespace ABC126C
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = temp[0];
            var K = temp[1];
            var total = 0.0;

            for (int i = 1; i <= N; i++)
            {
                var prob = 1.0 / N;
                var num = i;

                while (num < K)
                {
                    num *= 2;
                    prob *= 0.5;
                }

                total += prob;
            }

            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        String[] num = str.split(" ",0);
        int[] a  = new int[3];
        int i,j;

        a[0] = Integer.valueOf(num[0]);
        a[1] = Integer.valueOf(num[1]);
        a[2] = Integer.valueOf(num[2]);

        for (i = 2;i > 0; i--){
            for(j = 0;i > j;j++){
                if(a[j]>a[j+1]){
                    swap(a, j+1);
                }
            }
        }
        System.out.println(a[0]+" "+a[1]+" "+a[2]);

        scan.close();
    }
    public static void swap(int[] a,int b){
        int temp;
        temp = a[b];
        a[b] = a[b-1];
        a[b-1] = temp;
    }
}



Measured memory_bytes: 26124
#include<stdio.h>


int main(){
  double i;
  while(scanf("%lf",&i)!=EOF){
    if(48.0>=i){
      printf("light fly\n");
    }else if(51.0>=i){
      printf("fly\n");
    }else if(54.0>=i){
      printf("bantam\n");
    }else if(57.0>=i){
      printf("feather\n");
    }else if(60.0>=i){
      printf("light\n");
    }else if(64.0>=i){
      printf("light welter\n");
    }else if(69.0>=i){
      printf("welter\n");
    }else if(75.0>=i){
      printf("light middle\n");
    }else if(81.0>=i){
      printf("middle\n");
    }else if(91.0>=i){
      printf("light heavy\n");
    }else{
      printf("heavy\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define in(x, a, b) (a <= x && x < b)
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

const ll inf = 1000000001, INF = (ll)1e18 + 1;

int dirx[] = {1, 0, -1, 0};
int diry[] = {0, 1, 0, -1};

void solve() {
	int h, w, k, xs, ys, xt, yt;
	cin >> h >> w >> k >> xs >> ys >> xt >> yt;
	xs--; ys--; xt--; yt--;

	vector<string> s(h);
	for(int i = 0; i < h; i++) cin >> s[i];
	
	using P = pair<int, ii>;
	queue<P> q;
	vector<vi> dist(h, vi(w, inf));
	dist[xs][ys] = 0;
	q.push({0, {xs, ys}});
	while(!q.empty()) {
		int x = q.front().ss.ss, y = q.front().ss.ff, cost = q.front().ff;
		q.pop();
		for(int i = 0; i < 4; i++) {
			for(int j = 1; j <= k; j++) {
				int ny = y + diry[i] * j, nx = x + dirx[i] * j;
                if (not in(ny, 0, h) or not in(nx, 0, w)) break;
                int ncost = cost + 1;
                if (s[ny][nx] == '@') break;
                if (dist[ny][nx] > ncost) {
                    dist[ny][nx] = ncost;
                    q.push(P(ncost, ii(ny, nx)));
                }
                else if (dist[ny][nx] == ncost) continue;
                else break;
//				int nx = x + dirx[i] * j, ny = y + diry[i] * j;	
//				if(not in(x, 0, h) or not in(x, 0, w)) break;
//				int ncost = cost + 1;
//				if(s[nx][ny] == '@') break;
//				if(ncost < dist[nx][ny]) {
//					dist[nx][ny] = ncost;
//					q.push({-ncost, {nx, ny}});
//				} else if(ncost < dist[nx][ny]) {
//					continue;
//				} else break;
			}
		}
	}
	
	if(dist[xt][yt] == inf) cout << -1 << endl;
	else cout << dist[xt][yt] << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

Measured memory_bytes: 12160
#include <stdio.h>

int main(void) 
{
	int n, i;
	int a[52] = {0};
	scanf("%d", &n); getchar();
	for(i = 0; i < n; i++)
 {
		char c;
		int b, num;
		scanf("%c %d", &c, &num); getchar();
		if(c == 'S') b = 0;
		else if (c == 'H') b = 1;
		else if (c == 'C') b = 2;
		else b = 3;
		a[b * 13 + num-1] = 1;
	}
	for(i = 0; i < 52; i++) 
{
		if(!a[i]) {
			if(i / 13 == 0) {
				printf("S ");
			} else if(i / 13 == 1) {
				printf("H ");
			} else if(i / 13 == 2) {
				printf("C ");
			} else {
				printf("D ");
			}
			printf("%d\n", i % 13 + 1);
		}
	}
	return 0;
}


Measured memory_bytes: 2040
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

int main(void){
	int n,i;
	ll C,x[123456],v[123456],ans=0ll,a[123456],b[123456],c[123456],d[123456];
	cin >> n >> C;
	for(i=0; i<n; ++i){
		cin >> x[i] >> v[i];
	}
	a[0] = 0ll; b[0] = 0ll; c[0] = -INFLL; d[0] = -INFLL;
	for(i=0; i<n; ++i){
		a[i+1] = a[i] + v[i];
		b[i+1] = b[i] + v[n-i-1];
	}
	for(i=1; i<=n; ++i){
		a[i] -= x[i-1];
		c[i] = a[i] - x[i-1];
		b[i] -= (C - x[n-i]);
		d[i] = b[i] - (C - x[n-i]);
	}
	a[0] = -INFLL; b[0] = -INFLL;
	for(i=1; i<=n; ++i){
		ans = max(ans,max(a[i],b[i]));
		a[i] = max(a[i],a[i-1]);
		b[i] = max(b[i],b[i-1]);
		c[i] = max(c[i],c[i-1]);
		d[i] = max(d[i],d[i-1]);
	}
	for(i=1; i<=n; ++i){
		ans = max(ans,max(a[i]+d[n-i],b[i]+c[n-i]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5888
#include <stdio.h>
#include <math.h>

int main(void){
    int A,B;

    scanf("%d%d",&A,&B);

    if(A+B==3){
        printf("3");
    }

    else if(A+B==4){
        printf("2");
    }
     
     else if(A+B==5){
        printf("1");
    }       

    return 0;

}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
// 10min
int main(void){
  int n;
  long int ans = 0;
  
  scanf("%d", &n);

  for(int i = 1; i < n; i++){
    ans += i;
  }
  
  printf("%ld\n", ans);
  
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

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

  uint64_t n,k;
  cin>>n>>k;
  std::vector<std::bitset<64>> a(n);
  for(uint64_t i=0;i<n;i++){
    uint64_t pushed;
    cin>>pushed;
    a[i]=std::bitset<64>(pushed);
  }

  int topbit=-1;
  while(std::pow(2,topbit+1)<=k){
    topbit++;
  }


  std::bitset<64> result(0);

  for(int bi=topbit;bi>=0;bi--){
    int count=0;
    for(auto bs:a){
      if(bs[bi]){
        count++;
      }
    }
    if((n%2!=0&&count<=n/2)||(n%2==0&&count<n/2)){
      if(result[topbit]){
        std::bitset<64> temp=result;
        temp[bi]=true;
        if(k>=temp.to_ullong()){
          result[bi]=true;
        }
      }else{
        result[bi]=true;
      }
    }
  }



  uint64_t sum=0;
  for(auto bs:a){
    sum+=(bs^result).to_ullong();
  }
  cout<<sum<<endl;





  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fr(i,k,n) for(int i=k;i<n;i++)
#define read(x) cin>>x
#define ll long long int
#define mod 1000000007 
#define print(x) cout<<x<<endl
#define pb(x) push_back(x)
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dp[100000];
 
int main() { 
    fastIO;
     int t=1,n,k;
      
      
       cin>>n>>k;
       memset(dp,0,sizeof(dp));
       int a[100000];
        fr(i,0,n)
          cin>>a[i];
       int ans[100000];
       ans[0]=0;
         fr(i,1,n)
           ans[i]=INT_MAX;
       dp[0]=0;
       fr(i,0,n)
       { fr(j,i+1, i+k+1){
       if(j<n)
       { 
        ans[j]=min(ans[i]+abs(a[j]-a[i]) ,ans[j]);}
         
       }
       }
    print(ans[n-1]);   
     
    
      
	 
	return 0;
}


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

using namespace std;
typedef long long LL;

int main(){
  string S;
  cin >> S;
  LL K;
  cin >> K;
  LL n=S.size();
  rep(i,n){
    if(S[i]!=S[0]) break;
    if(i==n-1){
      LL ans=n*K/2;
      cout << ans << endl;
      return 0;
    }
  }
  string S1=S, S2=S;
  LL ans1=0, ans2=1;
  rep(i,n-1){
    if(S1[i]==S1[i+1]){
      ans1++;
      S1[i+1]='0';
    }
  }
  ans1*=K;
  if(S1[0]==S1[n-1]) ans1+=K-1;
  S2[0]='0';
  rep(i,n-1){
    if(S2[i]==S2[i+1]){
      ans2++;
      S2[i+1]='0';
    }
  }
  ans2*=K;

  cout << min(ans1,ans2) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define ll                 long long                            
#define ra                 return a;                                          
#define pb                 push_back                                                     
#define sti                stack<ll>
#define spi                stack<pair<ll,ll>>
#define S                  second
#define msi                map<string,ll >
#define msi                map<string,ll >
#define mii                map<ll ,ll >
#define dbg(x)             { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y)          { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z)        { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define mis                map<ll , string>
#define rep(i,a,b)         for(ll  i=a;i<b;i++)
#define mpi                map<pair<ll ,ll >,ll >                                                
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define F                  first 
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define vs                 vector<string>
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define hell               1000000007
#define bs                 binary_search
#define mp                 make_pair
#define qi                 queue<ll>
#define qs                 queue<string>
#define qpi                queue<pair<ll,ll>>
#define qps                queue<pair<ll,string>> 
#define endl               '\n' 
#define itr(a,it)          for(typeof(a.begin()) it=a.begin();it!=a.end();it++)// This will produce const_iterator for const object and normal iterator for non-const object
#define ss                 set<string>
using namespace std;
#define N  300005



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,k;
    cin>>n>>k;
    ll a[n],cost[n+1];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cost[0]=0;
    cost[1]=abs(a[1]-a[0]);
    for(ll i=2;i<n;i++)
    {
        if(i<=k)
        {
            ll mini = abs(a[i]-a[0])+cost[0];
            for(ll j=1;j<i;j++)
            {
                mini = min(abs(a[i]-a[j])+cost[j],mini);
            }
            cost[i]=mini;
        }
        else
        {
            ll mini = abs(a[i]-a[i-k])+cost[i-k];
            for(ll j=i-k+1;j<i;j++)
            {
                mini = min(abs(a[i]-a[j])+cost[j],mini);
            }
            cost[i]=mini;
        }
    }
    cout<< cost[n-1];


    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
 
  for(int i=1; i<N; i++){
    cin >>A.at(i);
  }

  vector<int> buka(N);
  int out;

  for(int i=1; i<N; i++){
    out=A.at(i);
    buka.at(out-1)=buka.at(out-1)+1;
  }

  for(int i=0; i<N; i++){
    cout <<buka.at(i)<<endl;
  }

return 0;
}


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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  long long cnt_R, cnt_G, cnt_B;
  cnt_R = 0;
  cnt_G = 0;
  cnt_B = 0;
  for(int i = 0; i < N; i++){
    if(S.at(i) == 'R') cnt_R++;
    if(S.at(i) == 'G') cnt_G++;
    if(S.at(i) == 'B') cnt_B++;
  }

  long long t_ans = cnt_R * cnt_G * cnt_B;

  long long cnt_num = 0;
  for(int j = 1; j < N; j++){
    for(int i = 0; i < j; i++){
      int k = 2 * j - i;
      if(k < N){
        if((S.at(i) != S.at(j)) && (S.at(i) != S.at(k)) && (S.at(j) != S.at(k))){
          cnt_num++;
        }
      }
    }
  }
  cout << t_ans - cnt_num << endl;
}


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


int main(void)
{   
  while(true){
  int p,q;
  cin >> p;
  if(p==0){
    break;
  }
  char  changes[p][2];
  for(int i=0;i<p;i++){
    cin >> changes[i][0];
    cin >> changes[i][1];
  }
  
  cin >> q;
  char words[q];
  for(int i=0;i<q;i++){
    cin >> words[i];
  }
  
  for (int i=0;i<q;i++){
    for(int j=0;j<p;j++){
      if(words[i]==changes[j][0]){
	 words[i]=changes[j][1];
	 break;
      }

  }
      cout << words[i];
  }
  cout << endl;

  }
    return 0;
}

Measured memory_bytes: 1244
# Paper
class Paper
  def initialize(x, y)
    @x, @y, @grids = x, y, Array.new(x) { Array.new(y, 0) }
  end

  def dye(x, y, d)
    for i in (0..(@x - 1)) do
      for j in (0..(@y - 1)) do
        @grids[i][j] += 1 if (x - i)**2 + (y - j)**2 <= d
      end
    end
  end

  def graph
    @grids.transpose.each do |row|
      puts row.join(' ')
    end
  end

  def dense(x, y, density = 1)
    @grids[x][y] += density if exists?(x, y)
  end

  def exists?(x, y)
    0 <= x && x <= @x - 1 && 0 <= y && y <= @y - 1
  end

  def max_density
    @grids.flatten.max
  end

  def while_grids_sum
    @grids.flatten.select { |x| x == 0 }.size
  end
end

inks = [1, 2, 4]

paper = Paper.new(10, 10)

while line = gets
  x, y, size = line.chomp.split(',').map(&:to_i)
  paper.dye(x, y, inks[size - 1])
end

puts paper.while_grids_sum
puts paper.max_density

Measured memory_bytes: 8656
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int N,K; cin >> N >> K;
  v<int> A(N);
  rep(i,N){
    int a; std::cin >> a;
    a--;
    A[i]=a;
  }
  int pre=0;
  unordered_map<int,int> mp;
  mp[0]++;
  v<int> count(N,0);
  v<int> node;
  node.push_back(0);
  int cnt=0;
  int mod=0,loop=0;
  while(1){
    pre=A[pre];
    mp[pre]++;
    cnt++;
    if(cnt==K){
      cout << pre+1 << endl;
      return 0;
    }
    if(mp[pre]>=2){
      mod=count[pre];
      loop=cnt-mod;
      break;
    }
    node.push_back(pre);
    count[pre]=cnt;
  }
  K-=mod;
  //fore(i,node) cout << i+1 << endl;
  cout << node[mod+K%loop]+1 << endl;
  //cout << mod << " " << loop << endl;
  return 0;
}


Measured memory_bytes: 14564
/*__//\\//\\//\\//\\//\\= BISMILLAHIR RAHMANIR RAHIM =//\\//\\//\\//\\//\\//__*/
#include <bits/stdc++.h>
//........................</HEADER>................................
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
//........................</CONSTANT DEFINE>........................
const unsigned int MOD = 1000000007;
#define ll long long

#define Imax 1e9+5
#define LLmax 1e18

#define Imin -1e9-5
#define LLmin -1e18

#define PI acos(-1.0)
#define EPS 1e-9
#define INF 1<<28

//........................</LOOP >.................................
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)

//................</ STANDARTD TEMPLATE LIBRARY>...................
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair((a),(b))

//........................</ TYPE CONVERSION>......................
#define toRad(a) ((a)*(PI)/180)
#define toDeg(a) ((a)*180/(PI))

//........................</ MATH>.................................
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sq(a) ((a)*(a))
inline bool isEq(double a,double b){
    return (abs(a-b)<EPS);
}
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}

//........................</ ARRAY DEFAULT>........................
#define mem(a,v) memset(a,v,sizeof(a))
string day [] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year

//........................</DIRECTION>.............................
int dx4[]={1,0,-1,0};
int dy4[]={0,1,0,-1}; //4 Direction

int dx8[]={1,1,0,-1,-1,-1,0,1};
int dy8[]={0,1,1,1,0,-1,-1,-1};//8 direction

int dxh[]={2,1,-1,-2,-2,-1,1,2};
int dyh[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction (horse)

//........................</ INPUT/OUTPUT>.........................
#define read(n) scanf("%d",&n)
#define write(n) printf("%d",n)
#define endl '\n'

#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//.......................</ PRE DEFINED FUNCTIONS>..................
bool sortByFirst(const pair<int,int>&a,const pair<int,int>&b){
    return a.first>b.first;
}
//vector <string> v;
//void dfs (string str, string t = "", int cnt = 0) {
//    if (cnt == 2) {
//        v.push_back (t);
//        return;
//    } else {
//        for (int i = 0; i <(int)str.size (); i ++) {
//            dfs (str, t + str [i], cnt + 1);
//        }
//    }
//}
//vector<vector<int> >divisor(100005);
//void divisors(){
//    for(int i=1;i<100005;i++){
//        for(int j=i;j<100005;j+=i){
//           divisor[j].push_back(i);
//        }
//    }
//}

int main () {
    FAST_IO
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int m1,d1,m2,d2;
    while(cin>>m1>>d1>>m2>>d2){
        if(d1==month[m1-1])cout<<"1"<<endl;
        else cout<<"0"<<endl;
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int h, w; cin>>h>>w;
    char a[10][10];
    int cnt=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>a[i][j];
            if(a[i][j]=='#') cnt++;
        }
    }

    if(cnt!=h+w-1){
        cout << "Impossible" << endl;
        return 0;
    }

    queue<P> que;
    que.push(P(0, 0));
    while(que.size()){
        int cy, cx;
        tie(cy, cx)=que.front(); que.pop();

        if(cy==h-1 && cx==w-1){
            cout << "Possible" << endl;
            return 0;
        }

        for(int i=0; i<2; i++){
            int ny=cy+dy[i], nx=cx+dx[i];
            if(ny<h && nx<w){
                if(a[ny][nx]=='#'){
                    a[ny][nx]='.';
                    que.push(P(ny, nx));
                }
            }
        }
    }
    cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
///////////////////////////////////////////////////////
int n,A=0,B=0;
cin >> n;
int a[n];
for(int i=0;i<n;i++){
	cin >> a[i];
}

sort(a,a+n);
for(int i=n-1;i>-1;i=i-2){
	A = A+a[i];
}
for(int i=n-2;i>-1;i=i-2){
	B = B+a[i];
}
cout << A-B << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
//Target for Pupil
//Implementation and Data structures
//Prodip sarker(student_ip)
#define bn begin()
#define en end()
#define mx 5000010
#define pb push_back
#define PI (2.0*acos(0.0))
#define al(a) a.begin(),a.end()
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rep(a,b) for(int a=0;a<b;++a)
#define fastio ios::sync_with_stdio(false)
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
	int a,b,c,n,i,t,tmp,d,e,f,p;
	string str;
	cin>>n>>a;
	cin>>str;
	for(i=0;i<n;i++)
	{
		if(a-1==i)
		cout<<(char)((str[i]-'0'+32)+'0');
		else 
		cout<<str[i];
	}
	return 0;
}

Measured memory_bytes: 3640
n = int(input())

for i in range(n):
    y, m, d = map(int, input().split())
    ans = 0

    while y < 1000:
        while m < 11:
            if y % 3 == 0 or m % 2 > 0:
                ans += 20 - d + 1
            else:
                ans += 19 - d + 1
            d = 1
            m += 1
        m = 1
        y += 1
    print(ans)


Measured memory_bytes: 5592
#include<stdio.h>

int main(void)
{
 int a,b,c,temp;
  scanf("%d",&a);
  scanf("%d",&b);
  temp = a+b;
  
  switch(temp)
  {
    case 5:
      c = 1;
      break;
     
    case 4:
     c = 2;
     break;
    
    case 3:
      c = 3;
      break;
  }
  
  printf("%d", c);
  
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    string s;
    cin >> s;
    vsort(s);
    if(s == "abc")Yes;
    else No;
    
	return  0;
}

Measured memory_bytes: 256
#include<iostream>[
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        int a[5000];
        for(int i=0;i<n;i++)cin>>a[i];
        int mxm=-1000001;
        for(int i=0;i<n;i++){
            int b=0;
            for(int j=i;j<n;j++){
                b+=a[j];
                mxm=max(mxm,b);
            }
        }
        cout<<mxm<<endl;
    }
    return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define infll 1000000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
using namespace std;

int read(){
	int x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
ll readll(){
	ll x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
int main(){
	int k,a,b;
	scanf("%d%d%d",&k,&a,&b);
	if (b<=a+2){ printf("%d\n",k+1); return 0; }
	ll ans=k+1;
	k-=a-1;
	ll now=0;
	if (k>=0){
		now=a+(k&1);
		now+=(ll)(b-a)*(k/2);
	}
	printf("%lld\n",max(ans,now));
	return 0;
}


Measured memory_bytes: 256
#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;

int main() {
	cin >> n;
	
	cout << (n - 1) / 2 << endl;
	
	return 0;
}


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

int main(){
  int H,W,K;cin>>H>>W>>K;
  char c[H][W];
  rep(i,H)rep(j,W)cin>>c[i][j];
  ll ans = 0;
  for(int bit1=0;bit1<(1<<H);++bit1){
    for(int bit2=0;bit2<(1<<W);++bit2){
      int cnt = 0;
      rep(i,H){
        rep(j,W){
          if(bit1 & (1<<i)) continue;
          if(bit2 & (1<<j)) continue;
          if(c[i][j]=='#') cnt++;
        }
      }
      if(cnt==K) ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include<cstdio>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
ll mod = 2e18;
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll n;
ll d[100010];
ll total = 1;
bool check() {
	rep(i, 0, n + 2) {
		if (d[i] > total)return false;
		total = (total - d[i]) * 2;
		if (total > 1000000000)return true;
	}
	return true;
}
void solve() {
	cin >> n;
	rep(i, 0, n + 1)cin >> d[i];
	if (!check()) {
		cout << -1 << endl;
		return;
	}
	vector<ll> most(n + 1);
	most[n] = d[n];
	for (int i = n-1; i >= 0; i--) {
		if(i<60)most[i] = min((1LL << i), most[i+1] + d[i]);
		else most[i] = most[i + 1] + d[i];
	}
	ll ans = 1, lo = 1 - d[0], hi = 2 * lo;
	for (int i = 1; i < n + 1; i++) {
		while (lo < hi) {
			ll mid = (lo + hi + 1) / 2;
			if (mid <= most[i]) {
				lo = mid;
			}
			else {
				hi = mid - 1;
			}
		}
		ans += lo;
		lo -= d[i];
		hi = 2 * lo;
	}
	cout << ans << endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 4720
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int []a = new int [n];
		
		for(int i = 0; i < n ;i++) {
			a[i] = sc.nextInt();
		}
		
		sc.close();
		
		long ans = Math.min(count(n,a,0),count(n,a,1));
		
		System.out.println(ans);
		
		
	}
	private static long count(int n, int []a, int pat) {
		
		long count = 0;
		long sum = 0;
			
		int temp = (int)Math.pow(-1, 1+pat);
		
		for(int i = 0 ; i < n ; i++) {
			sum += a[i];
			temp *= -1;
			if((long)temp * sum <= 0) {
				count += Math.abs(sum) + 1 ;
				sum = temp;
			}
			
		}
		
		return count;
	}
}


Measured memory_bytes: 50912
#include "bits/stdc++.h"
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define inv(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define endl "\n"
#define Endl "\n"

using namespace std;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int x, unsigned int y) {                                                    //return x^y in order(log(y))
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template<class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int sum;
  cin >> sum;
  while (sum != 0) {
    int sum2 = 0;
    rep(i, 9) {
      int temp;
      cin >> temp;
      sum2 += temp;
    }
    cout << sum - sum2 << endl;
    cin >> sum;
  }
}


Measured memory_bytes: 3004
N,M=gets.split.map(&:to_i)
edges=Array.new(N){Array.new}
edges_list=Array.new
M.times do
  a,b=gets.split.map(&:to_i)
  a-=1
  b-=1
  edges[a] << b
  edges[b] << a
  edges_list << [a,b]
end


ans=0
edges_list.each do |ra,rb|
  visited=Array.new(N,false)
  stack=[0]
  while !stack.empty?
    v=stack.pop
    next if visited[v]
    visited[v]=true
    edges[v].each do |vv|
      stack << vv if !(ra==v && rb==vv) && !(ra==vv && rb==v)
    end
  end
  ans+=1 if !visited.all?
end
p ans

Measured memory_bytes: 1788