akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<climits>
 
using namespace std;
 
#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()
 
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<int,int>> vpi;
typedef long long LL;
 
const long long OO = 2e18;
const double pi=2*acos(0.0);
 
bool isprime(long long int a){
    if(a==1){
        return false;
    }
    for(int i=2;i*i<=a;i++){
        if(a%i==0){
            return false;
        }
    }
    return true;
} 
 
bool iscoprime(int a,int b){
    int i;
    for(i=2;i<=min(a,b);i++){
        if(a%i==0 && b%i==0){
            return false;
        }
    }
    return true;
}
 
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}
 
int maxA(vi a){
    int m=0;
    for(int i=0;i<a.size();i++){
        m=max(m,a[i]);
    }
    return m;
}
 
int minA(vi a){
    int m=100000;
    for(int i=0;i<a.size();i++){
        m=min(m,a[i]);
    }
    return m;
}
 
vi freqN(vi a, int n){
    vi f(n);
    f={0};
    for(int i=0;i<a.size();i++){
        f[a[i]]++;
    }
    return f;
}
 
vi freqA(vi a){
    vi f(26);
    f={0};
    for(int i=0;i<a.size();i++){
        f[a[i]-'0']++;
    }
    return f;
}
 
bool mycomp(const pair<long int,long int>&p1 , const pair<long int,long int>&p2){
    if(p1.second < p2.second) return true;
    else if(p1.second==p2.second) return p1.first<p2.first;
    else return false;
}
 
unsigned int rightmostsetbit(unsigned int n){
    return n & -n;
}
 
bool cmp(pair<lld,lld>&p1 , pair<lld,lld>&p2){
    if((p1.first*p1.second)==(p2.first*p2.second)) return p1.second>p2.second;
    return (p1.first*p1.second)>(p2.first*p2.second);
}
 
int main(){
fast;
cin.tie(0);
lld n;
cin>>n;
lld a[n];
set<lld> s;
for(lld i=0;i<n;i++){
    cin>>a[i];
    s.insert(a[i]);
}
if(s.size()==n){
    cout<<"YES"<<endl;
}
else cout<<"NO"<<endl;
}

Measured memory_bytes: 11264
//     . .. ... .... ..... be name khoda ..... .... ... .. .     \\

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;

inline int in() { int x; scanf("%d", &x); return x; }
const int N = 2002;

int main()
{
	string s;
	cin >> s;
	int k = in();
	for(int i = 0; i < s.size(); i++)
		if(s[i] != 'a' && 'z' - s[i] + 1 <= k)
		{
			k -= ('z' - s[i] + 1);
			s[i] = 'a';
		}
	if(k > 0)
		s[s.size() - 1] += k % 26;
	cout << s << endl;
}


Measured memory_bytes: 640
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::*,
    std::{cmp::*, collections::*, convert::*, iter::*, marker::*, mem::*, ops::*},
};
fn main() {
    input! {//
        k:usize
    }
    for _ in 0..k {
        print!("ACL");
    }
    println!();
}


Measured memory_bytes: 2112
def calc(n, h):
    r = 0
    c = 0
    for i in range(0, n-1):
        if h[i] >= h[i+1]:
            c += 1
        else:
            if c > r:
                r = c
            c = 0
    if c > r:
        r = c
    return r


n = int(input())
h = list(map(int, input().split()))

r = calc(n, h)
print(r)


Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S, T;
	map<char, int> Ssame;
	map<char, int> Tsame;
	bool ans = true;

	for (char i = 'a'; i <= 'z'; i++) {
		Ssame[i] = -1;
		Tsame[i] = -1;
	}

	cin >> S >> T;

	rep(i, T.length()) {
		if ((Ssame[S[i]] != -1)
			&& (T[Ssame[S[i]]] != T[i])) {
			ans = false;
			break;
		}

		if ((Tsame[T[i]] != -1)
		&& (S[Tsame[T[i]]] != S[i])) {
			ans = false;
			break;
		}

		Ssame[S[i]] = i;
		Tsame[T[i]] = i;
	}

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0; i<n; i++) cin >> h[i];
  sort(h.begin(), h.end());
  int ans = 1000000009;
  for(int i=0; i<=n-k; i++){
    ans = min(ans, h[i+k-1]-h[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/


int n, m;
vector<int>G[605];
double far[605];
bool used[605];
int ps, pt;
double dfs(int x) {
	if (used[x])return far[x];
	used[x] = true;
	if (x == n - 1)return 0.;
	int cnt = 0;
	double sum = 0;
	for (int i : G[x]) {
		if (x == ps && i == pt)continue;
		sum += dfs(i);
		cnt++;
	}
	return far[x] = sum / cnt + 1.;
}
signed main() {
	cin >> n >> m;
	rep(i, m) {
		int s, t; cin >> s >> t; s--; t--;
		G[s].push_back(t);
	}
	double ans = dfs(0);
	rep(i, n) {
		if (G[i].size() <= 1)continue;
		double ma = -mod; int maxInd;
		for (int j : G[i]) {
			if (ma < far[j]) {
				ma = far[j]; maxInd = j;
			}
		}
		ps = i, pt = maxInd;
		rep(j, n)used[j] = false;
		chmin(ans, dfs(0));
	}
	printf("%.12lf\n", ans);
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define out(str) cout << str << endl

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

int a,b,sa,ans;

int main(){
    cin >> a >> b;
    sa = b-a;
    ans = 0;
    for(int i = 1; i <= sa;i++){
        ans += i;
    }
    out(ans-b);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
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(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c/a*b<<endl;
    return 0;
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def I():
    # 1 line 1 int
    return int(sys.stdin.readline().rstrip())
def LI():
    # 1 line n ints
    return list(map(int,sys.stdin.readline().rstrip().split()))
def S():
    # 1 line 1 string
    return sys.stdin.readline().rstrip()
def LS():
    # 1 line n strings
    return list(sys.stdin.readline().rstrip().split())

C1 = S()
C2 = S()

if C1[::-1] == C2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9904
n,m=map(int,input().split()) 
lists=[]
for i in range(m):
	s= list(map(int,input().split()))
	lists.append(s)
listp = [int(i) for i in input().split()]


#print(format(n,'b'))
#print(format(n,'b').zfill(n))
#print(format(n,'b').zfill(n)[1])
ans=0
for i in range(2**n):
	nn=format(i,"b")
	nnn=nn.zfill(n)	
	temp2=0
	for j in range(m):
		temp=0
		for k in range(lists[j][0]):
			ss=lists[j][k+1]
			temp=temp+int(nnn[ss-1])
		if temp%2==listp[j]:
			temp2=temp2+1
	if temp2==m:
		ans=ans+1
			
print(ans)
			


Measured memory_bytes: 42480
N,K = map(int,input().split())
MOD = 10**9+7

mn = mx = 0
for i in range(K):
    mn += i
    mx += N-i
ans = mx - mn + 1

for i in range(K,N+1):
    mn += i
    mx += N-i
    ans += mx - mn + 1
    ans %= MOD

print(ans%MOD)

Measured memory_bytes: 9108
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>
#include <queue>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

const double PI = 3.1415926535897932;
/******define variable start******/
ll n;
vector<string> s;
vector<ll> t;
string x;
/*******define variable end*******/
ll solve(){
    cin >> n;
    s.resize(n);
    t.resize(n);
    ll time;
    REP(i, n){
        cin >> s[i] >> t[i];
    }
    cin >> x;
    REP(i, n){
        if(!s[i].compare(x)){
            time = i;
        }
    }
    ll ans = 0;
    for(ll i = time+1; i < n; i++){
        ans += t[i];
    }
    cout << ans << endl;

    return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    return (int)end_solve;
}

Measured memory_bytes: 256
R, G, B, N = [int(i) for i in input().split(" ")]
count = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        _b = N - r * R - g * G
        if _b < 0:
            break
        if _b % B == 0:
            count += 1
print(count)

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int c[40];
int w,n,a,b;
int main()
{
	cin>>w>>n;
	for(int i=1;i<=w;i++)c[i]=i;		
	for(int i=1;i<=n;i++)
	{
		scanf("%d,%d",&a,&b);
		swap(c[a],c[b]);
	}
	for(int i=1;i<=w;i++)cout<<c[i]<<endl;
	return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,m;
  cin>> n >> m;
  
  vl x(n),y(n),z(n);
  rep(i,n) cin >> x[i] >> y[i] >> z[i];
  ll ans = 0;
  rep(i,1<<3){
    vl f(3);
    vl cakes;
    rep(j,3){
      if(i>>j&1)  f[j]=1;
      else f[j]=-1;
    }
    rep(k,n)cakes.push_back(f[0]*x[k]+f[1]*y[k]+f[2]*z[k]);
    sort(rng(cakes),greater<ll>());
    ll tot = 0;
    rep(k,m){
      tot+=cakes[k];
    }
    maxs(ans,tot);
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int t = N, c = 0;
  while (t > 0) {
    c += t % 10;
    t /= 10;
  }
  
  if (N % c == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    string s;cin>>s;
    int cnt=0,max=0;

    rep(i,s.size()){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
            cnt++;
            if(cnt>max){
                max=cnt;
            }
        }
        else {
            cnt=0;
        }
    }
    cout<<max<<endl;

}


Measured memory_bytes: 256
use std::io::{stdout, Write, BufWriter};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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! 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")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        p: [(usize, usize); m],
    }
    let mut py: Vec<((usize, usize), usize)> = p.into_iter().zip(1..).collect();
    py.sort_by_key(|t| (t.0).1);

    let mut kens = vec![1; n];
    for i in 0..m {
        (py[i].0).1 = kens[(py[i].0).0 - 1];
        kens[(py[i].0).0 - 1] += 1;
    }
    py.sort_by_key(|t| t.1);

    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    for i in 0..m {
        writeln!(out, "{0: >06}{1: >06}", (py[i].0).0, (py[i].0).1).unwrap();
    }
}

Measured memory_bytes: 13172
N = int(input())
A = [int(x) for x in input().split()]
D = set() #重複
S = set() #初出
for i in range(N):
    if A[i] in S:
        D.add(A[i])
    else:
        S.add(A[i])
#print(D,S)
M = max(S)
#print(M)
X = [1 for i in range(M+1)] #i番目が数字iに対応、条件を満たせば1、満たさなければ0にする。
#print(X)
for a in S:
    if a in D:
        X[a]=0 #aが重複していれば、aは条件を満たす数字ではない。
    for i in range(2*a,M+1,a):
        X[i]=0 #aはおｋ、2a以上のaの倍数は条件を満たさない。
        
ans = 0
for i in range(N):
    if X[A[i]]==1: #数字A(i)に対応するX[i]の箇所を参照して、条件を満たしていれば+1する
        ans += 1
print(ans)

Measured memory_bytes: 39160
from collections import deque

h, w = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
s = [list(input()) for _ in range(h)]

c = [i-1 for i in c]
d = [i-1 for i in d]

t0 = [(0, 1), (0, -1), (1, 0), (-1, 0)]
t1 = []
for i in range(-2, 3):
    for j in range(-2, 3):
        t1.append((i, j))
for i in t0:
    t1.remove(i)
t1.remove((0, 0))

check = [[-1]*w for _ in range(h)]
q = deque()
q.appendleft((c[0], c[1], 0))

while q:
    y, x, b = q.pop()
    if x == d[1] and y == d[0]:
        print(b)
        exit()
    if check[y][x] == -1:
        check[y][x] = b
        for dy, dx in t0:
            ydy, xdx = y+dy, x+dx
            if (0 <= xdx < w) and (0 <= ydy < h):
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.append((ydy, xdx, b))
        for dy, dx in t1:
            ydy, xdx = y+dy, x+dx
            if (0 <= xdx < w) and (0 <= ydy < h):
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.appendleft((ydy, xdx, b+1))
print(-1)

Measured memory_bytes: 202260
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)
struct edge{int to;double cost;};
typedef pair<int,int> P;

int V,n,m,x[1001],y[1001],S,G,B,X,Y,prv[1001];
double d[1001];
vector<edge> g[1001];

int main(){
	while(cin>>n&&n){
		fill(x,x+1001,-100);
		fill(y,y+1001,-100);
		rep(i,1001)g[i].clear();
		rep(i,n){cin>>B>>X>>Y;x[B]=X;y[B]=Y;}
		rep(i,1001)rep(j,1001)if(i!=j&&(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<=2500){
			edge e;
			e.to=j;e.cost=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
			g[i].push_back(e);
			e.to=i;
			g[j].push_back(e);
		}
		cin>>m;
		rep(h,m){
			cin>>S>>G;
			priority_queue<P,vector<P>,greater<P> > q;
			fill(d,d+1001,INF);
			fill(prv,prv+1001,-1);
			d[S]=0;
			q.push(P(0,S));
			while(!q.empty()){
				P p=q.top();q.pop();
				int v=p.second;
				if(d[v]<p.first)continue;
				rep(i,g[v].size()){
					edge e=g[v][i];
					if(d[e.to]>d[v]+e.cost){
						d[e.to]=d[v]+e.cost;
						q.push(P(d[e.to],e.to));
						prv[e.to]=v;
					}
				}
			}
			//cout<<prv[S]<<endl;
			//rep(i,1001)if(prv[i]!=-1)cout<<i<<" "<<prv[i]<<endl;
			if(d[G]==INF)cout<<"NA"<<endl;
			else{
				//cout<<d[G]<<endl;
				vector<int> path;
				for(;G!=-1;G=prv[G])path.push_back(G);
				reverse(path.begin(),path.end());
				rep(i,path.size())cout<<path[i]<<(i<path.size()-1?" ":"\n");
			}
		}
	}
}

Measured memory_bytes: 24000
s = input()
n = len(s) + 1

lst_0 = []
a = [-1 for i in range(n)]
if s[0] == '<':
    a[0] = 0
    lst_0.append(0)
if s[-1] == '>':
    a[-1] = 0
    lst_0.append(n-1)

mae = s[0]
for i in range(1, n-1):
    now = s[i]
    if mae == '>' and now == '<':
        a[i] = 0
        lst_0.append(i)
    mae = now

for i in lst_0:
    now = i - 1
    kazu = 1
    while now >= 0 and s[now] == '>':
        a[now] = max(a[now], kazu)
        now -= 1
        kazu += 1
    now = i + 1
    kazu = 1
    while now <= n-1 and s[now-1] == '<':
        a[now] = max(a[now], kazu)
        now += 1
        kazu += 1

print(sum(a))

Measured memory_bytes: 24092
(let* ((n (read))
       (m (read))
       (ans (loop :for x :from 0 :upto n
                    :thereis (loop :for y :from 0 :upto n
                                     :thereis (if (and (<= 0 (- n x y)) (= m (+ (* 10000 x) (* 5000 y) (* (- n x y) 1000))) )
                                                  (list x y (- n x y)))))))
  (if ans
      (format t "~A ~A ~A" (first ans) (second ans) (third ans))
      (format t "-1 -1 -1")))

Measured memory_bytes: 15844
S = input()

n = len(S)
counts = [0]*n
r_start = 0
rl_point = None
for i in range(n):
    if S[i:i+2] == "RL":
        rl_point = i
    if S[i:i+2] in ["LR", "L"]:
        r = rl_point+1 - r_start
        l = i - rl_point
        # print(r, l)
        counts[rl_point] += (-(-r//2)) + l//2
        counts[rl_point+1] += r//2 + (-(-l//2))
        r_start = i+1

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

Measured memory_bytes: 10484
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    rep(i,n){
        cin>>a>>b;
        if(a%b==0)Cout(b);
        else Cout(a%b);
    }
    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
//P,Q大きさNの順列で、Pの辞書順aとQの辞書順bの差を求める


int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for(int i = 0;i<N;i++){
    if(S[i] == 'A' && i<=N-3){
      if(S.substr(i,3) == "ABC"){
        ans++;
        i += 2;
      }
    }
    if(i >= N) break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
even = ["R", "U", "D"]
odd = ["L", "U", "D"]

flag = False

for idx, char in enumerate(S):
    if idx%2 == 0:
        if char in even:
            pass
        else:
            flag = True
            break
    else:
        if char in odd:
            pass
        else:
            flag = True
            break
        
if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

K, A, B = gets_i_list

diff = B - A
if diff <= 2
  puts K + 1
else
  k_count = K - A + 1
  ab_count = (k_count.to_f / 2).floor
  remain_count = k_count - ab_count * 2
  bc = A + (B - A) * ab_count + remain_count
  puts bc
end


Measured memory_bytes: 2044
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		 try {
		 BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		
		 String ln;
		ln = buf.readLine();
		
       String[] strAry = ln.split(" ");
       int x = Integer.parseInt(strAry[0]);
       int y = Integer.parseInt(strAry[1]);
       
       if (x < y){
       System.out.println("a < b");
       }else if(x == y){
    	   System.out.println("a == b");
       }else if(x > y){
    	   System.out.println("a > b");
       }
      
			} catch (IOException e) {
				// TODO ????????????????????? catch ????????????
				e.printStackTrace();
			}
    }
}

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

/*
templates for competitive programming
type long long -> type ll 
define constants : EPS, INF, MOD, PI
define macros : REP, FOR, ALL, SORT, REVERSE
define number theory functions: qp(a, b), qp(a, b, mo), gcd(a, b)
define dx, dy
*/
   typedef long long ll;

   const double EPS = (1e-7);
   const int INF =(1e9);
   const double PI = (acos(-1));
   const int MOD = (int(1e9) + 7);

   #define REP(i, n) for(int i = 0; i < (int)(n); i++)
   #define FOR(i, a, b) for (int i = (a); i < (b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((int)(x).size())


   #define dump(x) cerr<< #x << "= " << (x) << endl;

   int gcd(int a,int b){return b?gcd(b,a%b):a;};

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

int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   // input
   ll n; cin >> n;
   vector<int> a(n); 
   REP(i, n) cin >> a[i];

   ll ans = 0;
   ll right = 0;
   ll sum = 0;
   REP(left, n){
       if (left > right){
           left = right;
           sum = 0;
       }
       while ((right < n) && ((sum ^ a[right]) == (sum + a[right]))){
           sum += a[right];
           right++;
       }
       ans += right - left;
       sum -= a[left];
   }
   cout << ans << endl;
}

Measured memory_bytes: 1024
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = sc.nextInt();
        println((int)Math.pow(N, 3));
    }

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

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 21204
import math
N,A,B=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
dic={}
for i in range(N):
  v=a[i]
  if v not in dic.keys():
    dic[v]=1
  else:
    dic[v]+=1
tmp=0
num_used={}
m=10**18
M=-1
for i in range(A):
  v=a[i]
  m=min(m,v)
  M=max(M,v)
  tmp+=v
  if v not in num_used.keys():
    num_used[v]=1
  else:
    num_used[v]+=1
max_ave=tmp/A
print(max_ave)
if num_used[m]==dic[m]:
  print(1)
elif m==M:
  x=dic[m]
  y=num_used[m]
  cnt=0
  for i in range(y,min(x+1,B-A+y+1)):
    cnt+=math.factorial(x)//math.factorial(i)//math.factorial(x-i)
  print(cnt)
else:
  x=dic[m]
  y=num_used[m]
  cnt=math.factorial(x)//math.factorial(y)//math.factorial(x-y)
  print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i, n) cin >> vec[i];
    sort(all(vec));
    reverse(all(vec));
    vec[0] /= 2;
    
    int ans=0;
    rep(i, n){
        ans += vec[i];
    }
    out(ans);
}

Measured memory_bytes: 256
# coding: utf-8


S = input()

N = len(S)
K = N // 2


def is_kaibun(S):
    N = len(S)
    K = N // 2

    for i in range(0, K):
        if S[i] != S[N-1-i]:
            return False
    
    return True


former = S[:K]
latter = S[K+1:]

if is_kaibun(S) and is_kaibun(former) and is_kaibun(latter):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include<string>
using namespace std;
#define ll long long int
#define maxn 100005

void _init() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


vector<int> adj[maxn];


vector<int> dist(maxn, -1);

int dfs(int i) {
	if (dist[i] != -1)return dist[i];

	int maxDepth = INT_MIN;
	for (auto x : adj[i]) {
		maxDepth = max(maxDepth, 1 + dfs(x));
	}

	return dist[i] = maxDepth == INT_MIN ? 0 : maxDepth;
}

int main() {
	_init();

	int n, m;
	cin >> n >> m;
	for (int i = 0, a, b; i < m; ++i)
	{
		cin >> a >> b, a--, b--;
		adj[a].push_back(b);
	}

	int maxDepth = 0;
	for (int i = 0; i < n; i++) {
		maxDepth = max(maxDepth, dfs(i));
	}

	cout << maxDepth << endl;

	return 0;
}









Measured memory_bytes: 11016
from collections import defaultdict

def solve():
    N = int(input())
    A = map(int, input().split())
    d = defaultdict(lambda:0)
    for a in A:
        d[a]+=1
        d[a-1]+=1
        d[a+1]+=1
    # print(d)
    print(max(d.values()))
    
solve()

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[20],x = 0;
    cin>>n;
    for(int i = 0;i<n;i++)
        cin>>a[i];
    for(int i = 1;i<n-1;i++)
    {
        if(a[i]>=a[i-1]&&a[i]<a[i+1]||a[i]<a[i-1]&&a[i]>=a[i+1])
            x++;
    }
    cout<<x;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
bool is_prime(ll n){
    if(n <= 1)
        return false;
    if(n == 2)
        return true;
    if(n % 2 == 0)
        return false;
    for(ll i = 3; i * i <= n; i += 2)
        if(n % i == 0)  
            return false;
    return true;
}
int main(){
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    ll ans = 1;
    for(ll i = 2; i * i <= g; i++){
        if(g % i == 0){
           if(is_prime(i))
                ans++;
            if(is_prime(g / i))
                ans++;
        }
    }
    if(is_prime(g))
        ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>

int main()
{
    char b;
    char out;

    scanf("%c", &b);

    if(b == 'A') {
        out = 'T';
    } else if(b == 'T') {
        out = 'A';
    } else if(b == 'G') {
        out = 'C';
    } else {
        out = 'G';
    }

    printf("%c\n", out);

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cmath>


using namespace std;

bool eight(int n) {
	int count = 0;
	for (int i = 1; i <= n; i++) {
		if (n%i == 0) {
			count++;
		}
	}

	if (count == 8) {
		return true;
	}
	else
	{
		return false;
	}
}

int main(){
	int n;
	int	ans=0;
	cin >> n;

	for (int i = 1; i <= n; i += 2) {
		if (eight(i) == true) {
			ans++;
		}
	}

	cout << ans;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	scanf("%d", &n);
	int lo=0, hi=n-1;
	cout<<0<<endl;
	string s;
	cin>>s;
	int stat=-1;
	if (s=="Vacant") return 0;
	else if (s=="Male") stat=0;
	else stat=1;
	for (int i=0; i<19; i++) {
		int mid=(((n+hi-lo)%n)/2+lo)%n;
		cout<<mid<<endl;
		cin>>s;
		int stat2=-1;
		if (s=="Vacant") return 0;
		else if (s=="Male") stat2=0;
		else stat2=1;
		if ((stat==stat2)^((mid-lo)%2==0)) hi=mid-1;
		else {
			lo=mid+1;
			stat=1-stat2;
		}
		//printf("%d %d\n", lo, hi);
	}
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC165A()
{
	int K;
	cin >> K;
	int A, B;
	cin >> A >> B;
	for (int i = A; i <= B; ++i)
	{
		if (i % K == 0)
		{
			cout << "OK" << endl;
			return;
		}
	}
	cout << "NG" << endl;
}
int main()
{
	ABC165A();
	return 0;
}

Measured memory_bytes: 3676
#include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <functional>
using namespace std;
const double eps = 1e-9;

int n, k;
vector<int> w;

double bisection_method(double ng, double ok, function<double(double)> f) {
    assert(f(ng) == false);
    assert(f(ok) == true);
    for (int i = 0; i < 100; i++) {
        double mid = (ng + ok) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

vector<double> quadratic_equation(double a, double b, double c) {
    // ax^2 + bx + c = 0
    if (a == 0) {
        if (b == 0) return {};
        return { -c / b };
    }
    double d = b*b - 4*a*c;
    if (d < -eps) return {};                            // D < 0
    if (d < eps) return { -b / (2*a), -b / (2*a) };     // D == 0
    return { (-b + sqrt(d)) / (2*a), (-b - sqrt(d)) / (2*a) };
}

vector<double> cubic_equation(double a, double b, double c, double d) {
    // ax^3 + bx^2 + cx + d = 0
    if (a == 0) return quadratic_equation(b, c, d);
    if (a < 0) a = -a, b = -b, c = -c, d = -d;
    // (x - x0)(sx^2 + tx + u)
    // s = a, t = b + s*x0, u = c + t*x0 = -d/x0 <- x0 = 0 があるので使えない
    double x0 = bisection_method(-1e9, 1e9, [&](double x) {
        return a*x*x*x + b*x*x + c*x + d > 0;
    });
    vector<double> res = quadratic_equation(a, b + a*x0, c + b*x0 + a*x0*x0);
    res.push_back(x0);
    return res;
}

int main() {
    int t; cin >> t;
    while (t--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        vector<double> xs = cubic_equation(a, b, c, d);
        int pos = 0, neg = 0;
        for (double x : xs) {
            if (x > eps) pos++;
            if (x < -eps) neg++;
        }
        cout << pos << " " << neg << endl;
    }
    return 0;
}


Measured memory_bytes: 3048
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;int m,n;int a[500][500];
struct element{
	int val;int bef;int nxt;
} ui[500][500];int st[500];int d[500];
void dfs(int x)
{
	
}
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	cin>>m>>n;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
		for(int j=0;j<n;j++)
		{
			if(j==0)
			{
				st[i]=a[i][j];ui[i][a[i][j]].bef=-1;ui[i][a[i][j]].nxt=a[i][j+1];
			}
			else if(j==n-1)
			{
				ui[i][a[i][j]].bef=a[i][j-1];ui[i][a[i][j]].nxt=-1;
			}
			else
			{
				ui[i][a[i][j]].bef=a[i][j-1];;ui[i][a[i][j]].nxt=a[i][j+1];
			}
		}
	}int ans=1234567;
	for(int ii=0;ii<n;ii++)
	{
		memset(d,0,sizeof(d));int ret=0;int id;
		for(int j=0;j<m;j++)
		{
		
			d[st[j]]++;if(ret<d[st[j]]) id=st[j],ret=d[st[j]];
		}ans=min(ans,ret);
		for(int j=0;j<m;j++)
		{
			if(st[j]==id)
			{

				st[j]=ui[j][id].nxt;ui[j][st[j]].bef=-1;continue;
			}
			int q=ui[j][id].bef,w=ui[j][id].nxt;
			if(q!=-1)ui[j][q].nxt=w;
			if(w!=-1)ui[j][w].bef=q;
		}
	}cout<<ans<<endl;
	return 0;
}

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

using namespace std;


int main() {
  string s;
  int K;
  cin >> s >> K;
  
  vector<string> substr;
  
  for(int i=0; i<s.size(); ++i){
    for(int j=1; j<=K; ++j){
      string tmp = s.substr(i, j);
      substr.push_back(tmp);
    }
  }
  
  sort(substr.begin(), substr.end());
  substr.erase(unique(substr.begin(), substr.end()), substr.end());
  
  cout << substr[K-1] << endl;
  
}


Measured memory_bytes: 4240
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a[200010];
    cin>>n;
    map<long long,long long>mp;
    for(long long i=1;i<=n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    long long ans=0;
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        if(it->second>=2)
        {
            long long z=it->second;
            ans+=z*(z-1)/2;
        }
    }
    long long p=ans;
    for(long long i=1;i<=n;i++)
    {
        long long val=a[i];
        if(mp[val]>=2)
        {
            ans-=(mp[val]*(mp[val]-1))/2;
        }
        mp[val]-=1;
        if(mp[val]>=2)
        {
            ans+=(mp[val]*(mp[val]-1))/2;
        }
//        for(auto it=mp.begin();it!=mp.end();it++)
//        {
//            if(it->second>=2)
//            {
//                long long z=it->second;
//                ans+=z*(z-1)/2;
//            }
//        }
        mp[val]+=1;
        cout<<ans<<endl;
        ans=p;
    }
}

Measured memory_bytes: 11008
require 'pp'
S=gets.chomp.split('')
N=S.size
# validate
if(S[-1]=="1")
	puts -1
	exit(0)
end
if(S[0] != "1" || S[-2] != "1")
	puts -1
	exit(0)
end
for i in 0..(S.size/2)
	if(S[i]!=S[S.size-2-i])
		puts -1
		exit(0)
	end
end
# const
prev_one = 1
prev = 1
for i in 1..((S.size*1.0/2).ceil-1)
	puts "1 #{i+1}"
end
now = (S.size*1.0/2).ceil+1
(S.size/2-1).downto(0){|i|
	case S[i]
	when "1"
		puts "#{prev_one} #{now}"
		prev_one = now
		prev = now
		now += 1
	when "0"
		puts "#{prev_one} #{now}"
		prev = now
		now += 1
	end
}



Measured memory_bytes: 10748
#include<bits/stdc++.h>
#define N 2005
using namespace std;
deque<int> ans[N];
vector<int> g[N];
int n,vis[N],val[N];
deque<int> merge(deque<int> a,deque<int> b){//merge b to a
    deque<int> ret;
    while(!a.empty()||!b.empty())
        if(b.empty() || (!a.empty() && a.front()>b.front() ))
            ret.push_back(a.front()),a.pop_front();
        else ret.push_back(b.front()),b.pop_front();
    return ret;
}
void DFS(int u){
    vis[u]=1;
    for(int i:g[u])
        if(vis[i]==0)
            DFS(i),ans[u]=merge(ans[u],ans[i]);
    ans[u].push_front(val[u]);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&val[i]);
    sort(val+1,val+n+1);
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            if(__gcd(val[j],val[i])!=1) 
                g[i].push_back(j),g[j].push_back(i);
    for(int i=1;i<=n;i++) sort(g[i].begin(),g[i].end());
    for(int i=1;i<=n;i++)
        if(vis[i]==0)
            DFS(i),ans[0]=merge(ans[0],ans[i]);
    for(int i:ans[0]) printf("%d ",i);
    return 0;
}

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

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 2e5;
const ll MOD = 1e9 + 7;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

ll a[mxN], suma[mxN];

int main() {
	fast();
	int n,m;
	ll k;
	cin >> n >> m >> k;
	suma[0] = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		suma[i+1] = suma[i] + a[i];
	}
	ll sum = 0;
	int best = 0;
	for (int i = 0; i < m; ++i)
	{
		ll x;
		cin >> x;
		sum += x;
		if (sum > k) continue;
		int lb = 0, rb = n;
		while (lb < rb) {
			int mb = (lb+rb+1)/2;
			ll val = suma[mb];
			if (val + sum > k) {
				rb = mb - 1;
			} else {
				lb = mb;
			}
		}
		best = max(best, i + 1 + lb);
	}
	int lb = 0, rb = n;
	while (lb < rb) {
		int mb = (lb+rb+1)/2;
		ll val = suma[mb];
		if (val > k) {
			rb = mb - 1;
		} else {
			lb = mb;
		}
	}
	best = max(best, lb);
	cout << best << nl;
}

Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    string S;
    cin >> S;
    bool a = false;
    bool b = false;
    if (stoi(S.substr(0, 2)) <= 12 and stoi(S.substr(0, 2)) > 0)
        b = true;
    if (stoi(S.substr(2, 2)) <= 12 and stoi(S.substr(2, 2)) > 0)
        a = true;
    if (a and b)
        cout << "AMBIGUOUS" << endl;
    else if (a)
        cout << "YYMM" << endl;
    else if (b)
        cout << "MMYY" << endl;
    else
        cout << "NA" << endl;

    // system("pause");
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    string S[3];
    cin >> S[0] >> S[1] >> S[2];
    printf("%c%c%c\n", S[0][0], S[1][1], S[2][2]);
    return 0;
}


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

int main(){
  int N,M,a,b,x,ans;
  cin>>N>>M;
  vector<pair<int,int>>g(M);
  for(int i=0;i<M;i++){
    cin>>a>>b;
    g[i]=make_pair(b,a);
  }
  sort(g.begin(),g.end());
  ans=1;
    x=g[0].first-1;
  for(int i=1;i<M;i++){
    if(x<=g[i].first-1&&g[i].second-1<x){
      continue;
    }
    else{
      x=g[i].first-1;
      ans++;
    }
  }
 cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0);   cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define mod 1000000007
 
const int mxN = 3000 + 5;
//ll a[mxN];
ll n;
string cmp;
ll dp[mxN][mxN];
 
 
int main()
{
FIO
 
    cin >> n >> cmp;
    dp[1][1] = 1;
    for(int i = 2; i <= n; i++)
    {
        ll pfx[mxN] = {};
        for(int j = 1; j < i; j++)
            pfx[j] = (pfx[j-1] + dp[i-1][j]) % mod;
        for(int j = 1; j <= n; j++)
        {
            int l, r;
            if(cmp[i-2] == '<')
                l = 1, r = j - 1;
            else
                l = j, r = i - 1;
            if(l > r) continue;
            dp[i][j] = (dp[i][j] + pfx[r] - pfx[l-1] + mod) % mod;
        }
    }

    ll ans = 0;
    for(int i = 1; i <= n; i++)
        ans = (ans + dp[n][i]) % mod;

    cout << ans << endl;

}

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

//メモ用配列
int dp[16][16];

int main(){
  int a,b,n;
  while(cin>>a>>b,a||b){
    cin>>n;
    
    //メモ初期化
    memset(dp,-1,sizeof(dp));
    
    for(int i = 0; i < n; i++){
      int x,y;
      cin>>x>>y;
      //工事中のところに0
      dp[x-1][y-1] = 0;
    }
    
    //スタート地点に1代入
    dp[0][0] = 1;
    for(int i = 1; i < a; i++){
      //もし工事中だったら一個戻る
      if(dp[i][0]){
	dp[i][0] = dp[i-1][0];
      }
    }
    for(int i = 1; i < b; i++){
      //もし工事中だったら一個戻る
      if(dp[0][i]){
	dp[0][i] = dp[0][i-1];
      }
    }
    
    for(int i = 1; i < a; i++){
      for(int j = 1; j < b; j++){
	if(dp[i][j]){
	  dp[i][j] = dp[i][j-1]+dp[i-1][j];
	}
      }
    }
    
    cout<<dp[a-1][b-1]<<endl;
  }
  return 0;
}

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

using namespace std;

int main() {
    int N, M, C;
    cin >> N >> M >> C;

    int B[20];
    int A[20][20];

for(int i = 0; i < M; i++) {
    cin >> B[i];
}
for(int i = 0; i < N; i++) {
    for(int j = 0; j < M; j++) {
        cin >> A[i][j];
    }
}
//入力終わり

int ans = 0;
int count = 0;//正答数
for(int i = 0; i < N; i++) {
    ans = 0;
    for(int j = 0; j < M; j++) {
      ans = ans + A[i][j] * B[j];
    }
    ans = ans + C;
    if(ans > 0){
        count++;
    }//正答なら１カウント
}
cout << count << endl;

    return 0;
}

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

typedef long long ll;
const int maxn = 2e7 + 10, mod = 998244353;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

inline int add(int x, int y) {return x + y > mod ? x + y - mod : x + y;}
inline int sub(int x, int y) {return x < y ? x - y + mod : x - y;}
inline int fpow(int x, int k)
{
	int res = 1;
	while (k) {
		if (k & 1) res = (ll)res * x % mod;
		k >>= 1; x = (ll)x * x % mod;
	}
	return res;
}

int n, a, b;
int fac[maxn], ifac[maxn];

inline int C(int m, int n)
{
	if (n < 0 || m < n) return 0;
	return (ll)fac[m] * ifac[n] % mod * ifac[m - n] % mod;
}

inline int F(int x, int y)
{
	if (y <= x - 1) return 0;
	return sub(C(x + y, x), C(x + y, x - 1));
}

int main()
{
	n = gi(); a = gi(); b = gi();
	fac[0] = ifac[0] = ifac[1] = 1;
	for (int i = 1; i < maxn; ++i) fac[i] = (ll)fac[i - 1] * i % mod;
	ifac[maxn - 1] = fpow(fac[maxn - 1], mod - 2);
	for (int i = maxn - 2; ~i; --i) ifac[i] = (ll)ifac[i + 1] * (i + 1) % mod;

	if (!b) return puts("1"), 0;
	int ans = 0;
	for (int i = 0; i <= n - b; ++i) {
		int tmp = F(i, b - 1);
		if (i + b == n) {
			if (i == a) ans = add(ans, tmp);
		} else {
			int x = n - b - i - 1, y = a - i + 1;
			ans = (ans + (ll)tmp * C(x + y - 1, y - 1)) % mod;
		}
	}
	printf("%d\n", ans);

	return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n, c, k;
  cin >> n >> c >> k;
  vector<int> t(n);
  rep(i, n) cin >> t[i];
  sort(all(t));

  int ans = 0;
  int tt = -1;
  int cnt = 0;
  rep(i, n) {
    if (t[i] <= tt && cnt + 1 <= c)
      cnt++;
    else {
      ans++;
      tt = t[i] + k;
      cnt = 1;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
H, W = list(map(int, input().split()))

while H != 0 or W != 0 :

    print('#' * W)
    for i in range(H-2) :
        print('#', end = '')
        print('.' * (W - 2), end = '')
        print('#')
    print('#' * W)
    print()
    H, W = list(map(int, input().split()))

Measured memory_bytes: 7712
#include <bits/stdc++.h>
#define int long long
#define float long double
#define PB push_back
#define MP make_pair
#define ss second
#define ff first
#define PI 3.14159265
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int M = 1e9 + 7;

signed main(){
    fastrack;
    int n, k;
    cin >> n >> k;
    cout << min(n%k, abs(n%k - k)) << "\n";
    return 0;
}


Measured memory_bytes: 256