akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N;
	int ans = 0;
	vector<int> A, B;
	
	cin>>N;
	
	A.resize(N);
	B.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		B[i] = -(i+A[i]);
		A[i] -= i;
	}
	
	sort(B.begin(), B.end());
	
	for(int i = 0; i < N; i++){
		ans += upper_bound(B.begin(), B.end(), A[i]) - lower_bound(B.begin(), B.end(), A[i]);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 6328
object Main {
  def main(args:Array[String]): Unit = {
    Iterator.continually(readLine())
      .map(s => {
        val xs = s.split(" ").map(_.toInt)  
        (xs(0), xs(1))
      })
      .takeWhile{
        case (0,0) => false
        case _ => true
      }
      .foreach(xs => {
        val h = xs._1
        val w = xs._2
       
        var st = ""
        for (i <- 1 to h){
          if (i % 2 == 0) st += getChessboard(1 to w)("#")(".") + "\n"
          else st += getChessboard(1 to w)(".")("#") + "\n"
        }
        println(st)
      })
  }

  def getChessboard(r:Range)(even:String)(odd:String): String = {
    r.foldLeft(""){
        case (a, i) if (i % 2 == 0) => a + even 
        case (a, _) => a + odd
    }
  }
}

Measured memory_bytes: 118140
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<string>
#define MOD 998244353
#define INF 0x3f3f3f3f
#define eps 1e-4
#define N 210000
#define NUM 2000000
#define CHILD 29
#define DINF 99999999999.9
const double PI=acos(-1.0);
using namespace std;
typedef long long LL;
typedef pair<int,int > P;
int main()
{
	int i,j,n,m,a,b,c,d,cnt=0;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(i=0;i<=100;i++)
	{
		if(i>=a&&i<=b&&i>=c&&i<=d)
			cnt++;
	}
	cnt--;
	printf("%d\n",cnt<0?0:cnt);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

char str1[10];
char str2[1000];

int main() {
#ifdef TEST
    freopen("input", "r", stdin);
#endif

    scanf("%s", str1);
    int len1 = strlen(str1);

    for (int k = 0; k < len1; ++k) {
        if (str1[k] >= 'a') str1[k] -= ('a' - 'A');
    }
    int sum = 0;
    while (scanf("%s", str2)) {
        if(strcmp("END_OF_TEXT", str2) == 0) break;
        int len2 = strlen(str2);
        if(len2 < len1 || len2 > len1) continue;
        for (int i = 0; i <= len2 - len1; ++i) {
            if (str2[i] >= 'a') str2[i] -= ('a' - 'A');
            if(str2[i] == str1[0]) {
                int j = 0;
                for (; j < len1; ++j) {
                    if (str2[i + j] >= 'a') str2[i + j] -= ('a' - 'A');
                    if(str1[j] != str2[j + i]) break;
                }
                if (j == len1) {
                    sum++;
                    break;
                }
            }
        }
        memset(str2, 0x0, sizeof(str2));
    }
    printf("%d\n", sum);
    return 0;
}



Measured memory_bytes: 2068
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

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

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


int main(){
    string O, E;
    int i;
    cin >> O >> E;
    for(i = 0; i < E.length(); i++){
        cout << O[i] << E[i];
    }
    if(E.length() != O.length()) cout << O[i];
    cout << endl;
    return 0;
}




Measured memory_bytes: 3552
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input {(source=$s:expr,$($r:tt)*) => {let mut iter=$s.split_whitespace(); let mut next=||{iter.next().unwrap()}; input_inner! {next,$($r)*}};($($r:tt)*) => {let stdin=std::io::stdin();let mut bytes=std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next=move||->String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()}; input_inner! {next,$($r)*}};}
#[allow(unused_macros)]
macro_rules! input_inner {($next:expr) => {}; ($next:expr,) => {}; ($next:expr,$var:ident:$t:tt$($r:tt)*) => {let $var=read_value!($next,$t); input_inner! {$next$($r)*}};}
#[allow(unused_macros)]
macro_rules! read_value {($next:expr,($($t:tt),*)) => {($(read_value! ($next,$t)),*)}; ($next:expr, [$t:tt; $len:expr]) => {(0..$len).map(|_|read_value! ($next,$t)).collect::<Vec<_>>()}; ($next:expr,chars) => {read_value! ($next,String).chars().collect::<Vec<char>>()}; ($next:expr,usize1) => {read_value! ($next,usize)-1}; ($next:expr,$t:ty) => {$next().parse::<$t>().expect("Parse error")};}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX: usize = 100006;
#[allow(dead_code)]
const INF_U32: u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32: i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64: u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64: i64 = 1 << 62;
#[allow(dead_code)]
const MOD: i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{k:i64, s:i64};
    let mut ans = 0i64;
    for x in 0..k+1 {
        for y in 0..k+1 {
            let z = s - x - y;
            //debug!(x,y,z);
            if 0 <= z && z <= k {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		TreeSet<Integer> set=new TreeSet<>();
		int n=in.nextInt();
		for(int i=0;i<n;i++) {
			set.add(in.nextInt());
		}
		
		int m=in.nextInt();
		PrintWriter out=new PrintWriter(System.out);
		for(int i=0;i<m;i++) {
			int obj=in.nextInt();
			if(set.contains(obj))out.println(obj);
		}
		out.flush();
	}

}



Measured memory_bytes: 149404
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#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)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n, m; cin >> n >> m;
	vector<LL> x(n);
	vector<LL> y(n);
	vector<LL> z(n);

	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> z[i];
	}
	LL ans = -1e15;
	for (int msk = 0; msk < (1<<3); msk++) {
		
		vector<LL> temp(n);
		for (int i = 0; i < n; i++) {
			LL buf = 0;
			if ((msk >> 0) % 2 == 1) {
				buf += x[i];
			}
			else {
				buf -= x[i];
			}

			if ((msk >> 1) % 2 == 1) {
				buf += y[i];
			}
			else {
				buf -= y[i];
			}

			if ((msk >> 2) % 2 == 1) {
				buf += z[i];
			}
			else {
				buf -= z[i];
			}

			temp[i] = buf;
		}

		sort(temp.rbegin(), temp.rend());

		LL sum = 0;

		for (int j = 0; j < m; j++) {
			sum += temp[j];
		}

		ans = max(ans, sum);
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(container) container.begin(), container.end()
#define RevRange(container) container.rbegin(), container.rend()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
using namespace std;
using ll = long long;

int main(void){
    Cin(int, n);
    if(n == 2){
        Cin(int, a);
        Cin(int, b);
        Cout(a != b ? 0 : 1);
        return 0;
    }
    vector<pair<int,int>> c1(100001), c2(100001);
    For(i, 100001) c1[i].second = c2[i].second = i;
    
    
    For(i, n/2){
        Cin(int, a1);
        Cin(int, a2);
        c1[a1].first ++;
        c2[a2].first ++;
    }
    sort(RevRange(c1));
    sort(RevRange(c2));

    int ans = (c1[0].second != c2[0].second) ? n - c1[0].first - c2[0].first : min(n - c1[1].first - c2[0].first, n - c1[0].first - c2[1].first);
    Cout(ans);

}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

vector<long long> enumDivisor(long long n) {
    vector<long long> res;
    for (long long i = 1; i*i <= n; i++) {
        if (n%i) continue;
        res.push_back(i);
        if (i*i != n) res.push_back(n/i);
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    auto f = enumDivisor(m);
    ll ans = 0;
    for (ll x : f) {
        if (x * n <= m) chmax(ans, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) R a[i];
  sort(a,a+n,greater<ll>());
  ll ans=0;
  REP(i,m,n) ans+=a[i];
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    map<char, ll> count;

    string MARCH = "MARCH";
    for (int i = 0; i < 5; ++i) count[MARCH[i]] = 0;

    for (int i = 0; i < N; ++i) {
        string S;  cin >> S;
        count[S[0]] += 1;
    }

    // conbinations
    int first[10]  = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
    int second[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
    int third[10]  = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

    long long res = 0;
    for (int i = 0; i < 10; ++i) res += count[MARCH[first[i]]] * count[MARCH[second[i]]] * count[MARCH[third[i]]];
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    string s;
    cin >> s;
    string ans = "";
    for(int i = 0; i < s.length(); i++) {
        if(s[i] == 'B') {
            if(ans.length() == 0) continue;
            ans.pop_back();
        } else {
            ans.push_back(s[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
1e5。
全通りは試せない
sortして累積和で比較
40 1 30 2 7 20
1 2 7 20 30 40
1 3 10 30 60 100
越えられない壁3-7があれば、それ以下は死亡
*/
int main(){
  ll N; cin>>N;
  vector<ll> A(N+1,0), B(N+1,0);
  for(int i=1; i<=N; i++){
    ll a; cin>>a;
    A[i]=a;
  }
  sort(A.begin(), A.end());
  for(int i=1; i<=N; i++){
    B[i]=B[i-1]+A[i];
  }
  ll ans=1;
  for(int i=1; i<N; i++){//累積和の2倍が次のAに届くかどうか
    if (B[i]*2<A[i+1]) ans=1;
    else ans++;
  }
  cout<<ans<<endl;
}

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

int main()
{
    int N , M ,C;
    cin >> N >> M >> C;
    int B[M],a[N][M];
    rep(i,M) cin >> B[i];
    rep(i,N){
        rep(j,M) cin >> a[i][j];
    }

    int n =0;
    rep(i,N){
        int x = C;
        rep(j,M){
            x = x + a[i][j] * B[j];
        }

        if (x>0)n+=1;
    }

    cout << n;

    return 0;
}

Measured memory_bytes: 256
"""
n = 1
while n**5 < 10**9:
  n += 1
print(n)
# 64
"""
X = int(input())

for a in range(-128,128):
    for b in range(-128,128):
        if a ** 5 - b ** 5 == X:
            print(a, b)
            exit()

Measured memory_bytes: 9164
#include <iostream>

using namespace std;

int main(){
	long long n, m;
	while (1){
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		long long dp[11] = { 0 };
		long long d, p;
		for (int i = 0; i < n; i++){
			cin >> d >> p;
			dp[p] += d;
		}
		long long sum = 0;
		for (int i = 10; i >= 0; i--){
			if (i != 0 && m != 0){
				int x = m - dp[i];
				if (x < 0){
					x *= -1;
					dp[i] = x;
					m = 0;
				}
				else{
					m -= dp[i];
					dp[i] = 0;
				}
			}
			sum += dp[i] * i;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

ll find(ll x, vector<ll> &par){
    if(par.at(x)==x){
        return x;
    }else{
        return par.at(x)=find(par.at(x), par);
    }
}

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> A(M),B(M);
    
    vector<ll> par(N), rank(N), size(N);
    for(ll i=0; i<N; i++){
        par.at(i)=i;
        rank.at(i)=0;
      	size.at(i)=1;
    }

    for(ll i=0; i<M; i++){
        cin >> A.at(i) >> B.at(i);
        ll x=find(A.at(i)-1,par);
        ll y=find(B.at(i)-1,par);
        if(x!=y){
        if(rank.at(x)<rank.at(y)){
            par.at(x)=par.at(y);
            size.at(x)+=size.at(y);
      	    size.at(y)=size.at(x);
        }else{
            par.at(y)=par.at(x);
            if(rank.at(x)==rank.at(y)) rank.at(x)++;
            size.at(x)+=size.at(y);
      	    size.at(y)=size.at(x);
        }
        }
    }
    ll maxsize=0;
    for(ll i=0; i<N; i++){
      	ll x=find(i,par);
        ll a=size.at(x);
        if(a>maxsize) maxsize=a;
    }
    cout << maxsize;
}

Measured memory_bytes: 11180
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;
 
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

//最大公約数
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}

//最小公倍数
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}

typedef long long ll;

int mini[1001];

int main(){
	char a, b;
	
	scanf("%c %c", &a, &b);
	
	if (a == 'H'){
		if (b == 'H') cout << "H" << endl;
		if (b == 'D') cout << "D" << endl;
	}
	if (a == 'D'){
		if (b == 'H') cout << "D" << endl;
		if (b == 'D') cout << "H" << endl;
	}
	
	return 0;
}

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

void solve(){
    ll n;
    string s;
    cin >> n;
    cin >> s;
    bool dp[n+1][4][1000] = {};
    dp[0][0][0] = true;
    for(ll i=0; i < n; i++){
        for(ll j=0; j < 3; j++){
            for(ll k=0; k < 100; k++){
                if(dp[i][j][k]){
                    int num = k * 10 + int(s[i] - '0');
                    dp[i+1][j+1][num] = true;
                }
            }
        }
        for(ll j=0; j < 4; j++){
            for(ll k=0; k < 1000; k++){
                if(dp[i][j][k]) dp[i+1][j][k] = true;
            }
        }
    }
    ll cnt = 0;
    for(ll k=0; k < 1000; k++){
        if(dp[n][3][k]) cnt++;
    }
    cout << cnt << "\n";
}

int main(){
    solve();
}

Measured memory_bytes: 117504
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
P = list(map(int,input().split()))

for i in range(N):
    if P[i] != i+1:
        j = P.index(i+1)
        P[i],P[j] = P[j],P[i]
        break

print("YES" if P == list(range(1,N+1)) else "NO")

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int r, D, x;
  cin >> r >> D >> x;
  for(int i=0; i<10; i++){
    x = x*r-D;
    cout << x << endl;
  }
  return 0;
}

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

maxv = -2 * 10**9
minv = r[0]

for i in range(1, n):
    maxv = max(maxv, r[i]-minv)
    minv = min(minv, r[i])

print(maxv)


Measured memory_bytes: 13592
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define PI 3.141592653589793
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M;
  cin >> N >> M;
  vvll G(N, vll(0));
  vll num(N, -1);
  for(int i = 0; i < M; i++){
    ll A, B;
    cin >> A >> B;
    A--; B--;
    G.at(A).push_back(B); G.at(B).push_back(A);
  }
  queue<ll> que;
  que.push(0);

  while(!que.empty()){
    ll v = que.front();
    que.pop();
    for(int i = 0; i < G.at(v).size(); i++){
      ll next = G.at(v).at(i);
      if(num.at(next) != -1) continue;
      num.at(next) = v + 1;
      que.push(next);
    }
  }
  cout << "Yes" << endl;
  for(int i = 1; i < N; i++){
    cout << num.at(i) << endl;
  }
}

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

string field[8];

bool ch(int i,int j)
{
	if(field[i][j] == '1') return true;
	return false;
}

bool Check_A(int i,int j)
{
	if(i+1 < 8 && j+1 < 8)
	{
		if(ch(i,j) && ch(i+1,j) && ch(i,j+1) && ch(i+1,j+1))  return true;
	}
	return false;
}

bool Check_B(int i,int j)
{
	if(i+1 < 8 && i+2 < 8 && i+3 < 8)
	{
		if(ch(i,j) && ch(i+1,j) && ch(i+2,j) && ch(i+3,j)) return true;
	}
	return false;
}

bool Check_C(int i,int j)
{
	if(j+1 < 8 && j+2 < 8 && j+3 < 8)
	{
		if(ch(i,j) && ch(i,j+1) && ch(i,j+2) && ch(i,j+3)) return true;
	}
	return false;
}

bool Check_D(int i,int j)
{
	if(j-1 >= 0 && i+1 < 8 && i+2 < 8)
	{
		if(ch(i,j) && ch(i+1,j) && ch(i+1,j-1) && ch(i+2,j-1)) return true;
	}
	return false;
}

bool Check_E(int i,int j)
{
	if(i+1 < 8 && j+1 < 8 && j+2 < 8)
	{
		if(ch(i,j) && ch(i,j+1) && ch(i+1,j+1) && ch(i+1,j+2)) return true;
	}
	return false;
}

bool Check_F(int i,int j)
{
	if(i+1 < 8 && i+2 < 8 && j+1 < 8)
	{
		if(ch(i,j) && ch(i+1,j) && ch(i+1,j+1)&& ch(i+2,j+1)) return true;
	}
	return false;
}

bool Check_G(int i,int j)
{
	if(i+1 < 8 && j+1 < 8 && j-1 >= 0)
	{
		if(ch(i,j) && ch(i+1,j) && ch(i,j+1) && ch(i+1,j-1)) return true;
	}
	return false;
}

int main()
{
	while(cin >> field[0])
	{
		for(int i=1;i<8;i++)
		{
			cin >> field[i];
		}
		
		bool flag = true;
		for(int i=0;i<8;i++)
		{
			for(int j=0;j<8;j++)
			{
				if(Check_A(i,j) && flag)
				{
					cout << "A" << endl;
					flag = false;
				}

				if(Check_B(i,j) && flag)
				{
					cout << "B" << endl;
					flag = false;
				}

				if(Check_C(i,j) && flag)
				{
					cout << "C" << endl;
					flag = false;
				}

				if(Check_D(i,j) && flag)
				{
					cout << "D" << endl;
					flag = false;
				}				

				if(Check_E(i,j) && flag)
				{
					cout << "E" << endl;
					flag = false;
				}

				if(Check_F(i,j) && flag)
				{
					cout << "F" << endl;
					flag = false;
				}

				if(Check_G(i,j) && flag)
				{
					cout << "G" << endl;
					flag = false;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>
void swap(int *first, int *second)
{
    int temp = *first;
    *first = *second;
    *second = temp;
}
void quick_sort(int *arr, int l, int r)
{
    if(l >= r)
        return ;
    int x = arr[l], i = l - 1, j = r + 1;
    while(i < j)
    {
        do i++; while(arr[i] < x);
        do j--; while(arr[j] > x);
        if(i < j)
            swap(&arr[i], &arr[j]);
    }
    quick_sort(arr, l, j);
    quick_sort(arr, j + 1, r);
}
int main()
{
	int n;
	scanf("%d",&n);
	int arr[200005];
	for(int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
	}
	quick_sort(arr,0,n-1);
	int j;
	for(j=0;j<n-1;j++)
	{
		if(arr[j]==arr[j+1])
		{
			printf("NO\n");
			break;
		}
	}
	if(j==n-1)
	printf("YES\n");
	return 0;
}

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

constexpr int MOD = 1000000007;
 // constexpr int MOD = 998244353;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<long> R(N + 1);
  for (int i = 1; i < N + 1; i++) {
    R.at(i) = R.at(i - 1) + A.at(i - 1);
  }
  long ans = 0;
  for (int i = 0; i < N; i++) {
    long tmp = R.at(N) - R.at(i + 1);
    tmp %= MOD;
    tmp *= A.at(i);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 5572
($n,$a,$b,$c)=glob<>;@l=<>;$y=1e9;for$p(0..4**$n){@s=0 x4;$k=30;$s[$p%4]+=$l[$_],$k-=$p%4&&10,$p/=4for 0..$n;$x=abs($s[1]-$a)+abs($s[2]-$b)-$k+abs$s[3]-$c,$x<$y&&($y=$x),if$s[1]*$s[2]*$s[3]}print$y

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define int long long int
#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define pb push_back
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define DEBUG false
#pragma GCC optimize "trapv"

using namespace std;

void solve(double a[],int n)
{
    double dp[n+1][n+1];
    memset(dp,0.0,sizeof(dp));
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i;++j)
        {
            if(j==0)
            {
                dp[i][j]=dp[i-1][j]*(1.0-a[i]);
            }
            else
            dp[i][j]=(dp[i-1][j-1]*a[i])+(dp[i-1][j]*(1.0-a[i]));
        }
    }
    double ans=0.0;
    for(int i=(n+1)/2;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    cout<<setprecision(10)<<fixed<<ans;
}

int32_t main()
{
    nitro;
    int n;
    cin>>n;
    double a[n];
    for(int i=1;i<=n;i++)
    cin>>a[i];
    solve(a,n);
return 0;
}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using mii = std::map<int, int>;
using mll = std::map<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = 2*(int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
//const int dc[4] = {1, -1, 0,  0};
//const int dr[4] = {0,  0, 1, -1};
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T, typename U, typename V> inline
ostream& operator<<(ostream &o, tuple<T,U,V> &p)
{
    return o << "{" << get<0>(p) << "," << get<1>(p) << "," << get<2>(p) << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n;
    cin >> n;
    
    map<string, int> mp;

    irep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    
    string s[4] = {"AC","WA","TLE","RE"};

    irep(i, 4) {
        cout << s[i] << " x " << mp[s[i]] << endl;
    }
    return 0;
}

/*atcoder*/


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


int main() {
    string A,B,C;cin >> A >> B >> C;
    string a,b,c;
    a = A.at(0);
    b = B.at(0);
    c = C.at(0);
    cout << a+b+c << endl;

}       

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

using namespace std;

const int MAXN = 100001;
const int MAXK = 101;

int N,table[MAXN][3],dp[MAXN][3];

int main(){
	#ifdef EVAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	cin >> N;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 3; j++){
			cin >> table[i][j];
		}
	}
	for(int i = 0; i < 3; i++){
		dp[0][i] = table[0][i];
	}
	for(int i = 1; i < N; i++){
		for(int s = 0; s < 3; s++){
			int res = 0;
			for(int j = 0; j < 3; j++){
				if(j == s)continue;
				res = max(res,dp[i - 1][j]);
			}
			dp[i][s] = res + table[i][s];
		}
	}
	int res = 0;
	for(int i = 0; i < 3; i++){
		res = max(res,dp[N - 1][i]);
	}
	cout << res;
}

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

int main() {
  int w;
  while(cin >> w) {
    for(int i = 0, cnt = 0; w; ++i) {
      if(w & (1<<i)) {
	if(cnt) cout << " ";
	++cnt;
	cout << (1<<i);
	w &= ~(1<<i);
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>
#include<map>


#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 ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
typedef pair<ll,ll> LL_LLP;
#define INF 1000000007
#define MAX_H 100005

int main(){

    ll h,w,n,x,y;
    cin >> h >> w >> n;
    vector<P> arr;
    REP(i,n){

        cin >> x >> y;
        x--;
        y--;
        for(ll j = 0;j <= 2;j++){
            for(ll k = 0;k <= 2;k++){
                ll nx = x-j;
                ll ny = y-k;
                if(nx >= 0 && nx+2 < h && ny >= 0 && ny+2 < w){
                    arr.push_back(make_pair(nx,ny));
                }
            }
        }
    }
    /*正方形としてありうるものの左上の頂点を列挙*/

    map<P,ll> mp;
    map<P,ll>::iterator itr;
    ll black = 0;

    REP(i,arr.size()){
        mp[arr[i]]++;
    }

    vector<ll> ans(10,0);
    for(itr = mp.begin();itr != mp.end();itr++){
        ans[itr->second]++;
        black++;
    }
    ans[0] = (h-2)*(w-2) - black;
    REP(i,10){
        cout << ans[i] << endl;
    }

return 0;
}        

Measured memory_bytes: 64232
count = 0

S = [int(input()) for i in range(4)]
for i in range(S[0] + 1):
  for j in range(S[1] + 1):
    for k in range(S[2] + 1):
      if i * 500 + j * 100 + k * 50 == S[3]:
        count += 1
print(count)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String t = sc.nextLine();
        sc.close();
        if(s.length()+1==t.length()){
            String tSubstr = t.substring(0,s.length());
            if(s.equals(tSubstr)){
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35724
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    map <int, int> l;
    multiset <int> ans;
    for (int i = 1; i <= m; ++i)
    {
        l[i] = i;
        ans.emplace(0);
    }
    /*
        for (auto& i : l)
        {
            cout << i.second << '\t' << i.first << endl;
        }
    */
    for (int i = 1; i <= n; ++i)
    {
        int a, b;
        cin >> a >> b;
        ++b;
        auto it = l.lower_bound(a);
        int r = -1;
        for (; it != l.end() && it->first <= b; it = l.erase(it))
        {
            ans.erase(ans.find(it->first - it->second));
            r = max(r, it->second);
        }
        if (r != -1 && b <= m)
        {
            l[b] = r;
            ans.emplace(b - r);
        }
        cout << (ans.empty() ? -1 : *ans.begin() + i) << endl;
        /*
        cout << r << endl;
        for (auto& i : l)
        {
            cout << i.second << '\t' << i.first << endl;
        }
        cout << endl;
        */
    }
}

Measured memory_bytes: 22376
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
#define mx 500001
using namespace std;
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define mkp make_pair
//#define d double
void solve(){
	ll n,k;
	cin>>n>>k;
	vl vec(n);
	rep(i,0,n) cin>>vec[i];
	vl pre(n+1);
	for(int i=1;i<=n;i++) pre[i]=pre[i-1]+vec[i-1];
	for(int i=1;i<=n;i++) pre[i]=(pre[i]-i)%k;
	ll ans=0;
	k=min(n+1,k);
	map<int,int> mp;
	for(int i=n;i>=n-k+1;i--) mp[pre[i]]++;
	for(int i=n;i>=1;i--){
		mp[pre[i]]--;
		if(i>=k){
			ans+=mp[pre[i]];
			mp[pre[i-k]]++;
		}
		else{
			ans+=mp[pre[i]];
		}
	}
	cout<<ans;
		
	
	
	
	
	
}
int32_t main(){
FIO;
int t=1;
//cin>>t;
while(t--){
	solve();
}
}

Measured memory_bytes: 12800
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<29)
#define LLINF (1LL<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (b + c >= a)cout << b + c - a;
    else cout << 0;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main
{
	public static void main(String[] arg) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		char[] s = br.readLine().toCharArray();
		
		int N = s.length;
		for(int i=0; i<N/2; i++){
			char temp = s[i];
			s[i] = s[N-i-1];
			s[N-i-1] = temp;
		}

		System.out.println(s);
	}
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  int n;
  cin>>n;
  vector<pair<int,int>> a;
  rep(i,n){
    int x,l;
    cin>>x>>l;
    a.pb(make_pair(x+l,x-l));
  }
  sort(all(a));
  int fin=-INF,ans=0;
  rep(i,n){
    if(a[i].second>=fin) {
      fin=a[i].first;
      ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2420
from collections import defaultdict


def divide(n):  # unsort
    ans = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            ans.append(i)
            if n // i == i:
                continue
            ans.append(n // i)
    return ans


def calc(n, k):
    if k == 1:
        return False
    if n % k == 0:
        n //= k
        if n == 1:
            return True
        return calc(n, k)
    if n % k == 1:
        return True
    else:
        return False


n = int(input())
ans = 0
kouho = []
kouho += divide(n)
kouho += divide(n - 1)
kouho = set(kouho)
cnt = 0
for num in kouho:
    if calc(n, num):
        cnt += 1
print(cnt)


Measured memory_bytes: 4340
#include <stdio.h>

#define NMAX 1000
#define WMAX 10000

int mincost(short *, int, int);

int main(void)
{
	int i, j, n, d, wtemp, wmin=WMAX, cost=0;
	short w[NMAX], s[NMAX], l[NMAX];
	char c[WMAX+1]={0}, flag[NMAX]={0};
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%d",&w[i]);
		if (wmin > w[i]) wmin = w[i];
		c[w[i]]++;
	}
	j=0;
	for (i=0; i<=WMAX; i++) {
		if(c[i]) {
			s[j] = i;
			j++;
		}
	}
	
	for (i=0; i<n; i++) {
		if( flag[i]==0 ) {
			d = 0;
			flag[i]++;
			l[d] = w[i];
			d++;
			wtemp = w[i];
			while (1) {
				j = 0;
				while (s[j] != wtemp) {
					j++;
				}
				if(j == i) break;
				flag[j]++;
				l[d] = w[j];
				d++;
				wtemp = w[j];
			}
			cost += mincost(l, d, wmin);
		}
	}
	
	printf("%d\n",cost);
	
	return 0;
}

int mincost(short *l, int d, int wmin)
{
	int i, c1=0, c2, lmin=WMAX, imin;
	
	for (i=0; i<d; i++) {
		c1 += l[i];
		if(lmin > l[i]) {
			lmin = l[i];
		}
	}
	
	c2 = c1;
	c1 += (d-2)*lmin;
	c2 += lmin + (d+1)*wmin;
	
	if (c1 < c2) return c1;
	else return c2;
}

Measured memory_bytes: 624
object Main extends App {
  import scala.io.StdIn._

  readLine
  println(
    readLine.trim.split(' ').count(_.toInt % 2 == 0)
  )
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 43968
#include<cstdio>
#include<algorithm>
const int N=1e5+5;
int a[N],n,l,t,x,w;
long long cnt=1;
using namespace std;
inline char tc(void)
{
	static char fl[100000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,100000,stdin),A==B)?EOF:*A++;
}
inline void read(int &x)
{
	x=0; char ch=tc();
	while (ch<'0'||ch>'9') ch=tc();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=tc();
}
inline void write(int x)
{
	if (x/10) write(x/10);
	putchar(x%10+'0');
}
int main()
{
	//freopen("B.in","r",stdin); freopen("B.out","w",stdout);
	register int i;
	read(n); read(l); read(t);
	for (i=1;i<=n;++i)
	{
		read(x); read(w);
		if (w==1) a[i]=(x+t)%l,cnt+=(x+t)/l; else a[i]=(x-t%l+l)%l,cnt-=t%l>x?t/l+1:t/l;
	}
	cnt=(cnt%n+n-1)%n+1;
	sort(a+1,a+n+1);
	for (i=cnt;i<=n;++i)
	write(a[i]),putchar('\n');
	for (i=1;i<cnt;++i)
	write(a[i]),putchar('\n');
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define For(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>  
#define vd vector<double>
#define pi (int,int)
#define vpi vector<pair<int,int>>
#define vs vector<string>
#define mp make_pair
#define ll long long
#define vc vector<char>
#define rng(x) x.begin(),x.end()
#define B(x) x.begin()
#define E(x) x.end()
#define F first
#define S second
#define me max_element
#define ne min_element
#define LL "%I64d"
#define pi 3.1415926536
using namespace std;
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  
  string s;
  ll sum=0,i;
  cin>>s;
  For(i,0,s.length())
  {
    sum+=(int)(s[i]-48);
  }
  if(sum%9==0) cout<<"Yes";
  else cout<<"No";
  return 0;
}
 

        

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n + 1), b(n);
  rep(i, n + 1) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll ans = 0;
  rep(i, n) {
    ans += min(a[i] + a[i + 1], b[i]);
    if(a[i] < b[i]) a[i + 1] = max(0LL, a[i + 1] - b[i] + a[i]);
  }
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll dp[100005][2][105];

void Main() {
    string K;
    int D;
    cin >> K >> D;

    int N = (int) K.size();
    dp[0][0][0] = 1;
    rep(i, N) {
        int k = K[i] - '0';
        rep(j, 2) {
            rep(d, D) {
                if (j == 1) {
                    k = 9;
                }
                rep(e, k + 1) {
                    if (j == 0) {
                        if (e != k) {
                            dp[i + 1][1][(d + e) % D] += dp[i][j][d];
                            dp[i + 1][1][(d + e) % D] %= MOD;
                        } else {
                            dp[i + 1][0][(d + e) % D] += dp[i][j][d];
                            dp[i + 1][0][(d + e) % D] %= MOD;
                        }
                    } else {
                        dp[i + 1][1][(d + e) % D] += dp[i][j][d];
                        dp[i + 1][1][(d + e) % D] %= MOD;
                    }
                }
            }
        }
    }
    ll ans = (dp[N][0][0] + dp[N][1][0] - 1) % MOD;
    if (ans < 0) ans += MOD;
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 18688
n, m = [int(i) for i in input().split(" ")]
a = [0 for i in range(n)]
b = [0 for i in range(n)]
c = [0 for i in range(m)]
d = [0 for i in range(m)]
for i in range(n):
    a[i], b[i] = [int(i) for i in input().split(" ")]
for i in range(m):
    c[i], d[i] = [int(i) for i in input().split(" ")]

res = []
for i in range(n):
    tmp = 10 ** 10
    resj = 0
    for j in range(m):
        tmo = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if tmo < tmp:
            tmp = tmo
            resj = j
    res.append(resj)

for i in res:
    print(i+1)

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

int main() {
  
  int n,l;
  string S;
  cin >> n >> l ;
  
  vector<string> word(n);
  for(int i=0;i<n;i++){
    cin >> word.at(i) ;
  }
  
  sort(word.begin(),word.end());
  
  for(int i=0;i<n;i++){
    S = S + word.at(i);
  }
  
  cout << S << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
// #include <map>

using namespace std;

int main(){
    long long N, a, b;
    cin >> N;
    vector<int> A(N), B(N);
    // vector<pair<long long, long long> > A(N), B(N);

    long long ans = 0;
    for(int i = 0; i < N; ++i){
        cin >> a >> b;
        long long tmp = a + b;
        A[i] = tmp;
        ans -= b;
        // A[i] = make_pair(tmp, a);
        // B[i] = make_pair(tmp, b);
    }
    stable_sort(A.begin(), A.end(), greater<long long>());
    // stable_sort(B.begin(), B.end(), greater<pair<long long,long long> >());

    for(int i = 0; i < N; ++i){
        if(i % 2 == 0){
            ans += A[i];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int n,m;
  cin >> n >> m;
  
  map<int,bool> ac;

  int cnt_ac = 0;
  map<int,int> cnt_wa;
  for(int i = 0;i < m;i++){
    int p;
    cin >> p;
    string s;
    cin >> s;
    if(ac[p] == false && s == "AC"){
      cnt_ac++;
      ac[p] = true;
    }
    else if(ac[p] == false && s == "WA"){
      cnt_wa[p]++;
    }
  }
  
  int ans_wa = 0;
  for(auto p:cnt_wa){
    if(ac[p.first] == true)ans_wa+= p.second;
  }

  cout << cnt_ac << " " << ans_wa << endl;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#include <boost/math/common_factor.hpp>
using namespace std;

int main() {
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++){
       cin>>a[i];
   }
	int k =1;
	int count =0;
int c =0,j;
while(1){
    
    for( j = c;j<n;j++){
        if(a[j]==k){
            c=j+1;
            k++;
            break;
        }else{
             count++;
        }
       }
    if(j==n){
            break;
        }
    
}
	
	if(k==1){
	    cout<< -1<<endl;
	}else{
	    cout<<count<<endl;
	}
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
using namespace std;

int main() {
    int n, q, op, t, x;
    scanf("%d %d", &n, &q);
    vector<int> v[n];
    while (q--) {
        scanf("%d %d", &op, &t);
        if (op == 0) {
            scanf("%d", &x);
            v[t].push_back(x);
        } else if (op == 1) {
            if (!v[t].empty()) printf("%d", v[t][0]);
            for (int i = 1; i < v[t].size(); i++) printf(" %d", v[t][i]);
            printf("\n");
        } else {
            v[t].clear();
        }
    }
    return 0;
}


Measured memory_bytes: 5420