akhauriyash/Code-Regression huggingface dataset:
#![allow(unused)]

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
use std::collections::HashMap;
//use std::collections::HashSet;

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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)*}
    };
}

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, 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")
    };
}
//入力マクロここまで

fn main() {
    input! {
        n: usize,
        m: usize,
        ps: [(usize, String);m],
    }

    let mut ac = 0;
    let mut wa = vec![0; n];
    let mut ans = 0;

    let mut aced = vec![false; n];

    let acs = "AC".to_string();

    for e in ps {
        if e.1 == "AC" {
            if !aced[e.0 - 1] {
                ac += 1;
                aced[e.0 - 1] = true;
                ans += wa[e.0 - 1];
            }
        } else {
            if !aced[e.0 - 1] {
                wa[e.0 - 1] += 1;
            }
        }
    }

    println!("{} {}", ac, ans);
}

Measured memory_bytes: 8444
#include<cstdio>
int main(){
int a,b,c,s,i;
int m = 0;
std::scanf("%d%d%d",&a,&b,&c);
for(i = a;i <= b;i++){
    if(c % i == 0){
        m++;
        s = m;
        }
}
        std::printf("%d\n",s);
}


Measured memory_bytes: 2740
parseint(x) = parse(Int, x)
readint() = readline() |> parseint
readints() = map(parseint, readline() |> split)

function main()
    n = readint()
    p = readints()
    cnt = 0
    for i = 1:n
        (p[i] != i) && (cnt += 1)
    end
    println(cnt <= 2 ? "YES" : "NO")
end

main()

Measured memory_bytes: 117608
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
l=len(X)
c=0
for i in range(l):
 for j in range(i+1,l):
  t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5
  c+=t==int(t)
print(c)

Measured memory_bytes: 9348
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let s: String = read();
    let t: String = read();
    let s = s.chars().collect::<Vec<_>>();
    let t = t.chars().collect::<Vec<_>>();
    let mut dp: Vec<Vec<usize>> = vec![vec![0; t.len() + 1]; s.len() + 1];
    for i in 0..s.len() {
        for j in 0..t.len() {
            dp[i + 1][j + 1] = if s[i] == t[j] {
                std::cmp::max(std::cmp::max(dp[i][j] + 1, dp[i][j + 1]), dp[i + 1][j])
            } else {
                std::cmp::max(std::cmp::max(dp[i][j], dp[i][j + 1]), dp[i + 1][j])
            };
        }
    }
    let mut res = vec![];
    let mut i = s.len();
    let mut j = t.len();
    while i > 0 && j > 0 {
        if dp[i][j] == dp[i - 1][j] {
            i -= 1; // DP の遷移を遡る
        } else if dp[i][j] == dp[i][j - 1] {
            j -= 1;
        } else {
            res.push(s[i - 1]);
            i -= 1;
            j -= 1;
        }
    }
    res.reverse();
    println!("{}", res.into_iter().collect::<String>());
}


Measured memory_bytes: 90492
#include <bits/stdc++.h>
#define M 1000000007
#define INF 999999999
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define MAX 1000005
#define fs first
#define sc second 
#define N 3
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
typedef vector <ll> vi;



int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
 cin.tie(0);
 int a,b,c,d;
 cin>>a>>b>>c>>d;
ll ans=min(b,d)-max(a,c);
if(ans<=0)
    cout<<0<<endl;
else
    cout<<ans<<endl;
return 0;

}

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

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

	vector<int> a(n);
	for (int& ai : a) {
		cin >> ai;
	}

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

	int s = 0;
	for (int i = 0; i < k; ++i) {
		s += a[i];
	}

	cout << s;
	
	return 0;
}
	

Measured memory_bytes: 3632
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

A,B = [int(x) for x in input().split()]
dA = set(prime_decomposition(A))
dB = set(prime_decomposition(B))

cm = dA.intersection(dB)
cm.add(1)

print(len(cm))

Measured memory_bytes: 39152
#include <cstdio>
#include <cstdlib>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main() {
  int prime_flag[1000000];
  FOR(i, 2, 1000000) prime_flag[i] = 1;
  int t = 2;
  while(t < 1000000/2) {
    if(prime_flag[t]) {
      int k = 2;
      while(t * k < 1000000) {
	prime_flag[t*k] = 0;
	k++;
      }
    }
    t++;
  }
  int n;
  while(scanf("%d", &n) != EOF) {
    t = 0;
    REP(i, n+1) t += prime_flag[i];
    printf("%d\n", t);
  }
  
  return 0;
}

Measured memory_bytes: 6504
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <time.h>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define hoge cout << hoge << endl;
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,sum,ans;
ll a,b,c,d,e,f,g,h,w;
ll x[500005],y[500005],z[1000005];
ll s;

void solve(ll m){
	//m+1進数で表したときに解となるか
	num = 0;
	b = n;
	while(b > 0){
		num += b % (m+1);
		b /= (m+1);
	}
	if(num == s){
		ans = min(ans,m+1);
	}
}


int main(){	
	cin >> n >> s;
	a = abs(n - s);
	//aの約数のみが解の候補
	ans = INF;
	for(i=1;i*i<=a;i++){
		if(a % i == 0){
			solve(i);
			solve(a/i);
		}
	}
		

	if(n == s){
		p(n + 1);
	}else if(ans == INF){
		p(-1);
	}else{
		p(ans);
	}
	
	return 0;
}

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

int main(){
  double n;
  double ans;
  while(cin>>n){
    ans=n;
    for(int i=2;i<11;i++){
      if(i%2==0){
        n*=2;
        ans+=n;
      }else{
        n/=3;
        ans+=n;
      }
    }
    cout<<fixed<<setprecision(8)<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3192
//ABC137.cpp
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
	int K,X;
	cin>>K>>X;
	for(int i=X-K+1;i<X+K;i++){
		cout<<i<<" ";
	}
	cout<<endl;
	return 0;	
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int k,number;
    scanf("%d",&k);
    
    if (k % 2 == 0 || k % 5 == 0){
        printf("-1\n");
        return 0;
    }else{
        number = 7 % k;
        for(int i=0;i<k;i++){
          if (number == 0){
            printf("%d\n",i+1);
            return 0;
          }else{
            number = (number * 10 + 7) % k;
          }
        }
    }
    printf("-1\n");
    return 0;    
}

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

int main(){
  long long N,A,B;
  cin >> N >> A >> B;
  long long C=N/(A+B);
  if(C*(A+B)+A>=N){
    cout << C*A+(N-C*(A+B)) << endl;
  }
  else if(C==0){
    if(N<A){
      cout << N << endl;
    }
    else{
      cout << A << endl;
    }
  }
  else{
    cout << C*A+A << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r = sc.nextInt();

		if(n < 10){
			System.out.println(r + 100*(10 - n));
		}else{
			System.out.println(r);
		}
	}
}


Measured memory_bytes: 21332
n = int(input())
a = input().split()
T,A = int(a[0]), int(a[1])
titen = list(map(int,input().split()))

true_num = 1000
for i in range(n):
  t = T-0.006*titen[i]
  b = abs(t-A)
  if b < true_num:
    true_num = b
    res = i+1
    
print(res)
    
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (ll i=(a); i >= b; i--)

#define MN 505

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

    int r;
    cin >> r;
    cout << fixed << setprecision(5) << 3.14159*2*r << "\n";    

    return 0;
}


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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int mod = 1e9 + 7;

#define ll long long
struct Line
{
    mutable ll k, b, p;
    bool operator<(const Line& o) const { return k < o.k; }
    bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line, less<>>
{
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b)
    {  // floored division
        return a / b - ((a ^ b) < 0 && a % b);
    }
    bool isect(iterator x, iterator y)
    {
        if (y == end())
        {
            x->p = inf;
            return false;
        }
        if (x->k == y->k)
            x->p = x->b > y->b ? inf : -inf;
        else
            x->p = div(y->b - x->b, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll b)
    {
        auto z = insert({k, b, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p) isect(x, erase(y));
    }
    ll query(ll x)
    {
        // assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.b;
    }
};

const int N = 2e5 + 10;
int n;
LL c;
LL h[N];
LL dp[N];

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (~scanf("%d%lld", &n, &c))
    {
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &h[i]);
        }

        LL ans = 9e18;
        LineContainer lc;

        dp[1] = 0;
        lc.add(2 * h[1], -h[1] * h[1]);

        for (int i = 2; i <= n; i++)
        {
            LL v = -lc.query(h[i]);
            dp[i] = v + c + h[i] * h[i];
            // debug(i, v, c, h[i], dp[i]);
            lc.add(2 * h[i], -h[i] * h[i] - dp[i]);
        }
        ans = dp[n];
        printf("%lld\n", ans);
    }

    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	long long N, A, B; cin >> N >> A >> B;
	long long remainder = 0;
	if ((N % (A + B)) < A) remainder = (N % (A + B));
	else if ((N % (A + B)) > 0) remainder = A;
	
	cout << (N / (A + B)) * A + remainder;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def main():
    input = sys.stdin.readline
    k = int(input())
    if k % 10 == 2 or k % 10 == 4 or k % 10 == 5 or k % 10 == 6 or k % 10 == 8 or k % 10 == 0:
        print(-1)
        exit()
    elif k % 10 == 1:
        tmp = k * 7
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            if tmp // 10 % 10 <= 7:
                num = 7 - tmp // 10 % 10
            elif tmp // 10 % 10 == 8:
                num = 9
            elif tmp // 10 % 10 == 9:
                num = 8
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break
    elif k % 10 == 3:
        tmp = k * 9
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 3 - 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 5 * 10 ** 7:
                print(-1)
                break
    elif k % 10 == 7:
        tmp = k * 1
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 7 + 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break
    elif k % 10 == 9:
        tmp = k * 3
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) + 3) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break

if __name__ == '__main__':
    main()


Measured memory_bytes: 67644
#include <iostream>
#include <stdio.h>

void swap(int *a, int *b){

  int v = *a;
  
  *a = *b;

  *b = v;
}

int choicesort(int *A, int N){

  int count = 0;
  int i,j;
  for(j = 0; j < N-1; j++){
    int minj = j;
    for(i = j+1; i < N;i++){
      if(A[i] < A[minj]){
	minj = i;
      }
    }
    if(minj != j){
      swap(&A[j],&A[minj]);
      count++;
    }
  }
  return count;
}


int main(void){

  int N;
  int i;
  int c;

  while(~scanf("%d",&N)){
    
    int *A = new int[N];
    
    for(i=0;i < N;i++) scanf("%d", &A[i]);
    
    c = choicesort(A, N);
    
    std::cout << A[0];
    for(i=1;i < N;i++){
      std::cout << " " << A[i]; 
    }
    std::cout << std::endl;
    std::cout << c << std::endl;
    
    delete []A;

  }
  
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; i++) cin >> a.at(i);
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int res = 0;
    if (N%2!=0) a.push_back(0);
    for (int i=0; i<N; i+=2) {
        res+=(a.at(i)-a.at(i+1));
    }
    cout << res;
}

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

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

    for(int i=1;i<=N;i++){
        if(i%3!=0&&i%5!=0)ans+=i;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <unordered_map>
#include <cstring>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

char S[2*100000+5], T[2*100000+5];
unordered_map<char, char> ms, mt;

void solve() {
  int n = strlen(S);

	REP(i, 0, n) {
		if (!ms.count(S[i])) {
			ms[S[i]] = T[i];
		} else if (ms[S[i]] != T[i]) {
			puts("No");
			return;
		}
		if (!mt.count(T[i])) {
			mt[T[i]] = S[i];
		} else if (mt[T[i]] != S[i]) {
			puts("No");
			return;
		}
		
		
	}

	puts("Yes");
	return;

}


int main(void) {
    scanf("%s %s", S, T);

    solve();

	return 0;
}


Measured memory_bytes: 640
#include"stdio.h"

int main(){
    int N;
    int sum = 0;
    int check = 0;

    scanf("%d", &N);

    int L[N];

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

    for (int j = 0; j < N; j++){
        if(L[j] >= sum - L[j]){
            check++;
        }
    }

    if(check == 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
s = input()
k = int(input())
t = []
n = len(s)
for i in range(n):
  for j in range(1, k + 1):
    if i + j > n:
      continue
    t.append(s[i:i+j])
t = sorted(list(set(t)))
print(t[k - 1])


Measured memory_bytes: 5084
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    F = [[0] * 10 for _ in range(N)]
    for i in range(N):
        s = input().split()
        for j in range(10):
            F[i][j] = int(s[j])
    P = [[0] * 11 for _ in range(N)]
    for i in range(N):
        s = input().split()
        for j in range(11):
            P[i][j] = int(s[j])

    ans = -INF
    # 2 ^ nの組み合わせの全列挙
    for b in range(1, 2 ** 10):
        o = [0] * 10
        for i in range(10):
            if b & 1 << i:
                o[i] = 1

        total = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if o[j] == 1 and F[i][j] == 1:
                    c += 1
            total += P[i][c]
        ans = max(ans, total)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3824
n=int(input())
f=[[0 for i in range(10)] for j in range(n)]
for i in range(n):
  x=list(map(int,input().split()))
  f[i]=x[:]

p=[[0 for i in range(11)] for j in range(n)]
for i in range(n):
  x=list(map(int,input().split()))
  p[i]=x[:]

val=[0 for _ in range(1023)]
#ans=0
zr=[0 for _ in range(n)]
for i in range(1,1024):  #bit
  mx=0
  x=i-1
  opn=zr[:]
  #print(bin(i))
  for j in range(10):  #時間帯
    k=i%2
    i=i//2
    if k==1:
      for l in range(n):  #店ごとに営業時間がかぶってるか
        opn[l]+=f[l][j]
  for l in range(n):
    mx+=p[l][opn[l]]
  val[x]=mx
  #print(*opn)




#print(f)
#print(p)
print(max(val))

Measured memory_bytes: 3064
N,T=[int(i) for i in input().split()]
t_n=[int(i) for i in input().split()]

ans=T
for i in range(N-1):
    if t_n[i+1]-t_n[i]<=T:
        ans+=t_n[i+1]-t_n[i]
    else:
        ans+=T
print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;

int main(){
    cin >> n;
    vector<ll> l(100);
    l[0] = 2;
    l[1] = 1;
    rep(i,n){
        l[i+2] = l[i+1] + l[i];
    }
    cout << l[n] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int N, M;
vector<int> g[10];

int dfs(int bit, int v) {
    if (POPCNT(bit) == N) return 1;
    int res = 0;
    for (int nv : g[v]) if (!(bit >> nv & 1)) {
        res += dfs(bit | (1 << nv), nv);
    }
    return res;
}

void _main() {
    cin >> N >> M;
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cout << dfs(1, 0) << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	rep(i,c-a)cout<<'R';
	rep(i,d-b)cout<<'U';
	rep(i,c-a)cout<<'L';
	rep(i,d-b)cout<<'D';
	cout<<'D';
	rep(i,c-a+1)cout<<'R';
	rep(i,d-b+1)cout<<'U';
	cout<<"LU";
	rep(i,c-a+1)cout<<'L';
	rep(i,d-b+1)cout<<'D';
	cout<<'R'<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int MOD = 100000007;

int main()
{
    for(;;){
        string s;
        cin >> s;
        if(s == "#")
            return 0;
        int n = s.size();

        int i = 0;
        long long ret = 1;
        while(i < n){
            int j = i+1;
            while(j < n && s[i] == s[j])
                ++ j;

            int m = 5;
            if(s[i] == '8' || s[i] == '0')
                m = 3;

            ++ i;
            vector<long long> dp(m, 0);
            dp[0] = 1;
            int len = 0;
            int num = 0;
            while(i < j){
                if((j - i) % m == 0){
                    num += accumulate(dp.begin(), dp.end(), 0);
                    num %= MOD;
                }

                vector<long long> nextDp(m, 0);
                for(int k=0; k<m; ++k){
                    nextDp[0] += dp[k];
                    nextDp[0] %= MOD;
                    if(k+1 < m){
                        nextDp[k+1] += dp[k];
                        nextDp[k+1] %= MOD;
                    }
                }
                dp.swap(nextDp);

                ++ i;
            }

            num += accumulate(dp.begin(), dp.end(), 0);
            num %= MOD;
            ret *= num;
            ret %= MOD;
        }

        cout << ret << endl;
    }
}

Measured memory_bytes: 1148
# -*- coding: utf-8 -*-
N, M = map(int,input().split())
A = []
for i in range(N):
    A.append([int(i) for i in input().split()])

K = []
for i in range(N):
    K.append(A[i][0])
    del A[i][0]
#print(A)


tmp = A[0]
for i in range(1,N):
    tmp = list(set(tmp) & set(A[i]))
print(len(tmp))

"""
tmp = A[0]
for i in range(1, N):
    for j in range(len(tmp)):
        if not (tmp[j] in A[i]):
            del tmp[j]
print(len(tmp))
"""

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define mrep(p,mp) for(auto p : mp)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
int a,b;
cin >> a >> b;
int sum = a + b; 
if(sum % 3 == 0 || a % 3 == 0 || b % 3 == 0)
    cout << "Possible" << endl;
else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
#define rep(i,n) for (ll i=0;i<n;i++)
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a ;
    cin >> a;
    if(a){
        cout << 0;
    }else{
        cout << 1;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int n, m, c;

int main()
{
	while (true)
	{
		scanf("%d", &n);
		scanf("%d", &m);

		if (n == 0 && m == 0) { break; }

		vector<pair<int, int> > r(m);

		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf("%d", &c);

				r[j].first -= c;
			}
		}

		for (int i = 0; i < m; i++)
		{
			r[i].second = i + 1;
		}

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

		for (int i = 0; i < m; i++)
		{
			if (i) { printf(" "); }

			printf("%d", r[i].second);
		}

		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp>   
using namespace std;
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  tree_order_statistics_node_update>  ordered_set; 
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (long double)(0.00000000001)
#define side 1e9
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;

ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[100005];
void power()
{
    powe[0]=1;
    REP(i,1,100005)
    {
        powe[i]=mymod(2*powe[i-1],num);
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    g++;   //this line was added just to remove compiler warning
    ll res = (x%m + m) % m;
    return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
}
struct node
{
	vll adj;
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll mat[n][n];
    REP(i,0,n)
    {
        REP(j,0,n)
        {
            cin>>mat[i][j];
        }
    }
    vll dp((1<<n), 0);  //dp[i] : number of ways to make pairs such that the first popcount(i) women are paired with men
    dp[0] = 1;     // One way to make pair of no man and no woman
    REP(i,0,1<<n)
    {
        ll x = __builtin_popcount(i);  //currently x women are paired
        REP(j,0,n)
        {
            if(!(i & 1<<j) && mat[x][j]==1)
            {
                ll m2 = i^(1<<j);
                dp[m2]+=dp[i];
                dp[m2] = mymod(dp[m2], num);
            }
        }
    }
    cout<<dp[(1<<n) - 1]<<"\n";     
    return 0;
}




Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

struct UnionFind {
  vector<int> parent;
  UnionFind (int n) : parent(n, -1) {}
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (parent[y] < parent[x]) swap(x, y);
    if (parent[x] == parent[y]) --parent[x];
    parent[y] = x;
    return true;
  }
};

int main()
{
  ll n;
  cin>>n;
  vector<tuple<ll,ll>> vp;
  REP(i,n){
    ll x,y;
    cin>>x>>y;
    vp.emplace_back(x,y);
  }
  vector<vector<ll>> va(100001);
  REP(i,n) {
    ll x,y;
    tie(x,y) = vp[i];
    va[x].push_back(y);
  }
  UnionFind uf(100001);
  REP(i,100001) {
    FOR(j,1,va[i].size()) {
      uf.merge(va[i][0], va[i][j]);
    }
  }
  vector<set<ll>> vb(100001);
  vector<vector<ll>> vc(100001);
  REP(i,n) {
    ll x,y;
    tie(x,y) = vp[i];
    vb[uf.root(y)].insert(x);
    vc[y].push_back(x);
  }
  ll cnt=0;
  REP(i,100001) {
    cnt += vb[uf.root(i)].size() - vc[i].size();
  }
  cout<<cnt<<endl;

  return 0;
}


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

int main(void) {
    int a = 0;
    int b = 0;
    int originalA;
    int originalB;

    int mod;

    while (cin >> a) {
        cin >> b;
        originalA = a;
        originalB = b;

        while (true) {
            mod = a % b;
            if (mod == 0) {
                break;
            }
            a = b;
            b = mod;
        }
        cout << b << " " << (originalA / b)  * originalB << endl;
    }
    return 0;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
	int n, q;
	cin >> n >> q;
	UnionFind uf = UnionFind(n);
	for (int i=0;i<q;i++) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0) {
			uf.unite(x, y);
		} else { // com == 1
			cout << uf.same(x, y) << endl;
		}
	}
}


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

int main(){
  long long ans=0,count=0;
  string s;
  cin>>s;
  for(long long i=0;i<s.size();i++){
    if(s[i]=='W'){
      ans+=i-count;
      count++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep2(i, a, b) for(int i = (a); i < (b); i++)
typedef long long ll;

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

   string s[10] = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};

   cout << s[n % 10] << endl;
}

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

int n;
long long ans;
map<int, int> a;

int main()
{
	cin >> n;
	for (int i = 1, x; i <= n; i++)
	{
		cin >> x;
		ans += a[i - x];
		a[i + x]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 20468
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	string s;
	int c=0,x,y;
	cin>>s;
    for(int i=0;i<s.size();i++)
      if(s[i]=='A')
      {
      	x=i; break;
	  }
	for(int i=s.size()-1;i>=0;i--)
      if(s[i]=='Z')
      {
      	y=i; break;
	  }
	c=y-x+1;
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 640
#graph implementation
import math
n,m=map(int,input().split())
ans=['l']*n
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]=='l':
      ans[s-1]=c
    else:
        if ans[s-1]!=c:
            print(-1)
            exit(0)
if ans[0]=='l' and n>1:
    ans[0]=1
for i in range(n):
    if ans[i]=='l':
        ans[i]=0
if ans[0]==0 and n>1:
    print(-1)
else:
    for i in ans:
        print(i,end="")
print()


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  if (n * a <= b){
    cout << n * a << '\n';
  }
  else{
    cout << b << '\n';
  }
  return 0; 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[20];
	int i,a;
	scanf("%s",s);
	a=strlen(s);
	for(i=0;i<a;i++)
		if(s[i]==',') {
		s[i]=' ';
	}
	printf("%s\n",s);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
#define EPS (1e-10)
#define X real()
#define Y imag()
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef pair<P,double> C;

double cross(P a, P b){ return a.X*b.Y - a.Y*b.X;}

vector<double> malfatti_circle(P a, P b, P c){
  const double A = abs(b-c), B = abs(a-c), C = abs(a-b), r = abs(cross(b-a,c-a))/(A+B+C),
    x = (-A+B+C)/2.0/r, y = (A-B+C)/2.0/r, z = (A+B-C)/2.0/r;
  vector<double> ret(3);
  double r_a, r_b, r_c, small = 0.0, large = r;
  for(int i = 0; i < 100; ++i){
    r_a = (small+large)/2.0;
    double s = y*y, t = x*y*r_a - C*y - 2*r_a, u = C*C - 2.0*C*x*r_a + x*x*r_a*r_a;
    r_b = (-t - sqrt(t*t - s*u))/s;
    s = z*z;
    t = x*z*r_a - B*z - 2*r_a;
    u = B*B - 2.0*B*x*r_a + x*x*r_a*r_a;
    r_c = (-t - sqrt(t*t - s*u))/s;
    if(2*sqrt(r_b*r_c) + y*r_b + z*r_c > A){
      small = r_a;
    }else{
      large = r_a;
    }
  }
  ret[0] = r_a;
  ret[1] = r_b;
  ret[2] = r_c;
  return ret;
}

int main(){
  double x_a, y_a, x_b, y_b, x_c, y_c;
  while(cin >> x_a >> y_a >> x_b >> y_b >> x_c >> y_c, x_a||y_a||x_b||y_b||x_c||y_c){
    P a = P(x_a,y_a), b = P(x_b,y_b), c = P(x_c,y_c);
    vector<double> R = malfatti_circle(a,b,c);
    for(int i = 0; i < 3; ++i){
      printf("%.12f", R[i]);
      if(i < 3) cout << " ";
    }cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3284
N, X = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [abs(i - X) for i in a]

def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a

print(gcdlist(b))

Measured memory_bytes: 14224
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#ifndef NULL
#define NULL 0
#endif
using namespace std;

int mp[110][110];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		for (int j = 0; j < b; j++) {
			int c;
			cin >> c;
			mp[a][c] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < n; j++)
			cout << mp[i][j] << ' ';
		cout << mp[i][n] << endl;
	}
	return 0;
}  




Measured memory_bytes: 3108
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int MAX=100;
const ll INF=10000000000;

ll d[MAX][MAX];
int n,e;

void floyd(){
  rep(k,n){
    rep(i,n){
      if(d[i][k]==INF) continue;
      rep(j,n){
        if(d[k][j]==INF) continue;
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
}

int main(){
  cin>>n>>e;
  
  rep(i,n){
    rep(j,n){
      if(i==j) d[i][j]=0;
      else d[i][j]=INF;
    }
  }
  
  ll s,t,u;
  rep(i,e){
    cin>>s>>t>>u;
    d[s][t]=u;
  }
  
  floyd();
  
  bool b=false;
  rep(i,n){
    if(d[i][i]<0) b=true;
  }
  if(b) cout<<"NEGATIVE CYCLE"<<endl;
  else{
    rep(i,n){
      rep(j,n){
        if(j) cout<<" ";
        if(d[i][j]==INF) cout<<"INF";
        else cout<<d[i][j];
      }
      cout<<endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3168
#include<iostream>
#include<vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    int H, N, a;
    int result = 0;
    vector<int> A;

    cin >> H >> N;
    for (int i = 0; i < N; i++) {
        cin >> a;
        result = result + a;
    }
    if (H <= result) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}   

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n; cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n / 2; i++) {
		cnt += i != n - i;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int t;
	double kitaiti[11];
	double kakuritu_sum;
	int n,m;
	int v;
	double r;
	int i,j;
	scanf("%d",&t);
	for(i=0;i<=t;i++) {
		scanf("%d%d",&n,&m);
		kitaiti[i]=0;
		kakuritu_sum=0;
		for(j=0;j<m;j++) {
			scanf("%d%lf",&v,&r);
			kitaiti[i]+=v*r;
			kakuritu_sum+=r;
		}
		kitaiti[i]/=kakuritu_sum;
	}
	for(i=0;i<t;i++) {
		if(kitaiti[i]>kitaiti[t]+0.0000001)break;
	}
	puts(i<t?"YES":"NO");
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

class Main {
    public static int[] a;
    public static int n;
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int q = sc.nextInt();
        int[] m = new int[q];
        for (int i = 0; i < q; i++){
            m[i] = sc.nextInt();
        }

        for(int number : m){
            if (solve(0, number)) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }
        }
    }

    public static boolean solve(int i, int m) {
        if (m == 0) {
            return true;
        }

        if (i >= n) {
            return false;
        }

        boolean res = solve(i + 1, m) || solve(i + 1, m - a[i]);
        return res;
    }
}



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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
	string N;
	cin >> N;
	bool finished = false;
	rep(i, 3) {
		if (N.at(i) == '7') finished = true;
	}
	if (finished == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3620
# https://onlinejudge.u-aizu.ac.jp/problems/DPL_1_A

INF = float('inf')

if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    C = list(map(int, input().split()))
    dp = [INF for _ in range(N+1)]
    dp[0] = 0

    for i in range(M):
        c = C[i]
        for n in range(c, N+1):
            if dp[n-c] == INF:
                continue
            else:
                dp[n] = min(dp[n-c] + 1, dp[n])

    print(dp[N])



Measured memory_bytes: 7652
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int N;
int a, b, c;

int main() {
	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> a >> b >> c;
		if (a*a + b*b == c*c
			|| a*a + c*c == b*b
			|| b*b + c*c == a*a) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@*/
/*@                       @*/
/*@ debug output erased ? @*/
/*@                       @*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@*/

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
vector<pair<LL, int>> x_and_idx, y_and_idx;

struct UnionFind {
    vector<LL> data;
    UnionFind(LL size) : data(size, -1) { }

    bool unionSet(LL x, LL y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    
    bool findSet(LL x, LL y) {
        return root(x) == root(y);
    }
    
    LL root(LL x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }

    LL size(LL x) {
        return -data[root(x)];
    }
};

void solve(long long N, std::vector<long long> x, std::vector<long long> y){
    REP(i, N) {
        x_and_idx.PB(MP(x[i], i));
        y_and_idx.PB(MP(y[i], i));
    }
    UnionFind uf(N);

    sort(ALL(x_and_idx));
    sort(ALL(y_and_idx));

    vector<pair<LL, pair<int, int> > > memo;
    REP(i, N-1) {
        LL now = x_and_idx[i].first;
        if(!uf.findSet(x_and_idx[i].second, x_and_idx[i+1].second)) {
            if(x_and_idx[i].first == x_and_idx[i+1].first) {
                uf.unionSet(x_and_idx[i].second, x_and_idx[i+1].second);
            }else{
                memo.PB(MP(abs(x[x_and_idx[i].second] - x[x_and_idx[i+1].second]), MP(x_and_idx[i].second, x_and_idx[i+1].second)));
            }
        }

        now = y_and_idx[i].first;
        if(uf.findSet(y_and_idx[i].second, y_and_idx[i+1].second)) continue;
        if(y_and_idx[i].first == y_and_idx[i+1].first) {
            uf.unionSet(y_and_idx[i].second, y_and_idx[i+1].second);
        }else{
            memo.PB(MP(abs(y[y_and_idx[i].second] - y[y_and_idx[i+1].second]), MP(y_and_idx[i].second, y_and_idx[i+1].second)));
        }
    }
    sort(ALL(memo));
    LL ans = 0;
    REP(i, memo.size()){
        if(uf.size(0) == N) break;
        pair<LL, pair<int, int> > now = memo[i];
        if(uf.findSet(now.second.first, now.second.second)) continue;
        ans += now.first;
        uf.unionSet(now.second.first, now.second.second);
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 11876
#include<iostream>
using namespace std;
#include<stdio.h>
int main(){
	int n,i,a[1000]={0};
	cin>>n;
	for(i=0;i<n;i++){
		int x,c,d,f,r=0;
		cin>>x>>c>>d>>f;
		a[i]=x*d+c*f;
		if(d>=5&&f>=2)
		a[i]*=0.8;
		else if(d>=5&&f<2){
			r=(x*d+c*2)*0.8;
			if(a[i]>r)
			a[i]=r;
		}
		else if(d<5&&f>=2){
			r=(x*5+c*f)*0.8;
			if(a[i]>r)
			a[i]=r;
		}
	}
	for(i=0;i<n;i++)
	cout<<a[i]<<endl;
	return 0;
}

Measured memory_bytes: 3080
#include<string.h>
#include<math.h>
 
int main(){
   int count=0;
   char str[101];
   scanf("%s",str);
   int len=strlen(str);
   for(int i=0;i<len/2;i++) {
    if(str[i]!=str[len-i-1]) count++;    
   }
   printf("%d\n", count);
   return 0;
}

Measured memory_bytes: 128