akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#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(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#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 show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n, k;
  cin >> n >> k;
  vi p(n);
  rep(i,n) {
    cin >> p[i];
  }
  vector<int> csum(p.size()+1);
  rep(i,p.size()) {
    csum[i+1] = csum[i] + (1+p[i]);
  }
  int mx = 0;
  rep(i,n-k+1) {
    int tmp = csum[i+k] - csum[i];
    chmax(mx, tmp);
  }
  double ans = mx/2.0;
  cout << fixed << setprecision(10) << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
 
   
int main(){
 int  n;
 cin >>n;
 vector<string> s(n);
 rep(i,n)cin >> s.at(i);
 map<string,int> w;
 rep(i,n){
   if(w.count(s.at(i))){
     w.at(s.at(i))++;
   }
   else w[s.at(i)]=1;
 }
 int cnt=0;
 rep(i,n){
    cnt=max(cnt,w.at(s.at(i)));
 }
 for(auto p : w){
   auto k=p.first;
   auto v=p.second;
   if(cnt==v)cout << k << endl;
 }
} 
    

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

int main(){
	int x = 0;
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			x = i * j;
			cout << i << "x" << j << "=" << x << endl;
		}
	}

	return 0;
}

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

#define int long long
typedef pair<int, int> P;

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

/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/

int A, B, C;

signed main() {
    int ans = LLONG_MAX;
    cin >> A >> B >> C;
    for (int i = 0; i <= 100; i++) {
        int a = A > i ? A - i : (i - A) / 2 + (i - A) % 2 * 2;
        int b = B > i ? B - i : (i - B) / 2 + (i -B) % 2 * 2;
        int c = C > i ? C - i : (i - C) / 2 + (i - C) % 2 * 2;
        ans = min(ans, a + b + c);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    ++v[a - 1];
    ++v[b - 1];
  }
  rep(i, n){
    cout << v[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

const int MAX_H = 110, MAX_W = 110;
int H, W;

char field[MAX_H][MAX_W];

int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

bool infield(int h, int w){
    return (0<=h && h<H && 0<=w && w<W);
}

void dfs(int h, int w){
    //果物の定義
    char fruits = field[h][w];
    field[h][w] = '.';
    for(int i=0; i<4; i++){
        int nh = h+dh[i];
        int nw = w+dw[i];
        if(infield(nh, nw) && field[nh][nw]==fruits)
            dfs(nh, nw);
    }
}

void solve(){
    int ans = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            //更新された点は'.'にする
            if(field[i][j] != '.'){
                dfs(i, j);
                ans++;
            }
        }
    }
    printf("%d\n", ans);
}

int main(){
    
    while(scanf("%d%d", &H, &W), H|W){
        for(int i=0; i<H; i++)
            scanf("%s", field[i]);
        solve();
    }
    return 0;
}

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

public class Main{
	public static InputReader scn = new InputReader();
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws Exception {
//		System.out.println("GO");
		
		int a = scn.nextInt(), b = scn.nextInt(), c = scn.nextInt(), d = scn.nextInt();
		
		if(Math.abs(a - c) <= d || (Math.abs(a - b) <= d && Math.abs(b - c) <= d)) {
			out.println("Yes");
		} else {
			out.println("No");
		}
		out.flush();
	}

	public static class InputReader {
		InputStream is;

		public InputReader() {
			is = System.in;
		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		char[][] nextMatrix(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = next(m);
			return map;
		}

		int[] nextArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		int nextInt() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}
	}
}


Measured memory_bytes: 23124
N, T = list(map(int, input().split()))
ps = list(map(int, input().split()))
min_p = 99999999999999
max_diff = 0
min_n = 0
 
for i in range(0, N):
    if ps[i] < min_p:
        min_p = ps[i]
    elif max_diff == ps[i] - min_p:
        min_n += 1
    elif max_diff < ps[i] - min_p:
        max_diff = ps[i] - min_p
        min_n = 1
 
print(str(min_n))

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

int main(){
  char b;
  cin>>b;
  if(b=='A'){
    cout<<'T';
  }
  if(b=='T'){
    cout<<'A';
  }
  if(b=='C'){
    cout<<'G';
  }
  if(b=='G'){
    cout<<'C';
  }
  cout<<endl;
}


Measured memory_bytes: 384
while True:
	t = input().split()
	a = int(t[0])
	b = int(t[1])
	if (a == 0) and (b == 0):
			break
	if (a < b):
		print(str(a) + " " + str(b))
	else:
		print(str(b) + " " + str(a))

Measured memory_bytes: 7668
using System;
using System.Collections.Generic;
using System.Text;

namespace ALDS1_3_B {
    class Program {
        static void Main(string[] args) {
            string[] input1 = Console.ReadLine().Split(' ');
            int n = int.Parse(input1[0]);
            int q = int.Parse(input1[1]);

            Queue<KeyValuePair<string, int>> que = new Queue<KeyValuePair<string, int>>();
            for(int i = 0; i < n; i++) {
                string[] input2 = Console.ReadLine().Split(' ');
                que.Enqueue(new KeyValuePair<string, int>(input2[0], int.Parse(input2[1])));
            }

            StringBuilder sb = new StringBuilder();
            int time = 0;
            while (que.Count>0) {
                KeyValuePair<string, int> cur = que.Dequeue();
                if (cur.Value > q) {
                    que.Enqueue(new KeyValuePair<string, int>(cur.Key, cur.Value - q));
                    time += q;
                    continue;
                }
                time += cur.Value;
                sb.AppendFormat("{0} {1}\n", cur.Key, time);
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 18396
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

void out(vvi v) {
  for (int i = 0; i < v.size(); ++i) {
    for (int x : v[i]) cout << x + 1 << ' ';
    cout << endl;
  }
}

vvi gr;
vector<int> mt;
vector<char> used; 
bool try_kuhn (int v) {
  if (used[v])  return false;
  used[v] = true;
  for (size_t i=0; i<gr[v].size(); ++i) {
    int to = gr[v][i];
    if (mt[to] == -1 || try_kuhn (mt[to])) {
      mt[to] = v;
      mt[v] = to;
      return true;
    }
  }
  return false;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  vvi a(n, vi(m));
  vector<vvi> ra(n, vvi(n));
  for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
    cin >> a[i][j];
    --a[i][j];
    ra[i][a[i][j] / m].push_back(a[i][j]);
  }
  vvi b(n, vi(m));
  vvi c = b;
  for (int col = 0; col < m; ++col) {
    gr.assign(2 * n, vi());
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) if (!ra[i][j].empty()) {
        gr[i].push_back(n + j);
      }
    }
    mt.assign (gr.size(), -1);
    for (int run = 1; run;) {
      run = 0;
      used.assign(gr.size(), false);
      for (int v=0; v<n; ++v) if (mt[v] == -1 && try_kuhn(v)) {
        run = 1;
      }
    }
    for (int i = 0; i < n; ++i) {
      assert(mt[i] != -1);
      int j = mt[i] - n;
      b[i][col] = ra[i][j].back();
      ra[i][j].pop_back();
    }
  }
  for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
    c[b[i][j] / m][j] = b[i][j];
  }
  out(b);
  out(c);
  return 0;
}


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

def selectionSort(A,N):
    num=0
    for i in range(N-1):
        minj=i
        for j in range(i,N):
            if A[minj] > A[j]:
                minj=j
        if minj != i:
            tmp=A[i]
            A[i]=A[minj]
            A[minj]=tmp
            num += 1
    return A,num

A,N=selectionSort(A,N)
print(*A)
print(N)



Measured memory_bytes: 5604
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        List<int> b = new List<int>();
        for (int i = 0; i < n; i++)
            b.Add(a[i] - (i + 1));
        b.Sort();

        int b_median = b[n / 2];

        // 偶数の場合の場合分け。なくても何故か答え出る。 
        if (n % 2 == 0)
        {
            b_median = (b[n / 2 - 1] + b[n / 2]) / 2;
        }

        long ans = 0;
        for (int i = 0; i < n; i++)
        {
            ans += Math.Abs(a[i] - (b_median + i + 1));
        }
        Console.WriteLine(ans);
    }
}

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

int main() {
    int N, K;
  	cin >> N >> K;
  	vector<int> h(N);
  	rep(i,N) cin >> h[i];
  	
  	int cnt  = 0;
  	rep(i, N){
      if (h[i] >= K) cnt++;
    }
  	cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
// sort(v.rbegin(),v.rend());
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	
	ll a,b,c,d;

	cin>>a>>b>>c>>d;	

	ll p = a*c;
	ll q = a*d;

	ll r = b*c;
	ll s = b*d;

	cout<<max(p,max(q,max(r,s)))<<endl;
}

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

int main(){
  int n,x;
  cin >> n >> x;
  int l[n];
  for(int i = 0;i < n;i++){
    cin >> l[i];
  }
  int d = 0,result = 0,i = 0;
  while(d <= x && i <= n){
    result++;
    d += l[i];
    i++;
  }
  if(d > x){
    cout << result << endl;
  }
  else{
    cout << n+1 << endl;
  }
}

Measured memory_bytes: 256
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()

def main():
    S = list(input())
    T = list(input())

    S_memo = defaultdict(str)
    T_memo = defaultdict(str)

    for s, t in zip(S, T):
        if (S_memo[s] and S_memo[s] != t) or (T_memo[t] and T_memo[t] != s):
            print('No')
            exit()
        else:
            S_memo[s] = t
            T_memo[t] = s
    print('Yes')

if __name__ == '__main__':
    main()


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


void solve(long long N){
    vector<long long> divisors;
    long double sqrtN = sqrt(N);
    for(long long i=1;i<=sqrtN;i++){
        if(N%i == 0){
            divisors.push_back(i);
            // cerr<<i << endl;
        }
    }
    long long prior = divisors[divisors.size()-1];
    cerr<< prior << endl;
    long long last = N / prior;
    cout <<  prior + last -2<< endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
ll ceil(ll a,ll b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll i,j,arr[n+1],pos;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    vector<ll> v;
    ll cnt[n+1],x;
    map<ll,ll> occ;
    memset(cnt,0,sizeof(cnt));
    for(i=n;i>0;i--)
    {
        x=2;
        while((x*i)<=n)
        {
            if(occ[x*i]>0)
                cnt[i]++;
            x++;
        }
        if(cnt[i]%2!=arr[i-1])
        {
            v.push_back(i);
            occ[i]++;
            cnt[i]++;
        }
        
    }
    reverse(v.begin(),v.end());
    cout<<v.size()<<endl;
    for(i=0;i<v.size();i++)
    {
        cout<<v[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 17268
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  lol ans = 0;
  reps(i, n){
    if(i % 3 != 0 && i % 5 != 0){
      ans += i;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3652
def calc(N, S):
    id = {'R': 0, 'G': 1, 'B': 2}
    rgb = [[0, 0, 0] for _ in range(N)]
    rgb[0][id[S[0]]] = 1
    for i in range(1, N):
        for j in [0, 1, 2]:
            rgb[i][j] = rgb[i - 1][j]
            if j == id[S[i]]:
                rgb[i][j] += 1
    result = 0
    for i in range(N - 1, -1, -1):
        X = S[i]
        YZ = (['G', 'B'] if X == 'R' else ['R', 'B'] if X == 'G' else ['R', 'G'])
        j = i - 1
        while j > -1:
            if S[j] in YZ:
                result += rgb[j][3 - id[X] - id[S[j]]]
                if 2 * j - i > -1 and not S[2 * j - i] in [X, S[j]]:
                    result -=1
            j -= 1
    return result


N = int(input())
S = input()
print(calc(N, S))

Measured memory_bytes: 68664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <map>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){
    long long int n, p;
    cin>>n>>p;
    long long int result = 0;
    long long int tmp;
    string s;
    cin >> s;
    
    if(p==2||p==5){
        long long int tmp2=1;
        REP(i,n){

            tmp = (long long int)(s[i] - '0');
            if(tmp%p==0){
                result += i + 1;
            }
          //  cout << result << endl;
        }

        cout << result << endl;
    }else{
        vector<long long int> amari(10001, 0);
        amari[0] = 1;
        long long int num=0,bairitu = 1;
        DEFOR(i,n,0){
            num = (num + (bairitu * ((long long int)(s[i] - '0'))))% p;
            bairitu = (bairitu * 10) % p;
            result += amari[num];
            amari[num]++;
        }
        cout << result << endl;
    }

    return 0;
}


Measured memory_bytes: 832
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    ll N,A,B,C,D,E; 
    cin >> N >> A >> B >> C >> D >> E;
    if(min(A,min(B,min(C,min(D,E)))) >= N) {
        cout << 5 << endl;
    } else {
        if(N%min(A,min(B,min(C,min(D,E)))) == 0)
            cout << N / min(A,min(B,min(C,min(D,E)))) + 4 << endl;
        else cout << N / min(A,min(B,min(C,min(D,E)))) + 1 + 4 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include <algorithm>
#include <queue>
#define NIL -1
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MAX 10003
#define GREY 1
#define BLACK 0
#define WHITE 2
int main() {
	string s;
	int a[1000] = { 0 };
	cin >> s; bool d = true;
	int le = s.size();
	REP(i, le) {
		if (a[(int)s[i] - (int)'a'] == 1) {
			cout << "no" << endl; d = false; break;
		}
		a[(int)s[i] - (int)'a']++;
	}
	if (d) { cout << "yes" << endl; }
	return 0;
}


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

int main(){
	long long n, a, b;
	cin>>n>>a>>b;
	if(b<a)
		cout<<"0\n";
	else if(n==1 && a!=b)
		cout<<"0\n";
	else if(n <=2 )
		cout<<"1\n";
	else
		cout<<(n-2)*b - (n-2)*a +1<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int n, b[120000];
unsigned long long ans;

void sort(int *a, int n) {
	for(int i = n - 1; i > 0; --i) {
		int k = 0, tmp = a[i];
		a[i] = a[0];
		a[0] = tmp;
		for(;;)
			if(k * 2 + 2 < i)
				if(tmp < a[k * 2 + 1])
					if(a[k * 2 + 1] > a[k * 2 + 2]) {
					SWAP_1:
						a[k] = a[k * 2 + 1];
						a[k = k * 2 + 1] = tmp;
					}
					else {
					SWAP_2:
						a[k] = a[k * 2 + 2];
						a[k = k * 2 + 2] = tmp;
					}
				else if(tmp < a[k * 2 + 2]) goto SWAP_2;
				else break;
			else if(k * 2 + 2 == i)
				if(tmp < a[k * 2 + 1]) goto SWAP_1;
				else break;
			else break;
	}
}

void bs(int l, int r, int *a, int a_left, int a_right, int *c, int c_left, int c_right) {
	if(l < r) {
		int al = a_left, ar = a_right;
		while(al < ar)
			if(a[(al + ar - 1) / 2] < b[(l + r - 1) / 2]) al = (al + ar + 1) / 2;
			else ar = (al + ar - 1) / 2;
		int cl = c_left, cr = c_right;
		while(cl < cr)
			if(c[(cl + cr) / 2] > b[(l + r - 1) / 2]) cr = (cl + cr) / 2;
			else cl = (cl + cr + 2) / 2;
		ans += (unsigned long long)ar * (n - cr);
		bs(l, (l + r - 1) / 2, a, a_left, ar, c, c_left, cr);
		bs((l + r + 1) / 2, r, a, ar, a_right, c, cr, c_right);
	}
}

int main() {
	static int a[120000], c[120000];
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) {
		scanf("%d", a + i);
		for(int j = i, ia = a[i]; ia > a[(j - 1) / 2]; a[j = (j - 1) / 2] = ia) a[j] = a[(j - 1) / 2];
	}
	for(int i = 0; i < n; ++i) {
		scanf("%d", b + i);
		for(int j = i, ib = b[i]; ib > b[(j - 1) / 2]; b[j = (j - 1) / 2] = ib) b[j] = b[(j - 1) / 2];
	}
	for(int i = 0; i < n; ++i) {
		scanf("%d", c + i);
		for(int j = i, ic = c[i]; ic > c[(j - 1) / 2]; c[j = (j - 1) / 2] = ic) c[j] = c[(j - 1) / 2];
	}
	sort(a, n);
	sort(b, n);
	sort(c, n);
	bs(0, n, a, 0, n, c, 0, n);
	printf("%llu\n", ans);
}

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

int main() {

  int X,N;

  cin >>X>>N;
  
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin >>p[i];
  }
  sort(p.begin(),p.end());
  int a=0;
  int b=0;
    int m=1;
    for(int i=0;i<N;i++){
    if(p[i]==X){
      a=1;
      b=i;
    }
  }
  
  if(a==0){
    cout << X<< endl;
  }
  else{
    while(m>0){
    if(b-m<0){
      cout<<X-m<<endl;
      break;
    }
    
    if(b-m>=0){
     if(p[b-m]!=X-m){
     cout<< X-m <<endl;
       break;
     }
    }
    
     if(b+m>=N){
       cout<<X+m<<endl;
       break;
     }
    
      if(b+m<N){
        if(p[b+m]!=X+m){
          cout<<X+m<<endl;
          break;      
    }       
  }
      m=m+1;
    }
  }
    
 return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y){
    if (y == 0) return x;
    return gcd(y, x%y);
}
ll lcm(ll x,ll y){
    return x*y/gcd(x,y);
}
int main(void){
    ll n,m;cin>>n>>m;
    vector<ll> b(n);
    ll xx=-1;
    ll y;cin>>y;
    b[0]=y/2;
    while(y>0){
        if(y%2==1){
            xx=b[0]*2/y;
            break;
        }
        y/=2;
    }
    for(int i=1;i<n;i++){
        ll x;cin>>x;
        b[i]=x/2;
        if((x/xx)%2==0){
            cout<<0<<endl;
            return 0;
        }
    }
    ll L=b[0];
    for(int i=1;i<n;i++){
        L=lcm(L,b[i]);
        if(L>m){
            cout<<0<<endl;
            return 0;
        }
    }
    m/=L;
    ll res=(m+1)/2;
    cout<<res<<endl;
}

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

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextInt();
        var B = sc.ArrayInt(N-1);
        var A = new int[N + 1];
        A[0] = B[0];

        for (int i = 0; i < N-1; i++) {
            if (i == N -2 || B[i] <= B[i+1]) {
                A[i + 1] = B[i];
            } else {
                A[i + 1] = B[i + 1];
            }
        }
        WriteLine(A.Sum());
    }
    
}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13268
import java.util.*;

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

      int x=sc.nextInt();
      int a=sc.nextInt();

      if(x<a){
          System.out.println("0");
      }
      else{
        System.out.println("10");
      }

    }
}


Measured memory_bytes: 22996
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        long k = in.nextLong();
        in.nextLine();
        final int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        in.nextLine();
        if (k <= n) {
            int res;
            for (res = 1; k > 0; k--) {
                res = arr[res - 1];
            }
            System.out.println(res);
            return;
        }
        int slow = 1;
        int fast = 1;
        do {
            slow = arr[slow - 1];
            fast = arr[arr[fast - 1] - 1];
        } while (slow != fast);
        int cycle = 0;
        do {
            slow = arr[slow - 1];
            cycle++;
        } while (slow != fast);
        slow = 1;
        int initial = 0;
        while (slow != fast) {
            slow = arr[slow - 1];
            fast = arr[fast - 1];
            initial++;
        }
        k -= initial;
        k = Math.floorMod(k, cycle);
        int res;
        for (res = slow; k > 0; k--) {
            res = arr[res - 1];
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 60128
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

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

n = gets_i
alist = gets_i_list

i = 1
ans = []
alist.each do |a|
    if a == i
        ans.push i
        i += 1
    end
end

if ans.empty?
  puts -1
else
  puts n - ans.size
end

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;map<int,int> mp;
    for (int i=0; i<n; i++) {
	int x; cin>>x;
	mp[x]++;
    }

    int tot = 0;
    for (auto p: mp) {
	tot += p.second-1;
    }

    int cnt = mp.size();
    cnt -= (tot%2);
    out(cnt);
  

    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int N;
    cin >> N;
    int A[N][N-1];
    rep(i,N) rep(j,N-1) {
        cin >> A[i][j];
        A[i][j]--;
    }

    vector<int> count(N, 0);

    int leftCount = N * (N - 1) / 2;
    int days = 0;

    queue<int> que;
    rep(i,N) que.push(i);

    while (leftCount > 0) {
        vector<bool> played(N, false);
        queue<int> que_today;
        while (!que.empty()) {
            int i = que.front(); que.pop();
            if (played[i] || count[i] >= N - 1) continue;
            int k = A[i][count[i]];
            if (!played[k] && A[k][count[k]] == i) {
                count[i]++;
                count[k]++;
                played[i] = true;
                played[k] = true;
                que_today.push(i);
                que_today.push(k);
                leftCount--;
            }
        }
        if (que_today.empty()) {
            cout << -1 << endl;
            return 0;
        }
        while (!que_today.empty()) {
            que.push(que_today.front());
            que_today.pop();
        }
        days++;
    }

    cout << days << endl;
    
    return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
string a[500001];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		sort(a[i].begin(),a[i].end());
	}
	sort(a+1,a+n+1);
	long long ans=0;
	long long length=1;
	/*for(int i=1;i<=n;i++)
	cout<<a[i]<<endl;*/
	for(int i=1;i<=n;i++)
	{
		while(a[i]==a[i+1])
		{
			length++;
			i++;
		}
		ans+=length*(length-1)/2;
		length=1;
	}
	cout<<ans;
 } 

Measured memory_bytes: 10368
#C
n,q = map(int,input().split())
s = input()
#累積和で考える
cnt = 0
cumsum = []
prev = s[0]
for i in range(n):
    now = s[i]
    if now == "C" and prev == "A":
        cnt += 1
    cumsum.append(cnt)
    prev = now
    
#print(cumsum)
for i in range(q):
    l,r = map(int,input().split())
    print(cumsum[r-1] - cumsum[l-1])

Measured memory_bytes: 6128
def bubbleSort(a,n)
  count = 0
  flag = true
  while flag
    flag = false
    for j in (1..n-1).to_a.reverse
      if a[j] < a[j-1]
        a[j],a[j-1] = a[j-1],a[j]
        flag = true
        count += 1
      end
    end
  end
  return count
end

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|x| x.to_i}
count = bubbleSort(a,n)
printf("%s\n",a.join(" "))
printf("%d\n",count)


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

int main()
{
    long int n;
    cin >> n;

    long long int input;
    vector<long long int>vec;

    for(long int i = 0; i < n; i++){
        cin >> input;
        vec.push_back(input);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    long long int a = 0, b = 0, c = 0, area_1 = 0, area_2 = 0;
    int cnt = 0;

    for(long int i = 0; i < n; i++){
        if((vec[i] == vec[i+3] || vec[i] == vec[i+1]) && vec[i] > a){
            a = vec[i];
        }
        if(vec[i] == vec[i+3] && vec[i] > c){
            c = vec[i];
        }
        if((vec[i] == vec[i+3] || vec[i] == vec[i+1]) && vec[i] < a && vec[i] > b)
            b = vec[i];
    }

    area_1 = a*b;
    area_2 = c*c;

    if(area_1>area_2)
        cout << area_1;
    else
        cout << area_2;
    return 0;
}


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

int main() {
	int A,B,N,i,n1,n2,n4,n5,sums;
  	cin >> A >> B;
  	i = B - A;
  	sums = 0;
  	for (;i >= 0; i--){
 		N = A;
      	n1 = N % 10;
    	N /= 10;
    	n2 = N % 10;
    	N /= 100;
    	n4 = N % 10;
    	N /= 10;
    	n5 = N;
      	
      	if (n1 == n5 && n2 == n4){
        	sums++;
        }
      	A++;
    }
  	cout << sums << endl;
}

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

using namespace std;

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

	int n;

	cin >> n;

	n = 25 - n;

	cout << "Christmas";
	for(int i=0;i<n;i++)
	{
		cout << " Eve";
	}
	cout << '\n';
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

string str;
signed main(){
	cin >> str;
	int n = str.size(), ans = 0;
	rep(i,n){
		if(str[i] == 'g')ans++;
		else ans--;
	}
	printf("%lld\n", ans/2);
	return 0;
}




Measured memory_bytes: 512
n = int(input())
H = list(map(int, input().split()))
dp = [10**9 for i in range(n)]

dp[0] = 0
for i in range(1,n):
    b = 10**9
    if i > 1:
        b = dp[i-2] + abs(H[i]-H[i-2])
    dp[i] = min(dp[i-1] + abs(H[i]-H[i-1]),b)
print(dp[n-1])

Measured memory_bytes: 13928
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[100005];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int current_botan=1;
    int ans=0;
    for(int i=0;i<n;i++){
        if(current_botan==2)break;
    current_botan=a[current_botan];
    ans++;
    }
    if(ans>=n)cout<<-1<<endl;
    else cout<<ans<<endl;
}

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

int main(){
  int D,N;
  
  cin>>D>>N;
  
  
  if(D>0&&N<100){
    cout<<N*pow(100,D);
  }
  
  else if(D==1&&N==100){
    cout<<10100<<endl;
  }
  
  else if(D==2&&N==100){
    cout<<1010000<<endl;
  }
    
  else if(D==0&&N<100){
    cout<<N<<endl;
  }
  
  else if(D==0&&N==100){
    cout<<101<<endl;
  }
  
  
  
}

    


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

m = 1000
k = 0

for i in range(n - 1):
    if a[i] < a[i + 1]:
        tmp = m // a[i]
        k += tmp
        m -= tmp * a[i]
    else:
        m += k * a[i]
        k = 0
m += k * a[-1]
print(m)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define For(i, a, b) for(int i=(a); i<(b); i++)
#define rFor(i, a, b) for(int i=(a)-1; i>=(b); i--)
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
using namespace std;

int main(){
  int n, c; cin >> n >> c;
  int MAX = 200010;
  int tv[c][MAX];
  rep(i, c)rep(j, MAX) tv[i][j] = 0;
  rep(i, n){
    int s, t, c; cin >> s >> t >> c;
    tv[--c][2*s-1]++; tv[c][2*t+1]--;
  }
  rep(i, c){
    int cur = 0;
    rep(j, MAX) cur += tv[i][j], tv[i][j] = cur;
  }
  int ans = 0;
  rep(i, MAX){
    int cnt = 0;
    rep(j, c)if(tv[j][i] > 0) cnt++;
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 23680
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

long long number[87];



long long solve(const long long n)
{
  number[0] = 2LL;
  number[1] = 1LL;
  for (int i = 2; i <= n ; i++)
    number[i] = number[i - 2] + number[i - 1];
  return number[n];
}

int main()
{
  int n;
  cin >> n;
  cout << solve(n) << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int d = (b/a)*a;
  if((d>=b && d<= c) || (d+a>=b && d+a<=c)) cout << "OK" << endl;
  else cout << "NG" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int n;
	cin>>n;

	int a[n];
	int total=0;

	for(int i=0;i<n;i++){
		cin>>a[i];
		total+=a[i];
	}
	// cout<<"total:"<<total<<endl;
	sort(a,a+n);

	// for(int i=0;i<n;i++){
	// 	cout<<a[i]<<endl;
	// }
	int count=0;
	if(total%10!=0){
		cout<<total<<endl;
		return 0;
	}else{
		for(int i=0;i<n;i++){
			if(a[i]&10!=0){
				cout<<total-a[i]<<endl;
				return 0;
			}else{
				count++;
				
			}

			if(count==n){
				cout<<0<<endl;
			}
		}
	}



}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, B, C;
  cin >> A >> B >> C;
  if (A % 2 == 0 && A == B && B == C)
    cout << -1 << endl;
  else
  {
    ll ans = 0;
    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0)
    {
      ans++;
      ll D = A, E = B, F = C;
      A = E / 2 + F / 2;
      B = D / 2 + F / 2;
      C = D / 2 + E / 2;
      cerr << A << " " << B << " " << C << endl;
    }
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;
ll inf = (ll)1 << 62;

// Actual array
vector<ll> v;

// 2D memo
vector<vector<ll>> memo;

// Solves [lo,hi] with the current player
ll solve(ll lo, ll hi, bool b) {
    // Chech memo
    if(memo[lo][hi] != inf) return memo[lo][hi];

    // Base case
    if(lo == hi) {
        if(b) {
            memo[lo][hi] = v[lo];
            return v[lo];
        }
        else {
            memo[lo][hi] = -v[lo];
            return -v[lo];
        }
    }

    // General case
    ll ans;
    if(b) {
        ans = max(solve(lo+1,hi,!b) + v[lo], solve(lo,hi-1,!b) + v[hi]);
    }
    else {
        ans = min(solve(lo+1,hi,!b) - v[lo], solve(lo,hi-1,!b) - v[hi]);
    }
    memo[lo][hi] = ans;
    return ans;
}

int main() {
    ll n;
    cin >> n;
    v.resize(n);
    for(auto& i : v) {
        cin >> i;
    }
    memo.resize(n+1,vector<ll>(n+1,inf));
    cout << solve(0,n-1,true) << endl;
}


Measured memory_bytes: 70912
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int W,H,N; cin >> W >> H >> N;
    int xm = 0,xM = W,ym = 0,yM = H;
    rep(i,N){
        int x,y,a; cin >> x >> y >> a;
        if(a == 1){
            xm = max(xm,x);
        }
        else if(a == 2){
            xM = min(xM,x);
        }
        else if(a == 3){
            ym = max(ym,y);
        }
        else{
            yM = min(yM,y);
        }
    }
    cout << max(0,xM-xm)*max(0,yM-ym) << endl;
}

    



Measured memory_bytes: 256
N=int(input())
v=list(map(int,input().split()))
v_sort=sorted(v,reverse=False)
while len(v_sort)>1:
    v_sort=sorted(v_sort,reverse=False)
    v_sort.append((v_sort[0]+v_sort[1])/2)
    del v_sort[0]
    del v_sort[0]
print(*v_sort)

Measured memory_bytes: 9080
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
#define P 998244353

using namespace std;

int C[4444][4444], O[4444][4444];

int calc(int n, int a, int b) {
    if(n == 0) return 0;
    int ans = 0;
    for(int i = 0; i <= b && i <= n; i++) {
        int tmp = 0;
        if(i == 0) tmp = C[a + n - 1][n]; else
        if(a == 0) tmp = C[n - 1][i - 1]; else
        tmp = C[a + n - 1][a + i - 1];
        ans = (ans + tmp * O[2][i] % P * C[b][i]) % P;
    }
    return ans;
}

signed main() {
    int k, n;
    scanf("%lld%lld", &k, &n);
    for(int i = 0; i <= 4000; i++)
        for(int j = 0; j <= i; j++)
            C[i][j] = !j ? 1 : (C[i - 1][j - 1] + C[i - 1][j]) % P;
    for(int i = 0; i <= 4000; i++) {
        O[i][0] = 1;
        for(int j = 1; j <= 4000; j++) O[i][j] = O[i][j - 1] * i % P;
    }
    for(int i = 2; i <= 2 * k; i++) {
        int ans = 0, l = 1, r = k;
        l = max(l, i - k);
        r = min(r, i - 1);
        int tmp = (r - l + 1) / 2;
        if(i % 2 == 0) {
            ans = (calc(n, k - tmp * 2 - 1, tmp) + calc(n - 1, k - tmp * 2 - 1, tmp)) % P;
            // assume n > 1
        } else ans = calc(n, k - tmp * 2, tmp);
        printf("%lld\n", (ans % P + P) % P);
    }
    return 0;
}

Measured memory_bytes: 280832
#!/usr/bin/env python3
import sys
from functools import reduce
from operator import add
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int):
    if N % reduce(add, [int(c) for c in str(N)]) == 0:
        yes()
    else:
        no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <assert.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
#include <bitset>
// #include <iostream>
// #include <iomanip>
// #include <sstream>
using namespace std;
// const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
// const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dx[] = {2, 2, -2, -2, 1, 1, -1, -1};
// const int dy[] = {-1, 1, 1, -1, 2, -2, 2, -2};
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define fr(i, a, b) for(int i = a ; i < (int)b ; i++)
#define frr(i, a, b) for(int i = a ; i >= (int)b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false)
#define boost2 cin.tie(NULL)
#define ln puts("")
#define mems(a) memset(a, 0, sizeof(a))
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
ll on_bit(ll x, int pos) {x |= (1ll << pos); return x;}
int off_bit(int x, int pos) {x &= ~(1 << pos); return x;}
bool is_on_bit(ll x, int pos) {return ((x & (1ll << pos)) != 0);}
int flip_bit(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
int on_bit_all(int x, int pos) {x = (1 << pos)-1; return x;}
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int MOD = 1e9+7;
int add(ll a, ll b){return ((a%MOD)+(b%MOD))%MOD;}
int sub(ll a, ll b){return ((a%MOD)-(b%MOD))%MOD;}
int mult(ll a, ll b){return ((a%MOD)*(b%MOD))%MOD;}
ll powmod(ll a,ll b){ll res=1;assert(b>=0);a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

const int N=55;
ll len[N];

ll f_left(int n, ll x);
ll f_right(int n, ll x);
ll f(int n, ll x);

ll f_left(int n, ll x){
	return f(n-1,x);
}

ll f_right(int n, ll x){
	if(n==0)return 1LL;
	if(x==1)return 0LL;
	if(x==(len[n])/2+1){
		return (1ll<<(n));
	}
	return f(n-1,x-1);
}

ll f(int n, ll x){
	if(n==0)return 1LL;
	if(len[n]==x)return (1ll<<(n+1))-1;
	ll res=f_right(n,min((len[n])/2+1,x));
	if(x>(len[n])/2+1)res+=f_left(n,x-((len[n])/2+1));
	return res;
}

int main(){
	int n;
	ll x;
	sf("%d%lld",&n,&x);
	len[0]=1;
	fr(i,1,51)len[i]=len[i-1]+len[i-1]+3;
	pf("%lld\n",f(n,x));
	return 0;
}

/*
	1 P
	5 BP P PB
	13 BBPPPB P BPPPBB
	29 BBBPPPBPBPPPBB P BBPPPBPBPPPBBB
*/

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
 
#define abs(a) ((a) < (0)? -(a):(a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define pb push_back
 
int main() {
    ll a, b;
    cin >> a >> b;
    
    ll ans = a;
    if(a != b) {
        if(a%2==0 && b%2==0) ans = ((b-a)/2)%2==0? b : b^1;
        else if (a%2==0 && b%2==1) ans = ((b-a+1)/2)%2==0? 0:1;
        else if (a%2==1 && b%2==0) ans = ((b-a)/2)%2==0? a^b : a^b^1;
        else ans = ((b-a)/2)%2==0? a:a^1;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010];
int main() {
	int n;
  	cin>>n;
	for (int i = 0; i<n; i++) {
		cin >> a[i] >> b[i];
	}
	sort(a, a + n);
	sort(b, b + n);
	if (n & 1) {
		cout << b[n / 2] - a[n / 2] + 1 << endl;
	}
	else {
		cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1 << endl;
	}
	return 0;
}


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

int main(){
	int snukes, snacks;
	cin >>snukes >> snacks;

	vector<int> ans(snukes, -1);
	int a = 0;
	while(a < snacks){
		int d;
		cin >> d;
		vector<int> l(d, 0);
		for(int i=0;i<d;i++){
			cin >> l[i];
			ans[l[i]-1]++;
		}
		a++;
	}
	int count = 0;
	for(int i=0;i<ans.size();i++){
		if(ans[i] == -1)
			count++;
	}
	cout<<count<<endl;
   	return 0;
}

Measured memory_bytes: 3616