akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> w(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        w[a-1]++;
        w[b-1]++;
    }
    rep(i, n) {
        cout << w[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    double inv_sum = 0;
  	for (int i = 0; i < n; i++) {
      double x;
      cin >> x;
      inv_sum += 1./x;
    }
  	cout << 1./inv_sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    string s; cin >> s;
    bool f = false;
    rep(i, 0, s.size()){
        if(s[i] == 'C') f = true;
        if(f && s[i] == 'F'){
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
use std::cmp::max;
#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, 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!(a: usize, b: usize, c: usize,);
    let ans = max(max(a * 10 + b + c, a + b * 10 + c), a + b + c * 10);
    println!("{}", ans);
}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n;cin>>n && n;){
		vi a(n);
		rep(i,n) cin>>a[i];
		
		sort(all(a));
		
		int zero=count(all(a),0);
		vi b(begin(a),begin(a)+zero);
		a.erase(begin(a),begin(a)+zero);
		
		if(a.size()){
			if(zero%2){
				b.push_back(a[0]);
				swap(b[b.size()-2],b[b.size()-1]);
				a.erase(begin(a));
			}
			
			int one=count(all(a),1);
			b.insert(end(b),begin(a),begin(a)+one);
			a.erase(begin(a),begin(a)+one);
			
			int two=count(all(a),2),three=count(all(a),3);
			if(two+three==a.size() && two>=1 && three==1)
				swap(a[a.size()-2],a[a.size()-1]);
		}
		
		for(int x:a) cout<<x<<endl;
		for(int x:b) cout<<x<<endl;
	}
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vec<int> ans(10001);

    auto calc = [](int x,int y,int z){
        return x*x+y*y+z*z+x*y+y*z+z*x;
    };

    for(int x=1;x<=100;x++){
        for(int y=1;y<=100;y++){
            for(int z=1;z<=100;z++){
                int a = calc(x,y,z);
                if(a<=10000) ans[a]++;
            }
        }
    }
    int N;
    cin >> N;
    for(int i=1;i<=N;i++) cout << ans[i] << "\n";

}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

class DisjointSet{
public:
  vector<int> rank,p;
  vector<int> sz;
 
  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    sz.resize(size,0);
    for(int i=0;i<size;i++) makeSet(i);
  }
 
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
    sz[x]=1;
  }
 
  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }
 
  void unite(int x,int y){
    if(same(x,y)) return;
    link(findSet(x),findSet(y));
  }
 
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      sz[x]+=sz[y];
    }else{
      p[x]=y;
      sz[y]+=sz[x];
      if(rank[x]==rank[y]){
        rank[y]++;
      }
    }
  }
 
  int findSet(int x){
    if(x!=p[x]){
      p[x]=findSet(p[x]);
    }
    return p[x];
  }
 
  int findSize(int x){
    return sz[findSet(x)];
  }
};

ll N,M,Q;
vector<int> A,B,C;

int main(){
  cin>>N>>M>>Q;
  A.resize(Q);
  B.resize(Q);
  C.resize(Q);
  rep(i,Q) cin>>A[i]>>B[i]>>C[i];

  if(M==N-1){
    bool ok=true;
    for(int i=0;i<Q;i++) if(C[i]==1) ok=false;
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }

  DisjointSet us(N);
  for(int i=0;i<Q;i++){
    if(C[i]==0){
      if(!us.same(A[i],B[i])) us.unite(A[i],B[i]);
    }
  }
  for(int i=0;i<Q;i++){
    if(C[i]==1){
      if(us.same(A[i],B[i])){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }

  ll size=0;
  for(int i=0;i<N;i++){
    if(us.findSet(i)==i) size++;
  }

  ll p=N-size;
  p+=size*(size-1)/2;
  if(M<=p) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	
	int N, M;  cin >> N >> M;
	V pro(N),wa(N);
  	fill(ALL(pro), 0);
	fill(ALL(wa), 0);

 	int ac_count = 0, pena_count = 0;
	REP(i, M){
			int p;  string s;  cin >> p >> s; p -= 1;
			if(s == "AC" && pro[p] == 0){
					ac_count += 1;
              		pro[p] = 1;
              		pena_count += wa[p];
            }else
					wa[p] += 1;
	}

	cout << ac_count << " " << pena_count << endl;

	return 0;
}


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)

typedef long long ll;
typedef pair<ll, ll> point;

const int off = 1 << 18, MAXN = 2e5 + 5;
const ll inf = 1e17;

ll n, m;
vector <point> r[MAXN];

struct Tournament{
  ll t[2 * off], p[2 * off];
  Tournament(){
    REP(i, 2 * off){
      t[i] = 0;
      p[i] = 0;
    }
  }
  void prop(int x){
    if(p[x] == 0) return;
    t[x] += p[x];
    if(x < off){
      p[x * 2] += p[x];
      p[x * 2 + 1] += p[x];
    }
    p[x] = 0;
  }
  void postavi(ll x, int pos){
    pos += off; t[pos] = x; pos >>= 1;
    for( ; pos > 0; pos >>= 1)
      t[pos] = max(t[pos * 2], t[pos * 2 + 1]);
  }
  void update(int x, int lo, int hi, int a, int b, ll add){
    prop(x);
    if(lo >= b || hi <= a) return;
    if(lo >= a && hi <= b) { p[x] += add; prop(x); return; }
    int mid = (lo + hi) >> 1;
    update(x * 2, lo, mid, a, b, add); update(x * 2 + 1, mid, hi, a, b, add);
    t[x] = max(t[x * 2], t[x * 2 + 1]);
  }
  ll get(int x, int lo, int hi, int a, int b){
    prop(x);
    if(lo >= b || hi <= a) return 0;
    if(lo >= a && hi <= b) return t[x];
    int mid = (lo + hi) >> 1;
    return max( get(x * 2, lo, mid, a, b), get(x * 2 + 1, mid, hi, a, b) );
  }
} T;

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

  cin >> n >> m;
  REP(i, m){
    ll a, b, c; cin >> a >> b >> c; a --; b --;
    r[b].pb(point(a, c));
  }
  REP(i, n){
    ll x = T.get(1, 0, off, 0, i);
    T.postavi(x, i);

    for(auto it : r[i]){
      T.update(1, 0, off, it.first, i + 1, it.second);
    }
  }
  cout << max(T.get(1, 0, off, 0, n), 0LL);
}


Measured memory_bytes: 19456
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int[] x = new int[n];
	    int sq = 0;
	    int sum = 0;
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            sq += x[i] * x[i];
            sum += x[i];
        }
	    int p = sum / n;
        int p1 = p + 1;

        int r1 = (n * p - 2 * sum) * p;
        int r2 = (n * p1 - 2 * sum) * p1;
        int r = sq + Integer.min(r1, r2);
        System.out.println(r);
    }
}


Measured memory_bytes: 22992
trinum = gets
trinum = trinum.to_i
trinum.times do 
   a = gets
   num = a.split(' ')
   num.sort! {|x,y| x.to_i<=>y.to_i}
   if num[0].to_i**2 + num[1].to_i**2 == num[2].to_i**2 then
	  print "YES\n"
   else
	  print "NO\n"
   end
end

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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long,long long>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back

const int MOD1=1000000007;
const int MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const int dx[]={0,1,0,-1,1,-1,1,-1};
const int dy[]={1,0,-1,0,1,1,-1,-1};

#define unless(a) if(!(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(n);i++)
#define bitrep(i,s,n) for(int i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}
long long cutup(long long a,long long b){return (a+b-1)/b;}
long long popcnt(long long a){return __builtin_popcountll(a);}
template<class T,class U> inline bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template<class T,class U> inline bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}

struct edge{long long to,cost;};
struct edge2{long long from,to,cost;};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll r,g,b,n;
    cin>>r>>g>>b>>n;
    ll cnt=0;
    rep(i,n/r+1){
        rep(j,(n-i*r)/g+1){
            if((n-i*r-j*g)%b==0)cnt++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3596
def mcm(M):
  n = len(M)
  m = [[0 for i in range(n)] for j in range(n)]
  
  for l in range(2, n+1):
    for i in range(0, n-l+1):
      j = i + l - 1
      def cost(i, k ,j):
        return m[i][k] + m[k+1][j] + M[i][0]*M[k][1]*M[j][1]
      m[i][j] = min(cost(i, k, j) for k in range(i, j))
  
  return m[0][n-1]

n = input()
M = []

for i in range(n):
  M.append(map(int, raw_input().split()))
print mcm(M)

Measured memory_bytes: 6476
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            while(sc.hasNext()) {
                int N=sc.nextInt();
                int M=sc.nextInt();
                if(N+M==0)    break;
                int[] ds = new int[11];
                for(int i=0; i<N; i++) {
                    int d = sc.nextInt();  //距離
                    int p = sc.nextInt();  //単位距離あたりの期待値
                    ds[p] += d;            //各期待値を持つ距離が何単位分あるかカウント
                }
                int P = 0;                 //リスクの合計値
                for(int p= 10; p >=0; p--) {     //期待値の高い方から
                    if(M >= ds[p]) {
                        M -= ds[p];       //予算を消費
                    }
                    else {
                        P += (ds[p] - M) * p;  //予算が無くなった分だけ期待値を合計
                        M = 0;
                    }
                }
                System.out.println(P);
            }
        }
    }
}


Measured memory_bytes: 67472
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main(){
  string s;
  ll x, y;
  cin >> s >> x >> y;
  s += "T";
  V<bool> xdp(2 * (s.size() - 1) + 1, false), prex(2 * (s.size() - 1) + 1, false);
  V<bool> ydp(2 * (s.size() - 1) + 1, false), prey(2 * (s.size() - 1) + 1, false);
  ll d = 0, i = 0;
  for (ll si=0; si<s.size(); si++) {
    if (s.at(si)=='F') d++;
    else {
      if (!i) {
        prex.at(d + (s.size() - 1)) = true;
        prey.at(s.size()-1) = true;
      } else if (i % 2 == 1) {
        for (ll yi=0; yi<ydp.size(); yi++) {
          if (yi < d) ydp.at(yi) = prey.at(yi+d);
          else if (yi > ydp.size()-d-1) ydp.at(yi) = prey.at(yi-d);
          else {
            ydp.at(yi) = prey.at(yi+d) || prey.at(yi-d);
          }
        }
        prey = ydp;
        ydp = V<bool>(2 * (s.size() - 1) + 1, false);
      } else {
        for (ll xi=0; xi<xdp.size(); xi++) {
          if (xi < d) xdp.at(xi) = prex.at(xi+d);
          else if (xi > xdp.size()-d-1) xdp.at(xi) = prex.at(xi-d);
          else {
            xdp.at(xi) = prex.at(xi+d) || prex.at(xi-d);
          }
        }
        prex = xdp;
        xdp = V<bool>(2 * (s.size() - 1) + 1, false);
      }
      i++; d=0;
    }
  }
  if (prey.at(y+s.size()-1) && prex.at(x+s.size()-1)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int N, M;
    in(N); in(M);
    vector<int> H(N);
    rep(i, N) in(H[i]);
    vector<int> A(M), B(M);
    vector<bool> good(N, true);
    rep(i, M) {
        in(A[i]);
        in(B[i]);
        if (H[A[i]-1] <= H[B[i]-1]) good[A[i]-1] = false;
        if (H[B[i]-1] <= H[A[i]-1]) good[B[i]-1] = false;
    }
    int cnt = 0;
    rep(i, N) {
        if (good[i]) cnt++;
    }

    out(cnt);
	return 0;
}


Measured memory_bytes: 4584
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 08/07/2017 01:47:53
	flamers will **** you
*/
#include<bits/stdc++.h>
//#include<flamers.h>
#define ull unsigned long long
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> vect1, vect2;
	int x;
	for(int i = 0; i < n; i++){
		cin>>x;
		if(i % 2 == 0) vect1.push_back(x);
		else vect2.push_back(x);
	}
	
	if(n % 2 == 1) {
		for(int i = vect1.size()-1; i >= 0; i--){
			cout<<vect1[i]<<" ";
		}
		for(int i = 0; i < vect2.size(); i++){
			cout<<vect2[i]<<" ";
		}
	}
	else{
		for(int i = vect2.size()-1; i >= 0; i--){
			cout<<vect2[i]<<" ";
		}
		for(int i = 0; i < vect1.size(); i++){
			cout<<vect1[i]<<" ";
		}
	}
	return 0;
}


Measured memory_bytes: 3188
def includes(li1, li2):
    """Returns True if li2 is included in li1.
    Assumes li1 and li2 are sorted by ascending order.

    >>> includes([1, 2, 3], [1, 2])
    True
    >>> includes([1, 2, 3], [3, 4])
    False
    """
    def partition(li, x):
        if len(li) == 0:
            return 0
        mid = len(li) // 2
        if li[mid] < x:
            return mid + 1 + partition(li[mid+1:], x)
        elif li[mid] > x:
            return partition(li[:mid], x)
        else:
            return mid

    def binsearch(li, x):
        i = partition(li, x)
        if 0 <= i < len(li):
            return li[i] == x
        else:
            return False

    if len(li1) < len(li2):
        return False
    if len(li2) > 1:
        mid = len(li2) // 2
        i = partition(li1, li2[mid])
        if i >= len(li1) or li2[mid] != li1[i]:
            return False
        else:
            return (includes(li1[:i], li2[:mid])
                    and includes(li1[i+1:], li2[mid+1:]))
    elif len(li2) == 1:
        return binsearch(li1, li2[0])
    else:
        return True


def run():
    n = int(input())
    la = [int(x) for x in input().split()]
    assert(n == len(la))

    m = int(input())
    lb = [int(x) for x in input().split()]
    assert(m == len(lb))

    if includes(la, lb):
        print(1)
    else:
        print(0)


if __name__ == '__main__':
    run()



Measured memory_bytes: 35328
#include<bits/stdc++.h>
using namespace std;
signed  main() {
    int sz,m,a,b,c;
    cin>>sz;
    int v[sz];
    for(int i=0; i<sz; i++)
        cin>>v[i];
    cin>>m;
    while(m--) {
        cin>>a>>b>>c;
   rotate(v+a,v+b,v+c);
    }
    cout<<v[0];
    for(int i=1; i<sz; i++)
        cout<<' '<<v[i];
        cout<<endl;
    return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
using namespace std;
	
int main(){	
	int n,m,X,Y,x[110],y[110],a,b;
	cin >> n>>m>>X>>Y;
	for (int i=0;i<n;i++)
		cin >> x[i];
	for (int j=0;j<m;j++)
		cin >> y[j];
	for (int i=0;i<n;i++){
		for (int j=n;j>i;j--){
			if(x[j-1]<x[i])	{
			int d= x[j-1];
			x[j-1]=x[i];
			x[i]=d;	
			}
		}
	}
	for (int i=0;i<m;i++){
		for (int j=m;j>i;j--){
			if(y[j-1]<y[i])	{
			int d= y[j-1];
			y[j-1]=y[i];
			y[i]=d;	
			}
		}
	}
	a=(x[n-1]>X)?x[n-1]:X;
	b=(y[0]<Y)?y[0]:Y;
	if(a<b)cout << "No War"<<endl;
	else cout << "War"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
int32_t main()
{	
	Fast_IO
	#ifdef __WIN32 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w",stdout);
	#endif
	int n;cin>>n;
	int maxcap;cin>>maxcap;
	vector<int> weights(n);
	vector<int> values(n);
	int sumv=0;
	for(int i=0;i<n;i++){
		cin>>weights[i]>>values[i];
		// sumv+=values[i];
	}
	//dp[i] - max value for weight exactly i 
	vector<int> dp(maxcap+1,0);
	for(int i=0;i<n;i++){
		for(int j=maxcap-weights[i];j>=0;j--){
			dp[j+weights[i]]=max(dp[j+weights[i]],dp[j]+values[i]);
		}
	}	
	// int ans=0;
	// for(int i=0;i<=maxcap;i++){
	// 	cout<<dp[i]<<" ";
	// 	ans=max(ans,dp[i]);
	// }
	cout<<dp[maxcap];


}

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

typedef long long ll;
ll MOD = 1000000007;

struct bit {
	vector<ll> v;
	bit(int n) : v(n + 1) {}
	ll sum(int i) {
		ll res = 0;
		for (; i > 0; i -= i & -i) res += v[i];
		return res;
	}
	void add(int i, ll x) {
		for (i++; i < v.size(); i += i & -i) v[i] += x;
	}
};

int B = 500;

int main() {
	int N; cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &p[i]);
		p[i]--;
	}
	vector<vector<int> > num(N / B + 1, vector<int>(N + 1));
	for (int i = 0; i < N; i++)
		num[p[i] / B][i + 1]++;
	for (int j = 0; j <= N / B; j++)
		for (int i = 0; i < N; i++)
			num[j][i + 1] += num[j][i];
	int Q; cin >> Q;
	vector<vector<int> > query(N);
	vector<int> l(Q), r(Q);
	for (int q = 0; q < Q; q++) {
		scanf("%d%d", &l[q], &r[q]);
		l[q]--; r[q]--;
		query[r[q]].push_back(q);
	}
	vector<int> index(N, -1);
	bit bt(N);
	vector<int> A(N / B + 1);
	vector<vector<int> > v(N / B + 1);
	vector<vector<ll> > sum(N / B + 1, vector<ll>(1));
	ll cur = 0;
	vector<ll> ans(Q);
	for (int i = 0; i < N; i++) {
		for (int x = N - 1; x > p[i];) {
			if (x % B == B - 1 && x - B >= p[i]) {
				A[x / B]++;
				cur += v[x / B].size();
				x -= B;
			}
			else {
				if (index[x] != -1) {
					bt.add(index[x], 1);
					cur++;
				}
				x--;
			}
		}
		int x = p[i];
		index[x] = i;
		ll prev = sum[x / B].back();
		v[x / B].push_back(i);
		sum[x / B].push_back(prev + A[x / B]);
		for (int k = 0; k < query[i].size(); k++) {
			int q = query[i][k];
			ans[q] = cur - bt.sum(l[q]);
			for (int i = 0; i <= N / B; i++) {
				int j = num[i][l[q]];
				ans[q] -= (ll)j * A[i] - sum[i][j];
			}
		}
	}
	for (int q = 0; q < Q; q++)
		printf("%lld\n", ans[q]);
}

Measured memory_bytes: 92528
#include <bits/stdc++.h>
#define pb push_back
#define Int int64_t
using namespace std;

int64_t N;
int64_t K;
int main()
{
    cin>>N;

    Int min_curr=1e13+25;
    for(Int i=1;i*i<=N;++i){
        if(N%i) continue;
        min_curr=min(min_curr,i+(N/i)-2);
    }
   cout<<min_curr;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
int MAX=2004;
//int MAX=12;

int dist[2004][2004];
int ans[2004];
std::vector<int > to[2004];

void bfs(int n){
  //printf("bfs(%d) start\n",n);
  std::queue<int > queue;
  queue.push(n);
  queue.push(-1);
  int length=1;
  while(queue.size()>0){
    if (queue.front()==-1){
      length++;
      queue.pop();
      queue.push(-1);
      //printf("push -1\n");
    }
    int thisid = queue.front();
    //printf("thisid=%d\n", thisid);
    queue.pop();
    for (int i=0; i<to[thisid].size(); i++){
      if (dist[n][to[thisid][i]]==-1){
        dist[n][to[thisid][i]]=length;
        //printf("dist[%d][%d]=%d\n",n,to[thisid][i],length);
        queue.push(to[thisid][i]);
        //printf("push %d\n",to[thisid][i]);
      }
    }
  }
  return;
}

int main(){
  int N, X, Y;
  scanf("%d", &N);
  scanf("%d", &X);
  scanf("%d", &Y);
  X--;
  Y--;
  for (int i=0; i<MAX; i++){
    for (int j=0; j<MAX; j++){
      dist[i][j]=-1;
    }
  }

  for (int i=0; i<N-1; i++){
    to[i].push_back(i+1);
    to[i+1].push_back(i);
  }
  to[X].push_back(Y);
  to[Y].push_back(X);
  for (int i=0; i<N; i++){
    // dist[i][*]を決める
    dist[i][i]=0;
    bfs(i);
  }

  for (int i=0; i<MAX; i++){
    for (int j=0; j<MAX; j++){
      //printf("dist[%d][%d]=%d\n",i,j,dist[i][j]);
      if (dist[i][j]!=-1){
        ans[dist[i][j]]++;
      }
    }
  }
  for (int i=1; i<N; i++){
    printf("%d\n", ans[i]/2);
  }
  
  return 0;
}


Measured memory_bytes: 16504
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 24 14:37:00 2020

@author: matsui
"""

N,M=map(int,input().split())
A=[0]*N
B=[0]*N
ans=''
for i in range(M):
    s,c=map(int,input().split())
    if N!=1:
        if s==1 and c==0: ans=-1
    if B[s-1]==0:
        A[s-1]=c
    else:
        if A[s-1]!=c:
            ans=-1
    B[s-1]=1

if N!=1:
    if A[0]==0 and B[0]==0:
        A[0]=1


if ans != -1:
    for a in A: 
        ans+=str(a)

print(ans)

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

class SegTree{
	public:
		int N;
		vector<long long> Dat;
		SegTree(int n){
			if((n & (n - 1)) == 0) N = n;
			else{
				N = 1;
				while(n > 0){
					N <<= 1;
					n >>= 1;
				}
			}
			Dat.resize(2 * N - 1, 0);
		}

		void update(int i, int x){ // a[i] <- x
			i += N - 1;
			Dat[i] += x;
			while(i > 0){
				i = (i - 1) / 2;
				Dat[i] = Dat[i * 2 + 1] + Dat[i * 2 + 2];
			}
		}

		long long find(int a, int b, int k, int l, int r){ // return sum of [a, b) in node k, usage : st.find(x, y+1, 0, 0, st.N-1);
			if(r < a || b <= l) return 0;
			if(a <= l && r < b) return Dat[k];
			long long vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
			long long vr = find(a, b, k * 2 + 2, 1 + (l + r) / 2, r);
			return vl + vr;
		}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	SegTree st(n);
	while(q--){
		int c, x, y;
		cin >> c >> x >> y;
		if(c == 0) st.update(x-1, y);
		else cout << st.find(x-1, y, 0, 0, st.N-1) << "\n";
/*		for(int i=0; i<n; ++i)
			cout << st.Dat[i+st.N-1] << "\t";
		cout << "\n";
*/	}
}


Measured memory_bytes: 4920
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long 
ll x;
int t[200050],n,a[100050],b[100050],u[100050];
void add(int x){for (int i=x;i<=200000;i+=i&(-i))t[i]++;}
int query(int x){int ret=0;for (int i=x;i;i-=i&(-i))ret+=t[i];return ret;}
bool check(int p){
	memset(t,0,sizeof t);
	ll ret=0;
	for (int i=1;i<=n;i++)b[i]=(u[i]>=p)?1:-1;
	add(n);
	for (int i=1;i<=n;i++){
		b[i]=b[i]+b[i-1];
		ret+=query(n+b[i]);
		add(n+b[i]);
	} 
	return ret>=x;
}
int read(){
	int c=getchar(),ret=0;
	while (c<'0'||c>'9')c=getchar();
	while (c>='0'&&c<='9')ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
	return ret;
}
int main(){
	n=read();
	for (int i=1;i<=n;i++)u[i]=a[i]=read();
	x=(n*1ll*(n+1)/2+1)/2;
	std::sort(a+1,a+n+1);
	int tmp=std::unique(a+1,a+n+1)-a-1;
	int l=1,r=tmp,ans=1;
	while (l<=r){
		int mid=(l+r)>>1;
		if (check(a[mid]))ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d",a[ans]);
}

Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}

ll combination(ll n, ll r) {
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b) << endl;
}


Measured memory_bytes: 256
package main


import "fmt"

func main(){
  var a, b, c, d int
  fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
  
  for a > 0 && c > 0{
    c = c - b
    if c <= 0{
      fmt.Println("Yes")
      break
    }
    a = a - d
    if a <= 0{
      fmt.Println("No")
      break
    }
  }
}

Measured memory_bytes: 1816
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int a, b, c;cin>>a>>b>>c;
  cout<<(a+b+c>=22?"bust":"win")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define prt(x) cout<<x<<endl
#define prk(x) x<<" "
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#ifndef ONLINE_JUDGE
    freopen("A.in", "r", stdin);
#endif
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(6);
}
///////////////////////////
const int N = 5 + 1e5;
const int M = 7 + 3e2;

int t, n,k;
unordered_set<string>st;
string s;
vector<string>a;
int main () {
    
    cin>>s>>k;
    int sz=s.size();
    rep(i,0,sz-1)
    {
        rep(j,1,min(k,sz-i))
        {
            st.insert(s.substr(i,j));
        }
    }
    for(auto it=st.begin();it!=st.end();it++)
    {
        a.push_back(*it);
    }
    nth_element(a.begin(),a.begin()+k-1,a.end());
    cout<<a[k-1];

    return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

Int solve(const string& s){
    vector<string> days = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    int x = distance(begin(days), find(begin(days), end(days), s));
    return 7 - x;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    string s;
    cin >> s;
    cout << solve(s) << "\n";

    return 0;
}


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

int main(){
    int x, a, b;

    cin >> x >> a >> b;

    int s, t;
    s = fabs(x - a);
    t = fabs(x - b);

    if(s > t){
        cout << "B" << endl;
    }
    else{
        cout << "A" << endl;
    }

    return 0;
}

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


class Solver {
public:
    void solve();
    long long sumXORTo(long long x);
};

long long Solver::sumXORTo(long long x) {
    if (x % 2 != 0) {
        long long half = (x + 1) / 2;
        if (half % 2 != 0) {
            return 1;
        }
        else {
            return 0;
        }
    }
    else {
        long long half = (x + 1) / 2;
        if (half % 2 != 0) {
            return 1 ^ x;
        }
        else {
            return x;
        }
    }
}


void Solver::solve() {
    using namespace std;
    long long a, b;
    cin >> a >> b;

    long long a1 = sumXORTo(a - 1);
    long long b1 = sumXORTo(b);
    long long result = a1 ^ b1;
    cout << result << endl;
    


}



int main() {
    Solver solver = Solver();
    solver.solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

template <class _T> void tp_getPrimes(_T targ, std::map<_T, _T>& primes)
{
	_T target = targ;
	_T i = 2;
	while ((i * i) <= target) {
		if ((target % i) == 0) {
			target /= i;
			primes[i]++;
		}
		else {
			i++;
		}
	}
	if (target > 1) {
		primes[target]++;
	}
}

static void ABC084D_2017_Like_Summer();

#if 1
int main()
{
	ABC084D_2017_Like_Summer();
	fflush(stdout);
	return 0;
}
#endif

static void ABC084D_2017_Like_Summer()
{
	int Q;
	get1int(Q);

	std::vector<std::pair<int, int>> query(Q);
	for (int i = 0; i < Q; i++) {
		int l, r;
		get2int(l, r);
		query[i].first = l;
		query[i].second = r;
	}

	std::vector<int> nCount(100001, 0);
	for (int i = 1; i <= 100000; i++) {
		nCount[i] = nCount[i - 1];

		std::map<int, int> primes;
		tp_getPrimes<int>(i, primes);

		if ((primes.size() == 1) && (primes.begin()->second == 1)) {
			std::map<int, int> primes2;
			tp_getPrimes<int>((i + 1) / 2, primes2);
			if ((primes2.size() == 1) && (primes2.begin()->second == 1)) {
				nCount[i]++;
			}
		}
	}

	for (int i = 0; i < Q; i++) {
		int ans = nCount[query[i].second] - nCount[query[i].first - 1];
		printf("%d\n", ans);
	}
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    int n,k;
    string s;
    cin >> n >> k;
    cin >> s;

    vector<pair<int,int>> pos;
    
    bool flag = false;
    int left;
    REP(i,n){
        if(!flag && s[i] == '0'){
            left = i;
            flag = true;
        }
        else if(flag){
            if( s[i] == '1'){
                pos.push_back(pair<int,int>(left,i-1));
                flag = false;
            }
        }

        if(i == n-1 && s[i] == '0'){
                pos.push_back(pair<int,int>(left,i));
        }
    }

    if(k >= pos.size()){
        cout << s.size() << endl;
    }
    else{
        int sum = pos[k].first;
        int max = sum;
        for(int i = 1; k+i  < pos.size();i++){
            sum = pos[k+i].first - pos[i-1].second -1;
            if(sum > max){
                max = sum;
            }
        }
        sum = s.size() - 1 - pos[pos.size() - k - 1].second;
        chmax(max,sum);
        cout << max << endl;
    }



    return 0;
}

Measured memory_bytes: 1020
# ABC165c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)
    from math import floor
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    a, b, n = map(int, input().split())
    last = -1
    ans = -1

    def evaluate(number):
        return floor(a * number / b) - a * floor(number / b)

    # for i in range(1, n+1):
    #    print(i, evaluate(i))
    print(max(evaluate(min(b, n)), evaluate(min(b-1, n))))


if __name__ == '__main__':
    main()


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

int main(){
  int r;
  cin >> r;
  if(r < 1200){
    cout << "ABC";
  }else if(r < 2800){
    cout << "ARC";
  }else{
    cout << "AGC";
  }
  return 0;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    int ans = 0;
    rep(i, M){
        cin >> A[i];
        ans += A[i];
    }
    if(N - ans >= 0)
    cout << N - ans << endl;
    else
    cout << -1 << endl;
}

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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 10){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int N = input();

  string s;
  cin >> s;

  auto f = [&](int k) {
    int64 res = 0;
    int64 cnt_d = 0, cnt_m = 0, dm = 0;

    range(i, 0, N) {
      if (0 <= i - k && s[i - k] == 'D') {
        cnt_d--;
        dm -= cnt_m;
      }
      if (0 <= i - k && s[i - k] == 'M') {
        cnt_m--;
      }

      if (s[i] == 'D') {
        cnt_d++;
      }
      if (s[i] == 'M') {
        cnt_m++;
        dm += cnt_d;
      }

      if (s[i] == 'C') {
        res += dm;
      }
    }

    return res;
  };

  int q = input();
  while (q--) cout << f(input()) << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}


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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n; cin >> n;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];
    int ans = 1e9+7;    
    rep(i,-101,101) {
        int sum = 0;
        rep(j,0,n) {
            sum += (i-a[j]) * (i-a[j]);
        }
        ans = min(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
const int N=(2e5+1e4);
int n, k;
int a[N];
int go[N];
set<int>ss;
int ans=0;
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
 	go[0]=0;
	for(int i=1;i<n;i++)
	{
		if (a[i]>a[i-1]) 
		{
			go[i]=go[i-1]+1;
		}
		else
		{
			go[i]=0;
		}
		if (go[i]>=(k-1)) 
		{
			ans=1;
		}
	}
	for(int i=0;i<k;i++)
	{
		ss.insert(a[i]);
	}	
	if(go[k-1]!=k-1)
	{
		ans++;
	}
	for(int i=k;i<n;i++)
	{
		ss.insert(a[i]);
		if(((*(ss.begin()))!=a[i-k])||((*(ss.rbegin()))!=a[i]))
		{
			if(go[i]<k-1)
			{
				++ans;
			}
		}
		ss.erase(a[i-k]);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 11136
#include<stdio.h>

int main(){
  int N;
  scanf("%d", &N);
  
  if(N >= 64){
    printf("64\n");
  } else if(N >= 32){
    printf("32\n");
  } else if(N >= 16){
    printf("16\n");
  } else if(N >= 8){
    printf("8\n");
  } else if(N >= 4){
    printf("4\n");
  } else if(N >= 2){
    printf("2\n");
  } else {
    printf("1\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
from collections import Counter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
edge = [[] for _ in range(N + 1)]
for i in range(N - 1):
    x, y = map(int, input().split())
    edge[x].append((y, i))
    edge[y].append((x, i))

color = [-1] * (N - 1)


def dfs(s, p=-1, pc=-1):
    c = 0
    for t, x in edge[s]:
        if color[x] != -1:
            continue
        if t == p:
            continue
        c += 1
        if c == pc:
            c += 1
        color[x] = c
        dfs(t, s, c)


dfs(1)

print(len(Counter(color)))
print(*color, sep="\n")

Measured memory_bytes: 86004
// abc062_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
    int H, W;
    cin >> H >> W;
    vector<string> S(H+2);
    REP(i, H) cin >> S[i+1];
    REP(j, W) {
        S[0] += "#";
        S[H+1] += "#";
    }
    REP(i, H+2){
        S[i] = "#" + S[i] + "#";
        print(S[i]);
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  int all[4]={0,0,0,0};
  cin>>a>>b;
  all[a]=1;
  all[b]=1;
  for(int i =1;i<=3;i++)
    if(all[i]==0)
      cout<<i<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 100;
bool st[N];
int k,pri[N];

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    for(int i = 2;i <= N; ++i) {
        if(!st[i]) pri[k ++] = i;
        for(int j = 0;pri[j] <= N / i; ++j) {
            st[pri[j] * i] = 1;
            if(i % pri[j] == 0) break;
        }
    }
    int x;
    cin >> x;
    int l = 0,r = k;
    while(l < r) {
        int mid = l + r>> 1;
        if(pri[mid] >= x) r = mid;
        else l = mid + 1;
    }

    cout << pri[l];
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long a[n];
  long b[n];
  vector<pair<long,long>> p(n);
  int i;
  long ans = 0;
  for(i=0;i<n;i++){
    cin >> a[i];
    b[i] = abs(a[i]);
    p[i] = make_pair(b[i],a[i]);
  }
  int cnt = 0;
  sort(p.begin(),p.end());
  
  for(i=0;i<n;i++){
    if(p[i].second<0)cnt++;
  }
  if(cnt%2==1)p[0].first*=-1;
  
  
  for(i=0;i<n;i++){
    ans += p[i].first;
  }
  cout << ans;
  
}

Measured memory_bytes: 3328
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    h, w, k = map(int, input().split())
    s = [input() for _ in range(h)]
    st = [False] * h
    for i in range(h):
        if s[i].find('#') != -1:
            st[i] = True
    count = 0
    while st[count] == False:
        s[count] = list(s[i])
        count += 1
    c = 0
    for i in range(count, h):
        s[i] = list(s[i])
        fd = False
        if st[i] == False:
            s[i] = s[i-1]
            continue
        c += 1
        for j in range(w):
            if s[i][j] == '#':
                if fd == False:
                    fd = True
                    s[i][j] = c
                else:
                    c += 1
                    s[i][j] = c
            else:
                s[i][j] = c
    for i in range(count):
        s[i] = s[count]
    for i in range(h):
        for j in range(w):
            if j < w - 1:
                print(s[i][j], end=' ')
            else:
                print(s[i][j])


main()

Measured memory_bytes: 7504