akhauriyash/Code-Regression huggingface dataset:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
from collections import defaultdict
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    S = input()[:-1]
    
    if S in ["AAA", "BBB"]:
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':
    main()

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

int main() {
  int k, s, i, j, ans = 0;
  cin >> k >> s;
  for (i = 0; i <= k; ++i) {
    for (j = 0; j <= k; ++j) {
      if (0 <= s - i - j && s - i - j <= k) {
        ++ans;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
package main
 
import (
  "fmt"
)
 
func main() {
 
  d := scanNums(2)
  
  plus := d[0] + d[1]
  minus := d[0] - d[1]
  product := d[0] * d[1]
 
  var result int
  if plus >= minus {
    result = plus
  } else {
    result = minus
  }
  
  if product >= result {
    result = product
  }
  
  fmt.Print(result)
}
 
func scanNums(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}

Measured memory_bytes: 512
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main() {

	string s;
	vector<string> ss;
	int n;

	cin >> s >> n;

	

	int m = min(n, (int)s.size());

	for (int i = 1; i <= m; i++) {
		for (int j = 0; j < s.size(); j++) {
			if (j + i - 1 <= s.size() - 1) {
				string sub = s.substr(j, i);
				ss.push_back(sub);
			}
		}
	}

	sort(all(ss)); unique(all(ss));

	cout << ss[n - 1] << endl;

	return 0;
}


Measured memory_bytes: 1660
#include <stdio.h>

// 入力制約
#define NUM_MIN ( ( int ) 1 )
#define NUM_MAX ( ( int ) 100 )
#define ELEMENT_MIN ( ( int ) 0 )
#define ELEMENT_MAX ( ( int ) 100 )

// 制約判定結果
typedef enum
{
	kSuccess,
	kError
}Result;

// プロトタイプ宣言
Result checkNumRange( int num, int min, int max );
int execBubbleSort( int num, int* pArray );
void showArray( int num, int* pArray );
void swap( int* pX, int* pY );

//****************************************************/
// @brief  メイン関数
// @param  無し
// @return 正常終了なら0、異常終了なら-1を返す
//****************************************************/
int main( void )
{
	int i;
	int num;
	int array[NUM_MAX];
	int count;

	// 要素数の入力判定
	scanf( "%d\n", &num );
	if( checkNumRange( num, NUM_MIN, NUM_MAX ) == kError )
	{
		return -1;
	}

	// 要素の入力判定
	for( i = 0; i < num; i++ )
	{
		scanf( "%d", &array[i] );
		if( checkNumRange( array[i], ELEMENT_MIN, ELEMENT_MAX ) == kError )
		{
			return -1;
		}
	}

	// バブルソート実行
	count = execBubbleSort( num, &array[0] );
	// ソート回数を出力
	showArray( num, &array[0] );
	printf( "%d\n", count );

	return 0;
}

//****************************************************/
// @brief  入力値の制約判定
// @param  num : 判定対象の入力値
//         min : 最小値
//         max : 最大値
// @return 制約内ならkSuccess、制約外ならkErrorを返す
//****************************************************/
Result checkNumRange( int num, int min, int max )
{
	return ( ( num >= min ) && ( num <= max ) ) ? kSuccess : kError;
}

//****************************************************/
// @brief  バブルソートを実行し、ソート回数を返す
// @param  num    : 要素数
// @param  pArray : 要素を格納した配列先頭へのポインタ
// @return ソート回数
//****************************************************/
int execBubbleSort( int num, int* pArray )
{
	int i;
	int index = 0;	// 未ソート部分列の先頭インデックス
	int flag = 1;	// ソートしたら1, ソートしなければ0にする
	int count = 0;	// ソート回数

	while( flag )
	{
		flag = 0;
		for( i = num - 1; i >= index + 1; i-- )
		{
			if( pArray[i] < pArray[i - 1] )
			{
				// 要素入れ替え、ソート回数をカウント
				swap( &pArray[i], &pArray[i - 1] );
				flag = 1;
				count++;
			}
		}
		index++;
	}

	return count;
}

//****************************************************/
// @brief  変数の値を交換する
// @param  pX : 値を交換する変数1
// @param  pY : 値を交換する変数2
// @return 無し
//****************************************************/
void swap( int* pX, int* pY )
{
	int temp;

	temp = *pX;
	*pX = *pY;
	*pY = temp;
}

//****************************************************/
// @brief  配列要素の値を出力する
//         末尾以外は要素間にスペースを空け、末尾に改行を入れて出力する
// @param  num : 表示する配列要素数
// @param  pArray : 配列要素先頭アドレスへのポインタ
// @return 無し
//****************************************************/
void showArray( int num, int* pArray )
{
	int i;

	for( i = 0; i < num; i++ )
	{
		if( i != num - 1 )
		{
			// 出力する要素の末尾以外はスペースを空ける
			printf( "%d ", pArray[i] );
		}
		else
		{
			// 出力する要素の末尾は改行を入れる
			printf( "%d\n", pArray[i] );
		}
	}
}



Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int main(){
  int n,i,j;
  cin >> n;
  while(n!=0) {
    long long sum[5001]={};
    int b;
    long long o=1<<20;
    o*=-1;
    cin >> sum[1];
    for(i=2;i<=n;i++){
      cin >> b;
      sum[i]=sum[i-1]+b;
      //cout << sum[i] << endl;
    }
    
    for(i=0;i<=n;i++){
      for(j=i+1;j<=n;j++){
	o=max(o,sum[j]-sum[i]);
      }
    }
    cout << o << endl;
    cin >> n;
  }
  return 0;
  
}

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

int main(){
  
  string s,t;
  cin>>s;
  
  int ans=1;
  t+=s[0];
  for(int i=1;i<s.size();i++){
    if(i!=s.size()-1){
      if(t.size()==1){
      	if(s[i]==t[0]){
       	 t+=s[i+1];
        	ans++;
        	i++;
     	 }
     	 else{
       	 t=s[i];
       	 ans++;
      	}
  	  }
  	  else{
   	   t=s[i];
    	  ans++;
   	 }
    }
    else{
      if(t.size()==2||(t.size()==1&&t[0]!=s[i])){
        ans++;
      }
    }
  }
cout<<ans<<endl;
  
}

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


int main() {int A;
cin >> A;
int B;
cin >> B;
int M;
cin >> M;
int a[A], b[B], x[M], y[M], c[M];
for(int i=0;i<A;i++){cin>>a[i+1];
;}
for(int i=0;i<B;i++){cin>>b[i+1];
;}
for(int i=0;i<M;i++){cin>>x[i+1]>>y[i+1]>>c[i+1]
;}
int MIN=200000; int MINA, MINB; MINA=100000;MINB=100000;
for(int i=1;i<M+1;i++){MIN=min(MIN,a[x[i]]+b[y[i]]-c[i]);
;}
for(int i=0;i<A;i++){
    MINA=min(MINA,a[i+1]);
}
for(int j=0;j<B;j++){
    MINB=min(MINB,b[j+1]);
  }
MIN=min(MIN,MINA+MINB);
cout<<MIN<<endl;
return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n, m, k;
    cin >> n >> m >> k;
    vi a(n),b(m);
    rep(i,n) cin >> a.at(i);
    rep(i,m) cin >> b.at(i);
    vi asum(n+1),bsum(m);
    ll tempasum = 0;
    ll tempbsum = 0;
    asum.at(0) = 0;
    for(ll i=0; i<n; i++){
        tempasum += a.at(i);
        asum.at(i+1) = tempasum;
    }
    rep(i,m){
        tempbsum += b.at(i);
        bsum.at(i) = tempbsum;
    }
    ll res = 0;
    rep(i,n+1){
        ll remain = k - asum.at(i);
        if(remain < 0) continue;
        auto itr = upper_bound(bsum.begin(), bsum.end(), remain);
        ll length = itr - bsum.begin();
        ll tres = i + length;
        res = max(res, tres);
    }
    cout << res << endl;
}

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn f(s: &[char]) -> bool {
    let m = s.len();
    for i in 0..m {
        if s[i] != s[m - 1 - i] {
            return false;
        }
    }
    true
}

use std::iter::Iterator;
use std::cmp;

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

    let t = cmp::max(a + b, a -b);
    let tt = cmp::max(t, a * b);

    println!("{}", tt);

}


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

#define ll     long long
#define fr     first
#define sec    second
#define rep(i,n)  for(i=0;i<n;i++)
#define vi     vector <int>
#define vc     vector <char>
#define vl     vector <ll>
#define vb     vector <bool>
#define pb     push_back
#define M      1000000007
#define ios    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open   freopen("input.txt","r",stdin);
#define close  freopen("output.txt","w",stdout);
#define M_PI   3.14159265358979323846
#define pp     pair<int,int>
#define nn 100003

int main()
{
    ios;
    char c;
    cin>>c;
    if(c>=65 && c<=90)
        cout<<"A";
    else
        cout<<"a";
    return 0;
}


Measured memory_bytes: 3652
while 0 != n = gets.to_i do
  a = Array.new(10,0)
  n.times do
    s = gets.split.map(&:to_i)
    d = 0
    n.times do |i|
      printf("%5d",s[i])
      d = d + s[i]
      a[i] = a[i] + s[i]
    end
    printf("%5d\n",d)
  end
  z = 0
  n.times do |i|
    z = z + a[i]
    printf("%5d",a[i])
  end
  printf("%5d\n",z)
end

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

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 3e5 + 10;

int n;
int A[N], sumw[N], sumb[N];

bool check(int x) {
	int cur = A[1];
	For(i, 1, n - 1) if (i % 2 == 0) {
		if (cur >= x) cur = max(cur - A[i], 0);
		else cur -= A[i];
		cur += A[i + 1];
	}
	return cur >= x;
}

int main() {

	scanf("%d", &n);
	For(i, 1, n) {
		scanf("%d", &A[i]);
		sumb[i] = sumb[i - 1] + (i & 1 ? A[i] : 0);
		sumw[i] = sumw[i - 1] + (!(i & 1) ? A[i] : 0);
	}

	if (n % 2 == 0) {
		printf("%d %d\n", max(sumb[n], sumw[n]), min(sumb[n], sumw[n]));
		return 0;
	}

	int L = 0, R = sumb[n];
	while (L < R) {
		int mid = (L + R + 1) >> 1;
		if (check(mid)) L = mid;
		else R = mid - 1;
	}
	printf("%d %d\n", sumw[n] + L, sumb[n] - L);

	return 0;
}

Measured memory_bytes: 3712
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            int q = sc.nextInt();
            if ((n | q) == 0) {
                break;
            }
            int[] counts = new int[150];
            for (int i = 0; i < n; i++) {
                int m = sc.nextInt();
                ArrayList<Integer> list = new ArrayList<>();
                for (int j = 0; j < m; j++) {
                    int p = sc.nextInt();
                    if (list.contains(p)) {
                        continue;
                    }
                    list.add(p);
                    counts[p]++;
                }
            }
            int min = -1;
            int minI = -1;
            for (int i = 0; i < counts.length; i++) {
                if (min < counts[i]) {
                    min = counts[i];
                    minI = i;
                }
            }
            if (min < q) {
                System.out.println(0);
            } else {
                System.out.println(minI);
            }
        }
    }
}

Measured memory_bytes: 67692
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int, input().split())
p = list(map(int, input().split()))
uf = UnionFind(n)
xy = [list(map(int, input().split())) for _ in range(m)]
for i in range(m):
    a, b = xy[i][0], xy[i][1]
    a-= 1
    b-= 1
    uf.union(a, b)
cnt = 0
for i in range(n):
    if uf.same(p[i]-1, i):
        cnt += 1
print(cnt)




Measured memory_bytes: 34116
a = input().split()
W,H = int(a[0]),int(a[1])
x,y = int(a[2]),int(a[3])
r = int(a[4])
if 0 <= (x-r) and (x+r) <= W:
    if 0 <= (y-r) and (y+r) <= H:
        print("Yes")
    else:
        print("No")
else:
    print("No")


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

int main(){
  long long x,i,sum;
  i = 0;
  sum = 100;
  cin >> x;
  while(sum<x){
    sum = sum*1.01;
    i++;}
  cout << i << endl;
  return 0;
    
}


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

int main() {
  string s;
  cin >> s;
  int n = s.length();

  if (n == 2) {
    if (s[0] == s[1]) {
      cout << 1 << " " << 2 << endl;
    } else {
      cout << -1 << " " << -1 << endl;
    }
    return 0;
  }

  for (int i = 0; i < n - 1; i++) {
    if (s[i] == s[i + 1]) {
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    } else if (s[i] == s[i + 2]) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
h, w = gets.split.map(&:to_i)
s = []
h.times.each{
    si = gets.chomp
    s << si if si.include?("#")
}

len=s[0].length
(0..len-1).to_a.reverse.each{|i|
    alldot = true
    s.each{|si|
        alldot = false if si[i] == "#"
    }
    if alldot
        s.length.times.each{|j|
            s[j][i] = ''
        }
    end
}

s.each{|si|
    puts si
}


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
typedef long long ll;
#define PII pair<ll,ll>
const int maxn=1e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-10;
using namespace std;
int main()
{
	int n,m,ans=0;
	scanf("%d%d",&n,&m);
	ans=n*(n-1)/2+m*(m-1)/2;
	printf("%d\n",ans);
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;

	if (B >= A){
	cout << "unsafe" << "\n";
	} else{
	cout << "safe" << "\n";		
	}



	return 0;
}


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

double dist(int x1, int y1, int x2, int y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int fact(int n){
    int ret = 1;
    for(int i = 1; i <= n; ++i){
        ret *= i;
    }
    return ret;
}

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

    double ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            ans += dist(x[i],y[i],x[j],y[j]);
        }
    }
 
    printf("%.6f\n", 2*ans/n);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

int main() {
	vector<int> a(3);

	cin >> a[0] >> a[1] >> a[2];

	int res = *min_element(a.begin(), a.end());
	a.erase(min_element(a.begin(), a.end()));
	cout << res + (*min_element(a.begin(),a.end())) << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int64_t n;
    cin >> n;
    auto t1 = n / 3, t2 = n / 5, t3 = n / 15;
    cout << n * (n + 1) / 2 - 3 * t1 * (t1 + 1) / 2 - 5 * t2 * (t2 + 1) / 2 + 15 * t3 * (t3 + 1) / 2 << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define ff first
#define ss second
#define int long long 
#define endl "\n"
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);	

const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
int a[N] , pref[N];
int n , m;

void solve(){
	cin >> n ;
	int x = 0 ;
	for(int i = 0 ; i<n-1 ; i++){	
		cin >> x;
		pref[x]++;
	}	
	for(int i = 1 ; i<=n ; i++)
		cout<<pref[i]<<endl;
	
}

int32_t main(){
	FAST;
	int t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}

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

const int N = 610;
const int mod = 1e9 + 7;

int n, k, fix[N], f[N][N], mat[N];
long long g[N];

inline void calc(int l, int r) {
  for (int i = l; i <= r; i ++)
    if (mat[i]) if (mat[i] < l || mat[i] > r) return;
  long long ans = g[r - l + 1 - (fix[r] - fix[l - 1])];
  for (int i = l + 1; i < r; i ++)
    (ans -= f[l][i] * g[r - i - (fix[r] - fix[i])]) %= mod;
  f[l][r] = (ans % mod + mod) % mod;
}

int main() {
  scanf("%d%d", &n, &k);
  n *= 2;
  for (int i = 1, a, b; i <= k; i ++) {
    scanf("%d%d", &a, &b);
    fix[a] = fix[b] = 1;
    mat[a] = b; mat[b] = a;
  }
  g[0] = 1;
  for (int i = 1; i <= n; i ++) {
    fix[i] += fix[i - 1];
    g[i] = ( (i & 1) ? 0 : g[i - 2] * (i - 1) % mod );
  }
  long long ans = 0;
  for (int i = 2; i <= n; i += 2)
    for (int j = 1; i + j - 1 <= n; j ++) {
      calc(j, i + j - 1);
      int cont = 2 * k - (fix[i + j - 1] - fix[j - 1]);
      ans += f[j][i + j - 1] * g[n - i - cont] % mod;
    }
  printf("%lld\n", ans % mod);
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#include <iostream>
#define ll long long int
#define cases int t; cin >> t; while (t--)
#define pb push_back
using namespace std;

int main()
{
    int n, a, b; cin >> n >> a >> b;
    if (n*a <= b) cout << n*a << endl;
    else cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math/rand"
)

func main() {
	var D int
	fmt.Scan(&D)
	cs := make([]int, 26)
	for i := 0; i < 26; i++ {
		fmt.Scan(&cs[i])
	}

	ss := make([][26]int, D)
	for i := 0; i < D; i++ {
		for j := 0; j < 26; j++ {
			fmt.Scan(&ss[i][j])
		}
	}

	ts := make([]int, D)
	for d := 0; d < D; d++ {
		sat := int(-1e9)
		t := 0
		for i := 0; i < 26; i++ {
			ts[d] = i + 1
			s := solve(d+1, ts, cs, ss)
			if sat <= s {
				sat = s
				t = ts[d]
			}
		}
		ts[d] = t
	}

	sat1 := solve(D, ts, cs, ss)
	for i := 0; i < 170000; i++ {
		d := rand.Intn(365)
		q := rand.Intn(25) + 1

		t := ts[d]
		ts[d] = q
		sat2 := solve(D, ts, cs, ss)
		if sat1 < sat2 {
			sat1 = sat2
			continue
		}

		ts[d] = t
	}

	for i := 0; i < len(ts); i++ {
		fmt.Println(ts[i])
	}
}

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

func solve(D int, ts []int, cs []int, ss [][26]int) int {
	last := [26]int{}
	sat := 0
	for d := 0; d < D; d++ {
		j := ts[d] - 1
		last[j] = d + 1
		for i := 0; i < 26; i++ {
			sat -= (d + 1 - last[i]) * cs[i]
		}
		sat += ss[d][j]
	}

	return sat
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int N, A;
    cin >> N >> A;
    cout << N*N - A << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    int K;
    int odd_cnt, even_cnt;
    
    cin >> K;
    
    even_cnt = K / 2;
    odd_cnt = K - even_cnt;
    
    // cout << odd_cnt << " " << even_cnt << endl;
    
    cout << odd_cnt * even_cnt << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long X, long long N, std::vector<long long> p){
  set<ll> s(p.begin(),p.end());
  For(i,200){
    if(s.count(X-i)==0){
      cout<<X-i<<endl;
      return ;
    }
    if(s.count(X+i)==0){
      cout<<X+i<<endl;
      return;
    }
  }
}

int main(){
  cout<<setprecision(1000);
    long long X;
    scanf("%lld",&X);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(X, N, std::move(p));
    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000LL;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	ll ans = 1;
	bool zero = false;
	V<ll> a(n);
	rep(i, n) {
		cin >> a[i];
		if (a[i] == 0)zero = true;
	}
	if (zero)cout << 0 << endl;
	else {

		ll ans = 1;
		ll ans9 = 0;

		rep(i, n) {

			ans9 *= a[i];
			ans *= a[i];
			ans9 += ans / 1e9;
			ans %= (int)1e9;

			if (ans9 >= 1e9 && ans > 0) {
				cout << -1 << endl;
				return 0;
			}

		}

		cout << ans9 * (int)1e9 + ans << endl;

	}

}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(ll i=k;i<n;i++)
#define all(x) x.begin(),x.end()
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define xx first
#define yy second
#define MOD 1000000007
#define pb push_back
typedef long long ll;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}


int t[100000][3];
ll dp[100][100001];
int n,k;





ll slv(int i,int j){
	if(i >= n) return 0;
	ll & ret = dp[i][j]; 
	if(ret != -1) return ret;
	if(j + t[i][0] > k) return ret = slv(i+1,j);
	return ret = max(t[i][1] + slv(i+1,j+t[i][0]),slv(i+1,j));
}

int main(){
	FAST
	cin >> n >> k;
	rep(i,n) cin >> t[i][0] >> t[i][1];
	memset(dp,-1,sizeof(dp));
	cout << max(slv(0,0),max(slv(0,1),slv(0,2))) << endl;
	return 0;
}


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

int N;
long long int C, K, T[100006];
vector<long long int > V;

int main(void) {

	cin >> N >> C >> K;

	for (int i = 1; i <= N; i++) {
		cin >> T[i]; V.push_back(T[i]);
	}

	sort(V.begin(), V.end());

	int ans = 0;
	long long int tmp=V[0];
	long long int COUNT = 0;

	for (int i = 0; i <= N-1; i++) {
		//cout << "V= " << V[i] << " tmp= " << tmp << endl;
		if ((tmp <= V[i]) && (V[i] <= tmp + K) && (COUNT < C)) { COUNT++; }
		else { ans++;  tmp = V[i]; COUNT = 1; }
		//cout <<"tmp= "<< tmp <<" COUNT= " << COUNT << endl;
	}

	ans++;

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 2040
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int search(const int *s,int n,int x){
	rep(i,n){
		if(x==s[i])
			return 1;
		else if(x < s[i])
			return 0;
	}
	return 0;
}

int c(const int *s,const int *t,int n,int q){
	int c=0;
	rep(i,q){
		c+=search(s,n,t[i]);
	}
	return c;
}

int main(){
	int n,q;
	cin >> n;
	int s[n];
	cinf(s,n);
	cin >> q;
	int t[q];
	cinf(t,q);
	sort(s,s+n);
	cout << c(s,t,n,q) << endl;
}


Measured memory_bytes: 3604
#include<stdio.h>
#include<algorithm>
using namespace std;
long long a[1000005];
void init()
{
    a[0]=0;
    for(long long i=1;i<=1000000;i++)
    {
        if(i%3!=0&&i%5!=0)
            a[i]=a[i-1]+i;
        else a[i]=a[i-1];
    }
}
int main()
{
    init();int n;
    scanf("%d",&n);
    printf("%lld\n",a[n]);
}


Measured memory_bytes: 9544
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;

int main(){
  int a[5];
  int g=0;
  int b[5], c[5];
  for(int i=0; i<5; i++){
    cin >> a[i];
    c[i] = a[i] % 10;
    if(c[i] == 0) b[i] = a[i];
    else b[i] = a[i] + 10 - c[i];
    if(c[i] == 0) continue;
    else g = max(g, 10-c[i]);
  }
  int ans=0;
  for(int i=0; i<5; i++){
    ans += b[i];
  }
  ans -= g;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 888
#include<iostream>
using namespace std;
int check[1000001];
int main(){
	int s;
	cin >> s;
	for(int i=1;i<10000000;i++){
		check[s]++;
		if(check[s]==2){
			cout << i << endl;
			return 0;
		}
		if(s%2) s=3*s+1;
		else s/=2;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N; cin >> N;
    int ans = 0;
    int prev = 0;
    REP(i,N) {
        int a; cin >> a;
        if (prev == a) {
            ans++;
            a = 0;
        }
        prev = a;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	int n;
	cin >> n;
	if (n <= 999) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ABD" << endl;
	}
}	

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        var N = cin.nextlong;
        var M = cin.nextlong;

        if (N >= 2 && M >= 2)
        {
            WriteLine((N - 2) * (M - 2));
        }
        else if(N == 1 && M == 1)
        {
            WriteLine(1);
        }
        else
        {
            WriteLine(N * M - 2);
        }

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13140
a, b = [int(v) for v in input().split()]
# 0 < a <= b
if 0 < a:
  print("Positive")
elif a <= 0 <= b:
  print("Zero")
else:
  if (b - a + 1) % 2 == 1:
    print("Negative")
  else:
    print("Positive")

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
    long long x;
    mint(long long x=0):x(x % MOD + (0 <= x ? 0 : MOD)) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint& a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
    mint& operator-=(const mint& a) { if ((x -= a.x) < 0) x += MOD; return *this; }
    mint& operator*=(const mint& a) { (x *= a.x) %= MOD; return *this; }
    mint operator+(const mint& a) const { return mint(x) += a; }
    mint operator-(const mint& a) const { return mint(x) -= a; }
    mint operator*(const mint& a) const { return mint(x) *= a; }

    // for prime mod
    mint inv() const {
        long long a = x, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        return mint(u);
    }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { return mint(x) /= a; }
};
istream& operator>>(istream& is, const mint& a){ return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }

int main(){
    int N;
    string S;
    cin >> N >> S;

    map<char, int> mp;
    for (auto &i : S) mp[i]++;

    mint ans = 1;
    for (auto &p : mp) {
        ans *= p.second + 1;
    }
    ans -= 1;

    cout << ans << endl;
}

Measured memory_bytes: 512
import itertools
n,m=map(int,input().split())
a=list(map(int,input().split()))
ans=10**30
if m==0:
  print(0)
  exit()
for i in itertools.combinations(range(1,n),m-1):
  s=list(i)
  mx=a[0]
  cost=0
  for j in range(1,n):
    if j in s:
      if a[j]>mx:
        mx=a[j]
        continue
      else:
        cost+=mx+1-a[j]
        mx+=1
    mx=max(mx,a[j])
  ans=min(cost,ans)
print(ans)

Measured memory_bytes: 70252
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt(),d=nxt();
    vector <vector <int> > v;
    vector <int> row(d);
    v.resize(n,row);
    for(int i=0;i<n;i++)
        for(int j=0;j<d;j++)
            cin>>v[i][j];
    int test=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
        {
            int sum=0;
            for(int k=0;k<d;k++)
                sum+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
            int temp=sqrt(sum);
            if(temp*temp==sum)
                test++;
        }
    cout<<test<<endl;
    
    
    return 0;   
}


 
 


Measured memory_bytes: 256
n = int(input())
ls = [[] for i in range(n)]
for i in range(n-1):
    u,v,w = map(int,input().split())
    ls[u-1].append([v-1,w])
    ls[v-1].append([u-1,w])
#行ってないとこはtrue
check_edge = [True for i in range(n)]
stack = []
stack.append(0)
check_edge[0] = False
ans = [0]*n
while stack:
    v = stack.pop()
    for j in ls[v]:
        u,w = j[0],j[1]
        if not check_edge[u]:continue
        if w % 2 == 0:
            ans[u] = ans[v]
        else:
            ans[u] = not ans[v]
        check_edge[u] = False
        stack.append(u)
for i in range(n):
    if ans[i] == True:
        print(1)
    else:
        print(0)

Measured memory_bytes: 87456
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

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

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

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);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int ans=0;
	int x,y;cin>>x>>y;
	VI p(300,0);
	p.at(0)=300000;
	p.at(1)=200000;
	p.at(2)=100000;
	x--;y--;
	ans+=p.at(x)+p.at(y)+(x==0 and y==0) * 400000;
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
	
	int a,b,c,i,k=0;
	
	scanf("%d %d %d",&a,&b,&c);
	
	for(i=a;i<=b;i++){  
		
		if(c%i==0){  //????????????i??§?????£??????????????????????????????????´???°??????????????????????????????????¶???? 
			k=k+1;
		}
	}
	printf("%d\n",k);
	
	
	return 0;
}  

Measured memory_bytes: 596
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;


public class Answer
{
    private static void Main(string[] args)
    {
        int[] n_k = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        List<int> dice = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToList();

        int a = dice.GetRange(0, n_k[1]).Sum();
        int b = dice.GetRange(0, n_k[1]).Sum();

        for (int i = n_k[1]; i < dice.Count(); i++)
        {
            a = a + dice[i];
            a = a - dice[i - n_k[1]];

            if (a > b)
            {
                b = a;
            }
        }

        Console.WriteLine((n_k[1] + b) / 2.0);

    }
}

Measured memory_bytes: 34396
#1:初期化
N = int(input())
a = []
r_append = a.append
for i in range(N):
    r_append(list(map(int,input().split())))
dp = [[0]*3 for _ in range (N+1)]
#print(dp, sep="\n")
#print(a, sep="\n")

#2:初期値(元からゼロなので記述無し)

#3:dp実行部(貰うDP)
for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if(j == k):
                continue
            dp[i][j] = max(dp[i][j], dp[i-1][k]+a[i-1][j]) #dpは[1]からだが，aは[0]からに注意

#4:出力
dpmax = 0
for i in range(3):
    dpmax= max(dp[N][i], dpmax)
#print(*dp, sep="\n")
print(dpmax)


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

using namespace std;

int a[101];

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    bool ch = false;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum+=a[i];
        if (a[i] < 10 || a[i] % 10 != 0) {
            ch = true;
        }
    }
    if (ch) {
        if (sum % 10 != 0) {
            cout << sum << endl;
        } else {
            sort (a, a + n);
            for (int i = 0; i < n; ++i) {
                sum-=a[i];
                if (sum % 10 != 0) {
                    cout << sum << endl;
                    return 0;
                } else {
                    sum+=a[i];
                }
            }
        }
    } else {
        cout << 0 << endl;
    }
    return 0;
}

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

const int MAX_V = 15;
const int INF = 1e9;
int V, E, D[MAX_V][MAX_V], dp[1 << MAX_V][MAX_V];

int rec(int S, int v, int T){
    if (dp[S][v] >= 0) return dp[S][v];
    if (S == (1 << V) - 1 && v == T) return dp[S][v] = 0;
    
    int res = INF;
    for (int u = 0; u < V; ++u){
        if (!(S >> u & 1)) res = min(res, rec(S | 1 << u, u, T) + D[v][u]);
    }
    return dp[S][v] = res;
}

int main(){
    cin >> V >> E;
    for (int i = 0; i < V; ++i){
        for (int j = 0; j < V; ++j){
            D[i][j] = INF;
        }
    }

    for (int i = 0; i < E; ++i){
        int v, u, c;
        cin >> v >> u >> c;
        D[v][u] = c;
    }
    

    
    int ans = INF;
    for (int i = 0; i < V; ++i){
        for (int i = 0; i < (1 << V); ++i){
            for (int j = 0; j < V; ++j){
                dp[i][j] = -1;
            }
        }
        ans = min(ans, rec(0, i, i));
    }
    if (ans >= INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;    
    }
}


Measured memory_bytes: 5040
import sys
sys.setrecursionlimit(100000)

def load_balls():
	balls = []
	LINE_NUM, TOTAL = 0, 0
	while True:
		line = sys.stdin.readline().strip()
		LINE_NUM += 1
		if LINE_NUM == 1:
			TOTAL = int(line)+1
			continue
		balls.append([int(i) for i in line.split(" ")])
		if LINE_NUM == TOTAL: break
	return balls
balls_list = load_balls()
for balls in balls_list:
	left, right = [0], [0]
	for ball in balls:
		if left[-1] < ball: left.append(ball)
		elif right[-1] < ball: right.append(ball)
	print("YES" if len(left)-1 + len(right)-1 == 10 else "NO")

Measured memory_bytes: 7620
def gcd2(a,b):
  if b == 0:
    return a
  else:
    return(gcd2(b,a%b))

K=int(input())

def gcd(a,b,c):
 gcd=gcd2(a,b)
 return gcd2(gcd,c)
      
ans=0
for a in range(1,K+1):
  for b in range(a+1,K+1):
    for c in range(b+1,K+1):
     ans += gcd(a,b,c) * 6 
     
for a in range(1,K+1):
  for b in range(a+1,K+1):
     ans += gcd(a,a,b) * 6 

ans += K*(K+1)/2

print(int(ans))

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

int main() {
    int N; cin >> N;
    int F[101][11];
    rep(i, N){
        rep(j, 10){
            cin >> F[i][j];
        }
    }
    int P[101][11];
    rep(i, N){
        rep(j, 11){
            cin >> P[i][j];
        }
    }
    int ans = -1001001001;
    for (int i = 1; i < 1<<10; i++){
        int now = 0;
        rep(j, N){
            int cnt = 0;
            rep(k, 10){
                if(i>>k&1 && F[j][k] == 1){
                    cnt++;
                }
            }
            now += P[j][cnt];
            //cout << j << " " << cnt << " " << now << endl;
        }
        ans = max(ans, now);
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
	int n;
	double x1, y1, x2, y2, x3, y3;

	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

		if(y1-y2==0.0 || y1-y3==0.0){
			swap(x1, x2);
			swap(y1, y2);
		}
		if(y1-y2==0.0 || y1-y3==0.0){
			swap(x1, x3);
			swap(y1, y3);
		}

		double a12, b12, a13, b13;
		a12 = -(x1-x2)/(y1-y2);
		a13 = -(x1-x3)/(y1-y3);

		double x12, y12, x13, y13;
		x12 = (x1+x2)/2.0;
		y12 = (y1+y2)/2.0;
		x13 = (x1+x3)/2.0;
		y13 = (y1+y3)/2.0;

		b12 = y12 - a12 * x12;
		b13 = y13 - a13 * x13;

		double xp, yp;
		xp = -(b12-b13)/(a12-a13);
		yp = a12*xp + b12;

		double r;
		r = sqrt(pow((x1-xp),2.0) + pow((y1-yp),2.0));

		printf("%.3f %.3f %.3f\n", xp, yp, r);
	}


	return(0);
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
#define pa pair<int,int>
#define CLR(a,x) memset(a,x,sizeof(a))
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
const int maxn=62,P=1e9+7;

inline char gc(){
	return getchar();
	static const int maxs=1<<16;static char buf[maxs],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxs,stdin),p1==p2)?EOF:*p1++;
}
inline ll rd(){
    ll x=0;char c=gc();bool neg=0;
    while(c<'0'||c>'9'){if(c=='-') neg=1;c=gc();}
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();
    return neg?(~x+1):x;
}

bool num[maxn];
ll f[maxn][3][2];

inline void add(ll &a,ll b){a=(a+b)%P;}

int main(){
    //freopen("","r",stdin);
    ll N=rd();
    int l=-1;for(;N;N>>=1) num[++l]=N&1;
    f[l+1][1][1]=1;
    for(int i=l;i>=0;i--){
    	if(num[i]){
    		for(int j=0;j<=1;j++) for(int k=0;k<=1;k++) add(f[i][j][k],f[i+1][j][k]);
    		add(f[i][0][0],f[i+1][2][0]),add(f[i][0][1],f[i+1][2][1]);
    	
    		add(f[i][0][0],f[i+1][0][0]+f[i+1][0][1]+f[i+1][2][0]+f[i+1][2][1]);
    		add(f[i][2][0],f[i+1][1][0]+f[i+1][1][1]);
    		
    		add(f[i][0][0],f[i+1][0][0]+f[i+1][0][1]);
    		add(f[i][2][0],f[i+1][2][0]+f[i+1][2][1]);
    	}else{
    		add(f[i][0][0],f[i+1][0][0]),add(f[i][2][0],f[i+1][2][0]);
    		
    		for(int j=0;j<=1;j++) for(int k=0;k<=1;k++) add(f[i][j][k],f[i+1][j][k]);
    		add(f[i][0][0],f[i+1][2][0]),add(f[i][0][1],f[i+1][2][1]);
    	
    		add(f[i][0][0],f[i+1][0][0]),add(f[i][0][1],f[i+1][0][1]);
    		add(f[i][1][0],f[i+1][2][0]),add(f[i][1][1],f[i+1][2][1]);
    	}
    }
    ll ans=0;
    for(int i=0;i<=2;i++) for(int j=0;j<=1;j++) add(ans,f[0][i][j]);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
N,C=gets.split(" ").map &:to_i
IA=N.times.map{gets.split(" ").map &:to_i}
MS,CS,rs=[[0,0]],[0],0
IA.each_with_index{|v,i|CS[i+1]=CS[i]+v[1];MS[i+1]=[CS[i+1]-v[0],MS[i][0]].max,[CS[i+1]-2*v[0],MS[i][1]].max}
(0...N).map{|i|ob=CS[N]-CS[i];rs=[rs,ob+MS[i][0]-2*(C-IA[i][0]),ob+MS[i][1]-(C-IA[i][0])].max}
puts [rs,MS[N][0]].max


Measured memory_bytes: 19244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N;

int main(void){
    
    scanf("%d", &N);
    printf("%d\n", 24 + (24 - N));
	
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,g,h,i,j,k,l,m,n;
	scanf("%d",&a);
	while(a!=0) {
		d=0;
		e=0;
		f=0;
		g=0;
		h=0;
		i=0;
		j=0;
		k=0;
		l=0;
		m=0;
		for(b=1;b<=a;b++) {
			scanf("%d",&c);
			if(c==0) {
				d+=1;
			}
			if(c==1) {
				e+=1;
			}
			if(c==2) {
				f+=1;
			}
			if(c==3) {
				g+=1;
			}
			if(c==4) {
				h+=1;
			}
			if(c==5) {
				i+=1;
			}
			if(c==6) {
				j+=1;
			}
			if(c==7) {
				k+=1;
			}
			if(c==8) {
				l+=1;
			}
			if(c==9) {
				m+=1;
			}
		}
		if(d==0) {
			printf("-\n");
		}
		else {
			for(n=1;n<=d;n++) {
				printf("*");
			}
			printf("\n");
		}
		if(e==0) {
			printf("-\n");
		}
		else {
			for(n=1;n<=e;n++) {
				printf("*");
			}
			printf("\n");
		}
		if(f==0) {
			printf("-\n");
		}
		else {
			for(n=1;n<=f;n++) {
				printf("*");
			}
			printf("\n");
		}
		if(g==0) {
			printf("-\n");
		}
		else {
			for(n=1;n<=g;n++) {
				printf("*");
			}
			printf("\n");
		}
		if(h==0) {
			printf("-\n");
		}
		else {
			for(n=1;n<=h;n++) {
				printf("*");
			}
			printf("\n");
		}
		if(i==0) {
			printf("-\n");
		}
		else {
			for(n=1;n<=i;n++) {
				printf("*");
			}
			printf("\n");
		}
		if(j==0) {
			printf("-\n");
		}
		else {
			for(n=1;n<=j;n++) {
				printf("*");
			}
			printf("\n");
		}
		if(k==0) {
			printf("-\n");
		}
		else {
			for(n=1;n<=k;n++) {
				printf("*");
			}
			printf("\n");
		}
		if(l==0) {
			printf("-\n");
		}
		else {
			for(n=1;n<=l;n++) {
				printf("*");
			}
			printf("\n");
		}
		if(m==0) {
			printf("-\n");
		}
		else {
			for(n=1;n<=m;n++) {
				printf("*");
			}
			printf("\n");
		}
	scanf("%d",&a);
	}
	return 0;
}

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

int main(){
  int A,B;
  cin>>A>>B;
  int cosuu=0;
  int keta[5];

  for(int i=A; i<B+1;i++){
    keta[0]=(i%10);
    keta[1]=(i%100)/10;
    keta[2]=(i%1000)/100;
    keta[3]=(i%10000)/1000;
    keta[4]=(i%100000)/10000;
    if(keta[0]==keta[4]&&keta[1]==keta[3]){
      cosuu++;
    }
  }
  cout<<cosuu<<endl;

  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a,b,x;
  double t;
  cin>>a>>b>>x;
  if(a*a*b<=2*x) t=atan(2.0*(a*a*b-x)/a/a/a)*180.0/M_PI;
  else t=atan(0.5*a*b*b/x)*180.0/M_PI;
  cout<<fixed<<setprecision(10)<<t<<endl;
}

Measured memory_bytes: 384