akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
using namespace std;

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

const int INF = 1e18;

int N, A, B, C;
vector<int> l;

int rec(int idx, int a, int b, int c) {
    if (idx >= N) {
        if (a == 0 || b == 0 || c == 0) return INF;
        return abs(a - A) + abs(b - B) + abs(c - C);
    }

    int ret = INF;
    // A
    chmin(ret, rec(idx + 1, a + l[idx], b, c) + (a > 0 ? 10 : 0));
    // B
    chmin(ret, rec(idx + 1, a, b + l[idx], c) + (b > 0 ? 10 : 0));
    // C
    chmin(ret, rec(idx + 1, a, b, c + l[idx]) + (c > 0 ? 10 : 0));
    // 使わない
    chmin(ret, rec(idx + 1, a, b, c));

    return ret;
}

signed main() {
    cin >> N >> A >> B >> C;
    l.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> l[i];
    }

    int ans = rec(0, 0, 0, 0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> b(n-1);
  rep(i, n-1){
    int in;
    cin >> in;
    b.at(i) = in;
  }
  int ans = 0;
  rep(i, n){
    if(i == 0) ans += b.at(0);
    else if(i == n-1) ans += b.back();
    else ans += min(b.at(i-1), b.at(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int n, c;
        try (Scanner cin = new Scanner(System.in)) {
            n = cin.nextInt();
            c = 0;
            for (int i = 0;i < n; i++) {
                int x = cin.nextInt();
                int rem = x % 2;
                while (rem == 0) {
                    x = x / 2;
                    c++;
                    rem = x % 2;
                }
            }
        }

        System.out.println(c);
    }
}

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

fn main() {
    let n: usize = read();
    let mut a = vec![0u64; n];
    for i in 0..n {
        a[i] = read();
    }
    a.sort();
    let mut count_dict = std::collections::HashMap::new();

    count_dict.insert(a[0], n);
    for i in 1..n {
        if a[i] == a[i - 1] {
            continue;
        }
        count_dict.insert(a[i], n - i);
    }

    let mut ans = 0;
    for key in count_dict.keys() {
        if key % 2 == 1 {
            ans ^= count_dict[key];
        }
    }

    if ans == 0 {
        println!("second");
    } else {
        println!("first");
    }
}


Measured memory_bytes: 12540
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;


int N,M;
int ans;

string S;

int main() {
	cin >> S;
	
	for (int i = 0; i < 3; i++) {
		if (S[i] == 'R') {
			ans++;
		}
	}
	if (S == "RSR") {
		ans--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    int m;
    cin>>m;
    vpii conne(m);
    rep(i,0,m){
        int a,b;
        cin>>a>>b;
        conne[i].first=a;
        conne[i].second=b;
    }
    sort(conne.begin(),conne.end());
    vpii cut;
    rep(i,0,m){
        if(cut.size()==0)cut.push_back(conne[i]);
        else{
            bool ok=false;
        rep(j,0,cut.size()){
            if(cut[j].second>conne[i].first){
                chmin(cut[j].second,conne[i].second);
                ok=true;
            }
            if(ok)break;
        }
        if(!ok)cut.push_back(conne[i]);
       }
    }
    cout<<cut.size()<<endl;
    return 0;
}




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

using namespace std;

const int maxn = 1e5 + 50 ;
const int inf = 0x3f3f3f3f ;

int v[maxn] ,dp[maxn] ;

int main() {
	int n ;
	scanf("%d",&n) ;
	for (int i = 1 ; i <= n ; i ++ ) {
		scanf("%d",&v[i]) ;
	}
	dp[1] = v[1] ; int len = 1 ;
	for (int i = 2 ; i <= n ; i ++ ) {
		if ( dp[len] >= v[i] ) {
			dp[++len] = v[i] ;
		} else {
			int l = 1,r = len ,mid ;
			while ( l <= r ) {
				mid = (l + r)>>1 ;
				if ( dp[mid] >= v[i] ) {
					l = mid + 1 ;
				} else {
					r = mid - 1 ;
				}
			}
			dp[l] = v[i] ;
		}
	}
//	for (int i = 1 ; i <= n ; i ++ ) {
//		printf("%d ",dp[i]) ;
//	} puts("") ;
	printf("%d\n",len) ;
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  long long money = 0;
  h = min(h, 2 * q);
  s = min(s, 2 * h);
  if (2*s <= d) {
    cout << s*n << '\n';
  } 
  else {
    if (n % 2 == 0) {
      cout << n * d / 2 << '\n';
    }
    else {
      cout << (n-1) / 2 * d + s << '\n';
    }
  }
}


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

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int A, B;
    string S, ans = "Yes\n";
    cin >> A >> B >> S;
    rep(i, A + B + 1) {
        if (i == A) {
            if (S[i] != '-') ans = "No\n";
        } else {
            if (S[i] < '0' || S[i] > '9') ans = "No\n";
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
# include <stdlib.h>
 
int menor(const void * x, const void * y){
	int a = *((int *) x), b = *((int *) y);
 
	if (a<b)
		return 1;
	if (a>b)
		return -1;
 
	return 0;
 
}


int main(){
    int n, mv;
    
    scanf("%d %d", &n, &mv);
    
    int vec[n];
    double soma = 0;
    
    for (int i = 0; i < n; ++i){
        scanf("%d", &vec[i]);
        soma += vec[i];
    }
    
    qsort(vec, n, sizeof(vec[0]), menor);
    int count = 0, a = 0;
    double val = soma/(mv*4);
    
    //printf("%lf\n", val);
    for (int i = 0; i < mv; ++i){
        if (vec[i] >= val)
            count += 1;
        if (count == mv){
            a = 1;
            break;
        }
    }
    
    if (a ==1)
        printf("Yes\n");
    else
        printf("No\n");
    
    
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
 
void read (int&a) {
	a = 0; char k = getchar(); int f = 1;
	for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
	for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
	a *= f;
}
 
const int N = 200000 + 5, mod = 1000000007;
int fpow (int base, int v) {
	int tot = 1;
	for(; v; v >>= 1, base = 1LL * base * base % mod) if (v & 1) tot = 1LL * tot * base % mod;
	return tot;
}
void add (int&a, int b) { a = (a + b) % mod; }
vector<int> G[N], D[N];
int n, sz[N], dep[N];
 
void dfs (int u, int f) {
	dep[u] = dep[f] + 1;
	D[ dep[u] ].push_back (u);
	for (int i = 0; i < (signed)G[u].size(); ++i) if (G[u][i] != f) {
		dfs (G[u][i], u);
	}
}
 
int stk[N], top, dp[N], sum0[N], pow2[N];
 
int dp0(int x) { return (pow2[sz[x]] - dp[x] + mod) % mod; }
 
void upd (int x, int y) {
	sz[y] += sz[x];
	dp[y] = 1LL * dp[y] * dp0(x) % mod;
	add (dp[y], 1LL * sum0[y] * dp[x] % mod);
	sum0[y] = 1LL * sum0[y] * dp0(x) % mod;
}

int fa[N], L[N], llca[N];
int Find (int u) { return u == fa[u] ? u : fa[u] = Find (fa[u]); }

void tarjan (int u, int f) {
	if (L[u]) llca[L[u]] = Find (L[u]);
	for (int i = 0; i < (signed)G[u].size(); ++i) if (G[u][i] != f) {
		tarjan (G[u][i], u);
		fa[G[u][i]] = u;
	}
}

int main ()
{
	read (n); n++;
	pow2[0] = 1; for(int i = 1; i <= n; ++i) pow2[i] = 1LL * pow2[i - 1] * 2 % mod;
	for (int i = 2; i <= n; ++i) {
		int x; read (x); ++x;
		G[x].push_back (i), G[i].push_back (x);
	}
	dfs (1, 0);

	for (int i = 1; i <= n; ++i) fa[i] = i;
	for (int i = 1; i <= n; ++i) for (int j = 0; j < (signed)D[i].size() - 1; ++j) L[D[i][j + 1]] = D[i][j];
	tarjan (1, 0);

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int nowdep = i;
		if (!D[i].size()) break;
		stk[ top = 1 ] = D[i][0], dp[D[i][0]] = 1, sum0[D[i][0]] = 1, sz[D[i][0]] = 1;
		for (int j = 1; j < (signed)D[i].size(); ++j) {
			int p = D[i][j], lca = llca[stk[top]];
 
			dp[p] = 1, sum0[p] = 1, sz[p] = 1;
 
			while(dep[ stk[top] ] > dep[lca]) {
				if (top == 1 || dep[stk[top - 1]] < dep[lca]) { dp[lca] = 0, sum0[lca] = 1, sz[lca] = 0; upd (stk[top], lca); }
				else upd(stk[top], stk[top - 1]);
				top--;
			}
			if (top == 0 || stk[top] != lca) stk[++top] = lca;
			stk[++top] = p;
		}
		for (int i = top; i > 1; --i) upd (stk[i], stk[i - 1]);
		int tans;
		add (ans, tans = 1LL * pow2[n - (signed)D[nowdep].size()] * dp[stk[1]] % mod);
	}
	printf ("%d\n", ans);
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 n;
	while (cin >> n && n) {
		vector<int64> a(n);
		int64 sum = 0;
		REP(i, n) {
			cin >> a[i];
			sum += a[i];
		}
		int64 res = 0;
		REP(i, n) 
			if (a[i] * n <= sum) res++;
		cout << res << endl;
	}
}



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

int main() {
    int n, m;
    cin >> n >> m;
    double root = sqrt(m);
    int res = 1;
    for (int i = 1; i <= root; i++) {
        if (m % i == 0) {
            if (m / n >= i) {
                res = max(res, i);
            }
            if (m / n >= m / i) {
                res = max(res, m / i);
            }
        }
    }
    cout << res << endl;
}


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

#define ff first
#define ss second
#define pb push_back

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 2005;

int dp[3][3][N];

int ok(string t, string p, int ini, int a, int b){
  if(ini < 0){
    swap(t, p);
    swap(a, b);
    ini = abs(ini);
  }
  if(ini >= t.size()) return 1;
  if(dp[a][b][ini] != -1) return dp[a][b][ini];
  int id = 0;
  for(int i = ini; i < (int)t.size(); i++){
    if(id == p.size()) break;
    if(p[id] != t[i] && t[i] != '?' && p[id] != '?'){
      return dp[a][b][ini] = 0;
    }
    id++;
  }
  return dp[a][b][ini] = 1;
}

int main() {
  memset(dp, -1, sizeof dp);
  char a[3][N];
  scanf("%s", a[0]);
  scanf("%s", a[1]);
  scanf("%s", a[2]);
  string sa[3];
  sa[0] = a[0];
  sa[1] = a[1];
  sa[2] = a[2];
  int p[3] = {0, 1, 2};
  int ans = 3*N;
  do{
    for(int i = 0; i <= (int)sa[p[0]].size(); i++){
      if(ok(sa[p[0]], sa[p[1]], i, p[0], p[1])){
        int sz = max(sa[p[0]].size(), i + sa[p[1]].size());
        string aux0 = sa[p[0]];
        string aux1 = sa[p[1]];
        int id = 0;
        for(int j = 0; j <= sz; j++){
          if(ok(sa[p[0]], sa[p[2]], j, p[0], p[2]) && ok(sa[p[1]], sa[p[2]], j - i, p[1], p[2])){
            ans = min(ans, max(sz, (int)j + (int)sa[p[2]].size()));
          }
        }
      }
    }
  }while(next_permutation(p, p+3));
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n,ans=0;
    string s;
    cin >> n >> s;

    for(int i=1;i<n;i++){
        string x = s.substr(0,i), y = s.substr(i);
        int num=0;
        for(int j=0;j<26;j++){
            bool in_x = false, in_y = false;
            for(int k=0;k<x.size();k++){
                if(x.at(k) == (char)(j + 'a')) in_x = true;
            }
            for(int k=0;k<y.size();k++){
                if(y.at(k) == (char)(j + 'a')) in_y = true;
            }
            if(in_x && in_y) num++;
        }
        ans = max(ans,num);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	string s;
	string t;
}

void parseInput(T)(out Input input, T adapter)
{
	with (input)
	{
		s = adapter.readln();
		t = adapter.readln();
	}
}

struct Output
{
}

auto main2(Input* input)
{
	int minDistance = int.max;
	int i = 0;
	while (i + input.t.length <= input.s.length)
	{
		int distance = 0;
		for (int j = 0; j < input.t.length; j++)
		{
			if (input.s[i + j] != input.t[j])
				distance++;
		}

		if (distance < minDistance)
			minDistance = distance;

		i++;
	}

	return minDistance;
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`cabacc
abc`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 1);
	}

	unittest // example2
	{
		string example =
`codeforces
atcoder`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 6);
	}

	unittest // example3
	{
		string example =
``;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == _placeholder_);
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		parseInput(input, new StringAdapter(example));
	}
}

class StdinAdapter
{
	// readf!"%s"は使えない
	// https://issues.dlang.org/show_bug.cgi?id=19820
	uint readf(alias format, A...)(auto ref A args) { return std.stdio.readf!format(args); }
	string readln() { return std.stdio.readln().strip(); }
}

class StringAdapter
{
	import std.format;
	string _s;
	this(string input) { _s = input; }
	uint readf(alias format, A...)(auto ref A args) { return _s.formattedRead!format(args); }
	string readln()
	{
        string ret;
		auto i = _s.countUntil("\n");
		if (i == -1) { ret = _s; _s = ""; }
        else { ret = _s[0..i]; _s = _s[i+1..$]; }
		return ret;
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, new StdinAdapter());
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


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


int main(){
  int n; cin>>n;
  
  vector<tuple<string,int,int>> p(n);
  
  for(int i=0;i<n;i++){
    string a;
    int b;
    cin>>a>>b;
    p[i]=make_tuple(a,-b,i+1);
  }

  sort(p.begin(),p.end());
  
   for(int i=0;i<n;i++){
      cout<<get<2>(p[i])<<endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

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

Measured memory_bytes: 3604
N = int(input())
if N < 105:
    print(0)
    exit()
elif N == 105:
    print(1)
    exit()
else:
    dP ={2,3,5,7}
    for i in range(10,int(200**0.5)+2):
        bF = True
        for j in dP:
            if 0 == i % j :
                bF = False
                break
        if bF:
            dP.add(i)
    aP = sorted(list(dP - {2}))
    iL = len(aP)
    aN = []
    for i in range(iL):
        i1 = aP[i]
        i3 = i1**3
        for j in range(i+1,iL):
            j1 = aP[j]
            aN.append(i3*j1)
            for k in range(j+1,iL):
                k1 = aP[k]
                aN.append(i1*j1*k1)
                aN.append(i3*k1)

    aN = sorted(list(set(aN)))
    for i in range(len(aN)):
        if N < aN[i]:
            print(i)
            exit()


Measured memory_bytes: 3064
i = list(map(int, input().split())) 
#i_1 i_2を取得し、iに値を入れる
N = i[0]
X = i[1]
T = i[2]

if N%X == 0:
    k = N/X
    print(int(T*k))
else:
    k = int(N/X)+1
    print(int(T*k))






Measured memory_bytes: 9164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static int H;
    static int W;
    static boolean[][] P; // black=true

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        H = sc.nextInt();
        W = sc.nextInt();
        P = new boolean[H][W];
        for (int i = 0; i < H; i++) {
            String line = sc.next();
            for (int j = 0; j < W; j++) {
                P[i][j] = line.charAt(j) == '#';
            }
        }
        System.out.println( solve() ? "Yes" : "No" );
    }

    static boolean solve() {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if( P[i][j] && !hasAnyBlackAround(i, j) ) {
                    return false;
                }
            }
        }
        return true;
    }

    static boolean hasAnyBlackAround(int h, int w) {
        if( h != 0 && P[h-1][w] ) return true;
        if( h != H-1 && P[h+1][w] ) return true;
        if( w != 0 && P[h][w-1] ) return true;
        if( w != W-1 && P[h][w+1] ) return true;
        return false;
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

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

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 21204
#include "bits/stdc++.h"
/*
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
*/
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    ll x,y;cin>>x>>y;
    int res=1;
    while(true){
        x*=2;
        if(x>y) break;
        res++;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(N)]

from itertools import combinations

pairs = list(combinations(X, 2))

res = 0
for pair in pairs:
    d = 0
    for i in range(D):
        d += (pair[0][i] - pair[1][i])**2
    d = d**0.5
    if int(d) == d:
        res += 1

print(res)

Measured memory_bytes: 3188
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
s = lc()

ans = 0
for i in range(n):
    set1 = set(s[:i])
    set2 = set(s[i:])
    ans = max(ans, len(set1&set2))
    
print(ans)

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    for(int i=0;i<a;i++){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    for(int i=0;i<a;i++){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	    for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
	fact_inv[t]=power(fact[t], MOD-2);
	for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

int i,j,k,tmp;
ll ans = 0;

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

  int K; cin >> K;
  if(K%2==0 || K%5==0){cout << -1 << endl; return 0;}
  if(7%K==0){cout << 1 << endl; return 0;}
  tmp = 7 % K; ans = 2;
  while(true){
	  tmp = tmp * 10 + 7;
	  if(tmp % K ==0){cout << ans << endl; return 0;}
	  ans++; tmp = tmp % K;
  }

  return 0;
}


Measured memory_bytes: 3640
#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;
  int a, b, x = 0;
  
  rep (cnt, N) {
    cin >> a >> b;
    x += (b - a + 1);
  }
  
  cout << x << endl;  
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll NCK_MAX = 510000;
ll mod=1000000007;
ll extgcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0; return a;
  }
  ll q = a/b, g = extgcd(b, a - q*b, x, y);
  ll z = x - q * y;
  x = y;
  y = z;
  return g;
}
 
ll invmod (ll a, ll m) {
  ll x, y;
  extgcd(a, m, x, y);
  x %= m;
  if (x < 0) x += m;
  return x;
}

ll COM(ll n,ll k,ll mod){
    ll ans=1;
    for(ll i=0;i<k;i++){
        ans=((ans*(n-i)%mod)*invmod(k-i,mod))%mod;
    }
    return ans;
}
ll pw(ll a, ll b, ll mod) {
  if (b == 0) return 1;
  if (b % 2 == 1) return pw(a, b-1, mod) * a % mod;
  ll temp = pw(a, b/2, mod);
  return temp * temp % mod;
}
int main(void){
    ll n,a,b;
    cin>>n>>a>>b;
    cout<<(pw(2,n,mod)-1-COM(n,a,mod)-COM(n,b,mod)+3*mod)%mod<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
    char str[3];
    scanf("%s", str);

    if (str[0] != str[1]) {
        printf("Yes");
    } else if (str[1] != str[2]) {
        printf("Yes");
    } else if (str[2] != str[0]) {
        printf("Yes");
    } else {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
n = int(input())
lst = [int(x) for x in input().split()]
res = 1
isHigher = False

if 0 in lst:
  print(0)
else:
  for i in lst:
    res = res * i
    if res > 10**18:
      isHigher = True
      break
  if isHigher:
    print(-1)
  else:
    print(res)

Measured memory_bytes: 21468
import java.util.Scanner;

public class Main{

   public static void main(String[] args){
      
      Scanner reader = new Scanner(System.in);
      
      String s = reader.next();
      int iA = -1;
      int iZ = 0;
      
      for(int i = 0; i < s.length(); i++){
         String l = s.substring(i, i+1);
         if(l.equals("A") && iA < 0){
            iA = i;
         } else if(l.equals("Z") && i > iZ){
            iZ = i;
         }
      }
      
      System.out.println(iZ - iA + 1);
   }
}
         
         
      
      
      

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

cnt = 0
bOK = False
for _ in range(N):
	D1,D2 = map(int,input().split())

	if D1 == D2:
		cnt += 1
		if 3 <= cnt:
			bOK = True
	else:
		cnt = 0

if bOK:
	print("Yes")
else:
	print("No")



Measured memory_bytes: 62020
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    *t++;
    while(t != V.end()) {
        cout << " " << *t++;
        // if(t != V.end()) cout << " ";
    }
    cout << endl;
};

ll fib[100] = {0};
ll solve(int i) {
    if(fib[i] > 0) return fib[i];
    if(i < 2) return 1;
    return fib[i] = solve(i - 1) + solve(i - 2);
}

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

    int n;
    cin >> n;
    cout << solve(n) << endl;
}



Measured memory_bytes: 3160
import sys

input = sys.stdin.readline


def main():
    N, M, X = map(int, input().split())
    A = list(map(int, input().split()))

    cost_0 = 0
    cost_N = 0
    for a in A:
        if a < X:
            cost_0 += 1
        else:
            cost_N += 1

    ans = min(cost_0, cost_N)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

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

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

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

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

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

void Main() {
  ll N, M; cin >> N >> M;
  vector<e> E(M);
  rep(i, 0, M){
    cin >> E[i].a >> E[i].b;
    E[i].a--; E[i].b--;
  }
  vector<int> V(N);
  rep(i, 0, M){
    V[E[i].a]++;
    V[E[i].b]++;
  }
  string res = "YES";
  rep(i, 0, N){
    if(V[i] % 2) res = "NO";
  }
  cout << res << endl;
}

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

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

  Main();
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<vector<int>> c(3, vector<int>(3, 0));
    for (int i = 0; i < 3; i++) {
        cin >> c.at(i).at(0) >> c.at(i).at(1) >> c.at(i).at(2);
    }
    FOR(a1, 0, 101) {
        int a2, a3, b1, b2, b3;
        b1 = c.at(0).at(0) - a1;
        b2 = c.at(0).at(1) - a1;
        b3 = c.at(0).at(2) - a1;
        a2 = c.at(1).at(0) - b1;
        a3 = c.at(2).at(0) - b1;
        if ((a2 == c.at(1).at(1) - b2) && (a2 == c.at(1).at(2) - b3) &&
            (a3 == c.at(2).at(1) - b2) && (a3 == c.at(2).at(2) - b3)) {
            cout << "Yes" << endl;
            exit(0);
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3628
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

using namespace std;

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

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

vector<ll> S;
int b[200010];
int a[10010];

bool vis[10010];

void DFS(int u,ll s)
{
	if(vis[u])return;
	
	vis[u]=1;
	
	s+=b[u];
	
	S.pb(s);
	
	DFS(a[u],s);
}

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	int n,k;cin>>n>>k;
	for(int i=0;i<n;i++){cin>>a[i];a[i]--;}
	for(int i=0;i<n;i++)cin>>b[i];
	
	ll ans=-ll(1e18);
	
	for(int i=0;i<n;i++)
	{
		memset(vis,0,sizeof(vis));
		
		DFS(i,0);
		
		if(S.back()>0&&k>=int(S.size()))
		{
			ll q=k/int(S.size());
			
			if(q>=1)
			{
				ll mx=-ll(1e18);
				
				if(q-1>0)mx=0;
				
				for(int i=0;i<int(S.size());i++)mx=max(mx,S[i]);
				
				ans=max(ans,(q-1)*S.back()+mx);
			}
			
			{
				int r=k%int(S.size());
				
				ll mx=0;
				
				for(int i=0;i<r;i++)mx=max(mx,S[i]);
				
				ans=max(ans,mx+q*S.back());
			}
		}
		else for(int j=1;j<=k;j++)
		{
			if(j-1<S.size())ans=max(ans,S[j-1]);
			else break;
		}
		
		S.clear();
	}
	
	cout<<ans;
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


Measured memory_bytes: 3948
n, k = map(int, input().split())
d = [0] * k
sunuke = {}
for i in range(n):
    sunuke.setdefault(str(i), 0)
    #print(sunuke)

for i in range(k):
    d[i] = int(input())
    A = list(map(int,input().split()))
    #print(d[i],A)
    for j in range(d[i]):
        sunuke[str(A[j]-1)] += 1

ans = list(sunuke.values()).count(0)

print(ans)

Measured memory_bytes: 9156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp16
{
    class Program
    {
        static void Main(string[] args)
        {
            var values1 = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
            var values2 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            int N = values1[0];

            int[] an = values2;

            var resultStr = string.Join(" ",Enumerable.Zip(Enumerable.Range(1,N), values2, (index, value) => new { index, value }).OrderBy(tuple=>tuple.value).Select(tuple=>tuple.index));

            Console.WriteLine(resultStr);
        }
    }
}

Measured memory_bytes: 33500
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int A, B, M; cin >> A >> B >> M;
  vector<int> a(A);
  for (int& x: a) cin >> x;
  vector<int> b(B);
  for (int& x: b) cin >> x;

  int ma = 1e9, mb = 1e9;
  for (int& x: a) ma = min(ma, x);
  for (int& x: b) mb = min(mb, x);
  ll ans = ma + mb;
  while (M--) {
    int x, y, c; cin >> x >> y >> c;
    ans = min<ll>(ans, a[x - 1] + b[y - 1] - c);
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

int N;
cin >> N;
vector<int> a(N);
for(int i = 0; i < N; i++){
  cin >> a[i];
  a[i]--;
}

int ans = -1;

int now = 0;
for(int i = 0; i < N-1; i++){
  int next = a[now];
  if(next == 1){
    ans = i+1;
    break;
  }
  now = next;
}

cout << ans << endl;


  return 0;
}


Measured memory_bytes: 640
S = input()
N = len(S)
P = 2019
num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1
print(ans)

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

const double PI = 3.14159265358979323846;

int main()
{
    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<bool>> grid(h);
    rep(i, grid.size())
    {
        grid[i] = vector<bool>(w);
    }

    rep(i, h)
    {
        string s;
        cin >> s;
        rep(j, w)
        {
            if (s[j] == '#')
            {
                grid[i][j] = true;
            }
        }
    }

    int ans = 0;

    for (int s = 0; s < (1 << h); s++)
    {
        vector<bool> used_h(h);

        for (int i = 0; i < h; i++)
        {
            // iを使うかどうか
            if (s & (1 << i))
            {
                used_h[i] = true;
            }
        }
        for (int ss = 0; ss < (1 << w); ss++)
        {
            vector<bool> used_w(w);
            for (int j = 0; j < w; j++)
            {
                // jを使うかどうか
                if (ss & (1 << j))
                {
                    used_w[j] = true;
                }
            }
            int blacks = 0;
            rep(ii, h)
            {
                rep(jj, w)
                {
                    if (grid[ii][jj] && used_h[ii] && used_w[jj])
                    {
                        blacks++;
                    }
                }
            }
            if (blacks == k)
            {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];
#define ALL(v)  (v).begin(),(v).end()
std::set<int> st;
//#define MAX(a,b) if(a>b)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

    /*  ペア関連
    //vector<pair<long long, long long> > pairs(N);
    for(long long i=0; i<N; i++){
        long long a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    //sort(pairs.begin(), pairs.end(),greater<pair<int,int> >());
	sort(pairs.begin(), pairs.end());
    */

 	//stack<int> sta;   
    //queue<int> que;


int main(){
	
	long long N,M,K;
	string s;
    
	std::cin >> N;
    //std::cin >> N >> M;
    //std::cin >> N >> M >> K;
    
	std::vector<long long> v(N);
	std::vector<long long> w(N);
    //std::cin >> s;
    
    
    // 配列入力
    
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
	}
	
	/*
	for(long long i=0; i<N; i++){
		std::cin >> w[i];
	}
	*/
	
	
	//ソート
    std::sort(v.begin(),v.end());//昇順ソート
    //std::sort(v.begin(),v.end(),std::greater<long long>());//降順ソート
    //std::sort(w.begin(),w.end());//昇順ソート
    //std::sort(w.begin(),w.end(),std::greater<long long>());//降順ソート
    /*
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
		if(st.find(v[i])==st.end()){
			st.insert(v[i]);
		}
		else{
			st.erase(v[i]);
		}
	}
	*/

    
    int sum,sum1;
	sum=0;
	sum1=0;
	int flg,flg1,cnt,cnt1;
	flg=0;
	flg1=0;
	cnt=0;
	cnt1=0;
	int max;
	int max1;
	max=0;
	max1=0;

	int min;
	int min1;
	min=INF;
	min1=INF;
	int work;
	work=0;
	
    /*
	for(long long i=0; i<N; i++){
		
	}
	*/
	
	//文字列入力
	/*
	for(long long i=0; i<s.length(); i++){
		
		if(s[i]!='1'){
	}
	*/
	//work=(v[0]+v[N-1])/2;
	for(long long i=v[0]; i<v[N-1]; i++){
    	flg=1;
    	for(long long j=0; j<N; j++){
			sum+=pow(i-v[j],2);
		}
		min=MIN(sum,min);
		sum=0;
	}
	if(flg==0){
		min=0;
	}
    if(1){
    	printf("%d",min);
    	//puts("Yes");
    	//printf("%d",st.size());
    	//文字列の出力
    	//std::cout << s << std::endl;
    	
	}
	else{
		//puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,t,a,x;
	scanf("%d%d%d",&n,&t,&a);
	double ans=INT_MAX;
	int j=-1;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		if(abs(t-x*0.006-a)<ans){
			ans=abs(t-x*0.006-a);
			j=i;
		}
	}
	printf("%d\n",j);
	return 0;
} 

Measured memory_bytes: 256
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]

minv = 10**8
for i in range(2 ** N):
    alg = [0]*M
    cost = 0
    for j in range(N):
        if ((i >> j) & 1):
            for k, ca in enu(CA[j]):
                if k == 0:
                    cost += ca
                else:
                    alg[k-1] += ca
    if all([X<=val for val in alg]):
        if cost < minv:
            minv = cost

if minv == 10**8:
    print(-1)
else:
    print(minv)

Measured memory_bytes: 9496
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int M[] = new int[n+1];
        int DP[][] = new int[n+1][n+1];
        Arrays.fill(M,0);
        for(int i=0;i<n+1;i++) Arrays.fill(DP[i],0);
        for(int i=1;i<=n;i++){
            M[i-1] = sc.nextInt();
            M[i] = sc.nextInt();
        }
        for(int l=2;l<=n;l++){
            for(int i=1;i<=n-l+1;i++){
                int j = i+l-1;
                int min_cost = 999999999;
                for(int k=i;k<j;k++){
                    if(k==i) min_cost = DP[i][k]+DP[k+1][j]+M[i-1]*M[k]*M[j];
                    else min_cost = Math.min(min_cost,DP[i][k]+DP[k+1][j]+M[i-1]*M[k]*M[j]);
                }
                DP[i][j] = min_cost;
            }
        }
        System.out.println(DP[1][n]);
    }
}


Measured memory_bytes: 26740
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


#define REP(i,N) for(auto i = 0; i <N; i++)


typedef long long ll;
//const int MOD = pow(10,9)+7;
//const int MAX = 100001;

using namespace std;
int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}


int main() {
    
    int A = in(); int B = in(); int C = in();
    int D = in(); int E  =in(); int F = in();
    
    set<int> water;
    
    for(auto i = 0; i <= F/(100*A); i++){
        for(auto j = 0; 100*j*B <= F - i*A*100; i++){
            water.insert(i * 100 * A + j * 100 * B);
        }
    }
    
    int weightlimit;
    int sugarlimit;
    
    int lower;
    
    double maxsugar = -1;
    int maxwat = -1;
    int maxsug = -1;
    
    for(auto wat:water){
        
        weightlimit = F - wat;
        sugarlimit = wat/100 * E;
        
        lower = min(weightlimit,sugarlimit);
        
        for(auto i = 0; i *C < lower; i++){
            for(auto j = 0; j * D + i * C <= lower; j++){
                
                if (maxsugar < (double)(j * D + i * C)/(double)(wat + j * D + i * C)) {
                    maxsugar = (double)(j * D + i * C)/(double)(wat + j * D + i * C);
                    maxwat = wat;
                    maxsug =(j * D + i * C);
                }
                
            }
        }
        
    }
    
    cout << maxsug + maxwat << " " << maxsug << endl;
    
    
    return 0;
    
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.14159265359
int main(void){
    ll N=0,M=0;
    cin >> N >>M;
    
    
    for(ll i=0; i<M;i++){
    ll s=0;
    cin >>s;
    N=N-s;
    }
    
    if(N>=-1){
    cout << N << endl;
    }
    else cout << -1;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const double pi=acos(-1);
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll h,w,k;
cin>>h>>w>>k;
if(k==1000000000){
rep(i,w){
cout << 1000000000 << " ";}
rep(i, h-w){
cout << 1 << " ";}
cout << endl;}
else{
rep(i,w){
cout << k << " ";}
rep(i,h-w){
cout << k+1 << " ";}
cout << endl;}}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define INF 1e9
#define All(x) (x).begin(),(x).end()
#define F first
#define S second
#define Cout(x) cout << (x) << endl
typedef long long ll;
using namespace std;

int main(){
    string s,t;cin>>s>>t;
    cout<<t+s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789


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

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


ll S;
ll X1, X2;
ll Y1, Y2;

int main(){
    
    cin>>S;
    
    X1 = sqrt(S);
    if( S != (X1*X1) ) X1++;
    Y2 = X1;
    
    S = (X1*Y2)-S;
    
    if( S != 0 ){
        FOR( i, 1, mod ){
            if( S % i == 0 ){
                X2 = S / i;
                Y1 = i;
                if( X2 < mod-8 ) break;
            }
        }
    }
    
    printf("0 0 %lld %lld %lld %lld\n", X1, Y1, X2, Y2 );
    
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {

	int h, n;
	cin >> h >> n;
	int a[n], b[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cin >> b[i];
	}
	int dp[h + 1];
	dp[0] = 0;
	for (int i = 1; i <= h; i++) {
		int ans = (int) 1e8;
		for (int j = 0; j < n; j++) {
			int newH = i - a[j];
			ans = min(ans, b[j] + (newH >= 0 ? dp[newH] : 0));
		}
		dp[i]=ans;
	}
	cout<<dp[h];

}



Measured memory_bytes: 888
package main

import (
	"fmt"
	"math"
)

func main() {
	var num int
	fmt.Scan(&num)
	for i := 0; i < num; i++ {
		var x1, y1, x2, y2, x3, y3 float64
		fmt.Scanf("%f%f%f%f%f%f", &x1, &y1, &x2, &y2, &x3, &y3)

		a := 2 * (x2 - x1)
		b := 2 * (y2 - y1)
		c := 2 * (x3 - x1)
		d := 2 * (y3 - y1)
		e := x2*x2 - x1*x1 + y2*y2 - y1*y1
		f := x3*x3 - x1*x1 + y3*y3 - y1*y1

		// 直線1: ax + by - e = 0
		// 直線2: cx + dy - f = 0
		px := (d*e - b*f) / (a*d - b*c)
		py := (c*e - a*f) / (b*c - a*d)
		r := math.Sqrt((px-x1)*(px-x1) + (py-y1)*(py-y1))
		fmt.Printf("%.3f %.3f %.3f\n", px, py, r)
	}
}



Measured memory_bytes: 1128