akhauriyash/Code-Regression huggingface dataset:
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 305;

int n, K, h[mxn];
ll dp[mxn][mxn][mxn];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
/*
dp[at][can][prv], prvHeight can be compressed by prv. Notice that, dp[at][can][prvHeight+1]<=dp[at][can][prvHeight].
==> Notice that, if I change height I should change exactly as prv, as decreasing is useless and increasing can be postponed if necessary.
*/
    cin >> n >> K;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }

    for (int at = n+1; at>=1; at--) {
        for (int can = 0; can <= K; can++) {
            for (int prv = 0; prv <= n; prv++) {
                auto &ret = dp[at][can][prv];
                if(at==n+1){ret=0;continue;}
                ret = max(0, h[at]-h[prv])+dp[at+1][can][at];
                if (can) {
                    ret = min(ret, dp[at+1][can-1][prv]);
                }
            }
        }
    }

    cout << dp[1][K][0] << '\n';
}

Measured memory_bytes: 220672
#include <iostream>

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    int count;

    int number[B-A+1][5];

    for(int i=0; i < B-A+1; i++){
        int a = A + i;
        for (int j = 0; j < 5; j++)
        {
            number[i][j] = a % 10;
            //cout << number[i][j] << endl;
            a /= 10;
        }
        if(number[i][0] == number[i][4] && number[i][1] == number[i][3]){
            count++;
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
const int MAX_N=100009;
int par[MAX_N];
int myrank[MAX_N];
 
void init(int n){
  for(int i=1;i<=n;i++){par[i]=i; myrank[i]=0;}
}
 
int find(int x){
  if(par[x]==x){return x;}
  else{return par[x]=find(par[x]);}
}
 
void unite(int x, int y){
  x=find(x); y=find(y);
  if(x==y){return;}
  if(myrank[x]<myrank[y]){par[x]=y; myrank[y]+=myrank[x]+1;}
  else{par[y]=x; myrank[x]+=myrank[y]+1;}
  //if(myrank[x]==myrank[y]){myrank[x]++;}
}
 
bool same(int x, int y){return find(x)==find(y);}
 
int main(){
  long long N,M;
  cin >> N >> M;
  vector<int> A(M),B(M);
  for(int i=0;i<M;i++)cin >> A[i] >> B[i];
  init(100009);
  vector<long long> q;
  long long ans=N*(N-1)/2;
  q.push_back(ans);
  for(int i=M-1;i>0;i--){
    if(same(A[i],B[i])){q.push_back(ans);}
    else{
      int a=A[i],b=B[i]; A[i]=max(a,b); B[i]=min(a,b);
      ans-=(myrank[find(A[i])]+1)*(myrank[find(B[i])]+1);
      unite(A[i],B[i]);
      q.push_back(ans);
    }
  }
  for(int i=q.size()-1;i>=0;i--){cout << q[i] << endl;}
}

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


typedef long long ll;
const ll mod=1e9+7;
vector<int> primes;

ll f(int n, int m) {
	ll ans=0;
	while(n) {
		ans+=n/m;
		n/=m;
	}
	return ans;
}

int main() {
	// your code goes here
	int i, j, n;
	for(i=2; i<=1000; ++i) {
		for(j=2; j<i; ++j)
			if(i%j==0)	break;
		if(j==i)	primes.push_back(i);
	}
	cin>>n;
	ll ans=1;
	for(i=0; i<primes.size(); ++i) {
		//if(primes[i]<=n)	cout<<primes[i]<<endl;
		ll z=f(n, primes[i]);
		ans=(ans*(z+1LL))%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
N, D, A = map(int, input().split())
monster = []
for k in range(N):
  monster.append(list(map(int, input().split())))
monster.sort(key = lambda x: x[0])
for k in range(N):
  monster[k][1] = int((monster[k][1]-0.1)//A + 1)
ans = 0

final = monster[-1][0]
ruiseki = 0
minuslist = []
j = 0
for k in range(N):
  while (j < len(minuslist)):
    if monster[k][0] >= minuslist[j][0]:
      ruiseki -= minuslist[j][1]
      j += 1
    else:
      break
  if ruiseki < monster[k][1]:
    ans += monster[k][1] - ruiseki
    if monster[k][0] + 2*D +1 <= final:
      minuslist.append([monster[k][0]+2*D+1, monster[k][1] - ruiseki])
    ruiseki = monster[k][1]


print(ans)


Measured memory_bytes: 75260
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<string>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
struct edge {int /*from,*/to,cost;};

main(){
    int n;
    cin >> n;
    bool rullonz = false;
    REP(i,n){
        char tmp;
        cin >> tmp;
        if(tmp=='Y') rullonz = true;
    }

    puts(rullonz?"Four":"Three");

    return 0;
}


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

int main() {
  string S, T, U;
  int A, B;
  
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  
  if(S==U){
    cout << A-1 << ' ' << B <<endl;
  }
  else
  {
    cout << A << ' ' << B-1 << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin>>k;
  string s;
  cin>>s;
  if(s.size()<=k){
    cout<<s<<endl;
    return 0;
  }
  else{
    for(int i=0;i<k;i++){
      cout<<s.at(i);
    }
    cout<<"..."<<endl;
    return 0;
  }
  
}

Measured memory_bytes: 3596
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<cmath>

#define print(x) cout << #x << " = " << x << endl;

using namespace std;

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

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;


int main() {
	ll N;
	cin >> N;
	ll half = N / 2;

	ll X;
	vector<pair<int, ll>> Xs;
	vector<ll> Xs_buf;
	for (int i = 0; i < N; i++) {
		cin >> X;
		Xs.push_back(make_pair(i, X));
		Xs_buf.push_back(X);
	}

	sort(Xs.begin(), Xs.end(), [](const pair<int, ll>& a, const pair<int, ll>& b) { return a.second < b.second; });
	ll before = Xs[half - 1].second, after = Xs[half].second;

	for (int i = 0; i < N; i++) {
		if (Xs_buf[i] < after) cout << after << endl;
		else cout << before << endl;
	}

	return 0;
}

Measured memory_bytes: 11372
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll mod=1e9+7,dp[110][200000];
int main(){
    ll n,k;
    cin>>n>>k;
    fill(dp[0],dp[0]+2*ll(sqrt(n))+1,0);
    dp[0][1]=1;
    ll count=0;
    for(int i=1;n/i>sqrt(n);i++) count++;
    count+=ll(sqrt(n));
    rep(i,k+1){
        ll a=1,sum=0,b=count;
        for(;n/a>sqrt(n);a++) (sum+=dp[i][a])%=mod,dp[i+1][b]=sum,b--;
        for(int j=sqrt(n);j>=1;j--){
            ll x=n/j-n/(j+1);
            (sum+=dp[i][a]*x)%=mod;
            dp[i+1][b]=sum,b--;
            a++;
        }
        
    }
    cout<<dp[k+1][1]<<"\n";
}

Measured memory_bytes: 158848
#include <bits/stdc++.h>
using namespace std;
map<pair<string, string>,int> g;
int n;
char s[100005];
long long z;
int main(){
	cin>>n;
	scanf("%s",s);
	for(int i=0;i<1<<n;i++){
		string a,b;
		for (int j=0;j<n;j++){
			if ((i>>j)&1)a+=s[j];
			else b+=s[j];
		}
		g[{a, b}]++;
	}
	for(int i=0;i<1<<n;i++) {
		string a,b;
		for (int j=0;j<n;j++) {
			if((i>>j)&1)a+=s[2*n-1-j];
			else b+=s[2*n-1-j];
		}
		z+=g[{a,b}];
	}
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 91904
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;

	static int H[310];
	// 初期状態の必要な回数
	long long initial = 0;
	for(int i = 1; i <= N; i++) {
		cin >> H[i];
		if(H[i - 1] < H[i]) {
			initial += H[i] - H[i - 1];
		}
	}

	// flat[a][b]: a <= i <= bのH[i] = H[b + 1]としたときの減少数
	static long long flat[310][310];
	for(int b = N; b >= 1; b--) {
		for(int a = b; a >= 1; a--) {
			const auto left = H[a - 1];
			const auto right = H[b + 1];
			const auto x = H[a];
			int d = 0;

			// 谷の場合
			if(left > x && x < right) {
				d = min(left, right) - x;
			}
			// 山の場合
			else if(left < x && x > right) {
				d = x - max(left, right);
			}

			flat[a][b] = d + flat[a + 1][b];
		}
	}

	// ans[a][k]: a以降にコストkを使える時の最大減少数
	static long long ans[310][310];
	for(int k = 1; k <= K; k++) {
		for(int a = N; a >= 1; a--) {
			// a始めにコストを使わない
			ans[a][k] = max(ans[a][k], ans[a + 1][k]);
			// コストを使う
			const auto kl = min(k, N - a + 1);
			for(int i = 1; i <= kl; i++) {
				// コストを使用したら一個飛ばす
				ans[a][k] = max(ans[a][k], ans[a + i + 1][k - i] + flat[a][a + i - 1]);
			}
		}
	}

	const auto result = initial - ans[1][K];
	cout << result << endl;

	return 0;
}


Measured memory_bytes: 1792
# 写経
# https://betrue12.hateblo.jp/entry/2019/01/28/215129
# http://zehnpaard.hatenablog.com/entry/2018/06/26/201512
# https://atcoder.jp/contests/nikkei2019-qual/submissions/4112080

from collections import deque

n, m = map(int, input().split())
g = tuple(set() for _ in range(n))  # グラフの隣接リスト
ins = [0] * n  # 頂点の入次数を管理

for _ in range(n - 1 + m):
    s, t = (int(x) - 1 for x in input().split())
    # 頂点は0-indexedで管理する
    g[s].add(t)  # 頂点sから頂点tへの有向辺
    ins[t] += 1  # 入次数

root = -1  # 根の頂点番号（出力時の0-indexedから1-indexedへの変換（+1）で0になるようにとる）
dq = deque((v, root) for v in range(n) if ins[v] == 0)  # 入次数0の頂点の「番号vとその親root」
res = [-1] * n  # 親の頂点番号（0-indexedなので、出力時に1-indexedに直す）

while dq:
    v, root = dq.popleft()
    res[v] = root
    for u in g[v]:
        ins[u] -= 1  # 隣接する頂点の入次数をマイナス1
        if ins[u] == 0:
            dq.append((u, v))  # これによって入次数が0になればqに追加

res = (x + 1 for x in res)
print(*res, sep='\n')


Measured memory_bytes: 85152
#include<bits/stdc++.h>
#define N 366
#define L 16
#define M 9
#define D 7
using namespace std;
bool dp[N][M][D][D][D][D];
int d[N][L];
int dy[5]={0,-1,0,1,0};
int dx[5]={0,0,1,0,-1};
int n;

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    memset(d,0,sizeof(d));
    for(int i=0;i<n;i++)
      for(int j=0;j<L;j++)
	cin>>d[i][j];
    memset(dp,0,sizeof(dp));
    dp[0][4][1][1][1][1]=true;
    bool ans=false;
    for(int i=0;i<n-1;i++)
      for(int j=0;j<M;j++)
	for(int k1=0;k1<D;k1++)
	  for(int k2=0;k2<D;k2++)
	    for(int k3=0;k3<D;k3++)
	      for(int k4=0;k4<D;k4++){
		if(!dp[i][j][k1][k2][k3][k4])continue;
		int y=j/3,x=j%3;
		for(int l=0;l<5;l++){
		  for(int l2=0;l2<5;l2++){
		    if(!(l2==0||l==l2))continue;
		    int ny=y+dy[l]+dy[l2],nx=x+dx[l]+dx[l2];
		    if(ny<0||nx<0||3<=ny||3<=nx)continue;
		    int nj=ny*3+nx,flag=1;
		    if(nj<3){
		      if(d[i+1][nj]||d[i+1][nj+1]||d[i+1][nj+4]||d[i+1][nj+5])flag=0;
		    }else if(nj<6){
		      if(d[i+1][nj+1]||d[i+1][nj+2]||d[i+1][nj+5]||d[i+1][nj+6])flag=0;
		    }
		    else if(d[i+1][nj+2]||d[i+1][nj+3]||d[i+1][nj+6]||d[i+1][nj+7])flag=0;
		    int nk1=k1,nk2=k2,nk3=k3,nk4=k4;
		    if(nj==0)nk1=0;
		    else if(nk1==6)flag=0;
		    else nk1++;
		    if(nj==2)nk2=0;
		    else if(nk2==6)flag=0;
		    else nk2++;
		    if(nj==6)nk3=0;
		    else if(nk3==6)flag=0;
		    else nk3++;
		    if(nj==8)nk4=0;
		    else if(nk4==6)flag=0;
		    else nk4++;
		    if(flag)dp[i+1][nj][nk1][nk2][nk3][nk4]=true;
		  }
		}
	      }
    for(int i=0;i<M;i++)
      for(int k1=0;k1<D;k1++)
	for(int k2=0;k2<D;k2++)
	    for(int k3=0;k3<D;k3++)
	      for(int k4=0;k4<D;k4++)
		if(dp[n-1][i][k1][k2][k3][k4])ans=true;
    if(d[0][5]||d[0][6]
       ||d[0][9]||d[0][10])ans=false;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 10832
#include <iostream>
using namespace std;
int h, w;
string a, x;
int main() {
	cin>>h>>w;
	for(int i=0; i<w+2; i++) x += '#';
	cout<<x<<endl;
	while(h--) cin>>a, cout<<'#'<<a<<"#\n";
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


class BinaryNode:
    def __init__(self, key, left=None, right=None):
        self.val = key
        self.left = left
        self.right = right


def insert(root, node):
    if root is None:
        root = node
    else:
        if root.val < node.val:
            if root.right is None:
                root.right = node
            else:
                insert(root.right, node)
        else:
            if root.left is None:
                root.left = node
            else:
                insert(root.left, node)


def preorder(root):
    ret = []
    if root is None: return ret
    ret.append(root.val)
    ret.extend(preorder(root.left))
    ret.extend(preorder(root.right))
    return ret


def inorder(root):
    ret = []
    if root is None: return ret
    ret.extend(inorder(root.left))
    ret.append(root.val)
    ret.extend(inorder(root.right))
    return ret


def find(node, key):
    while node is not None and key != node.val:
        if key < node.val:
            node = node.left
        else:
            node = node.right
    return node


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    s, key = sl()
    root = BinaryNode(int(key))

    for n in range(N - 1):
        input = sl()
        if input[0] == 'print':
            print("", *inorder(root))
            print("", *preorder(root))
        elif input[0] == 'find':
            node = find(root, int(input[1]))
            print('yes' if node is not None else 'no')
        else:
            insert(root, BinaryNode(int(input[1])))


if __name__ == '__main__':
    main()



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

int n;
int l = 0, r = -1;
vector < pair < int ,int > > v;

int main(){
	
	scanf("%d",&n);
	for ( int i = 0; i < n; i++ ){
		int x, y;
		scanf("%d%d",&x,&y);
		v.push_back(make_pair(x,y));
	}
	sort(v.begin(),v.end());
	
	int ans = 0;
	for ( int i = 0; i < n; i++ ){
		int L = v[i].first, R = v[i].second;
		if ( L > r ){
			ans += r-l+1;
			l = L;
			r = R;
		} else {
			r = R;
		}
	}
	ans += r - l + 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() { cin >> a >> b >>c;
            cout<<(a+b)*c/2<<endl;
}


Measured memory_bytes: 256
n = gets
while line = gets do
    a=Array.new(3) { |i|  }
    a[0],a[1],a[2] = line.split.map(&:to_i)
    a=a.sort
    if a[2]**2==a[1]**2+a[0]**2 then
        puts 'YES'
    else
        puts 'NO'
    end
end

Measured memory_bytes: 6108
#include <stdio.h>
#define MAX 100
#define INF 200000
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
int n,a[MAX][MAX];
 
int main(){
    int i,k,c,u,v,j;
 
    scanf("%d",&n);
    for(i = 0;i<n;i++){
        for(j = 0;j<n;j++){
            a[i][j] = INF;
        }
    }
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(j = 0;j<k;j++){
            scanf("%d %d",&v,&c);
            a[u][v] = c;
        }
    }
    dijkstra();
 
    return 0;
}

void dijkstra(){
    int minv,i,v,u;
    int d[MAX],color[MAX];
 
    for(i=0;i<n;i++){
        d[i] = INF;
        color[i] = WHITE;
    }
 
    d[0] = 0;
    color[0] = GRAY;
    while(1){
        minv = INF;
        u = -1;
        for(i = 0;i<n;i++){
            if(minv>d[i] && color[i] != BLACK){
                u = i;
                minv = d[i];
            }
        }
        if(u == -1)break;
        color[u] = BLACK;
        for(v = 0;v<n;v++){
            if(color[v] != BLACK && a[u][v] != INF){
                if(d[v]>d[u]+a[u][v]){
                    d[v] = d[u] + a[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    for(i = 0;i<n;i++){
        printf("%d",i);
        printf(" ");
        d[i]= (d[i] == INF) ? -1 : d[i];
         printf("%d\n",d[i]);
    }
}
 

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

namespace lec10A
{
    class Program
    {
        static int [] fibo_arr = new int[45];

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            fibo_arr[0] = 1;
            fibo_arr[1] = 1;

            for (int i = 2; i < 45; i++)
            {
                fibo_arr[i] = 0;
            }

            int ans = Fibonacci(n);

            Console.WriteLine("{0}",ans);

            Console.ReadLine();
        }

        static int Fibonacci(int m)
        {
            if (fibo_arr[m] != 0)
            {
                return fibo_arr[m];
            }
            else
            {
                fibo_arr[m] = Fibonacci(m - 1) + Fibonacci(m - 2);
            }
            return fibo_arr[m];
            
        } 
    }
}


Measured memory_bytes: 17916
module WeightedDirectedGraph
  (Weight : sig
    type t
    val inf : t (* オーバーフローの恐れはないので，max_intとか突っ込んでも良い *)
    val zero : t
    val neg_inf : t (* オーバーフローの恐れはないので，min_intとか突っ込んでも良い *)
    val ( + ) : t -> t -> t
    val compare : t -> t -> int
  end) :
sig
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  val bellman_ford :
    (* 頂点数n *)
    int ->
    (* 辺のリスト
       頂点は0からn-1までの整数でなくてはならない
       2n回呼び出されるので，リストを作るのに時間がかかるならメモ化すること *)
    (int * int * Weight.t) church_list ->
    (* 始点 *)
    int ->
    (* 頂点を受け取り，そこまでの距離を返す関数
       頂点に到達するパスが無ければinfを返し，
       そこに到達するまでに負閉路があればneg_infを返す *)
    (int -> Weight.t)
end =
struct
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  let bellman_ford n es s =
    (* 距離を覚えるやつ *)
    let d = Array.make n Weight.inf in
    (* 経路に負閉路が含まれる頂点を覚えるやつ *)
    let neg = Array.make n false in
    d.(s) <- Weight.zero;
    (* n回目以降の反復 手動ループアンローリング *)
    let rec loop' n =
      if
        0 < n &&
        es.fold (fun (u, v, c) b -> (* bは更新の有無 *)
          let open Weight in
          if neg.(u) then neg.(v) <- true;
          (* 原点から到達できない頂点は更新しない *)
          0 < Weight.compare inf d.(u)
          (* c は u から v への辺の重さ
             d.(u) + c < d.(v) *)
          && 0 < Weight.compare d.(v) (d.(u) + c)
          (* n 回目以降に変更が起こった場合，v までの経路に負閉路が含まれている *)
          && (d.(v) <- d.(u) + c; neg.(v) <- true; true) || b) false
      then loop' (n - 1) in
    (* n-1回目までの反復 *)
    let rec loop = function
      | 0 -> loop' n
      | n ->
          if
            es.fold (fun (u, v, c) b ->
              let open Weight in
              (* 原点から到達できない頂点は更新しない *)
              0 < Weight.compare inf d.(u)
              && 0 < Weight.compare d.(v) (d.(u) + c)
              && (d.(v) <- d.(u) + c; true) || b) false
          then loop (n - 1) in
    loop (n - 1);
    fun v -> if neg.(v) then Weight.neg_inf else d.(v)
end


module G = WeightedDirectedGraph (struct
  type t = int
  let zero = 0
  let inf = min_int
  let neg_inf = max_int
  let ( + ) = ( + )
  let compare x y = compare y x
end)

let () = Scanf.scanf "%d %d %d\n" @@ fun n m p ->
  let abc = Array.init m @@ fun _ ->
    Scanf.scanf "%d %d %d\n" @@ fun a b c -> a - 1, b - 1, c - p in
  let d = G.bellman_ford n { G.fold = fun f -> Array.fold_right f abc } 0 (n - 1) in
  if max_int <= d
  then print_endline "-1"
  else Printf.printf "%d\n" @@ max 0 d


Measured memory_bytes: 4736
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5;
ll a[N], b[N], c[N];
ll dp[N][2][2][2];
int n;
ll solve(int idx, int aa, int bb, int cc){
    if(idx == n + 1) return 0;
    if(dp[idx][aa][bb][cc] != -1)
        return dp[idx][aa][bb][cc];
    ll ans = 0;
    if(!aa)
        ans = max(ans, a[idx] + solve(idx + 1, 1, 0, 0));
    if(!bb)
        ans = max(ans, b[idx] + solve(idx + 1, 0, 1, 0));
    if(!cc)
        ans = max(ans, c[idx] + solve(idx + 1, 0, 0, 1));

    ans = max(ans, solve(idx + 1, 0, 0, 0));
    return dp[idx][aa][bb][cc] = ans;
}
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(0, 0, 0, 0);
return 0;
}


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


#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define MAXX 10000007
#define INF INT_MAX

#define PI   3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll 	 long long 
#define mod  1000000007



int main()
{
	FAST;
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll k1 = a*c;
	ll k2 = b * d;
	ll k3 = a * d;
	ll k4 = b * c;
	cout << max(k1, max(k2, (max(k3, k4))));
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>

using namespace std;

const int MAX_N = 100000;
int par[MAX_N];
int rn[MAX_N];

void init(int n){
    for(int i=0; i<n; i++){
        par[i] = i;
        rn[i] = 0;
    }
}

int find(int x){
    if(par[x] == x) {
        return x;
    } else{
        par[x] = find(par[x]);
        return par[x];
    }
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x==y) return;

    if(rn[x] < rn[y]){
        par[x] = y;
    } else{
        par[y] = x;
        if(rn[x] == rn[y]) rn[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main(){
    int N, M, K;
    cin >> N >> M >> K; 
    init(N);

    int a[M], b[M];
    for(int i=0; i<M; i++){
        int s, t;
        cin >> s >> t;
        a[i] = s-1;
        b[i] = t-1;
        unite(a[i], b[i]);
    }

    int cnt[N];
    fill(cnt, cnt+N, 0);
    for(int i=0; i<N; i++){
        cnt[find(i)]++;
    }
    for(int i=0; i<N; i++){
        cnt[i] = cnt[find(i)];
    }

    for(int i=0; i<M; i++){
        cnt[a[i]]--;
        cnt[b[i]]--;
    }

    for(int i=0; i<K; i++){
        int s, t;
        cin >> s >> t;
        s--;t--;
        if(same(s, t)){
            cnt[s]--;
            cnt[t]--;
        }
    }

    for(int i=0; i<N; i++){
        cout << cnt[i]- 1 << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long long k, x;
    cin >> k >> x;
    auto s = x - k + 1;
    auto e = x + k;
    for (long long i = s; i < e; ++i) {
        if (i != s)
            cout << ' ';
        cout << i;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
W,H = 12,12
dxy = [[1,0],[0,1],[-1,0],[0,-1]]
def solve(field,w,h):
	if 0 <= w < W and 0 <= h < H and field[h][w] == "1":
		field[h][w] = "0"
		for dx,dy in dxy:
			solve(field,w+dx,h+dy)

while 1:
	try:
		field = [list(raw_input()) for i in range(H)]
		ans = 0
		for h in range(H):
			for w in range(W):
				if field[h][w] == "1":
					solve(field,w,h)
					ans += 1
		print ans
		raw_input()
	except:
		break

Measured memory_bytes: 4292
import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.*;
import java.math.*;
import java.util.HashMap;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		//int a = sc.nextInt();
		// スペース区切りの整数の入力
		//int b = sc.nextInt();
		//int c = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
		//1文字ずつ
		//s.atChar(i);
		// 出力
		//System.out.println("");
		//double countx=0;
		int n=sc.nextInt();
		

		
		int[] v = new int[n];
		int[] odd =new int[n/2];
		int[] even=new int[n/2];
		int[] dis=new int[n/2];
		int[] emode =new int[100001];
		int[] omode =new int[100001];
		for(int i=0;i<n/2;i++){//0 origin
			even[i]=sc.nextInt();
			odd[i]=sc.nextInt();
			emode[even[i]]++;
			omode[odd[i]]++;
		}
		if(n==2){
			if(even[0]==odd[0]){
				System.out.println(1);
			}else{
				System.out.println(0);
			}
			System.exit(0);
		}
	
		int epo=0;
		int epo2=0;
		int etmp=0;
		int etmp2=0;
		for(int i=0;i<100001;i++){
			if(emode[i]>etmp){
				epo2=epo;
				etmp2=etmp;
				epo=i;
				etmp=emode[i];
			}else if(emode[i]>etmp2){
				epo2=i;
				etmp2=emode[i];
			}
		}
		int opo=0;
		int opo2=0;
		int otmp=0;
		int otmp2=0;
		for(int i=0;i<100001;i++){
			if(omode[i]>otmp){
				opo2=opo;
				otmp2=otmp;
				opo=i;
				otmp=omode[i];
			}else if(omode[i]>otmp2){
				opo2=i;
				otmp2=omode[i];
			}
		}
		if(opo!=epo){
			System.out.println(n-(otmp+etmp));
		}else{
			int s=Math.max(otmp+etmp2, otmp2+etmp);
			System.out.println(n-s);
		}
		
		
		
	}
		
}

Measured memory_bytes: 63992
#include <bits/stdc++.h>
using namespace std;
int main(){
long long a,b,c;
cin >> a >> b >> c;
long double arg=c*3.14159265358979/180;
long double S=a*b*sin(arg)/2;
long double L=a+b+sqrt(a*a+b*b-2*a*b*cos(arg));
long double h=b*sin(arg);
cout << fixed << setprecision(30)<< S << " "<<  L << " " << h;
}


Measured memory_bytes: 3592
#include <iostream>

int main(){
    using namespace std;
    int n, x, c;
    cin >> n >> x;
    while( (n!=0) || (x!=0) ){
        c = 0;
        for(int i{1}; i<=n; i++){
            for(int j{i+1}; j<=n; j++){
                for(int k{j+1}; k<=n; k++){
                    if( (i+j+k)==x ){c++;}
                }
            }
        }
        cout << c << endl;
        cin >> n >> x;
    }
}


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

int main(){
   int N;
   string S;
   cin >> N >> S;
   vector<char> Ans;
   Ans.push_back(S.at(0));
   for (int i=0; i<N-1; i++){
      if (S.at(i) != S.at(i+1)){
         Ans.push_back(S.at(i+1));
      }
   }
   cout << Ans.size() << endl;

}



Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
//#include<cstdlib>
//#include<cmath>
//#include<cstring>
//#include<algorithm>
//#include<climits>
using namespace std;

int n,l,r,ans;

int main(){
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>l>>r;
		ans=ans+r-l+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val (n, a, b) = readLine()!!.split(" ").map(String::toLong)

    val set = n / (a + b)
    val mod = n % (a + b)
    val result = a * set + if (mod > a) {
        a
    } else {
        mod
    }
    println(result)
}






Measured memory_bytes: 37904
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[9];
    for(int i=0;i<9;i++)cin>>a[i];
    int n;
    cin>>n;
    int b[n];
    for(int i=0;i<n;i++){
        cin>>b[i];
        for(int j=0;j<9;j++){
            if(b[i]==a[j])a[j]=0;
        }
    }
    if(a[0]==a[1]&&a[1]==a[2]
    || a[3]==a[4]&&a[4]==a[5]
    || a[6]==a[7]&&a[7]==a[8]
    || a[0]==a[3]&&a[3]==a[6]
    || a[1]==a[4]&&a[4]==a[7]
    || a[2]==a[5]&&a[5]==a[8]
    || a[0]==a[4]&&a[4]==a[8]
    || a[2]==a[4]&&a[4]==a[6]){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,a[3][3];
    for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
    cin>>a[i][j];
    cin>>n;
    int t,b[11],i;
    for(i=0;i<n;i++)
    {
    	cin>>b[i];
    	for(int w=0;w<3;w++)
   		for(int j=0;j<3;j++)
   		if(b[i]==a[w][j])
   		a[w][j]=0;
	}
	int flag=1;
	if(a[0][0]==0)
	{
		if(a[0][1]==0&&a[0][2]==0)
		flag=0;
		if(a[1][0]==0&&a[2][0]==0)
		flag=0;
		if(a[1][1]==0&&a[2][2]==0)
		flag=0;
	}
	if(a[1][0]==0&&a[1][1]==0&&a[1][2]==0)
	flag=0;
	if(a[2][0]==0&&a[2][1]==0&&a[2][2]==0)
	flag=0;
	if(a[1][1]==0&&a[1][2]==0&&a[1][0]==0)
	flag=0;
	if(a[0][2]==0&&a[1][2]==0&&a[2][2]==0)
	flag=0;
	if(a[1][1]==0&&a[0][2]==0&&a[2][0]==0)
	flag=0;
	if(flag==0)
	cout<<"Yes";
	else
	cout<<"No";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long

int arr[100];

int main(void)
{
	int n, ans;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &arr[i]);

	ans = 0;
	for (int i = 0; i < n; i += 2)
		if (arr[i] % 2)
			ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;

int A,B;
int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >>A >> B;
    cout << (A*B) - (A + B) +1 << endl;

    

    return 0;
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
#define F first
#define S second
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
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;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
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> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int s, w; cin >> s >> w;
  if(s <= w)cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}


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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		int d = stdIn.nextInt();
		
		int aa = (c+b-1)/b; //高橋君が攻撃する回数
		int bb = (a+d-1)/d; 
		
		if(aa>bb) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
		
		
	}

}


Measured memory_bytes: 35720
#include<bits/stdc++.h>
using namespace std;
/*
bool isP(int n)
{
    if(n<=1)
        return 0;
    int x,i;
    double lim=sqrt(n);
    // int f=int(lim);
    for(i=2; i*i<=n; i++)
    {
        if(n%i==0)
            return 0;
    }
    return 1;
}
*/
int main()
{
    int n;
    cin>>n;
    double circum,pi=3.14159;
     circum=2*pi*n*1.0;
    cout.setf(ios::fixed);
    cout.precision(2);
    cout<<circum<<endl;
    return 0;
}



Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define ll long long

using namespace std;
ll n,W,w[200],v[200],m=1e15;
ll memo[105][105][1000];

ll dp(int i,int coun,int sub)
{
    if(i==n)return 0;
    if(memo[i][coun][sub]!=-1)return memo[i][coun][sub];
    ll x=0,y=0;
    ll s=W-(m*coun+sub);
    if(s-w[i]>=0)
        x=dp( i+1 , coun+1 , sub+(w[i]-m) )+v[i];
    y=dp(i+1,coun,sub);
    return memo[i][coun][sub]=max(x,y);
}


int main()
{
    memset(memo,-1,sizeof(memo));
    cin>>n>>W;
    for(int i=0; i<n; i++)
    {
        cin>>w[i]>>v[i];
        m=min(m,w[i]);
    }
    cout<<dp(0,0,0);
    return 0;
}


Measured memory_bytes: 86400
n=int(input())
d={'M':0,'A':0,'R':0,'C':0,'H':0}
ans=0
for _ in range(n):
	i=input()
	try:
		d[i[0]]+=1
	except:
		pass
ans+=d['M']*d['A']*d['R']
ans+=d['M']*d['A']*d['C']
ans+=d['M']*d['A']*d['H']
ans+=d['M']*d['C']*d['H']
ans+=d['M']*d['R']*d['H']
ans+=d['A']*d['R']*d['C']
ans+=d['A']*d['R']*d['H']
ans+=d['A']*d['C']*d['H']
ans+=d['R']*d['C']*d['H']
ans+=d['M']*d['C']*d['R']
print(ans)

Measured memory_bytes: 9260
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int c = Integer.parseInt(str[2]);
    System.out.println(Math.max(Math.max(10*a+b+c,10*b+a+c),10*c+a+b));
  }
}

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

int main(){
  string s;
  cin>>s;
  int a[255]={0};
  a[s[0]]+=1;
  a[s[1]]+=1;
  a[s[2]]+=1;
  a[s[3]]+=1;
  int cnt(0);
  for (int i(0);i<255;i++){
    if (a[i]!=0)cnt+=1;
  }
  if (cnt==2)cout<<"Yes"<<endl;
  else cout <<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;


int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if( (a < b) && (b < c)){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
static const long long MOD=1000000007;

int main(){
  long long N;
  cin>>N;
  long long A[200010];
  long long sum=0;
  for(long long i=0;i<N;i++){
    cin>>A[i];
    sum+=A[i];
  }
  sum%=1000000007;
  long long ans=0;
  sum-=A[0];
  if(sum<0){
    sum+=MOD;
  }
  for(long long i=0;i<N-1;i++){
    ans+=A[i]*sum;
    ans%=1000000007;
    sum-=A[i+1];
    if(sum<0){
    sum+=MOD;
    }
  } 
  cout<<ans<<endl;
  return 0;
}

 


Measured memory_bytes: 5148
#include<stdio.h>
#include<stdlib.h>

int main(){
    int n,*R,maxv,minv;
    scanf("%d",&n);
    R = (int *)malloc(sizeof(int) * n);
    // read the integers
    for(int i = 0; i < n; i++){
        scanf("%d",&R[i]);
    }
#ifdef D
    for (int j = 0; j < n; j++) {
        printf("%d ",R[j]);
    }
    printf("\n");
#endif
    
    maxv = R[1] - R[0];
    minv = R[0];
    // search the max profit to compare a minimum R[i] to the others
    for(int i = 1; i < n; i++){
        maxv = (maxv > R[i] - minv ? maxv : R[i] - minv);
        minv = (minv < R[i] ? minv : R[i]);
    }
    
    printf("%d\n",maxv);
    
    free(R);
    
    return 0;
}



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

int main(){
    int row,col;
    cin >> row >> col;

    vector<vector<int> > sheet(row+1, vector<int>(col+1));

    for (int i = 0; i < row; i++)
    {
        
        for (int j = 0; j < col; j++)
        {
            cin >> sheet[i][j];
            sheet[i][col] += sheet[i][j];
        }
    }
    for (int j = 0; j < col; j++)
    {
        for (int i = 0; i < row; i++)
        {
            sheet[row][j] += sheet[i][j];
        }

    }
    for (int j = 0; j < col; j++)
    {
        sheet[row][col] += sheet[row][j];
    }

    for (int i = 0; i <= row; i++)
    {
        
        for (int j = 0; j <= col; j++)
        {
            cout << sheet[i][j];
            if(j != col){
                cout << " ";
            }else{
                cout << endl;
            }
        }
        if(i != row){
          //cout << endl;
        }
    }
    


    return(0);
}


Measured memory_bytes: 3156
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  map<string, int> m;
  rep(i, n) {
    string s;
    cin >> s;
    m.insert(make_pair(s, 1));
  }
  cout << m.size() << endl;
}

Measured memory_bytes: 19208
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int cal[110];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>a>>b;

    if(a<10&&b<10)cout<<a*b<<"\n";
    else cout<<"-1\n";

    return 0;
}


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

int main(){
    string s; cin >> s;
    long long int k, ans = 0;
    cin >> k;

    bool setubi = false;

    if (s.at(0) == s.at(s.size() - 1)) setubi = true;

    long long int b_seq, e_seq;
    b_seq = 1;
    e_seq = 1;
    if (setubi){

        for (int i = 1; i < s.size(); i ++){
            if (s.at(i) != s.at(i - 1)){
                break;
            }
            b_seq += 1;
        }
        string r_s(s);
        //reverse_copy(s.begin(), s.end(), r_s);
        reverse(r_s.begin(), r_s.end());
        for (int i = 1; i < r_s.size(); i ++){
            if (r_s.at(i) != r_s.at(i - 1)){
                break;
            }
            e_seq += 1;
        }
        if (b_seq + e_seq >= s.size()){
            ans = (k * s.size()) / 2;
        }
        else{
            ans += (b_seq / 2) + (e_seq / 2);
            ans += ((b_seq + e_seq) / 2) * (k - 1);

            string sub_s = s.substr(b_seq, s.size() - b_seq - e_seq);
            long long seq_cnt = 1;
            for (int i = 1; i < sub_s.size(); i ++){
                if (sub_s.at(i - 1) == sub_s.at(i)){
                    seq_cnt += 1;
                    continue;
                }
                else{
                    ans += (seq_cnt / 2) * k;
                    seq_cnt = 1;
                }
            }
            ans += (seq_cnt / 2) * k;
        }

    }
    else{
        long long seq_cnt = 1;
        for (int i = 1; i < s.size(); i ++){
                if (s.at(i - 1) == s.at(i)){
                    seq_cnt += 1;
                    continue;
                }
                else{
                    ans += (seq_cnt / 2) * k;
                    seq_cnt = 1;
                }
            }
            ans += (seq_cnt / 2) * k;
    }


    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n, m;
	cin >> n >> m;
	vi a(m), b(m);
	map<int, int> mp;
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		mp[a[i]]++;
		mp[b[i]]++;
	}
	for(auto& p : mp) {
		if(p.se&1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

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

int main(void){
    string s,t,u;
    int a,b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(s==u) cout << a-1 << " " << b << endl;
    else cout << a << " " << b-1 << endl;
}

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

vector<bool> primes;
const int MAXV = 1e5;

int main()
{
    ll X;
    cin >> X;
    for (ll A = -200; A <= 200; A++) {
        for (ll B = -200; B <= 200; B++) {
            if (A*A*A*A*A - B*B*B*B*B == X) {
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3572
{-# LANGUAGE BangPatterns, OverloadedStrings #-}

import Control.Monad
import Data.Array.Unboxed
import Data.Bits
import Data.Char
import Data.Coerce
import Data.Function
import Data.Int 
import Data.IORef
import Data.List
import Data.Maybe
import qualified Data.Map.Strict as M
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  [h, w, k] <- getIntList
  let hs = powerset [1..h]
  let ws = powerset [1..w]
  let hws = map (map (\[x, y] -> (x, y)) . sequence) $ sequence [hs, ws]
  ps <- concat <$> replicateM h getLine
  let arr = listArray ((1, 1), (h, w)) $ map (=='#') ps :: Array (Int, Int) Bool
  print $ length $ filter (== k) $ map (length . filter id . map (arr !)) hws

-- Input

getInt :: IO Int
getInt = readLn

second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

getIntegerList :: IO [Integer]
getIntegerList = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

getIntPair :: IO (Int, Int)
getIntPair = do
  v <- getIntVec 2
  return (v V.! 0, v V.! 1)

-- Search

bisearch :: (Int -> Bool) -> (Int, Int) -> (Int, Int)
bisearch check = bis
  where
    bis (l, r)
      | l + 1 == r = (l, r)
      | check mid  = bis (mid, r)
      | otherwise  = bis (l, mid)
      where
        mid = l + (r - l) `div` 2

-- Modular Arithmetic
--
 
modulo :: Int64
modulo = 10^9+7
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod !x !y | x + y >= modulo = x + y - modulo
             | otherwise = x + y
subMod !x !y | x >= y = x - y
             | otherwise = x - y + modulo
mulMod !x !y = (x * y) `rem` modulo

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  (+) = coerce addMod
  (-) = coerce subMod
  (*) = coerce mulMod
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined
---
 
exEuclid :: (Eq a, Integral a) => a -> a -> (a, a, a)
exEuclid !f !g = loop 1 0 0 1 f g
  where loop !u0 !u1 !v0 !v1 !f 0 = (f, u0, v0)
        loop !u0 !u1 !v0 !v1 !f g =
          case divMod f g of
            (q,r) -> loop u1 (u0 - q * u1) v1 (v0 - q * v1) g r
 
recipM :: Int64 -> Int64
recipM !x = case exEuclid x modulo of
             (1,a,_) -> a `mod` modulo
             (-1,a,_) -> (-a) `mod` modulo
divM :: Int64 -> Int64 -> Int64
divM !x !y = x `mulMod` recipM y
 
instance Fractional N where
  (/) = coerce divM
  recip = coerce recipM
  fromRational = undefined

-- 組み合わせ
powerset :: [a] -> [[a]]  
powerset xs = filterM (\x -> [True, False]) xs


Measured memory_bytes: 4740