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


int main(){
    string T,dS;
    cin >> dS >> T;
    if(dS.size()<T.size()){
        cout <<"UNRESTORABLE";
        return 0;
    }
    //合致しているのがあればaでうめる
    for(int i=0;i<dS.size()-T.size()+1;i++){
        if(dS[dS.size()-1-i]==T[T.size()-1]){
            int j=0;
            while(j<T.size()){
                if(dS[dS.size()-1-i-j]!=T[T.size()-1-j]){
                    break;
                }else{
                    j++;
                }
                if(j==T.size()){
                    for(int k=0;k<dS.size();k++){
                        if(dS[k]=='?'){
                            dS[k]='a';
                        }
                    }
                    cout << dS;
                    return 0;
                }
            }
        }
    }
    //合致しているのがなければ下から?を埋める
    for(int i=0;i<dS.size()-T.size()+1;i++){
        if((dS[dS.size()-1-i]==T[T.size()-1])||(dS[dS.size()-1-i]=='?')){
            int j=0;
            while(j<T.size()){
                if((dS[dS.size()-1-i-j]!=T[T.size()-1-j])&&(dS[dS.size()-1-i-j]!='?')){
                    break;
                }else{
                    j++;
                }
                if(j==T.size()){
                    for(int k=0;k<T.size();k++){
                        dS[dS.size()-1-i-k]=T[T.size()-1-k];
                    }
                    for(int k=0;k<dS.size();k++){
                        if(dS[k]=='?'){
                            dS[k]='a';
                        }
                    }
                    cout << dS;
                    return 0;
                }
            }
        }
    }
    cout << "UNRESTORABLE";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long n,m,a[100001],b[100001],ans[100001],par[100001],Size[100001],num;
int root(int x){
    if(par[x]==x)return x;
    else return par[x]=root(par[x]);
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)par[i]=i,Size[i]=1;
    for(int i=1;i<=m;i++)cin>>a[i]>>b[i];
    num=n*(n-1)/2;
    for(int i=m;i;i--){
        ans[i]=num;
        int x=root(a[i]),y=root(b[i]);
        if(x!=y){
            num-=Size[x]*Size[y];
            Size[x]+=Size[y];
            par[y]=x;
        }
    }
    for(int i=1;i<=m;i++)cout<<ans[i]<<endl;
}


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

#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)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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(){
	int N,A,B;
	cin >> N >> A >> B;
	cout << min(A*N,B) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,m,idx;
string s;
pair< ll , ll > dp[100010];
priority_queue< pair<ll, pair< ll , ll > > > pq;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m >> s;
    dp[ n ] = { 0 , 0 };
    pq.push( { 0,  { -n , -n } } );

    for(ll i=n-1; i>=0; i--){
        if( s[i]=='1' ) continue;
        while( !pq.empty() && -pq.top().se.se-i > m ) pq.pop();

        if( pq.empty() ){
            cout << "-1";
            return 0;
        }

        dp[ i ] = { 1-pq.top().fi , -pq.top().se.se-i };
        pq.push( { -dp[i].fi , { -i
                 , -i } } );
    }

  //  for(ll i=0; i<=n; i++) cout << dp[i].fi << " " << dp[i].se << "\n"; return 0;

    while( idx < n ) cout << dp[ idx ].se << " " , idx+=dp[ idx ].se;

    return 0;
}


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

#define fre freopen("in.txt","r",stdin)
#define ll long long
#define abs(x) ((x)>0?(x):-(x))
#define mod 1000000007
#define scand(x) scanf("%d",&x);
#define scanlld(x) scanf("%I64d",&x);
#define scans(x) scanf("%s",x);
#define printd(x) printf("%d",x);
#define printlld(x) printf("%I64d",x);
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf (1<<30)
#define forup(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define boost ios_base::sync_with_stdio(0)
#define MAXN 1000003
ll a[MAXN];
vector<int>v;
int main()
{
	boost;
	//fre;
	int n,ans=0;
	cin>>n;
	forup(i,1,n+1){
		cin>>a[i];
		if(a[i]!=a[i-1])v.pb(i);
	}
	v.pb(n+1);
	for(int i=1;i<v.size();i++){
		ans+=(v[i]-v[i-1])/2;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
fn main() {
    let (n, m): (usize, usize) = (read::<usize>(), read::<usize>());
    let mut indeg = vec![0; n];
    let mut adjl = vec![vec![]; n];
    let mut leaves = vec![];
    for _ in 0..m {
        let (x, y): (usize, usize) = (read::<usize>() - 1, read::<usize>() - 1);
        adjl[x].push(y);
        indeg[y] += 1;
    }
    for i in 0..n {
        if indeg[i] == 0 {
            leaves.push(i);
        }
    }
    let mut ans = 0;
    while leaves.len() != 0 {
        let mut n_leaves = vec![];
        for l in leaves {
            for rem_to in &adjl[l] {
                indeg[*rem_to] -= 1;
                if indeg[*rem_to] == 0 {
                    n_leaves.push(*rem_to);
                }
            }
            adjl[l] = vec![];
        }
        leaves = n_leaves;
        ans += 1;
    }
    println!("{}", ans - 1);
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: isize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 10492
#include<bits/stdc++.h>
using namespace std;
string S[999],a;
int pass,miss[999],over[999],misscnt,totalcnt,n,m,i;
int main(){
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>S[i]>>over[i];
	}
	for(i=0;i<n;i++){
		pass=0;
		while(pass!=S[i].size()){
			cout<<"? "<<S[i]<<endl;
			cin>>a;
			totalcnt++;
			if(tolower(a[0])==tolower(S[i][pass])){ 
				S[i][pass]='_';pass++;misscnt++; 
			}
			else{
				miss[i]++;
				if(miss[i]>over[i]){
					m--;break;
				}
			}
		}
		if(m<=0){ 
			cout<<"! Game Over"<<endl;return 0; 
		}
	}
	cout<<fixed<<setprecision(1)<<"! Game Clear "<<(double)((int)(1000*misscnt/totalcnt)/10.0)<<endl;
}

Measured memory_bytes: 1304
#include <iostream>
using namespace std;
static const int N = 100;

int main() {
  int M[N][N];
  int n, u, k, v;

  cin >> n;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      M[i][j] = 0;
    }
  }

  for (int i = 0; i < n; ++i) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; ++j) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (j) cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }
}



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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    double t, x;
    cin >> t >> x;

    cout <<setprecision(100)<< t/x <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(ll i=0; i<n; i++)
#define REPR(i, n) for(ll i=n; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define pye cout << "Yes" << endl;
#define pno cout << "No" << endl;
#define prin(num) cout << num << endl;
#define sprin(str) cout << "str" << endl;
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100001
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll memo[MAX];

ll rec(ll n) {
    if(n==0) return 0;
    if(memo[n]!=-1) return memo[n];
    ll res=n;
    
    for(ll psix=1; psix<=n; psix*=6)
        res=min(res, rec(n-psix)+1);
    
    for(ll pnin=9; pnin<=n; pnin*=9)
        res=min(res, rec(n-pnin)+1);
    
    return memo[n]=res;
}


int main() {
    ll N; cin >> N;
    for(ll i=0; i<=N; i++) memo[i]=-1;
    
    cout << rec(N) << endl;
}


Measured memory_bytes: 5760
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;

int main(){
    string s;
    cin >> s;
    rep(i,s.size()){
      s[i]='x';
    }
    cout << s << endl; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
int main(){
  int n;
  cin >> n;
  vector<int> h(n);  
  rep(i,n)cin >> h[i];
  int len = 0;
  int now;
  int nmax = -1;
  for(int i = 1;i < n ;i++){
   //  cout << i << len << endl;
    now = h[i-1];
    if(h[i] > now){
      nmax = max(nmax,len);
      len = 0;
    }
    else{
       len++;
    }
  }
  nmax = max(nmax,len);
  cout << nmax << endl;
}

Measured memory_bytes: 640
char = ["a","b","c","d","e","f","g","h","i","j"]

normal_form = ["a"]

n = int(input())
for i in range(n-1):
  new_normal_form = []
  for s in normal_form:
    usingchars = len(set(s))
    for i in range(usingchars+1):
      new_normal_form.append(s+char[i])
  normal_form = new_normal_form

for s in normal_form:
  print(s)

Measured memory_bytes: 12976
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int m=sc.nextInt();
  int[]po=new int[n];
  for(int i=0;i<m;i++){
  po[sc.nextInt()-1]++;
    po[sc.nextInt()-1]++;
  }
  for(int i=0;i<n;i++)System.out.println(po[i]);
}
}

Measured memory_bytes: 22996
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,m; cin >> n >> m;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }

    vector<ll> cnt(m * 2 + 1), val(m * 2 + 1);
    ll sum = 0;
    rep(i,0,n-1){
        ll s, t;
        s = a[i], t = a[i+1];
        if(s > t)t += m;

        sum += (t - s);

        if(t - s == 1)continue;
        cnt[s + 2]++;cnt[t + 1]--;
        val[t + 1] -= t - s - 1;
    }

    rep(i,0,m*2){
        cnt[i + 1] += cnt[i];
    }
    debug(val, cnt);
    rep(i,1,m*2+1){
        val[i] += val[i-1] + cnt[i];
    }

    debug(val, cnt);
    rep(i,m,2*m) val[i - m] += val[i];
    debug(val);
    cout << sum - *max_element(all(val)) << endl;
}

Measured memory_bytes: 7112
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<long long>a(n);
    long long sum=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(i==0)continue;
        sum+=a[i];
    }
    long long dp[200005];
    dp[0]=a[0];
    long long ans=abs(sum-dp[0]);
    for(int i=1;i<n-1;i++){
        dp[i]+=(dp[i-1]+a.at(i));
        sum-=a.at(i);
        ans=min(ans,abs(sum-dp[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 6472
#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;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
template <typename T>
#define all(v) v.begin(),v.end()
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc;
    tc = 1;  
    while (tc--)
    {
        string s;
        cin >> s;
        int n = s.size();
        if(n%2==0){
            cout << "No";
            return 0;
        }
        string ss = s;
        reverse(all(ss));
        if(ss!=s){
            cout << "No";
            return 0;
        }
        string v = s.substr(0, n/ 2);
        string u = s.substr((n+3)/2-1, n);
       // cout << v << " " << u << endl;
        string g = v, h = u;
        reverse(all(g));
        reverse(all(h));
        if(g==v&&h==u){
            cout << "Yes";
        }
        else{
            cout << "No";
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define prique priority_queue
#define Fi first
#define Se second
signed main(){
    string s;
    bool b=true;
    cin>>s;
    int l=s.size();
    int ans=(l-1)*9;
    if(s[0]==9)ans+=s[0];
    else ans+=(s[0]-'0')-1;
    for(int i=1;i<l;i++){
        if(s[i]!='9')b=false;
    }
    if(b)ans++;
    if(l==1)ans=s[0]-'0';
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int abs(int a,int b){
  int c=max(a,b)-min(a,b);
  return c;
}
signed main(){
  vector<pair<int,int> > a;
  int b,c;
  int d,e;
  int q=0,w=0,z=0;
  cin>>b>>c;
  for(int i=0;i<b;i++){
    cin>>d>>e;
    a.push_back(make_pair(d,e));
  }		
  sort(a.begin(),a.end());
  while(true){
    if(a[w].second==0) w++;
    a[w].second--;
    q++;
    z+=a[w].first;
    if(q==c) break;
  }
  cout<<z<<"\n";
}


Measured memory_bytes: 2420
def no():
    print("No")
    exit()
H, W = map(int, input().split())
L = [0]*26
for i in range(H):
    for a in input():
        L[ord(a)-97] += 1
t4 = (H//2)*(W//2)
t2 = (H//2)*(W%2)+(H%2)*(W//2)
t1 = (H%2)*(W%2)
#print(L, t4, t2, t1)
for i, n in enumerate(L):
    q, m = divmod(n, 2)
    L[i] = q
    if m==1:
        t1 -= 1
if t1 != 0:
    no()
for i, n in enumerate(L):
    q, m = divmod(n, 2)
    L[i] = q
    if m==1:
        t2 -= 1
if t2 < 0 or t2%2 != 0:
    no()
t4 += t2//2

print("Yes")


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int n;
    cin >> n;
    VI a(n + 1), b(n);
    for (Int i = 0; i < n + 1; ++i) {
        cin >> a[i];
    }
    for (Int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    Int result = 0;
    for (Int i = 0; i < n; ++i) {
        if (a[i] + a[i + 1] < b[i]) {
            result += (a[i] + a[i + 1]);
            a[i] = 0;
            a[i + 1] = 0;
        } else if (a[i] < b[i]) {
            result += b[i];
            a[i + 1] -= (b[i] - a[i]);
            a[i] = 0;
        } else {
            result += b[i];
            a[i] -= b[i];
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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; }

const int INF = 1e9;

int main() {
    int n, k;
    cin >> n >> k;
    int h[n];
    for (int i = 0; i < n; i++) cin >> h[i];
    int dp[n];
    fill(dp, dp+n, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= min(k, n - 1 - i); j++) {
            chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#define ll long long
#define maxn 4001000
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define rep(i,a,b) for(int i=a;i<=b;i++)
const ll P=1e9+7;
using namespace std;
int main(){
	ll a,b;
	cin>>a>>b;
	cout<<a/__gcd(a,b)*b;
}

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

using namespace std;

constexpr int64_t MOD = 1e9+7;

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

  vector<int64_t> nums(N);
  for (int n = 0; n < N; ++n) {
    cin >> nums[n];
  }
  
  vector<vector<int64_t>> cnt(2, vector<int64_t>(61));                              
  for (int64_t n : nums) {
    bitset<61> bs(n);
    for (size_t i = 0; i <= 60; ++i) {
      if (bs.test(i)) {
        ++cnt[1][i];
      } else {
        ++cnt[0][i];
      }
    }
  }
  int64_t result = 0;
  for (size_t i = 0; i <= 60; ++i) {
    result += (static_cast<int64_t>(pow(2, i)) % MOD) * (cnt[0][i] * cnt[1][i] % MOD);
    result %= MOD;
  }
  cout << result << endl;
  
  return 0;
}


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

int main()
{
	int N;
	cin >> N;
	switch (N % 10) {
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon";
		break;
	case 1:
	case 6:
	case 8:
	case 0:
		cout << "pon";
		break;
	default:
		cout << "bon";
		break;
	}
	return 0;
}


Measured memory_bytes: 3600
d, g = list(map(int, input().split()))

ss = []
ps = []
cs = []

for i in range(d):
    p, c = list(map(int, input().split()))
    ps.append(p)
    cs.append(c)
    ss.append(100 * (i + 1))

# d, g = 2, 2000
# ps = [3, 5]
# ss = [100, 200]
# cs = [500, 800]


complete_scores = []
for i in range(d):
    complete_scores.append(ps[i] * ss[i] + cs[i])

# print(ps)
# print(ss)
# print(cs)
# print(complete_scores)

min_answers = sum(ps)
for i in range(2 ** d):
    current_score = 0
    current_answers = 0
    indexes = list(range(d))
    num = i
    for j in range(d):
        if num % 2:
            current_score += complete_scores[j]
            indexes.remove(j)
            current_answers += ps[j]
        num = num // 2

    if current_score >= g:
        min_answers = min(min_answers, current_answers)
        continue

    # print("indexes", indexes)

    for j in reversed(indexes):
        if current_score + ps[j] * ss[j] >= g:
            temp_ans = (g - current_score) // ss[j]
            if current_score + temp_ans * ss[j] >= g:
                current_answers += temp_ans
            else:
                current_answers += temp_ans + 1
            min_answers = min(min_answers, current_answers)
            break
        else:
            current_score += ss[j]
            current_answers += ps[j]

print(min_answers)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    while(1){
        
        int n,x,counter=0;
        scanf("%d%d",&n,&x);
        if(n==0&&x==0)break;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {   
                if(i==j) continue;
                for (int k = 1; k <= n; k++)
                {   
                    if(k==i||j==k) continue;
                    if(i+j+k==x)counter++;
                }
            }
        }
        printf("%d\n",counter/6);
    }
}


Measured memory_bytes: 3244
n=int(input())
y=[input() for i in range(n)]
x=sorted(y)

a=[list(map(str,x[i].split())) for i in range(n)]
b=[]
e=[]

while len(a):
  d=[]
  c=a[0][0]
  b.append(a[0][0])
  d.append(int(a[0][1]))
  a.pop(0)
  while len(a):
    if c==a[0][0]:
      b.append(a[0][0])
      d.append(int(a[0][1]))
      a.pop(0)
    else:
      break
  e+=sorted(d,reverse=True)

for i in range(n):
  print(y.index(b[i]+' '+str(e[i]))+1)

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

int main()
{
    ll x, count = 0;
    cin >> x;
    count = x / 11 * 2;
    x %= 11;
    if (x >= 1 && x <= 6)
        count++;
    else if (x >= 7)
        count += 2;
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    string t = s;
    reverse(t.begin(), t.end());
    string u = s + t;

    string x = s;
    rep(i, n+1) {
        string y = u.substr(i, n);
        if (y < x) x = y;
    }
    if (k == 1) {
        cout << x << endl;
        return 0;
    }

    int cnt = 1;
    rep(i, n) {
        if (i == 0) continue;
        if (x[0] == x[i]) cnt++;
        else break;
    }
    if (cnt == n) {
        cout << x << endl;
        return 0;
    }
    
    string y = x.substr(cnt, n - cnt);
    k--;
    while (cnt < n && k > 0) {
        cnt *= 2;
        k--;
    }

    string ans;
    if (cnt >= n) ans = string(n, x[0]);
    else ans = string(cnt, x[0]) + string(y.begin(), y.begin() + n - cnt);
    cout << ans << endl;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
    cout << "Left" << endl;
    }
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
}
}

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

int main(){
    int n,m,k,tmp,cnt=0;
    cin>>n>>m;
    vector<int> v(m+1,0);
    for(int i=0;i<n;i++){
        cin>>k;
        for(int j=0;j<k;j++){
            cin>>tmp;
            v[tmp]++;
        }
    }
    for(int x:v){
        if(x==n) cnt++;
    }
    cout<<cnt<<"\n";
    return 0;
}


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

int main(){
    int X;
    cin>>X;
    if(X>=1800){
        cout<<"1"<<endl;
    }else if(X>=1600){
        cout<<"2"<<endl;
    }else if(X>=1400){
        cout<<"3"<<endl;
    }else if(X>=1200){
        cout<<"4"<<endl;
    }else if(X>=1000){
        cout<<"5"<<endl;
    }else if(X>=800){
        cout<<"6"<<endl;
    }else if(X>=600){
        cout<<"7"<<endl;
    }else if(X>=400){
        cout<<"8"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%lld",&x);
int main(){
    ll a, b, x;
    sc(a) sc(b) sc(x)
    ll ans;
    ans = b / x;
    ans -= a / x;
    if (a % x == 0) ans += 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var bus = int.Parse(Console.ReadLine());
            var bus1 = int.Parse(Console.ReadLine());
            var train = int.Parse(Console.ReadLine());
            var train1 = int.Parse(Console.ReadLine());

            var travel = Math.Min(bus, bus1) + Math.Min(train, train1);

            Console.WriteLine(travel);
        }
    }
}


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

using namespace std;

#define PB push_back
#define SZ(a) (int)a.size()
#define MP make_pair

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;

int main() {

	int H,N;
	scanf("%d %d", &H, &N);

	for(int i = 0; i < N; i++) {
		int a;
		scanf("%d", &a);
		H-=a;
	}

	if(H <= 0) printf("Yes\n");
	else printf("No\n");

	return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
//B - Buildings are Colorful!
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

void recursive_comb(vector<ll>& indexes, ll s, ll rest, std::function<void(vector<ll>&)> f) {
    if (rest == 0) {
        f(indexes);
    } else {
        if (s < 0) return;
        recursive_comb(indexes, s - 1, rest, f);
        indexes.at(rest - 1) = s;
        recursive_comb(indexes, s - 1, rest - 1, f);
    }
}
// nCkの組み合わせに対して処理を実行する
void foreach_comb(ll n, ll k, std::function<void(vector<ll>&)> f) {
    vector<ll> indexes(k);
    recursive_comb(indexes, n - 1, k, f);
}
//foreach_comb(N-1, 2, [&](vector<ll>& indexes) {
//    dump(indexes[0],indexes[1]);
//});

int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in");
    //std::ifstream in("./input.txt");
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N,K; cin>>N>>K;
    vector<ll> an(N);
    for(auto&& a:an) {cin>>a;}

    auto calc_cost = [N](const vector<ll>& mvd,vector<ll> ann)->ll{
        ll ret=0;
        ll maxh=ann.at(0);
        FOR(i,0,N){
            auto it = find(mvd.begin(),mvd.end(), i);
            if(i!=0 && it != mvd.end()){
                auto&& a=ann.at(i);
                if(maxh<a){
                } else {
                    ll add=maxh-a+1;
                    ret += add;
                    a += add;
                }
            }
            maxh=max(ann.at(i),maxh);
        }
        return ret;
    };

    ll ans=INT64_MAX;
    foreach_comb(N,K,[&](vector<ll>& indexes) {
        dump(indexes);
        ans = min(ans,calc_cost(indexes,an));
    });
    cout<<ans<<endl;

    return 0;
}

struct Info{
    ll cost=0;
    ll h=0;
    ll pos=0;
};

int main__() {
    ll N,K; cin>>N>>K;    
    vector<ll> an(N);
    for(auto&& a:an){
        cin>>a;
    }

    ll maxh=an.at(0);
    vector<Info> tbl(N);
    FOR(i,0,N){
        auto&& d=tbl.at(i);
        d.h=an.at(i);
        d.cost = max(maxh-d.h,0LL);
        d.pos=i;
        maxh = max(maxh,an.at(i));
    }

    //cost優先、同costは後ろ優先
    sort(tbl.begin(),tbl.end(),[](const auto& a, const auto& b){ 
        if(a.cost==b.cost) return a.pos>b.pos;
        return a.cost<b.cost;
    });

    //動かすやつ決める
    vector<ll> mvd;
    FOR(i,0,K){
        mvd.push_back(tbl.at(i).pos);
    }

    ll ans=0;
    maxh=an.at(0);
    FOR(i,0,N){
        auto it = find(mvd.begin(),mvd.end(), i);
        if(i!=0 && it != mvd.end()){
            auto&& a=an.at(i);
            if(maxh<a){
            } else {
                ll add=maxh-an.at(i)+1;
                a += add;
                ans += add;
            }
        }
        maxh=max(an.at(i),maxh);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    
    s = input()
    t = input()
    count = 0
    for i in range(len(s)):
        if s[i] != t[i]:
            count += 1

    print(count)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9848
n,a,b,c,d=map(int, input().split())
s=list(input())

if d>c:
  #B→Aの順番でチェック
  for i in range(b-1,d-3):
    if "".join(s[i:i+2])=="##":
      print("No")
      exit()

  for i in range(a-1,c-3):
    if "".join(s[i:i+2])=="##":
      print("No")
      exit()
  #問題なければ終了
  print("Yes")

else:
  flag=False
  #BからDの間に3マス連続で空きがあるかチェック（AがBを抜かせるかどうか）
  for i in range(b-2, d-1):
    if "".join(s[i:i+3])=="...":
      flag=True
      break
  #抜かせる
  if flag:
    for i in range(a-1,c-3):
      if "".join(s[i:i+2])=="##":
        print("No")
        exit()
    print("Yes")
  #抜かせない
  else:
    print("No")

Measured memory_bytes: 10784
import sys
import heapq

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    MOD = 10 ** 9 + 7

    plus = []
    minus = []
    for a in A:
        if a >= 0:
            heapq.heappush(plus, -a)
        else:
            heapq.heappush(minus, a)

    ans = 1

    # 絶対マイナスになる場合
    if len(plus) < K - min((K - K % 2), (len(minus) - len(minus) % 2)):
        plus = []
        minus = []
        for a in A:
            if a >= 0:
                heapq.heappush(plus, a)
            else:
                heapq.heappush(minus, -a)

        while K > 0:
            if plus:
                x = plus[0]
            else:
                x = float("inf")

            if minus:
                y = -minus[0]
            else:
                y = float("inf")

            if abs(x) <= abs(y):
                ans *= x
                if plus:
                    heapq.heappop(plus)
            else:
                ans *= y
                if minus:
                    heapq.heappop(minus)

            ans %= MOD
            K -= 1

        print(ans)

    else:
        while K > 0:
            if K >= 2 and len(minus) >= 2 and len(plus) >= 2:
                x1 = plus[0]
                x2 = plus[1]
                y1 = minus[0]
                y2 = minus[1]
                if x1 * x2 <= y1 * y2:
                    y1 = heapq.heappop(minus)
                    y2 = heapq.heappop(minus)
                    ans *= (y1 * y2)
                    ans %= MOD
                    K -= 2
                else:
                    x1 = -heapq.heappop(plus)
                    ans *= x1
                    ans %= MOD
                    K -= 1
            elif K >= 2 and len(minus) >= 2:
                y1 = heapq.heappop(minus)
                y2 = heapq.heappop(minus)
                ans *= (y1 * y2)
                ans %= MOD
                K -= 2
            else:
                x = -heapq.heappop(plus)
                ans *= x
                ans %= MOD
                K -= 1

        print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31756
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine().trim()) != null && !"0".equals(line)) {
           int range = Integer.parseInt(line);
           int ans = 0;
           for(int i = 2 ; i <= range; i++) {
               if(range%i ==0 && i%2 != 0) ans++;
           }
           System.out.println(ans);
        }
    }
}


Measured memory_bytes: 24220
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//

struct Edge{
  int to;
  int cost;
};

vector<vector<Edge>> g;
vi ans;

void dfs(int v, int p=-1, int c=0){
  ans[v] = c;
  rep(i, g[v].size()){
    int u = g[v][i].to, w = g[v][i].cost;
    if (u == p) continue;
    if (w % 2 == 0) dfs(u, v, c);
    else dfs(u, v, c^1);
  }
}

int main() {
  int n;
  cin >> n;
  g.resize(n);
  ans = vi(n, -1);
  rep(i, n-1) {
    int u, v, w;
    cin >> u >> v >> w;
    --u; --v;
    w %= 2;
    g[u].push_back((Edge){v, w});
    g[v].push_back((Edge){u, w});
  }
  dfs(0);
  rep(i, n) cout << ans[i] << endl;
}

Measured memory_bytes: 12424
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%2lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;
int r;

int main(void) {
    scanf("%d", &r);
   

  
    printf("%d\n", r*r);

	return 0;
}


Measured memory_bytes: 256
a[101]={1,4,12,38};main(i,n,m){scanf("%d%d",&n,&m);
	if(m==1)for(;i<101;i++)a[i]=2*a[i-1]%1000000;
	else for(i=4;i<101;i++)a[i]=(4*a[i-1]-3*a[i-2]+2*a[i-3]+a[i-4]+3000000)%1000000;
	printf("%d\n",a[n]);exit(0);
}

Measured memory_bytes: 596
//Chandigarh University
//author:- shivamkr21
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r,d,f;
    cin>>r>>d>>f;
    for(int i=0;i<10;i++)
    {
        cout<<(r*f)-d<<"\n";
        f=(r*f)-d;
    }
    return 0;
}


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

int main() {
  long X,Y;
  cin >> X >> Y;
  long sa = Y/X;
  int ans = 1;
  long n2 = 2;
  for (int i=0; i<100; i++) {
    if (sa<n2) {
      break;
    }
    ans++;
    n2 = n2*2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    for (int i = 0; s[i]; ++ i) {
        if (s[i] == t[i]) cnt ++;
    }
    cout << cnt;
    
}

Measured memory_bytes: 256
#include<stdio.h>
int binarySearch(int);
int S[100000],n;

int main()
{

  int i=0,q,T[50000],j=0,c=0;

  scanf("%d",&n);

  while(i < n){
    scanf("%d",&S[i]);
    i++;
  }
  
  scanf("%d",&q);
  
  while(j < q){
    scanf("%d",&T[j]);
    j++;
  }
  
  for(i = 0;i < q;i++){
  c += binarySearch(T[i]);
  }
  printf("%d",c);
  printf("\n");
  return 0;
}

int binarySearch(int key)
{
  int left = 0;
  int right = n;
  int mid;
  while(left < right){
    mid = (left + right) / 2;
    if(S[mid] == key) return 1;
    else if(key < S[mid]) right = mid;
    else left = mid + 1;
  }
    return 0;
}

Measured memory_bytes: 1184
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[200200]={},ans[200200]={};
	cin>>n;
	FOR(i,0,n)cin>>a[i];
	FOR(i,0,n){
		int t=a[i];
		ans[t]=max(ans[t-1]+1,ans[t]+1);
	}
	int answ=0;
	FOR(i,0,n+1){
		answ=max(answ,ans[i]);
	}
	cout<<n-answ<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <map>

constexpr int MAX = 2 * 1e5 + 10;

int c[MAX];

std::map<int, int> b;

using ll = long long int;

int main()
{

    int n;

    std::cin >> n;

    for (int i = 1; i <= n; ++i)
    {
        int a;
        std::cin >> a;
        ++b[i + a];
        c[i] = i - a;
    }

    ll ans = 0;

    for (int i = 1; i <= n; ++i)
    {
        ans += b[c[i]];
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 20896
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int h, w, d; cin >> h >> w >> d;
    vector<vector<int>> a(h+1, vector<int>(w+1, -1));
    map<int, P> mp;
    rep(i, h) rep(j, w){
        cin >> a.at(i+1).at(j+1);
        mp[a.at(i+1).at(j+1)] = make_pair(i+1, j+1);
    }

    int q; cin >> q;
    vector<int> l(q), r(q);
    rep(i, q) cin >> l.at(i) >> r.at(i);

    vector<int> d2(h*w+1, 0);
    for(int i=d+1; i<=h*w; i++){
        d2.at(i) = d2.at(i-d) + (ll)abs(mp[i].first - mp[i-d].first) + (ll)abs(mp[i].second - mp[i-d].second); 
    } 

    rep(i, q){
        cout << d2.at(r.at(i)) - d2.at(l.at(i)) << endl;
    }

    return 0;
}


Measured memory_bytes: 8192
#include <limits.h>
#include <stdio.h>

int main(void) {
	int n, R, ans = INT_MIN, tmp;
	scanf("%d%d", &n, &tmp);
	for (int i = 1; i < n; ++i) {
		scanf("%d", &R);
		if (ans < R - tmp) ans = R - tmp;
		if (R < tmp) tmp = R;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2148
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MOD = 1e9+7;

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  rep(i, N) cin >> S[i];
  rep(i, M) cin >> T[i];
  vector<vector<int>> dp(N+1, vector<int>(M+1)), sum(N+2, vector<int>(M+2));
  dp[0][0] = 1;
  for(int i=0; i<=N; i++) {
    for(int j=0; j<=M; j++) {
      if(i && j && S[i-1] == T[j-1])
        dp[i][j] = sum[i][j];
      sum[i+1][j+1] = (((sum[i+1][j]+sum[i][j+1])%MOD-sum[i][j]+MOD)%MOD+dp[i][j])%MOD;
    }
  }
  cout << sum[N+1][M+1] << endl;
  return 0;
}

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

int A, B, C, D, E, F;
set<int> W, S;

void makeSet(set<int> &s, int a, int b) {
  for(int i = 0; i * a <= F; i++) {
    for(int j = 0; j * b <= F; j++) {
      int t = i * a + j * b;
      if(t > F) break;
      s.insert(t);
    }
  }
}

bool isOK(int a, int b) {
  return b * (100 + E) <= E * (a + b) && a + b <= F;
}

void chmax(int &ma, int &mb, int a, int b) {
  if(mb * (a + b) <= b * (ma + mb)) {
    ma = a;
    mb = b;
  }
}

int main() {
  cin >> A >> B >> C >> D >> E >> F;
  A *= 100, B *= 100;
  makeSet(W, A, B);
  makeSet(S, C, D);
  int a = F, b = 1;
  for(auto p : W) for(auto q : S) {
    if(isOK(p, q)) chmax(a, b, p, q);
  }
  cout << a + b << " " << b << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){

  string s;
  cin >> s;
  int n = s.size()-2;

  cout << s[0] << n << s[s.size()-1] << endl;

  return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        int    n;
        int    sub, flg;
        int[]  a;
        string[] str;

        n   = int.Parse(Console.ReadLine());    /* 標準入力                          */
        a   = new int[n];
        str = Console.ReadLine().Split(' ');    /* 2つ以上のスペース区切り入力の取得 */

        for(int cnt = 0; cnt < n; cnt++){
            a[cnt] = int.Parse(str[cnt]);
        }

        Array.Sort(a);

        sub = 0;
        flg = 0;
        for(int cnt = n - 1; cnt >= 0; cnt--){
            if(flg == 0){
                sub += a[cnt];
                flg++;
            } else{
                sub -= a[cnt];
                flg--;
            }
        }

        Console.WriteLine("{0}", sub);     /* 改行付き出力 */
    }
}


Measured memory_bytes: 13268
#include<stdio.h>
main(){
char C;
scanf("%c",&C);

if(C=='a'){
C='b';
}else if(C=='b'){
C='c';
}else if(C=='c'){
C='d';
}else if(C=='d'){
C='e';
}else if(C=='e'){
C='f';
}else if(C=='f'){
C='g';
}else if(C=='g'){
C='h';
}else if(C=='h'){
C='i';
}else if(C=='i'){
C='j';
}else if(C=='j'){
C='k';
}else if(C=='k'){
C='l';
}else if(C=='l'){
C='m';
}else if(C=='m'){
C='n';
}else if(C=='n'){
C='o';
}else if(C=='o'){
C='p';
}else if(C=='p'){
C='q';
}else if(C=='q'){
C='r';
}else if(C=='r'){
C='s';
}else if(C=='s'){
C='t';
}else if(C=='t'){
C='u';
}else if(C=='u'){
C='v';
}else if(C=='v'){
C='w';
}else if(C=='w'){
C='x';
}else if(C=='x'){
C='y';
}else if(C=='y'){
C='z';
} 

printf("%c",C);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define N 200005
#define ll long long
using namespace std;
ll a[N],b[N],n,x,y,fst[N],nxt[N],to[N],l,fa[N];
void link(ll x,ll y)
{
	to[++l]=y;nxt[l]=fst[x];fst[x]=l;
	to[++l]=x;nxt[l]=fst[y];fst[y]=l;
}
void biu()
{
	puts("NO");
	exit(0);
}
void dfs(ll x)
{
	b[x]=(nxt[fst[x]]==0)?a[x]:a[x]*2;
	for (ll i=fst[x];i;i=nxt[i])
		if (to[i]!=fa[x])
		{
			fa[to[i]]=x;
			dfs(to[i]);
			b[x]-=b[to[i]];
			if (b[to[i]]>a[x]) biu();
		}
	if (b[x]<0||b[x]>a[x]) biu();
}
int main()
{
	scanf("%lld",&n);
	for (ll i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for (ll i=1;i<n;i++)
	{
		scanf("%lld%lld",&x,&y);
		link(x,y);
	}
	dfs(1);
	if (b[1])biu();
	puts("YES");
}

Measured memory_bytes: 10752
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        int n = ReadInt();
        int k = ReadInt();
        Console.WriteLine(ReadInt(n).OrderBy(x => x).Take(k).Sum());
    }
}


static class Scanner
{
    static Queue<string> que = new Queue<string>();

    public static string Read()
    {
        if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s);
        return que.Dequeue();
    }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());
    public static decimal ReadDecimal() => decimal.Parse(Read());

    public static IEnumerable<string> Read(long n)
    {
        for (long i = 0; i < n; i++) yield return Read();
    }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
    public static IEnumerable<double> ReadDouble(long n) => Read(n).Select(double.Parse);
    public static IEnumerable<decimal> ReadDecimal(long n) => Read(n).Select(decimal.Parse);
}

Measured memory_bytes: 28916