akhauriyash/Code-Regression huggingface dataset:
N,K = map(int,input().split())
A = map(int,input().split())

A_sum = [0]
for a in A:
    A_sum.append(A_sum[-1]+a)

score = []
for r in range(1,N+1):
    for l in range(0,r):
        score.append(A_sum[r]-A_sum[l])

ans = 0
for i in range(40,-1,-1):
    count = 0
    score_a = []
    for j in score:
        if (j & (1<<i)):
            count += 1
            score_a.append(j)
    if count >= K:
        ans += (1<<i)
        score = [i for i in score_a]

print(ans)


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


public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		Integer nInteger = Integer.parseInt(bufferedReader.readLine());
		String string =bufferedReader.readLine();
		String []str = string.split(" ");
		
		for(int i = str.length-1; i >= 0; i--){
			if (i != 0) {
				System.out.print(str[i] + " ");
			}else{
				System.out.print(str[i]);
			}
		}System.out.println();
	}
}

Measured memory_bytes: 24368
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define IN inline
#define RE register
using namespace std;
const int maxn=2e3+5;
int n,m,q;
int l,u,r,d;
int sum[maxn][maxn][3];
char s[maxn];
bool mp[maxn][maxn];
IN int read(){
	int ret=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}
IN void work(){
	u=read(),l=read(),d=read(),r=read();
	int v=sum[d][r][0]-sum[d][l-1][0]-sum[u-1][r][0]+sum[u-1][l-1][0];
	int e1=sum[d][r][1]-sum[d][l-1][1]-sum[u][r][1]+sum[u][l-1][1];
	int e2=sum[d][r][2]-sum[d][l][2]-sum[u-1][r][2]+sum[u-1][l][2];
	printf("%d\n",v-e1-e2);
	return;
}
int main(){
// 	freopen("wang.in","r",stdin);
// 	freopen("wang.out","w",stdout);
	n=read(),m=read(),q=read();
	for(RE int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=m;j++) mp[i][j]=s[j]-'0';
	}
	for(RE int i=1;i<=n;i++)
	for(RE int j=1;j<=m;j++){
		sum[i][j][0]=sum[i][j-1][0]+sum[i-1][j][0]-sum[i-1][j-1][0]+mp[i][j];
		if(i>1) sum[i][j][1]=sum[i][j-1][1]+sum[i-1][j][1]-sum[i-1][j-1][1]+(mp[i][j]&mp[i-1][j]);
		if(j>1) sum[i][j][2]=sum[i][j-1][2]+sum[i-1][j][2]-sum[i-1][j-1][2]+(mp[i][j]&mp[i][j-1]);
	}
	for(RE int i=1;i<=q;i++) work();
	return 0;
}

Measured memory_bytes: 52736
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<int> a;

int main(){
  int n;
  cin >> n;
/*  char s;
  cin >> s;
  cin >> s;
  scanf ("%d",&n);
  printf("%d\n",n);*/
  while(n){
    int num=0;
    int en=0;
    int m=1;
    int mm=0;
    char al;
    char s;
    a.assign(26,0);
    //scanf ("\n");
    //scanf ("%c",&s);
    cin >> s;
    a[int(s)-65]++;
    num=num|(1<<(int(s)-65));
    al=s;
    if(n==1){
      en=1;
    }
    else{
      for(int t=1;t<n;t++){
        cin >> s;
        a[int(s)-65]++;
        num=num|(1<<(int(s)-65));
        if(m<a[int(s)-65]&&en==0){
          m=a[int(s)-65];
          al=s;
        }
        else{
          if(mm<a[int(s)-65]&&en==0){
            mm=a[int(s)-65];
          }
        }
        if((m-mm)>=n-t&&en==0){
          en=t+1;
        }
      }
    }
    if(en){
      printf("%c %d\n",al,en);
    }
    else{
      printf("TIE\n");
    }
    //scanf ("%d",&n);
    cin >> n;
  }
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define deb(x) cout << #x << " => " << x << endl

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

    int n; cin >> n;
    double p_head[n];
    for (int i = 0; i < n; i++) {
        cin >> p_head[i];
    }
    
    double dp[n + 1];
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j >= 0; j--) {
            dp[j] = (j == 0 ? 0 : dp[j - 1] * p_head[i]) + dp[j] * (1 - p_head[i]);
        }
    }
    double res = 0;
    for (int i = 0; i <= n; i++) {
        if (i > n - i) {
            res += dp[i];
        }
    }
    cout << setprecision(10) << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main() {
	int tmp[1000] = {0};
	int a, b;
	while (1) {
		if (cin >> a >> b == NULL)
			break;
		if (!a && !b) {
			bool flag = true;
			if (!(tmp[0] % 2 == 1 && tmp[1] % 2 == 1))
				flag = false;
			FOR(i,2,1000) {
				if (tmp[i] % 2 != 0)
					flag = false;
			}
			if (flag)
				cout << "OK" << endl;
			else
				cout << "NG" << endl;
			REP(i,1000)
				tmp[i] = 0;
			continue;
		}
		++tmp[a-1]; ++tmp[b-1];
	}
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int X, Y;
        public int[] XX, YY;
        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                X = line[2];
                Y = line[3];
            }

            XX = Input.ReadIntArray();
            YY = Input.ReadIntArray();

            X = Math.Max(X, XX.Max());
            Y = Math.Min(Y, YY.Min());

            Console.WriteLine(X < Y ? "No War" : "War");
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13396
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
ll test[12345678];
signed main() {
	ll n, m, q, k, a = 0, b = 0, c = 0, cnt = 0; string s, t;
	cin >> s; vector<ll>v;
	cout << s[0] << s[1] << s[2] << endl;
	return 0;
}

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



int main() {
	while (true) {
		int ans = 100000000;
		int n;
		cin >> n;
		if (n == 0) return 0;
		for (int i = 0; i < n; i++) {
			int num = i * i * i;
			if (num > n) break;
			int num2 = sqrt(n - num);
			int num3 = n - num - (num2 * num2);
			ans = min(ans, i + num2 + num3);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 2988
S = input()
left_stp = [v in ["L","U","D"] for i, v in enumerate(S) if i % 2 == 1]
right_stp = [v in ["R","U","D"] for i, v in enumerate(S) if i % 2 == 0]
if all(left_stp) and all(right_stp):
  print("Yes")
else:
  print("No")

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

const int MOD = (int)1e9+7;

int main(){
	int N,M,Q;
	cin >> N >> M >> Q;
	vector<int> L(M);
	vector<int> R(M);
	for(int i=0;i<M;i++)	cin >> L.at(i) >> R.at(i);
	vector<int> p(Q);
	vector<int> q(Q);
	for(int i=0;i<Q;i++)	cin >> p.at(i) >> q.at(i);

	vector<vector<int>> LR(N+1,vector<int>(N+1,0));
	for(int i=0;i<M;i++){
		LR.at(L.at(i)).at(R.at(i))++;
	}
	vector<vector<int>> sum(N+1,vector<int>(N+1,0));
	for(int i=0;i<N+1;i++){
		for(int j=0;j<N+1;j++){
			sum.at(i).at(j)=LR.at(i).at(j);
			if(i-1>=0)	sum.at(i).at(j)+=sum.at(i-1).at(j);
			if(j-1>=0)	sum.at(i).at(j)+=sum.at(i).at(j-1);
			if(i-1>=0 && j-1>=0)	sum.at(i).at(j)-=sum.at(i-1).at(j-1);
		}
	}

	for(int i=0;i<Q;i++){
		int start=p.at(i);
		int end=q.at(i);
		int ans=sum.at(end).at(end)-sum.at(end).at(start-1)-sum.at(start-1).at(end)+sum.at(start-1).at(start-1);
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;

int n, a, b, x[100010];
int ans = 0;
signed main()
{
  cin >> n >> a >> b;
  for(int i = 0; i < n; i++)
    cin >> x[i];

  for(int i = 1; i < n; i++)
    ans += min(a * (x[i] - x[i - 1]), b);

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


Measured memory_bytes: 1024
n,m=map(int,input().split())
Y=[[] for i in range(n+1)]
C=[]
ans={}

for city in range(m):
    p,y=map(int,input().split())
    Y[p].append((y,city))
    C.append(p)
    
for lis in Y:
    lis.sort()
    num=1
    for tup in lis:
        ans[tup[1]]=num
        num+=1

for res in range(m):
    #print((C[res],ans[res]))
    print('{:0=6}'.format(C[res])+'{:0=6}'.format(ans[res]))

Measured memory_bytes: 40736
using System;
using System.Diagnostics;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = new int[5] { 1, 2, 3, 4, 5 };
            int[] n = new int[5];
            n = Console.ReadLine().Split(" ").Select(s => int.Parse(s)).ToArray();
            foreach (var i in n)
            {
                if( i!=0 )
                x[i - 1] = 0;
            }
            Console.WriteLine(x.Sum());
        }
    }
}


Measured memory_bytes: 28292
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int meiro[110][110];
int cc;
int w,h;
int xx[]={1,-1,0,0};
int yy[]={0,0,1,-1};

void dfs(int x,int y){
	meiro[y][x]=-1;
	int i;
	for(i=0;i<4;i++){
		if(x+xx[i]<0||w<=x+xx[i]||y+yy[i]<0||h<=y+yy[i])continue;
		if(meiro[y+yy[i]][x+xx[i]]!=cc)continue;
		dfs(x+xx[i],y+yy[i]);
	}
}

int main() {
	int xs,ys,xg,yg,n,c,d,x,y;
	while(w=in(),h=in()){
		cin>>xs>>ys>>xg>>yg>>n;
		xs--;ys--;xg--;yg--;
		int i;
		memset(meiro,0,sizeof(meiro));
		for(i=0;i<n;i++){
			cin>>c>>d>>x>>y;
			x--;y--;
//cout<<c<<" "<<d<<" "<<x<<" "<<y<<endl;
			if(d==0){
				meiro[y][x]=meiro[y][x+1]=meiro[y][x+2]=meiro[y][x+3]=meiro[y+1][x]=meiro[y+1][x+1]=meiro[y+1][x+2]=meiro[y+1][x+3]=c;
			}else{
				meiro[y][x]=meiro[y][x+1]=meiro[y+1][x]=meiro[y+1][x+1]=meiro[y+2][x]=meiro[y+2][x+1]=meiro[y+3][x]=meiro[y+3][x+1]=c;
			}
		}
		if(meiro[ys][xs]==0){
			cout<<"NG\n";
			continue;
		}
		cc=meiro[ys][xs];
//cout<<"hoge\n";
		dfs(xs,ys);
//cout<<"piyo\n";
		if(meiro[yg][xg]==-1)cout<<"OK\n";
		else cout<<"NG\n";
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>

using namespace std;

int main(){
  int a,b,c,ans;
  string s;
  cin >> s;
  for(int i = 0; i < 3; i++){
    if(s[i] == s[i+1]){
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  static int []pre, in , post;
  static int n, pos,count;
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    int k;
    pre = new int[n];
    in = new int[n];
    post = new int[n];
    for(int i =0; i<n; i++){
      k = sc.nextInt();
      pre[i] = k;
    }

    for(int i = 0; i<n; i++){
      k = sc.nextInt();
      in[i] = k;
    }
    solve();
  }

  static void rec( int l, int r){
    if( l >= r)return;
    int root = pre[pos++];
    int m=0;
    while(in[m] != root)m++;
    rec(l,m);
    rec(m+1,r);
    post[count++] = root;
  }

  static void solve(){
    pos = 0;
    rec(0, n);
    StringBuilder bl = new StringBuilder();
    for (int i = 0; i < n-1; i++) {
      bl.append(post[i]);
      bl.append(" ");
    }
    bl.append(post[n-1]);
    bl.append("\n");
    System.out.print(bl);
  }
}


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

using namespace std;

#define ll  long long
#define ld  double

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

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

int f[3];
int p[2];
int v[2];

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

    int n;  cin >> n;

    int ans = 0;
    int pre = 0;

    for(int i = 0 ; i <= n ; ++i)   {
        int x = 0;
        if (i < n)
            cin >> x;

        p[0] = 0;
        p[1] = x - pre;

        if (p[0] < p[1])
            swap(p[0],p[1]);

        f[0] = f[1] = 1e9;
        f[2] = 0;

        for(int j = 0 ; j < 2 ; ++j)
        for(int k = 0 ; k < 2 ; ++k)    f[j + k] = min(f[j + k],max(0,v[j] + p[k]));

        if (f[0] > x)   {
            v[0] = f[1];
            v[1] = f[2];

            ans++;
        }
        else
            v[0] = f[0],
            v[1] = f[1];

        pre = x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using ll = long long;

using namespace std;
ll gcd(ll a, ll b)
{
	if(b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

int main()
{
  // 整数の入力
  int num;
  cin >> num;

  // 出力
  ll ret = 1LL;
  for(int i=0; i<num; i++)
  {
		ll T;
		cin >> T;
		ret = lcm(ret, T);
  }

	cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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;
}
int main(){
    while(true){
        ll n,m;cin >> n >>m;
        if(n==0)break;
        vl c(m),x(n);
        rep(i,m)cin >> c[i];
        rep(i,n)cin >> x[i];
        vvl dp(n+1,vl(256,inf));
        dp[0][128]=0;
        rep(i,n){
            rep(j,256){
                rep(k,m){
                    if(j+c[k]>255){
                        chmin(dp[i+1][255],dp[i][j]+(255-x[i])*(255-x[i]));
                        continue;
                    }
                     if(j+c[k]<0){
                        chmin(dp[i+1][0],dp[i][j]+(0-x[i])*(0-x[i]));
                        continue;
                    }
                    chmin(dp[i+1][j+c[k]],dp[i][j]+(j+c[k]-x[i])*(j+c[k]-x[i]));
                }
            }
        }
        ll ans=inf;
        rep(i,256){
            chmin(ans,dp[n][i]);
        }
        cout << ans <<endl;
    }
}


Measured memory_bytes: 43720
n = gets.chomp.to_i
p = gets.chomp.split.map(&:to_i)
ans = 0
for i in 1..p.length - 2
  if p[i - 1] > p[i] && p[i] >= p[i + 1] ||
     p[i - 1] <= p[i] && p[i] < p[i + 1]
    ans += 1
  end
end
puts ans


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

struct Card { char suit, value; };

void bubblesort(struct Card A[], int n) {
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j >= 0; j--) {
			if (A[j].value < A[j - 1].value) {
				swap(A[j], A[j - 1]);
			}
		}
	}
}

void selectionSort(struct Card A[], int n) {
	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (A[j].value < A[minj].value) {
				minj = j;
			}
		}
		swap(A[i], A[minj]);
	}
}

void trace(struct Card A[], int n) {
	for (int i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

bool isStable(struct Card A[], struct Card B[], int n) {
	for (int i = 0; i < n; i++) {
		if (A[i].suit != B[i].suit) return false;
	}
	return true;
}

int main() {
	int n; cin >> n;
	Card A[40], B[40];
	for (int i = 0; i < n; i++) cin >> A[i].suit >> A[i].value;
	for (int i = 0; i < n; i++) B[i] = A[i];
	bubblesort(A, n);
	trace(A, n);
	cout << "Stable" << endl;
	selectionSort(B, n);
	trace(B, n);
	cout << (isStable(A, B, n) ? "Stable" : "Not stable") << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>


using namespace std;

typedef long long LL;

int list1[30];
bool bn[30];
int totol;

int main()
{
    int n;
    string str1;
    while (cin >>n)
    {
        cin >>str1;
        //cout<<str1<<endl;
        memset(list1,0,sizeof(list1));
        memset(bn,false,sizeof(bn));
        totol =0;
        for (int i=0; i<n; i++)
        {
            if (str1[i]>='a' && str1[i]<='z')
                list1[str1[i]-'a']++;
        }
        for (int i=0; i<26; i++)
        {
            if (list1[i]>0)
                totol++;
        }
        int ans =0;
        int llans =0;
        for (int i=0; i<n; i++)
        {
            //cout<<list1[i]<<endl;
            if (bn[str1[i]-'a'] == false)
            {
                bn[str1[i]-'a'] = true;
                llans ++;
            }
            list1[str1[i]-'a']--;
            //cout<<str1[str1[i]]<<endl;
            if (list1[str1[i]-'a'] == 0)
                llans--;
            ans =max(ans,llans);
        }
        cout<<ans<<endl;
    }




#ifdef VSCode
    system("pause");
#endif
    return 0;
}

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

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, (n))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N, A, B;
    cin >> N >> A >> B;

    vector<double> v(N);
    REP(i, N) cin >> v[i];

    sort(v.begin(), v.end(), greater<LL>());

    double mv = 0;
    int l = 1;
    LL prev = -1;
    REP(i, A) {
        mv += v[i] / A;
        if (prev == v[i]) ++l;
        else {
            prev = v[i];
            l = 1;
        }
    }

    // count right
    int r = 0;
    FOR(i, A, N) {
        if (v[i] != v[A-1]) break;
        ++r;
    }

    // calc combination matrix
    int t = l+r+1;
    unsigned long long M[t][t];
    REP(i, t) REP(j, t) M[i][j] = 0;
    M[0][0] = 1;
    REP(i, l+r) {
        REP(j, i+1) {
            M[i+1][j] += M[i][j];
            M[i+1][j+1] += M[i][j];
        }
    }

    unsigned long long cnt = 0;
    if (l < A) {
        cnt += M[l+r][l];
    } else {
        // All values are the same.
        REP(i, min(B - A, r) + 1) {
            cnt += M[l+r][A+i];
        }
    }

    cout.precision(20);
    cout << fixed << mv << endl << cnt << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> p(m);
    REP(i, 0, m) {
        cin >> p[i];
        p[i]--;
    }
    vector<ll> A(n - 1), B(n - 1), C(n - 1);
    REP(i, 0, n - 1) {
        cin >> A[i] >> B[i] >> C[i];
    }
    vector<ll> imos(n, 0);
    REP(i, 0, m - 1) {
        int a = p[i], b = p[i + 1];
        if (a > b) swap(a, b);
        imos[a]++;
        imos[b]--;
    }
    REP(i, 0, n - 1) {
        imos[i + 1] += imos[i];
    }
    ll ans = 0;
    REP(i, 0, n - 1) {
        ans += min(A[i] * imos[i], B[i] * imos[i] + C[i]);
    }
    cout << ans << endl;
    return 0;
}



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

typedef long long ll;

ll A, B, K;

int main() {
  cin >> A >> B >> K;

  ll ans_A, ans_B;

  if (A > K) {
    ans_A = A - K;
    ans_B = B;
  }
  else if ((K - A) < B) {
    ans_A = 0;
    ans_B = B - (K-A);
  }
  else {
    ans_A = 0;
    ans_B = 0;
  }
  cout << ans_A << " " << ans_B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin>>N;
	vector<vector<int>>v(3);
	v[0].resize(N);
	v[1].resize(N);
	v[2].resize(N);
	for(int i=0;i<N;i++){
		cin>>v[0][i]>>v[1][i]>>v[2][i];
	}
	int dp[3][N];
	dp[0][0] = v[0][0];
	dp[1][0] = v[1][0];
	dp[2][0] = v[2][0];
	for(int j=1;j<N;j++){
		dp[0][j] = max(dp[1][j-1],dp[2][j-1])+v[0][j];
		dp[1][j] = max(dp[0][j-1],dp[2][j-1])+v[1][j];
		dp[2][j] = max(dp[1][j-1],dp[0][j-1])+v[2][j];
	}
	int res = max(dp[0][N-1],dp[1][N-1]);
	res = max(res,dp[2][N-1]);
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;

struct edge {
    int to,cost;
};

int n;
ve<ve<edge>> G;
vi ans;


void dfs(int u,int v,int color){

    //cout << 1 << endl;
    for (auto p : G[u]) {
        if(ans[p.to] != -1) continue;
        //cout << p.to << endl;
        if(p.cost%2==0){
            ans[p.to] = color;
            dfs(p.to,u,color);
        }
        else {
            if(color == 0) {
                ans[p.to] = 1;
                dfs(p.to,u,1);
            }
            else {
                ans[p.to] = 0;
                dfs(p.to,u,0);
            }
        }
            
    }
    
}



int main()
{
    cin >> n;
    G.resize(n);
    rep(i,n-1){
        int u,v,w;
        cin >> u >> v >> w;
        u--,v--;
        G[u].push_back({v,w});
        G[v].push_back({u,w});
    }
    ans.resize(n,-1);
    ans[0] = 0;
    
    dfs(0,-1,0);
    
    rep(i,n) cout << ans[i] << endl;


    return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const lli mod = 1e9 +7;


lli gcd(lli a, lli b){
    if(a%b==0) return b;
    return gcd(b,a%b);
}

lli lcm(lli a, lli b){
    return a /gcd(a,b) *b;
}

lli ExGCD(lli a, lli b, lli &x, lli &y){
    lli d=a;
    x=1; y=0;
    if(b!=0){ d=ExGCD(b, a%b, y, x); y-=a/b*x; }
    return d;
}
lli inverse(lli a){
    lli x,y;
    ExGCD(a, mod, x, y);
    return x>0? x: mod+x;
}

lli fact[300001];
lli inv[300001];
void maketable(){
    fact[0] = 1;
    for(int i=0; i<300000; i++){
        fact[i+1] = fact[i]*(i+1) %mod;
    }
    lli y;
    for(int i=0; i<300000; i++){
        ExGCD(fact[i], mod, inv[i], y);
        while(inv[i]<0) inv[i]+=mod;
    }
}

vector<pair<lli, lli> > factoring(lli n){
    vector<pair<lli, lli> > res;
    for(lli i=2; i*i<=n; i++){
        if(n%i == 0){
            res.emplace_back(i, 0);
            while(n%i == 0){
                n /= i;
                res.back().second++;
            }
        }
    }
    if(n != 1){
        res.emplace_back(n, 1);
    }
    return res;
}

int main(){
    maketable();
    lli n,m;
    cin >> n >> m;
    auto factor = factoring(m);
    lli ans = 1;
    for(auto p: factor){
        ans *= fact[n-1 +p.second];
        ans %= mod;
        ans *= inv[p.second];
        ans %= mod;
        ans *= inv[n-1];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll n,m;
  cin >> n >> m;
  vll a(n);
  rep(i,0,n) cin >> a[i];
  sort(all(a));
  
  vll s(n+1,0);
  rep(i,0,n) s[i+1]=s[i]+a[i];
  
  auto calc = [&](int x) {
    ll tot = 0, num = 0;
    rep(i,0,n) {
      int j = lower_bound(all(a), x-a[i]) - a.begin();
      num += n-j;
      tot += s[n]-s[j];
      tot += a[i]*ll(n-j);
    }
    return make_pair(tot,num);
  };
 
  int l = 0, r = 200005;
  while (l+1<r) {
    int c = (l+r)>>1;
    if (calc(c).second >= m) l = c; else r = c;
  }
  auto p = calc(l);
  ll ans = p.first;
  ans -= (p.second-m)*l;
  cout << ans << endl;
  
  
  
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 4784
//(UNCOMMENT WHEN SUBMITTING)
//#pragma GCC optimize("O3")
 
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
// #pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>

// clang-format off
#define range(i) for (int _ = 0; _ < i; _++)
#define vprnt(v) for (auto vi : v) cout << vi << " "; cout << endl;
#define fastio() ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace ::std;
int nxt() {int x;cin >> x;return x;}
ll nxtll() {ll x;cin >> x;return x;}
// clang-format on

ll MOD = 1000000007LL;
 
int main() {
    fastio();
    ll N = nxtll();
    vector<ll> A(N);
    generate(all(A), nxtll);


    ll sum = 0;
    for (int i = 0 ; i < N ; i++)
        sum = (sum + A[i]) % MOD;
    
    ll res = 0LL;
    for (int i = 0 ; i < N - 1 ; i++) {
        sum = (sum - A[i] + MOD) % MOD;
        res = (res + ((sum * A[i]) % MOD) ) % MOD;
    }

    cout << res << endl;

    
    return 0;
}

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

int a[200010];
int n;
int main(){

    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];

    sort(a, a+n);

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

    cout << "YES" << endl;
    
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y,z;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y<a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[1];
int l[1];
int j[1];

long long x,y,z,mod=1000000007;
//string r;
char r[3];

P u[200101];
priority_queue<P> q;
stack<int> s;
//set<int> s;
map<int,int> p;

vector<int> v[3];


bool as(P a,P b)
{
  if(a.x!=b.x)
  return a.x<b.x;
  return a.y>b.y;
}

int main()
{
  scanf("%d",&a);
  int x1=mod,x2=0,y1=mod,y2=0;
  for(int t=1;t<=a;t++)
  {
    scanf("%d %d",&n,&m);
    if(n>m) swap(n,m);
    if(y2<m&&x1>n) i=1;
    else if(y2<=m||x1>=n) i=0;
    x1=min(x1,n);
    x2=max(x2,n);
    y1=min(y1,m);
    y2=max(y2,m);
    q.push({n,m});
  }
  x=(long long)(y2-y1)*(x2-x1);
  n=mod,m=0;
  k=mod;
  for(;q.size();)
  {
    m=max(m,q.top().x);
    n=min(n,q.top().x);
    q.pop();
    if(q.size()) k=min(k,max(m,q.top().y)-min(n,y1));
    else k=min(k,m-n);
  }
  printf("%lld",min(x,(long long)k*(y2-x1)));
}
//5




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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
const int MOD=1e9+7;
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); <-- PUT IN main()/solve()!

using namespace std;

class ACircle {
public:
	void solve(std::istream& in, std::ostream& out) {
		int r;
		in >> r;
		out << r*r << "\n";
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ACircle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

ll solve(vpi v) {
    multiset<pi> a, b;
    for (auto& x: v) a.insert(x), b.insert({x.s,x.f});
    ll ans = 0;
    int cur = 0, dir = 1;
    while (sz(a)) {
        // cout << "HI " << cur << "\n";
        if (dir == 1) {
            auto z = *a.rbegin(); a.erase(a.find(z)), b.erase(b.find({z.s,z.f}));
            int des = max(cur,z.f); des = min(des,z.s);
            ans += abs(des-cur);
            cur = des;
        } else {
            auto z = *b.begin(); swap(z.f,z.s); a.erase(a.find(z)), b.erase(b.find({z.s,z.f}));
            int des = min(cur,z.s); des = max(des,z.f);
            ans += abs(des-cur);
            cur = des;
        }
        dir *= -1;
    }
    ans += abs(cur);
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int N; cin >> N;
    vpi v;
    F0R(i,N) {
        int a,b; cin >> a >> b;
        v.pb({a,b});
    }
    ll ans = solve(v);
    for (auto& a: v) {
        a = {-a.s,-a.f};
        // cout << a.f << " " << a.s << "\n";
    }
    ans = max(ans,solve(v));
    cout << ans;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

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

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;
int mod = 1000000007;

int main(void){
    string S; cin >> S;
    int x, y; cin >> x >> y;
    int pos_x = 0, pos_y = 0;
    int idx = 0;
    int lenS = S.length();
    while(idx < lenS && S[idx] == 'F'){
        pos_x++;
        idx++;
    }
    int turn_cnt = 0; //これが奇数回のうちはy方向に進めて、偶数回のうちはx方向に進める
    int dir_y = 0, dir_x = 0;
    vector<int> proceed_x, proceed_y;
    while(idx < lenS){
        if(S[idx] == 'T'){
            if(dir_x > 0) proceed_x.push_back(dir_x);
            if(dir_y > 0) proceed_y.push_back(dir_y);
            turn_cnt++;
            dir_x = 0, dir_y = 0;
        }
        else{
            if(turn_cnt % 2 == 0) dir_x++;
            else dir_y++;
        }
        idx++;
    }
    if(dir_x > 0) proceed_x.push_back(dir_x);
    if(dir_y > 0) proceed_y.push_back(dir_y);

    int acc_x = 0, acc_y = 0;
    rep(i, proceed_x.size()) acc_x += proceed_x[i];
    rep(i, proceed_y.size()) acc_y += proceed_y[i];

    x -= pos_x; y -= pos_y; //まあpos_yは0なんですけれどもね

    //(0,0)からproceed_xの要素とproceed_yの要素を全て使って(x, y)を実現
    //xとyは独立なのでxについてのロジックをそのままyに使えばいい
    x += acc_x;
    int dim2 = acc_x*2;
    if(x < 0 || x > dim2){
        cout << "No" << endl;
        return 0;
    }
    bool dp[proceed_x.size()+1][dim2+1];
    rep(i, proceed_x.size()+1){
        rep(j, dim2+1){
            dp[i][j] = false;
        }
    }
    dp[0][acc_x] = true;
    for(int i = 0; i < proceed_x.size(); i++){
        for(int j = 0; j <= dim2; j++){
            if(dp[i][j]){
                dp[i+1][j-proceed_x[i]] = true;
                dp[i+1][j+proceed_x[i]] = true;
            }
        }
    }
    bool res_x = dp[proceed_x.size()][x];

    y += acc_y;
    dim2 = acc_y*2;
    if(y < 0 || y > dim2){
        cout << "No" << endl;
        return 0;
    }
    bool dpy[proceed_y.size()+1][dim2+1];
    rep(i, proceed_y.size()+1){
        rep(j, dim2+1){
            dpy[i][j] = false;
        }
    }
    dpy[0][acc_y] = true;
    for(int i = 0; i < proceed_y.size(); i++){
        for(int j = 0; j <= dim2; j++){
            if(dpy[i][j]){
                dpy[i+1][j-proceed_y[i]] = true;
                dpy[i+1][j+proceed_y[i]] = true;
            }
        }
    }
    bool res_y = dpy[proceed_y.size()][y];
    if(res_x & res_y) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  for(int i = 0;i <= N;i++) {
    for(int j = 0;j <= M;j++) {
      int black = i*(M-j)+j*(N-i);
      if(black == K) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; 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 SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(m2 != m1 && d2 == 1) cout << 1 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5+2;
int arr[MX], nxtnum[MX], nxtpos[MX];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	for(int i=1; i<=n; i++) {
		cin >> arr[i];
	}
	for(int i=n; i>=1; i--) {
		nxtnum[arr[i]] = i;
		nxtpos[i] = nxtnum[arr[i]+1];
	}
	int t = 0;
	for(int i=1; i<=n; i++) {
		if(arr[i] == 1) {
			t = i;
			break;
		}
	}
	if(!t)
		return !(cout << -1);
	while(nxtpos[t]) {
		t = nxtpos[t];
	}
	cout << n-arr[t];
}

Measured memory_bytes: 2560
def main():
    n=int(input())
    X=input().strip()
    cnt_1=X.count('1')
    k1,k2=int(X,2)%(cnt_1-1) if cnt_1!=1 else 0,int(X,2)%(cnt_1+1)
    for i,x in enumerate(X):
        ans=0
        if x=='0':
            k=k2+pow(2,n-i-1,cnt_1+1)
            k%=cnt_1+1
            ans+=1
            while k:
                num=bin(k).count('1')
                k%=num
                ans+=1
        elif x=='1' and cnt_1!=1:
            k=k1-pow(2,n-i-1,cnt_1-1)
            k%=cnt_1-1
            ans+=1
            while k:
                num=bin(k).count('1')
                k%=num
                ans+=1
        else:
            ans=0
        print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 80396
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int cnt;
    vector<vector<int> > list(101, vector<int>(2));
    for(int i = 0; i < list.size(); i++) {
        cin >> list[i][0] >> list[i][1];
        if(list[i][0] == 0 && list[i][1] == 0) {
            cnt = i;
            break;
        }
    }

    for(int i = 0; i < cnt; i++) {
        int res = 0;
        for(int j = 1; j <= list[i][0]; j++) {
            for(int k = j + 1; k <= list[i][0]; k++) {
                if (list[i][1] - (j + k) > k && list[i][1] - (j + k)  <=list[i][0]  ) res += 1;
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>

using namespace std;

struct TopoSorter {
    const int WHITE = 0, GRAY = 1, BLACK = 2;
    int n;
    vector<vector<int>> g;
    bool hasCycle = false;
    vector<int> color;
    vector<int> s;
    
    TopoSorter(int n) : n(n) {
        g.assign(n, vector<int>());
        color.assign(n, WHITE);
    }
    
    void addEdge(int from, int to) {
        g[from].push_back(to);
    }
    
    void solve() {
        for (int i = 0; i < n; i++) {
            if (color[i] == WHITE) {
                dfs(i);
            }
        }
    }
    
    void dfs(int u) {
        color[u] = GRAY;
        for (int v : g[u]) {
            if (color[v] == WHITE) {
                dfs(v);
            }
            else if (color[v] == GRAY) {
                hasCycle = true;
            }
        }
        color[u] = BLACK;
        s.push_back(u);
    }   
};

int main() {
    int v, e;
    cin >> v >> e;
    TopoSorter d(v);
    for (int i = 0; i < e; i++) {
        int from, to;
        cin >> from >> to;
        d.addEdge(from, to);
    }
    d.solve();
    for (int i = v - 1; i >= 0; i--) {
        cout << d.s[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3700
N, A = map(int, input().split())
x = [int(i) for i in input().split()]

X = max(A, max(x))

dp = [[[0 for _ in range(N*X+1)] for _ in range(N+1)] for _ in range(N+1)]

for j in range(N+1):
    for k in range(N+1):
        for s in range(N*X+1):
            if j == 0 and k == 0 and s == 0:
                dp[j][k][s] = 1
            elif j >= 1 and s < x[j-1]:
                dp[j][k][s] = dp[j-1][k][s]
            elif j >= 1 and k >= 1 and s >= x[j-1]:
                dp[j][k][s] = dp[j-1][k][s]+dp[j-1][k-1][s-x[j-1]]
            else:
                dp[j][k][s] = 0

ans = 0
for k in range(1, N+1):
    ans += dp[N][k][k*A]

print(ans)


Measured memory_bytes: 96008
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

vector<pair<ll,ll>> factor_arr;

void myfactor(ll num){ 
    ll count = 0;   
    while (!(num % 2)) { 
        num >>= 1; count++; 
    }  
    if (count) factor_arr.push_back({2,count}); 
    for (auto i = 3; i <= sqrt(num); i += 2) { 
        count = 0; 
        while (num % i == 0) { 
            count++; 
            num /= i; 
        } 
        if (count) factor_arr.push_back({i,count}); 
    } 
    if (num > 2) factor_arr.push_back({num,1});
}

void virus(){
        ll a,b,c;
        cin>>a>>b>>c;
        cout<<min({a+b,b+c,a+c});
}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t=1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  ll n, k;
  cin >> n >> k;
  vll a(n);
  rep(i, 0, n){
    ll aa;
    cin >> aa;
    aa--;
    a.at(i) = aa;
  }
  ll roop = 0, to = 0, now = 0;
  vll seen(n, -1);
  seen.at(0) = 0;
  rep(i, 0, n){
    now = a.at(now);
    roop++;
    if(seen.at(now) == -1) seen.at(now) = roop;
    else{
      to = seen.at(now);
      roop -= to;
      break;
    }
  }
  if(k <= to){
    ll ans = 0;
    rep(i, 0, k) ans = a.at(ans);
    cout << ans + 1 << endl;
  }
  else{
    ll ans = 0;
    k -= to;
    k %= roop;
    rep(i, 0, to) ans = a.at(ans);
    rep(i, 0, k) ans = a.at(ans);
    cout << ans + 1 << endl;
  }
}

Measured memory_bytes: 6332
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
    string s;
    cin>>s;
    int kakaku=700;
    if(s[0]=='o')kakaku+=100;
    if(s[1]=='o')kakaku+=100;
    if(s[2]=='o')kakaku+=100;
    cout<<kakaku<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

int main() {
  for(int tci = 0; ; tci++) {
    int N,M; scanf("%d%d", &N, &M); if(N==0) break;
    vector<vector<pair<int,pair<int,int> > > > graph(N);
    for(int i = 0; i < M; i++) {
      int u,v,d,c; scanf("%d%d%d%d", &u, &v, &d, &c); u--; v--;
      graph[u].push_back(make_pair(v,make_pair(d,c)));
      graph[v].push_back(make_pair(u,make_pair(d,c)));
    }
    vector<char> vis(N);
    int cost_sum = 0;
    priority_queue<pair<pair<int,int>,int > > pq;
    pq.push(make_pair(make_pair(0,0),0));
    while(!pq.empty()) {
      int v = pq.top().second;
      int cost = pq.top().first.second;
      int dist = pq.top().first.first;
      pq.pop();
      if(vis[v]) continue;
      vis[v] = 1;
      cost_sum -= cost;
      for(int i = 0; i < (int)graph[v].size(); i++) {
        int w = graph[v][i].first;
        int d = graph[v][i].second.first;
        int c = graph[v][i].second.second;
        pq.push(make_pair(make_pair(dist-d,-c),w));
      }
    }
    printf("%d\n", cost_sum);
  }
  return 0;
}

Measured memory_bytes: 2320
n = int(input())
count = 0
def divisors(n):
    d=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            d.append(i)
            if i!=n//i:
                d.append(n//i)
    d.sort()
    return d
for i in range(n+1):
    if i % 2 == 1:
        if len(divisors(i)) == 8:
            count += 1
    else:
        continue
print(count)

Measured memory_bytes: 3188
import fractions
from functools import reduce
N,M= [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
#print(n)
n=sorted(set(n),reverse = True)
bs = n[0]
#print(n)
#c=len(n)
 
 
def lcm_b(a, b):
        #print("base",a,b)
        return (a * b) // fractions.gcd(a, b)
 
def lcm_o():
        global n
        return reduce(lcm_b, n)
 
def chk(v):
        global n
        for i in range(1,30):
                if v%2 == 1:break
                v = v//2
        t=2**(i-1)
        for j in range(len(n)):
                if n[j] % t == 0 and (n[j] / t) % 2 == 1:
                        n[j] = int(n[j]/t)
                else: return 0
        return int(t//2)
 
if len(n) > 1:
        
        c = chk(n[-1])
        
        if  c != 0:
                v = lcm_o()*c
                
                if v > M:
                        print(0) 
                else:
                        v = M//v
                        if v%2==1: v+=1
                        print(int(v//2))
        
        else: print(0)
elif len(n)==1:
        v = int(bs*0.5)
        v = M//v
        if v%2==1: v+=1
        print(int(v//2))

Measured memory_bytes: 18220
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
using Graph = vector<vector<pair<ll, ll>>>;


int main()
{
    ll N, M; cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256