akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define MP make_pair
#define PB push_back

using namespace std;
typedef pair<int,int> Pair;
typedef long double ld;
typedef long long ll;

const int mod = 998244353, MAX = 1e5, N = 4005;
//template{{{
const long double Pi = 3.14159265358979323846l;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; };
inline void inc(int &x, int y) { x += y; x -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		x = mul(x, x), y >>= 1;
	} return ans;
}

/*char buf[1<<23],obuf[1<<23],*p1=buf,*p2=buf, *O = obuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
void print(int x) {
    if(x > 9) print(x / 10);
    *O++=x%10+'0';
} */

template <class T> inline T	input() {
	T x; char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return flag ? -x : x;
}

template <class T> inline bool chkmin(T &x, T y) { x = x < y ? x : y; return x == y; }
template <class T> inline bool chkmax(T &x, T y) { x = x > y ? x : y; return x == y; }
template <class T> inline T gcd(T x, T y) { return !y ? x : gcd(y, x % y); }
template <class T> inline T sqrm(T x) { return (ll) x * x % mod; }
template <class T> inline T sqr(T x) { return x * x; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read; //}}}

int n, a[N];
int suf[4][N];
ll ans = 0;
char s[N];

int main() {
#ifdef local
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	freopen("log", "w", stderr);
#endif

	read(n);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; ++i)
		a[i] = s[i] == 'R' ? 1 : s[i] == 'G' ? 2 : 3;

	for (int i = n; i; --i) {
		suf[1][i] = suf[1][i + 1] + (a[i] == 1);
		suf[2][i] = suf[2][i + 1] + (a[i] == 2);
		suf[3][i] = suf[3][i + 1] + (a[i] == 3);
	}

	for (int i = 1; i < n; ++i)
		for (int j = i + 1; j < n; ++j) {
			if (a[i] == a[j]) continue;
			int tmp = suf[a[i] ^ a[j]][j + 1];
			if (j * 2 - i <= n && a[j * 2 - i] == (a[i] ^ a[j])) --tmp;
			ans += tmp;
		}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3860
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------

signed main() {
	int h, w;
	cin >> h;
	for (int i = 1; i <= h; i++) {
		bool l = i % 3 == 0;
		int x = i;
		while (x > 0) {
			if (x % 10 == 3) l = 1;
			x /= 10;
		}
		if (l) cout << " " << i;
	}
	cout << endl;
}


Measured memory_bytes: 3084
MOD = 10**9 + 7
N, M = map(int, input().split())
broken = [False] * (N+1)
for i in range(M):
    a = int(input())
    broken[a] = True
dp = [0] * (N+1)
dp[0] = 1
for i in range(1, N+1):
    if broken[i]:
        dp[i] = 0
        continue
    if i == 1:
        dp[i] = dp[i - 1]
    else:
        dp[i] = dp[i - 1] + dp[i - 2]
    dp[i] %= MOD

print(dp[N] % MOD)

Measured memory_bytes: 7668
# -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())
t=0
for i,a in enumerate(A):
    if i%2==0:  #奇数番目の時は足す
        t+=a
    else:       #偶数番目の時は引く
        t-=a
L=[]
for a in A:
    print t,
    t=a*2-t


Measured memory_bytes: 43176
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
d = gets.chomp.to_i
e = gets.chomp.to_i
k = gets.chomp.to_i
arr = [a,b,c,d,e]
can = true
[*0..4].each{|i|
  [*0..4].each{|j|
    can = false if (arr[j] - arr[i]).abs > k
    break unless can
  } 
}
puts can ? "Yay!" : ":("


Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define debug(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define debug(...) 
#define end_time()
#endif
 
 
#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
inline int gcd(int a, int b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); } 
inline int power(int x, int n, int m = LLONG_MAX)
    {  int res=1; x = (x%m + m)%m;
       while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
    }
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007

void solve(){
	int n;
	cin>>n;
	if(n>=30) cout<<"Yes\n";
	else cout<<"No\n";
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;++i) {
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	end_time();
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string key = "keyence";
    int l = key.size();
    bool ok = false;
    if(s.substr(0, l) == key) ok = true;
    else if(s.substr(s.size() - l) == key) ok = true;
    else if(s[0] == 'k' && s.back() == 'e')
    {
        string left = "";
        int pos = 0;
        for(int i = 0; i < s.size(); i++)
        {
            if(s[i] != key[pos]) break;
            left += s[i];
            pos++;
        }
        string right = "";
        int pos1 = key.size() - 1;
        for(int i = s.size() - 1; i >= 0; i--)
        {
            if(s[i] != key[pos1]) break;
            right += s[i];
            pos1--;
        }
        reverse(right.begin(), right.end());
        string ans = left;
        for(int i = 0; i < right.size(); i++)
        {
            ans += right.substr(i);
            if(ans == key) ok = true;
        }
        for(int i = 1; i <= left.size(); i++)
        {
            string tmp = left.substr(0, i);
            ans = tmp + right;
            if(ans == key) ok = true;
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {


	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	double a = sc.nextInt();
	double b = sc.nextInt();
	double c = sc.nextInt();
	
	if(a/c<=b) {
		System.out.println("Yes");
	}else {
		System.out.println("No");
	}
	
	
	}
		
	
}


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

int main() {
	string s;
	cin >> s;
	int count = 0;
	for(int i=0;i<s.size();i++){
		char a = s.at(i);
		int b = a - '0';
		count += b;

	}
	if(count % 9 == 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

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

const int MOD = 1000000007;

int main() {
  ll N, K; cin >> N >> K;

  ll total = 0;
  for (ll k = K; k <= N+1; k++) {
    ll first = k*(k-1)/2;
    ll final = (2*N-k+1) * k/2;
    ll add = final - first + 1;
    total = (total + add) % MOD;
  }

  cout << total << endl;
  return 0;
}

Measured memory_bytes: 3568
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    int C = Integer.parseInt(sc.next());

    int in[] = new int[3];
    in[0] = A;
    in[1] = B;
    in[2] = C;
    Arrays.sort(in);

    System.out.println(in[2] * 10 + in[1] + in[0]);

  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int t,n=10,a[10002],b[10002],c[10002];
bool flag;

void dfs(int dep,int db,int dc)
{
	if(!flag)return;
	if(dep==n)
	{
		flag=0;
		for(int i=1;i<db;++i)
			if(b[i]<b[i-1])
				flag=1;
		for(int i=1;i<dc;++i)
			if(c[i]<c[i-1])
				flag=1;
		return;
	}
	b[db]=a[dep];
	dfs(dep+1,db+1,dc);
	c[dc]=a[dep];
	dfs(dep+1,db,dc+1);
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		flag=1;
		for(int i=0;i<n;++i)
			scanf("%d",&a[i]);
		dfs(0,0,0);
		if(flag)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int d[N];
  for(int i=0; i<N; i++){
    cin >> d[i];
  }
  long sum = 0;
  for(int j=0; j<N; j++){
    for(int k=j+1; k<N; k++){
      sum += d[j]*d[k];
    }
  }
  
  cout << sum;
  
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    int ans1 = a/b;
    int ans2 = a%b;
    double ans3 = static_cast<double>(a)/static_cast<double>(b);
    printf("%d %d %.6f", ans1, ans2, ans3);
}


Measured memory_bytes: 3216
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7

a,b,c = map(int,input().split())
if a == b + c or b == a + c or c == a + b:
    print("Yes")
else:
    print("No")

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

using namespace std;

typedef long long ll;

const int N = 2e5 + 10;

int n, m, k;
ll a[N], b[N];

int main()
{
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1, x; i <= n; ++i) scanf("%d", &x), a[i] = a[i - 1] + x;
	for (int i = 1, x; i <= m; ++i) scanf("%d", &x), b[i] = b[i - 1] + x;
	
	int j = m;
	ll ans = 0;
	for (int i = 0; i <= n; ++i)
	{
		if (a[i] > k) break;
		while (a[i] + b[j] > k) j --;
		ans = max(ans, i + j + 0LL);
	}
	
	printf("%lld\n", ans);
	
	return 0;
} 

Measured memory_bytes: 6964
x = input()

K=0
U=0
P=0
C=0

for i in range(len(x)):
    if ord('K') == ord(x[i]):
        K += 1
    elif ord('U') == ord(x[i]):
        U += 1
    elif ord('P') == ord(x[i]):
        P += 1
    elif ord('C') == ord(x[i]):
        C += 1

print(min(K,U,P,C))


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


class RollingHash:
    def __init__(self, string):
        self.n = len(string)
        self.BASE = 1234
        self.MOD = (1 << 51) - 1
        self.hash = [0] * (self.n + 1)
        self.pow = [1] * (self.n + 1)

        for i, char in enumerate(string):
            self.hash[i + 1] = (self.hash[i] + ord(char)) * self.BASE % self.MOD
            self.pow[i + 1] = (self.pow[i] * self.BASE) % self.MOD

    def get_hash(self, l, r):
        """string[l:r]のハッシュ値を返す。O(1)"""
        res = (self.hash[r] - self.hash[l] * self.pow[r - l]) % self.MOD
        return res


n = int(input())
s = [input()[:-1] for i in range(n)]


s.sort(key=len)
str_set = set()
cnt = 0

for string in s:
    string = string[::-1]
    n = len(string)
    rh = RollingHash(string)

    for r in range(1, n + 1):
        if rh.get_hash(0, r) in str_set:
            cnt += 1

    set_char = set()
    for r in range(1, n + 1)[::-1]:
        set_char.add(string[r - 1])
        for char in set_char:
            if char == string[r - 1]:
                continue
            h = (rh.hash[r - 1] + ord(char)) * rh.BASE % rh.MOD
            if h in str_set:
                cnt += 1
    str_set.add(rh.get_hash(0, n))

print(cnt)

Measured memory_bytes: 133660
a = []
while True:
  H, W = list(map(int, input().split(' ')))
  if H == 0 and W == 0:
    break
  a.append([H, W])
for l in a:
  for h in range(l[0]):
    for w in range(l[1]):
      print('#', end='')
    print('', sep="\n")
  print('', sep="\n")


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

int main() {
  int n, k; cin>>n>>k;
  vector<long long> a(n), s(n+1, 0);
  for (int i = 0; i < n; i++) cin>>a[i];
  for (int i = 0; i < n; i++) s[i+1] = s[i] + a[i];

  long long ans = 0;
  map<int, int> v;
  int l = 0;
  for (int r = 0; r < n+1; r++) {
    if (r-l >= k) {
      --v[(s[l]-l)%k];
      ++l;
    }
    ans += v[(s[r]-r)%k];
    ++v[(s[r]-r)%k];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12800
//g++  5.4.0

#include <bits/stdc++.h>

using namespace std;

double dp[305][305][305];
double p[305][305][305];

int main()
{
    int n; cin >> n;
    
    
    for(int i = 0; i < 305; i++) for(int j = 0; j < 305; j++) for(int k = 0; k < 305; k++) dp[i][j][k] = 0;
    for(int i = 0; i < 305; i++) for(int j = 0; j < 305; j++) for(int k = 0; k < 305; k++) p[i][j][k] = 0;
    
    int cnt[4];
    for(int i = 0; i < 4; i++) cnt[i] = 0;
    for(int i = 0; i < n; i++){
        int tmp; cin >> tmp;
        cnt[tmp]++;
    }
    
    //for(int i = 0; i <= 3; i++) cout << cnt[i] << endl;
    
    p[cnt[1]][cnt[2]][cnt[3]] = 1;
    
    for(int k = n; k >= 0; k--){
        for(int j = n; j >= 0; j--){
            for(int i = n; i >= 0; i--){
                if(i == 0 && j == 0 && k == 0) continue;
                if(i+j+k > n) continue;
                double p_waste = (double)(n-(i+j+k))/n;
                double turn_to_next = p_waste/(1-p_waste)+1;
                dp[i][j][k] += turn_to_next*p[i][j][k];
                if(k != 0) {
                    double go = (double)k/(i+j+k);
                    p[i][j+1][k-1] += p[i][j][k]*go;
                    dp[i][j+1][k-1] += dp[i][j][k]*go;
                }
                if(j != 0) {
                    double go = (double)j/(i+j+k);
                    p[i+1][j-1][k] += p[i][j][k]*go;
                    dp[i+1][j-1][k] += dp[i][j][k]*go;
                }
                if(i != 0) {
                    double go = (double)i/(i+j+k);
                    p[i-1][j][k] += p[i][j][k]*go;
                    dp[i-1][j][k]   += dp[i][j][k]*go;
                }
            }
        }
    }
    
    printf("%.10lf\n", dp[0][0][0]);
}

Measured memory_bytes: 443648
n=int(input())
v=sorted(list(map(int,input().split())),reverse=True)
# print(v)

max_v=0
for i in range(n-1):
    max_v+=v[i]*((0.5)**(i+1))

max_v+=v[-1]*0.5**(n-1)
print(max_v)

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

using namespace std;

int digsum(int a) {
    int ret = 0;
    while(a) {
        ret += a % 10;
        a /= 10;
    }
    return ret;
}

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

    int ret = 0, ds;
    for(int i = 1; i <= N; i++) {
        ds = digsum(i);
        if(A <= ds && ds <= B) ret += i;
    }
	cout<< ret << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {

        try (final Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int result = 0;
            if (a > b) {
                result += a + (a - 1);
            } else if (b > a) {
                result += b + (b - 1);
            } else {
                result += a + b;
            }
            System.out.println(result);
        }
    }
}


Measured memory_bytes: 23380
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())
    s = list(input())
    cnt_w = s.count('W')
    cnt_e = s.count('E')

    tmp_w = 0
    tmp_e = 0

    ans = []

    for i in range(n):
        if s[i] == 'W':
            tmp_w += 1
        else:
            tmp_e += 1

        if s[i] == 'W':
            ans.append(tmp_w + cnt_e - tmp_e - 1)
        else:
            ans.append(tmp_w + cnt_e - tmp_e)

    print(min(ans))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5
WEEWW"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """12
WEWEWEEEWWWE"""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """8
WWWWWEEE"""
        output = """3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 20156
import itertools

n = int(input())
p = list(map(int, input().split()))
for i in range(len(p)):
	p[i] = p[i]-1
p = tuple(p)
q = list(map(int, input().split()))

a = list(itertools.permutations(range(n)))

for i in range(len(q)):
	q[i] = q[i]-1
q = tuple(q)
print(abs(a.index(p) - a.index(q)))

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int K;cin>>K;
	long sum = 0;
	rep(a,1,K+1)rep(b,1,K+1)rep(c,1,K+1){
		sum += gcd(a, gcd(b, c));
	}cout<<sum<<endl;
}

Measured memory_bytes: 3672
#include "stdio.h"

int main()
{
	int a, b, x, p;

	while(scanf("%d %d", &a, &b) != EOF){
		p = 1;

		x = a + b;

		while(x >= 10){
			x /= 10;

			p++;
		}

		printf("%d\n", p);
	}

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;


int main()
{


	int n;
	cin >> n;
	int arr[n + 1];
	arr[0] = 0;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];


	int dp[n + 1];

	dp[1] = 0;
	dp[2] = abs(arr[2] - arr[1]);

	for (int i = 3; i <= n; i++)
	{
		dp[i] = min((dp[i - 2] + abs(arr[i] - arr[i - 2])), (dp[i - 1] + abs(arr[i] - arr[i - 1])));
	}

	cout << dp[n] << endl;


}






Measured memory_bytes: 1152
// #include <stdio.h>
// #include <string.h>
//#include <iostream>
#include <math.h>
#include <iostream>
#include <utility>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
#include <string>
#include <set>


using namespace std;
typedef pair<int, int> XY;// Pair型変数の宣言
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
    

int main()
{
  	int Nmax = 20;
    char String[Nmax];
    int N;
    int i,j,k;
    int len;   // 文字列の長さ
    int flag=0;
 
    int A[Nmax];
    int B[Nmax];
    int C[Nmax];
    int M,D;
    int count = 0;
    int d1,d10;
    int d,m;
    ll K;


    scanf("%d ", &N);
 //   scanf("%lld", &K);
   for(i=1;i<=N;i++){
        scanf("%d ",&A[i]);
    }
  
   for(i=1;i<=N;i++){
        scanf("%d ",&B[i]);
    }
  
   for(i=1;i<=N-1;i++){
        scanf("%d",&C[i]);
    }
    
    int man=0;
   	int index;
    for(i=1;i<=N;i++){
       index = A[i];
        man = man + B[index];
      
        if( (i<=(N-1)) && (A[i] <= (N-1))  && (A[i+1] == A[i] +1) ){
            man = man + C[A[i]];
        }
            
    }
 
    
    // 結果出力
 	printf("%d ",man);

  return 0;
   
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int64_t S = 1, T = 1, U = 1;
  for (int i = 0; i < N; i++) {
    S = 10 * S % 1000000007;
    T = 9 * T % 1000000007;
    U = 8 * U % 1000000007;
  }
  int A = S - 2 * T + U;
  while (A >= 1000000007) {
    A -= 1000000007;
  }
  while (A < 0) {
    A += 1000000007;
  }
  cout << A << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    int initial_socket = 1, ans=0;
    while(initial_socket < b){
        initial_socket += a;
        initial_socket--;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>
#define max(p,q)((p)>(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)

int dp[10010];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	while(n--){
		int v,w,c;
		scanf("%d%d%d",&v,&w,&c);
		int k;
		for(k=1;2*k-1<=c;k*=2){
			for(int i=m-w*k;i>=0;i--)dp[i+w*k]=max(dp[i+w*k],dp[i]+v*k);
		}
		k=c-k+1;
		for(int i=m-w*k;i>=0;i--)dp[i+w*k]=max(dp[i+w*k],dp[i]+v*k);
	}
	printf("%d\n",dp[m]);
}


Measured memory_bytes: 2112
package main

import (
	"fmt"
)

const MOD = 1000000007

func main() {
	var s string
	fmt.Scan(&s)

	dp := make([][4]int64, len(s)+1)
	for i := len(s); i >= 0; i-- {
		for j := 3; j >= 0; j-- {
			if i == len(s) {
				if j == 3 {
					dp[i][j] = 1
				} else {
					dp[i][j] = 0
				}
			} else {
				if s[i] == '?' {
					dp[i][j] = dp[i+1][j] * 3
				} else {
					dp[i][j] = dp[i+1][j]
				}
				if j < 3 && (s[i] == '?' || s[i] == "ABC"[j]) {
					dp[i][j] += dp[i+1][j+1]
				}
				dp[i][j] %= MOD
			}
		}
	}
	fmt.Println(dp[0][0])
}


Measured memory_bytes: 4480
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    cout << 180 * (N - 2) << endl;
    return 0;
}


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

int main(){
    int n,k;cin >> n >> k;
    int d;
    int a;
    vector<int> snuke(n,0);
    while(cin >> d){
        for(auto i=0;i<d;i++){
            cin >> a;
            ++snuke.at(a-1);
        }
    }
    int ans=0;
    for(auto&& e:snuke){
        if(e==0){
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;
 
public class Main {
	static final Reader in = new Reader();
	
	public static void main(String[] args) {
		int n=in.nextInt(), m=in.nextInt();
		char[] s=in.next().toCharArray(), t=in.next().toCharArray();
		int g=gcd(n, m);
		for(int i1=0, i2=0; i1<s.length; i1+=n/g, i2+=m/g) {
			if(s[i1]!=t[i2]) {
				System.out.println(-1);
				return;
			}
		}
		System.out.println((long)n*m/g);
	}
	
	static int gcd(int a, int b) {
		while((a%=b)>0&&(b%=a)>0);
		return a^b;
	}
	
	static class Reader {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while(st==null||!st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch(Exception e) {}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

Measured memory_bytes: 26196
///
// File:  d.cpp
// Author: ymiyamoto
//
// Created on Wed Oct  4 21:03:40 2017
//

#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  string str;
  cin >> str;

  for (uint32_t i = 0; i < str.size() - 1; i++) {
    if (str[i] == str[i + 1]) {
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    } else if (i + 2 < str.size() && str[i] == str[i + 2]) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }

  cout << -1 << " " << -1 << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e4;

int main() {
    int h, n; cin >> h >> n;
    vvint dp(1005,vint(10005,inf));
    dp[0][0] = 0;
    REP(i,n+1) {
        int a, b; cin >> a >> b;
    rep(j,10005) {
            chmin(dp[i][j],dp[i-1][j]);
            chmin(dp[i][j],dp[i][max(j-a,0)]+b);
        }
    }
    cout << dp[n][h] << endl;
}

Measured memory_bytes: 39552
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

int ans = 0;
	VI a(5);
	REP(i, 5) {
		cin >> a[i];
		ans += 10 * (a[i] / 10);
		if (a[i] % 10 != 0)ans += 10;
		//cout << ans << endl;
		if(a[i] % 10 != 0)a[i] %= 10;
	}
	SORT(a);
	//cout << a[0] << endl;
	ans -= (10-a[0]);

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



Measured memory_bytes: 256
H, W = map(int, input().split())
Ass = [input() for _ in range(H)]

numHs = [0] * H
numWs = [0] * W
for i in range(H):
    for j in range(W):
        if Ass[i][j] == '#':
            numHs[i] += 1
            numWs[j] += 1

for i in range(H):
    if numHs[i] == 0: continue
    Bs = []
    for j in range(W):
        if numWs[j]:
            Bs += Ass[i][j]
    print(''.join(Bs))


Measured memory_bytes: 3064
#include <stdio.h>

#define n 100000

int N, H[n];

int main(void){
    int i;
    int tmp = 0, ans = 0;

    scanf("%d",&N);
    for (i = 0; i < N; i++){
        scanf("%d", &H[i]);
    }

    for (i = 0; i < N-1; i++){
        if (H[i] >= H[i+1]){
            tmp++;
            if (tmp > ans)
                ans = tmp;
        }
        else{
            tmp = 0;
        }


    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 512
n, m = map(int, raw_input().split())
p = [-1] + map(int, raw_input().split())
parent = {i: i for i in range(1, n+1)}
def root(x):
    if parent[x] != x:
        parent[x] = root(parent[x])
    return parent[x]
for i in range(m):
    x, y = map(int, raw_input().split())
    rx = root(x)
    ry = root(y)
    rx, ry = sorted([rx, ry])
    parent[x] = rx
    parent[y] = rx
    parent[ry] = rx

D = {} # root => (number set, order set)
for i in range(1, n+1):
    r = root(i)
    if not r in D:
        D[r] = (set(), set())
    D[r][0].add(i)
    D[r][1].add(p[i])
print sum([len(S & T) for S, T in D.values()])

Measured memory_bytes: 82144
using System;
using System.Linq;

namespace Part2 {
    class Program {
        static void Main(string[] args) {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            if (a > 9 || b > 9) {
                Console.WriteLine(-1);
            } else {
                Console.WriteLine(a * b);
            }
        }
    }
}

Measured memory_bytes: 13140
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
//const int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;

constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	cin >> N;
	vector<long long int>a(N / 2 + 1);
	vector<long long int>by(N + 1, 1);
	vector<long long int>rev(N + 1, 1);
	for (int i = 1; i <= N; i++) {
		by[i] = by[i - 1] * i;
		by[i] %= MOD;
		rev[i] = power(by[i], MOD - 2, MOD);
	}
	for (int i = 0; i <= N / 2; i++) {
		a[i] = by[N / 2] * rev[N / 2 - i];
		a[i] %= MOD;
		a[i] *= rev[i];
		a[i] %= MOD;
		a[i] *= power(2, N / 2 - i, MOD);
		a[i] %= MOD;
		//cout << i << " " << a[i] << endl;
	}
	auto asum = a;
	for (int i = 1; i <= N / 2; i++) {
		asum[i] += asum[i - 1];
		asum[i] %= MOD;
		//cout << i << " " << asum[i] << endl;
	}
	long long int ans = power(3, N, MOD);
	long long int minus = 0;
	for (int i = 1; i <= N / 2; i++) {
		long long int box = asum[N / 2] - asum[N / 2 - i];
	//	cout << box << endl;
		box += MOD;
		box %= MOD;
		box *= a[i];
		box *= 2;
		box %= MOD;
		minus += box;
		minus %= MOD;
		//cout << i << " " << minus << endl;
	}
	ans -= minus;
	ans += MOD;
	ans %= MOD;
	cout << ans << endl;
}

Measured memory_bytes: 234624
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n,m,v[maxn];
long long cnt[maxn][2];
vector<int> g[maxn];
int p1, p2, len;
long long dfs(int x, int p = 0, int d = 0) {
	++ cnt[x][d & 1];
	long long res = 0;
	for (int u=0;u< g[x].size();++u) {
		if (g[x][u] == p) continue;
		if (x == p1 && g[x][u] == p2) continue;
		if (x == p2 && g[x][u] == p1) continue;
		res += dfs(g[x][u], x, d + 1);
		cnt[x][0] += cnt[g[x][u]][0];
		cnt[x][1] += cnt[g[x][u]][1];
		res += abs(cnt[g[x][u]][0] - cnt[g[x][u]][1]);
	}
	return res;
}
void dfs2(int x, int p = 0) {
	v[x] = v[p] + 1;
	for (int u=0;u< g[x].size();++u) {
		if (g[x][u] == p) continue;
		if (v[g[x][u]]) {
			p1 = x;
			p2 = g[x][u];
			len = v[x] - v[g[x][u]] + 1;
		}
		else dfs2(g[x][u], x);
	}
}
long long calc(long long x) {
	memset(cnt, 0, sizeof(cnt));
	cnt[p1][0] += x;
	cnt[p2][1] += x;
	return dfs(1) + abs(x);
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++ i) {
		int u, v;
		
		scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	if (m == n - 1) {

		long long ans = dfs(1);
		if (cnt[1][0] != cnt[1][1]) return 0 * puts("-1");
		printf("%lld\n", ans);
	}
	else {
		dfs2(1);
		dfs(1);
		if (len & 1) {
			if (abs(cnt[1][0] - cnt[1][1]) & 1) return 0 * puts("-1");
			long long del = (cnt[1][0] - cnt[1][1]) / 2;
			memset(cnt, 0, sizeof(cnt));
			cnt[p1][0] -= del;
			cnt[p2][0] -= del;
			long long ans = dfs(1) + abs(del);
			printf("%lld\n", ans);
		}
		else {
			if (cnt[1][0] != cnt[1][1]) return 0 * puts("-1");
			long long l = - 1e9, r = 1e9, ans = 1e18;
			while (l + 10 <= r) {
				long long midl = (l + r) / 2;
				long long midr = (midl + r) / 2;
				memset(cnt, 0, sizeof(cnt));
				cnt[p1][0] += midl;
				cnt[p2][1] += midl;
				long long res1 = dfs(1,0,0)+abs(midl);
				memset(cnt, 0, sizeof(cnt));
				cnt[p1][0] += midr;
				cnt[p2][1] += midr;
				long long res2 = dfs(1,0,0)+abs(midr);
				ans = min(ans, res1);
				ans = min(ans, res2);
				if (res1 < res2) {
					r = midr - 1;
				}
				else {
					l = midl + 1;
				}
			}
			for (int i = l; i <= r; ++ i) ans = min(ans, calc(i));
			printf("%lld\n", ans);
		}
	}
}


Measured memory_bytes: 15488
#include <bits/stdc++.h>
using namespace std;
int n,t,biao;
int a[2001];
int main(){
	cin >> n >> t >> biao;
	float minv=10000;
	int mini;
	for (int i=1;i<=n;i++) cin >> a[i];
	for (int i=1;i<=n;i++){
		float v=abs((t-a[i]*0.006)-biao);
		if (v<minv){
			minv=v;
			mini=i;
		}
	}
	cout << mini;
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
	input = input.split(" ");
    input = input[0];
    
    var ans = "";	
	for(var i = 1; i <= input.length; i = i + 2){
	    ans += input[i -1]; 
	}
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 10700
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, X;
  cin >> N >> X;

  vector<ll> layers(N+1);
  vector<ll> pat(N+1);
  layers[0] = 1;
  pat[0] = 1;
  FOR(i, 1, N+1){
    layers[i] = 2*layers[i-1] + 3;
    pat[i] = 2*pat[i-1]+ 1;
  }

  ll layer_index = N;
  ll ans = 0;
  while(X>0){
    bool flag=true;
    while(X < layers[layer_index]){
      X--;
      layer_index--;
      if(layer_index<0){
        flag=false;
        break;
      }
    }
    if(!flag) break;
    X -= layers[layer_index];
    ans += pat[layer_index];
    if(X>0){
      X--;
      ans+=1;
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def isqrt(n):
    """integer sqrt: the maximum integer less than or equal to sqrt(n)"""
    x = n
    y = (x + 1) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

def solve(f):
    n, d1, d2 = f.read_int_list()

    a = [[0] * (2*n) for _ in xrange(2*n)]
    d = [d1, d2]

    for i in xrange(2):
        dist = set()
        for dx in xrange(2*n):
            dy2 = d[i] - dx**2
            if dy2 < 0: continue
            dy = isqrt(dy2)
            if dy**2 != dy2: continue

            for sx in [1, -1]:
                for sy in [1, -1]:
                    dist.add((sx*dx, sy*dy))

        vis = [[False] * (2*n) for _ in xrange(2*n)]
        for x in xrange(2*n):
            for y in xrange(2*n):
                if not vis[x][y]:
                    c = 2**i
                    que = [(x, y)]
                    while len(que) > 0:
                        que2 = []
                        for xi, yi in que:
                            if vis[xi][yi]: continue
                            vis[xi][yi] = True
                            a[xi][yi] += c
                            for dx, dy in dist:
                                if 0 <= xi+dx < 2*n and 0 <= yi+dy < 2*n:
                                    que2.append((xi+dx, yi+dy))
                        que = que2
                        c *= -1

    cnt = collections.defaultdict(list)
    for x in xrange(2*n):
        for y in xrange(2*n):
            cnt[a[x][y]].append((x, y))

    for k, v in cnt.items():
        if len(v) >= n**2:
            return "\n".join(["%d %d"%item for item in v[:n**2]])


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


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

int main() {
    int count;
    double score[1000];

    while (true) {
        cin >> count;
        if (count == 0) break;

        double sum = 0;
        for (int i = 0; i < count; i++) {
            cin >> score[i];
            sum += score[i];
        }

        double average = sum / count;
        double sum2 = 0;
        for (int i = 0; i < count; i++) {
            sum2 += pow(score[i] - average, 2);
        }

        printf("%lf\n", sqrt(sum2 / count));
    }
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f

int main(void)
{
    int n;
    cin>>n;
    int now;
    cin>>now;
    ll ans=0;
    for(int i=1;i<n;++i)
    {
        int tmp;
        cin>>tmp;
        if(tmp<now) ans+=now-tmp;
        else now=tmp;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
n, m, x = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))

INF = float('inf')
ans = INF

for i in range(2 ** n):
    bag = []
    score = [0] * m
    flg = True
    for j in range(n):
        if ((i >> j) & 1):
            bag.append(j)

    for j in range(1, m + 1):
        for k in bag:
            inc = a[k][j]
            score[j - 1] += inc

    for k in score:
        if k < x:
            flg = False

    if flg:
        pri = 0
        for j in bag:
            pri += a[j][0]
        if pri < ans:
            ans = pri

if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 68548
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

char str[200005];
int f[200005];

int main()
{
	scanf("%s", str + 1);
	size_t length = strlen(str + 1);
	f[1] = 1;
	if (str[2] == str[1])
		f[2] = 1;
	else
		f[2] = 2;

	for (size_t i = 3; i <= length; i++)
	{
		if (str[i] == str[i - 1])
		{
			f[i] = f[i - 3] + 2;
		}
		else
		{
			f[i] = f[i - 1] + 1;
		}
	}

	printf("%d\n", f[length]);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

int main(){

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

  vector<ll> a(X,0);
  vector<ll> b(Y,0);
  vector<ll> c(Z,0);
  
  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<ll>() );
  sort(b.begin(),b.end(),greater<ll>() );
  sort(c.begin(),c.end(),greater<ll>() );

  priority_queue<pair<ll,vector<int> > > que;

  que.push(make_pair(a[0]+b[0]+c[0], vector<int>{0,0,0}));

  set<vector<int> > st;

  for(int i=0; i<K; i++){
    auto tp=que.top();
    que.pop();
    cout << tp.first << endl;
    vector<int> tpv=tp.second;
    int c0=tpv[0];
    int c1=tpv[1];
    int c2=tpv[2];
    if(c0+1<X && st.count(vector<int>{c0+1,c1,c2})==0) {
      que.push(make_pair(a[c0+1]+b[c1]+c[c2],vector<int>{c0+1,c1,c2}));
      st.insert(vector<int>{c0+1,c1,c2});
    }
    if(c1+1<Y && st.count(vector<int>{c0,c1+1,c2})==0) {
      que.push(make_pair(a[c0]+b[c1+1]+c[c2],vector<int>{c0,c1+1,c2}));
      st.insert(vector<int>{c0,c1+1,c2});
    }
    if(c2+1<Z && st.count(vector<int>{c0,c1,c2+1})==0) {
      que.push(make_pair(a[c0]+b[c1]+c[c2+1],vector<int>{c0,c1,c2+1}));
      st.insert(vector<int>{c0,c1,c2+1});
    }
  }
  
  return 0;
  
}


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

int search(int A[], int n, int t)
{
    int left = 0, right = n - 1;
    int middle;
    while(left <= right)
    {
        middle = (left + right) / 2;
        if(A[middle] > t)
            right = middle - 1;
        else if(A[middle] < t)
            left = middle + 1;
        else
            return 1;
    }
    return 0;
}

int main()
{
    int N1, N2;
    int A[100000];
    int count = 0;
    int t;
    cin >> N1;
    for(int i = 0; i < N1; i++)
        cin >> A[i];
    cin >> N2;
    for(int j = 0; j < N2; j++)
    {
        cin >> t;
        if(search(A, N1, t))
            count += 1;
    }
    cout << count << endl;
}



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

int main() {
	int n,ans=0;
	vector<int> a;
	cin >> n;
	a.resize(n);
	REP(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	REP(i, n) {
		if (i % 2 == 0)ans += a[i];
		else ans -= a[i];
	}
	cout << ans;
	return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void pf(ll a, vl &s) {
	while (a % 2 == 0) {
		a = a / 2;
		s.pb(2);
	}
	for (ll i = 3; i * i <= a; i++) {
		while (a % i == 0) {
			a /= i;
			s.pb(i);
		}
	}
	if (a > 2)s.pb(a);
}
int main() {
	fast_io;
	ll a, b;
	cin >> a >> b;
	if (a > b)swap(a, b);
	set<ll> sa, sb;
	vl sva, svb;
	pf(a, sva);
	// pf(b,svb);
	// set<ll> aa;
	ll ans = 0 ;
	unordered_map<int, int> m;
	for (auto i : sva) {
		if (a % i == 0 && b % i == 0) {
			if (!m[i])ans++;
			m[i] = 1;
		}
	}
	// for(auto i:svb){
	// 	if(a%i==0 && b%i==0)aa.insert(i);
	// }
	cout << 1 + ans;
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 a, b, c, d;
  cin >> a >> b >> c >> d;
  i64 t = a + b + c + d;
  cout << abs(t - max({a, b, c, d}) - min({a, b, c, d}) - (max({a, b, c, d}) + min({a, b, c, d}))) << endl;
  return 0;
}



Measured memory_bytes: 3104
// https://atcoder.jp/contests/abc117/tasks/abc117_c

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

int main() {
    int n, m, tmp;
    vector<int> v, w;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());

    // 座標の差分を計算
    for (int i = 1; i < m; i++) {
        w.push_back(v[i] - v[i - 1]);
    }

    sort(w.begin(), w.end());

    int sum = 0;
    for (int i = 0; i < m - n; i++) {
        sum += w[i];
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1400