akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define swap(a,b) ((*a!=*b)&&(*a+=*b,*b=*a-*b,*a-=*b))
typedef long long LL;
const int IMIN=(1<<31);
const LL LINF=0x7fffffffffffffff;
#define rep(i,N) for(int i=0;i<(LL)N;i++)
#define array(N,t) (t*)calloc(N,sizeof(t))
int compare(const int*a,const int*b){if(*a<*b)return -1;else if(*a==*b)return 0;else return 1;}
inline LL IN(void)
{
  LL x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void Sort(unsigned *from,unsigned *to,unsigned bit)
{
  if(!bit||to<from+1)return;
  unsigned *left=from,*right=to-1;
  for(;;)
  {
    while(left<right&&!(*left&bit))left++;
    while(left<right&&(*right&bit))right--;
    if(left>=right)break;
    swap(left,right);
  }
  if(!(bit&*left)&&left<to)left++;
  bit>>=1;
  Sort(from,left,bit);
  Sort(left,to,bit);
}
static inline void Radix(int *array,const int len)
{
  unsigned *x=(unsigned*)array;
  rep(i,len)x[i]^=IMIN;
  Sort(x,x+len,IMIN);
  rep(i,len)x[i]^=IMIN;
}
int main(void)
{
  int N=IN(),i=0,m=0,p=0,z=0,temp,*A=array(N,int);
  LL K=IN(),low=-LINF/2,mid,high=LINF/2,count;
  rep(j,N){A[j]=IN();if(A[j]<0)m++;else if(A[j]>0)p++;else z++;}
  /*Radix(A,N);*/qsort(A,N,sizeof(int),(int(*)(const void*,const void*))compare);
  if(K>1ll*m*p&&K<1ll*m*p+1ll*z*(N-1)/2)return puts("0"),0;else temp=0;
  if(K<=1ll*m*p)high=1ll;else low=-1ll;
  while(high-low>1)
  {
    mid=(low+high)/2,count=0;
    if(!mid)count=1ll*m*p;
    else if(mid>0)
    {
      count=1ll*m*p+1ll*z*(m+p)+1ll*z*(z-1)/2;temp=N-1;i=m+z;
      while(i<N)
      {
        while(1ll*A[temp]*A[i]>=mid){temp--;}
        if(temp>i)count+=1ll*temp-i,i++;else break;
      }
      temp=0;i=m-1;
      while(i>=0)
      {
        while(1ll*A[temp]*A[i]>=mid){temp++;}
        if(temp<i)count+=1ll*i-temp,i--;else break;
      }
    }
    else
    {
      temp=m-1;i=N-1;
      while(i>=m+z)
      {
        while(temp>=0&&1ll*A[temp]*A[i]>=mid){temp--;}
        if(temp>=0){count+=1ll*temp+1;}i--;
      }
    }
    if(count<K)low=mid;else high=mid;
  }
  free(A);return printf("%lld\n",low),0;
}

Measured memory_bytes: 2980
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, v[50];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v, v + n);
    double val = v[0];
    for(int i = 1; i < n; i++){
        val = (val + v[i]) / 2;
    }
    cout << val << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int main() {
	int n; cin >> n;
	vector<int> t(n),x(n),y(n);
	for (int i = 0; i < n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}
	int time = 0,tsum = 0;
	for (int i = 0; i < n; i++) {
		if ((t[i] - time) % 2 == 0) {
			if (abs(x[i] + y[i] - tsum) % 2 != 0 || abs(x[i] + y[i] - tsum) > (t[i] - time)) {
				cout << "No";
				//cout << i;
				return 0;
			}
		}
		if ((t[i] - time) % 2 == 1) {
			if (abs(x[i] + y[i] - tsum) % 2 != 1 || abs(x[i] + y[i] - tsum) > (t[i] - time)) {
				cout << "No";
				//cout << i;
				return 0;
			}
		}
		time = t[i];
		tsum = x[i] + y[i];
	}
	cout << "Yes";
	
	cout << endl;
	return 0;
}

Measured memory_bytes: 1408
n,k=map(int,input().split())
li=list(map(int, input().split()))
tmp=0
for i in range(k):
  tmp+=li[i]

max=tmp
for i in range(1,n-k+1):
  tmp=tmp-li[i-1]+li[i+k-1]
  if max<=tmp:
    max=tmp
print((max+k)/2)

Measured memory_bytes: 25060
n=int(input())
if n%2:
  a=list(map(int,input().split()))
  s=[[a[0],0,0],[0,a[1],0],[a[0]+a[2],0,a[2]]]+[[0,0,0]for i in range(3,n)]
  for i in range(3,n):
    if i%2:
      s[i][1]=max(s[i-2][1],s[i-3][0])+a[i]
    else:
      s[i][0]=s[i-2][0]+a[i]
      s[i][2]=max([s[i-2][2],s[i-3][1],s[i-4][0]])+a[i]
  print(max([s[-1][2],s[-2][1],s[-3][0]]))
else:
  a=list(map(int,input().split()))
  s=[a[0],a[1]]+[0 for i in range(2,n)]
  for i in range(2,n):
    if i%2:
      s[i]=max([s[i-2],s[i-3]])+a[i]
    else:
      s[i]=s[i-2]+a[i]
  print(max(s[-2:]))

Measured memory_bytes: 53836
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
ll a[maxn],b[maxn];
int n;
vector<ll> t;
vector<ll> s;
int fail[maxn],len[maxn];
void prepare()
{
	memset(fail,-1,sizeof(fail));
	int j=-1;
	for(int i=1;i<t.size();i++)
	{
		while(j!=-1&&t[i]!=t[j+1])j=fail[j];
		if(t[i]==t[j+1])j++;
		fail[i]=j;
	//	cout<<"fail "<<i<<" "<<j<<endl;
	}
}
void kmp()
{
	int j=-1;
	for(int i=0;i<s.size();i++)
	{
		while(j!=-1&&s[i]!=t[j+1])j=fail[j];
		if(s[i]==t[j+1])j++;
	//	cout<<"kmp "<<i<<" "<<j<<endl;
		len[i]=j+1;
		if(j+1==t.size())j=fail[j];
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	for(int i=0;i<n;i++)scanf("%lld",&b[i]);
	if(n==1)
	{
		printf("%d %lld\n",0,a[0]^b[0]);
		return 0;
	}
	t.clear();
	for(int i=1;i<n;i++)t.push_back(b[i]^b[i-1]);
	prepare();
	s.clear();
	for(int i=1;i<n*2-1;i++)s.push_back(a[i%n]^a[(i-1)%n]);
	
//	for(int i=0;i<t.size();i++)cout<<t[i]<<" ";cout<<endl;
//	for(int i=0;i<s.size();i++)cout<<s[i]<<" ";cout<<endl;
	
	kmp();
	for(int i=1;i<n*2-1;i++)if(len[i]==n-1)
	{
		printf("%d %lld\n",i-n+2,a[i-n+2]^b[0]);
	}
	return 0;
}

Measured memory_bytes: 13292
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30
const double EPS = 1e-8;

double dtor(double deg) {       // x¨WA
  return deg*M_PI/180;
}

int main() {
  int m;
  while(cin >> m, m) {
    int v1[m];
    int hoge = 0;
    REP(i,m-1) {
      cin >> v1[i];
      hoge += v1[i];
    }
    v1[m-1] = 360-hoge;
    int n;
    cin >> n;
    int v2[n];
    hoge = 0;
    REP(i,n-1) {
      cin >> v2[i];
      hoge += v2[i];
    }
    v2[n-1] = 360-hoge;

    double s1 = 0;
    double s2 = 0;
    REP(i,m) 
      s1 += sin(dtor(v1[i]));
    REP(i,n)
      s2 += sin(dtor(v2[i]));
    //cout << s1 << " " <<s2 << endl;
    if (abs(s1-s2)<1e-10)
      cout << 0;
    else if (s1>s2)
      cout << 1;
    else
      cout << 2;
    cout << endl;
  }
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
 
class DandA {
    static void Main(string[] args) {
        int a = ReadLineInt();
        if (a >= 3200) {
            Console.WriteLine(ReadLineStr());
        } else {
            Console.WriteLine("red");
        }
    }
 
    static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static string[] strAry = new string[] {"L", "R", "U", "D"}; 
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private long ReadLineLong() {return long.Parse(Console.ReadLine());}
    static private double ReadLineDouble() {return double.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private double[] ReadLineDoubleArray() {return Console.ReadLine().Trim().Split().Select(a => double.Parse(a)).ToArray();}
    static private decimal[] ReadLineDecimalArray() {return Console.ReadLine().Trim().Split().Select(a => decimal.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
 
    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    
    //d = 365
    int d; cin >> d;
    
    //しばらく特定のタイプのコンテストが開催されないと、満足度が下がってしまいます
    int c[26]; rep(i,0,26) cin >> c[i]; 
    
    //d日目にiタイプのコンテスト開催　＝＞　満足度 += s[d][i]
    int s[d][26];
    rep(i,0,d) rep(j,0,26) cin >> s[i][j];

    int ans[500]; rep(i,0,d) ans[i] = rand()%26+1;
    ll satisfaction = 0;


    rep(i,0,d){
        cout << ans[i] << "\n";
    }
}


Measured memory_bytes: 3672
t = int(input())
wlist = [0]*4
for i in range(t):
    w = input()
    if w == "AC":
        wlist[0] += 1
    elif w == "WA":
        wlist[1] += 1
    elif w == "TLE":
        wlist[2] += 1
    else:
        wlist[3] += 1
print("AC x " + str(wlist[0]))
print("WA x " + str(wlist[1]))
print("TLE x " + str(wlist[2]))
print("RE x " + str(wlist[3]))

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

typedef pair<int,int> P;

int n,m,l,r,a,b;
vector<P> v;

int main(){
	scanf("%d%d",&n,&m);
	for(int i = 0 ; i < n ; i ++){
		scanf("%d%d",&l,&r);
		v.push_back(P(l,r));
	}
	sort(v.begin(),v.end());
	
	vector<int> L;
	bitset<200010> R; R.set();
	for(P p: v){
		int x = R._Find_next(p.second-1);
		if(x <= m){
			a ++;
			R[x] = false;
		}
		else {
			L.push_back(p.first);
		}
	}
	sort(L.begin(),L.end());
	
	for(int x: L){
		if(b<x){
			b++;
		}
	}
	printf("%d\n",n-min(a+b,m));
}
	

Measured memory_bytes: 3696
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll R, C, K;
  cin >> R >> C >> K;
  vector<vector<int>> m(R+1,vector<int>(C+1));
  int r, c, v;
  for (int i = 0; i != K; ++i) {
    cin >> r >> c >> v;
    m[r][c] = v;
  }
  ll dp[2][3001][4];
  fill((ll*)dp,(ll*)dp+2*3001*4,0ll);
    
  for (int i = 1; i <= R; ++i) {
    for (int j = 1; j <= C; ++j) {
      auto umax = max({dp[i%2][j-1][0],
                       dp[1-i%2][j][0], dp[1-i%2][j][1],
                       dp[1-i%2][j][2], dp[1-i%2][j][3]});
      dp[i%2][j][0] = umax;
      if (int V = m[i][j]; V) {
        dp[i%2][j][1] = max(dp[i%2][j-1][1], V + umax);
        dp[i%2][j][2] = max(dp[i%2][j-1][2], dp[i%2][j-1][1] + V);
        dp[i%2][j][3] = max(dp[i%2][j-1][3], dp[i%2][j-1][2] + V);
      } else {
        dp[i%2][j][1] = dp[i%2][j-1][1];
        dp[i%2][j][2] = dp[i%2][j-1][2];
        dp[i%2][j][3] = dp[i%2][j-1][3];
      }
    }
  }
  cout << *max_element(dp[R%2][C], dp[R%2][C]+4) << endl;
}


Measured memory_bytes: 38540
mod=10**9+7

S=int(input())
ans=0
L=[-1]*(S+1)

def f(n):
    if n==0:
        return 1
    elif n<0:
        return 0
    elif L[n]!=-1:
        return L[n]
    else:
        tmp=0
        for i in range(3,n+1):
            tmp+=f(n-i)
        L[n]=tmp
        return tmp
print(f(S)%mod)

Measured memory_bytes: 9336
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

ll n,a[5],ans=0;
int main(void){
	cin>>n;
	rep(i,5)cin>>a[i];
	rep(i,5){
		ll t=n/a[i];//全て移送する
		if(n%a[i]!=0)t++;
		ans=max(ans+1,t+i);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    bool stu[31] = {0};

    for (int i = 0; i < 28; i++) {
        int a;
        cin >> a;
        stu[a] = 1;
    }

    for (int i = 1; i <= 30; i++) {
        if (!stu[i]) cout << i << endl;
    }
}



Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>
#include<map>

using namespace std;

#define long long long
#define ft(i , a , b) for (long i = (long)a ; i <= (long)b ; i++)
#define fd(i , a , b) for (long i = (long)a ; i >= (long)b ; i--)
#define lt(i , a , b , c) for (long i = (long)a ; i <= (long)b ; i += (long)c)
#define ld(i , a , b , c) for (long i = (long)a ; i >= (long)b ; i -= (long)c)

#define X first
#define Y second

#define pb push_back
#define mp make_pair

const int mxN = 1e5 + 5;
const long oo = 1e15;
const long MOD = 1e9 + 7;
const int base = 311;

long TestCase;

void Solve() {
    string s;
    cin >> s;
    if ((int)s[0] >= 97) cout << "a";
    else cout << "A";
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    //cin >> TestCase;
    TestCase = 1;
    while(TestCase--)
        Solve();
    return 0;
}

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

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

  int board = 599;
  int ans = 0;
  for (int i = 0; i < 8; i++) {
    if ( X <= board + i*200) {
      ans = 8-i;
      break;
    } 
  }

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

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

#define ALL(V) (V).begin(),(V).end()

using namespace std;

typedef pair<int,int> ii_t;


int main() {
    int x, y, a, b, c;
    int k=0;
    long long answer = 0LL;
    cin >> x >> y >> a >> b >> c;
    vector<long long> p(a),q(b),r(c);
    for (int i=0;i<a;i++) cin >> p[i];
    for (int i=0;i<b;i++) cin >> q[i];
    for (int i=0;i<c;i++) cin >> r[i];

    sort(ALL(p),greater<long long>());
    sort(ALL(q),greater<long long>());
    sort(ALL(r),greater<long long>());

        // fprintf(stderr,"p4: x=%d,y=%d,k=%d,answer=%lld\n",x,y,k,answer);
    for (int i=0;i<x;i++) {
        answer += p[i];
    }
    for (int i=0;i<y;i++) {
        answer += q[i];
    }
    x--; y--;
        // fprintf(stderr,"p0: x=%d,y=%d,k=%d,answer=%lld\n",x,y,k,answer);
    while (x >= 0 && y >= 0 && k<c) {
        if (p[x] <= q[y] && p[x] < r[k]) {
            answer -= p[x];
            answer += r[k];
            x--;
            k++;
        } else if (p[x] >= q[y] && q[y] < r[k]) {
            answer -= q[y];
            answer += r[k];
            y--;
            k++;
        } else break;
        // fprintf(stderr,"p1: x=%d,y=%d,k=%d,answer=%lld\n",x,y,k,answer);
    }
    if (x < 0) {
        while (y >= 0 && k<c) {
            if (q[y] < r[k]) {
                answer -= q[y];
                answer += r[k];
                y--;
                k++;
            } else break;
          //  fprintf(stderr,"p2: x=%d,y=%d,k=%d,answer=%lld\n",x,y,k,answer);
        }
    }
    if (y < 0) {
        while (x >= 0 && k<c) {
            if (p[x] < r[k]) {
                answer -= p[x];
                answer += r[k];
                x--;
                k++;
            } else break;
           // fprintf(stderr,"p3: x=%d,y=%d,k=%d,answer=%lld\n",x,y,k,answer);
        }
    }

    cout << answer << endl;

    return 0;
}


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

using Field = vector<string>;

int main() {
  int H, W; cin >> H >> W;
  Field field(H);
  for (int i = 0; i < H; i++) cin >> field[i];
  
  vector<int> dx = {1, 0, -1, 0};
  vector<int> dy = {0, 1, 0, -1};
  
  queue<pair<int, int>> que;
  vector<vector<int>> dist(H, vector<int>(W, -1));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == '#') {
        dist[i][j] = 0;
        que.push(make_pair(i, j));
      }
    }
  }
  
  while (!que.empty()) {
    int i = que.front().first;
    int j = que.front().second;
    
    // cout << i << ' ' << j << endl;
    
    que.pop();
    
    for (int dir = 0; dir < 4; dir++) {
      int nx = j + dx[dir];
      int ny = i + dy[dir];
        
      if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
      if (dist[ny][nx] != -1) continue;
      
      dist[ny][nx] = dist[i][j] + 1;
      que.push(make_pair(ny, nx));
    }
  }
  
  int ans = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(ans, dist[i][j]);
    }
  }
  
  cout << ans << endl;  
}

Measured memory_bytes: 17120
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		boolean b = true;
		int ans = 2 * n;
		for (int i = 0; i < n; i++) {
			b = true;
			for (int j = 0; j + i < n; j++) {
				if (s[i + j] != t[j]) {
					b = false;
				}
			}
			if (b) {
				ans = n + i;
				break;
			}
		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 23764
#include <stdio.h>

int main(void){
  int a,b,x = 0;
  scanf("%d %d %d",&a,&b,&x);

  if(a>x){
    printf("NO\n");
  }else if(a+b<x){
    printf("NO\n");
  }else{
    printf("YES\n");
  }
  return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 09:48:04 2019

@author: maezawa
"""

n = int(input())
a = [[] for _ in range(n)]
for i in range(n):
    a[i] = list(map(int, input().split()))

dp = [[0]*3 for _ in range(n)]
dp[0][0] = a[0][0]
dp[0][1] = a[0][1]
dp[0][2] = a[0][2]

for i in range(1,n):
    dp[i][0] = max(dp[i-1][1]+a[i][0], dp[i-1][2]+a[i][0])
    dp[i][1] = max(dp[i-1][2]+a[i][1], dp[i-1][0]+a[i][1])
    dp[i][2] = max(dp[i-1][0]+a[i][2], dp[i-1][1]+a[i][2])
    
print(max([dp[n-1][j] for j in range(3)]))

Measured memory_bytes: 73120
#include <iostream>
#include<bits/stdc++.h>
#define inf 1e9
using namespace std;
struct activity{
    int A,B,C;
};
int cp(vector<activity>ar,int n){
    int dp[n+1][3];
    dp[1][0]=ar[1].A;
    dp[1][1]=ar[1].B;
    dp[1][2]=ar[1].C;
    for(int i=2;i<=n;i++){
        dp[i][0]=ar[i].A+max(dp[i-1][1],dp[i-1][2]);
         dp[i][1]=ar[i].B+max(dp[i-1][0],dp[i-1][2]);
          dp[i][2]=ar[i].C+max(dp[i-1][1],dp[i-1][0]);
    }
    return max(dp[n][0],max(dp[n][1],dp[n][2]));

    }
    

int main() {
    int n,k;
    cin>>n;
    vector<activity>ar(n+1);
    for(int i=1;i<=n;i++){
    cin>>ar[i].A;
    cin>>ar[i].B;
    cin>>ar[i].C;
}

    cout<<cp(ar,n);
}


Measured memory_bytes: 6676
import java.util.Scanner;

class Main {

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

        int K=stdIn.nextInt(); //1周の距離
        int N=stdIn.nextInt(); //家の軒数
        
        int min=0;
        int []a=new int[N];

        for(int i=0; i<N; i++){
            a[i]=stdIn.nextInt();
        }

        for(int i=0; i<N-1; i++){
            if(a[i+1]-a[i]>min){
                min=a[i+1]-a[i];
            }
        }
        if(K-a[N-1]+a[0]>min){
            min=K-a[N-1]+a[0];
        }
        System.out.println(K-min);
        

        
    }

}

Measured memory_bytes: 66884
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 = sc.nextInt();
		int K = sc.nextInt();
		int[] l = new int[N];
		for(int i = 0;i < N;++i)
			l[i] = sc.nextInt();
		sc.close();
		
		int ans = 0;
		Arrays.sort(l);
		for(int i = 0;i < K;++i)
			ans += l[N-i-1];
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

  int ans = 0;
  for(int i=0;i<N;i++){
    int tmp = 0;
    for(int j=0;j<26;j++){
      char ch = 'a' + j;
      bool ex1 = false ,ex2 = false;
      for(int k=0;k<i;k++){
        if(s[k]==ch) ex1 = true;
      }
      for(int k=i;k<N;k++){
        if(s[k]==ch) ex2 = true;
      }
      if(ex1 && ex2) tmp++;
    }

    ans = max(ans,tmp);
  }

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

Measured memory_bytes: 256
use std::*;
use std::collections::*;
use std::io::*;
// template {{{
macro_rules! get {
    ($($t:tt),*; $n:expr) => {
        {
            let stdin = std::io::stdin();
            let ret = std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
                let line = line.unwrap();
                let mut it = line.split_whitespace();
                _get!(it; $($t),*)
            }).collect::<Vec<_>>();
            ret
        }
    };
    ($($t:tt),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut it = line.split_whitespace();
            _get!(it; $($t),*)
        }
    };
}
macro_rules! _get {
    ($it:ident; [char]) => {
        _get!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; [u8]) => {
        _get!($it; String).bytes().collect::<Vec<_>>()
    };
    ($it:ident; usize1) => {
        $it.next().unwrap().parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap().parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:tt),+) => {
        ($(_get!($it; $t)),*)
    };
}
// }}}

fn main() {
    let s = get!(String);
    if s=="RRR" {
        println!("{}", 3);
    } else if s=="RRS" || s == "SRR" {
        println!("{}", 2);
    } else if s=="RSR" || s=="SSR" || s=="SRS" || s=="RSS" {
        println!("{}", 1);
    } else {
        println!("{}", 0);
    }
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
map<string,int> mp;
int main() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	mp[s]=1;
	int len=s.size();
	for(int i=1;i<n;i++) {
		string s2;
		cin>>s2;
		if(s2[0]!=s[len-1]) return puts("No"),0;
		if(mp[s2]) return puts("No"),0;
		mp[s2]=1;
		s=s2;
		len=s.size();
	}puts("Yes");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
int main() {
  string s;
  cin >> s;
  int n = s.size() + 1;
  vector<int> v(n, 0);
  for(int i = 0;i < n-1;i++) if(s[i] == '<') v[i+1] = v[i] + 1;
  for(int i = n-2;i > - 1;i--) if(s[i] == '>') v[i] = max(v[i], v[i+1]+1);
  cout << accumulate(all(v), 0LL) << endl;
}

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

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var d = new Dictionary<string, int>();
            for (var i = 0; i < N; i++)
            {
                var S = Console.ReadLine();
                if (!d.ContainsKey(S)) d[S] = 0;
                d[S]++;
            }

            var maxValue = d.Values.Max();
            var l = new List<string>();
            foreach (var kv in d)
            {
                if (kv.Value != maxValue) continue;
                l.Add(kv.Key);
            }

            l.Sort(StringComparer.Ordinal);
            Console.WriteLine(string.Join("\n", l));
        }
    }
}


Measured memory_bytes: 47992
h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]

#[print(maze[i]) for i in range(h)]
from collections import deque

mx = 0
for i in range(h):
  for j in range(w):
    s_y, s_x = i, j
    if maze[s_y][s_x] == '#':
      continue
    visited = [[0]*w for _ in range(h)]
    dis = [[0]*w for _ in range(h)]
    
    d = deque()
    d.append([s_y, s_x])
    visited[s_y][s_x] = 1
    
    while len(d):
      y, x = d.popleft()
      for dy, dx in [[-1,0], [1,0], [0, -1], [0, 1]]:
        next_y, next_x = y+ dy, x+dx
        if next_y>=0 and next_y<h and next_x>=0 and next_x<w:
          if maze[next_y][next_x]=='.' and visited[next_y][next_x]==0:
            d.append([next_y, next_x])
            dis[next_y][next_x] = dis[y][x] + 1
            visited[next_y][next_x] = 1
            if dis[next_y][next_x]>mx:
              mx = dis[next_y][next_x]
              
print(mx)

Measured memory_bytes: 46812
#include <iostream>
#include <string> 
#include <iomanip>
#include <cstdio>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <queue>
using namespace std;






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

	long long count = 0;


	for (int b = K+1; b <= N;b++) {
		count += (N / b) *max(b - K, 0);
		count += max(0, N % b + 1 - K);
	}

	if (K == 0) {
		count -= N;
	}

	cout << count;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	if (a+b==15) cout<<"+"<<endl;
	else if (a*b==15) cout<<"*"<<endl;
	else cout<<"x"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
 int main(){
   int n;
   std::cin >> n;

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

   int counter = 0;
   while (true){
     bool exist_odd = false;
     for(int i=0; i < n; ++i){
       if (array[i]%2 != 0){
         exist_odd = true;
       }
     }

     if (exist_odd) break;

     for(int i = 0; i<n; ++i){
       array[i] = array[i]/2;
       //std::cout << counter << std::endl;
     }
    ++counter;
   }


   std::cout << counter << std::endl;
   return 0;
 }


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp14
{
    class Class30
    {
        static void Main()
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = ab[0];
            var b = ab[1];
            int dif = Math.Abs(a - b)+1;
            if ((a < 0 && b > 0) | (a > 0 && b < 0) | a == 0 | b == 0)
            {
                Console.WriteLine("Zero");
            }
            else if (a > 0)
            {
                Console.WriteLine("Positive");
            }
            else
            {
                if (dif % 2 == 0)
                {
                    Console.WriteLine("Positive");
                }
                else
                {
                    Console.WriteLine("Negative");
                }
            }
        }
    }
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int h,w;
vector<int>v;

int ans[100][100];

void setAns(int count){
  int temp=0;
  int right=0,down=0,left=-2,up=-1;
  while(count!=h*w){

    for(right=left+2;right<w;right++){
      if(ans[temp][right]==-1){
        if(count==h*w)return;
        ans[temp][right]=v[count];
        count++;
      }else{
        break;
      }
    }
    temp=right-1;

    for(down=up+2;down<h;down++){
      if(ans[down][temp]==-1){
        if(count==h*w)return;
        ans[down][temp]=v[count];
        count++;
      }else{
        break;
      }
    }
    temp=down-1;

    for(left=right-2;left>=0;left--){
      if(ans[temp][left]==-1){
        if(count==h*w)return;
        ans[temp][left]=v[count];
        count++;
      }else{
        break;
      }
    }
    temp=left+1;

    for(up=down-2;up>=0;up--){
      if(ans[up][temp]==-1){
        if(count==h*w)return;
        ans[up][temp]=v[count];
        count++;
      }else{
        break;
      }
    }
    temp=up+1;
  }
}

int main(){

  cin>>h>>w;
  int n;cin>>n;
  int a[n+10];
  rep(i,0,n)cin>>a[i];

  int count=0;
  CLR(ans,-1);

  rep(i,0,n){
    rep(j,0,a[i]){
      v.push_back(i+1);
    }
  }
  setAns(0);

  rep(i,0,h){
    rep(j,0,w){
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
  long long n,ans=0,aa=0;
  cin>>n;
  long long v[n];
  for(int i=0;i<n;i++){
    cin>>v[i];
    ans+=abs(v[i]);
    if(v[i]<0){
    aa++;
    v[i]=abs(v[i]);
    }
  }
  if(aa%2==0)
  cout<<ans<<endl;
  else{
    sort(v,v+n);
    cout<<ans-v[0]*2<<endl;
  }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 int a,b;
	 cin>>a>>b;
	 cout<<a*b;
	 return 0;
}

Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b && b==c){
    cout<<"No";
    return 0;
  }
  if(a==b || b==c || c==a)
    cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

const int INF = 10000000;

using Mat = std::vector< std::vector<int> >;

void wf(Mat& adj_mat) {
  int n = adj_mat.size();

  for(int i = 0; i < n; ++i) {     // via node
    for(int j = 0; j < n; ++j) {   // start
      for(int k = 0; k < n; ++k) { // terminal
        adj_mat[j][k] = std::min(adj_mat[j][k], adj_mat[j][i] + adj_mat[i][k]);
      }
    }
  }
}

int main() {
  while(1){
    int n, m;
    int a, b, cost, time;

    std::cin >> n >> m;
    if (n == 0)
      break;

    Mat cost_table, time_table;
    cost_table.resize(m);
    time_table.resize(m);
    for(int i = 0; i < m; ++i) {
      cost_table.at(i).resize(m);
      time_table.at(i).resize(m);
      for(int j = 0; j < m; ++j){
        cost_table[i][j] = INF;
        time_table[i][j] = INF;
      }
    }

    for(int i = 0; i < n; ++i){
      std::cin >> a >> b >> cost >> time;
      --a, --b;
      cost_table[a][b] = cost_table[b][a] = cost;
      time_table[a][b] = time_table[b][a] = time;
    }

    wf(cost_table);
    wf(time_table);

    // Query
    int k;
    int p, q, r;
    std::cin >> k;
    for(int i = 0; i < k; ++i){
      std::cin >> p >> q >> r;
      --p, --q;
      if (r == 0)
        std::cout << cost_table[p][q] << std::endl;
      else
        std::cout << time_table[p][q] << std::endl;
    }
  }
}

Measured memory_bytes: 3176
#include<iostream>
#include<bits/stdc++.h>
#include<vector>

using namespace std;

int main()
{
	int n;
	cin>>n;
	vector<int> a,b,c;
	int p,q,r;
	for(int i=0;i<n;i++)
	{
		cin>>p>>q>>r;
		a.push_back(p);
		b.push_back(q);
		c.push_back(r);
	}
	int dp[n][3];
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	for(int i=1;i<n;i++)
	{
		dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
		//cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	return 0;
}

Measured memory_bytes: 5568
#include<iostream>
using namespace std;
int main(){

	int A,B,K;
	cin>>A>>B>>K;
	
	for(int i=0;i<K;i+=2){
		
		if(A%2==1)
			A--;
				
		int x=A/2;
		B+=x;
		A/=2;
		if(i+1==K) break;
		
		if(B%2==1)
			B--;
		int y=B/2;
		B/=2;
		A+=y;
		
	}
	cout<<A<<" "<<B;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
prime[1300];
int c;
int isPrime(int n){
	int i;
	for(i=0;i<c && prime[i]<n;i++){
		if(n==prime[i])
			return 1;
		if(n%prime[i]==0)
			return 0;
	}
	for(i=3;i<n/2;i++){
		if(n%i==0)return 0;
	}
	return 1;
}

int main(){
	int i,j,n,*p,*q;
	prime[0]=2;
	prime[1]=3;
	prime[2]=5;
	prime[3]=7;
	c=4;
	for(i=8;i<10010;i++){
		if(isPrime(i)){
			prime[c]=i;
			c++;
		}
	}
	for(;scanf("%d",&n)&&n;){
		for(i=1;1;i++){
			if(prime[i]>n)break;
			if(prime[i]-prime[i-1]==2){
				p=&prime[i-1];
				q=&prime[i];
			}
		}
		printf("%d %d\n",*p,*q);
	}
	return 0;
}

Measured memory_bytes: 408
N, K = map(int, input().split(' '))
red = N-K
p = 10**9+7


def comb(n, k, p):
    """power_funcを用いて(nCk) mod p を求める"""
    from math import factorial
    if n < 0 or k < 0 or n < k:
        return 0
    if n == 0 or k == 0:
        return 1
    a = factorial(n) % p
    b = factorial(k) % p
    c = factorial(n-k) % p
    return (a*power_func(b, p-2, p)*power_func(c, p-2, p)) % p


def power_func(a, b, p):
    """a^b mod p を求める"""
    if b == 0:
        return 1
    if b % 2 == 0:
        d = power_func(a, b//2, p)
        return d*d % p
    if b % 2 == 1:
        return (a*power_func(a, b-1, p)) % p


def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)


for i in range(1, K+1):
    print(comb(red+1, i, p)*comb(K-1, i-1, p) % p)

Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
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;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    string s; cin >> s;
    int start = 0;
    int end = 0;
    rep(i, s.length()){
        if(s[i]=='A'){
            start = i;
            break;
        }
    }
    rep(i, s.length()){
        if(s[i]=='Z') end = i;
    }
    pr(end-start+1);
}


Measured memory_bytes: 640
#include<stdio.h>
const int N = 305;
const int M = 305;
int main()
{
	int n, m;
	while(scanf("%d %d", &n, &m))
	{
		if(n == 0 && m == n)
		{
			break;
		}
		for(int i = 0;i < m; i++)
		{
			printf("#");
		}
		printf("\n");
		for(int i = 0; i < n-2; i++)
		{
			printf("#");
			for(int j = 0; j< m-2; j++)
			{
				printf(".");
			}
			printf("#");
			printf("\n");
		}
		for(int i = 0;i < m; i++)
		{
			printf("#");
		}
		printf("\n\n");
	}
	return 0;
}


Measured memory_bytes: 2600
n = int(input())
s = [input() for i in range(n)]
query ='abcdefghijklmnopqrstuvwxyz'
a = []
for i in query:
  ct = 999999999999999
  for j in range(n):
   ct = min(ct,s[j].count(i))
  if ct>0:
   a.append(i*ct)

print(''.join(a))

Measured memory_bytes: 3060
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)    
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]    

N, M, K = map(int,input().split())
uf = UnionFind(N)
f_b = [set() for _ in range(N)]
ans = []
for i in range(M):
    A, B = map(int,input().split())
    A -= 1
    B -= 1
    uf.union(A, B)
    uf.find(A)
    f_b[A].add(B)
    f_b[B].add(A)
    
for i in range(K):
    C, D = map(int,input().split())
    C -= 1
    D -= 1
    if uf.same(C, D):
        f_b[C].add(D)
        f_b[D].add(C)    

for i in range(N):
    ans.append(uf.size(i) - len(f_b[i]) - 1)
print(*ans)

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

int main()
{
    long long n,a,b,m;
    cin>>n>>a>>b;
    if((b-a)%2) m=min(a-1,n-b)+1+(b-a-1)/2;
    else m=(b-a)/2;
    cout<<m<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n[3]; // 0: Math+DP, 1: Greedy+Graph 2: Geometry+Other

bool all(int p, int* n, int size) {
    for (int i = 0; i < size; i++) if (n[i] != p) return false;
    return true;
}

int main() {
    int _n[6];
    while (cin >> _n[0] >> _n[1] >> _n[2] >> _n[3] >> _n[4] >> _n[5]) {
        if (all(0, _n, 6)) break;
        n[0] = _n[0] + _n[3];
        n[1] = _n[1] + _n[4];
        n[2] = _n[2] + _n[5];
        
        int lim = 2;
        for (int i = 0; i < 3; i++) 
            lim = min(lim, n[i]);

        int max_count = 0;
        for (int i = 0; i <= lim; i++) {
            int _count = i;
            _count += (n[0]-i) / 3;
            _count += (n[1]-i) / 3;
            _count += (n[2]-i) / 3;
            max_count = max(max_count, _count);
        }
        cout << max_count << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<ios>
int main(){
    int H,W,i,j;
    scanf("%d%d",&H,&W);
    char A[H+2][W+2];
    for( int i= 0;i < W+2;i++){
        A[0][i]='#';
        A[H+1][i]='#';
    }
    for(int i=1;i < H+1;i++){
        getchar();
        A[i][0] = '#';
        for(int j= 1;j<W+1;j++){
            scanf("%c",&A[i][j]);
        }
        A[i][W+1] = '#';
    }
    for(int i=0;i < H+2;i++){
        for (int j=0;j<W+2;j++){
            printf("%c",A[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 128
use proconio::*;

fn main() {
    input! {
        x: i64,
        n: usize,
        p: [i64; n]
    }
    
    if n == 0 {
        println!("{}", x);
        return;
    }

    let mut counter: [i64; 101] = [0; 101];
    for i in 0..n {
        counter[p[i] as usize] += 1;
    }

    let mut ans = None;
    for i in 0..=100 {
        for sign in [-1, 1].iter() {
            let val = x + sign * i as i64;
            if 1 <= val && val <= 100 {
                if counter[val as usize] > 0 { continue; }
            }

            ans = Some(val);
            break;
        }
        if ans != None { break; }
    }
    println!("{}", ans.unwrap());
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
int N;
float T,A;

int main(void){
  cin >> N >> T >> A;
  int i,min_index=-1;
  float min=INF,x;
  REP(i,N){
    cin >> x;
    if(min > abs(A-(T-x*0.006))){
      min = abs(A-(T-x*0.006));
      min_index = i;
    }
  }
  cout << min_index+1 << endl;
  return 0;
}

Measured memory_bytes: 384
mt = []
for _ in range(3):
    mt.append(list(map(int, input().split())))
b1b2, b2b3, a1a2, a2a3 = [],[],[],[]
for i in range(3):
    b1b2.append(mt[i][0]-mt[i][1])
    b2b3.append(mt[i][1]-mt[i][2])
    a1a2.append(mt[0][i]-mt[1][i])
    a2a3.append(mt[1][i]-mt[2][i])
array = [b1b2,b2b3,a1a2,a2a3]
def sl(es):
    return len(list(set(es))) == 1
if all([sl(es) for es in array]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

const int MAX = 100000;

int main(){
  stack<char> P;
  char r;
  string X;
  cin >> X;
  P.push('o');
  for(int i=0;i<X.size();i++){
    r=X[i];
    if(P.top()=='S' && r=='T'){
      P.pop();
    } else{
      P.push(r);
    }
  }
  cout << P.size()-1 << endl;
  return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

using vl    = vector<long long>;
using vvl   = vector<vl >;
using vvvl  = vector<vvl >;

/*Binary Indexed Tree*/
template<typename Type>
struct BIT{
	int n;				//n:=(要素数).
	vector<Type> dat;	//i:=[1,n].
	
	/*constructor.*/
	BIT(int n_):n(n_),dat(n_+1,0){}
	BIT(vector<Type> &v_):n(v_.size()),dat(v_.size()+1){
		copy(ALL(v_),dat.begin()+1);
		build();
	}
	
	void build(){//木を構築する. O(N).
		for(int i=1;i<n;++i){
			if(i+(i&-i)<=n) dat[i+(i&-i)]+=dat[i];
		}
	}
	void init(Type x=0){//全要素をxで初期化する. O(N).
		fill(dat.begin()+1,dat.end(),x);
		if(x==0) return;
		build();
	}
	void add(int i,Type x){//i番目の要素にxを足す. O(log N).
		if(i<=0 or n<i) return;
		for(;i<=n;i+=(i&-i)) dat[i]+=x;
	}
	Type sum(int i){//[1,i]間の和を求める. O(log N).
		if(i<=0 or n<i) return 0;
		Type res=0;
		for(;i>0;i-=(i&-i)) res+=dat[i];
		return res;
	}
	Type range_sum(int l,int r){return sum(r)-sum(l-1);}//[l,r]間の和を求める.
};

int main(){
	int n,q;
	cin>>n>>q;
	
	vl a(n);
	REP(i,n) cin>>a[i];
	
	BIT<llong> tree(a);
	REP(i,q){
		int t,x,y;
		cin>>t>>x>>y;
		
		if(t==0) tree.add(x+1,y);
		else cout<<tree.range_sum(x+1,y)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 12148
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    char a, b;
    cin >> a >> b;
    if(a == 'H' && b == 'H') cout << 'H' << endl;
    if(a == 'D' && b == 'H') cout << 'D' << endl;
    if(a == 'D' && b == 'D') cout << 'H' << endl;
    if(a == 'H' && b == 'D') cout << 'D' << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
char s[222222];
int a[222222],pa;
int l[222222],pl;
int r[222222],pr;
int d[222222],pd;
int vis[222222];
int la[222222],to[222222];
int main()
{
	int n=io::F()<<1;
	scanf("%s",s+1);
	s[0]=s[n]='1';
	for(register int i=1;i<=n;++i)
		if(s[i]=='1'&&s[i-1]=='1')l[++pl]=i;
			else if(s[i-1]=='1')d[++pd]=i;
					else if(s[i]=='1')d[++pd]=i;
	if(pl&1){puts("No");return 0;}
	if(pl%4==0)
	{
		for(register int i=1;i+i<=pl;++i)
			a[l[i]]=a[l[i+pl/2]]=++pa;
		for(register int i=1;i<=pd;i+=2)
			a[d[i]]=a[d[i+1]]=++pa;
		int cnt=0;
		++pa;
		for(register int i=1;i<=n;++i)
			if(a[i]==0)
			{
				a[i]=pa;
				++cnt;
				if(cnt==2)cnt=0,++pa;
			}
		puts("Yes");
		for(register int i=1;i<=n;++i)printf("%d ",a[i]);
		return 0;
	}
	for(register int i=2;i<pd;i+=2)
		if(d[i+1]-d[i]==1)a[d[i]]=a[d[i-1]]=++pa,d[i-1]=d[i]=0;
	std::sort(d,d+pd+1);
	pd=std::unique(d,d+pd+1)-d-1;
	if(pd<=2){puts("No");return 0;}
	for(register int i=5;i<=pd;i+=2)
		a[d[i]]=a[d[i+1]]=++pa;
	a[d[1]]=a[d[4]]=++pa;
	a[d[2]]=a[d[3]]=++pa;
	for(register int i=1;i<=pl;++i)
		if(l[i]>=d[2]&&l[i]<=d[3])r[++pr]=l[i],l[i]=0;
	std::sort(l,l+pl+1);
	pl=std::unique(l,l+pl+1)-l-1;
	if(pl==0){puts("No");return 0;}
	for(register int i=1;i+4<=pl;i+=4)
		a[l[i]]=a[l[i+2]]=++pa,a[l[i+1]]=a[l[i+3]]=++pa;
	for(register int i=1;i+4<=pr;i+=4)
		a[r[i]]=a[r[i+2]]=++pa,a[r[i+1]]=a[r[i+3]]=++pa;
	if(pl%4==1){a[l[pl]]=a[r[pr]]=++pa;}
	if(pl%4==3){a[l[pl]]=a[r[pr]]=++pa,a[l[pl-1]]=a[r[pr-1]]=++pa,a[l[pl-2]]=a[r[pr-2]]=++pa;}
	if(pl%4==2){a[l[pl-1]]=a[r[pr-3]]=++pa,a[l[pl]]=a[r[pr-1]]=++pa,a[r[pr-2]]=a[r[pr]]=++pa;}
	if(pl%4==0){a[l[pl-3]]=a[r[pr-1]]=++pa,a[l[pl-1]]=a[r[pr]]=++pa,a[l[pl-2]]=a[l[pl]]=++pa;}
	int cnt=0;
	++pa;
	for(register int i=1;i<=n;++i)
		if(a[i]==0)
		{
			a[i]=pa;
			++cnt;
			if(cnt==2)cnt=0,++pa;
		}
	puts("Yes");
	for(register int i=1;i<=n;++i)printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 5504