akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool comp(string a, string b)
{
    int open_a = 0, open_b = 0;
    for (int i = 0; i < a.length(); i++)
        if (a[i] == '(')
            open_a++;
    for (int i = 0; i < b.length(); i++)
        if (b[i] == '(')
            open_b++;

    int diffa = 2 * open_a - a.length();
    int diffb = 2 * open_b - b.length();

    if (diffa >= 0 && diffb >= 0)
        return (a.length() - open_a) < (b.length() - open_b);

    if (diffa < 0 && diffb >= 0)
        return false;

    if (diffa >= 0 && diffb < 0)
        return true;

    return open_a > open_b;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<string> v(n);
    for (auto &i : v)
        cin >> i;

    sort(v.begin(), v.end());
    sort(v.begin(), v.end(), comp);
    string ans = "";

    for (auto i : v)
    {
        //       cout << i << ' ';
        ans += i;
    }
    int a = 0;
    bool ok = true;
    for (int i = 0; i < ans.size(); i++)
    {
        if (ans[i] == '(')
            a++;
        else
        {
            a--;
        }
        if (a < 0)
        {
            ok = false;
            break;
        }
    }
    if (a != 0 || !ok)
    {
        cout << "No\n";
    }
    else
    {
        cout << "Yes\n";
    }
    return 0;
}


Measured memory_bytes: 36504
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const lint INF=1e18;

int n;
int ar[200005];

lint dp[200005][5];
int main(){
  cin>>n;
  REP(i,n) cin>>ar[i];

  REP(i,n+1) REP(t,5) dp[i][t]=INF;
  REP(i,5) dp[0][i]=0;

  REP(i,n){
    lint evmin=INF;
    REP(t,5){
      chmin(evmin,dp[i][t]);
      if(t==0) dp[i+1][t]=evmin+ar[i];
      else if(t==1 || t==3) dp[i+1][t]=evmin+(ar[i]==0?2:ar[i]%2);
      else if(t==2) dp[i+1][t]=evmin+(1-ar[i]%2);
      else if(t==4) dp[i+1][t]=evmin+ar[i];
    }
  }
  lint res=INF;
  REP(i,5) chmin(res,dp[n][i]);
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
const int N=1e5+5;
int n,m,cnt[N];bool ok[N];
int main(){
	scanf("%d%d",&n,&m);
	ok[1]=true;
	int ans=0;
	for(int i=1;i<=n;i++){
		cnt[i]=1;
	}
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		if(ok[x])ok[y]=true;
		cnt[x]--;
		cnt[y]++;
		if(cnt[x]==0)ok[x]=false;
	}
	for(int i=1;i<=n;i++){
		if(ok[i])ans++;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
typedef pair<ll,pair<ll,ll>>PP;
ll n,m,a,b,c,ch[200000];
vector<PP>v;
set<P>s;
int main(void){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a>>b>>c;
        a=max(a-c,0LL);
        b=max(b-c,0LL);
        v.push_back(PP{c,{a,b}});
    }
    sort(v.begin(),v.end());
    for(int i=0;i<m;i++){
        cin>>a;
        s.insert({a,i});
    }
    for(auto x:v){
        c=x.F,a=x.S.F,b=x.S.S;
        //cout<<s.size()<<endl;
        //cout<<c<<" "<<a<<" "<<b<<endl;
        auto itr=s.lower_bound(P{a,-1});
        while(itr!=s.end()){
            //cout<<itr->F<<" "<<b<<endl;
            if(itr->F<b){
                ch[itr->S]=c;
                //cout<<itr->S<<endl;
                s.erase(itr++);
            }
            else{
                break;
            }
        }
    }
    for(int i=0;i<m;i++){
        if(ch[i]==0)cout<<-1<<endl;
        else cout<<ch[i]<<endl;
    }
}


Measured memory_bytes: 22124
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(void){
    int n; cin>>n;
    vector <vector<int>> dp(100010 ,vector <int>( 3));
    vector <vector<int>> a(n ,vector <int>(3));
    for(int i=0;i<n;i++){
        cin>>a[i][0];
        cin>>a[i][1];
        cin>>a[i][2];
    }
    dp[0][0]=a[0][0]; dp[0][1]=a[0][1]; dp[0][2]=a[0][2]; 
    for(int i=0;i<n-1;i++){
            dp[i+1][0]=max(dp[i][1]+a[i+1][0],dp[i][2]+a[i+1][0]);
            dp[i+1][1]=max(dp[i][0]+a[i+1][1],dp[i][2]+a[i+1][1]);
            dp[i+1][2]=max(dp[i][0]+a[i+1][2],dp[i][1]+a[i+1][2]);
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]) <<endl;
}

Measured memory_bytes: 11136
use std::io::*;
use std::collections::HashSet;
use std::cmp;

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

fn read_vec_char() -> Vec<char> {
    read::<String>().chars().collect()
}

fn main() {
    let n = read::<usize>();
    let s = read_vec_char();
    let mut ans = 0;
    let mut s1: HashSet<char> = HashSet::new();
    let mut s2: HashSet<char>;
    for i in 1..n {
        s1.insert(s[i-1]);
        s2 = s[i..n].iter().map(|&x| x).collect();
        let m = s1.intersection(&s2).collect::<HashSet<_>>().len();
        ans = cmp::max(ans,m);
    }
    println!("{}",ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int a,b,k;
    cin >> a >> b >> k ;
    for(int i=0;i<k;i++){
        if(i%2==0) {
            a=a/2;
            b+=a;
        }
        else {
            b=b/2;
            a+=b;
        }
    }
    cout << a <<" "<< b;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FORR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (e), i ## __begin = (b); i -- > i ## __begin;)
#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) begin (x), end (x)
using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  string s; cin >> s;
  stack <char> st;

  int64_t ans = 0;

  for (auto && elem : s)
  {
    if (st.empty ()) st.push (elem);
    else
    {
      auto t = st.top ();
      if (t != elem)
      {
        st.pop ();
        ans += 2;
      }
      else st.push (elem);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
int main() {
	while (1) {
		long long int A, B, D; cin >> A >> B >> D;
		if (!A)break;
		pair<long long int, long long int >ans = make_pair(1e9, 1e9);
		for (int i = -10000; i <= 10000; ++i) {
			const int anum = abs(i);
			if (!((D - A*i)%B)) {
				long long int bnum = abs((D - A*i) / B);
				if (anum + bnum < ans.first + ans.second|| anum*A + bnum*B < ans.first*A + ans.second*B)ans = make_pair(anum, bnum);
			}
		}
		cout << ans.first << " " << ans.second << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll H,W;
	cin>>H>>W;
	char a[H][W];
	ll dp[H][W];
	memset(dp,0,sizeof(dp));
	for(ll i=0;i<H;i++)
	{
		for(ll j=0;j<W;j++)
			cin>>a[i][j];
	}
	for(ll i=0;i<H;i++)
	{
		if(a[i][0]=='#')
			break;
		dp[i][0]=1;
	}
	for(ll i=0;i<W;i++)
	{
		if(a[0][i]=='#')
			break;
		dp[0][i]=1;
	}
	for(ll i=1;i<H;i++)
	{
		for(ll j=1;j<W;j++)
		{
			if (a[i][j]=='.')
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	cout<<dp[H-1][W-1];
}

Measured memory_bytes: 9088
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

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

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  ll i,N,x;
  cin>>N;
  set<ll> se;
  rep(i,N){
    cin>>x;
    auto p=se.insert(x);
    if(!p.second){
      se.erase(x);
    }
  }
  cout<<se.size()<<endl;
  return 0;
}

Measured memory_bytes: 4864
#include <iostream>

#define ll long long

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;
    cout << ((n * (n - 1)) >> 1) + ((m * (m - 1)) >> 1);
    return 0;
}


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

using namespace std;

const int edge = 1;
const int no_edge = 0;

int main() {
  int vertex_num;
  cin >> vertex_num;

  // init
  vector<vector<int>> list_graph(
    vertex_num,
    vector<int>(vertex_num, 0)
  );

  // convert
  for(int i = 0; i < vertex_num; i++) {
    int vertex_label;
    int adjacency_vertex_num;
    cin >> vertex_label >> adjacency_vertex_num;

    for(int j = 0; j < adjacency_vertex_num; j++) {
      int adjacency_vertex_label;
      cin >> adjacency_vertex_label;

      list_graph[vertex_label - 1][adjacency_vertex_label - 1] = edge;
    }
  }


  // print
  for(int i = 0; i < vertex_num; i++) {
    for(int j = 0; j < vertex_num; j++) {
      cout << list_graph[i][j];

      if(j != vertex_num - 1) {
        cout << ' ';
      }
    }
    cout << endl;
  }
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
#define PI acos(-1.0)
#define EPS 1e-10
const ll INT = 1e16;
const ll MOD = 1e9 + 7;
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define rep(i,N) FOR(i, 0, N)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).reeal(), (b).real) && EQ((a).imag(), (b).imag()))
#define NIL -1

#define SIZE 2501
bool dp[2501][2501], nxt[2501][2501];

int main(){
    int n;
    cin>>n;
    vector<int> t(n);
    rep(i,n)cin>>t[i];
    dp[0][0]=true;
    rep(i,n){
        rep(j,SIZE){
            rep(k,SIZE){
                nxt[j][k] = dp[j][k];
                if(j >= t[i])nxt[j][k] |= dp[j-t[i]][k];
                if(k >= t[i])nxt[j][k] |= dp[j][k-t[i]];
            }
        }
        rep(j,SIZE)rep(k,SIZE)dp[j][k] = nxt[j][k];
    }
    int ans=SIZE, sum=0;
    rep(i,n)sum += t[i];
    rep(i,SIZE)rep(j,SIZE){
        if(dp[i][j]){
            int k = sum - i - j;
            ans = min(ans, max(i,max(j,k)));
        }
    }
    cout << ans << endl;
}


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

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

Measured memory_bytes: 256
#include <stdio.h>

int expr(char **);

int number(char **s) {
  int val = 0;
  while ('0' <= **s && **s <= '9') {
    val = val * 10 + **s - '0';
    (*s)++;
  }
  return val;
}

int factor(char **s) {
  if (**s == '(') {
    (*s)++;
    int val = expr(s);
    (*s)++;
    return val;
  }
  return number(s);
}

int term(char **s) {
  int val = factor(s);
  while (1) {
    if (**s == '*') {
      (*s)++;
      val *= factor(s);
    } else if (**s == '/') {
      (*s)++;
      val /= factor(s);
    } else {
      break;
    }
  }
  return val;
}

int expr(char **s) {
  int val = term(s);
  while (1) {
    if (**s == '+') {
      (*s)++;
      val += term(s);
    } else if (**s == '-') {
      (*s)++;
      val -= term(s);
    } else {
      break;
    }
  }
  return val;
}

int main() {
  int n;
  scanf("%d", &n);
  char s[101];
  while (n--) {
    scanf("%s", s);
    char *p = s;
    printf("%d\n", expr(&p));
  }
}

Measured memory_bytes: 1740
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare(const void * a,const void * b){
    return strcmp(a,b);


}

int main(){
    int n, l;
    scanf("%d %d",&n,&l);
    char s[n][l+1];
    for(int i = 0;i<n;++i)
        scanf("%s",s[i]);
        
    qsort(s,n,sizeof(s[0]),compare);    
        
        
    for(int i =0;i<n;++i)
        printf("%s",s[i]);
    printf("\n");
    
    return 0;
}

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

public class Main{

	//全てのカードリストを作る
	//入力されたカードをリストから除外する
	//出力
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		ArrayList<String> all_cards=new ArrayList<String>();
		String[] card_hilt_ary={"S","H","C","D"};

		//全てのカードリストを作る
		for(int i=0;i<4;i++){
			for(int j=1;j<=13;j++){
				all_cards.add(card_hilt_ary[i]+" "+String.valueOf(j));
			}
		}

		//カードを除外
		int being_num=sc.nextInt();
		for(int i=0;i<being_num;i++){
			String hilt=sc.next();
			String num=sc.next();
			//String being_cards=hilt+num;
			all_cards.remove(hilt+" "+num);
		}

		//出力
		for(int i=0;i<all_cards.size();i++){
			System.out.println(all_cards.get(i));
		}
	}

}



Measured memory_bytes: 26252
N, K = map(int, input().split())
D = list(map(int, input().split()))

d = []
for i in range(10):
    if i in D:
        pass
    else:
        d += [i]

def check(i):
    I = str(i) 
    n = len(I) 
    for j in range(n): 
        if int(I[j]) in d: 
            pass
        else: 
            return False
    return True

for i in range(N, 10**5 + 1): 
    if check(i): 
        print (i) 
        exit()


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <cstring>
using namespace std;

int main() {
	string str; //文字列
	getline(cin,str);

	for(int i=0;i<=str.size();i++)
		str[i]=toupper(str[i]);
	
	cout << str << endl;
	return 0;
}


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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int MAX = 103;
int G[MAX][MAX];
int color[MAX];
int nt[MAX], d[MAX], f[MAX];
int tt, n;

int next(int u) {
  for (int v=nt[u]; v<n; v++) {
    nt[u] = v + 1;
    if (G[u][v]) return v;
  }
  return -1;
}

void dfs_visit(int r) {
  memset(nt, 0, sizeof(nt));
  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  d[r] = ++tt;

  while (!S.empty()) {
    int u = S.top();
    int v = next(u);
    if (v != -1) {
      if (color[v] == WHITE) {
	color[v] = GRAY;
	d[v] = ++tt;
	S.push(v);
      }
    } else {
      S.pop();
      color[u] = BLACK;
      f[u] = ++tt;
    }
  }
}

void dfs() {
  memset(color, WHITE, sizeof(color));
  memset(nt, 0, sizeof(nt));
  tt = 0;

  rep(u,n) {
    if (color[u] == WHITE) dfs_visit(u);
  }
  rep(i,n) {
    cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
  }
}

int main() {

  cin >> n;
  rep(i,n) memset(G[i], WHITE, sizeof(G[i])); // init
  int u, k;
  rep(i,n) {
    cin >> u >> k;
    rep(j,k) {
      int t;
      cin >> t;
      G[i][t-1] = 1;
    }
  }

  dfs();

  return 0;
}



Measured memory_bytes: 3128
def main():
    from sys import stdin
    input = stdin.readline
    n, m = map(int, input().split())
    s = [i == "B" for i in input()]
    ab = [list(map(int, input().split())) for _ in [0]*m]
    g = [set() for _ in [0]*n]
    [g[a-1].add(b-1) for a, b in ab]
    [g[b-1].add(a-1) for a, b in ab]

    g2 = [[0, 0] for _ in [0]*n]

    for i in range(n):
        for j in g[i]:
            g2[i][s[j]] += 1

    ss = []
    for i, (j, k) in enumerate(g2):
        if (j == 0 and k > 0) or (j > 0 and k == 0):
            ss.append(i)

    while ss:
        i = ss.pop()
        c = s[i]
        for j in g[i]:
            if i != j:
                g[j].remove(i)
            g2[j][c] -= 1
            p, q = g2[j]
            if (p == 0 and q > 0) or (p > 0 and q == 0):
                ss.append(j)
        g[i] = set()

    for i in g:
        if len(i) > 0:
            print("Yes")
            return
    print("No")


main()


Measured memory_bytes: 136836
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn solve(_n: usize, _m: usize, p_ys: &mut Vec<(usize, usize)>) -> Vec<(usize, String)> {
    let mut p_ys_i: Vec<(usize, usize, usize)> = p_ys
        .iter()
        .enumerate()
        .map(|(i, &(p, y))| (p, y, i))
        .collect();

    p_ys_i.sort();

    let mut result = vec![];

    let mut current_pref: usize = 0;
    let mut city_num = 0;

    for &(p, _y, i) in p_ys_i.iter() {
        if current_pref != p {
            current_pref = p;
            city_num = 1;
        } else {
            city_num = city_num + 1
        };

        result.push((i, format!("{0: >06}{1: >06}", p, city_num)));
    }
    result
}

fn main() {
    input!(n: usize, m: usize, p_ys: [(usize, usize); m],);

    let mut p_ys = p_ys;
    let mut result = solve(n, m, &mut p_ys);

    result.sort_by(|&(i1, _), &(i2, _)| i1.cmp(&i2));

    for t in result.iter() {
        println!("{}", t.1);
    }
}


Measured memory_bytes: 18800
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	ll n;
	cin >> n;
	
	ll ans = 0;
	n--;
	
	if( n % 2 == 0 ) ans = n / 2 * (n + 1);
	else ans = (n + 1) / 2 * n;
	
	cout << ans << endl;
	
	return 0;
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define sz size()

const int MOD = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(0);
	int i, j, k, n;
	
	cin >> n;
	int a[n][n];

	for(i=0;i<n;++i)
		for(j=0;j<n;++j)
			cin >> a[i][j];

	auto add = [](int &x, int y)
	{
		x += y;
		if(x >= MOD)
			x -= MOD;
	};

	vector<int> dp(1 << n);
	dp[0] = 1;
	for(int mask=0;mask<(1<<n);++mask)
	{
		i = __builtin_popcount(mask);
		for(j=0;j<n;++j)
		{
			if(a[i][j] and !(mask & (1 << j)))
			{
				add(dp[mask | (1 << j)], dp[mask]);
			}
		}
	}

	cout << dp[(1 << n) - 1] << "\n";

	return 0;
}

Measured memory_bytes: 8448
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
child =[0]*(N+1)
child[0] =2

#根→葉に向かって、子の最大値
if N ==0 :
    if A[0] ==1:
        child[0] =0
    else:
        print(-1)
        exit()

#A[0] ==0はエラー＝根は頂点１つ（N=0の時はOK)
else:
    if A[0] !=0:
        print(-1)
        exit()
    else:
        for i in range(1,N):
            child[i] =2*(child[i-1] -A[i])
            if child[i]<0: #子がマイナスはありえない
                print(-1)
                exit()

        #葉→根に向かって子と葉の関係を見る
        if child[N-1] *2 <A[N]:
            print(-1)
            exit()
        else:
            child[N-1] =min(A[N],child[N-1])
        for i in range(N-2,-1,-1):
            child[i] =min(child[i],child[i+1] +A[i+1] )

print(sum(child) +1) #根も頂点、＋１

Measured memory_bytes: 674216
#include<iostream>
#include<cmath>
#include<queue>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
#include<utility>
#include<set>
#include<map>
#include<stack>
#include<vector>
#define inf 0x3f3f3f3f
using namespace std;
int T;
int n;
int x,a,b;
char s[100000+100];
int cnt[26];
int main()
{
   while(~scanf("%s",s))
   {
       memset(cnt,0,sizeof(cnt));
       int len = strlen(s);
       for(int i = 0;i<len;i++)
       {
           cnt[s[i]-'a']++;
       }
       int falg = 0;
       for(int i = 0;i<26;i++){
            if(cnt[i]==0){
                printf("%c",i+'a');
                falg = 1;
                break;
            }
       }
       if(!falg)
        cout<<"None"<<endl;
    else
        cout<<endl;
   }
}


Measured memory_bytes: 384
#!/usr/bin/env ruby
require 'prime'

n = STDIN.readline.strip.to_i

def fact(n)
  (1..n).inject(:*) || 1
end

f = fact(n)
factors = Prime.prime_division(f)
# puts "#{factors}"
c75 = factors.find_all{|f| f[1] >= 74}.map{|f| f[0]}
c25 = factors.find_all{|f| f[1] >= 24}.map{|f| f[0]}
c15 = factors.find_all{|f| f[1] >= 14}.map{|f| f[0]}
c5 = factors.find_all{|f| f[1] >= 4}.map{|f| f[0]}
c3 = factors.find_all{|f| f[1] >= 2}.map{|f| f[0]}
# puts "c5:#{c5}, size: #{c5.size}"
# puts "c3:#{c3}, size: #{c3.size}"
# c5C2 = |c5| * |c5-1| / 2
c75 = c75.size
c25_3 = c25.size * (c3.size - 1)
c15_5 = c15.size * (c5.size - 1)
c5_5_3 = c5.size * (c5.size - 1) / 2 * (c3.size - 2)
ans = c75 + c25_3 + c15_5 + c5_5_3 
puts ans


Measured memory_bytes: 2044
//itp1_10d
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
 double m1,m2,m3,m4,temp;
 int n;
 cin>>n;
 vector<int> x(n,0);
 vector<int> y(n,0);
 for(int i=0;i<n;i++)
  cin>>x[i];
 for(int i=0;i<n;i++)
  cin>>y[i];
 m1=0;
 for(int i=0;i<n;i++)
  m1+=1.0*abs(x[i]-y[i]);
 temp=0;
 for(int i=0;i<n;i++){
  temp+=1.0*(x[i]-y[i])*(x[i]-y[i]);
  m2=pow(temp,1.0/2.0);
 }
 temp=0;
 for(int i=0;i<n;i++){
  int j=abs(x[i]-y[i]);
  temp+=j*j*j;
  m3=pow(temp,1.0/3.0);
 }
 temp=0;
 for(int i=0;i<n;i++){
  int j=abs(x[i]-y[i]);
  if(j>temp)
   temp=j;
  }
  m4=temp;
 printf("%.6f\n",m1);
 printf("%.6f\n",m2);
 printf("%.6f\n",m3);
 printf("%.6f\n",m4);

 return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      x[j]++;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += i * x[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 42332
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(double i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int const INF = 1000000;
int main(){
    ll n,k;
    cin>>n>>k;
    map<ll,ll> m;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        m[a]+=b;
    }
    ll sum=k;
    for(auto itr=m.begin();itr!=m.end();itr++){
        sum-=min(sum,itr->second);
        if(sum==0){
            cout<<(itr->first)<<endl;
            return 0;
        }
        
        
    }
    
    return 0;
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  uint64_t g = gcd(m,n);
  if(m%g==0) return (m/g)*n;
  if(n%g==0) return (n/g)*m;
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t 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 maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

// keyが降順ソートされるmap
// map<int, int, std::greater<int>> edges;

signed main() {
  int n;
  cin >> n;
  
  ull l = 1;
  ull t = 1;
  for(int i=0;i<n;i++){
    cin >> t;
    l = lcm(l,t);
  }
  cout << l << endl;

  return 0;
}


Measured memory_bytes: 3660
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#define MAXN 200005
#define MAXM
#define LL long long
#define LD long double
using namespace std;

int h, w, n, d;

struct A {int x, y;} a[MAXN];

bool CMP(A c, A d)
{
	if(c.x==d.x) return c.y<d.y;
	return c.x<d.x;
}

int main()
{
	scanf("%d%d%d", &h, &w, &n);
	for(int i=1; i<=n; i++) scanf("%d%d", &a[i].x, &a[i].y);
	sort(a+1, a+n+1, CMP);
	for(int i=1; i<=n; i++)
	{
		if(a[i].x-a[i].y>=d+1)
		{
			printf("%d\n", a[i].x-1);
			return 0;
		}
		if(a[i].x-a[i].y==d) d++;
	}
	printf("%d\n", h);
	return 0;
}


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

bool solve(const vector<string>& w){
  const int n = w.size();

  for(int i = 0; i < n-1; ++i){
    if(w[i].back() != w[i+1].front()){
      return false;
    }
  }

  for(int i = 0; i < n; ++i){
    for(int j = i+1; j < n; ++j){
      if(w[i] == w[j]){
        return false;
      }
    }
  }
  return true;
}

vector<string> input(){
  int n; cin >> n;
  vector<string> w(n);
  for(int i = 0; i < n; ++i){
    cin >> w[i];
  }
  return w;
}

int main(){
  const vector<string> w = input();
  if(solve(w)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;
ll mod = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> id(m);
    vector<int> p(m), y(m);
    for( int i = 0; i < m; i++ ) {
        cin >> p[i] >> y[i];
        id[i] = make_pair( y[i], p[i] );
    }
    vector<int> num(n+1, 0);
    sort( id.begin(), id.end() );
    vector<map<int, int>> vm(n+1);
    for( int i = 0; i < m; i++ ) {
        vm[id[i].second][id[i].first] = num[id[i].second]+1;
        num[id[i].second]++;
    }
    for( int i = 0; i < m; i++ ) {
        printf( "%06d%06d\n", p[i], vm[p[i]][y[i]]);
    }

    return 0;  
}

Measured memory_bytes: 12928
A,B,C,D,E,F = map(int,input().split())
xmax = 100*A
kmax = 0
for n in range(31):
    for m in range(31):
        x = 100*(n*A+m*B)
        ymax = min((n*A+m*B)*E,F-100*(n*A+m*B))
        for k in range(ymax,ymax-C-1,-1):
            t = 0
            flag = 0
            while k-t*D>=0:
                if (k-t*D)%C==0:
                    flag = 1
                    break
                t += 1
            if flag==1:
                if kmax*(x+k)<k*(xmax+kmax):
                    xmax = x
                    kmax = k
print(xmax+kmax,kmax)

Measured memory_bytes: 40048
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define sint(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;


typedef pair<int,int>P;

const int MAX_N = 100005;

int n;

int main()
{
    while(1){
        cin >> n;
        if(n == 0){
            break;
        }
        vector<int> vec(n);
        rep(i,n){
            cin >> vec[i];
        }
        int ans = INF;
        rep(i,n){
            for(int j = i+1;j<n;j++){
                ans = min(ans,abs(vec[i]-vec[j]));
            }
        }
        cout << ans << "\n";
    }
}

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

using namespace std;

const int max_n = 2e5 + 5;

int tab[max_n];

map<int, int> zliczanie;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, wynik = 0;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> tab[i];
        zliczanie[tab[i]]++;
    }
    sort(tab, tab + n);
    for (int i = n - 1; i >= 0; i--){
        if (!zliczanie[tab[i]])
            continue;
        zliczanie[tab[i]]--;
        if (zliczanie[(2 << __lg(tab[i])) - tab[i]]){
            zliczanie[(2 << __lg(tab[i])) - tab[i]]--;
            wynik++;
        }
    }
    cout << wynik << "\n";
    return 0;
}

Measured memory_bytes: 23040
N = int(input())
A = list(map(int, input().split()))
B = [v-(i+1) for i,v in enumerate(A)]
#print(A)

B.sort()
#print(B)
#print(B[len(B)//2])
if len(B) % 2 == 1:
  pt = B[len(B)//2]
  val = sum([abs(pt - i) for i in B])
else:
  ptA = B[len(B)//2]
  valA = sum([abs(ptA - i) for i in B])
  ptB = B[len(B)//2 + 1]
  valB = sum([abs(ptB - i) for i in B])
  if valA < valB:
    val = valA
  else:
    val = valB
print(val)


Measured memory_bytes: 27928
n = int(input())
mod = 1000000007


def _mod(x, y):
    res = 1
    for i in range(y):
        res = (res * x) % mod
    return res


ans = _mod(10, n) - _mod(9, n) - _mod(9, n) + _mod(8, n)
ans %= mod
print(ans)


Measured memory_bytes: 9172
//累積和をmod Mでグループ分けすると、どのグループから2個取るか？という問題になるので、はい。
#include <iostream>
#include <map>
#define int long long
using namespace std;

int n, m;
int a[100001];
map<int, int> cnt;

signed main() {
	int i;
	
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		cin >> a[i + 1];
		a[i + 1] += a[i];
		a[i + 1] %= m;
	}
	
	for (i = 0; i <= n; i++) {
		if (cnt.find(a[i]) == cnt.end()) cnt[a[i]] = 0;
		cnt[a[i]]++;
	}
	
	int ans = 0;
	for (map<int, int>::iterator it = cnt.begin(); it != cnt.end(); it++) {
		ans += it->second * (it->second - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math
def nC2(n):
  # n = 0 -> 0
  # n = 1 -> 0
  if n<2:
    return 0
  return math.factorial(n) // (math.factorial(n - 2) * 2)
n,m = map(int, input().split())
# 135 3C2
# 2468 4C2
# nC2
r=nC2(n)+nC2(m)
print(r)

Measured memory_bytes: 9152
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define ceil(a,b) (a+b-1)/b
#define endl "\n"
const int N=100005;
const int inf=1e18;
const double eps=1e-9;

#define oa(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define o1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define o2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define o3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define o4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

int pow(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
int pow1(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
            res=res*a;
            res%=mod;
        }
        a=a*a;
        a%+mod;
        b>>=1;
    }
    return res;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	char c;
    cin>>c;
    if(c>='a'&&c<='z'){
        cout<<"a";
    }else{
        cout<<"A";
    }







	
return 0;
}


Measured memory_bytes: 3632
/*"Everything in the universe is balanced. Every disappointment
   you face in life will be balanced by something good for you!
                Keep going, never give up."            */

#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define rep(i,a,b) for(int i=a; i<=b; ++i)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define nl '\n'
#define pb push_back
#define all(a) a.begin(),a.end()
#define P pair<ll,ll> 
#define F first
#define S second
const ll N=1e6+9;
const ll mod=1e9+7;
ll powerk(ll x, ll y);
ll mul(ll x, ll y);
ll add(ll x, ll y);
ll sub(ll x, ll y);

ll a[N];
ll dp[500][500];

ll go(ll left, ll right){
	//cout<<left<<" "<<right<<nl;
	if(left==right)return 0;
	if(dp[left][right]!=1e18)return dp[left][right];
	rep(i,left,right-1){
		dp[left][right] = min(dp[left][right],a[right]-a[left-1]+go(left,i)+go(i+1,right));
	}
	//cout<<left<<" "<<right<<" "<<dp[left][right]<<nl;
	return dp[left][right];
}

void solve()
{    
  ll n,m;
  cin>>n;
  rep(i,1,n)cin>>a[i],a[i]+=a[i-1];
  rep(i,1,n)rep(j,1,n)dp[i][j]=1e18;
  cout<<go(1,n)<<nl;
  /*rep(i,1,n)dp[i][i]=0;
  rep(i,2,n){
  	rep(j,i,n){
  		ll k = j-i+1 ;
  		rep(l,k,j-1){
  			if(dp[k][j]>a[j]-a[k-1]+dp[k][l]+dp[l+1][j]){
  				dp[k][j] = dp[k][l]+dp[l+1][j]+a[j]-a[k-1];
  			}
  			//if(k==1 && j==4)cout<<dp[k][j]<<" "<<dp[k][j]<<nl;
  		}
   	}
  }
  cout<<dp[1][n];*/
 
}


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    while(t--)
    {
      solve();
    }  
}
ll mul(ll x, ll y){return (x*y)%mod;}
ll add(ll x, ll y){return (x+y)%mod;}
ll sub(ll x, ll y){return (x-y+mod)%mod;}
ll powerk(ll x, ll y)
{
  if(y==0)return 1;
  if(y==1)return x%mod;
  if(y&1)
    return ((powerk((x*x)%mod, y/2)%mod)*x)%mod;
  else return powerk((x*x)%mod,y/2)%mod;
}

// Xorawar

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  priority_queue<int> pq;
  for (int i = 0; i < N; i++){
    pq.push(A[i]);
  }
  for (int i = 0; i < M; i++){
    int x = pq.top();
    pq.pop();
    pq.push(x / 2);
  }
  long long ans = 0;
  while (!pq.empty()){
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;
}

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

const ll INF = 1LL << 60;

ll N, A, B, C;
vector<P> q;
vector<ll> d;

int main() {
    cin >> N >> A >> B >> C;
    d.push_back(A);
    d.push_back(B);
    d.push_back(C);

    rep(i, N) {
        string s;
        cin >> s;
        int a, b;
        if (s == "AB") {
            a = 0;
            b = 1;
        } else if (s == "BC") {
            a = 1;
            b = 2;
        } else {
            // AC
            a = 0;
            b = 2;
        }

        q.emplace_back(a, b);
    }

    // cout << q.size() << endl;
    // rep(i, q.size()) {
    //     cout << q[i].first << " " << q[i].second << endl;
    // }

    // for (int i = 3; i <= 10; i++) {
    //     cout << q[i].first << " " << q[i].second << endl;
    // }
    // return 0;

    // vector<char> ans;
    string ans = "";
    auto add = [&](int a, int b) {
        d[a]++;
        d[b]--;

        // ans.push_back('A' + a);
        ans += 'A' + a;
    };

    rep(i, N) {
        int a = q[i].first;
        int b = q[i].second;

        if (d[a] == 0 && d[b] == 0) {
            cout << "No" << endl;
            return 0;
        }

        if (d[a] == 0) {
            add(a, b);
        } else if (d[b] == 0) {
            add(b, a);
        } else {
            if (i == N - 1) {
                // どっちでもいい
                add(a, b);
                continue;
            }
            // cout << "other" << endl;
            int na = q[i + 1].first;
            int nb = q[i + 1].second;
            // cout << "other: " << na << " " << nb << endl;
            if (a == na || a == nb) {
                add(a, b);
            } else {
                add(b, a);
            }
        }
    }

    cout << "Yes" << endl;
    rep(i, N) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4300
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> P;
 
#define M 1005
#define MOD 1000000007
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
//	freopen("input.txt","rt",stdin);
	
	int n;
	cin>>n;
	
	vector<int> adjList[n+1];
	for(int i=2;i<=n;i++)
	{
		int x;
		cin>>x;
		adjList[x].ep(i);
	}
	
	
	for(int i=1;i<=n;i++)
		cout<<(int)adjList[i].size()<<"\n";
}


Measured memory_bytes: 14564
a,b=map(int,input().split())
flg=0
for i in range(1001):
    c=int(i*1.08)-i
    d=int(i*1.1)-i
    if c==a and b==d:
        print(i)
        flg=1
        exit()
if flg==0:
    print(-1)



Measured memory_bytes: 8928
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int sum = 0;
	rep(i, n) sum += a[i];
	int cnt = 0;
	rep(i, n) {
		if (a[i] * 4 * m >= sum) cnt++;
	}
	if (cnt >= m) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define ll                 long long                            
#define ra                 return a;                                          
#define pb                 push_back                                                     
#define sti                stack<ll>
#define spi                stack<pair<ll,ll>>
#define S                  second
#define msi                map<string,ll >
#define msi                map<string,ll >
#define mii                map<ll ,ll >
#define dbg(x)             { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y)          { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z)        { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define mis                map<ll , string>
#define rep(i,a,b)         for(ll  i=a;i<b;i++)
#define mpi                map<pair<ll ,ll >,ll >                                                
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define F                  first 
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define pqi                priority_queue<ll>
#define si                 set <ll>
#define vs                 vector<string>
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define hell               1000000007
#define bs                 binary_search
#define mp                 make_pair
#define qi                 queue<ll>
#define qs                 queue<string>
#define qpi                queue<pair<ll,ll>>
#define qps                queue<pair<ll,string>> 
#define endl               '\n' 
#define itr(a,it)          for(typeof(a.begin()) it=a.begin();it!=a.end();it++)// This will produce const_iterator for const object and normal iterator for non-const object
#define ss                 set<string>
using namespace std;
#define N  300005
ll dp[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
//    cin>>t;
    while(t--)
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    rep(i,0,n)
    cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    rep(i,1,n)
    {
    	dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
    	for(ll j=i-2;j>=0;j--){
    		if(i-j<k+1)
    		{
    			dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
    		}
    		else break;
    	}
    }
    cout<<dp[n-1];
}
    return 0;
}

Measured memory_bytes: 1792
import sys

def total(f):
    t = 0
    while True:
        s = f.read(1)
        if s:
            c = ord(s[0]) - 48
            if 0 <= c <= 9:
                t += c
                continue
        break
    return t

t = total(sys.stdin)
print('Yes' if t % 9 == 0 else 'No')


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

int main(){
  int N;
  cin >> N;
  
  int l, r;
  int counter;
  
  for (int i = 0; i < N; i++){
    cin >> l >> r;
    counter += (r - l + 1);
  }
  
  cout << counter << endl;
}

Measured memory_bytes: 256
import Data.Char(digitToInt)
main = do
  nkIn <- getLine
  slsIn <- getLine
  let
    [n,k] = map read $ words nkIn :: [Int]
    state = func1 slsIn '-' 0 []
    header = digitToInt $ head slsIn
    ans = func2 state state header header k 0 0
    func1 slsIn prev contLen ret
      | slsIn == []        = tail (reverse (contLen:ret))
      | head slsIn == prev = func1 (tail slsIn) prev (contLen+1) ret
      | otherwise          = func1 (tail slsIn) (head slsIn) 1 (contLen:ret)
    func2 state1 state2 hd1 hd2 k temp ret
      | state1 == []                               = (max temp ret)
      | hd1 == 1                                   = func2 (tail state1) state2 0 hd2 k (temp+(head state1)) (max temp ret)
      | hd1 == 0 && k > 0                          = func2 (tail state1) state2 1 hd2 (k-1) (temp+(head state1)) (max temp ret)
      | hd1 == 0 && k <= 0 && hd2 == 1             = func2 state1 (tail state2) hd1 0 k (temp-(head state2)) (max temp ret)
      | hd1 == 0 && k <= 0 && hd2 == 0             = func2 (tail state1) (tail state2) 1 1 k (temp+(head state1)-(head state2)) (max temp ret)
      | otherwise  = -1
    in
      putStrLn $ show ans


Measured memory_bytes: 35196
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#define REP(i,m,n) for(int i = (int) (m);i < (int) (n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

int n;

int main() {

	while (cin >> n) {
		if (n == 0) break;
		int c = 0;
		n = 1000 - n;
		while (n >= 500) {
			n -= 500;
			c++;
		}
		while (n >= 100) {
			n -= 100;
			c++;
		}
		while (n >= 50) {
			n -= 50;
			c++;
		}
		while (n >= 10) {
			n -= 10;
			c++;
		}
		while (n >= 5) {
			n -= 5;
			c++;
		}
		while (n >= 1) {
			n -= 1;
			c++;
		}
		cout << c << endl;
	}

	return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
#include<cmath>
#include<queue>
#include<algorithm>

using namespace std;
using ll=long long;
using db=double;

typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<bool> vbl;

int inf=(1LL<<31)-1;
int MOD=1000000007;

#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define f_i(a,b) for(int i=a;i<=b;i++)
#define f_j(a,b) for(int j=a;j<=b;j++)
#define vvii(c,a,b) vector<vector<ii>> c(a,vector<ii>(b,0))
#define vvll(c,a,b) vector<vector<ll>> c(a,vector<ll>(b,0))
#define vvstr(c,a,b) vector<vector<string> c(a,vector<string>(b,0))
#define vvbol(c,a,b) vector<vector<bool>> c(a,vector<bool>(b,true))

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    int count=0;
    fi(0,s.size())
    {
        if(s.at(i)!=t.at(i))
        {
            count++;
        }
    }
    cout << count << endl;

    return(0);
}

Measured memory_bytes: 3864