akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
INF = float("inf")
from bisect import bisect_left


def solve(N: int, K: int, A: "List[int]", F: "List[int]"):
    A.sort()
    F.sort(reverse=True)
    h = []
    for a, f in zip(A, F):
        h.append((a*f, a, f))
    h.sort()
    maxtime = h[-1][0]

    def isOK(y):
        i = bisect_left(h, (y+1, -1, -1))
        counter = 0
        # print(h[i:])
        for p, a, f in h[i:]:
            counter += a-y//f
        return counter <= K

    def binary_search(x):
        ng = -1
        ok = len(x)
        while abs(ok - ng) > 1:
            mid = (ok + ng)//2
            # print("mid: {}, in ({}, {})".format(mid, ng, ok))
            if isOK(mid):
                ok = mid
            else:
                ng = mid
        return ng, ok

    ng, ok = binary_search(range(maxtime))
    print(ok)

    # while k > 0:
    #     p1, a1, f1 = heapq.heappop(h)
    #     p2, a2, f2 = heapq.heappop(h)
    #     p1, p2 = -p1, -p2
    #     sub = min(a1 - math.ceil((p2/f1)-1), k)
    #     a1 -= sub
    #     k -= sub
    #     heapq.heappush(h, (-a1*f1, a1, f1))
    #     heapq.heappush(h, (-a2*f2, a2, f2))
    # # print(h)
    # p, a, f = heapq.heappop(h)
    # print(-p)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    F = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A, F)


if __name__ == '__main__':
    main()


Measured memory_bytes: 144812
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

#ifdef SHIK
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif

template<typename T>
void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( long long &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }

void R() {}
template<typename T, typename... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}

template<typename T>
void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
template<typename T>
void _W( const vector<T> &x ) {
    for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
        if ( i!=x.cbegin() ) putchar(' ');
        _W(*i);
    }
}

void W() {}
template<typename T, typename... U>
void W( const T& head, const U&... tail ) {
    _W(head);
    putchar(sizeof...(tail)?' ':'\n');
    W(tail...);
}

#ifdef SHIK
#define FILEIO(...)
#else
#define FILEIO(name) do {\
    freopen(name ".in","r",stdin); \
    freopen(name ".out","w",stdout); \
} while (0)
#endif

// }}}

const int N=110;
int n,a[N];
int main() {
    R(n);
    REP(i,n) R(a[i]);
    int ans=1e9;
    REP1(i,-100,+100) {
        int now=0;
        REP(j,n) now+=(a[j]-i)*(a[j]-i);
        ans=min(ans,now);
    }
    W(ans);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
K = int(input())
x = list(map(int, input().split()))
ans = []
for i in range(N):
    dx_a = abs(x[i] - 0)
    dx_b = abs(x[i] - K)
    ans.append(min(dx_a, dx_b) * 2)
print(sum(ans))

Measured memory_bytes: 3060
MOD = 998244353

N,K = map(int,input().split())

dp = [0]*(N+1)
dp[1]=1
ruiseki = [0]*(N+2)

LR = []
for k in range(K):
    l,r = map(int,input().split())
    LR.append([l,r]) 


for i in range(1,N+1):
    ruiseki[i]= (ruiseki[i] + ruiseki[i-1])%MOD
    dp[i]=ruiseki[i]
    if i == 1:
        dp[1]=1
    for k in range(K):
        l,r = LR[k]
        ruiseki[min(N+1,i+l)]= (ruiseki[min(N+1,i+l)] + dp[i])%MOD
        ruiseki[min(N+1,i+r+1)]=(ruiseki[min(N+1,i+r+1)] - dp[i])%MOD

print(dp[N])

Measured memory_bytes: 76992
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int W = sc.nextInt();
	long[][] value = new long[N][W+1];

	int[] w = new int[N];
	int[] v = new int[N];

	for(int i = 0; i<N; i++) {
	    w[i] = sc.nextInt();
	    v[i] = sc.nextInt();
	}

	for(int i = 0; i< N; i++) {
	    for(int j = 0; j< W+1; j++) {
		if(i == 0) {
		    if(w[0]<=j) value[i][j] = v[0];
		    continue;
		}
		if(j<=w[i]) {
		    value[i][j] = value[i-1][j];
		} else {
		    value[i][j] = Math.max(value[i-1][j-w[i]]+ v[i], value[i-1][j]);
		}
	    }
	}
	System.out.println(value[N-1][W]);


    }
}

Measured memory_bytes: 126804
#include<iostream>
using namespace std;
int main(){
char a[100000];
int k,j;
for(int i=0;i<100000;i++){cin>>a[i];}
for(k=0;k<50000;k++){
  if(!a[2*k]){return 0;}
  cout<<a[2*k];

}




return 0;
}

Measured memory_bytes: 384
#include<cstdio>

const int N=2005,D[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int n,m,Q,sumv[N][N],sume[N][N],sum[N][N][4];
char S[N][N];

int main()
{
	scanf("%d%d%d",&n,&m,&Q);
	for(int i=1;i<=n;i++)
		scanf("%s",S[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			sumv[i][j]=sumv[i-1][j]+sumv[i][j-1]-sumv[i-1][j-1]+(S[i][j]=='1');
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(S[i][j]=='1')
				for(int k=0;k<4;k++)
				{
					int x=i+D[k][0],y=j+D[k][1];
					if(x>=1&&x<=n&&y>=1&&y<=m&&S[x][y]=='1')
						sum[i][j][k]++,sume[i][j]++;
				}
			sume[i][j]+=sume[i-1][j]+sume[i][j-1]-sume[i-1][j-1];
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			for(int k=0;k<2;k++)
				sum[i][j][k]+=sum[i][j-1][k];
			for(int k=2;k<4;k++)
				sum[i][j][k]+=sum[i-1][j][k];
		}
	while(Q--)
	{
		int x1,y1,x2,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int v=sumv[x2][y2]-sumv[x2][y1-1]-sumv[x1-1][y2]+sumv[x1-1][y1-1];
		int e=sume[x2][y2]-sume[x2][y1-1]-sume[x1-1][y2]+sume[x1-1][y1-1];
		e-=sum[x2][y2][0]-sum[x2][y1-1][0];
		e-=sum[x1][y2][1]-sum[x1][y1-1][1];
		e-=sum[x2][y2][2]-sum[x1-1][y2][2];
		e-=sum[x2][y1][3]-sum[x1-1][y1][3];
		printf("%d\n",v-e/2);
	}
	return 0;
}


Measured memory_bytes: 99840
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n,m,a):
        t = [LI() for _ in range(m)]
        e = collections.defaultdict(set)
        for b,c in t:
            e[b].add(c)

        sm = max(a)
        ed = {}
        for i in range(1, n+1):
            t = {}
            q = set([i])
            for j in range(sm):
                nq = set()
                for c in q:
                    nq |= e[c]
                if (j+1) in a:
                    t[j+1] = nq
                q = nq
            ed[i] = t

        d = collections.defaultdict(lambda: None)
        d[n] = 0
        def ff(i):
            if not d[i] is None:
                return d[i]
            d[i] = inf
            mr = 0
            for n in a:
                mi = inf
                for ni in ed[i][n]:
                    t = ff(ni)
                    if mi > t:
                        mi = t
                if mr < mi:
                    mr = mi
            d[i] = mr + 1
            return mr + 1

        res = ff(1)
        for tt in range(n):
            for ti in range(1,n+1):
                if (not d[ti] is None) and d[ti] > tt:
                    d[ti] = None
            res = ff(1)
        if res >= inf:
            return 'IMPOSSIBLE'
        return res

    while 1:
        n,m,a,b,c = LI()
        if n == 0:
            break
        rr.append(f(n,m,[a,b,c]))
        break

    return '\n'.join(map(str, rr))


print(main())



Measured memory_bytes: 9832
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POSSIBLE(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Possible(i) cout<<(i?"Possible":"Impossible")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=998244353;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll A,ll B){
  return (B==0)?(A):(GCD(B,A%B));
}
ll LCM(ll A,ll B){
  return A/GCD(A,B)*B;
}
//
int main(){
	string S;
	int W;
	cin>>S>>W;
	int L=S.size();
	FOR(i,0,L){
		if(i%W==0){
			cout<<S[i];
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> z,s;
vector<string> vs;
int rec(int p,int u,int sum){
  if(p==z.size()) return !sum;
  int res=0;
  for(int i=z[p];i<10;i++) if(!((u>>i)&1)) res+=rec(p+1,u|(1<<i),sum+s[p]*i);
  return res;
}
int solve(){
  int i,j,k;
  vector<char> vc;
  map<char,int> m;
  for(i=0;i<vs.size();i++)
    for(j=0;j<vs[i].size();j++)
      if(m.find(vs[i][j])==m.end())
	m[vs[i][j]]=vc.size(),vc.push_back(vs[i][j]);
  z.clear();z.resize(vc.size(),0);
  s.clear();s.resize(vc.size(),0);
  reverse(vs.begin(),vs.end());
  for(i=0;i<vs.size();i++){
    if(vs[i].size()-1) z[m[vs[i][0]]]=1;
    reverse(vs[i].begin(),vs[i].end());
    for(j=0,k=1;j<vs[i].size();j++) s[m[vs[i][j]]]+=(i?1:-1)*k,k*=10;
  }
  return rec(0,0,0);
}
signed main(){
  int n;
  while(cin>>n,n){
    vs.clear();vs.resize(n);
    for(int i=0;i<n;i++) cin>>vs[i];
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 3112
from itertools import product
d = [[[e] if s+1 == e or (s-1 == e and s < 6) else range(11) for e in xrange(10)]
      for s in xrange(10)]
d[9][5] = [5]
for k,i,j in product(xrange(10),repeat=3):
    d[i][j] = min(d[i][j],d[i][k]+d[k][j],key=lambda x:len(x))
for s in xrange(7,10):
    for e in xrange(6,s):
        d[s][e] = d[s][0] + range(1,e+1)
for _ in xrange(input()):
    s,e = map(int,raw_input().split())
    print "{} {}".format(str(s)," ".join(map(str,d[s][e])))

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

using namespace std;

typedef long long ll;

const int MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> t(n), a(n);
    for (int i = 0; i < n; i++) cin >> t[i];
    for (int i = 0; i < n; i++) cin >> a[i];
    reverse(a.begin(), a.end());
    vector<int> m(n, 0);
    m[0] = t[0];
    for (int i = 1; i < n; i++) {
        if (t[i] > t[i - 1]) m[i] = t[i];
    }
    if (m[n - 1] != 0 && m[n - 1] != a[0]) {
        cout << 0 << endl;
        return 0;
    }
    m[n - 1] = a[0];
    for (int i = 1; i < n; i++) {
        if (a[i] > a[i - 1]) {
            if (m[n - i - 1] != 0 && m[n - i - 1] != a[i]) { 
                cout << 0 << endl;
                return 0;
            }
            if (m[n - i - 1] == 0 && a[i] > t[n - i - 1]) {
                cout << 0 << endl;
                return 0;
            }
            m[n - i - 1] = a[i];
        }
    }
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        if (m[i] == 0) ans = ans * (min(t[i], a[n - i - 1]) % MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int par[101];
int rank[101];
void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=1;
  }
}
int find(int x){
  if(par[x]==x){
    return x;
  }else{
    return par[x]=find(par[x]);
  }
}
void unit(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(rank[x]<rank[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(rank[x]==rank[y])rank[x]++;
  }
}
bool same(int x,int y){
  return find(x)==find(y);
}
struct edge{int u,v,cost;};
bool comp(const edge& e1,const edge& e2){
  return e1.cost<e2.cost;
}
edge es[10001];
int V,E;
int kruskal(){
  sort(es,es+E,comp);
  init(V);
  int res=0,cnt=0;
  for(int i=0;i<E;i++){
    edge e=es[i];
    if(!same(e.u,e.v)){
      unit(e.u,e.v);
      res+=e.cost;
      cnt++;
    }
  }
  return res/100-cnt;
}
int main(){
  while(cin>>V,V){
    cin>>E;
    for(int i=0;i<E;i++)
      scanf("%d,%d,%d",&es[i].u,&es[i].v,&es[i].cost);
    cout<<kruskal()<<endl;
  }
}

Measured memory_bytes: 3124
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a[5];
    int i;
    int min[2];
    min[1]=10;
    for(i=0;i<5;i++) {
        cin >> a[i];
        if(min[1]>a[i]%10 && a[i]%10!=0)min[1]=a[i]%10,min[0]=i;
    }
    int ans=0;
    for(i=0;i<5;i++){
        
       if (min[0]==i) ans+=a[i];
       else {
         if(a[i]%10!=0)ans+=a[i]/10*10+10;
        else ans+=a[i];
       }
    }
  cout << ans<< endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
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[i];
    }
    vector<vector<int>> A(N, vector<int>(M));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int sum = 0;
        for (int j = 0; j < M; j++) {
            sum += A[i][j] * B[j];
        }
        sum += C;
        if (sum > 0) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    string sa, sb, sc; cin >> sa >> sb >> sc;

    int a = 0;
    int b = 0;
    int c = 0;

    string next = "a";

    while (a <= sa.size() && b <= sb.size() && c <= sc.size()) {
        if (next == "a") {
            next = sa[a];
            ++a;
        }

        if (next == "b") {
            next = sb[b];
            ++b;
        }

        if (next == "c") {
            next = sc[c];
            ++c;
        }
    }

    if (a > sa.size()) {
        puts("A");
        return 0;
    }

    if (b > sb.size()) {
        puts("B");
        return 0;
    }

    if (c > sc.size()) {
        puts("C");
        return 0;
    }
}

Measured memory_bytes: 256
package main

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

/*-----------Main-----------*/

func main() {
	a, b, c := readI(), readI(), readI()
	k := readI()
	for i := 0; i < k; i++ {
		switch {
		case a >= b:
			b *= 2
		case b >= c:
			c *= 2
		}
	}
	if a < b && b < c {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

/*-----------Utilities-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}

func max(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] > m {
			m = a[i]
		}
	}
	return m
}

func min(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

func sortI(a []int) []int {
	sort.Ints(a)
	return a
}

func reverse(a []int) []int {
	l := len(a)
	r := make([]int, l)
	for i := 0; i < l; i++ {
		r[i] = a[l-i-1]
	}
	return r
}

func countI(a []int, b int) int {
	l := len(a)
	var c int
	for i := 0; i < l; i++ {
		if a[i] == b {
			c++
		}
	}
	return c
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	cin>>n>>k;
	long double res = 0;
	for(double x = 1; x <= n; ++x){
		double r = x;
		double s = 1;
		while(r <= k - 1){r *= 2; s *= 0.5;}
		//cout<<cnt<<endl;
		//cout<<s * (1.0 / n)<<endl;
		res += s * (1.0 / n);
	}
	cout<<setprecision(9)<<res<<endl;
	return 0;
}


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

namespace AtTest.ABC_121
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nmc = ReadInts();
            int n = nmc[0];
            int m = nmc[1];
            int c = nmc[2];
            int[] bs = ReadInts();
            int res = 0;
            for(int i = 0; i < n; i++)
            {
                int[] array = ReadInts();
                int tmp = 0;
                for(int j = 0; j < m; j++)
                {
                    tmp += array[j] * bs[j];
                }
                tmp += c;
                if (tmp > 0) res++;
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    string s;
    cin >> s;

    vector<string> day{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    REP(i, 7){
        if (day[i] == s) {
            i = 7 - i;
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n, a, b, ans = 0;
  scanf("%d%d%d", &n, &a, &b);
  for (int i=1; i<=n; i++) {
    int c = i, sum = 0;
    while (c != 0) {
      sum += c % 10;
      c /= 10;
    }
    if (a <= sum && sum <= b) ans += i;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int a, b, k;
  cin >> a >> b >> k;

  int cnt = 0;
  rep(i, 1000) {
    if ((a % (1000-i) == 0) && (b % (1000-i) == 0)) {
      cnt++;
    }
    if (cnt == k) {
      cout << 1000-i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a, b, c;
	int temp = 0;

	scanf("%d %d %d", &a, &b, &c);

	if (a > b) {
		temp = a; // 置き換える
		a = b;
		b = temp;
	}

	if (b > c) {
		temp = b;
		b = c;
		c = temp;
	}

	if (a > b){
		temp = a;
		a = b;
		b = temp;
	}

	printf("%d %d %d\n", a, b, c);

	return(0);

}


Measured memory_bytes: 2100
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = float("inf")
a.sort()
for i in range(N):
  t = 0
  p = a[i]
  for j in range(N):
    t += abs(p - a[j])
    p = a[j]
  res = min(res, t)
print(res)

Measured memory_bytes: 38768
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n; cin >> n;
  ll c1 = 0, c2 = 0, c3 = 0, sum = 0;
  rep(i, n) {
    string s; cin >> s;

    if (s[0] == 'B' && s[s.size() - 1] == 'A') c1++;
    else if (s[0] == 'B') c2++;
    else if (s[s.size() - 1] == 'A') c3++;

    for (int j = 1; j < s.size(); j++)
      if (s[j-1] == 'A' && s[j] == 'B') sum++;
  }
  if (c1 == 0) outl(sum + min(c2, c3));
  else if (c2 + c3 > 0) outl(sum + min(c2, c3) + c1);
  else outl(sum + c1 - 1);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

mod = 10**9+7

n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append(b)
    G[b].append(a)

cnt = [0]*n
def dfs(cur, prev):
    tmp = 1
    for to in G[cur]:
        if to != prev:
            tmp += dfs(to, cur)
    cnt[cur] = tmp
    return tmp

dfs(0, -1)

power = [0]*(n)
powe2_n = pow(2, n, mod)
powe2_n = pow(powe2_n, mod-2, mod)
power[n-1] = powe2_n
for i in reversed(range(n-1)):
    powe2_n *= 2
    powe2_n %= mod
    power[i] = powe2_n
ans = 0
from collections import deque
que = deque()
que.append((0, -1))

while que:
    cur, prev = que.pop()
    if len(G[cur]) == 1:
        if prev == -1:
            que.append((G[cur][0], cur))
        continue

    prob = 1
    prob -= power[n-2]

    for to in G[cur]:
        if to == prev:
            bubun_cnt = n-cnt[cur]
        else:
            que.append((to, cur))
            bubun_cnt = cnt[to]
        tmp = 1-power[bubun_cnt-1]
        tmp *= power[n-1-bubun_cnt-1]
        prob -= tmp
    prob %= mod
    ans += power[0]*prob
    ans %= mod

print(ans)



Measured memory_bytes: 169520
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
//============================================================================
//?????°?????????
//============================================================================
	int N,K;
	int A[101],B[101];
//============================================================================
//??\???
//============================================================================
	cin>>N>>K;
	for (int i=0;i<K;i++){
		cin>>A[i]>>B[i];
	}
	int D[101]={};
	for (int i=0;i<K;i++){
		D[A[i]]=B[i];
	}
//============================================================================
//????¨??????????
//============================================================================
	int R;

	int oldTT=0,newTT=1,oldCT=0,newCT=1,oldVT=0,newVT=1;
	int oldTC=0,newTC=1,oldCC=0,newCC=1,oldVC=0,newVC=1;
	int oldTV=0,newTV=1,oldCV=0,newCV=1,oldVV=0,newVV=1;
///
	if (D[1]==1){
		newCT=0;
		newVT=0;
		newCC=0;
		newCV=0;
		newVC=0;
		newVV=0;
	}
	if (D[1]==2){
		newTT=0;
		newTV=0;
		newVC=0;
		newTC=0;
		newVT=0;
		newVV=0;
	}
	if (D[1]==3){
		newTT=0;
		newTC=0;
		newCT=0;
		newCC=0;
		newCV=0;
		newTV=0;
	}
	if (D[2]==1){
		newTC=0;
		newTV=0;
		newCC=0;
		newCV=0;
		newVC=0;
		newVV=0;
	}
	if (D[2]==2){
		newTT=0;
		newTV=0;
		newCT=0;
		newCV=0;
		newVT=0;
		newVV=0;
	}
	if (D[2]==3){
		newTT=0;
		newTC=0;
		newCT=0;
		newCC=0;
		newVT=0;
		newVC=0;
	}


	for (int i=3;i<N+1;i++){
		oldTT=newTT;
		oldTC=newTC;
		oldTV=newTV;
		oldCT=newCT;
		oldCC=newCC;
		oldCV=newCV;
		oldVT=newVT;
		oldVC=newVC;
		oldVV=newVV;

		newTT=(oldCT+oldVT)%10000;
		newTC=(oldTT+oldCT+oldVT)%10000;
		newTV=(oldTT+oldCT+oldVT)%10000;
		newCT=(oldCC+oldTC+oldVC)%10000;
		newCC=(oldTC+oldVC)%10000;
		newCV=(oldCC+oldTC+oldVC)%10000;
		newVT=(oldVV+oldCV+oldTV)%10000;
		newVC=(oldVV+oldCV+oldTV)%10000;
		newVV=(oldCV+oldTV)%10000;

		if (D[i]==1){
			newTC=0;
			newTV=0;
			newCC=0;
			newCV=0;
			newVC=0;
			newVV=0;
		}
		if (D[i]==2){
			newTT=0;
			newTV=0;
			newCT=0;
			newCV=0;
			newVT=0;
			newVV=0;
		}
		if (D[i]==3){
			newTT=0;
			newTC=0;
			newCT=0;
			newCC=0;
			newVT=0;
			newVC=0;
		}
	}

	R=(newTT+newCT+newVT+newTC+newCC+newVC+newTV+newCV+newVV)%10000;

//============================================================================
//????????????R
//============================================================================
	cout<<R<<endl;
	return 0;

}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int sum=0;
	  for(int i=0;i<n;i++)
	  {
	  	for(int j=i+1;j<n;j++)
	  	sum+=a[i]*a[j];
	  }
	cout<<sum;
	
}

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

#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      int x;
      cin>>x;
      if(x==0){cout<<1<<endl;}
      else cout<<0<<endl;

      bye;
}


Measured memory_bytes: 3636
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for n in range(N):
  tmp = input()
  if tmp == "AC":
    AC += 1
  elif tmp == "WA":
    WA += 1
  elif tmp == "TLE":
    TLE += 1
  else:
    RE += 1
print("AC x "+str(AC))
print("WA x "+str(WA))
print("TLE x "+str(TLE))
print("RE x "+str(RE))

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	string s; cin >> s;
	string rev(s); reverse(rev.begin(), rev.end());
	if (s == rev) {
		string one = s.substr(0, ((s.size() - 1 / 2)));
		string revOne(one); reverse(revOne.begin(), revOne.end());
		if (one == revOne) {
			string two = s.substr((s.size() + 3) / 2 - 1);
			string revTwo(two); reverse(revTwo.begin(), revTwo.end());
			if (two == revTwo) {
				cout << "Yes";
			} else cout << "No";
		} else cout << "No";
	} else cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
 
int main ()
{
  prep();
  int a, b;
  cin >> a >> b;
  cout << (a^b);
  return 0; 
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order
//order_of_key

const int maxn = 1e6 + 5;

ll a,b,c,x,y;

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

  cin>>a>>b>>c>>x>>y;
  ll tot = 0;

  ll both = min(x,y);
  tot += both*min(a+b,2LL*c);
  x -= both;
  y -= both;

  tot += x*min(a,2LL*c);
  tot += y*min(b,2LL*c);
  
  cout<<tot<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>

typedef long long LL;
const LL Inf = 0x3f3f3f3f3f3f3f3f;
const int MN = 100005;

int N, X, Y, Z, B[MN], C[MN], P[MN];
LL Pre[MN], Suf[MN];
std::priority_queue<LL> pq;
LL Sum, Ans;

int main() {
	scanf("%d%d%d", &X, &Y, &Z), N = X + Y + Z, Ans = -Inf;
	for (int i = 1; i <= N; ++i) {
		int a;
		scanf("%d%d%d", &a, &B[i], &C[i]);
		B[i] -= a, C[i] -= a, P[i] = i;
		Sum += a;
	}
	std::sort(P + 1, P + N + 1, [](int i, int j) { return B[i] > B[j]; });
	for (int i = 1; i <= Y + Z; ++i) {
		Pre[i] = Pre[i - 1] + B[P[i]];
		pq.push(C[P[i]] - B[P[i]]);
		if ((int)pq.size() > Y) Pre[i] += pq.top(), pq.pop();
	}
	while (!pq.empty()) pq.pop();
	for (int i = N; i > Y; --i) {
		Suf[i] = Suf[i + 1];
		pq.push(C[P[i]]);
		if ((int)pq.size() > X) Suf[i] += pq.top(), pq.pop();
	}
	for (int i = Y; i <= Y + Z; ++i)
		Ans = std::max(Ans, Pre[i] + Suf[i + 1]);
	printf("%lld\n", Sum + Ans);
	return 0;
}

Measured memory_bytes: 5704
from collections import deque

n, m = map(int, input().split())
lst = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    lst[a].append(b)
    lst[b].append(a)

tai = [False] * (n+1)
tai[1] == True
ans = [0] * (n+1)

tri = deque([1])
while len(tri) > 0:
    num = tri.popleft()
    for i in lst[num]:
        if tai[i]:
            continue
        tri.append(i)
        tai[i] = True
        ans[i] = num

print('Yes')
for i in range(2, n+1):
    print(ans[i])

Measured memory_bytes: 98948
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  int maxnum=0;
  long long int ans=0;
  rep(i,n){
    maxnum=max(maxnum,a[i]);
    int Bi=maxnum;
    ans+=Bi-a[i];
  }
  cout<<ans;
}


Measured memory_bytes: 3964
// https://atcoder.jp/contests/abc106/tasks/abc106_b
#include <bits/stdc++.h>
using namespace std;
using P = pair<double, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// 約数の列挙
vector<int64_t> divisor(int64_t n) {
    vector<int64_t> ret;
    for (int64_t i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, cnt = 0;
    cin >> n;
    if (n < 105) {
        cout << "0\n";
        return 0;
    } else {
        for (int i = 105; i <= n; i += 2) {
            auto t = divisor(i);
            if (t.size() == 8) {
                cnt++;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
/*
ID: iCoder0020
PROG: Grid 1
LANG: C++                  
*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define INF 1e9
#define MOD 1000000007

template <typename T> void max_self(T &a, T b)
{
	a = max(a, b);
}

template <typename T> void min_self(T &a, T b)
{
	a = min(a,b);
}

int32_t main()
{
	int H,W;
	cin>>H>>W;
	char grid[H][W];
	for(int h = 0; h<H; h++)
		for(int w = 0; w<W; w++)
			cin>>grid[h][w];
	vector<vector<int>> dp(H, vector<int>(W, 0));
	dp[0][0] = 1;
	for(int i = 1; i<W; i++)
	{
		if(grid[0][i] == '.')
			dp[0][i] = dp[0][i-1];
		else
			dp[0][i] = 0;
	}
	for(int i = 1; i<H; i++)
	{
		if(grid[i][0] == '.')
			dp[i][0] = dp[i-1][0];
		else
			dp[i][0] = 0;
	}
	for(int i = 1; i<H; i++)
	{
		for(int j = 1; j<W; j++)
		{
			if(grid[i][j] == '#')
				dp[i][j] = 0;
			else
				dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
		}
	}

	cout<<dp[H-1][W-1]<<endl;
	return 0;	
}

Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include<cstring>
#include <string>
#define io ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int N=1e5+10;
//char s[N];
int a[N],b[N];
void solve(){
    string s;
    cin>>s;
    int n=s.size();
    unsigned long long ans=0;
    for(int i=0;i<n;i++){
        ans+=s[i]-'0';
    }
    if(ans%9)cout<<"No";
    else cout<<"Yes";
}
int main(){
    io;
    //int T;cin>>T;
    //while(T--)
        solve();
}


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

int main(){
	
	while(1){
	int i,j;
	int n,m;
	string a,b;
	vector<string> c,d;
	string x;
	vector<string> y;
	
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++){
			cin>>a;
			cin>>b;
			c.push_back(a);
			d.push_back(b);
		}

		cin>>m;
		for(i=0;i<m;i++){
			cin>>x;
			for(j=0;j<n;j++){
				if(x==c[j]){
					x=d[j];
					break;
				}
			}
			y.push_back(x);
		}
		
		for(i=0;i<m;i++) cout<<y[i];
		cout<<endl;
	}
return 0;
}

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

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}

set<ll> mp[50];
vi a;
void f(int i, ll mask) {
	if (mp[i].count(mask)) return;
	mp[i].insert(mask);
	if (i == sz(a)) return;
	f(i+1, mask);
	int x = a[i];
	for (int j = x; j <= 32; j += x) mask |= (1LL<<j);
	f(i+1, mask);
}

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

	int n; cin >> n;
	vi t(101);
	FOR (i,1,25) a.push_back(i), t[i]=1;
	FOR (i, 13,16) a.push_back(2*i), t[2*i]=1;
	f(0, 0);
	vi c(n+1); FOR (i, 1, n) cin >> c[i];
	ll sum = accumulate(all(c), 0LL);
	ll ans = sum;
	for (int &i : c) i *= -1;

	for (auto mask : mp[sz(a)]) {
		ll cur = 0;
		vi yo(n+1);
		FOR (i, 1, 32) if ((mask>>i)&1) {
			for (int j = i; j <= n; j += i) yo[j] = 1;
		}
		NFOR (i, n, 1) {
			if (yo[i]) cur += c[i];
			else if (!t[i]) {
				ll here = c[i];
				if (i*2 <= n and !yo[i*2]) here += c[i*2];
				if (i*3 <= n and !yo[i*3]) here += c[i*3];
				if (here > 0) {
					cur += here;
					yo[i]=1;
					if (i*2 <= n) yo[i*2]=1;
					if (i*3 <= n) yo[i*3]=1;
				}
			}
		}
		ans = max(ans, sum+cur);
	}
	cout << ans;


	return 0;
}


Measured memory_bytes: 63616
n,m = map(int,input().split())
lr = [list(map(int,input().split())) for _ in range(m)]
for i in range(m-1):
  if lr[i][0] > lr[i+1][0]:
    lr[i+1][0] = lr[i][0]
  if lr[i][1] < lr[i+1][1]:
    lr[i+1][1] = lr[i][1]
ans = lr[-1][1] - lr[-1][0] + 1
if ans >= 0:
  print(ans)
else:
  print(0)

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

int main() {
	string S;
	string T;
	cin >> S;
	cin >> T;
	int lenS = S.size();
	int lenT = T.size();
	int max = 0;
	for (int i = 0; i < lenS - lenT + 1; i++) {
		int count = 0;
		for (int j = 0; j < lenT; j++) {
			if (S[i + j] == T[j]) {
				count++;
			}
			if (count > max) {
				max = count;
			}
		}
	}
	cout << lenT - max << endl;
	return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int n;
    cin>>n>>s;
    for(int i=0;i<s.size();i++){
        if((int)s[i]+n>90){
            s[i] = s[i]+n-90+'A'-1;
        }
        else{
            s[i] = s[i]+n;
        }
        cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
c = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    c[a].append(b)
    c[b].append(a)

ans = 0
for i in range(n):
    high = h[i]
    for j in c[i]:
        if h[j] >= high:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 29316
#include <stdio.h>
int fibonacci(int n){
	int i;
	int f=1, f1=1, f2=1;
	for(i=2; i<=n; i++){
		f=f1+f2;
		f2=f1;
		f1=f;
	}
	return f;
}
int main(void){
	int n;
	scanf("%d", &n);
	printf("%d\n", fibonacci(n));
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[310][310];

int main(){
	ll sum=0;
	int n;cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++){
			bool flag=1;
			for(int k=1;k<=n;k++){
			if(a[i][j]>a[i][k]+a[k][j]){
				cout<<-1<<endl;
				return 0;
			}
			else if(i!=k&&j!=k&&a[i][j]==a[i][k]+a[k][j])
					flag=0;
			}
		if(flag){
			sum+=a[i][j];
		}
	}
}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 1024
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


def main():
    s = input()   
    count = 0
    ans = 0
    for i in s:
        if i == "R":
            count += 1
            ans = count
        else:
            count = 0
    print(ans)

if __name__ == '__main__':
	main()


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

int main() {
  int N, p, w, g, y;
  p = 0; w = 0; g = 0; y = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    string S;
    cin >> S;
    if(S == "P"){
      p++;
    }
    else if(S == "W"){
      w++;
    }
    else if(S == "G"){
      g++;
    }
    else if(S == "Y"){
      y++;
    }
  }
  if(p == 0 || w == 0 || g == 0 || y == 0){
    cout << "Three" << endl;
  }
  else if(p > 0 && w > 0 && g > 0 && y > 0){
    cout << "Four" << endl;
  }
}
    
  

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

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

int main() {
    int n;
    int a[100] = {0};
    cin >> n;
    rep(i,n) cin>>a[i];
    for(int i=n-1; i>=0; i--) {
        cout << a[i];
        if(i == 0) cout << endl;
        else cout << " ";
    }

    return 0;
}

Measured memory_bytes: 1160
l = int(input())

# ans = 0
# for i in range(1, 999):
#     for j in range(1, 999):
#         k = l - i - j
#         if 1 <= k <= 1000:
#             ans = max(ans, i*j*k)

# print(ans)

x = l/3
print(x**3)

Measured memory_bytes: 38256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	scan(N);
	char ans[1002][1002]={};
	char ans3[8][8]={"add","a.c","bbc"};
	char ans4[8][8]={"aaca","bbca","acbb","acaa"};
	char ans5[8][8]={"abbaa","acc.b","b..cb","b..ca","aabba"};
	char ans6[8][8]={"addaa.","a.c..b","bbc..b","aa.add","..ca.c","..cbbc"};
	char ans7[8][8]={"abbaa..","a.abb..","bba..aa","ac...bb","ac...aa","..aba..","..aba.."};
	rep(i,N) rep(j,N) ans[i][j]='.';
	if(N==2){
		prin(-1);
	}
	else if(N==3){
		rep(i,N) prin(ans3[i]);
	}
	else{
		int now=0;
		while(now<N){
			if(now+5==N){
				for(int i=now;i<now+5;i++) for(int j=now;j<now+5;j++) ans[i][j]=ans5[i-now][j-now];
				now+=5;
			}
			else if(now+6==N){
				for(int i=now;i<now+6;i++) for(int j=now;j<now+6;j++) ans[i][j]=ans6[i-now][j-now];
				now+=6;
			}
			else if(now+7==N){
				for(int i=now;i<now+7;i++) for(int j=now;j<now+7;j++) ans[i][j]=ans7[i-now][j-now];
				now+=7;
			}
			else{
				for(int i=now;i<now+4;i++) for(int j=now;j<now+4;j++) ans[i][j]=ans4[i-now][j-now];
				now+=4;
			}
		}
		rep(i,N){
			rep(j,N){
				printf("%c",ans[i][j]);
			}
			kaigyo;
		}
	}
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
      vector<int>T(3);
      for(int i=0;i<3;i++){
        cin>>T.at(i);}
      sort(T.begin(),T.end());
      
      if(T.at(0)+T.at(1)==T.at(2)){cout<<"Yes"<<endl;}
      else{cout<<"No"<<endl;}
      return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int k,q,d[5010];
	cin >> k >> q;
	for(int i = 0;i < k;i++) cin >> d[i];
	for(int i = 0;i < q;i++){
		int n,x,m;
		cin >> n >> x >> m;
		int sum = 0,zero = 0;
		for(int j = 0;j < k;j++){
			sum += d[j] % m;
			if(d[j] % m == 0) zero++;
		}
		int la = x + (n - 2) / k * sum,ans = 0;
		for(int j = 0;j <= (n - 2) % k;j++){
			la += d[j] % m;
			if(d[j] % m == 0) ans--;
		}
		cout << ans + n - 1 - (la / m - x / m) - (n - 2) / k * zero << endl;
	}
}

Measured memory_bytes: 384