akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<map>
#include<algorithm>
#include<utility>
using namespace std;

int main(void)
{
	int n;
	cin >> n;

	int v;
	vector<map<int, int>> mp(2, map<int, int>());
	for(int i=0; i<n; i++){
		cin >> v;

		mp[i%2][v]++;
	}

	vector<vector<pair<int, int>>> vct(2, vector<pair<int, int>>());
	for(int i=0; i<2; i++){
		for(auto it=mp[i].begin(); it!=mp[i].end(); it++)
			vct[i].push_back(make_pair(it->second, it->first));

		sort(vct[i].rbegin(), vct[i].rend());
	}

	int ret = n;
	if(vct[0].size() == 1 && vct[1].size() == 1 && vct[0][0].second == vct[1][0].second)
		ret /= 2;
	else{
		for(auto i : vct[0]){
			for(auto j : vct[1]){
				if(i.second == j.second)
					continue;

				ret = min(ret, n - i.first - j.first);
				break;
			}
		}
	}

	cout << ret << endl;

	return 0;
}


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

const int N = 1e6 + 10;

map<int, int> vis, c;
vector<int> v;

int main (void) {
	int n;
	scanf("%d", &n);
	for (int i = 1, val; i <= n; i++) {
		scanf("%d", &val);
		if (!vis[val]) {
			vis[val] = 1;
			v.push_back(val);
		}
		c[val] ++;
	}
	if (v.size() == 1) {
		if (v[0] == 0) {
			puts("Yes");
		} else {
			puts("No");
		}
	} else if (v.size() == 2) {
		sort(v.begin(), v.end());
		if (c[v[0]] * 2 == c[v[1]]) puts("Yes");
		else puts("No");
	} else if (v.size() == 3) {
		if ((v[0] ^ v[1] ^ v[2]) == 0) {;
			if (c[v[0]] == c[v[1]] && c[v[0]] == c[v[2]]) puts("Yes");
			else puts("No");
		}
		else 
			puts("No");
	} else {
		puts("No");
	}
}

Measured memory_bytes: 7800
# from sys import exit
N = int(input())
S = [str(input()) for _ in range(N)]
Aend = 0
Bstart = 0
BstartAend = 0
ABcon = 0
for s in S:
    if s[0] == "B" and s[-1] == "A":
        BstartAend += 1
    elif(s[0] == "B"):
        Bstart += 1
    elif(s[-1] == "A"):
        Aend += 1
    ABcon += s.count("AB")
# 小さい方を答えへ、そうじゃないのはあまり
tmp = min(Aend, Bstart)
if BstartAend == 0:
    print(ABcon + tmp)
else:
    if max(Aend, Bstart) == 0:
        print(ABcon + BstartAend - 1)
    else:
        print(ABcon + BstartAend + tmp)


Measured memory_bytes: 44632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 * 2;

int main() {
	int a[3];
	rep(i, 3) cin >> a[i];
	int k;
	cin >> k;
	sort(a, a + 3, greater<int>());
	ll out = a[0] * pow(2, k) + a[1] + a[2];
	cout << out << endl;
}


Measured memory_bytes: 4032
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
int GCD(int a,int b){
	if(!b)
		return a;
	return GCD(b,a%b);
}
int main(){
	int x;
	scanf("%d",&x);
	printf("%d\n",360/GCD(x,360));
}


Measured memory_bytes: 1728
main::IO()
main=do
  nc<-getLine
  kc<-getLine
  xc<-getLine
  yc<-getLine
  let n:k:x:y:[]=map read [nc,kc,xc,yc]::[Int]
  print (if n>k then ((n-k)*y)+(k*x) else n*x)

Measured memory_bytes: 508
#include <stdio.h>
int main(void){
char s[120];
  int n;
  int b=0,r=0,count;
  scanf("%d",&n);
  scanf("%s",s);
  for(count=0;s[count]!='\0';count++){
  if(s[count]=='B'){b++;}
      if(s[count]=='R'){r++;}
     // printf("A");
  }
  //printf("%d",r);
  if(r>b){printf("Yes");}
  else{printf("No");}
return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};

using P = Point<long long>;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		P p0, p1;
		cin >> p0.x >> p0.y >> p1.x >> p1.y;
		P p2, p3;
		cin >> p2.x >> p2.y >> p3.x >> p3.y;
		if((p1 - p0).cross(p3 - p2) == 0){
			cout << 2 << '\n';
		} else if((p1 - p0).dot(p3 - p2) == 0){
			cout << 1 << '\n';
		} else {
			cout << 0 << '\n';
		}
	}
}


Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;


int main(void){
  int n;
  cin >> n;
  cout << (1000-n%1000)%1000 << endl;
}


Measured memory_bytes: 3620
# coding: utf-8
import math


def sosuu(target):

    dst = int(math.sqrt(target))
    for i in range(2, dst):
        if target % i == 0:
            return False
    return True


def main():

    i = int(input())

    while True:
        if sosuu(i):
            print(i)
            break
        else:
            i += 1

    return 0

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int> >
#define ll long long
const int INF = 1e8;
const int MAXN = 3e5 + 200;
const  long double eps = 1e-9;
const long double pi = acos(-1.0);
using namespace std;

int n, k;
vector <int> g[MAXN];
int d[3001][3001];
void dis(){

}
void dis(int x){
    for (int i = 1; i <= n; i++) d[x][i] = -1;
    d[x][x] = 0;
    deque <int> q;
    q.pb(x);

    while (!q.empty()){
        int v = q.front();
        q.pop_front();
        for (auto u : g[v]){
            if (d[x][u] != -1) continue;
            d[x][u] = d[x][v] + 1;
            q.pb(u);
        }
    }

}
void solve(){
    cin >> n >> k;

    for (int i = 1; i <= n - 1; i++){
        int x, y;
        cin >> x >> y;
        g[x].pb(y); g[y].pb(x);
    }
    for (int i = 1; i <= n; i++)
        dis(i);


    int ans = 0;


    for (int v = 1; v <= n; v++){
        int kol = 0;
        if (k % 2 == 0) {
            for (int i = 1; i <= n; i++) if (d[v][i] <= k / 2) kol++;
            ans = max(ans, kol);
        }else {
            for (auto u : g[v]){
                kol = 0;
                for (int i = 1; i <= n; i++) if (min(d[v][i], d[u][i]) <= k / 2) kol++;
                ans = max(ans, kol);
            }
        }
    }

    cout << n - ans << endl;
}
/*
 6 1
 1 2
 2 3
 3 4
 4 5
 5 6
 */
int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(7);
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout)
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++)
        solve();

}

Measured memory_bytes: 32384
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

void main()
{
    auto K = readln.chomp.to!(char[]);
    auto D = readln.chomp.to!long;

    auto DP1 = new long[][](2, D);
    auto DP2 = new long[][](2, D);
    foreach (i, c; K) {
        if (i == 0) {
            foreach (x; 0..c-'0') {
                ++DP1[0][x % D];
            }
            ++DP1[1][(c-'0') % D];
        } else {
            foreach (x; 0..D) {
                foreach (y; 0..10) {
                    DP1[0][(x+y)%D] = (DP1[0][(x+y)%D] + DP2[0][x]) % P;
                }
                foreach (y; 0..c-'0') {
                    DP1[0][(x+y)%D] = (DP1[0][(x+y)%D] + DP2[1][x]) % P;
                }
                DP1[1][(x+c-'0')%D] = (DP1[1][(x+c-'0')%D] + DP2[1][x]) % P;
            }
        }
        DP2[0][] = DP1[0][].dup;
        DP2[1][] = DP1[1][].dup;
        DP1[0][] = 0;
        DP1[1][] = 0;
    }
    writeln((DP2[1][0] + DP2[0][0] - 1 + P) % P);
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
	int tmp;
	int cnt=0;
	rep(i,5){
		cin >> tmp;
		cnt++;
		if(tmp==0) {
			cout << cnt <<endl;
			return 0;
		}
	}
  return 0;
}

Measured memory_bytes: 3628
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhilash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();
            int east = 0;
            int west = 0;
            for (int i = 0; i < n; i++) {
                if (s.charAt(i) == 'E')
                    east++;
                else
                    west++;
            }
            int ans = Integer.MAX_VALUE;
            int ce = 0, cw = 0;
            for (int i = 0; i < n; i++) {
                int req = cw + east - ce + (s.charAt(i) == 'E' ? -1 : 0);
                ans = Math.min(ans, req);
                if (s.charAt(i) == 'E')
                    ce++;
                else
                    cw++;
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, a;
  cin >> n >> a;

  int ans = n * n - a;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//g++  5.4.0
 
#include<bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int inf = 2e18;
signed main()
{
    fast;
    int n;
    cin >> n;
    vector< int  > a(n+1,0 );
    for(int i=1 ; i<=n ; i++ )
    {
        cin >> a[i];
        a[i] += a[i-1];
    }
    
    int dp[ n+1 ][ n+1 ];
   
    for(int i=1 ; i<=n ; i++ ) dp[i][i] = 0;
    
    for(int len=2 ; len<=n ; len++ )
    {
        for(int st=1 ; st+len-1 <=n ; st++ )
        {
            int i = st;
            int j = st+len-1;
            dp[i][j] = inf;
            for(int mid = st+1 ; mid <= st+len-1 ; mid++ )
                dp[i][j] = min( dp[i][j] , dp[i][mid-1] + dp[mid][j] + a[j]-a[i-1] );
        }
    }
    cout << dp[1][n];
}

Measured memory_bytes: 1536
#include <stdio.h>

#define		MXARY			100+5

void	insertionSort(int A[MXARY], int);

int		A[MXARY]={'\0'};

int		main(void)
{
	int		N;
	int		k;

	scanf("%d",&N);
	for(k=0; k<N; k++)
	{
		scanf("%d",&A[k]);
	}
	for(k=0; k<N-1; k++)
	{
		printf("%d ",A[k]);
	}
	printf("%d\n",A[k]);
	insertionSort(A, N);
	return 0;
}

void 	insertionSort(int A[MXARY], int N)
{
	int		i, j, k;
	int		v;

	for(i=1; i<N; i++)
	{
		v = A[i];
		j = i - 1;

		while( j >= 0 && A[j] > v )
		{
			A[j+1] = A[j];
			j--;
			A[j+1] = v;
		}
		for(k=0; k<N-1; k++)
		{
			printf("%d ",A[k]);
		}
		printf("%d\n",A[k]);
	}
}

Measured memory_bytes: 600
//#include <bits/stdc++.h>
#include <iostream>
#include <climits>

using namespace std;

#define rep(i , n) for(int i=0 ; i<n ; i++)
#define rep1(i , n) for(int i=1 ; i<=n ; i++)

typedef long long int ll;


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

	int n,total;
	cin >> n >> total;
	int arr[100];

	rep(i , n)
		cin >> arr[i];

	int sum = 0;
	int min1 = INT_MAX;
	rep(i , n)
	{
		min1 = min(min1 , arr[i]);
		sum += arr[i];
	}

	total -= sum;
	cout << (n+(total/min1));
	return 0;
}

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






int ispalindrome(string s)
{
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        if(s[i]!=s[n-i-1])
        return 0;
    }
    return 1;
}

bool test=0;
void solve()
{
 
    int n;
    double x,y,ans;
    cin>>n;
    x=n/3.0;
    cout<<fixed<<setprecision(12)<<(x*x*x);
}



















int main() {
    int t=1;
	if(test)
	cin>>t;
	while(t--)
	{
	    solve();
	}
	return 0;
}


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

int main() {
	int n,red=0,blue=0;
	cin >> n;
	vector<char>rb(n);
	for (int i = 0; i < n; i++) {
		cin >> rb[i];
		if (rb[i] == 'R') {
			red++;
		}
		else {
			blue++;
		}
	}
	if (red > blue) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define mx *max_element
#define mi *min_element
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
int ncr(int n,int r){if(n<r)return 0;int p=1,k=1;if(n-r<r)r=n-r;if(r!=0){while(r){p*=n;k*=r;int g=__gcd(p, k);p/=g;k/=g;n--;r--;}}else p=1;return p;}
#define pi acos(-1)
int ar[N];
int tree[2*N];
int dp[N];
int bit[N];
signed main(){
 	
	SaveTime;
	int T=1;
	// cin >> T;
	while(T--){
		int n , m;
		cin >> n >> m;
		priority_queue <int>pq;
		for(int i =0 ;i < n ;i++){
			int x;
			cin >> x;
			pq.push(x);
		}
		for(int i =0 ;i < m ;i++){
			int x= pq.top();
			pq.pop();
			pq.push(x/2);
		}
		int ans = 0 ;
		while(!pq.empty()){
			int x= pq.top();
			ans+=x;
			pq.pop();
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int x,y,z=1;
    x = scanner.nextInt();
    y = scanner.nextInt();

    while(!(z==0)){
      if(x<y){
        z=x;
        x=y;
        y=z;
      }
      z = x % y;
      if(z==0){
        System.out.println(y);
      }
      x = y;
      y = z;
    }
  }
}



Measured memory_bytes: 26272
def main():
    n = int(input())
    aa = [int(input()) - 1 for _ in range(n)]
    visiteds = [False] * n
    i = 0
    res = 0
    while True:
        if visiteds[i]:
            print(-1)
            break
        if i == 1:
            print(res)
            break
        visiteds[i] = True
        res += 1
        i = aa[i]


if __name__ == '__main__':
    main()


Measured memory_bytes: 7888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    char x, y;
    cin >> x >> y;
    if(x > y) puts(">");
    else if(x < y) puts("<");
    else puts("=");
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAX 100000
#define NIL -1

int top=0, S[MAX];

int n;
int G[MAX][100];
int color[MAX];

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

void dfs(int r, int c){
  int u, v, i;
  push(r);
  color[r] = c;
  while( top != 0 ){
    u = S[top];
    pop();
    for( i = 0 ; i < len(u) ; i++ ){
      v = G[u][i];
      if( color[v] == NIL ){
        color[v] = c;
        push(v);
      }
    }
  }
}

void assignColor(){
  int id=1, i, u;
  for( i = 0 ; i < n ; i++ ){
    color[i] = NIL;
  }
  for( u = 0 ; u < n ; u++ ){
    if( color[u] == NIL ) dfs(u, id++);
  }
}

int len(int s){
  int i;
  for( i = 0 ; i < MAX ; i++ ){
    if( G[s][i] == '\0' ) return i;
  }
}

int main(){
  int i, s, t, m, q;

  scanf("%d%d",&n,&m);

  for( i = 0 ; i < m ; i++ ){
    scanf("%d%d",&s,&t);
    G[s][len(s)] = t;
    G[t][len(t)] = s;
  }

  assignColor();

  scanf("%d",&q);

  for( i = 0 ; i < q ; i++ ){
    scanf("%d%d",&s,&t);
    if( color[s] == color[t] ){
      printf("yes\n");
    }
    else printf("no\n");
  }

  return 0;
}



Measured memory_bytes: 41148
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int Q=stdIn.nextInt();
		int ans[]=new int[N];
		int kota[]=new int[Q];
		String S=stdIn.next();
		int z=1,y=0,l=0,r=0,num=0;
		while(z<N){
			if(S.substring(z,z+1).equals("C")&&S.substring(z-1,z).equals("A")){
				y++;
			}
			ans[z]=y;
			z++;
		}z=0;y=0;
		while(z<Q){
			l=stdIn.nextInt();
			r=stdIn.nextInt();
			kota[z]=ans[r-1]-ans[l-1];
			z++;
		}z=0;
		while(z<Q){
			System.out.println(kota[z]);
			z++;
		}
	}
}

Measured memory_bytes: 90108
#include<stdio.h>

int main(){
    int h,n;
    scanf("%d %d",&h,&n);
    int a[n+1];
    int i,sum=0;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum += a[i];
    }
    if(h-sum<=0){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        200005
#define mod         1000000007
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,count=0,ans,x,y;
    cin>>n;
    ll a[n+1];
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    x=a[n/2];
    y=a[n/2+1];
    ans=y-x;
    cout<<ans;
}

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

int main()
{
	char a, b;
	cin >> a >> b;
	if (a == 'D')
	{
		if (b == 'H')
		{
			b = 'D';
		}
		else
		{
			b = 'H';
		}
	}
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
#define pb push_back
int main() 
{ 
    ll n,c=0;string s; cin>>n>>s; vector<int> r,b,g;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R') r.pb(i+1);
        if(s[i]=='B') b.pb(i+1);
        if(s[i]=='G') g.pb(i+1);
    }
    ll ans=r.size()*b.size();
    ans*=g.size();//cout<<ans<<"\n";
    for(int d=1;d<=n/2;d++)
    {
        for(int i=0;i<s.size()-2*d;i++)
            if(s[i]!=s[i+d] && s[i]!=s[i+2*d] && s[i+d]!=s[i+2*d]) {ans--;}//c++; cout<<s[i]<<" "<<s[i+d]<<" "<<s[i+2*d]<<" "<<c<<"\n";}
        //cout<<c<<" "<<d<<"\n";c=0;
    }
    cout<<ans;
    return 0; 
} 


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;



int main(){
    int t_s, t_a, a_s, a_a;
    cin >> t_s >> t_a >> a_s >> a_a;

    while(1){
        a_s = a_s - t_a;
        //printf("a_s %d\n", a_s);
        if(a_s <= 0){
            break;
        }
        t_s = t_s - a_a;
        //printf("t_s %d\n", t_s);
        if(t_s <= 0){
            break;
        }
    }

    if(a_s <= 0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
    
}

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

const ll MAX = 1000003;
const ll MOD = 1000003;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long pow_mod(long long x, long long n) {
    long long a = 1, x2n = x;
    x2n %= MOD;
    while (n!=0) {
        if (n&1==1) {
            a *= x2n;
            a %= MOD;
        }
        x2n *= x2n;
        x2n %= MOD;
        n >>= 1;
    }
    return a;
}

ll mod_inv(ll a, ll m) {
    ll b = m, x = 1, y = 0, s, t;
    while ( b != 0 ) {
        s = y;
        y = x - ( a / b ) * y;
        x = s;
        t = b;
        b = a % b;
        a = t;
    }
    return (x % m + m) % m;
}

int main() {
    int Q;
    cin >> Q;
    COMinit();
    for ( int i = 0; i < Q; i++ ) {
        ll x,d,n;
        cin >> x >> d >> n;
        ll ans = 0;
        if ( d == 0 ) {
            ans = pow_mod(x, n);
        } else {
            ll xd = x * mod_inv(d, MOD) % MOD;
            if ( xd == 0 || MOD <= xd + n - 1) {
                ans = 0;
            } else {
                ll r = fac[(xd + n - 1 + MOD) % MOD] * finv[(xd - 1 + MOD) % MOD] % MOD;
                ans = r * pow_mod(d, n) % MOD;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 24320
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
ll u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
ll d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int f(ll a){
  for(int i=2;i<=sqrt(a);i++)if(a%i<1)return 0;
  return 1;
}
int x[1001];
int main(void){
  ll n;
  scanf("%lld",&n);
  int i;
  for(i=1;i*i<=n;i++){}
  i--;
  PRN(i*i);
  return 0;
}


Measured memory_bytes: 128
s=int(input())
a=[s]
i=0
while True:
  if a[i]%2==0:
    a.append(a[i]//2)
  else:
    a.append(a[i]*3+1)
  if a[i+1] in a[:i]:
    print(i+2)
    exit()
  i+=1
  

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

int n, pos = 0;
vector<int> pre, in, post;

void reconstruction(int left, int right) {
    if (left >= right) return;

    int r = pre[pos++];
    int mid = distance(in.begin(), find(in.begin(), in.end(), r));
    reconstruction(left, mid);
    reconstruction(mid+1, right);
    post.push_back(r);
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int num; cin >> num;
        pre.push_back(num);
    }
    for (int i = 0; i < n; i++) {
        int num; cin >> num;
        in.push_back(num);
    }

    reconstruction(0, n);
    for (int i = 0; i < n; i++) {
        cout << (i ? " ":"") << post[i];
    }
    cout << endl;

    return 0;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll a,b,c;
    cin >> a>> b >> c;
    cout << ((a+b>=c)?"Yes":"No") << endl;
    return 0;
}


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

#pragma region Macro
#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 SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

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

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	int X;
	cin >> X;

	if(X >= 30){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define ll long long int

using namespace std;

int main(void)
{
	int n;
	int i;
	int temp1, temp2;
	int hito = 0;
	vector<int> l, r;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> temp1 >> temp2;
		l.push_back(temp1);
		r.push_back(temp2);
	}

	for (i = 0; i < n; i++) {
		hito = hito + r[i] - l[i] + 1;
	}
	cout << hito << endl;
	return (0);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
const int N=200000;
int n,A[N],tot1,tot2,ans,mx1,mx2;
int t1,t2,m1,m2;
map<int,int> M1,M2;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>A[i];
	for(int i=1;i<=n;i+=2) M1[A[i]]++;
	map<int,int>::iterator iter;
	for(iter=M1.begin();iter!=M1.end();iter++)
	{
		int k=iter->second,num=iter->first;
		if(k>tot1) {tot2=tot1,mx2=mx1;mx1=num,tot1=k;}
		else if(k>tot2) {tot2=k,mx2=num;}
	}
//	printf("tot1=%d,mx1=%d,tot2=%d,mx2=%d\n",tot1,mx1,tot2,mx2);
	for(int i=2;i<=n;i+=2) M2[A[i]]++;
	for(iter=M2.begin();iter!=M2.end();iter++)
	{
		int k=iter->second,num=iter->first;
		if(k>t1) {t2=t1,m2=m1;m1=num,t1=k;}
		else if(k>t2) {t2=k,m2=num;}
	}
//	printf("t1=%d,m1=%d,t2=%d,m2=%d\n",t1,m1,t2,m2);
	if(m1!=mx1) {ans=n-t1-tot1;}
	else ans=n-max(t1+tot2,t2+tot1);
	printf("%d\n",ans);
	return 0;
}


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

int main(){
	string w;
	cin>>w;
	int count[26]={0};
	l(i,w.length()){
		count[w[i]-'a']++;
	}
	
	int count1=0;
	l(i,26){
		if(count[i]%2!=0)count1++;
		if(count1!=0){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";

}



Measured memory_bytes: 384
H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch, Cw, Dh, Dw = Ch - 1, Cw - 1, Dh - 1, Dw - 1
maze = [list(input()) for i in range(H)]
#print(maze)
  
ans = [[-1] * W for i in range(H)]  
ans[Ch][Cw] = 0
from collections import deque
q = deque([[0, Ch, Cw]])  
one = [[0, 1], [0, -1], [1, 0], [-1, 0]]
two = [[2, 2], [2, 1], [2, 0], [2, -1], [2, -2], [1, 2], [1, 1], [1, -1], [1, -2], [0, 2], [0, -2], [-1, 2], [-1, 1], [-1, -1], [-1, -2], [-2, 2], [-2, 1], [-2, 0], [-2, -1], [-2, -2]] 
while q:
  cnt, h, w = q.popleft()
  if ans[h][w] < cnt:
    continue
  for i, j in one:
    if (0 <= h + i < H) and (0 <= w + j < W) and (maze[h + i][w + j] != "#"):
        if ans[h + i][w + j] == -1 or ans[h + i][w + j] > cnt:
          ans[h + i][w + j] = cnt
          q.appendleft([cnt, h + i, w + j])
  for i, j in two:  
    if (0 <= h + i < H) and (0 <= w + j < W) and (maze[h + i][w + j] != "#"):
        if ans[h + i][w + j] == -1 or ans[h + i][w + j] > cnt + 1:
          ans[h + i][w + j] = cnt + 1
          q.append([cnt + 1, h + i, w + j])
              
print(ans[Dh][Dw])              
          
              
          
          
    
    
    

  


Measured memory_bytes: 155436
#! /usr/bin/env python3

# from math import gcd
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement


K = int(input())
S = input()

if len(S) > K:
    print(S[:K] + "...")
else:
    print(S)


Measured memory_bytes: 10460
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define Vi vector<int>
#define Vl vector<long long>
#define pb(a) push_back(a)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
ll a[100001];
ll m[100001]={},u[100001]={};
ll gcd(ll a2,ll b2){
	ll t;
	while(b2!=0){
		t=a2%b2;
		a2=b2;
		b2=t;
	}
	return a2;
}

int main() {

	int n;
	cin>>n;
	cin>>a[0];
	m[0]=a[0];
	rep(i,n-1){
		cin>>a[i+1];
		m[i+1]=gcd(a[i+1],m[i]);
	}
	ll ans=m[n-2];
	u[n-1]=a[n-1];
	for(int i=n-2; i>0; i--){
		u[i]=gcd(u[i+1],a[i]);
		ans=max(ans,gcd(u[i+1],m[i-1]));
	}
	cout<<max(ans,u[1])<<endl;

	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>

using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> A(H, vector<char>(W, 0));
	map<int, bool> outputH;
	map<int, bool> outputW;
	for (int i = 0; i < H; ++i) {
		bool check = false;
		for (int j = 0; j < W; ++j) {
			char c;
			cin >> c;
			A[i][j] = c;
			if (A[i][j] == '#')check = true;
		}
		if(!check) outputW[i] = 1;
	}
	for (int i = 0; i < W; ++i) {
		bool check = false;
		for (int j = 0; j < H; ++j) {
			if (A[j][i] == '#')check = true;
		}
		if(!check) outputH[i] = 1;
	}


	for (int i = 0; i < H; ++i) {
		if (outputW[i] == 1)continue;
		for (int j = 0; j < W; ++j) {
			if (outputH[j] == 1) {
				continue;
			}
			cout << A[i][j];
			
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
#endif
	int n;
	scanf("%d",&n);
	long long ans=0;
	int X=1,Y=n;
	while(X<=n&&Y>0){
		//printf("%d %d ",X,Y);
		if(1ll*X*Y<n){
			ans+=Y*1ll;
			X++;
		}
		else{
			Y--;
		}
		//printf("%d\n",ans);
	}	
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 3820
#include<bits/stdc++.h>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, m, k;
	cin>>n>>m>>k;
    int x1, y1, x2, y2;
	cin>>x1>>y1>>x2>>y2;
	x1--;
	y1--;
	x2--;
	y2--;
	char grid[n][m];
	int dist[n][m];
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			cin>>grid[i][j];
			dist[i][j] = INT_MAX;
		}
	}
 
    int d[4][2] = {{-1,0}, {0,-1}, {1,0}, {0,1}};
	queue<pair<int, int> > q;
	dist[x1][y1] = 0;
	q.push({x1, y1});
	while (!q.empty()) {
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
 
		for (int i=0; i<4; i++) {
			int nx = x;
			int ny = y;
			int nd = dist[x][y]+1;
			for (int j=1; j<=k; j++) {
				nx += d[i][0];
				ny += d[i][1];
 
				if (nx<0 || nx>=n || ny<0 || ny>=m || grid[nx][ny]=='@' || dist[nx][ny]<nd) {
					break;
				}
				if (dist[nx][ny]>nd) {
					dist[nx][ny] = nd;
					q.push({nx, ny});
				}
			}
		}
	}
 
	int ans = dist[x2][y2];
	cout<<(INT_MAX==ans ? -1 : ans)<<endl;
	return 0;
}
 

Measured memory_bytes: 9116
from collections import Counter
def main():
    N,*A=map(int, open(0).read().split())
    ans=True
    C=Counter(A)
    m=min(A)
    M=max(A)
    if C[m]>2:
        ans=False
    if N>2 and m==1:
        if C[1]!=1:
            ans=False
    if C[m]==1:
        if m*2!=M:
            ans=False
    else:
        if m*2-1!=M:
            ans=False
    for i in range(m+1,M+1):
        if i not in C or C[i]<2:
            ans=False
    print("Possible" if ans else "Impossible")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
using System;

namespace ABC052B
{
    static class Program
    {
        static void Main()
        {
            int length = int.Parse(Console.ReadLine());
            string text = Console.ReadLine();
            int nbr = 0;
            int maxNbr = 0;

            for (int i = 0; i < length; i++)
                if (text[i] == 'I')
                {
                    nbr++;
                    maxNbr = Math.Max(maxNbr, nbr);
                }
                else
                    nbr--;

            Console.WriteLine(maxNbr);
        }
    }
}

Measured memory_bytes: 13140
N = int(input())
A = [int(x) for x in input().split()]
A.insert(0,0)
A.append(0)
cost = 0
for i in range(1,N+2):
    cost += abs(A[i]-A[i-1])

def change(i):
    global A
    return -abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1])

for i in range(1,N+1):
    print(cost+change(i))

Measured memory_bytes: 20516
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000003;
using ll = long long;
using namespace std;

ll modPow(ll a, int n){
	ll res = 1;
	int i = 1;
	while( i <= n ) {
		if( n & i ){
			res *= a;
			res %= mod;
		}
		i <<= 1;
		a = a*a%mod;
	}
	return res;
}

ll mf[2000200];
ll dvf[2000200];

int main(){
	int q;
	scanf("%d\n", &q);
	mf[0] = 1; dvf[0] = 1;
	for( int k = 1; k <= 2000100; ++k ){
		mf[k] = (k*mf[k-1]) % mod;
		dvf[k] = (modPow(k, mod-2)*dvf[k-1]) % mod;
	}
	while( q-- ){
		ll x, d, n;
		scanf("%ld %ld %ld", &x, &d, &n);
		if( d == 0 ){
			printf("%d\n", modPow(x, n));
			continue;
		}
		if( n >= mod ){
			if( n >= mod ) printf("%d\n", 0);
			continue;
		}
		if( d != 1 ){
			x = (x*modPow(d, mod-2))%mod;
		}
		printf("%d\n", modPow(d, n) * ( mf[x+n-1]*dvf[x-1] % mod ) % mod );
	}
	return 0;
}

Measured memory_bytes: 32128
//from PKU1125
#define M 101
double dist[M][M],d;
next[M][M],x[M],y[M];
main(){
	int a,b,k,n,i,j;
	for(;scanf("%d",&n),n;){
		/*initialize*/
		for(i=1;i<=n;i++)scanf("%d",&a),scanf("%d%d",x+a,y+a);
		for(i=1;i<=n;i++)for(j=1;j<=n;next[i][j]=j,j++)
			dist[i][j]=(d=hypot(x[i]-x[j],y[i]-y[j]))<50.1?d:499;

		{/*warshall-floyd*/
			int k,i,j;
			for(k=1;k<=n;k++)
				for(i=1;i<=n;i++)
					for(j=1;j<=n;j++){
						if(dist[i][j]>dist[i][k]+dist[k][j])
							dist[i][j]=dist[i][k]+dist[k][j],next[i][j]=next[i][k];
					}
		}

		{/*query*/
			for(scanf("%d",&k);k;k--){
				scanf("%d%d",&a,&b);
				if(dist[a][b]>=499)puts("NA");
				else{
					for(j=a;j!=b;j=next[j][b])printf("%d ",j);
					printf("%d\n",b);
				}
			}
		}
	}exit(0);
}

Measured memory_bytes: 740
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
 
using namespace std;
 
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a * b > c * d)
    {
        cout << a*b << endl;
    }
    else if (a * b < c * d)
    {
        cout << c*d << endl;
    }
    else
    {
        cout << a*b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int main() {
	fastio;
	ll H, W;
	cin >> H >> W;

	if (H == 1 || W == 1) cout << 1;
	else cout << (H * W + 1) / 2;

	return 0;
}

Measured memory_bytes: 256
def roll(inst):
    global u, s, e, w, n, d
    if inst == 'N':
        u, s, n, d = s, d, u, n
    elif inst == 'E':
        u, e, w, d = w, u, d, e
    elif inst == 'S':
        u, s, n, d = n, u, d, s
    elif inst == 'W':
        u, e, w, d = e, d, u, w

u, s, e, w, n, d = map(int, input().split())
q = int(input())
for i in range(q):
    u1, s1 = map(int, input().split())
    if u1 == u:
        pass
    elif u1 == s:
        roll('N')
    elif u1 == e:
        roll('W')
    elif u1 == w:
        roll('E')
    elif u1 == n:
        roll('S')
    elif u1 == d:
        roll('N')
        roll('N')
    if s1 == s:
        print(e)
    elif s1 == e:
        print(n)
    elif s1 == n:
        print(w)
    elif s1 == w:
        print(s)

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

int main() {
  int n, t;
  cin >> n >> t;
  vector<ll> a(n + 1);
  for (ll &i : a) {
    cin >> i;
  }
  ll ans = 0;
  a[n] = LLONG_MAX;
  for (int i = 0; i < n; i++) {
    ans += min(a[i] + t, a[i+1]) - a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4824
#include <stdio.h>

int main(void)
{
    int X, A, B;
    scanf("%d%d%d", &X, &A, &B);
    if (B-A <= 0) {
        printf("delicious\n");
    } else if (B-A <= X) {
        printf("safe\n");
    } else {
        printf("dangerous\n");
    }
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  for (int i = K; i < N; ++i) {
    if (A[i] > A[i - K]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


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

using namespace std;

int main(){
  char a;
  cin>>a;
  if(a=='A')cout<<"T\n";
  if(a=='T')cout<<"A\n";
  if(a=='C')cout<<"G\n";
  if(a=='G')cout<<"C\n";
  return 0;
}

Measured memory_bytes: 256
def bs(L, key):
    inc, exc = -1, len(L)
    while abs(exc-inc) > 1:
        mid = (exc+inc)//2
        if L[mid] <= key:
            inc = mid
        else:
            exc = mid
    return inc


def main():
    N, M, K = map(int, input().split())
    A, B = [0], [0]
    for a in map(int, input().split()):
        A.append(A[-1]+a)
    for b in map(int, input().split()):
        B.append(B[-1]+b)
    ans = 0
    for i in range(N+1):
        j = bs(B, K-A[i])
        if j > -1:
            ans = max(ans, i+j)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 45792
#![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)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

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

// Functions

// Main
fn main(){
    input!{
        N: usize,
        _T: i64,
        A: [i64; N],
    }
    let (mut profit, mut cnt) = (0, 0);
    let mut minA = A[0];
    for i in 1..N{
        let p = A[i]-minA;
        if p==profit{
            cnt += 1;
        }else if p>profit{
            profit = p;
            cnt = 1;
        }
        minA = min(minA,A[i]);
    }
    println!("{}", cnt);
}

Measured memory_bytes: 4352
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let n: u64 = input();
    let a_vec = input_vec();
    let mut sum = 0;
    for i in 0..n {
        if i % 2 == 0 && a_vec[i as usize] % 2 == 1 {
            sum += 1;
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 2084
import java.util.Scanner;

public class Main{
	public static int n;
	public static int k;
	public static int []w;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		k = scan.nextInt();
		w = new int[n];
		for(int i = 0; i < n; i++) {
			w[i] = scan.nextInt();
		}
		scan.close();
		long ans = solve();
		System.out.println(ans);
	}
	public static int check(long p) {
		int i = 0;
		for(int j = 0; j < k; j++) {
			long s = 0;
			while(s + w[i] <= p) {
				s += w[i];
				i++;
				if(i == n) return n;
			}
		}
		return i;
	}
	public static long solve() {
		long left = 0;
		// 荷物の個数×1個当たりの最大重量
		long right = 100000 * 10000;
		long mid;
		while(right - left > 1) {
			mid = (left + right) / 2;
			int v = check(mid);
			if(v >= n) right = mid;
			else left = mid;
		}
		return right;
	}
}


Measured memory_bytes: 70688
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(usize);
    let ps = scan!(f64;;);

    let mut dp = vec![vec![0.0f64; n + 1]; n + 1];
    dp[0][0] = 1.0;
    for i in 0..ps.len() {
        for j in 0..i + 2 {
            dp[i + 1][j] =
                if j >= 1 { dp[i][j - 1] * ps[i] } else { 0.0 } + dp[i][j] * (1.0 - ps[i])
        }
    }
    println!("{}", dp[n].iter().rev().take((n + 1) / 2).sum::<f64>())
}


Measured memory_bytes: 90364
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;




int main(int argc, char *args[]) {
	char s;
	int counter = 0;
	for (int i = 0; i < 4; i++) {
		cin >> s;
		if (s == '+')counter += 1;
		else counter -= 1;
	}
	cout << counter << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[100]={};
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=100;i>=0;i--){
		int b=0;
		for(int j=0;j<n;j++){
			if(a[j]>=i){
				b+=1;
			}
		}
		if(b>=i){
			cout<<i<<endl;
			break;
		}
	}
}	



Measured memory_bytes: 3092
import sys
import bisect
input = sys.stdin.readline
##http://drken1215.hatenablog.com/entry/2019/01/14/033200
def solve():
  n,m = (int(i) for i in input().split())
  a = sorted(list(int(i) for i in input().split()))
  b = sorted(list(int(i) for i in input().split()))
  mod = 10**9+7
  for i in range(n-1):
    if a[i] == a[i+1] or a[i] > n*m:
      print(0)
      exit()
  for i in range(m-1):
    if b[i] == b[i+1] or b[i] > n*m:
      print(0)
      exit()
            
  
  
  ans = 1
  for i in range(n*m,0,-1):
    placea = bisect.bisect_left(a,i)
    placeb = bisect.bisect_left(b,i)
    if placea >= n or placeb >= m:
      ans *= 0
    else:
      if i == a[placea] and i == b[placeb]:
        ans *= 1
      elif i == a[placea] and i != b[placeb]:
        ans *= (m-placeb)
      elif i != a[placea] and i == b[placeb]:
        ans *= (n-placea)
      else:
        ans *= (m-placeb)*(n-placea)-(n*m-i)
    ans%= mod
  print(ans)
    
solve()

Measured memory_bytes: 3188
input = STDIN.read.split("\n").map{|l| l.split(" ").map{|i| i.to_i}}

limit = input[0][1]
input.shift

min_cost = nil
for r in input do
  cost = r[0]
  time = r[1]
  if time <= limit && (min_cost == nil || cost < min_cost) then
    min_cost = cost
  end
end

puts (min_cost == nil) ? 'TLE' : min_cost

Measured memory_bytes: 1788
n = gets.to_i
pontas = gets.chomp.chars

count_e = pontas.count('E')

costs = (0...n).each_with_object([]) { |i, result|
  prev_right_e, prev_left_w = result.last || [count_e, 0]

  result <<
    [
      pontas[i] == 'E' ? prev_right_e - 1 : prev_right_e,
      i.zero? ? 0 : (pontas[i - 1] == 'W' ? prev_left_w + 1 : prev_left_w)
    ]
}

puts costs.map { |left_cost, right_cost| left_cost + right_cost }.min

Measured memory_bytes: 47748