akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

    ll sum = 0;
    for(ll i=0;i<N+1;i++){
        if(i%3==0) continue;
        else if(i%5==0) continue;
        else sum += i;
    }

    cout << sum << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 3636
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=200005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
char str[max_n];
void reads(string& s){scanf(" %s",str);s=str;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n;
ll a[max_n],b[max_n];
map<P,int> mp;
P get(P p){
    if(p.fi<0)p.fi*=-1,p.se*=-1;
    else if(p.fi==0){
        if(p.se<0)p.se*=-1;
    }
    return p;
}
int main(){
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++)scanf("%lld%lld",a+i,b+i);
    for(int i=1;i<=n;i++){
        if(a[i]==0&&b[i]==0)ans++;
        else{
            ll d=__gcd(a[i],b[i]);
            a[i]/=d,b[i]/=d;
            //a[i]=abs(a[i]),b[i]=abs(b[i]);
            if(a[i]<0)a[i]=-a[i],b[i]=-b[i];
            else if(a[i]==0){
                if(b[i]<0)b[i]=-b[i];
            }
            mp[P(a[i],b[i])]++;
        }
    }
    int res=1;
    for(auto& x:mp){
        P p=x.first;
        swap(p.fi,p.se);
        p.fi*=-1;
        p=get(p);
        int c1=Pow(2,mp[p]);
        int c2=Pow(2,x.second);
        int c=Add(c1,c2);c=Sub(c,1);
        res=Mul(res,c);
        //cout<<x.fi.fi<<' '<<x.fi.se<<' '<<c<<endl;
        mp[p]=x.second=0;
    }
    res=Sub(res,1);
    ans=Add(ans,res);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 31856
#include<iostream>

using namespace std;
int main(){
	int a, b, c;
	string S, T;
	a = 0;

	cin >> S >> T;


	if (S[0] == T[0]) {
		a++;
	}
	if (S[1] == T[1]) {
		a++;
	}
	if (S[2] == T[2]) {
		a++;
	}
	cout << a << endl;


}

Measured memory_bytes: 256
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


while 1:
    h, w = LI()
    if w == h == 0:
        break
    for i in range(h):
        for q in range(w):
            print('#', end='')
        print('', end='\n')
    print('', end='\n')



Measured memory_bytes: 7112
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int N,M,i,j,k,l;
string A[50],B[50];
bool flag;
inline void solve(){
  IN2(N,M);
  REP(i,N)IN(A[i]);
  REP(i,M)IN(B[i]);
  REP(i,N){
    REP(j,N){
      flag=true;
      REP(k,M){
        REP(l,M){
          if(A[i+k][j+l]!=B[k][l]){
            flag=false;
            break;
          }
        }
        if(!flag)break;
      }
      if(flag){
        OUT("Yes");
        return;
      }
    }
  }
  OUT("No");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
n, k = map(int, input().split())
d = []
a = []
for i in range(k):
    d.append(int(input()))
    a.append(list(map(int, input().split())))

s = 0
for i in range(1, n + 1):
    tf = False
    for j in range(k):
        if i in a[j]:
            tf = True
            break
    if tf == False:
        s += 1

print(s)

Measured memory_bytes: 78880
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int w, a, b;
    cin >> w >> a >> b;
    int ans = 0;
    if (b >= a+w) ans = b-a-w;
    else if (b+w <= a) ans = a-b-w;
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

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

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	as := scanInts(n)
	as = append(as,0)

	ans := 0

	for i := 0; i < n; i++ {
		ans += as[i]/2
		if as[i]%2==1&&as[i+1]>0 {
			ans++
			as[i+1]--
		}
	}

	fmt.Println(ans)

}


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            Console.WriteLine((s[2] == s[3] && s[4] == s[5]) ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13140
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        ArrayList<Integer> H = new ArrayList<Integer>(N);

        boolean ans = true;
        for (int i=0;i<N;i++){
            H.add(i,scanner.nextInt());
        }

        for (int i=N-1;i>0;i--){
            if (H.get(i)<H.get(i-1)) {
                if (H.get(i-1)-H.get(i)>=2) {
                    ans = false;
                    break;
                }
                H.set(i-1, H.get(i - 1)-1);
            }
        }

        if (ans) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 62348
import java.lang.Math

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val P = readInputLine().split(" ").map { it.toInt() }.toIntArray()
    val Q = readInputLine().split(" ").map { it.toInt() }.toIntArray()

    val perm = IntArray(N) { it + 1 }

    var cnt = 1
    var a = 0
    var b = 0

    do {
        var ok = true
        for (i in 0 until N) {
            if (P[i] != perm[i]) {
                ok = false
                break
            }
        }
        if (ok) a = cnt
        ok = true
        for (i in 0 until N) {
            if (Q[i] != perm[i]) {
                ok = false
                break
            }
        }
        if (ok) b = cnt
        cnt++
    } while (nextPermutation(perm))

    println(Math.abs(a - b))
}

fun readInputLine(): String {
    return readLine()!!
}

fun nextPermutation(arr: IntArray): Boolean {
    var i = arr.size - 1
    while (i > 0 && arr[i - 1] >= arr[i]) {
        i--
    }

    if (i <= 0) {
        return false
    }

    var j = arr.size - 1
    while (arr[j] <= arr[i - 1]) {
        j--
    }

    var temp = arr[i - 1];
    arr[i - 1] = arr[j];
    arr[j] = temp;

    j = arr.size - 1;
    while (i < j) {
        temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
        i++;
        j--;
    }

    return true;
}


Measured memory_bytes: 38924
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, x, t;
  cin >> n >> x >> t;
  cout << (n + x - 1) / x * t << endl;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cstring>
#include<algorithm>
#define For(i, a, b) for(register int i = a; i <= b; ++i)
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
char s[maxn];
int dp[maxn], sum[maxn], n, flag, trans[3] = {0, -1, -1};

void Add(int & a, const int &b) {
	a += b;if(a >= mod) a -= mod;
}

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1), dp[0] = 1;
	For(i, 1, n) sum[i] = (sum[i - 1] + (s[i] - 'a' + 1)) % 3;
	For(i, 2, n)
		if(s[i] == s[i - 1]) 
			{flag = 1; break;}
	if(!flag) return printf("1"), 0;
	int from; dp[0] = 1;
	For(i, 1, n) {
		if(!sum[i] && i < n) dp[i] = 1;
		Add(dp[i], dp[i - 1]);
		from = trans[(sum[i] + (s[i] == 'a' ? 1 : 2)) % 3];
		if(~from) Add(dp[i], dp[from]);
		trans[sum[i]] = i;
	}
	printf("%d", dp[n]);
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))

approved = True
for a_i in a:
    if 0 == a_i % 2:
        if 0 != a_i % 3 and 0 != a_i % 5:
            approved = False
            break
print("APPROVED" if approved else "DENIED")


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

int main(){
        int a[50000];
        int i,j,min,sa,n;
        while(1) {
                cin>>n;

                if(n==0) {
                        break;
                }

                for(i=0; i<n; i++) {
                        cin>>a[i];
                }

                min=1000000;

                for(i=0; i<n; i++) {
                        for(j=0; j<n; j++) {
                                if(i!=j) {
                                        if(a[i]>a[j]) {
                                                sa=a[i]-a[j];
                                        }else{
                                                sa=a[j]-a[i];
                                        }

                                        if(min>sa) {
                                                min=sa;
                                        }
                                }
                        }
                }

                cout<<min<<endl;
        }

}



Measured memory_bytes: 3096
s=list(input())
n=len(s)
b=[0]*n
sec=-1
sec_=0
r=0
l=0
ri=0
li=0
child=0

for i in range(n):
    if i!=n-1:
      if s[i]=="R" and s[i+1]=="L":
        ri=i
        li=i+1
      if s[i]=="L" and s[i+1]=="R":
        sec_=sec
        sec=i
        child=sec-sec_
        if (ri-sec_)%2==1:
          r=(child+1)//2
          l=child//2
        else:
          r=child//2
          l=(child+1)//2
        b[ri]=r
        b[li]=l
    else:
      sec_=sec
      sec=i
      child=sec-sec_
      if (ri-sec_)%2==1:
        r=(child+1)//2
        l=child//2
      else:
        r=child//2
        l=(child+1)//2
      b[ri]=r
      b[li]=l
      
print(*b)

Measured memory_bytes: 7088
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
	int w, h;
	while (scanf("%d%d", &w, &h), w | h)
	{
		int x, y, dir;
		x = y = 1;
		dir = 0;
		while (true)
		{
			char buf[16];
			scanf("%s", buf);
			char c = *buf;
			if (c == 'S')
				break;
			
			if (c == 'F' || c == 'B')
			{
				int k;
				scanf("%d", &k);
				int d = (dir + (c == 'B' ? 2 : 0)) % 4;
				x = max(1, min(w, x + k * dx[d]));
				y = max(1, min(h, y + k * dy[d]));
			}
			else if (c == 'L')
				dir = (dir - 1 + 4) % 4;
			else if (c == 'R')
				dir = (dir + 1 + 4) % 4;
		}
		printf("%d %d\n", x, y);
	}
}

Measured memory_bytes: 0
import sys
n,y=map(int,input().split())

for ykc in range(0,y+1,10000):
  for ntb in range(0,y-ykc+1,5000):
    ntm=(y-ykc-ntb)
    nntm=ntm//1000
    nntb=ntb//5000
    nykc=ykc//10000
    if ntm%1000==0 and (nntm+nntb+nykc==n):
      print(nykc, nntb, nntm)
      sys.exit()
print('-1 -1 -1')


Measured memory_bytes: 9184
using System;
using System.Linq;

namespace _170_b
{
    internal class CraneAndTurtle
    {
        private static void Main(string[] args)
        {
            var xy = Console.ReadLine()?.Split(" ").Select(int.Parse).ToArray();
            if (xy == null) return;
            var x = xy[0];
            var y = xy[1];

            // 奇数
            if (y % 2 != 0)
            {
                Console.WriteLine("No");
                return;
            }

            // 足が足りない
            if (x * 4 < y)
            {
                Console.WriteLine("No");
                return;
            }

            // 足が余る
            if (x * 2 > y)
            {
                Console.WriteLine("No");
                return;
            }

            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 28320
n, x = [int(i) for i in input().split()]

memo = dict()
size = [0] * (n+1)
size[0] = 1

for i in range(1, n+1):
    size[i] = size[i-1] * 2 + 3

def dfs(i):
    global x
    res = 0
    if x <= 0:
        return 0
    if size[i] <= x and i in memo:
        x -= size[i]
        return memo[i]
    if i == 0:
        x -= 1
        return 1
    x -= 1 #B
    res += dfs(i-1)
    x -= 1 #P
    if x < 0:
        return res
    res += 1 #P
    res += dfs(i-1)
    x -= 1 #B
    memo[i] = res
    return res


print(dfs(n))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>

void print(std::string s, int shuffle_num);

int main(void) {
    std::string s;
    int m;
    std::cin >> s >> m;
    while(s != "-") {
        int shuffle_num = 0;
        for (int i = 0; i < m; i++) {
            int temp;
            std::cin >> temp;
            shuffle_num += temp;
        }
        print(s, shuffle_num);
        std::cin >> s >> m;
    }
    return EXIT_SUCCESS;
}

void print(std::string s, int shuffle_num) {
    int start = shuffle_num % s.size();
    std::string s_cp = s.substr(start, s.size() - start) + s.substr(0, start);         
    std::cout << s_cp << std::endl;
    return;
}

Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;
using pll = pair<ll, ll>;

int main(){
	int n;
	cin >> n;
	vector<ll> a(3 * n);
	for(int i = 0; i < 3 * n; ++i){
		cin >> a[i];
	}

	vector<ll> sum1(n * 2 + 1, 0);
	priority_queue<ll, vector<ll>, greater<ll>> que1;
	for(int i = 0; i < n; ++i){
		sum1[i + 1] = sum1[i] + a[i];
		que1.push(a[i]);
	}
	for(int i = n; i < n * 2; ++i){
		if(que1.top() < a[i]){
			sum1[i + 1] = sum1[i] - que1.top() + a[i];
			que1.pop();
			que1.push(a[i]);
		}
		else sum1[i + 1] = sum1[i];
	}

	vector<ll> sum2(n * 2 + 1, 0);
	priority_queue<ll> que2;
	for(int i = 0; i < n; ++i){
		int j = n * 3 - 1 - i;
		sum2[i + 1] = sum2[i] + a[j];
		que2.push(a[j]);
	}
	for(int i = n; i < n * 2; ++i){
		int j = n * 3 - 1 - i;
		if(que2.top() > a[j]){
			sum2[i + 1] = sum2[i] - que2.top() + a[j];
			que2.pop();
			que2.push(a[j]);
		}
		else sum2[i + 1] = sum2[i];
	}

	ll ans = -LINF;
	for(int i = n; i <= n * 2; ++i){
		ans = max(ans, sum1[i] - sum2[n * 3 - i]);
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 8052
#include <stdio.h>

int main(){
    int i, j, k;
    int n, x;
    int count;

    while(1){
        scanf("%d %d ", &n, &x);
        if(n==0&&x==0)break;
        count=0;
        for(i=1;3*i+3<=x;i++){
            for(j=i+1;i+2*j+1<=x;j++){
                for(k=n;k>j;k--){
                    if(x==i+j+k){
                        count++;
                        break;
                    }else if(x>=i+j+k){
                        break;
                    }
                }
            }
        }
        printf("%d\n", count);
    }
    return 0;
}

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

#define  quick  ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define s(x) sort(x.begin(),x.end())
#define sr(x) sort(x.begin(),x.end(),greater<ll>())
#define v1 vector<ll>
#define p1 pair<ll,ll>
#define m1 map<ll,ll>
#define ff first
#define ss second
#define ee '\n';
#define pb push_back
#define all(v) v.begin(),v.end()
#define f(i,x,y) for(i=x;i<y;i++)
#define mp make_pair
#define yes cout<<"YES"<<endl
#define no  cout<<"NO"<<endl

const int N = 1e5 + 5;

bool sortsec(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
       return (a.first > b.first);
}


void solve()
{
        double d,t,s;
        cin>>d>>t>>s;
        double x = d/s;
        if(x<=t)
        {
                cout<<"Yes"<<ee;
        }
        else
        {
               cout<<"No"<<ee;
        }
}

 int32_t main()
 {
    quick;
    ll t=1;
    //cin>>t;
    while(t--)
    {
       solve();
    }
    return 0;
 }

Measured memory_bytes: 3736
l,a[25],i,n,S;main(f){for(;~scanf(S="%d\n",&l);){for(i=l;i--;)scanf(S,a+l+~i);for(n=l?32:0;n;f=!f)n-=f?~-n%5:a[i=-~i%l],printf(S,n*=n>0);}}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
	int a[4];
	int b[4];
	int i, j;
	int hit, blow;
	
	while (scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]) != EOF){
		scanf("%d %d %d %d", &b[0], &b[1], &b[2], &b[3]);
		
		hit = blow = 0;
		for (i = 0; i < 4; i++){
			for (j = 0; j < 4; j++){
				if (a[i] == b[j]){
					if (i == j) hit++;
					else blow++;
				}
			}
		}
		
		printf("%d %d\n", hit, blow);
	}
	
	return (0);
}

Measured memory_bytes: 596
N, X = map(int, input().split())

nums = [1] * (N + 1)
for i in range(1, N + 1):
    nums[i] = nums[i - 1] * 2 + 3

memo = {}


def calc(N, X):
    if (N, X) in memo:
        return memo[N, X]

    if not 1 <= X <= nums[N]:
        return 0
    if N == 0:
        return 1
    if X == 1:
        return 0
    elif X <= nums[N - 1] + 1:
        memo[N, X] = calc(N - 1, X - 1)
    elif X <= nums[N - 1] + 2:
        memo[N, X] = calc(N - 1, nums[N - 1]) + 1
    elif X < 2 * nums[N - 1] + 2:
        memo[N, X] = calc(N - 1, nums[N - 1]) + 1 + calc(N - 1, X - nums[N - 1] - 2)
    else:
        memo[N, X] = 2 * calc(N - 1, nums[N - 1]) + 1
    return memo[N, X]


print(calc(N, X))

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

using namespace std;

#define MAX 514
#define INF (1e9)

struct Edge{
    int to,cost,c;
    Edge(int to,int cost,int c) :
        to(to),cost(cost),c(c) {}
};

int main(){
    int M,D,N,K;
    int d[MAX][1<<6];    
    while(cin >> M >> N >> K >> D, M){
        vector<Edge> G[MAX];
        vector<int> cake(M);
        for(int i = 0 ; i < M ; i++){
            cin >> cake[i];
        }
        int idx = 0,c;
        string a,b;
        map<string,int> mp;
        for(int i = 0 ; i < D ; i++){
            cin >> a >> b >> c;
            if(!mp.count(a)) mp[a] = idx++;
            if(!mp.count(b)) mp[b] = idx++;
            if(a[0] == 'C'){
                G[mp[b]].push_back(Edge(mp[a],c,a[1]-'1'));             
            }else{
                G[mp[b]].push_back(Edge(mp[a],c,-1));           
            }
            if(b[0] == 'C'){
                G[mp[a]].push_back(Edge(mp[b],c,b[1]-'1'));
            }else{
                G[mp[a]].push_back(Edge(mp[b],c,-1));           
            }

        }
        int s = mp["H"],t = mp["D"];
        for(int i = 0 ; i < MAX ; i++){
            for(int j = 0 ; j < (1<<6) ; j++){
                d[i][j] = INF;
            }
        }
        d[s][0] = 0;
        bool update = 1;
        while(update){
            update = 0;
            for(int i = 0 ; i < (int)mp.size() ; i++){
                for(int j = 0 ; j < (int)G[i].size() ; j++){
                    Edge e = G[i][j];
                    for(int S = (1<<6)-1 ; S >= 0 ; S--){
                        int ncost = d[i][S];
                        if(ncost == INF) continue;
                        ncost += e.cost*K;
                        if(e.c == -1){
                            if(ncost < d[e.to][S]){
                                d[e.to][S] = ncost;
                                update = 1;
                            }
                        }else{
                            if(S >> e.c & 1) continue;
                            if(ncost-cake[e.c] < d[e.to][S|(1<<e.c)]){
                                d[e.to][S|(1<<e.c)] = ncost-cake[e.c];
                                update = 1;
                            }
                        }
                    }
                }
            }
        }
        int res = INF;
        for(int i = 0 ; i < (1<<6) ; i++){
            res = min(res, d[t][i]);
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1396
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 A, B;
  std::cin >> A >> B;
  std::cout << std::max({2 * A - 1, 2 * B - 1, A + B}) << std::endl;
  return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
n = int(input())
coord = list()
for i in range(n):
    x, y = map(int, input().split())
    coord.append([x, y])

def calc_dist(x, y):
    ret = ((x[0] - y[0]) ** 2 + (x[1] -y[1]) **2) ** 0.5
    return ret

dist = []
for i in range(n):
    temp = []
    for j in range(n):
        temp.append(calc_dist(coord[i], coord[j]))
    dist.append(temp)

summed = 0
for k in range(len(dist)):
    summed += sum(dist[k])

ans = summed / n

print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int f[100010];
int a[100010];
int main()
{
    int m;
    cin>>m;
    for(int i=1; i<=m; i++)
        scanf("%d",&a[i]);
    f[1]=a[1];
    int ans=1;
    for(int i=2; i<=m; i++)
    {
        if(a[i]<=f[ans])
            f[++ans]=a[i];
        else
        {
            int l=1,r=ans;
            while(l<r)
            {
                int mid=(l+r)>>1;
                if(f[mid]>=a[i])
                    l=mid+1;
                else
                    r=mid;
            }
            f[l]=a[i];
        }
    }

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


Measured memory_bytes: 1024
//////////////////////////
//      _        ____   //
//  U  /"\  u U /"___|  //
//   \/ _ \/  \| | u    //
//   / ___ \   | |/__   //
//  /_/   \_\   \____|  //
//   \\    >>  _// \\   //
//  (__)  (__)(__)(__)  //
//  Compro by NULL_CT©  //
//////////////////////////
// STL libs
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(I, LIM) for (int I = 0; I < (LIM); I++)
#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;

typedef long long ll;

constexpr int MOD = 1000000007;  // 10^9+7

vector<long> divisor(long &_n) {
  vector<long> head, tail;
  for (long i = 1; i * i <= _n; i++) {
    if (_n % i == 0) {
      head.push_back(i);
      if (i * i != _n) tail.push_back(_n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return head;
}

long kadanes(vector<long> &_ls) {
  long highestMax = 0, currentMax = 0, length = _ls.size();
  for (long i = 0; i < length; i++) {
    currentMax = max(_ls[i], currentMax + _ls[i]);
    highestMax = max(highestMax, currentMax);
  }
  return highestMax;
}

struct init {
  init() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // cout<<fixed<<setprecision(20);
  }
} init;

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

int main() { ;
  ll n;
  cin >> n;
  cout << pow(n, 3) << "\n";
}


Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  vector<P> v(n);

  rep(i,n){
    cin>>v[i].F;
    v[i].S=i+1;
  }

  sort(all(v));

  vi ans(n);
  rep(i,n){
    cout<<v[i].S<<' ';
  }
  cout<<endl;

}

Measured memory_bytes: 3200
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	cin >> n;
	string s;
	for (int i = 0; i < n; i++) {
		vector<int>base(4,0);
		int out = 0, score = 0;
		while (out!=3) {
			cin >> s;
			if (s == "OUT")out++;
			else if (s == "HIT") {
				for (int j = 3; 0 < j; j--) {
					base[j] = base[j - 1];
				}
				base[0] = 1;
				if (base[3] == 1) {
					base[3] = 0;
					score++;
				}
			}
			else if (s == "HOMERUN") {
				int cnt = 0;
				for (int j = 0; j < 3; j++) {
					if (base[j] == 1) {
						cnt++;
						base[j] = 0;
					}
				}
				score += 1 + cnt;
			}
		}
		cout << score << endl;
	}
	return 0;
}

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

int main() {

    int H, W;
    
    cin >> H >> W;

    int a[502][502];

    for(int i = 1; i <= H ; ++i ) for(int j = 1; j <= W ; ++j ) cin >> a[i][j];

    int N = 0;

    int y[2][250000], x[2][250000];

    for(int i = 1; i <= H ; ++i ) for(int j = 1; j < W ; ++j ) {
        if( a[i][j] % 2 == 0 ) continue;
        y[0][N] = i, y[1][N] = i;
        x[0][N] = j, x[1][N] = j+1;
        ++N;
        --a[i][j];
        ++a[i][j+1];
    }

    for(int i = 1; i < H ; ++i ) {
        if( a[i][W] % 2 == 0 ) continue;
        y[0][N] = i, y[1][N] = i+1;
        x[0][N] = W, x[1][N] = W;
        ++N;
        --a[i][W];
        ++a[i+1][W];
    }
    
    cout << N << endl;

    for(int i = 0; i < N ; ++i ) {
        cout << y[0][i] << ' ';
        cout << x[0][i] << ' ';
        cout << y[1][i] << ' ';
        cout << x[1][i] << endl;
    }

    return 0;
}


Measured memory_bytes: 7040
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
#include <functional>
#include <string.h>
#include <numeric>
#include <math.h>

#define LOOP(N) for(int i=0; i<(N); ++i)
#define REP(i, N) for(int i=0; i<(N); ++i)
#define FOR(i, start, end) for(int i=(start); i<(end); ++i)

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using Graph = vector< vector<int> >;

struct Node {
    int num;
    vector<int> children;
    int add;
    int counter;
    Node() {
        counter = 0;
        add = 0;
    }
};


void add_all(vector<Node> &nodes, int p, int add=0) {
    nodes[p].add += add;
    if (nodes[p].add == 0) return;
    nodes[p].counter += nodes[p].add;
    for (auto child : nodes[p].children) {
        add_all(nodes, child, nodes[p].add);
    }
    nodes[p].add = 0;
}


int main() {
    int N, Q; cin >> N >> Q;
    vector<double> v(N, 0);
    vector<Node> nodes(N);
    REP(i, N) nodes[i].num = i;
    int a, b;
    FOR(i, 1, N) {
        cin >> a >> b;
        nodes[a-1].children.push_back(b-1);
    }
    
    int p, x;
    REP(i, Q) {
        cin >> p >> x;
        nodes[p-1].add += x;
    }
    
    REP(i, N) add_all(nodes, i);
    
    cout << nodes[0].counter;
    FOR(i, 1, N) cout << " " << nodes[i].counter;
}


Measured memory_bytes: 27392
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD				1000000007
#define MOD1			998244353
#define EPS				1e-9
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int tam = 10000010;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	ll ar[3][1000], ta[3], k;
	fore(i, 0, 3)
		cin>>ta[i];
	cin>>k;
	fore(i, 0, 3)
	{
		fore(j, 0, ta[i])
			cin>>ar[i][j];
		sort(ar[i], ar[i] + ta[i]);
	}
	priority_queue<pair<ll, pair<int, pair<int, int> > > > que;
	que.push(mp(ar[0][ta[0] - 1] + ar[1][ta[1] - 1] + ar[2][ta[2] - 1], mp(ta[0]-1, mp(ta[1]-1, ta[2]-1))));
	int x, y, z;
	map<pair<int,pair<int,int>>, bool> visi;
	int con = 0;
	while(con < k)
	{
		x = que.top().s.f;
		y = que.top().s.s.f;
		z = que.top().s.s.s;
		cout<<que.top().f<<'\n';
		con++;
		que.pop();
		if(x > 0 && !visi[mp(x-1, mp(y, z))])
		{
			visi[mp(x-1, mp(y, z))] = 1;
			que.push(mp(ar[0][x-1] + ar[1][y] + ar[2][z], mp(x-1, mp(y, z))));
		}
		if(y > 0 && !visi[mp(x, mp(y-1, z))])
		{
			visi[mp(x, mp(y-1, z))] = 1;
			que.push(mp(ar[0][x] + ar[1][y-1] + ar[2][z], mp(x, mp(y-1, z))));
		}
		if(z > 0 && !visi[mp(x, mp(y, z-1))])
		{
			visi[mp(x, mp(y, z-1))] = 1;
			que.push(mp(ar[0][x] + ar[1][y] + ar[2][z-1], mp(x, mp(y, z-1))));
		}
	}
	return 	0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

typedef pair<long long, long long> P;
int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    map<long long, long long> m;
    sort(A.begin(), A.end());
    vector<int> ju(N, 0);
    vector<long long> r(1e6 + 1, 0);
    for(int i = 1; i < N; i++){
        if(A[i] == A[i - 1]){
            ju[i] = -1;
            ju[i - 1] = -1;
        }
    }
    for(int i = 0; i < N; i++){
        if(m.count(A[i])) continue;
        long long t = A[i];
        long long res = 2;
        while(t*res <= A[N - 1]){
            r[t*res]++;
            res++;
        }
    }
    long long ans = 0;
    for(int i = 0; i < N; i++){
        if(r[A[i]] == 0 && ju[i] == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13560
n, m, l = [int(x) for x in input().split(" ")]

first = []
second = []

for _ in range(n):
    first.append([int(x) for x in input().split(" ")])

for _ in range(m):
    second.append([int(x) for x in input().split(" ")])

res = []

for i in range(n):
    res.append([])
    for j in range(l):
        a = 0
        for k in range(m):
            a +=(first[i][k] * second[k][j])
        res[i].append(a)

for r in res:
    print(*r)

Measured memory_bytes: 9180
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct edge{int to,cost;};
int V;
vector<edge> G[100010];
ll d[100010],d2[100010];
 
void dijkstra(int s){
  priority_queue<pint,vector<pint>,greater<pint>> que;
  fill(d,d+V,longinf);
  d[s]=0;
  que.push(pint(0,s));
  
  while(!que.empty()){
    pint p=que.top(); que.pop();
    int v=p.second;
    if(d[v]<p.first)continue;
    rep(i,G[v].size()){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(pint(d[e.to],e.to));
      }
    }
  }
}

void dijkstra2(int s){
  priority_queue<pint,vector<pint>,greater<pint>> que;
  fill(d2,d2+V,longinf);
  d2[s]=0;
  que.push(pint(0,s));
  
  while(!que.empty()){
    pint p=que.top(); que.pop();
    int v=p.second;
    if(d2[v]<p.first)continue;
    rep(i,G[v].size()){
      edge e=G[v][i];
      if(d2[e.to]>d2[v]+e.cost){
        d2[e.to]=d2[v]+e.cost;
        que.push(pint(d2[e.to],e.to));
      }
    }
  }
}

int main(){
  int n;
  cin >> n;
  V=n;
  rep(i,n-1){
    int x,y;
    cin >> x >> y;
    x--,y--;
    G[x].push_back({y,1});
    G[y].push_back({x,1});
  }
  dijkstra(0),dijkstra2(n-1);
  int f=0;
  rep(i,n){
    if(d[i]<=d2[i])f++;
  }
  if(2*f>n)cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
return 0;}

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

int main(){
  long N,M,L =1; cin >> N >> M;
  long a[N]; 
  for (int i =0; i<N; i++) {
    cin >> a[i]; a[i] /=2; L = lcm(L,a[i]);
  }

  for (int i =0; i<N; i++) {
    if (L / a[i] % 2 ==0) {
      cout << 0 << endl;
      return 0;
    }
  }
  long ans;
  if (M % (2*L) >=L) ans = M / (2*L) + 1;
  else ans = M/(2*L);
  cout << ans <<endl;                   
}

Measured memory_bytes: 4356
#include <iostream>
#include <cstdio>
#include <algorithm>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;



int n,k;

int const MAXN = 510000;


long long fac[MAXN], finv[MAXN], inv[MAXN];
long long A[MAXN];

// テーブルを作る前処理
void init_fac(ll MOD){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
    for (int i = 2; i < MAXN; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll modcomb( int n, int k, ll MOD ){
	if( n < k )	return 0;
	if( n < 0 || k < 0 )	return 0;
	return fac[n] * ( finv[k] * finv[n-k] % MOD ) % MOD;
}

bool cmp_reverse( int a, int b ){
	return a > b;
}



int main(){
	ll const MOD = 1000000007L;
	init_fac(MOD);

	std::cin >> n >> k;

	for( int i = 1; i <= n; i++ )
		std::cin >> A[i];

	

	ll maxsum = 0;
	ll minsum = 0;

	std::sort( A+1, A+1+n );
	for( int i = k; i <= n; i++ ){
		maxsum = ( maxsum + A[i] * modcomb( i-1, k-1, MOD ) % MOD ) % MOD;
		// printf("maxsum = %lld\n", maxsum);
	}

	std::sort( A+1, A+1+n, cmp_reverse );
	for( int i = k; i <= n; i++ ){
		minsum = ( minsum + A[i] * modcomb( i-1, k-1, MOD ) % MOD ) % MOD;
	}
	
	// printf("maxsum = %lld, minsum = %lld\n", maxsum, minsum );
	std::cout << (maxsum - minsum + MOD) % MOD << std::endl;
}


Measured memory_bytes: 14976
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;

template<typename T>
inline T in(){T tmp; cin >> tmp; return tmp;}

int main()
{
    int n;

    while (scanf("%d", &n), n){
        int dice[6] = {1, 2, 6, 5, 4, 3};
        int sum = 1;

        while (n-- > 0){
            string s = in<string>();

            if (s == "North"){
                int tmp = dice[0];
                for (int i = 0; i < 3; i++) dice[i] = dice[i + 1];
                dice[3] = tmp;
            }
            else if (s == "South"){
                int tmp = dice[3];
                for (int i = 3; i > 0; i--) dice[i] = dice[i - 1];
                dice[0] = tmp;
            }
            else if (s == "East"){
                int tmp = dice[4];
                dice[4] = dice[2];
                dice[2] = dice[5];
                dice[5] = dice[0];
                dice[0] = tmp;
            }
            else if (s == "West"){
                int tmp = dice[5];
                dice[5] = dice[2];
                dice[2] = dice[4];
                dice[4] = dice[0];
                dice[0] = tmp;
            }
            else if (s == "Right"){
                int tmp = dice[1];
                dice[1] = dice[5];
                dice[5] = dice[3];
                dice[3] = dice[4];
                dice[4] = tmp;
            }
            else if (s == "Left"){
                int tmp = dice[1];
                dice[1] = dice[4];
                dice[4] = dice[3];
                dice[3] = dice[5];
                dice[5] = tmp;
            }
            sum += dice[0];
        }
        printf("%d\n", sum);
    }

    return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int ans,now=0;
string s,t;
vector<int> v[30];
map<char,bool> m;

signed main() {
    cin >> s >> t;
    rep(i,s.size()) m[s[i]] = true;
    rep(i,t.size()) if (!m[t[i]]) {
            cout << -1 << endl;
            return 0;
        }
    rep(i,s.size()) v[s[i]-'a'].pb(i+1);
    rep(i,30) v[i].pb(INF);
    rep(i,t.size()) {
        auto itr = upper_bound(all(v[t[i]-'a']), now);
        if (*itr == INF) {
            ans += s.size();
            now = v[t[i]-'a'][0];
        } else {
            now = *itr;
        }
        if (now == s.size()) now = 0,ans += s.size();
    }
    ans += now;
    cout << ans << endl;
}




Measured memory_bytes: 1724
#include<iostream>
using namespace std;
int main()
{
int n, x, y, i, j, k, sum;
while(1)
{
	cin >> n >> x;
	if ( n == 0 && x == 0)break;
	else
	{
		sum = 0;
		for( i = 1; i <= n; i++)
		{
			for( j = 1; j <= n; j++)
			{
				if ( i == j )break;
				else
				{
					for( k = 1; k <= n; k++ )
					{
						if ( k == i || k == j )break;
						else
						{
							y = i + j + k;
							if ( y == x )sum++;
						}
					}
				}
			}
		} 
		cout << sum << endl;
	}
}

return 0;
}

Measured memory_bytes: 1160
# 君指先跃动の光は、私の一生不変の信仰に、唯私の超电磁炮永生き！
from sys import stdin, stdout
import math
import bisect
from collections import defaultdict
import datetime
import random

x,y,z = stdin.readline().strip().split()

x, y = y, x
x, z = z, x

stdout.writelines(' '.join([x,y,z]))

Measured memory_bytes: 46444
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
long long N,W;
long long w[105],u[105];
long long dp[100005][105];
long long ans=0;
int main()
{
	scanf("%d%d",&N,&W);
	for(int i=1;i<=N;i++)
	    scanf("%d%d",&w[i],&u[i]);
	for(int i=1;i<=W;i++)
	    for(int j=1;j<=N;j++)
	        if(i>=w[j])
	            dp[i][j]=max(dp[i][j-1],dp[i-w[j]][j-1]+u[j]);
	        else
	            dp[i][j]=max(dp[i][j-1],dp[i][j]);
	for(int i=1;i<=N;i++)
	    ans=max(ans,dp[W][i]);
	cout<<ans;
	return 0;
}

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

using namespace std;

int edge[220][220];
int X, Y, e, x, y;
bool done[220];

bool dfs(int s, int g){
    if(done[s])return false;
    done[s] = true;
    if(s == g)return true;
    for(int to = 0;to < 220;to++){
        if(edge[s][to] == 0)continue;
        if(dfs(to, g)){
            edge[s][to]--;
            edge[to][s]++;
            return true;
        }
    }
    return false;
}

int main(){
    cin >> X >> Y >> e;
    int s = X+Y, g = X+Y+1;
    for(int i = 0;i < e;i++){
        cin >> x >> y;
        edge[x][y+X] = 1;
    }
    for(int i = 0;i < X;i++)edge[s][i] = 1;
    for(int i = 0;i < Y;i++)edge[i + X][g] = 1;

    int ans = 0;
    while(true){
        fill(done, done + 220, false);
        if(!dfs(s, g))break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3272
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a,bbb=b;i<=bbb;++i)
#define repd(i,a,b) for(register int i=a,bbb=b;i>=bbb;--i)
#define reps(s) for(register int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define gmn(a,b) a=min(a,b)
#define gmx(a,b) a=max(a,b)
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
typedef double db;
inline int qi(){
    int f=0,fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ql(){
	ll f=0;int fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline db qd(){
    char c=getchar();int flag=1;double ans=0;
    while((!(c>='0'&&c<='9'))&&c!='-') c=getchar();
    if(c=='-') flag=-1,c=getchar();
    while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar();
    if(c=='.'){c=getchar();for(register int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();}
    return ans*flag;
}
//start!

int main()
{
	printf("%d\n",qi()^1); return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 100005;

int n,a[N];

int main() {

	n=read();  int num=0,num2=0;
	rep(i,1,n) {a[i]=read(); if (a[i]<0) ++num; else if (a[i]>0) ++num2;}
	sort(a+1,a+n+1);
	if (num==n) {
		int tmp=a[n],ans=a[n]; rep(i,1,n-1) ans-=a[i];
		printf("%d\n",ans);
		rep(i,1,n-1) {printf("%d %d\n",tmp,a[i]); tmp-=a[i];}
	} else if (num2==n) {
		int tmp=a[1],ans=-a[1]; rep(i,2,n) ans+=a[i];
		printf("%d\n",ans);
		rep(i,3,n) {printf("%d %d\n",tmp,a[i]); tmp-=a[i];}
		printf("%d %d\n",a[2],tmp);
	} else if (num==0&&num2==0) {
		puts("0"); rep(i,1,n-1) puts("0 0");
	} else {
		int ans=0; rep(i,1,n) ans+=abs(a[i]); printf("%d\n",ans);
		int ptr; 
		if (num==0) {rep(i,1,n) if (a[i]!=0) {ptr=i;break;}} 
		else {rep(i,1,n) if (a[i]>=0) {ptr=i; break;}}
		int tmp=a[1];
		rep(i,ptr+1,n) {printf("%d %d\n",tmp,a[i]); tmp-=a[i];}
		printf("%d %d\n",a[ptr],tmp); tmp=a[ptr]-tmp;
		rep(i,2,ptr-1) {printf("%d %d\n",tmp,a[i]); tmp-=a[i];}
	}
	

	return 0;
	
}


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


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

     int A[n];
     int B[n];
     int C[n];

     for(int i=0;i<n;i++) cin>>A[i];
     for(int i=0;i<n;i++) cin>>B[i];
     for(int i=0;i<n-1;i++) cin>>C[i];
     C[n] = 0;

     int nB[n];
     for(int i=0;i<n;i++){
          nB[i]= B[A[i]-1];
     }

     int nC[n];
     for(int i=0;i<n;i++){
          nC[i]= C[A[i]-1];
     }

     int ans = 0;

     for(int i=0;i<n;i++){
          if(i!=0 and A[i]==A[i-1]+1) ans = ans + nC[i-1];
          ans = ans + nB[i];
     }
     cout<<ans;
}

Measured memory_bytes: 256