akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    string s,t;
    
    cin >> s >> t;
    
    int res;
    int ans = 100000;
    for (int i = 0;i <= s.size()-t.size();i++){
        res = 0;
        for (int j = 0;j < t.size();j++){
            if (t[j] != s[i+j]){
                res++;
            }
        }
        ans = min(res,ans);
    }
    
    cout << ans << endl;
}


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

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

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

//#define int long long

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

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

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

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

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


VL A;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; cin >> N;
    A.resize(N);
    REP(i,N) cin >> A[i];
    LL ok = 1e18;
    LL ng = -1;
    while(abs(ok-ng) > 1){
        LL mid = (ok+ng) / 2;
        LL cnt = 0;
        REP(i,N){
            cnt += (A[i]+mid-(N-1)+N) / (N+1);
        }
        if(cnt <= mid) ok = mid;
        else ng = mid;
    }

    for(LL t = max(0LL,ok-5000); t <= ok + 5000; t++ ){
        LL cnt = 0;
        REP(i,N){
            cnt += (A[i]+t-(N-1)+N) / (N+1);
        }
        if(cnt <= t){
            cout << t << endl;
            return 0;
        }
    }



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rt insert
#define st first
#define nd second
#define lolo long long
#define pii pair < int , int >
#define DB printf("debug\n");
#define all(x) x.begin() , x.end()
using namespace std;
string s;
lolo sz,sp;
vector < lolo > freq(255);
int main(){
	//cin.tie(0);ios_base::sync_with_stdio(0);
	cin>>s;
	sz=s.length();
	for(int i=0;i<sz;i++)
		freq[s[i]]++;
	for(int i=0;i<255;i++){
		lolo asd=freq[i]*(freq[i]-1);
		sp+=asd/2;
	}
	cout<< 1 + sz*(sz-1)/2 - sp <<endl;
	return 0;
}

Measured memory_bytes: 640
def main():
    import sys
    input = sys.stdin.readline
    N, M = map(int, input().split())
    a = [0] * (1 + 10 ** 5)
    for _ in range(M):
        a[int(input())] = 1
    dp = [0] * (N + 1)
    dp[0] = 1
    if a[1]:
        pass
    else:
        dp[1] = 1

    for i in range(2, N + 1):
        if  a[i]:
            pass
        else:
            dp[i] += dp[i-1] + dp[i-2]
            dp[i] %= 1000000007

    print(dp[N])

main()


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


using Graph=vector<vector<int>>;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> d(n);
    Graph g(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        d[a]++,d[b]++;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        if(d[i]%2==1){
            cout<<"No"<<endl;
            return 0;
        }
    }

    vector<int> fv;
    for(int i=0;i<n;i++){
        if(d[i]>=6){
            cout<<"Yes"<<endl;
            return 0;
        }
        if(d[i]==4){
            fv.push_back(i);
        }
    }
    if(fv.size()>=3){
        cout<<"Yes"<<endl;
        return 0;
    }
    else if(fv.size()<=1){
        cout<<"No"<<endl;
        return 0;
    }
    
    function<bool(int,int)> dfs=[&](int v,int pre){
        if(v==fv[0] && pre!=-1) return true;
        else if(v==fv[1]) return false;
        bool ret=false;
        for(auto to:g[v]){
            if(pre==to) continue;
            if(dfs(to,v)) return true;
        }
        return false;
    };
    if(dfs(fv[0],-1)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define read_input         freopen("in.txt","r", stdin)
#define print_output       freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;

int sign(int x) {
    if(x > 0) return 1;
    else if(x < 0) return 0;
    else return -1;
}

ll f(ll t, int pre, int s) {
    if(s == 0) return abs(-1-pre-t);
    else return abs((1-t)-pre);
}

int main() {
    int n, a[100005];

    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];

    ll ans1 = 0, ans2 = 0;
    
    int s = 1;
    ll x = 0, tmp;
    for(int i = 1; i <= n; i++, s ^= 1) {
        tmp = x;
        x += a[i];
        if(sign(x) != s) ans1 += f(tmp, a[i], s);

        if(not s) x = min(-1LL, x);
        else x = max(1LL, x);
    }

    s = 0, x = 0;
    for(int i = 1; i <= n; i++, s ^= 1) {
        tmp = x;
        x += a[i];
        if(sign(x) != s) ans2 += f(tmp, a[i], s);

        if(not s) x = min(-1LL, x);
        else x = max(1LL, x);
    }

    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

int main(){
int a,b;
cin>>a>>b;
int ans;
if(a>b){
    ans=a-1;
}
else{
    ans=a;
}
cout<<ans<<endl;
 return 0;
}
/*
5 5

5

2 1

1

*/

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

public class Main{
      static int N=200+10;
      static int MOD=(int)1e9+7;
      static int solve(char[] a,char[] b) {
    	  int n=a.length,m=b.length;
    	  int ans=0;
    	  long ah=0,bh=0,t=1;
    	  for(int i=1;i<=Math.min(n,m);i++) {
    		  ah=(ah+a[n-i]*t)%MOD;
    		  bh=(bh*3+b[i-1])%MOD;
    		  if(ah==bh) ans=i;
    		  t=(t*3)%MOD;
    	  }
    	  return ans;
      }
      
      public static void main(String[] args){
          InputReader in=new InputReader(System.in);
          //Scanner sc=new Scanner(new InputStreamReader(System.in));
          PrintWriter out=new PrintWriter(System.out);
    	  int n=in.nextInt();
          String s1=in.next(),str=in.next();
          int cnt=0;
          out.println(2*n-solve(s1.toCharArray(),str.toCharArray()));
          out.flush();
      }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}


Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;

int main() {
	int n;
	cin >> n;
	i64 sum = 0;
	vector<int> a(n+1);
	ff(i, 1, n+1) {
		cin >> a[i];
		sum += a[i];
	}

	vector<int> ans(n+1);

	i64 ex = 0;
	for (int i = 2; i < n;i+=2) {
		ex += 2 * a[i];
	}
	ans[1] = sum - ex;
	ff(i, 2, n + 1) {
		ans[i] = 2 * a[i - 1] - ans[i - 1];
	}
	ff(i, 1, n + 1) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
const int N=305;

int n,a[N][N],b[N][N];
long long ans;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			cin >> a[i][j];
			if (i==j&&a[i][j]){
				cout << "-1\n";
				return 0;
			}
			b[i][j]=a[i][j];
		}
	}
	for (int k=1;k<=n;k++){
		for (int i=1;i<=n;i++){
			for (int j=1;j<=n;j++){
				b[i][j]=min(b[i][j],
				b[i][k]+b[k][j]);
			}
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if (a[i][j]!=b[i][j]){
				cout << "-1\n";
				return 0;
			}
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=i+1;j<=n;j++){
			int no=1;
			for (int k=1;k<=n;k++){
				if (k!=i&&k!=j&&
				a[i][k]+a[k][j]==a[i][j]){
					no=0;
				}
			}
			ans+=no*a[i][j];
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1024
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
#include<bits/stdc++.h>
using namespace std;
int n,sum;
char x;
queue<char> q;
int main()
{
	cin>>n;
	while(n--)
	{
		cin>>x;
		q.push(x);
	}
	char last=' ';
	while(q.size())
	{
		x=q.front();
		q.pop();
		if(x!=last)
		{
			sum++;
			last=x;
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 384
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    K = II()
    if K <= 10:
            print(K)
            return
    x = [0]
    x = [0,1]
    for _ in range(K-10):
        # print(x)
        c = 1
        for j in range(len(x)):
            if c == 0:
                break
            x[j] += 1
            c = x[j] // 10
            x[j] %= 10
        if c == 1:
            x.append(1)


        for i in range(1,len(x)):
            d = x[i] - x[i-1]
            if d < -1:
                c = 1
                for j in range(i,len(x)):
                    if c == 0:
                        break
                    x[j] += 1
                    c = x[j] // 10
                    x[j] %= 10
                if c == 1:
                    x.append(1)
                for j in range(i,0,-1):
                    x[j-1] = max(x[j] - 1,0)
            elif d > 1:
                x[i-1] = x[i] - 1
        for i in range(len(x)-1,0,-1):
            if x[i] - x[i-1] > 1:
                x[i-1] = x[i] -1

    
    ans = 0
    # print(x)
    for i in x[::-1]:
        ans *= 10
        ans += i
    print(ans)
    

    
    

if __name__ == '__main__':

    main()

Measured memory_bytes: 70504
#include "bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define all(v,a,b) v.begin(a),v.end(b)
#define in cin>>
#define out cout<<
#define endl <<endl
#define INF 100000000000

int main()
{
	int N;
	in N;
	out fixed << setprecision(8);
	vector<vector<int>> p(N,vector<int>(2));
	rep(i, N)
	{
		in p.at(i).at(0) >> p.at(i).at(1);
	}
	vector<vector<double>> l(N, vector<double>(N));
	rep(i, N)
	{
		rep(j, N)
		{
			if (i != j)
			{
				l.at(i).at(j) = sqrt(pow(p.at(i).at(0) - p.at(j).at(0), 2) + pow(p.at(i).at(1) - p.at(j).at(1), 2));
			}
		}
	}
	double ans = 0;
	int x = 1;
	rep(i, N)
	{
		rep(j, N)
		{
			if (i != j)
			{
				ans += l.at(i).at(j);
			}
		}
	}
	if (N != 1)
	{
		rep(i, N)
		{
			if (i == 0)
			{
				continue;
			}
			ans *= i;
		}
	}
	rep(i, N + 1)
	{
		if (i == 0)
		{
			continue;
		}
		x *= i;
	}
	out ans / x endl;
}


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

int main(){
  int N;
  cin>>N;
  int sum =0;
  
  for (int i = 0;i<N;i++) {
    int a;
    int b;
    cin>>a>>b;
    int c = b-a+1;
    sum += c;
  }
  
  cout<<sum<<endl;
}
    

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#from bisect import insort_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
#import heapq
#import numpy as np
N,Q = map(int,input().split())
tree = [[] for _ in range(N)]
cnt = [0]*N
for _ in range(N-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
for _ in range(Q):
    p,x = map(int,input().split())
    cnt[p-1] += x
sys.setrecursionlimit(10 ** 6)
def dfs(cur,parent):
    li = tree[cur]
    for chi in li:
        if chi == parent:
            continue
        cnt[chi] += cnt[cur]
        dfs(chi,cur)
dfs(0,-1)
print(*cnt)


Measured memory_bytes: 230960
s = gets.chomp
ok = true
if s[0] != 'A'
  ok = false
end
u = (s[2..-2].split("")).sort
if u[0] != 'C'
  ok = false
end
u << s[1]
u << s[-1]
for i in 1 .. u.size - 1
  if u[i] <= 'Z'
    ok = false
  end
end
puts (ok ? 'AC' : 'WA')


Measured memory_bytes: 1788
N = int(input())
V = list(map(int, input().split()))

vals = V[:]

import heapq
# ヒープ化
heapq.heapify(vals)
#print(vals)

while len(vals) != 1:
    min_1 = heapq.heappop(vals)
    min_2 = heapq.heappop(vals)
    
    heapq.heappush(vals, (min_1+min_2)/2)
    
print(vals[0])

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

int main() {
	int n,q;
	cin >> n;
	vector<int> na(n,0);
	for(int i=0;i<n;++i) scanf("%d", &na[i]);
	cin >> q;
	vector<int> qa(q,0);
	for(int i=0;i<q;++i) scanf("%d", &qa[i]);
	
	// linear search
	vector<int> ans;
	for(int i=0;i<q;++i) {
		for(int j=0;j<n;++j) {
			if(qa[i] == na[j]) {
				ans.push_back(qa[i]); 
				break;
			}
		}
	}
	cout << ans.size() << endl;
	/*
	for(int i=0;i<ans.size();++i){
		if(i>0) cout << " ";
		cout << ans[i];
	}
	cout << endl;
	*/
	return 0;
}



Measured memory_bytes: 3240
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}
int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n;
	cin>>n;
	int a[n];
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		if(x%2==0)
		{
			if(x%3!=0 && x%5!=0)
				ans=1;
		}
	}
	if(ans)
		cout<<"DENIED";
	else
		cout<<"APPROVED";


}
signed main()
{
	fastio;
//	test
		solve();
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	READ(s);
	cout << 0 << " " << 0 << " ";
	
	int x = sqrt(s);
	if (x*x != s) x++;
	
	int d = x*x - s;
	if (d <= 1e9) cout << x << " " << 1 << " " << d << " " << x;
	else cout << x << " " << 1 << " " << x*(x - 1) - s << " " << x - 1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}




int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	ll a;
	cin >> a;

	cout << a + a * a + a * a * a << endl;


	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; string S; cin >> N >> S;
    int cnt = 0;
    for (int i = 0; i < N - 2; ++i) {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') cnt++;
    }
    printf("%d\n", cnt);
}


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

int main()
{
  char n[5];
  cin >> n;
  
  if( n[0] == n[1] && n[1] == n[2] || n[1] == n[2] && n[2] == n[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

ll H, W, maxDist = 0; 
vector<vector<char>> maze;
vector<pair<ll, ll>> point;
vector<ll> dy = {0, 1, 0, -1};
vector<ll> dx = {1, 0, -1, 0};

ll bfs(pair<ll, ll> start, pair<ll, ll> goal)
{
	vector<vector<ll>> dist(H + 2, vector<ll>(W + 2, -1));
  	queue<pair<ll, ll>> Q;
  	dist[start.first][start.second] = 0;
  	Q.push(start);
  
  	while(!Q.empty()) {
    	pair<ll, ll> v = Q.front(); Q.pop();
      	rep(i, 0, 4) {
        	pair<ll, ll> nv = make_pair(v.first + dx[i], v.second + dy[i]);
          	if (dist[nv.first][nv.second] != -1 || maze[nv.first][nv.second] == '#') {
            	continue;
            }
          	dist[nv.first][nv.second] = dist[v.first][v.second] + 1;
          	Q.push(nv);
        }
    }
  	return dist[goal.first][goal.second];
}

int main()
{
  cin >> H >> W;
  maze = vector<vector<char>>(H + 2, vector<char>(W + 2));
  rep(j, 0, W + 2) {
  	maze[0][j] = '#';
  }
  rep(i, 1, H + 1) {
  	maze[i][0] = '#';
    maze[i][W + 1] = '#';
  }
  rep(j, 0, W + 2) {
  	maze[H + 1][j] = '#';
  }
  rep(i, 1, H + 1) {
    rep(j, 1, W + 1) {
    	cin >> maze[i][j];
      	if (maze[i][j] == '.') {
        	point.emplace_back(i, j);
        }
    }
  }
  rep(s, 0, point.size() - 1) {
  	rep(g, s + 1, point.size()) {
    	ll d = bfs(point[s], point[g]);
      	if (maxDist < d) maxDist = d;
    }
  }
  cout << maxDist << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int cmp(const void *a,const void *b)
{
    return (*(double*)a-*(double*)b);
}
int main ()
{
    int n,i;
    double a[50],s;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%lf",&a[i]);
    qsort(a,n,sizeof(double),cmp);
    s=(a[0]+a[1])/2;
    for(i=2;i<n;i++)
        s=(s+a[i])/2;
    printf("%lf\n",s);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        if(Math.abs(x - a) < Math.abs(x - b)){
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
}

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

using namespace std;

map <string, int> cnt;
string s[200005];

int main() {
	int n;
	scanf("%d", &n);
	
	int mx = 0;
	
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		cnt[s[i]]++;
		
		mx = max(cnt[s[i]], mx);
	}
	
	vector <string> sol;
	
	for (int i = 0; i < n; i++) {
		if (cnt[s[i]] == mx) {
			cnt[s[i]] = 0;
			sol.push_back(s[i]);
		}
	}
	
	sort(sol.begin(), sol.end());
	
	for (int i = 0; i < sol.size(); i++) cout << sol[i] << endl;
}


Measured memory_bytes: 29940
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	string S;
	
	cin >> S;
	
	if(S=="zyxwvutsrqponmlkjihgfedcba")
	{
		cout << -1 << endl;
		return 0;
	}
	
	if(S.size()==26)
	{
		int al[26]={};
		int index=0;
		for(int i=S.size()-1;i>0;i--)
		{
			al[S[i]-'a']++;
			if(S[i-1]<S[i])
			{
				for(int j=(int)(S[i-1]+1-'a');j<26;j++)
				{
					if(al[j]==1)
					{
						S[i-1]=char(j+'a');
						index=i;
						break;
					}
				}
				break;
			}
		}
		for(int i=0;i<index;i++)
			cout << S[i];
		cout << endl;
		return 0;
	}
	
	int al[26]={};
	for(int i=0;i<S.size();i++)
		al[S[i]-'a']++;
	
	cout << S;
	for(int i=0;i<26;i++)
	{
		if(al[i]==0)
		{
			cout << (char)('a'+i);
			break;
		}
	}
	cout << endl;
	return 0;
}

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

void main_()
{
    ll K, A, B;
    cin >> K >> A >> B;

    ll ans = 1;
    if (A >= B - 2) {
        // B-A <= 2の場合、変換しても増えないのでK回ビスケットを増やすのが最大
        ans += K;
    } else {
        for (ll count = 0; count < K;) {
            if (count == K - 1) {
                // 残り1回なら1個増やす
                ans++;
                count++;
            } else if (ans < A) {
                // ビスケットがA枚以下ならA枚まで増やす
                auto inc = min(A - ans, K - count);
                ans += inc;
                count += inc;
            } else {
                // A枚以上あるならA枚→1円→B枚をできるだけ行う
                auto conv_num = (K - count) / 2;
                ans += (B - A) * conv_num;
                count += conv_num * 2;
            }
        }
    }

    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
use proconio::*;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };
    let mut t = vec![100; d];
    let mut lasts = [-1; 26];
    // let mut score = 0;

    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let cur_score = calc_score(i, j, &c, &s, &mut lasts);
            if cur_score > max_score {
                max_score = cur_score;
                t[i] = j;
            }
        }
        lasts[t[i]] = i as i64;
        // score += max_score;
    }
    // println!("{}", score);

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}


Measured memory_bytes: 2296
#include<stdio.h>
int main(void){
    int n,k,x,y;
    int a,b,c,d,e,f,g,h,i,j;
    scanf("%d",&n);
    scanf("%d",&k);
    if(n%2==1){//1
        for(a=0;a<k;a++){
            scanf("%d%d",&x,&y);
            if(x+y<=n+1){//2
                if(x<=y){//3
                    if(x%3==0){
                        printf("3\n");
                    }
                    else{
                        printf("%d\n",x%3);
                    }
                }
                else{//3
                    if(y%3==0){
                        printf("3\n");
                    }
                    else{
                        printf("%d\n",y%3);
                    }
                }
            }
            else if(x+y>n+1){//2
                if(x<=y){//3
                    if((n-y)%3+1==0){
                        printf("3\n");
                    }
                    else{
                        printf("%d\n",(n-y)%3+1);
                    }
                }
                else{//3
                    if((n-x)%3+1==0){
                        printf("3\n");
                    }
                    else{
                        printf("%d\n",(n-x)%3+1);
                    }
                }
            }
        }
    }
    else if(n%2==0){//1
        for(a=0;a<k;a++){
            scanf("%d%d",&x,&y);
            if(x+y<=n+1){//2
                if(x<=y){//3
                    if(x%3==0){
                        printf("3\n");
                    }
                    else{
                        printf("%d\n",x%3);
                    }
                }
                else{//3
                    if(y%3==0){
                        printf("3\n");
                    }
                    else{
                        printf("%d\n",y%3);
                    }
                }
            }
            else if(x+y>n+1){//2
                if(x<=y){//3
                    if((n-y)%3+1==0){
                        printf("3\n");
                    }
                    else{
                        printf("%d\n",(n-y)%3+1);
                    }
                }
                else{//3
                    if((n-x)%3+1==0){
                        printf("3\n");
                    }
                    else{
                        printf("%d\n",(n-x)%3+1);
                    }
                }
            }
        }
    }
    return 0;
}

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

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	
	int n,i;
	cin>>n;

	int a[n+1];
	for(i=1;i<=n;i++)
	cin>>a[i];
	
	int ch[n+1];
	for(i=1;i<=n;i++){
		ch[i] = i - a[i];

	}

	map<int,int> m;

	for(i=1;i<=n;i++){
		m[abs(a[i]+i)]++;
	}

	long long int ans = 0;
	for(i=1;i<=n;i++){
		ans += m[ch[i]];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 22192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		String s = sc.next();
		StringBuilder sb = new StringBuilder();
		if(s.length() > k) {
			sb.append(s.substring(0, k));
			sb.append("...");
			System.out.println(sb);
		} else {
			System.out.println(s);
		}

	}

}


Measured memory_bytes: 35816
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
 
using namespace std;
 
int main()
{
    string s;
    cin >> s;
 
    long tsum = 0;
    for (int i = 0; i < (1 << s.size()-1); i++) {
        long sum = 0;
        long term = 0;
        for (int j = 0; j < s.size(); j++) {
            term = term * 10 + (s[j] - '0');
            if (i & (1 << j)) {
                sum += term;
                term = 0;
            }
        }
        sum += term;
        tsum += sum;
    }
    cout << tsum << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var X = IO_ShortCut.ReadInt;

            var a = X / 500;
            var b = (X - a * 500) / 5;
            WriteLine(1000 * a + 5 * b);
        }
    }

    public class IO_ShortCut
    {
        #region Input
        public static string ReadString => ReadLine();
        public static int ReadInt => int.Parse(ReadLine());
        public static long ReadLong => long.Parse(ReadLine());
        public static double ReadDouble => double.Parse(ReadLine());

        public static List<string> ReadSplitString => ReadLine().Split().ToList();
        public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
        public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
        public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        #endregion
    }

    public class Mod
    {
        // 割る数の定義
        private readonly static long M = 1000000007;

        // 足し算?
        public static long Add(long a, long b)
        {
            var result = a + b;
            if (a + b < 0)
                return result % M == 0 ? result % M : result % M + M;
            else if (a + b >= M)
                return result % M;
            else
                return result;
        }
        // 引き算
        // 割られる数が負になると余りの定義的にダメなので実装
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        // 掛け算
        //    public static long Multi(long a, long b)
        //    {

        //    }
    }

}

Measured memory_bytes: 11092
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, A;
    cin >> X >> A;
    if (X < A)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 10 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k;
char s[100005];
vector<int>v;
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    int ans=0;
    bool flag=true;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='0'&&flag)
            flag=false,v.push_back(i);
        if(s[i]=='1')
            flag=true;
    }
    v.push_back(n+1);
    int pos=0,si=v.size();
    flag=true;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='0'&&flag)
        {
            ans=max(ans,v[min(pos+k,si-1)]-i);
            flag=false,pos++;
        }
        if(s[i]=='1')
        {
            flag=true;
            //cout<<i<<' '<<pos<<' '<<pos+k<<' '<<v[min(pos+k,si-1)]<<endl;
            ans=max(ans,v[min(pos+k,si-1)]-i);
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;

int main(int argc, char* argv[])
{
    vector<int> num(3);
    cin >> num[0] >> num[1] >> num[2];

    sort(num.begin(), num.end());
    
    int ans;
    if (num[0] == num[1]) {
        ans = num[2];
    } else {
        ans = num[0];
    }

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

Measured memory_bytes: 256
<?php



fscanf(STDIN, "%d", $N);

$map = array_fill(1,$N,[]);
for($i=0;$i<$N-1;$i++){
    $tmp = explode(" ", trim(fgets(STDIN)));
    $map[$tmp[0]][$tmp[1]] = $tmp[2];
    $map[$tmp[1]][$tmp[0]] = $tmp[2];
}


$start = 1;
//$goal = 6;
$goal = PHP_INT_MAX; //全探索;
$ans_map = [];
$ans_map[$start] = 0;
$queue = [];

//初期キューの登録
getQueue($map[$start], 0,0);
$i = 0;
while (isset($queue[$i])) {
    getQueue($map[$queue[$i][0]], $queue[$i][1], $queue[$i][2]);
    unset($queue[$i]);
    $i++;
}

ksort($ans_map);
//回答出力
foreach($ans_map as $value){
    echo $value%2 . PHP_EOL;
}



/**
 * @param array $array
 * @param int $last_vec
 * @param int $count
 * @return int
 */
function getQueue(array $array, int $color, $dist)
{
    global $queue, $ans_map;
    foreach ($array as $key => $value) {
        if (!isset($ans_map[$key]) || $ans_map[$key] > ($value + $dist)) {
            $ans_map[$key] = $value + $dist;
            $queue[] = [$key, $ans_map[$key], $dist + $value];
        }
    }

    return 0;

}



Measured memory_bytes: 62840
#include <stdio.h>
#include <string.h>

int main(){
    int m, h;
    char cards[256], temp[256], result[256];
    int i, j=0, len;

    while(1){
        scanf("%s", cards);//??\???
        len=strlen(cards);//???????????????
        if(strcmp(cards, "-")==0&&len==1)break;//???????????????
        scanf("%d", &m);//?????£??????????????°
        
	for(;m>0;m--){
            scanf("%d", &h);//????????????????????°
            strcpy(temp, cards);//?????´
            for(i=0;i<h;i++){
                cards[len-h+i]=temp[i];// 255 a 
            }
            for(i=0;i<len-h;i++){	
                cards[i]=temp[i+h];	//a a b c?????????a
            }
        }

        for(i=0;i<len;i++){
            result[j++]=cards[i];      //a a b c   a
        }
        result[j++]='\n';
    }
    result[j]='\0';
    printf("%s", result);

    return 0;
}

Measured memory_bytes: 608
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto S = new uint[](M);
    foreach (i; 0 .. M)
    {
        foreach (s; aryread()[1 .. $])
        {
            S[i] = S[i] | (1 << (s - 1));
        }
    }
    auto P = aryread();
    long ans;
    outer: foreach (x; 0 .. (1 << N))
    {
        foreach (i; 0 .. M)
        {
            // popcnt(S[i] & x).writeln();
            if ((popcnt(S[i] & x) & 1) != P[i])
            {
                // writefln("%d %d %d", i, S[i], x);
                continue outer;
            }
        }
        ans++;
    }
    writeln(ans);
}


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

using ll = long long;

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

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	double R;
	cin >> R;
	cout << R * 2.0 * M_PI << endl;

	return 0;
}


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

using namespace std;

const int md = 998244353;
const int mxn = 3e3;

long long dp[mxn + 11][mxn + 11];
int a[mxn + 11];

int main(){
	int n, s;
	scanf("%d %d", &n, &s);
	for (int i = 0; i < n; i++){
		scanf("%d", a + i);
	}
	dp[0][0] = 1;
	for (int i = 0; i < n; i++){
		for (int j = 0; j <= s; j++){
			dp[i + 1][j] += 2 * dp[i][j];
			dp[i + 1][j] %= md;
			if (j + a[i] <= s){
				dp[i + 1][j + a[i]] += dp[i][j];
				dp[i + 1][j + a[i]] %= md;
			}
		}
	}
	printf("%d\n", dp[n][s]);
	return 0;
}


Measured memory_bytes: 74324
#include <stdio.h>

int main(void) {
	int kaisuu[100][2];
	int i,j;
	int num;
	int temp;
	for(i=0;i<100;i++) {
		kaisuu[i][0]=0;
		kaisuu[i][1]=i+1;
	}
	while(1) {
		if(scanf("%d",&num)==-1)break;
		kaisuu[num-1][0]++;
	}
	for(i=99;i>0;i--) {
		for(j=0;j<i;j++) {
			if(kaisuu[j][0]<kaisuu[j+1][0]) {
				temp=kaisuu[j][0];
				kaisuu[j][0]=kaisuu[j+1][0];
				kaisuu[j+1][0]=temp;
				temp=kaisuu[j][1];
				kaisuu[j][1]=kaisuu[j+1][1];
				kaisuu[j+1][1]=temp;
			}
		}
	}
	printf("%d\n",kaisuu[0][1]);
	for(i=1;i<100;i++) {
		if(kaisuu[i][0]!=kaisuu[i-1][0])break;
		printf("%d\n",kaisuu[i][1]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int n;cin>>n;
  int k;cin>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.rbegin(), a.rend());
  int l=0,r=1000000000;
  while(l<r){
    ll med=l+(r-l)/2ll;
    if((r-l)%2)med++;
    bool ok=false;
    ll cnt=0;
    for(int i=0;i<n;i++){
      if(a[i]<=med){
        break;
      }
      if(a[i]%med == 0)cnt += (a[i]/med-1);
      else cnt += a[i]/med;
    }
    if(cnt <= k){
      r = med - 1;
    } else {
      l = med;
    }
  }
  cout<<r+1<<endl;
  
  return 0;
}


Measured memory_bytes: 3944
# 最後の計算で(max)-(min)が必要
# max: 最大値 - ∑負の数
# min: 最小値 - ∑正の数

N = int(input())
A = list(map(int, input().split()))
A.sort()

ans = []
low = A[0]
high = A[-1]

for a in A[1:-1]:
    if a > 0:
        ans.append((low, a))
        low = low - a
    else:
        ans.append((high, a))
        high = high - a

ans.append((high, low))

print(high - low)
for (x, y) in ans:
    print(x, y)

Measured memory_bytes: 94200
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner (System.in);
    int B[][]=new int[3][3];
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        B[i][j]=sc.nextInt();}}
    int N =sc.nextInt();
    int M[]=new int[N];
    Integer[] P=new Integer[10];
    for(int k=0;k<N;k++){
      M[k]=sc.nextInt();
      loop:for(int l=0;l<3;l++){
        for(int m=0;m<3;m++){
          if(M[k]==B[l][m]){P[k]=3*l+m+1;break loop;}}}}
    if(Arrays.asList(P).contains(1)){
        if(Arrays.asList(P).contains(2)&&Arrays.asList(P).contains(3)){System.out.println("Yes");System.exit(0);}
        else if(Arrays.asList(P).contains(4)&&Arrays.asList(P).contains(7)){System.out.println("Yes");System.exit(0);}
        else if(Arrays.asList(P).contains(5)&&Arrays.asList(P).contains(9)){System.out.println("Yes");System.exit(0);}}
      if(Arrays.asList(P).contains(5)){
        if(Arrays.asList(P).contains(2)&&Arrays.asList(P).contains(8)){System.out.println("Yes");System.exit(0);}
        if(Arrays.asList(P).contains(3)&&Arrays.asList(P).contains(7)){System.out.println("Yes");System.exit(0);}
        if(Arrays.asList(P).contains(4)&&Arrays.asList(P).contains(6)){System.out.println("Yes");System.exit(0);}}
      if(Arrays.asList(P).contains(9)){
        if(Arrays.asList(P).contains(3)&&Arrays.asList(P).contains(6)){System.out.println("Yes");System.exit(0);}
        if(Arrays.asList(P).contains(7)&&Arrays.asList(P).contains(8)){System.out.println("Yes");System.exit(0);}}
    System.out.println("No");}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<29;
vector<pair<int,ll>> G[MAX];
int siz[MAX];
int N;
vector<int> center;

ll ans=0;

void DFS(int u,int p){
    siz[u]=1;
    bool ok=true;
    for(auto to:G[u]){
        if(to.fi==p) continue;
        DFS(to.fi,u);
        if(siz[to.first]>N/2) ok=false;
        siz[u]+=siz[to.fi];
    }
    if(N-siz[u]>N/2) ok=false;
    
    if(ok) center.push_back(u);
}

void zenn(int u,int p){
    for(auto to:G[u]){
        if(to.fi==p) continue;
        ans+=to.se*min(N-siz[to.fi],siz[to.fi]);
        int a=siz[u],b=siz[to.fi];
        siz[u]=N-b;
        siz[to.fi]=a;
        
        zenn(to.fi,u);
        
        siz[u]=a;
        siz[to.fi]=b;
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    
    for(int i=0;i<N-1;i++){
        int a,b,c;cin>>a>>b>>c;
        a--;b--;
        G[a].push_back(mp(b,c));
        G[b].push_back(mp(a,c));
    }
    
    DFS(0,-1);
    zenn(0,-1);
    
    ans*=2;
    
    ll hiku=INF;
    
    if(si(center)==2){
        for(auto to:G[center[0]]){
            if(to.fi==center[1]) chmin(hiku,to.se);
        }
    }else{
        for(auto to:G[center[0]]){
            chmin(hiku,to.se);
        }
    }
    
    cout<<ans-hiku<<endl;
    
}


Measured memory_bytes: 17280
#include<iostream>
using namespace std;
int main(){
    int n,a,ans=0,c=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a==c)c++;
        else ans++;
    }
    cout<<(ans==n?-1:ans)<<endl;
    return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void func(long long N, long long X, long long T) {}

int main() {
    long long N;
    scanf("%lld", &N);
    long long X;
    scanf("%lld", &X);
    long long T;
    scanf("%lld", &T);

    if (N % X == 0) {
        cout << (N / X) * T << endl;
    }

    else if (N % X != 0) {
        cout << ((N / X) + 1) * T << endl;
    }
    return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = (x-a)%b;
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#                         author:  kagemeka 
#                         created: 2019-11-07 13:09:56(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    h, w = (int(x) for x in sys.stdin.readline().split())
    canvas = ['.' * (w + 2)]
    for i in range(h):
        line = '.' + sys.stdin.readline().rstrip() + '.'
        canvas.append(line)
    canvas.append('.' * (w + 2))
    for i in range(1, h+1):
        for j in range(1, w+1):
            if canvas[i][j] == '.':
                continue
            else:
                if canvas[i-1][j] == '#' or canvas[i][j-1] == '#' or canvas[i][j+1] == '#' or canvas[i+1][j] == '#':
                    continue
                else:
                    print('No')
                    exit()
    print('Yes')


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 3064