akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int X;
int Y;
int N;
set<int> xs[200000];
int main(){
  int Lj4PdHRW;
  int i;
  int j;
  int k;
  int res = 1000000000;
  rd(X);
  rd(Y);
  rd(N);
  for(i=(0);i<(Y);i++){
    xs[i].insert(X);
  }
  for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
    rd(i);i += (-1);
    rd(j);j += (-1);
    xs[j].insert(i);
  }
  i = j = 0;
  for(;;){
    k = *(xs[j].lower_bound(i+1));
    chmin(res, k);
    if(k == i+1){
      break;
    }
    i++;
    if(j+1 == Y){
      break;
    }
    k = *(xs[j+1].lower_bound(i));
    if(k != i){
      j++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190925-1

// --- original code ---
// int X, Y, N;
// set<int> xs[2d5];
// 
// {
//   int i, j, k;
//   int res = 1d9;
//   
//   rd(X,Y,N);
//   rep(i,Y) xs[i].insert(X);
//   
//   rep(N){
//     rd(i--,j--);
//     xs[j].insert(i);
//   }
// 
//   i = j = 0;
//   for(;;){
//     k = *(xs[j].lower_bound(i+1));
//     res <?= k;
//     if(k == i+1) break;
//     i++;
// 
//     if(j+1 == Y) break;
//     k = *(xs[j+1].lower_bound(i));
//     if(k != i) j++;
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 28416
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n, k) for (int i = n; i < k; i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(24) << fixed << p << endl;
#define vi vector<int>
#define printv(v)                      \
    for (int i = 0; i < v.size(); i++) \
        P(v[i]);
#define printt(a, b) cout << a << " " << b << endl;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int MOD = 1e9 + 7;

bool pairCompare(const pair<int, int> &firstElof, const pair<int, int> &secondElof)
{
    return firstElof.second < secondElof.second;
}

void solve()
{
    ll n, m;
    cin >> n >> m;
    if (n == 1 && m == 1)
    {
        P(1);
        return;
    }
    if (n == 1 || m == 1)
    {
        P(n * m - 2);
        return;
    }
    if (n == 2 || m == 2)
    {
        P(0);
        return;
    }
    P((n - 2) * (m - 2));
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 200010
#define LL long long
char s[MAXN];
int cnt[30];
LL ans;
int main()
{
	scanf("%s",s);
	int n=strlen(s);
	for(int i=0;i<n;i++)
		cnt[s[i]-'a']++;
	ans=1LL*n*(n-1)/2;
	for(int i=0;i<26;i++)
		if(cnt[i]>1)
			ans-=1LL*cnt[i]*(cnt[i]-1)/2;
	ans++;
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
import java.util.*;
import static java.lang.Math.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int l = sc.nextInt();
        int r = sc.nextInt();
        int d = sc.nextInt();
        
        int ans = 0;
        for (int i = l; i <= r; i++) {
            if (i % d == 0) ans++;
        }
        System.out.println(ans);
    }
}


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

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

  if(S[K-1] == 'A') {
    S[K-1] = 'a';
  } else if (S[K-1] == 'B') {
    S[K-1] = 'b';
  } else if (S[K-1] == 'C') {
    S[K-1] = 'c';
  }

  cout << S << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{

	public static void main(String[] args) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] W = new int[n];
		String[] in = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			W[i] = Integer.parseInt(in[i]);
		}
		System.out.printf("%d\n", minCostSort(W));
	}

	public static int indexOf(int[] A, int x){
		for(int i = 0; i < A.length; i++){
			if(A[i] == x){
				return i;
			}
		}
		return -1;
	}

	public static int minCostSort(int[] W){
		int[] sorted = W.clone();
		Arrays.sort(sorted);
		int cost = 0;
		for(int i = 0; i < W.length; i++){
			int a = indexOf(W, sorted[i]);
			int j = 0;
			while(a > i){
				j++;
				int b = indexOf(W, sorted[a]);
				cost += W[b];
				int work = W[a];
				W[a] = W[b];
				W[b] = work;
				a = b;
			}
			cost += Math.min(sorted[i] * j, sorted[i] * 2 + sorted[0] * (j+2));
		}
		return cost;
	}
}

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

void solve()
{
  string s, t;
  cin>>s>>t;
  int cnt = 0;
  for(int i = 0; i<s.size(); i++)
  {
    if(s[i]!=t[i])
      cnt++;
  }
  cout<<cnt<<"\n";
}
int main()
{
  solve();
  return 0;
}

Measured memory_bytes: 3900
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    ans = []
    for i in range(2, 55555+1):
        if Math.isPrime(i) and (i-1) % 5 == 0:
            ans.append(i)
            if len(ans) == N:
                break
    print(*ans,sep=" ")


if __name__ == "__main__":
    main()


Measured memory_bytes: 39920
def f_takahashi_basics_in_education_and_learning(L, A, B, M, DIGIT_MAX=18):
    """numpyの行列演算だと L, A, B が 10**18 程度のときうまく動作しない"""
    def identity_matrix(n):
        """n×n単位行列"""
        return [[int(i == j) for i in range(n)] for j in range(n)]

    def multiply(a, b):
        """行列a, bの積"""
        row = len(a)
        col = len(b[0])
        t = len(b)
        ret = [[0] * col for _ in range(row)]
        for i in range(row):
            for j in range(col):
                for k in range(t):
                    ret[i][j] += a[i][k] * b[k][j]
        for i in range(row):
            for j in range(col):
                ret[i][j] %= M
        return ret

    def power(a, k):
        """行列aのk乗"""
        n = len(a)
        ret = identity_matrix(n)
        while k:
            if k & 1:
                ret = multiply(ret, a)
            a = multiply(a, a)
            k >>= 1
        return ret
 
    # 数列に対して、d桁の要素の個数を求める
    num_pow_d = [0] * (DIGIT_MAX + 1)
    for d in range(DIGIT_MAX + 1):
        if 10**d - 1 < A:
            continue
        # dに対してA + B*n <= 10**d - 1 となる最大のn(L以下しか取りえない)
        num_pow_d[d] = min(((10**d - 1 - A) // B) + 1, L)  # +1はnが0スタートのため
    ans = 0
    array = [[0, A, 1]]
    for d in range(1, DIGIT_MAX + 1):
        c_d = num_pow_d[d] - num_pow_d[d - 1]
        matrix = [[10**d, 0, 0], [1, 1, 0], [0, B, 1]]
        array = multiply(array, power(matrix, c_d))
    return array[0][0]

L, A, B, M = [int(i) for i in input().split()]
print(f_takahashi_basics_in_education_and_learning(L, A, B, M))

Measured memory_bytes: 3188
N,X,Y=gets.chomp.split(" ").map(&:to_i)
rets = Array.new(N-1, 0)
(1..(N-1)).each do |s|
    ((s+1)..(N)).each do |t|
        direct = t-s
        bypass = (X-s).abs + (Y-t).abs + 1
        if direct > bypass
            rets[bypass-1]+=1
        else
            rets[direct-1]+=1
        end
    end
end
rets.each {|r| puts r }


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

using namespace std;
vector<vector<long long> >grd;
vector<vector<vector<long long> > >dp;
long long ans=0ll;

int n,m,k;
long long slv(int x=0,int y=0,int tk=0){
    if(x==n-1&&y==m-1){
        return ((tk<3)?grd[x][y]:0ll);
    }
    long long &ret=dp[x][y][tk];
    if(ret!=-1ll)
        return ret;
    if(y<m-1){
        if(tk<3)
            ret=max(ret,slv(x,y+1,tk+1)+grd[x][y]);
        ret=max(ret,slv(x,y+1,tk));
    }
    if(x<n-1){
        ret=max(ret,slv(x+1,y,0)+((tk<3)?grd[x][y]:0ll));
    }
    return ret;
}

int main()
{///{}
    cin>>n>>m>>k;
    grd=vector<vector<long long> >(n,vector<long long >(m));
    dp=vector<vector<vector<long long> > >(n,vector<vector<long long> >(m,vector<long long>(5,-1ll)));
    for(int i=0;i<k;i++){
        long long x,y,v;
        cin>>x>>y>>v;
        x--;  y--;
        grd[x][y]=v;
    }
    cout<<slv()<<'\n';
    return 0;
}


Measured memory_bytes: 707236
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;

int main()
{
	char s[201], t[101], p[101];

	scanf("%s %s", s, p);

	strcpy(t, s);
	strcat(s, t);

	if (strstr(s, p) == NULL) printf("No\n");
	else printf("Yes\n");

	return 0;
}

Measured memory_bytes: 3164
/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 2e3+23;
const int maxn = 2e5+35;
LL n;
int main(){
    cin >> n; int ans = 0;
    for(int p = 2;1ll*p*p <= n; ++p){
        if(n%p == 0){
            int cnt = 0;
            while(n%p == 0){
                n /= p; cnt += 1;
            }
            for(int i = 1;;++i){
                if(cnt-i<i+1){
                    ans += i;
                    break;
                }
                else cnt -= i;
            }
        }
    }
    if(n > 1) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, bool> pib;

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<double> vf;

typedef long double ld;

#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

#define printItr(A) for(auto itr = A.begin(); itr != A.end(); ++itr){cout << * itr << ", ";}cout << endl;

const double PI = 3.141592653589793;

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

int main() {
	ll a, b, c;
	cin >> a >> b>>c;
	if (a + b + c >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define all(v) v.begin(),v.end()
#define make_unique(v) v.erase(unique(all(v)),v.end())
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define y1 EsiHancagorcRepa
 
const int N=2e5+10;
const ll MOD2=998244353;
const ll MOD=1e9+7;

vector<int> g[N];
int ans[N],s[N];
void dfs(int v,int par=-1,int gum=0){
    gum+=s[v];
    ans[v]=gum;
    trav(to,g[v])if (to!=par)dfs(to,v,gum);
}

int main(){
    fastio;
    srng;
    #ifdef ALEXPC
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    cout.precision(13);
    int n,q;
    cin>>n>>q;
    FOR(i,n-1){
        int a,b;
        cin>>a>>b;
        g[a].ad(b);
        g[b].ad(a);
    }
    FOR(i,q){
        int p,v;
        cin>>p>>v;
        s[p]+=v;
    }
    dfs(1);
    FORT(i,1,n){
        cout<<ans[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 24064
n = int(input())
a = input().split()
a = [int(i) for i in a]

count = 0
while(True):
    flag = True
    for i in range(n):
        if (a[i] % 2 == 1):
            flag = False
            break

    if (flag):
        count += 1
        for i in range(n):
            a[i] /= 2
    else:
        break

print(count)
        


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

int main(void) {
  int N;
  int *X, *Y;
  scanf("%d", &N);
  X = (int*)calloc(N, sizeof(int));
  Y = (int*)calloc(N, sizeof(int));
  for (int i = 0; i < N; i++) {
    scanf("%d", &X[i]);
  }
  memcpy(Y, X, sizeof(int) * N);
  qsort(Y, N, sizeof(int), cmp);

  for (int i = 0; i < N; i++) {
    if (X[i] <= Y[(N-1)/2]) {
      printf("%d\n", Y[(N-1)/2+1]);
    } else {
      printf("%d\n", Y[(N-1)/2]);
    }
  }

  return 0;
}

Measured memory_bytes: 3704
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(a, b, c) = in.readLine().split("\\s+").map(i => BigInt(i.toInt))

    out.println(
      if (c - a - b <= 0) {
        "No"
      } else if (4 * a * b < (c - a - b) * (c - a - b)) {
        "Yes"
      } else {
        "No"
      }
    )
    out.flush()
  }
}


Measured memory_bytes: 25548
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}

#define REP(i,s,n) for(int i=s; i!=n; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1'000'000'000+7)

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

template <template<class,class,class...> class C, typename K, typename V, typename... Args>
V map_get(const C<K,V,Args...>& m, K const& key, const V & defval)
{
    typename C<K,V,Args...>::const_iterator it = m.find( key );
    if (it == m.end())
        return defval;
    return it->second;
}

bool checked[3001][3001];
ll dp[3001][3001];
vector<int> a;
int N;

ll solve(int l, int r) {
    if (l > r) return 0;
    if (checked[l][r]) {
        return dp[l][r];
    }
    
    if ((l-1+N-r)%2 == 0) {
        dp[l][r] = max(solve(l+1, r) + a[l], solve(l, r-1) + a[r]);
    } else {
        dp[l][r] = min(solve(l+1, r) - a[l], solve(l, r-1) - a[r]);
    }
    checked[l][r] = true;
    return dp[l][r];
}

int main() {
    cin >> N;
    a.resize(N+1);
    REP(i, 0, N) {
        cin >> a[i+1];
    }

    cout << solve(1, N) << endl;
}


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

#define MAX 10000
#define NIL -1

struct Node {
  int parent;
  int left;
  int right;
};

Node T[MAX];
int n;

void preParse(int root) {
  if ( root == NIL ) return;
  printf(" %d", root);
  if ( T[root].left != NIL ) {
    preParse(T[root].left);
  }
  if ( T[root].right != NIL ) {
    preParse(T[root].right);
  }
}

void inParse(int root) {
  if ( root == NIL ) return;
  if ( T[root].left != NIL ) {
    inParse(T[root].left);
  }
  printf(" %d", root);
  if ( T[root].right != NIL ) {
    inParse(T[root].right);
  }
}

void postParse(int root) {
  if ( root == NIL ) return;
  if ( T[root].left != NIL ) {
    postParse(T[root].left);
  }
  if ( T[root].right != NIL ) {
    postParse(T[root].right);

  }
  printf(" %d", root);
}

int main() {
  int id, left, right, root;

  cin >> n;
  for ( int i = 0; i < n; i++ ) {
    T[i].parent = NIL;
  }

  for ( int i = 0; i < n; i++ ) {
    scanf("%d %d %d", &id, &left, &right);
    T[id].left = left;
    T[id].right = right;

    if ( left != NIL ) T[left].parent = id;
    if ( right != NIL ) T[right].parent = id;
  }

  for ( int i = 0; i < n; i++ ) {
    if ( T[i].parent == NIL ) root = i;
  }

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

Measured memory_bytes: 3188
N,M = map(int, input().split())
AC = [0]*N
WA = [0]*N
score = 0
pen = 0
for i in range(M):
  p,S = input().split()
  p = int(p)-1
  if AC[p] == 1:
    continue
  elif S == "WA":
    WA[p] += 1
  elif S == "AC":
    AC[p] = 1
    score += 1
    pen += WA[p]
print(score,pen)
     

Measured memory_bytes: 4596
#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>;

int main() {
    int N; cin >> N;
    vector<int> B(N);
    rep(i,N-1) cin >> B.at(i);
    vector<int> C(N);
    int ans = 0;
    ans += B.at(0);
    ans += B.at(N-2);
    for(int i = 1; i < N-1; i++)
        ans += min(B.at(i-1),B.at(i));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;


int main (){
  
  int pc,stu;
  
  while(1){

    cin >>pc>>stu;
    if (pc==0&&stu==0)break;
    
    int i,j,k,srec,sque,t,n,m,s,ts,te,sum;
    int record[pc][721];
    
    for(i=0;i<pc;i++){
      for(j=0;j<721;j++){
	record[i][j]=0;
      }
    }

    //record入力
    cin >>srec;
    for(i=0;i<srec;i++){
      cin >>t>>n>>m>>s;
      n--;
      
      if (s==1){
	//ログイン
	for(j=t-540;j<721;j++){
	  //if (j==19)cout<<"19"<<endl;
	  record[n][j] = m;
	  //cout <<"n="<<n<<" j="<<j<<" record="<<record[n][j] <<endl;
	}
      }else{
	//ログアウト
	for(j=t-540;j<721;j++){
	  record[n][j] = 0;
	}
      }
    }
    
    //記録チェック
    cin >> sque;
    for(i=0;i<sque;i++){
      sum = 0;
      cin >> ts >>te >>m;
      for(j=ts-540;j<te-540;j++){
	for(k=0;k<pc;k++){
	  if (record[k][j]==m){
	    sum += 1;
	    break;
	  }
	}
      }
      cout << sum <<endl;
    }

  }
    
  return 0;
}

Measured memory_bytes: 3920
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"4 3 2
" => r"YES",

r"2 3 4
" => r"NO"
}

use std::cmp;
use std::cmp::{max, min};
use std::collections::HashSet;
use std::f32::MAX;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        r: i32,
        g: i32,
        b: i32,
    }

    if (r * 100 + g * 10 + b) % 4 == 0 {
        "YES".to_string()
    } else {
        "NO".to_string()
    }
}


Measured memory_bytes: 4352
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        double r = 0;
        double circle_area = 0.0;
        double circumference = 0.0;

        double pi = Math.PI;

        Scanner sc= new Scanner(System.in);

        r = sc.nextDouble();

        circle_area = pi * r * r;
        circumference = 2 * pi * r;


        System.out.println( BigDecimal.valueOf(circle_area).toPlainString() + " " + BigDecimal.valueOf(circumference).toPlainString());
        sc.close();
    }
}


Measured memory_bytes: 28300
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   int n;
   string s;
   cin>>s;
   n=s.size();
   rep(i,n){
    cout<<"x";
   }
   cout<<endl;
}

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

using namespace std;
#define ll long long
#define fr(i,s,e) for(i=s;i<e;i++)

int main(){
    ll n,i,ans=0,ans1=0,ans2=0,b;
    cin>>n;
    ll a[n];
    fr(i,0,n){
    cin>>a[i];
    a[i]=a[i]-1-i;
    }
    sort(a,a+n);
    if(n%2==1){
        b=a[n/2];
        fr(i,0,n)
        ans1=ans1+abs(a[i]-b);
       ans=ans1;
    }
    else{
        b=(a[n/2-1]+a[n/2])/2;
        fr(i,0,n)
        ans=ans+abs(a[i]-b);
    }
    cout<<ans;
return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T> inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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

	ll n; cin >> n;

	vector<int> a(n); rep(i,n) {cin >> a[i]; if (n % 2 == a[i] % 2) { cout << 0 << endl; return 0;}}

	sort(all(a));
	vector<ll> b((n+1)/2);
	rep(i, n) {
	  b[a[i]/2]++;
		if (b[a[i]/2] > 2) {cout << 0 << endl; return 0;}
		if (a[i] == 0 && b[0] > 1){ cout << 0 << endl; return 0;}
	}

	ll ans = 1;
	rep(i, n / 2) {
	  ans <<= 1;
		ans %= MOD;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = k; i <= b; i += k) {
        if (a <= i && i <= b) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  double a[n+1];
  double s=0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    s=s+a[i];
  }
  double z=s/(4*m);
  int count=0;
  for(int i=0;i<n;i++)
  {
    if(a[i]>=z)
      count++;
  }
  if(count>=m)
  {
    cout<<"Yes";
  }
  else
  {
    cout<<"No";
  }
}

Measured memory_bytes: 256
# abc110_b


def solve(empireA, empireB):
    if min(empireB) - max(empireA) >= 1:
        return "No War"
    else:
        return "War"


if __name__ == "__main__":
    firstline = list(map(int, input("").split(" ")))
    empireA = list(map(int, input("").split(" ")))
    empireB = list(map(int, input("").split(" ")))
    empireA.append(firstline[2])
    empireB.append(firstline[3])
    print(solve(empireA, empireB))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define INF 1ll<<60
using namespace std;
bool cmd(pair<int,int> a,pair<int,int> b){
  return a.second<b.second;
}
signed main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int N;
  cin>>N;
  vector<pair<int,int> >vet(N);
  int a,b;
  for(int i=0;i<N;i++){
    cin>>a>>b;
    vet[i]=make_pair(a,b);
  }
  sort(vet.begin(),vet.end(),cmd);
  int aux=0;
  for(int i=0;i<N;i++){
    if(vet[i].second-aux>=vet[i].first){
      aux+=vet[i].first;
    }
    else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 3456
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

N,M=rl()

if N==1:
    if M==1:
        print(1)
    else:
        print(M-2)
else:
    if M==1:
        print(N-2)
    else:
        print((N-2)*(M-2))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int a,b;cin>>a>>b;
    int sum=1;
    int cnt = 0;
    while(sum<b){
        cnt++;
        sum = sum+a-1;
    }
    co(cnt);
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
    unsigned int inputN, total = 0;
    int inputK, tmp;

    scanf("%u%d", &inputN, &inputK);
    for (int index = 0; index < inputN; index++)
    {
        scanf("%d", &tmp);
        if (tmp >= inputK)
        {
            total++;
        }
    }

    printf("%u", total);

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
#define si scanf
#define so printf
#define N 100100
#define M 
#define INF  
template<typename TP>inline bool rd(TP& r)
{
	r=0;
	char tmp=getchar();
	while(tmp<'0'||tmp>'9')
	{
		if(tmp==EOF)
			return 0;
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		r=(r<<3)+(r<<1)+tmp-'0';
		tmp=getchar();
	}
	return 1;
	
} 
int n; 
long long s[N],b[N];
map<long long,long long> cnt;
int main()
{
	rd(n);
	for(int i=1;i<=n;++i)
	{
		rd(s[i]);
		b[i]=s[i];
		if(cnt.count(s[i])==0)
			cnt[s[i]]=1;
		else
			++cnt[s[i]];
	}
	long long ans=0;
	sort(b+1,b+n+1);
	n=unique(b+1,b+n+1)-(b+1);
	for(int i=1;i<=n;++i)
		if(b[i]>cnt[b[i]])
			ans+=cnt[b[i]];
		else
			ans+=cnt[b[i]]-b[i];
	so("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int n,h,w;
	cin >> n >> h >> w;
	cout << (n - h + 1) * (n - w + 1) << 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;

int main(){
    int n,m;
    int c=0;
    double s=0;
    cin>>n>>m;

    vector<int> a(n);

    rep(i,n){
        cin>>a.at(i);
        s=s+a.at(i);
    }

    double t=s/(4*m);

rep(i,n){
    if(a.at(i)>=t){
        c++;
    }
}

  
if(c>=m){
    cout<<"Yes"<<endl;}
    if(c<m){cout<<"No"<<endl;}
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

const ll MAX = 510000;
const ll MOD = 1000000007;

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

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

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


int main() {
    ll N; cin >> N;    
    init_ncr();
    vector<ll> A(N+1);
    map<ll,ll> M;
    bool found = false;
    ll L, R;
    rep(i, N+1) {
        cin >> A.at(i);
        if (!found) {
            if (M.count(A[i]) > 0) {
                L = M[A[i]] + 1; // 1-base
                R = i + 1;
                found = true;
            } else {
                M[A[i]] = i;
            }
        }
    }

    for (ll k = 1; k < N + 2; k++) {
        ll res;
        if (L+N-R >= k - 1)
            res = (modncr(N+1,k) - modncr(L+N-R, k-1));
        else
            res = modncr(N+1,k);
        if (res < 0) res += MOD;
        cout << res << endl;
    }
}


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

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
      cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    for (int i = 1; i < N; i+=2) {
      vec.at(i) *= -1;
    }
    int answer = 0;
    for (int i = 0; i < N; i++) {
      answer += vec.at(i);
    }
    cout << answer << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int[] count = new int[26];

		for (int i = 0; i < count.length; i++) {
			count[i] = 0;
		}
		for (int i = 0; i < s.length(); i++) {
			
			count[s.charAt(i)-'a']++;
		}

		for (int i = 0; i < count.length; i++) {
			if(count[i]>=2) {
				System.out.println("no");
				return;
			}
		}
		System.out.println("yes");
	}

}

Measured memory_bytes: 21844
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n = II()
ans = 1
if n == 1:
    print(1)
    exit()
for i in range(1, n+1):
    ans = i ** 2
    if ans > n:
        print((i-1) ** 2)
        exit()



Measured memory_bytes: 66028
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0221
{
    class Program
    {
        static void Main(string[] args)
        {

            while (true)
            {
                int[] vs = RArInt();
                if (vs.Sum() == 0) break;

                Queue<int> players = new Queue<int>();
                for (int i = 1; i <= vs[0]; i++) players.Enqueue(i);

                for (int i = 1; i <= vs[1]; i++)
                {
                    string state = RSt();
                    if (players.Count() > 1)
                    {                      
                        int tmp = players.Dequeue();
                        if (state == GetCorrectAnswer(i)) players.Enqueue(tmp);
                    }
                }
                Console.WriteLine(WAr(players.OrderBy(x => x)));
            }
        }

        static string GetCorrectAnswer(int n)
        {
            if (n % 15 == 0) return "FizzBuzz";
            if (n % 5 == 0) return "Buzz";
            if (n % 3 == 0) return "Fizz";
            return n.ToString();
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 20844
#include<stdio.h>

int main(void){
  int i,j;
  int card[5],cardnum[13];
  char hoge;
  int rs;//roop stop
  int three_card_flag,
      two_pair_flag,
      one_pair_flag;

  for(;scanf("%d%c%d%c%d%c%d%c%d",
        &card[0],&hoge,
        &card[1],&hoge,
        &card[2],&hoge,
        &card[3],&hoge,
        &card[4])==9;){
    //initialize
    rs=0;
    for(i=0;i<13;i++)
      cardnum[i]=0;
    three_card_flag=0;
    one_pair_flag=0;
    two_pair_flag=0;

    for(i=0;i<5;i++)
      cardnum[card[i]-1]++;

    //four card
    for(i=0;i<13;i++)
      if(cardnum[i]==4){
        printf("four card\n");
        rs=1;
        break;
      }

    if(rs) continue;
    ////three card
    for(i=0;i<13;i++)
      if(cardnum[i]==3){
        three_card_flag=1;
        break;
      }
    ////one pair
    for(i=0;i<13;i++)
      if(cardnum[i]==2){
        one_pair_flag=1;
        break;
      }
    i++;
    ////two pair
    for(;i<13;i++)
      if(cardnum[i]==2){
        two_pair_flag=1;
        break;
      }
    //full house
    if(three_card_flag && one_pair_flag){
      printf("full house\n");
      continue;
    }

    //straight
    if( cardnum[0] &&
        cardnum[9] &&
        cardnum[10] &&
        cardnum[11] &&
        cardnum[12]){
      printf("straight\n");
      continue;
    }
    for(i=0;i<9;i++)
      if(cardnum[i]==1)
        if( cardnum[i+1]==1 &&
            cardnum[i+2]==1 &&
            cardnum[i+3]==1 &&
            cardnum[i+4]==1){
          printf("straight\n");
          rs=1;
          break;
        }

    if(rs) continue;
    //three card
    if(three_card_flag){
      printf("three card\n");
      continue;
    }

    //two pair
    if(two_pair_flag){
      printf("two pair\n");
      continue;
    }

    //one pair
    if(one_pair_flag){
      printf("one pair\n");
      continue;
    }

    printf("null\n");
  }

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(){

    int m,f,r,i,count=0;
    int grade[1000];
    int re[1000];
    
    for (i=0; ; i++)
    {
        scanf("%d %d %d",&m,&f,&r);
        grade[i]=m+f;
        re[i]=r;
        count=count+1;
        if (m==-1||f==-1)
        {
            grade[i]=-1;
        }
        if (m==-1&&f==-1&&r==-1)
        {
            grade[i]=-100;
            break;
        }
        
    }
    for (i=0; i<count; i++)
    {
        if (grade[i]==-100&&r==-1)
                break;
        else if (grade[i]==-1)
            printf("F\n");
        else if (grade[i]>=80)
            printf("A\n");
        else if(grade[i]>=65)
            printf("B\n");
        else if(grade[i]>=50)
            printf("C\n");
        else if(grade[i]>=30)
        {
            if (re[i]>=50)
                printf("C\n");
        else
            printf("D\n");
        }
        else if (grade[i]<30)
            printf("F\n");
    }
    return 0;
    
   }

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;
  cin >> n >> m;
  if(n == 1){
    cout << 1 << endl;
    return 0;
  }
  if(m == 1){
    cout << n << endl;
    return 0;
  }
  vector<vector<ll>> like(n,vector<ll>(m));
  for(int i = 0;i < n;i++){
    for(int j = 0;j < m;j++){
      cin >> like[i][j];
      like[i][j]--;
    }
  }
  ll res = 0;
  res = 100000;
  vector<bool> play(m);
  for(int i = 0;i < m;i++)play[i] = true;
  for(int i = 0;i < m - 1;i++){
    vector<ll> now(m);
    for(int j = 0;j < m;j++)now[j] = 0;
    for(int j = 0;j < n;j++){
      for(int k = 0;k < m;k++){
        if(play[like[j][k]]){
          now[like[j][k]]++;
          k = m;
        }
      }
    }
    ll big = 0;
    ll bn = 0;
    for(int j = 0;j < m;j++){
      if(big < now[j]){
        big = now[j];
        bn = j;
      }
    }
    res = min(res,big);
    play[bn] = false;
  }
  cout << res << endl;
}

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

int main(){
  int i,j;ll cnt=0;
  int n,q;
  string s;
  cin>>n>>q;
  cin>>s;
  s=' '+s;
  int l[q],r[q];
  for(i=0;i<q;i++)cin>>l[i]>>r[i];
  int a[n+1];
  a[0]=0;
  for(i=1;i<=n;i++){
    if((i!=n && s[i]=='A' && s[i+1]=='C') || (s[i-1]=='A' && s[i]=='C')){
      a[i]=a[i-1]+1;
    }else a[i]=a[i-1];
  }
  for(i=0;i<q;i++){    
    cout<<(a[r[i]]-a[l[i]-1]-(a[r[i]]%2+a[l[i]-1]%2))/2<<endl;
  }
}

Measured memory_bytes: 2172
#include <iostream>
#include <vector>
#include <utility>
#include <queue>

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> a(n), b(n);
	priority_queue<pair<int, int> > pq;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) cin >> b[i];
	for (int i = 0; i < n; ++i) pq.push(make_pair(b[i], i));
	long long ans = 0;
	while (!pq.empty()) {
		int now = pq.top().second; pq.pop();
		int dif = b[now] - a[now];
		int tmp = b[(now - 1 + n) % n] + b[(now + 1) % n];
		if (dif != 0 && dif < tmp) {
			ans = -1;
			break;
		}
		ans += dif / tmp;
		b[now] -= dif / tmp * tmp;
		if (b[now] != a[now]) pq.push(make_pair(b[now], now));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3956
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}


void solve(int test) {
	string a,b; cin >> a >> b ;
	int n = sz(a) ;
	int ans = 0 ;

	rep(i,0,n) {
		if(a[i]!=b[i]) ++ans; 
	}
	cout << ans ;
}
 
int32_t main() {

    fast;
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

N = int(input())
XY = [[set() for i in range(10**5+1)] for j in range(2)]
for i in range(N):
  x, y = map(int, input().split())
  XY[0][x].add(y)
  XY[1][y].add(x)

is_visited_x = [False] * (10**5 + 1)
def dfs(x):
  global is_visited_x
  is_visited_x[x] = True
  stack = [[x], []]
  idx = 0
  num_e = 0
  num_xy = [1, 0]
  parent = 0
  while stack[0] or stack[1]:
    node = stack[idx][-1]
    children = XY[idx][node]
    if children:
      child = children.pop()
      XY[idx-1][child].remove(node) # 今来た道を削除
      num_e += 1
      if child in stack[idx-1]:
        continue
      stack[idx-1].append(child)
      num_xy[idx-1] += 1
      is_visited_x[child] += idx
      idx = (idx + 1) % 2
    else:
      stack[idx].pop()
      idx = (idx + 1) % 2
  return num_e, num_xy

ans = 0
for x in range(1, 10**5+1):
  if is_visited_x[x]:
    continue
  num_e, num_xy = dfs(x)
  ans += num_xy[0]*num_xy[1] - num_e

print(ans)

Measured memory_bytes: 80756
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;

int main() {
    int N, L;
    string Sc, tmp;
    vector<string> S;

    cin >> N >> L;

    for (int i = 0; i < N; i++) {
        cin >> tmp;
        S.push_back(tmp);
    }

    sort(S.begin(), S.end());

    for (int i = 0; i < N; i++) {
        Sc += S[i];
    }

    cout << Sc;
}



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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

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

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int N,M;
    scanf("%d%d",&N,&M);

    //X[0]~X[M-1]に格納→昇順ソート
    int* X;
    NEW(X,M);
    for(int i=0;i<M;i++){
        scanf("%d",&X[i]);
    }
    qsort(X,M,sizeof(int),asc);


    long ans=0;
    if(N<M){
        //X座標の差を配列Yに格納→昇順ソート
        int* Y;
        NEW(Y,M-1);
        for(int i=0;i<M-1;i++){
            Y[i]=X[i+1]-X[i];
        }
        qsort(Y,M-1,sizeof(int),asc);

        int j=0;
        while(M>N){
            ans+=Y[j];
            j++;
            M--;
        }
    }
    printf("%ld\n",ans);

    return 0;
}

Measured memory_bytes: 1396