akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
int main(void){
	//実家のような二分探索🏠👪
	int n,P,i;cin>>n>>P;
	vector<tuple<llint,llint,llint>> hito(n);
	llint gen=0;
	for(i=0;i<n;i++){
		cin>>get<1>(hito[i])>>get<2>(hito[i]);
		get<0>(hito[i])=(100-P)*get<1>(hito[i])+P*get<2>(hito[i]);
		gen-=P*get<2>(hito[i]);
	}
	sort(hito.rbegin(),hito.rend());
	for(i=0;i<n;i++){
		if(gen>=0){break;}
		gen+=get<0>(hito[i]);
	}
	cout<<i<<endl;
	RE;
}

Measured memory_bytes: 2688
from math import fabs
N=int(input())
pos=list(map(int,input().split()))
pos.insert(0,0)
pos.insert(N+1,0)
total_len=0
for i in range(N+1):
    total_len+=fabs(pos[i+1]-pos[i])
    

for i in range(N):
    total=total_len-fabs(pos[i+1]-pos[i])-fabs(pos[i+2]-pos[i+1])+fabs(pos[i+2]-pos[i])
    print(int(total))
    

Measured memory_bytes: 14048
n = int(input())
Dict = {}
for i in range(n):
  Str = input()
  if Str in Dict:
    Dict[Str]+=1
  else:
  	Dict[Str] = 0 
List = list(Dict.values())
Max = max(List)
Dict_sorted = sorted(Dict.items(), key=lambda x:x[0])
for i,j in Dict_sorted:
  if j ==Max:
    print(i)


Measured memory_bytes: 48220
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int worst = 0;
		int maxPlayer = 0;

		for (int i=0; i<N; i++){
			int A = sc.nextInt();
			int B = sc.nextInt();
			if (worst < A){
				worst = A;
				maxPlayer = A + B;
			}
		}
		System.out.println(maxPlayer);
	}
}


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

int main(){
    int N,K; cin >> N >> K;
    vector<int> v(N+1);
    rep(i,K){
        int d; cin >> d;
        rep(j,d){
            int a; cin >> a;
            v[a]++;
        }
    }

    ll res = 0;
    for(int i=1;i<=N;i++){
        if(v[i]==0) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 3640
a = input()
s = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
if a in s:
    print('a')
else:
    print('A')

Measured memory_bytes: 61600
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<int> x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
    }

    map<pair<int, int>, int> mp;

    rep(i, n) {
        rep(j, n) {

            if(i == j) {
                continue;
            }

            int A = x[i] - x[j];
            int B = y[i] - y[j];

            mp[make_pair(A, B)]++;

        }
    }

    int t = 0;
    for(auto& p : mp) {
        t = max(t, p.second);
    }

    cout << n-t << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;
const double PI=3.14159265359;

int main(){
	string s;
	int w;
	cin>>s;
	cin>>w;
	for(int i=0;i<s.size();i++){
		if(i%w==0)cout<<s[i];
	}
	cout<<endl;
	return 0;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	vector<int>X(N),Y(N);
	for (int i = 0; i < N; i++){
		cin >> X[i];
		Y[i] = X[i];
	}
	sort(Y.begin(), Y.end());

	
	for (int i = 0; i < N; i++){
		if (X[i] < Y[N / 2]) {
			cout << Y[N / 2] << endl;
		}
		else if (X[i] >= Y[N / 2]) {
			cout << Y[N / 2 - 1] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

/* DP */
template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

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


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(), K = in();
    vector<double> p(N+1);
    p[0] = 0;
    REP(i,N)p[i+1] =p[i] + in() + 1;
    double answer = 0;
    REP(i,N - K + 1){
        chmax(answer,p[i+K] - p[i]);
    }
    cout << answer/2 << "\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>  
using namespace std;  
#define _for(i,a,b) for(int i=a;i<=b;i++)  
int n,k;  
int main(int argc, char const *argv[])  
{  
    long long ans = 0;  
    cin>>n>>k;  
    int g = 0;  
    if(k==0)cout<<(long long)n*n<<endl;  
    else  
    {  
        for(int i=k+1;i<=n;i++)  
        {  
            int now = i - k;  
            int num = n/i;  
            int xx = num*i;  
            int kk = n-xx;  
            int gg = 0;  
            if(kk>=k)gg = kk-k+1;  
            ans+=gg;  
            ans+=now*num;  
        }  
        cout<<ans<<endl;          
    }  
  
    return 0;  
}

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

typedef vector<int > vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
#define sz(a)  int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define forn(i,n) for(int i=0;i<n;++i)
#define foru(i,n) for(int i=1;i<=n;++i)
#define fortr(i,v) for(auto &i:v)
#define set(n) __builtin_popcount(n)
#define ll long long

int maxima=0;

int dfs(int v,vi A[],int nodes[],bool visited[]) 
{
    visited[v] = true;
    for (int i=0;i<A[v].size();++i) 
    {
    	int u=A[v][i];
		if (!visited[u])
		{
            nodes[v]=max(dfs(u,A,nodes,visited)+1,nodes[v]);
		}
		else
		{
			nodes[v]=max(nodes[u]+1,nodes[v]);
		}
    }
    maxima=max(maxima,nodes[v]);
    return(nodes[v]);
}

int main()
{
	int n,m,x,y;
	cin>>n>>m;

	vi A[n+1];

	bool visited[n+1];
	int nodes[n+1];
	foru(i,n)
	{
		visited[i]=false;
		nodes[i]=0;
	}
	forn(i,m)
	{
		cin>>x>>y;
		A[x].pb(y);
		nodes[x]=1;
	}

	foru(i,n)
	{
		if(!visited[i])
			dfs(i,A,nodes,visited);
	}
	cout<<maxima<<endl;

}

Measured memory_bytes: 8960
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    a, b, c, k = map(int, input().split())
    if k <= a:
        print(k)
    elif a < k <= a + b:
        print(a)
    elif a + b < k:
        print(a - (k - a - b))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

int n;
long long x, y, ans;
double d;

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

    cin >> n >> d;
    
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        if (hypot(x, y) <= d) {
            ans++;
        }
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3780
S=input()
u = int(S[0:2])
l = int(S[2:4])

if u >= 1 and u <= 12:
    if l >= 1 and l <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif l >=1 and l <= 12:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3060
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		String s = sc.next();
		
		// 計算
		long result = 0;
		int[] sumR = new int[n+1];
		int[] sumG = new int[n+1];
		int[] sumB = new int[n+1];
		for(int i = 0; i < n; i++){
		    char a = s.charAt(i);
		    if(a == 'R'){
		        sumR[i+1] += sumR[i] + 1;
		        sumG[i+1] += sumG[i];
		        sumB[i+1] += sumB[i];
		    }
		    if(a == 'G'){
		        sumR[i+1] += sumR[i];
		        sumG[i+1] += sumG[i] + 1;
		        sumB[i+1] += sumB[i];
		    }
		    if(a == 'B'){
		        sumR[i+1] += sumR[i];
		        sumG[i+1] += sumG[i];
		        sumB[i+1] += sumB[i] + 1;
		    }
		}
		for(int i = 0; i < n; i++){
		    for(int j = i+1; j < n; j++){
		        char a = s.charAt(i);
		        char b = s.charAt(j);
		        if(a == b) continue;
		        if((a == 'R' && b == 'G') || (a == 'G' && b == 'R')){
		            result += sumB[n]-sumB[j+1];
		        }
		        if((a == 'G' && b == 'B') || (a == 'B' && b == 'G')){
		            result += sumR[n]-sumR[j+1];
		        }
		        if((a == 'B' && b == 'R') || (a == 'R' && b == 'B')){
		            result += sumG[n]-sumG[j+1];
		        }
		        if(j-i+j < n && s.charAt(j-i+j) != a && s.charAt(j-i+j) != b) result--;
		    }
		}
		
		// 出力
		System.out.println(result);
	}
	
}



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

int main(){
    int n, t,a;
    cin>>n>>t>>a;
    vector<int> h(n);
    double closest = INFINITY;
    int ans = 0;
    for(int i=0;i<n;i++){
        cin>>h.at(i);
        if(closest> abs(a-(t-h.at(i)*0.006))){
            closest= abs(a-(t-h.at(i)*0.006));
            ans = i;
        }
    }
    cout<<ans+1<<endl;
    
}


Measured memory_bytes: 256
from time import time
from random import randrange
start = time()
d = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(d):
    s.append(list(map(int, input().split())))
t = []
v = 0
last = [-1]*26
for i in range(d):
    bst = -10**10
    for j in range(26):
        tmp = s[i][j]
        for k in range(26):
            if j!=k:
                tmp -= c[k]*(i-last[k])
        if tmp>bst:
            bst = tmp
            bst_idx = j
    last[bst_idx] = i
    t.append(bst_idx)
    v += s[i][bst_idx]
    for j in range(26):
        v -= c[j]*(i-last[j])
mx = v
while time()-start<1.8:
    newt = t[:]
    nd = randrange(d)
    now = newt[nd]
    nq = randrange(25)
    newt[nd] = nq if nq<now else nq+1
    v = 0
    last = [-1]*26
    for i in range(d):
        v += s[i][newt[i]]
        last[newt[i]] = i
        for j in range(26):
            v -= c[j]*(i-last[j])
    if v>mx:
        mx = v
        t = newt
for i in t:
    print(i+1)

Measured memory_bytes: 9784
#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;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

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

vector<int> dp(mx,inf);
vector<int> a(1010),b(1010);
int h,n;

int rec(int k){
  if(k<=0){ return dp[0]=0; }
  if(dp[k]!=inf){ return dp[k]; }
  int res=inf;
  rep(i,n){
    res = min(res, rec(k-a[i])+b[i]);
  }
  return dp[k]=res;
}

int main(){
  cin >> h >> n;
  rep(i,n){ cin>>a[i]>>b[i]; }

  int ans = rec(h);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

ll dp[112345][15]; //dp[i][j] till i, mod result is j
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string inp;
    cin >> inp;
    
    if(inp[0] == '?'){
        rep(i, 10){
            dp[0][i] = 1;
        }
    }else{
        dp[0][ (inp[0]- '0')] = 1;
    }
    
    rep(i, inp.size()){
        if(i == 0) continue;
        
        if(inp[i] == '?'){
            rep(j, 13){
                rep(k, 10){
                    dp[i][(j * 10 + k)%13] += dp[i-1][j];
                    dp[i][(j * 10 + k)%13] %= MOD;
                }
            }
        }else{
            rep(j, 13){
                dp[i][ (j*10+ (inp[i] - '0') ) % 13 ] += dp[i-1][j];
                dp[i][ (j*10+ (inp[i] - '0') ) % 13 ] %= MOD;
            }
        }
    }
    
    cout << dp[inp.size() - 1][5] << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 12752
#include<bits/stdc++.h>
using namespace std;
#define what_is(x) cerr<<#x <<" is "<<x<<endl;
#define ll long long 
#define gcd(a,b) __gcd(a,b)
#define pi 2*acos(0.0)
//use emplace_back() instead of push_back()
template<typename T>
void print(T t)
{
	for(const auto& e:t)cout<<e<<" ";
	cout<<endl;
}
ll nod(ll n) 
{ 
    return floor(log10(n) + 1); 
}  
ll pfact(ll n)
{
	ll cnt=0;
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			cnt++;
			while(n%i==0)
			{
				n=n/i;
			}
		}
	}
	if(n!=1) cnt++;
	return cnt;
}
bool isprime(ll n)
{
	ll ch=true;
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)ch=false;
	}
	return ch;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
	cin>>n>>k;
	vector<ll>a(n);
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	if(k==1)
	{
		cout<<a[0]<<endl;
		return 0;
	}
	map<ll,ll>m;
	ll x=a[0];
	ll i=1,mod,st,tmpf=0;
	ll tmp=k;
	while(1)
	{		
		if(m[x])
		{
			mod=i-m[x];
			st=m[x];
			break;
		}
		m[x]=i;
		tmp--;
		if(tmp==0)
		{
			tmpf=1;
			break;
		}
		x=a[x-1];
		i++;		
	}	
	if(tmpf)
	{
		cout<<x<<endl;
		return 0;
	}
	k=k-st;
	k=k%mod;	
	for(ll i=0;i<k;i++)
	{
		x=a[x-1];
	}
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 14788
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,n=1,k;
	char a[1001],c;
	while((c=getchar())!='\n')
	{
		a[n++]=c;
	}
	scanf("%d",&k);
	for(i=1;i<n;i++)
	{
		if(i%k==1||k==1)
			printf("%c",a[i]);	
	}
	return 0;
}

Measured memory_bytes: 256
m, k = map(int, input().split())
l = int(2 ** (m + 1))
p = 2 ** m
if m == 0 or m == 1:
    if k == 0:
        if m == 0:
            print('0 0')
        else:
            print('0 0 1 1')
    else:
        print('-1')
else:
    if k >= p:
        print('-1')
    else:
        ans = []
        tmp = list(range(p))
        tmp.remove(k)
        ans.extend(tmp)
        ans.append(k)
        ans.extend(list(reversed(tmp)))
        ans.append(k)
        print(*ans)


Measured memory_bytes: 16240
a,b = map(int,input().split())
num_list = list(map(int,input().split()))
num_list.sort(reverse=1)
ans_list = []
for i in range(b-1):
  ans_list.append(abs(num_list[i]-num_list[i+1]))
#print(ans_list)
ans_list.sort(reverse=1)
#print(ans_list)
ans = sum(ans_list[a-1:])
print(ans)

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

int main()
{
	string s;
	while (cin >> s, s != "#") {
		int n = s.size();
		vector<int> c(n), d(n - 1);
		for (int i = 0; i < n; i++) {
			switch (s[i]) {
			case '1':
			case '4':
			case '7':
				c[i] = 1;
				break;
			case '2':
			case '8':
				c[i] = 2;
				break;
			case '3':
			case '6':
			case '9':
				c[i] = 3;
				break;
			}
		}
		for (int i = 0; i < n - 1; i++) {
			if (c[i + 1] - c[i] > 0) {
				d[i] = 1;
			}
			else if (c[i + 1] == c[i]) {
				d[i] = 0;
			}
			else {
				d[i] = -1;
			}
		}
		int r1 = 0, r2 = 0, s1 = 0, s2 = 1;
		for (int i = 0; i < n - 1; i++) {
			if (s1 == 0) {
				if (d[i] >= 0) {
					s1 = 1 - s1;
				}
				else {
					r1++;
				}
			}
			else if (d[i] <= 0) {
				s1 = 1 - s1;
			}
			else {
				r1++;
			}
			if (s2 == 0) {
				if (d[i] >= 0) {
					s2 = 1 - s2;
				}
				else {
					r2++;
				}
			}
			else if (d[i] <= 0) {
				s2 = 1 - s2;
			}
			else {
				r2++;
			}
		}
		cout << min(r1, r2) << endl;
	}
	return 0;
}

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

/* editorial */

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

    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<long long> A(X);
    vector<long long> B(Y);
    vector<long long> C(Z);
    for (int i = 0; i < X; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < Y; i++)
    {
        cin >> B[i];
    }
    for (int i = 0; i < Z; i++)
    {
        cin >> C[i];
    }
    sort(A.begin(), A.end(), greater<long long>());
    sort(B.begin(), B.end(), greater<long long>());
    sort(C.begin(), C.end(), greater<long long>());

    vector<long long> AB;
    for (int i = 0; i < X; i++)
    {
        for (int j = 0; j < Y; j++)
        {
            AB.push_back(A[i] + B[j]);
        }
    }
    sort(AB.begin(), AB.end(), greater<long long>());

    vector<long long> ABC;
    for (int i = 0; i < min(K, (int)AB.size()); i++)
    {
        for (int j = 0; j < min(K, Z); j++)
        {
            ABC.push_back(AB[i] + C[j]);
        }
    }
    sort(ABC.begin(), ABC.end(), greater<long long>());

    for (int i = 0; i < K; i++)
    {
        cout << ABC[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 43240
#include <stdio.h>

int main(void){
    int n, i;
    scanf("%d", &n);
    long a[n];
    long sum = 0;

    for(i = 0; i < n; i++)
        scanf("%ld", &a[i]);

    for(i = 1; i < n; i++){
        if(a[i - 1] > a[i]){
            sum += a[i - 1] - a[i];
            a[i] += (a[i - 1] - a[i]);
        }
    }

    printf("%ld\n", sum);

    return 0;
}

Measured memory_bytes: 3288
def resolve():
	import math
	A, B, H, M = map(int, input().split())
	l = (360/60)*M # long、弧度法：angle
	s = (360/12)*H + (360/12/60)*M # short
	theta = max(l, s) - min(l, s)
	theta = min(theta, 360-theta)
	ans = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(theta)))
	print(ans)
resolve()

Measured memory_bytes: 9512
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long int lli;


int main(void) {
    while(1) {
        vector<pair<lli,string>> dict;
        map<string,lli> max;
        int n,q;
        cin >> n >> q;
        if(!n) break;

        for(int i=0; i<n; i++) {
            string name;
            lli base, west;
            cin >> name >> base >> west;
            dict.push_back(pair<lli,string>(west-base+1, name));
            max[name] = base;
        }
        sort(begin(dict),end(dict));
        for(int i=0; i<q; i++) {
            lli y;
            cin >> y;
            auto it = upper_bound(begin(dict), end(dict), pair<lli,string>(y, string("\xFF")));

            if(it == dict.end())
                it = dict.begin() + (dict.size()-1);
            else if(it == dict.begin()) {
                cout << "Unknown" << endl;
                continue;
            }
            else
                it--;

            if((y-it->first+1) > max[it->second])
                cout << "Unknown" << endl;
            else
                cout << it->second << ' ' << y-(it->first)+1 << endl;
        }

    }
    return 0;
}

Measured memory_bytes: 3240
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define __int64 long long
int t[600000];
int n;
int a[211111];

int main(){
	cin>>n;
	int l=200000,r=200001;
	
	rep(i,n){
		cin>>a[i];
		if(i%2==(n%2)){
			t[r]=a[i];			
			r++;
		}
		else{
			t[l]=a[i];
			l--;
		}
	}
	
	for(int i=l+1;i<r;i++){
		cout<<t[i];
		if(i==r-1)cout<<endl;
		else cout<<" ";
	}
	return 0;
}

Measured memory_bytes: 3712
ENV[A='RUBY_THREAD_VM_STACK_SIZE']||exec({A=>?5*8},'ruby',$0)
F=->c{H[c].all?{|e|Z[e]?Z[c]-Z[e]!=0:(Z[e]=1^Z[c];F[e])}}
N,M=gets.split.map &:to_i;H=Hash.new{|h,k|h[k]=[]};Z={1=>0}
$<.map{|e|a,b=e.split.map &:to_i;H[a]<<b;H[b]<<a}
p (F[1]?(x,y=Z.partition{|k,v|v>0};x.size*y.size):N*~-N/2)-M

Measured memory_bytes: 111052
N,M,K= (int(i) for i in input().split())  
ok=0

for j in range(M+1):
 for i in range(N+1):
  if j*N+i*(M-2*j)==K or i*M+j*(N-2*i)==K:
    ok=1
 
if ok==0:
 print("No")
else:
 print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    string s;
    
    cin >> s;
        
    s.erase(unique(s.begin(), s.end()), s.end());
    
    cout << s.size() - 1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


int main(void)
{
    IOS
    int k; cin >> k;
    vector<ll> r;
    FOR(i,1,10) r.push_back(i);

    int prev = 0;
    while(r.size() < k) {
        int sz = r.size();
        FOR(i,prev,sz) {
            string s = to_string(r[i]);
            int x = s.back() - '0';
            FOR(j,x-1,x+2) {
                if (j < 0 || j > 9) continue;
                string t = s + to_string(j);
                r.push_back(stoll(t));
            }
        }
        prev = sz;
        //cerr << prev << endl;
    }

    sort(ALL(r));
    //REP(i,100) cerr << r[i] << endl;

    OUT(r[k-1])


    return 0;
}

Measured memory_bytes: 2420
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<stw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;
using ll = long long int;
using dis = pair<int,int>;
using Graph = vector<vector<dis>>;

int main(void){
    int N;cin>>N;
    Graph G(N+1);
    for(int i=1;i<N;i++){
        int u,v,w;cin>>u>>v>>w;
        G[u].push_back(make_pair(v,w));
        G[v].push_back(make_pair(u,w));
    }

    vector<int> dist(N+1,-1);
    dist[1] = 0;
    
    queue<int> que;
    que.push(1);
    
    while(!que.empty()){
        int v = que.front();
        que.pop();

        for(auto next_v : G[v]){
            if(dist[next_v.first]!=-1) continue;

            if(next_v.second%2==0){
                if(dist[v]) dist[next_v.first] = 1;
                else dist[next_v.first] = 0;
            }else{
                if(dist[v]) dist[next_v.first] = 0;
                else dist[next_v.first] = 1;
            }
            que.push(next_v.first);
        }
    }
    for(int i=1;i<=N;i++){
        cout << dist[i] << endl;
    }
}

Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000
#define ll long long
using namespace std;
int main()
{
    int N;
    cin >> N;
    double ans = 0;
    vector<pair<int, pair<int, int>>> c;
    rep(i, N)
    {
        int a = 0, b = 0;
        cin >> a >> b;
        c.push_back(make_pair(i, make_pair(a, b)));
    }
    sort(c.begin(), c.end());
    int j = 1, a = N;
    while (a != 1)
    {
        j *= a;
        a--;
    }
    do
    {
        rep(i, N - 1)
        {
            ans += (sqrt(pow(c[i + 1].second.first - c[i].second.first, 2) + pow(c[i + 1].second.second - c[i].second.second, 2)));
        }
    } while (next_permutation(c.begin(), c.end()));
    cout << std::fixed << std::setprecision(10) << ans / j << "\n";
}

Measured memory_bytes: 256
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    x = n%k
    ans = min(n,abs(x-k),x)
    print(ans)
    return

if __name__=='__main__':
    n,k = IL()
    solve()

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

int main()
{
long long int n,k;
cin>>n>>k;
vector<int> v(n),cint(n),cext(n);
for(int i=0;i<n;i++)
cin>>v[i];
reverse(v.begin(),v.end());
for(int i=0;i<n;i++)
{
int co=0;
for(int j=i+1;j<n;j++)
{
if(v[i]<v[j])
co++;
}
cint[i]=co;
}
for(int i=0;i<n;i++)
{
int co=0;
for(int j=0;j<n;j++)
{
if(i!=j)
{
if(v[i]<v[j])
co++;
}
}
cext[i]=co;
}
long long int res=0;
long long int mod=1000000007;
long long int m=(((k-1)*k)/2)%mod;
for(int i=0;i<n;i++)
{
res+=(cext[i]*m)%mod+(cint[i]*k)%mod;
res%=mod;
}
cout<<res<<endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v[505];
bool can[505];
int main(){
    int n,m,q;
    scanf("%d %d %d",&n,&m,&q);
    //cin>>n>>m>>q;
    int t1,t2;
    for(int i=0;i<m;i++){
        scanf("%d %d",&t1,&t2);
        v[t1].push_back(t2);
    }
    for (int j = 0; j < 505; ++j) {
        sort(v[j].begin(),v[j].end());
    }
 
 
    for(int i=0;i<q;i++){
        scanf("%d %d",&t1,&t2);
        int sum=0;
        for(int k=t1;k<=t2;k++){
            //int l=ma[k].size();
            if(!can[k]){
                sort(v[k].begin(),v[k].end());
                can[k]=1;
            }
            vector<int>::iterator up=upper_bound (v[k].begin(), v[k].end(), t2);
            sum+=(up- v[k].begin());
        }
        printf("%d\n",sum);
 
    }
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
int main() {
int D, G, cnt = 100000;
cin >> D >> G;

vector<int> p(D), bonus(D);
for (int i = 0; i < D; ++i) {
        cin >> p[i];
        cin >> bonus[i];
}

for (int i = 0; i < pow(2, D); ++i) {
        int sm = 0;
        int c = 0;
        for (int j = 0; j < D; ++j) {
                if ((i >> j) & 1) {
                        c += p[j];
                        sm += 100 * (j + 1) * p[j] + bonus[j];
                }   
        }   
        if (sm >= G) {
                cnt = min(cnt, c); 
                continue;
        }   
        bool flag = false;
        for (int k = D - 1; k >= 0; --k) {
                if (!((i >> k) & 1)) {
                        for (int l = 0; l < p[k] - 1; ++l) {
                                c++;
                                sm += 100 * (k + 1); 
                                if (sm >= G) {
                                        cnt = min(cnt, c); 
                                        flag = true;
                                        break;
                                }   
                        }   
                        if (flag) break;
                }   
        }   
}
cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if (b % a == 0) {
        println(a + b)
    }
    else {
        println(b - a)
    }
    return 0;
}

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

// グローバル変数
ll a, b;

// 関数プロトタイプ
void input();
void solve();

int main(void)
{
    input();
    solve();  
}

// 標準入力
void input() {
    cin >> a >> b;
}

void solve() {
    cout << a * b << endl;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template <class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template <class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

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

  int c = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == '1') {
      c++;
    }
  }
  p(c);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
static const int INF = 1e9+7;
using namespace std;

int main(){
    int e;
    while(1){
        cin>>e;
        int ans = INF;
        if(e == 0) break;
        for(int y = 0; y<=1000; y++){
            for(int z= 0; z<=100; z++){
                int x = e-y*y-z*z*z;
                if(x >= 0){
                    ans = min((x+y+z),ans);
                }
           }
        }    
        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 3044
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        String str[]=br.readLine().split(" ");
        int n=Integer.parseInt(str[0]);
        int m=Integer.parseInt(str[1]);
        long k=Long.parseLong(str[2]);
        str=br.readLine().split(" ");
        long arr1[]=new long[n];
        for(int i=0;i<n;i++)
        arr1[i]=Long.parseLong(str[i]);
        str=br.readLine().split(" ");
        long arr2[]=new long[m];
        for(int i=0;i<m;i++)
        arr2[i]=Long.parseLong(str[i]);
        long pref1[]=new long[n];
        long pref2[]=new long[m];
        TreeSet<Long> ts1=new TreeSet<>();
        TreeSet<Long> ts2=new TreeSet<>();
        TreeMap<Long,Integer> tmap1=new TreeMap<>();
        TreeMap<Long,Integer> tmap2=new TreeMap<>();
        pref1[0]=arr1[0];
        tmap1.put(pref1[0],0);
        ts1.add(pref1[0]);
        for(int i=1;i<n;i++)
        {
            pref1[i]=pref1[i-1]+arr1[i];
            ts1.add(pref1[i]);
            tmap1.put(pref1[i],i);
        }
        pref2[0]=arr2[0];
        tmap2.put(pref2[0],0);
        ts2.add(pref2[0]);
        for(int i=1;i<m;i++)
        {
            pref2[i]=pref2[i-1]+arr2[i];
            ts2.add(pref2[i]);
            tmap2.put(pref2[i],i);
        }
        int max=0;
        int cnt=0;
        for(long i:ts1)
        {
            long temp=k-i;
            if(ts2.floor(temp)!=null)
            {
                long temp2=ts2.floor(temp);
                //pw.println(temp2);
                int ind=tmap2.get(temp2);
                max=Math.max(max,cnt+ind+2);
            }
            else
            {
                if(i<=k)
                max=Math.max(max,cnt+1);
            }
            cnt++;
        }
        cnt=0;
        for(long i:ts2)
        {
            long temp=k-i;
            if(ts1.floor(temp)!=null)
            {
                long temp2=ts1.floor(temp);
                int ind=tmap1.get(temp2);
                max=Math.max(max,cnt+ind+2);
            }
            else
            {
                if(i<=k)
                max=Math.max(max,cnt+1);
            }
            cnt++;
        }
        pw.println(max);
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 123208
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int A,B;
    cin >> A >> B;
    if(A - 2 * B >= 0){
        cout << A - 2 * B << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
result = [0]*3
while True:
    a, b, c = sorted(map(int, input().split()))
    if a + b <= c:
        print(sum(result),*result)
        break
    flag = a ** 2 + b ** 2 - c*c
    if flag == 0:
        result[0] +=1
    elif flag >0:
        result[1] += 1
    else:
        result[2] += 1


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = numeric_limits<ll>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

ll K[4100][4100],x[4100][4100];
ll sum[4100];

//i~jテ」ツ?ョテ・ツ陳?
ll sum_w(int i,int j){
  return sum[j]-sum[i-1];
}

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

  int n;
  cin >> n;
  ll w[n+1];
  for(int i=1;i<=n;i++){
    cin >> w[i];
  }
  sum[0]=0;
  for(int i=1;i<=n;i++){
    sum[i]=sum[i-1]+w[i];
  }
  for(int i=0;i<n+1;i++){
    for(int j=0;j<n+1;j++){
      K[i][j]=0;
    }
  }
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j){
      x[i][j] = 99999999;
      x[i][i] = 0;
      K[i][i] = i;
    }
  }
  for(int k=1;k<n;k++){
    for(int i=1;i+k<=n;i++){
      int j=i+k;
      ll tmp = INF;
      for(ll r=K[i][j-1];r<=K[i+1][j];r++){
        ll c=x[i][r] + x[r+1][j]+sum_w(i,j);
        if(c<=tmp){
          tmp=c;
          K[i][j]=r;
        }
      }
      x[i][j]=tmp;
    }
  }
  cout << x[1][n] << endl;
}

Measured memory_bytes: 259532
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){
  ll n, m;
  cin >> n >> m;
  vll a(n);
  rep (i, n){cin >> a[i];}
  map<ll, ll> b;
  ll sum = 0;
  rep (i, n){
    sum += a[i];
    int x_temp = sum % m;
    if (b.find(x_temp) != b.end()){
      b[x_temp]++;
    }else{
      b[x_temp] = 1;
    }
  }
  ll ans = 0;
  for (auto i : b){
    if (i.first == 0){
      ans += (i.second + i.second*(i.second-1)/2);
    }else{
      ans += i.second*(i.second-1)/2;
    }
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; cin>>s;
	if(s =="Sunny"){
		cout<<"Cloudy";
	}
	else if(s == "Cloudy"){
		cout<<"Rainy";
	}
	else if(s == "Rainy"){
		cout<<"Sunny";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int n; cin>>n;
  int A[n];
  for(int i=0;i<n;i++){
    int a; cin>>a;
    A[i]=a;
  }
  sort(A,A+n);
  cout<<A[n-1]-A[0]<<endl;
}

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

using namespace std;

#define int long long

const int INF = 1e18;

long long d;
unsigned long long ans;
unsigned long long p[50];
map<int, int> kek[2];

void check(long long d, int L, int R, unsigned long long cnt)
{
    if (L >= R)
    {
        ans += cnt * (d == 0) * (L == R ? 10 : 1);
        return;
    }
    long long c = p[R] - p[L];
    vector<long long> xs;
    for (int digit = -9; digit <= 9; digit++)
    {
        if (digit < 0 && L == 0) continue;
        long long x = d - digit * c;
        xs.push_back(x);
    }
    sort(xs.begin(), xs.end());
    for (int i = -1; i < (int)xs.size(); i++)
    {
        if ((i == -1 || xs[i] < 0) && (i + 1 == xs.size() || xs[i + 1] >= 0))
        {
            if (i > -1)
            {
                int digit = (d - xs[i]) / c;
                check(xs[i], L + 1, R - 1, cnt * kek[L == 0][digit]);
            }
            if (i + 1 < xs.size())
            {
                int digit = (d - xs[i + 1]) / c;
                check(xs[i + 1], L + 1, R - 1, cnt * kek[L == 0][digit]);
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            kek[0][i - j]++;
        }
    }
    for (int i = 1; i < 10; i++)
    {
        for (int j = 1; j < 10; j++)
        {
            kek[1][i - j]++;
        }
    }
    cin >> d;
    p[0] = 1;
    for (int i = 1; i <= 19; i++) p[i] = p[i - 1] * 10;
    for (int len = 1; len <= 19; len++)
    {
        check(d, 0, len - 1, 1);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char a[110],b[110];
int main()
{
    int i,j,k1,k2;
    while(scanf("%s%s",a,b)!=EOF)
    {
        k1=strlen(a);
        k2=strlen(b);
        if(k1>k2)
        {
            printf("GREATER\n");
            continue;
        }
        else
        if(k1<k2)
        {
            printf("LESS\n");
            continue;
        }
        else
        if(k1==k2)
        {
            if(strcmp(a,b)>0)
            {
            printf("GREATER\n");
            continue;
            }
            else
            if(strcmp(a,b)<0)
            {
            printf("LESS\n");
            continue;
            }
            else
            if(strcmp(a,b)==0)
            {
                printf("EQUAL\n");
                continue;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env ruby
# 156-c
 
n = gets().to_i
x = gets().chomp.split(" ").map(&:to_i)
a = 0
(x.min..x.max).each {|i|
    c = 0
    x.each {|j|
        c = c + (i-j)*(i-j)
    }
    if a == 0 then
        a = c
    elsif a > c then
        a = c
    end
}
puts a

Measured memory_bytes: 1788
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();
        int[] W = new int[N];

        int sum = 0;
        for(int i=0; i<N; i++){
            W[i] = nextInt();
            sum += W[i];
        }

        int min = sum;
        int sum2 = 0;
        for(int i=0; i<N-1; i++){
            sum2 += W[i];
            min = Math.min(Math.abs(sum-sum2 - sum2), min);
        }

        println(min);
    }

    //最小公倍数lcm
    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (c/b);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


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


int main(void){
    int n;
    cin >> n;
    int res = n;
    for(int i=0;i<=n;i++){
        int cc= 0;
        int t = i;
        while (t >0){
            cc += t %6;
            t /=6;
        }
        t= n - i ;
        while (t >0){
            cc += t %9;
            t /=9;
        }
        if ( res > cc ) res = cc ;
    }
    cout << res << endl;
    
    return 0;
}

























































Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main() {

  int i;
  char s[101], p[101], h[201];

      scanf("%s", s);
      scanf("%s", p);
      strcpy(h , s);
      strcat(h , s);

      if(strstr(h, p) == NULL) {
	printf("No\n");
      } else {
	printf("Yes\n");
      }

      return 0;
}

Measured memory_bytes: 540
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}
        static void myerr(Object t){System.err.println(t);}
        static String getStr(){return sc.next();}
        static int getInt(){return sc.nextInt();}
        static Long getLong(){return sc.nextLong();}
        static boolean isNext(){return sc.hasNext();}
        public static void main(String[] args){
          int N = getInt();
          while(!isPrime(N)){
            N++;
          }
          myout(N);
        }
        //便利メソッド追加枠ここから
static boolean isPrime(long val){
        if(val <= 1 || (val != 2 && val % 2 == 0)){
                return false;
        }else if(val == 2){
                return true;
        }
        double root = Math.floor(Math.sqrt(val));
        for(long i = 3; i <= root; i += 2){
                if(val % i == 0){
                        return false;
                }
        }
        return true;
}
        //便利メソッド追加枠ここまで
}


Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
int ceil(int a,int b){
    return (a+b-1)/b;
}
int main(void){
    char c[3][3];
    rep(i,3){
        rep(j,3){
            cin>>c[i][j];
        }
    }
    cout<<c[0][0]<<c[1][1]<<c[2][2]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

constexpr int64_t divisor = 1000000007;

int main() {

  int64_t N, ans = 1;

  cin >> N;
  
  for(int64_t i=1;i<=N;i++) {
    ans *= i;
    if(ans > divisor)
      ans %= divisor;
  }

  cout << ans << endl;

  return 0;
}
  


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>
using namespace std;
using ll= long long;
#define rep(i,n) for(ll i=0;i<n;i++)
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int main() {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h+1)*(n - w+1) << endl;
}

Measured memory_bytes: 764
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    string s;
    cin >> s;
    int n;
    cin >> n;
    FOR(i, 0, n){
        string order, rep;
        int a, b;
        cin >> order >> a >> b;
        if(order=="replace"){
            cin >> rep;
            s.replace(a, b-a+1, rep);
        }
        if(order=="reverse"){
            reverse(s.begin()+a, s.begin()+b+1);
        }
        if(order=="print"){
            cout << s.substr(a, b - a + 1) << endl;
        }
    }
}

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

const ll INF = 1LL << 60;

struct Parser{
	string s;
	int N;
	int c;

	ll parse(string s){
		this->s = s;
		N = s.size();
		c = 0;
		try{
			ll ret = expr();
			if(!check(ret) || c != N) throw "";
			return ret;
		}
		catch(...){
			return INF;
		}
	}

	bool check(ll n){
		return 0 <= n && n < 1024;
	}

	void debug(string text){
		return;
		cout << text + " ";
		for(int i = 0; i < N; i++){
			if(i == c) cout << '[' << s[i] << ']';
			else cout << s[i];
		}
		cout << endl;
	}

	ll expr(){
		debug("expr");
		ll x = term();
		if(!check(x)) throw "";
		while(c < N){
			if(s[c] == '+'){
				c++;
				x += term();
				if(!check(x)) throw "";
			}
			else if(s[c] == '-'){
				c++;
				x -= term();
				if(!check(x)) throw "";
			}
			else break;
		}
		return x;
	}

	ll term(){
		debug("term");
		ll x = factor();
		if(!check(x)) throw "";
		while(c < N){
			if(s[c] == '*'){
				c++;
				x *= factor();
				if(!check(x)) throw "";
			}
			else break;
		}
		return x;
	}

	ll factor(){
		debug("factor");
		if(s[c] == '('){
			c++;
			int start = c;
			ll ret = expr();
			if(s[c] != ')') throw "";
			if(!check(ret)) throw "";
			//assert(s[c] == ')');
			int cnt = 0;
			bool op = 0;
			for(int i = start; i < c; i++){
				if(s[i] == '(') cnt++;
				if(s[i] == ')') cnt--;
				if(cnt == 0 && (s[i] == '+' || s[i] == '*' || s[i] == '-')) op = 1;
			}
			if(!op) throw "";
			c++;
			return ret;
		}
		return num();
	}

	ll num(){
		debug("num");
		if(!isdigit(s[c])) throw "";
		ll ret = 0;
		while(c < N && isdigit(s[c])){
			ret = ret * 2 + s[c] - '0';
			if(!check(ret)) throw "";
			c++;
		}
		return ret;
	}
} parser;

string t = "01+*-()";
ll ans = -1;

void dfs(int n, string s){
	if(n == s.size()){
		ll res = parser.parse(s);
		if(res != INF) ans = max(ans, res);
		return;
	}
	if(s[n] != '.'){
		return dfs(n + 1, s);
	}
	for(int i = 0; i < t.size(); i++){
		s[n] = t[i];
		dfs(n + 1, s);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string s;
	cin >> s;
	dfs(0, s);
	cout << ans << endl;
}

Measured memory_bytes: 3304
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<int> v(n);
    int p = 0;
    for (int i = 0; i < n; i++) {
        int h;
        std::cin >> h;
        if (p >= h) v[i] = v[i - 1] + 1;
        p = h;
    }

    std::cout << *std::max_element(v.begin(), v.end()) << std::endl;

    return 0;
}


Measured memory_bytes: 640