akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

struct SegmentTree{
private:
    int n;
    vector<ll> node;
public:
    SegmentTree(const int sz){
        n=1;
        while(n<sz)n*=2;
        node.resize(2*n-1,LINF);
        node[n-1]=0;
        for(int i=n-2;i>=0;i--){
            node[i]=min(node[2*i+1],node[2*i+2]);
        }
    }
    void update(int a,ll x){
        a+=n-1;
        node[a]=x;
        while(a>0){
            a=(a-1)/2;
            node[a]=min(node[2*a+1],node[2*a+2]);
        }
    }
    ll get(int a,int b,int k=0,int l=0,int r=-1){
        if(r==-1)r=n;
        if(b<=l||r<=a)return LINF;
        if(a<=l&&r<=b){
            return node[k];
        }
        else{
            return min(get(a,b,2*k+1,l,(l+r)/2),get(a,b,2*k+2,(l+r)/2,r));
        }
    }
    ll get(int a){
        return node[a+n-1];
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    pair<pair<int,int>,int> p[m];
    for(int i=0;i<m;i++){
        int l,r,c;
        cin>>l>>r>>c;
        --l,--r;
        p[i]={{r,l},c};
    }
    sort(p,p+m);
    SegmentTree seg(n);
    for(int i=0;i<m;i++){
        int l=p[i].first.second;
        int r=p[i].first.first;
        int c=p[i].second;
        ll t=seg.get(l,r);
        if(seg.get(r)>t+c){
            seg.update(r,t+c);
        }
    }
    if(seg.get(n-1)==LINF){
        cout<<-1<<endl;
    }
    else{
        cout<<seg.get(n-1)<<endl;
    }
}


Measured memory_bytes: 3456
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
	
		int []a = new int [n];
		
		for(int i = 0 ; i < n ;i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		
		Arrays.sort(a);
		
		int l = 0;
		int r = a[n-1];
		int mid = (r + l)/2;
		
		while(r - l > 1) {
			int cnt = 0;
			mid = (l + r)/2;
			for(int i = 0 ; i < n ;i++) {
				cnt += Math.ceil((double)a[i]/mid)-1;
			}
			
			if(cnt > k) {
				l = mid;
			}
			else if(cnt <= k) {
				r = mid;
			}
		}
		
		System.out.println(r);
		
	
	}

}


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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    int N;
    ll ans = 0;
    cin >> N;

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

    for (int i = 0; i < N; ++i)
    {
        for (int j = i + 1; j < N; ++j)
        {
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<int> h(n);
  REP(i, n) cin >> h[i];
  int ans = -1;
  int cnt = 0;
  FOR(i, 1, n - 1) {
    if (h[i - 1] >= h[i]) {
      cnt++;
    } else {
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  ans = max(ans, cnt);
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MX=3*1e5+100;
const long long INF = 1e18;
int N, M, k;
int arr[MX];
int main()
{
    string s;
    int A, B;
    cin>>A>>B>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i] == '-')
            {
                N=1;
                continue;
            }
        if(N == 0) A--;
        else B--;
    }
    if(A == 0 && B == 0)
    {
        cout<<"Yes";
    }
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;


    int main(){
        vector<vector<int>>a(3,vector<int>(3));
        vector<vector<bool>>f(3,vector<bool>(3));
        rep(i,3)rep(j,3){cin>>a[i][j];f[i][j] = false;}
        int n;cin>>n;
        rep(i,n){
            int b;cin>>b;
            rep(j,3)rep(k,3){
                if(b==a[j][k])f[j][k] = true;
            }
        }
        bool fl = false;
        rep(i,3){
            int cnt = 0;
            rep(j,3){
                if(f[i][j])cnt++;
            }
            if(cnt == 3)fl = true;
        }
        rep(j,3){
            int cnt = 0;
            rep(i,3){
                if(f[i][j])cnt++;
            }
            if(cnt == 3)fl = true;
        }
        if(f[0][0]&&f[1][1]&&f[2][2])fl = true;
        if(f[0][2]&&f[1][1]&&f[2][0])fl = true;
        cout<<(fl?"Yes":"No");
    }
    


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static char chkWin(String str){
    char[][] mark = {{str.charAt(0),str.charAt(1),str.charAt(2)},
                     {str.charAt(3),str.charAt(4),str.charAt(5)},
                     {str.charAt(6),str.charAt(7),str.charAt(8)}};
    for (int i = 0; i < 3; i++) {
      if (mark[i][0] != 's' && mark[i][0] == mark[i][1] &&
                               mark[i][0] == mark[i][2]){
        return mark[i][0];
      }
      else if(mark[0][i] != 's' && mark[0][i] == mark[1][i] &&
                                   mark[0][i] == mark[2][i]){
        return mark[0][i];
      }
    }
    if (mark[1][1] != 's'){
      if(mark[0][0] == mark[1][1] && mark[1][1] == mark[2][2]){
        return mark[2][2];
      }
      else if(mark[0][2] == mark[1][1] && mark[1][1] == mark[2][0]){
        return mark[2][0];
      }
    }
    return 'd';
  }

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      String str = sc.next();
      System.out.println(chkWin(str));
    }
  }
}

Measured memory_bytes: 11000
//　暑い日々　0579
#include<bits/stdc++.h>
using namespace std;
int dp[201][201];
int main(void)
{
	int d,n,t[201],a[201],b[201],c[201];
	int i,j,k,w=0,max;
	
	cin>>d>>n;
	for(i=1;i<=d;i++) cin>>t[i];
	for(i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
	
	for(i=1;i<=d;i++){
		for(j=1;j<=n;j++) dp[i][j]=-1;
	}
	
	for(i=1;i<=n;i++){
			if(t[1]<=b[i]&&t[1]>=a[i]) dp[1][i]=0;
	}
	
	for(i=1;i<d;i++){
		for(j=1;j<=n;j++){
			if(dp[i][j]!=-1){
				for(k=1;k<=n;k++){
					if(t[i+1]>=a[k]&&t[i+1]<=b[k]){
							w=abs(c[j]-c[k]);	
						if(dp[i+1][k]<dp[i][j]+w){
							dp[i+1][k]=dp[i][j]+w;
						}	
					}
				}
			}
		}
	}
	
	max=-1;
	for(i=1;i<=n;i++){
		if(max<dp[d][i]) max=dp[d][i];
	}
	
	cout<<max<<endl;
	
	return 0;
}	


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

int main() {
  int n; cin >> n;
  vector<int> a;
  a.push_back(0);
  long long total_cost = 0;
  for (int i = 1; i <= n; i++) {
    int x; cin >> x;
    a.push_back(x);
    total_cost += abs(x - a[i-1]);
  }
  a.push_back(0);
  total_cost += abs(0 - a[a.size() - 2]);
  for (int i = 1; i < a.size() - 1; i++) {
    long long cost = 0;
    if ((a[i] > a[i-1] && a[i-1] > a[i+1]) || (a[i+1] > a[i-1] && a[i-1] > a[i])) {
      cost = 2 * abs(a[i] - a[i - 1]);
    } else if ((a[i] > a[i+1] && a[i+1] > a[i-1]) || (a[i-1] > a[i+1] && a[i+1] > a[i])) {
      cost = 2 * abs(a[i+1] - a[i]);
    } else if (a[i+1] == a[i-1]) {
      cost = 2 * abs(a[i+1] - a[i]);
    }
    cout << total_cost - cost << endl;
  }
  return 0;
}


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

using namespace std;

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

#define INF 1<<30
#define F first
#define S second

int main(){
  ll a[20];
  ll n,ans;
  ll ice=INF;
  for(ll i=8;i>0;i/=2){
    cin>>a[i];
    if(ice>a[i]*i){
      ice=a[i]*i;
    }
  }
  cin>>n;
  
  ans=ice*(n/2);

  if(n%2==1) ans+=min(a[8]*4,min(a[4]*2,a[2]));
  printf("%lld\n",ans);
  
  return 0;
}


Measured memory_bytes: 256
L, N = map(int, input().split())
X=[0]
sumL=[0]
sumR=[0]
for i in range(N):
    X.append(int(input()))
    sumL.append(sumL[-1]+X[-1])
for i in range(N):
    sumR.append(sumR[-1]+L-X[N-i])
sumR.append(0)
sumR.reverse()
#print(X)
#print("sumL",sumL)
#print("sumR",sumR)
ans = 0
for b in range(N+1):
    z = sumL[b] + sumR[b+1]
    if(b > 0):
        if(b <= N-b):
            ans = max(ans, z+sumL[b-1]+sumR[b+1]-2*sumR[N+1-(N-b-b)])
            #print("A", b, z+sumL[b-1]+sumR[b+1]-2*sumR[N+1-(N-b-b)])
        else:
            ans = max(ans, z+sumL[b-1]+sumR[b+1]-2*sumL[b-(N-b)-1])
            #print("B", b, z+sumL[b-1]+sumR[b+1]-2*sumL[b-(N-b)-1])
    if(b < N):
        if(b >= N-b):
            ans = max(ans, z+sumL[b]+sumR[b+2]-2*sumL[b-(N-b)])
            #print("C", b, z+sumL[b]+sumR[b+2]-2*sumL[b-(N-b)])
            #print(b, z, sumR[b+1], sumL[b], sumR[b+2], sumL[b-(N-b)])
        else:
            ans = max(ans, z+sumL[b]+sumR[b+2]-2*sumR[N+1-(N-b-b)+1])
            #print("D", b, z+sumL[b]+sumR[b+2]-2*sumR[N+1-(N-b-b)+1])
    #print("------------------------")
print(ans)

Measured memory_bytes: 28476
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String arr[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
        String word=s.next();
        int j=0;
        for(String i:arr){
            if(i.equals(word)){
                System.out.println(7-j);
                break;
            }
            j++;
        }
    }
}



class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25296
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    int ans = 0;
    rep(i, n){
        cin >> h[i];
        if(h[i] >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

n,q=map(int, input().split())
ab=[]
for _ in range(n):
    ab.append([])
for _ in range(n-1):
    a,b=map(int, input().split())
    ab[a-1].append(b)
px=[0]*n
for _ in range(q):
    p,x=map(int, input().split())    
    px[p-1]+=x

def func(p, now):
    global res
    res[p-1]+=px[p-1]+now
    for i in ab[p-1]:
        func(i, res[p-1])

res=[0]*n

func(1, 0)

print(" ".join(map(str, res)))


Measured memory_bytes: 231388
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long

signed main() {
  string s;
  cin >>s;
  for(int i=s.length()-2;i>=2;i-=2) {
    string ss = s.substr(0,i/2);
    string sss = s.substr(i/2,i/2);
    //cout << i<<" "<<ss <<" "<<sss << endl;
    if(ss==sss) {
      cout << ss.length()*2 << endl;
      return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	//C問題

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scan = new Scanner(System.in);

		int r = scan.nextInt();

		System.out.println(r * r);
	}

}

Measured memory_bytes: 21844
#ABC154A
import sys
from collections import OrderedDict
d = OrderedDict()
s,t = sys.stdin.readline().split()
n1, n2 = map(int, sys.stdin.readline().split())
d[s] = n1
d[t] = n2

d[sys.stdin.readline().rstrip()] -=1

print(*d.values())


Measured memory_bytes: 3316
N = int(input())
A = list(input().split())
An = [int(num) for num in A]

sum = 0

for i in range(1,N):
  if An[i-1]<=An[i]:
    continue
  else:
    sum += (An[i-1]-An[i])
    An[i] = An[i-1]
    
print(sum)

Measured memory_bytes: 32480
// atcoder/abc132/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

const int N = 1e5 + 5;
vector<int> g[N];

int bfs01(int src, int dst)
{
  static int cost[N][3];
  static bool vis[N][3];
  fill(&cost[0][0], &cost[N - 1][3 - 1] + 1, -3);
  fill(&vis[0][0], &vis[N - 1][3 - 1] + 1, false);
  vis[src][0] = true;
  cost[src][0] = 0;

  queue<pair<int, int>> q;
  for (q.push({src, 0}); q.size(); q.pop()) {
    pair<int, int> p = q.front();
    const int curr = p.first;
    const int x = p.second;
    const int y = (x + 1) % 3;
    each (next, g[curr]) {
      if (vis[next][y]) continue;
      vis[next][y] = true;
      cost[next][y] = cost[curr][x] + 1;
      q.push({next, y});
    }
  }

  return cost[dst][0] / 3;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  while (cin >> n >> m) {
    fill(g, g + N, vector<int>());
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      g[a].push_back(b);
    }
    int s, t;
    cin >> s >> t;
    cout << bfs01(s - 1, t - 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 7168
#158_D
s = input()
q = int(input())

from collections import deque

s = deque(s)

rev = 1
for _ in range(q):
    Q = list(input().split())
    if Q[0] == "1":
        rev *= -1
    elif Q[0] == "2":
        if (Q[1]=="1" and rev==1) or (Q[1]=="2" and rev==-1):
            s.appendleft(Q[2])
        elif (Q[1]=="2" and rev==1) or (Q[1]=="1" and rev==-1):
            s.append(Q[2])
            
s = "".join(s)
            
if rev == -1:
    s = s[::-1]

print(s)

Measured memory_bytes: 14012
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 81

int N;
int energy[NUM];
bool dp[321][321][NUM];

void func(){

	scanf("%d",&N);

	int sum = 0;
	for(int i = 0; i < N; i++){
		scanf("%d",&energy[i]);
		sum += energy[i];
	}

	if(N <= 2){
		printf("%d\n",energy[N-1]);
		return;
	}

	for(int a = 0; a <= sum; a++){
		for(int b = 0; b <= sum; b++){
			for(int c = 0; c < NUM; c++)dp[a][b][c] = false;
		}
	}

	dp[energy[0]][energy[1]][0] = true;

	int right_value;
	for(int i = 1; i <= N-2; i++){

		right_value = energy[i+1];

		for(int left_value = 0; left_value <= sum; left_value++){
			for(int self_value = 0; self_value <= sum; self_value++){
				if(!dp[left_value][self_value][i-1])continue;

				dp[self_value][right_value][i] = true;
				if(self_value > 0){
					dp[self_value-1][right_value+left_value][i] = true;
				}
			}
		}
	}

	int ans = 0;
	for(int i = 0; i <= sum; i++){
		for(int k = 0; k <= sum; k++){
			if(dp[i][k][N-2]){
				ans = max(ans,k);
			}
		}
	}

	printf("%d\n",ans);
}


int main(){

	int num_case;
	scanf("%d",&num_case);

	for(int loop = 0; loop < num_case; loop++){
		func();
	}

	return 0;
}



Measured memory_bytes: 5308
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
unordered_map<ll,ll> mp;
set<ll> st;

//-------------------------↓↓↓↓↓↓------------------------

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

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

    rep(i,n){
        mp[a[i]]++;
        st.insert(a[i]);
    }

    rep(i,n){
        if(mp[a[i]]%2==0&&mp[a[i]]!=0)cnt++;
        mp[a[i]]=0;
    }
    if(cnt%2==1)ans=-1;
    Cout(ans+Size(st));
    return 0;
}


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

string query(int n) {
	cout << n << '\n' << flush;
	string s; cin >> s;
	if (s == "Vacant") exit(0);
	return s;
}

int main() {
	int n; cin >> n;
	int l = 0;
	int r = n - 1;
	string L = query(l);
	string R = query(r);

	while (l < r) {
		int m = (l + r) / 2;
		R = query(m);
		if (m % 2) {
			if (L == R) r = m;
			else l = m;
		} else {
			if (L == R) l = m;
			else r = m;
		}
	}
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

int N;
vector<int> A;

int main() {
    
    cin >> N;
    A.resize(N);
    cin >> A;
    
    sort(all(A));
    
    bool flag = true;
    
    for(auto i = 1; i<N; i++){
        
        if (A[i]%A[0] != 0) flag = false;
    }
    
    if (flag == true){
        cout << A[0] << endl;
        return 0;
    }
    
    flag = true;
    
    while(A.size()!=1){
        
        flag = false;

        for(auto i = 1; i<N; i++){
            A[i] %= A[0];
        }
        
        sort(all(A));
        A.erase(A.begin(),upper_bound(all(A),0));
        
    }
    
    cout << A[0] << endl;
    
    return 0;
}










Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;int k;
  cin>>k>>a>>b;
  a--;
  int p=a/k;
  int q=b/k;
  q-=p;
  if(q>=1)
    cout<<"OK\n";
  else
    cout<<"NG\n";
  return 0;
}
  

Measured memory_bytes: 3636
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  set<string> s;
  char last = w[0][0];
  bool ok = true;
  for (int i = 0; i < n; i++) {
    if (last != w[i][0]) {
      ok = false;
    }
    if (s.find(w[i]) != s.end()) {
      ok = false;
    }
    last = w[i][w[i].size() - 1];
    s.insert(w[i]);
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

const int MX = 205;
const int MP = 10000005;

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

struct GRAPH
{
	int fst[MX], nxt[MX*MX*2], v[MX*MX*2], w[MX*MX*2], lnum;
	
	void init()
	{
		memset(fst, 0xff, sizeof(fst));
		lnum = -1;
	}
	
	void addeg(int nu, int nv, int nw)
	{
		nxt[++lnum] = fst[nu];
		fst[nu] = lnum;
		v[lnum] = nv;
		w[lnum] = nw;
	}
	
	int vis[MX], dep[MX], que[MX], cur[MX];
	
	bool bfs(int frm, int tar)
	{
		int h = 1, t = 1;
		memset(dep, 0xff, sizeof(dep));
		que[h] = frm;
		dep[frm] = 0;
		while(h >= t)
		{
			int x = que[t++];
			for(int i=fst[x]; ~i; i=nxt[i])
				if(dep[v[i]]==-1 && w[i])
					dep[v[i]] = dep[x]+1, que[++h] = v[i];
		}
		return (dep[tar]!=-1);
	}
	
	int dinic(int x, int t, int mn)
	{
		if(x == t) return mn;
		int a, now = 0, y;
		for(int &i=cur[x]; ~i; i=nxt[i])
		{
			y = v[i];
			if(dep[y]==dep[x]+1 && w[i])
			{
				a = dinic(y, t, min(mn-now, w[i]));
				now += a;
				w[i] -= a;
				w[i^1] += a;
				if(now == mn) break;
			}
		}
		return now;
	}
	
	int mxf(int frm, int tar)
	{
		int f = 0;
		while(bfs(frm, tar))
		{
			memmove(cur, fst, sizeof(cur));
			f += dinic(frm, tar, 1000);
		}
		return f;
	}
} G;

int n, v;
int pos[MX];
int dif[MX];
int odd[MX], odn, eve[MX], evn;
bool vis[MP];
int prm[MP], pnum;

void init()
{
	vis[1] = 1;
	for(int i=2; i<MP; i++)
	{
		if(!vis[i]) prm[++pnum] = i;
		for(int j=1; j<=pnum; j++)
		{
			if(i*prm[j] >= MP) break;
			vis[i*prm[j]] = 1;
			if(i%prm[j] == 0) break;
		}
	}
}

int main()
{
	init();
	read(n);
	for(int i=1; i<=n; i++) read(pos[i]);
	for(int i=1; i<=n; i++)
	{
		if(v && dif[v]==pos[i]) v--;
		else dif[++v] = pos[i];
		dif[++v] = pos[i]+1;
	}
	for(int i=1; i<=v; i++)
		if(dif[i] & 1) odd[++odn] = dif[i];
		else eve[++evn] = dif[i];
	G.init();
	for(int i=1; i<=odn; i++)
		for(int j=1; j<=evn; j++)
			if(!vis[abs(odd[i]-eve[j])])
			{
				G.addeg(i, odn+j, 1);
				G.addeg(odn+j, i, 0);
			}
	for(int i=1; i<=odn; i++) G.addeg(odn+evn+1, i, 1), G.addeg(i, odn+evn+1, 0);
	for(int i=1; i<=evn; i++) G.addeg(odn+i, odn+evn+2, 1), G.addeg(odn+evn+2, odn+i, 0);
	int mch = G.mxf(odn+evn+1, odn+evn+2);
	printf("%d\n", (odn-mch)/2*2 + (evn-mch)/2*2 + (odn-mch)%2*3 + mch);
	return 0;
}

Measured memory_bytes: 14720
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int s;
  cin >> s;
  int a[1000000];

  a[0] = s;
  for(int i=0; i < 1000000; i++){
    if(a[i] % 2 == 0){
      a[i+1] = a[i] / 2;
    }else{
      a[i+1] = 3*a[i]+1;
    }
    for(int j=0; j < i; j++){
      if(a[j] == a[i+1]){
        cout << i+1+1 << endl;
        return 0;
      }
    }
  }

  return 0;
}


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

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

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		sc.close();

		if(Math.abs(a - c) <= d) {
			System.out.println("Yes");
		}else {
			if(Math.abs(a - b) <= d && Math.abs(b - c) <= d) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}

	}
}

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

namespace ITP1_10_C
{
    class Program
    {
        static void Main(string[] args)
        {
            // n人の得点s(1)～s(n)の標準偏差αを求めるプログラム

            // 得点の平均値をmとしたときの分散α^2は
            // α^2 =(Σ(j=1～n)(s(i)-m)^2/n で表せる
            // 分散αの正の平方根が標準偏差




            while (true)
            {
                int n = int.Parse(Console.ReadLine());                                      // 1行目 人数nの読み込み

                if (n == 0)
                {
                    break;
                }

                else
                {
                    int[] s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();        // 2行目 各得点s(i)の読み込み
                    double m = 0;                                                               // 平均点mの宣言と初期化
                    double variance = 0;                                                        // 分散の宣言と初期化


                    for (int i = 0; i < n; i++)                                                 // 平均点mを取得する
                    {
                        m += s[i];
                    }
                    m = m / n;

                    for (int j = 0; j < n; j++)                                                 // 標準偏差を求める
                    {
                        variance += Math.Pow(s[j] - m, 2) / n;
                    }

                    Console.WriteLine(Math.Sqrt(variance));
                }
            }

        }


    }
}



Measured memory_bytes: 18340
X, Y = map(int,input().split(' '))
sum1 = 0
flag = False

for x in range(X+1):
    sum1 = 10000 * x
    if sum1 > Y:
        break
    for y in range(X-x+1):
        sum2 = sum1 + 5000 * y
        if sum2 > Y:
            break
        if sum2 + 1000*(X-x-y) == Y:
            flag = True
            break
    if flag:
        break
if flag:
    print('{0} {1} {2}'.format(x,y,X-x-y))
else:
    print('-1 -1 -1')

Measured memory_bytes: 3064
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);

        Dice[] dice = new Dice[2];
        dice[0] = new Dice(br.readLine());
        dice[1] = new Dice(br.readLine());
        if(Compare.compare(dice[0],dice[1]) )System.out.println("Yes");
        else System.out.println("No");
    }
}


class Dice {
    public int[] plane = new int[6];
    int tmp = -1;

    public Dice(String all){
        String name[] = all.split(" ");
        for (int i=0; i<6; ++i) {
            plane[i] = Integer.parseInt(name[i]);
        }
    }

    public void east(){
      tmp = plane[0];
      plane[0] = plane[3];
      plane[3] = plane[5];
      plane[5] = plane[2];
      plane[2] = tmp;
    }

    public void north(){
      tmp = plane[0];
      plane[0] = plane[1];
      plane[1] = plane[5];
      plane[5] = plane[4];
      plane[4] = tmp;
    }

    public void south(){
      tmp = plane[0];
      plane[0] = plane[4];
      plane[4] = plane[5];
      plane[5] = plane[1];
      plane[1] = tmp;
    }

    public void west(){
      tmp = plane[0];
      plane[0] = plane[2];
      plane[2] = plane[5];
      plane[5] = plane[3];
      plane[3] = tmp;
    }

    public void spin(){
      tmp = plane[1];
      plane[1] = plane[2];
      plane[2] = plane[4];
      plane[4] = plane[3];
      plane[3] = tmp;
    }

}

class Compare {
    public static boolean compare(Dice d1, Dice d2){
        if(check(d1,d2)) return true;
        for (int i=0; i<3; ++i) {
            d2.spin();
            if(check(d1,d2)) return true;
        }
        d2.west();
        if(check(d1,d2)) return true;
        for (int i=0; i<3; ++i) {
            d2.spin();
            if(check(d1,d2)) return true;
        }
        d2.east();
        if(check(d1,d2)) return true;
        for (int i=0; i<3; ++i) {
            d2.spin();
            if(check(d1,d2)) return true;
        }
        d2.north();
        if(check(d1,d2)) return true;
        for (int i=0; i<3; ++i) {
            d2.spin();
            if(check(d1,d2)) return true;
        }
        d2.west();
        if(check(d1,d2)) return true;
        for (int i=0; i<3; ++i) {
            d2.spin();
            if(check(d1,d2)) return true;
        }
        d2.west();
        if(check(d1,d2)) return true;
        for (int i=0; i<3; ++i) {
            d2.spin();
            if(check(d1,d2)) return true;
        }

        return false;
    }
    public static boolean check(Dice d1, Dice d2){
        if(d1.plane[0] == d2.plane[0] && d1.plane[1] == d2.plane[1] && d1.plane[2] == d2.plane[2] && d1.plane[3] == d2.plane[3] && d1.plane[4] == d2.plane[4] && d1.plane[5] == d2.plane[5]){
                return true;
            }
            return false;
        }
}

Measured memory_bytes: 17100
#include<stdio.h>
#include<stdlib.h>

typedef struct{
    int num;
    int sum;
}strc;

int cmp(const void *a, const void *b){
    return ((strc*)a)->sum - ((strc*)b)->sum;
}

int asc(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
    int N, K;
    int A[210000];
    strc B[210000];
    int sum, num, ans=0;
    int i, j, k;
    int tmp;

    scanf("%d %d", &N, &K);
    for(i=0; i<N; i++){
        scanf("%d", &A[i]);
    }

    qsort(A, N, sizeof(int), asc);
    k=0;
    A[N]=0;
    num=A[0];
    sum=1;
    for(i=1; i<=N; i++){
        if(num!=A[i]){
            B[k].num = num;
            B[k].sum = sum;
            num = A[i];
            sum = 1;
            k++;
        }else{
            sum++;
        }
    }

    qsort(B, k, sizeof(strc), cmp);

    tmp = k-K;
    for(i=0; i<tmp; i++){
        ans += B[i].sum;
    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 3308
import java.util.Scanner;

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

        int[][] a = new int[2][n];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        int max = 0;
        int count = 0;
        for (int k = 0; k < n; k++) {
            for (int l = 0; l <= k; l++) {
                count += a[0][l];
            }
            for (int m = n-1; m >= k; m--) {
                count += a[1][m];
            }
            if (max < count) {
                max = count;
            }
            count = 0;
        }

        System.out.println(max);
    }
}

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

int main() {
  	int month1, month2, day1, day2;
  
  cin >> month1 >> day1 >> month2 >> day2;
  
  if (month1 == 12){
      if (month2 == 1){
       if (day1 ==31){
         cout << "1" << endl;
         return 0;
       }
      } else {
       cout << "0" << endl;
       return 0; 
      }
  }else if (month1 == 2){
    if(month1 == 2 && day1 == 28 && month2 == 3 && day2 == 1){
      cout << "1" << endl;
      return 0;
    } else {
      cout << "0" << endl;
      return 0;
    }
  }else if (month2 != month1 + 1){
      cout << '0' << endl;
      return 0;
  } else {
    if (month1 != 2 && month1 != 4 && month1 != 6 && month1 != 9 && month1 != 11){
      if (day1 == 31 && day2 == 1){
        cout << '1' << endl;
        return 0;
      }else {
        cout << "0" << endl;
        return 0;
      }
    } else {
      if (day1 ==30 && day2 == 1){
       cout << "1" << endl; 
        return 0;
      }else {
        cout << "0" << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> a(N), b(N), idx(N);
    iota(idx.begin(), idx.end(), 0);
    REP(i,N) cin >> a[i] >> b[i];
    sort(idx.begin(), idx.end(), [&](int x, int y){return a[x] + b[x] > a[y] + b[y];});
    ll ans = 0;
    REP(i,N){
        if(i % 2 == 0) ans += a[idx[i]];
        else ans -= b[idx[i]];
    }
    cout << ans << endl;
}

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

int main()
{
	int a, b, ans = 0;
	cin >> a >> b;
	for(int i = 1; i <= 1300; ++i)
	{
		int down = i * 0.08, up = i * 0.1;
		if(a == down && b == up)
		{
			ans = i;
			break;
		}
	}
	if(ans)
		cout << ans << endl;
	else 
		cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	bool ok=false;
	for(int i=0;i<=n/4;i++){
		for(int j=0;j<=n/7;j++){
			if(4*i+7*j==n)ok=true;
		}
	}
	if(ok){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (5000010)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
int n,c1,c2,c3,p,q,now,tar;
char s[N],str[N],w1,w2,w3;
vector<int> pos2; bool ban[N];
int gs(int x){
	if(s[x]==w1)return 1;else if(s[x]==w2)return 2;else return 3;
}
void getstr(int L,int R){
	if(L>R)return;
	int ch[4]={0,0,0,0};
	for(int i=L;i<=R;i++)ch[gs(i)]++;
	if(!ch[2]&&L>1&&R<n)q++,pos2.push_back(L-1);
	if(ch[2])p++; 
}
void del(){
	int tmp=0,lst=-1;
	for(int i=1;i<=n;i++)
	if(!ban[i]&&s[i]!=lst)lst=s[i],s[++tmp]=s[i];
	n=tmp;
}
void cal(){
	c1=c2=c3=0;
	for(int i=1;i<=n;i++)
	if(s[i]==w1)c1++;else if(s[i]==w2)c2++;else c3++;
	memset(ban,0,sizeof(ban));
}
void solve(int L,int R){
	if(L>R)return;
	if(L==R){
		if(L==1||L==n){if(s[L]==w3&&c3>c2)c3--,ban[L]=1;}
		return;
	}
	if(s[L]==w3&&c3>c2)c3--,ban[L]=1;
	if(s[R]==w3&&c3>c2)c3--,ban[R]=1;
}
void solve2(int L,int R){
	if(L>R)return;
	while(L<R&&now>tar){
		if(L+1>=R&&L!=1&&R!=n)break;
		now--,ban[L]=ban[L+1]=1,L+=2;
	}
}
int main(){
	scanf("%s",str+1),w1='A',w2='B',w3='C';
	for(int i=1;i<=strlen(str+1);i++)
	if(str[i]!=str[i-1]){
		s[++n]=str[i];
		if(s[n]==w1)c1++;else if(s[n]==w2)c2++;else c3++;
	}
	if(c1>c2)swap(c1,c2),swap(w1,w2);
	if(c1>c3)swap(c1,c3),swap(w1,w3);
	if(c2>c3)swap(c2,c3),swap(w2,w3);
	int j=0;
	for(int i=1;i<=n;i++)
	if(s[i]==w1)getstr(j+1,i-1),j=i; getstr(j+1,n);
	if(p<q)for(int i=0;i<q-p;i++)ban[pos2[i]]=1,c1--;
	del(),cal(),j=0;
	for(int i=1;i<=n;i++)
	if(s[i]==w1)solve(j+1,i-1),j=i; solve(j+1,n);
	del(),cal(),j=0,now=c2,tar=c1;
	for(int i=1;i<=n;i++)
	if(s[i]==w1)solve2(j+1,i-1),j=i; solve2(j+1,n);
	for(int i=1;i<=n;i++)
	if(!ban[i])printf("%c",s[i]);
}

Measured memory_bytes: 11896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
int n;
int a[1000005],b[1000005],c[1000005];

int main(){
	cin>>n;
	int x=0,y=0,maxh=(1<<30),h=0;
	int flag=0;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			h=-1;
			int flag=0;
			for(int z=0;z<n;z++){
				int k=abs(i-a[z])+abs(j-b[z])+c[z];
				if(h==-1){
					h=k;
					continue;
				}
				if(c[z]==0){
					if(flag==0){
						h=min(h,k);
					}else{
						if(h>k){
							h=-1;
							break;
						}
					}
				}else{
					if(flag==0){
						if(h<k){
							h=-1;
							break;
						}
						h=k;
					}else{
						if(h!=k){
							h=-1;
							break;
						}
					}
					flag=1;
				}
			}
			if(h>0){
				cout<<i<<" "<<j<<" "<<h<<endl;
				return 0;
			}
			
		}
	}
	return 0;
}
//

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

int main()
{
    int n; cin>>n;
    vector<int> a(n); for(auto& e: a) cin>>e;

    int res=1, i;
    for(i=0; i+1<n && a[i+1]==a[i]; ++i);
    bool inc=a[i+1]>a[i];
    for(int i=1; i<n; ++i) {
        if (a[i]==a[i-1]) continue;
        if ((a[i]>a[i-1])==inc) continue;
        ++res;
        while (i+1<n && a[i+1]==a[i]) ++i;
        inc=a[i+1]>a[i];
    }
    cout<<res<<endl;
}

Measured memory_bytes: 640
z = list(map(int, input().split()))
n = z[0]#人数
k = z[1]#最初のポイント
q = z[2]#問題の数

a = []#n人のゼッケン番号は引数+1
p = []#ポイント
for i in range(q):
	a.append(int(input()))

	
for i in range(n):
	p.append(k-q)


for i in range(q):
	p[ a[i]-1 ] += 1

for i in range(n):
	if p[i] > 0:
		print('Yes')
	else:
		print('No')


Measured memory_bytes: 11772
using System;
using System.Linq;

class C{
  public static void Main(){
    int[] inp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    int M = inp[1];
    int[] L = new int[M];
    int[] R = new int[M];
    int[] Te = new int[2];
    for (int i = 0; i < M; i++){
      Te = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
      L[i] = Te[0];
      R[i] = Te[1];
    }
    int ans = R.Min() - L.Max();
    if (ans >= 0) ans++;
    else ans = 0;
    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 22912
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
const int N=3005;
int n,m,nr,nc;
unordered_map<int,int>fr,fc;
ll ans,A[N],B[N],C[N],D[N],E[N],F[N],r[N],c[N],a[N][N];
bool vis1[N][N],vis2[N][N],vis[N][N];
ll area(int i,int j)
{
    return (r[i+1]-r[i])*(c[j+1]-c[j]);
}
bool up(int i,int j)
{
    return !vis2[i][j];
}
bool down(int i,int j)
{
    return !vis2[i+1][j];
}
bool left(int i,int j)
{
    return !vis1[i][j];
}
bool right(int i,int j)
{
    return !vis1[i][j+1];
}
void add(ll x)
{
    if(x==inf||ans+x>=inf)
    {
        printf("INF\n");exit(0);
    }
    ans+=x;
}
bool count0(int i,int j)
{
    return r[i]<=0&&r[i+1]>=0&&c[j]<=0&&c[j+1]>=0;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%lld%lld%lld",&A[i],&B[i],&C[i]),r[++nr]=A[i],r[++nr]=B[i],c[++nc]=C[i];
    for(int i=1;i<=m;i++) scanf("%lld%lld%lld",&D[i],&E[i],&F[i]),c[++nc]=F[i],c[++nc]=E[i],r[++nr]=D[i];
    sort(r+1,r+1+nr);
    sort(c+1,c+1+nc);
    nr=unique(r+1,r+1+nr)-r-1;
    nc=unique(c+1,c+1+nc)-c-1;
    for(int i=1;i<=nr;i++) fr[r[i]]=i;
    for(int i=1;i<=nc;i++) fc[c[i]]=i;
    for(int i=1;i<=n;i++)
    {
        int l=fr[A[i]],r=fr[B[i]],x=fc[C[i]];
        for(int j=l;j<r;j++)
            vis1[j][x]=true;
    }
    for(int i=1;i<=m;i++)
    {
        int l=fc[E[i]],r=fc[F[i]],x=fr[D[i]];
        for(int j=l;j<r;j++)
            vis2[x][j]=true;
    }
    queue<pair<int,int>>q;
    bool flag=false;
    for(int i=1;i<nr;i++)
        for(int j=1;j<nc;j++)
    {
        a[i][j]=area(i,j);
        if(up(i,j)&&i==1||down(i,j)&&i==nr-1||left(i,j)&&j==1||right(i,j)&&j==nc-1)
            a[i][j]=inf;
        if(count0(i,j))
        {
            flag=true;
            add(a[i][j]);
            q.push({i,j});
            vis[i][j]=true;
        }
    }
    if(!flag) add(inf);
    while(!q.empty())
    {
        int i=q.front().first,j=q.front().second;q.pop();
        if(up(i,j)&&!vis[i-1][j])
        {
            add(a[i-1][j]);
            vis[i-1][j]=true;
            q.push({i-1,j});
        }
        if(down(i,j)&&!vis[i+1][j])
        {
            add(a[i+1][j]);
            vis[i+1][j]=true;
            q.push({i+1,j});
        }
        if(left(i,j)&&!vis[i][j-1])
        {
            add(a[i][j-1]);
            vis[i][j-1]=true;
            q.push({i,j-1});
        }
        if(right(i,j)&&!vis[i][j+1])
        {
            add(a[i][j+1]);
            vis[i][j+1]=true;
            q.push({i,j+1});
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 97616
N,M = map(int,input().split())
A= set(int(input()) for _ in [0]*M)
mod = 10**9+7
dp = [0]*(N+1)
dp[0] = 1
for i in range(1,N+1):
    dp[i] = (dp[i-1]+dp[i-2])%mod
    if i in A:dp[i]=0
print(dp[N])

Measured memory_bytes: 12652
#include <iostream>

using namespace std;

int main()
{
    int a, b,c ;
    cin >> a>>b>>c;
    int w=a+b;
    int e=b+c;
    int r =a+c ;
    if (w<=r &&w<=e)
        cout << w;
    else if (e<=w&&e<=r)
    cout <<e;
    else if (r<=e &&r<=w)
        cout << r;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String argv[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int a[]=new int[M];
        for(int i=0; i<M; i++){
            a[i]=sc.nextInt();
        }

        int res=0;
        int count=0;
        int plc = X;
        for(int i=0; i<X; i++){
            plc--;
            for(int j=0; j<M; j++){
                if(plc==a[j]){
                    count++;
                    break;
                }
            }
        }
        res = count;
        
        count=0;
        plc=X;
        for(int i=0; i<N-X; i++){
            plc++;
            for(int j=0; j<M; j++){
                if(plc==a[j]){
                    count++;
                    break;
                }
            }
        }

        System.out.println(Math.min(res, count));

        


    }
}

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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0 or i % 5 == 0) continue;
		ans += i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

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

    string s;
    cin >> s;

    ll mx = 0;
    queue<ll> q;
    q.push(0);
    for (ll i = 0; i < n; i++)
    {
        //0から1に変わるiをpush
        while (i < n && s[i] == '0')
        {
            i++;
        }
        if (i != 0)
        {
            q.push(i);
        }

        //1から0に変わるiについて、最大値を確認
        while (i < n && s[i] == '1')
        {
            i++;
        }
        if (q.size() > k + 1)
        {
            //k回しか処理できないので、先頭を捨てる
            q.pop();
        }
        ll first = q.front();
        ll length = i - first;
        mx = max(length, mx);
    }

    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 640