akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_DEPRECATE
#include<bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; // 注意必要时改类型
typedef vector<int> vi;
const int N = 4e2 + 2;
//dp[i][j] 代表合并i-j的花费
//dp[i][j] = min(a[i] + dp[i+1][j], a[j] + a[i][j-1]) 
ll dp[N][N], a[N], prefix[N];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifdef _DEBUG
	int tt = clock();
	// freopen("in.txt", "r", stdin);
#endif 
	int n;
	cin >> n;
	memset(dp, 0x3f, sizeof(dp));
	for (Rint i = 0; i < n; ++i) {
		cin >> a[i];
		prefix[i + 1] = a[i] + prefix[i];
		dp[i][i] = 0;
	}
	for (Rint len = 2; len <= n; ++len) {
		for (Rint st = 0; st < n; ++st) {
			int end = st + len - 1;
			if (end >= n) continue;
			for (Rint mid = st; mid <= end; ++mid) {
				dp[st][end] = min(dp[st][end], dp[st][mid] + dp[mid + 1][end] + prefix[end + 1] - prefix[st]);
			}
		}
	}
	cout << dp[0][n - 1] << endl;

#ifdef _DEBUG
	cerr << "\nTIME = " << clock() - tt << endl;
	tt = clock();
#endif

	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int w, h, n;
int a[1005], b[1005];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> w >> h >> n;
    int nowx, nowy;
    ll ans = 0;
    rep(i, n) {
        int nxx, nxy;
        cin >> nxx >> nxy;
        if (i == 0) {
            nowx = nxx;
            nowy = nxy;
            continue;
        }
        int tmp = abs(nxx - nowx) + abs(nxy - nowy);
        if ((nxx > nowx && nxy > nowy) || (nxx < nowx && nxy < nowy)) {
            ans += tmp - min(abs(nxx - nowx), abs(nxy - nowy));
        }
        else {
            ans += tmp;
        }
        nowx = nxx; nowy = nxy;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3112
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int A = 1000001;

ll GCD(ll a, ll b){
    if(b == 0){
        return a;
    }else{
        return GCD(b, a % b);
    }
}
int main() {
    int n;
    cin >> n;
    ll ref = 0;
    ll sum = 0;
    vector<ll> a(n);
    vector<ll> c(A, 0);
    bool pairwise = true;

    
    for(int i = 0; i < n; i ++) {
        cin >> a[i];
        ref = GCD(a[i], ref);
        sum += a[i];
        c[a[i]]++;
    }
    for(int i = 2; i < A; i ++){
        int cnt = 0;
        for(int j = i; j < A; j += i){
            cnt += c[j];
        }
        if(cnt != 0 && cnt != 1){
            pairwise = false;
            break;
        }
    }
    
    
    if(pairwise == 1){
        cout << "pairwise coprime" << endl;
    }else if(ref == 1){
        cout << "setwise coprime" << endl;
    }else{
        cout << "not coprime" << endl;
    }
    return 0;
}


Measured memory_bytes: 18324
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  string s;
  cin >> s;
  vector<char> ans;
  for(int i=0; i<s.size(); i++){
    if(s[i]=='0') ans.push_back('0');
    else if(s[i]=='1') ans.push_back('1');
    else if(!ans.empty() )ans.pop_back();
  }
  for(int i=0; i<ans.size(); i++) cout << ans[i];
  cout << endl;
  return 0;
} 

Measured memory_bytes: 3632
#include <stdio.h>

int
main(void)
{
	int a;
	int num;
	int min = 1000000;
	int max = -1000000;
	long long sum = 0;

	scanf("%d", &num);

	for (int i = 0; i < num; i++) {
		scanf("%d", &a);
		if (min > a) 
			min = a;
		if (max < a) 
			max = a;
		sum += a;
	}

	printf("%d %d %lld\n", min, max, sum);

	return 0;
}


Measured memory_bytes: 2108
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll c=0,x=1,g=0,n,h,w,k,m,l,ans=1,ptr=0;
    string s,s1,s2;
    cin >> n;
    VI a(n);
    VI b(n);
    rep(i,n){
        cin >> a[i];
        b[a[i]]++;
	}
    if(n%2==0){
        rep(i,n){
            if(b[i]%2==1){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    else{
        rep(i,n){
            if(b[i]%2==1 && i!=0){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    c = floor(n/2);

    while(c>0){
        ans = ans * 2;
        ans %= mod;
        c--;
    }

    cout << ans << endl;
    return 0;
}

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

int main() {
  int N,sum=0;
  cin>>N;
  vector<int> scores(N);
  for(int i=0;i<N;i++){
    cin>>scores.at(i);
    sum+=scores.at(i);
  }
  if(sum%10!=0){cout<<sum<<endl;return 0;}
  sort(scores.begin(),scores.end());
  for(int i=0;i<N;i++){
    if(scores.at(i)%10!=0){
      cout<<sum-scores.at(i)<<endl;
      return 0;
    }
  }
  cout<<0<<endl;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,y; cin>>n>>y;
	for(int i=0;i<=n;++i){
		for(int j=0;j<=n-i;++j){
			int k=n-i-j;
			if(10000*i+5000*j+1000*k==y){
				cout<<i<<" "s<<j<<" "s<<k<<"\n"s;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1\n"s;
}


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

int main()
{
  int N, flag = 0;
  string S;
  
  cin >> N;
  
  for(int i=0; i<N; i++)
  {
    cin >> S;
    if(S == "Y")
    {
      flag++;
      break;
    }
    else continue;
  }
  
  if(flag) cout << "Four" << endl;
  else cout << "Three" << endl;
}

    


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

int main() {
  int N;
  cin >> N;
  
  int total = 0;

  for (int i = 0; i < N; i++) {
    int l,r;
    
    cin >> l >> r;
    
    total += (r - l + 1);
  }
  
  cout << total << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <queue>
#include <math.h>
#define SIZE 1002
#define REP(i, n) for (int i = 0; i < (n); i++)
#define X first
#define Y second

using namespace std;

typedef pair<double, double> V;
typedef long long ll;

// グローバル変数
int n;

// 自作のソート関数
bool less_theta(V& i, V& j) {
	double theta_i = 0, theta_j = 0;
	if (i.X != 0 || i.Y != 0)
		theta_i = atan2(i.X, i.Y);
	if (j.X != 0 || j.Y != 0)
		theta_j = atan2(j.X, j.Y);

	return theta_i < theta_j;
}

double dis(V& v)
{
	return v.X * v.X + v.Y * v.Y;
}

int main(void) {

// 入力

	cin >> n;
	vector<V> v(n);
	REP(i, n)
	{
		cin >> v[i].X >> v[i].Y;
	}

// 処理

	sort(v.begin(), v.end(), less_theta);
	double ans = 0;
	REP(i, n)
	{
		// 初期化
		V v_(0, 0);
		REP(j, n)
		{
			v_.X += v[(i + j) % n].X;
			v_.Y += v[(i + j) % n].Y;
			ans = max(ans, dis(v_));
		}
	}
	

// 出力

	cout << setprecision(12) << fixed << sqrt(ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		s = s.replaceFirst("a","");
		s = s.replaceFirst("b","");
		s = s.replaceFirst("c","");
		System.out.println(s.equals("")? "Yes":"No");
	}
}

Measured memory_bytes: 21972
if __name__== "__main__":
    n,m = map(int,input().split(" "))
    x = list(map(int,input().split(" ")))
    x_mod = list(map(lambda x: x%m, x))
    s = [set() for _ in range(m)]
    num = [0 for _ in range(m)]
    pair = [0 for _ in range(m)]
    dic = dict()
    sum = 0
    sum_h = 0
    for i in range(n):
        s[x_mod[i]].add(x[i])
        num[x_mod[i]] += 1
        if str(x[i]) in dic.keys():
            dic[str(x[i])] += 1
        else:
            dic[str(x[i])] = 1
        if x_mod[i]==0:
            sum += 0.5
        if m%2==0 and x_mod[i] == m/2:
            sum_h += 0.5
    for i in range(1,m):
        if i == m/2:
            continue
        p = list(s[i])
        for j in range(len(s[i])):
            pair[i] += int(dic[str(p[j])]/2)
    
    sum = int(sum)
    sum_h = int(sum_h)
    sum += sum_h
    for i in range(1,int((m+1)/2)):
        i_1 = i
        i_2 = m-i
        if num[i]>num[m-i]:
            i_1 = m-i
            i_2 = i
        sum += num[i_1]
        sum += min(int((num[i_2]-num[i_1])/2), pair[i_2])
    print(int(sum))




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

namespace ABC
{
    class ProgramC
    {
        struct Info
        {
            public int to;
            public string path;
        }
        static Queue<Info> _q = new Queue<Info>();
        static List<int>[] _graph;
        static int _count;
        static int _n;

        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            _n = int.Parse(inputs[0]);
            var m = int.Parse(inputs[1]);

            _graph = new List<int>[_n];
            for (var i = 0; i < _n; i++)
            {
                _graph[i] = new List<int>();
            }

            for (var i = 0; i < m; i++)
            {
                var inputs1 = Console.ReadLine().Split(" ");
                var a = int.Parse(inputs1[0]) - 1;
                var b = int.Parse(inputs1[1]) - 1;
                _graph[a].Add(b);
                _graph[b].Add(a);
            }

            _q.Enqueue(new Info() { to = 0, path = "0" });
            while (_q.Count > 0)
            {
                var info = _q.Dequeue();
                var v = info.to;
                var path = info.path;

                foreach (var t in _graph[v])
                {
                    if (path.Contains(t.ToString())) continue;
                    _q.Enqueue(new Info()
                    {
                        to = t,
                        path = path + t.ToString(),
                    });
                }

                if (path.Count() == _n)
                    _count++;
            }

            Console.WriteLine(_count);
        }
    }
}


Measured memory_bytes: 28960
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<algorithm>

using namespace std;

string s;
int main()
{
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5])
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<long> A(N+1,0); 
    map<long,long> mp; mp[0]++;
    for(int i=1;i<=N;i++) cin >> A[i],A[i] += A[i-1],mp[A[i]]++;
    long ans = 0;
    for(map<long,long>::iterator itr=mp.begin(); itr!=mp.end(); itr++) ans += itr->second * (itr->second-1L) / 2L;
    cout << ans << endl;
}

Measured memory_bytes: 14336
import functools
def find(s):
    dp=[]
    for i in range(len(s)):
        if i==0:
            dp+=[1]
        elif i==1:
            if s[0]==s[1]:
                dp+=[1]
            else:
                dp+=[2]
        else:
            if s[i]==s[i-1]:
                if i-3>=0:
                    dp+=[dp[i-3]+2]
                else:
                    dp+=[2]
            else:
                dp+=[dp[-1]+1]
    return dp[-1]
print(find(input()))
                


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

namespace CP
{
    class Atria
    {
        static List<List<Edge>> G;
        static bool[] seen;
        static long[] ans;
        static void Main(string[] args)
        {
            int v = int.Parse(ReadLine());
            G = new List<List<Edge>>();
            for (int i = 0; i < v; i++)
            {
                G.Add(new List<Edge>());
            }
            for (int i = 0; i < v - 1; i++)
            {
                long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();

                G[(int)(s[0] - 1)].Add(new Edge((int)s[1], s[2]));
                G[(int)(s[1] - 1)].Add(new Edge((int)s[0], s[2]));
            }
            int[] qk = ReadLine().Split(' ').Select(int.Parse).ToArray();
            //DFSによってKからの距離を計算する
            seen = new bool[v];
            seen[qk[1] - 1] = true;
            ans = new long[v];
            ans[qk[1] - 1] = 0;
            Dfs(qk[1] - 1, 0);
            //答える部分
            for (int i = 0; i < qk[0]; i++)
            {
                int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
                WriteLine(
                    ans[s[0] - 1] + ans[s[1] - 1]
                    );
            }

        }

        static void Dfs(int v, long tmp)
        {
            foreach (var edge in G[v])
            {
                if (seen[edge.node - 1]) continue;

                seen[edge.node-1] = true;
                ans[edge.node-1] = edge.distance + tmp;
                Dfs(edge.node-1, ans[edge.node-1]);
                seen[edge.node-1] = false;
            }
            return;
        }
    }

    class Edge
    {
        public int node { get; set; }
        public long distance { get; set; }

        public Edge(int n, long d)
        {
            node = n;
            distance = d;
        }
    }
}


Measured memory_bytes: 49500
#include <stdio.h>

int main(void){
  int n;
  scanf("%d", &n);
  int a[100000];
  int count[100000] = {0};
  int ans = 0;
  int button;
  
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  
  button = a[0];
  count[0]++;
  ans++;
  
  while(1){
    if(button == 2){
      printf("%d\n", ans);
      return 0;
    }
    
    count[button - 1]++;
    if(count[button - 1] > 1){
      printf("-1\n");
      return 0;
    }
    
    button = a[button - 1];
    ans++;
  }
}

Measured memory_bytes: 896
A = int(input())
B = int(input())
C = int(input())
X = int(input())
n = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i + 100*j + 50*k == X:
        n += 1
print(n)


Measured memory_bytes: 3060
def gcd(a,b):
    while a!=0 and b!=0:
        if a>b: #a<=b
            c = a
            a = b
            b = c
        b %= a
    return max(a,b)

n,x = map(int,input().split())
d = sorted(list(map(lambda a:abs(a-x),list(map(int,input().split())))))
now = d[0]
for i in d[1:]:
    now = gcd(now,i)
print(now)

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

void chmax(int64_t& a, int64_t b){
    a = max(a, b);
}

int main(){
    int N, A[100000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];

    vector<int> dp(N, 1e9), dp2(N);
    for(int i=0; i<N; i++){
        int pos = lower_bound(dp.begin(), dp.end(), A[i]) - dp.begin();
        dp[pos] = A[i];
        dp2[i] = pos;
    }
    int L = *max_element(dp2.begin(), dp2.end()) + 1;

    map<int, int64_t> sum[100001];
    sum[0][0] = 0;
    for(int i=0; i<N; i++){
        int l = dp2[i];
        int64_t prv = prev(sum[l].lower_bound(A[i]))->second;
        sum[l+1][A[i]] = prv + A[i];
    }
    int64_t ans = sum[L].rbegin()->second;
    cout << ans << endl;
}



Measured memory_bytes: 14968
#include <cstdio>
#include <cmath>
#include <climits>
#include <algorithm>

using namespace std;

double m,h,l;

int main()
{
    while(~scanf("%lf",&m)) {
        h=max(m,h);
        l=min(m,(double)INT_MAX);
    }
    printf("%f\n",fabs(h-l));
    return 0;
}

Measured memory_bytes: 1076
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("\\s");
		int a = sc.nextInt();
		int b = sc.nextInt();
		int C = sc.nextInt();

		double L = a + b + Math.sqrt(a*a + b*b - 2.0*a*b*Math.cos(Math.toRadians(C)));
		double h = b*Math.sin(Math.toRadians(C));
		double S = a*h/2.0;

		System.out.printf("%.8f\n",S);
		System.out.printf("%.8f\n",L);
		System.out.printf("%.8f\n",h);
	}
}

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

int arr[100010] = {};
bool f[100010] = {};

int solve(int i){
    
    //cout << i << " " << arr[i] << endl;
    
    if(i == 2){
        f[i] = true;
        return 1;
    }else if(f[i]){
        return 0;
    }
    
    f[i] = true;
    
    return solve(arr[i]) + 1;
    
}


int main(void){
    
    
    int n;
    cin >> n;
    
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
    }
    
    int result = solve(arr[1]);
    
    if(!f[2]){
        cout << -1 << endl;
    }else{
        cout << result << endl;
    }
    
}


Measured memory_bytes: 768
#include <iostream>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>
#include <iomanip>
#include <map>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Graph = vector<vector<T>>;

void printFixedDouble(double d, int fix) {
    cout << std::fixed;
    cout << std::setprecision(fix) << d << endl;
}

void mark(const int w, const int h, Graph<int> &map, int x, int y) {
    if (x < 0 || x >= w || y < 0 || y >= h) {
        return;
    }
    if (map[x][y] != 1) {
        return;
    }
    map[x][y] = 2;
    mark(w, h, map, x + 1, y - 1);
    mark(w, h, map, x, y - 1);
    mark(w, h, map, x - 1, y - 1);
    mark(w, h, map, x + 1, y);
    mark(w, h, map, x - 1, y);
    mark(w, h, map, x + 1, y + 1);
    mark(w, h, map, x, y + 1);
    mark(w, h, map, x - 1, y + 1);
}

int main() {
    while (1) {
        int w, h;
        cin >> w >> h;
        if (w == 0 && h == 0) {
            break;
        }

        Graph<int> map(w, vint(h, 0));
        rep(y, h) {
            rep(x, w) {
                cin >> map[x][y];
            }
        }

        int count = 0;
        rep(y, h) {
            rep(x, w) {
                if (map[x][y] == 1) {
                    mark(w, h, map, x, y);
                    count++;
                }
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 3392
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		String a=ir.next();
		String b=ir.next();
		String c=ir.next();
		out.println(a.charAt(a.length()-1)==b.charAt(0)&&b.charAt(b.length()-1)==c.charAt(0)?"YES":"NO");
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0) return 1;
	else if(N % 2 == 0) return power(MOD(a * a), N / 2);
	else return MOD(a * power(a, N - 1));
}

int inverse(int a){
	return power(a, p - 2);
}

int fact(int N){
	static vector<int> _fact(1, 1);
	for(int i = _fact.size(); i <= N; i++){
		_fact.push_back(MOD(i * _fact[i - 1]));
	}
	return _fact[N];
}
 
int fact_inv(int N){
	static vector<int> inv(2, 1), _fact_inv(2, 1);
	for(int i = inv.size(); i <= N; i++){
		inv.push_back(MOD(-(p / i) * inv[p % i]));
		_fact_inv.push_back(MOD(inv[i] * _fact_inv[i - 1]));
	}
	return _fact_inv[N];
}
 
int combination(int N, int k){
	if(k < 0 || N < k || N < 0) return 0;
	else return MOD(fact(N) * MOD(fact_inv(N - k) * fact_inv(k)));
}

signed main(){
	int N, K, i, ans = 0;
	scanf("%lld%lld", &N, &K);
	for(i = 0; i <= K && i < N; i++){
		ans = MOD(ans + combination(N, i) * combination(N - 1, i));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6768
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<queue>
#include<algorithm>

using namespace std;

int t;
int s[15];
int a[15],b[15];
int la,lb;
bool ok;

void DFS(int index){
	if(ok){
		return;
	}
	if(index==10){
		ok=true;
		return;
	}
//	cout<<"a:"<<endl;
//		for(int i=0;i<la;i++){
//			cout<<a[i]<<' ';
//		}
//		cout<<endl;
//	cout<<"b:"<<endl;
//		for(int i=0;i<lb;i++){
//			cout<<b[i]<<' ';
//		}
//		cout<<endl;
	if(la==0||s[index]>a[la-1]){
		a[la++]=s[index];
		DFS(index+1);
		la--;
	}
	if(lb==0||s[index]>b[lb-1]){
		b[lb++]=s[index];
		DFS(index+1);
		lb--;
	}
}

int main(){
	cin>>t;
	while(t--){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		la=lb=0;
		ok=false;
		for(int i=0;i<10;i++){
			cin>>s[i];
		}
		DFS(0);
		if(ok){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
//		for(int i=0;i<la;i++){
//			cout<<a[i]<<' ';
//		}
//		cout<<endl;
//		for(int i=0;i<lb;i++){
//			cout<<b[i]<<' ';
//		}
//		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;    
typedef long long ll;
//#define int long long
//#define int unsigned long long
const int mod = 1000000007;

struct node
{
    int index;
    int val;
};

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    
    int n, q;
    cin >> n >> q;
    
    vector<vector<int>> adj(n);
    vector<int> visited(n, 0);
    vector<int> has(n, 0);
    vector<int> ans(n, 0);
    
    for(int i = 0; i < n - 1; ++ i)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    while(q --)
    {
        int index, val;
        cin >> index >> val;
        --index;
        
        has[index] += val;
//        debug(index);
//        debug(has[index]);
    }
    
    queue<node> qu;
    node first = {0, 0};
    qu.push(first);
    visited[0] = 1;
    
    while(!qu.empty())
    {
        node cur = qu.front();
        qu.pop();
        int now = cur.val + has[cur.index];
        ans[cur.index] = now;
        for(int v : adj[cur.index])
        {
            if(visited[v] == 0)
            {
                visited[v] = 1;
                qu.push({v, now});
            }
        }
    }
    
    for(int i = 0; i < n; ++ i)
    {
        cout << ans[i] << " ";
    }
    cout << endl;
    
    return 0;
}






Measured memory_bytes: 17908
fun main(arr: Array<String>) {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(" ").map { it.toInt() }
    val ans = (1 until p.lastIndex).count { listOf(p[it-1], p[it], p[it+1]).sorted()[1] == p[it] }
    println(ans)
}


Measured memory_bytes: 39372
#include<stdio.h>
#include<algorithm>
using namespace std;
int A[210000];
int main()
{
    int N;
    scanf("%d",&N);
    for(int i=0; i<N; i++)
        scanf("%d",A+i);
    std::sort(A,A+N);
    for(int i=0; i<N-1; i++)
    {
        if(A[i]==A[i+1])
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
}


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

using ll=long long;
const ll MOD=1000000007;

int main() {
  ll x,a,b;
  cin >> x >> a >> b;
  if(a>=b)
    cout << "delicious" << endl;
  else if(b-a<=x)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,k;
    cin>>n>>k;
    vector<pair<int,int>>v(n);
    for(int i=0;i<n;i++){
        pair<int, int>p;
        cin>>p.first;
        cin>>p.second;
        v[i]=p;
    }
    vector<vector<long long >>dp(n+1, vector<long long>(k+1,0));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
            if(j<v[i-1].first)
                dp[i][j] = dp[i-1][j]; //within left on same row and top on previous column
            else
                dp[i][j] = max(v[i-1].second+dp[i-1][(j-v[i-1].first)], dp[i-1][j]);
            }
    }
    cout<<dp[n][k];
}


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

string Sum(string FirstInteger, string SecondInteger)
{
	if(FirstInteger.size() < SecondInteger.size()){
		swap(FirstInteger, SecondInteger);
	}
	int Degit = FirstInteger.size();
	string AddedZero(Degit - SecondInteger.size(), '0');
	SecondInteger = AddedZero + SecondInteger;
	string SumInteger(Degit, '0');
	bool IsMoveUp = false;
	for(int i = 0; i < Degit; i++){
		int Sum = IsMoveUp + FirstInteger[Degit-1-i] - '0' + SecondInteger[Degit-1-i] - '0';
		IsMoveUp = Sum / 10;
		SumInteger[Degit-1-i] = (Sum % 10) + '0';
	}
	if(IsMoveUp){
	    SumInteger = '1' + SumInteger;
	}
	return SumInteger;
}

int main()
{
	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		string FirstInteger, SecondInteger;
		cin >> FirstInteger >> SecondInteger;
//		cout << FirstInteger << '+' << SecondInteger << endl;
		string SumInteger = Sum(FirstInteger, SecondInteger);
//		cout << SumInteger.size() << "keta" << endl;
		if(SumInteger.size() <= 80){
//		    cout << "c" << endl;
		    cout << SumInteger.c_str() << endl;
//			cout << "b" << endl;
		}else{
			cout << "overflow" << endl;
		}
//		cout << "a" << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long a = scanner.nextLong(), b = scanner.nextLong(), c = scanner.nextLong(), d = scanner.nextLong();
			if (((b <= 0) && (c >= 0)) || ((a >= 0) && (c <= 0))) {
				// 正の数と負の数の組合せの場合
				System.out.println(max(a * c, a * d, b * c, b * d));
			} else {
				System.out.println(max(a * c, a * d, b * c, b * d, 0));
			}
		}
	}

	private static long max(long... a) {
		return Arrays.stream(a).max().getAsLong();
	}
}


Measured memory_bytes: 35884
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int in(int y,int x,int n){
  return 0<=y&&y<n&&0<=x&&x<n;
}
signed main(){
  int n;
  while(cin>>n,n){
    string s[n];
    for(int i=0;i<n;i++) cin>>s[i];
    int st=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	if(s[i][j]=='@') st+=(i*n+j)<<(n*n);
	else if(s[i][j]=='#') st+=1<<(i*n+j);
    
    int ans=-1,mask=(1<<(n*n))-1;
    //cout<<mask<<endl;
    int ax[]={1,1,1,0,0,-1,-1,-1};
    int ay[]={-1,0,1,-1,1,-1,0,1};
    queue<P> q;
    
    q.push(P(st,0));
    set<int> si;
    while(!q.empty()){
      P p=q.front();q.pop();
      int b=p.first,d=p.second;
      if(si.count(b)) continue;
      si.insert(b);
      int c=b&mask;
      int z=b>>(n*n);
      int y=z/n,x=z%n;
      if(c==0){
	ans=d;
	break;
      }
      for(int k=0;k<8;k++){
	int ny=y+ay[k],nx=x+ax[k],nb=0;
	if(!in(ny,nx,n)) continue;
	if((c>>(ny*n+nx))&1) continue;
	for(int i=0;i<n;i++){
	  for(int j=0;j<n;j++){
	    if(ny==i&&nx==j) continue;
	    int v=0;
	    for(int a=0;a<8;a++){
	      if(!in(i+ay[a],j+ax[a],n)) continue;
	      if((c>>((i+ay[a])*n+(j+ax[a])))&1) v++;
	      else if(ny==i+ay[a]&&nx==j+ax[a]) v++;
	    }
	    if((c>>(i*n+j))&1){
	      if(v==2||v==3) nb+=1<<(i*n+j);
	    }else{
	      if(v==3) nb+=1<<(i*n+j);
	    }
	  }
	}
	nb+=(ny*n+nx)<<(n*n);
	q.push(P(nb,d+1));
      }
    }
    
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>
int main()
{
    int a, n, min, max;
    long long sum;

    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        scanf("%d",&a);
		while(a < -1000000 || a > 1000000){
			scanf("%d",&a);
		}
        if(i==1){
            min = max = a;
            sum = a;
        }else{
            if(max < a){
                max = a;
            }else if(min > a){
                min = a;
            }
        sum += a;
        }
    }
    printf("%d %d %lld\n",min,max,sum);
}



Measured memory_bytes: 2096
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int n, d; cin >> n >> d;
  int i = 2 * d;
  int num = 1;
  while(i < n - 1){
    i += 2 * d + 1;
    num++;
  }
  cout << num << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,d;
    cin>>d>>n;
    int ans;
    if(d==0) ans=n;
    else if(d==1) ans=n*100;
    else if(d==2) ans=n*10000;
    if(n==100) ans+=ans/100;
    cout<<ans;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double x = sc.nextDouble();
    long a = 2 * (long)Math.ceil(x / (double)11);
    long b = 2 * (long)Math.ceil((x - 6) / (double)11) + 1;
    long c = Math.min(a, b); 
    System.out.println(c);
  }
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    Vl nds(N + 1, 1);
    for (ll i = 2; i <= N; i++) {
        for (ll j = i; j <= N; j += i) {
            ++nds[j];
        }
    }
    ll ans = 0;
    for (ll i = 1; i <= N; i++) {
        ans += nds[i] * i;
    }
    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 81320
//  Author: Tanuj Johal
//  It's a show time, Enjoy your everyday.

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define ini(a,n)    memset(a,n,sizeof(a))
#define ff          first
#define ss          second
#define inf         1e18
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}
#define run_time cout << "\nTIME = " << clock() - tt << endl; tt = clock();

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;
unordered_map<ll,set<ll>> g;
unordered_map<ll,ll> vis;
ll tt;
const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
const ll N = 2e5 + 10;
ll dx[4]={-1, +1, 0, 0};
ll dy[4]={0, 0, +1, -1};
bool imp = false;


void solve()
{
    ll n; cin >> n;
    ll i=0;
    ll xx = 0;
    while(true){
        i++;
        xx = xx*10 + 7;
        xx %= n;
        if(xx == 0){
            cout << i << endl;
            return;
        }

        if(vis[xx] != 0)
            break;

        vis[xx] = 1;
    }

    cout << -1 << endl;




}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    fio
//    precompute();

    int t=1;
    if(imp) cin>>t;
    tt = clock();
    while(t--)
    {
        // cout<<"Case #"<<tc<<": ";
        g.clear();
        vis.clear();
        solve();
        // tc++;
    }
//    run_time;

}

Measured memory_bytes: 42524
#include <bits/stdc++.h>
#define f(a, n) for (int a=0; a<n; a++)
#define F(a, n) for (int a=1; a<=n; a++)
using namespace std;

int r, c, n;

int lin(int x, int y){
	if (x != 0 && x != c && y != 0 && y != r) return -1;
	if (x == 0) return y;
	if (y == r) return r + x;
	if (x == c) return r+c+(r-y);
	return r+c+r+c-x;
}

int main(){
	cin>>c>>r>>n;
	vector<pair<int, int>> V;
	f(i, n){
		int a, b, c, d, e, f;
		cin>>a>>b>>c>>d;
		e = lin(a, b), f = lin(c, d);
		if (e == -1 || f == -1) continue;
		V.push_back({e, i});
		V.push_back({f, i});
	}
	sort(V.begin(), V.end());
	stack<int> S;
	S.push(-1);
	for (auto x: V){
		int y = x.second;
		if (S.top() != y) S.push(y);
		else S.pop();
	}
	if (S.size() == 1) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <bitset>
using namespace std;
int dec2bin(long k, bitset<32>& b)
{
	int i = 0;
	int a = k;
	while ( a != 0 ){
		if( a % 2 == 1)
			b.set(i);
		a /= 2;
		++i;
	}
	return i;
}
int main()
{
	long long n, m, c;
	cin >> m >> n;
	bitset<32> nbin;
	int k = dec2bin(n, nbin);
	long long M[32] = {};
	M[0] = m;
	for(int i = 1; i < k; ++i)
		M[i] = (M[i-1] * M[i-1]) % 1000000007;
	c = 1;
	for(int i = 0; i < k; ++i){
		if(nbin[i]){
			if(0 == i)	c = M[0];
			else		c = ( c * M[i] ) % 1000000007;
		}
	}
	cout << c << "\n";
	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        char N = scanner.next().toCharArray()[0];
        if(N >= 'a' && N <= 'z') {
            System.out.println('a');
            return;
        }
        System.out.println('A');

    }
}


Measured memory_bytes: 35776
<?php
function f($s, $arr) {
  $res = 0;
  for ($i = 0; $i < strlen($s); $i++) {
    foreach ($arr as $key => $value) {
      if ($s[$i] == $key) {
        if ($i > 0 && is_numeric($s[$i - 1])) {
          $res += $value * $s[$i - 1];
        } else {
          $res += $value;
        }
      }
    }
  }
  return $res;
}

fscanf(STDIN, "%d", $n);

while ($n--) {
  fscanf(STDIN, "%s %s", $s1, $s2);
  
  $arr = array('m' => 1000, 'c' => 100, 'x' => 10, 'i' => 1);
  $sum = f($s1, $arr) + f($s2, $arr);
  
  $arr_f = array_flip($arr);
  $ans = "";

  foreach ($arr_f as $key => $value) {
    if ($sum >= $key) {
      $ans .= (int)($sum / $key) . $value;
      $sum %= $key;
    }
  }

  $ans = str_replace("1", "", $ans);

  print $ans . "\n";
}

Measured memory_bytes: 6684
n = int(input())
L = list(map(int, input().split()))

L.sort()

if n <= 2:
    print(0)
    exit()

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if L[i] == L[j] or L[i] == L[k] or L[j] == L[k]:
                continue
            if L[k] < L[i]+L[j]:
                ans += 1
print(ans)


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}   


vector<vector<ll>> a(10001);//辺(添え字は始点、値は終点)
vector<ll> m(10000);//訪問したかどうか
void dfs(ll k, ll p, ll q){
  m[k]=1;
  for(ll i=0;i<a[k].size();i++){
    if(m[a[k][i]]==0&&(k!=p||a[k][i]!=q)&&(k!=q||a[k][i]!=p)){
      dfs(a[k][i],p,q); 
    }
  }
}


int main(){
  ll i,j,o;
  ll result=0,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll> p(k),q(k);
  for(i=0;i<k;i++){
    cin>>p[i]>>q[i];
    a[p[i]].push_back(q[i]);
    a[q[i]].push_back(p[i]);
  }
  for(i=0;i<k;i++){
    fill(ALL(m),0);
    dfs(p[i],p[i],q[i]);
    result+=m[q[i]];  
  }
  cout<<k-result<<endl;
  


  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

void disp_stone(vector<vector<char> > s, int H, int W){
	cerr << endl;
	rep (i, H){
		rep (j, W){
			cerr << s[i][j];
		} // end rep
		cerr << endl;
	} // end rep
}

// 落ちきった状態を作り出す
vector<vector<char> > all_fall(vector<vector<char> > s, int H, int W){
	vector<vector<char> > t = s;
//	disp_stone(t, H, W);
	while(true){
		bool update = false;
		for (int i = 0; i < H-1; ++i){
			for (int j = 0; j < W; ++j){
				if (t[i][j] != '0' && t[i+1][j] == '0'){
					swap(t[i][j], t[i+1][j]);
					update |= true;
					break;
				} // end if
			} // end for
			if (update) break;
		} // end for
		if (!update) break;
	} // end while
//	disp_stone(t, H, W);
	
	return t;
}

// 消滅する状態を作り出す
int disappearing(vector<vector<char> > &s, int H, int W, int K){
	int score = 0;
	for (int i = 0; i < H; ++i){
		int left = 0, right = 0;
		while(right < W){
			while (s[i][left] == s[i][right]){
				++right;
			} // end while
			if (right - 1 - left + 1 >= K){
				score += (right - 1 - left + 1)*(int)(s[i][left] - '0');
				for (int j = left; j < right; ++j){
					s[i][j] = '0';
				} // end for
			} // end if
			left = right;
		} // end while
	} // end for
	
	return score;
}

// 状態が変化しなくなるまでシミュレーション
int smulate(vector<vector<char> > s, int H, int W, int K){

	vector<vector<char> > t;
	int score = 0;
	for(int i = 0;; ++i){
		t = all_fall(s, H, W);
		if (t == s) break;
		score += (1<<i) * disappearing(t, H, W, K);
		s = t;		
	} // end for
	
	return score;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int H, W, K; cin >> H >> W >> K;
	vector<vector<char> > stones(H, vector<char>(W, 0));
	rep (i, H){
		rep (j, W){
			cin >> stones[i][j];
		} // end rep
	} // end rep

	int res = 0;
	rep (i, H){
		rep (j, W){
			vector<vector<char> > s = stones;
			s[i][j] = '0';
			int curr = smulate(s, H, W, K);
			res = max(res, curr);
		} // end rep
	} // end rep

	cout << res << endl;

	return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto x : v) cerr << x << ' '; cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, k, r, s, p;
	string t;
	cin >> n >> k >> r >> s >> p >> t;

	vector<bool> win(n);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (i < k || t[i-k] != t[i] || !win[i-k]) {
			if (t[i] == 'r') { // paper
				//cout << "paper" << endl;
				ans += p;
			}
			else if (t[i] == 's') { // rock
				//cout << "rock" << endl;
				ans += r;
			}
			else {
				//cout << "scissors" << endl;
				ans += s;
			}
			win[i] = true;
		}
		else {
			//cout << "nopoint" << endl;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 512
n, m = map(int, input().split())
p = 2 ** n
inf = 10 ** 9
dp = [inf] * p
dp[0] = 0
for i in range(m):
  a, b = map(int, input().split())
  c = sum([2 ** (int(j) - 1) for j in list(input().split())])
  for k in range(p):
    if dp[k|c] > dp[k] + a:
      dp[k|c] = dp[k] + a
      
if dp[-1] == inf:
  print(-1)
else:
  print(dp[-1])

Measured memory_bytes: 3188
#include <iostream>
#include <vector>

int main() {
  std::string S;
  std::cin >> S;
  
  bool even = false;
  for (auto &&c : S) {
    if ((even && (c == 'R')) || (!even && (c == 'L'))) {
      std::cout << "No" << std::endl;
      return 0;
    }
    even = !even;
  }
  std::cout << "Yes" << std::endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        while (scanner.hasNext()) {
           int d = scanner.nextInt();
           int sum = 0;
           
           for (int i = 0; i < (600-d)/d; i++) {
               sum += d * ((i+1)*d *(i+1)*d);
           }
           System.out.println(sum);
        }
    }
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int n; cin >> n;
    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; i++) {
        int x, l; cin >> x >> l;
        p[i] = make_pair(x + l, x - l);
    }

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

    int ans = 0;
    for (int i = 0; i < n; i++) {
        static int cur = -inf;
        if (p[i].second >= cur) {
            ans++;
            cur = p[i].first;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<utility>
#include<cstring>

typedef std::pair<int, int> P;

int n;
int sq[15][15];

int main()
{
	while( std::cin >> n, n )
	{
		memset( sq, 0, sizeof( sq ) );

		P p = P( n / 2, n / 2 + 1 );

		int cnt = 1;
		while( true )
		{
			if( cnt == n * n + 1 )
				break;

			int x = p.first, y = p.second;

			sq[y][x] = cnt;

			int nx = ( x + 1 ) % n, ny = ( y + 1 ) % n;
			if( sq[ny][nx] )
				p = P( ( nx - 1 + n ) % n, ( ny + 1 ) % n );
			else
				p = P( nx, ny );

			++cnt;
		}

		for( int i = 0; i != n; ++i )
		{
			for( int j = 0; j != n; ++j )
				std::cout << std::setw( 4 ) << std::right << sq[i][j];

			std::cout << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1168
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		var A = new List<long>();
		string[] str = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			A.Add(long.Parse(str[i]));
		}
		A.Sort((x,y)=>x.CompareTo(y));
		long ans = 0;
		var list = new List<long[]>();
		int c1 = 0;
		int c2 = N-1;
		while(N>=2){
			int f = 0;
			if(N>=3){
				if(Math.Abs(A[c1+1])>Math.Abs(A[c2-1])){
					if(A[c1+1]>0){
						f = 1;
					} else {
						f = -1;
					}
				} else {
					if(A[c2-1]>0){
						f = 1;
					} else {
						f = -1;
					}
				}
				if(f==1){
					long a = A[c1]-A[c2];
	                list.Add(new long[2]{A[c1],A[c2]});
					c2--;
					A[c1] = a;
				} else {
					long a = A[c2]-A[c1];
	                list.Add(new long[2]{A[c2],A[c1]});
					c1++;
					A[c2] = a;
				}
				N--;
			} else {
				ans = A[c2]-A[c1];
				list.Add(new long[2]{A[c2],A[c1]});
				N--;
			}
		}
		Console.WriteLine(ans);
		for(var i=0;i<list.Count;i++){
			Console.WriteLine(list[i][0]+" "+list[i][1]);
		}
	}
}

Measured memory_bytes: 36056