akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Dice {
	public int[] value;
	public Dice(String[] info, int size) {
		this.value = new int[size];
		for (int i = 0; i < size; i++) {
			this.value[i] = Integer.parseInt(info[i]);
		}
	}
}

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Dice dice = new Dice(br.readLine().split(" "), 6);
		String[] commands = br.readLine().split("");

		for (String command : commands) {
			int work = dice.value[0];
			if (command.equals("N")) {
				dice.value[0] = dice.value[1];
				dice.value[1] = dice.value[5];
				dice.value[5] = dice.value[4];
				dice.value[4] = work;
			} else if (command.equals("E")) {
				dice.value[0] = dice.value[3];
				dice.value[3] = dice.value[5];
				dice.value[5] = dice.value[2];
				dice.value[2] = work;
			} else if (command.equals("W")) {
				dice.value[0] = dice.value[2];
				dice.value[2] = dice.value[5];
				dice.value[5] = dice.value[3];
				dice.value[3] = work;
			} else {
				dice.value[0] = dice.value[4];
				dice.value[4] = dice.value[5];
				dice.value[5] = dice.value[1];
				dice.value[1] = work;
			}
		}
		System.out.println(dice.value[0]);
	}
}

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

int main()
{
	int n;
	while(cin >> n){
		if(!n)
			break;
		int m[100],a[100],b[100];
		int t[200];
		int max_m = 150;
		for(int i=0;i<n;i++){
			m[i]=0;a[i]=0;b[i]=0;
			t[i]=0;t[n+i]=0;
		}
		int pos = 0;
		for(int i=0;i<n;i++){
			cin >> m[i] >> a[i] >> b[i];
			t[pos++] = a[i];t[pos++] = b[i];
		}
		sort(t,t+(2*n));

		pos = 0;
		while(pos < 2*n){
			int tmp = t[pos++];
			for(int i=0;i<n;i++){
				if(tmp==b[i])
					max_m += m[i];
				if(tmp==a[i])
					max_m -= m[i];
			}
			if(max_m < 0){
				cout << "NG" << endl;
				break;
			}
			while(1){
				if(t[pos]!=t[pos-1])
					break;
				else
					pos++;
			}
		}
		if(max_m >= 0)
			cout << "OK" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void){
int a,b,c;
  scanf("%d", &a);
  if(a==1){
    printf("Hello World\n");
 } else if (a==2){
    scanf("%d", &b);
  scanf("%d", &c);
printf("%d\n", c+b);

    }

return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////




int main() {

	ll N;
	cin >> N;
	string S;
	cin >> S;

	vector<ll> A(2*N + 1,0);

	repn(i, 2 * N) {
		if (S[i - 1] == 'B') { A[i] = 1; }
	}

	vector<ll> L(2 * N + 1);
	ll t = 0;

	repn(i, 2 * N) {
		if (t % 2 != A[i]) { L[i] = 0; t++; }
		else { L[i] = 1; t--; }
	}

	ll ans = 0;

	if (t == 0) {
		ans = 1;
		ll l = 0;

		for (ll i = 2 * N; i > 0; i--) {
			if (L[i] == 1) { l++; }
			else { ans = ans * l%MOD; l--; }
		}

		repn(i, N) {
			ans = ans * i%MOD;
		}
	}
	
	cout << ans;

	system("PAUSE");

}


Measured memory_bytes: 3964
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val an = readLine()!!.split(" ").map(String::toInt)
    val bn = readLine()!!.split(" ").map(String::toInt)
    val cn = readLine()!!.split(" ").map(String::toInt)
    var ans = 0
    an.withIndex().forEach {
        ans += bn[it.value-1]
        if (it.index != 0 && (an[it.index-1]+1 == an[it.index])) {
            ans += cn[an[it.index-1] - 1]
        }
    }
    println(ans)
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

const lli MAX = 1000100;
const lli MOD = 1000000007;

lli dp[100][100];

void func(long long N, long long A, long long B, std::vector<long long> v){

    A--,B--;
    sort(v.rbegin(),v.rend());

    dp[0][0]=1;
    REP(i,0,100){
        REP(j,0,i+1){
            dp[i+1][j] += dp[i][j];
            dp[i+1][j+1] += dp[i][j];
        }
    }

    map<lli,lli> cnt;
    REP(i,0,N)cnt[v[i]]++;
    
    lli ans = 0;
    double ansper=0;
    cout<<setprecision(15);
    if(v[0]==v[A]){
        lli s = A+1;
        lli e = min(B+1,cnt[v[0]]);
        REP(i,s,e+1){
            ans += dp[cnt[v[0]]][i];
        }
        ansper = v[0];
    }
    else{
        REP(i,0,A+1)ansper += v[i];
        lli length = 0;
        REP(i,0,N)if(v[i]>v[A])length++;
        ansper = ansper/(double)(A+1);
        ans = dp[cnt[v[A]]][A-length+1];
        LOG2(A,length)
    }
    cout<<ansper<<endl;
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    std::vector<long long> v(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&v[i]);
    }
    func(N, A, B, std::move(v));
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    string s;
    cin>>s;
    int m=-1;
    rep(i,s.size()){
        int count=0;
        for(int j=i;j<s.size();j++){
            if(s.at(j)=='A'||s.at(j)=='C'||s.at(j)=='G'||s.at(j)=='T'){
                count++;
            }
            else{
                break;
            }
        }
        m=max(m,count);
    }
    cout<<m<<endl;
}


Measured memory_bytes: 256
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=200005;
vi v[N];
ll val[N];
// ll par[N];
void dfs(ll curr,ll p){
    val[curr]+=val[p];
    for(auto i:v[curr]){
        if(i==p) continue;
        dfs(i,curr);
    }
}
void solve(){
    ll n,m,a,b;
    cin>>n>>m;
    rep(i,1,n-1){
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    rep(i,1,m){
        cin>>a>>b;
        val[a]+=b;
    }
    dfs(1,0);
    rep(i,1,n) cout<<val[i]<<" ";

}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 24320
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
string a;
char c[100];
int top=1;
int main(){
	cin>>a;
	for(int i=0;i<a.size();i++){
		if(a[i]=='B')top--;
		if(top==0)top=1;
		if(a[i]!='B') c[top++]=a[i];
	}
	for(int i=1;i<top;i++)cout<<c[i];
	return 0;
}


Measured memory_bytes: 256
import numpy as np

A, B, C, X,Y = map(int,input().split())

m = min(X,Y)
p = np.abs(X-Y)

A_B_only = A*X+B*Y
A_B = A*m+B*m+p*2*C

if X<Y:
  AB = m*2*C+p*B
  AB_only = Y*2*C
elif Y<X:
  AB = m*2*C+p*A
  AB_only = X*2*C
elif X==Y:
  AB = m*2*C
  AB_only = X*2*C


print(min(A_B,AB,AB_only,A_B_only))

Measured memory_bytes: 12504
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	H := 0
	fmt.Fscan(read, &H)
	for i := 0; i < n-1; i++ {
		var h int
		fmt.Fscan(read, &h)

		if H > h {
			fmt.Fprintln(write, "No")
			return
		}

		if H < h {
			H = h - 1
		}
	}
	fmt.Fprintln(write, "Yes")
}


Measured memory_bytes: 3072
alp = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
       "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
s = list(input())
k = int(input())
a = 0
while k > 0:
    for i in range(26):
        if alp[i] == s[a]:
            t = i
            break
    if a == len(s) - 1:
        s[a] = alp[(t + k) % 26]
        break
    elif s[a] == "a":
        a = a
    elif 26 - t <= k:
        s[a] = "a"
        k -= 26 - t
    a += 1
print("".join(s))

Measured memory_bytes: 4152
n = int(input())
A = list(map(int,input().split()))
peer = [[] for _ in range(n)]
for _ in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append(b)
  peer[b].append(a)
inf = 10**12
minf = 10**11
pre = [inf for _ in range(n)]
pst = [[] for _ in range(n)]
right = [inf for _ in range(n)]
seen = [0 for _ in range(n)]
seen[0] = 1
now = [0]
while now:
  last = now
  now = []
  for x in last:
    for y in peer[x]:
      if seen[y] == 0:
        now.append(y)
        seen[y] = 1
        pre[y] = x
        right[y] = x
        if pst[x]:
          right[pst[x][-1]] = y
        pst[x].append(y)
down = [i for i in range(n)]
for i in range(n):
  if pst[i]:
    down[i] = pst[i][0]
#print(pre)
#print(right)
#print(pst)
#print(down)
seen = [0 for _ in range(n)]
import bisect
lis = [inf for _ in range(n)]
rec = [[] for _ in range(n)]
now = 0
ans = [0 for _ in range(n)]
while True:
  if seen[now] == 0:
    seen[now] += 1
    #print(A[now],lis)
    b = bisect.bisect_left(lis,A[now])
    rec[now] = [b,lis[b]]
    lis[b] = A[now]
    ans[now] = bisect.bisect_left(lis,minf)
    now = down[now]
  else:
    seen[now] += 1
    b,c = rec[now]
    lis[b] = c
    if now == 0:
      break
    now = right[now]
for x in ans:
  print(x)

Measured memory_bytes: 175920
import Data.List

f::Int->Int->Char
f n k
   |n<=k='w'
   |otherwise=' '

f2::Int->[Int]->Int
f2 n xs =let ys=filter ((=='w').head) $ group $ map (f n) xs
         in (length ys)

main=do
     e<-getLine
     es<-getLine
     let xs=map read (words es)::[Int]
     putStrLn $ show $ sum [f2 e xs|e<-[1..(maximum xs)]]

Measured memory_bytes: 1020
n, k = map(int, input().split(' '))
mod = int(1e9) + 7
ans = 0
for i in range(k, n + 2):
    lo = i * (i - 1) // 2
    hi = i * (2 * n - i + 1) // 2
    ans = (ans + hi - lo + 1) % mod
print(ans)

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

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

bool z[8];
int t;

int main() {
	int N; cin >> N;
	F0R(i,N) {
	    int x; cin >> x;
	    if (x<3200) z[x/400] = 1;
	    else t++;
	}
	int sum = 0; F0R(i,8) sum += z[i];
	cout << max(sum,1) << " " << sum+t;
}

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

using namespace std;

int r, D;
long long x;
long long ans;

int main(){
	scanf("%d%d%lld", &r, &D, &x);

	for(int i = 1; i <= 10; i++){
		ans = x * r - D;
		printf("%lld\n", ans);
		x = ans;
	}
	
	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);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long k = sc.nextLong();
		if (a >= k) {
			System.out.println((a - k) + " " + b);
			return;
		}

		System.out.println(0 + " " + Math.max(0, b - (k - a)));
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  string S;
  cin >> S;
  int cnt = 0;
  int N = S.length();
  REP(i, 0, S.length()/2) {
    if (S[i] != S[N - 1 - i]) cnt++;
  }
  cout<<cnt<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
// #define dump(x) cerr << #x << " = " << (x) << endl;
// #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
//                       << " " << __FILE__ << endl;

int main()
{
    long N, M;
    cin >> N >> M;

    priority_queue<long> q;

    REP(i, N)
    {
        long a;
        cin >> a;
        q.push(a);
    }

    REP(i, M)
    {
        long a = q.top();
        q.pop();

        q.push(a / 2);
    }

    long long sum = 0;
    REP(i, N)
    {

        sum += q.top();
        q.pop();
    }

    cout << sum << endl;
}

Measured memory_bytes: 1400
import math
n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]

s = 0
for i in range(n-1):
  for j in range(i+1,n):
    s += math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)
print(s*2/n)

Measured memory_bytes: 3060
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        var scaner = new Scanner(System.in);
        
        var n = scaner.nextInt();

        System.out.println((int)(n+Math.pow(n, 2)+Math.pow(n, 3)));

        scaner.close();
    }

}


Measured memory_bytes: 35872
#include <iostream>
using namespace std;
typedef long long ll;
ll k, a[210000], sma, lar, ans;
int main(void){
    // Your code here!
    cin >> k;
    sma = 2, lar = 2;
    for (ll i = 0; i < k; i++) cin >> a[i];
    for (ll i = k - 1; i >= 0; i--) {
        sma = ((sma - 1) / a[i] + 1) * a[i];
        lar = (lar / a[i] + 1) * a[i] - 1;
        if (sma > lar) ans++;
    }
    if (ans) cout << -1 << endl;
    else cout << sma << ' ' << lar << endl;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

int nc2 ( int n )
{
    n *= ( n - 1 ) ;
    n >>= 1 ;

    return n ;
}

void solve ( int test_case )
{
    int n , m ;
    cin >> n >> m ;

    int ans = nc2 ( n ) + nc2 ( m ) ;
    cout << ans ; line
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n;
    cin >> n;
    vll vec(n);
    ll count = 0;
    REP(i, n) cin >> vec.at(i);
    while (true) {
        REP(i, n) {
            if (vec.at(i) % 2 == 1) {
                cout << count << endl;
                return 0;
            }
            vec.at(i) /= 2;
        }
        count++;
    }
    return 0;
}

Measured memory_bytes: 256
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


N, M, X, Y = map(int, input().split())
x = readints()
y = readints()
# print(x)
# print(y)


def func(z):
    if (X < z and z <= Y):
        pass
    else:
        return False
    for i in range(N):
        if x[i] < z:
            pass
        else:
            return False
    for i in range(M):
        if y[i] >= z:
            pass
        else:
            return False
    return True


for i in range(-10000, 10000):
    if func(i) == True:
        print('No War')
        exit()
print('War')


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define N 100050
using namespace std;
typedef long long LL;
int n,x[N],y[N],a[N],b[N],fa[N],cnt;
LL ans = 0LL;

struct Edge{int a,b,v;}e[2*N];
bool cmp(Edge p1, Edge p2) {
	return p1.v < p2.v;
}


bool cmp1(int p1, int p2) {return x[p1] < x[p2];}
bool cmp2(int p1, int p2) {return y[p1] < y[p2];}

inline int rd() {
	int x=0,f=1;char ch=getchar();
	while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
int gf(int x) {return fa[x]==x?x:fa[x]=gf(fa[x]);}
int main() {
	n = rd();
	for (int i=1;i<=n;i++) x[i] = rd(), y[i] = rd();

	for (int i=1;i<=n;i++) fa[i] = a[i] = b[i] = i;
	sort(a+1,a+n+1,cmp1);
	sort(b+1,b+n+1,cmp2);
	
	for (int i=1;i<n;i++) e[++cnt] = (Edge){a[i], a[i+1], x[a[i+1]]-x[a[i]]};
	for (int i=1;i<n;i++) e[++cnt] = (Edge){b[i], b[i+1], y[b[i+1]]-y[b[i]]};
	
	sort(e+1,e+cnt+1,cmp);
	for (int i=1;i<=cnt;i++) {
		if (gf(e[i].a) != gf(e[i].b)) {
			fa[ gf(e[i].a) ] = gf(e[i].b);
			ans += e[i].v;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4608
#include <stdio.h>
int main(void){
	int a,b,c,d,e,ans;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(a<0)
		printf("%d\n",(-a)*c+d+b*e);
	else
		printf("%d\n",(b-a)*e);
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<sstream>
#include<numeric>
using namespace std;


int main() {

	unsigned int a, i, j, k, x, y;
	cin >> a;
	x = 0;
	for (i = 1; i <= a; i++) {
		for (j = 1; j <= a; j++) {
			y = gcd(i, j);
			for (k = 1; k <= a; k++) {
				x += (gcd(y, k));
			}
		}
	}
	cout << x << endl;
	return 0;
}

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

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

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 a, b, c, k;
    cin >> a >> b >> c >> k;

    cout << (k % 2 ? b - a : a - b) << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <string.h>
#define MOD 1000000007
#define N_MAX 200006

using namespace std;
typedef long long ll;

void ans(int k, int s, int t){
	if(__builtin_popcount(k) == 1)
    	cout << s << ' ' << t << ' ';
  	else {
    	int p = 1;
      	while(!(k&p) || !((s^t)&p))
        	p <<= 1;
      	int q = 1;
      	while(p == q || !(k&q))
          	q <<= 1;
      	ans(k^p, s, s^q);
      	ans(k^p, s^q^p, t);
    }
}
 
int main(){
	int N, A, B;
	cin >> N >> A >> B;
  	if(__builtin_popcount(A^B)%2 == 0)
    	cout << "NO" << endl;
  	else {
    	cout << "YES" << endl;
      	ans((1 << N)-1, A, B);
      	cout << endl;
    }
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define mp make_pair
#define np next_permutation
#define pb push_back
#define all(x) (x.begin(),x.end())
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)

#define fi first
#define se second 
using namespace std;
const int maxn=1e4+5;
const int maxl=26;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
int main()
{
	ios::sync_with_stdio(false); 
	string s;
	ull k;
	while(cin>>s>>k){
		int index=0;
		for(int i=0;i<s.length();i++){
			if(s[i]!='1'){
				index=i;
				break;
			}
		}
		if(k-1<index) cout<<1<<endl;
		else cout<<s[index]<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i;
  scanf("%d",&n);
  long int x,y;
  scanf("%li%li",&x,&y);
  long int sum=x+y, dif=x-y, maxsum=sum,minsum=sum,maxdif=dif,mindif=dif;
  for (i=1;i<n;i++){
    scanf("%li%li",&x,&y);
    sum=x+y;
    dif=x-y;
    if (sum>maxsum) maxsum=sum;
    else if(sum<minsum) minsum = sum;
    if (dif>maxdif) maxdif=dif;
    else if(dif<mindif) mindif=dif;
  }
  sum=maxsum-minsum;
  dif=maxdif-mindif;
  if(sum>dif) printf("%li\n", sum);
  else printf("%li\n", dif);
  return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

vector<ll> ans;
ll n;

void dfs(vector<ll> &a) {
  if (a.size() == n) {
    //処理

    vector<bool> f(3, false);
    REP(i, n) {
      if (a[i] == 3) f[0] = true;
      if (a[i] == 5) f[1] = true;
      if (a[i] == 7) f[2] = true;
    }
    if (!(f[0] && f[1] && f[2])) return;

    ll t = 0;
    REP(i, n) { t += pow(10, n - i - 1) * a[i]; }
    ans.push_back(t);
    // DEBUG(t);
    return;
  }
  vector<ll> t = {3, 5, 7};
  for (ll i = 0; i < 3; i++) {
    a.push_back(t[i]);
    dfs(a);
    a.pop_back();
  }
}

int main() {
  ll k;
  cin >> k;
  vector<ll> a;
  REP(i, 9) {
    n = i + 1;
    dfs(a);
  }
  sort(ALL(ans));
  ll cnt = 0;
  REP(i, ans.size()) {
    if (ans[i] <= k) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;

#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define ll long long
#define dbg(x) cout << #x << "=" << x << endl
#define dbg2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>  vi;
typedef vector<ll>  vl;
typedef vector<pii>  vpii;
typedef vector<pl>  vpl;
typedef vector<vi>  vvi;
typedef vector<vl>  vvl;
const int mod = 1000000007;

int main()
{
    int n{}, m{};
    cin >> n >> m;
    int sum{};
    for(int i = 0; i < m; i++){
        int x{};
        cin >> x;
        sum += x;
    }
    if(sum > n) cout << -1;
    else cout << n - sum;
}


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

signed main(){
  lint N; cin >> N;
  vector<lint> a(N);
  for(lint i = 0; i < N; i++) cin >> a[i], a[i] -= (i + 1);
  sort(a.begin(), a.end());
  lint x, ans = 0;
  if(N % 2 == 0) x = (a[N/2] + a[N/2 -1])/2;
  else x = a[N/2];
  for(lint i = 0; i < N; i++) ans += abs(x - a[i]);
  cout << ans << endl;
}

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

int main(){
 int n,k ;
  cin >> n >> k;
  int a[n]={0};
  for(int i = 0; i< n; i++) cin >> a[i];
 
int K = min(k,100);
for(int cnt= 1; cnt<=K; cnt++){
   int b[n] = {0};
  for(int i = 0; i< n; i++) {
        b[max(i-a[i], 0)] ++;
        b[min(i+a[i],n-1)+1]--;
      } 
  a[0] = b[0];
  for(int i = 1; i< n; i++)  a[i] = a[i-1]+ b[i];
}
 for(int i = 0; i< n; i++) cout << a[i] << " ";
 return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

int sx,sy,gx,gy;
bool ng[222][222];
int H,W;

const int INF=1001001001;
int dist[222][222][6];

bool ok(int y,int x){
    if(ng[y][x])return false;
    y-=100;x-=100;
    if(y<-H||y>H||x<-W||x>W)return false;
    return true;
}

signed main(){
    cin>>sx>>sy>>gx>>gy;
    sx+=100;sy+=100;gx+=100;gy+=100;
    int n;cin>>n;
    rep(i,n){
        int x,y;
        cin>>x>>y;
        x+=100;y+=100;
        ng[y][x]=true;
    }
    cin>>W>>H;

    fill_n(**dist,222*222*6,INF);
    dist[sy][sx][0]=0;
    priority_queue<tuple<int,int,int,int>,vector<tuple<int,int,int,int>>,greater<tuple<int,int,int,int>>>que;
    que.push(make_tuple(0,sy,sx,0));
    while(que.size()){
        int c,y,x,t;
        tie(c,y,x,t)=que.top();
        que.pop();
        if(dist[y][x][t]<c)continue;

        int h=abs((x-100)*(y-100)*t)%6;

        rep(i,7){
            int ny=y+dy[x%2][i],nx=x+dx[i],nt=(t+1)%6;
            if(!ok(ny,nx))continue;
            if(dist[ny][nx][nt]<=c+(i!=h))continue;
            dist[ny][nx][nt]=c+(i!=h);
            que.push(make_tuple(c+(i!=h),ny,nx,nt));
        }
    }

    int mi=INF;
    rep(i,6)chmin(mi,dist[gy][gx][i]);
    if(mi==INF)cout<<-1<<endl;
    else cout<<mi<<endl;
    return 0;
}

Measured memory_bytes: 5576
def main():
    from builtins import int, map, list, print, max
    import sys, math
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    A, B, N = input_number_list()
    x = min(B - 1, N)
    print(math.floor(A * x / B) - A * math.floor(x / B))


if __name__ == '__main__':
    main()


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

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

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

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

  int n, m, x;
  cin >> n >> m >> x;
  vi c(n);
  vector<vi> a(n, vi(m));
  rep(i, 0, n) {
    cin >> c[i];
    rep(j, 0, m)
      cin >> a[i][j];
  }

  const int INF = 1031231234;
  int best = INF;
  rep(bm, 0, 1 << n) {
    vi got(m);
    int cost = 0;
    rep(i, 0, n) {
      if (bm & (1 << i)) {
	cost += c[i];
	rep(j, 0, m) {
	  got[j] += a[i][j];
	}
      }
    }
    bool good = true;
    rep(j, 0, m) {
      if (got[j] < x) good = false;
    }
    if (good) {
      best = min(best, cost);
    }
  }
  if (best < INF) cout << best << '\n';
  else cout << -1 << '\n';
}


Measured memory_bytes: 3664
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

// index が条件を満たすかどうか
int main() {
	int a, b;
	cin >> a >> b;
	vector<string > s;
	string s1;
	string s2;
	for (int i = 0; i < a; i++) {
		s1 = s1 + to_string(b);
	}
	for (int i = 0; i < b; i++) {
		s2 = s2 + to_string(a);
	}
	s.push_back(s1);
	s.push_back(s2);
	sort(s.begin(), s.end());
	cout << s[0];
}

Measured memory_bytes: 256
from collections import Counter
def main():
    N, K = [int(x) for x in input().split()]
    counter = Counter()
    for _ in range(K):
        _ = input()
        counter += Counter([int(x) for x in input().split()])

    ans = 0
    for x in range(1, N+1):
        if counter[x] == 0:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9468
#include<bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
using namespace std;
ll h;ll w;char a[1000][1000];
ll dp[1000][1000];
int main()
{
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<h;i++){
            if(a[i][0]=='.')
        dp[i][0]=1;
            else
        break;
    }
       for(int i=0;i<w;i++){
            if(a[0][i]=='.')
        dp[0][i]=1;
            else
        break;
    }
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++)
        {   if(a[i][j]=='#')
            dp[i][j]=0;
            else
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }
    cout<<dp[h-1][w-1];
}


Measured memory_bytes: 9088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Read();
            var N = S.Length;
            if (KaibunCheck(S))
            {
                var a = S.Substring(0, ((N - 1) / 2));
                if (KaibunCheck(a))
                {
                    var b = S.Substring(((N + 3) / 2) - 1);
                    if (KaibunCheck(b))
                    {
                        WriteLine("Yes");
                        return;
                    }
                }
            }
            WriteLine("No");

        }
        static bool KaibunCheck(string S)
        {
            var Reversed_S = S.Reverse();
            if (S == string.Join("", Reversed_S))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
from itertools import combinations

N, K = map(int, input().split())

a = list(map(int, input().split()))
sub_a = {0}
a_first = a[0]

res = 10**11 # min(res, ) を取る場合はresを大きい数に取る

for j in range(N):
    if a_first < a[j]:
        sub_a.add(j)
        a_first = a[j]

colors = len(sub_a) # 最初に見えている色の種類
not_sub_a = {i for i in range(N)} - sub_a


for k in combinations(not_sub_a, K - colors):
    cost = 0
    test_a = []
    for i in range(N):
        if i in sub_a or i in k:
            test_a.append(a[i]) # test_a には左から写る予定のK個のビルの高さが入っている
    for i in range(len(test_a)-1):
        if test_a[i] >= test_a[i+1]:
            cost += test_a[i] - test_a[i+1] +1
            test_a[i+1] = test_a[i] + 1
    res = min(res, cost)

print(res)



Measured memory_bytes: 40432
n = int(input())
A = sorted(map(int, input().split()))

U = 10**6
line = [1]*(U+1)
ans = set()
depricated = set()
cnt = [0]*(U+1)
for a in A:
    cnt[a] += 1
    if cnt[a] == 2 and line[a]:
        depricated.add(a)
        continue
    if 2 < cnt[a]:
        continue
    if line[a]:
        ans.add(a)
        for p in range(2*a, U+1, a):
            line[p] = 0
print(len(ans-depricated))


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

int main() {
	string s;
	cin >> s;
	if (s == "RSR")
	{
		cout << "1";
		return 0;
	}
	size_t n = count(s.begin(), s.end(), 'R');
	cout << n;
}

Measured memory_bytes: 3596
N = int(input())

M1 = [6**i for i in range(7)]
M2 = [9**i for i in range(6)]
M = list(set(M1 + M2))
M.sort()
#print(M)


dp = [0 for i in range(N+1)]
dp[0] = 1

for i in range(1, N+1):
    if i in M:
        dp[i] = 1
    else:
        dp[i] = min(dp[i-1] + 1, dp[i])
    for j in M:
        if i + j <= N:
            if dp[i+j] == 0:
                dp[i+j] = dp[i] + 1
            else:
                dp[i+j] = min(dp[i] + 1, dp[i+j])

            #print(i, dp[i+j])
#print(dp)
print(dp[N])

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

int64_t gcd(int a, int b) {
	if (a > b) {
		return gcd(b, a);
	}
	else if (a == 0) {
		return b;
	}
	else {
		return gcd(b % a, a);
	}
}

int main() {
	int K;
	cin >> K;
	int64_t ans = 0;
	for (int i = 1;i <= K;++i) {
		for (int j = i;j <= K;++j) {
			for (int k = j;k <= K;++k) {
				if (i == j && j == k) {
					ans+= gcd(gcd(i, j), k);
				}
				else if (i != j && j != k && k != i) {
					ans += 6 * gcd(gcd(i, j), k);
				}
				else {
					ans += 3 * gcd(gcd(i, j), k);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n;
    int a[81];
    scanf("%d", &n);
    
    for(int i=1;i<=n;i++){
    scanf("%d", &a[i]);}
    
    long long int money =1000;
    long long int kabusuu=0;
    long long int maxmoney=1000;
    for(int i=1;i<n;i++){
        if(kabusuu==0){
            if(a[i]<a[i+1]){
            kabusuu=money/a[i];
            money=money%a[i];
            }    
        
        }else{
            if(a[i]>a[i+1]){
            money+=kabusuu*a[i];
            kabusuu=0;
            if(maxmoney<money){
                maxmoney=money;
            }
            }  
        }
       // printf("day %d money %lld kabu %lld\n",i,money,kabusuu);
    }
    
    money+=a[n]*kabusuu;
    if(maxmoney<money){
        maxmoney=money;
    }
    printf("%lld",maxmoney);
}


Measured memory_bytes: 1700
from bisect import bisect_left
import sys
def main():
    input = sys.stdin.readline
    A, B, Q = map(int, input().split())
    S = [int(input()) for _ in range(A)]
    T = [int(input()) for _ in range(B)]
    X = [int(input()) for _ in range(Q)]
    INF = 10 ** 11
    S = [-INF] + S + [INF]
    T = [-INF] + T + [INF]
    for x in X:
        i = bisect_left(S, x)
        ls = x - S[i - 1]
        rs = S[i] - x
        j = bisect_left(T, x)
        lt = x - T[j - 1]
        rt = T[j] - x
        print(min(max(ls, lt), max(rs, rt), 2 * ls + rt, ls + 2 * rt, 2 * rs + lt, rs + 2 * lt))

if __name__ == '__main__':
    main()


Measured memory_bytes: 118108
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int data[1001][1001], co[1001][2];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N - 1; j++){
      cin >> data[i][j];
      data[i][j]--;
    }
  }
  int day = 1, count = 0, flag = 1, vs;
  while(1){
    count = 0;
    for(int i = 0; i < N; i++){
      if(co[i][0] == N - 1)continue;
      if(co[i][1] == day)continue;
      vs = data[i][(co[i][0])];
      if(data[vs][(co[vs][0])] == i){
        if(co[i][1] == day || co[vs][1] == day)continue;
        if(co[i][0] == N - 1 || co[vs][0] == N - 1)continue;
        count++;
        co[i][0]++;
        co[i][1] = day;
        co[vs][0]++;
        co[vs][1] = day;
      }
    }
    if(count == 0){
      day--;
      break;
    }
    day++;
  }
  for(int i = 0; i < N; i++){
    if(co[i][0] != N - 1){
      flag = 0;
      break;
    }
  }
  if(flag == 1)cout << day << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 4224
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val ans = IntArray(4)
    for (i in 0 until N) {
      when(ns()) {
        "AC" -> ans[0]++
        "WA" -> ans[1]++
        "TLE" -> ans[2]++
        else -> ans[3]++
      }
    }
    out.println("AC x ${ans[0]}")
    out.println("WA x ${ans[1]}")
    out.println("TLE x ${ans[2]}")
    out.println("RE x ${ans[3]}")
  }













































  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


Measured memory_bytes: 47844
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if((a>=0&&b<=0)||(a<=0&&b>=0))
	{
		cout<<"Zero";return 0;
	}
	if(a>0&&b>0)
	{
		cout<<"Positive";return 0;
	}
	if(a<0&&b<0)
	{
		if((abs(abs(a)-abs(b))+1)%2==0)
		{
			cout<<"Positive";return 0;
		}
		else
		{
			cout<<"Negative";return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
struct Edge {
	int to;
	int id;
};
vector<vector<Edge>> g;
vector<int> ans;
void dfs(int p, int c = -1, int q = -1) {
	int k = 1;
	for (int i = 0; i < g[p].size(); ++i) {
		int np = g[p][i].to; int nid = g[p][i].id;
		if (c == k) k++;
		if (np == q) continue;
		ans[nid] = k++;
		dfs(np, ans[nid], p);
	}
	return;
}

void solve() {
	int n; cin >> n;
	g.resize(n);
	ans = vector<int>(n - 1);
	for (int i = 0; i < n - 1; ++i) {
		int a, b; cin >> a >> b;
		a--; b--;
		g[a].push_back({b, i});
		g[b].push_back({a, i});
	}
	dfs(0);
	int  color = 0;
	for (int i = 0; i < ans.size(); ++i) {
		color = max(color, ans[i]);
	}
	cout << color << endl;
	for (int i = 0; i < ans.size(); ++i) {
		cout << ans[i] << endl;
	}
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 8320
#include<stdio.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
int main(){
	int n,x = 0,max = 0;
	char s[100];
	scanf("%d",&n);
	scanf("%s",s);
	FOR(i,0,n){
		if(s[i] == 'I') x++;
		if(s[i] == 'D') x--;
		if(max < x) max = x;
	}
	printf("%d\n",max);
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e11;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	set<string>s;
	rep(i, N) {
		string S;
		cin >> S;
		s.insert(S);
	}
	cout << s.size();
}

Measured memory_bytes: 19260