akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <cstring>

using namespace std;

const int MOD = 998244353;

bool sameAll(const string& s){
	for(auto c : s) if(c != s[0]) return false;
	return true;
}

int search(const string& s){
	set<string> S; S.insert(s);
	queue<string> qu; qu.push(s);
	while(!qu.empty()){
		string str = qu.front(); qu.pop();
		for(int i=0;i+1<str.size();i++){
			if(str[i] == str[i+1]) continue;
			char c = 'a' + 3 - (str[i]-'a' + str[i+1]-'a');
			string next = str;
			next[i] = next[i+1] = c;
			if(S.count(next)) continue;
			S.insert(next);
			qu.push(next);
		}
	}
	return S.size();
}

int solve(const string& s){
	if(sameAll(s)) return 1;
	if(s.size() <= 4) return search(s);
	int dp[2][2][3][3];
	memset(dp, 0, sizeof(dp));
	for(int i=0;i<3;i++) dp[0][0][i][i] = 1;
	int type = s[0] - 'a';
	bool hasAdj = false;
	for(int i=1;i<s.size();i++){
		type = (type + s[i] - 'a') % 3;
		if(s[i] == s[i-1]) hasAdj = true;
		memset(dp[1], 0, sizeof(dp[1]));
		for(int adj=0;adj<2;adj++){
			for(int sum=0;sum<3;sum++){
				for(int prev=0;prev<3;prev++){
					for(int next=0;next<3;next++){
						int nextAdj = (adj == 1 || prev == next) ? 1 : 0;
						int nextSum = (sum + next) % 3;
						int& nextVal = dp[1][nextAdj][nextSum][next];
						nextVal = (nextVal + dp[0][adj][sum][prev]) % MOD; 
					}
				}
			}
		}
		memcpy(dp[0], dp[1], sizeof(dp[0]));
	}
	int res = 0;
	for(int i=0;i<3;i++) res = (res + dp[0][1][type][i]) % MOD;
	if(!hasAdj) res = (res + 1) % MOD;
	return res;
}

int main(){
	string S;
	while(cin >> S) cout << solve(S) << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <iterator>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e14, cnt;


ll a[1000001];
int main(){
	ll n,m;
	cin>>n>>m;
	ll p[m],y[m];
	vector<pair<ll,ll>> v;
	
	map<ll,ll> id;
	
	for(ll i=0; i<m; i++){
	
		cin>>p[i]>>y[i];
		v.push_back(make_pair(p[i],y[i]));
	}
	sort(v.begin(),v.end());
	for(ll i=0; i<m; i++){
		id[v[i].second]=a[v[i].first]+1;
		a[v[i].first]++;
	}
	for(ll i=0; i<m; i++){
		string s=to_string(p[i]);
		ll k=6-s.size();
		string s2=to_string(id[y[i]]);
		ll k2=6-s2.size();
		for(ll j=1; j<=k; j++) cout<<0;
		cout<<s;
		for(ll j=1; j<=k2; j++) cout<<0;
		cout<<id[y[i]]<<endl;
	}
	
}


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

#define pb push_back

using VI = vector <int>;
using ll = long long;

const int MXT = 26;
const int MXD = 365;

int D;
int C[MXT+10], S[MXD+10][MXT+10];

VI best;
ll best_score;

void update(VI &current, ll &new_score) {
	if (best.empty() || best_score < new_score) {
		best_score = new_score;
		best = current;
	}
	return;
}

void input() {
	scanf("%d", &D);
	for (int i = 1; i <= MXT; i ++) scanf("%d", &C[i]);
	for (int i = 1; i <= D; i ++) {
		for (int j = 1; j <= MXT; j ++) scanf("%d", &S[i][j]);
	}
	return;
}
void output() {
	for (auto x : best) printf("%d\n", x);
}

namespace Greedy {
	int last[MXT+10];
	void greedy() {
		for (int param = 1; param <= 100; param ++) {
			fill_n(last, MXT+1, 0);
			ll delta[MXT + 1] = {0};
			VI greedy_ans;
			ll score = 0;
			for (int i = 1; i <= D; i ++) {
				ll sum = 0;
				for (int j = 1; j <= MXT; j ++) delta[j] += C[j];
				sum = accumulate(delta + 1, delta + MXT + 1, 0ll);
				ll mx = -2e18;
				int ansd = -1;
				for (int j = 1; j <= MXT; j ++) {
					ll val = param * (- sum + delta[j]) + S[i][j];
					if (mx < val) mx = val, ansd = j;
				}
				score += S[i][ansd] + delta[ansd] - sum;
				delta[ansd] = 0;
				greedy_ans.pb(ansd);
			}
			update(greedy_ans, score);
		}
	}
}

int main() {
	input();
	Greedy::greedy();
	output();
	return 0;
}


Measured memory_bytes: 3816
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int N;
long long W, weight[MAX_N], value[MAX_N]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // 初期化
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;

    // 初期条件
    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {

            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // i 番目の品物を選ばない場合
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}

Measured memory_bytes: 89568
n=int(input())
a=list(map(int,input().split()))
s=[a[0]]
for i in range(1,n):
    s.append(s[-1]+a[i])

def f(c,i):
    global n,a,s
    return abs(s[c]-(s[i]-s[c]))

def g(c,i):
    global n,a,s
    return abs((s[c]-s[i])-(s[n-1]-s[c]))

ans=[]
for i in range(1,n-2):
    ans_=[]
    #左側決める
    l,r=0,i
    while l+2<r:
        c1=(l*2+r)//3
        c2=(l+2*r)//3
        if f(c1,i)>f(c2,i):
            l=c1
        else:
            r=c2
    x=sorted([(f(j,i),j) for j in range(l,r+1)])[0][1]
    ans_.append(s[x])
    ans_.append(s[i]-s[x])

    #右側決める
    l,r=i+1,n-1
    while l+2<r:
        c1=(l*2+r)//3
        c2=(l+2*r)//3
        if g(c1,i)>g(c2,i):
            l=c1
        else:
            r=c2
    x=sorted([(g(j,i),j) for j in range(l,r+1)])[0][1]
    ans_.append(s[x]-s[i])
    ans_.append(s[n-1]-s[x])

    ans.append(max(ans_)-min(ans_))
print(min(ans))

Measured memory_bytes: 100552
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

vector<int> es[1010];
vi x;

ll dfs(int cur) {
    if(es[cur].size() == 0) {
        return 0LL;
    }
    ll ret = 1e18;
    // ll dp[5010][2];
    vector<vl> dp(x[cur]+1, vl(2, 1e18));
    // rep(i, x[cur]+1) dp[i][0] = 1e18;
    dp[0][0] = 0;
    int now = 0, nxt = 1;
    for(auto& to : es[cur]) {
        rep(i, dp.size()) dp[i][nxt] = 1e18;
        ll tmp = dfs(to);
        for(int i = 0; i + tmp < dp.size(); ++i) dp[i+tmp][nxt] = min(dp[i+tmp][nxt], dp[i][now] + x[to]);
        for(int i = 0; i + x[to] < dp.size(); ++i) dp[i+x[to]][nxt] = min(dp[i+x[to]][nxt], dp[i][now] + tmp);
        swap(now, nxt);
    }
    rep(i, dp.size()) ret = min(ret, dp[i][now]);
    return ret;
}

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    string yes = "POSSIBLE", no = "IMPOSSIBLE";
    int n;
    cin >> n;
    rep(i, n-1) {
        int a;
        cin >> a;
        es[--a].pb(i+1);
    }
    x.resize(n);
    rep(i, n) cin >> x[i];
    ll ans = dfs(0);
    if(ans == 1e18) cout << no << endl;
    else cout << yes << endl;
    return 0;
}

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

int a[100100];
int dp[100100];

main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
    	scanf("%d",&a[i]);
	}
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	printf("%d\n",dp[n-1]);
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
//template <typename... T> void read(T& ... t){ ((cin >> t), ...); }
//template <typename... T> void write(T ... t){ ((cout << t), ...); }
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
using LL = long long;
using pii = pair<int,int>;
const int INF = 2e9;
const int MAXN = 2e3 +3;
int n;
int arr[MAXN];

int32_t main(){ FAST;
	cin >> n;
	for(int i=1; i<=n; ++i) cin >> arr[i];
	sort(arr+1, arr+n+1);
	
	int ans = 0;
	for(int a=1; a<=n; ++a) for(int b=a+1; b<=n; ++b){
		ans += upper_bound(arr+1, arr+n+1, arr[a]+arr[b]-1) - (arr+b) - 1;
	}
	cout << ans << ln;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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;

int main(){
    ll n;
    cin >> n;
    if(n%2==1)cout << 0 << endl;
    else {
        ll div = 10;
        ll ans = 0;
        while(div<=n){
            ans += n/div;
            div *= 5;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
/*
    @uthor: Amit Kumar
    user: CodeChef: dr_virus_ ; Codeforces,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll long long
#define ld double
#define endl "\n"

const ll mod = 1e9+7;
const ll inf = 1e18;


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
 /* #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif */

    ll t=1;
   // cin>>t;
    while(t--){
         ll k,a,b;
         cin>>k>>a>>b;
         for(auto i=a;i<=b;i++){
             if(i%k==0) {
                 cout<<"OK";
                 exit(0);
             }
         }
         cout<<"NG";
        //your code goes here
    }
    //cerr<<"Time Elapsed: "<<clock()/(double)CLOCKS_PER_SEC<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
/*    #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
//ll  t;cin>>t;while(t--)
{
  ll a,b,c,x=0;
  cin>>a;
  cout<<"ABC"<<a<<endl;
  
  

}
return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 1
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <random>
#include <ctime>

#define MOD 1000000007

const long long INF = 10000000000000000;

using namespace std;

int main(){
	int N;
	cin>>N;
	vector<int> s(N);
	long long total=0;
	bool flg=false;
	int min_val=999;
	for(int i=0;i<N;i++){
		cin>>s[i];
		total+=s[i];
		if(s[i]%10!=0 && s[i]<min_val){
			min_val=s[i];
			flg=true;
		}
	}
	if(total%10==0 && flg){
		cout<<total-min_val<<endl;
	}else if(total%10!=0){
		cout<<total<<endl;
	}else{
		cout<<"0"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n: usize,
        k: usize,
    }
    const MOD: u64 = 1_000_000_007;

    let mut fact = vec![vec![0; n+1]; n+1];
    fact[0][0] = 1;

    for i in 1..fact.len() {
        fact[i][0] = 1;
        fact[i][i] = 1;

        for j in 1..i {
            fact[i][j] = (fact[i -1][j-1] + fact[i-1][j]) % MOD;
        }
    }

    for i in 1..k+1 {
        println!("{}", fact[n-k+1][i] * fact[k-1][i-1] % MOD)
    }
}


Measured memory_bytes: 45308
import math
nums = [int(i) for i in input().split()]
n = nums[0]
x = nums[1]
y = nums[2]
res = [0 for i in range(2010)]

for i in range(1, n+1):
    for j in range(i+1, n+1):
        dis = j - i
        dis = min(dis, abs(i-x)+abs(j-y)+1)
        res[dis] += 1
for i in range(1, n):
    print(res[i])


Measured memory_bytes: 9284
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;
  
int main(){
  int n;
  cin >> n;
  auto h = vector<int>(n,0);
  for (int i = 0; i < n; i++)
  {
      cin >> h[i];
  }
  
  h[0]--;
  bool flag = true;
  for (int i = 1; i < n-1; i++)
  {
      if(h[i-1]<h[i]) h[i]--;
      if(h[i]>h[i+1]){
          flag = false;
          break;
      } 
  }
  
  
  cout << (flag == true ? "Yes":"No");
}
  

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<chrono>
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;

int main() {
	cin >> N >> M;
	vector<ll> A(N + 1), sum(N + 1,0);
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		sum[i] = sum[i - 1] + A[i];
		sum[i] %= M;
	}
	sort(sum.begin(), sum.end());
	vector<ll> com;
	ll tmp = 1;
	for (int i = 1; i <= N; i++) {
		if (sum[i] != sum[i-1]) {
			com.push_back(tmp);
			tmp = 1;
		}
		else tmp++;
	}
	com.push_back(tmp);
	for (ll i : com) {
		ans += i * (i - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2428
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define MAX 15000001
#define p pair<int,int>
#define speed ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0)

int getdiff(int a,int b,int c)
{
	int n = (a-int('0'))*100 + (b-int('0'))*10 + (c-int('0'));
	if(n> 753)
		return n-753;
	else
		return 753-n;
}

int main()
{
	string s;
	cin>>s;
	int diff=1000;
	for(int i=0;i<s.length()-2;i++)
	{
		diff=min(diff,getdiff(s[i],s[i+1],s[i+2]));
	}
	cout<<diff;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int MAX = 999999999;

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

    vector<int> nums(n);
    rep(i, n) cin >> nums[i];

    int out = nums.size();
    rep(i, n) m -= nums[i];

    out += m / *min_element(all(nums));

    cout << out << endl;
}

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

using namespace std;

int main(void) {
	string S;
	cin >> S;
	int Q;
	cin >> Q;
	bool reversed = false;
	deque<string> q;
	for(int i = 0; i < S.length(); ++i) {
		q.push_back(string({S[i]}));
	}
	for(int i = 0; i < Q; ++i) {
		int T;
		cin >> T;
		if(T == 1) {
			reversed ^= true;
		} else {
			int F;
			string C;
			cin >> F >> C;
			if((F == 1) ^ reversed) {
				q.push_front(C);
			} else {
				q.push_back(C);
			}
		}
	}
	string ans;
	if(reversed) {
		for(auto it = q.rbegin(); it != q.rend(); ++it) {
				ans += *it;
		}
	} else {
		for(auto it = q.begin(); it != q.end(); ++it) {
				ans += *it;
		}
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 17540
#include <stdio.h>

int main() {

	int d, t, s;
	scanf("%d", &d);
	scanf("%d", &t);
	scanf("%d", &s);

	if ((float)d / (float)s <= (float)t) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	
	return 0;
}

Measured memory_bytes: 1712
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
#L1～LNはL[0]~L[N-1]で取り出す。よってこれから竹1~Nのことを竹0~N-1と呼ぶ。

#メンバーの選び方[0]~[255]の「[合計初期サイズ, 本数]」を格納するリスト
initialSum = []
for i in range(2**N): #全てのフラグパターンについて計算する
    nowsum = 0
    nowbamboocnt = 0
    for j in range(N): #2^(j+1)乗で割った余りが2^j以上なら、フラグjがTrue
        if i % (2**(j+1)) >= 2**j:
            nowbamboocnt += 1
            nowsum += L[j] #j(0-N-1)本目の竹について見ているので、L[j]が今見ている竹の長さ
    initialSum.append([nowsum, nowbamboocnt])


#A,B,Cが竹を選んだ場合の所要MPを出し、最低値をminに格納する
bambooset = {i for i in range(N)} #存在する竹の組み合わせ
min = 3000 #最低値の初期化

lestbamboo = bambooset.copy() #残っている竹

for i, initSumA in enumerate(initialSum): #i:0~255。initsumA[0]は初期合計サイズ, initsumA[1]は本数
#Aはこのfor文で既に選ばれていると考えればいい。
    if initSumA[1] ==0 or N - initSumA[1] < 2: continue #竹が0とか、残り竹が0,1なら飛ばす
    lestbamboo = bambooset.copy() #再初期化
    for j in range(N): #使った竹はlestbambooからremove
        if i % (2**(j+1)) >= 2**j: #j(0-N-1)本目の竹について考えている
            lestbamboo.remove(j)
    necesMPforA = abs(A - initSumA[0]) + (initSumA[1]-1)*10 #abs(目標-合計)-合成必要MP

    #次はBを計算する。Bが取らなかったものの中からCが取る
    for b in range(2**len(lestbamboo)): #残った竹それぞれにつき取るか取らないか選ぶ
    #2*残り本数通りある。ex.3本残っているとして、b(000とか101とか)で、Bの選び方を示す
        lestbambooList = list(lestbamboo) #リスト化する [0]~[本数-1]。値は竹番号[0-N]
        #lestbambooListは自動的に昇順になっている
        bamboocntB = 0 #Bの本数
        nowsumB = 0
        lestbambooforC = lestbamboo.copy() #Cのための残り竹を入れる
        for k in range(len(lestbambooList)): #2^(k+1)乗で割った余りが2^k以上なら、フラグkがTrue
            if b % (2**(k+1)) >= 2**k: #Bがとる場合
                bamboocntB += 1
                nowsumB += L[lestbambooList[k]] #竹番号はlestbambooList[k]に入っている
                lestbambooforC.remove(lestbambooList[k])
        if bamboocntB == 0: continue #0本だと駄目なので飛ばす

        for m in range(2**len(lestbambooforC)): #残った竹それぞれにつき取るか取らないか
        #このfor文終了1回につき、ABCそれぞれの組み合わせが1つ終了！
        # →このループの終了時にminの判定を行う
            lestbambooforCList = list(lestbambooforC) #やっぱりリスト化
            bamboocntC = 0
            nowsumC = 0
            for n in range(len(lestbambooforCList)):
                if m % (2**(n+1)) >= 2**n: #Cがとる場合
                    bamboocntC += 1
                    nowsumC += L[lestbambooforCList[n]] #竹番号はlestbambooListforC[n]に入っている
            if bamboocntC == 0: continue #0本だと駄目なので飛ばす

            nowTotalSum = necesMPforA + abs(B - nowsumB) + (bamboocntB-1)*10 + abs(C - nowsumC) + (bamboocntC-1)*10
            #minの判定！
            if nowTotalSum < min: min = nowTotalSum

print(min)

Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
using namespace std;
int a[4][4];
int main()
{
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	if(a[1][2]+a[2][1]==a[1][1]+a[2][2]&&a[1][3]+a[3][1]==a[1][1]+a[3][3]&&a[2][3]+a[3][2]==a[2][2]+a[3][3])
	printf("Yes");
	else
	printf("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define SZ(x) x.size()
#define POP __builtin_popcount
#define CLZ __builtin_clz
#define CTZ __builtin_ctx
constexpr int INF {INT_MAX};
constexpr float INFF {FLT_MAX};
constexpr long long INFL {LLONG_MAX};
#define float long double
#define int long long

main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.setf(ios::fixed);
	int n;
	cin>>n;
	set<string> s;
	while (n--){
		string t;
		cin>>t;
		s.insert(t);
	}
	cout<<SZ(s)<<"\n";
}



Measured memory_bytes: 19220
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int x = 1;
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (x != 0) {
    x = a[x-1];
    if (x == 2) {
      count = i+1;
      break;
    }
    }
    else {
      x = a[x-1];
    }
  }
  if (count!=0) {
    cout << count << endl;
  }
  else {
    cout << -1 << endl;
  }
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

class UnionFind {
private: vector<int> p, r;
public:
         int comp;
         UnionFind(int n) { r.assign(n, 0); p.resize(n); iota(ALL(p), 0); comp = n; }
         int findset(int i) { return (p[i] == i) ? i : (p[i] = findset(p[i])); }
         bool unionset(int i, int j) {
             int x = findset(i), y = findset(j);
             if (x != y) {
                 --comp;
                 if (r[x] > r[y]) p[y] = x;
                 else { p[x] = y; if (r[x] == r[y]) ++r[y]; }
                 return true;
             }
             return false;
         }
};


int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m; cin >> n >> m;
    int deg[n]; memset(deg, 0, sizeof deg);
    vector<ii> el;
    FOR(i, 0, m-1) {
        int a, b; cin >> a >> b;
        --a, --b;
        ++deg[a], ++deg[b];
        el.emplace_back(a, b);
    }

    string ans = "";
    int deg4 = 0, x = -1;
    FOR(i, 0, n-1) {
        if (deg[i]%2 == 1) { ans = "No"; break; }
        if (deg[i] >= 6) ans = "Yes";
        if (deg[i] == 4) ++deg4, x = i;
    }

    if (ans == "") {
        if (deg4 >= 3) ans = "Yes";
        else if (deg4 == 2) {
            UnionFind UF(n);
            for (auto e : el) {
                if (e.fi != x and e.sc != x)
                    UF.unionset(e.fi, e.sc);
            }
            
            if (UF.comp >= 3) ans = "Yes";
            else ans = "No";
        }
        else ans = "No";
    }
    cout << ans << '\n';
}



Measured memory_bytes: 2164
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

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

void fill(vector<string>& field, int x, int y)
{
	int color = field[y][x];
	field[y][x] = 0;
	
	rep(i, 4)
	{
		int nx = x + dx[i], ny = y + dy[i];
		
		if(0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] == color)
		{
			fill(field, nx, ny);
		}
	}
}

int main()
{
	while(cin >> H >> W && W)
	{
		vector<string> field(H);
		
		rep(i, H)
			cin >> field[i];
		
		int res = 0;
		rep(y, H) rep(x, W)
		{
			if(field[y][x] != 0)
			{
				fill(field, x, y);
				res++;
			}
		}
		
		cout << res << endl;
	}
}

Measured memory_bytes: 0
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

tem = make_divisors(n)

ln = len(tem)


if ln%2==0:
    result = (tem[int(ln/2-1)]-1)+(tem[int(ln/2)]-1)
else:
    result = (tem[int(ln//2)]-1)*2

print(result)

Measured memory_bytes: 39152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;

#define push push_back
#define make make_pair

void print2d(vector<vector< long long int>> a){
    int r=a.size();
    int c=a[0].size();
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
}

long long helper(vector<vector< long long int>>a, int target){
  int n=a.size();
  vector<vector<long long int>>dp(target+1,vector<long long int>(n,0));
  sort(a.begin(),a.end());
    if(target==0) return 0;
    if(target<a[0][0])  return 0;
    int idx=0;
    // print2d(a);
  for(int i=1;i<=target;i++){
    if(i%a[0][0]==0){
        idx=i;
        break;
    }
  }
    for(int i=idx;i<=target;i++){
        dp[i][0]=a[0][1];
    }


    for(int i=1;i<=target;i++){
        for(int j=1;j<n;j++){
            dp[i][j]=max(dp[i][j-1],( (i-a[j][0]>=0) ? (dp[i-a[j][0]][j-1] + a[j][1]) : 0 ));
        }
    }
    // print2d(dp);

  return dp[target][n-1];
}


int main(){
  int n;
   int k;
   cin>>n>>k;
   vector<vector<long long int >> a(n,vector<long long int>(2,0));
   for(int i=0;i<n;i++){
     cin>>a[i][0]>>a[i][1];
   }

    long long int res=helper(a,k);
  cout<<res<<endl;
}


Measured memory_bytes: 82304
#include<iostream>
#include<vector>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

bool prime[7000000];

int main(){
	rep(i,7000000)prime[i]=true;
	prime[0]=prime[1]=false;
	loop(i,2,10000){
		for(long long j=i*2;j<7000000;j+=i)prime[j]=false;
	}
	vector<long long> p;
	rep(i,7000000)if(prime[i])p.push_back(i);
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		long long sum=0;
		rep(i,n)sum+=p[i];
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 13564
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	ll x,y;
	cin >> x>>y;
	if ((x>=0&&y>0)||(x<0&&y<=0)){
		if (x<y) cout << y-x << endl;
		else cout << 2 + x - y << endl;
	}
	else {
		cout << 1 + abs(abs(x) - abs(y)) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    double in;
    cin >> in;
    cout  << fixed << setprecision(6)  << in* in * 3.14159265358979 << " " << in * 2 * 3.14159265358979 << endl;
    return 0;
}



Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
int n, r, t, p[109], d[109], c[1009];
int main() {
	cin >> n >> r >> t;
	for(int i = 0; i < n; i++) cin >> p[i], d[i] = p[i] % r;
	queue<pair<int, int> > que;
	int ret = 0;
	for(int i = 0; i < t; i++) {
		while(que.size() && que.front().first == i) {
			c[que.front().second]++; que.pop();
		}
		for(int j = 0; j < n; j++) {
			if(c[d[j]] == 0) ret++;
			else c[d[j]]--;
			d[j] = (d[j] + p[j]) % r;
			que.push(make_pair(i + 2, d[j]));
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
using namespace std;
inline int read(){
    int w=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        w=(w<<3)+(w<<1)+ch-48;
        ch=getchar();
    }
    return w*f;
}
int n,m,q,a[200010],b[200010],ans,vec[20010];
priority_queue<int> pq;
inline void work(){
    while(!pq.empty()){
        if(pq.size()>=m){
            vec[0]++;vec[vec[0]]=-pq.top();
        }
        pq.pop();
    }
}
signed main(){
    n=read();m=read();q=read();ans=INF;
    for(int i=1;i<=n;i++)a[i]=read();
    for(int i=1;i<=n;i++){
        int now=a[i];
        for(int j=1;j<=n;j++){
            if(a[j]>=now) pq.push(-a[j]);
            else work();
        }
        work();
        if(vec[0]>=1){
            sort(vec+1,vec+vec[0]+1);
        }
        if(vec[0]>=q&&vec[1]==now){
            ans=min(ans,vec[q]-now);
        }
        memset(vec,0,sizeof(vec));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}

signed main() {
  ios::sync_with_stdio(false);
  ll k, X, Y;
  cin >> k >> X >> Y;
  ll x = X, y = Y;
  int xs = (x >= 0) ? 1 : -1;
  int ys = (y >= 0) ? 1 : -1;
  x = x * xs;
  y = y * ys;
  if(k % 2 == 0 && (x+y) % 2 == 1) {
    cout << -1 << endl;
    return 0;
  }
  vector<ll> a, b;
  while(x > k && x + y > 2 * k) {
    x -= k;
    a.push_back(x);
    b.push_back(y);
  }
  while(y > k && x + y > 2 * k) {
    y -= k;
    a.push_back(x);
    b.push_back(y);
  }

  if(x + y != k) {
    bool swapped = false;
    if(x > y) {
      swapped = true;
      swap(x, y);
    }
    ll c = (-x + y) / 2;
    ll nx = x + c - k;
    ll ny = y - c;
    if(swapped) swap(nx, ny);
    a.push_back(nx);
    b.push_back(ny);
    x = nx;
    y = ny;
    if(abs(x) + abs(y) != k) {
      bool swapped = false;
      if(abs(x) > abs(y)) {
        swapped = true;
        swap(x, y);
      }
      ll ny = abs(y) - (k / 2 + 1);
      if(abs(y - ny) != k / 2 + 1) ny *= -1;
      ll nx = abs(x) + k / 2;
      if(abs(x - nx) != k / 2) nx *= -1;
      if(swapped) swap(nx, ny);
      x = nx;
      y = ny;
      a.push_back(x);
      b.push_back(y);
    }
  }
  a.push_back(0);
  b.push_back(0);
  cout << a.size() << endl;
  REP(i, a.size()) {
    cout << (abs(X) - a[i]) * xs << " " << (abs(Y) - b[i]) * ys << endl;
  }
  return 0; 
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back

#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto item : (x))
#define output_s(a) printf("%s\n",(a).c_str())

//library----------------------------------------------


int main(){
    ll a,b;cin>>a>>b;
    printf("%lld\n",(a%b==0?-1:a));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,sum=0,minn=9999999;
	cin>>n>>x;
	int a[n+2];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]<minn)minn=a[i];
		x-=a[i];
		sum++;
	}
	sum+=x/minn;
	cout<<sum;
	return 0;
}

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

int main(){
  ll n,m; cin >> n >> m;
  ll ret = n*(n-1)/2 + m*(m-1)/2;
  cout << ret;

}

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

int main () {
  int A,B,count = 0;
  cin >> A >> B;
  for (int i = A; i <= B; i++){
    int a,b,c,d;
    a = i % 10;
    b = (i / 10) % 10;
    c = (i / 1000) % 10;
    d = i / 10000;
    if (a + b * 10 == c * 10 + d)
      count++;
  }
  cout << count <<endl;
}

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

int main() {
	int counter[105], n;
	// printf("%d", sizeof(counter) / sizeof(*counter));
	for (int i = 0; i < sizeof(counter) / sizeof(counter[0]); i++) counter[i] = 0;
	
	for (int i = 0; i < 3; i++) {
		scanf("%d", &n);
		counter[n] = 1;
	}
	
	int count = 0;
	for (int val : counter) count += val;
	
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
int N,M;
typedef long long ll;
typedef pair<int,int> p;
#define NMAX 1000
vector<p> data;
ll dp[NMAX][NMAX];

int main(){
    string S;

    cin >> S;

    if(S=="Sunny") cout << "Cloudy" << endl;
    if(S=="Cloudy") cout << "Rainy" <<endl;
    if(S=="Rainy") cout << "Sunny" <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

#define MAX 100000

int main(){
  int n;
  int dist[100][100];
  scanf("%d",&n);
  REP(i,n){
    int k, m;
    scanf("%d%d",&k,&m);
    REP(j,n) dist[k-1][j] = MAX;
    dist[k-1][k-1] = 0;
    REP(j,m){
      int d;
      scanf("%d",&d);
      dist[k-1][d-1] = 1;
    }
  }

  REP(k,n) REP(i,n) REP(j,n)
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

  int m;
  scanf("%d",&m);
  REP(i,m){
    int a, b, c;
    scanf("%d%d%d",&a,&b,&c);
    if(dist[a-1][b-1] == MAX || dist[a-1][b-1] + 1 > c)
      puts("NA");
    else
      printf("%d\n",dist[a-1][b-1]+1);
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())
L_list = list(map(int, input().split()))

result = 0
ind = range(len(L_list))
for i_1 in ind:
  ind_2 = range(i_1 + 1, len(L_list))
  for i_2 in ind_2:
    ind_3 = range(i_2 + 1, len(L_list))
    for i_3 in ind_3:
      if (L_list[i_1] + L_list[i_2] > L_list[i_3]) and (L_list[i_1] + L_list[i_3] > L_list[i_2]) and (L_list[i_3] + L_list[i_2] > L_list[i_1]):
        if (L_list[i_1] != L_list[i_2]) and (L_list[i_3] != L_list[i_2]) and (L_list[i_1] != L_list[i_3]): 
          result += 1
print(result)

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

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

constexpr long long inf = 1000006;

int main(){
    int n; cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    vector<pii> ans;
    ll mx = 0 , mn = inf;
    int mxi,mni;
    for(int i=0;i<n;i++){
        if(a[i] > mx){
            mx = a[i];
            mxi = i;
        }
        if(a[i] < mn){
            mn = a[i];
            mni = i;
        }
    }

    if(abs(mx) > abs(mn)){
        for(int i=0;i<n;i++){
            if(mxi == i) continue;
            ans.emplace_back(mxi,i);
        }
        for(int i=0;i<n-1;i++){
            ans.emplace_back(i,i+1);
        }
    }else{
        for(int i=0;i<n;i++){
            if(mni == i) continue;
            ans.emplace_back(mni,i);
        }
        for(int i=n-1;i>0;i--){
            ans.emplace_back(i,i-1);
        }
    }
    cout << ans.size() << endl;
    for(pii p : ans){
        cout << p.first+1 << " " << p.second+1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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


int main() {
    int n,k;
cin>>n>>k;
int a[n];
REP(i,n) cin>>a[i];
sort(a,a+n);

//REP(i,n) cout<<a[i]<<endl;
int m =a[k-1]-a[0];
REP(i,n-k+1) {m=min(m,a[i+k-1]-a[i]);}

cout<<m<<endl;

}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  long A,B,M;cin>>A>>B>>M;
  vector<long>a(A),b(B);
  for(long i=0;i<A;i++)cin>>a[i];
  for(long i=0;i<B;i++)cin>>b[i];
  vector<long>x(M),y(M),c(M);
  for(long i=0;i<M;i++)cin>>x[i]>>y[i]>>c[i];
  
  long ma=LONG_MAX,mb=LONG_MAX;
  for(long i=0;i<A;i++)ma=min(ma,a[i]);
  for(long i=0;i<B;i++)mb=min(mb,b[i]);
  long ans=ma+mb;
  for(long i=0;i<M;i++){
    ans=min(ans,a[x[i]-1]+b[y[i]-1]-c[i]);
  }
  cout<<ans;
  
  
  
}

Measured memory_bytes: 4224
N, K = tuple(map(int, input().split()))
num = [0] * K
for i in range(1, N+1):
    num[i % K] += 1
res = 0
for a in range(K):
    b = (K - a) % K
    c = (K - a) % K
    if (b + c) % K != 0:
        continue
    res += num[a] * num[b] * num[c]
print(res)

Measured memory_bytes: 4596
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int a,b,c;
    cin>>a>>b>>c;
    cout<<((c>a-b)?(c-a+b):0)<<endl;
    return 0;
}



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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);
int dp[MX],h[MX],pre[MX];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>h[i];
	fill(dp,dp+n,INF);
	dp[0]=0;
	for(int i=0;i<n;i++){
		dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
		dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include<iomanip>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>

i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

i64 cup(i64 xxx, i64 yyy) {//切り上げ
	return (xxx + yyy - 1) / yyy;
}

//メモリ置き場
string s,t;
int a, b;
string u;


//inputします
void input() {
	cin >> s >> t >> a >> b >> u;
}

//ライブラリ置き場

//main
int main() {
	input();
	if (s == u)a--;
	if (t == u)b--;
	cout << a <<" "<< b;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))


count = 0
l = 0
while count <= n:
    l = a[l]-1
    count += 1
    if l == 1:
        break

if l == 1:
    print(count)
else:
    print("-1")

Measured memory_bytes: 51288
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 2e5 + 5, MOD = 1e9 + 7;
ll fac[N], inv_fac[N];

ll bp(ll a, ll p) {
    ll r = 1;
    while (p > 0) {
        if (p & 1) {
            r = r * a % MOD;
        }
        p >>= 1;
        a = a * a % MOD;
    }
    return r;
}

ll c(int n, int k) {
    return fac[n] * inv_fac[n - k] % MOD * inv_fac[k] % MOD;
}

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

    fac[0] = 1;
    inv_fac[0] = 1;

    for (int i = 1; i < N; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv_fac[i] = bp(fac[i], MOD - 2);
    }

    int b, w;
    cin >> b >> w;
    b--;

    ll sum = 0, inv_two = bp(2, MOD - 2), anime = 1;

    int l = 0, r = 0;

    for (int i = 0; i <= b + w; i++) {
        int nl = max(0, i - b), nr = min(w - 1, i);

        while (l < nl) {
            anime = (anime - c(i, l) + MOD) % MOD;
            l++;
        }
        while (r < nr) {
            r++;
            anime = (anime + c(i, r) + MOD) % MOD;
        }


        ll ans = (sum + anime * bp(inv_two, i + 1)) % MOD;

        cout << ans << "\n";

        if (i >= w - 1 && i - w + 1 <= b) {
            sum = (sum + c(i, w - 1) * bp(inv_two, i + 1)) % MOD;
        }

        anime = (anime * 2 - c(i, r) + MOD) % MOD;

        if (l > 0)
            anime = (anime + c(i, l - 1));
    }



    return 0;
}

Measured memory_bytes: 5376
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<double,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll D;
    cin >> D;
    vector<double> c(27,0);
    for(ll i=0;i<26;++i)cin>>c[i+1];
    vector<vector<double>> S(D+1, vector<double>(27, 0));
    for(ll i=0;i<D;++i)
        for(ll j=0;j<26;++j)cin>>S[i+1][j+1];
    ll Maxscore=-INF;
    vl ans;
    for(double k=-1.0;k<=50;k+=0.02){
        vector<ll> last(27,0);
        ll score=0;
        vector<ll> t(D+1,0);
        for(ll i=1;i<=D;++i){
            ll mark;
            double Max=-2000000000;
            for(ll j=1;j<=26;++j){
                if(chmax(Max,S[i][j]+c[j]*(min(k,(double)D-i))))mark=j;
            }
            t[i]=mark;
            last[t[i]]=i;
            score+=S[i][t[i]];
            for(ll j=1;j<=26;++j)score-=c[j]*(i-last[j]);
        }
        if(chmax(Maxscore,score))ans=t;
    }
    for(double k=-1.0;k<=200;k+=0.02){
        vector<ll> last(27,0);
        ll score=0;
        vector<ll> t(D+1,0);
        for(ll i=1;i<=D;++i){
            ll mark;
            double Max=-2000000000;
            for(ll j=1;j<=26;++j){
                if(chmax(Max,S[i][j]+c[j]*k))mark=j;
            }
            t[i]=mark;
            last[t[i]]=i;
            score+=S[i][t[i]];
            for(ll j=1;j<=26;++j)score-=c[j]*(i-last[j]);
        }
        if(chmax(Maxscore,score))ans=t;
    }
    for(double k=-1.0;k<=100;k+=0.02){
        vector<ll> last(27,0);
        ll score=0;
        vector<ll> t(D+1,0);
        for(ll i=1;i<=D;++i){
            ll mark;
            double Max=-2000000000;
            for(ll j=1;j<=26;++j){
                if(chmax(Max,S[i][j]+c[j]*(i-last[j])*k))mark=j;
            }
            t[i]=mark;
            last[t[i]]=i;
            score+=S[i][t[i]];
            for(ll j=1;j<=26;++j)score-=c[j]*(i-last[j]);
        }
        if(chmax(Maxscore,score))ans=t;
    }
    for(ll i=1;i<=D;++i)prt(ans[i]);

    return 0;
}



Measured memory_bytes: 3948
#include<iostream>
#include<queue>
#include<utility>
using namespace std;

typedef pair<int,int> P;

int main(){
  int w,h;
  bool vw[50][50],pw[50][50];
  int grid[50][50];

  while(cin >> w >>h , w||h){
    for(int i=0;i<h;i++){
      for(int j=0;j<w-1;j++)cin >> vw[i][j];
      if(i!=h-1)for(int j=0;j<w;j++)cin >> pw[i][j];
    }

    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)grid[i][j] = 0;
    
    grid[0][0] = 1;
    queue<P> q;
    q.push(P(0,0));

    while(q.size()){
      P p = q.front(); q.pop();
      int y = p.first, x = p.second;

      if(y==h-1 && x==w-1)break;

      if(0<=y-1 && !pw[y-1][x] && !grid[y-1][x]){
	grid[y-1][x] = grid[y][x]+1;
	q.push(P(y-1,x));
      }
      if(0<=x-1 && !vw[y][x-1] && !grid[y][x-1]){
	grid[y][x-1] = grid[y][x]+1;
	q.push(P(y,x-1));
      }
      if(y+1<h && !pw[y][x] && !grid[y+1][x]){
	grid[y+1][x] = grid[y][x]+1;
	q.push(P(y+1,x));
      }
      if(x+1<w && !vw[y][x] && !grid[y][x+1]){
	grid[y][x+1] = grid[y][x]+1;
	q.push(P(y,x+1));
      }
    }
    cout << grid[h-1][w-1] << endl;
  }
}

Measured memory_bytes: 924
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n ,k;
  cin >> n >> k;
  vector<int> vec(n);
  
  for(int i = 0; i < n; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  int S = 0;
  for(int i = 0; i < k; i++){
    S += vec.at(i);
  }
  cout << S << endl;
}
  

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	vector<vector<int>> G(n);
	int ans = 0;
	rep(i,m){
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i,n){
		bool ok = true;
		for(auto nv : G[i]){
			if(h[i] <= h[nv]) ok = false;
		}
		if(ok) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8708