akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

template<typename M,typename N=M>
struct LazySegmentTree{
    using F=function<M(M,M)>; using G=function<M(M,N)>; using H=function<N(N,N)>;
    int sz,height; vector<M> data; vector<N> lazy;
    const F f;const G g; const H h; const M m1; const N n1;
    LazySegmentTree(int n,const F f,const G g,const H h,const M &m1,const N n1):f(f),g(g),h(h),m1(m1),n1(n1){
        sz=1,height=0; while(sz<n)sz<<=1,height++;
        data.assign(2*sz,m1); lazy.assign(2*sz,n1);
    }
    void build(vector<M> v){
        rep(i,0,v.size())data[i+sz]=v[i];
        rrep(k,sz-1,0)data[k]=f(data[2*k],data[2*k+1]);
    }
    M ref(int k){return lazy[k]==n1?data[k]:g(data[k],lazy[k]);}
    void recalc(int k){while(k>>=1)data[k]=f(ref(2*k),ref(2*k+1));}
    void thrust(int k){rrep(i,height,0)eval(k>>i);}
    void eval(int k){
        if(lazy[k]!=n1){
            lazy[2*k]=h(lazy[2*k],lazy[k]); lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
            data[k]=ref(k); lazy[k]=n1;
        }
    }
    void update(int a,int b,N x){
        thrust(a+=sz); thrust(b+=sz-1);
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
            if(l&1)lazy[l]=h(lazy[l],x),++l;
            if(r&1)--r,lazy[r]=h(lazy[r],x);
        }
        recalc(a); recalc(b);
    }
    M query(int a,int b){
        thrust(a+=sz); thrust(b+=sz-1);
        M L=m1,R=m1;
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
            if(l&1)L=f(L,ref(l++)); if(r&1)R=f(ref(--r),R);
        } return f(L,R);
    }
};

int main(){
   int n,q; scanf("%d%d",&n,&q);
   LazySegmentTree<ll> seg(n,
   [](ll a,ll b){return min(a,b);},
   [](ll a,ll b){return a+b;},
   [](ll a,ll b){return a+b;},INF,0);
   seg.build(vector<ll>(n,0));
   rep(i,0,q){
       int tmp; scanf("%d",&tmp);
       if(tmp==0){
           int s,t,x; scanf("%d%d%d",&s,&t,&x);
           t++; seg.update(s,t,x);
       }
       else{
           int s,t; scanf("%d%d",&s,&t); t++;
           printf("%d\n",seg.query(s,t));
       }
   }
   return 0;
}


Measured memory_bytes: 7596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int N;
    cin >> N;
    if(N%10 == 3){
        cout << "bon" << endl;
        return 0;
    }
    int a[] = {2,4,5,7,9};
    rep(i,5){
        if(N%10 == a[i]){
            cout << "hon" << endl;
            return 0;
        }
    }
    cout << "pon" << endl;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			String str = scan.next();
			if(str.equals("#")){
				break;
			}
			char city = 'A';
			for(int i = 0;i < str.length();i++){
				city = ans(city,str.charAt(i));
			}
			System.out.println((city == 'B')?"Yes":"No");
		}
	}
	
	public static char ans(char city,char road){
		switch(city){
		case 'A':
			return (road=='0')?'X':'Y';
		case 'B':
			return (road=='0')?'Y':'X';
		case 'X':
			return (road=='0')?'M':'Z';
		case 'Y':
			return (road=='0')?'X':'M';
		case 'W':
			return (road=='0')?'B':'Y';
		case 'Z':
			return (road=='0')?'W':'B';
		}
		return city;
	}
}

Measured memory_bytes: 17328
#include<bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define mod 1000000007LL
#define nax 200009LL
#define FOR(i,n,m) for(int i = (n); i < (m); i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())
 
 
typedef long long ll;
typedef vector<int> vi; 
typedef pair<int,int> ii;


int main(){
	fastio;

    ll x, y, a, b, c;
    cin>>x>>y>>a>>b>>c;
    vector<ll> r(a), g(b), q(c), ans;
    
    
    
    REP(i,a) cin>>r[i];
    REP(i,b) cin>>g[i];
    REP(i,c) cin>>q[i];

    sort(all(r));
    sort(all(g));
    sort(all(q));

    for(int i=sz(r)-1; i>=sz(r)-x; i--){
        ans.pb(r[i]);
    }
    for(int i=sz(g)-1; i>=sz(g)-y; i--){
        ans.pb(g[i]);
    }

    for(int i=sz(q)-1; i>=0; i--){
        ans.pb(q[i]);
    }
    ll sum=0;
    
    sort(all(ans));

    for(int i=sz(ans)-1; i>=sz(ans)-x-y; i--){
        sum+=ans[i];
    }

    cout<<sum;
	return 0;
}

Measured memory_bytes: 8688
#include<bits/stdc++.h>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    jaldi
    int n,m,pn;
    cin>>n>>m;
    string res;
    map<int,bool> mp;
    map<int,int> tmp;
    int ac=0,wa=0;
    for(int i=1;i<=m;i++)
    {
        cin>>pn>>res;
        if(res=="WA" && !mp[pn]) tmp[pn]++;
        if(res=="AC") mp[pn]=true;
    }
    for(int i=1;i<=n;i++)
    {
        if(mp[i])
        {
            ac++;
            wa+=tmp[i];
        }
    }
    cout<<ac<<" "<<wa;
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);	
    cin.tie(0);
	string s, ans = "";
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') ans += s[i];
		else if (s[i] == '1') ans += s[i];
		else if (s[i] == 'B') {
			if (ans.size() == 0) continue;
			ans.pop_back();
		}
	}
	cout << ans << "\n";
	return 0;
}


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

using namespace std;

#define F first
#define S second
//#define mp make_pair 
typedef long long ll;
#define int long long
#pragma GCC optimize("Ofast")

const int maxn = 2e5+10;
const int mod = 1e9+7;
const ll inf = 1e18+10;
//const int N = 2e6+10;

ll pw(ll a, ll b)
{
    if(b == 0) return 1;
    ll x = pw(a,b/2); x = (x*x) % mod;
    if(b & 1) x = (x*a) % mod;
    return x;
}

int n;
int a[maxn], dp[maxn];
map<int,int> sum;

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

    cin>> n;
    for(int i = 1; i <= n; i++)
    {
        cin>> a[i];
    }
    for(int i = 1; i <= n; i++)
    {
        if(a[i] == a[i-1]) 
            dp[i] = dp[i-1];
        else
            dp[i] = (dp[i-1] + sum[a[i]]) % mod;
        if(i == 1) dp[i] = 1;
        if(a[i] != a[i+1])
            (sum[a[i]] = dp[i]) %= mod;
     //   cout<< dp[i] <<" "<< sum[a[i]] <<"\n";
    }
    cout<< dp[n];
}


Measured memory_bytes: 15872
import Data.Array
import Data.Array.ST
createArr::[Char]->Array Char Int
createArr xs = runSTArray $ do
                        ar <- newArray ('a','z') 0
                        mapM_  (writer ar) xs
                        return ar
                          where writer ar c = do
                                            v<-readArray ar c
                                            writeArray ar c (v+1)

solver::[Char]->String
solver xs = if (and.(map (\x->x <= 1)).elems.createArr) xs then "yes" else "no"

main::IO()
main= do
  d<-getLine
  putStr ((solver d)++"\n")

Measured memory_bytes: 508
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define FF first
#define SS second
#define pii pair<int,int>
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(x) (int)x.size()
#define mp make_pair
#define Mod 1000000007
typedef long long int ll;

// dp[i][j] -> number of wyas of reaching the cell (i,j)

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// #endif

	int h, w, i, j;
	cin >> h >> w;
	vector<string> grid(h);

	for(i = 0; i < h; i++){
		cin >> grid[i];
		// cout<<grid[i]<<"\n";
	}

	vector<vector<int>> dp(h, vector<int>(w));
	
	for(i = 0; i < h; i++)
		for(j = 0; j < w; j++)
			dp[i][j] = 0;
	dp[0][0] = 1;

	for(i = 0; i < h; i++)
		for(j = 0; j < w; j++){
			if(i > 0 && grid[i-1][j] != '#')
				dp[i][j] += dp[i-1][j];
			if(j > 0 && grid[i][j-1] != '#')
				dp[i][j] += dp[i][j-1];

			dp[i][j] %= Mod;
		}

	cout<<dp[h-1][w-1]%Mod;
}

Measured memory_bytes: 5248
#include<stdio.h>

int main(void){
    int time,h,m,s;
    scanf("%d",&time);
    h = time/(60*60);
    m = (time- (h*60*60)) / 60;
    s = time - (h*60*60) - m*60;
    
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  char c;
  cin>>a>>c>>b;
  if(c=='+') cout<<a+b<<endl;
  else cout<<a-b<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)

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



int main(){
    
    int n,a,M=0,m=INF;
    
    cin>>n;
    rep(i,0,n){
        cin>>a;
        M=max(a,M);
        m=min(a,m);
    }
    cout<<M-m<<endl;
        
    return 0;
}

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

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;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#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 yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

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);

    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll q;
    cin >> q;

    REP(i, q) {
        ll k;
        cin >> k;

        ll dnum = 0;
        ll mnum = 0;
        ll dmnum = 0;
        ll ans = 0;
        REP(j, n) {
            //remove
            if (k <= j) {
                if (s[j - k] == 'D') {
                    dnum--;
                    dmnum -= mnum;
                }
                if (s[j-k] == 'M')
                    mnum--;
            }

            //add
            {
                if (s[j] == 'D')
                    dnum++;
                if (s[j] == 'M') {
                    mnum++;
                    dmnum += dnum;
                }
                if (s[j] == 'C')
                    ans+=dmnum;
            }
        }


        cout << ans << endl;
    }


}




Measured memory_bytes: 4268
x1, y1, x2, y2 = map(int, input().split())
xd = x2 - x1
yd = y2 - y1
x3 = x2 - yd
y3 = y2 + xd
x4 = x1 - yd
y4 = y1 + xd
print(x3,y3,x4,y4)

Measured memory_bytes: 3060
/*
Original problem: https://atcoder.jp/contests/dp/tasks/dp_p
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 1e9+7;

namespace SOLVE {
	int n;
	vector<VLL> E;
	vector<VLL> dp;

	void dfs(int v, int prev) {
		ll white = 1, black = 1;
		for (int e : E[v]) {
			if (e != prev) {
				dfs(e, v);

				white *= ((dp[e][0] + dp[e][1]) % mod);
				white %= mod;

				black *= (dp[e][0]);
				black %= mod;
			}
		}

		dp[v][0] = white;
		dp[v][1] = black;
	}

    void main() {
        int a,b;
		cin >> n;
		E.resize(n+1);

		REP(i,0,n-1){
			cin >> a >> b;
			E[a].push_back(b);
			E[b].push_back(a);
		}

		dp.resize(n+1, VLL(2)); // dp[i][black] gives the possibilities if it was white/black

		// rooted at 1: ans is 1,white + 1,black
		dfs(1, 0);
		ll ans = (dp[1][0] + dp[1][1]) % mod;
		cout << ans << endl;
    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  if (S[K-1] == 'A') {
    S[K-1] = 'a';
    cout << S << endl;
  }
  else if (S[K-1] == 'B') {
    S[K-1] = 'b';
    cout << S << endl;
  }
  else if (S[K-1] == 'C') {
    S[K-1] = 'c';
    cout << S << endl;
  }
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var res = a * b - a - b + 1;
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <float.h>
#include <queue>
#include <cstdio>
#include <iomanip>

using namespace std;

string s;

int main(){
  cin >> s;
  if (s =="Rainy") cout << "Sunny"<<endl;
  else if (s=="Sunny") cout << "Cloudy" <<endl;
  else if (s=="Cloudy") cout << "Rainy"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

typedef long long ll;

int main() {
	int n;
	scanf("%d", &n);
	
	ll p = 1e9 + 7;
	ll sa = 0, saa = 0;
	for (int i = 0; i < n; i++) {
		ll ai;
		scanf("%lld", &ai);
		
		sa += ai;
		sa %= p;
		saa += (ai * ai) % p;
		saa %= p;
	}
	ll ans2 = sa * sa - saa;
	ll ans;
	if (ans2 % 2 == 0)
	{
		ans = (ans2 + 2 * p) / 2;
	}
	else
	{
		ans = (ans2 + p) / 2;
	}
	printf("%lld", ans % p);
	
	
	
	
	return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>

#include <map>
 
using namespace std;
typedef long long ll;

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


ll ans,mx,sum,mn=1e8,flag;
int main(){
	ll n,x;
	cin>>n;
	ll a[n];
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
	sort(a,a+n);
	reverse(a,a+n);
	for(ll i=0; i<n; i++){
		if(a[i]==a[i+1] && i < n){
			ans = a[i];
			flag = i+1;
			break;
		}
	}
	for(int i=flag+1; i<n; i++){
		if(a[i]==a[i+1] && i <n){
			sum = a[i];
			break;
		}
	}
	cout<<ans *sum<<endl;
}



Measured memory_bytes: 1024
import Control.Monad
import Data.Maybe
import Data.List
import qualified Data.ByteString.Char8 as BS

main = abc159a

abc159a = do
  [n, m] <- getIntList
  print $ comb n + comb m

comb :: Integer -> Integer
comb k
    | k < 2 = 0
    | otherwise = div (k * (fromIntegral k - 1)) 2

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        sum+=x[i];
    }
    int v = (int)sum/n+1;
    int v2 = (int)sum/n;
    int ans = 0;
    int ans2 = 0;
    for (int i = 0; i < n; i++) {
        ans+=pow(abs(v-x[i]),2);
        ans2+=pow(abs(v2-x[i]),2);
    }
    cout << (ans < ans2 ? ans:ans2) << endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
a = list(map(lambda x: int(x)-1, input().split()))

if a[0] == 0:
    print(1)
    exit()

rec = [0]
s = set()
s.add(0)
cur = 0
while True:
    to = a[cur]
    if to in s:
        start = rec.index(to)
        cycle = len(rec)-start
        break
    rec.append(to)
    s.add(to)
    cur = to

if start > k:
    print(rec[k]+1)
    exit()
k -= start
print(rec[start+(k%cycle)]+1)



Measured memory_bytes: 126516
#include<iostream>
using namespace std;
int main() {
	int ans, n;
	cin >> n;
	if (n==100000) {
		ans = 90909;
	}
	else if (n>=10000) {
		ans = 909 + (n - 9999);
	}
	else if (n >= 1000) {
		ans = 909;
	}
	else if (n >= 100) {
		ans = 9 + (n - 99);
	}
	else if (n >= 10) {
		ans = 9;
	}
	else {
		ans = n;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <string.h>

int main() {
    char days[7][4] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    char in[4];
    std::cin >> in;

    for (int i = 0; i < 7; i++) {
        if (strcmp(in, days[i]) == 0) {
            std::cout << - (i - 7) << std::endl;
            return 0;
        }
    }
}


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


int main(){
    int k;
    cin >> k;
    int a,b;
    cin >> a>> b;
    int c = b/k;
    if(c*k>=a) cout << "OK" << endl;
    else cout << "NG" <<endl;
   }

Measured memory_bytes: 3632
N = int(input())
A = list(map(int, input().split()))

ans = 0
even = [a % 2 == 0 for a in A]
for i in range(2 ** N):
    tmp = even.copy()
    cnt = 0
    for j in range(N):
        if ((i >> j) & 1):
            tmp[j] = not tmp[j]
            cnt += 1
    if sum(tmp) > 0:
        ans += 2 ** cnt if i != 0 else 1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  for (int i = 0; i < N; i++){
	  cin >> card.at(i);
  }
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  int A = 0;
  int B = 0;
  for (int i = 0; i < N; i += 2){
	  A += card.at(i);
  }
  for (int i = 1; i < N; i += 2){
	  B += card.at(i);
  }
  cout << A - B << endl;
}


Measured memory_bytes: 256
//package atcoder;
 
import java.util.*;
import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int S[] = new int [N];
		int count = 0;
		boolean ok[] = new boolean[N];
		Arrays.fill(ok, true);
	
		if(M==0&&N==1) {
			System.out.println(0);
			System.exit(0);
		}
		for(int j=0;j<M;j++) {
			int n = sc.nextInt();
			int c = sc.nextInt();
			if(ok[n-1]){
				S[n-1] = c;
				ok[n-1] = false;
				if(N!=1&&n==1&&S[0]==0) {
					System.out.println(-1);
					System.exit(0);
					
					
				}
			}else {
				if(S[n-1]!=c) {
					System.out.println(-1);
					System.exit(0);
					//return;
				}
			}
		}
		
		if(ok[0]) {
			S[0] = 	1;
			for(int k=0;k<N;k++) {
				System.out.print(S[k]);
				
			}
			System.exit(0);
		}
		for(int l=0;l<N;l++) {
		System.out.print(S[l]);
		}
	}
}

Measured memory_bytes: 22996
package main

import (
	"bufio"
	"fmt"
	"os"
)

const Inf = 1 << 60

func main() {
	a, b, c, d := ReadInt(), ReadInt(), ReadInt(), ReadInt()
	ans := -Inf
	for _, x := range []int{a, b} {
		for _, y := range []int{c, d} {
			if ans < x*y {
				ans = x * y
			}
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include<stdio.h>

int search(int a[], int n, int key){
    int i = 0;
    a[n] = key;
    while(a[i] != key) i++;
    return i != n;
}

int main(){
    int i, n, a[10000+1], q, key, sum = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    scanf("%d", &q);
    for (i = 0; i < q; i++){
        scanf("%d", &key);
        if (search(a, n, key)) sum++;
    }

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

}


Measured memory_bytes: 2100
#include<iostream>
#include<climits>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
int main(){

	int n,a,b;
	cin >> n;
	if(n==1){
		cout << "Hello World" << endl;
	}else{
		cin >> a;
		cin >> b;
		cout << a+ b << endl;

	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n, price;
	scanf("%d %d", &n, &price);
	price /= 1000;
	int x, y, z;
	for (x = 0; x * 10 <= price&&x <= n; x++)
	{
		for (y = 0; y * 5 <= price - x * 10 && x + y <= n; y++)
		{
			z = n - x - y;
			if (price == x * 10 + y * 5 + z)
			{
				printf("%d %d %d", x, y, z);
				return 0;
			}
		}
	}
	printf("-1 -1 -1");
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
using namespace std;
int main(void)
{
	ll n;
	cin>>n;
	ll a[n], i;
	for(i=0; i<n; i++)
		cin>>a[i];
	ll ans[n];
	ans[n-1] = 0;
	ans[n-2] = abs(a[n-1]-a[n-2]);
	for(i=n-3; i>=0; i--)
		ans[i] = min(ans[i+1] + abs(a[i]-a[i+1]), ans[i+2] + abs(a[i]-a[i+2]));
	cout<<ans[0]<<"\n";
}		

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin,(a).rend()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	int n = s.size();
	reverse(all(s));
	vector<string> q = { "maerd","remaerd","esare","resare" };
	int i = 0;
	for (; i < n;) {
		bool elf = false;
		rep(j, 4) {
			if (s.substr(i, q[j].size()) == q[j]) {
				elf = true;
				i += q[j].size();
				break;
			}
		}
		if (!elf) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

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

int main() {
	int d,t,s;
	cin >> d >> t >> s;
	if (s*t>=d) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int facctorialMethod(int k);

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

    if(N == 1 && M == 1 || N == 0 && M == 0) {
        cout << 0 << endl;
    } else if(N == 1 || N == 0) {
        cout << facctorialMethod(M - 1) << endl;
    } else if(M == 1 || M == 0) {
        cout << facctorialMethod(N - 1) << endl;
    } else if(N == 2 && M == 2) {
        cout << 2 << endl;
    } else if(N == 2) {
        cout << 1 + facctorialMethod(M - 1) << endl;
    } else if(M == 2) {
        cout << facctorialMethod(N - 1) + 1 << endl;
    } else if(N == 3 && M == 3) {
        cout << 2 << endl;
    } else if(N == 3) {
        cout << 3 + facctorialMethod(M - 1) << endl;
    } else if(M == 3) {
        cout << facctorialMethod(N - 1) + 3 << endl;
    } else {
        cout << facctorialMethod(N - 1) + facctorialMethod(M - 1) << endl;
    }

    return 0;
}

int facctorialMethod(int k) {
    int sum = 0;
    for(int i = 1; i <= k; ++i) {
        sum += i;
    }
    return sum;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>


using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================

vpll prime_factor;
void div_prime(ll n)
{
	for (ll i = 2; i * i <= n; i++)
	{
		ll count = 0;
		while (n % i == 0)
		{
			count++;
			n /= i;
		}
		if (count)
		{
			pair<ll, ll> temp = { i, count };
			prime_factor.emplace_back(temp);
		}
	}
	if (n != 1)
	{
		pair<ll, ll> temp = { n, 1 };
		prime_factor.emplace_back(temp);
	}
}

int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================


	ll N, P;
	cin >> N >> P;


	div_prime(P);

	ll ans = 1;
	for (int i = 0; i < prime_factor.size(); i++)
	{
		ans *= pow(prime_factor[i].first, (prime_factor[i].second / N));
	}

	cout << ans << endl;




}





Measured memory_bytes: 384
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ni()
S = [ns() for _ in range(2)]
ct = [0] * N
if S[0][0] == S[1][0]:
    ct[0] = 3
else:
    ct[0] = 6

for i in range(N-1):
    if S[0][i] == S[1][i]:
        if S[0][i+1] == S[1][i+1] and S[0][i] == S[0][i+1]:
            ct[i+1] = ct[i]
        else:
            ct[i+1] = (ct[i] * 2) % mod
    else:
        if S[0][i] != S[0][i+1] and S[1][i] != S[1][i+1] and S[0][i+1] != S[1][i+1]:
            ct[i+1] = (ct[i] * 3) % mod
        else:
            ct[i+1] = ct[i]
print(ct[N-1])




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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

int main() {
    int A, B, C; cin >> A >> B >> C;
    if(A + B + C == 17) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3588
n , m = map(int, input().split())
combis = [set(list(map(int, input().split()))) for i in range(m)]
count = 0
for i in range(m):
    combis_x = combis[0:i] + combis[i+1:m]
    islands = []
    for combi in combis_x:
        # init
        if not islands:
            islands.append(combi)
            continue
        # compare existed islands
        new_islands = islands
        joint_i = []
        for j, island in enumerate(islands):
            if not island.isdisjoint(combi):
                new_islands[j] = island | combi
                joint_i.append(j)
        else:
            if not joint_i:
                new_islands.append(combi)
            elif len(joint_i) == 2:
                new_islands[joint_i[0]] = new_islands[joint_i[0]] | new_islands[joint_i[1]]
                new_islands.pop(joint_i[1])
        islands = new_islands

    # judge
    if len(islands) == 1 and len(islands[0]) == n:
        continue
    elif len(islands) == 1 and len(islands[0]) == n - 1:
        count += 1
    else:# len(islands) == 2 and islands[0].isdisjoint(islands[1]):
        count += 1
print(count)



Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;


int main()
{
    double a,b,c,d;
    scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
    printf("%f ",a*b/2.0);
    if(c==a/2.0&&d==b/2.0)
        printf("1\n");
    else
        printf("0\n");
    return 0;
}

Measured memory_bytes: 256
from fractions import Fraction
from collections import deque
import math

A,B,C,D,E,F = map(int, input().split())

# 作りうる水の量を洗い出す
waters = set()
waters.add(100*A)
if 200*B <= F:
    waters.add(200*B)
q = deque([100*A, 200*B])

while q:
    w = q.popleft()
    # 容器に入れられる量より多いならパス
    if w > F: continue
    for n in [100*A, 200*B]:
        if w + n <= F:
            waters.add(w + n)
            q.append(w + n)

waters = list(waters)
waters.sort()



# 最大濃度
max_conc = -1
# 最大濃度の時の水と砂糖
total = -1
sugar = -1

# それぞれの水量についてなるべく多く砂糖を入れてみる
for w in waters:
    # 砂糖の解けることができる量
    limit = math.floor(w * Fraction(E,100))
    # 全体でFまでしか入らないので、F-wとlimitの小さいほうまでしか追加できない
    limit = min(limit, F - w)
    # Cをi回、Dをj回追加する
    max_sugar = 0
    for i in range(limit // C + 1):
        tmp = C * i + ((limit - C*i) // D) * D
        
        max_sugar = max(max_sugar, tmp)
    if max_conc < Fraction(max_sugar, (w+max_sugar)):
        max_conc = Fraction(max_sugar, (w+max_sugar))
        total = w+max_sugar
        sugar = max_sugar

print(total, sugar)


Measured memory_bytes: 5048
H,W=map(int,input().split())
grid=[None]*H
for i in range(H):
  grid[i]=input()
  
from collections import deque
ans=0

INF=10**9
ans=0
for i in range(H):
  for j in range(W):
    dist=[[INF for j in range(W)] for i in range(H)]
    q=deque()
    q.append([i,j,0])
    while q:
      node=q.popleft()
      y=node[0]
      x=node[1]
      d=node[2]
      if grid[y][x]=="#":
        continue
      if dist[y][x]<=d:
        continue
      if ans<d:
        ans=d
      dist[y][x]=d
      cases=((0,1),(0,-1),(1,0),(-1,0))
      for c in cases:
        if 0<=y+c[0]<H and 0<=x+c[1]<W:
          q.append([y+c[0],x+c[1],d+1])
      
print(ans)

Measured memory_bytes: 3316
from functools import lru_cache

def main():
    n=int(input())
    dp=[float("inf")]*(n+1)
    dp[0]=0
    for i in range(n):
        dp[i+1] = min(dp[i+1], dp[i]+1)
        j,k = 6,9
        while i+j <= n:
            dp[i+j] = min(dp[i+j], dp[i]+1)
            j *= 6
        while i+k <= n:
            dp[i+k] = min(dp[i+k], dp[i]+1)
            k *= 9
    print(dp[-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 9924
#include <iostream>
using namespace std;
int main () {
    int i = 1;
    int n;
    cin >> n;
    while (i <= n) {
        bool out = false;
        if (i % 3 == 0)
            out = true;
        int x = i;
        while (x != 0) {
            if (x % 10 == 3)
                out = true;
            x /= 10;
        }
        if (out) 
            cout << " " << i; 
        ++i;
    }
    cout << "\n";
}


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

const long long mod = 1e9 + 7;

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

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

  long long ans = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < i; j++){
      if(A[j] < A[i]){
	ans += static_cast<long long>(K) * (K - 1) / 2;
	ans %= mod;
      }
    }
    for(int j = i + 1; j < N; j++){
      if(A[j] < A[i]){
	ans += static_cast<long long>(K) * (K + 1) / 2;
	ans %= mod;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	if((a * 100 + b * 10 + c) % 4 == 0) cout << "YES";
	else cout << "NO";
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
c=[]
for i in range(10):
    c.append(list(map(int,input().split())))
a=[]
for i in range(h):
    a.append(list(map(int,input().split())))


for k in range(10):
    for  i in range(10):
        for j in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])

s=0
for i in range(h):
    for j in range(w):
        if a[i][j]!=-1:
            s+=c[a[i][j]][1]
print(s)

Measured memory_bytes: 3316
#include <stdio.h>

int main(void) {
	int a,b,c;
	int t,et,tt,dt;
	int s;
	t=et=tt=dt=0;
	while(scanf("%d%d%d",&a,&b,&c)==3) {
		if(a>b){s=a;a=b;b=s;}
		if(b>c){s=b;b=c;c=s;}
		if(a>b){s=a;a=b;b=s;}
		if(a+b>c && b-a<c) {
			t++;
			if(a*a+b*b==c*c)tt++;
			else if(a*a+b*b>c*c)et++;
			else dt++;
		} else break;
	}
	printf("%d %d %d %d\n",t,tt,et,dt);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main() {
	string S;
	cin >> S;
	int n = 0;
	int s = 0;
	int w = 0;
	int e = 0;
	int Ssize = S.size();
	for (int i = 0; i < Ssize; i++) {
		if (S[i] == 'N' && n == 0) {
			n++;
		} else if (S[i] == 'S' && s == 0) {
			s++;
		} else if (S[i] == 'E' && e == 0) {
			e++;
		} else if (S[i] == 'W' && w == 0) {
			w++;
		}
	}
	//cout << "n:" << n << " s:" << s << " e:" << e << " w:" << w << endl;
	if (n != s) {
		cout << "No" << endl;
		return 0;
	}
	if (e != w) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
class UnionFind():
    # 全ての要素が別グループとして初期化
    def __init__(self, n):
        self.par = [i for i in range(n)]  # 要素の親の番号
        self.rank = [0 for _ in range(n)]  # グループの木の深さ
        self.size = [1 for _ in range(n)]  # グループのサイズ

    # 木の根を求める
    def find(self, x):
        if self.par[x] == x:  # 自分が親 =根
            return x
        else:
            self.par[x] = self.find(self.par[x])  # 自分の親の根を探し、それを自分の親とする(再帰)
            return self.par[x]

    # x,yが属する集合を結合する
    def unite(self, x, y):
        # それぞれの親を見つける
        x = self.find(x)
        y = self.find(y)
        if x == y:
            pass
        else:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x  # yの親をxにする
            self.size[x] += self.size[y]  # 親のサイズのみ正しい

    # x,yが属する集合が同じかを判別する
    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]


n, m = map(int,input().split())

uf = UnionFind(n)
for i in range(m):
    a,b=map(int,input().split())
    uf.unite(a-1,b-1)

# 正しい結果を得るために全要素をfindで確認する必要がある
for i in range(n):
    uf.find(i)

print(max(uf.size))

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

char s[1000010];
char t[1000010];

int n;

queue<int> q;

int main() {
	scanf("%d", &n); scanf("%s", s); scanf("%s", t);
	if(strcmp(s, t) == 0) { puts("0"); return 0; }
	int k = n - 1;
	int ans = 0;
	int last = -1;
	for(int i = n - 1; i >= 0; --i) {
		k = min(k, i);
		while(k >= 0 && s[k] != t[i]) --k;
		if(k < 0) { puts("-1"); return 0; }
		if(k==last) continue; last=k;
		while(q.size() && i < q.front() - (int)q.size() + 1) q.pop();
		q.push(k);
		ans = max(ans, (int)q.size());
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<int,int>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<60
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 1000000007;

inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;
x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17 -I .
//push_back -> emplace_back
int h,w;
vector<string>m;
bool seen[410][410];
ll res=0;
ll numb=0,numw=0;
void dfs(int y,int x){
   seen[y][x]=true;
   if(m[y][x]=='#')++numb;
   else ++numw;
   rep(i,4){
      int ny=y+dy[i],nx=x+dx[i];
      if(nx<0 || ny<0  || ny>=h || nx>=w)continue;
      if(m[y][x]==m[ny][nx])continue;
      if(seen[ny][nx])continue;
      dfs(ny,nx);
   }
   
}

int main(){
   cin>>h>>w;
   m.resize(h);
   CLR(seen);
   rep(i,h)cin>>m[i];
   rep(y,h)rep(x,w){
      if(m[y][x]=='.')continue;
      if(seen[y][x])continue;
      numb=numw=0;
      dfs(y,x);
      res+=numb*numw;
   }
   cout<<res<<endl;
}

Measured memory_bytes: 16492
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

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

    sort(ALL(A));
    reverse(ALL(A));

    ll dp[N + 2][N + 2];
    memset(dp, 0, sizeof(dp));

    REP(i, N) {
        REP(y, i + 2) {
            int x = i - y + 1;
            if (x > 0) dp[x][y] = max(dp[x][y], dp[x - 1][y] + A[i].fi * (A[i].se - x + 1));
            if (y > 0) dp[x][y] = max(dp[x][y], dp[x][y - 1] + A[i].fi * (N - y - A[i].se));
        }
    }

    ll ans = 0;
    REP(i, N) {
        ans = max(ans, dp[N - i][i]);
    }
    print(ans);
}


Measured memory_bytes: 35004
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static System.Math;
class Program
{
    public static void Main(string[] args)
    {
        var s = Console.ReadLine();
        var l = s.Length;
        var isBlack = true;
        int count = 0;
        foreach (var c in s)
        {
            if (isBlack)
            {
                if (c == '0')
                {
                    count++;
                }
            }
            else
            {
                if (c == '1')
                {
                    count++;
                }
            }

            isBlack ^= true;
        }

        Console.WriteLine(Min(count, (l - count)));
    }
}

Measured memory_bytes: 13244
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W

int main() {
    int N, R;
    cin >> N >> R;
    int ans = R;
    if(N < 10) {
        ans += 100* (10-N);
    }
    cout << ans << endl;

}



Measured memory_bytes: 256
N=gets.to_i
g=Array.new(N){[]}
(N-1).times do
  a,b,c = gets.split.map(&:to_i)
  g[a-1] << [b-1, c]
  g[b-1] << [a-1, c]
end

Q,K = gets.split.map(&:to_i)
stack = []
stack << [K-1, 0] # start, depth
depth = Array.new(N,-1) # depth from K-1
while !stack.empty?
  s, d = stack.pop
  depth[s] = d
  g[s].each do |(to, cost)|
    stack << [to, d+cost] if depth[to] == -1
  end
end
ans = []
Q.times do
  x,y = gets.split.map(&:to_i)
  ans << depth[x-1]+depth[y-1]
end
puts ans

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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}

int n, m, a[211];

int main() {
	megaRandom();
	scanf("%d%d", &n, &m);
	int tmp = 0;
	for(int i = 1; i <= m; i ++) {
		scanf("%d", &a[i]);
		tmp += (a[i] % 2);	
	}
	if(tmp > 2) {
		puts("Impossible");
		return 0;
	}
	for(int i = 2; i < m; i ++) {
		if(a[i] & 1) {
			if(a[1] & 1) swap(a[m], a[i]);
			else         swap(a[1], a[i]);	
		}
	}
	for(int i = 1; i <= m; i ++)
		printf("%d ", a[i]);
	printf("\n");
	if(m == 1) {
		if(n == 1) printf("1\n1"); 
		else       printf("2\n%d %d", a[1] - 1, 1);
		return 0;
	}
	a[1] --, a[m] ++;
	if(a[1] == 0) 
		printf("%d\n", m - 1);
	else 
		printf("%d\n", m);
	for(int i = 1; i <= m; i ++)
		if(a[i] > 0)
			printf("%d ", a[i]);

	return 0;  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){

    string s;
    cin >> s;

    ll n = 0;
    rep(i, 0, s.size()){
        if(s[i] != s[s.size() - 1 - i]){
            n++;
            s[i] = s[s.size() - 1 - i];
        }
    }
    cout << n << endl;

    return 0;
}


Measured memory_bytes: 256
MOD = 998244353



def dp_range(l, r):
    left = 0 if l-1 < 0 else dp_acc[l-1]
    right = 0 if r < 0 else dp_acc[r]
    return right - left

N, K = map(int, input().split())
segments = [tuple(map(int, input().split())) for _ in range(K)]
dp = [0] * (2 * N + 1)
dp_acc = [0] * (2 * N + 1)

dp[0], dp_acc[0] = 1, 1


for i in range(N):
    for j in range(K):
        dp[i] += dp_range(i - segments[j][1], i - segments[j][0])
        dp[i] %= MOD
        dp_acc[i] = (dp_acc[i - 1] + dp[i]) % MOD
print(dp[N-1])


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

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    int64_t ans = 0;
    while(true){
        bool updated = false;
        for(int i=0; i<N; i++){
            int64_t d = A[i]/N;
            ans += d;
            if(d > 0) updated = true;
            A[i] %= N;
            for(int j=0; j<N; j++) if(j!=i) A[j] += d;
        }
        if(!updated) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256