akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int main(){
  string S;
  cin >> S;
  
  bool strong = true;
  int n = S.size();
  for(int i = 0; i < n - i - 1; i++){
    if(S[i] != S[n - i - 1]){
      strong = false;
    }
  }
  
  for(int i = 0; i < n / 2 - i - 1; i++){
    if(S[i] != S[n / 2 - i - 1]){
      strong = false;
    }
  }
  
  for(int i = 0; n / 2 + i + 1 < n - i - 1; i++){
    if(S[i + n / 2 + 1] != S[n - i - 1]){
      strong = false;
    }
  }
  
  if(strong) puts("Yes");
  else puts("No");
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans=20051216,cnt;
string a,b;
int l[2222],r[2222],mx[2222];
void get_l_r(){
	for(int i=0;i<n;i++){
		for(r[i]=0;b[(i+r[i])%n]=='0';r[i]++);
		for(l[i]=0;b[(i-l[i]+n)%n]=='0';l[i]++);
	}
}
void solve(int x){
	memset(mx,0,sizeof mx);
	cnt=0;
	for(int i=0;i<n;i++){
		if(a[i]!=b[(x+i)%n])mx[l[i]]=max(mx[l[i]],r[i]),cnt++;
	}
	for(int i=n-1,Mx=0;i>=0;i--){
		ans=min(ans,i+i+Mx+abs(x-Mx)+cnt);
		Mx=max(Mx,mx[i]);
	}
}
int main(){
	cin>>a>>b;int cnta=0,cntb=0;
	for(char c:a)cnta+=(c-'0');
	for(char c:b)cntb+=(c-'0');
	if(!cntb){
		cout<<(-(cnta>0))<<endl;
		return 0;
	}n=a.size();
	get_l_r();
	for(int i=0;i<n;i++)solve(i);
	cnt=0;
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	get_l_r();
	for(int i=0;i<n;i++)solve(i);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/* 

*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <bitset>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define LSOne(S) (S & (-S))
#define EPS 1e-9
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pd;
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

inline bool IsOn(int& mask, int& b)
{
    return (mask & (1 << b));
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0); // BEFORE SUBMIT DON'T FORGET TO UNCOMMENT THIS
    int n;
    cin >> n;
    vector<vector<int>> score(n, vector<int>(n));
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            cin >> score[i][j];
        }
    }    

    int limit = (1 << n);
    vector<ll> sum(limit);

    for(int mask = 0; mask < limit; ++mask)
    {
        for(int j = 0; j < n; ++j)
        {
            for(int k = j+1; k < n; ++k)
            {
                if(IsOn(mask, j) && IsOn(mask, k))
                {
                    sum[mask] += score[j][k];
                }
            }
        }
    }

    vector<ll> dp(limit); // Max score if '1' bit in mask is already part of a group
    for(int mask = 0; mask < limit; ++mask)
    {
        for(int submask = mask; ; submask = (submask-1) & mask)
        {
            dp[mask] = max(dp[mask], dp[submask] + sum[mask ^ submask]);
            if(submask == 0) break;
        }
    }
    cout << dp[limit-1] << "\n";
    return 0; 
}


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

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

  ll ans = (n * (n + 1) / 2) - n;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b==c||a+c==b||c+b==a){
		cout<<"Yes"<<endl;
		//return 0;
	}else{
	  cout<<"No"<<endl;	
	}

	return 0;
} 

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin >> a.at(i);
	}

	vector<bool> used(n,false);

	int str = 1;
	int cnt = 0;
	while(true){
		if( used.at(str-1) == false ){
			used.at(str-1) = true;
			str = a.at(str-1);
			cnt++;
			if( str == 2 ){
				cout << cnt << endl;
				break;
			}
		}
		else{
			cout << "-1" << endl;
			break;
		}
	}

}


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

#define ll  long long
#define forn(i,n)   for(ll i=0;i<(ll)n;i++)

long long modsum(ll n)
{
    return (n-1)*n/2;
}


int main()
{
    ll n;
    cin>>n;
    cout<<modsum(n)<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    vector<ll> ps(5);
    for(int i = 0; i < 5; ++i){
        cin >> ps.at(i);
    }
    ll k;
    cin >> k;
    for(int i = 0; i < ps.size(); ++i){
        for(int j = i + 1; j < ps.size(); ++j){
            if(abs(ps.at(i) - ps.at(j)) > k){
                 cout << ":(" << endl;
                 return 0;
            }
        }
    }
    cout << "Yay!" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define Mod 1000000007
typedef long long int ll;
int main()
{
  int n;
  cin>>n;
  int i,a[n];
  for(i=0;i<n;i++)
  {
      cin>>a[i];
  }
  double p[n];
  for(i=0;i<n;i++)
  {
      a[i]=(double)a[i];
      p[i]=1.0;
      p[i]/=a[i];
  }
  double ans=0.0;
  for(i=0;i<n;i++)
  {
      ans+=p[i];
  }
  double k=1.0;
  k/=ans;
  cout<<setprecision(10)<<fixed<<k;

}


Measured memory_bytes: 256
n,m = map(int,input().split())
prb = [[0] for _ in range(n+1)]

for _ in range(m):
    sub = input().split()
    p, s = int(sub[0]), sub[1]
    lst = prb[p]
    if lst[-1] == 1:
        pass
    elif s == "WA":
        lst.append(0)
    elif s == "AC":
        lst.append(1)
    prb[p] = lst

ac_prb = [lst for lst in prb if lst[-1] == 1]
ac_num = len(ac_prb)
pe_num = -2*ac_num

for prb in ac_prb:
    pe_num += len(prb)

print(ac_num, pe_num)

Measured memory_bytes: 94740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
	
		if (s.charAt(5) == '0' && Character.getNumericValue(s.charAt(6)) < 5 ) {
			System.out.print("Heisei");
		} else {
			System.out.print("TBD");
		}
	}
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC145A
{
    class Program
    {
        static void Main(string[] args)
        {
            //var inputArr = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var inputInt = int.Parse(Console.ReadLine());

            //int ans = 0;
            //string ans = "";

            Console.WriteLine(inputInt*inputInt);
            Console.ReadKey();
        }
    }
}


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


public class Main{
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        ArrayList<String> s = new ArrayList<String>();
        int t[] = new int[N];
        int result = 0;
        for(int i=0;i<N;i++){
            s.add(sc.next());
            t[i] = sc.nextInt();
            result += t[i];
        }
        String X = sc.next();
        int f = s.indexOf(X);
        for(int i=0;i<=f;i++){
            result -= t[i];
        }


        out.println(result);
        out.flush();
    }
    static int fact(int N){
        if(N==0) return 1;
        else return N*fact(N-1);
    }
        
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
#define int ll
using namespace std;
 
const ll MOD = 1e9+7;
const ll INF = 1e12;
const ll LOG = 29;
#define PI 3.141592653589793238 


long long binpow(long long a, long long b) {
    a%=MOD;    
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD;
        a = (a * a)%MOD;
 
        
        b >>= 1;
    }
    res%=MOD;
    return res;
}
const ll N =(15);
ll grid[N][N];
ll c[N];
void solve(){
	ll n,m,x;
	cin>>n>>m>>x;
	for(int i =1;i<=n;i++){
		cin>>c[i];
		for(int j =1;j<=m;j++){
			cin>>grid[i][j];
		}
	}
	ll ans = INF;
	for(ll mask = 0;mask<(1ll<<n);mask++){
		vll lvl(n+1,0);
		ll cst = 0;
		for(int i =0;i<n;i++){
			if((mask&(1ll<<i))){
				cst += c[i+1];
				for(int j = 1;j<=m;j++) lvl[j] += grid[i+1][j];
			}
		}
		bool poss=true;
		for(int i =1;i<=m;i++){
			poss &= (lvl[i] >= x);
		}
		if(poss){
			ans =min(ans,cst);
		}
	}
	if(ans==INF)ans=-1;
	cout<<ans<<endl;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     
    ll t=1;
 //   cin>>t;
    while(t--){
        solve();
    }    
}

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define lb long double
#define vec vector<int>
#define set setprecision
#define mod 1000000007
#include<numeric>
using namespace std;
int gcd(int a, int b)
{if (a % b == 0)	return(b);
	else return(gcd(b, a % b));}
int lcm(int a, int b)
{return a * b / gcd(a, b);}
ll pow(ll a, ll b) {
	ll k = b % 30000, h = b / 30000,s = 1;
	rip(i, 30000)s = (s * a) % mod;ll j = 1;
	if (h != 0)rip(i, h)j = j * s % mod;
	if (k != 0)rip(i, k)j = j * a % mod;
	return(j);
}
int main() {
	ll a,b;
	cin >> a >> b;
	cout << a * b << " " << 2 * (a + b) << endl;
}


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

int main()
{
    int N, M, t=0, a;
    cin >> N >> M;
    for(int i=0; i<M; i++)
    {
        cin >> a;
        t+=a;
    }
    if(t>N)
        cout<< -1;
    else
        cout<< N-t;
}


Measured memory_bytes: 3592
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace4(x, y, z, d)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#d<<": "<<d<<endl

#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
//int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<pair<string,int>, int> &a,const pair<pair<string,int>, int> &b)
{
    if(a.ff.ff == b.ff.ff) {
        return (a.ff.ss > b.ff.ss);
    }
    return (a.ff.ff<b.ff.ff);
}
int poww(int a, int b)
{
    int res = 1;
    for(int i = 1; i<=b; ++i)
        res *= a;

    return res;
}
int findlcm(int arr[], int n) 
{ 
    // Initialize result 
    int ans = arr[0]; 
  
    // ans contains LCM of arr[0], ..arr[i] 
    // after i'th iteration, 
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (__gcd(arr[i], ans))); 
  
    return ans; 
}
bool prime[100001];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
  }
}

//Define mx for maximum range and MOD for large numbers
#define mx 100004
#define MOD 1000000007;
// Declare all the variables and global functions here - 
int n;
vector< pair <pair<string, int>, int > > v;
int32_t main()
{
    IOS;
 //    #ifndef ONLINE_JUDGE
 //    freopen("input.txt","r",stdin);
 //    freopen("output.txt","w",stdout);
	// #endif
    /********************* From here **********************/
    cin >> n;
    rep(i, 0, n){
    	string s;
    	cin >> s;
    	int a;
    	cin >> a;
    	v.pb(mp(mp(s, a), i+1));
    }

    sort(all(v), compare);

    rep(i, 0, n){
    	cout << v[i].ss << endl;
    }
    
    
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Text()
	sc.Scan()
	S := stoi(strings.Split(sc.Text(), " "))
	sc.Scan()
	sc.Text()
	sc.Scan()
	T := stoi(strings.Split(sc.Text(), " "))

	count := 0

	for _, v := range S {

		if len(T) == 0 {
			break
		}
		for i := 0; i < len(T); i++ {
			if v == T[i] {
				count++
				T = append(T[:i], T[i+1:]...)
				break
			}
		}
	}

	fmt.Println(count)
}

func stoi(a []string) []int {
	r := []int{}
	for _, v := range a {
		val, _ := strconv.Atoi(v)
		r = append(r, val)
	}

	return r
}



Measured memory_bytes: 1820
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
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;}

std::vector<std::vector<long long>> comb(int n) {
  std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() {
    ll N, A, B; cin >> N >> A >> B;
    vector<ll> v(N);
    std::vector<std::vector<long long>> cmb = comb(N+1);
    for (ll i = 0; i < N; i++) cin >> v[i];
    sort(v.begin(),v.end(),greater<ll>());
    double res = 0;
    for (ll i = 0; i < A; i++) {
        res += (double) v[i];
    }
    res /= (double)A;
    vector<ll> S(N+1,v[0]);
    for (ll i = 1; i < N; i++) S[i] = S[i-1] + v[i];

    ll cnt = 0;
    //num...何個選び取るか
    for (ll num = A; num <= B; num++) {
        if (S[num-1]*A < S[A-1]*num) break;
        //bound...境界の値
        ll bound = v[num-1];
        ll i = 0, a = 0, b = 0;
        while (v[i] > bound) i++; a = i;
        while (v[i] == bound && i < N) i++; b = i;
        cnt += cmb[b-a][num-a];
    }
    /*
    tmpよりも大きい要素数a
    同じ要素数b-a
    b-aの内から、不足する要素数を選び出す
    */
    printf("%.8lf\n",res);
    cout << cnt << endl;


}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    if a[i]>=b[i]:
        ans+=b[i]
        a[i]-=b[i]
        b[i]=0
    else:
        ans+=a[i]
        b[i]-=a[i]
        a[i]=0
        if a[i+1]>=b[i]:
            ans+=b[i]
            a[i+1]-=b[i]
            b[i]=0
        else:
            ans+=a[i+1]
            b[i]-=a[i+1]
            a[i+1]=0
print(ans)

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

signed main(){
	int N, i;
	scanf("%lld", &N);
	vector<int> A(N), B(N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%lld", &B[i]);
	}
	int ans = 0;
	while(1){
		int now = 0, cnt = 0;
		for(i = 0; i < N; i++){
//			printf("i= %d\n", i);
			if(B[i] < A[i]){
				printf("-1\n");
				return 0;
			}
			else if(B[i] == A[i]){
				now++;
			}
			else{
				if(B[(i - 1 + N) % N] < B[i] && B[i] > B[(i + 1) % N]){
					int a = B[(i - 1 + N) % N], b = B[i], c = B[(i + 1) % N];
					if(b - (a + c) < A[i]){
						printf("-1\n");
						return 0;
					}
					int m = max(max(a, c), A[i]);
					int k = ((b - m) + (a + c) - 1) / (a + c);
					k = max(k - 1, (int)1);
//					printf("test4\n");
//					printf("B[%d] = %d\n", i, B[i]);
					B[i] -= k * (a + c);
					cnt++;
//					printf("B[%d] = %d\n", i, B[i]);
					ans += k;
					if(B[i] < A[i]){
						printf("-1\n");
						return 0;
					}
//					printf("B[%d] = %d\n", i, B[i]);
				}
			}
		}
		if(cnt == 0){
			for(i = 0; i < N; i++){
				if(A[i] != B[i]){
					printf("-1\n");
					return 0;
				}
			}
			printf("%lld\n", ans);
			return 0;
		}
		if(now == N){
			printf("%lld\n", ans);
			return 0;
		}
	}
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define int long long int
#define vi vector<int>
#define vvi vector < vi >
#define pii pair<int,int>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define tr(k,st,en) for(int k = st; k <= en ; k++)
#define trb(k,en,st) for(int k = en; k >= st ; k--)
using namespace std;

//int n = 2;
//
//void add_self(int& a, int b){
//    a += b;
//    if (a >= mod) {
//        a-=mod;
//    }
//}
//
//int mul(int a, int b){
//    int c = a*b;
//    return c%mod;
//}
//
//struct M {
//    vector<vector<int>> t;
//    M(){
//        t.resize(n, vector<int>(n));
//    }
//    M operator * (M& b){
//        M c;
//        tr(i,0, n-1){
//            tr(j,0,n-1){
//                tr(k,0,n-1){
//                    add_self(c.t[i][j] , mul(t[i][k] ,b.t[k][j]));
//                }
//            }
//        }
//        return c;
//    }
//};
//M power(M x, int k){
//    M ans;
//    tr(i,0,n-1){
//        ans.t[i][i] = 1;
//    }
//    while (k) {
//        if (k%2) {
//            ans = ans * x;
//        }
//        x = x*x;
//        k/=2;
//    }
//    return ans;
//}


int32_t main()
{
    std::ios::sync_with_stdio(false);
    int n,m,sum;
    cin>>n>>m;
    tr(i,0,m-1){
        cin>>sum;
        n-=sum;
    }
    cout<< ( n >= 0 ? n : -1 )<<endl;
    return 0;
}




Measured memory_bytes: 3564
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,a,b,u,tot0=0,tot1=0,num,pv,j,i,seq0[20],seq1[20],opt0[1000005],opt1[1000005],cnt0=0,cnt1=0,nv[1000005];
void solve0(ll p)
{
	ll i,v;
	if(p==1)
	{
		opt0[++cnt0]=0;
		opt0[++cnt0]=1;
		return;
	}
	solve0(p-1);
	v=cnt0;
	for(i=v;i>=v-(1<<(p-1))+1;i--)opt0[++cnt0]=(1<<(p-1))+opt0[i];
}
void solve1(ll p)
{
	ll i,v;
	if(p==1)
	{
		opt1[++cnt1]=0;
		opt1[++cnt1]=1;
		return;
	}
	solve1(p-2);
	for(i=1;i<=cnt1;i++)nv[i]=opt1[i];
	for(i=1;i<=cnt1;i++)
	{
		if(i%2==1)
		{
			opt1[2*(i-1)+1]=nv[i];
			opt1[2*i]=nv[i]+(1<<(p-2));
		}
		else
		{
			opt1[2*(i-1)+1]=nv[i]+(1<<(p-2));
			opt1[2*i]=nv[i];
		}
	}
	cnt1*=2;
	v=cnt1;
	for(i=1;i<=(1<<(p-1));i++)opt1[++cnt1]=(opt0[i]^opt1[v])+(1<<(p-1));
}
int main()
{
	//freopen("233.txt","w",stdout);
	scanf("%lld%lld%lld",&n,&a,&b);
	for(i=0;i<n;i++)
	{
		if((a&(1<<i))==(b&(1<<i)))seq0[++tot0]=i;
		else seq1[++tot1]=i;
	}
	//printf("%lld %lld\n",tot0,tot1);
	if(tot1%2==0)
	{
		printf("NO\n");
		return 0; 
	}
	printf("YES\n");
	solve0(n+(n%2==0));
	solve1(tot1);
	//for(i=1;i<=8;i++)printf("%lld %lld\n",opt0[i],opt1[i]);
	//return 0;
	for(i=1;i<=(1<<tot1);i++)
	{
		num=a;
		for(u=1;u<=tot1;u++)
		{
			if(opt1[i]&(1<<(u-1)))num^=(1<<seq1[u]);
			//printf("#%lld %lld %lld\n",opt1[i],seq1[u],num);
		}
		if(i%2==1)
		{
			for(j=1;j<=(1<<tot0);j++)
			{
				pv=num;
				for(u=1;u<=tot0;u++)if(opt0[j]&(1<<(u-1)))pv^=(1<<seq0[u]);
				printf("%lld ",pv);
			}
		}
		else
		{
			for(j=(1<<tot0);j>0;j--)
			{
				pv=num;
				for(u=1;u<=tot0;u++)if(opt0[j]&(1<<(u-1)))pv^=(1<<seq0[u]);
				printf("%lld ",pv);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 7168
#include <cstdio>

int main(){
	int n;
	int M[11][11];
	int sum;
	
	for(;;){
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			sum = 0;
			for(int j = 0; j < n; j++){
				scanf("%d", &M[i][j]);
				sum += M[i][j];
			}
			M[i][n] = sum;
		}
	
		for(int i = 0; i <= n; i++){
			sum = 0;
			for(int j = 0; j < n; j++){
				sum += M[j][i];
			}
			M[n][i] = sum;
		}
	
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				printf("%5d", M[i][j]);
			}
			putchar('\n');
		}
	}
	return 0;
}

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

int main()
{	int n;
	cin>>n;
	int a[51],b[51];
	int sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int j=1;j<=n;j++){
		b[j]=j;
	}
	for(int i=1;i<=n;i++){
		if(a[i]!=b[i]){
			sum++;
		}
	}
	if(sum==0||sum==2){
		cout<<"YES";
	}
	else
		cout<<"NO";
	
	return 0;
}

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

int n;
int a[25][25];
long long dp[2097157][25];

// long long f(vector<bool> used, int pos) {
long long f(int used, int pos) {
    if(dp[used][pos] != -1) return dp[used][pos];
    if(pos == n) return dp[used][pos] = 1;
    
    int res = 0;
    for(int i = 0; i < n; i++) {
        if(a[pos][i] and !(used & (1 << i))) {
            // used[i] = true;
            used |= (1 << i);
            res = (res + f(used, pos+1))%MOD;
            // used[i] = false;
            used &= ~(1 << i);
        }
    }
    
    return dp[used][pos] = res;
}

int main() {
	// your code goes here
	ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
	cin >> n;
	for(int i = 0; i < n; i++) {
	    for(int j = 0; j < n; j++) {
	        cin >> a[i][j];
	    }
	}
// 	vector<bool> used(n, false);
    int used = 0;
    memset(dp, -1, sizeof dp);
	cout << f(used, 0);
	return 0;
}


Measured memory_bytes: 409984
import sys

def Merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = A[left:left+n1]+[SENTINEL]
    R = A[mid:mid+n2]+[SENTINEL]
    i = 0
    j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def MergeSort(A, left, right):
    global ncomp
    if left+1 < right:
        mid = (left + right)//2
        MergeSort(A, left, mid)
        MergeSort(A, mid, right)
        Merge(A, left, mid, right)
        ncomp += right-left
ncomp=0
n = int(sys.stdin.readline())
s = list(map(int, sys.stdin.readline().split()))
SENTINEL = max(s)+1
MergeSort(s, 0, n)
print(' '.join(map(str,s)))
print(ncomp)


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

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

  ll N;
  cin >> N;

  vector<double> p(N, 0);

  FOR(i, 0, N) cin >> p[i];

  vector<vector<double> > dp(N+1, vector<double>(N+1, 0));

  dp[0][0] = 1;

  FOR(i, 1, N+1)FOR(j, 0, i+1){
    double prob1 = j < i ? dp[i-1][j] : 0;
    double prob2 = j > 0 ? dp[i-1][j-1] : 0;

    dp[i][j] = prob1*(1.0-p[i-1])+prob2*p[i-1];
  }
  double out = 0.0;
  FOR(j, 0, N+1){
    if(N-j < j){
      out += dp[N][j];
    }
  }

  cout << fixed << setprecision(16) << out << endl;

}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n, k; cin >> n >> k;
	vector<int> p(n);
	for( auto &t : p ) cin >> t;
	sort( p.begin(), p.end() );
	int sum = 0;
	for( int i = 0; i < k; ++i ){
		sum += p[i];
	}
	cout << sum << endl;
}

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

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

    int h[n],c[n];

    for(i=0;i<n;i++){
        scanf("%d",&h[i+1]);    
    }

/* kまでの最小　c[k] kの高さh[k]   */

    for(i=0;i<n+1;i++){
        c[i]=0;
    }

    for(i=0;i<n;i++){
        if(i==0){
            c[i+2]=fabs(h[2]-h[1]);
            if(n==2){
                break;
            }else{
                continue;
            }
        }

        if(i==n-1) break;
        
        if(c[i + 1] + fabs(h[i + 2] - h[i + 1]) > c[i] + fabs(h[i + 2] - h[i])){
            c[i+2] =  c[i] + fabs(h[i + 2] - h[i]);
            
        }else{
            c[i+2] = c[i+1] + fabs(h[i + 2] - h[i + 1]);
        }
        //printf("%d\n",c[i+2]);
    }
    printf("%d\n",c[n]);
    return 0;
}

Measured memory_bytes: 896
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

int main() {
	string s;
	bool f[3] = {};
	cin >> s;
	repi(i, 0, 3) {
		int index = (int)(s[i] - 'a');
		f[index] = true;
	}
	if (f[0] && f[1] && f[2]) wrln("Yes");
	else wrln("No");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int Graph[1000][1000];

  int n,u,k,v,i,j;

  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    
    for(j=0;j<k;j++){
      scanf("%d",&v);
      Graph[u-1][v-1]=1;
    }
  }

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

      if(j!=0)printf(" ");
      if(Graph[i][j]==1) printf("1");
      else printf("0");
    }

    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <queue>
#include <cmath>
#include <functional>
#include <iomanip>

#include <map>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int MOD = 1e9+7;
const int INF = 1e9;
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
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;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif


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

  ll A[N], sum[N+1];
  sum[0] = 0;
  rep(i, N) {
    cin >> A[i];
    --A[i];
    sum[i+1] = sum[i] + A[i];
    sum[i+1] %= K;
  }
  ll ans = 0;
  map<ll, int> m;
  rep(r, N+1) {
    if (r - K >= 0) --m[sum[r-K]];
    ans += m[sum[r]];
    ++m[sum[r]];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 16000
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <unordered_map>
#include <memory.h>

// pi = atan(1)*4;

using namespace std;

int main(void)
{
	int h, w;
	vector <string> s;
	string t;

	cin >> h >> w;

	for (int i = 0; i < h; i++)
	{
		cin >> t;
		s.push_back(t);
		s.push_back(t);
	}

	for (int i = 0; i < s.size(); i++)
	{
		cout << s[i] << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
AB = [[A[i],B[i]] for i in range(N)]
AB.sort(key=lambda x:x[1])
A = [[AB[i][0],i] for i in range(N)]
A.sort(key=lambda x:x[0])
da = {}
for i in range(N):
    j = A[i][1]
    da[j] = i 

ans = True
i = 0
for j in range(N):
    i = da[i]
    if i == 0:
        break

A = [AB[i][0] for i in range(N)]
A.sort()
B.sort()
if j == N-1:
    ok = False
    for i in range(N-1):
        if B[i]>=A[i+1]:
            ok = True
    ans = ok

for i in range(N):
    if A[i]>B[i]:
        ans = False

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 113296
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  string T;
  T = "CODEFESTIVAL2016";
  int count = 0;
  rep(i,16)
  {
    if(S[i]!=T[i])
    {
      count ++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <assert.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
const int xdirec[] = { -1, 0, 1, 0 };
const int ydirec[] = { 0, -1, 0, 1 };

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

// フェルマーの小定理を用いたCombination計算(modの構造体と一緒に使う)
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};
int main()
{
	int x, y;
	cin >> x >> y;
	if ((x + y) % 3) {
		cout << 0 << endl;
		return 0;
	}
	int n = (x + y) / 3;
	x -= n; y -= n;
	if (x < 0 || y < 0) {
		cout << 0 << endl;
		return 0;
	}
	combination c(x + y);
	mint ans = c(x + y, x);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13796
import Control.Applicative

import Data.List
    (sort)
    
solve :: [Int] -> [Int]

solve
    = sort

output :: [Int] -> String

output xs
    = init $ concat [show x ++ " " | x <- xs]
    
main :: IO ()
    
main
    = do
        input <- map read.words <$> getLine
        putStrLn $ output $ solve input

Measured memory_bytes: 3668
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))	
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)	
#define FloorN(x, n)	((x)-(x)%(n))			
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long			ll;
typedef unsigned long long	ull;
typedef pair<ll, ll>		P;
typedef vector<ll>			VLL;
typedef vector<VLL>			VVLL;
typedef vector<VVLL>		VVVLL;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int A[3][3];
	REP(i, 3) {
		REP(j, 3) {
			cin >> A[i][j];
		}
	}

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

	REP(bCnt, N) {
		REP(i, 3) {
			REP(j, 3) {
				if (A[i][j] == b[bCnt]) {
					A[i][j] = INF;
				}
			}
		}
	}

	string ans = "No";
	REP(i, 3) {
		bool isOk = true;
		REP(j, 3) {
			if (A[i][j] != INF) {
				isOk = false;
				break;
			}
		}
		if (isOk) {
			ans = "Yes";
			break;
		}
	}

	REP(i, 3) {
		bool isOk = true;
		REP(j, 3) {
			if (A[j][i] != INF) {
				isOk = false;
				break;
			}
		}
		if (isOk) {
			ans = "Yes";
			break;
		}
	}
	
	if (A[0][0] == INF && A[1][1] == INF && A[2][2] == INF){
		ans = "Yes";
	}

	if (A[0][2] == INF && A[1][1] == INF && A[2][0] == INF){
		ans = "Yes";
	}

	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

using mint = atcoder::modint998244353;

const int MAX_N = 312345;
mint power_ten[MAX_N];
mint ones[MAX_N];

struct S {
  mint a;
  int size;
};
S op(S l, S r) { return S{l.a * power_ten[r.size] + r.a, l.size + r.size}; }
S e() { return S{0, 0}; }

struct F {
  mint d;
};
F composition(F l, F r) { if (l.d.val() == 0) return r; else return l; }
F id() { return F{0}; }

S mapping(F f, S x) {
  if (f.d == 0) return x;
  return S{ ones[x.size] * f.d, x.size };
}


int main2() {
  int N = nextLong();
  int Q = nextLong();

  atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(N);
  REP(i, N) {
    seg.set(i, S{1, 1});
  }
  REP(qi, Q) {
    int L = nextLong() - 1;
    int R = nextLong() - 1;
    int D = nextLong();
    seg.apply(L, R+1, F{D} );
    S ans = seg.all_prod();
    cout << ans.a.val() << '\n';
  }

  return 0;
}

int main() {
  power_ten[0] = 1;
  for (int i = 1; i < MAX_N; i++) {
    power_ten[i] = power_ten[i-1] * 10;
  }
  ones[0] = 0;
  for (int i = 1; i < MAX_N; i++) {
    ones[i] = ones[i-1] * 10 + 1;
  }
#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 12544
N = int(input())
A = [int(i) for i in input().split()]

A = [0] + A + [0]

allcost = 0
for i in range(len(A) - 1):
    allcost += abs(A[i+1] - A[i])

for i in range(1, N+1):
    old = abs(A[i+1] - A[i]) + abs(A[i] - A[i-1])
    new = abs(A[i+1] - A[i-1])
    print(allcost - old + new)

Measured memory_bytes: 14048
// Problem : A - Fairness
// Contest : AtCoder - AtCoder Grand Contest 024
// URL : https://atcoder.jp/contests/agc024/tasks/agc024_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、 
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int A,B,C;
	ll K;
	cin>>A>>B>>C>>K;
	if(K%2==0)
		cout<<A-B;
	else
		cout<<B-A;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  double A, ans = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A;
    ans += 1 / A;
  }
  cout << setprecision(20) << 1 / ans << endl;
  return 0;
}

Measured memory_bytes: 256
import math                                                                     

N = int(input())
a_dsum = 0 
b_dsum = 0 
ans = 100000

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)


for a in range(N + 1): 
    b = N - a 
    if sum(map(int, str(a))) > 1:
        a_dsum = digitSum(a)
    else:
        a_dsum = a
    if sum(map(int, str(b))) > 1:
        b_dsum = digitSum(b)
    else:
        b_dsum = b 
    tmp_sum = a_dsum + b_dsum
    if tmp_sum < ans:
        ans = tmp_sum

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
int main()
{
    int x;
    scanf("%d", &x);
    int a, b, f = 0;
    int aa, bb;
    for (a = 1;; a++)
    {
        aa = a * a * a * a * a;
        for (b = 0; b < a; b++)
        {
            bb = b * b * b * b * b;
            if (aa + bb == x)
            {
                f = -1;
                break;
            }
            else if (aa - bb == x)
            {
                f = 1;
                break;
            }
        }
        if (f != 0)
        {
            break;
        }
    }
    printf("%d %d", a, f * b);
    return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=105;
int a[maxn],flag[maxn];
int main()
 {
     int n;
     scanf("%d",&n);
     for(int i=1;i<=n;i++) scanf("%d",&a[i]);
     int ans=inf,pos=-1,sum=0;
     for(int i=1;i<=100;i++){
         sum=0;
         for(int j=1;j<=n;j++){
             sum+=(a[j]-i)*(a[j]-i);
         }
         
         if(sum<ans){
            ans=sum;
            pos=i;
            }
     }
     cout<<ans<<endl;
     return 0;
  }


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define DEBUG cout<<"shllhs"<<endl;
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 52
#define M 2005
#define INF 100000000000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-10
#define pi acos(-1.0)
using namespace std;
typedef pair<pair<int,int>,int> tri;
typedef pair<pair<ll,ll>,ll> trl;
typedef pair<int,int> pri;
typedef pair<ll,ll> prl;

ll dp[N][N][N*N];
int b[N];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    while(cin>>n>>a)
    {
        FOR(i,1,n)cin>>b[i];
        MST(dp,0);
        dp[0][0][0] = 1;
        ll ans = 0;
        FOR(i,1,n)
        {
            FOR(j,0,n)
            {
                FOR(k,0,2500)
                {
                    dp[i][j][k] = dp[i-1][j][k];
                    if(j>0&&b[i]<=k)dp[i][j][k]+=dp[i-1][j-1][k-b[i]];
                }
            }
        }
        FOR(j,1,n)
        {
            FOR(k,0,2500)
            {
                if(k%j == 0&&k/j == a)ans+=dp[n][j][k];
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 57472
def check():
    N = int(input())
    S = input()
    S = S[1:]+S[0]
    animal = ['W', 'S']
    
    for a in animal:
        for b in animal:
            #print(a,b)
            pre, nex = a, b
            answer = [a,b]
            for i in range(N):
                if nex == 'S':
                    if S[i] == 'o':
                        tmp = nex
                        nex = pre
                        pre = tmp
                        answer.append(nex)
                    elif S[i] == 'x':
                        tmp = nex
                        nex = 'W' if pre == 'S' else 'S'
                        pre = tmp
                        answer.append(nex)
                else:
                    if S[i] == 'o':
                        tmp = nex
                        nex = 'W'if pre == 'S' else 'S'
                        pre = tmp
                        answer.append(nex)
                    elif S[i] == 'x':
                        tmp = nex
                        nex = pre
                        pre = tmp
                        answer.append(nex)
                #print(nex)
            if nex == b and pre == a:
                return answer[:-2]
    else:
        return -1

ans = check()               
if type(ans) == int:
    print(ans)
else:
    print(''.join(ans))

Measured memory_bytes: 4884
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll n, k;
    cin >> n >> k;
    vector<int> d(10, 0);
    for(int i = 0; i < k; i++) {
        int inp;
        cin >> inp;
        d[inp] = 1;
    }
    for(int i = n; i <= 100 * n; i++) {
        string s = to_string(i);
        int flag = 1;
        for(auto e : s) {
            if(d[e - '0']) {
                flag = 0;
                break;
            }
        }
        if(flag) {
            cout << i << endl;
            return 0;
        }
    }
}

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

int main(){
  int N;
  cin>>N;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  sort(p.begin(),p.end());
  cout<<p[N-1]-p[0]<<endl;
  
}


Measured memory_bytes: 3632