akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18
const int N = 100010;//10^5+10

const int MAX_N = 2000;
int a[MAX_N], n, x;
int f[MAX_N][MAX_N];

int main() {
	
	string s; int k; cin >> s >> k;

	for (int i = 0; i < s.length(); i++) {
		while (s[i] != 'a'&& i != s.length() - 1) {
			int d = 26 - (s[i] - 'a');

			if (k - d >= 0) {
				k -= d;
				s[i] = 'a';
			}
			else {
				break;
			}
		}
	}

	if (s[s.length()-1] + k <= 'z') {
		s[s.length() - 1] = s[s.length() - 1] + k;

	}
	else {
		s[s.length() - 1] = s[s.length() - 1] + (k % 26) - 26;
	}

	if (s[s.length() - 1] < 'a')s[s.length() - 1] += 26;

	cout << s << endl;

	return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll n;
  cin >> n;

  cout << (n % 2 == 0 ? n / 2 - 1 : n / 2) << "\n";
}

Measured memory_bytes: 256
import collections
def solve(n, k, a_list):

    counter = collections.Counter()

    for i in a_list:
        counter[i] += 1

    tmp = sorted(counter.values(), reverse=True)
    ans = n - sum(tmp[:k])
    
    return ans

if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    a_list = [int(i) for i in input().split()]
    print(solve(n, k, a_list))

Measured memory_bytes: 32532
#include<stdio.h>
#include<math.h>
int main(void){
	int s[1001],i,n;
	double sd,bs,mean,sum;
	while(1){
		scanf("%d",&n);
		if(!n) break;
		for(i=0,sum=0;i<n;i++){
			scanf("%d",&s[i]);
			sum+=s[i];
		}
		mean=sum/n;
		for(i=0,bs=0;i<n;i++){
			bs+=pow(s[i]-mean,2);
		}
		sd=sqrt(bs/n);
		printf("%.8lf\n",sd);
	}
	return 0;
}

Measured memory_bytes: 640
s = input()
if s[-1]=='2'or s[-1]=='4' or s[-1]=='5' or s[-1]=='7' or s[-1]=='9':
  print("hon")
elif s[-1]=='0'or s[-1]=='1' or s[-1]=='6' or s[-1]=='8':
  print("pon")
else:
  print("bon")
   

Measured memory_bytes: 9044
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

using namespace std;

const double PI = 4*atan(1.0);

int main()
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == -1)
			break;

		double x = 1;
		double y = 0;
		for (int i = 1; i < n; ++i)
		{
			double angle = atan2(y, x) + PI/2;
			x += cos(angle);
			y += sin(angle);
		}
		printf("%.2f\n%.2f\n", x, y);
	}

	return 0;
}

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

// 文字列の式を計算して，vector<int> totalに保存していく
void result_calc(string calc, int64_t &total) {

    // counter は数字が存在するという意味なので使い切ること
    int counter = 0; 
    int64_t result = 0;
    
    for (int i = 0; i < calc.size(); i++) {

        if (calc.at(i) == '+') {

            // cout << "counter " << counter << endl;

            while (counter > 0) {
                // 累乗
                int rank = 1;
                for (int j = 0; j < counter - 1; j++) {
                    rank *= 10LL;
                }

                result += (int64_t(calc.at(i - counter)) - 48LL) * rank;

                // cout << "i - counter " << i - counter << endl;
                // cout << "calc.at(i - counter) " << calc.at(i - counter) << endl;
                // cout << "result " << result << endl;
                counter--;
            }
        }
        else {
            counter++;
        }
    }

    // cout << "final result is " << result << endl;
    total += result;
    // cout << total << endl;
    return;
}

// 考えられる組み合わせを列挙する
void tree_calc(vector<int> &vec, int64_t &total, string calc, int i) {
    // 停止
    if (i == vec.size() - 1) {

        calc += "+"; // 番人を設定する

        // cout << "This is final calc " << calc << endl;
        result_calc(calc, total);
        return;
    }


    // // 途中処理（確認用）
    // cout << "This is calc " << calc << endl;

    // 再帰
    tree_calc(vec, total, calc + to_string(vec.at(i + 1)), i + 1);
    tree_calc(vec, total, calc + "+" + to_string(vec.at(i + 1)), i + 1);
}

// 一時的に利用するstring calcを用意する
void show_calc(vector<int> &vec, int64_t &total) {

    string calc = to_string(vec.at(0));
    tree_calc(vec, total, calc, 0);
}

int main() {

    string S;
    cin >> S;

    vector<int> vec(S.size());
    for (int i = 0; i < S.size(); i++) {
        vec.at(i) = int(S.at(i)) - 48;
    }


    int64_t total = 0;
    show_calc(vec, total);

    cout << total << endl;
}


Measured memory_bytes: 3684
#include <iostream>
#include <vector>
int main(){
    using namespace std;
    int h,w,i,j,k;
    vector<int> v;
    h = 1;
    w = 1;
    while(h!=0||w!=0){
        cin >> h >> w;
        if(h==0&&w==0){
            break;
        }
        v.push_back(h);
        v.push_back(w);
    }
    int size = v.size();
    for(i=0;i<(size/2);i++){
        h = v[2*i];
        w = v[2*i+1];
        for(j=0;j<h;j++){
            for(k=0;k<w;k++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3168
#include<stdio.h>

int main(){
  int n,i,j,x;
  int card[4][13]={{0}};
  char p;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%*c%c %d",&p,&x);
      if(p=='S'){
        card[0][x-1]=x;
      }
      if(p=='H'){
        card[1][x-1]=x;
      }
      if(p=='C'){
        card[2][x-1]=x;
      }
      if(p=='D'){
        card[3][x-1]=x;
      }
    }
  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      if(card[i][j]==0){
        switch(i){
          case 0:printf("S %d\n",j+1);break;
          case 1:printf("H %d\n",j+1);break;
          case 2:printf("C %d\n",j+1);break;
          case 3:printf("D %d\n",j+1);break;
        }
      }
    }
  }

  return 0;
}

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



int main(){
  int N;
  cin >> N;
  vector<int>ans(N);
    for(int i =0; i<N; i++){
    int a;
    cin >> a;
    ans.at(a-1)=i+1;
  }
  for(int k=0; k<N; k++){
    cout<< ans.at(k)<<" ";
  }
}
    

Measured memory_bytes: 1152
'use strict'

const main = (input) => {
    const A = parseInt(input.split(' ')[0])
    const B = parseInt(input.split(' ')[1])
    if(A % 3 === 0 || B % 3 === 0 || (A + B) % 3 === 0){
        console.log('Possible')
    }else{
        console.log('Impossible')
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
#include<iostream>  
#include<string>  
#include<cstring>  
#include<algorithm>  
using namespace std;  
  
int main(){  
  
  int n,m,p;  
  int a;  
  int k;  
  int z[1001];  
  int ans;  
  
  while(true){  
    cin >> n >> m >> p;  
    if(!n && !m && !p) break;  
  
    a = 0;  
  
    for(int i=1;i<=n;i++){  
      cin >> k;  
      z[i] = k;  
      a += k;  
    }  
  
    p = 100 - p;  
  
    if(z[m] == 0) ans = 0;  
    else ans = a * p / z[m];  
  
    cout << ans << endl;  
  }  
}  

Measured memory_bytes: 1160
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        h: usize,
        w: usize,
        _k: usize,
        v: [chars; h]
    }
    let mut ans = vec![vec![0; w]; h];
    let mut cnum = 1;
    for i in 0..h {
        for j in 0..w {
            if v[i][j] == '#' {
                ans[i][j] = cnum;
                cnum += 1;
            }
        }
    }
    for i in 0..h {
        for j in 0..w - 1 {
            if ans[i][j] != 0 && ans[i][j + 1] == 0 {
                ans[i][j + 1] = ans[i][j];
            }
        }
        for j in (1..w).rev() {
            if ans[i][j] != 0 && ans[i][j - 1] == 0 {
                ans[i][j - 1] = ans[i][j];
            }
        }
    }
    for j in 0..w {
        for i in 0..h - 1 {
            if ans[i][j] != 0 && ans[i + 1][j] == 0 {
                ans[i + 1][j] = ans[i][j];
            }
        }
        for i in (1..h).rev() {
            if ans[i][j] != 0 && ans[i - 1][j] == 0 {
                ans[i - 1][j] = ans[i][j];
            }
        }
    }
    for i in 0..h {
        for j in 0..w - 1 {
            print!("{} ", ans[i][j]);
        }
        println!("{}", ans[i][w - 1]);
    }
}


Measured memory_bytes: 4860
#!/usr/bin/env python3
s = list(input())
n = len(s)
ans = "Yes"
x = (n-1)//2-1
y = (n+3)//2-1
n-=1
for i in range(x+1):
    if s[i] != s[n-i]:
        ans = "No"
        break
for j in range(x+1):
    if s[j] != s[x-j]:
        ans = "No"
        break
    if s[y+j] != s[n-j]:
        ans = "No"
        break
print(ans)

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin>>n;
    vi t(n), a(n);
    rep(i, n) cin>>t[i];
    rep(i, n) cin>>a[i];

    vi kakutei(n, 0);
    vi m(n);
    kakutei[0] = 1;
    m[0] = t[0];
    for (int i = 1; i < n; i++) {
        m[i] = t[i];
        if (t[i] > t[i - 1]) {
            kakutei[i] = 1;
        }
    }

    if (kakutei[n - 1] > 0 and m[n - 1] > a[n - 1]) {
        cout << 0 << endl;
        return 0;
    }

    if (kakutei[n - 1] == 0) {
        kakutei[n - 1] = 1;
        m[n - 1] = a[n - 1];
    }

    for (int i = n - 2; i >= 0; i--) {

        if (kakutei[i] > 0 and m[i] > a[i]) {
            cout << 0 << endl;
            return 0;
        }

        if (a[i] > a[i + 1]) {
            m[i] = a[i];
            kakutei[i] = 1;
        } else {
            m[i] = min(a[i], t[i]);
        }
    }

    const ll mod = 1e9 + 7;
    ll ans = 1;
    rep(i, n) {
        if (kakutei[i] == 0) ans = (ans * m[i]) % mod;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e5+5;
const long long inf=0x3f3f3f3f;
long long quick_pow(long long A,long long B,long long C)
{
	long long ans=1;
	while(B)
	{
		if(B&1)
			ans=(ans*A)%C;
		B>>=1;
		A=(A*A)%C;
	}
	return ans%C;
}
long long ans(long long x)
{
	if(x==0)
		return 0;
	long long kk=__builtin_popcount(x);
	return 1+ans(x%kk);
}
string s;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	long long n;
	cin>>n>>s;
	long long one=0;
	for(long long i=0;i<n;i++)
	{
		if(s[i]=='1')
			one++;
	}
	long long p1=0,p2=0;
	for(long long i=0;i<n;i++)
	{
		if(one!=1)
			p1=(p1*2+s[i]-'0')%(one-1);
		p2=(p2*2+s[i]-'0')%(one+1);
	}
	for(long long i=0;i<n;i++)
	{
		if((s[i]=='1'&&one==1))
			cout<<0<<endl;
		else if(s[i]=='1')
			cout<<1+ans((p1-quick_pow(2,n-i-1,one-1)+(one-1))%(one-1))<<endl;
		else if(s[i]=='0')
			cout<<1+ans((p2+quick_pow(2,n-i-1,one+1)+(one+1))%(one+1))<<endl;
	}
	return 0;
}




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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

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

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 
ll fff(ll n, vector<ll>& v, ll i, ll j, ll rl){
  ll can = 0;
  ll can_i = 0;

  cout << v[0]<<endl;
  
  // right
  if(rl == 0){
    rep(k, n){
      if(v[k]*(j-k)>can){
	can = v[k]*(j-k);
	can_i = k;
      }
      //cout << can<<endl;
    }
    v[can_i] = 0;
    return can;
  }
  // left
  else{
    rep(k, n){
      if(v[k]*(k-i)>can){
	can = v[k]*(k-i);
	can_i = k;
      }
      //cout << can<<endl;

    }
    v[can_i] = 0;
    return can;
  }
  
}


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

  ll tmp;
  map<ll, ll> m;
  priority_queue<ll> pq;
  pq.push(0);
  pq.push(0);
  rep(i, n){
    cin>>tmp;
    m[tmp]++;
    if(m[tmp]>1) {
      pq.push(tmp);
      m[tmp]=0;
    }
  }

  ll a ,b;
  a=pq.top();
  pq.pop();
  b=pq.top();

  cout << a* b<<endl;
  
}


Measured memory_bytes: 6528
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a, b;
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            if (a == 1) a = 14;
            if (b == 1) b = 14;
            if (a < b) Console.WriteLine("Bob");
            else if (a == b) Console.WriteLine("Draw");
            else Console.WriteLine("Alice");
        }
    }
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int train;
    int bus;

    train = min(a, b);
    bus = min(c, d);

    cout << train + bus << endl; 
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		long s = sc.nextLong();
		long c = sc.nextLong();
		long res = 0l;
		
		
		if (2*s == c) {
			res += s;
			s = 0;
			c = 0;
		} else if (2*s < c) {
			res += s;
			c -= 2*s;
			s = 0;
		} else if (2*s > c) {
			res += (c / 2);
			s -= (c / 2);
			c -= (c / 2)*2;
		}
		
		
		System.out.println(res + c/4);
		
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 24788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))
#define NM 1e6+5
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)

vector<P> setpf(ll x){
    vector<P> v;

    ll ret = 0;
    for(ll i = 2; i * i <= x; i++) {
        ret = 0;
    while(x % i == 0) {
        ret++;
        x /= i;
        }
        if (ret > 0) v.push_back(P(i, ret));
    }
    if(x != 1) v.push_back(P(x, 1));
    return v;

}

vector<P> LCM(vector<P> a, vector<P> b){
    vector<P> v; 
    auto i1 = a.begin();
    auto i2 = b.begin();
    ll ret = 0;
    while(i1 != a.end() || i2 != b.end()){
        ret = 0;
        if (i2 == b.end() || (i1 != a.end() && (*i1).first< (*i2).first)){
            ret = (*i1).second;
            v.push_back(P((*i1).first, ret));
            i1++;
        }else if(i1 == a.end() || (i2 != b.end() && (*i1).first > (*i2).first)){
            ret = (*i2).second;
            v.push_back(P((*i2).first, ret));
            i2++;
        }else{
            ret = max((*i1).second, (*i2).second);
            v.push_back(P((*i1).first, ret));
            i1++;
            i2++;
        }
    }
    return v;
}

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 powmod(ll a, ll p, ll MOD) {
	ll ans = 1;
	ll mul = a;
	for (; p > 0; p >>= 1, mul = (mul * mul) % MOD) {
		if ((p & 1) == 1)ans = (ans * mul) % MOD;
	}
	return ans;
}

int main() {
    const ll MOD = 1e9 + 7;
    ll N;
    cin >> N;
    vector<ll> v(N);
    vector<vector<P>> pv(N+1);
    ll lcm = 1, g, inv = 0;
    REP(i, N){
        cin >> v[i];
        pv[i] = setpf(v[i]);
        if (i == 0) pv[N] = pv[0];
        else pv[N] = LCM(pv[i], pv[N]);
    }
    ll mul = 1;
    for(auto iter : pv[N]){
        ll tmp = powmod(iter.first, iter.second, MOD);
        mul = (mul * tmp) % MOD;
    }

    ll ans = 0;
    REP(i, N){
        inv = mul * modinv(v[i], MOD) % MOD;
        ans = (ans + inv) % MOD;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

using ll = long long;
constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T gcd(T u, T v) {
    ll r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T lcm(T u, T v) {
    return u * v / gcd(u, v);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;

    ll ans = round_up(N, min({ A,B,C,D,E })) + 4;
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int Q;

void solve() {
	set<pl> S;
	S.insert(pl(-inf, 0));
	S.insert(pl(inf, 0));
	ll b = 0;
	ll sum = 2 * -inf;
	auto it = S.begin();
	cin >> Q;
	rep(q, 0, Q) {
		int t; cin >> t;
		if(t == 1) {
			ll a, c; cin >> a >> c;
			b += c;
			int at = (sz(S) - 1) / 2;
			S.insert(pl(a, q));
			if((*it).fst > a) {
				sum -= a;
				at++;
			}
			else {
				sum += a;
			}
			int nat = (sz(S) - 1) / 2;
			// debug(q, at, nat);
			if(nat < at) {
				it--;
				sum += (*it).fst * 2;
			}
			else if(nat > at) {
				sum -= (*it).fst * 2;
				it++;
			}
		}
		else {
			cout << (*it).fst << " " << -(*it).fst * ((sz(S) % 2 == 0) + 1) + sum + b << "\n";
		}
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 12800
#include <iostream>

int dist(int x1, int y1, int x2, int y2) {
  int xdist = 0, ydist;
  if (x1 > x2) xdist = x1 - x2;
  else xdist = x2 - x1;
  if (y1 > y2) ydist = y1 - y2;
  else ydist = y2 - y1;
  return xdist + ydist;
}

int main() {
  int n;
  std::cin >> n;

  bool ok = true;
  int t1 = 0, x1 = 0, y1 = 0;
  for (int i = 0; i < n; i++) {
    int t2 = 0, x2 = 0, y2 = 0;
    std::cin >> t2 >> x2 >> y2;
    int d = dist(x1, y1, x2, y2);
    int z = (t2 - t1) - d;
    if (z < 0 || z % 2 != 0) {
      ok = false;
      break;
    }
    t1 = t2;
    x1 = x2;
    y1 = y2;
  }
  if (ok) std::cout << "Yes";
  else std::cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string O,E;
    cin>>O>>E;
    int Os=O.size(),Es=E.size();
    if(Os-Es==0){
        for(int i=0;i<Os;i++){
            cout<<O[i]<<E[i];
        }
    }else{
        for(int i=0;i<Es;i++){
            cout<<O[i]<<E[i];
        }
        cout<<O[Os-1];
    }
    puts("");
}

Measured memory_bytes: 256
from sys import stdin, stdout
input = stdin.readline
print = stdout.write

N = int(input())
A = [[int(i) for i in input().split()] for _ in range(N)]
sumA = sum(sum(A, [])) // 2
correct = True

def isCorrect():
    for u in range(N):
        for v in range(u + 1, N):
            for k in range(N):
                if A[u][k] and A[v][k]:
                    #print(u,v,k,A[u][k],A[v][k],A[u][v])
                    if A[u][k] + A[k][v] < A[u][v]:
                        return False
    return True


if not isCorrect(): print(str(-1))
else:
    for u in range(N):
        for v in range(u + 1, N):
            for k in range(N):
                if A[u][k] and A[k][v]:
                    if A[u][k] + A[k][v] == A[u][v]:
                        sumA -= A[u][v]
                        break
    print(str(sumA))


Measured memory_bytes: 133896
import collections
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = collections.Counter(a)
d = c.most_common()
if len(c) <= k:
    print(0)
else:
    sum = 0
    for i in range(k, len(c)):
        sum += d[i][1]
    print(sum)

Measured memory_bytes: 39320
# https://atcoder.jp/contests/abc079/tasks/abc079_c
# C - Train Ticket

a, b, c, d = list(input().split()[0])
a, b, c, d = [int(x) for x in [a, b, c, d]]

# 2 ** 3通りなので全探索でいけそう
is_ok = False

for op1 in [True, False]:
    work_1 = a + b if op1 else a - b
    for op2 in [True, False]:
        work_2 = work_1 + c if op2 else work_1 - c
        for op3 in [True, False]:
            work_3 = work_2 + d if op3 else work_2 - d
            if work_3 == 7:
                is_ok = True
                op_list = [op1, op2, op3]
                break
        if is_ok:
            break
    if is_ok:
        break

op_list = ['+' if op else '-' for op in op_list]
ans = str(a) + op_list[0] + str(b) + op_list[1] + str(c) + op_list[2] + str(d) + '=7'
print(ans)


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

int main() {
int N, K;
cin >> N >> K;
int h;
int count = 0;


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

    if (h >= K)
  {
    count++;
  }
}

cout << count << endl;

}

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

int main(){
	int r, c;
	int a[101][101] = { 0 };
	cin >> r >> c;
	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < r; i++)	{
		for (int j = 0; j < c; j++){
			a[i][c] += a[i][j];
			a[r][j] += a[i][j];
		}
	}
	for (int i = 0; i < r; i++){
		a[r][c] += a[i][c];
	}
	for (int i = 0; i < r+1; i++){
		for (int j = 0; j < c+1; j++){
			if (j == 0){
				cout << a[i][j];
			}
			else{ 
				cout << " " << a[i][j]; 
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define con_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define con_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int n;
    cin>>n;
    vector<point> v(n);
    rep(i,n){
        cin>>v[i].x>>v[i].y;
    }
    double ans=0;
    rep(i,n){
        rep(j,n){
            if(i!=j)ans+=(double)sqrt(pow(v[j].x-v[i].x,2)+pow(v[j].y-v[i].y,2));
        }
    }
    ans/=n;
    printf("%.8lf\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int32_t main()
{
	cout << fixed << setprecision(6);
	double l;
	cin >> l;
	l=l/3;
	cout << l*l*l;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
s = [int(input()) for _ in range(n)]
S = sum(s)
if S % 10:
    print(S)
else:
    s.sort()
    f = 0
    for si in s:
        if si % 10:
            S -= si
            f = 1
            break
    if f:
        print(S)
    else:
        print(0)


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

const int MAX = 200001;

int N, M;
vector<int>  group(MAX);
vector<set<int>> F(MAX);
int gN = 1;

void dfs(int k){
  group[k] = gN;
  for(auto x: F[k]){
    if(group[x] == 0){
      dfs(x);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  long long N, M;
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    F[a].insert(b);
    F[b].insert(a);
  }
  for(int i = 0; i < N; i++){
    if(group[i] == 0){
      dfs(i);
      gN++;
    }
  }
  //cout<<endl;
  //for(int i = 0; i < N; i++) cout << group[i] <<endl;

  vector<int> ninzu(N);
  for(int i = 0; i < N; i++){
    if(group[i] != 0){
      ninzu[group[i]]++;
    }
  }
  cout << *max_element(ninzu.begin(), ninzu.end()) <<endl;
}



Measured memory_bytes: 39060
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          string s = Input.ScanStr();
          string res="";
          
          for(int i=0;i<s.Length;i++){
            if(s[i]=='0') res+="0";
            if(s[i]=='1') res+="1";
            if(s[i]=='B'&& res.Length!=0) res = res.Substring(0,res.Length-1);
          }
          
          Console.WriteLine(res);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

int main()
{
		string s;
		int count = 0;

		cin >> s;

		for (int i = 0; i < 4; i++)
		{
			for (int j = i+1; j < 4; j++)
			{
				if (s[i] == s[j])
				{
					count++;
				}
			}
		}

		if (count == 2)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
		  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
return (a % b + b) % b; }

int main()
{
    int n;
    cin >> n;
    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: 3636
import java.util.*;
public class Main {
	public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
      //取得
	  int N = sc.nextInt();
      int T = sc.nextInt();
      int[] A = new int[N*2]; 
      int min = 10001;
      int cost = 0;
      for(int i=0;i<2*N;i++){
       A[i] = sc.nextInt();
       if(i%2==1){//奇数はtのこと
         if(A[i]<=T){
           cost = A[i-1];
           min = Math.min(min,cost);
         }
       }
      }
      //出力
      if(min==10001){
        System.out.println("TLE");
      }else{
        System.out.println(min);
      }
    }
}


Measured memory_bytes: 36004
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define MAXN (111)
int a[MAXN];

int main()
{
	int n;
	scanf("%d",&n);
	int ans=0;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			for (int k=j+1;k<=n;k++)
				if (a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k])
					if (a[i]+a[j]>a[k]&&max(a[i],a[j])-min(a[i],a[j])<a[k])
						ans++;//,printf("%d %d %d\n",i,j,k);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3228
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(range(N))

ans = 0
msize = 0
psize = 0
minus ,plus =0,0
if sum(A)<sum(B):
   ans =-1
else:
   C = np.array(A)-np.array(B)
   minus = len([n for n in C if n <0])
   plusnum =sorted([n for n in C if n >0],reverse=True)
   msize =sum([ n for n in C if n<0])

   if minus==0:
      ans =0
   else:
      for i in range(len(plusnum)):
         psize =psize+ plusnum[i]

         if psize>=-msize:
            plus =i+1
            break
      ans = minus+plus



print(ans)


Measured memory_bytes: 35064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
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); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll MOD = 1000000007;
ll INF =1<<30;



int main(){
   vector<int>x;
   rep(i,5){
   int a,b,c,d,e;
   cin>>a>>b>>c>>d>>e;
   x.push_back(a);
   x.push_back(b);
   x.push_back(c);
   x.push_back(d);
   x.push_back(e);
   }
   int ans=0,ama=10;
   rep(i,5){
       if(x[i]%10==0) ans+=x[i];
       else {ans+=(x[i]/10*10)+10;
           ama=min(x[i]%10,ama);
       }
   }
   if(ama!=10) ans-=(10-ama);
   cout<<ans <<endl;

}

Measured memory_bytes: 3628
#include<cstdio>

using namespace std;

bool s(int x, int y, int z, int n){
    return ((x*x + y*y + z*z + x*y + x*z + y*z) == n);
}

int permutation(int a, int b, int c){
            if(a==b && b==c){
                return 1;
            }else if(a==b || b==c || a==c){
                return 3;
            }else{
                return 6;
            }
}

int main() {
    int n;
    scanf("%d",&n);
    for(int t=1;t<=n;t++){
        int count = 0;
        for(int i=1;i*i<=t;i++){
            for(int j=i;j*j<=t;j++){
                for(int k=j;k*k<=t;k++){
                    if(s(i,j,k,t)){
                        count+=permutation(i,j,k);
                    }
                }   
            }
        }
        printf("%d\n",count);
    }
    
    return 0;
}

Measured memory_bytes: 1728
use strict;
use warnings;
use utf8;

use feature qw(say);
use Data::Dumper;

my $k = <STDIN>;
chomp $k;
my ($n, $x, $t) = split / /, $k;


my $extra = $n % $x;
my $count = int($n/$x);

my $time;
if ($extra == 0) {
    $time = $count * $t;
} else {
    $time = ($count + 1) * $t;
}

say $time;

Measured memory_bytes: 6448
# https://atcoder.jp/contests/abc079/tasks/abc079_d

from collections import defaultdict

H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
for w in range(10):
    for u in range(10):
        for v in range(10):
            if c[u][v] > c[u][w] + c[w][v]:
                c[u][v] = c[u][w] + c[w][v]

cost = 0
for _ in range(H):
    lv = map(int, input().split())
    for v in lv:
        if v >= 0:
            cost += c[v][1]
print(cost)


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n;
string s[303];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	
	int cnt = 0;
	for(int k = 0; k < n; k++){
		bool b = 1;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(s[mod(i+k,n)][j] != s[mod(j+k,n)][i]) b = 0;
			}
		}
		
		if(b) cnt+=n;
	}
	cout << cnt << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 384
main :: IO ()
main = do
  _ <- getLine
  n <- fmap read . words <$> getLine :: IO [Int]
  print . minimum $ fmap (getCost n) [-100..100]

getCost :: [Int] -> Int -> Int
getCost ls n = sum $ fmap (cost n) ls where
  cost n1 n2 =  (n1 - n2) ^ (2 :: Int)


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

int f(int x)
{
    if (x % 2) {
        return (3 * x + 1);
    }
    return (x / 2);
}

int main( )
{
    int s;
    cin >> s;
    map<int, int> mp;
    mp[s] = 1;
    int i = 2, j;
    while ( 1 ) {
        j = f(s);
        if (mp.find(j) != mp.end()) {
            cout << i << '\n';
            return 0;
        }
        mp[j] = 1;
        s = j;
        i++;
    }
    return 0;
}

Measured memory_bytes: 256
n=int(input())
s=[input() for _ in range(n)]
ans=0
for k in range(n):
  cnt=0
  for i in range(n): 
    l=(i+k)%n
    for j in range(n):
      cnt+=s[i][j]==s[(i+j-l)%n][l]
  if cnt==n**2:ans+=n
print(ans)

Measured memory_bytes: 74432
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
using namespace std;
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; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
#define min(a, b) ((a) < (b) ? (a) : (b))

vector<pair<long long, long long>> prime_factorize(long long n) {
	vector<pair<long long, long long>> res;
	for (long long p = 2; p * p <= n; ++p) {
		// とりあえず約数を出す。
		if (n % p != 0) continue;
		int num = 0;
		while (n % p == 0) ++num; n /= p;
		res.push_back(make_pair(p, num));
	}
	// 1との約数をまとめて追加する。
	if (n != 1) res.push_back(make_pair(n, 1));
	return res;
}

long long gcd(long long x, long long y) {
	return y ? gcd(y, x % y) : x;
}

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

	int N; 
	cin >> N;
	vector<int>L(N);
	for (int i = 0; i < N; ++i) {
		cin >> L[i];
	}
	sort(L.begin(), L.end(), greater<int>());
	// 小さい数からから詰めていく
	long long res = 0;
	for (int a = 0; a < N - 1; a++) {
		int r = N - 1;
		for (int b = a + 1; b < N; b++) {
			while (b < r) {
				if (L.at(a) + L.at(b) > L.at(r) &&
					L.at(b) + L.at(r) > L.at(a) &&
					L.at(r) + L.at(a) > L.at(b)) {
					res += r - b;
					break;
				}
				else {
					--r;
				}
				
			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
ll J[100000], O[100000], I[100000];
int main() {
	int n;
	string a;
	cin >> n >> a;
	ll b = 0, c = 0, d = 0, e = 0, f = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 'J')
			b++;
		J[i] = b;
	}
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] == 'I')
			c++;
		I[i] = c;
		if (a[i] == 'O') {
			O[i] = (J[i] * I[i]);
			d += I[i];
			e += O[i];
			f += J[i];
		}
	}
	ll sum = max(e + d, f + e);
	for (int i = 1; i < n; i++) {
		sum = max(sum, e + (I[i] * J[i - 1]));
	}
	cout << sum << endl;
}

Measured memory_bytes: 5664
#include<iostream>

using namespace std;
int main(){
	long long n, count = 0;
	cin >> n;
	
	for(long long i = 0;i<=n/4;i++){
		if((n - 4*i)%7 == 0) {
			count += 1;
			break;
		}
	}
	if(count) cout << "Yes";
	else cout << "No";
}

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

signed main(){

//	vector<int> a(n);

  int n;
 
  cin >> n;

  int cnt=0;

  for(int i=0;i<=25;i++){
    for(int j=0;j<=14;j++){
      if(i*4 + j*7 == n){
        cnt = cnt + 1;
      }
    }
  }

  if(cnt != 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 3620