akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <ratio>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T, class U> using p = pair<T, U>;

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

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

const ull MOD = 1000'000'007;

ll N;

int main(){
    string S;
    cin >> S;
    for(auto& x : S){ x = 'x'; }
    cout << S << endl;
}



Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod1 1000000007
#define mod2 1000000009
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;

class CStep {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        int n;
        cin>>n;
        ll a[n];
        for (int i=0;i<n;i++)
            cin>>a[i];
        ll mx=a[0],ans=0;
        for (int i=0;i<n;i++){
            if (a[i]<mx){
                ans+=mx-a[i];
            }
            mx=max(mx,a[i]);
        }
        cout<<ans<<endl;
	}
};


int main() {
	CStep solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 5212
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int sum = 0;
        for(int i=0;i<M;i++){
            sum += sc.nextInt();
        }
        if(N>=sum){
            System.out.println(N-sum);
        }else {
            System.out.println(-1);
        }
        
    }
}

Measured memory_bytes: 46204
#include <stdio.h>
         
        int main()
        {int a,i;
        scanf("%d",&a);
        unsigned long long b[100000],c;
        c=1;
        for(i=0;i<a;i++){
            scanf("%llu",&b[i]);
            if(b[i]==0){printf("0");return 0;}
              }
        for(i=0;i<a;i++){
            long double cc=c;
            long double bi=b[i];
            if(cc*bi>1e+18){printf("-1");return 0;
                                }
                c=c*b[i];}
        printf("%llu\n",c);
         return 0;
        }

Measured memory_bytes: 2488
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))


ans = 10 ** 11
for  i in range(2 ** N):
    if bin(i).count("1") != K:
        continue
    max_height = 0
    height_num = 0
    for j in range(N):
        if i >> j & 1:
            if a[j] <= max_height:
                height_num += (max_height + 1 - a[j])
                max_height += 1
            else:
                max_height = a[j]
        else:
            max_height = max(max_height, a[j])
    ans = min(ans, height_num)

print(ans)

Measured memory_bytes: 42092
#include<stdio.h>
int main(void)
{
    int N, D, X, i, A[100], a, c;
    scanf("%d%d%d", &N, &D, &X);
    for(i=0; i<N; i++)
    scanf("%d", &A[i]);
    c = 0;
    for(i=0; i<N; i++)
       c = (D-1) / A[i] + c;
    a = c + 1*N + X;
    printf("%d\n", a);
    return 0;
}


Measured memory_bytes: 128
def acl_beginner_c():
    class UnionFind:
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    n, m = map(int, input().split())
    uft = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        uft.union(a-1, b-1)
    print(uft.group_count()-1)
acl_beginner_c()

Measured memory_bytes: 74208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)


vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int main(){
    int n;
    cin>>n;
    auto p=prime_table(55555);
    rep(i,55556){
        if(p[i]){
            if(i%5!=1)p[i]=false;
        }
    }
    int ctr=0;
    rep(i,55556){
        if(ctr==n)break;
        if(p[i]){
          if(ctr)cout<<" ";
          cout<<i;
          ++ctr;
        }
    }
    cout<<endl;
}

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

int main(){
    int a, b, c,d;
    cin >> a >> b >> c >> d;

    if(a+b > c+d)   cout << "Left\n";
    else if(a+b == c + d)   cout << "Balanced\n";
    else cout << "Right\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a,b;
  scanf("%d %d",&a,&b);
  if(a%3==0||b%3==0||(a+b)%3==0){
  	printf("Possible\n");
  }else{
  	printf("Impossible\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<long long int> a(n), b(n);
    for (int i = 0; i < n - 1; i++){
        cin >> b[i];
        a[i] = b[i];
    }
    a[n - 1] = a[n - 2];

    for (int i = 0; i < n - 1;i++) {
        if (a[i + 1] > b[i]) {
            a[i + 1] = b[i];
        }
    }
    int ans = 0;
    for (int i = 0; i < n;i++){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, i = LI()
    print(n-i+1)
    return

#B
def B():
    h, w = LI()
    a = SR(h)
    dy = defaultdict(int)
    dx = defaultdict(int)
    for y in range(h):
        for x in range(w):
            if a[y][x] == "#":
                dx[x] = 1
                dy[y] = 1
    dy = list(sorted(dy.items(), key=lambda x: x[0]))
    dx = list(sorted(dx.items(), key=lambda x: x[0]))
    for y,_ in dy:
        for x,_ in dx:
            print(a[y][x], end="")
        print()


    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 45016
#include <bits/stdc++.h>
#define MOD 1000000007
/// TONI BO$$ was here
/// #MLC

using namespace std;
int a[2001],b[2001];
long long dp[2001][2001];
int main()
{
    int n,m,i,j;
    scanf("%d%d",&n,&m);
    for(i=1; i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=1; i<=m;i++)
    {
        scanf("%d",&b[i]);
    }
    for(i=1; i<=n; i++)
    {
        if(a[i]==b[1])
            dp[i][1]=1;
        dp[i][1]+=dp[i-1][1];
    }
    for(i=1; i<=m; i++)
    {
        if(b[i]==a[1])
            dp[1][i]=1;
        dp[1][i]+=dp[1][i-1];
    }
    for(i=2; i<=n; i++)
        for(j=2; j<=m; j++)
        {
            if(a[i]==b[j])
                dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%MOD;
            dp[i][j]=(dp[i][j]+dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]+MOD)%MOD;
        }
    printf("%lld",(dp[n][m]+1)%MOD);

    return 0;
}


Measured memory_bytes: 31488
#include<stdio.h>
 int main(){
 	int a,b,odd = 0, even = 0;
 	scanf("%d %d",&a,&b);
 	for (int i=2; i<=a; i++){
 		odd =odd + i-1;
	 }
 	for (int i=2; i<=b; i++){
 		even = even+ i-1;
	 }
	 printf("%d",odd+ even);
 	return 0;
 }

Measured memory_bytes: 3224
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N, W;
    cin >> N >> W;

    long long dp[N + 1][W + 1];
    for (int i = 0; i < W + 1; ++i) {
        dp[0][i] = 0;
    }
    
    int w, v;
    for (int n = 1; n < N + 1; ++n) {
        cin >> w >> v;
        for (int i = W; i >= 0 ; --i) {
            if (i - w >= 0) {
                dp[n][i] = max(dp[n - 1][i - w] + v, dp[n - 1][i]);
            } else {
                dp[n][i] = dp[n - 1][i];
            }
        }
    }

    long long res = 0;
    for (int i = 0; i < W + 1; ++i) {
        res = max(res, dp[N][i]);
    }    
    
    cout << res << endl;
}


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

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

    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if((y-i*10000-j*5000)%1000==0&&(y-i*10000-j*5000)/1000+i+j==n&&y-i*10000-j*5000>=0){
                cout<<i<<endl;
                cout<<j<<endl;
                cout<<(y-i*10000-j*5000)/1000<<endl;
                return 0;
            }
            if((y-i*10000-j*1000)%5000==0&&(y-i*10000-j*1000)/5000+i+j==n&&y-i*10000-j*1000>=0){
                cout<<i<<endl;
                cout<<(y-i*10000-j*1000)/5000<<endl;
                cout<<j<<endl;
                return 0;
            }
            if((y-i*5000-j*1000)%10000==0&&(y-i*5000-j*1000)/10000+i+j==n&&y-i*5000-j*1000>=0){
                cout<<(y-i*5000-j*1000)/10000<<endl;
                cout<<i<<endl;
                cout<<j<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    int N;
    cin >> N;
    map<int,int> A;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        A[a]++;
    }
    for(auto a : A){
        if(a.se >= 2) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}


Measured memory_bytes: 12860
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	public void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n+1];
		StringTokenizer st = new StringTokenizer(reader.readLine());
		for (int i = 1; i <= n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		reader.close();
		
		for (int i = 1; i <= n; i++) {
			StringBuilder sb = new StringBuilder();
			sb.append("node " + i + ": ");
			sb.append("key = " + a[i] + ", ");
			int p = i/2;
			int l = i*2;
			int r = i*2+1;
			if (p >= 1) sb.append("parent key = " + (a[p]) + ", ");
			if (l <= n) sb.append("left key = " + (a[l]) + ", ");
			if (r <= n) sb.append("right key = " + (a[r]) + ", ");
			System.out.println(sb.toString());
		}
	}
}



Measured memory_bytes: 25300
# n = gets.to_i
# s = gets.chomp
n,m = gets.split.map(&:to_i)

# def y(f)
#     puts f ? "Yes" : "No"
# end

# y(true)

a = 0
b = 0
if n > 1
    a = n * (n-1) / 2
end
if m > 1
    b = m * (m-1) / 2
end

p a + b

Measured memory_bytes: 1788
#include <iostream>
using namespace std;
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <cstdlib>

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

int main() {
	
	string s; cin >> s;
	for(int i = 0; i < s.length(); i++) {
		if(s[i] == 'C') {
			for(int j = i+1; j < s.length(); j++) {
				if(s[j] == 'F') { cout << "Yes" <<endl; return 0; }
			}
		}
	}
	cout << "No" <<endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map { it.toLong() }

    println(f(a - 1) xor f(b))
}

fun f(n: Long): Long {
    val q = (n + 1) / 2
    val r = (n + 1) % 2
    return if (r == 0L) {
        if (q % 2 == 0L) 0 else 1
    } else {
        if (q % 2 == 0L) n else 1L xor n
    }
}

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

int main(){
	int n,y;
	cin>>n>>y;
	y/=1000;
	if(10*n<y or n>y){
		cout<<"-1 -1 -1"<<endl;
		return 0;
	}
	for(int i=y/10; i>=0; i--){
		for(int j=(y-i*10)/5; j>=0; j--){
			if(i+j+(y-i*10-j*5)==n and i*10+j*5+(y-i*10-j*5)==y){
				cout<<i<<" "<<j<<" "<<y-i*10-j*5<<endl;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

// BIT
class BIT {
private:
  vector<ll> vec;

public:
  BIT() { this->vec = vector<ll>(1, 0); }
  BIT(ll required_size) { this->vec = vector<ll>(required_size + 1, 0); }
  void add(ll arg_pos, ll num) {
    ll pos = arg_pos + 1;
    for (ll x = pos; x < this->vec.size(); x += x & -x)
      this->vec[x] += num;
  }
  ll sum(ll arg_pos) {
    ll pos = arg_pos + 1;
    ll ret = 0;
    for (ll x = pos; x > 0; x -= x & -x)
      ret += this->vec[x];
    return ret;
  }
};

void solve() {
  ll N;
  string S;
  ll Q;
  cin >> N >> S >> Q;
  unordered_map<char, BIT> bits;
  for (char i = 'a'; i <= 'z'; i++) {
    bits[i] = BIT(N);
  }
  rep (i, N) bits[S[i]].add(i, 1);
  rep (q, Q) {
    ll type;
    cin >> type;
    if (type == 1) {
      ll pos;
      char c;
      cin >> pos >> c;
      pos--;
      char old = S[pos];
      if (old != c) {
        S[pos] = c;
        bits[old].add(pos, -1);
        bits[c].add(pos, 1);
      }
    } else {
      ll l, r;
      cin >> l >> r;
      l--;
      r--;
      ll ans = 0;
      for (char c = 'a'; c <= 'z'; c++) {
        ll foo = bits[c].sum(r);
        ll bar = 0;
        if (l > 0) bar = bits[c].sum(l-1);
        if (bar < foo) ans++;
      }
      cout << ans << endl;
    }
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 102556
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String h1 = scanner.nextLine();
		int a = Integer.parseInt(h1);
		//System.out.println(a);

		String h2 = scanner.nextLine();
		String[] x = h2.split(" ");
		//Arrays.sort(x);


		for (int y = a - 1; y >= 0; y--) {
			if(y!=0)
			System.out.print(x[y] + " ");
			else
			System.out.println(x[y]);
		}
	}
}

Measured memory_bytes: 26172
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b) f(i,0,n){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

/*****************************************************************************/


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

	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << " " << max(a + b - n, 0);
	return 0;
}

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

int main() {
  int N, K, x = 1;
  cin >> N >> K;
 
  for (int i = 0; i < N; i++) {
      if(x * 2 > x + K){
        x += K;
      }
    else{
      x *= 2;
    }
  }
  cout << x << endl;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;


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

    int n;
    cin >> n;

    mii a;

    for(int i = 2; i <= n; ++i) {
        int num = i;
        for(int j = 2; j <= n; ++j) {
            while(true) {
                if(num % j != 0) break;
                a[j]++;
                num /= j;
            }
        }        
    }
    int ans = 1;
    mii d;
    for(auto i : a) {
        // cout << i.first  << " " << i.second << endl;
        if(i.second >= 74) d[74]++;
        if(i.second >= 24) d[24]++;
        if(i.second >= 14) d[14]++;
        if(i.second >= 4) d[4]++;
        if(i.second >= 2) d[2]++;
    }
    // printf("%d %d %d %d %d ", d[74], d[24], d[14], d[4],d[2]);
    cout << d[74] + d[24] * (d[2] - 1) + d[14] * (d[4] - 1) + d[4] * (d[4] - 1) * (d[2]-2) / 2 << endl;


    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    A = list(map(int,input().split()))

    ans = 0
    for mask in range(60): # 各桁ごとに、1を持つ数を探す
        one_sum = 0
        for a in A:
            one_sum += (a >> mask) & 1

        ans += one_sum * (N - one_sum) * 2**mask

    print(ans%(10**9+7))

if __name__ == "__main__":
  main()


Measured memory_bytes: 122844
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vp,vpp1;
vector<pair<ll,ll> >vdp,fin;
vector<ll>v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>power;

ll mulmod(ll a , ll b , ll mo)
{
    ll q = ((long double) a * (long double) b / (long double) mo);
    ll res = a * b - mo * q;
    return ((res % mo) + mo) % mo;
}
ll bigmod (ll a, ll b, ll c)
{
    ll res = 1;
    a=a%c;
    while (b > 0)
    {
        if (b % 2 == 1)
        {
            res=mulmod(res,a,c);
        }
        a=mulmod(a,a,c);
        b=b/2;
    }
    return res;
}
int main()
{
    fast;
    cin>>n>>k;
    ll ans[k+10];
    memset(ans,0,sizeof ans);
    for(ll i=k;i>=1;i--)
    {
        ll div=(k/i);
        ans[i]=bigmod(div,n,mod);
        for(ll j=i+i;j<=k;j+=i)
        {
            ans[i]=((ans[i]-ans[j])+mod)%mod;
        }
        sum=(sum+((ans[i]*i)%mod))%mod;
    }
    cout<<sum<<endl;
    return 0;
}


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

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

    vector<int> A(N);
    int cnt_max = 0;
    for (int i = 1; i <= N; i++) {
        int cnt = 0;
        int tmp = i;
        while (tmp < K) {
            tmp *= 2;
            cnt++;
        }
        if (i == 1) cnt_max = cnt;
        A[i - 1] = pow(2, cnt_max - cnt);
    }

    long double sum = 0;
    long double divide = N * pow(2, cnt_max);
    for (int i = 0; i < N; i++) sum += A[i];
    double ans = sum / divide;
    cout << fixed << setprecision(10) << ans << endl;
}

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

def main():
    W, H, N = map(int, input().split())
    dots = [list(map(int, input().split())) for _ in range(N)]
    max_x_left = 0
    min_x_right = W
    max_y_down = 0
    min_y_up = H
    for dot in dots:
        if dot[2] == 1 and dot[0] > max_x_left:
            max_x_left = dot[0]
        elif dot[2] == 2 and dot[0] < min_x_right:
            min_x_right = dot[0]
        elif dot[2] == 3 and dot[1] > max_y_down:
            max_y_down = dot[1]
        elif dot[2] == 4 and dot[1] < min_y_up:
            min_y_up = dot[1]
    if min_x_right <= max_x_left or min_y_up <= max_y_down:
        print(0)
    else:
        print((min_x_right - max_x_left) * (min_y_up - max_y_down))

if __name__ == '__main__':
    main()

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

int main() {
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    set<int> st;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'o') st.insert(i+1);
    }
    vector<int> saki, ato;
    auto it = st.begin();
    saki.push_back(*it);
    it++;
    int last = saki[0];
    int cnt = 1;
    while (cnt < K) {
        if ((*it) > last+C) {
            saki.push_back(*it);
            cnt++;
            last = (*it);
        }
        it++;
    }
    
    it = st.end();
    it--;
    ato.push_back(*it);
    it--;
    int nxt = ato[0];
    cnt = 1;
    while (cnt < K) {
        if ((*it) < nxt-C) {
            ato.push_back(*it);
            cnt++;
            nxt = (*it);
        }
        it--;
    }
    reverse(ato.begin(), ato.end());
    for (int i = 0; i < K; i++) {
        if (saki[i] == ato[i]) cout << saki[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 12796
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int gcd(int A,int B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
  int x;
  cin>>x;
  cout<<360/(gcd(360,x));
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<int>();
            for (int i = 0; i < 5; i++)
            {
                var point = ReadInt();
                if (point < 40)
                {
                    list.Add(40);
                }
                else
                {
                    list.Add(point);
                }
            }
            WriteLine(list.Average());
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 18296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DPH
{
    class Program
    {
        static char[,] map;
        static long[,] dp;
        static long mod = (long)(Math.Pow(10, 9) + 7);
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int H = int.Parse(input[0]);
            int W = int.Parse(input[1]);
            string[] S = new string[H];
            map = new char[H, W];
            dp = new long[H, W];
            for (int i = 0; i < H; i++)
            {
                S[i] = Console.ReadLine();
                for (int j = 0; j < W; j++)
                {
                    map[i, j] = S[i][j];
                    //Console.Write(map[i, j] + " ");
                }
                //Console.WriteLine();
            }
            if (map[0, 1] == '.')
            {
                dp[0, 1] = 1;
            }
            if (map[1, 0] == '.')
            {
                dp[1, 0] = 1;
            }
            long ans = dps(H, W) % mod;
            Console.WriteLine(ans);
        }
        static long dps(int x, int y)
        {
            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    if (map[i, j] == '.')
                    {
                        if (i > 0 && map[i - 1, j] == '.')
                        {
                            dp[i, j] += dp[i - 1, j]%mod;
                        }
                        if (j > 0 && map[i, j - 1] == '.')
                        {
                            dp[i, j] += dp[i, j - 1]%mod;
                        }
                    }

                    //Console.Write(dp[i, j] + " ");
                }
                //Console.WriteLine();
            }
            return dp[x - 1, y - 1];

        }
    }
}


Measured memory_bytes: 28880
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

bool v[100005];
stack<ll> v2;
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,K;
	cin >> N >> K;
	vector<pair<ll,ll>> s(N);
	rep(i,N)cin >> s[i].second >> s[i].first;
	sort(ALL(s),greater<>());
	ll sum = 0,type = 0;
	for(int i=0;i<K;i++){
		sum += s[i].first;
		if(!v[s[i].second]){
			type++;
			v[s[i].second]=1;
		}else{
			v2.push(s[i].first);
		}
	}
	ll ans = sum + type*type;
	for(int i=K;i<N;i++){
		if(v[s[i].second]==1)continue;
		else {
			if(v2.empty())break;
			sum += s[i].first;
			v[s[i].second]=1;
			sum -= v2.top();v2.pop();
			type++;
		}
		ans = max(ans,(sum + type*type));
	}
	cout << ans << endl;
}

Measured memory_bytes: 2176
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(int a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

ll INF = 10000000;
ll mod = 1000000007;//10^9+7



//番号ズレ注意！！
int main() {
    int S;
    cin>>S;
    int F=S/100,L=S%100;
    bool YYMM=true,MMYY=true;
    if(F>12||F==0){MMYY=false;}
    if(L>12||L==0){YYMM=false;}

    if(YYMM){
        if(!MMYY){cout<<"YYMM"<<endl;}else{cout<<"AMBIGUOUS"<<endl;}
    }else{
        if(MMYY){cout<<"MMYY"<<endl;}else{cout<<"NA"<<endl;}
    }
}

Measured memory_bytes: 256
//21171_somesh || asomesh999

#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;

int main()
{
	io
	#ifdef SOMU
		clock_t startTime = clock();
		freopen("input.txt","r",stdin);
	#endif

	string s;
	cin >> s;
	ll n = s.size() + 1;
	vl arr(n);
	fr(i, 0, n - 1) {
		if (s[i] == '<') {
			arr[i + 1] = max(arr[i + 1], arr[i] + 1);
		}
 	}
 	for (int i = n - 2; i >= 0; i--) {
 		if (s[i] == '>') {
 			arr[i] = max(arr[i], arr[i + 1] + 1);
 		}
 	}
	ll sum = 0;
	fr(i, 0, n) {
		sum += arr[i];
	}
	cout << sum;


	#ifdef SOMU
		cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;
	#endif
	return 0;
}

Measured memory_bytes: 4764
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	ll x;
	ll ans=0;
	
	cin>>x;
	ans = (x/11)*2;
	x%=11;
	//cerr<<x<<endl;
	if(x!=0)
	{
		if(x>6)
			ans+=2;
		else
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>

using namespace std;

int A, B, C, D;
long x[300000];
long y[300000][30];
long z[300000][30];

int main(int argc, char** argv) {
    cin >> A >> B >> C >> D;
    if ((abs(A - C) <= D) || (abs(A - B) <= D && abs(B - C) <= D))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
def get_greater_equals(number, target, exclude_digits):
    if number >= target:
        return number
    results = []
    for i in range(10):
        if not i in exclude_digits:
            if i == 0 and number == 0:
                continue
            results.append(
                get_greater_equals(number * 10 + i, target, exclude_digits))
    return min(results)


def main():
    n, k = [int(x) for x in input().rstrip().split(" ")]
    exclude_digits = [int(x) for x in input().rstrip().split(" ")]

    result = get_greater_equals(0, n, exclude_digits)
    print(result)

if __name__ == '__main__':
    main()

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

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> a(n+1);
	for (int i=1;i<=n;++i)
	{
		cin >> a[i];
	}

	for (int i=k+1;i<=n;++i)
	{
		if (a[i-k]<a[i])
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
}







Measured memory_bytes: 4044
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

string S;

int m[2020];

int modPow(int a, int n) {
  if(n==1)return a % 2019;
  if (n%2==1)return(a*modPow(a,n-1))%2019;
  int t=modPow(a,n/2);
  return (t*t)%2019;
}

int main(){
    cin>>S;
    reverse(S.begin(),S.end());
    int mod=S[0]-'0';
    m[0]++;
    m[mod]++;
    int Xi;
    int ans=0;
    for(int i=1;i<S.size();++i){
        int s=S[i]-'0';
        Xi=(mod+s*modPow(10,i))%2019;
        ans+=m[Xi];
        m[Xi]++;
        mod=Xi;
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main() {
  int n, p;
  scanf("%d %d", &n, &p);
  long long a = 0, b = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    if (x & 1) {
      auto ta = a + b;
      auto tb = b + a + 1;
      a = ta; b = tb;
    }
    else {
      auto ta = 2 * a + 1;
      auto tb = 2 * b;
      a = ta; b = tb;
    }
  }
  printf("%lld\n", p ? b : a + 1);
  return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
lx = list(map(int, input().split()))
if sum(lx)%n == 0:
  mx = int(sum(lx)/n)
  print(sum([(x - mx)**2 for x in lx]))
else:
  mx = float(sum(lx)/n)
  mxc = sum([(x - math.ceil(mx))**2 for x in lx])
  mxf = sum([(x - math.floor(mx))**2 for x in lx])
  if mxc < mxf:
    print(int(mxc))
  else:
    print(int(mxf))

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int64_t> t(n);
  std::cin >> t;
  int m;
  std::cin >> m;
  std::vector<std::pair<int, int>> d(m);
  std::cin >> d;

  const auto s = summation(t.cbegin(), t.cend());

  for (int i = 0; i < m; i++) {
    std::cout << s - t[d[i].first - 1] + d[i].second << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
N,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(1,N):
    tmp=a[i-1]+a[i]
    if tmp>x:
        ans+=tmp-x
        if a[i]>=tmp-x:
            a[i]-=tmp-x
        else:
            a[i]=0
print(ans)

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
ll a[maxn];
void run_case()
{
    int n;
    cin >> n;
    bool ok = 1;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] == 0)
            ok = 0;
    }
    if (!ok)
    {
        cout << 0 << "\n";
        return;
    }
    ll now = 1;
    ll num = 1e18;
    for (int i = 1; i <= n; i++)
    {
        //C;
        //DBG(now);
        if (now > num / a[i])
        {
            //ok = 0;
            cout << -1 << "\n";
            return;
        }
        now *= a[i];
    }
    cout << now << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 4436
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

count=0
if x==sum(a):
    print(n)
elif x>sum(a):
    print(n-1)
else:
    for i in range(n):
        if x>=a[i]:
            count+=1
            x-=a[i]
        else:
            break
    print(count)

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

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        this.PointCount = inpt[0];
        int pathCount = inpt[1];

        for (int i = 0; i < pathCount; i++)
        {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

            if(!this.Path.ContainsKey(inpt[0])) {
                this.Path.Add(inpt[0], new Dictionary<int, bool>());
            }
            this.Path[inpt[0]].Add(inpt[1], true);
            if (!this.Path.ContainsKey(inpt[1]))
            {
                this.Path.Add(inpt[1], new Dictionary<int, bool>());
            }
            this.Path[inpt[1]].Add(inpt[0], true);
        }
        int ans = this.GetAns(1, 1);
        Console.WriteLine(ans);
    }

    private int GetAns(int pos, int flags)
    {
        if ((1 << PointCount) - 1 == flags)
        {
            return 1;
        }
        int ans = 0;
        if (this.Path.ContainsKey(pos))
        {
            foreach (int next in this.Path[pos].Keys)
            {
                int key = 1 << (next-1);
                if ((flags & key) > 0)
                {
                    continue;
                }
                ans += this.GetAns(next, flags + key);
            }
        }
        return ans;
    }

    private int PointCount = 0;

    private Dictionary<int, Dictionary<int, bool>> Path = new Dictionary<int, Dictionary<int, bool>>();


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"



7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7



";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 13408
#include <cstdio>
#include <cstring>

using namespace std;

const int mod = 1000000007;
char s[100001];
int r[100001][3][2];
int sum[100001];
int dp[100001];

int main() {
    int n, i, j, k;
    long long ans = 0;
    
    scanf("%s", s);
    n = strlen(s);
    
    for (i = 0; i + 1 < n; i++) {
        if (s[i] == s[i + 1]) break;
    }
    
    if (i + 1 == n) {
        puts("1");
        return 0;
    }
    
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 2; j++) {
            r[n][i][j] = -1;
        }
    }
    
    for (i = n - 1; i >= 0; i--) {
        int c;
        
        if (s[i] == 'a') {
            c = 1;
        } else {
            c = 2;
        }
        
        sum[i] = (sum[i + 1] + c) % 3;
        
        for (j = 0; j < 3; j++) {
            for (k = 0; k < 2; k++) {
                r[i][(j + c) % 3][k] = r[i + 1][j][k];
            }
        }
        r[i][c][0] = i;
        
        if (s[i] == s[i + 1]) {
            for (j = 0; j < 3; j++) r[i][(j + c) % 3][1] = r[i + 1][j][0];
        }
    }
    
    dp[0] = 1;
    
    for (i = 0; i < n; i++) {
        int p;
        
        dp[i + 1] += dp[i];
        if (dp[i + 1] >= mod) dp[i + 1] -= mod;
        
        if (s[i] == 'a') {
            p = r[i][2][1];
        } else {
            p = r[i][1][1];
        }
        
        if (p >= 0) {
            dp[p + 1] += dp[i];
            if (dp[p + 1] >= mod) dp[p + 1] -= mod;
        }
    }
    
    for (i = 1; i <= n; i++) {
        if (sum[i] == 0) ans += dp[i];
    }
    
    printf("%lld\n", ans % mod);
    
    return 0;
}


Measured memory_bytes: 3328
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
L = LI()
L.sort()

ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1,N-1):
        b = L[j]
        for k in range(j+1,N):
            c = L[k]
            if a != b and b != c and c != a and a+b > c:
                ans += 1

print(ans)


Measured memory_bytes: 73592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef long double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define previous fake_previous
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const int MAXN = 100007;
const int MOD = 1000000007;
const ll INF = 1000000000LL * 1000000000;
const LL LINF = INF * (LL)INF;
const LD PI = acos(-1.0);
int n;
ll t;
ll ans = INF;
int a[2005];
int b[2005];
int catched[2005];
int main()
{
	cin >> n >> t;
	ans = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = a[i];
		ans += b[i];
	}
	for(int zsuvCnt = 1; zsuvCnt < n; zsuvCnt++)
	{
		ll curAns = zsuvCnt * t;
		for(int i = 0; i < n; i++)
		{
			b[i] = min(b[i] , a[(i + zsuvCnt) % n]);
			curAns += b[i];
		}
		ans = min(ans , curAns);
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
ll n, x, t;

inline void solve()
{
    cin >> n >> x >> t;
    cout << t * (n / x) + t * ((n % x > 0)) << endl;
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
        solve();
    TIME__END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
    
#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;

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

int32_t main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    REP(i, n) cin >> c[i];
    SORT(a); SORT(b); SORT(c);

    vector<int> ab(n, 0), bc(n, 0);
    int cnt_1=0;
    REP(i, n){
        if(i>0){
            ab[i]+=ab[i-1];
        }

        for(; cnt_1<n; cnt_1++){
            if(a[cnt_1]<b[i]){
                ab[i]++;
            }
            else{
                break;
            }
        }
    }

    int cnt_2=n-1;
    for(int i=n-1; i>=0; i--){
        if(i<n-1){
            bc[i]+=bc[i+1];
        }
        for(; cnt_2>=0; cnt_2--){
            if(b[i]<c[cnt_2]){
                bc[i]++;
            }
            else{
                break;
            }
        }
    }

    int ans=0;
    REP(i, n){
        ans+=(ab[i]*bc[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 4224
#include <iostream>

using namespace std;

int main()
{
	float x[4], y[4], z1, z2, z3;
	while (scanf("%f %f %f %f %f %f %f %f", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3])!= EOF) {
		
		z1=(x[2]-x[1])*(y[3]-y[1])-(y[2]-y[1])*(x[3]-x[1]);
		z2=(x[0]-x[2])*(y[3]-y[2])-(y[0]-y[2])*(x[3]-x[2]);
		z3=(x[1]-x[0])*(y[3]-y[0])-(y[1]-y[0])*(x[3]-x[0]);
		
		if ((z1 < 0 && z2 < 0 && z3 < 0) || (z1 > 0 && z2 > 0 && z3 > 0)) printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 0