akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int datas[15][15];
    for(int i=0; i<15; i++) {
        for(int j=0; j<15; j++) {
            datas[i][j] = -1;
        }
    }

    int n;
    cin >> n;
    
    for(int i=0; i<n; i++) {
        int a;
        cin >> a;
        for(int j=0; j<a; j++) {
            int x, y;
            cin >> x >> y;
            datas[i][x-1] = y;
        }
    }
    
    int result = 0;
    for(int i=0; i<(1<<n); i++) {
        bool isOK = true;
        for(int j=0; j<n; j++) {
            if(((i>>j)&0x01)==0x01) {
                for(int k=0; k<15; k++) {
                    if(datas[j][k] == -1) continue;
                    if(datas[j][k] != ((i>>k)&0x01)) isOK = false;
                }
            }
        }

        if(isOK) {
            int bit_counts = 0;
            for(int j=0; j<32; j++) {
                if(((i>>j)&0x01) == 0x01) bit_counts++;
            }
            if(bit_counts>result) result = bit_counts;
        }
    }
    
    cout << result << endl;

    return 0;    
}


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


using namespace std;
#define N 100010

int main(){
	int n,m,h[N],ma[N];
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>h[i];
		ma[i]=0;
	}
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		ma[a]=max(ma[a],h[b]);
		ma[b]=max(ma[b],h[a]);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=h[i]>ma[i];
	}
	cout<<ans<<endl;
	return 0;

}

Measured memory_bytes: 4392
sa=list(input())
sb=list(input())
sc=list(input())
i=sa_i=sb_i=sc_i=0
s="a"
while True:
  if s=="a":
    if len(sa)==sa_i:
      print("A")
      break
    s=sa[sa_i]
    sa_i+=1
  elif s=="b":
    if len(sb)==sb_i:
      print("B")
      break
    s=sb[sb_i]
    sb_i+=1
  elif s=="c":
    if len(sc)==sc_i:
      print("C")
      break
    s=sc[sc_i]
    sc_i+=1

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

const int N = 1e3 + 10;
const int M = 1e5 + 10; 

int n, w;
//ll dp[N][M];
//ll dp[2][M];
ll dp[M];
ll weight[N], value[N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	cin >> n >> w;
	for (int i = 1; i <= n; ++i) cin >> weight[i] >> value[i];
	
	/*
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= w; ++j) {
			if (weight[i] <= j)
				dp[i][j] = max(value[i] + dp[i-1][j-weight[i]], 
								          dp[i-1][j]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}

	cout << dp[n][w] << "\n";*/

	/*
	int m = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= w; ++j) {
			if (weight[i] <= j)
				dp[m][j] = max(value[i] + dp[m^1][j-weight[i]],
										  dp[m^1][j]);
			else
				dp[m][j] = dp[m^1][j];
		}
		m^=1;
	}

	cout << dp[m^1][w] << "\n";*/

	for (int i = 1; i <= n; ++i) {
		for (int j = w; j >= weight[i]; --j) {
			dp[j] = max(dp[j], value[i] + dp[j-weight[i]]);
		}
	}

	cout << dp[w] << "\n";

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int mod=998244353;
int main(){
    ll n,m;cin>>n>>m;
    ll ans=0;
    ans+=100*(n-m);
    ll k=1<<m;
    ans=1900*m+100*(n-m);
    ans*=k;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def new_value(value, shinsu):
    count = 0
    while(value > 0):
        count += 1
        value //= shinsu
        
    return count

if __name__ == '__main__':
  value, shinsu = input().split()
  value = int(value)
  shinsu = int(shinsu)
  
  print(new_value(value, shinsu))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define int          long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define pi           pair<int,int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define FIO         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}


void solve()
{
     int n;
     cin>>n;
     int a[n+1],b[n];
     rep(i,0, n+1)cin>>a[i];
     rep(i,0,n)cin>>b[i];
     int sum=0;
     rep(i,0,n)
     {
        //cout<<i<<":"<<" ";
        sum+=min(a[i],b[i]);
        //a[i]-=min(a[i],b[i]);
        b[i]-=min(a[i],b[i]);
        sum+=min(b[i],a[i+1]);
        a[i+1]-=min(b[i],a[i+1]);
        //cout<<sum<<endl;

     }
     cout<<sum<<endl;

}

signed main()
{
        FIO
       
        
        int t=1;
        //cin>>t;
        while(t--)
        solve();
        cerr<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;

        return 0;
}

Measured memory_bytes: 5360
#include <iostream>

using namespace std;

const int group[][7] = {
	{  1,  3,  5,  7,  8, 10, 12 },
	{  4,  6,  9, 11,  0,  0,  0 },
	{  2,  0,  0,  0,  0,  0,  0 },
};

int main(void) {
	int a[2];
	int g[2];
	cin >> a[0] >> a[1];

	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 7; k++) {
				if (a[i] == group[j][k]) g[i] = j;
			}
		}
	}
	if (g[0] == g[1]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
lst = []
for i in range(5):
    lst.append(int(input()))
lst.sort(reverse=True, key = lambda x : (x - 1) % 10)
s = 0
for i in range(5):
    s += lst[i]
    if s % 10 != 0 and i != 4:
        s += 10 - s % 10

print(s)

Measured memory_bytes: 2940
#include<stdio.h>
int a,b,k,i;
int main(void){
scanf("%d%d%d",&a,&b,&k);
for(i = 100;i >= 1;i--){
    if(a % i ==0 && b %i == 0){
        --k;
        if(k == 0){
            printf("%d",i);
            return 0;
        }
    }
}
}

Measured memory_bytes: 128
import math
n=int(input())
x=list(map(int, input().split()))
y=list(map(int, input().split()))

p=[0]*3
Max=0
for i in range(3):
    for j in range(n):
        p[i]+=abs(x[j]-y[j])**(i+1)
        if abs(x[j]-y[j])>Max:
            Max=abs(x[j]-y[j])
            
    print('{:.5f}'.format(p[i]**(1/(i+1))))
print('{:.5f}'.format(Max))


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pii pair<int, int>
#define vii vector<pii>
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vd vector<double>
#define vvi vector< vector<int> >
#define vvii vector< vector< pii > >
#define ld long double
#define mapii map<int, int>
#define mapsi map<string, int>
#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define INF  LLONG_MAX
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define pie  acos(-1)
#define mod(n,m) ((n % m + m) % m)
#define eps (1e-8)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'
#define output freopen("output.txt", "w", stdout)
#define mp(x, y, z) {{x, y}, z}

int modulo = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll fact[100001] = {};
    fact[0] = fact[1] = 1;
    erep(i, 2, 100000)
    {
        fact[i] = i*fact[i-1];
        fact[i] %= modulo;
    }
    int n, m;
    cin >> n >> m;
    if (n < m) swap(n, m);
    if (n == m)
    {
        ll a = fact[n], b = fact[m];
        ll ans = fact[n]*fact[m];
        ans %= modulo;
        ans *= 2;
        ans %= modulo;
        cout << ans;
    }
    else if (n-1 == m)
    {
        ll a = fact[n], b = fact[m];
        ll ans = fact[n]*fact[m];
        ans %= modulo;
        cout << ans;
    }
    else cout << 0;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max(a,b)-min(a,b))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)n,(int)n)
#define nHr(n,r) nCr((int)(n+r+1),(int)r)
ll sankaku(ll x){return x*(x+1)/2;}
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];

  scanf("%lld",&n);
  printf("%lld",sankaku(n-1));

  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
#エクサウィザーズ2019 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x,f):
    for i,j in td:
        if s[x] == i:
            if j == 'R':
                x += 1
                if x == n and f == 0:
                    return True
                elif x == n and f == 1:
                    return False
            else:
                x -= 1
                if x == -1 and f == 1:
                    return True
                elif x == -1 and f == 0:
                    return False
    return False

n,q = LI()
s = input()
td = [list(map(str,input().split())) for _ in range(q)]
ng,ok = -1,n
while abs(ok - ng) > 1:
    mid = (ok + ng)//2
    if f(mid,0):
        ok = mid
    else:
        ng = mid
R = ok
ng,ok = -1,n
while abs(ok - ng) > 1:
    mid = (ok + ng)//2
    if f(mid,1):
        ng = mid
    else:
        ok = mid
L = ng
print(R-L-1)


Measured memory_bytes: 93388
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
struct node{
	ll h,c;
};
ll dp[10001];
int main(){
	fast;
	memset(dp,0x3f,sizeof(dp));
	ll h,n;
	cin>>h>>n;
	node a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i].h>>a[i].c;
	}
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(int x=0;x<=h;x++){
			ll j=max(0,x-a[i].h);
			dp[x]=min(dp[x],dp[j]+a[i].c);
		}
	}cout<<dp[h]<<endl;
	return 0;
}/*『你强归你强，Siyuan比你强』*/





Measured memory_bytes: 512
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;
long a[200005];
long ans[200005];

int main(){
    scanf("%ld",  &n);
    for(long i = 1; i <= n; i++){
        scanf("%ld", &a[i]);
    }
    for(long  i = n; i > 0; i--){
        long cnt = 0;
        for(long j = i; j <= n; j += i){
            cnt += ans[j];
        }
        ans[i] = (a[i] + cnt) % 2;
    }
    long cnt = 0;
    for(long i = 1; i <= n; i++){
        if(ans[i]){
            cnt++;
        }
    }
    printf("%ld\n", cnt);
    for(long i = 1; i <= n; i++){
        if(ans[i]){
            printf("%ld\n", i);
        }
    }
    return 0;
}


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

typedef long long ll;
typedef long double ld;

ll tr;
map <int, int> ima;
ll res;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

	int n, p;
	cin >> n >> p;
	string s;
	cin >> s;
	if(p == 2){
        for(int i=0; i<n; i++){
            if((s[i]-'0')%2 == 0) res += i+1;
        }
        cout << res;
        return 0;
	}
	if(p == 5){
        for(int i=0; i<n; i++){
            if(s[i] == '0' || s[i] == '5') res += i+1;
        }
        cout << res;
        return 0;
	}
	ima[0] = 1;
	ll tr = 0, pr = 1;
	for(int i=n-1; i>=0; i--){
        tr = (pr*(s[i]-'0') + tr)%p;
        pr = (10*pr)%p;
        res += ima[tr];
        ima[tr]++;
	}
	cout << res;
    return 0;
}


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

int main() {
  double a,b,x;
  cin >> a >> b >> x;
  x/=a;
  if(a*b>=2*x){
      double y=2*x/b;
      double ans=atan(b/y);
      ans=ans*180/pi;
      cout << fixed << setprecision(10) << ans;
  }
  else{
      double y=(a*b-x)*2/a;
      double ans=atan(y/a);
      ans=ans*180/pi;
      cout << fixed << setprecision(10) << ans;
  }
}


Measured memory_bytes: 4096
S = input()
possible = False

def f(s, index):
  global possible

  if possible:
    return

  if index >= len(S):
    possible = True if s == "AKIHABARA" or s+"A" == "AKIHABARA" else False
    return
    
  f(s+"A"+S[index], index+1)
  f(s+S[index], index+1)

if len(S) >= 10:
  print('NO')
else:
  f("", 0)

  if(possible):
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

const int d[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

int H, W;
int M[1024][1024];

int count = 0;
int counted[1024][1024];
int visited[1024][1024];

int queue[1024 * 1024][2];

void nuru(int sy, int sx, int num) {
	int queue_start, queue_end;
	int i;
	queue_start = 0;
	queue_end = 1;
	queue[0][0] = sy;
	queue[0][1] = sx;
	if (visited[sy][sx] != 0 && counted[sy][sx] == 0) {
		count++;
		counted[sy][sx] = 1;
	}
	visited[sy][sx] = num;
	while (queue_start < queue_end) {
		int y = queue[queue_start][0];
		int x = queue[queue_start][1];
		queue_start++;
		for (i = 0; i < 4; i++) {
			int ny = y + d[i][0];
			int nx = x + d[i][1];
			if (M[y][x] < M[ny][nx] && visited[ny][nx] != num) {
				int already_one = 0;
				if (visited[ny][nx] != 0 && counted[ny][nx] == 0) {
					count++;
					counted[ny][nx] = 1;
				} else {
					if (counted[ny][nx]) already_one = 1;
				}
				visited[ny][nx] = num;
				if (!already_one) {
					queue[queue_end][0] = ny;
					queue[queue_end][1] = nx;
					queue_end++;
				}
			}
		}
	}
}

int main(void) {
	int i, j, k;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			if (scanf("%d", &M[i][j]) != 1) return 1;
		}
	}

	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
		int tomatuharuka = 0;
			for (k = 0; k < 4; k++) {
				int y = i + d[k][0];
				int x = j + d[k][1];
				if (M[y][x] == 0 || M[i][j] < M[y][x]) {
					tomatuharuka++;
				}
			}
			if (tomatuharuka == 4) {
				nuru(i, j, M[i][j]);
			}
		}
	}

	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 21076
import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
 
#maincode-------------------------------------------------

s = input()
t = input()
ans = 0

for i in range(len(t)):
    if t[i] != s[i]:
        ans += 1

for i in range(len(s)-len(t)):
    c = 0
    for j in range(len(t)):
        if t[j] != s[i + j]:
            c += 1
    ans = min(c,ans)
print(ans)

Measured memory_bytes: 9232
#include <iostream>

using namespace std;

int main() {
  int s;
  cin >> s;
  int i = 1;
  bool one = false;
  bool two = false;
  bool four = false;
  while (!(s == 1 && one || s == 2 && two || s == 4 && four)) {
    if (s == 1) one = true;
    if (s == 2) two = true;
    if (s == 4) four = true;
    s = s % 2 ? (3 * s) + 1 : s / 2;
    ++i;
  }
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 256
use std::collections::*;
use std::io::*;
use std::*;
// template {{{
macro_rules! get {
    ($($t:tt),*; $n:expr) => {
        {
            let stdin = std::io::stdin();
            let ret = std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
                let line = line.unwrap();
                let mut it = line.split_whitespace();
                _get!(it; $($t),*)
            }).collect::<Vec<_>>();
            ret
        }
    };
    ($($t:tt),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut it = line.split_whitespace();
            _get!(it; $($t),*)
        }
    };
}
macro_rules! _get {
    ($it:ident; [char]) => {
        _get!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; [u8]) => {
        _get!($it; String).bytes().collect::<Vec<_>>()
    };
    ($it:ident; usize1) => {
        $it.next().unwrap().parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap().parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:tt),+) => {
        ($(_get!($it; $t)),*)
    };
}
// }}}

fn main() {
    let (r, c, k) = get!(usize, usize, usize);
    let items = get!(usize1,usize1,i64;k);
    let mut dp = vec![vec![vec![0; 4]; c]; r];
    let mut itemmap = vec![vec![0; c]; r];
    for (ri, ci, vi) in items {
        itemmap[ri][ci] = vi;
    }
    dp[0][0][1] = itemmap[0][0];
    for i in 0..r {
        for j in 0..c {
            if i + 1 < r {
                dp[i + 1][j][0] = dp[i][j][0].max(dp[i][j][1].max(dp[i][j][2].max(dp[i][j][3])));
                dp[i + 1][j][1] = dp[i][j][0].max(dp[i][j][1].max(dp[i][j][2].max(dp[i][j][3])))
                    + itemmap[i + 1][j];
            }
            if j + 1 < c {
                dp[i][j + 1][1] = dp[i][j + 1][1].max(dp[i][j][0] + itemmap[i][j + 1]);
                dp[i][j + 1][2] = dp[i][j + 1][2].max(dp[i][j][1] + itemmap[i][j + 1]);
                dp[i][j + 1][3] = dp[i][j + 1][3].max(dp[i][j][2] + itemmap[i][j + 1]);
                dp[i][j + 1][0] = dp[i][j + 1][0].max(dp[i][j][0]);
                dp[i][j + 1][1] = dp[i][j + 1][1].max(dp[i][j][1]);
                dp[i][j + 1][2] = dp[i][j + 1][2].max(dp[i][j][2]);
                dp[i][j + 1][3] = dp[i][j + 1][3].max(dp[i][j][3]);
            }
        }
    }
    println!(
        "{}",
        dp[r - 1][c - 1][0]
            .max(dp[r - 1][c - 1][1].max(dp[r - 1][c - 1][2].max(dp[r - 1][c - 1][3])))
    );
}


Measured memory_bytes: 709788
s=input()
l=len(s)
m=(l-1)//2
lst1=[]
lst2=[]
for i in range(m):
  lst1.append(s[i])
  lst2.append(s[l-i-1])
chk='T'
if lst1!=lst2:
  chk='F'
n=m//2
lst3=[]
lst4=[]
lst5=[]
lst6=[]
for i in range(n):
  lst3.append(s[i])
  lst4.append(s[m-i-1])
  lst5.append(s[m+1+i])
  lst6.append(s[l-i-1])
if lst3!=lst4:
  chk='F'
if lst5!=lst6:
  chk='F'
if chk=='T':
  print('Yes')
else:
  print('No')
  
  

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


int main(){
	int n;
	while(cin>>n&&n){
		int ans=0;
		long long pow5=5;
		while(pow5<=n){
			ans+=n/pow5;
			pow5*=5;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s;
  cin >> s;

  deque<char> st;
  REP(i, s.size()){
    if(s[i] == '0' || s[i] == '1')
      st.push_back(s[i]);
    else{
      if(!st.empty())
        st.pop_back();
    }
  }

  while(!st.empty()){
    cout << st.front();
    st.pop_front();
  }

  cout << endl;

}


Measured memory_bytes: 256
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim().split(' ');
  var a = Number(inputs[0]);
  var b = Number(inputs[1]);
  if(a < b){
console.log('a < b');
  }else if (a > b){
console.log('a > b');
  }else {
console.log('a == b')
  }
  // ????????????????????????
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15500
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int zikan = 0;
		if(a+b>=24) {
			zikan = (a+b)-24;
		}else {
			zikan = a+b;
		}
		System.out.println(zikan);
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 5010, mod = 1e9+7;
int n,cnt,cir,a[N],f[N][N];

int fa[N],siz[N],flag[N];
inline int Find(int x){
	return fa[x]==x?x:fa[x]=Find(fa[x]);
}

inline int power(int a,int b){
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) ret=1ll*ret*a%mod;
	return ret;
}

int main(){
	n=read();
	For(i,1,n) fa[i]=i;
	For(i,1,n){
		a[i]=read(),cnt+=(a[i]==-1);
		if (a[i]==-1) continue;
		int x=Find(i),y=Find(a[i]);
		if (x==y) ++cir,flag[x]=1;
			else fa[x]=y,flag[y]|=flag[x];
	}
	For(i,1,n) siz[Find(i)]++;
	vector<int>v;
	For(i,1,n) if (Find(i)==i&&!flag[i]) v.pb(siz[i]);
	f[0][0]=1;
	For(i,1,siz(v)){
		f[i][0]=1ll*f[i-1][0]*(n-1)%mod;
		For(j,1,i) f[i][j]=(1ll*f[i-1][j]*(n-1)+1ll*f[i-1][j-1]*(j==1?1:j-1)%mod*v[i-1])%mod; 
	}
	int ans=1ll*n*power(n-1,cnt)%mod;
	For(i,2,siz(v)) ans=(ans+mod-f[siz(v)][i])%mod;
	for (int j = 0; j < v.size(); ++j) ans=(ans+mod-1ll*(v[j]-1)*power(n-1,siz(v)-1)%mod)%mod;
	ans=(ans+mod-1ll*cir*power(n-1,cnt)%mod)%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 70464
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val C = IntArray(N)
    val S = IntArray(N)
    val F = IntArray(N)
    for (i in 0 until N-1) {
        val (c, s, f) = readLine()!!.split(' ').map(String::toInt)
        C[i] = c
        S[i] = s
        F[i] = f
    }
    for ( i in 0 until N-1) {
        var ela = 0
        for (j in i until N-1) {
            ela = Math.max(ela, S[j])
            ela = ((ela + F[j]-1)/F[j]) * F[j]
            ela += C[j]
        }
        println(ela)
    }
    println(0)
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> freq(1e5+5, 0);
    for (int i = 0; i != N; ++i){
        int a;
        cin >> a;
        ++freq[a];
        ++freq[a + 1];
        ++freq[a + 2];
    }
    cout << *max_element(freq.begin(), freq.end()) << endl;
    return 0;
}

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

bool g[1000][1000];
bool visited[1000];
vector<int> res;

void find_cycle(int n, int start, vector<int>& path) {
	visited[start] = true;
	path.push_back(start);
	
	for (int dest = 0; dest < n; ++dest) {
		if (g[start][dest] && dest == path[0] && path.size() > 1 && (res.empty() || path.size() < res.size())) {
			res = path;
		} else if (g[start][dest] && !visited[dest]) {
			find_cycle(n, dest, path);
		}
	}

	path.pop_back();
}

int main() {
	memset(g, false, sizeof(g));

	int n, m;
	cin >> n >> m;

	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		g[a - 1][b - 1] = true;
	}

	for (int i = 0; i < n; ++i) {
		memset(visited, false, sizeof(visited));
		vector<int> p;
		find_cycle(n, i, p);
	}

	if (res.empty()) {
		cout << -1;
		return 0;
	}

	cout << res.size() << endl;
	for (int c : res) {
		cout << c + 1 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;

#define Whats(x) cout<<#x<<" is "<<(x)<<endl
#define Divhim() cout<<">>>>>>>>>"<<endl
#define Divher() cout<<"<<<<<<<<<"<<endl
#define Oops() cout<<"!!!!!!!!"<<endl

template<typename T> bool GetMax(T &a,T b)
{
	return (a>=b)?false:(a=b,true);
}

template<typename T> bool GetMin(T &a,T b)
{
	return (a<=b)?false:(a=b,true);
}

/*
	 -<Unlimited Blade Works>-
 */

const int N=1000000+10;

int n;
int fir[N],nxt[N<<1],to[N<<1],du[N],tote;

void Adde(int u,int v)
{
	++du[u];
	++du[v];
	to[++tote]=v;
	nxt[tote]=fir[u];
	fir[u]=tote;
	to[++tote]=u;
	nxt[tote]=fir[v];
	fir[v]=tote;
}

namespace Brute
{

	int G[20][20];
	int lst[20],ed,ans;

	bool Check()
	{
		for(int i=1;i<=n;++i)
		{
			for(int j=i+1;j<=n;++j)
			{
				bool fl=true;
				for(int k=1;k<=ed&&fl;++k)
					fl&=(G[i][lst[k]]==G[j][lst[k]]);
				if(fl)
					return false;
			}
		}
		return true;
	}

	void Dfs(int k)
	{
		if(k>n)
		{
			if(Check())
				GetMin(ans,ed);
			return;
		}
		Dfs(k+1);
		lst[++ed]=k;
		Dfs(k+1);
		--ed;
	}

	void Force()
	{
		memset(G,0x3f,sizeof G);
		for(int i=1;i<=n;++i)
			G[i][i]=0;
		for(int i=1,u,v;i<n;++i)
		{
			scanf("%d%d",&u,&v);
			++u;
			++v;
			G[u][v]=G[v][u]=1;
		}
		for(int k=1;k<=n;++k)
			for(int i=1;i<=n;++i)
				for(int j=1;j<=n;++j)
					GetMin(G[i][j],G[i][k]+G[k][j]);
		ans=n;
		Dfs(1);
		printf("%d",ans);
	}

}

int ans;
bool f[N],g[N];

void Dfs(int u,int fa=0)
{
	int cnt=0,x=0;
	for(int i=fir[u],v;i;i=nxt[i])if((v=to[i])!=fa)
	{
		Dfs(v,u);
		if(f[v])
		{
			f[u]=true;
			++x;
		}
		else
			++cnt;
	}
	for(int i=fir[u],v;i;i=nxt[i])if((v=to[i])!=fa&&g[v]&&!(x-f[v]))
	{
		g[u]=true;
		break;
	}
	if(cnt>1)
	{
		ans+=cnt-1;
		f[u]=true;
		g[u]=true;
	}
	else if(cnt==1)
		g[u]=true;
	if(fa||cnt>1)
		return;
	bool fl=false;
	vector<int> ch;
	for(int i=fir[u],v;i;i=nxt[i])
	{
		ch.push_back(v=to[i]);
		fl|=g[u];
	}
	if(!fl||ch.size()>2)
		return;
	if(ch.size()==1||(g[ch[0]]&&!f[ch[1]])||(g[ch[1]]&&!f[ch[0]]))
	{
		++ans;
		return;
	}
}

int main()
{
	scanf("%d",&n);
	if(n<=10)
	{
		Brute::Force();
		return 0;
	}
	for(int i=1,u,v;i<n;++i)
	{
		scanf("%d%d",&u,&v);
		++u;
		++v;
		Adde(u,v);
	}
	for(int i=1;i<=n;++i)if(du[i]!=1)
	{
		Dfs(i);
		printf("%d",ans);
		return 0;
	}
	return 0;
}

Measured memory_bytes: 25088
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
using namespace std;
signed main() {
	ll cnta = 0, cntb = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i += 2) {
		if (s[i] == 'p')cnta++;
	}
	for (int i = 1; i < s.size(); i += 2) {
		if (s[i] == 'g')cntb++;
	}
	cout << cntb - cnta << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 512
H,N=gets.chomp.split(" ").map(&:to_i)
MAGICS={}
N.times do
    a,b=gets.chomp.split(" ").map(&:to_i)
    if MAGICS[a] == nil
        MAGICS[a] = b
    else
        MAGICS[a] = [MAGICS[a],b].min
    end
end
MEMO=Array.new(H+1,(1 << 31) - 1)
MEMO[H]=0
cursor=H
loop do
    break if cursor==0
    m=MEMO[cursor]
    MAGICS.each do |a,b|
        c = cursor - a
        if c < 0
            c = 0
        end
        if MEMO[c] > m+b
            MEMO[c]= m+b
        end
    end
    cursor-=1
end
puts MEMO[0]


Measured memory_bytes: 3836
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    int A,B;
    string ans="No";
    cin >> A >> B;

    int digit=0;
    int temp=B;
     while (temp>0){
         digit++;
         temp/=10;
     }

     rep(i,digit){
         A*=10;
     }

     for(int i=1; i<A+B; i++){
         if(i*i==A+B) ans="Yes";
     }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int n,m,l;
    cin >> n >> m >> l;
     
    long long a[100][100], b[100][100];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> a[i][j];
        }
    }
    for(int i=0; i<m; i++){
        for(int j=0; j<l; j++){
            cin >> b[i][j];
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            long long f=0;
            for(int k=0; k<m; k++){
                f += a[i][k]*b[k][j];
            }
            if(j==0) cout << f;
            else cout << " " << f;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3224
MOD = 10**9+7
memo = [0]*10000

N = int(input())

def primeLst(k):
  acc = []
  if k == 1:
    return acc
  f = 2
  while f * f <= k:
    if k % f == 0:
      acc.append(f)
      k //= f
    else:
      f += 1
  if k != 1:
    acc.append(k)
  return acc

for i in range(N):
  l = primeLst(i+1)
  for x in l:
    memo[x] += 1

res = 1
for i in range(1,N):
  res *= memo[i+1] + 1
  res %= MOD

print(res)

Measured memory_bytes: 9264
import sys
sys.setrecursionlimit(10 ** 6)

def main():
    S = input()
    T = input()
    pair = {}
    pair2 = {}
    for i in range(len(S)):
        if S[i] not in pair.keys():
            pair[S[i]] = T[i]
        else:
            if pair[S[i]] != T[i]:
                print('No')
                return
        if T[i] not in pair2.keys():
            pair2[T[i]] = S[i]
        else:
            if pair2[T[i]] != S[i]:
                print('No')
                return
        
    
    print('Yes')


if __name__ == '__main__':
    main()

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

//#include "rubo.h"
//#define mp make_pair
//#define pb push_back
#define in int
#define ll long long
#define vc vector
#define SQ(j) (j)*(j)
//#define x first
//#define y second

//#define ld long double
#define dbl  long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define all(j) j.begin(), j.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt, ...) (0)
//#define HOME
//#define y0 ngacaleiebinvoaeu
//#define y1 gnarpipipaigare
#define j1 adsfndnasfafoasp

#define db(x) cout << #x << " = " << x << endl
#define dbCont(x) cout << #x << ": "; for(auto shun: x) cout << shun << ' '; cout << endl;

typedef long double ld;

using namespace std;


const int N = 400 + 5;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
vector<int> a;

ll dp[N][N];

int main() {
    cin >> n;
    loop(i, n) {
        int e;
        cin >> e;
        a.push_back(e);
    }

    loop(i,N){
        loop(j,N){
            dp[i][j] = 1e17;
        }
    }

    for (int l = 1; l <= n; l++) {
        for (int i = 0; i + l - 1 < n; i++) {
            int j = i + l - 1;
            if (l == 1) {
                dp[i][j] = 0;
            } else {
                ll sum = 0;
                for (int k = i; k <= j; k++) {
                    sum += a[k];
                }

                for (int k = i; k + 1 <= j; k++) {
                    dp[i][j] = min(
                            dp[i][j],
                            dp[i][k] + dp[k + 1][j] + sum
                    );
                }
            }
        }
    }

    ll res = dp[0][n-1];
    cout << res << endl;


    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  int f=0;
  int cnt=1;
  while(cnt<=N){
    f+=N/cnt%10;
    cnt*=10;
  }
  cout << (N%f==0? "Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define out(a) printf("%d ",a);
using namespace std;
int a,b;
char str[1][100];
bool flag;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	a=read(),b=read(); flag=true;
    scanf("%s",str); //cout<<str[0][a];
    if (str[0][a]!='-') flag=false;
      for (int i=0;i<=a+b;i++)
        if (i!=a) {
          if (str[0][i]<'0'||str[0][i]>'9') {
		    flag=false;
		    break;
		}
	  }
	  if (flag) puts("Yes");
	  else puts("No");
	  return 0;
}
          

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;

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

int main()
{
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> day(m+1);
  priority_queue<ll> today;

  rep(i,n) {
    ll a, b;
    cin >> a >> b;
    if (m-a+1 < 1) continue;
    day[m-a+1].push_back(b);
  }

  ll result = 0;
  for (ll i = m; i >= 1; i--) {
    if (!day[i].empty()) {
      for (auto x : day[i]) {
        today.push(x);
      }
    }
    if (!today.empty()) {
      result += today.top(); today.pop();
    }
  }

  cout << result << endl;
}


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

using namespace std;

const int N = 2e5 + 2;

int k, n, a[N];

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

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

    int answer = a[n] - a[1];

    for (int i = 1; i < n; i++) {
        answer = min(answer, k - (a[i + 1] - a[i]));
    }

    cout << answer << endl;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
t = [0]
t.append(a[-1])
for i in range(n - 2, -1, -1) :
    t.append((t[-1] + a[i]) % mod)
ans = 0
for i in range(n) :
    ans = (ans + a[i] * t[n - i - 1]) % mod
print(ans)

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for (int i=0; i<S.size()-1; ++i) {
        string a = S.substr(0, i+1);
        string b = S.substr(i+1, S.size()-(i+1));
        map<char, int> mp, mp2;
        for (char ch : a) mp[ch]++;
        int num = 0;
        for (char ch : b) mp2[ch]++;
        for (auto tmp : mp) {
            if (mp2[tmp.first]>0) num++;
        }
        ans = max(ans, num);
    }
    cout << ans << endl;
}


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

#define MAX 100010
#define MOD 1000000007
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define dbg(x) cout << #x << " = " << x << endl
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))

using namespace std;

int counter[MAX];

int main(){
    int n, i, j, k, l;

    while (scanf("%d", &n) != EOF){
        clr(counter);
        for (i = 1; i <= n; i++){
            for (j = 2, k = i; j <= i; j++){
                while ((k % j) == 0){
                    counter[j]++;
                    k /= j;
                }
            }
        }

        long long res = 1;
        for (i = 0; i < MAX; i++) res = (res * (counter[i] + 1)) % MOD;
        printf("%lld\n", res);
    }
    return 0;
}


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

using namespace std;

int main() {
  int K;
  string S;
  cin >> K >> S;
  if (S.length() <= K) {
    cout << S << endl;
  } else {
    for (int i = 0; i < K; i++) {
      cout << S[i];
    }
    cout << "..." << endl;
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
    int n, a, x[51];
    static long long dp[52][52][2501]={0}, ans=0;
    cin>>n>>a;
    for (int i=1; i<=n; i++) cin>>x[i];
    for (int i=0; i<=n; i++) dp[i][0][0]=1;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=i; j++)
        {
            for (int k=0; k<=2500; k++)
            {
                dp[i][j][k]=dp[i-1][j][k];
                if (k>=x[i]) dp[i][j][k]+=dp[i-1][j-1][k-x[i]];
            }
        }
    }
    for (int i=1; i<=n; i++) ans+=dp[n][i][i*a];
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 50048
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n;
  cin>>n;
  int c=0;
  vector<int64_t> d;
  for(int64_t i=1;i*i<=n-1;i++){
    if((n-1)%i==0){
      if(i!=1)
        d.push_back(i);
      if(i*i!=n-1)
        d.push_back((n-1)/i);
    }
  }
  sort(d.begin(),d.end());
  for(int64_t k=2,i=0;k*k<=n;k++){
    if(i<d.size()&&k==d.at(i)){
      i++;
      continue;
    }
    int64_t x=n;
    while(x%k==0)
      x/=k;
    c+=(x%k==1?1:0);
  }
  
  cout<<c+d.size()+1<<endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n,m;cin>>n>>m;
  vs a(n);
  rep(i,n)cin>>a[i];
  vs b(n);
  rep(i,m)cin>>b[i];
  
  bool exists=false;
  rep(ly,n){
    rep(lx,n){
      if(ly+m-1>=n||lx+m-1>=n)continue;
      bool match=true;
      rep(y,m){
        if(a[ly+y].substr(lx,m)!=b[y])match=false;
      }
      if(match)exists=true;
    }
  }
  
  if(exists){
    cout("Yes");
  }else{
    cout("No");
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())

my_list = []

for i in range(N):
    sp = input().split()
    sp[1] = int(sp[1])
    sp.insert(0, i+1)
    
    my_list.append(sp)
    
my_list.sort(key = lambda x: x[2], reverse=True)
my_list.sort(key = lambda x: x[1])

for i in my_list:
    print(i[0])

Measured memory_bytes: 9084
H = gets.to_i
nodes = gets.chomp.split(" ").map(&:to_i)

def left(i)
    (i+1)*2-1
end

def right(i)
    (i+1)*2
end

def max_heapify(nodes, i)
    l = left(i)
    r = right(i)
    largest = i
    if l < H && nodes[l] > nodes[i]
        largest = l
    end
    if r < H && nodes[r] > nodes[largest]
        largest = r
    end
    if largest != i
        nodes[i],nodes[largest] = nodes[largest],nodes[i]
        max_heapify(nodes, largest)
    end
end

(0..(H/2-1)).to_a.reverse.each do |i|
    max_heapify(nodes, i)
end

puts " " + nodes.join(" ")


Measured memory_bytes: 58108
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;


signed main(){
    int N,K;
    string S;cin>>N>>K>>S;
    int z=0;
    REP(i,N-1){
        if(S[i]==S[i+1])z++;
    }
    cout<<min(N-1,z+2*K);
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define POS(i,j) ((i)*m+(j))

void run(void){
  int n,k;
  scanf("%d%d",&n,&k);
  const int mod=1000000007;
  const int m=256;
  int *now=(int *)calloc(m*(n+1),sizeof(int));
  int *next=(int *)calloc(m*(n+1),sizeof(int));
  now[POS(0,0)]=1;
  int r;
  for(r=1;r<=n;r++){
    int a;
    scanf("%d",&a);
    int i,j;
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	next[POS(i,j)]=now[POS(i,j)];
      }
    }
    for(i=0;i<r;i++){
      for(j=0;j<m;j++){
	next[POS(i+1,j^a)]+=now[POS(i,j)];
	next[POS(i+1,j^a)]%=mod;
      }
    }
    int *swap=now;
    now=next;
    next=swap;
  }
  int64 ans=0;
  int64 fact=1;
  int i;
  for(i=1;i<=n;i++){
    fact=fact*i%mod;
    ans=(ans+fact*now[POS(i,k)])%mod;
  }
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
  int i,n,a[100];
  scanf("%d",&n); 
  for(i=0;i<n;i++){ 
   scanf("%d",&a[i]); 
  }
  for(i=0;i<n;i++){ 
    if(a[i]%2==0&&a[i]%3!=0&&a[i]%5!=0){ 
      puts("DENIED"); 
      return 0;  
    } 
  }
  puts("APPROVED");
  return 0; 
 }

Measured memory_bytes: 128
N = int(input())
As = list(map(int, input().split()))

ans = 1
flg = ''
for i in range(N - 1):
    if (flg == 'LE' and As[i] > As[i + 1]) or (flg == 'GE' and As[i] < As[i + 1]):
        ans += 1
        flg = ''
    else:
        if As[i] < As[i + 1]: flg = 'LE'
        elif As[i] > As[i + 1]: flg = 'GE'

print(ans)


Measured memory_bytes: 14224