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

public class Main{
	public static void main(String args[]) throws Exception {
		FastReader sc = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		String s = sc.next();
		int min = s.length();
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) != s.charAt(i + 1)) {
				min = Math.min(min, Math.max(i+1, s.length() - i - 1));
			}
		}

		out.println(min);
		out.close();

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				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());
		}

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 25044
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i = 0;i < n; i++)
#define REP(i,n) for(int i = 1;i <= n; i++)
#define ll long long
using namespace std;




int main(){

    int A[210000],N;
    int B;
    cin >> N;

   

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

        cin >> A[i];
    }

     sort(A,A + N);

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

        if(A[i] == A[i + 1]){

            B ++;

      
        }
    }

    if(B == 0){
        cout << "YES" <<endl;
    }else if(B > 0){
        cout <<"NO" <<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

/**
 *
 */
public class Main {
    public static final int MOD = 1_000_000_007;

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

        String L = sc.next();

        System.out.println(solve(L));
    }

    /**
     * http://kmjp.hatenablog.jp/entry/2019/06/09/0900
     *
     * @param L
     * @return
     */
    private static long solve(String L) {
        L = "0" + L;
        int N = L.length();
        long ans=0;
        long v=1, a=1;

        long[] s = new long[100002];
        s[0] = 1;
        for (int i=0; i<N; i++) {
            s[i+1] = s[i];
            if (L.charAt(i) == '1') {
                s[i+1] = s[i+1]*2 % MOD;
            }
        }

        for (int i=N-1; i>=1; i--) {
            if (L.charAt(i) == '1') {
                v = v*2 % MOD;
                ans += a*s[i]%MOD;
            }
            a = a*3%MOD;
        }
        ans += v;

        return ans%MOD;
    }
}

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

namespace CDiceAndCoin
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = inputs[0];
            var k = inputs[1];

            // 出目 Dice の値が K/2 ~ K - 1 の場合、１回コインの表が出れば勝ちなので 1/N * 1/2
            // 出目 Dice の値が K/4 ~ K/2 - 1 の場合、２回コインの表が出れば勝ちなので 1/N * (1/2)^2
            // ...
            // 出目 Dice が既に K 以上ならばコインを投げる必要はないため 1/N
            long sum = 0;
            var divCount = 0;
            var prevK = k;
            while (1 < prevK)
            {
                sum *= 2;

                var lower = (int)Math.Ceiling((float)prevK / 2);
                if (lower <= n)
                {
                    sum += Math.Min(prevK - 1, n) - lower + 1;
                }

                prevK = lower;
                divCount++;
            }

            var prob = sum / (n * Math.Pow(2, divCount));

            // K 以上の値ではコインを投げる必要がないため 1/N
            if (k <= n)
            {
                // 計算誤差が大きくなってしまうため 1/N ずつ加算
                for (var i = 0; i < n - k + 1; i++)
                {
                    prob += (double)1 / n;
                }
            }

            // 解答の出力
            Console.WriteLine(prob);
        }
    }
}


Measured memory_bytes: 13268
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]

sortthird = lambda x: x[2]
l.sort(key = sortthird)

for i in range(101):
    for j in range(101):
        ref = l[-1][2] + abs(l[-1][0] - i) + abs (l[-1][1] - j)
        for k in range(n):
            if l[k][2] == max(0, ref - abs(l[k][0] - i) - abs (l[k][1] - j)):
                continue
            else:
                break
        else:
            print(i, j, ref)
            exit()

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

int main() {
	int n,m;
	cin>>n>>m;
	vector<int> v[m];
	for(int i=0;i<m;i++){
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			int z;
			cin>>z;
			v[i].push_back(z);
		}
	}
	int p[m];
	for(int i=0;i<m;i++) cin>>p[i];
	int ans2=0;
	for(int i=0;i<(1<<n);i++){
		int big=0;
		for(int j=0;j<m;j++){
			int ans=0;
			for(int z=0;z<v[j].size();z++){
				if((1<<(v[j][z]-1))&i) ++ans;
			}
			if(ans%2==p[j]) ++big;
		}
		if(big==m) ++ans2;
	}
	cout<<ans2;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
typedef long long int lli;

lli gcd(lli x,lli y){
    if(y>x){
        lli tmp=x;
        x=y;
        y=tmp;
    }
    if(x%y==0)return y;
    else return gcd(y,x%y);
}
int main(void)
{
    lli a,b;

    scanf("%lld %lld",&a,&b);
    //printf("%lld\n",a*b);
    printf("%lld\n",a*b/gcd(a,b));

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int gcd(ll a, ll b) {
    if (a < b) {
        ll tmp = a;
        a = b;  b = tmp;
    }
    ll r = a % b;
    while (r != 0) {
        a = b;  b = r;
        r = a % b;
    }
    return b;
}

int main(void){
    int n, a[100010];
    cin >> n;
    int k[100010], l[100010];
    for (int i = 0; i < n; i++) cin >> a[i];
    
    k[0] = a[0];
    for (int i = 1; i < n; i++) {
        k[i] = gcd(k[i - 1], a[i]);
    }
    l[n - 1] = a[n - 1];
    for (int i = 1; i < n; i++) {
        l[n - 1 - i] = gcd(l[n - i], a[n - 1 - i]);
    }
    
    int ans = max(l[1], k[n - 2]);
    for (int i = 0; i < n - 2; i++) {
        ans = max(gcd(k[i], l[i + 2]), ans);
    }
    cout << ans << endl;
    
}



Measured memory_bytes: 1408
import java.util.*;
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))
        {
			System.out.println("0");
        }
      	else
        {
        	System.out.println(a-(b*2));
        }
	}
}

Measured memory_bytes: 22996
#pragma GCC optimize("O3")

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <random>
#include <set>
#include <ctime>
#include <cmath>
#include <string>

using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	cout << s.substr(0, 3);
}


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

#define REP(i,a,b) for(int i=a,i##_end_=b;i<=i##_end_;++i)
#define DREP(i,a,b) for(int i=a,i##_end_=b;i>=i##_end_;--i)
#define MREP(i,x) for(int i=beg[x],v;v=to[i],i;i=las[i])
#define debug(x) cout<<#x<<"="<<x<<endl
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define y1 asdasd
typedef long long ll;

using namespace std;

void File(){
    freopen("haner.in","r",stdin);
    freopen("haner.out","w",stdout);
}

template<typename T>void read(T &_){
    T __=0,mul=1; char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-')mul=-1;
        ch=getchar();
    }
    while(isdigit(ch))__=(__<<1)+(__<<3)+(ch^'0'),ch=getchar();
    _=__*mul;
}

const int maxn=40+10;
const int inf=0x3f3f3f3f;
int n,m,px,py,dp[maxn][maxn][maxn][maxn],sum[maxn][maxn],ans=inf;
char s[maxn][maxn];

int S(int x1,int y1,int x2,int y2){
    return sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1];
}

template<typename T>void chkmin(T &_,T __){_=_<__ ? _ : __;}

int main(){
    read(n); read(m);
    REP(i,1,n)scanf("%s",s[i]+1);
    REP(i,1,n){
        REP(j,1,m){
            if(s[i][j]=='P'){
                px=i; py=j; s[i][j]='+';
            }
            sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+(s[i][j]=='#');
            //cout<<sum[i][j]<<" ";
        }
        //cout<<endl;
    }
    memset(dp,63,sizeof(dp));
    dp[1][1][n][m]=0;//代表将(1,1,n,m)这个矩形独立的最小代价为0。
    REP(x1,1,n)REP(y1,1,m)
        DREP(x2,n,x1)DREP(y2,m,y1){
            if(x1<=px && x2>=px && y1<=py && y2>=py){
                int w=dp[x1][y1][x2][y2];
                REP(x,x1,x2)REP(y,y1,y2){
                    int cost1=S(x1,y1,x,y)+S(x+1,y+1,x2,y2);
                    int cost2=S(x1,y+1,x,y2)+S(x+1,y1,x2,y);
                    chkmin(dp[x1][y+1][x][y2],cost1+w);
                    chkmin(dp[x+1][y1][x2][y],cost1+w);
                    chkmin(dp[x1][y1][x][y],cost2+w);
                    chkmin(dp[x+1][y+1][x2][y2],cost2+w);
                }
                //cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<w<<endl;
                chkmin(ans,w+S(x1,y1,px,py));
                chkmin(ans,w+S(px,py,x2,y2));
                chkmin(ans,w+S(px,y1,x2,py));
                chkmin(ans,w+S(x1,py,px,y2));
            }
        }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 24704
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=404;
inline int quickpow(int base,int ind)
{
	base%=mod;
	int ans=1;
	while(ind>0)
	{
		if(ind&1)ans=ans*1ll*base%mod;
		ind>>=1;
		base=base*1ll*base%mod;
	}
	return ans;
}
int n,a[maxn],b[maxn];
int pospow[maxn][maxn],fact[maxn],invfact[maxn];
int dp[maxn][maxn];
inline int add(int &a,int b)
{
	b%=mod;
	a+=b;
	if(a>=mod)a-=mod;
}
int main()
{
	scanf("%d",&n);
	int sum=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		sum+=a[i];
	}
	sum=quickpow(sum,mod-2);
	for(int i=0;i<maxn;i++)
	{
		int base=i*1ll*sum%mod;
		int ans=1;
		for(int j=0;j<maxn;j++)
		{
			pospow[i][j]=ans;
			ans=ans*1ll*base%mod;
		}
	}
	fact[0]=1;
	for(int i=1;i<maxn;i++)
		fact[i]=fact[i-1]*1ll*i%mod;
	invfact[maxn-1]=quickpow(fact[maxn-1],mod-2);
	for(int i=maxn-2;i>=0;i--)
		invfact[i]=invfact[i+1]*1ll*(i+1)%mod;
	int suma=0,sumb=0;
	dp[0][0]=mod-1;
	for(int i=0;i<n;i++)//i-th number
	{
		for(int y=sumb;y>=0;y--)for(int x=suma;x>=0;x--)if(dp[x][y]!=0)//already taken
		{
			for(int j=0;j<b[i];j++)//take j of i
			{
				add(dp[x+j][y+a[i]],mod-dp[x][y]*1ll*pospow[a[i]][j]%mod*1ll*invfact[j]%mod);
			//	cout<<x<<" "<<y<<" "<<dp[x][y]<<" "<<x+j<<" "<<y+a[i]<<" "<<
			//	dp[x+j][y+a[i]]<<" "<<(dp[x][y]*1ll*pospow[a[i]][j]%mod*1ll*invfact[j]%mod)<<endl;
			}
		}
		suma+=b[i];
		sumb+=a[i];
	}
	int ans=0;
	for(int x=0;x<=suma;x++)for(int y=0;y<=sumb;y++)
	{
		add(ans,dp[x][y]*1ll*fact[x]%mod*1ll*quickpow(pospow[y][x+1],mod-2)%mod);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1536
#!/usr/bin/perl

$line = 0;
while (<>) {
    chomp;
    if ($line == 0) {
        @a = split //, $_;
    } elsif ($line == 1) {
        @b = split //, $_;
    } elsif ($line == 2) {
        @c = split //, $_;
    }
    $line++;
}

$t = 'a';
while (1) {
    if ($t eq 'a') {
        if ($#a == -1) {
            $win = 'A';
            last;
        }
        $t = shift @a;
    } elsif ($t eq 'b') {
        if ($#b == -1) {
            $win = 'B';
            last;
        }
        $t = shift @b;
    } elsif ($t eq 'c') {
        if ($#c == -1) {
            $win = 'C';
            last;
        }
        $t = shift @c;
    }
}

print "$win\n";


Measured memory_bytes: 512
import numpy as np
import itertools
import math

n = int(input())

towns = []

for i in range(n):
    towns.append(list(map(int, input().split())))

towns = np.array(towns)

l = np.zeros((n, n))

for i in range(n):
    for j in range(n):
        l[i, j] = np.sum((towns[i] - towns[j])**2) ** 0.5

ans = 0
for order in itertools.permutations(range(n), n):
    now = order[0]
    f = 0
    for i in order[1:]:
        f += l[now, i]
        now = i
    ans += f
print(ans/math.factorial(n))


Measured memory_bytes: 21876
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
using namespace std;
const int N = 10010;
int f[6 * N];
int main(){
	int n;
	cin >> n;
	int lim = sqrt(n);
	for(int i = 1; i <= lim; ++i)
		for(int j = 1; j <= lim; ++j)
			for(int k = 1; k <= lim; ++k)
				++f[i*i + j*j + k*k + i*j + j*k + k*i];
	for(int i = 1; i <= n; ++i) printf("%d\n", f[i]);
	return 0;
}


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

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int a = ni();
		int b = ni();

		boolean flg = false;
		if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
			flg = true;
		}
		String s = "";
		if (flg) {
			s = "Possible";
		} else {
			s = "Impossible";
		}
		out(s);

	}

	/*
	 * 以下メソッド集
	 */
	static int[] sort(int[] n) {
		Arrays.sort(n);
		return n;
	}

	static long[] sort(long[] n) {
		Arrays.sort(n);
		return n;
	}

	static int ketasuu(int n) {
		String str = "" + n;
		return str.length();
	}

	static int account(String str) {
		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static long min(long d, long e) {
		return Math.min(d, e);
	}

	static int min(int a, int b) {
		return (int) Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 35676
// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using ll  = long long;
using ull = unsigned long long;
// }}}

struct Edge {
    int to;
    int cost;
    Edge(int t, int c) : to(t), cost(c) {}
};

struct Node {
    int v;
    int d;
    Node(int vv, int dd) : v(vv), d(dd) {}
};

struct NodeGreater {
    bool operator()(Node lhs, Node rhs) const
    {
        return lhs.d > rhs.d;
    }
};

constexpr int INF = numeric_limits<int>::max();

int V;
int E;
int r;
vector<vector<Edge>> G;

void dijkstra(int start, vector<int>& d)
{
    deque<bool> done(V, false);
    priority_queue<Node, vector<Node>, NodeGreater> que;

    d.resize(V);
    fill(begin(d), end(d), INF);
    d[start] = 0;
    que.push(Node(start, 0));

    int n_remain = V;
    while(!que.empty()) {
        Node nodemin = que.top(); que.pop();
        int vmin = nodemin.v;
        int dmin = nodemin.d;

        if(d[vmin] < dmin) continue;

        done[vmin] = true;
        if(--n_remain == 0) break;

        for(Edge e : G[vmin]) {
            if(done[e.to]) continue;
            int d_new = dmin + e.cost;
            if(d_new < d[e.to]) {
                d[e.to] = d_new;
                que.emplace(e.to, d_new);
            }
        }
    }
}

void solve()
{
    vector<int> d(V);
    dijkstra(r, d);

    REP(i, V) {
        if(d[i] == INF) {
            cout << "INF" << "\n";
        }
        else {
            cout << d[i] << "\n";
        }
    }
}

int main()
{
    cin >> V >> E >> r;
    G.resize(V);

    REP(_, E) {
        int s, t, d;
        cin >> s >> t >> d;
        G[s].emplace_back(t, d);
    }

    solve();

    return 0;
}

Measured memory_bytes: 13004
#include <stdio.h>

int main(void){
    int n;
    scanf("%d", &n);

    int a[n];
    int count = 0;
    int j = 1;

    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    for(int i = 0; i < n; i++){
        if(a[i] == j){
            count++;
            j++;
        }
    }

    if(count == 0){
        printf("-1");
        return 0;
    }

    if(count == n){
        printf("0");
        return 0;
    }

    int sum;

    sum = n - count;

    printf("%d", sum);
}

Measured memory_bytes: 896
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val m = sc.nextLong
    val a = new Array[Long](n)
    for (i <- 0 until n) {
      a(i) = sc.nextLong
    }

    // 累積和のmodを計算
    val sum = new Array[Long](n + 1)
    for (i <- 0 until n) {
      sum(i + 1) = (sum(i) + a(i)) % m
    }

    // mで割った余りが等しくなる累積和の組はその差分（その間の値の合算値）がmの倍数（mで割り切れる）
    val mp = scala.collection.mutable.Map[Long, Long]()
    var ans = 0L
    for (i <- sum) {
      ans = ans + mp.get(i).getOrElse(0L)
      if (mp.contains(i)) mp(i) = mp(i) + 1L
      else mp.put(i, 1)
    }

    println(ans)
  }
}


Measured memory_bytes: 69640
public class Main {

  private static void solve() {
    int[] x = na(5);
    for (int i = 0; i < 5; i++) {
      if (x[i] == 0) {
        System.out.println(i + 1);
        return;
      }
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 36672
require "matrix"
n,m,l=gets.split.map(&:to_i)
a,b=[],[];ans=Array.new(n).map{Array.new(l,0)}
n.times{a<< gets.split.map(&:to_i)};a=Matrix[*a]
m.times{b<< gets.split.map(&:to_i)};b=Matrix[*b]
(a*b).to_a.map{|aa|puts aa.join(" ")}



Measured memory_bytes: 9176
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
//int freq[1000000+5];
 
 
int main(){
//	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin>>n;
	std::vector<int> v(n);
	int t;int mx=0;long long c=1;
	bool valid=true;
	for (int i = 0; i < n; ++i)
	{	
 
		scanf("%d",&t);
		if(i!=0){
			if(t==0)
				valid=false;
		}else{
			if(t!=0)
				valid=false;
		}
		mx=max(t,mx);
		v[t]++;
	}
	if(!valid){
		cout<<0;
		return 0;
	}
	for(int i=1;i<mx;i++){
		for(int j=0;j<v[i+1];j++){
			c*=v[i];
			if(c>=998244353){
				c=c%998244353;
			}
		}
	}
	cout<<c;
    return 0;
}

Measured memory_bytes: 640
def main():
    N = int(input())
    n = str(N)
    
    cnt = [[0] * (10) for _ in range(10)]
    
    for i in range(1, N+1):
        a = int(str(i)[0])
        b = i%10
        cnt[a][b] += 1
    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += cnt[i][j]*cnt[j][i]
    print(ans)
main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long 
#define MAX 3020
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf =  2*pow(10,9);
ll modulo = pow(10,9) + 7;


void display(vector<ll> a){
	for(auto f : a)
		cout<<f<<' ';
	cout<<endl<<endl;
}

void deal(){
	ll n;
	cin>>n;
	vector<vector<ll> > arr(n, vector<ll> (n));
	fori(n)
		forj(n)
			cin>>arr[i][j];	
	vector<ll> sms((1<<n), 0);
	fori(1<<n){
		forj(n){
			for(ll k = j+1; k<n; k++){
				if(((1<<j)&i) && ((1<<k)&i))
					sms[i]+=arr[j][k];
			}
		}
	}
	vector<ll> dp((1<<n), -inf);
	dp[0] = 0;
	for(ll i =1; i<(1<<n); i++){
		for(ll j = i; j; j--, j&=i){
			dp[i] = max(dp[i], sms[j] + dp[i^j]);
		}
	}
	cout<<dp[(1<<n)-1];
}

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









Measured memory_bytes: 1280
#include <stdio.h>

int main(void)
{
        int n,i,j,c=1;
        scanf("%d",&n);
        int h[n];
        for(i=0;i<n;i++)
                scanf("%d",&h[i]);

        for(i=1;i<n;i++){
                int d=0;
                for(j=0;j<i;j++){
                        if(h[i]>=h[j]) d++;
                }
                if(i==d) c++;
        }
        printf("%d\n",c);
        return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long n, a, b;
    cin >> n >> a >> b;

    long long sum = a + b, x, y;
    x = n / sum;
    y = n % sum;

    if (y <= a)
        cout << x * a + y << '\n';
    else
        cout << x * a + a << '\n';

    return 0;
}


Measured memory_bytes: 256
h, n = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
#(a,b):=(ダメージ,消費魔力)

dp = [float('inf')] * (h + 1)
dp[0] = 0

for i in range(h + 1):
    for j in range(n):
        if dp[i] == float('inf'):continue
        temp_a = i + ab[j][0] if i + ab[j][0] < h else h
        temp_b = dp[i] + ab[j][1]

        dp[temp_a] = min(dp[temp_a], temp_b)

print(dp[-1])
#print(dp)

Measured memory_bytes: 46300
/*Smile Please!*/
//hp1999
#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast() 	     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;

void solve()
{
 int n;
 
 cin>>n;
 
 vector<int> v(n);
 
 for(int i=0;i<n;++i)
 cin>>v[i];
 
 int tot=accumulate(all(v),0ll);
 
 int ans=inf,sum=0;
 for(int i=0;i<n;++i)
 {
  sum+=v[i];
  tot-=v[i];
  
  ans=min(ans,abs(tot-sum));
 }
 
 cout<<ans;
}

int32_t main()
{
 fast();

 int t=1;
 //cin>>t;
 while(t--)
 {
  solve();
 }

 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n, m, k;
        in >> n >> m >> k;
        bool ans = false;
        for (size_t i = 0; i <= n; i++) {
            for (size_t j = 0; j <= m; j++) {
                if (n*j + m*i - 2 * i*j == k) {
                    ans = true;
                    break;
                }
                if (ans) {
                    break;
                }
            }
            if (ans) {
                break;
            }
        }
        out << (ans ? "Yes" : "No") << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

int main() {
	int X,Y;
	cin >> X >> Y;
  cout << X + Y/2 << endl;
}

Measured memory_bytes: 256
def digits(x):
    i=0
    while (x>0):
        x/=10
        i+=1
    return i

while True:
    try:
        line=raw_input()
        (a,b)=line.split()
        (a,b)=map(int,(a,b))
        print digits(a+b)
    except EOFError: break

Measured memory_bytes: 4204
L, R = list(map(int, input().split()))
if R - L >= 2019:
    print(0)
elif R // 2019 > L // 2019:
    print(0)
else:
    Lm = L % 2019
    Rm = R % 2019
    minM = 9999
    for i in range(Lm, Rm):
        for j in range(i + 1, Rm + 1):
            m = (i * j) % 2019
            if minM > m:
                minM = m
    print(minM)


Measured memory_bytes: 41964
def examA():
    A = I(); B = I(); C = I(); D = I()
    ans = min(A,B) + min(C,D)
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()


Measured memory_bytes: 38256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
#define R register
#define EN std::puts("")
#define LL long long
inline LL read(){
    LL x=0,y=1;
    char c=std::getchar();
    while(c<'0'||c>'9'){if(c=='-') y=0;c=std::getchar();}
    while(c>='0'&&c<='9'){x=x*10+(c^48);c=std::getchar();}
    return y?x:-x;
}
//a:abs大的负数->abs小的负数->小正数->大正数
//b:大正数->小正数->abs小的负数->abs大的负数 
int n,fir;//a[fir]是a数组中第一个非负数
LL k;
LL a[200006],b[200006];
inline int finda(int i,LL ans){
    R int l=1,r=n,mid,ret=0;
    while(l<=r){
        mid=(l+r)>>1;
        if(a[mid]*a[i]<ans) ret=mid,l=mid+1;
        else r=mid-1;
    }
    return ret>=i?(ret-1):ret;//如果ret>=i，说明其中有一对是两个a[i]相乘得到，此时要减1
}
inline int findb(int i,LL ans){
    R int l=1,r=n,mid,ret=0;
    while(l<=r){
        mid=(l+r)>>1;
        if(b[mid]*a[i]<ans) ret=mid,l=mid+1;
        else r=mid-1;
    }
    return (ret+i>n)?(ret-1):ret;//同理，但b是倒序
}
inline int check(LL ans){
    LL nowk=0;
    for(R int i=1;i<fir;i++)//负数 
        nowk+=findb(i,ans);
    for(R int i=fir;i<=n;i++)//正数
        nowk+=finda(i,ans);
    nowk/=2;//去重
    return nowk>=k;
}
inline int cmp(int x,int y){
    return x<y;
}
int main(){
    n=read();k=read();
    for(R int i=1;i<=n;i++) a[i]=read(); 
    std::sort(a+1,a+1+n,cmp);
    fir=n+1;
    for(R int i=1;i<=n;i++)
        if(a[i]>=0){fir=i;break;}
    for(R int i=1;i<=n;i++) b[n-i+1]=a[i];//存入b数组，对负数二分时使用
    R LL l=-1e18,r=1e18,mid,ans;
    while(l<=r){
        mid=(l+r)/2;
        if(check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    std::printf("%lld",ans-1);
    return 0;
}

Measured memory_bytes: 3456
S=input()
P=2019

answer=0
mod_table=[0]*P
mod_table[0]=1
revS=S[::-1]
  
modp=0
mod10=1
for i in range(len(S)):
  mod10=(mod10*10)%P
  #modp=(10*modp+int(revS[i]))%P
  modp=(modp+mod10*int(revS[i]))%P
  mod_table[modp]+=1
    
#print(mod_table)
for i in range(P):
  answer+=mod_table[i]*(mod_table[i]-1)//2
  
print(answer)

Measured memory_bytes: 68512
/*
Dont BLUNDER
*/

// #pragma GCC optimize("O3")
// //#pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


 */
//#define d long double
#define int long long
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define pi acos(-1)

#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod1 = 998244353;
int const mod = 1000000007;
#define bitcount(x)       __builtin_popcountll(x)
#define l first
#define r second
const int inf = LLONG_MAX;
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// * Using PBDS *
/*typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
               os; */



int modexp(int x, int n) {
	if (n == 0) {
		return 1;
	}
	else if (n & 1) {
		return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;
	}
	else {
		return (modexp((x * x) % mod, n / 2) % mod);
	}
}

int modinv(int n)
{
	return modexp(n, mod - 2);
}

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}
bool comp(pair<int, pii> a, pair<int, pii> b) {
	if (a.first == b.first) {
		return a.second.first < b.second.first;
	}
	return a.first < b.first;

}




signed main()
{
	haha
// #ifndef ONLINE_JUDGE

// 	freopen("inp.txt", "r", stdin);

// 	freopen("out1.txt", "w", stdout);
// #endif
	string s, t;
	cin >> s >> t;
	int n = s.length();
	int m = t.length();
	int ans = 100000;
	for (int i = 0; i + m <= n; i++) {
		int c = 0;
		for (int j = 0; j < m; j++) {
			//cout << j << " " << i + j << endl;
			if (t[j] != s[j + i])
				c++;

		}
		//cout << endl;
		// cout << c << endl;
		ans = min(c, ans);

	}
	cout << ans;












}

Measured memory_bytes: 3652
#include<stdio.h>


int main(void){
	int n,m,l;

	scanf("%d",&n);
	m = (n + 1)/1.08;
	l = m * 1.08;

	if( n == l){
		printf("%d\n",m);
	}else{
		printf(":(\n");
	}

	return 0;
}



Measured memory_bytes: 256
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
use std::collections::HashSet;
fn main() {
    let _: usize = read();
    let a: Vec<usize> = read_vec();
    let mut v = vec![true; 1000001];
    let mut hs = HashSet::new();
    for i in &a {
        if hs.contains(i) {
            v[*i] = false;
        }
        else {
            hs.insert(*i);
            let mut j = *i + *i;
            while j < v.len() {
                v[j] = false;
                j += i;
            }
        }
    }
    let ans = a.into_iter().filter(|&x| v[x]).count();
    println!("{}", ans);
}

Measured memory_bytes: 9152
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
l = [a,b,c,d,e]
min = min(l)
f = n // min
g = n % min
if not(g == 0):
    f = f + 1
f = f + 4
print(f)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}



int main()
{
    fastio();
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
	vector<int>cost;
	int n, T, c, t;
	cin >> n >> T;
	for (int i = 0; i < n; i++) {
		cin >> c >> t;
		if (t <= T) {
			cost.push_back(c);
		}
	}
	if (cost.size() == 0) {
		cout << "TLE" << endl;
		return 0;
	}
	sort(cost.begin(), cost.end());
	cout << cost[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long int a,m,n,r,s=0;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>a;
        s=s+a;
    }
    r=n-s;
    if(r>0||r==0)
    cout<<r;
    else
        cout<<-1;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
    double a,b,x;
    cin >> a >> b >> x;
    double ans;
if(a*a*b/2<=x){
    ans=atan((2*a*a*b-2*x)/(a*a*a));
}
else{
    ans=atan(a*b*b/(2*x));
}
cout << fixed << setprecision(10) << ans*180/3.14159265358979;
}

Measured memory_bytes: 384
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
q=int(input())
S = [list(map(int, input().split())) for _ in range(q)]
C=Counter(a)
#print(C)
ans=0
for k,v in C.items():
    ans+=k*v
#print(ans)
for i in range(q):
    if S[i][0] in C:
        if C[S[i][0]]>=1:
            ans+=(S[i][1]-S[i][0])*C[S[i][0]]
            C[S[i][1]]+=C[S[i][0]]
            C[S[i][0]]=0
    print(ans)

Measured memory_bytes: 36520
/*
* Author : Omkar Deshmukh
*/
#include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

#define int long long
#define ll long long
#define endl '\n'
#define all(v) v.bg(), v.end()
#define intvect vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define boolv vector<bool>
#define ld long double
#define deb(x) cout << #x << " " << x << endl;
#define pb push_back
#define pob pop_back
#define ac accumulate
#define F first
#define bg begin
#define me max_element
#define S second
#define ub upper_bound
#define bs binary_search
#define lb lower_bound
#define ull unsigned long long

const ll mod = 1e9 + 7;
const int N = 1e3 + 4;
template <typename... T>
void read(T &... args)
{
    ((cin >> args), ...);
}

template <typename... T>
void write(T &&... args) //rvalue references
{
    ((cout << args), ...);
}

void vjudge()
{
#ifndef ONLINE_JUDGE
    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
const int MAX = 2e4 + 5;
const int INF = 1e9 + 5;
void solve(int test)
{
    int n;
    read(n);
    intvect a(n);
    int ans = 0;
    for (int i = 0; i < n; i++)
        read(a[i]);
    fo(i, n - 1)
    {
        if (a[i] > a[i + 1])
        {
            ans += (a[i] - a[i + 1]);
            a[i + 1] += (a[i] - a[i + 1]);
        }
    }
    write(ans);
}

int32_t main()
{
    vjudge();
    int t = 1;
    // read(t);
    for (int i = 1; i <= t; i++)
        solve(i);
}


Measured memory_bytes: 4776
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
import collections
import heapq


AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
INF = 2 ** 31 - 1
NO_VERTEX = -1


# Prim?????§??????0?????????????°???¨?????¨????±???????
def compute_mst_prim(max_v, adj_list):
    # pred[u]?????????u???????????¨???????????????????????¨???
    pred = collections.defaultdict(lambda: NO_VERTEX)
    # u??¨pred[u]????????¶???????????????key[u]?????\???
    key = collections.defaultdict(lambda: INF)
    key[0] = 0
    # ??????????????????????????????????????\?????¨????????¨??????
    pq = [(key[v], v) for v in range(max_v)]
    heapq.heapify(pq)
    # ????????????????????\?????????????????\??£???????????????????????????
    in_pq = array.array("B", (True for _ in range(max_v)))
    while pq:
        _, u = heapq.heappop(pq)
        in_pq[u] = False
        for v, v_cost in adj_list[u]:
            if in_pq[v]:
                weight = v_cost
                if weight < key[v]:
                    pred[v] = u
                    key[v] = weight
                    heapq.heappush(pq, (weight, v))
                    in_pq[v] = True
    return (pred, key)


def main():
    max_v, max_e = map(int, input().split())
    adjacency_list = collections.defaultdict(set)
    for _ in range(max_e):
        s, t, w = map(int, input().split())
        adjacency_list[s].add(AdjacentVertex(t, w))
        adjacency_list[t].add(AdjacentVertex(s, w))
    (_, key) = compute_mst_prim(max_v, adjacency_list)
    print(sum(key.values()))


if __name__ == '__main__':
    main()

Measured memory_bytes: 50000
#include <bits/stdc++.h>
using namespace std;
long long k;
int main()
{  
   cin >> k;
   long long sum = 7,i;
   for (i = 1; i <= 10000000; i++)
   {
      if (sum % k == 0)
      {
         cout<<i;
         return 0;
      }
      sum = sum % k;
      sum = sum * 10 + 7;
   }
   cout<<-1<<endl;
}

Measured memory_bytes: 3624
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{
  ll s,c;
  cin >> s >> c;

  ll ans = 0;

  if(s * 2 > c)
  {
    ans += c / 2;
  }
  else
  {
    ll buf = c - s * 2; // cの余った数
    ll buf2 = buf / 4;  // 余ったcでsccを作った数

    ans = s + buf2;
  }

  cout << ans << endl;
  



}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
# 2020/04/22
# AtCoder Beginner Contest 142 - C

# Input
n = int(input())
a = list(map(int,input().split()))
tbl = [-1] * (n+1)

# Calc
for i in range(n):
    tbl[a[i]] = i+1

tbl.pop(0)

# Output
print(' '.join(map(str, tbl)))


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n;
  cin >> n;
  map<int, int> a[n];
  for(int i=0;i<n;i++){
    int num;
    cin >> num;
    for(int j=0;j<num;j++){
      int x,y;
      cin >> x >> y;
      x--;
      a[i][x] = y;
    }
  }
  int maxCount = 0;
  for(int64_t i=0;i <= (1<<n);i++){
    bool isFailed = false;
    int count = 0;
    for(int j=0;j<n;j++){
      if(isFailed)break;
      if((i&(1<<j))!=0){
        count++;
        for(auto p:a[j]){
           if((i&(1<<p.first))!=0){
             if(p.second==0) isFailed = true;
           }
           else{
             if(p.second==1) isFailed = true;
           }
           if(isFailed)break;
        }
      }
    }
    if(!isFailed){
      maxCount = max(maxCount,count);
    }
  }
  cout << maxCount << endl;
  return 0;
}




Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
long long ans[10];
int main()
{
    int H, W, N;
    scanf("%d%d%d", &H, &W, &N);
    vector<pair<int, int> > points;
    vector<pair<int, int> > pos;
    for(int i=0; i<N; ++i)
    {
        int x, y; scanf("%d%d", &x, &y);
        --x; --y;
        points.emplace_back(x, y);
        for(int d=-1; d<=1; ++d)
            for(int e=-1; e<=1; ++e)
                pos.emplace_back(x+d, y+e);
    }
    sort(pos.begin(), pos.end());
    sort(points.begin(), points.end());
    pos.resize(unique(pos.begin(), pos.end())-pos.begin());
    ans[0] = 1LL*(H-2)*(W-2);
    for(auto t: pos)
    {
        int x, y; tie(x, y) = t;
        if(x <= 0 || x >= H-1 || y<=0 || y >= W-1) continue;
        ans[0]--;
        int cnt = 0;
        for(int d=x-1; d<=x+1; ++d)
            for(int e=y-1; e<=y+1; ++e)
                if(binary_search(points.begin(), points.end(), make_pair(d,e)))
                    ++cnt;
        ans[cnt]++;
    }
    for(int i=0; i<10; ++i)
        printf("%lld\n", ans[i]);
    return 0;
    
    
    
}

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

int main()
{
    int n=0,cnt=0;
    int a[100000]={0};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++) {
       if(a[a[i]-1]==i+1 && i<a[i]){
           cnt++;
       }
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int A,B;
    cin>>A>>B;
    if(A%3==0||B%3==0||(A+B)%3==0){cout<<"Possible"<<endl;}
    else{cout<<"Impossible"<<endl;}

    return 0; 
}

Measured memory_bytes: 256