akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;


//D
int main() {
	ll N, Q;
	scanf("%lld %lld", &N, &Q);

	vector<vector<ui>> graph(N + 1, vector<ui>(0));

	for (int i = 0; i < N - 1; i++) {
		ui a, b;
		scanf("%d %d", &a, &b);
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	vector<ll> count(N + 1, 0);
	vector<ll> countup(N + 1, 0);

	for (int i = 0; i < Q; i++) {
		ui p, x;
		scanf("%d %d", &p, &x);
		countup[p] += x;
	}

	//�[���D��ŏ��񂵂āA�ŏ��ɖK�⎞�ɂ̓J�E���g�A�b�v�����v���X�A�Ō�ɋA���Ă����Ƃ��Ƀ}�C�i�X
	ll add = 0;
	vector<ui> node_state(N + 1, 0); //0:���K�� 1:�ŏ��̖K��ς� 2:�Ō�̖K��ς�
	stack<ui> s;
	s.push(1); //node1����T���X�^�[�g

	while (s.empty() == false) {
		//printf("node:%d state:%d count:%lld\n", s.top(), node_state[s.top()], add);

		if (node_state[s.top()] == 0) {
			//���K��
			node_state[s.top()] = 1; //�ŏ��̖K��ς݂�
			add += countup[s.top()]; //���̃m�[�h�Ǝq�ɃJ�E���g�����Z����
			count[s.top()] = add; //���̃m�[�h�̃J�E���g�l����

			//�q���X�^�b�N�ɓ����
			for (auto child : graph[s.top()]) {
				if (node_state[child] == 0) {
					//���̖K����
					s.push(child);
				}
				else {
					//�������Ȃ�
				}
			}
		}
		else if (node_state[s.top()] == 1) {
			//�ŏ��̖K��ς݁����̃m�[�h�Ǝq�̖K�⊮��
			add -= countup[s.top()];
			s.pop();
		}
		
	}

	for (int i = 1; i <= N; i++) {
		printf("%lld ", count[i]);
	}

	return 0;
}



//int main()
//{
//	long N;
//
//	cin >> N;
//
//	vector<int> v;
//
//	for (long long iN = 0; iN < N; iN++) {
//		int value;
//
//		cin >> value;
//
//		v.push_back(value);
//	}
//
//	std::sort(v.begin(), v.end());
//
//	double result = 0.0;
//	result = (v[0] + v[1]) / 2.0;
//	for (long long iN = 2; iN < N; iN++) {
//		result = (result + v[iN]) / 2.0;
//	}
//
//	cout << result << endl;
//}


//int main()
//{
//	long N;
//
//	cin >> N;
//
//	vector<int> v;
//
//	for (long long iN = 0; iN < N; iN++) {
//		int value;
//
//		cin >> value;
//
//		v.push_back(value);
//	}
//
//	std::sort(v.begin(), v.end());
//
//	double result = 0.0;
//	result = (v[0] + v[1]) / 2.0;
//	for (long long iN = 2; iN < N; iN++) {
//		result = (result + v[iN]) / 2.0;
//	}
//
//	cout << result << endl;
//}


//int main()
//{
//	long N;
//
//	cin >> N;
//
//	double sum = 0.0;
//
//	for (long long iN = 0; iN < N; iN++) {
//		double value;
//
//		cin >> value;
//
//		sum += 1.0 / value;
//	}
//
//	double result = 1.0 / sum;
//
//	cout << result << endl;
//}


//int main()
//{
//	long a;
//	string s;
//
//	cin >> a >> s;
//
//	if (a >= 3200) {
//		cout << s << endl;
//	}
//	else {
//		cout << "red" << endl;
//	}
//
//}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll f(ll X) {
    if (X % 4 == 0) {
        return X;
    } else if (X % 4 == 1) {
        return 1;
    } else if (X % 4 == 2) {
        return X + 1;
    } else {
        return 0;
    }
}

void Main() {
    ll A, B;
    cin >> A >> B;
    ll ans = f(B) ^ f(A - 1);
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool used[1000005];
int main (){
	for (int i=100;i<=105;i++) used[i]=true;
	for (int i=1;i<=100000;i++){
		if (used[i])
			for (int j=100;j<=105;j++)
				used[i+j]=true;
	}
	int n;scanf ("%d",&n);
	printf ("%d",used[n]);
	return 0;
}

Measured memory_bytes: 384
def main():
    import sys
    from collections import deque
    input = sys.stdin.readline
    N = int(input())
    color = [-1] * N
    color[0] = 0
    uvw = []
    edge = [[]for _ in range(N)]
    # append=uvw.append
    for i in range(N-1):
        ui, vi, wi = map(int, input().split())
        ui -= 1
        vi -= 1
        edge[ui].append((vi, wi))
        edge[vi].append((ui, wi))
    stack = [0]
    for i in range(N):
        tmp = deque()
        while stack:
            i = stack.pop()
            for e, w in edge[i]:
                if color[e] == -1:
                    stack.append(e)
                    if color[i] == 0:
                        if w % 2 == 0:
                            color[e] = 0
                        else:
                            color[e] = 1
                    else:
                        if w % 2 == 0:
                            color[e] = 1
                        else:
                            color[e] = 0
        # print(color)
        stack = tmp
    print(*color, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 66704
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define INF 0x3f //plus infinite

int a[100002];

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

  int ans = 0;
  int state_now = 1;

  for(int i = 1;i <= n;i++){
    cin >> a[i];
  }
  
  while(a[state_now]){
    if(a[state_now] == 2){
      ++ans;
      cout << ans << endl;
      return 0;
    }else{
      int tmp = a[state_now];
      a[state_now] = 0;
      state_now = tmp;
      ++ans;
    }
  }
  cout << "-1" << endl;

}

/*文字列の辞書順について
 *C++の順序では'0'～'9'→'A'～'Z'→'a'～'z'の順に
 *                       なっていることに注意しましょう。
 */

/*行単位での入力
 * getline(cin,文字列変数);
 */


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String s = input.readLine();
        String output = "";

        for (int i = 0; i < s.length(); i++) {
            output = mutateStringBasedOnKey(output,s.charAt(i));
        }
        System.out.println(output);

    }

    private static String mutateStringBasedOnKey(String s, char key) {
        if (key == '0') {
            return s + "0";
        } else if (key == '1') {
            return s + "1";
        } else {
            if (s.isEmpty()) {
                return "";
            } else {
                return s.substring(0, s.length() - 1);
            }
        }
    }

}

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

int main() {
  int N;
  cin >> N;
  int A[110];
  for (auto i = 0; i < N; i++) {
    cin >> A[i];
  }
  bool f = true;
  int ans = 0;
  while (f) {
    f = false;
    for (auto j = N-1; j >= 1; j--) {
      if (A[j] < A[j-1]) {
        int temp = A[j-1];
        A[j-1] = A[j];
        A[j] = temp;
        f = true;
        ans++;
      }
    }
  }
  for (auto i = 0; i < N; i++) {
    cout << A[i];
    if (i != N-1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3100
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    int x[n], y[n];
    repi(i, n, 0)
    {
        cin >> x[i] >> y[i];
    }
    int ans = n;
    repi(i, n, 0)
    {
        repi(j, n, 0)
        {
            if (i == j)
                continue;
            ll dx = x[i] - x[j],
               dy = y[i] - y[j];
            int cost = 0;
            repi(ii, n, 0)
            {
                repi(jj, n, 0)
                {
                    if(ii == jj)continue;
                    if(dx == x[ii] - x[jj] && dy == y[ii] - y[jj])cost++;
                }
            }
            ans = min(ans,n-cost);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define repi(a,b) for(i=(a); i<(b); i++)
#include <iostream>

int main()
{
  long n;
  std::cin >> n;
  long *a = new long[n];
  long i;
  repi(0,n) std::cin >> a[i];
  long max=-1, count=0;
  repi(0,n)
  {
    if(a[i]>max)
    {
      max = a[i];
      count = 1;
    }
    else
    if(a[i]==max) count++;
  }
  if(count>=2)
    repi(0,n)
      std::cout << max << std::endl;
  else
  {
    long max2=-1;
    repi(0,n)
      if(a[i]>max2 && a[i]!=max)
        max2 = a[i];
    repi(0,n)
    {
      if(a[i]==max)
        std::cout << max2 << std::endl;
      else
        std::cout << max << std::endl;
    }
  }
  return 0;
}


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

ll dp[10003][10003];

string printLcs(string& s1, string& s2, int s1Len, int s2Len) {
	if(s1Len == 0 || s2Len  == 0) {
		return string("");
	}
	if(s1[s1Len - 1] == s2[s2Len - 1]) {
		return s1[s1Len -1] + printLcs(s1, s2, s1Len - 1, s2Len - 1);
	}
	else {
		if(dp[s1Len - 1][s2Len] > dp[s1Len][s2Len - 1]) {
			return printLcs(s1, s2, s1Len - 1, s2Len);
		}
		else {
			return printLcs(s1, s2, s1Len, s2Len - 1);
		}
	}
}

void findLCSLen(string& s1, string& s2, int s1Len, int s2Len) {
	
	for(int i = 0; i <= s1Len; ++i) {
		for(int j = 0; j <= s2Len; ++j) {
			if(i == 0 || j == 0) {
				dp[i][j] = 0;
			}
			else if(s1[i-1] == s2[j-1]) {
				dp[i][j] = 1 + dp[i-1][j-1];
			}
			else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
}
int main() {
	// your code goes here
	string s1, s2;
	cin >> s1;
	cin >> s2;
	
	//memset(dp, 0, sizeof(dp));
	findLCSLen(s1, s2, s1.length(), s2.length());
	string res = printLcs(s1, s2, s1.length(), s2.length());
	reverse(begin(res), end(res));
	
	cout << res;

	return 0;
}

Measured memory_bytes: 235136
#include<stdio.h>
#include<string.h>

#define M 1000003
#define L 14

char H[M][L]; 

int getChar(char ch)
{
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  return 0;
}

// convert a string into an integer value
long long getKey(char str[])
{
  long long sum = 0, p = 1, i;
  
  for (i = 0; i < strlen(str); i++)
  {
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key)
{
	return key % M;
}
int h2(int key)
{
	return 1 + key % (M - 20);
}

int find(char str[])
{
	long long key;
	long long h;
	long long d;
	
	key = getKey(str);
	h = h1(key);
	d = h2(key);
	
	while(1)
	{
		if(H[h][0] == '\0')
		{
			return 0;
		}
		if(strcmp(H[h], str) == 0)
		{
			return h;
		}
		h = (h + d) % M;
	}
}

int insert(char str[])
{
	long long key;
	long long h;
	long long d;
	
	key = getKey(str);
	h = h1(key);
	d = h2(key);
	
	while(1)
	{
		if(H[h][0] == '\0')
		{
			strcpy(H[h], str);
			return h;
		}
		h = (h + d) % M;
	}
}

int main()
{
    int i, n, h;
    char str[L], com[9];

    for (i = 0; i < M; i++) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++)
    {
		scanf("%s %s", com, str);
	
		if (com[0] == 'i')
		{
	    	insert(str);
		}
		else 
		{
	    	if(find(str)) printf("yes\n");
	    	else printf("no\n");
		}
    }
    return 0;
}

Measured memory_bytes: 14280
#include <bits/stdc++.h>
using namespace std;
int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  string map;
  cin >> map;
  for (int i = 0; i < map.size(); i++) {
    auto c = map.at(i);
    if (c == '\\') {
      S1.push(i);
    } else if (c == '/' && !S1.empty()) {
      auto idx_corr = S1.top();
      S1.pop();
      auto area_next = i - idx_corr;
      while (!S2.empty() && idx_corr < S2.top().first) {
        area_next += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(idx_corr, area_next));
    }
  }

  int A = 0, k = S2.size();
  string ans = "";
  for (size_t i = 0; i < k; i++) {
    A += S2.top().second;
    ans = " " + to_string(S2.top().second) + ans;
    S2.pop();
  }

  cout << A << endl;
  cout << k << ans << endl;
}



Measured memory_bytes: 3392
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

int dp[100001];

void solve()
{
    int N; cin >> N;
    
    // dp[i] : ちょうど i 円引き出すのにかかる最小コスト
    dp[1] = 1;

    // a, b を i 以下の最大の 6, 9 の べき とする
    // dp[i] = min(dp[i - a] + 1, dp[i - b] + 1, [k=1~5](dp[i - k] + k) )
    REP1(i, N)
    { // 1 円を i 回引き出すのが最大試行
        dp[i] = i;
        
        REP1(k, 5)
        {
            if (i - k < 1) continue;
            dp[i] = min(dp[i], dp[i - k] + k);
        }

        for (int k=1; (int)pow(6, k) <= i; k++)
        {
            int pow6 = pow(6, k);
            dp[i] = min(dp[i], dp[i - pow6] + 1);
        }

        for (int k=1; (int)pow(9, k) <= i; k++)
        {
            int pow9 = pow(9, k);
            dp[i] = min(dp[i], dp[i - pow9] + 1);
        }
    }
    cout << dp[N] << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 2e5 + 5;
 
int n,a[N];
map<ll,ll>M;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;cin>>n;
	ll res=0;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		res+=M[i-x];
		M[i+x]++;
	}
	cout<<res<<'\n';
	return 0;
}

Measured memory_bytes: 26344
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for(long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
using namespace std;

typedef long long ll;

long long myGcd(long long a, long long b)
{
	if (a % b == 0)return b;
	return myGcd(b, a % b);
}

int myGcd(int a, int b)
{
	if (a % b == 0)return b;
	return myGcd(b, a % b);
}

long long myLcm(long long a, long long b)
{
	return a * b / myGcd(a, b);
}

int myLcm(int a, int b)
{
	return a * b / myGcd(a, b);
}


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

	ll A, B, C, K;
	ll ans = 0;
	int sta = 0;

	cin >> A >> B >> C >> K;

	if (K > A)
	{
		ans += A;
		K -= A;
	}
	else
	{
		ans += K;
		K = 0;
	}

	if (K > B)
	{
		K -= B;
	}
	else
	{
		B -= K;
		K = 0;
	}

	if (K > 0)
	{
		ans -= K;
		K = 0;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;
int main()
{
	int a, b, c, k,ANS=0;
	vector<int> v;
	cin >> a >> b >> c >> k;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(), v.end());
	fore(i, 0, k)*(v.end() - 1) = *(v.end() - 1) * 2;
	fore(i, 0, 3)ANS = ANS + v[i];
	disp(ANS);
}

Measured memory_bytes: 256
N = int(input())
s = [0 for i in range(N)]
for i in range(N):
	s[i] = int(input())
s = sorted(s)
from functools import reduce
# N = 3
# s = sorted([5,20,15])
S = reduce(lambda a,b:a+b,s)
if S % 10 != 0:
	print(S)
	exit()
for i in range(N):
	if (S - s[i]) % 10 != 0:
		print(S - s[i])
		exit()
print(0)


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

int main(){
  double n,goukei = 0,kyokuti;
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i < n;i++){
    cin >> a.at(i);
    goukei += a.at(i);
  }
  double c = goukei / n;
  kyokuti = round(c);
  int b = kyokuti,kekka = 0;
  for(int i = 0;i < n;i++){
    kekka += (a.at(i) - b)*(a.at(i) - b);
  }
  cout << kekka << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),c=0;
		for(int i=0;i<n;++i)
			if(s.nextInt()==c+1)
				++c;
		System.out.println(c==0?-1:n-c);
	}
}


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

namespace ABC169
{
    class A
    {
        static void Main(string[] args)
        {
            // var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();

            var AB = Console.ReadLine().Split().Select(long.Parse).ToArray();

            Console.WriteLine(AB[0] * AB[1]);
        }
    }
}


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

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    map<char, int> x;
    REP(i,4)x[s[i]]++;
    if(x.size() == 2 && x.begin()->second == 2){
        PUTS("Yes");
    }
    else{
        PUTS("No");
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int h1 = sc.nextInt();
		int m1 = sc.nextInt();
		int h2 = sc.nextInt();
		int m2 = sc.nextInt();
		int k = sc.nextInt();
		
		int wakeUp = h1 * 60 + m1;
		int goBed = h2 * 60 + m2;
		
		int range = goBed - wakeUp - k;
		
		System.out.println(range);
		
		sc.close();
	}
}




Measured memory_bytes: 27108
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
ll num_of_primes(ll n)
{
    ll ret = 0;
    for(ll i = 2;i * i <= n;++i)
    {
        if(n % i == 0)
        {
            ++ret;
            while(n % i == 0)
                n /= i;
        }
    }
    ret += (n > 1);
    return ret;
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n, m;
    cin >> n >> m;
    cout << 1 + num_of_primes(__gcd(n, m));
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int gcd( int x, int y ){ return y ? gcd(y, x%y) : x; }
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
string f;
std::cin >>f;
rep(i,4){
  if(f[i]=='+')x++;
  else x--;
}
std::cout << x << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = (1<<30);
ll inf = (1LL<<60);
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() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int X = tx - sx;
	int Y = ty - sy;
	int i;
	//　一回目の行き
	for (i = 0; i < X; i++) cout << "R";
	for (i = 0; i < Y; i++) cout << "U";
	//　一回目の帰り
	for (i = 0; i < X; i++) cout << "L";
	for (i = 0; i < Y; i++) cout << "D";
	// 二回目の行き
	cout << "D";
	for (i = 0; i < X; i++) cout << "R";
	cout << "R";
	for (i = 0; i < Y; i++) cout << "U";
	cout << "U";
	cout << "L";
	//　二回目の帰り
	cout << "U";
	for (i = 0; i < X; i++) cout << "L";
	cout << "L";
	for (i = 0; i < Y; i++) cout << "D";
	cout << "D";
	cout << "R";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#define llint long long

using namespace std;

llint w, h;
llint x, y;

int main(void)
{
	cin >> w >> h;
	cin >> x >> y;
	
	int ans = 0;
	if(2*x == w && 2*y == h) ans = 1;
	printf("%.11f %d\n", w*h*0.5, ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 1e5+5, maxn1=202;
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll modneg(ll a,ll m)
{
    a = a % m;
    if(a<0)
        a=a+m;
    return a;
}
ll powermod(ll x, unsigned ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };
ll csb(ll n){ ll count = 0;while (n){ count += n & 1; n >>= 1; } return count;}


int main()
{

fastIO;
ll test,t,i,j,k,n,m,a,b,x,y,u,temp;
string s;
cin>>s;
if(s=="ABC")
    cout<<"ARC";
else
{
    cout<<"ABC";
}
return 0;
}

Measured memory_bytes: 3660
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}


fn main() {
    input!{
        n: usize,
        a: [usize; n-1],
    }
    let mut result: [i64; 200000] = [0; 200000];
    for i in 0..n-1 {
        let index: usize = a[i] -1;
        result[index] = result[index] + 1;
    }
    for i in 0..n {
        println!("{}", result[i]);
    }
}


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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool ok = false;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      ok = true;
      break;
    }
  }
  if (ok)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>
int main(){
  int n,x[9],y[9],i,j;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d%d",&x[i],&y[i]);
  }
  double sum=0,num=0,tim=1;
  double k=n;
  for(i=0; i<n-1; i++){
    num+=i+1;
    tim*=(i+1);
    for(j=i+1; j<n; j++){
      sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    }
  }
  sum=sum*(k-1)/num;
  printf("%lf\n",sum);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll i,w,N,MW,C[109][100009],Wi[109],Vi[109];
int main()
{
  ios_base::sync_with_stdio(false),cin.tie(0);
  cin>>N>>MW;
  for(i=1;i<=N;i++)
    cin>>Wi[i]>>Vi[i];
  for (i=0;i<=N ;i++) C[i][0] = 0;
  for (w=0;w<=MW;w++) C[0][w] = 0;
  for (i=1;i<=N;i++)
    for (w=1;w<=MW;w++) {
     if (Wi[i] > w)
      C[i][w] = C[i-1][w];
     else
       C[i][w] = max(C[i-1][w] , C[i-1][w-Wi[i]]+Vi[i]);
 }
  cout<<C[N][MW];
  return 0;
}


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

int main(){

    long long a = 0, b = 0, c, n;
    string s;
    cin >> a >>  b;
    if (a <= 12 && 5 < a){
        cout << b / 2 << endl;
        return 0;
    }else if(12 < a){
        cout << b << endl;
        return 0;
    }else{
   		cout << 0 << endl;
     }
    return 0;
    /*

    long long r, d, x;

    cin >> r >> d >> x;
    for(int i = 0; i < 10; i++){
        cout << x * r - d << endl;
        x = x * r - d;
    }

    return 0;

    long long n, m, ans = 0;
    cin >> n >> m;
    for(int i = 0; i < m;i ++){
        long long l, r;
        cin >> l >> r;
        if(l <= m && l <= r){
            ans++;
        }
    }
    cout << ans;
    return 0;*/

}


Measured memory_bytes: 384
from collections import defaultdict
N, M = map(int, input().split())
AB_dict = defaultdict(list)
AB = sorted([tuple(map(int, input().split())) for i in range(N)], reverse=True, key=lambda x: x[0])
AB = sorted(AB, reverse=True, key=lambda x: x[1])
EF = [M-i for i in range(10**5+1)]
ans = [0 for i in range(M)]
for i in range(N):
    Ai, Bi = AB[i]
    ans_i = EF[Ai]
    while ans_i >= 0 and ans[ans_i] != 0:
        ans_i -= 1
    if ans_i >= 0:
        ans[ans_i] = max(ans[ans_i], Bi)
        EF[Ai] = ans_i - 1
    else:
        EF[Ai] = ans_i
print(sum(ans))


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


void solve(long long N, std::vector<long long> T, long long M, std::vector<long long> P, std::vector<long long> X){
    ll sum=0;
    for(ll i=0; i< N; i++) sum += T[i];

    for(ll i=0; i< M; i++){
        cout << (sum - T[P[i]-1] + X[i]) << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> T(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&T[i]);
    }
    long long M;
    scanf("%lld",&M);
    std::vector<long long> P(M);
    std::vector<long long> X(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&P[i]);
        scanf("%lld",&X[i]);
    }
    solve(N, std::move(T), M, std::move(P), std::move(X));
    return 0;
}


Measured memory_bytes: 256
li=["R","U","D"]
li2=["L","U","D"]
s=input()
b=True
for i in range(len(s)):
    if(i+1)%2==0:
        if s[i] not in li2:
            b=False
            break
    else:
        if s[i] not in li:
            b=False
            break
if b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        Arrays.sort(array);
        
        int x = 0;
        int y = 0;
        for (int i = n-1; i >= 1; i--) {
            if (array[i] == array[i-1]) {
                if (x == 0) {
                    // System.out.println(i);
                    x = array[i];
                    i--;
                } else if (y == 0) {
                    // System.out.println(i);
                    y = array[i];
                    i--;
                    break;
                }
            }
        }
        System.out.println((long)x * y);
    }
}


Measured memory_bytes: 50316
#include <iostream>
using namespace std;
typedef long long ll;
ll h,w,n,s[10001],a,cnt=0,dp[100][100],x,y;
int main(void){
    cin>>h>>w>>n;
    for(int i=1;i<=n;i++){
        cin>>a;
        for(int j=0;j<a;j++){
            cnt++;
            x=(cnt-1)/w;
            if(x%2==0){
                y=(cnt-1)%w;
            }
            else y=w-(cnt-1)%w-1;
            dp[x][y]=i;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	if ( A + B >= C )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return ( 0 );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pp __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
int main()
{
    ARB
    int k,n;
    cin>>k>>n;
    int arr[n];
    for(int i=0; i<n; i++)
        cin>>arr[i];
    sort(arr,arr+n);
    int ans=k,sum=0;
    for(int i=1; i<n; i++)
    {
        ans=min(ans,k-arr[i]+arr[i-1]);
        sum+=arr[i]-arr[i-1];
    }
    ans=min(ans,sum);
    cout<<ans;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    string s;
    cin >> s;
    rep(i, s.size()){
        if(s[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
  ll n,m,k,i,j,result=0,x;
  int dp[200010]={0};
  string s;
  
  cin >> x;
  dp[0] = 1;
  rep(i,x){
    if(dp[i]==1){
      for(j=100;j<=105;j++){
        dp[i+j]=1;
      }
    }
  }
  result = dp[x];
  cout << (result==1 ? 1 : 0) << endl;
  return 0;
}

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

#define _ << " _ " <<
#define TRACE(x) cout << #x << " = " << x << endl



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

    long long a, b, c, k;     
    cin >> a >> b >> c >> k;
    if (k & 1) cout << b - a;
    else cout << a - b;

    return 0;
}

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

int main(){
  int N  ;
  cin >> N ;
  int A[100];
  bool ans = true;
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
for(int i=0;i<N;i++){
  if(A[i]%2==0&&A[i]%3!=0&&A[i]%5!=0) ans = false;
}
  
  if(ans) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  
}




Measured memory_bytes: 256
#1-6-1 #ABC085C
n,y=map(int,input().split())
y=int(y/1000)
s=[]
for a in range(1+y//10):
    now=y
    now-=10*a
    for b in range(1+now//5):
        nex=now-5*b
        if n-a-b==nex:
            s=[a,b,nex]
if s==[]:print('-1 -1 -1')
else:print(' '.join(map(str,s)))

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(ll i = a; i < n; i++)

#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include<cassert>
#include<stack>
#include<deque>
#include<list>
#include<sstream>
#include<unordered_map>
#include<time.h>
#include<functional>
#pragma comment(linker, "/STACK:8809999999")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<ld, ld> pld;
typedef pair<pll, ll> ppll;
typedef pair<pll, pll> ppp;
typedef vector<vector<vector<ll>>> vvv;
const ll mod = 1e9 + 7;
const ll atcmod = 998244353;
const ld eps = 1e-9;
const ll settled = 400007;


ll cl(ll& in)
{
	while (in < 0)
		in += atcmod;
	while (in >= atcmod)
		in -= atcmod;
	return in;
}


int main()
{
	ios_base::sync_with_stdio(false); cout.tie(NULL);
#ifndef overlord
	/*freopen("capitals.in", "r", stdin);
	freopen("capitals.out", "w", stdout);*/
#else
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
	ll n;
	cin >> n;
	vl a(n, 0);
	
	forn(i, 0, n)
		cin >> a[i];

	ll ans = 1;
	
	forn(i, 0, n)
	{
		ans *= 3;
		cl(ans);
	}

	ll ms = 0;
	
	forn(i, 0, n)
		ms += a[i];

	vl bp(ms*2 + 1, 0);
	bp[0] = 1;

	forn(i, 0, n)
	{
		for(ll j = ms + 1; j >= 0; j--)
		{
			bp[j + a[i]] += bp[j];
			cl(bp[j + a[i]]);
			bp[j] *= 2;
			cl(bp[j]);
		}
	}

	ll sum = 0;

	forn(i, (ms + 1) / 2, ms + 1)
	{
		sum += bp[i];
		cl(sum);
	}

	vl bp2(ms * 2 + 1, 0);
	bp2[0] = 1;
	forn(i, 0, n)
	{
		for (ll j = ms + 1; j >= 0; j--)
		{
			bp2[j + a[i]] += bp2[j];
			cl(bp2[j + a[i]]);
		}
	}

	if (ms % 2 == 0)
		sum -= bp2[ms / 2];
	cl(sum);

	ans = ans - sum*3 + atcmod;
	cl(ans);

	cout << ans;
	return 0;
}

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

int main(void){
    string a,b,c;
    cin>>a>>b>>c;
    cout<<(char)(toupper(a[0]));
    cout<<(char)(toupper(b[0]));
    cout<<(char)(toupper(c[0]));
    cout<<endl;
    return 0;
}

Measured memory_bytes: 384
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N, K;
	std::cin >> N >> K;
	if (N % K == 0) {
		std::cout << "0\n";
	} else {
		std::cout << "1\n";
	}
}


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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

int main() {
	int h, w;
	cin >> h >> w;
	int count = 0;
	rep(i, h) {
		rep(j, w) {
			char c;
			cin >> c;
			if (c == '#') count++;
		}
	}
	if (count == h + w - 1) {
		cout << "Possible" << endl;
	} else {
		cout << "Impossible" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=m;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev=inf;
string s;
vector<int> v;

int32_t main(void){
	scanf("%lld %lld",&n,&m);
	FOR{
		scanf("%lld",&a[i]);
	}
	for(int i=2;i<m;i++){
		cev=min(cev,a[i-1]+(n-a[i]));
		cev=min(cev,n-a[i+1]+(a[i]));
	}
	cev=min(cev,a[m]-a[1]);
	cev=min(cev,a[1]+n-a[1]);
	printf("%lld\n",cev);
	return 0;
}



Measured memory_bytes: 1792
n = gets.chomp.to_i
h = gets.chomp.split.map(&:to_i)
INF = 10 ** 9

dp = Array.new(10 ** 5 + 5, INF)

dp[0] = 0
dp[1] = (h[1] - h[0]).abs

2.upto(n-1) do |i|
  dp[i] = [dp[i-2] + (h[i] - h[i-2]).abs, dp[i-1] + (h[i] - h[i-1]).abs].min
end
p dp[n-1]


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int w,h;

int table[35][35];
int c[4];
int dist[35][35][4];

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

struct state{
	int x,y,d,costs;
	bool operator<(const state &arg)const{
		return costs > arg.costs;
	}
};

void dijkstra(){
	rep(i,h)rep(j,w)rep(k,4)dist[i][j][k]=inf;
	dist[0][0][1]=0;
	state s;
	s.x=0,s.y=0,s.d=1,s.costs=0;
	priority_queue<state>q;
	q.push(s);
	while(!q.empty()){
		state cur=q.top();q.pop();
		int x,y,d,costs;
		x=cur.x,y=cur.y,d=cur.d,costs=cur.costs;
		if(dist[y][x][d]<costs)
			continue;
		rep(i,4){
			int nx=x,ny=y,nd=d,ncosts=costs;
			nd=(nd+i)%4;
			nx+=dx[nd],ny+=dy[nd];
			if(table[y][x]!=i)
				ncosts+=c[i];
			if(0<=nx&&nx<w&&0<=ny&&ny<h){
				if(dist[ny][nx][nd]>ncosts){
					dist[ny][nx][nd]=ncosts;
					state nexts;
					nexts.x=nx,nexts.y=ny,nexts.d=nd,nexts.costs=ncosts;
					q.push(nexts);
				}
			}
		}
	}
	return;
}

int main(void){
	while(1){
		scanf("%d %d",&w,&h);
		if(w==0)
			break;
		rep(i,h)rep(j,w) scanf("%d",&table[i][j]);
		rep(i,4) scanf("%d",&c[i]);
		dijkstra();
		int ans=inf;
		rep(i,4) ans=min(ans,dist[h-1][w-1][i]);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1344
let id x = x
let n = Scanf.scanf "%d\n" id
let array = Array.init n (fun _ -> Scanf.scanf "%d\n" id)
let list = Array.to_list array
let h = Hashtbl.create 100000
 
let hash_check x =
  if Hashtbl.mem h x then let () = Hashtbl.remove h x in (-1)
  else let () = Hashtbl.add h x 1 in 1
 
let rec func l =
  match l with
  | [] -> 0
  | m :: rest -> (hash_check m) + (func rest)

let ans = func list     

let () =
  Printf.printf "%d\n" ans

Measured memory_bytes: 13440
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	long long  n,l,t,a,b,d,p,gosa,start,right,left,count;
	right = 0;
	left = 0;
	count = 0;
	gosa=0;
	vector<long long> x,w,f,h;
	cin >> n >> l >> t;
	for(int i=0;i<n;i++){
		cin >> a >> b;
		x.push_back(a);
		if(b==1){
			w.push_back(1);
			f.push_back(a);
			right +=1;
		}
		else{
			w.push_back(l-1);
			h.push_back(a);
			left +=1;
		}
	}
	if(w[0]==1){
		for(int i=0;i<left;i++){
			d = h[i]-x[0];
			if(2*t-d>=0){
				count += (2*t-d)/l + 1;
				if((2*t-d)%l==0){
					gosa =1;
				}
			}
		}
		count = count % n;
	}else{
		for(int i=0;i<right;i++){
			d = l-f[i]+x[0];
			if(2*t-d>=0){
				count += (2*t-d)/l +1;
			}
			if((2*t-d)%l==0){
					gosa = 1;
			}
		}
		count = count % n;
	}
	for(int i=0;i<n;i++){
		x[i] = (x[i] + w[i]*t)%l;
	}
	p = x[0];
	sort(x.begin(),x.end());
	if(w[0]==1){
		for(int i=0;i<n;i++){
			if(x[i]==p){
				start = i;
			}
		}
		for(int i=0;i<n;i++){
			cout << x[(n+start-count+i)%n] << endl;
		}
	}else{
		for(int i=0;i<n;i++){
			if(x[i]==p){
				start = i;
			}
		}
		for(int i=0;i<n;i++){
			cout << x[(start+count+i-gosa)%n] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4144
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define dd double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin>>n;
  int d[n];
  int i;
  for(i=0;i<n;i++){
  	cin>>d[i];
  }
  
  int s=0;
  for(i=0;i<n-1;i++){
  	int j;
  	for(j=i+1;j<n;j++){
  		int p=d[i]*d[j];
  		s=s+p;
	  }

  }
  
  cout<<s<<endl;
  
  
  return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(x =>int.Parse(x)).ToArray();
        var n = nk[0];
        var k = nk[1];
        var hs = new int[n];
        for (int i = 0; i < hs.Length; i++)
        {
            hs[i] = int.Parse(Console.ReadLine());
        }

        Array.Sort(hs);
        var m = n - k;
        var d = long.MaxValue;
        for (int i = 0; i <= m; i++)
        {
            d = Math.Min(d, hs[i + k - 1] - hs[i]);
        }
        Console.WriteLine(d);
    }
}

Measured memory_bytes: 17628