akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll R, C, K;
ll V[3001][3001], dp[3001][3001][4];

ll solve(){
    REP(i, R) REP(j, C) REP(k, 4) dp[i][j][k] = LONG_LONG_MIN / 2;
    dp[0][0][0] = 0;
    REP(i, R){
        REP(j, C){
            if(V[i][j] > 0){
                for(ll k = 2; k >= 0; k--) dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + V[i][j]);
            }
            REP(k, 4) dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
            REP(k, 4) dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
        }
    }
    ll ret = 0;
    REP(k, 4) ret = max(ret, dp[R - 1][C - 1][k]);
    return ret;
}

signed main(){
    cin >> R >> C >> K;
    ll r, c, v;
    REP(i, K){
        cin >> r >> c >> v;
        r--; c--;
        V[r][c] = v;
    }
    PRINT(solve());
    return 0;
}

Measured memory_bytes: 355312
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,h[100005],ans,cnt;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	for(int i=n;i>0;i--){
		if(i==n||h[i]>=h[i+1])cnt++;
		else ans=max(ans,cnt-1),cnt=1;
	}
	cout<<max(ans,cnt-1);
    return 0;
}

Measured memory_bytes: 640
n,m,q=map(int,input().split())
abcd=[]
x=[1]
for i in range(q):
    abcd.append(list(map(int,input().split())))
ans=0
def dfs(s):
    global ans
    if(len(s)==n):
        t=0
        for a,b,c,d in abcd:
            if(s[b-1]-s[a-1]==c):
                t+=d
        ans=max(t,ans)
        return 
    p=s[-1]
    while p<=m:
        s.append(p)
        dfs(s)
        p=s.pop()+1
dfs(x)
print(ans)

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

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   String original = br.readLine();
   int n = Integer.parseInt(br.readLine());


   for(int i = 0; i < n;i++){

	   String[] order = br.readLine().split(" ");

	   if( order[0].equals("print") ){

		   String print = original.substring( Integer.parseInt(order[1]), Integer.parseInt(order[2])+1 );
		   System.out.println(print);

      }else if( order[0].equals("reverse") ){
    	  String left = original.substring( 0, Integer.parseInt(order[1]));
    	  String right = original.substring(Integer.parseInt(order[2])+1 , original.length());
    	  StringBuffer before = new StringBuffer( original.substring( Integer.parseInt(order[1]) , Integer.parseInt(order[2])+1 ) );
    	  String reverse = before.reverse().toString();
    	  original = left + reverse + right;

      }else{

    	  String left = original.substring( 0, Integer.parseInt(order[1]));
    	  String right = original.substring(Integer.parseInt(order[2])+1 , original.length());
    	  original = left + order[3] + right;


      }
   }


  }
}

Measured memory_bytes: 25360
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int n, m;
    cin >> n >> m;

    vector<pair<ll,ll>> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i].first;
        a[i].second = 1;
    }

    vector<pair<ll,ll>> l(m);
    for(int i = 0; i < m; i++){
        cin >> l[i].second >> l[i].first;
    }

    for(int i = 0; i < m; i++){
        pair<ll,ll> tmp;
        tmp.first = l[i].first;
        tmp.second = l[i].second;
        a.push_back(tmp);
    }

    sort(a.begin(), a.end(), greater<pair<ll,ll>>());

    ll ans = 0;
    ll cnt = 0;
    for(int i = 0; i < a.size(); i++){
        if(cnt + a[i].second <= n){
            ans += a[i].first * a[i].second;
            cnt += a[i].second;
        } else {
            ans += a[i].first * (n - cnt);
            cnt = n;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 8800
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
const int MAXN=1e5+3;
int a[MAXN];
int b[MAXN];
int main()
{
    //freopen("a.in","r",stdin);
    int n;
    scanf("%d",&n);
    n/=2;
    for(int i=1;i<=n;++i)
    {
        scanf("%d%d",&a[i],&b[i]);
    }
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    int mac=0,zmac=0,macc=0;
    int no=1;
    for(int i=1;i<=n+1;++i)
    {
        if(a[i]==a[i+1])no++;
        else
        {
            if(!mac){mac=no;zmac=a[i];}
            else if(no>=mac){macc=mac;mac=no;zmac=a[i];}
            else if(no>macc){macc=no;}
            no=1;
        }
    }
    int mab=0,zmab=0,mabb=0;
    no=1;
    for(int i=1;i<=n+1;++i)
    {
        if(b[i]==b[i+1])no++;
        else
        {
            if(!mab){mab=no;zmab=b[i];}
            else if(no>=mab){mabb=mab;mab=no;zmab=b[i];}
            else if(no>mabb){mabb=no;}
            no=1;
        }
    }
    if(zmac!=zmab){cout<<n*2-mac-mab;return 0;}
    int k=max(mac+mabb,macc+mab);
    cout<<n*2-k;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n, m;
  cin >> n >> m;
  int a[m];
  for (int i(0);i<m;i++)	cin >> a[i];
  int s(0);
  for(int i(0);i<m;i++)	s += a[i];
  if(s > n)	cout << -1;
  else	cout << n - s;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <map>

using namespace std;

map<pair<int,int>,int> m;

vector<int> dw{-1,0,-2};
vector<int> dh{-1,0,-2};

long long int ans[123];

int main() {
    long long int W, H, N;
    cin >> H >> W >> N;
    for(int i = 0; i < N; i++) {
        int cw, ch;
        cin >> ch >> cw;
        for(auto w: dw) {
            for(auto h: dh) {
                int nw = cw + w;
                int nh = ch + h;
                if(nw >= 1 && nh >= 1 && nw <= W-2 && nh <= H-2) {
                    m[{nw, nh}]++;
                }
            }
        }
    }
    for(auto it: m) {
        ans[it.second]++;
    }
    ans[0] = (W-2ll)*(H-2ll);
    for(int i = 1; i <= 9; i++) {
        ans[0] -= ans[i];
    }
    for(int i = 0; i <= 9; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 56448
def resolve():
    throw_count = int(input())
    same_count = int(0)
    answer = "No"
    for _ in range(throw_count):
        throw_1, throw_2 = map(int, input().split())
        if throw_1 == throw_2:
            same_count += 1
            if same_count == 3:
                answer = "Yes"
                break
        else:
            if same_count > 0:
                same_count = 0
    print(answer)
resolve()

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

const int maxn = 1e5 + 10;
int a[maxn];
int b[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n;
	cin >> n;
	n *= n - 1;
	n /= 2;
	cout << n;
}


Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#define fi(p) for(int i=0;i<(p);i++)
using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	long A;
	long B;
	cin >> A >> B;

	if ((A + B) % 2 == 1) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << ((A + B) / 2) << endl;
	}

}


int main()
{
	solve();

	return 0;
}

Measured memory_bytes: 256
<?php
    $ND = explode(" ",trim(fgets(STDIN)));
    list($num,$cri) = $ND;
    $count = 0;

    for ($i = 0; $i < $num; $i++) {
        $input = explode(" ",trim(fgets(STDIN)));
        $dis = sqrt($input[0] * $input[0] + $input[1] * $input[1]);
        
        if ($dis <= $cri) {
            $count++;
        }
    }
    
    echo $count;
?>

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

using namespace std;
#define taskname "A"
#define pb  push_back
#define mp  make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2005;
const int maxm = 1e4 + 5;

int n;
ii a[maxn * 2];
int cost[maxn][2][maxn][2];
int dp[maxn][maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin);
        freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n * 2 ; ++i){
        char x;cin >> x >> a[i].second;
        if(x == 'W')a[i].first = 0;
        else a[i].first = 1;
    }
    for(int i = 1 ; i <= n * 2 ; ++i){
        for(int j = n * 2 ; j > i ; --j){
            cost[a[i].second][a[i].first][a[j].second][a[j].first]++;
        }
        for(int j = 1 ; j <= n ; ++j){
            for(int k = 0 ; k < 2 ; ++k){
                cost[a[i].second][a[i].first][j][k] += cost[a[i].second][a[i].first][j - 1][k];
            }
        }
    }
    fill_n(&dp[0][0],maxn*maxn,1e9);
    dp[0][0] = 0;
    for(int i = 0 ; i <= n ; ++i){
        for(int j = 0 ; j <= n ; ++j){
            if(i == 0 && j == 0)continue;
            if(i > 0)dp[i][j] = min(dp[i][j] , dp[i - 1][j] + cost[i][0][i - 1][0] + cost[i][0][j][1]);
            if(j > 0)dp[i][j] = min(dp[i][j] , dp[i][j - 1] + cost[j][1][i][0] + cost[j][1][j - 1][1]);
        }
    }
    cout << dp[n][n];
}


Measured memory_bytes: 78720
#include<cstdio>
#include<cstring>
const int N=1e5+11;
bool vis[26];
int len;
char s[N];
int main(){
	scanf("%s",s);len=strlen(s);
	for(int i=0;i<len;++i) vis[s[i]-'a']=1;
	for(int i=0;i<26;++i){
		if(!vis[i]){
			printf("%c",i+'a');
			return 0;
		}
	}
	printf("None");
	return 0;
}

Measured memory_bytes: 256
a,b,c,d,e,f = map(int, input().split())
ans = [-1,0,0]
for i in range(f//(a*100)+1):
  for j in range((f-a*100*i)//(b*100)+1):
    for k in range((f-a*i*100-b*j*100)//c+1):
      for l in range((f-a*i*100-b*j*100-c*k)//d+1):
        w = i*a+j*b
        s = k*c+l*d
        if w == 0:
          continue
        if w*e >= s and ans[0] < s/(w*100+s):
          ans = [s/(w*100+s),w*100+s,s]
print(ans[1],ans[2])


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

using namespace std;

typedef long long ll;

const ll inf = 1LL << 60;

int main(){
  ll N,W; cin >> N >> W; ll Max_v = 0;
  vector<ll> w(N); vector<ll> v(N);
  for(ll i = 0; i < N; i++){ cin >> w[i] >> v[i]; Max_v += v[i];}
  
  ll dp[110][100010];
  for(int i = 0; i < 110; i++){
    for(int j = 0; j < 100010; j++){
      dp[i][j] = inf;}}
  
  dp[0][0] = 0;
  
  for(ll i = 0; i < N; i++){
    for(ll sum_v = 0; sum_v <= Max_v; sum_v++){
      if( sum_v >= v[i]){dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i]);}
      dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v]);
    }}
  
  for(ll sum_v = Max_v; sum_v >= 0; sum_v--){
    if(dp[N][sum_v] <= W){ cout << sum_v<< endl; return 0;}}
  
return 0;}
      


Measured memory_bytes: 86144
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define mod 1000000007
#define INF 1000000000000000000
/****************************/
int n,k,c;
string s;
int best[200010];
int worst[200010];
int main()
{
	cin>>n>>k>>c;
	cin>>s;
	int cnt=0;
	int i=0;
	while(i<k)
	{
		if(s[cnt]=='o')
		{
			best[i]=cnt;
			cnt+=c+1;
			i++;
		}
		else
		{
			cnt++;
		}
	}
	cnt=n-1;
	i=0;
	while(i<k)
	{
		if(s[cnt]=='o')
		{
			worst[i]=cnt;
			cnt-=c+1;
			i++;
		}
		else
		{
			cnt--;
		}
	}
	rep(i,k)
	{
		if(best[i]==worst[k-i-1])
		{
			cout<<best[i]+1<<endl;
		}
	}
    return 0;
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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

int n;
int a[50];


int main(){
  cin >> n;
  a[0]=1;a[1]=1;
  rep(i,2,n+1){
    a[i] = a[i-1]+a[i-2];
  }
  cout << a[n] << endl;

  return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod || x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 20;
ll dp[2 * MAX_N + 10][1 << MAX_N];

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n, x, y, z;
    cin >> n >> x >> y >> z;
    ll full = (1 << (x + y + z)) - 1;
    x = x + y + z - 1;
    y = y + z - 1;
    z = z - 1;
    ll bad = (1 << x) | (1 << y) | (1 << z);
    dp[0][0] = 1;
    for(int i = 0; i < n; i ++) {
        for(int j = 0; j <= full; j ++) {
            if((j & bad) == bad) {continue;}
            //cout << i << " " << j << " " << dp[i][j] << endl;
            for(int k = 1; k <= 10; k ++) {
                dp[i + 1][((1 << (k - 1)) | (j << k)) & full] += dp[i][j];
                fix(dp[i][j]);
            }
        }
    }
    ll ret = 1;
    for(int i = 0; i < n; i ++) {
        ret = (ret * 10) % mod;
    }
    for(int i = 0; i <= full; i ++) {
        if((i & bad) == bad) {continue;}
        ret -= dp[n][i];
        fix(ret);
    }
    cout << ret << endl;
    return 0;
}




Measured memory_bytes: 82176
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll MOD = 1000000007;
ll INF =1<<30;
ll dp[110][100100];
 
 
int main(){
    int n,m;
    cin >> n >> m;
    vector<int>c,d;
     rep(i,m){
          int a,b;
          cin >> a>>b;
          a--,b--;
          if(a==0)c.push_back(b);
          if(b==0)c.push_back(a);
          if(a==n-1)d.push_back(b);
          if(b==n-1)d.push_back(a);
          }
     set<int>st;
     rep(i,c.size()) st.insert(c[i]);
     rep(i,d.size()) st.insert(d[i]);
     if(c.size()+d.size()!=st.size()) {
          cout << "POSSIBLE"<<endl;
     }
     else cout << "IMPOSSIBLE" <<endl;
}

Measured memory_bytes: 13416
#include <bits/stdc++.h>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
using ll = long long;

const int N = 1e5 + 1, MOD = 1e9 + 7;

vector <int> graph[N];

ll memo[N][2]; // 0 for black and 1 for white

ll add(ll x, ll y) {
	return (x % MOD + y % MOD) % MOD;
}

ll mult(ll x, ll y) {
	return ((x % MOD) * (y % MOD)) % MOD;
}

void DFS(int node, int prev_node) {
	memo[node][0] = memo[node][1] = 1;

	for(int child : graph[node]) {
		if(child != prev_node) {
			DFS(child, node);
			memo[node][0] = mult(memo[node][0],
					add(memo[child][0], memo[child][1]));
			memo[node][1] = mult(memo[node][1], memo[child][0]);
		}
	}
}

int main() {
	Data_Nerd
	int n; scanf("%d", &n);

	for(int i = 0; i < n - 1; ++i) {
		int u, v; scanf("%d%d", &u, &v);

		graph[u].emplace_back(v);
		graph[v].emplace_back(u);
	}

	DFS(1, 1);

	cout << add(memo[1][0], memo[1][1]);

}


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

int Max(int a,int b){
    return a>b?a:b;
}

int main()
{
    //O(1)できるのか
    int N,Y;
    scanf("%d %d",&N,&Y);

    //連立方程式ごちゃごちゃすると9000x+4000y=Y-1000N
    //t=(Y-1000N)/1000と置くと9x+4y=t(Ymod1000=0よりtは整数)
    int t=(Y-1000*N)/1000;

    //x,yの解の一つとして(t,-2t)が考えられるので
    //9(x-t)+4(y+2t)=0
    //9(x-t)=4(y+2t)
    //9と4は互いに素なのでkを整数とするとx-t=4k
    //x=4k+t
    //代入すると36k=-4(y+2t)
    //y=-9k-2t
    //x,y,z>=0なので
    //4k+t>=0
    //-t/4<=k
    //-9k-2t>=0
    //k<=-2t/9
    //(4k+t)+(-9k-2t)<=N
    //-5k-t<=N
    //(-t-N)/5<=k
    //まとめ
    //max(-t/4,(-t-N)/5)<=k<=-2t/9
    int k = Max(-t/4,(-t-N)/5);
    int x=4*k+t;
    int y=-9*k-2*t;
    int z=N-x-y;
    if(x>=0&&y>=0&&z>=0){
        printf("%d %d %d\n",x,y,z);
    }else{
        printf("-1 -1 -1\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int n;
vector <int> A(10000, 0);

// 1 ≤ n ≤ 2,000,000
// 0 ≤ A[i] ≤ 10,000

void printA() {
    int p_count = 0;
    for (int i = 0; i < 10000; i++) {
        if (A[i] != 0) {
            while (A[i] > 0) {
                if (p_count != n - 1) {
                    cout << i << " ";
                } else {
                    cout << i << endl;
                }
                p_count++;
                A[i]--;
            }
        }
    }
}

int main(){
    cin >> n;

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

    printA();

    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


/*
Euclidean Algorithm
 */
ll euclid(ll a, ll b){
  while (b>0){
    a = a % b;
    swap(a, b);
  }
  return a;
}



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

  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i,N){ cin >> A[i];}

  //unordered_map<ll, bool> seen_map;
  vector<ll> primes(0); 
  REP(i,N){
    ll ai = A[i];
    //if (seen_map.find(ai) != seen_map.end()) continue;
    //seen_map[ai] = 1;
    //bool seen = false;
    for(ll& p : primes){
      //seen_map[ai] = 1;
      if (ai%p==0){
        ai /= p;
        //if (seen_map.find(ai) != seen_map.end()){
        //  seen = true;
        //  break;
        //}
      }
      if (ai==1) break;
    }
    
    //if (seen) continue;
    
    if (ai>0){
      /*
      Prime factorization
      */
      for(ll i=2; i*i<=ai; i++) {
        if (ai%i == 0) {
          while(ai%i==0) {
            //seen_map[ai] = 1;
            ai/=i;
            primes.push_back(i);
          }
        }
      }
    }
    if(ai>1){
      primes.push_back(ai);
      //seen_map[ai] = 1;
    }
  }

  sort(primes.begin(), primes.end());
  //for (ll& p : primes){ cout << p << " "; }
  //cout << "\n";
  
  ll ans = 0;
  REP(i,N){
    ll ai = A[i];
    ll bi = 1;
    for (ll& p : primes){
      if (ai%p==0){
        ai /= p;
      } else {
        bi *= p;
        bi %= MOD;
      }
    }
    ans += bi;
    ans %= MOD;
  }


  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
    int a[4],b[4];
    int i;
    int a_ans=0,b_ans=0;

    for(i = 0;i < 4; i++){
        scanf("%d",&a[i]);
        a_ans += a[i];
    }
    for(i = 0;i < 4; i++){
        scanf("%d",&b[i]);
        b_ans += b[i];
    }
    if(a_ans > b_ans)printf("%d\n",a_ans);
    else if(b_ans >= a_ans)printf("%d\n",b_ans);

    return 0;
}

Measured memory_bytes: 592
#include <iostream>

using namespace std;

int main(){
    int a, b;
    char c;
    while(1){
        cin >> a;
        cin >> c;
        cin >> b;
        if(c == '+'){
            cout << a + b << endl;
        }
        else if(c == '-'){
            cout << a - b << endl;
        }
        else if(c == '*'){
            cout << a * b << endl;
        }
        else if(c == '/'){
            cout << a / b << endl;
        }
        else if(c == '?'){
            break;
        }
        
    }
    
    
    return 0;
}


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

using namespace std;

int n;
int nxt[200050][27], dp[200050];
int main(){

	string s;
	cin >> s;
	n = s.length();
	for(int i = 0; i<26; i++){
		int temp = -1;
		for(int j = n-1; j>=0; j--){
			if(s[j]-'a' == i) temp = j;
			nxt[j][i] = temp;
		}
	}
	for(int i=n-1; i>=0; i--){
		dp[i] = INT_MAX/2;
		for(int j = 0; j<26; j++){
			if(nxt[i][j] == -1) dp[i] = 0;
			else dp[i] = min(dp[i], dp[nxt[i][j]+1]+1);
		}
	}
	// length of ans is dp[0]+1
	int len=dp[0]+1;
	int cur = 0;
//	for(int i= 0; i<n; i++) printf("%d ", dp[i]); printf("\n");
	while(len){
		for(int i = 0; i<26; i++){
			if(nxt[cur][i] == -1 or dp[nxt[cur][i]+1]<len-1){ 
				cout << (char) (i+'a'); 
				cur = nxt[cur][i]+1; 
				break; 
			} // if no more, yay
		}
		len--;
	}
}


Measured memory_bytes: 22404
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string cell[100];
    int H, W, i, j, k;
    cin >> H >> W;

    for(i = 0; i < H; i++)cin >> cell[i];

    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; 
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  
    for(i = 0; i < H; i++){
      for(j = 0; j < W; j++){
        if(cell[i][j] == '#')continue;

        int cnt = 0;
          for(k = 0; k < 8; k++){
            const int x = i + dy[k];
            const int y = j + dx[k];

            if(x < 0 or H <= x)continue;
            if(y < 0 or W <= y)continue;
            if(cell[x][y] == '#')cnt++;
          }
      cell[i][j] = char(cnt + '0');
      }
    }
   for(i = 0; i < H; i++)cout << cell[i] << endl;
}

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

#include <cassert>
using namespace std;

int n;
vector<int> a;

vector<vector<int>> wins;

vector<vector<int>> g;
vector<int> topSort;
vector<bool> used;

void BuildTopSort(int v) {
    used[v] = true;
    for (int u : g[v]) {
        if (!used[u]) {
            BuildTopSort(u);
        }
    }
    topSort.push_back(v);
}

vector<int> dp;

void Solve() {
    wins.clear();
    wins.resize(n);

    used.assign(n, false);
    g.clear();
    g.resize(n);
    for (int i = 1; i < n; ++i) {
        g[i].push_back(a[i]);
        wins[a[i]].push_back(i);
    }
    topSort.clear();
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            BuildTopSort(i);
        }
    }
    reverse(topSort.begin(), topSort.end());

    int result = 0;

    vector<int> buffer;
    buffer.reserve(n);

    dp.resize(n);
    for (int i = 0; i < n; ++i) {
        const int v = topSort[i];

        buffer.clear();
        for (int u : wins[v]) {
            buffer.push_back(dp[u]);
        }
        sort(buffer.begin(), buffer.end());

        dp[v] = wins[v].size();
        for (int j = 0; j < (int) buffer.size(); ++j) {
            int rj = (int) buffer.size() - j;
            dp[v] = max(dp[v], buffer[j] + rj);
        }

        result = max(result, dp[v]);
    }

    cout << result << endl;
}

bool Read() {
    if (!(cin >> n)) {
        return false;
    }
    a.resize(n);
    for (int i = 1; i < n; ++i) {
        cin >> a[i];
        --a[i];
    }
    return true;
}

int main() {
    // freopen("input.txt", "r", stdin);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (Read()) {
        Solve();
    }

    return 0;
}


Measured memory_bytes: 12540
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64


int main(){
    string s;
    cin >> s;
    int length;
    if(s.length() %2 == 0) length=s.length() /2 -1;
    else length = (s.length() - 1 ) /2;
    while(length > 0){
        if( s.substr(0,length) == s.substr(length,length)){
            cout << length*2 << endl;
            return 0;
        }
        length-=1;
    }
}

Measured memory_bytes: 256
// Code by Nguyen Huu Lam
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long LL;

#define y0 Sword_Art_Online
#define y1 Your_lie_in_April
#define yn Darling_in_the_Franxx
#define tm Plastic_Memories
#define lr Charlotte
#define norm Weathering_with_you
#define left Violet_Evergarden
#define have Date_a_live
#define ends Your_name
#define prev Five_centimeters_per_second
#define hash Slient_voice

#define ordered_set tree<LL, null_type, less<LL>, rb_tree_tag, tree_order_statistics_node_update>
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

LL Rand(LL l, LL h){
    return uniform_int_distribution<LL>(l, h)(rng);
}

template <typename T> void read(T &t){
    t = 0; char ch = getchar(); int f = 1;
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    do { (t *= 10) += ch - '0'; ch = getchar(); } while (isdigit(ch)); t *= f;
}

const LL MaxN = 1 + 1e5;

LL n, a[MaxN], m;

void InOut(){
    #define TASK "ABC"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
}

int main(){
    // InOut();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    cout << 6 - (n + m) << endl;

    return 0;
}

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

int main() {
  int N, x;
  cin >> N >> x;
  vector<int> A(N);
  for (int &e : A) cin >> e;
  sort(A.begin(), A.end());
  
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (x-A[i] < 0) {
      cout << count << endl;
      return 0;
    }
    x -= A[i];
    count += 1;  
  }
  
  if (x != 0) count -= 1;
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	char x, y, c;
	bool cup[3];
	cup[0] = true; cup[1] = false; cup[2] = false;
	while (cin >> x >> c >> y) {
		swap(cup[x - 'A'], cup[y - 'A']);
	}
	for (char i = 0; i < 3; i++) {
		if (cup[i] == true)cout << (char)('A' + i) << endl;
	}
	return 0;
}

Measured memory_bytes: 1132
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>

using namespace std;

int main()
{
    int n, k;
    long double p[200010];
    long double s[200010] = {};
    long double max = -1;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i] = p[i] * (p[i] + 1) / 2 / p[i];
    }

    for (int i = 0; i < n; i++) {
        s[i+1] += s[i] + p[i];
    }

    for (int i = k; i < n+1; i++) {
        if (max < s[i] - s[i-k]) {
            max = s[i] - s[i-k];
        }
    }

    cout << fixed << setprecision(15) << max << endl;

}


Measured memory_bytes: 6528
#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ifor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
template <class T>
class bit
{
public:
    vector<T> dat;
    int n;

    bit(int n) : n(n) { dat.assign(n, 0); }
    bit(int n, T ini) : n(n) { dat.assign(n, ini); }
    // sum [0,i)
    T sum(int i)
    {
        int ret = 0;
        for (--i; i >= 0; i = (i & (i + 1)) - 1)
            ret += dat[i];
        return ret;
    }
    // sum [i,j)
    T sum(int i, int j) { return sum(j) - sum(i); }
    // add x to i
    void add(int i, T x)
    {
        for (; i < n; i |= i + 1)
            dat[i] += x;
    }
};
int main()
{
    int n;
    lli k;
    lli a[200005];
    lli res = 0;
    cin >> n >> k;
    rep(i, n)
    {
        cin >> a[i];
    }
    lli sum = 0;
    map<lli, lli> f;
    f[sum]++;
    rep(i, n)
    {
        sum += a[i];
        f[(i + 1) * k - sum] += 1;
    }
    int cnt = 0;
    map<lli, lli> comp;
    for (auto s : f) {
        //cout << "hash " << cnt << " " << s.first;
        comp[s.first] = cnt;
        cnt++;
    }
    bit<lli> bi(n + 10);
    bi.add(comp[0], 1);
    sum = 0;
    rep(i, n)
    {
        if (i == 0) {
            if (a[i] >= k) {
                res++;
            }
            sum += a[i];
            lli val = (i + 1) * k - sum;
            bi.add(comp[val], 1);
        } else if (n != 1) {
            sum += a[i];
            res += i + 1 - bi.sum(comp[(i + 1) * k - sum]);
            bi.add(comp[(i + 1) * k - sum], 1);
        }
        //cout << sum << " " << res << endl;
    }
    cout << res << endl;
}


Measured memory_bytes: 28416
N=int(input().strip())
pays=[]
p1=set([1,])
n=6
while n<=N:
    p1.add(n)
    n*=6
n=9
while n<=N:
    p1.add(n)
    n*=9
pays.append(p1)
p2=p1
i=1
while i<=N:
    if N in p2:
        break
    else:
        p3=set()
        i+=1
        for i1 in p2:
            for i2 in p1:
                if i1+i2 <=N:
                    p3.add(i1+i2)
        p2=p3
print(i)

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

const int DIM = 1e5 + 5;

int cnt[DIM];

int main(void) {
    ios::sync_with_stdio(false);
    
    string str;
    cin >> str;
    
    for (char ch : str)
        cnt[ch] = 1;
    
    for (char ch = 'a'; ch <= 'z'; ++ch) {
        if (!cnt[ch]) {
            cout << ch;
            return 0;
        }
    }
    
    cout << "None";
    return 0;
}


Measured memory_bytes: 512
import java.io.*;
import java.util.*;

public class Main{

	public static void main(String[] args) throws IOException{
		
		/*
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		*/
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Integer> list = new ArrayList<Integer>();

		int[] heights = null;
		String str = "";

		str = br.readLine();
		heights = new int[str.length() + 1];
		heights[0] = 0;

		int height = 0;
		for(int i = 0; i < str.length(); i++){
			char c = str.charAt(i);
			switch(c){
				case '\\' :
					height--;
					break;
				case '/' :
					height++;
					break;
			}
			heights[i+1] = height;
		}
		int no = 0;
		int limit = str.length()+1;
		for(int i = 0; i < limit; i++){
			int tmin = heights[i];
			for(int j = i+1; j < limit; j++){
				if(heights[i] < heights[j]) break;
				if(heights[i] == heights[j]){
					if(tmin == heights[i]) break;
					else{
						list.add(i);
						list.add(j);
						no++;
						i = j-1;
						break;
					}
				}
				if(tmin > heights[j]) tmin = heights[j];
			}
		}

		double[] areas = new double[no];
		for(int i = 0; i < areas.length; i++){
			int start = list.get(i * 2);
			int end = list.get(i * 2 + 1);

			height = 0;
			double area = .0;
			for(int j = start; j < end; j++){
				char c = str.charAt(j);
				
				area = area + height;
				switch(c){
					case '\\' :
						height++;
						area += 0.5;
						break;
					case '/' :
						height--;
						area -= 0.5;
						break;
				}
			}
			areas[i] = area;
		}

		int sum = 0;
		for(int i = 0; i < areas.length; i++){
			sum += (int) areas[i];
		}
		System.out.printf("%d\n", sum);
		System.out.printf("%d", no);
		for(int i = 0; i < areas.length; i++){
			System.out.printf(" %d", (int) areas[i]);
		}
		System.out.printf("\n");
	}
}

Measured memory_bytes: 31520
#include <iostream>
#include <string>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;

int main(void) {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string one = std::string(ty - sy, 'U') + std::string(tx - sx, 'R');
    string two = std::string(ty - sy, 'D') + std::string(tx - sx, 'L');
    cout << one + two + "LU" + one + "RD" + "RD" + two + "LU" << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	rep2(i, 1, 1300){
		int az, bz;
		az = i * 0.08;
		bz = i * 0.1;
		if(az == a && bz == b){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  ll r,g,b,n;
  cin4(r,g,b,n);
  ll ans=0;
  loop(i,n/r+1){
    loop(j,(n-r*i)/g+1){
      if((n-i*r-j*g)%b==0)ans++;
    }
  }
  putout(ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String present = sc.next();
		if(present.startsWith("YAKI")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 23764
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

x = int(read())
cnt = 0
for i in range(45000):
    cnt += i
    if cnt >= x:
        print(i)
        exit()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iterator>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

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

    REP(i, M){
        cin >> tmp;
        N -= tmp;
    }

    if(N < 0) N=-1;

    cout << N << endl;


    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ul=unsigned long long;
int s[500],t[500],tmp[500][500],S[500],T[500],n,bit=-1,IN;
ul ans[500][500],u[500],v[500];

void ng(){
  cout<<-1;
  exit(0);
}

struct P{int va,idx,ve,ne,al;};
bool operator <(const P&a,const P&b){return a.va<b.va;};
priority_queue<P>que;

#define REP(i) for(int i=0;i<n;i++)
#define U ((u[i]>>bit)&1)
#define V ((v[j]>>bit)&1)

#define F(va) {\
  if(!~tmp[i][j]){\
    ans[i][j]+=((ul)1<<bit)*(tmp[i][j]=va);\
    if(++S[i]<n&&IN)que.push({S[i],i,'S',s[i],1});\
    if(++T[j]<n&&IN)que.push({T[j],j,'T',t[j],1});\
  }\
}

void AL(){
  int koushin=1;
  while(koushin--){
    REP(i)
      if(s[i]==U){
        bool f=0;
        REP(j)f|=tmp[i][j]==s[i];
        if(f)REP(j){koushin|=tmp[i][j]<0;F(s[i]^1);}
      }
    REP(j)
      if(t[j]==V){
        bool f=0;
        REP(i)f|=tmp[i][j]==t[j];
        if(f)REP(i){koushin|=tmp[i][j]<0;F(t[j]^1);}
      }
  }
}

int main(){
  cin>>n;
  REP(i)cin>>s[i];
  REP(i)cin>>t[i];
  REP(i)cin>>u[i];
  REP(i)cin>>v[i];

  while(++bit<64){
    memset(tmp,-1,sizeof(tmp));
    memset(S,0,sizeof(S));
    memset(T,0,sizeof(T));
    IN=0;

    REP(i)if(s[i]^U)REP(j)F(s[i]^1);
    REP(j)if(t[j]^V)REP(i)F(t[j]^1);
    REP(i)REP(j)if(s[i]==U&&U==t[j]&&t[j]==V)F(s[i]);

    AL();
    IN=1;
    REP(i)if(S[i]<n)que.push({S[i],i,'S',s[i],1});
    REP(j)if(T[j]<n)que.push({T[j],j,'T',t[j],1});

    while(que.size()){
      P p=que.top();que.pop();
      if(p.ve=='S'){
        int i=p.idx;
        if(p.va<S[i])continue;
        REP(j)
          if(!~tmp[i][j]){
            F(p.ne);
            p.ne^=p.al;p.al=0;
          }
        AL();
      }
      else{
        int j=p.idx;
        if(p.va<T[j])continue;
        REP(i)
          if(!~tmp[i][j]){
            F(p.ne);
            p.ne^=p.al;p.al=0;
          }
        AL();
      }
    }
  }

  REP(i){
    ul A=ans[i][0];
    REP(j)
      if(s[i])A|=ans[i][j];
      else A&=ans[i][j];
    if(A!=u[i])ng();
  }
  REP(j){
    ul A=ans[0][j];
    REP(i)
      if(t[j])A|=ans[i][j];
      else A&=ans[i][j];
    if(A!=v[j])ng();
  }

  REP(i){
    REP(j)cout<<ans[i][j]<<" ";cout<<endl;
  }
}

Measured memory_bytes: 18340
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
n, k  = map(int, input().split())
p  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

q = sum(p[:k])
max_ = (q, 0, k)
for i in range(k, n):
    q = q + p[i] - p[i-k]
    if max_[0] < q:
        max_ = (q, i-k+1, i+1)

ans = 0
for p_ in p[max_[1]:max_[2]]:
    ans += 1 + (p_ - 1) * 0.5

#print(max_)
print(ans)


Measured memory_bytes: 71792
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    S = readline().strip()
    N = len(S)

    for i in range(N-1):
        if S[i+1] == S[i]:
            print(i + 1, i + 2)
            exit()

    for i in range(N-2):
        if S[i+2] == S[i]:
            print(i + 1, i + 3)
            exit()
    
    print(-1, -1)


if __name__ == "__main__":
    main()


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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl			'\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int maxn = 1e5 + 5;
void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vector<int> primes;

	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}
set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		// int count = 0;
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}

int power(int x, unsigned int y, int p)
{
	int res = 1;

	x = x % p;

	if (x == 0) return 0;
	;
	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;

		y = y >> 1; // y = y/2
		x = (x * x) % p;
	}
	return res;

}

// Graph------------------------------------------------------------------------


int32_t main()
{
	FIO;
	// c_p_c();
	// --------------------------------------------------
	// Never GIVE UP !!!!

	int n, k;
	cin >> n >> k;
	mk(arr, n, int);
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}

	vi dp(n, 1e9 + 5);
	dp[0] = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j <= i + k; j++)
		{
			dp[j] = min(dp[j], dp[i] + abs(arr[j] - arr[i]));
		}
	}

	cout << dp[n - 1] << endl;

}


Measured memory_bytes: 4792
#include<stdio.h>
int main()
{
    int a,b,c,ans;
    scanf("%d %d %d",&a,&b,&c);
    if(a>=1&&a<=100)
    {
    if(b>=1&&b<=100)
    {
    if(c>=1&&c<=100)
    {
    if(c%2==0)
    {
    ans=((a+b)*c)/2;
    printf("%d\n",ans);
    }
    }
    }
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void) {
  int a;
  cin >> a;
  unsigned long long sum = 0;
  for (int i = 1; i <= a; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  cout << sum << endl;
}


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

int main() {
  string W;
  cin>>W;
  map<char,int> mp;
  for(char x='a';x<='z';x++){
    mp[x]=0;
    rep(i,W.size()){
     if(W[i]==x) mp[x]++;
    }
  }
  for(char x='a';x<='z';x++){
    if(mp[x] %2 != 0) {
      puts("No");  
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ull unsigned long long int
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007 

int main()
{
  fast
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output2.txt", "w", stdout);
  #endif

  ll n,m;
  cin>>n>>m;
  ll i,j;
  vector<ll> a(n);
  for(i=0;i<n;i++)
  {
    cin>>a[i];
  }
  make_heap(a.begin(), a.end()); 
  
  while(m!=0)
  {
    ll temp=a.front();
    temp/=2;

    pop_heap(a.begin(), a.end()); 
    a.pop_back(); 
    
    a.push_back(temp); 

    m--;
  }
  ll sum=0;
  for(auto it=a.begin();it!=a.end();it++)
  {
    sum+=(*it);
  }
  cout<<sum<<endl;

  return 0;
}

Measured memory_bytes: 3964
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
void calc(vector<ll>&mae,vector<ll>&a,int n){
    mae[0] = 0;
    priority_queue<ll,vector<ll>,greater<ll>>que;
    rep(i,n)que.push(a[i]);
    rep(i,n){
        que.push(a[i+n]);
        ll mi = que.top();
        que.pop();
        mae[i+1] = mi+mae[i];
    }
}
int main(){
    int n;
    cin >> n;
    vector<ll>a(3*n);
    ll sum = 0;
    rep(i,3*n){
        scanf("%lld",&a[i]);
        sum+=a[i];
    }
    vector<ll>c(n+1);
    rep(i,n){
        c[0] += a[3*n-1-i];
    }
    rep(i,n){
        c[i+1]+=c[i]+a[3*n-1-n-i];
    }
    vector<ll>mae(n+1);
    vector<ll>ushiro(n+1);
    calc(mae,a,n);
    reverse(a.begin(),a.end());
    rep(i,3*n)a[i]=-a[i];
    calc(ushiro,a,n);
    rep(i,n+1)ushiro[i]=-ushiro[i];
    ll ans = -(1LL<<62);
    rep(i,n+1){
        ans = max(ans, sum-mae[i]+ushiro[n-i]-2*c[n-i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6760
n=int(input())
s=[]
for n in range(n):
    s1=int(input())
    s.append(s1)
t=[i for i in s if i%10!=0]
lt=len(t)
su=sum(s)
ans=0
if su%10!=0:
    ans=su
else:
    if lt!=0:
        ans=su-min(t)
print(ans)

Measured memory_bytes: 3064