akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <sstream>
#include <string>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=100001;
bool vis[N];
vector <int> adj[N];
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll binaryNum[32];
void decToBinary(ll n) 
{ 
    binaryNum[32]={0};
    int i = 0; 
    while (n > 0) { 
        binaryNum[i] = n % 2; 
        n = n / 2; 
        i++; 
    } 
} 

void solve(){
    ll k;
    cin>>k;
    int flag=1;
    ll r = 7%k;
    // if(r==0){
    //     cout<<"1";
    // }
    ll pos=1;
    while(r!=0){
        r = (10*r+7)%k;
        pos++;
        if(pos==k && r!=0){
            flag=0;
            break;
        }
    }
    if(flag){
        cout<<pos;
    }
    else{
        cout<<"-1";
    }
    

}


int main()
{
    // cout<<1<<endl;
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 6156
H, W, K = map(int, input().split())
S = [input() for h in range(H)]

# 横の割り方を全通り試す(2**(H-1))
ans = float('inf')
flag = False
for i in range(2**(H-1)):
    _ans = bin(i).count('1')
    chocos = [list(map(int, S[0]))]
    for j in range(H-1):
        if i >> j & 1:
            chocos.append(list(map(int, S[j+1])))
        else:
            for w in range(W):
                chocos[-1][w] += int(S[j+1][w])
                if chocos[-1][w] > K:
                    flag = True
                    break
            if flag:
                break
    if flag:
        flag = False
        continue
    ns = len(chocos)
    nums = [0] * ns
    is_next = False
    for w in range(W):
        for j in range(ns):
            nums[j] += chocos[j][w]
            if nums[j] > K:
                _ans += 1
                is_next = True
                break   
        if is_next:
            for j in range(ns):
                nums[j] = chocos[j][w]
            is_next = False
    
    ans = min(ans, _ans)

print(ans)

Measured memory_bytes: 52572
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as M
--import qualified Data.Vector as V
--import qualified Data.Vector.Mutable as VM

getBysplit = map read . words <$> getLine

main :: IO()
main = do
  n <- readLn :: IO Int
  l <- getBysplit :: IO [Int]
  print $ solve l


solve :: [Int] -> Int
solve lst = let
              ls = (sort . filter (<0)) lst
              bs = (sort . filter (>=0)) lst
              ans = if even $ length ls
                    then sum bs - sum ls
                    else let
                          temp1 = sum $ init ls
                          temp2 = if length bs > 0 then sum $ tail bs else 0
                          temp3 = if length bs > 0
                                  then  if - last ls > head bs then - last ls - head bs else last ls + head bs
                                  else last ls
                          in - temp1 + temp2 + temp3
              in ans


Measured memory_bytes: 60796
# 要素が入ってない場合の list.index の定義
def myindex(l:list, element, default=-1):
    if element in set(l):
        return l.index(element)
    else:
        return default

def main():
    n = int(input())
    S = []
    ans = ''
    for _ in range(n):
        S.append(list(input()))
    
    S.sort()
    t = S.pop()
    for i, u in enumerate(t):
        okflag = True
        for s in S:
            if myindex(s, u) == -1:
                okflag = False
                break
        if okflag:
            for s in S:
                s.pop(s.index(u))
            ans += u
    ans = sorted(ans)
    print(''.join(ans))

if __name__ == "__main__":
    main()


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

int main(){
    int a, b, tmp;
    for (int i=1; 1; i++){
        cin >> a >> b;
        if (a == 0 && b ==0) break;
        if (a > b){
            tmp = b;
            b = a;
            a = tmp;
        }
        cout << a << " " << b << endl;
    }
    return 0;   
}


Measured memory_bytes: 3052
#include <iostream>
#include <string>
#include <cmath>
#include <limits>
using namespace std;

int main(){
  long int N, D, e, w, a, cou=0;
  double b;
  long int X[2000000], Y[2000000];
  cin >> N >> D;
  for(int i = 0; i < N; ++i) cin >> X[i] >> Y[i];
  
  for(int k = 0; k < N; ++k){
    e = X[k] * X[k];
    w = Y[k] * Y[k];
    a = e + w;
    b = sqrt(a);
    if(b <= D){
      cou = cou + 1;
    }
    else{
      cou = cou + 0;
    }
  }
  cout << cou << endl;
}

Measured memory_bytes: 6332
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

const double eps = 1.0e-10;
double eq(double a, double b){ //a==b
  return abs(b-a)<eps;
}
double gt(double a, double b){ //a>b
  return !eq(a,b) && a > b;
}

int main(){
  while(true){
    int n,m;
    double answer = -1;
    cin >> n >> m;
    if( n == 0 && m == 0 ) break;
    double table[n][n];
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){
	cin >> table[i][j];
      }
    }
    double dp[n][m];
    for(int i = 0; i < n; ++i){
      dp[i][0] = 1.0;
    }
    for(int i = 1; i < m; ++i){
      for(int j = 0; j < n; ++j){
	double maximum = -1;
	for(int k = 0; k < n; ++k){
	  double t = table[k][j] * dp[k][i-1];
	  if( gt(t,maximum) ){
	    maximum=t;
	  }
	}
	dp[j][i] = maximum;
      }
    }
    
    for(int i = 0; i < n; ++i){
      if( gt( dp[i][m-1], answer ) )
	answer = dp[i][m-1];
    }
    printf("%.2lf\n",answer);

  }
  return 0;
}

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

int main()
{
  int n, m, q, a[50], b[50], c[50], d[50];
  cin >> n >> m >> q;
  for (int i = 0; i < q; i++)
  {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  int A[10];
  for (int i = 0; i < n; i++)
  {
    A[i] = 1;
  }

  uint64_t max = 0;
  while (1)
  {
    uint64_t pt = 0;
    for (int i = 0; i < q; i++)
    {
      if (A[b[i] - 1] - A[a[i] - 1] == c[i])
      {
        pt += d[i];
      }
    }

    if (pt > max)
    {
      max = pt;
    }

    for (int i = n - 1; i >= 0; i--)
    {
      if (A[i] == m)
      {
        if (i == 0)
        {
          cout << max << endl;
          return 0;
        }
        continue;
      }

      A[i]++;
      for (int j = i + 1; j < n; j++)
      {
        A[j] = A[i];
      }
      break;
    }
  }
}


Measured memory_bytes: 3636
n = int(input())
lis = []
for i in range(n):
    lis.append(int(input()))

k = 1
ans = 0
m = 0
while k != 2 and m < n:
    k = lis[k - 1]
    m += 1
if k == 2:
    print(m)
else:
    print("-1")


Measured memory_bytes: 12956
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.searchingconstellation", "r", stdin );
	string str = "";

	while (getline (cin, str ) ){
		int len = str.length();
		int m,n;
	
		if (len == 1 && str[0] == '0'){
			break;
		} // end if
		stringstream ssm (str);
		ssm >> m;

		multimap <int, int> conp;
		int i,j,k;

		for (i = 0; i < m; ++i){
			int x, y;
			getline (cin, str );
			stringstream ss(str);
			ss >> x >> y;
			conp.insert (make_pair(x, y ) );
		} // end for

		getline (cin, str );
		stringstream ssn (str );
		ssn >> n;

		multimap <int, int> picp;
		for (i = 0; i < n; ++i){
			int x, y;
			getline (cin, str );
			stringstream ss(str);
			ss >> x >> y;
			picp.insert (make_pair (x, y ) );
		} // end for

		multimap <int, int>::iterator it = conp.begin();

		int cbasex = (*it).first;
		int cbasey = (*it).second;
		
//		cout << "base: (" << cbasex << ',' << cbasey << ')' << endl;

		P cpos[m];
		cpos[0].first = 0;
		cpos[0].second = 0;
		++it;
		for (i = 1; i < m && it != conp.end(); ++i, ++it){
			cpos[i].first = (*it).first - cbasex;
			cpos[i].second = (*it).second - cbasey;
		} // end for

		P ppos[n];
		multimap <int, int>::iterator jt = picp.begin();
		for (j = 0; jt != picp.end(); ++jt, ++j ){
			ppos[j].first  = (*jt).first;
			ppos[j].second = (*jt).second;
		} // end for

		// for debug
/*
		for (i = 0; i < m; ++i){
			cout << '(' << cpos[i].first << ',';
			cout << cpos[i].second << ')' << endl;
		} // end for
		cout << "pic_pos:" << endl;
		for (j = 0; j < n; ++j){
			cout << '(' << ppos[j].first << ',';
			cout << ppos[j].second << ')' << endl;
		} // end for
		cout << endl;
*/
		for (j = 0; j < n; ++j){
			int basex = ppos[j].first;
			int basey = ppos[j].second;
//			cout << "base: (" << basex << ',' << basey << ')' << endl;

			vector <bool> match (m, false);
			match[0] = true;
			for (i = 1; i < m; ++i){
 				int posx = cpos[i].first + basex;
				int posy = cpos[i].second + basey;
//				cout << '(' << posx << ',' << posy << ')' << endl;
				for (k = 0; k < n; ++k){
					if (j == k){
						continue;
					} // end if
					if (posx == ppos[k].first
					&&  posy == ppos[k].second){
						match[i] = true;	
						break;
					} // end if
				} // end if
			} // end for
//			cout << endl;
			if ((int)count (match.begin(), match.end(), true ) == m ){
				cout << (basex - cbasex) << ' ';
				cout << (basey - cbasey) << endl;
				break;
			} // end if
		} // end for
	} // end loop
		
	return 0;
}

Measured memory_bytes: 992
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int R = sc.nextInt();
		R = Math.min(R, N - R);
		int[] P = new int[N];
		for (int i = 0; i < N; i++) {
			P[i] = Integer.parseInt(sc.next()) - 1;
		}
		int one = 0;
		ArrayList<Integer> len = new ArrayList<>();
		boolean[] used = new boolean[N];
		for (int i = 0; i < N; i++) {
			if (used[i]) continue;
			int cur = i;
			int l = 1;
			used[cur] = true;
			while (P[cur] != i) {
				cur = P[cur];
				++l;
				used[cur] = true;
			}
			if (l == 1) {
				one++;
			} else {
				len.add(l);
			}
		}
		Bits bs = new Bits(R + 1);
		bs.bits[0] = 1L;
		for (int i = 0; i < len.size(); i++) {
			bs.shiftLOr(len.get(i));
		}
		boolean ans = false;
		for (int i = 0; i <= one && i <= R; i++) {
			if (bs.get(R - i)) {
				ans = true;
				break;
			}
		}
		System.out.println(ans ? "Yes" : "No");

	}

	static class Bits {
		long[] bits;

		Bits(int size) {
			bits = new long[(size + 63) / 64];
		}

		void shiftLOr(int shift) {
			int m1 = shift >> 6;
			int m2 = shift & 63;
			if (m2 == 0) {
				for (int i = bits.length - 1 - m1; i >= 0; i--) {
					bits[i + m1] |= bits[i];
				}
			} else {
				for (int i = bits.length - 1 - m1; i >= 0; i--) {
					int p1 = i + m1 + 1;
					int p2 = i + m1;
					long v1 = bits[i] >>> (64 - m2);
					long v2 = bits[i] << m2;
					if (p1 < bits.length) {
						bits[p1] |= v1;
					}
					bits[p2] |= v2;
				}
			}
		}

		boolean get(int pos) {
			return ((bits[pos >> 6] >>> (pos & 63)) & 1) != 0;
		}

		void set(int pos) {
			bits[pos >> 6] |= (1L << (pos & 63));
		}
	}

}



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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N;
    string S,T;
    cin >> S;

    REP(i,S.size()){
        if(S.at(i)=='B'){
            if(T.size()>=1){
                T.pop_back();
            }
        }
        else{
            T.push_back(S.at(i));
        }
    }

    cout << T << endl;



}


Measured memory_bytes: 3616
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn str_to_ints(s: String) -> std::vec::Vec<i64> {
    let mut ret = std::vec::Vec::new();
    let ws = s.split_whitespace();
    for w in ws {
        ret.push(w.parse().unwrap());
    }
    ret
}

fn read_ints() -> std::vec::Vec<i64> {
    str_to_ints(read_line())
}

fn main() {
    let s = read_line();
    let mut s_vec: std::vec::Vec<i64> = std::vec::Vec::new();

    for c in s.chars() {
        if c == '1' {
            s_vec.push(1);
        } else {
            s_vec.push(0);
        }
    }

    if s_vec[0] != 1 || s_vec[s.len() - 1] != 0 {
        println!("-1");
        return
    }
    for i in 0..(s.len() / 2) {
        if s_vec[i] != s_vec[s.len() - i - 2] {
            println!("-1");
            return
        }
    }
    let mut s_vec_prime: std::vec::Vec<i64> = std::vec::Vec::new();
    for i in 0..s_vec.len() {
        if i == s_vec.len() - 1 {
            s_vec_prime.push(1);
        } else {
            s_vec_prime.push(s_vec[i]);
        }
    }

    let mut parents: std::vec::Vec<i64> = std::vec::Vec::new();
    let mut tmp_parent: i64 = s.len() as i64;
    for i in (0..(s.len() - 1)).rev() {
        if s_vec_prime[i + 1] == 1 {
            tmp_parent = i as i64 + 2;
        }
        parents.insert(0, tmp_parent);
    }

    for i in 0..(s.len() - 1) {
        println!("{} {}", i+1, parents[i]);
    }
}

Measured memory_bytes: 9596
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int		main(void)
{
	int ans = 1;
	bool f = true;

	for (int i = 0; i < 5; ++i)
	{
		int x;
		cin >> x;
		if (f && x != 0)
		{
			++ans;
		}
		else
		{
			f = false;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3584
S = gets.chomp
K = gets.to_i
N = S.size

list = S.chars

i = 0
k = K

while k > 0 && i < N
  s = list[i]

  if i < N - 1 && s == 'a'
    i += 1
    next
  end

  d = 26 - (s.ord - 97)

  if i == N - 1
    k %= 26
    k.times do
      if s == 'z'
        s = 'a'
      else
        s = s.next
      end
    end
    list[i] = s
  elsif d <= k
    k -= d
    list[i] = 'a'
  end

  i += 1
end

puts list.join


Measured memory_bytes: 11516
#include<bits/stdc++.h>
#define ll long long
#define eps 1e-8

using namespace std;

int main()
{
	cin.tie(0),ios::sync_with_stdio(0);
	int n,m,i,j;
	cin>>n>>m>>i>>j;
	cout<<n*m-i*m-j*(n-i)<<'\n';	
	return 0;
} 

Measured memory_bytes: 256
n,a,b,k=map(int,input().split())
m=998244353
s=[1]
for i in range(n):
    s.append((s[-1]*(n-i)*pow(i+1,m-2,m))%m)
p=0
for i in range(min(n+1,k//a+1)):
    if (k-i*a)%b==0:
        if (k-i*a)//b<=n:
            p=(p+s[i]*s[(k-i*a)//b])%m
print(p)

Measured memory_bytes: 15016
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
    cin>>n;
    int now=0;
    for (int i=0;i<n;++i) {
        int x;scanf("%d",&x);
        if (x==now+1) {
            ++now;
        }
    }
    if (now==0) puts("-1");
    else printf("%d\n",n-now);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using vs = vector<string>;
using pint = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    int ans = 0;
    rep(i, h) {
        rep(j, w) {
            if(s[i][j] == '#') continue;

            vvi dist(h, vi(w, INF));
            queue<P> q;
            
            auto update = [&](int i, int j, int x) {
                if(dist[i][j] != INF) return;
                dist[i][j] = x;
                q.push(P(i, j));
            };

            update(i, j, 0);

            while(!q.empty()) {
                int y = q.front().first;
                int x = q.front().second;
                q.pop();

                rep(dir, 4) {
                    int ny = y + dy[dir], nx = x + dx[dir];
                    if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
                    if(s[ny][nx] == '#') continue;
                    update(ny, nx, dist[y][x] + 1);
                }
            }
            rep(i, h) {
                rep(j, w) {
                    if(dist[i][j] == INF) continue;
                    ans = max(ans, dist[i][j]);
                }
            }
        }
    }

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

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

int main (){
	char c[3][3];
	for (int i = 0; i < 3; i++)for (int j = 0; j < 3; j++) cin >> c[i][j];
	cout << c[0][0] << c[1][1] << c[2][2] << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace shoboi_program
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());  // ユーザーの入力した整数を読み込む
            double enshu = x * 3.141592 *2;
            Console.Write("{0}", enshu); // 文字や数値の出力
        }
    }
}

Measured memory_bytes: 27600
#include <iostream>
#include <random>
#include <fstream> //iostreamのファイル入出力をサポート
#include <vector>
#include <algorithm>
#include <string>
#include <math.h> 
#include <time.h>
#define FOR(i,k,n) for((i)=(k);(i)<(n);(i)++)
#define rep(i,n) for (int i=0;i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define pb push_back
#define all(a) (a).begin(),(a).end()  //greater<int>()
#define ll long long
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define vs vector<string>
#define VI vector<int>
#define vi vector<int>
using namespace std;

int main(){
	int N,i,a;
	int ans1=0;
	int ans2=0;
	int cnt[9];
	rep(i,9){
		cnt[i]=0;
	}
	cin>>N;
	vi A;
	rep(i,N){
		cin>>a;
		A.pb(a);
	}

	rep(i,N){
		if(A[i]/400<8){
			cnt[A[i]/400]=1;
		}

		if(A[i]/400>=8){
			cnt[8]+=1;
		}
	}

	rep(i,8){
		ans1+=cnt[i];
	}

	if(ans1==0&&cnt[8]<=7){
		ans1=1;
		cout<<ans1<<" "<<cnt[8]<<endl;
		return 0;
	}
	if(ans1==0&&cnt[8]>7){
		ans1=1;
		//ans2=8;
		ans2=cnt[8];
		cout<<ans1<<" "<<ans2<<endl;
		return 0;
	}
	if(ans1>0&&ans1+cnt[8]<=7){
		ans2=ans1+cnt[8];
		cout<<ans1<<" "<<ans2<<endl;
		return 0;
	}
	if(ans1>0&&ans1+cnt[8]>7){
		//ans2=8;
		ans2=ans1+cnt[8];
		cout<<ans1<<" "<<ans2<<endl;
		return 0;
	}

	return 0;
}







Measured memory_bytes: 256
N = int(input())
inputData = input().split()
H = [int(x) for x in inputData]

go_right = [0]
num = 0

for i in range(0, N-1):
    if H[i] >= H[i+1]:
        go_right[num] += 1
    else:
        num += 1
        go_right.append(0)
ans = max(go_right)
print(ans)

Measured memory_bytes: 14648
S = input()
P = int(S[0:2])
Q = int(S[2:4])
if 0<P<=12 and 0<Q<=12:
    print("AMBIGUOUS")
elif 0<P<=12 and not (0<Q<=12):
    print("MMYY")
elif 0<Q<=12 and not (0<P<=12):
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 2940
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#define N 200005
#define M 1000005
using namespace std;
int n,tep[30],Cnt[30];
int Length[N],id[N];
int tree[M][27],siz[M];
int num[M][27],cnt=1;
long long ans;
string input[N];
map<string,int> inputnum;
inline void solve(string input)
{
	int i,j;
	int m=input.length(),x=1;
	for(i=0;i<26;i++)
	{
		tep[i]=-1;
	}
	
	for(i=0;i<m;i++)
	{
		if(tep[input[i]-'a']==-1)
		{
			tep[input[i]-'a']=i;
			Cnt[input[i]-'a']++;
		}
	}
	
	if(m==1)
	{
		ans+=Cnt[input[0]-'a']-1;
		return ;
	}
	
	for(i=m-1;i>=0;i--)
	{
		int y=input[i]-'a';
		if(!tree[x][y])
		{
			tree[x][y]=++cnt;
		}
		x=tree[x][y];
		siz[x]++;
		
		if(i==1)
		{
			ans+=num[x][input[0]-'a'];
		}
		
		for(j=0;j<26;j++)
		{
			if((~tep[j])&&tep[j]<i)
			{
				num[x][j]++;
			}
		}
	}
}
bool cmp(int i,int j)
{
	return Length[i]>Length[j];
}
int main(){
	cin>>n;
	int i;
	for(i=1;i<=n;i++)
	{
		cin>>input[i];
		Length[i]=input[i].length();
		id[i]=i;
	}
	sort(id+1,id+n+1,cmp);
	for(i=1;i<=n;i++)
	{
		solve(input[id[i]]);
		if(!inputnum.count(input[id[i]]))
		{
			inputnum[input[id[i]]]=1;
		}
		else
		{	
			ans+=inputnum[input[id[i]]];
		}
	}
	
	cout<<ans<<endl;
}
/*

*/


Measured memory_bytes: 226748
import math
A,B,N=input().split()
A=int(A)
B=int(B)
N=int(N)
if (1<=A<=10**6)and(1<=B<=10**12)and(1<=N<=10**12):
    if N<B:
        a=A*N/B
        a=math.floor(a)
        print(a)
    if N>=B:
        c=A-(A/B)
        c=math.floor(c)
        print(c)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define INF 0x3f3f3f3f
#define FI first
#define SE second
int mod = 1000000007;
const int N = 210;

int main() 
{
  //  freopen("in.txt", "r", stdin);
    int n;
    while (~scanf("%d", &n))
    {
        map<int, int> mp;
        for (int i = 0; i < n; i++)
        {
            int x;
            scanf("%d", &x);
            if (mp.find(x) == mp.end())
                mp[x] = 0;
            mp[x]++;
        }
        map<int, int>::iterator it = mp.begin();
        int ans = 0;
        for (; it != mp.end(); it++)
        {
            if (it->first > it->second)
                ans += it->second;
            else if (it->first < it->second)
                ans += it->second - it->first;
        }
        printf("%d\n", ans);
    }

    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long  
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define pi 3.1415926535
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   ll n,k;
   cin>>n>>k;
   ll ans=0;
   ll psum[n+2]={0};
   ll ssum[n+2]={0};
   int arr[n+2]={0};
   for(int i=1;i<=n+1;i++)
   arr[i]=i;ssum[1]=n;
   for(int i=2;i<=n+1;i++)
   {
       psum[i]=psum[i-1]+i-1;
       ssum[i]=ssum[i-1]+n-i+1;
    //   cout<<psum[i]<<" "<<ssum[i]<<endl;
   }
   for(int i=k;i<=n+1;i++)
   {
       ans+=(ssum[i]-psum[i]+1);
       ans%=mod;
   }
   cout<<ans;
    return 0;
}
//make all values ll

Measured memory_bytes: 7556
import collections
n = int(input())
w = [input() for i in range(n)]
c = collections.Counter(w)
flag = 0
if c.most_common()[0][1] != 1:
    flag = 1
for i in range(n-1):
    if w[i+1][0] != w[i][-1]:
        flag = 1
if flag == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1000000007;
void files(){
 freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);

}
void fast(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

}
int main(){
 fast();
 ll s;
 cin>>s;
 ll dp[s+1];
 memset(dp,0,sizeof dp);
 dp[0]=1;
 dp[1]=0;
 dp[2]=0;
 for(ll i=3; i<=s; i++){
    dp[i]=(dp[i-3]+dp[i-1])%mod;
 }
 cout<<dp[s];
}

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

int main() {
  int N;
  int t[100010];
  int x[100010];
  int y[100010];
  bool available = true;

  cin >> N;
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  for (int i = 1; i <= N; i++) {
    cin >> t[i] >> x[i] >> y[i];
    if ( t[i] % 2 == 0 && (x[i] + y[i]) % 2 == 1 ){
      available = false;
      break;
    } else if ( t[i] % 2 == 1 && (x[i] + y[i]) % 2 == 0 ) {
      available = false;
      break;
    }
  }

  if (available) {
    for (int i = 1; i <= N; i++) {
      if (t[i] - t[i - 1] < abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) {
        available = false;
        break;
      }
     }
  }
    
  if (available) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}



Measured memory_bytes: 1408
#include <stdio.h>

int main()
{
    long long int a,b;
    scanf("%lld %lld",&a,&b);

    if ((a + b) % 2 == 0)
    {
        printf("%lld",(a + b) / 2);
    }
    else
    {
        printf("IMPOSSIBLE");
    }
    
    
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

map<int64_t, int> prime_factor(int64_t n)
{
    map<int64_t, int> ret;
    for (int64_t i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1; 
    return ret;
  }

  int main()
  {
    ll n;
    cin >> n;
    ll ans = 0;
    for (auto p : prime_factor(n))
    {
        ll cnt=1;
        while (p.second>=cnt)
        {
            ans++;
            p.second-=cnt;
            cnt++;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int n;
    cin >> n;
    cout << 48-n << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

int main() {
	int n;
	cin >> n;
	vector<double> x(n), y(n);
	rep(i, n) cin >> x[i] >> y[i];
	vector<int> p(n);
	rep(i, n) p[i] = i;
	double ans = 0.0;
	do {
		double now = 0.0;
		rep(i, n-1) {
			now += sqrt((x[p[i]]-x[p[i+1]])*(x[p[i]]-x[p[i+1]]) + (y[p[i]]-y[p[i+1]])*(y[p[i]]-y[p[i+1]]));
		}
		ans += now;
	} while(next_permutation(all(p)));
	while(n) {
		ans /= (double) n;
		n--;
	}
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;
const int MAX_V = 110;
struct edge{
        int to, cap, rev;
        edge(int t,int c,int r): rev(r),to(t),cap(c) {}
};
struct Flow{
    
    vector<edge> G[MAX_V];//隣接リスト
    bool used[MAX_V];

    void add_edge(int from, int to, int cap){
        G[from].push_back(edge(to, cap, (int)(G[to].size())));//from -> to
        G[to].emplace_back(edge(from, 0, (int)(G[from].size() - 1)));//to -> from
    }

    //増加パスを探す
    int dfs(int v, int t, int f){
        if(v == t) return f;
        used[v] = true;
        for (int i = 0; i < G[v].size(); ++i){
            edge &e = G[v][i];
            if(!used[e.to] && e.cap > 0){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    //sからtへの最大流
    int max_flow(int s, int t){
        int flow = 0;
        while(1){
            memset(used, 0, sizeof(used));
            int f = dfs(s, t, INF);
            if(f == 0) return flow;
            flow += f;
        }
    }
};

int main(void){
    int V, E; cin >> V >> E;
    Flow mf;
    rep(i, E){
        int u, v, c; cin >> u >> v >> c;
        mf.add_edge(u, v, c);
    }
    printf("%d\n", mf.max_flow(0, V - 1));
    return 0;
}


Measured memory_bytes: 3264
#include<stdio.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7,MAX=1e6;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
typedef struct{int SPF[1000001];int Primes[168];int sz;}Template;
struct T{int fact[1000001],inv[1000001];};
Template P;struct T MODINV;
static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
static inline void ready(void)
{
  *P.SPF=1,*P.Primes=2,P.sz=1;
  rep(i,MAX/2)P.SPF[2*(i+1)]=2,P.SPF[2*(i+1)-1]=2*(i+1)-1;
  rep(i,MAX/2-1)
  {
    int x=2*(i+1)+1;if(P.SPF[x]==x){P.Primes[P.sz++]=x;}if(x*x>MAX)break;
    rep(j,P.sz){if(P.Primes[j]<=P.SPF[x]&&x*P.Primes[j]<=MAX)P.SPF[x*P.Primes[j]]=P.Primes[j];else break;}
  }
}
static inline void init(void)
{
  MODINV.fact[0]=1;rep(i,MAX)MODINV.fact[i+1]=1l*MODINV.fact[i]*(i+1)%MOD;
  MODINV.inv[MAX]=MPow(MODINV.fact[MAX],MOD-2);
  rep(i,MAX)MODINV.inv[MAX-1-i]=1l*MODINV.inv[MAX-i]*(MAX-i)%MOD;
}
int main(void)
{
  int N=IN(),A=0,flag=0,invsum=0,lcm=1,x=0,y=0,box[168]={0},unique[9999];
  init();ready();
  rep(i,N)
  {
    A=IN();invsum=(invsum+1l*MODINV.fact[A-1]*MODINV.inv[A]%MOD)%MOD;
    rep(j,168){x=0;while(A%P.Primes[j]==0){A/=P.Primes[j];if(box[j]<++x)box[j]=x;}}
    if(A!=1){rep(j,y){if(unique[j]==A)flag=1;continue;}if(!flag)unique[y++]=A;}flag=0;
  }
  rep(i,168)lcm=1l*lcm*MPow(P.Primes[i],box[i])%MOD;
  rep(i,y)lcm=1l*lcm*unique[i]%MOD;
  return printf("%ld\n",1l*lcm*invsum%MOD),0;
}

Measured memory_bytes: 13336
# -*- coding: utf-8 -*-
"""
The Outcome of Bonze
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0280

"""
import sys


def solve(N, C):
    points = [0] * (N+1)
    for i, c in enumerate(C, start=1):
        pos = N if i%N== 0 else i%N
        if c == 'M':
            points[pos] += 1
        elif c == 'S':
            points[0] += (points[pos] + 1)
            points[pos] = 0
        else:
            points[pos] += (points[0] + 1)
            points[0] = 0
    return sorted(points[1:]) + [points[0]]


def main(args):
    while True:
        N = int(input())
        if N == 0:
            break
        C = input()
        ans = solve(N, C)
        print(*ans, sep=' ')


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 5628
//package A;
//A - Air Conditioner
import java.util.Scanner;

public class Main {
    public void AirFunc(int temperature) {
        if (temperature >= 30)
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Main airObj = new Main();
        while (scanner.hasNext()){
            int n = scanner.nextInt();
            airObj.AirFunc(n);
        }
    }
}


Measured memory_bytes: 35724
#include <bits/stdc++.h>
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#define fst first
#define snd second
#define fore(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define bs binary_search
#define mm(a,b) memset(a,b,sizeof(a))
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int) (n).size())
#define MAXI ((ll)1e16)
#define MINI ((ll)-1e16)
using namespace std;
typedef long long ll;  
const long long M = 1e9 +7;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }        
string s;
ll d;
ll dp[10000][100][2];
ll solve(int i, int res, int k){
	if(i==SZ(s) && res == 0)return 1;
	if(i==SZ(s))return 0;
	ll &r = dp[i][res][k];
	if(~r)return r;
	r = 0;
	if(!k){
		fore(j,0,10){
			r=(r+solve(i+1,(res+j)%d,k))%M;
		}
	}else{
		fore(j,0,(s[i]-'0')+1){
			r=(r+solve(i+1,(res+j)%d,j==(s[i]-'0')))%M;
		}
	}
	return r;
}


int main(){FIN;
	cin >> s >> d;
	mm(dp,-1);
	cout << (solve(0,0,1)-1+M)%M;
}

Measured memory_bytes: 16640
import sys

n, m = map(int, input().split())
h = list(map(int, input().split()))
pp = set()
for _ in range(m):
    a, b = map(int, sys.stdin.readline().split())
    if h[a-1] <= h[b-1]:
        pp.add(a)
    if h[b-1] <= h[a-1]:
        pp.add(b)
print(n-len(pp))

Measured memory_bytes: 84888
fun main(args: Array<String>) {
    val input = readLine()!!.toInt()

    val ans = when (input.toString().length){
        1 -> input
        2 -> 9
        3 -> input - 99 + 9
        4 -> 909
        5 -> input - 9999 + 909
        6 -> 90909
        else -> 0
    }
    print(ans)
}

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

int main()
{
    long long K;
    std::cin >> K;
    // [1, 2, 3, 4, 5, 6, 7, 8, 9] 9個
    // [10, 11, 12, 21, 22, 23, 32, 33, 34, ..., 89, 98, 99] 9*3-1 = 26個
    // [100, 101, 110, 111, 112, ..., 998, 999] 26*3-3 = 75個
    // [1000, 1001, ...]
    std::vector<long long> lunlun_seq;
    lunlun_seq.reserve(K);
    for (long long i = 1; i < 10; i++)
    {
        lunlun_seq.push_back(i);
    }
    long long index = 0;
    while (lunlun_seq.size() < K)
    {
        long long prior = lunlun_seq[index];
        long long first = prior - (prior / 10) * 10;
        if (first != 0)
            lunlun_seq.push_back(10 * prior + first - 1);
        lunlun_seq.push_back(10 * prior + first);
        if (first != 9)
            lunlun_seq.push_back(10 * prior + first + 1);
        index++;
    }
    std::cout << lunlun_seq[K - 1] << std::endl;
}

Measured memory_bytes: 4680
#include "bits/stdc++.h"
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 1000000007;

struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		//assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
}; 
signed main() {
	combination com(2010);
	int s; cin >> s;
	mint ans = 0;
	for (int i = 1; i <= s; i++) {
		if (s - 3 * i < 0)break;
		ans += com(s - 2 * i - 1, s - 3 * i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3672
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <map>

using namespace std;

namespace {
}

int DFS(long long tmpN, int N, unsigned bitFlags) // tmpNは一時的に1e10になる。
{
	if (tmpN > N) {
		return 0;
	}

	int sum = 0;
	if (bitFlags == 0b111) {
		sum = 1;
	}

	sum += DFS(tmpN * 10 + 3, N, bitFlags | 0b100);
	sum += DFS(tmpN * 10 + 5, N, bitFlags | 0b010);
	sum += DFS(tmpN * 10 + 7, N, bitFlags | 0b001);

	return sum;
}

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

	unsigned bitFlags(0b00); // 3, 5, 7 
	cout << DFS(0, N, bitFlags) << endl;

	return 0;
}

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


int main() {
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i=0;i<h;i++) cin >> s[i];
    int ans=0;
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            if (s[i][j]=='.'){
                priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>>> pq;
                pq.push(make_pair(0,make_pair(j,i)));
                vector<vector<int>> t(h,vector<int>(w));
                for (int k=0;k<h;k++) {
                    for (int l=0;l<w;l++) t[k][l]=-1;
                }
                t[i][j]=0;
                int tans=0;
                while(!pq.empty()) {
                    pair<int,pair<int,int>> p=pq.top();
                    pq.pop();
                    int c=p.first;
                    int x=p.second.first;
                    int y=p.second.second;
                    for (int k=0;k<4;k++) {
                        int nx=x+dx[k];
                        int ny=y+dy[k];
                        if (nx>=0 && nx<w && ny>=0 && ny<h) {
                            if (s[ny][nx]=='.' && (t[ny][nx]>c+1 || t[ny][nx]==-1)) {
                                t[ny][nx]=c+1;
                                pq.push(make_pair(c+1,make_pair(nx,ny)));
                                tans=max(tans,c+1);
                            }
                        }
                    }
                }
                ans=max(ans,tans);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int a, b;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      a = i;
      break;
    }
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == 'Z') {
      b = i;
      break;
    }
  }
  cout << b - a + 1 << endl;
}

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

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

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

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

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

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

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

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

fn gcd_list(numbers: Vec<usize>) -> usize {
    fn gcd(a: usize, b: usize) -> usize {
        if b == 0 {
            a
        } else {
            gcd(b, a % b)
        }
    }
    if let Some((&head, tail)) = numbers.split_first() {
        // &b に注意
        tail.iter().fold(head, |a,&b| gcd(a, b))
    } else {
        panic!("Can't unwrap!");
    }
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    println!("{}",gcd_list(a));
}

Measured memory_bytes: 6396
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int val[1000000+1];
int dp[1000000+3][2];//这一位是否要借;
int main(){
	fastio;
	string n;
	cin>>n;
	int len=n.length();
	rep(i,len)
		val[i]=n[i]-'0';
	reverse(val,val+len);
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	rb(i,1,len){
		rb(j,0,9){
			rb(k,0,9){
//				cout<<j<<""
				if(j-k==val[i-1]){
					dp[i][0]=min(dp[i][0],dp[i-1][0]+j+k);
				}
				if(10+j-k==val[i-1]){
					dp[i][1]=min(dp[i][1],dp[i-1][0]+j+k);
				}
				if(j-1-k==val[i-1]){
					dp[i][0]=min(dp[i][0],dp[i-1][1]+j+k);
				}
				if(9+j-k==val[i-1]){
					dp[i][1]=min(dp[i][1],dp[i-1][1]+j+k);
				}
			}
		}
	}
	cout<<min(dp[len][0],dp[len][1]+1)<<endl;
	return 0;
}


Measured memory_bytes: 13084
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        for (long a=0;a<1000;a++) {
            for (long b=0;b<1000;b++) {
                if (a*a*a*a*a+b*b*b*b*b == x) {
                    System.out.println(a + " " + (-b));
                    return;
                } else if (a*a*a*a*a-b*b*b*b*b == x) {
                    System.out.println(a + " " + b);
                    return;
                } else if (-a*a*a*a*a+b*b*b*b*b == x) {
                    System.out.println((-a) + " " + (-b));
                    return;
                } else if (-a*a*a*a*a-b*b*b*b*b == x) {
                    System.out.println((-a) + " " + b);
                    return;
                }
            }
        }

    }
}


Measured memory_bytes: 38804
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int x, y;
    cin >> x >> y;
    if (y < x * 2) {
        cout << "No" << endl;
        return 0;
    }
    if (((y - x * 2) & 1) == 1) {
        cout << "No" << endl;
        return 0;
    }
    int b = (y - 2 * x) / 2;
    int a = x - b;
    if (a < 0) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}


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

int main()
{
  int a,b,c,d;
  cin>> a;
  cin >>b;
  cin>>c;
  d=(a*b);
  if(d<c) 
  {
  cout <<d<<endl;
  }
  else
  {
  cout << c<<endl;
  }
  return 0;
}

Measured memory_bytes: 3544
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
prev = -10
s = 0

for i in range(n):
    s += l2[l1[i]-1]
    if prev == l1[i] - 2 and prev >= 0:
        s += l3[prev]
    prev = l1[i]-1

print(s)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  int N, Ma, Mb; cin >> N >> Ma >> Mb;

  vector <int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++){
    cin >> A[i] >> B[i] >> C[i];
  }

  int DP[N + 1][401][401];
  for (int i = 0; i < N + 1; i++){
    for (int j = 0; j < 401; j++){
      for (int k = 0; k < 401; k++){
        DP[i][j][k] = nmax;
      }
    }
  }
  DP[0][0][0] = 0;

  for (int i = 1; i < N + 1; i++){
    for (int j = 0; j < 401; j++){
      for (int k = 0; k < 401; k++){
        DP[i][j][k] = DP[i - 1][j][k];
        if (j - A[i - 1] >= 0 && k - B[i - 1] >= 0){
          DP[i][j][k] = min(DP[i][j][k], DP[i - 1][j-A[i-1]][k-B[i-1]] + C[i-1]);
        }
      }
    }
  }

  int ans = nmax;
  for (int i = 1; i * Ma <= 400 && i * Mb <= 400; i++){
    ans = min(ans, DP[N][i * Ma][i * Mb]);
  }

  if (ans == nmax) ans = -1;
  cout << ans << endl;
    
  return 0;
}


Measured memory_bytes: 25984
n,m=map(int,input().split())
l=[]
l=sorted([list(map(int,input().split())) for i in range(m)],key=lambda x:x[1])
ans=1
now=l[0][1]-1

for x,y in l[1:]:
    if x<=now<=y-1:continue
    ans+=1
    now=y-1
print(ans)

Measured memory_bytes: 29848
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        var limit = input[0];

        for (int i = 0; i <= limit; i++)
        {
            var tenK = 10000 * i;
            for (int j = 0; i + j <= limit; j++)
            {
                var fiveK = 5000 * j;
                var oneK = 1000 * (limit - i - j);
                if (tenK + fiveK + oneK == input[1])
                {
                    Console.WriteLine($"{i} {j} {limit - i - j}");
                    return;
                }
            }
        }

        Console.WriteLine("-1 -1 -1");
    }
}

Measured memory_bytes: 13268