akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,i,j,cnt,ans,op,le[2010],re[2010],q[2010],a[2010][2010],b[2010][2010];
char s[2010];
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%s",s+1);
		for(j=1;j<=m;j++)a[i][j]=(s[j]=='#');
	}
	for(i=2;i<=n;i++){
		cnt=0;q[0]=0;
		for(j=1;j<m;j++){
			if(a[i][j]!=a[i][j+1]&&a[i-1][j]!=a[i-1][j+1]||a[i][j]==a[i][j+1]&&a[i-1][j]==a[i-1][j+1])op=1;
			 else op=0;
			if(op)b[i][j]=b[i-1][j]+1;
			 else b[i][j]=0;
			//printf("%d %d %d\n",i,j,b[i][j]);
			while(cnt&&b[i][q[cnt]]>b[i][j])cnt--;
			le[j]=q[cnt];
			q[++cnt]=j;
		}
		cnt=0;q[0]=m;
		for(j=m-1;j;j--){
			while(cnt&&b[i][q[cnt]]>=b[i][j])cnt--;
			re[j]=q[cnt];
			ans=max(ans,(re[j]-le[j])*(b[i][j]+1));
			q[++cnt]=j;
			//printf("%d %d %d %d\n",i,j,le[j],re[j]);
		}
	}
	ans=max(ans,max(n,m));
	printf("%d",ans);
}

Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(ll i=a ; i<n ; i++)
#define r0 return 0;

int main()
{
   fastio
   int n;
   cin>>n;
   int x=n%10;
   if(x==2 || x==4 ||x==5 ||x==7 ||x==9)
   cout<<"hon"<<"\n";
   else if(x==3)
   cout<<"bon"<<"\n";
   else
   cout<<"pon"<<"\n";
}


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

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

int main(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    if(n>=s.size()){
        cout<<s;
    }else{
        for(int i=0;i<n;i++){
            cout<<s[i];
        }
        cout<<"...";
    }
    


    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int64_t> X(N), Y(N);
  vector<int64_t> XA, YA;
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
    XA.emplace_back(X[i]);
    YA.emplace_back(Y[i]);
  }

  sort(XA.begin(), XA.end());
  sort(YA.begin(), YA.end());

  int64_t res = (XA[N - 1] - XA[0]) * (YA[N - 1] - YA[0]);

  for (int xi = 0; xi < N; xi++) {
    for (int xj = xi + 1; xj < N; xj++) {
      for (int yi = 0; yi < N; yi++) {
        for (int yj = yi + 1; yj < N; yj++) {
          int cnt = 0;
          int64_t lx = XA[xi], rx = XA[xj];
          int64_t by = YA[yi], uy = YA[yj];

          for (int i = 0; i < N; i++) {
            if (lx <= X[i] && X[i] <= rx && by <= Y[i] && Y[i] <= uy) cnt++;
          }

          if (cnt >= K) res = min(res, (rx - lx) * (uy - by));
        }
      }
    }
  }

  cout << res << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        int n, m; cin>>n>>m;
        if(n == 0) return 0;
        vector<int> h(n), w(m);
        for(int i=0; i<n; i++) cin>>h[i];
        for(int i=0; i<m; i++) cin>>w[i];

        vector<int> hsum(n+10, 0), wsum(m+10, 0);
        for(int i=0; i<n; i++){
            hsum[i+1] = hsum[i] + h[i];
        }
        for(int i=0; i<m; i++){
            wsum[i+1] = wsum[i] + w[i];
        }

        map<int, int> H, W;
        for(int i=0; i<=n; i++){
            for(int j=i+1; j<=n; j++){
                H[hsum[j] - hsum[i]]++;
            }
        }
        for(int i=0; i<=m; i++){
            for(int j=i+1; j<=m; j++){
                W[wsum[j] - wsum[i]]++;
            }
        }

        ll ans=0;
        for(auto i:H){
            ans += i.second * W[i.first];
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 34336
#include<iostream>
#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>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
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)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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


string s;
int k;
int n;

int main() {

	cin >> k >> s;

	rep(i, s.size()) {
		if (i + 1 > k) {
			cout << "...";
			break;
		}
		else cout << s[i];
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cmath>

#include <list>
#include <queue>
#include <algorithm>

#define INF 1000000000

using namespace std;
using ll = long long;

int main(void)
{
    int n;
    int a[200000];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    int max = a[0];
    ll sum = 0;
    for (int i = 1; i < n; i ++) {
        if (a[i] >= max) {
            max = a[i];
        } else {
            sum += max - a[i];
        }
    }

    cout << sum;
    return
     0;
}

Measured memory_bytes: 4400
def main():
    s = input()
    min_dif = 100000
    for i in range(len(s) - 2):
        x = int(s[i:i+3])
        dif = 753-x
        if dif < 0:
            dif *= -1
        if dif < min_dif:
            min_dif = dif
    print(min_dif)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
sa = list(input())
sb = list(input())
sc = list(input())

tmp = sa.pop(0)
while True:

  if tmp == "a":
    if len(sa) == 0:
      print("A")
      exit()
    else:
      tmp = sa.pop(0)
  elif tmp == "b":
    if len(sb) == 0:
      print("B")
      exit()
    else:
      tmp = sb.pop(0)
  elif tmp == "c":
    if len(sc) == 0:
      print("C")
      exit()
    else:
      tmp = sc.pop(0)
  

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long n,a,b;
int main(){
    scanf("%lld%lld%lld",&n,&a,&b);
    long long sum=(n/(a+b))*a;
    n%=(a+b);
    sum+=min(n,a);
    printf("%lld\n",sum);
    return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> pic(H);
  for (int i = 0; i < H; i++)
    cin >> pic[i];
  for (int i = 0; i < W + 2; i++)
    cout << "#";
    cout << endl;
  for (int i = 0; i < H; i++)
    cout << "#" << pic[i] << "#" << endl;
  for (int i = 0; i < W + 2; i++)
  cout << "#";
  cout << endl;
}


Measured memory_bytes: 256
program main
integer :: a,b,c,k,sum = 0

read(*,*)a,b,c,k

if (a>=k) then
sum = k
else if (a<k .and. b>=(k-a)) then
sum = a
else
sum = a - (k - a -b)
end if

write(*,*) sum
end program main

Measured memory_bytes: 2856
#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#define PI 3.14159265358979323846264338327950L
#define ll long long
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long double n;
    cin >> n;
    string ans = "";
    while(n>0){
        n--;
        long long z = n;
        ans += 'a'+z%26;
        n = floor(n/26);
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}

Measured memory_bytes: 3768
using System;

namespace Computation
{
    class Circle
    {
        static void Main(string[] args)
        {
            var r = double.Parse(Console.ReadLine());
            var S = Math.PI * r * r;
            var R = 2 * Math.PI * r;
            Console.WriteLine(S + " " +R);
        }
    }
}

Measured memory_bytes: 9228
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
p = na()
m = p[0]
ans = 0
for i in range(n):
    #print(m, p[i])
    if m >= p[i]:
        ans += 1
    m = min(m, p[i])
print(ans)

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


vector<vector<int>> G;
int color[100050];
bool dfs(int u,int c){
    color[u] = c;
    for(int i = 0; i < G[u].size();i++){
        int v = G[u][i];
        if(color[v]==c)return false;
        if(color[v]==0 && !dfs(v,-c))return false;
    }
    return true;
}


int main(void){
    long long N,M;
    cin >> N >> M;
    int A,E;

    G.assign(N,vector<int>());
    for(int i = 0; i < M;i++){
        cin >> A >> E;
        A--;
        E--;
        G[A].push_back(E);
        G[E].push_back(A);
    }
    long long B = 0, W = 0;

    if(dfs(0,1)){
        for(int i = 0; i < N;i++){
            if(color[i] == 1){
                B++;
            }else if(color[i] == -1){
                W++;
            }
        }
        cout << B*W-M<<endl;   
    }else{
        cout << N*(N-1)/2 - M <<endl;
    }
        
        
        
        
    
    
}

Measured memory_bytes: 9376
n,m,q = map(int, input().split())
rq=list()
for i in range(q):
    a,b,c,d = map(int, input().split())
    a-=1
    b-=1
    rq.append([a,b,c,d])
ans=0
def solve(A,ans):

    if len(A)==n:
        score=0
        for a,b,c,d in rq:
            if A[b]-A[a]==c:
                score+=d
        ans=max(ans,score)
        return ans
    else:
        for i in range(1,m+1):
            if len(A)>=1 and A[-1]>i:
                continue
            B = A + [i]
            ans = max(ans,solve(B,ans))
        return ans

ans= solve(list(),ans)
print(ans)



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

int main() {
    long long R;
    cin >> R;
    
    cout << R * 2 * 3.141592 << endl;
}

Measured memory_bytes: 3764
n=int(input())
a=[int(i) for i in input().split()]
av=0
for i in range(n):
    av+=a[i]
av/=n
ans=0
anss=abs(av-a[0])
for i in range(1,n):
    if anss>abs(av-a[i]):
        ans=i
        anss=abs(av-a[i])
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

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

  if(x<y) {
    tmp = x;
    x = y;
    y = tmp;
  }

  while(x%y!=0){
    tmp = x;
    x = y;
    y = tmp % y;
  }
  printf("%d\n", y);
  return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
int n, a[100010];
ll calc(ll s) {
  ll sum = 0, res = 0;
  for (int i = 0; i < n; ++i, s *= -1) {
    sum += a[i];
    if (sum * s > 0) continue;
    if (s > 0)
      res += (-sum + s), sum += (-sum + s);
    else
      res += (sum - s), sum += -(sum - s);
  }
  return res;
}
int main() {
  cin >> n;
  rep(i, n) cin >> a[i];
  cout << min(calc(1), calc(-1)) << endl;
  return 0;
}


Measured memory_bytes: 640
n=gets.to_i
aa=gets.chomp.split.map(&:to_i)
aa=aa.map.with_index { |a, i| a-i-1 }
aa.sort!
b=n.even? ? aa[n/2-1,2].inject(:+)/2 : aa[n/2]
aa = aa.map { |a| (a-b).abs }
puts aa.inject(:+)


Measured memory_bytes: 20992
K=int(input())
ans=0

def gcd2(a,b):
    if b==0:
        return a
    return gcd2(b,a%b)
def gcd3(a,b,c):
    return gcd2(gcd2(a,b),c)

for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i==j==k:
                ans+=gcd3(i,j,k)
            elif i==j or j==k:
                ans+=gcd3(i,j,k)*3
            else:
                ans+=gcd3(i,j,k)*6

print(ans)


Measured memory_bytes: 77412
from fractions import gcd
def lcm(a, b):
    return a*b//gcd(a, b)

def count(a, b, x):
    start = a + (a-a%x)%x
    end = b - b%x
    return max((end-start)//x + 1, 0)

A, B, C, D = map(int, input().split())
l = lcm(C, D)
ans = B - (A-1)
ans -= count(A, B, C) + count(A, B, D) - count(A, B, l)
print(ans)


Measured memory_bytes: 5048
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int H=stdIn.nextInt();
		int M=stdIn.nextInt();
		int h=stdIn.nextInt();
		int m=stdIn.nextInt();
		int K=stdIn.nextInt();
		int a=H*60+M,b=h*60+m;
		System.out.println(b-K-a);
	}
}


Measured memory_bytes: 35756
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

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>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n, k; cin >> n >> k;
    vint x(n); vin(x);
    int ans = 0;
    rfor(d, x) {
        ans  += 2 * min(abs(d), abs(k - d));
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;
  vi a(n),b(n);
  REP(i,n) cin>>a[i];


  vi c(1000001);

  for(ll i=0;i<n;i++){
    ll num=a[i];
    if (c[num]>=2)continue;

    for(ll j=1;j<=1000000;j++){
      num=a[i]*j;
      if (num>1000000)break;
      c[num]++;
    }
  }


  for(ll i=0;i<n;i++){
    if (c[a[i]]==1)ans++;
    //cout<<c[a[i]]<<endl;
  }



  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 14344
#include <bits/stdc++.h>
#include <iomanip>
#define M 100000
#define MAX 1000000001
#define MIN -100000000
#define mod 998244353 
#define ss second
#define ff first
#define ll long long int
#define pb push_back
#define ld double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

int main(){
	int n;
	cin>>n;
	int a[n],fr[1000001] = {0};
	for(int i=0;i<n;i++){
		cin>>a[i];
		fr[a[i]]++;
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		int temp = a[i];
		bool check = true;
		for(int j=1;j*j<=temp;j++){
			if(temp%j == 0){
				if(j == a[i]){
					if(fr[j] > 1){
						check = false;
						break;
					}
				}
				else if(fr[j] > 0){
					check = false;
					break;
				}
				int second = temp/j;
				if(second == temp){
					if(fr[second] > 1){
						check = false;
						break;
					}
				}
				else{
					if(fr[second] > 0){
						check = false;
						break;
					}
				}

			}
		}
		if(check)
			ans++;
	}
	cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 8308
#include <iostream>
#include <cstdio>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int a, b, c;
	while(cin >> a >> b >> c) {
		bool f[11];
		rep(i,11) {
			f[i] = 0;
		}
		f[a] = f[b] = f[c] = 1;
		int cnt = 0;
		rep2(i,1,11) {
			if(f[i]) continue;
			rep2(j,1,11) {
				if(i == j || f[j]) continue;
				if(a + b + i <= 20) cnt++;
			}
		}
		if(cnt >= 21) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int main()
{
  long long n,count=0,i,j;
  cin>>n;
  long long  a[n];
  for(i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(i=0;i<n-1;i++)
  { 	if(a[i]>a[i+1])
      {count+=(a[i]-a[i+1]);
      a[i+1]=a[i];}
    }
  cout<<count;
return 0;
}


Measured memory_bytes: 4712
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k,n;
  cin>>k>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  int res;
  res=min(a.at(n-1)-a.at(0),k+a.at(0)-a.at(1));
  for(int i=1;i<n-1;i++){
    res=min(k-a.at(i)+a.at(i-1),res);
    res=min(res,k+a.at(i)-a.at(i+1));
  }
  cout<<res<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 500001
#define NIL -1
typedef struct node{
  int left;
  int right;
  int key;
  int p;
  int leftid;
  int rightid;

}Node;
Node node[MAX];
int root=NIL;
void inorder(int);
void preorder(int);
void addTree(int n,int num){
  int tmp;
  //rootが空の場合
  if(node[n].key==root){
    root=n;
    node[root].key=num;
    
  }
  else{
  tmp=root;

  while(1){
    if(node[tmp].key>num){
      if(node[tmp].left!=NIL){
	tmp=node[tmp].leftid;
      }
      else{
	node[tmp].left=num;
	node[tmp].leftid=n+1;
	node[n+1].key=num;
	
	break;
      }
    }
    else{
      if(node[tmp].right!=NIL){
	tmp=node[tmp].rightid;
	
      }
      else{
	node[tmp].right=num;
	node[n+1].key=num;
	node[tmp].rightid=n+1;
	break;
      }
    }
  }
  
  node[n].p=tmp;
  
  }
}
int main(){
  int num,i,n,l=0,tmp;
  char name[100];
  scanf("%d",&n);
 for(i=0;i<MAX;i++){//初期化
    node[i].p=NIL;
    node[i].left=NIL;
    node[i].right=NIL;
    node[i].key=NIL;
    
  }


 for(i=0;i<n;i++){
    scanf("%s",name);
    if(name[0]=='i'){
      scanf("%d",&num);
      addTree(l,num);
      l++;
      }
      
   else if(name[0]=='p'){
    inorder(root);
   printf("\n");
   preorder(root);
   printf("\n");
      
    }
  }
 
 
 
  return 0;
}
void inorder(int t){
  if(node[t].left!=NIL){
    inorder(node[t].leftid);
  }
    printf(" %d",node[t].key);
  if(node[t].right!=NIL){
    inorder(node[t].rightid);
  }
}
void preorder(int t){
 
      printf(" %d",node[t].key);
  if(node[t].left!=NIL){
    preorder(node[t].leftid);
  }
  if(node[t].right!=NIL){
    preorder(node[t].rightid);
  }
}




Measured memory_bytes: 13416
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


double dist[1002];
int n;
long long x[1002], y[1002], r[1002];




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

	cin >> x[0] >> y[0] >> x[1] >> y[1];
	r[0] = r[1] = 0;
	cin >> n;
	for (int i = 2; i < n + 2; i++) {
		cin >> x[i] >> y[i] >> r[i];
	}
	rep(i, n + 2)dist[i] = 1e100;
	dist[0] = 0;

	priority_queue<pair<double, int>> pq;
	pq.emplace(0.0, 0);
	while (!pq.empty()) {
		double d;
		int u;
		tie(d, u) = pq.top();
		d = -d;
		pq.pop();
		if (dist[u] + 1e-20 < d)continue;

		for (int i = 1; i < n + 2; i++) {
			double nd = d + max(0.0, sqrt((x[u] - x[i])*(x[u] - x[i]) + (y[u] - y[i])*(y[u] - y[i])) - r[u] - r[i]);
			if (nd + 1e-20 < dist[i]) {
				dist[i] = nd;
				pq.emplace(-nd, i);
			}
		}
	}
	printf("%.9f\n", dist[1]);

	return 0;
}

Measured memory_bytes: 4464
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(null);
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            var c = int.Parse(line[2]);
            var d = int.Parse(line[3]);
            var ans = false;

            if (Math.Abs(a - c) <= d) ans = true;
            else if (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d) ans = true;

            if (ans) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

struct Edge{
    long long src, dst, weight, capacity;
    Edge(): src(0), dst(0), weight(0), capacity(0) {}
    Edge(long long s, long long d, long long w): src(s), dst(d), weight(w) {}
    Edge(long long s, long long d, long long w, long long c): src(s), dst(d), weight(w), capacity(c) {}
};

class Graph{
public:
    long long size;
    vector<vector<Edge>> node;
    Graph(long long n): size(n), node(n) {}
    void addEdge(long long s, long long d, long long w = 1){
        node[s].emplace_back(s, d, w);
        node[d].emplace_back(d, s, w);
    }
};

// Bipartite graph
ll bfs(Graph &g, ll sn, ll n){
    vi num(n, 0);
    queue<ll> que;
    que.push(sn);
    num[sn] = 1;
    ll maxVertex = -1;

    // その時点での頂点から直接到達可能な頂点に+1の番号を振る
    // 矛盾が生じた時点で-1を返す
    while(que.size()){
        auto node = que.front();
        que.pop();
        for(auto &edge: g.node[node]){
            // 未訪問なら
            if(num[edge.dst] == 0){
                num[edge.dst] = num[node] + 1;
                que.push(edge.dst);
                chmax(maxVertex, num[edge.dst]);
            }
            // 既に追加済みなら
            else{
                // 隣接部分と集合番号が一致したら矛盾
                if(num[edge.dst] == num[node]) return -1;
            }
        }
    }

    return maxVertex;
}   

int main(){
    Init();
    // n; 頂点数, minEdge, minNode; 次数が最も少ないノード
    ll n;
    cin >> n;
    Graph g(n);
    vector<string> s(n);
    rep(i, n){
        // 隣接リストの入力
        cin >> s[i];
        // 次数のカウントと辺の追加
        ll cnt = 0;
        rep(j, n){
            if(s[i][j] == '0') continue;
            cnt++;
            if(j <= i) continue;
            g.addEdge(i, j, 1);
        }
    }

    // 次数が最も少ないノードを始点として番号付けしていく
    ll ans = -2;
    for(ll i=0; i<n; i++) chmax(ans, bfs(g, i, n));
    cout << ans << endl;
}

Measured memory_bytes: 4996
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();
		long[][] cakes = new long[3][n];
		for (int i = 0 ; i < n ; i++) {
			cakes[0][i] = sc.nextLong();
			cakes[1][i] = sc.nextLong();
			cakes[2][i] = sc.nextLong();
		}
		int[][] rule = {{1,1,1},{1,1,-1},{1,-1,1},{-1,1,1},{1,-1,-1},{-1,1,-1},{-1,-1,1},{-1,-1,-1}};

		long max = 0;
		for (int i = 0 ; i < 8 ; i++) {
			int[] rule1 = rule[i];
			long tmp = 0;
			Long[] tmps = new Long[n];
			for (int j = 0 ; j < n ; j++) {
				tmps[j] = cakes[0][j] * rule1[0] + cakes[1][j] * rule1[1] + cakes[2][j] * rule1[2];
			}
			Arrays.sort(tmps, Comparator.reverseOrder());
			for (int j = 0 ; j < m ; j++) tmp += tmps[j];
			max = Math.max(tmp, max);
		}
		System.out.println(max);
	}
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin >> n){
    set<string> st;
    string s;
    rep(i,n){
      cin >> s;
      st.insert(s);
    }
    bool f = false;
    cin >> m;
    rep(i,m){
      cin >> s;
      if(st.find(s) == st.end()){
        cout << "Unknown " + s<< endl;
      }
      else{
        if(f){
          cout << "Closed by " + s<<endl;
        }
        else{
          cout << "Opened by " + s << endl;
        }
        f = !f;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3252
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for i in range(A+1):
	for j in range(B+1):
		for k in range(C+1):
			if (500*i+100*j+50*k) == X: count += 1

print(count)

Measured memory_bytes: 3064
#include <stdio.h>

int gcd(int a, int b) 
{
   while (b > 0) {
      int n;
      n = a % b;
      a = b;
      b = n;
   }
   return a;
}

int main() {

    int a, b, c;

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

    c = gcd(a, b);

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

    return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  ll x;
  cin >> x;
  ll res = (x / 11) * 2;
  if (x % 11 == 0) {
    // 処理なし
  } else if (x % 11 <= 6) {
    res += 1;
  } else {
    res += 2;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
d = []
for i in range(len(a)):
    d.append([a[i], i+1])
    
d = sorted(d)

print(' '.join([str(s) for z,s in d]))

Measured memory_bytes: 27300
n=int(input())
a=list(map(int,input().split()))
n=sum(list(map(lambda x: x<0,a)))
c0=sum(list(map(lambda x: x==0,a)))
if c0:
    print(sum(list(map(abs,a))))
    exit(0)
if n&1:
    print(sum(list(map(abs,a)))-2*min(list(map(abs,a))))
else:
    print(sum(list(map(abs,a))))


Measured memory_bytes: 14252
#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 <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int prefs, cs;
    cin >> prefs >> cs;
    vector<map<int,int>> cities(prefs+1);
    for(int i = 0; i < cs; i++) {
        int pref, year;
        cin >> pref >> year;
        cities[pref][year] = i;
    }

    vector<pii> ans(cs);
    for(int i = 1; i <= prefs; i++) {
        int idx = 1;
        for(auto pair: cities[i]) {
            int label = pair.second;
            ans[label] = make_pair(i, idx++);
        }
    }

    for(int i = 0; i < cs; i++) {
        printf("%06d%06d\n", ans[i].first, ans[i].second);
    }
    return 0;
}

Measured memory_bytes: 13436
def comb(n, r):
    if r<0 or r>n:
        return 0
    r=min(r, n-r)
    return g1[n]*g2[r]*g2[n-r]%MOD

MOD=10**9+7
MAXN=2000000+10
g1=[1, 1]
g2=[1, 1]
inverse=[0, 1]

for i in range(2, MAXN+1):
    g1.append((g1[-1]*i)%MOD)
    inverse.append(-inverse[MOD%i]*(MOD//i)%MOD)
    g2.append((g2[-1]*inverse[-1])%MOD)

X, Y=map(int, input().split())
ans=0
if (X+Y)%3==0:
    a=(2*X-Y)//3
    b=(2*Y-X)//3
    ans=comb(a+b, a)
print(ans)

Measured memory_bytes: 134072
M1,D1=map(int,input().split())
M2,D2=map(int,input().split())

if M1!=12:
    if M1<M2:
        print(str(1))
    else:
        print(str(0))
else:
    if M1>M2:
        print(str(1))
    else:
        print(str(0))

Measured memory_bytes: 3060
from collections import Counter

n=int(input())
d=list(map(int,input().split()))
dic=Counter(d)
MOD=998244353
ans=1
if d[0]!=0 or dic[0]!=1: print(0)
else:
    for i in range(1,max(dic.keys())+1):
        ans*=pow(dic[i-1],dic[i],MOD)
        ans%=MOD
    print(ans)

Measured memory_bytes: 24324
import sys
input = sys.stdin.readline

def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b

def main():
    n, x = (int(i) for i in input().split())
    town = (int(i) for i in input().split())

    distance = (abs(x-y) for y in town)
    res = next(distance)
    for d in distance:
        if d % res != 0:
            res = gcd(res, d)

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 11468
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
print(''.join([i[0].upper() for i in rs_()]))

Measured memory_bytes: 63468
def q(a,k):
 d[a]=k
 for b in t[a]:
  if'-1'!=b:q(b,k+1)
def n(a,k):
 h[a]=max(h[a],k)if a in h else k
 if'-1'!=p[a]:n(p[a],k+1)
t,p,s,d,h={},{},{},{},{}
for _ in[0]*int(input()):
 x,y,z=input().split()
 t[x]=set([y,z])-set(['-1'])
 p[y]=p[z]=x
 s[y],s[z]=z,y
r=(set(t)-set(p)).pop()
p[r]=s[r]='-1'
q(r,0)
for i in t:
 if not t[i]:n(i,0)
for i in map(str,sorted(map(int,t))):
 print(f"node {i}: parent = {p[i]}, sibling = {s[i]}, degree = {len(t[i])}, depth = {d[i]}, height = {h[i]}, {'root'if d[i]==0else'internal node'if t[i]else'leaf'}")


Measured memory_bytes: 5628
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int ans = 0;
		
		for(int i=1;i<=n;i++) {
			int a = scan.nextInt();
			if(i%2==1 && a%2==1) {
				ans++;
			}
		}
		
		System.out.println(ans);
		
		
		
	}
	
	
	public static int gcd(int x,int y) {
		if(x%y == 0) {
			return y;
		}else {
			return gcd(y,x%y);
		}
	}
}
 

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

string s, t, s_prime, t_prime;
vector<char> s_vec, t_vec;

int main() {
    cin >> s >> t;
    s_vec = vector<char>(s.begin(), s.end());
    t_vec = vector<char>(t.begin(), t.end());
    sort(s_vec.begin(), s_vec.end());
    sort(t_vec.begin(), t_vec.end(), greater<char>());
    s_prime = string(s_vec.begin(), s_vec.end());
    t_prime = string(t_vec.begin(), t_vec.end());
    cout << (s_prime < t_prime ? "Yes" : "No" ) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	//入力
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}

	//all: 全方向
	vector<vector<int>> all(H, vector<int>(W)),
		L(H, vector<int>(W)), R(H, vector<int>(W)),
		D(H, vector<int>(W)), U(H, vector<int>(W));

	//左上から攻める
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				L[i][j] = 0;
				U[i][j] = 0;
				continue;
			}

			if (j == 0) {//左端
				L[i][j] = 1;
			}
			else {
				L[i][j] = L[i][j - 1] + 1;
			}


			if (i == 0) {//上端
				U[i][j] = 1;
			}
			else {
				U[i][j] = U[i - 1][j] + 1;
			}

		}
	}

	//右下から攻める
	for (int i = H - 1; i >= 0; i--) {
		for (int j = W - 1; j >= 0; j--) {
			if (S[i][j] == '#') {
				R[i][j] = 0;
				D[i][j] = 0;
				continue;
			}
			if (j == W - 1) {//右端
				R[i][j] = 1;
			}
			else {
				R[i][j] = R[i][j + 1] + 1;
			}
			if (i == H - 1) {//下端
				D[i][j] = 1;
			}
			else {
				D[i][j] = D[i + 1][j] + 1;
			}
		}
	}

	//total
	int max_total = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				all[i][j] = 0;
			}
			else {
				all[i][j] = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3;
			}

			//最大値更新
			if (max_total < all[i][j]) {
				max_total = all[i][j];
			}
		}

	}
	cout << max_total;
	return 0;
}

Measured memory_bytes: 82816
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(In));
        }

        public long Min(params long[] a)
        {
            var min = a[0];
            for (int i = 1; i < a.Length; i++)
            {
                if (min > a[i]) min = a[i];
            }
            return min;
        }

        public long Max(params long[] a)
        {
            var max = a[0];
            for (int i = 1; i < a.Length; i++)
            {
                if (max < a[i]) max = a[i];
            }
            return max;
        }

        public void Solve(ConsoleInput input)
        {
            var n = input.ReadInt;
            var l = input.ReadLongArray(n);

            if (Max(l) < l.Sum() - Max(l))
                WriteLine("Yes");
            else
                WriteLine("No");

            //Solve(input);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private readonly char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            _separator = separator;
            _stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13396
n=int(input())
b=n%10
if (b==2)or (b==4 )or (b==5) or (b==7) or(b==9):
    print("hon")
elif(b==0) or(b== 1) or(b== 6) or(b== 8):
    print("pon")

else:
    print("bon")

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define endl '\n'
#define MOD 1000000007
#define MOD2 998244353

using namespace std;
typedef long long int ll;

int main(void)
{
	fast;
	#ifndef ONLINE_JUDGE
	// freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
	#endif

	int n; cin >> n;
	int c1 = 0, c2 = 0, c3 = 0;
	int a, b; cin >> a >> b;
	for (int i = 0; i < n; ++i)
		{
			int x; cin >> x;
			if (x <= a) ++c1;
			else if (x <= b) ++c2;
			else ++c3;
		}
	cout << min({c1, c2, c3});
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,v,n,i;
    cin>>a>>b;
    v=a+b;
    if(a%3==0 or b%3==0 or v%3==0)
    {
        cout<<"Possible"<<endl;
    }
    else{
    cout<<"Impossible"<<endl;
    }


    return 0;
}


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

#define _LL long long

int main()
{
    _LL n;
    cin >> n;
    _LL ans = 0;
    for( _LL k = 1; k <= n; k++ )
    {
        _LL num = n / k;
        ans += num * (k + k * num) / 2;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define MAX 1e9+7
#define MIN -1e9-7
#define int long long
#define endl "\n"
#define s(n) scanf("%d",&n)
#define mem memset(a, 0, sizeof(a))
#define minimum(a)	*min_element(a.begin(), a.end())
#define maximum(a)	*max_element(a.begin(), a.end())
typedef vector<int> vi;
typedef vector<string> vs;
/*
* * * * * * * * * * * * * * * * * * * * * *
*       ☆꧁𝓑𝓐𝓒𝓚_𝓛𝓞𝓖꧂☆              **
*                                        ***
* * * * * * * * * * * * * * * * * * * * *****
*/ 

int32_t main()
{
  string s;
  cin>>s;
  int n=s.size()-1;
  if(s[n]!='s')
  {
	  s+="s";
  } 
  else
  {
	  s+="es";
  }
  cout<<s<<endl;
return 0;

}




Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
   
   string s;
   cin >> s;
   
   bool ans = true;
   REP(i,s.size()){
      if(i%2==1){
         if(s[i]=='R') ans = false;
      }else{
         if(s[i]=='L') ans = false;
      }
   }
   
   if(ans){
      cout << "Yes\n";
   }else{
      cout << "No\n";
   }
   
   return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++) {
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  int min=0;
  for(int i=0;i<N;i++) {
    min += (a[0]-a[i])*(a[0]-a[i]);
  }
  for(int key=a[0]+1;key<=a[N-1];key++) {
    int ans=0;
    for(int j=0;j<N;j++) {
      ans += (key-a[j])*(key-a[j]);
    }
    if(min>ans) min=ans;
  }
  cout << min << endl;
}

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

int main() {
  int A,B;
  cin >> A >> B;

  if ((A + B) % 2 == 0) {
    cout << (A + B) /2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,mn=INT_MAX;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>arr[i];
    }
    for(int i=1; i<=n; i++)
    {
        int x=0,y=0;
        for(int j=1; j<=i; j++)
            x+=arr[j];
        for(int j=i+1; j<=n; j++)
            y+=arr[j];
        int z=abs(x-y);
        mn=min(mn,z);
    }
    cout<<mn<<endl;



    return 0;
}


Measured memory_bytes: 3616
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
using ll = long long int;

const int MAXP = 310;
ll N, K, MOD, dp[MAXP+5][MAXP+5], comb[MAXP+5][MAXP+5];

ll mod_pow(ll n, ll k) { return k ? mod_pow(n*n%MOD, k/2) * ((k&1)?n:1) % MOD : 1; }
void init() {
    for(int i=0; i<=MAXP; i++) {
        comb[i][0] = 1;
        for(int j=1; j<=i; j++) {
            comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % MOD;
        }
    }
}

ll nCr(ll n, ll r) {
    return (n < r or r < 0) ? 0 : comb[n][r];
}

ll solve(ll n, ll x) {
    if(x > K) return 0;
    if(dp[n][x] != -1) return dp[n][x];
    if(n == 1) return dp[n][x] = K-x+1;
    
    ll ans = 0;
    for(int k=1; k<n; k++) {
        ll v1 = solve(k, x+1);
        ll v2 = solve(n-k, x);
        ll v3 = solve(n-k, x+1);

        ll m1 = v1, m2 = (v2 - v3 + MOD) % MOD, m3 = nCr(n-2, k-1);
        (ans += m1 * m2 % MOD * m3 % MOD) %= MOD;
    }
    return dp[n][x] = (ans + solve(n, x+1)) % MOD;
}

int main() {
    cin >> N >> K >> MOD;
    init();
    fill(dp[0], dp[N+2], -1);
    cout << (solve(N+1, 0) - solve(N+1, 1) + MOD) % MOD << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define req(i, j, n) for(int i = j; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
ll h;
  cin>>h;
  ll n;
  cin>>n;
  ll d[n+1];
  ll ans=0;
  for(int i=1;i<=n;i++){
    cin>>d[i];
    ans+=d[i];}
  
  if(ans>=h){
    cout<<"Yes"<<endl;}
  else{
    cout<<"No"<<endl;}
  
  return 0;
  
  

}

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


int main() {
	
	string s;
	cin >> s;
	int cnt;
	for (int i=0; i<3; i++){
		if(s.at(i)=='o') cnt++;
	}
	cout << 700 + 100 * cnt << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
S = gets.chomp.chars
list = Array.new(S.size)
loop_l = nil
last_loop_l = nil
S.each.with_index do |ch, i|
  if ch == 'R'
    if loop_l == nil
      loop_l = i
      last_loop_l = i
    else
      last_loop_l = i
    end
  elsif ch == 'L'
    if loop_l != nil
      (last_loop_l..i).each do |j|
        list[j] = [0, j == i ? :left : :right]
      end
      (last_loop_l - 1).downto(loop_l) do |j|
        c, _ = list[j + 1]
        list[j] = [c + 1, :right]
      end
      loop_l = last_loop_l = nil
    else
      c, _ = list[i - 1]
      list[i] = [c + 1, :left]
    end
  end
end
ans = Array.new(S.size) { 0 }
(0...(S.size)).each do |i|
  distance, direction = list[i]
  if direction == :right
    start = i + distance
    if distance.odd?
      ans[start + 1] += 1
    else
      ans[start] += 1
    end
  else
    start = i - distance
    if distance.odd?
      ans[start - 1] += 1
    else
      ans[start] += 1
    end
  end
end
puts ans.join(' ')


Measured memory_bytes: 19324
n = int(input())
x = list(map(int, input().split()))

import copy

cp = copy.deepcopy(x)
cp.sort()
x_l = cp[n//2 - 1]
x_r = cp[n//2]

for ele in x:
    if ele <= x_l:
        print(x_r)
    else:
        print(x_l)


Measured memory_bytes: 25228
# coding: utf-8
# Your code here!
import math
nums = []
nums = input().split(" ")
num1 = int(nums[0])
num2 = int(float(nums[1])*1000)

 
ans = str(num1*num2)
if len(ans) < 4:
    print(0)
else:
    print(ans[:-3])

#print(format(float(nums[1]), '.20f'))
#print(round(float(nums[1]),2))

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> a(90);
  a.at(0) = 2LL;
  a.at(1) = 1LL;
  
  for (int i = 0; i < 88; i++) a.at(i + 2) = a.at(i + 1) + a.at(i);
  
  cout << a.at(N) << endl;
}


Measured memory_bytes: 3608
from collections import defaultdict
import heapq
n = int(input())
global S, Q, l
S = [0]
Q = [(0, 0)]
l = [1000000 for _ in range(n)]
l[0] = 0
w_graph = [defaultdict(int) for _ in range(n)]
graph = [[] for _ in range(n)]
G = [None] * n
def input_graph(n):
  for i in range(n):
    node_id, k, *v_list = list(map(int, input().split()))
    G[i] = [(v, c) for v, c in zip(v_list[::2], v_list[1::2])]

heapq.heapify(Q)
def dijkstra():
  c = 0
  while Q and c < 10:
    u_c, u = heapq.heappop(Q)
    for v, v_c in G[u]:
      """if v not in S:
        S.append(v)
        l[v] = l[u] + v_c
        heapq.heappush(Q, (l[v], v))"""
      if  (l[v] > l[u] + v_c):
        l[v] = l[u] + v_c
        heapq.heappush(Q, (l[v], v))


if __name__ == "__main__":
  input_graph(n)
  dijkstra()
  for i, c in enumerate(l):
    print(i, c)


Measured memory_bytes: 69284