akhauriyash/Code-Regression huggingface dataset:
#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 <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(int to, int cost){
        this->to = to;
        this->cost = cost;
    }
};

bool check(int pos, int t, const vector<pair<int, int> >& v)
{
    for(const auto& p : v){
        if(pos == p.first && t - p.second < 15)
            return false;
    }
    return true;
}

vector<pair<int, int> > normalize(int pos, int t, const vector<pair<int, int> >& v)
{
    vector<pair<int, int> > ans;
    for(const auto& p : v){
        if(pos == p.first){
            if(t - p.second < 15)
                ans.push_back(p);
        }
        else{
            if(t - p.second < 10)
                ans.push_back(p);
        }
    }
    sort(ans.begin(), ans.end());
    return ans;
}

int main()
{
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> d(n);
    for(int i=0; i<n; ++i)
        cin >> d[i];

    vector<vector<Edge> > edges(n);
    for(int i=0; i<m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        -- a;
        -- b;
        edges[a].push_back(Edge(b, c));
        edges[b].push_back(Edge(a, c));
    }

    vector<pair<int, int> > empty;
    vector<vector<map<vector<pair<int, int> >, int> > > dp(r+1, vector<map<vector<pair<int, int> >, int> >(n));
    dp[0][0][empty] = 0;
    for(int t=0; t<r; ++t){
        for(int curr=0; curr<n; ++curr){
            for(const auto& p : dp[t][curr]){
                vector<pair<int, int> > v = p.first;
                int ball = p.second;
                if(check(curr, t, v)){
                    v.push_back(make_pair(curr, t));
                    ball += d[curr];
                }

                for(const Edge& e : edges[curr]){
                    int next = e.to;
                    int t2 = t + e.cost;
                    if(t2 <= r){
                        auto v2 = normalize(next, t2, v);
                        dp[t2][next][v2] = max(dp[t2][next][v2], ball);
                    }
                }

                int t2;
                for(unsigned i=0; i<v.size(); ++i){
                    if(v[i].first == curr)
                        t2 = v[i].second + 15;
                }
                if(t2 <= r){
                    auto v2 = normalize(curr, t2, v);
                    dp[t2][curr][v2] = max(dp[t2][curr][v2], ball);
                }
            }
        }
    }
    
    int ans = 0;
    for(int t=0; t<=r; ++t){
        for(const auto& p : dp[t][n-1]){
            ans = max(ans, p.second);
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    if (N % 2 == 0) {
        cout << N / 2 - 1 << endl;
    } else {
        cout << N / 2 << endl;
    }
}

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


using namespace std;

int main() {

	uint64_t i=1,X,Y=100;
	cin >> X;

	
	while (1) {

		Y += Y / 100;
		
		if (Y >= X) {
			cout << i;
			return 0;
		}
		i++;

	}


}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
using namespace std;

vector<int> ans;
int main(){
  int n;
  
  cin >> n;
  for(int i=0; i<n; ++i){
    bitset<3> base{0};
    int flag = 0;
    int score = 0;
    string nock;

    while(flag!=3){
    cin >> nock;

    if(nock == "HIT"){
      if(base == 000){
	base = 001;
      }else if(base[2]){
	base = base << 1;
	base |= 001;
	++score;
      }else{
	base = base << 1;
	base |= 001;
      }
    }
    
    if(nock == "OUT"){
      ++flag;
      if(flag == 3){
	ans.push_back(score);
	//cout << "end" << endl;
      }
    }
    if(nock == "HOMERUN"){
      int j;
      j = base.count();
      score += j + 1;
      base = 000;
    }
    }
  }
  for(auto i:ans){
    cout << i << endl;
  }
  return 0;
}

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

int main() {
  int S;
  cin >> S;
  
  int A, B;
  A = S/100;
  B = S%100;
  
  if (A == 0 && B > 12) {
    cout << "NA" << endl;
  }
  else if (A > 12 && B == 0) {
    cout << "NA" << endl;
  }
  else if (A == 0 && B == 0) {
    cout << "NA" << endl;
  }
  else if (A > 12 && B > 12) {
    cout << "NA" << endl;
  }
  else if ((0 < A && A <= 12) && (0 < B && B <= 12)) {
    cout << "AMBIGUOUS" << endl;
  }
  else if (0 < A && A <= 12) {
    cout << "MMYY" << endl;
  }
  else {
    cout << "YYMM" << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,M,Q;
cin >> N >> M >> Q;
  
int ans = 0;
int a[Q], b[Q],c[Q],d[Q];
for(int i = 0; i < Q; i++){
  cin >> a[i] >> b[i] >> c[i] >> d[i];

}
int A[110];

  for(A[1] = 1; A[1] <=M ; A[1]++){
    for(A[2] = A[1]; A[2] <=M ; A[2]++){
      for(A[3] = A[2]; A[3] <=M ; A[3]++){
        for(A[4] = A[3]; A[4] <=M ; A[4]++){
          for(A[5] = A[4]; A[5] <=M ; A[5]++){
            for(A[6] = A[5]; A[6] <=M ; A[6]++){
              for(A[7] = A[6]; A[7] <=M ; A[7]++){
                for(A[8] = A[7]; A[8] <=M ; A[8]++){
                  for(A[9] = A[8]; A[9] <=M ; A[9]++){
                    for(A[10] = A[9]; A[10] <= M; A[10]++){
                      int sum = 0;
                    for(int i = 0; i< Q; i++){
                      if(A[b[i]]-A[a[i]]==c[i]){
                        sum+= d[i];
                      }
                    }
                    ans = max(sum,ans);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
cout << ans << endl;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007LL;

int main(void) {
    int N, K;
    double p = 0.0;
    cin >> N >> K;
    for (int i=1;i<=N;i++) {
        int b = i, j = 0;
        while (b < K) {
            b *= 2;
            j++;
        }
        p += 1.0/(N*(1<<j));
    }
    cout << setprecision(13) << p << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n, k, q;
    cin >> n >> k >> q;
    VI a(n, 0);
    int in;
    FOR(i, 0, q) {
        cin >> in;
        a[--in]++;
    }

    FOR(i, 0, n) {
        cout << (k + a[i] - q > 0 ? "Yes\n" : "No\n");
    }
}

Measured memory_bytes: 1024
open Scanf
open Printf

let fold_left1 f lst = List.fold_left f (List.hd lst) (List.tl lst)
let rec seq k n = if k = n then [n] else k :: seq (k+1) n

let rec g k n = if n < k then n else n mod k + g k (n / k)
let f n = fold_left1 min @@ List.map (fun i -> g 6 i + g 9 (n-i)) (seq 0 n)

let () = let ans = scanf "%d\n" f in
  printf "%d\n" ans

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001

int main() {
    int n;cin >> n;
    ll sum=0;
    int minus=0;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++) {
        cin >> a[i];
        if(a[i]<0) minus++;
        b[i]=abs(a[i]);
        sum += b[i];
    }
    sort(b.begin(),b.end());

    if(minus%2==0) cout << sum << endl;
    else cout << sum-2*b[0] << endl;

    return 0;
}

Measured memory_bytes: 4000
import Control.Monad (unless)
main = getContents >>= f .  map (map read . words) . lines where
    f :: [[Int]] -> IO ()
    f [] = return ()
    f ([x,y]:re) = unless (x == 0 && y == 0) $ do
        putStrLn . unwords . map show $
            case x `compare` y of
                GT -> [y,x]
                _ -> [x,y]
        f re

Measured memory_bytes: 4628
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]
sys.setrecursionlimit(10 ** 6)

class UnionFind():
	def __init__(self, lis):
		self.table = [-1 for _ in range(len(lis))]
		self.size = [x for x in lis]

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x])
			return self.table[x]

	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
				self.table[s1] -= 1
				self.size[s1] += self.size[s2]
				self.size[s2] = 0
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
				self.size[s2] += self.size[s1]
				self.size[s1] = 0
		return

n, m = map(int, input().split())
x = list(map(int, input().split()))
adj = [[] for _ in range(n)]
e = []
for i in range(m):
	a, b, y = map(int, input().split())
	a, b = a-1, b-1
	e.append((y, a, b))

used = [False for _ in range(m)]
candidate = [False for _ in range(m)]
e.sort()
uf = UnionFind(x)
for i in range(m):
	y, a, b = e[i]
	adj[a].append((b, y, i))
	adj[b].append((a, y, i))
	uf.unite(a, b)
	if uf.size[uf.find(a)] >= y:
		candidate[i] = True

ans = 0
for i in range(m-1, -1, -1):
	if used[i]:
		continue
	if not candidate[i]:
		ans += 1
	else:
		used[i] = True
		y, a, b = e[i]
		stack = [a, b]
		while stack:
			l = stack.pop()
			for v, z, j in adj[l]:
				if used[j]:
					continue
				if z <= y:
					stack.append(v)
					used[j] = True

print(ans)

Measured memory_bytes: 56964
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let hw: Vec<u64> = read_vec();
    let h = hw[0];
    let w = hw[1];

    if h == 1 || w == 1 {
        println!("1");
    } else {
        println!("{}", ((h + 1) / 2) * ((w + 1) / 2) + (h / 2) * (w / 2));
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


signed main(){ 
    int n; cin>>n;
    int a[n];
    set<int> s;
    for(int i=0;i<n;i++){
        cin>>a[i];
        s.insert(a[i]);
    } 
    int big=pow(10,18);
    int res=1;

    if(s.count(0)==1){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        if(a[i]>big){
            cout<<-1<<endl;
            return 0;
        }
        else{
            if(res>(big/a[i])){
                cout<<-1<<endl;
                return 0;
            }else{
                res=res*a[i];
            }
        }
    }

    if(res>big){
        cout<<-1<<endl;
    }else{
        cout<<res<<endl;
    }
}  

Measured memory_bytes: 8952
def main():
    n = int(input())
    word_lst = []
    previous_word = input()
    word_lst.append(previous_word)
    ok = True
    for i in range(1,n):
        now_word = input()
        if not (now_word[0] == previous_word[-1]):
            ok = False
            break
        if now_word in word_lst:
            ok = False
            break
        word_lst.append(now_word)
        previous_word = now_word
    if len(word_lst) != len(set(word_lst)):
        ok = False

    print("Yes" if ok else "No")






if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int d = sc.nextInt();
		int t = sc.nextInt();
		int s = sc.nextInt();

		if (d <= t * s){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}


}

Measured memory_bytes: 35640
from collections import Counter

n=int(input())
a=list(map(int, input().split()))

flag="No"

count_by_kw = Counter()
for i in range(n):
    count_by_kw[a[i]]+=1

if count_by_kw.get(0) == n:
    flag="Yes"

if count_by_kw.get(0) == n/3 and len(count_by_kw.keys())==2:
    flag="Yes"

cl=list(count_by_kw.values())
ck=list(count_by_kw.keys())

if len(cl)==3:
    if cl[0] == cl[1] and cl[1] == cl[2]:
        xor = ck[0]^ck[1]^ck[2]
        if xor == 0:
            flag="Yes"
        
print(flag)





Measured memory_bytes: 14468
#include<stdio.h>

int main(){
	int n,i,A,B,a,b;
	n=0;
	while(1){
	scanf("%d",&n);
	if(n==0){
	break;
	}
	A=0;
	B=0;
	for(i=0;i<n;i++){
	scanf("%d %d",&a,&b);
	if(a>b){
	A=A+a+b;
	}
	else if(a<b){
	B=B+a+b;
	}
	else if(a==b){
	A=A+a;
	B=B+b;
	}
	}
	printf("%d %d\n",A,B);
	}
	return 0;
}

Measured memory_bytes: 600
n = int(input())
links = [set() for _ in range(n)]

for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    w %= 2
    links[v].add((u, w))
    links[u].add((v, w))

colors = [-1] * n
q = [(0, 0, -1)]

while q:
    v, c, p = q.pop()
    colors[v] = c
    for u, w in links[v]:
        if u == p:
            continue
        q.append((u, c ^ w, v))

print('\n'.join(map(str, colors)))

Measured memory_bytes: 52932
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int[] a;

	void run(){
		a=new int[13];
		sc.useDelimiter(",|\n");
		for(; sc.hasNext();){
			Arrays.fill(a, 0);
			for(int i=0; i<5; i++){
				a[sc.nextInt()-1]++;
				// debug(sc.nextInt());
			}
			solve();
		}
	}

	void solve(){
		if(fourCard())
			println("four card");
		else if(fullHouse())
			println("full house");
		else if(straight())
			println("straight");
		else if(threeCard())
			println("three card");
		else if(twoPair())
			println("two pair");
		else if(onePair())
			println("one pair");
		else
			println("null");
	}

	boolean fourCard(){
		for(int x : a){
			if(x==4){
				return true;
			}
		}
		return false;
	}

	boolean fullHouse(){
		boolean f2=false, f3=false;
		for(int x : a){
			f2|=x==2;
			f3|=x==3;
		}
		return f2&&f3;
	}

	boolean straight(){
		for(int i=0; i<10; i++){
			if(a[i]*a[i+1]*a[i+2]*a[i+3]*a[(i+4)%13]==1)
				return true;
		}
		return false;
	}

	boolean threeCard(){
		for(int x : a){
			if(x==3){
				return true;
			}
		}
		return false;
	}

	boolean twoPair(){
		int c=0;
		for(int x : a){
			if(x==2){
				c++;
			}
		}
		return c==2;
	}

	boolean onePair(){
		for(int x : a){
			if(x==2){
				return true;
			}
		}
		return false;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}

}

Measured memory_bytes: 12000
import string
S = input()
T = input()

ascii_lower = list(string.ascii_lowercase)
s_list = [-1 for _ in range(26)]
t_list = s_list[:]


for s, t in zip(S, T):
  s_index = ascii_lower.index(s)
  t_index = ascii_lower.index(t)
  
  if s_list[s_index] != -1 or t_list[t_index] != -1:
    if s_list[s_index] != t_index or t_list[t_index] != s_index:
      print('No')
      break
  s_list[s_index] = t_index
  t_list[t_index] = s_index
else:
  print('Yes')

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

ll x;
  cin>>x;

  ll v=100;
  ll cnt=0;
  while(v<x){
    v*=1.01;
    cnt++;
  }
  cout<<cnt<<endl;

}



Measured memory_bytes: 3640
import kotlin.math.ceil
import kotlin.system.exitProcess

fun main(args: Array<String>) {
    abc173A(args)
}

fun abc173A(args: Array<String>) {
    val N = readLine()!!.toInt()
    println(((ceil(N.toDouble() / 1000) * 1000).toInt() - N))
}


Measured memory_bytes: 34580
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var aho = Console.ReadLine().Split();
    var a = int.Parse(aho[0]);
    var b = int.Parse(aho[1]);
    var s = b-a;
    var g = 0;
    for(int i = 1;i<=s;i++){
      g+=i;
    }
    Console.WriteLine(g-b);
  }
}

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

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

    static class TaskB {
        static final long MODULO = (long) 1e9 + 7;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] invs = new long[n + 1];
            if (n > 0)
                invs[1] = 1;
            for (int i = 2; i <= n; ++i) {
                invs[i] = (MODULO - invs[((int) (MODULO % i))] * (MODULO / i) % MODULO) % MODULO;
                if (invs[i] * i % MODULO != 1) throw new RuntimeException();
            }
            long[] byDist = new long[n];
            byDist[0] = 0;
            for (int i = 1; i < n; ++i) {
                byDist[i] = invs[i + 1] % MODULO;
            }
            long[] byDistSum = byDist.clone();
            for (int i = 1; i < n; ++i) {
                byDistSum[i] += byDistSum[i - 1];
                byDistSum[i] %= MODULO;
            }
            long res = 0;
            for (int i = 0; i < n; ++i) {
                long a = in.nextLong();
                res = (res + a * (1 + byDistSum[i] + byDistSum[n - 1 - i])) % MODULO;
            }
            for (int i = 1; i <= n; ++i) res = res * i % MODULO;
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }
}



Measured memory_bytes: 40060
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    Sourav Verma IPG_2013  ABV_IIITMG Task @ Codeforces 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/    

#include<bits/stdc++.h>

#define ll                    long long int
#define loop(i,a,b)           for(int i=(int)a;i<(int)b;++i)
#define rloop(i,a,b)          for(int i=(int)a;i<=(int)b;++i)
#define loopr(i,a,b)          for(int i=(int)a;i>=(int)b;--i)
#define count_1(n)            __builtin_popcountll(n)
#define pb                    push_back
#define mset(a,b,c)           loop(i,0,b) a[i]=c
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define itoc(c)               ((char)(((int)'0')+c))
#define vi                    vector<int>
#define vvi                   vector<vi>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define mini                  INT_MIN
#define sv()                  int t; scanf("%d",&t); while(t--)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll lcm(int x, int y) { return x * 1ll * y / (int)__gcd(x, y); }
ll hcf(ll a, ll b) {if(b>a) return (hcf(b, a)); if(a%b==0) return b; return (hcf(b, a%b));} 
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0);
    int n;cin>>n;;
    cout<<(n*(n+1))/2;
    return 0;
}

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

int main(){
    string s;cin >> s;
    int ans = 0;
    int g = 0;
    int p  =0;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'g'){
            if(g-p >0 ){
                ans ++;
                p++;
            }
            else{
                g ++;
            }
        }
        else{
            if(g-p > 0){
                p++;
            }
            else{
                g++;
                ans --;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>

using namespace std;

void room_search(int w, int h, const vector<string>& room, vector< vector<int> >& visited, int W, int H, int& ret) {
    int dw[] = {1, 0, -1, 0}, dh[] = {0, 1, 0, -1};
    visited[h][w] = 1;
    ret++;
    for (int i = 0; i < 4; i++) {
        int nw = w + dw[i], nh = h + dh[i];
        if (0 <= nw && nw < W && 0 <= nh && nh < H && visited[nh][nw] != 1 && room[nh][nw] == '.')  {
            room_search(nw, nh, room, visited, W, H, ret);
        }
    }
}

int main() {
    while(true) {
        int W, H;
        cin >> W >> H;
        if(W == 0 && H == 0) break;
        vector<string> room;
        vector< vector<int> > visited;
        int iw, ih;
        for(int h = 0; h < H; h++) {
            string s;
            cin >> s;
            for(int w = 0; w < W; w++) {
                if(s[w] == '@') {
                    iw = w;
                    ih = h;
                }
            }
            room.push_back(s);
            visited.push_back(vector<int>(W, 0));
        }
        int ret = 0;
        room_search(iw, ih, room, visited, W, H, ret);
        cout << ret << endl;
    }
}
// [Problem] Red and Black
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1130&lang=jp



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int a,b;
  cin >> a >> b;
  if(a >= 13){
    cout << b << endl;
  }else if(a <= 5){
    cout << 0 << endl;
  }else{
    cout << b/2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int a[100],b[100][4][4],n,m;
int fn(int p,int q,int r){
  int i;
  if(p==n)
    return 1;
  if(a[p]){
    if(q==r&&r==a[p])
      return 0;
    return fn(p+1,r,a[p]);
  }
  if(b[p][q][r]>=0)
    return b[p][q][r];
  int sm=0;
  for(i=1;i<=3;++i){
    if(q==r&&r==i)
      continue;
    sm=(sm+fn(p+1,r,i))%10000;
  }
  return b[p][q][r]=sm;
}
int main(){
  int i;
  cin>>n>>m;
  memset(a,0,sizeof(a));
  for(i=0;i<m;++i){
    int p,q;
    cin>>p>>q;
    --p;
    a[p]=q;
  }
  memset(b,-1,sizeof(b));
  cout<<fn(0,0,0)<<endl;
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string S;
        cin >> S;
        string s1 = S.substr(0, 2);
        string s2 = S.substr(2, 2);
        ll n1 = stoll(s1);
        ll n2 = stoll(s2);
        bool f1 = 0 <= n1 and n1 <= 99 and 1 <= n2 and n2 <= 12;
        bool f2 = 0 <= n2 and n2 <= 99 and 1 <= n1 and n1 <= 12;

        if (f1 and f2) {
                cout << "AMBIGUOUS" << endl;
        } else if (f1) {
                cout << "YYMM" << endl;
        } else if (f2) {
                cout << "MMYY" << endl;
        } else {
                cout << "NA" << endl;
        }

}

Measured memory_bytes: 3584
#include<iostream>

using namespace std;


int main() {
	int m, f, r;

	while(true) {
		cin >> m >> f >> r;

		if ((m == -1 && f == -1) && r == -1)break;

		if (m == -1 || f == -1) {
			cout << "F" << endl;
			continue;
		}

		if (m + f < 30) {
			cout << "F" << endl;
			continue;
		}
		if (30 <= m + f&&m + f < 50) {
			cout << (r < 50 ? "D" : "C") << endl;
			continue;
		}
		if (50 <= m + f&&m + f < 65) {
			cout << "C" << endl;
			continue;
		}
		if (65 <= m + f&&m + f < 80) {
			cout << "B" << endl;
			continue;
		}
		if (80 <= m + f) {
			cout << "A" << endl;
			continue;
		}
	}

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = a; i < (b + a); i++)
#define W1 while (1)
#define COUT(x) cout << x << endl
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define mod 1000000007
#define PB push_back
#define F first
#define S second

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  FOR(i, 1, n) {
    if (i % 3 != 0 && i % 5 != 0) {
      ans += i;
    }
  }
  COUT(ans);

  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
long long int a[200005], b[200005];
int asc(const void* x, const void* y)
{
	if (b[*(int*)x] > b[*(int*)y])return 1;
	if (b[*(int*)x] < b[*(int*)y])return -1;
	return 0;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	for (i = 0; i < n; i++)
		scanf("%lld %lld", &a[i], &b[i]);
	int c[200005];
	for (i = 0; i < n; i++)
		c[i] = i;
	qsort(c, n, sizeof(int), asc);
	long long int now = 0;
	for (i = 0; i < n; i++)
	{
		now += a[c[i]];
		if (now > b[c[i]])
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 4860
#include <bits/stdc++.h>
using namespace std;
int n, x, y, ans = 1;
const int MOD = 1000000007;
const int N = 200010;
int ok[N];
vector <int> bi[N], ls;
int fac[N], inv[N], sum;
int powi(int a, int b)
{
    int c = 1;
    for (; b; b >>= 1, a = 1ll * a * a % MOD)
        if (b & 1) c = 1ll * c * a % MOD;
    return c;
}
int main()
{
    cin >> n >> x >> y;
    fac[0] = 1;
    for (int i = 1; i <= n; ++ i) fac[i] = 1ll * fac[i - 1] * i % MOD;
    inv[n] = powi(fac[n], MOD - 2);
    for (int i = n - 1; ~i; -- i) inv[i] = 1ll * inv[i + 1] * (i + 1) % MOD;

    for (int i = 1; i <= n; ++ i)
    {
        int c, w;
        cin >> c >> w;
        bi[c].push_back(w);
    }
    for (int i = 1; i <= n; ++ i)
    {
        sort(bi[i].begin(), bi[i].end());
    }

    int fs = 0, sc = 0;
    for (int i = 1; i <= n; ++ i) if (bi[i].size())
    {
        if (!fs || bi[fs][0] > bi[i][0]) sc = fs, fs = i;
        else if (!sc || bi[sc][0] > bi[i][0]) sc = i;
    }
    if (!sc) {puts("1"); return 0;}
    ok[fs] = 1;
    for (int i = 1; i <= n; ++ i) if (bi[i].size())
        if (bi[fs][0] + bi[i][0] <= y) ok[i] = 1;

    for (int i = 1; i <= n; ++ i) if (bi[i].size() && ok[i])
    {
        int cnt = 1;
        for (int j = 1; j < bi[i].size(); ++ j)
            if (bi[i][0] + bi[i][j] <= x || bi[fs == i? sc: fs][0] + bi[i][j] <= y)
                cnt ++;
        ls.push_back(cnt); sum += cnt;
    }
    ans = fac[sum];
    for (int i = 0; i < ls.size(); ++ i) ans = 1ll * ans * inv[ls[i]] % MOD;
    cout << ans;
}


Measured memory_bytes: 14076
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
//#pragma GCC optimize "trapv"
int main()
{
	// ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
	ll x,k,d;
	cin>>x>>k>>d;
	x = abs(x);
	ll ans = x/d;
	ll ans1 = x- ans*d;
	if(k<=ans)
	{
		cout<<x - k*d<<"\n";
		return 0;
	}
	if(ans%2!=k%2)
	{
		ans1 = abs(ans1);
		ans1 = min(abs(ans1+d),abs(ans1-d));
	}
	cout<<ans1<<"\n";
}

Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test1 {

    class ClassMain {
        public static void Main(String[] args) {
            int n;
            while((n=int.Parse(Console.ReadLine()))!=0){
                int[] uriage = new int[10];
                for (int i = 0; i < n; i++) {
                    uriage[int.Parse(Console.ReadLine())]++;
                }
                for (int i = 0; i < 10; i++) {
                    String str = "";
                    //Console.WriteLine("i:" + uriage[i]);
                    if (uriage[i] == 0) { str = "-"; }
                    else {
                        for (int j = 0; j < uriage[i]; j++) {
                            str += "*";
                        }
                    }
                    Console.WriteLine(str);
                }
            }

            
        }

      
    }


}

Measured memory_bytes: 5928
#include <bits/stdc++.h>
#include <iostream>
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll maxn = 1000000000;
ll ans=0;
int sosu;
//---------------------------------------------------------------------------------------------------
 
void prime(ll n) {
    sosu=0;
    for(ll i=3;i*i<=n;i+=2){
        
        if(n%i==0){
            //ans++;
            sosu=1;
            break;
        }
    }
}
 
 
int main(){
    
    ll n,a;
    cin>>n;
    rep(i,n){
        cin>>a;
        if(a==2)ans++;
        if(a%2!=0){
            prime(a);
            if(sosu!=1){
                ans++;
                //cout<<a<<endl;
            }
        }
    }
    cout<<ans<<endl;
    
    
}
  




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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    string S, T;
    cin >> S >> T;

    bool ok = false;
    RREP(i, S.size()) {
        int s = i, t = 0;
        while (s < S.size() && t < T.size() && (S[s] == T[t] || S[s] == '?')) {
            s++;
            t++;
        }
        if (s <= S.size() && t == T.size()) {
            REP(j, T.size()) S[i + j] = T[j];
            ok = true;
            break;
        }
    }
    if (ok) {
        replace(ALL(S), '?', 'a');
        cout << S << endl;
    }
    else {
        cout << "UNRESTORABLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn       cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;


int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if((abs(a-b)<=d&&abs(b-c)<=d)||abs(a-c)<=d)yn
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1LL<<57)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	ll a,b;
	cin>>a>>b;
	cout<<((a*b)/__gcd(a,b))<<"\n";
	return;
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

#ifdef ONLINE_JUDGE
	time_t time_t1, time_t2;
	time_t1 = clock();
#endif

	while(T--)
	solve(T);

#ifdef ONLINE_JUDGE
	time_t2 = clock();
	SETF();
	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
	UNSETF();
#endif

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char a = sc.next().charAt(0);
        char b = sc.next().charAt(0);
        char c;
        if(b == 'H') {
            c = a == 'H' ? 'H' : 'D';
        } else {
            c = a == 'D' ? 'H' : 'D';
        }
        System.out.println(c);
    }
}

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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

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

    int n, d;
    cin >> n >> d;
    vector<vi> x(n, vi(d, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> x[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            ll v = 0;
            for (int k = 0; k < d; ++k) {
                ll dx = x[i][k] - x[j][k];
                dx *= dx;
                // cout << dx <<' ';
                v += dx;
            }

            ll s = sqrt(v);
            // cout << "| " << s << ' ' << v << '\n';
            if (s * s == v or (s - 1) * (s - 1) == v or (s + 1) * (s + 1) == v) {
                ++ans;
            }
        }
    }

    cout << ans << '\n';
    
    return 0;
}


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

#define int long long
#define endl '\n'

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    int n; cin>>n;
    int ans = 0;

    int a[n];
    for (int i = 0; i < n; i++) cin>>a[i];
    sort(a, a+n, greater<int>());
    ans += a[0];
    for (int i = 1; i < n-1; i++)
        ans += a[(i+1)/2];
    cout<<ans;
}

Measured memory_bytes: 5196
import java.util.Scanner;
 
public class Main { 
	final static boolean S = true;
	final static boolean W = false;
 
	public static void main(String[] args){
		try(Scanner scan = new Scanner(System.in)){
			int N = scan.nextInt();
			scan.nextLine();
			String s = scan.nextLine();
			
			boolean[] ans = new boolean[N+1];
			boolean[][] init = {{S, S}, {S, W}, {W, S}, {W, W}}; 
			
			for(int i = 0; i<4; i++){
				ans[0] = init[i][0];
				ans[1] = init[i][1];
				
				for(int j = 1; j<N; j++){
					boolean a = true;
					if(s.charAt(j) == 'x'){
						a = false;
					}
					
					boolean hanten = a ^ ans[j];
					if(hanten){
						ans[j+1] = !ans[j-1];
					}else{
						ans[j+1] = ans[j-1];
					}
				}
				
				boolean b = S;
 
				boolean a = true;
				if(s.charAt(0) == 'x'){
					a = false;
				}
				boolean hanten = a ^ ans[0];
				if(hanten){
					b = !ans[N-1];
				}else{
					b = ans[N-1];
				}
 
				if((ans[0] == ans[N]) && (ans[1] == b)){ 
					for(int j = 0; j<N; j++){
						String c = ans[j] ? "S" : "W";
						System.out.print(c);
					}
					System.out.println();
					return;
				}
				
			}
			
			System.out.println(-1);
		}
	}
}


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

using namespace std;

int main(){
  int N, D;
  cin >> N >> D;
  int X[N][D];
  for (int i = 0; i < N; i++){
    for (int j = 0; j < D; j++){
      cin >> X[i][j];
    }
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      if(i != j){
        int s = 0;
        for (int k = 0; k < D; k++) s += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        float ss = sqrt(s);
        if((float)((int)ss) == ss) ans++;
      }  
    }
    
  }
  
  printf("%d\n", ans);
}


Measured memory_bytes: 3700
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int N6[110000] = {}, N9[110000] = {};

int main(){
	
	int N;
	cin >> N;
	
	for(int i = 0; i <= N; i++){
		int hoge = i;
		while(hoge > 0){
			N6[i] += hoge % 6;
			hoge /= 6;
		}
		hoge = i;
		while(hoge > 0){
			N9[i] += hoge % 9;
			hoge /= 9;
		}
	}
	
	int ans = 1e9;
	for(int i = 0; i <= N; i++){
		ans = min(ans, N6[i] + N9[N - i]);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))

boo = False
for i in a:
  if i % 2 == 0:
    if i % 3 != 0 and i % 5 != 0:
      boo = True

str = 'DENIED' if boo else 'APPROVED'
print(str)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c, x;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> x;
	int ans = 0;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (i * 500 + j * 100 + k * 50 == x)ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
s = [i for i in range(1, 14)]
h = s[:]
c = s[:]
d = s[:]

for i in range(n):
    a, b = input().split()
    if a == 'S':
        s.remove(int(b))
    elif a == 'H':
        h.remove(int(b))
    elif a == 'C':
        c.remove(int(b))
    else:
        d.remove(int(b))

if s:
    for i in s:
        print('S {}'.format(i))
if s:
    for i in h:
        print('H {}'.format(i))
if s:
    for i in c:
        print('C {}'.format(i))
if s:
    for i in d:
        print('D {}'.format(i))


Measured memory_bytes: 5600
import java.util.*;

public class Main {
	
	public static void main(String[] args) {

		// argumentの取得
		Scanner s = new Scanner(System.in);

		String x = s.next();
        if (x.equals("Sunny")) {
          System.out.println("Cloudy");
        } else if (x.equals("Cloudy")) {
          System.out.println("Rainy");
        } else {
          System.out.println("Sunny");
        }
      
		// 戻り値の返却
		//System.out.println(x);
	
	} 
}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    while(1){
        ll n;cin>>n;
        if(n==0)break;
        ll cnt=0;
        vector<bool>leg(2);
        int ii=1;
        rep(i,n){
            string s;cin>>s;
            if(s=="lu"){
                leg[0]=1;
            }if(s=="ru"){
                leg[1]=1;
            }if(s=="ld"){
                leg[0]=0;
            }if(s=="rd"){
                leg[1]=0;
            }
            if(leg[0]==ii&&leg[1]==ii){
                cnt++;
                ii=1-ii;
            }
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3092
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto & in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

std::set<int> queue;
int N, K;
int P[200010];
int upover[200010];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> K ;
	for (int i = 0; i < N; i++)
	{
		in >> P[i];
	}
	upover[0] = 1;
	for (int i = 1; i < N; i++)
	{
		if (P[i - 1] < P[i]) {
			upover[i] = upover[i - 1] + 1;
		}
		else {
			upover[i] = 1;
		}
	}

	int left = 0, right = 0;
	for (right = 0; right < K; right++)
	{
		queue.insert(P[right]);
	}
	bool noupdate_fin = upover[K - 1] >= K;
	int count = 1;
	while (right < N) {

		bool lside = P[left] == *queue.begin();
		bool rside = P[right] > *queue.rbegin();
		if (lside && rside) {

		}
		else if(upover[right] < K){
			++count;
		}
		else if (!noupdate_fin) {
			noupdate_fin = true;
			++count;
		}
		queue.erase(P[left]);
		++left;
		queue.insert(P[right]);
		++right;
	}
	out << count << endl;


	return 0;
}
#endif


Measured memory_bytes: 11136