akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


# https://atcoder.jp/contests/abc152/submissions/9619555

import sys
readline = sys.stdin.readline



n = I()
G = [[] for _ in range(n)]
for i in range(n - 1):
    u, v = LI()
    G[u - 1] += [(i, v - 1)]
    G[v - 1] += [(i, u - 1)]


def dfs(root):
    q = [root]
    path_bit = [-1] * n
    path_bit[root] = 0
    while q:
        u = q.pop()
        for i, v in G[u]:
            if path_bit[v] != -1:
                continue
            path_bit[v] = path_bit[u] | 1 << i
            q += [v]
    return path_bit



def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff)
    return c


m = I()
cond = LIR(m)
path_bit = dfs(0)
cond_bit = [0] * m
for j, (u, v) in enumerate(cond):
    cond_bit[j] = path_bit[u - 1] ^ path_bit[v - 1]

L = [0] * (2 ** m)
C = [0] * n
for i in range(2 ** m):
    if i != 0:
        L[i] = L[(i ^ (i & -i))] | cond_bit[(i & -i).bit_length() - 1]
# それぞれの条件を満たさないものを全事象から引く。
# 次に、2個同時に条件を満たさないものをたす。という要領。
    cond_cnt = popcnt(i)
# p_cnt が満たさない条件の数。
    if cond_cnt % 2:
        C[n - 1 - popcnt(L[i])] -= 1
    else:
        C[n - 1 - popcnt(L[i])] += 1


ans = 0
for i in range(n):
    ans += 2 ** i * C[i]


print(ans)

Measured memory_bytes: 51944
#include <stdio.h>

void init_array(int num[],int n)
{
  for(int i=0; i<n; i++)
    num[i] = -1;
}

long check(int n,int m,long x,long a[n][m+1],int num[n])
{
  long sum = 0,p;
  
  for(int i=1; i<=m; i++){
    p = 0;
    for(int j=0; j<n; j++){
      if(num[j] == -1)
        break;
      p += a[num[j]][i];
    }
     if(p < x)
       return -1;
  }

  for(int i=0; i<n; i++){
    if(num[i] == -1)
      break;
    sum += a[num[i]][0];
  }
  return sum;
}

int main(void)
{
  int n,m;
  long x,min = -1,sum;
  
  scanf("%d %d %ld",&n,&m,&x);
  
  long a[n][m+1];
  
  for(int i=0; i<n; i++)
    for(int j=0; j<=m; j++)
      scanf("%ld",&a[i][j]);
  
  for(int i=0; i<(1<<n); i++){
    int num[n];
    init_array(num,n);
    int k = 0;
    for(int j=0; j<n; j++){
      if((i >> j) & 1)
        num[k++] = j;
    }
    
    sum = check(n,m,x,a,num);
  
  if(min == -1)
    min = sum;
  else if(sum != -1 && min > sum)
    min = sum;
  }
  
  printf("%ld\n",min);
        
  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=15000007;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e17;
const long double PI=acos(-1);



void solve(int T){
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout<<"Yes\n";
        return;
    }
    cout<<"No\n";
}

int main() {
    fastio
    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}





Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    vector<int> D(N); for (auto &d : D) cin >> d;
    sort(begin(D), end(D));
    if (N % 2 != 0) {
        cout << 0 << '\n';
    } else {
        cout << D[N/2] - D[N/2-1] << '\n';
    }
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

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

    double r, s, l;
    r = sc.nextDouble();
    s = r*r*Math.PI ;
    l = 2*r*Math.PI ;

    System.out.println( String.format("%.6f",s) + " " + String.format("%.6f",l) );

    } 
}


Measured memory_bytes: 28028
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  n %= 10;
  if (n == 3) {
	  cout << "bon" << endl;
	} else if (n == 0 || n == 1 || n == 6 || n == 8) {
	  cout << "pon" << endl;
	} else {
	  cout << "hon" << endl;
	}
  return 0;
}


Measured memory_bytes: 3644
var a:array[0..50]of longint;
    x,y,n,m,i:longint;
begin
  readln(n,m);
  for i:=1 to m do
  begin
    read(x,y);
    inc(a[x]);
    inc(a[y]);
  end;
  for i:=1 to n do
    writeln(a[i]);
end.

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < 3; i++) {
            char[] line = scanner.nextLine().toCharArray();
            for (int j = 0; j < 3; j++) {
                if (i == j) sb.append(line[j]);
            }
        }

        System.out.println(sb.toString());
    }
}


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

int main(){
    int r, g, b, sum;
    cin >> r >> g >> b;
    sum = r*100 + g*10 + b;
    if (sum % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	 string s;
	 cin >> s;
	 
	 set<char> st;
	 for(int i=0;i<s.size();i++){
	 	st.insert(s[i]);
	 }
	 if(st.size() == s.size()) cout<<"yes";
	 else cout<<"no";
	 return 0;
}

Measured memory_bytes: 256
// #include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power(((((a)%mod)*((a)%mod))%mod),b/2)%mod;
    else return (((a)%mod)*(power(((((a)%mod)*((a)%mod))%mod),b/2)%mod))%mod;
}
inline ll inverse(ll a) {
  a %= mod;
  if (a < 0) a += mod;
  ll b = mod, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += mod;
  return u;
}
  
  
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solution
ll fastmod(ll x)
{
    return x<mod?x:x%mod;
}
int32_t main()
{
    IOS
   
   
    int n,k;
    cin>>n>>k;
    
    int dp[k+1];
    memset(dp,0,sizeof(dp));
    for(int i=k;i>=1;--i)
    {
        dp[i]=power(k/i,n);
        for(int j=2*i;j<=k;j+=i)
        {
            dp[i]-=dp[j];
            dp[i]+=mod;
            dp[i]%=mod;
        }
    }        
    int ans=0;
    for(int i=1;i<=k;i++)
    {
        ans+=dp[i]*i;
        ans%=mod;
    }
    cout<<ans<<endl;

}       

Measured memory_bytes: 4324
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd>> Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod

bool Solve(ll B, ll W,ll T){
    if(!B) return true;
    if(W<=0) return false;
    if(W*T>=B) return true;
    return false;
}
int main(){
    ll A,V,B,W,T; cin>>A>>V>>B>>W>>T;
    B=abs(A-B);
    W=V-W;
    if(Solve(B,W,T)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    
}

Measured memory_bytes: 3632
import sys
readline = sys.stdin.readline
from collections import deque
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]

def main():
    H, W = map(int, readline().rstrip().split())
    mat = [list(readline().rstrip()) for _ in range(H)]

    start = []
    for h in range(H):
        for w in range(W):
            if mat[h][w] == '#':
                start.append((h, w))
    
    res = 0
    que = deque(start)
    while que:
        next_que = deque()
        for h, w in que:
            for dh, dw in directions:
                if not (0 <= h+dh < H and 0 <= w+dw < W):
                    continue
                if mat[h+dh][w+dw] == '#':
                    continue
                mat[h+dh][w+dw] = '#'
                next_que.append((h+dh, w+dw))

        res += 1
        que = next_que

    print(res - 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 134224
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(15);
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll ans = 0;
    int count = 0;
    ll mini = 9999999999;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        ans += abs(A[i]);
        if(A[i] < 0){
            count++;
        }
        mini = min(mini,abs(A[i]));
    }
    if(count % 2 == 0){
        cout << ans << endl;
    }
    else{
        cout << ans - 2 * abs(mini) << endl;
    }
    //cout << ans << endl;
}


Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;

int main() {FIN
    
    ll n, c = 0, i;
    cin >> n;
    vll fd(n);
    for (i = 0; i < n; i++)
		cin >> fd[i];
		
	sort(fd.rbegin(), fd.rend());
	i = 1;
	while (i < n) {
		c += fd[i / 2];
		i++;
	}
	
	cout << c << "\n";
    
    return 0;
}


Measured memory_bytes: 4780
import java.util.Scanner;

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

		int count = 0;
		int n = 0;

		for (int i = Math.max(a, b); i >= 1; i--) {
			if (a % i == 0 && b % i == 0) {
				count++;
				n = i;
				if (count >= k) break;
			}
		}

		System.out.println(n);
	}
}


Measured memory_bytes: 23380
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//????????????a???????????????
		int Height = sc.nextInt();
		//?¨??????????b???????????????
		int Breadth = sc.nextInt();
		//????????¢?????¢???????¨????
		int Area  = (Height * Breadth);
		//????????¢?????¨?????????????¨????
		int Periphery = (Height + Breadth) * 2;
		//??¨???
		System.out.println(Area + " " + Periphery);
	}
}

Measured memory_bytes: 26044
#include<bits/stdc++.h>
using namespace std;
int n,a[200005],ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	ans=a[1];
	for(int i=2;i<n;i++)
		if(a[i]<a[n]&&abs(a[n]-a[i]-a[i])<abs(a[n]-ans-ans))
			ans=a[i];
	printf("%d %d\n",a[n],ans);
	return 0;
}

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

using namespace std;
using ll = long long;

int main () {
	ll a, b, c, d, l, m;
	cin >> a >> b >> c >> d;
	l = c * d / __gcd(c, d);
	m = 
		((b / c) - ((a - 1) / c)) +
		((b / d) - ((a - 1) / d)) -
		((b / l) - ((a - 1) / l));
	cout << (b - a + 1 - m) << endl;
}

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

int main() {
    string s;
    cin >> s;
    string p;
    cin >> p;
    string s2;
    s2 = s + s;
    if (s2.find(p)!=-1){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


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

int main() {
  string s; cin >> s;
  int n = s.size();
  vll a(n+1);
  rep(i, n-1) {
    if (s[i] == '>' && s[i+1] == '<') {
      a[i+1] = 0;
      for (int j = i+1; s[j] == '<' && a[j] >= a[j+1]; j++)
        a[j+1] = a[j] + 1;
      for (int k = i; s[k] == '>' && a[k] <= a[k+1]; k--)
        a[k] = a[k+1] + 1;
    }
  }
  for (int i = 0; i <= n; i++)
    if (s[i] == '<' && a[i] >= a[i+1]) a[i+1] = a[i] + 1;
  for (int i = n; i >= 0; i--)
    if (s[i] == '>'&& a[i] <= a[i+1]) a[i] = a[i+1] + 1;
  ll ans = 0;
  // rep(i, n+1) cout << a[i] << " ";
  // cout << endl;
  rep(i, n+1) ans += a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4740
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char a[110],b[110];
bool cmp(char x,char y)
{
	return x>y;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>a>>b;
	sort(a,a+strlen(a));
	sort(b,b+strlen(b),cmp);
	if(strcmp(a,b)<0)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

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

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

int main(){
    ll N;
    cin >> N;
    ll small = (ll)sqrt(N);
    for(ll i=small; i>=1; i--){
        if (N%i==0){
            ll large = N/i;
            ll cnt=1;
            while(large>=10){
                large/=10;
                cnt++;
            }
            cout << cnt << endl;
            return 0;

        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
#include <boost/multiprecision/cpp_int.hpp>
#endif

#define p std::pair
#define ll long long
#define ull unsigned long long
#define pi (acos(-1))
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
void stat();
constexpr ll mod = 1000000000 + 7;

int main()
{
	int n;cin>>n;
	vec<int>v(n);
	rep(i,n){int a;
		cin>>a;v[i]=--a;
	}
	ll ans=0;

	rep(i,n){
if(v[v[i]]==i){++ans;}
	}
	cout<<ans/2<<endl;



    return 0;
}
ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat()
{
#ifdef local
    rep(i, 2) { std::cout << "local enable" << std::endl; }
#endif
#ifdef hacks
    rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}


Measured memory_bytes: 3708
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

string intToStr(int a){
    string res = "";
    while(a>0){
        res.push_back((char)(a%10+'0'));
        a/=10;
    }
    reverse(all(res));
    return res;
}

int main(){
    string s;
    cin >> s;
    int n = s.size();
    string res = "";
    res.push_back(s.front());
    res += intToStr(n-2);
    res.push_back(s.back());
    put(res);
    return 0;
}


Measured memory_bytes: 256
N=int(input())
A = []
for i in range(N):
  Ai=int(input())
  A.append(Ai)
on = 1 #現実世界での番号
for i in range(N):
  on = A[on-1] #次のボタンを知るために、配列を参照する
  if on == 2:
    print(i+1)
    break
if on != 2:
  print(-1)


Measured memory_bytes: 7084
#include <iostream>
using namespace std;
#define INF 1 << 30

int main(){
    int n, t, a, ans=0, min=INF; cin >> n >> t >> a;
    for(int i = 1; i <= n; i++){
        int h; cin >> h;
        int temp = 1000 * t - 6 * h - 1000 * a;
        if(temp < 0) temp *= -1;
        if(min > temp){
            min = temp; ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if(b == 1) {
      System.out.println("0");
    } else {
      System.out.println(a - b);
    }
  }
}

Measured memory_bytes: 21972
import java.util.Scanner;

    public class Main {

    	public static void main(String[] args) {

    		Scanner sc = new Scanner(System.in);

    		int d = sc.nextInt();
    		int n = sc.nextInt();

    		if (d == 0){
    			if (n == 100){
    				System.out.println(101);
    			} else {
    				System.out.println(n);
    			}
    		} else if (d == 1){
    			if (n == 100){
    				System.out.println(10100);
    			} else {
    				System.out.println(100*n);
    			}
    		} else if (d == 2){
    			if (n == 100){
    				System.out.println(1010000);
    			} else {
    				System.out.println(10000*n);
    			}
    		}
    	}
    }

Measured memory_bytes: 25172
import sys
input = sys.stdin.readline

N = int(input())
a = list(map(int, input().split()))
IJK = [0,0,0]
for i in range(N):
    IJK[a[i]-1]+=1

dp = [[[float(0)]*(N+3) for _ in range(N+3)] for _ in range(N+3)]

for k in range(N+1):
    for j in range(N+1):
        for i in range(N+1):
            if i+j+k > N: continue
            if i+j+k == 0: continue
            tmp = 1.0*N
            if i>0: tmp += i*dp[i-1][j][k]*1.0
            if j>0: tmp += j*dp[i+1][j-1][k]*1.0
            if k>0: tmp += k*dp[i][j+1][k-1]*1.0
            dp[i][j][k] = tmp/(i+j+k)
print(dp[IJK[0]][IJK[1]][IJK[2]])




Measured memory_bytes: 258312
N, D = map(int, input().split())
X = [list(map(float, input().split())) for _ in range(N)]
ans = 0

for i in range(N-1):
    for j in range(i+1,N):
        tm = 0
        if i != j:
            for k in range(D):
                tm += (X[i][k] - X[j][k])**2

            if (tm**0.5).is_integer():
                ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
long long int gcd(long long int x, long long int y){
  return y!=0 ? gcd(y, x%y) : x;
}
long long int lcm(long long int x, long long int y){
  return x*y/gcd(x, y);
}
long long int factorial(long long int x){
  return x==0 ? 1 : x*factorial(x-1);
}
int main(){
  int i, j, l, flag[4]={0, 0, 0, 0};
  char s[1002];
  cin >> s;
  l=strlen(s);
  for(i=0; i<l; i++){
    if(s[i]=='N') flag[0]=1;
    else if(s[i]=='W') flag[1]=1;
    else if(s[i]=='S') flag[2]=1;
    else flag[3]=1;
  }
  if((flag[0]+flag[2])%2==1||(flag[1]+flag[3])%2==1) cout << "No";
  else cout << "Yes";
  return 0;
}

    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(b>a)return 0;
	if(a==b)return 1;
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,m,a[100010];
priority_queue<int>q;
signed main(){
	cin>>n>>m;
	rep(i,n){
		cin>>a[i];
		q.push(a[i]);
	}
	rep(i,m){
		int x=q.top();
		q.pop();
		x/=2;
		q.push(x);
	}
	int sum=0;
	while(!q.empty()){
		sum+=q.top();
		q.pop();
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 1912
x, y = map(int, input().split())
ans = 0
if x ==3:
    ans += 100000
if x ==2:
    ans += 200000
if x ==1:
    ans += 300000
if y ==3:
    ans += 100000
if y ==2:
    ans += 200000
if y ==1:
    ans += 300000
if x == 1 and y == 1:
    ans +=400000
print(ans)

Measured memory_bytes: 3064
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n, a, b = M()
print(min(n*a, b))

Measured memory_bytes: 74576
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define mp make_pair

void print(auto &a)
{
    for (auto s: a) cout<<s<<' ';
    cout<<endl;
}

void get(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cin>>a[i];
}

const int p =  856;


int mul(int a, int b) {
    return (1LL * a%p * b%p) % p;
}

int add(int a, int b) {
    ll s = (a+b);
    s = s%p;
    if (s<0) s+=p; 
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}



vector<int> Z(string s)
{
int n = s.length();
vector<int> z(n);
int L = 0, R = 0;
for (int i = 1; i < n; i++) {
  if (i > R) {
    L = R = i;
    while (R < n && s[R-L] == s[R]) R++;
    z[i] = R-L; R--;
  } else {
    int k = i-L;
    if (z[k] < R-i+1) z[i] = z[k];
    else {
      L = i;
      while (R < n && s[R-L] == s[R]) R++;
      z[i] = R-L; R--;
    }
  }
}
return z;
}

mt19937 rnd(228);


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

    int n, m;
    cin>>n>>m;
    vector<vector<int>> G(n+1);
    int a, b;
    for (int i = 0; i<m; i++)
    {
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i = 1; i<=n; i++) if (G[i].size()%2==1) {cout<<"No"; return 0;}
    for (int i = 1; i<=n; i++) if (G[i].size()>4) {cout<<"Yes"; return 0;}
    if (m<n+2) {cout<<"No"; return 0;}
    vector<int> good;
    for (int i = 1; i<=n; i++) if (G[i].size()==4) good.push_back(i);
    if (good.size()>=3) {cout<<"Yes"; return 0;}
    for (auto s: good)
    {
        for (auto next: G[s])
        {
            int n = next;
            int p = s;
            while (G[n].size()!=4)
            {
                int n1 = n;
                n = G[n1][0];
                if (n==p) n = G[n1][1];
                p = n1;
            }
            if (n==s) {cout<<"Yes"; return 0;}
        }
    }
    cout<<"No"; return 0;
}

Measured memory_bytes: 5760
N, A, B = gets.split.map(&:to_i)
nn = N
ans = 0
1.upto(N) do |int|
  int2 = int
  pre = 0
  while int > 0
    pre += int % 10
    int /= 10
  end
  # p "#{pre}, #{int2}"
  ans += int2 if A <= pre && pre <= B
end
puts ans

Measured memory_bytes: 1788
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
for i in range(N):
	V[i] = V[i] - C[i]
V = sorted(V)
ans = 0
for i in range(N):
	if(V[-i]>0):
		ans += V[-i]
print(ans)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>
#include <map>

using namespace std;

int main(){
	long long N, x, ans = 0;

	cin >> N >> x;
	vector<long long> a(N);

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

	sort(a.begin(), a.end(), less<long long>());

	for (int i = 0; i < N; ++i){
		if (x < a[i])
			break;
		if (i == N - 1){
			if (x == a[i])
				++ans;
		}
		else{
			x -= a[i];
			++ans;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;

int main(void){
        int i,j;
        int n;
        char s[4100];
        long long r,g,b;

        scanf("%d",&n);
        scanf("%s",s);
        
        r=0;
        g=0;
        b=0;
        for(i=0;i<n;i++){
                if(s[i] == 'R'){
                        r++;
                } else if(s[i] == 'G'){
                        g++;
                } else if(s[i] == 'B'){
                        b++;
                }
        }

        long long ans = r*g*b;
        for(i=0;i<n;i++){
                for(j=1;j<=i;j++){
                        if(i+j >= n) break;
                        if(s[i]!=s[i-j] && s[i]!=s[i+j] && s[i-j]!=s[i+j]){
                                ans--;
                        }
                }
        }
        printf("%lld\n",ans);
        
        return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


ll a[5];

int main() {
    ll N;
    cin >> N;
    rep(i, 5)cin >> a[i];

    sort(a, a + 5);
    if (N % a[0] == 0)cout << N / a[0] + 4 << endl;
    else cout << N / a[0] + 5 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
#define X real()
#define Y imag()
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
#define prev(P, i) P[(i+P.size()-1) % P.size()]
#define diff(P, i) (next(P, i) - curr(P, i))
const double EPS = 1e-8;
const double INF = 1e12;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

//外積
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

//内積
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

//線 (線分)
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

//多角形
typedef vector<P> G;

double convex_diameter(const G &pt) {
  const int n = pt.size();
  int is = 0, js = 0;
  for (int i = 1; i < n; ++i) {
    if (imag(pt[i]) > imag(pt[is])) is = i;
    if (imag(pt[i]) < imag(pt[js])) js = i;
  }
  double maxd = norm(pt[is]-pt[js]);
  int i, maxi, j, maxj;
  i = maxi = is;
  j = maxj = js;
  do {
    if (cross(diff(pt,i), diff(pt,j)) >= 0) j = (j+1) % n;
    else i = (i+1) % n;
    if (norm(pt[i]-pt[j]) > maxd) {
      maxd = norm(pt[i]-pt[j]);
      maxi = i; maxj = j;
    }
  } while (i != is || j != js);
  return sqrt(maxd); /* farthest pair is (maxi, maxj). */
}

int main() {
  int N; cin >>N;
  G g(N);
  REP(i, N){
    double x, y; cin >>x >>y;
    g[i] = P(x, y);
  }
  printf("%.10lf\n", convex_diameter(g));
  return 0;
}

Measured memory_bytes: 2324
import sys
from io import StringIO
import unittest

def resolve():
    s, w = map(int, input().split())

    if s <= w:
        print("unsafe")
    else:
        print("safe")

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4 5"""
        output = """unsafe"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """100 2"""
        output = """safe"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """10 10"""
        output = """unsafe"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 75380
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    long long int N;
    cin >> N ;

    if( N < 10 ){
        cout << N << endl;

    } else if (10 <= N && N < 100){
        cout << 9 << endl;

    } else if (100 <= N && N <1000){
        int  k100 =  N % 1000 ;
        cout << k100-99 + 9 <<endl ;

    }else if ( 1000<= N && N < 10000){
        cout<<909 <<endl;
    } else if ( 10000 <= N && N <100000) {
        long long int k10000 ;
        int k10;
        k10000 = N % 100000 ;
        cout << k10000-9999 + 909 <<endl;
 
    }else {
        cout << 90909 <<endl;
    }

    return 0;
}

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>;


main() {
    string S;
    cin >> S;

    int ans = 0;
    rep(i, S.size()) if (S[i] == '1') ++ans;
    cout << ans << endl;
}   

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebug(multimap<T1, T2> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mdebugr(map<T1, T2, greater<T1>> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebugr(multimap<T1, T2, greater<T1>> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll n;
    cin >> n;

    if(n%2 == 0){
        cout << n/2-1 << endl;
    }else{
        cout << n/2 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
s = input()

L = 0
R = s.count("E")
ans = L + R

for i in range(N):
    if s[i] == "W":
        L += 1
    if s[i] == "E":
        R -= 1
    
    if L + R < ans:
        ans = L + R

print(ans)

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n,m;
  cin>>n>>m;
  int maxl=1,minr=n;
  rep(i,m){
    int l,r;
    cin>>l>>r;
    if(maxl<l) maxl=l;
    if(minr>r) minr=r;
  }
  
  int ans=max(0,minr-maxl+1);
  cout<<ans<<endl;
}


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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

constexpr int mod = 1e9 + 7;
constexpr int32_t inf = 1001001001;
constexpr int64_t infll = 1001001001001001001ll;
constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

// clang-format off
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }

template <typename T> void sort(vector<T> &v) { sort(all(v)); }
template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int n = in();
  vector<int> a(n);
  cin >> a;

  a.push_back(-1);

  int ans = 0, cnt = 1;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != a[i - 1]) {
      ans += cnt / 2;
      cnt = 1;
    } else {
      cnt++;
    }
  }

  cout << ans << endl;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  a.insert(a.begin(), 0);
  rep(i, n) a[i+1] += a[i];
  ll ans = INF64;
  for(int i = 1; i < n; ++i) chmin(ans, abs(a[n]-2*a[i]));
  cout << ans << endl;
}


Measured memory_bytes: 6336
import collections

n, q = map(int, input().split())
cnt = [0] * (n + 1)

# adjacency list for tree graph
g = [[] for _ in range(n + 1)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

# calc cnt
for _ in range(q):
    v, val = map(int, input().split())
    cnt[v] += val

q = collections.deque()
q.append(1)
checked = [0] * (n + 1)

while q:
    v = q.pop()
    checked[v] = 1
    for u in g[v]:
        if checked[u] == 1:
            continue
        cnt[u] += cnt[v]
        q.append(u)
print(*cnt[1:])


Measured memory_bytes: 56160
/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#include<bits/stdc++.h>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr <<"at line "<< __LINE__<<": [" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;

template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

const int mx=2e5+5;

int color[mx],par[mx];
vector<int>g[mx];

void bfs()
{
	color[1]=1;
	queue<int>q;
	q.push(1);
	
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		
		for(int v: g[u])
		{
			if(!color[v])
			{
				color[v]=1;
				par[v]=u;
				q.push(v);
			}
		}
	}
}

void solve()
{
	int n,m;
	cin>>n>>m;
	
	while(m--)
	{
		int u,v;
		cin>>u>>v;
		
		g[u].push_back(v);
		g[v].push_back(u);
	}		
	
	iota(par+2,par+n+1,2);
	
	bfs();
	
	for(int i=2;i<=n;i++)
	{
		if(par[i]==i)
		{
			cout<<"No";
			return;
		}
	}
	
	cout<<"Yes\n";
	
	for(int i=2;i<=n;i++) cout<<par[i]<<"\n";
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}


Measured memory_bytes: 13196
import sys

def judge(p, numList):
    for n in numList:
        if p[n] == False:
            return False
    return True

board = []
bingo = [False] * 9
for i in range(0, 3):
    board += list(map(int, input().split()))

N = int(input())
for i in range(0, N):
    n = int(input())
    for j in range(len(board)):
        if n == board[j]:
            bingo[j] = True

row = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
for r in row:
    if judge(bingo, r):
        print("Yes")
        sys.exit()
print("No")

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
  int i,j,k,n,tmp;
  int A[500];

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

  
  for(i=1;i<=n;i++){
    tmp = A[i];
    j = i-1;
    for(k=0;k<n;k++){
      if(k < n-1){
	printf("%d ",A[k]);
      }
      else  printf("%d\n",A[k]);
    }
    while(j >= 0 && A[j] > tmp){
      A[j+1] = A[j];
      j--;
      A[j+1] = tmp;
    }
  }
      
  return 0;
}



Measured memory_bytes: 2084