akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

signed main(){
	ll n, W;
	scanf("%lld %lld", &n, &W);
	vector<ll> w(n), v(n);
	scanf("%lld %lld", &w[0], &v[0]);
	vector<vector<ll> > data(4);
	data[0].push_back(v[0]);
	for(int i = 1; i < n; i++){
		scanf("%lld %lld", &w[i], &v[i]);
		data[w[i] - w[0]].push_back(v[i]);
	}
	for(int i = 0; i < 4; i++){
		sort(data[i].begin(), data[i].end(), greater<ll>());
		for(int j = 0; j < data[i].size(); j++){
			if(j == 0) continue;
			data[i][j] += data[i][j - 1];
		}
	}
	ll ans = 0;
	for(int x0 = 0; x0 <= data[0].size(); x0++){
		for(int x1 = 0; x1 <= data[1].size(); x1++){
			for(int x2 = 0; x2 <= data[2].size(); x2++){
				for(int x3 = 0; x3 <= data[3].size(); x3++){
					if(x0 + x1 + x2 + x3 > n) continue;
					if(w[0] * x0 + (w[0] + 1) * x1 + (w[0] + 2) * x2 + (w[0] + 3) * x3 > W) continue;
					ll ans1 = 0;
					if(data[0].size() && x0) ans1 += data[0][x0 - 1];
					if(data[1].size() && x1) ans1 += data[1][x1 - 1];
					if(data[2].size() && x2) ans1 += data[2][x2 - 1];
					if(data[3].size() && x3) ans1 += data[3][x3 - 1];
					ans = max(ans, ans1);
				}
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;
	int ans=0;
	for (int i=1;i<=n;i++)
	{
		int flag=0;
		for (int j=1;j<=i;j++)
		if (i%j==0) flag++;
		if (i%2==0) flag=0;
		if (flag==8) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
/*

A：1...n
B：1...n


*/
#include<bits/stdc++.h>
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const ll MAXN=1e6+5;
const ll INF=1e18;
const ll MOD=1e9+7;
ll n,m,mypow[20],a[MAXN];
multiset<ll,greater<ll> >ms[MAXN];
void init()
{
    mypow[0]=1;
    for(ll i=1;i<=20;i++)
    {
        mypow[i]=mypow[i-1]*2;
    }
}
void setunion(ll j,ll i)
{
    for(auto it=ms[i].begin();it!=ms[i].end();it++)
    {
        ms[j].insert(*it);
    }
}
bool addable(ll j,ll i)
{
    return (j&(1<<i))==0;
}
void refine(ll x)
{
    while(ms[x].size()>2)
    {
        ms[x].erase(--ms[x].end());
    }
}
void solve()
{
    for(ll i=0;i<m;i++)
    {
        ms[i].insert(a[i]);
    }

    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
            if(addable(j,i))
            {
                setunion(j|(1<<i),j);
                refine(j|(1<<i));
            }
        }
    }
    ll pre=0;
    for(ll i=1;i<m;i++)
    {
        pre=max(pre,(*ms[i].begin())+(*(++ms[i].begin())));
        printf("%lld\n",pre);
    }

}
int main()
{
    init();
    scanf("%lld",&n);
    m=mypow[n];
    for(ll i=0;i<m;i++)
    {
        scanf("%lld",&a[i]);
    }
    solve();
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n;
vll a;

void error(){
  cout << -1 << endl;
  exit(0);
}

lli ans;

int main(){
  cin >> n;
  a = vll(n+1);
  for(lli i = 1;i <= n;i++) cin >> a[i];
  a.push_back(0);
  a[0] = -1;
  for(lli i = 1;i <= n+1;i++){
    if(a[i] <= a[i-1]) ans += a[i-1];
    if(a[i] > a[i-1]+1) error();
  }
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string str;
    cin >> str;
    
    int n = SZ(str);
    string str2 = str;
    
    int al[26] = {0};
    int maxk, maxv = 0;
    rep(i, SZ(str)) al[str[i] - 'a']++;
    rep(i, 26) if (al[i] > maxv) { maxk = i; maxv = al[i]; }
    if (maxv == SZ(str)) { out(0); return 0; }
    
    // out(maxk << " " << maxv);
    // rep(i, 26) cout << al[i] << " " << (char)('a' + i) << endl;
    
    int ans = inf;
    rep(i, 26) {
        if (al[i] == 0) continue;
        str = str2;
        while (1) {
            string tt;
            int flg = 0;
            char tmp = 'a' + i;
            rep(i, SZ(str) - 1) {
                tt += (str[i] == tmp || str[i + 1] == tmp ? tmp : str[i]);
                if (tt[i] != tmp) flg = 1;
            }
            str = tt;
            // out(str);
            if (flg == 0) break;
        }
        chmin(ans, n - SZ(str));
    }
    
    
    
    out(ans);
}


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,a,n) for(int i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;

const int INF=1<<30;
const ll LINF = 1e18+5;

int main() {
    int N;
    cin >> N;
    string str;
    cin >> str;
    int ans = 0;
    rep(i, 10) {
        rep(j, 10) {
            rep(k, 10){
                int searching = 0;
                rep(l, N) {
                    if(searching == 0 && str[l] - '0' == i) {
                        searching = 1;
                    }else if(searching == 1 && str[l] - '0' == j) {
                        searching = 2;
                    }else if(searching == 2 && str[l] - '0' == k) {
                        searching = 3;
                        break;
                    }
                }
                if (searching == 3) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

namespace ABC083
{
    class B
    {
        static void Main(string[] args)
        {
            var NAB = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var N = NAB[0];
            var A = NAB[1];
            var B = NAB[2];
            var res = 0;
            for (int i = 1; i <= N; i++)
            {
                var n = i;
                var sum = n % 10;
                while ((n /= 10) != 0)
                    sum += n % 10;

                if (A <= sum && sum <= B) res += i;
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13268
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define MN 1000
int n,a[MN+5],q[MN+5],qn;
vector<int> ans;
int main()
{
	int i,j;long long s1=0,s2=0;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",&a[i]);
	for(i=j=1;i<=n;++i)if(a[i]>a[j])j=i;
	if(a[j]<=0)
	{
		printf("%d\n",a[j]);
		printf("%d\n",n-1);
		for(i=n;i>j;--i)printf("%d\n",i);
		for(i=1;i<j;++i)puts("1");
		return 0;
	}
	for(i=1;i<=n;++i)if(a[i]>0)(i&1?s1:s2)+=a[i];
	printf("%lld\n",max(s1,s2));
	for(i=s1>s2?1:2;i<=n;i+=2)if(a[i]>0)q[++qn]=i;
	while(q[1]>1){ans.push_back(1);for(i=1;i<=qn;++i)--q[i];--n;}
	while(q[qn]<n)ans.push_back(n--);
	while(qn>1)
	{
		while(q[2]>3)
		{
			ans.push_back(3);
			for(i=2;i<=qn;++i)q[i]-=2;
		}
		ans.push_back(2);
		for(i=1;i<qn;++i)q[i]=q[i+1]-2;--qn;
	}
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();++i)printf("%d\n",ans[i]);
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long ans = 0;

        if (n %2 != 0) {
            System.out.println(0);
            return;
        }

        long denominator = 10;
        while (n >= denominator) {
            ans += n/denominator;
            denominator *= 5;
        }

        System.out.println(ans);
    }
}



Measured memory_bytes: 23252
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll x, y;
    cin >> x >> y;

    rep(i, x + 1){
        ll x2 = i;
        ll x4 = x - i;

        ll ytemp = x2 * 2 + x4 * 4;
        if(ytemp == y){
            cout << "Yes" << endl;
            return 0;
        }
    }    

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3636
from math import radians, sin, cos, sqrt
EPS = 1e-10

n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for theta in range(0, 3600):
	e = (cos(radians(theta/10)), sin(radians(theta/10)))
	resx, resy = 0, 0
	for x, y in d:
		if x*e[0] + y*e[1] >= EPS:
			resx += x
			resy += y
	ans = max(ans, sqrt(resx**2 + resy**2))
print(ans)

Measured memory_bytes: 41452
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    long long X;
    int A, B;

    cin >> X;

    for (int i=-1000; i < 1000; i ++)
        for (int j=-1000; j < 1000; j++)
            if (pow(i, 5) - pow(j, 5) == X) {
                A = i;
                B = j;
            }
                

    cout << A << " " << B << endl;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,i;
	t = 1;
	while(t--) {
	 int arr[3];
	 for(i = 0; i < 3; i++)
	  cin >> arr[i];
	 sort(arr, arr + 3);
	 cout << arr[0] + arr[1] << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;

    vector<int>v(n);
    for (int i=0;i<n;i++) {
        cin>>v[i];
    }
    vector<int>c(n);
    for (int i=0;i<n;i++) {
        cin>>c[i];
    }

    int answer=0;

    for (int i=0;i<n;i++) {
        if(v[i]-c[i]>0){
            answer+=v[i]-c[i];
        }
    }

    cout<<answer<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
const int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
const int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;

const ll MI = -ll(1e18);
int main()
{
    vector<ll> a(2), b(2);
    rep(i,2) cin >> a[i];
    rep(i,2) cin >> b[i];
    ll ans = MI;
    rep(i,2) rep(j,2) {
        chmax(ans, a[i] * b[j]);
    }
    if ((a[0]<=0 && a[1]>=0)
        || (b[0]<=0 && b[1]>=0)) chmax(ans, 0ll);

    // if (b < 0) {
    //     if (d < 0) ans = a * c;
    //     else if (c >= 0) ans = b * c;
    //     else ans = 0;
    // }
    // else if (a >= 0){
    //     if (d < 0) ans = a * d;
    //     else if ()
    // }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3612
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 100000
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

//int G[MAX][MAX];
vector<int> G[MAX], colors(MAX, -1);


int bfs_colors(){
    queue<Pii> que;
    que.push(Pii(0, 0));
    while(!que.empty()){
        Pii p = que.front(); que.pop();
        if(colors[p.first] != -1){
            if(colors[p.first] != p.second){
                return 1;
            }else{
                continue;
            }
        }
        colors[p.first] = p.second;
        for(int next: G[p.first]){
            que.push(Pii(next, 1-p.second));
        }
    }
    return 0;
}


signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m, from, to;
    cin >> n >> m;
    rep(m){
        cin >> from >> to;
        from--; to--;
        G[from].pb(to);
        G[to].pb(from);
    }

    int loop_flag = bfs_colors();
    if(loop_flag){
        cout << (ll)n * (ll)(n-1) / 2 - (ll)m;
    }else{
        ll red = count(all(colors), 0);
        ll black = (ll)n - red;
        cout << red * black - (ll)m;
    }
    return 0;
}


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

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;

  for (int i = 0; i < S.length(); i++) {
    if ((i < A && S[i] == '-') || (i == A && S[i] != '-') ||
        (i > A && S[i] == '-')) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");
}

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

struct UnionFind{
    vector<int> data;

    UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);//親は負でサイズを保存
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  bool same(int x, int y){
      return find(x) == find(y);
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
  int n, m;
  cin >> n >> m;
  vector<P> edge;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a,--b;
    edge.push_back({a,b});
  }
  int res = 0;
  rep(i,m) {
    UnionFind uf(n);
    rep(j,m) {
      if(i == j)continue;
      uf.unite(edge[j].first,edge[j].second);
    }
    if(!uf.same(edge[i].first,edge[i].second)) res++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder{
    class Inonoa{
        static void Main(){
            long[] nmp = ILongs();
            long n = nmp[0];
            long m = nmp[1];
            long p = nmp[2];

            long[][] abcs = ILongLongs(m);

            const long LMAX = long.MaxValue;

            long[] cost = new long[n];
            bool[] tootta = new bool[n];
            cost[0] = 0;
            tootta[0] = true;
            for(int i=1;i<n;i++){
                cost[i] = LMAX;
            }

            for(int i=0;i<n-1;i++){
                foreach(long[] abc in abcs){
                    if(tootta[abc[0]-1] && cost[abc[1]-1] > cost[abc[0]-1] + p - abc[2]){
                        cost[abc[1]-1] = cost[abc[0]-1] + p - abc[2];
                        tootta[abc[1]-1] = true;
                    }
                }
            }

            bool[] toottayo = new bool[n];
            
            foreach(long[] abc in abcs){
                if(tootta[abc[0]-1] && cost[abc[1]-1] > cost[abc[0]-1] + p - abc[2]){
                    toottayo[abc[1]-1] = true;
                }
            }

            for(int i=0;i<n;i++){
                foreach(long[] abc in abcs){
                    if(toottayo[abc[0]-1]){
                        toottayo[abc[1]-1] = true;
                        if(abc[1]-1==n-1){
                            WriteLine(-1);
                            return;
                        }
                    }
                }
            }

            WriteLine(Max(-cost[n-1],0));
        }

        static readonly long MOD = 1000000007;

        ///<summary>a_1, a_2, a_3, ...みたいなの</summary>
        static long[] ILongs(){
            string[] s = ReadLine().Split();
            long[] re = new long[s.Length];
            for(long i=0;i<s.Length;i++){
                re[i] = long.Parse(s[i]);
            }
            return re;
        }

        ///<summary>xooxoxoxxoxo...みたいなの</summary>
        static char[] IChars(){
            return ReadLine().ToCharArray();
        }

        ///<summary>n m とかをちょっとはやくかくだけ</summary>
        static string[] IStrings(){
            return ReadLine().Split();
        }

        ///<summary>n行の入力を取ったり</summary>
        static long[][] ILongLongs(long n){
            long[][] re = new long[n][];
            for(long i=0;i<n;i++){
                string[] s = ReadLine().Split();
                re[i] = new long[s.Length];
                for(long j=0;j<s.Length;j++){
                    re[i][j] = long.Parse(s[j]);
                }
            }
            return re;
        }

        ///<summary>n行の文字列を取ったり</summary>
        static char[][] ICharsChars(long n){
            char[][] re = new char[n][];
            for(long i=0;i<n;i++){
                re[i] = ReadLine().ToCharArray();
            }
            return re;
        }
    }
}

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

int main(){


	int n;
	bool ans=false;
	cin>>n;
	while(n){
		if(n%10==7){
			ans=true;
			break;
		}
		n=n/10;
	}
	if(ans) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
 
#define INF_LL 1e18
#define INF 1e9
 
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
 
using namespace std;
 
using ll = long long;
using PII = pair<int, int>;
 
class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;
 
public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}
 
	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}
 
	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
 
		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}
 
	bool same(int x, int y){
		return find(x) == find(y);
	}
};
 
ll mod = 1e9+7;
 
ll powm(ll x, ll a){
	ll res = 1;
	REP(i, a){
		res = (res * x) % mod;
	}
	return res;
}
 
int main(void){
	int N;
	int a[100010] = {};
	vector<int> v;
	ll res = 0;
	cin >> N;
	REP(i, N){
		int c;
		cin >> c;
		a[c]++;
		res++;
	}
	
	ll abo_n = 0;
	REP(i, 100010){
		if(a[i] > 1) 
			abo_n += a[i]-1;
	}
	cout << res - abo_n - (abo_n%2) << endl;
}


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

int GetDigit(int num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(void){
  int n;
  cin >> n;
  
  int ans = 0;
  
  for (int i = 1; i <= n; i++) {
    if (GetDigit(i) % 2 == 1) {
      ans++;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

using namespace std;

int main(){

    int x;
    cin >> x;

    cout << ( (x == 7 || x == 5 || x == 3) ? "YES" :"NO") << endl;


    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
	int A, B;
	cin >> A >> B;
	if (A > 8 || B > 8) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
     int a,b,c=0,i;
     scanf("%d %d",&a,&b);
     if(a==b){
         c=a+b;
     }

     else if(a>b){
     for(i=0;i<2;i++){
         c=c+a;
         a=a-1;
     }
          }

     else if(b>a){
     for(i=0;i<2;i++){
         c=c+b;
         b=b-1;
     }
          }
       printf("%d\n",c);

}


Measured memory_bytes: 1732
n = int(input())
ab = [[0,0] for i in range(n)]
cd = [[0,0] for i in range(n)]
for i in range(n):
    ab[i] = map(int, input().split())

for i in range(n):
    cd[i] = map(int, input().split())

for i in range(n):
    ab[i] = tuple(ab[i])
    cd[i] = tuple(cd[i])

#print(ab)

ab.sort(key=lambda coordinates:coordinates[1]*(-1))
#print(ab)

#print(cd)
cd.sort()
#print(cd)

count = 0
i=0
j=0

while len(cd) > 0:
    flag = 0
    for j in range(len(ab)):
        if cd[0][0] > ab[j][0] and cd[0][1] > ab[j][1]:
            flag = 1
            del(cd[0])
            del(ab[j])
            #print("j=",j)
            #print("ab=",ab)
            #print("cd=",cd)
            break
    if flag==0:
        del(cd[0])
    else:
        count += 1

print(count)



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <string.h>
#include <queue>
#include <functional>

#define NMAX 100010
#define MOD 1000000007
#define INF 2000000000
#define PI 3.1415926535
#define EPS 1.e10-6

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) > 0 ? (a) : (-a))

typedef unsigned long long ull;
typedef long long ll;

using namespace std;

struct Pos {
	int x, y;
	int dist;
};

int map[21][21];
int n, m;
int vizMap[21][21];
queue<Pos> Q;
int maxDist;

int dl[] = { -1, 0, 1, 0 };
int dc[] = { 0, 1, 0, -1 };

bool inside(int x, int y)
{
	return (x >= 0 && x < n && y >= 0 && y < m);
}

int main()
{
	cin >> n >> m;
	cin.get();

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			char c;
			cin.get(c);
			if (c == '.')
				map[i][j] = 0;
			else
				map[i][j] = -1;
		}
		cin.get();
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (!map[i][j])
			{
				Pos st = { i, j, 0 };
				Q.push(st);
				vizMap[i][j] = 1;

				while (!Q.empty())
				{
					Pos curr = Q.front();
					Q.pop();
					maxDist = MAX(maxDist, curr.dist);

					for (int k = 0; k < 4; k++)
					{
						int l9 = curr.x + dl[k];
						int c9 = curr.y + dc[k];

						if (inside(l9, c9) && !vizMap[l9][c9] && !map[l9][c9])
						{
							Q.push({ l9, c9, curr.dist + 1});
							vizMap[l9][c9] = 1;
						}
					}
				}

				memset(vizMap, 0, sizeof(vizMap));
			}

	cout << maxDist << '\n';
}


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

using namespace std;

#define int long long int
#define cont continue;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define mp make_pair
#define endl '\n'


typedef vector<int> vi;
typedef set<int> si;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef map<int, int> mi;

//const
#define EPS 1e-9
#define INF LLONG_MAX
const int mod = 1000 * 1000 * 1000 + 7; //1e9+7
const double PI = 3.14159265358979323846264;
const pi steps[] = {{1, 0}, {0, 1}, { -1, 0}, {0, -1}, {1, -1}, {1, 1}, { -1, -1}, { -1, 1}}; //for (auto [dx,dy] : steps)
//const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};

// inputs & output & debug
#define w(t) int t; cin>> t; while(t--)

#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//useful functions
//#define deb(x) cout<<#x<<": "<<x<<endl;
#define isPowOfTwo(x) return (x && (!(x&(x-1))));
#define sz(a) (int)((a).size())
#define present(c,x) ((c).find(x) != (c).end())
#define ip_arr(a,n)   for(int i=0;i<n;i++) cin>>a[i];
#define op_arr(arr,n) for(int i=0;i<n;i++) cout<<arr[i]<<"\n"; cout<<endl;
#define fill_arr(arr,n,i) fill(arr,arr+n,i)
#define fill_vec(v,n,i) fill(v.begin(),v.begin()+n,i);
#define sortv(a) sort(a.begin(),a.end())

void fio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
void setUpLocal()
{
#ifndef ONLINE_JUDGE
	freopen("/Users/asuryana/Documents/CP/input.txt", "r", stdin);
	freopen("/Users/asuryana/Documents/CP/output.txt", "w", stdout);
#else
#define cerr if(0) cerr
#endif
}

const int maxN = 1e5 + 5;
vi gp[maxN];
int vis[maxN];
// int cnt[gp_size];

int dp[maxN];

void dfs(int i)
{
	vis[i] = 1;
	for (int child : gp[i])
	{
		if (!vis[child])
		{
			dfs(child);
		}
		//cerr << i << " " << child << " " << dp[i] << " " << dp[child] << endl;
		dp[i] = max(dp[i], 1 + dp[child]);
	}
}


void solve()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int m, n; cin >> m >> n;
		gp[m].pb(n);
	}

	for (int i = 1; i <= n; i++)
	{
		if (!vis[i])
		{
			dfs(i);
		}
	}

	int ans = 0;

	for (int i = 1; i <= n; i++)
		ans = max(ans, dp[i]);

	cout << ans << endl;

}

int32_t main()
{
	fio();
	//setUpLocal();
	return solve(), 0;
}


Measured memory_bytes: 13268
/* 7min */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                    \
  for (int i = 0; i < (int)(n); i++) \
    ;

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n;

  cin >> n;
  vector<long> l(n + 1, 0);
  l.at(0) = 2;
  l.at(1) = 1;

  for (int i = 2; i <= n; i++) {
    l.at(i) = l.at(i - 1) + l.at(i - 2);
  }

  cout << l.at(n) << endl;
}


Measured memory_bytes: 256
X, Y = map(int, input().split())

if 0 == X or 0 == Y:
	if X < Y:
		print(abs(X - Y))
		exit()
	print(abs(X - Y) + 1)
	exit()

if (X < 0 and 0 < Y) or (Y < 0 and 0 < X):
	print(abs(abs(0 - X) - abs(0 - Y)) + 1)
	exit()

if X < Y:
	print(abs(X - Y))
	exit()

print(abs(X - Y) + 2)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
 
using namespace std;
typedef unsigned long long ulli;
 
const ulli B = 100000007ULL;
 
int n, d;
vector<string> dat;
vector<pair<string, string> > ans;
set<ulli> vis;
 
void init(){
  dat.clear();
  ans.clear();
}
 
ulli getHash(const string &s) {
  ulli res = 0;
  for(int i = 0; i < s.size(); ++i) {
    res = res * B + s[i];
  }
  return res;
}
 
bool calc(const string &s, int x, bool f){
  ulli h = getHash(s);
  if(x >= 1 || (!f && d == x) || (f && d == 1)){
    if(!f){
      vis.insert(h);
    }
    if(f && vis.find(h) != vis.end()){
      return true;
    }
  }else{
    string t;
    //remove
    for(int i=0;i<s.size();i++){
      t.clear();
      for(int j=0;j<s.size();j++){
        if(i == j) continue;
        t.push_back(s[j]);
      }
      if(calc(t, x + 1, f)) return true;
    }
    //add
    for(int i=0;i<=s.size();i++){
      for(int k=0;k<26;k++){
        t.clear();
        for(int j=0;j<s.size();j++){
          if(i == j){
            t.push_back((char)k + 'a');
          }
          t.push_back(s[j]);
          if(i == s.size() && j + 1 == s.size()){
            t.push_back((char)k + 'a');
          }
        }
        if(calc(t, x + 1, f)) return true;
      }
    }
    //change
    for(int i=0;i<s.size();i++){
      for(int k=0;k<26;k++){
        t.clear();
        for(int j=0;j<s.size();j++){
          if(i == j){
            t.push_back((char)k + 'a');
          }else{
            t.push_back(s[j]);
          }
        }
        if(calc(t, x + 1, f)) return true;
      }
    }
    //swap
    t = s;
    for(int i=1;i<s.size();i++){
      swap(t[i-1], t[i]);
      if(calc(t, x + 1, f)) return true;
      swap(t[i-1], t[i]);
    }
  }
  return false;
}
 
main(){
  while(cin >> n && n){
    cin >> d;
    init();
    for(int i=0;i<n;i++){
      string in;
      cin >> in;
      dat.push_back(in);
    }
    sort(dat.begin(), dat.end());
    for(int i=0;i<n;i++){
      vis.clear();
      calc(dat[i], 0, false);
      for(int j=i+1;j<n;j++){
        if(calc(dat[j], 0, true)){
          ans.push_back(make_pair(dat[i], dat[j]));
        }
      }
    }
    for(int i=0;i<ans.size();i++){
      cout << ans[i].first << "," << ans[i].second << endl;
    }
    cout << ans.size() << endl;
  }
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> K;
  A=N/K;
  Out(min(abs(N-A*K),abs(N-(A+1)*K)));
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			StringTokenizer tokenizer = new StringTokenizer(scanner.nextLine()
					);
			int[] num = new int[8];
			for (int i = 0; i < 8; i++) {
				num[i] = Integer.parseInt(tokenizer.nextToken());
			}
			int[] a = { 1, 2, 1, 2, 1, 4, 1, 4 };
			int[] b = { 0, 2, 6, 4, 1, 3, 7, 5 };
			int min = Integer.MAX_VALUE;
			int resut = 0;
			for (int i = 0; i < 8; i++) {
				int sum = 0;
				for (int j = 0; j < 8; j++) {
					int c = a[(j + b[i]) % 8];
					sum += c - num[j] < 0 ? 0 : c - num[j];
				}
				if (min > sum) {
					min = sum;
					resut = i;
				}
			}
			for (int i = 0; i < 8; i++) {
				if (i != 0) {
					System.out.print(" ");
				}
				System.out.print(a[(i + b[resut]) % 8]);
			}
			System.out.println();
		}

	}
}

Measured memory_bytes: 18832
#include<bits/stdc++.h>
using namespace std;
int h,w;
int main(){
    cin>>h>>w;
    char arr[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>arr[i][j];
        }
    }
    vector<vector<long>>dp(h,vector<long>(w,0));
    dp[h-1][w-1]=1;
    for(int i=h-1;i>=0;i--){
        for(int j=w-1;j>=0;j--){
            if(arr[i][j]=='#')continue;
            else{
                if(i+1<h)dp[i][j]=dp[i+1][j];
                if(j+1<w)dp[i][j]=(dp[i][j]+dp[i][j+1])%1000000007;
            }
        }
    }
    cout<<dp[0][0];
    return 0;
}

Measured memory_bytes: 11916
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a * b % 2 == 0) {
			System.out.println("Even");
		} else {
			System.out.println("Odd");
		}
	}
}


Measured memory_bytes: 22612
#include <stdio.h>
int main()
{
	int i,j,x,y,box,a[100000][2];
	while(1){
		scanf("%d %d",&a[i][0],&a[i][1]);
		if(a[i][0]==0 && a[i][1]==0)
			break;
		if(a[i][0]>a[i][1]){
			box=a[i][0];a[i][0]=a[i][1];a[i][1]=box;
		}
		i++;
	}
	for(j=0;j<i;j++)
		printf("%d %d\n",a[j][0],a[j][1]);
	return 0;
}

Measured memory_bytes: 616
#include<cstdio>
#define ll long long
using namespace std;
ll k,ans;
ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}
int main(){
	scanf("%lld",&k);
	for(ll i=1;i<=k;i++){
		for(ll j=1;j<=k;j++){
			for(ll ij=1;ij<=k;ij++){
				ll ans1=gcd(i,j);
				ll ans2=gcd(ans1,ij);
				ans+=ans2;
			}
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3228
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
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...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int n,d;

main(){
	cin>>n>>d;
	dump((n+2*d)/(2*d+1));
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    char[] S = scanner.next().toCharArray();
    char[] T = scanner.next().toCharArray();
    String min = null;
    for (int i = 0; i < S.length; i++) {
      if (match(S, T, i)) {
        char[] s = new char[S.length];
        for (int j = 0; j < i; j++) {
          if (S[j] == '?') s[j] = 'a';
          else s[j] = S[j];
        }
        for (int j = 0; j < T.length; j++) s[i + j] = T[j];
        for (int j = i + T.length; j < S.length; j++) {
          if (S[j] == '?') s[j] = 'a';
          else s[j] = S[j];
        }
        String ss = new String(s);
        if (min == null || min.compareTo(ss) > 0) min = ss;
      }
    }
    if (min == null) System.out.println("UNRESTORABLE");
    else {
      System.out.println(min);
    }
  }

  private static boolean match(char[] s, char[] t, int p) {
    if (p + t.length > s.length) return false;
    for (int i = 0; i < t.length; i++) {
      if (s[p + i] != '?' && s[p + i] != t[i]) return false;
    }
    return true;
  }
}


Measured memory_bytes: 21588
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

struct Query {
  int b;
  int c;

  Query(int b, int c) {
    this->b = b;
    this->c = c;
  }

  bool operator>(const Query &q) const {
    return c < q.c;
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue <int, vector<int>, greater<int>> pque;

  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;

    pque.push(a);
  }

  priority_queue <Query, vector<Query>, greater<Query>> queryList;

  for (int i = 0; i < M; ++i) {
    int b, c;
    cin >> b >> c;

    queryList.push(Query(b, c));
  }

  while (!queryList.empty()) {
    Query q = queryList.top();
    queryList.pop();

    for (int i = 0; i < q.b; ++i) {
      if (pque.top() >= q.c) break;

      int v = pque.top();
      pque.pop();

      pque.push(q.c);
    }
  }

  ll ans = 0;

  while (!pque.empty()) {
    int v = pque.top();
    pque.pop();
    ans += v;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define int 		long long
#define endl 		"\n"
#define mod 		1000000007
#define inf 		1e12
#define IOS 		ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)


int32_t main() {

	IOS;

	int n, x, t;
	cin >> n >> x >> t;

	cout << ((n - 1) / x + 1) * t;

	return 0;

}

Measured memory_bytes: 3648
function main(input) {
  const formatted_input = input.split('\n');

  const N = parseInt(formatted_input[0], 10);
  const As = formatted_input[1].split(' ').map(x => parseInt(x));
  var edited_As = []
  var minus = As.filter(x => x<=0);
  var abs = As.map(x => Math.abs(x))
  var result = 0;
  for(var i=0;i<N;i++){
    var tmp = As[i];
    if(tmp<0){tmp = tmp*-1;}
    result += tmp;
  }

  if(minus.length%2==1){
    var min_value = Math.min(...abs);
    result = result - 2*Math.abs(min_value);
  }

  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));




Measured memory_bytes: 31792
#include <iostream>
using namespace std;
int main(void){
	long long int H,W;
  	
	std::cin >> H;
  	std::cin >> W;
 
 	if(H==1 || W==1){
	  	std::cout << 1;
    }else{
	  	std::cout << (long long int)((H*W+1)/2);
    }
  
    return 0;
}


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

a = []
cnt = 0

# a[0] = [7 % K]
a.append(7 % K)

for i in range(K):
    # a[i+1] = [(a[i]*10 + 7) % K]
    a.append((a[i]*10 + 7) % K)

for j in range(K):
    if a[j] == 0:
        cnt = 1
        break

if cnt == 0:
    print('-1')
else:
    print(j+1)



Measured memory_bytes: 48540
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
using boost::multiprecision::integer_modulus;
using namespace std;

int main() {
  int N, A, mod = 1e9+7;
  cin >> N >> A;
  cpp_int B = 1, lcm = A;
  while (cin >> A) {
    int gcd = __gcd(integer_modulus(lcm, A), A);
    lcm *= A / gcd;
    (B *= (A / gcd)) += lcm / A;
  }
  cout << integer_modulus(B, mod) << "\n";
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int month;
	int day;
	int i;
	int sum_day;
	int youbi;
	
	while (1){
		sum_day = 0;
		scanf("%d %d", &month, &day);
		if (month == 0){
			break;
		}
		for (i = 1; i < month; i++){
			switch (i){
				case 1:
				case 3:
				case 5:
				case 7:
				case 8:
				case 10:
				case 12:
				 sum_day += 31;
				break;
				
				case 2:
				  sum_day += 29;
				break;
				
				case 4:
				case 6:
				case 9:
				case 11:
				  sum_day += 30;
				break;
			}
		}
		sum_day += day;
		
		youbi = sum_day % 7;
		
		switch (youbi){
			case 1:
			  printf("Thursday\n");
			break;
			
			case 2:
			  printf("Friday\n");
			break;
			
			case 3:
			  printf("Saturday\n");
			break;
			
			case 4:
			  printf("Sunday\n");
			break;
			
			case 5:
			  printf("Monday\n");
			break;
			
			case 6:
			  printf("Tuesday\n");
			break;
			
			case 0:
			  printf("Wednesday\n");
			break;
		}
	}
	
	return (0);
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define prdb(pranay) cout << fixed << setprecision(10) << pranay;
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    speed;
    ll n, m;
    cin >> n >> m;

    ll i, j, k;
    vector<vector<ll>> adj(n + 1);
    for (i = 0; i < m; i++)
    {
        cin >> j >> k;
        adj[j].push_back(k);
        adj[k].push_back(j);
    }
    vector<bool> vis(n + 1, false);
    ll cnt = 0;
    for (i = 1; i <= n; i++)
    {
        if (!vis[i])
        {
            list<ll> l;
            l.push_back(i);
            vis[i] = true;
            while (!l.empty())
            {
                ll node = l.front();
                l.pop_front();
                for (auto nei : adj[node])
                {
                    if (!vis[nei])
                        l.push_back(nei), vis[nei] = true;
                }
            }
            cnt++;
        }
    }
    cout << cnt - 1 << endl;
}


Measured memory_bytes: 9536
#include <cstdio>
#include <set>
#include <queue>
#include <algorithm>

#define ff(i,a,b) for (int i=(a);i<=(b);i++)
using namespace std;
typedef long long ll;
typedef set<int> sI;
const int N=2e5+10;
int n,a[N],b[N];
queue<sI*> Q;

int main() {/*
    freopen("9.inp","r",stdin); freopen("9.out","w",stdout); //*/
    scanf("%d",&n); ff(i,1,n) scanf("%d",&a[i]);
    copy(a+1, a+n+1, b+1); sort(b+1, b+n+1);
    ff(i,1,n) {
        sI *s = new sI; s->insert(a[i]);
        Q.push(s);
    }
    ll ans=0ll;
    for (int i=1; i<=n; i++) {
        sI* ps=Q.front(); Q.pop();
        while (ps->count(b[i])==0) {
            sI *t=Q.front(); Q.pop();
            for (sI::iterator it=t->begin(); it!=t->end(); it++) {
                ps->insert(*it);
            }
            t->clear();
        }
        ps->erase(b[i]);
        ans += (int)ps->size();
        Q.push(ps);
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 34728
#include <bits/stdc++.h>
using namespace std;
long long n,x,a[2010],b[2010],ans,tmp;
int main(){
    scanf("%lld%lld",&n,&x);
    for(int i=0;i<n;i++)scanf("%lld",&a[i]);
    ans=1e14;memset(b,0x3f,sizeof(b));
	for(int i=0;i<n;i++){
        tmp=0;for(int j=1;j<=n;j++)b[j]=min(b[j],a[(j-i+n)%n]),tmp+=b[j];
        ans=min(ans,i*x+tmp);
    }printf("%lld\n",ans);
}

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

int main()
{
  int n,sum;
  sum=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a.at(i);
    sum+=a.at(i);
  }
  cout<<sum-n<<endl;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int64 D;
int64 ten[19] = {};

int64 dfs(int64 L, int64 d, int64 rest) {
//  cout << L << " " << d << " " << rest << endl;
  if (L/2 <= d) {
    return (rest==0)*(L % 2 ? 10 : 1);
  }
  int64 x = ten[L-d-1] -ten[d];
  vector<PLL> kouho(19);
  FOR(dd, -9, 10) {
    kouho[dd+9] = PLL(x*dd, dd);
  }
  sort(all(kouho));
  int64 idx = lower_bound(all(kouho), PLL(rest, -INF_LL)) - kouho.begin();
  int64 res = 0;
  if (idx < kouho.size()) {
    res += dfs(L, d + 1, rest - kouho[idx].sc * x) * (10 - abs(kouho[idx].sc) - (d == 0 && kouho[idx].fs >= 0));
//    cout << L << " " << d << " " << rest << " " << kouho[idx].sc << " " << x << endl;
  } if (idx > 0) {
    res += dfs(L, d + 1, rest - kouho[idx - 1].sc * x) * (10 - abs(kouho[idx - 1].sc) - (d == 0 && kouho[idx].fs >= 0));
//    cout << L << " " << d << " " << rest << " " << kouho[idx-1].sc << " " << x << endl;
  }
  return res;
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> D;
	int64 dd = log10(D)+1;
	int64 res = 0;
	ten[0] = 1;
	REP(i, 18) {
	  ten[i+1] = ten[i] * 10;
	}
	FOR(i, dd, 2*dd+1) {
	  res += dfs(i, 0, D);
	}
	cout << res << endl;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()
#define TST(H) (#H);

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll x, k, d;
	cin >>x >>k >>d;
	ll ans =0;
	x = abs(x);
	
	ll su = x/d;
	if(su >= k){
		cout << abs(x - d * k) <<"\n";
		return 0;
	}
	
	x = x - d*su;
	k -=su;
	//dbg(x,k);
	if(k%2){
		x -= d;
		x=abs(x);
	}
	cout << x <<"\n";
	return 0;
}



Measured memory_bytes: 3648