akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

long long mod = 1000000007;
std::vector<long long> fac(1000100), inv(1000100), finv(1000100); //階乗 / 逆元 / inv * fac
void comb_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2;i < 1000100; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

long long comb(int n,int r){
    if(n < r) return 0;
    if(n < 0 || r < 0)return 0;
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
}

int main()
{
    comb_init();
    int n,k;
    std::cin>>n>>k;
    for(int i = 1; i <= k;i++){
        long long tmp = comb(n - k + 1, i) % mod;
        long long tmp2 = comb(k-1,i-1) % mod;
        std::cout<<tmp * tmp2 % mod<<std::endl; 
    }
}

Measured memory_bytes: 23680
from collections import deque
s = input()
q = int(input())
flag = True
atama = deque()
osiri = deque()
for i in range(q):
    inp = input()
    if inp == '1':
        flag = not flag

    else:
        _, f, c = map(str, inp.split())
        if f == '1':
            if flag:
                atama.appendleft(c)
            else:
                osiri.append(c)
        else:
            if flag:
                osiri.append(c)
            else:
                atama.appendleft(c)

if flag:
    while(atama):
        tmp = atama.popleft()
        print(tmp, end='')
    print(s, end='')
    while(osiri):
        tmp = osiri.popleft()
        print(tmp, end='')
else:
    while(osiri):
        tmp = osiri.pop()
        print(tmp, end='')
    print(s[::-1], end='')
    while(atama):
        tmp = atama.pop()
        print(tmp, end='')


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

int main(){
  string s, t;
  cin >> s >> t;
  int ans = 10000;
  rep(i, s.size() - t.size() + 1){
    int count = 0;
    rep(j, t.size()){
      if (s[i+j] != t[j]) count++;
    }
    if (ans > count) ans = count;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int X, A;
  cin >> X >> A;
  if(X < A) cout << 0 << endl;
  else cout << 10 << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	n, m, c := 0, 0, 0
	fmt.Scan(&n, &m, &c)
	var b [20]int
	var a [20][20]int

	for i := 0; i < m; i++ {
		fmt.Scan(&b[i])
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Scan(&a[i][j])
		}

	}
	var ret, temp int
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			temp += a[i][j] * b[j]
		}
		if temp+c > 0 {
			ret++
		}
		temp = 0
	}
	fmt.Println(ret)
}


Measured memory_bytes: 512
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    if(n==1)cout<<0<<endl;
    vector<int>a;
    for(int i=0;i<n;i++){
        int x;cin>>x;
        a.emplace_back(x);
    }
    sort(a.rbegin(),a.rend());
    ll ans=a[0];
    int i=2;
    int j=1;
    while(i<n){
        if(i+1<n){ans+=a[j]+a[j];i+=2;j++;}
        else {ans+=a[j];i++;j++;}
    }
    cout<<ans<<endl;
    
    
    return 0;
} 

Measured memory_bytes: 4280
void main(){
	int n = _scan();
	int ans;
	if(n<600)ans=8;
	else if(n<800)ans=7;
	else if(n<1000)ans=6;
	else if(n<1200)ans=5;
	else if(n<1400)ans=4;
	else if(n<1600)ans=3;
	else if(n<1800)ans=2;
	else if(n<2000)ans=1;
	ans.writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2736
#include <iostream>

using namespace std;

int main()
{
	int d, n;
	cin >> d >> n;
	
	if(n == 100)
	{
		n++;
	}
	if(d == 0)
	{
		cout << n << endl;
	}
	else if(d == 1)
	{
		cout << n * 100 << endl;
	}
	else
	{
		cout << n * 100 * 100 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
l = gets.split.map(&:to_i)
a = [0]*n
l.each_cons(2){|s, t| s,t = t,s if s > t; a[s-1] += 1; a[t-1] -= 1 }
(1...n-1).each{ |i| a[i] += a[i-1] }
sum = 0
(n-1).times do |i|
  p, q, r = gets.split.map(&:to_i)
  (p-q)*a[i] < r ? (sum += p*a[i]) : (sum += q*a[i]+r)
end
p sum

Measured memory_bytes: 17680
from math import*
a=(0,0)
b=(100,0)

def koch(n,ax,ay,bx,by):
    if n==0:
        return 0
    th=pi/3
    sx=(2*ax+bx)/3
    sy=(2*ay+by)/3
    tx=(ax+2*bx)/3
    ty=(ay+2*by)/3
    ux=(tx-sx)*cos(th)-(ty-sy)*sin(th)+sx
    uy=(tx-sx)*sin(th)+(ty-sy)*cos(th)+sy
    
    koch(n-1,ax,ay,sx,sy)
    print(sx,sy)
    koch(n-1,sx,sy,ux,uy)
    print(ux,uy)
    koch(n-1,ux,uy,tx,ty)
    print(tx,ty)
    koch(n-1,tx,ty,bx,by)


n=int(input())
print(*a)
koch(n,*a,*b)
print(*b)


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

int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	cout << (min(b, d) - max(a, c) >= 0 ? min(b, d) - max(a, c) : 0) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
using namespace std;
char a[5];
int main()
{
	int x=0,y=0;
	cin>>a;
	if((a[0]=='0'&&a[1]!='0')||(a[0]=='1'&&a[1]>='0'&&a[1]<='2'))
	x=1;
	if((a[2]=='0'&&a[3]!='0')||(a[2]=='1'&&a[3]>='0'&&a[3]<='2'))
	y=1;
	if(x==1&&y==1)
	cout<<"AMBIGUOUS";
	else if(x==0&&y==0)
	cout<<"NA";
	else if(x==1&&y==0)
	cout<<"MMYY";
	else
	cout<<"YYMM";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int i,j,high,wide;

	while(1){
		scanf("%d %d",&high,&wide);
		
		if(high==0 && wide ==0) break;

		for(i=0;i<high;i++){
			for(j=0;j<wide;j++) printf("#");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
bool p[2];
int main(){
	memset(p,false,sizeof(p));
	string s;
	int ans;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='C')p[0]=true;
		if(s[i]=='F'&&p[0])p[1]=1;
	}
	if(p[1])printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var x1, y1, x2, y2 float64
	fmt.Scan(&x1, &y1, &x2, &y2)
	xDiff := math.Abs(x1 - x2)
	yDiff := math.Abs(y1 - y2)

	var x3, y3, x4, y4 float64

	if x1 <= x2 && y1 <= y2 {
		x3 = x2 - yDiff
		y3 = y2 + xDiff
		x4 = x3 - xDiff
		y4 = y3 - yDiff
	} else if x1 <= x2 && y1 >= y2 {
		x3 = x2 + yDiff
		y3 = y2 + xDiff
		x4 = x3 - xDiff
		y4 = y3 + yDiff
	} else if x1 >= x2 && y1 <= y2 {
		x3 = x2 - yDiff
		y3 = y2 - xDiff
		x4 = x3 + xDiff
		y4 = y3 - yDiff
	} else {
		x3 = x2 + yDiff
		y3 = y2 - xDiff
		x4 = x3 + xDiff
		y4 = y3 + yDiff
	}

	fmt.Println(x3, y3, x4, y4)
}

Measured memory_bytes: 512
N,C,K,*T=map(int, open(0).read().split())
T=sorted(T)
ans=0
cap=0
s=-1
for t in T:
    if t<=s and cap>0:
        cap-=1
    else:
        s=t+K
        cap=C-1
        ans+=1
print(ans)

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long

int main() {
  int n , a , b ;
  cin >> n >> a >> b ;
  int ans = 0;
  
  rep(i,n+1){
    int now = 0 ;
    string s = to_string(i);
    rep(j,s.size()){
      now += (int)s.at(j)-48;
    }
    if(a <= now && now <= b){
      ans+= i ;
    }
  }
  
  cout << ans ;
}


Measured memory_bytes: 384
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);i--)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  cin >> n;

  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  int ans = INF;
  REP(i,n-1){
    int tmp = 0;
    REP(j,n){
      if(i >= j) tmp += a[j];
      else tmp -= a[j];
    }
    ans = min(ans,abs(tmp));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
n,W=map(int,input().split())
w=[]
v=[]
for i in range(n):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
V=sum(v)+1
dp=[10**10 for i in range(sum(v)+1)]
dp[0]=0
for i in range(n):
    for j in range(V-1,-1,-1):
        if dp[j]!=10**10:
            dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i])
for i in range(V-1,-1,-1):
    if dp[i]<=W:
        print(i)
        exit()


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

int main(){
  int n,k;
  cin >> n >> k;
  int a[n] = {0};
  rep(i,k){
    int d;
    cin >> d;
    rep(j,d){
      int s;
      cin >> s;
      if(a[s-1]==0)++a[s-1];
    }
  }
  int ans=0;
  rep(i,n){
    if(a[i]==0)++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3568
def divisors(N):
  result = {1, N}
  for i in range(2, int(N**0.5)+2):
    if N % i == 0:
      result.add(i)
      result.add(N//i)
  return result

N = int(input().strip())
if N == 2: print(1)
else:
  ans = len(divisors(N-1))-1
  for k in divisors(N):
    if k == 1: continue
    n = N
    while n%k == 0: n = n//k
    if n%k == 1: ans += 1
  print(ans)

Measured memory_bytes: 39536
#include <iostream>

int main(){
	int f_x,sum_area;
	int d = 0;
	while(std::cin >> d){
		sum_area = 0;
		for(int i = d; i <= 600 - d; i += d){
			f_x = i * i;
			sum_area += f_x * d;
		}
		std::cout << sum_area << std::endl;
	}
}

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

int main(void)
{
  int64_t n, d;
  std::cin >> n >> d;

  d *= d;

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int64_t x, y;
    std::cin >> x >> y;

    int64_t ans = x * x + y * y;

    if (ans <= d) {
      cnt ++;
    }
  }

  std::cout << cnt << std::endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a,v,b,w,t; cin>>a>>v>>b>>w>>t;
  if(a==b){
    cout<<"YES"<<endl;
    exit(0);
  }
  if(v<=w){
    cout<<"NO"<<endl;
    exit(0);
  }
  a=max(b-a,a-b);
  v-=w;
  if(a<=v*t){
    cout<<"YES"<<endl;
    exit(0);
  }else{
    cout<<"NO"<<endl;
    exit(0);
  }
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}



template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


void dfs(int k,int p,vi &ret,WG<int> &es){
  for(auto e:es[k]){
    if(e.to==p) continue;
    ret[e.to]=ret[k]+1;
    dfs(e.to,k,ret,es);
  }

}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,u,v;
  cin>>n>>u>>v;
  u--;v--;
  WG<int> es(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    es[a].PB(edge<int>(b,1));
    es[b].PB(edge<int>(a,1));
  }

  vi distu(n,0);
  vi distv(n,0);

  dfs(u,-1,distu,es);
  dfs(v,-1,distv,es);
  

  int ans=0;
  rep(i,n){
    if(distu[i]<distv[i]) ans=max(ans,distv[i]);
  }


  cout<<ans-1<<endl;


}

Measured memory_bytes: 17408
n = int(input())
while (n != 0):
    A=0
    B=0
    for i in range(n):
        a,b = map(int, input().split())
        if (a>b):
            A+=(a+b)
        elif (b>a):
            B += (a+b)
        else:
            A+=a
            B+=b
    print("{} {}".format(A,B))
    n = int(input())


Measured memory_bytes: 5608
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int, int>pii;
bool isok(vector<int>v, int med)
{
	vector<pii>now;
	now.push_back(make_pair(0, -1));
	for (int i = 0; i < v.size(); i++)
	{
		int t = now[now.size() - 1].first;
		if (t < v[i])now.push_back(make_pair(v[i], 0));
		else
		{
			for (;;)
			{
				pii z = now[now.size() - 1];
				if (z.first>v[i])now.pop_back();
				else
				{
					int x = v[i];
					for (;;)
					{
						if (x <= 0)return false;
						if (now[now.size() - 1].first != x)now.push_back(make_pair(x, 0));
						if (now[now.size() - 1].second < med - 1)
						{
							now[now.size() - 1].second++;
							break;
						}
						else x--, now.pop_back();
					}
					break;
				}
			}
		}
		//for (int j = 0; j < now.size(); j++)printf("%d %d   ", now[j].first, now[j].second); printf("\n");
	}
	return true;
}
int main()
{
	int num;
	scanf("%d", &num);
	vector<int>v;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		v.push_back(z);
	}
	bool is1 = true;
	for (int i = 0; i < num - 1; i++)if (v[i] >= v[i + 1])is1 = false;
	if (is1)
	{
		printf("1\n");
		return 0;
	}
	int beg = 2, end = 1010101010;
	for (;;)
	{
		if (beg == end)break;
		int med = (beg + end) / 2;
		if (isok(v, med))end = med;
		else beg = med + 1;
	}
	printf("%d\n", beg);
}

Measured memory_bytes: 2840
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	int N; cin >> N;


	map<string, int> S;
	set<string> SET;
	int MAX = 0;
	for (int i = 0; i < N; i++) {
		string s; cin >> s;
		SET.insert(s);
		S[s] += 1;	
		MAX = max(MAX, S[s]);
	}

	for (string x : SET) {
		if (MAX == S[x]) {
			cout << x << endl;
		}
	}
	


	return 0;
}


Measured memory_bytes: 34788
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
string s;
ll memo[100100][4] = {0};
ll dp(ll i, ll j){
    if(i == -1 && j == 0) return 1;
    if(i == -1) return 0;
    if(memo[i][j] != -1) return memo[i][j];

    ll res = 0;
    if(s[i] == '?'){
        if(j != 0) res += dp(i - 1, j - 1);
        res %= MOD;
        res += dp(i - 1, j) * 3;
        res %= MOD;
    } else {
        if(s[i] == 'C' && j == 3){
            res += dp(i - 1, j - 1);
        } else if(s[i] == 'B' && j == 2){
            res += dp(i - 1, j - 1);
        } else if(s[i] == 'A' && j == 1){
            res += dp(i - 1, j - 1);
        }
        res %= MOD;
        res += dp(i - 1, j);
        res %= MOD;
    }
    res %= MOD;
    return memo[i][j] = res;
}
int main(void){
    cin >> s;
    for(int i = 0; i <= s.size(); i++){
        for(int j = 0; j < 4; j++){
            memo[i][j] = -1;
        }
    }
    cout << dp(s.size() - 1, 3) % MOD << endl;
}

Measured memory_bytes: 8320
// Problem : F - Knapsack for All Segments
// Contest : AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=998244353;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=5e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}

	const int N=1e6+10;
	//------------------FIXED------------------
	int dp[N];
	void main()
	{
		int n=qread(),S=qread(),ans=0;
		fo(i,1,n)
		{
			int aa=qread();if(aa>S) continue;
			if(aa==S) add(ans,1ll*(n-i+1)*i%MOD );
			add(ans, 1ll*dp[S-aa]*(n-i+1)%MOD );
			fd(i,S,aa) add(dp[i], dp[i-aa] );add(dp[aa],i);
		}write(ans);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	// freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::main();
	//debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

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

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define INF (1<<28)
#define pb push_back
#define fs first
#define sc second

const char dx[]={0,1,0,-1},dy[]={1,0,-1,0};
template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", " ;
	return out << "}" << endl;
}
template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}

int main(){
	int n;
	cin >> n;
	vector<vi > e(n);
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	vi d[2];
	rep(i,2){
		d[i].resize(n);
		priority_queue<pii> q; // dst, ind
		q.push(i?pii(0,n-1):pii(0,0));
		while(!q.empty()){
			pii p = q.top();
			q.pop();
			if(d[i][p.sc] || p.fs != 0 && p.sc == (n-1) * i) continue;
			d[i][p.sc] = -p.fs;
			rep(j,e[p.sc].size()){
				q.push(pii(p.fs - 1, e[p.sc][j]));
			}
		}
	}
	int cnt [] = {0,0};
	rep(i,n){
		cnt[d[0][i]>d[1][i]]++;
	}
//	rep(i,2)cout << d[i];

//	cout << pii(cnt[0], cnt[1]) << endl;
	cout << (cnt[0]>cnt[1]? "Fennec" : "Snuke") << endl;
	return 0;
}


Measured memory_bytes: 9252
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("Three")
    else:print("Four")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())




n = ip()                              #入力整数1つ
#a,b= (int(i) for i in input().split())      #入力整数横2つ
#k,a,b = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
a.sort(reverse=True)
s = 0
for i in range(1,len(a),2):
    a[i]*=-1
print(sum(a))


Measured memory_bytes: 5212
#include<bits/stdc++.h>
using namespace std;
int a[20000];
int main()
{
	int N;cin>>N;
	for(int i=1;i<200;i++){
		for(int j=1;j<200;j++){
			for(int k=1;k<200;k++){
				if(i*i+j*j+k*k+i*j+j*k+k*i<10005)
					a[i*i+j*j+k*k+i*j+j*k+k*i]++;
			}
		}
	}
	for(int i=1;i<=N;i++){
		printf("%d\n",a[i]);
	}
	return 0;
}

Measured memory_bytes: 3628
def main():
  n = int(input())
  cnt = 0
  same = 0

  for a in range(1, n):
    for b in range(a, n):
      if a * b >= n:
        break

      cnt += 1
      if a == b:
        same += 1

  print((cnt - same) * 2 + same)



main()


Measured memory_bytes: 9168
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), cnt(9, 0);
    rep(i,n){
        cin >> a[i];
        if(a[i] >= 3200) cnt[8]++;
        else cnt[a[i]/400]++;
    }
    int mx = 0;
    rep(i,8){
        if(cnt[i] > 0) ++mx;
    }
    int mi = mx;
    mx += cnt[8];
    chmax(mi, 1);
    cout << mi << " " << mx << endl;
	return 0;
}

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

typedef struct{
  double x,y;
}P;

void koch(int n,P a,P b){

  P s,t,u;
  double th = M_PI * 60 / 180.0;

  if(n==0) return;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x -s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x -s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n-1,a,s);
  printf("%f %f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%f %f\n",t.x,t.y);
  koch(n-1,t,b);
}

int main(){
  P a,b;
  int n;

  scanf("%d",&n);
  a.x = a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%f %f\n",a.x,a.y);
  koch(n,a,b);
  printf("%f %f\n",b.x,b.y);

  return 0;
}



Measured memory_bytes: 2124
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;

    vector<vector<int>> E(M, vector<int>(2));
    REP(i, M)
    cin >> E[i][0] >> E[i][1];

    vector<int> V(N);
    iota(ALL(V), 1);

    int ans = 0;
    do
    {
        if (V[0] != 1)
            break;

        bool go;
        REP(i, N - 1)
        {
            go = false;
            REP(j, M)
            {
                if ((V[i] == E[j][0] && V[i + 1] == E[j][1]) || (V[i + 1] == E[j][0] && V[i] == E[j][1]))
                {
                    go = true;
                    break;
                }
            }

            if (!go)
                break;
        }

        if (go)
            ans++;

    } while (next_permutation(ALL(V)));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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


int main()
{
  vector<int> v(5);
  REP(i, 5) cin >> v[i];
  vector<int> w(v);
  int sum = 0;
  REP(i, 5) {
    w[i] = (w[i] + 9)/10 * 10;
    sum += w[i];
  }
  int ans = INF;
  REP(i, 5) {
    ans = min(ans, sum - w[i] + v[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

import javax.xml.validation.SchemaFactoryConfigurationError;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int[] l = new int[q];
		int[] r = new int[q];

		for (int i = 0; i < q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		//lcnt[i]・・・1文字目から i 文字目までのACの数
		int[] lcnt = new int[n + 1];
		lcnt[0] = 0;
		lcnt[1] = 0;

		for (int i = 0; i < n - 1; i++) {
			lcnt[i + 2] = lcnt[i + 1];
			if (s.substring(i, i + 2).equals("AC")) {
				lcnt[i + 2]++;
			}
		}

		for (int i = 0; i < q; i++) {
//			System.out.print("i:" + i + ", ");
//			System.out.print(
//					"lcnt[" + r[i] + "]:" + lcnt[r[i]] + ", lcnt[" + (l[i]) + "]:" + lcnt[l[i]] + ", ans:");
			System.out.println(lcnt[r[i]] - lcnt[l[i]]);
		}

		sc.close();
	}
}

Measured memory_bytes: 88324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;

int main() {
  ll a,b,n;
  cin >> a >> b >> n;
  if(b>n){
    cout << a*n/b;
  }
  else{
    cout << a*(b-1)/b;
  }
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt(),x,y,count = 0;
    int[] n = new int[N];
    
    for(int i = 0; i < N; i++)
    	n[i] = sc.nextInt();
    
    for(int i = 0; i < N; i++){
    	x = i;
    	for(int j = i; j < N; j++){
    		if(n[j] < n[x])
    			x = j;
    	}
    		
    	if(i != x){
    		y = n[i];
    		n[i] = n[x];
    		n[x] = y;
    		count++;
    	}	
    }
    for(int i = 0; i < N; i++)
    	if(i != N - 1)
    		System.out.print(n[i] + " ");
    	else
    		System.out.println(n[i]);
    
    System.out.println(count);
    
    sc.close();
  }
}

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

int main(){
  int N;
  cin>>N;
  int S[3*N];
  for(int i=0;i<3*N;i++){
    cin>>S[i];
  }
  sort(S, S+3*N);

  long long total=0;
  for(int i=0;i<N;i++){
    total=total+S[3*N-2-i*2];
  }

  cout<<total<<endl;

  return 0;
}

  

Measured memory_bytes: 1408
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N = int(input())
S = list(input())


# S-->Sと並べる
lst = [None] * (N + 2)
lst[0] = 'S'
if S[0] == 'o':
    lst[1] = 'S'
    lst[-1] = 'S'
else:
    lst[1] = 'S'
    lst[-1] = 'W'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: #x
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N - 1] == lst[N + 1] and lst[0] == lst[N]:
    print (*lst[:-2], sep = '')
    # print (lst)
    exit()

#S-->Wと並べる
lst = [None] * (N + 2)
lst[0] = 'S'
if S[0] == 'o':
    lst[1] = 'W'
    lst[-1] = 'W'
else:
    lst[1] = 'W'
    lst[-1] = 'S'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: #x
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N - 1] == lst[N + 1] and lst[0] == lst[N]:
    print (*lst[:-2], sep = '')
    # print (lst)
    exit()

#W-->Wと並べる
lst = [None] * (N + 2)
lst[0] = 'W'
if S[0] == 'o':
    lst[1] = 'W'
    lst[-1] = 'S'
else:
    lst[1] = 'W'
    lst[-1] = 'W'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: #x
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N - 1] == lst[N + 1] and lst[0] == lst[N]:
    print (*lst[:-2], sep = '')
    # print (lst)
    exit()

#W-->Sと並べる
lst = [None] * (N + 2)
lst[0] = 'W'
if S[0] == 'o':
    lst[1] = 'S'
    lst[-1] = 'W'
else:
    lst[1] = 'S'
    lst[-1] = 'S'
for i in range(1, N):
    if S[i] == 'o':
        if lst[i] == 'S':
            lst[i + 1] = lst[i - 1]
        else:
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
    else: #x
        if lst[i] == 'S':
            lst[i + 1] = 'S' if lst[i - 1] == 'W' else 'W'
        else:
            lst[i + 1] = lst[i - 1]

if lst[N - 1] == lst[N + 1] and lst[0] == lst[N]:
    print (*lst[:-2], sep = '')
    # print (lst)
    exit()

print (-1)

Measured memory_bytes: 8556
#include <iostream>

using namespace std;

int main()
{
  long long n,i,s=0;
  cin>>n;
  for(i=1;i<=n;i++)
  {
      if(i<3)
        s+=i;
      else if(i<5&&i!=3)
        s+=i;
      else if(i%3!=0&&i%5!=0)
        s+=i;
  }
  cout<<s;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

ll A;
int b0,b1;
scanf("%lld %d.%d",&A, &b0, &b1);

int B = 100*b0 + b1;
cout << (A*B)/100 << endl;

return 0;
}

Measured memory_bytes: 3752
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.trim().split_whitespace();
    let n: u32 = iter.next().unwrap().parse().unwrap();
    let k: u32 = iter.next().unwrap().parse().unwrap();
    let ans = (n - 1) / (k - 1) + if (n - 1) % (k - 1) == 0 { 0 } else { 1 };
    println!("{}", ans);
}


Measured memory_bytes: 4352
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	ans := 0
	mx := 0
	for i := 0; i < n; i++ {
		tmp := sc.NextInt()
		ans += tmp
		if mx < tmp {
			mx = tmp
		}
	}
	ans -= (mx / 2)
	fmt.Printf("%+v\n", ans) // output for debug

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	unsigned long long int n;
	cin>>n;
	unsigned long long int arr[n+1]={0};
	unsigned long long int brr[n+1];
	unsigned long long int i,j,k;
	for(i=1;i<=n;i++)
	{  
		cin>>brr[i];
		arr[brr[i]]++;
	}
	
	unsigned long long int crr[n+1]={0};
	unsigned long long int  tot=0;
	for(i=1;i<=n;i++)
	{
		crr[i]=(arr[i]*(arr[i]-1))/2;
		tot=tot+crr[i];
	}
	
	
	for(i=1;i<=n;i++)
	{
	cout<<tot-(arr[brr[i]]-1)<<endl;	
	}

	
	
}

Measured memory_bytes: 7296
while e = gets
    equation = e.chomp.sub!(/=/, '+').split('+')
    flag = false
    start_index = 0
    
    if (equation[0].length >= 2 && equation[0][0] == "X") ||
        (equation[1].length >= 2 && equation[1][0] == "X") ||
        (equation[2].length >= 2 && equation[2][0] == "X")
        start_index = 1
    end
    
    for i in start_index..9
        sec1 = equation[0].gsub("X", i.to_s)
        sec2 = equation[1].gsub("X", i.to_s)
        sec3 = equation[2].gsub("X", i.to_s)
        
        if sec1.to_i + sec2.to_i == sec3.to_i
            puts i
            flag = true
            break
        end
    end
    puts "NA" if flag == false
end



Measured memory_bytes: 6972
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll A,B,C,K,N,M,X,Y;
string S;
vector<ll> vec;

void solve() {
	cin >> N >> M;

	ll ans = 0;

	if (M > 0) {
		for (int i=1;i<N;i++) {
			ans += M + i;
		}
	}
	else if (N + M - 1 < 0) {
		for (int i = 0; i < N - 1; i++) {
			ans += M + i;
		}
	}
	else {
		for (int i = 0; i < N; i++) {
			ans += M + i;
		}
	}

	cout << ans;
}

int main() {
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 100001
vector<int> G[maxn];
int P[maxn], ans;
bool V[maxn];
set<int> s;
void DFS(int u){
	V[u] = true; 
	if(s.count(u)) ans += 1;
	else s.insert(u);
	if(s.count(P[u])) ans += 1;
	else s.insert(P[u]);
	for(int v: G[u]) if(V[v] == false) DFS(v);
}
int main(){
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	for(int i = 1; i <= N; i += 1) cin >> P[i];
	for(int i = 1; i <= M; i += 1){
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i = 1; i <= N; i += 1) if(V[i] == false){
		s.clear();
		DFS(i);
	}
	cout << ans;
}

Measured memory_bytes: 13952
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    int K, X;
    cin>>K>>X;
    cout<<((K*500>=X) ? "Yes" : "No") <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i = 0;i<n;i++){
		cin>>a[i];
	}
	int flag = 1;
	int kaisu = 0;
	while(flag){
		flag = 0;
		for(int i = n-1;i>0;i--){	
			if(a[i] <a[i-1]){
				int o;
				o = a[i];
				a[i] = a[i-1];
				a[i-1] = o;
				flag = 1;
				kaisu ++;
			}
		}
	}
	for(int i = 0;i<n-1;i++){
		cout<<a[i]<<" ";
	}
	cout<<a[n-1]<<endl;
	cout<<kaisu<<endl;
	return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ff first
#define ss second
#define SZ(x) ((int)(x).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 3e3+100;
int R, C, K;
ll a[MAXN][MAXN], DP[4][MAXN][MAXN];

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> R >> C >> K;
    while(K--){
        int x, y; ll v;
        cin >> x >> y >> v;
        a[x][y] = v;
    }
    for(int i = 1; i <= R; i++){
        for(int j = 1; j <= C; j++){
            DP[0][i][j] = 0;
            for(int k = 0; k <= 3; k++){
                DP[0][i][j] = max(DP[0][i][j], DP[k][i-1][j]);
            }
            DP[1][i][j] = DP[0][i][j] + a[i][j];
            for(int k = 0; k < 3; k++){
                DP[k+1][i][j] = max({DP[k+1][i][j], DP[k+1][i][j-1], DP[k][i][j-1] + a[i][j]});
            }
        }
    }
    ll ans = 0;
    for(int k = 0; k <= 3; k++) ans = max(ans, DP[k][R][C]);
    cout << ans;
}

Measured memory_bytes: 366900
#include <stdio.h>
#include <string.h>
int main(){
	int i,k,j,lens,lenp,cnt,yes=0;
	char s[101],p[101];
	scanf("%s",s);
	scanf("%s",p);
	lens=strlen(s);
	lenp=strlen(p);
	for(i=0;i<lens;i++){
		j=0;
		cnt=0;
		for(k=i;k<i+lenp;k++){
			if(s[k%lens]==p[j]){
				j++;
				cnt++;
			}else{
				break;
			}
		}
		if(cnt==lenp){
			printf("Yes\n");
			yes=1;
			break;
		}
	}
	if(yes==0){
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 1816
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * Created by yangyuyin on 16/10/23.
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int K =sc.nextInt();
        int T = sc.nextInt();
        int count=0;
        Comparator<Cake> order = new Comparator<Cake>() {
            @Override
            public int compare(Cake o1, Cake o2) {
                if(o2.count>o1.count) return 1;
                if(o2.count<o1.count) return -1;
                return 0;
            }
        };
        PriorityQueue<Cake> queue = new PriorityQueue<Cake>(order);
        for(int i=0;i<T;i++){
            Cake cake = new Cake(i,sc.nextInt());
            queue.add(cake);
        }
        Cake yesterday = queue.poll();
        for(int i=1;i<K;i++){
            if(queue.isEmpty()) {
                count++;
            }else {
                Cake today = queue.poll();
                yesterday.count--;
                if(yesterday.count!=0) {
                    queue.add(yesterday);
                }
                yesterday = today;
            }
        }
        System.out.print(count);
    }
    public static class Cake{
        int type;
        int count;
        Cake(int type, int count){
            this.type=type;
            this.count=count;
        }
    }
}


Measured memory_bytes: 10192
#include<bits/stdc++.h>
using namespace std;
deque<int>l;
int n,w;
int main(){
    cin>>n;
    for(int i=n%2;i<n+n%2;i++){
        cin>>w;
        if(i%2==0)l.push_back(w);
        else l.push_front(w);
    }
    for(deque<int>::iterator i=l.begin();i!=l.end();i++)
	  cout<<*i<<" ";
}

Measured memory_bytes: 2944