akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n,x;
    cin >> n;
    int mi = 1005,ma = -1;
    for(int i=0;i<n;i++){
    	cin >> x;
    	if(x<mi) mi = x;
    	if(x>ma) ma = x;
	}
	cout << ma-mi << "\n";
    
	return 0;
}

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

int main() {
    int N, M;
    string S;
    cin >> N >> M >> S;

    int idx = N;
    vector<int> ans;
    while (idx != 0) {
        for (int move = min(M, idx); move >= 0; move--) {
            if (move == 0) {
                cout << -1 << endl;
                return 0;
            }

            if (S[idx - move] == '0') {
                ans.push_back(move);
                idx -= move;
                break;
            }
        }
    }

    for (int i = ans.size() - 1; i >= 0; i--) {
        cout << ans[i] << (i ? " " : "\n");
    }
}

Measured memory_bytes: 1144
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        Integer x = sc.nextInt();
        Set<Integer> st = new HashSet<Integer>();
        int count = 1;
         
        while(!st.contains(x)){
            st.add(x);
            if(x % 2 == 0){
                x = x/2;
            }else if(x % 2 == 1){
                x = 3 * x + 1;
            }
            count++;
        }     
        System.out.println(count);
    }
}

Measured memory_bytes: 23124
#include<iostream>

bool ans[12];
double b[12]={128,64,32,16,8,4,2,1,0.5,0.25,0.125,0.0625};
double n;

void solve(){
	for(int i=0; i<12; i++){
		if(n-b[i] >= 0){
			n -= b[i];
			ans[i] = true;
		}else
			ans[i] = false;
	}
}

void show(){
	if(n)
		std::cout << "NA";
	else{
		for(int i=0; i<12; i++){
			if(i==8)
				std::cout << '.';
			if(ans[i])
				std::cout << 1;
			else
				std::cout << 0;
		}
	}
	std::cout << std::endl;
}

int main(){
	while(true){
		std::cin >> n;
		if(n<0)
			return 0;
		solve();
		show();
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <tuple>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define all(v) (v).begin(),(v).end()
#define clr(a,b) memset((a),(b),sizeof(a))
#define sz size()
#define pb push_back
#define print(x) cout << x << endl
int n,m;
int x[100];

int main(){
  string s,t = "YAKI",ans = "";
  cin >> s;
  if(s.sz < 4)puts("No");
  else{
    rep(i,0,4){
      ans += s[i];
    }
    if(ans == t)puts("Yes");
    else puts("No");
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    map<ll, ll> nums;
    ll sum = 0;
    nums[sum]++;
    rep(i, n)
    {
        sum += a[i];
        nums[sum % m]++;
    }
    ll ans = 0;
    for (auto it : nums)
    {
        ans += it.second * (it.second - 1) / 2; // it.second個から2個選ぶ
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,k;
  cin>>a>>b>>k;
  int m=min(a,b);
  int count=0;
  int ans;
  for(int i=m;i>=1;i--){
    if(a%i==0 && b%i==0){
      count++;
      if(count==k){
        ans=i;
        break;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
while True:
	try:
		a,b,c,d,e,f = map(float,raw_input().split(' '))
		p = round((c*e-b*f)/(a*e-b*d),4)
		q = round((a*f-c*d)/(a*e-b*d),4)
		x = '%.3f' % p
		y = '%.3f' % q
		if str(x) == '-0.000': x = '%.3f' % 0.000
		if str(y) == '-0.000': y = '%.3f' % 0.000
		print x,y
	except: break

Measured memory_bytes: 4268
#include<stdio.h>
int main(){
    int N;
    scanf("%d",&N);
    int a[N];
    int i,b=0;
    for (i=0; i<N; i++){
        scanf("%d",&a[i]);
        if(i%2==0 && a[i]%2==1){
            b++;
        }
    }
    
    printf("%d",b);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29) //53687091
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
int N;
string s1,s2;

void solve(){
    int i;
    bool status; //1:横,0:縦
    ll ans;
    if(s1[0]==s1[1]){ //横
        ans=6ll;
        i=2;
        status = true;
    }else{ //縦
        ans=3ll;
        i=1;
        status = false;
    }
    
    for(;i<s1.size();i++){
        if(s1[i]==s1[i+1]){
            if(status){ //横→横
                ans*=3ll;
                status = true;
            }else{ //縦→横
                ans*=2ll;
                status = true;
            }
            i++;
        }else{
            if(status){ //横→縦
                ans*=1ll;
                status= false;
            }else{ //縦→縦
                ans*=2ll;
                status=false;
            }
        }
        ans %= MOD;
    }
    cout<<ans<<"\n";
}
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin>>N>>s1>>s2;
    solve();
    
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int n = s.length();
    for(int i=0; i<n; i++){
        if(s[i]=='?'){
            s[i] = 'D';
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3748
using System;

public class Test
{
	static public void Main( )
	{
		while( true ) {
		string[] xy = Console.ReadLine().Split( ' ' );
		
		if( "0" == xy[0] && "0" == xy[1] ) { break; }
		
		var x = int.Parse( xy[0] );
		var y = int.Parse( xy[1] );
		
		if( y < x ) {
			int t = x;
			x = y;
			y = t;
		}
		
		Console.WriteLine( "{0} {1}", x, y );
		}
	}
}

Measured memory_bytes: 5772
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int n, m, ans;
vector<vector<int>> ABCD;
void dfs(vector<int> tmp, int pre) {
    if (tmp.size() == n) {
        int sum = 0;
        for (auto a : ABCD) if (tmp[a[1]] - tmp[a[0]] == a[2]) sum += a[3];
        chmax(ans, sum);
        return;
    }
    for (int i=pre; i<=m; ++i) {
        vector<int> tmp2 = tmp;
        tmp2.push_back(i);
        dfs(tmp2, i);
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q; cin >> n >> m >> q;
    rep(i, q) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        ABCD.push_back({--a, --b, c, d});
    }
    vector<int> tmp;
    dfs(tmp, 1);
    cout << ans << endl;
    // int n, m, q; cin >> n >> m >> q;
    // ll ans = 0;
    // vector<ll> A(q), B(q), C(q), D(q);
    // rep(i, q) {
    //     int a, b, c, d; 
    //     cin >> A[i] >> B[i] >> C[i] >> D[i];
    //     A[i]--; B[i]--;
    // }
    // vector<int> V(m);
    // rep(i, m) V[i] = i+1;
    // for (ll bit=1; bit < (1<<m); ++bit) {
    //     vector<int> tmp;
    //     ll score = 0;
    //     if (__builtin_popcount(bit) != n) continue;
    //     // cout <<  bitset<8>(bit) << endl;
    //     for (int i=0; i<m; ++i) {
    //         if (bit & (1<<i)) tmp.push_back(V[i]);
    //     }
    //     // rep(i, tmp.size()) cout << tmp[i] << " ";
    //     rep(i, q) {
    //         if (tmp[B[i]] - tmp[A[i]] == C[i]) score += D[i];
    //     }
    //     cout << score << endl;
    //     chmax(ans, score);
    // }
    // cout << ans << endl;
    return 0;
}

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

int main(){

    int n, w; cin >> n >> w;
    vector<int> c(n);
    for(int i = 0; i < n; i++) cin >> c[i];
    sort(c.begin(), c.end());
    int now = 0;
    int next = 1;

    //dp[i][j][k] := i番目まで見て、未だとってない友達の中で重さが最小のものがc[j]で,合計の重さがkである通り数
    vector<vector<vector<int> > > dp(2, vector<vector<int> > (n, vector<int> (w + 1, 0)));
    dp[0][0][0] = 1;
    for(int i = 0; i < n; i++){

        for(int j = 0; j < n; j++){
            for(int k = 0; k <= w; k++){
                dp[next][j][k] = 0;
            }
        }

        for(int j = 0; j < n; j++){
            for(int k = 0; k <= w; k++){

                //とる
                if(k + c[i] <= w){
                    if(j == i && j + 1 < n) (dp[next][j + 1][k + c[i]] += dp[now][j][k]) %= MOD;
                    else if(j <= i) (dp[next][j][k + c[i]] += dp[now][j][k]) %= MOD;
                }
                //とらない
                (dp[next][j][k] += dp[now][j][k]) %= MOD;
            }
        }


        swap(now, next);
    }

    int ans = 0;
    for(int j = 0; j < n; j++){
        for(int k = 0; k <= w; k++){
            if(c[j] + k > w) (ans += dp[now][j][k]) %= MOD;
        }
    }

    /*for(int i = 0; i < n + 1; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < w + 1; k++){
                cout << dp[i][j][k] << " ";
            }
            cout << endl;
        }
        cout << endl;
    }*/
    cout << ans << endl;
        
    return 0;   
}


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

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	vector<bool> check(1000005,1);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	sort(v.begin(), v.end());
	int maximum = v[n-1],i=0;
	
	for(int i=0;i<n;++i)
	{
		if (check[v[i]])
		{
			for (int j = v[i]+v[i]; j <= maximum;j+=v[i])
				check[j] = false;
			int j = i;
			while (j+1<n && v[j] == v[j + 1])
			{
				check[v[j + 1]] = false;
				++j;
			}
			if (i+1<n &&  v[i] == v[i + 1])
				check[v[i]] == false;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		if (check[v[i]])
			++ans;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4052
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        for(int i=0;i<a-1;i++){
                               int b = sc.nextInt();
                               in[b-1]++;
                            }
		
        for(int i=0;i<a;i++){System.out.println(in[i]);
                                                 
                            }
       
		
	}
}


Measured memory_bytes: 70224
#1段づつ考えていく
#その1段の連結成分の個数が水やりをする回数である
n=int(input())
h=list(map(int,input().split()))
#連結部分の探索
ans=0
for i in range(max(h)):
  j=0
  num=0
  while j<n:
    if h[j]==0:
      j=j+1
    else:
      num=num+1
      while j<n and h[j]>0:
        h[j]=h[j]-1
        j=j+1
  ans=ans+num
print(ans)

    
  

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

int main() {
 vector<char> S (6);
  for (int i = 0; i < 6; i++) {
    cin >> S[i];
  }
  if (S[2] == S[3] && S[4] == S[5]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
using namespace std;
using ll = long long;
const ll mod =  1000000007;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (int i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

signed main() {
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if(a==b) {
    cout << a*2 << endl;
    return 0;
  }
  cout << max(a, b) * 2 -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int A, B;
  cin >> A >> B;

  int T = A + B;

  if(T < 24) {
    cout << T << endl;
  } else {
    cout << (T-24) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
DP = [0, abs(h[1]-h[0])]

for i in range(N-2):
  DP.append(min(DP[i] + abs(h[i+2]-h[i]), DP[i+1] + abs(h[i+2]-h[i+1])))
print(DP[-1])

Measured memory_bytes: 13980
N,D,A=map(int,input().split())
D*=2 # 爆発の長さ
X=[None]*N
for i in range(N):
  X[i]=list(map(int,input().split()))

X=sorted(X,key=lambda x:x[0])
# lastX=X[-1][0] # 最後のモンスターの場所
damage=0 # 現在の爆発が与えられるダメージ
from collections import deque
bombs=deque() # 爆弾が切れるタイミング
# [位置、効力]
ans=0
for i in range(len(X)):
  x=X[i][0]
  h=X[i][1] # モンスターの体力
  # 爆発が途切れていないかを確認
  while bombs:
    b=bombs.popleft()
    if b[0]<x:
      damage-=b[1]
    else:
      bombs.appendleft(b)
      break
  h-=damage
  if h>0:
    turn=((h+A-1)//A)
    damage+=turn*A
    ans+=turn
    bombs.append([x+D,turn*A])
print(ans)

Measured memory_bytes: 66456
n = int(input())
a = list(map(int, input().split()))

l = a[0]
cnt = 1
ans = 0

for i in range(1, n):
    if l == a[i]:
        cnt += 1
    else:
        ans += cnt // 2
        l = a[i]
        cnt = 1

ans += cnt // 2

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

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


Measured memory_bytes: 3636
N = input()
if N == '0':
  print(0)

  
def fac(num):
  if num % 2 == 0:
    return 1 + fac(num / 2)
  else:
    return 0

As = [int(a) for a in input().split()]


Fs = [fac(a) for a in As]

print(int(min(Fs)))

Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <utility>

#define INF INT_MAX / 2
using namespace std;

typedef pair<int, int> P;
typedef long long ll;

int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};
bool used[30][30];

int bfs(int sy,int sx,const vector<vector<int> >&tiles){
	queue<pair<int,int> > q;
	q.push(make_pair(sy,sx));
	int X = tiles[0].size();
	int Y = tiles.size();
	memset(used,0,sizeof(used));
	used[sy][sx] = true;
	int ret= 0;
	while(!q.empty()){
		P p = q.front();q.pop();
		int y = p.first;int x = p.second;
		for(int i=0;i<4;i++){
			int ny = y + dy[i];
			int nx = x + dx[i];
			if( ny < 0 || nx < 0 || ny >= Y || nx >= X || used[ny][nx] || tiles[ny][nx]==0)continue;
			used[ny][nx] = true;
			q.push(make_pair(ny,nx));
			ret++;
		}
	}
	return ret+1;
}

int main(void) {
	int w,h;
	while(cin >> w >> h,w+h!=0){
	vector<vector<int> >tiles(h,vector<int>(w));
	int sx,sy;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char c;cin >> c;
			if(c=='.')
				tiles[i][j] = 1;
			else if(c=='#')
				tiles[i][j] = 0;
			else{
				tiles[i][j] = 1;
				sx = j;sy = i;
			}
		}
	}
	cout << bfs(sy,sx,tiles) << endl;
}
}

// command ctrl 上下
// command D
// command caps G → '' ""
// vector<vector<int>> a(N,vector<int>(M,-1));

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,r;
    cin >> n >> r;
    int ans = r;
    if(n<10){
    	ans = r+100*(10-n);
    	cout << ans << "\n";
    }
    else cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>


long marge ( long *A, long l, long m, long r){

    long c=0;

    long n1, n2;
    long *L, *R;
    long i, j, k;


    n1 = m - l; n2 = r - m;
    
    L = (long*)malloc(sizeof(long)*(n1+1));
    R = (long*)malloc(sizeof(long)*(n2+1));

    for( i=0L; i<n1; i++ ) L[i] = A[l+i];
    for( i=0L; i<n2; i++ ) R[i] = A[m+i];

    L[n1] = LONG_MAX;
    R[n2] = LONG_MAX;


    i=0L; j=0L;
    for( k=l; k<r; k++ ){
        if( L[i] <= R[j] ){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
            c += (n1-i);
        }
    }

    free( L );
    free( R );

    return c;
}


long margeSort( long *A, long l, long r ){

    long m; // mid
    long c=0;


    if( l+1L < r ){
        m = ( l + r ) /2L;

        c += margeSort( A, l, m );
        c += margeSort( A, m, r );
        c += marge( A, l, m, r );
    }

    return c;
}




int main(){

    long n;
    long *S;
    long i;
    long c;
    
    scanf( "%ld", &n );

    S = (long*)malloc(sizeof(long)*n);

    for( i=0; i<n; i++ ){
        scanf( "%ld", &S[i] );
    }
    
    c = margeSort( S, 0L, n );

    printf( "%ld\n", c);

    free(S);
    return 0;
}



Measured memory_bytes: 4596
#include <stdio.h>
int main(){
  int k,sept;
  int i,tmp;
  
  scanf("%d",&k);
  switch(k%10){
    case 0:
    case 2:
    case 4:
    case 5:
    case 6:
    case 8:
      printf("-1");
      return 0;
    default:
      sept=7;
      i=1;
      while(1){
        if(sept%k==0){
          printf("%d",i);
          return 0;
        }
        sept=sept*10%k+7%k;
        i++;
      }
  }
}

Measured memory_bytes: 1732
using System;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Linq;
using System.IO;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            int N = cin.ReadInt;
            int[] a_n = cin.ReadIntArray(N);

            Dictionary<int, long> counts = new Dictionary<int, long>();

            for (int i = 0; i < N; i++)
            {
                if (counts.ContainsKey(a_n[i]))
                {
                    counts[a_n[i]]++;
                }
                else
                {
                    counts.Add(a_n[i], 1);
                }
            }

            long ans = 0;
            foreach (KeyValuePair<int, long> pair in counts)
            {
                if (pair.Value > 1)
                {
                    ans += pair.Value * (pair.Value - 1) / 2;
                }
            }

            for (int i = 0; i < N; i++)
            {
                int num = a_n[i];
                long count = counts[num];
                Console.WriteLine(ans - (count - 1));
            }
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 44424
import heapq

N, M = map(int, input().split())
a_list = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a_list)
for _ in range(M):
    min_num = heapq.heappop(a_list)
    heapq.heappush(a_list, (-1) * (-min_num // 2))
print(-sum(a_list))


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

int main(void){
    int cnt1, cnt2;
    char s[15], t[15], u[15];
    scanf("%s""%s", s, t);
    scanf("%d""%d", &cnt1, &cnt2);
    scanf("%s", u);
    if(strcmp(s, u) == 0){
        cnt1 -= 1;
    }else{
        cnt2 -= 1;
    }
    printf("%d %d\n", cnt1, cnt2);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){a%=mod;b%=mod;return a*b%mod;}
inline int power(int a,int b,int MOD){a%=mod;int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
    SPEED;
    int n;
    cin>>n;
    vector<int>count(61,0);
    for(int i=0;i<n;i++)
    {
          int x;
          cin>>x;
          for(int j=0;j<=60;j++)
            if(x&(1LL<<j))
                count[j]++;
    }
    int res=0;
    for(int i=0;i<=60;i++)
    {
          res=add(res,mul(1LL<<i,mul(count[i],n-count[i])));
    }
    cout<<res<<endl;
    time();
    return 0;
}

Measured memory_bytes: 384
function main(input) {
  const [n, a, b, c, d, e] = input.trim().split("\n").map(n => Number(n));
  const min = Math.min(...[a, b, c, d, e]);
  const result = Math.ceil(n/min)+4;
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
N = int(input())
a = list(map(int, input().split()))
top = 0
color = []
for i in range(N):
    if a[i] < 400:
        color.append(0)
    elif a[i] < 800:
        color.append(1)
    elif a[i] < 1200:
        color.append(2)
    elif a[i] < 1600:
        color.append(3)
    elif a[i] < 2000:
        color.append(4)
    elif a[i] < 2400:
        color.append(5)
    elif a[i] < 2800:
        color.append(6)
    elif a[i] < 3200:
        color.append(7)
    else:
        top += 1

s = set(color)
print(max(1, len(s)), len(s) + top)


Measured memory_bytes: 3064
N = int(input())
l, r = [], []
for i in range(N):
  L,R=map(int,input().split())
  l+= [L]
  r+= [R]
  
prime = [0,0]+[1]*10**5#素数テーブル
for i in range(10**3):#エラトステネスのふるいにかける
  if prime[i]==0: continue
  for j in range(i+1,10**5+1):
    if j%i==0: prime[j]=0
  
ans = []
for i in range(10**5+1):
  if prime[i]:
    if prime[(i+1)//2]: ans+=[1]
    else: ans+=[0]
  else: ans+=[0]
ans2= [0]
for i in range(10**5):
  ans2+=[ans2[-1]+ans[i+1]]
for i in range(N): 
  print(ans2[r[i]]-ans2[l[i]-1])

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

using LL = long long;

struct LCA {
    int n, log2_n;
    vector<int> depth;
    vector<vector<int>> par;

    void dfs(const vector<vector<int>>& G, int v, int p, int d) {
        depth[v] = d;
        par[0][v] = p;
        for (auto to : G[v]) {
            if (to != p) dfs(G, to, v, d+1);
        }
    }

    LCA(const vector<vector<int>>& G, int root=0) :
        n(G.size()), log2_n(log2(n)), depth(n),
        par(log2_n+1, vector<int>(n,-1)) {

            dfs(G, root, -1, 0);
            for (int k = 0; k < log2_n; ++k) {
                for (int v = 0; v < n; ++v) {
                    if (par[k][v] != -1) {
                        par[k+1][v] = par[k][par[k][v]];
                    }
                }
            }
        }

    int query(int u, int v) {
        if (depth[u] > depth[v]) swap(u, v);

        // align the depth of u and v
        for (int k = 0; k <= log2_n; ++k) {
            if ((depth[v] - depth[u]) >> k & 1) {
                v = par[k][v];
            }
        }
        if (u == v) return u;

        // go back until u and v's parents do not match
        for (int k = log2_n; k >= 0; --k) {
            if (par[k][u] != par[k][v]) {
                u = par[k][u];
                v = par[k][v];
            }
        }
        return par[0][u];
    }
};

void dfs(const vector<vector<int>>& G, vector<int>& par, int v, int p) {
    par[v] = p;
    for (auto u : G[v]) {
        if (u == p) continue;
        dfs(G, par, u, v);
    }
}

int main()
{
    int n; cin >> n;
    vector<vector<int>> G(n);
    for (int i = 0; i < n-1; ++i) {
        int a,b; cin >> a >> b; --a,--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int m; cin >> m;
    vector<int> u(m), v(m);
    for (int i = 0; i < m; ++i) {
        cin >> u[i] >> v[i];
        --u[i], --v[i];
    }

    vector<int> par(n);
        // par[i] := 頂点0を根とする根つき木における,
        //           頂点i の親
    dfs(G, par, 0, -1);

    LCA lca(G);

    vector<LL> cover(m);
        // cover[i] := u[i],v[i] がカバーする辺の集合
        // 辺のid は子のindex とする
    for (int i = 0; i < m; ++i) {
        int t = lca.query(u[i], v[i]);
        int U = u[i], V = v[i];
        while (U != t) {
            cover[i] |= 1LL<<U;
            U = par[U];
        }
        while (V != t) {
            cover[i] |= 1LL<<V;
            V = par[V];
        }
    }

    LL ans = 0;

    for (int s = 0; s < 1<<m; ++s) {
        LL used = 0;
            // used := u[i],v[i] (i in s) がカバーする辺の集合
        for (int i = 0; i < m; ++i) if (s & 1<<i) {
            used |= cover[i];
        }

        if (__builtin_parityll(s)) {
            ans -= 1LL<<(n-1-__builtin_popcountll(used));
        } else {
            ans += 1LL<<(n-1-__builtin_popcountll(used));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
const int MAX = 3000000;
const int MOD = 998244353;
int add(int a, int b) {return (a + b)%MOD;}
int mul(int a, int b) {return 1LL*a*b%MOD;}
int sub(int a, int b) {return add(a, MOD-b);}
int pow_mod(int b, int p) {
	int ret = 1;
	while( p ) {
		if( p & 1 ) ret = mul(ret, b);
		b = mul(b, b);
		p >>= 1;
	}
	return ret;
}
int fct[MAX + 5], ifct[MAX + 5];
void init() {
	fct[0] = 1;
	for(int i=1;i<=MAX;i++)
		fct[i] = mul(fct[i-1], i);
	ifct[MAX] = pow_mod(fct[MAX], MOD - 2);
	for(int i=MAX-1;i>=0;i--)
		ifct[i] = mul(ifct[i+1], i+1);
}
int comb(int n, int m) {
	if( n < m ) return 0;
	else return mul(fct[n], mul(ifct[m], ifct[n-m]));
}
int n, m, l;
int main() {
	init(); scanf("%d%d", &n, &m);
	int ans = 0;
	for(int i=(m&1);i<=n&&i<=m;i+=2) {
		int t = (3*m - i) / 2;
		int del = comb(t + n - 1, n - 1);
		if( t >= m )
			del = sub(del, mul(i, comb(t - m + n - 1, n - 1)));
		if( t >= m + 1 )
			del = sub(del, mul(n - i, comb(t - m - 1 + n - 1, n - 1)));
		ans = add(ans, mul(comb(n, i), del));
	}
	printf("%d\n", ans);
}

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

checked =[ [ 0 for i in range(W)   ] for j in range(H)]
# ok 1
# ng -1
# yet 0

def check(i,j):
    if checked[i][j] == 1:
        return True
    if s[i][j] == ".":
        return True
    if i == 0 and j == 0:
        if s[1][0] == "#":
            checked[1][0] = 1
            return True
        elif s[0][1] == "#":
            checked[0][1] = 1
            return True
        else:
            return False
    if i == 0 and j == W -1:
        if s[1][j] == "#":
            checked[i][j] == 1
            return True
        elif s[0][j-1] == "#":
            checked[0][j-1] = 1
            return True
        else:
            return False
    if i == H - 1 and j == 0:
        if s[i - 1][0] == "#":
            checked[i- 1][0] = 1
            return True
        elif s[i][1] == "#":
            checked[i][1] = 1
            return True
        else:
            return False
    if i == H -1 and j == W - 1:
        if s[i - 1][j] == "#":
            checked[i- 1][j] = 1
            return True
        elif s[i][j - 1] == "#":
            checked[i][j -1] = 1
            return True
        else:
            return False
    if  i == 0:
        if s[i + 1][j] == "#":
            checked[i+1][j] = 1
            return True
        if s[i][j -1] == "#":
            checked[i][j-1] = 1
            return True
        if s[i][j+1] == "#":
            checked[i][j+1] = 1
            return True
        else:
            return False
    if i == H - 1:
        if s[i - 1][j] == "#":
            checked[i-1][j] = 1
            return True
        if s[i][j -1] == "#":
            checked[i][j-1] = 1
            return True
        if s[i][j+1] == "#":
            checked[i][j+1] = 1
            return True
        else:
            return False
    if j == 0:
        if s[i - 1][j] == "#":
            checked[i- 1][j] = 1
            return True
        if s[i + 1][j] == "#":
            checked[i+ 1][j] = 1
            return True
        elif s[i][j + 1] == "#":
            checked[i][ j +1] = 1
            return True
        else:
            return False
    if j == W - 1:
        if s[i - 1][j] == "#":
            checked[i- 1][j] = 1
            return True
        if s[i + 1][j] == "#":
            checked[i+ 1][j] = 1
            return True
        elif s[i][j - 1] == "#":
            checked[i][ j -1] = 1
            return True
        else:
            return False
    else:
        if s[i - 1][j] == "#":
            checked[i- 1][j] = 1
            return True
        if s[i + 1][j] == "#":
            checked[i+ 1][j] = 1
            return True
        elif s[i][j - 1] == "#":
            checked[i][ j -1] = 1
            return True
        elif s[i][j + 1] == "#":
            checked[i][ j +1] = 1
            return True
        else:
            return False

# 一行
for i,sw in enumerate(s):
    for j, sh in enumerate(sw):
        flag = check(i,j)
        if not flag:
            print("No")
            exit()

print("Yes")


Measured memory_bytes: 3320
N = gets.to_i
S = []
count_M = 0
count_A = 0
count_R = 0
count_C = 0
count_H = 0
for i in 0..N-1
    S[i] = gets.chomp
    if S[i][0] == 'M'
        count_M += 1
    elsif S[i][0] == 'A'
        count_A += 1
    elsif S[i][0] == 'R'
        count_R += 1
    elsif S[i][0] == 'C'
        count_C += 1
    elsif S[i][0] == 'H'
        count_H += 1
    end
end

puts (count_M * count_A * count_R + count_M * count_A * count_C + count_M * count_A * count_H + count_M * count_R * count_C + count_M * count_R * count_H + count_M * count_C * count_H + count_A * count_R * count_C + count_A * count_R * count_H + count_A * count_C * count_H + count_R * count_C * count_H)

Measured memory_bytes: 9468
import javax.swing.*;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int maxWeight = sc.nextInt();
        long[] weights = new long[count];
        int[] values = new int[count];
        for (int i = 0; i < count; i++) {
            weights[i] = sc.nextLong();
            values[i] = sc.nextInt();
        }
        int maxValue = 100001;
        long[][] res = new long[count][maxValue];
        boolean[][] b = new boolean[count][maxValue];
        for (int i = 0; i < count; i++) {
            for (int j = 0; j < maxValue; j++) {
                res[i][j] = Integer.MAX_VALUE;
            }
        }
        for (int i = 0; i < maxValue; i++) {
            b[0][i] = true;
        }
        res[0][values[0]] = weights[0];
        res[0][0] = 0;

        for (int i = 1; i < count; i++) {
            for (int j = 0; j < maxValue; j++) {
                long without = res[i - 1][j];
                long with = Integer.MAX_VALUE;

                if (j >= values[i]) {
                    with = res[i - 1][j - values[i]] + weights[i];
                }
                res[i][j] = Math.min(without, with);
            }
        }


        int min = 0;
        for (int i = 0; i < count; i++) {
            for (int j = 0; j < maxValue; j++) {
                if (res[i][j] <= maxWeight) {
                    min = Math.max(j, min);
                }

            }
        }
        System.out.println(min);
    }

}

Measured memory_bytes: 126540
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k]+A[k][j]:
                print(-1)
                exit()

ans = 0
for i in range(N):
    for j in range(N):
        if all([A[i][j] < A[i][k]+A[k][j] or k==i or k==j for k in range(N)]):
            ans += A[i][j]
            
print(ans//2)


Measured memory_bytes: 46300
H,W = map(int,input().split())

A = [input() for _ in range(H)]

bl = True
x,y = 0,0
for _ in range(H+W-2):
  if x+1 < H and A[x+1][y] == '#':
    x += 1
    continue
  if y+1 < W and A[x][y+1] == '#':
    y += 1
    continue
  bl = False
  break

bl = bl and (sum(x.count('#') for x in A) == H+W-1)
answer = 'Possible' if bl else 'Impossible'
print(answer)

Measured memory_bytes: 3064
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
const long long maxV = 1e10;


bool canlift(int w[], int n, int k, long long weight){
    int sum = 0;
    for (int i = 0; i < n; i++){
        if (w[i] > weight) return false;
        else if (sum+w[i] > weight){
            --k;
            sum = w[i];
        }
        else sum += w[i];
    }
    bool res = (k > 0);
    return res;
}


int main(){
    int n, k;
    cin >> n >> k;
    int w[n];
    rep(i,n) cin >> w[i];
    long long l = 0, r = maxV, mid;
    while(l+1 < r){
        mid = (l+r)/2;
        if (canlift(w,n,k,mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
    return 0;
}





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

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

    vector<int> num(3);
    REP(i, 3) cin >> num[i];
    sort(num.begin(), num.end());

    int diff = num[2] - num[0] + num[2] - num[1];
    if (diff % 2) cout << diff / 2 + 2 << '\n';
    else cout << diff / 2 << '\n';
    return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

bool f(int n) {
    return 1 <= n && n <= 12;
}

string calc(string s) {
    auto a = (10 * (s[0] - '0')) + (s[1] - '0');
    auto b = (10 * (s[2] - '0')) + (s[3] - '0');

    if (f(a) && f(b)) return "AMBIGUOUS";

    if (f(a)) return "MMYY";
    if (f(b)) return "YYMM";

    return "NA";
}

void main() {
    string s = read!string;
    writeln(calc(s));
}


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

int main() {
  int K,X;
  cin >> X >> K;
  if (K + X > 100000) {
    for (int i = K - X + 1; i < 100000; i++) {
      cout << i << " ";
    }
    cout << 100000;
  }
  if (K - X < -100000) {
    for (int i = -100000; i < K + X - 1; i++) {
      cout << i << " ";
    }
    cout << K + X - 1;
  }
  if (K + X - 1 <= 100000 && K - X + 1 >= -100000) {
    for (int i = K - X + 1; i < K + X - 1; i++) {
      cout << i << " ";
    }
    cout << K + X - 1;
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long c=K;
		for(int i=1;i<N;i++) {
		      c = c*(K-1);
	    }
	    System.out.println(c);
	  }

}

Measured memory_bytes: 23892
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	int A,B,C,K;
	int i, r = 0;
	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);
	scanf("%d", &K);
	
	for (i = 1; i <= K; i++) {
		if (i <= A) r++;
		else if (i <= (A+B)) r += 0;
		else r--;
	}
	printf ("%d\n", r);
	return(0);
}


Measured memory_bytes: 1708
#include<stdio.h>
int main() {
  int n = 200000;
  int tmp;
  int max = -2000000000;
  int r[n];
  int i;

  // n?????????
  scanf("%d", &n);

  // R?????????
  for(i = 0; i < n; i++) {
    scanf("%d", &r[i]);
  }

  // ?????§???????¨????
  int min = r[0];
  for(i = 1; i < n; i++){
    tmp = r[i] - min;
    if (tmp > max) {
      max = tmp;
    }
    if (tmp < 0) {
      min = r[i];
    }
  }

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

Measured memory_bytes: 1376
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int i=max(a,b)-min(a,b);
int j=max(b,c)-min(b,c);
int k=max(a,c)-min(a,c);
	if(i<=d && j<=d || k<=d)
		cout<<"Yes";
	else
		cout<<"No";
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
const ll P = 1e9+7;
int N, M;
ll X[Nmax], Y[Nmax];

int main(){
	cin >> N >> M;
	for(int i=0; i<N; i++) cin >> X[i];
	for(int j=0; j<M; j++) cin >> Y[j];

	ll x_total = 0;
	ll y_total = 0;
	for(int i=0; i<N/2; i++){
		x_total += (N-2*i-1)*(X[N-i-1]-X[i]);
		x_total %= P;
	}
	for(int j=0; j<M/2; j++){
		y_total += (M-2*j-1)*(Y[M-j-1]-Y[j]);
		y_total %= P;
	}
	
	//cout << x_total << " " << y_total << endl;

	cout << (x_total*y_total)%P << endl;

	return 0;
}


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

using namespace std;

map <long long, char> mm;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, m;
    string s, t;
    cin >> n >> m >> s >> t;

    long long len = 1LL * n * m / __gcd(n, m);
    for (int i = 0; i <= n - 1; i++) mm[i * len / n + 1] = s[i];
    for (int i = 0; i <= m - 1; i++) if (mm.count(i * len / m + 1) && mm[i * len / m + 1] != t[i]) return cout << -1, 0;
    cout << len;
    return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x /gcd(x, y) * y );
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
char c[2010][2010];
ll sum[2010][2010];
ll res[10][10];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	map<ll, ll>mp;
	rep(i, n) {
		cin >> a[i];
		ll target = a[i];
		for (ll j = 2;j <= sqrt(target) + 1;++j) {
			ll res = 0;
			while (target % j == 0) {
				res++;
				target /= j;
			}
			if (mp[j] < res)mp[j] = res;
		}
		if (target != 1) {
			if (mp[target] == 0)mp[target]++;
		}
	}
	ll ans = 0;
	ll total = 1;
	for (auto p : mp) {
		rep(i, p.second) {
			total *= p.first;
			total %= MOD;
		}
	}
	rep(i, n) {
		ans += total * modinv(a[i], MOD);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    if(b>0 && d>0){
        if(a<=0 && c<=0){
            cout << max(b*d,a*c) << "\n";
            return 0;
        }else{
            cout << b*d << "\n";
            return 0;
        }
    }else if(b<=0 && d<=0){
        cout << a*c << "\n";
        return 0;
    }else if(b>0 && d<=0){
        if(a<=0){
            cout << c*a << "\n";
            return 0;
        }else{
            cout << a*d << "\n";
            return 0;
        }
    }else if(b<=0 && d>0){
        if(c<=0){
            cout << a*c << "\n";
            return 0;
        }else{
            cout << c*b << "\n";
            return 0;
        }
    }
    return 0;
}   

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

typedef signed long long ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) x.begin(),x.end()

#define DEBUG

int main()
{
	int n;
	int a[1001];
	cin >> n;
	rep(i, n)
	{
		cin >> a[i];
	}

	cout << a[n-1];
	for(int i = n-2; i >= 0; i--)
	{
		cout << ' ' << a[i];
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = 1234567;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int n;
	cin>>n;
	int a;
	vector<int> A;
	rep(i,n){
		cin>>a;
		A.push_back(a);
	}
	ll ans = LINF;
	for(int x=-100; x<=100; x++){
		ll calc = 0;
		rep(i,n){
			calc += pow(x-A[i],2);
		}
		ans = min(ans,calc);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256