akhauriyash/Code-Regression huggingface dataset:
import java.util.*
import java.io.PrintWriter

val pw = PrintWriter(System.out)
val MOD = 1000000007L
val INF = 2147483647
val LINF = 9223372036854775807L

fun main(args: Array<String>){
    solve()
    pw.flush()    
}

fun solve(){
    val (n, m) = nextIntList()
    println(n * (n - 1) / 2 + m * (m - 1) / 2)


}

// Print
fun println(v: String){
    pw.println(v)
}
fun print(v: String){
    pw.print(v)
}

// Read
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map{ it.toInt() }
fun nextLongList() = next().split(" ").map{ it.toLong() }
fun nextDoubleList() = next().split(" ").map{ it.toDouble() }
fun nextAryln(n: Int) = Array(n){ next() }
fun nextIntAryln(n: Int) = IntArray(n){ nextInt() }
fun nextLongAryln(n: Int) = LongArray(n){ nextLong() }
fun nextDoubleAryln(n: Int) = DoubleArray(n) { nextDouble() }

// Math
fun abs(n: Int) : Int = Math.abs(n)
fun abs(n: Long) : Long = Math.abs(n)
fun abs(n: Double) : Double = Math.abs(n)
fun max(a: Int = -INF, b: Int = -INF, c: Int = -INF, d: Int = -INF, e: Int = -INF): Int = listOf(a, b, c, d, e).max()!!
fun max(a: Long = -LINF, b: Long = -LINF, c: Long = -LINF, d: Long = -LINF, e: Long = -LINF): Long = listOf(a, b, c, d, e).max()!!.toLong()
fun min(a: Int = INF, b: Int = INF, c: Int = INF, d: Int = INF, e: Int = INF): Int = listOf(a, b, c, d, e).min()!!
fun min(a: Long = LINF, b: Long = LINF, c: Long = LINF, d: Long = LINF, e: Long = LINF): Long = listOf(a, b, c, d, e).min()!!.toLong()
fun prime(from: Long, to: Long = from) : List<Long>{
    return (from..to).filter{ i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all{ j -> i % j != 0L}
    }
}
fun gcd(a: Long, b: Long) : Long = if(a % b == 0L) b else gcd(b, (a % b))
fun lcm(a: Long, b: Long) : Long = a / gcd(a, b) * b
fun modpow(a: Long, n: Long, p:Long = MOD) : Long {
    var res = 1L
    var ar = a
    var nr = n
    while(nr > 0){
        if((nr and 1) == 1L) res = res * ar % p
        ar = ar * ar % p
        nr = nr shr 1
    }
    return res
}
fun modinv(a: Long, p: Long = MOD) : Long = modpow(a, p - 2, p)
fun ncr(n: Long, r: Long) : Long {
    var a = 1L
    var b = 1L
    for (i in 1..r) {
        a = a * (n + 1 - i) % MOD
        b = b * i % MOD
    }
    return modinv(b, MOD) * a % MOD
}


Measured memory_bytes: 35980
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector <ll> c(n);
  REP(i, n) {
	cin >> c[i];
  }
  sort(all(c), greater <ll>());
  if (n == 1) {
	  cout << 2 * c[0] % mod << endl;
	  return 0;
	}
  ll t1 = 1;
  ll t2 = 1;
  REP(i, 2 * n - 1) {
	t1 = t1 * 2 % mod;
  }
  REP(i, 2 * n - 2) {
	t2 = t2 * 2 % mod;
  }
  ll ans = 0;
  REP(i, n) {
	ans = (ans + ((t1 + t2 * i) % mod) * c[i] % mod) % mod;
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

struct UnionFind {
	int s, num; // [0, s) の s 個の要素がある。num は非空集合の個数。
	vector<vector<int>> v;
	vector<int> find;
	
	UnionFind() { s = 0; }
	UnionFind(int s) { init(s); }
	void init(int arg_s) {
		num = s = arg_s;
		v.clear();
		find.clear();
		inc(i, s) { v.PB({i}); find.PB(i); }
	}
	bool unite(int x, int y) {
		assert(inID(x, 0, s) && inID(y, 0, s));
		if(find[x] == find[y]) { return false; }
		num--;
		if(v[find[x]].size() > v[find[y]].size()) { swap(x, y); }
		int fx = find[x];
		for(auto && e: v[fx]) { v[find[y]].PB(e); find[e] = find[y]; }
		v[fx].clear();
		return true;
	}
};

// ----

LL n, m, x, MOD = 1e9 + 7;
array<LL, 3> e[2000];

int main() {
	cin >> n >> m >> x;
	inc(i, m) {
		LL a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		e[i] = { c, a, b };
	}
	sort(e, e + m);
	
	LL mst = 0;
	{
		UnionFind uf(n);
		inc(i, m) { if(uf.unite(e[i][1], e[i][2])) { mst += e[i][0]; } }
		assert(uf.num == 1);
	}
	if(mst > x) { cout << 0 << endl; return 0; }
	
	int a = 0, b = 0, c = 0;
	inc(k, m) {
		UnionFind uf(n);
		uf.unite(e[k][1], e[k][2]);
		LL s = e[k][0];
		inc(i, m) { if(uf.unite(e[i][1], e[i][2])) { s += e[i][0]; } }
		if(s <  x) { a++; }
		if(s == x) { b++; }
		if(s >  x) { c++; }
	}
	assert(a + b + c == m);
	
	assert((mst == x && a == 0 && b >= n - 1) || (mst < x && a >= n - 1));
	
	LL ans = 1;
	if(a > 0) { b++; }
	inc(i, b) { (ans *= 2) %= MOD; }
	(ans += MOD - 2) %= MOD;
	inc(i, c) { (ans *= 2) %= MOD;  }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
 
int main(){
    int N,M;
    cin >> N >> M;
    vector<long long> X(N),Y(N),Z(N);
    rep(i,N) cin >> X[i] >> Y[i] >> Z[i];
    int S[2] = {-1,1};

    long long res = 0;
    for(int bit = 0;bit < (1 << 3);bit++){
        int i1 = (bool)(bit & (1 << 0));
        int i2 = (bool)(bit & (1 << 1));
        int i3 = (bool)(bit & (1 << 2));
        long long r = 0;
        vector<pair<long long,int>> R(N);
        rep(i,N){
            long long sum = X[i] * S[i1] + Y[i] * S[i2] + Z[i] * S[i3];
            R[i] = make_pair(sum,i);
        } 
        sort(R.begin(),R.end(),greater<pair<long long,int>>());
        long long v1=0,v2=0,v3=0;
        rep(i,M){
            v1 += X[R[i].second];
            v2 += Y[R[i].second];
            v3 += Z[R[i].second];
        }
        long long sum = abs(v1) + abs(v2) + abs(v3);
        res = max(res,sum);
    }
    cout << res << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
  long long MOD=1000000007;
  #define IOS() ios_base::sync_with_stdio(0); cin.tie(0);
  typedef long long ll;
  #define pb push_back
  typedef pair<string,string> pi;


int main()
{
  IOS();
  int h;int w;
  cin>>h>>w;
  string a[h];
  for (int i = 0; i < h; ++i)
  {
      cin>>a[i];
  }

  ll dp[h][w];
  for (int i = 0; i < h; ++i)
  {
      for (int j = 0; j < w; ++j)
      {
          dp[i][j]=0;
      }
  }

  dp[h-1][w-1]=1;

  for(int i=h-1;i>=0;i--)
  {
    for(int j=w-1;j>=0;j--)
    {
      if(a[i][j]=='.')
      {
        if(i-1>=0)
          dp[i-1][j]=(dp[i-1][j]+dp[i][j])%MOD;
        if(j-1>=0)
          dp[i][j-1]=(dp[i][j-1]+dp[i][j])%MOD;
      }
    }
  }


  cout<<dp[0][0]%MOD<<endl;

  return 0;
}

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

int main(){
int d;
while(cin >> d){
int s;
s=600/d;
int a;
a=0;
int b;
b=0;
while(a<s){
b=b+d*d*a*a;
a=a+1;}
cout << b*d <<endl;}

}

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

const int mod = 1e9 + 7;
typedef long long ll;
ll d[100010];
int main()
{
    ll n, q;
    scanf("%lld%lld", &n, &q);
    for (int i = 0; i < n; i++)
    {

        scanf("%lld", &d[i]);
    }
    for (int i = 1; i <= q; i++)
    {
        ll nn, x, m;
        scanf("%lld%lld%lld", &nn, &x, &m);
        ll tot = 0;
        ll ret = 0, ret1 = 0;
        for (int j = 0; j < n; j++)
        {
            if (d[j] % m == 0)
                ret++;
            tot = tot + d[j] % m;
        }
        ll ans = ((nn - 1) / n) * tot / m;
        ll nw = x % m + ((nn - 1) / n) * (tot % m) % m;
        for (int j = 0; j < (nn - 1) % n; j++)
        {
            if (d[j] % m == 0)
                ret1++;
            nw += d[j] % m;
        }
        ans += nw / m;
        printf("%lld\n", nn - 1 - ans - ret1 - ((nn - 1) / n) * ret);
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, tot = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  int num = 1;
  for (int i = 0; i < N; i++) {
    if (vec.at(i) == num) {
      tot += 1;
      num += 1;
    }
  }
  
  if (tot == 0) {
    cout << -1 << endl;
  }
  else {
    cout << N - tot << endl;
  }
}

Measured memory_bytes: 1152
#include<stdio.h>
#include <math.h>
int main()
{
  int i,j;
      int x=(int)(pow(10,9)+7);
  long long int d=1;
  int ans;
  scanf("%d",&i);
  for(j=1;j<=i;j++)
  {
    d*=j;
    //while(d>=(pow(10,9)+7))
    //{
    //  d-=(pow(10,9)+7);
    //}
    d%=x;
  }
  printf("%lld\n",d);
}


Measured memory_bytes: 128
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
using namespace std;
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;	
int main() {
	string s, ss;
	cin >> s >> ss;
	sort(ALL(s));
	sort(ALL(ss), greater<char>());
	cout << (s < ss ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 100005;
int n;
long long ans;
char s[11];
string t[mx];
map<string, int> mp;
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%s", s);
		sort(s,s+10);
		mp[s]++;
	}
	for(auto it: mp){
		long long t = it.second;
		ans += t * (t-1) / 2;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 11904
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
long long int dp[12][100000] = {};
int main() {
	/*int a, b, c;
	a = 1;
	b = 6;
	c = 9;
	vector<int>s;
	vector<int>anss;
	int n;
	cin >> n;
	int ans = 0;
	s.push_back(a);
	for (int i = 0; i < 6; i++) {
		s.push_back(b);
		s.push_back(c);
		b = b * 6;
		c = c * 9;
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < 12; i++) {
		cout << s[i] << endl;
	}*/
	int n, k;
	cin >> n >> k;
	vector<int>s;
	for (int i = 0; i < n; i++) {
		int l;
		cin >> l;
		s.push_back(l);
	}
	sort(s.begin(), s.end(),greater<int>());
	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans = ans + s[i];
	}
	cout << ans;
}

Measured memory_bytes: 256
# 直前数文字しか影響しないと思えばDPと見当つく
MOD = 10**9 + 7
N = int(input())
dp = [[[[0]*5 for i in range(5)] for i in range(5)] for i in range(N+1)]

dp[0][0][0][0] = 1
for n in range(N):
    for i in range(5):
        for j in range(5):
            for k in range(5):
                for l in range(1,5):
                    if j == 1 and k == 2 and l == 3: continue  # AGC
                    if j == 2 and k == 1 and l == 3: continue  # GAC
                    if j == 1 and k == 3 and l == 2: continue  # ACG
                    if i == 1 and k == 2 and l == 3: continue  # A?GC
                    if i == 1 and j == 2 and l == 3: continue  # AG?C
                    dp[n+1][j][k][l] += dp[n][i][j][k]

ans = 0
for i in range(1,5):
    for j in range(1,5):
        for k in range(1,5):
            ans += dp[N][i][j][k]
            ans %= MOD
print(ans)



Measured memory_bytes: 3572
splitSum :: [String]-> Int -> Int
splitSum [] acc = acc
splitSum src acc = splitSum (tail src) acc'
  where
    acc' = acc + (read $ head src)

isH :: String -> String
isH s = if org `mod` sum' == 0 then
          "Yes"
        else
          "No"
  where
    org = read s
    sum' = splitSum [[c]| c<-s] 0

main = do
  n <- getLine
  putStrLn $ isH n

Measured memory_bytes: 508
# seishin.py
N = int(input())
*A, = map(int, input().split())

def solve(x):
    data = [0]*(N+1)
    def add(k, x):
        while k <= N:
            data[k] += x
            k += k & -k
    def get(k):
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s
    c = 0; d = 10**18
    for a in A:
        if x <= a:
            c += 1
        else:
            c -= 1
        d = min(c, d)
    res = N*(N+1)//2
    c = -d+1
    for a in A:
        res -= get(c)
        if x <= a:
            c += 1
        else:
            c -= 1
        add(c, 1)
    return res <= N*(N+1)//4

left = min(A); right = max(A)+1
while left+1 < right:
    mid = (left + right) // 2
    if solve(mid):
        left = mid
    else:
        right = mid
print(left)


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

int main(void) {
  int n;
  int h, m, s;

  cin >> n;
  h = n / 3600;
  m = (n % 3600) / 60;
  s = n % 60;

  cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3104
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	string s;
	long long int res = 0;
	cin >> s;
	for (int i = 0; i < (int)s.size() - 2; i++) {
		if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
			long long int back = 0;
			while (i - back >= 0 && s[i - back] == 'A')
				back++;
			long long int front = 0;
			while (i + front * 2 + 2 < s.size() && s[i + front * 2 + 1] == 'B' && s[i + front * 2 + 2] == 'C')
				front++;
			res += back * front;
			int isB = 1;
			for (int j = 0; j < back + 2 * front; j++) {
				if (j < front * 2) {
					if (isB == 1)
						s[i - back + 1 + j] = 'B';
					else
						s[i - back + 1 + j] = 'C';
					isB = 1 - isB;
				}
				else {
					s[i - back + 1 + j] = 'A';
				}
			}
			// cout << s << endl;
		}
	}
	cout << res << endl;
}














Measured memory_bytes: 640
#include <stdio.h>
 
int main(void) {
	int x,y;
	while(scanf("%d %d", &x, &y) != EOF){
		while(x > 0 && y > 0){
			if(x < y) y %= x;
			else x %= y;
		}
		printf("%d\n", x > 0? x : y);
	}
	return 0;
}
 

Measured memory_bytes: 596
import math
S=input()

N=math.floor(len(S))
N1=math.floor(((len(S)-1)/2))
N2=math.floor(((len(S)+3)/2)-1)

S1=S[:N1]
S2=S[N2:N]

if (S==S[::-1]) and (S1==S1[::-1]) and (S2==S2[::-1]):
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
     
#define pb emplace_back
#define fi first
#define se second
     
using namespace std;
     
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ ll x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int x, ip;

int main(){

  x = in();
  ip = in();

  double p = ip / 100.0;

  printf( "%.18lf\n" , ( x + 1 ) / 2 / p );

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int s = 0;
        for(int i = 0 ; i < n ; i++ ){
            a[i] = sc.nextInt();
            s += a[i];
        }
        Arrays.sort(a);
        sc.close();
        if(1.0 * s / (4 * m) > a[n - m]){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 35968
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {x: usize};

    if x < 600 {
        println!("8")
    } else if x < 800 {
        println!("7")
    } else if x < 1000 {
        println!("6")
    } else if x < 1200 {
        println!("5")
    } else if x < 1400 {
        println!("4")
    } else if x < 1600 {
        println!("3")
    } else if x < 1800 {
        println!("2")
    } else if x < 2000 {
        println!("1")
    }
}


Measured memory_bytes: 2144
import sys

readline = sys.stdin.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


def solve():
    n = ni()
    s = ns()
    l = list()
    for i in range(1, n-1):
        if s[i] == '0':
            li = ri = i
            while li > 0 and s[li - 1] == '1':
                li -= 1
            while ri + 1 < n and s[ri + 1] == '1':
                ri += 1
            if li != i != ri:
                l.append((i-1, i+2))
                for j in range(li, i-1):
                    l.append((j, i+2))
                for j in range(i+2, ri+1):
                    l.append((i-1, j+1))
    l.sort()
    l.sort(key = lambda x: x[1])
    # print(l)
    m = len(l)
    dp = [0]*(n+1)
    idx = 0
    for i in range(n+1):
        dp[i] = max(dp[i], dp[i-1])
        while idx < m and l[idx][0] == i:
            x, y = l[idx]
            dp[y] = max(dp[y], dp[x] + y - x - 2)
            idx += 1
    # print(dp)
    print(dp[n])
    return

solve()

# T = ni()
# for _ in range(T):
#     solve()


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


template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }


  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};


int main(){
    ll n,q; cin >> n >> q;
    SegmentTree<ll> seg(n,[](ll a, ll b){return min(a,b);},(1LL<<31)-1);
    while(q--){
        ll a,x,y; cin >> a >> x >> y;
        if(a==0) seg.update(x,y);
        else cout << seg.query(x,y+1) << endl;
    }
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n, m;
    cin >> n;
    vstr s(n);
    rep(i, n) cin >> s[i];
    cin >> m;
    vstr t(m);
    rep(i, m) cin >> t[i];

    map<string, int> mp;
    rep(i, n)
    {
        if (mp.count(s[i]) == 0)
        {
            mp.insert(make_pair(s[i], 1));
        }
        else
        {
            ++mp[s[i]];
        }
    }
    rep(i, m)
    {
        if (mp.count(t[i]) != 0)
        {
            --mp[t[i]];
        }
    }

    int ans = 0;
    for (auto x : mp)
    {
        ans = max(ans, x.second);
    }
    cout << ans << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#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<int, int>;
const int inf{int(1e9)};
const int mod = 1000000007;

// 二分累乗法
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(void){
  ll N;
  cin >> N;
  ll a = modpow(10, N, 1000000007);  // 10^n
  ll b = modpow(9, N, 1000000007);  // 9^n
  ll c = modpow(8, N, 1000000007);  // 8^n
  ll ans = ((a + c) % mod + mod - (2 * b) % mod) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3576
N = input("")
S = input("")

maru_batsu = 0
judge_skip = False
for index in range(1, int(N)):
    s0 = S[index - 1]
    s1 = S[index]
    if judge_skip == True:
        judge_skip = False
        continue
    if s0 != s1:
        maru_batsu += 1
        judge_skip = True
print(maru_batsu)
    


Measured memory_bytes: 5752
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
using MS = map<string, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  cin >> n;
  MS m;
  bool ans = true;
  vector<string> w(n);
  cin >> w[0];
  m[w[0]]++;
  reps1(i, n) {
    cin >> w[i];
    if (w[i][0] != w[i-1][w[i-1].size()-1]) ans = false;
    if (m[w[i]] != 0) ans = false;
    m[w[i]]++;
  }

  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

#define ll             long long
#define LL             long long
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define sz(x)          (int)x.size()
#define TN             typename
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof(a))
#define endl           '\n'

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> T lcm(T a, T b) {return a * (b / gcd(a, b));}
template <TN T> T sqr(T a) {return a * a;}
template <TN T> T cube(T a) {return a * a * a;}
template <TN T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void smax(T &a, T b) {a = a > b ? a : b;}

template <TN T> inline void Int(T &n) {
	n = 0; int f = 1; register int ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
	for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
	n = n * f;
}

#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
	vector <string> v;
	stringstream ss(s); string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
	cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
	err(++it, args...);
}

inline int in() {int n; scanf("%d", &n); return n;}
inline ll Lin() {ll n; scanf("%lld", &n); return n;}
inline double Din() {double n; scanf("%lf", &n); return n;}

inline int add(int a, int b, int mod) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b, int mod) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b, int mod) {return (ll)a * b % mod;}

const int N          = 2e5 + 5;
const ll  Mod        = (ll)1e9 + 7;
const int inf        = (int)2e9;
const ll  Inf        = (ll)1e18;
const int mod        = (int)1e9 + 7;


int solve() {
	int n = in();
	int can[n][n];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			can[i][j] = in();
		}
	}
	vector<int> dp((1 << n), 0);
	dp[0] = 1;
	for (int mask = 0; mask < (1 << n) - 1; mask++) {
		int a = __builtin_popcount(mask);
		for (int b = 0; b < n; b++) {
			if (can[a][b] && !(mask & (1 << b))) {
				int mask2 = mask | (1 << b);
				dp[mask2] = add(dp[mask2], dp[mask], mod);
			}
		}
	}
	printf("%d\n", dp[(1 << n) - 1]);
	return 0;
}

int main() {
	int test = 1, tc = 0;
	//scanf("%d", &test);
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define srep(i,n,m) for(int i=(int)n;i<=(int)m;i++)
int n,m;
int dp[52][52][52][52];
bool ok[52][52][52][52];
int inf = 1000000;
vector<string>s;
int saiki(int a,int b,int c,int d){
    if(a<0||a>=n||c<0||c>=n||b<0||b>=m||d<0||d>=m)return -inf;
    if(s[a][b]=='#'||s[c][d]=='#')return -inf;
    if(a==c&&b==d)return 0;
    if(ok[a][b][c][d])return dp[a][b][c][d]; 
    ok[a][b][c][d] = 1;
    if(a>c||b>d){
        return dp[a][b][c][d] = -inf;
    }
    if(s[a][b]>='a'&&s[a][b]<='z'&&s[c][d]==s[a][b]+('A'-'a')){
        if(c==a+1&&b==d)return dp[a][b][c][d]=1;
        if(c==a&&d==b+1)return dp[a][b][c][d]=1;
        int tmp = -inf;
        tmp = max(tmp,saiki(a+1,b,c-1,d)+1);
        tmp = max(tmp,saiki(a+1,b,c,d-1)+1);
        tmp = max(tmp,saiki(a,b+1,c-1,d)+1);
        tmp = max(tmp,saiki(a,b+1,c,d-1)+1);
        srep(i,a,c){
            srep(j,b,d){
                if(i==c&&j==d)continue;
                if(s[i][j]!=s[a][b]+('A'-'a'))continue;
                tmp = max(tmp,saiki(a,b,i,j)+saiki(i+1,j,c,d));
                tmp = max(tmp,saiki(a,b,i,j)+saiki(i,j+1,c,d));
            }
        }
        
        if(tmp<0)tmp = -inf;
        return dp[a][b][c][d] = tmp;
    }else{
        if(c==a+1&&b==d)return dp[a][b][c][d]=0;
        if(c==a&&d==b+1)return dp[a][b][c][d]=0;
        int tmp = -inf;
        tmp = max(tmp,saiki(a+1,b,c,d));
        tmp = max(tmp,saiki(a,b,c-1,d));
        tmp = max(tmp,saiki(a,b+1,c,d));
        tmp = max(tmp,saiki(a,b,c,d-1));
        if(s[a][b]>='a'&&s[a][b]<='z'&&s[c][d]>='A'&&s[c][d]<='Z'){
            srep(i,a,c){
                srep(j,b,d){
                    if(i==c&&j==d)continue;
                    if(s[i][j]!=s[a][b]+('A'-'a'))continue;
                    tmp = max(tmp,saiki(a,b,i,j)+saiki(i+1,j,c,d));
                    tmp = max(tmp,saiki(a,b,i,j)+saiki(i,j+1,c,d));
                }
            }
        }
        if(tmp<0)tmp = -inf;
        return dp[a][b][c][d] = tmp;
    }
}


int main(){
    while(cin >> n >> m &&n!=0){
        s.resize(n);
        rep(i,n)cin >> s[i];
        rep(i,52){
            rep(j,52){
                rep(k,52){
                    rep(l,52){
                        dp[i][j][k][l] = 0;
                        ok[i][j][k][l] = 0;
                    }
                }
            }
        }
        int ans = saiki(0,0,n-1,m-1);
        if(ans<0){
            cout << -1 << endl;
        }else{
            cout << ans << endl;
        }
    }
    return 0;
}


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

int main() {
	long n;
	cin >> n;
	vector<long> as(n),ori(n);
	for (long i = 0; i < n; i++){
		cin >> as.at(i);
		ori.at(i) = as.at(i);
	}
	sort(as.begin(),as.end());
	for (long i = 0; i < n; i++){
		if(ori.at(i) == as.at(n-1)){
			cout << as.at(n-2) << endl;
			continue;
		}
		cout << as.at(n-1) << endl;
	}	
}


Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <climits>
using namespace std;
int main(){
    int n,x;
    int m[100];
    
    cin>>n>>x;
// printf("%d\n",n);
// printf("%d\n",x);
    int min=INT_MAX;
    int powder=x;
    int count=n;

    for(int j=0;j<n;j++){
        cin>>m[j];
        
        if(min>m[j])min=m[j];
        powder-=m[j];
        
    }
// printf("%d\n",min);
    while((powder-=min)>=0){
        count++;
        // printf("%d\n",powder);
    }

    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAP_SIZE = 100;
#define drp(y, x) m[(y) + 10][(x) + 10] += 1

int m[MAP_SIZE][MAP_SIZE];

void setMap(int y, int x, int s);
void searchMap();

int main(){
    int x, y, s;
    memset(m, 0, sizeof(m));
    while(scanf("%d,%d,%d", &x, &y, &s) != EOF) setMap(y, x, s);
    searchMap();
    return 0;
}

void setMap(int y, int x, int s){
    drp(y, x);
    int mx[3][4] = {{0, 1, 0, -1}, {-1, 1, 1, -1}, {0, 2, 0, -2}};
    int my[3][4] = {{-1, 0, 1, 0}, {-1, -1, 1, 1}, {-2, 0, 2, 0}};
    for(int i = 0; i < s; i++){
        for(int j = 0; j < 4; j++){
            drp(y + my[i][j], x + mx[i][j]);
        }
    }
}

void searchMap(){
    int blankSum = 0, max = -1;
    for(int i = 10; i < 20; i++){
        for(int j = 10; j < 20; j++){
            if(m[i][j] > max) max = m[i][j];
            if(m[i][j] == 0) blankSum++;
        }
    }
    cout <<blankSum <<endl <<max <<endl;
}

Measured memory_bytes: 1256
#include<stdio.h>

int main()
{
    int N,M,i,a,b;
    int grad[1000];
    scanf("%d", &N);
    scanf("%d", &M);
    for(i=1;i<=N;i++)
        grad[i]=0;
    for(i=1;i<=M;i++)
    {
        scanf("%d %d", &a, &b);
        grad[a]=grad[a]+1;
        grad[b]=grad[b]+1;
    }
    for(i=1;i<=N;i++)
        printf("%d\n", grad[i]);
    return 0;
}

Measured memory_bytes: 128
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

for i in range(1 << 3):
    check = int(S[0])
    for j in range(3):
        if i & (1<<j):
            check += int(S[j+1])
        else:
            check -= int(S[j+1])
    if check == 7:
        ans = S[0]
        for j in range(3):
            if i & (1<<j):
                ans += '+' + S[j+1]
            else:
                ans += '-' + S[j+1]
        break

ans += '=7'

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		int sum = S.length()/2;
		int k = S.length();
		int ans = 0;
		for(int i = 0; i < sum; i++){
			k--;
			if(S.charAt(i) != S.charAt(k)){
				ans++;
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
}


Measured memory_bytes: 35320
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
string s;
int ss;
int main()
{
	cin>>s;
	bool flag=true;
	ss=s.size();
	rep2(i,1,ss)
	{
		if(s[i]!='9')flag=false;
	}
	if(flag)
	{
		cout<<(int)(s[0]-'0')+9*(ss-1)<<endl;
	}
	else
	{
		cout<<(int)(s[0]-'0')+9*(ss-1)-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	long long a,b,x;
	scanf("%lld %lld %lld", &a, &b, &x);

	long long a1 = a / x + 1;

	long long b1 = b / x + 1;

	long long ans = b1-a1;
	if(a%x==0) ans++;

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1001001001;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll memo[100000];
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
int main() {
    ll num[3][3];
    rep(i,3)
    rep(j,3)cin >> num[i][j];
    bool ans = true;
    rep(i,2){//横列
        if(num[i][0] - num[i + 1][0] != num[i][1] - num[i + 1][1] ||
            num[i][2] - num[i + 1][2] != num[i][1] - num[i + 1][1])ans = false;
    }
    rep(i,2){
        if(num[0][i] - num[0][i + 1] != num[1][i] - num[1][i + 1] ||
            num[2][i] - num[2][i + 1] != num[1][i] - num[1][i + 1])ans = false;
    }
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
N,Y=map(int, input().split())
f=False
for x in range(0, N + 1):
    for y in range(0, N + 1 -x):
        z=N-x-y
        if Y==10000*x + 5000*y + 1000*z :
            f=True
            break
    else:
        continue
    break

if f:
    print(x,y,z)
else:
    print("-1 -1 -1")

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

using namespace std;
int h[100005];
int dp[100005];

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

    dp[0] = 0;
    dp[1] = 0;
    for (int i = 2; i <= n; ++i) {
        for (int j = max(i - k, 1); j < i; ++j) { // i-k ~~~~~ i-1
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }

    }
    cout << dp[n] << endl;

    return 0;
}

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

using namespace std;

string a, b, c;
int i, j;


int main() {

	cin >> a >> b;

	if ( a.length() < b.length() ) {
		cout << "LESS" << endl;
	}else if (a.length() > b.length() ) {
		cout << "GREATER" << endl;
	}else if (a < b) {
		cout << "LESS" << endl;
	}else if(a > b) {
		cout << "GREATER" << endl;
	}else {
		cout << "EQUAL" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
  int N;
  cin>>N;
  int a=1;
  for(int i=0;i<N;i++){
    if(a*2<=N){
      a*=2;
    }
    else if(a>N){
      break;
    }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
// g++ -std=gnu++1y -O2 -I/opt/boost/gcc/include -L/opt/boost/gcc/lib -o ./a.out ./X.cpp & a.out //
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ull unsigned long long


using namespace std;

const ll INF = 1e18 + 7;

int main()
{
    ios_base::sync_with_stdio(false);	
    cin.tie(NULL); cout.tie(NULL);
    
    
    int N, W; cin >> N >> W;
    
    vector<int> w(N), v(N);
    
    int sum = 0;
    
    for(int i = 0; i<N; i++)
    { 
		int wn, vn; cin >> wn >> vn;
		v[i] = vn;
		w[i] = wn;
		sum += vn;
	}
	
    
    vector<ll> dp(sum + 1, INF);
    
    dp[0] = 0;
    
    for(int i = 0; i<N; i++)
    { 
		int vn = v[i];
		int wn = w[i];
		
		for(int val = sum-vn; val >= 0; --val)
		{
			dp[val+vn] = min(dp[val+vn], dp[val] + wn);
		}
		
	}
    
    ll ans = 0;
    
    for(ll i = 0; i < dp.size(); i++)
    {
		if(dp[i] <= W) ans = max(ans, i);
	}
	
	cout << ans << '\n';
		
    
    return 0;
}



Measured memory_bytes: 1024
from functools import reduce
def GCD(a:int , b: int) -> int:
    return a if b == 0 else GCD(b, a % b)
def LCM(a: int, b: int) -> int:
    return a * b // GCD(a, b)

n = int(input())
t = [int(input()) for _ in range(n)]

ans = reduce(LCM, t)

print(ans)


Measured memory_bytes: 3572
#include <stdio.h>
#include <unistd.h>

#define SIZE 2000000

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp, n;
  char com[21], buf[20];
  buf[19]='\n';
  char *p,*c1,*c2;
  c1 = com+1;
  c2 = com+2;
  do {
    fgets(com, 20, stdin);
    if (*com == 'i') {
      n = 0;
      p = com+7;
      while (*p!='\n') {
        n = n*10+*p-'0';
        p++;
      }
      A[++H] = n;
      for (i=H; i>1 && A[i>>1]<A[i];i>>=1) {
        tmp = A[i>>1];
        A[i>>1] = A[i];
        A[i] = tmp;
      }

    } else if (*c1=='x') { // extract
      n = A[1];
      for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
      write(1, buf+i+1, 19-i); //puts(buf+i+1);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i<<1;
        if (l < H && A[l] > A[i])        largest = l;
        else         largest = i;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (*c2!='d');
  return 0;
}


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

int n,back[105],la,MEMO[105];
multiset<int> edge[105];

int treediameter(void)
{
	int FAR=0,MA=0;
	for (int i = 0; i < n; ++i)
	{
		MEMO[i]=-1;
	}
	MEMO[0]=0;
	queue<int> que;
	que.push(0);
	while (!que.empty())
	{
		int now=que.front();que.pop();
		for (auto v:edge[now])
		{
			if (MEMO[v]==-1)
			{
				MEMO[v]=MEMO[now]+1;
				if (MEMO[v]>MA)
				{
					MA=MEMO[v];
					FAR=v;
				}
				que.push(v);
			}
		}
	}
	for (int i = 0; i < n; ++i)
	{
		MEMO[i]=-1;
	}
	int ans=0;
	MEMO[FAR]=0;
	queue<int> qu;
	qu.push(FAR);
	while (!qu.empty())
	{
		int now=qu.front();qu.pop();
		for (auto v:edge[now])
		{
			if (MEMO[v]==-1)
			{
				back[v]=now;
				MEMO[v]=MEMO[now]+1;
				if (ans<MEMO[now]+1)
				{
					la=v;
				}
				ans=max(ans,MEMO[v]);
				qu.push(v);
			}
		}
	}
	return ans;
}

int main(int argc, char const *argv[])
{
	cin>>n;
	int a,b;
	for (int i = 0; i < n-1; ++i)
	{
		cin>>a>>b;
		--a;--b;
		edge[a].insert(b);
		edge[b].insert(a);
	}
	int r=treediameter();
	if (r%2==0)
	{
		int o=la;
		while (MEMO[o]!=r/2)
		{
			o=back[o];
		}
		int memo[n]={},cnt[n]={};
		for (int i = 0; i < n; ++i)
		{
			memo[i]=-1;
		}
		queue<int> que;
		que.push(o);
		memo[o]=0;
		while (!que.empty())
		{
			int tmp=0,now=que.front();que.pop();
			for (auto v:edge[now])
			{
				if (memo[v]==-1)
				{
					memo[v]=memo[now]+1;
					++tmp;
					que.push(v);
				}
			}
			cnt[memo[now]]=max(cnt[memo[now]],tmp);
		}
		int ans1=r/2+1;
		long long ans2=1LL;
		for (int i = 0; i < ans1-1; ++i)
		{
			ans2*=(long long)cnt[i];
		}
		for (auto w:edge[o])
		{
			for (int i = 0; i < n; ++i)
			{
				memo[i]=-1;
				cnt[i]=0;
			}
			queue<int> qu;
			qu.push(o);
			qu.push(w);
			memo[o]=0;
			memo[w]=0;
			while (!qu.empty())
			{
				int tmp=0,now=qu.front();qu.pop();
				for (auto v:edge[now])
				{
					if (memo[v]==-1)
					{
						memo[v]=memo[now]+1;
						++tmp;
						qu.push(v);
					}
				}
				cnt[memo[now]]=max(cnt[memo[now]],tmp);
			}
			long long nans=2LL;
			for (int i = 0; i < ans1-1; ++i)
			{
				nans*=(long long)cnt[i];
			}
			ans2=min(ans2,nans);
		}
		cout<<ans1<<" "<<ans2<<endl;
	}
	else
	{
		int o=la;
		while (MEMO[o]!=r/2+1)
		{
			o=back[o];
		}
		int memo[n]={},cnt[n]={};
		for (int i = 0; i < n; ++i)
		{
			memo[i]=-1;
		}
		queue<int> que;
		que.push(o);
		que.push(back[o]);
		memo[o]=0;
		memo[back[o]]=0;
		while (!que.empty())
		{
			int tmp=0,now=que.front();que.pop();
			for (auto v:edge[now])
			{
				if (memo[v]==-1)
				{
					memo[v]=memo[now]+1;
					++tmp;
					que.push(v);
				}
			}
			cnt[memo[now]]=max(cnt[memo[now]],tmp);
		}
		int ans1=r/2+1;
		long long ans2=2LL;
		for (int i = 0; i < ans1-1; ++i)
		{
			ans2*=(long long)cnt[i];
		}
		cout<<ans1<<" "<<ans2<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, v[100002];
int winn(int turn)
{
    int odd = 0, even = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(v[i] % 2 == 0)
            ++even;
        else
            if(v[i] == 1)
                ++odd;
    }
    if(even % 2 == 1)
        return turn;
    if(even < n - 1)
        return 3 - turn;
    if(odd)
        return 3 - turn;
    for(int i = 1; i <= n; ++i)
        if(v[i] % 2 == 1)
            --v[i];
    int cmm = v[1];
    for(int i = 1; i <= n; ++i)
        cmm = __gcd(cmm, v[i]);
    for(int i = 1; i <= n; ++i)
        v[i] /= cmm;
    return winn(3 - turn);
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    int tu = winn(1);
    if(tu == 1)
        cout << "First";
    else
        cout << "Second";
    return 0;
}

Measured memory_bytes: 640
from collections import Counter
n,m = (int(x) for x in input().split())
a = list(map(int, input().split()))
s = [0]*(n+1)
for i in range(1,n+1):
  s[i] = (s[i-1] + a[i-1])%m

cl = Counter(s).values()
ans = sum(i*(i-1)//2 for i in cl)
print(ans)




Measured memory_bytes: 16556