akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner inputData = new Scanner( System.in);
//		各面(S1~S6)の値を取得する処理
		int[] dice_surface = new int[7];
		for( int count=1; count<=6; count++) {
			dice_surface[count] = inputData.nextInt();
		}
		Dice dice = new Dice(dice_surface);
//		命令となる文字列を取得する処理
		char[] commandAll = inputData.next().toCharArray();
		
		for( char command : commandAll) {
			switch( command) {
			case 'N' :
				dice.roll_N();
				break;
			case 'S' :
				dice.roll_S();
				break;
			case 'W' :
				dice.roll_W();
				break;
			case 'E' :
				dice.roll_E();
				break;
			}
		}
		dice.outSurface();
	}
}

//サイコロに関するクラス
class Dice {
//	配列のインデックスをサイコロの番号と合わせる為(roll時の値保管用の為)7つ用意
	public static int[] surface = new int[7];
	
	public Dice() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
	public Dice(int[] surface_in) {
		// TODO 自動生成されたコンストラクター・スタブ
		surface = surface_in;
	} 
	public void outSurface() {
		System.out.println( surface[1]);
	}
	
	public void roll_N() {
		surface[0] = surface[1];
		surface[1] = surface[2];
		surface[2] = surface[6];
		surface[6] = surface[5];
		surface[5] = surface[0];
	}
	public void roll_S() {
		surface[0] = surface[1];
		surface[1] = surface[5];
		surface[5] = surface[6];
		surface[6] = surface[2];
		surface[2] = surface[0];
	}
	public void roll_W() {
		surface[0] = surface[1];
		surface[1] = surface[3];
		surface[3] = surface[6];
		surface[6] = surface[4];
		surface[4] = surface[0];
	}
	public void roll_E() {
		surface[0] = surface[1];
		surface[1] = surface[4];
		surface[4] = surface[6];
		surface[6] = surface[3];
		surface[3] = surface[0];
	}
}



Measured memory_bytes: 26352
#include <iostream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;


int main() {
    int h, n;
    cin >> h >> n;
    vector <vector <long long>> dp(n, vector <long long>(h + 1));
    vector <pair<int, int> > s(n);
    vector <long long> mins(h + 1);
    mins[0] = 10000000000;
    for (int i = 0; i < n; ++i) {
        cin >> s[i].first >> s[i].second;
    }
    for (int i = 1; i <= h; ++i) {
        mins[i] = 1000000000000;
        for (int j = 0; j < n; ++j) {
            if (s[j].first >= i)
                dp[j][i] = s[j].second;
            else {
                dp[j][i] = s[j].second + mins[i - s[j].first];
            }
            mins[i] = min(mins[i], dp[j][i]);
        }
    }
    cout << mins[h];
    return 0;
}

Measured memory_bytes: 78592
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000//10^8

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



int main(){
    int n,m;
    while(cin>>n>>m,n||m){
        bool senbei[n][m];
        for(int i=0;i<=n-1;i++)for(int j=0;j<=m-1;j++)cin>>senbei[i][j];
        bool sen[n][m];
        int ans=0;
        for(int s=0;s<1<<n;s++){
            for(int i=0;i<=n-1;i++){
                if(s>>i&1)for(int j=0;j<=m-1;j++)sen[i][j]=!senbei[i][j];
                else for(int j=0;j<=m-1;j++)sen[i][j]=senbei[i][j];
            }
            int count=0;
            for(int j=0;j<=m-1;j++){
                int cou=0;
                for(int i=0;i<=n-1;i++)if(!sen[i][j])cou++;
                count+=max(cou,n-cou);
            }
            if(count>ans)ans=count;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3244
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> p(4),t(4);
    for(int i=0; i<4; i++){
        cin >> p[i];
    }
    for(int i=0; i<4; i++){
        cin >> t[i];
    }
    int ans = inf;
    for(int i=0; i<=100; i++){
        for(int j=0; j<=100; j++){
            for(int k=0; k<=100; k++){
                int l = max(0,(N - (t[0]*i+t[1]*j+t[2]*k)));
                if(l){
                    l = (l+t[3]-1)/t[3];
                }
                chmin(ans,p[0]*i + p[1]*j + p[2]*k + p[3]*l);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3216
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    a = readInt()
    ans = 0
    for i in range(n):
        if i%2==0 and a[i]%2==1:
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  vector<ll> sp(a + 1), sq(b + 1), sr(c + 1);
  for (int i = 0; i < a; i++) cin >> p[i];
  for (int i = 0; i < b; i++) cin >> q[i];
  for (int i = 0; i < c; i++) cin >> r[i];

  set<ll> s;
  for (auto &&v : p) s.insert(v);
  for (auto &&v : q) s.insert(v);
  for (auto &&v : r) s.insert(v);
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());
  for (int i = 0; i < a; i++) sp[i + 1] = sp[i] + p[i];
  for (int i = 0; i < b; i++) sq[i + 1] = sq[i] + q[i];
  for (int i = 0; i < c; i++) sr[i + 1] = sr[i] + r[i];
  ll ans = 0;
  for (auto &&v : s) {
    ll temp = 0;
    auto pit = lower_bound(p.begin(), p.end(), v);
    auto qit = lower_bound(q.begin(), q.end(), v);
    ll rest = 0;
    if (p.end() - pit >= x) {
      temp = sp[a] - sp[a - x];
    } else {
      temp = sp[a] - sp[a - (p.end() - pit)];
      rest += x - (p.end() - pit);
    }
    if (q.end() - qit >= y) {
      temp += sq[b] - sq[b - y];
    } else {
      temp += sq[b] - sq[b - (q.end() - qit)];
      rest += y - (q.end() - qit);
    }
    if (rest > c) continue;
    temp += sr[c] - sr[c - rest];
    ans = max(ans, temp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 19072
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, h, w; cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
}

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

int main(){
    while(true){
        int n,r;
        cin >> n >> r;
        if(n==0)break;
        vector<int> card(n);
        for(int i=0;i<n;i++){
            card[i]=i+1;
        }
        for(int i=0;i<r;i++){
            int p,c;
            cin >> p >> c;
            int pos=n-p-c+1;
            queue<int> temp;
            for(int j=0;j<c;j++){
                temp.push(card[pos]);
                card.erase(card.begin()+pos);
            }
            while(!temp.empty()){
                card.push_back(temp.front());
                temp.pop();
            }
        }
        cout << card[n-1] << endl;
    }
    return 0;
}

                

Measured memory_bytes: 3048
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()

class Heap(object):
    def __init__(self, A):
        self._heap = []
        # heapify は O(n) でできるらしいが、O(nlogn) で妥協
        # cf. https://github.com/python/cpython/blob/3.8/Lib/heapq.py
        for a in A:
            self.append(a)

    def __len__(self):
        return len(self._heap)

    def __bool__(self):
        return bool(self._heap)

    def front(self):
        assert self
        return self._heap[0]

    def append(self, x):
        self._heap.append(x)
        now = len(self)-1
        heap = self._heap
        # n の親は (n-1)//2
        while now!=0 and heap[now] < heap[(now-1)//2]:
            heap[now], heap[(now-1)//2] = heap[(now-1)//2], heap[now]
            now = (now-1)//2

    def pop(self):
        assert self
        if len(self)==1:
            return self._heap.pop()

        heap = self._heap
        res, heap[0] = heap[0], heap.pop()
        # n の子は 2*n+1, 2*n+2
        now = 0
        while(1):
            if now*2+1 >= len(self): break # 子が存在しない
            # 子がひとつだけのとき、必要なら入れ替えて終わり
            if now*2+1 == len(self)-1:
                if heap[now] > heap[now*2+1]:
                    heap[now], heap[now*2+1] = heap[now*2+1], heap[now]
                break
            # 子が複数のとき
            else:
                # 親、子1、子2のうち、親が最小であれば終わり
                if min(heap[now], heap[2*now+1], heap[2*now+2]) == heap[now]: break
                # そうでないとき、子のうち小さい方を親と入れ替える
                next = min((heap[2*now+1],2*now+1), (heap[2*now+2],2*now+2))[1]
                heap[now], heap[next] = heap[next], heap[now]
                now = next

        return res

    def sort(self):
        return [self.pop() for _ in range(len(self))]

def resolve():
    n, m = map(int,input().split())
    A = list(map(lambda x:-int(x),input().split()))
    heap = Heap(A)
    for _ in range(m):
        x = -heap.pop()
        x //= 2
        heap.append(-x)

    print(-sum(heap._heap))
resolve()

Measured memory_bytes: 63856
#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll;
int main()
{
	ll n;
	cin>>n;
	int a[n-1];
	vector<int>v;
     for(ll i=0;i<n-1;i++)
     	cin>>a[i];
    ll ans=0;
    ans=ans+a[0];
    for(int i=1;i<n-1;i++)
    {
    	ans=ans+min(a[i],a[i-1]);
    }
  ans =ans+a[n-2];
  cout<<ans<<endl;
    
	} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ld INF = 1e10;
const ld EPS = 1e-10;

//aがINFまたは-INFであるかどうか
bool judge(ld a){
    return abs(abs(a)-INF) < EPS;
}

int main(){
    map<char, int> mp;
    mp['R'] = 0, mp['U'] = 1, mp['L'] = 2, mp['D'] = 3;
    int N; cin >> N;
    //1つ目が移動方向(長方形の種類)、2つ目が端の座標
    ld pos[4][4];
    rep(i, 4){
        pos[i][0] = -INF, pos[i][1] = -INF;
        pos[i][2] = INF, pos[i][3] = INF;
    }
    rep(i, N){
        ld x, y; char d;
        cin >> x >> y >> d;
        int a = mp[d];
        pos[a][0] = max(pos[a][0], x);
        pos[a][1] = max(pos[a][1], y);
        pos[a][2] = min(pos[a][2], x);
        pos[a][3] = min(pos[a][3], y);
    }
    vector<ld> check;
    //任意の２つの長方形を比較
    rep(i, 4){
        rep(j, 4){
            //どの端に注目するか
            rep(k, 4){
                if(judge(pos[i][k]) || judge(pos[j][k])) continue;
                ld r = abs(pos[i][k] - pos[j][k]);
                check.pb(r), check.pb(r/2);
            }
        }
    }
    ld ans = 1e18;
    for(auto &e: check){
        ld X = max({pos[0][0]+e, pos[1][0], pos[2][0]-e, pos[3][0]});
        ld Y = max({pos[0][1], pos[1][1]+e, pos[2][1], pos[3][1]-e});
        ld x = min({pos[0][2]+e, pos[1][2], pos[2][2]-e, pos[3][2]});
        ld y = min({pos[0][3], pos[1][3]+e, pos[2][3], pos[3][3]-e});
        ans = min(ans, (X-x)*(Y-y));
    }
    cout << sp(15) << ans << endl;
}

Measured memory_bytes: 384
import Data.List (splitAt)
main = getLine >>= print.palindromephilia

palindromephilia :: String -> Int
palindromephilia str = sum $ zipWith f ls rs'
  where len = length str
        (ls, rs) = splitAt (len `div` 2) str
        rs' = reverse rs
        f a b = if a == b then 0 else 1

Measured memory_bytes: 508
import math

a, b, c = map(int, input().split())

cnt = 0

if a == b == c and (a+b+c)%2 == 0:
    print(-1)
    exit()
else:
    while a%2 == 0 and b%2 == 0 and c%2 == 0:
        a, b, c = b/2 + c/2, a/2 + c/2, a/2 + b/2
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
from collections import defaultdict
def solve():
    n = int(input())
    m = defaultdict(int)
    for _ in range(n):
        m["".join(sorted(input()))] += 1
    ans = 0
    for s, i in m.items():
        if i != 1:
            ans += i * (i - 1) // 2
    print(ans)
solve()


Measured memory_bytes: 18236
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>

#define max  1000

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}
int int_sort( const void * a , const void * b ) {
  return strcmp(( char * )a , ( char * )b );
}

int main()
{
    long long int x, ctmp=100, y=0;
    
    scanf("%lld", &x);
    
    while (ctmp<x) {
        ctmp+=ctmp*0.01;
        y++;
    }
    
    printf("%lld", y);
    
    return 0;
} 



Measured memory_bytes: 1728
def resolve():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10 ** 9] * n
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, n):
        for j in range(1, min(k + 1, i + 1)):
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
    print(dp[-1])


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 52448
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long e = sc.nextLong();
		long min = Math.min(a, Math.min(b, Math.min(c, Math.min(d, e))));
		long time;
		if(n < min) {
			time = 5;
		} else if(n % min == 0) {
			time = n / min + 4;
		} else {
			time = n / min + 5;
		}
		System.out.println(time);
	}

}


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

int main(){
	int n,q,t;
	ll k;
	cin >> n >> k >>q;
	vector<ll> a(n,k-q);
	rep(i,q){
		cin >> t;
		a[t-1]++;
	}
	rep(i,n){
		if(a[i] > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
#define LL long long
#include <string>

int main()
{
    char n[10];
    cin >> n;
    for (int i = 0; i < 3; ++i) {
        if (n[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 3632
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scanner = new Scanner(System.in);
		long a = scanner.nextLong();
		long b = scanner.nextLong();
		long c = scanner.nextLong();
		long d = scanner.nextLong();
		
		long max = Long.MIN_VALUE;
		
		if(a*c > max)
			max = a*c;
			
		if(a*d > max)
			max = a*d;
			
		if(b*c > max)
			max = b*c;
		
		if(b*d > max)
			max = b*d;
			
		System.out.println(max);

	}
}

Measured memory_bytes: 35532
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	D = inputInt()
	C = inputList()
	S = []
	for i in range(D):
		s = inputList()
		S.append(s)

	ans1 = []
	ans2 = []
	ans3 = []
	ans4 = []
	for i in range(D):
		bestSco1 = 0
		bestSco2 = 0
		bestSco3 = 0
		bestSco4 = 0
		bestI1 = 1
		bestI2 = 1
		bestI3 = 1
		bestI4 = 1

		for j,val in enumerate(S[i]):
			if j == 0:
				tmpAns = ans1 + [j+1]
				tmpSco = findScore(tmpAns, S, C)
				if bestSco1 < tmpSco:
					bestSco4 = bestSco3
					bestI4 = bestI3
					bestSco3 = bestSco2
					bestI3 = bestI2
					bestSco2 = bestSco1
					bestI2 = bestI1
					bestSco1 = tmpSco
					bestI1 = j+1
			else:
				tmpAns1 = ans1 + [j+1]
				tmpAns2 = ans2 + [j+1]
				tmpAns3 = ans3 + [j+1]
				tmpAns4 = ans4 + [j+1]
				tmpSco1 = findScore(tmpAns1, S, C)
				tmpSco2 = findScore(tmpAns2, S, C)
				tmpSco3 = findScore(tmpAns3, S, C)
				tmpSco4 = findScore(tmpAns4, S, C)
				if bestSco1 < tmpSco1:
					bestSco1 = tmpSco1
					bestI1 = j+1
				if bestSco2 < tmpSco2:
					bestSco2 = tmpSco2
					bestI2 = j+1
				if bestSco3 < tmpSco3:
					bestSco3 = tmpSco3
					bestI3 = j+1
				if bestSco4 < tmpSco4:
					bestSco4 = tmpSco4
					bestI4 = j+1
		ans1.append(bestI1)
		ans2.append(bestI2)
		ans3.append(bestI3)
		ans4.append(bestI4)

	aa = []
	aa.append(bestSco1)
	aa.append(bestSco2)
	aa.append(bestSco3)
	aa.append(bestSco4)
	aa.sort()
	aa = aa[::-1]

	if aa[0] == bestSco1:
		for i in ans1:
			print(i)
	elif aa[0] == bestSco2:
		for i in ans2:
			print(i)
	elif aa[0] == bestSco3:
		for i in ans3:
			print(i)
	elif aa[0] == bestSco4:
		for i in ans4:
			print(i)


def findScore(ans, S, C):
	scezhu = [inf for i in range(26)]
	sco = 0
	for i,val in enumerate(ans):
		tmp = S[i][val-1]
		scezhu[val-1] = i
		mins = 0
		for j,vol in enumerate(C):
			if scezhu[j] == inf:
				mins = mins + (vol * (i+1))
			else:
				mins = mins + (vol * ((i+1)-(scezhu[j]+1)))
		tmp -= mins
		sco += tmp
	return sco

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 86952
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb(x)           push_back(x)
#define mkp(x,y)        make_pair(x,y)
#define L               length()
#define int             long long
#define bs              binary_search
#define mod             1e9+7
#define IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(v)          v.begin(),v.end()
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define F               first
#define S               second
#define pii             pair<int,int>
#define vi              vector<int>
#define vs              size()
#define gcd(a,b)        __ gcd(a,b)
#define endl            '\n'
#define atoi            stoi
#define elasped_time    1.0 * clock() / CLOCKS_PER_SEC
#define si              set <int>
#define vpii            vector < pair <int,int> >
#define memf(a)         memset(a,false,sizeof(a))
#define memt(a)         memset(a,true,sizeof(a))
#define xxx             998244353
#define pi              3.141592653589
#define ninf            INT_MIN
#define inf             INT_MAX
int max(int a,int b){if(a>b){return a;}else{return b;}}
int min(int a,int b){if(a<b){return a;}else{return b;}}
int sz(vi v){if(v.empty()){return 0;}else{return v.vs;}}
int sz(si v){if(v.empty()){return 0;}else{return v.vs;}}
int sz(vpii v){if(v.empty()){return 0;}else{return v.vs;}}
int power(int b,int e)
{
    if(e==0)
    return 1;
    if(e%2)
    return ((b*power((b)*(b),(e-1)/2)));
    else
    return power((b)*(b),e/2);
}
int modpower(int b,int e,int q)
{
    int MOD=q;
    if(e==0)
    return 1;
    if(e%2)
    return ((b%MOD)*modpower((b%MOD)*(b%MOD),(e-1)/2,q))%MOD;
    else
    return modpower((b%MOD)*(b%MOD),e/2,q)%MOD;
}
void dpv(vi v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void dpv(vpii v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i].F<<" "<<v[i].S<<endl;
    }
}
void dpv(set <int> v)
{
    for(auto i:v)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}
//////////////////////**TREE MOVES STARTS**//////////////////////////////
///// **TREE MOVES ENDS**////////////////////////////

////*SOLUTION TO THE QUESTION STARTS HERE*///////
void oblivious()
{
    int n,k;
    cin>>n>>k;
    int h[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    if(k>n)
    {
        cout<<(h[n]-h[1])<<endl;
        return;
    }
    int dp[n+1]; //minimum amount of money required to reach nth stone
    mem0(dp);
    dp[1]=0;
    for(int i=2;i<=k;i++)
    {
        dp[i]=abs(h[i]-h[1]);
    }
    for(int i=k+1;i<=n;i++)
    {
        int ans=INT_MAX;
        for(int j=1;j<=k;j++)
        {
            ans=min(dp[i-j]+abs(h[i]-h[i-j]),ans);
        }
        dp[i]=ans;
    }
    cout<<dp[n]<<endl;
}
signed main()
{
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    int t=1;
    //cin>>t;
    while(t--)
    {
        oblivious();
    }
    return 0;
}
//Md Zuhair

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int n,t;
int a[3030], b[3030];

int dp[3001][3001];

int solve(int idx, int time) {
	if(idx == n){return 0;}
	if(time >= t){return 0;}
	if(dp[idx][time] != -1){return dp[idx][time];}
	return dp[idx][time] = max(solve(idx+1, time), b[idx] + solve(idx+1, time+a[idx]));
}

int main(){
	memset(dp, -1, sizeof dp);
	scanf("%d %d",&n,&t);
	int i,j;
	ii temp[3030];
	for(i=0;i<n;i++){
		scanf("%d %d",&a[i],&b[i]);
		temp[i].first = a[i], temp[i].second = b[i];
	}
	sort(temp, temp+n);
	for(i=0;i<n;i++){
		a[i] = temp[i].first, b[i] = temp[i].second;
	}
	printf("%d\n",solve(0,0));

	return 0;
};

Measured memory_bytes: 35712
# coding: utf-8
# Your code here!
S = input()
if 1 <= int(S[:2]) <= 12:
    if 1 <= int(S[2:]) <= 12:
        print ("AMBIGUOUS")
    else:
        print ("MMYY")
else:
    if 1 <= int(S[2:]) <= 12:
        print ("YYMM")
    else:
        print ("NA")

Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
  int n,i,j,k;
  int m,f,r;
  scanf("%d %d %d",&m,&f,&r);

  while (!((m==-1) && (f==-1) && (r==-1))){
    if ((m==-1) || (f==-1)){
      printf("%c\n",'F');
    }else if (m+f>=80){
      printf("%c\n",'A');
    }else if(m+f>=65){
      printf("%c\n",'B');
    }else if(m+f>=50){
      printf("%c\n",'C');
    }else if(m+f>=30){
      if (r>=50){
        printf("%c\n",'C');
      }else{
        printf("%c\n",'D');
      }
    }else{
      printf("%c\n",'F');
    }
    scanf("%d",&m);
    scanf("%d",&f);
    scanf("%d",&r);
  }
 
 
  return 0;
}





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

int n;
int cnt = 0;
set<int> st;

void calc(int x, int y) {
	if(x == 0) {
		return;
	}
	for(int i = 3; i <= 7; i += 2) {
		int tmp = y * 10 + i;
		set<int> st2;
		for(int i = 0; i <= cnt - x; i++) {
			st2.insert(tmp % 10);
			tmp /= 10;
		}
		if(st2.size() == 3 && y * 10 + i <= n) {
			st.insert(y * 10 + i);
		}
		calc(x - 1, y * 10 + i);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	cin >> n;
	int tmp = n;
	while(tmp > 0) {
		tmp /= 10;
		cnt++;
	}
	calc(cnt, 0);
	cout << st.size() << endl;
	return 0;	
}


Measured memory_bytes: 1536
#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;

void solve()
{
    lli h, a;
    cin>>h>>a;
    lli ans = ceil(h * 1.0 / a);
    cout<<ans;
    cout<<'\n';
    return ;
}



/*
*/

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: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,a[10001],sum=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n-1;i++)
        for(int j=i+1;j<=n;j++)
        {
            if(a[i]<a[j]) swap(a[i],a[j]);
        }
    for(int i=1;i<=k;i++) sum+=a[i];
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

s = 0
for i in range(N):
    s += abs(A[i])

if 0 in A:
    print(s)
    exit(0)

parity = 0
for i in range(N):
    if A[i] < 0:
        parity += 1

if parity % 2 == 0:
    print(s)
    exit(0)

mx = 1 << 30
for i in range(N):
    mx = min(mx , abs(A[i]))
print(s - mx * 2)

Measured memory_bytes: 64752
//番号を保って向きを変える、は、すれちがって番号を変えると解釈できる。
//そうすると、1回ぶつがるごとに蟻の番号は+1, または, -1変化する。これは蟻の進む向きによる。
//各蟻についてぶつかる回数を求めるのが本質で、これは適当にO(1)でできる。
//最後にぶつかったまま止まる場合が厄介。最後はぶつかったとみなす。
#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

int n, L, t;
int x[100000], w[100000];
vector<P> rights;	//(pos, id)
vector<P> lefts;
int ans[100000];

signed main() {
	int i;
	
	cin >> n >> L >> t;
	
	rep(i, n) {
		cin >> x[i] >> w[i];
		if (w[i] == 1) rights.push_back(P(x[i], i));
		else lefts.push_back(P(x[i], i));
	}
	sort(rights.begin(), rights.end());
	sort(lefts.begin(), lefts.end());
	
	int rsz = rights.size(); rep(i, rsz) rights.push_back(P(rights[i].first + L, rights[i].second));
	int lsz = lefts.size(); rep(i, lsz) lefts.push_back(P(lefts[i].first + L, lefts[i].second));
	//cout << endl;
	//rep(i, rights.size()) cout << rights[i].first << " " << rights[i].second << endl; cout << endl;
	//rep(i, lefts.size()) cout << lefts[i].first << " " << lefts[i].second << endl; cout << endl;
	
	rep(i, rsz) {
		int l = upper_bound(lefts.begin(), lefts.end(), P(rights[i].first, 114514)) - lefts.begin();
		int r = upper_bound(lefts.begin(), lefts.end(), P(rights[i].first + (2 * t) % L, 114514)) - lefts.begin();
		int cnt = r - l + lsz * ((2 * t) / L);
		int id = (rights[i].second + cnt % n) % n;
		int pos = (rights[i].first + t % L) % L;
		ans[id] = pos; //cout << id << endl;
	}
	
	rep(i, lsz) {
		int l = upper_bound(rights.begin(), rights.end(), P(lefts[i + lsz].first - (2 * t) % L, -114514)) - rights.begin();
		int r = upper_bound(rights.begin(), rights.end(), P(lefts[i + lsz].first, -114514)) - rights.begin();
		int cnt = r - l + rsz * ((2 * t) / L);
		int id = (lefts[i + lsz].second - cnt % n + n) % n;
		int pos = (lefts[i + lsz].first - t % L) % L;
		ans[id] = pos; //cout << id << endl;
	}
	
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 6884
n,k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()
ans = h[k-1] - h[0]
for j in range(0,n-k+1):
  if  h[j+k-1] - h[j] < ans:
    ans = h[j+k-1] - h[j]
print(ans)

Measured memory_bytes: 7384
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>
#include <stdlib.h>


int main(){

    string S;
    cin >> S;
    int nagasa = S.length();
    int cnt = 0;
    if(nagasa % 2 != 0) nagasa--;
    else nagasa -= 2;

    int i = nagasa;
    while(i >= 2){
        string str1 = S.substr(0,i/2);
        string str2 = S.substr(i/2 ,i/2);
        if(str1 == str2) {
            cnt = i;
            break;
        }
        i -= 2;

    }
    
    cout << cnt << endl;
    return 0; 
}

Measured memory_bytes: 256
n=int(input())
a=[]
b=[]
for i in range(n):
    p=[int(j) for j in input().split()]
    a.append(p[0])
    b.append(p[1])

a.reverse()
b.reverse()
ans=0
import math
for i in range(n):
    a[i]+=ans
    ans+=b[i]*math.ceil(a[i]/b[i])-a[i]
print(ans)
        




Measured memory_bytes: 15020
#include<iostream>
#include<iomanip>

using namespace std;

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

	int n, t, l, b;
	while (cin >> n >> t >> l >> b, n) {
		bool lose[110] = { false }, back[110] = { false };
		int x;
		for (int i = 0; i < l; i++) {
			cin >> x;
			lose[x] = true;
		}
		for (int i = 0; i < b; i++) {
			cin >> x;
			back[x] = true;
		}

		double dp[110][110] = { 0 };
		dp[0][0] = 1.0;
		for (int turn = 0; turn < t; turn++) {
			for (int pos = 0; pos < n; pos++) {
				if (dp[turn][pos] == 0) continue;

				for (int dice = 1; dice <= 6; dice++) {
					int npos = pos + dice;
					if (n < npos)npos = n - (npos - n);

					if (lose[npos]) {
						dp[turn + 2][npos] += dp[turn][pos] / 6.0;
					}
					else if (back[npos]) {
						dp[turn + 1][0] += dp[turn][pos] / 6.0;
					}
					else {
						dp[turn + 1][npos] += dp[turn][pos] / 6.0;
					}
				}
			}
		}
		double ans = 0;
		for (int turn = 1; turn <= t; turn++) {
			ans += dp[turn][n];
		}
		cout << fixed << setprecision(6) << ans << endl;
	}
}

Measured memory_bytes: 1368
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

int n,p[50],t[50],dp[50][4],minnum,ans;

int main()
{
    while(scanf("%d",&n) && n!=0)
    {
      for(int i=0;i<n;i++)scanf("%d%d",&p[i],&t[i]);
      memset(dp,-1,sizeof(dp));if(p[0]<=t[0])dp[0][1]=p[0];
      for(int i=1;i<n;i++)
      {
        minnum=99999999;
        for(int j=1;j<4;j++)if(dp[i-1][j]!=-1 && p[i]+p[i-1]*(j+1)<=t[i]-t[i-1])minnum=min(minnum,dp[i-1][j]+p[i]+p[i-1]);
        if(minnum!=99999999)dp[i][1]=minnum;
        if(dp[i-1][1]!=-1 && abs(p[i]-p[i-1])*2<=t[i]-t[i-1])dp[i][2]=dp[i-1][1]+abs(p[i]-p[i-1]);
        if(dp[i-1][2]!=-1 && abs(p[i]-p[i-1])*3<=t[i]-t[i-1])dp[i][3]=dp[i-1][2]+abs(p[i]-p[i-1]);
      }
      ans=-1;
      for(int i=1;i<4;i++)if(dp[n-1][i]!=-1 && (ans==-1 || ans>dp[n-1][i]))ans=dp[n-1][i];
      if(ans==-1)
      {
        for(int j=0;j<n;j++)
        {
          ans=-1;
          for(int i=1;i<4;i++)if(dp[j][i]!=-1 && (ans==-1 || ans>dp[j][i]))ans=dp[j][i];
          if(ans==-1)
          {
            printf("NG %d\n",j+1);
            break;
          }
        }
      }
      else printf("OK %d\n",ans+p[n-1]);
    }
    return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>

int main(void) {
  int A,B,C,D;

  scanf("%d%d%d%d", &A, &B, &C, &D);

  int x;

  if( A < B )
    x = A;
  else
    x = B;

  int y;

  if( C < D )
    y = C;
  else
    y = D;

  int ans = x + y;
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N,M; cin >> N >> M;
    string s; cin >> s;
    reverse(s.begin(),s.end());
    int now = 0;
    vector<int> ans;
    while(true){
        bool ok = false;
        for(int i = now+M; i >= now+1; i--){
            if(i <= N && s[i] == '0'){
                ans.push_back(i-now);
                now = i;
                ok = true;
                break;
            }
        }
        if(!ok){
            cout << -1 << endl;
            return 0;
        }
        if(now == N) break;
    }
    reverse(ans.begin(),ans.end());
    rep(i,ans.size()) cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 1144
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    h,w = f()
    g = [ f() for i in range(h)]

    cnt = 0
    ans = []
    for i in range(h):
        for j in range(w):
            if g[i][j]%2 == 0:
                continue
            else:
                if j+1<w  and (g[i][j+1]%2 == 1 or i+1 == h):
                    g[i][j+1] += 1
                    cnt+=1
                    ans += [(i+1, j+1, i+1, j+1+1)]

                elif i+1<h:
                    g[i+1][j] += 1
                    cnt+=1
                    ans += [(i+1, j+1, i+2, j+1)]

    
    print(cnt)
    for i in ans:
        print(i[0], i[1], i[2], i[3])



solve()


Measured memory_bytes: 26592
#include<stdio.h>
#include<string.h>
#define LEN 13
#define N 1000000

int A(char);
int insert(char*);
int find(char*);
int keyA(int);
int keyB(int);
int getkey(char*);

char dic[N][LEN];

int main(){
    int i,n;
    
    char com[7],in[LEN];
    
    for(i = 0;i < N;i++){
        dic[i][0] = '\0';
    }
    
    scanf("%d",&n);
    
    for(i = 0;i < n;i++){
        scanf("%s %s",com,in);
        
        if(strcmp(com,"insert") == 0){
            insert(in);
        }
        else if(strcmp(com,"find") == 0){
            if(find(in) == 1) printf("yes\n");
            else printf("no\n");
        }
    }
    return 0;
}

int A(char a){
    
    if(a == 'A') return 0;
    else if(a == 'C') return 1;
    else if(a == 'G') return 2;
    else return 3;
}

int insert(char* a){
    int i,key,num;
    
    key = getkey(a);
    
    for(i = 0; ;i++){
        num = (keyA(key) + i*keyB(key)) % N;
        if(strcmp(dic[num],a) == 0) return 1;
        else if(strlen(dic[num]) == 0){
            strcpy(dic[num],a);
            return 0;
        }
    }
    return 0;
}

int find(char *a){
    int i,key,num;
    key = getkey(a);
    for(i = 0; ;i++){
        num = (keyA(key) + i*keyB(key)) % N;
        if(strcmp(dic[num],a) == 0) return 1;
        else if(strlen(dic[num]) == 0) return 0;
    }
    return 0;
}

int keyA(int key){
    return key % N;
}

int keyB(int key){
    return 1 + key % (N - 1);
}

int getkey(char *a){
    int i,sum = 0,p = 1;
    
    for(i = 0;i < strlen(a);i++){
        sum += p * A(a[i]);
        p*=5;
    }
    return sum;
}



Measured memory_bytes: 14436
import heapq
import copy

N = int(input())
A_l = [int(input()) * -1 for _ in range(N)] 
A = copy.deepcopy(A_l)
heapq.heapify(A_l)

m = heapq.heappop(A_l) * -1
n = heapq.heappop(A_l) * -1

for a in A:
  if a * -1 == m:
    print(n)
  else:
    print(m)

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

int main() {
    long n;
    long long result = 0;
    cin >> n;
    for (long i=1; i<=n; i++) {
        if (i%3!=0 && i%5!=0) result+=i;
    }
    cout << result;
    return 0;
}

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


// 2011/10/23

// 0089 Ðµ`
public class Main {

	// C return falseÅ¨µÜ¢
	boolean main() throws IOException {

		List<int[]> list = new ArrayList<int[]>();
		
		int size = 0;
		for(int i = 0;; i++) {
			if (size != 0 && i >= size * 2 - 1)
				break;
			int[] ia = readIntArray();
			list.add(ia);
			if (size == 0 && ia.length < i + 1)
				size = i;
		}
		

		int[] prevLine = new int[] { list.get(0)[0] };
		
		for(int y = 1; y < size * 2 - 1; y++) {
			
			int xSize = y + 1;
			if (y >= size) {
				xSize = size * 2 -1 - y;
			}
			log.printf("xSize=%d\n", xSize); 
			int[] line = new int[xSize];
			for(int x = 0; x < xSize; x++) {
				int max = 0;
				if (y < size) { // O¼
					if (x - 1 >= 0) {
						max = prevLine[x - 1];
					}
					if (x < prevLine.length) {
						max = Math.max(max, prevLine[x]);
					}
				}
				else { // ã¼
					if (x >= 0) {
						max = prevLine[x];
					}
					if (x + 1 < prevLine.length) {
						max = Math.max(max, prevLine[x + 1]);
					}
				}
				max += list.get(y)[x];
				line[x] = max;
				log.printf("%d ", max);
			}
			log.printf("\n");
			
			prevLine = line;
		}
		
			
		// ðÌ\¦
		System.out.printf("%d\n", prevLine[0]);
		
		
		return false;
		//return true; // ³íI¹ Ö
	}
	

//	private final static boolean DEBUG = true;  // debug
	private final static boolean DEBUG = false; // release

	public static void main(String[] args) throws IOException {

		if (DEBUG) {
			log = System.out;
			
			String inputStr = "7:3,8:8,1,0:2,7,4,4:4,5,2,6,5:2,7,4,4:8,1,0:3,8:7:";

			inputStr = inputStr.replace(":", "\n");

			reader = new BufferedReader(new StringReader(inputStr)); 

		}
		else {
			log = new PrintStream(new OutputStream() { public void write(int b) {} } ); // «ÌÄ
			reader = new BufferedReader(new InputStreamReader(System.in)); // R\[©ç
		}
		
		//int N = readIntArray()[0];

		for(int i = 0; /*i < N*/; i++) {
			boolean b = new Main().main();
			if (!b)
				break;
		}		
		
		reader.close();
	}

	
	static PrintStream log;
	static BufferedReader reader;
	

	// WüÍæè1sªÌæØè¶æØèÅÌ®lðÇÞ
	// EOFÌêÍnullðÔ·
	private static int[] readIntArray() throws IOException {

		String s = null;
		for(;;) {
			s = reader.readLine();
			log.printf("%s\n", s);
			if (s == null)
				return null;
			s = s.trim();
			if (s.length() != 0) // ¦¦¦@Ç¤àËRósðÇÞ±Æª éBÇÝòÎ·Æ¤Ü­¢­çµ¢BBBB
				break;
		}
		
		String[] sp = s.split("[ ,]"); // æØè¶ÍXy[X©J}
		int[] a = new int[sp.length];
		for(int i = 0; i < sp.length; i++) {
			a[i] = Integer.parseInt(sp[i]);
		}
		return a;
	}
		
}

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

map<int,int>mp;

int main()
{
    long long n;
    cin>>n;
    long long arr[n+10];
    long long sum=0;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        sum=sum+arr[i];
        mp[arr[i]]++;
    }
    int t;
    cin>>t;
    while(t--)
    {
        long long a,b;
        cin>>a>>b;
            sum=sum-(a*mp[a]);
            sum=sum+(b*mp[a]);
            mp[b]=mp[b]+mp[a];
            mp[a]=0;
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 8748
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 3e6 + 5, oo = 1e9;

int main()
{
    ll n, c = 0;
    ll sum = 0;
    scanf("%lld", &n);
    for(int i = 1 ; i <= n ; i ++)
    {
        if((i % 3 == 0 or i % 5 == 0)) continue;
        sum += i;
    }
    printf("%lld\n", sum);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  int mn = INT_MAX;
  for (int i = 0; i < n; i++) {
    int left = 0, right = 0;
    bool l = true;
    for (int j = 0; j < n; j++) {
      if (l) {
        left += w[j];
      } else {
        right += w[j];
      }
      if (i == j) { l = false; }
    }
    mn = min(mn, abs(left - right));
  }
  cout << mn << endl;
}

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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
//RNG based on mersenne_twister 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }


int _runtimeTerror_()
{
	int n;
	cin>>n;
	string s=to_string(n);
	if(s[0]=='7' || s[1]=='7' || s[2]=='7')
	{
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	cerr<<"\n"<<_time_;
	return 0;
}


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

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

  set<int> s;
  int r = 1, x = 7;
  while (x % k) {
    r++;
    x = (10 * x + 7) % k;
    if (s.count(x)) {
      r = -1;
      break;
    }
    s.insert(x);
  }
  cout << r << endl;
}


Measured memory_bytes: 50448
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>
#include<queue>
#include<set>


#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}



bool comp(const pair<long long int, vector<int>> a, const pair<long long int, vector<int>> b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}
	else {
		return a.second < b.second;
	}

}







bool isReversible(string str) {

	int index1 = 0, index2 = str.size() - 1;

	while (index1 < index2) {
		if (str[index1] != str[index2])return false;
		index1++;
		index2--;
	}

	return true;


}



int main(){

	int buf[10][10] = { 0 };

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		string str = to_string(i);

		int first = str[0] - '0';
		int last = str[str.size() - 1] - '0';

		buf[first][last]++;
	}

	long long int ans = 0;

	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {

			ans += buf[i][j] * buf[j][i];
		}
	}


	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 256
import itertools
a, b = map(int, input().split())

#約数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
c = make_divisors(a)
d = make_divisors(b)

f = list(set(c) & set(d))
ans = []

for s in f:
    if is_prime(s):
        ans.append(s)
print(len(ans)+1)

Measured memory_bytes: 5276
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 

#include <boost/format.hpp>

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;

string lpad(string l,int s,int n){
    string temp = to_string(n);
    string res = "";
    int loop = s - temp.size();
    while(loop--) res+=l;

    return res+temp;
}

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

    printIf(n%2==0,n,n*2)
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int x,y;
  cin >> x >> y;
  int d[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
  if(d[x-1] == d[y-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

typedef long long ll;

const int MAXN = 100000;

ll S[MAXN + 5], A[MAXN + 5], M;
int N, V, P;

int main() {
	scanf("%d%lld%d%d", &N, &M, &V, &P);
	for(int i=1;i<=N;i++) scanf("%lld", &A[i]);
	sort(A + 1, A + N + 1);
	for(int i=N;i>=1;i--) S[i] = S[i + 1] + A[i];
	int cnt = P;
	for(int i=N-P;i>=1;i--) {
		if( A[i] + M < A[N-P+1] ) break;
		else if( i + P - 1 >= V ) cnt++;
		else {
			ll del = ((N-P+1) - (i+1) + 1)*(A[i] + M) - (S[i+1] - S[N-P+2]);
			if( del / (V - (i+P-1)) >= M ) cnt++;
			else break;
		}
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 1664
using System;

class Program {
  static void Main(string[] args) {
    string s = Console.ReadLine();
    for (int i = 1; i < s.Length; ++i) {
      if (s[i] == s[i-1]) {
        Console.WriteLine("Bad");
        return;
      }
    }
    Console.WriteLine("Good");
  }
}

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


unsigned long long solve(){
  unsigned long long M,N;
  cin >> M >> N;
  if(M==1 && N==1) return 1;
  if(M==1) return N-2;
  if(N==1) return M-2;
  return (M-2)*(N-2);
}
int main() {
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 256