akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<atcoder/segtree>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
#include <math.h>
using namespace std ;
using namespace atcoder ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
void chmax(ll &a,ll b){	if(a<b) a = b ;}
void chmin(ll &a,ll b){ if(a>b) a = b ;}

ll op(ll a,ll b){return max(a,b) ;}
ll e(){return -INF ;}
ll border ;
bool f(ll v){return v<border ;}

int main(){
  ll n,q ;
  cin >> n >> q ;
  vll a(n) ;
  for(auto &i:a) cin >> i ;
  segtree<ll,op,e> sgt(a) ;
  while(q--){
    ll t,u,v ;
    cin >> t >> u >> v ;
    if(t==1){
      sgt.set(u-1,v) ; 
    }
    if(t==3){
      border = v ;
      cout << sgt.max_right<f>(u-1)+1 << endl ;
    }
    if(t==2){
      cout << sgt.prod(u-1,v) << endl ;
    }
  }
}


Measured memory_bytes: 9068
import math

def main():
    n, k = map(int, input().split())
    sunuke = [False] * n
    for i in range(k):
        d = int(input())
        A = map(int, input().split())
        for a in A:
            sunuke[a-1] = True

    print(sunuke.count(False))

main()

Measured memory_bytes: 9172
import java.util.Scanner;


class Main {
      
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in) ;
            int k = sc.nextInt();
            String s = sc.next() ;
            
            if( k>=s.length()){
                  System.out.println(s);
            }else{
                  System.out.println(s.substring(0,k)+"...");
            }
            
            
      }
      
}

Measured memory_bytes: 38388
#include <iostream>
#include <vector>
#include<queue>
#include<iomanip>
#include<array>
using namespace std;
#define MAX 1000000000
#define ll long long


int main(int argc, char* argv[]) {

	int K;
	string S;
	cin >>K>>S ;
	if (S.length() <= K)
	{
		cout << S;
	}
	else
	{
		for (int i = 0; i < K; ++i)
		{
			cout << S[i];
		}
		cout << "...";
	}
	return 0;
}	


Measured memory_bytes: 3628
/**
 * There is a start and there is no end in the space. ---Infinity.
 * It ruins and goes though there is also a start in stars. ---Finite.
 * Only the man who has wisdom can read the most foolish one from the history.
 * Fishes living in the sea doesn't know the life in the land.
 * It also ruins and goes if they have wisdom.
 * It funnier that man exceeds the speed of light than fish start living in the land.
 * It can be said that this is an final ultimatum from the god to the people who can fight.
 *
 * Steins;Gate
 */

#include <bits/stdc++.h>

const int N = 150000;

int n, A, B, p[N], top, now, lm, same, dt;

inline void out(int x) {
    for(int i = 0; i < n; i++) {
        printf("%d", (x >> i) & 1);
    }
    return;
}

inline int cal(int x) {
    int ans = 0;
    while(x) {
        ans++;
        x -= x & (-x);
    }
    return ans;
}

inline int Abs(int x) {
    return x < 0 ? -x : x;
}

inline int First(int x) {
    for(int i = n - 1; i >= 0; i--) {
        if((x >> i) & 1) return 1 << i;
    }
    return 0;
}

void solve(int n, int l, int r, int a, int b) {
    if(n == 1) {
        p[l] = a;
        p[r] = b;
        return;
    }
    int mid = (l + r) >> 1, nexlm = (1 << (n - 1)) - 1;
    if(((a >> (n - 1)) & 1) == ((b >> (n - 1)) & 1)) {
        solve(n - 1, mid + 1, r, a & nexlm, b & nexlm);
        if((a >> (n - 1)) & 1) {
            for(int i = mid + 1; i <= r; i++) {
                p[i] |= 1 << (n - 1);
            }
            p[l] = p[mid + 1];
            solve(n - 1, l + 1, mid + 1, a & nexlm, p[mid + 2] & nexlm);
        }
        else {
            p[l] = p[mid + 1];
            solve(n - 1, l + 1, mid + 1, a & nexlm, p[mid + 2] & nexlm);
            for(int i = l + 1; i <= mid + 1; i++) {
                p[i] |= (1 << (n - 1));
            }
        }
    }
    else {
        solve(n - 1, l, mid, a & nexlm, (b & nexlm) ^ 1);
        if((a >> (n - 1)) & 1) {
            for(int i = l; i <= mid; i++) {
                p[i] |= 1 << (n - 1);
            }
            solve(n - 1, mid + 1, r, p[mid] & nexlm, b & nexlm);
        }
        else {
            solve(n - 1, mid + 1, r, p[mid] & nexlm, b & nexlm);
            for(int i = mid + 1; i <= r; i++) {
                p[i] |= 1 << (n - 1);
            }
        }
    }
    return;
}

int main() {

    scanf("%d%d%d", &n, &A, &B);
    lm = (1 << n) - 1, dt = A ^ B, same = dt ^ lm;

    if((cal(dt) & 1) == 0) {
        puts("NO");
    }
    else {
        puts("YES");
        solve(n, 0, lm, A, B);
        for(int i = 0; i <= lm; i++) {
            //out(p[i]); printf(" ");
            printf("%d ", p[i]);
            //puts("");
        }
    }
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <stack>

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

typedef long long LL;
typedef pair<int, int> PII;

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repl(i, n) for(LL i = 0; i < (LL)(n); i++)

int main(void){
  string a;
  cin >> a;
  if (a[1] == 'B') {
    a[1] = 'R';
  } else if (a[1] == 'R') {
    a[1] = 'B';
  }
  cout << a;
  return 0;
};

Measured memory_bytes: 3132
# 初期入力
N = int(input())
H = list(map(int, input().split()))

#
right_high_num =0
count =0
count_kiroku =[]
for i in range(N-1):
    if 0 <= H[i] -H[i+1] : #右が低い＝移動できる
        count += 1
    else:
        count_kiroku.append(count)
        count =0
count_kiroku.append(count)
ans = max(count_kiroku) 
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S, T;
    cin >> S >> T;
    int s = size (S);
    int t = size (T);
    int x = t;
    // cout << s << endl << t << endl;
    for (int i = 0; i <= s - t; i ++) {
        int a = 0;
        for (int j = 0; j < t; j ++) {
            if (S[i + j] != T[j]) {
                a ++;
            }
        }
        if (a < x) {
            x = a;
        }
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a,b;
  cin >> a >> b;
  int c = 0;
  for(int i = 0; i < 3; i++){
  	if(a[i] == b[i])c++;
  }
  cout << c << endl;
  return 0;
}

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

int main(){
  int n,a[100];
  cin>>n;
  for (int i=0;i<n;i++) cin>>a[i];

  for (int i=0;i<n;i++){
    int v=a[i];
    int j=i-1;
    
    while(j>=0&&a[j]>v){
      a[j+1]=a[j];
      j--;
      }
      a[j+1]=v;
      for (int k=0;k<n;k++) {
        if (k!=n-1) cout<<a[k]<<' ';
        else cout<<a[k]<<endl;
  }
    
  }
 }


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,k;

int main(){
	cin>>n>>k;
	int N=(int)(sqrt(n)+eps);
	vvi dp(2,vi(N+1));
	for(int i=1;i<=N;i++){
		dp[0][i]=1;
		if(i*i<n) dp[1][i]=n/i-max(n/(i+1),N);
	}
	for(int i=1;i<k;i++){
		vvi DP(2,vi(N+1));
		int S=0,t=0;
		for(auto j:dp[0]) (S+=j)%=mod;
		for(auto j:dp[1]) (t+=j)%=mod;
		for(int j=1;j<=N;j++){
			DP[0][j]=(S+t)%mod;
			(t+=mod-dp[1][j])%=mod;
		}
		t=0;
		for(int j=1;j<=N;j++) if(j*j<n){
			(t+=dp[0][j])%=mod;
			DP[1][j]=(ll)t*(n/j-max(n/(j+1),N))%mod;
		}
		dp=DP;
	}
	int res=0;
	for(int i=0;i<2;i++) for(auto j:dp[i]) (res+=j)%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 912
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       		ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl 			"\n"

typedef long long int  ll;


int main()
{
	FAST;
	string str;

	cin >> str;


	int first = (str[0]-'0')*10 + str[1]-'0';
	int second = (str[2]-'0')*10 + str[3]-'0';

    if(first == 0 && second == 0)
        cout << "NA";
	else if(first <= 12 && second <= 12 && first != 0 && second != 0)
		cout << "AMBIGUOUS";
	else if(second <= 12 && second != 0)
			cout << "YYMM";
	else if(first <= 12 && first != 0)
		cout << "MMYY";
	else
	    cout << "NA";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<ll> a,b;
int main()
{
	int i,n;
	scanf("%d",&n);
	ll x,y;
	for(i=0;i<n;++i)
	{
		cin>>x>>y;
		a.push_back(x);
		b.push_back(y);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	if(n%2==1)
	{
		x = a[(n)/2];
		y = b[(n)/2];
		cout << y-x+1;
	}
	if(n%2==0)
	{
		cout << b[n/2-1]+b[n/2]-a[n/2-1]-a[n/2]+1;
	}
}

Measured memory_bytes: 6752
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
 
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)
 
using namespace std;
 
 
int main(void){
 
int l[10] ,v1,v2;
char cc;
 
    while(cin >> l[0] ){
        rep2(i,1,10) cin >> cc >> l[i];
        cin >> cc >> v1 >> cc >> v2;
        int kr=0;
        rep(i,10) kr += l[i];
        double tm = kr * 1.0l / (v1 + v2);
        double km = v1 * tm;
        kr = 0;
        rep(i,10){
            kr += l[i];
            if(kr >= km){
                cout << i+1 << endl;
                break;
            }  
        }
//      printf("%f,%f kr=%d\n",tm,km,kr);
    }
    return 0;
     
     
}

Measured memory_bytes: 1160
#![allow(non_snake_case, unused_imports)]

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

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        L: [i64; N],
    }
    let mut maxL = 0;
    let mut sumL = 0;
    for i in 0..N{
        maxL = max(maxL,L[i]);
        sumL += L[i];
    }
    println!("{}", if sumL>maxL*2 {"Yes"}else{"No"});
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    int N, D;
    cin >> N >> D;
    v2int X(N, vint(D, 0));
    rep(i, N) {
        rep(j, D) {
            cin >> X[i][j];
        }
    }
    int ans = 0;
    rep(i, N) {
        REP(j, i + 1, N) {
            int dist2 = 0;
            rep(k, D) {
                dist2 += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            auto dist = int(sqrt(double(dist2)) + 0.1);
            if (dist* dist == dist2) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n];
	int sum=0;
	int a;
	int gr=0,br=0,grr=0,p=0,d=0,e=0,j=0,k=0,f=0;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		a = arr[i]/400;
		if(a==0)
			gr=1;
		if(a>=1 && a<2)
			br=1;
		if(a>=2 && a<3)
			grr=1;
		if(a>=3 && a<4)
			p=1;
		if(a>=4 && a<5)
			d=1;
		if(a>=5 && a<6)
			e=1;
		if(a>=6 && a<7)
			j=1;
		if(a>=7 && a<8)
			k=1;
		if(a>=8)
			f++;

	}
	sum += (gr+br+grr+p+d+e+j+k);
	if(sum==0 && f)
		cout<<"1"<<" ";
	else
		cout<<sum<<" ";
	cout<<sum+f<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++) // ex)REP(i,10) i=0~i=9
#define REPR(i, n) for(int i = n;i >= 0;i--) // ex)REPR(i,10) i=10~i=0
#define FOR(i, m, n) for(int i = m;i < n;i++) //ex)FOR(i,3,10) i=3~i=9
#define FORR(i, m, n) for(int i = m;i >= n;i--) 
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end()); //
#define llong long long //64bitに拡張
#define pb(a) push_back(a)　
#define INF 999999999 //大きな値
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//座標上を探索
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
int A,B;
cin >> A >> B;
if(A == 1){ 
A = 14;
}
if(B == 1){ 
B = 14;
}
if(A>B){ 
   cout << "Alice" << endl;
   }else if(A<B){ 
   cout << "Bob" << endl;
   }else{ 
   cout << "Draw" << endl;
   }
}

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

using namespace std;

int n,k,a[100001],ans=2147483647;

int main(){
	scanf("%d%d",&n,&k);for(int i=1;i<=n;++i)scanf("%d",a+i);
	for(int i=1;i<=n-k+1;++i){
		int x=a[i],y=a[i+k-1];
		if(x<0&&y<0)ans=min(ans,abs(x));
		if(x<0&&y>=0)ans=min(ans,min(abs(x)+y-x,abs(y)+y-x));
		if(x>=0&&y>=0)ans=min(ans,y);
	}
	printf("%d",ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int W, H, N;
    int ymax[100005] = {};

    cin >> W >> H >> N;
    for(int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        ymax[x] = max(ymax[x], y);
    }
    
    int minv = 1 << 28;
    int mm = 0;
    for(int i = W - 1; i >= 0; i--) {
        minv = min(i + mm, minv);
        mm = max(ymax[i], mm);
    }

    cout << minv << endl;
    return (0);
}

Measured memory_bytes: 3484
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main(){
    int n, w;
    cin >> n >> w;
    vector<P> wv(n+1);
    rep(i,n) cin >> wv[i+1].fi >> wv[i+1].se;
    vector<vector<ll>> dp(n+1,vector<ll>(w+1));
    for(int i=1; i<n+1; i++){
        int w0 = wv[i].fi, v0 = wv[i].se;
        rep(x,w0)dp[i][x]=dp[i-1][x];
        for(int x = w0; x < w+1; x++){
            dp[i][x] = max(dp[i-1][x],dp[i-1][x-w0] + v0);
        }
    }

    cout << dp[n][w] << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repab(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
#define endl "\n"

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

//--//--//--//--//--//--//--//--//--//--//--//

 
int main() {
  string s;
  cin >> s;
  
  if(s.at(s.size()-1) == 's'){
    cout << s << "es" << endl;
  }
  else{
    cout << s << "s" << endl;
  }

  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define hell (int)(1e9+7)
#define int long long int
#define inf 1000000000000

using namespace std;

void solve(){
    int n;
    cin>>n;
    vector <int> a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=inf;
    for(int i=0;i<=100;i++){
        int cost=0;
        for(int x:a){
            cost+=(x-i)*(x-i);
        }
        ans=min(ans,cost);
    }
    cout<<ans;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t,c;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
p [*0...gets.to_i**2].product([*$<].map{|x|
	Complex(*x.split.map(&:to_i))
}.sort_by(&:arg)).group_by(&:first).map{|x|
	[*x[0]/x[1].size..x[0]/x[1].size+x[0]%x[1].size].map{|y|x[1][y%x[1].size][1]}.inject(:+).abs
}.max

Measured memory_bytes: 89848
/* https://atcoder.jp/contests/abc126/tasks/abc126_a */

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <locale>

using namespace std;

/* {{{ Variables */
int N, K;
string S;
/* }}} */

int main(int argc, char *argv[])
{
  /* {{{ Input */
  cin >> N >> K >> S;
  /* }}} */

  /* {{{ Output */
  S.at(K-1) = tolower(S.at(K-1));

  cout << S << endl;
  /* }}} */

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> l(n);
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    ll ans = 1;
    ll x = 0;
    for(int i = 0; i < n; i++){
        x += l[i];
        if(x<=k){ans++;}
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func visit(cnt, a int) int {
	if a%2 == 1 {
		return cnt
	}
	return visit(cnt+1, a/2)
}

func main() {
	var n, a, cnt int
	var min int = math.MaxInt64
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		cnt = visit(0, a)
		if cnt < min {
			min = cnt
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N := ReadInt()
	As := ReadInts(N)

	sort.Sort(sort.Reverse(sort.IntSlice(As)))
	c := make(map[int]int)
	for i := 0; i < N; i++ {
		c[As[i]]++
	}

	ans := 0
	for _, x := range As {
		if c[x] == 0 {
			continue
		}
		for b := 2; b <= x*2; b *= 2 {
			y := b - x
			if y < 1 {
				continue
			}
			if x == y {
				if c[x] >= 2 {
					c[x] -= 2
					ans++
					continue
				}
			} else {
				if c[x] >= 1 && c[y] >= 1 {
					c[x]--
					c[y]--
					ans++
					continue
				}
			}
		}
	}

	fmt.Println(ans)
}

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 15212
h,w = map(int,input().split())
s = []
for i in range(h):
    s.append(input())

ans = 'Yes'
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            continue

        bl = False
        for dy,dx in [(-1,0),(1,0),(0,-1),(0,1)]:
            y,x = i+dy,j+dx
            if 0<=y<h and 0<=x<w and s[y][x]=='#':
                bl = True

        if not bl:
            ans = 'No'

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;


int stones[10000][2];

int snext(int n,int k){
    if (k==0) {
        return n;
    }
    return snext(stones[n][0], k-1);
}

void srm(int n){
    int aft = stones[n][0];
    int bef = stones[n][1];
    stones[bef][0] = aft;
    stones[aft][1] = bef;
    stones[n][1]=0;
}


int main(){
    for(;;){
        int n,k,m;
        cin >> n>>k>>m;
        if(!n and !k and !m)break;
        for(int i=1;i<=n;i++){
            stones[i][0]=i+1;
            stones[i][1]=i-1;
        }
        stones[1][1]=n;
        stones[n][0]=1;
        srm(m);
        int flag=m;
        for (int i=0; i<n-2; i++) {
            flag = snext(flag, k);
            srm(flag);
        }
        for (int i=1; i<=n; i++) {
            if(stones[i][1]!=0){
                cout <<i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 1236
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(abs(a-b) > k || abs(a-c) > k ||abs(a-d) > k ||abs(a-e) > k ||abs(b-c) > k ||abs(b-d) > k ||abs(b-e) > k ||abs(c-d) > k ||abs(c-e) > k ||abs(d-e) > k)
    {
        cout << ":(";
    }
    else
    {
        cout << "Yay!";
    }

    return 0;
}


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

bool check(string S) {
  if (S.size() % 2 == 1)
    return false;
  int x = S.size() / 2;
  for (int i = 0; i < x; i++) {
    if (S[i] != S[i + x])
      return false;
  }
  return true;
}

int main() {
  string S;
  cin >> S;
  for (int i = S.size() - 1;; i--) {
    if (check(S.substr(0, i))) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
  
const int N=2e+4 + 5;
long long int a[N],b[N],dp[N];
int n,h;

long long int solve(int i)
{
    if(i<=0)
        return 0;
    if(dp[i]==0)
    {
        dp[i]=b[1]+solve(i-a[1]);
        for(int j=1;j<=n;j++)
            dp[i]=min(b[j]+solve(i-a[j]),dp[i]);
    }
    return dp[i];
}

int main()
{
    cin>>h>>n;    
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i];
    cout<<solve(h);
}

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

int main()
{
    long long N;
    cin >> N;
    string C;
    int red = 0;
    int res = 0;
    cin >> C;
    for (int i = 0; i < N; i++)if(C[i]=='R')red++;
    for (int i = 0; i < red; i++)if(C[i]=='W')res++;
    cout<<res;
}

Measured memory_bytes: 3752
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    bool flag = 0,start = 1;
    ll i = 0,cnt = 0;
    while(i < n){
        if (i == n-1){
            cnt++;
            break;
        }
        if (start){
            if (a[i] < a[i+1]){
                flag = 1;
                start = 0;
            }
            else if (a[i] > a[i+1]){
                flag = 0;
                start = 0;
            }
            i++;
        }
        else if (flag){
            if (a[i] > a[i+1]){
                cnt++;
                start = 1;
            }
            i++;
        }
        else{
            if (a[i] < a[i+1]){
                cnt++;
                start = 1;
            }
            i++;
        }
    }
    PRINT(cnt);
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int N;
	cin >> N;
	vector<vector<int> > P(N, vector<int>(N));
	vector<pair<int, int> > O(N*N);
	vector<vector<int> > d(N, vector<int>(N, N));
	vector<vector<bool> > used(N, vector<bool>(N));
	forn(r, N)
	{
		forn(c,N)
		{
			d[r][c] = min({ r, N - 1 - r, c, N-1-c});
		}
	}

	forn(rr, N*N)
	{
		int tmp;
		cin >> tmp;
		--tmp;
		O[rr] = { tmp / N, tmp%N };
	}

	vector<pair<int, int> > neighb = { {-1,0},{1,0},{0,1},{0,-1} };
	int res = 0;
	for (auto oi : O)
	{
		int actr = oi.first;
		int actc = oi.second;
		int actd = d[actr][actc];
		res += actd;
		used[actr][actc] = true;
		vector<pair<int, int> > q(1, { actr, actc });
		forn(qid, q.size())
		{
			int currr = q[qid].first;
			int currc = q[qid].second;
			int currd = d[currr][currc] + (used[currr][currc] ? 0 : 1);
			for (auto ni : neighb)
			{
				int candr = currr + ni.first;
				int candc = currc + ni.second;
				if (candr >= 0 && candr < N && candc >= 0 && candc < N)
				{
					if (d[candr][candc] > currd)
					{
						d[candr][candc] = currd;
						q.push_back({ candr, candc });
					}
				}
			}
		}
	}
	cout << res << endl;
	return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] bCards = new String[Integer.parseInt(br.readLine())];
		String[] sCards = new String[bCards.length];
		String[] strs = br.readLine().split(" ");
		for (int i = 0; i < bCards.length; i++) {
			bCards[i] = strs[i];
			sCards[i] = String.valueOf(bCards[i]);
		}

		bubbleSort(bCards);
		selectionSort(sCards);
		StringBuilder bSb = new StringBuilder();
		StringBuilder sSb = new StringBuilder();
		boolean isStable = true;
		for (int i = 0 ; i < bCards.length; i++) {
			if (i > 0) {
				bSb.append(" ");
				sSb.append(" ");
			}
			bSb.append(bCards[i]);
			sSb.append(sCards[i]);
			if (isStable && !bCards[i].equals(sCards[i])) {
				isStable = false;
			}
		}
		System.out.println(bSb.toString() + "\n" + "Stable");
		if (isStable) {
			System.out.println(sSb.toString() + "\n" + "Stable");
		} else {
			System.out.println(sSb.toString() + "\n" + "Not stable");
		}
	}

	public static void bubbleSort(String[] cards) {
		for (int i = 0; i < cards.length; i++) {
			for (int j = cards.length - 1; j > 0; j--) {
				if (cards[j].charAt(1) < cards[j - 1].charAt(1)) {
					String temp = cards[j];
					cards[j] = cards[j - 1];
					cards[j - 1] = temp;
				}
			}
		}
	}

	public static void selectionSort(String[] cards) {
		for (int i = 0; i < cards.length; i++) {
			int minIdx = i;
			for (int j = i + 1; j < cards.length; j++) {
				if (cards[minIdx].charAt(1) > cards[j].charAt(1)) {
					minIdx = j;
				}
			}
			if (i == minIdx) continue;
			String temp = cards[i];
			cards[i] = cards[minIdx];
			cards[minIdx] = temp;
		}
	}
}

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

using namespace std; 

#define endl "\n"



long long int divisors[1000006]={0};
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
   
   int n;
   cin>>n;
   int x[n],y[n],i,cnt=0;
   for(i=0;i<n;++i)
   {
       cin>>x[i]>>y[i];
   }
   
   for(i=0;i<n;++i)
   {
       if(x[i]==y[i])
          cnt++;
          
        else
        {
            if(cnt>=3)
               break;
             
             cnt=0;  
        }
   }
   
   if(cnt>=3)
     cout<<"Yes";
     
   else
     cout<<"No";
   
   
  
     return 0;
}

Measured memory_bytes: 3648
from collections import deque
N, *L = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for a,b in zip(*[iter(L)]*2):
  dic[a] += [b]
  dic[b] += [a]
fdist = [-1]*(N+1)
sdist = [-1]*(N+1)
fdist[1] = 0
sdist[N] = 0
q = deque([1])
while q:
  v = q.popleft()
  for u in dic[v]:
    if fdist[u] == -1:
      fdist[u] = fdist[v] + 1
      q.append(u)
q = deque([N])
while q:
  v = q.popleft()
  for u in dic[v]:
    if sdist[u]==-1:
      sdist[u] = sdist[v] + 1
      q.append(u)
ans = sum(a<=b for a,b in zip(fdist,sdist))-1
if 2*ans>N:
  print('Fennec')
else:
  print('Snuke')

Measured memory_bytes: 30964
s = gets.chomp.chars
i = 0
while i < s.size/2
  unless (s[i] == s[((s.size - 1)/2)-i-1]) && (s[i] == s[s.size - i - 1]) && (s[i] == s[(s.size + 3)/2+i-1])
    break
  end
  i += 1
end
if i == s.size/2
  puts "Yes"
else
  puts "No"
end

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

template <class T>
using lim = numeric_limits<T>;

bool can[10];
int cost[10] = {0,2,5,5,4,5,6,3,7,6};
char num[10] = {'0','1','2','3','4','5','6','7','8','9'};

// stores a big number
// supports comparison and cout
struct bigInt{
	string s;
	
	bigInt(){s="0";}
	bigInt(string a){s=a;}
	
	bigInt append(char a){
		return bigInt(s+a);
	}
	
	bool operator<(const bigInt &other)const{
		int n = s.length();
		int m = other.s.length();
		if (n != m) return n < m;
		for (int i = 0; i < n; i++){
			if (s[i] == other.s[i]) continue;
			return (int)s[i]-'0' < (int)other.s[i]-'0';
		}
		return true;
	}
	
	friend ostream& operator<<(ostream &os, const bigInt a);
};

ostream& operator<<(ostream& os, const bigInt a){
	os << a.s;
	return os;
}

int main() {
	ios_base::sync_with_stdio(false) ;
	cin.tie(0);
	
	memset(can, 0, sizeof can);
	
	int n, m;
	cin >> n >> m;
	
	bigInt dp[n+1];
	dp[0] = bigInt("");
	for (int i = 0; i < m; i++){
		int a; cin >> a;
		can[a] = true;
	}
	
	// adding all available matches and getting the max
	// dp[i] is maximum val at i
	for (int i = 0; i < n; i++){
		for (int j = 1; j < 10; j++){
			if (!can[j] || dp[i].s=="0" || i + cost[j] > n) continue;
			dp[i+cost[j]] = max(dp[i+cost[j]], dp[i].append(num[j]));
		}
	}
	
	cout << dp[n] << endl;
}



Measured memory_bytes: 44800
import java.util.Scanner;

class Main {
  public static int m = 1000000007;

  public static int pow(int a, int b) {
    long s = 1;
    long a2 = a;
    while (b > 0) {
      if ((b & 1) != 0) {
        s = s * a2 % m;
      }
      a2 = a2 * a2 % m;
      b >>= 1;
    }
    return (int)s;
  }
  public static int reverse(int a) {
    return pow(a, m - 2);
  }

  public static int sub(int n, int a) {
    if (a > n / 2) {
      a = n - a;
    }
    long s1 = 1;
    int n2 = n - a;
    for (int i = n; i > n2; i--) {
      s1 = s1 * i % m;
    }
    long s2 = 1;
    for (int i = 1; i <= a; i++) {
      s2 = s2 * i % m;
    }
    int s3 = reverse((int)s2);
    return (int)(s1 * s3 % m);
  }

  public static void main(String[] args) {
    var sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

    long all = pow(2, n);

    long answer = (all + 2 * m - sub(n, a) - sub(n, b) - 1) % m;
    System.out.println(answer);
  }
}

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

template <typename T> T gcd(T x, T y) { return( y ? gcd(y, x % y) : x); }
template <typename T> T lcm(T x, T y) { return( x / gcd(x, y) * y); }
template <typename T> void printVec(vector<T> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

int main() {
  int x, y;
  cin >> x >> y;
  for (int i = 0; i <= x; i++) {
    int count;
    count = i * 2 + (x - i) * 4;
    if (count == y) {
      cout <<  "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
int main(void)
{
	int N,k,m,j,i;
	scanf("%d",&N);
	while(N!=0){
		m=0;
		j=0;
		for(i=0;i<N;i++){
			scanf("%d",&k);
			if(k<2){
				m=m+1;
				if(k==0){
					j=j+1;
				}
			}
		}		
		if(m==N){
			printf("NA\n");
		}
		else{
			printf("%d\n",N-j+1);
		}
		scanf("%d",&N);
	}
	return 0;
}

Measured memory_bytes: 612
import java.lang.Math
import kotlin.comparisons.*

val MOD: Int = 1000000000 + 7
val MODL: Long = MOD.toLong()

data class Restaurant(val no: Int, val city: String, val score: Int)

fun main(args: Array<String>)
{
    val n = read().toInt()
    val list = mutableListOf<Restaurant>()
    for (i in 1..n) {
        val (s, p) = read().split()
        list.add(Restaurant(i, s, p.toInt()))
    }
    list.sortWith(compareBy({it.city}, {-it.score}))

    for (i in 0 until n) {
        println(list[i].no)
    }
}

fun read(): String = readLine()!!
fun CharSequence.split(): List<String> = this.split(" ")
fun Iterable<String>.toInt(): List<Int> = this.map{it.toInt()}


Measured memory_bytes: 35948
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
#define mx 1000011
int dp[mx];
void solve()
{int n,k;
cin>>n>>k;
pair<int,int> arr[k];
for(int i=0;i<k;i++)
{
    cin>>arr[i].ff>>arr[i].ss;
}
int dp[n+1]={};
int mod=998244353;
    int pref[n+1]={};
     dp[1]=1;
     pref[1]=1;
     for(int i=2;i<=n;i++)
     {
         for(int j=0;j<k;j++)
         {
             int s=arr[j].ff;
             int e=arr[j].ss;
             s=i-s;
             e=i-e;
             if(s<1)
                s=0;
             if(e<1)
                e=1;
             int res=pref[s]-pref[e-1];
             res%=mod;
             if(res<0)
                res+=mod;
             dp[i]+=res;
             dp[i]%=mod;
         }
         pref[i]=pref[i-1]+dp[i];
         pref[i]%=mod;
     }
int ans=dp[n];
cout<<ans<<endl;


}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
    return 0;
}


Measured memory_bytes: 6728
//13
#include<iostream>
#include<string>

using namespace std;

int main(){
  char t[128];
  t['(']=')';
  t[')']='(';
  t['[']=']';
  t[']']='[';
  t['}']='{';
  t['{']='}';
  string s;
  cin>>s;
  string a=s.substr(0,s.find("iwi"));
  string b=s.substr(s.find("iwi")+3);
  int m=0;
  for(int i=0;i<1<<a.size();i++){
    string ap;
    for(int j=0;j<a.size();j++){
      if(i>>j&1){
	ap+=a[j];
      }
    }
    for(int j=0;j<1<<b.size();j++){
      string bp;
      for(int k=0;k<b.size();k++){
	if(j>>k&1){
	  bp+=b[k];
	}
      }
      if(ap.size()==bp.size()){
	int k;
	for(k=0;k<ap.size();k++){
	  if(t[ap[k]]!=bp[ap.size()-1-k])break;
	}
	if(k==ap.size()&&ap.size()>m){
	  m=ap.size();
	}
      }
    }
  }
  cout<<m*2+3<<endl;
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
ll a[50];
int n;
int check(ll k){
	int i;
	ll cnt=0;
	FOR(i,0,n){
		if(a[i]+k>=n){
			cnt+=(a[i]+k+1)/(n+1);
		}
	}
	return cnt==k;
}
int main(void)
{
	int i;
	ll sum=0,k;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	FOR(k,MAX(0,sum-(n-1)*n),sum){
		if(check(k)){
			printf("%lld\n",k);
			return 0;
		}
	}
	return 0;
}

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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

template<class T> T sum(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    T ans = T();
    for(typename vector<T>::iterator t = begin; t != end; t++) ans += *t;
    return ans;
}

template<class T> T min(const vector<T>& v) {
    return *min_element(v.begin(), v.end());
}

template<class T> T min(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *min_element(begin, end);
}

template<class T> T max(const vector<T>& v) {
    return *max_element(v.begin(), v.end());
}

template<class T> T max(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *max_element(begin, end);
}

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

    int N = next<int>();
    string S = next<string>();

    int ans = 0;

    times(N, _) {
        string B = next<string>();
        upto(1, ~-B.size() / ~-S.size(), d) {
            upto(0, ~-B.size() - ~-S.size() * d, s) {
                times(S.size(), i) {
                    if(B[s + d * i] != S[i]) goto pyon;
                }
                ans++;
                goto pyonpyon;
                pyon:;
            }
        }
        pyonpyon:;
    }

    cout << ans ln;

    return 0;
}

Measured memory_bytes: 1212
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		Long sum = n % 2 == 0 ? (1l + n) * (n / 2) : (1l + n) * (n / 2) + (n / 2 + 1);

		System.out.println(sum - n);
	}
}

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

bool check(int start, int end,string s) {
  for(int i = start; i + 1 <= end; i++) {
    if(s[i] == '#' && s[i + 1] == '#') return false;
  }
  return true;
}

int main(){
  int N,A,B,C,D;
  cin >> N >> A >> B >> C >> D;
  string s;
  cin >> s;
  s = "#" + s + "#";
  
  if(!check(A,C,s) || !check(B,D,s)) {
    puts("No");
    return 0;
  }
  
  if( C > D) {
    bool ok = false;
    for (int i = B; i <= D; i++) {
      if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') {
        ok = true;
      }
    }
    if(!ok) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 844
N = int(input())
ABs = [list(map(int, input().split())) for i in range(N)]
ABs = sorted(ABs, key=lambda x:x[1])
total = 0
is_comp = True
for task_i in ABs:
    total += task_i[0]
    #print("total: {}, limit: {}".format(total, task_i[1]))
    if total > task_i[1]:
        is_comp = False
        break
if is_comp:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 55196
import sys
input = sys.stdin.readline
from collections import Counter
N = int(input())
S = [input().strip() for i in range(N)]

cnt = Counter(S)

print('AC x '+str(cnt['AC']))
print('WA x '+str(cnt['WA']))
print('TLE x '+str(cnt['TLE']))
print('RE x '+str(cnt['RE']))



Measured memory_bytes: 16624
def solve(s):
    mod = 2019
    counts = [0]*mod
    counts[0] = 1
    result = 0
    suffix = 0
    power_of_ten = 1
    for char in s[::-1]:
        digit = int(char)
        suffix = (suffix + digit*power_of_ten) % mod
        result += counts[suffix]
        counts[suffix] += 1
        power_of_ten = 10 * power_of_ten % mod

    return result


if __name__ == "__main__":
    print(solve(input()))


Measured memory_bytes: 9316
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int main(void){
    int i,j,n,buf[1300000]={0},pr[100000]={0};
    for(i=2;i<1300000;i++){
        if((i==2 || i==3 || i==5)||(i%2 && i%3 && i%5)){buf[i]=i;}
    }
    for(i=0;i<sqrt(1300000);i++){
        if(!(buf[i])){continue;}
        for(j=i+1;j<1300000;j++){
            if(!(buf[j]%buf[i])){buf[j]=0;}
        }
    }
    j=0;
    for(i=0;i<1300000;i++){
        if(buf[i]){pr[j]=buf[i];j++;}
    }
    
    while(1){
        scanf("%d",&n);
        if(!n){break;}
        auto tg=lower_bound(pr,pr+100000,n);
        if(n==*tg){printf("0\n");}
        else{printf("%d\n",*tg-*(tg-1));}
    }        
    return 0;
}



Measured memory_bytes: 8088
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 200015

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;


ll N,A[maxn],sol;
map<ll,int> M;
int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N ;

    for(int i=1;i<=N;i++)
        cin >> A[i] , M[A[i]+i]++;

    for(int i=1;i<=N;i++)
        if(M.find(i-A[i])!=M.end())
            sol+=M[i-A[i]];

    cout << sol;







}


Measured memory_bytes: 17608