akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

#define N 123456*2+1

char prime[N];

void make(){

  for(int i = 0; i < N; i++) prime[i] = '1';
  prime[0] = '0';
  prime[1] = '0';

  for(int i = 2; i*i < N; i++){
    if(prime[i] == '1'){
      for(int j = i*2; j < N; j+=i){
	prime[j] = '0';
      }
    }
  }

}

int main(){

  make();

  int in;

  while(cin >> in){
    if(in == 0) break;

    int sum = 0;

    for(int i = in+1; i <= in*2; i++){
      if(prime[i] == '1') sum++;
    }

    cout << sum << endl;

  }

  return 0;
}

Measured memory_bytes: 0
N=int(input())
S=input()
    
for i in range(4):
  ans=[0]*N
  if i==0:
    ans[-1]="S"
    ans[0]="S"
  elif i==1:
    ans[-1]="S"
    ans[0]="W"
  elif i==2:
    ans[-1]="W"
    ans[0]="S"
  else:
    ans[-1]="W"
    ans[0]="W"
  
  for j,s in enumerate(S):
    if j!=N-1 and j!=N-2:
      if ans[j]=="S":
        if s=="o":
          ans[j+1]=ans[j-1]
        else:
          if ans[j-1]=="S":
            ans[j+1]="W"
          else:
            ans[j+1]="S"
      else:
        if s=="x":
          ans[j+1]=ans[j-1]
        else:
          if ans[j-1]=="S":
            ans[j+1]="W"
          else:
            ans[j+1]="S"
    elif j==N-2:
      flag=0
      if ans[N-2]=="S":
        if s=="o":
          if ans[N-1]==ans[N-3]:
            flag=1
        else:
          if ans[N-1]!=ans[N-3]:
            flag=1
      else:
        if s=="x":
          if ans[N-1]==ans[N-3]:
            flag=1
        else:
          if ans[N-1]!=ans[N-3]:
            flag=1
    elif flag:  
      if ans[N-1]=="S":
        if s=="o":
          if ans[N-2]==ans[0]:
            print("".join(ans));exit()
        else:
          if ans[N-2]!=ans[0]:
            print("".join(ans));exit()
      else:
        if s=="x":
          if ans[N-2]==ans[0]:
            print("".join(ans));exit()
        else:
          if ans[N-2]!=ans[0]:
            print("".join(ans));exit()
print(-1)
      
    


Measured memory_bytes: 5076
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// chrono::steady_clock sc;
 //  	auto start = sc.now();
 //  	ifstream cin;
 //  	cin.open("INPUT.txt");

	long long int A,B;
	cin>>A>>B;
	long long int x,y;
	if(B%4==0)
	{
		x=B;
	}
	else if(B%4==1)
	{
		x=1;
	}
	else if(B%4==2)
	{
		x=B+1;
	}
	else if(B%4==3)
	{
		x=0;
	}
	if(A-1>=0)
	{
		if((A-1)%4==0)
		{
			y=A-1;
		}
		else if((A-1)%4==1)
		{
			y=1;
		}
		else if((A-1)%4==2)
		{
			y=A;
		}
		else if((A-1)%4==3)
		{
			y=0;
		}
	}
	else
	{
		y=0;
	}
	long long int ans=x^y;
	cout<<ans<<endl;
	
	// cin.close();
	// auto end = sc.now();
 //   	auto time_span = static_cast<chrono::duration<double>>(end - start);
 //   	cout<<"Operation took: "<<time_span.count()<<" seconds";

	return 0;
}

Measured memory_bytes: 256
module Main where
--import Debug.Trace
import Data.List
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: [Int]-> [[Int]] -> [[Int]] -> [[Int]]
solve [n, m, l] anm bml = iterR 0 where
    iterR r
        | r >= n    = []
        | otherwise = iterC 0 : iterR (r+1) where
            iterC c
                | c >= l = []
                | otherwise = prod 0 : iterC (c+1) where
                    prod x
                        | x >= m = 0
                        | otherwise = aij ! (r, x) * bij ! (x, c) + prod (x+1)
    aij = listArray ((0,0),(n-1,m-1)) (concat anm)
    bij = listArray ((0,0),(m-1,l-1)) (concat bml)

readLine:: IO [Int]
readLine = fmap (map read . words) getLine

readUntil :: ([Int] -> Bool) -> IO [[Int]]
readUntil eof = iter where
    iter = readLine >>=
            (\a -> if eof a then return [] else fmap (a:) iter)

readLines :: Int -> IO [[Int]]
readLines 0 = return []
readLines n = readLine >>= (\a -> fmap (a:) (readLines (pred n)))
            
eof :: [Int] -> Bool
eof (x0:x1:xs) = all (==0) [x0, x1]

main :: IO() 
main = do
    [n, m, l] <- readLine
    anm  <- readLines n
    bml  <- readLines m
    mapM_ putStrLn $ map (\y -> init (concatMap (\x-> show x ++ " ") y)) (solve [n, m, l] anm bml)



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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vi v(3);
	REP(i, 3)cin >> v[i];
	int ret = INF;
	sort(ALL(v));
	do {
		int ans = 0;
		ans += abs(v[2] - v[1]);
		ans += abs(v[1] - v[0]);
		ret = min(ret, ans);
	} while (next_permutation(ALL(v)));
	cout << ret << endl;
}

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

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

    static class E {
        public void solve(int testNumber, InputReader sc, PrintWriter out) {
            int n = sc.nextInt();
            int a[] = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                a[i] = sc.nextInt();
            }
            HashSet<Long> set1 = new HashSet<>();
            HashMap<Long, Integer> map = new HashMap<>();
            for (int i = 1; i <= n; i++) {
                long sum = a[i] + i;
                set1.add(sum);
                if (map.containsKey(sum)) {
                    map.put(sum, map.get(sum) + 1);
                } else
                    map.put(sum, 1);
            }
            long count = 0;
            for (int i = 1; i <= n; i++) {
                long diff = i - a[i];
                if (set1.contains(diff)) {
                    count += map.get(diff);
                }
                // if(set1.contains(-diff)){
                //   count+=map.get(-diff);
                //}
            }
            out.println(count);
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 80224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    string s; cin >> s;
    if(s == "ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }

}

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

using namespace std;

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

	int n;
	cin >> n;
	int cnt[4]={0};
	for(int i=0; i<n; i++){
        string str;
        cin >> str;
        if(str=="AC")
            cnt[0]++;
        else if(str=="WA")
            cnt[1]++;
        else if(str=="TLE")
            cnt[2]++;
        else if(str=="RE")
            cnt[3]++;
	}
	cout << "AC x " << cnt[0] << endl;
    cout << "WA x " << cnt[1] << endl;
    cout << "TLE x " << cnt[2] << endl;
    cout << "RE x " << cnt[3] << endl;

	return 0;
}


Measured memory_bytes: 3620
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] t = new long[n + 1];
    long[] a = new long[n + 1];
    t[0] = 1;
    a[0] = 1;
    for(int i = 1; i <= n; i++) {
      long T = sc.nextLong();
      long A = sc.nextLong();
      long i1 = (t[i - 1] + T - 1) / T;
      long i2 = (a[i - 1] + A - 1) / A;
      long ii = Math.max(i1, i2);
      t[i] = T * ii;
      a[i] = A * ii; 
    }
    System.out.println(t[n] + a[n]);
  }
}

Measured memory_bytes: 39544
s=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
h=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
c=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
d=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
n=gets.to_i
n.times do
  a,b=gets.split
  b=b.to_i
  s[b]=0 if a=='S'
  h[b]=0 if a=='H'
  c[b]=0 if a=='C'
  d[b]=0 if a=='D'
end
for i in 1..13
  puts 'S '+i.to_s if s[i]>0
end
for i in 1..13
  puts 'H '+i.to_s if h[i]>0
end
for i in 1..13
  puts 'C '+i.to_s if c[i]>0
end
for i in 1..13
  puts 'D '+i.to_s if d[i]>0
end


Measured memory_bytes: 6876
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 998244353;

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

signed main(){
  int N;
  cin >> N;
  
  vector<int> cnt(N+1);
  for( int i = 0; i < N; i++ ){
    int A;
    cin >> A;
    if( i == 0 && A != 0 ){
      cout << 0 << endl;
      return 0;
    }
    cnt.at(A)++;
  }
  
  int ans;
  //途中で0が出てきたらtrue
  bool z = 0;
  for( int i = 0; i <= N; i++ ){
    if( i == 0 ){ //根
      if( cnt.at(0) != 1 ){
        cout << 0 << endl;
        return 0;
      }
      ans = 1;
    }else{
      if( cnt.at(i) == 0 ) z = 1;
      else{
        if( z ){
          cout << 0 << endl;
          return 0;
        }
        int B = modpow(cnt.at(i-1), cnt.at(i), MOD);
        ans = ans*B%MOD;
      }
    }
  }
  cout << ans << endl;
  
  
}

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

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

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
vector<pair<ll, int>> factorize(ll n)
{
    vector<pair<ll, int>> res;
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i)
            continue;
        res.emplace_back(i, 0);
        while (n % i == 0)
        {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1)
        res.emplace_back(n, 1);
    return res;
}

int main(void)
{
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		int x, ans = 0;
		for (int i = 1; i <= n; i++) {
			x = i / 10000 + i % 10000 / 1000 + i % 1000 / 100 + i % 100 / 10 + i % 10;
			if (x >= a && b >= x) {
				ans += i;
			}
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 27044
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string N;
    cin >> N;
    int sum=0;
    if(N[0]==N[1]&&N[1]==N[2]){
        cout << "Yes" << endl;
        return 0;
    }
    if(N[1]==N[2]&&N[2]==N[3]){
        cout << "Yes" << endl;
        return 0;
        
    }
    if(N[2]==N[3]&&N[3]==N[4]){
        cout << "Yes" << endl;
    }
    else { cout << "No" << endl;}
    return 0;
    // Your code here!
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using v  = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

const ll INF = 1001001001001;

int main(){
    ll n;cin>>n;
    
    if(n==1){
        cout << 0 << endl;
        return 0;
    }
    
    v a;
    
    for(ll i=2; i*i<=n; i++){
        if(n%i==0){
            a.push_back(0);
            while(n%i==0){
                a[a.size()-1]++;
                n /= i;
            }
        }
    }
    if(n!=1){
        a.push_back(1);
    }
    
    int ans = 0;
    
    for(int i=0; i<a.size(); i++){
        double t = (sqrt(8*a[i]+1)-1)/2.0;
        ans += (int)t;
    }
    
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3724
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <string_view>
#include <vector>

#include <cmath>
#include <cctype>

int main() {
  std::string s, t;
  std::cin >> s >> t;

  int cnt = 0;

  for (std::size_t i = 0; i < s.size(); ++i) {
    if (s[i] != t[i]) {
      ++cnt;
    }
  }

  std::cout << cnt << '\n';
}


Measured memory_bytes: 3928
N, K = gets.chomp.split(" ").map(&:to_i)
S = gets.chomp

h = []
h << [0, 0] if S[0] == '0'
wk, flg = [0, false]
(0...N).each{|i|
  (wk = i; flg = true) if (not flg) && S[i] == '1'
  (h << [wk, i - 1]; flg = false) if flg && S[i] == '0'
}
flg ? (h << [wk, N - 1]) : (h << [N - 1, N - 1])
ans = []
(0...(h.size - K)).each{|i|
  ans << (h[i+K][1] - h[i][0] + 1)
}
ans << N if ans.empty?

puts ans.max


Measured memory_bytes: 6648
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)
#define INF 1000000000
#define pow10 tipa_pow10
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
int q , a , b;
ll score;
ll f(int idx , int x)
{
    ll L = idx;
    ll R = x - idx + 1;
    if(R >= b)
        R++;
    if(L >= a)
        L++;
    return L * R;
}
bool good(int x)
{
    int l = 1 , r = x;
   while (r - l >= 3) {
        int m1 = l + (r - l) / 3;
        int m2 = r - (r - l) / 3;
        if (f (m1 , x) < f (m2 , x))
            l = m1;
        else
            r = m2;
    }
    for(int i = l; i <= r; i++)
    {
        if(f(i , x) >= score)
            return false;
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> q;
    while(q--)
    {
        cin >> a >> b;
        score = (ll)a * b;
        int ans =  0;
        for(int i = 30; i >= 0; i--)
        {
            if(good(ans + (1 << i)))
                ans += (1 << i);
        }
        cout << ans << endl;
    }


}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>

using namespace std;

struct Store{
        int listnum;
        string city;
        int point;
    };

bool comp(const Store& a, const Store& b){
    if(a.city!=b.city){
        return a.city<b.city;
    }else{
        return a.point>b.point;
    }
};


int main(){
    int N;
    cin>>N;
    vector<Store> p(N);
    for(int i=0;i<N;i++){
        string S;
        int P;
        cin>>S;
        scanf("%d",&P);
        p[i]={i+1,S,P};
    }
    
    sort(p.begin(),p.end(),comp);

    for(int i=0;i<N;i++){
        cout<<p[i].listnum<<endl;
    }
}

Measured memory_bytes: 256
# ABC113C - ID
def main():
    N, M, *PY = map(int, open(0).read().split())
    P = [[] for _ in range(N + 1)]  # prefectures
    # classify cities by prefectures
    for num, (pref, year) in enumerate(zip(*[iter(PY)] * 2)):
        P[pref] += [(year, num)]
    ans = [[] for _ in range(M)]
    P = [sorted(p) for p in P]  # sort by year
    for pref_idx, pref in enumerate(P):
        for city_idx, (_, num) in enumerate(pref, 1):
            x = "{:06}{:06}".format(pref_idx, city_idx)
            ans[num] = x
    print("\n".join(map(str, ans)))

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 51420
import java.util.Scanner;



class Main{

	public static void main(String[] args) {



		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		String S = scan.next();

		int[] wBefore = new int[N];
		for(int i = 1;i < N;i++){
			if(S.charAt(i-1) == 'W'){
				wBefore[i] += wBefore[i-1] + 1;
			}else{
				wBefore[i ] = wBefore[i -1];
			}
		}

		int[] eafter = new int[N];
		for(int i=S.length()-2; i >= 0; i--){
			if(S.charAt(i+1) =='E'){
				eafter[i] += eafter[i+1] + 1;
			}else{
				eafter[i] = eafter[i+1];
			}
			
		}
		
		
		int min =Integer.MAX_VALUE;
		for(int i = 0; i < S.length();i++){
			min = Math.min(min, wBefore[i]+eafter[i]);
		}
		
		
		System.out.println(min);





	}
}








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

int m, d, g, n;
bool change[105][105];
string r;
bool goal(){
    int now = m - 1;
    for(int i = 0;i < d;i++){
	if(change[i][now - 1]){
	    now--;
	}
	else if(change[i][now]){
	    now++;
	}
    }
    return now == g - 1;
}

int main(){
    while(cin >> n, n){
	cin >> m >> g >> d;
	for(int i = 0;i < d;i++){
	    cin >> r;
	    for(int j = 0;j < n - 1;j++){
		change[i][j] = r[j] == '1';
		change[i][j + 1] = false;
	    }
	}
	if(goal()){
	    cout << 0 << endl;
	    continue;
	}
	bool ok = false;
	for(int i = 0;i < d && !ok;i++){
	    for(int j = 0;j < n - 1 && !ok;j++){
		if((j == 0 || !change[i][j - 1]) && !change[i][j + 1] && !change[i][j]){
		    change[i][j] = true;
		    if(goal()){
			ok = true;
			cout << i + 1 << " " << j + 1 << endl;
		    }
		    change[i][j] = false;
		}
	    }
	}
	if(!ok){
	    cout << 1 << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 1208
n = gets.to_i
a = gets.split(" ").map(&:to_i).sort.reverse
if a.include?(0)
  puts 0
  exit
end
sum = 1
lm = 10**18
n.times{ |i|
  sum *= a[i]
  if sum > lm
    puts -1
    exit
  end
}
puts sum

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    int even=0;
    rep(i,n){
        cin>>a[i];
        if(a[i]%2==0) even++;
    }
    int p=1;
    rep(i,n){
        p*=3;
    }
    if(even==0) cout<<p-1<<"\n";
    else cout<<p-pow(2,even)<<"\n";
    return 0;
}

Measured memory_bytes: 4240
//package atcoder;
 
import java.util.*;
//import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N  =sc.nextInt();
		int P[] = new int[N];
		for(int i=0;i<N;i++) {
			P[i] = sc.nextInt();
		}
		int ok = Integer.MAX_VALUE;
		int count = 0;
		for(int j=0;j<N;j++) {
			ok = Math.min(ok,P[j]);
			if(ok==P[j]) {
				count ++;
			}
		}
		System.out.println(count);

			
	}
}

Measured memory_bytes: 66076
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
const int INF = 1e9;
const int MOD = 1e9+7;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N; cin >> N;
    vl A(N); REP(i, N) cin >> A[i];
    sort(ALL(A));

    ll ans = 0;

    if(N % 2 == 0)
    {
        ll sum = 0;
        REP(i, N/2) sum -= 2*A[i];
        sum += A[N/2-1];
        sum -= A[N/2];
        for(int i = N/2; i < N; i++) sum += 2*A[i];
        ans = max(ans, sum);
    }
    else
    {
        ll sum = 0;
        REP(i, N/2) sum -= 2*A[i];
        sum -= A[N/2];
        sum -= A[N/2+1];
        for(int i = N/2; i < N; i++) sum += 2*A[i];
        ans = max(ans, sum);

        sum = 0;
        reverse(ALL(A));
        REP(i, N/2) sum += 2*A[i];
        sum += A[N/2];
        sum += A[N/2+1];
        for(int i = N/2; i < N; i++) sum -= 2*A[i];
        ans = max(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cmath>
#include<array>
#include<algorithm>
#include<queue>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
#include<bitset>
#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x, y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x, LLI y) {
//	return x / gcd(x, y) * y;
//}

//long nCr(int n, int r) {
//	long ans = 1;
//	for (int i = n; i > n - r; i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; i++) {
//		ans = ans / i;
//	}
//	return ans;
//}
//long nHr(int n,int r) {
//	n = n + r - 1;
//	return nCr(n,r);
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	double W, H, x, y;
	cin >> W >> H >> x >> y;
	double res = (W * H) / 2;
	if (W / 2 == x && H / 2 == y) {
		cout << res << endl;
		cout << 1 << endl;
	}
	else {
		cout << res << endl;
		cout << 0 << endl;
	}
}


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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    ll N; cin >>N;
    vector<int> d(N);
    ll sum = 0;
    ll sq_sum = 0;
    rep(i, N) {
        ll d; cin >> d;
        sum += d;
        sq_sum += d*d;
    }
    ll ans = (sum * sum - sq_sum) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#N = gets.to_i               # 単一整数
#a = gets.split.map(&:to_i)  # スペースで区切られた複数の整数
#a = N.times.map{gets.to_i}  # 縦に並んだ複数の整数。たまにある
#S = gets.chomp              # 文字列。chompを付けないと改行文字がついてくる

def solve168A(n)
  last_n = n % 10
  if last_n == 3
    puts ('bon')
  elsif last_n == 2 or last_n == 4 \
    or last_n == 5 or last_n == 7 or last_n == 9
    puts ('hon')
  else
    puts ('pon')
  end
end

def soleve168B(k,s)
  if s.length > k 
    first_x_char = s[0..k-1]
    puts (first_x_char + '...')
  else
    puts (s)
  end
end

=begin
N = gets.to_i
solve168A(N)
=end

K = gets.to_i
S = gets.chomp
soleve168B(K,S)

Measured memory_bytes: 14248
void main() {
  problem();
}

void problem() {
  auto N = scan!int;
  
  int countF(int n) {
    int c;
    foreach(x; 1..101) {
      auto tx = x^^2;
      if (tx > n) break;
      foreach(y; x..101) {
        auto ty = tx + y^^2 + x*y;
        if (ty > n) break;
      
        foreach(z; y..101) {
          auto t = ty + z^^2 + y*z + z*x;
          if (t > n) break;
          if (t == n) {
            if (x == y && y == z) {
              c++;
              continue;
            }
            if (x != y && y != z) {
              c += 6;
              continue;
            }
            c += 3;
          }
        }
      }
    }
    return c;
  }

  void solve() {
    foreach(i; 1..N+1) {
      countF(i).writeln;
    }
  }

  solve();
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


Measured memory_bytes: 2720
#include<cstdio>
#include<cstring>

int main()
{
    int a[1000],n;
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        int l = 0;
        while(n--) scanf("%d",&a[l++]);
        int i,j;
        for(i=0;i<l;i++)
        {
            for(j=0;j<i;j++)
            {
                if(a[j]>a[i])
                {
                    int temp;
                    temp = a[j];
                    a[j] = a[i];
                    a[i] = temp;
                }
            }
            for(j=0;j<l;j++) printf("%d%c",a[j],(j==l-1)?'\n':' ');
        }
    }
    return 0;
}

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

int main(){
  ll k,now=0,ans=0;
  cin>>k;
  if(k%2==0 || k%5==0){cout<<-1<<endl;return 0;}
  else{
    for(int i=0;i<=k;i++){
      now*=10;
      now+=7;
      ans++;
      now%=k;
      if(now==0){cout<<ans<<endl;return 0;}
    }
  }
  cout<<-1<<endl;
}


Measured memory_bytes: 3632
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 4;

int n, a[N], l[N], r[N];

void prepare() {
    vector<pii> s = {pii(0, 0)};
    for (int i = 1; i <= n; ++i) {
        while (s.back().second > a[i]) {
            s.pop_back();
        }
        l[i] = s.back().first;
        s.em_back(i, a[i]);
    }

    s = {pii(n + 1, 0)};
    for (int i = n; i > 0; --i) {
        while (s.back().second > a[i]) {
            s.pop_back();
        }
        r[i] = s.back().first;
        s.em_back(i, a[i]);
    }
}

void calc() {
    ll res = 0;
    for (int i = 1; i <= n; ++i) {
        res += (ll)a[i] * (i - l[i]) * (r[i] - i);
    }
    cout << res << "\n";
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    prepare();
    calc();
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 7452
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;


namespace AtCoder{

class Program{

static void Main(string[] args){

//int x = int.Parse(Console.ReadLine());
var s = Console.ReadLine().ToCharArray().Select(x => int.Parse(x.ToString())).ToArray();
int abs = 753;
for(int i = 0;i < s.Length - 2;i++){

int num = s[i]*100 + s[i+1]*10 + s[i+2];

if(abs > Math.Abs(753 - num)){

abs = Math.Abs(753 - num);

}

}
Console.WriteLine(abs);
}
}
}

Measured memory_bytes: 13396
#include <stdio.h>
int main(void){
    int r,g,b,a,ans;
    char buf[256];
    scanf("%d%d%d",&r,&g,&b);
    sprintf(buf,"%d%d",g,b);
    sscanf(buf,"%d",&a) ;
    if(a%4 == 0 || b == 0){
        printf("YES");
    }else{
        printf("NO");
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define md 1000000007
using namespace std;
int main() {
    string a,b;
    ll bf = -1,nt,n;
    ll ans = 1;
    cin>>n;
    cin>>a;
    cin>>b;
    int l = a.length();
    for (int i = 0;i<l;i++) {
        if (a[i] == a[i - 1])continue;
        else if (a[i] == b[i]) {
            nt = 1;
            if (bf == 1)ans = (ans * 2)%md;
            else if (bf == -1)ans = 3;
            bf = nt;
        }
        else if (a[i] == a[i + 1]) {
            nt = 2;
            if (bf == 1)ans = (ans * 2)%md;
            else if (bf == 2)ans = (ans * 3)%md;
            else ans = 6;
            bf = nt;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e7
#define mod 1000000007

using namespace std;
typedef long long int ll;
typedef tuple<int,int,int> tii;
typedef tuple<long long int,long long int,long long int> tll;
typedef tuple<double,double,double> tdd;


int main()
{
    ll N; cin >> N;
    vector<vector<ll>>dp(N+1,vector<ll>(1<<2,0));
    dp[0][0] = 1;
    for(int i = 1; i <= N; i++)
    {
        for(int bit = 0; bit < (1<<2); bit++)
        {
            if(bit == 0)
            {
                dp[i][bit] = dp[i-1][bit]*8;
                dp[i][bit] %= mod;
            }
            else if(bit == 1<<0)
            {
                dp[i][bit] = dp[i-1][0] + dp[i-1][bit]*9;
                dp[i][bit] %= mod;
            }
            else if(bit == 1<<1)
            {
                dp[i][bit] = dp[i-1][0] + dp[i-1][bit]*9;
                dp[i][bit] %= mod;
            }
            else
            {
                dp[i][bit] = dp[i-1][1<<1] + dp[i-1][1<<0] + dp[i-1][bit]*10;
                dp[i][bit] %= mod;
            }
        }
    }
    cout << dp[N][(1<<0)+(1<<1)] << endl;
}

Measured memory_bytes: 73328
#include <stdio.h>
int main() {
    int a, b, d, r;
    double f;
    
    scanf("%d%d", &a, &b);
    
    d = a / b;
    r = a % b;
    f = (double)a / b;
    
    printf("%d %d %f\n", d, r, f);
    
    return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> a(n);
	for (int x = 1; x <= 100; ++x) {
		for (int y = 1; y <= 100; ++y) {
			for (int z = 1; z <= 100; ++z) {
				int res = x*x+y*y+z*z+x*y+x*z+y*z;
				if (res <= n) ++a[res-1]; 
			}
		}
	}
	for (int x:a) cout << x << "\n";
}


Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 300300;
int n, k;
int a[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &k, &n);
	
	if (k % 2 == 0) {
		printf("%d", k / 2);
		for (int i = 1; i < n; i++)
			printf(" %d", k);
		printf("\n");
		return 0;
	}

	for (int i = 0; i < n; i++)
		a[i] = (k + 1) / 2;
	int s = n / 2;
	int L = n;
	while(s--) {
		if (a[L - 1] == 1) {
			L--;
			continue;
		}
		a[L - 1]--;
		while(L < n)
			a[L++] = k;
	}
	for (int i = 0; i < L; i++)
		printf("%d ", a[i]);
	printf("\n");

	return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


int main() {
	int a;
	int N,M=0,sum=0; cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		if (a > M) M = a;
		sum += a;
		
	}
	//cout << M;
	if (sum-M > M) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}


	return 0;
}

Measured memory_bytes: 256
// Aizu Vol-10 1008: What Color Is The Universe?
// 2017.8.19 bal4u@uu

#include <stdio.h>
#include <string.h>

#define HASHSIZ 99991 // 199999  299993
typedef struct { int n, c; } HASH;
HASH hash[HASHSIZ + 5], *hashend = hash + HASHSIZ;

int color, cnt;

int lookup(int n)
{
	HASH *p = hash + n % HASHSIZ;
	while (p->n) {
		if (p->n == n) return ++(p->c);
		if (++p == hashend) p = hash;
	}
	p->n = n, p->c = 1;
	return 1;
}

int main()
{
	int n, i, k;

	while (scanf("%d", &n) && n) {
		memset(hash, 0, sizeof(hash)), cnt = 1;
		for (i = 0; i < n; i++) {
			scanf("%d", &k);
			if (lookup(k) == cnt) cnt++, color = k;
		}
		if (--cnt > n / 2) printf("%d\n", color);
		else puts("NO COLOR");
	}
	return 0;
}

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

int main(){
	int A, B, C, X;
  	cin >> A >> B >> C >> X;
  	int res = 0;
  	for(int a = 0; a <= A; ++a){
    	for(int b = 0; b <= B; ++b){
        	for(int c = 0; c <= C; ++c){
            	int total = 500 * a + 100 * b + 50 * c;
              	if(total == X) ++res;
            }
        }
    }
  	cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
// id: ALDS1_1_2_A
#include <iostream>

using std::cin;
using std::cout;
using std::endl;
using std::swap;

static const int MAX_N = 100;

int bubble_sort(int a[], int n);

int main()
{
	int arr[MAX_N];
	int n;
	int swap_times = 0;

	cin >> n;
	for ( int i = 0; i < n; ++i )
		cin >> arr[i];

	swap_times = bubble_sort(arr, n);

	cout << arr[0];
	for ( int i = 1; i < n; ++i )
		cout << " " << arr[i];
	cout << endl;

	cout << swap_times << endl;

	return 0;
}

int bubble_sort(int a[], int n)
{
	int cnt = 0;
	bool flag = true;
	int i = 0;

	while ( flag ) {
		flag = false;

		for ( int j = n - 1; j > i; --j )
			if ( a[j] < a[j - 1] ) {
				swap(a[j - 1], a[j]);
				++cnt;
				flag = true;
			}

		++i;
	}

	return cnt;
}


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

int main()
{
	vector<int> A,A1;
	int N;
	cin >> N;
	int t;
	int a;
	for (t = 0; t < N; t++) {
		cin >> a;
		A.push_back(a);
		A1.push_back(a);
	}
	sort(A.begin(), A.end());
	for (t = 0; t < N; t++) {
		if (A1[t] == A[N - 1]) {
			cout << A[N - 2]<<endl;
		}
		else
			cout << A[N - 1]<<endl;
	}
		return 0;
}

Measured memory_bytes: 3436
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 0;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int h, w, n;
vector<int>a[300000];
signed main() {
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++) {
		int u = read(), v = read();
		a[v].push_back(u);
	}
	for (int i = 1; i <= h; i++) {
		sort(all(a[i]));
	}
	int t = 1, ans = Inf;
	for (int i = 1; i <= w; i++) {
		int k = lower_bound(all(a[i]), t) - a[i].begin();
		//今の居場所がt、ぶつかる場所はk
		if (k == a[i].size()) {
			ans = min(ans, h);
		}
		else {
			ans = min(ans, a[i][k] - 1);
		}
		t++;
		k = lower_bound(all(a[i + 1]), t) - a[i + 1].begin();
		while (k < a[i + 1].size() && a[i + 1][k] == t) {
			k++;
			t++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
int ss[100005];
void ini()
{
    for(int i=0;i<100005;i++)
    {
        ss[i]=i;
    }
}
int main() {
    int n,count=0;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    sort(arr,arr+n);
    int mid=n/2;
    mid--;
    count=arr[mid+1]-arr[mid];
    cout<<count<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<cassert>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<time.h>
#include<vector>
#include<bitset>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(int i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0(i,n) REP(i,0,n-1)
#define repG(i,x) for(int i=pos[x];~i;i=e[i].next)
#define ll long long
#define db double
const int N=7;
const int INF=1e9+7;
int k;

int main(){
	scanf("%d",&k);
	if(k<=500){
		printf("%d\n",k);
		rep(i,k){
			rep(j,k)printf("%d ",i);
			puts("");
		}
		puts("");
	}
	else{
		puts("500");
		int n=500;
		rep(i,500){
			rep(j,500){
				if(i&1)printf("%d ",(i+j)%n+1);
				else {
					if((i+j)%n+n+1<=k)printf("%d ",(i+j)%n+n+1);
					else printf("%d ",(i+j)%n+1);
				}
			}
			puts("");
		}
	}
	return 0;
}

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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define sz(v) ll(v.size())

// topologicalSort
const ll INF = 100000000;

vector<ll> topologicalSort(ll N, ll M, vector<pair<ll, ll>> P) {
    vector<ll> A; // ソート後の配列
    vector<ll> H(N); // 入次数を管理
    stack<ll> st; // 入次数0の頂点集合
    vector<vector<ll>> g(N); // グラフの管理
    fill(H.begin(), H.end(), 0);

    rep(i, M) H[P[i].second]++;
    rep(i, N) if(is(H[i], 0)) st.push(i);
    rep(i, M) g[P[i].first].push_back(P[i].second); while(st.size()) {
        int i = st.top(); st.pop();
        A.push_back(i);
        for (int j: g[i]) {
            H[j]--;
            if (is(H[j], 0)) st.push(j);
        }
    }
    return A;
}

void solve(ll N, ll M, vector<ll> x, vector<ll> y){
    vector<pair<ll, ll>> P;
    rep(i, M) {
        P.push_back(make_pair(x[i]-1, y[i]-1));
    }
    vector<vector<ll>> g(N);
    rep(i, sz(P)) g[P[i].second].push_back(P[i].first);
    vector<ll> A;
    A = topologicalSort(N, M, P);
    ll dp[N];
    fill(dp, dp+N, 0);
    FOR(i, 0, N) {
        vector<ll> L = g[A[i]];
        ll mx = 0;
        rep(j, sz(L)) {
            mx = max(mx, dp[L[j]]);
        }
        dp[A[i]] = mx + 1;
    }
    ll mx = 0;
    rep(i, N) mx = max(mx, dp[i]);
    cout << mx - 1 << endl;
}

int main() {
  ll N;
    scanf("%lld",&N);
    ll M;
    scanf("%lld",&M);
    vector<ll> x(M);
    vector<ll> y(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
  solve(N, M, move(x), move(y));
  return 0;
}


Measured memory_bytes: 18416
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;

int main()
{
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	int n;
	cin >> n;
	vector<string> a(n);
	REP(i, n) cin >> a[i];
	vector<string> ret;
	
	for (int i = n - 1; i >= 0; i -= 2)
		ret.push_back(a[i]);
	for (int i = n % 2; i < n; i += 2)
		ret.push_back(a[i]);

	REP(i, n)
	{
		if (i + 1 == n) cout << ret[i] << "\n";
		else cout << ret[i] << " ";
	}

	return 0;
}




Measured memory_bytes: 14832
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<int(n);i++)
using namespace std;
int main(){
    ll n;
    cin >> n;
    ll x=n;
    int sum=0;
    while(x>0){
        sum+=x%10;
        x/=10;
    }
    if(n%sum==0) cout << "Yes" <<endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k,s,ans=0;cin>>k>>s;
  for(ll x=0;x<=k;++x) for(ll y=0;y<=k;++y) 
    if(x+y<=s&&x+y+k>=s) ans++;
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
char s[15];
inline int Abs(int x){return x<0?-x:x;}
int main(){
	int n,i,x,ans=1e9;
	scanf("%s",s);
	n=strlen(s);
	for(i=0;i<n-2;i++){
		x=(s[i]-48)*100+(s[i+1]-48)*10+s[i+2]-48;
		if(Abs(753-x)<ans)ans=Abs(753-x);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:16777216")
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <unordered_map>

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 2e5 + 7;
const int inf = 2e9 + 7;
const ll infl = 1e18 + 7;
const long double eps = 1e-9;
const ll mod = 998244353;

int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif // _DEBUG

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, W;
	cin >> n >> W;
	vector<pair<int, ll>> a;
	for (int i = 0; i < n; i++) {
		int w, v;
		cin >> w >> v;
		a.push_back({ w, v });
	}

	int ans = -1;
	vector<vector<ll>> dp(n + 1, vector<ll>(maxn, inf));
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < maxn; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j - a[i - 1].ss >= 0) {
				ll res = dp[i - 1][j - a[i - 1].ss] + a[i - 1].ff;
				dp[i][j] = min(dp[i][j], res);
			}
			if (j > ans && dp[i][j] <= W) ans = j;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 159744
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n; cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        cin >> b[i];
    }
    for (int i = 0; i < n - 2; ++i)
    {
        if (a[i] == b[i] && a[i + 1] == b[i + 1] && a[i + 2] == b[i + 2]) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 3656