akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <algorithm>
#define INF 5000

using namespace std;
typedef pair<int, int> P;

char **s;
int **dis;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

int main(int argc, char const* argv[])
{
	int h, w;
	cin >> h >> w;
	s = new char*[h];
	dis = new int*[h];
	int white = 0;
	for(int i = 0; i < h; i++){
			s[i] = new char[w];
			dis[i] = new int[w];
			for(int j = 0; j < w; j++){
					cin >> s[i][j];
					if(s[i][j] == '.')white++;
					dis[i][j] = INF;
			}
	}
	queue<P> q;
	q.push(make_pair(0, 0));
	dis[0][0] = 0;
	while(!q.empty()){
			P p = q.front(); q.pop();
			int px = p.second;
			int py = p.first;
			if(px == w - 1 && py == h - 1){
					cout << white - dis[py][px] - 1 << endl;
					return 0;
			}
			for(int i = 0; i < 4; i++){
					int cx = px + dx[i];
					int cy = py + dy[i];
					if(cx >= 0 && cx < w && cy >= 0 && cy < h && s[cy][cx] == '.'){
							if(dis[cy][cx] == INF){
									q.push(make_pair(cy, cx));
									dis[cy][cx] = dis[py][px] + 1;
							}
					}
			}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
li = list(map(int,input().split()))
lie = [i for i in li if i % 2 == 0]
for i in range(len(lie)):
    if lie[i] % 3 == 0 or lie[i] % 5 == 0:
        pass
    else :
        print("DENIED")
        exit()
print("APPROVED")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR0(i, n) for (int i = 0; i < n; i++)
#define FOR1(i, n) for (int i = 1; i <= n; i++)
#define FORl(i, l, n) for (int i = l; i < n; i++)
using namespace std;
#define pi pair<ll, ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x, 0, sizeof(x));
#define vi vector<ll>
#define sync                      \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);                   \
	cout.tie(0);
#define endl '\n'
#define sp << " " <<
#define intmax 1e14
ll mod = 1e9 + 7;

ll power(ll num, ll g, ll mod)
{
	if (g == 0)
		return 1;
	if (g % 2 == 1)
		return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power((num * num) % mod, g / 2, mod);
}

ll a[10000001];
int main() {
    ll n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		for(int j = 1; i*j <= n; j++){
			a[i*j]++;
		}
	}
	ll sum = 0;
	for(int i = 1; i <= n; i++){
		sum += a[i]*i;
	}
	cout << sum << endl;
}

Measured memory_bytes: 81748
n = int(input())

if n == 10 ** 5:
    print(90909)
elif n >= 10 ** 4:
    print(n - 10 ** 4 + 909 + 1)
elif n >= 10 ** 3:
    print(909)
elif n >= 10 ** 2:
    print(n - 10 ** 2 + 9 + 1)
elif n >= 10:
    print(9)
else:
    print(n)

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if (abs(a-b)>abs(a-c)) {
        if (abs(a-c)<=d) {
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }else{
        if (abs(a-b)<=d) {
            if (abs(b-c)<=d) {
                cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}

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

int main(void){

  int n,num[3],min,cnt=0,kouyaku[50000];
  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> num[i];
  }

  sort(num,num+n);

  min = num[0];

  for(int i = 1; i <= sqrt(min); i++){
    if(min % i == 0){
      kouyaku[cnt] = i;
      cnt++;
      if(i != min / i ){
      kouyaku[cnt] = min / i;
      cnt++;
      }
    }
  }

  sort(kouyaku,kouyaku+cnt);
  
  if(n == 3){
    for(int i = 0;i < cnt; i++){
      if(num[1] % kouyaku[i] == 0 && num[2] % kouyaku[i] == 0){
	cout << kouyaku[i] << endl;
      }
    }
  }else{
    for(int i = 0;i < cnt; i++){
      if(num[1] % kouyaku[i] == 0){
	cout << kouyaku[i] << endl;
      }    
    }
  }
  
  return 0;
}

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


int main()
{
    int A,B,C;
    int count5=0;
    int count7=0;
    cin>>A>>B>>C;

    if(A==7)
    {
        count7+=1;
    }
    else if(A==5)
    {
        count5+=1;
    }

    if(B==7)
    {
        count7+=1;
    }
    else if(B==5)
    {
        count5+=1;
    }

    if(C==7)
    {
        count7+=1;
    }
    else if(C==5)
    {
        count5+=1;
    }

    if(count7==1 && count5==2)
    {
        puts("YES");
    }else{
        puts("NO");
    }
    return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int length = sc.nextInt();
        final int[] numbers = new int[length];

        for (int i = 0; i < length; i++) {
            numbers[i] = sc.nextInt();
        }

        output(numbers);

        for (int i = 1; i < length; i++) {
            final int temp = numbers[i];

            int j;
            for (j = i - 1; j >= 0 && numbers[j] > temp; j--) {
                numbers[j + 1] = numbers[j];
            }
            numbers[j + 1] = temp;
            output(numbers);
        }

        sc.close();
    }

    public static void output(int[] numbers) {
        int i;
        for (i = 0; i < numbers.length - 1; i++) {
            System.out.print(numbers[i] + " ");
        }
        System.out.println(numbers[i]);
    }

}



Measured memory_bytes: 32868
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int n;
map<string, int> m;

int main() {
    cin >> n;
    rep(i, n) {
        string s;
        cin >> s;
        m[s]++;
    }
    
    int maxv = -1;
    for(const auto& x : m) {
        int value = x.second;
        if(value > maxv) maxv = value;
    }
    for(auto i = m.begin(); i != m.end(); i++) {
        if(i->second == maxv) {
            cout << i->first << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  if(a * b % 2 == 0)
  {
    cout << "Even" << endl;
  }
  else
  {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 3492
#include <iostream>
#include <algorithm>
using namespace  std;
int rg[200005] = { 0 };
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> rg[i];
	}
	sort(rg + 1, rg + n + 1);
	long long ans = 0;
	for (int i = 1; i <= n-k; i++) {
		ans += rg[i];
	}
	//ans += k;
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, lk[maxn + 10], vis[maxn + 10], clk;
int l[maxn + 10], r[maxn + 10];
vector<int> g[maxn + 10];

bool dfs(int p) {
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		if (vis[e] != clk) {
			vis[e] = clk;
			if (!lk[e] || dfs(lk[e])) {
				lk[e] = p; return 1;
			}
		}
	}
	return 0;
}

void getans(int p, int lst) {
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		if (e != lst && vis[e] != clk) {
			vis[e] = clk;
			l[e] = p; r[e] = lk[e];
			getans(lk[e], e);
		}
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int k; scanf("%d", &k);
		while (k--) {
			int x; scanf("%d", &x);
			g[x].push_back(i);
		}
	}
	for (int i = 1; i <= n; ++i)
		random_shuffle(g[i].begin(), g[i].end());
	for (int i = 1; i < n; ++i) {
		++clk;
		if (!dfs(i)) {
			printf("-1"); return 0;
		}
	}
	++clk;
	getans(n, 0); 
	for (int i = 1; i < n; ++i)
		if (!l[i]) {
			printf("-1"); return 0;
		}
	for (int i = 1; i < n; ++i)
		printf("%d %d\n", l[i], r[i]);
}


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

string s;
int total,i;

int main(){
	ios_base::sync_with_stdio(false);

	cin>>s;
	total=0;

	for(i=0;i<s.length();i++){
		if(i%2==0){
			if(s[i]=='R' || s[i]=='U' || s[i]=='D')total++;
		}
		else{
			if(s[i]=='L' || s[i]=='U' || s[i]=='D')total++;
		}
	}	
	if(total==s.length())cout<<"Yes\n";
	else cout<<"No\n";
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
dp = [[0,0] for i in range(1<<n)]
def merge(ls1,ls2):
  p,q = ls1
  r,s = ls2
  ret = [max(p,r)]
  if p>r:
    ret.append(max(q,r))
  else:
    ret.append(max(p,s))
  return ret
for i in range(1<<n):
  dp[i][0] = a[i]
for i in range(n):
  for j in range(1<<n):
    if 1<<i & j:
      dp[j] = merge(dp[j],dp[1<<i^j])
ans = [0 for i in range(2**n)]
for i in range(1,1<<n):
  ans[i] = max(ans[i-1],sum(dp[i]))
for i in ans:
  if i:
    print(i)

Measured memory_bytes: 160880
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s,t = input().split()
res = ''
for i in range(n):
    res += s[i] + t[i]
print(res)

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

using namespace std;

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

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

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

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

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

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

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

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

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

using State = string::const_iterator;

ll number(State &begin) {
    ll num = 0, tmp = 1;
    while ('0' <= *begin and *begin <= '9') {
        (num += (*begin - '0') * tmp) %= MOD;
        (tmp *= 10) %= MOD;
        ++begin;
    }
    return num;
}

ll expression(State& begin);

ll term(State &begin) {
    if (*begin == '>') {
        ++begin;
        ll exp = expression(begin);
        assert(*begin == '<');
        ++begin;
        assert(*begin == 'S');
        ++begin;
        return (exp * exp) % MOD;
    }
    assert('0' <= *begin and *begin <= '9');
    return number(begin);
}

ll expression(State& begin) {
    vll result;
    result.push_back(term(begin));
    while (*begin == '>') {
        ++begin;
        assert(*begin == '>');
        ++begin;
        result.push_back(term(begin));
    }
    reverse(all(result));
    ll ret = result[0];
    REP(i, SZ(result)-1) {
        ret >>= min(result[i+1], 60LL);
    }
    return ret;
}

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

    for (;;) {
        string s; getline(cin, s);
        if (s == "#") break;

        string t;
        for (char c : s) {
            if (c != ' ') t += c;
        }

        reverse(all(t));
        State begin = t.begin();
        ll ans = expression(begin);
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 6568
#include<iostream>
#include<cstring>
#include<cstring>
#include<stdlib.h>
using namespace std;
#include<algorithm>
long long a[100005];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)	
		cin>>a[i];
	sort(a+1,a+n+1);
	int k1=1,k2;
	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
			{
				k1=(k1+1)%2;
			}
		else
			k2+=k1,k1=1;
	}
	if(k1==1)
		k2++;
	cout<<k2<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int main() {

   int N,M;
   cin >> N >> M;
   vector<int> ans(N+1);
   REP(i,N) ans[i+1] = 0;

   REP(i,M) {
      int a,b; cin >> a >> b;
      ans[a]++;
      ans[b]++;
   }

   for(int i=1;i<=N;i++) {
      cout << ans[i] << endl;
   }

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr ll mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    mint two = 2;
    mint tinv = two.inv();
    vec<int> degX(N,0),degY(N,0);
    set<Pa<int,int>> X,Y;
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        degX[--a]++; degX[--b]++;
        X.insert(minmax({a,b}));
    }
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        degY[--a]++; degY[--b]++;
        Y.insert(minmax({a,b}));
    }
    mint ans = tinv.pow(2)*N*(N-1);
    mint cnt = 0;
    for(auto& e:X){
        int a = e.first,b = e.second;
        ll c = N-1-degY[a]-degY[b]+(Y.count(e));
        cnt += c;
    }
    ans += tinv.pow(4)*cnt;
    cnt = 0;
    for(int i=0;i<N;i++){
        cnt += N-1-degY[i];
        cnt += N-1-degX[i];
    }
    ans -= tinv.pow(3)*cnt;
    cout << ans << "\n";
}


Measured memory_bytes: 23168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

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

    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int le=1;le<n;le++){
        int ri=le+k-1;
        if(ri>=n)break;
        if(a[le-1]<a[ri])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 4428
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll X,Y,Z;cin >> X >> Y >>  Z;
    cout << (X-Z)/(Y+Z) <<endl;
}

Measured memory_bytes: 504
#include <iostream>
using namespace std;
int main() {
  int a, b;

  scanf("%d%d", &a, &b);

  int ans = 0;

  if ((a % 2 == 0)||(b % 2 == 0)) {
    
    printf("Even");
  }
  else {
    printf("Odd");
  }

  return 0;
}

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

namespace ABC128 {
	class Program {
		static void Main(string[] args) {
			// 入力
			int N; // スイッチの数
			int M; // 電球の数
			int[] firstArray = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
			N = firstArray[0];
			M = firstArray[1];
			int[, ] s = new int[M, N]; // 電球にささっているスイッチの番号(0:刺さっていない 1:ささっている)
			for (int i = 0; i < M; i++) {
				for (int j = 0; j < N; j++) {
					s[i, j] = 0;
				}
			}
			for (int i = 0; i < M; i++) {
				int[] array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
				for (int j = 0; j < array[0]; j++) {
					s[i, array[j + 1] - 1] = 1;
				}
			}
			int[] p = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
			// 処理・出力
			// 全探索するとO(N*M*2^N)、M,N<=10である。10^5程度に収まるしそれでいいのでは？
			// int値にスイッチの状態を格納すると、インクリメントだけで次の状態を調べられる。
			Int32 switchState = 0; // N個のスイッチの状態を格納している
			Int32[] judge = new int[N];
			judge[0] = 1;
			for (int i = 1; i < N; i++) {
				judge[i] = judge[i - 1] * 2;
			}
			int stateCount = 1; // 状態の数
			for (int i = 0; i < N; i++) {
				stateCount *= 2;
			}
			int answer = 0;
			for (switchState = 0; switchState < stateCount; switchState++) {
				bool allLight = true;
				// 各電球がつくかを調べる
				for (int i = 0; i < M; i++) {
					int count = 0; // スイッチのONの個数
					// つながっているスイッチの個数を調べる
					for (int j = 0; j < N; j++) {
						if (s[i, j] == 0) {
							// 刺さっていないスイッチは無視
							continue;
						}
						if ((switchState & judge[j]) != 0) {
							// ONならcountを増加
							count++;
						}
					}
					// 付くかの判定
					if (count % 2 != p[i]) {
						// Mの電球が付いていないなら、この状態では全ての電球がつくことはない
						allLight = false;
						break;
					}
				}
				// 全て付いている場合は場合の数を+1
				if (allLight) {
					answer++;
				}
			}
			// 出力
			Console.WriteLine(answer);
		}
	}
}

Measured memory_bytes: 11220
#include <iostream>
#include <stdio.h>

using namespace std;

int m,cn[8],ck[8],an[10000];

void cal(int s,int k) {
	int i;
	if (k==m) return;
	for (i=0;i<=ck[k];i++) {
		if (i>0) an[s+i*cn[k]]++;
		cal(s+i*cn[k],k+1);}
}

int main() {
 int i,g,n;
 while(cin >> m) {
	 if (m==0) break;
	 for (i=0;i<m;i++) cin >> cn[i] >> ck[i];
     for (i=0;i<10000;i++) an[i]=0;
	 cal(0,0);
	 cin >> g;
	 for (i=0;i<g;i++) { cin >> n; cout << an[n] << endl; }
 }
return 0;
 }

Measured memory_bytes: 1200
#include<cstdio>


using namespace std;

int A[200000];
int N;

int main() {
    scanf("%d", &N);
    for(int i = 0; i < N; ++i) {
        scanf("%d", A+i);
    }
    if(A[0] != 0) {
        printf("-1\n");
        return 0;
    }
    for(int i = 1; i < N; ++i) {
        if(A[i-1]+1 < A[i]) { // 2以上増やすことはできない
            printf("-1\n");
            return 0;
        }
    }

    long long int num = 0;
    int cur = 0;
    for(int i = N-1; i >= 0; --i) {
        if(cur < A[i]) {
            num += A[i];
            cur = A[i];
        }
        --cur;
    }
    printf("%lld\n", num);
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
#define f(x,y,z) for(int x=(y),__=(z);x<=__;++x)
typedef long long ll;
#define v64 vector<ll>
//dp[i][j]：到第i个，j==1：选择此个，j==0：不选择此个，到此共选择了i/2个，得到的最大值。
/* 转移方程：
 
i为奇数时
选择(i-1)/2个 
dp[i][1]= arr[i]+max{dp[i-2][0],dp[i-2][1],dp[i-3][1],dp[i-3][0]}

dp[i][0]= max{dp[i-2][0]+arr[i-1],dp[i-3][1]+arr[i-1],dp[i-3][0]+arr[i-2],dp[i-3][0]+arr[i-1]} 
i为偶数时

*/ 
ll dp[maxn][2];
int main(){
	int n;
	scanf("%d",&n);
	v64 arr(n+1,0);
	f(i,1,n)
		cin >> arr[i];
	dp[2][1]=arr[2];
	dp[2][0]=arr[1];
	f(i,3,n){
		if(i&1){
			ll tmp=max({dp[i-3][1],dp[i-3][0],dp[i-2][0],dp[i-2][1]}); 
			dp[i][1]=arr[i]+tmp;
			dp[i][0]=max(arr[i-2]+dp[i-3][0],arr[i-1]+dp[i-2][0]);
		}
		else{
			dp[i][1]=arr[i]+dp[i-1][0];
			dp[i][0]=arr[i-1]+dp[i-2][0];
		}
	}
	printf("%lld\n",max(dp[n][1],dp[n][0]));
}

Measured memory_bytes: 8072
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
  int n;
  cin >> n;
  cout << (1 + n) * n / 2 << endl;
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    map<char,int> m;
    for(int i=0;i<s.size();i++){
        m[s[i]]++;
    }
    for(char i='a';i<='z';i++){
        if(m[i]==0){
            cout << i << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

bool know[12][12];


bool match(const vector<int>& lhs, const vector<int>& rhs)
{
    if (lhs.size() != rhs.size()) return false;
    rep(i, lhs.size()) {
        if (lhs[i] != rhs[i]) return false;
    }
    return true;
}

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

    int n;
    cin >> n;
    vector<int> p(n), q(n), t(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    rep(i, n) t[i] = i+1;

    int pOrd = -1;
    int qOrd = -1;
    int ord = 0;
    do {
        if (pOrd < 0 && match(p, t)) pOrd = ord;
        if (qOrd < 0 && match(q, t)) qOrd = ord;
        ++ord;
    } while ((pOrd < 0 || qOrd < 0) && next_permutation(t.begin(), t.end()));

    cout << abs(pOrd - qOrd) << endl;

    return 0;
}


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

int main() {
    int N;
    string S;
    cin >> N >> S;

    rep(i, S.size()) {
        char s = S[i];
        s += N;
        if (s > 'Z') s -= 'Z' - 'A' + 1;
        cout << s;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define ve vector
const int mod = 1000000007;
int main(){
    int n,m;
    cin >> n >> m;
    ve<int> s(n), t(m);
    rep(i,n) cin >> s[i];
    rep(i,m) cin >> t[i];
    ve<ve<ll>> dp0(n+3,ve<ll>(m+3));
    ve<ve<ll>> dp1(n+3,ve<ll>(m+3));

    dp0[0][0] = 1;

    for(int i = 0; i <= n+1; i++){
        for(int j = 0; j <= m+1; j++){
            (dp0[i+1][j] += dp0[i][j]) %=mod;
            (dp1[i][j] += dp0[i][j]) %= mod;
            (dp1[i][j+1] += dp1[i][j]) %= mod;
            if(s[i] == t[j]){
                (dp0[i+1][j+1] += dp1[i][j]) %= mod;
            }
        }
    }
    cout << dp1[n][m] << endl;
    return 0;
}

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

int main(){
  int X;
  cin >> X;
  if(X==2){
    cout << X << endl;
    return 0;
  }
  while(1){
    bool flag = true;
    if(X%2==0){
      X++;
      flag = false;
      continue;
    }
    for(int i=3; i<=sqrt(X); i+=2){
      if(X%i==0){
        X++;
        flag = false;
        break;
      }
    }
    if(flag) break;
  }
  cout << X << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

#define MOD (1000000007)

ll c[2001][2001];

int main()
{
	int N, K;
	ll ans, blue_div, red_div;

	repc(n, 0, 2000) {
		repc(r, 0, n) {
			if (r == 0 || r == n) c[n][r] = 1;
			else {
				c[n][r] = (c[n - 1][r - 1] + c[n - 1][r]) % MOD;
			}
		}
	}

	cin >> N >> K;

	repc(i, 1, K) {
		ans = 1;

		blue_div = c[K - 1][i - 1];
		red_div = c[N - K + 1][i];

		ans = (blue_div * red_div) % MOD;

		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 30080
#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)};
int main(void){
  int N, M, X;
  cin >> N >> M >> X;
  vector <int> A(N);
  rep(i,M) cin >> A[i];


  int left = 0;
  for (int i = 0; i < M; i++){
    if (A[i] < X) left ++;
  }

  int right = 0;
  for (int i = 0; i < M; i++){
    if (A[i] > X) right ++;
  }

  cout << min(left, right) << endl;
}


Measured memory_bytes: 3616
//by OIerC
//Forca Barcelona!
#include<cstdio>
#include<algorithm>
using namespace std;

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 2e3 + 5;

int a[N][N], b[N][N], left[N][N], right[N][N], up[N][N];
char s[N];

int main()
{
	int n = read();
	int m = read();
	int ans = max(n, m);
	
	for (int i = 1; i <= n; ++i)
	{
		scanf("%s", s + 1);
		for (int j = 1; j <= m; ++j)
			if (s[j] == '#') a[i][j] = 1;		
	}
	/*
	if (n == 2 && m == 2)
	{
		if ((a[1][1] + a[1][2] + a[2][1] + a[2][2]) % 2 == 0)
			printf("4\n");
		else
			printf("2\n");
		return 0;
	}
	*/
	for (int i = 1; i < n; ++i)
		for (int j = 1; j < m; ++j)
			if ((a[i][j] + a[i][j + 1] 
			+ a[i + 1][j] + a[i + 1][j + 1]) % 2 == 0)
			{
				b[i][j] = 1;
				left[i][j] = j;
				right[i][j] = j;
				up[i][j] = 1;
			}
	--n;
	--m;
	
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 2; j <= m; ++j)
			if (b[i][j] == b[i][j - 1] && b[i][j])
				left[i][j] = left[i][j - 1];
		
		for (int j = m - 1; j >= 1; --j)
			if (b[i][j] == b[i][j + 1] && b[i][j])
				right[i][j] = right[i][j + 1];
	}
	
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
		{
			if (i > 1 && b[i][j] == b[i - 1][j] && b[i][j])
			{
				left[i][j] = max(left[i][j], left[i - 1][j]);
				right[i][j] = min(right[i][j], right[i - 1][j]);
				up[i][j] = up[i - 1][j] + 1;
			}
			
			int x = right[i][j] - left[i][j] + 1;
			int y = up[i][j];
			
			ans = max(ans, (x + 1) * (y + 1));
		}
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 78592
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N;
vi G[101010];

int f(int idx, int par) {
    int ret = 0;
    for (auto& nxt : G[idx]) {
        if (nxt != par) {
            ret ^= (f(nxt, idx) + 1);
        }
    }
    return ret;
}

void solve() {
    if (f(0, -1))
        cout << "Alice" << endl;
    else
        cout << "Bob" << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].eb(b);
        G[b].eb(a);
    }


    solve();
    return 0;
}


Measured memory_bytes: 10496
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;

int main() {
	int n;
	char str[10], com[13];
	map<string, bool>T;

	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%s%s", com, str);
		if (com[0] == 'i')T[string(str)] = true;
		else {
			if (T[string(str)])printf("yes\n");
			else printf("no\n");
		}
	}

	return 0;
}

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

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

int main(){
    int A[3][3];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    int b[N];
    for(int i = 0; i < N; i++){
        cin >> b[i];
    }

    int checker[3][3] = {0};
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < N; k++){
                if(b[k] == A[i][j]){
                    checker[i][j] = 1;
                    break;
                }
            }
        }
    }

    bool is_bingo = false;

    for(int i = 0; i < 3; i++){
        int sum_yoko = 0;
        int sum_tate = 0;
        for(int j = 0; j < 3; j++){
            sum_yoko += checker[i][j];
            sum_tate += checker[j][i];
        }

        if(sum_yoko == 3 || sum_tate == 3){
            is_bingo = true;
            break;
        }
    }

    if(checker[0][0] + checker[1][1] + checker[2][2] == 3 ||
    checker[0][2] + checker[1][1] + checker[2][0] == 3){
        is_bingo = true;
    }

    if(is_bingo){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*mokosucio's file*/
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define fs first
#define sc second
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+5; 

const double PI =  3.141592653589793;

int main(){
	IO;
	ll n,a;
	cin>>n;
	ll r [n];
	memset(r,0,sizeof(r));
	forn(i,n-1){
		cin>>a;
		r[a-1]++;
	}
	forn(i,n){
		cout<<r[i]<<"\n";
	}
	return 0;
}



Measured memory_bytes: 5204
#include<iostream>
#include<string>
#include<vector>

using namespace std;

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

	string tarou, hanako;
	int score_ta = 0, score_ha = 0;

	for (int i = 0; i < n; i++) {
		cin >> tarou >> hanako;

		int maxlength = tarou.length() < hanako.length() ? tarou.length() : hanako.length();

		for (int j = 0; j < maxlength; j++) {
			if (tarou[j] > hanako[j]) {
				score_ta += 3;
				break;
			}
			else if (tarou[j] < hanako[j]) {
				score_ha += 3;
				break;
			}
			else if (tarou[j] == hanako[j]) {
				if (j == maxlength - 1 && tarou.length() == hanako.length()) {
					score_ta++;
					score_ha++;
					break;
				}
				else if(j == maxlength - 1 && tarou.length() > hanako.length()) {
					score_ta += 3;
					break;
				}
				else if (j == maxlength - 1 && tarou.length() < hanako.length()) {
					score_ha += 3;
					break;
				}
			}
		}
	}

	cout << score_ta << " " << score_ha << "\n";
}

Measured memory_bytes: 1204
// ABC173C - H and V

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

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	int H, W, K;
	cin >> H >> W >> K;
	char m[H][W];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char t;
			cin >> t;
			m[i][j] = t;
		}
	}

	int ans = 0;
	char temp[H][W];
	for (int i = 0; i < (1 << H); i++) {
		for (int j = 0; j < (1 << W); j++) {
			memcpy(temp, m, sizeof(m));
			for (int i2 = 0; i2 < H; i2++) {
				if ((i & (1<<i2)) != 0) {
					for (int j2 = 0; j2 < W; j2++) {
						temp[i2][j2] = '.';
					}
				}
			}
			for (int j2 = 0; j2 < W; j2++) {
				if ((j & (1<<j2)) != 0) {
					for (int i2 = 0; i2 < H; i2++) {
						temp[i2][j2] = '.';
					}
				}
			}
			int temp_count = 0;
			for (int i2 = 0; i2 < H; i2++) {
				for (int j2 = 0; j2 < W; j2++) {
//					cout << temp[i2][j2];
					if (temp[i2][j2] == '#') {
						++temp_count;
					}
				}
//				cout << endl;
			}
			if (temp_count == K) {
				++ans;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

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; }
const ll INF = 1LL << 60;

//---main---------------------------------------------
int main(){
    //main
    int H,W,K;
    cin >> H >> W >> K;
    vector<vector<int>> M(H, vector<int>(W,0));
    vector<vector<int>> Mt(H, vector<int>(W,0));

    char Mij;
    rep(i,H) rep(j,W){
        cin >> Mij;
        if(Mij == '#') M[i][j] = 1;
    }


    /*
    rep(i,H){
        rep(j,W-1) cout << M[i][j] ;
        cout << M[i][W-1] << endl;
    }
    */

    int ans = 0;
    rep(ci,int(pow(2,H)+0.5)){
        rep(cj,int(pow(2,W)+0.5)){
            int Bk = 0;
            rep(i,H) rep(j,W){
                // ci%2^i == 1 ならi行目はカウントしない
                if((ci % int(pow(2,i+1)+0.5))/int(pow(2,i)+0.5)==0){
                    if((cj % int(pow(2,j+1)+0.5))/int(pow(2,j)+0.5)==0){
                        Bk += M[i][j];
                    }
                }
            }
            if(Bk == K) ans ++;
            //cout << ci << " " << cj << " " << Bk << endl;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4092
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
#define all(x) x.begin(),x.end()
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int n;cin>>n;
    int dp[114514][3];
    rep(i,0,n+1)rep(j,0,3)dp[i][j]=-1;
    rep(i,0,3)dp[0][i]=0;
    int h[3];
    rep(i,1,n+1){
        rep(j,0,3)cin>>h[j];
        rep(j,0,3)rep(k,0,3){
            if(j==k)continue;
            dp[i][j]=max(dp[i][j],dp[i-1][k]+h[j]);
        }
    }
    int ans=-1;
    rep(i,0,3)ans=max(ans,dp[n][i]);
    cout<<ans<<endl;return 0;
}

Measured memory_bytes: 2816
def main():
    M1, D1  = list(map(int, input().split()))
    M2, D2  = list(map(int, input().split()))

    if D2 == 1 and M1 != M2:
        print(1)
    else:
        print(0)
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
ll int large=(ll int)1e18;
ll int mod=(ll int)1e9+7;
ll int const N=(ll int)1e6+10;


ll int mod_exp(ll int x,ll int n)
{
    ll int result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n=n/2;
    }
    return result;
}

ll int mod_inverse(ll int a)
{
    return mod_exp(a,mod-2);
}

ll int const sz=N;
 ll int seive[sz];


int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll int T,i,j,ij;
T=1;
//cin>>T;
while(T--)
{
  ll int n;
  cin>>n;
  ll int a[n];
  rep(i,0,n)
  cin>>a[i];

  ll int num1=count(a,a+n,1);
  if(num1>1)
  {
      cout<<0;
  }
  else if(num1==1)
  {
      cout<<1;
  }
  else
  {
     for(ll int i=0;i<n;i++)
     {
         for(ll int j=a[i];j<sz;j+=a[i])
            seive[j]++;
     }
     ll int ans=0;
     rep(i,0,n)
     {
         if(seive[a[i]]==1)
            ans++;
     }

     cout<<ans<<endl;
  }


}
return 0;
}










Measured memory_bytes: 12940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	const int mod = 1e9 + 7;
	int n, q; cin >> n >> q;
	vi a(n), x(q), y(q); rep(i, n) cin >> a[i];
	rep(i, q) cin >> x[i] >> y[i];
	
	vi dp(n * n), last(n * n);
	vi two(q + 1, 1);
	rep(i, q) two[i + 1] = two[i] * 2 % mod;
	
	auto get = [&](int i, int k){
		dp[i] = dp[i] * (ll)two[k - last[i]] % mod;
		last[i] = k + 1;
		return dp[i];
	};
	auto update = [&](int a, int b, int c, int d, int k){
		int v1 = get(a * n + b, k);
		int v2 = get(c * n + d, k);
		(dp[a * n + b] += v2) %= mod;
		(dp[c * n + d] += v1) %= mod;
	};
	
	rep(i, n) rep(j, n) if(a[i] < a[j]) dp[i * n + j] = 1;
	rep(k, q){
		int l = x[k] - 1, r = y[k] - 1;
		rep(i, n) if(i != l && i != r){
			//(l, i) <=> (r, i)
			update(l, i, r, i, k);
			//(i, l) <=> (i, r)
			update(i, l, i, r, k);
		}
		update(l, r, r, l, k);
	}
	ll ans = 0;
	rep(i, n) rep(j, i) ans += get(i * n + j, q);
	cout << ans % mod << endl;
	return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <algorithm>
#include <vector>


using namespace std;
 
bool canTriangle(int a, int b, int c){
    return (a < b + c);
}
int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    int ans = 0;
    for(int i = 0; i < n; i++) cin >> l[i];
    std::sort(l.begin(), l.end(),std::greater<int>());
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if(l[i] >= l[j] + l[k]) break;
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
h, w, k = gets.split.map(&:to_i)
field = h.times.map {gets.chomp.chars}
 
num = 0
 
(1..h).each do |y_num|
  field.combination(y_num) do |rows|
    tmp = rows.transpose.map(&:join)
    (0..tmp.size).each do |x_num|
      tmp.combination(x_num) do |cols|
        co = cols.map {_1.count("#")}.sum
        num += 1 if co == k
      end
    end
  end
end
 
puts num

Measured memory_bytes: 14364
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, T; 
  cin >> N >> T;

  vector<int> A(N), B(N);
  REP(i, N) cin >> A[i] >> B[i];

  vector<int> o(N);
  iota(ALL(o), 0);
  sort(ALL(o), [&](int const & l, int const & r){
      return A[l] < A[r];
      });

  vector<vector<int>> dp(N+1, vector<int>(6010, -INF));
  dp[0][0] = 0;

  REP(i, N) REP(j, T){
    int I = o[i];
    chmax(dp[i+1][j], dp[i][j]);
    chmax(dp[i+1][j+A[I]], dp[i][j]+B[I]);
  }

  int ans = 0;
  REP(i, N+1) REP(j, 6010){
    chmax(ans, dp[i][j]);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 141440
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};
use std::collections::HashSet;

fn divisors(N: i64) -> HashSet<i64> {
  let mut ds = vec![];
  let mut d = 1;
  while d * d <= N {
    if N % d == 0 {
      ds.push(d);
      ds.push(N / d);
    }
    d += 1;
  }
  let uniq: HashSet<i64> = ds.into_iter().collect();
  uniq
}

fn main() {
    let s: String = read();
    let s_char: Vec<char> = s.chars().collect();
    let s_len = s_char.len();
    let mut ans: i64 = 0;

    for i in 0..s_len {
       for j in i..s_len {
           if ['A', 'C', 'G', 'T'].contains(&s_char[j as usize]) {
                ans = max(ans, (j-i +1) as i64);
                continue;
           }
           break;
       } 
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!long);
    auto A = s[0];
    auto B = s[1];

    long[] X, Y;
    bool[long] st;
    long aa = A, bb = B;

    for (long a = 1; a * a <= aa; a++) {
        if (aa % a == 0) {
            X ~= a;
            while (a != 1 && aa % a == 0)
                aa /= a;
        }
    }

    if (aa > 1) X ~= aa;


    for (long a = 1; a * a <= bb; a++) {
        if (bb % a == 0) {
            Y ~= a;
            while (a != 1 && bb % a == 0)
                bb /= a;
        }
    }

    if (bb > 1) Y ~= bb;

    foreach (a; X) if (A % a == 0 && B % a == 0) st[a] = true;
    foreach (a; Y) if (A % a == 0 && B % a == 0) st[a] = true;

    auto C = st.keys.array;
    int M = C.length.to!int;
    long ans = 1;

    foreach (mask; 0..(1<<M)) {
        long[] lst;
        foreach (i; 0..M) {
            if (mask & (1 << i)) lst ~= C[i];
        }
        bool ok = true;
        foreach (i; 0..M) {
            foreach (j; i+1..M) {
                if (gcd(C[i], C[j]) != 1) {
                    ok = false;
                    break;
                }
            }
            if (!ok) break;
        }
        if (ok) ans = max(ans, mask.popcnt);
    }

    ans.writeln;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> list(n);
    for(int i=0; i<n; i++){
        cin >> list.at(i);
    }
    vector<int> dis_sum_list(100);
    for(int p=0; p<100; p++){
        int dis_sum = 0;
        for(int i=0; i<n; i++){
            dis_sum += pow(list.at(i) - p-1, 2);
        }
        dis_sum_list.at(p) = dis_sum;
    }

    int m=1000000;
    for(int i=0; i<100; i++){
        if(m>dis_sum_list.at(i)){
            m = dis_sum_list.at(i);
        }
    }
    cout << m;
}


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

int main() {
  int N, n1000, n100, n10, n1;
  cin >> N;
  n1000 = N / 1000;
  n100 = (N - 1000 * n1000) / 100;
  n10 = (N - 1000 * n1000 - 100 * n100) /10;
  n1 = N - 1000 * n1000 - 100 * n100 - 10 * n10;
  if (((n1000 == n100) && (n100 == n10)) || ((n100 == n10) && (n10 == n1))) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}


Measured memory_bytes: 256