akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MAX 3010
using namespace std;

int P;
int arr[MAX];
int brr[MAX];
int poly[MAX];

int add(int a, int b)
{
	return (a + b) % P;
}

int prod(int a, int b)
{
	return 1LL * a * b % P;
}

int power(int a, int n)
{
	if (!n) return 1;
	int mid = power(a, n / 2);
	mid = prod(mid, mid);
	if (n % 2) mid = prod(mid, a);
	return mid;
}

int inv(int a)
{
	return power(a, P - 2);
}

int main(void)
{
	cin >> P;
	for (int i = 0; i < P; i++)
	{
		int val;
		cin >> val;
		if (!val) continue;
		brr[0] = 0;
		brr[1] = P - 1;
		for (int j = 2; j < P; j++) brr[j] = 0;
		brr[P] = 1;
		for (int j = P; j > 0; j--)
		{
			arr[j - 1] = brr[j];
			brr[j - 1] = add(brr[j - 1], prod(brr[j], i));
			brr[j] = 0;
		}
		int polyVal = 0;
		int pwr = 1;
		for (int j = 0; j < P; j++)
		{
			polyVal = add(polyVal, prod(arr[j], pwr));
			pwr = prod(pwr, i);
		}
		polyVal = inv(polyVal);
		for (int j = 0; j < P; j++) arr[j] = prod(arr[j], polyVal);
		for (int j = 0; j < P; j++) poly[j] = add(poly[j], arr[j]);
	}
	for (int i = 0; i < P; i++) cout << poly[i] << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
 
char s[201],t[101],p[101];
 
scanf("%s",&s);
 
scanf("%s",&p);
 
strcpy(t,s);
 
strcat(s,t);
 
 
if(strstr(s,p)==NULL){printf("No\n");}
else printf("Yes\n");
 
 
 
return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <unordered_map>
using namespace std;

int main() {
	int N;
	unordered_map<string, int> mp;  
	long long answer=0;
	cin>>N;
 
  	vector<string> A;
 
  	for (int i = 0; i < N; i++) {
      		string s;
      		cin >> s;
      		sort(s.begin(), s.end());
      		A.push_back(s);
    }

    for (int i = 0; i < N; i++) {
      	if(mp[A.at(i)]>=1) {
      		answer+=mp[A.at(i)];
      		mp[A.at(i)]++;
      	}
      	else mp[A.at(i)] = 1;
    }
    cout<<answer<<endl;
}

Measured memory_bytes: 11380
a,b,c = map(int, input().split())
k = int(input())

# a < b
# b < c


ans = 0
while a >= b:
    ans += 1
    b *= 2

while b >= c:
    ans += 1
    c *= 2

if ans <= k:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9164
n, x = map(int, input().split())
b = 1
p = 1
for i in range(n):
    b = 2 * b + 3
    p = 2 * p + 1
x -= 1
b -= 1
ans = 0
while True:
    if x == 0:
        if b == 0:
            ans += 1
        break
    elif x == b:
        ans += p
        break
    elif x == b // 2:
        ans += p // 2 + 1
        break
    elif 0 < x < b // 2:
        x -= 1
    else:
        x -= b // 2 + 1
        ans += p // 2 + 1
    b = (b - 3) // 2
    p = (p - 1) // 2
print(ans)


Measured memory_bytes: 61812
#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
const ll mod = 1000000007;


int main(){
  ll n;
  scanf("%lld", &n);
  ll a,b;
  for(ll i=1;i<=n;i++){
    if(n%i==0){a=i;b=n/i;break;}
  }
  //cout<<a<<" "<<b<<endl;
  ll min=n+2;

  for(ll i=a; i<=sqrt(b); i++){
    if(n%i==0){
      if(min>i+n/i)min=i+n/i;
    }
    //cout<<min<<endl;
  }
  cout<<min-2<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
    /**
     *
     */

    private static final int _100000 = 100000;

    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int[]  x;
        int i;
        x = new int[100000];
        int count = 0;
        try {
            for(i=1;i<100000;i++) {
            String line = reader.readLine();
            x[i] = Integer.parseInt(line);
            if (x[i] == 0) break;
            count++;
            }

            for(i=1;i<=count;i++){
                System.out.println("Case " + i + ": " + x[i]);
            }

        } catch (IOException e) {
            System.out.println(e);
        } catch (NumberFormatException e){
            System.out.println("falese");
        }
    }
}


Measured memory_bytes: 31936
a, b, c = map(int,input().split())

if(a <= b <= c):
    print(str(a) + " " + str(b) + " " + str(c))
elif(a <= c <= b):
    print(str(a) + " " + str(c) + " " + str(b))
elif(b <= a <= c):
    print(str(b) + " " + str(a) + " " + str(c))     
elif(b <= c <= a):
    print(str(b) + " " + str(c) + " " + str(a))
elif(c <= a <= b):
    print(str(c) + " " + str(a) + " " + str(b))
else:
    print(str(c) + " " + str(b) + " " + str(a))  


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


int main() {
    int n;
    cin >> n;
    int a,xin,yin;
    vector<vector<pair<int,int>>> t(n);
    for (int i=0;i<n;i++) {
        cin >> a;
        for (int j=0;j<a;j++) {
            cin >> xin >> yin;
            t[i].push_back(make_pair(xin-1,yin));
        }
    }
    int ans=0;
    for (int bit=0;bit<(1<<n);bit++) {
        bool flag=true;
        vector<int> f(n);
        int tans=0;
        for (int i=0;i<n;i++) {
            if (bit & (1<<i)) {
                f[i]=1;
                tans++;
            } else f[i]=0;
        }
        for (int i=0;i<n;i++) {
            if (f[i]==1) {
                for (int j=0;j<t[i].size();j++) {
                    int x=t[i][j].first;
                    int y=t[i][j].second;
                    if (f[x]!=y) flag=false;
                }
            }
        }
        if (flag) ans=max(ans,tans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int app() {
  int n,k;
  cin>>n>>k;

  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
  }

  sort(p.begin(),p.end());

  int ans=0;
  rep(i,k) ans+=p[i];

  return ans;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int ans=1;
  for (int a = 1; a * a <= m; a++) {
    if (m % a != 0) {
      continue;
    }
    int b = m / a;
    if ((long)a * n <= m) {
      ans = max(a,ans);
    }
    if ((long)b * n <= m) {
      ans = max(b,ans);
    }
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
#define repM1(i, n) for(ll i = (ll)(n - 1); i > 0; i--)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	cout << fixed << setprecision(18);

	ll n;

	cin >> n;

	n %= 10;

	if (n == 3)
		cout << "bon" << endl;
	else if (n == 0 || n == 1 || n == 6 || n == 8)
		cout << "pon" << endl;
	else
		cout << "hon" << endl;


	return 0;
}

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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class BTrickOrTreat {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, k; cin >> n >> k;
      vector<int> cnt(n);
      rep(i, k) {
        int d; cin >> d;
        rep(j, d) {
          int a; cin >> a; a--;
          cnt[a]++;
        }


      }
      int ans = 0;
      rep(i, n) {
        if (cnt[i]==0) ans++;
      }
      cout << ans << endl;
    }
};

signed main() {
  BTrickOrTreat solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3640
from collections import Counter

N = int(raw_input())
s = []
for i in range(0,N):
  K = (''.join(sorted(raw_input())))
  s.append(K)
ans = 0

for i in Counter(s).values():
  if i > 1:
    for j in range(1,i):
      ans = ans + j
print ans


Measured memory_bytes: 20972
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	long long int ans1 = 0, ans2 = 0;
	long long int sum1 = 0, sum2 = 0;
	for(auto i = 0; i < n; ++i){
		long long int  a;
		cin >> a;
		if(i % 2 == 0){
			if(sum1 + a <= 0){
				ans1 += abs(sum1 + a) + 1;
				sum1 = 1;
			}else{
				sum1 += a;
			}
			if(sum2 + a >= 0){
				ans2 += abs(sum2 + a) + 1;
				sum2 = -1;
			}else{
				sum2 += a;
			}
		}else{
			if(sum1 + a >= 0){
				ans1 += abs(sum1 + a) + 1;
				sum1 = -1;
			} else{
				sum1 += a;
			}
			if(sum2 + a <= 0){
				ans2 += abs(sum2 + a) + 1;
				sum2 = 1;
			} else{
				sum2 += a;
			}
		}
	}
	cout << min(ans1, ans2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

		int n;

	cin>>n;

	string str = "ABC";

	string qtr;

	cin>>qtr;

	int cnt =0;

	for(int i=0;i<qtr.size();i++){

if(qtr[i]=='A'&&qtr[i+1]=='B'&&qtr[i+2]=='C'){

	  i+=2;

	  cnt++;

	}

	}

	cout<<cnt;

}

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

using namespace std;

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

#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-6;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int A, B, C, D; cin >> A >> B >> C >> D;

    for (;;) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            break;
        }

        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            break;
        }
    }

    return 0;
}


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

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

	int H, W;
	scanf("%d %d", &H, &W);

	vector<vector<int>> C(10, vector<int>(10));
	vector<int> D(10);
	vector<int> old_D(10, 10000);
	old_D[1] = 0;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			scanf("%d", &C[i][j]);
		}
	}

	for (int k = 0; k < 10 - 1; k++) {
		for (int i = 0; i < 10; i++) {
			D[i] = old_D[i];
			for (int j = 0; j < 10; j++) {
				D[i] = min(old_D[j] + C[i][j], D[i]);  // j->i
			}
		}
		for (int i = 0; i < 10; i++) {
			old_D[i] = D[i];
			// cout << i << " " << D[i] << "\n";
		}
		// cout << "\n";
	}

	int tmp;
	int result = 0;
	for (int i = 0; i < H * W; i++) {
		scanf("%d", &tmp);
		if (tmp != -1) {
			result += D[tmp];
		}
	}
	cout << result;
	return 0;
}

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

static class Program
{
    static void Main(string[] args)
    {
        var V = Console.ReadLine().Split();
        long A = long.Parse(V[0]);
        int B = int.Parse(string.Join("", V[1].Split('.')));
        Console.WriteLine(A * B / 100);
    }
}


Measured memory_bytes: 27528
#include<stdio.h>

int main(void) {
        char line[10];
        int H,W;
        int i,j;
        int sharpFirst = 0;

        while ( ( fgets(line, sizeof(line), stdin) ) ) {
                sscanf(line, "%d %d", &H, &W);
                if( ( H == 0 ) && ( W == 0) ) break;
                for ( i = 1; i <= H; i++ ) {
                        for ( j = 1; j <= W; j++ ) {
                                if ( (i % 2) == (j % 2) )  printf("#");
                                else printf(".");
                        }
                        printf("\n");
                }
                printf("\n");
        }
        return 0;
}

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

int main(void){
  int a,b,c,x;
  int sum,cnt = 0;
  cin >> a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        sum = i *500 +j*100 +k*50;
        if(sum == x)cnt++;
      }
    }
  }
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, m;
	cin>>n>>m;
	if(m==n) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
	vector<ll> a(X), b(Y), c(Z);
	rep(i, X) cin >> a[i];
	rep(i, Y) cin >> b[i];
	rep(i, Z) cin >> c[i];

	vector<ll> ab;
	rep(i, X){
		rep(j, Y){
			ab.push_back(a[i]+b[j]);
		}
	}

	sort(all(ab));
	reverse(all(ab));
	vector<ll> tmpv;
	rep(i, min(3000, (int)ab.size())){
		tmpv.push_back(ab[i]);
	}

	vector<ll> res;
	rep(i, tmpv.size()){
		rep(j, Z){
			res.push_back(tmpv[i]+c[j]);
		}
	}

	sort(all(res));
	reverse(all(res));

	rep(i, K){
		cout << res[i] << endl;
	}
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 46856
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 998244353;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=3*1e5+3;

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

      int m,d;
      cin>>m>>d;
      int ans=0;
      for(int i=1;i<=m;i++)
      {
            for(int j=1;j<=d;j++)
            {
                  if(j/10>=2&&(j%10>=2)&&(j/10)*(j%10)==i)
                        ans++;
            }
      }
      cout<<ans;
}
// I never lose. I either win or I learn


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

const ll MAXN = 200000;

ll A, B, ans=0, C[41], D[41];

signed main(){
    cin >> A >> B;
    A--;
    for(int i=0;i<41;i++) {
        ll e = pow(2, i+1);
        C[i] = (e/2)*(A/e);
        if(A%e-e/2+1>0) C[i] += A%e-e/2+1;
        D[i] = (e/2)*(B/e);
        if(B%e-e/2+1>0) D[i] += B%e-e/2+1;
    }
    /*
    for(int i=0;i<41;i++) {
        cout << " " << C[i];
    }
    cout << endl;
    for(int i=0;i<41;i++) {
        cout << " " << D[i];
    }
    */
    for(int i=0;i<41;i++) {
        if((D[i]-C[i])%2==1) {
            ans += pow(2, i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n=I()
    lis=LI()
    lis=list(accumulate(lis))
    lis=[0]+lis
    c=Counter(lis)
    ans=0
    #print(lis)
    for x in c.keys():
        y=c[x]
        #print(y)
        ans+=y*(y-1)//2
    print(ans)
    
        
                





if __name__=="__main__":
    main()


Measured memory_bytes: 137388
#include<bits/stdc++.h>
#define fi        first
#define se        second
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
typedef pair<ll,int>  PLI;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
int main()
{
	IOS();
	
	
	int n;
	set<int> s;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		s.insert(x); 
	}
	cout<<(n==s.size()?"YES":"NO")<<endl;
	
	
	
	
	
	
	
	

	
	
	return 0;
}



Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define H (int)998244353
int32_t main() {

    int n, s, i, j;
    cin >> n >> s;
    int a[n];
    for (i = 0; i < n; i++) 
         cin >> a[i];
    int dp[s + 1][n];
    for (i = 0; i < s + 1; i++) {
        for (j = 0; j < n; j++) 
             dp[i][j] = 0;
    }

    dp[0][0] = 2;
    if (a[0] <= s)
        dp[a[0]][0] = 1;

    for (j = 1; j < n; j++) {
         for (i = 0; i <= s; i++) {
              if (dp[i][j - 1] != 0) { 
                  dp[i][j] = (dp[i][j] + (dp[i][j - 1] * 2) % H) %H;
                  if (i + a[j] <= s) {
                      dp[i + a[j]][j] = (dp[i + a[j]][j] + dp[i][j - 1]) % H;
                  } 
              }
         }
    } 
    cout << dp[s][n-1];
    return 0;
}

Measured memory_bytes: 73896
n = int(input())
sp=[]
for i in range(n):
    s1,p1 = map(str,input().split())
    sp.append([i+1,s1,int(p1)])
sp = list(reversed(sorted(sp,key=lambda x:x[2])))
sp = sorted(sp,key=lambda x:x[1])
for i in range(n):
    print(sp[i][0])


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

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};


template<typename T>
struct Combination {
private:
  int sz;
  vector<T> F, F_;
public:
  Combination(int sz) : sz(sz), F(sz+1), F_(sz+1) {
    F[0] = 1;
    for(int i = 0; i < sz; ++i) F[i+1] = F[i]*(i+1);
    F_.back() = (T)1/F.back();
    for(int i = sz-1; i >= 0; --i) F_[i] = F_[i+1]*(i+1);
  }
  T C(int n, int k){
    assert(n <= sz);
    if(n < 0 or k > n) return (T)0;
    return F[n]*F_[k]*F_[n-k];
  }
};

int main(){
  using mint = modint<(int)1e9+7>;
  long long N, M, K;
  cin >> N >> M >> K;
  vector<vector<mint>> D(N,vector<mint>(M,0));
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < M; ++j){
      D[i][j] += i+j;
    }
  }
  for(int i = 0; i < N; ++i){
    for(int j = 1; j < M; ++j){
      D[i][j] += D[i][j-1];
    }
  }
  for(int i = 1; i < N; ++i){
    for(int j = 0; j < M; ++j){
      D[i][j] += D[i-1][j];
    }
  }
  Combination<mint> comb(N*M+1);
  mint ans = 0;
  mint t = comb.C(N*M-2,K-2);
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < M; ++j){
      ans += t*D[i][j];
      ans += t*D[N-1-i][j];
      ans += t*D[i][M-1-j];
      ans += t*D[N-1-i][M-1-j];
      ans -= t*D[0][j];
      ans -= t*D[0][M-1-j];
      ans -= t*D[i][0];
      ans -= t*D[N-1-i][0];
    }
  }
  ans /= 2;
  cout << ans << endl;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;


int main() {
  ll n; cin >> n; vi vec(n);
  rep(i,n) {
    ll x; cin >> x; vec.at(i) = x;
  }
  
  ll mini = 1000000000; 
  
  rep(i,99){
    ll sum = 0;
    rep(j,n){
      sum += (vec.at(j)-i+1)*(vec.at(j)-i+1);
    }
    
    mini = min(mini,sum);
  }
  
  cout << mini << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]

def a(A,B,x): return (A*x//B)-A*(x//B)

def main():
    A,B,N = MI()
    """
    max = 0
    m = 0
    for x in range(0, N+1):
        ai = a(A,B,x)
        if max < ai :
            max = ai
        elif ai<0 and m == 0:
            max = ai
            m +=1

        print(x,a(A,B,x))
    """
    if N >= B:
        x = (N//B)*B-1
    elif N == B:
        x = N-1
    elif N < B:
        x = N
    print(a(A,B,x))

    



    


if __name__ == "__main__":
	main()

Measured memory_bytes: 62032
#include <bits/stdc++.h>
using namespace std;
 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define left  (2*idx)+1
#define right (2*idx)+2
#define pb push_back
#define ll long long
#define all(x) x.begin(),x.end()
 

const ll MOD = (ll)(1e9 + 7); 
const ll N = 0;

int main()
{
	FIO;
	ll x;
	cin >> x;
	ll mn = (ll)(1e13);

	
	for(ll i=1; i*i<=x; i++) {
		if(x%i!=0) {
			continue;
		}
		ll j = x/i;
		mn = min(mn, j+i-2);
	} 
	cout << mn << "\n";
	return 0;	
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
  string s,t;
  cin >> s >> t;

  for(int i = 0; i < s.size(); i++) {
    for(int j = s.size()-1; j >= i+1; j--)
      if(s[j] < s[j-1]) swap(s[j],s[j-1]);
  }
  for(int i = 0; i < t.size(); i++) {
    for(int j = t.size()-1; j >= i+1; j--)
      if(t[j] > t[j-1]) swap(t[j],t[j-1]);
  }
  if(s < t)
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

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

        int input[] = new int [N];

        for (int i = 0 ; i< N ; i++) {
        	input[i] = sc.nextInt();
        }
        sc.close();


        int count = 0;
        Arrays.sort(input);

        for (int i = 0 ; i< N - 2  ; i++) {
        	for(int j = i + 1; j < N - 1 ; j++) {
                for (int k = j + 1 ; k < N ; k++) {
                	 if ( input[i] + input[j] <= input[k]) {
                		 break;
                	 }
                	 count++;
                }
        	}
        }
    	System.out.println(count);
    }
}

Measured memory_bytes: 28008
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,m,A[200010];
    cin>>n >> m;
  
    rep(i,n)
      cin>>A[i];
  
    vector<int> c;
  vector<int> idx(n+1,-1);
  
  int k = 1, l = 0;
  {
    int a = 1;
    while(idx[a] == -1){
      idx[a] = c.size();
      c.push_back(a);
      a = A[a-1];
    }
    k = c.size() - idx[a];
    l = idx[a];
  }
  
  if(m < l) cout << c[m] << endl;
  else{
    m -= l;
    m %= k;
    cout << c[l+m] << endl;
  }
  
}


Measured memory_bytes: 6660
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<stack>
#include<queue>


using namespace std;

int main()
{
//    freopen("input.in", "r", stdin);
    
    int n; cin >> n;
    int hit = 0;
    while(n--)
    {
        int a, b;
        cin >> a >> b;
        hit += b-a+1;
    }
    cout << hit << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<time.h>
#include<assert.h>
#include<iostream>
using namespace std;
typedef long long LL;
typedef pair<int,int>pi;
int cnt[2];
int main(){
	int n,a,b;scanf("%d%d%d",&n,&a,&b);
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='c'){puts("No");continue;}
		bool ps=0;
		if(s[i]=='a'){
			if(cnt[0]<a+b)ps=1;
			else ps=0;	
		}
		else{
			if(cnt[0]<a+b&&(cnt[1]<b))ps=1;
			else ps=0;
		}
		if(ps){
			puts("Yes");
			cnt[0]++;
			if(s[i]=='b')cnt[1]++;
		}
		else puts("No");
	}
	return 0;
}


Measured memory_bytes: 896
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
t=t.replace('r','P')
t=t.replace('s','R')
t=t.replace('p','S')
t=t.lower()
ans=r*t.count('r')+s*t.count('s')+p*t.count('p')

l=int(n/k)
for i in range(k):
  j=i
  while j+k<=n-1:
    if t[j]==t[j+k]:
      ans-=r*(t[j+k]=='r')+s*(t[j+k]=='s')+p*(t[j+k]=='p')
      t=t[:j+k]+'x'+t[j+k+1:]
    j+=k
      



print(ans)

Measured memory_bytes: 3476
import java.util.*;
public class Main {
	public static void main(String[] args) {
      	Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
        int K = sc.nextInt();
      	int[] A = new int[N];
      	for (int i = 0; i < N; i++) A[i] = sc.nextInt();
      	int[] dp = new int[N];
      	Arrays.fill(dp,Integer.MAX_VALUE);
      	dp[0] = 0;
      	for (int i = 1; i < N; i++) {
			      for (int j = 1; j <= Math.min(K,i); j++) {
              	dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(A[i] - A[i - j]));
            }
        }
      	System.out.println(dp[N - 1]);
    }
}

Measured memory_bytes: 51032
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n,m = map(int, input().split())
s = input()
t = input()

gcd_ = gcd(n,m)
lcm = n*m//gcd_

a = lcm//n
b = lcm//m

flag=0
le = min(n,m)//(min(n,m)//gcd_)

for i in range(le):
    if s[i*b]!=t[i*a]:
        flag=1

if flag==1:
    print(-1)
else:
    print(lcm)

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 n, r;
	while(cin >> n >> r && n && r){
		vector<int32> x(n, 0);
		int32 cup = r, cnt = 0;
		int32 now = 0;
		int32 res = 0;
		while(1){
			res++;
			if(cup){
				if(x[now] == 0) cnt++;
				x[now]++;
				cup--;
				if(cup == 0 && cnt == 1) break;
			}else{
				if(x[now]) cnt--;
				cup += x[now];
				x[now] = 0;
			}
			now = (now+1)%n;
		}
		cout << now << endl;
	}
}


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

long long int dfs(int k, int now, int from, vector<vector<int>>& ls)
{
  int i;
  int can_use_color;
  if(from == -1)can_use_color = k-1;
  else can_use_color = k-2;
  if(k < ls.at(now).size())return 0;
  else
  {
    long long case_num = 1;
    for(i = 0; i < ls.at(now).size(); i++)
    {
      if(ls.at(now).at(i) != from)
      {
        case_num *= can_use_color;
        can_use_color--;
        case_num%=1000000007;
      }
    }
    for(i = 0; i < ls.at(now).size(); i++)
    {
      if(ls.at(now).at(i) != from)
      {
        case_num *= dfs(k, ls.at(now).at(i), now, ls);
        case_num %= 1000000007;
      }
    }
    return case_num;
  }
}

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n-1);
  vector<int> b(n-1);
  int i,j;
  for(i = 0; i < n-1; i++)
  {
    cin >> a.at(i) >> b.at(i);
  }
  vector<vector<int>> ls(n, vector<int>(0));
  for(i = 0; i < n-1; i++)
  {
    ls.at(a.at(i)-1).push_back(b.at(i)-1);
    ls.at(b.at(i)-1).push_back(a.at(i)-1);
  }
  long long ans = dfs(k,0,-1,ls);
  cout << ans*k%1000000007 << endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for(int i = 0; i < h; i++) cin >> a.at(i);
  
  bool ok = true;
  vector<int> dx = {0, 1, 0, -1};
  vector<int> dy = {1, 0, -1, 0};
  vector<vector<int>> check(h, vector<int>(w));
  queue<pair<int, int>> dfs;
  dfs.push({0,0});
  while(dfs.size() > 0){
    queue<pair<int, int>> now;
    while(dfs.size() > 0){
      now.push(dfs.front());
      dfs.pop();
    }
    
    while(now.size() > 0){
      auto nw = now.front();
      now.pop();
      check.at(nw.second).at(nw.first) = 1;
      int cnt = 0;
      for(int i = 0; i < 4; i++){
        int nx = nw.first + dx.at(i), ny = nw.second + dy.at(i);
        if(nx >= w || nx < 0 || ny >= h || ny < 0) continue;
        if(a.at(ny).at(nx) == '.') continue;
        if(check.at(ny).at(nx) == 1) continue;
        if(i >= 2) ok = false;
        cnt++;
        dfs.push({nx, ny});
      }
      if(cnt > 1){
        ok = false;
        break;
      }
    }
  }
  if(check.at(h-1).at(w-1) != 1) ok = false;
  
  if(ok) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int M = 3000;

ll dp[2][52][6002];

int main()
{
    int n, m;
    cin >> n >> m;
    dp[0][0][M] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < i; j++){
            for(int k = 0; k <= M * 2; k++) dp[i % 2][j][k] = 0;
        }
        for(int j = 2; j <= i; j++){
            for(int k = i * 2; k <= M * 2; k++){
                dp[i % 2][j][k] = (dp[i % 2][j][k] + dp[(i + 1) % 2][j - 2][k - i * 2] * (i - j + 1) * (i - j + 1)) % MOD;
            }
        }
        for(int j = 1; j < i; j++){
            for(int k = 0; k <= M * 2; k++){
                dp[i % 2][j][k] = (dp[i % 2][j][k] + dp[(i + 1) % 2][j - 1][k] * 2 * (i - j)) % MOD;
            }
        }
        for(int j = 0; j < i; j++){
            for(int k = 0; k <= M * 2 - i * 2; k++){
                dp[i % 2][j][k] = (dp[i % 2][j][k] + dp[(i + 1) % 2][j][k + i * 2]) % MOD;
            }
        }
        for(int j = 1; j <= i; j++){
            for(int k = 0; k <= M * 2; k++){
                dp[i % 2][j][k] = (dp[i % 2][j][k] + dp[(i + 1) % 2][j - 1][k]) % MOD;
            }
        }
    }
    cout << dp[n % 2][n][M + m] << endl;
}


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

using ll = long long;

signed main(){
	ll n,x,t;
	cin >> n >> x >> t;

	ll ans = (n % x == 0) ? n/x : (n/x)+1 ;
	cout << ans*t << "\n";

	return 0;
}

Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
bool a[30],b[30];
int main() {
	int N,ans=0;
	std::string S;
	std::cin>>N>>S;
	for(int i=1;i<N;i++){
		std::fill(a,a+26,false);
		std::fill(b,b+26,false);
		std::string t=S.substr(0,i),r=S.substr(i,N-i);
		for(char c:t)a[c-'a']=true;
		for(char c:r)b[c-'a']=true;
		int cnt=0;
		for(int j=0;j<26;j++){
			if(a[j]&&b[j])cnt++;
		}
		ans=std::max(ans,cnt);
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 3624
#include <limits>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

template<class F>
void times_do(size_t n, F func)
{
    for(size_t i = 0; i < n; ++i) func();
}

struct v2 {
    int x = 0, y = 0;
};

struct visit {
    int time = 0;
    v2 pos;
};

int distance(const v2& a, const v2& b)
{
    return abs(a.x - b.x) + abs(a.y - b.y);
}

bool visitable(const visit& current, const visit& next)
{
    const int t = next.time - current.time;
    const int d = distance(next.pos, current.pos);
    if(t < d) return false;
    if((t - d)%2==1) return false;
    return true;
}

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

    vector<visit> visits;
    visits.reserve(n);

    times_do(n, [&](){
        visit v;
        cin >> v.time >> v.pos.x >> v.pos.y;
        visits.push_back(v);
    });

    visit current;
    for(const auto& next : visits)
    {
        if(!visitable(current, next))
        {
            cout << "No\n";
            return 0;
        }
        current = next;
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 1408
#ifndef TKLIB_SEGTREE_HPP
#define TKLIB_SEGTREE_HPP

#include <vector>
#include <functional>

namespace tklib {

template <typename T, typename Op = std::plus<T>>
class Segtree {
private:
    std::size_t N;
    std::vector<T> data;
    T idelem;
    const Op &op;

public:
    Segtree(std::size_t n, T idelem, const Op &op = Op())
    : N(1), idelem(idelem), op(op) {
        while(N < n) N <<= 1;
        data.assign(2 * N, idelem);
    }

    template <typename InputIt>
    Segtree(InputIt first, InputIt last, T idelem, const Op &op = Op())
    : N(1), idelem(idelem), op(op) {
        std::vector<T> buffer(first, last);
        while(N < buffer.size()) N <<= 1;
        data.assign(2 * N, idelem);
        std::swap_ranges(buffer.begin(), buffer.end(), data.begin() + N);
        for(int i = N - 1; i > 0; --i) data[i] = op(data[2 * i], data[2 * i + 1]);
    }

    void update(std::size_t pos, T val) {
        for(data[pos += N] = val; pos >>= 1; ) {
            data[pos] = op(data[pos << 1], data[(pos << 1) + 1]);
        }
    }

    T query(std::size_t left, std::size_t right) {
        T vl = idelem, vr = idelem;
        for(left += N, right += N; left < right; left >>= 1, right >>= 1) {
            if(left & 1) vl = op(vl, data[left++]);
            if(right & 1) vr = op(data[--right], vr);
        }
        return op(vl, vr);
    }

    T operator[](std::size_t k) {
        return data[k + N];
    }
};

} // nasmespace tklib

#endif // TKLIB_SEGTREE_HPP


#include <bits/stdc++.h>
using namespace std;

int main() {
    int N; cin >> N;
    string S; cin >> S;
    vector<int> A(S.size());
    for(int i=0; i<S.size(); ++i) A[i] = (1 << (S[i] - 'a'));
    auto op = [](int a, int b){return a | b;};
    tklib::Segtree<int, decltype(op)> st(begin(A), end(A), 0, op);

    int Q; cin >> Q;
    while(Q--) {
        int k; cin >> k;
        if(k == 1) {
            int i; char c; cin >> i >> c;
            st.update(i - 1, (1 << (c - 'a')));
        } else {
            int l, r; cin >> l >> r;
            cout << __builtin_popcount(st.query(l - 1, r)) << '\n';
        }
    }
}

Measured memory_bytes: 8836
import java.util.Scanner;
     
    class Main{
        public static void main(String[] args) {
            Scanner scn=new Scanner(System.in);
            int h=scn.nextInt();
            int w=scn.nextInt();
            char[][] map=new char[h][w];
            for(int i=0;i<h;i++){
                String text=scn.next();
                for(int j=0;j<w;j++){
                    map[i][j]=text.charAt(j);
                }
            }
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    int cnt=0;
                    if(i!=0){
                        if(map[i-1][j]=='#') cnt++;
                        if(j!=0){
                        if(map[i-1][j-1]=='#') cnt++;
                        }
                        if(j!=w-1){
                            if(map[i-1][j+1]=='#') cnt++;
                        }
                    } 
                    if(i!=h-1){
                        if(map[i+1][j]=='#') cnt++;
                        if(j!=0){
                        if(map[i+1][j-1]=='#') cnt++;
                        }
                        if(j!=w-1){
                            if(map[i+1][j+1]=='#') cnt++;
                        }
                    } 
                    if(j!=0){
                       if( map[i][j-1]=='#') cnt++;
                    }
                    if(j!=w-1){
                       if( map[i][j+1]=='#') cnt++;
                    }
                   if(map[i][j]!='#') map[i][j]=(char)(cnt+48);
     
                }
            }
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    System.out.print(map[i][j]);
                }
                System.out.println();
            }
        }
    }

Measured memory_bytes: 23124
# triples of unique characters
# j - i != k - j

#from bisect import bisect_right

N = int(input())
S = input()

def solve(N, S):
    R = [1] if S[0] == "R" else [0]
    G = [1] if S[0] == "G" else [0]
    B = [1] if S[0] == "B" else [0]
    
    for i in range(1, N):
        char = S[i]

        if char == "R":
            R.append(R[-1] + 1)
            G.append(G[-1])
            B.append(B[-1])
        elif char == "G":
            R.append(R[-1])
            G.append(G[-1] + 1)
            B.append(B[-1])
        else:
            R.append(R[-1])
            G.append(G[-1])
            B.append(B[-1] + 1)
    
    count = 0

    for i in range(N-2):
        for j in range(i+1, N-1):
            if S[i] == S[j]:
                continue
            
            if S[i] != "R" and S[j] != "R":
                prefix = R
                char = "R"
            elif S[i] != "G" and S[j] != "G":
                prefix = G
                char = "G"
            else:
                prefix = B
                char = "B"

            k = 2*j-i

            count += prefix[-1] - prefix[j]
            if k < N and S[k] == char:
                count -= 1     
                
    return count

print(solve(N, S))

Measured memory_bytes: 74384
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1;
const int inf=(1ull<<31)-1;
ll n,ans;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>n;
	for (ll i=sqrt(n)+1;i>0;i--){
		if (n%i==0){
			ans=i+n/i-2;
			break;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;

const ll INF = 1e18L + 5;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, w;
    cin >> n >> w;
    int weight[n + 1];
    int value[n + 1];
    int value_sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> weight[i] >> value[i];
        value_sum += value[i];
    }
    vector<ll> dp(value_sum + 1, INF);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = value_sum; j >= 0; j--) {
            if (j >= value[i]) {
                dp[j] = min(dp[j - value[i]] + weight[i], dp[j]);
            }
        }
    }
    ll res = 0L;
    for (int i = 1; i <= value_sum; i++) {
        if (dp[i] <= w) {
            res = max((ll)i, res);
        }
    }
    cout << res <<endl;
    return 0;
}

Measured memory_bytes: 1024