akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;
signed main(){
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    set<int> l;
    for (int i = n-1, p = 0; i >= 0; --i) {
        if (s[i] == 'o') ++p, l.insert(i), i -= c;
        if (p > k) return 0;
    }
    for (int i = 0, p = 0; i < n && p < k; ++i) {
        if (s[i] == 'o') ++p, (l.find(i)!=l.end()?cout<<i+1<<"\n":cout<<""), i += c;
    }
}


Measured memory_bytes: 11012
#include<iostream>
using namespace std;
int main(){
    int K,X;
    cin>>K>>X;
    int C=X-(K-1);
    for(int i=C;i<=(C+(2*K)-2);i++){
        if(i<-1000000||1000000<i){continue;}
        cout<<i<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    double mx = -1;
    ll al=0,st=0;
    for(int i=0;100*a*i<=f;i++){
        for(int j=0;100*a*i+100*b*j<=f;j++){
            for(int k=0;100*a*i+100*b*j+c*k<=f;k++){
                for(int l=0;100*a*i+100*b*j+c*k+d*l<=f;l++){
                    if(i+j+k+l == 0){
                        continue;
                    }
                    if(c*k+d*l<=(a*i+b*j)*e){
                        double cri = (double)(c*k+d*l)/(100*a*i+100*b*j+c*k+d*l);
                        if(mx < cri){
                            mx = cri;
                            al = 100*a*i+100*b*j+c*k+d*l,st = c*k+d*l;
                        }
                    }
                }
            }
        }
    }
    cout << al << " " << st << endl;
    return 0;
}


Measured memory_bytes: 256
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [a,b,c,d] <- map (read::String->Int) . words <$> getLine
  let t = intersect [a..b] [c..d]
  print $ safelast t - safehead t
  
safehead [] = 0
safehead (x:_) = x

safelast [] = 0
safelast [x] = x
safelast (_:xs) = safelast xs

Measured memory_bytes: 3884
#!/usr/bin/env python3
import sys
import numpy as np
import math

def solve(N: int, K: int, A: "List[int]"):
    index_1 = np.argsort(A)[0]
    if K >= N:
        return print(1)
    l = index_1
    r = N - index_1 - 1
    ans = math.ceil((l + r) / (K - 1))
    print(ans)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24928
#include<iostream>

using namespace std;

int main(){

	int a,b,N,M; cin >> N >> M;
	int A[50],B[50],C[50],D[50],ans[50],num[50];
	int dis;

	//cout << N << M <<endl;

	//Input of Students
	for(int i=0; i < N; i++)
		cin >> A[i] >> B[i];

	//Input of Check Point
	for(int i=0; i < M; i++)
		cin >> C[i] >> D[i];

	dis = 0;
	for(int i=0; i<50; i++){
		ans[i] =1000000000;
	}
	//Caluculation of Mahattan distance
	for(int i=0; i < N; i++){
		for(int j=0; j< M; j++){
			dis = abs(A[i]-C[j]) + abs(B[i]-D[j]);
			if(dis < ans[i] )	{
				ans[i] = dis;
				num[i] = j+1;
			}
		}
	}

	for(int i=0; i < N; i++)
		cout << num[i] <<endl;

		return 0;
}

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

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

  int N, M, K;
  cin >> N >> M >> K;
  deque<lint> A(N), B(M);
  for (auto &i : A) {
    cin >> i;
  }  
  for (auto &i : B) {
    cin >> i;
  }
  for (int i = 1; i < M; i++) {
    B[i] += B[i - 1];
  }
  for (int i = 1; i < N; i++) {
    A[i] += A[i - 1];
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] > K) break;
    int left = K - A[i];
    int bb = upper_bound(begin(B), end(B), left) - begin(B);
    ans = max(ans, i + 1 + bb);
  }
  for (int i = 0; i < M; i++) {
    if (B[i] > K) break;
    int left = K - B[i];
    int bb = upper_bound(begin(A), end(A), left) - begin(A);
    ans = max(ans, i + 1 + bb);
  }

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


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

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

const int mod = 1e9+7;
const int inf = 2e18;

int32_t main()
{	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	int a[n+5];
	for (int i = 0; i < n; ++i)
	{
		/* code */cin>>a[i];
	}
	sort(a,a+n);
	int tot = n-2;	
	int sum = a[n-1];
	for(int i=n-2;i>=0;i--)
	{	
		if(tot>0)
		{
		if((tot-2)<0)
		{
			sum+=a[i];
			tot--;break;
		}
		else if((tot-2)==0)
		{
			sum+=(2*a[i]);
			tot-=2;
			break;
		}
		else
		{
			sum+=(2*a[i]);
			tot-=2;
		}
		}
	}
	cout<<sum<<'\n';
	return 0;
}	

Measured memory_bytes: 5200
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(b-a == c-b){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import itertools


def is_triangle(a, b, c):
    return abs(b - c) < a < b + c


N = int(input())
L = map(int, input().split())
triangles = itertools.combinations(L, 3)
count = 0

for triangle in triangles:
    a = triangle[0]
    b = triangle[1]
    c = triangle[2]

    if (a != b and b != c and c != a) and is_triangle(a, b, c):
        count += 1

print(count)


Measured memory_bytes: 9184
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m, i = 1;
	cin>>n>>m;
	int g = pow(2,m);
	int ans = i*(1900*m+(n-m)*100)*g;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
   string s, t; cin >> s >> t;

   string t2;
   for(int i=0; i<t.size()-1; i++){
      t2 += t.at(i);
   }
   if(t2==s){
      cout << "Yes" << endl;
   }
   else{
      cout << "No" << endl;
   }

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n,x;
  cin>>n>>x;
  int a[n];
  rep(i,0,n) cin>>a[i];
  int gc=abs(a[0]-x);
  rep(i,1,n){
    gc=__gcd(gc,abs(a[i]-x));
  }
  cout<<gc<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3940
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        final int m = (int)Math.sqrt(M);
        boolean[] prm = new boolean[m+1];
        for(int i = 2;i < m+1;i++)  prm[i] = true;
        for(int i = 2;i < m+1;i++){
            if(prm[i]){
                for(int j = 2*i;j < m+1;j += i) prm[j] = false;
            }
        }
        int[] L1 = new int[m+1];
        int[] L2 = new int[m+1];
        int id = 0;
        int M2 = M;
        for(int i = 2;i < m+1;i++){
            if(prm[i] && M2%i == 0){
                L1[id] = i;
                while(M2%i == 0){
                    L2[id]++;
                    M2 /= i;
                }
                id++;
            }
            if(i == m && M2 > 1){
                L1[id] = M2;
                L2[id]++;
                id++;
            }
        }
        int p = solve(1, L1, L2, 0, N, id);
        System.out.println(M/p);
    }
    public static int solve(int a, int[] l1, int[] l2, int ind, int n, int l){
        if(ind == l){
            if(a >= n)  return a;
            else    return 1000000007;
        }else{
            int min = 1000000007;
            for(int i = 0;i <= l2[ind];i++){
                min = Math.min(solve(a*(int)Math.pow(l1[ind], i), l1, l2, ind+1, n, l), min);
            }
            return min;
        }
    }
}

Measured memory_bytes: 22996
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main(){
  input!{
    r: f64
  };
  println!("{}", r * 2f64 * std::f64::consts::PI);
}


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

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if((a==b && b!=c)||(b==c && c!=a)||(c==a && a!=b) ){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,K;
ll a[100010];
ll plusSum=0;
int main(){
    cin>>N>>K;
    for(ll i=0;i<N;i++){
		cin>>a[i];
		if(a[i]>0){
			plusSum+=a[i];
		}
    }
	ll ans=0;
	ll l=0,r=K;
	ll minusSum=0;
	for(ll i=l;i<r;i++){
		if(a[i]<0){
			minusSum+=a[i];
		}
	}
	while(r<=N){
		while(a[r]>=0 && r<=N){
			r++;
		}
		while(r-l>=K){
			ans=max(ans,plusSum+minusSum);
			if(a[l]<0){
				minusSum-=a[l];
			}
			l++;
		}
		if(r==N)break;
		minusSum+=a[r];
		r++;
	}
	l=0;r=K;
	minusSum=0;
	for(ll i=l;i<r;i++){
		if(a[i]>0){
			minusSum+=a[i];
		}
	}
	while(r<=N){
		while(a[r]<0 && r<=N){
			r++;
		}
		while(r-l>=K){
			ans=max(ans,plusSum-minusSum);
			if(a[l]>0){
				minusSum-=a[l];
			}
			l++;
		}
		if(r==N)break;
		minusSum+=a[r];
		r++;
	}
	cout<<ans<<endl;
    return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

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

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int n, x;
  cin >> n >> x;
  vi d(n + 1);
  d[0] = 0;
  int ans = 1;
  FOR(i, 1, n + 1) {
    d[i] = d[i - 1] + read();
    if (d[i] <= x) ans++;
  }
  print(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef vector<PP> V;
typedef vector<vector<int> > VV;
VV d;
void wf(int n) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	d = VV(n, vector<int>(n, INT_MAX / 3));
	V e(m);
	for (int i = 0; i < n; i++) d[i][i] = 0;
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		e[i] = PP(P(min(a, b), max(a, b)), c);
		d[a][b] = c;
		d[b][a] = c;
	}
	wf(n);
	int ans = 0;
	for (int i = 0; i < m; i++) {
		int a = e[i].first.first;
		int b = e[i].first.second;
		int c = e[i].second;
		if (d[a][b] < c) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
N, M, T = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [a[0]]
for i in range(1, N):
    b.append(a[i] - a[i-1])
b.append(T-a[N-1])

ans = 0
ans += b[0] - M
for i in range(1, N):
    ans += max(0, b[i]-2*M)
ans += max(0, b[N]-M)
print(ans)

Measured memory_bytes: 7708
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define MP make_pair
#define PB push_back
#define PII pair<int, int>
typedef long long LL;
const LL P = 998244353;
const int N = 2e5+10;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,a[N],b[N];

int calc(int i){
	return b[(i+1)%n]+b[(i+n-1)%n]; 
}

int main(){
	scanf("%d",&n);
	rep(i,0,n-1)scanf("%d",a+i);
	rep(i,0,n-1)scanf("%d",b+i);
	
	LL s1=0, s2=0, ans=0;
	rep(i,0,n-1) s1+=1ll*a[i], s2+=1ll*b[i];
	//cout<<s1<<" "<<s2<<endl;
	
	priority_queue<PII> heap;
	rep(i,0,n-1) heap.push({b[i],i});
	while(s2>s1){
		PII x = heap.top();
		heap.pop();
		int i = x.second;
		if(b[i]==a[i])continue;
		
		if(b[i]<=calc(i)){
			printf("-1\n");
			return 0;
		}
		if(b[i]%calc(i)>=a[i]){
			s2 = s2 - 1ll * b[i] + 1ll * b[i] % calc(i);
			ans += 1ll * b[i] / calc(i);
			b[i] %= calc(i);
			heap.push({b[i],i});
		}else{
			if( (b[i]-a[i])%calc(i)!=0 ){
				printf("-1\n");
				return 0;
			}else{
				s2 = s2 - 1ll * (b[i] - a[i]);
				ans += 1ll * (b[i] - a[i]) / calc(i);
				b[i] = a[i];
			}
		}
		//rep(i,0,n-1)cout<<b[i]<<" ";cout<<endl;
		//cout<<s2<<endl;
	}
	rep(i,0,n-1)if(a[i]!=b[i]){
		printf("-1\n");
		return 0;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3956
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

n = int(input())
d = sorted(list(map(int, input().split())))
x = n//2
print(d[x] - d[x-1])

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

int main() {

  int a, b, c;
  int result = 0;
  cin >> a >> b >> c;
  
  do {
      if (c % a == 0) {
        result++;
      }
    a++;
  } while (a <= b);

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 3132
# 最初の数字0, 1, 2 は操作の種類を示し、それぞれpushBack、randomAccess、popBackを表します。

gets

b = []

loop do
    s = gets
    if !s then
        break
    end
    
    a = s.split(" ")
    case a[0].to_i
    when 0 then
        b.push(a[1])
    when 1 then
        print b[a[1].to_i], "\n"
    when 2 then
        b.pop
    end
end



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

int main() {
    int N;
    cin >> N;
    N = N % 10;
    if (N == 3) {
        cout << "bon" << endl;
    } else if (N == 0) {
        cout << "pon" << endl;
    } else if (N == 1) {
        cout << "pon" << endl;
    } else if (N == 6) {
        cout << "pon" << endl;
    } else if (N == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> ab(m + 1);
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		if (a > m) continue;
		ab[a].emplace_back(b);
	}
	priority_queue<int> que;
	ll ans = 0;
	rep(i, m + 1) {
		for (auto& c : ab[i]) {
			que.push(c);
		}
		if (!que.empty()) {
			ans += que.top();
			que.pop();
		}
	}
	dunk(ans);
	return 0;
}


Measured memory_bytes: 5632
#include <iostream>
#include<cstdio>
#include<iomanip>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
typedef long long ll;

int main(int argc, char *argv[])
{
	long double a,b,x, h, ret;

	cin >> a >> b>>x;

	h=(2*x/(a*a))-b;
	cerr << h << endl;
	if (h>=0)
	{
		ret=atan2(b-h,a)*180/M_PI;
	}
	else
	{
		h=2*x/a/b;
		cerr << h;			
		ret=atan2(b,h)*180/M_PI;
	}

	cout << std::setprecision(15) <<ret << endl;
	return 0;
}



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

CSF = [list(map(int, input().split())) for i in range(N-1)]

for i in range(N):
    tmp = 0
    for j in range(i,N-1):
        tmp = max(tmp, CSF[j][1])

        if not (tmp % CSF[j][2] == 0):
            tmp = tmp + CSF[j][2] - tmp % CSF[j][2]
        tmp += CSF[j][0]
            
    print(tmp)


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

int main()
{
    int n;
    cin >> n;
    int* arr;
    arr = new int[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int cnt = 1;
    int flag = 0;
    for (int i = 0; i < n; i++)
    {
        if (arr[i] == cnt)
        {
            cnt++;
            flag = 1;
        }
    }
    if (!flag)
        cout << -1 << endl;
    else
    cout<< n - cnt + 1<<endl;
    return 0;
}

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

void fnInput(llong& rnLow, llong& rnHigh, int& rnDivsor1, int& rnDivsor2)
{
  cin >> rnLow >> rnHigh >> rnDivsor1 >> rnDivsor2;
}
  
llong fnAntiDivCnt(llong nLow, llong nHigh, int nDivsor1, int nDivsor2)
{
  int nDividend = max(nDivsor1, nDivsor2);
  int nDivisor = min(nDivsor1, nDivsor2);

  while (nDividend % nDivisor)
  {
    int nRemndr = nDividend % nDivisor;
    nDividend = nDivisor;
    nDivisor  = nRemndr;
  }
  llong nDivLcm = (llong)nDivsor1 * (nDivsor2 / nDivisor);
  llong nLowLessDiv1Cnt = (nLow - 1) / nDivsor1;
  llong nLowLessDiv2Cnt = (nLow - 1) / nDivsor2;
  llong nLowLessDLcmCnt = (nLow - 1) / nDivLcm;

  llong nHighDev1Cnt = nHigh / nDivsor1;
  llong nHighDev2Cnt = nHigh / nDivsor2;
  llong nHighDLcmCnt = nHigh / nDivLcm;
  
  llong nDivsible = (nHighDev1Cnt + nHighDev2Cnt - nHighDLcmCnt) -
                    (nLowLessDiv1Cnt + nLowLessDiv2Cnt - nLowLessDLcmCnt);
  return (nHigh - nLow + 1) - nDivsible;
}
  
int main()
{
  llong nLow, nHigh;
  int   nDivsor1, nDivsor2;

  fnInput(nLow, nHigh, nDivsor1, nDivsor2);
  cout << fnAntiDivCnt(nLow, nHigh, nDivsor1, nDivsor2) << endl;

  return 0;
}

Measured memory_bytes: 256
from collections import deque
import heapq
n,k = map(int,input().split())
v = deque(list(map(int,input().split())))

ans = 0
for i in range(min(n,k)+1):
    for j in range(min(n,k)-i+1):
        l = [0]
        r = [0]
        mm = [0]
        for p in range(i):
            if v[p] > 0:
                l.append(v[p])
            else:
                heapq.heappush(mm,v[p])
        for o in range(j):
            if v[-o-1] > 0:
                r.append(v[-o-1])
            else:
                heapq.heappush(mm,v[-o-1])
        for m in range(min(k-i-j,len(mm))):
            heapq.heappop(mm)
        ans = max(ans,sum(l)+sum(r)+sum(mm))
print(ans)

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

int main(){
    int a,b;
    char op;
        
    while(1){    
        cin >> a >> op >> b;

        if (op == '+'){
            cout << a + b << endl;
        } else if (op == '-'){
            cout << a - b << endl;
        } else if (op == '*'){
            cout << a * b << endl;
        } else if (op == '/'){
            cout << (int)a / b << endl;
        } else {
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;

 int main() {
     int H, W;
     cin >> H >> W;

     vector<vector<char>> grid(H, vector<char>(W));
     vector<vector<int>> L(H, vector<int>(W, 0)), R(H, vector<int>(W, 0)), U(H, vector<int>(W, 0)), D(H, vector<int>(W, 0));

     rep(i, 0, H) {
       rep(j, 0, W) {
         cin >> grid.at(i).at(j);
       }
     }

     rep(i, 0, H) {
       rep(j, 0, W) {
         if (grid.at(i).at(j) == '#') continue;
         else if (j == 0) L.at(i).at(j) = 1;
         else L.at(i).at(j) = L.at(i).at(j - 1) + 1;
       }
     }

     rep(i, 0, H) {
       for (int j = W - 1; j >= 0; j--) {
         if (grid.at(i).at(j) == '#') continue;
         else if (j == W - 1) R.at(i).at(j) = 1;
         else R.at(i).at(j) = R.at(i).at(j + 1) + 1;
       }
     }

     rep(i, 0, W) {
       rep(j, 0, H) {
         if (grid.at(j).at(i) == '#') continue;
         else if (j == 0) U.at(j).at(i) = 1;
         else U.at(j).at(i) = U.at(j - 1).at(i) + 1;
       }
     }

     rep(i, 0, W) {
       for (int j = H - 1; j >= 0; j--) {
         if (grid.at(j).at(i) == '#') continue;
         else if (j == H - 1) D.at(j).at(i) = 1;
         else D.at(j).at(i) = D.at(j + 1).at(i) + 1;
       }
     }

     int ans = 0;

     rep(i, 0, H) {
       rep(j, 0, W) {
         ans = max(ans, L.at(i).at(j) + R.at(i).at(j) + U.at(i).at(j) + D.at(i).at(j) - 3);
       }
     }
     cout << ans << endl;
 }


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

int main(){
  int i=1;
  int x=1;

  while(1){
    cin >> x;
    if(x!=0){
      cout << "Case " << i << ": " << x << endl;
      i++;
    }
    if(x==0){
      break;
    }
  }
  return 0;
}

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

int main() {
  int a,b,c;
  cin >> a;
  cin >> b;
  cin >> c;
  if(a>b){
    if(b>c){
      cout << a-c << endl;
    }
    else {
      if(a>c){
      cout << a-b << endl;
      }
      else{
        cout << c-b << endl;
      }
    }
  }
  else{
    if(a>c){
      cout << b-c << endl;
    }
    else{
      if(b>c){
      cout << b-a << endl;
      }
      else {
        cout << c-a << endl; 
      }
    }
  }
}


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


if(N <10):
    print(N)
elif(N <100):
    print(9)
elif(N < 1000):
    print((N-100+1)+9)
elif(N < 10000):
    print(909)
elif(N < 100000):
    print((N-10000+1)+909)
else:
    print(90909)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define fLoop for(lli i = 0; i < N; i++)
main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli N, K;
    cin >> N >> K;
    lli *input = new lli[N];
    for(lli i = 0; i < N; i++) {
    	cin >> input[i];
	}
	lli *DP = new lli[N];
	for(lli i = 0; i < N; i++) {
		DP[i] = INT_MAX;
	}
	DP[0] = 0;
	for(lli i = 1; i < N; i++) {
		for(lli j = i - 1; j >= max((lli)0, i - K); j--) {
			DP[i] = min(DP[i], DP[j] + abs(input[i] - input[j]));
		}
	}
	cout << DP[N - 1];
	delete[] DP;
}


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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    ll N, x;
    std::cin >> N >> x;
    std::vector<ll> A(N), A_sub(N);
    REP(i, N) {
        std::cin >> A[i];
        A_sub[i] = A[i];
    }

    chmin(A_sub[0], x);
    REP(i, N - 1) {
        auto sum = A_sub[i] + A_sub[i + 1];
        if(x < sum) {
            A_sub[i + 1] -= sum - x;
        }
    }

    ll ans = 0;
    REP(i, N) {
        ans += A[i] - A_sub[i];
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int n;
int l, r;

int main(void)
{
	int cnt;
	
	scanf( "%d", &n );
	
	cnt = 0;
	while( n-- ) {
		scanf( "%d %d", &l, &r );
		
		cnt += r - l + 1;
		
	}
	
	printf( "%d\n", cnt );
	
	return 0;
}

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

int main(){
    bitset<4000001>bit;
    bit[0]=1;
    int n,arr[2001],sum=0;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    int median=(sum>>1)+sum%2;
    for(int i=0; i<n; i++)bit|=(bit<<arr[i]);
    for(int i=median; i<=sum; i++)
        if(bit[i])cout<<i,exit(0);
return 0;
}


Measured memory_bytes: 1664
N, W = map(int, input().split())
jw = [list(map(int, input().split())) for _ in range(N)]
ans = [[0 for _ in range(W + 1)] for __ in range(N)]
for w in range(W + 1):
    if w >= jw[0][1]:
        ans[0][w] = jw[0][0]
    else:
        pass
for n in range(1, N):
    for w in range(W + 1):
        if w < jw[n][1]:
            ans[n][w] = ans[n-1][w]
        else:
            ans[n][w] = max(ans[n-1][w], ans[n-1][w - jw[n][1]] + jw[n][0])
print(ans[N-1][W])



Measured memory_bytes: 25516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

int di[] = {0, 1, 0, -1};
int dj[] = {1, 0, -1, 0};
int main() {
    FAST_IO();
    int N, M; cin >> N >> M;
    vector<string> B(N);
    rep(i, N) cin >> B[i];
    vector<vector<int>> dist(N, vector<int>(M, -1));
    // find dist array from nearest black square
    queue<pii> Q;
    rep(i, N) rep(j, M) {
        if(B[i][j] == '#') {
            dist[i][j] = 0;
            Q.push({i, j});
        }
    }
    // there exist at least one black square for initial condition
    while(!Q.empty()) {
        pii here = Q.front(); Q.pop();
        rep(k, 4) {
            int ni = here.first + di[k], nj = here.second + dj[k];
            if(ni >= 0 && ni < N && nj >= 0 && nj < M && dist[ni][nj] == -1) {
                dist[ni][nj] = dist[here.first][here.second] + 1;
                Q.push({ni, nj});
            }
        }
    }
    int maxDist = 0;
    rep(i, N) rep(j, M) {
        maxDist = max(maxDist, dist[i][j]);
    }
    cout << maxDist << "\n";
}

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

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int H, W, h, w;
int A[1011][1011];

void MAIN() {
    scanf("%d%d%d%d", &H, &W, &h, &w);
    bool yes = true;
    if (1 < w && W % w) {
	REP (i, H) {
	    int z = W/w;
	    for (int j=0; j<W; j+=w) {
		A[i][j] = z+1;
		A[i][j+w-1] = -z-2;
	    }
	}
    } else if (1 < h && H % h) {
	REP (j, W) {
	    int z = H/h;
	    for (int i=0; i<H; i+=h) {
		A[i][j] = z+1;
		A[i+h-1][j] = -z-2;
	    }
	}
    } else {
	yes = false;
    }

    if (yes) {
	puts("Yes");
	REP (i, H) rprintf("%d", A[i], A[i]+W);
    } else {
	puts("No");
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define  ll   long long int
#define  sz   20010

using namespace std;


map<ll,ll>mp;
int main()
{


     ll a,b,k,i,j,p;

     cin>>a>>b>>k;

     p=0;

     for(i=a;i<=b;i++)
     {
         cout<<i<<endl;
         p++;
         mp[i]=1;
         if(p==k)break;
     }
     p=0;
     ll x=b-k+1;
     if(x>=a && x<=b){
     for(i=x;i<=b;i++)
     {
        if(mp[i]==0)cout<<i<<endl;
         p++;
         if(p==k)break;
     }
     }
    return 0;
}



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

struct restraunt{
    string name;
    int point;
    int num;
};
bool operator< (const restraunt& x,const restraunt& y){
   return (x.name==y.name?x.point < y.point:x.name > y.name);//昇順
}

int main(){
    int n;
    cin >> n;
    priority_queue<restraunt> pq;
    for(int i = 0;i < n;i ++){
        string s;
        int p;
        cin >> s >> p;
        pq.push({s,p,i+1});
    }
    for(int i = 0;i < n;i ++){
        cout << pq.top().num << endl;
        pq.pop();
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

ll a[200010];
signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) cin >> a[i];

  FOR(i, 1, n) a[i] += a[i-1];
  //REP(i, n) cout << a[i] << " ";
  //cout << endl;
  ll ret = LLINF;
  REP(i, n-1) {
    ret = min(ret, abs(a[i]-(a[n-1]-a[i])));
    //cout << ret << endl;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 1792
using System; 
using System.Text; 
using System.Collections.Generic;
using System.Linq; 
using E = System.Linq.Enumerable; 

class Program {
     
     static void Main(string[] args) {
     //入力を受け取る
     var N   = int.Parse(Console.ReadLine());
     var A  = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
     
     var cum = new long[N+1];
     
     for(int i = 1;i <= N; i++){
         cum[i] =  cum[i-1]+A[i-1];
         
     }
     
     var ans = long.MaxValue;
     
     for(int i = 1;i < N; i++){
         //スヌケの合計値
         var snuke = cum[i];
         
         //アライグマの合計値
         var arai  = cum[N]-cum[i];
         //Console.WriteLine(arai);
         //二人の差の絶対値
         var dis   = Math.Abs(arai-snuke);
         
         if(ans > dis){
             ans = dis;
         }
     }
        Console.WriteLine(ans);
     }
     
     
}
     
     
     
     
     


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

#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)


int N,M;

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
};

    int main(){
        cin>>N>>M;
        UnionFind unf(N);

        for(int i=0;i<M;i++){
            int tmp,tmp1;
            cin>>tmp>>tmp1;
            tmp--;tmp1--;
            unf.unite(tmp,tmp1);
        }

        ll kazu=0;
        for(int i=0;i<N;i++){
            if(unf.r[i]<0){
                kazu++;
            }
        }

        ll ans = kazu-1;

        cout<<ans<<endl;







    }


Measured memory_bytes: 3788
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		new A().doIt();
	}

	class A {
		void doIt() {
			String str = sc.next();
			if(str.length() < 4){
				System.out.println("No");
			}else{
				if(str.substring(0,4).equals("YAKI")) System.out.println("Yes");
				else System.out.println("No");
			}
		}
	}
}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;
 
typedef long double ld;
using namespace std;
 
 
int main() {
    string S;
    cin >>S;
    ll K=0;
    string t,p="";
    REP(i,SZ(S)){
        t+=S[i];
        if(t==p)continue;
        p=t;
        t="";
        K++;
    }
    cout<<K<<endl;

 
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int f[200001][2];
char s[200001];
int n;
int main()
{
    scanf("%d" , &n);
    scanf("%s", s);
    for (int i = 0; i < n; i ++)
        s[i] = (s[i] == '#');
    f[n - 1][s[n - 1]] = 0;
    f[n - 1][!s[n - 1]] = 1;
    for (int i = n - 1; i > 0; i --) {
        f[i - 1][0] = f[i - 1][1] = n;
        for (int j = 0; j < 2; j++)
            for (int k = 0; k < 2; k++)
                if (!(j == 0 && k == 1))
                    f[i - 1][k] = min(f[i - 1][k], f[i][j] + (k != s[i - 1]));
    }
    printf("%d\n", min(f[0][0], f[0][1]));
    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  int n;
  cin >> n;
  
  vector<int> mochi(n);
  
  for(int i=0; i<n; i++){
    cin >> mochi.at(i);
  }
  
  int counter = 0;
  for(int i=0; i<n; i++){
    int maximum = 0;
    if(mochi.at(i)>maximum){
      maximum = mochi.at(i);
      mochi.at(i) = 0;
      counter++;
    }
    for(int j=0; j<n; j++){
      if(maximum == mochi.at(j)){
        mochi.at(j) = 0;
      }
    }
  }
  
  cout << counter << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    ll n; cin >> n;
    vector<ll> v(100001);
    ll sum = 0;
    rep(i, n) {
        ll a; cin >> a;
        v[a]++;
        sum += a;
    }
    int q; cin >> q;
    rep(i, q) {
        ll b, c; cin >> b >> c;
        sum -= b * v[b];
        sum += c * v[b];
        v[c] += v[b];
        v[b] = 0;
        cout << sum << endl;
    }
}


Measured memory_bytes: 4060
#include <cmath>
#include <cstdio>
using namespace std;

bool check(long long int n, long long int s, const long long int &b){
  s -= n;
  s /= b-1;
  while(n > 0){
    n /= b;
    s += n;
    if(s > 0) return false;
  }
  return s == 0;
}

int main(){
  long long int n, s;
  scanf("%lld %lld", &n, &s);
  if(s > n){
    printf("%d\n",-1);
    return 0;
  }else if(s == n){
    printf("%lld\n",n+1);
    return 0;
  }
  long long int d = n - s, ans = -1, m = sqrt(d);
  for(long long int i = 1; i <= m; ++i){
    if(d != d/i*i) continue;
    if(check(n,s,i+1)){
      printf("%lld\n",i+1);
      return 0;
    }
    if(check(n,s,d/i+1)){
      ans = d/i+1;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
import sys
from collections import deque
import copy
import heapq

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] =  [int(input_raw[0]), int(input_raw[1])]
    graph = {}
    for i in range(M):
        input_raw = read_func().strip().split()
        [a, b, c] =  [int(input_raw[0]), int(input_raw[1]), -long(input_raw[2])]
        if a not in graph:
            graph[a] = [(b, c)]
        else:
            graph[a].append((b, c))

    dummy_inf = long(sys.maxint) * long(sys.maxint)
    dist_list =[dummy_inf for i in range(N + 1)]
    dist_list[1] = 0L

    for i in range(0, 2 * N):
        for j in range(1, N + 1):
            if j not in graph:
                continue
            for edge in graph[j]:
                if dist_list[j] < dummy_inf:
                    #new_cost = dist_list[j] + edge[1]
                    if dist_list[j] + edge[1] < dist_list[edge[0]]:
                        dist_list[edge[0]] = dist_list[j] + edge[1]
                        if (i >= N - 1 and edge[0] == N):
                            print "inf"
                            return
    print -dist_list[N]


if __name__ == '__main__':
    main()

Measured memory_bytes: 3404
#include <stdio.h>

long dif(long a,long b){
  if(b-a>0){
    return b-a;
  }else{
    return a-b;
  }
}

long main(){
  long n,sunuke=0,arai=0,sum,ans,i,box;
  long a[200005];
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);  
  }
  for(i=0;i<n-1;i++){
    a[i+1] += a[i];
  }  
  sum = a[n-1];
  for(i=0;i<n-1;i++){
    box = dif(a[i],sum-a[i]);
    if(i==0){
      ans = box;
    }else{
      if(box<ans){
        ans = box;
      }
    }
  }
  printf("%ld",ans);
  return 0;
}

Measured memory_bytes: 1664
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { fill(arr.begin(), arr.end(), v); }
//template<typename Type> inline void sort(Type& arr, bool order = true){ sort(arr.begin(), arr.end(), order ? less<>() : greater<>()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll N, K;
    cin >> N >> K;
    // 最初のサイコロだけでうまくいく場合
    double p = max(double(N - K+1) / N, 0.0);
    //
    rep(i, min(K-1,N))
    {
        ll s = i + 1;
        ll needScale = (K + s - 1) / s - 1;
        ll odds = 1;
        while (needScale != 0)
        {
            needScale >>= 1;
            odds *= 2;
        }
        p += 1.0 / double(odds*N);
    }
    //
    outD(p);
    //
    return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

ll W, H, N;
vllvll grid;

void paintx(ll sx, ll gx)
{
        rep(i, 0, H) {
                rep(j, sx, gx) {
                        grid[i][j] = 1;
                }
        }
}

void painty(ll sy, ll gy)
{
        rep(i, sy, gy) {
                rep(j, 0, W) {
                        grid[i][j] = 1;
                }
        }
}

int main()
{
        cin >> W >> H >> N;
        grid.resize(H, vll(W, 0));
        rep(i, 0, N) {
                ll x, y, a;
                cin >> x >> y >> a;
                if (a == 1) paintx(0, x);
                if (a == 2) paintx(x, W);
                if (a == 3) painty(0, y);
                if (a == 4) painty(y, H);
        }
        ll cnt = 0;
        rep(i, 0, H) {
                rep(j, 0, W) {
                        if (grid[i][j] == 0) ++cnt;
                }
        }
        //print2d(grid);
        cout << cnt << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define INF (ll)1e18+9
#define N 2000006

using namespace std;

int n, m, k;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
    if (i * j + (n - i) * (m - j) == k || !k) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a-lin bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
 
    int N;cin >> N;
    vector<long long> retu(N);
    for(int i = 0;i<N;i++) cin >> retu.at(i);
    vector<long long> rui(N+1);
    for(int i = 0;i<N;i++){
        rui.at(i+1) = rui.at(i)+retu.at(i);
        rui.at(i+1) %= MOD;
    }
    long long ans = 0;
    for(long long i = 0;i<N;i++){
        ans += retu.at(i)*rui.at(i);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6340