akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-9;
char str[100010];
int main()
{
    scanf("%s",str);
    int len=strlen(str);
    if(len==2&&str[0]==str[1])
    {
        printf("1 2\n");
        return 0;
    }
    for(int i=0;i<len-1;i++)
    {
        if(str[i]==str[i+1]||(i+2<len&&str[i]==str[i+2]))
        {
            if(str[i]==str[i+1])
            {
                if(i+1==len-1)
                {
                    printf("%d %d\n",len-2,len);
                    return 0;
                }
                else
                {
                    printf("%d %d\n",i+1,i+3);
                    return 0;
                }
            }
            else
            {
                printf("%d %d\n",i+1,i+3);
                return 0;
            }
        }
    }
    printf("-1 -1\n");
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int p[1010];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    sort(p,p+n);
    int sum=0;
    for(int i=0;i<k;i++){
        sum+=p[i];
    }
    cout<<sum<<"\n";
    return(0);
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    int K;
    cin >> K;
    set<string> all;
    for(int i = 0; i < S.size(); i++){
        string a = "";
        for(int j = 0; j < 5; j++){
            if(i+j>= S.size())continue;
            a += S.at(i+j);
            all.insert(a);
        }
    }
    
    auto itr = all.begin();
    for(int i = 0; i < K-1; i++){
        ++itr;
    }
    cout << *itr << endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

const int MAX = 101000;
ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll comb(ll n, ll r){
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

void init(){
	const int bound = 100500;
	fact[0] = 1;
	for( int i = 0; i < bound; ++i ) fact[i+1] = fact[i]*(i+1)%MOD;
	fact_inv[bound] = power( fact[bound], MOD-2 );
	for( int i = bound-1; i >= 0; --i ) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

bool exist[MAX];
	
int main(){
	int n; cin >> n;
	init();
	vector<int> a(n+1);
	int dup = 0;
	for( int i = 0; i <= n; ++i ){
		int tmp; cin >> tmp;
		if( exist[tmp] ) dup = tmp;
		exist[tmp] = true;
		a[i] = tmp;
	}
	int l = -1 , r = -1;
	for( int i = 0; i <= n; ++i ){
		if( a[i] == dup ){
			if( l == -1 ) l = i;
			else r = n-i;
		}
	}
	ll m = l+r;
	for( ll i = 1; i <= n+1; ++i ){
		if( m+1 < i ){
			cout << comb(n+1, i) % MOD << endl;
		} else {
			ll diff = comb( m+1, i ) - comb( m, i );
			cout << ( comb(n+1, i) - diff + MOD ) % MOD  << endl; 
		}
	}
    return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)

#define NIL -1
#define MAX 2000000

struct Node{
    int parent = NIL;
    int value = 0;
};

Node T[MAX];

int main(){
// ここに処理を記述
    int N, Q;
    cin >> N >> Q;

    int ai, bi;

    FOR(i,1,N){
        cin >> ai >> bi;
        T[bi].parent = ai;
    }

    int pj, xj;

    REP(i,Q){
        cin >> pj >> xj;
        T[pj].value += xj;
    }

    FOR(i,2,N+1){
        int p = T[i].parent;
        if(p != NIL) T[i].value += T[p].value;
    }

    REP(i,N){
        cout << T[i+1].value << " "; 
    }
    cout << "\n";

return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int A, B; cin >> A >> B;
	if (A <= 0 && B >= 0) {
		print("Zero");
	} else if (A >= 0) {
		print("Positive");
	} else {
		if ((B - A + 1) % 2 == 0) {
			print("Positive");
		} else {
			print("Negative");
		}
	}
}

Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll mod_pow(ll x, ll n, ll m) {
    if(n == 0) return 1;
    ll res = mod_pow(x * x % m, n / 2, m);
    if(n & 1) res = res * x % m;
    return res;
}

void solve() {
	int n, p; cin >> n >> p;
    string s; cin >> s;
    reverse(all(s));
    vector<int> cnt(n + 1, 0);
    rep(i, n) {
        cnt[i + 1] = ((cnt[i])+ (s[i] - '0') * mod_pow(10, i, p)) % p;
        //cerr << cnt[i + 1] << endl;
    }
    map<int, int> mp;
    int ans = 0;
    if(p != 2 && p != 5) {
        rep(i, n + 1) {
            mp[cnt[i]] ++;
        }
        for(int k = 0; k < p; ++k) {
            ans += (mp[k] * (mp[k] - 1)) / 2;
        }
    } else if(p == 2) {
        reverse(all(s));
        rep(i, n) {
            int c = s[i] - '0';
            if(c % 2 == 0) {
                ans += (i + 1);
            }
        }
    } else if(p == 5) {
        reverse(all(s));
        rep(i, n) {
            if(s[i] == '5' || s[i] == '0') {
                ans += (i + 1);
            }
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 2580
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		if(x + r > W || x - r < 0 || y - r < 0 || y + r > H)
			System.out.printf("No\n");
		else
			System.out.printf("Yes\n");
	}
}



Measured memory_bytes: 26420
#include <stdio.h>
int main()
{
  int h,m,s,S;
  int x;

  scanf("%d",&S);

  h=S/3600;
  x=S-3600*h;
  m=x/60;
  s=x-m*60;

  printf("%d:%d:%d\n",h,m,s);
  return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<climits>
#include<cfloat>

using namespace std;

double EPS=1e-10;

double add(double a,double b){
  if(abs(a+b)<EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x,y;
  point(){}
  point(double x,double y) : x(x) , y(y) {}

  point operator + (point p) {
    return point(add(x,p.x),add(y,p.y));
  }

  point operator - (point p) {
    return point(add(x,-p.x),add(y,-p.y));
  }

  point operator * (double d) {
    return point(x*d,y*d);
  }

  point operator / (double d) {
    return point(x/d,y/d);
  }

  bool operator == (const point &p)const{
    return abs(x-p.x)<EPS && abs(y-p.y)<EPS;
  }
};

struct circle{
  point p;
  double r;
  circle(){}
  circle(point p,double r):p(p),r(r){}
};

double dist(point a, point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

vector<point> circle_cross(circle a, circle b){
  vector<point>ret;

  double x=a.p.x-b.p.x,y=a.p.y-b.p.y;
  double L=x*x+y*y;

  if(L>pow(a.r+b.r,2))return ret;

  L=sqrt(L);
  double C=atan2(b.p.y-a.p.y,b.p.x-a.p.x);
  double alpha=acos((L*L+a.r*a.r-b.r*b.r)/(2*L*a.r));

  point r1,r2;
  r1.x=a.p.x+cos(C+alpha),r1.y=a.p.y+sin(C+alpha);
  r2.x=a.p.x+cos(C-alpha),r2.y=a.p.y+sin(C-alpha);

  ret.push_back(r1),ret.push_back(r2);
  return ret;
}

int main(void){

  int n;
  point a;
  vector<point>P;
  vector<circle>C;

  while(cin >> n,n){
    P.clear();
    C.clear();
    for(int i=0;i<n;i++){
      cin >> a.x >> a.y;
      P.push_back(a);
    }

    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	if(dist(P[i],P[j])>2.0+EPS)continue;
	vector<point>res=circle_cross(circle(P[i],1.0),circle(P[j],1.0));
	for(int k=0;k<res.size();k++){
	  C.push_back(circle(res[k],1));
	}
      }
    }

    int ans=1;
    for(int i=0;i<C.size();i++){
      int cnt=0;
      for(int j=0;j<P.size();j++)
	if(dist(C[i].p,P[j])<1.0+EPS)cnt++;
	
      ans=max(ans,cnt);
    }

    cout << ans << endl;
  }

  return 0;
}

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

int main(void) {
    int n;
    int sum = 0;
    cin >> n;
    vector<string> a(n);
    vector<string> b;
    
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    set<string> st(a.begin(), a.end());
    cout << st.size();
}

Measured memory_bytes: 25172
/*  4_1
    Y_Aizaki    */

#include <stdio.h>
#include <math.h>
#define PI 3.14159265359

/* プロトタイプ宣言 */
double radian(double hour_date, double minute_date);
double handDistance(double rad_date, double len_date1, double len_date2);

int main(void){
    double len_hour, len_minute, hour, minute;
    // 時針の長さ、分針の長さ、~時、~分
    scanf("%lf%lf%lf%lf", &len_hour, &len_minute, &hour, &minute);

    double rad;
    // 針間の角度
    rad = radian(hour, minute);

    double ans;
    // answer
    ans = handDistance(rad, len_hour, len_minute);
    printf("%.10f\n", ans);

    return 0;

}

double radian(double hour_date, double minute_date){
    double rad_hour, rad_minute, rad;

    rad_hour = (PI / 6.0) * hour_date + (PI / 360.0) * minute_date;
    rad_minute = (PI / 30.0) * minute_date;
    rad = rad_hour - rad_minute;
    
    return rad;
    // radが負であったり、PIより大きい場合もあるが、後の余弦定理で用いる点で支障はない

}

double handDistance(double rad_date, double len_date1, double len_date2){
    double distance;
    distance = sqrt(pow(len_date1, 2.0) + pow(len_date2, 2.0) - 2.0 * len_date1 * len_date2 * cos(rad_date));

    return distance;
}


Measured memory_bytes: 2600
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
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; cin >> N;
    map<char, int> res;
    rep(i,N) {
        string S; cin >> S;
        map<char, int> t;
        rep(j,S.size()) t[S[j]]++;
        if (i == 0) {res = t; continue;}
        else for (int a = 'a'; a <= 'z'; a++)
            if (t.count(a)) {if (res.count(a)) chmin(res[a], t[a]);}
            else res.erase(a);
    }

    for (auto x : res) {
        rep(i, x.second) cout << x.first;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<limits.h>
#include<utility>
#include<cstdlib>
#include<bitset>
#define LP(i,n) for(int i=0;i<n;i++)
#define LPIN(n,a) for(int i=0;i<n;i++)cin >> a[i]
using namespace std;

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

Measured memory_bytes: 256
input()
xs = list(map(int, input().split()))

def insertion_sort(xs):
  for i in range(1, len(xs)):
    v = xs[i]
    j = i - 1
    while j >= 0 and xs[j] > v:
      xs[j + 1] = xs[j]
      j -= 1
    xs[j + 1] = v
    print(*xs)

print(*xs)
insertion_sort(xs)

Measured memory_bytes: 8112
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
cd=[list(map(int,input().split())) for i in range(m)]

for a,b in ab:
    ans=-1
    kyori=float('inf')
    i=1
    for c,d in cd:
        if kyori>abs(a-c)+abs(b-d):
            ans=i
            kyori=abs(a-c)+abs(b-d)
        i+=1
    print(ans)

Measured memory_bytes: 67236
#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<<"Balanced"<<endl;
  } else if (a+b > c+d){
    cout<<"Left"<<endl;
  } else {
    cout<<"Right"<<endl;
  }
}


Measured memory_bytes: 256
n,m = map(int,input().split())
matrix = [list(map(int,input().split())) for i in range(n)]
vector = [int(input()) for i in range(m)]
for i in range(n):
    ans = 0
    for j in range(m):
        ans += matrix[i][j]*vector[j]
    print(ans)



Measured memory_bytes: 6016
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;


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

    int n, m;
    int s[11][11];
    int k[11], p[11];

    cin >> n >> m;
    rep(i, m) {
        cin >> k[i];
        rep(j, k[i]) {
            cin >> s[i][j];
            --s[i][j];
        }
    }
    rep(i, m) cin >> p[i];

    int ans = 0;
    rep(x, 1<<n) {
        bool ok = true;
        rep(i, m) {
            int cnt = 0;
            rep(j, k[i]) {
                if (x & (1 << s[i][j])) {
                    ++cnt;
                }
            }
            if (cnt % 2 != p[i]) {
                ok = false;
                break;
            }
        }
        if (ok) ++ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{

  int n,flg = 0;
  string s;

  cin >> n ;
  cin >> s ;

  if(n % 2 != 0){

    cout << "No" << endl;

  } else {

    n /= 2;

    for(int i=0; i<n; i++){
      if(s[i] != s[i+n]) flg = 1;
    }

    if(!flg) cout << "Yes" << endl;
    else cout << "No" << endl;

  }

  return 0;

}


Measured memory_bytes: 256
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()


def solve():
    c = Counter()
    for a in A:
        c[a - 1] += 1
        c[a] += 1
        c[a + 1] += 1

    x, k = c.most_common()[0]

    return k


print(solve())


Measured memory_bytes: 28092
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  
  cout << a[n-1] - a[0];
  
  return 0;
}

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

inline int rd() {int r;scanf("%d",&r);return r;}
int n,m,d[N];
int main() {
    n = rd(), m = rd();
    for (int i=1;i<=m;i++) d[rd()]++, d[rd()]++;
    int ans = 1;
    for (int i=1;i<=n;i++) if (d[i]&1) ans = 0;
    puts(ans?"YES":"NO");
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
 
int main()
{
    int n,t,mx;
    while(cin >> n, n)
    {
        mx = -(1<<30);
        int dt[5000]={0};
        for(int i=0; i<n; i++)
        {
            cin >> t;
            for(int j=0; j<=i; j++)
            {
                dt[j]+=t;
                mx=max(mx,dt[j]);
            }
        }
        cout << mx << endl;
    }
}


Measured memory_bytes: 3124
# cook your dish here
a,b,c = map(int, input().split())
k = int(input())
c1, c2 = 0, 0
while b<=a:
    b=b*2
    c1 = c1 + 1
while c <= b:
    c=c*2
    c2 = c2 +1
if c1 + c2 <= k:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9060
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	int i, j;
	int w;
	int a, b, ah, bh;
	int tempa, tempb;
	scanf("%d %d", &a, &b);
	a--;
	b--;
	w=100;
	ah=50;
	bh=50;
	if(!a and b) ah=0, b++;
	else if(!b and a) bh=0, a++;
	
	printf("%d %d\n", ah+bh, w);
	for(i=1; i<=ah; i++){
		for(j=1; j<=w; j++){
			if(i%3!=1 and i>1 and i<ah and j>1 and j<w and !(i&1)==(j&1) and a){
				putchar('.');
				a--;
			}
			else putchar('#');
		}
		putchar('\n');
	}
	
	for(i=1; i<=bh; i++){
		for(j=1; j<=w; j++){
			if(i%3!=1 and i>1 and i<bh and j>1 and j<w and !(i&1)==(j&1) and b){
				putchar('#');
				b--;
			}
			else putchar('.');
		}
		putchar('\n');
	}
	return 0;
}
/*
........
#.#.#.#.
........
#.#.#.#.
........
*/

Measured memory_bytes: 256
import itertools
import bisect
N, M ,K = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))

accum_al = list(itertools.accumulate(al))
accum_bl = list(itertools.accumulate(bl))
accum_al.insert(0,0)
accum_bl.insert(0,0)
# print(accum_al)
# print(accum_bl)

ans = 0
index = 0
for i in range(N+1):
    nokori = K - accum_al[i]
    if nokori < 0:
        continue
    else:
        index = bisect.bisect_right(accum_bl,nokori)-1
    tmp = i + index
    #print(i,index,tmp)
    if tmp > ans:
        ans = tmp
print(ans)

Measured memory_bytes: 47400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = 1e9+7;
const double EPS = 1e-9;

void solve() {
  string s, t;
  cin >> s >> t;

  map<char, vi> position;
  rep(i,s.size()) position[s[i]].push_back(i+1);  // 1-indexed
  for (auto &v : position) v.second.push_back(s.size()+1);

  ll loop = 0; int num = 0; int tmp;
  rep(j,t.size()) {
    if (!position.count(t[j])) {
      cout << -1 << endl;
      return;
    }

    tmp = num;
    num = *upper_bound(ALL(position[t[j]]), tmp);
    if (num > s.size()) {
      ++loop;
      num = position[t[j]][0];
    }
  }

  ll ans = loop * s.size() + num;
  cout << ans << endl;
  return;
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 1216
x, n = map(int, input().split())

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))

    p = sorted(p)
    pn = len(p)
    for i in range(pn):
        if x not in p:
            ans = x
        else:
            for j in range(100):
                if (x + j) not in p:
                    ans_1 = x + j
                    break
            for j in range(100):
                if (x - j) not in p:
                    ans_2 = x - j
                    break
            if abs(ans_1 - x) >= abs(ans_2 - x):
                ans = ans_2
            else:
                ans = ans_1
    print(ans)


Measured memory_bytes: 9176
#include<stdio.h>
#define N 200000

int main(){
  int i, j, n, max, min, sum;
  int A[N];
  
  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  max = A[1] - A[0];
  min = A[0];
  for(i = 1; i < n; i++){
    if(max < A[i] - min) max = A[i] - min;
    if(min > A[i]) min = A[i];
  }
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 1380
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define sortv(v) sort(v.begin(),v.end())
#define sorta(A,N) sort(A,A+N)
#define rep(i,a,N) for(ll i=a;i<N;i++)
#define test(T) ll T; cin>>T; while(T--)
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
/*ll gcd(ll a,ll b){
    if(!a)
        return b;
    else
        return gcd(b%a,a);
}
ll N=1e7+1;
vector<ll>prime(N);
ll power(ll a,ll b){
    a%=MOD;
    ll res=1;
    while(b){
        if(b&1)
            res*=a%MOD;
        a*=a%MOD;
        b>>=1;
    }
    return res;
}
void sieve(){
    rep(i,0,N) prime[i]=i;
    for(ll i=4;i<N;i+=2)
        prime[i]=2;
    for(ll i=3;i*i<N;i+=2){
        if(prime[i]==i)
            for(ll j=i*i;j<N;j+=i)
                if(prime[j]==j)
                    prime[j]=i;
    }
}
vector<ll> factor(ll N){
    vector<ll> fac;
    while(N!=1){
        fac.pb(prime[N]);
        N/=prime[N];
    }
    return fac;
}*/
void solve(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    double A,B,N,x;
    cin>>A>>B>>N;
    if(N>=B) x=B-1;
    else x=N;
    cout<<floor(A*x/B)-A*floor(x/B);
}
int main(){
    speed;
    solve();
}


Measured memory_bytes: 3792
N = int(input())
a,b,c = [0]*N,[0]*N,[0]*N

for i in range(N):
    a[i],b[i],c[i] = map(int,input().split())
    
#3パターンがN日
dp = [[0]*3 for i in range(N)]
#初期値は以下
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]

#二日目以降の操作(i日目に?操作した場合のdp)
for i in range(1,N):
    dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i]
    dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b[i] 
    dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c[i] 
    
print(max(dp[-1]))

Measured memory_bytes: 61784
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> work(100005);
    for(int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        work[a].emplace_back(b);
    }
    priority_queue<int> que;
    ll ans = 0;
    for(int i = 0; i <= m; i++) {
        for(int w : work[i]) {
            que.push(w);
        }
        if(!que.empty()) {
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
int ans;
int main(){
    char c=getchar();
    while(c!='\n') {
    	ans+=(int)(c-'0');
    	ans%=9;
    	c=getchar();
	}
	if(ans==0) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3628
package main

import(
  "fmt"
  "sort"
)

func main() {
  var n, l int
  fmt.Scan(&n, &l)
  s := make([]string, n)
  for i := range s {
    fmt.Scan(&s[i])
  }
  sort.Strings(s)
  for _, t := range s {
    fmt.Print(t)
  }
}


Measured memory_bytes: 512
"""
事前に、100000以下の数のうち、2017に似た数を列挙しておく。
メモの仕方としては、2017に似た数を小さい順に並べておけばよい。
2017に似た数を探すのは、まず100000以下の素数を全部列挙して、その中で条件に当てはまるものを愚直に探す。
"""
memo = [1]*(100001)
memo[0] = 0
memo[1] = 0
primes = set()
for i in range(100001):
    if memo[i] == 1:
        primes.add(i)
        for j in range(i*2,100001,i):
            memo[j] = 0

answers = []
for p in primes:
    if (p+1)//2 in primes:
        answers.append(p)

Q = int(input())
for _ in range(Q):
    ans = 0
    l,r = map(int,input().split())
    for a in answers:
        if l<=a<=r:
            ans += 1
    print(ans)

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

int main(void){
    int a,b,c,d;
    long long s1,s2;

    cin >> a >> b >> c >> d ;
    s1 = a*b;
    s2 = c*d;
    cout << max(s1, s2) << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {
		Scanner scn = new Scanner(System.in);
		String str = scn.nextLine();
		int step = scn.nextInt();
		for(int i = 0;i < str.length();i += step) {
			System.out.print(str.toCharArray()[i]);
		}
		System.out.println();
	}

	public static double f(double theta) {
		return theta - Math.sin(theta * 2)/2;
	}
}

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

int main() {
  // 入力(4桁の数字)を受け取る
  int N;
  cin >> N;
  
  // 便宜上、各桁を分解する
  int N1 = N % 10;			// 1桁め
  int N2 = (N / 10) % 10;	// 2桁め
  int N3 = (N / 100) % 10;	// 3桁め
  int N4 = (N / 1000) % 10;	// 4桁め
  
  // 「良い整数」か判定
  bool bGood = false;
  if(N1 == N2 && N2 == N3){
    cout << "Yes" << endl;
  }
  else if(N2 == N3 && N3 == N4){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
implicit none
INTEGER(8) :: n,i,ans,k
REAL(8),ALLOCATABLE,DIMENSION(:) :: a

ans = 0
k = 0

READ(5,*) n
ALLOCATE(a(n))
READ(5,*) (a(i),i=1,n)

call heapsort(n,a)

do i=n,1,-1
    if(MOD(n-i,2)==0)then
        ans = ans+a(i)
    else
        ans = ans-a(i)
    endif
enddo

WRITE(6,"(i0)") ans

end

!---http://slpr.sakura.ne.jp/qp/sortf90/---
subroutine heapsort(n,array)
    implicit none
    INTEGER(8),INTENT(IN) :: n
    DOUBLE PRECISION,INTENT(INOUT) :: array(1:n)

    INTEGER :: i,k,j,l
    DOUBLE PRECISION :: t

    if(n.le.0)then
        WRITE(6,*)"Error, at heapsort"; stop
    endif

    if(n.eq.1)return
        l=n/2+1
        k=n
        do while(k.ne.1)
            if(l.gt.1)then
                l = l-1
                t = array(l)
            else
                t=array(k)
                array(k) = array(l)
                k = k-1
                if(k.eq.1)then
                    array(1) = t
                    exit
                endif
            endif
            i = l
            j = l+l
            do while(j.le.k)
                if(j.lt.k)then
                    if(array(j).lt.array(j+1))j=j+1
                endif
                if(t.lt.array(j))then
                    array(i)=array(j)
                    i=j
                    j=j+j
                else
                    j=k+1
                endif
            enddo
            array(i)=t
    enddo
    RETURN
end subroutine


Measured memory_bytes: 768
import math
N = int(input())
A = list(map(int, input().split()))

s = math.ceil(sum(A)/N)
t = math.floor(sum(A)/N)

ans_s = 0
ans_t = 0
for a in A:
    ans_s += (a-s)**2
    ans_t += (a-t)**2
print(min(ans_s, ans_t))


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<long long int, long long int>> ab(n);
    for(auto& e : ab) cin >> e.first >> e.second;
    sort(ab.begin(), ab.end());
    long long int res = 0;
    for(int i = 0;i < n;i++){
        if(m >= ab[i].second){
            m -= ab[i].second;
            res += ab[i].first * ab[i].second;
        }else{
            res += m * ab[i].first;
            break;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};

signed main(){
  int n;
  cin>>n;
  r(i,100){
    r(j,100){
      if(i*4+j*7==n){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
 
using namespace std;

/**************************************************************************/
int main()
{
	fastIO;
	ll a,b,c;
	cin>>a>>b;
	c = a + b - 1;
	cout<<a*b-c;
}/*************************************************************************/ 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

  char maze[2010][2010];
  int yoko[2010][2010];
  int tate[2010][2010];
void solve() {
  int ans = 0;
  int h,w;
  cin >> h >> w;
  REP(i,h) REP(j,w) cin >> maze[i][j];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] == '.') {
        int cnt = 0;
        int k = j;
        while (k < w && maze[i][k] == '.') {
          cnt++;
          k++;
        }
        for (int kk = j; kk < k; kk++) {
          yoko[i][kk] = cnt;
        }
        j = k;
      }
    }
  }
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (maze[j][i] == '.') {
        int cnt = 0;
        int k = j;
        while (k < h && maze[k][i] == '.') {
          cnt++;
          k++;
        }
        for (int kk = j; kk < k; kk++) {
          tate[kk][i] = cnt;
        }
        j = k;
      }
    }
  }
  REP(i,h) {
    REP(j,w) {
      if (maze[i][j] == '.')
        ans = max(ans, tate[i][j] + yoko[i][j] - 1);
    }
  }
  cout << ans << endl;
}

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

  /*Regular*/
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }

  // /*ICPC*/
  // while (cin >> t >> d >> l, t) {
  //   solve();
  // }

  //solve();
  return 0;
}

Measured memory_bytes: 35712
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int a[n+1]={};

  for(int i=0;i<=1;i++){
    for(int j=0;j<=1;j++){
      a[0]=i;
      a[1]=j;
      int flag1=0,flag2=0;
      for(int k=2;k<n;k++){
        if(a[k-1]==0&&s[k-1]=='o') a[k]=a[k-2];
        if(a[k-1]==0&&s[k-1]=='x') a[k]=a[k-2]^1;
        if(a[k-1]==1&&s[k-1]=='o') a[k]=a[k-2]^1;
        if(a[k-1]==1&&s[k-1]=='x') a[k]=a[k-2];
      }
      if(a[0]==0&&s[0]=='o'&&a[n-1]==a[1]) flag1=1;
      if(a[0]==0&&s[0]=='x'&&a[n-1]!=a[1]) flag1=1;
      if(a[0]==1&&s[0]=='o'&&a[n-1]!=a[1]) flag1=1;
      if(a[0]==1&&s[0]=='x'&&a[n-1]==a[1]) flag1=1;
      if(a[n-1]==0&&s[n-1]=='o'&&a[n-2]==a[0]) flag2=1;
      if(a[n-1]==0&&s[n-1]=='x'&&a[n-2]!=a[0]) flag2=1;
      if(a[n-1]==1&&s[n-1]=='o'&&a[n-2]!=a[0]) flag2=1;
      if(a[n-1]==1&&s[n-1]=='x'&&a[n-2]==a[0]) flag2=1;
      if(flag1&&flag2){
        for(int l=0;l<n;l++){
          if(a[l]) cout<<'W';
          else cout<<'S';
        }
        cout<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 896
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long h = sc.nextLong();
		long w = sc.nextLong();

		if ( h==1 || w==1) {
			System.out.println(1);
			System.exit(0);
		}
		// 出力
		System.out.println(w*(h/2l)+(h%2l)*(w+1l)/2l);
	}
}

Measured memory_bytes: 21716
/* Simplicity and Goodness */
 
#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;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;


void solve()
{   
    string s;
    cin >> s;

    int l = 0, r = (int)s.size() - 1;

    int cnt = 0; bool ok = 1;

    while(!s.empty() and (l < r)) {
        if(s[l] == s[r]) {
            l ++; r --;
        } else if(s[l] == 'x') {
            cnt ++; l ++;
        } else if(s[r] == 'x') {
            cnt ++; r --;
        } else {
            ok = 0; break;
        }
    }

    if(ok) {
        prin(cnt);
    } else {
        prin(-1);
    }
}

int main()
{
    int t = 1;
    // scn(t);

    while(t --) {
        solve();
    }
    return 0;
}

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

int main(){
  int A, B, T;
  cin >> A >> B >> T;

  cout << B * (T / A) << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
constexpr int N = 100'000, INF = 1'000'000'000;
int n, k, s;
int a[N];
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n >> k >> s;
    for (int i = 0; i < k; ++i)
        a[i] = s;
    for (int i = k; i < n; ++i) {
        if (s == INF) {
            a[i] = s - 1;
        } else {
            a[i] = s + 1;
        }
    }
    for (int i = 0; i < n; ++i)
        std::cout << a[i] << " \n"[i == n - 1];
    return 0;
}

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

int main(){
  int N,ans=0,min;
  cin>>N;
  
  int P[N];
  
  for(int i=0;i<N;i++){cin>>P[i];}
  
  for(int i=0;i<N;i++){
    if(i==0){min=P[i];ans++;}
    
    if(P[i]<min){
      ans++;min=P[i];
    }
  }
  
  cout<<ans<<endl;
}
    

Measured memory_bytes: 1024
#include <algorithm>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

void update(map<int, int>& tab, int w, int v)
{
    tab[w] = max(tab[w], v);
}

int main()
{
    int N, W;
    cin >> N >> W;
    map<int, vector<int>> weightValues;
    for (int i = 0; i < N; ++i) {
        int w, v;
        cin >> w >> v;
        weightValues[w].push_back(v);
    }

    map<int, int> tab;
    tab.insert(make_pair(0, 0));

    for (auto iter : weightValues) {
        map<int, int> ntab;

        vector<int>& vv = iter.second;
        sort(vv.begin(), vv.end(), greater<int>());

        int w = iter.first;

        for (auto titer : tab) {
            int tabw = titer.first;
            int tabv = titer.second;

            update(ntab, tabw, tabv);

            for (int v : vv) {
                tabw += w;
                tabv += v;
                if (tabw > W)
                    break;
                update(ntab, tabw, tabv);
            }
        }

        ntab.swap(tab);
    }

    int ans = 0;
    for (auto iter : tab) {
        ans = max(ans, iter.second);
    }

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


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>

#define MAX(a, b) ((a > b) ? a : b)

static void countNumOfAlphabet(const uint32_t N, const char * S, uint32_t *counter) {
	for (uint32_t idx = 0; idx < N; idx++) {
		counter[S[idx] - 'a']++;
	}
}

static uint32_t countSameAlphabet(const uint32_t * const left, const uint32_t * const right) {
	uint32_t sameCount = 0;
	for (uint32_t idx = 0; idx < 26; idx++) {
		if (left[idx] > 0 && right[idx] > 0) {
			sameCount++;
		}
	}

	return sameCount;
}

int main(void) {
	uint32_t N; 
	char S[101];
	uint32_t max = 0;

	scanf("%"PRIu32"\n%s", &N, &S);

	uint32_t leftCount[26];
	uint32_t rightCount[26];
	for (uint32_t idx = 0; idx < 26; idx++) {
		leftCount[idx] = 0;
		rightCount[idx] = 0;
	}
	countNumOfAlphabet(N, S, rightCount);

	for (uint32_t cutPos = 0; cutPos < N - 1; cutPos++) {
		rightCount[S[cutPos] - 'a']--;
		leftCount[S[cutPos] - 'a']++;

		const uint32_t sameCount = countSameAlphabet(leftCount, rightCount);
		if (sameCount > max) {
			max = sameCount;
		}
	}

	printf("%"PRIu32, max);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,k;
double a[N];
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%lf",&a[i]);
        a[i]=a[i]*(a[i]+1)/2/a[i];
        a[i]+=a[i-1];
    }
    double ans=0;
    for(int i=k;i<=n;i++)
    {
        ans=max(ans,a[i]-a[i-k]);
    }
    printf("%.10f\n",ans);
}


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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int  i = 0; i < N; i++){
	cin >> a[i];
    }

    vector<vector<int>> x(N, vector<int>(20, 0));
    for (int i = 0; i < N; i++){
	int t = a[i];
	int j = 0;
	while (t > 0){
	    x[i][j] = t%2;
	    t /= 2;
	    j++;
	}
    }

    ll res = 1;
    int l = 0, r = 0;
    bool bit[20];
    for (int i = 0; i < 20; i++){
	if (x[0][i] == 1) bit[i] = true;
	else bit[i] = false;
    }
    while (l < N){
	if (r < N-1){
	    bool can = true;
	    for (int i = 0; i < 20; i++){
		if (x[r+1][i] == 0) continue;
		if (bit[i] == true) can = false;
	    }

	    if (!can){
		for (int i = 0; i < 20; i++){
		    if (x[l][i] == 1){
			bit[i] = false;
		    }
		}
		l++;
		res += (r-l+1);
	    } else {
		for (int i = 0; i < 20; i++){
		    if (x[r+1][i] == 1) bit[i] = true;
		}
		res++;
		r++;
	    }
	} else {
	    l++;
	    res += (r-l+1);
	}
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 24448
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n,a;
	cin>>n;
	set<int> s;
	for (int i = 0; i < n; ++i)
		{
			cin>>a;
			s.insert(a);
		}	
    SZ(s)==n?cout<<"YES":cout<<"NO";
   return 0;
}


Measured memory_bytes: 13032
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main(){
      
  fastio();
  int n,m,i,j,t;
  cin>>n;
  map<int,int> occ;
  int ans=-1;
  cin>>n;	
  i=1;
  occ[n]=1;
  //cout<<n<<" "<<i<<"\n";
  while(true)
  {
  	if(n&1)
  		n=3*n+1;
  	else
  		n=n/2;
  	i++;
  	//cout<<n<<" "<<i<<endl;
  	if(occ[n]==0)
  		occ[n]=i;
  	else
  	{
  		ans=i;
  		break;
  	}
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
int A[N];
 
int Partition( int p, int r ){
  int x,change;
  int i,j;
  x=A[r];
  i=p-1;

  for(j=p;j<r;j++){
    if(A[j]<=x)
      {
	i++;
	change=A[i];
	A[i]=A[j];
	A[j]=change;
      }
  }

  change=A[i+1];
  A[i+1]=A[r];
  A[r]=change;
  return i+1;
}



int main()
{
  int n,x,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      scanf("%d",&A[i]);
      //配列
    }
  x=Partition(1,n);
  for(i=1;i<=n;i++)
    {
      if(i==x)
	{
	  printf("[%d]",A[i]);  
	}
      else
	{
	  printf("%d",A[i]);
	}
      if(i<n)
	{
	  printf(" ");
	}
    }
  printf("\n");
  return 0;
}

Measured memory_bytes: 992
import java.util.Arrays;
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());
		int[] A = new int[N];
		int[] sortedA = new int[N];
		int idx;
		for (idx = 0; idx < N; idx++) {
			A[idx] = Integer.parseInt(sc.next());
			sortedA[idx] = A[idx];
		}
		Arrays.parallelSort(sortedA);

		int max = sortedA[N - 1];
		int second = sortedA[N - 2];

		for (idx = 0; idx < N; idx++) {
			if (A[idx] == max) {
				System.out.println(second);
			} else {
				System.out.println(max);
			}
		}

	}

}


Measured memory_bytes: 71908
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

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

int main() {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;

    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        cnt++;
        if (i == a) {
            if (s[i] != '-') {
                cout << "No" << endl;
                return 0;
            }
        } else if (!isdigit(s[i])) {
            cout << "No" << endl;
            return 0;
        }
    }

    if (cnt == a + b + 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int n,a[100005];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	scanf("%d",&a[i]);
	}
	int ans=0;
	for(int i=1;i<n;i++){
		if(a[i]==a[i+1]){
			ans++;a[i+1]=(i+n);
		}
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 764
#include<stdio.h>
int main(){
	int c=0;
	int d=0;
	char b[100000];
	char e[100000];
	
	scanf("%d",&d);
	scanf("%s",b);

	for(int i=1;i<d;i++)
	{		
			if(b[i]!=b[i-1]) 
			 {
				e[c]=b[i];
				c++;
			}	
	}
	
	printf("%d",c+1);	
	return 0;
} 

Measured memory_bytes: 256
a,b,c,x = 4.times.map{gets.to_i}
count = 0

(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      count +=1 if (i * 500) + (j * 100) + (k * 50) == x
    end
  end
end

puts count

Measured memory_bytes: 1916
# -*- coding: utf-8 -*-
k = int(input())

r = 0
c = 0
for i in range(1, 1000001):
    r *= 10
    r += 7
    c += 1

    r %= k
    if r == 0:
        break

if r != 0:
    print(-1)
else:
    print(c)


Measured memory_bytes: 9164
#include<bits/stdc++.h>
    using namespace std;
    const int MAXN = 100005;
    const long long INF = 1e18;
    template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
    template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
    template <typename T> void read(T &x) {
    	x = 0; int f = 1;
    	char c = getchar();
    	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
    	x *= f;
    }
    template <typename T> void write(T x) {
    	if (x < 0) x = -x, putchar('-');
    	if (x > 9) write(x / 10);
    	putchar(x % 10 + '0');
    }
    template <typename T> void writeln(T x) {
    	write(x);
    	puts("");
    }
    int n; long long ans, c;
    long long x[MAXN], v[MAXN], pre[MAXN], sum[MAXN];
    void solve(long long c) {
    	for (int i = 1; i <= n; i++) {
    		sum[i] = sum[i - 1] + v[i];
    		pre[i] = max(pre[i - 1], sum[i] - x[i]);
    	}
    	long long now = 0;
    	for (int i = n; i >= 1; i--) {
    		chkmax(ans, now + pre[i]);
    		now += v[i] - 2 * (c - x[i]);
    		c = x[i];
    	}
    }
    int main() {
    	read(n), read(c);
    	for (int i = 1; i <= n; i++)
    		read(x[i]), read(v[i]);
    	solve(c);
    	for (int i = 1; i <= n; i++)
    		x[i] = c - x[i];
    	reverse(x + 1, x + n + 1);
    	reverse(v + 1, v + n + 1);
    	solve(c);
    	writeln(ans);
    	return 0;
    }

Measured memory_bytes: 3328
from itertools import accumulate
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
s = list(accumulate(a))

ans = float("inf")

for j in range(2,n-1):
    i_list = []
    i_left = bisect_left(s, s[j-1]//2)-1
    if i_left != -1:
        i_list.append([s[i_left], s[j-1]-s[i_left]])
    if i_left != j-2:
        i_list.append([s[i_left+1], s[j-1]-s[i_left+1]])

    k_list = []
    k_left = bisect_left(s, s[j-1]+(s[-1]-s[j-1])//2)-1
    if k_left != j-1:
        k_list.append([s[k_left] - s[j-1], s[-1]-s[k_left]])
    if k_left != n-2:
        k_list.append([s[k_left+1] - s[j-1], s[-1]-s[k_left+1]])
    for i in i_list:
        for k in k_list:
            tmp = max(i+k)-min(i+k)
            ans = min(ans, tmp)
print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  auto y = x;
  sort(x.begin(), x.end());
  int mid = n / 2;
  int minv = x[mid - 1];
  int maxv = x[mid];
  for (int i = 0; i < n; i++) {
    if (maxv > y[i]) {
      cout << maxv << endl;
    } else {
      cout << minv << endl;
    }
  }
}


Measured memory_bytes: 3712