akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

import static java.math.BigDecimal.ROUND_HALF_UP;


public class Main {
    private static int MOD = 1000000007;


    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        int[] abhm = readIntegers(br);
        int a = abhm[0];
        int b = abhm[1];
        int h = abhm[2];
        int m = abhm[3];

        // 0時と12時0分だけは0
        // 1時間ごとに30度
        double tan = (h * 30) + (0.5 * m); // 短針が0時から何度の位置にあるか
        double tyou = m * 6; // 長針も同様

        double kakudo = tyou - tan; // 長針と短針の位置の差が角度となる
//        kakudo = Math.abs(kakudo); // わかりやすく
//        if (kakudo == 0d || kakudo == 360d) { // 長針と短針が重なっている場合
//            System.out.println(0); //距離は0
//            return;
//        }
//        if (kakudo == 180d) { // 180度真逆の場合は長針と短針の長さになるだろう
//            System.out.println(a + b);
//            return;
//        }

        double rad = Math.toRadians(kakudo);
        // 余弦定理
        double a_sq = (a * a) + (b * b) - (2 * a * b * Math.cos(rad));
        System.out.println(Math.sqrt(a_sq));
    }

    private static int readInteger(BufferedReader br) throws IOException {
        return Integer.parseInt(br.readLine());
    }

    private static int[] readIntegers(BufferedReader br) throws IOException {
        String[] s = br.readLine().split(" ");
        int[] ret = new int[s.length];
        for (int i = 0; i < s.length; i++) {
            ret[i] = Integer.parseInt(s[i]);
        }
        return ret;
    }

}


Measured memory_bytes: 25512
package main

import (
	"fmt"
)

func main() {
	var w string
	fmt.Scan(&w)
	
	words := make(map[string]int)
	
	for i := 0; i < len(w); i++ {
		tmp := string(w[i])
		words[tmp]++
	}
	
	for _,v := range words {
		if v % 2 != 0 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

Measured memory_bytes: 512
#include<iostream>

using namespace std;

// A,B <= 100
// N <= 10000
// N <= 1009
int main(){
  int a,b;
  cin >> a >> b;
  for(int i=0; i < 1009; i++){
	int za = i*8/100;
	int zb = i*10/100;
	if(a == za && b == zb){
	  cout << i << endl;
	  return 0;
	}
  }
  cout << -1 << endl;
  return 0;
}



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

int a, b;

int main() {
    cin >> a >> b;
    vector<string> s(100, string(50, '.') + string(50, '#'));
    a--, b--;
    for (int i = 0; i < 100 && b; i += 2) {
        for (int j = 0; j < 49 && b; j += 2) {
            s[i][j] = '#';
            b--;
        }
    }
    for (int i = 0; i < 100 && a; i += 2) {
        for (int j = 99; j > 50 && a; j -= 2) {
            s[i][j] = '.';
            a--;
        }
    }
    cout << 100 << ' ' << 100 << endl;
    for (auto e : s) {
        cout << e << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long nCk(int n,int k){
	long r=1;
	for(int i=1;i<=k;++i){
		r*=n+1-i;
		r/=i;
	}
	return r;
}
long N,A,B,l,r,v[50],c;
double s;
main(){
	cin>>N>>A>>B;
	for(int i=0;i<N;++i)cin>>v[i];
	sort(v,v+N);
	reverse(v,v+N);
	for(int i=0;i<A;++i)s+=v[i];
	l=r=A-1;
	while(l-1>=0&&v[l-1]==v[A-1])--l;
	while(r+1<N&&v[r+1]==v[A-1])++r;
	for(int i=A;i<=(l?A:B);++i)c+=nCk(r-l+1,i-l);
	printf("%.15f\n%ld",s/A,c);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using pint=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define ceil_div(a,b) (a+(b-1))/b
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
#define $in(v,n) ;rep(II,0,n)cin>>v[II]
inline void IN(void){return;}
template<typename F,typename... R>inline void IN(F& f, R&... r){cin>>f;IN(r...);}
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;}

#include <iomanip>

int main(){
    int n; IN(n);
    vector<pint> d(n);
    rep(i, 0, n) IN(d[i].first, d[i].second);

    vector<int> c(n); rep(i, 0, n) c[i] = i;
    double sum = 0;
    do{
        double dist = 0;
        rep(i, 1, n){
            int a = c[i-1], b = c[i];
            double x = pow(d[a].first - d[b].first, 2);
            double y = pow(d[a].second - d[b].second, 2);
            dist += sqrt(x+y);
        }
        sum += dist;
    }while(next_permutation(ALL(c)));

    ll q = 1; rep(i, 1, n+1) q *= i;
    cout << fixed << setprecision(15) << sum/q << el;
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	ll n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	if ((b - a) % 2 == 0) {
		printf("%lld\n", (b - a) / 2);
	} else {
		auto f = [&](ll a, ll b) {
			ll ans = a;
			b -= a;
			a = 1;
			ans += (b - a) / 2;
			return ans;
		};
		printf("%lld\n", min(f(a, b), f(n + 1 - b, n + 1 - a)));
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
   int N;
   cin>>N;
   vector<int>A(32);
   A={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   cout<<A[N-1]<<endl;
}

Measured memory_bytes: 3592
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int N = Integer.parseInt(in.next());
            long T = Long.parseLong(in.next());
            long t[] = new long[N];
            for (int i = 0; i < N; i++) {
                t[i] = Long.parseLong(in.next());
            }
            long ans = 0;

            for (int i = 1; i < N; i++) {
                if (t[i] - t[i - 1] < T) ans += t[i] - t[i - 1];
                else ans += T;
            }
            // 出力
            out.println(ans + T);

        }

    }
}



Measured memory_bytes: 60864
n=int(input())
#a,b,c=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

i=1
mn=len(str(n))
while i*i<=n:
    if n%i==0:
        b=n//i
        mn=min(mn,max(len(str(i)),len(str(b))))
    i+=1
print(mn)

Measured memory_bytes: 9032
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScan in = new MyScan(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            int a = in.nextInt() - 1;
            int b = in.nextInt() - 1;

            out.println("100 100");


            char[][] res = new char[100][100];
            for (int s = 0; s < 50; s++) {
                Arrays.fill(res[s], '.');
                Arrays.fill(res[s + 50], '#');
            }

            for (int i = 0; i < 50; i += 2) {
                for (int r = 0; r < 100; r += 2) {
                    if (b > 0) {
                        res[i][r] = '#';
                        b--;
                    }
                }
            }

            for (int i = 51; i < 100; i += 2) {
                for (int r = 0; r < 100; r += 2) {
                    if (a > 0) {
                        res[i][r] = '.';
                        a--;
                    }
                }
            }


            for (char[] l : res) {
                out.println(new String(l));
            }


        }

    }

    static class MyScan {
        private final InputStream in;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0;
        public int ptrbuf = 0;

        public MyScan(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 23380
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

ll dp[100005][2];

int main(){
  string l;
  cin >> l;
  int n=l.size();
  dp[0][1]=1;
  rep(i, n){
    dp[i+1][0]+=3*dp[i][0];
    dp[i+1][0]%=mod;
    if(l[i]=='0'){
      dp[i+1][1]+=dp[i][1];
    } else {
      dp[i+1][1]+=2*dp[i][1];
      dp[i+1][1]%=mod;
      dp[i+1][0]+=dp[i][1];
      dp[i+1][0]%=mod;
    }
  }
  cout << (dp[n][1]+dp[n][0])%mod << endl;
  return 0;
}


Measured memory_bytes: 5316
#include<stdio.h>
int main()
{
	int input;
	scanf("%d",&input);
	if(input>=10 && input<=99)
	{
		if(input%10==9 || input/10==9)
		{
			printf("Yes\n");
		}
		else printf("No\n");
		
	}
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int fac(int x) {
	if (x <= 1) return 1;
	return x * fac(x - 1);
}

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	vector<int> q(n);

	for (auto& e : p) {
		cin >> e;
	}
	for (auto& e : q) {
		cin >> e;
	}

	vector<int> r(n);
	for (int i = 0; i < n; i++) {
		r.at(i) = i + 1;
	}

	int count = 1;
	int a = -1, b = -1;
	do {
		if (p == r) a = count;
		if (q == r) b = count;
		count++;
	} while (next_permutation(r.begin(), r.end()));

	cout << abs(a - b) << endl;
}


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


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

  vector<long long> arr(N + 1);
  arr[0] = 2;
  arr[1] = 1;

  for (int i = 1; i < N; ++i) {
    arr[i + 1] = arr[i] + arr[i - 1];
  }

  cout << arr[N] << endl;
}


Measured memory_bytes: 256
/**
 * @author karayuu
 */

fun main(args: Array<String>) {
  val (n, a, b) = readLine()!!.split(" ").map { it.toInt() }
  val r1 =  n * a
  if (r1 >= b) {
    println(b)
  } else {
    println(r1)
  }
}

Measured memory_bytes: 38080
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#define nmax_def 110000
using namespace std;
typedef long long ll;

int main() {
	int i, j;
	string S;
	cin >> S;
	char a, b;
	bool ans = 1;
	if (S[0] == S[1])
	{
		if (S[2] == S[3])
		{
			if (S[0] == S[2])
				ans = 0;
		}
		else
			ans = 0;
	}
	else
	{
		if (S[0] == S[2])
		{
			if (S[1] != S[3])
				ans = 0;
		}
		else if (S[0] == S[3])
		{
			if (S[1] != S[2])
				ans = 0;
		}
		else
			ans = 0;
	}
	if (ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=1001;
int main()
{
   fast ;
   ll a,b ;
   cin>>a>>b ;
   ll ans=0 ;
   for(ll i=2;i*i<=a;i++)
   {
      if(a%i==0)
      {
          if(b%i==0)
          {
              ans++ ;
          }
          while(a%i==0)
            a/=i ;
      }
   }
   if(a>1)
   {
       if(b%a==0)
        ans++ ;
   }
   cout<<(ans+1) ;


}


Measured memory_bytes: 256
import itertools
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
city_list_grouped = itertools.groupby(city_list_sorted,key=lambda x:x[0])
ans = [None for i in range(M)]
m =0
for k, v in city_list_grouped:
  counter1 = 1
  for x1 in v:
    ans[m] = [x1[2],format(k,'0>6')+format(counter1,'0>6')]
    counter1 += 1 
    m+=1

for x in sorted(ans):
  print(x[1])

Measured memory_bytes: 95192
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>

using namespace std;

int main(){
   int n;
   cin>>n;
   map<int,int> mp;
   for(int i=0;i<n;i++){
      int a;
      cin>>a;
      mp[a]++;
   }
   
   int ans=0;
   for(auto m:mp){
      if(m.second<m.first)ans+=m.second;
      else ans+=m.second-m.first;
   }
   cout<<ans<<endl;


   
}

   


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

int N, D;
cin >> N >> D;
vector<vector<int>> table(N, vector<int>(2));
for (int i = 0; i < N; i++){
    cin >> table.at(i).at(0) >>table.at(i).at(1);
}

double temp = 0;
int ans = 0;

for (int i = 0; i < N; i++){
    temp = sqrt(pow(table.at(i).at(0), 2) + pow(table.at(i).at(1), 2));
    if(D >= temp){
        ans++;
    }
}

cout << ans << endl;

return 0;
}

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

class Solution {
    public:
        int sol(){
            int n,y;
            cin>>n;
            vector<int> a;
            vector<int> dp(n,INT_MAX);
            for(int i=0;i<n;i++){
                cin>>y;
                a.push_back(y);
            }
            dp[0] = 0;
            for(int i=1;i<n;i++){
                for(int j=i-1;j>=0&&j>=i-2;j--){
                    dp[i] = min(dp[i],dp[j]+abs(a[j]-a[i])); 
                }
            }
            return dp[n-1];
        }
};

int main(){
    Solution test;
    cout<<test.sol();
    return 0;
}

Measured memory_bytes: 1276
#include <stdio.h>
#include <math.h>
 
int isprime(long L){
  long i=3;
  long Ls = (long)sqrt(L);
  if (!(L%2)) return 0;
  while (i<=Ls) {
    if(!(L%i))return 0;
    i+=2;
  }
  return 1;
}
 
int main(void) {
  int N,n,t=0;
  long L;
  scanf("%d\n",&N);
  for(n=0;n<N;n++) {
    scanf("%ld\n",&L);
    if (L==2)     t++;
    else if (L>2) t+=isprime(L);
  }
  printf("%d\n",t);
  return 0;
}


Measured memory_bytes: 2036
def main():
    a, b = map(int, input().split())

    if a == 0 or b == 0:
        print("Zero")
    
    elif a < 0 and b > 0:
        print("Zero")

    elif a < 0 and b < 0:
        if abs(b - a + 1) % 2 == 1:
            print("Negative")
        else:
            print("Positive")

    elif a > 0 and b > 0:
        print("Positive")

if __name__ == "__main__":
    main()

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

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

    int N;
    cin >> N;

    string S;
    cin >> S;

    int x = 0;
    int ans = 0;
    for(int i = 0; i < N; ++i){
        if(S[i] == 'I'){
            ++x;
        }
        if(S[i] == 'D'){
            --x;
        }
        ans = max(ans, x);
    }

    cout << ans << endl;

    return 0;
};

Measured memory_bytes: 256
const Main = input => {
    input = input[0].split(' ');
    var r = parseInt(input[0], 10);
    var d = parseInt(input[1], 10);
    var x = parseInt(input[2], 10);
    var i;
    for (i = 0; i < 10; i++) {
        x = r * x - d;
        console.log(x);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 7756
# ARC61, C

S = input()
sum_all = 0

#指定した位置で分割
def func(s, idx):
    if len(idx) == 0:
        return int(s)
    sum_ = 0
    start=0
    for j in idx:
        sum_ += int(s[start:(j+1)])
        start = j + 1
    sum_ += int(s[idx[-1]+1:])
    return sum_

for bit in range(1<<(len(S)-1)):
    idx = [i for i in range(len(S)-1) if (bit & (1<<i))]
    sum_all += func(S, idx)
print(sum_all)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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 main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    rep(i,n){
        cin >> a[i];
        ++mp[a[i]];
    }
    int ans = 0;
    for(int i = 30; i >= 1; --i){
        ll x = (1LL << i);
        for(auto &p : mp){
            if(p.first >= x) continue;
            if(p.second == 0) continue;
            ll y = x - p.first;
            if(y > p.first) continue;
            if(y == p.first){
                ans += p.second / 2;
                p.second %= 2;
            }
            else{
                ll cnt = min(p.second, mp[y]);
                ans += cnt;
                p.second -= cnt;
                mp[y] -= cnt;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 29828
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
typedef struct pair<int,int> P;
const int MAXN=1000+2;
int h,w,n,tot,gx,gy,ab=1;
char fac[MAXN][MAXN];
int fo[MAXN][MAXN];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

void bfs(){
	memset(fo,0,sizeof(fo));
	queue<P> Q;
	Q.push(P(gx,gy)),fo[gx][gy]=0;
	while(Q.size()){
		P p=Q.front(); Q.pop();
		if(fac[p.first][p.second]-'0'==ab){
			++ab,gx=p.first,gy=p.second,tot+=fo[gx][gy],fac[gx][gy]='.';
			break;
		}
		for(int i=0;i<4;++i){
			int nx=p.first+dx[i],ny=p.second+dy[i];
			if(nx<1 || nx>h || ny<1 || ny>w || fac[nx][ny]=='X' || fo[nx][ny]) continue;
			Q.push(P(nx,ny)),fo[nx][ny]=fo[p.first][p.second]+1;
		}
	}
	if(ab<=n) bfs();
	else return ;
}

int main(){
	cin>>h>>w>>n;
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j){
			cin>>fac[i][j];
			if(fac[i][j]=='S') gx=i,gy=j;
		}
	bfs();
	cout<<tot<<endl;
	return 0;
} 


Measured memory_bytes: 8048
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
                                                                                        
                       
                                                                                                                       
                                                                                                                       
                                                                                                                       
using namespace std;


int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=0;i<1000;i++){
        if(i*a%b==c){
                cout<<"YES";
                return 0;
        }
    }
    cout<<"NO";

    return 0;
}    

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Hassan El Desouky
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define el '\n'
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define RI(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(n)-1)
#define SQR(x) (x)*(x)
#define all(v)  	((v).begin()),((v).end())
typedef long long ll;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef long double ld;
typedef vector<int>		vi;
typedef vector<pii>		vpii;
const double EPS = 1e-9;
const int N = 1e3+2, M = 2e5+5, OO = 0x3f3f3f3f;
//int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
//int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1}; // 8 Directio
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction


class ATrapezoids {
public:
	void solve(std::istream& in, std::ostream& out) {
        int a, b, h; in >> a >> b >> h;
        out << ((a+b)*h)/2 << el;
	}
};


int main() {
	ATrapezoids solver;
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,k;
    cin>>k>>a>>b;
    if(k<=a){
    	return puts("1"),0;
	}
    else if(a<=b){
    	return puts("-1"),0;
	}
    else{
    	 printf("%lld\n",((k-a)/(a-b)+bool((k-a)%(a-b)))<<1|1);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn=1e6+10;
int n,x,y,A,B,C,a[maxn],b[maxn],c[maxn];
long long ans;
priority_queue<int,vector<int>,greater<int> >q;
inline bool cmp(int aa,int bb){return aa>bb;}
int main()
{
	scanf("%d%d%d%d%d",&x,&y,&A,&B,&C);
	for (int i=1;i<=A;i++) scanf("%d",&a[i]);
	sort(a+1,a+A+1,cmp);
	for (int i=1;i<=B;i++) scanf("%d",&b[i]);
	sort(b+1,b+B+1,cmp);
	for (int i=1;i<=C;i++) scanf("%d",&c[i]);
	sort(c+1,c+C+1,cmp);
	for (int i=1;i<=x;i++) q.push(a[i]),ans+=a[i];
	for (int i=1;i<=y;i++) q.push(b[i]),ans+=b[i];
	for (int i=1;i<=C;i++)
	if (q.top()<c[i])
	{
		ans+=c[i]-q.top(); q.pop(); q.push(c[i]);
	}
	printf("%lld\n",ans);
return 0;
}

Measured memory_bytes: 9976
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ll n; cin >> n;
    vector<ll> v(n+1);
    v[0] = 0;
    REP(i,1,n+1){
        ll num; cin >> num;
        v[i] = v[i-1] + num;
    }
    map<ll, ll> m;
    rep(i,n+1){
        m[v[i]]++;
    }
    ll ans = 0;
    for(auto val : m){
        if(val.second>=2){
            ans += val.second*(val.second-1)/2;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 14336
#include <cstdio>
#include <string>
using namespace std;

int main()
{
	int n;
	string num[] = {
		"0111111",
		"0000110",
		"1011011",
		"1001111",
		"1100110",
		"1101101",
		"1111101",
		"0100111",
		"1111111",
		"1101111"
	};
	
	while (scanf("%d", &n), n != -1){
		int input;
		char str[10] = "0000000";
		char diff[10] = "0000000";
			
		for (int i = 0; i < n; i++){
			
			scanf("%d", &input);
			
			for (int j = 0; j < 7; j++){
				if (input == 0){
					
					//printf(" %s %s\n", str, num[0].c_str());
					
					if (str[j] == num[0][j]){
						diff[j] = '0';
					}
					else {
						diff[j] = '1';
						str[j] = num[0][j];
					}
				}
				else if (input == 1){
				//	printf(" %s\n", str);
					
					if (str[j] == num[1][j]){
						diff[j] = '0';
					}
					else {
						diff[j] = '1';
						str[j] = num[1][j];
					}
				}
				else if (input == 2){
					if (str[j] == num[2][j]){
						diff[j] = '0';
					}
					else {
						diff[j] = '1';
						str[j] = num[2][j];
					}
				}
				else if (input == 3){
					if (str[j] == num[3][j]){
						diff[j] = '0';
					}
					else {
						diff[j] = '1';
						str[j] = num[3][j];
					}
				}
				else if (input == 4){
					if (str[j] == num[4][j]){
						diff[j] = '0';
					}
					else {
						diff[j] = '1';
						str[j] = num[4][j];
					}
				}
				else if (input == 5){
					if (str[j] == num[5][j]){
						diff[j] = '0';
					}
					else {
						diff[j] = '1';
						str[j] = num[5][j];
					}
				}
				else if (input == 6){
					if (str[j] == num[6][j]){
						diff[j] = '0';
					}
					else {
						diff[j] = '1';
						str[j] = num[6][j];
					}
				}
				else if (input == 7){
					if (str[j] == num[7][j]){
						diff[j] = '0';
					}
					else {
						diff[j] = '1';
						str[j] = num[7][j];
					}
				}
				else if (input == 8){
					if (str[j] == num[8][j]){
						diff[j] = '0';
					}
					else {
						diff[j] = '1';
						str[j] = num[8][j];
					}
				}
				else if (input == 9){
					if (str[j] == num[9][j]){
						diff[j] = '0';
					}
					else {
						diff[j] = '1';
						str[j] = num[9][j];
					}
				}
			}
			printf("%s\n", diff);
		}
	}
}

Measured memory_bytes: 1048
package main

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

// const abcd = "abcdefghijklnmopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

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

func main() {
	log.SetFlags(log.Lshortfile)
	scn := newScanner()
	s := scn.next()
	fmt.Println(s[:len(s)-8])
}

///////////////////////////////////////////////////
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) nextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) nextInt() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) nextInt64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int dp[11000];

int main(){
  string a,b;
  cin>>a>>b;

  if(a=="H") cout<<b<<endl;
  else if(b=="H") cout<<"D"<<endl;
  else cout<<"H"<<endl;
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

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

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

void solve(vi xs)
{
	int n=xs.size();

	vector<tuple<int,int>> ts(n);
	rep(i,n) ts[i]=mt(xs[i],i+1);
	sort(all(ts));

	deque<int> q;
	for(auto t:ts){
		int x=get<1>(t);
		rep(_,x-1) q.push_back(x);
	}

	vi occ(n+1),res;
	int p=0;
	for(auto t:ts){
		int i,x; tie(i,x)=t;
		for(;p<i;p++){
			if(q.empty()){
				cout<<"No"<<endl;
				return;
			}
			occ[q.front()]++;
			res.push_back(q.front());
			q.pop_front();
		}
		p=i+1;
		if(occ[x]<x-1){
			cout<<"No"<<endl;
			return;
		}
		res.push_back(x);
		rep(_,n-x) q.push_back(x);
	}

	while(q.size()){
		res.push_back(q.front());
		q.pop_front();
	}

	cout<<"Yes"<<endl;
	rep(i,res.size())
		cout<<res[i]<<" \n"[i+1==res.size()];
}

int main()
{
	for(int n;cin>>n&&n;){
		vi xs(n);
		rep(i,n) cin>>xs[i],xs[i]--;
		solve(xs);
	}
}


Measured memory_bytes: 2932
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>
#include <utility>

using namespace std;

int main()
{
    int N, X, Y;
    cin >> N >> X >> Y;
    int cost[N][N];
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (i == j)
                cost[i][j] = 0;
            else
                cost[i][j] = N;
        }
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (i == j) 
                continue;
            int tmp1 = min(cost[i][j], abs(j - i));
            int tmp2 = min(cost[j][i], abs(j - i));
            cost[i][j] = tmp1;
            cost[j][i] = tmp2;
        }
    }
    cost[X - 1][Y - 1] = 1;
    cost[Y - 1][X - 1] = 1;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (i == j) 
                continue;
            int tmp1 = min(cost[i][j], cost[i][X - 1] + cost[X - 1][Y - 1] + cost[Y - 1][j]);
            int tmp2 = min(cost[j][i], cost[i][X - 1] + cost[X - 1][Y - 1] + cost[Y - 1][j]);
            cost[i][j] = tmp1;
            cost[j][i] = tmp2;
        }
    }

    int ans[N];
    for (int i = 0; i < N; i++)
        ans[i] = 0;

    for (int i = 0; i < N - 1; i++)
        for (int j = i + 1; j < N; j++)
            ans[cost[i][j] - 1]++;

    for (int i = 0; i < N - 1; i++)
        cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 15872
from operator import itemgetter
N = int(input())
SP_1 = [list(input().split()) for i in range(N)]
for i in range(N) :
    SP_1[i][1] = int(SP_1[i][1])
buf = 0
SP_2 = SP_1
SP_1 = sorted(SP_1,key = itemgetter(0))
# print(SP_1)
for i in range(1,N) :
    if SP_1[i][0] != SP_1[i-1][0] :
        #print(SP_1[buf:i])
        SP_1[buf:i] = sorted(SP_1[buf:i],key = itemgetter(1),reverse = True)
        buf = i
SP_1[buf:N] = sorted(SP_1[buf:N],key=itemgetter(1),reverse = True)
# print(SP_1) 
for i in range(N) :
    for j in range(N) :
        if SP_1[i] == SP_2[j] :
            print(j+1)
            break

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

#define INF (1<<30)

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

	long long ans=INF;
	for(long long i=1; i<=sqrt(n); i++){
		long long a=i, b=n/i;
		if(a*b!=n)continue;

		long long M=max(a,b);

		long long d=1;
		while(M>=10){
			M/=10;
			d++;
		}
		ans=min(ans,d);

	}

	cout<<ans<<endl;


	return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

char c;

signed main() {
    cin >> c;
    cout << (char)(c+1) << endl;
}



Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    LL X;
    R(X);
    LL an=1e9;
    while(X){
        an=min(an,abs(X%1000-753));
        X/=10;
    }
    W(an);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=1; i<(n); i++)
int main()
{
    int n;
    cin >> n;
    int ans;
    rep(i, n+2){
        if(i*i > n){
            ans = (i-1)*(i-1);
            break;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
double ans,p;
int n,k,now;
int main(){
	scanf("%d%d",&n,&k);
	fo(i,1,n){
		p=1.0/n;
		now=i;
		while (now<k){
			now*=2;
			p*=0.5;
		}
		ans+=p;
	}
	printf("%.15f\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,c=0;
    char s[100];
    cin>>n;
    for(int i = 0;i<n;i++){
        cin>>s[i];
    }
    for(int i = 0; i < n-2;i++){
        if(s[i]=='A'){
            if(s[i+1]=='B'&&s[i+2]=='C'){
                c++;
                i=i+2;
            }
        }
    }
    cout<<c<<endl;
}


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

#define rep(i,j) for(int i=0;i<(int)(j);++i)
typedef long long qword;
const int maxn = 1e5 + 10;
qword a[maxn];



inline void work(int N, int k) {
    rep(i,N) {
        cin >> a[i];
    }
    qword ans = 0x7fffffffff;
    for (int i = 0; i < N - k + 1; ++ i) {
        qword x = a[i], y = a[i + k - 1];
        if (1ll * x * y < 0) {
            ans = min(ans, 2 * abs(x) + abs(y));
            ans = min(ans, 2 * abs(y) + abs(x));
        } else {
            ans = min(ans, max(abs(x), abs(y)));
        }
    }
    cout << ans << endl;
}

int main() {
    int N, k;
    while (cin >> N >> k) {
        work(N, k);
      	return 0;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef unsigned long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

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

LL dp[110][21];

int main(void)
{
	ios::sync_with_stdio(false);
	int n;
	while(cin >> n && n)
	{
		memset(dp, 0, sizeof(dp));
		dp[0][getInt()] = 1;
		for (int i = 0; i < n - 2; i++)
		{
			int num = getInt();
			for (int j = 0; j < 21; j++)
			{
				int a = j + num;
				int b = j - num;
				if(inRange(0, 21, a))
					dp[i + 1][a] += dp[i][j];
				if(inRange(0, 21, b))
					dp[i + 1][b] += dp[i][j];
			}
		}
		cout << dp[n - 2][getInt()] << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
// Sequence
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int n;
int a[100000];
long long c[2];

int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int C=0;C<2;C++){
        int sign=C*2-1;
        int sum=0;
        for(int i=0;i<n;i++){
            if((sum+a[i])*sign<1){
                c[C]+=abs(sum+a[i]-sign);
                sum=sign;
            }else sum+=a[i];
            sign*=-1;
        }
    }
    cout<<min(c[0],c[1]);

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

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

	for (int i = 0; i < N; i++) {
		double ax, ay, ar, bx, by, br;
		cin >> ax >> ay >> ar >> bx >> by >> br;

		double d, x, y;
		x = abs(ax - bx);
		y = abs(ay - by);
		d = sqrt(x * x + y * y);

		int a = -100;
		if (d < abs(ar - br)) {
			if (ar > br) {
				a = 2;
			}
			else {
				a = -2;
			}
		}
		else if (d > (ar + br)) {
			a = 0;
		}
		else {
			a = 1;
		}

		cout << a << endl;
	}
}


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

using namespace std;

static string ln = "\n";
static string sp = " ";

int n, k;
int r, s, p;

static char rock = 'r';
static char scissors = 's';
static char paper = 'p';

int getWinPoints(char a) {
  if (a == rock) return p;
  if (a == paper) return s;
  return r;
}

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

  string t;

  cin >> n >> k;
  cin >> r >> s >> p;
  cin >> t;

  bool m[n];
  for (int i = 0; i < n; i++) m[i] = false;

  int sum = 0;

  for (int i = 0; i < n; i++) {
    bool isFirstTime = i < k || t[i] != t[i - k];
    bool isWin = isFirstTime || !m[i - k];
    if (!isWin) continue;

    sum += getWinPoints(t[i]);
    m[i] = true;
  }

  cout << sum << ln;
}



Measured memory_bytes: 592
n,w=map(int,input().split())
W=[0]*n
V=[0]*n
for i in range(n):
  W[i],V[i]=map(int,input().split())
dp=[[0]*(w+1) for _ in range(n+1)]  
for i in range(1,n+1):
  for j in range(1,w+1):
    if j-W[i-1]>=0:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-W[i-1]]+V[i-1])
    else:
      dp[i][j]=dp[i-1][j]
print(dp[n][w])      

Measured memory_bytes: 120300
N = int(input())
l = list(map(int,input().split()))

# 元のindexを保存
idx_dict = {}
for i in range(N):
    idx_dict[i] = l[i]

l.sort()
smaller_middle_idx = int(N / 2) - 1
bigger_middle_idx = int(N / 2)

for i in range(N):
    except_num = idx_dict[i] #今回取り除く数
    
    if l[smaller_middle_idx] == l[bigger_middle_idx]:
        print(l[smaller_middle_idx])

    elif except_num < l[bigger_middle_idx]:
        print(l[bigger_middle_idx])
    
    else:
        print(l[smaller_middle_idx])

Measured memory_bytes: 38408
main(void){
    
    int a,b,x,y,r;
    
    scanf("%d %d %d %d %d",&a,&b,&x,&y,&r);
    
    if(x+r<=a && y+r<=b && x-r>=0 && y-r>=0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
}


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

#define ff first
#define ss second
#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define endl "\n"      // Comment in INTERACTIVE(there just use endl which flushes output , no need of fflush(sdtout)).
//  for counting setbits -> __builtin_popcountll(x)
// for counting zerobits -> __builtin_ctzll(x)
#define fastio() ios_base::sync_with_stdio(false);        cin.tie(NULL); //(unties i/o buffer).
            // DON'T USE SCANF/PRINTF WITH IT (c/c++ -> seperates buffer).

const int mod = 1000000007;
// const int N = 2*(1e5) + 2;
// int arr[N];

int32_t main(){
    fastio();

    // #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    // #endif

     // ***** AC_chahiye EK BAR MEIN

     // BEGIN CODE HERE
    int n;
    cin>>n;
    vi h(n+1);
    for(int i = 1;i <= n; ++i)
        cin>>h[i];
    vi dp(n+1);

    dp[1] = 0, dp[2] = abs(h[2] - h[1]);
    for(int i = 3;i <= n; ++i)
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i-1])  ,  dp[i - 2] + abs(h[i] - h[i - 2]));
    cout<<dp[n];
    //getch();
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int n; cin >> n;
	vector<int> l(n), r(n);
	int count = 0;
	rep(i,n){
		cin >> l[i] >> r[i];
		count += r[i] - l[i]+1;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
constexpr int INF = (numeric_limits<int>::max() == INT_MAX ? (int)1e9 : (long long)1e18);
constexpr long double eps = 1e-6;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;using pii = pair<int,int>;using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void fast_io(){ios::sync_with_stdio(false); cin.tie(nullptr);}
signed main(){
    int N; cin >> N;
    vector<vector<pii>>input(N);
    rep(i,N){
        int n; cin >> n;
        vector<pii>t(n);
        for(auto& p : t) cin >> p.first >> p.second;
        input[i] = t;
    }
    int ans = 0;
    for(int bit = 0; bit < (1LL << N); ++bit){
        vector<bool>is_honest(N,false);
        for(int i = 0; i < N; ++i) is_honest[i] = (bit & (1LL << i));
        bool valid = true;
        for(int i = 0; i < N; ++i){
            if(not is_honest[i])continue;
            for(int j = 0; j < input[i].size(); ++j){
                int id = input[i][j].first;
                int t = input[i][j].second;
                if(is_honest[id - 1] != t) valid = false;
            }
        }
        if(valid)cmax(ans,count_if(all(is_honest),[](bool e){return e;}));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque

def permutation(n, r):
    if (r < 0) or (n < r):
        return 0

    res = factinv[r] % p
    for i in range(r):
        res = res * (n - i) % p

    return fact[n] * factinv[n-r] % p

def BFS(tree, root):
    N = len(tree)
    dist = [-1]*N

    res = K

    q = deque([root])
    dist[root] = 0

    while q:
        v = q.popleft()
        for n_v in tree[v]:
            if dist[n_v] != -1:
                continue
            dist[n_v] = dist[v] + 1
            q.append(n_v)
        
        child_cnt = len(tree[v])
        if dist[v] > 0:
            child_cnt -= 1

        if child_cnt > 0:
            color = K - 1
            if dist[v] > 0:
                color -= 1
            
            if color < child_cnt:
                res = 0
                break
            else:
                res *= permutation(color, child_cnt)
                res %= p
    
    return res

N, K = map(int, input().split())
tree = [[] for _ in range(N)]

p = 10 ** 9 + 7

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, K + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

for i in range(N - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

print(BFS(tree, 0))

Measured memory_bytes: 96200