akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;


int main(int argc, char *argv[]) {
	int n, u, v;
	cin >> n >> u >> v;
	unordered_map<int, unordered_set<int>> um;
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		um[a].insert(b);
		um[b].insert(a);
	}
	unordered_map<int, int> du, dv;
	unordered_map<int,int > du_last, dv_last;
	vector<int> v1, v2;
	v1.push_back(u);
	du[u] = 0;
	while (v1.size() > 0) {
		v2.clear();
		for (auto vv : v1) {
			for (auto next : um[vv]) {
				if (du.find(next) == du.end()) {
					du[next] = du[vv] + 1;
					v2.push_back(next);
					du_last[next] = vv;
				}
			}
		}
		v1 = v2;
	}

	v1.clear();
	v1.push_back(v);
	dv[v] = 0;
	while (v1.size() > 0) {
		v2.clear();
		for (auto vv : v1) {
			for (auto next : um[vv]) {
				if (dv.find(next) == dv.end()) {
					dv[next] = dv[vv] + 1;
					v2.push_back(next);
					dv_last[next] = vv;
				}
			}
		}
		v1 = v2;
	}

	int res = 0;
	for (int i = 1; i <= n; i++) {
		if (um[i].size() == 1) {
			if (du[i] < dv[i]) {
				res = max(res, dv[i] - 1);
			}
		}
	}
	cout << res << endl;
}









Measured memory_bytes: 36260
N=int(input())
S=list(input())
dic={}
count=0
for i in S:
    if not i in dic.keys():
        dic[i]=[count]
    else:
        dic[i].append(count)
    count+=1

max_count=0
for j in range(1,N+1):
    count=0
    for key,value in dic.items():
        if len(value)==1:
            continue
        else:
            if value[0]<=j and j<value[-1]:
                count+=1
    if max_count<count:
        max_count=count
print(max_count)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
    long long x;
    int N,M;
    long long total = 0;
 
    vector<long long>A;

    cin >> N >> M;
    for(int i=0;i<N;i++){
        cin >> x;
        A.push_back(x);
        total += x;
    }
    sort(A.begin(),A.end(),std::greater<int>());
    if(A[M-1]*4*M >= total){
        printf("Yes\n");
    }else{
        printf("No\n");
    }


   
    return 0;
}

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

    int n;
    cin >> n;
    vector<int> p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    
    vector<int> v(n);
    iota(v.begin(), v.end(), 1);

    int cnt = 0, a, b;
    do{
        cnt++;
        if(v == p) a = cnt;
        if(v == q) b = cnt;
    }while(next_permutation(v.begin(), v.end()));

    cout << abs(a-b) << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int ddx[8]={0,0,-1,1,1,1,-1,-1};
int ddy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	char s[SIZE];
	cin>>s;
	int sz=strlen(s);
	for(int i=0;i<sz;i++){
		if(!(i%2))
			cout<<s[i];
	}
	cout<<endl;
	return 0;
}

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

int n,p,q[200010]={},d[200010]={},jwb = 0;

int main() {
  cin >> n;
  for (int i=1;i<=n;++i) {
    cin >> p;
    q[p] = i;
    if (q[p-1]) d[i] = d[q[p-1]] + 1;
    else d[i] = 1;
    jwb = max(jwb, d[i]);
  }
  cout << n-jwb << endl;
  return 0;
}

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

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var n = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        Console.WriteLine(a.Sum() >= h ? "Yes" : "No");
    }
}


Measured memory_bytes: 16608
#include<stdio.h>
int expo(int b,int p);
int main(void){
    int N;
    scanf("%d",&N);
    if(N == 1){
        printf("%d",1);
    }else{
        //bは31まで
    //配列ex[i]はiをp乗してN未満の最大のべき乗をもとめ、代入する
    int ex[31];
        //while文で回す
     int i,p;
        for(i = 2;i <= 31;i++){
            
            p = 0;
            while((expo(i,1)<N)&&(expo(i,p+1) <= N)){
                p++;
            }
            ex[i] = expo(i,p);

        }
    //ex[]の最大値を求める
    int max = ex[0];
    for(i = 2;i <= 31;i++){
        if(ex[i] >= max){
            max = ex[i];
        }
    }

    printf("%d",max);
    }

}

int expo(int b,int p){

    if(p == 0){
        return 1;
    }else if(p == 1){
        return b;
    }else{
        int a = expo(b,p-1);
        return a * b;
    }

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()

using namespace std;

void execute()
{
	int N;
	cin >> N;
	vector<int> prime(55555, 1);
	vector<int> anss(57, 0);
	int count = 1;

	anss[0] = 2;
	prime[0] = prime[1] = 0;

	for (int i = 2; i < 55555; i++)
	{
		if (prime[i] == 0)
			continue;

		for (int j = i * 2; j < 55555; j += i)
		{
			prime[j] = 0;
		}

		if (i % 5 == 1)
		{
			anss[count++] = i;
		}

		if (N < count)
			break;
	}

	for (int i = 0; i < N; i++)
	{
		cout << anss[i] << " ";
	}
	cout << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

long long int gcd(long long int n1,long long int n2)
{
    if (n2 != 0)
       return gcd(n2, n1%n2);
    else
       return n1;
}

int main()
{
    long long int a,b,c,d,e,a1,a2,a3,b1,b2,b3,ans,ext1=0,ext2=0;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    e=c*d/gcd(c,d);

    if(a%c==0)  a1=a;
    else a1=((a+c)/c)*c;
    if(a%d==0)  a2=a;
    else a2=((a+d)/d)*d;
    if(a%e==0)  a3=a;
    else a3=((a+e)/e)*e;
    if(a1>b)    a1=0;
    if(a2>b)    a2=0;
    if(a3>b)    a3=0;

    b1=(b/c)*c;
    b2=(b/d)*d;
    b3=(b/e)*e;

    if(b1<a)    b1=0;
    if(b2<a)    b2=0;
    if(b3<a)    b3=0;

    if(a1==0)   ext1++;
    if(a2==0)   ext1++;
    if(a3==0)   ext2++;

    ans=b-a+1-((b1-a1)/c+1+(b2-a2)/d+1-ext1)+(b3-a3)/e+1-ext2;

    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int &a:A)
        cin >> a;
    
    vector<int> B;
    int s = 0;
    for(int i=A.size()-1; i>=0; i=i-2){
        B.push_back(A[i]);
        s = i;
    }
    
    for(int i=!s; i<A.size()-1; i=i+2)
        B.push_back(A[i]);
    
    for(int i=0; i<B.size(); i++){
        if(i==B.size()-1) cout << B[i];
        else cout << B[i] << " ";
    }
    cout << endl;
    
    return 0;
}


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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

int main(){
	int statT[2],statA[2];
	int turn = 1;
	cin >> statT[0] >> statT[1];
	cin >> statA[0] >> statA[1];

	while( statT[0] * statA[0] > 0 ){
		if( turn )	statA[0] -= statT[1];
		else	statT[0] -= statA[1];

		turn ^= 1;
	}

	if( statA[0] <= 0 )	cout << "Yes" << endl;
	else	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3596
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a1(n), a2(n);
    cin >> a1 >> a2;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int cnt = 0;
        for(int j = 0; j <= i; j++){
            cnt += a1[j];
        }
        for(int j = i; j < n; j++){
            cnt += a2[j];
        }
        ans = max(ans, cnt);
    }
    cout << ans << '\n';
}


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


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 <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s; int k;
	cin >> s >> k;
	vs v;
	REP(i, s.size())
	{
		FOR(j, 1, 6)
		{
			if (i + j > s.size()) break;
			string t = s.substr(i, j);
			v.push_back(t);
		}
	}
	sort(ALL(v));
	v.erase(unique(ALL(v)), v.end());
	cout << v[k - 1] << endl;
	return 0;
}

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

ll powmod(ll x, ll y)
{
    ll res = 1;
    for (ll i = 0; i < y; i++)
    {
        res = res * x % MOD;
    }

    return res;
}

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

    ll ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n);
    ans %= MOD;
    ans = (ans + MOD) % MOD;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                             \
  cerr << __LINE__ << ": " << #x << " = {";          \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) { \
    cerr << ((hoge) ? "," : "") << x[hoge];          \
  }                                                  \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W, M;
  cin >> H >> W >> M;
  int h[M], w[M];
  int cnth[H], cntw[W];
  fill(cnth, cnth + H, 0);
  fill(cntw, cntw + W, 0);
  for (int i = 0; i < M; i++) {
    cin >> h[i] >> w[i];
    h[i]--, w[i]--;
    cnth[h[i]]++;
    cntw[w[i]]++;
  }
  set<pair<int, int>> S;
  vector<pair<int, int>> vh;
  vector<pair<int, int>> vw;
  for (int i = 0; i < M; i++) {
    S.insert(make_pair(h[i], w[i]));
    vh.emplace_back(cnth[h[i]], h[i]);
    vw.emplace_back(cntw[w[i]], w[i]);
  }
  sort(vh.rbegin(), vh.rend());
  sort(vw.rbegin(), vw.rend());
  vh.erase(unique(vh.begin(), vh.end()), vh.end());
  vw.erase(unique(vw.begin(), vw.end()), vw.end());
  int ans = 0;
  for (int i = 0; i < vh.size(); i++) {
    if (ans >= vh[i].first + vw[0].first) {
      break;
    }
    for (int j = 0; j < vw.size(); j++) {
      if (ans >= vh[i].first + vw[j].first) {
        break;
      }
      ans = vh[i].first + vw[j].first;
      if (S.count(make_pair(vh[i].second, vw[j].second))) ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main()
{
	int s,k,c=0;
	scanf("%d%d",&k,&s);
	for(int x=0;x<=k;x++)
    {
        for (int y=0;y<=k;y++)
        {
            int z=s-(x+y);
            if(z>=0&&z<=k)
            {
                c++;
            }
        }
    }
    printf("%d",c);
}




Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int[] a = new int[N];
		int[] b = new int[N];
		int[] c = new int[M];
		int[] d = new int[M];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for(int j = 0; j < M; j++) {
			c[j] = sc.nextInt();
			d[j] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			int min = 0, man = 0,minIndex=0;
			for(int j = 0; j < M; j++) {
				man = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				if(man < min || j == 0) {
					min = man;
					minIndex = j;
					//System.out.println(man);
				}
				man = 0;
			}
			System.out.println(minIndex + 1);
		}
	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <string>

using namespace std;

int main() {
	string a = "ABCDE";
	int p, q;
	while (cin >> p >> q) {
		if (p == 0 && q == 0) {
			break;
		}
		int max = p+q;
		char maxn = a[0];
		for (int i = 1; i < a.size(); i++) {
			cin >> p >> q;
			if (max < p+q) {
				max = p+q;
				maxn = a[i];
			}
		}
		cout << maxn << " " << max << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
n=int(input())
a=[int(input()) for i in range(n)]
a=sorted(a)
x=a[0]
c=1
ct=0
for i in range(1,n):
  if a[i]==x:
    c+=1
    if i==n-1:
      if c%2==1:
        ct+=1
  else:
    if c%2==1:
      ct+=1
    x=a[i]
    c=1
    if i==n-1:
      ct+=1
print(ct)

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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque…双方向リスト
//stack…FILO, 深さ優先探索
//queue…FIFO, 幅優先探索
//priority_queue…格納された最大値から順に取り出す
//pair…二つの値を一組
//tuple…複数の値を一組

const int mod = 1e9+7;

template<typename T>
void remove(std::vector<T>& vector, char index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}
template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}
template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}

using Graph = vector<vector<int>>;

template <class T, class S>
class Edge {
  T to;  //辺の行き先
  S weight;  //辺の重み

public:
  Edge(T t, S w) : to(t), weight(w) {}
};

int ansi = 0;
ll ansl = 0;
double ansd = 0.0;

int accumul(int mul) {
  if (mul == 0) {
    return 1;
  } else {
    return mul * accumul(mul-1);
  }
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int den = n * a;
  cout << min(b, den);
}

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
    int N; cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int A = 0;
    rep(i, N) A += a[i];
    vector<bool> dp(A + 1);
    dp[0] = true;
    rep(i, N) for (int x = A; x >= a[i]; x--) if (dp[x - a[i]]) dp[x] = true;
    int ans = 0;
    rep(x, A + 1) if (x % 10 && dp[x]) ans = x;
    cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    ans = n
    for a in range(1,int(n**0.5) + 1):
        if n % a == 0:
            b = n // a
            ans = min(ans, func(a,b))
    print(ans)

def func(a,b):
    str_a = str(a)
    str_b = str(b)
    return max(len(str_a), len(str_b))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin >> n;
	ll ans = 0;
	vector<int> s(n);
	map<int, int> mapp;
	for(int i = 0; i < n; i++)
	{
		int a; cin >> a;
		s[i] = i + a + 1;
		mapp[i - a + 1]++;
	}
	for(int i = 0; i < n; i++) ans += mapp[s[i]];
	cout << ans;

	return 0;
}


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

int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll div = x/d;
    if(div>=k){
        cout << abs(x)-abs(k*abs(d));
        //cout << 1 << endl;
        return 0;
    }
    else{
        if((k-div)%2==0){
            cout << abs(x)-abs(div*abs(d)) << endl;
        }
        else
        {
            cout << abs((abs(x)-abs(div*abs(d)))-abs(d)) << endl;
        }
    }
}

Measured memory_bytes: 3632
#pragma GCC diagnostic ignored "-Wunused-result"

#include <stdio.h>

int main(void) {
  unsigned long N,K;
  unsigned long long count = 0;
  
  scanf("%lu %lu", &N, &K);

  count += (N/K)*(N/K)*(N/K);
  
  if (K%2 == 0){ // even
    unsigned long m = N/(K/2) - N/K; 
    count += m*m*m;
  }
  
  printf("%llu\n",count);
  return 0;

}


Measured memory_bytes: 128
#include <stdio.h>

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

int tgcd(int a, int b, int c)
{
	return(gcd(gcd(a,b), c));
}

int main(void)
{
	int num;
	int k;
	int i,j,l;
	int hoge;

	scanf("%d", &k);
	num = 0;
	i = 1;
	while(i <= k)
	{
		j = 1;
		while(j <= k)
		{
			l = 1;
			while(l <= k)
			{
				num = num + tgcd(i, j, l);
				l++;
			}
			j++;
		}
		i++;
	}

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


Measured memory_bytes: 2136
#include <iostream>
using namespace std;
int main() {
	while (1) {
		int n, m, c[10000] = { 0 }, a[100000] = { 0 }, b[100000] = { 0 }, ans = 0;
		cin >> n >> m;
		if (n == 0 && m == 0) return 0;
		for (int i = 0; i < m; i++) {
			cin >> a[i] >> b[i];
			if (a[i] == 1) c[b[i]] = 1;
			if (b[i] == 1) c[a[i]] = 1;
		}
		for (int i = 2; i <= n; i++) {
			if (c[i] == 1) {
				for (int j = 0; j < m; j++) {
					if (a[j] == i) if (c[b[j]] != 1) c[b[j]] = 2;
					if (b[j] == i) if (c[a[j]] != 1) c[a[j]] = 2;
				}
			}
		}
		for (int i = 2; i <= n; i++) {
			if (c[i] == 1 || c[i] == 2) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
const int N=15;

char a[N][N],b[N][N];
int n,m,match[N],use[N];

inline int Equal(int x,int y) {
	for (int i=1;i<=n;i++) {
		if (b[i][x]!=b[n-i+1][y]) return 0;
	}
	return 1;
}

inline void check() {
	int res=m&1;
	memset(use,0,sizeof(use));
	int now=1;
	for (int i=1;i<=n;i++) {
		if (i==match[i]) {
			for (int j=1;j<=m;j++)
				b[(n+1)>>1][j]=a[i][j];
		}
		if (i<match[i]) {
			for (int j=1;j<=m;j++) {
				b[now][j]=a[i][j];
				b[n-now+1][j]=a[match[i]][j];
			}
			++now;		
		}
	}		
	for (int i=1;i<=m;i++) {
		if (use[i]) continue;
		for (int j=i+1;j<=m;j++)
			if (!use[j]&&Equal(i,j)) {
				use[i]=j; use[j]=i;
				break;
			}
		if (!use[i]) {
			int flag=1;
			for (int j=1;j<=n;j++) 
				if (b[j][i]!=b[n-j+1][i]) flag=0;
			if (!flag) return;
			if (--res<0) return;
		}
	}
	puts("YES"); exit(0);
}

void dfs(int x,int res) {
	if (x==n+1) return (void) (check());
	if (match[x]) return (void) (dfs(x+1,res));
	if (res) {
		int flag=1;
//		for (int i=1;i<=m;i++) 
//			if (a[x][i]!=a[x][m-i+1]) flag=0;
		if (flag) {
			match[x]=x;
			dfs(x+1,0);
			match[x]=0;			
		}
	}
	for (int i=x+1;i<=n;i++) {
		if (!match[i]) {
			match[i]=x; match[x]=i;
			dfs(x+1,res);
			match[i]=0; match[x]=0;
		}
	}
}

int main() {
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%s",a[i]+1);
	dfs(1,n&1);
	puts("NO");
	return 0;
}
/*
3 3
aac
bab
cba
*/

Measured memory_bytes: 256
s = input()
t = input()

def match(s1, s2):
    if len(s1) < len(s2):
        return False
    for i, j in zip(s1, s2):
        if i != j and i != "?":
            return False
    return True

result = []
for i in range(50):
    if match(s[i:], t):
        result.append((s[:i] + t + s[i + len(t):]).replace("?", "a"))
result.sort()
if not result:
    print("UNRESTORABLE")
else:
    print(result[0])


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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	
	while (1) {
		int n, r;
		int p, c;
		int a[51] = {};
		int b[51] = {};
		
		cin >> n >> r;
		if (n == 0 && r == 0) {
			break;
		}
		FOR(i, 1, n) {
			a[i] = n - i + 1;
		}
		FOR(i, 1, r) {
			cin >> p >> c;
			FOR(t, 1, p - 1) {
				b[t] = a[t];
			}
			FOR(t, 1, c) {
				a[t] = a[p + t - 1];
			}
			FOR(t, 1, p - 1) {
				a[c+t] = b[t];
			}
		}
		cout << a[1] << endl;
	}

}


Measured memory_bytes: 3052
import sys
input = sys.stdin.buffer.readline

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

ax = sorted(a, key=lambda x:(x[0], x[1]))
ay = sorted(a, key=lambda x:(x[1], x[0]))

ans = 0
lx, ly = ax[0][0], ax[0][1]
ux, uy = ax[0][0], ax[0][1]
for i in range(n):
    if ax[i][0] - lx + ax[i][1] - ly < 0:
        lx, ly = ax[i][0], ax[i][1]
    if ax[i][0] - ux + ax[i][1] - uy > 0:
        ux, uy = ax[i][0], ax[i][1]
    ans = max(ans, ux-lx + uy - ly)
    
lx, ly = ax[0][0], ax[0][1]
ux, uy = ax[0][0], ax[0][1]
for i in range(n):
    if ax[i][0] - lx + ly - ax[i][1] < 0:
        lx, ly = ax[i][0], ax[i][1]
    if ax[i][0] - ux + uy - ax[i][1] > 0:
        ux, uy = ax[i][0], ax[i][1]
    ans = max(ans, ux-lx + ly - uy)
print(ans)

Measured memory_bytes: 125644
// Dāritys Morgho ban Rōvēgrie
// Math = ♥
// Sometimes it is people that no one imagines anything of who do things that no one can imagine
// After all this time? Always

#include <bits/stdc++.h>                        // uncomment before submission
//#include <ext/pb_ds/assoc_container.hpp>		// uncomment before submission
//#include <ext/pb_ds/tree_policy.hpp>			// uncomment before submission
//using namespace __gnu_pbds;					// uncomment before submission
using namespace std;
//<---------------------------------------------------Template----------------------------------------------------------->
#define int long long
#define ll long long
#define ld long double
const int INF = 1e15 + 7;
const int MAX = 1e5 + 7;
const int MOD = 1e9 + 7;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;                  // Vector of long long
typedef vector<vi> vvi;                 // Vector of vi
typedef vector<ii> vii;                 // Vector of pairs
typedef vector<vii> vvii;               // Vector of Vector of pairs
typedef vector<bool> vb;                // Vector of bool
#define pq priority_queue               // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                        // For pairs
#define ss second                       // For pairs
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//<----------------------------------------------------------------------------------------------------------------------->

int n, m;
vvi g;
vi f;

int solve(int s)
{
    if (f[s] != -1) return f[s];

    f[s] = 0;
    for (int i: g[s])
        f[s] = max(f[s], solve(i) + 1);

    return f[s];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x, y;
    cin >> n >> m;

    g.resize(n + 1), f.resize(n + 1, -1);
    for (int i = 0; i < m; i++)
        cin >> x >> y, g[y].pb(x);

    int ans = 0;
    for (int v = n; v >= 1; v--)
        ans = max(ans, solve(v));

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


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

int dfs(vector<vector<int>>&graph,int ind,vector<int> &visited){
    visited[ind]=1;
    int ans=1;
    for(int i=0;i<graph[ind].size();i++){
        if(!visited[graph[ind][i]]){
            ans+=dfs(graph,graph[ind][i],visited);
        }
    }
    return ans;
}
 
int main(){
    //ios_base::sync_with_stdio(false);
    int i,n,m;
    cin >>n>>m;
    vector<pair<int,int>> friends;
    vector<vector<int>> graph(n);
    for(i=0;i<m;i++){
        int x,y;
        cin >>x>>y;
        if(x<y) swap(x,y);
        friends.push_back(make_pair(x,y));
    }
    sort(friends.begin(),friends.end());
    i=0;
    vector<vector<int>> fr;
    while(i<m){
        pair<int,int> curr=friends[i];
        while(i<m&&friends[i]==curr){
            i++;
        }
        graph[curr.first-1].push_back(curr.second-1);
        graph[curr.second-1].push_back(curr.first-1);
    }
    vector<int> vis(n,0);
    int ans=0;
    for(i=0;i<n;i++){
        if(!vis[i]) ans=max(ans,dfs(graph,i,vis));
    }
    cout <<ans<<endl;
}   

Measured memory_bytes: 25852
H,W = map(int,input().split())
s = [list(input()) for i in range(H)]

def draw_check(s):
    for i in range(H):
        for j in range(W):
            if s[i][j] == '.':
                continue
            else:
                if all([s[max(0,i-1)][j] == '.',s[min(H-1,i+1)][j] == '.',s[i][max(0,j-1)] == '.',s[i][min(W-1,j+1)] == '.']):
                    return False
                    break
        else:
            continue
        break

    return True

if draw_check(s):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) {    
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		ArrayList<String> words = new ArrayList<String>();
		for (int i = 0; i < N; i++) {
			char[] cur = I.next().toCharArray();
			Arrays.sort(cur);
			String sort = new String(cur);
			words.add(sort);
		}
		Collections.sort(words);
		long curlen = 1;
		long ans = 0;
		for (int i = 1; i < N; i++) {
			String prev = words.get(i-1);
			String cur = words.get(i);
			if (prev.equals(cur)) curlen++;
			else {
				ans+=curlen*(curlen-1)/2;
				curlen=1;
			}
		}
		ans+=curlen*(curlen-1)/2; //Last ever contiguous sub-array of anagrams
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
	}
}



Measured memory_bytes: 50728
#include <iostream>
#include <algorithm>
#include <typeinfo>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <numeric>
using namespace std;



//Trick or Treat
int main() {

	string s;
	cin >> s;
	if (s == "ABC") {
		cout << "ARC";
	}
	else {
		cout << "ABC";
	}
	
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string Yes[2] = {"Yes", "No"};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;

/*------------------------------------------------------------------*/
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n; cin >> n;
    ll ans = 0;
    vector<ll> a(n), b(n), c(n), sum(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    sum[0] = 0;

    rep(i, n){
        auto pos = lower_bound(a.begin(), a.end(), b[i]);
        int index = distance(a.begin(), pos);
        sum[i + 1] = sum[i] + index;
    }
    rep(i, n){
        auto pos = lower_bound(b.begin(), b.end(), c[i]);
        int index = distance(b.begin(), pos);
        ans += sum[index];
    }
    cout << ans << endl;
}


Measured memory_bytes: 6348
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int64_t N, M;
    cin >> N >> M;
    int64_t ans = 0;
    ans = min(N, M / 2);
    N -= ans;
    M -= ans * 2;
    ans += M / 4;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  long long sum = 0;
  REP(i,n) {
    long long a;
    cin >> a;
    sum+= a;
  }
  cout << sum / n << endl;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();
        if(a!=0){
        System.out.println(b/x-(a-1)/x);
        }else{
            System.out.println(b/x+1);
        }

    }
}

Measured memory_bytes: 23764
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
          var data = ReadLine().Split(' ').Select(int.Parse).ToArray();
          var tester = new int[100];
         for(int i = 0; i < data[1]; i++){
              int d = int.Parse(ReadLine());
              int[] A = ReadLine().Split(' ').Select(int.Parse).ToArray();
              for(int j = 0; j < d; j++){
                  tester[A[j] - 1]++;
              }
         }
         int ans = 0;
         for(int i = 0; i < data[0]; i++){
             if(tester[i] == 0) ans++;
         }
         WriteLine(ans);
      }
   }
}

Measured memory_bytes: 28512
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

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

	vector<string> data(H);
	for (int i = 0; i < H; i++) cin >> data[i];

	for (const auto &elem : data) cout << elem << "\n" << elem << "\n";

	return 0;
}

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

int main() {
	int h, w;
	cin >> h >> w;

	char alpha[27] = { '0', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
	string a;
	for ( int i = 1; i <= h; i++ ) {
		for ( int j = 1; j <= w; j++ ) {
			cin >> a;
			if ( a == "snuke" ) {
				cout << alpha[j] << i << endl;
			}
		}
	}
}


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

int main() {
    int n,k;
    cin >> n >> k;
    double probability = 0;
    for(int i = 1;i<=n;i++){
        int power_of_two = ceil(log2(k) - log2(i));
        double temp = 1;
        for(int j = 0;j<power_of_two;j++){
            temp /= 2;
        }
        probability += (1/(double)n) * temp;
    }
    cout << fixed << setprecision(10);
    cout << probability;
    return 0;
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int main() {
    int n, ans = 0, suf = 0;
    string s;
    cin >> n >> s;
    while (1) {
        if ((suf = s.find("ABC", suf)) == string::npos)
            break;
        suf++;
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <unistd.h>

int main()
{
  int N,i;
  scanf("%d",&N);
  char S[N],T[N];
  scanf("%s %s",&S,&T);
  while (S[i])
  {
    write(1, &S[i], 1);
    write(1, &T[i], 1);
    i++;
  }
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a > b && a > c) cout << "A" << endl;
    else if(b > c) cout << "B" << endl;
    else cout << "C" << endl;
    return 0;
}



Measured memory_bytes: 3088
object Main {
  def main(args: Array[String]): Unit = {
    val factors = scala.io.StdIn.readLine.split("")
    var sum = 0

    factors.foreach({ i =>
      if     (i == "+") sum += 1
      else if(i == "-") sum -= 1
    })

    println(sum)
  }
}

Measured memory_bytes: 25424
#include<bits/stdc++.h>
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int s[M], c[M];
    rep(i, M) {
        cin >> s[i];
        cin >> c[i];
    }

    int d[4];
    rep(i, 4){
        d[i] = -1;
    }
    rep(i, M){
        if (d[s[i]] == -1) {
            d[s[i]] = c[i];
        } else {
            if (d[s[i]] != c[i]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    ll ans = 0;



    rep(i, N) {
        if (i == N-1) {
            if (d[N-i] != -1) {
                ans += pow(10,i)*d[N-i];
            } else {
                ans += pow(10,i);
            }
        } else {
            if(d[N-i] != -1) {
                ans += pow(10,i)*d[N-i];
            }
        }
    }
    if (d[1] == 0 && N != 1) {
        cout << -1 << endl;
        return 0;
    } else if (d[1] == 0 && N == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (N == 1 && d[1] == -1) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES	//used before importing cmath to enable math constant M_PI

#include <iostream>
#include <iomanip>
#include <cmath>

struct Point
{
	double x;
	double y;
};


void koch(int depth, Point start, Point end)
{
	using namespace std;
	cout.precision(8);
	cout << std::fixed;

	if (depth == 0)
	{
		return;
	}
	
	Point s, t, u;
	double sixty = M_PI * 60 / 180;
	s.x = (2 * start.x + end.x) / 3.0;
	s.y = (2 * start.y + end.y) / 3.0;
	t.x = (start.x + 2 * end.x) / 3.0;
	t.y = (start.y + 2 * end.y) / 3.0;
	u.x = (t.x - s.x)*cos(sixty) - (t.y - s.y)*sin(sixty) + s.x;
	u.y = (t.x - s.x)*sin(sixty) + (t.y - s.y)*cos(sixty) + s.y;

	koch(depth - 1, start, s);
	cout << s.x << ' ' << s.y << endl;
	koch(depth - 1, s, u);
	cout << u.x << ' ' << u.y << endl;
	koch(depth - 1, u, t);
	cout << t.x << ' ' << t.y << endl;
	koch(depth - 1, t, end);
}

int main()
{
	Point a, b;
	int n;
	std::cin >> n;
	a.x = 0.0, a.y = 0.0;
	b.x = 100.0, b.y = 0;
	std::cout << a.x << ' ' << a.y << std::endl;
	koch(n, a, b);	
	std::cout << b.x << ' ' << b.y << std::endl;
	return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

long long N;
vector<long long> A;

int main() {
	cin >> N;
	A.resize(N);
	for (long long n = 0; n < N; n++)cin >> A[n];
	long long ans = 0;
	for (long long n = 0; n < N; n++) {
		long long t = 0;
		while (A[n] % 2 == 0) {
			A[n] /= 2;
			t++;
		}
		ans += t;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(){
	bool dp[20][20];
	char r[20][20];
	int w,h;
	while(true){
	cin>>w>>h;
	if(w==0&&h==0)
		break;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>r[i][j];
			dp[i][j]=false;
			if(r[i][j]=='@')
				dp[i][j]=true;
		}
	}
	int count=1,cop=1;
	while(true){
	cop=count;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			bool t=false;
			if(i<h-1){
			if(dp[i+1][j]==true&&r[i][j]=='.')
				t=true;
			}
			if(i>0){
			if(dp[i-1][j]==true&&r[i][j]=='.')
				t=true;
			}
			if(j<w-1){
			if(dp[i][j+1]==true&&r[i][j]=='.')
				t=true;
			}
			if(j>0){
			if(dp[i][j-1]==true&&r[i][j]=='.')
				t=true;
			}
			if(t==true&&dp[i][j]==false){
				count++;
				dp[i][j]=true;
			}
		}
	}
	if(cop==count)
		break;
	}
	cout<<count<<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}



int main() {
  int n,z,w;
  cin >> n >> z >> w;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  reverse(a.begin(),a.end());
  if (n>1)
  {if (abs(a[1]-a[0])<(abs(a[0]-w))) cout << abs(a[0]-w) << endl;
  else cout << abs(a[1]-a[0]) << endl;}
  else
  {
    cout << abs(a[0]-w) << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	bool arr[110];
	memset(arr,0,sizeof(arr));
	int ans=0;
	int n;cin>>n;for(int x=0;x<n;x++){
		int a;cin>>a;if(!arr[a]){
			ans++;arr[a]=true;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<math.h>


int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

int GetOddSum(char *buf){
    int ret=0;

    for(int i=0; i<7; i++)
        ret += buf[2*i+1] - '0';
    return ret;
}

int GetEvenSum(char *buf){
    int ret=0;

    for(int i=0; i<8; i++){
        int tmp =2*(buf[2*i] - '0');

        ret += (tmp>=10)?(tmp%10 +1):(tmp);
    }
    return ret;
}


int main(){
    int N,max=0,next_max=0;
    int A[200000];

    scanf("%d%*c",&N);
    for(int i=0; i<N; i++){
        scanf("%d%*c",&(A[i]));
        if(A[i]>max){
            next_max = max;
            max = A[i];
        }
        else if(A[i]>next_max){
            next_max = A[i];
        }
    }

    for(int i=0; i<N; i++){
        printf("%d\n", (A[i]==max)?(next_max):(max));
    }
    return 0;
}

Measured memory_bytes: 2304
import math
n=int(input())
csf=[input() for _ in range(n-1)]
for i in range(n-1):
  c,s,f=map(int, csf[i].split())
  cost=s+c
  for j in range(i+1, n-1):
    c,s,f=map(int, csf[j].split())
    cost=math.ceil((cost-s)/f)*f+s+c if cost > s else s+c
  print(cost)
print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

    string t;
    cin >> t;
    rep(i,t.size()){
        if(t[i]=='?'){
            t[i]='D';
        }
    }
    cout << t << endl;

    return 0;
}

Measured memory_bytes: 3740