akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; Next(a); return a; }
  template<class A, class B>void Next(pair<A, B>& a) { cin >> a.first >> a.second; }
  template<class A>void Next(A& a) { cin >> a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) (*this), i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;
/*---------------------------------------------------------------------*/

struct XY {
  int x, y;
  XY&operator+=(const XY&d) { x += d.x; y += d.y; return *this; }
  XY operator+(const XY&d)const { return XY(*this) += d; }
  bool operator==(const XY&d)const { return x == d.x && y == d.y; }
  bool check(int w, int h)const { return 0 <= x && x < w && 0 <= y && y < h; }
};
const XY d4[] = { { -1,0 }, { 1,0 }, { 0,-1 }, { 0,1 }, };
template<class T> auto get(T& a, XY d)->decltype(a[d.y][d.x]) { return a[d.y][d.x]; }
ostream& operator<<(ostream& os, XY d) { return os << '(' << d.x << ',' << d.y << ')'; }



void Calc() {

  var(int, h, w, k);

  auto s = in.Array<string>(h);
  XY start;
  rep(i, h)rep(j, w)if (s[i][j] == 'S') {
    start = { j, i };
    break;
  }

  vector<XY> p;
  p.push_back(start);
  queue<pair<int, XY>> q;
  q.push({ 0, start });

  while (q.size()) {
    auto pp = q.front(); q.pop();
    auto t = pp.second;
    if (get(s, t) == 'A')continue;
    p.push_back(t);
    get(s, t) = 'A';
    if (pp.first == k)continue;
    for (auto& i : d4) {
      auto next = i + t;
      if (next.check(w, h) && get(s, next) == '.') {
        q.push({pp.first + 1, next});
      }
    }
  }

  err(s);
  const int INF = 1e9 - 1;

  int ans = INF;
  for (auto& i : p) {
    auto mini = min({ i.x, i.y, w - i.x - 1, h - i.y - 1 });
    amin(ans, (mini + k - 1) / k + 1);
  }

  cout << (ans) << endl;


}


Measured memory_bytes: 11256
#include<iostream>
#include<string>

using namespace std;

int main(){
    int a, b;
    string s, ans="Yes";
    cin >> a >> b >> s;
    for(int i=0;i<a;i++){
        if(s[i]<'0'||s[i]>'9')ans="No";
    }
    if(s[a]!='-')ans="No";
    for(int i=a+1;i<a+b+1;i++){
        if(s[i]<'0'||s[i]>'9')ans="No";
    }
    cout << ans << endl;
    return 0;
}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

int main() {
    lli a, b, c;
    cin3(a, b, c);
    if (c - (a-b) < 0)
        cout << 0 << endl;
    else
        cout <<  c - (a-b) << endl;
}


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

int main() {
  int N;
  vector<int64_t> number = vector<int64_t>(87);
  number.at(0) = 2;
  number.at(1) = 1;
  cin >> N ;
  for (int i=2;i<N+1;i++){
    number.at(i) = number.at(i-2)+number.at(i-1);
  }
  cout << number.at(N) << endl;

}


Measured memory_bytes: 256
// Last Change: 02/16/2019 21:39:49.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

// const ll INF = 1000000005;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);

  ll first;
  cin >> first;
  ll minVal = first;
  queue<ll> q;
  ll input;
  for (int i = 1; i < N; ++i) {
    cin >> input;
    if (minVal > input) {
      q.push(minVal);
      minVal = input;
    } else {
      q.push(input);
    }
  }

  ll tmp;
  ll nextMinVal = minVal;
  while (!q.empty()) {
    // cout << " nextMinVal=" << nextMinVal << endl;
    tmp = q.front();
    // cout << tmp << endl;
    q.pop();
    tmp = tmp % nextMinVal;
    // cout << tmp << endl;
    if (tmp != 0) {
      if (nextMinVal > tmp) {
        q.push(nextMinVal);
        nextMinVal = tmp;
      }
    }
  }
  cout << nextMinVal << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    if(N%2==0)cout<<0.5<<endl;
    else printf("%.10f\n",1.0*(N+1)/(2*N));
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int cnt=0;
	int look=a[0];
	if(n==1){cout<<1; return 0;}
	for(int i=1;i<n;i++)
	{
		if(a[i]>=a[i-1]&&a[i]>=look)
		{
			look=a[i];
			cnt++;
		}
	}
	cout<<cnt+1;
}

		
			

Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

x=int(input())
ans=x//500*1000
tmp=x%500
ans+=tmp//5*5
print(ans)

Measured memory_bytes: 64492
from itertools import accumulate

H, W, K = map(int, input().split())
s = [input() for _ in range(H)]

ans = []
acc = 0
l = 0
for i in s:
    cnt = i.count("#")
    if cnt == 0:
        if not ans:
            l += 1
        else:
            ans.append(ans[-1])
    else:
        k = [0] * W
        for j in range(W):
            if i[j] == "#":
                k[j] = 1
        k = list(accumulate(k))
        for j in range(W):
            if k[j] == 0:
                k[j] = 1
            k[j] += acc
        ans.append(k)
    if ans and l >= 1 :
        for _ in range(l):
            ans.append(ans[-1])
        l = 0
    acc += cnt
        
for i in ans:
    print(" ".join(map(str, i)))

Measured memory_bytes: 7284
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

#define MOD 100000007

typedef long long LL;

int dp[2001][1001];

int combmod(int a, int b){
	b = min(b, a - b);

	dp[0][0] = 1;
	for(int i = 1; i <= a; ++i){
		dp[i][0] = 1;
		for(int j = 1; j <= b; ++j){
			dp[i][j] = (dp[i-1][j-1] + dp[i-1][j]) % MOD;
		}
	}
	return dp[a][b];
}

int main(){
	int r, c, a1, a2, b1, b2;
	cin >> r >> c >> a1 >> a2 >> b1 >> b2;
	int dx = abs(a1 - b1), dy = abs(a2 - b2);

	LL u = 1;

	if( dx == r - dx ){
		u *= 2;
	}
	else if( dx > r - dx ){
		dx = r - dx;
	}
	
	if( dy == c - dy ){
		u *= 2;
	}
	else if( dy > c - dy ){
		dy = c - dy;
	}

	int t = (combmod(dx + dy, dx) * u) % MOD;
	cout << t << endl;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  int t;
  cin >> N >> M;
  vector<int> city(N, 0); 
  for (int i = 0; i < M * 2; i++){
    cin >> t; 
    city.at(t-1)++; 
  }
  for (int i = 0; i < N; i++){
    cout << city.at(i) << endl; 
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A=0;
  int B=0;
  int N;
  cin>>N;
  vector<int> data(N);
  for(int i=0;i<N;i++){
    cin>>data.at(i);
  }
  sort(data.begin(),data.end());
  reverse(data.begin(),data.end());
  for(int i=0;i<N;i+=2){
    A+=data.at(i);
  }
  for(int i=1;i<N;i+=2){
    B+=data.at(i);
  }
  cout<<A-B<<endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}


int main() {
    ll n, x;
    cin >> n;

    // call(n);

    for(ll i = 1;i <= n;i++){
        x = i;
        if(x % 3 == 0 || x % 10 == 3){
            cout << " " << i;
        } else{
            while(x){
                x /= 10;
                if(x % 10 == 3){
                    cout << " " << i;
                    break;
                }
            }
        }
    }
    cout << endl;




    return 0;
}



Measured memory_bytes: 3096
d=int(input())
c=list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(d)]
last = [0 for i in range(26)]
satis = 0
for i in range(1,d+1):
  t=int(input())
  last[t-1]= i
  satis += s[i-1][t-1]
  for j in range(26):
    satis -= c[j] * (i - last[j])
  print(satis)

Measured memory_bytes: 9384
# include <bits/stdc++.h>
# define ll long long
# define all(x) x.begin(), x.end()
# define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
# define MOD 1000000007
														
using namespace std;

vector <ll> factmod;
vector <ll> inversemod;
ll powmod(int x,int y){
	ll re=1;
	ll curr=x;
	while(y){
		if (y&1){
			re=(re*curr)%MOD;
		}
		curr=(curr*curr)%MOD;
		y>>=1;
	}
	return re;
}

ll combi (int x,int y){
	return factmod[y]*inversemod[x]%MOD*inversemod[y-x]%MOD;
}

int main(){
	fastio;
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	h--;w--;a--;b--;
	factmod.assign(h+w,1);
	inversemod.assign (h+w,1);
	for (int i=1;i<h+w;i++){
		factmod[i]=factmod[i-1]*i%MOD;
		inversemod[i]=powmod(factmod[i],MOD-2);
	}
	ll ans=0;
	if (b<w){
		for (int h1=0;h1<h-a;h1++){
			ll tmp=combi(h1,h1+b)%MOD;
			ans=(ans+tmp*combi(h-h1,h-h1+w-b-1))%MOD;
		}
	}
	cout<<ans<<'\n';
	return 0;
}
	


Measured memory_bytes: 6272
n,k = map(int,input().split())
h = [int(input()) for _ in range(n)]
h.sort()
m = 10**10
for i in range(n-k+1):
    b = h[i]
    a = h[i+k-1]
    if a - b < m:
        m = a - b

print(m)

Measured memory_bytes: 7384
def s():
 n=int(input())-1
 A=list(map(int,input().split()))
 i=0
 for j in range(n):
  if A[j]<=A[-1]:A[i],A[j]=A[j],A[i];i+=1
 A[i],A[n]=A[n],A[i]
 print(" ".join(map(str,A[:i]))+" ["+str(A[i])+"] "+" ".join(map(str,A[i+1:])))
if'__main__'==__name__:s()


Measured memory_bytes: 16388
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    cout = []
    for i in range(3):
        x = input()
        cout.append(x[i])
    print(''.join(cout))
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38636
n,k,s=map(int,input().split())
ans=[]
for i in range(k):
    ans.append(s)
for i in range(n-k):
    if s<10**9:
        ans.append(s+1)
    else:
        ans.append(s-1)
for i in range(n):
    print(ans[i],end=" ")

Measured memory_bytes: 49696
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PriorityQueue <Integer> priorityQueue = new PriorityQueue<Integer>(Comparator.reverseOrder());
        while(true){
            String command = sc.next();
            if(command.equals("end")){
                break;
            }else if(command.equals("insert")){
                priorityQueue.add(sc.nextInt());
            }else{
                System.out.println(priorityQueue.poll());
            }
        }
    }
}


Measured memory_bytes: 582704
import sys, math, copy
sys.setrecursionlimit(10**8)

def main():
    n = int(input())
    x = list(input())
    for i in range(n):
        x[i] = int(x[i])
    A0 = 0
    A1 = 0
    B = sum(x)
    for i in range(n):
        if B+1 != 0:
            A0 += x[i]*pow(2,n-i-1,B+1)
            A0 %= B+1
        if B-1 != 0:
            A1 += x[i]*pow(2,n-i-1,B-1)
            A1 %= B-1
    for i in range(n):
        if x[i] == 0:
            BB = B + 1
            AA = A0 + pow(2,n-i-1,BB)
        else:
            BB = B - 1
            if BB == 0:
                AA = 0
            else:
                AA = A1 - pow(2,n-i-1,BB)
        ans = 1
        if BB == 0:
            print(0)
            continue
        while AA%BB != 0:
            AA = AA%BB
            AAA = AA
            BB = 0
            while AAA != 0:
                BB += AAA%2
                AAA //= 2
            ans += 1
        print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 94544
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

#define long long long // for codeforces

map<char,int> conv;

int main(){
  int cnt = 0;
  rep(i,10) conv['0' + i] = cnt++;
  rep(i,26) conv['A' + i] = cnt++;
  rep(i,26) conv['a' + i] = cnt++;

  vector<int> g(1<<19, 0);
  g[1] = 1;
  int mex = 2;
  rep(i,2,1<<19){
    g[i] = 0;
    int tmp = i;
    while(tmp > 0){
      while(tmp%2 == 0) tmp /= 2;
      int cur = 1;
      while(tmp%2==1){
        tmp /= 2;
        cur = cur*2 + 1;
      }
      cur /= 2;
      g[i] = g[i] ^ g[cur];
      if(i == cur) {
        g[i] = mex++;
      }
    }
    if(i<20) dbg(g[i]);
  }

  int ans = 0;
  int n;
  scanf("%d", &n);
  rep(i,n){
    int p;
    char s[100];
    scanf("%d %s", &p, s);
    int num = 0;
    for(int j = 0; s[j] != '\0'; j++){
      num = num * p + conv[s[j]];
    }
    ans = ans ^ g[num];
  }

  cout << (ans == 0 ? "lose" : "win") << endl;

  return 0;
}



Measured memory_bytes: 4776
#include <stdio.h>

int max(int a,int b){
    if(a<b) return b;
    else return a;
}

int main(void){
    int n,cost[101000][3],a[101000][3]={0};
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++) scanf("%d",&a[i][j]);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k)continue;
                cost[i+1][k]=max(cost[i+1][k],cost[i][j]+a[i][k]);
            }
        }
    }
    int ans=max(cost[n][0],max(cost[n][1],cost[n][2]));
    printf("%d",ans);
    return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;


int main() {
    int n;
    cin >> n;
    vector<int> numbers(n);
    rep(i, n)cin >> numbers[i];

    int ave = accumulate(numbers.begin(), numbers.end(), 0) / n;
    int ans = 0;
    {
        for (int num : numbers) {
            int score = (num - ave) * (num - ave);
            ans += score;
        }
    }
    {
        ave++;
        int now = 0;
        for (int num : numbers) {
            int score = (num - ave) * (num - ave);
            now += score;
        }
        cmin(ans, now);
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n + 1);
    for (int i = 1; i <= n; i++) cin >> h[i];

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

    int ans = 0;

    for (int i = 1; i <= n; i++)  {
        bool high = true;
        for (auto j : w[i]) {
            if (!(h[i] > h[j])) {
                high = false;
                break;
            }
        }
        if (high) ans += 1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 8804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
//void chmin(int &a, int b) { if (a > b) a = b; }
//void chmax(int &a, int b) { if (a < b) a = b; }

vector<int> yakusuu(int n){
    vector<int> ans;
    for (int i = 1; i*i <= n; ++i) {
        if(n%i == 0){
            ans.push_back(i);
            if(i*i != n){
                ans.push_back(n/i);
            }
        }
    }
    return ans;
}

int main() {
    int n,cnt = 0;
    cin >> n;
    vector<int> tmp;
    for (int i = 1; i <= n; ++i) {
        if(i%2 == 1){
            tmp = yakusuu(i);
            if(tmp.size() == 8) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define in auto&it
#define out auto it
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
const double pi = acos(-1);
#define error(x) cerr<<#x<<" = "<<x<<'\n';
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		freopen("error.txt", "w", stderr);
	#endif
	fastio
	int n;
	cin>>n;
	int ar[n];
	for(int i=0;i<n;++i) cin>>ar[i];
	ll sum=0;
	for(int i=1;i<n;++i){
		if(ar[i-1]>ar[i]){
			sum+=ar[i-1]-ar[i];
			ar[i]=ar[i-1];
		}			
	}
	//for(int i=0;i<n;++i) cout<<ar[i];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 4392
import sys
n=int(input())
s=input()
if n%2==1:
    print("No")
    sys.exit()
s1=s[0:int(n/2)]
s2=s[int(n/2):]
if s1==s2:
    print("Yes")
else:
    print("No")
#print(s1)
#print(s2)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                                #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,pa>
                                        #define ppa pair<int,int>
                                        #define ppap pair<pa,pa>
                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-10)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
                                  #define VI vector<int>
                                        using namespace std;


int gcd(int a,int b){
	if(a<b) return gcd(b,a);
	if(b==0) return a;
	if(a%b==0) return b;
	return gcd(b,a%b);
}
map<int,int>ma;
           signed main(){
               int n;
  cin>>n;
           	for(int i=0;i<n;i++){
           		int k;
           	cin>>k;
           		ma[k]++;
           	}
           	int u;
           	int ans=0;
           	cin>>u;
           	for(int i=0;i<u;i++){
           	int k;
           		cin>>k;
           		if(ma[k]>0) ans++;
           	
           	}
           	
           	cout<<ans<<endl;
           }
             

Measured memory_bytes: 3172
str = input()

def checkstr(str):
    if len(str) % 2 != 0: return False
    half = int(len(str) / 2)
    if str[0:half] == str[half:len(str)]: return True
    else: return False

for x in range(len(str) -1):
    answer = len(str) - (x + 1)
    check = checkstr(str[0:answer])
    if check == True: break
print(answer)

Measured memory_bytes: 3060
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ans;
  ans = min(b,d) - max(a,c);
  
  if(ans < 0){
    cout << 0;
  }else{
    cout << ans;
  }
  
  return 0;
}

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

using namespace std;

signed main(){
    
    int n, k; cin >> n >> k;
    if(k == 1) cout << 0 << endl;
    else cout << n - k << endl;   
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n;
string s;
int r, b;
signed main() {
	cin >> n >> s;
	rep(i, n) {
		if (s[i] == 'R')r++;
		else b++;
	}
	if (r > b)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    vl a(n+2,0);
    vl v(n+2,0);
    ll sum = 0;
    rep(i,n){
        cin >> a[i+1];
        v[i+1] = abs(a[i+1] - a[i]);
        sum += v[i+1];
    }
    v[n+1] = abs(a[n+1]-a[n]);
    sum += v[n+1];
    //cout << sum << endl;
    rep(i,n){
        cout << sum + abs(a[i+2] - a[i]) - (v[i+2] + v[i+1]) << endl;
    }
}

Measured memory_bytes: 2816
#include <iostream>
using namespace std;
typedef long long ll;
ll n, p, ans;

ll pow(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return x * pow(x, y - 1);
	}
	else
	{
		ll yy = pow(x, y / 2);
		return yy * yy;
	}
}

int main()
{
	cin >> n >> p;
	if (n == 1)
	{
		cout << p << endl;
		return 0;
	}
	if (n > 100)
	{
		cout << 1 << endl;
      	return 0;
	}
	for (ll i = 1; pow(i, n) <= p; i++)
	{
		if (p % pow(i, n) == 0) ans = i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))

def simulate():
    global A
    B = [0]*N
    for i in range(N):
        l = max(0, i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    # if sum(B) == N*K:
    #     print(*[N]*N)
    #     print('aaaa')
    #     exit()
    A = B

for k in range(min(K,43)):
    simulate()
print(*A)

Measured memory_bytes: 174316
#include <iostream>
using namespace std;
int main(void){
   int A, B, C, D, E, time=0;
   cin >> A >> B >> C >> D >> E;
   
   if(A<0){
        time += (-A)*C;
        time += D;
        time += B*E;
   }
   else{
       time += (B-A)*E;
   }
   
   cout << time << endl;
   return 0;
    
}



Measured memory_bytes: 3076
a, b, k = map(int, input().split())
kcd = 0
for i in range(min(a + 1, b + 1), 0, -1):
    if a % i == 0 and b % i == 0:
        k -= 1
    if k == 0:
        kcd = i
        break
print(kcd)

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

const int MAX = 10000000;
const int MOD = 1000000007;

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

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

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



int main(){
    ll X,Y,total=0,Z;
    cin >> X >> Y;
    if((X+Y)%3!=0){
        cout << total << endl;
        return 0;
    }
    
    if(X>2*Y||Y>2*X){
        cout << total << endl;
        return 0;
    }
    Z=X+Y;
    X=X-Z/3;
    Y=Y-Z/3;
    
    Z=min(X,Y);
    
    // 前処理
    COMinit();

    // 計算例
    cout << COM(X+Y, X) << endl;
    

    return 0;
}




Measured memory_bytes: 234624
#include <iostream>
using namespace std ;
int main()
{
	int i;
	char s[100001];
	cin >> s;

	int app[26] = {}; //zenbu0
	
	for (i=0; s[i] != '\0'; i++){
		app[s[i] - 'a'] = 1;
	}
	for (int i = 0; i < 26; ++i) {
		if (app[i]==0) {
			cout << (char)(i + 'a');
			//printf("%c\n", (char)(i + 'a'));
			return 0;
		}
	}
	cout << "None";
	return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;

int main()
{	
	ll n,k;
	cin>>n>>k;
	if(k==1)
	{
		cout<<0;
		return 0;
	}
	ll a=n-k+1;
	ll b=1;
	cout<<a-b;
	return 0;
}

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

using namespace std;

int main() {

	int n, l;
	cin >> n >> l;

	int total=0;
	for (int i = 1; i < n+1; i++) {
		total += l + i - 1;
	}

	int minn = 100000;
	int minaji = 100000;
	for (int i = 1; i < n + 1; i++) {
		if (abs(total-(total- l- i + 1)) < minn) {
			minn = abs(total - (total - l - i + 1));
			minaji = total - l - i + 1;
		}
	}
	cout << minaji<< endl;

}

Measured memory_bytes: 256
import sys, math
#import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.buffer.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = 998244353
#from decimal import Decimal

x,n=mdata()
p=set(mdata())
m=x
v=0
for i in range(1,102):
    if i not in p:
        if abs(i-x)<m:
            v=i
            m=abs(i-x)
out(v)



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

int  bubbleSort(int A[],int N){
    int sw=0;
    bool flag=1;
    for(int i=0;flag;i++){
        flag=0;
        for(int j=N-1;j>=i+1;j--){
            if(A[j]<A[j-1]){
                swap(A[j],A[j-1]);
                flag=1;
                sw++;
            }
        }
    }
    return sw;
}
int main(){
    int A[100],N,sw;
    cin >> N;
    for(int i=0;i<N;i++)cin >> A[i];
    sw=bubbleSort(A,N);
    
    for(int i=0;i<N;i++){
        if(i)cout <<" ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    
    return 0;
}


Measured memory_bytes: 3104
n, k = map(int, input().split())
x = [int(i) for i in input().split()]
y = list(map(abs,x))
xl=0
xr=0
loop=n-k+1
ans=100000000000

for i in range(loop):
    if(x[i]*x[i+k-1]>=0):
        tmp=max(y[i],y[i+k-1])
        if(ans>tmp):
            ans=tmp
    else:
        tmp=2*min(y[i],y[i+k-1])+max(y[i],y[i+k-1])
        if(ans>tmp):
            ans=tmp
print(ans)


Measured memory_bytes: 14568
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;

int main()
{
    int m,n,ans=0;
    cin>>n;
    m=inf;
    int k;
    for(int i=0;i<n;i++)
    {
        cin>>k;
        if(k<m)
        {
            m=k;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    long n;
    cin >> n;
    long sum = 0;
    vector<long> num(n);
    
    for(int i=0 ; i < n ; i++){
        cin >> num[i];
        sum += num[i];
        //cout << n << num[i];
    }

    sort(num.begin(),num.end());
    //int sum = accumulate(num.begin(),num.end(),0);
 
    cout << num[0] << " " << num[n-1] <<" " <<  sum << endl;  
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while (A > 0) {
    C -= B;
    A -= D;
  }
  if (C > 0) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
  int q;
  cin >> q;

  for(int i = 0; i < q; i++){
    string a, b;
    cin >> a;
    cin >> b;

    vector<vector<int> > dp(a.size() + 1, vector<int>(b.size() + 1, 0));
    for(int i = 0; i < (int)a.size(); i++){ dp[i][0] = 0; }
    for(int i = 0; i < (int)b.size(); i++){ dp[0][i] = 0; }

    for(int i = 1; i <= (int)a.size(); i++){
      for(int j = 1; j <= (int)b.size(); j++){
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        if(a[i - 1] == b[j - 1])
          dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
      }
    }

    cout << dp[a.size()][b.size()] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 6756
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define P(x) cout << x << endl
#define D(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(int)(n); i++)
#define DEC(i,n) for (int i=(int)(n); --i>=0;)
#define S(s) (int)((s).size())
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,(v))
#define MA(a,v) a = max(a,(v))
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
typedef pair<int,int> ii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> myset;
const int N=2e5+5;
int a[N], pref[N];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k; cin>>n>>k;
    F(i,n) {
        cin>>a[i];
        a[i] -= k;
    }
    pref[0] = 0;
    F(i,n) {
        pref[i+1] = pref[i] + a[i];
    }
    myset s;
    s.insert({pref[n],n});
    int tot=0;
    DEC(i,n) {
        ii p{pref[i], i};
        tot += S(s) - s.order_of_key(p);
        s.insert(p);
    }
    P(tot);
}

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

int main(){
  ll n, k;
  cin >> n >> k;
  vector<vector<ll>> dp(n+1,vector<ll>(k+1));
  rep(i,k+1) dp[0][i] = 1;
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= k; j++) {
      if(i >= j) (dp[i][j] += dp[i-j][j]) %= mod;
      (dp[i][j] += dp[i][j-1]) %= mod;
    }
  }
  ll ans = (dp[n][k] - dp[n][k-1]) % mod;
  if(ans < 0) ans += mod;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 10712
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int X= sc.nextInt();

		if (X==3 || X==5 || X==7) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 23764
include Math
n = gets.chomp.to_i
digit_cout = log10(n).to_i
ans = 0
case digit_cout
when 5
  ans = 90909
when 4
  ans = (10000..n).count + (100..999).count + (1..9).count
when 3
  ans = (100..999).count + (1..9).count
when 2
  ans = (100..n).count + (1..9).count
when 1
  ans = (1..9).count
when 0
  ans = (1..n).count
end
p ans


Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, K;
const ll MAX_K = 100, MAX_RN = 40000;
// ll dp[MAX_K][MAX_RN];

int main(){
  cin >> N >> K;

  vll vec;
  for(ll i = 1; i * i <= N; i++) {
    vec.pb(i);
    if(i * i != N) {
      vec.pb(N / i);
    }
  }

  sort(ALL(vec));

  ll M = vec.size();

  vector<vector<ll>> dp(K, vector<ll>(M));

  dp[0][0] = 1;
  REP(i, M - 1) {
    dp[0][i + 1] = vec[i + 1] - vec[i];
  }

  REP(i, K - 1) {
    ll s = 0;
    RREP(j, M) {
      s += dp[i][M - j - 1];
      s %= MOD;
      dp[i + 1][j] = dp[0][j] * s % MOD;
    }
  }

  ll ans = 0;
  REP(j, M) {
    ans += dp[K - 1][j];
    ans %= MOD;
  }

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



Measured memory_bytes: 50936
#include <stdio.h>

int n, m;
int a[1024];

int main(void) {
	while (scanf("%d%d", &n, &m) == 2 && (n|m) != 0) {
		int i, j;
		int max = -1;
		for (i = 0; i < n; i++) {
			if (scanf("%d", &a[i]) != 1) return 1;
		}
		for (i = 0; i < n; i++) {
			for (j = i + 1; j < n; j++) {
				int sumipe = a[i] + a[j];
				if (sumipe <= m && max < sumipe) max = sumipe;
			}
		}
		if (max < 0) puts("NONE"); else printf("%d\n", max);
	}
	return 0;
}



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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

const int MAX = 1500001;

int hn[MAX] = {};
int wn[MAX] = {};

int main() {
	int n, m;

	while( 1 ) {
		cin >> n >> m; if( n == 0 && m == 0 ) break;
		vector<int> h( n );
		vector<int> w( m );

		REP( i, n ) {
			cin >> h[i];
			hn[h[i]]++;
		}
		REP( i, m ) {
			cin >> w[i];
			wn[w[i]]++;
		}


		REP( i, n ) {
			int htmp = h[i];
			FOR( j, i + 1, n ) {
				htmp += h[j];
				hn[htmp]++;
			}
		}
		
		REP( i, m ) {
			int wtmp = w[i];
			FOR( j, i + 1, m ) {
				wtmp += w[j];
				wn[wtmp]++;
			}
		}
		
		int cnt = 0;
		REP( i, MAX ) {
			if( hn[i] && wn[i] ) {
				cnt += hn[i] * wn[i];
			}
		}

		cout << cnt << endl;

		memset( hn, 0, sizeof( hn ) );
		memset( wn, 0, sizeof( wn ) );
	}
}


Measured memory_bytes: 14812
#include<stdio.h>

int main (void){

    int w,h;
    int i,j,k,l;

    while(scanf("%d%d",&w,&h),w){
        int dp[128][128][5]={{{0}}};
        dp[1][1][4]=1;
        int ans=0;

        for(i=1;i<=h;i++){
            for(j=1;j<=w;j++){
                for(k=0;k<5;k++){
                    switch(k){
                        case 0:
                            dp[i][j+1][1]+=dp[i][j][k];
                            dp[i][j+1][1]%=100000;
                            break;
                        case 2:
                            dp[i+1][j][3]+=dp[i][j][k];
                            dp[i+1][j][3]%=100000;
                            break;
                        case 1:
                            dp[i][j+1][1]+=dp[i][j][k];
                            dp[i+1][j][2]+=dp[i][j][k];
                            dp[i][j+1][1]%=100000;
                            dp[i+1][j][2]%=100000;
                            break;
                        case 3:
                            dp[i+1][j][3]+=dp[i][j][k];
                            dp[i][j+1][0]+=dp[i][j][k];
                            dp[i+1][j][3]%=100000;
                            dp[i][j+1][0]%=100000;
                            break;
                        case 4:
                            dp[i][j+1][1]+=dp[i][j][k];
                            dp[i+1][j][3]+=dp[i][j][k];
                            dp[i][j+1][1]%=100000;
                            dp[i+1][j][3]%=100000;
                            break;
                    }
                }
            }
        }
        for(i=0;i<4;i++){
            ans+=dp[h][w][i];
        }


        //printf("%d\n",dp[1][1][4]);
        /*puts("DBG");
        for(i=1;i<=h;i++){
            printf("###");
            for(j=1;j<=w;j++){
                for(k=0;k<5;k++){
                    printf("%7d",dp[i][j][k]);
                }
                printf(" ");
            }
            puts("");
        }
        /*for(i=0;i<5;i++){
            printf("%d### %d\n",i,dp[h][w][i]);
        }*/
        printf("%d\n",ans%100000);
    }

    return 0;
}

Measured memory_bytes: 924
s = input()
n = len(s)

res = 10**5
for c in set(list(s)):
    ss = list(s)
    cnt = 0
    while len(set(ss))>1:
        cnt += 1
        for i in range(len(ss)-1):
            if c==ss[i+1]:
                ss[i] = c
        ss.pop()
    res = min(res, cnt)

print(res)

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

int main()
{
  int n;
  cin >> n;
  if (n < 3) {
    cout << 0 << endl;
    return 0;
  }
  vector<int64_t> l(n);
  for (auto&& e : l) {
    cin >> e;
  }
  int64_t ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
        int64_t x = min(l[i], l[j]);
        int64_t y = max(l[i], l[j]);
        int64_t z = l[k];
        if (z < y) {
          if (x + z > y) {
            ans++;
          }
        } else if (x + y > z) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


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


int main() {
    int h,w;
    cin>>h>>w;
    string a;
    
    map<char,int> book;
    
    rep(i,h){
        cin>>a;
        rep(j,w)book[a[j]]++;
    }
    
    vector<int> count(4,0);
    
    for(auto p: book){
        count[p.second%4]++;
    }
    
    if(h%2==1 && w%2==1){
        if(count[1]+count[3]!=1){
            cout << "No" << endl;
            return 0;
        }
        
        if(count[1]==1){
            count[0]++;
        }
        if(count[3]==1){
            count[2]++;
        }
        
        if(count[2] > (h/2)+(w/2) || (count[2]+(h/2)+(w/2))%2==1){
            cout << "No" << endl;
            return 0;
        }
        
        cout << "Yes" << endl;
        
    }else if(h%2==0 && w%2==0){
        if(count[1]!=0 || count[2]!=0 || count[3]!=0){
            cout << "No" << endl;
            return 0;
        }
        cout << "Yes" << endl;
        
    }else{
        if(h%2)swap(h,w);
        
        if(count[1]!=0 || count[3]!=0){
            cout << "No" << endl;
            return 0;
        }
        
        if(count[2] > (h/2) || (count[2]+(h/2))%2==1){
            cout << "No" << endl;
            return 0;
        }
        cout << "Yes" << endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

class AB {
	private int fA;
	private int fB;

	public AB(int a, int b) {
		fA = a;
		fB = b;
	}

	public int getA() {
		return fA;
	}

	public int getB() {
		return fB;
	}

	public void setB(int b) {
		fB = b;
	}
}

class compAB implements Comparator<AB> {
	public int compare(AB ab1, AB ab2) {
		if (ab1.getA() < ab2.getA()) {
			return -1;
		} else if (ab1.getA() > ab2.getA()) {
			return 1;
		} else {
			return 0;
		}
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		ArrayList<AB> ABList = new ArrayList<AB>(N);
		for (int i = 0; i < N; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			ABList.add(new AB(a, b));
		}
		sc.close();

		Collections.sort(ABList, new compAB());

		long c = 0;
		int id = 0;
		for (int j = 0; j < M; j++) {
			c += ABList.get(id).getA();
			ABList.get(id).setB(ABList.get(id).getB() - 1);
			if (ABList.get(id).getB() == 0) {
				id++;
			}
		}

		System.out.println(c);
	}
}

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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

using namespace std;

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

    ll i,j,n,t=1,k=0,cnt=0,mini=LLONG_MAX,maxi=LLONG_MIN,ans=0;
    ll m;
    cin>>n;
    ll a[n],x[n+1],s[n+1];
    rep(i,0,n) cin>>a[i];
    j=0;
    rep(i,0,n)
    {
        while(j<n && ((ans&a[j])==0))
            ans+=a[j],j++;
        cnt+=j-i;
        ans-=a[i];
    }
    ret(cnt)
    return 0;

}


Measured memory_bytes: 1792