akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    using namespace  std;
    #define mod 1000000007
    typedef long long ll;
    ll dp[105][100000+5];
    int main()
    {
        ll n, w;
        cin >> n >> w;
        memset(dp, -1LL, sizeof(dp));
        for(int i = 0; i < n; i++)dp[i][0] = 0;
        for(int i = 0; i < n; i++){
            ll a, b;
            cin >> a >> b;
            dp[i][b] = a;
            if(i > 0){
                for(int j = 0; j <= 100000- 1000; j++){
                    if(dp[i-1][j] >= 0){
                        dp[i][j+b] = dp[i][j+b] == -1 ? dp[i-1][j]+ a : min(dp[i-1][j]+ a, dp[i][j+b]);
                        dp[i][j] = dp[i][j] == -1 ? dp[i-1][j] : min(dp[i-1][j], dp[i][j]);
                    }
                }
            }
        }
        int ans = 0;
            for(int j = 0; j <= 100000; j++)if(dp[n-1][j] != -1 and dp[n-1][j] <= w)ans = j;
        cout << ans;
    }

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



int main(){
    int n;
    cin >> n;
    int sm =0;
    int mx =0;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        sm += a;
        mx = max(mx,a);
    }
    cout << sm-mx/2 << endl;
    return 0;
}

Measured memory_bytes: 888
use std::io::{Read, Write, stdin, stdout};

fn solve<R: Read, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_to_string(&mut s).unwrap();
    write!(output, "{}", s.replace(",", " ")).unwrap();
}

fn main() {
    solve(stdin(), stdout());
}

#[cfg(test)]
mod tests {
    fn test(input: &[u8], output: &[u8]) {
        let mut v = Vec::<u8>::new();
        ::solve(input, &mut v);
        assert_eq!(&v, &output);
    }
    #[test]
    fn case1() {
        test(b"happy,newyear,enjoy\n", b"happy newyear enjoy\n");
    }
    #[test]
    fn case2() {
        test(b"haiku,atcoder,tasks\n", b"haiku atcoder tasks\n");
    }
    #[test]
    fn case3() {
        test(b"abcde,fghihgf,edcba\n", b"abcde fghihgf edcba\n");
    }
}

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

using namespace std;
using lint = long long;

lint a[200010];
map<lint, lint> mp;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }

    lint tot = 0;
    for (auto x:mp) {
        lint t = x.second;
        tot += t * (t - 1) / 2;
    }
    for (int i = 1; i <= n; i++) {
        cout << tot - (mp[a[i]] - 1) << endl;
    }
    return 0;
}


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

int main() {
 int n,t,a;cin>>n>>t>>a;
 vector<int> h(n);
 double mn=1e+9;
 int ans;
 rep(i,n){
   cin>>h[i];
   double ta = abs(a-t+h[i]*0.006);
   if(mn>abs(ta)){
     mn=ta;
     ans = i+1;
   }
 }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;cin>>n;
	vint t(n), v(n);
	vint a(n), b(n);
	rep(i, n){
		cin>>t[i];
	}
	rep(i, n){
		cin>>v[i];
	}
	rep(i, n){
		if(i == 0){
			a[i] = 0;
		}else{
			a[i] = min(v[i-1], a[i-1]+t[i-1]);
		}
	}
	for(int i = n-1;i >= 0;i--){
		if(i == n-1){
			b[i] = 0;
		}else{
			b[i] = min(v[i+1], b[i+1]+t[i+1]);
		}
	}
	double ans = 0.0;
	rep(i, n){
		if(a[i] >= v[i]){
			if(b[i] >= v[i]){
				ans += (double)v[i]*(double)t[i];
			}else if((double)b[i]+(double)t[i] >= (double)v[i]){
				ans += (double)v[i]*(double)t[i] - (double)((double)v[i]-(double)b[i])*((double)v[i]-(double)b[i])/2.0;
			}else{
				ans += (double)b[i]*(double)t[i] + (double)t[i]*(double)t[i]/2.0;
			}
		}else{
			if(b[i] >= v[i]){
				if(a[i]+t[i] >= v[i]){
					ans += (double)v[i]*(double)t[i] - (double)((double)v[i]-(double)a[i])*((double)v[i]-(double)a[i])/2.0;
				}else{
					ans += (double)a[i]*(double)t[i] + (double)t[i]*(double)t[i]/2.0;
				}
			}else{
				if((double)((double)a[i]+(double)b[i]+(double)t[i])/2.0 > (double)v[i]){
					ans += (double)v[i]*(double)t[i] - (double)((double)v[i]-(double)a[i])*((double)v[i]-(double)a[i])/2.0 - (double)((double)v[i]-(double)b[i])*((double)v[i]-(double)b[i])/2.0;
				}else{
					double koux = (double)(b[i]+t[i]-a[i])/2.0;
					if(koux < 0.0){
						ans += (double)t[i]*(double)b[i] + (double)t[i]*(double)t[i]/2.0;
					}else if( koux > t[i]){
						ans += (double)t[i]*a[i] + (double)t[i]*(double)t[i]/2.0;
					}else{
						ans += (double)koux*(2*(double)a[i]+koux)/2.0 + (double)((double)t[i]-koux)*(2*(double)b[i]+(double)t[i]-koux)/2.0;
					}
				}
			}
		}
	}
	//cout << ans << endl;
	printf("%.15f\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<iosfwd>
using namespace std;
int main(){
    char a;
    cin >> a;
    if(a=='A') cout << "T" << endl;
    if(a=='T') cout << "A" << endl;
    if(a=='C') cout << "G" << endl;
    if(a=='G') cout << "C" <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int R;
  scanf("%d", &R);

  if ( R < 1200 ) printf("ABC\n");
  else if ( R < 2800 ) printf("ARC\n");
  else printf("AGC\n");
  return 0;
}


Measured memory_bytes: 128
n = int(input())

BA = []
for i in range(n):
    a, b = map(int, input().split())
    BA.append([b, a])

BA.sort()
t = 0
for i in range(n):
    t += BA[i][1]
    if t > BA[i][0]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 35608
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

// VMAX is the maximum value of element in progression.
const VMAX = 10000

func main() {
	fmt.Println(answer(os.Stdin))
}

func answer(r io.Reader) string {
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	// A[0], B[0] and C[0] won't be used due to handling the inconsistency
	// between the size of slice and its number of element.
	A, B := make([]int, n+1), make([]int, n+1)
	C := make([]int, VMAX+1)
	for i := 0; i < n; i++ {
		sc.Scan()
		A[i+1], _ = strconv.Atoi(sc.Text())
		C[A[i+1]]++
	}

	countingSort(A, C, &B, n)
	return String(B)
}

func countingSort(A, C []int, B *[]int, n int) {
	for i := 1; i <= VMAX; i++ {
		C[i] += C[i-1]
	}

	for j := 1; j <= n; j++ {
		(*B)[C[A[j]]] = A[j]
		C[A[j]]--
	}
}

func String(B []int) string {
	// trim junk element B[0] when stringifying the entire elements of progression.
	return strings.TrimRight(fmt.Sprintf("%+v", B[1:])[1:], "]")
}



Measured memory_bytes: 75244
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

use std::cmp::*;

fn main() {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];

    let mut shop = vec![Vec::new(); n];
    for i in 0..n
    {
        let data: Vec<u64> = read_vec();
        shop[i] = data;
    }

    // 価格の安いショップから前に出す
    shop.sort();

    let mut sum_price = 0_u64;
    let mut buyed_count = 0_u64;

    for i in 0..n
    {
        // 店iで購入する数
        let bc_tmp = min(m as u64 - buyed_count, shop[i][1]);

        // 更新
        sum_price += bc_tmp * shop[i][0];
        buyed_count += bc_tmp;

        if buyed_count == m as u64 { break; }
    }

    println!("{}", sum_price);
}


Measured memory_bytes: 10492
#include<cstdio>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	a=100*a+10*b+c;
	if(a==557||a==575||a==755) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
int asc(const void *a, const void *b)
{
    return *(long int *)a - *(long int *)b;
}
int dis(const void *a, const void *b)
{
    return *(long int *)b - *(long int *)a;
}
int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    if (a > b)
    {
        for (int i = 0; i < a; i++)
        {
            printf("%d", b);
        }
    }
    else
    {
        for (int i = 0; i < b; i++)
        {
            printf("%d", a);
        }
    }
    return 0;
}

Measured memory_bytes: 128
n,p=map(int,input().split())
a=list(map(int,input().split()))
odd_cnt=0
for i in range(n):
    if a[i]%2==1:
        odd_cnt=1
if odd_cnt==0:#全て偶数
    if p==0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))
        


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int x;
	cin >> x;
	if(x >= 30) cout <<"Yes";
	else cout << "No";
	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int highest = 0;
    int ans = 0;
    for (int i=0;i<n;i++){
        int p;
        cin >> p;
        ans += p;
        if (p>=highest) highest = p;
    }
    ans -= (highest/2);
    cout << ans << endl;
}

Measured memory_bytes: 256
// ALDS1_9_A.cpp
// Heaps - Complete Binary Tree
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> cbt(n);
    for (int i = 0; i < n; i++) {
        cin >> cbt[i];
    }
    for (int i = 1; i<= n; i++) {
        printf("node %d: key = %d, ", i, cbt[i-1]);
        int parent = i / 2;
        int left = 2 * i;
        int right = 2 * i + 1;
        if (parent > 0)
            printf("parent key = %d, ", cbt[parent-1]);
        if (left <= n)
            printf("left key = %d, ", cbt[left-1]);
        if (right <= n)
            printf("right key = %d, ", cbt[right-1]);
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 3144
import sys
def input():
    return sys.stdin.readline()[:-1]
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
m=min(a)+min(b)
for i in range(M):
    x,y,c=map(int,input().split())
    t=a[x-1]+b[y-1]-c
    if m>t:
        m=t
print(m)

Measured memory_bytes: 18612
from itertools import permutations
n, m = map(int, input().split())
ab = [[] for i in range(n)]
for i in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    ab[a].append(b)
    ab[b].append(a)
cnt = 0
if n == 2:
    if 1 in ab[0]:
        print(1)
    else:
        print(0)
    exit()
for p in permutations(range(1, n)):
    if p[0] in ab[0]:
        flag = True
        for i in range(n - 2):
            if p[i + 1] not in ab[p[i]]:
                flag = False
                break
        if flag:
            cnt += 1
print(cnt)

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

using namespace std;
const int maxn=1e5+16;
map<int,int> mp;
bool cmp(int x,int y)
{
	return x>y;
}
int a[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	mp.clear();
	int x;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		mp[a[i]]++;
	}
	sort(a,a+n,cmp);
	int ans=0;
	for(int i=0;i<n;i++){
		if(mp[a[i]]>a[i]){
			ans+=mp[a[i]]-a[i];	
			mp[a[i]]=a[i];
		}else if(mp[a[i]]<a[i]){
			ans+=mp[a[i]];	
			mp[a[i]]=a[i];
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

    int h, w;
    cin >> h >> w;
    int area[h][w];
    rep(i,h){
        rep(j,w){
            cin >> area[i][j];
        }
    }

    vector<vi> result(250010, vector<int>(5,0));

    int count = 0;

    rep(i,h){
        rep(j,w){
            if(area[i][j] % 2 == 1){
                if(j != w-1){
                    area[i][j]--;
                    area[i][j+1]++;
                    result[count][0] = i;
                    result[count][1] = j;
                    result[count][2] = i;
                    result[count][3] = j+1;
                    count++;
                }else if(i != h-1){
                    area[i][j]--;
                    area[i+1][j]++;
                    result[count][0] = i;
                    result[count][1] = j;
                    result[count][2] = i+1;
                    result[count][3] = j;
                    count++;
                }
            }
        }
    }

    cout << count << endl;
    rep(i, count){
        cout << result[i][0]+1 << " " << result[i][1]+1 << " " << result[i][2]+1 << " " << result[i][3]+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 16896
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
//int const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

ll X,K,D;

int main(){
    cin>>X>>K>>D;

    ll ans;
    ll cnt=abs(X)/D;
    if(K<cnt) ans=abs(abs(X)-abs(K*D));
    else{
        ans=abs(abs(X)-abs(cnt*D));
        K-=cnt;
        if(K&1) ans=abs(ans-D);
    }

    cout<<ans<<endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	// 周期があるので必ずa_i-1になるような数が存在する
	LL N; cin >> N;
	FOR(i, 0, N) {
		LL a; cin >> a;
		ans += a - 1;
	}


	cout << ans << "\n";

	return 0;
}

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

int main()
{
   string s;
   cin>>s;
   if(s[2]==s[3]&&s[4]==s[5])
   {
     cout<<"Yes"<<endl;
   }
  else
  {
    cout<<"No"<<endl;
  }
  return 0;
}

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

int main(){
  int h,w; cin>>h>>w;
  int c[10][10];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>c[i][j];
    }
  }
  for(int k=0;k<10;k++){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        if(c[i][j]>c[i][k]+c[k][j]) c[i][j]=c[i][k]+c[k][j];
      }
    }
  }
  long long ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int a; cin>>a;
      if(a==-1) continue;
      ans+=c[a][1];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "4 3", "1 2", "2 3", "1 4" ].parse.expand.solve == "2\n2\n1\n1" );
	assert( [ "2 5", "1 2", "2 1", "1 2", "2 1", "1 2" ].parse.expand.solve == "5\n5" );
	assert( [ "8 8", "1 2", "3 4", "1 5", "2 8", "3 7", "5 2", "4 1", "6 8" ].parse.expand.solve == "3\n3\n2\n2\n2\n1\n1\n2" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto abs = new long[ 2 ][ nm[ 1 ] ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	return tuple( nm[ 0 ], abs );
}

auto solve( long n, long[ 2 ][] abs )
{
	auto ss = new long[ n ];
	foreach( ab; abs )
	{
		ss[ ab[ 0 ] - 1 ]++;
		ss[ ab[ 1 ] - 1 ]++;
	}
	return ss.to!( string[] ).join( "\n" );
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;


int main(){
    LL x,y;
    cin >> x >> y;
    if(abs(x-y)<=1) puts("Brown");
    else puts("Alice");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<stack>
#include<queue>
#include<map> 
#include<list>
#include<string>
#include<cstring>
#include<set>
#include<vector>
#define ll long long
#define memset(a,n) memset(a,n,sizeof(a))
#define mp make_pair 
#define pb push_back
using namespace std;
const int maxn = 2e5 + 100;


int main()
{
	int n;int a[maxn];ll p[maxn];scanf("%d",&n);
	for(int i = 1 ;i <= n;i++) scanf("%d",&a[i]);
	p[1] = a[1];
	for(int i = 3;i <= n;i += 2){
		p[i] = p[i-2] + a[i];
	}
	ll dp[maxn] = {0};
	for(int i = 2; i <= n;i++){
		if(i & 1){
			dp[i] = max(dp[i-1],dp[i-2]+a[i]);
		}else{
			dp[i] = max(dp[i-2] + a[i],p[i-1]);
		}
	}
	printf("%lld\n",dp[n]);
}

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

namespace ConsoleApp1
{
    class Program
    {
        public static int GetInt()
        {
            int a = int.Parse(Console.ReadLine());
            return a;
        }

        public static int[] GetIntArray()
        {
            var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            return a;
        }

        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            if (S == "Sunny")
            {
                Console.WriteLine("Cloudy");
            }
            if (S == "Cloudy")
            {
                Console.WriteLine("Rainy");
            }
            if (S == "Rainy")
            {
                Console.WriteLine("Sunny");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

//#define mod 1000000007;

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

    string s,t;
    cin>>s>>t;
    long long a = 0;
    for(int i=0;i<s.size(); i++)
    {
        if(s[i] != t[i])
            a++;
    }
    cout<<a;

    return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <set>


int main(void) {
	int a, b; std::cin >> a >> b;
	std::string str_a(a, '0' + b), str_b(b, '0' + a);
	std::cout << std::min(str_a, str_b) << std::endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int MAX = (1e5)+1;

struct node {
	int x, y, q, idx;
	bool operator<(node& rhs) {
		if(q < rhs.q) return true;
		else if(q > rhs.q) return false;

		if(!q) return y < rhs.y;
		else if(q == 1) return x < rhs.x;
		else if(q == 2) return y > rhs.y;
		else return x > rhs.x;
	}
};

int r, c, n;
vector<pair<pii, pii> > a;
vector<node> b;
bool valid = true, mark[MAX];

int getq(int x, int y) {
	if(!x) return 0;
	else if(y == c) return 1;
	else if(x == r) return 2;
	else if(!y) return 3;
	else return -1;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> r >> c >> n;
	for(int i = 0, x1, y1, x2, y2; i < n; i++) {
		cin >> x1 >> y1 >> x2 >> y2;
		a.emplace_back((pii) {x1, y1}, (pii) {x2, y2});
		if(getq(x1, y1) != -1 && getq(x2, y2) != -1) {
			b.push_back((node) {x1, y1, getq(x1, y1), i});
			b.push_back((node) {x2, y2, getq(x2, y2), i});
		}
	}
	sort(b.begin(), b.end());
	stack<int> st;
	for(int i = 0; i < b.size(); i++) {
		if(!mark[b[i].idx]) {
			st.push(b[i].idx);
			mark[b[i].idx] = true;
		} else {
			valid &= st.top() == b[i].idx;
			st.pop();
		}
	}
	cout << (valid ? "YES" : "NO");
}


Measured memory_bytes: 7396
#include <stdio.h>
#include <stdlib.h>

#define QUEUE_SIZE 100000
#define next(a) (((a)+1)%QUEUE_SIZE)
#define max(a,b) ((a) > (b) ? (a) : (b))

int queue[QUEUE_SIZE];
int front;
int rear;

void init(){
	front = rear = 0;
}
void enqueue(int x){
	if(next(rear)==front){
		printf("full");
		exit(1);
	}
	queue[rear]=x;
	rear = next(rear);
}
int dequeue(){
	if(front==rear){
		printf("Nodata");
		exit(1);
	}
	int x  = queue[front];
	front = next(front);
	return x;
}
int isempty(){
	return front==rear;
}
int main(){
	int n,ans;
	scanf("%d",&n);
	int i,j,temp;
	int x,y;
	int m[2][n];
	int s[2][100]={};
	for(i=0;i<2;i++){
		for(j=0;j<n;j++)scanf("%d",&m[i][j]);
	}
	enqueue(0);
	s[0][0]=m[0][0];
	while(isempty()==0){
		temp = dequeue();
		x = temp/1000;
		y = temp%1000;
		/*今回は右と下にしかアクセスしないので訪問済みデータはいらない*/
		if((y+1)<n){
			if((s[x][y]+m[x][y+1])>s[x][y+1]){
				s[x][y+1]=s[x][y]+m[x][y+1];
				enqueue(1000*(x)+(y+1));
			}else{
				enqueue(1000*(x)+(y+1));
			}
		}
		if((x+1)<2){
			if((s[x][y]+m[x+1][y])>s[x+1][y]){
				s[x+1][y]=s[x][y]+m[x+1][y];
				enqueue(1000*(x+1)+(y));
			}else{
				enqueue(1000*(x+1)+(y));
			}
		}
	}
	printf("%d",s[1][n-1]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1;
	// cin>>t;
	while (t--)
	{
		int n;
		cin >> n;
		vector<int> arr, brr(n), crr(n);
		for (int i = 1; i <= n; i++) arr.pb(i);
		for (auto &i : brr) cin >> i;
		for (auto &j : crr) cin >> j;
		int a = 0, b = 0, i = 0, j = 0;
		while (1) {
			if (i == 0 && arr != brr) {
				a++;
			}
			else i = 1;
			if (j == 0 && arr != crr) {
				b++;
			}
			else j = 1;
			if (i == 1 && j == 1) break;
			next_permutation(all(arr));
		}
		cout << abs(a - b) << "\n";

	}
	return 0;
}

Measured memory_bytes: 3612
n = int(input()) 
nums = list(map(int, input().split()))
nums.sort()

left = nums[0]
right = sum(nums[1:])

ans = right - left
arg = 0
for i in range(1, n - 1):
	left += nums[i]
	right -= nums[i]
	if right - left > ans:
		arg = i
		ans = right - left

print(ans)

l_list = nums[:(arg + 1)]
r_list = nums[(arg + 1):]

while len(l_list) > 1:
	x = r_list.pop()
	y = l_list.pop()
	print(str(x) + " " + str(y))
	r_list.append(x - y)

x = l_list.pop()
while len(r_list) > 1:
	y = r_list.pop()
	print(str(x) + " " + str(y))
	x = x - y

print(str(r_list.pop()) + " " + str(x))


Measured memory_bytes: 14264
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var arr = [-1];
	var pow3 = [1];
	for(var i = 1 ; i < 11; i++){
		pow3[i] = 3*pow3[i-1];
	}
	var M = 1000000000;
	var a,b,c;
	var ans = 0;
	var arr357 = [3,5,7];
	for(var i = 0; i < M; i++){
		a = i;
		arr[0]++;
		for(var j = 0; j < 10; j++){
			if(arr[j]===3){
				arr[j]-=3;
				if(arr[j+1]===undefined){
					arr[j+1] = 0;
					break;
				}else{
					arr[j+1]++;
				}
			}

		}
		c = arr.map(el=>arr357[el]);
		//console.log(i,arr,c)
		if(toInt(c.reverse().join(''))>n){
			break;
		}
		if(arr.indexOf(0)===-1 || arr.indexOf(1)===-1 || arr.indexOf(2)===-1){
			continue;
		}
		ans++;

	}
	console.log(ans);
}

Measured memory_bytes: 21192
#include<iostream>
#include<cfloat>
#include<cmath>
#include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std;
 
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS )
#define dle(a, b) (equals(a, b) || a < b )
#define PI 3.14159265359
#define PI2 6.28318530718
#define INF 9999999.9999

class Point{
public:
  double x, y;
  Point ( double x = 0, double y = 0): x(x), y(y){}
  Point operator + ( Point p ){ return Point(x + p.x, y + p.y); }
  Point operator - ( Point p ){ return Point(x - p.x, y - p.y); }
  Point operator * ( double a ){ return Point(x*a, y*a); }
  Point operator / ( double a ){ return Point(x/a, y/a); }
  double abs() { return sqrt(norm());}
  double norm() { return x*x + y*y; }
  bool operator < ( const Point &p ) const {
    return x != p.x ? x < p.x : y < p.y;
  }
  bool operator == ( const Point &p ) const {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};

class Segment{
public:
  Point p1, p2;
  Segment ( Point p1 = Point(), Point p2 = Point() ): p1(p1), p2(p2){}
  double abs() { return sqrt(norm());}
  double norm() { return (p2.x - p1.x)*(p2.x - p1.x) + (p2.y - p1.y)*(p2.y - p1.y); }
};

typedef Segment Line;
typedef Point Vector;

double norm( Vector a ){ return a.x*a.x + a.y*a.y; }
double abs( Vector a ){ return sqrt(norm(a)); }
Point polar( double a, double r ){ return Point(cos(r)*a, sin(r)*a);}
double getDistance( Vector a, Vector b ){ return abs(a - b); }
double dot( Vector a, Vector b ){ return a.x*b.x + a.y*b.y; }
double cross( Vector a, Vector b ){ return a.x*b.y - a.y*b.x; }

double getDistanceLP(Line s,Point p){
  return abs(cross(s.p2-s.p1,p-s.p1)/abs(s.p2-s.p1));
}
double getDistanceSP(Segment s,Point p){
  if(dot(s.p2-s.p1,p-s.p1)<0.0)return abs(p-s.p1);
  if(dot(s.p1-s.p2,p-s.p2)<0.0)return abs(p-s.p2);
  return getDistanceLP(s,p);
}

double R;
int N,ans,id;
Point p[100];
double r[100],v[100],d[100],nd[100];
bool die[100];
Segment s;

int main(){
  while(1){
    cin>>R>>N;
    if(R==0&&N==0)break;
    for(int i=0;i<N;i++){
      cin>>p[i].x>>p[i].y>>r[i]>>v[i];
      nd[i]=d[i]=getDistance(p[i],Point(0,0));
      die[i]=false;
    }

    while(1){

      //１分進める
      for(int i=0;i<N;i++){
	nd[i]=max(R,nd[i]-v[i]);
      }
      
      //最も近くにいる敵を探す
      double mini=INF;
      id=-1;
      for(int i=0;i<N;i++){
	if( die[i] )continue;
	if(nd[i] < EPS+R)continue;
	if(nd[i] > mini)continue;
	mini=nd[i];
	id=i;
      }
      if(id==-1)break;

      //レーザー発射の処理
      s = Segment( p[id] , p[id] );
      s.p1 = s.p1 / d[id];
      s.p1 = s.p1 * R;

      s.p2 = s.p2 / d[id];
      s.p2 = s.p2 * 10000000.0;
    
      for(int i=0;i<N;i++){
	if( nd[i] < EPS+R ) continue;
	
	Point a = p[i];
	a = a / d[i];
	a = a * nd[i];
	if( getDistanceSP( s, a ) < EPS+r[i] )die[i]=true;

      }
      //１ターン終了
    }

    ans=0;
    for(int i=0;i<N;i++){
      if(die[i]==false)ans++;
    }
    cout<<ans<<endl;
  }
    
  
  return 0;
}

Measured memory_bytes: 1236
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var N, M int
var dp []int
var path [][]int

func dfs(u int) int {
	if dp[u] != -1 {
		return dp[u]
	}
	r := 0
	for _, v := range path[u] {
		r = MaxIn2Values(r, dfs(v)+1)
	}
	dp[u] = r
	return r
}

func main() {
	N = nextInt()
	M = nextInt()
	dp = make([]int, N)
	path = make([][]int, N)
	var from, to int
	for i := 0; i < M; i++ {
		from = nextInt() - 1
		to = nextInt() - 1
		path[from] = append(path[from], to)
	}
	for i := 0; i < N; i++ {
		dp[i] = -1
	}
	for i := 0; i < N; i++ {
		dfs(i)
	}
	ans := 0
	for i := 0; i < N; i++ {
		ans = MaxIn2Values(ans, dp[i])
	}
	fmt.Println(ans)
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinIn2Values(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 14720
class Node:
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None
        self.p = None

def insert(z,root):
    y = None
    x = root
    while x != None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.p = y
    if y == None:
        root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

    return root

def printPreorderList(p):
    if p == None:
        return
    print("",p.key,end = "")
    printPreorderList(p.left)
    printPreorderList(p.right)

def printInorderList(p):
    if p == None:
        return
    printInorderList(p.left)
    print("",p.key,end = "")
    printInorderList(p.right)

def find(key, root):
    x = root
    while x != None:
        if key == x.key:
            print("yes")
            return
        elif key < x.key:
            x = x.left
        else:
            x = x.right
    print("no")


n = int(input())
root = None
for ni in range(n):
    s = input()
    if s[0] == "i":
        s, key = s.split()
        key = int(key)
        root = insert(Node(key), root)
    elif s[0] == "p":
        printInorderList(root)
        print()
        printPreorderList(root)
        print()
    elif s[0] == "f":
        s, key = s.split()
        key = int(key)
        find(key, root)


Measured memory_bytes: 85456
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(){
    long long int ans;
    int n;
    scanf("%d",&n);
    
    long long int a[n];
    int i;
    for(i=0;i<n;i++)scanf("%lld",&a[i]);
    
    long long int sa[n];
    for(i=0;i<n;i++)sa[i]=a[i];
    sort(sa,sa+n);
    
    long long int sum=0;
    long long int sum2=0;
    
    if(n%2==0){
        a[0]=sa[n/2];
        a[n-1]=sa[n/2-1];
        for(i=1;i<n-1;i++){
            if(i%2==1)a[i]=sa[(i-1)/2];
            if(i%2==0)a[i]=sa[n-i/2];
            if(i>0)sum+=abs(a[i]-a[i-1]);
            if(i==n-2)sum+=abs(a[i+1]-a[i]);
        }
    }else{
        a[0]=sa[(n-1)/2+1];
        a[n-1]=sa[(n-1)/2];
        for(i=1;i<n-1;i++){
            if(i%2==1)a[i]=sa[i/2];
            if(i%2==0)a[i]=sa[n-i/2];
            sum+=abs(a[i]-a[i-1]);
            if(i==n-2)sum+=a[i+1]-a[i];
        }
        for(i=0;i<n;i++)
        a[0]=sa[(n-1)/2];
        a[n-1]=sa[(n-1)/2-1];
        for(i=1;i<n-1;i++){
            if(i%2==0)a[i]=sa[(i-1)/2];
            if(i%2==1)a[i]=sa[n-1-i/2];
            sum2+=abs(a[i]-a[i-1]);
            if(i==n-2)sum2+=abs(a[i+1]-a[i]);
        }
    }
    if(sum>sum2){
        ans=sum;
    }else{
        ans=sum2;
    }
    if(n==2)ans=abs(a[1]-a[0]);
    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int i,a,b,c;
	cin>>a>>b>>c;
	for(i=a;i<=b;i++){
		if(i<a+c||i>b-c)cout<<i<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[list(map(int,input().split())) for i in range(2)]

ans=0
#どこで下に移動するか考える
for i in range(n):
    count=sum(a[0][:i+1])+sum(a[1][i:])
    ans=max(ans,count)
print(ans)


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
            var A = input[0];
            var B = input[1];
            var C = input[2];
            var limit = A - B;
            var ans = C - limit;
            if (ans < 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(ans);
            }

        }
    }
}


Measured memory_bytes: 11348
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  ll n, x, m;

  cin >> n >> x >> m;

  ll ans = 0;

  ll cycle = 0, tot = 0, left = n;

  vector<char> u(m + 1);

  while(true) {
    ans += x;
    left--;
    if(left == 0) { cout << ans; return 0; }
    if(u[x]) break;
    u[x] = true;
    x = (x * x) % m;
  }

  ll stop = x;

  do {
    tot += x;
    cycle++;
    x = (x * x) % m;
  } while(x != stop);

  ans += tot * (left / cycle);

  left %= cycle;

  while(left--) {
    x = (x * x) % m;
    ans += x;
  }

  cout << ans;

  return 0;
}
/*

*/


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    if(A1 + A2 + A3 >= 22){
        cout << "bust" << endl;
    } 
    else{
        cout << "win" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
def factorize(n): #素因数分解
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

N,P = map(int,input().split())

fact = factorize(P)

ans = 1
for f,n in fact:
    ans *= f**(n//N)

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

void main()
{
  int a,b,c,k;
  scanf("%d %d %d %d", &a, &b, &c, &k);
  if (k - a - b <= 0)
  {
    if( k <= a)
    {
      printf("%d\n", k);
    }
    else
    {
       printf("%d\n", a);
    }
  }
  else
  {
    k = k - a - b;
    printf("%d\n", a - k);
  }
}

Measured memory_bytes: 1728
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        sc.close();

        long rn = (long) Math.sqrt(N);
        ArrayList<Integer> ans = new ArrayList<>();
        for (long i = 1; i <= rn; i++) {
            if (N % i != 0) {
                continue;
            } else {
                long j = N / i;
                ans.add(dig(i, j));
            }
        }
        Collections.sort(ans);
        System.out.println(ans.get(0));
    }

    private static int dig(long a, long b) {
        int ad = 0;
        while (a > 0) {
            a /= 10;
            ad++;
        }
        int bd = 0;
        while (b > 0) {
            b /= 10;
            bd++;
        }
        return Math.max(ad, bd);
    }
}


Measured memory_bytes: 23764
n,m=map(int,input().split())
h=list(map(int,input().split()))
ans=0
l=[[] for i in range(n+1)]
for j in range(m):
  a,b=map(int,input().split())
  l[a].append(b)
  l[b].append(a)

for i in range(1,n+1):
  now=l[i]
  o=0
  for j in now:
    if h[i-1]>h[j-1]:
      o+=1
  if o==len(now):
    ans+=1
print(ans)

Measured memory_bytes: 29460
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();
		int ans=0;

		for(int i=1; i<=n; i++) {
			int temp=i,sum=0;
			while(temp > 0) {
				sum += temp%10;
				temp /= 10;
			}
			if(sum >= a && sum <= b) ans += i;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int sum;
  
  for(int i = 0; i < N; i++){
    int X;
    cin >> X;
    
    //ロボットBよりボールのほうが大きい場合
    if(K < X){
      sum += (X - K) * 2;
      
    //ロボットBよりボールのほうが小さい場合
    }else{
      //ロボットAとボールのほうが近い場合
      if(X < (K - X)){
        sum += X * 2;
        
      }else{
        sum += (K - X) * 2;
      }
    }
  }
  
  cout << sum << endl;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
signed main()
{
    int n,l;
    cin>>n>>l;
    vector<string> v(n);
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    string ans;
    for(int i=0;i<v.size();i++)
        ans+=v[i];
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
// AOJ 0251: Magic Square
// 2017.12.16 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 100002

/* UNION-FIND library */
int p[MAX], rank[MAX];
void link(int x, int y) {
	if (rank[x] > rank[y]) p[y] = x;
	else { p[x] = y; if (rank[x] == rank[y]) rank[y] = rank[y] + 1;	}
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }

char f[MAX];
char buf[20], *bp;

int in()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3)+(n<<1) + (*bp++ & 0xf);
	bp++;
	return n;
}

int main()
{
	int n, m, a, b, ans;

	while (fgets(bp=buf, 20, stdin) && *bp != '0') {
		n = in(), m = in();

		memset(rank, 0, sizeof(int)*(n+1));
		for (a = 1; a <= n; a++) p[a] = a;
		memset(f, 0, n+1);

		ans = 1;
		while (m--) {
			fgets(bp=buf, 20, stdin);
			a = in(), b = in();
			if (++f[a] > 2) ans = 0;
			if (++f[b] > 2) ans = 0;
			if (find_set(a) == find_set(b)) ans = 0;
			union_set(a, b);
			if (!ans) break;
		}
		if (m > 0) while (m--) fgets(bp=buf, 20, stdin);
		puts(ans ? "yes" : "no");
	}
	return 0;
}

Measured memory_bytes: 2452
#include<iostream>
#include<limits.h>
using namespace std;

int main(){
long long n, c, x[100010], v[100010];
long long cl1[100010], cl2[100010];
long long ac1[100010], ac2[100010];
cin>>n>>c;
for (int i=0; i<n; i++){
cin>>x[i]>>v[i];
}
cl1[0]=v[0]-x[0];
ac2[0]=cl1[0]-x[0];
for (int i=1; i<n; i++){
cl1[i]=cl1[i-1]-(x[i]-x[i-1])+v[i];
ac2[i]=cl1[i]-x[i];
}
ac1[n-1]=v[n-1]-(c-x[n-1]);
cl2[n-1]=ac1[n-1]-(c-x[n-1]);
for (int i=n-2; i>=0; i--) {
ac1[i]=ac1[i+1]-(x[i+1]-x[i])+v[i];
cl2[i]=ac1[i]-(c-x[i]);
}

long long ans=0, max=0;
for (int i=n-1; i>=0; i--){
if (ans<cl1[i]+max) ans=cl1[i]+max;
if (max<cl2[i]) max=cl2[i];
}
max=0;
for (int i=0; i<n; i++){
if (ans<ac1[i]+max) ans=ac1[i]+max;
if (max<ac2[i]) max=ac2[i];
}
if (ans<0) ans=0;

cout<<ans<<endl;//462
}

Measured memory_bytes: 4992
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();

            int ans = Integer.MAX_VALUE;
            for (long i = 1; i * i <= n; i++) {
                if (n % i == 0) {
                    ans = String.valueOf(n / i).length();
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 23380
il = lambda: list(map(int, input().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
a = il()
dic = dict()
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
l = []
for i, j in sorted(dic.items())[::-1]:
    if j >= 4:
        l.append(i)
        l.append(i)
    elif j >= 2:
        l.append(i)
    if len(l) == 2:
        break
print(l[0] * l[1] if l else 0)

Measured memory_bytes: 21128
#include <bits/stdc++.h>
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf (int)50000000000 //5･10^10
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
  int n,m;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  sort(a,a+n);
  reverse(a,a+n);
  rep(i,n) {
    if(1<i) {
      if(abs(a[0]/2-a[i])<abs(a[0]/2-a[m])) {
        m=i;
      }
    }
    else if(i) {
      m=1;
    }
  }
  cout<<a[0]<<" "<<a[m]<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,m,d[500],sum,ans;
int px(int x,int y)
{
	return x>y;
}
int main()
{
  cin>>m;
  cin>>n;
  for(int i=1;i<=m;i++)
  {
  	cin>>d[i];
  }
  sort(d+1,d+1+m,px);
  for(int j=1;j<=n;j++)
  ans+=d[j];
  cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;
    static int N;
    static int[,] F;
    static int[,] P;
    static void input()
    {
        cin = new Scanner();
        N = cin.nextInt();
        F = new int[N, 10];
        P = new int[N, 11];
        for (int i = 0; i < N; i++)
            for (int j = 0; j < 10; j++)
                F[i, j] = cin.nextInt();

        for (int i = 0; i < N; i++)
            for (int j = 0; j < 11; j++)
                P[i, j] = cin.nextInt();
    }
    static void solve()
    {
        input();
        int ans = int.MinValue;
        for(int i = 1; i < (1 << 10); i++)
        {
            int value = 0;
            for(int j = 0; j < N; j++)
            {
                int count = 0;
                for(int k = 0; k <= 10; k++)
                {
                    if (((i >> k) & 1) == 1 && F[j, k] == 1)
                        count++;
                }
                value += P[j, count];
            }
            ans = Max(ans, value);
        }
        WriteLine(ans);
    }
    class Scanner
    {
        string[] s;
        int i;

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

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 13140