akhauriyash/Code-Regression huggingface dataset:
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
  ll a, b;
  cin >> a >> b;

  ll c = b - a;

  ll B = 0;
  ll old = 0;
  for (int i = 1; i <= c; ++i) {
    B = old + i;
    old = B;
  }

  cout << B - b << endl;
  
  return 0;
}

Measured memory_bytes: 3564
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]

d = dict()
for name in s:
    if name[0] not in d:
        d[name[0]] = 1
    else:
        d[name[0]] += 1

res = 0
for v in list(combinations(['M', 'A', 'R', 'C', 'H'], 3)):
    if v[0] in d and v[1] in d and v[2] in d:
        res += d[v[0]] * d[v[1]] * d[v[2]]

print(res)

Measured memory_bytes: 83224
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func main() {
	defer write.Flush()

	var n, m int
	fmt.Fscan(read, &n, &m)

	ans := n*(n-1)/2 + m*(m-1)/2
	fmt.Fprintln(write, ans)
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

static class CodeJam
{
    static int[] Solve(int N, int[] B)
    {
        var list = new List<int>(B);
        var stack = new Stack<int>();
        while (list.Count > 0)
        {
            int i = list.Count - 1;
            while (i >= 0)
            {
                if (list[i] == i + 1)
                {
                    stack.Push(i + 1);
                    list.RemoveAt(i);
                    break;
                }
                --i;
            }
            if (i < 0) { return null; }
        }
        return stack.ToArray();
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] B = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var ans = Solve(N, B);
        if (ans != null)
        {
            foreach (int n in ans) { Console.WriteLine(n); }
        }
        else
        {
            Console.WriteLine(-1);
        }
    }
}


Measured memory_bytes: 13268
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        while (true)
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 0) break;
            var s = Enumerable.Repeat(0, n).Select(_ => int.Parse(Console.ReadLine())).ToArray();
            var min =  s.Min();
            var max =  s.Max();
            Console.WriteLine((s.Sum() - min - max) / (n - 2));
        }
        Console.Out.Flush();
    }
}


Measured memory_bytes: 16328
n,d,a = map(int,input().split())
xh = [list(map(int,input().split())) for _ in range(n)]
xh.sort()

ans = 0
att = [0]*n
cnt = 0
f = []
f1 = [0]*n

for x,h in xh:
    f.append(h)

for i in range(n):
    tmp = xh[i][0] + 2 * d
    while cnt < n:
        if xh[cnt][0] <= tmp:
            cnt += 1
        else:
            break
    att[i] = min(cnt-1, n-1)

for i in range(n):
    if f[i] > 0:
        da = -(-f[i]//a)
        ans += da
        f1[i] -= da * a
        if att[i]+1 < n:
            f1[att[i]+1] += da * a
    if i < n-1:
        f1[i+1] += f1[i]
        f[i+1] += f1[i+1]
print(ans)


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

using namespace std;

int main() {
        string s;
        cin >> s;
        int a=s.length();
        int cnt=0, haba=0;
        for(int i=2; i<=a-2; i++){
            if(s[i]=='C')
                cnt++;
        }
        for(int i=1; i<a; i++){
            if(int(s[i])>=65 && int(s[i]<91))
            haba++;
        }
        if(s[0]=='A' && cnt==1 && haba==1){
            cout << "AC";
            return 0;
        }
        else{
            cout << "WA";
            return 0;
        }
}


Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<iostream>
#define LL long long
using namespace std;
const int N=100010;
struct lxs1
{
	LL x;
};
struct lxs2
{
	bool operator()(lxs1 a,lxs1 b) 
	{
		return a.x<b.x;
	}
};
LL n,m,ans;
priority_queue<lxs1,vector<lxs1>,lxs2> d;
int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	{
		lxs1 y;
		scanf("%lld",&y.x);
		d.push(y);
	}
	while(m!=0&&d.top().x!=0)
	{
		lxs1 now=d.top();
		d.pop();
		while(m!=0&&now.x>=d.top().x&&now.x!=0)
		{
			now.x/=2;
			m--;
		}
		d.push(now);
	}
	while(d.top().x!=0&&!d.empty())
	{
		ans+=d.top().x;
		d.pop();
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  int N,M;
  cin >> N >> M;
  vector<bool> over(N,false);
  vector<int> WA(N,0);
  for(int i=0;i<M;i++){
    int p;
    string S;
    cin >> p >> S;
    --p;
    if(over[p]){
      continue;
    }
    if(S=="AC"){
      over[p]=true;
    }
    else{
      WA[p]++;
    }
  }
  int ACans=0,WAans=0;
  for(int i=0;i<N;i++){
    if(over[i]){
      ACans++;
      WAans+=WA[i];
    }
  }
  cout << ACans << " " << WAans << endl;
}

Measured memory_bytes: 3732
module Main where

import Control.Applicative
import Data.List

getInt :: IO Int
getInt = head <$> getInts

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  {xs <- getInts
  ; putStrLn $ unwords $ map show $ sort xs
  }



Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define pb push_back
#define in insert
#define ff first
#define ss second
#define mp make_pair
#define int long long
#define uint unsigned long long
#define rep(i,x,m) for(int i=x;i<m;i++)
#define repr(i,x,m) for(int i=x;i>=m;i--)
#define MOD 1000000007
#define endl "\n"
using namespace std;
#define noob ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void ram5564()
{
    int n;
    cin>>n;
    bool ok=false;
    while(n--)
    {
    	int a;
    	cin>>a;
    	if(a%2==0)
    	{
    		if(a%3!=0&&a%5!=0)
    		{
    			ok=true;
    		}
    	}
    }
    if(ok)
    	cout<<"DENIED";
    else 
    	cout<<"APPROVED";
}

signed main()
{
		noob
		
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 768
A, B, C, D = [int(_) for _ in input().split()]

import numpy as np

# B
b = (B // C + B // D) - (B // np.lcm(C, D))
A = A - 1
a = (A // C + A // D) - (A // np.lcm(C, D))

print(B - A - (b - a))

Measured memory_bytes: 26928
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cctype>
#define LL long long
#define N 200010
#define M 4010
using namespace std;
const LL MOD = 1000000007LL;
int u[N], v[N];
LL cnt[M][M], fac[M * 2], infac[M * 2];
int n, m;

LL pow(LL x, LL y){
	LL ret = 1LL;
	while (y){
		if (y % 2) ret = ret * x % MOD;
		x = x * x % MOD;
		y /= 2;
		//cout << y << endl;
	}
	return ret;
}
void Init(){
	fac[0] = 1LL, infac[0] = 1LL;
	for (LL i = 1; i <= 8000; ++ i){
		fac[i] = fac[i - 1] * i % MOD;
		infac[i] = pow(fac[i], MOD - 2LL);
	}
}

LL cal(int x, int y){
	return fac[x + y] * infac[x] % MOD * infac[y] % MOD;
}

int main(){
	int i, j;
	Init();

	scanf("%d", &n);
	for (i = 0; i < n; ++ i){
		scanf("%d%d", &u[i], &v[i]);
		cnt[2000 - u[i]][2000 - v[i]]++;
	}
	for (i = 0; i <= 4000; ++ i)
		for (j = 0; j <= 4000; ++ j){
			if (i > 0)  cnt[i][j] = (cnt[i - 1][j] + cnt[i][j]) % MOD;
			if (j > 0)  cnt[i][j] = (cnt[i][j - 1] + cnt[i][j]) % MOD;
		}

	LL ans = 0LL;
	for (i = 0; i < n; ++ i){
		ans = (ans + cnt[2000 + u[i]][2000 + v[i]]) % MOD;
		ans = (ans - cal(2 * u[i], 2 * v[i])) % MOD;
		if (ans < 0) ans += MOD;
	}
	ans = (ans * pow(2LL, MOD - 2LL)) % MOD;
	printf("%lld\n", ans);
}

Measured memory_bytes: 127232
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5;
ll N,M;
const ll MOD=1e9+7;
ll fac[MAX_N+30],ifac[MAX_N+30];
ll mpw(ll n,ll m){
	ll ret=1;
	while(m){
		if (m&1){
			ret*=n;
			ret%=MOD;
		}
		n*=n;
		n%=MOD;
		m>>=1;
	}
	return ret;
}
ll minv(ll n){
	return mpw(n,MOD-2);
}
ll comb(int n,int m){
	return fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;
}
int main(){
	cin>>N>>M;
	fac[0]=1;
	REP(i,MAX_N+29){
		fac[i+1]=fac[i]*(i+1)%MOD;
	}
	ifac[MAX_N+29]=minv(fac[MAX_N+29]);
	for(int i=MAX_N+28;i>=0;i--){
		ifac[i]=ifac[i+1]*(i+1)%MOD;
	}
	map<int,int> pri;
	for(int i=2;i*i<=M;i++){
		while(M%i==0){
			M/=i;
			pri[i]++;
		}
	}
	if (M!=1){
		pri[M]++;
	}
	ll ans=1;
	for(auto ite:pri){
		ans*=comb(ite.second+N-1,N-1);
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
using namespace literals;

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int64_t N;
  cin >> N;
  int64_t ans = INT64_MAX;
  for (int64_t i = 1; i * i <= N; ++i) {
    if (N % i)continue;
    ans = min(ans,i+N/i-2);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())

path = [[True for i in range(n)] for i in range(n)]

if n%2 == 0:
    for i in range(n//2):
        path[i][i] = False
        path[i][n-i-1] = False
        path[n - i - 1][i] = False
else:
    for i in range(n//2):
        path[i][i] = False
        path[i][n-i-2] = False
        path[n - i - 1][i] = False

ans = []
# print(path)

for i in range(n):
    for j in range(i+1,n):
        if path[i][j]:
            ans.append([i+1,j+1])

print(len(ans))
for a in ans:
    print(str(a[0])+" "+str(a[1]))

Measured memory_bytes: 3848
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <math.h>
#define lli long long int
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

char a[304][304];
lli ans[304][304];

void solve()
{
    lli h, w, k;
    cin>>h>>w>>k;
    for(int i = 0; i < h; i ++) {
        for(int j = 0; j < w; j ++) {
            cin>>a[i][j];
        }
    }
    lli x = 1;
    for(int i = 0; i < h; i ++) {
        for(int j = 0; j < w; j ++) {
            if(a[i][j] == '#') {
                ans[i][j] = x ++;
            }
        }
    }
    lli cur = 1;
    for(int i = 0; i < h; i ++) {
        bool flag = 0;
        for(int j = 0; j < w; j ++) {
            if(a[i][j] == '#') {
                flag = 1;
                cur = ans[i][j];
                break ;
            }
        }
        if(flag == 0)
            cur = 0;
        for(int j = 0; j < w; j ++) {
            if(ans[i][j] < cur)
                ans[i][j] = cur;
            else {
                cur = ans[i][j];
            }
        }
    }
    for(int i = 0; i < w; i ++) {
        for(int j = 1; j < h; j ++) {
            if(ans[j][i] == 0) {
                ans[j][i] = ans[j - 1][i];
            }
        }
    }
    for(int i = w - 1; i >= 0; i --) {
        for(int j = h - 2; j >= 0; j --) {
            if(ans[j][i] == 0) {
                ans[j][i] = ans[j + 1][i];
            }
        }
    }
    for(int i = 0; i < h; i ++) {
        for(int j = 0; j < w; j ++) {
            cout<<ans[i][j]<<' ';
        }
        cout<<endl;
    }
    cout<<'\n';
    return ;
}

/*
3 3 5
#.#
#.#
...
*/
;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


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

long long dp[1010][20202];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    using Block = array<long long, 3>;
    vector<int> idx;
    vector<Block> bv;
    for (int i = 0; i < n; i++) {
        idx.emplace_back(i);
        long long w, s, v; cin >> w >> s >> v;
        bv.push_back({w, s, v});
    }
    auto cmp = [&](int i, int j) {
        return bv[i][0] + bv[i][1] < bv[j][0] + bv[j][1];
    };
    sort(idx.begin(), idx.end(), cmp);
    for (int i = 0; i < n; i++) {
        int c = idx[i];
        for (int j = 0; j <= 20000; j++) {
            if (j <= bv[c][1]) {
                dp[i+1][j+bv[c][0]] = max(dp[i+1][j+bv[c][0]], dp[i][j] + bv[c][2]);
            }
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
    long long ans = 0;
    for (int i = 0; i <= 20000; i++) {
        ans = max(ans, dp[n][i]);
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans = 0;
    REP(i,n-2)if(s.substr(i,3)=="ABC")ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
def main():
    input = sys.stdin.readline
    N=int(input())
    tasks=[tuple(map(int, input().split())) for _ in range(N)]

    from operator import itemgetter
    tasks.sort(key=itemgetter(1))
    t=0
    for task in tasks:
        t += task[0]
        if t > task[1]:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 31964
#include <stdio.h>

int main(){
	int i, a;
	i = 1;
	scanf("%d", &a);
	if(a != 0){
		printf("Case %d: %d\n", i, a);
		i = 2;
	while(a != 0){
		scanf("%d", &a);
		if(a == 0){
			break;
		}
		printf("Case %d: %d\n", i, a);
		i ++;
	}
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(){
  int a, b, c;
  while(scanf("%d%d%d", &a, &b, &c) && (a != -1 || b != -1 || c != -1)){
    if(a < 0 || b < 0) puts("F");
    else if(a + b >= 80) puts("A");
    else if(a + b >= 65) puts("B");
    else if(a + b >= 50 || c >= 50) puts("C");
    else if(a + b >= 30) puts("D");
    else puts("F");
  }
  return 0;
}



Measured memory_bytes: 2048
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		WriteLine(I[0] / (double)I[1]);
	}
}


Measured memory_bytes: 11348
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class Main implements Runnable {

    private void solve() throws IOException {

        StringTokenizer st = new StringTokenizer(reader.readLine());
        writer.println(st.nextToken().charAt(0)+""+st.nextToken().charAt(0)+""+st.nextToken().charAt(0));
    }


    public static void main(String[] args) {

        new Main().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
//             reader = new BufferedReader(new FileReader("input.txt"));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while(tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }

        return tokenizer.nextToken();
    }
}


Measured memory_bytes: 8148
require 'set'
groups = [Set[1, 3, 5, 7, 8, 10, 12], Set[4, 6, 9, 11], Set[2]]
x, y = gets.split(' ').map(&:to_i)
x_index = 99
groups.each.with_index do |group, i|
  if group.include?(x)
    x_index = i
    break
  end
end

puts groups[x_index].include?(y) ? 'Yes' : 'No'
  



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

int main()
{
    long long l, r;
    cin >> l >> r;

    r = min(r, l+4038);
    int ans = 2018;
    for(long long i=l; i<=r-1; i++){
        for(long long j=i+1; j<=r; j++){
            int mod = i*j%2019;
            ans = min(ans, mod);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//Totka hai dosto
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int32_t main()
{
	int n,k;
	cin>>n>>k;
	int freq[200];
	memset(freq,0,sizeof freq);
	int d,x;
	for(int i=0;i<k;i++)
	{
		cin>>d;
		while(d--)
		{
			cin>>x;
			freq[x]++;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(freq[i]==0)
		ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


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

    int X=-1,Y=-1,Z=-1;
    for(int x=0;x<=2000;x++){
        for(int y=0;y<=2000;y++){
            if(9*x+4*y == M/1000 - N  and  x+y <= N){
                X = x; Y = y;
            }
        }
    }

    if(X == -1 and Y == -1) Z = -1;
    else Z = N - X - Y;

    cout << X << " " << Y << " " << Z << endl;
    return 0;
}



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

using namespace std;

int n, k;
int dp[101][4][4];
int data[101];

main(){
  dp[0][0][0] = 1;
  cin >> n >> k;
  for(int i=0;i<k;i++){
    int in;
    cin >> in;
    cin >> data[in];
  }
  for(int i=1;i<=n;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
        if(data[i] != 0){
          if(j == k && j == data[i]){
          }else{
            dp[i][k][data[i]] += dp[i-1][j][k];
            dp[i][k][data[i]] %= 10000;
          }
        }else{
          for(int l=1;l<4;l++){
            if(j == k && j == l){
            }else{
              dp[i][k][l] += dp[i-1][j][k];
              dp[i][k][l] %= 10000;
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      ans += dp[n][i][j];
      ans %= 10000;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

struct unionfind{
    int par[200010]; // 親ノード 必要に応じて要素数を変えよう
    int rank[200010]; // ランク 必要に応じて要素数を変えよう
    unionfind(int n){
        init(n);
    }
    void init(int n){
        for(int i=0;i<=n;i++){
            par[i]=i;
            rank[i]=1;
        }
    }
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            return par[x] = root(par[x]);
        }
    }
    int size(int x){
        return rank[root(x)];
    }
    bool same(int x,int y) {
        return root(x) == root(y);
    }
    void unite(int x,int y) {
        x=root(x);
        y=root(y);
        if(x==y){
            return;
        }
        if(rank[x]<rank[y]){
            swap(x,y);
        }
        rank[x]=rank[x]+rank[y];
        par[y]=x;
    }
};

int main() {
    int n, m; cin>> n >> m;
    unionfind tree(n);
    rep(i, m){
        int a, b;
        a--; b--;
        cin>> a >> b;
        tree.unite(a, b);
    }

    int ans = 0;
    rep(i, n){
        ans = max(ans, tree.size(i));
    }
    cout<< ans << endl;
}


Measured memory_bytes: 5184
#include <stdio.h>

int a[25], n, min;

void solve(int s, int p, int g)
{
	int i;
	
	if (n == s){
		
		if (p < g){
			i = g - p;
		}
		else {
			i = p - g;
		}
		if (min > i){
			min = i;
		}
		
		return;
	}
	
	solve (s + 1, p + a[s], g);
	solve (s + 1, p, g + a[s]);
}
	

int main(void)
{
	int i;
	
	while(1){
		scanf ("%d", &n);
		if (n == 0){
			break;
		}
		min = 20000005;
		for (i = 0; i < n; i++){
			scanf ("%d", &a[i]);
		}
		
		solve (0, 0, 0);
		
		printf("%d\n", min);
	}
	
	return (0);
}

Measured memory_bytes: 600
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(input().split())
    return li

# --------------------------------------------

dp = None

def main():
    N = int(input())
    A = int(input())

    print(N*N - A)

main()


Measured memory_bytes: 5184
import numpy as np
num = [int(i) for i in input().split()]
num = np.array(num)

is_1 = len(num[num == 1])
is_9 = len(num[num == 9])
is_7 = len(num[num == 7])
is_4 = len(num[num == 4])

if is_1 > 0 and is_9 > 0 and is_7 > 0 and is_4 > 0:
  print('YES')
else:
  print('NO')

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

#define N_MAX   (100000)

typedef long long ll;

int result;
ll N;

int serch753(ll i, bool flg_3, bool flg_5, bool flg_7) {
    if (i > N) return result;
    if (flg_3 && flg_5 && flg_7) result++;
    serch753(i * 10 + 3, true, flg_5, flg_7);
    serch753(i * 10 + 5, flg_3, true, flg_7);
    serch753(i * 10 + 7, flg_3, flg_5, true);
}

int main()
{
    // 整数の入力

    cin >> N ;

    serch753(0, false, false, false);
    cout << result << endl;
    return 0;

}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	map<int, bool> S, H, C, D;
	for (int i = 0; i < n; i++){
		char c;
		int x;
		cin >> c >> x;
		if (c == 'S') S[x] = true;
		else if (c == 'H') H[x] = true;
		else if (c == 'C') C[x] = true;
		else D[x] = true;
	}

	for (int i = 1; i < 14; i++){
		if (!(S[i])) cout << 'S' << " " << i << endl;
	}
	for (int i = 1; i < 14; i++){
		if (!(H[i])) cout << 'H' << " " << i << endl;
	}
	for (int i = 1; i < 14; i++){
		if (!(C[i])) cout << 'C' << " " << i << endl;
	}
	for (int i = 1; i < 14; i++){
		if (!(D[i])) cout << 'D' << " " << i << endl;
	}
}



Measured memory_bytes: 3132
import java.util.*;

 
class Main {
 
    private static Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
        String s = sc.next();
        String s2 = sc.next();
        //int x =Integer.parseInt(s);
        //int y =Integer.parseInt(s);
        long x =Long.parseLong(s);
        long y = Long.parseLong(s2);
        long push=0;
        if(x==y){
            System.out.println(push);
            return;
        }
        if(x>=0){
            if(x<y){
                push=y-x;
            }else{
                if(y>0){
                    push=x-y+2;
                }else{
                    if(Math.abs(y)>x){
                        push=Math.abs(y)-x+1;
                    }else{
                        push=x-Math.abs(y)+1;
                    }
                }
            }   
        }else{
            if(x<y){
                if(y>0){
                    if(Math.abs(x)>y){
                        push=Math.abs(x)-y+1;
                    }else{
                        push=y-Math.abs(x)+1;
                    }
                }else{
                    push=y-x;
                }
            }else{
                push=x-y+2;
            }

        }
        System.out.println(push);
        //String s = String.valueOf(i);
        //int i = Integer.parseInt(s);
        //System.out.println((s + s).contains(s2) ? "Yes" : "No");

    }
}

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

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int q = Integer.parseInt(str[0]);
		SortedMap<String, Integer> mpa = new TreeMap<String, Integer>();
		for(int i = 0; i < q; i++){
			str = br.readLine().split(" ");
			int op = Integer.parseInt(str[0]);
			if(op == 0){
				String key = str[1];
				int x = Integer.parseInt(str[2]);
				mpa.put(key, x);
			}else if(op == 1){
				String key = str[1];
				if(mpa.containsKey(key)) System.out.println(mpa.get(key));
				else System.out.println(0);
			}else if(op == 2){
				String key = str[1];
				if(mpa.containsKey(key)) mpa.remove(key);
			}else{
				String L = str[1];
				String R = str[2] + "#";
				SortedMap<String, Integer> mpb = mpa.subMap(L, R);
				for(String s : mpb.keySet()){
					System.out.println(s + " " + mpa.get(s));
				}
			}
		}
	}
}



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

int main() {

  int N;
  cin >> N;

  vector<int> L(N);

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

  sort(L.begin(), L.end());

  int cnt = 0;
  int tmpcnt = 0;

  for(int i = 0; i < L.size(); i++){
    if(i >= 1){
      if(L[i] == L[i - 1]){
        cnt += tmpcnt;
        continue;
      }
    }
    tmpcnt = 0;
    for(int j = i + 1; j < L.size(); j++){
      if(L[i] == L[j]){
        continue;
      }
      for(int k = j + 1; k < L.size(); k++){
        if(L[k] >= L[i] + L[j]){
          break;
        }else if(L[j] != L[k]){
          tmpcnt++;
        }
      }
    }
    cnt += tmpcnt;
  }
  cout << cnt << endl;

  return 0;
}


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

using namespace std;

typedef pair<int, int> P;

vector<int> Gw[200000];
vector<int> Gr[200000];

P city[200000];

bool used_w[200000] = {false};
bool used_r[200000] = {false};

void dfs_w(int n, int s){
    used_w[n] = true;
    city[n].first = s;
    for(int i = 0; i < Gw[n].size(); i++){
        if(!used_w[Gw[n][i]]) dfs_w(Gw[n][i], s);
    }
}

void dfs_r(int n, int s){
    used_r[n] = true;
    city[n].second = s;
    for(int i = 0; i < Gr[n].size(); i++){
        if(!used_r[Gr[n][i]]) dfs_r(Gr[n][i], s);
    }
}


int main(){
    int N, K, L;
    cin >> N >> K >> L;
    map<P, int> m;
    for(int i = 0; i < K; i++){
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        Gw[p].push_back(q);
        Gw[q].push_back(p);
    }
    for(int i = 0; i < L; i++){
        int r, s;
        cin >> r >> s;
        r--;
        s--;
        Gr[r].push_back(s);
        Gr[s].push_back(r);
    }
    for(int i = 0; i < N; i++){
        if(!used_r[i]){
            dfs_r(i, i);
        }
        if(!used_w[i]){
            dfs_w(i, i);
        }

        if(m.count(city[i]) == 0){
            m[city[i]] = 1;
        }else{
            m[city[i]]++;
        }
    }
    for(int i = 0; i < N; i++){
        cout << m[city[i]];
        if(i < N-1) cout << ' ';
        else cout << endl;
    }
}

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

void swap(int &a, int &b){
	int temp = a;
	a = b;
	b = temp;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c << "\n";
	return 0;
}

Measured memory_bytes: 256
num=int(input())

AC=0
WA=0
TLE=0
RE=0

for i in range(num):
    x=input()
    if x=="AC":
        AC+=1
    elif x=="WA":
        WA+=1
    elif x=="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: 9200
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BSubstring {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        string s, t;
        cin >> s >> t;
        int res = INF;
        REP(i, s.size()) {
            if (i + t.size() - 1 >= s.size()) break;
            int tmp = 0;
            REP(j, t.size()) {
                if (s[i + j] != t[j]) tmp++;
            }
            res = min(res, tmp);
        }

        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BSubstring solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3616
//
//  A - AtCoDeerくんとペンキ.cpp
//  Practice
//
//  Created by Hajime Sakamoto on 2020/05/29.
//  Copyright © 2020 Hajime Sakamoto. All rights reserved.
//

#include <stdio.h>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <iterator>

using namespace std;


int main(){
    
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if (a!=b & a!=c & b!=c){
        cout << 3;
    }
    else if (a==b & a==c){
        cout << 1;
    }
    else {
        cout << 2;
    }
    
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    while(a >= b) {
        b *= 2;
        ans++;
    }
    while(b >= c) {
        c *= 2;
        ans++;
    }
    if(ans <= k) cout << "Yes" << endl;
    else cout << "No" << endl;
   
    return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;
import java.util.Arrays;
class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		final int cnt = scan.nextInt();
		
		for(int i = 0; i < cnt; i++) {
			Integer[] tri = new Integer[3];
			
			tri[0] = scan.nextInt();
			tri[1] = scan.nextInt();
			tri[2] = scan.nextInt();
			
			Arrays.sort(tri);
			
			tri[0] *= tri[0];
			tri[1] *= tri[1];
			tri[2] *= tri[2];
			
			if((tri[0] + tri[1]) == tri[2]) {
				System.out.println("YES");
			}
			
			else {
				System.out.println("NO");
			}
		}
	}
	
}

Measured memory_bytes: 23364
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>

using namespace std;

int main() {
	int n = 0, m = 0, k = 0,d=0;
	cin >> n >> m >> k>>d;
	int a = abs(n - m);
	int b = abs(m - k);
	int c = abs(n - k);
	if (c <= d) {
		cout << "Yes" << endl;
	}
	else if (a <= d && b<=d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	system("PAUSE");
}

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

int dp[15][9000],ara[14][14],tra[14],cost[14],n,m,x,a,b,mx=9999999;

bool ck(int x,int ps)
{
    return (bool)(x&(1<<ps));
}

int on(int x,int ps)
{
    return x|(1<<ps);
}

int solve(int idx,int mask)
{

    if(idx==n)
    {
          int flg=0;

          for(int i=0;i<n;i++)
          {
              if(i==0){ for(int lp=0;lp<m;lp++)tra[lp]=0; }


              if(ck(mask,i)==1)
              {
                  for(int lp=0;lp<m;lp++)
                  {
                      if(tra[lp]<x && tra[lp]+ara[i][lp]>=x)flg++;

                      tra[lp]=tra[lp]+ara[i][lp];

                  }

              }


          }

          if(flg==m)return 0;
          else
          {
              return mx;
          }



    }
    else if(dp[idx][mask]!=-1)
    {
        return dp[idx][mask];
    }
    else
    {

        long long s=on(mask,idx);
        long long p=cost[idx]+solve(idx+1,s);
        long long q=solve(idx+1,mask);

        dp[idx][mask]=min(p,q); return dp[idx][mask];

    }



}


int main()
{


    int i,j,k,ans;
    scanf("%d %d %d",&n,&m,&x);

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

        for(j=0;j<m;j++)
        {
            scanf("%d",&ara[i][j]);
        }

    }

    memset(dp,-1,sizeof dp);

    ans=solve(0,0);

    if(ans<mx)printf("%d\n",ans);
    else
        printf("-1\n");


    return 0;
}





Measured memory_bytes: 4356
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; std::cin >> N;
  std::vector<int> a(N+1), b(N+1);
  for (int i = 1; i <= N; ++i) {
    std::cin >> a[i];
  }

  int cnt = 0;
  for (int i = N; i > 0; --i) {
    int x = 0;
    for (int j = 2; i*j <= N; ++j) {
      x += b[i*j];
    }
    if (x % 2 != a[i]) {
      b[i] = 1;
    } else {
      b[i] = 0;
    }

    if (b[i]>0) ++cnt;
  }

  if (cnt == 0) {
    std::cout << 0 << std::endl;
    return 0;
  }

  std::cout << cnt << std::endl;
  for (int i = 1; i <= N; ++i) {
    if (b[i]>0) std::cout << i << " ";
  }
  std::cout << std::endl;
}


Measured memory_bytes: 2432
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextFloatVec() []float64 {
  L := strings.Split(NextLine(), " ")
  N := make([]float64, len(L))
  for i := range N {
    N[i], _ = strconv.ParseFloat(L[i], 64)
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func MaxFloat(x, y float64) float64 {
  if x < y { return y }
  return x
}
func Dist0(A *[]float64) float64 {
  x, y := (*A)[0], (*A)[1]
  return math.Sqrt(x * x + y * y)
}
func InnerProduct(A, B *[]float64) float64 {
  return (*A)[0] * (*B)[0] + (*A)[1] * (*B)[1]
}
func Angle(A, B *[]float64) float64 {
  acos := math.Acos(InnerProduct(A, B) / Dist0(A) / Dist0(B))
  theta := acos / math.Pi * 180.0
  _A := []float64{-(*A)[1], (*A)[0]}
  if InnerProduct(&_A, B) < 0 { theta = 360 - theta }
  return theta
}

type Engines [][]float64
func (E Engines) Len() int { return len(E) }
func (E Engines) Less(i, j int) bool { return E[i][2] < E[j][2] }
func (E Engines) Swap(i, j int) { E[i], E[j] = E[j], E[i] }

func main() {
  N := NextInt()
  E := make([][]float64, 0)
  X := []float64{1.0, 0.0}
  C := 0
  for i := 0; i < N; i++ {
    XY := NextFloatVec()
    if XY[0] != 0.0 || XY[1] != 0.0 {
      angle := Angle(&X, &XY)
      XY = append(XY, angle)
      E = append(E, XY)
      E = append(E, []float64{0.0, 0.0, angle - 180.0})
      E = append(E, []float64{0.0, 0.0, angle + 180.0})
      E = append(E, []float64{XY[0], XY[1], angle + 360.0})
      C++
    }
  }
  sort.Sort(Engines(E))
  ans := 0.0
  t := 0
  D := []float64{0.0, 0.0}
  cnt := 0
  for _, e := range E {
    for E[t][2] - e[2] < 180.0 {
      D[0] += E[t][0]
      D[1] += E[t][1]
      t++
    }
    ans = MaxFloat(Dist0(&D), ans)
    D[0] -= e[0]
    D[1] -= e[1]
    if e[0] != 0.0 || e[1] != 0.0 { cnt++ }
    if cnt == C { break }
  }
  Write(ans)
  Output()
}

Measured memory_bytes: 768
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  string s;
  cin >> s;
  string t = "CODEFESTIVAL2016";
  int ans = 0;
  rep(i,16) ans += s[i]!=t[i];
  cout<<ans<<endl;
  return 0;
}































Measured memory_bytes: 256
// g++ hello.cpp -o hello & hello
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)  

#define MP make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void test();

int main()
{
//freopen("input.in","r",stdin);freopen("output.in","w",stdout);
int t=1;
//   cin>>t;
for(int i=1;i<=t;i++)
{    
//	cout<<"Case #"<<i<<": ";
	test();
cout<<endl;
}
return 0;
}
void test() 
{
int l,r,d;
cin>>l>>r>>d;
int ans=0;
for(int i=l;i<=r;i++)
if(i%d==0)ans++;
cout<<ans;
}

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

using namespace std;

int main()
{
	int n, k, x, y, s = 0;
	scanf("%d %d %d %d", &n, &k, &x, &y);
	
	if(n > k)
		s = k*x+(n-k)*y;
	else
		s = n*x;
	
	printf("%d\n", s);
	
	return 0;
}

Measured memory_bytes: 256
// see https://github.com/LumaKernel/vimfiles/tree/master/snippets/cp-cpp/temp.snip
/// --- .lumrc Template {{{ ///
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = tuple<ll, ll>;
using P3 = tuple<ll, ll, ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VP = vector<P>;
using VS = vector<string>;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define FORI(i,a,b) for(int i=int(a);i<=int(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPI(i,n) FORI(i,0,n)
#define RFOR(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define RFORI(i,a,b) for(int i=int(b);i>=int(a);--i)
#define RREP(i,n) RFOR(i,0,n)
#define RREPI(i,n) RFORI(i,0,n)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique(ALL(a)),(a).end())
#define PB push_back
#define EACH(i,c) REP(i,(c).size())
#define REACH(i,c) RREP(i,(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))

#define BR cout<<"\n";

#ifdef DEBUG
#define dump(...) cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n";
#else
#define dump(...)
#endif

#define YES(x) cout<<((x)?"YES":"NO")<<"\n";
#define Yes(x) cout<<((x)?"Yes":"No")<<"\n";
#define yes(x) cout<<((x)?"yes":"no")<<"\n";

inline int omajinai_int_in(){omajinai;int n;cin>>n;return n;}
inline ll omajinai_ll_in(){omajinai;ll n;cin>>n;return n;}
inline string omajinai_string_in(){omajinai;string n;cin>>n;return n;}
inline int int_in(){int n;cin>>n;return n;}
inline ll ll_in(){ll n;cin>>n;return n;}
inline string string_in(){string n;cin>>n;return n;}
#define oini omajinai_int_in()
#define oinl omajinai_ll_in()
#define oins omajinai_string_in()
#define ini int_in()
#define inl ll_in()
#define ins string_in()

#define isInside(y,x) (0<=(y)&&(y)<h&&0<=(x)&&(x)<w)

#define fi(x) (get<0>(x))
#define se(x) (get<1>(x))
#define th(x) (get<2>(x))
#define fo(x) (get<3>(x))
#define fif(x) (get<4>(x))

template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '{'; EACH(i, v) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "}";  return o; }

template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }

template <typename T> inline void smax(T &a, T b) { a = a > b ? a : b; }
template <typename T> inline void smin(T &a, T b) { a = a < b ? a : b; }

constexpr double PI = acos(-1);

/// }}}--- ///

constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr int MOD = 1e9+7;

int a[2][100];
ll dp[2][100];
int main() {
  int n=ini;
  REP(y,2)REP(i, n) a[y][i]=ini;
  dp[0][0] = a[0][0];
  REP(i, n) {
    dp[0][i] = dp[0][i-1] + a[0][i];
    dp[1][i] = max(dp[1][i-1], dp[0][i]) + a[1][i];
  }
  cout << dp[1][n-1] << endl;
}

//


Measured memory_bytes: 256
def resolve():
    MAX_COST = 10**9
    num_steps = int(input())

    steps = list(map(int,input().split()))

    min_cost = [MAX_COST for i in range(num_steps)]
    min_cost[0] = 0
    min_cost[1] = abs(steps[1] - steps[0])
    
    for si in range(2,num_steps):
        min_cost[si] = min(min_cost[si - 1] + abs(steps[si-1] - steps[si]),min_cost[si - 2] + abs(steps[si-2] - steps[si]))

    print(min_cost[-1])
resolve()

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

int dp[32768];
int gg[32768];

int root = 0;
int p[100001];
int x[100001];


vector< pair<int, int> > g[100001];
int cnt[16];

void dfs(int me){
    for(auto &nxt: g[me]){
        if(nxt.first == p[me]) continue;
        p[nxt.first] = me;
        x[nxt.first] = nxt.second;
        dfs(nxt.first);
        x[me] ^= nxt.second;
    }
    if(me > 0) cnt[x[me]]++;
}

int rec(int now){
    if(~dp[now]) return dp[now];
    int bst = 0;
    for(int i=1;i<=15;i++){
        if(now & (1 << (i-1))){
            for(int j=1;j<=15;j++){
                if(i == j) continue;
                int nxt = now - (1 << (i-1));
                nxt ^= (1 << (j-1));
                nxt ^= (1 << ((i^j)-1));
                if(gg[nxt] < gg[now]){
                    if(gg[now] - gg[nxt] == 3){
                        bst = max(bst, 1 + rec(nxt));
                    }else{
                        bst = max(bst, rec(nxt));
                    }
                }
            }
        }
    }
    dp[now] = bst;
    //printf("%d %d\n", now, bst);
    return bst;
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int aa, bb, cc;
        scanf("%d%d%d",&aa,&bb,&cc);
        g[aa].push_back({bb, cc});
        g[bb].push_back({aa, cc});
    }
    p[0] = 0;
    dfs(0);
    int ans = 0;
    for(int i=0;i<32768;i++){
        dp[i] = -1;
        for(int j=0;j<15;j++){
            if(i &(1 << j)) gg[i]++;
        }
    }
    for(int i=1;i<16;i++){
        ans += cnt[i] / 2;
        root += (1 << (i-1)) * (cnt[i] % 2);
    }
    //printf("%d\n", root);
    printf("%d\n", ans + gg[root] - rec(root));
}


Measured memory_bytes: 11264
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string s;
  int k;
  cin>>k>>s;
  if(s.size()<=k)cout<<s<<endl;
  else{
    int j=s.size()-k;
    for(int i=0;i<j;i++){
      s.pop_back();
    }
    cout<<s<<"..."<<endl;
  }
  return 0;
}

Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

a,b=mii()

p=a+b

if p>=24:
    p-=24
print(p)

Measured memory_bytes: 5144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int dp[105][4][2];

int main() {
  string s; int k; cin >> s >>k;
  int n = s.length();
  // dp[i][j][eq] := seen i digits; j zero's eq=1: eq so far
  dp[0][0][1] = 1;
  rep(i,n) {
    rep(j,k+1) {
      rep(l, 2) {
        int x = s[i] - '0';
        rep(d, 10) {
          int ni = i+1, nj=j, eq=l;
          if (d!=0) nj++;
          if (nj > k) continue;
          if (l==1) {
            if (x < d) continue;
            if (x > d) eq = 0;
          }
          dp[ni][nj][eq] += dp[i][j][l];
        }
      }
    }
  } 
  cout << dp[n][k][0] + dp[n][k][1] << endl;
  return 0;
}

Measured memory_bytes: 256