akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
  int i,j,k,a=0;
  int N=0;/*お札の枚数*/
  int Y=0;/*お金の総額*/
  int man=0,gosen=0,sen=0;
  scanf("%d %d",&N,&Y);
  for(i=0;i<=N;i++)
  {
    for(j=0;j<=N;j++)
    {
       k=N-(i+j);
      if(k>=0&&i+j+k==N&&10000*k+5000*j+1000*i==Y)
      {
        man=k;
        gosen=j;
        sen=i;
        a=1;
        break;   
      }
    }
  }
  if(a==1)
  {
    printf("%d %d %d",man,gosen,sen);
  }
    else printf("-1 -1 -1");
  return 0;
}
    

Measured memory_bytes: 1732
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

mod = 10 ** 9 + 7

n = ni()
ans = 1
for i in range(1, n+1):
    ans *= i
    ans %= mod
print(ans)


Measured memory_bytes: 3900
#include<stdio.h>
int main()
{
	int h,w,i,j;
	char a[103][103];
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			scanf(" %c",&a[i][j]);
		}
	}
	for(i=0;i<w+2;i++)
	{
		printf("#");
	}
	printf("\n");
	for(i=0;i<h;i++)
	{
		printf("#");
		for(j=0;j<w;j++)
		{
			printf("%c",a[i][j]);
		}
		printf("#\n");
	}
	for(i=0;i<w+2;i++)
	{
		printf("#");
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <cassert>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    int ans = 0;
    rep(i,n)if(i%2 == 0 && a[i]%2)ans++;
    cout << ans << endl;

}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 50005
#define INF 0x3f3f3f3f
#define MST(vis,x) memset(vis,x,sizeof(vis))
int main()
{
    int n,m,x;
    while(scanf("%d%d%d",&n,&m,&x)!=EOF)
    {
        int temp=n+m;
        if(temp>=x)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
N,M=gets.split.map(&:to_i)
 
edges=Array.new(N){Array.new}

M.times do
  l,r,d=gets.split.map(&:to_i)
  l-=1
  r-=1
  edges[l] << [r,d]
  edges[r] << [l,-d]
end

point=Array.new(N,nil)
ok_flag=true
N.times do |base|
  next if !point[base].nil?
  stack=[[base,0]]
  while !stack.empty?
    v,at=stack.pop
    if !point[v].nil?
      #puts "in #{v} guess:#{point[v]} fact:#{at}"
      ok_flag=false if point[v]!=at
      next
    end
    point[v]=at
    edges[v].each do |vv,d|
      stack << [vv,at+d]
    end
  end
end
puts ok_flag ? "Yes" : "No"


Measured memory_bytes: 54908
def check(a,b):
  if a<b:
    return 'up'
  if a>b:
    return 'down'
  return ''

def solve():
  ans = 1
  N = int(input())
  A = list(map(int, input().split()))
  ud = ''
  for i in range(N-1):
    a = check(A[i],A[i+1])
    if ud=='' or ud==a:
      ud = a
      continue
    if a=='':
      continue
    ans += 1
    ud = ''
  return ans
print(solve())


Measured memory_bytes: 19948
import sys
n,k=map(int,input().split())
d=list(input().split())

for i in range(n,100000):
    ans=list(str(i))
    flag=0
    for x in ans:
        if x  in d:
            flag=1
    if flag==0:
        print(''.join(ans))
        sys.exit()

Measured memory_bytes: 3060
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	int A, B;
	sci(A), sci(B);
	int MAX = 1e8+5;
	for (ll i = 0; i < MAX; ++i) {
		ll a = (i * 8)/100;
		ll b = (i * 10)/100;
		if (a == A && b == B) {
			printf("%lld\n", i);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    cs = [0] * n
    for _ in range(m):
        a, b = map(int, input().split())
        cs[a - 1] += 1
        cs[b - 1] += 1
    for c in cs:
        print(c)


if __name__ == '__main__':
    main()


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

using namespace std;

int const NMAX = 100;
int v[1 + NMAX];

int main() {

  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1;i <= n;i++){
    cin >> v[i];
  }
  sort(v+1, v+n+1);
  for(int i = 1;i <= n;i++){
    ans += (-1 * (i % 2)) * v[i] + ( 1 * (i % 2 == 0)) * v[i];
  }
  cout << abs(ans);
  return 0;
}


Measured memory_bytes: 3644
while True:
  a, op, b = input().split()
  a = int(a)
  b = int(b)

  if op == "?":
    break
  elif op == "+":
    answer = a + b
  elif op == "-":
    answer = a - b
  elif op == "*":
    answer = a * b
  elif op == "/":
    answer = a / b

  print(int(answer))


Measured memory_bytes: 5596
n = int(input())
d = list(map(int, input().split()))

a = [0] * n
for i in range(n):
    a[d[i]] += 1

if a[0] == 1 and d[0] == 0:
    ans = 1
    for i in range(1, n):
        ans *= a[i-1]**a[i]
        ans %= 998244353

    print(ans)
else:
    print(0)

Measured memory_bytes: 20492
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long a[100010];
int main() {
	int n;
	cin >> n;
	long long co = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		co += a[i] / 2;
	}
	bool b = false;
	for (int i = 0; i < n; i++) {
		if (a[i] == 0) {
			b = false;
		}
		if (b == true && a[i] % 2 != 0) {
			co++;
			b = false;
		}
		else if (a[i] % 2 != 0) {
			b = true;
		}
	}
	cout << co << endl;
	return 0;
}


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

int main(){
  int N; cin >> N;
  map<string, long long> mp;
  for(int i=0; i<N; i++){
    string s; cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }

  long long ans = 0;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
    ans += (itr -> second) * (itr -> second - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
def f():
    return int(raw_input())
def f2():
    return map(int, raw_input().split())

def merge(left, mid, right):
    L = S[left:mid]
    R = S[mid:right]
    lp, rp, xp = 0, 0, 0
    a, b = L[0], R[0]
    c = right - left
    x = [0] * c
    flg = True
    
    while flg:
        while flg and a <= b:
            x[xp] = a
            lp += 1
            xp += 1
            try:
                a = L[lp]
            except:
                for e in R[rp:]:
                    x[xp] = e
                    xp += 1
                flg = False
        while flg and a >= b:
            x[xp] = b
            rp += 1
            xp += 1
            try:
                b = R[rp]
            except:
                for e in L[lp:]:
                    x[xp] = e
                    xp += 1
                flg = False
    S[left:right] = x
    return c

def mergesort(left, right):
    c = 0
    if left + 1 < right:
        mid = (left + right)/2
        c += mergesort(left, mid)
        c += mergesort(mid, right)
        c += merge(left, mid, right)
    return c

global S
n = f()
S = f2()

c = mergesort(0, n)
print " ".join(map(str,S))
print c

Measured memory_bytes: 52884
#include <cstdio>
int k, n, m;

int main() {
	scanf ( "%d %d %d", &k, &n, &m );
	for ( int i = n;i <= m;i ++ )
		if ( i % k == 0 ) return ! printf ( "OK" );
	printf ( "NG" );
	return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
#include<unordered_map>
#include<algorithm>
#include <cstdlib>
#include <complex>
/*
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*    ▀▀       ▀▀▀▀▀▀    ▀     ▀▀▀▀▀▀      ▀    ▀
*   ▀  ▀      ▀         ▀     ▀            ▀  ▀
*  ▀    ▀     ▀ ▀ ▀     ▀     ▀ ▀ ▀         ▀
* ▀ ▀▀▀▀ ▀    ▀         ▀     ▀             ▀
*▀        ▀   ▀         ▀     ▀             ▀
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*/
using namespace std;
void afify()
{
	ios::sync_with_stdio(0);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
//===============================================
#define ll long long
#define ld long double
#define mk make_pair
#define loop(i,intial,n)  for(int i=(intial);i<n;i++)
#define loopn(j,n,ends) for(int j=int(n-1);j>=ends;j--)
#define loopm(name)  for(auto it : name)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(v) v.begin(),v.end()
#define PI (ld)(3.14159265358979323846)
//===============================================
#define SF(a) scanf("%d",&a)
#define SF2(a,b) scanf("%d %d",&a,&b)
#define SFLL(a) scanf("%lld",&a)
#define SFLL2(a,b) scanf("%lld %lld",&a,&b)
#define PF(a) printf("%d\n",a)
#define PFLL(a) printf("%lld\n",a)
//===============================================
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <vi> vvi;
typedef vector <vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;
typedef stringstream ss;
const double EPS = 1e-4;
const ll oo = (ll) 1e8 + 7;
const ll N = 1e5 + 18;
const ll mod = 1073741824;
//int dx[] = { 0, 0, -1, 1 };
//int dy[] = { 1, -1, 0, 0 };
//int dx[] = { 1,1,0,-1,-1,-1,0,1 };
//int dy[] = { 0,1,1,1,0,-1,-1,-1 };
//freopen("largest.in", "r", stdin);
//freopen("output.txt", "w", stdout);

int main()
{
	afify();
	string s;
	cin>>s;
	loop(i,0,s.length()-8)cout<<s[i];


	return 0;
}


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

int main(void) {
    int k;
    int a, b;
    cin >> k;
    cin >> a >> b;

    bool flag = false;

    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            flag = true;
            break;
        }
    }

    if (flag) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
s = input()
a = ""
for i in range(0, len(s)):
  if s[i] == "0":
    a += "0"
  elif s[i] == "1":
    a += "1"
  elif s[i] == "B" and len(a) != 0:
    b = a[0:-1]
    a = b
print(a)

Measured memory_bytes: 2940
import math

MINUTES_L = 6       # 長針が1分間で動く角度
MINUTES_S = 0.5     # 短針が1分間で動く角度
HOURS_S = 30        # 短針が1時間で動く角度

A, B, H, m = map(int, input().split())

angle_L = MINUTES_L * m
angle_S = HOURS_S * H + MINUTES_S * m

# 長針が示す座標を求める
radian = angle_L * math.pi / 180
y_L = math.sin(radian) * B
x_L = math.cos(radian) * B

# 短針が示す座標を求める
radian = angle_S * math.pi / 180
y_S = math.sin(radian) * A
x_S = math.cos(radian) * A

# 2点間の距離
ans = math.sqrt((x_L - x_S) * (x_L - x_S) + (y_L - y_S) * (y_L - y_S))

print(ans)


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

using namespace std;

int main(){
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    char a, b, c;
    a = s1[0];
    b = s2[0];
    c = s3[0];
    cout << a << b << c << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1e5)+10;
int n,a[3];
char s[maxn][3];
char ans[maxn];
void No() { printf("No\n"); exit(0); }
void Yes() {
	printf("Yes\n");
	for (int i=1;i<=n;i++) printf("%c\n",ans[i]);
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	read(a[0]); read(a[1]); read(a[2]);
	for (int i=1;i<=n;i++) {
		scanf("%s",s[i]+1);
	}
	s[n+1][1]='A',s[n+1][2]='B';
	int x,y,z,p,q;
	for (int i=1;i<=n;i++) {
		x=s[i][1]-'A',y=s[i][2]-'A';
		if (!a[x]&&!a[y]) No();
		if (!a[x]) z=x;
		else if (!a[y]) z=y;
		else {
			if (a[y]==1) {
				p=s[i+1][1]-'A',q=s[i+1][2]-'A';
				if (y==p||y==q) z=y; else z=x;
			} else z=x;
		}
		a[z]++;
		a[x+y-z]--;
		ans[i]='A'+z;
	}
	Yes();
	
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 4252
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    ll a;
    string s;
    cin >> a >> s;
    if (a >= 3200) {
        cout << s;
    } else {
        cout << "red";
    }

    return 0;
}

Measured memory_bytes: 256
#include   <stdio.h>
int main()
{


int   m,f,r;
while(1)
{
scanf("%d %d %d",&m,&f,&r);
if(m==-1&&f==-1&&r==-1){
break;
}
if(m==-1||f==-1){
puts("F");
}
else if(m+f>=80){
puts("A");
}
else if(m+f>=65){
puts("B");
}
else if(m+f>=50||r>=50){
puts("C");
}
else if(m+f>=30){
puts("D");
}
else{
puts("F");
}
}


return 0;
}


Measured memory_bytes: 2060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const int maxN = 110;

#define FORU(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define REPU(i, r) for (int i = 0; i < r; ++i)
#define LL long long
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define PINT pair < ll, int >
#define BIT(x, i) ((x >> i) & 1)
#define NUM_SET_BIT __builtin_popcountll

int a[maxN * maxN], res[maxN][maxN], m, n, p;

int main() {
    cin >> m >> n;
    cin >> p;
    FORU(i, 1, p) cin >> a[i];
        
    int k = 1;
    FORU(i, 1, m) {
        int s = (i % 2) ? 1 : n;
        int t = (i % 2) ? n + 1 : 0;
        int j = (i % 2) ? 1 : -1;
        while (s != t) {
            res[i][s] = k;
            --a[k]; s += j;
            if (a[k] == 0) ++k;
        }
    }

    FORU(i, 1, m) {
        FORU(j, 1, n) printf("%d ", res[i][j]);
        cout << endl;
    }
}


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

int main(){
  string num;
  cin >> num;
  int a = (num[0]-'0');
  int b = (num[1]-'0');
  int c = (num[2]-'0');
  int d = (num[3]-'0');

  if(a+b+c+d==7){
    cout << a << '+' << b << '+' << c << '+' << d << '=' << 7 << endl;
    return 0;
  }
  else if(a+b+c-d==7){
    cout << a << '+' << b << '+' << c << '-' << d << '=' << 7 << endl;
    return 0;
  }
  else if(a+b-c+d==7){
    cout << a << '+' << b << '-' << c << '+' << d << '=' << 7 << endl;
    return 0;
  }
  else if(a+b-c-d==7){
    cout << a << '+' << b << '-' << c << '-' << d << '=' << 7 << endl;
    return 0;
  }
  else if(a-b+c+d==7){
    cout << a << '-' << b << '+' << c << '+' << d << '=' << 7 << endl;
    return 0;
  }
  else if(a-b+c-d==7){
    cout << a << '-' << b << '+' << c << '-' << d << '=' << 7 << endl;
    return 0;
  }
  else if(a-b-c+d==7){
    cout << a << '-' << b << '-' << c << '+' << d << '=' << 7 << endl;
    return 0;
  }
  else if(a-b-c-d==7){
    cout << a << '-' << b << '-' << c << '-' << d << '=' << 7 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
n, y = map(int, input().split())

r = (-1, -1, -1)

for i in range(n + 1):
  for j in range(n + 1 - i):
    if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
      print(i, j, n - i - j)
      exit()

print(*r)

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

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int total = 0;
  for (size_t i = 1; i < 10000; i++) {
    if (i % a == 0) {
      total += a;
      if (total % b == c) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }

  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

if 0 in A:
    print(0)
    exit()

dp = [1] * (n + 1)
for i in range(n):
    dp[i + 1] = dp[i] * A[i]
    if dp[i + 1] > 10 ** 18:
        print(-1)
        exit()

print(dp[n])

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

template<class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  
  vector<vector<ll>> a(n, vector<ll>(3));
  rep(i, n) rep(j, 3) cin >> a[i][j];
  
  vector<vector<ll>> dp(n + 1, vector<ll>(3));
  rep(i, n) rep(j, 3) rep(k, 3) {
    if (j == k) continue;
    chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
  }
  
  ll ans = 0;
  rep(i, 3) chmax(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14012
a,b,c=map(int,input().split())
m=list(map(int,input().split()))
s=t=0
for i in range(a):
    n=list(map(int,input().split()))
    for j in range(b):
        s+=n[j]*m[j]
    if s+c>0:
        t+=1
    s=0
print(t)

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

typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

void solve(){
	
}

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
	int n; cin>>n;
    double d; cin>>d;
    int ans=0;
    for (int i=0; i<n; i++){
        double x,y; cin>>x>>y;
        double dist = sqrt(x*x + y*y);
        if (dist <= d){
            ++ans;
        }
    }
	cout<<ans<<'\n';
	return 0;
}
/*
NARCO
*/


Measured memory_bytes: 3812
m,n=map(int,input().split())
bitn=format(n,'b')
flag=[0]*len(bitn)
flag[0]=m
for i in range(1,len(bitn)):
    flag[i]=(flag[i-1]**2)%1000000007
ans=1
bitn=bitn[::-1]
for i in range(len(bitn)):
    if bitn[i]=='1':
        ans=(ans*flag[i])%1000000007
print(ans)


Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp,t, n,j, a[200600], ans;
bool cond;
char c;
string s;
int main()
{
    //I am Monim, a tiny creature of Allah
    cin >> n >> j >> t;
    cout << (n/j+(n%j>0))*t << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int n, m, a;
    while (cin >> n >> m >> a, n)
    {
        vector<tuple<int, int, int>> v(m);
        for (int i = 0; i < m; ++i)
        {
            int h, p, q;
            cin >> h >> p >> q;
            v[i] = make_tuple(h, p, q);
        }
        sort(v.begin(), v.end(), greater<tuple<int, int, int>>());
        for (auto x : v)
        {
            if (get<1>(x) == a)
                a = get<2>(x);
            else if (get<2>(x) == a)
                a = get<1>(x);
        }
        cout << a << endl;
    }
}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;


int main()
{
  int N;
  multiset<int> A;
  map<int, int> mokuji;
  int Q;
  int B[100050];
  int C[100050];
  long long sum = 0;
  
  //読み込み
  cin >> N;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    if(mokuji.count(a)){
      mokuji[a] += 1;
    }else{
          mokuji[a] = 1;
    }
    sum += a;
   
  }

  cin >> Q;
  for(int i=0;i<Q;i++){
    cin >> B[i] >>C[i];
  }

  
  //操作
  for(int i=0;i<Q;i++){
    //リストにある場合
    if(mokuji.count(B[i])){
      if(mokuji.count(C[i])){
        mokuji[C[i]] += mokuji[B[i]];
      }else{
        mokuji[C[i]] = mokuji[B[i]];
      }
      
      sum -= B[i]*mokuji[B[i]];
      sum += C[i]*mokuji[B[i]];
      mokuji.erase(B[i]);
    }
    cout << sum << endl;
  }

    
  
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

const ll M = 998244353;
vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)


ll mpow(ll x, ll n){
  ll ans = 1;
  while(n != 0){
	if(n&1) ans = ans*x % M;
	x = x*x % M;
	n = n >> 1;
  }
  return ans;
}

ll comb(ll a, ll b){
  if(a == 0 && b == 0)return 1;
  if(a < b || a < 0)return 0;
  ll tmp = ifac[a-b]* ifac[b] % M;
  return tmp * fac[a] % M;
}

int main()
{
  ll n, p, even=0, odd=0, a, m, c=0;
  cin >> n >> p;
  m = pow(2, n);
  
  forll(i, 0, n){
	cin >> a;
	if (a % 2 == 0)
	  even++;
	else
	  odd++;
  }

  fac[0] = 1;
  ifac[0] = 1;
  for(ll i = 0; i<300000; i++){
	fac[i+1] = fac[i]*(i+1) % M;
	ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M;
  }
  
  if(p == 0){
	for (ll i=1; i<=odd; i+=2)  // how many sacs to choose
	  c += comb(odd, i);
  }
  else{
	if (odd == 0){
	  cout << 0 << endl;
	  return 0;
	}
	for(ll i=i; i<=odd; i+=2)
	  c += comb(odd, i);
  }
  cout <<setprecision(20) << m - c * pow(2, even) << endl;
}


Measured memory_bytes: 4992
#include<stdio.h>
int main(void)
{
  int n,k;
  double sum=0;
  scanf("%d",&n);
  scanf("%d",&k);
  for (int i=1;i<=n;i++)
  {
    int temp=i;
    for (int j=0;j<100;j++)
    {
      if(temp>=k)
      {
        sum+=1.0/temp*i;
        break;
      }
      temp*=2;
    }
  }
  printf("%10.10f",sum/n);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main(){
    string s;
    cin>>s;
    int l=s.length();
    int ans=0;
    char c;
    c=s[0];
    for(int i=1;i<l;i++){
        if(s[i]!=c){
            ans++;
            c=s[i];
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

ll convert(ll x) {
    ll ret = 0;
    string s = to_string(x);

    for (char c : s) ret += c - '0';

    return ret;
}

int main() {
    int m; cin >> m;
    vector<ll> d(m), c(m);

    REP(i, m) cin >> d[i] >> c[i];

    ll sum = 0, n = 0;

    vector<ll> p(m);
    REP(i, m) {
        sum += c[i] * d[i];
        n += c[i];
    }

    cout << n + (sum - 1) / 9 - 1 << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main()
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> cntsum(n, 0);
    repl(i, 1, n) {
        if(s[i - 1] == 'A' && s[i] == 'C') {
            cntsum[i] = cntsum[i - 1] + 1;
        }
        else cntsum[i] = cntsum[i - 1];
    }
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        cout << cntsum[r] - cntsum[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 3848
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int[] alphabet = new int[26];
		
		while (sc.hasNext()) {
			String s = sc.nextLine();
			for (int i=0; i<s.length(); i++) {
				char c = s.charAt(i);
				if ('a'<=c && c<='z') {
					alphabet[c-97]++;
				}
				else if ('A'<=c && c<='Z') {
					alphabet[c-65]++;
				}
			}
		}
		
		for (int i=0; i<26; i++) {
			System.out.println((char)(i+97)+" : "+alphabet[i]);
		}
		
		
		
	}
}


Measured memory_bytes: 26196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define each(i, n) for(auto&& i: n)

int main() {
  char C;
  cin >> C;
  C++;
  cout << C << endl;
}  

Measured memory_bytes: 256
#include "stdio.h"



int main(void) {

	int number;
	int array[20], barray[20], carray[19];
	int sum = 0;
	scanf("%d", &number);

	for (int i = 1; i<=number; i++) {
		scanf("%d", &array[i]);
	}
	for (int i = 1; i<=number; i++) {
		scanf("%d", &barray[i]);
	}
	for (int i = 1; i<=number - 1; i++) {
		scanf("%d", &carray[i]);
	}

	for (int i = 1; i<=number; i++) {
		sum += barray[array[i]];
			if ((array[i] == array[i-1] + 1) && (i != 1)) {
				sum += carray[array[i-1]];
			}
	}
	printf("%d\n", sum);

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
char s[111];
int main(){
    cin>>s + 1;
    if(s[1] == 'S'){
        puts("Cloudy");
    }
    if(s[1] == 'C'){
        puts("Rainy");
    }
    if(s[1] == 'R'){
        puts("Sunny");
    }
    return 0;
}

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

using namespace std;

int V[105];

int memo[55][55][105];

int dp(int s, int e, int k){
	if(s > e){
		return 0;
	}else if(k == 0){
		return 0;
	}else if(memo[s][e][k] != -1){
		return memo[s][e][k];
	}else{
		int ans = 0;
		if(k >= 2){
			ans = max(ans, dp(s+1, e, k-2)); 
			ans = max(ans, dp(s, e-1, k-2)); 
		}
		ans = max(ans, V[s]+dp(s+1, e, k-1)); 
		ans = max(ans, V[e]+dp(s, e-1, k-1)); 
		
		return memo[s][e][k] = ans;
	}
}

int main(){
	int N, K;
	scanf("%d%d", &N, &K);
	for(int i = 0; i < N; i ++){
		scanf("%d", &V[i]);
	}
	
	memset(memo, -1, sizeof(memo));
	printf("%d", dp(0, N-1, K));
	return 0;
}


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

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

	int a,b,c,d; cin >> a >> b >> c >> d;

	int l1,l2;
	if(a%d==0) l1 =(a/d)-1;
	else l1 =a/d;

	if(c%b==0) l2=(c/b)-1;
	else l2 = c/b;	
	
	if(l1>=l2) cout <<"Yes";
	else cout << "No";
	

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
using ll = long long;
using ull =  unsigned long long;

#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#define pf printf
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define sll(x,y) scanf("%lld %lld",&x,&y)

#define pii pair<int,int>
#define nl '\n'
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
#define out(x) cout <<"#x = "<<x<<endl
#define outt(x,y) cout <<"# "<<x<<" "<<y<<endl
#define mem(array,value) memset(array,value,sizeof(array))
#define MX 10005

ll n,weight;
ll w[107];
ll v[107];
ll dp[107][100007];
ll solve(ll pos,ll cap)
{
	if(pos==n)return 0;
	if(dp[pos][cap]!=-1)return dp[pos][cap];
	ll ans=0;
	ans = solve(pos+1,cap);
	if(w[pos]+cap<=weight){
		ans = max(ans,v[pos]+solve(pos+1,cap+w[pos]));
	}
	return dp[pos][cap]=ans;
}
int main()
{
	fast_io

	mem(dp,-1);
	cin >>n>>weight;

	for(int i=0;i<n;i++){
		cin >>w[i]>>v[i];
	}
	
	cout << solve(0,0)<<endl;
	return 0;
}

Measured memory_bytes: 83840
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;

int D;
VI c;
VVI s;

VI calc_scores(const VI &t) {
	VI scores(D, 0);
	VI lastday(26, 0);

	int score = 0;
	for (int i = 0; i < D; i++) {
		int day = i + 1;
		int contest = t[i] - 1;
		lastday[contest] = day;
		score += s[i][contest];

		for (int j = 0; j < 26; j++) {
			score -= c[j] * (day - lastday[j]);
		}
		scores[i] = score;
	}

	return scores;
}

int main() {
	cin >> D;

	c.assign(26, 0);
	for (int i = 0; i < c.size(); i++) {
		cin >> c[i];
	}
	s.assign(D, VI(26, 0));
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < s[i].size(); j++) {
			cin >> s[i][j];
		}
	}

	VI t(D, 0);
	for (int i = 0; i < D; i++) {
		cin >> t[i];
	}

	int M;
	cin >> M;
	vector<int> d(M), q(M);
	for (int i = 0; i < M; i++) {
		cin >> d[i] >> q[i];
	}

	VI ans(M, 0);
	for (int i = 0; i < M; i++) {
		t[d[i]-1] = q[i];
		auto scores = calc_scores(t);
		ans[i] = scores.back();
	}

	for (auto x: ans) {
		cout << x << endl;
	}
	return 0;
}


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

int main()
{
  	int a, b, c;
  	cin>>a>>b>>c;
  	map<int, int> m;
  	m[a]++;m[b]++;m[c]++;
  	int count = 0;
  	for(auto i = m.begin(); i != m.end(); i++)
    {
    	if(i -> second != 0)
          	count++;
    }
  	cout<<count<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a,b,c;
	scanf ("%d",&a);
	scanf ("%d",&b);
	scanf ("%d",&c);
	if(a-b<=c)
	  printf("%d",c-(a-b));
	else 
	  printf("%d",0);
	
	// your code goes here
	return 0;
}


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

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i];
    sort(v.begin(), v.end());

    long long ans = 0;
    for(int i=0; i<n; ++i){
        int k = i + 2;
        for(int j=i+1; j<n; ++j){
            while(k < n && v[k] < v[i] + v[j])
                ++ k;
            ans += max(0, k - j - 1);
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

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

    int x = N % 10;
    string ans;
    if(x == 3)
        ans = "bon";
    else if(x == 0 || x == 1 || x == 6 || x == 8)
        ans = "pon";
    else
        ans = "hon";

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


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

#define int int64_t


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    for (int i=0; i<5; i++) {
        int tmp;
        cin >> tmp;
        if (tmp == 0) {
            cout << i+1;
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 3192
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
   
using namespace std;
 
#define pi 3.141592653589793
 
bool isfinish(char p[8][8][8], int n, int m, int z[8][8], int x, int y)
{
    int dx[13] = {1, 0, 0, 1, 1, 0, 0, 1, -1, 1, 1, -1, 1};
    int dy[13] = {0, 1, 0, 1, -1, 1, 1, 0, 0, 1, 1, 1, -1};
    int dz[13] = {0, 0, 1, 0, 0, 1, -1, 1, 1, 1, -1, 1, 1};
    for(int i = 0; i < 13; i++){
        int ballnum = 1;
        int nx = x + dx[i], ny = y + dy[i], nz = z[x][y] - 1 + dz[i];
        char c = p[x][y][z[x][y] - 1];
        while(nx > 0 && ny > 0 && nz > 0 && nx <= n && ny <= n && nz <= z[nx][ny] - 1 && c == p[nx][ny][nz]){
            ballnum++;
            nx += dx[i];
            ny += dy[i];
            nz += dz[i];
        }
        nx = x - dx[i];
        ny = y - dy[i];
        nz = z[x][y] - 1 - dz[i];
        while(nx > 0 && ny > 0 && nz > 0 && nx <= n && ny <= n && nz <= z[nx][ny] - 1 && c == p[nx][ny][nz]){
            ballnum++;
            nx -= dx[i];
            ny -= dy[i];
            nz -= dz[i];
        }
        // cout << ballnum << endl;
        if(ballnum >= m) return true;
    }
    return false;
}
 
int main()
{
    int n, m, p;
    while(1){
        cin >> n >> m >> p;
        if(n == 0 && m == 0 && p == 0) break;
        char puzzle[8][8][8];
        int height[8][8];
        for(int i = 1; i < n + 1; i++){
            for(int j = 1; j < n + 1; j++){
                height[i][j] = 1;
                for(int k = 1; k < n + 1; k++){
                    puzzle[i][j][k] = 'n';
                }
            }
        }
        // height[i][j]: (x, y) = (i, j)の現在の高さ、次に玉が置かれる位置
        int x, y;
        int ans = -1;
        for(int i = 0; i < p; i++){
            cin >> x >> y;
            if(ans != -1) continue;
            if(i % 2 == 0) puzzle[x][y][height[x][y]] = 'b';
            else puzzle[x][y][height[x][y]] = 'w';
            height[x][y]++;
            if(isfinish(puzzle, n, m, height, x, y)) ans = i + 1;
        }
        if(ans == -1) cout << "Draw" << endl;
        else if(ans % 2 == 1) cout << "Black" << " " << ans << endl;
        else cout << "White" << " " << ans << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
ll A[MAX_N] = {};
ll diff[MAX_N] = {};    // A[i] と A[i+1] の差分

signed main()
{
    cin >> N;
    ll sum = 0;
    REP(i, N) {
        cin >> A[i];
        sum += A[i];
        if(i > 0) { diff[i-1] = A[i] - A[i-1]; }
    }
    diff[N-1] = A[0] - A[N-1];
    ll fact = 0;    // 1 回で加算される数
    for(int i = 1; i <= N; ++i) {
        fact += i;
    }
    ll turn = sum / fact;   // 今回必要なターン数

    bool isAllSame = true;
    REP(i, N-1) {
        if(diff[i] != diff[i+1]) {
            isAllSame = false;
            break;
        }
    }
    if(isAllSame) {
        if(turn % N != 0 || turn * fact != sum) { printf("NO\n"); }
        else { printf("YES\n"); }
        return 0;
    }

    // diff が現実的な値か
    ll diff_sum = 0;
    REP(i, N) {
        diff_sum += diff[i];
        if(diff[i] <= turn && diff[i] >= (1 * turn - N * turn) &&
           abs(diff[i] - turn) % N == 0) {
            // OK
        } else {
            printf("NO\n");
            return 0;
        }
    }
    if(diff_sum == 0) { printf("YES\n"); }
    else { printf("NO\n"); }
    return 0;
}


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

int main() {
	double d[10];
	double a;
	while (cin >> a) {
		d[0] = a;
		d[1] = d[0] * 2;
		d[2] = d[1] / 3;
		d[3] = d[2] * 2;
		d[4] = d[3] / 3;
		d[5]=d[4] * 2;
		d[6] = d[5] / 3;
		d[7] = d[6] * 2;
		d[8] = d[7] / 3;
		d[9] = d[8] * 2;
		double ca=0;
		for (int i = 0; i < 10; i++) {
			ca += d[i];
		}
		cout << fixed << setprecision(9) << ca << endl;
	}
	return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, K;
    cin >> N >> K;
    ll A[N];
    rep(i, N) cin >> A[i];
    sort(A, A+N, greater<ll>() );
    ll n = N, m = MOD, inv[n+1];
    rep2(i, 1, n){
        inv[i] = 1;
        ll e[31];
        e[0] = i;
        rep2(j, 1, 30) e[j] = (e[j-1]*e[j-1]) % m;
        ll k = m-2;
        int cnt = 0;
        while(k > 0){
            if(k % 2 == 1) inv[i] *= e[cnt], inv[i] %= m;
            k /= 2;
            cnt++;
        }
    }
    ll fac[N+1], ifac[N+1];
    fac[0] = 1, ifac[0] = 1;
    rep2(i, 1, N){
        fac[i] = (fac[i-1]*i)%MOD;
        ifac[i] = (ifac[i-1]*inv[i])%MOD;
    }
    ll ans = 0;
    rep(i, N-K+1){
        ll a = (MOD+A[i]+MOD-A[N-1-i])%MOD;
        ll c = fac[N-1-i];
        c *= ifac[K-1], c %= MOD;
        c *= ifac[N-K-i], c %= MOD;
        ans += (a*c)%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
# お約束
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def parse(args, *params):
    return tuple(p(v) for p, v in zip(params, next(args).split()))

from bisect import bisect_right as bsr

# エントリーポイント
def main(args):
    A, B, Q = parse(args, int, int, int)
    S = list(int(next(args)) for _ in range(A))
    T = list(int(next(args)) for _ in range(B))
    X = tuple(int(next(args)) for _ in range(Q))

    s = [-INF] + S + [INF]
    t = [-INF] + T + [INF]
    for x in X:
        sr = bsr(s, x)
        sl = sr - 1
        tr = bsr(t, x)
        tl = tr - 1
        min_cost = INF
        for st in [s[sl], s[sr]]:
            for tt in [t[tl], t[tr]]:
                min_cost = min(min_cost, abs(st - x) + abs(tt - st))
                min_cost = min(min_cost, abs(tt - x) + abs(tt - st))
        print(min_cost)

import sys
if __name__ == '__main__':
    main(iter(sys.stdin.read().split("\n")))


Measured memory_bytes: 42008
N = int(input())
A = list(map(int, input().split()))

def bubbleSort(A, N):
    counter = 0
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                temp = A[j-1]
                A[j-1] = A[j]
                A[j] = temp
                counter += 1
                flag = 1
        i +=1
    return A,counter
    
A, counter = bubbleSort(A, N)

print(' '.join(repr(e) for e in A))
print(counter)



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

int main(){
    int s;
    int count = 1;
    cin >> s;
    while(true){
        if(s == 4 || s == 2 || s == 1){
            cout << count+3 << endl;
            break;
        }
        if(s%2 == 0){
            s = s/2;
        }else{
            s = 3*s + 1;
        }
        count++;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k; cin >> n >> k;
    vector<int> data(n + 1, 0);
    for (int i = 1 ; i <= n ; i++)
        cin >> data[i], data[i]--;
    unordered_map<int, int> cnt;
    int sum1 = 0, sum2 = 0; LL ans = 0;
    for (int i = 0 ; i <= n ; i++) {
        sum1 += data[i];
        sum1 %= k;
        if (i - k >= 0) {
            sum2 += data[i - k];
            sum2 %= k;
            cnt[sum2]--;
        }
        ans += cnt[sum1];
        cnt[sum1]++;
    }
    cout << ans << '\n';
}

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

#define fi first
#define se second

using namespace std;

typedef long long ui;

int x;

int exgcd(int a, int b, int &x, int &y) {
	if (b == 0) {
		x = 1; y = 0; return a;
	}
	int res = exgcd(b, a % b, x, y);
	int t = x; x = y; y = t - a / b * y;
	return res;
}

int main() {
	scanf("%d", &x);
	int p, q;
	int ha = exgcd(x, 360, p, q);
	p = (p % 360 + 360) % 360;
	printf("%d\n", 360 / ha);
	return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();


// Description: DP using Convex hull Trick
// TimeComplexity: $ \mathcal{O}(n)$
// Verifyed: AOJ 2725

//Inequality sign min >=  max <=

template<typename T> class CHT {
public:
	T getval(T x) {
		while (deq.size() >= 2 && f(deq[0], x) >= f(deq[1], x)) deq.pop_front();
		return f(deq[0], x);
	}

	void push(T ca, T cb) {
		const int idx = a.size();
		a.push_back(ca), b.push_back(cb);
		while (deq.size() >= 2 && check(idx)) deq.pop_back();
		deq.push_back(idx);
	}

	int size() {return deq.size();}
private:
	vector<T> a, b;
	deque<int> deq;

	T f(int idx, T x) {return 1LL * a[idx] * x + b[idx];}

	bool check(int idx) {
		const int i = deq[size() - 2], j = deq[size() - 1], k = idx;
		return (b[j] - b[i]) * (a[k] - a[j]) <= (b[k] - b[j]) * (a[j] - a[i]);
	}
};

const int limit = 200010;
ll dp[limit];

int main(void){
	ll n,c;
	cin >> n >> c;
	vector<ll> h(n);
	rep(i,n) cin >> h[i];
	CHT<ll> cht;

	rep(i,n){
		if(i){
			ll cur = cht.getval(h[i]) + h[i] * h[i] + c;
			dp[i] = cur;
		}
		cht.push(- 2LL * h[i], dp[i] + h[i] * h[i]);
	}

	cout << dp[n-1] << endl;

	return 0;
}

Measured memory_bytes: 7012
#include<stdio.h>
int main()
{
	int a,b,c,x,i,j,k,t=0;
 
	scanf("%d%d%d%d",&a,&b,&c,&x);
 
	for(i=0;i<=a;i++)
		for(j=0;j<=b;j++)
			for(k=0;k<=c;k++){
				if(i*500+j*100+k*50==x)
					t++;
			}
	printf("%d",t);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int n;
ll a, b;
int arr[5010];
ll D[5010][5010];

int main() {
    int i, j;

    scanf("%d%lld%lld",&n,&a,&b);
    for (i=1;i<=n;i++) {
        scanf("%d",&arr[i]);
    }
    memset(D,0x3f,sizeof(D));
    D[0][0] = 0;
    for (i=1;i<=n;i++) {
        for (j=0;j<arr[i];j++) {
            D[i][arr[i]] = min(D[i][arr[i]],D[i-1][j]);
            D[i][j] = min(D[i][j],D[i-1][j]+a);
        }
        for (j=arr[i]+1;j<=n;j++) {
            D[i][j] = min(D[i][j],D[i-1][j]+b);
        }
    }
    ll mini = LINF;
    for (i=0;i<=n;i++) mini=min(mini,D[n][i]);
    printf("%lld\n",mini);

    return 0;
}


Measured memory_bytes: 196480
#include<bits/stdc++.h>
using namespace std;
bool isok(string s)
{
	for (int i=0;i<(int)s.length();i++)
		if (s[i]!='R')
			return false;
	return true;
}
int main()
{
	int mx=0,res;
	string s;
	cin>>s;
	if (s=="SRS")
	{
		cout<<1<<endl;
		return 0;
	}
	for (int i=0;i<(int)s.length();i++)
	{
		res=0;
		for (int j=1;i+j<=(int)s.length();j++)
		{
			if (isok(s.substr(i,i+j)))
			{
				res++;
			}
		}
		mx=max(mx,res);
	}
	cout<<mx<<endl;
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

string S;
int Q, q, F;
char C;
vector<char> leftS, rightS;

void solve() {
    cin >> S >> Q;
    bool forward = true;
    while (Q--) {
        cin >> q;
        if (q == 1) {
            forward = !forward;
        } else {
            cin >> F >> C;
            if (F == 1) {
                if (forward) leftS.push_back(C);
                else rightS.push_back(C);
            } else {
                if (forward) rightS.push_back(C);
                else leftS.push_back(C);
            }
        }
    }
    if (forward) {
        reverse(leftS.begin(), leftS.end());
        for (auto& i : leftS) cout << i;
        cout << S;
        for (auto& i : rightS) cout << i;
    } else {
        reverse(rightS.begin(), rightS.end());
        reverse(S.begin(), S.end());
        for (auto& i : rightS) cout << i;
        cout << S;
        for (auto& i : leftS) cout << i;
    }
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 976