akhauriyash/Code-Regression huggingface dataset:
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

struct UnionFind {
  vector<int> data;

  UnionFind(int sz) { data.assign(sz, -1); }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y)
      return (false);
    if (data[x] > data[y])
      swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if (data[k] < 0)
      return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) { return (-data[find(k)]); }
};
template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return cost; }
};

template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

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

  int V, E;
  cin >> V >> E;
  Edges<int> G;
  REP(i, E) {
    int s, t, w;
    cin >> s >> t >> w;
    G.emplace_back(s, t, w);
  }
  UnionFind uf(V);
  sort(ALL(G));

  int ans = 0;
  for (auto e : G) {
    if (uf.find(e.src) != uf.find(e.to)) {
      uf.unite(e.src, e.to);
      ans += e.cost;
    }
  }
  cout << ans << endl;

  return 0;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	double R;
	cin >> R;

	double pi = 3.141592653;

	double ans = 2.0 * pi * R;
	cout << fixed << setprecision(10) << ans << "\n";


	return 0;
}


Measured memory_bytes: 3764
#include <iostream>
using namespace std;
int main(){
    int A;
    int B;
    int C;
    int D[11];
    cin >> A >> B >>C;
    D[0] = C;
    for(int i=0; i<10; i++){
D[i+1] = A * D[i] - B;
    cout << D[i+1] <<endl;}
}

Measured memory_bytes: 256
#![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! {
        h:u64,
        n:u64,
        a:[u64;n],
    }

    let sum = a.iter().sum();

    if h <= sum {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

using ll = long long;
using P = pair<int, int>;

int main() {
    int n, m;
    while(cin >> n >> m, n) {
        vector<int> a(n+1);
        for(int i=1; i<=n; ++i) {
            cin >> a[i];
            a[i] %= m;
            (a[i] += a[i-1]) %= m;
        }
        int res = 0;
        set<int> s;
        s.insert(0);
        for(int i=1; i<=n; ++i) {
            auto it = s.upper_bound(a[i]);
            res = max(res, a[i]);
            if(it != s.end()) {
                res = max(res, (a[i] - *it + m) % m);
            }
            s.insert(a[i]);
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 4140
<?php
fscanf(STDIN, "%d", $num);
while ($tmp = trim(fgets(STDIN))) {
    $input = explode(' ', $tmp);
}

for ($n = 0; $n < $num; $n++) {
    if ($n === $num - 1) {
        echo $input[$n] . "\n";
    } else {
        echo $input[$n] . ' ';
    }
}
for ($i = 1; $i < $num; $i++) {
    $h = $i - 1;
    $target = $input[$i];
    while ($h >= 0 && (int)$input[$h] >= (int)$target) {
        $input[$h + 1] = $input[$h];
        $input[$h] = $target;
        $h--;
    }
    for ($n = 0; $n < $num; $n++) {
        if ($n === $num - 1) {
            echo $input[$n] . "\n";
        } else {
            echo $input[$n] . ' ';
        }
    }
}


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

int main()
{
	auto&& as_int = [] (char c) { return(int) c - '0'; };
	string s;
	cin >> s;
	size_t n = s.length();
	int cnt = 0;
	vector<int> t(n + 1, 0);
	vector<int> ms(2019, 0);
	{

		t[n] = 0;
		int factor = 1;

		ms[0]++;
		for (int i = n - 1; i >= 0; i--)
		{
			auto&& tmp =
				t[i] = (t[i + 1] + as_int(s[i]) * factor) % 2019;
			factor = factor * 10 % 2019;
			ms[tmp]++;
		}
	}
	for (auto& i : ms)
	{
		cnt += i * (i - 1) / 2;
	}
	cout << cnt << endl;
}

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

using namespace std;

int main(void)
{
	int n;
	int *a;
	int mi, ma;
	long sum;

	cin >> n;
	a = new int[n];

	cin >> a[0];
	mi = ma = sum = a[0];
	for (int i = 1; i < n && cin >> a[i]; i++) {
		mi = min(a[i], mi);
		ma = max(a[i], ma);
		sum += a[i];
	}	

	cout << mi << ' ' << ma << ' ' << sum << endl;
}

Measured memory_bytes: 3152
import sys
import numpy as np

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, d, x = I[:3]
a = I[3:]

def main():
    return x + np.sum((d - 1) // a + 1)

if __name__ == '__main__':
    ans = main()
    print(ans)

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N; cin >> N;
	map<int,int> cnt;
	vi A(N);
	forn(i,0,N){
		cin >> A[i];
		cnt[A[i]]++;
	}
	sort(all(A));
	if(A[0] == 1){
		if(cnt[1] == 1){
			cout << 1 << '\n';
		}else{
			cout << 0 << '\n';
		}
		return 0;
	}
	int maxi = A[N-1];
	set<int> S;
	int res = 0;
	forn(i,0,N){
		if(!S.count(A[i]) && cnt[A[i]] == 1){
			res++;
		}
		for(int j = A[i]; j <= maxi; j += A[i]){
			S.insert(j);
		}
	}
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 54016
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
ll MOD = 1000000007;
 
int main()
{
    int X, A;
    cin >> X >> A;
 
    if (X < A) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}

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

using namespace std;
using ll = long long int;

int main() {
	ll  n;
	cin>>n;
	ll nums[n];
	for(ll i = 0; i < n; i++) cin>>nums[i];
	unordered_map<ll,ll> cnt;
	for(ll i = 0; i < n; i++) cnt[nums[i]]++;
	ll ans = 0;
	for(auto x: cnt) {
		ans += x.second*(x.second-1)/2;
	}
	for(ll i = 0; i < n; i++) {
		cout<<ans-(cnt[nums[i]]-1)<<"\n";
	}
	return 0;
}


Measured memory_bytes: 9160
/**
 * @author torith
 * @date 2018-11-07
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct hint
{
    int x;
    int y;
    int h;
};

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<hint> hints;
    hint sample;
    for (int i = 0; i < N; ++i) {
        int x,y,h; cin >> x >> y >> h;
        hint a = {x, y, h};
        hints.push_back(a);
        if (h != 0) sample = a;
    }

    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            bool frg = true;
            int height = abs(i - sample.x) + abs(j - sample.y) + sample.h;
            for (int k = 0; k < N; ++k) {
                int dis = abs(i - hints[k].x) + abs(j - hints[k].y);
                if (hints[k].h != max(height - dis, 0)) {
                    frg = false;
                    break;
                }
            }
            if(frg){
                cout << i << " " << j << " " << height << "\n";
                return 0;
            }
        }
    }


    return 0;
}



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;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n,k;cin>>n>>k;
    vector<int> a(n);rep(i,n)cin>>a[i];
    for(int i=k;i<n;++i){
        if(a[i]>a[i-k]){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }

}

Measured memory_bytes: 3988
import sys
input=sys.stdin.readline


class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*n
        self.rank=[-1]*n

    def Find_Root(self,x):
        if self.root[x]<0:return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def size(self,x):
        return -self.root[self.Find_Root(x)]

    def members(self,x):
        root=self.Find_Root(x)
        return [i for i in range(self.n) if self.Find_Root(i)==root]

    def roots(self):
        return[i for i,j in enumerate(self.root) if j<0]

    def group_members(self):
        return {i:self.members(i) for i in self.roots()}

    def group_count(self):
        return len(self.roots())


n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(m)]

UnionFind=UnionFind(n+1)
for a,b in AB:
    if UnionFind.isSameGroup(a,b) is False:
        UnionFind.Unite(a,b)

ans=0
for i in range(1,n+1):
    cnt=UnionFind.size(i)
    if ans<cnt:
        ans=cnt
print(ans)

Measured memory_bytes: 107844
import java.util.*;
import java.util.Collections;

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();
    int cnt = 0;
    if (A == B) {
      cnt++;
    }
    ;
    if (B == C) {
      cnt++;
    }
    ;
    if (C == A) {
      cnt++;
    }
    ;
    if (cnt == 1) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23764
n,m = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(m):
    a,b = list(map(int,input().split()))
    link[a-1].append(b-1)
    link[b-1].append(a-1)

def isbi():
    colors = [-1] * n
    colors[0] = 0
    q = [(0, 0)]
    visited = set()
    cnt = 0
    while q:
        now, c = q.pop()
        if now in visited:
            if colors[now] != c:
                return False
            continue
        visited.add(now)
        colors[now] = c
        cnt += c
        for nxt in link[now]:
            q.append((nxt, c ^ 1))
    return cnt

ret = isbi()
if not ret:
    ans = n*(n-1)//2 - m
else:
    ans=ret*(n-ret) - m
print(ans)

Measured memory_bytes: 69464
#define pMax 10000
#include <iostream>
using namespace std;


bool isPrime[pMax];

void makePrime(void) {
    
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i = 2; i <= pMax; i++) {
        isPrime[i] = true;
    }
    for(int i = 2; i <= pMax; i++) {
        if(isPrime[i]) {
            for(int j = i + i; j <= pMax; j += i) {
                isPrime[j] = false;
            }
        }
    }
}

int main(void){
    // Your code here!
    
    makePrime();
    int n;
    
    while(cin >> n) {
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            if(isPrime[i] && isPrime[n+1-i])
                ans++;
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

int gcd(int a, int b)
{
    if (a < b)
        int c = a, a = b, b = c;
    return a % b == 0 ? b : gcd(b, a % b);
}

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

    int n, ma, mb, a[50], b[50], c[50];

    cin >> n >> ma >> mb;
    REP(i, n)
    cin >> a[i] >> b[i] >> c[i];

    int dp[2][500][500];

    REP(i, 500)
    REP(j, 500)
    {
        dp[0][i][j] = 10000;
        dp[1][i][j] = 10000;
    }

    int res = 0;

    dp[0][0][0] = 0;

    auto cur = dp[0];
    auto next = dp[1];

    REP(i, n)
    {
        REP(j, 500)
        {
            REP(k, 500)
            {
                next[j][k] = min(next[j][k], cur[j][k]);
                if (j >= a[i] && k >= b[i])
                    next[j][k] = min(next[j][k], cur[j - a[i]][k - b[i]] + c[i]);
            }
        }

        swap(cur, next);
    }

    int ca = ma;
    int cb = mb;

    res = 10000;

    while (ca < 500 & cb < 500)
    {
        res = min(res, cur[ca][cb]);
        ca += ma;
        cb += mb;
    }

    cout << (res == 10000 ? -1 : res) << endl;

    return 0;
}

Measured memory_bytes: 2176
import java.util.*;
public class Main{
  	public static void main (String [] args){
      	Scanner scanner = new Scanner (System.in);
      	int N = scanner.nextInt();
      	int [] arr = new int [N];
      	for (int i = 0; i < N; i++){
          	arr[i] = scanner.nextInt();
        }
      	Arrays.sort(arr);
      	int half = (arr[N-1])/2;
      	int sum = 0;
      	for (int i = 0; i < N-1; i++){
          	sum += arr[i];
        }
      	sum += half;
      	System.out.println(sum);
    }
}

Measured memory_bytes: 35736
import numpy as np

N,M,X = map(int,input().split())
arr = [np.array(list(map(int,input().split()))) for _ in range(N)]
ans = float('inf')
for i in range(2**N):
  arr_sum = np.array([0]*(M+1))
  for j in range(N):
    if i>>j&1:
      arr_sum += arr[j]
  if np.all(arr_sum[1:]>=X):
    ans = min(ans,arr_sum[0])

if ans == float('inf'):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 27340
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
inline int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int sub(int a,int b){a-=b;return a<0?a+mod:a;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
/* math */
const int N = (1<<18)*18;
int ch[N][2], s[N], sum[N], prod[N], cnt;
int H;
int inv[1<<18];
inline void addtag(int x,int p){
	prod[x]=mul(prod[x], p);
	sum[x]=mul(sum[x],p);
}
inline void pd(int x){
	if(prod[x]!=1){
		for(int j=0;j<2;j++)if(ch[x][j]){
			addtag(ch[x][j], prod[x]);
		}
		prod[x]=1;
	}
}
inline void ins(int& rt,int s,int x,int dep,int curs){
	int c=(s>>(dep-1))&1;
	if(!rt){
		rt=++cnt;
		prod[rt] = 1, sum[rt] = 0;
	}
	// cout << x << "::" << curs << endl;
	pd(rt);
	if(!dep){
		sum[rt] = add(sum[rt], mul(x, s));
		prod[rt] = 1;
		return ;
	}
	ins(ch[rt][c],s,x,dep-1,curs*2+c);
	if(ch[rt][0])sum[rt] = add(sum[rt], sum[ch[rt][0]]);
	if(ch[rt][1])sum[rt] = add(sum[rt], sum[ch[rt][1]]);
	sum[rt] = mul(sum[rt], curs);
}
int ans2;
inline int merge(int x,int y,int s){
	if(!x||!y)return x+y;
	pd(x),pd(y);
	ch[x][0] = merge(ch[x][0], ch[y][0], s<<1), ch[x][1] = merge(ch[x][1], ch[y][1], s<<1|1);
	// cout << s << ":" << sum[x] << " " << sum[y] << ":" << endl;
	int qwq = mul(inv[s], mul(sum[x], sum[y]));
	// cout << qwq << endl;
	ans2 = add(ans2, qwq);
	ans2 = sub(ans2, mul(s/2,mul(sum[x],sum[y])));
	// cout << mul(s/2,mul(sum[x],sum[y])) << endl;
	sum[x] = add(sum[x], sum[y]);
	return x;
}

int p[1<<18];
int rt[1<<18];

int main()
{
	inv[1]=1;for(int i=2;i<1<<18;i++){
		inv[i] = mul(mod-mod/i,inv[mod%i]);
	}
	cin >> H;
	for(int i=0;i<1<<(H-1);i++){
		scanf("%d",&p[(1<<(H-1))+i]);
		p[(1<<(H-1))+i]--;
		p[(1<<(H-1))+i]+=1<<(H-1);
	}
	int ans=0;
	for(int i=(1<<H)-1;i;i--){
		if(i>=(1<<(H-1))){
			// cout << i << "->" << p[i] << "!" << endl;
			ins(rt[i], p[i], i, H-1, 1);
		}else{
			ans2=0;
			rt[i] = merge(rt[i<<1], rt[(i<<1)|1], 1);
			ans2 = mul(ans2, i);
			ans = add(ans, ans2);
			// cout << i << ">> ";cout << ans << ":" << ans2 << endl;
			addtag(rt[i], i);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 43176
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    s = "".join(list(sorted(s_input())))
    t = "".join(list(sorted(s_input(), reverse=True)))
    if s < t:
        print("Yes")
    else:
        print("No")





if __name__=="__main__":
    main()


Measured memory_bytes: 71968
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int a, b ;
  cin >> a >> b ;
  
  if(a==1){
    a = 14 ;
  }
  else{
    a = a ;
  }
  if(b==1){
    b = 14 ;
  }
  else{
    b = b ;
  }
  
  if(a<b){
    cout <<"Bob"<<endl ;
  }
  else if(a==b){
    cout <<"Draw"<<endl ;
  }
  else{
    cout <<"Alice"<<endl ;
  }
    
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()     //main method
{
    FIO;
    ll n;
    cin>>n;
    ll arr[n+1];
    for(ll i=0;i<n;i++){
        cin>>arr[i];
    }
    ll ans=0;
   for(ll i=0;i<n-1;i++){
       if(arr[i]>arr[i+1]){
           ans+=arr[i]-arr[i+1];
           arr[i+1]=arr[i];
       }
       else continue;
   }
   cout<<ans<<"\n";







    return 0;
}

Measured memory_bytes: 5144
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";}
template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";}
template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;

int main() {
  ll n; cin>>n;
  ll an=0;
  for(ll i=2;i*i<=n;i++) {
    if (n%i==0) {
      ll nm=0;
      while(n%i==0) nm++,n/=i;
      //cout<<nm<<" ";
      ll ii=1;
      do {
        nm-=ii,ii++;
        if (nm>=0) an++;
        else break;
      } while(true);
    }
  }
  if (n>1) an++;
  cout<<an<<endl;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-
from sys import stdin

###########################################
# delete here


############################################
#from sys import stdin
import numpy as np

# read data for n sequences.
data = stdin.readline().split()
a = int(data[0])
b = int(data[1])
c = int(data[2])

if a == b == c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 20756
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
bool ispal(string a)
{
    long long int n=a.length();
    if(n==1)
        return true;
    else{
    int i=0,j;
    j=n-1;
    while(1)
    {
        if(a[i]!=a[j])
        {
            cout<<i<<" "<<j;
           return false;
        }
        i++,j--;
        if(i==j)
         {
        //     cout<<i<<" ";
             break;
        }
    }
    return true;
}}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin>>n;
    string a;
    cin>>a;
    ll cr=0,cw=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]=='R')
            cr++;
        else
            cw++;
    }
    ll ans=0;
    for(int i=0;i<cr;i++)
    {
        if(a[i]=='W')
            ans++;
    }
    cout<<ans;
 }


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<int, int> P;

int n;
vector<vector<int> > G(100001);
int dis_f[100001], dis_s[100001];
int ans_f, ans_s;

/* xからの距離情報 */
void dfs(int x, int *dis)
{
    REP(i, G[x].size()) {
        if(dis[G[x][i]] == INF) {
            dis[G[x][i]] = dis[x] + 1;
            dfs(G[x][i], dis);
        }
    }
}

int main()
{
    cin >> n;
    REP(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    REP(i, n) dis_f[i] = INF, dis_s[i] = INF;

    dis_f[0] = 0, dis_s[n-1] = 0;
    dfs(0, dis_f), dfs(n-1, dis_s);

    REP(i, n) if(dis_f[i] <= dis_s[i]) ans_f++; else ans_s++;

    if(ans_f > ans_s) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

    return 0;
}


Measured memory_bytes: 12800
N = int(input())

S = []
for _ in range(N):
  S.append(input())

print('{} {} {}'.format('AC','x',S.count('AC')))
print('{} {} {}'.format('WA','x',S.count('WA')))
print('{} {} {}'.format('TLE','x',S.count('TLE')))
print('{} {} {}'.format('RE','x',S.count('RE')))

Measured memory_bytes: 16292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
   
    int H, W;
    cin >> H >> W;
    
    int c[10][10];
    rep(i, 10) rep(j, 10) cin >> c[i][j];
    
    int List[10] = {0};
    rep(i, H) rep(j, W) {
        int A;
        cin >> A;
        if (A == -1) continue;
        List[A]++;
    }
    
    
    int ans[10];
    
    rep(i, 10) { // 単一始点問題を9回解く
        if (i == 1) continue;
        
        int table[10];
        fill_n(table, 10, inf);
        
        queue<pii> q;
        rep(j, 10) {
            if (j == i) continue;
            q.push(pii{j, c[i][j]});
            table[j] = c[i][j];
        }
        
        while (!q.empty()) {
            int now = q.front().F;
            int cost = q.front().S;
            q.pop();
            
            rep(j, 10) {
                if (now == j) continue;
                
                if (table[j] > cost + c[now][j]) {
                    table[j] = cost + c[now][j];
                    q.push(pii{j, table[j]});
                }
            }
        }
        
        ans[i] = table[1];
    }
    
    // outa(ans, 10);
    
    int Ans = 0;
    rep(i, 10) {
        if (i == 1) continue;
        Ans += ans[i] * List[i];
    }
    out(Ans);
    
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 200100
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
	
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);

}



int32_t main(){
	fastio;
	int n,m;
	cin>>n>>m;
	int res=0;
	if(n>1){
		res+=(n*(n-1))/2;
	}
	if(m>1){
		res+=(m*(m-1))/2;
	}
	cout<<res<<endl;
	
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    string s1,s2,s3,t = "a";
    int c1 = 0,c2 = 0,c3 = 0;
    cin >> s1 >> s2 >> s3;
    while (1) {
        if (t[0] == 'a') {
            if (s1.size() > c1) {
                t[0] = s1[c1];
                ++c1;
            }else{
                cout << "A" << endl;
                return 0;
            }
        }else if (t[0] == 'b') {
            if (s2.size() > c2) {
                t[0] = s2[c2];
                ++c2;
            }else{
                cout << "B" << endl;
                return 0;
            }
        }else if (t[0] == 'c') {
            if (s3.size() > c3) {
                t[0] = s3[c3];
                ++c3;
            }else{
                cout << "C" << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

bool cant[20][20];
int a,b,ans;

int main()
{
	while(cin >> a >> b,a)
	{
		REP(i,20)REP(j,20)cant[i][j] = false;
		ans = 0;
		int n;
		cin >> n;
		
		REP(i,n)
		{
			int x,y;
			cin >> x >> y;
			cant[x-1][y-1] = true;
		}
		
		queue<pair<int,int> > q;
		q.push(MP(0,0));
		
		while(!q.empty())
		{
			pair<int,int> tmp = q.front();q.pop();
			
			if(tmp.FI == a-1 && tmp.SE == b-1)
			{
				ans++;
				continue;
			}
			
			if(cant[tmp.FI][tmp.SE] == true)
			{
				continue;
			}
			
			if(tmp.FI < a-1)
			{
				q.push(MP(tmp.FI+1,tmp.SE));
			}
			
			if(tmp.SE < b-1)
			{
				q.push(MP(tmp.FI,tmp.SE+1));
			}
		}
		
		cout << ans << endl;
	}
		

	
	return 0;
}

Measured memory_bytes: 9236
/*
ID: htc9811
LANG: C++
TASK:
*/
 
//#define Online
#define LOCAL
//#define debug
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
using namespace std;
const string TASK="";
vector<int> _V(int a[],int _n){vector<int> _v;for(int i=0;i<_n;i++) _v.push_back(a[i]);return _v;}
vector<long long> _V(long long a[],int _n){vector<long long> _v;for(int i=0;i<_n;i++) _v.push_back(a[i]);return _v;}
vector<string> _V(string a[],int _n){vector<string> _v;for(int i=0;i<_n;i++) _v.push_back(a[i]);return _v;}
inline string _IN(){return TASK+".in";}
inline string _OUT(){return TASK+".out";}
 
const int N=105;
int n,m,ans;
int v[N],w[N];
int dp[N][N][3*N];
 
int main(){
	#ifdef Online
	freopen(_IN().c_str(),"r",stdin);
	freopen(_OUT().c_str(),"w",stdout);
	#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d%d",w+i,v+i);
	for(int i=1;i<=n;i++) for(int j=0;j<=i;j++) for(int k=0;k<=3*j;k++){
		dp[i][j][k]=dp[i-1][j][k];
		if(k>=(w[i]-w[1])&&j) dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][k-w[i]+w[1]]+v[i]);
	}
//	for(int i=0;i<=n;i++) for(int j=0;j<=i;j++) for(int k=0;k<=3*j;k++) cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
	for(int i=0;i<=n;i++) for(int k=0;k<=3*i;k++){
		long long W=k+1LL*w[1]*i;
		if(W<=m) ans=max(ans,dp[n][i][k]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 11392
//二分探索 : O(N^2*logN)

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<long long> L(N);

    for (int i = 0; i < N; i++) cin >> L[i];
    sort(L.begin(), L.end());  //ソート

    long long res = 0; //result

    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            auto k = lower_bound(L.begin(), L.end(), L[i]+L[j]);
            int index = k - L.begin();
            res += index - (j+1);
        }           
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long int ll;
int n,m;
int a[50];
int b[50];
bool G[50][50];
bool visited[50];

void dfs(int v){
	visited[v]=true;
	for(int v2=0;v2<n;v2++){
		if(G[v][v2]==false)continue;
		if(visited[v2])continue;
		dfs(v2);
	}
}
int main(){
	cin >> n >> m ;
	for(int i=0;i<m;i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		G[a[i]][b[i]]=G[b[i]][a[i]]=true;
	}
	int ans=0;
	for(int i=0;i<m;i++){
		G[a[i]][b[i]]=G[b[i]][a[i]]=false;
		for(int j=0;j<n;j++){
			visited[j]=false;
		}
		dfs(0);
		bool bridge=false;
		for(int j=0;j<n;j++){
			if(visited[j]==false) bridge=true;
		}
		if(bridge)ans++;
		G[a[i]][b[i]]=G[b[i]][a[i]]=true;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter

n, k = map(int, input().split())
a = list(map(int, input().split()))
check = [0] * n
# for i, val in enumerate(a):
#　１回でも行ったことのある場所へ行けば、ループになる

target = 0
for i in range(k):
    if (check[target] == 2):  #
        #print('A', i)
        count = Counter(check)
        num_2 = count[2]
        #print(num_2)
        temp = k - (i)
        mod = temp % num_2
        for j in range(mod):
            aaa = a[target]
            target = aaa - 1

        ans = target + 1
        break

    else:
        check[target] += 1
        aaa = a[target]
        target = aaa - 1

        ans = target + 1

print(ans)


Measured memory_bytes: 33836
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= 9; i++)
		for(int j = 1; j <= 9; j++)
			if(i * j == N) {
				puts("Yes");
				return 0;
			}
	puts("No");
	return 0;
}

Measured memory_bytes: 128
mod = 10**9+7


def inv(a, mod):
    r = [1, 0, a]
    w = [0, 1, mod]
    while w[2] != 1:
        q = r[2]//w[2]
        r_new = [r[0]-q*w[0], r[1]-q*w[1], r[2]-q*w[2]]
        r = w
        w = r_new
    x, y = w[0], w[1]    # a*x+y*mod = 1
    return (mod+x % mod) % mod


max_num = 2*10**6+100
fact = [0 for _ in range(max_num)]
ifact = [0 for _ in range(max_num)]

fact[0] = fact[1] = 1
ifact[0] = ifact[1] = 1

for i in range(2, max_num):
    fact[i] = fact[i-1] * i % mod
    ifact[i] = ifact[i-1] * inv(i, mod) % mod


def cmb(x, y):
    return fact[x] * ifact[y] * ifact[x-y] % mod


def solve(r, c):
    ans = 0
    for i in range(r+1):
        ans += cmb(c+i+1, c)
        ans %= mod
    return ans


r1, c1, r2, c2 = map(int, input().split())

ans = solve(r2, c2) - solve(r2, c1-1) - solve(r1-1, c2) + solve(r1-1, c1-1)
ans %= mod

print(ans)


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

string added[] = {"maerd", "remaerd", "esare", "resare"};


int main()
{
    string s;cin >> s;
    int sl = (int)s.length();
    reverse(s.begin(), s.end());
    int index = 0;
    while(index < sl)
    {
        int flag = 0;
        for(auto &&temp: added)
        {
            int len = (int)temp.length();
            if(equal(s.begin()+index, s.begin()+index+len, temp.begin(), temp.end()))
            {
                index += len;
                flag++;
                break;
            }
        }
        if(flag == 0) break;
    }
    if(index == sl)
    {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
}

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

int n,x,y,a[45],b[45],c[45];
int dp[45][454][545];
int ans=INF;
int ta,mu;

signed main(){
	cin>>n>>x>>y;
	rep(i,n){
		rep(j,401){
			rep(k,401)dp[i][j][k]=INF;
		}
	}
	cin>>a[0]>>b[0]>>c[0];
	dp[0][0][0]=0;
	ta=a[0],mu=b[0];
	dp[0][a[0]][b[0]]=c[0];
	for(int i=1;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
		ta+=a[i];
		mu+=b[i];
		rep(j,401){
			rep(k,401){
				if(j>=a[i]&&k>=b[i])dp[i][j][k]=min(dp[i-1][j][k],dp[i-1][j-a[i]][k-b[i]]+c[i]);
				dp[i][j][k]=min(dp[i-1][j][k],dp[i][j][k]);
			}
		}
	}
	rep(j,401){
		rep(k,401){
			if((!(j==0&&k==0))&&x*k==y*j&&j<=ta&&k<=mu)ans=min(ans,dp[n-1][j][k]);
		}
	}
	if(ans==INF)cout<<-1<<endl;
	else cout<<ans<<endl;
}

Measured memory_bytes: 38912
from collections import defaultdict

def main():
    N, K = map(int, input().split())
    d = [0] * K
    A = [[] for _ in range(K)]
    B = defaultdict(int)
    for i in range(K):
        d[i] = int(input())
        A[i] = list(map(int, input().split()))
        for a in A[i]:
            B[a] += 1
    ans = 0
    for i in range(1,N+1):
        if B[i] == 0:
            ans += 1
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 68292
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    string S;
    cin >> S;
    if (S == "ABC")
        cout << "ARC" << endl;
    else 
        cout << "ABC" << endl;

    return 0;
}


Measured memory_bytes: 3640
n, x = [int(i) for i in input().split()]

num_p = [0 for i in range(n+1)]

for i in range(1, n+1):
  num_p[i] = num_p[i-1] * 2 + 1

total = 1
for i in range(1, n + 1):
  total = total * 2 + 3

cnt = 0
left = 1
right = total

for i in range(n,-1, -1):
  center = (left + right) // 2
  if x == center:
    cnt += num_p[i] + 1
    break
  if x > center:
    cnt += num_p[i] + 1
    left = center + 1
    right = right - 1
  else:
    left = left + 1
    right = center -1

print(cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

ll choose(int n, int a) {
  ll x = 1, y = 1;
  for (int i = 0; i < a; ++i) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m, n;
  cin >> m >> n;
  ll mans = choose(m,2);
  ll nans = choose(n, 2);
  cout << nans + mans << '\n';
}


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

using namespace std;

const int N = 2 * 1e5 + 100;
const long long MOD = 1e9 + 7;
int n;
long long a[N], sum1, sum2;

int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= n; i ++ ) {
		scanf ("%lld", &a[i]);
		sum1 += a[i];
	}
	for (int i = 1; i <= n; i ++ ) {
		sum1 -= a[i];
		sum2 = sum2 + ((sum1 % MOD) * (a[i] % MOD)) % MOD;
		sum2 %= MOD;
	}
	printf ("%lld\n", sum2);
	return 0;
}

Measured memory_bytes: 5372
n,m=map(int,input().split(" "))
l=[]
bone=[]
for i in range(m):
		a,b=input().split(" ")
		if a=="1":l.append(b)
		if b==str(n):bone.append(a)

ans=list(set(l) & set(bone))
if len(ans)!=0:
	print("POSSIBLE")
else:			
	print("IMPOSSIBLE")

Measured memory_bytes: 26732
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] arr = line.split(" ");
		int r = Integer.parseInt(arr[0]);
		int c = Integer.parseInt(arr[1]);

		int[][] spreadsheet = new int[r + 1][c + 1];
		int row = 0;
		while ((line = br.readLine()) != null) {
			String[] cols = line.split(" ");
			for (int col = 0; col < c; col++) {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			}
			row++;
		}

		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			}
			System.out.println();
		}
	}
}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}

#define rep(i,n) for(ll i=1; i<(ll)(n); i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0; i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

int main(){
    ll n; cin >> n;
    vector<ll> v(10001, 0);
    rep(i,100){
        rep(j,100){
            rep(k,100){
                ll ans = i*i + j*j + k*k + i*j + j*k + k*i;
                if (ans <= 10000) v.at(ans)++;
            }
        }
    }
  	rep(i, n+1)cout << v.at(i) << endl;
}

Measured memory_bytes: 3624
<?php

$input_str = trim(fgets(STDIN));

$command_count = intval(trim(fgets(STDIN)));

for ($i = 0; $i < $command_count; $i++) {
    $command = explode(" ", trim(fgets(STDIN)));
    $length = intval($command[2]) - intval($command[1]) + 1;
    switch ($command[0]){
        case "print":
            echo substr($input_str, intval($command[1]), $length)."\n";
            break;
        case "replace":
            $input_str = substr_replace($input_str, $command[3], intval($command[1]), $length);
            break;
        case "reverse":
            $tmp = strrev(substr($input_str, intval($command[1]), $length));
            $input_str = substr_replace($input_str, $tmp, intval($command[1]), $length);
            break;
    }
}



Measured memory_bytes: 9296
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

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

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

modint dp[3005][6005];

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

    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];

    dp[0][0] = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= s; ++j){
            if(dp[i][j] == 0)   continue;
            dp[i + 1][j] += dp[i][j] * 2;
            dp[i + 1][j + a[i]] += dp[i][j];
        }
    }

    cout << dp[n][s] << endl;
}

Measured memory_bytes: 74104
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

using Edges = vector<pair<int, int>>;
using Graph = vector<Edges>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const LL INF = (1LL << 60);
vector<LL> dijkstra(const Graph &g, int s) {
    int n = g.size();
    vector<LL> dist(n, INF);
    min_priority_queue<pair<LL, int>> que;

    que.push({0, s});
    dist[s] = 0;
    while(not que.empty()) {
        auto dv = que.top(); que.pop();
        LL d = dv.first;
        int v = dv.second;

        if (dist[v] < d) continue;
        for (auto e : g[v]) {
            if (dist[v] + e.second < dist[e.first]) {
                dist[e.first] = dist[v] + e.second;
                que.push({dist[e.first], e.first});
            }
        }
    }
    return dist;
}
int main() {
    int n, m; cin >> n >> m;
    Graph graph(n);
    rep(i, m) {
        int a, b; cin >> a >> b;
        --a, --b;
        graph[a].push_back({b, 1});
        graph[b].push_back({a, 1});
    }
    auto dist = dijkstra(graph, 0);
    if (dist[n - 1] == 2) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 16488
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >>n >> k;
    vector<int> vc(n);
    for(int i = 0;i < n;i++) {
        cin >> vc[i];
    }
    sort(vc.rbegin(), vc.rend());
    int sum = 0;
    for(int i = 0;i < k;i++) {
        sum+=vc[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 256