akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int t[110000];
vector<int>g[110000];
int ijk[110000];
int v[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a-1;i++){
		int p,q;scanf("%d%d",&p,&q);
		p--;q--;
		g[p].push_back(q);g[q].push_back(p);
	}
	int b;scanf("%d",&b);
	for(int i=0;i<a;i++)t[i]=-1;
	for(int i=0;i<a;i++)ijk[i]=mod;
	priority_queue<pair<int,int> > Q;
	for(int i=0;i<b;i++){
		int p,q;scanf("%d%d",&p,&q);p--;
		t[p]=q;
		ijk[p]=q;
		Q.push(make_pair(-q,p));
	}
	while(Q.size()){
		int cost=-Q.top().first;
		int at=Q.top().second;
		Q.pop();
		if(v[at])continue;
		v[at]=1;
		for(int i=0;i<g[at].size();i++){
			int to=g[at][i];
			if(v[to]||ijk[to]<=cost+1)continue;
			ijk[to]=cost+1;
			Q.push(make_pair(-ijk[to],to));
		}
	}
	for(int i=0;i<a;i++){
		if(t[i]!=-1&&ijk[i]!=t[i]){
			printf("No\n");return 0;
		}
		for(int j=0;j<g[i].size();j++){
			if(ABS(ijk[i]-ijk[g[i][j]])!=1){
				printf("No\n");return 0;
			}
		}
	}
	printf("Yes\n");
	for(int i=0;i<a;i++)printf("%d\n",ijk[i]);

}

Measured memory_bytes: 8948
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}




int N;
string s, t;

int main () {
  cin >> N;
  cin >> s;
  cin >> t;

  Rep(i, N) {
    int len = N - i;

    if (s.substr(i, len) == t.substr(0, len)) {
      cout << 2 * N - len << "\n";
      return 0;
    }
  }

  cout << 2 * N << "\n";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var array = Array.ConvertAll(ReadLine().Split(' '), long.Parse);
        Array.Sort(array);
        var dic = new Dictionary<long, int>();
        var nums = new List<long>();
        for (var i = num-1; i >= 0; i--)
        {
            if (dic.ContainsKey(array[i])) dic[array[i]]++;
            else dic[array[i]] = 1;
            if (dic[array[i]] > 1&&dic[array[i]]%2==0)
            {
                nums.Add(array[i]);
                if (nums.Count == 2) { WriteLine(nums[0] * nums[1]);return; }
            }
        }
        WriteLine(0);
    }
}

Measured memory_bytes: 26464
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define forg(i,x) for(int i=first[x];i;i=nxt[i])
#define uu unsigned
#define fi first
#define se second
#define od(x) ((x)&1)
#define ev(x) (od(x)^1)
#define mi2(x) (1<<(x))
#define scanf a1234=scanf
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
int a1234;
char buf[1<<18],*bufs=buf,*buft=buf;
inline int gc(){
    return bufs==buft&&(buft=(bufs=buf)+fread(buf,1,1<<18,stdin)),bufs==buft?-1:*bufs++;
}
inline void xxx(){for(;;);}

const int mxn=4003,base=2001,mxm=2e5+3,c1=8000;
const uu mod=1e9+7;
uu dp[mxn][mxn];
int n,a[mxm],b[mxm];
long long jc[8003],inv[8003];
inline int por(long long a,int b){
	long long res=1;
	for(;b;b>>=1){
		if(b&1)(res*=a)%=mod;
		a=a*a%mod;
	}
	return res;
}
inline int C(int x,int y){return jc[x]*inv[y]%mod*inv[x-y]%mod;}

int main(){
	jc[0]=inv[0]=1;
	for(int i=1;i<=c1;++i)jc[i]=jc[i-1]*i%mod;
	inv[c1]=por(jc[c1],mod-2);for(int i=c1-1;i;--i)inv[i]=inv[i+1]*(i+1)%mod;
	scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d%d",a+i,b+i);
	for(int i=1;i<=n;++i)++dp[base-a[i]][base-b[i]];
	for(int i=1;i<=4001;++i)for(int j=1;j<=4001;++j)dp[i][j]+=dp[i-1][j]+dp[i][j-1],dp[i][j]%=mod;
	uu ans=0;
	for(int i=1;i<=n;++i)ans+=mod-C(2*(a[i]+b[i]),2*a[i]),ans%=mod;
	for(int i=1;i<=n;++i)ans+=dp[base+a[i]][base+b[i]],ans%=mod;
	printf("%u\n",ev(ans)?ans/2:(ans+mod)/2);
    return 0;
}


Measured memory_bytes: 68084
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var nums = Console.ReadLine().Split(' ');

        var a = int.Parse(nums[0]);
        var b = int.Parse(nums[1]);
        var c = int.Parse(nums[2]);

        var n = int.Parse(Console.ReadLine());

        for (var i = 0; i < n; i++)
        {
            if (a >= b)
            {
                b = b * 2;
            }
            else
            {
                c = c * 2;
            }
        }


        if(a < b && a < c && b < c)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }


        Console.ReadLine();
    }


}




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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] read = br.readLine().split(" ");
		read[0] = read[0].substring(0,1);
		read[1] = read[1].substring(0,1).toUpperCase();
		read[2] = read[2].substring(0,1);
		System.out.println(read[0] + read[1] + read[2]);
	}
}

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

struct node{
    int key;
    node *left,*right,*p;
    node(){}
    node(int key):key(key){left=right=p=NULL;};
};
node *root;

int insert(node z){
    node *y=NULL;
    node *x=root;
    while(x!=NULL){
        y=x;
        if(z.key<x->key){
            x=x->left;
        }
        else{
            x=x->right;
        }
    }
    z.p=y;
    if(y==NULL){
        root=new node(z);
    }
    else if(z.key<y->key){
        y->left=new node(z);
    }
    else{
        y->right=new node(z);
    }
    return 0;
}
int t(node *a){
    if(a==NULL)return 0;
    t(a->left);
    cout <<" " << a->key;
    t(a->right);
    return 0;
}
int u(node *a){
    if(a==NULL)return 0;
    cout <<" "<< a->key;
    u(a->left);
    u(a->right);
    return 0;
}
int main(void){
    int m;
    
    root=NULL;
    cin >> m;
    for(int i=0;i<m;i++){
        string s;
        cin >> s;
        if(s=="print"){
            t(root);
            cout << endl;
            u(root);
            cout << endl;
            continue;
        }
        int n;
        cin >> n;
        insert(node(n));
        
    }
    return 0;
}


Measured memory_bytes: 26448
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll mod = 1000000007;
int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++)
		cin >> d[i];
	sort(all(d));
	cout << d[n / 2] - d[n / 2 - 1];
}

Measured memory_bytes: 640
package main

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

var in = newIo(bufio.NewScanner(os.Stdin))

func main() {
	n := in.nextInt()
	print(solve(n))
}

func solve(n int) string {
	if n == 1 {
		return "Hello World"
	}
	a := in.nextInt()
	b := in.nextInt()
	return strconv.Itoa(a + b)
}

func print(result ...interface{}) {
	for _, r := range result {
		kind := reflect.TypeOf(r).Kind()
		if kind == reflect.Array || kind == reflect.Slice {
			rv := reflect.ValueOf(r)
			cnv := make([]interface{}, rv.Len())
			for i := 0; i < rv.Len(); i++ {
				cnv[i] = rv.Index(i).Interface()
			}
			print(cnv...)
		} else {
			fmt.Println(r)
		}
	}
}

type io struct {
	sc *bufio.Scanner
}

func newIo(sc *bufio.Scanner) *io {
	i := new(io)
	i.sc = sc
	i.sc.Split(bufio.ScanWords)
	return i
}

func (i *io) setSplit(f bufio.SplitFunc) {
	i.sc.Split(f)
}

func (i *io) nextIntSlice(y int, delim string) [][]int {
	result := make([][]int, y)
	for j := 0; j < y; j++ {
		line := i.next()
		result[j] = perseIntSlice(strings.Split(line, delim))
	}
	return result
}

func (i *io) next() string {
	i.sc.Scan()
	return i.sc.Text()
}

func (i *io) nextInt() int {
	return perseInt(i.next())
}

func (i *io) nextLong() int64 {
	return perseLong(i.next())
}

func perseInt(s string) int {
	in, _ := strconv.Atoi(s)
	return in
}

func perseLong(s string) int64 {
	in, _ := strconv.ParseInt(s, 10, 64)
	return in
}

func perseIntSlice(s []string) []int {
	var r = make([]int, len(s))
	for i := 0; i < len(s); i++ {
		r[i] = perseInt(s[i])
	}
	return r
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ll n;
    cin>>n;
    ll a[n], ans = 0, s = 0;
    scan(a, 0, n);
    forn(i, 0, n){
        s+=a[i];
        s%=mod;
    }
    forn(i, 0, n){
        s-=a[i];
        if(s<0)s+=mod;
        ans = add(ans, mul(a[i], s));
    }
    cout<<ans<<endl;

}

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

using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    vector<int> B(N);
    for(int i = 0; i < N; i++){
        cin >> B[i];
    }
    vector<int> C(N);
    for(int i = 0; i < N; i++){
        cin >> C[i];
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());
    long long sum = 0;
    for(int bi = 0; bi < N; bi++){
        decltype(A)::iterator itA = lower_bound(A.begin(), A.end(), B[bi]);
        long long a = itA - A.begin();
        decltype(C)::iterator itC = upper_bound(C.begin(), C.end(), B[bi]);
        long long c = C.end() - itC;
        sum += a * c;
    }
    cout << sum << endl;
    return 0;
}

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

namespace ABC150C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] P = ReadInt();
            int[] Q = ReadInt();

            List<int> master = new List<int>();
            for (int i = 0; i < N; i++)
            {
                master.Add(i + 1);
            }

            int countP = int.MaxValue;
            int countQ = int.MaxValue;
            int count = 1;
            foreach (var item in GetPermutation(master))
            {
                bool okp = true;
                bool okq = true;
                for (int i = 0; i < N; i++)
                {
                    if (item[i] != P[i]) { okp = false; }
                    if (item[i] != Q[i]) { okq = false;}
                }

                if (okp && countP > count) countP = count;
                if (okq && countQ > count) countQ = count;
                count++;
            }

            Console.WriteLine(Math.Abs(countP - countQ));
            Console.ReadKey();
        }

        /// <summary>
        /// 順列組み合わせ
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <returns></returns>
        public static IEnumerable<T[]> GetPermutation<T>(IEnumerable<T> collection)
        {
            if (collection.Count() == 1)
            {
                yield return new T[] { collection.First() };
            }

            foreach (var item in collection)
            {
                var selected = new T[] { item };
                var unused = collection.Except(selected);

                foreach (var rightside in GetPermutation(unused))
                {
                    yield return selected.Concat(rightside).ToArray();
                }
            }
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 24312
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>

using namespace std;
using ll = long long;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

signed main() {
  ios::sync_with_stdio(false);
  string l;
  cin >> l;
  int n = l.length();
  vector<vector<ll>> dp = vector<vector<ll>>(n+1, vector<ll>(2, 0));
  dp[1][0] = 1;
  dp[1][1] = 2;
  REP_FROM(i, 1, n) {
    if(l[i] == '1') {
      dp[i+1][0] = (dp[i][0] * 3 + dp[i][1]) % mod;
      dp[i+1][1] = dp[i][1] * 2 % mod;
    }
    else {
      dp[i+1][0] = dp[i][0] * 3 % mod;
      dp[i+1][1] = dp[i][1];
    }
  }
  cout << (dp[n][0] + dp[n][1]) % mod << endl;
  // REP(i, n+1) cout << dp[i][0] << " ";
  // cout << endl;
  // REP(i, n+1) cout << dp[i][1] << " ";
  // cout << endl;
  return 0;
}


Measured memory_bytes: 5840
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Measured memory_bytes: 13980
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
T = input()

if S == T[:-1]:
    Yes()
else:
    No()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#include <string>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

ll dp[MAX*10][2];

int main(void) {
  ll i, j, k, l;
  
  string L;
  cin >> L;
  ll N=L.size();
  
  for(i=0; i<=N; i++) for(j=0; j<2; j++) dp[i][j]=INF;
  
  dp[0][0]=0;
  dp[0][1]=1;
  for(i=0; i<N; i++) {
    ll c=L[i]-'0';
    chmin(dp[i+1][0], min(dp[i][0]+c, dp[i][1]+(10-c)));
    chmin(dp[i+1][1], min(dp[i][0]+c+1, dp[i][1]+(10-c-1)));
  }
  
  pt(dp[N][0]);
  
}



Measured memory_bytes: 17028
#coding:utf-8
#1_6_B
def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1

n = int(input())
numbers = list(map(int, input().split()))
x = partition(numbers, 0, n - 1)
numbers[x] = "[{}]".format(numbers[x])
print(*numbers)

Measured memory_bytes: 18352
import Data.List
import Control.Applicative
import Control.Monad

isRightTrig :: Int -> Int -> Int -> String
isRightTrig a b c = if x * x + y * y == z * z then "YES" else "NO"
    where [x, y, z] = sort [a, b, c]

main :: IO ()
main = do
    n <- (read :: String -> Int) <$> getLine
    rs <- replicateM n ((\[a, b, c] -> isRightTrig a b c) . map read . words <$> getLine)
    putStr $ unlines $ rs

Measured memory_bytes: 4592
a,b,c = map(int,input().split())
k=[]
if (b-a)//2<c:
    for i in range(b-a+1):
        print(a+i)
else:
    for i in range(c):
        print(a+i)
        k.append(b-i)
    for i in range(c):
        print(k[len(k)-1-i])

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5 + 5;
const int MAXQ = 2e5 + 5;
const int mod = 998244353;

ll pw[MAXN], psum[MAXN];

struct Segment_Tree
{
	ll sum[MAXN<<2];
	int tag[MAXN<<2];
	#define ls(u) ((u)<<1)
	#define rs(u) ((u)<<1|1)
	#define lson(u) ls(u),l,mid
	#define rson(u) rs(u),mid+1,r
	inline void push_up(int u){ sum[u] = (sum[ls(u)] + sum[rs(u)]) %mod;}
	inline void push_down(int u,int l,int r)
	{
		if(~tag[u])
		{
			int mid = (l+r)>>1;
			sum[ls(u)] = tag[u] * (psum[mid] - psum[l-1] + mod) %mod;
			sum[rs(u)] = tag[u] * (psum[r] - psum[mid] + mod) %mod;
			tag[ls(u)] = tag[rs(u)] = tag[u];
			tag[u] = -1;
		}
	}
	void build(int u,int l,int r)
	{
		tag[u] = -1;
		if(l==r){ sum[u] = pw[l]; return;}
		int mid = (l+r)>>1;
		build(lson(u)); build(rson(u));
		push_up(u);
	}
	void update(int u,int l,int r,int ql,int qr,int k)
	{
		if(ql<=l && r<=qr){ sum[u] = k * (psum[r] - psum[l-1] + mod) %mod; tag[u] = k; return;}
		push_down(u,l,r);
		int mid = (l+r)>>1;
		if(ql<=mid) update(lson(u),ql,qr,k);
		if(mid<qr) update(rson(u),ql,qr,k);
		push_up(u);
	}
	ll query_all(void){ return sum[1];}
}tree;

int main(void)
{
	pw[1] = psum[1] = 1;
	for(int i=2; i<MAXN; ++i)
		pw[i] = pw[i-1] * 10 %mod,
		psum[i] = (psum[i-1] + pw[i]) %mod;
	
	int n,Q;
	scanf("%d%d",&n,&Q);
	
	tree.build(1,1,n);
	
	while(Q--)
	{
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		tree.update(1,1,n, n-r+1, n-l+1, k);
		printf("%lld\n",tree.query_all());
	}
	return 0;
}

Measured memory_bytes: 13120
#include <bits/stdc++.h>
using namespace std;
/*
void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}
*/

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

    vector<int> Q(N);
    for (int i=0; i<N; i++) cin >> Q[i];
    
    vector<int> order(N);
    for (int i=1; i<=N; i++) order[i-1]=i;

    long P_id = 0;
    long Q_id = 0;
    long id = 1;
    do
    {
        if (P==order) P_id = id;
        if (Q==order) Q_id = id;
        if (P_id&&Q_id) break;
        id++;
        //printVector(order);
    } while (next_permutation(order.begin(), order.end()));

    long ans = abs(P_id - Q_id);
    cout << ans << endl;

    /*
    //////////////////////////////
    cout << P_id << endl;
    cout << Q_id << endl;
    */

}

Measured memory_bytes: 3628
import java.math.BigDecimal;
import java.util.*;

public class Main 
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        BigDecimal a = new BigDecimal(s1);
        BigDecimal b = new BigDecimal(s2);
        b = b.multiply(a);
        System.out.println(b.longValue());
    } 
}

Measured memory_bytes: 27224
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
 #define big 1000000007
int main(){
    int n;
    cin>>n;
    int min=100000;
    for(int i=1;i<=n-1;i++){
        int a=i;
        int b = n-i;
        string A = to_string(a);
        string B = to_string(b);
        int sum=0;
        for(int k=0;k<A.size();k++){
            sum += A[k] -'0';
        }
        for(int k=0;k<B.size();k++){
            sum += B[k]-'0';
        }
        if(sum < min){
            min = sum;
        }
    }
    cout<<min<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
#include<climits>
#include<queue>
#include<unordered_set>
#include<algorithm>
#include<iomanip>
#include <typeinfo> 
#include <set>
#define ll long long int
#include <iostream>
using namespace std;
int mat[1005][1005];
int main() {
       
       string s;
       cin>>s;
       int n=s.size(),ans=0,cnt=0;
       for(int i=0;i<n;i++){
       	if(s[i]=='R'){
       		cnt++;
		   }
		   else
		   {
		   	cnt=0;
		   }
		   ans=max(ans,cnt);
	   }
       cout<<ans<<endl;
		return 0;
}

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

int n, k;
vector<long long> a;

bool check(int x) {
  vector<int> rem(n);
  for (int i = 0; i < n; i++) rem[i] = a[i] % x;
  sort(rem.begin(), rem.end());

  int pos = 0, neg = 0;
  int r = n-1;
  for (int l = 0; l <= r; l++) {
    pos += rem[l];
    while (pos > neg) {
      neg += x - rem[r];
      --r;
    }
  }

  if (pos <= k) return true;
  else return false;
}

int main() {
  cin>>n>>k;
  a.resize(n);
  for (int i = 0; i < n; i++) cin>>a[i];

  int s;
  for (int i = 0; i < n; i++) s += a[i];
  vector<int> divs;
  for (int i = 1; i * i <= s; i++) {
    if (s % i == 0) {
      divs.emplace_back(i);
      divs.emplace_back(s / i);
    }
  }
  sort(divs.begin(), divs.end());

  int ans = 1;
  for (auto x: divs) {
    if (check(x)) ans = x;
  }
  cout << ans << endl;

  return 0;
}

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

mt19937 rnd;
uniform_real_distribution<> dist01(0.0, 1.0);
double rnd01(){ return dist01(rnd);}

const double TIME_LIMIT = 1950;
double elapsed;
chrono::system_clock::time_point t_start;
void update_time(){
    auto t_now = chrono::system_clock::now();
    elapsed = chrono::duration_cast<chrono::milliseconds>(t_now - t_start).count();
}
bool timeover(){ return (elapsed > TIME_LIMIT);}

int N, X[100], Y[100];
bitset<100> use;
int64_t opt, now;
int64_t x, y;

void toggle(int i){
    if(use[i]){
        use[i] = 0;
        x -= X[i];
        y -= Y[i];
    }else{
        use[i] = 1;
        x += X[i];
        y += Y[i];
    }
}

void try_update(){
    // pick random & update
    int i = rnd() % N;
    toggle(i);

    // calculate
    int64_t score = x*x + y*y;
    opt = max(opt, score);
    const int64_t T = 1e4;
    double temp = T * (1 - elapsed/TIME_LIMIT) + 1;
    double prob = exp((score - now) / temp);
    if(rnd01() < prob){
        now = score;
    }else{
        // rollback
        toggle(i);
    }
}

void reset(){
    for(int i=0; i<N; i++) use[i] = 0;
    x = y = now = 0;
}

int main(){
    // get input & initialize
    cin >> N;
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i];

    t_start = chrono::system_clock::now();

    // iterate
    int iter = 0;
    while(!timeover()){
        iter++;
        try_update();
        if(iter % 1000 == 0) update_time();
        if(iter% 1000000 == 0) reset();
    }

    // output result
    cout << fixed << setprecision(10) << sqrt(opt) << endl;
    //cout << opt << endl;

    // output debug
    cerr << "score: " << opt << endl;
    cerr << "iter: " << iter << endl;
    update_time();
    cerr << "elapsed: " << elapsed << endl;
    return 0;
}


Measured memory_bytes: 512
N,M = map(int,input().split())
tower = list(map(int,input().split()))
road = [list(map(int,input().split())) for i in range(M)]
aa = ['.']*N
for i in road:
  if tower[i[0]-1] > tower[i[1]-1]:
    aa[i[1]-1] = 'v'
  elif tower[i[0]-1] == tower[i[1]-1]:
    aa[i[0]-1] = aa[i[1]-1] = 'v'
  else:
    aa[i[0]-1] = 'v'
print(aa.count('.'))

Measured memory_bytes: 31916
//このように絞った方が良いかも
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.Scanner;


/**
 * Base_version with PrintWriter and FastScanner
 */ 
 
class Main { 
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();//Scanner→FastScanner, Delete(System.in)
      	int x = sc.nextInt();//longをintに戻した
      	int t = sc.nextInt();//longをintに戻した
      	PrintWriter out = new PrintWriter(System.out);
        out.println(Math.max(x - t, 0));
      	out.flush();
    }
}

//add 
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: 21332
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
ll di[]={-1,0,1,0};
ll dj[]={0,1,0,-1};

int main(){
    ll h,w,k;
    cin>>h>>w>>k;
    ll si, sj, ti, tj;
    cin>>si>>sj>>ti>>tj;
    si--; sj--; ti--; tj--;
    vector<string> g(h);
    for(ll i=0;i<h;i++){
        cin>>g[i];
    }

    auto toId = [&](ll i, ll j, ll v){
        return (i*w+j)*4+v;
    };

    auto ceil = [&](ll x){
        return (x+k-1)/k*k;
    };

    vector<ll> dist(h*w*4,INF);

    priority_queue<P,vector<P>,greater<P> > q;
    
    auto push = [&](ll i, ll j, ll v, ll x){
        ll id = toId(i,j,v);
        if(dist[id]<=x) return;
        dist[id]=x;
        q.emplace(P(x,id));
    };

    for(ll v=0;v<4;v++) push(si,sj,v,0);

    while(!q.empty()){
        ll d=q.top().first;
        ll id=q.top().second;
        q.pop();
        if(dist[id] < d) continue;
        ll i=id/4/w;
        ll j=id/4%w;
        ll v=id%4;
        for(ll nv=0;nv<4;nv++){
            push(i,j,nv,ceil(d));
        }
        ll ni=i+di[v];
        ll nj=j+dj[v];
        if(ni>=0 && ni<h && nj>=0 && nj<w){
            if(g[i][j]=='.'){
                push(ni,nj,v,d+1);
            }
        }
    }
    ll ans=INF;
    for(ll v=0;v<4;v++) ans=min(ans,dist[toId(ti,tj,v)]);
    if(ans==INF){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ceil(ans)/k<<endl;

}

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

const int MAX_N=101000;
bool prime[MAX_N+1];

void sieve()
{
  prime[0]=prime[1]=false;
  for(int i=2;i<=MAX_N;i++)
    prime[i]=true;
  for(int i=2;i<=MAX_N;i++)
    if(prime[i])
      for(int j=i*2;j<=MAX_N;j+=i)
	prime[j]=false;
}

int is_prime(int n,int p)
{
  vector<int> primeplus;
  vector<int> array;
  int l=0;
  for(int i=n+1;l<=30;i++)
    if(prime[i]){
      array.push_back(i); l++;
    }
  for(int i=0,k=0;k<=250;i++)
    for(int j=0;j<=i;j++){
      primeplus.push_back(array[i]+array[j]); k++;
    }
  sort(primeplus.begin(),primeplus.end());

  return primeplus[p-1];
}

int main()
{
  int n,p;
  sieve(); 
  for(;;){
    cin>>n>>p;
    if(n==-1&&p==-1) break;
    
    cout<<is_prime(n,p)<<endl;
  }
}


Measured memory_bytes: 1316
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int solve(){
    int a,b; cin>>a>>b;
    if(a>b) cout<<2*a-1;
    else if(a==b) cout<<a+b;
    else cout<<2*b-1;
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#define ll long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define inf 1ll<<60
ll read()
{
	ll tmp=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())tmp=tmp*10+c-'0';
	return tmp*f;
}
using namespace std;
int main()
{
	ll a=read(),b=read(),n=read();
	ll x=a/n;
	if(a%n>0)++x;
	ll y=b/n;
	printf("%lld\n",y-x+1);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main(){
  int n[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin>>K;
  cout<<n[K-1]<<endl;
  return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

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

// constexpr inline ll mod = 1'000'000'007;
// constexpr int max_n = 200'000 + 5;

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    int n;
    cin>>n;
    vector<int> res(n);
    rep(i,n-1) {
        int a; cin>>a; a--;
        res[a]++;
    }
    rep(i,n) {
        cout << res[i] << '\n';
    }

    return 0;
}


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

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  x -= a;
  cout << x%b << endl;
  return 0;
}


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

int main(){
  int a, b, c, max, ans;
  cin >> a >> b >> c;
  max = a;
  if (a < b & c < b){
    max = b;
  }
  if(b < c & a < c){
    max = c;
  }
  ans = a * b * c / max / 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{
    public static void main(String[] Args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        final int[][] mat = new int[n][n];
        StringTokenizer st;
        for(int i = 0; i<n; i++){
            st = new StringTokenizer(br.readLine(), " ");
            final int u = Integer.parseInt(st.nextToken())-1;
            final int k = Integer.parseInt(st.nextToken());
            for(int j = 0; j<k; j++){
                ++mat[u][Integer.parseInt(st.nextToken())-1];
            }
        }
        final StringBuilder sb = new StringBuilder();
        for(int i = 0; i<n; i++){
            sb.append(mat[i][0]);
            for(int j = 1; j<n; j++){
                sb.append(' ').append(mat[i][j]);
            }
            sb.append('\n');
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 25432
def main():
  import sys
  input = sys.stdin.readline
  
  N = int(input())
  E = [[] for _ in range(N)]
  # E:頂点a,bをつなぐ枝にiという番号をふる。
  for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    E[a].append((b,i))
    E[b].append((a,i))
  
  # dfs(u,v,p):uからvまでのパス上にある頂点をEGにセットする。
  EG = []
  def dfs(u,v,p):
    if u == v:
      return True
    for t,i in E[u]:
      if t == p:
        continue
      if dfs(t,v,u):
        EG.append(i)
        return True
    return False
  
  M = int(input())
  EM = []
  for i in range(M):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    EM.append((u,v))

  # ES[i]:i番目の制約のパス上にある頂点
  ES = []
  for i in range(M):
    u,v = EM[i]
    EG = []
    dfs(u,v,-1)
    ES.append((u,v,EG))
  
  ans = 0
  for i in range(1<<M):
    # EG2:iのビットが立っているところの制約のパス上にある頂点の集合。
    # bc:iのビットが立っている個数。
    EG2 = []
    bc = 0
    for j in range(M):
      if (i>>j)&1 == 1:
        bc += 1
        EG2 += ES[j][2]
    p = len(set(EG2))
    # 包除原理より
    if bc%2 == 0:
      ans += 2**(N-1-p)
    else:
      ans -= 2**(N-1-p)
  print(ans)

if __name__ == '__main__':
  main()


Measured memory_bytes: 43964
import math
# [int(i) for i in input().split(' ')]
n, = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')]

cur = 0
ret = 0
for t in a:
    if cur > t:
        ret += cur - t
    else:
        cur = t

print(ret)


Measured memory_bytes: 33016
#include <iostream>

using namespace std;

int main() {
    
    string a;
    string b;
    cin >> a >> b;
    int cnt = 0;
    for(int i = 0;i < 3;i++){
        
        if(a[i] == b[i]){
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}



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

ll kaijo(ll n) {
  if (n == 1)
    return 1;
  else
    return n * kaijo(n - 1) % c;
}

int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = (kaijo(n) * kaijo(m)) % c;
  if (n == m)
    cout << (ans * 2) % c << endl;
  else if (abs(n - m) == 1)
    cout << ans << endl;
  else
    cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 5156
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  string s,t;
  std::cin >> s >>t;
  if(s[0]==t[2] && s[1]==t[1] && s[2]==t[0]) printf("YES\n");
  else printf("NO\n");
  return 0;
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

s=array(3,1,0)
3.times do|i|
  s[i]=get_i
end
n=gets.to_i
ans=array(3,3,0)
b=array(n,1,0)
n.times do|i|
  b=gets.to_i
  3.times do|j|
    3.times do|k|
      ans[j][k]=1 if s[j][k]==b
    end
  end
end
if ans[1][1]==1 and ans[0][0]==1 and ans[2][2]==1
  puts "Yes"
elsif ans[1][1]==1 and ans[2][0]==1 and ans[0][2]==1
  puts "Yes"
else
  flag=true
  3.times do|i|
    flag=true
    3.times do|j|
      if ans[i][j]!=1
        flag=false
        break
      end 
    end
    if flag
      break
    end
  end
  if flag
    puts "Yes"
  else
    3.times do|i|
      flag=true
      3.times do|j|
        if ans[j][i]!=1
          flag=false
          break
        end
      end
        if flag
          break
        end
    end
    puts yn_judge(flag)
  end
end

Measured memory_bytes: 1788
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
f=[a,b,c,d,e]
data=[0]*5
for i in range(5):
  if f[i]%10==0:
    continue
  else:
    data[i]=10-f[i]%10
print(a+data[0]+b+data[1]+c+data[2]+d+data[3]+e+data[4]-max(data))

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

using namespace std;

int main(){
	int h, w, m;
	cin>>h>>w>>m;
	vector<int> col(w + 1, 0);
	vector<int> row(h + 1, 0);
	int A[m];
	int B[m];
	map<pair<int,int>, int> store_AB; 
	for (int i=0; i<m; i++){
		cin>>A[i]>>B[i];
		store_AB[ pair<int,int>(A[i], B[i])] ++;
		row[A[i]]++;
		col[B[i]]++;
	}
	int ans_1 = 0;
	int k = 0;
	int check = 0;
	for (int i=1; i<row.size(); i++){
		if(row[i] > ans_1){
			ans_1 = row[i];
		}
	}
	vector<int> store_1;
	for (int i=1; i<row.size(); i++){
		if(row[i] == ans_1){
			store_1.push_back(i);
		}
	}
	int ans_2 = 0;
	int l = 0;
	for (int i=1; i<col.size(); i++){
		if(col[i] > ans_2){
			ans_2 = col[i];
		}
	}
	vector<int> store_2;
	for (int i=1; i<col.size(); i++){
		if(col[i] == ans_2){
			store_2.push_back(i);
		}
	}
	for (int i=0; i<store_1.size(); i++){
		for (int j=0; j<store_2.size(); j++){
			if(store_AB[pair<int,int>(store_1[i], store_2[j])] == 0){
				check = 1;
				break;
			}
		}
		if(check == 1)	break;
	}
	if(check == 1) cout<<ans_1 + ans_2;
	else cout<<ans_1 + ans_2 - 1;
}

Measured memory_bytes: 30836
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c;
    cin>>n>>m>>c;
    vector<int> b(m);
    for(int i=0; i<m; i++){
        cin>>b.at(i);
    }
    int ans=0;
    int count=0;
    while(count<n){
        int z=0;
        for(int i=0; i<m; i++){
            int a;
            cin>>a;
            z+=a*b.at(i);
        }
        if(z+c>0) ans++;
        count++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3548
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
s = np.array(list(map(lambda x: 1 if x == "W" else 0,
                      list(input()))), 
             dtype=int)

wp = np.cumsum(s)
ope = 0
alter = 0
for c, w in zip(s[::-1], wp[::-1]):
    # c == "W"
    if c == 1:
        continue

    # c == "R"
    if w - ope > 0:
        ope += 1
    
    if w - ope == 0:
        break

print(ope)


Measured memory_bytes: 30344
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
/*
	Source: AtCoder Beginner Contest 054
	Author: fts2001 (the_silliest)
 */
using namespace std;
int a,b;
string n[55],m[55];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>a>>b;
    for(int i=0;i<a;i++){
        cin>>n[i];
    }
    for(int i=0;i<b;i++){
        cin>>m[i];
    }
    for(int i=0;i<a-b+1;i++){
        for(int j=0;j<a-b+1;j++){
            bool flag=true;
            for(int k=0;k<b;k++){
                for(int l=0;l<b;l++){
                    if(m[k][l]!=n[i+k][j+l]){
                        flag=false;
                        break;
                    }
                }
                if(!flag)break;
            }
            if(flag){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
from sys import stdin,stdout
s=input();n=len(s)
t=input();n1=len(t);ans=n1
for i in range(n-n1+1):
    s1=s[i:i+n1]
    changes=sum(1 for ch,ch1 in zip(t,s1) if ch!=ch1)
    ans=min(ans,changes)
print(ans)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << fixed << setprecision(10) << W * H / 2.0 << " ";
    if (W / 2.0 == x && H / 2.0 == y)
        cout << 1 << endl;
    else if (W / 2.0 == x || H / 2.0 == y || x == 0 || y == 0 || x == W || y  == H)
        cout << 0 << endl;
    else
        cout << 0 << endl;
}

Measured memory_bytes: 256
import Control.Applicative
 
main :: IO ()
main =  do 
    s <- getLine
    putStrLn $ solve s
 
solve :: String -> String
solve s | s == "Sunny"  = "Cloudy"
        | s == "Cloudy" = "Rainy" 
        | s == "Rainy"  = "Sunny"

Measured memory_bytes: 380
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 2000005
#define endl '\n'

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int fact[MAX];
int exp(int base, int e , int mod){
    int result = 1;
    base %= mod;
    while(e){
        if(e & 1 )
        result =  result  * base % mod;

            base = base * base % mod;
            e >>=1 ;
    }
    return result;
}

void factorial(){
    fact[0] = 1;
    for(int i = 1 ; i< MAX ; i++)
        fact[i] = fact[i-1] * i % MOD;
}

void solve() {
    factorial();
    int x , y;
    cin>>x>>y;
    if((x + y) % 3 != 0){
        cout<<0<<endl;
        return;
    }
    if((2 * x - y ) % 3 == 0 && (2 * y - x) % 3 == 0 ){
        int m = (2 * x - y) / 3 ;
        int n = (2 * y - x) / 3 ;
        if(m < 0 || n < 0)
            cout<<0<<endl;
        else cout<<fact[n + m] * (exp(fact[n] , MOD - 2 , MOD) * exp(fact[m] , MOD - 2 , MOD) % MOD) % MOD<<endl;
    }else cout<<0<<endl;

}


int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 15872
class Integer
    def seq?(i = nil)
        i ||= self % 10
        return false if self % 10 != i
        return true if self < 10
        (self / 10).seq?(i - 1)
    end
end
gets
a = gets.split.map(&:to_i)
p a.combination(2).map {|x, y| x * y}.select(&:seq?).max || -1


Measured memory_bytes: 10828