akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
a = list(map(int, input().split()))

cnt1 = 0
for i in range(n - 1):
    for  j in range(i + 1, n):
        if a[i] > a[j]:
            cnt1 += 1

a.sort()
cnt2 = 0
c = 0
i = 0
c_n = a[0]
while True:
    cnt = 0
    while a[i + cnt] == c_n:
        cnt +=1
        if i + cnt == n:
            break
    cnt2 += cnt*c
    c += cnt
    i += cnt
    if i == n:
        break
    c_n = a[i]

ans = cnt1*k + cnt2*k*(k - 1)//2
print(ans%(10**9 + 7))

Measured memory_bytes: 9156
import java.io.IOException;
import java.util.Scanner;

/**
 * Created on 2017/09/30 21:10.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);

        while (sc.hasNextInt()) {
            int minA = -1;
            int minB = Integer.MAX_VALUE;

            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                int b = sc.nextInt();
                if (minB > b) {
                    minA = a;
                    minB = b;
                }
            }
            System.out.println(minA + minB);
        }
    }
}

Measured memory_bytes: 63948
import bisect,collections,copy,heapq,itertools,math,string
import sys
# sys.setrecursionlimit(1000000)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
# A = [LI() for _ in range(N)]

l = len(str(N))

if l <= 3:
    a = 1000 - N
elif N % 1000 == 0:
    a = 0
else:
    a = 1000 - (N % 1000) 

print(a)

Measured memory_bytes: 68404
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    for(int i = 0;i * 4 <= n;i++)
    {
        for(int j = 0;j * 7 <= n;j++)
        {
            if(i * 4 + j * 7 == n)
            {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d%d%d%d%d", $sh, $sm, $eh, $em, $k);
  $start = $sh*60 + $sm;
  $end = $eh*60 + $em;
  
  $end -= $start;
  $end -= $k;
  
  echo $end;

Measured memory_bytes: 16176
#include<stdio.h>

int main(){

int a,b,c,x,Ans;

scanf("%d %d %d",&a,&b,&c);
Ans=0;
for(x=a;x<=b;x++){

if(c%x==0){
Ans++;
}
}
printf("%d\n",Ans);

return 0;

}




Measured memory_bytes: 2752
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    ll N, K;
    vector<pair<ll, ll>> td;

    void input() {

    }


    void solve() {
        input();
        cin >> N >> K;

        vector<ll> t(N), d(N);
        rep(i, 0, N) {
            cin >> t[i] >> d[i];
        }
        for (int i = 0; i < N; ++i) {
            td.emplace_back(t[i], d[i]);
        }
        sort(all(td), [](pair<ll, ll> a, pair<ll, ll> b) {
            return a.second > b.second;
        });


        vector<vector<ll>> table(N);
        for (int i = 0; i < td.size(); ++i) {
            table[td[i].first - 1].push_back(td[i].second);
        }

        //K個選ぶ
        ll ans = 0ll;
        ll kouho = 0ll;
        set<ll> used;
        vector<vector<ll> > usedtable(N);
        vector<ll> tapu;
        for (int i = 0; i < K; ++i) {
            used.insert(td[i].first - 1);
            usedtable[td[i].first - 1].push_back(td[i].second);
            kouho += td[i].second;
        }
        for (int i = 0; i < N; ++i) {
            sort(all(usedtable[i]));
            for (int j = 0; j + 1 < usedtable[i].size(); ++j) {
                tapu.push_back(usedtable[i][j]);
            }
        }
        kouho += used.size() * used.size();
        ans = kouho;
        sort(all(tapu));


        vector<ll> tapi;
        for (int i = 0; i < N; ++i) {
            if (used.count(i) == 0 && table[i].size() > 0) {
                sort(all(table[i]));
                tapi.push_back(table[i].back());
            }
        }
        sort(tapi.rbegin(), tapi.rend());

        ll shu = used.size();
        for (int i = 0; i < tapu.size() && i < tapi.size(); ++i) {
            kouho -= shu * shu;
            shu++;
            kouho += shu * shu;
            kouho += tapi[i];
            kouho -= tapu[i];
            chmax(ans, kouho);
        }
        cout << ans << endl;


    }
};


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

    Solve().solve();


    return 0;
}


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

mod = 10 ** 9 + 7
s = 0
for i in range(N):
    s += A[i]
    s %= mod

ans = 0
for i in range(N - 1):
    s -= A[i]
    ans += s * A[i]
    ans %= mod

print(ans)


Measured memory_bytes: 94220
import numpy as np
def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int #整数
float #小数

#for
for name in fruits: #fruitの頭から操作
    print(name)

#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト(文字列も可）内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True)  #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる
sum([2,3,   ,3]) #リストの合計

abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値
text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)

exit(0) #強制終了

cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す
"""
N,M=map(int,input().split())
day=sum(list(map(int,input().split())))
if day<=N:
    print(N-day)
else:
    print(-1)


Measured memory_bytes: 27940
N, P = map(int, input().split())
from collections import Counter

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    fct_c = Counter(fct)
    return fct_c

def solve():
    ans = 1
    c = factorize(P)
    for k, v in c.items():
        ans *= k**(v//N)
    return ans
print(solve())

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

int sum[3001][3001] ; 
int dp[3001][3001] ;
#define inf (1LL<<60)

void sum1(int arr[], int n)
{
	for(int i=0 ; i< n ; i++)
	{
		for(int j=i ; j< n ;j++)
		{
			sum[i][j]= arr[j]+((j==i)?0 :sum[i][j-1]) ; 
		}
	}
	
}



int fn(int arr[] ,int i ,int j,   int n )
{
	if(i==j)
	{
		return 0 ; 
	}

	if(dp[i][j] !=-1)
	{
		return dp[i][j] ; 
	}


	int ans= inf; 
	for(int k=i ; k< j ; k++)
	{
		int z= sum[i][j]+fn(arr, i, k, n)+fn(arr, k+1, j,n) ; 
		ans=min(ans, z) ; 
	}

	return dp[i][j]=  ans ; 


}



int32_t main()
{
	int n ; 
	cin>>n ; 
	int arr[n+1] ; 
	for(int i=0 ; i<n ; i++)
	{
		cin>>arr[i] ; 
	}

	sum1(arr, n) ; 

	// for(int i=0 ; i<n ; i++)
	// {
	// 	cout<<prefix[i]<<" "; 
	// }


	memset(dp, -1, sizeof(dp)) ; 

	cout<<fn(arr,0, n-1,n) ; 
}

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

#define MAX_N 101000
#define SWAP( a, b ) do { int tmp; tmp = a; a = b; b = tmp; } while( 0 )

int isPrime[ MAX_N + 1 ] = { 0, 0, 1 };

void quickSort( int *, int, int );
int median( int, int, int );
void insertionSort( int *, int );

int main( void ) {
	int i, j, N, P, cnt, p[ 22 ], sum[ 253 ];

	for ( i = 3; i <= MAX_N; i += 2 )
		isPrime[ i ] = 1;

	for ( i = 3; i * i <= MAX_N; i += 2 )
		if ( isPrime[ i ] )
			for ( j = i * 2; j <= MAX_N; j += i )
				isPrime[ j ] = 0;

	for ( ; scanf( "%d %d", &N, &P ), N != -1; printf( "%d\n", sum[ P - 1 ] ) ) {
		cnt = 0;
		for ( i = N + 1; cnt < 22; i++ )
			if ( isPrime[ i ] )
				p[ cnt++ ] = i;

		cnt = 0;
		for ( i = 0; i < 22; i++ )
			for ( j = i; j < 22; j++ )
				sum[ cnt++ ] = p[ i ] + p[ j ];

		quickSort( sum, 0, 199 );
	}

	return 0;
}

void quickSort( int *data, int l, int r ) {
	if ( l < r ) {
		int i = l, j = r, pivot = median( data[ i ], data[ ( i + j ) / 2 ], data[ j ] );

		while ( 1 ) {
			for ( ; data[ i ] < pivot; i++ ) ;
			for ( ; pivot < data [ j ]; j-- ) ;
			if ( i >= j )
				break;

			SWAP( data[ i ], data[ j ] );

			i++;
			j--;
		}

		if ( i - l < 20 )
			insertionSort( data + l, i - l );
		else
			quickSort( data, l, i - 1 );

		if ( r - j < 20 )
			insertionSort( data + j + 1, r - j );
		else
			quickSort( data, j + 1, r );
	}
}

int median( int x, int y, int z ) {
	if ( x < y )
		if ( y < z )
			return y;
		else if ( z < x )
			return x;
		else
			return z;
	else if ( z < y )
		return y;
	else if ( x < z )
		return x;
	else
		return z;
}

void insertionSort( int *data, int n ) {
	int i, j, tmp;

	for ( i = 1; i < n; i++ ) {
		tmp = data[ i ];

		for ( j = i; j && data[ j - 1 ] > tmp; j-- )
			data[ j ] = data[ j - 1 ];

		data[ j ] = tmp;
	}
}

Measured memory_bytes: 988
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	int a2 = 1, b2 = 1, i = 1;
	while (!(b2 - a2 == b - a))
	{
		i++;
		a2 = b2;
		b2 += i;
	}
	cout << a2 - a;
}

Measured memory_bytes: 256
#include <cstdio>
int N, MEMO[100][100], V[100][100];
struct info {
    int r;
    int c;
};
struct info MAT[100];
int DP(int i, int j);
void input(void);
int main(void){
    //freopen("in.txt", "r", stdin);
    input();
    printf("%d\n", DP(0, N - 1));
    return 0;
}
int DP(int i, int j){
    if (V[i][j] == 1) return MEMO[i][j];
    V[i][j] = 1;
    if (i >= j) return 0;
    int min = 987654321;
    for(int k = i; k < j; k++){
        int cnd = DP(i, k) + DP(k + 1, j) + MAT[i].r * MAT[k].c * MAT[j].c;
        if (cnd < min) min = cnd;
    }
    MEMO[i][j] = min;
    return min;
}
void input(void){
    scanf("%d", &N);
    for(int i = 0; i < N; i++) scanf("%d%d", &MAT[i].r, &MAT[i].c);
}

Measured memory_bytes: 1104
let () =
  let f pair n = match pair with
    | ([], lst2) -> ([n], lst2)
    | (lst1, []) -> if List.hd lst1 < n then (n :: lst1, []) else (lst1, [n])
    | (lst1, lst2) ->
      let b = List.hd lst1 > List.hd lst2 in 
      if b && List.hd lst1 < n then (n :: lst1, lst2)
      else if List.hd lst2 < n then (lst1, n :: lst2)
      else if List.hd lst1 < n then (n :: lst1, lst2)
      else raise Not_found in
  Scanf.scanf "%d\n" @@ fun x ->
  for i = 0 to x - 1 do
    let arr = Array.init 10 @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
    Printf.printf "%s\n"
    (try        
       let _,_ = List.fold_left f ([], []) (Array.to_list arr) in "YES"
     with Not_found -> "NO")
  done


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
#define ll long long 
#define INF 1e+9
const int maxn = 100000 + 5;

int n;
int dp[maxn];
vector<int> mem;

int solve()
{
    fill(dp, dp+n, INF);
    rep(i,n){
        *lower_bound(dp, dp+n, mem[i]) = mem[i];
    }
    return lower_bound(dp, dp+n, INF) - dp;
}

int main()
{
    cin >> n;
    mem.resize(n);
    rep(i,n) cin >> mem[i];   
    cout << solve() << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <queue>
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(a==b and b==c and a==c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

int main() {

	int a, b;
	string s;
	
	do {
		cin >> a >> b;

	} while (a < 1 || a > 13 || b < 1 || b > 13);
	
	

	if (a > b && a != 1) {
		s = "Alice";
		if (b == 1) {
			s = "Bob";
		}
		
	}
	else if (a < b) {
		s = "Bob";
		if (a == 1) {
			s = "Alice";
		}
		
	}
	else {
		s = "Draw";
		
	}

	cout << s << endl;
}

Measured memory_bytes: 3624
n,m = map(int,input().split())
s = input()
ans = []
now = n
while now>0:
    for i in range(m):
        if now-m+i>=0 and s[now-m+i]=='0':
            now = now-m+i
            ans.append(m-i)
            break
    else:
        print('-1')
        exit()
for i in ans[::-1]:
    print(i,end=' ')


Measured memory_bytes: 5616
package main

import (
	f "fmt"
)

func main() {

	var a, b, c int
	var sum int
	f.Scan(&a, &b, &c, &sum)

	cnt := 0 //何通りのパターンがあったか

	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			for k := 0; k <= c; k++ {
				if i*500+j*100+k*50 == sum {
					cnt++
				}
			}
		}
	}

	f.Println(cnt)

}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
	public class Dish
	{
		public int Time { get; set; }
		public int Amari { get; set; }
	}


	static void Main(string[] args)
	{

		var array = new List<Dish>();
		for (int i = 0; i < 5; i++)
		{
			var time = int.Parse(Console.ReadLine());
			var amari = 0;
			if(time % 10 != 0)
			{
				amari = 10 - time % 10;
			}
			array.Add(new Dish() { Time = time, Amari = amari });
		}

		array = array.OrderBy(x => x.Amari).ToList();


		var answer = 0;
		var count = 0;
		foreach (var dish in array)
		{
			count++;
			answer += dish.Time;
			if (dish.Amari != 0 && count < 5)
			{
				answer += dish.Amari;
			}
		}
		
		Console.WriteLine(answer);
	}
}


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

int main(){
  int n, x[100],ans=10000000;
  cin >>n;
  for (int i=0;i<n;i++){
    cin >>x[i];
}
for (int p=0;p<101;p++){
int v=0;
for (int i=0;i<n;i++){
v+=(x[i]-p)*(x[i]-p);
}
ans = min(ans,v);
}
cout <<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int K;
    cin >> K;
    int limit = K;
    int val = 0;
    int v = 1;
    rep(i, limit){
        if(i > 0){
            v *= 10;
            v = v % K;
        }

        val = (7 * v + val) % K;
        if(val == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3604
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val line = sc.nextLine()
    val length = line.length
    val rest = 15 - length
    if (line.count(_ == 'o') + rest >= 8) {
      println("YES")
    } else println("NO")
  }

}


Measured memory_bytes: 25808
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;
using pll = pair<ll, ll>;
using T = tuple<ll, int, int>;

int n, m;
ll s;

const int max_a = 50;
const int max_n = 50;
const ll max_s = 50 * 50 + 5;

struct Edge{
  int to, fare;
  ll time;
  Edge(int to, int f, ll t) : to(to), fare(f), time(t){}
};

vector<vector<Edge>> g;

vector<ll> c;
vector<ll> d;

vector<vector<ll>> dist;
void dijkstra(int start){
  dist.assign(n, vector<ll>(max_s + 5, LINF));
  dist[start][s] = 0;
  priority_queue<T, vector<T>, greater<T>> que;
  que.push(T(dist[start][s], start, s));

  while(!que.empty()){
    auto v = que.top();
    que.pop();
    int from, cur_s;
    ll dis;
    tie(dis, from, cur_s) = v;
    if(dis > dist[from][cur_s])continue;

    int ns = min(cur_s + c[from], max_s);
    if(dist[from][cur_s] + d[from] < dist[from][ns]){
      dist[from][ns] = dist[from][cur_s] + d[from];
      que.push(T(dist[from][ns], from, ns));
    }

    for(auto nv : g[from]){
      int to = nv.to;
      ll time = nv.time;
      int fare = nv.fare;
      int ns = cur_s - fare;
      if(ns < 0)continue;
      if(dist[from][cur_s] + time < dist[to][ns]){
	      dist[to][ns] = dist[from][cur_s] + time;
	      que.push(T(dist[to][ns], to, ns));
      }
    }
  }
}

int main(){
  cin >> n >> m >> s;
  g.resize(n);
  for(int i = 0; i < m; ++i){
    int u, v, a;
    ll b;
    cin >> u >> v >> a >> b;
    --u;
    --v;
    g[u].emplace_back(v, a, b);
    g[v].emplace_back(u, a, b);
  }
  c.resize(n);
  d.resize(n);  
  for(int i = 0; i < n; ++i){
    cin >> c[i] >> d[i];
  }

  s = min(s, max_s);
  dijkstra(0);

  for(int i = 1; i < n; ++i){
    ll ans = LINF;
    for(int j = 0; j < max_s + 5; ++j){
      ans = min(ans, dist[i][j]);
    }
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 6280
s = input()

if s[0] == "A" and s[2:-1].count("C") == 1:
  idx_C = s[2:-1].index("C") + 2
  s = s[1:idx_C] + s[idx_C+1:]
  if s.lower() == s:
    print("AC")
    exit()
print("WA")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main() 
{
	int n,m;
	cin>>n>>m;
	int sum=0;
	for(int i=1;i<=m;i++)
	{
		int x;
		cin>>x;
		sum+=x;	
	}
	if(n>=sum)
	cout<<n-sum<<endl;
	else
	cout<<"-1"<<endl;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
const int oo = 1e8+7;

vector<ll> groups, dp;

//global vars for rec
vector<int> not_taken;
ll score;

//2^N Subset of addings on top of base mask
void rec(int i, int mask, int group) {
    
    if(i == (int)not_taken.size()) {
        dp[mask] = max(dp[mask], score + groups[group]);
    } else {
        rec(i+1, mask, group); // we skip not_taken[i] and don't add it
        rec(i+1, mask ^ (1 << not_taken[i]), group ^ (1 << not_taken[i])); // we add not_taken[i] to the group
    }
}

int main() {
    
    int n;
    scanf("%d",&n);
    
    vector<vector<ll>> in(n, vector<ll>(n));
    
    groups.assign(1 << n, 0);
    dp.assign(1 << n, -oo);
    
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            scanf("%lld", &in[i][j]);
        }
    }
    
    // preprocesar el score de cualquier posible grupo
    
    for(int mask = 0; mask < (1 << n); ++mask) {
        for(int i = 0; i < n; ++i) if(mask & (1 << i)) {
            for(int j = i+1; j < n; ++j) if(mask & (1 << j)) {
                groups[mask] += in[i][j];
            }
        }
    }
    
    // bottom up dp
    
    dp[0] = 0;
    
    for(int mask = 0; mask < (1 << n); ++mask) {
        not_taken.clear();
        for(int i = 0; i < n; ++i) if(!(mask & (1 << i))) {
            not_taken.push_back(i);
        }
        score = dp[mask];
        rec(0, mask, 0);
    }
    
    printf("%lld\n", dp[(1 << n)-1]);
}



Measured memory_bytes: 1280
#include<iostream>

using namespace std;

int main()
{
	int n, k;
	bool flg;
	
	while(cin >> n >> k, (n!=0 || k!=0))
	{
		flg = true;
		int* map = new int[k];
		for(int i=0; i < k; i++) cin >> map[i];
		for(int i=0; i < n; i++) {
			for(int j=0; j < k; j++) {
				int b; cin >> b;
				map[j] -= b;
				if(map[j] < 0) flg = false;
			}
		}
		if( flg ) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 916
import itertools
N, K = map(int,input().split())
A = list(map(int,input().split()))
K = min(41,K)
#A = [0] * N

for k in range(K):
    imos = [0] * (N+1)
    for n in range(N):
        a = n - A[n]
        b = n + A[n]
        a = max(0,a)
        b = min(N-1,b)
        imos[a] += 1
        imos[b+1] -= 1
    csum = list(itertools.accumulate(imos))
    A = csum[:-1]
A = [str(a) for a in A]
print (' '.join(A))


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

int main() {
  long long n, m, sum;
  sum = 0;
  cin >> n >> m;
  vector<int> vec(m);
  for(int i=0; i < m; i++){
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  if(sum > n){
    sum = -1;
  }
  else{
    sum = n - sum;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3672
class UnionFind:
  def __init__(self,n):
    self.n=n
    self.parent=[i for i in range(n)] # 親
    self.rank=[1]*n # 木の高さ
    self.size=[1]*n # size[i]はiを根とするグループのサイズ
    
  def find(self,x): # xの根を返す
    if self.parent[x]==x:
      return x
    else:
      self.parent[x]=self.find(self.parent[x]) # 経路圧縮
      return self.parent[x]
  
  def unite(self,x,y): # x,yの属する集合を併合する
    x=self.find(x)
    y=self.find(y)
    if x != y:
      if self.rank[x]<self.rank[y]:
        self.parent[x]=y
        self.size[y]+=self.size[x]
      else:
        self.parent[y]=x
        self.size[x]+=self.size[y]
        if self.rank[x]==self.rank[y]:
          self.rank[x]+=1

  def group_size(self,x): # xが属する集合の大きさを返す
    return self.size[self.find(x)]

N, M =map(int,input().split())
A, B = [0]*M, [0]*M

direct = [[] for _ in range(N)]
uf = UnionFind(N)

for i in range(M):
    A[i], B[i] = map(int,input().split())
    A[i] -= 1
    B[i] -= 1
    uf.unite(A[i], B[i])

ans = 0
for i in range(N):
    ans = max(ans, uf.group_size(i))
print(ans)

Measured memory_bytes: 43628
using System;
using System.Linq;
using System.Collections.Generic;

public class Test
{
	public static void Main( )
	{
		var stack = new Stack<int>();
		var line = Console.ReadLine().Trim().Split();
		
		int a,b;
		foreach( var s in line ) {
			if( s.Equals( "+" ) ) {
				b = stack.Pop();
				a = stack.Pop();
				stack.Push( (a+b) );
			} else if( s.Equals( "-" ) ) {
				b = stack.Pop();
				a = stack.Pop();
				stack.Push( (a-b) );
			} else if( s.Equals( "*" ) ) {
				b = stack.Pop();
				a = stack.Pop();
				stack.Push( (a*b) );
			} else if( s.Equals( "/" ) ) {
				b = stack.Pop();
				a = stack.Pop();
				stack.Push( (a/b) );
			} else {
				stack.Push( int.Parse(s) );
			}
		}
		
		Console.WriteLine( "{0}", stack.Pop() );

		return;
	}
}


Measured memory_bytes: 18416
#include <cstdio>

#include <vector>

using namespace std;

typedef long long ll;

const int N = 100010, P = 1000000007;

int n, k;
int dp[N];
bool vis[N], prt[N];
vector<int> g[N];

int norm(int x) { return x >= P ? (x - P) : x; }

void dfs(int u) {
  vis[u] = true;
  dp[u] = 1;
  int cnt = prt[u];
  for (int v : g[u])
    if (!vis[v]) {
      prt[v] = true;
      dfs(v);
      ++cnt;
      dp[u] = dp[u] * (ll)dp[v] % P * (k - cnt) % P;
    }
}

int main() {
  scanf("%d%d", &n, &k);
  for (int rep = 1; rep < n; ++rep) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  int ans = dp[1] * (ll)k % P;
  printf("%d\n", ans);
  return 0;
}

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

int main(void)
{
    int N,ans = 0;
    bool flag = false;
    cin >> N;
    vector<int> a(N+1);
    vector<bool> d(N+1);

    for(int i = 1;i <= N;i++){
        cin >> a[i];
        d[i] = false;
    }

    for(int i = 1;d[i] == false;i = a[i]){
        d[i] = true;
        ans++;
        if(d[2] == true){
            flag = true;
            break;
        }
    }

    if(flag)
        cout << ans-1 << endl;

    else
        cout << -1 << endl;

    return 0;
}

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

int main() {
    int n; cin >> n;
    int all = 0; int mmax = 0;
    for (int i = 0; i < n; i++) {
        int p; cin >> p;
        all += p; mmax = max(mmax, p);
    }
    if (mmax * 2 < all) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; /* keyを発見 */
    if(key > A[mid]) left = mid + 1; /* 後半を探索 */
    else if(key < A[mid]) right = mid; /* 前半を探索 */
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,a;
    cin>>n;
    map<ll,ll> mp;
    for(ll i=0;i<n;i++){
        cin>>a;
        mp.insert(make_pair(a,i));
    }
    for(auto x:mp){
        cout<<x.second+1<<" ";
    }
    cout<<endl;
    return 0;
}

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

int main()
{
    int x; cin >> x;
    ll i = x;
    while(1)
    {
    	ll cnt = 0;
    	for(int j = 1; j <= sqrt(x); j++) if(!(i % j)) cnt += 2;
    	if(cnt == 2)
    	{
    		cout << i;
    		break;
    	}
    	i++;
    }
 
    return 0;
}

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

using namespace std;

int main(){
	int R, C, N;
	while(cin >> R >> C >> N){
		vector<pair<int,int>> vp;
		for(int i=0;i<N;i++){
			int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
			if((x1%R == 0 || y1%C == 0) && (x2%R == 0 || y2%C == 0)){
				auto makeIdx = [&](int x, int y){
					if(y == 0) return x;
					if(x == R) return R + y;
					if(y == C) return 2 * R + C - x;
					return 2 * (R + C) - y;
				};
				vp.emplace_back(makeIdx(x1, y1), i);
				vp.emplace_back(makeIdx(x2, y2), i);
			}
		}
		sort(vp.begin(), vp.end());
		vector<int> cnt(N, 0);
		stack<int> st;
		bool ok = true;
		for(const auto& p : vp){
			if(cnt[p.second]){
				if(st.top() != p.second){
					ok = false;
					break;
				}
				st.pop();
			} else {
				st.push(p.second);
				cnt[p.second] = 1;
			}
		}
		cout << (ok ? "YES" : "NO") << endl;
	}
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long x, k, d;
  cin >> x >> k >> d;
  long long res;
  if (x < 0) {
    // x + d * k >= 0
    long long nk = -x / d;
    if (x + d * nk < 0)
      ++nk;
    if (nk > k)
      res = x + d * k;
    else {
      long long rem = nk - k;
      if (rem % 2 == 0)
        res = x + d * nk;
      else
        res = x + d * (nk - 1);
    }
  } else {
    // x - d * k <= 0
    long long nk = x / d;
    if (x - d * nk > 0)
      ++nk;
    if (nk > k)
      res = x - d * k;
    else {
      long long rem = nk - k;
      if (rem % 2 == 0)
        res = x - d * nk;
      else
        res = x - d * (nk - 1);
    }
  }
  cout << abs(res) << '\n';
  return 0;
}

Measured memory_bytes: 3656
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

vector<ll> get_divisor(ll x){
    vector<ll> ans;
    for(ll i = 1; i * i <= x; i++){
        if(x % i == 0){
            ans.push_back(i);
            if(i * i != x)
                ans.push_back(x/i);
        }
    }

    return ans;
}

ll power(int n, int p)
{
    if (p == 0)
        return 1;
    long long res = 1;
    long long add = n;
    while (p > 0)
    {
        if (p & 1)
            res = (res * add);
        p >>= 1;
        add = add*add;
    }
    return res;
}

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

    ll ans = 0;
    auto d1 = get_divisor(n-1);
    ans += d1.size() - 1;
    auto d2 = get_divisor(n);
    for(auto d: d2){
        ll tmp = n / d;
        if(tmp % d == 1)
            ans++;
    }

    IFOR(i, 2, 40){
        for(ll j = 1;j<=1000000;j++){
            ll p = power(j, i);
            if(p > n) break;
            if(n % p > 0) continue;
            if((n/p)%j == 1)
                ans++;
        }
    }

    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,d;
    cin >> n >> d;
    int X[n][d];
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < d; ++j)
        {
            cin >> X[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = i+1; j < n; ++j)
        {
            int norm = 0;
            for (int k = 0; k < d; ++k)
            {
                int diff = abs(X[i][k] - X[j][k]);
                norm += diff * diff;
            }
            bool flag = false;
            for (int k = 0; k <= norm; ++k)
            {
                if (k * k == norm)
                {
                    flag = true;
                }
            }
            if (flag)
                ++ans;
        }
    }
    cout << ans << endl;
}

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

int main() {
    string s; cin >> s;
    set<char> st;
    for (int i = 0; i < s.size(); i++) {
        if (i == 0 && (s.at(i) != 'A')) {
                puts("WA");
                return 0;
        }
        else if (2 <= i && i <= s.size() -2) {
            if (s.at(i) == 'C') {
                if (st.count('C') == 1) {
                    puts("WA");
                    return 0;
                }
                st.insert(s.at(i));
                continue;
            }
            else if (!('a' <= s.at(i) && s.at(i) <= 'z')) {       
                puts("WA");
                return 0;
            }
        }
        else if (!('a' <= s.at(i) && s.at(i) <= 'z') && i != 0) {
            puts("WA");
            return 0;
        }
    }

    if (st.count('C') == 1)
        puts("AC");
    else
        puts("WA");
     
    return 0;
}

Measured memory_bytes: 256
n = int(input())
count = {}
res = 0
for i in range(n):
  si = input()
  sortedSi = sorted(si)
  tSi = tuple(sortedSi)
  if tSi not in count:
    count[tSi] = 0
  res += count[tSi]
  count[tSi] += 1
print(res)

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

//拡張ユークリッドの互除法
int extgcd(int a, int b, int& x, int& y) {
    int d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

// mod逆元
int mod_inverse(int a, int m) {
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

string S;
signed main() {
    int mod=1e9+7;
    cin>>S;
    int ans=0;
    int A=0,h=0,AB=0,hB=0,Ah=0,hh=0;
    int k1=1;
    for(int i=0;i<S.length();i++){
        if(S[i]=='?')(k1*=3)%=mod;
    }
    int k2=k1*mod_inverse(3,mod)%mod;
    int k3=k2*mod_inverse(3,mod)%mod;
    int k4=k3*mod_inverse(3,mod)%mod;
    for(int i=0;i<S.length();i++){
        if(S[i]=='A'){
            A++;
        }else if(S[i]=='B'){
            AB+=A;
            hB+=h;
        }else if(S[i]=='C'){
            (ans+=AB*k1%mod)%=mod;
            (ans+=Ah*k2%mod)%=mod;
            (ans+=hB*k2%mod)%=mod;
            (ans+=hh*k3%mod)%=mod;
        }else{
            (ans+=AB*k2%mod)%=mod;
            (ans+=Ah*k3%mod)%=mod;
            (ans+=hB*k3%mod)%=mod;
            (ans+=hh*k4%mod)%=mod;
            Ah+=A;
            hh+=h;
            h++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
    int n,i,j;
    scanf("%d",&n);
    for(i = 1 ; i <= 9 ; i++)
    {
        for(j = i ; j <= 9 ; j++)
        {
            if(i * j == n)
            {
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 1644
import math


def main():
    # n = int(input())
    # n, k = map(int, input().split())
    # h = list(map(int, input().split()))
    s = input()
    # h = [int(input()) for _ in rane(n)]
    f = int(s[:2])
    b = int(s[2:])
    if 1 <= f and f <= 12 and 1 <= b and b <= 12:
        print("AMBIGUOUS")
    elif 0 <= f and f <= 99 and 1 <= b and b <= 12:
        print("YYMM")
    elif 0 <= b and b <= 99 and 1 <= f and f <= 12:
        print("MMYY")
    else:
        print("NA")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61500
#include<bits/stdc++.h>
using namespace std;
long long a[200005],mp[2100],ans;
int main(){
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	long long y=1;
	for(int i=0;i<s.size();i++){
		a[i]=(y*(s[i]-'0'))%2019;
		y=(y*10)%2019;
	}
	y=0;
	for(int i=0;i<s.size();i++){
		y=(y+a[i])%2019;
		mp[y]++;
	}
	for(int i=0;i<2019;i++)
		ans+=mp[i]*(mp[i]-1)/2;
	ans+=mp[0];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5280
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n k

100
 */
int n,k;

int main(){
  cin>>n>>k;
  if(2*k-1<=n)
    cout<<"YES\n";
  else
    cout<<"NO\n";

  return 0;
}


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

using namespace std;
using ll=long long;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,a,b) for(int i=a;i<b;i++)

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

    vector<long double> a(n);
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        a[i]=(x+1);
        a[i]/=2;
//        cout<<a[i]<<" ";
    }
//    cout<<endl;
    long double final=0;
    for(int i=0;i<k;i++){
        final+=a[i];
    }
    long double tmp=final;
    for(int i=k;i<n;i++){

        tmp-=a[i-k];
        tmp+=a[i];
//        cout<<final<<" ";
        final=max(final,tmp);
    }
    cout<<setprecision(14);
    cout<<final<<endl;
}

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

using namespace std;

long long int gcd(long long int A, long long int B){
	if( A < B ){
		return gcd(B, A);
	}
	if( B == 0 ){
		return A;
	}
	return gcd(B, A%B);
}


class combination{
public:

	//Nの最大値がわかれば代入する
	combination(long long int combinationThreshold = 1e7){
		( *this ).combinationThreshold = combinationThreshold + 2;
	}

	//a^p % mod
	long long int powmod(long long int A, long long int P, long long int M = LLONG_MAX){
		long long int ans = 1;
		long long int mul = A;
		for( ; P > 0; P >>= 1, mul = ( mul*mul ) % M ){
			if( ( P & 1 ) == 1 ) ans = ( ans*mul ) % M;
		}
		return ans;
	}

	//nCk mod m
	long long int cb(long long int N, long long int K, long long int M = LLONG_MAX){
		if( N < combinationThreshold ){// 事前計算O(N)、答えるのはO(1)
			if( inv.size() == 0 ){
				inv = vector<long long int>(combinationThreshold);
				inv[1] = 1;
				for( long long int i = 2; i < combinationThreshold; i++ ){
					inv[i] = M - ( M / i )*inv[M%i] % M;
				}
				fact = vector<long long int>(combinationThreshold);
				fact[0] = 1;
				revFact = vector<long long int>
					(combinationThreshold);
				revFact[0] = 1;
				for( long long int i = 1; i < combinationThreshold; i++ ){
					fact[i] = ( fact[i - 1] * i ) % M;
					revFact[i] = ( revFact[i - 1] * inv[i] ) % M;
				}
			}
			return ( ( ( fact[N] * revFact[K] ) % M )*revFact[N - K] ) % M;
		} else{
			return cbOnce(N, K, M);
		}
	}

	//一回だけなら最速 O(K + log(M))
	long long int cbOnce(long long int N, long long int K, long long int M = LLONG_MAX){
		if( K > N / 2 ) return cbOnce(N, N - K, M);
		long long int ans = 1;
		long long int div = 1;
		for( long long int i = 0; i < K; i++ ){
			ans *= N - i;
			ans %= M;
			div *= i + 1;
			div %= M;
		}
		ans *= powmod(div, M - 2, M);
		return ans % M;
	}

private:
	vector<vector<long long int>>C;//3000以下の答え
	vector<long long int>fact;//階乗
	vector<long long int>revFact;//階乗の逆元
	vector<long long int>inv;//mod pでの逆元

	long long int combinationThreshold;//Nの最大値がわかれば入れる。
};



const long long int mod = 998244353LL;



int main(){
	long long int N, A, B, K;
	cin >> N >> A >> B >> K;

	//Kが0の場合は1通り
	if( K==0 ){
		cout << 1 << endl;
		return 0;
	}
	//AとBが同じで、KがAの倍数ではない場合は0通り
	if( ( A == B && K%A != 0 ) ){
		cout << 0 << endl;
		return 0;
	}

	// A>Bにしたい

	if( A < B ){
		swap(A, B);
	}


	long long int i = K / A;
	while( i >= 0 ){
		if( ( K - i * A ) % B == 0 ){
			break;
		}
		i--;
	}
	if( i == -1 ){
		cout << 0 << endl;
		return 0;
	}
	long long int j = ( K - i * A ) / B;
	long long int ans = 0;

	long long int gcdv = gcd(A, B);
	long long int av = A / gcdv;
	long long int bv = B / gcdv;

	combination cb(N);
	while( i >= 0 ){
		if( i <= N && j <= N ){
			ans += cb.cb(N, i, mod)*cb.cb(N, j, mod) % mod;
			ans %= mod;
		}
		i -= bv;
		j += av;
	}
	cout << ans << endl;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  auto cal = [](long long n) {
    return n * n * n;
  };
  long long n, K;
  cin >> n >> K;
  long long ans = cal(n / K);
  if (!(K & 1)) {
    ans += cal(n / K + (n % K >= K / 2));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    char s1, s2, s3;
    scanf("%c%c%c", &s1, &s2, &s3);

    short ans = 0;
    if(s1 == '1') ans++;
    if(s2 == '1') ans++;
    if(s3 == '1') ans++;

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
import java.text.DecimalFormat;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = sc.nextInt();
        final int A = sc.nextInt();
        final int B = sc.nextInt();
        String ans = "NG";
        
        for (int i = A; i <= B; i++) {
            if (i % N == 0) ans = "OK";
        }
        
        
        
        out.println(ans);

        out.flush();
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

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


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

int main() {
  string s;
  while(cin >> s && s!="0000") {
    int cnt=0;
    bool ck=true;
    while(s!="6174") {
      cnt++;
      int a[4];
      fill(a,a+4,0);
      for(int i=0; i<4; i++) a[i]=(int)s[i]-48;
      sort(a,a+4);
      int b=0,c=0,k1=1,k2=1000;
      for(int i=0; i<4; i++) {
	b+=a[i]*k1;
	c+=a[i]*k2;
	k1*=10;
	k2/=10;
      }
      stringstream ss;
      ss << b-c;
      ss >> s;
      if(s.size()<4) {
	while(s.size()<4) s="0"+s;
      }
      if(s=="0000") {
	cout << "NA" << endl;
	ck=false;
	break;
      }
    }
    if(ck) cout << cnt << endl;
  }
  return 0;
}


Measured memory_bytes: 1232
def triangle_check(a, b, c):
  if a>b+c:
    return False
  elif b>a+c:
    return False
  elif c>a+b:
    return False
  else:
    return True

def count_triangles(n, sticks):
  assert len(sticks) == n, "lenght of sticks does not match `n`"
  count = 0

  for i in range(len(sticks)-2):
    for j in range(i+1, len(sticks)-1):
      for k in range(j+1, len(sticks)):
        count += triangle_check(sticks[i], sticks[j] , sticks[k])

  return count

def findnumberofTriangles(arr): 
  
    # Sort array and initialize count as 0 
    n = len(arr) 
    arr.sort() 
    count = 0
  
    # Fix the first element. We need to run till n-3 as 
    # the other two elements are selected from arr[i+1...n-1] 
    for i in range(0, n-2): 
  
        # Initialize index of the rightmost third element 
        k = i + 2
  
        # Fix the second element 
        for j in range(i+1,n): 
  
            # Find the rightmost element which is smaller 
            # than the sum of two fixed elements 
            # The important thing to note here is, we use 
            # the previous value of k. If value of arr[i] + 
            # arr[j-1] was greater than arr[k], then arr[i] + 
            # arr[j] must be greater than k, because the array 
            # is sorted. 
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
  
            # Total number of possible triangles that can be 
            # formed with the two fixed elements is k - j - 1. 
            # The two fixed elements are arr[i] and arr[j]. All 
            # elements between arr[j+1] to arr[k-1] can form a 
            # triangle with arr[i] and arr[j]. One is subtracted 
            # from k because k is incremented one extra in above 
            # while loop. k will always be greater than j. If j 
            # becomes equal to k, then above loop will increment k, 
            # because arr[k] + arr[i] is always greater than arr[k] 
            count += k - j - 1
  
    return count 

if __name__ == "__main__":

  n = int(input())
  sticks = sorted(list(map(int, input().split(" "))))
  # num_triangles = count_triangles(n, sticks)
  num_triangles = findnumberofTriangles(sticks)
  print(num_triangles)

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

int main(void)
{
    string s;
    cin >> s;
    int x = 0;
    int ct = 0;
    for (int i = 0; i < s.length(); ++i)
    {
        if (s[i] == 'R')
        {
            ++ct;
            x = max(x, ct);
        }
        else
        {
            ct = 0;
        }
    }
    cout << x << endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
#define N 20
#define Q 200

int keisan(int *, int, int, int, int);

int main(){

  int i, j;
  int n, q;
  int a[N], m[Q];
  int out;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  scanf("%d", &q);

  for(i = 0; i < q; i++){
    scanf("%d", &m[i]);
  }

  for(i = 0; i < q; i++){

    out = keisan(&a[0], 0, m[i], 0, n);
      
    if(out == 1) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int keisan(int *a, int res, int m, int i, int n){

  if(m == 0 || res == 1) return 1;

  if(i == n) return 0;

  res = keisan(a, res, m - a[i], i + 1, n);

  res = keisan(a, res, m, i + 1, n);

  return res;
}

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

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

signed main(void) {
  int i,j;
  int n,a,b;
  cin>>n>>a>>b;
  vi h(n);
  rep(i,n)cin>>h[i];
  ll lb=0,ub=INF;
  a-=b;
  rep(j,1000){
    int mid=(lb+ub)/2;
    int sum=0;
    int tmp=mid*b;
    rep(i,n){
      int p=h[i]-tmp;
      if(p>0)sum+=(p-1)/a+1;
    }
    if(sum>mid)lb=mid+1;
    else ub=mid;
  }
  cout<<lb<<endl;
}

Measured memory_bytes: 1024