akhauriyash/Code-Regression huggingface dataset:
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def equals(self,another):

        ret = False;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret

diceA = Dice()
diceB = Dice()

table = list(map(int,input().split()))
diceA.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

table = list(map(int,input().split()))
diceB.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

if diceA.equals(diceB):
    print("Yes")
else:
    print("No")



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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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


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

int32_t main()
{
	//c_p_c();
	int n;
	cin >> n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
			    if(arr[i] == arr[j] || arr[j] == arr[k] || arr[k] == arr[i]) continue;
				if(arr[i] < (arr[j] + arr[k]) and arr[j] < (arr[i] + arr[k]) and arr[k] < (arr[i] + arr[j])){
				    ans++;
				    //cout<<arr[i]<<" "<<arr[j]<<" "<<arr[k]<<endl; 
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3564
package main

import (
        "fmt"
        "math/big"
)

func gcd(m, n uint64) uint64 {
        x := new(big.Int)
        y := new(big.Int)
        z := new(big.Int)
        a := new(big.Int).SetUint64(m)
        b := new(big.Int).SetUint64(n)
        return z.GCD(x, y, a, b).Uint64()
}

func main() {
        var a, b uint64
        fmt.Scan(&a, &b)
        fmt.Println(gcd(a, b))
}



Measured memory_bytes: 1188
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;

int main(){
   int n;
   cin>>n;
   for(int i=n;i>0;i--){
      for(int j=1;j*j<=i;j++){
         if(j*j==i){
            cout<<i<<endl;
            return 0;
         }
      }
   }
}

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

int main(int argc, char const *argv[])
{
  int h, w;
  char *data;
  char tmp[100];
  int idx = 0;
  bool hmark[100];
  bool wmark[100];

  cin >> h >> w;

  // init
  for (int i = 0; i < h; i++)
  {
    hmark[i] = false;
  }
  for (int i = 0; i < w; i++)
  {
    wmark[i] = false;
  }

  // read data
  data = new char[h * w];
  for (int i = 0; i < h; i++)
  {
    cin >> tmp;
    for (int j = 0; j < w; j++)
    {
      data[idx++] = tmp[j];
    }
  }

  // calc
  for (int i = 0; i < h; i++)
  {
    bool blackAvailable = false;
    for (int j = 0; j < w; j++)
    {
      if (data[i * w + j] == '#')
      {
        blackAvailable = true;
        break;
      }
    }
    hmark[i] = !blackAvailable;
  }

  for (int i = 0; i < w; i++)
  {
    bool blackAvailable = false;
    for (int j = 0; j < h; j++)
    {
      if (data[j * w + i] == '#')
      {
        blackAvailable = true;
        break;
      }
    }
    wmark[i] = !blackAvailable;
  }

  // write
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      if (hmark[i] == false && wmark[j] == false)
      {
        cout << data[i * w + j];
      }
    }
    if (hmark[i] == false)
    {
      cout << endl;
    }
  }

  delete data;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;


int main(){
	long long out;
	int n;
	while(cin >> n){
		out = 1;
		for(int i = 0; i <= n; i++){
			if(i){
				out *= i;
			}
		}

		cout << out << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
(* O(k^2) (k = max n m) *)
Scanf.scanf " %d" @@ fun n ->
  let ss = Array.init n @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s in
  let m = Scanf.scanf " %d" @@ (+) 0 in
  let ts = Array.init m @@ fun _ -> Scanf.scanf " %s" @@ fun t -> t in
  let f acc s =
    let c = Array.fold_left (fun c s' -> if s' = s then c + 1 else c) 0 ss in
    let c = Array.fold_left (fun c t -> if t = s then c - 1 else c) c ts in
    max acc c in
  Array.to_list ss |> List.sort_uniq compare |> List.fold_left f 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;

vector<ll> g[2*100007];
vector<bool> vs(2*100007);


void dfs(ll s,ll &cnt)
{
    vs[s]=true;
    cnt++;
    ll i;
    
    for(i=0;i<g[s].size();i++)
    {
        if(vs[g[s][i]]==false)
        {
            dfs(g[s][i],cnt);
        }
    }
}

int main() 
{
    ll n,m,i,j;
    cin>>n>>m;
    
    map<pair<ll,ll>,ll> mp;
    
    ll x,y;
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        pair<ll,ll> p=make_pair(min(x,y),max(x,y));
        if(mp[p]==0)
        {
            g[x].push_back(y);
            g[y].push_back(x);
        }
        mp[p]++;
    }
    
    ll mx=0;
    for(i=1;i<=n;i++)
    {
        if(vs[i]==false)
        {
            ll cnt=0;
            dfs(i,cnt);
            mx=max(mx,cnt);
        }
    }
    cout<<mx;
}

Measured memory_bytes: 36332
import numpy as np
n, d = map(int, input().split())
x = np.array([[int(i) for i in input().split(" ")] for j in range(n)])
c = 0
for i in range(1,n):
    t = x[:-1*i,:]-x[1*i:,:]
    t = np.sqrt(np.sum(t*t, axis=1))
    c += np.sum(t%1==0)
print(c)

Measured memory_bytes: 22028
import java.util.Scanner;

public class Main {
    static final String[] t = {"dream", "dreamer", "erase", "eraser"};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        boolean flag = true;
        int i = s.length() - 1;

        while (i >= 0){
            for (int j = 0; j < 4; j++) {
                flag = true;
                for (int k = 0 ; k <t[j].length() ; k++) {
                    if (i-k < 0 || s.charAt(i-k)!=t[j].charAt(t[j].length() - 1 - k)){
                        flag = false;
                        break;
                    }
                }
                if (flag){
                    i -= t[j].length();
                    break;
                }
            }
            if (!flag) break;
        }

        System.out.println(((flag)?"YES":"NO"));
    }
}


Measured memory_bytes: 13732
n=int(input())
numlist=[int(i) for i in input().split()]
count=0
for i in range(1,n-1):
    if (numlist[i]>numlist[i-1] and numlist[i]<numlist[i+1]) or (numlist[i]<numlist[i-1] and numlist[i]>numlist[i+1]):
        count+=1
print(count)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  string s;
  cin>>s;

  if(s[0]=='9' || s[1]=='9') cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

from itertools import product

n, m = [int(x) for x in input().split()]
s = [[int(x) - 1 for x in input().split()][1:] for i in range(m)]
p = [int(x) for x in input().split()]

ans = 0

for ss in product((0, 1), repeat=n):
    for st, par in zip(s, p):
        if (sum(ss[sti] for sti in st) & 1) != par:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
  int n,ans=0,cnt=1,x=0;
  cin >> n;
  vector<int> a=input(n);
  for(int i=0;i<n;i++){
    if(a[i]>cnt||x==a[i]){
      ans++;
    }
    if(a[i]==cnt){
      cnt++;
      x=a[i];
    }
  }
  sort(a.begin(),a.end());
  if(a[0]!=1){
    cout << -1 << endl;
  }else{
    cout << n-x << endl;
  }
}


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

using namespace std;


int main(void){
    int n;
    cin>>n;
    int k;
    cin>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    
    int ans=0;
    for(int i=0;i<n;i++){
        ans+=min(a[i],k-a[i])*2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
#define int long long
using namespace std;
bool ispalindrome(string& s)
{
    int i=0;
    int j=s.size()-1;
    while(i<=j)
        if(s[i++]!=s[j--])
        return false;
    return true;
}
int modPow(int a,int b,int mod)
{
    while(b>1)
    {
        if(b%2==0)
        {
            a=a*a%mod;
            b/=2;
        }
        else
            return a*modPow(a,b-1,mod)%mod;
    }
    return a;

}
bool prime[2001];
void sieve()
{
    prime[1]=false;
    for(int i=2;i*i<2001;i++)
    {
        if(prime[i])
        {
            for(int j=i*i;j<2001;j+=i)
                prime[j]=false;
        }
    }
}
signed main() {
	//code

	bool ok=false;
	int n;
	cin>>n;
	int d[2][n];
    cin>>d[0][0]>>d[1][0]>>d[0][1]>>d[1][1];
    for(int i=2;i<n;i++)
    {
        cin>>d[0][i]>>d[1][i];
        if(d[0][i]==d[1][i] && d[0][i-1]==d[1][i-1] && d[0][i-2]==d[1][i-2])
            ok=true;
    }
    if(ok)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] list = str.split(" ");
		long n = Long.parseLong(list[0]);
		long m = Long.parseLong(list[1]);
		long answer = 0;

		if(n > m/2){
			answer = m/2;
		}else{
			answer = n + (m-n*2)/4;
		}
		System.out.println(answer);
	}

}


Measured memory_bytes: 20564
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define m_p			make_pair
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i =a, i>=b;i--)
#define sz(x)       (int)x.size()
#define F			first
#define S			second
#define debug(x)	for(int i=0;i<x;i++) cout<<"##########"<<endl
#define M			1000000007
#define ll			long long int
#define lMax		LLONG_MAX
#define pii 		pair<int ,int >
#define	all(a)		a.begin(), a.end()
#define vi 			vector<int> 
#define vii 		vector<pii>

// queue<int> , prefix_sum(a,a+n) , reverse(a,a+n) , priority_queue <int> max heap , priority_queue <int, vector<int>, greater<int> > min heap;
// == > != precedence gretaer then & , << precedence greater than <= == => , 
//int chk, cnt, fl, pos, in, src, tar, val, res. dummy;  fill (myvector.begin(),myvector.begin()+4,5), freq;

void solve()
{
	int n,k;
	cin>>n>>k;
	int arr[n];
	rep(i,0,n)
	{
		cin>>arr[i];
	}
	
	int dp[n];
	dp[0]=0;
	for(int i=1;i<=k && i<n;i++)
	{
		dp[i]=abs(arr[0]-arr[i]);
	}
	
	for(int i=k+1;i<n;i++)
	{
		dp[i]=INT_MAX;
		for(int j=1;j<=k;j++)
		{
			dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
		}
	}
	cout<<dp[n-1]<<endl;
}

signed main()
{
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		int t=1;
		while(t--)
		{
			solve();
		}
}

Measured memory_bytes: 1024
import math

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

def soinsu(test):
    list_sosu = []
    x = 0
    while x==0:
        for i in range(2,test+1):
            if i > int(math.sqrt(test)):
                list_sosu.append(test)
                x = 1
                break
            elif test % i == 0:
                test = int(test/i)
                if test == 1:
                    x = 1
                list_sosu.append(i)
                break
    return set(list_sosu)

if A == 1 or B == 1:
    print(1)
    
else:
    print(len(soinsu(A)&soinsu(B))+1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	int n;
	cin >> n;
	ll rem = n%1000;
	cout << (1000 - rem)%1000 << endl;

	return 0;
}


Measured memory_bytes: 3652
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x: isize,
        a: isize,
        b: isize,
    }

    if b - a > x{
        println!("dangerous");
    }else if b - a > 0{
        println!("safe");
    }else{
        println!("delicious");
    }
}


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

using namespace std;

#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef vector<int>vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

ll n,a,b,c;
string s,t[4];

int main()
{
	cin >> s;
	int len = s.length();
	int pos = 0;
	bool ans = true;
	t[0] = "dream";
	t[1] = "erase";
	while(pos<len)
	{
		if(s[pos]=='d')
		{
			//dream
			for(int i=0;i<5;i++)
			{
				if(s[pos+i]!=t[0][i]) ans = false;
			}
			if(ans) pos+=5;
			if(s[pos]=='e'&&s[pos+1]=='r'&&s[pos+2]!='a') pos+=2;
		}
		else
		{
			//erase
			for(int i=0;i<5;i++)
			{
				if(s[pos+i]!=t[1][i]) ans = false;
			}
			if(ans) pos+=5;
			if(s[pos]=='r') pos++;
		}
		//cout << ans << " " << pos << endl;
		if(!ans) break;
	}
	if(ans) cout << "YES\n";
	else cout << "NO\n";
	return 0;
}

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

using namespace std;

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

    if (b <= a) {
        string s = "";
        char c = '0' + b;
        for (int i = 0; i < a; ++i) {
            s = s + c;
        }
        cout << s;
        return 0;
    }
    else if (a < b) {
        string z = "";
        char x = '0' + a;
        for (int i = 0; i < b; ++i) {
            z = z + x;
        }
        cout << z;
        return 0;
    }

}

Measured memory_bytes: 256
function main()
  n, k = parse.(Int, split(readline()))

  mod = 10^9 + 7

  ans = 0
  count_list = zeros(Int, k)

  for i in k:-1:1
    count = powermod(div(k, i), n, mod)
    for j in 2:Int(floor(k / i))
      count -= count_list[i * j]
    end

    count_list[i] = count
    ans += count * i
  end

  println(ans % mod)
end

main()


Measured memory_bytes: 182668
#include <stdio.h>

#define SQ(X) \
  ( (X) * (X) )
#define CB(X) \
  ( (X) * (X) * (X) )
#define ABS(X) \
  ( (X) < 0 ? -(X) : (X) )

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    double res, q;
    int d;
    
    scanf ( "%d", &d );
    if ( d == -1 )  break ;

    q = (double)d;
    res = q / 2.;
    while ( ABS( CB( res ) - q ) >= q * 1.e-5 )
    {
      res = res - ( CB( res ) - q ) / 3. / SQ( res );
    }

    printf ( "%lf\n", res );
  }

  return ( 0 );
}

Measured memory_bytes: 0
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

def point(A):
    if A == "r":
        return P
    elif A == "s":
        return R
    else:
        return S

ans = 0
for i in range(K):
    s = T[i::K]
    t = "a"
    for j in range(len(s)):
        if t == s[j]:
            t = "a"
        else:
            ans += point(s[j])
            t = s[j]

print(ans)

Measured memory_bytes: 3316
#include <map>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
const int N=1e3+10;
int main(){
    int now=0,n,f,k,a[N][N];
    map<string,int> m;
    string s,b[N];
    vector<pair<string,string>> ans;
    vector<int> temp;
    scanf("%d%d",&n,&f);
    for(int i=0;i<n*10;i++)for(int j=0;j<n*10;j++)a[i][j]=0;
    for(int i=0;i<n;i++){
        scanf("%d",&k);
        temp.clear();
        for(int i=0;i<k;i++){
            cin>>s;
            if(m.find(s)==m.end()){
                temp.PB(now);
                b[now]=s;
                m.insert(MP(s,now++));
            }
            else temp.PB(m[s]);
        }
        for(int j=0;j<temp.size();j++)for(int r=0;r<temp.size();r++)a[temp[j]][temp[r]]++;
    }
    for(int i=0;i<now;i++)for(int j=i+1;j<now;j++)if(a[i][j]>=f){
        if(b[i]>b[j])ans.PB(MP(b[j],b[i]));
        else ans.PB(MP(b[i],b[j]));
    }
    sort(ans.begin(),ans.end());
    printf("%lu\n",ans.size());
    for(int i=0;i<ans.size();i++)cout<<ans[i].F<<" "<<ans[i].S<<endl;
}


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

using namespace std;

int main(){
	long long int K;
	cin >> K;
	vector<long long int>A(K);
	for( size_t i = 0; i < K; i++ ){
		cin >> A[i];
	}
	long long int ansmax = 2, ansmin = 2;
	for( int i = K - 1; i >= 0; i-- ){
		if( ( (int) ( ( ansmin - 1 ) / A[i] ) ) == ( (int) ( ansmax / A[i] ) ) ){
			cout << -1 << endl;
			return 0;
		}
		ansmin = ( ( ansmin - 1 ) / A[i] + 1 )*A[i];
		ansmax = ( ansmax / A[i] + 1 )*A[i] - 1;
	}
	cout << ansmin << " " << ansmax << endl;
}

Measured memory_bytes: 1024
import math
while True:
    n=int(input())
    if n==0:
        break
    sum=sqsum=0.0
    l=list(map(float,input().split()))
    for e in l:
        sum+=e
        sqsum+=e**2
    mean=sum/n
    sqmean=sqsum/n
    var=sqmean-mean**2
    std=math.sqrt(var)
    print('{:.8f}'.format(std))


Measured memory_bytes: 5776
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;

int K, N;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  priority_queue<int, vector<int>, greater<>> que;
  rep(i, N) {
    int a; cin >> a;
    que.push(a);
    if (que.size() > K) {
      que.pop();
    }
  }

  int sum = 0;
  rep(i, K) {
    sum += que.top();
    que.pop();
  }
  cout << sum << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX-1;
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };

ll sum(ll mi, ll ma) {
	ll res = (ma + 1)*ma / 2 - mi * (mi - 1) / 2;
	return res;
}



int main(){
	ll n, k;
	cin >> n >> k;


	ll ans = 0;
	if (k == 0) {
		ans = n * n;
	}
	else {
		for (ll b = 1; b <= n; b++) {
			if (k >= b)continue;
			ll ma = (n - k) / b;
			ll mi = (n - b + 1) / b;
			ll ma_mod = (n - k) % b;
			ll mi_mod = (n - b + 1) % b;
			if (ma == mi) {
				ans += (ma_mod - mi_mod + 1)*(ma + 1);
			}
			else if (ma == mi + 1) {
				ans += (ma + 1) * (ma_mod + 1);
				ans += (mi + 1) * (b - mi_mod);
			}
			else {
				ans += (ma + 1) * (ma_mod + 1);
				ans += (mi + 1) * (b - mi_mod);
				ans += b * sum(mi + 2, ma);
			}
		}
	}

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

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

using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  s.pop_back();
  bool tf = false;
  while (!tf and s.size() > 1) {
    if (s.size()%2==0) {
      string fsub = s.substr(0,s.size()/2), bsub = s.substr(s.size()/2, s.size()-1);
      if (fsub==bsub) tf = true;
      else s.pop_back();
    }
    else s.pop_back();
  }
  if (tf) cout << s.size() << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  ll N; cin>>N;
  ll H[N];
  rep(i,N){
    cin>>H[i];
  }
  ll i=0;
  ll count=0;
  
  while(i<N-1){
    ll a=0;
    while(H[i]<H[i+1]) {
      i++;
      if(i>N-2) break;
    }
    while(H[i]>=H[i+1]) {
      a++;
      i++;
      if(i>N-2) break;
    }
    count=max(count,a);
  }
  
    
  
  cout<<count<<endl;
}
  

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PF push_front
#define PB push_back
#define VE vector<int>
#define VP vector<PA>
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int MOD=1e9+7;
const int INF=1e9+7;
//
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PF push_front
#define PB push_back
#define VE vector<int>
#define VP vector<PA>
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
//
int H,W;
char S[50][50];
int sx=0,sy=0;
int gx,gy;
int D[50][50];
int DX[4]={-1,0,1,0};
int DY[4]={0,-1,0,1};
int BFS(){
  queue<PA> que;
  FOR(i,0,H){
    FOR(j,0,W){
      D[i][j]=INF;
    }
  }
  que.push(MA(sx,sy));
  D[sx][sy]=0;
  while(que.size()){
    PA P=que.front();
    que.pop();
    if(P.FI==gx&&P.SE==gy){
      break;
    }
    FOR(i,0,4){
      int NX=P.FI+DX[i],NY=P.SE+DY[i];
      if(0<=NX&&NX<H&&0<=NY&&NY<W&&S[NX][NY]=='.'&&D[NX][NY]==INF){
        que.push(MA(NX,NY));
        D[NX][NY]=D[P.FI][P.SE]+1;
      }
    }
  }
  return D[gx][gy];
}
int main(){
  cin>>H>>W;
  int cnt=0;
  FOR(i,0,H){
    FOR(j,0,W){
      cin>>S[i][j];
      if(S[i][j]=='.'){
        cnt++;
      }
    }
  }
  gx=H-1;gy=W-1;
  if(BFS()==INF){
    cout<<-1<<endl;
  }else{
    cout<<cnt-BFS()-1<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
	int i;
	int length;
	char str[5000+1];

	fgets(str, sizeof(str), stdin);
	length = strlen(str);
	if(str[length - 1] == '\n'){
		str[length - 1] = '\0';
	}
	
	for(i = 0; i < length-1; i++){
		if(str[i] >= 97 && str[i] <= 122){
			str[i] -= 32; 
		}
	}
	printf("%s\n",str);
	
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include<algorithm>
#include <vector>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define max(x,y) (((x)>(y)) ? x:y)
#define min(x,y) (((x)<(y)) ? x:y)
#define FOR(a) for(int i=0;i<a;i++)
#define ender {return 0;}
#define tosasuretu(a) (a*(a+1)/2)
inline ll kaizyo(ll);
ll gcd(ll, ll);
ll combination(ll, ll);
int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	int ans = H * W - ((h*W) + (H*w)) + (h * w);
	cout << ans;
	return 0;
}


inline ll kaizyo(ll x) {
	long ans = 1;
	for (int z = 0; z < x; z++) {
		ans *= (x - z);
	}
	return ans;
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int res = 0;
  
  for(int i = 0; i < 1000; ++i){
	stringstream ss;
    ss << setw(3) << setfill('0') << i;
    string num = ss.str();
    
    // numの何桁目を見ているか
    int idx_num = 0;
    
    for(int j = 0; j < n && idx_num < 3; ++j){
      // sの左から見ていって，一致すればidx_numを進める  
      if(num[idx_num] == s[j]){
        ++idx_num;
      }
      
      // idx_numが3になれば作れるのでカウント
      if(idx_num == 3){
        ++res;
      } 
    }
  }
  
  cout << res << endl;

}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        out.println(in.next().replace('1', '2').replace('9', '1').replace('2', '9'));
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

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

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll h,w;
    cin>>h>>w;
    string s[101];
    rep(i,0,h)cin>>s[i];
    ll dp[105][105];
    rep(i,0,h){
    	rep(j,0,w){
    		dp[i][j]=inf;
    	}
    }
    rep(i,0,h){
    	rep(j,0,w){
    		if (i+j==0)dp[i][j]=(s[i][j]=='#');
    		if (i>0)dp[i][j]=min(dp[i][j],dp[i-1][j]+(s[i][j]=='#' && s[i-1][j]=='.'));
    		if (j>0)dp[i][j]=min(dp[i][j],dp[i][j-1]+(s[i][j]=='#' && s[i][j-1]=='.'));    		
    	}
    }
    cout<<dp[h-1][w-1];
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 384
IDENTIFICATION DIVISION.
       PROGRAM-ID. ATCODER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  indata PIC X(100).
       01  a1 PIC S9(08).
       01  a2 PIC S9(08).
       01  a3 PIC S9(08).
       01  r1 PIC S9(08).
       01  r2 PIC S9(08).
       01  r3 PIC S9(08).
       01  r pic S9(08).
       01 disp pic Z(20)9.
       PROCEDURE DIVISION.
        ACCEPT indata.
        
        UNSTRING indata DELIMITED BY SPACE INTO a1 a2 a3.
        COMPUTE r1 = a1 + a2
        COMPUTE r2 = a1 + a3
        COMPUTE r3 = a2 + a3

        IF r1 <= r2 AND r1 <= r3 THEN
          MOVE FUNCTION TRIM(r1) to disp
          DISPLAY disp
        ELSE IF r2 <= r1 AND r2 <= r3 THEN
          MOVE FUNCTION TRIM(r2) to disp
          DISPLAY disp
        ELSE
          MOVE FUNCTION TRIM(r3) to disp
          DISPLAY disp
        END-IF
        END-IF


       STOP RUN.


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }

int main() {
    int n;
	cin >> n;
    
    float ans = 2 * 3.14159265 * n;
    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3784
n,m=map(int,input().split())
A=[]
[A.append(list(map(int,input().split()))) for i in range(m)]
ans=[1] if n!=1 else [0]
[ans.append(0) for i in range(n-1)]
for i in range(m):
  for j in range(m):
    if A[i][0]==A[j][0] and A[i][1]!=A[j][1]:
      print(-1)
      exit()
if [1,0] in A and n!=1:
  print(-1)
  exit()

for i in range(m):
  ans[A[i][0]-1]=A[i][1]
print(int("".join(map(str,ans))))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <queue>
//#include <tuple>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, a, b) for(int i=(a); i<(int)(b); i++)

typedef long long ll;

using namespace std;

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

int main(void){
	int n; cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];

	rep(i, n-1){
		rep2(j, i, n){
			swap(p[i], p[j]);
			bool flag = true;
			rep(k, n-1){
				if(p[k] > p[k+1]){
					flag = false;
					break;
				}
			}
			if(flag){
				cout << "YES" << endl;
				return 0;
			}
			swap(p[i], p[j]);
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

using namespace std;

int main(){
	int n, m, s, t, q, i, j;
	int id, color = 0;
	bool answer_yes = false;

	// enter
	cin >> n >> m;
	vector< vector<int> > Adj(n);
	vector<int> Stack;
	vector<int> Check(n, 0);
	vector<int>::iterator it, itend;
	for (i = 0; i < m; i++) {
		cin >> s >> t;
		Adj[s].push_back(t);
		Adj[t].push_back(s);
	}

	// calculate
	for (i = 0; i < n; i++) {
		if (Check[i] == 0) {
			color++;
			Stack.push_back(i);
			Check[i] = color;
			while (!Stack.empty()) {
				id = Stack.back();
				itend = Adj[id].end();
				for (it = Adj[id].begin(); it != itend; it++) {
					if (!Check[*it]) {
						Stack.push_back(*it);
						Check[*it] = color;
						break;
					}
				}
				if (it == itend) {
					Stack.pop_back();
				}
			}
		}
	}

	//find
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> s >> t;		
		if (Check[s] == Check[t]) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    n++;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a.at(i);
    }
    vector<ll> c(n);//分岐点の最大数

    c.at(0) =  (1 - a.at(0));
//    if (c.at(0) < 0) {
    if (1 < a.at(0)) {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 1; i < n; i++) {
        c.at(i) = 2 * (c.at(i - 1) - a.at(i - 1));
//        if (c.at(i) < 0) {
        if (2*(c.at(i-1)-a.at(i-1)) < 0) {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<ll> b(n);

    for (int i = n - 2; i >= 0; i--) {
        ll ab = a.at(i + 1) + b.at(i + 1);
        if(c.at(i) < a.at(i)){
            cout << -1 << endl;
            return 0;
        }
        ll ca = c.at(i) - a.at(i);
        if (ab <= ca) {
            b.at(i) = ab;
        } else if (ab <= 2 * ca) {
            b.at(i) = ca;
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    ll ans = 0;
    rep(i, n) {
        ans += b.at(i) + a.at(i);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5640
from sys import stdin
def main():
    readline=stdin.readline
    s=readline().strip()

    res=0
    for i in range(len(s)):
        if i%2==0:
            if s[i]=="g":
                pass
            else:
                res-=1
        else:
            if s[i]=="g":
                res+=1
            else:
                pass
            
    print(res)

if __name__=="__main__":
    main()

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

int main(){
  int a,b;cin >> a >> b;
  if(a == b)cout << "Draw" << endl;
  else if(a == 1)cout << "Alice" << endl;
  else if(b == 1)cout << "Bob" << endl;
  else if(a>b)cout << "Alice" << endl;
  else if(b>a)cout << "Bob" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

vector<LL> make_divisors(LL n) {
    vector<LL> res;

    for (LL i = 1LL; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }

    return res;
}
int main() {
    int n; LL m;
    cin >> n >> m;

    auto divs = make_divisors(m);

    LL ans = 1;
    for (auto d : divs) {
        if (d * n <= m) ans = max(ans, d);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from functools import lru_cache
import sys
 
sys.setrecursionlimit(10 ** 9)
 
t = int(input())
 
for _ in range(t):
  n,a,b,c,d = map(int, input().split())
  #辞書形式で最低枚数を管理
  dic = {0:0, 1:d}
  @lru_cache(maxsize = None)
  def f(n):
    if n in dic:
      return dic[n]
    #dを全部使う
    nn = n * d
    #nの直近の5の倍数を経由、以下同様
    n5 = (n % 5) * d + c + f(n // 5)
    if n % 5 != 0:
      ##n = 11の場合、n % 5 = 1, -n % 5 = 4
      n5 = min(n5, (-n % 5) * d + c + f((n // 5) + 1))
    n3 = (n % 3) * d + b + f(n // 3)
    if n % 3 != 0:
      n3 = min(n3, (-n % 3) * d + b + f((n // 3) + 1))
    n2 = (n % 2) * d + a + f(n // 2)
    if n % 2 != 0:
      n2 = min(n2, (n % 2) * d + a + f((n // 2) + 1))

    ret = min(nn, n2, n3, n5)
    dic[n] = ret
    return ret
 
  print(f(n))

Measured memory_bytes: 11824
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N;

const int S = 55555;
bool is_prime[S+10];
 
signed main() {
    memset(is_prime, true, sizeof(is_prime));
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<=S; i++) {
        if(is_prime[i]) {
            for(int k=2*i; k<=S; k+=i) {
                is_prime[k] = false;
            }
        }
    }

    vector<int> ans;

    for(int i=3; i<=S; i++) {
        if(is_prime[i] && i % 5 == 1) {
            ans.push_back(i);
        }
    }

    cin >> N;
    for(int i=0; i<N; i++) {
        printf("%lld%c", ans[i], (i+1 == N ? '\n' : ' '));
    }
    return 0;
}

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

int M;
int N;
const int INF = 1500000;
vector<int> book;

bool c(int x) {
	int d = 1;
	int wid = 0;
	for (int i = 0; i < N; i++) {
		wid += book[i];
		if (wid > x) {
			wid = 0;
			d++;
			i--;
		}
	}
	return d <= M;
}

int main(void) {
	while (cin >> M >> N, N) {
		// input
		book.clear();
		int buf;
		for (int i = 0; i < N; i++) {
			cin >> buf;
			book.push_back(buf);
		}

		// calc
		int l = *(max_element(book.begin(), book.end())) - 1, u = INF;
		while (u - l > 1) {
			int mid = (l + u) / 2;
			if (c(mid)) {
				u = mid;
			}else {
				l = mid;
			}
		}

		// output
		cout << u << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

ll gcd(ll x, ll y){
      return (y==0)? x: gcd(y,x%y);
   }

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = a * b / gcd(a,b);
    cout  <<  ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

int N;
int a[11];

i64 slv(int i, i64 mul)
{
  if (i >= N) { return !(mul & 1) ? 1 : 0; }
  return
    slv(i+1, mul * (a[i]  )) +
    slv(i+1, mul * (a[i]-1)) +
    slv(i+1, mul * (a[i]+1));
}

signed main()
{
  cin >> N;

  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    if (a[i] > 2) {
      a[i] = (a[i] & 1) ? 3 : 2;
    }
  }

  cout << slv(0, 1) << endl;


  return 0;
}



Measured memory_bytes: 256