akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.math.BigDecimal;
class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);

  double L = scan.nextInt();
    double M = L / 3;
  BigDecimal bd1 = new BigDecimal(M);
  BigDecimal bd2 = new BigDecimal(M);
  BigDecimal result1 = bd1.multiply(bd2);
  BigDecimal result2 = result1.multiply(bd1);
  
  System.out.println(result2);
  
 }
}

Measured memory_bytes: 22100
<?php
  fscanf(STDIN, "%d%d", $n,$m);
  $stir = array_fill(1,$n,1);
  for($i=0; $i<$m; $i++){
      $a = trim(fgets(STDIN));
      $stir[$a] = 0;
  }
  
  $dp[0] = 1;
  if($stir[1]) $dp[1] = 1;
  else $dp[1] = 0;
  for($i=2; $i<=$n; $i++){
      if($stir[$i]){
          $dp[$i] = ($dp[$i-1]+$dp[$i-2])%(10**9+7);
      }else{
          $dp[$i] = 0;
      }
  }
  
//   print_r($dp);
  echo $dp[$n];

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

int main() {
  int x;
  cin >> x;
  string s;
  if(x/100==7){
    s="Yes";
  }
  else if ((x/10)%10 == 7){
    s="Yes";
  }
  else if(x%10 == 7){
    s="Yes";
  }
  else{
    s="No";
  }
  cout << s << endl;


}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            string s = Console.ReadLine();
            string t = Console.ReadLine();
            int[] sr = new int[26];
            int[] tr = new int[26];
            string ans = "Yes";
            for(var i = 0; i < 26; i++)
            {
                sr[i] = -1;
                tr[i] = -1;
            }
            for(var i = 0; i < s.Length; i++)
            {
                if (sr[s[i] - 'a'] < 0)
                {
                    sr[s[i] - 'a'] = t[i] - 'a';
                }
                else
                {
                    if (t[i] - 'a' != sr[s[i] - 'a']) 
                    {
                        ans = "No";
                        break;
                    }
                }

                if (tr[t[i] - 'a'] < 0)
                {
                    tr[t[i] - 'a'] = s[i] - 'a';
                }
                else
                {
                    if (s[i] - 'a' != tr[t[i] - 'a'])
                    {
                        ans = "No";
                        break;
                    }
                }
            }
            Console.WriteLine(ans);

        
            Console.Out.Flush();
        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}
    

Measured memory_bytes: 13140
#include <iostream>
#include <string>

using namespace std;

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

	int a = 0; 
	int b = 0;

	for (int i = 0; i < n; i++)
	{
		string s;
		string t;

		cin >> s >> t;

		if (s.compare(t) > 0)
		{
			a += 3;
		}
		else if (s.compare(t) == 0)
		{
			a += 1;
			b += 1;
		}
		else
		{
			b += 3;
		}
	}

	cout << a << " " << b << endl;
}


Measured memory_bytes: 3104
import math
N,K = map(int,input().split())
blue = K
red = N-K
def combinations(n, r):
  if n == r:
    return 1
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(1,K+1):
  if i > N-K+1:
    print(0)
  else:
    ans = (combinations(red+1, i)*combinations(K-1, i-1))%(10**9+7)
    print(ans)


Measured memory_bytes: 3316
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
 

int main(){
  ll n, a, b; cin >> n >> a >> b;
  if(b-a<0){
    cout << 0 << endl; return 0;
  }
  if(n==1){
    if(a==b) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
  }
  if(n==2){
    cout << 1 << endl; return 0;
  }
  cout << (b-a)*(n-2) + 1 << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//char型から数値型に変換する関数（z.at(i)などに使用）
int ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
//入力した値の階乗（を1000000007で割ったあまり）を求める関数
int fact(int64_t x){
  int64_t y=1;
  if(x==0){
    return 1;
  }
  else{
  for(int64_t i=1;i<=x;i++){
   y*=i;
   y%=1000000007;
  }
  return y;
  }
}
// mod. m での a の逆元 a^{-1} を計算する関数
int64_t modinv(int64_t a,int64_t m) {
    int64_t b=m,u=1,v=0;
    while(b){
        int64_t t=a/b;
        a-=t*b;swap(a,b);
        u-=t*v;swap(u,v);
    }
    u%=m;
    if(u<0)u+=m;
    return u;
}
// a ÷ b mod.1000000007 
// a を 10000000007 で割ってから b の逆元をかけて計算
// a*modinv(b,1000000007)%1000000007
//nCr（を1000000007で割ったあまり）を求める関数
int combi(int64_t n,int64_t r){
  int64_t z=(fact(n-r)*fact(r))%1000000007;
  return fact(n)*modinv(z,1000000007)%1000000007;
}
int main() {
  int64_t n;
  cin>>n;
  vector<int64_t> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  int64_t sum=0;
  for(int i=0;i<n;i++){
    sum+=a.at(i)-1;
  }
  cout<<sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#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()

using namespace std;
using ll = long long;
using ld = long double;

const int N = 100002;
int used[N], cc[N];
vector<int> g[N];
vector<pair<int, int>> ans;

void dfs(int v, int p) {
    used[v] = 1;
    for (int u : g[v]) {
        if (u == p)
            continue;
        if (!used[u])
            dfs(u, v);
        else if (used[u] == 1) {
            ans.push_back({v, u});
            cc[v] ^= 1;
        }
    }
    if (cc[v]) {
        if (p == -1) {
            cout << -1;
            exit(0);
        }
        ans.push_back({v, p});
    }
    else if (p != -1) {
        ans.push_back({p, v});
        cc[p] ^= 1;
    }
    used[v] = 2;
}

int main() {
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m, u, v;
    cin >> n >> m;
    rep(i, m) {
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int i = 1; i <= n; i++)
        if (!used[i])
            dfs(i, -1);
    for (auto &p : ans)
        cout << p.first << ' ' << p.second << '\n';
}



Measured memory_bytes: 14836
from collections import defaultdict

n = int(input())
A = [int(i) for i in input().split()]
p = 10 ** 9 + 7

m = n % 2 == 0
cnt = defaultdict(int)

for a in A:
    if (a % 2 == 0) == m:
        print(0)
        exit()
    cnt[a] += 1
    if cnt[a] > 2 or cnt[0] > 1:
        print(0)
        exit()

print(pow(2, (n//2), p))

Measured memory_bytes: 14820
#include<bits/stdc++.h>
#define it register int
#define ct const int
#define il inline
using namespace std;
typedef long long ll;
#define rll register ll
#define cll const ll
typedef unsigned long long ull;
const int N=1000005;
char s[N];
int main(){
	scanf("%s",s+1);it i,n=strlen(s+1);
	printf("%s",s+1);s[n]=='s'?puts("es"):puts("s"); 
	return 0;
}


Measured memory_bytes: 3828
// C++11
#include <iostream>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::swap;

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

  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int count = 0;

  for (int i = 0; i < N; i++) {
    int mini = i;
    for (int j = i; j < N; j++) {
      if (A[j] < A[mini]) {
        mini = j;
      }
    }
    if (i != mini) {
      swap(A[i], A[mini]);
      count++;
    }
  }

  for (int i = 0; i < N; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl;
  cout << count << endl;

  return 0;
}



Measured memory_bytes: 3100
import math
a, b, x = map(int, input().split())
h = x / (a ** 2)
r = math.atan((b - h) * 2 / a)
if h < a / 2 * math.tan(r):
    r = math.atan(b ** 2 * a / 2 / x)
print("{:.10f}".format(math.degrees(r)))

Measured memory_bytes: 3060
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        //ある場所にある1を持ってきたい気持ちが生える
        //いや、まず動かせるのは2つ刻みなので
        //奇数番目だけ独立でソート、偶数番目だけ独立でソート
        //奇数番目の中の異端児は前の方に集める、偶数番目の中の異端児も前の方に…
        //そうするとswapでくいってできるので、またソート…
        //swapで解消できる不和は2なので、/2
        //だめなの?
        int n = int.Parse(Console.ReadLine());
        var a = Enumerable.Repeat(0, n).Select(_ => int.Parse(Console.ReadLine())).ToList();
        var ca = a.Compress().ToList();
        Console.WriteLine(ca.Where((x, y) => x % 2 != y % 2).Count() / 2);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static IEnumerable<int> Compress<T>(this IEnumerable<T> enumerable) where T : IComparable<T>
    {
        var dict = enumerable.OrderBy(x => x).Distinct().Select((x, y) => new Tuple<T, int>(x, y)).ToDictionary(x => x.Item1, x => x.Item2);
        return enumerable.Select(x => dict[x]);
    }
}


Measured memory_bytes: 29788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    int l[n];
    rep(i, n) {
        cin >> l[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
                int t[3];
                t[0] = l[i];
                t[1] = l[j];
                t[2] = l[k];
                sort(t, t + 3);
                if (t[2] < t[0] + t[1]) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program {

	static long mod = 1000000007;
	static int[] ans;
	static void Main(string[] args) {

		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

		//int n = int.Parse(Console.ReadLine());
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		int res = 0;


		int n = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		res = 3 * n * n;

			Console.WriteLine(res);
			return;

	}



	//	文字列strをindex番目からdで上書き
	static string strOverWrite(string str, int i, string s) {
		return str.Remove(i, s.Length).Insert(i, s);
	}

	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}


}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  
  int maxv = -2000000000;
  int minv = vec.at(0);
  
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, vec.at(i) - minv);
    minv = min(minv, vec.at(i));
  }
  
  cout << maxv << endl;
}




Measured memory_bytes: 3596
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

N = gete(int)

cur = [0] * 3

for _ in range(N):
    a, b, c = geta(int)
    prev = cur[:]
    cur[0] = max(prev[1], prev[2]) + a
    cur[1] = max(prev[2], prev[0]) + b
    cur[2] = max(prev[0], prev[1]) + c

print(max(cur))


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

const int MOD = 1000000007;
bool is_safe[100010];
int dp[100010];

int rec(int i) {
    if(dp[i] != -1) return dp[i];
    if(i == 0) return 1;
    int res = 0;
    if(is_safe[i-1]) res += rec(i-1);
    if(is_safe[i-2]) res += rec(i-2);
    return dp[i] = res % MOD;
}

int main() {
    int N, M; cin >> N >> M;
    for(int i = 0; i < 100010; ++i) {
        is_safe[i] = true;
        dp[i] = -1;
    }
    
    for(int i = 0; i < M; ++i) {
        int a; cin >> a;
        is_safe[a] = false;
    }
    
    cout << rec(N) << endl;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
 
int main(){
  ll i, j;
  ll n;
  cin >> n;
  cout << "A";
  if(n < 1200)
    cout << "B";
  else if(n < 2800)
    cout << "R";
  else
    cout << "G";
  cout << "C" << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


Int solve(vector<Int> A, vector<Int>B){
  const Int N = A.size();
  priority_queue<P> Q;
  for(Int i=0;i<N;i++) Q.emplace(B[i], i);

  Int res = 0;
  while(!Q.empty()){
    Int val, idx; tie(val, idx) = Q.top(); Q.pop();
    Int a = B[(idx-1+N)%N];
    Int b = B[idx];
    Int c = B[(idx+1)%N];
    Int target = A[idx];
    if(b == target) continue;
    if(b - a - c < target) return -1;
    Int nb = target + ((b - target) % (a + c));
    res += ((b - target) / (a + c));
    B[idx] = nb;
    if(nb != target) Q.emplace(nb, idx);

  }
  return res;

}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  vector<Int> A(N), B(N);
  cin>>A>>B;

  Int ans = solve(A, B);
  cout<<ans<<endl;

  return 0;
}


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

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

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

    long long int n, m;
    cin >> n >> m;

    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define akumanosuuji = 666;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n,d,x,ans=0;
    cin >> n >> d >> x;
    int a[n];
    rep(i,n){
        cin >> a[i];
        ans += (d+a[i]-1) / a[i];
    }
    cout << ans + x << endl;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int X;
  X = max(max(A, B), C);
  if ((3 * X - A - B - C) % 2 == 0) {
    cout << (3 * X - A - B - C) / 2 << endl;
  }
  else {
    cout << (3 * X + 3 - A - B - C) / 2 << endl;
  }
}


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


using namespace std;

const int N =1000;

typedef long long ll;

ll f[N][N];
ll a[N],s[N]; 

int main()
{
	int n;
	cin>>n;
	s[0]=0;
	for(int i=1;i<=n;i++)	{
		int x;
		cin>>x;
		s[i]+=s[i-1]+x;	
	}
	memset(f,0,sizeof(f));
	for(int len=2;len<=n;len++)
	{
		for(int i=1;i+len-1<=n;i++)
		{
			int j=i+len-1;
			f[i][j]=1e18;
			for(int k=i;k<j;k++)
			f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]+s[j]-s[i-1]);
		}
	}
	cout<<f[1][n]<<endl;
}

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

#define MAX 1000

using namespace std;

int lcs(string s1, string s2) {
    int C[MAX+1][MAX+1];
    int m = s1.size();
    int n = s2.size();
    for (int i = 0; i <= m; ++i) {
        C[i][0] = 0;
    }
    for (int j = 0; j <= n; ++j) {
        C[0][j] = 0;
    }

    for (int i = 1; i <= m; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (s1[i-1] == s2[j-1]) {
                C[i][j] = C[i-1][j-1] + 1;
            }
            else {
                C[i][j] = max(C[i][j-1], C[i-1][j]);
            }
        }
    }

    return C[m][n];
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s1, s2;
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}

Measured memory_bytes: 7052
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, k;
  int p = 1;
  cin >> N >> k;
  for (int i = 0; i<N; i++) {
    if (i == 0) {
      p *= k;
    }
    else {
      p *= k-1;
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF (1LL << 60)
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#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 sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 200005;

ll sm[MAX_N];

ll solve(int st, int ed) //[st,ed)の和
{
    return sm[ed]-sm[st];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        sm[i+1] = sm[i] + a[i];
    }
    ll ans = INF;
    for(int i=2;i<=n-2;i++){
        int l=1,h=i-1;
        while(h-l>1){
            int mid = (l+h)/2;
            if(solve(0,mid) < solve(mid, i)){
                l = mid;
            }else{
                h = mid;
            }
        }
        vector<pll> vec[2];
        ll u = solve(0,l), v = solve(l,i);
        vec[0].pb(pll(min(u,v),max(u,v)));
        u = solve(0,h), v = solve(h,i);
        vec[0].pb(pll(min(u,v),max(u,v)));
        //-------------------------------------------
        l=i+1,h=n-1;
        while(h-l>1){
            int mid = (l+h)/2;
            if(solve(i,mid) < solve(mid, n)){
                l = mid;
            }else{
                h = mid;
            }
        }
        u = solve(i,l), v = solve(l,n);
        vec[1].pb(pll(min(u,v),max(u,v)));
        u = solve(i,h), v = solve(h,n);
        vec[1].pb(pll(min(u,v),max(u,v)));
        rep(j,2){
            rep(k,2){
                cmn(ans,max({vec[0][j].fi,vec[0][j].se,vec[1][k].fi,vec[1][k].se})-min({vec[0][j].fi,vec[0][j].se,vec[1][k].fi,vec[1][k].se}));
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2560
package main
import (
  "fmt"
  "strconv"
)
func main() {
  var n int
  fmt.Scan(&n)
  str := strconv.Itoa(n)
  sum := 0
  for _, char := range str {
    num, _ := strconv.Atoi(string(char))
    sum += num
  }
  var result string
  if n%sum == 0 {
    result = "Yes"
  } else {
    result = "No"
  }
  fmt.Println(result) 
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, m, l;

int main(){
	cin >> n >> m >> l;
	cout << abs(n-m) + abs(m-l) + abs(n-l) - max(abs(n-m), max(abs(m-l), abs(n-l))) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define fi first
#define se second
using pii = pair<int,int>;
using ll = long long;
using vi = vector<int>;

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

    char s[1024];
    int w;

    cin >> s >> w;
    int len = strlen(s);
    for (int i=0; i<len; i+=w) cout << s[i];
    cout << endl;
}



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

const int N = 300, M = 30000, INF = 0x3f3f3f3f;

struct Edge {
	int to, res;
	Edge *next;
	Edge () {}
	Edge (int to, int res, Edge *next) : to (to), res (res), next (next) {}
}*head[N], pool[M], *pis = pool, *cur[N];

void AddEdge (int u, int v, int c) {
	head[u] = new (pis++) Edge (v, c, head[u]);
	head[v] = new (pis++) Edge (u, c, head[v]);
}

int h, w, d[N], s, t;
char ma[105][105];
bool vis[N];

queue<int>Q;
bool Bfs () {
	memset(vis, 0, sizeof vis);
	vis[s] = 1; int u; Q.push(s);
	while (!Q.empty ()) {
		u = Q.front(); Q.pop();
		for (Edge *now = head[u]; now; now = now -> next) if (now -> res && !vis[now -> to]) {
			d[now -> to] = d[u] + 1;
			vis[now -> to] = 1;
			Q.push (now -> to);
		}
	}
	return vis[t];
}

int Dfs (int u, int f) {
	if (u == t || !f) return f;
	int fellow = 0, D;
	for (Edge *&now = cur[u]; now; now = now -> next) if (d[now -> to] == d[u] + 1 && (D = Dfs (now -> to, min (f, now -> res)))) {
		fellow += D; f -= D;
		now -> res -= D; (pool + ((now - pool) ^ 1)) -> res += D;
		if (!f) break;
	}
	return fellow;
}

int main () {
	scanf("%d%d", &h, &w); s = h + w; t = s + 1;
	for (int i = 0; i < h; ++i) scanf("%s", ma[i]);
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (ma[i][j] == 'o') {
				AddEdge(i, j + h, 1);
			} else if (ma[i][j] == 'S') {
				AddEdge(s, i, INF);
				AddEdge(s, j + h, INF);
			} else if (ma[i][j] == 'T') {
				AddEdge(i, t, INF);
				AddEdge(j + h, t, INF);
			}
		}
	}
	int fellow = 0;
	while (Bfs()) {
		for (int i = 0; i <= t; ++i) cur[i] = head[i];
		fellow += Dfs(s, INF);
	}
	printf("%d\n", fellow >= INF ? -1 : fellow);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
using namespace std;
const int64_t MOD = 1e9 + 7;

int n;
vector<vector<bool>> M(100, vector<bool>(100));
vector<int> C(100), d(100), f(100), nt(100);
int tt;

int next(int u) {
	for (int i = nt.at(u); i < n; i++) {
		nt.at(u) = i + 1;
		if (M.at(u).at(i)) return i;
	}
	return -1;
}

void dfs_visit(int r) {
	for (int i = 0; i < n; i++) nt.at(i) = 0;

	stack<int> S;
	S.push(r);
	C.at(r) = 1;
	d.at(r) = ++tt;

	while (!S.empty()) {
		int u = S.top();
		int v = next(u);

		if (v != -1) {
			if (C.at(v) == 0) {
				C.at(v) = 1;
				d.at(v) = ++tt;
				S.push(v);
			}
		}
		else {
			S.pop();
			C.at(u) = 2;
			f.at(u) = ++tt;
		}
	}
}

void dfs() {
	for (int i = 0; i < n; i++) {
		C.at(i) = 0;
		nt.at(i) = 0;
	}
	tt = 0;

	for (int i = 0; i < n; i++) {
		if (C.at(i) == 0) dfs_visit(i);
	}

	for (int i = 0; i < n; i++) {
		cout << i + 1 << ' ' << d.at(i) << ' ' << f.at(i) << endl;
	}
}

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

	for (int i = 0; i < n; i++) {
		cin >> v >> k;

		for (int j = 0; j < k; j++) {
			int x;
			cin >> x;
			M.at(v - 1).at(x - 1) = true;
		}
	}

	dfs();

	return 0;
}


Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace No1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32( Console.ReadLine());
            string str = Console.ReadLine();
            string[] strs = str.Split(' ');
            ulong[] num = new ulong[(int)1e6];
            ulong sum = 0, tem = (Int64)1e9 + 7;
            for (var i = 0; i < strs.Length; i++)
            {
                num[i] = ulong.Parse(strs[i]);
               
            }
            ulong nums = 1;
            for (var i = 0; i < 64; i++)
            {
                ulong zero = 0, one = 0;
                for (var j=0;j<n;j++) 
                {
                    if (num[j] % 2 == 1)
                        one++;
                    else
                        zero++;
                    num[j] = num[j] / 2;
                }
                ulong b = zero * one;
                //Console.WriteLine(zero+" "+one+" "+nums);
                sum = (sum + (b % tem * nums % tem) % tem) %tem;
                nums = (nums * 2) % tem;

            }
            Console.WriteLine(sum%tem);

        }
    }
}


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

int main(){
    int n, cnt=0;
    cin >> n;
    vector<int> p(n);
    for(int i=0; i<n; i++){
        cin >> p.at(i);
    }

    for(int i=0; i<n-2; i++){
        if((p[i]<=p[i+1]&&p[i+1]<=p[i+2])||(p[i+2]<=p[i+1]&&p[i+1]<=p[i])){
            cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  string s;
  cin >> n >> s >> k;
  for(int i=0;i<n;i++){
    if(s.at(i)!=s.at(k-1)){
      s.at(i)='*';
    }
  }
 cout << s << endl;
}

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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int a = 1;
	int b = 0;
	int c = 0;
	char c0, c1;

#if INPUT_FROM_FILE
	//std::ifstream ifs("test.txt");
	FILE *fp = fopen("test.txt", "r");
#endif

	
#if INPUT_FROM_FILE
	while(fscanf(fp, "%c,%c", &c0, &c1) != EOF){
#else
	while(scanf("%c,%c", &c0, &c1) != EOF){
#endif
		if((c0 == 'A' && c1 == 'B') || (c0 == 'B' && c1 == 'A')){
			std::swap(a, b);
		}
		else if((c0 == 'A' && c1 == 'C') || (c0 == 'C' && c1 == 'A')){
			std::swap(a, c);
		}
		else{
			std::swap(b, c);
		}
			
	}

	if(a > 0){
		std::cout << "A" << std::endl;
	}
	else if(b > 0){
		std::cout << "B" << std::endl;
	}
	else{
		std::cout << "C" << std::endl;
	}
	return 0;
}



Measured memory_bytes: 3224
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();

        int i = 0;
        while(((X-1)*i +1 )<Y){
            i++;
        }
        System.out.println(i);
    }
}

Measured memory_bytes: 22612
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
  Scanner in=new Scanner(System.in);

  int n, sum;

  while(true){
  int count = 0;
  n = in.nextInt();
  sum = in.nextInt();

  if(n==0 && sum==0)break;

    for(int i=1;i<n-1;i++){
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      }
    System.out.println(count);
  }
  }
}

Measured memory_bytes: 26196
#include <stdio.h>
int main(void)
{
    char a[100];
    int c=0;
    int flg=1;
    int i,j;
    scanf("%s", a);
    for(i=0;a[i]!='\0';i++){
        c++;
    }
    for(i=c-1,j=0;i>=0,j<c;j++,i--){
        if(a[j]!=a[i]){
            flg=0;
            break;
        }

    }
    if(flg==1){
        printf("Yes");
    }else{
        printf("No");
    }
}

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

int main(){
  int n; cin>>n;
  vector<double> v(n);
  double tmp1,tmp2;
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.rbegin(),v.rend());
  while(v.size()>1){
    tmp1=v[v.size()-1];
    tmp2=v[v.size()-2];
    v.pop_back();
    v[v.size()-1]=(tmp1+tmp2)/2;
    //cout <<v[v.size()-1] <<endl;
  }
  cout <<v[0] <<endl;
}

Measured memory_bytes: 256
#include <queue>
#include <string>
#include <iostream>
using namespace std;
int main() {
  string cmd;
  priority_queue<int> Q;
  while(cin >> cmd && cmd != "end") {
    if(cmd == "insert") {
      int n; cin >> n;
      Q.push(n);
    }else if (cmd == "extract") {
      cout << Q.top() << endl;
      Q.pop();
    }
  }
}

Measured memory_bytes: 6924
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,hd[N],to[N],nx[N],du[N],tt;
void add(int u,int v){ //cout<<"add:"<<u<<" "<<v<<endl;
	nx[++tt]=hd[u]; to[hd[u]=tt]=v; du[v]++;
	nx[++tt]=hd[v]; to[hd[v]=tt]=u; du[u]++;
}
vector<int>h[N];
int pt[N],is[N];
void dfs(int u,int fa){ //cout<<u<<" "<<fa<<endl;
	int z=h[u].size(); pt[u]=0;
	for(int i=0;i<z;i++){
		int v=h[u][i]; if(v==fa) continue;
		dfs(v,u);
		if(pt[u]) add(pt[u],pt[v]),pt[u]=0;
		else pt[u]=pt[v];
	}
	if(!pt[u]) pt[u]=u;  
	if(!is[u]) is[u]=-1+(pt[u]==u)*2;
	else if((is[u]==1 && pt[u]!=u) || (is[u]==-1 && pt[u]==u)){
		//puts("-1");
		puts("IMPOSSIBLE");
		exit(0);
	}
}
int ans[N];
void work(){
	int rt=0;
	for(int i=1;i<=n;i++) h[i].clear();
	for(int x,i=1;i<=n;i++){
		scanf("%d",&x);
		if(~x) h[x].push_back(i),h[i].push_back(x);
		else rt=i;
	}
	dfs(rt,0);
	//if(!ans[pt[rt]]) ans[pt[rt]]=1;
	//else ans[pt[rt]]=-1;
	//puts("");
	//cout<<1<<endl;
}
void clr(int u){
	for(int e=hd[u];e;e=nx[e]){
		int v=to[e]; if(ans[v]) continue;
		ans[v]=-ans[u]; clr(v);
	}
}
int main()
{
	srand(time(0));
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(int p=0;p<2;p++) work();
	for(int i=1;i<=n;i++){
		if(~is[i] && !ans[i]) ans[i]=1;
		if(du[i]) clr(i);
	}
	puts("POSSIBLE");
	for(int i=1;i<=n;i++) printf("%d ",ans[i]); puts("");
	return 0;
}


Measured memory_bytes: 53504
#include <iostream>
#define MAXN 2020

using namespace std;

int n, s;
  long long valor[MAXN], peso[MAXN];
  long long dp[MAXN][MAXN];

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

  for(int i = 1; i <= n; i++){
    cin >> peso[i] >> valor[i];
  }
  for(int i = 1; i <= n; i++){
    for(int j = s; j >= 0; j--){
      dp[i][j] = dp[i - 1][j];
      if(j - peso[i] >= 0){
        dp[i][j] = max(dp[i - 1][j], valor[i] + dp[i - 1][j - peso[i]]);
      }
    }
  }
  cout << dp[n][s] << " ";
  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
  int n;
  cin>>n;
  vector<int>v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  vector<int>L(100005),R(100005);
  for(int i=0;i<n;i++){
     if(i%2==0){
      L[v[i]]++;
     }
     if(i%2!=0){
      R[v[i]]++;
    }
  }
  int ml=*max_element(L.begin(),L.end());
  int ml2=0;
  int mli=0;
  for(int i=0;i<100005;i++){
    if(L[i]==ml){mli=i;}
    if(L[i]!=ml){ml2=max(L[i],ml2);}
  }
  for(int i=0;i<100005;i++){
    if(i!=mli){ml2=max(L[i],ml2);}
  }
  
  int mr=*max_element(R.begin(),R.end());
  int mr2=0;
  int mri=0;
  for(int i=0;i<100005;i++){
    if(R[i]==mr){mri=i;}
    if(R[i]!=mr){mr2=max(R[i],mr2);}
  }
  for(int i=0;i<100005;i++){
    if(i!=mri){mr2=max(R[i],mr2);}
  }
  if(mli!=mri){cout<<n-ml-mr<<endl;}
  if(mli==mri){cout<<min(n-ml-mr2,n-mr-ml2)<<endl;}
  return 0;
}

Measured memory_bytes: 4556
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>

#define INF 1000000000;
#define MOD 1000000007;
typedef long long ll;
using namespace std;

int main()
{
    vector<int> A(3);
    for (auto&a : A) {
        cin >> a;
    }
    sort(A.begin(), A.end());
    int ans = 0;
    for (int i = 1; i < 3; i++) {
        ans += A[i] - A[i - 1];
    }
    cout << ans << endl;

}



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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int n, x[55], y[55];
map<ii, int> mp;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i] >> y[i];

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (i != j)
				mp[{x[i] - x[j], y[i] - y[j]}]++;

	int res = 0;
	for (auto it : mp)
		res = max(res, it.se);
	cout << n - res << endl;

	return 0;
}


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

typedef long long int ll;

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

	int n;
	cin >> n;
	int ac = 0, wa = 0, tle = 0, re = 0;
	for (int i = 0; i < n; i++){
		string s;
		cin >> s;
		if (s == "AC") ac++;
		else if (s == "WA") wa++;
		else if (s == "TLE") tle++;
		else if (s == "RE") re++;
	}

	printf("AC x %d\n", ac);
	printf("WA x %d\n", wa);
	printf("TLE x %d\n", tle);
	printf("RE x %d\n", re);
}

Measured memory_bytes: 3744
let calc n =
    let rec _calc n a =
        if n <= 1
        then a
        else
            match a with
              ((t, p) :: _) -> _calc (n - 1) ((2 * t + 3, 2 * p + 1) :: a)
            | _ -> [] in
    _calc n [(1, 1)];;

let solve table x =
    let rec _solve table x a =
        match table with
          [] -> (a + (if x <= 0 then 0 else 1))
        | ((t, p) :: rs) ->
                if x <= 1 + t
                then _solve rs (x - 1) a
                else _solve rs (x - 2 - t) (a + p + 1) in
    _solve table x 0;;



let () =
    let (n, x) = Scanf.scanf "%d %d" (fun n x -> n, x) in
    let table = calc n in
    print_int (solve table x);
    print_newline ();;



Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class Solve
{
    public static void Main(string[] args)
    {
        new ABC_C();
    }
}
public class ABC_A
{
    public ABC_A()
    {
        var s = Ex.Read;
        if (s[2] == s[3] && s[4] == s[5])
        {
            Ex.Cw("Yes");
        }
        else Ex.Cw("No");
    }
}
public class ABC_B
{
    public ABC_B()
    {
        var x = Ex.ReadLong;
        long ans = 0;
        ans += (x / 500) * 1000;
        x %= 500;
        ans += (x / 5) * 5;
        Ex.Cw($"{ans}");
    }
}
public class ABC_C
{
    public ABC_C()
    {
        var arr1 = Ex.ReadLongArray();
        //1周Kメートルの円形の湖があり
        var k = arr1[0];
        //その周りにN軒の家
        var n = arr1[1];

        //var r = k / Math.PI / 2;

        var arr = Ex.ReadLongArray();
        long[] a = new long[n];
        long prev = arr[0];
        for (long i = 1; i < n; i++)
        {
            var j = arr[i];
            a[i] = j - prev;
            prev = j;
        }

        a[0] = k - prev + arr[0];
        Array.Sort(a);

        long ans = 0;
        for (long i = 1; i < n; i++)
        {
            ans += a[i - 1];
        }
        Ex.Cw($"{ans}");
    }
}
public class ABC_D
{
    public ABC_D()
    {

    }
}
public class ABC_E
{
    public ABC_E()
    {

    }
}
public class ABC_F
{
    public ABC_F()
    {

    }
}
public static class Ex
{
    public static void Cw(string s)
    {
        Console.WriteLine(s);
    }

    public static string Read { get { return Console.ReadLine().Trim(); } }
    public static int ReadInt { get { return int.Parse(Read); } }
    public static long ReadLong { get { return long.Parse(Read); } }
    public static double ReadDouble { get { return double.Parse(Read); } }
    public static string[] ReadArray() { return Read.Split(' '); }
    public static int[] ReadIntArray() { return Read.Split(' ').Select(s => int.Parse(s)).ToArray(); }
    public static long[] ReadLongArray() { return Read.Split(' ').Select(s => long.Parse(s)).ToArray(); }
    public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n,k;
int w[100001];

typedef ll meguru_t;
const meguru_t MGRMX = LONG_MAX;
bool isOK(ll mid){
    int idx = 0;
    REP(i,k){
        ll p = 0;
        while(idx < n && p+w[idx] <= mid){   
            p += w[idx++];
        }
    }
    return idx == n;
}
meguru_t binary_search() {
    meguru_t ok = MGRMX, ng = 0;
    while (abs(ok-ng) > 1) {
        meguru_t mid = (ok + ng) / 2;
        //DEBUG(mid);
        if (isOK(mid)) ok = mid;
        else ng = mid;
    }

    return ok;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    
    cin>>n>>k;
    REP(i,n){
        cin>>w[i];
    }
    
    ll ans = binary_search();
    cout << ans << endl;
    return 0;
}


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

using namespace std;

long long solve(int a, int b){

    long long ret = 1;
    while(b--) ret *= a;
    return ret;

}

int main(){

    int d;

    while(cin >> d){

        long long ans = 0;

        for(int i = 1; i < 600 / d; ++i){
            ans += solve(d * i, 2) * d;
        }

        cout << ans << endl;

    }

}

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

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

  long m = n * (n + 1) / 2;
  if (sum % m) {
    cout << "NO" << endl;
    return 0;
  }

  long num = sum / m;
  long cnt = 0;

  vector<long> d(n);
  for (int i = 0; i < n; i++) {
    d[i] = a[(i + 1) % n] - a[i];
    d[i] -= num;
    if (d[i] == 0) {
      continue;
    }
    if (d[i] < 0 && (-d[i]) % n == 0) {
      cnt += (-d[i]) / n;
      continue;
    }
    cout << "NO" << endl;
    return 0;
  }

  if (cnt == num) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


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

#define ll long long
#define ar array

int main() {

    ios::sync_with_stdio(false);
	
	int n, r;
	
	cin >> n;
	
	if(n%2 == 0){
		r = pow(n/2, 2);
		cout << r << endl;
	}
	else{
		r=((n-1)/2)*((n-(n-1)/2));
		cout << r << endl;
	}
	
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static Scanner sc = new Scanner(System.in);
	public static int n;
	public static int[] score = new int[2];
	
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		while(read()){
			solve();
		}
	}

	
	public static boolean read(){
		n = sc.nextInt();
		score[0] = 0;
		score[1] = 0;
		
		if(n == 0){
			return false;
		}
		
		for(int i=0; i<n; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			if(a > b){
				score[0] += a;
				score[0] += b;
			} else if(a < b){
				score[1] += a;
				score[1] += b;
			} else{
				score[0] += a;
				score[1] += b;
			}
		}
		
		return true;
	}
	
	public static void solve(){
		System.out.println(Integer.toString(score[0]) + " " + Integer.toString(score[1]));
		
	}
	
	
	
}

Measured memory_bytes: 12000
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double PI = 3.1415926535898;
int main(){
	int a,b,x;
	scanf("%d%d%d",&a,&b,&x);
	if(x<=(a*a*b)/2){
		double side = 1.0*x/a*2/b;
		double ans = atan(side/b);
		printf("%lf\n",90.0-(ans/PI*180));
	} 
	else{
		double side = (1.0*a*a*b-x)/a*2/a;
		double ans = atan(side/a);
		printf("%lf\n",ans/PI*180);
	}
	return 0;
}


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

using namespace std;

int main(){
  string s;
  cin >> s;
  
  bool result = true;
  int n = s.size();
  for(int i = 0; i < n; i++){
    result = ((i % 2 == 0 && s[i] != 'L') || (i % 2 == 1 && s[i] != 'R'));
    if(!result) break;
  }
  
  cout << (result ? "Yes" : "No") << endl;
  
  return 0;
}

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

int main() {
	long long N, K, S;
	cin >> N >> K >> S;
	if (N - K + 1 <= S) {
		vector<long long> V(N - K + 1);
		for (int i = 0; i < N - K; i++) V[i] = 1;
		V[N - K] = S + K - N;
		for (int i = 0; i < N; i++) {
			cout << V[i % (N - K + 1)];
			if (i == N - 1) cout << endl;
			else cout << " ";
		}
		return 0;
	}
	else {
		vector<long long> ANS;
		for (int i = 0; i < K; i++) ANS.push_back(S);
		for (int i = K; i < N; i++) ANS.push_back(S + 1);
		for (int i = 0; i < N; i++) {
			cout << ANS[i];
			if (i == N - 1) cout << endl;
			else cout << " ";
		}
		return 0;
	}
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;

const int mx=200010;
const ll mod=1e9+7;

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

int main(){
  cin >> n;
  for(int i=1; i<=n; i++){cin >> a[i]; b[i]=a[i];}
  
  sort(b,b+mx);
  reverse(b,b+mx);
  
  if(b[0]==b[1]){
    for(int i=1; i<=n; i++){cout << b[0] << endl;}
    return 0;
  } else {
    for(int i=1; i<=n; i++){
      if(a[i]!=b[0]){
        cout << b[0] << endl;
      } else {
        cout << b[1] << endl;
      }
    }
    return 0;    
  }
  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define pi 3.1415926536
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int> s
#define lpair pair<LL, LL>
#define MP make_pair
#define INF 2147483647
#define _INF -2147483647
#define MM multimap
#define PB push_back
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    char s[4];
    cin >> s;
    if (s[0] == s[1])
        cout << "Bad";
    else if (s[1] == s[2])
        cout << "Bad";
    else if (s[2] == s[3])
        cout << "Bad";
    else if (s[3] == s[4])
        cout << "Bad";
    else
        cout << "Good";
    return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#define MOD 1000000007
typedef long long ll;
inline ll quick_pow(ll a, ll n)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}
struct Matrix
{
	ll arr[2][2];
	Matrix()
	{
		memset(arr, 0, sizeof(arr));
	}
	inline ll *operator [](const int &x)
	{
		return arr[x];
	}
	inline const ll *operator [](const int &x) const
	{
		return arr[x];
	}
	inline Matrix operator *(const Matrix &a) const
	{
		Matrix res;
		for (int i = 0; i < 2; i++)
		{
			for (int j = 0; j < 2; j++)
			{
				for (int k = 0; k < 2; k++)
					(res[i][k] += arr[i][j] * a[j][k]) %= MOD;
			}
		}
		return res;
	}
};
char str[1005][1005];
int main()
{
	// freopen("AGC003-F.in", "r", stdin);
	int n, m;
	ll k;
	scanf("%d%d%lld", &n, &m, &k);
	for (int i = 0; i < n; i++)
		scanf("%s", str[i]);
	int lr = 0, ud = 0, blk = 0, adj = 0;
	for (int i = 0; i < n; i++)
		lr += str[i][0] == '#' && str[i][m - 1] == '#';
	for (int i = 0; i < m; i++)
		ud += str[0][i] == '#' && str[n - 1][i] == '#';
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
			blk += str[i][j] == '#';
	}
	if (k == 1 || (lr && ud))
	{
		puts("1");
		return 0;
	}
	ll ans = quick_pow(blk, k - 1);
	if (lr)
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 1; j < m; j++)
				adj += str[i][j] == '#' && str[i][j - 1] == '#';
		}
	}
	else
	{
		for (int i = 1; i < n; i++)
		{
			for (int j = 0; j < m; j++)
				adj += str[i][j] == '#' && str[i - 1][j] == '#';
		}
	}
	Matrix res, trans;
	res[0][0] = adj;
	res[0][1] = blk;
	trans[0][0] = lr + ud;
	trans[1][0] = adj;
	trans[1][1] = blk;
	k -= 2;
	while (k)
	{
		if (k & 1)
			res = res * trans;
		trans = trans * trans;
		k >>= 1;
	}
	if (!lr && !ud)
		printf("%lld\n", ans);
	else
		printf("%lld\n", (ans - res[0][0] + MOD) % MOD);
	return 0;
}

Measured memory_bytes: 1152