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

int N;
string S;

int main() {
    cin >> N >> S;

    string ans = "";

    for (int i = 0; i < S.length(); i++) {
        if ((int)(S[i] + N) <= (int)('Z')) {
            ans += (char)((int)(S[i] + N));
        }
        else {
            ans += (char)(( (int)( S[i] + N ) - 26 ));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
int main(){
	long long int k,a,b;
	scanf("%lld%lld%lld",&k,&a,&b);
	long long int ans=0;
	k++;
	if(k<a){
		ans=k;
	}else{
		ans=a;
		k=k-a;
		if(b-a>2){
			ans=ans+(k/2)*(b-a)+k%2;
		}else{
			ans=ans+k;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換

int main() {
string a,b;
cin>>a>>b;
int A = a.size(),B = b.size();
if(A < B){
    cout<<"LESS"<<endl;
}else if(A > B){
    cout<<"GREATER"<<endl;
}else
{
    rep(i,A){
        if(a[i] < b[i]){
            cout<<"LESS"<<endl;
            return 0;
        }else if(a[i] > b[i]){
             cout<<"GREATER"<<endl;
             return 0;
        }
    }
    cout<<"EQUAL"<<endl;
}

   return 0;
}


Measured memory_bytes: 3600
import sys
import math
input = sys.stdin.readline

N = int(input())
x = []
y = []

for i in range(N):
    p, q = map(int, input().split())
    x.append(p)
    y.append(q)

ans = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
#        print ("i="+str(i)+", j="+str(j))
#        print ("xi="+str(x[i])+", xj="+str(x[j]))
#        print ("yi="+str(y[i])+", yj="+str(y[j]))
        ans += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)

ans = ans / N
print (ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<algorithm>

int main()
{
	int m, n;
	m = 1;
	n = 1;
	while (m <= 9) {
		while (n <= 9) {
			printf("%dx%d=%d\n", m, n,  m * n);
			n++;
		}
		n = 1;
		m++;
	}
    return 0;
}

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

using namespace std;

int main()
{
    int a, b, c = 0;

    cin >> a;
    cin >> b;
    cin >> c;

    string res = "No";
    if (a == b)
        res = a != c ? "Yes" : "No";
    if (b == c)
        res = b != a ? "Yes" : "No";
    if (a == c)
        res = a != b ? "Yes" : "No";

    cout << res;
}

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

int main() {
  long long int i,n,m,ans=1,ll=1000000007;
  
  cin>>n>>m;
  if(n==m){
    for(i=1;i<=n;i++)
      ans=(ans*i)%ll;
    for(i=1;i<=m;i++)
      ans=(ans*i)%ll;
    cout<<(2*ans)%ll;
  }
  
 else if(n+1==m || n==m+1){
    for(i=1;i<=n;i++)
      ans=(ans*i)%ll;
    for(i=1;i<=m;i++)
      ans=(ans*i)%ll;
    cout<<(ans)%ll;
  
  }
  
  else cout<<0;
}

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

#define all(v) begin(v), end(v)
#define endl '\n';
#define int long long
#define pii pair<int, int>

int32_t main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);

    string s; cin >> s;
    cout << s.substr(0, 3) << endl;

}

Measured memory_bytes: 3640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func rScan() []rune {
	return []rune(Scan())
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func mod(x, d int) int {
	x %= d
	if x < 0 {
		x += d
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := -int(1e+18)
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := int(1e+18)
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}
func bPrint(f bool, x string, y string) {
	if f {
		fmt.Println(x)
	} else {
		fmt.Println(y)
	}
}
func iSSPrint(x []int) {
	fmt.Println(strings.Trim(fmt.Sprint(x), "[]"))
}

var lp1 int = 1000000007
var lp2 int = 998244353

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, lp1)
	sc.Split(bufio.ScanWords)
	s := Scan()
	if s[len(s)-1] == 's' {
		fmt.Println(s + "es")
	} else {
		fmt.Println(s + "s")
	}
}


Measured memory_bytes: 1772
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	print(max(a * b, c * d));
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#n=int(input())
x,y,z=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

temp1=x
temp2=y
temp3=z
x,y=y,x
x,z=z,x

print("{0} {1} {2} ".format(x,y,z))



Measured memory_bytes: 2940
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = rr()
sn = 0
for i in n:
    sn += int(i)
print('Yes' if int(n) % sn == 0 else 'No')








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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val,typename Number>
//use ll or int for gcd
Val gcd(Val a, Val b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//count vector and return pair (count,vector item)
template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->push_back(make_pair(count,A->at(i)));
        count = 1;
      }
    }else{
      R->push_back(make_pair(count,A->at(i)));
      count = 1;
    }
  }
}

//---------------------------------------------------------------

int main(){
  int N;
  string ans = "Yes";
  cin>>N;
  vector<pair<ll,ll>> A;
  rep(i,N){
    ll a,b;
    cin>>a>>b;
    A.emplace_back(b,a);
  }
  sort(A.begin(),A.end());
  ll now = 0;
  rep(i,N){
    now+=A.at(i).second;
    if(now>A.at(i).first){
      ans="No";
      break;
    }
  }

  cout<<ans<<endl;

}


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

int main(){
  int A, B, T, result=0;
  string S;
  cin >> A >> B >> T;
  int j=1;
  for(int i=0;i<T+1;i++){
    if(i!=0&&i%(A*j)==0){
  	  result += B;
      j++;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;

// ??°?????????????????¬??????
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;


int main() {
  int a, b;
  while(true) {
    scanf("%d %d", &a, &b);
    if(a==0 && b==0) break;
    else printf("%d %d\n", min(a,b), max(a,b));
  }
  return 0;
}

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

int main(){
  int N,K,ans;
  long long Y;
  ans=0;
 cin>>N>>Y;
for(int i=0;i<N+1;i++){
  for(int j=0;j<N-i+1;j++){
    if(N-i-j>=0){
    if((N-j-i)*10000+j*5000+i*1000==Y){
      cout<<(N-j-i)<<" "<<j<<" "<<i<<endl;
      i=1000000;
      break;
    }
    }
  }
  if(i==N){
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
  }
}
}

Measured memory_bytes: 256
def digits(x)
    x.to_s.length
end

n = gets.to_i
ans = digits(n)

# a<=√Nまでで良い理由は、
# AとBの間に暗黙の大小関係として A≤Bが成立しているから

(2..Math.sqrt(n).ceil).each do |a|
    next if n % a != 0
    b = n/a
    t = [digits(a),digits(b)].max
    ans = t if t < ans
end
puts ans

Measured memory_bytes: 1788
H,W=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]
A=[list(map(int,input().split())) for i in range(H)]
for k in range(10):
  for i in range(10):
    for j in range(10):
      if c[i][j]>c[i][k]+c[k][j]:
        c[i][j]=c[i][k]+c[k][j]
ans=0
for i in range(H):
  for j in range(W):
    if A[i][j]!=-1:
      ans+=c[A[i][j]][1]
print(ans)


Measured memory_bytes: 3444
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            int C = line[2];
            Console.WriteLine(A * C <= B ? C : B / A);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repv(i,a,b) for(ll i=b-1;i>=a;i--)
#define MAXN 300005
#define endl "\n"

ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;}

int n,d;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>d;
    int cnt=n/(2*d+1);
    int cnt2=n%(2*d+1);
    if(cnt2>0) cout<<cnt+1<<endl;
    else cout<<cnt<<endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
        static void Main(string[] args)
        {
          //入力を受け取る
          var N = int.Parse(Console.ReadLine());
          int[] S = new int[N];
          for(int i = 0; i < N ; i++){
            S[i] = int.Parse(Console.ReadLine());
          }
          var res = S.Sum();
          Array.Sort(S);
          //小さいものが10の倍数でなくなるまで除いていく
          if(res%10 == 0){
            for(int i = 0; i < N ; i++){
              var org = res-S[i];
              if(org%10 != 0){
                res = org;
                break;
              }else if(i == N-1){
                res = 0;
              }
            }
          }

          //var A1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

          Console.WriteLine(res);
        }
}


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

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

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
		Sequence solver = new Sequence();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}


	static class Sequence {
		private int n;
		private long a[];

		private long output;
		private Scanner scanner;

		public Sequence() {
			this.scanner = new Scanner(System.in);
		}

		public void readInput() {
			n = Integer.parseInt(scanner.next());
			a = new long[n];
			for(int i=0; i<n; i++) {
				a[i] = Integer.parseInt(scanner.next());
			}
		}

		private int count(int sign) {
			int count=0;
			long sum=0;
			for(int i=0; i<n; i++) {
				sum += a[i];
				if(i%2==sign) {
					// a[i]までの合計を正にするとき
					if(sum<=0) {
						count += 1-sum;
						sum = 1;
					}
				} else {
					// a[i]までの合計を負にするとき
					if(0<=sum) {
						count += 1+sum;
						sum = -1;
					}
				}
			}
			return count;
		}

		public void solve() {

			/* https://atcoder.jp/contests/abc059/submissions/8183898 */
			long sum1 = 0;
			long count1 = 0;
			long sum2 = 0;
			long count2 = 0;
			for (int i = 0; i < n; i++) {
			    sum1 += a[i];
			    sum2 += a[i];
			    if (i % 2 == 0) {
			        if (sum1 <= 0) {
			            count1 += 1 - sum1;
			            sum1 = 1;
			        }
			        if (sum2 >= 0) {
			            count2 += sum2 + 1;
			            sum2 = -1;
			        }
			    } else {
			        if (sum2 <= 0) {
			            count2 += 1 - sum2;
			            sum2 = 1;
			        }
			        if (sum1 >= 0) {
			            count1 += sum1 + 1;
			            sum1 = -1;
			        }
			    }
			}
			output = Math.min(count1,count2);
		}

		public void writeOutput() {
			System.out.println(output);
		}
	}

}

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

using namespace std;
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

int main(){
    int n,ans,MAX=0,cnt=0;
    cin>>n;

    repr(i,n,1){
        int N=i;
        while(N%2==0){
            cnt++;
            N/=2;
        }
        if(cnt>=MAX){

            MAX=cnt;
            ans=i;
        }
        cnt=0;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector as V
import Data.Tuple (swap)
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.List (intercalate)

main :: IO ()
main = do
  let
    fromEdgesToAdjacencyVectorN :: Int -> [(Int, Int)] -> V.Vector [Int]
    fromEdgesToAdjacencyVectorN n = V.accum (flip (:)) (V.replicate n [])
    fromAdjacencyVectorToTree :: V.Vector [Int] -> Int -> Tree Int
    fromAdjacencyVectorToTree adjacency root = Node root (map (f root) (adjacency V.! root))
      where
        f :: Int -> Int -> Tree Int
        f p i = Node i (map (f i) . filter (/= p) $ adjacency V.! i)
    fromTreeToCumCounts counts tree = do
      v <- VU.thaw counts
      let
        f c (Node x ts) = do
                            VUM.write v x c'
                            mapM_ (f c') ts
          where
            c' = c + (counts VU.! x)
      f 0 tree
      VU.freeze v
  [n, q] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  abs <- sequence . replicate (n - 1) $ unsafeListToPair . map (pred . unsafeTextToInt) . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    adjacency = fromEdgesToAdjacencyVectorN n . ((++) <$> id <*> map swap) $ abs :: V.Vector [Int]
    tree = fromAdjacencyVectorToTree adjacency 0 :: Tree Int
  pxs <- sequence . replicate q $ ((,) <$> pred . fst <*> snd) . unsafeListToPair . map unsafeTextToInt . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    counts = VU.accum (+) (VU.replicate n 0) $ pxs :: VU.Vector Int
  cumCounts <- fromTreeToCumCounts counts tree
  putStrLn . intercalate " " . map show . VU.toList $ cumCounts

data Tree a = Node a [Tree a]

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair [x, y] = (x, y)
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 187040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            sS = System.Console.ReadLine().Trim().Split(' ');
            List<int> lstB = new List<int>();
            for (int i = 0; i < sS.Length; i++) { lstB.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<int> lstA = new List<int>();
            lstA.Add(lstB[0]);
            for (int i = 0; i < lstB.Count - 1; i++)
            {
                lstA.Add(Math.Min(lstB[i], lstB[i + 1]));
            }
            lstA.Add(lstB[lstB.Count - 1]);

            // 出力
            System.Console.WriteLine("{0}", lstA.Sum().ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long ans = 0;
        ans += b / c - (a - 1) / c;
        ans += b / d - (a - 1) / d;
        ans -= b / Lcm(c, d) - (a - 1) / Lcm(c, d);
        Console.WriteLine(b - a + 1 - ans);
    }

    static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    static long Gcd(long a, long b)
    {
        long r = a % b;
        if (r == 0) return b;
        return Gcd(b, r);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

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

int main() {
  int n;
  cin >> n;
  n %= 10;
  if ((n == 2) || (n == 4) || (n == 5) || (n == 7) || (n == 9))
    cout << "hon" << endl;
  else if ((n == 0) || (n == 1) || (n == 6) || (n == 8))
    cout << "pon" << endl;
  else
    cout << "bon" << endl;
  return 0;
}


Measured memory_bytes: 3624
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<int, int> II;

vector<vector<II>> e;
vector<int> vis;
vector<int> col;
int mx;

void dfs(int n, int c) {
	if (vis[n]) return;
	vis[n] = 1;
	int nc = 0;
	for (auto kv : e[n]) {
		if (col[kv.second]) {
			continue;
		}
		if (++nc == c) {
			++nc;
		}
		col[kv.second] = nc;
		dfs(kv.first, nc);
		mx = max(mx, nc);
	}
}

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		mx = 0;
		int n = -1;
		cin >> n;
		if (n < 0) return 0;
		e.clear();
		e.resize(n);
		col.clear();
		col.resize(n);
		vis.clear();
		vis.resize(n);
		for (int i = 0; i < n - 1; ++i) {
			int a, b;
			cin >> a >> b;
			--a, --b;
			e[a].push_back({ b, i });
			e[b].push_back({ a, i });
		}
		dfs(0, 0);
		cout << mx << endl;
		for (int i = 0; i < n - 1; ++i) {
			cout << col[i] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#define N 300005
using namespace std;

typedef long long ll;
ll fac[N]={1,1}, inv[N]={1,1}, fiv[N]={1,1};
ll n, M = 998244353, A, B, k, ans;

ll c(ll p) {return fac[n] * fiv[n-p] % M * fiv[p] % M;}

int main()
{
	ll i, j;
	cin >> n >> A >> B >> k;
	for(i=2; i<=n; i++) {
		fac[i] = fac[i-1] * i % M;
		inv[i] = inv[M%i] * (M-M/i) % M;
		fiv[i] = fiv[i-1] * inv[i] % M;
	}
	for (i = 0; i * A <= k && i <= n; i++) {
		if ((k - i * A) % B) continue;
		j = (k - i * A) / B;
		if (j <= n) ans = (ans + (c(i) * c(j)) % M) % M;
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 7296
import java.util.*;

class Main {
    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        int w = sc.nextInt();
        int n = sc.nextInt();

        int[] member = new int[w];
        for (int m = 0; m < w; m++) {
            member[m] = m;
        }

        for (int t = 0; t < n; t++) {
            String[] bar = sc.next().split(",");
            int a = Integer.parseInt(bar[0]) - 1;
            int b = Integer.parseInt(bar[1]) - 1;

            int tmp = member[b];
            member[b] = member[a];
            member[a] = tmp;
        }

        for (int m = 0; m < w; m++) {
            System.out.println(member[m] + 1);
        }
    }
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;
    long double ans=0,d,n,m;
    cin>>n>>m>>d;

    if(d == 0){
        ans = (m-1)/n;
    }else{
        ans = (m-1)*(((n-d)*2)/(n*n));
    }
    
    cout <<fixed<<setprecision(16)<<ans << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a=0,b=0,c=0;
  cin>>N;
  for(int i=0;i<N;i++){
    int A;
    cin>>A;
    if(A%4==0)
      a++;
    else if(A%2==0)
      b++;
    else
      c++;
  }
  if(c<=a)
    cout<<"Yes"<<endl;
  else if(c==a+1 && b==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

int main() {

  int N;
  cin>>N;

  int a[N];
  for(int i = 1; i <= N; i++) cin>>a[i];

  for(int i = 1; i <= N; i++) {
    cout<<"node "<<i<<": key = "<<a[i]<<", ";
    if(i != 1) cout<<"parent key = "<<a[i/2]<<", ";
    if(i*2 <= N) cout<<"left key = "<<a[i*2]<<", ";
    if(i*2+1 <= N) cout<<"right key = "<<a[i*2+1]<<", ";
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3092
import heapq

n, m = map(int, input().split())
a = list(int(i)*(-1) for i in input().split())

heapq.heapify(a)
for i in range(m):
    max = heapq.heappop(a)
    heapq.heappush(a,int(max/2))

print(sum(a) * (-1))



Measured memory_bytes: 14380
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll a, b, n;
  cin >> a >> b >> n;

  if (n < b) { // Here, max is n.
    ll diff = (a*n)/b;
    cout << diff << endl;
    return 0;
  }

  // Here, n >= b.
  // we use b-1.
  ll diff = (a*(b-1))/b;
  cout << diff << endl;
}


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

int main()
{
    int n, m;
    int sum = 0;
    cin >> n >> m;
    vector<vector<int>> vecA(n, vector<int>(m));
    vector<int> vecb(m);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> vecA.at(i).at(j);
        }
    }

    for (int i = 0; i < m; i++) {
        cin >> vecb.at(i);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            sum += vecA.at(i).at(j) * vecb.at(j);
        }
        cout << sum << endl;
        sum = 0;
    }
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long
#define MOD ((int)1e9 + 7)

using namespace std;

const ll mx = 1e5 + 1;
ll fact[mx];

ll pow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return pow(n, p - 2, p);
}

void init()
{
    fact[0] = 1;

    for (ll i = 1; i <= mx; i++)
    {
        fact[i] = (fact[i - 1] * i) % MOD;
    }
}

ll nCr(ll n, ll r, ll p)
{
    if (n < r)
        return 0;

    if (r == 0)
        return 1;
    return (fact[n] * modInverse(fact[r], p) % p *
            modInverse(fact[n - r], p) % p) %
           p;
}

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

    init();

    vector<ll> arr(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

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

    ll ans = 0;
    ll right = 0;

    for (int i = 0; i < n; i++)
    {
        arr[i] %= MOD;
        ans += (nCr(i, k - 1, MOD) * arr[i]) % MOD;
        ans = (ans + MOD) % MOD;
        right += (nCr(n - i - 1, k - 1, MOD) * arr[i]) % MOD;
        ans = (ans + MOD) % MOD;
    }

    ans -= right;
    ans = (ans + MOD) % MOD;

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
typedef unsigned long long int llu;
typedef long long int lli;
int main(void)
{
    llu n,m;
    llu ans=0;

    scanf("%llu %llu",&n,&m);
    if(n<=m/2){
        ans+=n;
        m-=n*2;
        ans+=m/4;
    }
    else{
        ans=m/2;
    }

    printf("%llu\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
unordered_map<string,int>m;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	int n,i;
	long long ans=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>s;
		sort(s.begin(),s.end());
		ans+=m[s];
		m[s]++;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 10660
<?php

$arrX = array();
$arrY = array();
$posX = array();
$posY = array();
fscanf(STDIN, "%d %d", $N, $K);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d", $x[$i], $y[$i]);
    $arrX[$x[$i]]++;
    $arrY[$y[$i]]++;
}
ksort($arrX);
ksort($arrY);

$posX = array_keys($arrX);
$posY = array_keys($arrY);

$idxX = array_flip($posX);
$idxY = array_flip($posY);

$mapXY = array(array());
for ($i = 0; $i < $N; $i++) {
    $xx = $idxX[$x[$i]];
    $yy = $idxY[$y[$i]];
    $mapXY[$xx][$yy]++;
}

for ($x = 0; $x < count($idxX); $x++) {
    for ($y = 0; $y < count($idxY); $y++) {
        $mapXY[$x][$y] = $mapXY[$x-1][$y] + $mapXY[$x][$y-1] - $mapXY[$x-1][$y-1] + $mapXY[$x][$y];
    }
}

$ans = PHP_INT_MAX;

for ($x1 = 0  ; $x1 < count($idxX); $x1++) {
for ($x2 = $x1; $x2 < count($idxX); $x2++) {
for ($y1 = 0  ; $y1 < count($idxY); $y1++) {
for ($y2 = $y1; $y2 < count($idxY); $y2++) {
    $posX1 = $posX[$x1];
    $posX2 = $posX[$x2];
    $posY1 = $posY[$y1];
    $posY2 = $posY[$y2];
    $numXY = $mapXY[$x2][$y2] - $mapXY[$x1-1][$y2] - $mapXY[$x2][$y1-1] + $mapXY[$x1-1][$y1-1];
    $width = max(1, $posX2 - $posX1);
    $height = max(1, $posY2 - $posY1);
    if ($numXY >= $K) {
        $ans = min($ans, $width * $height);
    }
}    
}    
}    
}

echo $ans . PHP_EOL;


Measured memory_bytes: 4728
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      h: usize,
      w: usize,
      k: usize,
      c: [Bytes; h]
   }

   let mut ans = 0;
   for n in 0..(1 << h) {
      for m in 0..(1 << w) {
         let mut x = 0;
         for i in 0..h {
            for j in 0..w {
               if (n >> i) & 1 == 0 && (m >> j) & 1 == 0 && c[i][j] == b'#' {
                  x += 1;
               }
            }
         }
         if x == k {
            ans += 1;
         }
      }
   }
   println!("{}", ans);
}


Measured memory_bytes: 2180
#include<stdio.h>
int main()
{
    int n,i,c=0;

    scanf("%d",&n);

    int a[n];

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

        if(a[i]!= i+1)
        {
             c++;
        }
    }

    if(c> 2)
        printf("NO\n");
    else
        printf("YES\n");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

ll num(ll n){
    if(n==0)return 0;
    else return 2*num(n/2)+1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    cout<<num(n);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char num[1001];
	int sum,i;

	while(1){
	scanf("%s",num);
	i=0;
	sum=0;

	while(num[i]!=0)
		sum += num[i++] - '0';

	if(!sum)
		break;
	printf("%d\n", sum);
	}
	return 0;
}

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

using namespace std;

int main()
{
	int R;

	cin >> R;

	if (R < 1200) {
		printf("ABC");
	}
	else if (R < 2800) {
		printf("ARC");
	}
	else {
		printf("AGC");
	}

    return 0;
}



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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N, A, B;
  cin >> N >> A >> B;

  cout << (N / (A + B) * A) + min(N % (A + B), A) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int read();
int n, c, l[51];
double f[502][102], res, cnt;
int main() {
    n = read(), c = read();
    for (int i = 0; i < n; ++i) l[i] = read();
    sort(l, l + n);
    while (1) {
        for (int i = 0; i <= c * n; ++i)
            for (int s = 0; s < (1 << n - 1); ++s) f[i][s] = 0;
        f[l[n - 1] * n][0] = 1;
        for (int i = 1, p; i <= c * n; ++i) {
            if ((p = i % n - 1) < 0) continue;
            for (int j = i; j <= c * n; ++j)
                for (int s = 0; s < (1 << n - 1); ++s)
                    if (~s >> p & 1)
                        f[min(c * n, max(j, i + l[p] * n))][s | (1 << p)] +=
                            f[j][s];
        }
        res += f[c * n][(1 << n - 1) - 1], ++cnt;
        if (!next_permutation(l, l + n - 1)) break;
    }
    printf("%.13lf\n", (double)res / cnt / pow(c, n - 1));
    return 0;
}

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
#define ll long long
#define iiMPQ priority_queue<ii,vector<ii>,greater<ii> >
#define MPQ priority_queue<int,vector<int>,greater<int> >
#define PQ priority_queue<int>
#define iiPQ priority_queue<ii>
#define US unordered_set<int>
#define UMS unordered_multiset<int>
#define UM unordered_map<int>
#define iiUS unordered_set<ii>
#define ST stack<int>
#define MS multiset<int>
#define scan1(n) cin>>n
#define scan2(a,b) cin>>a>>b
#define scan3(a,b,c) cin>>a>>b>>c
#define print(n) cout<<n
#define println(n) cout<<n<<"\n"
#define vi vector<int>
#define vii vector<ii>
#define viii vector<iii>
#define fi first
#define se second
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,s,e) for(int i=s;i<e;++i)
#define REPS(i,s,e,st) for(int i=s;i<e;i+=st)
#define rep(i,n) for(int i=n-1;i>=0;--i)
#define repr(i,s,e) for(int i=s;i>=e;--i)
#define reps(i,s,e,st) for(int i=s;i>=e;i-=st)
#define SET(arr,k) memset(arr,k,sizeof arr)
#define speed ios::sync_with_stdio(0); cin.tie(0);
#define mp make_pair
#define pb push_back
#define Qu queue
#define Vt vector
#define Dq deque
#define prints(n) cout << n << " ";

long long power(int a,int b,int c) {
  if (b == 0) return 1%c; 
  long long temp = power(a, b/2,c)%c;
  if (b%2 == 0) return (temp * temp)%c;
  return ((a * temp)%c * temp)%c;
}

void m1(){
  int k; cin >> k;
  if(k%2==0 || k%5 ==0){
  	cout << -1;
    return;
  }
  if(k == 1 || k == 7){
  	cout << 1;
    return;
  }
  int cur = 1;
  for(int i=2;i<=k;++i){
    cur = (cur + power(10,i-1,k)+k*1000000)%k;
  	if((7*cur)%k == 0){
    	cout << i;
      return;
    }
  }
  cout << -1;
}
/* 
void m2(){
  int t; scan1(t);
  while(t--) m1();
}
*/
 
signed main(){
  speed;
  //freopen("in.txt","r",stdin);
  m1();
  //m2();
}


Measured memory_bytes: 3624
import java.util.*;
import java.io.*;

public class Main {

  private static void solve() {
    int n = nextInt();
    int k = nextInt();

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

    Arrays.sort(a);

    int[][] dp = new int[2][k + 1];

    for (int i = 0; i < a[0]; i++) {
      dp[0][i] = 1;
      dp[1][i] = 0;
    }

    for (int j = 0; j <= k; j++) {
      for (int i = 0; i < 2; i++) {
        boolean wins = false;
        for (int l = 0; l < n && !wins; l++) {
          if (j - a[l] >= 0) {
            wins = dp[1 - i][j - a[l]] == i;
          }
        }

        dp[i][j] = wins ? i : 1 - i;
      }
    }

    System.out.println(dp[0][k] == 0 ? "First" : "Second");
  }
  
  private static void run() {
    br = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);

    solve();

    out.close();
  }

  private static StringTokenizer st;
  private static BufferedReader br;
  private static PrintWriter out;

  private static String next() {
    while (st == null || !st.hasMoreElements()) {
      String s;
      try {
        s = br.readLine();
      } catch (IOException e) {
        return null;
      }
      st = new StringTokenizer(s);
    }
    return st.nextToken();
  }

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

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

  public static void main(String[] args) {
    run();
  }
}

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

int main(void){
    long n;
    cin >> n;
    vector<long> a(n);
    vector<long> fsum(n);
    vector<long> bsum(n);
    for(long i=0; i<n; i++){
        cin >> a[i];
    }
    fsum[0] = labs(a[0]-0);
    for(long i=1; i<n; i++){
        fsum[i]=fsum[i-1]+labs(a[i]-a[i-1]);
    }
    bsum[n-1] = labs(a[n-1]-0);
    for(long i=n-2; i>=0; i--){
        bsum[i]=bsum[i+1]+labs(a[i]-a[i+1]);
    }
    cout << labs(a[1]-0) + bsum[1] << endl;
    for(long i=1; i<n-1; i++){
        cout << fsum[i-1]+labs(a[i+1]-a[i-1])+bsum[i+1] << endl;
    }
    cout << fsum[n-2]+labs(a[n-2]-0) << endl;
    return 0;
}


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

using namespace std;

int main()
{
  int N;
  int a[100];
  cin>> N;
  for(int i=0;i<N;i++)cin>> a[i];

  int ret=0;
  sort(a,a+N,greater<int>());
  for(int i=0;i<N;i++)
  {
    if(i%2==0)ret+=a[i];
    else ret-=a[i];
  }
  cout<< ret<< endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a,b,c;

	scanf("%d %d %d",&a,&b,&c);
	if(a==b||a==c||b==c){
		if(a==b&&a==c&&b==c){
			puts("No");
		}
		else puts("Yes");
	}
	else puts("No");

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	int T;
	cin >> T;
	vector<int> x(m);
	vector<int> y(m);
	for(int i = 0; i < m; i++){
		cin >> x[i] >> y[i];
		x[i]--; y[i]--;
	}
	if(T == 1){
		using B = bitset<50000>;
		vector<B> cur(n);
		for(int i = 0; i < n; i++){
			cur[i][i].flip();
		}
		for(int i = 0; i < m; i++){
			cur[x[i]] |= cur[y[i]];
			cur[y[i]] |= cur[x[i]];
		}
		for(int i = 0; i < n; i++){
			if((int)cur[i].count() == n){
				vector<int> where(n, 0);
				where[i] = 1;
				string st(m, '.');
				for(int j = m-1; j >= 0; j--){
					st[j] = "^v"[where[x[j]] < where[y[j]]];
					where[x[j]] |= where[y[j]];
					where[y[j]] |= where[x[j]];
				}
				cout << st << '\n';
				return 0;
			}
		}
		cout << -1 << '\n';
	} else if(T == 2){
		if(n == 2){
			cout << -1 << '\n';
			return 0;
		}
		string st(m, '^');
		vector<int> reach(3, 1);
		int last = -1;
		for(int i = 0; i < m; i++){
			if(y[i] >= 3) continue;
			int other = 3 - x[i] - y[i];
			if(!reach[other]){
				assert(last >= 0);
				st[last] ^= ('^' ^ 'v');
				reach[other] = true;
			}
			st[i] = '^';
			reach[x[i]] = true;
			reach[y[i]] = false;
			last = i;
		}
		cout << st << '\n';
	}
}


Measured memory_bytes: 309936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

ll mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    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;
    }
};

class combination{
public:
    vector<mint> fact,inv,finv;
    combination(int N){
        fact = inv = finv = vector<mint>(N+1);
        fact[0] = fact[1] = 1;
        inv[0] = inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(ll i=2;i<=N;i++){
            fact[i] = fact[i-1]*i;
            inv[i] = (mint) mod - inv[mod%i]*(mod/i);
            finv[i] = finv[i-1]*inv[i];
        }
    }
    mint f(int i){
        return fact[i];
    }
    mint comb(int n,int k){
        if(n<k) return 0;
        if(n<0 || k<0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }
    mint hcomb(int n,int k){
        if(n==0 && k==0) return 1;
        return comb(n+k-1,k);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    mint ans = 0;
    vec<mint> pow2(N+1,1);
    for(int i=1;i<=N;i++) pow2[i] = pow2[i-1]*2;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        mint val = ((mint) 1+a).pow(i);
        val *= a;
        ans += val*pow2[N-i-1];
    }
    cout << ans << "\n";
}


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

int main() {
  int N, K, x, i;
  cin >> N >> K;
  x = 1;
  for (i = 0;i < N;i++) {
    if (x + K >= 2 * x) {
      x *= 2;
    }
    else x += K;
  }
  cout << x << endl;
}

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

ll N, A[3], AI;
lf dp[305][305][305];

lf solve(ll a, ll b, ll c) {
	if (a == 0 && b == 0 && c == 0) return 0;
	if (a < 0 || b < 0 || c < 0) return 0;
	if (dp[a][b][c] >= 0) return dp[a][b][c];
	ll total = a+b+c;
	lf s = 0;
	return dp[a][b][c] = (lf)N/total + (lf)a/total * solve(a-1, b, c) + (lf)b/total * solve(a+1, b-1, c) + (lf)c/total * solve(a, b+1, c-1);
}

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

	cin >> N;
	for (ll i = 0; i < N; i++) {
		cin >> AI;
		A[AI-1]++;
	}

	for (ll i = 0; i < 305; i++) {
		for (ll j = 0; j < 305; j++) {
			for (ll k = 0; k < 305; k++) {
				dp[i][j][k] = -1;
			}
		}
	}

	cout << fixed << setprecision(12) << solve(A[0], A[1], A[2]) << "\n";

}


Measured memory_bytes: 443648
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int d = sc.nextInt();
		Point[] points = new Point[h * w + 1];
		for (int i = 0; i < h; i++) {
		    for (int j = 0; j < w; j++) {
		        points[sc.nextInt()] = new Point(i, j);
		    }
		}
		int[] sums = new int[h * w + 1];
		for (int i = d + 1; i <= h * w; i++) {
		    sums[i] = sums[i - d];
		    sums[i] += points[i].getValue(points[i - d]);
		}
		int q = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    sb.append(- sums[sc.nextInt()] + sums[sc.nextInt()]).append("\n");
		}
		System.out.print(sb);
    }
    
    static class Point {
        int x;
        int y;
        
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
        
        public int getValue(Point another) {
            return Math.abs(x - another.x) + Math.abs(y - another.y);
        }
    }
}



Measured memory_bytes: 100192